@skathio/somi 2.2.2 → 3.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 (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 +225 -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 +691 -30
  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 +366 -0
  128. package/tests/scripts/somi-mcp.sh +12 -0
@@ -0,0 +1,287 @@
1
+ #!/usr/bin/env bash
2
+ # Unit guard for tests/scripts/lib/retirement-gate.mjs (the stale-vocabulary retirement gate).
3
+ #
4
+ # The gate exists to catch a half-converted file that scripts/validate.sh's frontmatter
5
+ # assertions structurally cannot see. validate.sh:296-300 already documents the trap a check like
6
+ # this can fall into: a pattern broad enough to match the CORRECTED text fires on its own fix, and
7
+ # a check that fires on its own fix is a check nobody keeps. So this proves the gate BOTH ways —
8
+ # red against a synthetic fixture still carrying the retired vocabulary, green against a clean one
9
+ # — rather than trusting it because the real tree happens to pass today.
10
+ #
11
+ # The gate exits 0 for every SCAN outcome (clean or stale) and signals purely through stdout
12
+ # content (`ok*` vs. anything else) — a scan result must never exit non-zero, because
13
+ # scripts/validate.sh assigns its stdout via command substitution under `set -euo pipefail`, and a
14
+ # plain assignment's exit status is the substitution's: a non-zero exit there kills the caller at
15
+ # the assignment, before the `case` that prints the hit list ever runs. The CALLER SHAPE case below
16
+ # reproduces that exact seam. (A missing-argument usage error is a different case, exits 2, and
17
+ # reaches the terminal via stderr instead — see the gate's own exit-contract comment.)
18
+ set -uo pipefail
19
+
20
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
21
+ GATE="$ROOT/tests/scripts/lib/retirement-gate.mjs"
22
+
23
+ pass=0; fail=0
24
+ ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
25
+ bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
26
+
27
+ echo "== stale-vocabulary retirement gate =="
28
+
29
+ TMP="$(mktemp -d)"
30
+ trap 'rm -rf "$TMP"' EXIT
31
+
32
+ # --- RED: a synthetic fixture still carrying the retired vocabulary must fail -------------------
33
+ STALE="$TMP/stale"; mkdir -p "$STALE/agents" "$STALE/commands"
34
+ cat > "$STALE/agents/example.md" <<'EOF'
35
+ ---
36
+ name: example
37
+ description: An example agent.
38
+ model: sonnet
39
+ ---
40
+
41
+ > **Tier: ECO (`sonnet`).** This agent runs on the ECO tier and hands off to the MAX tier when
42
+ > deeper design is needed. See the MAX->ECO handoff for details.
43
+ EOF
44
+
45
+ out="$(cd "$STALE" && node "$GATE" agents commands 2>&1)"; rc=$?
46
+ if [ "$rc" -eq 0 ]; then
47
+ ok "gate always exits 0, even against a stale fixture (signals failure via stdout content only)"
48
+ else
49
+ bad "gate exited non-zero ($rc) against a stale fixture -- it must always exit 0 (got: $out)"
50
+ fi
51
+ case "$out" in
52
+ "STALE VOCABULARY"*) ok "gate's stdout starts with STALE VOCABULARY against a fixture that still carries MAX/ECO vocabulary" ;;
53
+ *) bad "gate's stdout does not start with STALE VOCABULARY against a fixture that still carries MAX/ECO vocabulary (got: $out)" ;;
54
+ esac
55
+ case "$out" in
56
+ *"STALE VOCABULARY"*"ECO"*) ok "gate's report names the stale hit" ;;
57
+ *) bad "gate's report does not name the stale hit (got: $out)" ;;
58
+ esac
59
+
60
+ # --- RED: a hardcoded model name outside frontmatter must also fail -----------------------------
61
+ STALE2="$TMP/stale2"; mkdir -p "$STALE2/commands"
62
+ cat > "$STALE2/commands/example.md" <<'EOF'
63
+ ---
64
+ description: An example command.
65
+ model: sonnet
66
+ ---
67
+
68
+ Task the reviewer agent (`opus`) on a fresh context.
69
+ EOF
70
+ out2="$(cd "$STALE2" && node "$GATE" commands 2>&1)"; rc2=$?
71
+ if [ "$rc2" -eq 0 ]; then
72
+ ok "gate always exits 0 against a fixture with a hardcoded model name in prose"
73
+ else
74
+ bad "gate exited non-zero ($rc2) against a fixture with a hardcoded model name in prose (got: $out2)"
75
+ fi
76
+ case "$out2" in
77
+ "STALE VOCABULARY"*) ok "gate's stdout starts with STALE VOCABULARY for a hardcoded model name in prose" ;;
78
+ *) bad "gate's stdout does not start with STALE VOCABULARY for a hardcoded model name in prose (got: $out2)" ;;
79
+ esac
80
+
81
+ # --- CALLER SHAPE: reproduce scripts/validate.sh's own `assignment under set -e` + `case` idiom -
82
+ # against the stale fixture, line for line. This is the exact seam the dead-diagnostic bug lived
83
+ # in: node exiting non-zero under `set -euo pipefail` killed the caller at a plain assignment,
84
+ # silently, before the `case` that prints the hit list ever ran. A regression here (the gate
85
+ # exiting non-zero again) makes this fail the same way the real bug did: the diagnostic never
86
+ # reaches `caller_out` at all.
87
+ caller_out="$(
88
+ exec 2>&1
89
+ set -euo pipefail
90
+ cd "$STALE"
91
+ retirement_gate=$(node "$GATE" agents commands)
92
+ case "$retirement_gate" in
93
+ ok*) echo " $retirement_gate" ;;
94
+ *)
95
+ echo "STALE VOCABULARY RETIREMENT GATE FAILED:" >&2
96
+ echo "$retirement_gate" >&2
97
+ exit 1
98
+ ;;
99
+ esac
100
+ )"
101
+ caller_rc=$?
102
+ if [ "$caller_rc" -eq 1 ]; then
103
+ ok "caller-shape subshell exits 1 via the case's own exit"
104
+ else
105
+ bad "caller-shape subshell exited $caller_rc, expected 1 from the case block (got: $caller_out)"
106
+ fi
107
+ case "$caller_out" in
108
+ *"STALE VOCABULARY RETIREMENT GATE FAILED:"*"ECO"*)
109
+ ok "caller-shape diagnostic reaches output: header and the stale hit are both present" ;;
110
+ *)
111
+ bad "caller-shape diagnostic did not reach output -- the assignment likely died under set -e before the case ran (got: $caller_out)" ;;
112
+ esac
113
+
114
+ # --- GREEN: the converted-style equivalent must pass ---------------------------------------------
115
+ CLEAN="$TMP/clean"; mkdir -p "$CLEAN/agents" "$CLEAN/commands"
116
+ cat > "$CLEAN/agents/example.md" <<'EOF'
117
+ ---
118
+ name: example
119
+ description: An example agent.
120
+ model: sonnet
121
+ cost: medium
122
+ ---
123
+
124
+ > **Cost: medium (`cost: medium`).** This agent runs at cost: medium and hands off to cost: high
125
+ > when deeper design is needed. See the design->execution handoff for details.
126
+ EOF
127
+ cat > "$CLEAN/commands/example.md" <<'EOF'
128
+ ---
129
+ description: An example command.
130
+ model: sonnet
131
+ cost: medium
132
+ ---
133
+
134
+ Task the reviewer agent (`cost: high`) on a fresh context.
135
+ EOF
136
+
137
+ if out3="$(cd "$CLEAN" && node "$GATE" agents commands 2>&1)"; then
138
+ ok "gate exits 0 against a fully-converted fixture"
139
+ else
140
+ bad "gate exits non-zero against a fully-converted fixture (got: $out3)"
141
+ fi
142
+ case "$out3" in
143
+ ok*) ok "gate's report starts with 'ok' on the clean fixture" ;;
144
+ *) bad "gate's report does not start with 'ok' on the clean fixture (got: $out3)" ;;
145
+ esac
146
+
147
+ # --- Frontmatter `model:` line is structural, not vocabulary: alone, it must not fail -----------
148
+ FRONTMATTER_ONLY="$TMP/frontmatter-only"; mkdir -p "$FRONTMATTER_ONLY/agents"
149
+ cat > "$FRONTMATTER_ONLY/agents/example.md" <<'EOF'
150
+ ---
151
+ name: example
152
+ description: An example agent with only a bare model: line, no other vocabulary.
153
+ model: opus
154
+ cost: high
155
+ ---
156
+
157
+ Ordinary body text with no retired vocabulary anywhere in it.
158
+ EOF
159
+ if out4="$(cd "$FRONTMATTER_ONLY" && node "$GATE" agents 2>&1)"; then
160
+ ok "a bare frontmatter 'model: opus' line alone does not fail the gate"
161
+ else
162
+ bad "a bare frontmatter 'model: opus' line alone failed the gate (got: $out4)"
163
+ fi
164
+
165
+ # --- RED: a bare `model: opus` line OUTSIDE frontmatter and outside any fence must fail -- the ---
166
+ # exemption is POSITIONAL, not "any column-0 line reading model: <value>, anywhere in the file" --
167
+ POSITIONAL="$TMP/positional"; mkdir -p "$POSITIONAL/agents"
168
+ cat > "$POSITIONAL/agents/example.md" <<'EOF'
169
+ ---
170
+ name: example
171
+ description: An example agent.
172
+ model: sonnet
173
+ cost: high
174
+ ---
175
+
176
+ Some ordinary prose above a stray line.
177
+
178
+ model: opus
179
+
180
+ More ordinary prose below it.
181
+ EOF
182
+ out7="$(cd "$POSITIONAL" && node "$GATE" agents 2>&1)"
183
+ case "$out7" in
184
+ "STALE VOCABULARY"*) ok "a bare 'model: opus' line outside frontmatter and outside a fence fails the gate" ;;
185
+ *) bad "a bare 'model: opus' line outside frontmatter and outside a fence did not fail the gate -- the exemption is lexical again, not positional (got: $out7)" ;;
186
+ esac
187
+
188
+ # --- GREEN: a `model: opus` line INSIDE a fenced code block teaching the frontmatter shape -------
189
+ # (docs/EXTENDING.md's and docs/COMMANDS.md's "Adding an agent/command" recipes) must NOT fail ---
190
+ FENCED="$TMP/fenced"; mkdir -p "$FENCED/docs"
191
+ cat > "$FENCED/docs/example.md" <<'EOF'
192
+ ## Adding an agent
193
+
194
+ ```markdown
195
+ ---
196
+ name: <name>
197
+ description: ...
198
+ model: opus
199
+ cost: high
200
+ ---
201
+ ```
202
+
203
+ More prose after the fence, with no retired vocabulary.
204
+ EOF
205
+ out8="$(cd "$FENCED" && node "$GATE" docs 2>&1)"
206
+ case "$out8" in
207
+ ok*) ok "a 'model: opus' line inside a fenced documentation example does not fail the gate" ;;
208
+ *) bad "a 'model: opus' line inside a fenced documentation example failed the gate (got: $out8)" ;;
209
+ esac
210
+
211
+ # --- RED: a capitalized model name in prose must also fail -- MODEL_PATTERN is case-insensitive --
212
+ CAPS="$TMP/caps"; mkdir -p "$CAPS/docs"
213
+ cat > "$CAPS/docs/example.md" <<'EOF'
214
+ Opus front-loads the reasoning; Sonnet executes; Haiku is the cheapest tier.
215
+ EOF
216
+ out9="$(cd "$CAPS" && node "$GATE" docs 2>&1)"
217
+ case "$out9" in
218
+ "STALE VOCABULARY"*) ok "a capitalized model name ('Opus') in prose fails the gate" ;;
219
+ *) bad "a capitalized model name in prose did not fail the gate -- MODEL_PATTERN missed the capitalized spelling (got: $out9)" ;;
220
+ esac
221
+
222
+ # --- A named exemption (e.g. CHANGELOG.md) keeps carrying the old words without failing ---------
223
+ EXEMPT="$TMP/exempt"; mkdir -p "$EXEMPT"
224
+ cat > "$EXEMPT/CHANGELOG.md" <<'EOF'
225
+ ## [1.1.0] - MAX/ECO economy & the execution brief
226
+
227
+ Re-tiers SoMi's models: the MAX tier (opus) front-loads; the ECO tier (sonnet) executes.
228
+ EOF
229
+ if out5="$(cd "$EXEMPT" && node "$GATE" . 2>&1)"; then
230
+ ok "CHANGELOG.md keeps the retired vocabulary without failing the gate (named exemption)"
231
+ else
232
+ bad "CHANGELOG.md failed the gate despite being a named exemption (got: $out5)"
233
+ fi
234
+
235
+ # --- tests/evals/results/ is skipped even though it is swept ------------------------------------
236
+ EVALS="$TMP/evals"; mkdir -p "$EVALS/tests/evals/results"
237
+ cat > "$EVALS/tests/evals/results/transcript.json" <<'EOF'
238
+ {"transcript": "Depth gate: proceeding on ECO (`/plan`), not escalating to MAX."}
239
+ EOF
240
+ if out6="$(cd "$EVALS" && node "$GATE" tests 2>&1)"; then
241
+ ok "tests/evals/results/ is skipped even though a transcript inside it carries the old words"
242
+ else
243
+ bad "tests/evals/results/ was swept and failed the gate (got: $out6)"
244
+ fi
245
+
246
+ # --- RED: an odd run of fence markers must not leave the fence tracker stuck open ---------------
247
+ # A boolean toggle flips on ANY backtick run, so a four-backtick-fenced block whose own CONTENT
248
+ # contains a three-backtick line (an odd count: open, content, close = 3 toggles, ending true)
249
+ # leaves the tracker believing it is still inside a fence for the rest of the file -- silently
250
+ # exempting a real, bare `model:` line in ordinary prose below it. CommonMark's rule (track the
251
+ # opening marker's length, close only on a marker at least as long) must not make this mistake.
252
+ FENCE_NESTING="$TMP/fence-nesting"; mkdir -p "$FENCE_NESTING/docs"
253
+ printf '%s\n' \
254
+ 'Some prose above.' \
255
+ '' \
256
+ '````' \
257
+ 'A fenced block using four backticks.' \
258
+ '```' \
259
+ 'This inner line has exactly three backticks; a boolean toggle would flip on it too.' \
260
+ '````' \
261
+ '' \
262
+ 'model: opus' \
263
+ '' \
264
+ 'More prose below the real close.' \
265
+ > "$FENCE_NESTING/docs/example.md"
266
+ out10="$(cd "$FENCE_NESTING" && node "$GATE" docs 2>&1)"
267
+ case "$out10" in
268
+ "STALE VOCABULARY"*"model: opus"*)
269
+ ok "a bare 'model: opus' line after an odd-count nested fence run still fails the gate" ;;
270
+ *)
271
+ bad "an odd-count nested fence run left the tracker stuck open -- 'model: opus' below it was silently exempted (got: $out10)" ;;
272
+ esac
273
+
274
+ # --- Pin EXEMPT_FILES.size so growing the exemption list is a deliberate, visible edit -----------
275
+ exempt_count="$(awk '
276
+ /^const EXEMPT_FILES = new Set\(\[$/ { f=1; next }
277
+ f && /^\]\);$/ { f=0; next }
278
+ f { print }
279
+ ' "$GATE" | grep -c "'")"
280
+ if [ "$exempt_count" -eq 10 ]; then
281
+ ok "EXEMPT_FILES has exactly 10 entries (growing the list is now a visible test failure, not a silent edit)"
282
+ else
283
+ bad "EXEMPT_FILES has $exempt_count entries, expected 10 -- if the exemption list grew on purpose, update this pin deliberately"
284
+ fi
285
+
286
+ echo "retirement gate tests: $pass ok, $fail failed"
287
+ [ "$fail" -eq 0 ] || exit 1
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env bash
2
+ # Proves the lens membership validate.sh's write-discipline check DERIVES from
3
+ # commands/review-panel.md's table (same extraction regex) includes every seated review agent, and
4
+ # that the check goes RED in a `cp -a` copy when a seated agent loses its `## Write discipline`.
5
+ # Chained from dispatch-reference-gate.sh (validate.sh is at its size budget).
6
+ set -uo pipefail
7
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
8
+ pass=0; fail=0
9
+ ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
10
+ bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
11
+ derive() { grep -oE '^\| *`[a-z][a-z0-9-]*`' "$1/commands/review-panel.md" | tr -d '|` ' | sort -u; }
12
+
13
+ echo "== review-panel seated-lens derivation =="
14
+ seated="$(derive "$ROOT")"
15
+ for a in reviewer security-reviewer architecture-reviewer test-strategist plan-reviewer sdlc-reviewer; do
16
+ if grep -qx "$a" <<<"$seated"; then ok "derived membership includes $a"; else bad "derived membership is missing $a"; fi
17
+ grep -q '^## Write discipline' "$ROOT/agents/$a.md" && ok "agents/$a.md has Write discipline" || bad "agents/$a.md lacks Write discipline"
18
+ done
19
+ # Each seated lens is also named in the parallel-start block, so a seat cannot exist without a start.
20
+ for a in $seated; do
21
+ grep -qE "^Task +$a " "$ROOT/commands/review-panel.md" && ok "parallel start Tasks $a" || bad "parallel start does not Task $a"
22
+ done
23
+
24
+ TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
25
+ cp -a "$ROOT/commands" "$ROOT/agents" "$TMP/"
26
+ sed -i '/^## Write discipline/d' "$TMP/agents/plan-reviewer.md"
27
+ red=0
28
+ for a in $(derive "$TMP"); do grep -q '^## Write discipline' "$TMP/agents/$a.md" || red=$((red+1)); done
29
+ [ "$red" -eq 1 ] && ok "RED: removing plan-reviewer's Write discipline is caught via the derived table" || bad "RED fixture caught $red agents, expected 1"
30
+
31
+ echo "review-panel-seats tests: $pass ok, $fail failed"
32
+ [ "$fail" -eq 0 ] || exit 1
@@ -89,6 +89,25 @@ printf 'four\n' >> src/b.txt # weighted 8 > cap 6
89
89
  expect_exit "check-diff: over weighted cap exits 3" 3 \
