moflo 4.8.49 → 4.8.51

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 (439) hide show
  1. package/.claude/guidance/shipped/moflo-core-guidance.md +646 -646
  2. package/bin/cli.js +1 -1
  3. package/bin/hooks.mjs +607 -607
  4. package/bin/index-all.mjs +2 -2
  5. package/bin/session-start-launcher.mjs +272 -272
  6. package/package.json +22 -23
  7. package/src/{@claude-flow → packages}/cli/dist/src/init/claudemd-generator.js +45 -45
  8. package/src/{@claude-flow → packages}/cli/dist/src/init/executor.js +0 -4
  9. package/src/{@claude-flow → packages}/cli/dist/src/init/moflo-init.js +764 -764
  10. package/src/{@claude-flow → packages}/cli/dist/src/version.js +1 -1
  11. package/src/{@claude-flow → packages}/cli/package.json +1 -1
  12. package/.claude/agents/dual-mode/codex-coordinator.md +0 -224
  13. package/.claude/agents/dual-mode/codex-worker.md +0 -211
  14. package/.claude/agents/dual-mode/dual-orchestrator.md +0 -291
  15. package/.claude/agents/payments/agentic-payments.md +0 -126
  16. package/.claude/agents/sublinear/consensus-coordinator.md +0 -338
  17. package/.claude/agents/sublinear/matrix-optimizer.md +0 -185
  18. package/.claude/agents/sublinear/pagerank-analyzer.md +0 -299
  19. package/.claude/agents/sublinear/performance-optimizer.md +0 -368
  20. package/.claude/agents/sublinear/trading-predictor.md +0 -246
  21. package/.claude/agents/templates/automation-smart-agent.md +0 -205
  22. package/.claude/agents/templates/coordinator-swarm-init.md +0 -105
  23. package/.claude/agents/templates/github-pr-manager.md +0 -177
  24. package/.claude/agents/templates/implementer-sparc-coder.md +0 -259
  25. package/.claude/agents/templates/memory-coordinator.md +0 -187
  26. package/.claude/agents/templates/migration-plan.md +0 -746
  27. package/.claude/agents/templates/orchestrator-task.md +0 -139
  28. package/.claude/agents/templates/performance-analyzer.md +0 -199
  29. package/.claude/agents/templates/sparc-coordinator.md +0 -183
  30. package/.claude/commands/agents/README.md +0 -10
  31. package/.claude/commands/agents/agent-capabilities.md +0 -21
  32. package/.claude/commands/agents/agent-coordination.md +0 -28
  33. package/.claude/commands/agents/agent-spawning.md +0 -28
  34. package/.claude/commands/agents/agent-types.md +0 -26
  35. package/.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md +0 -54
  36. package/.claude/commands/analysis/README.md +0 -9
  37. package/.claude/commands/analysis/bottleneck-detect.md +0 -162
  38. package/.claude/commands/analysis/performance-bottlenecks.md +0 -59
  39. package/.claude/commands/analysis/performance-report.md +0 -25
  40. package/.claude/commands/analysis/token-efficiency.md +0 -45
  41. package/.claude/commands/analysis/token-usage.md +0 -25
  42. package/.claude/commands/automation/README.md +0 -9
  43. package/.claude/commands/automation/auto-agent.md +0 -122
  44. package/.claude/commands/automation/self-healing.md +0 -106
  45. package/.claude/commands/automation/session-memory.md +0 -90
  46. package/.claude/commands/automation/smart-agents.md +0 -73
  47. package/.claude/commands/automation/smart-spawn.md +0 -25
  48. package/.claude/commands/automation/workflow-select.md +0 -25
  49. package/.claude/commands/monitoring/README.md +0 -9
  50. package/.claude/commands/monitoring/agent-metrics.md +0 -25
  51. package/.claude/commands/monitoring/agents.md +0 -44
  52. package/.claude/commands/monitoring/real-time-view.md +0 -25
  53. package/.claude/commands/monitoring/status.md +0 -46
  54. package/.claude/commands/monitoring/swarm-monitor.md +0 -25
  55. package/.claude/commands/optimization/README.md +0 -9
  56. package/.claude/commands/optimization/auto-topology.md +0 -62
  57. package/.claude/commands/optimization/cache-manage.md +0 -25
  58. package/.claude/commands/optimization/parallel-execute.md +0 -25
  59. package/.claude/commands/optimization/parallel-execution.md +0 -50
  60. package/.claude/commands/optimization/topology-optimize.md +0 -25
  61. package/.claude/scripts/build-embeddings.mjs +0 -549
  62. package/.claude/scripts/generate-code-map.mjs +0 -956
  63. package/.claude/scripts/hooks.mjs +0 -607
  64. package/.claude/scripts/index-all.mjs +0 -193
  65. package/.claude/scripts/index-guidance.mjs +0 -917
  66. package/.claude/scripts/index-tests.mjs +0 -729
  67. package/.claude/scripts/lib/moflo-resolve.mjs +0 -14
  68. package/.claude/scripts/lib/process-manager.mjs +0 -256
  69. package/.claude/scripts/lib/registry-cleanup.cjs +0 -41
  70. package/.claude/scripts/semantic-search.mjs +0 -473
  71. package/.claude/scripts/session-start-launcher.mjs +0 -272
  72. package/src/@claude-flow/cli/dist/src/commands/orc.js +0 -767
  73. package/src/@claude-flow/cli/dist/src/services/container-worker-pool.js +0 -584
  74. package/src/@claude-flow/memory/dist/hybrid-backend.js +0 -569
  75. package/src/@claude-flow/memory/dist/hybrid-backend.test.js +0 -320
  76. package/src/@claude-flow/memory/dist/sqlite-backend.js +0 -572
  77. /package/src/{@claude-flow → packages}/cli/README.md +0 -0
  78. /package/src/{@claude-flow → packages}/cli/bin/cli.js +0 -0
  79. /package/src/{@claude-flow → packages}/cli/bin/mcp-server.js +0 -0
  80. /package/src/{@claude-flow → packages}/cli/bin/preinstall.cjs +0 -0
  81. /package/src/{@claude-flow → packages}/cli/dist/src/appliance/gguf-engine.js +0 -0
  82. /package/src/{@claude-flow → packages}/cli/dist/src/appliance/ruvllm-bridge.js +0 -0
  83. /package/src/{@claude-flow → packages}/cli/dist/src/appliance/rvfa-builder.js +0 -0
  84. /package/src/{@claude-flow → packages}/cli/dist/src/appliance/rvfa-distribution.js +0 -0
  85. /package/src/{@claude-flow → packages}/cli/dist/src/appliance/rvfa-format.js +0 -0
  86. /package/src/{@claude-flow → packages}/cli/dist/src/appliance/rvfa-runner.js +0 -0
  87. /package/src/{@claude-flow → packages}/cli/dist/src/appliance/rvfa-signing.js +0 -0
  88. /package/src/{@claude-flow → packages}/cli/dist/src/benchmarks/pretrain/index.js +0 -0
  89. /package/src/{@claude-flow → packages}/cli/dist/src/commands/agent.js +0 -0
  90. /package/src/{@claude-flow → packages}/cli/dist/src/commands/analyze.js +0 -0
  91. /package/src/{@claude-flow → packages}/cli/dist/src/commands/appliance-advanced.js +0 -0
  92. /package/src/{@claude-flow → packages}/cli/dist/src/commands/appliance.js +0 -0
  93. /package/src/{@claude-flow → packages}/cli/dist/src/commands/benchmark.js +0 -0
  94. /package/src/{@claude-flow → packages}/cli/dist/src/commands/claims.js +0 -0
  95. /package/src/{@claude-flow → packages}/cli/dist/src/commands/completions.js +0 -0
  96. /package/src/{@claude-flow → packages}/cli/dist/src/commands/config.js +0 -0
  97. /package/src/{@claude-flow → packages}/cli/dist/src/commands/daemon.js +0 -0
  98. /package/src/{@claude-flow → packages}/cli/dist/src/commands/deployment.js +0 -0
  99. /package/src/{@claude-flow → packages}/cli/dist/src/commands/diagnose.js +0 -0
  100. /package/src/{@claude-flow → packages}/cli/dist/src/commands/doctor.js +0 -0
  101. /package/src/{@claude-flow → packages}/cli/dist/src/commands/embeddings.js +0 -0
  102. /package/src/{@claude-flow → packages}/cli/dist/src/commands/epic.js +0 -0
  103. /package/src/{@claude-flow → packages}/cli/dist/src/commands/gate.js +0 -0
  104. /package/src/{@claude-flow → packages}/cli/dist/src/commands/github.js +0 -0
  105. /package/src/{@claude-flow → packages}/cli/dist/src/commands/guidance.js +0 -0
  106. /package/src/{@claude-flow → packages}/cli/dist/src/commands/hive-mind.js +0 -0
  107. /package/src/{@claude-flow → packages}/cli/dist/src/commands/hooks.js +0 -0
  108. /package/src/{@claude-flow → packages}/cli/dist/src/commands/index.js +0 -0
  109. /package/src/{@claude-flow → packages}/cli/dist/src/commands/init.js +0 -0
  110. /package/src/{@claude-flow → packages}/cli/dist/src/commands/issues.js +0 -0
  111. /package/src/{@claude-flow → packages}/cli/dist/src/commands/mcp.js +0 -0
  112. /package/src/{@claude-flow → packages}/cli/dist/src/commands/memory.js +0 -0
  113. /package/src/{@claude-flow → packages}/cli/dist/src/commands/migrate.js +0 -0
  114. /package/src/{@claude-flow → packages}/cli/dist/src/commands/neural.js +0 -0
  115. /package/src/{@claude-flow → packages}/cli/dist/src/commands/performance.js +0 -0
  116. /package/src/{@claude-flow → packages}/cli/dist/src/commands/plugins.js +0 -0
  117. /package/src/{@claude-flow → packages}/cli/dist/src/commands/process.js +0 -0
  118. /package/src/{@claude-flow → packages}/cli/dist/src/commands/progress.js +0 -0
  119. /package/src/{@claude-flow → packages}/cli/dist/src/commands/providers.js +0 -0
  120. /package/src/{@claude-flow → packages}/cli/dist/src/commands/route.js +0 -0
  121. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/backup.js +0 -0
  122. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/benchmark.js +0 -0
  123. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/import.js +0 -0
  124. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/index.js +0 -0
  125. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/init.js +0 -0
  126. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/migrate.js +0 -0
  127. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/optimize.js +0 -0
  128. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/setup.js +0 -0
  129. /package/src/{@claude-flow → packages}/cli/dist/src/commands/ruvector/status.js +0 -0
  130. /package/src/{@claude-flow → packages}/cli/dist/src/commands/security.js +0 -0
  131. /package/src/{@claude-flow → packages}/cli/dist/src/commands/session.js +0 -0
  132. /package/src/{@claude-flow → packages}/cli/dist/src/commands/start.js +0 -0
  133. /package/src/{@claude-flow → packages}/cli/dist/src/commands/status.js +0 -0
  134. /package/src/{@claude-flow → packages}/cli/dist/src/commands/swarm.js +0 -0
  135. /package/src/{@claude-flow → packages}/cli/dist/src/commands/task.js +0 -0
  136. /package/src/{@claude-flow → packages}/cli/dist/src/commands/transfer-store.js +0 -0
  137. /package/src/{@claude-flow → packages}/cli/dist/src/commands/update.js +0 -0
  138. /package/src/{@claude-flow → packages}/cli/dist/src/commands/workflow.js +0 -0
  139. /package/src/{@claude-flow → packages}/cli/dist/src/config/moflo-config.js +0 -0
  140. /package/src/{@claude-flow → packages}/cli/dist/src/config-adapter.js +0 -0
  141. /package/src/{@claude-flow → packages}/cli/dist/src/index.js +0 -0
  142. /package/src/{@claude-flow → packages}/cli/dist/src/infrastructure/in-memory-repositories.js +0 -0
  143. /package/src/{@claude-flow → packages}/cli/dist/src/init/helpers-generator.js +0 -0
  144. /package/src/{@claude-flow → packages}/cli/dist/src/init/index.js +0 -0
  145. /package/src/{@claude-flow → packages}/cli/dist/src/init/mcp-generator.js +0 -0
  146. /package/src/{@claude-flow → packages}/cli/dist/src/init/settings-generator.js +0 -0
  147. /package/src/{@claude-flow → packages}/cli/dist/src/init/statusline-generator.js +0 -0
  148. /package/src/{@claude-flow → packages}/cli/dist/src/init/types.js +0 -0
  149. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-client.js +0 -0
  150. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-server.js +0 -0
  151. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/agent-tools.js +0 -0
  152. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/agentdb-tools.js +0 -0
  153. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/analyze-tools.js +0 -0
  154. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/auto-install.js +0 -0
  155. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/browser-tools.js +0 -0
  156. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/claims-tools.js +0 -0
  157. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/config-tools.js +0 -0
  158. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/coordination-tools.js +0 -0
  159. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/daa-tools.js +0 -0
  160. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/embeddings-tools.js +0 -0
  161. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/github-tools.js +0 -0
  162. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/hive-mind-tools.js +0 -0
  163. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/hooks-tools.js +0 -0
  164. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/index.js +0 -0
  165. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/memory-tools.js +0 -0
  166. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/neural-tools.js +0 -0
  167. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/performance-tools.js +0 -0
  168. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/progress-tools.js +0 -0
  169. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/security-tools.js +0 -0
  170. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/session-tools.js +0 -0
  171. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/swarm-tools.js +0 -0
  172. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/system-tools.js +0 -0
  173. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/task-tools.js +0 -0
  174. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/terminal-tools.js +0 -0
  175. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/transfer-tools.js +0 -0
  176. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/types.js +0 -0
  177. /package/src/{@claude-flow → packages}/cli/dist/src/mcp-tools/workflow-tools.js +0 -0
  178. /package/src/{@claude-flow → packages}/cli/dist/src/memory/ewc-consolidation.js +0 -0
  179. /package/src/{@claude-flow → packages}/cli/dist/src/memory/intelligence.js +0 -0
  180. /package/src/{@claude-flow → packages}/cli/dist/src/memory/memory-bridge.js +0 -0
  181. /package/src/{@claude-flow → packages}/cli/dist/src/memory/memory-initializer.js +0 -0
  182. /package/src/{@claude-flow → packages}/cli/dist/src/memory/sona-optimizer.js +0 -0
  183. /package/src/{@claude-flow → packages}/cli/dist/src/output.js +0 -0
  184. /package/src/{@claude-flow → packages}/cli/dist/src/parser.js +0 -0
  185. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/manager.js +0 -0
  186. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/store/discovery.js +0 -0
  187. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/store/index.js +0 -0
  188. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/store/search.js +0 -0
  189. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/store/types.js +0 -0
  190. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/tests/demo-plugin-store.js +0 -0
  191. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/tests/standalone-test.js +0 -0
  192. /package/src/{@claude-flow → packages}/cli/dist/src/plugins/tests/test-plugin-store.js +0 -0
  193. /package/src/{@claude-flow → packages}/cli/dist/src/production/circuit-breaker.js +0 -0
  194. /package/src/{@claude-flow → packages}/cli/dist/src/production/error-handler.js +0 -0
  195. /package/src/{@claude-flow → packages}/cli/dist/src/production/index.js +0 -0
  196. /package/src/{@claude-flow → packages}/cli/dist/src/production/monitoring.js +0 -0
  197. /package/src/{@claude-flow → packages}/cli/dist/src/production/rate-limiter.js +0 -0
  198. /package/src/{@claude-flow → packages}/cli/dist/src/production/retry.js +0 -0
  199. /package/src/{@claude-flow → packages}/cli/dist/src/prompt.js +0 -0
  200. /package/src/{@claude-flow → packages}/cli/dist/src/runtime/headless.js +0 -0
  201. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/ast-analyzer.js +0 -0
  202. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/coverage-router.js +0 -0
  203. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/coverage-tools.js +0 -0
  204. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/diff-classifier.js +0 -0
  205. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/enhanced-model-router.js +0 -0
  206. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/flash-attention.js +0 -0
  207. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/graph-analyzer.js +0 -0
  208. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/index.js +0 -0
  209. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/lora-adapter.js +0 -0
  210. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/model-router.js +0 -0
  211. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/moe-router.js +0 -0
  212. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/q-learning-router.js +0 -0
  213. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/semantic-router.js +0 -0
  214. /package/src/{@claude-flow → packages}/cli/dist/src/ruvector/vector-db.js +0 -0
  215. /package/src/{@claude-flow → packages}/cli/dist/src/services/agent-router.js +0 -0
  216. /package/src/{@claude-flow → packages}/cli/dist/src/services/agentic-flow-bridge.js +0 -0
  217. /package/src/{@claude-flow → packages}/cli/dist/src/services/claim-service.js +0 -0
  218. /package/src/{@claude-flow → packages}/cli/dist/src/services/daemon-lock.js +0 -0
  219. /package/src/{@claude-flow → packages}/cli/dist/src/services/headless-worker-executor.js +0 -0
  220. /package/src/{@claude-flow → packages}/cli/dist/src/services/index.js +0 -0
  221. /package/src/{@claude-flow → packages}/cli/dist/src/services/learning-service.js +0 -0
  222. /package/src/{@claude-flow → packages}/cli/dist/src/services/moflo-require.js +0 -0
  223. /package/src/{@claude-flow → packages}/cli/dist/src/services/registry-api.js +0 -0
  224. /package/src/{@claude-flow → packages}/cli/dist/src/services/ruvector-training.js +0 -0
  225. /package/src/{@claude-flow → packages}/cli/dist/src/services/worker-daemon.js +0 -0
  226. /package/src/{@claude-flow → packages}/cli/dist/src/services/worker-queue.js +0 -0
  227. /package/src/{@claude-flow → packages}/cli/dist/src/services/workflow-gate.js +0 -0
  228. /package/src/{@claude-flow → packages}/cli/dist/src/suggest.js +0 -0
  229. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/anonymization/index.js +0 -0
  230. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/deploy-seraphine.js +0 -0
  231. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/export.js +0 -0
  232. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/index.js +0 -0
  233. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/ipfs/client.js +0 -0
  234. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/ipfs/upload.js +0 -0
  235. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/models/seraphine.js +0 -0
  236. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/serialization/cfp.js +0 -0
  237. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/storage/gcs.js +0 -0
  238. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/storage/index.js +0 -0
  239. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/discovery.js +0 -0
  240. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/download.js +0 -0
  241. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/index.js +0 -0
  242. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/publish.js +0 -0
  243. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/registry.js +0 -0
  244. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/search.js +0 -0
  245. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/tests/standalone-test.js +0 -0
  246. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/store/types.js +0 -0
  247. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/test-seraphine.js +0 -0
  248. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/tests/test-store.js +0 -0
  249. /package/src/{@claude-flow → packages}/cli/dist/src/transfer/types.js +0 -0
  250. /package/src/{@claude-flow → packages}/cli/dist/src/types.js +0 -0
  251. /package/src/{@claude-flow → packages}/cli/dist/src/update/checker.js +0 -0
  252. /package/src/{@claude-flow → packages}/cli/dist/src/update/executor.js +0 -0
  253. /package/src/{@claude-flow → packages}/cli/dist/src/update/index.js +0 -0
  254. /package/src/{@claude-flow → packages}/cli/dist/src/update/rate-limiter.js +0 -0
  255. /package/src/{@claude-flow → packages}/cli/dist/src/update/validator.js +0 -0
  256. /package/src/{@claude-flow → packages}/guidance/README.md +0 -0
  257. /package/src/{@claude-flow → packages}/guidance/dist/adversarial.js +0 -0
  258. /package/src/{@claude-flow → packages}/guidance/dist/analyzer.js +0 -0
  259. /package/src/{@claude-flow → packages}/guidance/dist/artifacts.js +0 -0
  260. /package/src/{@claude-flow → packages}/guidance/dist/authority.js +0 -0
  261. /package/src/{@claude-flow → packages}/guidance/dist/capabilities.js +0 -0
  262. /package/src/{@claude-flow → packages}/guidance/dist/coherence.js +0 -0
  263. /package/src/{@claude-flow → packages}/guidance/dist/compiler.js +0 -0
  264. /package/src/{@claude-flow → packages}/guidance/dist/conformance-kit.js +0 -0
  265. /package/src/{@claude-flow → packages}/guidance/dist/continue-gate.js +0 -0
  266. /package/src/{@claude-flow → packages}/guidance/dist/crypto-utils.js +0 -0
  267. /package/src/{@claude-flow → packages}/guidance/dist/evolution.js +0 -0
  268. /package/src/{@claude-flow → packages}/guidance/dist/gates.js +0 -0
  269. /package/src/{@claude-flow → packages}/guidance/dist/gateway.js +0 -0
  270. /package/src/{@claude-flow → packages}/guidance/dist/generators.js +0 -0
  271. /package/src/{@claude-flow → packages}/guidance/dist/headless.js +0 -0
  272. /package/src/{@claude-flow → packages}/guidance/dist/hooks.js +0 -0
  273. /package/src/{@claude-flow → packages}/guidance/dist/index.js +0 -0
  274. /package/src/{@claude-flow → packages}/guidance/dist/ledger.js +0 -0
  275. /package/src/{@claude-flow → packages}/guidance/dist/manifest-validator.js +0 -0
  276. /package/src/{@claude-flow → packages}/guidance/dist/memory-gate.js +0 -0
  277. /package/src/{@claude-flow → packages}/guidance/dist/meta-governance.js +0 -0
  278. /package/src/{@claude-flow → packages}/guidance/dist/optimizer.js +0 -0
  279. /package/src/{@claude-flow → packages}/guidance/dist/persistence.js +0 -0
  280. /package/src/{@claude-flow → packages}/guidance/dist/proof.js +0 -0
  281. /package/src/{@claude-flow → packages}/guidance/dist/retriever.js +0 -0
  282. /package/src/{@claude-flow → packages}/guidance/dist/ruvbot-integration.js +0 -0
  283. /package/src/{@claude-flow → packages}/guidance/dist/temporal.js +0 -0
  284. /package/src/{@claude-flow → packages}/guidance/dist/trust.js +0 -0
  285. /package/src/{@claude-flow → packages}/guidance/dist/truth-anchors.js +0 -0
  286. /package/src/{@claude-flow → packages}/guidance/dist/types.js +0 -0
  287. /package/src/{@claude-flow → packages}/guidance/dist/uncertainty.js +0 -0
  288. /package/src/{@claude-flow → packages}/guidance/dist/wasm-kernel.js +0 -0
  289. /package/src/{@claude-flow → packages}/guidance/package.json +0 -0
  290. /package/src/{@claude-flow → packages}/memory/README.md +0 -0
  291. /package/src/{@claude-flow → packages}/memory/dist/agent-memory-scope.js +0 -0
  292. /package/src/{@claude-flow → packages}/memory/dist/agent-memory-scope.test.js +0 -0
  293. /package/src/{@claude-flow → packages}/memory/dist/agentdb-adapter.js +0 -0
  294. /package/src/{@claude-flow → packages}/memory/dist/agentdb-backend.js +0 -0
  295. /package/src/{@claude-flow → packages}/memory/dist/agentdb-backend.test.js +0 -0
  296. /package/src/{@claude-flow → packages}/memory/dist/application/commands/delete-memory.command.js +0 -0
  297. /package/src/{@claude-flow → packages}/memory/dist/application/commands/store-memory.command.js +0 -0
  298. /package/src/{@claude-flow → packages}/memory/dist/application/index.js +0 -0
  299. /package/src/{@claude-flow → packages}/memory/dist/application/queries/search-memory.query.js +0 -0
  300. /package/src/{@claude-flow → packages}/memory/dist/application/services/memory-application-service.js +0 -0
  301. /package/src/{@claude-flow → packages}/memory/dist/auto-memory-bridge.js +0 -0
  302. /package/src/{@claude-flow → packages}/memory/dist/auto-memory-bridge.test.js +0 -0
  303. /package/src/{@claude-flow → packages}/memory/dist/benchmark.test.js +0 -0
  304. /package/src/{@claude-flow → packages}/memory/dist/cache-manager.js +0 -0
  305. /package/src/{@claude-flow → packages}/memory/dist/controller-registry.js +0 -0
  306. /package/src/{@claude-flow → packages}/memory/dist/controller-registry.test.js +0 -0
  307. /package/src/{@claude-flow → packages}/memory/dist/database-provider.js +0 -0
  308. /package/src/{@claude-flow → packages}/memory/dist/database-provider.test.js +0 -0
  309. /package/src/{@claude-flow → packages}/memory/dist/domain/entities/memory-entry.js +0 -0
  310. /package/src/{@claude-flow → packages}/memory/dist/domain/index.js +0 -0
  311. /package/src/{@claude-flow → packages}/memory/dist/domain/repositories/memory-repository.interface.js +0 -0
  312. /package/src/{@claude-flow → packages}/memory/dist/domain/services/memory-domain-service.js +0 -0
  313. /package/src/{@claude-flow → packages}/memory/dist/hnsw-index.js +0 -0
  314. /package/src/{@claude-flow → packages}/memory/dist/hnsw-lite.js +0 -0
  315. /package/src/{@claude-flow → packages}/memory/dist/index.js +0 -0
  316. /package/src/{@claude-flow → packages}/memory/dist/infrastructure/index.js +0 -0
  317. /package/src/{@claude-flow → packages}/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +0 -0
  318. /package/src/{@claude-flow → packages}/memory/dist/learning-bridge.js +0 -0
  319. /package/src/{@claude-flow → packages}/memory/dist/learning-bridge.test.js +0 -0
  320. /package/src/{@claude-flow → packages}/memory/dist/memory-graph.js +0 -0
  321. /package/src/{@claude-flow → packages}/memory/dist/memory-graph.test.js +0 -0
  322. /package/src/{@claude-flow → packages}/memory/dist/migration.js +0 -0
  323. /package/src/{@claude-flow → packages}/memory/dist/persistent-sona.js +0 -0
  324. /package/src/{@claude-flow → packages}/memory/dist/query-builder.js +0 -0
  325. /package/src/{@claude-flow → packages}/memory/dist/rvf-backend.js +0 -0
  326. /package/src/{@claude-flow → packages}/memory/dist/rvf-learning-store.js +0 -0
  327. /package/src/{@claude-flow → packages}/memory/dist/rvf-migration.js +0 -0
  328. /package/src/{@claude-flow → packages}/memory/dist/sqljs-backend.js +0 -0
  329. /package/src/{@claude-flow → packages}/memory/dist/types.js +0 -0
  330. /package/src/{@claude-flow → packages}/memory/package.json +0 -0
  331. /package/src/{@claude-flow → packages}/neural/README.md +0 -0
  332. /package/src/{@claude-flow → packages}/neural/dist/algorithms/a2c.js +0 -0
  333. /package/src/{@claude-flow → packages}/neural/dist/algorithms/curiosity.js +0 -0
  334. /package/src/{@claude-flow → packages}/neural/dist/algorithms/decision-transformer.js +0 -0
  335. /package/src/{@claude-flow → packages}/neural/dist/algorithms/dqn.js +0 -0
  336. /package/src/{@claude-flow → packages}/neural/dist/algorithms/index.js +0 -0
  337. /package/src/{@claude-flow → packages}/neural/dist/algorithms/ppo.js +0 -0
  338. /package/src/{@claude-flow → packages}/neural/dist/algorithms/q-learning.js +0 -0
  339. /package/src/{@claude-flow → packages}/neural/dist/algorithms/sarsa.js +0 -0
  340. /package/src/{@claude-flow → packages}/neural/dist/application/index.js +0 -0
  341. /package/src/{@claude-flow → packages}/neural/dist/application/services/neural-application-service.js +0 -0
  342. /package/src/{@claude-flow → packages}/neural/dist/domain/entities/pattern.js +0 -0
  343. /package/src/{@claude-flow → packages}/neural/dist/domain/index.js +0 -0
  344. /package/src/{@claude-flow → packages}/neural/dist/domain/services/learning-service.js +0 -0
  345. /package/src/{@claude-flow → packages}/neural/dist/index.js +0 -0
  346. /package/src/{@claude-flow → packages}/neural/dist/modes/balanced.js +0 -0
  347. /package/src/{@claude-flow → packages}/neural/dist/modes/base.js +0 -0
  348. /package/src/{@claude-flow → packages}/neural/dist/modes/batch.js +0 -0
  349. /package/src/{@claude-flow → packages}/neural/dist/modes/edge.js +0 -0
  350. /package/src/{@claude-flow → packages}/neural/dist/modes/index.js +0 -0
  351. /package/src/{@claude-flow → packages}/neural/dist/modes/real-time.js +0 -0
  352. /package/src/{@claude-flow → packages}/neural/dist/modes/research.js +0 -0
  353. /package/src/{@claude-flow → packages}/neural/dist/pattern-learner.js +0 -0
  354. /package/src/{@claude-flow → packages}/neural/dist/reasoning-bank.js +0 -0
  355. /package/src/{@claude-flow → packages}/neural/dist/reasoningbank-adapter.js +0 -0
  356. /package/src/{@claude-flow → packages}/neural/dist/sona-integration.js +0 -0
  357. /package/src/{@claude-flow → packages}/neural/dist/sona-manager.js +0 -0
  358. /package/src/{@claude-flow → packages}/neural/dist/types.js +0 -0
  359. /package/src/{@claude-flow → packages}/neural/package.json +0 -0
  360. /package/src/{@claude-flow → packages}/shared/README.md +0 -0
  361. /package/src/{@claude-flow → packages}/shared/dist/core/config/defaults.js +0 -0
  362. /package/src/{@claude-flow → packages}/shared/dist/core/config/index.js +0 -0
  363. /package/src/{@claude-flow → packages}/shared/dist/core/config/loader.js +0 -0
  364. /package/src/{@claude-flow → packages}/shared/dist/core/config/schema.js +0 -0
  365. /package/src/{@claude-flow → packages}/shared/dist/core/config/validator.js +0 -0
  366. /package/src/{@claude-flow → packages}/shared/dist/core/event-bus.js +0 -0
  367. /package/src/{@claude-flow → packages}/shared/dist/core/index.js +0 -0
  368. /package/src/{@claude-flow → packages}/shared/dist/core/interfaces/agent.interface.js +0 -0
  369. /package/src/{@claude-flow → packages}/shared/dist/core/interfaces/coordinator.interface.js +0 -0
  370. /package/src/{@claude-flow → packages}/shared/dist/core/interfaces/event.interface.js +0 -0
  371. /package/src/{@claude-flow → packages}/shared/dist/core/interfaces/index.js +0 -0
  372. /package/src/{@claude-flow → packages}/shared/dist/core/interfaces/memory.interface.js +0 -0
  373. /package/src/{@claude-flow → packages}/shared/dist/core/interfaces/task.interface.js +0 -0
  374. /package/src/{@claude-flow → packages}/shared/dist/core/orchestrator/event-coordinator.js +0 -0
  375. /package/src/{@claude-flow → packages}/shared/dist/core/orchestrator/health-monitor.js +0 -0
  376. /package/src/{@claude-flow → packages}/shared/dist/core/orchestrator/index.js +0 -0
  377. /package/src/{@claude-flow → packages}/shared/dist/core/orchestrator/lifecycle-manager.js +0 -0
  378. /package/src/{@claude-flow → packages}/shared/dist/core/orchestrator/session-manager.js +0 -0
  379. /package/src/{@claude-flow → packages}/shared/dist/core/orchestrator/task-manager.js +0 -0
  380. /package/src/{@claude-flow → packages}/shared/dist/events/domain-events.js +0 -0
  381. /package/src/{@claude-flow → packages}/shared/dist/events/event-store.js +0 -0
  382. /package/src/{@claude-flow → packages}/shared/dist/events/event-store.test.js +0 -0
  383. /package/src/{@claude-flow → packages}/shared/dist/events/example-usage.js +0 -0
  384. /package/src/{@claude-flow → packages}/shared/dist/events/index.js +0 -0
  385. /package/src/{@claude-flow → packages}/shared/dist/events/projections.js +0 -0
  386. /package/src/{@claude-flow → packages}/shared/dist/events/rvf-event-log.js +0 -0
  387. /package/src/{@claude-flow → packages}/shared/dist/events/state-reconstructor.js +0 -0
  388. /package/src/{@claude-flow → packages}/shared/dist/events.js +0 -0
  389. /package/src/{@claude-flow → packages}/shared/dist/hooks/example-usage.js +0 -0
  390. /package/src/{@claude-flow → packages}/shared/dist/hooks/executor.js +0 -0
  391. /package/src/{@claude-flow → packages}/shared/dist/hooks/hooks.test.js +0 -0
  392. /package/src/{@claude-flow → packages}/shared/dist/hooks/index.js +0 -0
  393. /package/src/{@claude-flow → packages}/shared/dist/hooks/registry.js +0 -0
  394. /package/src/{@claude-flow → packages}/shared/dist/hooks/safety/bash-safety.js +0 -0
  395. /package/src/{@claude-flow → packages}/shared/dist/hooks/safety/file-organization.js +0 -0
  396. /package/src/{@claude-flow → packages}/shared/dist/hooks/safety/git-commit.js +0 -0
  397. /package/src/{@claude-flow → packages}/shared/dist/hooks/safety/index.js +0 -0
  398. /package/src/{@claude-flow → packages}/shared/dist/hooks/session-hooks.js +0 -0
  399. /package/src/{@claude-flow → packages}/shared/dist/hooks/task-hooks.js +0 -0
  400. /package/src/{@claude-flow → packages}/shared/dist/hooks/types.js +0 -0
  401. /package/src/{@claude-flow → packages}/shared/dist/hooks/verify-exports.test.js +0 -0
  402. /package/src/{@claude-flow → packages}/shared/dist/index.js +0 -0
  403. /package/src/{@claude-flow → packages}/shared/dist/mcp/connection-pool.js +0 -0
  404. /package/src/{@claude-flow → packages}/shared/dist/mcp/index.js +0 -0
  405. /package/src/{@claude-flow → packages}/shared/dist/mcp/server.js +0 -0
  406. /package/src/{@claude-flow → packages}/shared/dist/mcp/session-manager.js +0 -0
  407. /package/src/{@claude-flow → packages}/shared/dist/mcp/tool-registry.js +0 -0
  408. /package/src/{@claude-flow → packages}/shared/dist/mcp/transport/http.js +0 -0
  409. /package/src/{@claude-flow → packages}/shared/dist/mcp/transport/index.js +0 -0
  410. /package/src/{@claude-flow → packages}/shared/dist/mcp/transport/stdio.js +0 -0
  411. /package/src/{@claude-flow → packages}/shared/dist/mcp/transport/websocket.js +0 -0
  412. /package/src/{@claude-flow → packages}/shared/dist/mcp/types.js +0 -0
  413. /package/src/{@claude-flow → packages}/shared/dist/plugin-interface.js +0 -0
  414. /package/src/{@claude-flow → packages}/shared/dist/plugin-loader.js +0 -0
  415. /package/src/{@claude-flow → packages}/shared/dist/plugin-registry.js +0 -0
  416. /package/src/{@claude-flow → packages}/shared/dist/plugins/index.js +0 -0
  417. /package/src/{@claude-flow → packages}/shared/dist/plugins/official/hive-mind-plugin.js +0 -0
  418. /package/src/{@claude-flow → packages}/shared/dist/plugins/official/index.js +0 -0
  419. /package/src/{@claude-flow → packages}/shared/dist/plugins/official/maestro-plugin.js +0 -0
  420. /package/src/{@claude-flow → packages}/shared/dist/plugins/types.js +0 -0
  421. /package/src/{@claude-flow → packages}/shared/dist/resilience/bulkhead.js +0 -0
  422. /package/src/{@claude-flow → packages}/shared/dist/resilience/circuit-breaker.js +0 -0
  423. /package/src/{@claude-flow → packages}/shared/dist/resilience/index.js +0 -0
  424. /package/src/{@claude-flow → packages}/shared/dist/resilience/rate-limiter.js +0 -0
  425. /package/src/{@claude-flow → packages}/shared/dist/resilience/retry.js +0 -0
  426. /package/src/{@claude-flow → packages}/shared/dist/security/index.js +0 -0
  427. /package/src/{@claude-flow → packages}/shared/dist/security/input-validation.js +0 -0
  428. /package/src/{@claude-flow → packages}/shared/dist/security/secure-random.js +0 -0
  429. /package/src/{@claude-flow → packages}/shared/dist/services/index.js +0 -0
  430. /package/src/{@claude-flow → packages}/shared/dist/services/v3-progress.service.js +0 -0
  431. /package/src/{@claude-flow → packages}/shared/dist/types/agent.types.js +0 -0
  432. /package/src/{@claude-flow → packages}/shared/dist/types/index.js +0 -0
  433. /package/src/{@claude-flow → packages}/shared/dist/types/mcp.types.js +0 -0
  434. /package/src/{@claude-flow → packages}/shared/dist/types/memory.types.js +0 -0
  435. /package/src/{@claude-flow → packages}/shared/dist/types/swarm.types.js +0 -0
  436. /package/src/{@claude-flow → packages}/shared/dist/types/task.types.js +0 -0
  437. /package/src/{@claude-flow → packages}/shared/dist/types.js +0 -0
  438. /package/src/{@claude-flow → packages}/shared/dist/utils/secure-logger.js +0 -0
  439. /package/src/{@claude-flow → packages}/shared/package.json +0 -0
