muonroi-cli 1.7.2 → 1.8.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 (322) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +122 -122
  3. package/dist/packages/agent-harness-core/src/event-filter.js +1 -0
  4. package/dist/packages/agent-harness-core/src/event-redact.js +8 -0
  5. package/dist/packages/agent-harness-core/src/mcp-server.d.ts +16 -0
  6. package/dist/packages/agent-harness-core/src/mcp-server.js +88 -10
  7. package/dist/packages/agent-harness-core/src/protocol.d.ts +15 -0
  8. package/dist/packages/agent-harness-core/src/selector.js +2 -2
  9. package/dist/packages/agent-harness-core/src/transports/sidechannel.js +1 -1
  10. package/dist/packages/agent-harness-opentui/src/agent-mode.js +1 -1
  11. package/dist/packages/agent-harness-opentui/src/install.js +1 -1
  12. package/dist/src/__test-stubs__/vitest-setup.js +4 -0
  13. package/dist/src/agent-harness/__tests__/mock-model.spec.js +54 -0
  14. package/dist/src/agent-harness/mock-model.d.ts +1 -1
  15. package/dist/src/agent-harness/mock-model.js +32 -3
  16. package/dist/src/agent-harness/test-spawn.js +3 -1
  17. package/dist/src/chat/chat-keychain.js +9 -1
  18. package/dist/src/cli/cost-forensics.js +12 -12
  19. package/dist/src/cli/keys.d.ts +2 -2
  20. package/dist/src/cli/keys.js +107 -28
  21. package/dist/src/cli/usage-report.js +2 -2
  22. package/dist/src/council/__tests__/abort-threading.test.d.ts +1 -0
  23. package/dist/src/council/__tests__/abort-threading.test.js +193 -0
  24. package/dist/src/council/__tests__/clarification-prompt.test.js +21 -1
  25. package/dist/src/council/__tests__/council-turn-length-emit.test.d.ts +1 -0
  26. package/dist/src/council/__tests__/council-turn-length-emit.test.js +130 -0
  27. package/dist/src/council/__tests__/debate-round-budget.test.d.ts +1 -0
  28. package/dist/src/council/__tests__/debate-round-budget.test.js +45 -0
  29. package/dist/src/council/__tests__/evaluator-metrics.test.js +3 -0
  30. package/dist/src/council/__tests__/post-debate-recommendation.test.d.ts +1 -0
  31. package/dist/src/council/__tests__/post-debate-recommendation.test.js +58 -0
  32. package/dist/src/council/__tests__/research-tools.test.js +4 -0
  33. package/dist/src/council/__tests__/round-tools.test.js +6 -0
  34. package/dist/src/council/clarifier-question-cap.test.d.ts +12 -0
  35. package/dist/src/council/clarifier-question-cap.test.js +73 -0
  36. package/dist/src/council/clarifier.d.ts +29 -1
  37. package/dist/src/council/clarifier.js +64 -1
  38. package/dist/src/council/debate-planner.d.ts +2 -1
  39. package/dist/src/council/debate-planner.js +5 -3
  40. package/dist/src/council/debate.d.ts +9 -0
  41. package/dist/src/council/debate.js +88 -8
  42. package/dist/src/council/index.d.ts +46 -1
  43. package/dist/src/council/index.js +125 -19
  44. package/dist/src/council/llm.js +41 -13
  45. package/dist/src/council/prompts.js +56 -21
  46. package/dist/src/council/types.d.ts +14 -1
  47. package/dist/src/ee/__tests__/export-transcripts.test.js +1 -1
  48. package/dist/src/ee/bridge.d.ts +3 -1
  49. package/dist/src/ee/bridge.js +9 -3
  50. package/dist/src/ee/bridge.test.js +1 -2
  51. package/dist/src/ee/client.js +15 -2
  52. package/dist/src/ee/recall-ledger.d.ts +20 -0
  53. package/dist/src/ee/recall-ledger.js +40 -1
  54. package/dist/src/ee/search.d.ts +25 -0
  55. package/dist/src/ee/search.js +73 -0
  56. package/dist/src/ee/types.d.ts +15 -1
  57. package/dist/src/ee/who-am-i.d.ts +41 -0
  58. package/dist/src/ee/who-am-i.js +143 -0
  59. package/dist/src/ee/who-am-i.test.d.ts +1 -0
  60. package/dist/src/ee/who-am-i.test.js +101 -0
  61. package/dist/src/generated/version.d.ts +1 -1
  62. package/dist/src/generated/version.js +1 -1
  63. package/dist/src/headless/council-answers.js +1 -0
  64. package/dist/src/headless/output.d.ts +30 -1
  65. package/dist/src/headless/output.js +180 -0
  66. package/dist/src/headless/output.test.js +61 -1
  67. package/dist/src/hooks/index.js +48 -2
  68. package/dist/src/index.d.ts +2 -0
  69. package/dist/src/index.js +55 -60
  70. package/dist/src/lsp/client-normalize.test.d.ts +12 -0
  71. package/dist/src/lsp/client-normalize.test.js +34 -0
  72. package/dist/src/lsp/client.d.ts +1 -0
  73. package/dist/src/lsp/client.js +10 -2
  74. package/dist/src/lsp/manager.d.ts +1 -1
  75. package/dist/src/lsp/manager.js +2 -2
  76. package/dist/src/lsp/manager.test.js +2 -2
  77. package/dist/src/lsp/runtime.d.ts +1 -1
  78. package/dist/src/lsp/runtime.js +2 -2
  79. package/dist/src/maintain/__tests__/gh-create-pr.test.js +7 -3
  80. package/dist/src/maintain/__tests__/pr-builder.test.js +7 -3
  81. package/dist/src/mcp/__tests__/client-pool.spec.js +3 -3
  82. package/dist/src/mcp/__tests__/ee-tools.test.js +42 -14
  83. package/dist/src/mcp/__tests__/forensics-tools.test.js +3 -3
  84. package/dist/src/mcp/__tests__/lsp-tools.test.js +4 -4
  85. package/dist/src/mcp/client-pool.d.ts +1 -1
  86. package/dist/src/mcp/client-pool.js +25 -9
  87. package/dist/src/mcp/ee-tools.d.ts +10 -0
  88. package/dist/src/mcp/ee-tools.js +34 -0
  89. package/dist/src/mcp/oauth-callback.js +2 -2
  90. package/dist/src/mcp/parse-headers.test.js +14 -14
  91. package/dist/src/mcp/self-verify-jobs.js +1 -3
  92. package/dist/src/mcp/setup-guide-text.js +74 -74
  93. package/dist/src/mcp/smoke.test.js +43 -43
  94. package/dist/src/models/catalog-gemini.test.js +12 -10
  95. package/dist/src/models/catalog.json +106 -38
  96. package/dist/src/ops/doctor.js +7 -7
  97. package/dist/src/orchestrator/__tests__/auto-commit.test.d.ts +1 -0
  98. package/dist/src/orchestrator/__tests__/auto-commit.test.js +142 -0
  99. package/dist/src/orchestrator/__tests__/batch-turn-runner.test.js +2 -0
  100. package/dist/src/orchestrator/__tests__/delegations.test.d.ts +1 -0
  101. package/dist/src/orchestrator/__tests__/delegations.test.js +96 -0
  102. package/dist/src/orchestrator/__tests__/message-processor.test.js +1 -0
  103. package/dist/src/orchestrator/__tests__/stream-runner.test.js +29 -0
  104. package/dist/src/orchestrator/agent.test.js +5 -2
  105. package/dist/src/orchestrator/auto-commit.d.ts +110 -0
  106. package/dist/src/orchestrator/auto-commit.js +364 -0
  107. package/dist/src/orchestrator/batch-turn-runner.d.ts +3 -2
  108. package/dist/src/orchestrator/batch-turn-runner.js +2 -1
  109. package/dist/src/orchestrator/compaction-proposer-prompt.d.ts +8 -0
  110. package/dist/src/orchestrator/compaction-proposer-prompt.js +43 -0
  111. package/dist/src/orchestrator/compaction.d.ts +22 -0
  112. package/dist/src/orchestrator/compaction.js +42 -0
  113. package/dist/src/orchestrator/delegations.d.ts +1 -0
  114. package/dist/src/orchestrator/delegations.js +41 -0
  115. package/dist/src/orchestrator/error-utils.js +27 -2
  116. package/dist/src/orchestrator/message-processor.d.ts +21 -5
  117. package/dist/src/orchestrator/message-processor.js +219 -2573
  118. package/dist/src/orchestrator/orchestrator.d.ts +8 -2
  119. package/dist/src/orchestrator/orchestrator.js +187 -34
  120. package/dist/src/orchestrator/preprocessor.d.ts +13 -0
  121. package/dist/src/orchestrator/preprocessor.js +145 -0
  122. package/dist/src/orchestrator/prompts.d.ts +8 -0
  123. package/dist/src/orchestrator/prompts.js +76 -60
  124. package/dist/src/orchestrator/safety-askcard.d.ts +66 -0
  125. package/dist/src/orchestrator/safety-askcard.js +74 -0
  126. package/dist/src/orchestrator/sandbox.test.js +8 -5
  127. package/dist/src/orchestrator/scope-ceiling.js +1 -1
  128. package/dist/src/orchestrator/stall-watchdog.d.ts +47 -0
  129. package/dist/src/orchestrator/stall-watchdog.js +23 -0
  130. package/dist/src/orchestrator/stall-watchdog.test.js +36 -1
  131. package/dist/src/orchestrator/stream-runner.js +52 -30
  132. package/dist/src/orchestrator/sub-agent-model-tier.js +1 -1
  133. package/dist/src/orchestrator/subagent-compactor.d.ts +14 -0
  134. package/dist/src/orchestrator/subagent-compactor.js +83 -10
  135. package/dist/src/orchestrator/subagent-compactor.spec.js +132 -0
  136. package/dist/src/orchestrator/text-tool-call-detector.d.ts +9 -5
  137. package/dist/src/orchestrator/text-tool-call-detector.js +16 -12
  138. package/dist/src/orchestrator/text-tool-call-detector.test.js +66 -8
  139. package/dist/src/orchestrator/tool-args-repair.js +1 -1
  140. package/dist/src/orchestrator/tool-engine.d.ts +151 -0
  141. package/dist/src/orchestrator/tool-engine.js +3079 -0
  142. package/dist/src/orchestrator/turn-runner-deps.d.ts +1 -0
  143. package/dist/src/pil/__tests__/discovery-types.test.js +15 -4
  144. package/dist/src/pil/__tests__/discovery.test.js +89 -145
  145. package/dist/src/pil/__tests__/dual-run.test.js +2 -0
  146. package/dist/src/pil/__tests__/layer1-intent-trace.test.js +3 -0
  147. package/dist/src/pil/__tests__/layer1-intent.test.js +3 -0
  148. package/dist/src/pil/__tests__/layer16-clarity.test.js +35 -32
  149. package/dist/src/pil/__tests__/layer18-acceptance.test.js +1 -78
  150. package/dist/src/pil/__tests__/layer2_5-ponytail.test.d.ts +1 -0
  151. package/dist/src/pil/__tests__/layer2_5-ponytail.test.js +53 -0
  152. package/dist/src/pil/__tests__/layer3-ee-injection.test.js +67 -4
  153. package/dist/src/pil/__tests__/layer3-injected-chunk.test.js +14 -2
  154. package/dist/src/pil/__tests__/layer4-gsd.test.js +30 -0
  155. package/dist/src/pil/__tests__/layer5-context.test.js +39 -1
  156. package/dist/src/pil/__tests__/layer6-output.test.js +30 -2
  157. package/dist/src/pil/__tests__/orchestrator-integration.test.js +3 -1
  158. package/dist/src/pil/__tests__/pipeline.test.js +11 -8
  159. package/dist/src/pil/__tests__/response-tools.test.js +52 -0
  160. package/dist/src/pil/agent-operating-contract.d.ts +1 -1
  161. package/dist/src/pil/agent-operating-contract.js +5 -3
  162. package/dist/src/pil/agent-operating-contract.test.js +2 -2
  163. package/dist/src/pil/cheap-model-playbook.d.ts +1 -1
  164. package/dist/src/pil/cheap-model-playbook.js +1 -1
  165. package/dist/src/pil/cheap-model-workbooks.d.ts +1 -1
  166. package/dist/src/pil/cheap-model-workbooks.js +1 -1
  167. package/dist/src/pil/config.d.ts +20 -0
  168. package/dist/src/pil/config.js +35 -0
  169. package/dist/src/pil/discovery-types.d.ts +32 -9
  170. package/dist/src/pil/discovery.d.ts +3 -3
  171. package/dist/src/pil/discovery.js +138 -244
  172. package/dist/src/pil/index.d.ts +1 -1
  173. package/dist/src/pil/index.js +1 -1
  174. package/dist/src/pil/layer1-intent.d.ts +9 -1
  175. package/dist/src/pil/layer1-intent.js +99 -44
  176. package/dist/src/pil/layer1-intent.test.js +112 -2
  177. package/dist/src/pil/layer15-context-scan.js +1 -1
  178. package/dist/src/pil/layer16-clarity.d.ts +21 -25
  179. package/dist/src/pil/layer16-clarity.js +52 -88
  180. package/dist/src/pil/layer18-acceptance.d.ts +13 -3
  181. package/dist/src/pil/layer18-acceptance.js +1 -75
  182. package/dist/src/pil/layer2-personality.js +7 -8
  183. package/dist/src/pil/layer2_5-ponytail.d.ts +2 -0
  184. package/dist/src/pil/layer2_5-ponytail.js +41 -0
  185. package/dist/src/pil/layer3-ee-injection.js +180 -14
  186. package/dist/src/pil/layer4-gsd.js +22 -8
  187. package/dist/src/pil/layer5-context.d.ts +1 -0
  188. package/dist/src/pil/layer5-context.js +26 -11
  189. package/dist/src/pil/layer6-output.js +23 -5
  190. package/dist/src/pil/llm-classify.js +3 -3
  191. package/dist/src/pil/native-capabilities-workbook.d.ts +1 -1
  192. package/dist/src/pil/native-capabilities-workbook.js +4 -3
  193. package/dist/src/pil/pipeline.js +15 -1
  194. package/dist/src/pil/response-tools.d.ts +16 -0
  195. package/dist/src/pil/response-tools.js +41 -0
  196. package/dist/src/pil/schema.d.ts +8 -0
  197. package/dist/src/pil/schema.js +24 -3
  198. package/dist/src/pil/task-tier-map.js +7 -7
  199. package/dist/src/pil/types.d.ts +9 -3
  200. package/dist/src/product-loop/__tests__/discovery-interview.test.js +103 -1
  201. package/dist/src/product-loop/__tests__/gather-selectable-alts.test.js +34 -0
  202. package/dist/src/product-loop/__tests__/sprint-self-verify.test.js +12 -12
  203. package/dist/src/product-loop/discovery-interview.d.ts +20 -0
  204. package/dist/src/product-loop/discovery-interview.js +121 -7
  205. package/dist/src/product-loop/done-gate.js +3 -3
  206. package/dist/src/product-loop/gather.js +19 -5
  207. package/dist/src/product-loop/loop-driver.js +20 -20
  208. package/dist/src/product-loop/progress-snapshot.js +4 -4
  209. package/dist/src/product-loop/sprint-self-verify.js +2 -2
  210. package/dist/src/providers/__tests__/reasoning-roundtrip.test.js +12 -0
  211. package/dist/src/providers/auth/__tests__/gemini-oauth.test.d.ts +1 -5
  212. package/dist/src/providers/auth/__tests__/gemini-oauth.test.js +1 -5
  213. package/dist/src/providers/auth/gcloud.d.ts +28 -0
  214. package/dist/src/providers/auth/gcloud.js +102 -0
  215. package/dist/src/providers/auth/gemini-oauth.d.ts +46 -19
  216. package/dist/src/providers/auth/gemini-oauth.js +292 -105
  217. package/dist/src/providers/auth/grok-oauth.d.ts +1 -1
  218. package/dist/src/providers/auth/grok-oauth.js +1 -1
  219. package/dist/src/providers/auth/registry.js +28 -6
  220. package/dist/src/providers/gemini.d.ts +1 -1
  221. package/dist/src/providers/gemini.js +10 -3
  222. package/dist/src/providers/keychain.d.ts +2 -2
  223. package/dist/src/providers/keychain.js +20 -2
  224. package/dist/src/providers/mcp-vision-bridge.js +48 -48
  225. package/dist/src/providers/openai.js +5 -1
  226. package/dist/src/providers/runtime.d.ts +1 -1
  227. package/dist/src/providers/runtime.js +11 -2
  228. package/dist/src/providers/siliconflow-sse-repair.js +1 -1
  229. package/dist/src/providers/strategies/google.strategy.d.ts +9 -2
  230. package/dist/src/providers/strategies/google.strategy.js +159 -9
  231. package/dist/src/providers/strategies/thinking-mode.js +19 -6
  232. package/dist/src/providers/types.d.ts +1 -1
  233. package/dist/src/reporter/index.js +1 -1
  234. package/dist/src/router/decide.test.js +40 -8
  235. package/dist/src/router/step-router.d.ts +20 -0
  236. package/dist/src/router/step-router.js +73 -0
  237. package/dist/src/scaffold/bb-ecosystem-apply.js +47 -47
  238. package/dist/src/scaffold/bb-quality-gate.js +5 -5
  239. package/dist/src/scaffold/continuation-prompt.js +60 -60
  240. package/dist/src/scaffold/init-new.js +453 -453
  241. package/dist/src/self-qa/__tests__/scenario-planner.test.js +3 -3
  242. package/dist/src/self-qa/agentic-loop.js +19 -19
  243. package/dist/src/self-qa/orchestrator.js +5 -5
  244. package/dist/src/self-qa/scenario-planner.js +1 -1
  245. package/dist/src/self-qa/spec-emitter.js +4 -4
  246. package/dist/src/storage/__tests__/migrations.test.js +2 -2
  247. package/dist/src/storage/index.d.ts +1 -1
  248. package/dist/src/storage/index.js +1 -1
  249. package/dist/src/storage/interaction-log.js +5 -5
  250. package/dist/src/storage/migrations.js +122 -122
  251. package/dist/src/storage/session-experience-store.js +4 -4
  252. package/dist/src/storage/sessions.js +43 -43
  253. package/dist/src/storage/transcript-view.js +7 -1
  254. package/dist/src/storage/transcript.d.ts +1 -0
  255. package/dist/src/storage/transcript.js +55 -0
  256. package/dist/src/storage/ui-interaction-log.d.ts +17 -0
  257. package/dist/src/storage/usage.js +14 -14
  258. package/dist/src/storage/workspaces.js +12 -12
  259. package/dist/src/tools/__tests__/native-tools.test.js +6 -0
  260. package/dist/src/tools/bash.d.ts +36 -23
  261. package/dist/src/tools/bash.js +59 -301
  262. package/dist/src/tools/bash.test.js +2 -257
  263. package/dist/src/tools/file-tracker.d.ts +5 -0
  264. package/dist/src/tools/file-tracker.js +14 -0
  265. package/dist/src/tools/file.js +2 -0
  266. package/dist/src/tools/git-safety.d.ts +38 -1
  267. package/dist/src/tools/git-safety.js +94 -4
  268. package/dist/src/tools/git-safety.test.js +45 -1
  269. package/dist/src/tools/native-tools.d.ts +1 -1
  270. package/dist/src/tools/native-tools.js +56 -0
  271. package/dist/src/tools/registry-bash-empty-command.test.js +4 -3
  272. package/dist/src/tools/registry-git-safety.test.js +17 -6
  273. package/dist/src/tools/registry.d.ts +5 -0
  274. package/dist/src/tools/registry.js +185 -11
  275. package/dist/src/types/index.d.ts +7 -1
  276. package/dist/src/ui/app.d.ts +1 -0
  277. package/dist/src/ui/app.js +0 -0
  278. package/dist/src/ui/components/council-question-card.js +1 -0
  279. package/dist/src/ui/components/message-view.js +37 -3
  280. package/dist/src/ui/components/structured-response-view.js +7 -0
  281. package/dist/src/ui/components/task-list-panel.js +3 -12
  282. package/dist/src/ui/containers/chat-feed.d.ts +40 -0
  283. package/dist/src/ui/containers/chat-feed.js +66 -0
  284. package/dist/src/ui/containers/modals-layer.d.ts +87 -0
  285. package/dist/src/ui/containers/modals-layer.js +18 -0
  286. package/dist/src/ui/slash/__tests__/menu-parity.test.d.ts +1 -0
  287. package/dist/src/ui/slash/__tests__/menu-parity.test.js +1 -0
  288. package/dist/src/ui/slash/__tests__/ponytail.test.d.ts +1 -0
  289. package/dist/src/ui/slash/__tests__/ponytail.test.js +37 -0
  290. package/dist/src/ui/slash/council-inspect.js +4 -4
  291. package/dist/src/ui/slash/export.js +16 -1
  292. package/dist/src/ui/slash/menu-items.js +1 -0
  293. package/dist/src/ui/slash/ponytail.d.ts +2 -0
  294. package/dist/src/ui/slash/ponytail.js +19 -0
  295. package/dist/src/ui/status-bar/store.js +0 -1
  296. package/dist/src/ui/status-bar/store.test.js +2 -2
  297. package/dist/src/ui/use-app-logic.d.ts +26 -0
  298. package/dist/src/ui/use-app-logic.js +0 -0
  299. package/dist/src/ui/utils/relaunch.js +1 -1
  300. package/dist/src/ui/utils/text.d.ts +11 -0
  301. package/dist/src/ui/utils/text.js +21 -1
  302. package/dist/src/ui/utils/text.test.js +25 -1
  303. package/dist/src/ui/utils/tools.js +3 -1
  304. package/dist/src/usage/cost-log.js +2 -2
  305. package/dist/src/usage/estimator.d.ts +14 -0
  306. package/dist/src/usage/estimator.js +22 -0
  307. package/dist/src/utils/__tests__/compaction-caps.test.d.ts +21 -0
  308. package/dist/src/utils/__tests__/compaction-caps.test.js +187 -0
  309. package/dist/src/utils/__tests__/llm-deadline-abort.test.d.ts +1 -0
  310. package/dist/src/utils/__tests__/llm-deadline-abort.test.js +33 -0
  311. package/dist/src/utils/clipboard-image.js +23 -23
  312. package/dist/src/utils/llm-deadline.d.ts +9 -1
  313. package/dist/src/utils/llm-deadline.js +31 -2
  314. package/dist/src/utils/permission-mode.d.ts +33 -0
  315. package/dist/src/utils/permission-mode.js +164 -3
  316. package/dist/src/utils/permission-mode.test.js +92 -1
  317. package/dist/src/utils/settings.d.ts +27 -31
  318. package/dist/src/utils/settings.js +100 -109
  319. package/dist/src/utils/side-question.js +2 -2
  320. package/dist/src/utils/skills.js +3 -3
  321. package/dist/src/verify/__tests__/coverage-parsers.test.js +30 -30
  322. package/package.json +1 -1
