forked from akaszubski/autonomous-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1416 lines (1203 loc) · 47.6 KB
/
install.sh
File metadata and controls
executable file
·1416 lines (1203 loc) · 47.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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# autonomous-dev Plugin Installer - PRIMARY INSTALL METHOD
#
# Bootstrap-First Architecture: This is the REQUIRED install method for autonomous-dev.
# The marketplace alone is insufficient because it cannot configure global infrastructure.
# autonomous-dev is a development system, not a simple plugin.
#
# Usage:
# bash <(curl -sSL https://raw.githubusercontent.com/akaszubski/autonomous-dev/master/install.sh)
#
# What this does (that the marketplace cannot):
# 1. Creates global infrastructure:
# - ~/.claude/hooks/ (security validation, auto-approval)
# - ~/.claude/lib/ (Python dependencies)
# - ~/.claude/settings.json (permission patterns)
# 2. Downloads plugin files to ~/.autonomous-dev-staging/
# 3. Installs /setup command to .claude/commands/
# 4. You restart Claude Code and run /setup
# 5. /setup wizard intelligently handles:
# - Fresh installs (copies all files, guides PROJECT.md creation)
# - Brownfield (preserves existing .claude/ files)
# - Upgrades (updates plugin, preserves customizations)
#
# Why not marketplace alone?
# The marketplace can download files but CANNOT:
# - Create directories in ~/.claude/
# - Modify ~/.claude/settings.json
# - Install global hooks for all projects
# - Configure Bash tool permissions
#
# The marketplace is useful as an OPTIONAL supplement for updates after
# this script has run at least once.
#
# Requirements:
# - curl or wget
# - Python 3.9+
# - Claude Code installed
#
# Security:
# - HTTPS with TLS 1.2+
# - No sudo required
#
set -euo pipefail
# 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
# Configuration
GITHUB_REPO="akaszubski/autonomous-dev"
GITHUB_BRANCH="master"
GITHUB_RAW="https://raw.githubusercontent.com/${GITHUB_REPO}/${GITHUB_BRANCH}"
STAGING_DIR="${HOME}/.autonomous-dev-staging"
MANIFEST_FILE="plugins/autonomous-dev/config/install_manifest.json"
# Parse arguments
VERBOSE=false
CLEAN=false
while [[ $# -gt 0 ]]; do
case $1 in
--verbose|-v)
VERBOSE=true
shift
;;
--clean)
CLEAN=true
shift
;;
--help|-h)
echo "autonomous-dev Plugin Installer"
echo ""
echo "One-liner install for both fresh installs and updates."
echo ""
echo "Usage: install.sh [OPTIONS]"
echo ""
echo "Options:"
echo " --verbose, -v Show detailed output"
echo " --clean Remove existing staging directory first"
echo " --help, -h Show this help message"
echo ""
echo "After running this script:"
echo " 1. Restart Claude Code (Cmd+Q / Ctrl+Q)"
echo " 2. Run /setup in your project"
echo ""
echo "The /setup wizard will:"
echo " - Detect fresh install vs update"
echo " - Install all plugin files"
echo " - Protect your PROJECT.md and .env"
echo " - Guide you through configuration"
exit 0
;;
*)
echo -e "${RED}Unknown option: $1${NC}"
echo "Use --help for usage information"
exit 1
;;
esac
done
# Logging functions
log_info() {
echo -e "${BLUE}ℹ${NC} $1"
}
log_success() {
echo -e "${GREEN}✓${NC} $1"
}
log_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
log_error() {
echo -e "${RED}✗${NC} $1"
}
log_step() {
echo -e "${CYAN}→${NC} $1"
}
# Check for curl or wget
check_downloader() {
if command -v curl &> /dev/null; then
DOWNLOADER="curl"
elif command -v wget &> /dev/null; then
DOWNLOADER="wget"
else
log_error "Neither curl nor wget found. Please install one of them."
exit 1
fi
if $VERBOSE; then
log_info "Using ${DOWNLOADER} for downloads"
fi
}
# Download file from GitHub
download_file() {
local url="$1"
local output="$2"
# Create parent directory if needed
mkdir -p "$(dirname "$output")"
if [[ "$DOWNLOADER" == "curl" ]]; then
curl --proto '=https' --tlsv1.2 -sSL "$url" -o "$output" 2>/dev/null
else
wget --secure-protocol=TLSv1_2 -qO "$output" "$url" 2>/dev/null
fi
}
# Download manifest and parse file list
download_manifest() {
log_step "Downloading manifest..."
local manifest_url="${GITHUB_RAW}/${MANIFEST_FILE}"
local manifest_path="${STAGING_DIR}/manifest.json"
if ! download_file "$manifest_url" "$manifest_path"; then
log_error "Failed to download manifest"
log_info "URL: ${manifest_url}"
return 1
fi
# Verify it's valid JSON
if ! python3 -c "import json; json.load(open('${manifest_path}'))" 2>/dev/null; then
log_error "Invalid manifest (not valid JSON)"
return 1
fi
log_success "Manifest downloaded"
return 0
}
# Download all files from manifest
download_files() {
log_step "Downloading plugin files..."
local manifest_path="${STAGING_DIR}/manifest.json"
local total_files=0
local downloaded=0
local failed=0
# Use Python to parse manifest and get file list (with path traversal validation)
local files
files=$(python3 -c "
import json
import sys
with open('${manifest_path}') as f:
manifest = json.load(f)
for component, config in manifest.get('components', {}).items():
for file_path in config.get('files', []):
# CWE-22: Validate paths to prevent directory traversal
if '..' in file_path or file_path.startswith('/') or file_path.startswith('~'):
print(f'SECURITY: Rejected malicious path: {file_path}', file=sys.stderr)
continue
# Reject paths with null bytes or other suspicious patterns
if '\x00' in file_path or '\\\\' in file_path:
print(f'SECURITY: Rejected suspicious path: {file_path}', file=sys.stderr)
continue
print(file_path)
")
# Count total files
total_files=$(echo "$files" | wc -l | tr -d ' ')
log_info "Found ${total_files} files to download"
# Download each file
while IFS= read -r file_path; do
if [[ -z "$file_path" ]]; then
continue
fi
local url="${GITHUB_RAW}/${file_path}"
local output="${STAGING_DIR}/files/${file_path}"
if download_file "$url" "$output"; then
((downloaded++))
if $VERBOSE; then
log_success " Downloaded: $(basename "$file_path")"
fi
else
((failed++))
log_warning " Failed: $(basename "$file_path")"
fi
# Progress indicator (every 20 files)
if ! $VERBOSE && (( downloaded % 20 == 0 )); then
echo -ne "\r${CYAN}→${NC} Downloaded ${downloaded}/${total_files} files..."
fi
done <<< "$files"
if ! $VERBOSE; then
echo "" # New line after progress
fi
if [[ $failed -gt 0 ]]; then
log_warning "Downloaded ${downloaded}/${total_files} files (${failed} failed)"
return 1
fi
log_success "Downloaded ${downloaded} files"
return 0
}
# Also download VERSION file
download_version() {
local version_url="${GITHUB_RAW}/plugins/autonomous-dev/VERSION"
local version_path="${STAGING_DIR}/VERSION"
if download_file "$version_url" "$version_path"; then
local version
version=$(cat "$version_path")
log_info "Plugin version: ${version}"
fi
}
# Bootstrap the /setup command directly (enables fresh installs)
bootstrap_setup_command() {
log_step "Bootstrapping /setup command..."
local setup_source="${STAGING_DIR}/files/plugins/autonomous-dev/commands/setup.md"
local setup_target=".claude/commands/setup.md"
# Check if setup.md was downloaded
if [[ ! -f "$setup_source" ]]; then
log_warning "setup.md not found in staging - /setup command won't be available"
return 1
fi
# CWE-73: Check if source is a symlink (security protection)
if [[ -L "$setup_source" ]]; then
log_warning "Security: setup.md is a symlink - skipping for safety"
return 1
fi
# Create .claude/commands/ directory if needed (with error handling)
if ! mkdir -p ".claude/commands" 2>/dev/null; then
log_warning "Failed to create .claude/commands/ directory (permission denied?)"
return 1
fi
# Backup existing file if present
if [[ -f "$setup_target" ]]; then
cp "$setup_target" "${setup_target}.backup" 2>/dev/null || true
fi
# Copy setup.md to enable /setup command (use -P to not follow symlinks)
if cp -P "$setup_source" "$setup_target"; then
return 0
else
log_warning "Failed to copy setup.md to .claude/commands/"
return 1
fi
}
# Configure global settings.json with correct permission patterns
configure_global_settings() {
log_step "Configuring global settings..."
local template_path="${STAGING_DIR}/files/plugins/autonomous-dev/config/global_settings_template.json"
local script_path="${STAGING_DIR}/files/plugins/autonomous-dev/scripts/configure_global_settings.py"
local home_path="${HOME}/.claude"
# Check if template was downloaded
if [[ ! -f "$template_path" ]]; then
log_warning "Template not found - skipping settings configuration"
return 1
fi
# Check if script was downloaded
if [[ ! -f "$script_path" ]]; then
log_warning "Configure script not found - skipping settings configuration"
return 1
fi
# Run configuration script (always exits 0, check JSON output)
local result
result=$(python3 "$script_path" --template "$template_path" --home "$home_path" 2>&1)
# Parse result JSON
local success
success=$(echo "$result" | python3 -c "import json, sys; data=json.load(sys.stdin); print('true' if data.get('success') else 'false')" 2>/dev/null || echo "false")
if [[ "$success" == "true" ]]; then
local created
created=$(echo "$result" | python3 -c "import json, sys; data=json.load(sys.stdin); print('true' if data.get('created') else 'false')" 2>/dev/null || echo "false")
if [[ "$created" == "true" ]]; then
log_success "Created ~/.claude/settings.json from template"
else
log_success "Updated ~/.claude/settings.json (preserved customizations)"
fi
return 0
else
local error_msg
error_msg=$(echo "$result" | python3 -c "import json, sys; data=json.load(sys.stdin); print(data.get('message', 'Unknown error'))" 2>/dev/null || echo "Configuration failed")
log_warning "Settings configuration: ${error_msg}"
return 1
fi
}
# Migrate hooks from array format to object format (Claude Code 2.0)
# Issue #156: Users with old settings.json need hooks migrated
migrate_hooks_format() {
log_step "Checking hooks format..."
local lib_path="${STAGING_DIR}/files/plugins/autonomous-dev/lib"
local settings_path="${HOME}/.claude/settings.json"
# Check if settings.json exists
if [[ ! -f "$settings_path" ]]; then
log_info "No settings.json found - skipping hooks migration"
return 0
fi
# Check if hook_activator.py was downloaded
if [[ ! -f "${lib_path}/hook_activator.py" ]]; then
log_warning "hook_activator.py not found - skipping hooks migration"
return 1
fi
# Run migration (Python one-liner to call the function)
local result
result=$(PYTHONPATH="${lib_path}:${lib_path}/.." python3 -c "
import sys
sys.path.insert(0, '${STAGING_DIR}/files/plugins/autonomous-dev/lib')
sys.path.insert(0, '${STAGING_DIR}/files/plugins')
from pathlib import Path
try:
from hook_activator import migrate_hooks_to_object_format
result = migrate_hooks_to_object_format(Path('${settings_path}'))
import json
print(json.dumps(result, default=str))
except Exception as e:
import json
print(json.dumps({'migrated': False, 'error': str(e)}))
" 2>&1)
# Parse result
local migrated
migrated=$(echo "$result" | python3 -c "import json, sys; data=json.load(sys.stdin); print('true' if data.get('migrated') else 'false')" 2>/dev/null || echo "false")
if [[ "$migrated" == "true" ]]; then
log_success "Migrated hooks to Claude Code 2.0 format"
return 0
else
local format_type
format_type=$(echo "$result" | python3 -c "import json, sys; data=json.load(sys.stdin); print(data.get('format', 'unknown'))" 2>/dev/null || echo "unknown")
if [[ "$format_type" == "object" ]]; then
log_info "Hooks already in correct format"
return 0
elif [[ "$format_type" == "missing" ]]; then
log_info "No hooks to migrate"
return 0
else
local error_msg
error_msg=$(echo "$result" | python3 -c "import json, sys; data=json.load(sys.stdin); print(data.get('error', 'Unknown'))" 2>/dev/null || echo "Unknown")
log_warning "Hooks migration: ${error_msg}"
return 1
fi
fi
}
# Clean orphan files from a directory based on manifest
# Usage: clean_orphan_files <target_dir> <component_name> <file_extension>
clean_orphan_files() {
local target_dir="$1"
local component_name="$2"
local file_ext="$3"
local manifest_path="${STAGING_DIR}/manifest.json"
local cleaned=0
# Skip if target directory doesn't exist
if [[ ! -d "$target_dir" ]]; then
return 0
fi
# Get expected files from manifest
local expected_files
expected_files=$(python3 -c "
import json
import sys
from pathlib import Path
with open('${manifest_path}') as f:
manifest = json.load(f)
component = manifest.get('components', {}).get('${component_name}', {})
for file_path in component.get('files', []):
print(Path(file_path).name)
" 2>/dev/null)
if [[ -z "$expected_files" ]]; then
return 0
fi
# Find and remove orphan files (files in target but not in manifest)
while IFS= read -r actual_file; do
if [[ -z "$actual_file" ]]; then
continue
fi
local file_name
file_name=$(basename "$actual_file")
# Skip __init__.py and __pycache__
if [[ "$file_name" == "__init__.py" ]] || [[ "$file_name" == "__pycache__" ]]; then
continue
fi
# Check if file is in expected list
if ! echo "$expected_files" | grep -qx "$file_name"; then
# File is orphan - remove it
if rm "$actual_file" 2>/dev/null; then
((cleaned++))
if $VERBOSE; then
log_warning " Removed orphan: $file_name"
fi
fi
fi
done < <(find "$target_dir" -maxdepth 1 -type f -name "*${file_ext}" 2>/dev/null)
if [[ $cleaned -gt 0 ]]; then
log_info "Cleaned ${cleaned} orphan ${component_name} file(s)"
fi
return 0
}
# Install hook files to ~/.claude/hooks/
install_hook_files() {
log_step "Installing hook files to ~/.claude/hooks/..."
# Clean orphan hooks first (TRUE SYNC - remove files not in manifest)
clean_orphan_files "${HOME}/.claude/hooks" "hooks" ".py"
local hook_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/hooks"
local hook_target_dir="${HOME}/.claude/hooks"
local installed=0
local failed=0
# Check if hook source directory exists
if [[ ! -d "$hook_source_dir" ]]; then
log_warning "Hooks directory not found in staging - hook files won't be installed"
return 1
fi
# Create target directory if it doesn't exist
if ! mkdir -p "$hook_target_dir" 2>/dev/null; then
log_error "Failed to create ~/.claude/hooks/ directory (permission denied?)"
return 1
fi
# Get list of .py files from hooks directory
local hook_files
hook_files=$(find "$hook_source_dir" -maxdepth 1 -type f -name "*.py")
if [[ -z "$hook_files" ]]; then
log_info "No hook files found to install"
return 0
fi
# Count total files
local total_files
total_files=$(echo "$hook_files" | wc -l | tr -d ' ')
log_info "Found ${total_files} hook files to install"
# Copy each hook file
while IFS= read -r hook_file; do
if [[ -z "$hook_file" ]]; then
continue
fi
local file_name
file_name=$(basename "$hook_file")
# Security: Check if file is a symlink
if [[ -L "$hook_file" ]]; then
log_warning " Skipping symlink: $file_name"
((failed++))
continue
fi
# Copy file to target directory (use -P to not follow symlinks)
if cp -P "$hook_file" "$hook_target_dir/$file_name"; then
((installed++))
if $VERBOSE; then
log_success " Installed: $file_name"
fi
else
((failed++))
log_warning " Failed: $file_name"
fi
done <<< "$hook_files"
# Report results
if [[ $failed -gt 0 ]]; then
log_warning "Installed ${installed}/${total_files} hook files (${failed} failed)"
return 1
fi
log_success "Installed ${installed} hook file(s) to ~/.claude/hooks/"
return 0
}
# Install core commands globally to ~/.claude/commands/ (sync.md, setup.md)
# These commands must be available in ALL repos for bootstrapping
install_global_commands() {
log_step "Installing core commands to ~/.claude/commands/..."
local command_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/commands"
local command_target_dir="${HOME}/.claude/commands"
local installed=0
local failed=0
# Core commands that must be available globally for bootstrapping
local core_commands=("sync.md" "setup.md" "health-check.md")
# Check if command source directory exists
if [[ ! -d "$command_source_dir" ]]; then
log_warning "Commands directory not found in staging - global commands won't be installed"
return 1
fi
# Create target directory if it doesn't exist
if ! mkdir -p "$command_target_dir" 2>/dev/null; then
log_error "Failed to create ~/.claude/commands/ directory (permission denied?)"
return 1
fi
# Install each core command
for cmd in "${core_commands[@]}"; do
local source_file="$command_source_dir/$cmd"
local target_file="$command_target_dir/$cmd"
if [[ ! -f "$source_file" ]]; then
log_warning " Not found in staging: $cmd"
((failed++))
continue
fi
# Security: Check if file is a symlink
if [[ -L "$source_file" ]]; then
log_warning " Skipping symlink: $cmd"
((failed++))
continue
fi
# Copy file to target directory
if cp -P "$source_file" "$target_file"; then
((installed++))
if $VERBOSE; then
log_success " Installed globally: $cmd"
fi
else
((failed++))
log_warning " Failed: $cmd"
fi
done
# Report results
if [[ $failed -gt 0 ]]; then
log_warning "Installed ${installed}/${#core_commands[@]} core commands globally (${failed} failed)"
return 1
fi
log_success "Installed ${installed} core command(s) to ~/.claude/commands/"
return 0
}
# Install lib files to ~/.claude/lib/
install_lib_files() {
log_step "Installing lib files to ~/.claude/lib/..."
# Clean orphan libs first (TRUE SYNC - remove files not in manifest)
clean_orphan_files "${HOME}/.claude/lib" "lib" ".py"
local lib_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/lib"
local lib_target_dir="${HOME}/.claude/lib"
local installed=0
local failed=0
# Check if lib source directory exists
if [[ ! -d "$lib_source_dir" ]]; then
log_warning "Lib directory not found in staging - lib files won't be installed"
return 1
fi
# Create target directory if it doesn't exist
if ! mkdir -p "$lib_target_dir" 2>/dev/null; then
log_error "Failed to create ~/.claude/lib/ directory (permission denied?)"
return 1
fi
# Get list of .py files from lib directory
local lib_files
lib_files=$(find "$lib_source_dir" -maxdepth 1 -type f -name "*.py" ! -name "__init__.py")
if [[ -z "$lib_files" ]]; then
log_info "No lib files found to install"
return 0
fi
# Count total files
local total_files
total_files=$(echo "$lib_files" | wc -l | tr -d ' ')
log_info "Found ${total_files} lib files to install"
# Copy each lib file
while IFS= read -r lib_file; do
if [[ -z "$lib_file" ]]; then
continue
fi
local file_name
file_name=$(basename "$lib_file")
# Security: Check if file is a symlink
if [[ -L "$lib_file" ]]; then
log_warning " Skipping symlink: $file_name"
((failed++))
continue
fi
# Copy file to target directory (use -P to not follow symlinks)
if cp -P "$lib_file" "$lib_target_dir/$file_name"; then
((installed++))
if $VERBOSE; then
log_success " Installed: $file_name"
fi
else
((failed++))
log_warning " Failed: $file_name"
fi
done <<< "$lib_files"
# Report results
if [[ $failed -gt 0 ]]; then
log_warning "Installed ${installed}/${total_files} lib files (${failed} failed)"
return 1
fi
log_success "Installed ${installed} lib file(s) to ~/.claude/lib/"
return 0
}
# Install agent files to .claude/agents/
bootstrap_agents() {
log_step "Installing agent files to .claude/agents/..."
local agent_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/agents"
local agent_target_dir=".claude/agents"
local installed=0
local failed=0
# Check if agent source directory exists
if [[ ! -d "$agent_source_dir" ]]; then
log_warning "Agents directory not found in staging - agent files won't be installed"
return 1
fi
# Create target directory if it doesn't exist
if ! mkdir -p "$agent_target_dir" 2>/dev/null; then
log_error "Failed to create .claude/agents/ directory (permission denied?)"
return 1
fi
# Get list of .md files from agents directory
local agent_files
agent_files=$(find "$agent_source_dir" -maxdepth 1 -type f -name "*.md")
if [[ -z "$agent_files" ]]; then
log_info "No agent files found to install"
return 0
fi
# Count total files
local total_files
total_files=$(echo "$agent_files" | wc -l | tr -d ' ')
log_info "Found ${total_files} agent files to install"
# Copy each agent file
while IFS= read -r agent_file; do
if [[ -z "$agent_file" ]]; then
continue
fi
local file_name
file_name=$(basename "$agent_file")
# Security: Check if file is a symlink
if [[ -L "$agent_file" ]]; then
log_warning " Skipping symlink: $file_name"
((failed++))
continue
fi
# Copy file to target directory (use -P to not follow symlinks)
if cp -P "$agent_file" "$agent_target_dir/$file_name"; then
((installed++))
if $VERBOSE; then
log_success " Installed: $file_name"
fi
else
((failed++))
log_warning " Failed: $file_name"
fi
done <<< "$agent_files"
# Report results
if [[ $failed -gt 0 ]]; then
log_warning "Installed ${installed}/${total_files} agent files (${failed} failed)"
return 1
fi
log_success "Installed ${installed} agent file(s) to .claude/agents/"
return 0
}
# Install command files to .claude/commands/ (excluding setup.md which is already bootstrapped)
bootstrap_commands() {
log_step "Installing command files to .claude/commands/..."
local command_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/commands"
local command_target_dir=".claude/commands"
local installed=0
local failed=0
# Check if command source directory exists
if [[ ! -d "$command_source_dir" ]]; then
log_warning "Commands directory not found in staging - command files won't be installed"
return 1
fi
# Create target directory if it doesn't exist (should already exist from bootstrap_setup_command)
if ! mkdir -p "$command_target_dir" 2>/dev/null; then
log_error "Failed to create .claude/commands/ directory (permission denied?)"
return 1
fi
# Get list of .md files from commands directory (exclude setup.md - already installed)
local command_files
command_files=$(find "$command_source_dir" -maxdepth 1 -type f -name "*.md" ! -name "setup.md")
if [[ -z "$command_files" ]]; then
log_info "No additional command files found to install"
return 0
fi
# Count total files
local total_files
total_files=$(echo "$command_files" | wc -l | tr -d ' ')
log_info "Found ${total_files} command files to install (setup.md already installed)"
# Copy each command file
while IFS= read -r command_file; do
if [[ -z "$command_file" ]]; then
continue
fi
local file_name
file_name=$(basename "$command_file")
# Security: Check if file is a symlink
if [[ -L "$command_file" ]]; then
log_warning " Skipping symlink: $file_name"
((failed++))
continue
fi
# Copy file to target directory (use -P to not follow symlinks)
if cp -P "$command_file" "$command_target_dir/$file_name"; then
((installed++))
if $VERBOSE; then
log_success " Installed: $file_name"
fi
else
((failed++))
log_warning " Failed: $file_name"
fi
done <<< "$command_files"
# Report results
if [[ $failed -gt 0 ]]; then
log_warning "Installed ${installed}/${total_files} command files (${failed} failed)"
return 1
fi
log_success "Installed ${installed} command file(s) to .claude/commands/"
return 0
}
# Install script files to .claude/scripts/
bootstrap_scripts() {
log_step "Installing script files to .claude/scripts/..."
local script_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/scripts"
local script_target_dir=".claude/scripts"
local installed=0
local failed=0
# Check if script source directory exists
if [[ ! -d "$script_source_dir" ]]; then
log_warning "Scripts directory not found in staging - script files won't be installed"
return 1
fi
# Create target directory if it doesn't exist
if ! mkdir -p "$script_target_dir" 2>/dev/null; then
log_error "Failed to create .claude/scripts/ directory (permission denied?)"
return 1
fi
# Get list of .py files from scripts directory
local script_files
script_files=$(find "$script_source_dir" -maxdepth 1 -type f -name "*.py")
if [[ -z "$script_files" ]]; then
log_info "No script files found to install"
return 0
fi
# Count total files
local total_files
total_files=$(echo "$script_files" | wc -l | tr -d ' ')
log_info "Found ${total_files} script files to install"
# Copy each script file
while IFS= read -r script_file; do
if [[ -z "$script_file" ]]; then
continue
fi
local file_name
file_name=$(basename "$script_file")
# Security: Check if file is a symlink
if [[ -L "$script_file" ]]; then
log_warning " Skipping symlink: $file_name"
((failed++))
continue
fi
# Copy file to target directory (use -P to not follow symlinks)
if cp -P "$script_file" "$script_target_dir/$file_name"; then
((installed++))
if $VERBOSE; then
log_success " Installed: $file_name"
fi
else
((failed++))
log_warning " Failed: $file_name"
fi
done <<< "$script_files"
# Report results
if [[ $failed -gt 0 ]]; then
log_warning "Installed ${installed}/${total_files} script files (${failed} failed)"
return 1
fi
log_success "Installed ${installed} script file(s) to .claude/scripts/"
return 0
}
# Install config files to .claude/config/
bootstrap_config() {
log_step "Installing config files to .claude/config/..."
local config_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/config"
local config_target_dir=".claude/config"
local installed=0
local failed=0
# Check if config source directory exists
if [[ ! -d "$config_source_dir" ]]; then
log_warning "Config directory not found in staging - config files won't be installed"
return 1
fi
# Create target directory if it doesn't exist
if ! mkdir -p "$config_target_dir" 2>/dev/null; then
log_error "Failed to create .claude/config/ directory (permission denied?)"
return 1
fi
# Get list of .json files from config directory
local config_files
config_files=$(find "$config_source_dir" -maxdepth 1 -type f -name "*.json")
if [[ -z "$config_files" ]]; then
log_info "No config files found to install"
return 0
fi
# Count total files
local total_files
total_files=$(echo "$config_files" | wc -l | tr -d ' ')
log_info "Found ${total_files} config files to install"
# Copy each config file
while IFS= read -r config_file; do
if [[ -z "$config_file" ]]; then
continue
fi
local file_name
file_name=$(basename "$config_file")
# Security: Check if file is a symlink
if [[ -L "$config_file" ]]; then
log_warning " Skipping symlink: $file_name"
((failed++))
continue
fi
# Copy file to target directory (use -P to not follow symlinks)
if cp -P "$config_file" "$config_target_dir/$file_name"; then
((installed++))
if $VERBOSE; then
log_success " Installed: $file_name"
fi
else
((failed++))
log_warning " Failed: $file_name"
fi
done <<< "$config_files"
# Report results
if [[ $failed -gt 0 ]]; then
log_warning "Installed ${installed}/${total_files} config files (${failed} failed)"
return 1
fi
log_success "Installed ${installed} config file(s) to .claude/config/"
return 0
}
# Install template files to .claude/templates/
bootstrap_templates() {
log_step "Installing template files to .claude/templates/..."
local template_source_dir="${STAGING_DIR}/files/plugins/autonomous-dev/templates"
local template_target_dir=".claude/templates"
local installed=0
local failed=0
# Check if template source directory exists
if [[ ! -d "$template_source_dir" ]]; then