90
90
  node "$LOOP" check-diff --slug demo --iteration 1.1
91
91
 
92
+ # `git diff` reads the index and tracked work-tree paths, so a file git
93
+ # has never been told about is in NEITHER -- a brand-new file counted zero until
94
+ # someone ran `git add`, and the cap under-measured by the whole size of every
95
+ # file an iteration introduced. Silently, and in the direction that lets work
96
+ # through. Measured on the same tree before and after the file exists, rather
97
+ # than asserted against a hardcoded total that would drift with the block above.
98
+ node "$LOOP" init --force --slug untracked --loop code --iteration 1.1 \
99
+ --files "src/new.txt" --diff-cap 100 >/dev/null
100
+ before="$(node "$LOOP" check-diff --slug untracked --iteration 1.1 | jq .diff_lines)"
101
+ printf 'x\ny\nz\n' > src/new.txt # untracked: never `git add`ed
102
+ after="$(node "$LOOP" check-diff --slug untracked --iteration 1.1 | jq .diff_lines)"
103
+ check "check-diff: an untracked file counts its lines (F-220)" \
104
+ "$([[ "$after" == "$((before + 3))" ]]; echo $?)"
105
+
106
+ printf 'churn\n' > .somi/untracked-note.md # excluded pathspec, must stay 0
107
+ after2="$(node "$LOOP" check-diff --slug untracked --iteration 1.1 | jq .diff_lines)"
108
+ check "check-diff: untracked .somi files stay excluded (F-220)" \
109
+ "$([[ "$after2" == "$after" ]]; echo $?)"
110
+
92
111
  # --- somi-loop: record/finish/resume (session-death recovery) -------------------