@@ -26,7 +26,80 @@
26
26
  */
27
27
  import { getModelByTier } from "../models/registry.js";
28
28
  import { detectProviderForModel } from "../providers/runtime.js";
29
+ import { readTimeoutEnv } from "../utils/ee-logger.js";
29
30
  import { isModelDisabled, isProviderDisabled, loadUserSettings } from "../utils/settings.js";
31
+ // ─── EE-guided SAMR override ─────────────────────────────────────────────────
32
+ // EE_SAMR_TIMEOUT: per-call budget for consulting the EE brain about SAMR.
33
+ // Default 2s, range 500ms..5s. Falls back to heuristics on timeout/error.
34
+ const EE_SAMR_TIMEOUT_MS = readTimeoutEnv("MUONROI_EE_SAMR_TIMEOUT_MS", 2000, 500, 5000);
35
+ /**
36
+ * Consult the EE brain + local heuristics to decide whether SAMR should be
37
+ * enabled for this turn even when the user config has it disabled.
38
+ *
39
+ * Resolution order:
40
+ * 1. Fast heuristic — mechanical/simple tasks skip EE entirely (zero cost).
41
+ * 2. EE brain — asks classifyViaBrain for a yes/no + execution tier.
42
+ * 3. Heuristic fallback — when EE is unreachable, uses taskType + complexity.
43
+ */
44
+ export async function eeSamrGuidance(params) {
45
+ const { userMessage, taskType, taskConfidence, complexitySize, taskComplexity } = params;
46
+ // Step 1: fast heuristic — mechanical tasks never benefit from SAMR
47
+ const mechanicalTypes = new Set(["general", "documentation", "generate", "build", "chitchat"]);
48
+ if (taskType && mechanicalTypes.has(taskType)) {
49
+ return { overrideConfig: null, reason: `mechanical taskType=${taskType} — no SAMR benefit` };
50
+ }
51
+ // Step 2: fast heuristic — trivial tasks don't need a split
52
+ if (taskComplexity === "low" && (complexitySize === "small" || complexitySize === undefined)) {
53
+ return { overrideConfig: null, reason: "low complexity + small — no SAMR benefit" };
54
+ }
55
+ // Step 3: ask EE brain
56
+ try {
57
+ const { classifyViaBrain } = await import("../ee/bridge.js");
58
+ const eePrompt = [
59
+ `Task: ${userMessage.slice(0, 200)}`,
60
+ `Context: type=${taskType ?? "unknown"} complexity=${taskComplexity ?? "unknown"} size=${complexitySize ?? "unknown"}`,
61
+ `Question: Would splitting the work into (1) premium reasoning then (2) cheap execution save tokens without hurting quality?`,
62
+ `Reply valid JSON: {"samr":true,"executionTier":"balanced"} or {"samr":false}`,
63
+ ].join("\n");
64
+ const response = await classifyViaBrain(eePrompt, EE_SAMR_TIMEOUT_MS, {
65
+ systemPrompt: 'You are a SAMR (Step-Aware Model Routing) evaluator. Given a task description, context, and question, reply ONLY with valid JSON: {"samr":true,"executionTier":"balanced"} or {"samr":false}. No extra text, no markdown.',
66
+ responseFormat: { type: "json_object" },
67
+ maxTokens: 100,
68
+ });
69
+ if (!response) {
70
+ // Fallback heuristic when EE unreachable
71
+ return samrHeuristicFallback(taskType, taskComplexity, complexitySize);
72
+ }
73
+ const parsed = JSON.parse(response);
74
+ if (parsed.samr === true) {
75
+ const tier = parsed.executionTier === "fast" ? "fast" : "balanced";
76
+ return {
77
+ overrideConfig: { enabled: true, toolExecutionTier: tier, premiumSynthesis: false },
78
+ reason: `ee-guided: ${tier} execution phase`,
79
+ };
80
+ }
81
+ return { overrideConfig: null, reason: "ee-declined" };
82
+ }
83
+ catch {
84
+ return samrHeuristicFallback(taskType, taskComplexity, complexitySize);
85
+ }
86
+ }
87
+ /**
88
+ * Deterministic fallback when EE brain is unreachable.
89
+ * Reasoning-heavy tasks with high complexity are strong SAMR candidates.
90
+ */
91
+ function samrHeuristicFallback(taskType, taskComplexity, complexitySize) {
92
+ const reasoningTypes = new Set(["plan", "analyze", "refactor", "debug", "architect"]);
93
+ if (taskType && reasoningTypes.has(taskType)) {
94
+ if (taskComplexity === "high" || complexitySize === "large") {
95
+ return {
96
+ overrideConfig: { enabled: true, toolExecutionTier: "balanced", premiumSynthesis: false },
97
+ reason: `heuristic: ${taskType}/${taskComplexity ?? "?"}/${complexitySize ?? "?"} benefits from SAMR`,
98
+ };
99
+ }
100
+ }
101
+ return { overrideConfig: null, reason: "heuristic: no benefit" };
102
+ }
30
103
  // ─── Defaults ────────────────────────────────────────────────────────────────
