@claude-flow/cli 3.0.0-alpha.37 → 3.0.0-alpha.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.claude/helpers/README.md +97 -0
  2. package/.claude/helpers/adr-compliance.sh +186 -0
  3. package/.claude/helpers/auto-commit.sh +178 -0
  4. package/.claude/helpers/checkpoint-manager.sh +251 -0
  5. package/.claude/helpers/daemon-manager.sh +252 -0
  6. package/.claude/helpers/ddd-tracker.sh +144 -0
  7. package/.claude/helpers/github-safe.js +106 -0
  8. package/.claude/helpers/github-setup.sh +28 -0
  9. package/.claude/helpers/guidance-hook.sh +13 -0
  10. package/.claude/helpers/guidance-hooks.sh +102 -0
  11. package/.claude/helpers/health-monitor.sh +108 -0
  12. package/.claude/helpers/learning-hooks.sh +329 -0
  13. package/.claude/helpers/learning-optimizer.sh +127 -0
  14. package/.claude/helpers/learning-service.mjs +1144 -0
  15. package/.claude/helpers/metrics-db.mjs +488 -0
  16. package/.claude/helpers/pattern-consolidator.sh +86 -0
  17. package/.claude/helpers/perf-worker.sh +160 -0
  18. package/.claude/helpers/quick-start.sh +19 -0
  19. package/.claude/helpers/security-scanner.sh +127 -0
  20. package/.claude/helpers/setup-mcp.sh +18 -0
  21. package/.claude/helpers/standard-checkpoint-hooks.sh +189 -0
  22. package/.claude/helpers/swarm-comms.sh +353 -0
  23. package/.claude/helpers/swarm-hooks.sh +761 -0
  24. package/.claude/helpers/swarm-monitor.sh +211 -0
  25. package/.claude/helpers/sync-v3-metrics.sh +245 -0
  26. package/.claude/helpers/update-v3-progress.sh +166 -0
  27. package/.claude/helpers/v3-quick-status.sh +58 -0
  28. package/.claude/helpers/v3.sh +111 -0
  29. package/.claude/helpers/validate-v3-config.sh +216 -0
  30. package/.claude/helpers/worker-manager.sh +170 -0
  31. package/dist/src/init/executor.d.ts.map +1 -1
  32. package/dist/src/init/executor.js +103 -26
  33. package/dist/src/init/executor.js.map +1 -1
  34. package/dist/src/init/mcp-generator.js +2 -2
  35. package/dist/src/init/mcp-generator.js.map +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +1 -1
