@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,108 @@
1
+ #!/usr/bin/env bash
2
+ # Regression test for scripts/validate.sh's never-degrade dispatch guard: resolveModel() called
3
+ # against a decision's `ceiling` field instead of its `selected` field would silently run a unit at
4
+ # whatever the session merely PERMITS, not the tier decideDispatch picked. That guard was
5
+ # hand-verified RED once, by eye, and its automated test then dropped to fit a diff cap -- exactly
6
+ # the failure this repo has already hit repeatedly (see
7
+ # tests/scripts/retirement-gate.sh's own header): a guard proven only by memory of once failing.
8
+ #
9
+ # Runs the REAL block, extracted verbatim from a throwaway COPY of scripts/validate.sh (never the
10
+ # real file, per this repo's cp -a scratch-copy convention) between two markers that are the
11
+ # block's own structure (`dispatch_guard_failed=0` .. its second closing `fi`) -- not a second,
12
+ # hand-typed copy of the grep pattern that could silently go stale.
13
+ #
14
+ # Residual, stated honestly: this proves the block's own logic still catches a violation, not that
15
+ # scripts/validate.sh hasn't disabled the whole block wholesale (e.g. wrapped in `if false`).
16
+ set -uo pipefail
17
+
18
+ ROOT_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
19
+ VALIDATE="$ROOT_REPO/scripts/validate.sh"
20
+
21
+ pass=0; fail=0
22
+ ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
23
+ bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
24
+ assert_rc() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (expected exit $3, got $2)"; fi; }
25
+ assert_has() { if grep -qF "$2" "$3"; then ok "$1"; else bad "$1 (got: $(cat "$3"))"; fi; }
26
+
27
+ echo "== never-degrade dispatch guard (scripts/validate.sh) =="
28
+
29
+ TMP="$(mktemp -d)"
30
+ trap 'rm -rf "$TMP"' EXIT
31
+
32
+ SCRATCH_VALIDATE="$TMP/validate.sh"
33
+ cp -a "$VALIDATE" "$SCRATCH_VALIDATE"
34
+
35
+ BLOCK="$(awk '
36
+ /^dispatch_guard_failed=0$/ { capture=1 }
37
+ capture { print; if ($0 == "fi") { n++; if (n == 2) exit } }
38
+ ' "$SCRATCH_VALIDATE")"
39
+
40
+ if [ -z "$BLOCK" ]; then
41
+ bad "could not extract the guard block from scripts/validate.sh -- its markers may have moved"
42
+ echo "never-degrade dispatch guard tests: $pass ok, $fail failed"
43
+ exit 1
44
+ fi
45
+
46
+ # Falling through with no violation ends on a false `[ ... -ne 0 ]` test (harmless mid-script under
47
+ # validate.sh's own flow, which just continues) -- an isolated `bash -c` would otherwise report
48
+ # THAT test's own status as its exit code. Appending `exit 0` makes "no violation" unambiguous.
49
+ SNIPPET="$BLOCK"$'\nexit 0'
50
+
51
+ run_guard() { ( cd "$1" && bash -c "$SNIPPET" ) >"$2" 2>"$3"; } # $1=root $2=stdout-file $3=stderr-file
52
+
53
+ # --- RED: a planted violation in a swept file must fail the guard, naming file and line -----------
54
+ RED="$TMP/red"; mkdir -p "$RED/agents"
55
+ cat > "$RED/agents/example.md" <<'EOF'
56
+ ---
57
+ name: example
58
+ cost: high
59
+ ---
60
+ Deliberately unsanctioned: resolveModel(decision.ceiling, host).
61
+ EOF
62
+ red_out="$TMP/red.out"; red_err="$TMP/red.err"
63
+ run_guard "$RED" "$red_out" "$red_err"; rc=$?
64
+ assert_rc "a planted resolveModel(x.ceiling) call makes the guard exit non-zero" "$rc" 1
65
+ assert_has "the guard's report names the violating file and line" \
66
+ 'agents/example.md:5:Deliberately unsanctioned: resolveModel(decision.ceiling, host).' "$red_out"
67
+ assert_has "the guard's diagnostic explains the violation" 'UNSANCTIONED DISPATCH' "$red_err"
68
+
69
+ # --- RED2: the planted violation at the REAL live call site's own path (scripts/somi-dispatch.mjs,
70
+ # outside scripts/lib/) must also fail -- the agents/ fixture above can't detect `scripts` dropped
71
+ # from the swept roots, or the scripts/lib/ exemption widened to all of scripts/.
72
+ RED2="$TMP/red2"; mkdir -p "$RED2/scripts"
73
+ cat > "$RED2/scripts/somi-dispatch.mjs" <<'EOF'
74
+ // Deliberately unsanctioned, planted at the one live call site's own path (outside scripts/lib/).
75
+ resolveModel(decision.ceiling, host);
76
+ EOF
77
+ red2_out="$TMP/red2.out"; red2_err="$TMP/red2.err"
78
+ run_guard "$RED2" "$red2_out" "$red2_err"; rc=$?
79
+ assert_rc "a planted violation at scripts/somi-dispatch.mjs (outside scripts/lib/) fails the guard" \
80
+ "$rc" 1
81
+ assert_has "the guard's report names scripts/somi-dispatch.mjs and its line" \
82
+ 'scripts/somi-dispatch.mjs:2:resolveModel(decision.ceiling, host);' "$red2_out"
83
+
84
+ # --- CLEAN: no unsanctioned call anywhere in the swept roots must pass -----------------------------
85
+ CLEAN="$TMP/clean"; mkdir -p "$CLEAN/agents"
86
+ cat > "$CLEAN/agents/example.md" <<'EOF'
87
+ ---
88
+ name: example
89
+ cost: high
90
+ ---
91
+ Sanctioned: modelForDispatch(decideDispatch(declaredCost, ceiling), host).
92
+ EOF
93
+ clean_out="$TMP/clean.out"; clean_err="$TMP/clean.err"
94
+ run_guard "$CLEAN" "$clean_out" "$clean_err"; rc=$?
95
+ assert_rc "a clean tree (no unsanctioned call) passes the guard" "$rc" 0
96
+
97
+ # --- EXEMPT: the identical call inside scripts/lib/ is the sanctioned internal, not flagged --------
98
+ EXEMPT="$TMP/exempt"; mkdir -p "$EXEMPT/scripts/lib"
99
+ cat > "$EXEMPT/scripts/lib/cost-ceiling.mjs" <<'EOF'
100
+ // modelForDispatch()'s own sanctioned internal -- this file is the one exemption, by path.
101
+ resolveModel(decision.ceiling, host);
102
+ EOF
103
+ exempt_out="$TMP/exempt.out"; exempt_err="$TMP/exempt.err"
104
+ run_guard "$EXEMPT" "$exempt_out" "$exempt_err"; rc=$?
105
+ assert_rc "the identical call inside scripts/lib/ is exempt and does not fail the guard" "$rc" 0
106
+
107
+ echo "never-degrade dispatch guard tests: $pass ok, $fail failed"
108
+ [ "$fail" -eq 0 ] || exit 1
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env bash
2
+ # Unit + fixture guard for tests/scripts/lib/dispatch-reference-gate.mjs -- every command that
3
+ # Tasks an agent directly must reference skills/somi-dispatch/SKILL.md, the same as the front
4
+ # door. Proves the gate BOTH ways, the same discipline retirement-gate.sh and dispatch-guard.sh
5
+ # already apply to their own gates: green against the real tree, and red against a `cp -a` copy
6
+ # with one command's reference removed -- never trusted only because the real tree happens to pass
7
+ # today.
8
+ set -uo pipefail
9
+
10
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
11
+ GATE="$ROOT/tests/scripts/lib/dispatch-reference-gate.mjs"
12
+
13
+ pass=0; fail=0
14
+ ok() { pass=$((pass+1)); printf ' ok %s\n' "$1"; }
15
+ bad() { fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
16
+
17
+ echo "== command <-> somi-dispatch skill reference gate =="
18
+
19
+ TMP="$(mktemp -d)"
20
+ trap 'rm -rf "$TMP"' EXIT
21
+
22
+ # --- unit-level: the derivation itself, against synthetic fixtures, independent of the real repo --
23
+ unit_out="$(node --input-type=module -e '
24
+ import { agentStartedBy, agentNamesFrom, DISPATCH_REFERENCE_RE } from "'"$GATE"'";
25
+ import fs from "node:fs";
26
+ import path from "node:path";
27
+ import os from "node:os";
28
+
29
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "dispatch-gate-unit-"));
30
+ fs.mkdirSync(path.join(tmp, "agents"));
31
+ for (const n of ["coder", "reviewer", "architecture-reviewer"]) {
32
+ fs.writeFileSync(path.join(tmp, "agents", n + ".md"), "---\nname: " + n + "\n---\n");
33
+ }
34
+ fs.writeFileSync(path.join(tmp, "agents", "somi.md"), "---\nname: somi\n---\n");
35
+ const names = agentNamesFrom(path.join(tmp, "agents"));
36
+
37
+ const cases = [
38
+ ["Brief the `coder` agent via the Task tool with:", "coder"],
39
+ ["Task coder ( = /code <slug> )", "coder"],
40
+ ["Task the [`reviewer`](../agents/reviewer.md) on a fresh context", "reviewer"],
41
+ ["Task [`architecture-reviewer`](../agents/architecture-reviewer.md) (and more)", "architecture-reviewer"],
42
+ ["Brief [`agents/coder.md`](../agents/coder.md) via the Task tool with:", "coder"],
43
+ // The newer call-site verbs, and case-insensitivity on all of them.
44
+ ["Start the `coder` agent via the Task tool with:", "coder"],
45
+ ["Spawn the `reviewer` agent for a fresh-context pass", "reviewer"],
46
+ ["Dispatch the `coder` agent with the current findings", "coder"],
47
+ ["Run the `reviewer` agent on the same diff", "reviewer"],
48
+ ["run the `coder` agent (lowercase verb)", "coder"],
49
+ ["brief the `reviewer` agent (lowercase verb)", "reviewer"],
50
+ // A router Tasking another COMMAND, never an agent -- must NOT match.
51
+ ["Task /code-loop \"<slug> phase <N>, iteration <M>\"", null],
52
+ // Coincidental English-word / cross-reference prose -- must NOT match (no real call-site shape).
53
+ ["what is the user-visible impact, since when", null],
54
+ ["amortized across every later /design, cold /plan, and /impact", null],
55
+ // somi.md is exempt -- agentNamesFrom already drops it, so even a literal call-site shape naming
56
+ // it must not match (nothing here Tasks the front door).
57
+ ["Brief the `somi` agent via the Task tool with:", null],
58
+ ];
59
+
60
+ let ok = 0, bad = 0;
61
+ for (const [text, want] of cases) {
62
+ const got = agentStartedBy(text, names);
63
+ if (got === want) { ok++; }
64
+ else { bad++; console.log("MISMATCH: " + JSON.stringify(text) + " -> got " + got + ", want " + want); }
65
+ }
66
+
67
+ // DISPATCH_REFERENCE_RE itself: a bare mention of the CLI fallback script must NOT satisfy the
68
+ // reference requirement (that was the pre-fix bug -- "somi-dispatch" as a bare substring matched
69
+ // scripts/somi-dispatch.mjs too), but either real reference shape must.
70
+ const refCases = [
71
+ // A bare CLI-fallback-script mention alone is NOT a reference -- this is the exact bug the
72
+ // literal-token fix closes (a "somi-dispatch" SUBSTRING match used to be satisfied by this).
73
+ ["fall back to node scripts/somi-dispatch.mjs resolve --agent x", false],
74
+ // A bare skill-name mention with neither the full "skills/somi-dispatch" path nor "somi_resolve"
75
+ // is also NOT enough on its own -- proves the fix is not just "any somi-dispatch mention".
76
+ ["full rules: the `somi-dispatch` skill (`somi_skill`, or `somi:somi-dispatch` on Claude Code) only, nothing else", false],
77
+ // The real shape every rewritten command reference line now uses -- true because it names
78
+ // `somi_resolve` literally, not because it mentions the skill by name.
79
+ ["Before this `Task`, call `somi_resolve` for `coder` (with `project_dir`), pass its model, and put `dispatched at cost: <tier>` in the briefing; full rules: the `somi-dispatch` skill (`somi_skill`, or `somi:somi-dispatch` on Claude Code).", true],
80
+ // The older full-path markdown-link shape still satisfies it too.
81
+ ["started per [`skills/somi-dispatch`](../skills/somi-dispatch/SKILL.md)", true],
82
+ ["no dispatch reference here at all", false],
83
+ ];
84
+ for (const [text, want] of refCases) {
85
+ const got = DISPATCH_REFERENCE_RE.test(text);
86
+ if (got === want) { ok++; }
87
+ else { bad++; console.log("REF MISMATCH: " + JSON.stringify(text) + " -> got " + got + ", want " + want); }
88
+ }
89
+
90
+ console.log("UNIT " + ok + " " + bad);
91
+ fs.rmSync(tmp, { recursive: true, force: true });
92
+ ' 2>&1)"
93
+ echo "$unit_out" | grep -v '^UNIT ' | sed 's/^/ /'
94
+ unit_line="$(echo "$unit_out" | grep '^UNIT ')"
95
+ unit_ok="$(echo "$unit_line" | awk '{print $2}')"
96
+ unit_bad="$(echo "$unit_line" | awk '{print $3}')"
97
+ if [ "$unit_bad" = "0" ] && [ -n "$unit_ok" ]; then
98
+ ok "all $unit_ok synthetic call-site/exclusion cases matched the expected agent (or no-match)"
99
+ else
100
+ bad "synthetic call-site cases: $unit_bad mismatch(es) -- see MISMATCH lines above"
101
+ fi
102
+
103
+ # --- fixture-level: a `cp -a` copy of the real commands/ + agents/ -------------------------------
104
+ cp -a "$ROOT/commands" "$TMP/commands"
105
+ cp -a "$ROOT/agents" "$TMP/agents"
106
+
107
+ # --- GREEN: the unmodified copy passes -----------------------------------------------------------
108
+ if out_green="$(node "$GATE" "$TMP/commands" "$TMP/agents" 2>&1)"; then
109
+ ok "gate exits 0 against an unmodified cp -a copy of the real commands/ + agents/"
110
+ else
111
+ bad "gate exited non-zero against an unmodified copy (got: $out_green)"
112
+ fi
113
+ case "$out_green" in
114
+ ok*) ok "gate's report starts with 'ok' against the unmodified copy" ;;
115
+ *) bad "gate's report does not start with 'ok' against the unmodified copy (got: $out_green)" ;;
116
+ esac
117
+
118
+ # A missing REFERENCE is already caught by the RED case below -- what a count alone catches is
119
+ # different: the call-site DETECTION itself regressing (a wording change the patterns in
120
+ # dispatch-reference-gate.mjs no longer match), which would silently shrink "checked" with no
121
+ # MISSING DISPATCH REFERENCE line to flag it, since a command that drops out of detection is never
122
+ # in "missing" either. A LOWER bound, not a pin: this repo only grows agent-starting commands over
123
+ # time, and a hand-maintained exact count is exactly the kind of pin that goes stale on a legitimate
124
+ # addition -- a real detection regression still fails loud (the count drops below the floor).
125
+ checked_count="$(echo "$out_green" | grep -oE 'ok \([0-9]+ command' | grep -oE '[0-9]+')"
126
+ if [ -n "$checked_count" ] && [ "$checked_count" -ge 21 ]; then
127
+ ok "at least 21 commands are derived as starting an agent (got $checked_count; matches or exceeds the real repo today)"
128
+ else
129
+ bad "expected at least 21 commands derived as starting an agent, got $checked_count -- the call-site pattern derivation may have regressed"
130
+ fi
131
+
132
+ # --- RED: removing commands/code.md's dispatch reference must fail ------------------------------
133
+ # Strips BOTH satisfying tokens, not just one -- the gate now accepts either "skills/somi-dispatch"
134
+ # or "somi_resolve" (DISPATCH_REFERENCE_RE), so a fixture that only strips lines mentioning
135
+ # "somi-dispatch" would leave a bare "somi_resolve" mention behind and this RED case would no
136
+ # longer actually go red.
137
+ sed -i -E '/somi-dispatch|somi_resolve/d' "$TMP/commands/code.md"
138
+ out_red="$(node "$GATE" "$TMP/commands" "$TMP/agents" 2>&1)"; rc_red=$?
139
+ if [ "$rc_red" -eq 1 ]; then
140
+ ok "gate exits 1 once commands/code.md's dispatch reference is removed"
141
+ else
142
+ bad "gate did not exit 1 after removing commands/code.md's reference (rc=$rc_red, out=$out_red)"
143
+ fi
144
+ case "$out_red" in
145
+ *"MISSING DISPATCH REFERENCE: code.md"*) ok "gate names code.md as missing the dispatch reference" ;;
146
+ *) bad "gate's output does not name code.md as missing the reference (got: $out_red)" ;;
147
+ esac
148
+
149
+ # --- RED fixture does not spuriously flag OTHER commands (only code.md was touched) --------------
150
+ case "$out_red" in
151
+ *"MISSING DISPATCH REFERENCE"*"MISSING DISPATCH REFERENCE"*)
152
+ bad "more than one command flagged missing -- only commands/code.md was modified (got: $out_red)" ;;
153
+ *)
154
+ ok "exactly one command (code.md) is flagged, not a spurious wider failure" ;;
155
+ esac
156
+
157
+ # --- a router command (no agents/ reference at all) is correctly excluded, both green and red ----
158
+ router_out="$(node --input-type=module -e '
159
+ import { agentStartedBy, agentNamesFrom } from "'"$GATE"'";
160
+ const names = agentNamesFrom("'"$TMP"'/agents");
161
+ import fs from "node:fs";
162
+ const text = fs.readFileSync("'"$TMP"'/commands/ship.md", "utf8");
163
+ console.log(agentStartedBy(text, names) === null ? "EXCLUDED" : "FALSE POSITIVE");
164
+ ' 2>&1)"
165
+ case "$router_out" in
166
+ EXCLUDED) ok "commands/ship.md (a router -- Tasks other commands, never an agent) is correctly excluded" ;;
167
+ *) bad "commands/ship.md was NOT excluded (got: $router_out) -- a router must never be misdiagnosed as starting an agent" ;;
168
+ esac
169
+
170
+ bash "$ROOT/tests/scripts/review-panel-seats.sh" || fail=$((fail+1))
171
+
172
+ echo "dispatch-reference-gate tests: $pass ok, $fail failed"
173
+ [ "$fail" -eq 0 ] || exit 1