@claude-flow/cli 3.32.1 → 3.32.3

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 (657) hide show
  1. package/.claude/helpers/.helpers-version +1 -1
  2. package/.claude/helpers/helpers.manifest.json +3 -3
  3. package/.claude/helpers/statusline.cjs +24 -17
  4. package/.claude/helpers/statusline.js +19 -31
  5. package/catalog-manifest.json +2 -2
  6. package/package.json +1 -1
  7. package/plugins/ruflo-metaharness/.claude-plugin/plugin.json +1 -1
  8. package/plugins/ruflo-metaharness/scripts/smoke.sh +8 -5
  9. package/plugins/ruflo-metaharness/skills/harness-similarity/SKILL.md +1 -1
  10. package/dist/src/agenticow/speculative-exploration.d.ts +0 -148
  11. package/dist/src/agenticow/speculative-exploration.js +0 -218
  12. package/dist/src/appliance/gguf-engine.d.ts +0 -91
  13. package/dist/src/appliance/gguf-engine.js +0 -425
  14. package/dist/src/appliance/ruvllm-bridge.d.ts +0 -102
  15. package/dist/src/appliance/ruvllm-bridge.js +0 -292
  16. package/dist/src/appliance/rvfa-builder.d.ts +0 -44
  17. package/dist/src/appliance/rvfa-builder.js +0 -329
  18. package/dist/src/appliance/rvfa-distribution.d.ts +0 -97
  19. package/dist/src/appliance/rvfa-distribution.js +0 -370
  20. package/dist/src/appliance/rvfa-format.d.ts +0 -111
  21. package/dist/src/appliance/rvfa-format.js +0 -393
  22. package/dist/src/appliance/rvfa-runner.d.ts +0 -69
  23. package/dist/src/appliance/rvfa-runner.js +0 -237
  24. package/dist/src/appliance/rvfa-signing.d.ts +0 -123
  25. package/dist/src/appliance/rvfa-signing.js +0 -347
  26. package/dist/src/autopilot-state.d.ts +0 -77
  27. package/dist/src/autopilot-state.js +0 -271
  28. package/dist/src/benchmarks/gaia-agent-planning.smoke.d.ts +0 -18
  29. package/dist/src/benchmarks/gaia-agent-planning.smoke.js +0 -253
  30. package/dist/src/benchmarks/gaia-agent.d.ts +0 -198
  31. package/dist/src/benchmarks/gaia-agent.js +0 -651
  32. package/dist/src/benchmarks/gaia-causal-memory.d.ts +0 -133
  33. package/dist/src/benchmarks/gaia-causal-memory.js +0 -281
  34. package/dist/src/benchmarks/gaia-causal-memory.smoke.d.ts +0 -22
  35. package/dist/src/benchmarks/gaia-causal-memory.smoke.js +0 -300
  36. package/dist/src/benchmarks/gaia-convergence.d.ts +0 -138
  37. package/dist/src/benchmarks/gaia-convergence.js +0 -260
  38. package/dist/src/benchmarks/gaia-convergence.smoke.d.ts +0 -19
  39. package/dist/src/benchmarks/gaia-convergence.smoke.js +0 -246
  40. package/dist/src/benchmarks/gaia-critic.d.ts +0 -123
  41. package/dist/src/benchmarks/gaia-critic.js +0 -312
  42. package/dist/src/benchmarks/gaia-critic.smoke.d.ts +0 -21
  43. package/dist/src/benchmarks/gaia-critic.smoke.js +0 -327
  44. package/dist/src/benchmarks/gaia-decomposer.d.ts +0 -125
  45. package/dist/src/benchmarks/gaia-decomposer.js +0 -350
  46. package/dist/src/benchmarks/gaia-decomposer.smoke.d.ts +0 -21
  47. package/dist/src/benchmarks/gaia-decomposer.smoke.js +0 -228
  48. package/dist/src/benchmarks/gaia-e2e-smoke.d.ts +0 -27
  49. package/dist/src/benchmarks/gaia-e2e-smoke.js +0 -136
  50. package/dist/src/benchmarks/gaia-extract.smoke.d.ts +0 -45
  51. package/dist/src/benchmarks/gaia-extract.smoke.js +0 -242
  52. package/dist/src/benchmarks/gaia-hardness/features.d.ts +0 -46
  53. package/dist/src/benchmarks/gaia-hardness/features.js +0 -170
  54. package/dist/src/benchmarks/gaia-hardness/predictor.d.ts +0 -105
  55. package/dist/src/benchmarks/gaia-hardness/predictor.js +0 -260
  56. package/dist/src/benchmarks/gaia-hardness/predictor.smoke.d.ts +0 -20
  57. package/dist/src/benchmarks/gaia-hardness/predictor.smoke.js +0 -235
  58. package/dist/src/benchmarks/gaia-hardness/train-data-loader.d.ts +0 -51
  59. package/dist/src/benchmarks/gaia-hardness/train-data-loader.js +0 -179
  60. package/dist/src/benchmarks/gaia-judge.d.ts +0 -88
  61. package/dist/src/benchmarks/gaia-judge.js +0 -437
  62. package/dist/src/benchmarks/gaia-loader.d.ts +0 -87
  63. package/dist/src/benchmarks/gaia-loader.js +0 -326
  64. package/dist/src/benchmarks/gaia-tools/file_read.d.ts +0 -35
  65. package/dist/src/benchmarks/gaia-tools/file_read.js +0 -403
  66. package/dist/src/benchmarks/gaia-tools/grounded_query.d.ts +0 -126
  67. package/dist/src/benchmarks/gaia-tools/grounded_query.js +0 -225
  68. package/dist/src/benchmarks/gaia-tools/index.d.ts +0 -32
  69. package/dist/src/benchmarks/gaia-tools/index.js +0 -36
  70. package/dist/src/benchmarks/gaia-tools/types.d.ts +0 -62
  71. package/dist/src/benchmarks/gaia-tools/types.js +0 -12
  72. package/dist/src/benchmarks/gaia-tools/web_search.d.ts +0 -30
  73. package/dist/src/benchmarks/gaia-tools/web_search.js +0 -210
  74. package/dist/src/benchmarks/gaia-voting.d.ts +0 -88
  75. package/dist/src/benchmarks/gaia-voting.js +0 -297
  76. package/dist/src/benchmarks/gaia-voting.smoke.d.ts +0 -20
  77. package/dist/src/benchmarks/gaia-voting.smoke.js +0 -332
  78. package/dist/src/benchmarks/pretrain/index.d.ts +0 -58
  79. package/dist/src/benchmarks/pretrain/index.js +0 -404
  80. package/dist/src/business-pods/bbs-budget-tracker.d.ts +0 -139
  81. package/dist/src/business-pods/bbs-budget-tracker.js +0 -358
  82. package/dist/src/business-pods/domain-affinity-policy.d.ts +0 -47
  83. package/dist/src/business-pods/domain-affinity-policy.js +0 -65
  84. package/dist/src/business-pods/pod-schema.d.ts +0 -96
  85. package/dist/src/business-pods/pod-schema.js +0 -225
  86. package/dist/src/commands/advisor.d.ts +0 -15
  87. package/dist/src/commands/advisor.js +0 -94
  88. package/dist/src/commands/agent-wasm.d.ts +0 -14
  89. package/dist/src/commands/agent-wasm.js +0 -333
  90. package/dist/src/commands/agent.d.ts +0 -8
  91. package/dist/src/commands/agent.js +0 -927
  92. package/dist/src/commands/analyze.d.ts +0 -19
  93. package/dist/src/commands/analyze.js +0 -2047
  94. package/dist/src/commands/announcements.d.ts +0 -17
  95. package/dist/src/commands/announcements.js +0 -0
  96. package/dist/src/commands/appliance-advanced.d.ts +0 -9
  97. package/dist/src/commands/appliance-advanced.js +0 -215
  98. package/dist/src/commands/appliance.d.ts +0 -8
  99. package/dist/src/commands/appliance.js +0 -404
  100. package/dist/src/commands/autopilot.d.ts +0 -15
  101. package/dist/src/commands/autopilot.js +0 -407
  102. package/dist/src/commands/benchmark.d.ts +0 -10
  103. package/dist/src/commands/benchmark.js +0 -460
  104. package/dist/src/commands/claims.d.ts +0 -10
  105. package/dist/src/commands/claims.js +0 -620
  106. package/dist/src/commands/cleanup.d.ts +0 -13
  107. package/dist/src/commands/cleanup.js +0 -250
  108. package/dist/src/commands/completions.d.ts +0 -10
  109. package/dist/src/commands/completions.js +0 -539
  110. package/dist/src/commands/config.d.ts +0 -8
  111. package/dist/src/commands/config.js +0 -428
  112. package/dist/src/commands/daemon.d.ts +0 -59
  113. package/dist/src/commands/daemon.js +0 -1733
  114. package/dist/src/commands/deployment.d.ts +0 -10
  115. package/dist/src/commands/deployment.js +0 -672
  116. package/dist/src/commands/doctor.d.ts +0 -10
  117. package/dist/src/commands/doctor.js +0 -1695
  118. package/dist/src/commands/eject.d.ts +0 -33
  119. package/dist/src/commands/eject.js +0 -195
  120. package/dist/src/commands/embeddings.d.ts +0 -18
  121. package/dist/src/commands/embeddings.js +0 -1623
  122. package/dist/src/commands/funnel.d.ts +0 -18
  123. package/dist/src/commands/funnel.js +0 -302
  124. package/dist/src/commands/gaia-bench.d.ts +0 -40
  125. package/dist/src/commands/gaia-bench.js +0 -597
  126. package/dist/src/commands/guidance.d.ts +0 -8
  127. package/dist/src/commands/guidance.js +0 -556
  128. package/dist/src/commands/hive-mind.d.ts +0 -11
  129. package/dist/src/commands/hive-mind.js +0 -1319
  130. package/dist/src/commands/hooks.d.ts +0 -8
  131. package/dist/src/commands/hooks.js +0 -4595
  132. package/dist/src/commands/index.d.ts +0 -118
  133. package/dist/src/commands/index.js +0 -364
  134. package/dist/src/commands/init.d.ts +0 -13
  135. package/dist/src/commands/init.js +0 -1297
  136. package/dist/src/commands/issues.d.ts +0 -21
  137. package/dist/src/commands/issues.js +0 -567
  138. package/dist/src/commands/mcp.d.ts +0 -11
  139. package/dist/src/commands/mcp.js +0 -732
  140. package/dist/src/commands/memory-backup.d.ts +0 -11
  141. package/dist/src/commands/memory-backup.js +0 -46
  142. package/dist/src/commands/memory-distill.d.ts +0 -27
  143. package/dist/src/commands/memory-distill.js +0 -374
  144. package/dist/src/commands/memory.d.ts +0 -8
  145. package/dist/src/commands/memory.js +0 -1596
  146. package/dist/src/commands/metaharness.d.ts +0 -39
  147. package/dist/src/commands/metaharness.js +0 -215
  148. package/dist/src/commands/migrate.d.ts +0 -8
  149. package/dist/src/commands/migrate.js +0 -742
  150. package/dist/src/commands/neural.d.ts +0 -10
  151. package/dist/src/commands/neural.js +0 -4331
  152. package/dist/src/commands/performance.d.ts +0 -10
  153. package/dist/src/commands/performance.js +0 -583
  154. package/dist/src/commands/plugins.d.ts +0 -11
  155. package/dist/src/commands/plugins.js +0 -826
  156. package/dist/src/commands/process.d.ts +0 -10
  157. package/dist/src/commands/process.js +0 -694
  158. package/dist/src/commands/progress.d.ts +0 -11
  159. package/dist/src/commands/progress.js +0 -259
  160. package/dist/src/commands/providers.d.ts +0 -10
  161. package/dist/src/commands/providers.js +0 -502
  162. package/dist/src/commands/proxy.d.ts +0 -21
  163. package/dist/src/commands/proxy.js +0 -310
  164. package/dist/src/commands/route.d.ts +0 -16
  165. package/dist/src/commands/route.js +0 -822
  166. package/dist/src/commands/ruvector/backup.d.ts +0 -11
  167. package/dist/src/commands/ruvector/backup.js +0 -747
  168. package/dist/src/commands/ruvector/benchmark.d.ts +0 -11
  169. package/dist/src/commands/ruvector/benchmark.js +0 -490
  170. package/dist/src/commands/ruvector/import.d.ts +0 -18
  171. package/dist/src/commands/ruvector/import.js +0 -373
  172. package/dist/src/commands/ruvector/index.d.ts +0 -29
  173. package/dist/src/commands/ruvector/index.js +0 -129
  174. package/dist/src/commands/ruvector/init.d.ts +0 -11
  175. package/dist/src/commands/ruvector/init.js +0 -467
  176. package/dist/src/commands/ruvector/migrate.d.ts +0 -11
  177. package/dist/src/commands/ruvector/migrate.js +0 -498
  178. package/dist/src/commands/ruvector/optimize.d.ts +0 -11
  179. package/dist/src/commands/ruvector/optimize.js +0 -505
  180. package/dist/src/commands/ruvector/pg-utils.d.ts +0 -14
  181. package/dist/src/commands/ruvector/pg-utils.js +0 -41
  182. package/dist/src/commands/ruvector/setup.d.ts +0 -18
  183. package/dist/src/commands/ruvector/setup.js +0 -765
  184. package/dist/src/commands/ruvector/status.d.ts +0 -11
  185. package/dist/src/commands/ruvector/status.js +0 -479
  186. package/dist/src/commands/security.d.ts +0 -10
  187. package/dist/src/commands/security.js +0 -1007
  188. package/dist/src/commands/session.d.ts +0 -8
  189. package/dist/src/commands/session.js +0 -757
  190. package/dist/src/commands/settings.d.ts +0 -19
  191. package/dist/src/commands/settings.js +0 -180
  192. package/dist/src/commands/spinner.d.ts +0 -16
  193. package/dist/src/commands/spinner.js +0 -329
  194. package/dist/src/commands/start.d.ts +0 -8
  195. package/dist/src/commands/start.js +0 -418
  196. package/dist/src/commands/status.d.ts +0 -8
  197. package/dist/src/commands/status.js +0 -608
  198. package/dist/src/commands/swarm.d.ts +0 -8
  199. package/dist/src/commands/swarm.js +0 -891
  200. package/dist/src/commands/task.d.ts +0 -8
  201. package/dist/src/commands/task.js +0 -675
  202. package/dist/src/commands/transfer-store.d.ts +0 -13
  203. package/dist/src/commands/transfer-store.js +0 -428
  204. package/dist/src/commands/update.d.ts +0 -8
  205. package/dist/src/commands/update.js +0 -276
  206. package/dist/src/commands/verify.d.ts +0 -19
  207. package/dist/src/commands/verify.js +0 -261
  208. package/dist/src/commands/version.d.ts +0 -42
  209. package/dist/src/commands/version.js +0 -106
  210. package/dist/src/commands/workflow.d.ts +0 -8
  211. package/dist/src/commands/workflow.js +0 -617
  212. package/dist/src/config/harness-feedback-applier.d.ts +0 -50
  213. package/dist/src/config/harness-feedback-applier.js +0 -122
  214. package/dist/src/config/proven-config-refresh.d.ts +0 -39
  215. package/dist/src/config/proven-config-refresh.js +0 -154
  216. package/dist/src/config/proven-config-rvfa.d.ts +0 -23
  217. package/dist/src/config/proven-config-rvfa.js +0 -73
  218. package/dist/src/config/proven-config.d.ts +0 -86
  219. package/dist/src/config/proven-config.js +0 -176
  220. package/dist/src/config-adapter.d.ts +0 -15
  221. package/dist/src/config-adapter.js +0 -186
  222. package/dist/src/encryption/vault.d.ts +0 -94
  223. package/dist/src/encryption/vault.js +0 -172
  224. package/dist/src/fs-secure.d.ts +0 -86
  225. package/dist/src/fs-secure.js +0 -133
  226. package/dist/src/funnel/advisor-tip.d.ts +0 -58
  227. package/dist/src/funnel/advisor-tip.js +0 -92
  228. package/dist/src/funnel/attribution.d.ts +0 -37
  229. package/dist/src/funnel/attribution.js +0 -101
  230. package/dist/src/funnel/consent.d.ts +0 -22
  231. package/dist/src/funnel/consent.js +0 -58
  232. package/dist/src/funnel/credit-errors.d.ts +0 -31
  233. package/dist/src/funnel/credit-errors.js +0 -88
  234. package/dist/src/funnel/credit-notifier.d.ts +0 -44
  235. package/dist/src/funnel/credit-notifier.js +0 -74
  236. package/dist/src/funnel/disclosure.d.ts +0 -47
  237. package/dist/src/funnel/disclosure.js +0 -109
  238. package/dist/src/funnel/enrollment.d.ts +0 -36
  239. package/dist/src/funnel/enrollment.js +0 -64
  240. package/dist/src/funnel/environment.d.ts +0 -17
  241. package/dist/src/funnel/environment.js +0 -39
  242. package/dist/src/funnel/event-transport.d.ts +0 -51
  243. package/dist/src/funnel/event-transport.js +0 -199
  244. package/dist/src/funnel/events.d.ts +0 -42
  245. package/dist/src/funnel/events.js +0 -150
  246. package/dist/src/funnel/index.d.ts +0 -21
  247. package/dist/src/funnel/index.js +0 -21
  248. package/dist/src/funnel/insights.d.ts +0 -49
  249. package/dist/src/funnel/insights.js +0 -120
  250. package/dist/src/funnel/local-signals.d.ts +0 -15
  251. package/dist/src/funnel/local-signals.js +0 -68
  252. package/dist/src/funnel/message-transport.d.ts +0 -51
  253. package/dist/src/funnel/message-transport.js +0 -149
  254. package/dist/src/funnel/messages.d.ts +0 -55
  255. package/dist/src/funnel/messages.js +0 -160
  256. package/dist/src/funnel/payout.d.ts +0 -40
  257. package/dist/src/funnel/payout.js +0 -60
  258. package/dist/src/funnel/power-saver-notifier.d.ts +0 -44
  259. package/dist/src/funnel/power-saver-notifier.js +0 -92
  260. package/dist/src/funnel/precedence.d.ts +0 -16
  261. package/dist/src/funnel/precedence.js +0 -85
  262. package/dist/src/funnel/promo.d.ts +0 -41
  263. package/dist/src/funnel/promo.js +0 -144
  264. package/dist/src/funnel/rate-limit-notifier.d.ts +0 -55
  265. package/dist/src/funnel/rate-limit-notifier.js +0 -102
  266. package/dist/src/funnel/rotation.d.ts +0 -19
  267. package/dist/src/funnel/rotation.js +0 -70
  268. package/dist/src/funnel/state.d.ts +0 -13
  269. package/dist/src/funnel/state.js +0 -52
  270. package/dist/src/funnel/toggle-cooldown.d.ts +0 -17
  271. package/dist/src/funnel/toggle-cooldown.js +0 -32
  272. package/dist/src/funnel/types.d.ts +0 -98
  273. package/dist/src/funnel/types.js +0 -26
  274. package/dist/src/index.d.ts +0 -81
  275. package/dist/src/index.js +0 -609
  276. package/dist/src/infrastructure/in-memory-repositories.d.ts +0 -68
  277. package/dist/src/infrastructure/in-memory-repositories.js +0 -264
  278. package/dist/src/init/claudemd-generator.d.ts +0 -16
  279. package/dist/src/init/claudemd-generator.js +0 -368
  280. package/dist/src/init/executor.d.ts +0 -41
  281. package/dist/src/init/executor.js +0 -2142
  282. package/dist/src/init/helper-refresh.d.ts +0 -79
  283. package/dist/src/init/helper-refresh.js +0 -347
  284. package/dist/src/init/helper-signing.d.ts +0 -37
  285. package/dist/src/init/helper-signing.js +0 -67
  286. package/dist/src/init/helpers-generator.d.ts +0 -87
  287. package/dist/src/init/helpers-generator.js +0 -1456
  288. package/dist/src/init/index.d.ts +0 -13
  289. package/dist/src/init/index.js +0 -15
  290. package/dist/src/init/mcp-generator.d.ts +0 -26
  291. package/dist/src/init/mcp-generator.js +0 -126
  292. package/dist/src/init/memory-package-resolver.d.ts +0 -53
  293. package/dist/src/init/memory-package-resolver.js +0 -118
  294. package/dist/src/init/settings-generator.d.ts +0 -14
  295. package/dist/src/init/settings-generator.js +0 -462
  296. package/dist/src/init/statusline-generator.d.ts +0 -28
  297. package/dist/src/init/statusline-generator.js +0 -177
  298. package/dist/src/init/types.d.ts +0 -331
  299. package/dist/src/init/types.js +0 -276
  300. package/dist/src/log-filters.d.ts +0 -46
  301. package/dist/src/log-filters.js +0 -107
  302. package/dist/src/mcp-client.d.ts +0 -92
  303. package/dist/src/mcp-client.js +0 -397
  304. package/dist/src/mcp-server.d.ts +0 -163
  305. package/dist/src/mcp-server.js +0 -751
  306. package/dist/src/mcp-tools/agent-execute-core.d.ts +0 -115
  307. package/dist/src/mcp-tools/agent-execute-core.js +0 -587
  308. package/dist/src/mcp-tools/agent-tools.d.ts +0 -9
  309. package/dist/src/mcp-tools/agent-tools.js +0 -837
  310. package/dist/src/mcp-tools/agentbbs-tools.d.ts +0 -28
  311. package/dist/src/mcp-tools/agentbbs-tools.js +0 -394
  312. package/dist/src/mcp-tools/agentdb-tools.d.ts +0 -35
  313. package/dist/src/mcp-tools/agentdb-tools.js +0 -1473
  314. package/dist/src/mcp-tools/agenticow-loader.d.ts +0 -59
  315. package/dist/src/mcp-tools/agenticow-loader.js +0 -105
  316. package/dist/src/mcp-tools/agenticow-speculate-tools.d.ts +0 -24
  317. package/dist/src/mcp-tools/agenticow-speculate-tools.js +0 -209
  318. package/dist/src/mcp-tools/agenticow-tools.d.ts +0 -36
  319. package/dist/src/mcp-tools/agenticow-tools.js +0 -360
  320. package/dist/src/mcp-tools/analyze-tools.d.ts +0 -38
  321. package/dist/src/mcp-tools/analyze-tools.js +0 -346
  322. package/dist/src/mcp-tools/auto-install.d.ts +0 -83
  323. package/dist/src/mcp-tools/auto-install.js +0 -131
  324. package/dist/src/mcp-tools/autopilot-tools.d.ts +0 -12
  325. package/dist/src/mcp-tools/autopilot-tools.js +0 -231
  326. package/dist/src/mcp-tools/browser-intent-tools.d.ts +0 -162
  327. package/dist/src/mcp-tools/browser-intent-tools.js +0 -548
  328. package/dist/src/mcp-tools/browser-session-tools.d.ts +0 -27
  329. package/dist/src/mcp-tools/browser-session-tools.js +0 -398
  330. package/dist/src/mcp-tools/browser-tools.d.ts +0 -21
  331. package/dist/src/mcp-tools/browser-tools.js +0 -760
  332. package/dist/src/mcp-tools/business-pod-tools.d.ts +0 -20
  333. package/dist/src/mcp-tools/business-pod-tools.js +0 -169
  334. package/dist/src/mcp-tools/claims-tools.d.ts +0 -12
  335. package/dist/src/mcp-tools/claims-tools.js +0 -863
  336. package/dist/src/mcp-tools/config-tools.d.ts +0 -8
  337. package/dist/src/mcp-tools/config-tools.js +0 -411
  338. package/dist/src/mcp-tools/coordination-tools.d.ts +0 -13
  339. package/dist/src/mcp-tools/coordination-tools.js +0 -729
  340. package/dist/src/mcp-tools/daa-tools.d.ts +0 -13
  341. package/dist/src/mcp-tools/daa-tools.js +0 -534
  342. package/dist/src/mcp-tools/embeddings-tools.d.ts +0 -9
  343. package/dist/src/mcp-tools/embeddings-tools.js +0 -904
  344. package/dist/src/mcp-tools/github-tools.d.ts +0 -9
  345. package/dist/src/mcp-tools/github-tools.js +0 -659
  346. package/dist/src/mcp-tools/guidance-tools.d.ts +0 -15
  347. package/dist/src/mcp-tools/guidance-tools.js +0 -639
  348. package/dist/src/mcp-tools/hive-mind-tools.d.ts +0 -8
  349. package/dist/src/mcp-tools/hive-mind-tools.js +0 -953
  350. package/dist/src/mcp-tools/hooks-tools.d.ts +0 -65
  351. package/dist/src/mcp-tools/hooks-tools.js +0 -4824
  352. package/dist/src/mcp-tools/http-fetch-tools.d.ts +0 -55
  353. package/dist/src/mcp-tools/http-fetch-tools.js +0 -329
  354. package/dist/src/mcp-tools/index.d.ts +0 -34
  355. package/dist/src/mcp-tools/index.js +0 -40
  356. package/dist/src/mcp-tools/managed-agent-tools.d.ts +0 -22
  357. package/dist/src/mcp-tools/managed-agent-tools.js +0 -357
  358. package/dist/src/mcp-tools/memory-tools.d.ts +0 -14
  359. package/dist/src/mcp-tools/memory-tools.js +0 -1330
  360. package/dist/src/mcp-tools/metaharness-tools.d.ts +0 -51
  361. package/dist/src/mcp-tools/metaharness-tools.js +0 -684
  362. package/dist/src/mcp-tools/neural-tools.d.ts +0 -54
  363. package/dist/src/mcp-tools/neural-tools.js +0 -1168
  364. package/dist/src/mcp-tools/performance-tools.d.ts +0 -16
  365. package/dist/src/mcp-tools/performance-tools.js +0 -675
  366. package/dist/src/mcp-tools/progress-tools.d.ts +0 -14
  367. package/dist/src/mcp-tools/progress-tools.js +0 -348
  368. package/dist/src/mcp-tools/request-tracker.d.ts +0 -17
  369. package/dist/src/mcp-tools/request-tracker.js +0 -27
  370. package/dist/src/mcp-tools/ruvllm-tools.d.ts +0 -9
  371. package/dist/src/mcp-tools/ruvllm-tools.js +0 -355
  372. package/dist/src/mcp-tools/security-tools.d.ts +0 -18
  373. package/dist/src/mcp-tools/security-tools.js +0 -556
  374. package/dist/src/mcp-tools/session-tools.d.ts +0 -8
  375. package/dist/src/mcp-tools/session-tools.js +0 -517
  376. package/dist/src/mcp-tools/swarm-tools.d.ts +0 -37
  377. package/dist/src/mcp-tools/swarm-tools.js +0 -390
  378. package/dist/src/mcp-tools/system-tools.d.ts +0 -13
  379. package/dist/src/mcp-tools/system-tools.js +0 -688
  380. package/dist/src/mcp-tools/task-tools.d.ts +0 -8
  381. package/dist/src/mcp-tools/task-tools.js +0 -487
  382. package/dist/src/mcp-tools/terminal-tools.d.ts +0 -8
  383. package/dist/src/mcp-tools/terminal-tools.js +0 -306
  384. package/dist/src/mcp-tools/testgen-tools.d.ts +0 -26
  385. package/dist/src/mcp-tools/testgen-tools.js +0 -168
  386. package/dist/src/mcp-tools/tool-loop-guardrail.d.ts +0 -31
  387. package/dist/src/mcp-tools/tool-loop-guardrail.js +0 -71
  388. package/dist/src/mcp-tools/transfer-tools.d.ts +0 -14
  389. package/dist/src/mcp-tools/transfer-tools.js +0 -447
  390. package/dist/src/mcp-tools/types.d.ts +0 -8
  391. package/dist/src/mcp-tools/types.js +0 -8
  392. package/dist/src/mcp-tools/validate-input.d.ts +0 -9
  393. package/dist/src/mcp-tools/validate-input.js +0 -9
  394. package/dist/src/mcp-tools/wasm-agent-tools.d.ts +0 -13
  395. package/dist/src/mcp-tools/wasm-agent-tools.js +0 -840
  396. package/dist/src/mcp-tools/workflow-tools.d.ts +0 -8
  397. package/dist/src/mcp-tools/workflow-tools.js +0 -884
  398. package/dist/src/memory/bge-embedder.d.ts +0 -25
  399. package/dist/src/memory/bge-embedder.js +0 -121
  400. package/dist/src/memory/cross-encoder-rerank.d.ts +0 -33
  401. package/dist/src/memory/cross-encoder-rerank.js +0 -123
  402. package/dist/src/memory/embedding-policy.d.ts +0 -21
  403. package/dist/src/memory/embedding-policy.js +0 -30
  404. package/dist/src/memory/embedding-quantization.d.ts +0 -62
  405. package/dist/src/memory/embedding-quantization.js +0 -156
  406. package/dist/src/memory/ewc-consolidation.d.ts +0 -305
  407. package/dist/src/memory/ewc-consolidation.js +0 -611
  408. package/dist/src/memory/graph-edge-writer.d.ts +0 -95
  409. package/dist/src/memory/graph-edge-writer.js +0 -217
  410. package/dist/src/memory/hybrid-retrieval.d.ts +0 -77
  411. package/dist/src/memory/hybrid-retrieval.js +0 -192
  412. package/dist/src/memory/intelligence.d.ts +0 -405
  413. package/dist/src/memory/intelligence.js +0 -1316
  414. package/dist/src/memory/lucene-bm25.d.ts +0 -19
  415. package/dist/src/memory/lucene-bm25.js +0 -308
  416. package/dist/src/memory/memory-bridge.d.ts +0 -537
  417. package/dist/src/memory/memory-bridge.js +0 -2460
  418. package/dist/src/memory/memory-initializer.d.ts +0 -556
  419. package/dist/src/memory/memory-initializer.js +0 -3021
  420. package/dist/src/memory/neural-package-bridge.d.ts +0 -48
  421. package/dist/src/memory/neural-package-bridge.js +0 -87
  422. package/dist/src/memory/rabitq-index.d.ts +0 -60
  423. package/dist/src/memory/rabitq-index.js +0 -242
  424. package/dist/src/memory/sona-optimizer.d.ts +0 -267
  425. package/dist/src/memory/sona-optimizer.js +0 -779
  426. package/dist/src/memory/structured-distill.d.ts +0 -48
  427. package/dist/src/memory/structured-distill.js +0 -125
  428. package/dist/src/output.d.ts +0 -9
  429. package/dist/src/output.js +0 -9
  430. package/dist/src/parser.d.ts +0 -89
  431. package/dist/src/parser.js +0 -516
  432. package/dist/src/plugins/manager.d.ts +0 -133
  433. package/dist/src/plugins/manager.js +0 -415
  434. package/dist/src/plugins/store/discovery.d.ts +0 -99
  435. package/dist/src/plugins/store/discovery.js +0 -1224
  436. package/dist/src/plugins/store/index.d.ts +0 -76
  437. package/dist/src/plugins/store/index.js +0 -141
  438. package/dist/src/plugins/store/search.d.ts +0 -46
  439. package/dist/src/plugins/store/search.js +0 -230
  440. package/dist/src/plugins/store/types.d.ts +0 -279
  441. package/dist/src/plugins/store/types.js +0 -7
  442. package/dist/src/plugins/tests/demo-plugin-store.d.ts +0 -7
  443. package/dist/src/plugins/tests/demo-plugin-store.js +0 -126
  444. package/dist/src/plugins/tests/standalone-test.d.ts +0 -12
  445. package/dist/src/plugins/tests/standalone-test.js +0 -188
  446. package/dist/src/plugins/tests/test-plugin-store.d.ts +0 -7
  447. package/dist/src/plugins/tests/test-plugin-store.js +0 -206
  448. package/dist/src/production/circuit-breaker.d.ts +0 -101
  449. package/dist/src/production/circuit-breaker.js +0 -241
  450. package/dist/src/production/error-handler.d.ts +0 -92
  451. package/dist/src/production/error-handler.js +0 -299
  452. package/dist/src/production/index.d.ts +0 -23
  453. package/dist/src/production/index.js +0 -18
  454. package/dist/src/production/monitoring.d.ts +0 -161
  455. package/dist/src/production/monitoring.js +0 -356
  456. package/dist/src/production/rate-limiter.d.ts +0 -80
  457. package/dist/src/production/rate-limiter.js +0 -201
  458. package/dist/src/production/retry.d.ts +0 -48
  459. package/dist/src/production/retry.js +0 -179
  460. package/dist/src/prompt.d.ts +0 -44
  461. package/dist/src/prompt.js +0 -501
  462. package/dist/src/runtime/headless.d.ts +0 -60
  463. package/dist/src/runtime/headless.js +0 -284
  464. package/dist/src/runtime/parent-death-watchdog.d.ts +0 -42
  465. package/dist/src/runtime/parent-death-watchdog.js +0 -70
  466. package/dist/src/ruvector/agent-wasm.d.ts +0 -228
  467. package/dist/src/ruvector/agent-wasm.js +0 -463
  468. package/dist/src/ruvector/ast-analyzer.d.ts +0 -67
  469. package/dist/src/ruvector/ast-analyzer.js +0 -277
  470. package/dist/src/ruvector/codemods/engine.d.ts +0 -45
  471. package/dist/src/ruvector/codemods/engine.js +0 -291
  472. package/dist/src/ruvector/codemods/scope-analysis.d.ts +0 -29
  473. package/dist/src/ruvector/codemods/scope-analysis.js +0 -162
  474. package/dist/src/ruvector/coverage-router.d.ts +0 -160
  475. package/dist/src/ruvector/coverage-router.js +0 -531
  476. package/dist/src/ruvector/coverage-tools.d.ts +0 -33
  477. package/dist/src/ruvector/coverage-tools.js +0 -157
  478. package/dist/src/ruvector/diff-classifier.d.ts +0 -175
  479. package/dist/src/ruvector/diff-classifier.js +0 -699
  480. package/dist/src/ruvector/diskann-backend.d.ts +0 -78
  481. package/dist/src/ruvector/diskann-backend.js +0 -310
  482. package/dist/src/ruvector/enhanced-model-router.d.ts +0 -172
  483. package/dist/src/ruvector/enhanced-model-router.js +0 -577
  484. package/dist/src/ruvector/graph-analyzer.d.ts +0 -187
  485. package/dist/src/ruvector/graph-analyzer.js +0 -929
  486. package/dist/src/ruvector/graph-backend.d.ts +0 -79
  487. package/dist/src/ruvector/graph-backend.js +0 -220
  488. package/dist/src/ruvector/index.d.ts +0 -38
  489. package/dist/src/ruvector/index.js +0 -86
  490. package/dist/src/ruvector/lora-adapter.d.ts +0 -292
  491. package/dist/src/ruvector/lora-adapter.js +0 -710
  492. package/dist/src/ruvector/model-prices.d.ts +0 -50
  493. package/dist/src/ruvector/model-prices.js +0 -72
  494. package/dist/src/ruvector/model-router.d.ts +0 -408
  495. package/dist/src/ruvector/model-router.js +0 -1162
  496. package/dist/src/ruvector/neural-router.d.ts +0 -182
  497. package/dist/src/ruvector/neural-router.js +0 -825
  498. package/dist/src/ruvector/output-verifier.d.ts +0 -83
  499. package/dist/src/ruvector/output-verifier.js +0 -277
  500. package/dist/src/ruvector/q-learning-router.d.ts +0 -227
  501. package/dist/src/ruvector/q-learning-router.js +0 -721
  502. package/dist/src/ruvector/router-calibrator.d.ts +0 -65
  503. package/dist/src/ruvector/router-calibrator.js +0 -120
  504. package/dist/src/ruvector/router-parallel-recorder.d.ts +0 -127
  505. package/dist/src/ruvector/router-parallel-recorder.js +0 -183
  506. package/dist/src/ruvector/router-trajectory.d.ts +0 -194
  507. package/dist/src/ruvector/router-trajectory.js +0 -281
  508. package/dist/src/ruvector/run-transcript-recorder.d.ts +0 -154
  509. package/dist/src/ruvector/run-transcript-recorder.js +0 -209
  510. package/dist/src/ruvector/ruvllm-wasm.d.ts +0 -179
  511. package/dist/src/ruvector/ruvllm-wasm.js +0 -379
  512. package/dist/src/ruvector/semantic-router.d.ts +0 -77
  513. package/dist/src/ruvector/semantic-router.js +0 -178
  514. package/dist/src/ruvector/task-embedder.d.ts +0 -56
  515. package/dist/src/ruvector/task-embedder.js +0 -237
  516. package/dist/src/ruvector/trajectory-tree.d.ts +0 -113
  517. package/dist/src/ruvector/trajectory-tree.js +0 -237
  518. package/dist/src/ruvector/vector-db.d.ts +0 -73
  519. package/dist/src/ruvector/vector-db.js +0 -301
  520. package/dist/src/ruvector/wasm-embedder.d.ts +0 -13
  521. package/dist/src/ruvector/wasm-embedder.js +0 -143
  522. package/dist/src/services/agentic-flow-bridge.d.ts +0 -50
  523. package/dist/src/services/agentic-flow-bridge.js +0 -95
  524. package/dist/src/services/ai-job-dedup.d.ts +0 -61
  525. package/dist/src/services/ai-job-dedup.js +0 -136
  526. package/dist/src/services/checkpoint-gate.d.ts +0 -140
  527. package/dist/src/services/checkpoint-gate.js +0 -223
  528. package/dist/src/services/claim-service.d.ts +0 -204
  529. package/dist/src/services/claim-service.js +0 -818
  530. package/dist/src/services/config-file-manager.d.ts +0 -37
  531. package/dist/src/services/config-file-manager.js +0 -224
  532. package/dist/src/services/container-worker-pool.d.ts +0 -204
  533. package/dist/src/services/container-worker-pool.js +0 -589
  534. package/dist/src/services/daemon-autostart.d.ts +0 -17
  535. package/dist/src/services/daemon-autostart.js +0 -102
  536. package/dist/src/services/distill-oracle.d.ts +0 -190
  537. package/dist/src/services/distill-oracle.js +0 -349
  538. package/dist/src/services/distill-tuning.d.ts +0 -111
  539. package/dist/src/services/distill-tuning.js +0 -510
  540. package/dist/src/services/evolve-proof.d.ts +0 -253
  541. package/dist/src/services/evolve-proof.js +0 -343
  542. package/dist/src/services/fable-harness.d.ts +0 -207
  543. package/dist/src/services/fable-harness.js +0 -388
  544. package/dist/src/services/git-workspace-identity.d.ts +0 -42
  545. package/dist/src/services/git-workspace-identity.js +0 -99
  546. package/dist/src/services/global-ai-budget.d.ts +0 -135
  547. package/dist/src/services/global-ai-budget.js +0 -415
  548. package/dist/src/services/harness-benchmark.d.ts +0 -68
  549. package/dist/src/services/harness-benchmark.js +0 -94
  550. package/dist/src/services/harness-canary.d.ts +0 -60
  551. package/dist/src/services/harness-canary.js +0 -69
  552. package/dist/src/services/harness-corpus-harvester.d.ts +0 -51
  553. package/dist/src/services/harness-corpus-harvester.js +0 -74
  554. package/dist/src/services/harness-flywheel-generations.d.ts +0 -115
  555. package/dist/src/services/harness-flywheel-generations.js +0 -360
  556. package/dist/src/services/harness-flywheel-runtime.d.ts +0 -25
  557. package/dist/src/services/harness-flywheel-runtime.js +0 -92
  558. package/dist/src/services/harness-flywheel.d.ts +0 -48
  559. package/dist/src/services/harness-flywheel.js +0 -207
  560. package/dist/src/services/harness-frozen-eval.d.ts +0 -22
  561. package/dist/src/services/harness-frozen-eval.js +0 -66
  562. package/dist/src/services/harness-hosts.d.ts +0 -40
  563. package/dist/src/services/harness-hosts.js +0 -88
  564. package/dist/src/services/harness-improvement-ledger.d.ts +0 -63
  565. package/dist/src/services/harness-improvement-ledger.js +0 -101
  566. package/dist/src/services/harness-loop.d.ts +0 -53
  567. package/dist/src/services/harness-loop.js +0 -85
  568. package/dist/src/services/harness-qualification.d.ts +0 -66
  569. package/dist/src/services/harness-qualification.js +0 -143
  570. package/dist/src/services/harness-replay.d.ts +0 -37
  571. package/dist/src/services/harness-replay.js +0 -92
  572. package/dist/src/services/harness-verify.d.ts +0 -33
  573. package/dist/src/services/harness-verify.js +0 -26
  574. package/dist/src/services/harness-worker.d.ts +0 -23
  575. package/dist/src/services/harness-worker.js +0 -66
  576. package/dist/src/services/headless-worker-executor.d.ts +0 -358
  577. package/dist/src/services/headless-worker-executor.js +0 -1269
  578. package/dist/src/services/index.d.ts +0 -13
  579. package/dist/src/services/index.js +0 -11
  580. package/dist/src/services/memory-backup.d.ts +0 -53
  581. package/dist/src/services/memory-backup.js +0 -198
  582. package/dist/src/services/memory-distillation.d.ts +0 -41
  583. package/dist/src/services/memory-distillation.js +0 -277
  584. package/dist/src/services/native-training.d.ts +0 -68
  585. package/dist/src/services/native-training.js +0 -141
  586. package/dist/src/services/registry-api.d.ts +0 -58
  587. package/dist/src/services/registry-api.js +0 -146
  588. package/dist/src/services/repo-supervisor.d.ts +0 -70
  589. package/dist/src/services/repo-supervisor.js +0 -228
  590. package/dist/src/services/ruvector-training.d.ts +0 -222
  591. package/dist/src/services/ruvector-training.js +0 -693
  592. package/dist/src/services/swarm-memory-branches.d.ts +0 -135
  593. package/dist/src/services/swarm-memory-branches.js +0 -213
  594. package/dist/src/services/weight-eft.d.ts +0 -305
  595. package/dist/src/services/weight-eft.js +0 -296
  596. package/dist/src/services/worker-daemon.d.ts +0 -439
  597. package/dist/src/services/worker-daemon.js +0 -1865
  598. package/dist/src/services/worker-queue.d.ts +0 -194
  599. package/dist/src/services/worker-queue.js +0 -513
  600. package/dist/src/services/workspace-lease.d.ts +0 -55
  601. package/dist/src/services/workspace-lease.js +0 -191
  602. package/dist/src/suggest.d.ts +0 -53
  603. package/dist/src/suggest.js +0 -200
  604. package/dist/src/transfer/anonymization/index.d.ts +0 -25
  605. package/dist/src/transfer/anonymization/index.js +0 -175
  606. package/dist/src/transfer/deploy-seraphine.d.ts +0 -13
  607. package/dist/src/transfer/deploy-seraphine.js +0 -205
  608. package/dist/src/transfer/export.d.ts +0 -25
  609. package/dist/src/transfer/export.js +0 -113
  610. package/dist/src/transfer/index.d.ts +0 -12
  611. package/dist/src/transfer/index.js +0 -31
  612. package/dist/src/transfer/ipfs/client.d.ts +0 -109
  613. package/dist/src/transfer/ipfs/client.js +0 -307
  614. package/dist/src/transfer/ipfs/upload.d.ts +0 -95
  615. package/dist/src/transfer/ipfs/upload.js +0 -413
  616. package/dist/src/transfer/models/seraphine.d.ts +0 -72
  617. package/dist/src/transfer/models/seraphine.js +0 -373
  618. package/dist/src/transfer/serialization/cfp.d.ts +0 -49
  619. package/dist/src/transfer/serialization/cfp.js +0 -183
  620. package/dist/src/transfer/storage/gcs.d.ts +0 -82
  621. package/dist/src/transfer/storage/gcs.js +0 -272
  622. package/dist/src/transfer/storage/index.d.ts +0 -6
  623. package/dist/src/transfer/storage/index.js +0 -6
  624. package/dist/src/transfer/store/discovery.d.ts +0 -84
  625. package/dist/src/transfer/store/discovery.js +0 -382
  626. package/dist/src/transfer/store/download.d.ts +0 -70
  627. package/dist/src/transfer/store/download.js +0 -334
  628. package/dist/src/transfer/store/index.d.ts +0 -84
  629. package/dist/src/transfer/store/index.js +0 -153
  630. package/dist/src/transfer/store/publish.d.ts +0 -76
  631. package/dist/src/transfer/store/publish.js +0 -294
  632. package/dist/src/transfer/store/registry.d.ts +0 -58
  633. package/dist/src/transfer/store/registry.js +0 -285
  634. package/dist/src/transfer/store/search.d.ts +0 -54
  635. package/dist/src/transfer/store/search.js +0 -232
  636. package/dist/src/transfer/store/tests/standalone-test.d.ts +0 -12
  637. package/dist/src/transfer/store/tests/standalone-test.js +0 -190
  638. package/dist/src/transfer/store/types.d.ts +0 -193
  639. package/dist/src/transfer/store/types.js +0 -6
  640. package/dist/src/transfer/test-seraphine.d.ts +0 -6
  641. package/dist/src/transfer/test-seraphine.js +0 -105
  642. package/dist/src/transfer/tests/test-store.d.ts +0 -7
  643. package/dist/src/transfer/tests/test-store.js +0 -214
  644. package/dist/src/transfer/types.d.ts +0 -245
  645. package/dist/src/transfer/types.js +0 -6
  646. package/dist/src/types.d.ts +0 -13
  647. package/dist/src/types.js +0 -13
  648. package/dist/src/update/checker.d.ts +0 -34
  649. package/dist/src/update/checker.js +0 -191
  650. package/dist/src/update/executor.d.ts +0 -33
  651. package/dist/src/update/executor.js +0 -217
  652. package/dist/src/update/index.d.ts +0 -33
  653. package/dist/src/update/index.js +0 -64
  654. package/dist/src/update/rate-limiter.d.ts +0 -20
  655. package/dist/src/update/rate-limiter.js +0 -96
  656. package/dist/src/update/validator.d.ts +0 -17
  657. package/dist/src/update/validator.js +0 -123
