@skathio/somi 2.2.2 → 3.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 (128) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +8 -2
  3. package/.copilot-extension/extension.json +9 -8
  4. package/.copilot-extension/marketplace.json +2 -2
  5. package/README.md +45 -33
  6. package/VERSION +1 -1
  7. package/agents/architecture-reviewer.md +16 -0
  8. package/agents/atlas.md +102 -0
  9. package/agents/coder.md +66 -22
  10. package/agents/designer.md +20 -16
  11. package/agents/discovery-analyst.md +6 -5
  12. package/agents/impact.md +97 -0
  13. package/agents/incident.md +96 -0
  14. package/agents/plan-reviewer.md +70 -0
  15. package/agents/planner.md +77 -20
  16. package/agents/pr.md +101 -0
  17. package/agents/refactor-designer.md +82 -0
  18. package/agents/refactorer.md +30 -24
  19. package/agents/reviewer.md +28 -25
  20. package/agents/sdlc-reviewer.md +69 -0
  21. package/agents/security-reviewer.md +17 -0
  22. package/agents/somi.md +204 -153
  23. package/agents/test-strategist.md +16 -1
  24. package/commands/adopt.md +21 -7
  25. package/commands/architecture-review.md +8 -5
  26. package/commands/atlas.md +24 -72
  27. package/commands/code-loop.md +46 -15
  28. package/commands/code-parallel.md +6 -4
  29. package/commands/code.md +29 -21
  30. package/commands/debug.md +17 -11
  31. package/commands/design.md +48 -31
  32. package/commands/discover.md +26 -16
  33. package/commands/impact.md +16 -54
  34. package/commands/incident.md +22 -55
  35. package/commands/plan-loop.md +43 -17
  36. package/commands/plan.md +64 -26
  37. package/commands/pr.md +19 -66
  38. package/commands/refactor-design.md +98 -0
  39. package/commands/refactor.md +22 -23
  40. package/commands/release-readiness.md +16 -7
  41. package/commands/review-panel.md +31 -10
  42. package/commands/review.md +21 -14
  43. package/commands/security-review.md +12 -3
  44. package/commands/ship-loop.md +71 -54
  45. package/commands/ship.md +17 -13
  46. package/commands/test-strategy.md +6 -4
  47. package/commands/upgrade.md +10 -8
  48. package/examples/discovery-example.md +2 -2
  49. package/examples/sample-consumer/CLAUDE.md +41 -7
  50. package/examples/sample-consumer/README.md +36 -22
  51. package/hooks/lib/common.mjs +66 -20
  52. package/hooks/post-tool/audit-log.mjs +7 -11
  53. package/hooks/post-tool/lint-changed-files.mjs +8 -11
  54. package/hooks/pre-tool/block-dangerous-bash.mjs +32 -44
  55. package/hooks/pre-tool/block-secret-writes.mjs +6 -9
  56. package/hooks/pre-tool/gate-dep-install.mjs +18 -27
  57. package/hooks/pre-tool/guard-protected-paths.mjs +9 -11
  58. package/hooks/session-start/detect-repo-instructions.mjs +21 -23
  59. package/hooks/user-prompt-submit/inject-workflow-context.mjs +190 -42
  60. package/mcp.json +10 -0
  61. package/package.json +5 -2
  62. package/rules/CLAUDE.md +22 -19
  63. package/scripts/check-links.mjs +218 -0
  64. package/scripts/check-session-artefacts.mjs +149 -0
  65. package/scripts/check-size-budget.mjs +137 -0
  66. package/scripts/generate-digest.mjs +176 -0
  67. package/scripts/lib/cost-ceiling.mjs +317 -0
  68. package/scripts/lib/cost-model.mjs +95 -0
  69. package/scripts/lib/dispatch-resolver.mjs +224 -0
  70. package/scripts/lib/mcp-project-root.mjs +183 -0
  71. package/scripts/size-budget-overrides.json +74 -0
  72. package/scripts/somi-check.mjs +6 -13
  73. package/scripts/somi-dispatch.mjs +141 -0
  74. package/scripts/somi-findings.mjs +4 -5
  75. package/scripts/somi-loop.mjs +181 -13
  76. package/scripts/somi-mcp.mjs +357 -0
  77. package/scripts/validate.sh +690 -29
  78. package/skills/clean-code/SKILL.md +1 -1
  79. package/skills/plan-review/SKILL.md +79 -0
  80. package/skills/rules/SKILL.md +47 -0
  81. package/skills/sdlc-process/SKILL.md +74 -0
  82. package/skills/somi-dispatch/SKILL.md +220 -0
  83. package/skills/somi-routing/SKILL.md +31 -6
  84. package/skills/{test-strategy → testing-playbook}/SKILL.md +1 -1
  85. package/templates/ATLAS.md.tmpl +4 -4
  86. package/templates/BRIEF.md.tmpl +23 -22
  87. package/templates/DECISIONS.md.tmpl +1 -0
  88. package/templates/DESIGN.md.tmpl +5 -5
  89. package/templates/DIARY.md.tmpl +10 -5
  90. package/templates/DOD.md.tmpl +24 -0
  91. package/templates/PROGRESS.md.tmpl +3 -16
  92. package/templates/SOMI-README.md.tmpl +3 -3
  93. package/tests/hooks/cases/inject-workflow-context.json +120 -7
  94. package/tests/hooks/run.sh +20 -11
  95. package/tests/scripts/check-links.sh +105 -0
  96. package/tests/scripts/check-session-artefacts.sh +60 -0
  97. package/tests/scripts/check-size-budget.sh +71 -0
  98. package/tests/scripts/checkpoint-gate.sh +90 -0
  99. package/tests/scripts/convergence-runner.sh +1510 -0
  100. package/tests/scripts/cost-ceiling.sh +343 -0
  101. package/tests/scripts/cost-model.sh +192 -0
  102. package/tests/scripts/dispatch-guard.sh +108 -0
  103. package/tests/scripts/dispatch-reference-gate.sh +173 -0
  104. package/tests/scripts/eval-runner.sh +3691 -0
  105. package/tests/scripts/evals-packaging.sh +117 -0
  106. package/tests/scripts/fixtures/legacy-shard-no-schema.json +50 -0
  107. package/tests/scripts/generate-digest.sh +180 -0
  108. package/tests/scripts/goldens/loop-state-breach.json +1 -0
  109. package/tests/scripts/goldens/loop-state-done.json +1 -0
  110. package/tests/scripts/goldens/somi-loop.json +1 -1
  111. package/tests/scripts/lib/adr-shape.mjs +41 -0
  112. package/tests/scripts/lib/checkpoint-gate.mjs +54 -0
  113. package/tests/scripts/lib/digest-marker-coupling.mjs +52 -0
  114. package/tests/scripts/lib/dispatch-reference-gate.mjs +112 -0
  115. package/tests/scripts/lib/multipass-dependence.mjs +192 -0
  116. package/tests/scripts/lib/multipass-source-identity.mjs +243 -0
  117. package/tests/scripts/lib/reference-pair.mjs +61 -0
  118. package/tests/scripts/lib/retirement-gate.mjs +167 -0
  119. package/tests/scripts/lib/shell-embedded-js.mjs +47 -0
  120. package/tests/scripts/lib/somi-mcp-client.mjs +102 -0
  121. package/tests/scripts/lib/somi-mcp-tests.mjs +401 -0
  122. package/tests/scripts/lib/somi-mcp-tool-schema.mjs +38 -0
  123. package/tests/scripts/retirement-gate.sh +287 -0
  124. package/tests/scripts/review-panel-seats.sh +32 -0
  125. package/tests/scripts/run.sh +184 -2
  126. package/tests/scripts/somi-agent-dispatch-contract.sh +195 -0
  127. package/tests/scripts/somi-dispatch.sh +354 -0
  128. package/tests/scripts/somi-mcp.sh +12 -0
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env bash
2
2
  # Validation script run as `npm test`. Checks JSON validity, Node source syntax, and frontmatter.
