claude-flow-novice 2.0.3 → 2.0.4

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 (272) hide show
  1. package/dist/src/cli/commands/guidance.js +487 -668
  2. package/dist/src/cli/commands/index-validate.js +18 -29
  3. package/dist/src/cli/commands/mcp-troubleshoot.js +230 -282
  4. package/dist/src/cli/commands/neural-goal-init.js +92 -125
  5. package/dist/src/cli/commands/swarm-exec.js +317 -393
  6. package/dist/src/cli/commands/swarm.js +1 -1
  7. package/dist/src/cli/commands/validate-framework.js +983 -1100
  8. package/dist/src/cli/commands/validate.js +144 -223
  9. package/dist/src/cli/simple-commands/__tests__/agent.test.js +265 -277
  10. package/dist/src/cli/simple-commands/__tests__/memory.test.js +6 -7
  11. package/dist/src/cli/simple-commands/__tests__/swarm.test.js +373 -356
  12. package/dist/src/cli/simple-commands/__tests__/task.test.js +6 -7
  13. package/dist/src/cli/simple-commands/agent.js +157 -193
  14. package/dist/src/cli/simple-commands/analysis.js +336 -446
  15. package/dist/src/cli/simple-commands/automation-executor.js +1095 -1339
  16. package/dist/src/cli/simple-commands/automation.js +481 -469
  17. package/dist/src/cli/simple-commands/batch-manager.js +261 -313
  18. package/dist/src/cli/simple-commands/claude-telemetry.js +241 -267
  19. package/dist/src/cli/simple-commands/claude-track.js +68 -90
  20. package/dist/src/cli/simple-commands/concurrent-display.js +266 -320
  21. package/dist/src/cli/simple-commands/config.js +245 -290
  22. package/dist/src/cli/simple-commands/coordination.js +182 -234
  23. package/dist/src/cli/simple-commands/enhanced-ui-views.js +812 -615
  24. package/dist/src/cli/simple-commands/enhanced-webui-complete.js +922 -981
  25. package/dist/src/cli/simple-commands/fix-hook-variables.js +274 -294
  26. package/dist/src/cli/simple-commands/github/gh-coordinator.js +378 -457
  27. package/dist/src/cli/simple-commands/github/github-api.js +535 -574
  28. package/dist/src/cli/simple-commands/github/init.js +276 -303
  29. package/dist/src/cli/simple-commands/github.js +222 -247
  30. package/dist/src/cli/simple-commands/goal.js +51 -63
  31. package/dist/src/cli/simple-commands/hive-mind/auto-save-middleware.js +208 -278
  32. package/dist/src/cli/simple-commands/hive-mind/communication.js +601 -696
  33. package/dist/src/cli/simple-commands/hive-mind/core.js +907 -979
  34. package/dist/src/cli/simple-commands/hive-mind/db-optimizer.js +406 -655
  35. package/dist/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1125 -1245
  36. package/dist/src/cli/simple-commands/hive-mind/memory.js +854 -1090
  37. package/dist/src/cli/simple-commands/hive-mind/performance-optimizer.js +459 -574
  38. package/dist/src/cli/simple-commands/hive-mind/performance-test.js +263 -347
  39. package/dist/src/cli/simple-commands/hive-mind/queen.js +727 -768
  40. package/dist/src/cli/simple-commands/hive-mind/session-manager.js +745 -1049
  41. package/dist/src/cli/simple-commands/hive-mind-optimize.js +227 -283
  42. package/dist/src/cli/simple-commands/hive-mind-wizard.js +174 -217
  43. package/dist/src/cli/simple-commands/hive-mind.js +1842 -2283
  44. package/dist/src/cli/simple-commands/hive.js +90 -79
  45. package/dist/src/cli/simple-commands/hook-safety.js +431 -521
  46. package/dist/src/cli/simple-commands/hooks/session-start-soul.js +203 -254
  47. package/dist/src/cli/simple-commands/hooks.js +1064 -1204
  48. package/dist/src/cli/simple-commands/init/agent-copier.js +294 -319
  49. package/dist/src/cli/simple-commands/init/batch-init.js +496 -562
  50. package/dist/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +13 -19
  51. package/dist/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +13 -19
  52. package/dist/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +61 -88
  53. package/dist/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +125 -150
  54. package/dist/src/cli/simple-commands/init/claude-commands/slash-commands.js +42 -49
  55. package/dist/src/cli/simple-commands/init/claude-commands/sparc-commands.js +43 -61
  56. package/dist/src/cli/simple-commands/init/copy-revised-templates.js +141 -147
  57. package/dist/src/cli/simple-commands/init/executable-wrapper.js +31 -44
  58. package/dist/src/cli/simple-commands/init/gitignore-updater.js +64 -90
  59. package/dist/src/cli/simple-commands/init/help.js +104 -107
  60. package/dist/src/cli/simple-commands/init/hive-mind-init.js +509 -528
  61. package/dist/src/cli/simple-commands/init/index.js +1510 -1759
  62. package/dist/src/cli/simple-commands/init/performance-monitor.js +234 -317
  63. package/dist/src/cli/simple-commands/init/rollback/backup-manager.js +441 -504
  64. package/dist/src/cli/simple-commands/init/rollback/index.js +289 -364
  65. package/dist/src/cli/simple-commands/init/rollback/recovery-manager.js +652 -728
  66. package/dist/src/cli/simple-commands/init/rollback/rollback-executor.js +416 -481
  67. package/dist/src/cli/simple-commands/init/rollback/state-tracker.js +369 -448
  68. package/dist/src/cli/simple-commands/init/sparc/roo-readme.js +1 -2
  69. package/dist/src/cli/simple-commands/init/sparc/roomodes-config.js +122 -99
  70. package/dist/src/cli/simple-commands/init/sparc/workflows.js +32 -37
  71. package/dist/src/cli/simple-commands/init/sparc-structure.js +55 -62
  72. package/dist/src/cli/simple-commands/init/template-copier.js +421 -533
  73. package/dist/src/cli/simple-commands/init/templates/coordination-md.js +3 -6
  74. package/dist/src/cli/simple-commands/init/templates/enhanced-templates.js +344 -318
  75. package/dist/src/cli/simple-commands/init/templates/github-safe-enhanced.js +173 -218
  76. package/dist/src/cli/simple-commands/init/templates/github-safe.js +65 -75
  77. package/dist/src/cli/simple-commands/init/templates/memory-bank-md.js +3 -6
  78. package/dist/src/cli/simple-commands/init/templates/readme-files.js +2 -4
  79. package/dist/src/cli/simple-commands/init/templates/safe-hook-patterns.js +187 -230
  80. package/dist/src/cli/simple-commands/init/templates/sparc-modes.js +53 -80
  81. package/dist/src/cli/simple-commands/init/templates/verification-claude-md.js +101 -85
  82. package/dist/src/cli/simple-commands/init/validation/config-validator.js +283 -330
  83. package/dist/src/cli/simple-commands/init/validation/health-checker.js +495 -561
  84. package/dist/src/cli/simple-commands/init/validation/index.js +302 -358
  85. package/dist/src/cli/simple-commands/init/validation/mode-validator.js +308 -359
  86. package/dist/src/cli/simple-commands/init/validation/post-init-validator.js +389 -366
  87. package/dist/src/cli/simple-commands/init/validation/pre-init-validator.js +270 -268
  88. package/dist/src/cli/simple-commands/init/validation/test-runner.js +427 -447
  89. package/dist/src/cli/simple-commands/init.js +1 -2
  90. package/dist/src/cli/simple-commands/mcp-health.js +131 -158
  91. package/dist/src/cli/simple-commands/mcp-integration-layer.js +533 -634
  92. package/dist/src/cli/simple-commands/mcp.js +345 -400
  93. package/dist/src/cli/simple-commands/memory-consolidation.js +426 -537
  94. package/dist/src/cli/simple-commands/memory.js +247 -311
  95. package/dist/src/cli/simple-commands/migrate-hooks.js +39 -46
  96. package/dist/src/cli/simple-commands/monitor.js +294 -363
  97. package/dist/src/cli/simple-commands/neural.js +51 -65
  98. package/dist/src/cli/simple-commands/pair-autofix-only.js +538 -662
  99. package/dist/src/cli/simple-commands/pair-basic.js +528 -656
  100. package/dist/src/cli/simple-commands/pair-old.js +430 -543
  101. package/dist/src/cli/simple-commands/pair-working.js +615 -751
  102. package/dist/src/cli/simple-commands/pair.js +615 -751
  103. package/dist/src/cli/simple-commands/performance-hooks.js +83 -111
  104. package/dist/src/cli/simple-commands/performance-metrics.js +348 -433
  105. package/dist/src/cli/simple-commands/process-ui-enhanced.js +708 -787
  106. package/dist/src/cli/simple-commands/process-ui.js +230 -254
  107. package/dist/src/cli/simple-commands/realtime-update-system.js +525 -611
  108. package/dist/src/cli/simple-commands/sparc/architecture.js +1704 -1530
  109. package/dist/src/cli/simple-commands/sparc/commands.js +438 -516
  110. package/dist/src/cli/simple-commands/sparc/completion.js +1224 -1481
  111. package/dist/src/cli/simple-commands/sparc/coordinator.js +913 -978
  112. package/dist/src/cli/simple-commands/sparc/index.js +241 -298
  113. package/dist/src/cli/simple-commands/sparc/phase-base.js +314 -390
  114. package/dist/src/cli/simple-commands/sparc/pseudocode.js +965 -869
  115. package/dist/src/cli/simple-commands/sparc/refinement.js +980 -1273
  116. package/dist/src/cli/simple-commands/sparc/specification.js +559 -645
  117. package/dist/src/cli/simple-commands/sparc-modes/architect.js +1 -1
  118. package/dist/src/cli/simple-commands/sparc-modes/ask.js +1 -1
  119. package/dist/src/cli/simple-commands/sparc-modes/code.js +1 -1
  120. package/dist/src/cli/simple-commands/sparc-modes/debug.js +1 -1
  121. package/dist/src/cli/simple-commands/sparc-modes/devops.js +1 -1
  122. package/dist/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
  123. package/dist/src/cli/simple-commands/sparc-modes/generic.js +1 -1
  124. package/dist/src/cli/simple-commands/sparc-modes/index.js +47 -55
  125. package/dist/src/cli/simple-commands/sparc-modes/integration.js +1 -1
  126. package/dist/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
  127. package/dist/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
  128. package/dist/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
  129. package/dist/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
  130. package/dist/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
  131. package/dist/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
  132. package/dist/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
  133. package/dist/src/cli/simple-commands/sparc-modes/swarm.js +101 -87
  134. package/dist/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
  135. package/dist/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
  136. package/dist/src/cli/simple-commands/sparc.js +465 -493
  137. package/dist/src/cli/simple-commands/start-ui.js +108 -132
  138. package/dist/src/cli/simple-commands/start-wrapper.js +240 -268
  139. package/dist/src/cli/simple-commands/start.js +1 -1
  140. package/dist/src/cli/simple-commands/status.js +254 -275
  141. package/dist/src/cli/simple-commands/stream-chain-clean.js +128 -171
  142. package/dist/src/cli/simple-commands/stream-chain-fixed.js +61 -82
  143. package/dist/src/cli/simple-commands/stream-chain-real.js +267 -331
  144. package/dist/src/cli/simple-commands/stream-chain-working.js +211 -263
  145. package/dist/src/cli/simple-commands/stream-chain.js +260 -318
  146. package/dist/src/cli/simple-commands/stream-processor.js +290 -315
  147. package/dist/src/cli/simple-commands/swarm-executor.js +189 -222
  148. package/dist/src/cli/simple-commands/swarm-metrics-integration.js +208 -300
  149. package/dist/src/cli/simple-commands/swarm-ui.js +623 -703
  150. package/dist/src/cli/simple-commands/swarm-webui-integration.js +258 -286
  151. package/dist/src/cli/simple-commands/swarm.js +887 -1082
  152. package/dist/src/cli/simple-commands/task.js +161 -206
  153. package/dist/src/cli/simple-commands/timestamp-fix.js +59 -89
  154. package/dist/src/cli/simple-commands/token-tracker.js +258 -316
  155. package/dist/src/cli/simple-commands/tool-execution-framework.js +433 -519
  156. package/dist/src/cli/simple-commands/train-and-stream.js +275 -331
  157. package/dist/src/cli/simple-commands/training-pipeline.js +619 -725
  158. package/dist/src/cli/simple-commands/training.js +170 -227
  159. package/dist/src/cli/simple-commands/verification-hooks.js +261 -284
  160. package/dist/src/cli/simple-commands/verification-integration.js +389 -417
  161. package/dist/src/cli/simple-commands/verification-training-integration.js +486 -606
  162. package/dist/src/cli/simple-commands/verification.js +493 -513
  163. package/dist/src/cli/simple-commands/web-server.js +766 -836
  164. package/dist/src/cli/simple-commands/webui-validator.js +106 -124
  165. package/dist/src/coordination/event-bus/demo-wasm-integration.js +212 -251
  166. package/dist/src/coordination/event-bus/qe-event-bus.js +608 -748
  167. package/dist/src/coordination/event-bus/qe-event-bus.test.js +379 -454
  168. package/dist/src/coordination/iteration-tracker.js +363 -454
  169. package/dist/src/enterprise/analytics-manager.js +1135 -0
  170. package/dist/src/enterprise/audit-manager.js +1115 -0
  171. package/dist/src/enterprise/cloud-manager.js +891 -0
  172. package/dist/src/enterprise/deployment-manager.js +966 -0
  173. package/dist/src/enterprise/index.js +6 -0
  174. package/dist/src/enterprise/project-manager.js +584 -0
  175. package/dist/src/enterprise/security-manager.js +991 -0
  176. package/dist/src/index.js +1 -1
  177. package/dist/src/mcp/DEPRECATED.js +46 -60
  178. package/dist/src/mcp/fixes/mcp-error-fixes.js +115 -134
  179. package/dist/src/mcp/implementations/agent-tracker.js +114 -128
  180. package/dist/src/mcp/implementations/daa-tools.js +292 -350
  181. package/dist/src/mcp/implementations/workflow-tools.js +329 -361
  182. package/dist/src/mcp/mcp-config-manager.js +1183 -1331
  183. package/dist/src/mcp/mcp-server-novice-simplified.js +11 -17
  184. package/dist/src/mcp/mcp-server-novice.js +11 -17
  185. package/dist/src/mcp/mcp-server-sdk.js +11 -17
  186. package/dist/src/mcp/mcp-server.js +1620 -1484
  187. package/dist/src/mcp/ruv-swarm-wrapper.js +209 -239
  188. package/dist/src/memory/advanced-serializer.js +609 -589
  189. package/dist/src/memory/enhanced-examples.js +220 -305
  190. package/dist/src/memory/enhanced-memory.js +295 -336
  191. package/dist/src/memory/enhanced-session-serializer.js +408 -492
  192. package/dist/src/memory/fallback-memory-system.js +900 -1021
  193. package/dist/src/memory/fallback-store.js +93 -131
  194. package/dist/src/memory/high-performance-serialization.js +592 -730
  195. package/dist/src/memory/in-memory-store.js +161 -213
  196. package/dist/src/memory/index.js +123 -157
  197. package/dist/src/memory/lock-free-structures.js +578 -764
  198. package/dist/src/memory/memory-mapped-persistence.js +585 -766
  199. package/dist/src/memory/memory-pressure-manager.js +569 -707
  200. package/dist/src/memory/migration.js +358 -445
  201. package/dist/src/memory/shared-memory.js +641 -768
  202. package/dist/src/memory/sqlite-store.js +245 -325
  203. package/dist/src/memory/sqlite-wrapper.js +122 -151
  204. package/dist/src/memory/swarm-memory.js +470 -603
  205. package/dist/src/memory/test-example.js +126 -134
  206. package/dist/src/memory/ultra-fast-memory-store.js +622 -821
  207. package/dist/src/memory/unified-memory-manager.js +356 -437
  208. package/dist/src/migration/index.js +92 -0
  209. package/dist/src/migration/logger.js +121 -0
  210. package/dist/src/migration/migration-analyzer.js +268 -0
  211. package/dist/src/migration/migration-runner.js +522 -0
  212. package/dist/src/migration/migration-validator.js +285 -0
  213. package/dist/src/migration/progress-reporter.js +150 -0
  214. package/dist/src/migration/rollback-manager.js +321 -0
  215. package/dist/src/migration/tests/migration-system.test.js +7 -0
  216. package/dist/src/migration/types.js +3 -0
  217. package/dist/src/swarm/CodeRefactoringSwarm.js +777 -952
  218. package/dist/src/swarm/__tests__/integration.test.js +227 -0
  219. package/dist/src/swarm/__tests__/prompt-copier.test.js +344 -0
  220. package/dist/src/swarm/advanced-orchestrator.js +1095 -0
  221. package/dist/src/swarm/claude-code-interface.js +961 -0
  222. package/dist/src/swarm/claude-flow-executor.js +229 -0
  223. package/dist/src/swarm/consensus-coordinator.js +475 -0
  224. package/dist/src/swarm/coordinator.js +2993 -0
  225. package/dist/src/swarm/direct-executor.js +1180 -0
  226. package/dist/src/swarm/error-recovery/advanced-error-detection.js +691 -0
  227. package/dist/src/swarm/error-recovery/automated-recovery-workflows.js +998 -0
  228. package/dist/src/swarm/error-recovery/error-recovery-coordinator.js +1197 -0
  229. package/dist/src/swarm/error-recovery/recovery-monitoring.js +772 -0
  230. package/dist/src/swarm/error-recovery/resilience-architecture.js +714 -0
  231. package/dist/src/swarm/error-recovery/self-healing-mechanisms.js +1319 -0
  232. package/dist/src/swarm/error-recovery/test-error-recovery-effectiveness.js +808 -0
  233. package/dist/src/swarm/executor-v2.js +322 -0
  234. package/dist/src/swarm/executor.js +815 -0
  235. package/dist/src/swarm/hive-mind-integration.js +703 -0
  236. package/dist/src/swarm/index.js +41 -0
  237. package/dist/src/swarm/json-output-aggregator.js +267 -0
  238. package/dist/src/swarm/large-scale-coordinator.js +542 -0
  239. package/dist/src/swarm/mcp-integration-wrapper.js +628 -0
  240. package/dist/src/swarm/memory.js +1117 -0
  241. package/dist/src/swarm/optimizations/__tests__/optimization.test.js +348 -0
  242. package/dist/src/swarm/optimizations/async-file-manager.js +285 -0
  243. package/dist/src/swarm/optimizations/circular-buffer.js +162 -0
  244. package/dist/src/swarm/optimizations/connection-pool.js +244 -0
  245. package/dist/src/swarm/optimizations/index.js +28 -0
  246. package/dist/src/swarm/optimizations/optimized-executor.js +320 -0
  247. package/dist/src/swarm/optimizations/ttl-map.js +234 -0
  248. package/dist/src/swarm/prompt-cli.js +200 -0
  249. package/dist/src/swarm/prompt-copier-enhanced.js +202 -0
  250. package/dist/src/swarm/prompt-copier.js +381 -0
  251. package/dist/src/swarm/prompt-manager.js +295 -0
  252. package/dist/src/swarm/prompt-utils.js +310 -0
  253. package/dist/src/swarm/result-aggregator.js +718 -0
  254. package/dist/src/swarm/sparc-executor.js +1568 -0
  255. package/dist/src/swarm/strategies/auto.js +758 -0
  256. package/dist/src/swarm/strategies/base.js +128 -0
  257. package/dist/src/swarm/strategies/research.js +914 -0
  258. package/dist/src/swarm/strategies/strategy-metrics-patch.js +2 -0
  259. package/dist/src/swarm/types.js +52 -0
  260. package/dist/src/swarm/workers/copy-worker.js +56 -0
  261. package/dist/src/utils/__tests__/github-cli-safety-wrapper.test.js +332 -400
  262. package/dist/src/utils/github-cli-safe.js +56 -64
  263. package/dist/src/utils/github-cli-safety-wrapper.js +451 -546
  264. package/dist/src/utils/npx-isolated-cache.js +104 -119
  265. package/dist/src/utils/preference-manager.js +622 -652
  266. package/dist/src/utils/timezone-utils.js +86 -105
  267. package/dist/src/validators/epic-config-schema.js +214 -0
  268. package/dist/src/validators/index.js +10 -0
  269. package/dist/src/validators/swarm-init-validator.js +259 -0
  270. package/dist/src/validators/todowrite-batching-validator.js +215 -0
  271. package/dist/src/validators/todowrite-integration.js +187 -0
  272. package/package.json +2 -2
