@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,224 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Cross-checks agents/somi.md's dispatch instructions against both dispatch surfaces' real
3
- # behavior. A prompt cannot be exercised without a model, but what it tells the model to RUN can
4
- # be: the primary path is the bundled somi_resolve/somi_command MCP tools (checked against the
5
- # real server below, driven rather than hand-typed), and the CLI fallback invocation shape plus the
6
- # exit codes Step 4 maps must still be real and current against scripts/somi-dispatch.mjs, not
7
- # prose that quietly drifted from either surface it describes.
8
- set -uo pipefail
9
-
10
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
11
- AGENT_MD="$ROOT_REPO/agents/somi.md"
12
- SKILL_MD="$ROOT_REPO/skills/somi-dispatch/SKILL.md"
13
- CLI="$ROOT_REPO/scripts/somi-dispatch.mjs"
14
- COMMAND_MDS="$ROOT_REPO/agents/somi-flow.md $ROOT_REPO/agents/somi-general.md $ROOT_REPO/skills/somi-checkpoint/SKILL.md "$(ls "$ROOT_REPO"/skills/flow-*/SKILL.md)
15
-
16
- pass=0; fail=0
17
- ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
18
- bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
19
-
20
- echo "== somi agent <-> somi-dispatch.mjs dispatch contract =="
21
-
22
- TMP="$(mktemp -d)"
23
- trap 'rm -rf "$TMP"' EXIT
24
- fresh() { mktemp -d -p "$TMP"; }
25
- reach() { # $1=name $2=want-exit-code, remaining = CLI args after 'resolve'
26
- local name="$1" want="$2" rc=0
27
- shift 2
28
- CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve "$@" >/dev/null 2>&1 || rc=$?
29
- if [ "$rc" = "$want" ]; then ok "$name"; else bad "$name (expected exit $want, got $rc)"; fi
30
- }
31
-
32
- # --- the CLI-fallback invocation shape is named in skills/somi-dispatch/SKILL.md (the resolve
33
- # procedure lives there so every command that Tasks an agent shares it, not just the front door) --
34
- # checked against the skill and, for belt-and-braces, agents/somi.md too, since either file could
35
- # carry the wording after a future edit.
36
- if grep -qF 'resolve --agent <agent name> --host <host>' "$AGENT_MD" "$SKILL_MD"; then
37
- ok "skills/somi-dispatch/SKILL.md names the 'resolve --agent ... --host ...' invocation shape"
38
- else
39
- bad "neither agents/somi.md nor skills/somi-dispatch/SKILL.md names the resolve --agent/--host CLI fallback shape -- if the wording changed intentionally, update this test to match it"
40
- fi
41
-
42
- out="$(CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent somi-coder --host claude-code)"; rc=$?
43
- if [ "$rc" -eq 0 ] && node -e 'JSON.parse(process.argv[1])' "$out" >/dev/null 2>&1; then
44
- ok "the literal CLI-fallback invocation Step 4 names succeeds against the real CLI and prints valid JSON"
45
- else
46
- bad "Step 4's CLI-fallback invocation does not succeed against the real CLI (rc=$rc, out=$out)"
47
- fi
48
-
49
- # --- the two host values the dispatch skill names are the CLI's own recognized host strings -------
50
- if grep -q '`claude-code` if this turn is running in Claude Code' "$AGENT_MD" "$SKILL_MD" \
51
- && grep -q '`copilot` if.*running in GitHub Copilot' "$AGENT_MD" "$SKILL_MD"; then
52
- ok "skills/somi-dispatch/SKILL.md names claude-code and copilot precisely as the two --host values"
53
- else
54
- bad "neither agents/somi.md nor skills/somi-dispatch/SKILL.md clearly names both claude-code and copilot as --host values"
55
- fi
56
- for h in claude-code copilot; do
57
- hrc=0
58
- CLAUDE_PROJECT_DIR="$(fresh)" node "$CLI" resolve --agent somi-coder --host "$h" >/dev/null 2>&1 || hrc=$?
59
- if [ "$hrc" = "0" ]; then ok "--host $h is accepted by the real CLI"; else bad "--host $h was rejected (rc=$hrc)"; fi
60
- done
61
-
62
- # --- the exit codes the dispatch skill maps are EXACTLY the CLI's real EXIT_* constants -----------
63
- PROMPT_CODES="$(grep -ohE '^- `[0-9]+`' "$AGENT_MD" "$SKILL_MD" | grep -oE '[0-9]+' | sort -un | tr '\n' ' ')"
64
- CLI_CODES="$(grep -oE '^const EXIT_[A-Z_]+ = [0-9]+;' "$CLI" | grep -oE '[0-9]+' | sort -un | tr '\n' ' ')"
65
- if [ -n "$PROMPT_CODES" ] && [ "$PROMPT_CODES" = "$CLI_CODES" ]; then
66
- ok "the exit codes skills/somi-dispatch/SKILL.md maps ($PROMPT_CODES) exactly match the CLI's real EXIT_* constants ($CLI_CODES)"
67
- else
68
- bad "the mapped exit codes ($PROMPT_CODES) do not match the CLI's real EXIT_* constants ($CLI_CODES)"
69
- fi
70
-
71
- # --- each code Step 4 maps is genuinely reachable against the real CLI, not merely documented -----
72
- reach "64 (usage) is reachable: missing --agent" 64
73
- reach "65 (unknown agent) is reachable" 65 --agent totally-not-a-real-agent
74
- reach "66 (no tier source) is reachable: somi is exempt from cost resolution" 66 --agent somi
75
-
76
- R67="$(fresh)"; mkdir -p "$R67/.somi"
77
- printf '{"cost": {"ceiling": "low"}\n' > "$R67/.somi/config.json" # missing closing brace
78
- r67rc=0
79
- CLAUDE_PROJECT_DIR="$R67" node "$CLI" resolve --agent somi-coder >/dev/null 2>&1 || r67rc=$?
80
- if [ "$r67rc" = "67" ]; then
81
- ok "67 (project environment/config failure) is reachable: unparsable .somi/config.json"
82
- else
83
- bad "67 was not reachable via an unparsable config.json (got $r67rc)"
84
- fi
85
-
86
- # 67 is also reachable AFTER an earlier successful call persisted a ceiling (M1: a config error must
87
- # never surface as 66, blamed on the agent's own cost: declaration, just because it happened on a
88
- # LATER call than the one that wrote .somi/somi-state/ceiling.json). The first call passes
89
- # --ceiling so state really exists before the config is corrupted.
90
- R67_POST="$(fresh)"; mkdir -p "$R67_POST/.somi"
91
- printf '{"cost": {"ceiling": "high"}}\n' > "$R67_POST/.somi/config.json"
92
- CLAUDE_PROJECT_DIR="$R67_POST" node "$CLI" resolve --agent somi-coder --ceiling high >/dev/null 2>&1 # persists state
93
- [ -f "$R67_POST/.somi/somi-state/ceiling.json" ] || bad "the first call did not persist a ceiling state file"
94
- printf '{"cost": {"ceiling": "high"}\n' > "$R67_POST/.somi/config.json" # now corrupt
95
- r67postrc=0
96
- CLAUDE_PROJECT_DIR="$R67_POST" node "$CLI" resolve --agent somi-coder >/dev/null 2>&1 || r67postrc=$?
97
- if [ "$r67postrc" = "67" ]; then
98
- ok "67 is reachable even AFTER state was persisted, not just on a fresh project"
99
- else
100
- bad "config corrupted after state was persisted did not reach 67 (got $r67postrc) -- may be misattributed to 66"
101
- fi
102
-
103
-
104
- # --- agents/somi.md + skills/somi-dispatch/SKILL.md's tool/argument names match the REAL
105
- # somi-mcp.mjs tools/list --------------------------------------------------------------------------
106
- # Step 4/5 now call the bundled MCP tools as their primary path (the CLI above is the fallback, only
107
- # where SoMi's own install path is already known); the RESOLVE side of that (somi_resolve's
108
- # arguments, fallback order, exit-code mapping) moved out of agents/somi.md into
109
- # skills/somi-dispatch/SKILL.md so every command that Tasks an agent directly shares it too --
110
- # agents/somi.md keeps only what's specific to the front door (somi_command, the classify/recursion
111
- # steps). So this section checks the UNION of both files: wherever a given rule now lives, it must
112
- # still be there, and it must still be derived from the REAL server, never a hand-typed second copy
113
- # of scripts/somi-mcp.mjs's TOOLS table, which is exactly the kind of copy that quietly drifts.
114
- echo "== agents/somi.md + skills/somi-dispatch/SKILL.md <-> somi-mcp.mjs tool/argument contract =="
115
-
116
- SCHEMA_JSON="$(node "$ROOT_REPO/tests/scripts/lib/somi-mcp-tool-schema.mjs" 2>/dev/null || true)"
117
- if [ -z "$SCHEMA_JSON" ] || ! node -e 'JSON.parse(process.argv[1])' "$SCHEMA_JSON" >/dev/null 2>&1; then
118
- bad "could not drive scripts/somi-mcp.mjs's real tools/list to derive its schema"
119
- else
120
- ok "drove the real MCP server to derive its tools/list schema"
121
-
122
- schema_field() { node -e '
123
- const s = JSON.parse(process.argv[1])[process.argv[2]] || {};
124
- console.log((s[process.argv[3]] || []).join(" "));
125
- ' "$SCHEMA_JSON" "$1" "$2"; }
126
-
127
- # The UNION of the front door, the skill, AND every commands/*.md file -- a command's own
128
- # dispatch-reference line now names `somi_resolve`/`somi_skill` directly (not just a link to the
129
- # skill), so a stale or invented tool name there would otherwise go unchecked: the skill/front-door
130
- # pair alone can't see a typo that only ever appears in a command file.
131
- # somi_agent is a read-only text reader that dispatch must NOT use (an agent starts as its agent_type),
132
- # so it is the one real tool the dispatch text is required to leave unnamed.
133
- REAL_TOOLS="$(node -e 'console.log(Object.keys(JSON.parse(process.argv[1])).filter((t) => t !== "somi_agent").sort().join(" "))' "$SCHEMA_JSON")"
134
- PROMPT_TOOLS="$(grep -ohE '`somi_[a-z_]+`' "$AGENT_MD" "$SKILL_MD" $COMMAND_MDS | tr -d '`' | sort -u | tr '\n' ' ' | sed 's/ *$//')"
135
- if [ "$REAL_TOOLS" = "$PROMPT_TOOLS" ]; then
136
- ok "agents/somi.md + skills/somi-dispatch/SKILL.md + the runner, general agent, checkpoint and flow skills together name exactly the server's real tools ($REAL_TOOLS)"
137
- else
138
- bad "tool-name mismatch -- server: [$REAL_TOOLS] vs agents/somi.md + skills/somi-dispatch/SKILL.md + the runner, general agent, checkpoint and flow skills: [$PROMPT_TOOLS]"
139
- fi
140
- if node -e 'process.exit(Object.keys(JSON.parse(process.argv[1])).includes("somi_agent") ? 0 : 1)' "$SCHEMA_JSON"; then
141
- ok "somi_agent still exists as a reader, and the dispatch text above names it nowhere"
142
- else
143
- bad "somi_agent disappeared from the server -- its removal needs an audit of its consumers first"
144
- fi
145
-
146
- # somi_resolve: every REAL property must be named somewhere across the two files (nothing silently
147
- # dropped) -- and every key the skill's own canonical invocation example passes must be a REAL
148
- # property (nothing invented, nothing stale).
149
- REAL_RESOLVE_PROPS="$(schema_field somi_resolve properties)"
150
- for prop in $REAL_RESOLVE_PROPS; do
151
- if grep -qE "\b${prop}\b" "$AGENT_MD" "$SKILL_MD"; then
152
- ok "somi_resolve's real argument '$prop' is named in agents/somi.md or skills/somi-dispatch/SKILL.md"
153
- else
154
- bad "somi_resolve's real argument '$prop' is never mentioned in agents/somi.md or skills/somi-dispatch/SKILL.md"
155
- fi
156
- done
157
-
158
- SNIPPET="$(cat "$AGENT_MD" "$SKILL_MD" | sed -n '/somi_resolve({ agent:/,/})/p')"
159
- if [ -z "$SNIPPET" ]; then
160
- bad "neither agents/somi.md nor skills/somi-dispatch/SKILL.md has a somi_resolve({ agent: ...}) canonical invocation example -- if the wording changed intentionally, update this test to match it"
161
- else
162
- ok "found the canonical somi_resolve invocation example (skills/somi-dispatch/SKILL.md)"
163
- SNIPPET_KEYS="$(printf '%s' "$SNIPPET" | grep -oE '[a-zA-Z_]+:' | tr -d ':' | sort -u | tr '\n' ' ' | sed 's/ *$//')"
164
- for key in $SNIPPET_KEYS; do
165
- case " $REAL_RESOLVE_PROPS " in
166
- *" $key "*) ok "the example's argument '$key' is a real somi_resolve property" ;;
167
- *) bad "the example passes '$key', which is not a real somi_resolve property" ;;
168
- esac
169
- done
170
- REAL_RESOLVE_REQUIRED="$(schema_field somi_resolve required)"
171
- for req in $REAL_RESOLVE_REQUIRED; do
172
- case " $SNIPPET_KEYS " in
173
- *" $req "*) ok "the example passes somi_resolve's required argument '$req'" ;;
174
- *) bad "somi_resolve's required argument '$req' is missing from the example" ;;
175
- esac
176
- done
177
- fi
178
-
179
- # somi_command: same shape, one required "name" argument -- stays specific to agents/somi.md
180
- # (only the front door reads a command's procedure text this way), but check both files anyway
181
- # so a future move doesn't silently drop the check.
182
- REAL_COMMAND_PROPS="$(schema_field somi_command properties)"
183
- for prop in $REAL_COMMAND_PROPS; do
184
- if grep -qE "\b${prop}\b" "$AGENT_MD" "$SKILL_MD"; then
185
- ok "somi_command's real argument '$prop' is named in agents/somi.md or skills/somi-dispatch/SKILL.md"
186
- else
187
- bad "somi_command's real argument '$prop' is never mentioned in agents/somi.md or skills/somi-dispatch/SKILL.md"
188
- fi
189
- done
190
-
191
- # somi_skill: same shape again, one required "name" argument -- checked against the UNION that
192
- # actually names it (agents/somi.md today; any commands/*.md file would also count).
193
- REAL_SKILL_PROPS="$(schema_field somi_skill properties)"
194
- for prop in $REAL_SKILL_PROPS; do
195
- if grep -qE "\b${prop}\b" "$AGENT_MD" "$SKILL_MD" $COMMAND_MDS; then
196
- ok "somi_skill's real argument '$prop' is named in agents/somi.md, skills/somi-dispatch/SKILL.md, or a command"
197
- else
198
- bad "somi_skill's real argument '$prop' is never mentioned in agents/somi.md, skills/somi-dispatch/SKILL.md, or any command"
199
- fi
200
- done
201
- fi
202
-
203
- # --- the dispatcher's known-command list is exactly commands/*.md, and each has a flow skill ------
204
- # The dispatcher recognises explicit commands from its own inline list (it reads no install files),
205
- # so a command added without the list would degrade to classification silently.
206
- known_list() { # $1 = agents/somi.md path; prints the backticked names after "Known commands:"
207
- awk '/Known commands:/{f=1} f{print} f&&/Never re-classify/{exit}' "$1" | grep -oE '`[a-z][a-z0-9-]*`' | tr -d '`' | sort -u
208
- }
209
- LISTED="$(known_list "$AGENT_MD")"
210
- REAL="$(for f in "$ROOT_REPO"/commands/*.md; do basename "$f" .md; done | sort -u)"
211
- if [ -n "$LISTED" ] && [ "$LISTED" = "$REAL" ]; then
212
- ok "agents/somi.md's known-command list equals commands/*.md ($(echo "$REAL" | wc -l) commands)"
213
- else
214
- bad "agents/somi.md's known-command list differs from commands/*.md: $(diff <(echo "$LISTED") <(echo "$REAL") | tr '\n' ' ')"
215
- fi
216
- for n in $REAL status; do
217
- [ -f "$ROOT_REPO/skills/flow-$n/SKILL.md" ] || bad "no skills/flow-$n/SKILL.md for the '$n' flow"
218
- done
219
- ok "every known flow has its skills/flow-<name>/SKILL.md"
220
- cp "$AGENT_MD" "$TMP/somi.md"; sed -i 's/`upgrade`\./`upgrade`, `bogus`./' "$TMP/somi.md"
221
- if [ "$(known_list "$TMP/somi.md")" != "$REAL" ]; then ok "red proof: an extra name in the list is caught"; else bad "red proof: an extra name in the list was not caught"; fi
222
-
223
- echo "somi agent <-> somi-dispatch.mjs dispatch contract tests: $pass ok, $fail failed"
224
- [ "$fail" -eq 0 ] || exit 1
@@ -1,286 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Guard for scripts/somi-config.mjs: show/get/set/unset/init over a project's .somi/config.json.
3
- # Checks every operation, byte-exact init, preservation of unrelated keys, the key allowlist, whole-block
4
- # validation, exit codes (64 arguments / 67 the project's files), no-follow and atomic writes, and
5
- # agreement with the resolver. The safety checks are also proven red on mutated copies of the script.
6
- set -uo pipefail
7
-
8
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
9
- CLI="$ROOT_REPO/scripts/somi-config.mjs"
10
-
11
- pass=0; fail=0
12
- ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
13
- bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
14
- check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
15
-
16
- echo "== somi-config =="
17
-
18
- TMP="$(mktemp -d)"
19
- trap 'chmod -R u+rwx "$TMP" 2>/dev/null; rm -rf "$TMP"' EXIT
20
-
21
- proj() { mktemp -d -p "$TMP"; }
22
- # $1 = cli, $2 = project, rest = args -> stdout in $TMP/out, stderr in $TMP/err, prints the exit code
23
- cfg() { local cli=$1 p=$2; shift 2; node "$cli" "$@" --project-dir "$p" > "$TMP/out" 2> "$TMP/err"; echo $?; }
24
- jf() { node -e "const o=JSON.parse(require('fs').readFileSync('$TMP/out','utf8')); const v=($1); process.stdout.write(typeof v==='string'?v:JSON.stringify(v))"; }
25
- EXPECT="$TMP/expected.json"
26
- node --input-type=module -e "const D = await import('$ROOT_REPO/scripts/lib/cost-defaults.mjs'); process.stdout.write(D.serializeDefaultConfig())" > "$EXPECT"
27
- res() { CLAUDE_PROJECT_DIR="$1" env -u SOMI_COST_CEILING node "$ROOT_REPO/scripts/somi-dispatch.mjs" resolve --agent "$2"; }
28
- fld() { node -e "process.stdout.write(String(JSON.parse(process.argv[1])[process.argv[2]]))" "$1" "$2"; }
29
- ascii_only() { LC_ALL=C grep -q -P '[^\x09\x0a\x20-\x7e]' "$1" && echo no || echo yes; }
30
-
31
- # --- init: byte-exact, no-op when present ---------------------------------------------------------
32
- P="$(proj)"
33
- check "init: exit 0" "$(cfg "$CLI" "$P" init)" "0"
34
- check "init creates exactly the text the SessionStart hook writes" "$(cmp -s "$P/.somi/config.json" "$EXPECT" && echo same)" "same"
35
- check "init output says created" "$(jf 'o.created')" "true"
36
- check ".somi was created with mode 700" "$(stat -c %a "$P/.somi")" "700"
37
- printf '{"mine":1}' > "$P/.somi/config.json"
38
- check "init over an existing file: exit 0" "$(cfg "$CLI" "$P" init)" "0"
39
- check "... a no-op, file untouched, reported created:false" "$(cat "$P/.somi/config.json")|$(jf 'o.created')" '{"mine":1}|false'
40
-
41
- # --- show -----------------------------------------------------------------------------------------
42
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
43
- check "show: exit 0" "$(cfg "$CLI" "$P" show)" "0"
44
- check "show on a fresh default config: ceiling medium from config" "$(jf 'o.ceiling')" '{"value":"medium","source":"config","from":"project"}'
45
- check "show: every shipped agent is listed with default, tier, source" "$(jf 'o.agents.length === Object.keys(JSON.parse(require("fs").readFileSync("'"$EXPECT"'","utf8")).cost.agents).length && o.agents.every((a) => a.tier === a.default && a.source === "override")')" "true"
46
- check "show: no warnings for a fresh default config" "$(jf 'o.warnings')" "[]"
47
- check "show output is one ASCII line" "$(wc -l < "$TMP/out" | tr -d ' ')|$(ascii_only "$TMP/out")" "1|yes"
48
- P="$(proj)"
49
- check "show with no config file: exists false, ceiling default medium" "$(cfg "$CLI" "$P" show)|$(jf 'o.exists')|$(jf 'o.ceiling')" '0|false|{"value":"medium","source":"default"}'
50
- check "show with no config: agents follow the ceiling, security-reviewer warning present" "$(jf 'o.agents.find((a) => a.name === "somi-security-reviewer").tier + "/" + o.agents.find((a) => a.name === "somi-security-reviewer").source')|$(jf 'o.warnings.length')" "medium/ceiling|1"
51
- check "show created nothing" "$([ -e "$P/.somi" ] && echo made || echo none)" "none"
52
-
53
- # --- cost.mapping.<host>.<tier>: the writer behind the Copilot model picker (#34, #35) ---------------
54
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
55
- check "set cost.mapping.copilot.high to a preference list: stored as an array, parsed value echoed" \
56
- "$(cfg "$CLI" "$P" set cost.mapping.copilot.high 'big-a, big-b')|$(jf 'JSON.stringify(o.value)')|$(node -e 'process.stdout.write(JSON.stringify(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).cost.mapping.copilot.high))' "$P/.somi/config.json")" \
57
- '0|["big-a","big-b"]|["big-a","big-b"]'
58
- check "... with a warning naming the tiers the host map still lacks" "$(jf 'o.warnings.some((w) => w.startsWith("cost.mapping.copilot has no low, medium entry yet"))')" "true"
59
- cfg "$CLI" "$P" set cost.mapping.copilot.low mini-x > /dev/null; cfg "$CLI" "$P" set cost.mapping.copilot.medium mid-x > /dev/null
60
- check "a single id is stored as a string; a complete host map has no incomplete-map warning" "$(cfg "$CLI" "$P" get cost.mapping.copilot.low)|$(jf 'o.value')|$(cfg "$CLI" "$P" show)|$(jf 'o.warnings.some((w) => w.includes("cost.mapping"))')" "0|mini-x|0|false"
61
- check "the resolver now enforces copilot's high tier with the first candidate" "$(CLAUDE_PROJECT_DIR="$P" env -u SOMI_COST_CEILING node "$ROOT_REPO/scripts/somi-dispatch.mjs" resolve --agent somi-designer --host copilot | node -e 'const o=JSON.parse(require("fs").readFileSync(0,"utf8")); process.stdout.write(o.model+"/"+o.enforced)')" "big-a/true"
62
- check "a remap with --refuse-lowering is refused (64) with its own message" "$(cfg "$CLI" "$P" set cost.mapping.copilot.high cheap-x --refuse-lowering)|$(grep -c 'remaps a tier to a different model' "$TMP/err")" "64|1"
63
- for v in 'bad id' 'a,a' ',' "$(printf 'm%d,' 1 2 3 4 5 6 7 8 9 | sed 's/,$//')"; do
64
- check "a bad model value is a usage error (64): $v" "$(cfg "$CLI" "$P" set cost.mapping.copilot.high "$v")" "64"
65
- done
66
- check "set on a whole host map (no tier) is a usage error (64)" "$(cfg "$CLI" "$P" set cost.mapping.copilot gpt-x)" "64"
67
- check "unset cost.mapping.copilot removes the host map" "$(cfg "$CLI" "$P" unset cost.mapping.copilot)|$(node -e 'process.stdout.write(String(JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")).cost.mapping))' "$P/.somi/config.json")" "0|undefined"
68
-
69
- # --- show --host: the unmapped-host warning (#36) --------------------------------------------------
70
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
71
- check "show --host copilot, default config (10 agents pinned high), no mapping: one unmapped warning naming the count" \
72
- "$(cfg "$CLI" "$P" show --host copilot)|$(jf 'o.warnings.filter((w) => w.startsWith("copilot has no model mapping, so 10 high-tier agent(s)")).length')" "0|1"
73
- check "show --host claude-code: shipped mapping, no unmapped warning" "$(cfg "$CLI" "$P" show --host claude-code)|$(jf 'o.warnings')" "0|[]"
74
- check "show without --host: no unmapped warning (the host is unknown)" "$(cfg "$CLI" "$P" show)|$(jf 'o.warnings')" "0|[]"
75
- node -e 'const f=process.argv[1];const c=JSON.parse(require("fs").readFileSync(f,"utf8"));c.cost.mapping={copilot:{low:"m-low",medium:"m-mid",high:"m-high"}};require("fs").writeFileSync(f,JSON.stringify(c,null,2)+"\n")' "$P/.somi/config.json"
76
- check "show --host copilot with cost.mapping.copilot set: no unmapped warning" "$(cfg "$CLI" "$P" show --host copilot)|$(jf 'o.warnings')" "0|[]"
77
- P="$(proj)"; mkdir -p "$P/.somi"
78
- printf '{"cost":{"ceiling":"low"}}\n' > "$P/.somi/config.json"
79
- check "show --host copilot where nothing resolves high: no unmapped warning" "$(cfg "$CLI" "$P" show --host copilot)|$(jf 'o.warnings.some((w) => w.includes("no model mapping"))')" "0|false"
80
- check "--host on set is a usage error (64)" "$(cfg "$CLI" "$P" set cost.ceiling high --host copilot)" "64"
81
- check "--host with a bad name is a usage error (64)" "$(cfg "$CLI" "$P" show --host 'Co pilot')" "64"
82
-
83
- # --- get / set / unset ----------------------------------------------------------------------------
84
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
85
- check "get cost.ceiling" "$(cfg "$CLI" "$P" get cost.ceiling)|$(jf 'o.value + "/" + o.source')" "0|medium/config"
86
- check "get cost.agents.somi-coder" "$(cfg "$CLI" "$P" get cost.agents.somi-coder)|$(jf 'o.value + "/" + o.source')" "0|medium/override"
87
- check "get cost.agents.nobody -> null" "$(cfg "$CLI" "$P" get cost.agents.nobody)|$(jf 'o.value + "/" + o.source')" "0|null/none"
88
- check "set cost.ceiling low" "$(cfg "$CLI" "$P" set cost.ceiling low)|$(jf 'o.changed')" "0|true"
89
- out="$(res "$P" somi-coder)"
90
- check "resolver agrees: the new ceiling is live, coder (pinned medium) stays medium" "$(fld "$out" ceiling)/$(fld "$out" tier)" "low/medium"
91
- cfg "$CLI" "$P" set cost.agents.somi-designer low > /dev/null
92
- out="$(res "$P" somi-designer)"
93
- check "resolver agrees: set cost.agents.somi-designer low -> low/override" "$(fld "$out" tier)/$(fld "$out" tier_source)" "low/override"
94
- cfg "$CLI" "$P" set cost.agents.somi-designer high > /dev/null
95
- out="$(res "$P" somi-designer)"
96
- check "resolver agrees: set cost.agents.somi-designer high -> high/override (above the low ceiling)" "$(fld "$out" tier)/$(fld "$out" tier_source)" "high/override"
97
- check "set to the same value is a no-op (changed false)" "$(cfg "$CLI" "$P" set cost.agents.somi-designer high)|$(jf 'o.changed')" "0|false"
98
- cfg "$CLI" "$P" unset cost.agents.somi-designer > /dev/null
99
- out="$(res "$P" somi-designer)"
100
- check "unset removes the pin: designer follows the ceiling" "$(fld "$out" tier)/$(fld "$out" tier_source)" "low/ceiling"
101
- check "unset of an absent entry succeeds with changed:false" "$(cfg "$CLI" "$P" unset cost.agents.somi-designer)|$(jf 'o.changed')" "0|false"
102
- check "no temp file is left behind" "$(ls -A "$P/.somi" | tr '\n' ' ')" "config.json "
103
- P2="$(proj)"; cfg "$CLI" "$P2" set cost.ceiling high > /dev/null
104
- check "set on an absent config starts from the default file (pins exist) with the change applied" "$(node -e "const a=JSON.parse(require('fs').readFileSync('$P2/.somi/config.json','utf8')), d=JSON.parse(require('fs').readFileSync('$EXPECT','utf8')); d.cost.ceiling='high'; process.stdout.write(String(JSON.stringify(a)===JSON.stringify(d)))")" "true"
105
- P2="$(proj)"
106
- check "unset on an absent config is a no-op: changed false, nothing created" "$(cfg "$CLI" "$P2" unset cost.agents.somi-coder)|$(jf 'o.changed')|$([ -e "$P2/.somi" ] && echo made || echo none)" "0|false|none"
107
- P2="$(proj)"; cfg "$CLI" "$P2" init > /dev/null; sleep 1; before="$(stat -c '%i %Y' "$P2/.somi/config.json")"
108
- check "unset of an absent entry writes nothing (inode and mtime unchanged)" "$(cfg "$CLI" "$P2" unset cost.agents.nobody)|$(jf 'o.changed')|$(stat -c '%i %Y' "$P2/.somi/config.json")" "0|false|$before"
109
-
110
- # --- preservation and ordering --------------------------------------------------------------------
111
- P="$(proj)"; mkdir "$P/.somi"
112
- printf '%s' '{"zeta":{"keep":[1,2,{"a":null}]},"loop":{"max":3},"cost":{"mapping":{},"ceiling":"high","agents":{"somi-coder":"low"}},"alpha":"x"}' > "$P/.somi/config.json"
113
- cfg "$CLI" "$P" set cost.agents.somi-planner medium > /dev/null
114
- check "unrelated and unknown top-level keys are preserved, key order is stable, new entry appended" \
115
- "$(node -e "const o=JSON.parse(require('fs').readFileSync('$P/.somi/config.json','utf8')); process.stdout.write(Object.keys(o).join()+'|'+Object.keys(o.cost).join()+'|'+Object.keys(o.cost.agents).join()+'|'+JSON.stringify(o.zeta)+o.alpha+o.loop.max)")" \
116
- 'zeta,loop,cost,alpha|mapping,ceiling,agents|somi-coder,somi-planner|{"keep":[1,2,{"a":null}]}x3'
117
- check "file is 2-space JSON with a trailing newline" "$(head -c 3 "$P/.somi/config.json" | tr '\n' '$')|$(tail -c 2 "$P/.somi/config.json" | od -An -c | tr -d ' ')" '{$ |}\n'
118
- printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; chmod 600 "$P/.somi/config.json"
119
- cfg "$CLI" "$P" set cost.ceiling low > /dev/null
120
- check "an existing file's mode is kept" "$(stat -c %a "$P/.somi/config.json")" "600"
121
-
122
- # --- warnings --------------------------------------------------------------------------------------
123
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
124
- check "set security-reviewer low: succeeds with the fixed warning" "$(cfg "$CLI" "$P" set cost.agents.somi-security-reviewer low)|$(jf 'o.warnings')" '0|["somi-security-reviewer runs below high; pin it with: set cost.agents.somi-security-reviewer high"]'
125
- check "show carries the same warning" "$(cfg "$CLI" "$P" show)|$(jf 'o.warnings.length')" "0|1"
126
- check "set security-reviewer back to high clears it" "$(cfg "$CLI" "$P" set cost.agents.somi-security-reviewer high)|$(jf 'o.warnings')" "0|[]"
127
- check "set an agent not in the default table: accepted, unknown warning" "$(cfg "$CLI" "$P" set cost.agents.my-agent high)|$(jf 'o.warnings.length')" "0|1"
128
- cfg "$CLI" "$P" show > /dev/null
129
- check "show flags the extra name unknown:true with no default" "$(jf 'JSON.stringify(o.agents.find((a) => a.name === "my-agent"))')" '{"name":"my-agent","tier":"high","source":"override","from":"project","default":null,"unknown":true}'
130
-
131
- # --- 64: arguments ---------------------------------------------------------------------------------
132
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null; cp "$P/.somi/config.json" "$TMP/before"
133
- for args in "set cost.mapping.x low" "set cost.foo low" "set loop.max 3" "set cost.ceiling turbo" "set cost.agents.somi-coder turbo" "set cost.agents.Bad_Name low" "set cost.agents.constructor low" "set cost.agents.__proto__ low" "unset cost.ceiling" "unset loop" "get loop.max" "set cost.ceiling" "frobnicate" "show extra" "set cost.ceiling low --bogus x"; do
134
- # shellcheck disable=SC2086
135
- rc="$(cfg "$CLI" "$P" $args)"
136
- check "bad input exits 64 and prints nothing on stdout: $args" "$rc|$(wc -c < "$TMP/out" | tr -d ' ')" "64|0"
137
- done
138
- check "none of those changed the file" "$(cmp -s "$P/.somi/config.json" "$TMP/before" && echo same)" "same"
139
- check "a project dir that is not a directory exits 64" "$(node "$CLI" show --project-dir "$TMP/no-such-dir" > /dev/null 2>&1; echo $?)" "64"
140
- check "error output is ASCII and does not echo a raw hostile key" "$(cfg "$CLI" "$P" set "$(printf 'cost.\xe2\x80\xaeevil\nx')" low)|$(ascii_only "$TMP/err")" "64|yes"
141
-
142
- # --- 67: the project's files -----------------------------------------------------------------------
143
- bad_cfg() { # $1 = label, $2 = body
144
- P="$(proj)"; mkdir "$P/.somi"; printf '%s' "$2" > "$P/.somi/config.json"
145
- rc="$(cfg "$CLI" "$P" set cost.ceiling low)"
146
- check "$1: set exits 67, file untouched" "$rc|$(cat "$P/.somi/config.json")" "67|$2"
147
- check "$1: show exits 67 too" "$(cfg "$CLI" "$P" show)" "67"
148
- }
149
- bad_cfg "invalid JSON" '{ not json'
150
- bad_cfg "a JSON array" '[1]'
151
- bad_cfg "an unknown cost key" '{"cost":{"cieling":"low"}}'
152
- bad_cfg "a bad tier in the existing file" '{"cost":{"agents":{"somi-coder":"turbo"}}}'
153
- bad_cfg "a bad ceiling value in the existing file" '{"cost":{"ceiling":"turbo"}}'
154
- bad_cfg "a top-level ceiling" '{"ceiling":"low"}'
155
- P="$(proj)"; mkdir "$P/.somi"; head -c 70000 /dev/zero | tr '\0' ' ' > "$P/.somi/config.json"; printf '{}' >> "$P/.somi/config.json"; cp "$P/.somi/config.json" "$TMP/big.before"
156
- check "an oversize config exits 67, untouched" "$(cfg "$CLI" "$P" set cost.ceiling low)|$(cmp -s "$P/.somi/config.json" "$TMP/big.before" && echo same)" "67|same"
157
- check "error text does not echo file text" "$(P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"cieling":"SECRET-VALUE"}}' > "$P/.somi/config.json"; cfg "$CLI" "$P" show > /dev/null; grep -c SECRET-VALUE "$TMP/err" | tr -d ' ')" "0"
158
-
159
- # --- links: writes never follow one, reads (show, get) do -----------------------------------------
160
- echo KEEP > "$TMP/victim.txt"; OUTSIDE="$(mktemp -d -p "$TMP")"
161
- P="$(proj)"; ln -s "$OUTSIDE" "$P/.somi"
162
- for op in "set cost.ceiling low" "unset cost.agents.somi-coder" init; do
163
- # shellcheck disable=SC2086
164
- check "a symlinked .somi: $op exits 67" "$(cfg "$CLI" "$P" $op)" "67"
165
- done
166
- check "... nothing was written outside" "$(ls -A "$OUTSIDE" | wc -l | tr -d ' ')" "0"
167
- check "a symlinked .somi: show reads through it (a junction on Windows)" "$(cfg "$CLI" "$P" show)|$(jf 'o.exists')" "0|false"
168
- SHARED="$(mktemp -d -p "$TMP")"; printf '{"cost":{"ceiling":"low"}}' > "$SHARED/config.json"; P="$(proj)"; ln -s "$SHARED" "$P/.somi"
169
- check "... and reads the config behind it" "$(cfg "$CLI" "$P" show)|$(jf 'o.ceiling.value')" "0|low"
170
- check "... get too" "$(cfg "$CLI" "$P" get cost.ceiling)|$(jf 'o.value')" "0|low"
171
- P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$TMP/real.json"; ln -s "$TMP/real.json" "$P/.somi/config.json"
172
- check "a symlinked config.json: show reads through it" "$(cfg "$CLI" "$P" show)|$(jf 'o.ceiling.value')" "0|high"
173
- check "a symlinked config.json: set exits 67" "$(cfg "$CLI" "$P" set cost.ceiling low)" "67"
174
- check "... the link target is untouched" "$(cat "$TMP/real.json")" '{"cost":{"ceiling":"high"}}'
175
- check "init over a symlinked config.json is a no-op (it exists)" "$(cfg "$CLI" "$P" init)|$(jf 'o.created')" "0|false"
176
- P="$(proj)"; mkdir "$P/.somi"; ln -s "$TMP/not-there.json" "$P/.somi/config.json"
177
- check "init over a dangling symlink is a no-op, nothing created through it" "$(cfg "$CLI" "$P" init)|$([ -e "$TMP/not-there.json" ] && echo made || echo none)" "0|none"
178
- P="$(proj)"; mkdir -p "$P/.somi/config.json"
179
- check "config.json as a directory: set exits 67" "$(cfg "$CLI" "$P" set cost.ceiling low)" "67"
180
-
181
- # --- atomic: a failing write leaves the original and no temp file -----------------------------------
182
- if [ "$(id -u)" -eq 0 ]; then
183
- echo " skip read-only .somi cases: running as root, chmod does not stop root"
184
- else
185
- P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; chmod 555 "$P/.somi"
186
- check "an unwritable .somi: set exits 67" "$(cfg "$CLI" "$P" set cost.ceiling low)" "67"
187
- check "... the original is intact and no temp file exists" "$(cat "$P/.somi/config.json")|$(ls -A "$P/.somi" | tr '\n' ' ')" '{"cost":{"ceiling":"high"}}|config.json '
188
- chmod 755 "$P/.somi"
189
- fi
190
-
191
- # --- a rewrite must not lose data or exceed what the reader accepts ------------------------------------
192
- exact() { # $1 = total bytes of a 2-space config {pad, cost.ceiling low}
193
- node -e "const mk=(n)=>JSON.stringify({pad:'x'.repeat(n),cost:{ceiling:'low'}},null,2)+'\n'; const base=mk(0).length; process.stdout.write(mk($1-base))"
194
- }
195
- P="$(proj)"; mkdir "$P/.somi"; exact 65535 > "$P/.somi/config.json"
196
- check "a rewrite that lands exactly on the 64 KiB limit succeeds and the result is readable" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(stat -c %s "$P/.somi/config.json")|$(cfg "$CLI" "$P" show)" "0|65536|0"
197
- P="$(proj)"; mkdir "$P/.somi"; exact 65536 > "$P/.somi/config.json"; cp "$P/.somi/config.json" "$TMP/lim.before"
198
- check "a rewrite one byte over the limit is refused (67), file untouched" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(cmp -s "$P/.somi/config.json" "$TMP/lim.before" && echo same)" "67|same"
199
- P="$(proj)"; mkdir "$P/.somi"; node -e "const n=20000; require('fs').writeFileSync('$P/.somi/config.json', '{\"deep\":'+'['.repeat(n)+']'.repeat(n)+',\"cost\":{\"ceiling\":\"low\"}}')"; cp "$P/.somi/config.json" "$TMP/deep.before"
200
- check "20000-deep unrelated nesting: set exits 67 with one line, no stack trace, file untouched" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(wc -l < "$TMP/err" | tr -d ' ')|$(grep -c ' at ' "$TMP/err" | tr -d ' ')|$(cmp -s "$P/.somi/config.json" "$TMP/deep.before" && echo same)" "67|1|0|same"
201
- for spec in 'big integer|{"big":12345678901234567890,"cost":{"ceiling":"low"}}' 'out-of-range number|{"f":1e400,"cost":{"ceiling":"low"}}' 'duplicate key|{"a":1,"a":2,"cost":{"ceiling":"low"}}' 'nested duplicate key|{"o":{"k":1,"k":2},"cost":{"ceiling":"low"}}' 'duplicate inside cost|{"cost":{"ceiling":"low","ceiling":"high"}}'; do
202
- label="${spec%%|*}"; body="${spec#*|}"
203
- P="$(proj)"; mkdir "$P/.somi"; printf '%s' "$body" > "$P/.somi/config.json"
204
- check "$label: set exits 67 and the file is untouched" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(cat "$P/.somi/config.json")" "67|$body"
205
- check "$label: show still works (read-only)" "$(cfg "$CLI" "$P" show)" "0"
206
- done
207
- P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"s":"a,\"k\": 12345678901234567890 {","n":1.0,"safe":9007199254740991,"cost":{"ceiling":"low"}}' > "$P/.somi/config.json"
208
- check "numbers and duplicates inside strings, safe integers and 1.0 do not trigger the refusal" "$(cfg "$CLI" "$P" set cost.ceiling high)|$(node -e "const o=JSON.parse(require('fs').readFileSync('$P/.somi/config.json','utf8')); process.stdout.write(o.s+'|'+o.safe+'|'+o.n+'|'+o.cost.ceiling)")" '0|a,"k": 12345678901234567890 {|9007199254740991|1|high'
209
-
210
- # --- the ceiling the resolver would use ---------------------------------------------------------------------
211
- envcfg() { local p=$1; shift; env SOMI_COST_CEILING="$ENVV" node "$CLI" "$@" --project-dir "$p" > "$TMP/out" 2> "$TMP/err"; echo $?; }
212
- P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"
213
- ENVV=low
214
- check "SOMI_COST_CEILING outranks the config: effective ceiling low from env, tiers follow it, warnings say why" "$(envcfg "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')|$(jf 'o.agents.find((a) => a.name === "somi-coder").tier')|$(jf 'o.warnings.length')|$(jf 'o.ceiling.value')" '0|{"value":"low","source":"env"}|low|2|high'
215
- check "set reports the effective ceiling too" "$(envcfg "$P" set cost.agents.somi-coder medium)|$(jf 'o.effective_ceiling.source')|$(jf 'o.warnings.length')" "0|env|2"
216
- ENVV=turbo
217
- check "an invalid SOMI_COST_CEILING is exit 64" "$(envcfg "$P" show)" "64"
218
- P="$(proj)"; mkdir -p "$P/.somi/somi-state"; printf '%s' '{}' > "$P/.somi/config.json"; printf '%s' '{"ceiling":"low","ceiling_origin":"cli"}' > "$P/.somi/somi-state/ceiling.json"
219
- check "a persisted cli ceiling is in force when the config sets none: source state, with its warning" "$(cfg "$CLI" "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')|$(jf 'o.warnings.length')" '0|{"value":"low","source":"state"}|2'
220
- printf '%s' '{"ceiling":"low","ceiling_origin":"config"}' > "$P/.somi/somi-state/ceiling.json"
221
- check "a persisted ceiling that was not set by a flag or env is ignored: default medium" "$(cfg "$CLI" "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')" '0|{"value":"medium","source":"default"}'
222
- printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; printf '%s' '{"ceiling":"low","ceiling_origin":"cli"}' > "$P/.somi/somi-state/ceiling.json"
223
- check "the config outranks a persisted ceiling" "$(cfg "$CLI" "$P" show)|$(jf 'JSON.stringify(o.effective_ceiling)')" '0|{"value":"high","source":"config"}'
224
- out="$(CLAUDE_PROJECT_DIR="$P" env -u SOMI_COST_CEILING node "$ROOT_REPO/scripts/somi-dispatch.mjs" resolve --agent somi-coder)"
225
- check "and the resolver agrees with that" "$(fld "$out" ceiling)/$(fld "$out" ceiling_source)" "high/config"
226
- P="$(proj)"; mkdir -p "$P/.somi/somi-state"; printf '%s' '{}' > "$P/.somi/config.json"; printf '{ bad' > "$P/.somi/somi-state/ceiling.json"
227
- check "a corrupt state file is exit 67 for show" "$(cfg "$CLI" "$P" show)" "67"
228
-
229
- # --- small behaviours ------------------------------------------------------------------------------------------
230
- P="$(proj)"
231
- check "a new file honours the umask (umask 077 -> mode 600)" "$( (umask 077; node "$CLI" init --project-dir "$P" > /dev/null 2>&1); stat -c %a "$P/.somi/config.json")" "600"
232
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
233
- check "the agent name somi is accepted without the not-a-shipped-agent warning" "$(cfg "$CLI" "$P" set cost.agents.somi low)|$(jf 'o.warnings.filter((w) => /not a shipped/.test(w)).length')" "0|0"
234
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
235
- check "no temp file is left behind after many writes" "$(for t in low medium high low; do cfg "$CLI" "$P" set cost.ceiling $t > /dev/null; done; ls -A "$P/.somi" | tr '\n' ' ')" "config.json "
236
-
237
- # --- red proofs on mutated copies --------------------------------------------------------------------
238
- mut() { # $1 = name, $2 = file (relative to scripts/), $3 = exact text, $4 = replacement
239
- local d="$TMP/$1"; mkdir -p "$d/scripts"; [ -d "$d/scripts/lib" ] || cp -r "$ROOT_REPO/scripts/lib" "$d/scripts/lib"; cp "$CLI" "$d/scripts/"
240
- M_FILE="$d/scripts/$2" M_FROM="$3" M_TO="$4" node -e "const f=process.env.M_FILE,fs=require('fs'),s=fs.readFileSync(f,'utf8');if(!s.includes(process.env.M_FROM))process.exit(3);fs.writeFileSync(f,s.replace(process.env.M_FROM,()=>process.env.M_TO))" || bad "mutant $1 did not apply"
241
- }
242
- mut_more() { M_FILE="$TMP/$1/scripts/$2" M_FROM="$3" M_TO="$4" node -e "const f=process.env.M_FILE,fs=require('fs'),s=fs.readFileSync(f,'utf8');if(!s.includes(process.env.M_FROM))process.exit(3);fs.writeFileSync(f,s.replace(process.env.M_FROM,()=>process.env.M_TO))" || bad "mutant $1 (second edit) did not apply"; }
243
- mut allowlist lib/cost-config-edit.mjs "if (!m) throw new EditError(" "if (false) throw new EditError("
244
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
245
- rc="$(cfg "$TMP/allowlist/scripts/somi-config.mjs" "$P" set cost.bogus.x low)"
246
- if [ "$rc" != 64 ]; then ok "red proof: without the key allowlist a bad key is no longer a clean 64 (rc $rc)"; else bad "red proof: allowlist mutant still gives 64"; fi
247
- mut wholeblock somi-config.mjs "checkCost(next.cost, (m) => usage(m));" ""
248
- P="$(proj)"; cfg "$CLI" "$P" init > /dev/null
249
- rc="$(cfg "$TMP/wholeblock/scripts/somi-config.mjs" "$P" set cost.agents.constructor low)"
250
- if [ "$rc" = 0 ] && grep -q constructor "$P/.somi/config.json"; then ok "red proof: without whole-block validation a forbidden agent name is written"; else bad "red proof: whole-block mutant did not write (rc $rc)"; fi
251
- mut nofollow-dir somi-config.mjs "if (d && !d.isDirectory()) project(" "if (false) project("
252
- mut_more nofollow-dir somi-config.mjs "if (!loc.dirStat?.isDirectory()) project(" "if (false) project("
253
- mut_more nofollow-dir somi-config.mjs "if (!now || !now.isDirectory() || now.dev !== loc.dirStat.dev || now.ino !== loc.dirStat.ino) project(" "if (false) project("
254
- P="$(proj)"; OUTSIDE="$(mktemp -d -p "$TMP")"; ln -s "$OUTSIDE" "$P/.somi"
255
- cfg "$TMP/nofollow-dir/scripts/somi-config.mjs" "$P" init > /dev/null
256
- if [ -e "$OUTSIDE/config.json" ]; then ok "red proof: without the .somi link check init writes through the link"; else bad "red proof: no-follow (.somi) mutant wrote nothing"; fi
257
- mut nofollow-cfg lib/cost-ceiling.mjs "| (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0)" "| (fs.constants.O_NONBLOCK ?? 0)"
258
- P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$TMP/real2.json"; ln -s "$TMP/real2.json" "$P/.somi/config.json"
259
- rc="$(cfg "$TMP/nofollow-cfg/scripts/somi-config.mjs" "$P" set cost.ceiling low)"
260
- if [ "$rc" = 0 ]; then ok "red proof: without O_NOFOLLOW a symlinked config.json is read through (set succeeds instead of exit 67)"; else bad "red proof: no-follow (config.json) mutant still refused"; fi
261
- mut sizecap somi-config.mjs "if (Buffer.byteLength(text) > MAX_CONFIG_BYTES) project(" "if (false) project("
262
- P="$(proj)"; mkdir "$P/.somi"; exact 65536 > "$P/.somi/config.json"
263
- rc="$(cfg "$TMP/sizecap/scripts/somi-config.mjs" "$P" set cost.ceiling high)"
264
- if [ "$rc" = 0 ] && [ "$(stat -c %s "$P/.somi/config.json")" -gt 65536 ]; then ok "red proof: without the size check a file its own reader rejects is written"; else bad "red proof: size-cap mutant (rc $rc)"; fi
265
- mut hazard somi-config.mjs "if (why) project(" "if (false) project("
266
- P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"big":12345678901234567890,"cost":{"ceiling":"low"}}' > "$P/.somi/config.json"
267
- rc="$(cfg "$TMP/hazard/scripts/somi-config.mjs" "$P" set cost.ceiling high)"
268
- if [ "$rc" = 0 ] && ! grep -q 12345678901234567890 "$P/.somi/config.json"; then ok "red proof: without the hazard check a big integer is silently rewritten"; else bad "red proof: hazard mutant (rc $rc)"; fi
269
- mut absent lib/cost-config-edit.mjs "const next = absent ? buildDefaultConfig() : cfg;" "const next = cfg ?? {};"
270
- P="$(proj)"; rc="$(cfg "$TMP/absent/scripts/somi-config.mjs" "$P" set cost.ceiling high)"
271
- if [ "$rc" = 0 ] && [ "$(node -e "console.log(JSON.parse(require('fs').readFileSync('$P/.somi/config.json','utf8')).cost.agents === undefined)")" = true ]; then ok "red proof: without starting from the defaults a set on an absent file loses the pins"; else bad "red proof: absent mutant (rc $rc)"; fi
272
- mut envrank somi-config.mjs "if (env !== undefined && env !== '') {" "if (false) {"
273
- P="$(proj)"; mkdir "$P/.somi"; printf '%s' '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"
274
- ENVV=low; env SOMI_COST_CEILING=low node "$TMP/envrank/scripts/somi-config.mjs" show --project-dir "$P" > "$TMP/out" 2>/dev/null
275
- if [ "$(jf 'o.effective_ceiling.source')" = config ]; then ok "red proof: without reading SOMI_COST_CEILING the effective ceiling ignores it"; else bad "red proof: env mutant"; fi
276
- if [ "$(id -u)" -ne 0 ]; then
277
- mut atomic somi-config.mjs "fd = fs.openSync(tmp, WRITE_FLAGS, 0o644);" "fs.writeFileSync(loc.file, text); return true;"
278
- P="$(proj)"; mkdir "$P/.somi"; printf '{"cost":{"ceiling":"high"}}' > "$P/.somi/config.json"; chmod 555 "$P/.somi"
279
- rc="$(cfg "$TMP/atomic/scripts/somi-config.mjs" "$P" set cost.ceiling low)"
280
- if [ "$rc" = 0 ]; then ok "red proof: a direct (non-temp-file) write succeeds where the atomic one refuses"; else bad "red proof: atomic mutant still failed (rc $rc)"; fi
281
- chmod 755 "$P/.somi"
282
- fi
283
-
284
- echo "somi-config tests: $pass ok, $fail failed"
285
- [ "$fail" -eq 0 ] || exit 1
286
- node "$ROOT_REPO/tests/scripts/lib/somi-mcp-config-tests.mjs" || exit 1