3
- # The runtime it validates is zero-dependency Node (D1/D5): JSON validity uses `node -e JSON.parse`
4
- # (not `jq`), and source syntax uses `node --check` over the ported `.mjs` files (not `shellcheck`/
5
- # `bash -n` over `.sh`, which no longer exist under scripts/ or hooks/ — see work item
6
- # node-runtime-port). This file itself stays bash (dev/CI tooling, per context.md §6), invoked from
7
- # `npm test`; it needs neither jq nor shellcheck installed. Also emits a minimal coverage/lcov.info
3
+ # The runtime it validates is zero-dependency Node: JSON validity uses `node -e JSON.parse`
4
+ # (not `jq`), and source syntax uses `node --check` over the `.mjs` files (not `shellcheck`/
5
+ # `bash -n` over `.sh`, which no longer exist under scripts/ or hooks/). This file itself stays
6
+ # bash (dev/CI tooling), invoked from `npm test`; it needs neither jq nor shellcheck installed. Also emits a minimal coverage/lcov.info
8
7
  # stub so the hashira-ops CI coverage-report action has a file to parse (no unit test suite).
9
8
  set -euo pipefail
10
9
 
11
- # JSON validity via Node's own parser (D5: no jq). Fails loudly on the first invalid file.
10
+ # JSON validity via Node's own parser (no jq). Fails loudly on the first invalid file.
12
11
  json_valid() { node -e 'JSON.parse(require("fs").readFileSync(process.argv[1],"utf8"))' "$1"; }
13
12
 
14
13
  echo "==> Validating JSON files..."
@@ -18,6 +17,7 @@ for f in \
18
17
  .copilot-extension/extension.json \
19
18
  .copilot-extension/marketplace.json \
20
19
  .claude/settings.json \
20
+ mcp.json \
21
21
  package.json \
22
22
  hooks/hooks.json \
23
23
  examples/sample-consumer/.claude/settings.json; do
@@ -26,7 +26,11 @@ for f in \
26
26
  done
27
27
 
28
28
  echo "==> Node syntax check (node --check over the ported .mjs)..."
29
- find hooks scripts -name '*.mjs' -type f -print0 \
29
+ # tests/evals is excluded from the published package (tests/.npmignore), so this path does not
30
+ # exist in an unpacked tarball -- where `npm test` is exactly what a release smoke check runs.
31
+ # Naming a missing directory makes find exit 1 and the whole script die under `set -e`.
32
+ EVAL_TREE=""; [ -d tests/evals ] && EVAL_TREE="tests/evals"
33
+ find hooks scripts $EVAL_TREE -name '*.mjs' -type f -print0 \
30
34
  | xargs -0 -I{} node --check {}
31
35
 
32
36
  echo "==> Hook behavior fixtures..."
@@ -39,6 +43,133 @@ bash tests/hooks/run.sh
39
43
  echo "==> Loop-state & findings-ledger tests..."
40
44
  bash tests/scripts/run.sh
41
45
 
