monomind 1.8.0 → 1.9.0

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 (566) hide show
  1. package/.claude/agents/design/design-monodesign.md +121 -0
  2. package/.claude/agents/github/issue-tracker.md +12 -12
  3. package/.claude/agents/github/pr-manager.md +10 -10
  4. package/.claude/agents/github/release-manager.md +49 -105
  5. package/.claude/agents/github/repo-architect.md +73 -92
  6. package/.claude/agents/github/sync-coordinator.md +55 -123
  7. package/.claude/agents/marketing/marketing-competitive-content.md +155 -0
  8. package/.claude/agents/marketing/marketing-content-creator.md +13 -0
  9. package/.claude/agents/marketing/marketing-cro-specialist.md +147 -0
  10. package/.claude/agents/marketing/marketing-email-specialist.md +90 -0
  11. package/.claude/agents/marketing/marketing-launch-strategist.md +129 -0
  12. package/.claude/agents/marketing/marketing-pricing-strategist.md +127 -0
  13. package/.claude/agents/specialists/integration-architect.md +94 -0
  14. package/.claude/commands/agents/README.md +4 -0
  15. package/.claude/commands/agents/agent-capabilities.md +6 -2
  16. package/.claude/commands/agents/agent-coordination.md +4 -0
  17. package/.claude/commands/agents/agent-spawning.md +4 -0
  18. package/.claude/commands/agents/agent-types.md +6 -2
  19. package/.claude/commands/analysis/README.md +14 -5
  20. package/.claude/commands/analysis/bottleneck-detect.md +30 -123
  21. package/.claude/commands/analysis/performance-bottlenecks.md +14 -14
  22. package/.claude/commands/analysis/performance-report.md +38 -11
  23. package/.claude/commands/analysis/token-efficiency.md +13 -16
  24. package/.claude/commands/analysis/token-usage.md +34 -12
  25. package/.claude/commands/automation/README.md +15 -5
  26. package/.claude/commands/automation/auto-agent.md +49 -85
  27. package/.claude/commands/automation/self-healing.md +20 -18
  28. package/.claude/commands/automation/session-memory.md +28 -29
  29. package/.claude/commands/automation/smart-agents.md +17 -9
  30. package/.claude/commands/automation/smart-spawn.md +52 -11
  31. package/.claude/commands/automation/workflow-select.md +46 -11
  32. package/.claude/commands/browse.md +5 -0
  33. package/.claude/commands/coordination/README.md +9 -5
  34. package/.claude/commands/coordination/agent-spawn.md +53 -9
  35. package/.claude/commands/coordination/swarm-init.md +39 -42
  36. package/.claude/commands/coordination/task-orchestrate.md +65 -11
  37. package/.claude/commands/github/README.md +21 -8
  38. package/.claude/commands/github/github-modes.md +9 -5
  39. package/.claude/commands/github/issue-tracker.md +34 -33
  40. package/.claude/commands/github/pr-manager.md +20 -17
  41. package/.claude/commands/github/release-manager.md +37 -49
  42. package/.claude/commands/github/repo-architect.md +39 -41
  43. package/.claude/commands/github/sync-coordinator.md +45 -49
  44. package/.claude/commands/hive-mind/README.md +42 -17
  45. package/.claude/commands/hive-mind/hive-mind-consensus.md +68 -4
  46. package/.claude/commands/hive-mind/hive-mind-init.md +55 -5
  47. package/.claude/commands/hive-mind/hive-mind-memory.md +69 -4
  48. package/.claude/commands/hive-mind/hive-mind-spawn.md +71 -10
  49. package/.claude/commands/hive-mind/hive-mind-status.md +52 -4
  50. package/.claude/commands/hive-mind/hive-mind-stop.md +51 -4
  51. package/.claude/commands/hive-mind/hive-mind.md +74 -14
  52. package/.claude/commands/hooks/README.md +62 -7
  53. package/.claude/commands/hooks/overview.md +94 -35
  54. package/.claude/commands/hooks/post-edit.md +48 -87
  55. package/.claude/commands/hooks/post-task.md +37 -87
  56. package/.claude/commands/hooks/pre-edit.md +52 -84
  57. package/.claude/commands/hooks/pre-task.md +46 -81
  58. package/.claude/commands/hooks/session-end.md +49 -85
  59. package/.claude/commands/hooks/setup.md +87 -58
  60. package/.claude/commands/mastermind/_repeat.md +308 -0
  61. package/.claude/commands/mastermind/architect.md +49 -0
  62. package/.claude/commands/mastermind/brain.md +98 -0
  63. package/.claude/commands/mastermind/build.md +22 -0
  64. package/.claude/commands/mastermind/content.md +22 -0
  65. package/.claude/commands/mastermind/createorg.md +94 -0
  66. package/.claude/commands/mastermind/finance.md +22 -0
  67. package/.claude/commands/mastermind/idea.md +22 -0
  68. package/.claude/commands/mastermind/marketing.md +22 -0
  69. package/.claude/commands/mastermind/master.md +379 -0
  70. package/.claude/commands/mastermind/ops.md +22 -0
  71. package/.claude/commands/mastermind/release.md +22 -0
  72. package/.claude/commands/mastermind/research.md +22 -0
  73. package/.claude/commands/mastermind/review.md +22 -0
  74. package/.claude/commands/mastermind/runorg.md +106 -0
  75. package/.claude/commands/mastermind/sales.md +22 -0
  76. package/.claude/commands/mastermind/techport.md +17 -0
  77. package/.claude/commands/memory/README.md +75 -5
  78. package/.claude/commands/memory/memory-search.md +63 -11
  79. package/.claude/commands/monitoring/README.md +64 -4
  80. package/.claude/commands/monitoring/agent-metrics.md +50 -10
  81. package/.claude/commands/monitoring/agents.md +59 -32
  82. package/.claude/commands/monitoring/status.md +96 -34
  83. package/.claude/commands/monograph/README.md +102 -0
  84. package/.claude/commands/monograph/monograph-build.md +79 -0
  85. package/.claude/commands/monograph/monograph-search.md +96 -0
  86. package/.claude/commands/monograph/monograph-stats.md +53 -0
  87. package/.claude/commands/monograph/monograph-watch.md +63 -0
  88. package/.claude/commands/monograph/monograph-wiki.md +91 -0
  89. package/.claude/commands/monomind/createtask.md +277 -0
  90. package/.claude/commands/{monomind-do.md → monomind/do.md} +21 -8
  91. package/.claude/commands/monomind/help.md +118 -0
  92. package/.claude/commands/{monomind-idea.md → monomind/idea.md} +22 -28
  93. package/.claude/commands/{monomind-improve.md → monomind/improve.md} +21 -27
  94. package/.claude/commands/monomind/memory.md +230 -0
  95. package/.claude/commands/monomind/repeat.md +201 -0
  96. package/.claude/commands/monomind/review.md +313 -0
  97. package/.claude/commands/monomind/specialagents.md +125 -0
  98. package/.claude/commands/monomind/swarm.md +161 -0
  99. package/.claude/commands/monomind/understand.md +148 -0
  100. package/.claude/commands/optimization/README.md +69 -5
  101. package/.claude/commands/optimization/auto-topology.md +66 -43
  102. package/.claude/commands/optimization/parallel-execution.md +65 -39
  103. package/.claude/commands/optimization/performance-optimize.md +79 -0
  104. package/.claude/commands/pair/README.md +48 -230
  105. package/.claude/commands/pair/examples.md +85 -441
  106. package/.claude/commands/pair/modes.md +77 -303
  107. package/.claude/commands/pair/session.md +76 -359
  108. package/.claude/commands/sparc/analyzer.md +9 -26
  109. package/.claude/commands/sparc/architect.md +8 -25
  110. package/.claude/commands/sparc/ask.md +27 -68
  111. package/.claude/commands/sparc/batch-executor.md +8 -25
  112. package/.claude/commands/sparc/code.md +12 -53
  113. package/.claude/commands/sparc/coder.md +8 -25
  114. package/.claude/commands/sparc/debug.md +12 -53
  115. package/.claude/commands/sparc/debugger.md +8 -25
  116. package/.claude/commands/sparc/designer.md +8 -25
  117. package/.claude/commands/sparc/devops.md +16 -57
  118. package/.claude/commands/sparc/docs-writer.md +12 -53
  119. package/.claude/commands/sparc/documenter.md +8 -25
  120. package/.claude/commands/sparc/innovator.md +8 -25
  121. package/.claude/commands/sparc/integration.md +12 -53
  122. package/.claude/commands/sparc/mcp.md +12 -53
  123. package/.claude/commands/sparc/memory-manager.md +28 -25
  124. package/.claude/commands/sparc/optimizer.md +8 -25
  125. package/.claude/commands/sparc/orchestrator.md +35 -97
  126. package/.claude/commands/sparc/post-deployment-monitoring-mode.md +13 -54
  127. package/.claude/commands/sparc/refinement-optimization-mode.md +13 -54
  128. package/.claude/commands/sparc/researcher.md +8 -25
  129. package/.claude/commands/sparc/reviewer.md +8 -25
  130. package/.claude/commands/sparc/security-review.md +13 -54
  131. package/.claude/commands/sparc/sparc-modes.md +97 -151
  132. package/.claude/commands/sparc/sparc.md +16 -56
  133. package/.claude/commands/sparc/spec-pseudocode.md +13 -54
  134. package/.claude/commands/sparc/supabase-admin.md +19 -66
  135. package/.claude/commands/sparc/swarm-coordinator.md +21 -25
  136. package/.claude/commands/sparc/tdd.md +8 -25
  137. package/.claude/commands/sparc/tester.md +8 -25
  138. package/.claude/commands/sparc/tutorial.md +12 -53
  139. package/.claude/commands/sparc/workflow-manager.md +8 -25
  140. package/.claude/commands/sparc.md +76 -130
  141. package/.claude/commands/stream-chain/pipeline.md +72 -77
  142. package/.claude/commands/stream-chain/run.md +133 -47
  143. package/.claude/commands/swarm/README.md +37 -12
  144. package/.claude/commands/swarm/analysis.md +47 -69
  145. package/.claude/commands/swarm/development.md +45 -69
  146. package/.claude/commands/swarm/examples.md +77 -142
  147. package/.claude/commands/swarm/maintenance.md +47 -74
  148. package/.claude/commands/swarm/optimization.md +54 -87
  149. package/.claude/commands/swarm/research.md +47 -107
  150. package/.claude/commands/swarm/swarm-analysis.md +58 -4
  151. package/.claude/commands/swarm/swarm-background.md +61 -4
  152. package/.claude/commands/swarm/swarm-modes.md +63 -4
  153. package/.claude/commands/swarm/swarm-monitor.md +50 -4
  154. package/.claude/commands/swarm/swarm-status.md +40 -4
  155. package/.claude/commands/swarm/swarm-strategies.md +73 -5
  156. package/.claude/commands/swarm/swarm.md +70 -18
  157. package/.claude/commands/swarm/testing.md +51 -102
  158. package/.claude/commands/tokens.md +6 -1
  159. package/.claude/commands/training/README.md +36 -6
  160. package/.claude/commands/training/model-update.md +68 -15
  161. package/.claude/commands/training/neural-patterns.md +54 -55
  162. package/.claude/commands/training/neural-train.md +70 -16
  163. package/.claude/commands/training/pattern-learn.md +60 -16
  164. package/.claude/commands/training/specialization.md +78 -49
  165. package/.claude/commands/truth/start.md +87 -109
  166. package/.claude/commands/ts.md +7 -2
  167. package/.claude/commands/verify/check.md +90 -34
  168. package/.claude/commands/verify/start.md +71 -94
  169. package/.claude/commands/workflows/README.md +62 -6
  170. package/.claude/commands/workflows/development.md +69 -61
  171. package/.claude/commands/workflows/research.md +73 -47
  172. package/.claude/commands/workflows/workflow-create.md +75 -16
  173. package/.claude/commands/workflows/workflow-execute.md +94 -16
  174. package/.claude/commands/workflows/workflow-export.md +81 -16
  175. package/.claude/helpers/control-start.cjs +91 -0
  176. package/.claude/helpers/extras-registry.json +4104 -1991
  177. package/.claude/helpers/graphify-freshen.cjs +44 -13
  178. package/.claude/helpers/hook-handler.cjs +256 -1
  179. package/.claude/helpers/learning-service.mjs +0 -0
  180. package/.claude/helpers/loop-tracker.cjs +107 -0
  181. package/.claude/helpers/metrics-db.mjs +0 -0
  182. package/.claude/helpers/router.cjs +48 -68
  183. package/.claude/helpers/skill-registry.json +89 -104
  184. package/.claude/helpers/statusline.cjs +33 -2
  185. package/.claude/helpers/swarm-hooks.sh +0 -0
  186. package/.claude/scheduled_tasks.lock +1 -0
  187. package/.claude/settings.json +15 -0
  188. package/.claude/skills/.monomind/data/ranked-context.json +5 -0
  189. package/.claude/skills/.monomind/sessions/current.json +13 -0
  190. package/.claude/skills/.monomind/sessions/session-1777829336455.json +15 -0
  191. package/.claude/skills/.monomind/sessions/session-1777831614725.json +15 -0
  192. package/.claude/skills/.monomind/sessions/session-1777832095857.json +15 -0
  193. package/.claude/skills/.monomind/sessions/session-1777839814183.json +15 -0
  194. package/.claude/skills/.monomind/sessions/session-1777841847131.json +15 -0
  195. package/.claude/skills/.monomind/sessions/session-1777843309463.json +15 -0
  196. package/.claude/skills/.monomind/sessions/session-1777880867159.json +15 -0
  197. package/.claude/skills/.monomind/sessions/session-1777881884593.json +15 -0
  198. package/.claude/skills/.monomind/sessions/session-1777884090471.json +15 -0
  199. package/.claude/skills/.monomind/sessions/session-1777884808221.json +15 -0
  200. package/.claude/skills/.monomind/sessions/session-1777885672155.json +15 -0
  201. package/.claude/skills/.monomind/sessions/session-1777886852818.json +15 -0
  202. package/.claude/skills/.monomind/sessions/session-1777896532690.json +15 -0
  203. package/.claude/skills/agentdb-advanced/SKILL.md +11 -12
  204. package/.claude/skills/agentdb-learning/SKILL.md +20 -21
  205. package/.claude/skills/agentdb-memory-patterns/SKILL.md +28 -30
  206. package/.claude/skills/agentdb-optimization/SKILL.md +11 -12
  207. package/.claude/skills/agentdb-vector-search/SKILL.md +37 -41
  208. package/.claude/skills/{v3-integration-deep → agentic-integration}/SKILL.md +20 -13
  209. package/.claude/skills/agentic-jujutsu/SKILL.md +22 -22
  210. package/.claude/skills/{v3-cli-modernization → cli-modernization}/SKILL.md +17 -8
  211. package/.claude/skills/{v3-core-implementation → core-implementation}/SKILL.md +33 -8
  212. package/.claude/skills/{v3-ddd-architecture → ddd-architecture}/SKILL.md +18 -25
  213. package/.claude/skills/github-code-review/SKILL.md +82 -83
  214. package/.claude/skills/github-multi-repo/SKILL.md +42 -46
  215. package/.claude/skills/github-project-management/SKILL.md +83 -88
  216. package/.claude/skills/github-release-management/SKILL.md +12 -18
  217. package/.claude/skills/github-workflow-automation/SKILL.md +70 -74
  218. package/.claude/skills/hooks-automation/SKILL.md +9 -13
  219. package/.claude/skills/mastermind/_intake.md +83 -0
  220. package/.claude/skills/mastermind/_protocol.md +275 -0
  221. package/.claude/skills/mastermind/architect.md +847 -0
  222. package/.claude/skills/mastermind/build.md +158 -0
  223. package/.claude/skills/mastermind/content.md +185 -0
  224. package/.claude/skills/mastermind/createorg.md +318 -0
  225. package/.claude/skills/mastermind/finance.md +154 -0
  226. package/.claude/skills/mastermind/idea.md +158 -0
  227. package/.claude/skills/mastermind/marketing.md +216 -0
  228. package/.claude/skills/mastermind/monotask.md +350 -0
  229. package/.claude/skills/mastermind/ops.md +156 -0
  230. package/.claude/skills/mastermind/references/copywriting-frameworks.md +181 -0
  231. package/.claude/skills/mastermind/references/persuasion-psychology.md +158 -0
  232. package/.claude/skills/mastermind/release.md +156 -0
  233. package/.claude/skills/mastermind/research.md +156 -0
  234. package/.claude/skills/mastermind/review.md +157 -0
  235. package/.claude/skills/mastermind/runorg.md +308 -0
  236. package/.claude/skills/mastermind/sales.md +158 -0
  237. package/.claude/skills/mastermind/techport.md +743 -0
  238. package/.claude/skills/{v3-mcp-optimization → mcp-optimization}/SKILL.md +35 -14
  239. package/.claude/skills/{v3-memory-unification → memory-unification}/SKILL.md +20 -4
  240. package/.claude/skills/monodesign/SKILL.md +302 -0
  241. package/.claude/skills/monodesign/reference/adapt.md +190 -0
  242. package/.claude/skills/monodesign/reference/animate.md +175 -0
  243. package/.claude/skills/monodesign/reference/antipatterns-catalog.md +187 -0
  244. package/.claude/skills/monodesign/reference/audit.md +133 -0
  245. package/.claude/skills/monodesign/reference/bolder.md +113 -0
  246. package/.claude/skills/monodesign/reference/brand-workflow.md +180 -0
  247. package/.claude/skills/monodesign/reference/brand.md +114 -0
  248. package/.claude/skills/monodesign/reference/clarify.md +174 -0
  249. package/.claude/skills/monodesign/reference/cognitive-load.md +106 -0
  250. package/.claude/skills/monodesign/reference/color-and-contrast.md +105 -0
  251. package/.claude/skills/monodesign/reference/colorize.md +154 -0
  252. package/.claude/skills/monodesign/reference/component-specs.md +260 -0
  253. package/.claude/skills/monodesign/reference/component-states.md +274 -0
  254. package/.claude/skills/monodesign/reference/component-system.md +358 -0
  255. package/.claude/skills/monodesign/reference/copy-formulas.md +160 -0
  256. package/.claude/skills/monodesign/reference/craft.md +193 -0
  257. package/.claude/skills/monodesign/reference/critique.md +213 -0
  258. package/.claude/skills/monodesign/reference/delight.md +302 -0
  259. package/.claude/skills/monodesign/reference/design-principles.md +246 -0
  260. package/.claude/skills/monodesign/reference/distill.md +111 -0
  261. package/.claude/skills/monodesign/reference/document.md +427 -0
  262. package/.claude/skills/monodesign/reference/extract.md +69 -0
  263. package/.claude/skills/monodesign/reference/harden.md +347 -0
  264. package/.claude/skills/monodesign/reference/heuristics-scoring.md +234 -0
  265. package/.claude/skills/monodesign/reference/image-prompts.md +118 -0
  266. package/.claude/skills/monodesign/reference/interaction-design.md +195 -0
  267. package/.claude/skills/monodesign/reference/layout.md +141 -0
  268. package/.claude/skills/monodesign/reference/live.md +622 -0
  269. package/.claude/skills/monodesign/reference/motion-design.md +109 -0
  270. package/.claude/skills/monodesign/reference/onboard.md +234 -0
  271. package/.claude/skills/monodesign/reference/optimize.md +258 -0
  272. package/.claude/skills/monodesign/reference/overdrive.md +130 -0
  273. package/.claude/skills/monodesign/reference/personas.md +179 -0
  274. package/.claude/skills/monodesign/reference/polish.md +233 -0
  275. package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +108 -0
  276. package/.claude/skills/monodesign/reference/product.md +62 -0
  277. package/.claude/skills/monodesign/reference/quieter.md +99 -0
  278. package/.claude/skills/monodesign/reference/responsive-design.md +114 -0
  279. package/.claude/skills/monodesign/reference/shape.md +151 -0
  280. package/.claude/skills/monodesign/reference/spatial-design.md +100 -0
  281. package/.claude/skills/monodesign/reference/teach.md +156 -0
  282. package/.claude/skills/monodesign/reference/token-architecture.md +222 -0
  283. package/.claude/skills/monodesign/reference/typeset.md +124 -0
  284. package/.claude/skills/monodesign/reference/typography.md +159 -0
  285. package/.claude/skills/monodesign/reference/ux-research.md +143 -0
  286. package/.claude/skills/monodesign/reference/ux-rules.md +211 -0
  287. package/.claude/skills/monodesign/reference/ux-writing.md +107 -0
  288. package/.claude/skills/monomotion/SKILL.md +145 -0
  289. package/.claude/skills/monomotion/rules/api-control.md +139 -0
  290. package/.claude/skills/monomotion/rules/effects.md +109 -0
  291. package/.claude/skills/monomotion/rules/integration.md +140 -0
  292. package/.claude/skills/monomotion/rules/scroll.md +131 -0
  293. package/.claude/skills/monomotion/rules/sequencing.md +105 -0
  294. package/.claude/skills/monomotion/rules/svg.md +101 -0
  295. package/.claude/skills/monomotion/rules/text.md +119 -0
  296. package/.claude/skills/pair-programming/SKILL.md +1 -1
  297. package/.claude/skills/performance-analysis/SKILL.md +3 -3
  298. package/.claude/skills/{v3-performance-optimization → performance-optimization}/SKILL.md +16 -8
  299. package/.claude/skills/reasoningbank-agentdb/SKILL.md +17 -19
  300. package/.claude/skills/reasoningbank-intelligence/SKILL.md +4 -6
  301. package/.claude/skills/{v3-security-overhaul → security-hardening}/SKILL.md +13 -3
  302. package/.claude/skills/skill-builder/SKILL.md +19 -19
  303. package/.claude/skills/sparc-methodology/SKILL.md +55 -211
  304. package/.claude/skills/stop-slop/SKILL.md +67 -0
  305. package/.claude/skills/stop-slop/references/examples.md +61 -0
  306. package/.claude/skills/stop-slop/references/phrases.md +130 -0
  307. package/.claude/skills/stop-slop/references/structures.md +136 -0
  308. package/.claude/skills/swarm-advanced/SKILL.md +13 -43
  309. package/.claude/skills/{v3-swarm-coordination → swarm-coordination}/SKILL.md +39 -21
  310. package/.claude/skills/swarm-orchestration/SKILL.md +12 -12
  311. package/.claude/skills/verification-quality/SKILL.md +5 -5
  312. package/.claude/statusline-command.sh +0 -0
  313. package/.claude/statusline.sh +0 -0
  314. package/.claude-plugin/scripts/install.sh +0 -0
  315. package/.claude-plugin/scripts/uninstall.sh +0 -0
  316. package/.claude-plugin/scripts/verify.sh +0 -0
  317. package/README.md +5 -5
  318. package/package.json +17 -17
  319. package/packages/@monomind/cli/README.md +441 -0
  320. package/packages/@monomind/cli/bin/cli.js +78 -13
  321. package/packages/@monomind/cli/bin/mcp-server.js +0 -0
  322. package/packages/@monomind/cli/dist/src/agents/halt-signal.js +33 -7
  323. package/packages/@monomind/cli/dist/src/agents/managed-agent.js +5 -2
  324. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.d.ts +3 -2
  325. package/packages/@monomind/cli/dist/src/agents/prompt-experiment.js +1 -1
  326. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.d.ts +5 -2
  327. package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.js +26 -4
  328. package/packages/@monomind/cli/dist/src/agents/specialization-scorer.js +17 -9
  329. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.d.ts +5 -3
  330. package/packages/@monomind/cli/dist/src/agents/trigger-scanner.js +58 -10
  331. package/packages/@monomind/cli/dist/src/agents/version-store.d.ts +0 -1
  332. package/packages/@monomind/cli/dist/src/agents/version-store.js +44 -21
  333. package/packages/@monomind/cli/dist/src/autopilot-state.js +79 -28
  334. package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.d.ts +7 -2
  335. package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.js +20 -8
  336. package/packages/@monomind/cli/dist/src/benchmarks/metric-evaluators.d.ts +2 -1
  337. package/packages/@monomind/cli/dist/src/benchmarks/metric-evaluators.js +25 -2
  338. package/packages/@monomind/cli/dist/src/commands/agent.js +6 -4
  339. package/packages/@monomind/cli/dist/src/commands/appliance-advanced.js +23 -0
  340. package/packages/@monomind/cli/dist/src/commands/autopilot.js +3 -3
  341. package/packages/@monomind/cli/dist/src/commands/benchmark.js +119 -8
  342. package/packages/@monomind/cli/dist/src/commands/claims.js +22 -14
  343. package/packages/@monomind/cli/dist/src/commands/config.js +32 -0
  344. package/packages/@monomind/cli/dist/src/commands/daemon.js +13 -11
  345. package/packages/@monomind/cli/dist/src/commands/deployment.js +21 -2
  346. package/packages/@monomind/cli/dist/src/commands/doctor.js +5 -4
  347. package/packages/@monomind/cli/dist/src/commands/embeddings.js +124 -48
  348. package/packages/@monomind/cli/dist/src/commands/hive-mind.js +15 -14
  349. package/packages/@monomind/cli/dist/src/commands/hooks.js +45 -41
  350. package/packages/@monomind/cli/dist/src/commands/index.d.ts +2 -0
  351. package/packages/@monomind/cli/dist/src/commands/index.js +20 -7
  352. package/packages/@monomind/cli/dist/src/commands/init.js +53 -19
  353. package/packages/@monomind/cli/dist/src/commands/mcp.js +31 -44
  354. package/packages/@monomind/cli/dist/src/commands/memory.js +47 -15
  355. package/packages/@monomind/cli/dist/src/commands/migrate.js +156 -108
  356. package/packages/@monomind/cli/dist/src/commands/monograph.d.ts +8 -0
  357. package/packages/@monomind/cli/dist/src/commands/monograph.js +526 -0
  358. package/packages/@monomind/cli/dist/src/commands/neural.js +96 -56
  359. package/packages/@monomind/cli/dist/src/commands/performance.js +30 -8
  360. package/packages/@monomind/cli/dist/src/commands/plugins.js +13 -37
  361. package/packages/@monomind/cli/dist/src/commands/process.js +25 -2
  362. package/packages/@monomind/cli/dist/src/commands/providers.js +37 -5
  363. package/packages/@monomind/cli/dist/src/commands/replay.js +4 -4
  364. package/packages/@monomind/cli/dist/src/commands/route.js +37 -5
  365. package/packages/@monomind/cli/dist/src/commands/ruvector/import.js +12 -2
  366. package/packages/@monomind/cli/dist/src/commands/ruvector/init.js +15 -0
  367. package/packages/@monomind/cli/dist/src/commands/ruvector/status.js +16 -3
  368. package/packages/@monomind/cli/dist/src/commands/security.js +342 -193
  369. package/packages/@monomind/cli/dist/src/commands/session.js +51 -8
  370. package/packages/@monomind/cli/dist/src/commands/start.js +18 -4
  371. package/packages/@monomind/cli/dist/src/commands/swarm.js +47 -36
  372. package/packages/@monomind/cli/dist/src/commands/tokens.js +11 -11
  373. package/packages/@monomind/cli/dist/src/commands/transfer-store.js +1 -1
  374. package/packages/@monomind/cli/dist/src/commands/workflow.js +31 -4
  375. package/packages/@monomind/cli/dist/src/config-adapter.d.ts +2 -1
  376. package/packages/@monomind/cli/dist/src/consensus/audit-writer.js +46 -13
  377. package/packages/@monomind/cli/dist/src/consensus/vote-signer.d.ts +0 -3
  378. package/packages/@monomind/cli/dist/src/consensus/vote-signer.js +9 -1
  379. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.d.ts +4 -2
  380. package/packages/@monomind/cli/dist/src/dlq/dlq-reader.js +25 -8
  381. package/packages/@monomind/cli/dist/src/dlq/dlq-replayer.d.ts +10 -3
  382. package/packages/@monomind/cli/dist/src/dlq/dlq-replayer.js +50 -16
  383. package/packages/@monomind/cli/dist/src/dlq/dlq-writer.js +27 -5
  384. package/packages/@monomind/cli/dist/src/eval/dataset-manager.d.ts +2 -2
  385. package/packages/@monomind/cli/dist/src/eval/dataset-manager.js +26 -16
  386. package/packages/@monomind/cli/dist/src/eval/trace-collector.js +23 -3
  387. package/packages/@monomind/cli/dist/src/index.js +12 -10
  388. package/packages/@monomind/cli/dist/src/init/claudemd-generator.js +8 -8
  389. package/packages/@monomind/cli/dist/src/init/executor.js +153 -70
  390. package/packages/@monomind/cli/dist/src/init/helpers-generator.js +35 -22
  391. package/packages/@monomind/cli/dist/src/init/mcp-generator.js +3 -3
  392. package/packages/@monomind/cli/dist/src/init/settings-generator.js +10 -3
  393. package/packages/@monomind/cli/dist/src/init/shared-instructions-generator.js +18 -3
  394. package/packages/@monomind/cli/dist/src/init/statusline-generator.js +3 -1
  395. package/packages/@monomind/cli/dist/src/init/types.d.ts +35 -11
  396. package/packages/@monomind/cli/dist/src/init/types.js +5 -9
  397. package/packages/@monomind/cli/dist/src/interactive/interrupt.js +8 -3
  398. package/packages/@monomind/cli/dist/src/mcp/tool-registry.js +38 -4
  399. package/packages/@monomind/cli/dist/src/mcp-client.js +10 -4
  400. package/packages/@monomind/cli/dist/src/mcp-server.d.ts +9 -2
  401. package/packages/@monomind/cli/dist/src/mcp-server.js +182 -35
  402. package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.js +66 -34
  403. package/packages/@monomind/cli/dist/src/mcp-tools/agentdb-tools.js +34 -7
  404. package/packages/@monomind/cli/dist/src/mcp-tools/analyze-tools.js +25 -16
  405. package/packages/@monomind/cli/dist/src/mcp-tools/auto-install.js +4 -6
  406. package/packages/@monomind/cli/dist/src/mcp-tools/autopilot-tools.js +12 -2
  407. package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.js +199 -20
  408. package/packages/@monomind/cli/dist/src/mcp-tools/claims-tools.js +68 -18
  409. package/packages/@monomind/cli/dist/src/mcp-tools/config-tools.js +33 -5
  410. package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.js +59 -4
  411. package/packages/@monomind/cli/dist/src/mcp-tools/daa-tools.js +46 -10
  412. package/packages/@monomind/cli/dist/src/mcp-tools/embeddings-tools.js +46 -5
  413. package/packages/@monomind/cli/dist/src/mcp-tools/github-tools.js +29 -16
  414. package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +38 -10
  415. package/packages/@monomind/cli/dist/src/mcp-tools/hive-mind-tools.js +96 -33
  416. package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +70 -37
  417. package/packages/@monomind/cli/dist/src/mcp-tools/memory-tools.js +29 -13
  418. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +5867 -56
  419. package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +121 -37
  420. package/packages/@monomind/cli/dist/src/mcp-tools/performance-tools.js +21 -8
  421. package/packages/@monomind/cli/dist/src/mcp-tools/progress-tools.js +10 -8
  422. package/packages/@monomind/cli/dist/src/mcp-tools/request-tracker.js +4 -1
  423. package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.js +19 -8
  424. package/packages/@monomind/cli/dist/src/mcp-tools/session-tools.js +57 -17
  425. package/packages/@monomind/cli/dist/src/mcp-tools/swarm-tools.js +35 -17
  426. package/packages/@monomind/cli/dist/src/mcp-tools/system-tools.js +4 -3
  427. package/packages/@monomind/cli/dist/src/mcp-tools/task-tools.js +53 -13
  428. package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.js +63 -14
  429. package/packages/@monomind/cli/dist/src/mcp-tools/transfer-tools.js +21 -16
  430. package/packages/@monomind/cli/dist/src/mcp-tools/workflow-tools.js +92 -23
  431. package/packages/@monomind/cli/dist/src/memory/ewc-consolidation.js +41 -10
  432. package/packages/@monomind/cli/dist/src/memory/intelligence.d.ts +2 -2
  433. package/packages/@monomind/cli/dist/src/memory/intelligence.js +39 -13
  434. package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +1 -0
  435. package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +149 -56
  436. package/packages/@monomind/cli/dist/src/memory/memory-initializer.js +107 -45
  437. package/packages/@monomind/cli/dist/src/memory/sona-optimizer.d.ts +8 -1
  438. package/packages/@monomind/cli/dist/src/memory/sona-optimizer.js +25 -8
  439. package/packages/@monomind/cli/dist/src/observability/replay-reader.d.ts +40 -0
  440. package/packages/@monomind/cli/dist/src/observability/replay-reader.js +138 -0
  441. package/packages/@monomind/cli/dist/src/orchestration/routing-modes.js +35 -5
  442. package/packages/@monomind/cli/dist/src/parser.d.ts +8 -0
  443. package/packages/@monomind/cli/dist/src/parser.js +48 -14
  444. package/packages/@monomind/cli/dist/src/plugins/manager.js +112 -19
  445. package/packages/@monomind/cli/dist/src/plugins/store/discovery.d.ts +1 -1
  446. package/packages/@monomind/cli/dist/src/plugins/store/discovery.js +80 -62
  447. package/packages/@monomind/cli/dist/src/production/circuit-breaker.js +8 -1
  448. package/packages/@monomind/cli/dist/src/production/error-handler.d.ts +4 -2
  449. package/packages/@monomind/cli/dist/src/production/error-handler.js +27 -5
  450. package/packages/@monomind/cli/dist/src/production/monitoring.js +8 -4
  451. package/packages/@monomind/cli/dist/src/production/rate-limiter.js +30 -22
  452. package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.js +2 -2
  453. package/packages/@monomind/cli/dist/src/ruvector/coverage-router.js +19 -9
  454. package/packages/@monomind/cli/dist/src/ruvector/diff-classifier.d.ts +1 -0
  455. package/packages/@monomind/cli/dist/src/ruvector/diff-classifier.js +26 -6
  456. package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.js +24 -2
  457. package/packages/@monomind/cli/dist/src/ruvector/index.d.ts +1 -2
  458. package/packages/@monomind/cli/dist/src/ruvector/index.js +2 -2
  459. package/packages/@monomind/cli/dist/src/ruvector/model-router.d.ts +4 -2
  460. package/packages/@monomind/cli/dist/src/ruvector/model-router.js +30 -6
  461. package/packages/@monomind/cli/dist/src/ruvector/moe-router.d.ts +7 -0
  462. package/packages/@monomind/cli/dist/src/ruvector/moe-router.js +35 -12
  463. package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.d.ts +7 -1
  464. package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.js +40 -9
  465. package/packages/@monomind/cli/dist/src/services/claim-service.d.ts +3 -1
  466. package/packages/@monomind/cli/dist/src/services/claim-service.js +33 -2
  467. package/packages/@monomind/cli/dist/src/services/config-file-manager.d.ts +16 -2
  468. package/packages/@monomind/cli/dist/src/services/config-file-manager.js +105 -17
  469. package/packages/@monomind/cli/dist/src/services/container-worker-pool.js +51 -11
  470. package/packages/@monomind/cli/dist/src/services/headless-worker-executor.d.ts +7 -0
  471. package/packages/@monomind/cli/dist/src/services/headless-worker-executor.js +188 -45
  472. package/packages/@monomind/cli/dist/src/services/registry-api.js +62 -9
  473. package/packages/@monomind/cli/dist/src/services/ruvector-training.js +8 -0
  474. package/packages/@monomind/cli/dist/src/services/worker-daemon.d.ts +4 -1
  475. package/packages/@monomind/cli/dist/src/services/worker-daemon.js +112 -28
  476. package/packages/@monomind/cli/dist/src/services/worker-queue.d.ts +9 -2
  477. package/packages/@monomind/cli/dist/src/services/worker-queue.js +86 -5
  478. package/packages/@monomind/cli/dist/src/suggest.js +9 -0
  479. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.d.ts +5 -3
  480. package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.js +17 -5
  481. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.d.ts +3 -0
  482. package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.js +30 -6
  483. package/packages/@monomind/cli/dist/src/transfer/anonymization/index.js +5 -3
  484. package/packages/@monomind/cli/dist/src/transfer/export.js +5 -3
  485. package/packages/@monomind/cli/dist/src/transfer/ipfs/client.js +84 -7
  486. package/packages/@monomind/cli/dist/src/transfer/ipfs/upload.js +13 -4
  487. package/packages/@monomind/cli/dist/src/transfer/storage/gcs.js +19 -10
  488. package/packages/@monomind/cli/dist/src/transfer/store/discovery.d.ts +9 -2
  489. package/packages/@monomind/cli/dist/src/transfer/store/discovery.js +68 -13
  490. package/packages/@monomind/cli/dist/src/transfer/store/download.d.ts +15 -6
  491. package/packages/@monomind/cli/dist/src/transfer/store/download.js +113 -24
  492. package/packages/@monomind/cli/dist/src/transfer/store/publish.d.ts +1 -1
  493. package/packages/@monomind/cli/dist/src/transfer/store/publish.js +13 -14
  494. package/packages/@monomind/cli/dist/src/transfer/store/registry.d.ts +3 -3
  495. package/packages/@monomind/cli/dist/src/transfer/store/registry.js +32 -16
  496. package/packages/@monomind/cli/dist/src/update/checker.js +17 -4
  497. package/packages/@monomind/cli/dist/src/update/executor.js +25 -20
  498. package/packages/@monomind/cli/dist/src/update/rate-limiter.d.ts +11 -0
  499. package/packages/@monomind/cli/dist/src/update/rate-limiter.js +23 -3
  500. package/packages/@monomind/cli/dist/src/utils/parse-jsonl.d.ts +6 -0
  501. package/packages/@monomind/cli/dist/src/utils/parse-jsonl.js +22 -0
  502. package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.js +37 -3
  503. package/packages/@monomind/cli/dist/src/workflow/dag-builder.js +27 -11
  504. package/packages/@monomind/cli/dist/src/workflow/dag-executor.js +51 -13
  505. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.d.ts +3 -0
  506. package/packages/@monomind/cli/dist/src/workflow/dsl-schema.js +6 -2
  507. package/packages/@monomind/cli/dist/src/workflow/template-engine.js +7 -0
  508. package/packages/@monomind/cli/dist/src/workflow/workflow-executor.js +95 -14
  509. package/packages/@monomind/cli/package.json +5 -3
  510. package/packages/@monomind/guidance/README.md +1192 -0
  511. package/packages/@monomind/shared/README.md +322 -0
  512. package/packages/@monomind/shared/dist/types/consensus-audit.d.ts +3 -1
  513. package/packages/README.md +513 -0
  514. package/.claude/agents/design/design-brand-guardian.md +0 -323
  515. package/.claude/agents/design/design-image-prompt-engineer.md +0 -237
  516. package/.claude/agents/design/design-inclusive-visuals-specialist.md +0 -72
  517. package/.claude/agents/design/design-ui-designer.md +0 -384
  518. package/.claude/agents/design/design-ux-architect.md +0 -470
  519. package/.claude/agents/design/design-ux-researcher.md +0 -330
  520. package/.claude/agents/design/design-visual-storyteller.md +0 -150
  521. package/.claude/agents/design/design-whimsy-injector.md +0 -439
  522. package/.claude/agents/v3/integration-architect.md +0 -338
  523. package/.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md +0 -54
  524. package/.claude/commands/coordination/init.md +0 -44
  525. package/.claude/commands/coordination/orchestrate.md +0 -43
  526. package/.claude/commands/coordination/spawn.md +0 -45
  527. package/.claude/commands/github/code-review-swarm.md +0 -550
  528. package/.claude/commands/github/code-review.md +0 -25
  529. package/.claude/commands/github/github-swarm.md +0 -121
  530. package/.claude/commands/github/issue-triage.md +0 -25
  531. package/.claude/commands/github/multi-repo-swarm.md +0 -519
  532. package/.claude/commands/github/pr-enhance.md +0 -26
  533. package/.claude/commands/github/project-board-sync.md +0 -471
  534. package/.claude/commands/github/release-swarm.md +0 -590
  535. package/.claude/commands/github/repo-analyze.md +0 -25
  536. package/.claude/commands/github/swarm-issue.md +0 -482
  537. package/.claude/commands/github/swarm-pr.md +0 -310
  538. package/.claude/commands/github/workflow-automation.md +0 -468
  539. package/.claude/commands/hive-mind/hive-mind-metrics.md +0 -8
  540. package/.claude/commands/hive-mind/hive-mind-resume.md +0 -8
  541. package/.claude/commands/hive-mind/hive-mind-sessions.md +0 -8
  542. package/.claude/commands/hive-mind/hive-mind-wizard.md +0 -8
  543. package/.claude/commands/list-agents.md +0 -17
  544. package/.claude/commands/memory/memory-persist.md +0 -25
  545. package/.claude/commands/memory/memory-usage.md +0 -25
  546. package/.claude/commands/memory/neural.md +0 -47
  547. package/.claude/commands/metrics.md +0 -11
  548. package/.claude/commands/monitoring/real-time-view.md +0 -25
  549. package/.claude/commands/monitoring/swarm-monitor.md +0 -25
  550. package/.claude/commands/monomind-createtask.md +0 -302
  551. package/.claude/commands/monomind-help.md +0 -103
  552. package/.claude/commands/monomind-memory.md +0 -107
  553. package/.claude/commands/monomind-repeat.md +0 -149
  554. package/.claude/commands/monomind-swarm.md +0 -205
  555. package/.claude/commands/optimization/cache-manage.md +0 -25
  556. package/.claude/commands/optimization/topology-optimize.md +0 -25
  557. package/.claude/commands/pair/commands.md +0 -546
  558. package/.claude/commands/pair/config.md +0 -510
  559. package/.claude/commands/pair/start.md +0 -209
  560. package/.claude/commands/use-agent.md +0 -67
  561. package/.claude/skills/monomind-createtask/SKILL.md +0 -269
  562. package/.claude/skills/monomind-task-engine/SKILL.md +0 -358
  563. /package/.claude/agents/{v3 → specialists}/memory-specialist.md +0 -0
  564. /package/.claude/agents/{v3 → specialists}/performance-engineer.md +0 -0
  565. /package/.claude/agents/{v3 → specialists}/queen-coordinator.md +0 -0
  566. /package/.claude/agents/{v3 → specialists}/security-architect.md +0 -0
