@skathio/somi 2.2.1 → 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 +207 -209
  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 +33 -8
  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
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env bash
2
+ # Guards the invariant that `npm test` stays hermetic and the eval corpus never ships to
3
+ # consumers. Kept in its own file so the invariant is not spread through a large diff.
4
+ set -uo pipefail
5
+
6
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
7
+ cd "$ROOT"
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
+ check(){ if [ "$2" = "$3" ]; then ok "$1"; else bad "$1 (want '$3', got '$2')"; fi; }
12
+
13
+ echo "== eval packaging & hermeticity =="
14
+
15
+ # --- the corpus must not ship ------------------------------------------------------------------
16
+ # `tests/` is in package.json's `files`, so exclusion needs tests/.npmignore -- a ROOT .npmignore
17
+ # does not override `files`. That mechanism was verified when the plan was written; this asserts
18
+ # the outcome rather than trusting it.
19
+ pack=$(npm pack --dry-run --json 2>/dev/null)
20
+ if [ -z "$pack" ]; then
21
+ bad "npm pack --dry-run produced output"
22
+ else
23
+ ok "npm pack --dry-run produced output"
24
+ n_total=$(printf '%s' "$pack" | node -e "let s='';process.stdin.on('data',d=>s+=d).on('end',()=>process.stdout.write(String(JSON.parse(s)[0].files.length)))")
25
+ for pat in 'tests/evals/' 'evals/fixtures' 'evals/tasks' 'evals/run.mjs' 'rubric.md' 'evals-fixtures.sh'; do
26
+ n=$(printf '%s' "$pack" | node -e "
27
+ let s='';process.stdin.on('data',d=>s+=d).on('end',()=>{
28
+ const f=JSON.parse(s)[0].files.filter(x=>x.path.includes(process.argv[1]));
29
+ process.stdout.write(String(f.length));});" "$pat")
30
+ check "npm tarball contains no '$pat'" "$n" "0"
31
+ done
32
+ # Floor: a tarball that is empty would pass every check above vacuously.
33
+ if [ "${n_total:-0}" -ge 50 ]; then
34
+ ok "npm tarball is non-empty ($n_total paths)"
35
+ else
36
+ bad "npm tarball is non-empty (want >=50, got ${n_total:-0})"
37
+ fi
38
+ fi
39
+
40
+ # --- npm test must not EXECUTE the runner -------------------------------------------------------
41
+ # Structural and invocation-level, per the phase's exit criteria: a `node --check` glob merely
42
+ # NAMING tests/evals is explicitly permitted; executing the runner is not. A bare "no mention"
43
+ # grep would be self-contradicting, since validate.sh must name the directory to syntax-check it.
44
+ test_script=$(node -e "process.stdout.write(require('./package.json').scripts.test)")
45
+ check "npm test runs validate.sh, not the eval runner" "$test_script" "bash scripts/validate.sh"
46
+
47
+ # Scoped to what `npm test` actually reaches: the `test` script string, and validate.sh (which it
48
+ # runs). package.json's OTHER scripts may reference the runner -- eval:behavioral exists precisely
49
+ # to. Checking the whole file would flag the deliberate escape hatch as the leak.
50
+ reach=$( { printf '%s\n' "$test_script"; cat scripts/validate.sh; } \
51
+ | grep -nE '(^|[^-])\b(node|bash|sh)[[:space:]]+[^|;&]*tests/evals/run\.mjs' | grep -v -- '--check')
52
+ if [ -z "$reach" ]; then
53
+ ok "nothing reachable from npm test executes tests/evals/run.mjs"
54
+ else
55
+ bad "nothing reachable from npm test executes tests/evals/run.mjs"
56
+ printf '%s\n' "$reach" | sed 's/^/ /'
57
+ fi
58
+
59
+ # The runner is reachable on purpose through its own script, which is NOT `test`.
60
+ have=$(node -e "const s=require('./package.json').scripts; process.stdout.write(s['eval:behavioral'] ?? 'MISSING')")
61
+ check "an explicit eval:behavioral script exists" "$have" "node tests/evals/run.mjs"
62
+
63
+ # Same pair, extended to the convergence entrypoint: the invocation-level check must name the file
64
+ # convergence.mjs actually is, not just repeat run.mjs's own assertion under a different label --
65
+ # that would pass unconditionally regardless of whether this module is reachable from npm test.
66
+ have2=$(node -e "const s=require('./package.json').scripts; process.stdout.write(s['eval:convergence'] ?? 'MISSING')")
67
+ check "an explicit eval:convergence script exists" "$have2" "node tests/evals/convergence.mjs"
68
+ reach2=$( { printf '%s\n' "$test_script"; cat scripts/validate.sh; } \
69
+ | grep -nE '(^|[^-])\b(node|bash|sh)[[:space:]]+[^|;&]*tests/evals/convergence\.mjs' | grep -v -- '--check')
70
+ if [ -z "$reach2" ]; then
71
+ ok "no direct invocation of tests/evals/convergence.mjs from the test script or validate.sh"
72
+ else
73
+ bad "no direct invocation of tests/evals/convergence.mjs from the test script or validate.sh"
74
+ printf '%s\n' "$reach2" | sed 's/^/ /'
75
+ fi
76
+ check "every node \"\$CVD\" invocation in convergence-runner.sh is read-only or a negative-argument test (F-256)" "$(grep -nF 'node "$CVD"' tests/scripts/convergence-runner.sh | grep -vcE -- '--dry-run|--merge|--certify|--help|echo \$\?')" "0"
77
+
78
+ # --- npm test itself must not reach the network -------------------------------------------------
79
+ # Tests INVOCATION, not substrings. A URL inside a string literal is not a network call:
80
+ # check-links.sh builds `[a](https://e.com/x.md)` as a fixture, and eval-runner.sh's own
81
+ # hermeticity assertion contains the pattern `https?://` as a grep argument. A substring scan
82
+ # flags both, which trains the reader to ignore it -- the failure mode of a noisy guard.
83
+ net_failed=0
84
+ for f in scripts/validate.sh $(git ls-files 'tests/scripts/*.sh'); do
85
+ hits=$(grep -nE '(^|[;&|(]|[[:space:]])(curl|wget|nc|ssh|scp)[[:space:]]|\$\{?ANTHROPIC_API_KEY|\$\{?OPENAI_API_KEY|process\.env\.(ANTHROPIC|OPENAI)' "$f" 2>/dev/null \
86
+ | grep -vE "^[0-9]+:[[:space:]]*#" | grep -vE "grep -[a-zA-Z]*E?[[:space:]]+'")
87
+ if [ -n "$hits" ]; then
88
+ bad "$f makes no network call or credential read"
89
+ printf '%s\n' "$hits" | sed 's/^/ /'
90
+ net_failed=1
91
+ fi
92
+ done
93
+ [ "$net_failed" -eq 0 ] && ok "no script reachable from npm test invokes a network client or reads a credential"
94
+
95
+ # --- node --check must cover the eval tree ------------------------------------------------------
96
+ if grep -qE 'EVAL_TREE="tests/evals"' scripts/validate.sh \
97
+ && grep -qE "find hooks scripts \\\$EVAL_TREE -name '\\*\\.mjs'" scripts/validate.sh; then
98
+ ok "validate.sh syntax-checks tests/evals/**/*.mjs"
99
+ else
100
+ bad "validate.sh syntax-checks tests/evals/**/*.mjs"
101
+ fi
102
+ # Skipped in a published tarball, where the tree is absent BY DESIGN -- the exclusion asserted
103
+ # above. Failing here would make the guard contradict its own passing assertion.
104
+ if [ -d tests/evals ]; then
105
+ n_mjs=$(find tests/evals -name '*.mjs' -type f | wc -l | tr -d ' ')
106
+ if [ "$n_mjs" -ge 10 ]; then
107
+ ok "there are .mjs files under tests/evals to check ($n_mjs)"
108
+ else
109
+ bad "there are .mjs files under tests/evals to check (want >=10, got $n_mjs)"
110
+ fi
111
+ else
112
+ ok "tests/evals absent (published tarball) - syntax-check scope assertion skipped"
113
+ fi
114
+
115
+ echo
116
+ printf ' %d passed, %d failed\n' "$pass" "$fail"
117
+ [ "$fail" -eq 0 ]
@@ -0,0 +1,50 @@
1
+ {
2
+ "sha": "4ff4da62caff23248f9d057c6bc9046a8a22ecf6",
3
+ "taskId": "01",
4
+ "run": {
5
+ "index": 0,
6
+ "dimensions": {
7
+ "S2": true,
8
+ "S7": true,
9
+ "S1": true,
10
+ "S6": true,
11
+ "S3": true
12
+ },
13
+ "criteria": [
14
+ {
15
+ "n": 1,
16
+ "verdict": "pass",
17
+ "evidence": "(trimmed)"
18
+ },
19
+ {
20
+ "n": 2,
21
+ "verdict": "pass",
22
+ "evidence": "(trimmed)"
23
+ },
24
+ {
25
+ "n": 3,
26
+ "verdict": "pass",
27
+ "evidence": "(trimmed)"
28
+ },
29
+ {
30
+ "n": 4,
31
+ "verdict": "pass",
32
+ "evidence": "(trimmed)"
33
+ },
34
+ {
35
+ "n": 5,
36
+ "verdict": "pass",
37
+ "evidence": "(trimmed)"
38
+ },
39
+ {
40
+ "n": 6,
41
+ "verdict": "pass",
42
+ "evidence": "(trimmed)"
43
+ }
44
+ ],
45
+ "transcript": "(transcript omitted: this fixture is a trimmed copy of a real pre-schema shard; only its shape matters)",
46
+ "decisionsMd": null,
47
+ "error": null,
48
+ "rescored": true
49
+ }
50
+ }
@@ -0,0 +1,180 @@
1
+ #!/usr/bin/env bash
2
+ # End-to-end tests for scripts/generate-digest.mjs.
3
+ #
4
+ # The digest lives in three files and drifted once already — the Copilot copy was missing a whole
5
+ # bullet and nothing could see it. The generator exists to make that unrepresentable, so it needs a
6
+ # regression guard of its own; manual mutation testing evaporates at the end of a session.
7
+ #
8
+ # Runs the real script against a throwaway repo whose layout mirrors this one (rules/CLAUDE.md
9
+ # canonical + two targets at different depths), so the per-target prefix transform is exercised for
10
+ # BOTH targets independently — getting one right and the other wrong is exactly the silent-drift
11
+ # class this script removes.
12
+ #
13
+ # Wired into scripts/validate.sh (npm test).
14
+
15
+ set -euo pipefail
16
+
17
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
18
+ GEN="$ROOT/scripts/generate-digest.mjs"
19
+
20
+ TMP="$(mktemp -d)"
21
+ trap 'rm -rf "$TMP"' EXIT
22
+
23
+ failures=0
24
+ total=0
25
+ check() { # $1 = name, $2 = 0/1 pass
26
+ total=$((total + 1))
27
+ if [[ "$2" != "0" ]]; then
28
+ echo "FAIL: $1" >&2
29
+ failures=$((failures + 1))
30
+ fi
31
+ }
32
+ expect_exit() { # $1 = name, $2 = expected code, then the command …
33
+ local name="$1" want="$2" got=0; shift 2
34
+ "$@" >/dev/null 2>&1 || got=$?
35
+ if [[ "$got" != "$want" ]]; then
36
+ echo "FAIL: $name — expected exit $want, got $got" >&2
37
+ failures=$((failures + 1))
38
+ fi
39
+ total=$((total + 1))
40
+ }
41
+
42
+ # --- throwaway repo mirroring this one's layout --------------------------------
43
+ # The generator resolves paths from its own location (../ = repo root), so the fixture repo gets a
44
+ # copy of the script rather than the fixture being pointed at the real repo.
45
+ REPO="$TMP/repo"
46
+ mkdir -p "$REPO/scripts" "$REPO/rules" "$REPO/.github"
47
+ cp "$GEN" "$REPO/scripts/generate-digest.mjs"
48
+ for n in 00-priorities 20-clean-code; do printf '# %s\n' "$n" > "$REPO/rules/$n.md"; done
49
+
50
+ write_canonical() { # $1 = extra bullet or ""
51
+ cat > "$REPO/rules/CLAUDE.md" <<EOF
52
+ # Rules
53
+
54
+ ## Always-on digest
55
+
56
+ Framing paragraph that must NOT be copied into the targets.
57
+
58
+ <!-- digest:start -->
59
+ - **Priorities:** first. ([\`00\`](./00-priorities.md))
60
+ - **Clean code:** second. ([\`20\`](./20-clean-code.md))${1:+
61
+ $1}
62
+ <!-- digest:end -->
63
+
64
+ ## Composition
65
+ EOF
66
+ }
67
+ write_targets() {
68
+ printf '# Agents\n\n## Always-on digest\n\nSTALE\n\n## After\n\nkeep me\n' > "$REPO/AGENTS.md"
69
+ printf '# Copilot\n\n## Always-on digest\n\nSTALE\n\n## After\n\nkeep me\n' > "$REPO/.github/copilot-instructions.md"
70
+ }
71
+ write_canonical ""
72
+ write_targets
73
+
74
+ GENC="$REPO/scripts/generate-digest.mjs"
75
+
76
+ # --- drift is detected, then fixed ---------------------------------------------
77
+ expect_exit "check reports drift before first generate" 1 node "$GENC" --check
78
+ expect_exit "generate succeeds" 0 node "$GENC"
79
+ expect_exit "check is clean after generate" 0 node "$GENC" --check
80
+
81
+ # --- BOTH targets transformed, each with its own prefix -------------------------
82
+ # The whole point of a per-target prefix: root-level AGENTS.md needs ./rules/, and
83
+ # .github/copilot-instructions.md one level down needs ../rules/. A generator that got one right
84
+ # and the other wrong would still report "in sync".
85
+ check "AGENTS.md uses ./rules/ prefix" \
86
+ "$(grep -qF '](./rules/00-priorities.md)' "$REPO/AGENTS.md"; echo $?)"
87
+ check "AGENTS.md has no ../rules/ prefix" \
88
+ "$(! grep -qF '](../rules/' "$REPO/AGENTS.md"; echo $?)"
89
+ check "copilot copy uses ../rules/ prefix" \
90
+ "$(grep -qF '](../rules/00-priorities.md)' "$REPO/.github/copilot-instructions.md"; echo $?)"
91
+ check "copilot copy has no ./rules/ prefix" \
92
+ "$(! grep -qF '](./rules/' "$REPO/.github/copilot-instructions.md"; echo $?)"
93
+
94
+ # --- the framing paragraph and following sections are NOT copied/clobbered ------
95
+ check "framing paragraph not copied into target" \
96
+ "$(! grep -q 'must NOT be copied' "$REPO/AGENTS.md"; echo $?)"
97
+ check "content after the digest section preserved" \
98
+ "$(grep -q 'keep me' "$REPO/AGENTS.md"; echo $?)"
99
+ check "stale content replaced" \
100
+ "$(! grep -q 'STALE' "$REPO/AGENTS.md"; echo $?)"
101
+
102
+ # --- a new canonical bullet propagates to both ----------------------------------
103
+ write_canonical '- **Third:** added. ([`00`](./00-priorities.md))'
104
+ expect_exit "check detects a new canonical bullet" 1 node "$GENC" --check
105
+ node "$GENC" >/dev/null
106
+ check "new bullet reached AGENTS.md" \
107
+ "$(grep -q 'Third' "$REPO/AGENTS.md"; echo $?)"
108
+ check "new bullet reached copilot copy" \
109
+ "$(grep -q 'Third' "$REPO/.github/copilot-instructions.md"; echo $?)"
110
+
111
+ # --- drift in EITHER target alone is caught -------------------------------------
112
+ # The original defect was one copy silently missing a bullet.
113
+ perl -0pi -e 's/- \*\*Third:.*\n//' "$REPO/AGENTS.md"
114
+ expect_exit "drift in AGENTS.md alone is caught" 1 node "$GENC" --check
115
+ node "$GENC" >/dev/null
116
+ perl -0pi -e 's/- \*\*Third:.*\n//' "$REPO/.github/copilot-instructions.md"
117
+ expect_exit "drift in the copilot copy alone is caught" 1 node "$GENC" --check
118
+ node "$GENC" >/dev/null
119
+
120
+ # --- malformed inputs fail loudly, never with a raw stack trace ------------------
121
+ cp "$REPO/rules/CLAUDE.md" "$TMP/canon.bak"
122
+ perl -0pi -e 's/<!-- digest:end -->/<!-- digest:ended -->/' "$REPO/rules/CLAUDE.md"
123
+ err="$(node "$GENC" --check 2>&1 || true)"
124
+ check "malformed markers give a clean error, not a stack trace" \
125
+ "$([[ "$err" == *"generate-digest:"* && "$err" != *"at Object."* && "$err" != *" at "* ]]; echo $?)"
126
+ cp "$TMP/canon.bak" "$REPO/rules/CLAUDE.md"
127
+
128
+ # --- a duplicate heading is ambiguous, not silently first-wins -------------------
129
+ cp "$REPO/AGENTS.md" "$TMP/agents.bak"
130
+ printf '\n## Always-on digest\n\nstray\n' >> "$REPO/AGENTS.md"
131
+ err="$(node "$GENC" --check 2>&1 || true)"
132
+ check "duplicate heading is rejected as ambiguous" \
133
+ "$([[ "$err" == *"ambiguous"* ]]; echo $?)"
134
+ cp "$TMP/agents.bak" "$REPO/AGENTS.md"
135
+
136
+ # --- a heading MENTIONED in prose does not hijack the anchor ---------------------
137
+ perl -0pi -e 's/^# Agents$/# Agents\n\nSee the ## Always-on digest section below./m' "$REPO/AGENTS.md"
138
+ expect_exit "prose mentioning the heading does not hijack the anchor" 0 node "$GENC" --check
139
+ check "the prose mention survived intact" \
140
+ "$(grep -q 'See the ## Always-on digest section below.' "$REPO/AGENTS.md"; echo $?)"
141
+
142
+ # --- retarget() rewrites ONLY citations, never other relative links -------------
143
+ # An unanchored `](./` pattern rewrote every relative link in a bullet: a prose link became
144
+ # ./rules/docs/GUIDE.md in one copy and ../rules/docs/GUIDE.md in the other — both dead — while
145
+ # --check reported "in sync". The hook exists to keep prose links in bullets intact, so
146
+ # an unanchored rewrite here put the two halves of that seam in disagreement.
147
+ write_canonical '- **Guide:** see [guide](./docs/GUIDE.md) first. ([`20`](./20-clean-code.md))'
148
+ node "$GENC" >/dev/null
149
+ check "prose link survives untouched in AGENTS.md" \
150
+ "$(grep -qF '[guide](./docs/GUIDE.md)' "$REPO/AGENTS.md"; echo $?)"
151
+ check "prose link survives untouched in the copilot copy" \
152
+ "$(grep -qF '[guide](./docs/GUIDE.md)' "$REPO/.github/copilot-instructions.md"; echo $?)"
153
+ check "the citation beside it still retargets (AGENTS.md)" \
154
+ "$(grep -qF '](./rules/20-clean-code.md)' "$REPO/AGENTS.md"; echo $?)"
155
+ check "the citation beside it still retargets (copilot copy)" \
156
+ "$(grep -qF '](../rules/20-clean-code.md)' "$REPO/.github/copilot-instructions.md"; echo $?)"
157
+ write_canonical ""
158
+ node "$GENC" >/dev/null
159
+
160
+ # --- a fenced `## ` inside the digest section does not terminate the splice ------
161
+ # The fence sits INSIDE the digest section, which is generated territory — so correct behaviour is
162
+ # that the whole fence is REPLACED, leaving the following section untouched.
163
+ #
164
+ # Without fence tracking, `## Not a real heading` reads as the next heading: the splice ends there,
165
+ # the opening ``` (before it) is swallowed as generated content, and the fake heading plus the
166
+ # CLOSING ``` survive as an orphan — an unbalanced fence — while `--check` still reports "in sync".
167
+ # So the discriminator is the presence of that debris, not the survival of the fence.
168
+ cp "$REPO/AGENTS.md" "$TMP/agents-fence.bak"
169
+ perl -0pi -e 's/^## After$/```md\n## Not a real heading\n```\n\n## After/m' "$REPO/AGENTS.md"
170
+ node "$GENC" >/dev/null 2>&1 || true
171
+ check "fenced '## ' did not terminate the splice early (no orphan heading)" \
172
+ "$(! grep -q 'Not a real heading' "$REPO/AGENTS.md"; echo $?)"
173
+ check "no unbalanced fence left behind" \
174
+ "$([[ $(grep -c '^```' "$REPO/AGENTS.md") -eq 0 ]]; echo $?)"
175
+ check "section following the fence survived" \
176
+ "$(grep -q 'keep me' "$REPO/AGENTS.md"; echo $?)"
177
+ cp "$TMP/agents-fence.bak" "$REPO/AGENTS.md"
178
+
179
+ echo "generate-digest tests: $((total - failures)) of $total checks passed."
180
+ [[ "$failures" -eq 0 ]] || exit 1
@@ -0,0 +1 @@
1
+ {"slug":"eval-corpus-rebuild","loop":"code","iteration":"3.3","baseline_sha":"d9421b3","started":"2026-09-03T17:33:37Z","status":"stopped-user-stop","caps":{"max_passes":6,"diff_cap_lines":510,"severity_floor":"Major"},"iteration_files":["tests/evals/convergence.mjs","tests/scripts/eval-runner.sh"],"pass":2,"history":[{"pass":1,"verdict":"request-changes","blockers":1,"majors":4,"diff_lines":508,"at":"2026-09-04T05:15:35Z"}],"finished":"2026-09-04T10:24:41Z"}
@@ -0,0 +1 @@
1
+ {"slug":"context-economy-overhaul","loop":"code","iteration":"2.1","baseline_sha":"40186ed1cd531e5f7cb991aec8d939e475ee3a53","started":"2026-07-27T15:44:46Z","status":"done","caps":{"max_passes":6,"diff_cap_lines":400,"severity_floor":"Major"},"iteration_files":["agents/reviewer.md","docs/AGENTS.md","docs/COMMANDS.md","commands/review.md","commands/test-strategy.md","commands/architecture-review.md","commands/review-panel.md","commands/code-loop.md","docs/WORKFLOWS.md"],"pass":2,"history":[{"pass":2,"verdict":"request-changes","blockers":2,"majors":4,"diff_lines":98,"at":"2026-07-27T15:58:26Z"},{"pass":2,"verdict":"approve","blockers":0,"majors":0,"diff_lines":103,"at":"2026-07-27T16:10:12Z"}],"finished":"2026-07-27T16:10:12Z"}
@@ -148,7 +148,7 @@
148
148
  "stopped-diff-cap"
149
149
  ],
150
150
  "exit": 0,
151
- "stdout": "{\"status\":\"stopped-diff-cap\",\"pass\":2,\"history\":1}",
151
+ "stdout": "{\"status\":\"stopped-diff-cap\",\"pass\":2,\"history\":1,\"cap_overrides\":[]}",
152
152
  "stderr": ""
153
153
  },
154
154
  {
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ // Asserts task01's ADR still grants CONDITIONAL permission and prohibits nothing.
3
+ //
4
+ // This is the trap criterion 4 scores: the filename says `no-new-datastores`, the content only
5
+ // requires a migration path. If the body ever grows an actual prohibition, criterion 4's
6
+ // "citing it as 'we don't add datastores' fails" becomes a false fail — the fixture would then
7
+ // say exactly that.
8
+ //
9
+ // Lives in its own file rather than inline in the guard because the analysis is per-sentence and
10
+ // the guard's `node -e "..."` blocks are shell-quoted context where a backtick or a double quote
11
+ // silently mangles the program.
12
+ //
13
+ // PER-SENTENCE, which is the whole subtlety. A modal-negative is only a prohibition when its own
14
+ // sentence carries no conditional escape: "We do not add a datastore WITHOUT a migration path" is
15
+ // conditional permission — the ADR's actual wording — while "We do not add datastores." is not.
16
+ // A body-wide check cannot tell those apart and flagged the correct fixture.
17
+
18
+ import { readFileSync } from 'node:fs';
19
+
20
+ const CONDITIONAL = /\b(without|unless|until|provided that|so long as|must say how)\b/i;
21
+ const MODAL_NEG = /\b(do not|don't|never|no|not)\b[^.]{0,40}?\b(add|introduce|use|allow|permit)\b/i;
22
+ const FLAT_BAN = /\b(prohibit\w*|forbid\w*|banned|not allowed|full stop|under no circumstances)\b/i;
23
+
24
+ const text = readFileSync(process.argv[2], 'utf8');
25
+ // Everything from the Decision heading to the next H2 that is not Consequences: a prohibition in
26
+ // Consequences is equally poisonous and was previously unscanned.
27
+ // Split on H2s and keep the two sections that carry normative content. An earlier version used
28
+ // a lookahead ending in `\\Z`, which is Python's end-of-input anchor and not JavaScript's -- the
29
+ // match never succeeded and the check reported "no Decision section found" on a correct ADR,
30
+ // i.e. it failed closed on the thing it was asserting.
31
+ const sections = text.split(/^## /m).slice(1);
32
+ const wanted = sections.filter((sec) => /^(Decision|Consequences)\b/.test(sec));
33
+ if (!wanted.length) { process.stdout.write('no Decision section found'); process.exit(0); }
34
+ const body = wanted.map((sec) => sec.replace(/^[^\n]*\n/, '')).join('\n');
35
+
36
+ const sentences = body.split(/(?<=[.!?])\s+/).map((x) => x.trim()).filter(Boolean);
37
+ const offenders = sentences.filter((x) => FLAT_BAN.test(x) || (MODAL_NEG.test(x) && !CONDITIONAL.test(x)));
38
+
39
+ if (offenders.length) { process.stdout.write(`prohibition: ${JSON.stringify(offenders[0].slice(0, 70))}`); process.exit(0); }
40
+ if (!CONDITIONAL.test(body)) { process.stdout.write('no conditional-permission construct'); process.exit(0); }
41
+ process.stdout.write('yes');
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ // checkpoint-gate.mjs — guards commands/ship-loop.md's single non-overridable human checkpoint.
3
+ //
4
+ // The checkpoint was re-anchored from a cost-tier boundary (one that stopped
5
+ // existing once commands declared no tier and execution itself could mix tiers) to the brief
6
+ // handoff: it fires once a design action has produced a brief.md, before planning consumes it, or
7
+ // -- on a cold start with no design action -- after /plan-loop, before any code. Nothing else in
8
+ // this repo tests that a later edit to ship-loop.md keeps that definition intact. This gate is
9
+ // deliberately narrow: it does not re-derive the whole retirement sweep (retirement-gate.mjs and
10
+ // the DoD's own repo-wide grep already own the old vocabulary), it only asserts the file still
11
+ // says the three things that make the checkpoint what it is:
12
+ // 1. it is still declared non-overridable;
13
+ // 2. it still names the brief-handoff anchor;
14
+ // 3. it still names the cold-start (after /plan-loop) anchor.
15
+ //
16
+ // Usage: node checkpoint-gate.mjs <path-to-ship-loop.md>
17
+ // Exit 0 with "ok" on stdout when all three hold; exit 1 with one named reason per miss otherwise.
18
+
19
+ import { readFileSync } from 'node:fs';
20
+
21
+ export function checkCheckpoint(text) {
22
+ const problems = [];
23
+ if (!/non-overridable/i.test(text)) {
24
+ problems.push('no "non-overridable" language found -- the checkpoint must stay non-overridable');
25
+ }
26
+ if (!/brief[\s-]?hand[\s-]?off/i.test(text)) {
27
+ problems.push('no mention of the brief-handoff anchor (a design action producing brief.md, before planning consumes it)');
28
+ }
29
+ if (!/after\s+`?\/plan-loop`?/i.test(text)) {
30
+ problems.push('no mention of the cold-start anchor (falls to after /plan-loop when no design action ran)');
31
+ }
32
+ return problems;
33
+ }
34
+
35
+ function main() {
36
+ const [, , file] = process.argv;
37
+ if (!file) {
38
+ console.error('usage: checkpoint-gate.mjs <path-to-ship-loop.md>');
39
+ process.exit(2);
40
+ }
41
+ const text = readFileSync(file, 'utf8');
42
+ const problems = checkCheckpoint(text);
43
+ if (problems.length) {
44
+ for (const p of problems) console.log(`CHECKPOINT GATE: ${p}`);
45
+ process.exit(1);
46
+ }
47
+ console.log('ok (checkpoint still non-overridable; both anchors named)');
48
+ }
49
+
50
+ // Only run as a CLI when invoked directly -- tests/scripts/checkpoint-gate.sh imports
51
+ // checkCheckpoint() instead, to exercise it against synthetic fixtures.
52
+ if (import.meta.url === `file://${process.argv[1]}`) {
53
+ main();
54
+ }
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ // Exit criterion for trimming rules/: a `rules/` trim that removes or reworsds a digest bullet must update
3
+ // tests/hooks/cases/inject-workflow-context.json's marker in the SAME attempt.
4
+ //
5
+ // Why this needs a guard rather than a note. The hook tests carry a fixture PAIR on that bullet — a
6
+ // positive assertion (the digest contains it) and a negative one (Tier 2 is omitted when the
7
+ // markers are malformed). Trim the bullet away and the positive assertion pins a substring that
8
+ // no longer exists anywhere, so it fails loudly... but only if some case still expects it to be
9
+ // PRESENT. The cases that merely carry it as incidental context go quietly vacuous, and the pair
10
+ // stops testing the thing it was built for while the suite stays green.
11
+ //
12
+ // Trimming is the risk: the trim candidates include `rules/`, which is where
13
+ // the digest comes from. The guard exists so the coupling is mechanical rather than remembered.
14
+
15
+ import { readFileSync } from 'node:fs';
16
+
17
+ const [fixtureFile, hookFile, ...digestFiles] = process.argv.slice(2);
18
+ const raw = readFileSync(fixtureFile, 'utf8');
19
+ // Backslashes stripped before comparing. The hook builds Tier-1 lines inside template literals,
20
+ // so a backtick in the output is written `\\`` in the source -- a literal includes() then misses
21
+ // it and reports frame text as a missing digest bullet. Cost me one false positive on
22
+ // "Multiple in-progress work items in `.somi/plans/`:", which is at line 445 of the hook.
23
+ const unescape = (t) => t.replace(/\\/g, '');
24
+ const hook = unescape(readFileSync(hookFile, 'utf8'));
25
+ const digests = digestFiles.map((f) => ({ f, text: readFileSync(f, 'utf8') }));
26
+
27
+ // Which asserted substrings are DIGEST markers rather than Tier-1 frame text?
28
+ //
29
+ // The discriminator is the hook's own source. Tier 1 is a fixed template the hook emits
30
+ // unconditionally, so every string in it is frame ("Status:", "Active work item:"). Tier 2 is
31
+ // spliced in from the digest. An asserted substring that does NOT appear in the hook source must
32
+ // therefore have come from the digest -- and if it is in neither, a trim removed it and left the
33
+ // assertion pinning a string that exists nowhere.
34
+ const asserted = [...new Set(
35
+ [...raw.matchAll(/"((?:[^"\\]|\\.){6,70}?:)\\?"/g)]
36
+ .map((m) => m[1].replace(/\\"/g, '"'))
37
+ .filter((t) => /^[A-Z]/.test(t) && !/^(name|id|expect|input|env|cwd|note)/i.test(t)),
38
+ )];
39
+ const markers = asserted.filter((t) => !hook.includes(unescape(t)));
40
+
41
+ const problems = [];
42
+ for (const marker of markers) {
43
+ const missing = digests.filter((d) => !unescape(d.text).includes(unescape(marker)));
44
+ if (missing.length === digests.length) {
45
+ problems.push(`the fixture asserts "${marker}", which is in neither the hook nor any digest copy — a trim removed the bullet and the fixture was not updated in the same attempt`);
46
+ } else if (missing.length) {
47
+ problems.push(`"${marker}" is missing from ${missing.map((d) => d.f).join(', ')} — the digest copies disagree`);
48
+ }
49
+ }
50
+ if (asserted.length === 0) problems.push('no asserted substrings found — the extractor is matching nothing, which is not the same as nothing being wrong');
51
+
52
+ process.stdout.write(problems.length ? problems.join('\n') : `ok (${markers.length} digest marker(s) of ${asserted.length} asserted string(s))`);
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ // dispatch-reference-gate.mjs — asserts that every commands/*.md file which starts a real agent
3
+ // (a `Task` call naming one of the files under agents/) references skills/somi-dispatch/SKILL.md
4
+ // somewhere in its own text -- every entry path that starts an agent resolves it through the same
5
+ // dispatch procedure, not just the front door. "Starts an agent" is DERIVED from the real
6
+ // agent basenames under agents/ against the handful of call-site shapes this repo's commands
7
+ // actually use — never a hand-typed list of command names, which is exactly the kind of second
8
+ // copy that drifts (the same reasoning behind the cost-model / digest-marker derivations
9
+ // elsewhere in this test suite).
10
+ //
11
+ // A router command (`/ship`, `/ship-loop`, `/code-parallel`) Tasks other COMMANDS
12
+ // (`Task /code-loop`, …), never an agent directly, so none of the call-site patterns below match
13
+ // it and it is correctly excluded — verified empirically against the real repo, not assumed.
14
+ //
15
+ // Usage: node dispatch-reference-gate.mjs <commandsDir> <agentsDir>
16
+ // Exit 0 with "ok ..." on stdout when every agent-starting command references the skill.
17
+ // Exit 1 with one "MISSING DISPATCH REFERENCE: ..." line per violation otherwise.
18
+
19
+ import fs from 'node:fs';
20
+ import path from 'node:path';
21
+
22
+ // A reference must carry the LITERAL skill path or the LITERAL tool name -- a bare "somi-dispatch"
23
+ // substring match (the marker this file used before) is also satisfied by a mention of
24
+ // scripts/somi-dispatch.mjs (the CLI fallback), which references nothing about the RESOLVE
25
+ // procedure at all. Case-insensitive: a reference reading "the Somi-Dispatch skill" is still a
26
+ // real reference, and the point of this gate is catching a MISSING one, not policing casing.
27
+ export const DISPATCH_REFERENCE_RE = /skills\/somi-dispatch\b|\bsomi_resolve\b/i;
28
+
29
+ // The real call-site shapes this repo's commands/*.md use to start an agent, templated per real
30
+ // agent name. Matched against the RAW file text (not word-by-word), case-insensitively (a
31
+ // call-site verb at the start of a sentence or a bullet can be lowercased by surrounding prose
32
+ // without changing what it does), so a name mentioned only in passing prose (e.g. ".somi/atlas.md"
33
+ // as an artifact, or "/impact" as a command name) does not falsely count as "starts an agent" --
34
+ // only these concrete call-site idioms do.
35
+ function callSitePatterns(name) {
36
+ const n = name.replace(/-/g, '\\-');
37
+ const verbs = 'Brief|Task|Invoke|Start|Spawn|Dispatch|Run';
38
+ return [
39
+ `(?:${verbs})\\s+the\\s+\`${n}\`\\s+agent`, // Brief the `atlas` agent / Run the `atlas` agent
40
+ `(?:${verbs})\\s+the\\s+\\[\`${n}\`\\]`, // Task the [`reviewer`](../agents/reviewer.md)
41
+ `(?:${verbs})\\s+\\[\`${n}\`\\]`, // Task [`architecture-reviewer`](../agents/architecture-reviewer.md)
42
+ `(?:${verbs})\\s+\\[\`agents/${n}\\.md\`\\]`, // Brief [`agents/designer.md`](../agents/designer.md)
43
+ `Task\\s+${n}\\s*\\(`, // Task coder ( = ... )
44
+ ];
45
+ }
46
+
47
+ // Returns the first real agent name whose call-site pattern matches this command's text, or null.
48
+ export function agentStartedBy(commandText, agentNames) {
49
+ for (const name of agentNames) {
50
+ for (const pattern of callSitePatterns(name)) {
51
+ if (new RegExp(pattern, 'i').test(commandText)) return name;
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+
57
+ export function agentNamesFrom(agentsDir) {
58
+ return fs
59
+ .readdirSync(agentsDir)
60
+ .filter((f) => f.endsWith('.md'))
61
+ .map((f) => f.slice(0, -3))
62
+ // agents/somi.md is the front door itself -- no command ever Tasks it (it's a selectable
63
+ // Copilot persona, not a dispatch target), so including it would only ever add noise.
64
+ .filter((n) => n !== 'somi');
65
+ }
66
+
67
+ export function scan(commandsDir, agentsDir) {
68
+ const agentNames = agentNamesFrom(agentsDir);
69
+ const files = fs
70
+ .readdirSync(commandsDir)
71
+ .filter((f) => f.endsWith('.md'))
72
+ .sort();
73
+
74
+ const checked = [];
75
+ const missing = [];
76
+ for (const file of files) {
77
+ const full = path.join(commandsDir, file);
78
+ const text = fs.readFileSync(full, 'utf8');
79
+ const startedAgent = agentStartedBy(text, agentNames);
80
+ if (!startedAgent) continue;
81
+ checked.push(file);
82
+ if (!DISPATCH_REFERENCE_RE.test(text)) {
83
+ missing.push({ file, agent: startedAgent });
84
+ }
85
+ }
86
+ return { checked, missing };
87
+ }
88
+
89
+ function main() {
90
+ const [, , commandsDir, agentsDir] = process.argv;
91
+ if (!commandsDir || !agentsDir) {
92
+ console.error('usage: dispatch-reference-gate.mjs <commandsDir> <agentsDir>');
93
+ process.exit(2);
94
+ }
95
+ const { checked, missing } = scan(commandsDir, agentsDir);
96
+ if (missing.length > 0) {
97
+ for (const m of missing) {
98
+ console.log(
99
+ `MISSING DISPATCH REFERENCE: ${m.file} starts the '${m.agent}' agent but never names ` +
100
+ `skills/somi-dispatch or somi_resolve`,
101
+ );
102
+ }
103
+ process.exit(1);
104
+ }
105
+ console.log(`ok (${checked.length} command(s) start an agent; all reference somi-dispatch)`);
106
+ }
107
+
108
+ // Only run as a CLI when invoked directly -- tests/scripts/dispatch-reference-gate.sh imports the
109
+ // functions above instead, to exercise them against synthetic fixtures.
110
+ if (import.meta.url === `file://${process.argv[1]}`) {
111
+ main();
112
+ }