@@ -0,0 +1,111 @@
1
+ #!/bin/bash
2
+ # V3 Helper Alias Script - Quick access to all V3 development tools
3
+
4
+ set -e
5
+
6
+ HELPERS_DIR=".claude/helpers"
7
+
8
+ case "$1" in
9
+ "status"|"st")
10
+ "$HELPERS_DIR/v3-quick-status.sh"
11
+ ;;
12
+
13
+ "progress"|"prog")
14
+ shift
15
+ "$HELPERS_DIR/update-v3-progress.sh" "$@"
16
+ ;;
17
+
18
+ "validate"|"check")
19
+ "$HELPERS_DIR/validate-v3-config.sh"
20
+ ;;
21
+
22
+ "statusline"|"sl")
23
+ ".claude/statusline.sh"
24
+ ;;
25
+
26
+ "update")
27
+ if [ -z "$2" ] || [ -z "$3" ]; then
28
+ echo "Usage: v3 update <metric> <value>"
29
+ echo "Examples:"
30
+ echo " v3 update domain 3"
31
+ echo " v3 update agent 8"
32
+ echo " v3 update security 2"
33
+ echo " v3 update performance 2.5x"
34
+ echo " v3 update memory 45%"
35
+ echo " v3 update ddd 75"
36
+ exit 1
37
+ fi
38
+ "$HELPERS_DIR/update-v3-progress.sh" "$2" "$3"
39
+ ;;
40
+
41
+ "full-status"|"fs")
42
+ echo "🔍 V3 Development Environment Status"
43
+ echo "====================================="
44
+ echo ""
45
+ echo "📊 Quick Status:"
46
+ "$HELPERS_DIR/v3-quick-status.sh"
47
+ echo ""
48
+ echo "📺 Full Statusline:"
49
+ ".claude/statusline.sh"
50
+ ;;
51
+
52
+ "init")
53
+ echo "🚀 Initializing V3 Development Environment..."
54
+
55
+ # Run validation first
56
+ echo ""
57
+ echo "1️⃣ Validating configuration..."
58
+ if "$HELPERS_DIR/validate-v3-config.sh"; then
59
+ echo ""
60
+ echo "2️⃣ Showing current status..."
61
+ "$HELPERS_DIR/v3-quick-status.sh"
62
+ echo ""
63
+ echo "✅ V3 development environment is ready!"
64
+ echo ""
65
+ echo "🔧 Quick commands:"
66
+ echo " v3 status - Show quick status"
67
+ echo " v3 update - Update progress metrics"
68
+ echo " v3 statusline - Show full statusline"
69
+ echo " v3 validate - Validate configuration"
70
+ else
71
+ echo ""
72
+ echo "❌ Configuration validation failed. Please fix issues before proceeding."
73
+ exit 1
74
+ fi
75
+ ;;
76
+
77
+ "help"|"--help"|"-h"|"")
78
+ echo "Claude Flow V3 Helper Tool"
79
+ echo "=========================="
80
+ echo ""
81
+ echo "Usage: v3 <command> [options]"
82
+ echo ""
83
+ echo "Commands:"
84
+ echo " status, st Show quick development status"
85
+ echo " progress, prog [args] Update progress metrics"
86
+ echo " validate, check Validate V3 configuration"
87
+ echo " statusline, sl Show full statusline"
88
+ echo " full-status, fs Show both quick status and statusline"
89
+ echo " update <metric> <value> Update specific metric"
90
+ echo " init Initialize and validate environment"
91
+ echo " help Show this help message"
92
+ echo ""
93
+ echo "Update Examples:"
94
+ echo " v3 update domain 3 # Mark 3 domains complete"
95
+ echo " v3 update agent 8 # Set 8 agents active"
96
+ echo " v3 update security 2 # Mark 2 CVEs fixed"
97
+ echo " v3 update performance 2.5x # Set performance to 2.5x"
98
+ echo " v3 update memory 45% # Set memory reduction to 45%"
99
+ echo " v3 update ddd 75 # Set DDD progress to 75%"
100
+ echo ""
101
+ echo "Quick Start:"
102
+ echo " v3 init # Initialize environment"
103
+ echo " v3 status # Check current progress"
104
+ ;;
105
+
106
+ *)
107
+ echo "Unknown command: $1"
108
+ echo "Run 'v3 help' for usage information"
109
+ exit 1
110
+ ;;
111
+ esac
@@ -0,0 +1,216 @@
1
+ #!/bin/bash
2
+ # V3 Configuration Validation Script
3
+ # Ensures all V3 development dependencies and configurations are properly set up
4
+
5
+ set -e
6
+
7
+ echo "🔍 Claude Flow V3 Configuration Validation"
8
+ echo "==========================================="
9
+ echo ""
10
+
11
+ ERRORS=0
12
+ WARNINGS=0
13
+
14
+ # Color codes
15
+ RED='\033[0;31m'
16
+ YELLOW='\033[0;33m'
17
+ GREEN='\033[0;32m'
18
+ BLUE='\033[0;34m'
19
+ RESET='\033[0m'
20
+
21
+ # Helper functions
22
+ log_error() {
23
+ echo -e "${RED}❌ ERROR: $1${RESET}"
24
+ ((ERRORS++))
25
+ }
26
+
27
+ log_warning() {
28
+ echo -e "${YELLOW}⚠️ WARNING: $1${RESET}"
29
+ ((WARNINGS++))
30
+ }
31
+
32
+ log_success() {
33
+ echo -e "${GREEN}✅ $1${RESET}"
34
+ }
35
+
36
+ log_info() {
37
+ echo -e "${BLUE}ℹ️ $1${RESET}"
38
+ }
39
+
40
+ # Check 1: Required directories
41
+ echo "📁 Checking Directory Structure..."
42
+ required_dirs=(
43
+ ".claude"
44
+ ".claude/helpers"
45
+ ".claude-flow/metrics"
46
+ ".claude-flow/security"
47
+ "src"
48
+ "src/domains"
49
+ )
50
+
51
+ for dir in "${required_dirs[@]}"; do
52
+ if [ -d "$dir" ]; then
53
+ log_success "Directory exists: $dir"
54
+ else
55
+ log_error "Missing required directory: $dir"
56
+ fi
57
+ done
58
+
59
+ # Check 2: Required files
60
+ echo ""
61
+ echo "📄 Checking Required Files..."
62
+ required_files=(
63
+ ".claude/settings.json"
64
+ ".claude/statusline.sh"
65
+ ".claude/helpers/update-v3-progress.sh"
66
+ ".claude-flow/metrics/v3-progress.json"
67
+ ".claude-flow/metrics/performance.json"
68
+ ".claude-flow/security/audit-status.json"
69
+ "package.json"
70
+ )
71
+
72
+ for file in "${required_files[@]}"; do
73
+ if [ -f "$file" ]; then
74
+ log_success "File exists: $file"
75
+
76
+ # Additional checks for specific files
77
+ case "$file" in
78
+ "package.json")
79
+ if grep -q "agentic-flow.*alpha" "$file" 2>/dev/null; then
80
+ log_success "agentic-flow@alpha dependency found"
81
+ else
82
+ log_warning "agentic-flow@alpha dependency not found in package.json"
83
+ fi
84
+ ;;
85
+ ".claude/helpers/update-v3-progress.sh")
86
+ if [ -x "$file" ]; then
87
+ log_success "Helper script is executable"
88
+ else
89
+ log_error "Helper script is not executable: $file"
90
+ fi
91
+ ;;
92
+ ".claude-flow/metrics/v3-progress.json")
93
+ if jq empty "$file" 2>/dev/null; then
94
+ log_success "V3 progress JSON is valid"
95
+ domains=$(jq -r '.domains.total // "unknown"' "$file" 2>/dev/null)
96
+ agents=$(jq -r '.swarm.totalAgents // "unknown"' "$file" 2>/dev/null)
97
+ log_info "Configured for $domains domains, $agents agents"
98
+ else
99
+ log_error "Invalid JSON in v3-progress.json"
100
+ fi
101
+ ;;
102
+ esac
103
+ else
104
+ log_error "Missing required file: $file"
105
+ fi
106
+ done
107
+
108
+ # Check 3: Domain structure
109
+ echo ""
110
+ echo "🏗️ Checking Domain Structure..."
111
+ expected_domains=("task-management" "session-management" "health-monitoring" "lifecycle-management" "event-coordination")
112
+
113
+ for domain in "${expected_domains[@]}"; do
114
+ domain_path="src/domains/$domain"
115
+ if [ -d "$domain_path" ]; then
116
+ log_success "Domain directory exists: $domain"
117
+ else
118
+ log_warning "Domain directory missing: $domain (will be created during development)"
119
+ fi
120
+ done
121
+
122
+ # Check 4: Git configuration
123
+ echo ""
124
+ echo "🔀 Checking Git Configuration..."
125
+ if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
126
+ log_success "Git repository detected"
127
+
128
+ current_branch=$(git branch --show-current 2>/dev/null || echo "unknown")
129
+ log_info "Current branch: $current_branch"
130
+
131
+ if [ "$current_branch" = "v3" ]; then
132
+ log_success "On V3 development branch"
133
+ else
134
+ log_warning "Not on V3 branch (current: $current_branch)"
135
+ fi
136
+ else
137
+ log_error "Not in a Git repository"
138
+ fi
139
+
140
+ # Check 5: Node.js and npm
141
+ echo ""
142
+ echo "📦 Checking Node.js Environment..."
143
+ if command -v node >/dev/null 2>&1; then
144
+ node_version=$(node --version)
145
+ log_success "Node.js installed: $node_version"
146
+
147
+ # Check if Node.js version is 20+
148
+ node_major=$(echo "$node_version" | cut -d'.' -f1 | sed 's/v//')
149
+ if [ "$node_major" -ge 20 ]; then
150
+ log_success "Node.js version meets requirements (≥20.0.0)"
151
+ else
152
+ log_error "Node.js version too old. Required: ≥20.0.0, Found: $node_version"
153
+ fi
154
+ else
155
+ log_error "Node.js not installed"
156
+ fi
157
+
158
+ if command -v npm >/dev/null 2>&1; then
159
+ npm_version=$(npm --version)
160
+ log_success "npm installed: $npm_version"
161
+ else
162
+ log_error "npm not installed"
163
+ fi
164
+
165
+ # Check 6: Development tools
166
+ echo ""
167
+ echo "🔧 Checking Development Tools..."
168
+ dev_tools=("jq" "git")
169
+
170
+ for tool in "${dev_tools[@]}"; do
171
+ if command -v "$tool" >/dev/null 2>&1; then
172
+ tool_version=$($tool --version 2>/dev/null | head -n1 || echo "unknown")
173
+ log_success "$tool installed: $tool_version"
174
+ else
175
+ log_error "$tool not installed"
176
+ fi
177
+ done
178
+
179
+ # Check 7: Permissions
180
+ echo ""
181
+ echo "🔐 Checking Permissions..."
182
+ test_files=(
183
+ ".claude/statusline.sh"
184
+ ".claude/helpers/update-v3-progress.sh"
185
+ )
186
+
187
+ for file in "${test_files[@]}"; do
188
+ if [ -f "$file" ]; then
189
+ if [ -x "$file" ]; then
190
+ log_success "Executable permissions: $file"
191
+ else
192
+ log_warning "Missing executable permissions: $file"
193
+ log_info "Run: chmod +x $file"
194
+ fi
195
+ fi
196
+ done
197
+
198
+ # Summary
199
+ echo ""
200
+ echo "📊 Validation Summary"
201
+ echo "===================="
202
+ if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then
203
+ log_success "All checks passed! V3 development environment is ready."
204
+ exit 0
205
+ elif [ $ERRORS -eq 0 ]; then
206
+ echo -e "${YELLOW}⚠️ $WARNINGS warnings found, but no critical errors.${RESET}"
207
+ log_info "V3 development can proceed with minor issues to address."
208
+ exit 0
209
+ else
210
+ echo -e "${RED}❌ $ERRORS critical errors found.${RESET}"
211
+ if [ $WARNINGS -gt 0 ]; then
212
+ echo -e "${YELLOW}⚠️ $WARNINGS warnings also found.${RESET}"
213
+ fi
214
+ log_error "Please fix critical errors before proceeding with V3 development."
215
+ exit 1
216
+ fi
@@ -0,0 +1,170 @@
1
+ #!/bin/bash
2
+ # Claude Flow V3 - Unified Worker Manager
3
+ # Orchestrates all background workers with proper scheduling
4
+
5
+ set -euo pipefail
6
+
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
9
+ METRICS_DIR="$PROJECT_ROOT/.claude-flow/metrics"
10
+ PID_FILE="$METRICS_DIR/worker-manager.pid"
11
+ LOG_FILE="$METRICS_DIR/worker-manager.log"
12
+
13
+ mkdir -p "$METRICS_DIR"
14
+
15
+ # Worker definitions: name:script:interval_seconds
16
+ WORKERS=(
17
+ "perf:perf-worker.sh:300" # 5 min
18
+ "health:health-monitor.sh:300" # 5 min
19
+ "patterns:pattern-consolidator.sh:900" # 15 min
20
+ "ddd:ddd-tracker.sh:600" # 10 min
21
+ "adr:adr-compliance.sh:900" # 15 min
22
+ "security:security-scanner.sh:1800" # 30 min
23
+ "learning:learning-optimizer.sh:1800" # 30 min
24
+ )
25
+
26
+ log() {
27
+ echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
28
+ }
29
+
30
+ run_worker() {
31
+ local name="$1"
32
+ local script="$2"
33
+ local script_path="$SCRIPT_DIR/$script"
34
+
35
+ if [ -x "$script_path" ]; then
36
+ "$script_path" check 2>/dev/null &
37
+ fi
38
+ }
39
+
40
+ run_all_workers() {
41
+ log "Running all workers (non-blocking)..."
42
+
43
+ for worker_def in "${WORKERS[@]}"; do
44
+ IFS=':' read -r name script interval <<< "$worker_def"
45
+ run_worker "$name" "$script"
46
+ done
47
+
48
+ # Don't wait - truly non-blocking
49
+ log "All workers spawned"
50
+ }
51
+
52
+ run_daemon() {
53
+ local interval="${1:-60}"
54
+
55
+ log "Starting worker manager daemon (interval: ${interval}s)"
56
+ echo $$ > "$PID_FILE"
57
+
58
+ trap 'log "Shutting down..."; rm -f "$PID_FILE"; exit 0' SIGTERM SIGINT
59
+
60
+ while true; do
61
+ run_all_workers
62
+ sleep "$interval"
63
+ done
64
+ }
65
+
66
+ status_all() {
67
+ echo "╔══════════════════════════════════════════════════════════════╗"
68
+ echo "║ Claude Flow V3 - Worker Status ║"
69
+ echo "╠══════════════════════════════════════════════════════════════╣"
70
+
71
+ for worker_def in "${WORKERS[@]}"; do
72
+ IFS=':' read -r name script interval <<< "$worker_def"
73
+ local script_path="$SCRIPT_DIR/$script"
74
+
75
+ if [ -x "$script_path" ]; then
76
+ local status=$("$script_path" status 2>/dev/null || echo "No data")
77
+ printf "║ %-10s │ %-48s ║\n" "$name" "$status"
78
+ fi
79
+ done
80
+
81
+ echo "╠══════════════════════════════════════════════════════════════╣"
82
+
83
+ # Check if daemon is running
84
+ if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
85
+ echo "║ Daemon: RUNNING (PID: $(cat "$PID_FILE")) ║"
86
+ else
87
+ echo "║ Daemon: NOT RUNNING ║"
88
+ fi
89
+
90
+ echo "╚══════════════════════════════════════════════════════════════╝"
91
+ }
92
+
93
+ force_all() {
94
+ log "Force running all workers..."
95
+
96
+ for worker_def in "${WORKERS[@]}"; do
97
+ IFS=':' read -r name script interval <<< "$worker_def"
98
+ local script_path="$SCRIPT_DIR/$script"
99
+
100
+ if [ -x "$script_path" ]; then
101
+ log "Running $name..."
102
+ "$script_path" force 2>&1 | while read -r line; do
103
+ log " [$name] $line"
104
+ done
105
+ fi
106
+ done
107
+
108
+ log "All workers completed"
109
+ }
110
+
111
+ case "${1:-help}" in
112
+ "start"|"daemon")
113
+ if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
114
+ echo "Worker manager already running (PID: $(cat "$PID_FILE"))"
115
+ exit 1
116
+ fi
117
+ run_daemon "${2:-60}" &
118
+ echo "Worker manager started (PID: $!)"
119
+ ;;
120
+ "stop")
121
+ if [ -f "$PID_FILE" ]; then
122
+ kill "$(cat "$PID_FILE")" 2>/dev/null || true
123
+ rm -f "$PID_FILE"
124
+ echo "Worker manager stopped"
125
+ else
126
+ echo "Worker manager not running"
127
+ fi
128
+ ;;
129
+ "run"|"once")
130
+ run_all_workers
131
+ ;;
132
+ "force")
133
+ force_all
134
+ ;;
135
+ "status")
136
+ status_all
137
+ ;;
138
+ "logs")
139
+ tail -50 "$LOG_FILE" 2>/dev/null || echo "No logs available"
140
+ ;;
141
+ "help"|*)
142
+ cat << EOF
143
+ Claude Flow V3 - Worker Manager
144
+
145
+ Usage: $0 <command> [options]
146
+
147
+ Commands:
148
+ start [interval] Start daemon (default: 60s cycle)
149
+ stop Stop daemon
150
+ run Run all workers once
151
+ force Force run all workers (ignore throttle)
152
+ status Show all worker status
153
+ logs Show recent logs
154
+
155
+ Workers:
156
+ perf Performance benchmarks (5 min)
157
+ health System health monitoring (5 min)
158
+ patterns Pattern consolidation (15 min)
159
+ ddd DDD progress tracking (10 min)
160
+ adr ADR compliance checking (15 min)
161
+ security Security scanning (30 min)
162
+ learning Learning optimization (30 min)
163
+
164
+ Examples:
165
+ $0 start 120 # Start with 2-minute cycle
166
+ $0 force # Run all now
167
+ $0 status # Check all status
168
+ EOF
169
+ ;;
170
+ esac
@@ -1 +1 @@
1
- {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/init/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAgB,MAAM,YAAY,CAAC;AAgIxE;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAiF3E;AAwjBD,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/init/executor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAgB,MAAM,YAAY,CAAC;AAgIxE;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAiF3E;AAspBD,eAAe,WAAW,CAAC"}
@@ -397,35 +397,79 @@ async function copyAgents(targetDir, options, result) {
397
397
  }
398
398
  }
