claude-flow-novice 1.3.0 → 1.3.2

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 (305) hide show
  1. package/.claude-flow-novice/preferences/generation.json +147 -0
  2. package/.claude-flow-novice/preferences/language-configs/javascript.json +51 -0
  3. package/.claude-flow-novice/preferences/language-configs/python.json +50 -0
  4. package/.claude-flow-novice/preferences/language-configs/rust.json +237 -0
  5. package/.claude-flow-novice/preferences/language-configs/typescript.json +54 -0
  6. package/.claude-flow-novice/preferences/project-local.json +91 -0
  7. package/.claude-flow-novice/preferences/resource-delegation.json +120 -0
  8. package/.claude-flow-novice/preferences/team-shared.json +195 -0
  9. package/.claude-flow-novice/preferences/user-global.json +247 -0
  10. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-JAVASCRIPT.md +769 -0
  11. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-PYTHON.md +1214 -0
  12. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-RUST.md +475 -0
  13. package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-TYPESCRIPT.md +851 -0
  14. package/.claude-flow-novice/templates/claude-md-templates/README.md +263 -0
  15. package/CLAUDE.md +81 -0
  16. package/README-NPM.md +0 -0
  17. package/package.json +11 -7
  18. package/scripts/build/README.md +167 -0
  19. package/scripts/build/build-config.js +27 -0
  20. package/scripts/build/build-prompt-copier.sh +30 -0
  21. package/scripts/build/performance-monitor.js +869 -0
  22. package/scripts/build/prepare-publish.js +150 -0
  23. package/scripts/build/typescript-fixer.js +621 -0
  24. package/scripts/build/unified-builder.sh +428 -0
  25. package/scripts/build/update-bin-version.js +32 -0
  26. package/scripts/dev/README.md +264 -0
  27. package/scripts/dev/claude-flow-wrapper.sh +35 -0
  28. package/scripts/dev/claude-monitor.py +419 -0
  29. package/scripts/dev/claude-sparc.sh +562 -0
  30. package/scripts/dev/claude-wrapper.sh +17 -0
  31. package/scripts/dev/demo-phase3-compliance.js +172 -0
  32. package/scripts/dev/demo-task-system.ts +224 -0
  33. package/scripts/dev/deployment-validator.js +315 -0
  34. package/scripts/dev/spawn-claude-terminal.sh +32 -0
  35. package/scripts/dev/start-portal.sh +506 -0
  36. package/scripts/dev/start-web-ui.js +15 -0
  37. package/scripts/dev/stop-portal.sh +311 -0
  38. package/scripts/dev/validate-examples.ts +288 -0
  39. package/scripts/dev/validate-phase2.cjs +451 -0
  40. package/scripts/dev/validate-phase2.js +785 -0
  41. package/scripts/dev/validate-phase3.cjs +208 -0
  42. package/scripts/dev/validate-security-remediation.js +1 -0
  43. package/scripts/legacy/README.md +272 -0
  44. package/scripts/legacy/batch-fix-ts.sh +54 -0
  45. package/scripts/legacy/build-migration.sh +105 -0
  46. package/scripts/legacy/build-monitor.js +209 -0
  47. package/scripts/legacy/build-with-filter.sh +84 -0
  48. package/scripts/legacy/build-workaround.sh +71 -0
  49. package/scripts/legacy/fix-ts-advanced.js +358 -0
  50. package/scripts/legacy/fix-ts-final.sh +50 -0
  51. package/scripts/legacy/fix-ts-targeted.sh +49 -0
  52. package/scripts/legacy/fix-typescript-errors.js +305 -0
  53. package/scripts/legacy/force-build.sh +63 -0
  54. package/scripts/legacy/optimize-performance.js +400 -0
  55. package/scripts/legacy/performance-monitor.js +263 -0
  56. package/scripts/legacy/performance-monitoring.js +532 -0
  57. package/scripts/legacy/performance-test-runner.js +645 -0
  58. package/scripts/legacy/quick-fix-ts.js +281 -0
  59. package/scripts/legacy/safe-build.sh +63 -0
  60. package/scripts/migration/README.md +434 -0
  61. package/scripts/migration/install-arm64.js +78 -0
  62. package/scripts/migration/install.js +83 -0
  63. package/scripts/migration/migrate-hooks.js +173 -0
  64. package/scripts/migration/migration-examples.ts +318 -0
  65. package/scripts/optimization/build-optimizer.js +438 -0
  66. package/scripts/optimization/config-validator.js +761 -0
  67. package/scripts/optimization/test-optimization.js +432 -0
  68. package/scripts/optimization/unified-activation.js +839 -0
  69. package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
  70. package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
  71. package/scripts/performance/test-enhanced-backend.sh +504 -0
  72. package/scripts/performance-test-runner.js +698 -0
  73. package/scripts/security/README.md +339 -0
  74. package/scripts/security/install-git-hooks.sh +132 -0
  75. package/scripts/security/ruv-swarm-safe.js +74 -0
  76. package/scripts/test/README.md +236 -0
  77. package/scripts/test/check-links.ts +274 -0
  78. package/scripts/test/check-performance-regression.ts +168 -0
  79. package/scripts/test/coverage-report.ts +692 -0
  80. package/scripts/test/generate-swarm-tests.js +633 -0
  81. package/scripts/test/integration-test-validation.cjs +253 -0
  82. package/scripts/test/load-test-swarm.js +576 -0
  83. package/scripts/test/run-phase3-compliance-tests.js +427 -0
  84. package/scripts/test/test-batch-tasks.ts +29 -0
  85. package/scripts/test/test-byzantine-resolution.js +246 -0
  86. package/scripts/test/test-claude-spawn-options.sh +63 -0
  87. package/scripts/test/test-cli-wizard.js +331 -0
  88. package/scripts/test/test-comprehensive.js +401 -0
  89. package/scripts/test/test-coordination-features.ts +238 -0
  90. package/scripts/test/test-fallback-systems.js +276 -0
  91. package/scripts/test/test-init-command.ts +302 -0
  92. package/scripts/test/test-mcp.ts +251 -0
  93. package/scripts/test/test-runner.ts +568 -0
  94. package/scripts/test/test-swarm-integration.sh +92 -0
  95. package/scripts/test/test-swarm.ts +142 -0
  96. package/scripts/test/validation-summary.ts +408 -0
  97. package/scripts/utils/README.md +261 -0
  98. package/scripts/utils/clean-build-artifacts.sh +94 -0
  99. package/scripts/utils/cleanup-root.sh +69 -0
  100. package/scripts/utils/fix-cliffy-imports.js +307 -0
  101. package/scripts/utils/fix-duplicate-imports.js +114 -0
  102. package/scripts/utils/fix-error-handling.cjs +70 -0
  103. package/scripts/utils/fix-import-paths.js +104 -0
  104. package/scripts/utils/fix-imports.js +116 -0
  105. package/scripts/utils/fix-shebang.js +78 -0
  106. package/scripts/utils/fix-test-modules.js +27 -0
  107. package/scripts/utils/fix-timezone-issue-246.js +200 -0
  108. package/scripts/utils/fix-ts-comprehensive.py +182 -0
  109. package/scripts/utils/fix-ts-targeted-batch.js +250 -0
  110. package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
  111. package/scripts/utils/simple-test-fixer.js +190 -0
  112. package/scripts/utils/validate-metrics-structure.cjs +144 -0
  113. package/scripts/verify-mcp-server.js +86 -0
  114. package/src/cli/simple-commands/__tests__/agent.test.js +291 -0
  115. package/src/cli/simple-commands/__tests__/memory.test.js +8 -0
  116. package/src/cli/simple-commands/__tests__/swarm.test.js +371 -0
  117. package/src/cli/simple-commands/__tests__/task.test.js +8 -0
  118. package/src/cli/simple-commands/agent.js +216 -0
  119. package/src/cli/simple-commands/analysis.js +570 -0
  120. package/src/cli/simple-commands/automation-executor.js +1603 -0
  121. package/src/cli/simple-commands/automation.js +627 -0
  122. package/src/cli/simple-commands/batch-manager.js +338 -0
  123. package/src/cli/simple-commands/claude-telemetry.js +311 -0
  124. package/src/cli/simple-commands/claude-track.js +102 -0
  125. package/src/cli/simple-commands/concurrent-display.js +348 -0
  126. package/src/cli/simple-commands/config.js +319 -0
  127. package/src/cli/simple-commands/coordination.js +307 -0
  128. package/src/cli/simple-commands/enhanced-ui-views.js +654 -0
  129. package/src/cli/simple-commands/enhanced-webui-complete.js +1038 -0
  130. package/src/cli/simple-commands/fix-hook-variables.js +363 -0
  131. package/src/cli/simple-commands/github/gh-coordinator.js +605 -0
  132. package/src/cli/simple-commands/github/github-api.js +624 -0
  133. package/src/cli/simple-commands/github/init.js +543 -0
  134. package/src/cli/simple-commands/github.js +377 -0
  135. package/src/cli/simple-commands/goal.js +145 -0
  136. package/src/cli/simple-commands/hive-mind/auto-save-middleware.js +311 -0
  137. package/src/cli/simple-commands/hive-mind/communication.js +740 -0
  138. package/src/cli/simple-commands/hive-mind/core.js +1031 -0
  139. package/src/cli/simple-commands/hive-mind/db-optimizer.js +872 -0
  140. package/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1364 -0
  141. package/src/cli/simple-commands/hive-mind/memory.js +1292 -0
  142. package/src/cli/simple-commands/hive-mind/performance-optimizer.js +618 -0
  143. package/src/cli/simple-commands/hive-mind/performance-test.js +373 -0
  144. package/src/cli/simple-commands/hive-mind/queen.js +809 -0
  145. package/src/cli/simple-commands/hive-mind/session-manager.js +1223 -0
  146. package/src/cli/simple-commands/hive-mind-optimize.js +361 -0
  147. package/src/cli/simple-commands/hive-mind-wizard.js +281 -0
  148. package/src/cli/simple-commands/hive-mind.js +3112 -0
  149. package/src/cli/simple-commands/hive.js +140 -0
  150. package/src/cli/simple-commands/hook-safety.js +671 -0
  151. package/src/cli/simple-commands/hooks.js +1268 -0
  152. package/src/cli/simple-commands/init/.claude/checkpoints/1756224542.json +7 -0
  153. package/src/cli/simple-commands/init/.claude/checkpoints/1756224544.json +8 -0
  154. package/src/cli/simple-commands/init/README.md +106 -0
  155. package/src/cli/simple-commands/init/VALIDATION_ROLLBACK.md +488 -0
  156. package/src/cli/simple-commands/init/agent-copier.js +347 -0
  157. package/src/cli/simple-commands/init/batch-init.js +663 -0
  158. package/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +438 -0
  159. package/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +876 -0
  160. package/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +356 -0
  161. package/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +501 -0
  162. package/src/cli/simple-commands/init/claude-commands/slash-commands.js +57 -0
  163. package/src/cli/simple-commands/init/claude-commands/sparc-commands.js +296 -0
  164. package/src/cli/simple-commands/init/copy-revised-templates.js +175 -0
  165. package/src/cli/simple-commands/init/executable-wrapper.js +122 -0
  166. package/src/cli/simple-commands/init/gitignore-updater.js +137 -0
  167. package/src/cli/simple-commands/init/help.js +110 -0
  168. package/src/cli/simple-commands/init/hive-mind-init.js +749 -0
  169. package/src/cli/simple-commands/init/index.js +1953 -0
  170. package/src/cli/simple-commands/init/performance-monitor.js +344 -0
  171. package/src/cli/simple-commands/init/rollback/backup-manager.js +542 -0
  172. package/src/cli/simple-commands/init/rollback/index.js +399 -0
  173. package/src/cli/simple-commands/init/rollback/recovery-manager.js +778 -0
  174. package/src/cli/simple-commands/init/rollback/rollback-executor.js +521 -0
  175. package/src/cli/simple-commands/init/rollback/state-tracker.js +486 -0
  176. package/src/cli/simple-commands/init/sparc/roo-readme.js +61 -0
  177. package/src/cli/simple-commands/init/sparc/roomodes-config.js +102 -0
  178. package/src/cli/simple-commands/init/sparc/workflows.js +40 -0
  179. package/src/cli/simple-commands/init/sparc-structure.js +68 -0
  180. package/src/cli/simple-commands/init/template-copier.js +640 -0
  181. package/src/cli/simple-commands/init/templates/CLAUDE.md +1185 -0
  182. package/src/cli/simple-commands/init/templates/CLAUDE.md.optimized +265 -0
  183. package/src/cli/simple-commands/init/templates/claude-flow-universal +81 -0
  184. package/src/cli/simple-commands/init/templates/claude-flow.bat +18 -0
  185. package/src/cli/simple-commands/init/templates/claude-flow.ps1 +24 -0
  186. package/src/cli/simple-commands/init/templates/claude-md.js +1101 -0
  187. package/src/cli/simple-commands/init/templates/commands/analysis/bottleneck-detect.md +162 -0
  188. package/src/cli/simple-commands/init/templates/commands/automation/auto-agent.md +122 -0
  189. package/src/cli/simple-commands/init/templates/commands/coordination/swarm-init.md +85 -0
  190. package/src/cli/simple-commands/init/templates/commands/github/github-swarm.md +121 -0
  191. package/src/cli/simple-commands/init/templates/commands/helpers/standard-checkpoint-hooks.sh +179 -0
  192. package/src/cli/simple-commands/init/templates/commands/hooks/notification.md +113 -0
  193. package/src/cli/simple-commands/init/templates/commands/hooks/post-command.md +116 -0
  194. package/src/cli/simple-commands/init/templates/commands/hooks/post-edit.md +117 -0
  195. package/src/cli/simple-commands/init/templates/commands/hooks/post-task.md +112 -0
  196. package/src/cli/simple-commands/init/templates/commands/hooks/pre-command.md +113 -0
  197. package/src/cli/simple-commands/init/templates/commands/hooks/pre-edit.md +113 -0
  198. package/src/cli/simple-commands/init/templates/commands/hooks/pre-search.md +112 -0
  199. package/src/cli/simple-commands/init/templates/commands/hooks/pre-task.md +111 -0
  200. package/src/cli/simple-commands/init/templates/commands/hooks/session-end.md +118 -0
  201. package/src/cli/simple-commands/init/templates/commands/hooks/session-restore.md +118 -0
  202. package/src/cli/simple-commands/init/templates/commands/hooks/session-start.md +117 -0
  203. package/src/cli/simple-commands/init/templates/coordination-md.js +340 -0
  204. package/src/cli/simple-commands/init/templates/coordination.md +16 -0
  205. package/src/cli/simple-commands/init/templates/enhanced-templates.js +2347 -0
  206. package/src/cli/simple-commands/init/templates/github-safe-enhanced.js +331 -0
  207. package/src/cli/simple-commands/init/templates/github-safe.js +106 -0
  208. package/src/cli/simple-commands/init/templates/memory-bank-md.js +259 -0
  209. package/src/cli/simple-commands/init/templates/memory-bank.md +16 -0
  210. package/src/cli/simple-commands/init/templates/readme-files.js +72 -0
  211. package/src/cli/simple-commands/init/templates/safe-hook-patterns.js +430 -0
  212. package/src/cli/simple-commands/init/templates/settings.json +109 -0
  213. package/src/cli/simple-commands/init/templates/settings.json.enhanced +35 -0
  214. package/src/cli/simple-commands/init/templates/sparc-modes.js +1401 -0
  215. package/src/cli/simple-commands/init/templates/verification-claude-md.js +432 -0
  216. package/src/cli/simple-commands/init/validation/config-validator.js +354 -0
  217. package/src/cli/simple-commands/init/validation/health-checker.js +599 -0
  218. package/src/cli/simple-commands/init/validation/index.js +388 -0
  219. package/src/cli/simple-commands/init/validation/mode-validator.js +387 -0
  220. package/src/cli/simple-commands/init/validation/post-init-validator.js +390 -0
  221. package/src/cli/simple-commands/init/validation/pre-init-validator.js +290 -0
  222. package/src/cli/simple-commands/init/validation/test-runner.js +488 -0
  223. package/src/cli/simple-commands/init.js +4 -0
  224. package/src/cli/simple-commands/mcp-health.js +163 -0
  225. package/src/cli/simple-commands/mcp-integration-layer.js +689 -0
  226. package/src/cli/simple-commands/mcp.js +420 -0
  227. package/src/cli/simple-commands/memory-consolidation.js +631 -0
  228. package/src/cli/simple-commands/memory.js +345 -0
  229. package/src/cli/simple-commands/migrate-hooks.js +63 -0
  230. package/src/cli/simple-commands/monitor.js +417 -0
  231. package/src/cli/simple-commands/neural.js +148 -0
  232. package/src/cli/simple-commands/pair-autofix-only.js +755 -0
  233. package/src/cli/simple-commands/pair-basic.js +751 -0
  234. package/src/cli/simple-commands/pair-old.js +623 -0
  235. package/src/cli/simple-commands/pair-working.js +849 -0
  236. package/src/cli/simple-commands/pair.js +849 -0
  237. package/src/cli/simple-commands/performance-hooks.js +149 -0
  238. package/src/cli/simple-commands/performance-metrics.js +601 -0
  239. package/src/cli/simple-commands/process-ui-enhanced.js +821 -0
  240. package/src/cli/simple-commands/process-ui.js +274 -0
  241. package/src/cli/simple-commands/realtime-update-system.js +659 -0
  242. package/src/cli/simple-commands/sparc/architecture.js +1750 -0
  243. package/src/cli/simple-commands/sparc/commands.js +575 -0
  244. package/src/cli/simple-commands/sparc/completion.js +1831 -0
  245. package/src/cli/simple-commands/sparc/coordinator.js +1045 -0
  246. package/src/cli/simple-commands/sparc/index.js +321 -0
  247. package/src/cli/simple-commands/sparc/phase-base.js +430 -0
  248. package/src/cli/simple-commands/sparc/pseudocode.js +984 -0
  249. package/src/cli/simple-commands/sparc/refinement.js +1856 -0
  250. package/src/cli/simple-commands/sparc/specification.js +736 -0
  251. package/src/cli/simple-commands/sparc-modes/architect.js +125 -0
  252. package/src/cli/simple-commands/sparc-modes/ask.js +126 -0
  253. package/src/cli/simple-commands/sparc-modes/code.js +148 -0
  254. package/src/cli/simple-commands/sparc-modes/debug.js +112 -0
  255. package/src/cli/simple-commands/sparc-modes/devops.js +137 -0
  256. package/src/cli/simple-commands/sparc-modes/docs-writer.js +38 -0
  257. package/src/cli/simple-commands/sparc-modes/generic.js +34 -0
  258. package/src/cli/simple-commands/sparc-modes/index.js +201 -0
  259. package/src/cli/simple-commands/sparc-modes/integration.js +55 -0
  260. package/src/cli/simple-commands/sparc-modes/mcp.js +38 -0
  261. package/src/cli/simple-commands/sparc-modes/monitoring.js +38 -0
  262. package/src/cli/simple-commands/sparc-modes/optimization.js +38 -0
  263. package/src/cli/simple-commands/sparc-modes/security-review.js +130 -0
  264. package/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +167 -0
  265. package/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +38 -0
  266. package/src/cli/simple-commands/sparc-modes/supabase-admin.js +149 -0
  267. package/src/cli/simple-commands/sparc-modes/swarm.js +436 -0
  268. package/src/cli/simple-commands/sparc-modes/tdd.js +112 -0
  269. package/src/cli/simple-commands/sparc-modes/tutorial.js +277 -0
  270. package/src/cli/simple-commands/sparc.js +530 -0
  271. package/src/cli/simple-commands/start-ui.js +147 -0
  272. package/src/cli/simple-commands/start-wrapper.js +285 -0
  273. package/src/cli/simple-commands/start.js +2 -0
  274. package/src/cli/simple-commands/status.js +303 -0
  275. package/src/cli/simple-commands/stream-chain-clean.js +221 -0
  276. package/src/cli/simple-commands/stream-chain-fixed.js +89 -0
  277. package/src/cli/simple-commands/stream-chain-real.js +408 -0
  278. package/src/cli/simple-commands/stream-chain-working.js +323 -0
  279. package/src/cli/simple-commands/stream-chain.js +491 -0
  280. package/src/cli/simple-commands/stream-processor.js +340 -0
  281. package/src/cli/simple-commands/swarm-executor.js +253 -0
  282. package/src/cli/simple-commands/swarm-metrics-integration.js +371 -0
  283. package/src/cli/simple-commands/swarm-ui.js +741 -0
  284. package/src/cli/simple-commands/swarm-webui-integration.js +311 -0
  285. package/src/cli/simple-commands/swarm.js +2277 -0
  286. package/src/cli/simple-commands/task.js +228 -0
  287. package/src/cli/simple-commands/templates/mle-star-workflow.json +294 -0
  288. package/src/cli/simple-commands/timestamp-fix.js +104 -0
  289. package/src/cli/simple-commands/token-tracker.js +372 -0
  290. package/src/cli/simple-commands/tool-execution-framework.js +555 -0
  291. package/src/cli/simple-commands/train-and-stream.js +354 -0
  292. package/src/cli/simple-commands/training-pipeline.js +874 -0
  293. package/src/cli/simple-commands/training.js +288 -0
  294. package/src/cli/simple-commands/verification-hooks.js +336 -0
  295. package/src/cli/simple-commands/verification-integration.js +464 -0
  296. package/src/cli/simple-commands/verification-training-integration.js +646 -0
  297. package/src/cli/simple-commands/verification.js +551 -0
  298. package/src/cli/simple-commands/web-server.js +929 -0
  299. package/src/cli/simple-commands/webui-validator.js +136 -0
  300. package/src/language/README.md +503 -0
  301. package/src/language/claude-md-generator.js +618 -0
  302. package/src/language/cli.js +422 -0
  303. package/src/language/example.js +347 -0
  304. package/src/language/integration-system.js +619 -0
  305. package/src/language/language-detector.js +581 -0