46
+ echo "==> Link-checker tests..."
47
+ bash tests/scripts/check-links.sh
48
+
49
+ echo "==> Session-artefact gate tests..."
50
+ # Guards scripts/check-session-artefacts.mjs: fails on a tagged comment, passes a clean one, and
51
+ # honours its explicit exclusions.
52
+ bash tests/scripts/check-session-artefacts.sh
53
+
54
+ echo "==> File-size budget gate tests..."
55
+ # Guards scripts/check-size-budget.mjs: an un-ledgered oversized file fails, a ledgered file may
56
+ # shrink but not grow, a stale entry warns, a malformed ledger fails loudly.
57
+ bash tests/scripts/check-size-budget.sh
58
+
59
+ echo "==> Digest-generator tests..."
60
+ # Guards scripts/generate-digest.mjs: per-target prefix transform, drift detection in EITHER
61
+ # copy alone, clean errors on malformed input, and splice anchoring. Wiring `--check` itself
62
+ # into this script is the separate "Validating digest parity" step below — this is the
63
+ # unit guard for the generator, not the drift gate.
64
+ bash tests/scripts/generate-digest.sh
65
+
66
+ echo "==> Cost model resolver tests..."
67
+ bash tests/scripts/cost-model.sh
68
+
69
+ echo "==> Cost ceiling tests..."
70
+ bash tests/scripts/cost-ceiling.sh
71
+
72
+ echo "==> Dispatch resolver tests..."
73
+ bash tests/scripts/somi-dispatch.sh
74
+
75
+ echo "==> Front-door agent <-> dispatch resolver contract tests..."
76
+ # agents/somi.md is a prompt and can't be exercised without a model, but what its Step 4 tells the
77
+ # model to RUN can be checked deterministically: the resolve --agent/--host invocation shape it
78
+ # instructs, and the exit codes it maps, must both be real and current against the actual CLI.
79
+ bash tests/scripts/somi-agent-dispatch-contract.sh
80
+
81
+ echo "==> Bundled MCP server tests (somi_resolve / somi_command)..."
82
+ # scripts/somi-mcp.mjs is the MCP-native equivalent of the CLI above, launched from
83
+ # ${CLAUDE_PLUGIN_ROOT}/${PLUGIN_ROOT} so a prompt never needs an install path. Both wrap the
84
+ # identical scripts/lib/dispatch-resolver.mjs, so this drives the real JSON-RPC stdio protocol
85
+ # rather than re-testing the resolver's arithmetic a third time.
86
+ bash tests/scripts/somi-mcp.sh
87
+
88
+ echo "==> Validating the never-degrade dispatch guard..."
89
+ # scripts/lib/cost-ceiling.mjs's modelForDispatch() is the ONLY sanctioned way to turn a dispatch
90
+ # decision into a model: it resolves the SELECTED tier and refuses anything shaped as other than an
91
+ # "allow" decision. Calling the underlying model resolver directly against a decision's ceiling
92
+ # field instead of its selected field reads fine in English but is a different, unsanctioned
93
+ # composition -- it would run a unit at whatever tier the session merely PERMITS rather than the
94
+ # tier decideDispatch actually picked for it, silently running above what the unit declared. This
95
+ # gate closes that path structurally rather than by convention: nothing outside the library itself
96
+ # may compose the two functions that way. scripts/somi-dispatch.mjs is the first real dispatch call
97
+ # site this machinery ever had (before it, decideDispatch/modelForDispatch had zero live callers),
98
+ # so the gate had to land no later than this change, not after.
99
+ #
100
+ # EXEMPT: scripts/lib/ -- cost-ceiling.mjs's own modelForDispatch() resolves against a decision's
101
+ # SELECTED tier, never its ceiling, but the exemption is by path, not by re-deriving that fact here
102
+ # on every run. Also EXEMPT: tests/scripts/dispatch-guard.sh -- this guard's own regression test,
103
+ # which plants the violating call ON PURPOSE inside a synthetic fixture to prove the guard catches
104
+ # it; the same self-exemption tests/scripts/retirement-gate.sh needs from the gate it tests.
105
+ dispatch_guard_failed=0
106
+ if grep -rnE 'resolveModel\([A-Za-z_$][A-Za-z0-9_$]*\.ceiling' \
107
+ agents commands docs scripts hooks tests README.md AGENTS.md 2>/dev/null \
108
+ | grep -v '^scripts/lib/' | grep -v '^tests/scripts/dispatch-guard\.sh:'; then
109
+ echo "UNSANCTIONED DISPATCH: resolveModel() called against a ceiling value directly above -- use modelForDispatch(decideDispatch(...), host) instead, which resolves the SELECTED tier" >&2
110
+ dispatch_guard_failed=1
111
+ fi
112
+ if [ "$dispatch_guard_failed" -ne 0 ]; then
113
+ exit 1
114
+ fi
115
+ bash tests/scripts/dispatch-guard.sh
116
+
117
+ echo "==> Diary compaction rule present in the template..."
118
+ # The rule must stay triggered and concrete: a numeric trigger, a verbatim move to diary-archive.md,
119
+ # and the never-move rule for decision-change / plan-change entries. Weakening it back to
120
+ # a soft "may compact" wording lets that log grow without bound.
121
+ DIARY_TMPL="${DIARY_TMPL:-templates/DIARY.md.tmpl}"
122
+ for pat in 'more than 40' 'diary-archive\.md' 'verbatim' 'Never move a `decision-change` or `plan-change`'; do
123
+ grep -Eq -- "$pat" "$DIARY_TMPL" || { echo "DIARY COMPACTION RULE WEAKENED: '$pat' missing from $DIARY_TMPL" >&2; exit 1; }
124
+ done
125
+ echo " ok: $DIARY_TMPL"
126
+
127
+ echo "==> Eval fixture guards..."
128
+ # Guards tests/evals/fixtures/. Two defects are guarded here: a plan tree shipped
129
+ # under `.somi/` that .gitignore silently dropped from the package, and pass criteria
130
+ # written into fixture source as comments the candidate reads — which would have flatlined two
131
+ # load-bearing rubric dimensions at pass in BOTH arms of the trim comparison, reporting no
132
+ # regression on exactly what the corpus exists to protect.
133
+ if [ -d tests/evals ]; then bash tests/scripts/evals-fixtures.sh; else echo " (skipped: tests/evals not packaged)"; fi
134
+
135
+ echo "==> Eval runner unit tests..."
136
+ # Guards tests/evals/run.mjs: the N-of-M grading bands, the trim-comparison rule, the result
137
+ # schema, and --source worktree cleanup. Hermetic -- every case is --dry-run or a direct call.
138
+ # This runs the runner's UNIT tests; it never invokes the runner against a model. The structural
139
+ # assertion that npm test cannot execute the runner lives inside eval-runner.sh itself.
140
+ if [ -d tests/evals ]; then bash tests/scripts/eval-runner.sh; else echo " (skipped: tests/evals not packaged)"; fi
141
+
142
+ echo "==> Convergence gate CLI unit tests..."
143
+ # Guards tests/evals/convergence.mjs's CLI section: argument parsing, --dry-run's shape/zero-model-call
144
+ # contract, --merge/--certify's shard-fold report, and the sha boundary check. Mirrors
145
+ # eval-runner.sh's own pattern -- unit-tests the gate logic, never a live run. The module's
146
+ # non-CLI logic is already covered by eval-runner.sh; this file is scoped to the CLI section
147
+ # alone, so the two stay disjoint rather than duplicating each other.
148
+ if [ -d tests/evals ]; then bash tests/scripts/convergence-runner.sh; else echo " (skipped: tests/evals not packaged)"; fi
149
+
150
+ echo "==> Eval packaging & hermeticity..."
151
+ # The hermeticity invariant lives here, and this step owns it alone: `npm test` never
152
+ # invokes a model, reaches the network, or reads a credential -- and the eval corpus never ships
153
+ # to consumers. Asserted at the INVOCATION level, because validate.sh must NAME tests/evals to
154
+ # syntax-check it, so a "no mention" rule would be self-contradicting.
155
+ bash tests/scripts/evals-packaging.sh
156
+
157
+ echo "==> Digest-marker / hook-fixture coupling..."
158
+ # A `rules/` trim that removes or rewords a digest bullet must update
159
+ # tests/hooks/cases/inject-workflow-context.json's Tier-2 marker in the SAME attempt. The fixture
160
+ # has a PAIR of cases on that bullet (positive + negative); trim the bullet and the cases that
161
+ # carry it as incidental context go quietly vacuous while the suite stays green.
162
+ #
163
+ # `rules/` is the tree most likely to be trimmed, so this is the coupling most likely to break.
164
+ coupling=$(node tests/scripts/lib/digest-marker-coupling.mjs \
165
+ tests/hooks/cases/inject-workflow-context.json \
166
+ hooks/user-prompt-submit/inject-workflow-context.mjs \
167
+ rules/CLAUDE.md .github/copilot-instructions.md)
168
+ case "$coupling" in
169
+ ok*) echo " $coupling" ;;
170
+ *) echo "DIGEST-MARKER COUPLING BROKEN:" >&2; echo "$coupling" >&2; exit 1 ;;
171
+ esac
172
+
42
173
  echo "==> Validating agent/command/skill frontmatter..."
43
174
  failed=0
44
175
  while IFS= read -r f; do
@@ -55,38 +186,285 @@ if [ "$failed" -ne 0 ]; then
55
186
  exit 1
56
187
  fi
57
188
 
58
- echo "==> Validating MAX/ECO model tiering..."
59
- # Extract the first `model:` value from a file's frontmatter (the block between the
60
- # first two `---` lines).
189
+ echo "==> Validating cost-tier declarations..."
190
+ # Extract the first `cost:` (or `model:`) value(s) from a file's frontmatter (the block between
191
+ # the first two `---` lines). A declared `cost:` is a CAPABILITY SET -- every tier that unit can
192
+ # usefully run at, comma-separated in strictly ascending order -- and a dispatcher selects the
193
+ # highest member its ceiling permits; that selection is capability, never a downgrade to a tier
194
+ # the unit didn't declare. agents/reviewer.md's shipped `cost: medium, high` is a real example: a
195
+ # lighter pass is honestly useful at `medium`, adversarial fresh-eyes review needs `high`. What a
196
+ # file Tasks never contributes a value here, and a spawned unit never inherits its caller's tier
197
+ # either direction: a cost: medium orchestrator Tasking a cost: high agent stays declared medium --
198
+ # the agent's own frontmatter is where high is truthfully declared, once -- and a cost: high agent
199
+ # Tasking a cost: low, medium helper does not pull that helper up to high either.
200
+ cost_of() {
201
+ awk '/^---$/{c++} c==1 && /^cost:[[:space:]]*/{sub(/^cost:[[:space:]]*/,""); print; exit}' "$1"
202
+ }
61
203
  model_of() {
62
204
  awk '/^---$/{c++} c==1 && /^model:[[:space:]]*/{sub(/^model:[[:space:]]*/,""); print; exit}' "$1"
63
205
  }
