claude-flow 2.7.34 → 2.7.36

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 (134) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/bin/claude-flow +1 -1
  3. package/dist/src/__tests__/benchmarks/performance.bench.js +0 -19
  4. package/dist/src/__tests__/benchmarks/performance.bench.js.map +1 -1
  5. package/dist/src/__tests__/hook-matchers.test.js.map +1 -1
  6. package/dist/src/agents/agent-registry.js.map +1 -1
  7. package/dist/src/api/auth-service.js.map +1 -1
  8. package/dist/src/api/claude-client-enhanced.js +4 -2
  9. package/dist/src/api/claude-client-enhanced.js.map +1 -1
  10. package/dist/src/api/claude-client.js +4 -2
  11. package/dist/src/api/claude-client.js.map +1 -1
  12. package/dist/src/api/database-service.js.map +1 -1
  13. package/dist/src/api/swarm-api.js +1 -1
  14. package/dist/src/api/swarm-api.js.map +1 -1
  15. package/dist/src/cli/commands/hive-mind/wizard.js +1 -1
  16. package/dist/src/cli/commands/hive-mind/wizard.js.map +1 -1
  17. package/dist/src/cli/help-formatter.js +0 -5
  18. package/dist/src/cli/init/index.js +55 -33
  19. package/dist/src/cli/init/index.js.map +1 -1
  20. package/dist/src/cli/simple-commands/init/skills-copier.js +1 -1
  21. package/dist/src/cli/simple-commands/init/skills-copier.js.map +1 -1
  22. package/dist/src/cli/simple-orchestrator.js +1 -1
  23. package/dist/src/cli/simple-orchestrator.js.map +1 -1
  24. package/dist/src/coordination/conflict-resolution.js +1 -1
  25. package/dist/src/coordination/conflict-resolution.js.map +1 -1
  26. package/dist/src/coordination/load-balancer.js +1 -1
  27. package/dist/src/coordination/load-balancer.js.map +1 -1
  28. package/dist/src/core/DatabaseManager.js +39 -9
  29. package/dist/src/core/DatabaseManager.js.map +1 -1
  30. package/dist/src/core/config.js +1 -1
  31. package/dist/src/core/config.js.map +1 -1
  32. package/dist/src/enterprise/audit-manager.js +1 -1
  33. package/dist/src/enterprise/audit-manager.js.map +1 -1
  34. package/dist/src/providers/openai-provider.js +2 -2
  35. package/dist/src/providers/openai-provider.js.map +1 -1
  36. package/dist/src/sdk/checkpoint-manager.js +1 -1
  37. package/dist/src/sdk/checkpoint-manager.js.map +1 -1
  38. package/dist/src/services/agentic-flow-hooks/workflow-hooks.js +1 -1
  39. package/dist/src/services/agentic-flow-hooks/workflow-hooks.js.map +1 -1
  40. package/dist/src/swarm/coordinator.js +1 -1
  41. package/dist/src/swarm/coordinator.js.map +1 -1
  42. package/dist/src/utils/error-recovery.js +215 -0
  43. package/dist/src/utils/error-recovery.js.map +1 -0
  44. package/dist/src/utils/key-redactor.js.map +1 -1
  45. package/dist/src/utils/metrics-reader.js +10 -0
  46. package/dist/src/verification/rollback.js +2 -2
  47. package/dist/src/verification/rollback.js.map +1 -1
  48. package/dist/src/verification/tests/mocks/false-reporting-scenarios.test.js +4 -2
  49. package/dist/src/verification/tests/mocks/false-reporting-scenarios.test.js.map +1 -1
  50. package/docs/.claude-flow/metrics/performance.json +3 -3
  51. package/docs/.claude-flow/metrics/task-metrics.json +3 -3
  52. package/docs/architecture/README.md +555 -0
  53. package/docs/architecture/github-workflows-optimization-strategy.md +1079 -0
  54. package/docs/architecture/workflow-architecture-diagram.md +615 -0
  55. package/docs/architecture/workflow-optimization-implementation-guide.md +593 -0
  56. package/docs/features/AUTOMATIC_ERROR_RECOVERY_v2.7.35.md +321 -0
  57. package/docs/features/automatic-error-recovery.md +333 -0
  58. package/docs/fixes/WORKFLOW_FIXES.md +292 -0
  59. package/docs/fixes/WORKFLOW_FIXES_FINAL_STATUS.md +291 -0
  60. package/docs/fixes/github-workflow-fixes-pr888.md +279 -0
  61. package/docs/fixes/workflow-fixes-action-plan.md +388 -0
  62. package/docs/github-issues/README.md +88 -0
  63. package/docs/github-issues/wsl-enotempty-automatic-recovery.md +470 -0
  64. package/docs/github-workflow-fixes.md +219 -0
  65. package/docs/reviews/github-workflows-analysis-report.md +820 -0
  66. package/docs/reviews/pr-888-review-report.md +560 -0
  67. package/docs/testing/CONFIRMATION_AUTOMATIC_ERROR_RECOVERY.md +384 -0
  68. package/docs/testing/DOCKER_TEST_RESULTS_v2.7.35.md +305 -0
  69. package/docs/troubleshooting/wsl-better-sqlite3-error.md +239 -0
  70. package/docs/validation/workflow-fix-verification.md +206 -0
  71. package/package.json +7 -7
  72. package/scripts/create-github-issue.sh +64 -0
  73. package/scripts/test-docker-wsl.sh +198 -0
  74. package/src/__tests__/benchmarks/performance.bench.ts +2 -25
  75. package/src/__tests__/hook-matchers.test.ts +2 -0
  76. package/src/agents/agent-registry.ts +1 -1
  77. package/src/api/auth-service.ts +1 -1
  78. package/src/api/claude-client-enhanced.ts +2 -1
  79. package/src/api/claude-client.ts +2 -2
  80. package/src/api/database-service.ts +1 -2
  81. package/src/api/swarm-api.ts +2 -2
  82. package/src/cli/commands/hive-mind/wizard.ts +1 -1
  83. package/src/cli/init/index.ts +72 -42
  84. package/src/cli/simple-commands/init/skills-copier.js +1 -1
  85. package/src/cli/simple-orchestrator.ts +1 -1
  86. package/src/coordination/conflict-resolution.ts +1 -1
  87. package/src/coordination/load-balancer.ts +1 -1
  88. package/src/core/DatabaseManager.ts +55 -9
  89. package/src/core/config.ts +1 -1
  90. package/src/enterprise/audit-manager.ts +1 -1
  91. package/src/providers/openai-provider.ts +2 -2
  92. package/src/sdk/checkpoint-manager.ts +1 -1
  93. package/src/services/agentic-flow-hooks/workflow-hooks.ts +1 -1
  94. package/src/swarm/coordinator.ts +1 -1
  95. package/src/utils/error-recovery.ts +325 -0
  96. package/src/verification/rollback.ts +2 -2
  97. package/src/verification/tests/mocks/false-reporting-scenarios.test.ts +6 -3
  98. /package/docs/{BUG_REPORT_MEMORY_STATS.md → bug-reports/BUG_REPORT_MEMORY_STATS.md} +0 -0
  99. /package/docs/{MCP_2025_FEATURE_CONFIRMATION.md → features/MCP_2025_FEATURE_CONFIRMATION.md} +0 -0
  100. /package/docs/{OPTIONAL_LOCAL_EMBEDDINGS.md → features/OPTIONAL_LOCAL_EMBEDDINGS.md} +0 -0
  101. /package/docs/{mcp-2025-implementation-summary.md → features/mcp-2025-implementation-summary.md} +0 -0
  102. /package/docs/{mcp-spec-2025-implementation-plan.md → features/mcp-spec-2025-implementation-plan.md} +0 -0
  103. /package/docs/{AGENTIC_FLOW_ENABLED_LOG_FIX.md → fixes/AGENTIC_FLOW_ENABLED_LOG_FIX.md} +0 -0
  104. /package/docs/{MEMORY_COMMAND_FIX.md → fixes/MEMORY_COMMAND_FIX.md} +0 -0
  105. /package/docs/{NPX_MEMORY_FIX_v2.7.19.md → fixes/NPX_MEMORY_FIX_v2.7.19.md} +0 -0
  106. /package/docs/{REMOTE_INSTALL_FIX.md → fixes/REMOTE_INSTALL_FIX.md} +0 -0
  107. /package/docs/{SQLITE_FIX_COMPLETE_v2.7.21.md → fixes/SQLITE_FIX_COMPLETE_v2.7.21.md} +0 -0
  108. /package/docs/{NPM_PUBLISH_GUIDE_v2.7.33.md → guides/NPM_PUBLISH_GUIDE_v2.7.33.md} +0 -0
  109. /package/docs/{SWARM_INITIALIZATION_GUIDE.md → guides/SWARM_INITIALIZATION_GUIDE.md} +0 -0
  110. /package/docs/{AGENTDB_BRANCH_MERGE_VERIFICATION.md → integration/AGENTDB_BRANCH_MERGE_VERIFICATION.md} +0 -0
  111. /package/docs/{INTEGRATION_STATUS_FINAL.md → integration/INTEGRATION_STATUS_FINAL.md} +0 -0
  112. /package/docs/{agentic-flow-agentdb-mcp-integration.md → integration/agentic-flow-agentdb-mcp-integration.md} +0 -0
  113. /package/docs/{phase-1-2-implementation-summary.md → integration/phase-1-2-implementation-summary.md} +0 -0
  114. /package/docs/{.github-release-issue-v2.7.33.md → releases/.github-release-issue-v2.7.33.md} +0 -0
  115. /package/docs/{RELEASE_NOTES_v2.7.15.md → releases/RELEASE_NOTES_v2.7.15.md} +0 -0
  116. /package/docs/{RELEASE_NOTES_v2.7.33.md → releases/RELEASE_NOTES_v2.7.33.md} +0 -0
  117. /package/docs/{RELEASE_READINESS_SUMMARY.md → releases/RELEASE_READINESS_SUMMARY.md} +0 -0
  118. /package/docs/{RELEASE_SUMMARY_v2.7.33.md → releases/RELEASE_SUMMARY_v2.7.33.md} +0 -0
  119. /package/docs/{V2.7.14_RELEASE_NOTES.md → releases/V2.7.14_RELEASE_NOTES.md} +0 -0
  120. /package/docs/{V2.7.25_RELEASE_NOTES.md → releases/V2.7.25_RELEASE_NOTES.md} +0 -0
  121. /package/docs/{V2.7.26_RELEASE_SUMMARY.md → releases/V2.7.26_RELEASE_SUMMARY.md} +0 -0
  122. /package/docs/{V2.7.27_RELEASE_NOTES.md → releases/V2.7.27_RELEASE_NOTES.md} +0 -0
  123. /package/docs/{V2.7.28_RELEASE_NOTES.md → releases/V2.7.28_RELEASE_NOTES.md} +0 -0
  124. /package/docs/{AGENTIC_FLOW_INTEGRATION_REVIEW.md → reviews/AGENTIC_FLOW_INTEGRATION_REVIEW.md} +0 -0
  125. /package/docs/{BRANCH_REVIEW_SUMMARY.md → reviews/BRANCH_REVIEW_SUMMARY.md} +0 -0
  126. /package/docs/{DEEP_CODE_REVIEW_v2.7.33.md → reviews/DEEP_CODE_REVIEW_v2.7.33.md} +0 -0
  127. /package/docs/{LATEST_LIBRARIES_REVIEW.md → reviews/LATEST_LIBRARIES_REVIEW.md} +0 -0
  128. /package/docs/{REGRESSION_TEST_REPORT_v2.7.33.md → testing/REGRESSION_TEST_REPORT_v2.7.33.md} +0 -0
  129. /package/docs/{V2.7.27_TEST_REPORT.md → testing/V2.7.27_TEST_REPORT.md} +0 -0
  130. /package/docs/{regression-analysis-phase-1-2.md → testing/regression-analysis-phase-1-2.md} +0 -0
  131. /package/docs/{TRANSFORMER_INITIALIZATION_ISSUE.md → troubleshooting/TRANSFORMER_INITIALIZATION_ISSUE.md} +0 -0
  132. /package/docs/{FIX_VERIFICATION_MEMORY_STATS.md → validation/FIX_VERIFICATION_MEMORY_STATS.md} +0 -0
  133. /package/docs/{TOOL_VALIDATION_REPORT.md → validation/TOOL_VALIDATION_REPORT.md} +0 -0
  134. /package/docs/{VALIDATION_REPORT_v2.7.1.md → validation/VALIDATION_REPORT_v2.7.1.md} +0 -0
