-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·546 lines (471 loc) · 16.9 KB
/
install.sh
File metadata and controls
executable file
·546 lines (471 loc) · 16.9 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
#!/bin/bash
# CARL Installation Script
# Installs CARL (Context-Aware Requirements Language) system
#
# Prerequisites:
# - jq (JSON processor) - https://jqlang.github.io/jq/
# - yq (YAML processor) - https://github.com/mikefarah/yq
#
# Usage:
# curl -fsSL https://github.com/ClaytonHunt/carl/releases/latest/download/install.sh | bash
#
# Environment Variables:
# CARL_VERSION - Specific version to install (default: latest)
# CARL_VERBOSE - Enable verbose output (1/0)
# CARL_DRY_RUN - Show what would be done without installing (1/0)
set -euo pipefail
# Configuration
REPO_OWNER="ClaytonHunt"
REPO_NAME="carl"
CARL_VERSION="${CARL_VERSION:-latest}"
VERBOSE="${CARL_VERBOSE:-0}"
DRY_RUN="${CARL_DRY_RUN:-0}"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
log() {
echo -e "${BLUE}$1${NC}"
}
warn() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
error() {
echo -e "${RED}❌ $1${NC}" >&2
}
success() {
echo -e "${GREEN}✅ $1${NC}"
}
verbose() {
if [ "$VERBOSE" = "1" ]; then
echo -e "${BLUE}🔍 $1${NC}"
fi
}
# Check dependencies
check_dependencies() {
verbose "Checking system dependencies..."
local missing_deps=()
local missing_tools=()
# Check basic system tools
command -v curl >/dev/null || missing_deps+=("curl")
command -v tar >/dev/null || missing_deps+=("tar")
command -v grep >/dev/null || missing_deps+=("grep")
command -v sed >/dev/null || missing_deps+=("sed")
# Check CARL-specific requirements
command -v jq >/dev/null || missing_tools+=("jq")
command -v yq >/dev/null || missing_tools+=("yq")
if [ ${#missing_deps[@]} -ne 0 ]; then
error "Missing basic system dependencies: ${missing_deps[*]}"
echo "Please install the missing system tools and try again."
exit 1
fi
if [ ${#missing_tools[@]} -ne 0 ]; then
error "Missing CARL dependencies: ${missing_tools[*]}"
echo ""
echo "CARL requires jq and yq for JSON/YAML processing."
echo ""
echo "📦 Installation Instructions:"
echo ""
if [[ " ${missing_tools[*]} " =~ " jq " ]]; then
echo "🔧 jq (JSON processor):"
echo " macOS: brew install jq"
echo " Ubuntu: sudo apt-get install jq"
echo " CentOS: sudo yum install jq"
echo " Windows: choco install jq"
echo " Manual: https://jqlang.github.io/jq/download/"
echo ""
fi
if [[ " ${missing_tools[*]} " =~ " yq " ]]; then
echo "⚙️ yq (YAML processor):"
echo " macOS: brew install yq"
echo " Ubuntu: sudo snap install yq"
echo " pip: pip install yq"
echo " go: go install github.com/mikefarah/yq/v4@latest"
echo " Manual: https://github.com/mikefarah/yq/releases"
echo ""
fi
echo "After installation, run this script again."
exit 1
fi
USE_JQ=1
verbose "All dependencies satisfied (jq and yq found)"
}
# Check write permissions
check_permissions() {
verbose "Checking write permissions..."
if [ ! -w . ]; then
error "No write permission in current directory: $(pwd)"
echo "Please run this script from a directory you can write to."
exit 1
fi
verbose "Write permissions OK"
}
# Determine version to install
resolve_version() {
if [ "$CARL_VERSION" = "latest" ]; then
log "🔍 Fetching latest CARL release..."
local api_url="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest"
local release_info
if ! release_info=$(curl -s "$api_url"); then
error "Failed to fetch release information from GitHub"
exit 1
fi
if [ "$USE_JQ" = "1" ]; then
CARL_VERSION=$(echo "$release_info" | jq -r '.tag_name')
else
CARL_VERSION=$(echo "$release_info" | grep '"tag_name"' | sed 's/.*"tag_name": *"\([^"]*\)".*/\1/')
fi
if [ -z "$CARL_VERSION" ] || [ "$CARL_VERSION" = "null" ]; then
error "Could not determine latest version"
exit 1
fi
success "Latest version: $CARL_VERSION"
else
log "📌 Installing specific version: $CARL_VERSION"
fi
# Set download URL
# Check if this looks like a branch name (contains non-version characters)
if [[ "$CARL_VERSION" =~ ^v?[0-9]+\.[0-9]+(\.[0-9]+)?(-.*)?$ ]]; then
# Looks like a version tag (v2.0.0, 2.0.0, v2.0.0-beta, etc.)
TARBALL_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/archive/refs/tags/${CARL_VERSION}.tar.gz"
verbose "Treating '$CARL_VERSION' as a tag"
else
# Treat as branch name (main, carl-system-v2, feature-branch, etc.)
TARBALL_URL="https://github.com/${REPO_OWNER}/${REPO_NAME}/archive/refs/heads/${CARL_VERSION}.tar.gz"
verbose "Treating '$CARL_VERSION' as a branch"
fi
verbose "Download URL: $TARBALL_URL"
}
# Check existing installation and compatibility
check_existing_installation() {
if [ -f ".carl/schemas/carl-settings.schema.yaml" ]; then
local current_version
current_version=$(grep 'default: "' .carl/schemas/carl-settings.schema.yaml | sed 's/.*default: "\([^"]*\)".*/\1/' 2>/dev/null || echo "unknown")
log "📦 Found existing CARL installation: v$current_version"
# Check v1.x -> v2.x compatibility
if [[ "$current_version" =~ ^1\. ]] && [[ "$CARL_VERSION" =~ ^v?2\. ]]; then
error "CARL v1.x is incompatible with v2.x"
echo ""
echo "Please remove the existing installation first:"
echo " rm -rf .carl .claude/agents/carl* .claude/commands/carl CLAUDE.md"
echo ""
echo "Then run the installer again."
exit 1
fi
log "🔄 Upgrading CARL to $CARL_VERSION"
return 0
else
log "🆕 Fresh CARL installation: $CARL_VERSION"
return 1
fi
}
# Download and extract CARL
download_carl() {
log "📥 Downloading CARL $CARL_VERSION..."
TEMP_DIR=$(mktemp -d)
verbose "Using temporary directory: $TEMP_DIR"
# Ensure cleanup on exit
trap "rm -rf $TEMP_DIR" EXIT
if ! curl -fsSL "$TARBALL_URL" | tar -xz -C "$TEMP_DIR" --strip-components=1; then
error "Failed to download or extract CARL archive"
echo "URL: $TARBALL_URL"
exit 1
fi
# Verify download integrity
if [ ! -f "$TEMP_DIR/.carl/schemas/carl-settings.schema.yaml" ]; then
error "Downloaded archive is missing core CARL files"
echo "This may indicate a corrupted download or invalid version."
exit 1
fi
verbose "Download and extraction completed successfully"
}
# Install CARL system files
install_system_files() {
if [ "$DRY_RUN" = "1" ]; then
log "🔍 DRY RUN - would install the following:"
echo " 📁 .carl/ directory (schemas, hooks, project structure, CARL.md guide)"
echo " 🤖 .claude/agents/carl-*.md files"
echo " 📋 .claude/commands/carl/ directory"
echo " 🔧 Merge hooks into .claude/settings.json"
return 0
fi
log "📁 Installing CARL system files..."
# Install .carl directory
verbose "Installing .carl directory..."
cp -r "$TEMP_DIR/.carl" .
# Install Claude Code integration files
verbose "Installing Claude Code integration..."
mkdir -p .claude/{agents,commands}
# Copy CARL agents (only carl-* files)
if [ -d "$TEMP_DIR/.claude/agents" ]; then
cp "$TEMP_DIR/.claude/agents/"carl-*.md .claude/agents/ 2>/dev/null || true
fi
# Copy CARL commands
if [ -d "$TEMP_DIR/.claude/commands/carl" ]; then
cp -r "$TEMP_DIR/.claude/commands/carl" .claude/commands/
fi
# Set executable permissions on hook scripts
verbose "Setting executable permissions on hooks..."
find .carl/hooks -name "*.sh" -exec chmod +x {} \; 2>/dev/null || true
success "CARL system files installed"
}
# Merge CARL hooks into Claude settings
merge_claude_settings() {
if [ "$DRY_RUN" = "1" ]; then
return 0
fi
local settings_file=".claude/settings.json"
local temp_settings="$TEMP_DIR/.claude/settings.json"
if [ -f "$settings_file" ]; then
log "🔧 Merging CARL hooks into existing Claude settings..."
# Create backup
cp "$settings_file" "${settings_file}.backup"
verbose "Created backup: ${settings_file}.backup"
if [ "$USE_JQ" = "1" ] && [ -f "$temp_settings" ]; then
# Use jq for proper JSON merging
verbose "Using jq for JSON merging..."
# Smart merge that replaces CARL hooks and preserves non-CARL hooks
if jq -s '
def is_carl_hook(hook):
(hook.command // "") | contains("$CLAUDE_PROJECT_DIR/.carl/hooks");
def filter_non_carl_hooks(hooks_array):
hooks_array | map(select(.hooks | map(is_carl_hook(.)) | any | not));
def merge_hooks(existing; new):
existing as $existing |
new as $new |
($new | to_entries | map({
key: .key,
value: (
if $existing[.key] then
# For existing hook types, keep non-CARL hooks and add new CARL hooks
(filter_non_carl_hooks($existing[.key]) + .value)
else
# For new hook types, use as-is
.value
end
)
}) | from_entries) as $merged_new |
$existing * $merged_new;
.[0] * {
"hooks": merge_hooks(.[0].hooks // {}; .[1].hooks // {})
}' \
"$settings_file" "$temp_settings" > "${settings_file}.tmp"; then
mv "${settings_file}.tmp" "$settings_file"
success "Settings merged successfully"
else
warn "jq merge failed - restoring backup"
mv "${settings_file}.backup" "$settings_file"
fi
else
warn "Cannot merge settings automatically - manual merge required"
echo "Your original settings are backed up to ${settings_file}.backup"
echo "CARL settings are in $temp_settings"
fi
# Validate final JSON
if [ "$USE_JQ" = "1" ]; then
if ! jq empty "$settings_file" 2>/dev/null; then
warn "Invalid JSON detected - restoring backup"
mv "${settings_file}.backup" "$settings_file"
fi
fi
else
log "📄 Creating new Claude settings with CARL hooks..."
mkdir -p .claude
if [ -f "$temp_settings" ]; then
cp "$temp_settings" "$settings_file"
success "Claude settings created"
else
warn "No CARL settings template found in download"
fi
fi
}
# Generate CARL settings file
generate_carl_settings() {
if [ "$DRY_RUN" = "1" ]; then
return 0
fi
local settings_file=".carl/carl-settings.json"
# Don't overwrite existing personal settings
if [ -f "$settings_file" ]; then
verbose "Personal CARL settings exist - not overwriting"
return 0
fi
log "⚙️ Generating CARL configuration..."
# Generate from schema defaults (simplified version)
# In a real implementation, this would parse the schema and generate defaults
cat > "$settings_file" << 'EOF'
{
"system": {
"version": "2.0.0",
"project_root": "",
"installation_path": "",
"created_at": ""
},
"audio": {
"enabled": true,
"notifications": {
"session_start": {
"enabled": true,
"message_template": "Good {time_of_day}, CARL session started",
"fallback_message": "Good {time_of_day}, CARL session started"
},
"stop": {
"enabled": true,
"message_template": "{project} operation completed",
"fallback_message": "{project} operation completed"
},
"attention": {
"enabled": true,
"message_template": "{project} needs your attention",
"fallback_message": "Claude Code needs your attention"
},
"progress_milestone": {
"enabled": false,
"message_template": "Progress milestone reached",
"fallback_message": "Progress milestone reached"
},
"schema_validation_error": {
"enabled": false,
"message_template": "Schema validation error detected",
"fallback_message": "Schema validation error detected"
},
"tech_debt_detected": {
"enabled": false,
"message_template": "Technical debt detected",
"fallback_message": "Technical debt detected"
}
},
"voice": {
"macos": {
"voice": "default",
"rate": 200,
"volume": 0.5
},
"linux": {
"voice": "default",
"rate": "normal",
"volume": "normal"
},
"wsl": {
"voice": "default",
"rate": 0,
"volume": 100
},
"windows": {
"voice": "default",
"rate": 0,
"volume": 100
},
"elevenlabs": {
"integration_level": "disabled",
"mcp_enabled": false,
"voice_id": "21m00Tcm4TlvDq8ikWAM",
"model": "eleven_monolingual_v1",
"output_format": "mp3_44100_128",
"cache_audio": true,
"cache_duration_hours": 24,
"generic_messages_only": true
}
}
},
"session": {
"auto_compaction": true,
"compaction_strategy": "calendar_based",
"retention_periods": {
"daily_sessions_days": 7
},
"track_agent_performance": true,
"track_command_metrics": true
},
"hooks": {
"schema_validation": {
"strict_mode": true,
"auto_fix_minor_issues": true
},
"progress_tracking": {
"auto_update_percentages": true,
"milestone_thresholds": [25, 50, 75, 90, 100]
},
"tech_debt_extraction": {
"keywords": ["TODO", "FIXME", "HACK", "XXX", "NOTE"],
"auto_prioritize": true
},
"completion_handler": {
"auto_move_completed": true,
"completion_threshold": 100
}
},
"context_injection": {
"enabled": true,
"carl_commands_only": true,
"include_active_work": true,
"include_recent_sessions": false,
"max_context_tokens": 500
},
"developer": {
"preferred_time_format": "12h",
"timezone": "auto",
"work_hours": {
"start": "07:00",
"end": "18:00"
}
}
}
EOF
# Update with actual values
local project_root=$(pwd)
local installation_path="$project_root/.carl"
local created_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
if [ "$USE_JQ" = "1" ]; then
jq --arg project_root "$project_root" \
--arg installation_path "$installation_path" \
--arg created_at "$created_at" \
--arg version "$CARL_VERSION" \
'.system.project_root = $project_root | .system.installation_path = $installation_path | .system.created_at = $created_at | .system.version = $version' \
"$settings_file" > "${settings_file}.tmp" && mv "${settings_file}.tmp" "$settings_file"
fi
success "CARL configuration generated"
}
# Display success message and next steps
show_success() {
echo ""
success "CARL $CARL_VERSION installed successfully!"
echo ""
echo "🚀 Next steps:"
echo " 1. Run: /carl:analyze"
echo " 2. Start planning: /carl:plan 'Add user authentication'"
echo " 3. Execute work: /carl:task [work-item.carl]"
echo " 4. Monitor progress: /carl:status"
echo ""
echo "📚 Documentation: https://github.com/${REPO_OWNER}/${REPO_NAME}"
echo "🆘 Support: https://github.com/${REPO_OWNER}/${REPO_NAME}/issues"
if [ -f ".claude/settings.json.backup" ]; then
echo "💾 Your original Claude settings backed up to .claude/settings.json.backup"
fi
}
# Main installation flow
main() {
echo "🎯 CARL Installation Script"
echo "=========================================="
check_dependencies
check_permissions
resolve_version
local is_upgrade=false
if check_existing_installation; then
is_upgrade=true
fi
download_carl
install_system_files
merge_claude_settings
generate_carl_settings
if [ "$DRY_RUN" = "1" ]; then
log "🔍 DRY RUN completed - no files were modified"
exit 0
fi
show_success
}
# Run main function
main "$@"