forked from VoltAgent/awesome-claude-code-subagents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-agents.sh
More file actions
executable file
·583 lines (503 loc) · 17.6 KB
/
install-agents.sh
File metadata and controls
executable file
·583 lines (503 loc) · 17.6 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
#!/bin/bash
# Claude Code Agents Installer
# Interactive script to install/uninstall agents from this repository
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CATEGORIES_DIR="$SCRIPT_DIR/categories"
GLOBAL_AGENTS_DIR="$HOME/.claude/agents"
LOCAL_AGENTS_DIR=".claude/agents"
CLAUDE_AGENTS_DIR="" # Will be set by select_install_mode
INSTALL_MODE="" # "global" or "local"
SOURCE_MODE="" # "local" or "remote"
# GitHub API configuration
GITHUB_API_BASE="https://api.github.com/repos/laywill/awesome-claude-code-subagents/contents"
GITHUB_RAW_BASE="https://raw.githubusercontent.com/laywill/awesome-claude-code-subagents/main"
# Cache for remote data
REMOTE_CATEGORIES=()
REMOTE_AGENTS=()
# Function to check if local .claude directory exists
has_local_claude_dir() {
[[ -d ".claude" ]]
}
# Function to check if local categories directory exists
has_local_categories() {
[[ -d "$CATEGORIES_DIR" ]]
}
# Function to check if curl is available
check_curl() {
if ! command -v curl &> /dev/null; then
echo -e "${RED}Error: curl is required for remote mode but not installed.${NC}"
exit 1
fi
}
# Function to fetch categories from GitHub API
fetch_categories_remote() {
local response
response=$(curl -s "$GITHUB_API_BASE/categories")
# Check for rate limiting or errors
if echo "$response" | grep -q "API rate limit exceeded"; then
echo -e "${RED}GitHub API rate limit exceeded. Please try again later or use local mode.${NC}"
sleep 3
return 1
fi
if echo "$response" | grep -q '"message"'; then
echo -e "${RED}Error fetching from GitHub API.${NC}"
sleep 3
return 1
fi
# Parse JSON response - extract directory names starting with numbers
REMOTE_CATEGORIES=()
while IFS= read -r line; do
if [[ -n "$line" ]]; then
REMOTE_CATEGORIES+=("$line")
fi
done < <(echo "$response" | grep -o '"name": "[0-9][^"]*"' | sed 's/"name": "//;s/"$//' | sort)
return 0
}
# Function to fetch agents from a category via GitHub API
fetch_agents_remote() {
local category="$1"
local response
response=$(curl -s "$GITHUB_API_BASE/categories/$category")
# Check for errors
if echo "$response" | grep -q '"message"'; then
return 1
fi
# Parse JSON response - extract .md files excluding README.md
REMOTE_AGENTS=()
while IFS= read -r line; do
if [[ -n "$line" && "$line" != "README.md" ]]; then
REMOTE_AGENTS+=("$line")
fi
done < <(echo "$response" | grep -o '"name": "[^"]*\.md"' | sed 's/"name": "//;s/"$//' | sort)
return 0
}
# Function to download an agent file from GitHub
download_agent() {
local category="$1"
local agent_file="$2"
local dest_path="$3"
local url="$GITHUB_RAW_BASE/categories/$category/$agent_file"
if curl -sS "$url" -o "$dest_path" 2>/dev/null; then
return 0
else
return 1
fi
}
# Function to select source mode (local or remote)
select_source_mode() {
# If no local categories, automatically use remote
if ! has_local_categories; then
SOURCE_MODE="remote"
check_curl
echo -e "${YELLOW}No local repository found. Using remote mode (GitHub).${NC}"
sleep 1
return
fi
show_header
echo -e "${BOLD}Select source:${NC}\n"
echo -e " ${YELLOW}1)${NC} Local files ${CYAN}(from cloned repository)${NC}"
echo -e " Faster, works offline"
echo ""
echo -e " ${YELLOW}2)${NC} Remote ${CYAN}(download from GitHub)${NC}"
echo -e " Always up-to-date"
echo ""
echo -e " ${YELLOW}q)${NC} Quit"
echo ""
read -p "Enter your choice: " choice
case "$choice" in
1)
SOURCE_MODE="local"
;;
2)
SOURCE_MODE="remote"
check_curl
;;
q|Q)
echo -e "\n${GREEN}Goodbye!${NC}"
exit 0
;;
*)
echo -e "${RED}Invalid choice. Please try again.${NC}"
sleep 1
select_source_mode
;;
esac
}
# Function to select installation mode
select_install_mode() {
show_header
echo -e "${BOLD}Select installation mode:${NC}\n"
echo -e " ${YELLOW}1)${NC} Global installation ${CYAN}(~/.claude/agents/)${NC}"
echo -e " Available for all projects"
echo ""
if has_local_claude_dir; then
echo -e " ${YELLOW}2)${NC} Local installation ${CYAN}(.claude/agents/)${NC}"
echo -e " Only for current project"
else
echo -e " ${BLUE}2)${NC} Local installation ${CYAN}(not available)${NC}"
echo -e " ${YELLOW}No .claude/ directory found in current directory${NC}"
fi
echo ""
echo -e " ${YELLOW}q)${NC} Quit"
echo ""
read -p "Enter your choice: " choice
case "$choice" in
1)
CLAUDE_AGENTS_DIR="$GLOBAL_AGENTS_DIR"
INSTALL_MODE="global"
mkdir -p "$CLAUDE_AGENTS_DIR"
;;
2)
if has_local_claude_dir; then
CLAUDE_AGENTS_DIR="$LOCAL_AGENTS_DIR"
INSTALL_MODE="local"
mkdir -p "$CLAUDE_AGENTS_DIR"
else
echo -e "\n${RED}Local installation not available. No .claude/ directory found.${NC}"
sleep 2
select_install_mode
return
fi
;;
q|Q)
echo -e "\n${GREEN}Goodbye!${NC}"
exit 0
;;
*)
echo -e "${RED}Invalid choice. Please try again.${NC}"
sleep 1
select_install_mode
;;
esac
}
# Function to display a header
show_header() {
clear
echo -e "${BOLD}${CYAN}"
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ Claude Code Agents Installer ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
if [[ -n "$INSTALL_MODE" ]]; then
local mode_str=""
if [[ "$INSTALL_MODE" == "global" ]]; then
mode_str="Global (~/.claude/agents/)"
else
mode_str="Local (.claude/agents/)"
fi
local source_str=""
if [[ "$SOURCE_MODE" == "remote" ]]; then
source_str=" | Source: GitHub"
else
source_str=" | Source: Local"
fi
echo -e "${BLUE}Mode: ${mode_str}${source_str}${NC}\n"
fi
}
# Function to get category display name (remove number prefix)
# Uses awk for Title Case conversion (compatible with macOS and Linux)
get_category_name() {
local dir="$1"
echo "$dir" | sed 's/^[0-9]*-//' | tr '-' ' ' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1'
}
# Function to check if an agent is installed
is_agent_installed() {
local agent_file="$1"
local agent_name=$(basename "$agent_file")
[[ -f "$CLAUDE_AGENTS_DIR/$agent_name" ]]
}
# Function to get agent description from frontmatter
get_agent_description() {
local agent_file="$1"
grep -A1 "^description:" "$agent_file" 2>/dev/null | head -1 | sed 's/^description: *//' | cut -c1-60
}
# Function to display category selection menu
select_category() {
show_header
echo -e "${BOLD}Select a category:${NC}\n"
local categories=()
local i=1
if [[ "$SOURCE_MODE" == "remote" ]]; then
# Remote mode: fetch from GitHub API
echo -e "${CYAN}Fetching categories from GitHub...${NC}\n"
if ! fetch_categories_remote; then
echo -e "${RED}Failed to fetch categories. Press Enter to retry.${NC}"
read
select_category
return
fi
for dirname in "${REMOTE_CATEGORIES[@]}"; do
categories+=("$dirname")
local display_name=$(get_category_name "$dirname")
echo -e " ${YELLOW}$i)${NC} $display_name"
((i++))
done
else
# Local mode: read from filesystem
for dir in "$CATEGORIES_DIR"/*/; do
if [[ -d "$dir" && $(basename "$dir") != "." ]]; then
local dirname=$(basename "$dir")
# Skip if it's not a category directory (doesn't start with number)
if [[ "$dirname" =~ ^[0-9]+ ]]; then
categories+=("$dirname")
local display_name=$(get_category_name "$dirname")
local agent_count=$(ls "$dir"/*.md 2>/dev/null | grep -v README.md | wc -l | tr -d ' ')
echo -e " ${YELLOW}$i)${NC} $display_name ${CYAN}($agent_count agents)${NC}"
((i++))
fi
fi
done
fi
echo ""
echo -e " ${YELLOW}q)${NC} Quit"
echo ""
read -p "Enter your choice: " choice
if [[ "$choice" == "q" || "$choice" == "Q" ]]; then
echo -e "\n${GREEN}Goodbye!${NC}"
exit 0
fi
if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#categories[@]} )); then
SELECTED_CATEGORY="${categories[$((choice-1))]}"
return 0
else
echo -e "${RED}Invalid choice. Please try again.${NC}"
sleep 1
select_category
fi
}
# Function to display agent selection menu with multi-select
select_agents() {
local category="$1"
local category_name=$(get_category_name "$category")
# Build list of agents (excluding README.md)
local agents=()
local agent_states=()
if [[ "$SOURCE_MODE" == "remote" ]]; then
# Remote mode: fetch from GitHub API
show_header
echo -e "${BOLD}Category: ${CYAN}$category_name${NC}\n"
echo -e "${CYAN}Fetching agents from GitHub...${NC}\n"
if ! fetch_agents_remote "$category"; then
echo -e "${RED}Failed to fetch agents. Press Enter to go back.${NC}"
read
return 1
fi
for agent_file in "${REMOTE_AGENTS[@]}"; do
agents+=("$agent_file")
# Check if installed (by filename)
if [[ -f "$CLAUDE_AGENTS_DIR/$agent_file" ]]; then
agent_states+=(1)
else
agent_states+=(0)
fi
done
else
# Local mode: read from filesystem
local category_path="$CATEGORIES_DIR/$category"
for agent_file in "$category_path"/*.md; do
local basename=$(basename "$agent_file")
if [[ "$basename" != "README.md" ]]; then
agents+=("$basename")
if [[ -f "$CLAUDE_AGENTS_DIR/$basename" ]]; then
agent_states+=(1)
else
agent_states+=(0)
fi
fi
done
fi
# Store original states to calculate changes
local original_states=("${agent_states[@]}")
while true; do
show_header
echo -e "${BOLD}Category: ${CYAN}$category_name${NC}\n"
echo -e "Use number keys to toggle selection. ${GREEN}[✓]${NC} = will be installed, ${RED}[ ]${NC} = will be removed\n"
local i=1
for agent_file in "${agents[@]}"; do
local agent_name="${agent_file%.md}"
local is_installed=""
local status_icon=""
local status_color=""
if [[ -f "$CLAUDE_AGENTS_DIR/$agent_file" ]]; then
is_installed=" ${BLUE}(installed)${NC}"
fi
if [[ ${agent_states[$((i-1))]} -eq 1 ]]; then
status_icon="[✓]"
status_color="${GREEN}"
else
status_icon="[ ]"
status_color="${RED}"
fi
echo -e " ${YELLOW}$i)${NC} ${status_color}${status_icon}${NC} $agent_name$is_installed"
((i++))
done
echo ""
echo -e " ${YELLOW}a)${NC} Select all"
echo -e " ${YELLOW}n)${NC} Deselect all"
echo -e " ${YELLOW}c)${NC} Confirm selection"
echo -e " ${YELLOW}b)${NC} Back to categories"
echo -e " ${YELLOW}q)${NC} Quit"
echo ""
read -p "Enter your choice: " choice
case "$choice" in
[0-9]*)
if (( choice >= 1 && choice <= ${#agents[@]} )); then
# Toggle selection
local idx=$((choice-1))
if [[ ${agent_states[$idx]} -eq 1 ]]; then
agent_states[$idx]=0
else
agent_states[$idx]=1
fi
fi
;;
a|A)
for i in "${!agent_states[@]}"; do
agent_states[$i]=1
done
;;
n|N)
for i in "${!agent_states[@]}"; do
agent_states[$i]=0
done
;;
c|C)
# Calculate changes
local to_install=()
local to_uninstall=()
for i in "${!agents[@]}"; do
local agent_file="${agents[$i]}"
local is_selected=${agent_states[$i]}
# Check if currently installed
local was_installed=0
if [[ -f "$CLAUDE_AGENTS_DIR/$agent_file" ]]; then
was_installed=1
fi
if [[ $was_installed -eq 0 && $is_selected -eq 1 ]]; then
to_install+=("$agent_file")
elif [[ $was_installed -eq 1 && $is_selected -eq 0 ]]; then
to_uninstall+=("$agent_file")
fi
done
confirm_and_apply "$category" "${to_install[*]}" "${to_uninstall[*]}"
return
;;
b|B)
return 1
;;
q|Q)
echo -e "\n${GREEN}Goodbye!${NC}"
exit 0
;;
esac
done
}
# Function to confirm and apply changes
confirm_and_apply() {
local category="$1"
local install_list="$2"
local uninstall_list="$3"
# Convert space-separated strings back to arrays
IFS=' ' read -ra to_install <<< "$install_list"
IFS=' ' read -ra to_uninstall <<< "$uninstall_list"
# Filter out empty entries
local install_count=0
local uninstall_count=0
for item in "${to_install[@]}"; do
[[ -n "$item" ]] && ((install_count++))
done
for item in "${to_uninstall[@]}"; do
[[ -n "$item" ]] && ((uninstall_count++))
done
show_header
echo -e "${BOLD}Confirmation${NC}\n"
if [[ $install_count -eq 0 && $uninstall_count -eq 0 ]]; then
echo -e "${YELLOW}No changes to apply.${NC}"
echo ""
read -p "Press Enter to continue..."
return
fi
if [[ $install_count -gt 0 ]]; then
echo -e "${GREEN}Agents to install ($install_count):${NC}"
for agent_file in "${to_install[@]}"; do
if [[ -n "$agent_file" ]]; then
echo -e " ${GREEN}+${NC} ${agent_file%.md}"
fi
done
echo ""
fi
if [[ $uninstall_count -gt 0 ]]; then
echo -e "${RED}Agents to uninstall ($uninstall_count):${NC}"
for agent_file in "${to_uninstall[@]}"; do
if [[ -n "$agent_file" ]]; then
echo -e " ${RED}-${NC} ${agent_file%.md}"
fi
done
echo ""
fi
echo -e "${BOLD}Summary:${NC} ${GREEN}$install_count to install${NC}, ${RED}$uninstall_count to uninstall${NC}"
echo ""
read -p "Apply these changes? (y/N): " confirm
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
echo ""
# Perform installations
for agent_file in "${to_install[@]}"; do
if [[ -n "$agent_file" ]]; then
if [[ "$SOURCE_MODE" == "remote" ]]; then
# Download from GitHub
echo -e "${CYAN}Downloading $agent_file...${NC}"
if download_agent "$category" "$agent_file" "$CLAUDE_AGENTS_DIR/$agent_file"; then
echo -e "${GREEN}✓${NC} Installed: $agent_file"
else
echo -e "${RED}✗${NC} Failed to download: $agent_file"
fi
else
# Copy from local
local source_path="$CATEGORIES_DIR/$category/$agent_file"
if [[ -f "$source_path" ]]; then
cp "$source_path" "$CLAUDE_AGENTS_DIR/$agent_file"
echo -e "${GREEN}✓${NC} Installed: $agent_file"
fi
fi
fi
done
# Perform uninstallations
for agent_file in "${to_uninstall[@]}"; do
if [[ -n "$agent_file" ]]; then
if [[ -f "$CLAUDE_AGENTS_DIR/$agent_file" ]]; then
rm "$CLAUDE_AGENTS_DIR/$agent_file"
echo -e "${RED}✓${NC} Uninstalled: $agent_file"
fi
fi
done
echo ""
echo -e "${GREEN}${BOLD}Changes applied successfully!${NC}"
else
echo -e "${YELLOW}Changes cancelled.${NC}"
fi
echo ""
read -p "Press Enter to continue..."
}
# Main loop
main() {
select_install_mode
select_source_mode
while true; do
select_category
while select_agents "$SELECTED_CATEGORY"; do
:
done
done
}
# Run main function
main