399
399
  }
400
+ /**
401
+ * Find source helpers directory
402
+ */
403
+ function findSourceHelpersDir(sourceBaseDir) {
404
+ const possiblePaths = [];
405
+ // If explicit source base directory is provided, check it first
406
+ if (sourceBaseDir) {
407
+ possiblePaths.push(path.join(sourceBaseDir, '.claude', 'helpers'));
408
+ }
409
+ // IMPORTANT: Check the package's own .claude/helpers directory
410
+ // This is the primary path when running as an npm package
411
+ // __dirname is typically /path/to/node_modules/@claude-flow/cli/dist/src/init
412
+ // We need to go up 4 levels to reach the package root
413
+ const packageRoot = path.resolve(__dirname, '..', '..', '..', '..');
414
+ const packageHelpers = path.join(packageRoot, '.claude', 'helpers');
415
+ if (fs.existsSync(packageHelpers)) {
416
+ possiblePaths.unshift(packageHelpers); // Add to beginning (highest priority)
417
+ }
418
+ // From dist/src/init -> go up to project root
419
+ let currentDir = __dirname;
420
+ for (let i = 0; i < 10; i++) {
421
+ const parentDir = path.dirname(currentDir);
422
+ const helpersPath = path.join(parentDir, '.claude', 'helpers');
423
+ if (fs.existsSync(helpersPath)) {
424
+ possiblePaths.push(helpersPath);
425
+ }
426
+ currentDir = parentDir;
427
+ }
428
+ // Also check relative to process.cwd() for development
429
+ const cwdBased = [
430
+ path.join(process.cwd(), '.claude', 'helpers'),
431
+ path.join(process.cwd(), '..', '.claude', 'helpers'),
432
+ path.join(process.cwd(), '..', '..', '.claude', 'helpers'),
433
+ ];
434
+ possiblePaths.push(...cwdBased);
435
+ for (const p of possiblePaths) {
436
+ if (fs.existsSync(p)) {
437
+ return p;
438
+ }
439
+ }
440
+ return null;
441
+ }
400
442
  /**
401
443
  * Write helper scripts
402
444
  */