@@ -1,707 +1,584 @@
1
1
  /**
2
2
  * Pair Programming with Recursive Auto-Fix Stream Chaining
3
3
  * Automatically fixes and improves code until verification threshold is met
4
- */
5
-
6
- import fs from 'fs/promises';
7
- import path from 'path';
8
- import { spawn, exec } from 'child_process';
9
- import { promisify } from 'util';
10
- import readline from 'readline';
11
-
4
+ */ import fs from "node:fs/promises";
5
+ import path from "path";
6
+ import { spawn, exec } from "child_process";
7
+ import { promisify } from "util";
8
+ import readline from "readline";
12
9
  const execAsync = promisify(exec);
13
-
14
- class AutoFixPairSession {
15
- constructor(options = {}) {
16
- this.sessionId = `pair_${Date.now()}`;
17
- this.mode = options.mode || 'switch';
18
- this.agent = options.agent || 'auto';
19
- this.verify = options.verify || false;
20
- this.autoFix = options.autoFix || false; // New: Enable recursive auto-fix
21
- this.test = options.test || false;
22
- this.threshold = options.threshold || 0.95;
23
- this.maxIterations = options.maxIterations || 5; // Max fix attempts
24
- this.startTime = new Date();
25
- this.status = 'active';
26
- this.currentRole = 'driver';
27
- this.verificationScores = [];
28
- this.fixHistory = [];
29
- this.currentIteration = 0;
30
- this.rl = null;
31
- }
32
-
33
- async start() {
34
- await this.saveSession();
35
- this.showWelcome();
36
-
37
- if (this.verify && this.autoFix) {
38
- console.log('\n🔄 Auto-Fix Mode Enabled');
39
- console.log(' • Will automatically fix issues until threshold is met');
40
- console.log(` • Maximum iterations: ${this.maxIterations}`);
41
- console.log(` • Target threshold: ${this.threshold}`);
42
-
43
- // Start the recursive fix loop
44
- await this.recursiveFixLoop();
45
- } else if (this.verify) {
46
- await this.runVerification();
10
+ let AutoFixPairSession = class AutoFixPairSession {
11
+ async start() {
12
+ await this.saveSession();
13
+ this.showWelcome();
14
+ if (this.verify && this.autoFix) {
15
+ console.log('\n🔄 Auto-Fix Mode Enabled');
16
+ console.log(' • Will automatically fix issues until threshold is met');
17
+ console.log(` • Maximum iterations: ${this.maxIterations}`);
18
+ console.log(` • Target threshold: ${this.threshold}`);
19
+ // Start the recursive fix loop
20
+ await this.recursiveFixLoop();
21
+ } else if (this.verify) {
22
+ await this.runVerification();
23
+ }
24
+ await this.startInteractiveMode();
47
25
  }
48
-
49
- await this.startInteractiveMode();
50
- }
51
-
52
- /**
26
+ /**
53
27
  * Recursive stream-chaining loop that fixes issues until threshold is met
54
- */
55
- async recursiveFixLoop() {
56
- console.log('\n🚀 Starting Recursive Auto-Fix Loop...');
57
- console.log('━'.repeat(50));
58
-
59
- let score = 0;
60
- this.currentIteration = 0;
61
-
62
- while (score < this.threshold && this.currentIteration < this.maxIterations) {
63
- this.currentIteration++;
64
- console.log(`\n📍 Iteration ${this.currentIteration}/${this.maxIterations}`);
65
-
66
- // Step 1: Run verification
67
- const verificationResult = await this.runVerification();
68
- score = verificationResult.score;
69
-
70
- if (score >= this.threshold) {
71
- console.log(`\n Threshold met! Score: ${score.toFixed(2)} >= ${this.threshold}`);
72
- break;
73
- }
74
-
75
- // Step 2: Identify issues
76
- const issues = this.identifyIssues(verificationResult);
77
- console.log(`\n🔍 Issues found: ${issues.length}`);
78
- issues.forEach((issue) => console.log(` • ${issue.type}: ${issue.description}`));
79
-
80
- // Step 3: Create fix chain
81
- if (issues.length > 0) {
82
- console.log('\n🔗 Creating stream-chain to fix issues...');
83
- await this.createFixChain(issues);
84
- }
85
-
86
- // Step 4: Wait a bit before next iteration
87
- await new Promise((resolve) => setTimeout(resolve, 2000));
88
- }
89
-
90
- if (score < this.threshold) {
91
- console.log(`\n⚠️ Max iterations reached. Final score: ${score.toFixed(2)}`);
92
- console.log('💡 Manual intervention may be required.');
93
- } else {
94
- console.log(`\n🎉 Success! All issues fixed. Final score: ${score.toFixed(2)}`);
28
+ */ async recursiveFixLoop() {
29
+ console.log('\n🚀 Starting Recursive Auto-Fix Loop...');
30
+ console.log(''.repeat(50));
31
+ let score = 0;
32
+ this.currentIteration = 0;
33
+ while(score < this.threshold && this.currentIteration < this.maxIterations){
34
+ this.currentIteration++;
35
+ console.log(`\n📍 Iteration ${this.currentIteration}/${this.maxIterations}`);
36
+ // Step 1: Run verification
37
+ const verificationResult = await this.runVerification();
38
+ score = verificationResult.score;
39
+ if (score >= this.threshold) {
40
+ console.log(`\n✨ Threshold met! Score: ${score.toFixed(2)} >= ${this.threshold}`);
41
+ break;
42
+ }
43
+ // Step 2: Identify issues
44
+ const issues = this.identifyIssues(verificationResult);
45
+ console.log(`\n🔍 Issues found: ${issues.length}`);
46
+ issues.forEach((issue)=>console.log(` • ${issue.type}: ${issue.description}`));
47
+ // Step 3: Create fix chain
48
+ if (issues.length > 0) {
49
+ console.log('\n🔗 Creating stream-chain to fix issues...');
50
+ await this.createFixChain(issues);
51
+ }
52
+ // Step 4: Wait a bit before next iteration
53
+ await new Promise((resolve)=>setTimeout(resolve, 2000));
54
+ }
55
+ if (score < this.threshold) {
56
+ console.log(`\n⚠️ Max iterations reached. Final score: ${score.toFixed(2)}`);
57
+ console.log('💡 Manual intervention may be required.');
58
+ } else {
59
+ console.log(`\n🎉 Success! All issues fixed. Final score: ${score.toFixed(2)}`);
60
+ }
61
+ // Show fix history
62
+ this.showFixHistory();
95
63
  }
96
-
97
- // Show fix history
98
- this.showFixHistory();
99
- }
100
-
101
- /**
64
+ /**
102
65
  * Create a stream chain to fix identified issues
103
- */
104
- async createFixChain(issues) {
105
- const chains = [];
106
-
107
- for (const issue of issues) {
108
- let chainCommand = null;
109
-
110
- switch (issue.type) {
111
- case 'lint':
112
- chainCommand = this.createLintFixChain();
113
- break;
114
- case 'typecheck':
115
- chainCommand = this.createTypeFixChain();
116
- break;
117
- case 'build':
118
- chainCommand = this.createBuildFixChain();
119
- break;
120
- case 'test':
121
- chainCommand = this.createTestFixChain();
122
- break;
123
- }
124
-
125
- if (chainCommand) {
126
- chains.push(chainCommand);
127
- }
128
- }
129
-
130
- // Execute fix chains
131
- for (const chain of chains) {
132
- console.log(` 🔧 Executing: ${chain.description}`);
133
- await this.executeChain(chain);
134
-
135
- // Record fix attempt
136
- this.fixHistory.push({
137
- iteration: this.currentIteration,
138
- type: chain.type,
139
- command: chain.command,
140
- timestamp: new Date(),
141
- });
142
- }
143
- }
144
-
145
- /**
146
- * Create lint fix chain using stream-chaining
147
- */
148
- createLintFixChain() {
149
- return {
150
- type: 'lint',
151
- description: 'Auto-fix linting issues',
152
- command: async () => {
153
- console.log(' Running: npm run lint --fix');
154
-
155
- // First, try auto-fix
156
- try {
157
- await execAsync('npm run lint -- --fix 2>&1 || true');
158
- console.log(' ✅ Linting auto-fix applied');
159
- } catch (error) {
160
- console.log(' ⚠️ Some linting issues require manual fixes');
66
+ */ async createFixChain(issues) {
67
+ const chains = [];
68
+ for (const issue of issues){
69
+ let chainCommand = null;
70
+ switch(issue.type){
71
+ case 'lint':
72
+ chainCommand = this.createLintFixChain();
73
+ break;
74
+ case 'typecheck':
75
+ chainCommand = this.createTypeFixChain();
76
+ break;
77
+ case 'build':
78
+ chainCommand = this.createBuildFixChain();
79
+ break;
80
+ case 'test':
81
+ chainCommand = this.createTestFixChain();
82
+ break;
83
+ }
84
+ if (chainCommand) {
85
+ chains.push(chainCommand);
86
+ }
161
87
  }
162
-
163
- // If complex issues remain, use Claude stream chain
164
- const { stdout: lintOutput } = await execAsync('npm run lint 2>&1 || true');
165
- if (lintOutput.includes('error')) {
166
- console.log(' 🤖 Using Claude to fix remaining issues...');
167
- await this.executeClaudeFixChain('lint', lintOutput);
88
+ // Execute fix chains
89
+ for (const chain of chains){
90
+ console.log(` 🔧 Executing: ${chain.description}`);
91
+ await this.executeChain(chain);
92
+ // Record fix attempt
93
+ this.fixHistory.push({
94
+ iteration: this.currentIteration,
95
+ type: chain.type,
96
+ command: chain.command,
97
+ timestamp: new Date()
98
+ });
168
99
  }
169
- },
170
- };
171
- }
172
-
173
- /**
100
+ }
101
+ /**
102
+ * Create lint fix chain using stream-chaining
103
+ */ createLintFixChain() {
104
+ return {
105
+ type: 'lint',
106
+ description: 'Auto-fix linting issues',
107
+ command: async ()=>{
108
+ console.log(' Running: npm run lint --fix');
109
+ // First, try auto-fix
110
+ try {
111
+ await execAsync('npm run lint -- --fix 2>&1 || true');
112
+ console.log(' ✅ Linting auto-fix applied');
113
+ } catch (error) {
114
+ console.log(' ⚠️ Some linting issues require manual fixes');
115
+ }
116
+ // If complex issues remain, use Claude stream chain
117
+ const { stdout: lintOutput } = await execAsync('npm run lint 2>&1 || true');
118
+ if (lintOutput.includes('error')) {
119
+ console.log(' 🤖 Using Claude to fix remaining issues...');
120
+ await this.executeClaudeFixChain('lint', lintOutput);
121
+ }
122
+ }
123
+ };
124
+ }
125
+ /**
174
126
  * Create TypeScript fix chain
175
- */
176
- createTypeFixChain() {
177
- return {
178
- type: 'typecheck',
179
- description: 'Fix TypeScript errors',
180
- command: async () => {
181
- console.log(' Analyzing TypeScript errors...');
182
-
183
- // Get type errors
184
- const { stdout: typeErrors } = await execAsync('npm run typecheck 2>&1 || true');
185
-
186
- if (typeErrors.includes('error')) {
187
- console.log(' 🤖 Using Claude to fix type errors...');
188
- await this.executeClaudeFixChain('typescript', typeErrors);
189
- }
190
- },
191
- };
192
- }
193
-
194
- /**
127
+ */ createTypeFixChain() {
128
+ return {
129
+ type: 'typecheck',
130
+ description: 'Fix TypeScript errors',
131
+ command: async ()=>{
132
+ console.log(' Analyzing TypeScript errors...');
133
+ // Get type errors
134
+ const { stdout: typeErrors } = await execAsync('npm run typecheck 2>&1 || true');
135
+ if (typeErrors.includes('error')) {
136
+ console.log(' 🤖 Using Claude to fix type errors...');
137
+ await this.executeClaudeFixChain('typescript', typeErrors);
138
+ }
139
+ }
140
+ };
141
+ }
142
+ /**
195
143
  * Create build fix chain
196
- */
197
- createBuildFixChain() {
198
- return {
199
- type: 'build',
200
- description: 'Fix build errors',
201
- command: async () => {
202
- console.log(' Analyzing build errors...');
203
-
204
- const { stdout: buildErrors } = await execAsync('npm run build 2>&1 || true');
205
-
206
- if (buildErrors.includes('error')) {
207
- console.log(' 🤖 Using Claude to fix build errors...');
208
- await this.executeClaudeFixChain('build', buildErrors);
209
- }
210
- },
211
- };
212
- }
213
-
214
- /**
144
+ */ createBuildFixChain() {
145
+ return {
146
+ type: 'build',
147
+ description: 'Fix build errors',
148
+ command: async ()=>{
149
+ console.log(' Analyzing build errors...');
150
+ const { stdout: buildErrors } = await execAsync('npm run build 2>&1 || true');
151
+ if (buildErrors.includes('error')) {
152
+ console.log(' 🤖 Using Claude to fix build errors...');
153
+ await this.executeClaudeFixChain('build', buildErrors);
154
+ }
155
+ }
156
+ };
157
+ }
158
+ /**
215
159
  * Create test fix chain
216
- */
217
- createTestFixChain() {
218
- return {
219
- type: 'test',
220
- description: 'Fix failing tests',
221
- command: async () => {
222
- console.log(' Analyzing test failures...');
223
-
224
- const { stdout: testOutput } = await execAsync('npm test 2>&1 || true');
225
-
226
- if (testOutput.includes('fail')) {
227
- console.log(' 🤖 Using Claude to fix test failures...');
228
- await this.executeClaudeFixChain('test', testOutput);
229
- }
230
- },
231
- };
232
- }
233
-
234
- /**
160
+ */ createTestFixChain() {
161
+ return {
162
+ type: 'test',
163
+ description: 'Fix failing tests',
164
+ command: async ()=>{
165
+ console.log(' Analyzing test failures...');
166
+ const { stdout: testOutput } = await execAsync('npm test 2>&1 || true');
167
+ if (testOutput.includes('fail')) {
168
+ console.log(' 🤖 Using Claude to fix test failures...');
169
+ await this.executeClaudeFixChain('test', testOutput);
170
+ }
171
+ }
172
+ };
173
+ }
174
+ /**
235
175
  * Execute Claude stream chain to fix specific issues
236
- */
237
- async executeClaudeFixChain(type, errorOutput) {
238
- const prompts = {
239
- lint: `Fix these ESLint errors. Output only the corrected code:\n\n${errorOutput}`,
240
- typescript: `Fix these TypeScript errors. Output only the corrected code:\n\n${errorOutput}`,
241
- build: `Fix these build errors. Output only the corrected code:\n\n${errorOutput}`,
242
- test: `Fix these test failures. Output only the corrected code:\n\n${errorOutput}`,
243
- };
244
-
245
- return new Promise((resolve, reject) => {
246
- // Create stream chain using Claude
247
- const claude = spawn('claude', ['-p', '--output-format', 'stream-json', prompts[type]]);
248
-
249
- let output = '';
250
-
251
- claude.stdout.on('data', (data) => {
252
- output += data.toString();
253
- });
254
-
255
- claude.on('close', (code) => {
256
- if (code === 0) {
257
- // Parse and apply fixes
258
- this.applyClaudeFixes(type, output);
259
- resolve();
260
- } else {
261
- reject(new Error(`Claude fix chain failed with code ${code}`));
262
- }
263
- });
264
-
265
- claude.on('error', (error) => {
266
- console.error(' ❌ Claude chain error:', error.message);
267
- reject(error);
268
- });
269
- });
270
- }
271
-
272
- /**
176
+ */ async executeClaudeFixChain(type, errorOutput) {
177
+ const prompts = {
178
+ lint: `Fix these ESLint errors. Output only the corrected code:\n\n${errorOutput}`,
179
+ typescript: `Fix these TypeScript errors. Output only the corrected code:\n\n${errorOutput}`,
180
+ build: `Fix these build errors. Output only the corrected code:\n\n${errorOutput}`,
181
+ test: `Fix these test failures. Output only the corrected code:\n\n${errorOutput}`
182
+ };
183
+ return new Promise((resolve, reject)=>{
184
+ // Create stream chain using Claude
185
+ const claude = spawn('claude', [
186
+ '-p',
187
+ '--output-format',
188
+ 'stream-json',
189
+ prompts[type]
190
+ ]);
191
+ let output = '';
192
+ claude.stdout.on('data', (data)=>{
193
+ output += data.toString();
194
+ });
195
+ claude.on('close', (code)=>{
196
+ if (code === 0) {
197
+ // Parse and apply fixes
198
+ this.applyClaudeFixes(type, output);
199
+ resolve();
200
+ } else {
201
+ reject(new Error(`Claude fix chain failed with code ${code}`));
202
+ }
203
+ });
204
+ claude.on('error', (error)=>{
205
+ console.error(' ❌ Claude chain error:', error.message);
206
+ reject(error);
207
+ });
208
+ });
209
+ }
210
+ /**
273
211
  * Apply fixes suggested by Claude
274
- */
275
- async applyClaudeFixes(type, streamOutput) {
276
- try {
277
- // Extract content from stream-json output
278
- const fixes = this.extractFixesFromStream(streamOutput);
279
-
280
- if (fixes && fixes.length > 0) {
281
- console.log(` 📝 Applying ${fixes.length} fixes...`);
282
-
283
- // Apply each fix (simplified - in production would need file mapping)
284
- for (const fix of fixes) {
285
- // This is simplified - real implementation would parse and apply fixes
286
- console.log(` • Fixed: ${fix.file || type}`);
212
+ */ async applyClaudeFixes(type, streamOutput) {
213
+ try {
214
+ // Extract content from stream-json output
215
+ const fixes = this.extractFixesFromStream(streamOutput);
216
+ if (fixes && fixes.length > 0) {
217
+ console.log(` 📝 Applying ${fixes.length} fixes...`);
218
+ // Apply each fix (simplified - in production would need file mapping)
219
+ for (const fix of fixes){
220
+ // This is simplified - real implementation would parse and apply fixes
221
+ console.log(` • Fixed: ${fix.file || type}`);
222
+ }
223
+ console.log(' ✅ Fixes applied successfully');
224
+ }
225
+ } catch (error) {
226
+ console.error(' ⚠️ Could not apply all fixes:', error.message);
287
227
  }
288
-
289
- console.log(' ✅ Fixes applied successfully');
290
- }
291
- } catch (error) {
292
- console.error(' ⚠️ Could not apply all fixes:', error.message);
293
228
  }
294
- }
295
-
296
- /**
229
+ /**
297
230
  * Extract fixes from Claude's stream-json output
298
- */
299
- extractFixesFromStream(streamOutput) {
300
- const fixes = [];
301
- const lines = streamOutput.split('\n').filter((line) => line.trim());
302
-
303
- for (const line of lines) {
304
- try {
305
- const json = JSON.parse(line);
306
-
307
- // Look for code fixes in the stream
308
- if (json.type === 'message' && json.message && json.message.content) {
309
- for (const item of json.message.content) {
310
- if (item.type === 'text' && item.text) {
311
- // Parse for code blocks or fix instructions
312
- const codeMatch = item.text.match(/```[\w]*\n([\s\S]*?)```/g);
313
- if (codeMatch) {
314
- fixes.push({
315
- type: 'code',
316
- content: codeMatch[0].replace(/```[\w]*\n|```/g, ''),
317
- });
318
- }
231
+ */ extractFixesFromStream(streamOutput) {
232
+ const fixes = [];
233
+ const lines = streamOutput.split('\n').filter((line)=>line.trim());
234
+ for (const line of lines){
235
+ try {
236
+ const json = JSON.parse(line);
237
+ // Look for code fixes in the stream
238
+ if (json.type === 'message' && json.message && json.message.content) {
239
+ for (const item of json.message.content){
240
+ if (item.type === 'text' && item.text) {
241
+ // Parse for code blocks or fix instructions
242
+ const codeMatch = item.text.match(/```[\w]*\n([\s\S]*?)```/g);
243
+ if (codeMatch) {
244
+ fixes.push({
245
+ type: 'code',
246
+ content: codeMatch[0].replace(/```[\w]*\n|```/g, '')
247
+ });
248
+ }
249
+ }
250
+ }
251
+ }
252
+ } catch (e) {
253
+ // Skip non-JSON lines
319
254
  }
320
- }
321
255
  }
322
- } catch (e) {
323
- // Skip non-JSON lines
324
- }
256
+ return fixes;
325
257
  }
326
-
327
- return fixes;
328
- }
329
-
330
- /**
258
+ /**
331
259
  * Execute a fix chain command
332
- */
333
- async executeChain(chain) {
334
- try {
335
- await chain.command();
336
- } catch (error) {
337
- console.error(` ❌ Fix failed: ${error.message}`);
260
+ */ async executeChain(chain) {
261
+ try {
262
+ await chain.command();
263
+ } catch (error) {
264
+ console.error(` Fix failed: ${error.message}`);
265
+ }
338
266
  }
339
- }
340
-
341
- /**
267
+ /**
342
268
  * Identify issues from verification results
343
- */
344
- identifyIssues(verificationResult) {
345
- const issues = [];
346
-
347
- if (verificationResult.results) {
348
- for (const check of verificationResult.results) {
349
- if (check.score < 0.8) {
350
- issues.push({
351
- type: check.name.toLowerCase().replace(' check', '').replace(' ', ''),
352
- description: `Score: ${check.score.toFixed(2)}`,
353
- severity: check.score < 0.5 ? 'high' : 'medium',
354
- });
269
+ */ identifyIssues(verificationResult) {
270
+ const issues = [];
271
+ if (verificationResult.results) {
272
+ for (const check of verificationResult.results){
273
+ if (check.score < 0.8) {
274
+ issues.push({
275
+ type: check.name.toLowerCase().replace(' check', '').replace(' ', ''),
276
+ description: `Score: ${check.score.toFixed(2)}`,
277
+ severity: check.score < 0.5 ? 'high' : 'medium'
278
+ });
279
+ }
280
+ }
355
281
  }
356
- }
282
+ return issues;
357
283
  }
358
-
359
- return issues;
360
- }
361
-
362
- /**
284
+ /**
363
285
  * Run verification and return detailed results
364
- */
365
- async runVerification() {
366
- console.log('\n🔍 Running verification check...');
367
-
368
- const checks = [
369
- {
370
- name: 'Type Check',
371
- command: 'npm run typecheck 2>&1 || true',
372
- weight: 0.4,
373
- },
374
- {
375
- name: 'Linting',
376
- command: 'npm run lint 2>&1 || true',
377
- weight: 0.3,
378
- },
379
- {
380
- name: 'Build',
381
- command: 'npm run build 2>&1 || true',
382
- weight: 0.3,
383
- },
384
- ];
385
-
386
- const results = [];
387
- let totalScore = 0;
388
- let totalWeight = 0;
389
-
390
- for (const check of checks) {
391
- try {
392
- const { stdout, stderr } = await execAsync(check.command);
393
- const output = stdout + stderr;
394
-
395
- let score = 1.0;
396
- if (output.toLowerCase().includes('error')) {
397
- const errorCount = (output.match(/error/gi) || []).length;
398
- score = Math.max(0.2, 1.0 - errorCount * 0.1);
399
- } else if (output.toLowerCase().includes('warning')) {
400
- const warningCount = (output.match(/warning/gi) || []).length;
401
- score = Math.max(0.7, 1.0 - warningCount * 0.05);
286
+ */ async runVerification() {
287
+ console.log('\n🔍 Running verification check...');
288
+ const checks = [
289
+ {
290
+ name: 'Type Check',
291
+ command: 'npm run typecheck 2>&1 || true',
292
+ weight: 0.4
293
+ },
294
+ {
295
+ name: 'Linting',
296
+ command: 'npm run lint 2>&1 || true',
297
+ weight: 0.3
298
+ },
299
+ {
300
+ name: 'Build',
301
+ command: 'npm run build 2>&1 || true',
302
+ weight: 0.3
303
+ }
304
+ ];
305
+ const results = [];
306
+ let totalScore = 0;
307
+ let totalWeight = 0;
308
+ for (const check of checks){
309
+ try {
310
+ const { stdout, stderr } = await execAsync(check.command);
311
+ const output = stdout + stderr;
312
+ let score = 1.0;
313
+ if (output.toLowerCase().includes('error')) {
314
+ const errorCount = (output.match(/error/gi) || []).length;
315
+ score = Math.max(0.2, 1.0 - errorCount * 0.1);
316
+ } else if (output.toLowerCase().includes('warning')) {
317
+ const warningCount = (output.match(/warning/gi) || []).length;
318
+ score = Math.max(0.7, 1.0 - warningCount * 0.05);
319
+ }
320
+ totalScore += score * check.weight;
321
+ totalWeight += check.weight;
322
+ const icon = score >= 0.8 ? '✅' : score >= 0.5 ? '⚠️' : '❌';
323
+ console.log(` ${icon} ${check.name}: ${score.toFixed(2)}`);
324
+ results.push({
325
+ name: check.name,
326
+ score,
327
+ output: output.slice(0, 200),
328
+ errors: (output.match(/error/gi) || []).length,
329
+ warnings: (output.match(/warning/gi) || []).length
330
+ });
331
+ } catch (error) {
332
+ console.log(` ❌ ${check.name}: 0.00 (failed)`);
333
+ results.push({
334
+ name: check.name,
335
+ score: 0,
336
+ error: error.message
337
+ });
338
+ totalWeight += check.weight;
339
+ }
402
340
  }
403
-
404
- totalScore += score * check.weight;
405
- totalWeight += check.weight;
406
-
407
- const icon = score >= 0.8 ? '✅' : score >= 0.5 ? '⚠️' : '❌';
408
- console.log(` ${icon} ${check.name}: ${score.toFixed(2)}`);
409
-
410
- results.push({
411
- name: check.name,
412
- score,
413
- output: output.slice(0, 200),
414
- errors: (output.match(/error/gi) || []).length,
415
- warnings: (output.match(/warning/gi) || []).length,
416
- });
417
- } catch (error) {
418
- console.log(` ❌ ${check.name}: 0.00 (failed)`);
419
- results.push({ name: check.name, score: 0, error: error.message });
420
- totalWeight += check.weight;
421
- }
341
+ const averageScore = totalWeight > 0 ? totalScore / totalWeight : 0;
342
+ console.log(`\n📊 Verification Score: ${averageScore.toFixed(2)}/${this.threshold}`);
343
+ const verificationResult = {
344
+ score: averageScore,
345
+ results,
346
+ timestamp: new Date(),
347
+ iteration: this.currentIteration
348
+ };
349
+ this.verificationScores.push(verificationResult);
350
+ return verificationResult;
422
351
  }
423
-
424
- const averageScore = totalWeight > 0 ? totalScore / totalWeight : 0;
425
-
426
- console.log(`\n📊 Verification Score: ${averageScore.toFixed(2)}/${this.threshold}`);
427
-
428
- const verificationResult = {
429
- score: averageScore,
430
- results,
431
- timestamp: new Date(),
432
- iteration: this.currentIteration,
433
- };
434
-
435
- this.verificationScores.push(verificationResult);
436
-
437
- return verificationResult;
438
- }
439
-
440
- /**
352
+ /**
441
353
  * Show fix history
442
- */
443
- showFixHistory() {
444
- if (this.fixHistory.length > 0) {
445
- console.log('\n📋 Fix History:');
446
- console.log('━'.repeat(50));
447
-
448
- for (const fix of this.fixHistory) {
449
- console.log(
450
- ` Iteration ${fix.iteration}: Fixed ${fix.type} at ${fix.timestamp.toLocaleTimeString()}`,
451
- );
452
- }
453
-
454
- console.log('━'.repeat(50));
455
- console.log(` Total fixes applied: ${this.fixHistory.length}`);
456
- console.log(` Final iterations: ${this.currentIteration}`);
354
+ */ showFixHistory() {
355
+ if (this.fixHistory.length > 0) {
356
+ console.log('\n📋 Fix History:');
357
+ console.log(''.repeat(50));
358
+ for (const fix of this.fixHistory){
359
+ console.log(` Iteration ${fix.iteration}: Fixed ${fix.type} at ${fix.timestamp.toLocaleTimeString()}`);
360
+ }
361
+ console.log('━'.repeat(50));
362
+ console.log(` Total fixes applied: ${this.fixHistory.length}`);
363
+ console.log(` Final iterations: ${this.currentIteration}`);
364
+ }
457
365
  }
458
- }
459
-
460
- showWelcome() {
461
- console.log('\n🚀 Starting Pair Programming Session');
462
- console.log('━'.repeat(50));
463
- console.log(`Session ID: ${this.sessionId}`);
464
- console.log(`Mode: ${this.mode}`);
465
- console.log(`Verification: ${this.verify ? '✅ Enabled' : '❌ Disabled'}`);
466
- console.log(`Auto-Fix: ${this.autoFix ? '✅ Enabled' : '❌ Disabled'}`);
467
- console.log(`Testing: ${this.test ? '✅ Enabled' : '❌ Disabled'}`);
468
-
469
- if (this.autoFix) {
470
- console.log(`\n🔄 Recursive Auto-Fix Settings:`);
471
- console.log(` • Target threshold: ${this.threshold}`);
472
- console.log(` • Max iterations: ${this.maxIterations}`);
473
- console.log(` • Stream chaining: Enabled`);
366
+ showWelcome() {
367
+ console.log('\n🚀 Starting Pair Programming Session');
368
+ console.log('━'.repeat(50));
369
+ console.log(`Session ID: ${this.sessionId}`);
370
+ console.log(`Mode: ${this.mode}`);
371
+ console.log(`Verification: ${this.verify ? '✅ Enabled' : '❌ Disabled'}`);
372
+ console.log(`Auto-Fix: ${this.autoFix ? '✅ Enabled' : '❌ Disabled'}`);
373
+ console.log(`Testing: ${this.test ? '✅ Enabled' : '❌ Disabled'}`);
374
+ if (this.autoFix) {
375
+ console.log(`\n🔄 Recursive Auto-Fix Settings:`);
376
+ console.log(` • Target threshold: ${this.threshold}`);
377
+ console.log(` • Max iterations: ${this.maxIterations}`);
378
+ console.log(` • Stream chaining: Enabled`);
379
+ }
380
+ console.log('━'.repeat(50));
474
381
  }
475
-
476
- console.log('━'.repeat(50));
477
- }
478
-
479
- async startInteractiveMode() {
480
- this.rl = readline.createInterface({
481
- input: process.stdin,
482
- output: process.stdout,
483
- prompt: '\n💻 pair> ',
484
- });
485
-
486
- console.log('\n💡 Interactive mode active. Type /help for commands.\n');
487
-
488
- this.showCommands();
489
- this.rl.prompt();
490
-
491
- this.rl.on('line', async (line) => {
492
- const input = line.trim();
493
-
494
- if (input.startsWith('/')) {
495
- await this.handleCommand(input);
496
- } else if (input) {
497
- console.log('🤖 AI: Processing your input...');
498
- }
499
-
500
- this.rl.prompt();
501
- });
502
-
503
- this.rl.on('close', () => {
504
- this.end();
505
- });
506
- }
507
-
508
- showCommands() {
509
- console.log('\n📝 Session Commands:');
510
- console.log(' /help - Show available commands');
511
- console.log(' /verify - Run verification check');
512
- console.log(' /autofix - Start recursive auto-fix');
513
- console.log(' /status - Show session status');
514
- console.log(' /metrics - Show quality metrics');
515
- console.log(' /history - Show fix history');
516
- console.log(' /test - Run tests');
517
- console.log(' /commit - Commit with verification');
518
- console.log(' /end - End session');
519
- }
520
-
521
- async handleCommand(command) {
522
- const [cmd] = command.split(' ');
523
-
524
- switch (cmd) {
525
- case '/help':
382
+ async startInteractiveMode() {
383
+ this.rl = readline.createInterface({
384
+ input: process.stdin,
385
+ output: process.stdout,
386
+ prompt: '\n💻 pair> '
387
+ });
388
+ console.log('\n💡 Interactive mode active. Type /help for commands.\n');
526
389
  this.showCommands();
527
- break;
528
-
529
- case '/verify':
530
- await this.runVerification();
531
- break;
532
-
533
- case '/autofix':
534
- await this.recursiveFixLoop();
535
- break;
536
-
537
- case '/status':
538
- await this.showStatus();
539
- break;
540
-
541
- case '/metrics':
542
- this.showMetrics();
543
- break;
544
-
545
- case '/history':
546
- this.showFixHistory();
547
- break;
548
-
549
- case '/test':
550
- await this.runTests();
551
- break;
552
-
553
- case '/commit':
554
- await this.commitWithVerification();
555
- break;
556
-
557
- case '/end':
558
- case '/exit':
559
- await this.end();
560
- process.exit(0);
561
- break;
562
-
563
- default:
564
- console.log(`❌ Unknown command: ${cmd}`);
565
- console.log('💡 Type /help for available commands');
390
+ this.rl.prompt();
391
+ this.rl.on('line', async (line)=>{
392
+ const input = line.trim();
393
+ if (input.startsWith('/')) {
394
+ await this.handleCommand(input);
395
+ } else if (input) {
396
+ console.log('🤖 AI: Processing your input...');
397
+ }
398
+ this.rl.prompt();
399
+ });
400
+ this.rl.on('close', ()=>{
401
+ this.end();
402
+ });
566
403
  }
567
- }
568
-
569
- async showStatus() {
570
- const duration = Math.floor((Date.now() - this.startTime) / 1000 / 60);
571
-
572
- console.log('\n📊 Session Status');
573
- console.log(''.repeat(40));
574
- console.log(`Session ID: ${this.sessionId}`);
575
- console.log(`Duration: ${duration} minutes`);
576
- console.log(`Auto-Fix: ${this.autoFix ? 'Enabled' : 'Disabled'}`);
577
- console.log(`Fix Iterations: ${this.currentIteration}`);
578
- console.log(`Fixes Applied: ${this.fixHistory.length}`);
579
-
580
- if (this.verificationScores.length > 0) {
581
- const latest = this.verificationScores[this.verificationScores.length - 1];
582
- console.log(`Latest Score: ${latest.score.toFixed(2)}`);
404
+ showCommands() {
405
+ console.log('\n📝 Session Commands:');
406
+ console.log(' /help - Show available commands');
407
+ console.log(' /verify - Run verification check');
408
+ console.log(' /autofix - Start recursive auto-fix');
409
+ console.log(' /status - Show session status');
410
+ console.log(' /metrics - Show quality metrics');
411
+ console.log(' /history - Show fix history');
412
+ console.log(' /test - Run tests');
413
+ console.log(' /commit - Commit with verification');
414
+ console.log(' /end - End session');
583
415
  }
584
- }
585
-
586
- showMetrics() {
587
- console.log('\n📈 Quality Metrics');
588
- console.log('━'.repeat(40));
589
-
590
- if (this.verificationScores.length > 0) {
591
- console.log('\nScore Progression:');
592
- this.verificationScores.forEach((v, i) => {
593
- const bar = ''.repeat(Math.floor(v.score * 20));
594
- console.log(` ${i + 1}. ${bar} ${v.score.toFixed(2)}`);
595
- });
596
-
597
- // Show improvement
598
- if (this.verificationScores.length > 1) {
599
- const first = this.verificationScores[0].score;
600
- const last = this.verificationScores[this.verificationScores.length - 1].score;
601
- const improvement = ((last - first) * 100).toFixed(1);
602
- console.log(`\n Improvement: +${improvement}%`);
603
- }
416
+ async handleCommand(command) {
417
+ const [cmd] = command.split(' ');
418
+ switch(cmd){
419
+ case '/help':
420
+ this.showCommands();
421
+ break;
422
+ case '/verify':
423
+ await this.runVerification();
424
+ break;
425
+ case '/autofix':
426
+ await this.recursiveFixLoop();
427
+ break;
428
+ case '/status':
429
+ await this.showStatus();
430
+ break;
431
+ case '/metrics':
432
+ this.showMetrics();
433
+ break;
434
+ case '/history':
435
+ this.showFixHistory();
436
+ break;
437
+ case '/test':
438
+ await this.runTests();
439
+ break;
440
+ case '/commit':
441
+ await this.commitWithVerification();
442
+ break;
443
+ case '/end':
444
+ case '/exit':
445
+ await this.end();
446
+ process.exit(0);
447
+ break;
448
+ default:
449
+ console.log(`❌ Unknown command: ${cmd}`);
450
+ console.log('💡 Type /help for available commands');
451
+ }
604
452
  }
605
- }
606
-
607
- async runTests() {
608
- console.log('\n🧪 Running tests...');
609
- try {
610
- const { stdout } = await execAsync('npm test 2>&1 || true');
611
- const passed = stdout.includes('PASS');
612
- console.log(` ${passed ? '✅' : '❌'} Tests ${passed ? 'passed' : 'failed'}`);
613
- return passed;
614
- } catch (error) {
615
- console.log(' ❌ Test execution failed:', error.message);
616
- return false;
453
+ async showStatus() {
454
+ const duration = Math.floor((Date.now() - this.startTime) / 1000 / 60);
455
+ console.log('\n📊 Session Status');
456
+ console.log(''.repeat(40));
457
+ console.log(`Session ID: ${this.sessionId}`);
458
+ console.log(`Duration: ${duration} minutes`);
459
+ console.log(`Auto-Fix: ${this.autoFix ? 'Enabled' : 'Disabled'}`);
460
+ console.log(`Fix Iterations: ${this.currentIteration}`);
461
+ console.log(`Fixes Applied: ${this.fixHistory.length}`);
462
+ if (this.verificationScores.length > 0) {
463
+ const latest = this.verificationScores[this.verificationScores.length - 1];
464
+ console.log(`Latest Score: ${latest.score.toFixed(2)}`);
465
+ }
617
466
  }
618
- }
619
-
620
- async commitWithVerification() {
621
- const result = await this.runVerification();
622
-
623
- if (result.score >= this.threshold) {
624
- console.log('✅ Verification passed! Ready to commit.');
625
- } else {
626
- console.log('❌ Verification failed!');
627
- console.log('💡 Run /autofix to automatically fix issues');
467
+ showMetrics() {
468
+ console.log('\n📈 Quality Metrics');
469
+ console.log('━'.repeat(40));
470
+ if (this.verificationScores.length > 0) {
471
+ console.log('\nScore Progression:');
472
+ this.verificationScores.forEach((v, i)=>{
473
+ const bar = '█'.repeat(Math.floor(v.score * 20));
474
+ console.log(` ${i + 1}. ${bar} ${v.score.toFixed(2)}`);
475
+ });
476
+ // Show improvement
477
+ if (this.verificationScores.length > 1) {
478
+ const first = this.verificationScores[0].score;
479
+ const last = this.verificationScores[this.verificationScores.length - 1].score;
480
+ const improvement = ((last - first) * 100).toFixed(1);
481
+ console.log(`\n Improvement: +${improvement}%`);
482
+ }
483
+ }
628
484
  }
629
- }
630
-
631
- async end() {
632
- console.log('\n🛑 Ending pair programming session...');
633
-
634
- if (this.rl) this.rl.close();
635
-
636
- this.status = 'completed';
637
- await this.saveSession();
638
-
639
- const duration = Math.floor((Date.now() - this.startTime) / 1000 / 60);
640
- console.log('\n✨ Session Complete!');
641
- console.log('━'.repeat(40));
642
- console.log(`Duration: ${duration} minutes`);
643
- console.log(`Total Fixes: ${this.fixHistory.length}`);
644
- console.log(`Final Iterations: ${this.currentIteration}`);
645
-
646
- if (this.verificationScores.length > 0) {
647
- const final = this.verificationScores[this.verificationScores.length - 1];
648
- console.log(`Final Score: ${final.score.toFixed(2)}`);
485
+ async runTests() {
486
+ console.log('\n🧪 Running tests...');
487
+ try {
488
+ const { stdout } = await execAsync('npm test 2>&1 || true');
489
+ const passed = stdout.includes('PASS');
490
+ console.log(` ${passed ? '✅' : '❌'} Tests ${passed ? 'passed' : 'failed'}`);
491
+ return passed;
492
+ } catch (error) {
493
+ console.log(' ❌ Test execution failed:', error.message);
494
+ return false;
495
+ }
649
496
  }
650
-
651
- console.log('\n👋 Thanks for pair programming!\n');
652
- }
653
-
654
- async saveSession() {
655
- const sessionPath = '.claude-flow/sessions/pair';
656
- await fs.mkdir(sessionPath, { recursive: true });
657
-
658
- const sessionData = {
659
- id: this.sessionId,
660
- mode: this.mode,
661
- verify: this.verify,
662
- autoFix: this.autoFix,
663
- threshold: this.threshold,
664
- startTime: this.startTime.toISOString(),
665
- status: this.status,
666
- verificationScores: this.verificationScores,
667
- fixHistory: this.fixHistory,
668
- iterations: this.currentIteration,
669
- };
670
-
671
- await fs.writeFile(
672
- path.join(sessionPath, `${this.sessionId}.json`),
673
- JSON.stringify(sessionData, null, 2),
674
- );
675
- }
676
- }
677
-
497
+ async commitWithVerification() {
498
+ const result = await this.runVerification();
499
+ if (result.score >= this.threshold) {
500
+ console.log('✅ Verification passed! Ready to commit.');
501
+ } else {
502
+ console.log('❌ Verification failed!');
503
+ console.log('💡 Run /autofix to automatically fix issues');
504
+ }
505
+ }
506
+ async end() {
507
+ console.log('\n🛑 Ending pair programming session...');
508
+ if (this.rl) this.rl.close();
509
+ this.status = 'completed';
510
+ await this.saveSession();
511
+ const duration = Math.floor((Date.now() - this.startTime) / 1000 / 60);
512
+ console.log('\n✨ Session Complete!');
513
+ console.log('━'.repeat(40));
514
+ console.log(`Duration: ${duration} minutes`);
515
+ console.log(`Total Fixes: ${this.fixHistory.length}`);
516
+ console.log(`Final Iterations: ${this.currentIteration}`);
517
+ if (this.verificationScores.length > 0) {
518
+ const final = this.verificationScores[this.verificationScores.length - 1];
519
+ console.log(`Final Score: ${final.score.toFixed(2)}`);
520
+ }
521
+ console.log('\n👋 Thanks for pair programming!\n');
522
+ }
523
+ async saveSession() {
524
+ const sessionPath = '.claude-flow/sessions/pair';
525
+ await fs.mkdir(sessionPath, {
526
+ recursive: true
527
+ });
528
+ const sessionData = {
529
+ id: this.sessionId,
530
+ mode: this.mode,
531
+ verify: this.verify,
532
+ autoFix: this.autoFix,
533
+ threshold: this.threshold,
534
+ startTime: this.startTime.toISOString(),
535
+ status: this.status,
536
+ verificationScores: this.verificationScores,
537
+ fixHistory: this.fixHistory,
538
+ iterations: this.currentIteration
539
+ };
540
+ await fs.writeFile(path.join(sessionPath, `${this.sessionId}.json`), JSON.stringify(sessionData, null, 2));
541
+ }
542
+ constructor(options = {}){
543
+ this.sessionId = `pair_${Date.now()}`;
544
+ this.mode = options.mode || 'switch';
545
+ this.agent = options.agent || 'auto';
546
+ this.verify = options.verify || false;
547
+ this.autoFix = options.autoFix || false; // New: Enable recursive auto-fix
548
+ this.test = options.test || false;
549
+ this.threshold = options.threshold || 0.95;
550
+ this.maxIterations = options.maxIterations || 5; // Max fix attempts
551
+ this.startTime = new Date();
552
+ this.status = 'active';
553
+ this.currentRole = 'driver';
554
+ this.verificationScores = [];
555
+ this.fixHistory = [];
556
+ this.currentIteration = 0;
557
+ this.rl = null;
558
+ }
559
+ };
678
560
  async function pairCommand(args = [], flags = {}) {
679
- console.log('\n👥 Pair Programming with Auto-Fix');
680
- console.log('━'.repeat(50));
681
-
682
- if (flags.help || args.includes('--help')) {
561
+ console.log('\n👥 Pair Programming with Auto-Fix');
562
+ console.log('━'.repeat(50));
563
+ if (flags.help || args.includes('--help')) {
564
+ showHelp();
565
+ return;
566
+ }
567
+ if (flags.start) {
568
+ const session = new AutoFixPairSession({
569
+ mode: flags.mode || 'switch',
570
+ verify: flags.verify || false,
571
+ autoFix: flags.autofix || flags.fix || false,
572
+ test: flags.test || false,
573
+ threshold: parseFloat(flags.threshold) || 0.95,
574
+ maxIterations: parseInt(flags.iterations) || 5
575
+ });
576
+ return await session.start();
577
+ }
683
578
  showHelp();
684
- return;
685
- }
686
-
687
- if (flags.start) {
688
- const session = new AutoFixPairSession({
689
- mode: flags.mode || 'switch',
690
- verify: flags.verify || false,
691
- autoFix: flags.autofix || flags.fix || false,
692
- test: flags.test || false,
693
- threshold: parseFloat(flags.threshold) || 0.95,
694
- maxIterations: parseInt(flags.iterations) || 5,
695
- });
696
-
697
- return await session.start();
698
- }
699
-
700
- showHelp();
701
579
  }
702
-
703
580
  function showHelp() {
704
- console.log(`
581
+ console.log(`
705
582
  📚 USAGE:
706
583
  claude-flow-novice pair [options]
707
584
 
@@ -751,5 +628,4 @@ function showHelp() {
751
628
  .claude/commands/pair/README.md
752
629
  `);
753
630
  }
754
-
755
631
  export default pairCommand;