64
- tier_failed=0
65
- assert_model() {
206
+ cost_failed=0
207
+
208
+ # Both the valid-cost enum and each tier's expected model are DERIVED from
209
+ # scripts/lib/cost-model.mjs in one node call, not hardcoded a second time here -- a repricing or
210
+ # a new tier is then a one-file edit instead of two files drifting apart.
211
+ #
212
+ # CAPTURE, CHECK, THEN EVAL -- deliberately not a bare `eval "$(node -e …)"`. A PARTIAL failure
213
+ # (resolveModel throws for one tier mid-forEach, after valid_costs and earlier ranks already
214
+ # printed) exits node non-zero, but that status is invisible to `eval`: the failing command
215
+ # substitution is only an argument being built for eval, not the exit status of a simple command,
216
+ # so `set -e` cannot see it and the script would report the cost block PASSED with that tier's
217
+ # model_for_* silently missing. Assigning to a plain variable first makes the substitution's exit
218
+ # status the ASSIGNMENT's status, which the explicit `||` below then catches -- and it must be
219
+ # explicit, not a bare `cost_env=$(node …)`: under `set -e` a bare assignment dies silently at the
220
+ # assignment, with no diagnostic reaching the user about which check was skipped.
221
+ cost_env="$(node -e '
222
+ import("./scripts/lib/cost-model.mjs").then((m) => {
223
+ console.log("valid_costs=" + JSON.stringify(m.VALID_COSTS.join("|")));
224
+ m.VALID_COSTS.forEach((c, idx) => {
225
+ console.log("rank_" + c + "=" + idx);
226
+ console.log("model_for_" + c + "=" + JSON.stringify(m.resolveModel(c, "claude-code")));
227
+ });
228
+ });
229
+ ')" || { echo "cost-model derivation failed; cannot validate cost tiers" >&2; exit 1; }
230
+ eval "$cost_env"
231
+
232
+ # (a) `cost:` lives on agents only -- `cost:` sizes an agent instance being spawned, and a
233
+ # command isn't one, so `cost:` on a command binds to nothing. Every agents/*.md file must declare
234
+ # a `cost:` field (EXEMPTION:
235
+ # agents/somi.md, see below) and every value in it (split on comma, for graded units) must be one
236
+ # of scripts/lib/cost-model.mjs's VALID_COSTS. Every commands/*.md file must NOT declare one -- the
237
+ # front door spawns that command's paired agent at the agent's own declared tier instead.
238
+ #
239
+ # EXEMPTION: agents/somi.md. `cost:` on this one file was always decorative -- the host binds the
240
+ # model when the user picks this agent in its own UI, so nothing in this repo could ever act on
241
+ # the declaration. A field nothing can read is worse than no field: a future dispatcher would have
242
+ # to treat a decorative declaration as a trap. Named here, not silently skipped, so a later reader
243
+ # does not "fix" it back in.
244
+ #
245
+ # Commands must not declare `model:` either, for the same reason: Claude Code honoured a
246
+ # command's own `model:` for that command's own turn, which taught the repo that a command has a
247
+ # cost while every dispatch target's actual cost lives on the agent it Tasks. Agents keep
248
+ # `model:` -- it is still the mechanism Claude Code reads to pick a Tasked subagent's model, and
249
+ # the retirement gate's frontmatter exemption (tests/scripts/lib/retirement-gate.mjs) still applies
250
+ # to it.
251
+ for f in agents/*.md commands/*.md; do
252
+ [ -f "$f" ] || continue
253
+ got="$(cost_of "$f")"
254
+ case "$f" in
255
+ commands/*.md)
256
+ if [ -n "$got" ]; then
257
+ echo "COST TIER ON COMMAND: $f declares cost: '$got' -- commands declare no cost: of their own; declare cost: on the agent this command Tasks instead" >&2
258
+ cost_failed=1
259
+ fi
260
+ declared_model="$(model_of "$f" | tr -d '[:space:]')"
261
+ if [ -n "$declared_model" ]; then
262
+ echo "MODEL ON COMMAND: $f declares model: '$declared_model' -- commands no longer declare a model of their own; the front door dispatches this command's paired agent at the agent's own declared cost/model instead" >&2
263
+ cost_failed=1
264
+ fi
265
+ continue
266
+ ;;
267
+ agents/somi.md)
268
+ if [ -n "$got" ]; then
269
+ echo "COST TIER ON EXEMPT AGENT: $f declares cost: '$got' -- this file is exempt from cost: entirely (see the EXEMPTION comment above); remove the declaration" >&2
270
+ cost_failed=1
271
+ fi
272
+ continue
273
+ ;;
274
+ esac
275
+ if [ -z "$got" ]; then
276
+ echo "COST TIER MISSING: $f has no 'cost:' field in frontmatter" >&2
277
+ cost_failed=1
278
+ continue
279
+ fi
280
+ # Reject an empty element (leading/trailing/double comma, e.g. "medium," or ",high") before
281
+ # splitting -- `IFS=',' read -ra` silently drops a trailing empty field, so a malformed list
282
+ # would otherwise split clean and pass.
283
+ stripped="$(echo "$got" | tr -d '[:space:]')"
284
+ case "$stripped" in
285
+ ,*|*,|*,,*)
286
+ echo "COST TIER MALFORMED: $f has an empty cost value (leading/trailing/double comma) in '$got'" >&2
287
+ cost_failed=1
288
+ continue
289
+ ;;
290
+ esac
291
+ IFS=',' read -ra cost_values <<< "$got"
292
+ prev_rank=-1
293
+ for v in "${cost_values[@]}"; do
294
+ v="$(echo "$v" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
295
+ case "|$valid_costs|" in
296
+ *"|$v|"*)
297
+ rank_var="rank_$v"
298
+ rank="${!rank_var}"
299
+ ;;
300
+ *)
301
+ echo "COST TIER INVALID: $f declares cost value '$v' (expected one of $valid_costs)" >&2
302
+ cost_failed=1
303
+ rank=-1
304
+ ;;
305
+ esac
306
+ # Multi-value cost must be strictly ascending with no duplicates (low < medium < high) -- a
307
+ # second value that repeats or precedes the first is a hand-edit slip a reader will not
308
+ # notice, and the field is about to become a dispatch input.
309
+ if [ "$rank" -ge 0 ] && [ "$rank" -le "$prev_rank" ]; then
310
+ echo "COST TIER UNORDERED: $f declares '$got' -- multi-value cost must be strictly ascending ($valid_costs), no duplicates" >&2
311
+ cost_failed=1
312
+ fi
313
+ [ "$rank" -ge 0 ] && prev_rank="$rank"
314
+ done
315
+ done
316
+
317
+ # (b) Pin the exact declared cost for the files where the value is load-bearing beyond "some
318
+ # valid tier" -- mirrors the thirteen model-value assertions this block replaces.
319
+ assert_cost() {
66
320
  local f="$1" want="$2" got
67
- got="$(model_of "$f")"
321
+ got="$(cost_of "$f" | tr -d '[:space:]')"
68
322
  if [ "$got" != "$want" ]; then
69
- echo "MODEL TIER MISMATCH: $f model is '$got', expected '$want'" >&2
70
- tier_failed=1
323
+ echo "COST TIER MISMATCH: $f cost is '$got', expected '$want'" >&2
324
+ cost_failed=1
71
325
  fi
72
326
  }
73
- # ECO tier (sonnet): planning + coding execute against the MAX brief.
74
- assert_model agents/planner.md sonnet
75
- assert_model agents/coder.md sonnet
76
- assert_model agents/somi.md sonnet
77
- # MAX tier (opus): front-load reasoning + fresh-eyes review.
78
- for a in discovery-analyst designer refactorer reviewer security-reviewer architecture-reviewer test-strategist; do
79
- assert_model "agents/$a.md" opus
327
+ # low, medium: these three widen downward under the opt-in bar for `low` -- a builder-tier agent
328
+ # may declare `low` once it can still do a reduced-depth version of its job and its own output says
329
+ # so when it ran that way, even though the reduced depth would not hold up as the only tier it ever
330
+ # ran at. `low` only ever runs when the session ceiling resolves to `low` -- an explicit CLI flag or
331
+ # SOMI_COST_CEILING for this session, or inherited from a committed .somi/config.json or a saved
332
+ # state file that persists across sessions -- and the front door announces that ceiling and its
333
+ # source before work starts, so the quality drop is a trade the user can see, not one sprung on
334
+ # them. Each agent's own frontmatter and "Running at `low`" section name what that agent's
335
+ # reduced-depth pass keeps and what it trims -- read those, not this comment, for the specifics.
336
+ # refactorer still has no `high` member: a refactor too big for one diff is a different job, split
337
+ # out to the refactor-designer sibling below, not a third tier declared here. agents/somi.md is
338
+ # EXEMPT from this whole block (see the comment above the loop) -- it declares no cost: at all.
339
+ for a in planner coder refactorer; do
340
+ assert_cost "agents/$a.md" low,medium
341
+ done
342
+ # high-only: a wrong call here is paid for through everything downstream that builds on it, so a
343
+ # cheaper pass would be cheaper-and-wrong, not genuinely useful -- these never gain a lower member.
344
+ # atlas joins this set: its whole value is one high-quality read of the repository, paid once.
345
+ for a in discovery-analyst designer security-reviewer refactor-designer atlas; do
346
+ assert_cost "agents/$a.md" high
347
+ done
348
+ # medium, high: a lighter pass is genuinely useful under a capped ceiling, but the deepest work
349
+ # needs the strong model -- these grade ONE job over two depths, not two different jobs, so a
350
+ # blind ceiling pick is safe at either member. These are judges, not builders: a weaker judge
351
+ # doesn't produce weaker output, it produces a false pass with nothing downstream to catch what it
352
+ # missed, so the opt-in bar for `low` above does not extend to this set.
353
+ for a in reviewer architecture-reviewer test-strategist plan-reviewer sdlc-reviewer; do
354
+ assert_cost "agents/$a.md" medium,high
355
+ done
356
+ # medium-only, judge not builder: impact's deliverable is a proceed / design-first / reconsider
357
+ # verdict and, in diff mode, the review-lens selection -- a reduced-depth pass would undercount the
358
+ # blast radius and can return a false "proceed, small" with nothing downstream to re-check it, or
359
+ # drop a lens (security-reviewer, worst case) that then never runs elsewhere. Same false-pass
360
+ # failure that keeps the medium,high judges above off `low`, so impact stays off it too despite
361
+ # tracing an already-written call graph -- still no `high` member, since even its full-depth pass is
362
+ # mechanical tracing, not open-ended research.
363
+ assert_cost agents/impact.md medium
364
+ # medium-only: incident's mitigation-stage judgment (flag flip vs. revert vs. scoped patch, verified
365
+ # against the live symptom) and its debt-capture accounting both need full reasoning on every run --
366
+ # every job this agent accepts is, by construction, a live outage handed off after framing, so there
367
+ # is no lighter version of the call to make honestly.
368
+ assert_cost agents/incident.md medium
369
+ # graded over one job at two depths: mechanical aggregation of existing artifacts is already a
370
+ # correct, usable PR description at low; a fuller pass adds house-style matching, never required.
371
+ assert_cost agents/pr.md low,medium
372
+
373
+ # (c) `model:` and `cost:` state one fact twice -- assert `model:` resolves from the declared
374
+ # `cost:` set's TOP (highest, rightmost) member, deriving the expected model from resolveModel()
375
+ # rather than a second hardcoded table. Top-ness, not mere membership: a `model:` naming a lower
376
+ # declared member would silently run the agent at that lower tier regardless of ceiling -- the
377
+ # muted-reviewer failure `cost:` exists to prevent, re-opened by hand. `agents/` only -- commands
378
+ # declare neither `cost:` nor `model:` any more (asserted above), so there is nothing here to check
379
+ # them against.
380
+ for f in agents/*.md; do
381
+ [ -f "$f" ] || continue
382
+ got="$(cost_of "$f" | tr -d '[:space:]')"
383
+ [ -z "$got" ] && continue # already reported as COST TIER MISSING above
384
+ declared_model="$(model_of "$f" | tr -d '[:space:]')"
385
+ IFS=',' read -ra mv_values <<< "$got"
386
+ top="${mv_values[${#mv_values[@]}-1]}"
387
+ mv="model_for_$top"
388
+ expected="${!mv:-}"
389
+ # An unrecognized top value was already reported as COST TIER INVALID above -- nothing further
390
+ # to check here (no expected model to compare against).
391
+ if [ -n "$expected" ] && [ "$expected" != "$declared_model" ]; then
392
+ echo "MODEL/COST MISMATCH: $f declares cost: $got (top tier: $top) with model: $declared_model, expected '$expected' per scripts/lib/cost-model.mjs" >&2
393
+ cost_failed=1
394
+ fi
80
395
  done
81
- # MAX front-load commands run opus end-to-end (their orchestration is judgment-heavy).
82
- assert_model commands/discover.md opus
83
- assert_model commands/design.md opus
84
- assert_model commands/atlas.md opus
85
- if [ "$tier_failed" -ne 0 ]; then
396
+
397
+ if [ "$cost_failed" -ne 0 ]; then
86
398
  exit 1
87
399
  fi
88
400
 
89
- echo "==> Validating new MAX/ECO artifacts..."
401
+ echo "==> Validating cost-tier prose against coder/planner/refactorer's declared set..."
402
+ # coder, planner, and refactorer all declare the widened `low, medium` set above; a stale "declares
403
+ # cost: medium" claim about any of the three -- in a command's own explanatory prose, or in another
404
+ # agent's cross-reference -- understates what they can run at and drifts back to exactly the
405
+ # muted-capability bug this rework exists to close, silently and outside the frontmatter checks
406
+ # above (which only ever see the agent's OWN file, never a claim made about it elsewhere). Matched
407
+ # on the literal three-agent list, never a fourth: impact and incident are legitimately medium-only
408
+ # today, so a plain `cost: medium` claim about either is correct, not stale, and must not fire here.
409
+ stale_cost_claim_failed=0
410
+ if grep -rnE '(coder|planner|refactorer)[^\n]{0,80}cost: medium`' commands/ agents/ docs/ 2>/dev/null; then
411
+ echo "STALE COST CLAIM: coder/planner/refactorer all declare the widened 'cost: low, medium' -- the line(s) above still claim a plain 'cost: medium'" >&2
412
+ stale_cost_claim_failed=1
413
+ fi
414
+ if [ "$stale_cost_claim_failed" -ne 0 ]; then
415
+ exit 1
416
+ fi
417
+
418
+ echo "==> Validating command <-> somi-dispatch skill reference..."
419
+ # Every command that Tasks an agent directly resolves it through the same dispatch procedure the
420
+ # front door uses, not just when a request is routed through agents/somi.md. "Starts an agent"
421
+ # is DERIVED from the real agent basenames under agents/ against this repo's own call-site idioms
422
+ # (see tests/scripts/lib/dispatch-reference-gate.mjs) -- never a hand-typed command list, which
423
+ # would silently miss a new command that Tasks an agent without also adding it here.
424
+ # tests/scripts/dispatch-reference-gate.sh proves this gate RED (a `cp -a` copy with one command's
425
+ # reference removed) and GREEN, the same two-sided proof retirement-gate.sh and dispatch-guard.sh
426
+ # already give their own gates.
427
+ if ! node tests/scripts/lib/dispatch-reference-gate.mjs commands agents; then
428
+ exit 1
429
+ fi
430
+ bash tests/scripts/dispatch-reference-gate.sh
431
+
432
+ echo "==> Validating the stale-vocabulary retirement gate..."
433
+ # scripts/validate.sh only ever asserted frontmatter VALUES above, never prose -- so a
434
+ # half-converted ruleset (frontmatter switched to the new cost field, prose still naming the
435
+ # retired tiers) would otherwise pass silently. tests/scripts/lib/retirement-gate.mjs sweeps the
436
+ # roots below for the retired two-valued tier vocabulary and for hardcoded Claude model-name
437
+ # mentions outside frontmatter, exemptions named in its own header.
438
+ # tests/scripts/retirement-gate.sh proves this gate fails against a synthetic fixture still
439
+ # carrying the old vocabulary and passes against a clean one, per the trap the tools-doctrine
440
+ # sweep below documents (a check that can fire on its own fix needs to be proven against both
441
+ # states, not just trusted against the final one).
442
+ retirement_gate=$(node tests/scripts/lib/retirement-gate.mjs \
443
+ agents commands docs rules skills templates README.md CHANGELOG.md AGENTS.md .github \
444
+ .copilot-extension .claude-plugin examples hooks scripts tests)
445
+ case "$retirement_gate" in
446
+ ok*) echo " $retirement_gate" ;;
447
+ *)
448
+ echo "STALE VOCABULARY RETIREMENT GATE FAILED:" >&2
449
+ echo "$retirement_gate" >&2
450
+ exit 1
451
+ ;;
452
+ esac
453
+ bash tests/scripts/retirement-gate.sh
454
+
455
+ echo "==> Validating /ship-loop's non-overridable checkpoint..."
456
+ # /ship-loop's single mandatory human checkpoint moved from a cost-tier boundary (which
457
+ # stopped existing once commands declared no tier) to the brief handoff. Nothing else here fails
458
+ # the build if a later edit to commands/ship-loop.md quietly drops "non-overridable" or either of
459
+ # the two anchors the checkpoint fires at -- the brief handoff, and (on a cold start with no design
460
+ # action) after /plan-loop. tests/scripts/checkpoint-gate.sh proves this gate both ways, against
461
+ # the real file and against a `cp`'d copy with the wording deliberately weakened.
462
+ if ! node tests/scripts/lib/checkpoint-gate.mjs commands/ship-loop.md; then
463
+ exit 1
464
+ fi
465
+ bash tests/scripts/checkpoint-gate.sh
466
+
467
+ echo "==> Validating new cost-tier artifacts..."
90
468
  for f in \
91
469
  templates/BRIEF.md.tmpl \
92
470
  templates/DESIGN.md.tmpl \
@@ -106,7 +484,7 @@ for f in \
106
484
  exit 1
107
485
  fi
108
486
  done
109
- # The execution brief is the load-bearing MAX→ECO handoff — it must be referenced by
487
+ # The execution brief is the load-bearing design→execution handoff — it must be referenced by
110
488
  # the agents/commands that produce and consume it, not orphaned.
111
489
  if ! grep -rIlq 'BRIEF\.md\.tmpl' agents commands; then
112
490
  echo "templates/BRIEF.md.tmpl is not referenced by any agent or command" >&2
@@ -130,6 +508,289 @@ if [ "$index_failed" -ne 0 ]; then
130
508
  exit 1
131
509
  fi
132
510
 
511
+ echo "==> Validating agent <-> docs/AGENTS.md index completeness..."
512
+ # Every agents/<name>.md must have a matching '### <name>' section in docs/AGENTS.md, and every
513
+ # such section must have a matching agents/<name>.md file -- mirrors the skills <-> docs/SKILLS.md
514
+ # check above. Without this, a new agent file ships undocumented and stays green forever, which is
515
+ # exactly how refactor-designer shipped with no docs/AGENTS.md section for two review passes.
516
+ # Reserved heading level: '### ' in docs/AGENTS.md is read ENTIRELY as agent-section markers by
517
+ # this loop -- any other H3 (e.g. "### Cost tiering details") is misdiagnosed as an orphaned agent
518
+ # section. A non-agent subsection belongs at a different heading level (## or ####), not H3.
519
+ agent_index_failed=0
520
+ for f in agents/*.md; do
521
+ [ -f "$f" ] || continue
522
+ name="$(basename "$f" .md)"
523
+ if ! grep -qE "^### ${name}\$" docs/AGENTS.md; then
524
+ echo "AGENT NOT INDEXED: $name (docs/AGENTS.md has no '### $name' section)" >&2
525
+ agent_index_failed=1
526
+ fi
527
+ done
528
+ while IFS= read -r name; do
529
+ [ -z "$name" ] && continue
530
+ if [ ! -f "agents/$name.md" ]; then
531
+ echo "AGENT SECTION ORPHANED: docs/AGENTS.md has '### $name' but agents/$name.md does not exist -- if this is not an agent section, use ## or #### instead of ###" >&2
532
+ agent_index_failed=1
533
+ fi
534
+ done < <(grep -E '^### ' docs/AGENTS.md | sed 's/^### //')
535
+ if [ "$agent_index_failed" -ne 0 ]; then
536
+ exit 1
537
+ fi
538
+
539
+ echo "==> Validating command <-> docs/COMMANDS.md index completeness..."
540
+ # Every commands/<name>.md must appear as a linked row in docs/COMMANDS.md's catalogue table, and
541
+ # every linked row must correspond to a real commands/<name>.md file -- mirrors the agent <->
542
+ # docs/AGENTS.md check above. docs/COMMANDS.md has no '### <name>' sections, so this gate matches
543
+ # on the link form: only a catalogue-table row (a line starting with "| [") counts as an index
544
+ # entry -- prose mentioning ../commands/<name>.md elsewhere must not. Both directions read from
545
+ # the SAME indexed set below, so the table is checked against commands/ exactly, both ways.
546
+ command_index_failed=0
547
+ indexed_commands="$(grep -E '^\| \[' docs/COMMANDS.md | grep -oE '\.\./commands/[A-Za-z0-9_-]+\.md' | sed -E 's#^\.\./commands/##; s#\.md$##')"
548
+ for f in commands/*.md; do
549
+ [ -f "$f" ] || continue
550
+ name="$(basename "$f" .md)"
551
+ if ! grep -qxF "$name" <<< "$indexed_commands"; then
552
+ echo "COMMAND NOT INDEXED: $name (docs/COMMANDS.md's catalogue table has no link to ../commands/$name.md)" >&2
553
+ command_index_failed=1
554
+ fi
555
+ done
556
+ while IFS= read -r name; do
557
+ [ -z "$name" ] && continue
558
+ if [ ! -f "commands/$name.md" ]; then
559
+ echo "COMMAND LINK ORPHANED: docs/COMMANDS.md's catalogue table links to ../commands/$name.md but commands/$name.md does not exist -- if this is not a catalogue-table row, use a different link form outside the table" >&2
560
+ command_index_failed=1
561
+ fi
562
+ done <<< "$indexed_commands"
563
+ if [ "$command_index_failed" -ne 0 ]; then
564
+ exit 1
565
+ fi
566
+
567
+ echo "==> Validating command/skill namespace collisions..."
568
+ # (a) commands/ and skills/ share ONE namespace on Claude Code — a command and a skill with the
569
+ # same name collide, and the skill silently loses. That is the defect this check exists to catch:
570
+ # commands/test-strategy.md shadowed skills/test-strategy/SKILL.md, the skill never loaded,
571
+ # and nothing errored.
572
+ #
573
+ # Keyed on DIRECTORY name. That is sufficient under EITHER registration mechanism — not because
574
+ # the mechanism is settled (it is not; the probe is still open) but by composition: check (c)
575
+ # below forces declared-name == directory for every skill, so no command basename can equal any
576
+ # skill's declared name either. Unstated premise, verified today and unchecked: zero of the
577
+ # commands/*.md files declare a frontmatter `name:`. If one ever does, this composition breaks
578
+ # silently.
579
+ collision_failed=0
580
+ for f in commands/*.md; do
581
+ [ -f "$f" ] || continue
582
+ name="$(basename "$f" .md)"
583
+ if [ -f "skills/$name/SKILL.md" ]; then
584
+ echo "NAMESPACE COLLISION: commands/$name.md and skills/$name/SKILL.md — the skill will be shadowed" >&2
585
+ collision_failed=1
586
+ fi
587
+ done
588
+ if [ "$collision_failed" -ne 0 ]; then
589
+ exit 1
590
+ fi
591
+
592
+ echo "==> Validating skill frontmatter name <-> directory parity..."
593
+ # (c) A skill's declared `name:` and its directory must agree. A mismatch is invisible to every
594
+ # other gate here: reverting a renamed skill's `name:` once left BOTH acceptance
595
+ # greps plus the whole suite green. Whether the host registers on directory or on `name:`
596
+ # is not settled (evidence points at directory — Anthropic's hookify ships a mismatch and its own
597
+ # commands invoke the directory name), so this ships as a parity/hygiene assertion: an
598
+ # undetectable inconsistency between the two is worth failing on either way. Do NOT reword this
599
+ # as "prevents a collision" until the mechanism probe has returned.
600
+ parity_failed=0
601
+ for f in skills/*/SKILL.md; do
602
+ [ -f "$f" ] || continue
603
+ dir="$(basename "$(dirname "$f")")"
604
+ declared="$(awk '/^---$/{c++; next} c==1 && /^name:[[:space:]]*/{sub(/^name:[[:space:]]*/,""); gsub(/^["'"'"']|["'"'"']$/,""); sub(/[[:space:]]+$/,""); print; exit}' "$f")"
605
+ if [ "$dir" != "$declared" ]; then
606
+ echo "SKILL NAME PARITY: skills/$dir/SKILL.md declares name: '$declared' (expected '$dir')" >&2
607
+ parity_failed=1
608
+ fi
609
+ done
610
+ if [ "$parity_failed" -ne 0 ]; then
611
+ exit 1
612
+ fi
613
+
614
+ echo "==> Validating review-agent write-discipline contracts..."
615
+ # (d) Five documents assert that every review-type agent carries a `## Write discipline` section,
616
+ # and /review-panel's argument for running four lenses concurrently DEPENDS on it. A fifth review
617
+ # agent added without one falsifies all five at once and silently holes that rationale. The
618
+ # two-part sweep below finds false statements; only this finds a MISSING one.
619
+ contract_failed=0
620
+ # DERIVED, not hardcoded: the seated lenses are read out of commands/review-panel.md's own table —
621
+ # the document whose concurrency rationale depends on the claim. A hardcoded list cannot detect the
622
+ # threat this check exists for (a FIFTH review agent seated without a contract); it would only
623
+ # catch removal from the four already known.
624
+ # Extraction is deliberately NAME-AGNOSTIC: any backticked cell leading a table row. An earlier
625
+ # form matched `*-reviewer`/`*-strategist`, which caught a seated `perf-reviewer` but would have
626
+ # let `accessibility-auditor` or `perf-lens` through silently — and because the other four still
627
+ # derived, the vacuity guard below would not have fired either. Trade accepted deliberately: a
628
+ # future table in this file leading with a backticked non-agent cell now produces a LOUD, named
629
+ # MISSING AGENT error rather than a silent miss. Loud-and-wrong is diagnosable; silent-and-missing
630
+ # is the defect class this check exists to remove.
631
+ seated="$(grep -oE '^\| *`[a-z][a-z0-9-]*`' commands/review-panel.md | tr -d '|` ' | sort -u)"
632
+ if [ -z "$seated" ]; then
633
+ echo "WRITE CONTRACT CHECK: found no seated lenses in commands/review-panel.md — table shape changed?" >&2
634
+ contract_failed=1
635
+ fi
636
+ for a in $seated; do
637
+ if [ ! -f "agents/$a.md" ]; then
638
+ echo "MISSING AGENT: commands/review-panel.md seats '$a' but agents/$a.md does not exist" >&2
639
+ contract_failed=1
640
+ elif ! grep -q '^## Write discipline' "agents/$a.md"; then
641
+ echo "MISSING WRITE CONTRACT: agents/$a.md has no '## Write discipline' section" >&2
642
+ contract_failed=1
643
+ fi
644
+ done
645
+ if [ "$contract_failed" -ne 0 ]; then
646
+ exit 1
647
+ fi
648
+ # pr is never seated in commands/review-panel.md (it is not a review lens), so the derived sweep
649
+ # above cannot cover it -- but its own contract is load-bearing (agents/pr.md's Write discipline
650
+ # section is the only thing gating an ungated `gh pr create`), so assert it directly.
651
+ if ! grep -q '^## Write discipline' agents/pr.md; then
652
+ echo "MISSING WRITE CONTRACT: agents/pr.md has no '## Write discipline' section" >&2
653
+ exit 1
654
+ fi
655
+
656
+ echo "==> Validating the tools-doctrine two-part sweep..."
657
+ # The `read-only` grep STRUCTURALLY cannot find false-rationale locations that omit the phrase —
658
+ # which is why docs/AGENTS.md and docs/COMMANDS.md had to be hand-added to the sweep list,
659
+ # and why docs/EXTENDING.md was missed entirely until code review. Both patterns must stay clean.
660
+ # Pattern 2 targets the false RATIONALE, not the token `tools:` — a broader pattern matches the
661
+ # corrected text too, and a check that fires on its own fix is a check nobody keeps.
662
+ sweep_failed=0
663
+ # SWEEP ROOTS: all eight trees. An earlier draft ran three and silently dropped rules/ —
664
+ # the digest SOURCE injected into every gated turn of every consuming project, and one the
665
+ # parity-only drift gate below cannot cover (it verifies the copies match the canonical, never
666
+ # that the canonical is true).
667
+ SWEEP_ROOTS="agents/ commands/ docs/ rules/ skills/ templates/ AGENTS.md .github/"
668
+ # Pattern 1 must cover BOTH grammatical shapes the false claim takes. An earlier draft matched
669
+ # only "does not have Write/Edit" and "agent is read-only (Read" — 4 of the 12 known instances,
670
+ # missing every commands/review-panel.md case and docs/WORKFLOWS.md:290, which are the two
671
+ # worst cases because /review-panel's concurrency argument rests on them. The
672
+ # `by contract` filter is what lets the CORRECTED text through: it says read-only and means it.
673
+ if grep -rnE 'do(es)? not have (Write|Edit)|agent is read-only \(Read|(lens|lenses|[Rr]eviewer|review agents?) (is|are) \*{0,2}read-only|read-only review (lens|lenses|agents?)' $SWEEP_ROOTS 2>/dev/null | grep -vE 'read-only \*{0,2}(by contract|\*{0,2} ?by contract)'; then
674
+ echo "FALSE CAPABILITY CLAIM: an agent/lens is described as lacking Write/Edit; no SoMi agent declares tools: — restate as a contract" >&2
675
+ sweep_failed=1
676
+ fi
677
+ # Pattern 2 targets the false RATIONALE, never the token `tools:` — a broader pattern matches the
678
+ # corrected text too, and a check that fires on its own fix is a check nobody keeps. `cross-runtime
679
+ # compat` rather than bare `cross-runtime`: this repo legitimately discusses cross-host runtime
680
+ # portability in docs/HOOKS.md, INSTALL.md, PLUGIN.md and architecture.md, and firing there would
681
+ # report "FALSE TOOLS RATIONALE" about a sentence with nothing to do with tools.
682
+ if grep -rniE 'cross-runtime compat|leave it unrestricted|works across Claude Code and GitHub Copilot|declares its own tools' $SWEEP_ROOTS 2>/dev/null; then
683
+ echo "FALSE TOOLS RATIONALE: both hosts support tools:; omission is a simplicity choice, not compatibility" >&2
684
+ sweep_failed=1
685
+ fi
686
+ if [ "$sweep_failed" -ne 0 ]; then
687
+ exit 1
688
+ fi
689
+
690
+ echo "==> Validating digest parity across the three copies..."
691
+ # (b) The canonical rules/CLAUDE.md is the only editable copy; AGENTS.md and
692
+ # .github/copilot-instructions.md are generated. Hand-syncing three copies is what let the Copilot
693
+ # copy silently lose the `Reasoning craft` bullet. This is the DRIFT GATE — tests/scripts/
694
+ # generate-digest.sh is the generator's unit guard, which is a different thing.
695
+ if ! node scripts/generate-digest.mjs --check; then
696
+ echo "DIGEST DRIFT: regenerate with \`node scripts/generate-digest.mjs\`" >&2
697
+ exit 1
698
+ fi
699
+
700
+ echo "==> Validating version consistency across the six stamped locations..."
701
+ # (e) VERSION, package.json, both plugin manifests and both marketplace manifests must agree.
702
+ #
703
+ # CORRECTED at code review: an earlier comment here claimed "release stamps them at publish time,
704
+ # so drift is latent rather than active." That is false, and the false premise is what made this
705
+ # check look sufficient. `.github/workflows/publish.yml` runs `npm pkg set version=…` against an
706
+ # rsync'd copy — it stamps **package.json alone**, then asserts the checked-out tree is unchanged.
707
+ # The other five ship in the tarball at whatever value is committed. So every release publishes
708
+ # package.json at N+1 beside five files at N, and this check runs PRE-stamp and structurally
709
+ # cannot see that. It is still worth having — it catches a hand-bump that updates some but not
710
+ # all six — but do not extend it to the packed output on the strength of the old rationale.
711
+ #
712
+ # Parsed with node, not grep: two of the six carry the version at a nested array path
713
+ # (.plugins[0].version, .extensions[0].version), which a line-oriented grep cannot address.
714
+ # NOTE package-lock.json is deliberately NOT in the set — it carries the version at two paths and
715
+ # is regenerated by `npm install`, not hand-bumped; adding it would fail on a legitimate workflow.
716
+ version_report="$(node -e '
717
+ const fs = require("fs");
718
+ const read = (label, fn) => { try { return { label, value: fn() }; } catch (e) { return { label, value: undefined, err: e.message }; } };
719
+ const j = (p) => JSON.parse(fs.readFileSync(p, "utf8"));
720
+ // Each read is individually guarded. An earlier form evaluated the two nested accesses OUTSIDE the
721
+ // guard, so a manifest whose plugins/extensions array was empty — still valid JSON, so the earlier
722
+ // json_valid loop passes it — died on a TypeError stack instead of reaching the diagnostic below.
723
+ const found = [
724
+ read("VERSION", () => fs.readFileSync("VERSION", "utf8").trim()),
725
+ read("package.json", () => j("package.json").version),
726
+ read(".claude-plugin/plugin.json", () => j(".claude-plugin/plugin.json").version),
727
+ read(".claude-plugin/marketplace.json", () => j(".claude-plugin/marketplace.json").plugins[0].version),
728
+ read(".copilot-extension/extension.json", () => j(".copilot-extension/extension.json").version),
729
+ read(".copilot-extension/marketplace.json", () => j(".copilot-extension/marketplace.json").extensions[0].version),
730
+ ];
731
+ const missing = found.filter((f) => !f.value);
732
+ if (missing.length) {
733
+ console.error("VERSION UNREADABLE:");
734
+ for (const m of missing) console.error(" " + m.label + (m.err ? " (" + m.err + ")" : ""));
735
+ process.exit(1);
736
+ }
737
+ const distinct = [...new Set(found.map((f) => f.value))];
738
+ if (distinct.length !== 1) {
739
+ console.error("VERSION MISMATCH across the six stamped locations:");
740
+ for (const f of found) console.error(" " + f.value + " " + f.label);
741
+ process.exit(1);
742
+ }
743
+ ' 2>&1)" || { echo "$version_report" >&2; exit 1; }
744
+
745
+ echo "==> Validating relative markdown links..."
746
+ # (f) Every git-tracked *.md except CHANGELOG.md (generated release history). `.somi/` needs no
747
+ # filter — it is gitignored, so `git ls-files` cannot produce a path inside it.
748
+ #
749
+ # FENCED AND INLINE CODE ARE SKIPPED, and that is the correctness story: a fence-blind first draft
750
+ # flagged four *displayed sample links* in examples/feature-plan-example.md as dead, and "fixing"
751
+ # them wrote a CI token into the rendered body of the example that ships to npm. Scans whole-file
752
+ # content, so a link whose text wraps across lines is seen (this repo hard-wraps at ~100 chars);
753
+ # reference-style links are resolved.
754
+ #
755
+ # A link that must stay live but whose target lives outside this repo carries an inline same-line
756
+ # `<!-- illustrative-path -->` marker — scoped to examples/, so a marker anywhere else FAILS rather
757
+ # than exempts. A marker on a link that DOES resolve fails too, so the hatch cannot outlive its
758
+ # reason. Prefer a code span or a fence over a marker; see check-links.mjs's header.
759
+ if ! node scripts/check-links.mjs; then
760
+ exit 1
761
+ fi
762
+
763
+ echo "==> Validating no session-artefact references in shipped code and prose..."
764
+ # Comments in hooks/ and scripts/, and every line of agents/, commands/, skills/, must not point at
765
+ # the gitignored .somi/ planning folder (finding ids, decision tags, iteration/phase numbers) --
766
+ # a reader who cloned the repo cannot resolve them. Scope, patterns and exclusions live in
767
+ # scripts/check-session-artefacts.mjs.
768
+ if ! node scripts/check-session-artefacts.mjs; then
769
+ exit 1
770
+ fi
771
+
772
+ echo "==> Validating file-size budgets..."
773
+ # Prompt files 300 lines, .mjs 500, .sh 800 (tracked files only). Files already over budget are
774
+ # recorded in scripts/size-budget-overrides.json and may not grow past their recorded size.
775
+ # Budgets and ledger governance live in the header of scripts/check-size-budget.mjs.
776
+ if ! node scripts/check-size-budget.mjs; then
777
+ exit 1
778
+ fi
779
+
780
+ echo "==> Validating the trivial threshold is defined once and referenced by /code..."
781
+ # Routing is model-judged, so the testable invariant is structural: the definition exists in the
782
+ # routing skill and the /code command points at it rather than restating it.
783
+ if ! grep -q '^## The trivial threshold' skills/somi-routing/SKILL.md; then
784
+ echo "FAIL: skills/somi-routing/SKILL.md lacks the 'The trivial threshold' section" >&2
785
+ exit 1
786
+ fi
787
+ if ! grep -q 'somi-routing/SKILL.md#the-trivial-threshold' commands/code.md; then
788
+ echo "FAIL: commands/code.md does not reference the trivial threshold" >&2
789
+ exit 1
790
+ fi
791
+
792
+ # Coder: Decision Ladder step sits between "Map the change" and "Implement"; no-plan path cites the threshold.
793
+ { awk '/^[0-9]+\. \*\*Map the change/{m=NR} /^[0-9]+\. \*\*Climb the Decision Ladder/{l=NR} /^[0-9]+\. \*\*Implement the smallest/{i=NR} END{exit !(m && l>m && i>l)}' agents/coder.md && grep -q 'somi-routing/SKILL.md#the-trivial-threshold' agents/coder.md; } || { echo "FAIL: agents/coder.md needs the Decision Ladder between Map and Implement, and the trivial-threshold reference" >&2; exit 1; }
133
794
  echo "==> Creating coverage stub..."
134
795
  mkdir -p coverage
135
796
  printf 'TN:\nend_of_record\n' > coverage/lcov.info