-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·274 lines (233 loc) · 7.47 KB
/
install.sh
File metadata and controls
executable file
·274 lines (233 loc) · 7.47 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/bin/bash
# Claude Code Agents & Skills - Interactive Installer
# Installs agents, commands, and hooks to your Claude configuration
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
CLAUDE_DIR="$HOME/.claude"
AGENTS_DIR="$CLAUDE_DIR/agents"
COMMANDS_DIR="$CLAUDE_DIR/commands"
HOOKS_DIR="$CLAUDE_DIR/hooks"
REPO_AGENTS_DIR="./agents"
REPO_COMMANDS_DIR="./commands"
REPO_HOOKS_DIR="./hooks"
print_header() {
echo ""
echo -e "${CYAN}========================================================${NC}"
echo -e "${CYAN} Claude Code Agents & Skills - Installer${NC}"
echo -e "${CYAN}========================================================${NC}"
echo ""
}
print_success() { echo -e "${GREEN}+${NC} $1"; }
print_warning() { echo -e "${YELLOW}!${NC} $1"; }
print_error() { echo -e "${RED}x${NC} $1"; }
print_info() { echo -e "${BLUE}i${NC} $1"; }
check_repository() {
if [ ! -d "$REPO_AGENTS_DIR" ] && [ ! -d "$REPO_COMMANDS_DIR" ]; then
print_error "Run this script from the repository root directory."
exit 1
fi
}
setup_directories() {
print_info "Setting up Claude directories..."
mkdir -p "$AGENTS_DIR" "$COMMANDS_DIR" "$HOOKS_DIR"
print_success "Directories ready"
echo ""
}
check_existing_file() {
local source_file=$1
local target_file=$2
if [ -f "$target_file" ]; then
if ! diff -q "$source_file" "$target_file" &>/dev/null; then
return 0
fi
fi
return 1
}
check_existing_dir() {
local source_dir=$1
local target_dir=$2
if [ -d "$target_dir" ]; then
if ! diff -rq "$source_dir" "$target_dir" &>/dev/null; then
return 0
fi
fi
return 1
}
# --- Agents ---
get_available_agents() {
if [ -d "$REPO_AGENTS_DIR" ]; then
find "$REPO_AGENTS_DIR" -maxdepth 1 -name "*.md" -exec basename {} .md \;
fi
}
install_agent() {
local name=$1 force=$2
local src="$REPO_AGENTS_DIR/${name}.md"
local dst="$AGENTS_DIR/${name}.md"
[ ! -f "$src" ] && { print_error "Agent '$name' not found"; return 1; }
if check_existing_file "$src" "$dst"; then
if [ "$force" != "yes" ]; then
print_warning "Agent '$name' exists and differs"
read -p " Overwrite? (y/n): " -n 1 -r; echo
[[ ! $REPLY =~ ^[Yy]$ ]] && { print_info "Skipped '$name'"; return 0; }
fi
fi
cp "$src" "$dst"
print_success "Installed agent: $name"
}
# --- Commands ---
get_available_commands() {
if [ -d "$REPO_COMMANDS_DIR" ]; then
find "$REPO_COMMANDS_DIR" -mindepth 1 -maxdepth 1 -type d -exec basename {} \;
fi
}
install_command() {
local name=$1 force=$2
local src="$REPO_COMMANDS_DIR/$name"
local dst="$COMMANDS_DIR/$name"
local flat_file="$COMMANDS_DIR/${name}.md"
[ ! -d "$src" ] && { print_error "Command '$name' not found"; return 1; }
# Handle flat file → directory migration
# Claude Code supports both ~/.claude/commands/foo.md and ~/.claude/commands/foo/foo.md
# If a flat file exists alongside the directory, it causes duplicate commands
if [ -f "$flat_file" ]; then
if [ "$force" != "yes" ]; then
print_warning "Command '$name' exists as flat file (${name}.md)"
read -p " Replace with directory format? (y/n): " -n 1 -r; echo
[[ ! $REPLY =~ ^[Yy]$ ]] && { print_info "Skipped '$name'"; return 0; }
fi
rm -f "$flat_file"
print_info "Removed flat file: ${name}.md"
fi
if check_existing_dir "$src" "$dst"; then
if [ "$force" != "yes" ]; then
print_warning "Command '$name' exists and differs"
read -p " Overwrite? (y/n): " -n 1 -r; echo
[[ ! $REPLY =~ ^[Yy]$ ]] && { print_info "Skipped '$name'"; return 0; }
fi
rm -rf "$dst"
fi
cp -r "$src" "$COMMANDS_DIR/"
print_success "Installed command: $name"
}
# --- Hooks ---
get_available_hooks() {
if [ -d "$REPO_HOOKS_DIR" ]; then
find "$REPO_HOOKS_DIR" -maxdepth 1 -name "*.sh" -exec basename {} \;
fi
}
install_hook() {
local name=$1 force=$2
local src="$REPO_HOOKS_DIR/$name"
local dst="$HOOKS_DIR/$name"
[ ! -f "$src" ] && { print_error "Hook '$name' not found"; return 1; }
if check_existing_file "$src" "$dst"; then
if [ "$force" != "yes" ]; then
print_warning "Hook '$name' exists and differs"
read -p " Overwrite? (y/n): " -n 1 -r; echo
[[ ! $REPLY =~ ^[Yy]$ ]] && { print_info "Skipped '$name'"; return 0; }
fi
fi
cp "$src" "$dst"
chmod +x "$dst"
print_success "Installed hook: $name"
}
# --- Selection menus ---
select_items() {
local type=$1
shift
local items=("$@")
if [ ${#items[@]} -eq 0 ]; then
print_info "No ${type}s found"
return
fi
echo -e "${CYAN}Available ${type}s:${NC}"
echo ""
local i=1
for item in "${items[@]}"; do
echo " $i) $item"
((i++))
done
echo " a) Install all"
echo " s) Skip"
echo ""
read -p "Select (comma-separated numbers, 'a' for all, 's' to skip): " selection
if [ "$selection" == "s" ] || [ "$selection" == "S" ]; then
print_info "Skipping ${type}s"
echo ""
return
fi
echo ""
if [ "$selection" == "a" ] || [ "$selection" == "A" ]; then
for item in "${items[@]}"; do
install_${type} "$item" "no"
done
else
IFS=',' read -ra SELS <<< "$selection"
for sel in "${SELS[@]}"; do
sel=$(echo "$sel" | xargs)
if [[ "$sel" =~ ^[0-9]+$ ]]; then
local idx=$((sel - 1))
if [ $idx -ge 0 ] && [ $idx -lt ${#items[@]} ]; then
install_${type} "${items[$idx]}" "no"
else
print_warning "Invalid selection: $sel"
fi
fi
done
fi
echo ""
}
# --- MCP checks ---
check_greptile_mcp() {
print_info "Greptile MCP Check"
echo ""
if ! command -v claude &>/dev/null; then
print_warning "Claude CLI not found - skipping MCP check"
echo ""
return 0
fi
if claude mcp list 2>/dev/null | grep -q "greptile"; then
print_success "Greptile MCP already installed"
else
print_warning "Greptile MCP not detected"
echo ""
print_info "The greptile-review-loop agent requires the Greptile MCP plugin."
echo ""
echo -e "${YELLOW}To install Greptile:${NC}"
echo " 1. Install the Greptile GitHub app at https://app.greptile.com"
echo " 2. Add the Greptile MCP plugin to Claude Code"
fi
echo ""
}
# --- Main ---
main() {
print_header
check_repository
setup_directories
print_info "Step 1: Agents"
echo ""
local agents=($(get_available_agents))
select_items "agent" "${agents[@]}"
print_info "Step 2: Commands"
echo ""
local commands=($(get_available_commands))
select_items "command" "${commands[@]}"
print_info "Step 3: Hooks"
echo ""
local hooks=($(get_available_hooks))
select_items "hook" "${hooks[@]}"
print_info "Step 4: Dependency Checks"
echo ""
check_greptile_mcp
echo -e "${CYAN}========================================================${NC}"
print_success "Installation complete!"
echo ""
print_info "Restart Claude Code to load new configurations."
echo -e "${CYAN}========================================================${NC}"
}
main