claude-flow-novice 1.5.4 → 1.5.5

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.
@@ -105,6 +105,7 @@ async function readClaudeMdTemplate() {
105
105
  for (const templatePath of possiblePaths) {
106
106
  try {
107
107
  const content = await fs.readFile(templatePath, 'utf8');
108
+ console.log(`✅ Using CLAUDE.md template from: ${templatePath}`);
108
109
  return content;
109
110
  } catch (error) {
110
111
  // Try next path
@@ -112,9 +113,8 @@ async function readClaudeMdTemplate() {
112
113
  }
113
114
  }
114
115
 
115
- // Fallback to generating if template file is not found in any location
116
- console.warn('Warning: Template file not found in any location, using generated content');
117
- return createOptimizedSparcClaudeMd();
116
+ // If template not found, throw error instead of falling back
117
+ throw new Error('CLAUDE.md template file not found! Please ensure templates are included in the build.');
118
118
  }
119
119
 
120
120
  /**
@@ -7,16 +7,34 @@
7
7
  * Keeps it focused and lightweight - no bloat!
8
8
  */
9
9
 
10
- import { ClaudeMdGenerator } from '../language/claude-md-generator.js';
11
- import { LanguageDetector } from '../language/language-detector.js';
12
10
  import fs from 'fs/promises';
13
11
  import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+ import { dirname } from 'path';
14
14
 
15
15
  export class ClaudeMdSlashCommand {
16
16
  constructor(projectPath = process.cwd()) {
17
17
  this.projectPath = projectPath;
18
18
  this.claudeMdPath = path.join(projectPath, 'CLAUDE.md');
19
19
  this.copyToMainPath = path.join(projectPath, 'claude-copy-to-main.md');
20
+
21
+ // Get the directory of this module to find the template
22
+ const __filename = fileURLToPath(import.meta.url);
23
+ const __dirname = dirname(__filename);
24
+ this.templatePath = path.join(__dirname, '..', 'cli', 'simple-commands', 'init', 'templates', 'CLAUDE.md');
25
+ }
26
+
27
+ /**
28
+ * Read the CLAUDE.md template file
29
+ */
30
+ async readTemplate() {
31
+ try {
32
+ const content = await fs.readFile(this.templatePath, 'utf8');
33
+ console.log('✅ Using CLAUDE.md template');
34
+ return content;
35
+ } catch (error) {
36
+ throw new Error(`CLAUDE.md template not found at ${this.templatePath}`);
37
+ }
20
38
  }
21
39
 
22
40
  /**
@@ -37,13 +55,8 @@ export class ClaudeMdSlashCommand {
37
55
  const existingClaudeExists = await this.fileExists(this.claudeMdPath);
38
56
  const shouldUseNpxProtection = isNpxInstall && existingClaudeExists;
39
57
 
40
- // Step 2: Generate content using existing system
41
- const generator = new ClaudeMdGenerator(this.projectPath, {
42
- backupExisting: backup && !shouldUseNpxProtection,
43
- preserveCustomSections: true
44
- });
45
-
46
- const newContent = await generator.generateClaudeMd();
58
+ // Step 2: Read template content (no language detection, just use template)
59
+ const newContent = await this.readTemplate();
47
60
 
48
61
  // Step 3: Handle NPX protection
49
62
  if (shouldUseNpxProtection) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow-novice",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "description": "Standalone Claude Flow for beginners - AI agent orchestration made easy with enhanced TDD testing pipeline. Enhanced init command creates complete agent system, MCP configuration with 30 essential tools, and automated hooks with single-file testing, real-time coverage analysis, and advanced validation. Fully standalone with zero external dependencies, complete project setup in one command.",
5
5
  "mcpName": "io.github.ruvnet/claude-flow",
6
6
  "main": ".claude-flow-novice/dist/index.js",
@@ -226,6 +226,7 @@
226
226
  "./hooks/enhanced-hooks-cli": "./.claude-flow-novice/dist/src/hooks/enhanced-hooks-cli.js"
227
227
  },
228
228
  "dependencies": {
229
+ "@anthropic-ai/claude-agent-sdk": "^0.1.1",
229
230
  "@modelcontextprotocol/sdk": "^1.18.2",
230
231
  "boxen": "^8.0.1",
231
232
  "chalk": "^4.1.2",
@@ -0,0 +1,520 @@
1
+ #!/bin/bash
2
+
3
+ ###############################################################################
4
+ # Claude SDK Migration Script
5
+ # Phase 4: Production Optimization
6
+ #
7
+ # Performs gradual rollout of SDK integration with validation and rollback
8
+ ###############################################################################
9
+
10
+ set -e
11
+
12
+ # Colors for output
13
+ RED='\033[0;31m'
14
+ GREEN='\033[0;32m'
15
+ YELLOW='\033[1;33m'
16
+ BLUE='\033[0;34m'
17
+ NC='\033[0m' # No Color
18
+
19
+ # Configuration
20
+ MIGRATION_LOG="./logs/sdk-migration.log"
21
+ ROLLBACK_SNAPSHOT="./backups/pre-sdk-snapshot"
22
+ VALIDATION_THRESHOLD=0.95
23
+ MAX_ERROR_RATE=0.01
24
+
25
+ # Create required directories
26
+ mkdir -p logs backups
27
+
28
+ # Logging functions
29
+ log() {
30
+ echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1" | tee -a "$MIGRATION_LOG"
31
+ }
32
+
33
+ warn() {
34
+ echo -e "${YELLOW}[$(date +'%Y-%m-%d %H:%M:%S')] WARNING:${NC} $1" | tee -a "$MIGRATION_LOG"
35
+ }
36
+
37
+ error() {
38
+ echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] ERROR:${NC} $1" | tee -a "$MIGRATION_LOG"
39
+ }
40
+
41
+ info() {
42
+ echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')] INFO:${NC} $1" | tee -a "$MIGRATION_LOG"
43
+ }
44
+
45
+ # Phase detection
46
+ get_current_phase() {
47
+ if [ -f ".migration-phase" ]; then
48
+ cat .migration-phase
49
+ else
50
+ echo "0"
51
+ fi
52
+ }
53
+
54
+ set_phase() {
55
+ echo "$1" > .migration-phase
56
+ log "Migration phase set to: $1"
57
+ }
58
+
59
+ # Backup current state
60
+ create_backup() {
61
+ log "Creating backup snapshot..."
62
+
63
+ mkdir -p "$ROLLBACK_SNAPSHOT"
64
+
65
+ # Backup critical files
66
+ cp .env "$ROLLBACK_SNAPSHOT/.env.backup" 2>/dev/null || true
67
+ cp package.json "$ROLLBACK_SNAPSHOT/package.json.backup"
68
+
69
+ # Backup current metrics
70
+ if [ -f ".metrics-snapshot" ]; then
71
+ cp .metrics-snapshot "$ROLLBACK_SNAPSHOT/metrics-snapshot.backup"
72
+ fi
73
+
74
+ # Store current git commit
75
+ git rev-parse HEAD > "$ROLLBACK_SNAPSHOT/git-commit.txt" 2>/dev/null || true
76
+
77
+ log "✅ Backup created at: $ROLLBACK_SNAPSHOT"
78
+ }
79
+
80
+ # Restore from backup
81
+ restore_backup() {
82
+ error "Restoring from backup..."
83
+
84
+ if [ ! -d "$ROLLBACK_SNAPSHOT" ]; then
85
+ error "No backup found! Cannot rollback."
86
+ exit 1
87
+ fi
88
+
89
+ # Restore environment
90
+ cp "$ROLLBACK_SNAPSHOT/.env.backup" .env 2>/dev/null || true
91
+
92
+ # Restore git state if available
93
+ if [ -f "$ROLLBACK_SNAPSHOT/git-commit.txt" ]; then
94
+ COMMIT=$(cat "$ROLLBACK_SNAPSHOT/git-commit.txt")
95
+ git checkout "$COMMIT" 2>/dev/null || warn "Could not restore git commit"
96
+ fi
97
+
98
+ # Restart services
99
+ npm run stop 2>/dev/null || true
100
+ npm run start
101
+
102
+ log "✅ Rollback complete"
103
+ }
104
+
105
+ # Validate SDK installation
106
+ validate_sdk_installation() {
107
+ log "Validating SDK installation..."
108
+
109
+ if ! npm list @anthropic-ai/claude-agent-sdk > /dev/null 2>&1; then
110
+ warn "SDK not installed. Installing..."
111
+ npm install @anthropic-ai/claude-agent-sdk
112
+ fi
113
+
114
+ # Verify SDK can be required
115
+ node -e "require('@anthropic-ai/claude-agent-sdk')" || {
116
+ error "SDK installation failed"
117
+ return 1
118
+ }
119
+
120
+ log "✅ SDK installation validated"
121
+ return 0
122
+ }
123
+
124
+ # Run tests
125
+ run_tests() {
126
+ local test_type=$1
127
+ log "Running $test_type tests..."
128
+
129
+ case $test_type in
130
+ "unit")
131
+ npm test -- --testPathPattern="src/sdk" || return 1
132
+ ;;
133
+ "integration")
134
+ npm run test:integration || return 1
135
+ ;;
136
+ "performance")
137
+ npm run test:performance || return 1
138
+ ;;
139
+ *)
140
+ npm test || return 1
141
+ ;;
142
+ esac
143
+
144
+ log "✅ $test_type tests passed"
145
+ return 0
146
+ }
147
+
148
+ # Collect metrics
149
+ collect_metrics() {
150
+ log "Collecting current metrics..."
151
+
152
+ # Make metrics collection request
153
+ local metrics=$(curl -s http://localhost:3000/api/summary 2>/dev/null || echo "{}")
154
+
155
+ if [ "$metrics" = "{}" ]; then
156
+ warn "Could not collect metrics - dashboard may not be running"
157
+ return 1
158
+ fi
159
+
160
+ echo "$metrics" > .metrics-snapshot
161
+ log "✅ Metrics collected"
162
+ return 0
163
+ }
164
+
165
+ # Validate metrics
166
+ validate_metrics() {
167
+ log "Validating metrics against thresholds..."
168
+
169
+ if [ ! -f ".metrics-snapshot" ]; then
170
+ warn "No metrics snapshot found"
171
+ return 1
172
+ fi
173
+
174
+ # Extract key metrics using node
175
+ local validation_result=$(node -e "
176
+ const metrics = require('./.metrics-snapshot');
177
+ const validationSuccess = metrics.quality?.validationSuccessRate || 0;
178
+ const errorRate = metrics.performance?.errorRate || 1;
179
+
180
+ const passed = validationSuccess >= $VALIDATION_THRESHOLD && errorRate <= $MAX_ERROR_RATE;
181
+
182
+ console.log(JSON.stringify({
183
+ passed,
184
+ validationSuccess,
185
+ errorRate,
186
+ message: passed ? 'Metrics validation passed' : 'Metrics validation failed'
187
+ }));
188
+ ")
189
+
190
+ local passed=$(echo "$validation_result" | node -pe "JSON.parse(require('fs').readFileSync(0)).passed")
191
+
192
+ if [ "$passed" = "true" ]; then
193
+ log "✅ Metrics validation passed"
194
+ return 0
195
+ else
196
+ error "❌ Metrics validation failed"
197
+ echo "$validation_result" | tee -a "$MIGRATION_LOG"
198
+ return 1
199
+ fi
200
+ }
201
+
202
+ # Phase 0: Pre-migration setup
203
+ phase_0_setup() {
204
+ log "========================================="
205
+ log "Phase 0: Pre-migration Setup"
206
+ log "========================================="
207
+
208
+ # Create backup
209
+ create_backup
210
+
211
+ # Validate environment
212
+ if [ ! -f ".env" ]; then
213
+ warn "No .env file found. Creating from template..."
214
+ cp .env.example .env 2>/dev/null || {
215
+ error "No .env.example found. Please create .env manually."
216
+ return 1
217
+ }
218
+ fi
219
+
220
+ # Check for API key
221
+ if ! grep -q "CLAUDE_API_KEY" .env; then
222
+ error "CLAUDE_API_KEY not found in .env"
223
+ return 1
224
+ fi
225
+
226
+ # Install SDK
227
+ validate_sdk_installation || return 1
228
+
229
+ # Run baseline tests
230
+ run_tests "unit" || return 1
231
+
232
+ set_phase 1
233
+ log "✅ Phase 0 complete - Ready for gradual rollout"
234
+ }
235
+
236
+ # Phase 1: Enable caching (5% traffic)
237
+ phase_1_caching() {
238
+ log "========================================="
239
+ log "Phase 1: Enable SDK Caching (5% traffic)"
240
+ log "========================================="
241
+
242
+ # Update environment variables
243
+ cat >> .env << EOF
244
+
245
+ # SDK Integration - Phase 1
246
+ ENABLE_SDK_INTEGRATION=true
247
+ SDK_INTEGRATION_MODE=parallel
248
+ ENABLE_SDK_CACHING=true
249
+ ENABLE_CONTEXT_EDITING=true
250
+ SDK_ROLLOUT_PERCENTAGE=5
251
+ EOF
252
+
253
+ log "Environment variables updated"
254
+
255
+ # Restart with new config
256
+ info "Restarting services..."
257
+ npm run stop 2>/dev/null || true
258
+ sleep 2
259
+ npm run start &
260
+
261
+ # Wait for startup
262
+ sleep 10
263
+
264
+ # Start monitoring
265
+ info "Starting monitoring dashboard..."
266
+ npm run dashboard &
267
+ DASHBOARD_PID=$!
268
+ sleep 5
269
+
270
+ # Collect initial metrics
271
+ collect_metrics || warn "Could not collect initial metrics"
272
+
273
+ # Monitor for 1 hour (or as specified)
274
+ local monitor_duration=${PHASE_1_DURATION:-3600}
275
+ info "Monitoring for $monitor_duration seconds..."
276
+
277
+ local start_time=$(date +%s)
278
+ local check_interval=60
279
+
280
+ while [ $(($(date +%s) - start_time)) -lt $monitor_duration ]; do
281
+ sleep $check_interval
282
+
283
+ collect_metrics
284
+
285
+ if ! validate_metrics; then
286
+ error "Metrics validation failed during Phase 1"
287
+ warn "Initiating rollback..."
288
+ restore_backup
289
+ return 1
290
+ fi
291
+
292
+ info "Phase 1 monitoring: $(($(date +%s) - start_time))s / ${monitor_duration}s"
293
+ done
294
+
295
+ log "✅ Phase 1 monitoring complete - Metrics stable"
296
+ set_phase 2
297
+ }
298
+
299
+ # Phase 2: Self-validation (25% traffic)
300
+ phase_2_validation() {
301
+ log "========================================="
302
+ log "Phase 2: Enable Self-Validation (25% traffic)"
303
+ log "========================================="
304
+
305
+ # Update rollout percentage
306
+ sed -i 's/SDK_ROLLOUT_PERCENTAGE=5/SDK_ROLLOUT_PERCENTAGE=25/' .env
307
+
308
+ # Enable self-validation
309
+ cat >> .env << EOF
310
+ ENABLE_SELF_VALIDATION=true
311
+ VALIDATION_MODE=parallel
312
+ CONFIDENCE_THRESHOLD=0.75
313
+ EOF
314
+
315
+ log "Self-validation enabled"
316
+
317
+ # Restart services
318
+ npm run stop 2>/dev/null || true
319
+ sleep 2
320
+ npm run start &
321
+ sleep 10
322
+
323
+ # Run validation tests
324
+ run_tests "integration" || {
325
+ error "Integration tests failed in Phase 2"
326
+ restore_backup
327
+ return 1
328
+ }
329
+
330
+ log "✅ Phase 2 complete - Self-validation working"
331
+ set_phase 3
332
+ }
333
+
334
+ # Phase 3: Full integration (75% traffic)
335
+ phase_3_full_integration() {
336
+ log "========================================="
337
+ log "Phase 3: Full SDK Integration (75% traffic)"
338
+ log "========================================="
339
+
340
+ # Update rollout percentage
341
+ sed -i 's/SDK_ROLLOUT_PERCENTAGE=25/SDK_ROLLOUT_PERCENTAGE=75/' .env
342
+
343
+ # Enable full features
344
+ cat >> .env << EOF
345
+ SDK_INTEGRATION=full
346
+ CONSENSUS_MODE=validated_only
347
+ MAX_PARALLEL_AGENTS=10
348
+ EOF
349
+
350
+ log "Full integration enabled"
351
+
352
+ # Restart services
353
+ npm run stop 2>/dev/null || true
354
+ sleep 2
355
+ npm run start &
356
+ sleep 10
357
+
358
+ # Run comprehensive tests
359
+ run_tests "integration" || {
360
+ error "Integration tests failed in Phase 3"
361
+ restore_backup
362
+ return 1
363
+ }
364
+
365
+ run_tests "performance" || {
366
+ error "Performance tests failed in Phase 3"
367
+ restore_backup
368
+ return 1
369
+ }
370
+
371
+ log "✅ Phase 3 complete - Full integration working"
372
+ set_phase 4
373
+ }
374
+
375
+ # Phase 4: Production (100% traffic)
376
+ phase_4_production() {
377
+ log "========================================="
378
+ log "Phase 4: Production Deployment (100% traffic)"
379
+ log "========================================="
380
+
381
+ # Update to 100%
382
+ sed -i 's/SDK_ROLLOUT_PERCENTAGE=75/SDK_ROLLOUT_PERCENTAGE=100/' .env
383
+
384
+ # Production configuration
385
+ cat >> .env << EOF
386
+ ENVIRONMENT=production
387
+ MONITORING_ENABLED=true
388
+ ALERTS_ENABLED=true
389
+ AUTO_ROLLBACK=true
390
+ EOF
391
+
392
+ log "Production configuration applied"
393
+
394
+ # Final restart
395
+ npm run stop 2>/dev/null || true
396
+ sleep 2
397
+ npm run start &
398
+ sleep 10
399
+
400
+ # Comprehensive validation
401
+ info "Running production validation..."
402
+ npm run validate:production || {
403
+ error "Production validation failed"
404
+ restore_backup
405
+ return 1
406
+ }
407
+
408
+ # Collect final metrics
409
+ collect_metrics
410
+
411
+ log "========================================="
412
+ log "✅ SDK MIGRATION COMPLETE!"
413
+ log "========================================="
414
+
415
+ # Print summary
416
+ info "Migration Summary:"
417
+ info " - Phase 0: Setup ✓"
418
+ info " - Phase 1: Caching (5%) ✓"
419
+ info " - Phase 2: Validation (25%) ✓"
420
+ info " - Phase 3: Integration (75%) ✓"
421
+ info " - Phase 4: Production (100%) ✓"
422
+ info ""
423
+ info "Dashboard: http://localhost:3000"
424
+ info "Logs: $MIGRATION_LOG"
425
+ info "Backup: $ROLLBACK_SNAPSHOT"
426
+
427
+ set_phase "complete"
428
+ }
429
+
430
+ # Rollback function
431
+ rollback() {
432
+ log "========================================="
433
+ log "INITIATING EMERGENCY ROLLBACK"
434
+ log "========================================="
435
+
436
+ local current_phase=$(get_current_phase)
437
+ error "Rolling back from phase: $current_phase"
438
+
439
+ restore_backup
440
+
441
+ # Reset phase
442
+ set_phase 0
443
+
444
+ error "Rollback complete. Please investigate issues before retrying."
445
+ exit 1
446
+ }
447
+
448
+ # Main migration flow
449
+ main() {
450
+ log "========================================="
451
+ log "Claude SDK Migration"
452
+ log "Started: $(date)"
453
+ log "========================================="
454
+
455
+ # Set up error handling
456
+ trap rollback ERR
457
+
458
+ local current_phase=$(get_current_phase)
459
+ local target_phase=${1:-4}
460
+
461
+ info "Current phase: $current_phase"
462
+ info "Target phase: $target_phase"
463
+
464
+ # Execute phases
465
+ if [ "$current_phase" -lt 1 ] && [ "$target_phase" -ge 1 ]; then
466
+ phase_0_setup || exit 1
467
+ fi
468
+
469
+ if [ "$current_phase" -lt 2 ] && [ "$target_phase" -ge 2 ]; then
470
+ phase_1_caching || exit 1
471
+ fi
472
+
473
+ if [ "$current_phase" -lt 3 ] && [ "$target_phase" -ge 3 ]; then
474
+ phase_2_validation || exit 1
475
+ fi
476
+
477
+ if [ "$current_phase" -lt 4 ] && [ "$target_phase" -ge 4 ]; then
478
+ phase_3_full_integration || exit 1
479
+ fi
480
+
481
+ if [ "$current_phase" -lt 5 ] && [ "$target_phase" -ge 4 ]; then
482
+ phase_4_production || exit 1
483
+ fi
484
+
485
+ log "========================================="
486
+ log "Migration completed successfully!"
487
+ log "Completed: $(date)"
488
+ log "========================================="
489
+ }
490
+
491
+ # Handle command line arguments
492
+ case "${1:-migrate}" in
493
+ migrate)
494
+ main "${2:-4}"
495
+ ;;
496
+ rollback)
497
+ rollback
498
+ ;;
499
+ status)
500
+ current_phase=$(get_current_phase)
501
+ echo "Current migration phase: $current_phase"
502
+ if [ -f ".metrics-snapshot" ]; then
503
+ echo "Latest metrics:"
504
+ cat .metrics-snapshot | node -pe "JSON.stringify(JSON.parse(require('fs').readFileSync(0)), null, 2)"
505
+ fi
506
+ ;;
507
+ validate)
508
+ validate_metrics
509
+ ;;
510
+ *)
511
+ echo "Usage: $0 {migrate|rollback|status|validate} [target_phase]"
512
+ echo ""
513
+ echo "Commands:"
514
+ echo " migrate [phase] - Run migration to specified phase (default: 4)"
515
+ echo " rollback - Rollback to pre-migration state"
516
+ echo " status - Show current migration status"
517
+ echo " validate - Validate current metrics"
518
+ exit 1
519
+ ;;
520
+ esac