403
445
  async function writeHelpers(targetDir, options, result) {
404
446
  const helpersDir = path.join(targetDir, '.claude', 'helpers');
405
- const sourceBaseDir = options.sourceBaseDir;
447
+ // Find source helpers directory (works for npm package and local dev)
448
+ const sourceHelpersDir = findSourceHelpersDir(options.sourceBaseDir);
406
449
  // Try to copy existing helpers from source first
407
- if (sourceBaseDir) {
408
- const sourceHelpersDir = path.join(sourceBaseDir, '.claude', 'helpers');
409
- if (fs.existsSync(sourceHelpersDir)) {
410
- const helperFiles = fs.readdirSync(sourceHelpersDir);
411
- for (const file of helperFiles) {
412
- const sourcePath = path.join(sourceHelpersDir, file);
413
- const destPath = path.join(helpersDir, file);
414
- // Skip directories and only copy files
415
- if (!fs.statSync(sourcePath).isFile())
416
- continue;
417
- if (!fs.existsSync(destPath) || options.force) {
418
- fs.copyFileSync(sourcePath, destPath);
419
- // Make shell scripts executable
420
- if (file.endsWith('.sh')) {
421
- fs.chmodSync(destPath, '755');
422
- }
423
- result.created.files.push(`.claude/helpers/${file}`);
424
- }
425
- else {
426
- result.skipped.push(`.claude/helpers/${file}`);
450
+ if (sourceHelpersDir && fs.existsSync(sourceHelpersDir)) {
451
+ const helperFiles = fs.readdirSync(sourceHelpersDir);
452
+ let copiedCount = 0;
453
+ for (const file of helperFiles) {
454
+ const sourcePath = path.join(sourceHelpersDir, file);
455
+ const destPath = path.join(helpersDir, file);
456
+ // Skip directories and only copy files
457
+ if (!fs.statSync(sourcePath).isFile())
458
+ continue;
459
+ if (!fs.existsSync(destPath) || options.force) {
460
+ fs.copyFileSync(sourcePath, destPath);
461
+ // Make shell scripts and mjs files executable
462
+ if (file.endsWith('.sh') || file.endsWith('.mjs')) {
463
+ fs.chmodSync(destPath, '755');
427
464
  }
465
+ result.created.files.push(`.claude/helpers/${file}`);
466
+ copiedCount++;
467
+ }
468
+ else {
469
+ result.skipped.push(`.claude/helpers/${file}`);
428
470
  }
471
+ }
472
+ if (copiedCount > 0) {
429
473
  return; // Skip generating if we copied from source
430
474
  }
431
475
  }
@@ -452,28 +496,61 @@ async function writeHelpers(targetDir, options, result) {
452
496
  }
453
497
  }
454
498
  }
499
+ /**
500
+ * Find source .claude directory for statusline files
501
+ */
502
+ function findSourceClaudeDir(sourceBaseDir) {
503
+ const possiblePaths = [];
504
+ // If explicit source base directory is provided, check it first
505
+ if (sourceBaseDir) {
506
+ possiblePaths.push(path.join(sourceBaseDir, '.claude'));
507
+ }
508
+ // IMPORTANT: Check the package's own .claude directory
509
+ const packageRoot = path.resolve(__dirname, '..', '..', '..', '..');
510
+ const packageClaude = path.join(packageRoot, '.claude');
511
+ if (fs.existsSync(packageClaude)) {
512
+ possiblePaths.unshift(packageClaude); // Add to beginning (highest priority)
513
+ }
514
+ // From dist/src/init -> go up to project root
515
+ let currentDir = __dirname;
516
+ for (let i = 0; i < 10; i++) {
517
+ const parentDir = path.dirname(currentDir);
518
+ const claudePath = path.join(parentDir, '.claude');
519
+ if (fs.existsSync(claudePath)) {
520
+ possiblePaths.push(claudePath);
521
+ }
522
+ currentDir = parentDir;
523
+ }
524
+ for (const p of possiblePaths) {
525
+ if (fs.existsSync(p)) {
526
+ return p;
527
+ }
528
+ }
529
+ return null;
530
+ }
455
531
  /**
456
532
  * Write statusline configuration
457
533
  */
458
534
  async function writeStatusline(targetDir, options, result) {
459
535
  const claudeDir = path.join(targetDir, '.claude');
460
536
  const helpersDir = path.join(targetDir, '.claude', 'helpers');
537
+ // Find source .claude directory (works for npm package and local dev)
538
+ const sourceClaudeDir = findSourceClaudeDir(options.sourceBaseDir);
461
539
  // Try to copy existing advanced statusline files from source
462
- const sourceBaseDir = options.sourceBaseDir;
463
540
  const advancedStatuslineFiles = [
464
541
  { src: 'statusline.sh', dest: 'statusline.sh', dir: claudeDir },
465
542
  { src: 'statusline.mjs', dest: 'statusline.mjs', dir: claudeDir },
466
543
  ];
467
544
  let copiedAdvanced = false;
468
- if (sourceBaseDir) {
545
+ if (sourceClaudeDir) {
469
546
  for (const file of advancedStatuslineFiles) {
470
- const sourcePath = path.join(sourceBaseDir, '.claude', file.src);
547
+ const sourcePath = path.join(sourceClaudeDir, file.src);
471
548
  const destPath = path.join(file.dir, file.dest);
472
549
  if (fs.existsSync(sourcePath)) {
473
550
  if (!fs.existsSync(destPath) || options.force) {
474
551
  fs.copyFileSync(sourcePath, destPath);
475
- // Make shell scripts executable
476
- if (file.src.endsWith('.sh')) {
552
+ // Make shell scripts and mjs executable
553
+ if (file.src.endsWith('.sh') || file.src.endsWith('.mjs')) {
477
554
  fs.chmodSync(destPath, '755');
478
555
  }
479
556
  result.created.files.push(`.claude/${file.dest}`);