@skathio/somi 4.1.1 → 5.0.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 (372) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +8 -3
  3. package/.claude-plugin/plugin.json +9 -10
  4. package/.copilot-extension/extension.json +32 -40
  5. package/.copilot-extension/marketplace.json +8 -3
  6. package/README.md +83 -228
  7. package/VERSION +1 -1
  8. package/agents/somi-reviewer.md +21 -40
  9. package/agents/somi-security-reviewer.md +16 -90
  10. package/agents/somi-worker-high.md +11 -0
  11. package/agents/somi-worker-low.md +11 -0
  12. package/agents/somi-worker-medium.md +11 -0
  13. package/agents/somi.md +8 -75
  14. package/commands/somi-config.md +5 -14
  15. package/commands/somi-deliver.md +11 -0
  16. package/commands/somi-quality.md +10 -0
  17. package/commands/somi-review.md +10 -0
  18. package/commands/somi-status.md +11 -0
  19. package/commands/somi.md +10 -0
  20. package/hooks/hooks.json +28 -23
  21. package/hooks/lib/common.mjs +45 -34
  22. package/hooks/pre-tool/apply-tier.mjs +31 -0
  23. package/hooks/pre-tool/block-dangerous-bash.mjs +15 -0
  24. package/hooks/pre-tool/gate-dep-install.mjs +2 -2
  25. package/hooks/pre-tool/guard-protected-paths.mjs +9 -16
  26. package/hooks/pre-tool/guard-tier-config.mjs +17 -0
  27. package/hooks/pre-tool/reviewers-read-only.mjs +11 -0
  28. package/hooks/session-start/inject-digest.mjs +51 -0
  29. package/hooks/stop/review-due.mjs +40 -0
  30. package/hooks/user-prompt/capture-prompt.mjs +17 -0
  31. package/library/lenses/architecture.md +1 -0
  32. package/library/lenses/test-strategy.md +1 -0
  33. package/library/roles/accessibility.md +1 -0
  34. package/library/roles/answer.md +1 -0
  35. package/library/roles/atlas.md +1 -0
  36. package/library/roles/build.md +1 -0
  37. package/library/roles/debug.md +6 -0
  38. package/library/roles/design.md +1 -0
  39. package/library/roles/discover.md +1 -0
  40. package/library/roles/incident.md +1 -0
  41. package/library/roles/migrate.md +1 -0
  42. package/library/roles/perf.md +1 -0
  43. package/library/roles/plan.md +1 -0
  44. package/library/roles/refactor.md +1 -0
  45. package/library/roles/review.md +1 -0
  46. package/library/roles/security-review.md +1 -0
  47. package/library/roles/upgrade.md +1 -0
  48. package/library/skills/accessibility.md +16 -0
  49. package/library/skills/ci-infra-gotchas.md +12 -0
  50. package/library/skills/perf-method.md +10 -0
  51. package/library/skills/secure-coding.md +18 -0
  52. package/library/skills/testing-checklist.md +16 -0
  53. package/library/skills/threat-modeling.md +10 -0
  54. package/package.json +12 -17
  55. package/profiles/claude.json +21 -0
  56. package/profiles/copilot.json +5 -0
  57. package/rules/digest.md +40 -0
  58. package/scripts/check-links.mjs +65 -76
  59. package/scripts/lib/advisor.mjs +207 -0
  60. package/scripts/lib/check.mjs +165 -0
  61. package/scripts/lib/copilot-workflow.mjs +41 -0
  62. package/scripts/lib/doctor.mjs +91 -0
  63. package/scripts/lib/gates.mjs +69 -0
  64. package/scripts/lib/git-tree.mjs +201 -0
  65. package/scripts/lib/init.mjs +23 -0
  66. package/scripts/lib/ledger.mjs +38 -0
  67. package/scripts/lib/mcp-project-root.mjs +63 -67
  68. package/scripts/lib/migrate.mjs +73 -0
  69. package/scripts/lib/path-facts.mjs +2 -2
  70. package/scripts/lib/path-safety.mjs +6 -134
  71. package/scripts/lib/plan.mjs +69 -0
  72. package/scripts/lib/policy.mjs +103 -0
  73. package/scripts/lib/pr.mjs +28 -0
  74. package/scripts/lib/prompt.mjs +72 -0
  75. package/scripts/lib/quality/clones.mjs +76 -0
  76. package/scripts/lib/quality/css.mjs +43 -0
  77. package/scripts/lib/quality/gate.mjs +230 -0
  78. package/scripts/lib/quality/limits.mjs +73 -0
  79. package/scripts/lib/quality/metrics.mjs +159 -0
  80. package/scripts/lib/quality/parse.mjs +73 -0
  81. package/scripts/lib/quality/repo.mjs +69 -0
  82. package/scripts/lib/quality/run.mjs +38 -0
  83. package/scripts/lib/reviews.mjs +132 -0
  84. package/scripts/lib/routes.mjs +108 -0
  85. package/scripts/lib/setup.mjs +34 -0
  86. package/scripts/lib/shards.mjs +166 -0
  87. package/scripts/lib/signals.mjs +110 -0
  88. package/scripts/lib/state.mjs +42 -0
  89. package/scripts/lib/tiers.mjs +42 -0
  90. package/scripts/lib/update-notice.mjs +48 -0
  91. package/scripts/lib/views.mjs +62 -0
  92. package/scripts/lib/workflows.mjs +56 -0
  93. package/scripts/somi-mcp.mjs +181 -323
  94. package/scripts/somi.mjs +208 -0
  95. package/scripts/vendor/tree-sitter/LICENSE.vscode-tree-sitter-wasm +21 -0
  96. package/scripts/vendor/tree-sitter/LICENSE.web-tree-sitter +21 -0
  97. package/scripts/vendor/tree-sitter/cgmanifest.vscode-tree-sitter-wasm.json +16 -0
  98. package/scripts/vendor/tree-sitter/manifest.json +59 -0
  99. package/scripts/vendor/tree-sitter/package.json +3 -0
  100. package/scripts/vendor/tree-sitter/tree-sitter-css.wasm +0 -0
  101. package/scripts/vendor/tree-sitter/tree-sitter-javascript.wasm +0 -0
  102. package/scripts/vendor/tree-sitter/tree-sitter-tsx.wasm +0 -0
  103. package/scripts/vendor/tree-sitter/tree-sitter-typescript.wasm +0 -0
  104. package/scripts/vendor/tree-sitter/web-tree-sitter.js +4081 -0
  105. package/scripts/vendor/tree-sitter/web-tree-sitter.wasm +0 -0
  106. package/skills/somi-expertise/SKILL.md +6 -0
  107. package/workflows/deliver-stages.js +81 -0
  108. package/.claude/settings.json +0 -131
  109. package/agents/somi-architecture-reviewer.md +0 -101
  110. package/agents/somi-atlas.md +0 -100
  111. package/agents/somi-coder.md +0 -60
  112. package/agents/somi-designer.md +0 -36
  113. package/agents/somi-discovery-analyst.md +0 -57
  114. package/agents/somi-flow.md +0 -47
  115. package/agents/somi-general.md +0 -36
  116. package/agents/somi-impact.md +0 -95
  117. package/agents/somi-incident.md +0 -94
  118. package/agents/somi-plan-reviewer.md +0 -68
  119. package/agents/somi-planner.md +0 -57
  120. package/agents/somi-pr.md +0 -99
  121. package/agents/somi-refactor-designer.md +0 -81
  122. package/agents/somi-refactorer.md +0 -99
  123. package/agents/somi-sdlc-reviewer.md +0 -67
  124. package/agents/somi-test-strategist.md +0 -87
  125. package/commands/adopt.md +0 -14
  126. package/commands/architecture-review.md +0 -19
  127. package/commands/atlas.md +0 -19
  128. package/commands/code-loop.md +0 -19
  129. package/commands/code-parallel.md +0 -19
  130. package/commands/code.md +0 -19
  131. package/commands/debug.md +0 -19
  132. package/commands/design.md +0 -19
  133. package/commands/discover.md +0 -19
  134. package/commands/impact.md +0 -19
  135. package/commands/incident.md +0 -19
  136. package/commands/plan-loop.md +0 -19
  137. package/commands/plan.md +0 -19
  138. package/commands/pr.md +0 -19
  139. package/commands/refactor-design.md +0 -19
  140. package/commands/refactor.md +0 -19
  141. package/commands/release-readiness.md +0 -19
  142. package/commands/review-panel.md +0 -19
  143. package/commands/review.md +0 -19
  144. package/commands/security-review.md +0 -19
  145. package/commands/ship-loop.md +0 -19
  146. package/commands/ship.md +0 -19
  147. package/commands/test-strategy.md +0 -19
  148. package/commands/upgrade.md +0 -19
  149. package/examples/README.md +0 -19
  150. package/examples/code-review-example.md +0 -88
  151. package/examples/discovery-example.md +0 -200
  152. package/examples/feature-plan-example.md +0 -377
  153. package/examples/full-pipeline-example.md +0 -188
  154. package/examples/sample-consumer/.claude/settings.json +0 -29
  155. package/examples/sample-consumer/CLAUDE.md +0 -78
  156. package/examples/sample-consumer/README.md +0 -102
  157. package/hooks/post-tool/lint-changed-files.mjs +0 -209
  158. package/hooks/pre-tool/guard-cost-lowering.mjs +0 -192
  159. package/hooks/session-start/detect-repo-instructions.mjs +0 -287
  160. package/hooks/session-start/ensure-default-config.mjs +0 -113
  161. package/hooks/user-prompt-submit/inject-workflow-context.mjs +0 -580
  162. package/rules/00-priorities.md +0 -48
  163. package/rules/10-solid.md +0 -87
  164. package/rules/20-clean-code.md +0 -62
  165. package/rules/30-security-owasp.md +0 -83
  166. package/rules/40-engineering-practices.md +0 -65
  167. package/rules/50-collaboration.md +0 -114
  168. package/rules/99-overrides.md +0 -52
  169. package/rules/CLAUDE.md +0 -200
  170. package/scripts/check-session-artefacts.mjs +0 -149
  171. package/scripts/check-size-budget.mjs +0 -137
  172. package/scripts/generate-digest.mjs +0 -176
  173. package/scripts/lib/agent-info.mjs +0 -85
  174. package/scripts/lib/agent-registry.mjs +0 -92
  175. package/scripts/lib/cost-ceiling.mjs +0 -328
  176. package/scripts/lib/cost-config-edit.mjs +0 -102
  177. package/scripts/lib/cost-config.mjs +0 -64
  178. package/scripts/lib/cost-defaults.mjs +0 -53
  179. package/scripts/lib/cost-lowering.mjs +0 -89
  180. package/scripts/lib/cost-model.mjs +0 -110
  181. package/scripts/lib/dispatch-resolver.mjs +0 -243
  182. package/scripts/lib/escalation-facts.mjs +0 -146
  183. package/scripts/lib/escalation.mjs +0 -129
  184. package/scripts/lib/findings-ledger.mjs +0 -241
  185. package/scripts/lib/install-text.mjs +0 -97
  186. package/scripts/lib/loop-caps.mjs +0 -140
  187. package/scripts/lib/loop-diff.mjs +0 -38
  188. package/scripts/lib/loop-dispatch.mjs +0 -19
  189. package/scripts/lib/loop-engine.mjs +0 -227
  190. package/scripts/lib/loop-escalate.mjs +0 -49
  191. package/scripts/lib/loop-exit.mjs +0 -47
  192. package/scripts/lib/loop-notes-compact.mjs +0 -72
  193. package/scripts/lib/loop-notes.mjs +0 -282
  194. package/scripts/lib/loop-review.mjs +0 -395
  195. package/scripts/lib/loop-state.mjs +0 -44
  196. package/scripts/lib/loop-step-close.mjs +0 -75
  197. package/scripts/lib/loop-step-kit.mjs +0 -179
  198. package/scripts/lib/loop-step-review.mjs +0 -140
  199. package/scripts/lib/loop-step-tool.mjs +0 -89
  200. package/scripts/lib/loop-step.mjs +0 -303
  201. package/scripts/lib/run-budget.mjs +0 -28
  202. package/scripts/lib/run-card.mjs +0 -73
  203. package/scripts/lib/size-tier.mjs +0 -184
  204. package/scripts/lib/tier-record.mjs +0 -82
  205. package/scripts/size-budget-overrides.json +0 -58
  206. package/scripts/somi-card.mjs +0 -39
  207. package/scripts/somi-check.mjs +0 -237
  208. package/scripts/somi-config.mjs +0 -421
  209. package/scripts/somi-dispatch.mjs +0 -141
  210. package/scripts/somi-findings.mjs +0 -100
  211. package/scripts/somi-loop.mjs +0 -139
  212. package/scripts/somi-tier.mjs +0 -393
  213. package/scripts/validate.sh +0 -653
  214. package/skills/api-design/SKILL.md +0 -147
  215. package/skills/clean-code/SKILL.md +0 -142
  216. package/skills/flow-adopt/SKILL.md +0 -92
  217. package/skills/flow-architecture-review/SKILL.md +0 -94
  218. package/skills/flow-atlas/SKILL.md +0 -34
  219. package/skills/flow-code/SKILL.md +0 -167
  220. package/skills/flow-code-loop/SKILL.md +0 -263
  221. package/skills/flow-code-parallel/SKILL.md +0 -160
  222. package/skills/flow-debug/SKILL.md +0 -141
  223. package/skills/flow-design/SKILL.md +0 -170
  224. package/skills/flow-discover/SKILL.md +0 -204
  225. package/skills/flow-impact/SKILL.md +0 -35
  226. package/skills/flow-incident/SKILL.md +0 -49
  227. package/skills/flow-plan/SKILL.md +0 -254
  228. package/skills/flow-plan-loop/SKILL.md +0 -254
  229. package/skills/flow-pr/SKILL.md +0 -34
  230. package/skills/flow-refactor/SKILL.md +0 -58
  231. package/skills/flow-refactor-design/SKILL.md +0 -97
  232. package/skills/flow-release-readiness/SKILL.md +0 -82
  233. package/skills/flow-review/SKILL.md +0 -193
  234. package/skills/flow-review-panel/SKILL.md +0 -154
  235. package/skills/flow-security-review/SKILL.md +0 -83
  236. package/skills/flow-ship/SKILL.md +0 -125
  237. package/skills/flow-ship-loop/SKILL.md +0 -274
  238. package/skills/flow-somi-config/SKILL.md +0 -142
  239. package/skills/flow-status/SKILL.md +0 -43
  240. package/skills/flow-test-strategy/SKILL.md +0 -83
  241. package/skills/flow-upgrade/SKILL.md +0 -82
  242. package/skills/market-research/SKILL.md +0 -125
  243. package/skills/observability/SKILL.md +0 -133
  244. package/skills/owasp-defense/SKILL.md +0 -141
  245. package/skills/plan-review/SKILL.md +0 -83
  246. package/skills/reasoning-craft/SKILL.md +0 -213
  247. package/skills/requirements-engineering/SKILL.md +0 -137
  248. package/skills/role-coder/SKILL.md +0 -247
  249. package/skills/role-designer/SKILL.md +0 -172
  250. package/skills/role-discovery-analyst/SKILL.md +0 -288
  251. package/skills/role-planner/SKILL.md +0 -353
  252. package/skills/role-reviewer/SKILL.md +0 -218
  253. package/skills/rules/SKILL.md +0 -47
  254. package/skills/sdlc-process/SKILL.md +0 -74
  255. package/skills/solid-principles/SKILL.md +0 -143
  256. package/skills/somi-checkpoint/SKILL.md +0 -95
  257. package/skills/somi-dispatch/SKILL.md +0 -259
  258. package/skills/somi-routing/SKILL.md +0 -158
  259. package/skills/testing-playbook/SKILL.md +0 -133
  260. package/skills/threat-modeling/SKILL.md +0 -117
  261. package/templates/ADR.md.tmpl +0 -73
  262. package/templates/ATLAS.md.tmpl +0 -75
  263. package/templates/BRD.md.tmpl +0 -68
  264. package/templates/BRIEF.md.tmpl +0 -119
  265. package/templates/CONTEXT.md.tmpl +0 -74
  266. package/templates/DECISIONS.md.tmpl +0 -105
  267. package/templates/DESIGN.md.tmpl +0 -83
  268. package/templates/DIARY.md.tmpl +0 -70
  269. package/templates/DOD.md.tmpl +0 -90
  270. package/templates/FRD.md.tmpl +0 -64
  271. package/templates/PHASE.md.tmpl +0 -80
  272. package/templates/PROGRESS.md.tmpl +0 -63
  273. package/templates/RCA.md.tmpl +0 -53
  274. package/templates/RD-README.md.tmpl +0 -70
  275. package/templates/RESEARCH.md.tmpl +0 -96
  276. package/templates/REVIEW.md.tmpl +0 -82
  277. package/templates/SDD.md.tmpl +0 -82
  278. package/templates/SOMI-README.md.tmpl +0 -83
  279. package/templates/SPEC.md.tmpl +0 -123
  280. package/templates/SRS.md.tmpl +0 -85
  281. package/templates/TDD.md.tmpl +0 -77
  282. package/tests/hooks/cases/audit-log.json +0 -21
  283. package/tests/hooks/cases/block-dangerous-bash.json +0 -166
  284. package/tests/hooks/cases/block-secret-writes.json +0 -140
  285. package/tests/hooks/cases/detect-repo-instructions.json +0 -105
  286. package/tests/hooks/cases/gate-dep-install.json +0 -42
  287. package/tests/hooks/cases/guard-protected-paths.json +0 -222
  288. package/tests/hooks/cases/inject-workflow-context.json +0 -239
  289. package/tests/hooks/cases/lint-changed-files.json +0 -120
  290. package/tests/hooks/run.sh +0 -392
  291. package/tests/scripts/agent-model-frontmatter.sh +0 -38
  292. package/tests/scripts/agent-names.sh +0 -77
  293. package/tests/scripts/check-frontmatter.sh +0 -37
  294. package/tests/scripts/check-links.sh +0 -105
  295. package/tests/scripts/check-session-artefacts.sh +0 -60
  296. package/tests/scripts/check-size-budget.sh +0 -71
  297. package/tests/scripts/checkpoint-gate.sh +0 -131
  298. package/tests/scripts/convergence-runner.sh +0 -1514
  299. package/tests/scripts/cost-ceiling.sh +0 -255
  300. package/tests/scripts/cost-defaults.sh +0 -130
  301. package/tests/scripts/cost-hardcap.sh +0 -338
  302. package/tests/scripts/cost-lowering.sh +0 -261
  303. package/tests/scripts/cost-model.sh +0 -196
  304. package/tests/scripts/dispatch-guard.sh +0 -108
  305. package/tests/scripts/dispatch-line-gate.sh +0 -61
  306. package/tests/scripts/dispatch-reference-gate.sh +0 -173
  307. package/tests/scripts/ensure-default-config.sh +0 -162
  308. package/tests/scripts/escalation.sh +0 -409
  309. package/tests/scripts/eval-runner.sh +0 -3692
  310. package/tests/scripts/evals-packaging.sh +0 -224
  311. package/tests/scripts/fact-sheet.sh +0 -296
  312. package/tests/scripts/fixtures/legacy-shard-no-schema.json +0 -50
  313. package/tests/scripts/fixtures/mock-stdin-read-throw.cjs +0 -18
  314. package/tests/scripts/fixtures/size-tier-cases.json +0 -87
  315. package/tests/scripts/generate-digest.sh +0 -180
  316. package/tests/scripts/global-config.sh +0 -167
  317. package/tests/scripts/goldens/loop-state-breach.json +0 -1
  318. package/tests/scripts/goldens/loop-state-done.json +0 -1
  319. package/tests/scripts/goldens/somi-findings.json +0 -336
  320. package/tests/scripts/goldens/somi-loop.json +0 -168
  321. package/tests/scripts/lib/adr-shape.mjs +0 -41
  322. package/tests/scripts/lib/agent-registry-tests.mjs +0 -95
  323. package/tests/scripts/lib/brief-only-guard.mjs +0 -27
  324. package/tests/scripts/lib/checkpoint-gate.mjs +0 -91
  325. package/tests/scripts/lib/digest-marker-coupling.mjs +0 -52
  326. package/tests/scripts/lib/dispatch-reference-gate.mjs +0 -121
  327. package/tests/scripts/lib/escalation-facts-tests.mjs +0 -140
  328. package/tests/scripts/lib/escalation-tests.mjs +0 -154
  329. package/tests/scripts/lib/findings-ledger-tests.mjs +0 -118
  330. package/tests/scripts/lib/loop-engine-tests.mjs +0 -287
  331. package/tests/scripts/lib/loop-escalate-tests.mjs +0 -356
  332. package/tests/scripts/lib/loop-flow-gate.mjs +0 -173
  333. package/tests/scripts/lib/loop-notes-tests.mjs +0 -384
  334. package/tests/scripts/lib/loop-step-cli-tests.mjs +0 -156
  335. package/tests/scripts/lib/loop-step-close-tests.mjs +0 -351
  336. package/tests/scripts/lib/loop-step-lenient-tests.mjs +0 -114
  337. package/tests/scripts/lib/loop-step-state-tests.mjs +0 -127
  338. package/tests/scripts/lib/loop-step-tests.mjs +0 -499
  339. package/tests/scripts/lib/loop-step-unwritten-tests.mjs +0 -55
  340. package/tests/scripts/lib/multipass-dependence.mjs +0 -192
  341. package/tests/scripts/lib/multipass-source-identity.mjs +0 -243
  342. package/tests/scripts/lib/path-facts-tests.mjs +0 -198
  343. package/tests/scripts/lib/path-safety-tests.mjs +0 -201
  344. package/tests/scripts/lib/reference-pair.mjs +0 -61
  345. package/tests/scripts/lib/retirement-gate.mjs +0 -172
  346. package/tests/scripts/lib/run-suites.mjs +0 -139
  347. package/tests/scripts/lib/shell-embedded-js.mjs +0 -47
  348. package/tests/scripts/lib/ship-loop-sizing-guard.mjs +0 -52
  349. package/tests/scripts/lib/site-roadmap-gate.mjs +0 -64
  350. package/tests/scripts/lib/size-tier-drift.mjs +0 -74
  351. package/tests/scripts/lib/sizing-score-tests.mjs +0 -210
  352. package/tests/scripts/lib/sizing-set-tests.mjs +0 -131
  353. package/tests/scripts/lib/somi-mcp-client.mjs +0 -102
  354. package/tests/scripts/lib/somi-mcp-config-tests.mjs +0 -92
  355. package/tests/scripts/lib/somi-mcp-loop-tests.mjs +0 -226
  356. package/tests/scripts/lib/somi-mcp-tests.mjs +0 -491
  357. package/tests/scripts/lib/somi-mcp-tier-tests.mjs +0 -64
  358. package/tests/scripts/lib/somi-mcp-tool-schema.mjs +0 -38
  359. package/tests/scripts/loop-engine.sh +0 -22
  360. package/tests/scripts/loop-flow-gate.sh +0 -11
  361. package/tests/scripts/retirement-gate.sh +0 -306
  362. package/tests/scripts/review-panel-seats.sh +0 -32
  363. package/tests/scripts/run-card.sh +0 -57
  364. package/tests/scripts/run-suites.sh +0 -74
  365. package/tests/scripts/run.sh +0 -689
  366. package/tests/scripts/site-roadmap-gate.sh +0 -76
  367. package/tests/scripts/size-tier.sh +0 -562
  368. package/tests/scripts/somi-agent-dispatch-contract.sh +0 -224
  369. package/tests/scripts/somi-config.sh +0 -286
  370. package/tests/scripts/somi-dispatch.sh +0 -465
  371. package/tests/scripts/somi-mcp.sh +0 -15
  372. package/tests/scripts/suite-plan.json +0 -20