@@ -0,0 +1,198 @@
1
+ #!/bin/bash
2
+ # Test automatic error recovery in Docker (simulates WSL)
3
+ # Run this before creating GitHub issue
4
+
5
+ set -e
6
+
7
+ echo "🐳 Testing Automatic Error Recovery in Docker"
8
+ echo ""
9
+
10
+ # Colors for output
11
+ GREEN='\033[0;32m'
12
+ RED='\033[0;31m'
13
+ YELLOW='\033[1;33m'
14
+ NC='\033[0m' # No Color
15
+
16
+ # Test configurations
17
+ DISTROS=("ubuntu:22.04" "ubuntu:20.04" "debian:11" "debian:12")
18
+ TEST_RESULTS=()
19
+
20
+ # Function to test on a distro
21
+ test_distro() {
22
+ local distro=$1
23
+ echo ""
24
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
25
+ echo "Testing on: $distro"
26
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
27
+ echo ""
28
+
29
+ # Run test in Docker
30
+ docker run --rm -i $distro bash -c "
31
+ set -e
32
+
33
+ echo '📦 Installing dependencies...'
34
+ apt-get update -qq
35
+ apt-get install -y -qq curl build-essential python3 git > /dev/null 2>&1
36
+
37
+ echo '📥 Installing Node.js...'
38
+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - > /dev/null 2>&1
39
+ apt-get install -y -qq nodejs > /dev/null 2>&1
40
+
41
+ echo '🔍 Node version:'
42
+ node --version
43
+ npm --version
44
+
45
+ echo ''
46
+ echo '🚀 Running claude-flow init --force...'
47
+ echo ''
48
+
49
+ # Run the actual test
50
+ npx claude-flow@alpha init --force
51
+
52
+ echo ''
53
+ echo '✅ Test completed successfully on $distro'
54
+ " && {
55
+ echo -e "${GREEN}✅ PASS: $distro${NC}"
56
+ TEST_RESULTS+=("PASS: $distro")
57
+ } || {
58
+ echo -e "${RED}❌ FAIL: $distro${NC}"
59
+ TEST_RESULTS+=("FAIL: $distro")
60
+ }
61
+ }
62
+
63
+ # Function to test with corrupted cache simulation
64
+ test_corrupted_cache() {
65
+ echo ""
66
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
67
+ echo "Testing with corrupted npm cache simulation"
68
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
69
+ echo ""
70
+
71
+ docker run --rm -i ubuntu:22.04 bash -c "
72
+ set -e
73
+
74
+ apt-get update -qq
75
+ apt-get install -y -qq curl build-essential python3 git > /dev/null 2>&1
76
+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - > /dev/null 2>&1
77
+ apt-get install -y -qq nodejs > /dev/null 2>&1
78
+
79
+ echo '💥 Simulating corrupted npm cache...'
80
+ mkdir -p ~/.npm/_npx/test-corrupt/node_modules/better-sqlite3
81
+ touch ~/.npm/_npx/test-corrupt/node_modules/better-sqlite3/.lock
82
+
83
+ echo ''
84
+ echo '🚀 Running claude-flow init --force with corrupted cache...'
85
+ echo ''
86
+
87
+ npx claude-flow@alpha init --force
88
+
89
+ echo ''
90
+ echo '✅ Recovery from corrupted cache successful'
91
+ " && {
92
+ echo -e "${GREEN}✅ PASS: Corrupted cache recovery${NC}"
93
+ TEST_RESULTS+=("PASS: Corrupted cache recovery")
94
+ } || {
95
+ echo -e "${RED}❌ FAIL: Corrupted cache recovery${NC}"
96
+ TEST_RESULTS+=("FAIL: Corrupted cache recovery")
97
+ }
98
+ }
99
+
100
+ # Function to test without --force flag
101
+ test_without_force() {
102
+ echo ""
103
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
104
+ echo "Testing without --force flag (3 retries max)"
105
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
106
+ echo ""
107
+
108
+ docker run --rm -i ubuntu:22.04 bash -c "
109
+ set -e
110
+
111
+ apt-get update -qq
112
+ apt-get install -y -qq curl build-essential python3 git > /dev/null 2>&1
113
+ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - > /dev/null 2>&1
114
+ apt-get install -y -qq nodejs > /dev/null 2>&1
115
+
116
+ echo '🚀 Running claude-flow init (no --force)...'
117
+ echo ''
118
+
119
+ npx claude-flow@alpha init
120
+
121
+ echo ''
122
+ echo '✅ Init without --force successful'
123
+ " && {
124
+ echo -e "${GREEN}✅ PASS: Init without --force${NC}"
125
+ TEST_RESULTS+=("PASS: Init without --force")
126
+ } || {
127
+ echo -e "${RED}❌ FAIL: Init without --force${NC}"
128
+ TEST_RESULTS+=("FAIL: Init without --force")
129
+ }
130
+ }
131
+
132
+ # Main test execution
133
+ echo "Starting comprehensive Docker tests..."
134
+ echo ""
135
+ echo "This will test:"
136
+ echo " - Multiple Linux distributions"
137
+ echo " - Corrupted cache recovery"
138
+ echo " - With and without --force flag"
139
+ echo ""
140
+
141
+ read -p "Continue? (y/n) " -n 1 -r
142
+ echo ""
143
+
144
+ if [[ ! $REPLY =~ ^[Yy]$ ]]; then
145
+ echo "Aborted"
146
+ exit 1
147
+ fi
148
+
149
+ # Run tests
150
+ for distro in "${DISTROS[@]}"; do
151
+ test_distro "$distro"
152
+ done
153
+
154
+ test_corrupted_cache
155
+ test_without_force
156
+
157
+ # Print summary
158
+ echo ""
159
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
160
+ echo "TEST SUMMARY"
161
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
162
+ echo ""
163
+
164
+ PASS_COUNT=0
165
+ FAIL_COUNT=0
166
+
167
+ for result in "${TEST_RESULTS[@]}"; do
168
+ if [[ $result == PASS* ]]; then
169
+ echo -e "${GREEN}✅ $result${NC}"
170
+ ((PASS_COUNT++))
171
+ else
172
+ echo -e "${RED}❌ $result${NC}"
173
+ ((FAIL_COUNT++))
174
+ fi
175
+ done
176
+
177
+ echo ""
178
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
179
+ echo "Total: $((PASS_COUNT + FAIL_COUNT)) tests"
180
+ echo -e "${GREEN}Passed: $PASS_COUNT${NC}"
181
+ echo -e "${RED}Failed: $FAIL_COUNT${NC}"
182
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
183
+ echo ""
184
+
185
+ if [ $FAIL_COUNT -eq 0 ]; then
186
+ echo -e "${GREEN}✅ All tests passed!${NC}"
187
+ echo ""
188
+ echo "Next steps:"
189
+ echo "1. Review test results above"
190
+ echo "2. Run: bash scripts/create-github-issue.sh"
191
+ echo "3. Update issue with test results"
192
+ exit 0
193
+ else
194
+ echo -e "${RED}❌ Some tests failed${NC}"
195
+ echo ""
196
+ echo "Please fix failing tests before creating GitHub issue"
197
+ exit 1
198
+ fi
@@ -5,11 +5,10 @@
5
5
  * Benchmarks session forking, hook matchers, and in-process MCP