93
112
  node "$LOOP" record-pass --slug demo --iteration 1.1 --verdict request-changes --blockers 0 --majors 2 >/dev/null
94
113
  out="$(node "$LOOP" resume --slug demo --iteration 1.1)"
@@ -99,6 +118,169 @@ out="$(node "$LOOP" stats --slug demo --iteration 1.1)"
99
118
  check "finish: status recorded for the run ledger" \
100
119
  "$(jq -e '.status == "stopped-diff-cap"' <<<"$out" >/dev/null; echo $?)"
101
120
 
121
+ # --- somi-loop: mid-loop cap re-resolution without --force ---------------
122
+ # commands/code-loop.md's documented remedy for a fired gate: "the user adjusts the
123
+ # env var explicitly and re-runs — the loop does not 'decide' to widen its own
124
+ # bounds." Before this fix, caps were resolved only at `init` and frozen into state:
125
+ # setting the env var and re-running `pass`/`check-diff` changed nothing, and the
126
+ # only path that DID re-resolve (`init --force`) discarded pass history — the one
127
+ # thing a mid-loop raise must not do. This block is the regression guard: it fails
128
+ # red against the pre-fix scripts/somi-loop.mjs (verified by hand, not committed —
129
+ # see the coder's summary) and asserts the remedy now actually works, on the SAME
130
+ # subcommand, without losing baseline/history, with the raise persisted for audit.
131
+ #
132
+ # Runs against ITS OWN throwaway repo — $REPO above has, by this point, accumulated
133
+ # scenario-specific mutations to src/a.txt and src/b.txt plus an untracked src/new.txt
134
+ # from earlier sections; none are in capfix's iteration_files, so every one of them
135
+ # would count double against its narrow 4-line cap. Same reasoning as the golden
136
+ # section further down, which isolates itself for exactly this reason.
137
+ F29_REPO="$TMP/f29-repo"
138
+ mkdir -p "$F29_REPO/src" "$F29_REPO/.somi"
139
+ (
140
+ cd "$F29_REPO"
141
+ git init -q -b main
142
+ git config user.email t@t && git config user.name t
143
+ printf 'one\n' > src/a.txt
144
+ git add -A && git commit -qm init
145
+ )
146
+ export CLAUDE_PROJECT_DIR="$F29_REPO"
147
+ cd "$F29_REPO"
148
+ unset SOMI_CODE_LOOP_MAX_PASSES SOMI_CODE_LOOP_DIFF_CAP 2>/dev/null || true
149
+
150
+ node "$LOOP" init --slug capfix --loop code --iteration 1.1 \
151
+ --files "src/capfix.txt" --max-passes 1 --diff-cap 4 >/dev/null
152
+ baseline_before="$(node "$LOOP" stats --slug capfix --iteration 1.1 | jq -r .baseline_sha)"
153
+
154
+ node "$LOOP" pass --slug capfix --iteration 1.1 >/dev/null # pass 1 of 1 — ok
155
+ node "$LOOP" record-pass --slug capfix --iteration 1.1 \
156
+ --verdict request-changes --blockers 0 --majors 1 >/dev/null
157
+ expect_exit "F-29: pass beyond max_passes still gates before any override" 2 \
158
+ node "$LOOP" pass --slug capfix --iteration 1.1
159
+
160
+ # `|| true` below: under `set -euo pipefail`, a bare `var=$(cmd)` that exits
161
+ # non-zero aborts the WHOLE suite right here with no test name and every check
162
+ # below unreported — reproduced by hand against the pre-fix script (exit 2,
163
+ # "max-passes-exceeded: pass 2 > cap 1"). `|| true` keeps a regression a reported
164
+ # `check` failure instead of a silent suite death.
165
+ out="$(SOMI_CODE_LOOP_MAX_PASSES=5 node "$LOOP" pass --slug capfix --iteration 1.1)" || true
166
+ check "F-29: env var re-run of the SAME subcommand (no --force) honours the raised cap" \
167
+ "$(jq -e '.max_passes == 5 and .pass == 2' <<<"$out" >/dev/null; echo $?)"
168
+ unset SOMI_CODE_LOOP_MAX_PASSES 2>/dev/null || true
169
+
170
+ out="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
171
+ check "F-29: baseline_sha untouched by the override" \
172
+ "$([[ "$(jq -r .baseline_sha <<<"$out")" == "$baseline_before" ]]; echo $?)"
173
+ check "F-29: pass history from before the override survives (still 1 entry)" \
174
+ "$(jq -e '(.history | length) == 1 and .history[0].verdict == "request-changes"' <<<"$out" >/dev/null; echo $?)"
175
+ check "F-29: the raise is persisted as an auditable cap_overrides entry, after_pass recorded pre-increment" \
176
+ "$(jq -e '.cap_overrides | length == 1 and .[0].field == "max_passes" and .[0].from == 1 and .[0].to == 5 and .[0].source == "env" and .[0].after_pass == 1' <<<"$out" >/dev/null; echo $?)"
177
+
178
+ # Same shape for diff_cap_lines, via the CLI flag instead of the env var (the other
179
+ # documented-precedence entry point — see commands/code-loop.md).
180
+ printf 'one\ntwo\nthree\n' > src/capfix.txt # untracked, in-scope: +3 lines, under cap 4
181
+ out="$(node "$LOOP" check-diff --slug capfix --iteration 1.1)"
182
+ check "F-29: check-diff under the original cap needs no override" \
183
+ "$(jq -e '.cap == 4 and .weighted_lines == 3' <<<"$out" >/dev/null; echo $?)"
184
+
185
+ printf 'four\nfive\n' >> src/capfix.txt # now +5 lines, weighted 5 > cap 4
186
+ expect_exit "F-29: check-diff over the original cap still gates before any override" 3 \
187
+ node "$LOOP" check-diff --slug capfix --iteration 1.1
188
+
189
+ # Same `|| true` reasoning as the env-var re-run above — this bare substitution
190
+ # would exit 3 (diff-cap-exceeded) against the pre-fix script and abort the suite.
191
+ out="$(node "$LOOP" check-diff --slug capfix --iteration 1.1 --diff-cap 10)" || true
192
+ check "F-29: --diff-cap flag re-run of the SAME subcommand (no --force) honours the raised cap" \
193
+ "$(jq -e '.cap == 10 and .weighted_lines == 5' <<<"$out" >/dev/null; echo $?)"
194
+
195
+ out="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
196
+ check "F-29: pass/history/baseline still untouched after the diff-cap override too" \
197
+ "$(jq -e '.pass == 2 and (.history | length) == 1' <<<"$out" >/dev/null; echo $?)"
198
+ check "F-29: baseline_sha still untouched after the diff-cap override" \
199
+ "$([[ "$(jq -r .baseline_sha <<<"$out")" == "$baseline_before" ]]; echo $?)"
200
+ check "F-29: both overrides are recorded, in order, in cap_overrides, after_pass recorded correctly" \
201
+ "$(jq -e '.cap_overrides | length == 2 and .[1].field == "diff_cap_lines" and .[1].from == 4 and .[1].to == 10 and .[1].source == "cli" and .[1].after_pass == 2' <<<"$out" >/dev/null; echo $?)"
202
+
203
+ # --- malformed cap values must be rejected, not silently coerced to NaN/null ----
204
+ # `Number()` on "1,000"/"unlimited"/"none" yields NaN, which is FALSE against BOTH
205
+ # gate comparisons (`cur + 1 > max`, `weighted > cap`) — the gate goes fail-open —
206
+ # and `JSON.stringify` then persists that NaN as `null`, which the next bare call
207
+ # falls through past (via firstDefined) to re-arm at the DEFAULT, with no
208
+ # cap_overrides entry recording the reversion. validateCap() rejects (exit 64)
209
+ # rather than coerces. Verified on both gates, both entry points (env AND flag).
210
+ before="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
211
+
212
+ expect_exit "F-29: malformed SOMI_CODE_LOOP_MAX_PASSES env var is rejected (64), not silently disabled" 64 \
213
+ env SOMI_CODE_LOOP_MAX_PASSES=unlimited node "$LOOP" pass --slug capfix --iteration 1.1
214
+ expect_exit "F-29: malformed --max-passes flag is rejected (64), not silently disabled" 64 \
215
+ node "$LOOP" pass --slug capfix --iteration 1.1 --max-passes '1,000'
216
+ expect_exit "F-29: malformed SOMI_CODE_LOOP_DIFF_CAP env var is rejected (64), not silently disabled" 64 \
217
+ env SOMI_CODE_LOOP_DIFF_CAP=unlimited node "$LOOP" check-diff --slug capfix --iteration 1.1
218
+ expect_exit "F-29: malformed --diff-cap flag is rejected (64), not silently disabled" 64 \
219
+ node "$LOOP" check-diff --slug capfix --iteration 1.1 --diff-cap none
220
+
221
+ after="$(node "$LOOP" stats --slug capfix --iteration 1.1)"
222
+ check "F-29: every rejected malformed value left caps/cap_overrides/pass/history byte-identical" \
223
+ "$([[ "$before" == "$after" ]]; echo $?)"
224
+
225
+ out="$(node "$LOOP" finish --slug capfix --iteration 1.1 --status stopped-max-passes-exceeded)"
226
+ check "F-29: finish's stdout surfaces cap_overrides too, not just the gitignored state file" \
227
+ "$(jq -e '.cap_overrides | length == 2' <<<"$out" >/dev/null; echo $?)"
228
+ # Deliberately NOT "stopped-diff-cap" (the pre-existing spelling two blocks up, at
229
+ # line 116) — that bare reason matches neither CAP_BREACH_STATUSES
230
+ # (tests/evals/lib/convergence.mjs) nor commands/code-loop.md's documented status
231
+ # list; a separate open item, not to be copied here.
232
+
233
+ # --- somi-loop (plan): mirrors the code-loop block above for `--loop plan` -
234
+ # Plan loops have exactly one hard gate (`max_passes`); `diff_cap_lines` always
235
+ # short-circuits to 0 for the plan family in reresolveCap()/resolveInitCap(), so
236
+ # `--diff-cap` must be provably inert regardless of what's passed — asserted below
237
+ # rather than only "verified by hand" as pass 1's review left it.
238
+ PLAN29_REPO="$TMP/plan29-repo"
239
+ mkdir -p "$PLAN29_REPO/src" "$PLAN29_REPO/.somi"
240
+ (
241
+ cd "$PLAN29_REPO"
242
+ git init -q -b main
243
+ git config user.email t@t && git config user.name t
244
+ printf 'one\n' > src/a.txt
245
+ git add -A && git commit -qm init
246
+ )
247
+ export CLAUDE_PROJECT_DIR="$PLAN29_REPO"
248
+ cd "$PLAN29_REPO"
249
+ unset SOMI_PLAN_LOOP_MAX_PASSES 2>/dev/null || true
250
+
251
+ node "$LOOP" init --slug planfix --loop plan --max-passes 1 >/dev/null
252
+ plan_baseline_before="$(node "$LOOP" stats --slug planfix | jq -r .baseline_sha)"
253
+
254
+ node "$LOOP" pass --slug planfix >/dev/null # pass 1 of 1 — ok
255
+ expect_exit "F-29 (plan): pass beyond max_passes still gates before any override" 2 \
256
+ node "$LOOP" pass --slug planfix
257
+
258
+ out="$(SOMI_PLAN_LOOP_MAX_PASSES=5 node "$LOOP" pass --slug planfix)" || true
259
+ check "F-29 (plan): env var re-run of the SAME subcommand (no --force) honours the raised cap" \
260
+ "$(jq -e '.max_passes == 5 and .pass == 2' <<<"$out" >/dev/null; echo $?)"
261
+ unset SOMI_PLAN_LOOP_MAX_PASSES 2>/dev/null || true
262
+
263
+ out="$(node "$LOOP" stats --slug planfix)"
264
+ check "F-29 (plan): baseline_sha untouched by the override" \
265
+ "$([[ "$(jq -r .baseline_sha <<<"$out")" == "$plan_baseline_before" ]]; echo $?)"
266
+ check "F-29 (plan): the raise is persisted as an auditable cap_overrides entry" \
267
+ "$(jq -e '.cap_overrides | length == 1 and .[0].field == "max_passes" and .[0].from == 1 and .[0].to == 5 and .[0].source == "env" and .[0].after_pass == 1' <<<"$out" >/dev/null; echo $?)"
268
+
269
+ out="$(node "$LOOP" check-diff --slug planfix --diff-cap 999999)"
270
+ check "F-29 (plan): --diff-cap is inert on a plan loop — cap stays 0 regardless" \
271
+ "$(jq -e '.cap == 0' <<<"$out" >/dev/null; echo $?)"
272
+ out="$(node "$LOOP" stats --slug planfix)"
273
+ check "F-29 (plan): the inert --diff-cap flag records no cap_overrides entry" \
274
+ "$(jq -e '.cap_overrides | length == 1' <<<"$out" >/dev/null; echo $?)"
275
+
276
+ out="$(node "$LOOP" finish --slug planfix --status stopped-max-passes-exceeded)"
277
+ check "F-29 (plan): finish's stdout surfaces cap_overrides too" \
278
+ "$(jq -e '.cap_overrides | length == 1' <<<"$out" >/dev/null; echo $?)"
279
+
280
+ # Restore the shared $REPO context for every section below.
281
+ export CLAUDE_PROJECT_DIR="$REPO"
282
+ cd "$REPO"
283
+
102
284
  # --- somi-findings: identity + breaker semantics --------------------------------