@@ -0,0 +1,874 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Training Pipeline with Real Task Execution
4
+ * Executes actual code and learns from real test results
5
+ */
6
+
7
+ import fs from 'fs/promises';
8
+ import path from 'path';
9
+ import { execSync, spawn } from 'child_process';
10
+ import { promisify } from 'util';
11
+ import { exec } from 'child_process';
12
+
13
+ const execAsync = promisify(exec);
14
+
15
+ /**
16
+ * Training Pipeline that executes real tasks and learns from actual results
17
+ */
18
+ export class TrainingPipeline {
19
+ constructor() {
20
+ this.pipelineConfig = '.claude-flow/pipeline-config.json';
21
+ this.trainingLog = '.claude-flow/training/pipeline-log.jsonl';
22
+ this.improvementMetrics = '.claude-flow/metrics/improvements.json';
23
+ this.agentProfiles = '.claude-flow/agents/profiles.json';
24
+ this.realTasksDir = '.claude-flow/training/real-tasks';
25
+ this.initialized = false;
26
+ }
27
+
28
+ /**
29
+ * Initialize the training pipeline
30
+ */
31
+ async initialize() {
32
+ // Create necessary directories
33
+ const dirs = [
34
+ '.claude-flow/pipeline',
35
+ '.claude-flow/training',
36
+ '.claude-flow/training/real-tasks',
37
+ '.claude-flow/metrics',
38
+ '.claude-flow/agents',
39
+ '.claude-flow/validation',
40
+ '.claude-flow/benchmarks',
41
+ ];
42
+
43
+ for (const dir of dirs) {
44
+ await fs.mkdir(dir, { recursive: true });
45
+ }
46
+
47
+ // Load or create pipeline configuration
48
+ await this.loadPipelineConfig();
49
+
50
+ console.log('šŸš€ Training Pipeline initialized');
51
+ this.initialized = true;
52
+ }
53
+
54
+ /**
55
+ * STAGE 1: Generate Training Tasks
56
+ * Creates actual code files that can be tested
57
+ */
58
+ async generateTrainingTasks(complexity = 'medium') {
59
+ const taskId = Date.now();
60
+ const taskDir = path.join(this.realTasksDir, `task-${taskId}`);
61
+ await fs.mkdir(taskDir, { recursive: true });
62
+
63
+ const tasks = {
64
+ easy: [
65
+ {
66
+ type: 'function',
67
+ name: 'validateEmail',
68
+ task: 'Create email validation function',
69
+ code: `function validateEmail(email) {
70
+ const regex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;
71
+ return regex.test(email);
72
+ }
73
+
74
+ module.exports = { validateEmail };`,
75
+ test: `
76
+ const { validateEmail } = require('./index');
77
+
78
+ describe('validateEmail', () => {
79
+ test('validates correct email', () => {
80
+ expect(validateEmail('test@example.com')).toBe(true);
81
+ });
82
+
83
+ test('rejects invalid email', () => {
84
+ expect(validateEmail('invalid')).toBe(false);
85
+ });
86
+ });
87
+ `,
88
+ },
89
+ ],
90
+ medium: [
91
+ {
92
+ type: 'api',
93
+ name: 'userApi',
94
+ task: 'Build user API endpoint',
95
+ code: `
96
+ const express = require('express');
97
+ const app = express();
98
+
99
+ app.use(express.json());
100
+
101
+ const users = [];
102
+
103
+ app.get('/users', (req, res) => {
104
+ res.json(users);
105
+ });
106
+
107
+ app.post('/users', (req, res) => {
108
+ const { name, email } = req.body;
109
+ if (!name || !email) {
110
+ return res.status(400).json({ error: 'Name and email required' });
111
+ }
112
+ const user = { id: users.length + 1, name, email };
113
+ users.push(user);
114
+ res.status(201).json(user);
115
+ });
116
+
117
+ module.exports = app;
118
+ `,
119
+ test: `
120
+ const request = require('supertest');
121
+ const app = require('./index');
122
+
123
+ describe('User API', () => {
124
+ test('GET /users returns empty array initially', async () => {
125
+ const res = await request(app).get('/users');
126
+ expect(res.status).toBe(200);
127
+ expect(res.body).toEqual([]);
128
+ });
129
+
130
+ test('POST /users creates a user', async () => {
131
+ const res = await request(app)
132
+ .post('/users')
133
+ .send({ name: 'Test', email: 'test@test.com' });
134
+ expect(res.status).toBe(201);
135
+ expect(res.body.name).toBe('Test');
136
+ });
137
+ });
138
+ `,
139
+ },
140
+ ],
141
+ hard: [
142
+ {
143
+ type: 'algorithm',
144
+ name: 'sortAlgorithm',
145
+ task: 'Implement efficient sorting',
146
+ code: `
147
+ function quickSort(arr) {
148
+ if (arr.length <= 1) return arr;
149
+
150
+ const pivot = arr[Math.floor(arr.length / 2)];
151
+ const left = arr.filter(x => x < pivot);
152
+ const middle = arr.filter(x => x === pivot);
153
+ const right = arr.filter(x => x > pivot);
154
+
155
+ return [...quickSort(left), ...middle, ...quickSort(right)];
156
+ }
157
+
158
+ function mergeSort(arr) {
159
+ if (arr.length <= 1) return arr;
160
+
161
+ const mid = Math.floor(arr.length / 2);
162
+ const left = mergeSort(arr.slice(0, mid));
163
+ const right = mergeSort(arr.slice(mid));
164
+
165
+ const result = [];
166
+ let i = 0, j = 0;
167
+
168
+ while (i < left.length && j < right.length) {
169
+ if (left[i] < right[j]) {
170
+ result.push(left[i++]);
171
+ } else {
172
+ result.push(right[j++]);
173
+ }
174
+ }
175
+
176
+ return result.concat(left.slice(i)).concat(right.slice(j));
177
+ }
178
+
179
+ module.exports = { quickSort, mergeSort };
180
+ `,
181
+ test: `
182
+ const { quickSort, mergeSort } = require('./index');
183
+
184
+ describe('Sorting Algorithms', () => {
185
+ const unsorted = [3, 1, 4, 1, 5, 9, 2, 6];
186
+ const sorted = [1, 1, 2, 3, 4, 5, 6, 9];
187
+
188
+ test('quickSort sorts correctly', () => {
189
+ expect(quickSort(unsorted)).toEqual(sorted);
190
+ });
191
+
192
+ test('mergeSort sorts correctly', () => {
193
+ expect(mergeSort(unsorted)).toEqual(sorted);
194
+ });
195
+
196
+ test('handles empty arrays', () => {
197
+ expect(quickSort([])).toEqual([]);
198
+ expect(mergeSort([])).toEqual([]);
199
+ });
200
+ });
201
+ `,
202
+ },
203
+ ],
204
+ };
205
+
206
+ const selectedTasks = tasks[complexity] || tasks.medium;
207
+ const realTasks = [];
208
+
209
+ // Create real task files
210
+ for (const task of selectedTasks) {
211
+ const projectDir = path.join(taskDir, task.name);
212
+ await fs.mkdir(projectDir, { recursive: true });
213
+
214
+ // Write actual code file
215
+ await fs.writeFile(path.join(projectDir, 'index.js'), task.code);
216
+
217
+ // Write test file
218
+ await fs.writeFile(path.join(projectDir, 'index.test.js'), task.test);
219
+
220
+ // Create package.json with real dependencies
221
+ const packageJson = {
222
+ name: task.name,
223
+ version: '1.0.0',
224
+ scripts: {
225
+ test: 'jest --silent',
226
+ lint: 'eslint index.js || true',
227
+ typecheck: "echo 'No TypeScript' || true",
228
+ },
229
+ devDependencies: {
230
+ jest: '^29.0.0',
231
+ eslint: '^8.0.0',
232
+ supertest: '^6.0.0',
233
+ },
234
+ dependencies: {
235
+ express: task.type === 'api' ? '^4.18.0' : undefined,
236
+ },
237
+ };
238
+
239
+ await fs.writeFile(
240
+ path.join(projectDir, 'package.json'),
241
+ JSON.stringify(packageJson, null, 2),
242
+ );
243
+
244
+ realTasks.push({
245
+ ...task,
246
+ projectDir,
247
+ taskId,
248
+ });
249
+ }
250
+
251
+ console.log(`šŸ“ Generated ${realTasks.length} ${complexity} training tasks`);
252
+ return realTasks;
253
+ }
254
+
255
+ /**
256
+ * STAGE 2: Execute Tasks with Different Strategies
257
+ * Actually runs npm install, tests, and measures real performance
258
+ */
259
+ async executeTrainingRun(tasks, agentConfig = {}) {
260
+ const results = [];
261
+
262
+ for (const task of tasks) {
263
+ console.log(`\nšŸ”„ Executing task: ${task.task}`);
264
+
265
+ // Install dependencies (only once per task)
266
+ try {
267
+ console.log(` šŸ“¦ Installing dependencies...`);
268
+ execSync('npm install --silent', {
269
+ cwd: task.projectDir,
270
+ stdio: 'pipe',
271
+ });
272
+ } catch (e) {
273
+ console.log(` āš ļø Install warning: ${e.message.slice(0, 50)}`);
274
+ }
275
+
276
+ // Test different strategies with REAL variations
277
+ const strategies = agentConfig.strategies || ['conservative', 'balanced', 'aggressive'];
278
+
279
+ for (const strategy of strategies) {
280
+ const result = await this.executeTaskWithStrategy(task, strategy);
281
+ results.push({
282
+ task: task.task,
283
+ type: task.type,
284
+ strategy,
285
+ ...result,
286
+ timestamp: new Date().toISOString(),
287
+ });
288
+ }
289
+ }
290
+
291
+ // Save real results
292
+ const resultsFile = `.claude-flow/training/real-results-${Date.now()}.json`;
293
+ await fs.writeFile(resultsFile, JSON.stringify(results, null, 2));
294
+
295
+ return results;
296
+ }
297
+
298
+ /**
299
+ * Execute a task with a specific strategy
300
+ * Strategies affect how we modify and test the code
301
+ */
302
+ async executeTaskWithStrategy(task, strategy) {
303
+ const startTime = Date.now();
304
+ const checks = {};
305
+
306
+ // Save original code
307
+ const originalCode = await fs.readFile(path.join(task.projectDir, 'index.js'), 'utf8');
308
+
309
+ // Modify code based on strategy (but more carefully!)
310
+ if (strategy === 'aggressive') {
311
+ // Aggressive: Skip some validation (but keep valid syntax)
312
+ const aggressiveCode = originalCode.replace(/if \(!(\w+)\)/g, 'if (false && !$1)');
313
+ await fs.writeFile(path.join(task.projectDir, 'index.js'), aggressiveCode);
314
+ } else if (strategy === 'conservative') {
315
+ // Conservative: Add validation at the top of functions
316
+ const conservativeCode = originalCode.replace(
317
+ /function (\w+)\((.*?)\) {/g,
318
+ 'function $1($2) {\n // Extra validation for conservative strategy\n if (arguments.length === 0) throw new Error("No arguments provided");',
319
+ );
320
+ await fs.writeFile(path.join(task.projectDir, 'index.js'), conservativeCode);
321
+ }
322
+ // Balanced: Keep original code
323
+
324
+ // Run REAL tests
325
+ try {
326
+ const testResult = execSync('npm test', {
327
+ cwd: task.projectDir,
328
+ encoding: 'utf8',
329
+ stdio: 'pipe',
330
+ });
331
+ checks.test = {
332
+ passed: true,
333
+ score: 1.0,
334
+ output: testResult.slice(0, 100),
335
+ };
336
+ } catch (e) {
337
+ checks.test = {
338
+ passed: false,
339
+ score: 0.3,
340
+ error: e.message.slice(0, 100),
341
+ };
342
+ }
343
+
344
+ // Run REAL lint
345
+ try {
346
+ const lintResult = execSync('npm run lint', {
347
+ cwd: task.projectDir,
348
+ encoding: 'utf8',
349
+ stdio: 'pipe',
350
+ });
351
+ const hasErrors = lintResult.includes('error');
352
+ checks.lint = {
353
+ passed: !hasErrors,
354
+ score: hasErrors ? 0.5 : 1.0,
355
+ };
356
+ } catch (e) {
357
+ checks.lint = {
358
+ passed: false,
359
+ score: 0.3,
360
+ };
361
+ }
362
+
363
+ // Restore original code after testing
364
+ await fs.writeFile(path.join(task.projectDir, 'index.js'), originalCode);
365
+
366
+ // Calculate REAL performance metrics
367
+ const executionTime = Date.now() - startTime;
368
+ const successRate =
369
+ Object.values(checks).filter((c) => c.passed).length / Object.values(checks).length;
370
+
371
+ // Strategy-specific scoring based on REAL results
372
+ let strategyBonus = 0;
373
+ if (strategy === 'aggressive' && executionTime < 1000) {
374
+ strategyBonus = 0.2; // Bonus for fast execution
375
+ } else if (strategy === 'conservative' && successRate === 1.0) {
376
+ strategyBonus = 0.3; // Bonus for perfect reliability
377
+ } else if (strategy === 'balanced' && successRate > 0.5 && executionTime < 2000) {
378
+ strategyBonus = 0.25; // Bonus for good balance
379
+ }
380
+
381
+ const score =
382
+ successRate * 60 + Math.max(0, 1 - executionTime / 5000) * 20 + strategyBonus * 20;
383
+
384
+ return {
385
+ executionTime,
386
+ successRate,
387
+ checks,
388
+ strategy,
389
+ score,
390
+ real: true, // Mark as real execution
391
+ };
392
+ }
393
+
394
+ /**
395
+ * STAGE 3: Learn from Results
396
+ * Updates profiles based on actual performance
397
+ */
398
+ async learnFromResults(results) {
399
+ console.log('\n🧠 Learning from results...');
400
+
401
+ // Load current agent profiles
402
+ let profiles = {};
403
+ try {
404
+ const data = await fs.readFile(this.agentProfiles, 'utf8');
405
+ profiles = JSON.parse(data);
406
+ } catch {
407
+ profiles = this.getDefaultProfiles();
408
+ }
409
+
410
+ // Analyze REAL results by strategy
411
+ const strategyPerformance = {};
412
+ for (const result of results) {
413
+ if (!strategyPerformance[result.strategy]) {
414
+ strategyPerformance[result.strategy] = {
415
+ totalScore: 0,
416
+ count: 0,
417
+ avgExecutionTime: 0,
418
+ successRate: 0,
419
+ realExecutions: 0,
420
+ };
421
+ }
422
+
423
+ const perf = strategyPerformance[result.strategy];
424
+ perf.totalScore += result.score;
425
+ perf.count++;
426
+ perf.avgExecutionTime += result.executionTime;
427
+ perf.successRate += result.successRate;
428
+ if (result.real) perf.realExecutions++;
429
+ }
430
+
431
+ // Calculate averages and update profiles with REAL data
432
+ for (const [strategy, perf] of Object.entries(strategyPerformance)) {
433
+ perf.avgScore = perf.totalScore / perf.count;
434
+ perf.avgExecutionTime = perf.avgExecutionTime / perf.count;
435
+ perf.successRate = perf.successRate / perf.count;
436
+
437
+ // Update with stronger learning for real executions
438
+ const learningRate = perf.realExecutions > 0 ? 0.4 : 0.1;
439
+ this.updateAgentProfile(profiles, strategy, perf, learningRate);
440
+ }
441
+
442
+ // Save updated profiles
443
+ await fs.writeFile(this.agentProfiles, JSON.stringify(profiles, null, 2));
444
+
445
+ // Generate recommendations based on performance
446
+ const recommendations = this.generateRecommendations(strategyPerformance);
447
+
448
+ console.log('\nšŸ“Š Learning Results:');
449
+ for (const [strategy, perf] of Object.entries(strategyPerformance)) {
450
+ console.log(
451
+ ` ${strategy}: Score ${perf.avgScore.toFixed(2)}, Success ${(perf.successRate * 100).toFixed(1)}%, Time ${perf.avgExecutionTime.toFixed(0)}ms`,
452
+ );
453
+ }
454
+
455
+ return { profiles, recommendations };
456
+ }
457
+
458
+ updateAgentProfile(profiles, strategy, performance, learningRate = 0.3) {
459
+ if (!profiles[strategy]) {
460
+ profiles[strategy] = {
461
+ successRate: 0.5,
462
+ avgScore: 50,
463
+ avgExecutionTime: 2000,
464
+ uses: 0,
465
+ realExecutions: 0,
466
+ };
467
+ }
468
+
469
+ const profile = profiles[strategy];
470
+
471
+ // Update with exponential moving average
472
+ profile.successRate =
473
+ profile.successRate * (1 - learningRate) + performance.successRate * learningRate;
474
+ profile.avgScore = profile.avgScore * (1 - learningRate) + performance.avgScore * learningRate;
475
+ profile.avgExecutionTime =
476
+ profile.avgExecutionTime * (1 - learningRate) + performance.avgExecutionTime * learningRate;
477
+ profile.uses++;
478
+ if (performance.realExecutions) {
479
+ profile.realExecutions = (profile.realExecutions || 0) + performance.realExecutions;
480
+ }
481
+
482
+ // Add performance trend
483
+ if (!profile.trend) profile.trend = [];
484
+ profile.trend.push({
485
+ score: performance.avgScore,
486
+ timestamp: new Date().toISOString(),
487
+ real: performance.realExecutions > 0,
488
+ });
489
+ if (profile.trend.length > 20) {
490
+ profile.trend = profile.trend.slice(-20);
491
+ }
492
+
493
+ // Mark improvement
494
+ if (profile.trend.length > 1) {
495
+ const recent =
496
+ profile.trend.slice(-5).reduce((sum, t) => sum + t.score, 0) /
497
+ Math.min(5, profile.trend.length);
498
+ const older =
499
+ profile.trend.slice(0, -5).reduce((sum, t) => sum + t.score, 0) /
500
+ Math.max(1, profile.trend.length - 5);
501
+ profile.improving = recent > older;
502
+ profile.improvementRate = (((recent - older) / older) * 100).toFixed(1);
503
+ }
504
+ }
505
+
506
+ generateRecommendations(strategyPerformance) {
507
+ const recommendations = [];
508
+
509
+ for (const [strategy, perf] of Object.entries(strategyPerformance)) {
510
+ if (perf.successRate < 0.7) {
511
+ recommendations.push({
512
+ type: 'improve_reliability',
513
+ strategy,
514
+ action: `${strategy} needs better error handling (${(perf.successRate * 100).toFixed(1)}% success)`,
515
+ priority: 'high',
516
+ });
517
+ }
518
+
519
+ if (perf.avgExecutionTime > 3000) {
520
+ recommendations.push({
521
+ type: 'optimize_speed',
522
+ strategy,
523
+ action: `${strategy} is too slow (${perf.avgExecutionTime.toFixed(0)}ms avg)`,
524
+ priority: 'medium',
525
+ });
526
+ }
527
+
528
+ if (perf.avgScore > 75) {
529
+ recommendations.push({
530
+ type: 'good_performance',
531
+ strategy,
532
+ action: `${strategy} performing well (${perf.avgScore.toFixed(1)} score)`,
533
+ priority: 'info',
534
+ });
535
+ }
536
+ }
537
+
538
+ return recommendations;
539
+ }
540
+
541
+ /**
542
+ * Full Training Pipeline Execution
543
+ */
544
+ async runFullPipeline(options = {}) {
545
+ const { complexity = 'medium', iterations = 3, validate = true } = options;
546
+
547
+ console.log('šŸŽÆ Starting Training Pipeline');
548
+ console.log('━'.repeat(50));
549
+
550
+ await this.initialize();
551
+
552
+ // Capture baseline metrics
553
+ const baselineMetrics = await this.captureMetrics();
554
+
555
+ let cumulativeResults = [];
556
+
557
+ for (let i = 1; i <= iterations; i++) {
558
+ console.log(`\nšŸ“ Iteration ${i}/${iterations}`);
559
+ console.log('─'.repeat(40));
560
+
561
+ // Stage 1: Generate tasks
562
+ const tasks = await this.generateTrainingTasks(complexity);
563
+
564
+ // Stage 2: Execute with real code
565
+ const results = await this.executeTrainingRun(tasks);
566
+ cumulativeResults = [...cumulativeResults, ...results];
567
+
568
+ // Stage 3: Learn from results
569
+ const { profiles, recommendations } = await this.learnFromResults(results);
570
+
571
+ // Show recommendations
572
+ if (recommendations.length > 0) {
573
+ console.log('\nšŸ’” Recommendations:');
574
+ for (const rec of recommendations.slice(0, 3)) {
575
+ console.log(` • ${rec.action}`);
576
+ }
577
+ }
578
+
579
+ // Stage 4: Validate if enabled
580
+ if (validate && i === iterations) {
581
+ const currentMetrics = await this.captureMetrics();
582
+ const validation = await this.validateImprovements(baselineMetrics, currentMetrics);
583
+
584
+ if (validation.summary.overallImprovement) {
585
+ console.log('āœ… Improvement detected!');
586
+ } else {
587
+ console.log('āš ļø More training needed for significant improvement');
588
+ }
589
+ }
590
+ }
591
+
592
+ // Generate final report
593
+ const report = await this.generateFinalReport(cumulativeResults);
594
+ console.log('\n' + report);
595
+
596
+ return {
597
+ success: true,
598
+ totalTasks: cumulativeResults.length,
599
+ realExecutions: cumulativeResults.filter((r) => r.real).length,
600
+ improvements: await this.calculateOverallImprovement(baselineMetrics),
601
+ };
602
+ }
603
+
604
+ // Reuse helper methods from original
605
+ async captureMetrics() {
606
+ try {
607
+ const data = await fs.readFile(this.agentProfiles, 'utf8');
608
+ const profiles = JSON.parse(data);
609
+
610
+ // Calculate weighted average from all strategies
611
+ let totalScore = 0;
612
+ let totalSuccess = 0;
613
+ let totalTime = 0;
614
+ let count = 0;
615
+
616
+ for (const profile of Object.values(profiles)) {
617
+ if (profile.uses > 0) {
618
+ totalScore += profile.avgScore;
619
+ totalSuccess += profile.successRate;
620
+ totalTime += profile.avgExecutionTime;
621
+ count++;
622
+ }
623
+ }
624
+
625
+ return {
626
+ successRate: count > 0 ? totalSuccess / count : 0,
627
+ executionTime: count > 0 ? totalTime / count : 0,
628
+ score: count > 0 ? totalScore / count : 0,
629
+ };
630
+ } catch {
631
+ return {
632
+ successRate: 0,
633
+ executionTime: 0,
634
+ score: 0,
635
+ };
636
+ }
637
+ }
638
+
639
+ async validateImprovements(beforeMetrics, afterMetrics) {
640
+ const validation = {
641
+ improved: [],
642
+ declined: [],
643
+ unchanged: [],
644
+ summary: {},
645
+ };
646
+
647
+ const metrics = ['successRate', 'executionTime', 'score'];
648
+
649
+ for (const metric of metrics) {
650
+ const before = beforeMetrics[metric] || 0.01; // Avoid division by zero
651
+ const after = afterMetrics[metric] || 0;
652
+ const change = after - before;
653
+ const percentChange = (change / before) * 100;
654
+
655
+ if (percentChange > 5) {
656
+ validation.improved.push({ metric, change: percentChange });
657
+ } else if (percentChange < -5) {
658
+ validation.declined.push({ metric, change: percentChange });
659
+ } else {
660
+ validation.unchanged.push({ metric, change: percentChange });
661
+ }
662
+ }
663
+
664
+ validation.summary = {
665
+ overallImprovement: validation.improved.length > validation.declined.length,
666
+ improvementScore: validation.improved.length - validation.declined.length,
667
+ timestamp: new Date().toISOString(),
668
+ };
669
+
670
+ console.log(`\nāœ… Validating improvements...`);
671
+ console.log(` Improved: ${validation.improved.length} metrics`);
672
+ console.log(` Declined: ${validation.declined.length} metrics`);
673
+ console.log(` Unchanged: ${validation.unchanged.length} metrics`);
674
+
675
+ return validation;
676
+ }
677
+
678
+ async calculateOverallImprovement(baselineMetrics) {
679
+ const currentMetrics = await this.captureMetrics();
680
+
681
+ const base = {
682
+ successRate: baselineMetrics.successRate || 0.01,
683
+ executionTime: baselineMetrics.executionTime || 1,
684
+ score: baselineMetrics.score || 0.01,
685
+ };
686
+
687
+ return {
688
+ successRate: ((currentMetrics.successRate - base.successRate) / base.successRate) * 100,
689
+ executionTime:
690
+ ((base.executionTime - currentMetrics.executionTime) / base.executionTime) * 100,
691
+ score: ((currentMetrics.score - base.score) / base.score) * 100,
692
+ };
693
+ }
694
+
695
+ async generateFinalReport(results) {
696
+ const realResults = results.filter((r) => r.real);
697
+ const successRates = {};
698
+ const scores = {};
699
+ const times = {};
700
+
701
+ for (const result of realResults) {
702
+ if (!successRates[result.strategy]) {
703
+ successRates[result.strategy] = [];
704
+ scores[result.strategy] = [];
705
+ times[result.strategy] = [];
706
+ }
707
+ successRates[result.strategy].push(result.successRate);
708
+ scores[result.strategy].push(result.score);
709
+ times[result.strategy].push(result.executionTime);
710
+ }
711
+
712
+ let report = 'šŸ“Š Training Pipeline Report\n';
713
+ report += '━'.repeat(50) + '\n\n';
714
+
715
+ for (const strategy of Object.keys(successRates)) {
716
+ const avgSuccess =
717
+ successRates[strategy].reduce((a, b) => a + b, 0) / successRates[strategy].length;
718
+ const avgScore = scores[strategy].reduce((a, b) => a + b, 0) / scores[strategy].length;
719
+ const avgTime = times[strategy].reduce((a, b) => a + b, 0) / times[strategy].length;
720
+
721
+ report += `Strategy: ${strategy}\n`;
722
+ report += ` Average Success Rate: ${(avgSuccess * 100).toFixed(1)}%\n`;
723
+ report += ` Average Score: ${avgScore.toFixed(2)}\n`;
724
+ report += ` Average Time: ${avgTime.toFixed(0)}ms\n`;
725
+ report += ` Real Executions: ${successRates[strategy].length}\n`;
726
+ report += '\n';
727
+ }
728
+
729
+ return report;
730
+ }
731
+
732
+ getDefaultProfiles() {
733
+ return {
734
+ conservative: {
735
+ successRate: 0.5,
736
+ avgScore: 50,
737
+ avgExecutionTime: 3000,
738
+ uses: 0,
739
+ realExecutions: 0,
740
+ },
741
+ balanced: {
742
+ successRate: 0.5,
743
+ avgScore: 50,
744
+ avgExecutionTime: 2000,
745
+ uses: 0,
746
+ realExecutions: 0,
747
+ },
748
+ aggressive: {
749
+ successRate: 0.5,
750
+ avgScore: 50,
751
+ avgExecutionTime: 1000,
752
+ uses: 0,
753
+ realExecutions: 0,
754
+ },
755
+ };
756
+ }
757
+
758
+ async loadPipelineConfig() {
759
+ try {
760
+ const data = await fs.readFile(this.pipelineConfig, 'utf8');
761
+ return JSON.parse(data);
762
+ } catch {
763
+ const defaultConfig = {
764
+ version: '2.0.0',
765
+ strategies: ['conservative', 'balanced', 'aggressive'],
766
+ learningRate: 0.4,
767
+ minSamplesForUpdate: 3,
768
+ useRealExecution: true,
769
+ created: new Date().toISOString(),
770
+ };
771
+
772
+ await fs.writeFile(this.pipelineConfig, JSON.stringify(defaultConfig, null, 2));
773
+ return defaultConfig;
774
+ }
775
+ }
776
+ }
777
+
778
+ /**
779
+ * CLI Command Handler
780
+ */
781
+ export async function trainingPipelineCommand(args, flags) {
782
+ const pipeline = new TrainingPipeline();
783
+ const subcommand = args[0] || 'run';
784
+
785
+ switch (subcommand) {
786
+ case 'run':
787
+ // Run real pipeline
788
+ const options = {
789
+ complexity: flags.complexity || 'medium',
790
+ iterations: parseInt(flags.iterations) || 3,
791
+ validate: flags.validate !== false,
792
+ };
793
+
794
+ console.log('šŸš€ Starting Training Pipeline');
795
+ console.log(` Complexity: ${options.complexity}`);
796
+ console.log(` Iterations: ${options.iterations}`);
797
+ console.log(` Validation: ${options.validate ? 'Enabled' : 'Disabled'}`);
798
+
799
+ const result = await pipeline.runFullPipeline(options);
800
+
801
+ if (result.success) {
802
+ console.log('\nāœ… Training Pipeline completed');
803
+ console.log(` Total tasks: ${result.totalTasks}`);
804
+ console.log(` Real executions: ${result.realExecutions}`);
805
+
806
+ if (result.improvements) {
807
+ console.log('\nšŸ“ˆ Improvements:');
808
+ console.log(
809
+ ` Success Rate: ${result.improvements.successRate > 0 ? '+' : ''}${result.improvements.successRate.toFixed(1)}%`,
810
+ );
811
+ console.log(
812
+ ` Execution Time: ${result.improvements.executionTime > 0 ? '+' : ''}${result.improvements.executionTime.toFixed(1)}%`,
813
+ );
814
+ console.log(
815
+ ` Score: ${result.improvements.score > 0 ? '+' : ''}${result.improvements.score.toFixed(1)}%`,
816
+ );
817
+ }
818
+ }
819
+ break;
820
+
821
+ case 'status':
822
+ // Show real pipeline status
823
+ await pipeline.initialize();
824
+
825
+ let profiles = {};
826
+ try {
827
+ const data = await fs.readFile(pipeline.agentProfiles, 'utf8');
828
+ profiles = JSON.parse(data);
829
+ } catch {
830
+ profiles = pipeline.getDefaultProfiles();
831
+ }
832
+
833
+ console.log('\nšŸ“Š Training Pipeline Status');
834
+ console.log('━'.repeat(50));
835
+
836
+ console.log('\nšŸ¤– Strategy Profiles:');
837
+ for (const [strategy, profile] of Object.entries(profiles)) {
838
+ console.log(` ${strategy}:`);
839
+ console.log(` Success Rate: ${(profile.successRate * 100).toFixed(1)}%`);
840
+ console.log(` Average Score: ${profile.avgScore.toFixed(2)}`);
841
+ console.log(` Execution Time: ${profile.avgExecutionTime.toFixed(0)}ms`);
842
+ console.log(` Total Uses: ${profile.uses}`);
843
+ console.log(` Real Executions: ${profile.realExecutions || 0}`);
844
+ if (profile.improving !== undefined) {
845
+ console.log(
846
+ ` Trend: ${profile.improving ? 'šŸ“ˆ Improving' : 'šŸ“‰ Declining'} (${profile.improvementRate}%)`,
847
+ );
848
+ }
849
+ }
850
+ break;
851
+
852
+ case 'validate':
853
+ // Validate current performance
854
+ await pipeline.initialize();
855
+ const metrics = await pipeline.captureMetrics();
856
+ console.log('\nšŸ“Š Current Performance:');
857
+ console.log(` Success Rate: ${(metrics.successRate * 100).toFixed(1)}%`);
858
+ console.log(` Avg Execution Time: ${metrics.executionTime.toFixed(0)}ms`);
859
+ console.log(` Average Score: ${metrics.score.toFixed(2)}`);
860
+ break;
861
+
862
+ default:
863
+ console.log('Usage: train-pipeline <command> [options]');
864
+ console.log('\nCommands:');
865
+ console.log(' run - Run training pipeline with real code');
866
+ console.log(' status - Show pipeline status');
867
+ console.log(' validate - Check current performance');
868
+ console.log('\nOptions:');
869
+ console.log(' --complexity <level> - easy/medium/hard');
870
+ console.log(' --iterations <n> - Training cycles');
871
+ }
872
+ }
873
+
874
+ export default TrainingPipeline;