@skathio/somi 4.1.0 → 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 -226
  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 -278
  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 -301
  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 -128
  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 -371
  334. package/tests/scripts/lib/loop-step-cli-tests.mjs +0 -141
  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,491 +0,0 @@
1
- #!/usr/bin/env node
2
- // Drives scripts/somi-mcp.mjs over REAL stdio JSON-RPC (via somi-mcp-client.mjs) to prove the
3
- // bundled MCP server behaves identically to scripts/somi-dispatch.mjs's CLI (they share
4
- // scripts/lib/dispatch-resolver.mjs) and that its own project-root resolution
5
- // (scripts/lib/mcp-project-root.mjs) follows the documented order without ever touching this
6
- // repo's own .somi/somi-state/. Every scenario runs against its own throwaway temp directory.
7
- //
8
- // Invoked from tests/scripts/somi-mcp.sh, which is wired into scripts/validate.sh.
9
-
10
- import { execFileSync } from 'node:child_process';
11
- import { mkdtempSync, rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
12
- import { tmpdir } from 'node:os';
13
- import path from 'node:path';
14
- import { fileURLToPath } from 'node:url';
15
- import { McpClient } from './somi-mcp-client.mjs';
16
- import { installText } from '../../../scripts/lib/install-text.mjs';
17
-
18
- const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
19
- const SERVER = path.join(ROOT, 'scripts', 'somi-mcp.mjs');
20
- const CLI = path.join(ROOT, 'scripts', 'somi-dispatch.mjs');
21
-
22
- let pass = 0;
23
- let fail = 0;
24
- function ok(name) { pass++; console.log(` ok ${name}`); }
25
- function bad(name, detail) { fail++; console.log(` FAIL ${name}${detail ? ` (${detail})` : ''}`); }
26
- function check(name, got, want) {
27
- if (JSON.stringify(got) === JSON.stringify(want)) ok(name);
28
- else bad(name, `want ${JSON.stringify(want)}, got ${JSON.stringify(got)}`);
29
- }
30
-
31
- const tmpRoot = mkdtempSync(path.join(tmpdir(), 'somi-mcp-test-'));
32
- function fresh() {
33
- const d = path.join(tmpRoot, `p${Math.random().toString(36).slice(2)}`);
34
- mkdirSync(d, { recursive: true });
35
- return d;
36
- }
37
-
38
- function projWith(body) {
39
- const d = fresh();
40
- mkdirSync(path.join(d, '.somi'), { recursive: true });
41
- writeFileSync(path.join(d, '.somi', 'config.json'), body);
42
- return d;
43
- }
44
-
45
- async function withClient(env, fn) {
46
- const client = new McpClient(SERVER, { env });
47
- try {
48
- return await fn(client);
49
- } finally {
50
- client.close();
51
- }
52
- }
53
-
54
- async function toolCall(client, name, args) {
55
- return client.request('tools/call', { name, arguments: args });
56
- }
57
-
58
- function toolText(result) {
59
- return result?.content?.[0]?.text ?? '';
60
- }
61
-
62
- async function run() {
63
- console.log('== somi-mcp (stdio MCP server) ==');
64
-
65
- // --- initialize / tools/list -------------------------------------------------------------
66
- await withClient({}, async (client) => {
67
- const init = await client.initialize();
68
- check('initialize echoes the requested protocolVersion', init.protocolVersion, '2024-11-05');
69
- check('initialize reports capabilities.tools', init.capabilities?.tools, {});
70
- check('initialize reports serverInfo.name', init.serverInfo?.name, 'somi');
71
-
72
- const list = await client.request('tools/list', {});
73
- const names = (list.tools || []).map((t) => t.name).sort();
74
- check('tools/list carries exactly somi_resolve, somi_agent_info, somi_command, somi_skill, somi_agent, somi_tier, somi_config and somi_loop', names, ['somi_agent', 'somi_agent_info', 'somi_command', 'somi_config', 'somi_loop', 'somi_resolve', 'somi_skill', 'somi_tier']);
75
-
76
- const ping = await client.request('ping', {});
77
- check('ping returns an empty result', ping, {});
78
- });
79
-
80
- // --- somi_resolve success matches the CLI's own output for the same args ------------------
81
- await withClient({}, async (client) => {
82
- await client.initialize();
83
- const proj = fresh();
84
- const result = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', host: 'claude-code', ceiling: 'low', project_dir: proj });
85
- const mcpJson = JSON.parse(toolText(result));
86
-
87
- const cliOut = execFileSync(process.execPath, [CLI, 'resolve', '--agent', 'somi-coder', '--host', 'claude-code', '--ceiling', 'low'], {
88
- env: { ...process.env, CLAUDE_PROJECT_DIR: fresh() },
89
- encoding: 'utf8',
90
- });
91
- const cliJson = JSON.parse(cliOut);
92
- check(
93
- 'somi_resolve (project_dir arg) matches the CLI byte-for-shape on tier/model/supported',
94
- { tier: mcpJson.tier, model: mcpJson.model, supported: mcpJson.supported, agent: mcpJson.agent },
95
- { tier: cliJson.tier, model: cliJson.model, supported: cliJson.supported, agent: cliJson.agent },
96
- );
97
- check('the resolved project dir is where ceiling state actually landed', existsSync(path.join(proj, '.somi', 'somi-state', 'ceiling.json')), true);
98
- });
99
-
100
- // --- CLI vs MCP parity with NO ceiling argument: config decides, and a bare resolve writes no state
101
- await withClient({}, async (client) => {
102
- await client.initialize();
103
- const mk = () => projWith('{"cost":{"ceiling":"low"}}');
104
- const proj = mk();
105
- const mcpJson = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: proj })));
106
- const cliJson = JSON.parse(execFileSync(process.execPath, [CLI, 'resolve', '--agent', 'somi-coder'], {
107
- env: { ...process.env, CLAUDE_PROJECT_DIR: mk(), SOMI_COST_CEILING: '' },
108
- }).toString());
109
- check('no ceiling argument: MCP and CLI both resolve ceiling low from the config', [mcpJson.ceiling, mcpJson.ceiling_source, cliJson.ceiling, cliJson.ceiling_source], ['low', 'config', 'low', 'config']);
110
- check('a bare MCP resolve writes no .somi/somi-state', existsSync(path.join(proj, '.somi', 'somi-state')), false);
111
- });
112
-
113
- // --- #32: enforced/reason are exposed, and a config mapping makes copilot enforced ----------
114
- await withClient({}, async (client) => {
115
- await client.initialize();
116
- const bare = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'copilot', ceiling: 'high', project_dir: fresh() })));
117
- check('copilot, no mapping: model null, enforced false, reason names host',
118
- [bare.model, bare.enforced, /no model mapping for host copilot.*low, medium and high/.test(bare.reason ?? '')], [null, false, true]);
119
- const mapped = fresh();
120
- mkdirSync(path.join(mapped, '.somi'), { recursive: true });
121
- writeFileSync(path.join(mapped, '.somi', 'config.json'),
122
- JSON.stringify({ cost: { mapping: { copilot: { low: 'gpt-5-mini', medium: 'gpt-5', high: 'gpt-5-pro' } } } }));
123
- const m = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'copilot', ceiling: 'high', project_dir: mapped })));
124
- check('copilot with config mapping: model set, enforced true, no reason',
125
- [m.model, m.enforced, 'reason' in m], ['gpt-5-pro', true, false]);
126
- const cc = JSON.parse(toolText(await toolCall(client, 'somi_resolve', { agent: 'somi-designer', host: 'claude-code', project_dir: fresh() })));
127
- check('claude-code default: model set, enforced true', [typeof cc.model, cc.enforced], ['string', true]);
128
- });
129
-
130
- // --- the four failure codes surface as isError with the matching code --------------------
131
- await withClient({}, async (client) => {
132
- await client.initialize();
133
-
134
- let r = await toolCall(client, 'somi_resolve', { agent: '../etc/passwd', project_dir: fresh() });
135
- check('64 (usage: invalid agent) is isError', r.isError, true);
136
- check('64 appears in the error text', /\(exit 64\)/.test(toolText(r)), true);
137
-
138
- r = await toolCall(client, 'somi_resolve', { agent: 'totally-not-a-real-agent', project_dir: fresh() });
139
- check('65 (unknown agent) is isError', r.isError, true);
140
- check('65 appears in the error text', /\(exit 65\)/.test(toolText(r)), true);
141
-
142
- r = await toolCall(client, 'somi_resolve', { agent: 'somi', project_dir: fresh() });
143
- check('66 (malformed: somi is exempt) is isError', r.isError, true);
144
- check('66 appears in the error text', /\(exit 66\)/.test(toolText(r)), true);
145
- check("66's message names the exemption, matching the CLI's own wording", /exempt/.test(toolText(r)), true);
146
-
147
- const brokenProj = fresh();
148
- mkdirSync(path.join(brokenProj, '.somi'), { recursive: true });
149
- writeFileSync(path.join(brokenProj, '.somi', 'config.json'), '{"cost": {"ceiling": "low"}\n'); // missing brace
150
- r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: brokenProj });
151
- check('67 (project environment failure: unparsable config.json) is isError', r.isError, true);
152
- check('67 appears in the error text', /\(exit 67\)/.test(toolText(r)), true);
153
- });
154
-
155
- // --- hard cap / overrides / size cap surface through somi_resolve unchanged -----------------
156
- await withClient({}, async (client) => {
157
- await client.initialize();
158
- const withConfig = projWith;
159
- let r = await toolCall(client, 'somi_resolve', { agent: 'somi-designer', project_dir: withConfig('{"cost":{"ceiling":"low"}}') });
160
- let j = JSON.parse(toolText(r));
161
- check('hard cap: high-only designer under ceiling low is clamped, degraded, tier_source ceiling', [j.tier, j.degraded, j.declared, j.tier_source], ['low', true, ['high'], 'ceiling']);
162
- r = await toolCall(client, 'somi_resolve', { agent: 'somi-designer', project_dir: withConfig('{"cost":{"ceiling":"low","agents":{"somi-designer":"high"}}}') });
163
- j = JSON.parse(toolText(r));
164
- check('a cost.agents override wins over the ceiling', [j.tier, j.degraded, j.tier_source], ['high', false, 'override']);
165
-
166
- r = await toolCall(client, 'somi_resolve', { agent: 'somi-designer', project_dir: withConfig('{"cost":{"agents":{"somi-designer":"turbo"}}}') });
167
- check('a bad override value is isError with exit 67', [r.isError, /\(exit 67\)/.test(toolText(r))], [true, true]);
168
-
169
- r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: withConfig(`{"pad":"${'x'.repeat(70000)}"}`) });
170
- check('an oversize config.json is isError with exit 67', [r.isError, /\(exit 67\)/.test(toolText(r))], [true, true]);
171
- });
172
-
173
- // --- path traversal rejected before any read ----------------------------------------------
174
- await withClient({}, async (client) => {
175
- await client.initialize();
176
- const proj = fresh();
177
- const r = await toolCall(client, 'somi_resolve', { agent: '../etc/passwd', project_dir: proj });
178
- check('path traversal in agent is rejected', r.isError, true);
179
- check('a rejected agent leaves the project root untouched -- no .somi/ written', existsSync(path.join(proj, '.somi')), false);
180
-
181
- const proj2 = fresh();
182
- const r2 = await toolCall(client, 'somi_resolve', { agent: 'a/b', project_dir: proj2 });
183
- check('a bare slash in agent is also rejected', r2.isError, true);
184
- });
185
-
186
- // --- somi_command: real text, and its own path-traversal rejection ------------------------
187
- await withClient({}, async (client) => {
188
- await client.initialize();
189
- const r = await toolCall(client, 'somi_command', { name: 'plan' });
190
- check('somi_command returns commands/plan.md content, not an error', r.isError, undefined);
191
- check('the returned text is really commands/plan.md', toolText(r).includes('# /plan — Planning workflow'), true);
192
-
193
- const bad1 = await toolCall(client, 'somi_command', { name: '../etc/passwd' });
194
- check('somi_command rejects a path-traversal name', bad1.isError, true);
195
-
196
- const unknown = await toolCall(client, 'somi_command', { name: 'not-a-real-command' });
197
- check('somi_command rejects an unknown command name', unknown.isError, true);
198
- });
199
-
200
- // --- somi_skill: real text, and its own allowlist-before-path traversal rejection ---------
201
- await withClient({}, async (client) => {
202
- await client.initialize();
203
- const r = await toolCall(client, 'somi_skill', { name: 'somi-dispatch' });
204
- check('somi_skill returns skills/somi-dispatch/SKILL.md content, not an error', r.isError, undefined);
205
- check('the returned text is really skills/somi-dispatch/SKILL.md', toolText(r).includes('somi-dispatch — resolve, then start, one agent'), true);
206
-
207
- const bad1 = await toolCall(client, 'somi_skill', { name: '../x' });
208
- check('somi_skill rejects a path-traversal name (../x) via the allowlist, before any read', bad1.isError, true);
209
- check('the traversal rejection is the usual usage code (64), not a filesystem error', /\(exit 64\)/.test(toolText(bad1)), true);
210
-
211
- const unknownSkill = await toolCall(client, 'somi_skill', { name: 'not-a-real-skill' });
212
- check('somi_skill rejects an unknown skill name', unknownSkill.isError, true);
213
- });
214
-
215
- // --- somi_agent: the agent's instructions without frontmatter, same allowlist ------------
216
- await withClient({}, async (client) => {
217
- await client.initialize();
218
- const r = await toolCall(client, 'somi_agent', { name: 'somi-reviewer' });
219
- check('somi_agent returns agents/somi-reviewer.md content, not an error', r.isError, undefined);
220
- check('the returned text starts at the body: no frontmatter, no model: line', /^---|^model:/m.test(toolText(r)), false);
221
- check('the returned text is really the reviewer body', toolText(r).length > 1000 && /reviewer/i.test(toolText(r)), true);
222
-
223
- const bad1 = await toolCall(client, 'somi_agent', { name: '../agents/reviewer' });
224
- check('somi_agent rejects a path-traversal name with the usage code (64)', /\(exit 64\)/.test(toolText(bad1)), true);
225
-
226
- const unknown = await toolCall(client, 'somi_agent', { name: 'not-a-real-agent' });
227
- check('somi_agent rejects an unknown agent with exit 65', /\(exit 65\)/.test(toolText(unknown)), true);
228
- });
229
-
230
- // --- unknown tool name -> JSON-RPC error, not a tool result -------------------------------
231
- await withClient({}, async (client) => {
232
- await client.initialize();
233
- let errored = false;
234
- try {
235
- await toolCall(client, 'bogus_tool', {});
236
- } catch {
237
- errored = true;
238
- }
239
- check('an unknown tool name is a JSON-RPC error', errored, true);
240
- });
241
-
242
- // --- malformed JSON and an unknown method don't kill the server ---------------------------
243
- await withClient({}, async (client) => {
244
- await client.initialize();
245
- client.writeRaw('this is not json');
246
- const parseErr = await client.waitFor((m) => m.error?.code === -32700);
247
- check('malformed JSON gets a JSON-RPC parse error', parseErr.error.code, -32700);
248
- check('a parse error has id: null (nothing to correlate)', parseErr.id, null);
249
-
250
- client.notify('bogus/notification', {});
251
- client.writeRaw(JSON.stringify({ jsonrpc: '2.0', id: 999, method: 'bogus/method' }));
252
- const methodErr = await client.waitFor((m) => m.id === 999);
253
- check('an unknown METHOD gets a JSON-RPC method-not-found error', methodErr.error?.code, -32601);
254
-
255
- // The server must still answer a perfectly good request after all of the above.
256
- const list = await client.request('tools/list', {});
257
- check('the server is still alive and answers a valid request afterward', Array.isArray(list.tools), true);
258
- });
259
-
260
- // --- project-root resolution (scripts/lib/mcp-project-root.mjs) ---------------------------
261
- // No project_dir, no host root: project_dir alone decides.
262
- await withClient({}, async (client) => {
263
- await client.initialize();
264
- const proj = fresh();
265
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low', project_dir: proj });
266
- check('no host root: project_dir alone decides', r.isError, undefined);
267
- check('ceiling state landed under the project_dir argument', existsSync(path.join(proj, '.somi', 'somi-state')), true);
268
- });
269
-
270
- // A HOST root (CLAUDE_PROJECT_DIR) is used directly when no project_dir is given.
271
- {
272
- const envProj = fresh();
273
- await withClient({ CLAUDE_PROJECT_DIR: envProj }, async (client) => {
274
- await client.initialize();
275
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
276
- check('CLAUDE_PROJECT_DIR is used when no project_dir is given', r.isError, undefined);
277
- check('ceiling state landed under CLAUDE_PROJECT_DIR', existsSync(path.join(envProj, '.somi', 'somi-state')), true);
278
- });
279
- }
280
-
281
- // M3: a host root (CLAUDE_PROJECT_DIR) exists AND project_dir is OUTSIDE it -- refused (64),
282
- // nothing read or written anywhere. This closes the prompt-injection path: model-supplied text
283
- // choosing both which .somi/config.json is read and where state is written, unconstrained.
284
- {
285
- const hostProj = fresh();
286
- const outsideProj = fresh();
287
- await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
288
- await client.initialize();
289
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: outsideProj });
290
- check('M3: project_dir outside the host root is refused', r.isError, true);
291
- check('M3: the refusal is a usage error (64)', /\(exit 64\)/.test(toolText(r)), true);
292
- check('M3: no .somi/ written under the host root', existsSync(path.join(hostProj, '.somi')), false);
293
- check('M3: no .somi/ written under the rejected project_dir either', existsSync(path.join(outsideProj, '.somi')), false);
294
- });
295
- }
296
-
297
- // M3: a host root exists AND project_dir is INSIDE it (a subdirectory) or EQUAL to it -- both
298
- // allowed, and project_dir (the more specific path) is what's actually used.
299
- {
300
- const hostProj = fresh();
301
- const insideProj = path.join(hostProj, 'packages', 'sub');
302
- mkdirSync(insideProj, { recursive: true });
303
- await withClient({ CLAUDE_PROJECT_DIR: hostProj }, async (client) => {
304
- await client.initialize();
305
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low', project_dir: insideProj });
306
- check('M3: project_dir inside the host root is allowed', r.isError, undefined);
307
- check('M3: ceiling state landed under project_dir itself, not the host root', existsSync(path.join(insideProj, '.somi', 'somi-state')), true);
308
- check('M3: the host root itself got no .somi/ written', existsSync(path.join(hostProj, '.somi')), false);
309
-
310
- const r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: hostProj });
311
- check('M3: project_dir equal to the host root is allowed', r2.isError, undefined);
312
- });
313
- }
314
-
315
- // M1: a single MCP root (no CLAUDE_PROJECT_DIR) is used when the client declares `roots`.
316
- await withClient({}, async (client) => {
317
- await client.initialize({ roots: {} });
318
- const rootsProj = fresh();
319
- client.rootsHandler = () => [rootsProj];
320
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
321
- check('M1: a single MCP root is used when the client declares the capability', r.isError, undefined);
322
- check('M1: the server actually asked for roots/list', client.messages.some((m) => m.method === 'roots/list'), true);
323
- check('M1: ceiling state landed under the root the client returned', existsSync(path.join(rootsProj, '.somi', 'somi-state')), true);
324
- });
325
-
326
- // M1: a non-file:// root URI is dropped, never resolved as a path under the server's own cwd --
327
- // with nothing else establishing a root, this must refuse (67), never guess.
328
- await withClient({}, async (client) => {
329
- await client.initialize({ roots: {} });
330
- client.rootsHandler = () => [{ uri: 'not-a-file-uri' }];
331
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
332
- check('M1: a non-file root URI is rejected outright (never resolved as a relative path)', r.isError, true);
333
- check('M1: with only a non-file root offered, "no root" (67) is reported, not a guessed path', /\(exit 67\)/.test(toolText(r)), true);
334
- });
335
-
336
- // M1: a percent-encoded file:// root URI is decoded with url.fileURLToPath, not hand-sliced --
337
- // the scratchpad ships both a literal "a%20b" dir and a real "a b" (space) dir so this
338
- // distinguishes correct decoding from a naive prefix-strip.
339
- {
340
- const rootDir = fresh();
341
- const spaced = path.join(rootDir, 'a b');
342
- const literalPercent = path.join(rootDir, 'a%20b');
343
- mkdirSync(spaced, { recursive: true });
344
- mkdirSync(literalPercent, { recursive: true });
345
- await withClient({}, async (client) => {
346
- await client.initialize({ roots: {} });
347
- client.rootsHandler = () => [{ uri: `file://${encodeURI(spaced)}` }];
348
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
349
- check('M1: a percent-encoded root URI resolves (isError undefined)', r.isError, undefined);
350
- check('M1: it decodes to the REAL space directory, not the literal-percent one', existsSync(path.join(spaced, '.somi', 'somi-state')), true);
351
- check('M1: the literal "a%20b" directory is untouched', existsSync(path.join(literalPercent, '.somi')), false);
352
- });
353
- }
354
-
355
- // M1: more than one MCP root, no project_dir to select one -- ambiguous, refused, never guesses
356
- // the first one. M1+M3: project_dir selecting exactly one of them is allowed.
357
- await withClient({}, async (client) => {
358
- await client.initialize({ roots: {} });
359
- const rootA = fresh();
360
- const rootB = fresh();
361
- client.rootsHandler = () => [rootA, rootB];
362
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low' });
363
- check('M1: more than one root with no project_dir is ambiguous and refused', r.isError, true);
364
- check('M1/M3: ambiguous roots refusal is the project-environment family (67)', /\(exit 67\)/.test(toolText(r)), true);
365
- check('M1: neither offered root got a .somi/ written', existsSync(path.join(rootA, '.somi')) || existsSync(path.join(rootB, '.somi')), false);
366
-
367
- const r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: 'low', project_dir: rootB });
368
- check('M1+M3: project_dir selecting one of several ambiguous roots is allowed', r2.isError, undefined);
369
- check('M1+M3: state landed under the SELECTED root', existsSync(path.join(rootB, '.somi', 'somi-state')), true);
370
- check('M1+M3: the other offered root got nothing written', existsSync(path.join(rootA, '.somi')), false);
371
- });
372
-
373
- // M1: a root that doesn't exist is rejected, never created (cost-ceiling.mjs's saveState does a
374
- // recursive mkdir -- this proves it's never reached for a bogus root).
375
- await withClient({}, async (client) => {
376
- await client.initialize({ roots: {} });
377
- const missing = path.join(tmpRoot, `missing-${Math.random().toString(36).slice(2)}`);
378
- client.rootsHandler = () => [missing];
379
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder' });
380
- check('M1: a nonexistent MCP root is rejected', r.isError, true);
381
- check('M1: it is never silently created', existsSync(missing), false);
382
- });
383
-
384
- // Nothing establishes a root -> a clear, distinct refusal (67), never a silent fallback. A
385
- // malformed project_dir (relative, nonexistent) is a usage error (64) regardless.
386
- await withClient({}, async (client) => {
387
- await client.initialize(); // no `roots` capability declared
388
- const r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder' });
389
- check('no root establishable is isError', r.isError, true);
390
- check('the error names the reason and how to fix it', /project_dir/.test(toolText(r)), true);
391
- check('the exit-67 family is used for "cannot establish a root"', /\(exit 67\)/.test(toolText(r)), true);
392
-
393
- let r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: 'relative/path' });
394
- check('a non-absolute project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
395
- r2 = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', project_dir: '/definitely/does/not/exist/anywhere' });
396
- check('a nonexistent project_dir is rejected (64)', /\(exit 64\)/.test(toolText(r2)), true);
397
- });
398
-
399
- // --- m1: a present-but-wrong-shaped argument is 64, never silently defaulted -----------------
400
- await withClient({}, async (client) => {
401
- await client.initialize();
402
- const proj = fresh();
403
- let r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', host: ['copilot'], project_dir: proj });
404
- check('m1: an array-valued host is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
405
- check('m1: a rejected host leaves the project root untouched', existsSync(path.join(proj, '.somi')), false);
406
-
407
- const proj2 = fresh();
408
- r = await toolCall(client, 'somi_resolve', { agent: 'somi-coder', ceiling: '', project_dir: proj2 });
409
- check('m1: an empty-string ceiling is rejected (64), not silently defaulted', /\(exit 64\)/.test(toolText(r)), true);
410
- check('m1: a rejected ceiling leaves the project root untouched', existsSync(path.join(proj2, '.somi')), false);
411
- });
412
-
413
- // --- m2: an object-valued agent/name is a clean tool error, never a crashed JSON-RPC internal
414
- // error (-32603) from throwing inside a template-literal interpolation ------------------------
415
- await withClient({}, async (client) => {
416
- await client.initialize();
417
- const r = await toolCall(client, 'somi_resolve', { agent: { toString: null }, project_dir: fresh() });
418
- check('m2: an object-valued agent (toString: null) is a clean isError, not a crash', r.isError, true);
419
- check('m2: it is reported as the usual 64, not surfaced as an internal error', /\(exit 64\)/.test(toolText(r)), true);
420
-
421
- const r2 = await toolCall(client, 'somi_command', { name: { toString: null } });
422
- check('m2: an object-valued somi_command name is a clean isError, not a crash', r2.isError, true);
423
- check('m2: it is reported as the usual 64, not surfaced as an internal error', /\(exit 64\)/.test(toolText(r2)), true);
424
- });
425
-
426
- // --- install-text names: the unknown-name text, object-shaped names, a bounded name, and a read error that is not "missing" ---
427
- await withClient({}, async (client) => {
428
- await client.initialize();
429
- const texts = [];
430
- for (const [tool, name] of [['somi_command', 'no-such-command'], ['somi_skill', 'no-such-skill']]) texts.push(toolText(await toolCall(client, tool, { name })));
431
- check('an unknown command and an unknown skill are 65 and say which kind and name', texts.map((t) => [/\(exit 65\)$/.test(t), t.includes(`unknown ${t.includes('somi-command') ? 'command' : 'skill'} "no-such-`)]), [[true, true], [true, true]]);
432
- const objects = [];
433
- for (const tool of ['somi_skill', 'somi_agent']) objects.push(await toolCall(client, tool, { name: { toString: null } }));
434
- check('an object-shaped skill or agent name is a clean 64, not an internal error', objects.map((r) => [r.isError, /\(exit 64\)$/.test(toolText(r))]), [[true, true], [true, true]]);
435
- const long = toolText(await toolCall(client, 'somi_skill', { name: 'a'.repeat(5000) }));
436
- check('a name over 64 characters is a 64 whose text does not repeat it', [/\(exit 64\)$/.test(long), long.length < 200], [true, true]);
437
- check('a name of exactly 64 characters passes the bound (and is unknown, 65)', /\(exit 65\)$/.test(toolText(await toolCall(client, 'somi_skill', { name: 'a'.repeat(64) }))), true);
438
- });
439
- {
440
- const install = fresh(); mkdirSync(path.join(install, 'commands', 'x.md'), { recursive: true });
441
- let code = null; try { installText('command', { name: 'x' }, { installRoot: install }); } catch (e) { code = e.code; }
442
- check('a read error that is not "missing" (a directory at commands/x.md) is rethrown, never reported as an unknown command', code, 'EISDIR');
443
- }
444
-
445
- // --- M2: the SAME bad input produces the SAME code through the CLI and the MCP tool ----------
446
- {
447
- const badInputs = [
448
- { name: 'invalid agent name', args: { agent: 'Not-Valid' } },
449
- { name: 'unrecognized ceiling', args: { agent: 'somi-coder', ceiling: 'ultra' } },
450
- { name: 'somi is exempt from cost resolution', args: { agent: 'somi' } },
451
- { name: 'unknown agent', args: { agent: 'totally-not-a-real-agent' } },
452
- ];
453
- for (const { name, args } of badInputs) {
454
- const proj = fresh();
455
- const cliArgs = [CLI, 'resolve', '--agent', args.agent];
456
- if (args.ceiling) cliArgs.push('--ceiling', args.ceiling);
457
- let cliCode = 0;
458
- try {
459
- execFileSync(process.execPath, cliArgs, { env: { ...process.env, CLAUDE_PROJECT_DIR: proj }, stdio: 'pipe' });
460
- } catch (e) {
461
- cliCode = e.status;
462
- }
463
- await withClient({}, async (client) => {
464
- await client.initialize();
465
- const r = await toolCall(client, 'somi_resolve', { ...args, project_dir: fresh() });
466
- const mcpMatch = /\(exit (\d+)\)/.exec(toolText(r));
467
- const mcpCode = mcpMatch ? Number(mcpMatch[1]) : 0;
468
- check(`M2 parity (${name}): CLI exit ${cliCode} === MCP code ${mcpCode}`, mcpCode, cliCode);
469
- });
470
- }
471
- }
472
-
473
- // --- m5: initialize answers with a version it actually supports, never an echo -----------------
474
- await withClient({}, async (client) => {
475
- const init = await client.request('initialize', { protocolVersion: '1999-01-01', capabilities: {} });
476
- check('m5: an unsupported protocolVersion is NOT echoed back', init.protocolVersion, '2025-06-18');
477
- client.notify('notifications/initialized');
478
- });
479
- }
480
-
481
- run()
482
- .then(() => {
483
- console.log(`somi-mcp tests: ${pass} ok, ${fail} failed`);
484
- rmSync(tmpRoot, { recursive: true, force: true });
485
- process.exit(fail === 0 ? 0 : 1);
486
- })
487
- .catch((e) => {
488
- console.error('somi-mcp-tests.mjs crashed:', e.stack || e);
489
- rmSync(tmpRoot, { recursive: true, force: true });
490
- process.exit(1);
491
- });
@@ -1,64 +0,0 @@
1
- #!/usr/bin/env node
2
- // Drives scripts/somi-mcp.mjs over real stdio JSON-RPC for the somi_tier tool: the sizing CLI's own output and
3
- // exit codes for every case, the advertised schema, and the hint for invented signal names. Invoked from
4
- // tests/scripts/somi-mcp.sh next to the main MCP tests.
5
-
6
- import { execFileSync } from 'node:child_process';
7
- import { existsSync } from 'node:fs';
8
- import path from 'node:path';
9
- import { fileURLToPath } from 'node:url';
10
- import { McpClient } from './somi-mcp-client.mjs';
11
- import { SIGNAL_IDS } from '../../../scripts/lib/size-tier.mjs';
12
-
13
- const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
14
- const SERVER = path.join(ROOT, 'scripts', 'somi-mcp.mjs');
15
- let pass = 0; let fail = 0;
16
- const check = (name, got, want) => {
17
- if (JSON.stringify(got) === JSON.stringify(want)) { pass++; console.log(` ok ${name}`); } else { fail++; console.log(` FAIL ${name} (want ${JSON.stringify(want)}, got ${JSON.stringify(got)})`); }
18
- };
19
- async function withClient(env, fn) {
20
- const client = new McpClient(SERVER, { env });
21
- try { await client.initialize(); return await fn(client); } finally { client.close(); }
22
- }
23
- const toolCall = (client, name, args) => client.request('tools/call', { name, arguments: args });
24
- const toolText = (r) => r?.content?.[0]?.text ?? '';
25
-
26
- async function run() {
27
- console.log('== somi_tier (MCP) ==');
28
- // --- somi_tier: the sizing CLI's own output and exit codes, for every case --------------------
29
- await withClient({}, async (client) => {
30
- await client.initialize();
31
- const TIER_CLI = path.join(ROOT, 'scripts', 'somi-tier.mjs');
32
- const base = { T1: true, T2: true, T3: true, T4: true, T5: true, sensitive_core: false, hard_surface: false, design_open: false, open_questions: 0, acceptance_testable: true, modules_touched: 1, est_files: 1, est_diff_lines: 40, existing_work_item: false, brief_exists: false };
33
- const sig = (over = {}) => Object.fromEntries(Object.entries({ ...base, ...over }).map(([k, v]) => [k, { value: v, evidence: 'e' }]));
34
- const cases = [
35
- ['trivial', sig(), undefined], ['small', sig({ T2: false, est_diff_lines: 80 }), undefined],
36
- ['floor', sig({ T3: false, sensitive_core: true, hard_surface: true }), undefined], ['security lens, no floor', sig({ T3: false }), undefined], ['unknown signal', { ...sig(), T3: { value: null, evidence: 'x' } }, undefined],
37
- ['raise', sig(), 'full'], ['lower below the floor', sig({ T3: false, sensitive_core: true }), 'small'],
38
- ];
39
- for (const [label, signals, override] of cases) {
40
- const argv = [TIER_CLI, 'resolve', '--signals', '-', ...(override ? ['--override', override] : [])];
41
- let want; let code = 0;
42
- try { want = execFileSync(process.execPath, argv, { input: JSON.stringify(signals), encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trimEnd(); } catch (e) { code = e.status; want = null; }
43
- const r = await toolCall(client, 'somi_tier', { signals, ...(override ? { override } : {}) });
44
- if (code === 0) check(`somi_tier ${label}: same JSON as the CLI`, [r.isError, toolText(r)], [undefined, want]);
45
- else check(`somi_tier ${label}: error carries the CLI exit code`, [r.isError, toolText(r).endsWith(`(exit ${code})`)], [true, true]);
46
- }
47
- // The advertised schema lists the rubric's own ids (imported, not copied), each with value and evidence.
48
- const tierTool = ((await client.request('tools/list', {})).tools || []).find((t) => t.name === 'somi_tier');
49
- const sp = tierTool?.inputSchema?.properties?.signals;
50
- check('somi_tier schema: signals lists exactly the rubric signal ids, all required', [Object.keys(sp?.properties ?? {}), sp?.required], [[...SIGNAL_IDS], [...SIGNAL_IDS]]);
51
- check('somi_tier schema: every signal is an object that requires value and evidence', Object.values(sp?.properties ?? {}).every((v) => v.type === 'object' && JSON.stringify(v.required) === '["value","evidence"]'), true);
52
- check('somi_tier description says the ids are exact and points at the routing skill without stating a threshold', [/ids in `signals` are exact/.test(tierTool?.description ?? ''), /somi-routing/.test(sp?.description ?? ''), /\b(40|50)\b/.test(JSON.stringify(sp))], [true, true, false]);
53
- const invented = await toolCall(client, 'somi_tier', { signals: { business_logic_complexity: { value: true, evidence: 'SECRET-VALUE' }, 'x\u202ey': 1 } });
54
- const iv = JSON.parse(toolText(invented));
55
- check('somi_tier: invented names come back as unrecognized next to the expected ids; the decision is the closed one (full) and no value is echoed', [iv.tier, iv.unrecognized, iv.expected, toolText(invented).includes('SECRET-VALUE'), toolText(invented).includes('\u202e')], ['full', ['business_logic_complexity', 'x\u202ey'], [...SIGNAL_IDS], false, false]);
56
- check('somi_tier: a correct call carries neither unrecognized nor expected', ['unrecognized' in JSON.parse(toolText(await toolCall(client, 'somi_tier', { signals: sig() }))), 'expected' in JSON.parse(toolText(await toolCall(client, 'somi_tier', { signals: sig() })))], [false, false]);
57
- const noObj = await toolCall(client, 'somi_tier', { signals: [1] });
58
- check('somi_tier rejects non-object signals with 64 and writes nothing', [noObj.isError, /\(exit 64\)/.test(toolText(noObj)), existsSync(path.join(ROOT, '.somi', 'somi-state', 'tier', 'x.json'))], [true, true, false]);
59
- });
60
-
61
- console.log(`somi_tier tests: ${pass} ok, ${fail} failed`);
62
- if (fail) process.exitCode = 1;
63
- }
64
- run().catch((e) => { console.error(e); process.exit(1); });
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
- // Drives scripts/somi-mcp.mjs's REAL `tools/list` (over real stdio JSON-RPC, via the same
3
- // McpClient tests/scripts/lib/somi-mcp-tests.mjs uses) and prints each tool's name -> {required,
4
- // properties} as one JSON object on stdout.
5
- //
6
- // tests/scripts/somi-agent-dispatch-contract.sh reads this to check agents/somi.md's Step 4/5
7
- // against the server's actual advertised schema, instead of a hand-typed copy of the tool/argument
8
- // names that could quietly drift from what the server really exposes.
9
-
10
- import path from 'node:path';
11
- import { fileURLToPath } from 'node:url';
12
- import { McpClient } from './somi-mcp-client.mjs';
13
-
14
- const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..');
15
- const SERVER = path.join(ROOT, 'scripts', 'somi-mcp.mjs');
16
-
17
- async function main() {
18
- const client = new McpClient(SERVER, {});
19
- try {
20
- await client.initialize();
21
- const { tools } = await client.request('tools/list', {});
22
- const shape = {};
23
- for (const t of tools || []) {
24
- shape[t.name] = {
25
- required: [...(t.inputSchema?.required || [])].sort(),
26
- properties: Object.keys(t.inputSchema?.properties || {}).sort(),
27
- };
28
- }
29
- process.stdout.write(JSON.stringify(shape));
30
- } finally {
31
- client.close();
32
- }
33
- }
34
-
35
- main().catch((e) => {
36
- console.error(`somi-mcp-tool-schema: ${e.stack || e}`);
37
- process.exit(1);
38
- });
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env bash
2
- # The loop engine's libraries (scripts/lib/loop-*.mjs), called in-process: cap resolution and every handler take
3
- # their environment as a parameter and never read process.env (sentinels planted in it, global config included,
4
- # are ignored), malformed caps are refused with exit 64, and the exit model is plain data (check-diff over the cap
5
- # returns its JSON and code 3 in one result). scripts/lib/findings-ledger.mjs gets the same treatment: record's
6
- # identity, breaker and no-write-on-bad-input behaviour, the resolve/reopen/open/get lifecycle, and no environment
7
- # read. The composite steps (loop-step.mjs) and the notes writers have their own test files below, the last one the leniency toward a model's habits. The CLI's bytes
8
- # are pinned separately by tests/scripts/run.sh and its goldens.
9
- set -euo pipefail
10
- ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
11
- # Hermetic like scripts/validate.sh: the developer's global config must not reach the suite.
12
- export SOMI_GLOBAL_CONFIG=""
13
- node "$ROOT/tests/scripts/lib/loop-engine-tests.mjs"
14
- node "$ROOT/tests/scripts/lib/findings-ledger-tests.mjs"
15
- node "$ROOT/tests/scripts/lib/loop-notes-tests.mjs"
16
- node "$ROOT/tests/scripts/lib/loop-step-tests.mjs"
17
- node "$ROOT/tests/scripts/lib/loop-step-state-tests.mjs"
18
- node "$ROOT/tests/scripts/lib/loop-step-close-tests.mjs"
19
- node "$ROOT/tests/scripts/lib/loop-step-cli-tests.mjs"
20
- node "$ROOT/tests/scripts/lib/loop-step-unwritten-tests.mjs"
21
- node "$ROOT/tests/scripts/lib/loop-step-lenient-tests.mjs"
22
- node "$ROOT/tests/scripts/lib/loop-escalate-tests.mjs"
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Guards the shape of both loop flows' MCP path (calls per clean pass, no CLI step before the Host fallback, the engine's
3
- # tokens, the safety rules, the size budget), proven red on mutated copies, with one real pass per flow through the
4
- # server (tests/scripts/lib/loop-flow-gate.mjs). It fails unless the summary line printed.
5
- set -euo pipefail
6
- ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
7
- # Hermetic like scripts/validate.sh: the developer's global config must not reach the suite.
8
- export SOMI_GLOBAL_CONFIG=""
9
- out="$(node "$ROOT/tests/scripts/lib/loop-flow-gate.mjs")" || { printf '%s\n' "$out"; exit 1; }
10
- printf '%s\n' "$out"
11
- printf '%s\n' "$out" | grep -Eq '^loop flow shape: [1-9][0-9]* ok, 0 failed$'