103
285
  F1='[{"file":"src/a.txt","symbol":"HandleWebhook","title":"Missing rate limit on retry path","severity":"Major","confidence":"High"}]'
104
286
 
@@ -176,7 +358,7 @@ expect_exit "somi-check: clean staged set passes" 0 node "$CHECK" --staged
176
358
  #
177
359
  # Everything above asserts *behavioral properties* (cap precedence, weighting,
178
360
  # recurrence semantics) — sufficient to gate this bash implementation, but it gives
179
- # Phase 1's Node port no byte-level "does this match?" target. This section runs a
361
+ # the Node port no byte-level "does this match?" target. This section runs a
180
362
  # second, independent, fully-scripted scenario against ITS OWN throwaway repo (kept
181
363
  # separate from $REPO above, which by this point has accumulated a lot of
182
364
  # scenario-specific mutations — reusing it would couple golden ordering to the
@@ -186,7 +368,7 @@ expect_exit "somi-check: clean staged set passes" 0 node "$CHECK" --staged
186
368
  # Mode: `SOMI_GOLDEN_MODE=capture bash tests/scripts/run.sh` (re)writes the golden
187
369
  # files under tests/scripts/goldens/; the default, `check` (every normal dev/CI
188
370
  # run), replays the same scenario and fails loudly on any drift from what's
189
- # committed. Once Phase 1 points $LOOP/$FINDINGS at the Node CLIs, `check` mode
371
+ # committed. Once $LOOP/$FINDINGS point at the Node CLIs, `check` mode
190
372
  # is exactly the parity gate: same scenario, same normalization, byte-for-byte
191
373
  # comparison — a divergence here is a real behavior regression, not noise.
192
374
  #