@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,255 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Unit guard for scripts/lib/cost-ceiling.mjs: the session cost ceiling.
3
- #
4
- # Exercises: re-resolution per dispatch across separate process invocations (state lives on disk,
5
- # not in memory), a bare .somi/config.json edit cannot move a ceiling already recorded,
6
- # hard-cap selection (no override: the ceiling tier itself, whatever was declared; the declared set
7
- # only feeds `degraded`; the old never-degrade rule is reversed), and a
8
- # malformed ceiling or declared set — from config, an env var, or an explicit argument — dying loudly
9
- # instead of silently disabling the ceiling.
10
- set -uo pipefail
11
-
12
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
13
- LIB="$ROOT_REPO/scripts/lib/cost-ceiling.mjs"
14
-
15
- pass=0; fail=0
16
- ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
17
- bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
18
- check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
19
-
20
- # Runs a snippet with the module imported as `C` and `ROOT` bound to a throwaway directory.
21
- run() { node --input-type=module -e "const C = await import('$LIB'); const ROOT = '$1'; $2"; }
22
- expect_exit() { # $1 = name, $2 = expected exit code, $3 = root, $4 = snippet
23
- local name="$1" want="$2" root="$3" snippet="$4" got=0
24
- run "$root" "$snippet" >/dev/null 2>&1 || got=$?
25
- if [ "$got" = "$want" ]; then ok "$name"; else bad "$name (expected exit $want, got $got)"; fi
26
- }
27
-
28
- echo "== cost ceiling =="
29
-
30
- TMP="$(mktemp -d)"
31
- trap 'rm -rf "$TMP"' EXIT
32
-
33
- # State file helper: prints the persisted state as compact JSON, or "none".
34
- state() { run "$1" 'const fs = await import("node:fs"); const f = C.ceilingStatePath(ROOT); process.stdout.write(fs.existsSync(f) ? fs.readFileSync(f, "utf8") : "none")'; }
35
- res() { run "$1" 'const r = C.resolveCeiling(ROOT, undefined); process.stdout.write([r.ceiling, r.overridden, r.source, r.ceiling_origin].join(","))'; }
36
-
37
- # --- nothing set: the built-in default is medium, and nothing is written ------------------------
38
- A="$TMP/a"; mkdir -p "$A/.somi"
39
- check "no config, no state, no env, no arg: medium, from the default" "$(res "$A")" "medium,false,default,default"
40
- check "... and a resolve with nothing explicit writes no state file" "$(state "$A")" "none"
41
- check "DEFAULT_CEILING is medium" "$(run "$A" 'process.stdout.write(C.DEFAULT_CEILING)')" "medium"
42
-
43
- # --- config is read LIVE: an edit between two resolves moves the ceiling -------------------------
44
- B="$TMP/b"; mkdir -p "$B/.somi"
45
- printf '{"cost": {"ceiling": "low"}}\n' > "$B/.somi/config.json"
46
- check "config's cost.ceiling is honoured" "$(res "$B")" "low,false,config,config"
47
- printf '{"cost": {"ceiling": "high"}}\n' > "$B/.somi/config.json"
48
- check "a bare config edit moves the ceiling on the very next resolve (config is live)" "$(res "$B")" "high,false,config,config"
49
- printf '{}\n' > "$B/.somi/config.json"
50
- check "removing cost.ceiling from the config falls back to the default" "$(res "$B")" "medium,false,default,default"
51
- check "config-only resolves never write state" "$(state "$B")" "none"
52
-
53
- # --- CLI/env beat config, and are persisted with their origin ------------------------------------
54
- printf '{"cost": {"ceiling": "low"}}\n' > "$B/.somi/config.json"
55
- out="$(SOMI_COST_CEILING=high node --input-type=module -e "const C = await import('$LIB'); const r = C.resolveCeiling('$B', undefined); process.stdout.write(r.ceiling+','+r.overridden+','+r.source+','+r.override.field+','+r.override.from+','+r.override.to+','+r.override.source)")"
56
- check "env value beats config, and the override record names what was in force" "$out" "high,true,env,ceiling,low,high,env"
57
- check "the override was persisted with origin env and a one-entry ceiling_overrides" \
58
- "$(run "$B" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write([s.ceiling, s.ceiling_origin, s.ceiling_overrides.length, s.ceiling_overrides[0].source].join(","))')" \
59
- "high,env,1,env"
60
-
61
- # Config OUTRANKS a persisted cli/env ceiling (it is live; state only fills in when config is silent).
62
- check "persisted env ceiling is outranked by cost.ceiling in config (config > persisted state)" \
63
- "$(res "$B")" "low,false,config,config"
64
- printf '{}\n' > "$B/.somi/config.json"
65
- check "with config silent, the persisted env ceiling stands: source state, origin env" \
66
- "$(res "$B")" "high,false,state,env"
67
- printf '{"cost": {"ceiling": "low"}}\n' > "$B/.somi/config.json"
68
- check "no duplicate override entry was recorded by the bare calls" \
69
- "$(run "$B" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(String(s.ceiling_overrides.length))')" \
70
- "1"
71
-
72
- # --- an explicit argument beats an env var set in the SAME call ---------------------------------
73
- out="$(SOMI_COST_CEILING=low node --input-type=module -e "const C = await import('$LIB'); const r = C.resolveCeiling('$B', 'medium'); process.stdout.write(r.ceiling+','+r.override.source+','+r.override.from+','+r.ceiling_origin)")"
74
- check "explicit argument wins over env, is recorded with source cli; from is the ceiling in force" "$out" "medium,cli,low,cli"
75
- check "an explicit CLI value matching what config gives still reports source cli and persists origin cli" \
76
- "$(run "$B" 'const r = C.resolveCeiling(ROOT, "low"); process.stdout.write([r.overridden, r.source, r.ceiling_origin].join(","))')" \
77
- "false,cli,cli"
78
- check "... the persisted origin is now cli" \
79
- "$(run "$B" 'const fs = await import("node:fs"); process.stdout.write(JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")).ceiling_origin)')" "cli"
80
- out="$(SOMI_COST_CEILING=low node --input-type=module -e "const C = await import('$LIB'); process.stdout.write(C.resolveCeiling('$B', undefined).source)")"
81
- check "an explicit env var: source is 'env'" "$out" "env"
82
-
83
- # --- a persisted ceiling that was NOT set by cli/env yields to config and to the default ---------
84
- STATES="$TMP/states"
85
- for spec in 'legacy|{"ceiling":"high"}' 'default-origin|{"ceiling":"high","ceiling_origin":"default"}' 'config-origin|{"ceiling":"high","ceiling_origin":"config"}'; do
86
- name="${spec%%|*}"; body="${spec#*|}"
87
- d="$STATES-$name"; mkdir -p "$d/.somi/somi-state"; printf '%s' "$body" > "$d/.somi/somi-state/ceiling.json"
88
- check "$name fixture was written" "$(state "$d")" "$body"
89
- check "$name state (high) yields to the medium default" "$(res "$d")" "medium,false,default,default"
90
- printf '{"cost": {"ceiling": "low"}}\n' > "$d/.somi/config.json"
91
- check "$name state (high) yields to config low" "$(res "$d")" "low,false,config,config"
92
- rm "$d/.somi/config.json"
93
- done
94
- # A state file written before origins were recorded: just {"ceiling":"high"}.
95
- LEG="$TMP/legacy-literal"; mkdir -p "$LEG/.somi/somi-state"; printf '{"ceiling":"high"}' > "$LEG/.somi/somi-state/ceiling.json"
96
- check "the legacy fixture really holds high" "$(state "$LEG")" '{"ceiling":"high"}'
97
- check "a legacy state file does not outrank the default" "$(res "$LEG")" "medium,false,default,default"
98
- d="$STATES-cli"; mkdir -p "$d/.somi/somi-state"; printf '{"ceiling":"low","ceiling_origin":"cli"}' > "$d/.somi/somi-state/ceiling.json"
99
- check "a cli-origin state (low) does apply when config is silent" "$(res "$d")" "low,false,state,cli"
100
- printf '{"cost": {"ceiling": "high"}}\n' > "$d/.somi/config.json"
101
- check "... and config high outranks it" "$(res "$d")" "high,false,config,config"
102
- d="$STATES-yield-write"; mkdir -p "$d/.somi/somi-state"; printf '{"ceiling":"high"}' > "$d/.somi/somi-state/ceiling.json"
103
- run "$d" 'C.resolveCeiling(ROOT, undefined)' >/dev/null
104
- check "a yielding legacy state file is left untouched by a bare resolve" "$(state "$d")" '{"ceiling":"high"}'
105
- check "an explicit value persists over a legacy state file, with origin" \
106
- "$(run "$d" 'C.resolveCeiling(ROOT, "low"); const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(s.ceiling + "," + s.ceiling_origin + "," + s.ceiling_overrides[0].from)')" \
107
- "low,cli,medium"
108
-
109
- check "a present state file with an invalid (not merely absent) ceiling_origin value dies loudly" \
110
- "$(run "$STATES-yield-write" 'const fs = await import("node:fs"); fs.writeFileSync(C.ceilingStatePath(ROOT), JSON.stringify({ceiling:"low",ceiling_origin:"bogus"})); try { C.resolveCeiling(ROOT, undefined); process.stdout.write("no"); } catch { process.stdout.write("threw"); }')" \
111
- "threw"
112
- check "config-stale is gone: no resolve ever reports it" \
113
- "$(run "$B" 'process.stdout.write(String(JSON.stringify(C.resolveCeiling(ROOT, undefined)).includes("stale")))')" "false"
114
-
115
- # --- an UNPARSABLE state file (bad JSON, not just a wrong shape) dies loudly and names the file --
116
- STATE_BROKEN="$TMP/state-broken"; mkdir -p "$STATE_BROKEN/.somi/somi-state"
117
- printf '{"ceiling": "low"\n' > "$STATE_BROKEN/.somi/somi-state/ceiling.json" # missing closing brace
118
- expect_exit "an unparsable state file dies loudly rather than a bare uncaught SyntaxError" 1 \
119
- "$STATE_BROKEN" 'C.resolveCeiling(ROOT, undefined)'
120
- check "the unparsable-state error names the ceiling.json file path, not a bare JSON position" \
121
- "$(run "$STATE_BROKEN" 'try { C.resolveCeiling(ROOT, undefined); } catch (e) { process.stdout.write(String(e.message.includes("ceiling.json"))); }')" \
122
- "true"
123
- SYMS="$TMP/state-symlink"; mkdir -p "$SYMS/.somi/somi-state"; printf '{"ceiling":"low","ceiling_origin":"cli"}' > "$SYMS/real.json"
124
- ln -s ../../real.json "$SYMS/.somi/somi-state/ceiling.json"
125
- expect_exit "a symlinked state file is refused rather than followed" 1 "$SYMS" 'C.resolveCeiling(ROOT, undefined)'
126
-
127
- # --- malformed values die loudly, never silently defang the ceiling -----------------------------
128
- M="$TMP/m"; mkdir -p "$M/.somi"
129
- run "$M" 'C.resolveCeiling(ROOT, "low")' >/dev/null; run "$M" 'C.resolveCeiling(ROOT, "high")' >/dev/null
130
- expect_exit "a malformed explicit argument is rejected (uncaught, not swallowed)" 1 \
131
- "$M" 'C.resolveCeiling(ROOT, "unlimited")'
132
- expect_exit "a malformed env var is rejected" 1 \
133
- "$M" 'process.env.SOMI_COST_CEILING = "unlimited"; C.resolveCeiling(ROOT, undefined)'
134
- check "a rejected malformed value leaves the on-disk ceiling and override count untouched" \
135
- "$(run "$M" 'const fs = await import("node:fs"); const s = JSON.parse(fs.readFileSync(C.ceilingStatePath(ROOT), "utf8")); process.stdout.write(s.ceiling + "," + s.ceiling_overrides.length)')" \
136
- "high,2"
137
-
138
- CFG="$TMP/c"; mkdir -p "$CFG/.somi"
139
- printf '{"cost": {"ceiling": "unlimited"}}\n' > "$CFG/.somi/config.json"
140
- expect_exit "a malformed config-sourced ceiling dies loudly" 1 \
141
- "$CFG" 'C.resolveCeiling(ROOT, undefined)'
142
- check "a failed config read leaves no state file behind" \
143
- "$(run "$CFG" 'const fs = await import("node:fs"); process.stdout.write(String(fs.existsSync(C.ceilingStatePath(ROOT))))')" \
144
- "false"
145
-
146
- # --- a wrong-shaped `cost` container fails closed, not open to the loosest ceiling --------------
147
- SHAPE1="$TMP/shape1"; mkdir -p "$SHAPE1/.somi"; printf '{"cost": "low"}' > "$SHAPE1/.somi/config.json"
148
- expect_exit "a cost key that is a string, not an object, dies loudly rather than defaulting" 1 \
149
- "$SHAPE1" 'C.resolveCeiling(ROOT, undefined)'
150
- SHAPE2="$TMP/shape2"; mkdir -p "$SHAPE2/.somi"; printf '{"cost": {"celing": "low"}}' > "$SHAPE2/.somi/config.json"
151
- expect_exit "a typo'd key inside cost dies loudly rather than falling back to the default" 1 \
152
- "$SHAPE2" 'C.resolveCeiling(ROOT, undefined)'
153
- SHAPE3="$TMP/shape3"; mkdir -p "$SHAPE3/.somi"; printf '{"ceiling": "low"}' > "$SHAPE3/.somi/config.json"
154
- expect_exit "a ceiling key at the top level (outside cost) dies loudly, not silently ignored" 1 \
155
- "$SHAPE3" 'C.resolveCeiling(ROOT, undefined)'
156
-
157
- # --- an UNPARSABLE config.json (bad JSON, not just a wrong shape) dies loudly too, never {} ------
158
- BROKEN="$TMP/broken"; mkdir -p "$BROKEN/.somi"
159
- printf '{"cost": {"ceiling": "low"}\n' > "$BROKEN/.somi/config.json" # missing closing brace
160
- expect_exit "an unparsable config.json dies loudly rather than silently resolving to {}" 1 \
161
- "$BROKEN" 'C.resolveCeiling(ROOT, undefined)'
162
- broken_out="$(run "$BROKEN" 'C.resolveCeiling(ROOT, undefined); process.stdout.write("SHOULD-NOT-PRINT")' 2>/dev/null)"
163
- check "an unparsable config.json produces no stdout before dying" "$broken_out" ""
164
- check "the unparsable-config error names the config file path" \
165
- "$(run "$BROKEN" 'try { C.resolveCeiling(ROOT, undefined); } catch (e) { process.stdout.write(String(e.message.includes("config.json"))); }')" \
166
- "true"
167
- check "an unparsable config leaves no state file behind" \
168
- "$(run "$BROKEN" 'const fs = await import("node:fs"); process.stdout.write(String(fs.existsSync(C.ceilingStatePath(ROOT))))')" \
169
- "false"
170
-
171
- # --- a present state file with a semantically corrupt ceiling dies loudly, not silently ---------
172
- CORRUPT="$TMP/corrupt"; mkdir -p "$CORRUPT/.somi/somi-state"
173
- printf '{}' > "$CORRUPT/.somi/somi-state/ceiling.json"
174
- expect_exit "a present state file missing its ceiling key dies loudly" 1 \
175
- "$CORRUPT" 'C.resolveCeiling(ROOT, undefined)'
176
- check "the thrown message names the state file, not a flag or env var" \
177
- "$(run "$CORRUPT" 'try { C.resolveCeiling(ROOT, undefined); } catch (e) { process.stdout.write(String(e.message.includes("ceiling.json"))); }')" \
178
- "true"
179
-
180
- # --- decideDispatch: the ceiling is a HARD cap. With no override the selected tier IS the ceiling,
181
- # whatever the unit declared; the declared set (a capability set) is echoed in `supported` and used
182
- # only to compute `degraded`. A bare string is a one-member set. The old never-degrade rule (run at
183
- # the cheapest declared member when none fits) is reversed. Override / source cases: cost-hardcap.sh.
184
- # Each case prints action,selected,supported,degraded,tier_source.
185
- dd() { run "$B" "const d = C.decideDispatch($1); process.stdout.write([d.action, d.selected, d.supported.join('|'), d.degraded, d.tier_source].join(','))"; }
186
-
187
- check "one-member set under a higher ceiling: runs at the ceiling, not degraded" \
188
- "$(dd '"low", "high"')" "allow,high,low,false,ceiling"
189
- check "single-high declaration under a medium ceiling: clamped to medium, degraded" \
190
- "$(dd '"high", "medium"')" "allow,medium,high,true,ceiling"
191
- check "single-high declaration under a low ceiling: clamped to low, degraded" \
192
- "$(dd '["high"], "low"')" "allow,low,high,true,ceiling"
193
- check "two-member set [medium,high], ceiling low: clamped to low, below every declared member" \
194
- "$(dd '["medium","high"], "low"')" "allow,low,medium|high,true,ceiling"
195
- check "two-member set [medium,high], ceiling medium: medium, degraded (below its highest member)" \
196
- "$(dd '["medium","high"], "medium"')" "allow,medium,medium|high,true,ceiling"
197
- check "two-member set [medium,high], ceiling high: high, not degraded" \
198
- "$(dd '["medium","high"], "high"')" "allow,high,medium|high,false,ceiling"
199
- check "three-member set, ceiling low: low, degraded" \
200
- "$(dd '["low","medium","high"], "low"')" "allow,low,low|medium|high,true,ceiling"
201
- check "three-member set, ceiling medium: medium, degraded" \
202
- "$(dd '["low","medium","high"], "medium"')" "allow,medium,low|medium|high,true,ceiling"
203
- check "three-member set, ceiling high: high, not degraded" \
204
- "$(dd '["low","medium","high"], "high"')" "allow,high,low|medium|high,false,ceiling"
205
-
206
- # Sweep: without an override, selected is exactly the ceiling for every set x ceiling; the selected
207
- # tier may be outside the declared set, and degraded is exactly "selected below the top member".
208
- check "no override: selected === ceiling and degraded matches rank, across every set x ceiling" \
209
- "$(run "$B" 'const sets=[["low"],["medium"],["high"],["low","medium"],["medium","high"],["low","high"],["low","medium","high"]]; const R={low:0,medium:1,high:2}; let bad=0; for (const s of sets) for (const c of ["low","medium","high"]) { const d=C.decideDispatch(s,c); if (d.action!=="allow"||d.selected!==c||d.tier_source!=="ceiling") bad++; if (d.degraded !== (R[c] < R[s[s.length-1]])) bad++; } process.stdout.write(String(bad))')" \
210
- "0"
211
-
212
- check "the decision object is frozen -- a caller cannot rewrite the selection after the fact" \
213
- "$(run "$B" 'const d = C.decideDispatch(["low","high"], "high"); try { d.selected = "low"; } catch {} process.stdout.write(d.selected)')" \
214
- "high"
215
- check "the supported array itself is frozen too, not just the decision object wrapping it" \
216
- "$(run "$B" 'const d = C.decideDispatch(["low","high"], "high"); const before = d.supported.length; try { d.supported.push("medium"); } catch {} process.stdout.write(String(d.supported.length === before))')" \
217
- "true"
218
- check "the allow shape carries exactly action, ceiling, degraded, selected, supported, tier_source" \
219
- "$(run "$B" 'process.stdout.write(Object.keys(C.decideDispatch(["low","high"], "high")).sort().join("|"))')" \
220
- "action|ceiling|degraded|selected|supported|tier_source"
221
- expect_exit "an unrecognized cost value throws rather than silently allowing" 1 \
222
- "$B" 'C.decideDispatch("critical", "high")'
223
- expect_exit "an unrecognized ceiling value throws rather than silently allowing" 1 \
224
- "$B" 'C.decideDispatch("low", "critical")'
225
- expect_exit "an unordered declared set (high before medium) throws rather than being silently sorted" 1 \
226
- "$B" 'C.decideDispatch(["high","medium"], "high")'
227
- expect_exit "a duplicate in the declared set throws" 1 \
228
- "$B" 'C.decideDispatch(["medium","medium"], "high")'
229
- expect_exit "an empty declared set throws rather than resolving to no-capability-silently" 1 \
230
- "$B" 'C.decideDispatch([], "high")'
231
-
232
- # --- modelForDispatch: the sanctioned composition from a decideDispatch decision ----------------
233
- check "modelForDispatch resolves the model for the SELECTED tier, not just any declared member" \
234
- "$(run "$B" 'process.stdout.write(C.modelForDispatch(C.decideDispatch(["low","medium"],"medium"), "claude-code"))')" \
235
- "sonnet"
236
- check "modelForDispatch on a one-member set resolves the CEILING tier's model (hard cap), not the member's" \
237
- "$(run "$B" 'process.stdout.write(C.modelForDispatch(C.decideDispatch("low","high"), "claude-code"))')" \
238
- "opus"
239
- check "modelForDispatch follows an override above the ceiling" \
240
- "$(run "$B" 'process.stdout.write(C.modelForDispatch(C.decideDispatch("low","low","high"), "claude-code"))')" \
241
- "opus"
242
- # decideDispatch itself can only produce "allow" -- the guard is unreachable by construction, but it
243
- # is still exercised directly against a hand-built non-allow shape, so the backstop stays proven.
244
- expect_exit "modelForDispatch refuses a decision shaped as anything but allow" 1 \
245
- "$B" 'C.modelForDispatch({ action: "refuse", supported: ["high"], ceiling: "low" }, "claude-code")'
246
- expect_exit "modelForDispatch refuses a missing decision" 1 \
247
- "$B" 'C.modelForDispatch(undefined, "claude-code")'
248
-
249
- echo "cost ceiling tests: $pass ok, $fail failed"
250
- [ "$fail" -eq 0 ] || exit 1
251
- bash "$(dirname "${BASH_SOURCE[0]}")/cost-hardcap.sh" || exit 1
252
- bash "$(dirname "${BASH_SOURCE[0]}")/ensure-default-config.sh" || exit 1
253
- bash "$(dirname "${BASH_SOURCE[0]}")/somi-config.sh" || exit 1
254
- bash "$(dirname "${BASH_SOURCE[0]}")/cost-lowering.sh" || exit 1
255
- bash "$(dirname "${BASH_SOURCE[0]}")/agent-model-frontmatter.sh" || exit 1
@@ -1,130 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Guard for the default tier table (scripts/lib/cost-defaults.mjs), the one source of each agent's tier:
3
- # - the table lists exactly the agents/*.md files, minus the exempt front-door `somi` (existence, both
4
- # directions);
5
- # - no agents/*.md or commands/*.md declares `cost:` (the real check from scripts/validate.sh, extracted
6
- # from a copy of it and run over fixtures, so this proves that block's own logic).
7
- # Each check is also proven red: a copy of the table with one row removed or added, and fixtures that
8
- # declare `cost:`, must fail the same comparison.
9
- set -uo pipefail
10
-
11
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
12
- LIB_SRC="$ROOT_REPO/scripts/lib"
13
-
14
- pass=0; fail=0
15
- ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
16
- bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
17
- check() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
18
-
19
- echo "== cost defaults =="
20
-
21
- TMP="$(mktemp -d)"
22
- trap 'rm -rf "$TMP"' EXIT
23
-
24
- # Prints the agent names (agents/*.md minus the exempt `somi`), sorted.
25
- agent_files() { for f in "$1"/*.md; do n="$(basename "$f" .md)"; [ "$n" = somi ] || printf '%s\n' "$n"; done | sort; }
26
- # Prints the table's agent names for the lib dir given, sorted.
27
- table_names() {
28
- node --input-type=module -e "
29
- const D = await import('$1/cost-defaults.mjs');
30
- for (const k of Object.keys(D.AGENT_DEFAULT_TIERS)) console.log(k);" | sort
31
- }
32
-
33
- EXPECT="$(agent_files "$ROOT_REPO/agents")"
34
- [ -n "$EXPECT" ] || bad "no agent file was found"
35
- check "the table lists exactly the agent files (minus the exempt somi)" "$(table_names "$LIB_SRC")" "$EXPECT"
36
-
37
- # The tier values themselves: a literal expected list (changing a tier is a deliberate edit here).
38
- EXPECT_TIERS="somi-architecture-reviewer:high
39
- somi-atlas:high
40
- somi-coder:medium
41
- somi-designer:high
42
- somi-discovery-analyst:high
43
- somi-flow:medium
44
- somi-general:medium
45
- somi-impact:medium
46
- somi-incident:medium
47
- somi-plan-reviewer:high
48
- somi-planner:medium
49
- somi-pr:medium
50
- somi-refactor-designer:high
51
- somi-refactorer:medium
52
- somi-reviewer:high
53
- somi-sdlc-reviewer:high
54
- somi-security-reviewer:high
55
- somi-test-strategist:high"
56
- table_tiers() {
57
- node --input-type=module -e "
58
- const D = await import('$1/cost-defaults.mjs');
59
- for (const [k, v] of Object.entries(D.AGENT_DEFAULT_TIERS)) console.log(k + ':' + v);" | sort
60
- }
61
- EXPECT_TIERS="$(printf '%s\n' "$EXPECT_TIERS" | sort)"
62
- check "the table's name:tier list equals the literal expected list" "$(table_tiers "$LIB_SRC")" "$EXPECT_TIERS"
63
-
64
- # Red proofs on copies of the lib.
65
- mutant() { # $1 = name, $2 = sed expression
66
- mkdir -p "$TMP/$1"; cp "$LIB_SRC"/cost-*.mjs "$TMP/$1/"; sed -i "$2" "$TMP/$1/cost-defaults.mjs"
67
- cmp -s "$LIB_SRC/cost-defaults.mjs" "$TMP/$1/cost-defaults.mjs" && bad "mutant $1 did not change the file"
68
- }
69
- mutant tier-changed "s/^ 'somi-coder': 'medium',/ 'somi-coder': 'high',/"
70
- mutant row-removed "/^ 'somi-atlas': 'high',/d"
71
- mutant row-added "s/^ 'somi-atlas': 'high',/ 'somi-atlas': 'high',\n 'somi-ghost': 'low',/"
72
- if [ "$(table_tiers "$TMP/tier-changed")" != "$EXPECT_TIERS" ]; then ok "red proof: the tier list check fails for tier-changed"; else bad "red proof: a changed tier went unnoticed"; fi
73
- for m in row-removed row-added; do
74
- if [ "$(table_names "$TMP/$m")" != "$EXPECT" ]; then ok "red proof: existence check fails for $m"; else bad "red proof: existence check still holds for $m"; fi
75
- done
76
- mkdir -p "$TMP/agents-extra"; cp "$ROOT_REPO"/agents/*.md "$TMP/agents-extra/"; printf -- '---\nname: extra\n---\n' > "$TMP/agents-extra/extra.md"
77
- if [ "$(agent_files "$TMP/agents-extra")" != "$(table_names "$LIB_SRC")" ]; then ok "red proof: an agent file with no table row fails the check"; else bad "red proof: an unlisted agent file went unnoticed"; fi
78
-
79
- # No agent or command declares `cost:` -- the real block from scripts/validate.sh, over fixtures.
80
- HELPER="$(awk '/^fm_has\(\) \{/{c=1} c{print} c&&/^\}$/{exit}' "$ROOT_REPO/scripts/validate.sh")"
81
- BLOCK="$(awk '/^cost_failed=0$/{c=1} c{print} c&&/^done$/{exit}' "$ROOT_REPO/scripts/validate.sh")"
82
- if [ -z "$HELPER" ] || [ -z "$BLOCK" ]; then bad "could not extract the cost check from scripts/validate.sh -- its markers may have moved"; else
83
- SNIPPET="$HELPER"$'\n'"$BLOCK"$'\nexit $cost_failed'
84
- fx() { (cd "$1" && bash -c "$SNIPPET" 2>"$1/err"); echo $?; }
85
- mkdir -p "$TMP/fx-ok/agents" "$TMP/fx-ok/commands" "$TMP/fx-agent/agents" "$TMP/fx-agent/commands" "$TMP/fx-cmd/agents" "$TMP/fx-cmd/commands" "$TMP/fx-crlf/agents" "$TMP/fx-crlf/commands"
86
- printf -- '---\nname: x\ndescription: d\n---\nbody line: cost: high\n' > "$TMP/fx-ok/agents/x.md"
87
- printf -- '---\ndescription: d\n---\nbody\n' > "$TMP/fx-ok/commands/c.md"
88
- for d in fx-agent fx-cmd fx-crlf; do cp "$TMP/fx-ok/agents/x.md" "$TMP/$d/agents/x.md"; cp "$TMP/fx-ok/commands/c.md" "$TMP/$d/commands/c.md"; done
89
- printf -- '---\nname: x\ncost: medium, high\n---\n' > "$TMP/fx-agent/agents/x.md"
90
- printf -- '---\ndescription: d\ncost: high\n---\n' > "$TMP/fx-cmd/commands/c.md"
91
- printf -- '---\r\nname: x\r\ncost: high\r\n---\r\n' > "$TMP/fx-crlf/agents/x.md"
92
- check "an agent and a command without a frontmatter cost: pass (a body line is not frontmatter)" "$(fx "$TMP/fx-ok")" "0"
93
- check "red proof: an agent declaring cost: fails" "$(fx "$TMP/fx-agent")" "1"
94
- check "red proof: a command declaring cost: fails" "$(fx "$TMP/fx-cmd")" "1"
95
- check "red proof: a CRLF agent declaring cost: fails" "$(fx "$TMP/fx-crlf")" "1"
96
- grep -q "agents/x.md declares cost:" "$TMP/fx-agent/err" && ok "the message names the offending file" || bad "message wrong: $(cat "$TMP/fx-agent/err")"
97
- n="$(awk 'FNR==1{c=0} /^---$/{c++} c==1 && /^cost:/{print FILENAME; nextfile}' "$ROOT_REPO"/agents/*.md "$ROOT_REPO"/commands/*.md | wc -l)"
98
- check "no shipped agent or command declares cost:" "$n" "0"
99
- fi
100
-
101
- # The shape of the default config.
102
- node --input-type=module -e "
103
- const D = await import('$LIB_SRC/cost-defaults.mjs');
104
- const C = await import('$LIB_SRC/cost-ceiling.mjs');
105
- const V = await import('$LIB_SRC/cost-config.mjs');
106
- const cfg = D.buildDefaultConfig();
107
- const out = [];
108
- out.push(['ceiling is the built-in default', cfg.cost.ceiling === C.DEFAULT_CEILING && D.DEFAULT_CEILING_TIER === C.DEFAULT_CEILING]);
109
- out.push(['validates through the shared validator', (() => { try { V.validateCostConfig(cfg.cost); return true; } catch { return false; } })()]);
110
- out.push(['agents are sorted by name', Object.keys(cfg.cost.agents).join() === Object.keys(cfg.cost.agents).sort().join()]);
111
- out.push(['the table is frozen and null-prototype', Object.isFrozen(D.AGENT_DEFAULT_TIERS) && Object.getPrototypeOf(D.AGENT_DEFAULT_TIERS) === null]);
112
- out.push(['serialization is stable and is JSON, 2-space indent, trailing newline', D.serializeDefaultConfig() === D.serializeDefaultConfig() && D.serializeDefaultConfig() === JSON.stringify(cfg, null, 2) + '\n' && D.serializeDefaultConfig().endsWith('}\n')]);
113
- out.push(['serialization round-trips to the same object', JSON.stringify(JSON.parse(D.serializeDefaultConfig())) === JSON.stringify(cfg)]);
114
- out.push(['the somi front-door agent is not listed', !('somi' in D.AGENT_DEFAULT_TIERS)]);
115
- out.push(['a bad table row is rejected', (() => { try { D.buildDefaultConfig({ 'somi-coder': 'turbo' }); return false; } catch { return true; } })()]);
116
- out.push(['a bad agent name is rejected', (() => { try { D.buildDefaultConfig({ 'Bad_Name': 'low' }); return false; } catch { return true; } })()]);
117
- for (const [n, v] of out) console.log((v ? 'ok' : 'FAIL') + '\t' + n);" > "$TMP/shape.out" 2>&1
118
- while IFS=$'\t' read -r s n; do case "$s" in ok) ok "$n" ;; FAIL) bad "$n" ;; *) bad "unexpected output: $s $n" ;; esac; done < "$TMP/shape.out"
119
-
120
- # No model names anywhere in the file or its output: the pattern comes from the shipped mapping.
121
- PATTERN="$(node --input-type=module -e "
122
- const M = await import('$LIB_SRC/cost-model.mjs');
123
- console.log(Object.values(M.HOST_MODELS).flatMap((h) => Object.values(h)).join('|'))")"
124
- if [ -n "$PATTERN" ] && ! grep -qiE "$PATTERN" "$LIB_SRC/cost-defaults.mjs" \
125
- && ! node --input-type=module -e "const D = await import('$LIB_SRC/cost-defaults.mjs'); process.stdout.write(D.serializeDefaultConfig())" | grep -qiE "$PATTERN"; then
126
- ok "no model name in the table file or in the serialized config"
127
- else bad "a model name appears in the table file or the serialized config"; fi
128
-
129
- echo "cost defaults tests: $pass ok, $fail failed"
130
- [ "$fail" -eq 0 ] || exit 1