31
104
  const DEFAULT_CONFIG = {
32
105
  enabled: false,
@@ -91,24 +91,24 @@ function buildSampleRuleCs(projectName, intent) {
91
91
  .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
92
92
  .join("");
93
93
  const contextTypeName = `${projectName}RuleContext`;
94
- return `using Muonroi.RuleEngine.Abstractions;
95
- using Muonroi.RuleEngine.Core;
96
-
97
- namespace ${projectName}.Domain.Rules;
98
-
99
- /// <summary>
100
- /// Sample rule for intent: ${intent}.
101
- /// Generated by muonroi-cli — replace stub logic with real business logic.
102
- /// </summary>
103
- [MExtractAsRule("SAMPLE_${intent.toUpperCase().replace(/[-\s]/g, "_")}", DependsOn = new string[] { })]
104
- public class Sample${intentPascal}Rule : IRule<${contextTypeName}>
105
- {
106
- public Task<RuleResult> EvaluateAsync(${contextTypeName} context, CancellationToken cancellationToken = default)
107
- {
108
- // TODO: Replace with real ${intent} evaluation logic.
109
- return Task.FromResult(RuleResult.Passed());
110
- }
111
- }
94
+ return `using Muonroi.RuleEngine.Abstractions;
95
+ using Muonroi.RuleEngine.Core;
96
+
97
+ namespace ${projectName}.Domain.Rules;
98
+
99
+ /// <summary>
100
+ /// Sample rule for intent: ${intent}.
101
+ /// Generated by muonroi-cli — replace stub logic with real business logic.
102
+ /// </summary>
103
+ [MExtractAsRule("SAMPLE_${intent.toUpperCase().replace(/[-\s]/g, "_")}", DependsOn = new string[] { })]
104
+ public class Sample${intentPascal}Rule : IRule<${contextTypeName}>
105
+ {
106
+ public Task<RuleResult> EvaluateAsync(${contextTypeName} context, CancellationToken cancellationToken = default)
107
+ {
108
+ // TODO: Replace with real ${intent} evaluation logic.
109
+ return Task.FromResult(RuleResult.Passed());
110
+ }
111
+ }
112
112
  `;
113
113
  }
114
114
  export async function generateSampleRule(serverDir, projectName, intent, fsOps) {
@@ -133,32 +133,32 @@ function buildSampleRuleTestCs(projectName, intent) {
133
133
  .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
134
134
  .join("");
135
135
  const contextTypeName = `${projectName}RuleContext`;
136
- return `using Muonroi.RuleEngine.Abstractions;
137
- using Muonroi.RuleEngine.Core;
138
- using Xunit;
139
-
140
- namespace ${projectName}.UnitTests.Rules;
141
-
142
- /// <summary>
143
- /// Tests for Sample${intentPascal}Rule.
144
- /// Generated by muonroi-cli — extend with real test cases.
145
- /// </summary>
146
- public class Sample${intentPascal}RuleTests
147
- {
148
- [Fact]
149
- public async Task EvaluateAsync_ReturnsRuleResultPassed()
150
- {
151
- // Arrange — senior-grade: uses FactBag + reflection-free context construction
152
- var context = new ${contextTypeName}();
153
- var rule = new Sample${intentPascal}Rule();
154
-
155
- // Act
156
- var result = await rule.EvaluateAsync(context, CancellationToken.None);
157
-
158
- // Assert
159
- Assert.Equal(RuleResultStatus.Passed, result.Status);
160
- }
161
- }
136
+ return `using Muonroi.RuleEngine.Abstractions;
137
+ using Muonroi.RuleEngine.Core;
138
+ using Xunit;
139
+
140
+ namespace ${projectName}.UnitTests.Rules;
141
+
142
+ /// <summary>
143
+ /// Tests for Sample${intentPascal}Rule.
144
+ /// Generated by muonroi-cli — extend with real test cases.
145
+ /// </summary>
146
+ public class Sample${intentPascal}RuleTests
147
+ {
148
+ [Fact]
149
+ public async Task EvaluateAsync_ReturnsRuleResultPassed()
150
+ {
151
+ // Arrange — senior-grade: uses FactBag + reflection-free context construction
152
+ var context = new ${contextTypeName}();
153
+ var rule = new Sample${intentPascal}Rule();
154
+
155
+ // Act
156
+ var result = await rule.EvaluateAsync(context, CancellationToken.None);
157
+
158
+ // Assert
159
+ Assert.Equal(RuleResultStatus.Passed, result.Status);
160
+ }
161
+ }
162
162
  `;
163
163
  }
164
164
  export async function generateSampleRuleTest(serverDir, projectName, intent, fsOps) {
@@ -246,9 +246,9 @@ export async function copyBoundaryScript(serverDir, bbRepoRoot, fsOps) {
246
246
  const ciContent = fsOps.readFile(ciYmlPath);
247
247
  // Idempotency: skip if already wired
248
248
  if (!ciContent.includes(BOUNDARIES_SCRIPT_NAME)) {
249
- const boundaryStep = `
250
- - name: Check modular boundaries
251
- run: pwsh ./scripts/${BOUNDARIES_SCRIPT_NAME} -RepoRoot .
249
+ const boundaryStep = `
250
+ - name: Check modular boundaries
251
+ run: pwsh ./scripts/${BOUNDARIES_SCRIPT_NAME} -RepoRoot .
252
252
  `;
253
253
  // Append before the last line or after the last job step
254
254
  const updated = `${ciContent.trimEnd()}\n${boundaryStep}\n`;
@@ -93,11 +93,11 @@ export async function runQualityGateWithRetry(opts, onRetryCodeGen) {
93
93
  const failureSummary = firstResult.failures
94
94
  .map((f) => `### ${f.step}\n\`\`\`\n${f.output.slice(0, 500)}\n\`\`\``)
95
95
  .join("\n\n");
96
- const councilPrompt = `${opts.intentPrompt}
97
-
98
- ## Gate failures (please fix in next iteration)
99
- ${failureSummary}
100
-
96
+ const councilPrompt = `${opts.intentPrompt}
97
+
98
+ ## Gate failures (please fix in next iteration)
99
+ ${failureSummary}
100
+
101
101
  Please revise the BB ecosystem wiring to fix these compilation/boundary errors.`;
102
102
  // Call council once with failures appended
103
103
  await continueAsCouncil({
@@ -1,66 +1,66 @@
1
1
  export function buildIdealContinuationPrompt(input) {
2
2
  const { originalPrompt, projectDir, templateName, installedPackages } = input;
3
3
  const packagesSuffix = installedPackages && installedPackages.length > 0 ? ` with packages: ${installedPackages.join(", ")}` : "";
4
- return `You are continuing a /ideal product loop. The project has been scaffolded at ${projectDir} using the BB template ${templateName}${packagesSuffix}.
5
-
6
- User's original request:
7
- "${originalPrompt}"
8
-
9
- You MUST implement this feature now. Do NOT ask the user for clarification unless a hard blocker is reached (missing API key, ambiguous schema requirement, etc.).
10
-
11
- Execute these steps in order:
12
-
13
- 1. Discover structure (1-2 tool calls max)
14
- - PREFERRED: if a \`muonroi-docs\` MCP tool is in your tool list (look for any \`mcp_*docs*_docs_search\` tool), call it with query \`"${templateName} structure overview"\`. This is faster than reading files.
15
- - FALLBACK: list the project directory, then read whichever of \`README.md\`, \`AGENTS.md\`, \`Agent.md\`, \`EE-INTENT.md\` actually exist (do NOT assume — missing files are fine, just skip them).
16
- - Identify: project name, main entry point (Program.cs / Gateway), modular boundaries, where to add new domain code.
17
-
18
- IMPORTANT — Template sample files are REFERENCE ONLY:
19
- - The BB template ships example code (e.g. \`todo-app.Catalog\`, sample \`TodoRepository\`, \`Catalog\` controller, \`DocTemplateDbContext\`, \`BaseTemplateDbContext\`) named after the template/demo, NOT after the user's project.
20
- - Read AT MOST ONE such sample file to learn the convention, then DELETE all template sample directories before generating your real domain code. They are reference, not the user's feature.
21
- - Do not re-read the same sample file repeatedly. If you need its pattern again, recall from memory or rely on \`docs.search\`.
22
- - RENAME every file/class/namespace that still contains the literal token \`BaseTemplate\`, \`DocTemplate\`, or \`TemplateSample\` to a project-appropriate name BEFORE writing domain code. After cleanup, \`git grep -i basetemplate\` MUST return zero hits — the post-scaffold quality gate fails if any survive.
23
- - DELETE any stub \`<projectName>.Catalog/\` directory that lives at server root next to \`server/src/Services/\` — \`dotnet new\` may emit a duplicate empty stub.
24
-
25
- .NET / C# conventions to follow:
26
- - Async methods MUST accept and forward \`CancellationToken\` to every downstream await; suffix names with \`Async\`.
27
- - Prefer singular folder names that already exist in the template; if you add new folders, use \`Infrastructure\` (singular), \`Enums\` (plural), \`Authorization\` instead of "Permissioning".
28
- - Namespace MUST mirror the folder path under the project, in PascalCase.
29
- - DTO ≠ Entity. Don't return EF entities from controllers — always project to a DTO.
30
- - DI registration uses \`AddX*\` extension methods in a static class under \`Extensions/\` or \`DependencyInjection/\`; wire them from \`Program.cs\`. Do not register services inline in \`Program.cs\`.
31
-
32
- Frontend / client/ conventions (apply ONLY if a \`client/\` directory exists in the scaffold):
33
- - NEVER delete or overwrite \`SemanticProvider\`, \`createSemanticRegistry\`, or any \`<Semantic ...>\` wrapper that the scaffold wrote into \`main.tsx\` / \`app.component.ts\`. The agent harness depends on them — removing them silently breaks all E2E specs. If you rewrite \`main.tsx\`, re-include the existing SemanticProvider block verbatim.
34
- - Wrap every NEW user-visible region with \`<Semantic id="..." role="..." name="...">\` (composer, list, listitem, modal, statusbar). Pick \`role\` from the union in \`@muonroi/agent-harness-core/protocol\`.
35
- - NEVER hardcode API URLs in components. Read from \`import.meta.env.VITE_API_BASE\` (React/Vite) or \`environment.apiBase\` (Angular). If \`.env.example\` does not exist yet, create it with a sensible default; never inline \`http://localhost:5000\` or similar in source.
36
- - Put HTTP + DTO code under \`client/src/api/\`. Define request/response types in \`api/types.ts\` (mirror the C# DTO names). Components import a typed client; never call \`fetch\` directly.
37
- - Every async view needs THREE states: loading, empty, error. Surface errors via a toast/notification component, not \`console.error\`. Provide an \`ErrorBoundary\` at the app shell.
38
- - No inline \`style={{...}}\` literals — use CSS modules (\`*.module.css\`) or utility classes (Tailwind if scaffolded). If neither is present, write tokens + reset into \`src/styles/app.css\` and import it ONCE in main; reference variables via \`var(--color-...)\`.
39
- - TypeScript MUST be strict. If \`tsconfig.json\` does not have \`"strict": true\`, add it. Run \`bunx tsc --noEmit\` before declaring done — it must exit 0.
40
- - Run \`bun run build\` from \`client/\` before declaring done — it must exit 0 with zero browser-side console errors.
41
-
42
- 2. Design the feature
43
- - List the domain entity(ies), DTOs, endpoints, persistence model.
44
- - Match BB conventions (controller-per-resource, MediatR/CQRS if used, validation patterns observed in step 1).
45
- - State your design in 5-10 lines before generating code.
46
-
47
- 3. Generate code
48
- - Create files in the locations identified in step 1.
49
- - Wire DI in Program.cs (use BB extension methods if present).
50
- - Mirror existing patterns — same namespaces, attributes, error-handling style.
51
-
52
- 4. Verify
53
- - Run \`dotnet build\` from the server root — must exit 0.
54
- - If a \`client/\` directory exists, also run \`bun install\` and \`bun run build\` from \`client/\`.
55
- - Report concrete evidence: build output excerpt + file list created.
56
-
57
- 5. Summarize
58
- - 3-5 bullets: what was added, where, how to test manually.
59
-
60
- Constraints:
61
- - Don't re-scaffold. Don't run \`dotnet new\` again.
62
- - Don't \`cd\` into ${projectDir} — your working directory is already there.
63
- - Don't ask "do you want me to continue?" — proceed end-to-end.
4
+ return `You are continuing a /ideal product loop. The project has been scaffolded at ${projectDir} using the BB template ${templateName}${packagesSuffix}.
5
+
6
+ User's original request:
7
+ "${originalPrompt}"
8
+
9
+ You MUST implement this feature now. Do NOT ask the user for clarification unless a hard blocker is reached (missing API key, ambiguous schema requirement, etc.).
10
+
11
+ Execute these steps in order:
12
+
13
+ 1. Discover structure (1-2 tool calls max)
14
+ - PREFERRED: if a \`muonroi-docs\` MCP tool is in your tool list (look for any \`mcp_*docs*_docs_search\` tool), call it with query \`"${templateName} structure overview"\`. This is faster than reading files.
15
+ - FALLBACK: list the project directory, then read whichever of \`README.md\`, \`AGENTS.md\`, \`Agent.md\`, \`EE-INTENT.md\` actually exist (do NOT assume — missing files are fine, just skip them).
16
+ - Identify: project name, main entry point (Program.cs / Gateway), modular boundaries, where to add new domain code.
17
+
18
+ IMPORTANT — Template sample files are REFERENCE ONLY:
19
+ - The BB template ships example code (e.g. \`todo-app.Catalog\`, sample \`TodoRepository\`, \`Catalog\` controller, \`DocTemplateDbContext\`, \`BaseTemplateDbContext\`) named after the template/demo, NOT after the user's project.
20
+ - Read AT MOST ONE such sample file to learn the convention, then DELETE all template sample directories before generating your real domain code. They are reference, not the user's feature.
21
+ - Do not re-read the same sample file repeatedly. If you need its pattern again, recall from memory or rely on \`docs.search\`.
22
+ - RENAME every file/class/namespace that still contains the literal token \`BaseTemplate\`, \`DocTemplate\`, or \`TemplateSample\` to a project-appropriate name BEFORE writing domain code. After cleanup, \`git grep -i basetemplate\` MUST return zero hits — the post-scaffold quality gate fails if any survive.
23
+ - DELETE any stub \`<projectName>.Catalog/\` directory that lives at server root next to \`server/src/Services/\` — \`dotnet new\` may emit a duplicate empty stub.
24
+
25
+ .NET / C# conventions to follow:
26
+ - Async methods MUST accept and forward \`CancellationToken\` to every downstream await; suffix names with \`Async\`.
27
+ - Prefer singular folder names that already exist in the template; if you add new folders, use \`Infrastructure\` (singular), \`Enums\` (plural), \`Authorization\` instead of "Permissioning".
28
+ - Namespace MUST mirror the folder path under the project, in PascalCase.
29
+ - DTO ≠ Entity. Don't return EF entities from controllers — always project to a DTO.
30
+ - DI registration uses \`AddX*\` extension methods in a static class under \`Extensions/\` or \`DependencyInjection/\`; wire them from \`Program.cs\`. Do not register services inline in \`Program.cs\`.
31
+
32
+ Frontend / client/ conventions (apply ONLY if a \`client/\` directory exists in the scaffold):
33
+ - NEVER delete or overwrite \`SemanticProvider\`, \`createSemanticRegistry\`, or any \`<Semantic ...>\` wrapper that the scaffold wrote into \`main.tsx\` / \`app.component.ts\`. The agent harness depends on them — removing them silently breaks all E2E specs. If you rewrite \`main.tsx\`, re-include the existing SemanticProvider block verbatim.
34
+ - Wrap every NEW user-visible region with \`<Semantic id="..." role="..." name="...">\` (composer, list, listitem, modal, statusbar). Pick \`role\` from the union in \`@muonroi/agent-harness-core/protocol\`.
35
+ - NEVER hardcode API URLs in components. Read from \`import.meta.env.VITE_API_BASE\` (React/Vite) or \`environment.apiBase\` (Angular). If \`.env.example\` does not exist yet, create it with a sensible default; never inline \`http://localhost:5000\` or similar in source.
36
+ - Put HTTP + DTO code under \`client/src/api/\`. Define request/response types in \`api/types.ts\` (mirror the C# DTO names). Components import a typed client; never call \`fetch\` directly.
37
+ - Every async view needs THREE states: loading, empty, error. Surface errors via a toast/notification component, not \`console.error\`. Provide an \`ErrorBoundary\` at the app shell.
38
+ - No inline \`style={{...}}\` literals — use CSS modules (\`*.module.css\`) or utility classes (Tailwind if scaffolded). If neither is present, write tokens + reset into \`src/styles/app.css\` and import it ONCE in main; reference variables via \`var(--color-...)\`.
39
+ - TypeScript MUST be strict. If \`tsconfig.json\` does not have \`"strict": true\`, add it. Run \`bunx tsc --noEmit\` before declaring done — it must exit 0.
40
+ - Run \`bun run build\` from \`client/\` before declaring done — it must exit 0 with zero browser-side console errors.
41
+
42
+ 2. Design the feature
43
+ - List the domain entity(ies), DTOs, endpoints, persistence model.
44
+ - Match BB conventions (controller-per-resource, MediatR/CQRS if used, validation patterns observed in step 1).
45
+ - State your design in 5-10 lines before generating code.
46
+
47
+ 3. Generate code
48
+ - Create files in the locations identified in step 1.
49
+ - Wire DI in Program.cs (use BB extension methods if present).
50
+ - Mirror existing patterns — same namespaces, attributes, error-handling style.
51
+
52
+ 4. Verify
53
+ - Run \`dotnet build\` from the server root — must exit 0.
54
+ - If a \`client/\` directory exists, also run \`bun install\` and \`bun run build\` from \`client/\`.
55
+ - Report concrete evidence: build output excerpt + file list created.
56
+
57
+ 5. Summarize
58
+ - 3-5 bullets: what was added, where, how to test manually.
59
+
60
+ Constraints:
61
+ - Don't re-scaffold. Don't run \`dotnet new\` again.
62
+ - Don't \`cd\` into ${projectDir} — your working directory is already there.
63
+ - Don't ask "do you want me to continue?" — proceed end-to-end.
64
64
  - If you hit a blocker that genuinely needs the user, state EXACTLY which decision is blocking and stop.`;
65
65
  }
66
66
  //# sourceMappingURL=continuation-prompt.js.map