-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·156 lines (132 loc) · 4.48 KB
/
install.sh
File metadata and controls
executable file
·156 lines (132 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
set -e
# Bouncer installer
# Usage: curl -fsSL https://raw.githubusercontent.com/buildingopen/bouncer/master/install.sh | bash
GREEN='\033[0;32m'
DIM='\033[2m'
BOLD='\033[1m'
RESET='\033[0m'
echo ""
echo -e "${GREEN}${BOLD}bouncer${RESET} installer"
echo -e "${DIM}Gemini audits Claude Code.${RESET}"
echo ""
# Check Python
if ! command -v python3 &>/dev/null; then
echo "Error: python3 not found. Install Python 3.8+ first."
exit 1
fi
# Check pip
if ! python3 -m pip --version &>/dev/null; then
echo "Error: pip not found. Install pip first."
exit 1
fi
# Resolve source files. When the installer is run from a local checkout, copy
# directly from disk; when piped from curl, download from GitHub.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR="${BOUNCER_SOURCE_DIR:-}"
REPO_REF="${BOUNCER_REPO_REF:-master}"
REPO_BASE_URL="${BOUNCER_BASE_URL:-https://raw.githubusercontent.com/buildingopen/bouncer/${REPO_REF}}"
if [ -z "$SOURCE_DIR" ] && [ -f "$SCRIPT_DIR/gemini-audit.py" ] && [ -f "$SCRIPT_DIR/skill/SKILL.md" ]; then
SOURCE_DIR="$SCRIPT_DIR"
fi
copy_or_download() {
local relative_path="$1"
local destination="$2"
if [ -n "$SOURCE_DIR" ]; then
cp "$SOURCE_DIR/$relative_path" "$destination"
else
curl -fsSL "$REPO_BASE_URL/$relative_path" -o "$destination"
fi
}
# Install dependency
echo -e "${DIM}Installing google-genai...${RESET}"
python3 -m pip install --quiet --user --break-system-packages google-genai
# Create directories
mkdir -p ~/.claude/hooks
mkdir -p ~/.claude/skills/bouncer/scripts
# Install files
echo -e "${DIM}Installing bouncer files...${RESET}"
copy_or_download "gemini-audit.py" ~/.claude/hooks/gemini-audit.py
copy_or_download "gemini-audit.sh" ~/.claude/hooks/gemini-audit.sh
copy_or_download "skill/SKILL.md" ~/.claude/skills/bouncer/SKILL.md
copy_or_download "skill/scripts/bouncer-check.py" ~/.claude/skills/bouncer/scripts/bouncer-check.py
copy_or_download "skill/scripts/bouncer-deep.py" ~/.claude/skills/bouncer/scripts/bouncer-deep.py
chmod +x ~/.claude/hooks/gemini-audit.sh ~/.claude/hooks/gemini-audit.py
chmod +x ~/.claude/skills/bouncer/scripts/bouncer-check.py
chmod +x ~/.claude/skills/bouncer/scripts/bouncer-deep.py
# Register Stop hook in settings.json
SETTINGS="$HOME/.claude/settings.json"
if [ -f "$SETTINGS" ]; then
# Check if hook already registered
if grep -q "gemini-audit" "$SETTINGS" 2>/dev/null; then
echo -e "${DIM}Hook already registered in settings.json${RESET}"
else
# Add hook to existing settings using Python for safe JSON manipulation
python3 -c "
import json, sys
with open('$SETTINGS', 'r') as f:
settings = json.load(f)
hook_entry = {
'type': 'command',
'command': '~/.claude/hooks/gemini-audit.sh',
'timeout': 60
}
hooks = settings.setdefault('hooks', {})
stop = hooks.setdefault('Stop', [{'matcher': '', 'hooks': []}])
# Find the matcher='' entry or create one
target = None
for entry in stop:
if entry.get('matcher', '') == '':
target = entry
break
if not target:
target = {'matcher': '', 'hooks': []}
stop.append(target)
target.setdefault('hooks', []).append(hook_entry)
with open('$SETTINGS', 'w') as f:
json.dump(settings, f, indent=2)
"
echo -e "${DIM}Hook registered in settings.json${RESET}"
fi
else
# Create settings.json from scratch
python3 -c "
import json
settings = {
'hooks': {
'Stop': [{
'matcher': '',
'hooks': [{
'type': 'command',
'command': '~/.claude/hooks/gemini-audit.sh',
'timeout': 60
}]
}]
}
}
with open('$SETTINGS', 'w') as f:
json.dump(settings, f, indent=2)
"
echo -e "${DIM}Created settings.json with hook${RESET}"
fi
# Enable
touch ~/.claude/.gemini-audit-enabled
# Check API key
if [ -z "$GEMINI_API_KEY" ] && [ -z "$GOOGLE_API_KEY" ]; then
echo ""
echo -e "${GREEN}${BOLD}Installed!${RESET} One step left:"
echo ""
echo " export GEMINI_API_KEY=\"your-key-here\""
echo ""
echo -e "${DIM}Add to your .bashrc/.zshrc. Get a free key at:${RESET}"
echo " https://aistudio.google.com/apikey"
else
echo ""
echo -e "${GREEN}${BOLD}Installed and ready.${RESET}"
fi
echo ""
echo -e " Stop hook: ${GREEN}active${RESET} (every Claude response is audited)"
echo -e " Skill: ${GREEN}active${RESET} (type /bouncer for on-demand audit)"
echo ""
echo -e "${DIM}Disable: rm ~/.claude/.gemini-audit-enabled${RESET}"
echo ""