@@ -7,7 +7,7 @@
7
7
  * - Structured error responses
8
8
  * - Error aggregation and reporting
9
9
  *
10
- * @module @monoes/cli/production/error-handler
10
+ * @module @monomind/cli/production/error-handler
11
11
  */
12
12
  export interface ErrorContext {
13
13
  operation: string;
@@ -55,8 +55,10 @@ export declare class ErrorHandler {
55
55
  isRetryable(category: ErrorCategory): boolean;
56
56
  /**
57
57
  * Sanitize input to remove sensitive data
58
+ * Cycle-safe and depth-bounded — circular references and deeply nested objects
59
+ * will not cause stack overflow.
58
60
  */
59
- sanitize(input: Record<string, unknown>): Record<string, unknown>;
61
+ sanitize(input: Record<string, unknown>, _seen?: WeakSet<object>, _depth?: number): Record<string, unknown>;
60
62
  /**
61
63
  * Handle an error and return a structured response
62
64
  */
@@ -7,7 +7,7 @@
7
7
  * - Structured error responses
8
8
  * - Error aggregation and reporting
9
9
  *
10
- * @module @monoes/cli/production/error-handler
10
+ * @module @monomind/cli/production/error-handler
11
11
  */
12
12
  // ============================================================================
13
13
  // Error Classification
@@ -126,10 +126,17 @@ export class ErrorHandler {
126
126
  }
127
127
  /**
128
128
  * Sanitize input to remove sensitive data
129
+ * Cycle-safe and depth-bounded — circular references and deeply nested objects
130
+ * will not cause stack overflow.
129
131
  */
130
- sanitize(input) {
132
+ sanitize(input, _seen = new WeakSet(), _depth = 0) {
131
133
  if (!this.config.sanitize)
132
134
  return input;
135
+ if (_depth > 20)
136
+ return { '[MAX_DEPTH]': true };
137
+ if (_seen.has(input))
138
+ return { '[CIRCULAR]': true };
139
+ _seen.add(input);
133
140
  const sanitized = {};
134
141
  for (const [key, value] of Object.entries(input)) {
135
142
  const lowerKey = key.toLowerCase();
@@ -138,7 +145,7 @@ export class ErrorHandler {
138
145
  sanitized[key] = '[REDACTED]';
139
146
  }
140
147
  else if (typeof value === 'object' && value !== null) {
141
- sanitized[key] = this.sanitize(value);
148
+ sanitized[key] = this.sanitize(value, _seen, _depth + 1);
142
149
  }
143
150
  else {
144
151
  sanitized[key] = value;
@@ -154,8 +161,22 @@ export class ErrorHandler {
154
161
  const category = this.classifyError(error);
155
162
  const retryable = this.isRetryable(category);
156
163
  const now = new Date().toISOString();
157
- // Track error counts for rate limiting
164
+ // Track error counts for rate limiting and enforce cap
158
165
  this.trackError(category);
166
+ const rateEntry = this.errorCounts.get(category);
167
+ if (rateEntry && rateEntry.count > this.config.maxErrorsPerMinute) {
168
+ return {
169
+ success: false,
170
+ error: {
171
+ code: 'ERR_RATE_LIMITED',
172
+ message: 'Error rate limit exceeded',
173
+ category,
174
+ retryable: false,
175
+ },
176
+ context,
177
+ timestamp: new Date().toISOString(),
178
+ };
179
+ }
159
180
  // Build structured error
160
181
  const structured = {
161
182
  success: false,
@@ -261,7 +282,8 @@ export class ErrorHandler {
261
282
  // Remove potential sensitive data from message
262
283
  let sanitized = message;
263
284
  for (const key of SENSITIVE_KEYS) {
264
- const pattern = new RegExp(`${key}[=:]?\\s*["']?[^\\s"']+["']?`, 'gi');
285
+ // Use a non-backtracking pattern: key followed by = or : then non-whitespace
286
+ const pattern = new RegExp(`${key}[=:]\\S+`, 'gi');
265
287
  sanitized = sanitized.replace(pattern, `${key}=[REDACTED]`);
266
288
  }
267
289
  return sanitized;
@@ -8,7 +8,7 @@
8
8
  * - Health checks
9
9
  * - Alerting
10
10
  *
11
- * @module @monoes/cli/production/monitoring
11
+ * @module @monomind/cli/production/monitoring
12
12
  */
13
13
  // ============================================================================
14
14
  // Default Configuration
@@ -101,13 +101,13 @@ export class MonitoringHooks {
101
101
  this.activeRequests++;
102
102
  this.requestCount++;
103
103
  const startTime = Date.now();
104
- this.counter('request_started', 1, { requestId });
104
+ this.counter('request_started', 1, {});
105
105
  // Return end function
106
106
  return () => {
107
107
  this.activeRequests--;
108
108
  const duration = Date.now() - startTime;
109
109
  this.responseTimes.push(duration);
110
- this.histogram('response_time_ms', duration, { requestId });
110
+ this.histogram('response_time_ms', duration, {});
111
111
  // Keep only last 1000 response times
112
112
  if (this.responseTimes.length > 1000) {
113
113
  this.responseTimes = this.responseTimes.slice(-1000);
@@ -122,7 +122,6 @@ export class MonitoringHooks {
122
122
  this.counter('error', 1, {
123
123
  ...labels,
124
124
  errorType: error.name,
125
- errorMessage: error.message.slice(0, 100),
126
125
  });
127
126
  }
128
127
  // ============================================================================
@@ -331,6 +330,11 @@ export class MonitoringHooks {
331
330
  }
332
331
  // Remove old acknowledged alerts
333
332
  this.alerts = this.alerts.filter(a => !a.acknowledged || Date.now() - a.timestamp < 300000);
333
+ // Cap total alerts to prevent unbounded growth
334
+ const MAX_ALERTS = 500;
335
+ if (this.alerts.length > MAX_ALERTS) {
336
+ this.alerts = this.alerts.slice(-MAX_ALERTS);
337
+ }
334
338
  }
335
339
  }
336
340
  // ============================================================================
@@ -7,7 +7,7 @@
7
7
  * - Burst allowance
8
8
  * - Sliding window tracking
9
9
  *
10
- * @module @monoes/cli/production/rate-limiter
10
+ * @module @monomind/cli/production/rate-limiter
11
11
  */
12
12
  // ============================================================================
13
13
  // Rate Limiter
@@ -52,9 +52,8 @@ export class RateLimiter {
52
52
  }
53
53
  // Clean old requests from sliding window
54
54
  bucket.requests = bucket.requests.filter(t => t > now - limits.windowMs);
55
- // Calculate remaining
56
- const maxWithBurst = Math.floor(limits.maxRequests * this.config.burstMultiplier);
57
- const remaining = maxWithBurst - bucket.requests.length;
55
+ // Calculate remaining — uses base maxRequests (consistent with getStatus())
56
+ const remaining = limits.maxRequests - bucket.requests.length;
58
57
  if (remaining <= 0) {
59
58
  // Rate limited
60
59
  const oldestRequest = bucket.requests[0];
@@ -134,7 +133,11 @@ export class RateLimiter {
134
133
  const operationCounts = new Map();
135
134
  const users = new Set();
136
135
  for (const [key, bucket] of this.buckets) {
137
- const [operation, userId] = key.split(':');
136
+ const colonIdx = key.indexOf(':');
137
+ const prefix = colonIdx >= 0 ? key.slice(0, colonIdx) : key;
138
+ const suffix = colonIdx >= 0 ? key.slice(colonIdx + 1) : undefined;
139
+ const operation = prefix === 'global' ? (suffix ?? prefix) : prefix;
140
+ const userId = prefix === 'global' ? undefined : suffix;
138
141
  if (userId)
139
142
  users.add(userId);
140
143
  const current = operationCounts.get(operation) || 0;
@@ -167,24 +170,29 @@ export class RateLimiter {
167
170
  };
168
171
  }
169
172
  cleanupBuckets() {
170
- // Limit number of tracked buckets
171
- if (this.buckets.size > this.config.maxTrackedUsers) {
172
- const now = Date.now();
173
- const toDelete = [];
174
- // Find buckets with no recent requests
175
- for (const [key, bucket] of this.buckets) {
176
- const recent = bucket.requests.filter(t => t > now - this.config.windowMs * 2);
177
- if (recent.length === 0) {
178
- toDelete.push(key);
179
- }
180
- }
181
- // Delete stale buckets
182
- for (const key of toDelete) {
173
+ if (this.buckets.size <= this.config.maxTrackedUsers)
174
+ return;
175
+ const now = Date.now();
176
+ const target = Math.floor(this.config.maxTrackedUsers * 0.8);
177
+ // First pass: delete buckets with no recent activity (cheap LRU)
178
+ for (const [key, bucket] of this.buckets) {
179
+ if (this.buckets.size <= target)
180
+ break;
181
+ const recent = bucket.requests.filter(t => t > now - this.config.windowMs * 2);
182
+ if (recent.length === 0)
183
183
  this.buckets.delete(key);
184
- if (this.buckets.size <= this.config.maxTrackedUsers * 0.8) {
185
- break;
186
- }
187
- }
184
+ }
185
+ if (this.buckets.size <= target)
186
+ return;
187
+ // Second pass: even active buckets get evicted if we are still over the cap.
188
+ // Eviction order: oldest first-request timestamp wins (true LRU on activity).
189
+ const entries = Array.from(this.buckets.entries())
190
+ .map(([key, bucket]) => ({ key, oldest: bucket.requests[0] ?? 0 }))
191
+ .sort((a, b) => a.oldest - b.oldest);
192
+ for (const { key } of entries) {
193
+ if (this.buckets.size <= target)
194
+ break;
195
+ this.buckets.delete(key);
188
196
  }
189
197
  }
190
198
  }
@@ -8,7 +8,7 @@
8
8
  * Published API (v0.1.0): WasmAgent, WasmGallery, WasmMcpServer,
9
9
  * WasmRvfBuilder, JsModelProvider, initSync.
10
10
  *
11
- * @module @monoes/cli/ruvector/agent-wasm
11
+ * @module @monomind/cli/ruvector/agent-wasm
12
12
  */
13
13
  import { readFileSync } from 'node:fs';
14
14
  import { createRequire } from 'node:module';
@@ -39,7 +39,7 @@ export async function initAgentWasm() {
39
39
  const require_ = createRequire(import.meta.url);
40
40
  const wasmPath = require_.resolve('@ruvector/rvagent-wasm/rvagent_wasm_bg.wasm');
41
41
  const wasmBytes = readFileSync(wasmPath);
42
- mod.initSync(wasmBytes);
42
+ mod.initSync({ module: wasmBytes });
43
43
  _wasmReady = true;
44
44
  }
45
45
  catch (err) {
@@ -9,11 +9,15 @@
9
9
  // ============================================================================
10
10
  // Caching for Performance
11
11
  // ============================================================================
12
+ import { existsSync } from 'node:fs';
13
+ import { readFile } from 'node:fs/promises';
14
+ import { resolve, normalize, isAbsolute, join } from 'node:path';
12
15
  /**
13
16
  * Cache for coverage data (1 minute TTL)
14
17
  */
15
18
  const coverageDataCache = new Map();
16
19
  const COVERAGE_CACHE_TTL_MS = 60 * 1000; // 1 minute
20
+ const COVERAGE_CACHE_MAX = 50;
17
21
  /**
18
22
  * Clear coverage cache
19
23
  */
@@ -378,16 +382,14 @@ export async function coverageGaps(options = {}) {
378
382
  * Returns null if path is invalid or attempts traversal
379
383
  */
380
384
  function validateProjectPath(inputPath) {
381
- const { resolve, normalize, isAbsolute } = require('path');
385
+ // resolve, normalize, isAbsolute imported at top of module
382
386
  // Default to cwd if not provided
383
387
  const basePath = inputPath || process.cwd();
384
388
  // Normalize and resolve the path
385
389
  const normalizedPath = normalize(basePath);
386
390
  const resolvedPath = isAbsolute(normalizedPath) ? normalizedPath : resolve(process.cwd(), normalizedPath);
387
- // Check for path traversal attempts
388
- if (normalizedPath.includes('..') && !resolvedPath.startsWith(process.cwd())) {
389
- // Only allow .. if it resolves within or above cwd
390
- // For safety, reject any path with .. that goes outside project
391
+ // Enforce containment: resolved path must stay within cwd regardless of how it was expressed
392
+ if (!resolvedPath.startsWith(process.cwd())) {
391
393
  return null;
392
394
  }
393
395
  // Additional validation: no null bytes or control characters
@@ -417,9 +419,7 @@ async function loadProjectCoverage(projectRoot, skipCache) {
417
419
  return cached.report;
418
420
  }
419
421
  }
420
- const { existsSync } = require('fs');
421
- const { readFile } = require('fs/promises');
422
- const { join, normalize } = require('path');
422
+ // existsSync, readFile, join, normalize imported at top of module
423
423
  // Try common coverage locations (all relative to validated root)
424
424
  const coverageLocations = [
425
425
  ['coverage', 'coverage-final.json'],
@@ -436,6 +436,11 @@ async function loadProjectCoverage(projectRoot, skipCache) {
436
436
  }
437
437
  if (existsSync(coveragePath)) {
438
438
  try {
439
+ const { stat } = await import('node:fs/promises');
440
+ const MAX_COVERAGE_SIZE = 50 * 1024 * 1024; // 50 MB
441
+ const fileStats = await stat(coveragePath);
442
+ if (fileStats.size > MAX_COVERAGE_SIZE)
443
+ continue;
439
444
  // Use async file read for non-blocking I/O
440
445
  const content = await readFile(coveragePath, 'utf-8');
441
446
  const router = new CoverageRouter();
@@ -446,8 +451,13 @@ async function loadProjectCoverage(projectRoot, skipCache) {
446
451
  else if (coveragePath.endsWith('.info')) {
447
452
  report = router.parseCoverage(content, 'lcov');
448
453
  }
449
- // Cache the result
454
+ // Cache the result (evict oldest entry if at capacity)
450
455
  if (report) {
456
+ if (coverageDataCache.size >= COVERAGE_CACHE_MAX) {
457
+ const firstKey = coverageDataCache.keys().next().value;
458
+ if (firstKey !== undefined)
459
+ coverageDataCache.delete(firstKey);
460
+ }
451
461
  coverageDataCache.set(root, { report, timestamp: Date.now() });
452
462
  return report;
453
463
  }
@@ -52,6 +52,7 @@ export declare class DiffClassifier {
52
52
  private ruvectorEngine;
53
53
  private useNative;
54
54
  private classificationCache;
55
+ private static readonly MAX_CLASSIFICATION_CACHE;
55
56
  constructor(config?: Partial<DiffClassifierConfig>);
56
57
  initialize(): Promise<void>;
57
58
  parseDiff(diffContent: string): FileDiff[];
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * Diff Classifier for Change Analysis
3
3
  */
4
+ import { execFileSync, execFile } from 'node:child_process';
5
+ import { promisify } from 'node:util';
6
+ const execFileAsync = promisify(execFile);
4
7
  const DEFAULT_CONFIG = {
5
8
  maxDiffSize: 10000,
6
9
  classifyByImpact: true,
@@ -25,6 +28,7 @@ export class DiffClassifier {
25
28
  ruvectorEngine = null;
26
29
  useNative = false;
27
30
  classificationCache = new Map();
31
+ static MAX_CLASSIFICATION_CACHE = 100;
28
32
  constructor(config = {}) {
29
33
  this.config = { ...DEFAULT_CONFIG, ...config };
30
34
  }
@@ -127,6 +131,11 @@ export class DiffClassifier {
127
131
  const testingStrategy = this.determineTestingStrategy(path, primary, impactLevel);
128
132
  const riskFactors = this.identifyRiskFactors(path, hunks, impactLevel);
129
133
  const classification = { primary, secondary, confidence, impactLevel, suggestedReviewers, testingStrategy, riskFactors };
134
+ if (this.classificationCache.size >= DiffClassifier.MAX_CLASSIFICATION_CACHE) {
135
+ const oldest = this.classificationCache.keys().next().value;
136
+ if (oldest !== undefined)
137
+ this.classificationCache.delete(oldest);
138
+ }
130
139
  this.classificationCache.set(cacheKey, classification);
131
140
  return classification;
132
141
  }
@@ -308,9 +317,10 @@ export function createDiffClassifier(config) {
308
317
  // ============================================================================
309
318
  // Optimized Git Diff Functions
310
319
  // ============================================================================
311
- // Cache for diff results (TTL-based)
320
+ // Cache for diff results (TTL-based, bounded LRU)
312
321
  const diffCache = new Map();
313
322
  const CACHE_TTL_MS = 5000; // 5 seconds - short TTL since diffs change frequently
323
+ const DIFF_CACHE_MAX_ENTRIES = 50;
314
324
  /**
315
325
  * Validate git ref to prevent command injection
316
326
  * Only allows safe characters: alphanumeric, -, _, /, ., ~, ^
@@ -320,6 +330,12 @@ function validateGitRef(ref) {
320
330
  if (!/^[a-zA-Z0-9_\-./~^@]+$/.test(ref)) {
321
331
  throw new Error(`Invalid git ref: contains unsafe characters`);
322
332
  }
333
+ // Reject leading dash — git interprets `-`-prefixed refs as flags (e.g. --output=...,
334
+ // -G<regex>, -S<string>). execFile defeats shell injection but does NOT prevent the
335
+ // git binary itself from treating an attacker-controlled ref as a flag.
336
+ if (ref.startsWith('-')) {
337
+ throw new Error(`Invalid git ref: must not start with '-'`);
338
+ }
323
339
  // Block multiple dots (path traversal)
324
340
  if (ref.includes('..') && !ref.match(/^[a-zA-Z0-9_\-]+\.\.\.?[a-zA-Z0-9_\-]+$/)) {
325
341
  if (!/^\w+\.\.[.\w]+$/.test(ref)) {
@@ -344,7 +360,7 @@ export function getGitDiffNumstat(ref = 'HEAD') {
344
360
  if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
345
361
  return cached.files;
346
362
  }
347
- const { execFileSync } = require('child_process');
363
+ // execFileSync imported at top of module
348
364
  try {
349
365
  // SECURITY: Use execFileSync with args array instead of shell string
350
366
  // This prevents command injection via the ref parameter
@@ -397,7 +413,13 @@ export function getGitDiffNumstat(ref = 'HEAD') {
397
413
  files.push({ path, status, additions, deletions, hunks: 1, binary });
398
414
  }
399
415
  }
400
- // Cache the result
416
+ // Cache the result with FIFO eviction. Without a cap, an attacker calling
417
+ // analyze_diff with HEAD~0...HEAD~N (all valid refs) grew this Map to GBs.
418
+ if (diffCache.size >= DIFF_CACHE_MAX_ENTRIES) {
419
+ const oldestKey = diffCache.keys().next().value;
420
+ if (oldestKey !== undefined)
421
+ diffCache.delete(oldestKey);
422
+ }
401
423
  diffCache.set(cacheKey, { files, timestamp: Date.now() });
402
424
  return files;
403
425
  }
@@ -417,9 +439,7 @@ export async function getGitDiffNumstatAsync(ref = 'HEAD') {
417
439
  if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
418
440
  return cached.files;
419
441
  }
420
- const { execFile } = require('child_process');
421
- const { promisify } = require('util');
422
- const execFileAsync = promisify(execFile);
442
+ // execFileAsync declared at top of module
423
443
  try {
424
444
  // SECURITY: Use execFile with args array instead of shell string
425
445
  const { stdout: numstatOutput } = await execFileAsync('git', [
@@ -8,8 +8,20 @@
8
8
  *
9
9
  * @module enhanced-model-router
10
10
  */
11
- import { existsSync, readFileSync } from 'fs';
12
- import { extname } from 'path';
11
+ import { existsSync, readFileSync, realpathSync, statSync } from 'fs';
12
+ import { extname, resolve, sep } from 'path';
13
+ const MAX_ROUTE_FILE_SIZE = 1 * 1024 * 1024; // 1 MB
14
+ function isPathSafe(filePath) {
15
+ const root = process.cwd();
16
+ try {
17
+ const real = realpathSync(filePath);
18
+ return real === root || real.startsWith(root + sep);
19
+ }
20
+ catch {
21
+ const resolved = resolve(filePath);
22
+ return resolved === root || resolved.startsWith(root + sep);
23
+ }
24
+ }
13
25
  import { getModelRouter } from './model-router.js';
14
26
  // ============================================================================
15
27
  // Intent Detection Patterns
@@ -361,6 +373,11 @@ export class EnhancedModelRouter {
361
373
  */
362
374
  async analyzeASTComplexity(filePath) {
363
375
  try {
376
+ if (!isPathSafe(filePath))
377
+ return 0.5;
378
+ const st = statSync(filePath, { throwIfNoEntry: false });
379
+ if (!st || st.size > MAX_ROUTE_FILE_SIZE)
380
+ return 0.5;
364
381
  const content = readFileSync(filePath, 'utf-8');
365
382
  const lines = content.split('\n');
366
383
  // Simple heuristics for complexity
@@ -419,6 +436,11 @@ export class EnhancedModelRouter {
419
436
  if (!filePath || !existsSync(filePath)) {
420
437
  return { success: false, confidence: 0 };
421
438
  }
439
+ if (!isPathSafe(filePath))
440
+ return { success: false, confidence: 0 };
441
+ const fst = statSync(filePath, { throwIfNoEntry: false });
442
+ if (!fst || fst.size > MAX_ROUTE_FILE_SIZE)
443
+ return { success: false, confidence: 0 };
422
444
  const originalCode = context?.originalCode || readFileSync(filePath, 'utf-8');
423
445
  const intentToInstruction = {
424
446
  'var-to-const': 'Convert all var declarations to const',
@@ -10,7 +10,7 @@
10
10
  * - Graph boundary analysis
11
11
  * - Flash Attention for faster similarity computations
12
12
  *
13
- * @module @monoes/cli/ruvector
13
+ * @module @monomind/cli/ruvector
14
14
  */
15
15
  export { QLearningRouter, createQLearningRouter, type QLearningRouterConfig, type RouteDecision } from './q-learning-router.js';
16
16
  export { MoERouter, getMoERouter, resetMoERouter, createMoERouter, EXPERT_NAMES, NUM_EXPERTS, INPUT_DIM, HIDDEN_DIM, type ExpertType, type MoERouterConfig, type RoutingResult, type LoadBalanceStats, } from './moe-router.js';
@@ -20,7 +20,6 @@ export { CoverageRouter, createCoverageRouter, coverageRoute, coverageSuggest, c
20
20
  export { coverageRouterTools, hooksCoverageRoute, hooksCoverageSuggest, hooksCoverageGaps } from './coverage-tools.js';
21
21
  export { buildDependencyGraph, analyzeGraph, analyzeMinCutBoundaries, analyzeModuleCommunities, detectCircularDependencies, exportToDot, loadRuVector, fallbackMinCut, fallbackLouvain, clearGraphCaches, getGraphCacheStats, type GraphNode, type GraphEdge, type DependencyGraph, type MinCutBoundary, type ModuleCommunity, type CircularDependency, type GraphAnalysisResult, } from './graph-analyzer.js';
22
22
  export { FlashAttention, getFlashAttention, resetFlashAttention, computeAttention, benchmarkFlashAttention, getFlashAttentionSpeedup, type FlashAttentionConfig, type AttentionResult, type BenchmarkResult, } from './flash-attention.js';
23
- export { LoRAAdapter, getLoRAAdapter, resetLoRAAdapter, createLoRAAdapter, adaptEmbedding, trainLoRA, getLoRAStats, DEFAULT_RANK, DEFAULT_ALPHA, INPUT_DIM as LORA_INPUT_DIM, OUTPUT_DIM as LORA_OUTPUT_DIM, type LoRAConfig, type LoRAWeights, type AdaptationResult, type LoRAStats, } from './lora-adapter.js';
24
23
  export { ModelRouter, getModelRouter, resetModelRouter, createModelRouter, routeToModel, routeToModelFull, analyzeTaskComplexity, getModelRouterStats, recordModelOutcome, MODEL_CAPABILITIES, COMPLEXITY_INDICATORS, type ClaudeModel, type ModelRouterConfig, type ModelRoutingResult, type ComplexityAnalysis, } from './model-router.js';
25
24
  export { SemanticRouter, createSemanticRouter, type Intent, type RouteResult, type RouterConfig, } from './semantic-router.js';
26
25
  export { isRuvllmWasmAvailable, initRuvllmWasm, getRuvllmStatus, createHnswRouter, createSonaInstant, createMicroLora, formatChat, createKvCache, createGenerateConfig, createBufferPool, createInferenceArena, HNSW_MAX_SAFE_PATTERNS, type HnswRouterConfig, type HnswPattern, type HnswRouteResult, type SonaConfig, type MicroLoraConfig, type ChatMessage, type GenerateOptions, type RuvllmStatus, } from './ruvllm-wasm.js';
@@ -10,7 +10,7 @@
10
10
  * - Graph boundary analysis
11
11
  * - Flash Attention for faster similarity computations
12
12
  *
13
- * @module @monoes/cli/ruvector
13
+ * @module @monomind/cli/ruvector
14
14
  */
15
15
  export { QLearningRouter, createQLearningRouter } from './q-learning-router.js';
16
16
  export { MoERouter, getMoERouter, resetMoERouter, createMoERouter, EXPERT_NAMES, NUM_EXPERTS, INPUT_DIM, HIDDEN_DIM, } from './moe-router.js';
@@ -30,7 +30,7 @@ export { buildDependencyGraph, analyzeGraph, analyzeMinCutBoundaries, analyzeMod
30
30
  // Cache utilities (NEW)
31
31
  clearGraphCaches, getGraphCacheStats, } from './graph-analyzer.js';
32
32
  export { FlashAttention, getFlashAttention, resetFlashAttention, computeAttention, benchmarkFlashAttention, getFlashAttentionSpeedup, } from './flash-attention.js';
33
- export { LoRAAdapter, getLoRAAdapter, resetLoRAAdapter, createLoRAAdapter, adaptEmbedding, trainLoRA, getLoRAStats, DEFAULT_RANK, DEFAULT_ALPHA, INPUT_DIM as LORA_INPUT_DIM, OUTPUT_DIM as LORA_OUTPUT_DIM, } from './lora-adapter.js';
33
+ // lora-adapter removed superseded by SONA instant adaptation
34
34
  export { ModelRouter, getModelRouter, resetModelRouter, createModelRouter, routeToModel, routeToModelFull, analyzeTaskComplexity, getModelRouterStats, recordModelOutcome, MODEL_CAPABILITIES, COMPLEXITY_INDICATORS, } from './model-router.js';
35
35
  export { SemanticRouter, createSemanticRouter, } from './semantic-router.js';
36
36
  // ── RuVector LLM WASM (inference utilities) ─────────────────
@@ -160,7 +160,7 @@ export declare class ModelRouter {
160
160
  /**
161
161
  * Record outcome for learning
162
162
  */
163
- recordOutcome(task: string, model: ClaudeModel, outcome: 'success' | 'failure' | 'escalated'): void;
163
+ recordOutcome(task: string, model: ClaudeModel, outcome: 'success' | 'failure' | 'escalated', complexity?: number): void;
164
164
  /**
165
165
  * Get router statistics
166
166
  */
@@ -186,7 +186,9 @@ export declare class ModelRouter {
186
186
  reset(): void;
187
187
  }
188
188
  /**
189
- * Get or create the singleton ModelRouter instance
189
+ * Get or create the singleton ModelRouter instance.
190
+ * Throws if called with a config that differs from the one used to create
191
+ * the existing instance — silent config mismatch causes hard-to-debug routing bugs.
190
192
  */
191
193
  export declare function getModelRouter(config?: Partial<ModelRouterConfig>): ModelRouter;
192
194
  /**
@@ -18,7 +18,7 @@
18
18
  *
19
19
  * @module model-router
20
20
  */
21
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
21
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync } from 'fs';
22
22
  import { dirname, join } from 'path';
23
23
  /**
24
24
  * Model capabilities and characteristics
@@ -323,7 +323,7 @@ export class ModelRouter {
323
323
  /**
324
324
  * Record outcome for learning
325
325
  */
326
- recordOutcome(task, model, outcome) {
326
+ recordOutcome(task, model, outcome, complexity) {
327
327
  // Update circuit breaker state
328
328
  if (outcome === 'failure') {
329
329
  this.consecutiveFailures[model]++;
@@ -331,11 +331,14 @@ export class ModelRouter {
331
331
  else {
332
332
  this.consecutiveFailures[model] = 0;
333
333
  }
334
+ // Use per-task complexity when provided; fall back to running average so
335
+ // callers that don't have the routing result can still record outcomes.
336
+ const taskComplexity = complexity ?? this.state.avgComplexity;
334
337
  // Track in history
335
338
  this.state.learningHistory.push({
336
339
  task: task.slice(0, 100),
337
340
  model,
338
- complexity: this.state.avgComplexity,
341
+ complexity: taskComplexity,
339
342
  outcome,
340
343
  timestamp: new Date().toISOString(),
341
344
  });
@@ -378,7 +381,16 @@ export class ModelRouter {
378
381
  const fullPath = join(process.cwd(), this.config.statePath);
379
382
  if (existsSync(fullPath)) {
380
383
  const data = readFileSync(fullPath, 'utf-8');
381
- return { ...defaultState, ...JSON.parse(data) };
384
+ const parsed = { ...defaultState, ...JSON.parse(data) };
385
+ if (!Number.isFinite(parsed.avgComplexity))
386
+ parsed.avgComplexity = defaultState.avgComplexity;
387
+ if (!Number.isFinite(parsed.avgConfidence))
388
+ parsed.avgConfidence = defaultState.avgConfidence;
389
+ if (!Number.isFinite(parsed.totalDecisions) || parsed.totalDecisions < 0)
390
+ parsed.totalDecisions = defaultState.totalDecisions;
391
+ if (!Number.isFinite(parsed.circuitBreakerTrips) || parsed.circuitBreakerTrips < 0)
392
+ parsed.circuitBreakerTrips = defaultState.circuitBreakerTrips;
393
+ return parsed;
382
394
  }
383
395
  }
384
396
  catch {
@@ -397,7 +409,9 @@ export class ModelRouter {
397
409
  mkdirSync(dir, { recursive: true });
398
410
  }
399
411
  this.state.lastUpdated = new Date().toISOString();
400
- writeFileSync(fullPath, JSON.stringify(this.state, null, 2));
412
+ const tmp = fullPath + '.tmp';
413
+ writeFileSync(tmp, JSON.stringify(this.state, null, 2));
414
+ renameSync(tmp, fullPath);
401
415
  }
402
416
  catch {
403
417
  // Ignore save errors in non-critical scenarios
@@ -425,12 +439,21 @@ export class ModelRouter {
425
439
  // Singleton & Factory Functions
426
440
  // ============================================================================
427
441
  let modelRouterInstance = null;
442
+ let modelRouterInstanceConfig;
428
443
  /**
429
- * Get or create the singleton ModelRouter instance
444
+ * Get or create the singleton ModelRouter instance.
445
+ * Throws if called with a config that differs from the one used to create
446
+ * the existing instance — silent config mismatch causes hard-to-debug routing bugs.
430
447
  */
431
448
  export function getModelRouter(config) {
432
449
  if (!modelRouterInstance) {
433
450
  modelRouterInstance = new ModelRouter(config);
451
+ modelRouterInstanceConfig = config;
452
+ return modelRouterInstance;
453
+ }
454
+ if (config !== undefined && JSON.stringify(config) !== JSON.stringify(modelRouterInstanceConfig)) {
455
+ throw new Error('ModelRouter singleton already initialized with different config. ' +
456
+ 'Call resetModelRouter() first, or use createModelRouter() for a separate instance.');
434
457
  }
435
458
  return modelRouterInstance;
436
459
  }
@@ -439,6 +462,7 @@ export function getModelRouter(config) {
439
462
  */
440
463
  export function resetModelRouter() {
441
464
  modelRouterInstance = null;
465
+ modelRouterInstanceConfig = undefined;
442
466
  }
443
467
  /**
444
468
  * Create a new ModelRouter instance (non-singleton)
@@ -195,6 +195,13 @@ export declare class MoERouter {
195
195
  * @returns MoE router instance
196
196
  */
197
197
  export declare function getMoERouter(config?: Partial<MoERouterConfig>): MoERouter;
198
+ /**
199
+ * Get singleton MoE router instance, waiting for initialization to complete
200
+ *
201
+ * @param config - Optional configuration (only used on first call)
202
+ * @returns Promise resolving to fully initialized MoE router instance
203
+ */
204
+ export declare function getMoERouterReady(config?: Partial<MoERouterConfig>): Promise<MoERouter>;
198
205
  /**
199
206
  * Reset singleton instance (for testing)
200
207
  */