@@ -1,465 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Unit guard for scripts/somi-dispatch.mjs: the deterministic dispatch resolver a prompt shells out
3
- # to for "which tier and model should this agent run at, right now" -- the first real call site for
4
- # decideDispatch/modelForDispatch (nothing before this composed them together outside a test).
5
- #
6
- # Exercises: resolution against real shipped agents at every representative default tier
7
- # (high, medium) across all three ceilings; ceiling_source surfacing each of
8
- # cli/env/config/state/default; an unmapped host resolving to model: null rather than a guess; the
9
- # project's `.somi/config.json` `cost.mapping` override (an unmapped host gaining a mapped model, a
10
- # single claude-code tier overridden, a __proto__ key rejected, a malformed mapping -- missing tier
11
- # or non-string model -- failing loudly with no JSON on stdout); a path-traversal attempt in
12
- # --agent rejected before any file is read, in either direction (`../` and a bare `/`); the somi
13
- # exemption and an unknown agent each failing with their own distinct, clear, non-zero exit code;
14
- # an empty or missing value for --host/--ceiling/--agent rejected outright rather than falling
15
- # through to a silent default; and the three exit codes (usage / unknown agent / no tier source) staying distinct from each other and from success.
16
- #
17
- # Every invocation is scoped to its OWN throwaway CLAUDE_PROJECT_DIR, so the real repo's
18
- # .somi/somi-state/ceiling.json is never read or written by this suite -- agent FILES are still looked up in
19
- # the REAL agents/ directory (the resolver's install root, not the project root), while each agent's
20
- # tier comes from scripts/lib/cost-defaults.mjs -- the behavior under test, not something to fake.
21
- set -uo pipefail
22
-
23
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
24
- CLI="$ROOT_REPO/scripts/somi-dispatch.mjs"
25
-
26
- pass=0; fail=0
27
- ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
28
- bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
29
- check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
30
-
31
- echo "== somi-dispatch resolve =="
32
-
33
- TMP="$(mktemp -d)"
34
- trap 'rm -rf "$TMP"' EXIT
35
- fresh() { mktemp -d -p "$TMP"; }
36
-
37
- # $1 = project root, remaining = full CLI args (including the subcommand).
38
- run() {
39
- local proj="$1"; shift
40
- CLAUDE_PROJECT_DIR="$proj" node "$CLI" "$@"
41
- }
42
- # $1 = a captured JSON string, $2 = key to extract.
43
- field() {
44
- node -e 'const o = JSON.parse(process.argv[1]); process.stdout.write(String(o[process.argv[2]]))' "$1" "$2"
45
- }
46
- expect_exit() { # $1 = name, $2 = expected exit code, $3 = project root, remaining = CLI args
47
- local name="$1" want="$2" proj="$3" got=0
48
- shift 3
49
- run "$proj" "$@" >/dev/null 2>&1 || got=$?
50
- if [ "$got" = "$want" ]; then ok "$name"; else bad "$name (expected exit $want, got $got)"; fi
51
- }
52
-
53
- # --- high-only (`somi-designer`, cost: high): the ceiling is a hard cap, so it runs AT the ceiling and
54
- # is reported degraded when that is below its default tier high ----------------------------------------
55
- for spec in low:haiku:true medium:sonnet:true high:opus:false; do
56
- IFS=: read -r c m d <<<"$spec"
57
- out="$(run "$(fresh)" resolve --agent somi-designer --ceiling "$c")"
58
- check "designer (high-only) under ceiling=$c: tier is the ceiling (hard cap)" "$(field "$out" tier)" "$c"
59
- check "designer under ceiling=$c: model is $m" "$(field "$out" model)" "$m"
60
- check "designer under ceiling=$c: degraded is $d, tier_source ceiling" \
61
- "$(field "$out" degraded)/$(field "$out" tier_source)" "$d/ceiling"
62
- done
63
- # An agent override wins over the ceiling, through the CLI.
64
- R_OVR="$(fresh)"; mkdir -p "$R_OVR/.somi"
65
- printf '{"cost": {"ceiling": "low", "agents": {"somi-designer": "high"}}}\n' > "$R_OVR/.somi/config.json"
66
- out="$(run "$R_OVR" resolve --agent somi-designer)"
67
- check "cost.agents.somi-designer=high beats ceiling=low: tier high, model opus, tier_source override" \
68
- "$(field "$out" tier)/$(field "$out" model)/$(field "$out" tier_source)" "high/opus/override"
69
-
70
- # --- default high, also acceptable at medium (`somi-reviewer`): the tier is the ceiling itself; degraded when below the default -
71
- out="$(run "$(fresh)" resolve --agent somi-reviewer --ceiling low)"
72
- check "reviewer (default high) under ceiling=low: clamped to the ceiling (low), degraded" \
73
- "$(field "$out" tier)/$(field "$out" degraded)" "low/true"
74
- out="$(run "$(fresh)" resolve --agent somi-reviewer --ceiling medium)"
75
- check "reviewer under ceiling=medium: selects medium" "$(field "$out" tier)" "medium"
76
- out="$(run "$(fresh)" resolve --agent somi-reviewer --ceiling high)"
77
- check "reviewer under ceiling=high: selects high" "$(field "$out" tier)" "high"
78
-
79
- # --- default medium, opt-in low (`somi-coder`): the opt-in `low` bar's shipped example ------------------------
80
- out="$(run "$(fresh)" resolve --agent somi-coder --ceiling low)"
81
- check "coder (default medium) under ceiling=low: selects low" "$(field "$out" tier)" "low"
82
- check "coder under ceiling=low: model is haiku" "$(field "$out" model)" "haiku"
83
- out="$(run "$(fresh)" resolve --agent somi-coder --ceiling medium)"
84
- check "coder under ceiling=medium: selects medium" "$(field "$out" tier)" "medium"
85
- out="$(run "$(fresh)" resolve --agent somi-coder --ceiling high)"
86
- check "coder under ceiling=high: runs at the ceiling (high), not degraded" \
87
- "$(field "$out" tier)/$(field "$out" degraded)/$(field "$out" tier_source)" "high/false/ceiling"
88
- check "coder under ceiling=high: model is opus" "$(field "$out" model)" "opus"
89
-
90
- # --- ceiling_source covers all of cli/env/config/state/default -- this is what lets a dispatcher announce a `low`
91
- # ceiling honestly, by its real source, not just its bare value. -----------------------------------
92
- out="$(run "$(fresh)" resolve --agent somi-coder)"
93
- check "no config, no env, no --ceiling: ceiling_source is default" "$(field "$out" ceiling_source)" "default"
94
-
95
- out="$(run "$(fresh)" resolve --agent somi-coder --ceiling medium)"
96
- check "explicit --ceiling: ceiling_source is cli" "$(field "$out" ceiling_source)" "cli"
97
-
98
- R_ENV="$(fresh)"
99
- out="$(CLAUDE_PROJECT_DIR="$R_ENV" SOMI_COST_CEILING=medium node "$CLI" resolve --agent somi-coder)"
100
- check "SOMI_COST_CEILING set, no --ceiling: ceiling_source is env" "$(field "$out" ceiling_source)" "env"
101
-
102
- R_CFG="$(fresh)"; mkdir -p "$R_CFG/.somi"
103
- printf '{"cost": {"ceiling": "low"}}\n' > "$R_CFG/.somi/config.json"
104
- out="$(run "$R_CFG" resolve --agent somi-coder)"
105
- check "cost.ceiling in .somi/config.json: ceiling_source is config" "$(field "$out" ceiling_source)" "config"
106
- out2="$(run "$R_CFG" resolve --agent somi-coder)"
107
- check "a second call is config again (config is read live, not remembered as state)" \
108
- "$(field "$out2" ceiling_source)/$(field "$out2" ceiling_origin)" "config/config"
109
- printf '{"cost": {"ceiling": "high"}}\n' > "$R_CFG/.somi/config.json"
110
- out="$(run "$R_CFG" resolve --agent somi-coder)"
111
- check "editing the config between two calls moves the ceiling" "$(field "$out" ceiling)/$(field "$out" tier)" "high/high"
112
- out="$(run "$R_CFG" resolve --agent somi-coder --ceiling low)"
113
- check "--ceiling beats the config and persists" "$(field "$out" ceiling_source)/$(field "$out" ceiling)" "cli/low"
114
- rm "$R_CFG/.somi/config.json"
115
- out="$(run "$R_CFG" resolve --agent somi-coder)"
116
- check "with the config gone, the persisted CLI ceiling is state with origin cli" \
117
- "$(field "$out" ceiling_source)/$(field "$out" ceiling_origin)/$(field "$out" ceiling)" "state/cli/low"
118
- out="$(run "$(fresh)" resolve --agent somi-coder)"
119
- check "no config, no state: the default ceiling is medium" "$(field "$out" ceiling)/$(field "$out" tier)" "medium/medium"
120
-
121
- # --- unmapped host: model is null (let the host choose), never a guessed name -------------------
122
- out="$(run "$(fresh)" resolve --agent somi-coder --host some-future-host --ceiling high)"
123
- check "unmapped host: model is null" "$(field "$out" model)" "null"
124
- check "unmapped host: tier still resolves normally (the ceiling, high)" "$(field "$out" tier)" "high"
125
-
126
- # --- .somi/config.json's cost.mapping override: how a host SoMi doesn't map (e.g. Copilot) is told
127
- # which of ITS OWN models is low/medium/high -- reused via readCostConfig, merged via
128
- # mergeHostMapping, never a second config reader. A malformed one fails loudly, no stdout -- exit 67
129
- # whenever the project's own cost.mapping is the cause: either the mapping's own SHAPE is invalid
130
- # (mergeHostMapping's own checks: a disallowed host key, a non-object per-host value), or the shape
131
- # is fine but the resolved data is incomplete or wrong for the tier actually selected (resolveModel's
132
- # checks, via modelForDispatch) for a host the project's OWN mapping named -- a partial override of a
133
- # shipped host replaces that host's whole tier map rather than merging it tier-by-tier, so overriding
134
- # just one tier drops the others, and the resulting error names ".somi/config.json cost.mapping"
135
- # explicitly rather than reading like agent coder's own broken cost: declaration. Exit 66 stays
136
- # reserved for a resolution failure on a host the project's mapping never mentioned at all -- which
137
- # would mean a bug in the shipped HOST_MODELS table itself (see scripts/somi-dispatch.mjs's own
138
- # split). ------------------------------------------------------------------------------------------
139
- expect_malformed() { # $1=name $2=want-exit-code $3=proj, remaining = CLI args
140
- local name="$1" want="$2" proj="$3" out rc=0; shift 3
141
- out="$(run "$proj" "$@" 2>/dev/null)" || rc=$?
142
- check "$name: exit $want" "$rc" "$want"
143
- check "$name: no JSON on stdout" "$out" ""
144
- }
145
-
146
- # Otherwise-unmapped host, mapped by the project: resolves to it for the tier actually selected
147
- # (--ceiling high -> coder resolves to high, so the high entry is used). Without the mapping,
148
- # same as any unmapped host: null.
149
- R_MAP="$(fresh)"; mkdir -p "$R_MAP/.somi"
150
- printf '{"cost": {"mapping": {"copilot": {"low": "gpt-5-mini", "medium": "gpt-5", "high": "gpt-5-pro"}}}}\n' \
151
- > "$R_MAP/.somi/config.json"
152
- out="$(run "$R_MAP" resolve --agent somi-coder --host copilot --ceiling high)"
153
- check "copilot mapped via project config: model is the mapped high entry" "$(field "$out" model)" "gpt-5-pro"
154
- out="$(run "$(fresh)" resolve --agent somi-coder --host copilot)"
155
- check "copilot with no project mapping: model is null" "$(field "$out" model)" "null"
156
-
157
- # #32: `enforced` is true only when a concrete model id was resolved; otherwise false with a reason.
158
- out="$(run "$(fresh)" resolve --agent somi-designer --host copilot)"
159
- check "copilot, no mapping, high agent: model is null" "$(field "$out" model)" "null"
160
- check "copilot, no mapping: enforced is false" "$(field "$out" enforced)" "false"
161
- case "$(field "$out" reason)" in
162
- *"low, medium and high"*) ok "copilot, no mapping: reason tells the user to map all three tiers" ;;
163
- *) bad "copilot, no mapping: reason tells the user to map all three tiers (got '$(field "$out" reason)')" ;;
164
- esac
165
- case "$(field "$out" reason)" in
166
- *"no model mapping for host copilot"*) ok "copilot, no mapping: reason names the host" ;;
167
- *) bad "copilot, no mapping: reason names the host (got '$(field "$out" reason)')" ;;
168
- esac
169
- out="$(run "$R_MAP" resolve --agent somi-designer --host copilot --ceiling high)"
170
- check "copilot with a config mapping: model is the mapped high entry" "$(field "$out" model)" "gpt-5-pro"
171
- check "copilot with a config mapping: enforced is true" "$(field "$out" enforced)" "true"
172
- check "copilot with a config mapping: no reason key" "$(field "$out" reason)" "undefined"
173
- out="$(run "$(fresh)" resolve --agent somi-designer --host claude-code)"
174
- check "claude-code default: enforced is true" "$(field "$out" enforced)" "true"
175
-
176
- # #32: the dispatch skill keeps the honesty rule -- a text-level guard so it cannot be edited away.
177
- SKILL="$ROOT_REPO/skills/somi-dispatch/SKILL.md"
178
- skill_flat="$(tr '\n' ' ' < "$SKILL" | tr -s ' ')" # phrases may be line-wrapped in the source
179
- if printf '%s' "$skill_flat" | grep -qF 'requested cost: <tier> (not enforced: no mapped model)' \
180
- && printf '%s' "$skill_flat" | grep -qF 'reserved for enforced dispatches' \
181
- && printf '%s' "$skill_flat" | grep -qF 'which rule wins' \
182
- && printf '%s' "$skill_flat" | grep -qF 'ONE user-visible line per agent type per session'; then
183
- ok "dispatch skill carries the requested-cost line, the rule order, and the unenforced notice"
184
- else
185
- bad "dispatch skill is missing the requested-cost line, the rule order, or the unenforced notice (#32)"
186
- fi
187
- # Newline-insensitive: a phrase wrapped across two source lines must still be seen. Any file naming
188
- # the enforced line must also name the unenforced one; the three trimming agents must honour both.
189
- unguarded=""
190
- for c in "$ROOT_REPO"/commands/*.md "$ROOT_REPO"/agents/*.md; do
191
- flat="$(tr '\n' ' ' < "$c" | tr -s ' ')"
192
- case "$flat" in *'dispatched at cost:'*) case "$flat" in *'requested cost:'*) ;; *) unguarded="$unguarded $(basename "$c")" ;; esac ;; esac
193
- done
194
- check "every command/agent naming 'dispatched at cost:' also names the unenforced 'requested cost' line" "$unguarded" ""
195
- trim_missing=""
196
- for a in somi-coder somi-planner somi-refactorer; do
197
- flat="$(tr '\n' ' ' < "$ROOT_REPO/agents/$a.md" | tr -s ' ')"
198
- case "$flat" in *'dispatched at cost: low` or `requested cost: low'*) ;; *) trim_missing="$trim_missing $a" ;; esac
199
- done
200
- check "coder/planner/refactorer trim on 'requested cost: low' as well as 'dispatched at cost: low'" "$trim_missing" ""
201
- check "the unenforced briefing line reads 'no mapped model' everywhere" \
202
- "$(grep -rlE 'running on the host model' "$ROOT_REPO/commands" "$ROOT_REPO/agents" "$ROOT_REPO/skills" "$ROOT_REPO/docs" | tr '\n' ' ')" ""
203
-
204
- # A project mapping can override a single claude-code tier; designer at --ceiling high selects high,
205
- # isolating the override to exactly the tier it names.
206
- R_OVERRIDE="$(fresh)"; mkdir -p "$R_OVERRIDE/.somi"
207
- printf '{"cost": {"mapping": {"claude-code": {"low": "haiku", "medium": "sonnet", "high": "custom-opus"}}}}\n' \
208
- > "$R_OVERRIDE/.somi/config.json"
209
- out="$(run "$R_OVERRIDE" resolve --agent somi-designer --ceiling high)"
210
- check "project mapping overrides claude-code's high tier" "$(field "$out" model)" "custom-opus"
211
-
212
- # A __proto__ key is rejected outright (mergeHostMapping's denylist) -- this is the PROJECT's own
213
- # config.json being malformed, exit 67, never merged.
214
- R_PROTO="$(fresh)"; mkdir -p "$R_PROTO/.somi"
215
- printf '{"cost": {"mapping": {"__proto__": {"low": "x"}}}}\n' > "$R_PROTO/.somi/config.json"
216
- expect_malformed "a __proto__ key in cost.mapping" 67 "$R_PROTO" resolve --agent somi-coder
217
- proto_err="$(run "$R_PROTO" resolve --agent somi-coder 2>&1 >/dev/null)"
218
- case "$proto_err" in
219
- *"__proto__"*) ok "the __proto__ rejection names the disallowed key" ;;
220
- *) bad "the __proto__ rejection does not name the key (got: $proto_err)" ;;
221
- esac
222
-
223
- # A mapped host missing the tier actually selected (coder's default selection is medium; this
224
- # mapping supplies only low), and a non-string model value, are shape-valid but data-incomplete for
225
- # THIS dispatch -- resolveModel's own checks, via modelForDispatch. Both name "copilot", which the
226
- # project's OWN mapping named, so both are the project's fault: exit 67, message names
227
- # ".somi/config.json cost.mapping" (not every mapping problem is the project's own file being
228
- # broken in the STRUCTURAL sense mergeHostMapping checks, but these two are still its own data).
229
- R_PARTIAL="$(fresh)"; mkdir -p "$R_PARTIAL/.somi"
230
- printf '{"cost": {"mapping": {"copilot": {"low": "gpt-5-mini"}}}}\n' > "$R_PARTIAL/.somi/config.json"
231
- expect_malformed "a mapped host missing the selected tier" 67 "$R_PARTIAL" resolve --agent somi-coder --host copilot
232
- partial_msg="$(run "$R_PARTIAL" resolve --agent somi-coder --host copilot 2>&1 >/dev/null || true)"
233
- case "$partial_msg" in
234
- *".somi/config.json cost.mapping"*) ok "the missing-tier error names .somi/config.json cost.mapping" ;;
235
- *) bad "the missing-tier error does not name .somi/config.json cost.mapping (got: $partial_msg)" ;;
236
- esac
237
-
238
- R_NONSTRING="$(fresh)"; mkdir -p "$R_NONSTRING/.somi"
239
- printf '{"cost": {"mapping": {"copilot": {"low": "gpt-5-mini", "medium": 5, "high": "gpt-5-pro"}}}}\n' \
240
- > "$R_NONSTRING/.somi/config.json"
241
- expect_malformed "a non-string mapped model" 67 "$R_NONSTRING" resolve --agent somi-coder --host copilot --ceiling medium
242
- nonstring_msg="$(run "$R_NONSTRING" resolve --agent somi-coder --host copilot --ceiling medium 2>&1 >/dev/null || true)"
243
- case "$nonstring_msg" in
244
- *".somi/config.json cost.mapping"*) ok "the non-string-model error names .somi/config.json cost.mapping" ;;
245
- *) bad "the non-string-model error does not name .somi/config.json cost.mapping (got: $nonstring_msg)" ;;
246
- esac
247
-
248
- # The reported bug: a partial override of a SHIPPED host (claude-code) that names only one tier
249
- # replaces that host's whole tier map (mergeHostMapping never merges tier-by-tier), so every OTHER
250
- # tier for that host now fails too -- and the failure must name .somi/config.json cost.mapping, not
251
- # read like coder's own cost: declaration is broken.
252
- R_SHIPPED_PARTIAL="$(fresh)"; mkdir -p "$R_SHIPPED_PARTIAL/.somi"
253
- printf '{"cost": {"mapping": {"claude-code": {"high": "custom-opus"}}}}\n' > "$R_SHIPPED_PARTIAL/.somi/config.json"
254
- expect_malformed "a partial override of the shipped claude-code host drops its other tiers" 67 \
255
- "$R_SHIPPED_PARTIAL" resolve --agent somi-coder --ceiling medium
256
- shipped_partial_msg="$(run "$R_SHIPPED_PARTIAL" resolve --agent somi-coder --ceiling medium 2>&1 >/dev/null || true)"
257
- case "$shipped_partial_msg" in
258
- *".somi/config.json cost.mapping"*) ok "the shipped-host partial-override error names .somi/config.json cost.mapping" ;;
259
- *) bad "the shipped-host partial-override error does not name .somi/config.json cost.mapping (got: $shipped_partial_msg)" ;;
260
- esac
261
-
262
- # A tier key outside low|medium|high in cost.mapping is ALSO the project's own file being malformed
263
- # (mergeHostMapping's own check, same as __proto__ above) -- exit 67, not 66.
264
- R_BADTIER="$(fresh)"; mkdir -p "$R_BADTIER/.somi"
265
- printf '{"cost": {"mapping": {"copilot": {"lo": "gpt-5-mini"}}}}\n' > "$R_BADTIER/.somi/config.json"
266
- expect_malformed "a tier key outside low|medium|high in cost.mapping" 67 "$R_BADTIER" resolve --agent somi-coder --host copilot
267
-
268
- # A named regression test: bootstrap normally (valid config, ceiling state written), THEN corrupt
269
- # config.json -- the ceiling itself doesn't re-read config after bootstrap, but the mapping
270
- # (read fresh every call) does, and its failure must be reported as the PROJECT's file breaking
271
- # (67), never as agent coder's own cost: declaration being malformed (66).
272
- R_POSTBOOT="$(fresh)"; mkdir -p "$R_POSTBOOT/.somi"
273
- printf '{"cost": {"ceiling": "high"}}\n' > "$R_POSTBOOT/.somi/config.json"
274
- run "$R_POSTBOOT" resolve --agent somi-coder >/dev/null # bootstrap: writes .somi/somi-state/ceiling.json
275
- printf '{"cost": {"ceiling": "high"}\n' > "$R_POSTBOOT/.somi/config.json" # now corrupt (missing brace)
276
- postboot_rc=0
277
- run "$R_POSTBOOT" resolve --agent somi-coder >/dev/null 2>&1 || postboot_rc=$?
278
- check "config corrupted AFTER a successful bootstrap: exit 67, not 66" "$postboot_rc" "67"
279
-
280
- # --- path traversal in --agent: rejected before any file is read, in either direction ------------
281
- expect_exit "path traversal in --agent (../etc/passwd) rejected as a usage error" 64 \
282
- "$(fresh)" resolve --agent ../etc/passwd
283
- expect_exit "a slash in --agent (a/b) rejected as a usage error" 64 \
284
- "$(fresh)" resolve --agent a/b
285
-
286
- R_TRAV="$(fresh)"
287
- run "$R_TRAV" resolve --agent ../etc/passwd >/dev/null 2>&1
288
- if [ -e "$R_TRAV/.somi" ]; then
289
- bad "a rejected --agent must be caught before the ceiling is ever touched (found .somi/ in the project root)"
290
- else
291
- ok "a rejected --agent (../etc/passwd) leaves the project root untouched -- rejected before any read"
292
- fi
293
-
294
- # --- somi is exempt: a clear, distinct, non-zero error, never a guessed model --------------------
295
- expect_exit "agent somi (exempt from cost:) fails with its own distinct exit code" 66 \
296
- "$(fresh)" resolve --agent somi
297
- msg="$(run "$(fresh)" resolve --agent somi 2>&1 >/dev/null || true)"
298
- case "$msg" in
299
- *exempt*) ok "somi's error message names the exemption, not a generic failure" ;;
300
- *) bad "somi's error message does not mention the exemption (got: $msg)" ;;
301
- esac
302
-
303
- # --- unknown agent: a clear, distinct, non-zero error --------------------------------------------
304
- expect_exit "unknown agent fails with its own distinct exit code" 65 \
305
- "$(fresh)" resolve --agent totally-not-a-real-agent
306
- msg="$(run "$(fresh)" resolve --agent totally-not-a-real-agent 2>&1 >/dev/null || true)"
307
- case "$msg" in
308
- *"unknown agent"*) ok "unknown-agent error message says so" ;;
309
- *) bad "unknown-agent error message is unclear (got: $msg)" ;;
310
- esac
311
-
312
- # --- the four failure exit codes, DERIVED from the CLI's own EXIT_* constants (not re-typed here),
313
- # are pairwise distinct, and distinct from success (0) -------------------------------------------
314
- cli_codes="$(grep -oE '^const EXIT_[A-Z_]+ = [0-9]+;' "$CLI" | grep -oE '[0-9]+')"
315
- check "the CLI declares exactly four EXIT_* constants" "$(printf '%s\n' "$cli_codes" | wc -l | tr -d ' ')" "4"
316
- check "the CLI's own EXIT_* constants are pairwise distinct, and none is 0 (success)" \
317
- "$(printf '%s\n0\n' "$cli_codes" | sort -u | wc -l | tr -d ' ')" "5"
318
-
319
- # --- bad args: missing --agent, unknown subcommand, unknown flag --------------------------------
320
- expect_exit "missing --agent is a usage error" 64 "$(fresh)" resolve
321
- expect_exit "unknown subcommand is a usage error" 64 "$(fresh)" bogus-subcommand --agent somi-coder
322
- expect_exit "unknown flag is a usage error" 64 "$(fresh)" resolve --agent somi-coder --bogus-flag x
323
- expect_exit "no subcommand at all is a usage error" 64 "$(fresh)"
324
-
325
- # --- an empty or missing flag value is rejected outright, never silently defaulted --------------
326
- expect_exit "--host with an explicitly empty value is a usage error, not a silent default" 64 \
327
- "$(fresh)" resolve --agent somi-coder --host ""
328
- expect_exit "a trailing --host with no value at all is a usage error" 64 \
329
- "$(fresh)" resolve --agent somi-coder --host
330
- expect_exit "--ceiling with an explicitly empty value is a usage error" 64 \
331
- "$(fresh)" resolve --agent somi-coder --ceiling ""
332
- expect_exit "a trailing --ceiling with no value at all is a usage error" 64 \
333
- "$(fresh)" resolve --agent somi-coder --ceiling
334
- expect_exit "--agent with an explicitly empty value is a usage error" 64 \
335
- "$(fresh)" resolve --agent ""
336
-
337
- # --- a syntactically-present but invalid --ceiling VALUE (not empty/missing, an unrecognized tier)
338
- # is a usage error, and -- the actual point of this guard -- it must be rejected BEFORE
339
- # resolveCeiling() ever touches disk, so a rejected value leaves no .somi/ state behind. -----------
340
- R_BADCEIL="$(fresh)"
341
- expect_exit "an invalid --ceiling VALUE ('critical') is a usage error, not a project-env failure" 64 \
342
- "$R_BADCEIL" resolve --agent somi-coder --ceiling critical
343
- badceil_msg="$(run "$R_BADCEIL" resolve --agent somi-coder --ceiling critical 2>&1 >/dev/null || true)"
344
- case "$badceil_msg" in
345
- *"--ceiling"*"critical"*) ok "the bad --ceiling error names the flag and the rejected value" ;;
346
- *) bad "the bad --ceiling error is unclear (got: $badceil_msg)" ;;
347
- esac
348
- if [ -e "$R_BADCEIL/.somi" ]; then
349
- bad "a rejected --ceiling value must be caught before the ceiling state is ever touched (found .somi/ in the project root)"
350
- else
351
- ok "a rejected --ceiling value ('critical') leaves the project root untouched -- validated before resolveCeiling touches disk"
352
- fi
353
-
354
- # --- project environment/config failures: exit 67, distinct from 64 (usage) and 66 (declaration),
355
- # and the message names the offending file -- these are the caller's PROJECT state being broken,
356
- # not a bad argument to this command and not a bad agent declaration. ------------------------------
357
- R_CFG_BROKEN="$(fresh)"; mkdir -p "$R_CFG_BROKEN/.somi"
358
- printf '{"cost": {"ceiling": "low"}\n' > "$R_CFG_BROKEN/.somi/config.json" # missing closing brace
359
- expect_exit "an unparsable .somi/config.json is a project-env failure (67), not usage or malformed" 67 \
360
- "$R_CFG_BROKEN" resolve --agent somi-coder
361
- cfg_broken_msg="$(run "$R_CFG_BROKEN" resolve --agent somi-coder 2>&1 >/dev/null || true)"
362
- case "$cfg_broken_msg" in
363
- *"config.json"*) ok "the unparsable-config error names config.json" ;;
364
- *) bad "the unparsable-config error does not name config.json (got: $cfg_broken_msg)" ;;
365
- esac
366
-
367
- R_STATE_BROKEN="$(fresh)"; mkdir -p "$R_STATE_BROKEN/.somi/somi-state"
368
- printf '{"ceiling": "low"\n' > "$R_STATE_BROKEN/.somi/somi-state/ceiling.json" # missing closing brace
369
- expect_exit "an unparsable .somi/somi-state/ceiling.json is a project-env failure (67)" 67 \
370
- "$R_STATE_BROKEN" resolve --agent somi-coder
371
- state_broken_msg="$(run "$R_STATE_BROKEN" resolve --agent somi-coder 2>&1 >/dev/null || true)"
372
- case "$state_broken_msg" in
373
- *"ceiling.json"*) ok "the unparsable-state error names ceiling.json" ;;
374
- *) bad "the unparsable-state error does not name ceiling.json (got: $state_broken_msg)" ;;
375
- esac
376
-
377
- # A malformed SOMI_COST_CEILING is the CALLER's input (same channel as --ceiling, just an env var
378
- # instead of a flag), not the project's own persisted state -- classified 64 (usage), not 67, and
379
- # -- the actual point of this guard -- rejected before resolveCeiling() ever touches disk, same as
380
- # a bad --ceiling value above.
381
- R_ENV_BAD="$(fresh)"
382
- env_bad_rc=0
383
- CLAUDE_PROJECT_DIR="$R_ENV_BAD" SOMI_COST_CEILING=critical node "$CLI" resolve --agent somi-coder >/dev/null 2>&1 || env_bad_rc=$?
384
- check "a malformed SOMI_COST_CEILING is a usage error (64), not a project-env failure" "$env_bad_rc" "64"
385
- if [ -e "$R_ENV_BAD/.somi" ]; then
386
- bad "a rejected SOMI_COST_CEILING must be caught before the ceiling state is ever touched (found .somi/ in the project root)"
387
- else
388
- ok "a rejected SOMI_COST_CEILING ('critical') leaves the project root untouched -- validated before resolveCeiling touches disk"
389
- fi
390
- envbad_msg="$(CLAUDE_PROJECT_DIR="$(fresh)" SOMI_COST_CEILING=critical node "$CLI" resolve --agent somi-coder 2>&1 >/dev/null || true)"
391
- case "$envbad_msg" in
392
- *"SOMI_COST_CEILING"*"critical"*) ok "the bad SOMI_COST_CEILING error names the variable and the rejected value" ;;
393
- *) bad "the bad SOMI_COST_CEILING error is unclear (got: $envbad_msg)" ;;
394
- esac
395
-
396
- # --- output shape: exactly the documented fields (`enforced` added by #32; `reason` only when unenforced), and a real JSON array for `supported` -----
397
- out="$(run "$(fresh)" resolve --agent somi-coder --ceiling medium)"
398
- check "JSON output carries exactly agent/agent_type/ceiling/ceiling_origin/ceiling_source/declared/degraded/enforced/model/supported/tier/tier_source" \
399
- "$(node -e 'process.stdout.write(Object.keys(JSON.parse(process.argv[1])).sort().join("|"))' "$out")" \
400
- "agent|agent_type|ceiling|ceiling_origin|ceiling_source|declared|degraded|enforced|model|supported|tier|tier_source"
401
- check "coder's supported set is exactly [medium], echoing its default tier from the table" \
402
- "$(node -e 'process.stdout.write(JSON.parse(process.argv[1]).supported.join(","))' "$out")" \
403
- "medium"
404
-
405
- # --- ceiling_origin surfaces through the CLI, not just the library: the source/origin distinction
406
- # that makes "ceiling_source: state" actionable round-trips through the JSON. ---------------------
407
- out="$(run "$(fresh)" resolve --agent somi-coder)"
408
- check "fresh project, no override: ceiling_origin matches ceiling_source ('default')" \
409
- "$(field "$out" ceiling_origin)" "default"
410
-
411
- R_ORIGIN="$(fresh)"; mkdir -p "$R_ORIGIN/.somi"
412
- printf '{"cost": {"ceiling": "low"}}\n' > "$R_ORIGIN/.somi/config.json"
413
- run "$R_ORIGIN" resolve --agent somi-coder --ceiling medium >/dev/null # persisted from the CLI; config still outranks it
414
- rm "$R_ORIGIN/.somi/config.json"
415
- out="$(run "$R_ORIGIN" resolve --agent somi-coder)" # a later bare call, config gone: state on disk
416
- check "a later call: ceiling_source is 'state' but ceiling_origin still says 'cli' -- actionable" \
417
- "$(field "$out" ceiling_source),$(field "$out" ceiling_origin)" "state,cli"
418
-
419
- # --- the tier comes from the default table, never from the agent file --------------------------------
420
- # A leftover `cost:` line in an agent file (step one of retiring it) is ignored, and so is the file's
421
- # line-ending style (#28: a Windows clone rewrites agent files to CRLF). Run a copy of the install whose
422
- # planner declares `cost: low` and whose agent files are all CRLF.
423
- LEFTOVER_INSTALL="$(fresh)"
424
- cp -R "$ROOT_REPO/scripts" "$ROOT_REPO/agents" "$LEFTOVER_INSTALL/"
425
- sed -i '0,/^description:/s/^description:/cost: low\ndescription:/' "$LEFTOVER_INSTALL/agents/somi-planner.md"
426
- for f in "$LEFTOVER_INSTALL"/agents/*.md; do sed -i 's/$/\r/' "$f"; done
427
- leftover_rc=0
428
- out="$(CLAUDE_PROJECT_DIR="$(fresh)" node "$LEFTOVER_INSTALL/scripts/somi-dispatch.mjs" resolve --agent somi-planner --host copilot 2>&1)" || leftover_rc=$?
429
- check "a leftover cost: line in a CRLF agent file: resolve exits 0" "$leftover_rc" "0"
430
- [ "$leftover_rc" = 0 ] && check "... and planner's supported set is the table's [medium], not the file's low" \
431
- "$(node -e 'process.stdout.write(JSON.parse(process.argv[1]).supported.join(","))' "$out")" "medium"
432
- grep -q '^cost: low' "$LEFTOVER_INSTALL/agents/somi-planner.md" || bad "fixture did not plant the leftover cost: line"
433
- # Red proof: if the resolver took the tier from anywhere but the table, the same assertion would see it.
434
- sed -i "s/const defaultTier = AGENT_DEFAULT_TIERS\[agent\];/const defaultTier = 'low';/" "$LEFTOVER_INSTALL/scripts/lib/dispatch-resolver.mjs"
435
- out="$(CLAUDE_PROJECT_DIR="$(fresh)" node "$LEFTOVER_INSTALL/scripts/somi-dispatch.mjs" resolve --agent somi-planner --host copilot 2>&1)" || true
436
- check "red proof: a resolver that ignores the table reports a different supported set" \
437
- "$(node -e 'process.stdout.write(JSON.parse(process.argv[1]).supported.join(","))' "$out")" "low"
438
-
439
- # An agent file with no table entry (and not the exempt somi) is a gap in the plugin itself: 66, naming the table.
440
- GHOST_INSTALL="$(fresh)"
441
- cp -R "$ROOT_REPO/scripts" "$ROOT_REPO/agents" "$GHOST_INSTALL/"
442
- printf -- '---\nname: ghost\ndescription: d\n---\nbody\n' > "$GHOST_INSTALL/agents/ghost.md"
443
- ghost_rc=0
444
- msg="$(CLAUDE_PROJECT_DIR="$(fresh)" node "$GHOST_INSTALL/scripts/somi-dispatch.mjs" resolve --agent ghost 2>&1 >/dev/null)" || ghost_rc=$?
445
- check "an agent file with no default-tier table entry exits 66" "$ghost_rc" "66"
446
- case "$msg" in
447
- *"default tier table"*) ok "... and the message names the table" ;;
448
- *) bad "... the message does not name the table (got: $msg)" ;;
449
- esac
450
-
451
- # --- #35: a preference list in cost.mapping -> model is the first, model_candidates the list ---------
452
- P35="$(mktemp -d)"; mkdir "$P35/.somi"
453
- printf '{"cost":{"ceiling":"high","mapping":{"copilot":{"low":"m-l","medium":"m-m","high":["m-h1","m-h2"]}}}}\n' > "$P35/.somi/config.json"
454
- out35="$(CLAUDE_PROJECT_DIR="$P35" env -u SOMI_COST_CEILING node "$CLI" resolve --agent somi-designer --host copilot)"
455
- check "#35: a list mapping resolves model to the first candidate, enforced, with model_candidates" \
456
- "$(node -e 'const o=JSON.parse(process.argv[1]); process.stdout.write([o.model, o.enforced, JSON.stringify(o.model_candidates)].join("|"))' "$out35")" 'm-h1|true|["m-h1","m-h2"]'
457
- out35b="$(CLAUDE_PROJECT_DIR="$P35" env -u SOMI_COST_CEILING node "$CLI" resolve --agent somi-coder --host copilot --ceiling medium)"
458
- check "#35: a plain-string tier carries no model_candidates field" "$(node -e 'process.stdout.write(String("model_candidates" in JSON.parse(process.argv[1])))' "$out35b")" "false"
459
- printf '{"cost":{"ceiling":"high","mapping":{"copilot":{"low":"m-l","medium":"m-m","high":[]}}}}\n' > "$P35/.somi/config.json"
460
- rc35=0; CLAUDE_PROJECT_DIR="$P35" env -u SOMI_COST_CEILING node "$CLI" resolve --agent somi-designer --host copilot >/dev/null 2>&1 || rc35=$?
461
- check "#35: an empty list in the project's mapping is a project config failure (67)" "$rc35" "67"
462
- rm -rf "$P35"
463
-
464
- echo "somi-dispatch tests: $pass ok, $fail failed"
465
- [ "$fail" -eq 0 ] || exit 1
@@ -1,15 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Guards scripts/somi-mcp.mjs: the bundled, zero-dependency stdio MCP server wrapping the same
3
- # scripts/lib/dispatch-resolver.mjs the CLI (scripts/somi-dispatch.mjs) uses. A JSON-RPC stdio
4
- # conversation needs request/response correlation and (for the roots/list rung) a SERVER-initiated
5
- # request answered by the test acting as the client -- awkward in bash alone, so the actual
6
- # protocol driving lives in tests/scripts/lib/somi-mcp-tests.mjs; this file is the thin wrapper
7
- # scripts/validate.sh calls, matching how other heavier checks in this suite pair a .sh entry
8
- # point with a .mjs implementation (e.g. tests/scripts/lib/digest-marker-coupling.mjs).
9
- set -euo pipefail
10
-
11
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
12
- node "$ROOT_REPO/tests/scripts/lib/somi-mcp-tests.mjs"
13
- node "$ROOT_REPO/tests/scripts/lib/somi-mcp-tier-tests.mjs"
14
- node "$ROOT_REPO/tests/scripts/lib/agent-registry-tests.mjs"
15
- node "$ROOT_REPO/tests/scripts/lib/somi-mcp-loop-tests.mjs"
@@ -1,20 +0,0 @@
1
- {
2
- "comment": "How validate.sh's test scripts are scheduled (tests/scripts/lib/run-suites.mjs --plan). 'alone' scripts run by themselves, with nothing else on the machine: their checks carry wall-clock limits that CPU contention breaks. 'shards' split the slow scripts across CI runners; the 'light' shard is every queued script no shard names, so the shards together always cover every script once. A name here that validate.sh does not queue fails the run.",
3
- "alone": [
4
- "tests/scripts/eval-gate-micro-tasks.sh"
5
- ],
6
- "shards": {
7
- "heavy-1": [
8
- "tests/scripts/eval-gate-micro-tasks.sh"
9
- ],
10
- "heavy-2": [
11
- "tests/scripts/eval-gate-ab-driver.sh",
12
- "tests/scripts/eval-gate-ab-tasks.sh"
13
- ],
14
- "heavy-3": [
15
- "tests/scripts/eval-gate-review-recall.sh",
16
- "tests/scripts/eval-gate-bench-compare.sh",
17
- "tests/scripts/eval-gate-micro-lint.sh"
18
- ]
19
- }
20
- }