@@ -1,2142 +0,0 @@
1
- /**
2
- * Init Executor
3
- * Main execution logic for V3 initialization
4
- */
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import { fileURLToPath } from 'url';
8
- import { createRequire } from 'module';
9
- import { dirname } from 'path';
10
- // ESM-compatible __dirname
11
- const __filename = fileURLToPath(import.meta.url);
12
- const __dirname = dirname(__filename);
13
- import { detectPlatform, DEFAULT_INIT_OPTIONS } from './types.js';
14
- import { generateSettingsJson, generateSettings } from './settings-generator.js';
15
- import { generateMCPJson } from './mcp-generator.js';
16
- import { generateStatuslineScript } from './statusline-generator.js';
17
- import { generatePreCommitHook, generatePostCommitHook, generateSessionManager, generateAgentRouter, generateMemoryHelper, generateHookHandler, generateIntelligenceStub, generateAutoMemoryHook, generateRufloHookCjs, } from './helpers-generator.js';
18
- import { getInstalledCliVersion, HELPERS_STAMP_FILE } from './helper-refresh.js';
19
- import { generateClaudeMd } from './claudemd-generator.js';
20
- import { recordMemoryPackagePath } from './memory-package-resolver.js';
21
- /**
22
- * Skills to copy based on configuration
23
- */
24
- const SKILLS_MAP = {
25
- core: [
26
- 'swarm-orchestration',
27
- 'swarm-advanced',
28
- 'sparc-methodology',
29
- 'hooks-automation',
30
- 'pair-programming',
31
- 'verification-quality',
32
- 'stream-chain',
33
- 'skill-builder',
34
- ],
35
- browser: ['browser'], // agent-browser integration
36
- dualMode: ['dual-mode'], // Claude Code + Codex hybrid execution
37
- agentdb: [
38
- 'agentdb-advanced',
39
- 'agentdb-learning',
40
- 'agentdb-memory-patterns',
41
- 'agentdb-optimization',
42
- 'agentdb-vector-search',
43
- 'reasoningbank-agentdb',
44
- 'reasoningbank-intelligence',
45
- ],
46
- github: [
47
- 'github-code-review',
48
- 'github-multi-repo',
49
- 'github-project-management',
50
- 'github-release-management',
51
- 'github-workflow-automation',
52
- ],
53
- flowNexus: [
54
- 'flow-nexus-neural',
55
- 'flow-nexus-platform',
56
- 'flow-nexus-swarm',
57
- ],
58
- v3: [
59
- 'v3-cli-modernization',
60
- 'v3-core-implementation',
61
- 'v3-ddd-architecture',
62
- 'v3-integration-deep',
63
- 'v3-mcp-optimization',
64
- 'v3-memory-unification',
65
- 'v3-performance-optimization',
66
- 'v3-security-overhaul',
67
- 'v3-swarm-coordination',
68
- ],
69
- };
70
- /**
71
- * Commands to copy based on configuration
72
- * ADR-128 Phase 4: every subdirectory under .claude/commands/ now has a
73
- * corresponding key. The flow-nexus/ dir was deleted (belongs to the plugin).
74
- * New substrate keys default true; opt-in keys (pair, training, stream-chain,
75
- * truth, verify) default false per ADR-128 §Phase 3 opt-in rationale.
76
- */
77
- const COMMANDS_MAP = {
78
- core: ['claude-flow-help.md', 'claude-flow-swarm.md', 'claude-flow-memory.md'],
79
- analysis: ['analysis'],
80
- automation: ['automation'],
81
- github: ['github'],
82
- hooks: ['hooks'],
83
- monitoring: ['monitoring'],
84
- optimization: ['optimization'],
85
- sparc: ['sparc'],
86
- // ADR-128 Phase 4 promotions (previously orphaned)
87
- agents: ['agents'],
88
- coordination: ['coordination'],
89
- hiveMind: ['hive-mind'],
90
- memory: ['memory'],
91
- swarm: ['swarm'],
92
- workflows: ['workflows'],
93
- // Opt-in categories (non-universal; default false in CommandsConfig)
94
- pair: ['pair'],
95
- training: ['training'],
96
- streamChain: ['stream-chain'],
97
- truth: ['truth'],
98
- verify: ['verify'],
99
- };
100
- /**
101
- * Agents to copy based on configuration
102
- */
103
- const AGENTS_MAP = {
104
- core: ['core'],
105
- consensus: ['consensus'],
106
- github: ['github'],
107
- hiveMind: ['hive-mind'],
108
- sparc: ['sparc'],
109
- swarm: ['swarm'],
110
- browser: ['browser'], // agent-browser integration
111
- dualMode: ['dual-mode'], // Claude Code + Codex hybrid execution
112
- // V3-specific agents
113
- v3: ['v3'],
114
- optimization: ['optimization'],
115
- templates: ['templates'],
116
- testing: ['testing'],
117
- sublinear: ['sublinear'],
118
- flowNexus: ['flow-nexus'],
119
- analysis: ['analysis'],
120
- architecture: ['architecture'],
121
- development: ['development'],
122
- devops: ['devops'],
123
- documentation: ['documentation'],
124
- specialized: ['specialized'],
125
- goal: ['goal'],
126
- sona: ['sona'],
127
- payments: ['payments'],
128
- data: ['data'],
129
- custom: ['custom'],
130
- };
131
- /**
132
- * Directory structure to create
133
- */
134
- const DIRECTORIES = {
135
- claude: [
136
- '.claude',
137
- '.claude/skills',
138
- '.claude/commands',
139
- '.claude/agents',
140
- '.claude/helpers',
141
- ],
142
- runtime: [
143
- '.claude-flow',
144
- '.claude-flow/data',
145
- '.claude-flow/logs',
146
- '.claude-flow/sessions',
147
- '.claude-flow/hooks',
148
- '.claude-flow/agents',
149
- '.claude-flow/workflows',
150
- ],
151
- };
152
- /**
153
- * Execute initialization
154
- */
155
- export async function executeInit(options) {
156
- // Detect platform
157
- const platform = detectPlatform();
158
- const result = {
159
- success: true,
160
- platform,
161
- created: {
162
- directories: [],
163
- files: [],
164
- },
165
- skipped: [],
166
- errors: [],
167
- summary: {
168
- skillsCount: 0,
169
- commandsCount: 0,
170
- agentsCount: 0,
171
- hooksEnabled: 0,
172
- },
173
- };
174
- const targetDir = options.targetDir;
175
- try {
176
- // Create directory structure
177
- await createDirectories(targetDir, options, result);
178
- // Generate and write settings.json
179
- if (options.components.settings) {
180
- await writeSettings(targetDir, options, result);
181
- }
182
- // Generate and write .mcp.json
183
- if (options.components.mcp) {
184
- await writeMCPConfig(targetDir, options, result);
185
- }
186
- // Copy skills
187
- if (options.components.skills) {
188
- await copySkills(targetDir, options, result);
189
- }
190
- // Copy commands
191
- if (options.components.commands) {
192
- await copyCommands(targetDir, options, result);
193
- }
194
- // Copy agents
195
- if (options.components.agents) {
196
- await copyAgents(targetDir, options, result);
197
- }
198
- // Generate helpers
199
- if (options.components.helpers) {
200
- await writeHelpers(targetDir, options, result);
201
- // #2545: The auto-memory hook needs @claude-flow/memory, which is an
202
- // optionalDependency of the CLI and lands in the npx cache — unreachable
203
- // by a node_modules walk-up from the user's project. Resolve it from the
204
- // CLI's own context now (where it IS present) and record the absolute
205
- // path in a machine-local sidecar the hook reads first. Best-effort:
206
- // when the optional dep is absent the hook fails loud and doctor flags it.
207
- const memRecord = recordMemoryPackagePath(targetDir, 'init');
208
- if (memRecord) {
209
- result.created.files.push('.claude-flow/memory-package.json');
210
- }
211
- // #2568-followup: if this project already has a memory DB that predates
212
- // the `vector_indexes` table (older CLI / agentdb-written), self-heal it
213
- // so the statusline vector count + namespace routing work. Best-effort,
214
- // dynamically imported so a WASM-only host without better-sqlite3 just
215
- // skips it.
216
- //
217
- // Persistent memory ON BY DEFAULT: `runtime.memoryBackend` already
218
- // defaults to 'hybrid' in DEFAULT_INIT_OPTIONS, but that only ever
219
- // configured the DECLARED backend — the actual .swarm/memory.db file
220
- // was never created until something eventually called `memory store`
221
- // or the user ran `memory init --force` by hand (both the generated
222
- // CLAUDE.md and the quickstart docs told users to do this as a
223
- // separate step). A fresh project could sit for days looking
224
- // "configured for AgentDB" while genuinely capturing nothing, with no
225
- // signal that the config and the on-disk reality had diverged. Fresh
226
- // projects now get the DB eagerly created here, matching what
227
- // `memoryBackend` already promised; MINIMAL_INIT_OPTIONS
228
- // (memoryBackend: 'memory') opts out, matching its non-persistent intent.
229
- try {
230
- const memDbPath = path.join(targetDir, '.swarm', 'memory.db');
231
- if (fs.existsSync(memDbPath)) {
232
- const { repairVectorIndexes } = await import('../memory/memory-initializer.js');
233
- await repairVectorIndexes(memDbPath, { autoRecover: true });
234
- }
235
- else if (options.runtime.memoryBackend !== 'memory') {
236
- const { initializeMemoryDatabase } = await import('../memory/memory-initializer.js');
237
- const initResult = await initializeMemoryDatabase({
238
- backend: options.runtime.memoryBackend,
239
- dbPath: memDbPath,
240
- verbose: false,
241
- });
242
- if (initResult.success) {
243
- result.created.files.push('.swarm/memory.db');
244
- }
245
- }
246
- }
247
- catch { /* best-effort — never block init on memory setup */ }
248
- }
249
- // Generate statusline
250
- if (options.components.statusline) {
251
- await writeStatusline(targetDir, options, result);
252
- }
253
- // Generate runtime config
254
- if (options.components.runtime) {
255
- await writeRuntimeConfig(targetDir, options, result);
256
- }
257
- // Create initial metrics for statusline (prevents "all zeros" display)
258
- if (options.components.statusline) {
259
- await writeInitialMetrics(targetDir, options, result);
260
- }
261
- // Generate CLAUDE.md
262
- if (options.components.claudeMd) {
263
- await writeClaudeMd(targetDir, options, result);
264
- }
265
- // Count enabled hooks
266
- result.summary.hooksEnabled = countEnabledHooks(options);
267
- }
268
- catch (error) {
269
- result.success = false;
270
- result.errors.push(error instanceof Error ? error.message : String(error));
271
- }
272
- return result;
273
- }
274
- /**
275
- * Merge new settings into existing settings.json
276
- * Preserves user customizations while adding new features like Agent Teams
277
- * Uses platform-specific commands for Mac, Linux, and Windows
278
- */
279
- function mergeSettingsForUpgrade(existing) {
280
- const merged = { ...existing };
281
- const platform = detectPlatform();
282
- const isWindows = platform.os === 'windows';
283
- // Platform-specific command wrappers
284
- // Windows: Use PowerShell-compatible commands
285
- // Mac/Linux: Use bash-compatible commands with 2>/dev/null
286
- // NOTE: teammateIdleCmd and taskCompletedCmd were removed.
287
- // TeammateIdle/TaskCompleted are not valid Claude Code hook events and caused warnings.
288
- // Agent Teams hook config lives in claudeFlow.agentTeams.hooks instead.
289
- // 1. Merge env vars (preserve existing, add new)
290
- const existingEnv = existing.env || {};
291
- merged.env = {
292
- ...existingEnv,
293
- CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: '1',
294
- CLAUDE_FLOW_V3_ENABLED: existingEnv.CLAUDE_FLOW_V3_ENABLED || 'true',
295
- CLAUDE_FLOW_HOOKS_ENABLED: existingEnv.CLAUDE_FLOW_HOOKS_ENABLED || 'true',
296
- };
297
- // 2. Merge hooks (preserve existing, add new Agent Teams + auto-memory hooks)
298
- const existingHooks = existing.hooks || {};
299
- merged.hooks = { ...existingHooks };
300
- // Cross-platform auto-memory hook commands that resolve paths via git root.
301
- // Uses node -e with git rev-parse so hooks work regardless of CWD (#1259, #1284).
302
- const gitRootResolver = "var c=require('child_process'),p=require('path'),u=require('url'),r;"
303
- + "try{r=c.execSync('git rev-parse --show-toplevel',{encoding:'utf8'}).trim()}"
304
- + 'catch(e){r=process.cwd()}';
305
- const autoMemoryScript = '.claude/helpers/auto-memory-hook.mjs';
306
- const autoMemoryImportCmd = `node -e "${gitRootResolver}var f=p.join(r,'${autoMemoryScript}');import(u.pathToFileURL(f).href)" import`;
307
- const autoMemorySyncCmd = `node -e "${gitRootResolver}var f=p.join(r,'${autoMemoryScript}');import(u.pathToFileURL(f).href)" sync`;
308
- // Add auto-memory import to SessionStart (if not already present)
309
- const sessionStartHooks = existingHooks.SessionStart;
310
- const hasAutoMemoryImport = sessionStartHooks?.some(group => group.hooks?.some(h => h.command?.includes('auto-memory-hook')));
311
- if (!hasAutoMemoryImport) {
312
- const startHooks = merged.hooks;
313
- if (!startHooks.SessionStart) {
314
- startHooks.SessionStart = [{ hooks: [] }];
315
- }
316
- const startGroup = startHooks.SessionStart[0];
317
- if (!startGroup.hooks)
318
- startGroup.hooks = [];
319
- startGroup.hooks.push({
320
- type: 'command',
321
- command: autoMemoryImportCmd,
322
- timeout: 6000,
323
- continueOnError: true,
324
- });
325
- }
326
- // Add auto-memory sync to SessionEnd (if not already present)
327
- const sessionEndHooks = existingHooks.SessionEnd;
328
- const hasAutoMemorySync = sessionEndHooks?.some(group => group.hooks?.some(h => h.command?.includes('auto-memory-hook')));
329
- if (!hasAutoMemorySync) {
330
- const endHooks = merged.hooks;
331
- if (!endHooks.SessionEnd) {
332
- endHooks.SessionEnd = [{ hooks: [] }];
333
- }
334
- const endGroup = endHooks.SessionEnd[0];
335
- if (!endGroup.hooks)
336
- endGroup.hooks = [];
337
- // Insert at beginning so sync runs before other cleanup
338
- endGroup.hooks.unshift({
339
- type: 'command',
340
- command: autoMemorySyncCmd,
341
- timeout: 8000,
342
- continueOnError: true,
343
- });
344
- }
345
- // NOTE: TeammateIdle and TaskCompleted are NOT valid Claude Code hook events.
346
- // They cause warnings when present in settings.json hooks.
347
- // Remove them if they exist from a previous init.
348
- delete merged.hooks.TeammateIdle;
349
- delete merged.hooks.TaskCompleted;
350
- // Their configuration lives in claudeFlow.agentTeams.hooks instead.
351
- // 3. Fix statusLine config (remove invalid fields, ensure correct format)
352
- // Claude Code only supports: type, command, padding
353
- //
354
- // #2448 — Detect and REGENERATE the runaway `npx @claude-flow/cli@latest`
355
- // statusline form. Pre-#2337 init wrote this to settings.json; it spawns
356
- // a cold Node process + npm registry round-trip on every fire (statusline
357
- // refires every few hundred ms), which on macOS produced load average 49
358
- // / jetsam / kernel panic. Preserving the user's existing command (the
359
- // old behavior here) means anyone who installed pre-#2337 and upgraded
360
- // never gets the fix. Now we detect the broken form and overwrite.
361
- const NEW_STATUSLINE_CMD = `node -e "var c=require('child_process'),p=require('path'),r;try{r=c.execSync('git rev-parse --show-toplevel',{encoding:'utf8'}).trim()}catch(e){r=process.cwd()}var s=p.join(r,'.claude/helpers/statusline.cjs');process.argv.splice(1,0,s);require(s)"`;
362
- // Matches any invocation of `claude-flow hooks statusline` — either via npx
363
- // (`npx [--prefer-offline] [@]claude-flow[/cli][@<tag>] hooks statusline …`)
364
- // or as a bare command (`claude-flow hooks statusline …`). Both forms cold-
365
- // load the ONNX model on every fire (~1s); Claude Code times out and hides
366
- // the status bar (#2450). The migration replaces the whole command with
367
- // NEW_STATUSLINE_CMD which invokes the local helper directly via `node -e`.
368
- // Flag-list repetition bounded at 10 (real invocations never carry more) —
369
- // an unbounded `*` here is exponential-backtracking-prone (CodeQL
370
- // js/redos): a crafted settings.json command string with dozens of
371
- // dash-token repetitions can hang this check for minutes.
372
- const BROKEN_STATUSLINE_RE = /(?:npx\s+(?:--?\S+\s+){0,10})?@?claude-flow(?:\/cli)?(?:@\S+)?\s+hooks\s+statusline/;
373
- const existingStatusLine = existing.statusLine;
374
- if (existingStatusLine) {
375
- const existingCmd = typeof existingStatusLine.command === 'string' ? existingStatusLine.command : '';
376
- const isBroken = BROKEN_STATUSLINE_RE.test(existingCmd);
377
- merged.statusLine = {
378
- type: 'command',
379
- command: isBroken || !existingCmd ? NEW_STATUSLINE_CMD : existingCmd,
380
- // Remove invalid fields: refreshMs, enabled (not supported by Claude Code)
381
- };
382
- }
383
- // #2448 — Detect and REGENERATE per-action hook commands that still use
384
- // the runaway `npx @claude-flow/cli@latest hooks <sub>` form. These fire
385
- // on every PreToolUse/PostToolUse/UserPromptSubmit, each spawning ~130 MB
386
- // of cold Node + npm registry resolution; the storm is what kernel-paniced
387
- // the reporter's machine in #2448.
388
- //
389
- // We walk each hook event's `hooks[]` and swap any command matching the
390
- // broken pattern for the local-helper form. Idempotent: re-running this
391
- // migration on already-correct settings is a no-op.
392
- // Bounded for the same reason as BROKEN_STATUSLINE_RE above (CodeQL js/redos).
393
- const BROKEN_HOOK_RE = /npx\s+(?:--?\S+\s+){0,10}@?claude-flow\/cli@latest\s+hooks\s+(\S+)/;
394
- const localHookCmd = (sub) => {
395
- // POSIX form mirrors settings-generator.ts::hookCmd() exactly.
396
- // Windows users hit a separate code path (cmd /c …) — Claude Code on
397
- // Windows is rarer and the migration there is left to a follow-up.
398
- if (process.platform === 'win32') {
399
- return `cmd /c "IF EXIST \"%CLAUDE_PROJECT_DIR%\\.claude\\helpers\\hook-handler.cjs\" (node \"%CLAUDE_PROJECT_DIR%\\.claude\\helpers\\hook-handler.cjs\" ${sub}) ELSE (node \"%USERPROFILE%\\.claude\\helpers\\hook-handler.cjs\" ${sub})"`;
400
- }
401
- return `sh -c 'D="\${CLAUDE_PROJECT_DIR:-.}"; [ -f "$D/.claude/helpers/hook-handler.cjs" ] || D="\${HOME}"; exec node "$D/.claude/helpers/hook-handler.cjs" ${sub}'`;
402
- };
403
- const mergedHooks = merged.hooks;
404
- if (mergedHooks) {
405
- for (const eventName of Object.keys(mergedHooks)) {
406
- const groups = mergedHooks[eventName];
407
- if (!Array.isArray(groups))
408
- continue;
409
- for (const group of groups) {
410
- if (!Array.isArray(group.hooks))
411
- continue;
412
- for (const h of group.hooks) {
413
- if (typeof h?.command !== 'string')
414
- continue;
415
- const m = BROKEN_HOOK_RE.exec(h.command);
416
- if (!m)
417
- continue;
418
- // Subcommand captured (e.g. "pre-bash", "post-edit", "route") — keep it.
419
- h.command = localHookCmd(m[1]);
420
- }
421
- }
422
- }
423
- }
424
- // 4. Merge claudeFlow settings (preserve existing, add agentTeams + memory)
425
- const existingClaudeFlow = existing.claudeFlow || {};
426
- const existingMemory = existingClaudeFlow.memory || {};
427
- merged.claudeFlow = {
428
- ...existingClaudeFlow,
429
- version: existingClaudeFlow.version || '3.0.0',
430
- enabled: existingClaudeFlow.enabled !== false,
431
- agentTeams: {
432
- enabled: true,
433
- teammateMode: 'auto',
434
- taskListEnabled: true,
435
- mailboxEnabled: true,
436
- coordination: {
437
- autoAssignOnIdle: true,
438
- trainPatternsOnComplete: true,
439
- notifyLeadOnComplete: true,
440
- sharedMemoryNamespace: 'agent-teams',
441
- },
442
- hooks: {
443
- teammateIdle: { enabled: true, autoAssign: true, checkTaskList: true },
444
- taskCompleted: { enabled: true, trainPatterns: true, notifyLead: true },
445
- },
446
- },
447
- memory: {
448
- ...existingMemory,
449
- learningBridge: existingMemory.learningBridge ?? { enabled: true },
450
- memoryGraph: existingMemory.memoryGraph ?? { enabled: true },
451
- agentScopes: existingMemory.agentScopes ?? { enabled: true },
452
- },
453
- };
454
- return merged;
455
- }
456
- /**
457
- * Execute upgrade - updates helpers and creates missing metrics without losing data
458
- * This is safe for existing users who want the latest statusline fixes
459
- * @param targetDir - Target directory
460
- * @param upgradeSettings - If true, merge new settings into existing settings.json
461
- */
462
- export async function executeUpgrade(targetDir, upgradeSettings = false) {
463
- const result = {
464
- success: true,
465
- updated: [],
466
- created: [],
467
- preserved: [],
468
- errors: [],
469
- settingsUpdated: [],
470
- };
471
- try {
472
- // Ensure required directories exist
473
- const dirs = [
474
- '.claude/helpers',
475
- '.claude-flow/metrics',
476
- '.claude-flow/security',
477
- '.claude-flow/learning',
478
- ];
479
- for (const dir of dirs) {
480
- const fullPath = path.join(targetDir, dir);
481
- if (!fs.existsSync(fullPath)) {
482
- fs.mkdirSync(fullPath, { recursive: true });
483
- }
484
- }
485
- // 0. ALWAYS update critical helpers (force overwrite)
486
- const sourceHelpersForUpgrade = findSourceHelpersDir();
487
- if (sourceHelpersForUpgrade) {
488
- // Keep in sync with helper-refresh.ts:CRITICAL_HELPERS.
489
- const criticalHelpers = ['auto-memory-hook.mjs', 'hook-handler.cjs', 'intelligence.cjs', 'statusline.cjs'];
490
- for (const helperName of criticalHelpers) {
491
- const targetPath = path.join(targetDir, '.claude', 'helpers', helperName);
492
- const sourcePath = path.join(sourceHelpersForUpgrade, helperName);
493
- if (fs.existsSync(sourcePath)) {
494
- if (fs.existsSync(targetPath)) {
495
- result.updated.push(`.claude/helpers/${helperName}`);
496
- }
497
- else {
498
- result.created.push(`.claude/helpers/${helperName}`);
499
- }
500
- fs.copyFileSync(sourcePath, targetPath);
501
- try {
502
- fs.chmodSync(targetPath, '755');
503
- }
504
- catch { }
505
- }
506
- }
507
- }
508
- else {
509
- // Source not found (npx with broken paths) — use generated fallbacks
510
- const generatedCritical = {
511
- 'hook-handler.cjs': generateHookHandler(),
512
- 'intelligence.cjs': generateIntelligenceStub(),
513
- 'auto-memory-hook.mjs': generateAutoMemoryHook(),
514
- };
515
- for (const [helperName, content] of Object.entries(generatedCritical)) {
516
- const targetPath = path.join(targetDir, '.claude', 'helpers', helperName);
517
- if (fs.existsSync(targetPath)) {
518
- result.updated.push(`.claude/helpers/${helperName}`);
519
- }
520
- else {
521
- result.created.push(`.claude/helpers/${helperName}`);
522
- }
523
- fs.writeFileSync(targetPath, content, 'utf-8');
524
- try {
525
- fs.chmodSync(targetPath, '755');
526
- }
527
- catch { }
528
- }
529
- }
530
- // Stamp the installed version so the startup auto-refresh treats these as
531
- // current (no redundant re-copy on the next command).
532
- try {
533
- fs.writeFileSync(path.join(targetDir, '.claude', 'helpers', HELPERS_STAMP_FILE), getInstalledCliVersion(), 'utf-8');
534
- }
535
- catch { /* non-fatal */ }
536
- // #2545: (re)record the resolved @claude-flow/memory path so the auto-memory
537
- // hook can find it on the npx install path. Best-effort — see executeInit.
538
- const memRecord = recordMemoryPackagePath(targetDir, 'upgrade');
539
- if (memRecord) {
540
- result.updated.push('.claude-flow/memory-package.json');
541
- }
542
- // 1. ALWAYS update statusline helper (force overwrite)
543
- const statuslinePath = path.join(targetDir, '.claude', 'helpers', 'statusline.cjs');
544
- // Use default options with statusline config
545
- const upgradeOptions = {
546
- ...DEFAULT_INIT_OPTIONS,
547
- targetDir,
548
- force: true,
549
- statusline: {
550
- ...DEFAULT_INIT_OPTIONS.statusline,
551
- refreshInterval: 5000,
552
- },
553
- };
554
- const statuslineContent = generateStatuslineScript(upgradeOptions);
555
- if (fs.existsSync(statuslinePath)) {
556
- result.updated.push('.claude/helpers/statusline.cjs');
557
- }
558
- else {
559
- result.created.push('.claude/helpers/statusline.cjs');
560
- }
561
- fs.writeFileSync(statuslinePath, statuslineContent, 'utf-8');
562
- // 2. Create MISSING metrics files only (preserve existing data)
563
- const metricsDir = path.join(targetDir, '.claude-flow', 'metrics');
564
- const securityDir = path.join(targetDir, '.claude-flow', 'security');
565
- // v3-progress.json
566
- const progressPath = path.join(metricsDir, 'v3-progress.json');
567
- if (!fs.existsSync(progressPath)) {
568
- const progress = {
569
- version: '3.0.0',
570
- initialized: new Date().toISOString(),
571
- domains: { completed: 0, total: 5, status: 'INITIALIZING' },
572
- ddd: { progress: 0, modules: 0, totalFiles: 0, totalLines: 0 },
573
- swarm: { activeAgents: 0, maxAgents: 15, topology: 'hierarchical-mesh' },
574
- learning: { status: 'READY', patternsLearned: 0, sessionsCompleted: 0 },
575
- _note: 'Metrics will update as you use Ruflo'
576
- };
577
- fs.writeFileSync(progressPath, JSON.stringify(progress, null, 2), 'utf-8');
578
- result.created.push('.claude-flow/metrics/v3-progress.json');
579
- }
580
- else {
581
- result.preserved.push('.claude-flow/metrics/v3-progress.json');
582
- }
583
- // swarm-activity.json
584
- const activityPath = path.join(metricsDir, 'swarm-activity.json');
585
- if (!fs.existsSync(activityPath)) {
586
- const activity = {
587
- timestamp: new Date().toISOString(),
588
- processes: { agentic_flow: 0, mcp_server: 0, estimated_agents: 0 },
589
- swarm: { active: false, agent_count: 0, coordination_active: false },
590
- integration: { agentic_flow_active: false, mcp_active: false },
591
- _initialized: true
592
- };
593
- fs.writeFileSync(activityPath, JSON.stringify(activity, null, 2), 'utf-8');
594
- result.created.push('.claude-flow/metrics/swarm-activity.json');
595
- }
596
- else {
597
- result.preserved.push('.claude-flow/metrics/swarm-activity.json');
598
- }
599
- // learning.json
600
- const learningPath = path.join(metricsDir, 'learning.json');
601
- if (!fs.existsSync(learningPath)) {
602
- const learning = {
603
- initialized: new Date().toISOString(),
604
- routing: { accuracy: 0, decisions: 0 },
605
- patterns: { shortTerm: 0, longTerm: 0, quality: 0 },
606
- sessions: { total: 0, current: null },
607
- _note: 'Intelligence grows as you use Ruflo'
608
- };
609
- fs.writeFileSync(learningPath, JSON.stringify(learning, null, 2), 'utf-8');
610
- result.created.push('.claude-flow/metrics/learning.json');
611
- }
612
- else {
613
- result.preserved.push('.claude-flow/metrics/learning.json');
614
- }
615
- // audit-status.json
616
- const auditPath = path.join(securityDir, 'audit-status.json');
617
- if (!fs.existsSync(auditPath)) {
618
- const audit = {
619
- initialized: new Date().toISOString(),
620
- status: 'PENDING',
621
- cvesFixed: 0,
622
- totalCves: 3,
623
- lastScan: null,
624
- _note: 'Run: npx @claude-flow/cli@latest security scan'
625
- };
626
- fs.writeFileSync(auditPath, JSON.stringify(audit, null, 2), 'utf-8');
627
- result.created.push('.claude-flow/security/audit-status.json');
628
- }
629
- else {
630
- result.preserved.push('.claude-flow/security/audit-status.json');
631
- }
632
- // 3. Merge settings if requested
633
- if (upgradeSettings) {
634
- const settingsPath = path.join(targetDir, '.claude', 'settings.json');
635
- if (fs.existsSync(settingsPath)) {
636
- try {
637
- const existingSettings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
638
- const mergedSettings = mergeSettingsForUpgrade(existingSettings);
639
- fs.writeFileSync(settingsPath, JSON.stringify(mergedSettings, null, 2), 'utf-8');
640
- result.updated.push('.claude/settings.json');
641
- result.settingsUpdated = [
642
- 'env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS',
643
- 'hooks.SessionStart (auto-memory import)',
644
- 'hooks.SessionEnd (auto-memory sync)',
645
- 'hooks.TeammateIdle (removed — not a valid Claude Code hook)',
646
- 'hooks.TaskCompleted (removed — not a valid Claude Code hook)',
647
- 'claudeFlow.agentTeams',
648
- 'claudeFlow.memory (learningBridge, memoryGraph, agentScopes)',
649
- ];
650
- }
651
- catch (settingsError) {
652
- result.errors.push(`Settings merge failed: ${settingsError instanceof Error ? settingsError.message : String(settingsError)}`);
653
- }
654
- }
655
- else {
656
- // Create new settings.json with defaults
657
- const defaultSettings = generateSettings(DEFAULT_INIT_OPTIONS);
658
- fs.writeFileSync(settingsPath, JSON.stringify(defaultSettings, null, 2), 'utf-8');
659
- result.created.push('.claude/settings.json');
660
- result.settingsUpdated = ['Created new settings.json with Agent Teams'];
661
- }
662
- }
663
- }
664
- catch (error) {
665
- result.success = false;
666
- result.errors.push(error instanceof Error ? error.message : String(error));
667
- }
668
- return result;
669
- }
670
- /**
671
- * Execute upgrade with --add-missing flag
672
- * Adds any new skills, agents, and commands that don't exist yet
673
- * @param targetDir - Target directory
674
- * @param upgradeSettings - If true, merge new settings into existing settings.json
675
- */
676
- export async function executeUpgradeWithMissing(targetDir, upgradeSettings = false) {
677
- // First do the normal upgrade (pass through upgradeSettings)
678
- const result = await executeUpgrade(targetDir, upgradeSettings);
679
- if (!result.success) {
680
- return result;
681
- }
682
- // Initialize tracking arrays
683
- result.addedSkills = [];
684
- result.addedAgents = [];
685
- result.addedCommands = [];
686
- try {
687
- // Ensure target directories exist
688
- const skillsDir = path.join(targetDir, '.claude', 'skills');
689
- const agentsDir = path.join(targetDir, '.claude', 'agents');
690
- const commandsDir = path.join(targetDir, '.claude', 'commands');
691
- for (const dir of [skillsDir, agentsDir, commandsDir]) {
692
- if (!fs.existsSync(dir)) {
693
- fs.mkdirSync(dir, { recursive: true });
694
- }
695
- }
696
- // Find source directories
697
- const sourceSkillsDir = findSourceDir('skills');
698
- const sourceAgentsDir = findSourceDir('agents');
699
- const sourceCommandsDir = findSourceDir('commands');
700
- // Debug: Log source directories found
701
- if (process.env.DEBUG || process.env.CLAUDE_FLOW_DEBUG) {
702
- console.log('[DEBUG] Source directories:');
703
- console.log(` Skills: ${sourceSkillsDir || 'NOT FOUND'}`);
704
- console.log(` Agents: ${sourceAgentsDir || 'NOT FOUND'}`);
705
- console.log(` Commands: ${sourceCommandsDir || 'NOT FOUND'}`);
706
- }
707
- // Add missing skills
708
- if (sourceSkillsDir) {
709
- const allSkills = Object.values(SKILLS_MAP).flat();
710
- const debugMode = process.env.DEBUG || process.env.CLAUDE_FLOW_DEBUG;
711
- if (debugMode) {
712
- console.log(`[DEBUG] Checking ${allSkills.length} skills from SKILLS_MAP`);
713
- }
714
- for (const skillName of [...new Set(allSkills)]) {
715
- const sourcePath = path.join(sourceSkillsDir, skillName);
716
- const targetPath = path.join(skillsDir, skillName);
717
- const sourceExists = fs.existsSync(sourcePath);
718
- const targetExists = fs.existsSync(targetPath);
719
- if (debugMode) {
720
- console.log(`[DEBUG] Skill '${skillName}': source=${sourceExists}, target=${targetExists}`);
721
- }
722
- if (sourceExists && !targetExists) {
723
- copyDirRecursive(sourcePath, targetPath);
724
- result.addedSkills.push(skillName);
725
- result.created.push(`.claude/skills/${skillName}`);
726
- }
727
- }
728
- }
729
- // Add missing agents
730
- if (sourceAgentsDir) {
731
- const allAgents = Object.values(AGENTS_MAP).flat();
732
- for (const agentCategory of [...new Set(allAgents)]) {
733
- const sourcePath = path.join(sourceAgentsDir, agentCategory);
734
- const targetPath = path.join(agentsDir, agentCategory);
735
- if (fs.existsSync(sourcePath) && !fs.existsSync(targetPath)) {
736
- copyDirRecursive(sourcePath, targetPath);
737
- result.addedAgents.push(agentCategory);
738
- result.created.push(`.claude/agents/${agentCategory}`);
739
- }
740
- }
741
- }
742
- // Add missing commands
743
- if (sourceCommandsDir) {
744
- const allCommands = Object.values(COMMANDS_MAP).flat();
745
- for (const cmdName of [...new Set(allCommands)]) {
746
- const sourcePath = path.join(sourceCommandsDir, cmdName);
747
- const targetPath = path.join(commandsDir, cmdName);
748
- if (fs.existsSync(sourcePath) && !fs.existsSync(targetPath)) {
749
- if (fs.statSync(sourcePath).isDirectory()) {
750
- copyDirRecursive(sourcePath, targetPath);
751
- }
752
- else {
753
- fs.copyFileSync(sourcePath, targetPath);
754
- }
755
- result.addedCommands.push(cmdName);
756
- result.created.push(`.claude/commands/${cmdName}`);
757
- }
758
- }
759
- }
760
- }
761
- catch (error) {
762
- result.errors.push(`Add missing failed: ${error instanceof Error ? error.message : String(error)}`);
763
- }
764
- return result;
765
- }
766
- /**
767
- * Create directory structure
768
- */
769
- async function createDirectories(targetDir, options, result) {
770
- const dirs = [
771
- ...DIRECTORIES.claude,
772
- ...(options.components.runtime ? DIRECTORIES.runtime : []),
773
- ];
774
- for (const dir of dirs) {
775
- const fullPath = path.join(targetDir, dir);
776
- if (!fs.existsSync(fullPath)) {
777
- fs.mkdirSync(fullPath, { recursive: true });
778
- result.created.directories.push(dir);
779
- }
780
- }
781
- }
782
- /**
783
- * Write settings.json
784
- */
785
- async function writeSettings(targetDir, options, result) {
786
- const settingsPath = path.join(targetDir, '.claude', 'settings.json');
787
- const generated = JSON.parse(generateSettingsJson(options));
788
- if (fs.existsSync(settingsPath) && !options.force) {
789
- // Merge hooks/env/permissions into existing settings instead of skipping
790
- try {
791
- const existing = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
792
- let merged = false;
793
- // Merge hooks (the critical missing piece — #1484)
794
- if (generated.hooks && !existing.hooks) {
795
- existing.hooks = generated.hooks;
796
- merged = true;
797
- }
798
- // Merge env vars (for CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS etc.)
799
- if (generated.env) {
800
- existing.env = { ...(existing.env || {}), ...generated.env };
801
- merged = true;
802
- }
803
- // Merge permissions (add ruflo allow rules)
804
- if (generated.permissions?.allow) {
805
- const existingAllow = existing.permissions?.allow || [];
806
- const newRules = generated.permissions.allow.filter((r) => !existingAllow.includes(r));
807
- if (newRules.length > 0) {
808
- existing.permissions = existing.permissions || {};
809
- existing.permissions.allow = [...existingAllow, ...newRules];
810
- merged = true;
811
- }
812
- }
813
- if (merged) {
814
- fs.writeFileSync(settingsPath, JSON.stringify(existing, null, 2), 'utf-8');
815
- result.created.files.push('.claude/settings.json (merged hooks)');
816
- }
817
- else {
818
- result.skipped.push('.claude/settings.json');
819
- }
820
- }
821
- catch {
822
- // Existing file is corrupt — overwrite
823
- fs.writeFileSync(settingsPath, JSON.stringify(generated, null, 2), 'utf-8');
824
- result.created.files.push('.claude/settings.json');
825
- }
826
- return;
827
- }
828
- fs.writeFileSync(settingsPath, JSON.stringify(generated, null, 2), 'utf-8');
829
- result.created.files.push('.claude/settings.json');
830
- }
831
- /**
832
- * #1779 — Walk parents of `targetDir` plus the user-global Claude Code
833
- * config locations, looking for any `.mcp.json` (or `~/.claude.json`)
834
- * that already declares a `ruflo`-keyed MCP server. We use this to skip
835
- * writing our own `claude-flow`-keyed entry when the user has already
836
- * registered the same binary under the new name — that's exactly the
837
- * "same MCP server twice under two different prefixes" duplication the
838
- * issue describes.
839
- *
840
- * Returns the path of the file that already declares `ruflo`/`claude-flow` (so we can
841
- * surface it in the skipped-message), or null if none found.
842
- */
843
- function detectExistingRufloMCP(targetDir) {
844
- const home = (process.env.HOME ?? process.env.USERPROFILE) ?? '';
845
- const candidates = new Set();
846
- // User-global Claude Code config locations
847
- if (home) {
848
- candidates.add(path.join(home, '.claude.json'));
849
- candidates.add(path.join(home, '.claude', 'mcp.json'));
850
- }
851
- // Walk parents of targetDir up to root, checking for .mcp.json at each
852
- const targetResolved = path.resolve(targetDir);
853
- let dir = targetResolved;
854
- const targetAncestors = new Set();
855
- while (true) {
856
- candidates.add(path.join(dir, '.mcp.json'));
857
- targetAncestors.add(normalizeProjectKey(dir));
858
- const parent = path.dirname(dir);
859
- if (parent === dir)
860
- break;
861
- dir = parent;
862
- }
863
- // Skip the targetDir itself — that's the one we're about to write
864
- candidates.delete(path.join(targetResolved, '.mcp.json'));
865
- for (const candidate of candidates) {
866
- if (!fs.existsSync(candidate))
867
- continue;
868
- try {
869
- const parsed = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
870
- if (!parsed || typeof parsed !== 'object')
871
- continue;
872
- // (a) Top-level mcpServers (legacy / global form).
873
- // Accept BOTH names so init does not add a second server for the same
874
- // binary when a project carries a pre-rename `claude-flow` registration
875
- // and the current generator would write `ruflo` (#2612).
876
- if (parsed.mcpServers && typeof parsed.mcpServers === 'object') {
877
- const servers = parsed.mcpServers;
878
- // #2369: also recognise the legacy dist-tag keys generated by
879
- // pre-rename installs (claude-flow ≤ 2.x). Without these the
880
- // detection walks parent dirs, doesn't match, and writes a NEW
881
- // claude-flow-keyed config — both servers then run under
882
- // different prefixes producing duplicate-tool noise.
883
- if ('claude-flow' in servers ||
884
- 'ruflo' in servers ||
885
- 'claude-flow@alpha' in servers ||
886
- 'claude-flow@v3alpha' in servers)
887
- return candidate;
888
- }
889
- // (b) #1840: Claude Code project-scoped registrations under
890
- // parsed.projects[<projectPath>].mcpServers. Match by
891
- // normalized path against targetDir or any of its ancestors so an
892
- // existing `claude-flow` or `ruflo` registration in this repo is
893
- // detected even when Claude stored the key with different casing/slash style.
894
- if (parsed.projects && typeof parsed.projects === 'object') {
895
- for (const [projectKey, projectVal] of Object.entries(parsed.projects)) {
896
- if (!projectVal || typeof projectVal !== 'object')
897
- continue;
898
- const projectMcp = projectVal.mcpServers;
899
- if (!projectMcp || typeof projectMcp !== 'object')
900
- continue;
901
- const mcp = projectMcp;
902
- // #2369: legacy dist-tag keys also count as already-registered.
903
- if (!('claude-flow' in mcp) &&
904
- !('ruflo' in mcp) &&
905
- !('claude-flow@alpha' in mcp) &&
906
- !('claude-flow@v3alpha' in mcp))
907
- continue;
908
- if (targetAncestors.has(normalizeProjectKey(projectKey))) {
909
- return `${candidate} (projects[${projectKey}])`;
910
- }
911
- }
912
- }
913
- }
914
- catch { /* malformed JSON — ignore */ }
915
- }
916
- return null;
917
- }
918
- /**
919
- * Normalize a project path key for cross-platform comparison.
920
- * Claude Code stores Windows paths like "C:/Users/.../Project" while
921
- * Node's `path.resolve()` may emit "C:\Users\...\Project". Lowercase +
922
- * forward-slash gives a stable comparison key on both platforms.
923
- */
924
- function normalizeProjectKey(p) {
925
- return path.resolve(p).replace(/\\/g, '/').toLowerCase();
926
- }
927
- /**
928
- * Write .mcp.json
929
- */
930
- async function writeMCPConfig(targetDir, options, result) {
931
- const mcpPath = path.join(targetDir, '.mcp.json');
932
- if (fs.existsSync(mcpPath) && !options.force) {
933
- // #2369: an existing .mcp.json from a pre-rename install is the most
934
- // common cause of "autopilot tools missing after init" reports. Parse
935
- // the existing file and surface a loud, specific message naming the
936
- // stale key so users know to either delete the file or re-run with
937
- // --force. Without this they get a silent skip and no warning.
938
- try {
939
- const parsed = JSON.parse(fs.readFileSync(mcpPath, 'utf-8'));
940
- const servers = parsed?.mcpServers;
941
- if (servers && typeof servers === 'object') {
942
- const staleKeys = ['claude-flow@alpha', 'claude-flow@v3alpha'].filter(k => k in servers);
943
- if (staleKeys.length > 0) {
944
- result.skipped.push(`.mcp.json (existing file uses deprecated key '${staleKeys[0]}' — autopilot/browser/wasm-agent tools will be missing; ` +
945
- `delete .mcp.json and re-run, or re-run with --force to overwrite)`);
946
- return;
947
- }
948
- }
949
- }
950
- catch {
951
- // Existing file isn't valid JSON — fall through to the generic skip.
952
- }
953
- result.skipped.push('.mcp.json');
954
- return;
955
- }
956
- // #1779/#2612 — Skip writing if the user already has this MCP server
957
- // registered elsewhere (parent .mcp.json, ~/.claude.json, etc). The
958
- // canonical key is `claude-flow` (per #2206 — matches mcp__claude-flow__*
959
- // plugin tool refs); a stray `ruflo`-keyed entry pointing at the same
960
- // binary is the legacy-duplicate form that #2612 healed. Writing our
961
- // fresh `claude-flow` entry on top of either variant starts the same
962
- // binary twice under two tool namespaces. Force-mode (`--force`)
963
- // bypasses this guard for users who actually want both registrations.
964
- if (!options.force) {
965
- const existingRufloPath = detectExistingRufloMCP(targetDir);
966
- if (existingRufloPath) {
967
- result.skipped.push(`.mcp.json (existing ruflo/claude-flow MCP registration found at ${existingRufloPath} — would create duplicate; pass --force to write anyway)`);
968
- return;
969
- }
970
- }
971
- const content = generateMCPJson(options);
972
- fs.writeFileSync(mcpPath, content, 'utf-8');
973
- result.created.files.push('.mcp.json');
974
- }
975
- /**
976
- * Copy skills from source
977
- */
978
- async function copySkills(targetDir, options, result) {
979
- const skillsConfig = options.skills;
980
- const targetSkillsDir = path.join(targetDir, '.claude', 'skills');
981
- // Determine which skills to copy
982
- const skillsToCopy = [];
983
- if (skillsConfig.all) {
984
- // Copy all available skills
985
- Object.values(SKILLS_MAP).forEach(skills => skillsToCopy.push(...skills));
986
- }
987
- else {
988
- if (skillsConfig.core)
989
- skillsToCopy.push(...SKILLS_MAP.core);
990
- if (skillsConfig.agentdb)
991
- skillsToCopy.push(...SKILLS_MAP.agentdb);
992
- if (skillsConfig.github)
993
- skillsToCopy.push(...SKILLS_MAP.github);
994
- if (skillsConfig.flowNexus)
995
- skillsToCopy.push(...SKILLS_MAP.flowNexus);
996
- if (skillsConfig.browser)
997
- skillsToCopy.push(...SKILLS_MAP.browser);
998
- if (skillsConfig.v3)
999
- skillsToCopy.push(...SKILLS_MAP.v3);
1000
- if (skillsConfig.dualMode)
1001
- skillsToCopy.push(...SKILLS_MAP.dualMode);
1002
- }
1003
- // Find source skills directory
1004
- const sourceSkillsDir = findSourceDir('skills', options.sourceBaseDir);
1005
- if (!sourceSkillsDir) {
1006
- result.errors.push('Could not find source skills directory');
1007
- return;
1008
- }
1009
- // Copy each skill
1010
- for (const skillName of [...new Set(skillsToCopy)]) {
1011
- const sourcePath = path.join(sourceSkillsDir, skillName);
1012
- const targetPath = path.join(targetSkillsDir, skillName);
1013
- if (fs.existsSync(sourcePath)) {
1014
- if (!fs.existsSync(targetPath) || options.force) {
1015
- copyDirRecursive(sourcePath, targetPath);
1016
- result.created.files.push(`.claude/skills/${skillName}`);
1017
- result.summary.skillsCount++;
1018
- }
1019
- else {
1020
- result.skipped.push(`.claude/skills/${skillName}`);
1021
- }
1022
- }
1023
- }
1024
- }
1025
- /**
1026
- * Copy commands from source
1027
- */
1028
- async function copyCommands(targetDir, options, result) {
1029
- const commandsConfig = options.commands;
1030
- const targetCommandsDir = path.join(targetDir, '.claude', 'commands');
1031
- // Determine which commands to copy
1032
- const commandsToCopy = [];
1033
- if (commandsConfig.all) {
1034
- Object.values(COMMANDS_MAP).forEach(cmds => commandsToCopy.push(...cmds));
1035
- }
1036
- else {
1037
- if (commandsConfig.core)
1038
- commandsToCopy.push(...COMMANDS_MAP.core);
1039
- if (commandsConfig.analysis)
1040
- commandsToCopy.push(...COMMANDS_MAP.analysis);
1041
- if (commandsConfig.automation)
1042
- commandsToCopy.push(...COMMANDS_MAP.automation);
1043
- if (commandsConfig.github)
1044
- commandsToCopy.push(...COMMANDS_MAP.github);
1045
- if (commandsConfig.hooks)
1046
- commandsToCopy.push(...COMMANDS_MAP.hooks);
1047
- if (commandsConfig.monitoring)
1048
- commandsToCopy.push(...COMMANDS_MAP.monitoring);
1049
- if (commandsConfig.optimization)
1050
- commandsToCopy.push(...COMMANDS_MAP.optimization);
1051
- if (commandsConfig.sparc)
1052
- commandsToCopy.push(...COMMANDS_MAP.sparc);
1053
- // ADR-128 Phase 4 substrate promotions
1054
- if (commandsConfig.agents)
1055
- commandsToCopy.push(...(COMMANDS_MAP.agents || []));
1056
- if (commandsConfig.coordination)
1057
- commandsToCopy.push(...(COMMANDS_MAP.coordination || []));
1058
- if (commandsConfig.hiveMind)
1059
- commandsToCopy.push(...(COMMANDS_MAP.hiveMind || []));
1060
- if (commandsConfig.memory)
1061
- commandsToCopy.push(...(COMMANDS_MAP.memory || []));
1062
- if (commandsConfig.swarm)
1063
- commandsToCopy.push(...(COMMANDS_MAP.swarm || []));
1064
- if (commandsConfig.workflows)
1065
- commandsToCopy.push(...(COMMANDS_MAP.workflows || []));
1066
- // ADR-128 Phase 4 opt-in categories
1067
- if (commandsConfig.pair)
1068
- commandsToCopy.push(...(COMMANDS_MAP.pair || []));
1069
- if (commandsConfig.training)
1070
- commandsToCopy.push(...(COMMANDS_MAP.training || []));
1071
- if (commandsConfig.streamChain)
1072
- commandsToCopy.push(...(COMMANDS_MAP.streamChain || []));
1073
- if (commandsConfig.truth)
1074
- commandsToCopy.push(...(COMMANDS_MAP.truth || []));
1075
- if (commandsConfig.verify)
1076
- commandsToCopy.push(...(COMMANDS_MAP.verify || []));
1077
- }
1078
- // Find source commands directory
1079
- const sourceCommandsDir = findSourceDir('commands', options.sourceBaseDir);
1080
- if (!sourceCommandsDir) {
1081
- result.errors.push('Could not find source commands directory');
1082
- return;
1083
- }
1084
- // Copy each command/directory
1085
- for (const cmdName of [...new Set(commandsToCopy)]) {
1086
- const sourcePath = path.join(sourceCommandsDir, cmdName);
1087
- const targetPath = path.join(targetCommandsDir, cmdName);
1088
- if (fs.existsSync(sourcePath)) {
1089
- if (!fs.existsSync(targetPath) || options.force) {
1090
- if (fs.statSync(sourcePath).isDirectory()) {
1091
- copyDirRecursive(sourcePath, targetPath);
1092
- }
1093
- else {
1094
- fs.copyFileSync(sourcePath, targetPath);
1095
- }
1096
- result.created.files.push(`.claude/commands/${cmdName}`);
1097
- result.summary.commandsCount++;
1098
- }
1099
- else {
1100
- result.skipped.push(`.claude/commands/${cmdName}`);
1101
- }
1102
- }
1103
- }
1104
- }
1105
- /**
1106
- * Copy agents from source
1107
- */
1108
- async function copyAgents(targetDir, options, result) {
1109
- const agentsConfig = options.agents;
1110
- const targetAgentsDir = path.join(targetDir, '.claude', 'agents');
1111
- // Determine which agents to copy
1112
- const agentsToCopy = [];
1113
- if (agentsConfig.all) {
1114
- Object.values(AGENTS_MAP).forEach(agents => agentsToCopy.push(...agents));
1115
- }
1116
- else {
1117
- if (agentsConfig.core)
1118
- agentsToCopy.push(...AGENTS_MAP.core);
1119
- if (agentsConfig.consensus)
1120
- agentsToCopy.push(...AGENTS_MAP.consensus);
1121
- if (agentsConfig.github)
1122
- agentsToCopy.push(...AGENTS_MAP.github);
1123
- if (agentsConfig.hiveMind)
1124
- agentsToCopy.push(...AGENTS_MAP.hiveMind);
1125
- if (agentsConfig.sparc)
1126
- agentsToCopy.push(...AGENTS_MAP.sparc);
1127
- if (agentsConfig.swarm)
1128
- agentsToCopy.push(...AGENTS_MAP.swarm);
1129
- if (agentsConfig.browser)
1130
- agentsToCopy.push(...AGENTS_MAP.browser);
1131
- // V3-specific agent categories
1132
- if (agentsConfig.v3)
1133
- agentsToCopy.push(...(AGENTS_MAP.v3 || []));
1134
- if (agentsConfig.optimization)
1135
- agentsToCopy.push(...(AGENTS_MAP.optimization || []));
1136
- if (agentsConfig.testing)
1137
- agentsToCopy.push(...(AGENTS_MAP.testing || []));
1138
- // Dual-mode agents (Claude Code + Codex hybrid)
1139
- if (agentsConfig.dualMode)
1140
- agentsToCopy.push(...(AGENTS_MAP.dualMode || []));
1141
- }
1142
- // Find source agents directory
1143
- const sourceAgentsDir = findSourceDir('agents', options.sourceBaseDir);
1144
- if (!sourceAgentsDir) {
1145
- result.errors.push('Could not find source agents directory');
1146
- return;
1147
- }
1148
- // Copy each agent category
1149
- for (const agentCategory of [...new Set(agentsToCopy)]) {
1150
- const sourcePath = path.join(sourceAgentsDir, agentCategory);
1151
- const targetPath = path.join(targetAgentsDir, agentCategory);
1152
- if (fs.existsSync(sourcePath)) {
1153
- if (!fs.existsSync(targetPath) || options.force) {
1154
- copyDirRecursive(sourcePath, targetPath);
1155
- // Count agent files (.md only — .yaml agents were migrated to .md)
1156
- const mdFiles = countFiles(sourcePath, '.md');
1157
- result.summary.agentsCount += mdFiles;
1158
- result.created.files.push(`.claude/agents/${agentCategory}`);
1159
- }
1160
- else {
1161
- result.skipped.push(`.claude/agents/${agentCategory}`);
1162
- }
1163
- }
1164
- }
1165
- }
1166
- /**
1167
- * Find source helpers directory.
1168
- * Validates that the directory contains hook-handler.cjs to avoid
1169
- * returning the target directory or an incomplete source.
1170
- */
1171
- function findSourceHelpersDir(sourceBaseDir) {
1172
- const possiblePaths = [];
1173
- const SENTINEL_FILE = 'hook-handler.cjs'; // Must exist in valid source
1174
- // If explicit source base directory is provided, check it first
1175
- if (sourceBaseDir) {
1176
- possiblePaths.push(path.join(sourceBaseDir, '.claude', 'helpers'));
1177
- }
1178
- // Strategy 1: require.resolve to find package root (most reliable for npx)
1179
- try {
1180
- const esmRequire = createRequire(import.meta.url);
1181
- const pkgJsonPath = esmRequire.resolve('@claude-flow/cli/package.json');
1182
- const pkgRoot = path.dirname(pkgJsonPath);
1183
- possiblePaths.push(path.join(pkgRoot, '.claude', 'helpers'));
1184
- }
1185
- catch {
1186
- // Not installed as a package — skip
1187
- }
1188
- // Strategy 2: __dirname-based (dist/src/init -> package root)
1189
- const packageRoot = path.resolve(__dirname, '..', '..', '..');
1190
- const packageHelpers = path.join(packageRoot, '.claude', 'helpers');
1191
- possiblePaths.push(packageHelpers);
1192
- // Strategy 3: Walk up from __dirname looking for package root
1193
- let currentDir = __dirname;
1194
- for (let i = 0; i < 10; i++) {
1195
- const parentDir = path.dirname(currentDir);
1196
- if (parentDir === currentDir)
1197
- break; // hit filesystem root
1198
- const helpersPath = path.join(parentDir, '.claude', 'helpers');
1199
- possiblePaths.push(helpersPath);
1200
- currentDir = parentDir;
1201
- }
1202
- // Strategy 4: Check cwd-relative paths (for local dev)
1203
- const cwdBased = [
1204
- path.join(process.cwd(), '.claude', 'helpers'),
1205
- path.join(process.cwd(), '..', '.claude', 'helpers'),
1206
- path.join(process.cwd(), '..', '..', '.claude', 'helpers'),
1207
- ];
1208
- possiblePaths.push(...cwdBased);
1209
- // Return first path that exists AND contains the sentinel file
1210
- for (const p of possiblePaths) {
1211
- if (fs.existsSync(p) && fs.existsSync(path.join(p, SENTINEL_FILE))) {
1212
- return p;
1213
- }
1214
- }
1215
- return null;
1216
- }
1217
- /**
1218
- * Write helper scripts
1219
- */
1220
- async function writeHelpers(targetDir, options, result) {
1221
- const helpersDir = path.join(targetDir, '.claude', 'helpers');
1222
- // Find source helpers directory (works for npm package and local dev)
1223
- const sourceHelpersDir = findSourceHelpersDir(options.sourceBaseDir);
1224
- // On Windows: emit a notice before writing helpers — the settings.json
1225
- // hooks will use node-based commands instead of bash shims (#2132).
1226
- if (process.platform === 'win32') {
1227
- console.log('Detected Windows — adding cross-platform hook overrides to .claude/settings.json (#2132)');
1228
- }
1229
- // Try to copy existing helpers from source first
1230
- if (sourceHelpersDir && fs.existsSync(sourceHelpersDir)) {
1231
- const helperFiles = fs.readdirSync(sourceHelpersDir);
1232
- let copiedCount = 0;
1233
- for (const file of helperFiles) {
1234
- const sourcePath = path.join(sourceHelpersDir, file);
1235
- const destPath = path.join(helpersDir, file);
1236
- // Skip directories and only copy files
1237
- if (!fs.statSync(sourcePath).isFile())
1238
- continue;
1239
- if (!fs.existsSync(destPath) || options.force) {
1240
- fs.copyFileSync(sourcePath, destPath);
1241
- // Make shell scripts and mjs files executable
1242
- if (file.endsWith('.sh') || file.endsWith('.mjs')) {
1243
- fs.chmodSync(destPath, '755');
1244
- }
1245
- result.created.files.push(`.claude/helpers/${file}`);
1246
- copiedCount++;
1247
- }
1248
- else {
1249
- result.skipped.push(`.claude/helpers/${file}`);
1250
- }
1251
- }
1252
- // #2132: Always generate ruflo-hook.cjs regardless of source copy path.
1253
- // The source helpers dir may not contain this file (it lives in
1254
- // plugins/ruflo-core/scripts/, not .claude/helpers/), but it must
1255
- // always be present so Windows users can use the node-based shim.
1256
- const rufloHookDest = path.join(helpersDir, 'ruflo-hook.cjs');
1257
- if (!fs.existsSync(rufloHookDest) || options.force) {
1258
- fs.writeFileSync(rufloHookDest, generateRufloHookCjs(), 'utf-8');
1259
- result.created.files.push('.claude/helpers/ruflo-hook.cjs');
1260
- }
1261
- else {
1262
- result.skipped.push('.claude/helpers/ruflo-hook.cjs');
1263
- }
1264
- if (copiedCount > 0) {
1265
- return; // Skip generating if we copied from source
1266
- }
1267
- }
1268
- // Fall back to generating helpers if source not available
1269
- const helpers = {
1270
- 'pre-commit': generatePreCommitHook(),
1271
- 'post-commit': generatePostCommitHook(),
1272
- 'session.js': generateSessionManager(),
1273
- 'router.js': generateAgentRouter(),
1274
- 'memory.js': generateMemoryHelper(),
1275
- 'hook-handler.cjs': generateHookHandler(),
1276
- 'intelligence.cjs': generateIntelligenceStub(),
1277
- 'auto-memory-hook.mjs': generateAutoMemoryHook(),
1278
- // #2132: cross-platform Node.js port of ruflo-hook.sh — always deployed so
1279
- // Windows users have a working shim even if the plugin's hooks.json bash
1280
- // commands are overridden via settings.json.
1281
- 'ruflo-hook.cjs': generateRufloHookCjs(),
1282
- };
1283
- for (const [name, content] of Object.entries(helpers)) {
1284
- const filePath = path.join(helpersDir, name);
1285
- if (!fs.existsSync(filePath) || options.force) {
1286
- fs.writeFileSync(filePath, content, 'utf-8');
1287
- // Make shell scripts executable
1288
- if (!name.endsWith('.js')) {
1289
- fs.chmodSync(filePath, '755');
1290
- }
1291
- result.created.files.push(`.claude/helpers/${name}`);
1292
- }
1293
- else {
1294
- result.skipped.push(`.claude/helpers/${name}`);
1295
- }
1296
- }
1297
- }
1298
- /**
1299
- * Find source .claude directory for statusline files
1300
- */
1301
- function findSourceClaudeDir(sourceBaseDir) {
1302
- const possiblePaths = [];
1303
- // If explicit source base directory is provided, check it first
1304
- if (sourceBaseDir) {
1305
- possiblePaths.push(path.join(sourceBaseDir, '.claude'));
1306
- }
1307
- // IMPORTANT: Check the package's own .claude directory
1308
- // Go up 3 levels: dist/src/init -> dist/src -> dist -> root
1309
- const packageRoot = path.resolve(__dirname, '..', '..', '..');
1310
- const packageClaude = path.join(packageRoot, '.claude');
1311
- if (fs.existsSync(packageClaude)) {
1312
- possiblePaths.unshift(packageClaude); // Add to beginning (highest priority)
1313
- }
1314
- // From dist/src/init -> go up to project root
1315
- let currentDir = __dirname;
1316
- for (let i = 0; i < 10; i++) {
1317
- const parentDir = path.dirname(currentDir);
1318
- const claudePath = path.join(parentDir, '.claude');
1319
- if (fs.existsSync(claudePath)) {
1320
- possiblePaths.push(claudePath);
1321
- }
1322
- currentDir = parentDir;
1323
- }
1324
- for (const p of possiblePaths) {
1325
- if (fs.existsSync(p)) {
1326
- return p;
1327
- }
1328
- }
1329
- return null;
1330
- }
1331
- /**
1332
- * Write statusline configuration
1333
- */
1334
- async function writeStatusline(targetDir, options, result) {
1335
- const claudeDir = path.join(targetDir, '.claude');
1336
- const helpersDir = path.join(targetDir, '.claude', 'helpers');
1337
- // Find source .claude directory (works for npm package and local dev)
1338
- const sourceClaudeDir = findSourceClaudeDir(options.sourceBaseDir);
1339
- // Try to copy existing advanced statusline files from source
1340
- const advancedStatuslineFiles = [
1341
- { src: 'statusline.sh', dest: 'statusline.sh', dir: claudeDir },
1342
- { src: 'statusline.mjs', dest: 'statusline.mjs', dir: claudeDir },
1343
- ];
1344
- if (sourceClaudeDir) {
1345
- for (const file of advancedStatuslineFiles) {
1346
- const sourcePath = path.join(sourceClaudeDir, file.src);
1347
- const destPath = path.join(file.dir, file.dest);
1348
- if (fs.existsSync(sourcePath)) {
1349
- if (!fs.existsSync(destPath) || options.force) {
1350
- fs.copyFileSync(sourcePath, destPath);
1351
- // Make shell scripts and mjs executable
1352
- if (file.src.endsWith('.sh') || file.src.endsWith('.mjs')) {
1353
- fs.chmodSync(destPath, '755');
1354
- }
1355
- result.created.files.push(`.claude/${file.dest}`);
1356
- }
1357
- else {
1358
- result.skipped.push(`.claude/${file.dest}`);
1359
- }
1360
- }
1361
- }
1362
- }
1363
- // ALWAYS generate statusline.cjs — the generated version includes AgentDB
1364
- // vectors/size, tests, ADRs, hooks, and integration stats that the
1365
- // pre-installed static copy in the npm package lacks.
1366
- // This must overwrite any copy from writeHelpers() which copies the legacy file.
1367
- const statuslineScript = generateStatuslineScript(options);
1368
- const statuslinePath = path.join(helpersDir, 'statusline.cjs');
1369
- fs.writeFileSync(statuslinePath, statuslineScript, 'utf-8');
1370
- result.created.files.push('.claude/helpers/statusline.cjs');
1371
- }
1372
- /**
1373
- * Write runtime configuration (.claude-flow/)
1374
- */
1375
- async function writeRuntimeConfig(targetDir, options, result) {
1376
- const configPath = path.join(targetDir, '.claude-flow', 'config.yaml');
1377
- if (fs.existsSync(configPath) && !options.force) {
1378
- result.skipped.push('.claude-flow/config.yaml');
1379
- return;
1380
- }
1381
- const config = `# RuFlo V3 Runtime Configuration
1382
- # Generated: ${new Date().toISOString()}
1383
-
1384
- version: "3.0.0"
1385
-
1386
- swarm:
1387
- topology: ${options.runtime.topology}
1388
- maxAgents: ${options.runtime.maxAgents}
1389
- autoScale: true
1390
- coordinationStrategy: consensus
1391
-
1392
- memory:
1393
- backend: ${options.runtime.memoryBackend}
1394
- enableHNSW: ${options.runtime.enableHNSW}
1395
- persistPath: .claude-flow/data
1396
- cacheSize: 100
1397
- # ADR-049: Self-Learning Memory
1398
- learningBridge:
1399
- enabled: ${options.runtime.enableLearningBridge ?? options.runtime.enableNeural}
1400
- sonaMode: balanced
1401
- confidenceDecayRate: 0.005
1402
- accessBoostAmount: 0.03
1403
- consolidationThreshold: 10
1404
- memoryGraph:
1405
- enabled: ${options.runtime.enableMemoryGraph ?? true}
1406
- pageRankDamping: 0.85
1407
- maxNodes: 5000
1408
- similarityThreshold: 0.8
1409
- agentScopes:
1410
- enabled: ${options.runtime.enableAgentScopes ?? true}
1411
- defaultScope: project
1412
-
1413
- neural:
1414
- enabled: ${options.runtime.enableNeural}
1415
- modelPath: .claude-flow/neural
1416
-
1417
- hooks:
1418
- enabled: true
1419
- autoExecute: true
1420
-
1421
- mcp:
1422
- autoStart: ${options.mcp.autoStart}
1423
- port: ${options.mcp.port}
1424
- `;
1425
- fs.writeFileSync(configPath, config, 'utf-8');
1426
- result.created.files.push('.claude-flow/config.yaml');
1427
- // Write .gitignore
1428
- const gitignorePath = path.join(targetDir, '.claude-flow', '.gitignore');
1429
- const gitignore = `# Claude Flow runtime files
1430
- data/
1431
- logs/
1432
- sessions/
1433
- neural/
1434
- *.log
1435
- *.tmp
1436
- `;
1437
- if (!fs.existsSync(gitignorePath) || options.force) {
1438
- fs.writeFileSync(gitignorePath, gitignore, 'utf-8');
1439
- result.created.files.push('.claude-flow/.gitignore');
1440
- }
1441
- // Write CAPABILITIES.md with full system overview
1442
- await writeCapabilitiesDoc(targetDir, options, result);
1443
- }
1444
- /**
1445
- * Write initial metrics files for statusline
1446
- * Creates baseline data so statusline shows meaningful state instead of all zeros
1447
- */
1448
- async function writeInitialMetrics(targetDir, options, result) {
1449
- const metricsDir = path.join(targetDir, '.claude-flow', 'metrics');
1450
- const learningDir = path.join(targetDir, '.claude-flow', 'learning');
1451
- const securityDir = path.join(targetDir, '.claude-flow', 'security');
1452
- // Ensure directories exist
1453
- for (const dir of [metricsDir, learningDir, securityDir]) {
1454
- if (!fs.existsSync(dir)) {
1455
- fs.mkdirSync(dir, { recursive: true });
1456
- }
1457
- }
1458
- // Create initial v3-progress.json
1459
- const progressPath = path.join(metricsDir, 'v3-progress.json');
1460
- if (!fs.existsSync(progressPath) || options.force) {
1461
- const progress = {
1462
- version: '3.0.0',
1463
- initialized: new Date().toISOString(),
1464
- domains: {
1465
- completed: 0,
1466
- total: 5,
1467
- status: 'INITIALIZING'
1468
- },
1469
- ddd: {
1470
- progress: 0,
1471
- modules: 0,
1472
- totalFiles: 0,
1473
- totalLines: 0
1474
- },
1475
- swarm: {
1476
- activeAgents: 0,
1477
- maxAgents: options.runtime.maxAgents,
1478
- topology: options.runtime.topology
1479
- },
1480
- learning: {
1481
- status: 'READY',
1482
- patternsLearned: 0,
1483
- sessionsCompleted: 0
1484
- },
1485
- _note: 'Metrics will update as you use Ruflo. Run: npx ruflo@latest daemon start'
1486
- };
1487
- fs.writeFileSync(progressPath, JSON.stringify(progress, null, 2), 'utf-8');
1488
- result.created.files.push('.claude-flow/metrics/v3-progress.json');
1489
- }
1490
- // Create initial swarm-activity.json
1491
- const activityPath = path.join(metricsDir, 'swarm-activity.json');
1492
- if (!fs.existsSync(activityPath) || options.force) {
1493
- const activity = {
1494
- timestamp: new Date().toISOString(),
1495
- processes: {
1496
- agentic_flow: 0,
1497
- mcp_server: 0,
1498
- estimated_agents: 0
1499
- },
1500
- swarm: {
1501
- active: false,
1502
- agent_count: 0,
1503
- coordination_active: false
1504
- },
1505
- integration: {
1506
- agentic_flow_active: false,
1507
- mcp_active: false
1508
- },
1509
- _initialized: true
1510
- };
1511
- fs.writeFileSync(activityPath, JSON.stringify(activity, null, 2), 'utf-8');
1512
- result.created.files.push('.claude-flow/metrics/swarm-activity.json');
1513
- }
1514
- // Create initial learning.json
1515
- const learningPath = path.join(metricsDir, 'learning.json');
1516
- if (!fs.existsSync(learningPath) || options.force) {
1517
- const learning = {
1518
- initialized: new Date().toISOString(),
1519
- routing: {
1520
- accuracy: 0,
1521
- decisions: 0
1522
- },
1523
- patterns: {
1524
- shortTerm: 0,
1525
- longTerm: 0,
1526
- quality: 0
1527
- },
1528
- sessions: {
1529
- total: 0,
1530
- current: null
1531
- },
1532
- _note: 'Intelligence grows as you use Ruflo'
1533
- };
1534
- fs.writeFileSync(learningPath, JSON.stringify(learning, null, 2), 'utf-8');
1535
- result.created.files.push('.claude-flow/metrics/learning.json');
1536
- }
1537
- // Create initial audit-status.json
1538
- const auditPath = path.join(securityDir, 'audit-status.json');
1539
- if (!fs.existsSync(auditPath) || options.force) {
1540
- const audit = {
1541
- initialized: new Date().toISOString(),
1542
- status: 'PENDING',
1543
- cvesFixed: 0,
1544
- totalCves: 3,
1545
- lastScan: null,
1546
- _note: 'Run: npx @claude-flow/cli@latest security scan'
1547
- };
1548
- fs.writeFileSync(auditPath, JSON.stringify(audit, null, 2), 'utf-8');
1549
- result.created.files.push('.claude-flow/security/audit-status.json');
1550
- }
1551
- }
1552
- /**
1553
- * Write CAPABILITIES.md - comprehensive overview of all Ruflo features
1554
- */
1555
- async function writeCapabilitiesDoc(targetDir, options, result) {
1556
- const capabilitiesPath = path.join(targetDir, '.claude-flow', 'CAPABILITIES.md');
1557
- if (fs.existsSync(capabilitiesPath) && !options.force) {
1558
- result.skipped.push('.claude-flow/CAPABILITIES.md');
1559
- return;
1560
- }
1561
- const capabilities = `# RuFlo V3 - Complete Capabilities Reference
1562
- > Generated: ${new Date().toISOString()}
1563
- > Full documentation: https://github.com/ruvnet/claude-flow
1564
-
1565
- ## 📋 Table of Contents
1566
-
1567
- 1. [Overview](#overview)
1568
- 2. [Swarm Orchestration](#swarm-orchestration)
1569
- 3. [Available Agents (60+)](#available-agents)
1570
- 4. [CLI Commands (26 Commands, 140+ Subcommands)](#cli-commands)
1571
- 5. [Hooks System (27 Hooks + 12 Workers)](#hooks-system)
1572
- 6. [Memory & Intelligence (RuVector)](#memory--intelligence)
1573
- 7. [Hive-Mind Consensus](#hive-mind-consensus)
1574
- 8. [Performance Targets](#performance-targets)
1575
- 9. [Integration Ecosystem](#integration-ecosystem)
1576
-
1577
- ---
1578
-
1579
- ## Overview
1580
-
1581
- RuFlo V3 is a domain-driven design architecture for multi-agent AI coordination with:
1582
-
1583
- - **15-Agent Swarm Coordination** with hierarchical and mesh topologies
1584
- - **HNSW Vector Search** - 150x-12,500x faster pattern retrieval
1585
- - **SONA Neural Learning** - Self-optimizing with <0.05ms adaptation
1586
- - **Byzantine Fault Tolerance** - Queen-led consensus mechanisms
1587
- - **MCP Server Integration** - Model Context Protocol support
1588
-
1589
- ### Current Configuration
1590
- | Setting | Value |
1591
- |---------|-------|
1592
- | Topology | ${options.runtime.topology} |
1593
- | Max Agents | ${options.runtime.maxAgents} |
1594
- | Memory Backend | ${options.runtime.memoryBackend} |
1595
- | HNSW Indexing | ${options.runtime.enableHNSW ? 'Enabled' : 'Disabled'} |
1596
- | Neural Learning | ${options.runtime.enableNeural ? 'Enabled' : 'Disabled'} |
1597
- | LearningBridge | ${options.runtime.enableLearningBridge ? 'Enabled (SONA + ReasoningBank)' : 'Disabled'} |
1598
- | Knowledge Graph | ${options.runtime.enableMemoryGraph ? 'Enabled (PageRank + Communities)' : 'Disabled'} |
1599
- | Agent Scopes | ${options.runtime.enableAgentScopes ? 'Enabled (project/local/user)' : 'Disabled'} |
1600
-
1601
- ---
1602
-
1603
- ## Swarm Orchestration
1604
-
1605
- ### Topologies
1606
- | Topology | Description | Best For |
1607
- |----------|-------------|----------|
1608
- | \`hierarchical\` | Queen controls workers directly | Anti-drift, tight control |
1609
- | \`mesh\` | Fully connected peer network | Distributed tasks |
1610
- | \`hierarchical-mesh\` | V3 hybrid (recommended) | 10+ agents |
1611
- | \`ring\` | Circular communication | Sequential workflows |
1612
- | \`star\` | Central coordinator | Simple coordination |
1613
- | \`adaptive\` | Dynamic based on load | Variable workloads |
1614
-
1615
- ### Strategies
1616
- - \`balanced\` - Even distribution across agents
1617
- - \`specialized\` - Clear roles, no overlap (anti-drift)
1618
- - \`adaptive\` - Dynamic task routing
1619
-
1620
- ### Quick Commands
1621
- \`\`\`bash
1622
- # Initialize swarm
1623
- npx @claude-flow/cli@latest swarm init --topology hierarchical --max-agents 8 --strategy specialized
1624
-
1625
- # Check status
1626
- npx @claude-flow/cli@latest swarm status
1627
-
1628
- # Monitor activity
1629
- npx @claude-flow/cli@latest swarm monitor
1630
- \`\`\`
1631
-
1632
- ---
1633
-
1634
- ## Available Agents
1635
-
1636
- ### Core Development (5)
1637
- \`coder\`, \`reviewer\`, \`tester\`, \`planner\`, \`researcher\`
1638
-
1639
- ### V3 Specialized (4)
1640
- \`security-architect\`, \`security-auditor\`, \`memory-specialist\`, \`performance-engineer\`
1641
-
1642
- ### Swarm Coordination (5)
1643
- \`hierarchical-coordinator\`, \`mesh-coordinator\`, \`adaptive-coordinator\`, \`collective-intelligence-coordinator\`, \`swarm-memory-manager\`
1644
-
1645
- ### Consensus & Distributed (7)
1646
- \`byzantine-coordinator\`, \`raft-manager\`, \`gossip-coordinator\`, \`consensus-builder\`, \`crdt-synchronizer\`, \`quorum-manager\`, \`security-manager\`
1647
-
1648
- ### Performance & Optimization (5)
1649
- \`perf-analyzer\`, \`performance-benchmarker\`, \`task-orchestrator\`, \`memory-coordinator\`, \`smart-agent\`
1650
-
1651
- ### GitHub & Repository (9)
1652
- \`github-modes\`, \`pr-manager\`, \`code-review-swarm\`, \`issue-tracker\`, \`release-manager\`, \`workflow-automation\`, \`project-board-sync\`, \`repo-architect\`, \`multi-repo-swarm\`
1653
-
1654
- ### SPARC Methodology (6)
1655
- \`sparc-coord\`, \`sparc-coder\`, \`specification\`, \`pseudocode\`, \`architecture\`, \`refinement\`
1656
-
1657
- ### Specialized Development (8)
1658
- \`backend-dev\`, \`mobile-dev\`, \`ml-developer\`, \`cicd-engineer\`, \`api-docs\`, \`system-architect\`, \`code-analyzer\`, \`base-template-generator\`
1659
-
1660
- ### Testing & Validation (2)
1661
- \`tdd-london-swarm\`, \`production-validator\`
1662
-
1663
- ### Agent Routing by Task
1664
- | Task Type | Recommended Agents | Topology |
1665
- |-----------|-------------------|----------|
1666
- | Bug Fix | researcher, coder, tester | mesh |
1667
- | New Feature | coordinator, architect, coder, tester, reviewer | hierarchical |
1668
- | Refactoring | architect, coder, reviewer | mesh |
1669
- | Performance | researcher, perf-engineer, coder | hierarchical |
1670
- | Security | security-architect, auditor, reviewer | hierarchical |
1671
- | Docs | researcher, api-docs | mesh |
1672
-
1673
- ---
1674
-
1675
- ## CLI Commands
1676
-
1677
- ### Core Commands (12)
1678
- | Command | Subcommands | Description |
1679
- |---------|-------------|-------------|
1680
- | \`init\` | 4 | Project initialization |
1681
- | \`agent\` | 8 | Agent lifecycle management |
1682
- | \`swarm\` | 6 | Multi-agent coordination |
1683
- | \`memory\` | 11 | AgentDB with HNSW search |
1684
- | \`mcp\` | 9 | MCP server management |
1685
- | \`task\` | 6 | Task assignment |
1686
- | \`session\` | 7 | Session persistence |
1687
- | \`config\` | 7 | Configuration |
1688
- | \`status\` | 3 | System monitoring |
1689
- | \`workflow\` | 6 | Workflow templates |
1690
- | \`hooks\` | 17 | Self-learning hooks |
1691
- | \`hive-mind\` | 6 | Consensus coordination |
1692
-
1693
- ### Advanced Commands (14)
1694
- | Command | Subcommands | Description |
1695
- |---------|-------------|-------------|
1696
- | \`daemon\` | 5 | Background workers |
1697
- | \`neural\` | 5 | Pattern training |
1698
- | \`security\` | 6 | Security scanning |
1699
- | \`performance\` | 5 | Profiling & benchmarks |
1700
- | \`providers\` | 5 | AI provider config |
1701
- | \`plugins\` | 5 | Plugin management |
1702
- | \`deployment\` | 5 | Deploy management |
1703
- | \`embeddings\` | 4 | Vector embeddings |
1704
- | \`claims\` | 4 | Authorization |
1705
- | \`migrate\` | 5 | V2→V3 migration |
1706
- | \`process\` | 4 | Process management |
1707
- | \`doctor\` | 1 | Health diagnostics |
1708
- | \`completions\` | 4 | Shell completions |
1709
-
1710
- ### Example Commands
1711
- \`\`\`bash
1712
- # Initialize
1713
- npx @claude-flow/cli@latest init --wizard
1714
-
1715
- # Spawn agent
1716
- npx @claude-flow/cli@latest agent spawn -t coder --name my-coder
1717
-
1718
- # Memory operations
1719
- npx @claude-flow/cli@latest memory store --key "pattern" --value "data" --namespace patterns
1720
- npx @claude-flow/cli@latest memory search --query "authentication"
1721
-
1722
- # Diagnostics
1723
- npx @claude-flow/cli@latest doctor --fix
1724
- \`\`\`
1725
-
1726
- ---
1727
-
1728
- ## Hooks System
1729
-
1730
- ### 27 Available Hooks
1731
-
1732
- #### Core Hooks (6)
1733
- | Hook | Description |
1734
- |------|-------------|
1735
- | \`pre-edit\` | Context before file edits |
1736
- | \`post-edit\` | Record edit outcomes |
1737
- | \`pre-command\` | Risk assessment |
1738
- | \`post-command\` | Command metrics |
1739
- | \`pre-task\` | Task start + agent suggestions |
1740
- | \`post-task\` | Task completion learning |
1741
-
1742
- #### Session Hooks (4)
1743
- | Hook | Description |
1744
- |------|-------------|
1745
- | \`session-start\` | Start/restore session |
1746
- | \`session-end\` | Persist state |
1747
- | \`session-restore\` | Restore previous |
1748
- | \`notify\` | Cross-agent notifications |
1749
-
1750
- #### Intelligence Hooks (5)
1751
- | Hook | Description |
1752
- |------|-------------|
1753
- | \`route\` | Optimal agent routing |
1754
- | \`explain\` | Routing decisions |
1755
- | \`pretrain\` | Bootstrap intelligence |
1756
- | \`build-agents\` | Generate configs |
1757
- | \`transfer\` | Pattern transfer |
1758
-
1759
- #### Coverage Hooks (3)
1760
- | Hook | Description |
1761
- |------|-------------|
1762
- | \`coverage-route\` | Coverage-based routing |
1763
- | \`coverage-suggest\` | Improvement suggestions |
1764
- | \`coverage-gaps\` | Gap analysis |
1765
-
1766
- ### 12 Background Workers
1767
- | Worker | Priority | Purpose |
1768
- |--------|----------|---------|
1769
- | \`ultralearn\` | normal | Deep knowledge |
1770
- | \`optimize\` | high | Performance |
1771
- | \`consolidate\` | low | Memory consolidation |
1772
- | \`predict\` | normal | Predictive preload |
1773
- | \`audit\` | critical | Security |
1774
- | \`map\` | normal | Codebase mapping |
1775
- | \`preload\` | low | Resource preload |
1776
- | \`deepdive\` | normal | Deep analysis |
1777
- | \`document\` | normal | Auto-docs |
1778
- | \`refactor\` | normal | Suggestions |
1779
- | \`benchmark\` | normal | Benchmarking |
1780
- | \`testgaps\` | normal | Coverage gaps |
1781
-
1782
- ---
1783
-
1784
- ## Memory & Intelligence
1785
-
1786
- ### RuVector Intelligence System
1787
- - **SONA**: Self-Optimizing Neural Architecture (<0.05ms)
1788
- - **MoE**: Mixture of Experts routing
1789
- - **HNSW**: 150x-12,500x faster search
1790
- - **EWC++**: Prevents catastrophic forgetting
1791
- - **Flash Attention**: 2.49x-7.47x speedup
1792
- - **Int8 Quantization**: 3.92x memory reduction
1793
-
1794
- ### 4-Step Intelligence Pipeline
1795
- 1. **RETRIEVE** - HNSW pattern search
1796
- 2. **JUDGE** - Success/failure verdicts
1797
- 3. **DISTILL** - LoRA learning extraction
1798
- 4. **CONSOLIDATE** - EWC++ preservation
1799
-
1800
- ### Self-Learning Memory (ADR-049)
1801
-
1802
- | Component | Status | Description |
1803
- |-----------|--------|-------------|
1804
- | **LearningBridge** | ${options.runtime.enableLearningBridge ? '✅ Enabled' : '⏸ Disabled'} | Connects insights to SONA/ReasoningBank neural pipeline |
1805
- | **MemoryGraph** | ${options.runtime.enableMemoryGraph ? '✅ Enabled' : '⏸ Disabled'} | PageRank knowledge graph + community detection |
1806
- | **AgentMemoryScope** | ${options.runtime.enableAgentScopes ? '✅ Enabled' : '⏸ Disabled'} | 3-scope agent memory (project/local/user) |
1807
-
1808
- **LearningBridge** - Insights trigger learning trajectories. Confidence evolves: +0.03 on access, -0.005/hour decay. Consolidation runs the JUDGE/DISTILL/CONSOLIDATE pipeline.
1809
-
1810
- **MemoryGraph** - Builds a knowledge graph from entry references. PageRank identifies influential insights. Communities group related knowledge. Graph-aware ranking blends vector + structural scores.
1811
-
1812
- **AgentMemoryScope** - Maps Claude Code 3-scope directories:
1813
- - \`project\`: \`<gitRoot>/.claude/agent-memory/<agent>/\`
1814
- - \`local\`: \`<gitRoot>/.claude/agent-memory-local/<agent>/\`
1815
- - \`user\`: \`~/.claude/agent-memory/<agent>/\`
1816
-
1817
- High-confidence insights (>0.8) can transfer between agents.
1818
-
1819
- ### Memory Commands
1820
- \`\`\`bash
1821
- # Store pattern
1822
- npx @claude-flow/cli@latest memory store --key "name" --value "data" --namespace patterns
1823
-
1824
- # Semantic search
1825
- npx @claude-flow/cli@latest memory search --query "authentication"
1826
-
1827
- # List entries
1828
- npx @claude-flow/cli@latest memory list --namespace patterns
1829
-
1830
- # Initialize database
1831
- npx @claude-flow/cli@latest memory init --force
1832
- \`\`\`
1833
-
1834
- ---
1835
-
1836
- ## Hive-Mind Consensus
1837
-
1838
- ### Queen Types
1839
- | Type | Role |
1840
- |------|------|
1841
- | Strategic Queen | Long-term planning |
1842
- | Tactical Queen | Execution coordination |
1843
- | Adaptive Queen | Dynamic optimization |
1844
-
1845
- ### Worker Types (8)
1846
- \`researcher\`, \`coder\`, \`analyst\`, \`tester\`, \`architect\`, \`reviewer\`, \`optimizer\`, \`documenter\`
1847
-
1848
- ### Consensus Mechanisms
1849
- | Mechanism | Fault Tolerance | Use Case |
1850
- |-----------|-----------------|----------|
1851
- | \`byzantine\` | f < n/3 faulty | Adversarial |
1852
- | \`raft\` | f < n/2 failed | Leader-based |
1853
- | \`gossip\` | Eventually consistent | Large scale |
1854
- | \`crdt\` | Conflict-free | Distributed |
1855
- | \`quorum\` | Configurable | Flexible |
1856
-
1857
- ### Hive-Mind Commands
1858
- \`\`\`bash
1859
- # Initialize
1860
- npx @claude-flow/cli@latest hive-mind init --queen-type strategic
1861
-
1862
- # Status
1863
- npx @claude-flow/cli@latest hive-mind status
1864
-
1865
- # Spawn workers
1866
- npx @claude-flow/cli@latest hive-mind spawn --count 5 --type worker
1867
-
1868
- # Consensus
1869
- npx @claude-flow/cli@latest hive-mind consensus --propose "task"
1870
- \`\`\`
1871
-
1872
- ---
1873
-
1874
- ## Performance Targets
1875
-
1876
- | Metric | Target | Status |
1877
- |--------|--------|--------|
1878
- | HNSW Search | 150x-12,500x faster | ✅ Implemented |
1879
- | Memory Reduction | 50-75% | ✅ Implemented (3.92x) |
1880
- | SONA Integration | Pattern learning | ✅ Implemented |
1881
- | Flash Attention | 2.49x-7.47x | 🔄 In Progress |
1882
- | MCP Response | <100ms | ✅ Achieved |
1883
- | CLI Startup | <500ms | ✅ Achieved |
1884
- | SONA Adaptation | <0.05ms | 🔄 In Progress |
1885
- | Graph Build (1k) | <200ms | ✅ 2.78ms (71.9x headroom) |
1886
- | PageRank (1k) | <100ms | ✅ 12.21ms (8.2x headroom) |
1887
- | Insight Recording | <5ms/each | ✅ 0.12ms (41x headroom) |
1888
- | Consolidation | <500ms | ✅ 0.26ms (1,955x headroom) |
1889
- | Knowledge Transfer | <100ms | ✅ 1.25ms (80x headroom) |
1890
-
1891
- ---
1892
-
1893
- ## Integration Ecosystem
1894
-
1895
- ### Integrated Packages
1896
- | Package | Version | Purpose |
1897
- |---------|---------|---------|
1898
- | agentic-flow | 3.0.0-alpha.1 | Core coordination + ReasoningBank + Router |
1899
- | agentdb | 3.0.0-alpha.10 | Vector database + 8 controllers |
1900
- | @ruvector/attention | 0.1.3 | Flash attention |
1901
- | @ruvector/sona | 0.1.5 | Neural learning |
1902
-
1903
- ### Optional Integrations
1904
- | Package | Command |
1905
- |---------|---------|
1906
- | ruv-swarm | \`npx ruv-swarm mcp start\` |
1907
- | flow-nexus | \`npx flow-nexus@latest mcp start\` |
1908
- | agentic-jujutsu | \`npx agentic-jujutsu@latest\` |
1909
-
1910
- ### MCP Server Setup
1911
- \`\`\`bash
1912
- # Add Ruflo MCP
1913
- claude mcp add ruflo -- npx -y ruflo@latest mcp start
1914
-
1915
- # Optional servers
1916
- claude mcp add ruv-swarm -- npx -y ruv-swarm mcp start
1917
- claude mcp add flow-nexus -- npx -y flow-nexus@latest mcp start
1918
- \`\`\`
1919
-
1920
- ---
1921
-
1922
- ## Quick Reference
1923
-
1924
- ### Essential Commands
1925
- \`\`\`bash
1926
- # Setup
1927
- npx ruflo@latest init --wizard
1928
- npx ruflo@latest daemon start
1929
- npx ruflo@latest doctor --fix
1930
-
1931
- # Swarm
1932
- npx ruflo@latest swarm init --topology hierarchical --max-agents 8
1933
- npx ruflo@latest swarm status
1934
-
1935
- # Agents
1936
- npx ruflo@latest agent spawn -t coder
1937
- npx ruflo@latest agent list
1938
-
1939
- # Memory
1940
- npx ruflo@latest memory search --query "patterns"
1941
-
1942
- # Hooks
1943
- npx ruflo@latest hooks pre-task --description "task"
1944
- npx ruflo@latest hooks worker dispatch --trigger optimize
1945
- \`\`\`
1946
-
1947
- ### File Structure
1948
- \`\`\`
1949
- .claude-flow/
1950
- ├── config.yaml # Runtime configuration
1951
- ├── CAPABILITIES.md # This file
1952
- ├── data/ # Memory storage
1953
- ├── logs/ # Operation logs
1954
- ├── sessions/ # Session state
1955
- ├── hooks/ # Custom hooks
1956
- ├── agents/ # Agent configs
1957
- └── workflows/ # Workflow templates
1958
- \`\`\`
1959
-
1960
- ---
1961
-
1962
- **Full Documentation**: https://github.com/ruvnet/claude-flow
1963
- **Issues**: https://github.com/ruvnet/claude-flow/issues
1964
- `;
1965
- fs.writeFileSync(capabilitiesPath, capabilities, 'utf-8');
1966
- result.created.files.push('.claude-flow/CAPABILITIES.md');
1967
- }
1968
- /**
1969
- * Write CLAUDE.md with swarm guidance
1970
- */
1971
- async function writeClaudeMd(targetDir, options, result) {
1972
- const claudeMdPath = path.join(targetDir, 'CLAUDE.md');
1973
- if (fs.existsSync(claudeMdPath) && !options.force) {
1974
- result.skipped.push('CLAUDE.md');
1975
- }
1976
- else {
1977
- // #2208: if overwriting an existing CLAUDE.md (force mode), back it up first so
1978
- // users don't silently lose curated project context.
1979
- if (fs.existsSync(claudeMdPath)) {
1980
- const backupBase = `${claudeMdPath}.pre-ruflo`;
1981
- // Don't clobber an existing backup — append a timestamp if one already exists.
1982
- const backupPath = fs.existsSync(backupBase)
1983
- ? `${backupBase}.${Date.now()}`
1984
- : backupBase;
1985
- fs.copyFileSync(claudeMdPath, backupPath);
1986
- result.created.files.push(path.basename(backupPath));
1987
- console.warn(`[ruflo init] Existing CLAUDE.md backed up to ${path.basename(backupPath)} before overwrite`);
1988
- }
1989
- // Determine template: explicit option > infer from components > 'standard'
1990
- const inferredTemplate = (!options.components.commands && !options.components.agents) ? 'minimal' : undefined;
1991
- const content = generateClaudeMd(options, inferredTemplate);
1992
- fs.writeFileSync(claudeMdPath, content, 'utf-8');
1993
- result.created.files.push('CLAUDE.md');
1994
- }
1995
- // Also write/append global ~/.claude/CLAUDE.md so ruflo tools are used automatically (#1497).
1996
- // Opt-out via --no-global / options.skipGlobalClaudeMd (#1744 — keeps global rules file pristine
1997
- // for users who don't want a per-machine pointer block).
1998
- const homeDir = process.env.HOME || process.env.USERPROFILE || '';
1999
- if (homeDir && !options.skipGlobalClaudeMd) {
2000
- const globalClaudeDir = path.join(homeDir, '.claude');
2001
- const globalClaudeMd = path.join(globalClaudeDir, 'CLAUDE.md');
2002
- const rufloBlock = [
2003
- '',
2004
- '# Ruflo Integration (auto-generated by ruflo init)',
2005
- 'When working on multi-file tasks or complex features, use ToolSearch to find and invoke ruflo MCP tools.',
2006
- 'Key tools: memory_store, memory_search, hooks_route, swarm_init, agent_spawn.',
2007
- 'Check system-reminder tags for [INTELLIGENCE] pattern suggestions before starting work.',
2008
- '',
2009
- ].join('\n');
2010
- try {
2011
- if (!fs.existsSync(globalClaudeDir)) {
2012
- fs.mkdirSync(globalClaudeDir, { recursive: true });
2013
- }
2014
- if (fs.existsSync(globalClaudeMd)) {
2015
- const existing = fs.readFileSync(globalClaudeMd, 'utf-8');
2016
- if (!existing.includes('Ruflo Integration')) {
2017
- fs.appendFileSync(globalClaudeMd, rufloBlock);
2018
- result.created.files.push('~/.claude/CLAUDE.md (appended ruflo block)');
2019
- }
2020
- }
2021
- else {
2022
- fs.writeFileSync(globalClaudeMd, rufloBlock.trimStart(), 'utf-8');
2023
- result.created.files.push('~/.claude/CLAUDE.md');
2024
- }
2025
- }
2026
- catch {
2027
- // Non-critical — global CLAUDE.md is best-effort
2028
- }
2029
- }
2030
- else if (options.skipGlobalClaudeMd) {
2031
- result.skipped.push('~/.claude/CLAUDE.md (--no-global)');
2032
- }
2033
- }
2034
- /**
2035
- * Find source directory for skills/commands/agents
2036
- */
2037
- function findSourceDir(type, sourceBaseDir) {
2038
- // Build list of possible paths to check
2039
- const possiblePaths = [];
2040
- // If explicit source base directory is provided, use it first
2041
- if (sourceBaseDir) {
2042
- possiblePaths.push(path.join(sourceBaseDir, '.claude', type));
2043
- }
2044
- // IMPORTANT: Check the package's own .claude directory first
2045
- // This is the primary path when running as an npm package
2046
- // __dirname is typically /path/to/node_modules/@claude-flow/cli/dist/src/init
2047
- // We need to go up 3 levels to reach the package root (dist/src/init -> dist/src -> dist -> root)
2048
- const packageRoot = path.resolve(__dirname, '..', '..', '..');
2049
- const packageDotClaude = path.join(packageRoot, '.claude', type);
2050
- if (fs.existsSync(packageDotClaude)) {
2051
- possiblePaths.unshift(packageDotClaude); // Add to beginning (highest priority)
2052
- }
2053
- // From dist/src/init -> go up to project root
2054
- const distPath = __dirname;
2055
- // Try to find the project root by looking for .claude directory
2056
- let currentDir = distPath;
2057
- for (let i = 0; i < 10; i++) {
2058
- const parentDir = path.dirname(currentDir);
2059
- const dotClaudePath = path.join(parentDir, '.claude', type);
2060
- if (fs.existsSync(dotClaudePath)) {
2061
- possiblePaths.push(dotClaudePath);
2062
- }
2063
- currentDir = parentDir;
2064
- }
2065
- // Also check relative to process.cwd() for development
2066
- const cwdBased = [
2067
- path.join(process.cwd(), '.claude', type),
2068
- path.join(process.cwd(), '..', '.claude', type),
2069
- path.join(process.cwd(), '..', '..', '.claude', type),
2070
- ];
2071
- possiblePaths.push(...cwdBased);
2072
- // Check v2 directory for agents
2073
- if (type === 'agents') {
2074
- possiblePaths.push(path.join(process.cwd(), 'v2', '.claude', type), path.join(process.cwd(), '..', 'v2', '.claude', type));
2075
- }
2076
- // Plugin directory
2077
- possiblePaths.push(path.join(process.cwd(), 'plugin', type), path.join(process.cwd(), '..', 'plugin', type));
2078
- for (const p of possiblePaths) {
2079
- if (fs.existsSync(p)) {
2080
- return p;
2081
- }
2082
- }
2083
- return null;
2084
- }
2085
- /**
2086
- * Copy directory recursively
2087
- */
2088
- function copyDirRecursive(src, dest) {
2089
- fs.mkdirSync(dest, { recursive: true });
2090
- const entries = fs.readdirSync(src, { withFileTypes: true });
2091
- for (const entry of entries) {
2092
- const srcPath = path.join(src, entry.name);
2093
- const destPath = path.join(dest, entry.name);
2094
- if (entry.isDirectory()) {
2095
- copyDirRecursive(srcPath, destPath);
2096
- }
2097
- else {
2098
- fs.copyFileSync(srcPath, destPath);
2099
- }
2100
- }
2101
- }
2102
- /**
2103
- * Count files with extension in directory
2104
- */
2105
- function countFiles(dir, ext) {
2106
- let count = 0;
2107
- const entries = fs.readdirSync(dir, { withFileTypes: true });
2108
- for (const entry of entries) {
2109
- const fullPath = path.join(dir, entry.name);
2110
- if (entry.isDirectory()) {
2111
- count += countFiles(fullPath, ext);
2112
- }
2113
- else if (entry.name.endsWith(ext)) {
2114
- count++;
2115
- }
2116
- }
2117
- return count;
2118
- }
2119
- /**
2120
- * Count enabled hooks
2121
- */
2122
- function countEnabledHooks(options) {
2123
- const hooks = options.hooks;
2124
- let count = 0;
2125
- if (hooks.preToolUse)
2126
- count++;
2127
- if (hooks.postToolUse)
2128
- count++;
2129
- if (hooks.userPromptSubmit)
2130
- count++;
2131
- if (hooks.sessionStart)
2132
- count++;
2133
- if (hooks.stop)
2134
- count++;
2135
- if (hooks.preCompact)
2136
- count++;
2137
- if (hooks.notification)
2138
- count++;
2139
- return count;
2140
- }
2141
- export default executeInit;
2142
- //# sourceMappingURL=executor.js.map