@@ -1,277 +1,277 @@
1
- /**
2
- * MoFlo Project Initializer
3
- *
4
- * One-stop setup that makes MoFlo work out of the box:
5
- * 1. Generate moflo.yaml (project config)
6
- * 2. Set up .claude/settings.json hooks
7
- * 3. Create .claude/skills/flo/ skill (with /fl alias)
8
- * 4. Append MoFlo section to CLAUDE.md
9
- * 5. Initialize memory DB
10
- * 6. Auto-index guidance + code map
11
- */
12
- import * as fs from 'fs';
13
- import * as path from 'path';
14
- import { fileURLToPath } from 'url';
15
- // ============================================================================
16
- // Init
17
- // ============================================================================
18
- /**
19
- * Discover guidance directories by checking top-level candidates AND walking
20
- * the project tree for subproject .claude/guidance dirs (monorepo support).
21
- */
22
- function discoverGuidanceDirs(root) {
23
- const TOP_LEVEL = ['.claude/guidance', 'docs/guides', 'docs', 'architecture', 'adr', '.cursor/rules'];
24
- const found = TOP_LEVEL.filter(d => fs.existsSync(path.join(root, d)));
25
- // Walk up to 3 levels deep looking for .claude/guidance in subprojects
26
- const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.reports', '.swarm', '.claude-flow', 'packages']);
27
- function walk(dir, depth) {
28
- if (depth > 3)
29
- return;
30
- try {
31
- const entries = fs.readdirSync(path.join(root, dir), { withFileTypes: true });
32
- for (const entry of entries) {
33
- if (!entry.isDirectory() || SKIP.has(entry.name))
34
- continue;
35
- const rel = dir ? `${dir}/${entry.name}` : entry.name;
36
- const guidancePath = `${rel}/.claude/guidance`;
37
- if (fs.existsSync(path.join(root, guidancePath))) {
38
- // Verify it has .md files
39
- try {
40
- const files = fs.readdirSync(path.join(root, guidancePath));
41
- if (files.some(f => f.endsWith('.md')))
42
- found.push(guidancePath);
43
- }
44
- catch { /* skip unreadable */ }
45
- }
46
- else {
47
- walk(rel, depth + 1);
48
- }
49
- }
50
- }
51
- catch { /* skip unreadable directories */ }
52
- }
53
- walk('', 0);
54
- return found;
55
- }
56
- /**
57
- * Discover test directories by checking common locations and walking for
58
- * colocated __tests__ dirs. Returns relative paths.
59
- */
60
- export function discoverTestDirs(root) {
61
- const TOP_LEVEL = ['tests', 'test', '__tests__', 'spec', 'e2e'];
62
- const found = TOP_LEVEL.filter(d => fs.existsSync(path.join(root, d)));
63
- // Walk up to 3 levels deep looking for __tests__ dirs inside src
64
- const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.reports', '.swarm', '.claude-flow']);
65
- function walk(dir, depth) {
66
- if (depth > 3)
67
- return;
68
- try {
69
- const entries = fs.readdirSync(path.join(root, dir), { withFileTypes: true });
70
- for (const entry of entries) {
71
- if (!entry.isDirectory() || SKIP.has(entry.name))
72
- continue;
73
- const rel = dir ? `${dir}/${entry.name}` : entry.name;
74
- if (entry.name === '__tests__') {
75
- found.push(rel);
76
- }
77
- else {
78
- walk(rel, depth + 1);
79
- }
80
- }
81
- }
82
- catch { /* skip unreadable directories */ }
83
- }
84
- walk('', 0);
85
- return found;
86
- }
87
- /**
88
- * Discover source directories by walking the project tree.
89
- * Finds directories named 'src' (or top-level 'packages', 'lib', etc.)
90
- * that contain .ts/.tsx/.js/.jsx files. Skips node_modules, dist, etc.
91
- */
92
- function discoverSrcDirs(root) {
93
- const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.reports', '.swarm', '.claude-flow']);
94
- // Top-level candidates that are always source roots if they exist
95
- const TOP_LEVEL = ['packages', 'lib', 'app', 'apps', 'services', 'server', 'client'];
96
- const found = [];
97
- // Add top-level candidates first
98
- for (const d of TOP_LEVEL) {
99
- if (fs.existsSync(path.join(root, d)))
100
- found.push(d);
101
- }
102
- // Walk up to 3 levels deep looking for 'src' and 'migrations' directories
103
- const SRC_NAMES = new Set(['src', 'migrations']);
104
- function walk(dir, depth) {
105
- if (depth > 3)
106
- return;
107
- try {
108
- const entries = fs.readdirSync(path.join(root, dir), { withFileTypes: true });
109
- for (const entry of entries) {
110
- if (!entry.isDirectory() || SKIP.has(entry.name))
111
- continue;
112
- const rel = dir ? `${dir}/${entry.name}` : entry.name;
113
- if (SRC_NAMES.has(entry.name)) {
114
- // Check it actually has source files
115
- try {
116
- const files = fs.readdirSync(path.join(root, rel));
117
- const hasSource = files.some(f => /\.(ts|tsx|js|jsx)$/.test(f));
118
- if (hasSource)
119
- found.push(rel);
120
- }
121
- catch { /* skip unreadable */ }
122
- }
123
- else {
124
- walk(rel, depth + 1);
125
- }
126
- }
127
- }
128
- catch { /* skip unreadable directories */ }
129
- }
130
- walk('', 0);
131
- // Deduplicate: if 'packages' is found, don't also include 'packages/foo/src'
132
- // since the code-map walker handles subdirs
133
- return found.filter(d => {
134
- return !found.some(other => other !== d && d.startsWith(other + '/'));
135
- });
136
- }
137
- /**
138
- * Run interactive wizard to collect user preferences.
139
- */
140
- async function runWizard(root) {
141
- const { confirm, input } = await import('../prompt.js');
142
- // Detect project structure
143
- const detectedGuidance = discoverGuidanceDirs(root);
144
- const detectedSrc = discoverSrcDirs(root);
145
- // Ask questions
146
- const guidance = await confirm({
147
- message: detectedGuidance.length > 0
148
- ? `Found guidance docs in ${detectedGuidance.join(', ')}. Enable guidance indexing?`
149
- : 'Do you have project guidance/documentation to index?',
150
- default: true,
151
- });
152
- let guidanceDirs = detectedGuidance.length > 0 ? detectedGuidance : ['.claude/guidance'];
153
- if (guidance) {
154
- const answer = await input({
155
- message: 'Guidance directories (comma-separated):',
156
- default: guidanceDirs.join(', '),
157
- });
158
- guidanceDirs = answer.split(',').map((d) => d.trim()).filter(Boolean);
159
- }
160
- const codeMap = await confirm({
161
- message: detectedSrc.length > 0
162
- ? `Found source in ${detectedSrc.join(', ')}. Enable code map for navigation?`
163
- : 'Enable code map for codebase navigation?',
164
- default: true,
165
- });
166
- let srcDirs = detectedSrc.length > 0 ? detectedSrc : ['src'];
167
- if (codeMap) {
168
- const answer = await input({
169
- message: 'Source directories (comma-separated):',
170
- default: srcDirs.join(', '),
171
- });
172
- srcDirs = answer.split(',').map((d) => d.trim()).filter(Boolean);
173
- }
174
- // Detect test directories
175
- const detectedTests = discoverTestDirs(root);
176
- const tests = await confirm({
177
- message: detectedTests.length > 0
178
- ? `Found tests in ${detectedTests.join(', ')}. Enable test file indexing?`
179
- : 'Enable test file indexing?',
180
- default: true,
181
- });
182
- let testDirs = detectedTests.length > 0 ? detectedTests : ['tests'];
183
- if (tests) {
184
- const answer = await input({
185
- message: 'Test directories (comma-separated):',
186
- default: testDirs.join(', '),
187
- });
188
- testDirs = answer.split(',').map((d) => d.trim()).filter(Boolean);
189
- }
190
- const gates = await confirm({
191
- message: 'Enable workflow gates (memory-first, task-create-before-agents)?',
192
- default: true,
193
- });
194
- const stopHook = await confirm({
195
- message: 'Enable session-end hook (saves session state)?',
196
- default: true,
197
- });
198
- return { guidance, guidanceDirs, codeMap, srcDirs, tests, testDirs, gates, stopHook };
199
- }
200
- /**
201
- * Get default answers (--yes mode).
202
- */
203
- function defaultAnswers(root) {
204
- const guidanceDirs = discoverGuidanceDirs(root);
205
- if (guidanceDirs.length === 0)
206
- guidanceDirs.push('.claude/guidance');
207
- const srcDirs = discoverSrcDirs(root);
208
- if (srcDirs.length === 0)
209
- srcDirs.push('src');
210
- const testDirs = discoverTestDirs(root);
211
- if (testDirs.length === 0)
212
- testDirs.push('tests');
213
- return { guidance: true, guidanceDirs, codeMap: true, srcDirs, tests: true, testDirs, gates: true, stopHook: true };
214
- }
215
- /**
216
- * Get minimal answers (--minimal mode).
217
- */
218
- function minimalAnswers() {
219
- return { guidance: false, guidanceDirs: [], codeMap: false, srcDirs: [], tests: false, testDirs: [], gates: false, stopHook: false };
220
- }
221
- export async function initMoflo(options) {
222
- const { projectRoot, force, interactive, minimal } = options;
223
- const steps = [];
224
- // Collect answers based on mode
225
- const answers = minimal
226
- ? minimalAnswers()
227
- : interactive
228
- ? await runWizard(projectRoot)
229
- : defaultAnswers(projectRoot);
230
- // Step 1: moflo.yaml
231
- steps.push(generateConfig(projectRoot, force, answers));
232
- // Step 2: .claude/settings.json hooks
233
- steps.push(generateHooks(projectRoot, force, answers));
234
- // Step 3: .claude/skills/flo/ (with /fl alias)
235
- steps.push(generateSkill(projectRoot, force));
236
- // Step 4: CLAUDE.md MoFlo section
237
- steps.push(generateClaudeMd(projectRoot, force));
238
- // Step 5: .claude/scripts/ from moflo bin/
239
- steps.push(syncScripts(projectRoot, force));
240
- // Step 6: .gitignore entries
241
- steps.push(updateGitignore(projectRoot));
242
- // Step 7: .claude/guidance/moflo-bootstrap.md (subagent bootstrap protocol)
243
- steps.push(syncBootstrapGuidance(projectRoot, force));
244
- // Step 8: Sync ALL shipped guidance docs from moflo to project
245
- steps.push(...syncAllShippedGuidance(projectRoot, force));
246
- return { steps };
247
- }
248
- // ============================================================================
249
- // Step 1: moflo.yaml
250
- // ============================================================================
251
- function generateConfig(root, force, answers) {
252
- const configPath = path.join(root, 'moflo.yaml');
253
- if (fs.existsSync(configPath) && !force) {
254
- return { name: 'moflo.yaml', status: 'skipped', detail: 'Already exists (use --force to overwrite)' };
255
- }
256
- const projectName = path.basename(root);
257
- const guidanceDirs = answers?.guidanceDirs ?? ['.claude/guidance'];
258
- const srcDirs = answers?.srcDirs ?? ['src'];
259
- const testDirs = answers?.testDirs ?? ['tests'];
260
- const gatesEnabled = answers?.gates ?? true;
261
- // Detect languages
262
- const extensions = new Set();
263
- for (const dir of srcDirs) {
264
- const fullDir = path.join(root, dir);
265
- if (fs.existsSync(fullDir)) {
266
- try {
267
- scanExtensions(fullDir, extensions, 0, 3);
268
- }
269
- catch { /* skip */ }
270
- }
271
- }
272
- const detectedExts = extensions.size > 0
273
- ? [...extensions].sort()
274
- : ['.ts', '.tsx', '.js', '.jsx'];
1
+ /**
2
+ * MoFlo Project Initializer
3
+ *
4
+ * One-stop setup that makes MoFlo work out of the box:
5
+ * 1. Generate moflo.yaml (project config)
6
+ * 2. Set up .claude/settings.json hooks
7
+ * 3. Create .claude/skills/flo/ skill (with /fl alias)
8
+ * 4. Append MoFlo section to CLAUDE.md
9
+ * 5. Initialize memory DB
10
+ * 6. Auto-index guidance + code map
11
+ */
12
+ import * as fs from 'fs';
13
+ import * as path from 'path';
14
+ import { fileURLToPath } from 'url';
15
+ // ============================================================================
16
+ // Init
17
+ // ============================================================================
18
+ /**
19
+ * Discover guidance directories by checking top-level candidates AND walking
20
+ * the project tree for subproject .claude/guidance dirs (monorepo support).
21
+ */
22
+ function discoverGuidanceDirs(root) {
23
+ const TOP_LEVEL = ['.claude/guidance', 'docs/guides', 'docs', 'architecture', 'adr', '.cursor/rules'];
24
+ const found = TOP_LEVEL.filter(d => fs.existsSync(path.join(root, d)));
25
+ // Walk up to 3 levels deep looking for .claude/guidance in subprojects
26
+ const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.reports', '.swarm', '.claude-flow', 'packages']);
27
+ function walk(dir, depth) {
28
+ if (depth > 3)
29
+ return;
30
+ try {
31
+ const entries = fs.readdirSync(path.join(root, dir), { withFileTypes: true });
32
+ for (const entry of entries) {
33
+ if (!entry.isDirectory() || SKIP.has(entry.name))
34
+ continue;
35
+ const rel = dir ? `${dir}/${entry.name}` : entry.name;
36
+ const guidancePath = `${rel}/.claude/guidance`;
37
+ if (fs.existsSync(path.join(root, guidancePath))) {
38
+ // Verify it has .md files
39
+ try {
40
+ const files = fs.readdirSync(path.join(root, guidancePath));
41
+ if (files.some(f => f.endsWith('.md')))
42
+ found.push(guidancePath);
43
+ }
44
+ catch { /* skip unreadable */ }
45
+ }
46
+ else {
47
+ walk(rel, depth + 1);
48
+ }
49
+ }
50
+ }
51
+ catch { /* skip unreadable directories */ }
52
+ }
53
+ walk('', 0);
54
+ return found;
55
+ }
56
+ /**
57
+ * Discover test directories by checking common locations and walking for
58
+ * colocated __tests__ dirs. Returns relative paths.
59
+ */
60
+ export function discoverTestDirs(root) {
61
+ const TOP_LEVEL = ['tests', 'test', '__tests__', 'spec', 'e2e'];
62
+ const found = TOP_LEVEL.filter(d => fs.existsSync(path.join(root, d)));
63
+ // Walk up to 3 levels deep looking for __tests__ dirs inside src
64
+ const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.reports', '.swarm', '.claude-flow']);
65
+ function walk(dir, depth) {
66
+ if (depth > 3)
67
+ return;
68
+ try {
69
+ const entries = fs.readdirSync(path.join(root, dir), { withFileTypes: true });
70
+ for (const entry of entries) {
71
+ if (!entry.isDirectory() || SKIP.has(entry.name))
72
+ continue;
73
+ const rel = dir ? `${dir}/${entry.name}` : entry.name;
74
+ if (entry.name === '__tests__') {
75
+ found.push(rel);
76
+ }
77
+ else {
78
+ walk(rel, depth + 1);
79
+ }
80
+ }
81
+ }
82
+ catch { /* skip unreadable directories */ }
83
+ }
84
+ walk('', 0);
85
+ return found;
86
+ }
87
+ /**
88
+ * Discover source directories by walking the project tree.
89
+ * Finds directories named 'src' (or top-level 'packages', 'lib', etc.)
90
+ * that contain .ts/.tsx/.js/.jsx files. Skips node_modules, dist, etc.
91
+ */
92
+ function discoverSrcDirs(root) {
93
+ const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'coverage', '.next', '.reports', '.swarm', '.claude-flow']);
94
+ // Top-level candidates that are always source roots if they exist
95
+ const TOP_LEVEL = ['packages', 'lib', 'app', 'apps', 'services', 'server', 'client'];
96
+ const found = [];
97
+ // Add top-level candidates first
98
+ for (const d of TOP_LEVEL) {
99
+ if (fs.existsSync(path.join(root, d)))
100
+ found.push(d);
101
+ }
102
+ // Walk up to 3 levels deep looking for 'src' and 'migrations' directories
103
+ const SRC_NAMES = new Set(['src', 'migrations']);
104
+ function walk(dir, depth) {
105
+ if (depth > 3)
106
+ return;
107
+ try {
108
+ const entries = fs.readdirSync(path.join(root, dir), { withFileTypes: true });
109
+ for (const entry of entries) {
110
+ if (!entry.isDirectory() || SKIP.has(entry.name))
111
+ continue;
112
+ const rel = dir ? `${dir}/${entry.name}` : entry.name;
113
+ if (SRC_NAMES.has(entry.name)) {
114
+ // Check it actually has source files
115
+ try {
116
+ const files = fs.readdirSync(path.join(root, rel));
117
+ const hasSource = files.some(f => /\.(ts|tsx|js|jsx)$/.test(f));
118
+ if (hasSource)
119
+ found.push(rel);
120
+ }
121
+ catch { /* skip unreadable */ }
122
+ }
123
+ else {
124
+ walk(rel, depth + 1);
125
+ }
126
+ }
127
+ }
128
+ catch { /* skip unreadable directories */ }
129
+ }
130
+ walk('', 0);
131
+ // Deduplicate: if 'packages' is found, don't also include 'packages/foo/src'
132
+ // since the code-map walker handles subdirs
133
+ return found.filter(d => {
134
+ return !found.some(other => other !== d && d.startsWith(other + '/'));
135
+ });
136
+ }
137
+ /**
138
+ * Run interactive wizard to collect user preferences.
139
+ */
140
+ async function runWizard(root) {
141
+ const { confirm, input } = await import('../prompt.js');
142
+ // Detect project structure
143
+ const detectedGuidance = discoverGuidanceDirs(root);
144
+ const detectedSrc = discoverSrcDirs(root);
145
+ // Ask questions
146
+ const guidance = await confirm({
147
+ message: detectedGuidance.length > 0
148
+ ? `Found guidance docs in ${detectedGuidance.join(', ')}. Enable guidance indexing?`
149
+ : 'Do you have project guidance/documentation to index?',
150
+ default: true,
151
+ });
152
+ let guidanceDirs = detectedGuidance.length > 0 ? detectedGuidance : ['.claude/guidance'];
153
+ if (guidance) {
154
+ const answer = await input({
155
+ message: 'Guidance directories (comma-separated):',
156
+ default: guidanceDirs.join(', '),
157
+ });
158
+ guidanceDirs = answer.split(',').map((d) => d.trim()).filter(Boolean);
159
+ }
160
+ const codeMap = await confirm({
161
+ message: detectedSrc.length > 0
162
+ ? `Found source in ${detectedSrc.join(', ')}. Enable code map for navigation?`
163
+ : 'Enable code map for codebase navigation?',
164
+ default: true,
165
+ });
166
+ let srcDirs = detectedSrc.length > 0 ? detectedSrc : ['src'];
167
+ if (codeMap) {
168
+ const answer = await input({
169
+ message: 'Source directories (comma-separated):',
170
+ default: srcDirs.join(', '),
171
+ });
172
+ srcDirs = answer.split(',').map((d) => d.trim()).filter(Boolean);
173
+ }
174
+ // Detect test directories
175
+ const detectedTests = discoverTestDirs(root);
176
+ const tests = await confirm({
177
+ message: detectedTests.length > 0
178
+ ? `Found tests in ${detectedTests.join(', ')}. Enable test file indexing?`
179
+ : 'Enable test file indexing?',
180
+ default: true,
181
+ });
182
+ let testDirs = detectedTests.length > 0 ? detectedTests : ['tests'];
183
+ if (tests) {
184
+ const answer = await input({
185
+ message: 'Test directories (comma-separated):',
186
+ default: testDirs.join(', '),
187
+ });
188
+ testDirs = answer.split(',').map((d) => d.trim()).filter(Boolean);
189
+ }
190
+ const gates = await confirm({
191
+ message: 'Enable workflow gates (memory-first, task-create-before-agents)?',
192
+ default: true,
193
+ });
194
+ const stopHook = await confirm({
195
+ message: 'Enable session-end hook (saves session state)?',
196
+ default: true,
197
+ });
198
+ return { guidance, guidanceDirs, codeMap, srcDirs, tests, testDirs, gates, stopHook };
199
+ }
200
+ /**
201
+ * Get default answers (--yes mode).
202
+ */
203
+ function defaultAnswers(root) {
204
+ const guidanceDirs = discoverGuidanceDirs(root);
205
+ if (guidanceDirs.length === 0)
206
+ guidanceDirs.push('.claude/guidance');
207
+ const srcDirs = discoverSrcDirs(root);
208
+ if (srcDirs.length === 0)
209
+ srcDirs.push('src');
210
+ const testDirs = discoverTestDirs(root);
211
+ if (testDirs.length === 0)
212
+ testDirs.push('tests');
213
+ return { guidance: true, guidanceDirs, codeMap: true, srcDirs, tests: true, testDirs, gates: true, stopHook: true };
214
+ }
215
+ /**
216
+ * Get minimal answers (--minimal mode).
217
+ */
218
+ function minimalAnswers() {
219
+ return { guidance: false, guidanceDirs: [], codeMap: false, srcDirs: [], tests: false, testDirs: [], gates: false, stopHook: false };
220
+ }
221
+ export async function initMoflo(options) {
222
+ const { projectRoot, force, interactive, minimal } = options;
223
+ const steps = [];
224
+ // Collect answers based on mode
225
+ const answers = minimal
226
+ ? minimalAnswers()
227
+ : interactive
228
+ ? await runWizard(projectRoot)
229
+ : defaultAnswers(projectRoot);
230
+ // Step 1: moflo.yaml
231
+ steps.push(generateConfig(projectRoot, force, answers));
232
+ // Step 2: .claude/settings.json hooks
233
+ steps.push(generateHooks(projectRoot, force, answers));
234
+ // Step 3: .claude/skills/flo/ (with /fl alias)
235
+ steps.push(generateSkill(projectRoot, force));
236
+ // Step 4: CLAUDE.md MoFlo section
237
+ steps.push(generateClaudeMd(projectRoot, force));
238
+ // Step 5: .claude/scripts/ from moflo bin/
239
+ steps.push(syncScripts(projectRoot, force));
240
+ // Step 6: .gitignore entries
241
+ steps.push(updateGitignore(projectRoot));
242
+ // Step 7: .claude/guidance/moflo-bootstrap.md (subagent bootstrap protocol)
243
+ steps.push(syncBootstrapGuidance(projectRoot, force));
244
+ // Step 8: Sync ALL shipped guidance docs from moflo to project
245
+ steps.push(...syncAllShippedGuidance(projectRoot, force));
246
+ return { steps };
247
+ }
248
+ // ============================================================================
249
+ // Step 1: moflo.yaml
250
+ // ============================================================================
251
+ function generateConfig(root, force, answers) {
252
+ const configPath = path.join(root, 'moflo.yaml');
253
+ if (fs.existsSync(configPath) && !force) {
254
+ return { name: 'moflo.yaml', status: 'skipped', detail: 'Already exists (use --force to overwrite)' };
255
+ }
256
+ const projectName = path.basename(root);
257
+ const guidanceDirs = answers?.guidanceDirs ?? ['.claude/guidance'];
258
+ const srcDirs = answers?.srcDirs ?? ['src'];
259
+ const testDirs = answers?.testDirs ?? ['tests'];
260
+ const gatesEnabled = answers?.gates ?? true;
261
+ // Detect languages
262
+ const extensions = new Set();
263
+ for (const dir of srcDirs) {
264
+ const fullDir = path.join(root, dir);
265
+ if (fs.existsSync(fullDir)) {
266
+ try {
267
+ scanExtensions(fullDir, extensions, 0, 3);
268
+ }
269
+ catch { /* skip */ }
270
+ }
271
+ }
272
+ const detectedExts = extensions.size > 0
273
+ ? [...extensions].sort()
274
+ : ['.ts', '.tsx', '.js', '.jsx'];
275
275
  const yaml = `# MoFlo — Project Configuration
276
276
  # Generated by: moflo init
277
277
  # Docs: https://github.com/eric-cielo/moflo
@@ -368,297 +368,297 @@ model_routing:
368
368
  # agent_overrides:
369
369
  # security-architect: opus # Always use opus for security
370
370
  # researcher: sonnet # Pin research to sonnet
371
- `;
372
- fs.writeFileSync(configPath, yaml, 'utf-8');
373
- return { name: 'moflo.yaml', status: 'created', detail: `Detected: ${srcDirs.join(', ')} | ${detectedExts.join(', ')}` };
374
- }
375
- function scanExtensions(dir, extensions, depth, maxDepth) {
376
- if (depth > maxDepth)
377
- return;
378
- const entries = fs.readdirSync(dir, { withFileTypes: true });
379
- for (const entry of entries.slice(0, 100)) {
380
- if (entry.isDirectory() && !['node_modules', '.git', 'dist', 'build'].includes(entry.name)) {
381
- scanExtensions(path.join(dir, entry.name), extensions, depth + 1, maxDepth);
382
- }
383
- else if (entry.isFile()) {
384
- const ext = path.extname(entry.name);
385
- if (['.ts', '.tsx', '.js', '.jsx', '.py', '.go', '.rs', '.java', '.kt', '.swift', '.rb', '.cs'].includes(ext)) {
386
- extensions.add(ext);
387
- }
388
- }
389
- }
390
- }
391
- // ============================================================================
392
- // Step 2: .claude/settings.json hooks
393
- // ============================================================================
394
- function generateHooks(root, force, answers) {
395
- const settingsPath = path.join(root, '.claude', 'settings.json');
396
- const settingsDir = path.dirname(settingsPath);
397
- if (!fs.existsSync(settingsDir)) {
398
- fs.mkdirSync(settingsDir, { recursive: true });
399
- }
400
- let existing = {};
401
- if (fs.existsSync(settingsPath)) {
402
- try {
403
- existing = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
404
- }
405
- catch { /* start fresh */ }
406
- // Check if MoFlo hooks already set up
407
- const settingsStr = JSON.stringify(existing);
408
- const hasGateHooks = settingsStr.includes('flo gate') || settingsStr.includes('moflo gate');
409
- if (hasGateHooks && !force) {
410
- return { name: '.claude/settings.json', status: 'skipped', detail: 'MoFlo hooks already configured' };
411
- }
412
- }
413
- // Build hooks config — all on by default (opinionated pit-of-success)
414
- const hooks = {
415
- "PreToolUse": [
416
- {
417
- "matcher": "^(Write|Edit|MultiEdit)$",
418
- "hooks": [{
419
- "type": "command",
420
- "command": "npx flo hooks pre-edit",
421
- "timeout": 5000
422
- }]
423
- },
424
- {
425
- "matcher": "^(Glob|Grep)$",
426
- "hooks": [{
427
- "type": "command",
428
- "command": "npx flo gate check-before-scan",
429
- "timeout": 3000
430
- }]
431
- },
432
- {
433
- "matcher": "^Read$",
434
- "hooks": [{
435
- "type": "command",
436
- "command": "npx flo gate check-before-read",
437
- "timeout": 3000
438
- }]
439
- },
440
- {
441
- "matcher": "^Task$",
442
- "hooks": [
443
- {
444
- "type": "command",
445
- "command": "npx flo gate check-before-agent",
446
- "timeout": 3000
447
- },
448
- {
449
- "type": "command",
450
- "command": "npx flo hooks pre-task",
451
- "timeout": 5000
452
- }
453
- ]
454
- },
455
- {
456
- "matcher": "^Bash$",
457
- "hooks": [{
458
- "type": "command",
459
- "command": "npx flo gate check-dangerous-command",
460
- "timeout": 2000
461
- }]
462
- }
463
- ],
464
- "PostToolUse": [
465
- {
466
- "matcher": "^(Write|Edit|MultiEdit)$",
467
- "hooks": [{
468
- "type": "command",
469
- "command": "npx flo hooks post-edit",
470
- "timeout": 5000
471
- }]
472
- },
473
- {
474
- "matcher": "^Task$",
475
- "hooks": [{
476
- "type": "command",
477
- "command": "npx flo hooks post-task",
478
- "timeout": 5000
479
- }]
480
- },
481
- {
482
- "matcher": "^TaskCreate$",
483
- "hooks": [{
484
- "type": "command",
485
- "command": "npx flo gate record-task-created",
486
- "timeout": 2000
487
- }]
488
- },
489
- {
490
- "matcher": "^Bash$",
491
- "hooks": [{
492
- "type": "command",
493
- "command": "npx flo gate check-bash-memory",
494
- "timeout": 2000
495
- }]
496
- },
497
- {
498
- "matcher": "^mcp__moflo__memory_(search|retrieve)$",
499
- "hooks": [{
500
- "type": "command",
501
- "command": "npx flo gate record-memory-searched",
502
- "timeout": 2000
503
- }]
504
- }
505
- ],
506
- "UserPromptSubmit": [
507
- {
508
- "hooks": [
509
- {
510
- "type": "command",
511
- "command": "npx flo gate prompt-reminder",
512
- "timeout": 2000
513
- },
514
- {
515
- "type": "command",
516
- "command": "npx flo hooks route",
517
- "timeout": 5000
518
- }
519
- ]
520
- }
521
- ],
522
- "SessionStart": [
523
- {
524
- "hooks": [
525
- {
526
- "type": "command",
527
- "command": "node \"$CLAUDE_PROJECT_DIR/.claude/scripts/session-start-launcher.mjs\"",
528
- "timeout": 3000
529
- }
530
- ]
531
- }
532
- ],
533
- "Stop": [
534
- {
535
- "hooks": [{
536
- "type": "command",
537
- "command": "npx flo hooks session-end",
538
- "timeout": 5000
539
- }]
540
- }
541
- ],
542
- "PreCompact": [
543
- {
544
- "hooks": [{
545
- "type": "command",
546
- "command": "npx flo gate compact-guidance",
547
- "timeout": 3000
548
- }]
549
- }
550
- ],
551
- "Notification": [
552
- {
553
- "hooks": [{
554
- "type": "command",
555
- "command": "npx flo hooks notification",
556
- "timeout": 3000
557
- }]
558
- }
559
- ]
560
- };
561
- // Merge: preserve existing non-MoFlo hooks, add MoFlo hooks
562
- existing.hooks = hooks;
563
- // Ensure statusLine is always present (required for dashboard display).
564
- // The executor.ts / settings-generator.ts code path adds this, but
565
- // moflo-init.ts uses its own generateHooks() which was missing it.
566
- if (!existing.statusLine) {
567
- existing.statusLine = {
568
- type: 'command',
569
- command: 'node "$CLAUDE_PROJECT_DIR/.claude/helpers/statusline.cjs"',
570
- };
571
- }
572
- fs.writeFileSync(settingsPath, JSON.stringify(existing, null, 2), 'utf-8');
573
- return { name: '.claude/settings.json', status: existing.hooks ? 'updated' : 'created', detail: '14 hooks configured (gates, lifecycle, routing, session)' };
574
- }
575
- // ============================================================================
576
- // Step 3: .claude/skills/flo/ skill (with /fl alias)
577
- // ============================================================================
578
- function generateSkill(root, force) {
579
- const skillDir = path.join(root, '.claude', 'skills', 'flo');
580
- const skillFile = path.join(skillDir, 'SKILL.md');
581
- const aliasDir = path.join(root, '.claude', 'skills', 'fl');
582
- const aliasFile = path.join(aliasDir, 'SKILL.md');
583
- if (fs.existsSync(skillFile) && !force) {
584
- return { name: '.claude/skills/flo/', status: 'skipped', detail: 'Already exists' };
585
- }
586
- if (!fs.existsSync(skillDir)) {
587
- fs.mkdirSync(skillDir, { recursive: true });
588
- }
589
- // Copy static SKILL.md from moflo package instead of generating it
590
- let skillContent = '';
591
- // Resolve this file's directory in ESM-safe way
592
- let thisDir;
593
- try {
594
- thisDir = path.dirname(fileURLToPath(import.meta.url));
595
- }
596
- catch {
597
- // Fallback for CJS or environments where import.meta.url is unavailable
598
- thisDir = typeof __dirname !== 'undefined' ? __dirname : '';
599
- }
600
- const staticSkillCandidates = [
601
- // Installed via npm (most common)
602
- path.join(root, 'node_modules', 'moflo', '.claude', 'skills', 'flo', 'SKILL.md'),
603
- // Running from moflo repo itself (dev)
604
- ...(thisDir ? [path.join(thisDir, '..', '..', '..', '..', '.claude', 'skills', 'flo', 'SKILL.md')] : []),
605
- ];
606
- for (const candidate of staticSkillCandidates) {
607
- try {
608
- if (fs.existsSync(candidate)) {
609
- skillContent = fs.readFileSync(candidate, 'utf-8');
610
- break;
611
- }
612
- }
613
- catch { /* skip inaccessible paths */ }
614
- }
615
- if (!skillContent) {
616
- return { name: '.claude/skills/flo/', status: 'error', detail: 'Could not find SKILL.md in moflo package' };
617
- }
618
- fs.writeFileSync(skillFile, skillContent, 'utf-8');
619
- // Create /fl alias (same content)
620
- if (!fs.existsSync(aliasDir)) {
621
- fs.mkdirSync(aliasDir, { recursive: true });
622
- }
623
- fs.writeFileSync(aliasFile, skillContent.replace('name: flo', 'name: fl'), 'utf-8');
624
- // Clean up old /mf skill directory if it exists
625
- const oldSkillDir = path.join(root, '.claude', 'skills', 'mf');
626
- if (fs.existsSync(oldSkillDir)) {
627
- fs.rmSync(oldSkillDir, { recursive: true });
628
- }
629
- return { name: '.claude/skills/flo/', status: 'created', detail: '/flo skill ready (alias: /fl)' };
630
- }
631
- // ============================================================================
632
- // Step 4: CLAUDE.md MoFlo section
633
- // ============================================================================
634
- // Markers for idempotent CLAUDE.md injection — keep in sync with claudemd-generator.ts
635
- const MOFLO_MARKER = '<!-- MOFLO:INJECTED:START -->';
636
- const MOFLO_MARKER_END = '<!-- MOFLO:INJECTED:END -->';
637
- // Also detect legacy markers so we can replace them
638
- const LEGACY_MARKERS = ['<!-- MOFLO:START -->', '<!-- MOFLO:SUBAGENT-PROTOCOL:START -->'];
639
- const LEGACY_MARKERS_END = ['<!-- MOFLO:END -->', '<!-- MOFLO:SUBAGENT-PROTOCOL:END -->'];
640
- function generateClaudeMd(root, force) {
641
- const claudeMdPath = path.join(root, 'CLAUDE.md');
642
- let existing = '';
643
- if (fs.existsSync(claudeMdPath)) {
644
- existing = fs.readFileSync(claudeMdPath, 'utf-8');
645
- // Check for current or legacy markers
646
- const allStartMarkers = [MOFLO_MARKER, ...LEGACY_MARKERS];
647
- const allEndMarkers = [MOFLO_MARKER_END, ...LEGACY_MARKERS_END];
648
- for (let i = 0; i < allStartMarkers.length; i++) {
649
- if (existing.includes(allStartMarkers[i])) {
650
- // Always strip the existing section so we can re-inject the latest version.
651
- // This ensures CLAUDE.md stays current when moflo updates its injected content.
652
- const startIdx = existing.indexOf(allStartMarkers[i]);
653
- const endIdx = existing.indexOf(allEndMarkers[i]);
654
- if (endIdx > startIdx) {
655
- existing = existing.substring(0, startIdx) + existing.substring(endIdx + allEndMarkers[i].length);
656
- }
657
- }
658
- }
659
- }
660
- // Minimal injection — just enough for Claude to work with moflo.
661
- // All detailed docs live in .claude/guidance/shipped/moflo.md.
371
+ `;
372
+ fs.writeFileSync(configPath, yaml, 'utf-8');
373
+ return { name: 'moflo.yaml', status: 'created', detail: `Detected: ${srcDirs.join(', ')} | ${detectedExts.join(', ')}` };
374
+ }
375
+ function scanExtensions(dir, extensions, depth, maxDepth) {
376
+ if (depth > maxDepth)
377
+ return;
378
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
379
+ for (const entry of entries.slice(0, 100)) {
380
+ if (entry.isDirectory() && !['node_modules', '.git', 'dist', 'build'].includes(entry.name)) {
381
+ scanExtensions(path.join(dir, entry.name), extensions, depth + 1, maxDepth);
382
+ }
383
+ else if (entry.isFile()) {
384
+ const ext = path.extname(entry.name);
385
+ if (['.ts', '.tsx', '.js', '.jsx', '.py', '.go', '.rs', '.java', '.kt', '.swift', '.rb', '.cs'].includes(ext)) {
386
+ extensions.add(ext);
387
+ }
388
+ }
389
+ }
390
+ }
391
+ // ============================================================================
392
+ // Step 2: .claude/settings.json hooks
393
+ // ============================================================================
394
+ function generateHooks(root, force, answers) {
395
+ const settingsPath = path.join(root, '.claude', 'settings.json');
396
+ const settingsDir = path.dirname(settingsPath);
397
+ if (!fs.existsSync(settingsDir)) {
398
+ fs.mkdirSync(settingsDir, { recursive: true });
399
+ }
400
+ let existing = {};
401
+ if (fs.existsSync(settingsPath)) {
402
+ try {
403
+ existing = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
404
+ }
405
+ catch { /* start fresh */ }
406
+ // Check if MoFlo hooks already set up
407
+ const settingsStr = JSON.stringify(existing);
408
+ const hasGateHooks = settingsStr.includes('flo gate') || settingsStr.includes('moflo gate');
409
+ if (hasGateHooks && !force) {
410
+ return { name: '.claude/settings.json', status: 'skipped', detail: 'MoFlo hooks already configured' };
411
+ }
412
+ }
413
+ // Build hooks config — all on by default (opinionated pit-of-success)
414
+ const hooks = {
415
+ "PreToolUse": [
416
+ {
417
+ "matcher": "^(Write|Edit|MultiEdit)$",
418
+ "hooks": [{
419
+ "type": "command",
420
+ "command": "npx flo hooks pre-edit",
421
+ "timeout": 5000
422
+ }]
423
+ },
424
+ {
425
+ "matcher": "^(Glob|Grep)$",
426
+ "hooks": [{
427
+ "type": "command",
428
+ "command": "npx flo gate check-before-scan",
429
+ "timeout": 3000
430
+ }]
431
+ },
432
+ {
433
+ "matcher": "^Read$",
434
+ "hooks": [{
435
+ "type": "command",
436
+ "command": "npx flo gate check-before-read",
437
+ "timeout": 3000
438
+ }]
439
+ },
440
+ {
441
+ "matcher": "^Task$",
442
+ "hooks": [
443
+ {
444
+ "type": "command",
445
+ "command": "npx flo gate check-before-agent",
446
+ "timeout": 3000
447
+ },
448
+ {
449
+ "type": "command",
450
+ "command": "npx flo hooks pre-task",
451
+ "timeout": 5000
452
+ }
453
+ ]
454
+ },
455
+ {
456
+ "matcher": "^Bash$",
457
+ "hooks": [{
458
+ "type": "command",
459
+ "command": "npx flo gate check-dangerous-command",
460
+ "timeout": 2000
461
+ }]
462
+ }
463
+ ],
464
+ "PostToolUse": [
465
+ {
466
+ "matcher": "^(Write|Edit|MultiEdit)$",
467
+ "hooks": [{
468
+ "type": "command",
469
+ "command": "npx flo hooks post-edit",
470
+ "timeout": 5000
471
+ }]
472
+ },
473
+ {
474
+ "matcher": "^Task$",
475
+ "hooks": [{
476
+ "type": "command",
477
+ "command": "npx flo hooks post-task",
478
+ "timeout": 5000
479
+ }]
480
+ },
481
+ {
482
+ "matcher": "^TaskCreate$",
483
+ "hooks": [{
484
+ "type": "command",
485
+ "command": "npx flo gate record-task-created",
486
+ "timeout": 2000
487
+ }]
488
+ },
489
+ {
490
+ "matcher": "^Bash$",
491
+ "hooks": [{
492
+ "type": "command",
493
+ "command": "npx flo gate check-bash-memory",
494
+ "timeout": 2000
495
+ }]
496
+ },
497
+ {
498
+ "matcher": "^mcp__moflo__memory_(search|retrieve)$",
499
+ "hooks": [{
500
+ "type": "command",
501
+ "command": "npx flo gate record-memory-searched",
502
+ "timeout": 2000
503
+ }]
504
+ }
505
+ ],
506
+ "UserPromptSubmit": [
507
+ {
508
+ "hooks": [
509
+ {
510
+ "type": "command",
511
+ "command": "npx flo gate prompt-reminder",
512
+ "timeout": 2000
513
+ },
514
+ {
515
+ "type": "command",
516
+ "command": "npx flo hooks route",
517
+ "timeout": 5000
518
+ }
519
+ ]
520
+ }
521
+ ],
522
+ "SessionStart": [
523
+ {
524
+ "hooks": [
525
+ {
526
+ "type": "command",
527
+ "command": "node \"$CLAUDE_PROJECT_DIR/.claude/scripts/session-start-launcher.mjs\"",
528
+ "timeout": 3000
529
+ }
530
+ ]
531
+ }
532
+ ],
533
+ "Stop": [
534
+ {
535
+ "hooks": [{
536
+ "type": "command",
537
+ "command": "npx flo hooks session-end",
538
+ "timeout": 5000
539
+ }]
540
+ }
541
+ ],
542
+ "PreCompact": [
543
+ {
544
+ "hooks": [{
545
+ "type": "command",
546
+ "command": "npx flo gate compact-guidance",
547
+ "timeout": 3000
548
+ }]
549
+ }
550
+ ],
551
+ "Notification": [
552
+ {
553
+ "hooks": [{
554
+ "type": "command",
555
+ "command": "npx flo hooks notification",
556
+ "timeout": 3000
557
+ }]
558
+ }
559
+ ]
560
+ };
561
+ // Merge: preserve existing non-MoFlo hooks, add MoFlo hooks
562
+ existing.hooks = hooks;
563
+ // Ensure statusLine is always present (required for dashboard display).
564
+ // The executor.ts / settings-generator.ts code path adds this, but
565
+ // moflo-init.ts uses its own generateHooks() which was missing it.
566
+ if (!existing.statusLine) {
567
+ existing.statusLine = {
568
+ type: 'command',
569
+ command: 'node "$CLAUDE_PROJECT_DIR/.claude/helpers/statusline.cjs"',
570
+ };
571
+ }
572
+ fs.writeFileSync(settingsPath, JSON.stringify(existing, null, 2), 'utf-8');
573
+ return { name: '.claude/settings.json', status: existing.hooks ? 'updated' : 'created', detail: '14 hooks configured (gates, lifecycle, routing, session)' };
574
+ }
575
+ // ============================================================================
576
+ // Step 3: .claude/skills/flo/ skill (with /fl alias)
577
+ // ============================================================================
578
+ function generateSkill(root, force) {
579
+ const skillDir = path.join(root, '.claude', 'skills', 'flo');
580
+ const skillFile = path.join(skillDir, 'SKILL.md');
581
+ const aliasDir = path.join(root, '.claude', 'skills', 'fl');
582
+ const aliasFile = path.join(aliasDir, 'SKILL.md');
583
+ if (fs.existsSync(skillFile) && !force) {
584
+ return { name: '.claude/skills/flo/', status: 'skipped', detail: 'Already exists' };
585
+ }
586
+ if (!fs.existsSync(skillDir)) {
587
+ fs.mkdirSync(skillDir, { recursive: true });
588
+ }
589
+ // Copy static SKILL.md from moflo package instead of generating it
590
+ let skillContent = '';
591
+ // Resolve this file's directory in ESM-safe way
592
+ let thisDir;
593
+ try {
594
+ thisDir = path.dirname(fileURLToPath(import.meta.url));
595
+ }
596
+ catch {
597
+ // Fallback for CJS or environments where import.meta.url is unavailable
598
+ thisDir = typeof __dirname !== 'undefined' ? __dirname : '';
599
+ }
600
+ const staticSkillCandidates = [
601
+ // Installed via npm (most common)
602
+ path.join(root, 'node_modules', 'moflo', '.claude', 'skills', 'flo', 'SKILL.md'),
603
+ // Running from moflo repo itself (dev)
604
+ ...(thisDir ? [path.join(thisDir, '..', '..', '..', '..', '.claude', 'skills', 'flo', 'SKILL.md')] : []),
605
+ ];
606
+ for (const candidate of staticSkillCandidates) {
607
+ try {
608
+ if (fs.existsSync(candidate)) {
609
+ skillContent = fs.readFileSync(candidate, 'utf-8');
610
+ break;
611
+ }
612
+ }
613
+ catch { /* skip inaccessible paths */ }
614
+ }
615
+ if (!skillContent) {
616
+ return { name: '.claude/skills/flo/', status: 'error', detail: 'Could not find SKILL.md in moflo package' };
617
+ }
618
+ fs.writeFileSync(skillFile, skillContent, 'utf-8');
619
+ // Create /fl alias (same content)
620
+ if (!fs.existsSync(aliasDir)) {
621
+ fs.mkdirSync(aliasDir, { recursive: true });
622
+ }
623
+ fs.writeFileSync(aliasFile, skillContent.replace('name: flo', 'name: fl'), 'utf-8');
624
+ // Clean up old /mf skill directory if it exists
625
+ const oldSkillDir = path.join(root, '.claude', 'skills', 'mf');
626
+ if (fs.existsSync(oldSkillDir)) {
627
+ fs.rmSync(oldSkillDir, { recursive: true });
628
+ }
629
+ return { name: '.claude/skills/flo/', status: 'created', detail: '/flo skill ready (alias: /fl)' };
630
+ }
631
+ // ============================================================================
632
+ // Step 4: CLAUDE.md MoFlo section
633
+ // ============================================================================
634
+ // Markers for idempotent CLAUDE.md injection — keep in sync with claudemd-generator.ts
635
+ const MOFLO_MARKER = '<!-- MOFLO:INJECTED:START -->';
636
+ const MOFLO_MARKER_END = '<!-- MOFLO:INJECTED:END -->';
637
+ // Also detect legacy markers so we can replace them
638
+ const LEGACY_MARKERS = ['<!-- MOFLO:START -->', '<!-- MOFLO:SUBAGENT-PROTOCOL:START -->'];
639
+ const LEGACY_MARKERS_END = ['<!-- MOFLO:END -->', '<!-- MOFLO:SUBAGENT-PROTOCOL:END -->'];
640
+ function generateClaudeMd(root, force) {
641
+ const claudeMdPath = path.join(root, 'CLAUDE.md');
642
+ let existing = '';
643
+ if (fs.existsSync(claudeMdPath)) {
644
+ existing = fs.readFileSync(claudeMdPath, 'utf-8');
645
+ // Check for current or legacy markers
646
+ const allStartMarkers = [MOFLO_MARKER, ...LEGACY_MARKERS];
647
+ const allEndMarkers = [MOFLO_MARKER_END, ...LEGACY_MARKERS_END];
648
+ for (let i = 0; i < allStartMarkers.length; i++) {
649
+ if (existing.includes(allStartMarkers[i])) {
650
+ // Always strip the existing section so we can re-inject the latest version.
651
+ // This ensures CLAUDE.md stays current when moflo updates its injected content.
652
+ const startIdx = existing.indexOf(allStartMarkers[i]);
653
+ const endIdx = existing.indexOf(allEndMarkers[i]);
654
+ if (endIdx > startIdx) {
655
+ existing = existing.substring(0, startIdx) + existing.substring(endIdx + allEndMarkers[i].length);
656
+ }
657
+ }
658
+ }
659
+ }
660
+ // Minimal injection — just enough for Claude to work with moflo.
661
+ // All detailed docs live in .claude/guidance/shipped/moflo-core-guidance.md.
662
662
  const mofloSection = `
663
663
  ${MOFLO_MARKER}
664
664
  ## MoFlo — AI Agent Orchestration
@@ -702,204 +702,204 @@ npx flo doctor --fix # Health check
702
702
  ### Full Reference
703
703
 
704
704
  For CLI commands, hooks, agents, swarm config, memory commands, and moflo.yaml options, see:
705
- \`.claude/guidance/shipped/moflo.md\`
705
+ \`.claude/guidance/shipped/moflo-core-guidance.md\`
706
706
  ${MOFLO_MARKER_END}
707
- `;
708
- const finalContent = existing.trimEnd() + '\n' + mofloSection;
709
- fs.writeFileSync(claudeMdPath, finalContent, 'utf-8');
710
- return {
711
- name: 'CLAUDE.md',
712
- status: existing ? 'updated' : 'created',
713
- detail: 'MoFlo section injected (~35 lines)',
714
- };
715
- }
716
- // ============================================================================
717
- // Step 5: .claude/scripts/ — sync from moflo bin/
718
- // These scripts are used by session-start hooks for indexing, code map, etc.
719
- // Always overwrite to keep them in sync with the installed moflo version.
720
- // ============================================================================
721
- const SCRIPT_MAP = {
722
- 'hooks.mjs': 'hooks.mjs',
723
- 'session-start-launcher.mjs': 'session-start-launcher.mjs',
724
- 'index-guidance.mjs': 'index-guidance.mjs',
725
- 'build-embeddings.mjs': 'build-embeddings.mjs',
726
- 'generate-code-map.mjs': 'generate-code-map.mjs',
727
- 'semantic-search.mjs': 'semantic-search.mjs',
728
- 'index-tests.mjs': 'index-tests.mjs',
729
- };
730
- function syncScripts(root, force) {
731
- const scriptsDir = path.join(root, '.claude', 'scripts');
732
- if (!fs.existsSync(scriptsDir)) {
733
- fs.mkdirSync(scriptsDir, { recursive: true });
734
- }
735
- // Find moflo bin/ directory
736
- let syncThisDir;
737
- try {
738
- syncThisDir = path.dirname(fileURLToPath(import.meta.url));
739
- }
740
- catch {
741
- syncThisDir = typeof __dirname !== 'undefined' ? __dirname : '';
742
- }
743
- const candidates = [
744
- path.join(root, 'node_modules', 'moflo', 'bin'),
745
- // When running from moflo repo itself
746
- ...(syncThisDir ? [path.join(syncThisDir, '..', '..', '..', '..', 'bin')] : []),
747
- ];
748
- const binDir = candidates.find(d => { try {
749
- return fs.existsSync(d);
750
- }
751
- catch {
752
- return false;
753
- } });
754
- if (!binDir) {
755
- return { name: '.claude/scripts/', status: 'skipped', detail: 'moflo bin/ not found' };
756
- }
757
- let copied = 0;
758
- for (const [dest, src] of Object.entries(SCRIPT_MAP)) {
759
- const srcPath = path.join(binDir, src);
760
- const destPath = path.join(scriptsDir, dest);
761
- if (!fs.existsSync(srcPath))
762
- continue;
763
- // Always overwrite scripts to keep in sync (they're derived, not user-edited)
764
- if (!fs.existsSync(destPath) || force || isStale(srcPath, destPath)) {
765
- fs.copyFileSync(srcPath, destPath);
766
- copied++;
767
- }
768
- }
769
- if (copied === 0) {
770
- return { name: '.claude/scripts/', status: 'skipped', detail: 'Scripts already up to date' };
771
- }
772
- return { name: '.claude/scripts/', status: 'updated', detail: `${copied} scripts synced from moflo` };
773
- }
774
- function isStale(srcPath, destPath) {
775
- try {
776
- return fs.statSync(srcPath).mtimeMs > fs.statSync(destPath).mtimeMs;
777
- }
778
- catch {
779
- return true;
780
- }
781
- }
782
- // ============================================================================
783
- // Step 6: .gitignore
784
- // ============================================================================
785
- function updateGitignore(root) {
786
- const gitignorePath = path.join(root, '.gitignore');
787
- const entries = ['.claude-epic/', '.swarm/', '.moflo/'];
788
- if (!fs.existsSync(gitignorePath)) {
789
- // Create .gitignore with common defaults + MoFlo entries
790
- const defaultEntries = ['node_modules/', 'dist/', '.env', '.env.*', ''];
791
- const content = '# Dependencies\n' + defaultEntries.join('\n') + '\n# MoFlo state\n' + entries.join('\n') + '\n';
792
- fs.writeFileSync(gitignorePath, content, 'utf-8');
793
- return { name: '.gitignore', status: 'created', detail: 'Created with node_modules, .env, and MoFlo entries' };
794
- }
795
- const existing = fs.readFileSync(gitignorePath, 'utf-8');
796
- const toAdd = entries.filter(e => !existing.includes(e));
797
- if (toAdd.length === 0) {
798
- return { name: '.gitignore', status: 'skipped', detail: 'Entries already present' };
799
- }
800
- fs.appendFileSync(gitignorePath, '\n# MoFlo state (gitignored)\n' + toAdd.join('\n') + '\n');
801
- return { name: '.gitignore', status: 'updated', detail: `Added: ${toAdd.join(', ')}` };
802
- }
803
- // ============================================================================
804
- // Step 7: .claude/guidance/moflo-bootstrap.md
805
- // Copies the agent bootstrap guidance to the project so subagents can read it
806
- // from disk without requiring memory search.
807
- // ============================================================================
808
- function syncBootstrapGuidance(root, force) {
809
- const guidanceDir = path.join(root, '.claude', 'guidance');
810
- const targetFile = path.join(guidanceDir, 'moflo-bootstrap.md');
811
- // Find the source bootstrap file from the moflo package
812
- let sourceDir;
813
- try {
814
- sourceDir = path.dirname(fileURLToPath(import.meta.url));
815
- }
816
- catch {
817
- sourceDir = typeof __dirname !== 'undefined' ? __dirname : '';
818
- }
819
- const candidates = [
820
- path.join(root, 'node_modules', 'moflo', '.claude', 'guidance', 'shipped', 'moflo-subagents.md'),
821
- // When running from moflo repo itself
822
- ...(sourceDir ? [path.join(sourceDir, '..', '..', '..', '..', '.claude', 'guidance', 'shipped', 'moflo-subagents.md')] : []),
823
- ];
824
- const sourceFile = candidates.find(f => { try {
825
- return fs.existsSync(f);
826
- }
827
- catch {
828
- return false;
829
- } });
830
- if (!sourceFile) {
831
- return { name: 'guidance/moflo-bootstrap.md', status: 'skipped', detail: 'Source bootstrap not found' };
832
- }
833
- // Check if target exists and is up to date
834
- if (fs.existsSync(targetFile) && !force) {
835
- if (!isStale(sourceFile, targetFile)) {
836
- return { name: 'guidance/moflo-bootstrap.md', status: 'skipped', detail: 'Already up to date' };
837
- }
838
- }
839
- // Read source and prepend header
840
- const content = fs.readFileSync(sourceFile, 'utf-8');
841
- const header = `<!-- AUTO-GENERATED by moflo init. Do not edit — changes will be overwritten on next init. -->\n<!-- Source: moflo/.claude/guidance/shipped/moflo-subagents.md -->\n<!-- To customize, create your own project-specific guidance in .claude/guidance/. -->\n\n`;
842
- fs.mkdirSync(guidanceDir, { recursive: true });
843
- fs.writeFileSync(targetFile, header + content, 'utf-8');
844
- return {
845
- name: 'guidance/moflo-bootstrap.md',
846
- status: fs.existsSync(targetFile) ? 'updated' : 'created',
847
- detail: 'Subagent bootstrap protocol'
848
- };
849
- }
850
- // ============================================================================
851
- // Step 8: Sync ALL shipped guidance docs
852
- // Discovers all .md files in moflo/.claude/guidance/shipped/ and copies them
853
- // to project .claude/guidance/. Skips moflo-subagents.md (handled by Step 7).
854
- // ============================================================================
855
- function syncAllShippedGuidance(root, force) {
856
- const guidanceDir = path.join(root, '.claude', 'guidance');
857
- let sourceDir;
858
- try {
859
- sourceDir = path.dirname(fileURLToPath(import.meta.url));
860
- }
861
- catch {
862
- sourceDir = typeof __dirname !== 'undefined' ? __dirname : '';
863
- }
864
- // Find the shipped guidance directory
865
- const shippedCandidates = [
866
- path.join(root, 'node_modules', 'moflo', '.claude', 'guidance', 'shipped'),
867
- ...(sourceDir ? [path.join(sourceDir, '..', '..', '..', '..', '.claude', 'guidance', 'shipped')] : []),
868
- ];
869
- const shippedDir = shippedCandidates.find(d => { try {
870
- return fs.existsSync(d) && fs.statSync(d).isDirectory();
871
- }
872
- catch {
873
- return false;
874
- } });
875
- if (!shippedDir) {
876
- return [{ name: 'guidance/shipped/*', status: 'skipped', detail: 'Shipped guidance directory not found' }];
877
- }
878
- // Discover all .md files, skip moflo-subagents.md (synced separately as moflo-bootstrap.md)
879
- const files = fs.readdirSync(shippedDir).filter(f => f.endsWith('.md') && f !== 'moflo-subagents.md');
880
- if (files.length === 0) {
881
- return [{ name: 'guidance/shipped/*', status: 'skipped', detail: 'No shipped guidance files found' }];
882
- }
883
- const results = [];
884
- for (const filename of files) {
885
- const sourceFile = path.join(shippedDir, filename);
886
- const targetFile = path.join(guidanceDir, filename);
887
- if (fs.existsSync(targetFile) && !force) {
888
- if (!isStale(sourceFile, targetFile)) {
889
- results.push({ name: `guidance/${filename}`, status: 'skipped', detail: 'Already up to date' });
890
- continue;
891
- }
892
- }
893
- const content = fs.readFileSync(sourceFile, 'utf-8');
894
- const header = `<!-- AUTO-GENERATED by moflo init. Do not edit — changes will be overwritten on next init. -->\n<!-- Source: moflo/.claude/guidance/shipped/${filename} -->\n\n`;
895
- fs.mkdirSync(guidanceDir, { recursive: true });
896
- fs.writeFileSync(targetFile, header + content, 'utf-8');
897
- results.push({
898
- name: `guidance/${filename}`,
899
- status: 'updated',
900
- detail: `Shipped guidance synced`,
901
- });
902
- }
903
- return results;
904
- }
707
+ `;
708
+ const finalContent = existing.trimEnd() + '\n' + mofloSection;
709
+ fs.writeFileSync(claudeMdPath, finalContent, 'utf-8');
710
+ return {
711
+ name: 'CLAUDE.md',
712
+ status: existing ? 'updated' : 'created',
713
+ detail: 'MoFlo section injected (~35 lines)',
714
+ };
715
+ }
716
+ // ============================================================================
717
+ // Step 5: .claude/scripts/ — sync from moflo bin/
718
+ // These scripts are used by session-start hooks for indexing, code map, etc.
719
+ // Always overwrite to keep them in sync with the installed moflo version.
720
+ // ============================================================================
721
+ const SCRIPT_MAP = {
722
+ 'hooks.mjs': 'hooks.mjs',
723
+ 'session-start-launcher.mjs': 'session-start-launcher.mjs',
724
+ 'index-guidance.mjs': 'index-guidance.mjs',
725
+ 'build-embeddings.mjs': 'build-embeddings.mjs',
726
+ 'generate-code-map.mjs': 'generate-code-map.mjs',
727
+ 'semantic-search.mjs': 'semantic-search.mjs',
728
+ 'index-tests.mjs': 'index-tests.mjs',
729
+ };
730
+ function syncScripts(root, force) {
731
+ const scriptsDir = path.join(root, '.claude', 'scripts');
732
+ if (!fs.existsSync(scriptsDir)) {
733
+ fs.mkdirSync(scriptsDir, { recursive: true });
734
+ }
735
+ // Find moflo bin/ directory
736
+ let syncThisDir;
737
+ try {
738
+ syncThisDir = path.dirname(fileURLToPath(import.meta.url));
739
+ }
740
+ catch {
741
+ syncThisDir = typeof __dirname !== 'undefined' ? __dirname : '';
742
+ }
743
+ const candidates = [
744
+ path.join(root, 'node_modules', 'moflo', 'bin'),
745
+ // When running from moflo repo itself
746
+ ...(syncThisDir ? [path.join(syncThisDir, '..', '..', '..', '..', 'bin')] : []),
747
+ ];
748
+ const binDir = candidates.find(d => { try {
749
+ return fs.existsSync(d);
750
+ }
751
+ catch {
752
+ return false;
753
+ } });
754
+ if (!binDir) {
755
+ return { name: '.claude/scripts/', status: 'skipped', detail: 'moflo bin/ not found' };
756
+ }
757
+ let copied = 0;
758
+ for (const [dest, src] of Object.entries(SCRIPT_MAP)) {
759
+ const srcPath = path.join(binDir, src);
760
+ const destPath = path.join(scriptsDir, dest);
761
+ if (!fs.existsSync(srcPath))
762
+ continue;
763
+ // Always overwrite scripts to keep in sync (they're derived, not user-edited)
764
+ if (!fs.existsSync(destPath) || force || isStale(srcPath, destPath)) {
765
+ fs.copyFileSync(srcPath, destPath);
766
+ copied++;
767
+ }
768
+ }
769
+ if (copied === 0) {
770
+ return { name: '.claude/scripts/', status: 'skipped', detail: 'Scripts already up to date' };
771
+ }
772
+ return { name: '.claude/scripts/', status: 'updated', detail: `${copied} scripts synced from moflo` };
773
+ }
774
+ function isStale(srcPath, destPath) {
775
+ try {
776
+ return fs.statSync(srcPath).mtimeMs > fs.statSync(destPath).mtimeMs;
777
+ }
778
+ catch {
779
+ return true;
780
+ }
781
+ }
782
+ // ============================================================================
783
+ // Step 6: .gitignore
784
+ // ============================================================================
785
+ function updateGitignore(root) {
786
+ const gitignorePath = path.join(root, '.gitignore');
787
+ const entries = ['.claude-epic/', '.swarm/', '.moflo/'];
788
+ if (!fs.existsSync(gitignorePath)) {
789
+ // Create .gitignore with common defaults + MoFlo entries
790
+ const defaultEntries = ['node_modules/', 'dist/', '.env', '.env.*', ''];
791
+ const content = '# Dependencies\n' + defaultEntries.join('\n') + '\n# MoFlo state\n' + entries.join('\n') + '\n';
792
+ fs.writeFileSync(gitignorePath, content, 'utf-8');
793
+ return { name: '.gitignore', status: 'created', detail: 'Created with node_modules, .env, and MoFlo entries' };
794
+ }
795
+ const existing = fs.readFileSync(gitignorePath, 'utf-8');
796
+ const toAdd = entries.filter(e => !existing.includes(e));
797
+ if (toAdd.length === 0) {
798
+ return { name: '.gitignore', status: 'skipped', detail: 'Entries already present' };
799
+ }
800
+ fs.appendFileSync(gitignorePath, '\n# MoFlo state (gitignored)\n' + toAdd.join('\n') + '\n');
801
+ return { name: '.gitignore', status: 'updated', detail: `Added: ${toAdd.join(', ')}` };
802
+ }
803
+ // ============================================================================
804
+ // Step 7: .claude/guidance/moflo-bootstrap.md
805
+ // Copies the agent bootstrap guidance to the project so subagents can read it
806
+ // from disk without requiring memory search.
807
+ // ============================================================================
808
+ function syncBootstrapGuidance(root, force) {
809
+ const guidanceDir = path.join(root, '.claude', 'guidance');
810
+ const targetFile = path.join(guidanceDir, 'moflo-bootstrap.md');
811
+ // Find the source bootstrap file from the moflo package
812
+ let sourceDir;
813
+ try {
814
+ sourceDir = path.dirname(fileURLToPath(import.meta.url));
815
+ }
816
+ catch {
817
+ sourceDir = typeof __dirname !== 'undefined' ? __dirname : '';
818
+ }
819
+ const candidates = [
820
+ path.join(root, 'node_modules', 'moflo', '.claude', 'guidance', 'shipped', 'moflo-subagents.md'),
821
+ // When running from moflo repo itself
822
+ ...(sourceDir ? [path.join(sourceDir, '..', '..', '..', '..', '.claude', 'guidance', 'shipped', 'moflo-subagents.md')] : []),
823
+ ];
824
+ const sourceFile = candidates.find(f => { try {
825
+ return fs.existsSync(f);
826
+ }
827
+ catch {
828
+ return false;
829
+ } });
830
+ if (!sourceFile) {
831
+ return { name: 'guidance/moflo-bootstrap.md', status: 'skipped', detail: 'Source bootstrap not found' };
832
+ }
833
+ // Check if target exists and is up to date
834
+ if (fs.existsSync(targetFile) && !force) {
835
+ if (!isStale(sourceFile, targetFile)) {
836
+ return { name: 'guidance/moflo-bootstrap.md', status: 'skipped', detail: 'Already up to date' };
837
+ }
838
+ }
839
+ // Read source and prepend header
840
+ const content = fs.readFileSync(sourceFile, 'utf-8');
841
+ const header = `<!-- AUTO-GENERATED by moflo init. Do not edit — changes will be overwritten on next init. -->\n<!-- Source: moflo/.claude/guidance/shipped/moflo-subagents.md -->\n<!-- To customize, create your own project-specific guidance in .claude/guidance/. -->\n\n`;
842
+ fs.mkdirSync(guidanceDir, { recursive: true });
843
+ fs.writeFileSync(targetFile, header + content, 'utf-8');
844
+ return {
845
+ name: 'guidance/moflo-bootstrap.md',
846
+ status: fs.existsSync(targetFile) ? 'updated' : 'created',
847
+ detail: 'Subagent bootstrap protocol'
848
+ };
849
+ }
850
+ // ============================================================================
851
+ // Step 8: Sync ALL shipped guidance docs
852
+ // Discovers all .md files in moflo/.claude/guidance/shipped/ and copies them
853
+ // to project .claude/guidance/. Skips moflo-subagents.md (handled by Step 7).
854
+ // ============================================================================
855
+ function syncAllShippedGuidance(root, force) {
856
+ const guidanceDir = path.join(root, '.claude', 'guidance');
857
+ let sourceDir;
858
+ try {
859
+ sourceDir = path.dirname(fileURLToPath(import.meta.url));
860
+ }
861
+ catch {
862
+ sourceDir = typeof __dirname !== 'undefined' ? __dirname : '';
863
+ }
864
+ // Find the shipped guidance directory
865
+ const shippedCandidates = [
866
+ path.join(root, 'node_modules', 'moflo', '.claude', 'guidance', 'shipped'),
867
+ ...(sourceDir ? [path.join(sourceDir, '..', '..', '..', '..', '.claude', 'guidance', 'shipped')] : []),
868
+ ];
869
+ const shippedDir = shippedCandidates.find(d => { try {
870
+ return fs.existsSync(d) && fs.statSync(d).isDirectory();
871
+ }
872
+ catch {
873
+ return false;
874
+ } });
875
+ if (!shippedDir) {
876
+ return [{ name: 'guidance/shipped/*', status: 'skipped', detail: 'Shipped guidance directory not found' }];
877
+ }
878
+ // Discover all .md files, skip moflo-subagents.md (synced separately as moflo-bootstrap.md)
879
+ const files = fs.readdirSync(shippedDir).filter(f => f.endsWith('.md') && f !== 'moflo-subagents.md');
880
+ if (files.length === 0) {
881
+ return [{ name: 'guidance/shipped/*', status: 'skipped', detail: 'No shipped guidance files found' }];
882
+ }
883
+ const results = [];
884
+ for (const filename of files) {
885
+ const sourceFile = path.join(shippedDir, filename);
886
+ const targetFile = path.join(guidanceDir, filename);
887
+ if (fs.existsSync(targetFile) && !force) {
888
+ if (!isStale(sourceFile, targetFile)) {
889
+ results.push({ name: `guidance/${filename}`, status: 'skipped', detail: 'Already up to date' });
890
+ continue;
891
+ }
892
+ }
893
+ const content = fs.readFileSync(sourceFile, 'utf-8');
894
+ const header = `<!-- AUTO-GENERATED by moflo init. Do not edit — changes will be overwritten on next init. -->\n<!-- Source: moflo/.claude/guidance/shipped/${filename} -->\n\n`;
895
+ fs.mkdirSync(guidanceDir, { recursive: true });
896
+ fs.writeFileSync(targetFile, header + content, 'utf-8');
897
+ results.push({
898
+ name: `guidance/${filename}`,
899
+ status: 'updated',
900
+ detail: `Shipped guidance synced`,
901
+ });
902
+ }
903
+ return results;
904
+ }
905
905
  //# sourceMappingURL=moflo-init.js.map