-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·501 lines (427 loc) · 14 KB
/
install.sh
File metadata and controls
executable file
·501 lines (427 loc) · 14 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
#!/bin/bash
# Spellbook Installer
# https://github.com/majiayu000/spellbook
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Config
REPO_URL="${SPELLBOOK_REPO_URL:-https://github.com/majiayu000/spellbook.git}"
LEGACY_REPO_URL="https://github.com/majiayu000/claude-arsenal.git"
CLAUDE_DIR="$HOME/.claude"
CODEX_DIR="$HOME/.codex"
CLAUDE_SKILLS_DIR="$CLAUDE_DIR/skills"
CLAUDE_AGENTS_DIR="$CLAUDE_DIR/agents"
CODEX_SKILLS_DIR="$CODEX_DIR/skills"
INSTALL_DIR="$HOME/.spellbook"
LEGACY_INSTALL_DIR="$HOME/.claude-arsenal"
TARGET="claude"
# Print banner
print_banner() {
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ Spellbook Installer ║"
echo "║ 83 Skills | 7 Agents | Claude + Codex Ready ║"
echo "║ ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
# Print colored message
info() { echo -e "${BLUE}[INFO]${NC} $1"; }
success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
# Check prerequisites
check_prerequisites() {
info "Checking prerequisites..."
if ! command -v git &> /dev/null; then
error "Git is not installed. Please install git first."
fi
success "Prerequisites check passed"
}
# Clone or update repository
setup_repo() {
info "Setting up Spellbook repository..."
if [ -d "$INSTALL_DIR" ]; then
info "Updating existing installation..."
cd "$INSTALL_DIR"
git pull --quiet
elif [ -d "$LEGACY_INSTALL_DIR" ]; then
info "Migrating existing Claude Arsenal checkout..."
mv "$LEGACY_INSTALL_DIR" "$INSTALL_DIR"
cd "$INSTALL_DIR"
git remote set-url origin "$REPO_URL" 2>/dev/null || true
git pull --quiet || git pull --quiet "$LEGACY_REPO_URL" main
else
info "Cloning repository..."
if ! git clone --quiet "$REPO_URL" "$INSTALL_DIR"; then
warn "Primary Spellbook URL unavailable; falling back to legacy Claude Arsenal URL"
git clone --quiet "$LEGACY_REPO_URL" "$INSTALL_DIR"
fi
fi
success "Repository ready at $INSTALL_DIR"
}
# Target helpers
target_includes_claude() {
[ "$TARGET" = "claude" ] || [ "$TARGET" = "all" ]
}
target_includes_codex() {
[ "$TARGET" = "codex" ] || [ "$TARGET" = "all" ]
}
validate_target() {
case "$TARGET" in
claude|codex|all) ;;
*) error "Invalid target: $TARGET (expected claude, codex, or all)" ;;
esac
}
# Create target directories
setup_directories() {
info "Setting up target directories for: $TARGET"
if target_includes_claude; then
mkdir -p "$CLAUDE_SKILLS_DIR"
mkdir -p "$CLAUDE_AGENTS_DIR"
fi
if target_includes_codex; then
mkdir -p "$CODEX_SKILLS_DIR"
fi
success "Directories created"
}
list_installable_skill_names() {
for skill_dir in "$INSTALL_DIR/skills"/*/; do
if [ -f "$skill_dir/SKILL.md" ]; then
basename "${skill_dir%/}"
fi
done
for skill_file in "$INSTALL_DIR/skills"/*.SKILL.md; do
if [ -f "$skill_file" ]; then
basename "$skill_file" .SKILL.md
fi
done
}
check_skill_conflicts() {
local duplicates
duplicates=$(list_installable_skill_names | sort | uniq -d)
if [ -n "$duplicates" ]; then
error "Duplicate skill install names found. Resolve these before installing:\n$duplicates"
fi
}
validate_registry() {
if [ ! -f "$INSTALL_DIR/scripts/validate_skills.py" ]; then
warn "Skill validator not found; skipping registry validation"
return
fi
if ! command -v python3 &> /dev/null; then
error "python3 is required for skill registry validation."
fi
python3 "$INSTALL_DIR/scripts/validate_skills.py" --check
}
is_managed_path() {
local path="$1"
[[ "$path" == *"claude-arsenal"* ]] || [[ "$path" == *"spellbook"* ]]
}
prepare_directory_skill_target() {
local skills_dir="$1"
local skill_name="$2"
local target="$skills_dir/$skill_name"
if [ -L "$target" ]; then
rm -f "$target"
elif [ -d "$target" ] && [ -L "$target/SKILL.md" ]; then
local linked_skill
linked_skill=$(readlink "$target/SKILL.md" 2>/dev/null || true)
if is_managed_path "$linked_skill"; then
rm -rf "$target"
fi
fi
}
prepare_file_skill_target() {
local skills_dir="$1"
local skill_name="$2"
local target="$skills_dir/$skill_name"
if [ -L "$target" ]; then
rm -f "$target"
fi
mkdir -p "$target"
}
# Install all skills into one runtime target
install_all_skills_to_dir() {
local skills_dir="$1"
local runtime_name="$2"
info "Installing all skills for $runtime_name..."
local count=0
# Install directory-based skills
for skill_dir in "$INSTALL_DIR/skills"/*/; do
if [ -f "$skill_dir/SKILL.md" ]; then
skill_name=$(basename "$skill_dir")
prepare_directory_skill_target "$skills_dir" "$skill_name"
ln -sfn "$skill_dir" "$skills_dir/$skill_name"
count=$((count + 1))
fi
done
# Install file-based skills (.SKILL.md files)
for skill_file in "$INSTALL_DIR/skills"/*.SKILL.md; do
if [ -f "$skill_file" ]; then
skill_name=$(basename "$skill_file" .SKILL.md)
prepare_file_skill_target "$skills_dir" "$skill_name"
ln -sfn "$skill_file" "$skills_dir/$skill_name/SKILL.md"
count=$((count + 1))
fi
done
success "Installed $count skills for $runtime_name"
}
# Install all skills
install_all_skills() {
if target_includes_claude; then
install_all_skills_to_dir "$CLAUDE_SKILLS_DIR" "Claude Code"
fi
if target_includes_codex; then
install_all_skills_to_dir "$CODEX_SKILLS_DIR" "Codex"
fi
}
# Install specific skills into one runtime target
install_skills_to_dir() {
local skills_dir="$1"
local runtime_name="$2"
local skills_list="$3"
info "Installing selected skills for $runtime_name: $skills_list"
IFS=',' read -ra SKILLS <<< "$skills_list"
local count=0
for skill in "${SKILLS[@]}"; do
skill=$(echo "$skill" | xargs) # trim whitespace
# Check if directory-based skill
if [ -f "$INSTALL_DIR/skills/$skill/SKILL.md" ]; then
prepare_directory_skill_target "$skills_dir" "$skill"
ln -sfn "$INSTALL_DIR/skills/$skill" "$skills_dir/$skill"
count=$((count + 1))
info " ✓ $skill"
# Check if file-based skill
elif [ -f "$INSTALL_DIR/skills/$skill.SKILL.md" ]; then
prepare_file_skill_target "$skills_dir" "$skill"
ln -sfn "$INSTALL_DIR/skills/$skill.SKILL.md" "$skills_dir/$skill/SKILL.md"
count=$((count + 1))
info " ✓ $skill"
else
warn " ✗ $skill (not found)"
fi
done
success "Installed $count skills for $runtime_name"
}
# Install specific skills
install_skills() {
local skills_list="$1"
if target_includes_claude; then
install_skills_to_dir "$CLAUDE_SKILLS_DIR" "Claude Code" "$skills_list"
fi
if target_includes_codex; then
install_skills_to_dir "$CODEX_SKILLS_DIR" "Codex" "$skills_list"
fi
}
# Install all agents
install_agents() {
info "Installing agents..."
local count=0
for agent_file in "$INSTALL_DIR/agents"/*.md; do
if [ -f "$agent_file" ]; then
agent_name=$(basename "$agent_file")
ln -sfn "$agent_file" "$CLAUDE_AGENTS_DIR/$agent_name"
count=$((count + 1))
fi
done
success "Installed $count agents"
}
# List available skills
list_skills() {
echo -e "\n${BLUE}Available Skills:${NC}\n"
echo "Directory-based skills:"
for skill_dir in "$INSTALL_DIR/skills"/*/; do
if [ -f "$skill_dir/SKILL.md" ]; then
echo " - $(basename "$skill_dir")"
fi
done
echo -e "\nFile-based skills:"
for skill_file in "$INSTALL_DIR/skills"/*.SKILL.md; do
if [ -f "$skill_file" ]; then
echo " - $(basename "$skill_file" .SKILL.md)"
fi
done
}
# Uninstall
uninstall_from_skills_dir() {
local skills_dir="$1"
for skill_path in "$skills_dir"/*; do
[ -e "$skill_path" ] || continue
if [ -L "$skill_path" ]; then
target=$(readlink -f "$skill_path" 2>/dev/null || readlink "$skill_path" 2>/dev/null)
if is_managed_path "$target"; then
rm -f "$skill_path"
fi
elif [ -d "$skill_path" ] && [ -L "$skill_path/SKILL.md" ]; then
target=$(readlink -f "$skill_path/SKILL.md" 2>/dev/null || readlink "$skill_path/SKILL.md" 2>/dev/null)
if is_managed_path "$target"; then
rm -rf "$skill_path"
fi
fi
done
}
uninstall() {
warn "Uninstalling Spellbook..."
if target_includes_claude; then
uninstall_from_skills_dir "$CLAUDE_SKILLS_DIR"
for agent_file in "$CLAUDE_AGENTS_DIR"/*.md; do
if [ -L "$agent_file" ]; then
target=$(readlink -f "$agent_file" 2>/dev/null || readlink "$agent_file" 2>/dev/null)
if is_managed_path "$target"; then
rm -f "$agent_file"
fi
fi
done
fi
if target_includes_codex; then
uninstall_from_skills_dir "$CODEX_SKILLS_DIR"
fi
if [ "$TARGET" = "all" ]; then
rm -rf "$INSTALL_DIR"
rm -rf "$LEGACY_INSTALL_DIR"
else
warn "Leaving shared source checkout at $INSTALL_DIR; use --target all --uninstall to remove it"
fi
success "Spellbook uninstalled for target: $TARGET"
}
# Print usage
usage() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --target TARGET Install target: claude, codex, or all (default: claude)"
echo " --all Install all skills and supported agents"
echo " --skills SKILL_LIST Install specific skills (comma-separated)"
echo " --agents Install only Claude Code agents"
echo " --list List available skills"
echo " --validate Validate skill registry and metadata"
echo " --uninstall Remove Spellbook symlinks for the selected target"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " $0 --target all --all"
echo " $0 --target codex --skills typescript-project,python-project"
echo " $0 --list"
}
parse_args() {
POSITIONAL=()
while [ $# -gt 0 ]; do
case "$1" in
--target)
if [ -z "${2:-}" ]; then
error "Please provide a target: claude, codex, or all"
fi
TARGET="$2"
shift 2
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
PARSED_ARGS=("$@")
}
install_supported_agents() {
if target_includes_claude; then
install_agents
elif [ "$TARGET" = "codex" ]; then
warn "Agents are Claude Code-specific; skipping agents for Codex target"
fi
}
# Main
main() {
parse_args "$@"
set -- "${PARSED_ARGS[@]}"
print_banner
validate_target
if [ $# -eq 0 ]; then
check_prerequisites
setup_repo
check_skill_conflicts
validate_registry
setup_directories
install_all_skills
install_supported_agents
else
case "$1" in
--all)
check_prerequisites
setup_repo
check_skill_conflicts
validate_registry
setup_directories
install_all_skills
install_supported_agents
;;
--skills)
if [ -z "${2:-}" ]; then
error "Please provide a comma-separated list of skills"
fi
check_prerequisites
setup_repo
check_skill_conflicts
validate_registry
setup_directories
install_skills "$2"
;;
--agents)
check_prerequisites
setup_repo
setup_directories
install_supported_agents
;;
--list)
setup_repo
check_skill_conflicts
list_skills
exit 0
;;
--validate)
setup_repo
check_skill_conflicts
validate_registry
exit 0
;;
--uninstall)
uninstall
exit 0
;;
--help|-h)
usage
exit 0
;;
*)
error "Unknown option: $1\nRun '$0 --help' for usage."
;;
esac
fi
echo ""
success "Installation complete!"
echo ""
info "Next steps:"
if target_includes_claude; then
echo " - Claude Code: type '/' to see installed skills"
fi
if target_includes_codex; then
echo " - Codex: restart Codex so it reloads ~/.codex/skills"
fi
echo " - Start using skills like /typescript-project"
echo ""
info "Installation directory: $INSTALL_DIR"
if target_includes_claude; then
info "Claude skills directory: $CLAUDE_SKILLS_DIR"
fi
if target_includes_codex; then
info "Codex skills directory: $CODEX_SKILLS_DIR"
fi
echo ""
}
main "$@"