@skathio/somi 4.1.1 → 5.0.1

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 +88 -227
  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 +29 -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 +44 -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 +167 -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 +97 -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 +58 -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 +182 -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,392 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Behavioral fixture runner for the deterministic guardrail hooks.
3
- #
4
- # Each file in tests/hooks/cases/<name>.json declares the hook script it
5
- # exercises plus a list of cases:
6
- #
7
- # {
8
- # "script": "pre-tool/block-dangerous-bash.sh",
9
- # "cases": [
10
- # { "name": "rm-rf-root", "expect": "deny",
11
- # "expect_reason": "rm -rf /",
12
- # "payload": { "tool_name": "Bash", "tool_input": { "command": "rm -rf /" } } },
13
- # { "name": "opted-in", "expect": "allow",
14
- # "env": { "SOMI_ALLOW_DEP_INSTALL": "1" },
15
- # "payload": { ... } },
16
- # { "name": "config-allowlisted", "expect": "allow",
17
- # "config": { "dep_install": { "allow": ["@types/"] } },
18
- # "payload": { ... } },
19
- # { "name": "surfaces-context", "expect_context": "somi repo-awareness",
20
- # "files": { "AGENTS.md": "# repo instructions\n" },
21
- # "payload": { ... } }
22
- # ]
23
- # }
24
- #
25
- # Case fields beyond "expect" (PreToolUse allow/deny):
26
- # - "files": an object mapping a path (relative to the case's throwaway
27
- # CLAUDE_PROJECT_DIR) to file content, written before the hook runs — for
28
- # hooks that read repo-local files (e.g. detect-repo-instructions.sh's
29
- # AGENTS.md/CLAUDE.md scan). Mirrors the "config" → .somi/config.json
30
- # staging below, generalized to arbitrary relative paths. Keys are
31
- # rejected (case FAILS loudly) if they contain a ".." path segment or a
32
- # leading "/" — such a key would otherwise escape the case dir.
33
- # - "setup_git": true — initializes a real git repo in the case dir (`git
34
- # init -b main`, a throwaway commit identity, `git add -A` + an
35
- # `--allow-empty` commit of whatever "files" staged) before the hook
36
- # runs — for hooks that shell out to `git diff`/`git status` (e.g.
37
- # inject-workflow-context.sh's loose-end nudges). The commit gives those
38
- # hooks a real HEAD to diff against even when "files" staged nothing.
39
- # - "dirty_files": like "files", but written *after* the "setup_git"
40
- # baseline commit — so a new path lands untracked (visible in `git status
41
- # --porcelain` as `??`) and an overwritten already-committed path lands
42
- # modified-unstaged (visible in `git diff HEAD`). Same unsafe-key guard as
43
- # "files". Meaningless without "setup_git" (no git repo to be dirty in).
44
- # - "prime": true — runs the hook once beforehand (same sanitized env and
45
- # payload as the real run below), discarding its output but still failing
46
- # the case loudly if that priming invocation errors, so a hook whose
47
- # behavior depends on its own prior invocation (e.g.
48
- # inject-workflow-context.sh's signature-gated re-emission, which reads a
49
- # state file the hook itself wrote last time) can be tested against its
50
- # *second* call rather than its first. Note: this reuses the case's audit
51
- # log path, so pairing "prime" with an audit-log assertion on a hook that
52
- # writes audit lines would double-count; harmless for hooks (like
53
- # inject-workflow-context.sh) that never call somi::audit.
54
- # - "files_after_prime": like "files", but written after the priming
55
- # invocation and before the real one — for perturbing whatever state the
56
- # prior invocation just persisted (e.g. adding a new
57
- # .somi/reviews/*/*.md so a signature computed from directory-listing
58
- # mtimes changes deterministically, with no sleep/timing dependency,
59
- # rather than relying on touching an existing file's mtime). Only
60
- # meaningful alongside "prime".
61
- # - A payload, or a value inside "env", may reference the literal token
62
- # "{{CASE_DIR}}", substituted with the case's absolute throwaway-dir path
63
- # before the hook runs — for hooks that check real absolute paths (e.g.
64
- # lint-changed-files.sh's `[[ -f "$PATH_INPUT" ]]`, or
65
- # inject-workflow-context.mjs's pluginRoot() reading CLAUDE_PLUGIN_ROOT /
66
- # SOMI_VENDOR_ROOT), so a case can point at a file staged via "files"
67
- # without hardcoding a path the hook's own CWD wouldn't resolve.
68
- # - "expect_context": asserted as a substring of
69
- # `.hookSpecificOutput.additionalContext` — for PostToolUse/UserPromptSubmit/
70
- # SessionStart hooks that surface context instead of a permission decision.
71
- # Independent of "expect"; a case may declare either, both, or (paired with
72
- # "expect": "deny") "expect_reason" as well. There is deliberately no
73
- # Stop-event (`decision`-shape) assertion path — no Stop hooks are wired in
74
- # hooks.json today, so that shape would be untested speculative scope.
75
- # - "expect_no_context": true — asserts `.hookSpecificOutput.additionalContext`
76
- # is absent/empty — for PostToolUse hooks whose current behavior is a
77
- # documented no-op (e.g. lint-changed-files.sh with no configured linter).
78
- # - "expect_context_excludes": asserted as a substring that must NOT appear
79
- # in `.hookSpecificOutput.additionalContext` — the negative complement to
80
- # "expect_context", for a hook that emits *some* context (so
81
- # "expect_no_context" doesn't apply — a plain substring match on the part
82
- # that IS present can't rule out something else silently being appended
83
- # alongside it) but where one specific piece of content must be absent
84
- # (e.g. inject-workflow-context.sh still prints its standing reminder
85
- # block on an unrelated branch, but a particular work-item hint inside
86
- # that block must not appear for this case's staged input).
87
- # - "expect_reason": asserted as a substring of
88
- # `.hookSpecificOutput.permissionDecisionReason` on deny cases — catches a
89
- # hook that still denies (so `expect: deny` alone would pass) but whose
90
- # matched/interpolated text drifted, e.g. an ERE→RegExp port that shifts
91
- # *which* substring a pattern captures.
92
- # - "expect_audit_log": asserted as a substring of the case's audit-log file
93
- # (see below) — for hooks whose only observable effect is the audit-log
94
- # side-effect (audit-log.sh emits no stdout decision at all).
95
- # - "expect_no_audit_log": true — asserts the case's audit-log file was never
96
- # created (e.g. audit-log.sh's no-tool_name early exit).
97
- #
98
- # A case that declares none of the seven recognized assertion fields above
99
- # runs the hook and passes vacuously (a typo'd field name would silently
100
- # produce a meaningless green case) — the runner fails such a case loudly
101
- # instead.
102
- #
103
- # The runner pipes each payload into the script under a sanitized environment
104
- # (session opt-ins unset unless the case sets them; CLAUDE_PLUGIN_ROOT and
105
- # SOMI_VENDOR_ROOT are also unset unless the case sets them — otherwise
106
- # whatever's ambient in the environment running `npm test` would leak into
107
- # pluginRoot()'s fixture cases, phase 1 iteration 1.2; SOMI_AUDIT_LOG defaults
108
- # to a per-case throwaway file, "$case_dir/audit.log", so audit writes never
109
- # leak across cases; CLAUDE_PROJECT_DIR points at the same throwaway per-case
110
- # dir, into which the optional `config` object is written as .somi/config.json)
111
- # and asserts every expectation the case declares.
112
- #
113
- # Wired into scripts/validate.sh (npm test) — CI fails when a pattern change
114
- # weakens a guarantee. If you change a hook pattern, add or update a fixture.
115
-
116
- set -euo pipefail
117
-
118
- ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
119
- CASES_DIR="$ROOT/tests/hooks/cases"
120
- TMP="$(mktemp -d)"
121
- trap 'rm -rf "$TMP"' EXIT
122
-
123
- total=0
124
- failures=0
125
-
126
- # Reject "files" staging keys that could escape the per-case throwaway dir: a
127
- # ".." path segment (anywhere in the path, not just a bare prefix) or a
128
- # leading "/". Fixture keys are maintainer-committed, not attacker-controlled,
129
- # but a typo should fail the case loudly rather than silently write outside
130
- # case_dir.
131
- is_unsafe_staging_key() {
132
- local key="$1"
133
- [[ "$key" == /* ]] && return 0
134
- local part
135
- local IFS='/'
136
- for part in $key; do
137
- [[ "$part" == ".." ]] && return 0
138
- done
139
- return 1
140
- }
141
-
142
- # Writes cases[$idx].$field (an object mapping relative path -> content) into
143
- # $dir, one file per key, validating every key via is_unsafe_staging_key first
144
- # (shared by "files", "dirty_files", and "files_after_prime" — same shape,
145
- # different write timing). Prints a FAIL line and returns 1 on an unsafe key
146
- # (caller must count a failure and skip the case); returns 0 otherwise,
147
- # including when the field is absent/empty.
148
- stage_case_files() {
149
- local case_file="$1" idx="$2" dir="$3" field="$4" script_rel="$5" name="$6"
150
- local rel_path
151
- while IFS= read -r rel_path; do
152
- [[ -z "$rel_path" ]] && continue
153
- if is_unsafe_staging_key "$rel_path"; then
154
- echo "FAIL: [$script_rel] $name — unsafe \"$field\" key escapes the case dir: $rel_path" >&2
155
- return 1
156
- fi
157
- mkdir -p "$dir/$(dirname "$rel_path")"
158
- jq -r --argjson idx "$idx" --arg key "$rel_path" ".cases[\$idx].$field[\$key]" "$case_file" \
159
- > "$dir/$rel_path"
160
- done < <(jq -r ".cases[$idx].$field // {} | keys[]" "$case_file")
161
- return 0
162
- }
163
-
164
- for case_file in "$CASES_DIR"/*.json; do
165
- script_rel="$(jq -r '.script' "$case_file")"
166
- script="$ROOT/hooks/$script_rel"
167
- # Dispatch by extension (node-runtime-port phase 2, iteration 2.1): a
168
- # ".mjs" hook is invoked via `node "$script"`; a ".sh" hook stays a direct
169
- # exec, as before. This lets a single hook flip to its .mjs port (by
170
- # changing the fixture's "script" field) without disturbing any other
171
- # fixture still pointed at ".sh" — no hook is deleted until Phase 3.
172
- #
173
- # The executable-bit precondition is relaxed to the ".sh" branch only: a
174
- # ".mjs" file invoked via `node "$script"` doesn't need an exec bit, and
175
- # the exec bit doesn't exist on Windows — the exact host this work item
176
- # targets. The ".mjs" branch checks readability instead.
177
- case "$script_rel" in
178
- *.mjs)
179
- if [[ ! -r "$script" ]]; then
180
- echo "FAIL: $(basename "$case_file") — hook script missing or not readable: hooks/$script_rel" >&2
181
- failures=$((failures + 1))
182
- continue
183
- fi
184
- cmd=(node "$script")
185
- ;;
186
- *)
187
- if [[ ! -x "$script" ]]; then
188
- echo "FAIL: $(basename "$case_file") — hook script missing or not executable: hooks/$script_rel" >&2
189
- failures=$((failures + 1))
190
- continue
191
- fi
192
- cmd=("$script")
193
- ;;
194
- esac
195
-
196
- count="$(jq '.cases | length' "$case_file")"
197
- for ((i = 0; i < count; i++)); do
198
- total=$((total + 1))
199
- name="$(jq -r ".cases[$i].name" "$case_file")"
200
- expect="$(jq -r ".cases[$i].expect // empty" "$case_file")"
201
- expect_context="$(jq -r ".cases[$i].expect_context // empty" "$case_file")"
202
- expect_reason="$(jq -r ".cases[$i].expect_reason // empty" "$case_file")"
203
- expect_no_context="$(jq -r ".cases[$i].expect_no_context // false" "$case_file")"
204
- expect_context_excludes="$(jq -r ".cases[$i].expect_context_excludes // empty" "$case_file")"
205
- expect_audit_log="$(jq -r ".cases[$i].expect_audit_log // empty" "$case_file")"
206
- expect_no_audit_log="$(jq -r ".cases[$i].expect_no_audit_log // false" "$case_file")"
207
- has_assertion="$(jq -r ".cases[$i] | (has(\"expect\") or has(\"expect_context\") or has(\"expect_reason\") or has(\"expect_no_context\") or has(\"expect_context_excludes\") or has(\"expect_audit_log\") or has(\"expect_no_audit_log\"))" "$case_file")"
208
- payload="$(jq -c ".cases[$i].payload" "$case_file")"
209
-
210
- # Sanitized environment: session opt-ins never leak in from the caller;
211
- # audit-log writes land in a per-case throwaway file, not the repo's
212
- # .somi/; the project root is a per-case temp dir so .somi/config.json
213
- # is case-controlled.
214
- case_dir="$TMP/case-$total"
215
- mkdir -p "$case_dir"
216
- # {{CASE_DIR}} in the payload resolves to this case's absolute throwaway
217
- # dir, for hooks that check real absolute paths (see header comment).
218
- payload="${payload//\{\{CASE_DIR\}\}/$case_dir}"
219
- config="$(jq -c ".cases[$i].config // empty" "$case_file")"
220
- if [[ -n "$config" ]]; then
221
- mkdir -p "$case_dir/.somi"
222
- printf '%s' "$config" > "$case_dir/.somi/config.json"
223
- fi
224
- # Arbitrary file staging: a case may declare "files": { "rel/path": "content" }
225
- # to be written into the case dir before the hook runs (e.g. AGENTS.md for
226
- # detect-repo-instructions.sh). Generalizes the config staging above.
227
- # Keys are validated (no ".." segment, no leading "/") before any write.
228
- if ! stage_case_files "$case_file" "$i" "$case_dir" "files" "$script_rel" "$name"; then
229
- failures=$((failures + 1))
230
- continue
231
- fi
232
-
233
- # "setup_git": true — real git repo in the case dir, with whatever
234
- # "files" staged committed as its baseline, so hooks that shell out to
235
- # `git diff`/`git status` (e.g. inject-workflow-context.sh) have a real
236
- # HEAD to compare against.
237
- setup_git="$(jq -r ".cases[$i].setup_git // false" "$case_file")"
238
- if [[ "$setup_git" == "true" ]]; then
239
- git -C "$case_dir" init -q -b main
240
- git -C "$case_dir" config user.email "somi-fixture@test.local"
241
- git -C "$case_dir" config user.name "somi-fixture"
242
- git -C "$case_dir" add -A
243
- git -C "$case_dir" commit -q -m "fixture baseline" --allow-empty
244
- fi
245
-
246
- # "dirty_files": written after the baseline commit above, so a new path
247
- # is untracked and an overwritten committed path is modified-unstaged.
248
- if ! stage_case_files "$case_file" "$i" "$case_dir" "dirty_files" "$script_rel" "$name"; then
249
- failures=$((failures + 1))
250
- continue
251
- fi
252
-
253
- env_args=("SOMI_AUDIT_LOG=$case_dir/audit.log" "CLAUDE_PROJECT_DIR=$case_dir")
254
- while IFS= read -r kv; do
255
- [[ -z "$kv" ]] && continue
256
- # {{CASE_DIR}} in an env value resolves the same way it does in the payload (see header
257
- # comment) — needed for a case to point CLAUDE_PLUGIN_ROOT / SOMI_VENDOR_ROOT at its own
258
- # throwaway case directory (pluginRoot()'s fixture cases, phase 1 iteration 1.2).
259
- kv="${kv//\{\{CASE_DIR\}\}/$case_dir}"
260
- env_args+=("$kv")
261
- done < <(jq -r ".cases[$i].env // {} | to_entries[] | \"\(.key)=\(.value)\"" "$case_file")
262
-
263
- # "prime": true — run the hook once first, discarding output, so a
264
- # signature/state file the hook itself writes is already in place before
265
- # the real (assertable) invocation below. "files_after_prime" perturbs
266
- # that state between the two invocations (see header comment).
267
- prime="$(jq -r ".cases[$i].prime // false" "$case_file")"
268
- if [[ "$prime" == "true" ]]; then
269
- if ! printf '%s' "$payload" \
270
- | env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES -u CLAUDE_PLUGIN_ROOT -u SOMI_VENDOR_ROOT "${env_args[@]}" "${cmd[@]}" >/dev/null; then
271
- echo "FAIL: [$script_rel] $name — priming invocation exited non-zero" >&2
272
- failures=$((failures + 1))
273
- continue
274
- fi
275
- if ! stage_case_files "$case_file" "$i" "$case_dir" "files_after_prime" "$script_rel" "$name"; then
276
- failures=$((failures + 1))
277
- continue
278
- fi
279
- fi
280
-
281
- if ! out="$(printf '%s' "$payload" \
282
- | env -u SOMI_ALLOW_DEP_INSTALL -u SOMI_ALLOW_LOCKFILES -u CLAUDE_PLUGIN_ROOT -u SOMI_VENDOR_ROOT "${env_args[@]}" "${cmd[@]}")"; then
283
- echo "FAIL: [$script_rel] $name — hook exited non-zero" >&2
284
- failures=$((failures + 1))
285
- continue
286
- fi
287
-
288
- decision="allow"
289
- if [[ -n "$out" ]] \
290
- && jq -e '.hookSpecificOutput.permissionDecision == "deny"' <<<"$out" >/dev/null 2>&1; then
291
- decision="deny"
292
- fi
293
-
294
- if [[ -n "$expect" ]] && [[ "$decision" != "$expect" ]]; then
295
- echo "FAIL: [$script_rel] $name — expected $expect, got $decision" >&2
296
- [[ -n "$out" ]] && echo " output: $out" >&2
297
- failures=$((failures + 1))
298
- fi
299
-
300
- if [[ -n "$expect_reason" ]]; then
301
- reason=""
302
- [[ -n "$out" ]] && reason="$(jq -r '.hookSpecificOutput.permissionDecisionReason // empty' <<<"$out")"
303
- if [[ "$reason" != *"$expect_reason"* ]]; then
304
- echo "FAIL: [$script_rel] $name — permissionDecisionReason did not contain expected substring" >&2
305
- echo " expected substring: $expect_reason" >&2
306
- echo " actual reason: $reason" >&2
307
- failures=$((failures + 1))
308
- fi
309
- fi
310
-
311
- if [[ -n "$expect_context" ]]; then
312
- context=""
313
- [[ -n "$out" ]] && context="$(jq -r '.hookSpecificOutput.additionalContext // empty' <<<"$out")"
314
- if [[ "$context" != *"$expect_context"* ]]; then
315
- echo "FAIL: [$script_rel] $name — additionalContext did not contain expected substring" >&2
316
- echo " expected substring: $expect_context" >&2
317
- echo " actual context: $context" >&2
318
- failures=$((failures + 1))
319
- fi
320
- fi
321
-
322
- if [[ "$expect_no_context" == "true" ]]; then
323
- context=""
324
- [[ -n "$out" ]] && context="$(jq -r '.hookSpecificOutput.additionalContext // empty' <<<"$out")"
325
- if [[ -n "$context" ]]; then
326
- echo "FAIL: [$script_rel] $name — expected no additionalContext, got one" >&2
327
- echo " actual context: $context" >&2
328
- failures=$((failures + 1))
329
- fi
330
- fi
331
-
332
- if [[ -n "$expect_context_excludes" ]]; then
333
- context=""
334
- [[ -n "$out" ]] && context="$(jq -r '.hookSpecificOutput.additionalContext // empty' <<<"$out")"
335
- if [[ "$context" == *"$expect_context_excludes"* ]]; then
336
- echo "FAIL: [$script_rel] $name — additionalContext contained a substring it must not" >&2
337
- echo " excluded substring: $expect_context_excludes" >&2
338
- echo " actual context: $context" >&2
339
- failures=$((failures + 1))
340
- fi
341
- fi
342
-
343
- if [[ -n "$expect_audit_log" ]]; then
344
- audit_log_content=""
345
- [[ -f "$case_dir/audit.log" ]] && audit_log_content="$(cat "$case_dir/audit.log")"
346
- if [[ "$audit_log_content" != *"$expect_audit_log"* ]]; then
347
- echo "FAIL: [$script_rel] $name — audit log did not contain expected substring" >&2
348
- echo " expected substring: $expect_audit_log" >&2
349
- echo " actual audit log: $audit_log_content" >&2
350
- failures=$((failures + 1))
351
- fi
352
- fi
353
-
354
- if [[ "$expect_no_audit_log" == "true" ]] && [[ -f "$case_dir/audit.log" ]]; then
355
- echo "FAIL: [$script_rel] $name — expected no audit-log write, but one occurred" >&2
356
- echo " actual audit log: $(cat "$case_dir/audit.log")" >&2
357
- failures=$((failures + 1))
358
- fi
359
-
360
- if [[ "$has_assertion" != "true" ]]; then
361
- echo "FAIL: [$script_rel] $name — case declares no recognized assertion field (expect/expect_context/expect_reason/expect_no_context/expect_audit_log/expect_no_audit_log); it would pass vacuously" >&2
362
- failures=$((failures + 1))
363
- fi
364
- done
365
- done
366
-
367
- # The write guards must be registered for every file-writing tool, in the plugin's hooks.json and in this repo's
368
- # vendored .claude/settings.json, or a payload for the tool never reaches them. Both files must list the same tools.
369
- total=$((total + 1))
370
- if ! node --input-type=module -e '
371
- import fs from "node:fs";
372
- const tools = new Map();
373
- for (const file of process.argv.slice(1)) {
374
- const reg = JSON.parse(fs.readFileSync(file, "utf8")).hooks.PreToolUse;
375
- for (const guard of ["block-secret-writes", "guard-protected-paths"]) {
376
- const entry = reg.find((e) => e.hooks.some((h) => h.command.includes(`/${guard}.mjs`)));
377
- const listed = (entry?.matcher ?? "").split("|");
378
- for (const t of ["Write", "Edit", "MultiEdit", "NotebookEdit"]) if (!listed.includes(t)) { console.error(`${file}: ${guard} is not registered for ${t}`); process.exit(1); }
379
- tools.set(`${file}:${guard}`, [...listed].sort().join("|"));
380
- }
381
- }
382
- if (new Set(tools.values()).size !== 1) { console.error(`the matchers differ: ${JSON.stringify([...tools])}`); process.exit(1); }
383
- ' "$ROOT/hooks/hooks.json" "$ROOT/.claude/settings.json"; then
384
- echo "FAIL: a write guard is not registered for every file-writing tool in hooks.json and .claude/settings.json" >&2
385
- failures=$((failures + 1))
386
- fi
387
-
388
- if (( failures > 0 )); then
389
- echo "hook fixtures: $failures of $total cases FAILED" >&2
390
- exit 1
391
- fi
392
- echo "hook fixtures: all $total cases passed."
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Regression test for scripts/validate.sh check (c): an agent that declares `model:` fails the build.
3
- # Runs the REAL block (and the model_of helper it calls), extracted from a scratch COPY of validate.sh, over
4
- # fixture agent directories -- not a second hand-typed copy of the check. Also asserts the shipped agents/
5
- # declare none. Residual: this proves the block's own logic, not that validate.sh still runs it.
6
- set -uo pipefail
7
-
8
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
9
- pass=0; fail=0
10
- ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
11
- bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
12
-
13
- echo "== agent model frontmatter (scripts/validate.sh) =="
14
- TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
15
- cp -a "$ROOT_REPO/scripts/validate.sh" "$TMP/validate.sh"
16
-
17
- HELPER="$(awk '/^model_of\(\) \{/{c=1} c{print} c&&/^\}$/{exit}' "$TMP/validate.sh")"
18
- BLOCK="$(awk '/^# \(c\) /{c=1} c{print} c&&/^done$/{exit}' "$TMP/validate.sh")"
19
- if [ -z "$HELPER" ] || [ -z "$BLOCK" ]; then bad "could not extract the check from scripts/validate.sh -- its markers may have moved"; echo "agent model tests: $pass ok, $fail failed"; exit 1; fi
20
- SNIPPET="$HELPER"$'\ncost_failed=0\n'"$BLOCK"$'\nexit $cost_failed'
21
-
22
- run() { (cd "$1" && bash -c "$SNIPPET" 2>"$1/err"); echo $?; }
23
- mkdir -p "$TMP/good/agents" "$TMP/bad/agents" "$TMP/crlf/agents"
24
- printf -- '---\nname: x\ndescription: d\ncost: low\n---\nbody mentions model: here\n' > "$TMP/good/agents/x.md"
25
- printf -- '---\nname: x\ndescription: d\nmodel: some-model\ncost: low\n---\nbody\n' > "$TMP/bad/agents/x.md"
26
- cp "$TMP/good/agents/x.md" "$TMP/bad/agents/y.md"
27
- printf -- '---\r\nname: x\r\nmodel: m\r\ncost: low\r\n---\r\n' > "$TMP/crlf/agents/x.md"
28
-
29
- [ "$(run "$TMP/good")" = 0 ] && ok "an agent without model: passes (a body line that mentions model: is not frontmatter)" || bad "clean agent rejected"
30
- [ "$(run "$TMP/bad")" = 1 ] && ok "an agent declaring model: fails the check" || bad "model: agent accepted"
31
- grep -q "MODEL ON AGENT: agents/x.md" "$TMP/bad/err" && ! grep -q "agents/y.md" "$TMP/bad/err" && ok "the message names the offending file only, and says why" || bad "message wrong: $(cat "$TMP/bad/err")"
32
- grep -q "inherit the session tier" "$TMP/bad/err" && ok "the message states the reason (an unresolved launch must inherit the session tier)" || bad "reason missing"
33
- [ "$(run "$TMP/crlf")" = 1 ] && ok "a CRLF file declaring model: fails too" || bad "CRLF agent accepted"
34
- n="$(grep -l '^model:' "$ROOT_REPO"/agents/*.md | wc -l)"
35
- [ "$n" = 0 ] && ok "no shipped agent declares model:" || bad "$n shipped agent(s) declare model:"
36
-
37
- echo "agent model tests: $pass ok, $fail failed"
38
- [ "$fail" -eq 0 ]
@@ -1,77 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Guard for agent identity (4.0.0 rename): every agents/*.md has a frontmatter `name` equal to its file
3
- # stem; every specialist is `somi-` prefixed and only the front door is the bare `somi`; and every
4
- # identifier-shaped reference in shipped text (`Task <agent>`, `--agent <agent>`, `agent: "<agent>"`,
5
- # `cost.agents.<agent>`, `subagent_type=<agent>`) names a real agent, so a stale pre-4.0.0 name fails here.
6
- set -uo pipefail
7
-
8
- ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
9
- echo "== agent names =="
10
-
11
- check_tree() { # $1 = repo root; prints one line per problem
12
- node --input-type=module - "$1" <<'EOF'
13
- import fs from 'node:fs';
14
- import path from 'node:path';
15
- const root = process.argv[2];
16
- const problems = [];
17
- const agentsDir = path.join(root, 'agents');
18
- const stems = fs.readdirSync(agentsDir).filter((f) => f.endsWith('.md')).map((f) => f.slice(0, -3));
19
- for (const stem of stems) {
20
- const text = fs.readFileSync(path.join(agentsDir, `${stem}.md`), 'utf8').replace(/\r\n/g, '\n');
21
- const name = /^---\n(?:.*\n)*?name: *([^\n]+)\n/.exec(text)?.[1]?.trim();
22
- if (name !== stem) problems.push(`agents/${stem}.md: frontmatter name ${JSON.stringify(name)} != file stem`);
23
- if (stem !== 'somi' && !stem.startsWith('somi-')) problems.push(`agents/${stem}.md: a specialist must be named somi-<name>`);
24
- }
25
- const known = new Set(stems);
26
- const REF = /(?:\bTask |--agent |\bagent: ?["']?|cost\.agents\.|subagent_type[=:] ?)([a-z][a-z0-9-]*)/g;
27
- const SKIP = new Set(['CHANGELOG.md']);
28
- function walk(dir) {
29
- for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
30
- const p = path.join(dir, e.name);
31
- if (e.isDirectory()) walk(p);
32
- else if (/\.(md|mjs|json)$/.test(e.name) && !SKIP.has(path.relative(root, p))) {
33
- const text = fs.readFileSync(p, 'utf8');
34
- for (const m of text.matchAll(REF)) {
35
- const id = m[1];
36
- // Placeholders and command recursions (`Task /code-loop`) are not agent ids.
37
- if (known.has(id) || /^(name|agent|x|foo|bad|the|a|an|one|each|that|this|is|tool|it|in|via)$/.test(id)) continue;
38
- if (!stems.includes(`somi-${id}`)) continue; // only flag names that are a renamed agent
39
- problems.push(`${path.relative(root, p)}: stale agent id "${id}" (use "somi-${id}")`);
40
- }
41
- }
42
- }
43
- }
44
- for (const d of ['agents', 'commands', 'skills', 'rules', 'docs', 'templates', 'hooks', 'scripts']) {
45
- if (fs.existsSync(path.join(root, d))) walk(path.join(root, d));
46
- }
47
- for (const f of ['README.md', 'AGENTS.md']) {
48
- const p = path.join(root, f);
49
- if (fs.existsSync(p)) for (const m of fs.readFileSync(p, 'utf8').matchAll(REF)) {
50
- if (!known.has(m[1]) && stems.includes(`somi-${m[1]}`)) problems.push(`${f}: stale agent id "${m[1]}" (use "somi-${m[1]}")`);
51
- }
52
- }
53
- process.stdout.write(problems.map((x) => `${x}\n`).join(''));
54
- EOF
55
- }
56
-
57
- pass=0; fail=0
58
- ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
59
- bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
60
-
61
- out="$(check_tree "$ROOT_REPO")"
62
- if [ -z "$out" ]; then ok "the shipped tree: names match stems, specialists are somi-*, no stale agent ids"; else bad "the shipped tree:"; printf '%s\n' "$out" | sed 's/^/ /'; fi
63
-
64
- # Red proofs on a scratch copy: each class of mistake is caught.
65
- TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
66
- red() { # $1 = label, $2 = mutation (run in the copy)
67
- rm -rf "$TMP/r"; mkdir -p "$TMP/r"; cp -R "$ROOT_REPO/agents" "$ROOT_REPO/commands" "$TMP/r/"
68
- (cd "$TMP/r" && eval "$2")
69
- if [ -n "$(check_tree "$TMP/r")" ]; then ok "red proof: $1"; else bad "red proof: $1 (not caught)"; fi
70
- }
71
- red "a frontmatter name that differs from its stem" "sed -i 's/^name: somi-coder\$/name: coder/' agents/somi-coder.md"
72
- red "a specialist file without the somi- prefix" "mv agents/somi-pr.md agents/pr.md; sed -i 's/^name: somi-pr\$/name: pr/' agents/pr.md"
73
- red "a stale 'Task reviewer' line in a command" "printf 'Task reviewer (= /review)\n' >> commands/review.md"
74
- red "a stale cost.agents.<old> key in prose" "printf 'set cost.agents.security-reviewer high\n' >> commands/review.md"
75
-
76
- echo "agent-names tests: $pass ok, $fail failed"
77
- [ "$fail" -eq 0 ]
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Tests for scripts/check-frontmatter.mjs. Each case writes one agent file into a throwaway tree
3
- # and asserts the exit code, never touching the real tree.
4
-
5
- set -euo pipefail
6
- ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
7
- CHECK="$ROOT/scripts/check-frontmatter.mjs"
8
- TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
9
- failures=0; total=0
10
- R="$TMP/r"
11
- # $1 = case name, $2 = expected exit, $3 = the agent file's frontmatter body (between the ---).
12
- case_fm() { local name="$1" want="$2" got=0
13
- rm -rf "$R"; mkdir -p "$R/agents" "$R/commands" "$R/skills"
14
- printf -- '---\n%s\n---\n\nBody.\n' "$3" > "$R/agents/a.md"
15
- node "$CHECK" "$R" >/dev/null 2>&1 || got=$?
16
- [[ "$got" == "$want" ]] || { echo "FAIL: $name -- expected exit $want, got $got" >&2; failures=$((failures+1)); }
17
- total=$((total+1)); }
18
-
19
- case_fm "plain values pass" 0 $'name: a\ndescription: Reviews plans, code and designs.\ntools: Read, Grep'
20
- case_fm "double-quoted value with ': ' passes" 0 $'name: a\ndescription: "checks divergence: did it follow"'
21
- case_fm "single-quoted value with ': ' passes" 0 $'name: a\ndescription: \'it\'\'s a: test\''
22
- case_fm "plain value containing ': ' fails (#30, reviewer)" 1 $'name: a\ndescription: checks divergence: did it follow'
23
- case_fm "plain value with backticked 'cost: high' fails (#30, designer)" 1 $'name: a\ndescription: Design agent (`cost: high`). Use first.'
24
- case_fm "plain value starting with a backtick fails" 1 $'name: a\ndescription: `x` does y'
25
- case_fm "plain value starting with [ fails" 1 $'name: a\nargument-hint: [nothing] | refresh'
26
- case_fm "plain value containing ' #' fails" 1 $'name: a\ndescription: step #1 and more # here'
27
- case_fm "unterminated double quote fails" 1 $'name: a\ndescription: "open'
28
- case_fm "a non key-value line fails" 1 $'name: a\njust some prose'
29
- rm -rf "$R"; mkdir -p "$R/agents" "$R/commands" "$R/skills"; printf 'no frontmatter\n' > "$R/agents/a.md"
30
- got=0; node "$CHECK" "$R" >/dev/null 2>&1 || got=$?; total=$((total+1))
31
- [[ "$got" == 1 ]] || { echo "FAIL: missing frontmatter -- expected exit 1, got $got" >&2; failures=$((failures+1)); }
32
- rm -rf "$R"; mkdir -p "$R/agents" "$R/commands" "$R/skills"; printf -- '---\r\nname: a\r\ndescription: ok\r\n---\r\n' > "$R/agents/a.md"
33
- got=0; node "$CHECK" "$R" >/dev/null 2>&1 || got=$?; total=$((total+1))
34
- [[ "$got" == 0 ]] || { echo "FAIL: CRLF frontmatter -- expected exit 0, got $got" >&2; failures=$((failures+1)); }
35
-
36
- if (( failures )); then echo "check-frontmatter tests: $failures of $total failed" >&2; exit 1; fi
37
- echo "check-frontmatter tests: $total of $total checks passed."