claude-flow-novice 1.5.5 → 1.5.7

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.
@@ -1,444 +1,66 @@
1
- #!/bin/bash
2
-
3
- ###############################################################################
4
- # Claude SDK Emergency Rollback Script
5
- # Restores system to pre-SDK state
6
- ###############################################################################
7
-
8
- set -e
9
-
10
- # Colors
11
- RED='\033[0;31m'
12
- GREEN='\033[0;32m'
13
- YELLOW='\033[1;33m'
14
- BLUE='\033[0;34m'
15
- NC='\033[0m'
16
-
17
- # Configuration
18
- BACKUP_DIR="./backups/pre-sdk-snapshot"
19
- ROLLBACK_LOG="./logs/rollback-$(date +%Y%m%d-%H%M%S).log"
20
- TIMESTAMP=$(date +'%Y-%m-%d %H:%M:%S')
21
-
22
- # Logging
23
- log() { echo -e "${GREEN}[$TIMESTAMP]${NC} $1" | tee -a "$ROLLBACK_LOG"; }
24
- warn() { echo -e "${YELLOW}[$TIMESTAMP] WARNING:${NC} $1" | tee -a "$ROLLBACK_LOG"; }
25
- error() { echo -e "${RED}[$TIMESTAMP] ERROR:${NC} $1" | tee -a "$ROLLBACK_LOG"; }
26
- info() { echo -e "${BLUE}[$TIMESTAMP] INFO:${NC} $1" | tee -a "$ROLLBACK_LOG"; }
27
-
28
- mkdir -p logs
29
-
30
- log "========================================="
31
- log "🚨 EMERGENCY ROLLBACK INITIATED"
32
- log "========================================="
33
-
34
- # Pre-rollback checks
35
- check_backup() {
36
- if [ ! -d "$BACKUP_DIR" ]; then
37
- error "Backup directory not found: $BACKUP_DIR"
38
- error "Cannot proceed with rollback without backup!"
39
- exit 1
40
- fi
41
-
42
- info "Backup directory found: $BACKUP_DIR"
43
-
44
- # List backup contents
45
- info "Backup contents:"
46
- ls -lh "$BACKUP_DIR" | tee -a "$ROLLBACK_LOG"
47
- }
48
-
49
- # Capture current state for postmortem
50
- capture_failure_state() {
51
- log "Capturing failure state for analysis..."
52
-
53
- local failure_dir="./backups/failure-$(date +%Y%m%d-%H%M%S)"
54
- mkdir -p "$failure_dir"
55
-
56
- # Capture metrics
57
- if [ -f ".metrics-snapshot" ]; then
58
- cp .metrics-snapshot "$failure_dir/metrics-at-failure.json"
59
- info "Metrics snapshot saved"
60
- fi
61
-
62
- # Capture logs
63
- if [ -f "logs/sdk-migration.log" ]; then
64
- cp logs/sdk-migration.log "$failure_dir/migration-log.txt"
65
- info "Migration log saved"
66
- fi
67
-
68
- # Capture alerts
69
- if [ -f "logs/alerts.json" ]; then
70
- cp logs/alerts.json "$failure_dir/alerts.json"
71
- info "Alerts saved"
72
- fi
73
-
74
- # Capture environment
75
- env | grep -E "SDK|CLAUDE|ENABLE" > "$failure_dir/environment.txt" || true
76
- info "Environment variables saved"
77
-
78
- # Capture current phase
79
- if [ -f ".migration-phase" ]; then
80
- cp .migration-phase "$failure_dir/phase-at-failure.txt"
81
- info "Migration phase saved"
82
- fi
83
-
84
- # Capture git state
85
- git rev-parse HEAD > "$failure_dir/git-commit.txt" 2>/dev/null || true
86
- git status > "$failure_dir/git-status.txt" 2>/dev/null || true
87
- git diff > "$failure_dir/git-diff.txt" 2>/dev/null || true
88
-
89
- log "✅ Failure state captured at: $failure_dir"
90
- echo "$failure_dir" > .last-failure-dir
91
- }
92
-
93
- # Stop services
94
- stop_services() {
95
- log "Stopping all services..."
96
-
97
- # Stop dashboard
98
- if pgrep -f "dashboard" > /dev/null; then
99
- info "Stopping dashboard..."
100
- pkill -f "dashboard" || true
101
- sleep 2
102
- fi
103
-
104
- # Stop monitoring
105
- if pgrep -f "monitor-migration" > /dev/null; then
106
- info "Stopping migration monitor..."
107
- pkill -f "monitor-migration" || true
108
- sleep 2
109
- fi
110
-
111
- # Stop application
112
- npm run stop 2>/dev/null || true
113
- sleep 3
114
-
115
- log "✅ Services stopped"
116
- }
117
-
118
- # Restore environment
119
- restore_environment() {
120
- log "Restoring environment configuration..."
121
-
122
- if [ -f "$BACKUP_DIR/.env.backup" ]; then
123
- cp "$BACKUP_DIR/.env.backup" .env
124
- log "✅ .env restored"
125
- else
126
- warn "No .env backup found"
127
-
128
- # Remove SDK-related variables
129
- if [ -f ".env" ]; then
130
- info "Removing SDK variables from .env..."
131
- sed -i '/SDK_/d' .env
132
- sed -i '/ENABLE_SDK_/d' .env
133
- sed -i '/ENABLE_SELF_VALIDATION/d' .env
134
- sed -i '/VALIDATION_MODE/d' .env
135
- sed -i '/CONFIDENCE_THRESHOLD/d' .env
136
- fi
137
- fi
138
- }
139
-
140
- # Restore package.json
141
- restore_packages() {
142
- log "Restoring package dependencies..."
143
-
144
- if [ -f "$BACKUP_DIR/package.json.backup" ]; then
145
- cp "$BACKUP_DIR/package.json.backup" package.json
146
- log "✅ package.json restored"
147
-
148
- info "Reinstalling dependencies..."
149
- npm install 2>&1 | tee -a "$ROLLBACK_LOG"
150
- else
151
- warn "No package.json backup found"
152
-
153
- # Remove SDK package
154
- info "Removing Claude Agent SDK..."
155
- npm uninstall @anthropic-ai/claude-agent-sdk 2>&1 | tee -a "$ROLLBACK_LOG" || true
156
- fi
157
- }
158
-
159
- # Restore git state
160
- restore_git() {
161
- log "Restoring git state..."
162
-
163
- if [ -f "$BACKUP_DIR/git-commit.txt" ]; then
164
- local commit=$(cat "$BACKUP_DIR/git-commit.txt")
165
- info "Restoring to commit: $commit"
166
-
167
- # Stash any changes
168
- git stash push -m "Pre-rollback stash $(date +%Y%m%d-%H%M%S)" 2>/dev/null || true
169
-
170
- # Checkout commit
171
- git checkout "$commit" 2>&1 | tee -a "$ROLLBACK_LOG" || {
172
- error "Could not restore git commit"
173
- warn "Manual git restore may be required"
174
- }
175
-
176
- log "✅ Git state restored"
177
- else
178
- warn "No git commit backup found"
179
- info "Current git state will be preserved"
180
- fi
181
- }
182
-
183
- # Restore database (if applicable)
184
- restore_database() {
185
- log "Checking for database backups..."
186
-
187
- if [ -f "$BACKUP_DIR/database.backup.db" ]; then
188
- info "Restoring database..."
189
- cp "$BACKUP_DIR/database.backup.db" ./data/swarm.db
190
- log "✅ Database restored"
191
- else
192
- info "No database backup found (may not be needed)"
193
- fi
194
- }
195
-
196
- # Clean SDK artifacts
197
- clean_sdk_artifacts() {
198
- log "Cleaning SDK artifacts..."
199
-
200
- # Remove phase marker
201
- rm -f .migration-phase
202
- info "Removed phase marker"
203
-
204
- # Remove metrics snapshot
205
- rm -f .metrics-snapshot
206
- info "Removed metrics snapshot"
207
-
208
- # Clean SDK cache (if any)
209
- if [ -d ".sdk-cache" ]; then
210
- rm -rf .sdk-cache
211
- info "Removed SDK cache"
212
- fi
213
-
214
- # Clean SDK logs
215
- if [ -d "logs/sdk" ]; then
216
- mv logs/sdk "logs/sdk-$(date +%Y%m%d-%H%M%S).backup"
217
- info "Archived SDK logs"
218
- fi
219
-
220
- log "✅ SDK artifacts cleaned"
221
- }
222
-
223
- # Validate rollback
224
- validate_rollback() {
225
- log "Validating rollback..."
226
-
227
- # Check critical files exist
228
- local critical_files=(
229
- "package.json"
230
- ".env"
231
- "src/index.js"
232
- )
233
-
234
- for file in "${critical_files[@]}"; do
235
- if [ ! -f "$file" ]; then
236
- error "Critical file missing after rollback: $file"
237
- return 1
238
- fi
239
- done
240
-
241
- # Check SDK is not installed
242
- if npm list @anthropic-ai/claude-agent-sdk > /dev/null 2>&1; then
243
- warn "SDK still appears to be installed"
244
- info "Attempting to remove..."
245
- npm uninstall @anthropic-ai/claude-agent-sdk || true
246
- fi
247
-
248
- # Check environment variables
249
- if grep -q "ENABLE_SDK_INTEGRATION=true" .env 2>/dev/null; then
250
- warn "SDK environment variables still present"
251
- sed -i '/ENABLE_SDK_INTEGRATION/d' .env
252
- fi
253
-
254
- log "✅ Rollback validation passed"
255
- }
256
-
257
- # Restart services
258
- restart_services() {
259
- log "Restarting services with pre-SDK configuration..."
260
-
261
- # Start application
262
- info "Starting application..."
263
- npm run start &
264
- local APP_PID=$!
265
-
266
- # Wait for startup
267
- sleep 10
268
-
269
- # Check if running
270
- if ps -p $APP_PID > /dev/null; then
271
- log "✅ Application started successfully (PID: $APP_PID)"
272
- else
273
- error "Application failed to start"
274
- return 1
275
- fi
276
- }
277
-
278
- # Run post-rollback tests
279
- run_tests() {
280
- log "Running post-rollback validation tests..."
281
-
282
- # Run basic tests
283
- info "Running unit tests..."
284
- if npm test 2>&1 | tee -a "$ROLLBACK_LOG"; then
285
- log "✅ Tests passed"
286
- else
287
- error "Tests failed after rollback"
288
- warn "Manual intervention may be required"
289
- return 1
290
- fi
291
- }
292
-
293
- # Generate rollback report
294
- generate_report() {
295
- log "Generating rollback report..."
296
-
297
- local report_file="./logs/rollback-report-$(date +%Y%m%d-%H%M%S).md"
298
-
299
- cat > "$report_file" << EOF
300
- # SDK Rollback Report
301
-
302
- **Date:** $(date)
303
- **Status:** Complete
304
- **Duration:** $((SECONDS / 60)) minutes
305
-
306
- ## Rollback Details
307
-
308
- ### Pre-Rollback State
309
- - **Phase:** $(cat "$BACKUP_DIR/../failure-$(date +%Y%m%d)*/phase-at-failure.txt" 2>/dev/null || echo "Unknown")
310
- - **Failure State:** $(cat .last-failure-dir 2>/dev/null || echo "Not captured")
311
-
312
- ### Actions Taken
313
- 1. ✅ Services stopped
314
- 2. ✅ Failure state captured
315
- 3. ✅ Environment restored
316
- 4. ✅ Dependencies restored
317
- 5. ✅ Git state restored
318
- 6. ✅ SDK artifacts cleaned
319
- 7. ✅ Rollback validated
320
- 8. ✅ Services restarted
321
- 9. ✅ Tests executed
322
-
323
- ### Validation Results
324
- - Environment: ✅ Restored
325
- - Dependencies: ✅ Restored
326
- - Git State: ✅ Restored
327
- - Tests: ✅ Passed
328
- - Services: ✅ Running
329
-
330
- ### Post-Rollback Metrics
331
- $(cat .metrics-snapshot 2>/dev/null || echo "No metrics available")
332
-
333
- ## Next Steps
334
-
335
- 1. **Investigate Failure:**
336
- - Review failure state at: $(cat .last-failure-dir 2>/dev/null || echo "Unknown")
337
- - Analyze logs: logs/sdk-migration.log
338
- - Check alerts: logs/alerts.json
339
-
340
- 2. **Root Cause Analysis:**
341
- - Identify what caused the rollback
342
- - Document findings
343
- - Create fix plan
344
-
345
- 3. **Prepare for Retry:**
346
- - Fix identified issues
347
- - Update configuration
348
- - Plan retry strategy
349
-
350
- 4. **Monitor:**
351
- - Watch system health for 24 hours
352
- - Verify baseline metrics
353
- - Ensure stability before retry
354
-
355
- ## Support
356
- - **Rollback Log:** $ROLLBACK_LOG
357
- - **Failure State:** $(cat .last-failure-dir 2>/dev/null || echo "Unknown")
358
- - **Documentation:** docs/sdk-migration-guide.md
359
-
360
- ---
361
- *Generated automatically by rollback-sdk.sh*
362
- EOF
363
-
364
- log "✅ Report generated: $report_file"
365
- cat "$report_file"
366
- }
367
-
368
- # Main rollback procedure
369
- main() {
370
- local start_time=$SECONDS
371
-
372
- log "Starting rollback procedure..."
373
- log "Timestamp: $TIMESTAMP"
374
-
375
- # Execute rollback steps
376
- check_backup || exit 1
377
- capture_failure_state
378
- stop_services
379
- restore_environment
380
- restore_packages
381
- restore_git
382
- restore_database
383
- clean_sdk_artifacts
384
- validate_rollback || {
385
- error "Rollback validation failed!"
386
- error "System may be in inconsistent state"
387
- exit 1
388
- }
389
- restart_services || {
390
- error "Failed to restart services"
391
- exit 1
392
- }
393
- run_tests || warn "Tests failed - manual review needed"
394
-
395
- # Generate report
396
- generate_report
397
-
398
- local duration=$((SECONDS - start_time))
399
-
400
- log "========================================="
401
- log "✅ ROLLBACK COMPLETE"
402
- log "Duration: $((duration / 60))m $((duration % 60))s"
403
- log "========================================="
404
-
405
- info ""
406
- info "Next Steps:"
407
- info "1. Review rollback report: ./logs/rollback-report-*.md"
408
- info "2. Investigate failure state: $(cat .last-failure-dir 2>/dev/null)"
409
- info "3. Monitor system health: npm run dashboard"
410
- info "4. Document findings before retry"
411
- info ""
412
-
413
- log "Rollback log saved to: $ROLLBACK_LOG"
414
- }
415
-
416
- # Handle command line
417
- case "${1:-rollback}" in
418
- rollback)
419
- main
420
- ;;
421
- status)
422
- if [ -f ".last-failure-dir" ]; then
423
- echo "Last failure state: $(cat .last-failure-dir)"
424
- if [ -d "$(cat .last-failure-dir)" ]; then
425
- echo "Failure files:"
426
- ls -lh "$(cat .last-failure-dir)"
427
- fi
428
- else
429
- echo "No previous rollback found"
430
- fi
431
- ;;
432
- report)
433
- if [ -f "./logs/rollback-report-"*.md ]; then
434
- latest=$(ls -t ./logs/rollback-report-*.md | head -1)
435
- cat "$latest"
436
- else
437
- echo "No rollback reports found"
438
- fi
439
- ;;
440
- *)
441
- echo "Usage: $0 {rollback|status|report}"
442
- exit 1
443
- ;;
444
- esac
1
+ #!/bin/bash
2
+
3
+ # Claude Agent SDK - Rollback Script
4
+ # Instant rollback of SDK integration
5
+
6
+ set -e
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
10
+ BACKUP_DIR="$PROJECT_ROOT/.sdk-backup"
11
+ LOG_FILE="$PROJECT_ROOT/sdk-rollback.log"
12
+
13
+ # Colors
14
+ RED='\033[0;31m'
15
+ GREEN='\033[0;32m'
16
+ YELLOW='\033[1;33m'
17
+ BLUE='\033[0;34m'
18
+ NC='\033[0m'
19
+
20
+ log() {
21
+ echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1" | tee -a "$LOG_FILE"
22
+ }
23
+
24
+ error() {
25
+ echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"
26
+ }
27
+
28
+ success() {
29
+ echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE"
30
+ }
31
+
32
+ echo "=== SDK Rollback Log ===" > "$LOG_FILE"
33
+ log "Starting SDK rollback..."
34
+
35
+ # Disable SDK in environment
36
+ log "Disabling SDK integration..."
37
+ if [ -f "$PROJECT_ROOT/.env" ]; then
38
+ sed -i.bak '/^# Claude Agent SDK Configuration/,/^$/d' "$PROJECT_ROOT/.env"
39
+ sed -i.bak '/^ENABLE_SDK/d' "$PROJECT_ROOT/.env"
40
+ sed -i.bak '/^SDK_/d' "$PROJECT_ROOT/.env"
41
+ success "SDK environment variables removed"
42
+ fi
43
+
44
+ # Restore backup if needed
45
+ if [ -f "$BACKUP_DIR/.env.backup" ]; then
46
+ log "Restoring environment from backup..."
47
+ cp "$BACKUP_DIR/.env.backup" "$PROJECT_ROOT/.env"
48
+ success "Environment restored"
49
+ fi
50
+
51
+ success "Rollback complete!"
52
+
53
+ cat <<EOF
54
+
55
+ ╔══════════════════════════════════════════════════════════════╗
56
+ ║ SDK Rollback Successful ║
57
+ ╚══════════════════════════════════════════════════════════════╝
58
+
59
+ SDK Integration: DISABLED
60
+ ✅ System: Restored to pre-SDK state
61
+
62
+ 📁 Rollback log: $LOG_FILE
63
+
64
+ EOF
65
+
66
+ log "Rollback complete. System restored."
@@ -44,8 +44,6 @@ import { createLocalExecutable } from './executable-wrapper.js';
44
44
  import { createSparcStructureManually } from './sparc-structure.js';
45
45
  import { createClaudeSlashCommands } from './claude-commands/slash-commands.js';
46
46
  import { createOptimizedClaudeSlashCommands } from './claude-commands/optimized-slash-commands.js';
47
- // execSync imported above as execSyncOriginal\nconst execSync = execSyncOriginal;
48
- import { promises as fs } from 'fs';
49
47
  import { copyTemplates } from './template-copier.js';
50
48
  import { copyRevisedTemplates, validateTemplatesExist } from './copy-revised-templates.js';
51
49
  import {