6
6
  */
7
7
 
8
+ /* eslint-disable no-console */
9
+
8
10
  import { describe, it, expect, beforeAll, afterAll } from '@jest/globals';
9
11
  import { performance } from 'perf_hooks';
10
- import { ClaudeFlowSDKAdapter } from '../../sdk/sdk-config.js';
11
- import { TaskExecutorSDK } from '../../swarm/executor-sdk.js';
12
- import { ClaudeClientV25 } from '../../api/claude-client-v2.5.js';
13
12
 
14
13
  interface BenchmarkResult {
15
14
  name: string;
@@ -89,31 +88,9 @@ class PerformanceBenchmark {
89
88
 
90
89
  describe('Performance Benchmarks', () => {
91
90
  let benchmark: PerformanceBenchmark;
92
- let adapter: ClaudeFlowSDKAdapter;
93
- let executor: TaskExecutorSDK;
94
- let client: ClaudeClientV25;
95
91
 
96
92
  beforeAll(() => {
97
93
  benchmark = new PerformanceBenchmark();
98
-
99
- adapter = new ClaudeFlowSDKAdapter({
100
- apiKey: 'test-api-key',
101
- swarmMode: true,
102
- persistenceEnabled: true,
103
- });
104
-
105
- executor = new TaskExecutorSDK({
106
- apiKey: 'test-api-key',
107
- swarmMode: true,
108
- });
109
-
110
- client = new ClaudeClientV25(
111
- {
112
- apiKey: 'test-api-key',
113
- enableSwarmMode: true,
114
- },
115
- undefined
116
- );
117
94
  });
118
95
 
119
96
  afterAll(() => {
@@ -4,6 +4,8 @@
4
4
  * Comprehensive test suite for hook pattern matching system
5
5
  */
6
6
 
7
+ /* eslint-disable */
8
+
7
9
  import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
8
10
  import {
9
11
  HookMatcher,
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import type { DistributedMemorySystem } from '../memory/distributed-memory.js';
7
- import type { AgentState, AgentId, AgentType, AgentStatus } from '../swarm/types.js';
7
+ import type { AgentState, AgentType, AgentStatus } from '../swarm/types.js';
8
8
  import { EventEmitter } from 'node:events';
9
9
 
10
10
  export interface AgentRegistryEntry {
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { ILogger } from '../core/logger.js';
7
- import { AuthenticationError, AuthorizationError } from '../utils/errors.js';
7
+ import { AuthenticationError } from '../utils/errors.js';
8
8
  import { nanoid } from 'nanoid';
9
9
  import { createHash, createHmac, timingSafeEqual } from 'crypto';
10
10
 
@@ -483,9 +483,10 @@ export class EnhancedClaudeAPIClient extends EventEmitter {
483
483
  case 401:
484
484
  case 403:
485
485
  return new ClaudeAuthenticationError(message, errorData);
486
- case 429:
486
+ case 429: {
487
487
  const retryAfter = errorData.error?.retry_after;
488
488
  return new ClaudeRateLimitError(message, retryAfter, errorData);
489
+ }
489
490
  case 500:
490
491
  return new ClaudeInternalServerError(message, errorData);
491
492
  case 503:
@@ -6,7 +6,6 @@
6
6
  import { EventEmitter } from 'events';
7
7
  import { ILogger } from '../core/logger.js';
8
8
  import { ConfigManager } from '../config/config-manager.js';
9
- import { getErrorMessage } from '../utils/error-handler.js';
10
9
  import {
11
10
  ClaudeAPIError,
12
11
  ClaudeInternalServerError,
@@ -655,9 +654,10 @@ export class ClaudeAPIClient extends EventEmitter {
655
654
  case 401:
656
655
  case 403:
657
656
  return new ClaudeAuthenticationError(message, errorData);
658
- case 429:
657
+ case 429: {
659
658
  const retryAfter = errorData.error?.retry_after;
660
659
  return new ClaudeRateLimitError(message, retryAfter, errorData);
660
+ }
661
661
  case 500:
662
662
  return new ClaudeInternalServerError(message, errorData);
663
663
  case 503:
@@ -4,8 +4,7 @@
4
4
  */
5
5
 
6
6
  import { ILogger } from '../core/logger.js';
7
- import { ConfigManager } from '../config/config-manager.js';
8
- import { SwarmError, DatabaseError } from '../utils/errors.js';
7
+ import { DatabaseError } from '../utils/errors.js';
9
8
  import { nanoid } from 'nanoid';
10
9
 
11
10
  export interface DatabaseConfig {
@@ -11,7 +11,7 @@ import { ICoordinationManager } from '../coordination/manager.js';
11
11
  import { SwarmCoordinator } from '../swarm/coordinator.js';
12
12
  import { AgentManager } from '../agents/agent-manager.js';
13
13
  import { ResourceManager } from '../resources/resource-manager.js';
14
- import { Task, Agent, SwarmConfig, SwarmStatus } from '../utils/types.js';
14
+ import { SwarmConfig } from '../utils/types.js';
15
15
  import { ValidationError, SwarmError } from '../utils/errors.js';
16
16
  import { nanoid } from 'nanoid';
17
17
 
@@ -123,7 +123,7 @@ export class SwarmApi {
123
123
  });
124
124
 
125
125
  // Error handling
126
- this.router.use((err: Error, req: any, res: any, next: any) => {
126
+ this.router.use((err: Error, req: any, res: any, _next: any) => {
127
127
  this.logger.error('Swarm API error', {
128
128
  error: err.message,
129
129
  stack: err.stack,
@@ -383,7 +383,7 @@ async function submitTaskWizard() {
383
383
  ]);
384
384
 
385
385
  let taskDescription = '';
386
- let taskConfig: any = {};
386
+ const taskConfig: any = {};
387
387
 
388
388
  if (template === 'custom') {
389
389
  const answers = await inquirer.prompt([
@@ -5,6 +5,7 @@ import { createSwarmCommands } from './swarm-commands.js';
5
5
  import { createSparcEnvironment } from './sparc-environment.js';
6
6
  import { createClaudeConfig } from './claude-config.js';
7
7
  import { createBatchToolsGuide } from './batch-tools.js';
8
+ import { errorRecovery } from '../../utils/error-recovery.js';
8
9
 
9
10
  export interface InitOptions {
10
11
  sparc?: boolean;
@@ -12,56 +13,85 @@ export interface InitOptions {
12
13
  }
13
14
 
14
15
  export async function initCommand(options: InitOptions = {}) {
15
- try {
16
- const fs = await import('fs/promises');
17
- const path = await import('path');
16
+ // Wrap entire initialization in retry logic with automatic recovery
17
+ return errorRecovery.retryWithRecovery(
18
+ async () => {
19
+ try {
20
+ const fs = await import('fs/promises');
21
+ const path = await import('path');
18
22
 
19
- printSuccess('Initializing Claude-Flow project...');
23
+ printSuccess('Initializing Claude-Flow project...');
20
24
 
21
- // Phase 1: Create directory structure
22
- console.log('\n📁 Phase 1: Creating directory structure...');
23
- await createDirectoryStructure();
25
+ // Check WSL environment and apply fixes proactively
26
+ if (errorRecovery.isWSL()) {
27
+ console.log('🔍 WSL environment detected');
28
+ const wslCheck = await errorRecovery.recoverWSLErrors();
29
+ if (wslCheck.recovered) {
30
+ console.log('✅ WSL environment optimized\n');
31
+ }
32
+ }
24
33
 
25
- // Phase 2: Create base configuration
26
- console.log('\n⚙️ Phase 2: Creating configuration...');
27
- await createClaudeConfig(options);
34
+ // Phase 1: Create directory structure
35
+ console.log('\n📁 Phase 1: Creating directory structure...');
36
+ await createDirectoryStructure();
28
37
 
29
- // Phase 3: Create swarm commands and documentation
30
- console.log('\n🤖 Phase 3: Creating swarm commands...');
31
- await createSwarmCommands();
38
+ // Phase 2: Create base configuration
39
+ console.log('\n⚙️ Phase 2: Creating configuration...');
40
+ await createClaudeConfig(options);
32
41
 
33
- // Phase 4: Create batch tools guides
34
- console.log('\n🔧 Phase 4: Creating batch tools guides...');
35
- await createBatchToolsGuide();
42
+ // Phase 3: Create swarm commands and documentation
43
+ console.log('\n🤖 Phase 3: Creating swarm commands...');
44
+ await createSwarmCommands();
36
45
 
37
- // Phase 5: SPARC environment (if requested)
38
- if (options.sparc) {
39
- console.log('\n🚀 Phase 5: Creating SPARC environment...');
40
- await createSparcEnvironment();
41
- }
46
+ // Phase 4: Create batch tools guides
47
+ console.log('\n🔧 Phase 4: Creating batch tools guides...');
48
+ await createBatchToolsGuide();
49
+
50
+ // Phase 5: SPARC environment (if requested)
51
+ if (options.sparc) {
52
+ console.log('\n🚀 Phase 5: Creating SPARC environment...');
53
+ await createSparcEnvironment();
54
+ }
55
+
56
+ // Success summary
57
+ console.log('\n🎉 Project initialized successfully!');
58
+ console.log(' 📁 Created .claude/ directory structure');
59
+ console.log(' 📋 Created comprehensive swarm command documentation');
60
+ console.log(' 🔧 Created batch tools coordination guides');
61
+ console.log(' 📖 Created detailed usage examples with orchestration');
42
62
 
43
- // Success summary
44
- console.log('\n🎉 Project initialized successfully!');
45
- console.log(' 📁 Created .claude/ directory structure');
46
- console.log(' 📋 Created comprehensive swarm command documentation');
47
- console.log(' 🔧 Created batch tools coordination guides');
48
- console.log(' 📖 Created detailed usage examples with orchestration');
63
+ console.log('\n Next steps:');
64
+ console.log(' 1. Run "claude-flow swarm --help" to see swarm options');
65
+ console.log(' 2. Check .claude/commands/swarm/ for detailed documentation');
66
+ console.log(' 3. Review batch tools guide for orchestration patterns');
67
+ console.log(' 4. Run "claude-flow help" for all available commands');
49
68
 
50
- console.log('\n Next steps:');
51
- console.log(' 1. Run "claude-flow swarm --help" to see swarm options');
52
- console.log(' 2. Check .claude/commands/swarm/ for detailed documentation');
53
- console.log(' 3. Review batch tools guide for orchestration patterns');
54
- console.log(' 4. Run "claude-flow help" for all available commands');
69
+ if (options.sparc) {
70
+ console.log(' 5. Run "claude-flow sparc modes" to see available SPARC modes');
71
+ console.log(' 6. Use TodoWrite/TodoRead for task coordination');
72
+ console.log(' 7. Use Task tool for parallel agent execution');
73
+ }
74
+ } catch (error) {
75
+ // Attempt automatic error recovery
76
+ const recovery = await errorRecovery.recoverInitErrors(error);
55
77
 
56
- if (options.sparc) {
57
- console.log(' 5. Run "claude-flow sparc modes" to see available SPARC modes');
58
- console.log(' 6. Use TodoWrite/TodoRead for task coordination');
59
- console.log(' 7. Use Task tool for parallel agent execution');
78
+ if (recovery.recovered) {
79
+ console.log(' Recovered from error, retrying initialization...\n');
80
+ throw error; // Trigger retry
81
+ } else {
82
+ printError(
83
+ `Failed to initialize project: ${error instanceof Error ? error.message : String(error)}`,
84
+ );
85
+ throw error;
86
+ }
87
+ }
88
+ },
89
+ {
90
+ maxRetries: options.force ? 5 : 3,
91
+ delay: 1000,
92
+ onRetry: (attempt, error) => {
93
+ console.log(`\n🔄 Retry attempt ${attempt} after error recovery...`);
94
+ }
60
95
  }
61
- } catch (error) {
62
- printError(
63
- `Failed to initialize project: ${error instanceof Error ? error.message : String(error)}`,
64
- );
65
- throw error;
66
- }
96
+ );
67
97
  }
@@ -12,7 +12,7 @@ const __dirname = dirname(__filename);
12
12
  export async function copySkillFiles(targetDir, options = {}) {
13
13
  console.log(' 🚀 copySkillFiles function called');
14
14
  console.log(` 📂 Target directory: ${targetDir}`);
15
- console.log(` ⚙️ Options:`, options);
15
+ console.log(` ⚙️ Options: { force: ${options.force || 'false'}, dryRun: ${options.dryRun || 'false'} }`);
16
16
  console.log(` 📍 __dirname: ${__dirname}`);
17
17
 
18
18
  const { force = false, dryRun = false } = options;
@@ -77,7 +77,7 @@ function startWebUI(host: string, port: number) {
77
77
  const activeConnections: Set<any> = new Set();
78
78
 
79
79
  // CLI output capture system
80
- let cliProcess: any = null;
80
+ const cliProcess: any = null;
81
81
 
82
82
  const consoleHTML = `
83
83
  <!DOCTYPE html>
@@ -277,7 +277,7 @@ export class ConflictResolver {
277
277
  }
278
278
 
279
279
  // Build context based on conflict type
280
- let context: any = {};
280
+ const context: any = {};
281
281
 
282
282
  if (preferredStrategy === 'priority') {
283
283
  // In a real implementation, fetch agent priorities from configuration
@@ -228,7 +228,7 @@ export class LoadBalancer extends EventEmitter {
228
228
 
229
229
  try {
230
230
  // Filter agents based on constraints
231
- let candidates = this.filterAgentsByConstraints(availableAgents, task, constraints);
231
+ const candidates = this.filterAgentsByConstraints(availableAgents, task, constraints);
232
232
 
233
233
  if (candidates.length === 0) {
234
234
  throw new Error('No suitable agents available for task');
@@ -12,6 +12,8 @@ export class DatabaseManager implements IDatabaseProvider {
12
12
  private dbType: 'sqlite' | 'json';
13
13
  private dbPath: string;
14
14
  private initialized: boolean = false;
15
+ private retryCount: number = 0;
16
+ private maxRetries: number = 3;
15
17
 
16
18
  constructor(dbType: 'sqlite' | 'json' = 'sqlite', dbPath?: string) {
17
19
  this.dbType = dbType;
@@ -19,18 +21,36 @@ export class DatabaseManager implements IDatabaseProvider {
19
21
 
20
22
  // Try SQLite first, fallback to JSON if needed
21
23
  if (this.dbType === 'sqlite') {
22
- try {
23
- this.provider = new SQLiteProvider(this.dbPath);
24
- } catch (error) {
25
- console.warn('SQLite not available, falling back to JSON storage:', error);
26
- this.provider = new JSONProvider(this.dbPath.replace('.sqlite', '.json'));
27
- this.dbType = 'json';
28
- }
24
+ this.provider = this.initializeSQLiteWithRecovery();
29
25
  } else {
30
26
  this.provider = new JSONProvider(this.dbPath);
31
27
  }
32
28
  }
33
29
 
30
+ /**
31
+ * Initialize SQLite with automatic error recovery
32
+ */
33
+ private initializeSQLiteWithRecovery(): IDatabaseProvider {
34
+ try {
35
+ return new SQLiteProvider(this.dbPath);
36
+ } catch (error) {
37
+ const errorMsg = error instanceof Error ? error.message : String(error);
38
+
39
+ // Check if it's an npm cache error
40
+ if (errorMsg.includes('ENOTEMPTY') || errorMsg.includes('better-sqlite3')) {
41
+ console.warn('⚠️ SQLite initialization failed due to npm cache error');
42
+ console.warn(' Will attempt automatic recovery during initialize()');
43
+ } else {
44
+ console.warn('SQLite not available, falling back to JSON storage:', error);
45
+ }
46
+
47
+ // Fallback to JSON for now
48
+ this.provider = new JSONProvider(this.dbPath.replace('.sqlite', '.json'));
49
+ this.dbType = 'json';
50
+ return this.provider;
51
+ }
52
+ }
53
+
34
54
  private getDefaultPath(): string {
35
55
  const baseDir = path.join(process.cwd(), '.claude-flow');
36
56
  return this.dbType === 'sqlite'
@@ -40,8 +60,34 @@ export class DatabaseManager implements IDatabaseProvider {
40
60
 
41
61
  async initialize(): Promise<void> {
42
62
  await fs.ensureDir(path.dirname(this.dbPath));
43
- await this.provider.initialize();
44
- this.initialized = true;
63
+
64
+ try {
65
+ await this.provider.initialize();
66
+ this.initialized = true;
67
+ } catch (error) {
68
+ // If JSON provider failed, just propagate the error
69
+ if (this.dbType === 'json') {
70
+ throw error;
71
+ }
72
+
73
+ // For SQLite errors, attempt recovery
74
+ const errorMsg = error instanceof Error ? error.message : String(error);
75
+ if (this.retryCount < this.maxRetries) {
76
+ console.warn(`⚠️ Database initialization failed (attempt ${this.retryCount + 1}/${this.maxRetries})`);
77
+ console.warn(` Error: ${errorMsg}`);
78
+
79
+ // Attempt to recover by switching to JSON
80
+ console.log('🔄 Switching to JSON storage as fallback...');
81
+ this.provider = new JSONProvider(this.dbPath.replace('.sqlite', '.json'));
82
+ this.dbType = 'json';
83
+ this.retryCount++;
84
+
85
+ // Retry initialization with JSON provider
86
+ await this.initialize();
87
+ } else {
88
+ throw error;
89
+ }
90
+ }
45
91
  }
46
92
 
47
93
  async store(key: string, value: any, namespace: string = 'default'): Promise<void> {
@@ -81,7 +81,7 @@ const FORMAT_PARSERS: Record<string, FormatParser> = {
81
81
  // Simple YAML parser for basic key-value pairs
82
82
  const lines = content.split('\n');
83
83
  const result: any = {};
84
- let current = result;
84
+ const current = result;
85
85
  const stack: any[] = [result];
86
86
 
87
87
  for (const line of lines) {
@@ -728,7 +728,7 @@ export class AuditManager extends EventEmitter {
728
728
  let totalEntries = 0;
729
729
  let verifiedEntries = 0;
730
730
  let corruptedEntries = 0;
731
- let missingEntries = 0;
731
+ const missingEntries = 0;
732
732
 
733
733
  const trails = trailId
734
734
  ? ([this.auditTrails.get(trailId)].filter(Boolean) as AuditTrail[])
@@ -292,8 +292,8 @@ export class OpenAIProvider extends BaseProvider {
292
292
  const reader = response.body!.getReader();
293
293
  const decoder = new TextDecoder();
294
294
  let buffer = '';
295
- let totalPromptTokens = 0;
296
- let totalCompletionTokens = 0;
295
+ const totalPromptTokens = 0;
296
+ const totalCompletionTokens = 0;
297
297
 
298
298
  while (true) {
299
299
  const { done, value } = await reader.read();
@@ -70,7 +70,7 @@ export class RealCheckpointManager extends EventEmitter {
70
70
  queryGenerator: Query,
71
71
  autoCheckpoint: boolean = false
72
72
  ): Promise<void> {
73
- let messages = this.sessionMessages.get(sessionId) || [];
73
+ const messages = this.sessionMessages.get(sessionId) || [];
74
74
  this.sessionMessages.set(sessionId, messages);
75
75
 
76
76
  let messageCount = this.messageCounters.get(sessionId) || 0;