checkwright 0.20.0 → 0.21.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 (32) hide show
  1. package/package.json +2 -2
  2. package/payload/canon-kit/SPEC.md +2 -2
  3. package/payload/canon-kit/checks/check-md-refs.sh +22 -9
  4. package/payload/canon-kit/checks/check-spec-pointer.sh +6 -2
  5. package/payload/context-kit/SPEC.md +13 -6
  6. package/payload/context-kit/lib/toolfloor.sh +1 -1
  7. package/payload/delegation-kit/README.md +2 -1
  8. package/payload/delegation-kit/SPEC.md +207 -35
  9. package/payload/delegation-kit/checks/check-agent-tier-explicit.sh +61 -0
  10. package/payload/delegation-kit/gate-tests/check-agent-tier-explicit/bad/agents/silent.md +7 -0
  11. package/payload/delegation-kit/gate-tests/check-agent-tier-explicit/bad/args +1 -0
  12. package/payload/delegation-kit/gate-tests/check-agent-tier-explicit/bad/expect.txt +1 -0
  13. package/payload/delegation-kit/gate-tests/check-agent-tier-explicit/good/agents/explicit-cheap.md +7 -0
  14. package/payload/delegation-kit/gate-tests/check-agent-tier-explicit/good/agents/explicit-inherit.md +8 -0
  15. package/payload/delegation-kit/gate-tests/check-agent-tier-explicit/good/args +1 -0
  16. package/payload/delegation-kit/gate-tests/check-agent-tier-explicit/good/expect.txt +1 -0
  17. package/payload/delegation-kit/lib/delegation.sh +2 -0
  18. package/payload/delegation-kit/smoke/install.sh +1 -0
  19. package/payload/delegation-kit/templates/agent-execution.md +74 -9
  20. package/payload/gate-sdk/SPEC.md +6 -5
  21. package/payload/gate-sdk/bin/gen-pre-commit.sh +1 -1
  22. package/payload/gate-sdk/bin/run-gates.sh +1 -1
  23. package/payload/gate-sdk/checks/check-graph.sh +3 -3
  24. package/payload/gate-sdk/checks/check-reads-couples.sh +3 -1
  25. package/payload/gate-sdk/checks/check-tree-terms.sh +11 -7
  26. package/payload/gate-sdk/lib/gate.sh +29 -13
  27. package/payload/lifecycle-kit/SPEC.md +14 -4
  28. package/payload/lifecycle-kit/templates/lead.md +38 -3
  29. package/payload/site-kit/SPEC.md +104 -12
  30. package/payload/site-kit/checks/check-docs-render-fidelity.sh +100 -27
  31. package/payload/site-kit/gate-tests/check-docs-render-fidelity-batch.test.sh +158 -0
  32. package/payload/site-kit/lib/site.sh +16 -2
@@ -17,7 +17,27 @@ reach-through, not a change to this protocol; every rule below still applies.
17
17
  stops and reports rather than choosing.
18
18
  - **Background + notification, never poll.** Always `run_in_background`; wait for
19
19
  the completion notification; do not read the output file. Backgrounding keeps
20
- the main loop free to redirect.
20
+ the main loop free to redirect. Backgrounding survives a **turn**, not a
21
+ **session**. A supervisor's turn ends and its session lives on, so a
22
+ backgrounded dispatch wakes it by notification — that is the sanctioned
23
+ pattern just stated. A **dispatched agent's** turn end *is* its session end,
24
+ and what that reliably kills is the **observer, not the work**: an `Agent`
25
+ child is reaped with its parent, but a shell `run_in_background` child
26
+ survives — orphaned, still writing, with nothing left able to read it. The
27
+ survivor is the worse case, because it keeps mutating shared files while the
28
+ next actor moves against them. Either way the caller gets no result, so a
29
+ dispatched agent **never ends a turn on work still running** — it awaits its
30
+ own long-running work to completion, however long, and reports only results
31
+ it holds. Awaiting, not "dispatch in the foreground": foreground is a choice
32
+ for a shell command and not reliably one for an `Agent` dispatch, which the
33
+ harness may detach whether or not backgrounding was requested. And not by
34
+ ending the turn to wait for the completion notification — that is the one act
35
+ that revokes the channel, which is how a *careful* reader reaches this
36
+ failure. Wait **in-turn on a condition** instead: loop on the work's own
37
+ artifact (evidence file, lock, exit marker) with the harness's waiting
38
+ primitive. Never-poll governs waiting on an `Agent`'s completion notification,
39
+ a channel a supervisor has; condition-waiting is the only one a dispatched
40
+ role has.
21
41
  - **Serialize on shared files; ≤`DELEGATION_KIT_FAN_WIDTH`-wide otherwise.**
22
42
  Agents that edit a shared file (see the roster below) run one at a time —
23
43
  dispatch, await notification, validate, dispatch the next. Independent
@@ -29,6 +49,13 @@ reach-through, not a change to this protocol; every rule below still applies.
29
49
  `isolation: worktree` (own index); reserve the unlocked
30
50
  ≤`DELEGATION_KIT_FAN_WIDTH`-wide bound for **read-only** fan-outs. "No lockfile
31
51
  churn" is a false safety signal — the index is shared regardless.
52
+ Serialization is by **completion**, not by notification: the next dispatch
53
+ begins after the previous one has *returned and been validated*. A supervisor
54
+ reaches that point via the completion notification; a **dispatched agent**
55
+ reaches it in-turn, awaiting each child before dispatching the next (it cannot
56
+ end its turn to wait — see the backgrounding rule). The ordering requirement
57
+ is identical for both; only the waiting mechanism differs, and neither role
58
+ may overlap two agents on a shared file or the git index.
32
59
  - **One commit per unit, sized to finish within budget.** Each unit gets its own
33
60
  commit (+ a `[blocked-by: prior]` tag where ordered). A unit that investigates
34
61
  long before its first commit is the only thing an interrupt can destroy —
@@ -37,7 +64,7 @@ reach-through, not a change to this protocol; every rule below still applies.
37
64
  - **Gate-driven worklist where one exists.** Drive the sweep from the gate's
38
65
  output, so an interrupt loses only the in-flight uncommitted unit and a fresh
39
66
  session re-runs the gate to resume.
40
- - **Resume journal — agent writes, supervisor deletes.** The agent `Write`s a
67
+ - **Resume journal — agent writes, scratch reset sweeps.** The agent `Write`s a
41
68
  running progress journal (findings triaged, edits applied, what remains) to a
42
69
  repo-local gitignored scratch dir in the main checkout — `.tmp/` here — never a
43
70
  temporary worktree (deleted with the worktree) nor a system temp dir (a restart
@@ -48,14 +75,23 @@ reach-through, not a change to this protocol; every rule below still applies.
48
75
  `DONE` marker. Each finding is
49
76
  written into the journal *inline as it is confirmed* — never "see final
50
77
  output": the agent's return message dies with the session, so a pointer-only
51
- journal makes `DONE` lie about recoverability. **Agents have no `rm`, so the
52
- supervisor deletes the journal at the post-commit validation checkpoint.** A
53
- journal *without* a `DONE` marker signals interruption only in a **cold read**
78
+ journal makes `DONE` lie about recoverability. **Nobody deletes a journal
79
+ while the work it covers is live** — not the agent (no `rm`) and not the
80
+ supervisor, whose deletion would take the file out from under a resumed agent
81
+ and destroy its own pull channel mid-unit. Cleanup is the consumer's scratch
82
+ reset at its next work-unit boundary, not a chore in this protocol. `DONE` is
83
+ the completion marker and counts **only as the file's last line**: a session
84
+ resumed past its own marker appends after it. A journal *without* a `DONE`
85
+ marker signals interruption only in a **cold read**
54
86
  — the supervisor found a journal but never consumed the agent's return (its
55
87
  session died before returning); there, no `DONE` = interrupted, resume from
56
88
  it. On the ordinary path the supervisor consumed the return and ran its
57
89
  post-commit verification, which *is* the completion attest, so the missing
58
- marker is redundant, not a signal of interruption. **Caveat — a background agent's sandbox may block
90
+ marker is redundant, not a signal of interruption. Since every journal now
91
+ outlives its session, presence alone signals nothing — tell a live journal
92
+ from a spent one by its per-session name, the work cursor, and `git log`
93
+ (delegation-kit/SPEC.md §Resume journal — agent writes, scratch reset
94
+ sweeps). **Caveat — a background agent's sandbox may block
59
95
  the journal write.** `run_in_background` agents have been observed unable to
60
96
  `Write` to the granted path and silently falling back to returning findings in
61
97
  their final message — which makes the journal mechanic non-functional exactly
@@ -63,7 +99,23 @@ reach-through, not a change to this protocol; every rule below still applies.
63
99
  (audit, survey), the return value *is* the contract — don't rely on a journal.
64
100
  Reserve the journal / worktree isolation for agents that **mutate files**, and
65
101
  for those grant the journal path explicitly before dispatch rather than
66
- assuming the write succeeds.
102
+ assuming the write succeeds. A contract has two ends, though: the child owes
103
+ no journal, and the **parent** owes the durable landing of what it received
104
+ before acting on it (next bullet). The caveat is about a backgrounded child's
105
+ write failing silently, so it never licensed the parent — which has already
106
+ demonstrated it can write, being the session that granted the path.
107
+
108
+ - **Findings you will act on are durable before you act on them.** A child's
109
+ return value lives only in your context, and your context dies with your
110
+ session. Before you *act* on a dispatched agent's findings — edit against
111
+ them, rule from them, plan the next wave on them — land them somewhere that
112
+ survives you: a commit, or your own journal. The write is the parent's,
113
+ discharged on receipt, not a chore delegated back to the child. This binds
114
+ whoever holds findings they will act on, at any depth. It costs one write per
115
+ returned child, not a running narration. A session that is itself dispatched
116
+ writes to the journal path it was granted; a top-level session has no journal
117
+ in this contract and discharges by committing, which it is by construction
118
+ able to do.
67
119
  - **Validate after every agent commit** — a sub-agent's "passed" claim is not
68
120
  trustworthy. Re-run the relevant gates (the sweep's own gate) and the consumer
69
121
  validate battery below. **Diff every gate change in an agent commit before
@@ -90,6 +142,13 @@ reach-through, not a change to this protocol; every rule below still applies.
90
142
  window-expensive than its
91
143
  subagent-token total suggests, so size waves to leave the next one headroom, or
92
144
  accept one wave per window.
145
+ **The projection reaches downward as well as forward.** The guard re-arms at
146
+ every depth — a dispatched session's own dispatches fire it too — but each
147
+ verdict prices **one call**, never the subtree that call opens. Nothing
148
+ between a dispatch and its children's children ever sees the whole. So budget
149
+ a dispatch you expect to fan out for its **subtree**, not its own turn, and
150
+ read a child's fan-out as your spend even though its verdicts land in a
151
+ context you never see.
93
152
  **Do not read live budget off the statusline while parked on a dispatch.**
94
153
  Observed: the harness statusline does not refresh while the main session waits
95
154
  on a background agent's completion notification, so its displayed budget
@@ -113,8 +172,14 @@ reach-through, not a change to this protocol; every rule below still applies.
113
172
  whose description commits to review work, never one that disclaims it (an
114
173
  excerpt-locator serves pure search, not audit). Selection sits with the
115
174
  dispatching session — its context holds what selection
116
- needs — and a standing choice lands in a tracked agent-type definition, never
117
- per-dispatch habit.
175
+ needs — and it is **affirmative**: an unselected dispatch does not fall back
176
+ to a cheap default, it **inherits the dispatcher's tier**, so declining to
177
+ choose silently buys the most expensive tier in reach — and buys it precisely
178
+ for the read-only fan-outs that are the cheapest work you dispatch. That is
179
+ why a standing choice lands in a tracked agent-type definition rather than
180
+ per-dispatch habit, and why an omitted `model:` field there is not a neutral
181
+ default but the inherit default: the field is stated even when the answer is
182
+ to inherit.
118
183
  - **Never revert substantial completed work on your own design judgment** —
119
184
  especially an expensive delegated sweep. Surface the tension and wait for the
120
185
  explicit go-ahead before discarding it: a self-judged revert forfeits the
@@ -346,8 +346,9 @@ Every registered gate's header carries a one-line coupling manifest:
346
346
 
347
347
  - `couples=` — the surfaces the gate binds (comma-separated globs). One token
348
348
  is special: `kit:<glob>`, which the shared manifest reader in `lib/gate.sh`
349
- (`gate_expand_couples`) expands to `<kit-root>/<glob>` — repo-root-relative —
350
- for every `gate_kit_roots` member at read time; the same reader feeds
349
+ (`gate_expand_couples_var`) expands to `<kit-root>/<glob>` —
350
+ repo-root-relative — for every `gate_kit_roots` member at read time; the same
351
+ reader feeds
351
352
  `gen-pre-commit` (hook emission), `check-graph` (freshness + the HTML
352
353
  projection), and `run-gates --for` (path-scoped selection §run-gates), so
353
354
  emitter, checker, and selector cannot desync on the kit set. A
@@ -659,7 +660,7 @@ contract); the runner captures it.
659
660
  `run-gates.sh --for <path> [<path>...]` is the path-scoped selector, the
660
661
  agent-callable half of the oracle-first rule: it resolves the registry exactly
661
662
  as a bare run, then runs only the members whose *effective trigger* (`trigger=`
662
- else `couples=`, expanded through `gate_expand_couples`) glob-matches at least
663
+ else `couples=`, expanded through `gate_expand_couples_var`) glob-matches at least
663
664
  one given repo-relative path. Registry order and per-gate output are unchanged;
664
665
  a bare `run-gates.sh` keeps its behavior. The loop this buys — edit → run
665
666
  coupled gates → read the verdict+help — is strictly cheaper than reading gate
@@ -672,7 +673,7 @@ staged-path matching**: the glob step is `gate_staged_matches` in `lib/gate.sh`,
672
673
  whose body `gen-pre-commit` emits verbatim as the hook's `staged_matches` (the
673
674
  self-contained hook and the selector share one source, held in sync by
674
675
  check-graph's freshness assertion §check-graph), and both draw the `# graph:`
675
- fields through `gate_manifest_field` + `gate_expand_couples` — the single reader
676
+ fields through `gate_manifest_field` + `gate_expand_couples_var` — the single reader
676
677
  §The `# graph:` manifest names. Two hook behaviors the selector reproduces
677
678
  beyond that matcher: a `trigger=*` gate is selected for every path, and a
678
679
  `mode=staged` gate — whose hook branch matches by git pathspec (exact path or
@@ -867,7 +868,7 @@ failure report as before) or when `GATE_SDK_VERBOSE` is set, and a fully green
867
868
  hook run prints one summary line carrying its executed-invocation count. The
868
869
  wrapper lives in the emitter's heredoc, so the freshness assertion carries any
869
870
  change into the committed hooks. A `trigger=`/`couples=` `kit:<glob>` token is emitted *expanded*
870
- (via `gate_expand_couples`), so adding a kit later reddens `check-graph`
871
+ (via `gate_expand_couples_var`), so adding a kit later reddens `check-graph`
871
872
  (committed hook ≠ `--emit`) until regeneration — the freshness gate keeps the
872
873
  static hooks honest across a kit-set change.
873
874
 
@@ -69,7 +69,7 @@ emit_block() {
69
69
  local gate="$1" couples trigger mode gen relpath
70
70
  couples="$(manifest_field "$gate" couples)"
71
71
  trigger="$(manifest_field "$gate" trigger)"; trigger="${trigger:-$couples}"
72
- trigger="$(gate_expand_couples "$trigger")"
72
+ gate_expand_couples_var trigger "$trigger"
73
73
  mode="$(manifest_field "$gate" mode)"
74
74
  gen="$(manifest_field "$gate" gen)"
75
75
  relpath="$(resolve_rel "$gate")" || relpath="$GATES_DIR/$gate.sh"
@@ -60,7 +60,7 @@ select_for() {
60
60
  }
61
61
  couples="$(gate_manifest_field "$src" couples)"
62
62
  trigger="$(gate_manifest_field "$src" trigger)"; trigger="${trigger:-$couples}"
63
- trigger="$(gate_expand_couples "$trigger")"
63
+ gate_expand_couples_var trigger "$trigger"
64
64
  mode="$(gate_manifest_field "$src" mode)"
65
65
  IFS=',' read -ra globs <<<"$trigger"
66
66
  if [[ "$trigger" == '*' ]]; then
@@ -112,7 +112,7 @@ emit_graph() {
112
112
  valve=*) valve="${kv#valve=}" ;;
113
113
  esac
114
114
  done
115
- couples="$(gate_expand_couples "$couples")"
115
+ gate_expand_couples_var couples "$couples"
116
116
  C_COUPLES[$c]="$couples"; C_DIR[$c]="$dir"; C_VALVE[$c]="$valve"
117
117
  local -a csurf; IFS=',' read -ra csurf <<<"$couples"
118
118
  for s in "${csurf[@]}"; do NODE_SEEN[$s]=1; done
@@ -517,8 +517,8 @@ for c in "${CHECKS[@]}"; do
517
517
  *) errors+=("MANIFEST: $script unknown manifest key '$kv'") ;;
518
518
  esac
519
519
  done
520
- couples="$(gate_expand_couples "$couples")"
521
- [[ -n "$trigger" ]] && trigger="$(gate_expand_couples "$trigger")"
520
+ gate_expand_couples_var couples "$couples"
521
+ [[ -n "$trigger" ]] && gate_expand_couples_var trigger "$trigger"
522
522
  [[ "$dir" == bi || "$dir" == one ]] || errors+=("MANIFEST: $script dir= must be bi|one (got '$dir')")
523
523
  [[ "$valve" == none || "$valve" == PROPOSED ]] || errors+=("MANIFEST: $script valve= must be none|PROPOSED (got '$valve')")
524
524
  [[ "$tier" == precommit || "$tier" == align-only || "$tier" == commit-msg ]] || errors+=("MANIFEST: $script tier= must be precommit|align-only|commit-msg (got '$tier')")
@@ -102,7 +102,9 @@ findings=()
102
102
 
103
103
  for src in "${sources[@]+"${sources[@]}"}"; do
104
104
  [[ -f "$src" ]] || continue
105
- couples="$(gate_expand_couples "$(gate_manifest_field "$src" couples)")"
105
+ couples=""
106
+ couples_field="$(gate_manifest_field "$src" couples)"
107
+ gate_expand_couples_var couples "$couples_field"
106
108
  IFS=',' read -ra COUPLE_GLOBS <<<"$couples"
107
109
  walks="$(extract_walks "$src")"; st=$?
108
110
  fail_closed "$st" READS-COUPLES "awk walk-scan($src)"
@@ -34,20 +34,24 @@ fi
34
34
  listing="$(git ls-files -- "$SCANROOT")"; st=$?
35
35
  fail_closed "$st" TREE-TERMS git-ls-files
36
36
 
37
- patfile="$(printf '%s\n' "$patterns")"
38
- hits=""
39
- scanned=0
37
+ # spec: gate-sdk/SPEC.md §check-tree-terms — the filter pass (pruned dirs, the pattern-file's own basename, non-regular files) stays a per-path loop with no fork in it; the grep itself batches every surviving path into one process instead of re-materialising the pattern file and re-execing grep per file
38
+ paths=()
40
39
  while IFS= read -r path; do
41
40
  [[ -n "$path" ]] || continue
42
41
  gate_path_pruned "$path" && continue
43
42
  base="${path##*/}"
44
43
  [[ "$base" == msg-patterns* ]] && continue
45
44
  [[ -f "$path" ]] || continue
46
- scanned=$((scanned + 1))
47
- m="$(grep -EnHf <(printf '%s\n' "$patfile") "$path")"; mst=$?
48
- [[ "$mst" -le 1 ]] || fail_closed "$mst" TREE-TERMS grep
49
- [[ -n "$m" ]] && hits+="$m"$'\n'
45
+ paths+=("$path")
50
46
  done <<< "$listing"
47
+ scanned="${#paths[@]}"
48
+
49
+ hits=""
50
+ if [[ "$scanned" -gt 0 ]]; then
51
+ m="$(grep -EnHf <(printf '%s\n' "$patterns") "${paths[@]}")"; mst=$?
52
+ [[ "$mst" -le 1 ]] || fail_closed "$mst" TREE-TERMS grep
53
+ [[ -n "$m" ]] && hits="$m"$'\n'
54
+ fi
51
55
 
52
56
  if [[ -n "$hits" ]]; then
53
57
  echo "check-tree-terms: tracked file(s) match a banned pattern (leaked local/private term):"
@@ -122,39 +122,55 @@ gate_fixture_suites() {
122
122
  done
123
123
  }
124
124
 
125
- # spec: gate-sdk/SPEC.md §lib/gate.sh — gate_kit_roots as repo-root-relative dirs (the anchor the couples globs share); absolute roots resolve against the kits' parent, relative roots (a GATE_SDK_KIT_DIRS override) pass through
126
- gate_kit_roots_rel() {
125
+ # spec: gate-sdk/SPEC.md §lib/gate.sh — the gate_kit_roots_rel cache-fill, split out so an in-process caller (gate_expand_couples) can prime the shared _gate_kit_roots_rel_cache array and read it directly, with no stdout round-trip / process-substitution fork of its own. The kit-root set cannot change mid-process, so a cold-cache fill (the realpath-per-root fork cost) happens at most once per gate invocation.
126
+ _gate_kit_roots_rel_ensure_cache() {
127
+ [[ -n "${_gate_kit_roots_rel_cache_set:-}" ]] && return 0
127
128
  local anchor root
128
129
  anchor="${GATE_SDK_ROOT:-$(gate_sdk_root)}"; anchor="${anchor%/*}"
130
+ _gate_kit_roots_rel_cache=()
129
131
  while IFS= read -r root; do
130
132
  if [[ "$root" == /* ]]; then
131
- realpath --relative-to="$anchor" "$root" 2>/dev/null || printf '%s\n' "$root"
132
- else
133
- printf '%s\n' "$root"
133
+ root="$(realpath --relative-to="$anchor" "$root" 2>/dev/null || printf '%s' "$root")"
134
134
  fi
135
+ _gate_kit_roots_rel_cache+=("$root")
135
136
  done < <(gate_kit_roots)
137
+ _gate_kit_roots_rel_cache_set=1
136
138
  }
137
139
 
138
- # spec: gate-sdk/SPEC.md §check-graph — expand each kit:<glob> token in a comma-joined couples/trigger field to <kit-root>/<glob> for every gate_kit_roots_rel member; non-kit tokens pass through verbatim. The single reader gen-pre-commit, check-graph, and the hook share, so emitter and checker cannot desync.
139
- gate_expand_couples() {
140
- local field="$1"
141
- local -a roots=() parts=() out=()
142
- mapfile -t roots < <(gate_kit_roots_rel)
140
+ # spec: gate-sdk/SPEC.md §lib/gate.sh — gate_kit_roots as repo-root-relative dirs (the anchor the couples globs share); absolute roots resolve against the kits' parent, relative roots (a GATE_SDK_KIT_DIRS override) pass through
141
+ gate_kit_roots_rel() {
142
+ _gate_kit_roots_rel_ensure_cache
143
+ printf '%s\n' "${_gate_kit_roots_rel_cache[@]}"
144
+ }
145
+
146
+ # spec: gate-sdk/SPEC.md §check-graph — expand each kit:<glob> token in a comma-joined couples/trigger field to <kit-root>/<glob> for every gate_kit_roots_rel member; non-kit tokens pass through verbatim. Assigns into the caller's <outvar> by nameref rather than printing, so a per-manifest-line loop calls this directly (no `$(...)` fork) and the whole loop shares one _gate_kit_roots_rel_ensure_cache fill instead of paying it — and forking — once per line. gate_expand_couples below is the same expansion for a caller that still wants the stdout form.
147
+ gate_expand_couples_var() {
148
+ local -n _gate_expand_couples_out="$1"
149
+ local field="$2"
150
+ local -a parts=() out=()
151
+ _gate_kit_roots_rel_ensure_cache
143
152
  IFS=',' read -ra parts <<<"$field"
144
153
  local tok r glob
145
154
  for tok in "${parts[@]}"; do
146
155
  if [[ "$tok" == kit:* ]]; then
147
156
  glob="${tok#kit:}"
148
- for r in "${roots[@]}"; do out+=("${r%/}/$glob"); done
157
+ for r in "${_gate_kit_roots_rel_cache[@]}"; do out+=("${r%/}/$glob"); done
149
158
  else
150
159
  out+=("$tok")
151
160
  fi
152
161
  done
153
162
  local IFS=','
154
- printf '%s\n' "${out[*]}"
163
+ _gate_expand_couples_out="${out[*]}"
164
+ }
165
+
166
+ # spec: gate-sdk/SPEC.md §check-graph — the gate_expand_couples_var expansion, printed to stdout for a `$(...)` caller; gate_expand_couples_var is the in-process form a hot per-line loop should call instead.
167
+ gate_expand_couples() {
168
+ local __gate_expand_couples_result
169
+ gate_expand_couples_var __gate_expand_couples_result "$1"
170
+ printf '%s\n' "$__gate_expand_couples_result"
155
171
  }
156
172
 
157
- # spec: gate-sdk/SPEC.md §The `# graph:` manifest — read one field from a resolved gate's `# graph:` line; the shared field reader gen-pre-commit and run-gates --for selection draw the manifest through (the couples-token expansion stays gate_expand_couples, the reader check-graph also shares). Emits the value, empty when the field is absent; never fails on a missing field.
173
+ # spec: gate-sdk/SPEC.md §The `# graph:` manifest — read one field from a resolved gate's `# graph:` line; the shared field reader gen-pre-commit and run-gates --for selection draw the manifest through (the couples-token expansion is gate_expand_couples_var, the reader check-graph also shares). Emits the value, empty when the field is absent; never fails on a missing field.
158
174
  gate_manifest_field() {
159
175
  local src="$1" key="$2" man kv
160
176
  man="$(grep -m1 '^# graph: ' "$src" 2>/dev/null || true)"
@@ -1468,8 +1468,10 @@ resume journal, escalations to the message channel), the compact economics —
1468
1468
  the split-where-the-tail-dominates rule, the unified posture's handoff compact,
1469
1469
  and operator-suggested compacts at the acceptance
1470
1470
  boundaries that pay under the cold-wakes-times-compressible-residue rule —
1471
- with the dispatch-granularity rule (batch units sharing a kit or SPEC
1472
- surface, split on a model-tier change or a delegation-kit split trigger) and
1471
+ with the dispatch-granularity rule (the roster derived from every unit the
1472
+ iteration promoted rather than from the amendment set, then batch units
1473
+ sharing a kit or SPEC surface, split on a model-tier change or a
1474
+ delegation-kit split trigger) and
1473
1475
  the lead-owns-batching clause (an intra-stage batch split is N sibling stage
1474
1476
  sessions the lead dispatches and validates — each a same-stage re-entry,
1475
1477
  §The state machine — and a stage session never dispatches a sibling stage
@@ -1478,9 +1480,17 @@ the stamps-authoritative invariant carried from §The state machine as the
1478
1480
  design's load-bearing rule — with its two corollaries: the lead never
1479
1481
  hand-derives prior-stage completeness from WORKFLOW-STATE or the git log (it
1480
1482
  dispatches and trusts `enter-stage.sh`'s fail-closed refusal, or gates an
1481
- expensive dispatch with `--simulate`, §bin/enter-stage.sh), and a ruling
1483
+ expensive dispatch with `--simulate`, and reads that same drain-entry verdict
1484
+ **before** declaring a stage's batches complete rather than after,
1485
+ §bin/enter-stage.sh), and a ruling
1482
1486
  whose acting session is not imminent is filed to a durable governed surface
1483
- in the moment it is made. The template also carries the lead's first step —
1487
+ in the moment it is made. An earlier second assertion over the drain
1488
+ assertion's own population is **ruled out** on record: a batching roster has
1489
+ dropped a promoted unit in practice and `check-stage-entry` named
1490
+ it at the refused entry, so the defect is detected late — at the price of one
1491
+ wasted dispatch — rather than undetected, and a duplicate reading of one fact
1492
+ would buy only the timing the simulate read already buys for free.
1493
+ The template also carries the lead's first step —
1484
1494
  writing the session-role marker context-kit's hook reads
1485
1495
  (context-kit/SPEC.md §The session-context hook). Dispatch safety is not re-owned — it inherits
1486
1496
  delegation-kit's protocol by citation (delegation-kit/SPEC.md §The delegation
@@ -132,11 +132,18 @@ goes to the operator, never substituted by the lead's own judgment.
132
132
  ## Channel design
133
133
 
134
134
  Two channels, each with one job. Routine narration and findings go to the
135
- **resume journal** (a pull channel — delegation-kit's journal mechanics apply
136
- unchanged). The **message channel** carries only the escalation classes. This
135
+ **resume journal** (a pull channel — delegation-kit's journal mechanics own
136
+ the rest). The **message channel** carries only the escalation classes. This
137
137
  is how verbosity is controlled: by channel design, not by asking a session to
138
138
  be quiet.
139
139
 
140
+ A pull channel is read, never consumed: the lead **does not delete** a stage
141
+ session's journal, at the post-commit checkpoint or anywhere else. A resumable
142
+ session is still writing to it, and deleting it is how a lead destroys the
143
+ channel it is meant to keep reading for the rest of the unit. It is swept with
144
+ the rest of the scratch dir at the iteration boundary
145
+ (delegation-kit/SPEC.md §Resume journal — agent writes, scratch reset sweeps).
146
+
140
147
  ## Policy is config, not prose
141
148
 
142
149
  All *standing* dispatch policy — everything true of every dispatch, not the
@@ -187,6 +194,15 @@ consequences:
187
194
  context is actually common; split where the model tier changes or a
188
195
  delegation-kit split trigger fires — per-batch model tiering is the dominant
189
196
  window lever, not token counts.
197
+ The set being batched is **every unit the iteration promoted** — every
198
+ top-level entry in the configured active queue sections, debt units as much as
199
+ feature units — never the amendment set. A debt unit converges an
200
+ implementation on existing spec and mints no governed name, so it carries no
201
+ `[spec:]` ref; keying the roster on amendments makes exactly the
202
+ amendment-free half of the queue invisible, and it disappears silently because
203
+ the units that vanish are the ones that left no artifact to miss. Derive the
204
+ roster from the queue, which is the record of what was promoted, and re-read
205
+ it rather than carrying a count.
190
206
  - **Tier each batch to its work class.** The lead reads the **work-class**
191
207
  labels of the deltas in a batch — via the `[spec:]` amendments the batch's
192
208
  entries point at, where `/spec` emits one `{mechanical | design-bearing}` tag
@@ -258,7 +274,7 @@ Cache-keepalive pinging is ruled out: at batched escalation rates the idle
258
274
  re-warm pings cost more than the cold reads they avoid, burn the shared budget
259
275
  window, and invite idle-turn drift.
260
276
 
261
- ## Mechanical floor — the escalation-shape guard
277
+ ## Mechanical floor
262
278
 
263
279
  Prompts request; guards enforce. The four-header escalation shape has an
264
280
  optional guard-kit mechanical floor — a SendMessage guard registered in the
@@ -269,3 +285,22 @@ kit mechanism; the ruling-class roster stays consumer config (above).
269
285
  *<escalation-guard: whether this consumer wires the optional guard-kit
270
286
  SendMessage guard for its stage sessions, or leaves it inert — the mechanical
271
287
  floor and where its opt-in lives.>*
288
+
289
+ The floor under the batching-roster rule is `check-stage-entry`'s drain-entry
290
+ assertion: the drain stage refuses to be entered while the active queue still
291
+ carries entries, so a dropped unit surfaces as a **refused entry** at the next
292
+ stage rather than never. That is a backstop, not the working signal — it costs
293
+ a dispatch to learn from. Read it early and cheaply instead: the `--simulate`
294
+ read §The lead model already names for gating an expensive dispatch, aimed at
295
+ the drain stage, returns the same verdict with no session spent. Run it
296
+ **before** declaring a stage's batches complete, not after — a simulate run
297
+ that follows the declaration confirms the drop instead of preventing it, and a
298
+ roster has already lost a promoted unit in practice. Keying the roster on the
299
+ wrong set is only one way to lose a unit: a plain miscount against the queue
300
+ loses one just as quietly, and neither failure reddens on its own. That is why
301
+ the rule is to re-read the queue rather than to key it differently.
302
+
303
+ The floor's honest limit belongs with it: it fires on the queue's *residue*, so
304
+ it catches a dropped unit and says nothing about a unit batched onto the wrong
305
+ surface or tiered wrongly. Those stay prompt-side — the ordinary
306
+ prompts-request/guards-enforce split rather than a gap.
@@ -58,11 +58,29 @@ told to load but cannot find. Knobs:
58
58
  aliases, and dated posts are immutable published artifacts.
59
59
  - `SITE_KIT_DOCS_DIR` — the docs-site root `check-docs-render-fidelity` walks
60
60
  for tracked markdown pages, default `docs`.
61
- - `SITE_KIT_RENDERER` — array, the stdin→stdout GFM-to-HTML command
62
- `check-docs-render-fidelity` renders each page through, default the kramdown
63
- CLI invocation with GFM input — `ruby -e '…Kramdown::Document…input: "GFM"…'`,
64
- the parser GitHub Pages pins. A consumer whose Pages stack differs points this
61
+ - `SITE_KIT_RENDERER` — array, the stdin→stdout **single-document** GFM-to-HTML
62
+ command, default the kramdown CLI invocation with GFM input —
63
+ `ruby -e '…Kramdown::Document…input: "GFM"…'`, the parser GitHub Pages pins.
64
+ It is the contract `check-docs-render-fidelity` renders each page through when
65
+ `SITE_KIT_RENDERER_BATCH` is empty: one of the gate's two renderer contracts,
66
+ and the fallback of the pair. A consumer whose Pages stack differs points this
65
67
  at its own renderer; an unresolvable one fails the gate closed.
68
+ - `SITE_KIT_RENDERER_BATCH` — array, **optional**: a command rendering N
69
+ documents over one stream, `NUL`-terminated in both directions and
70
+ count-preserving, the framing specified in §check-docs-render-fidelity. Setting
71
+ it collapses the gate's per-page interpreter restarts into a single process,
72
+ which is where substantially all of that gate's cost lives. Its default is the
73
+ batch form of the same kramdown-with-GFM-input invocation `SITE_KIT_RENDERER`
74
+ defaults to — a `ruby -e` loop splitting stdin on `NUL` and writing one
75
+ `NUL`-terminated HTML document per input — filled **only when
76
+ `SITE_KIT_RENDERER` is itself still at its kit default.** Filling it
77
+ unconditionally would defeat a deliberate pin: a consumer who points
78
+ `SITE_KIT_RENDERER` at the version-locked bundle below, not knowing a second
79
+ knob now exists, would have that pinned oracle replaced by this unpinned one
80
+ and the gate would report clean against a parser build they explicitly
81
+ rejected — a false clean produced by an upgrade. Under the rule they instead
82
+ keep the per-document path at its own cost and its own semantics, and opt in by
83
+ pointing this knob at the batch form of their own pinned renderer.
66
84
  - `SITE_KIT_CONFIG_FILE` — the loader override; when set it must resolve, else
67
85
  the gate exits 2 rather than silently run on defaults.
68
86
 
@@ -184,6 +202,49 @@ consumer registers this gate; it stays outside env-probe's probe-set floor, and
184
202
  published docs site simply omits the gate by the registry-not-array convention
185
203
  and never installs the dependency.
186
204
 
205
+ **The batch stream, and why the count is the fail-closed.** One renderer process
206
+ per page is the gate's whole cost — the interpreter restarts, not the rendering —
207
+ so where `SITE_KIT_RENDERER_BATCH` is non-empty the gate renders the corpus over
208
+ one stream instead. The framing is `NUL`-terminated in both directions: the gate
209
+ writes each front-matter-stripped body, `NUL`-terminated, to the command's stdin,
210
+ and the command writes each rendered document to stdout in the **same order**,
211
+ each `NUL`-terminated. `NUL` is a *terminator* rather than a separator, so N
212
+ documents produce exactly N `NUL`s with no trailing-empty ambiguity, and it is
213
+ unforgeable by page content for a stronger reason than rarity: bash cannot hold a
214
+ `NUL` in a variable, so the gate's own reader has already dropped any `NUL` in
215
+ the source before framing happens. A sentinel line would be forgeable — by a docs
216
+ page describing this contract, first of all. Length-prefixed framing is equally
217
+ sound and loses only on the obligation it puts on a consumer, who would have to
218
+ implement exact-byte reads where splitting on a byte is a one-liner in every
219
+ language a Pages stack might use.
220
+
221
+ Two implementation constraints follow, and a natural reading of the contract
222
+ breaks both. **Command substitution strips `NUL`**, so the batch output must
223
+ never pass through `$(…)`; the gate reads it through a **process substitution**
224
+ instead, which also keeps the loop body in the current shell so the findings it
225
+ appends to survive. Writer and reader being separate processes
226
+ is what makes the exchange deadlock-free. **Process substitution discards the
227
+ renderer's exit status**, so the batch path cannot keep the per-page fail-closed
228
+ the per-document loop has — and a renderer that dies mid-stream yields fewer
229
+ documents than pages. The gate therefore compares documents-read against
230
+ pages-enumerated after the loop, which detects renderer death, truncation and
231
+ framing error alike, one check standing in for the status the shell threw away.
232
+ It exits 2 — a refusal to run the oracle — never 1, which would report a finding
233
+ about the docs. Per-document scanning is unchanged: each document read off the
234
+ stream goes through the same assertions, and the source-side scans are untouched.
235
+
236
+ **Probe routing.** The gate probes the oracle it will actually run, and only that
237
+ one. With the batch knob empty it probes `SITE_KIT_RENDERER` on a one-line
238
+ document exactly as above. With the batch knob set it probes the batch command
239
+ instead, on a probe that exercises the framing as well as the parser: two
240
+ one-line documents in, exactly two non-empty documents back. Probing the
241
+ per-document renderer too would refuse a batch-only consumer over a renderer this
242
+ run never invokes. A **failing** batch probe exits 2 and does not fall back: a
243
+ set knob is the consumer's deliberate statement about which parser is
244
+ authoritative, so quietly rendering through a different one is the same
245
+ false-clean class the fill condition in §Layout and configuration closes from the
246
+ other direction. A gate that cannot run its configured oracle refuses.
247
+
187
248
  The false-positive floor is the assertion's hard boundary, deliberately set. The
188
249
  backtick symptom rests on a property of well-formed markdown: every backtick
189
250
  belongs to a code span, which renders inside `<code>` and is excluded from the
@@ -233,9 +294,18 @@ test isolating it — a page with no fence, no surplus heading and no table, who
233
294
  only defect is the severed span, reds span-only and clears in the
234
295
  doubled-backtick form — so a widening that reds nothing new cannot pass. The
235
296
  table assertion likewise carries its own unit test (a collapsed table reds
236
- table-only, a trailing blank clears).
297
+ table-only, a trailing blank clears). The batch contract carries a unit test of
298
+ its own for the same reason — the good/bad pair sets no renderer knob, so it
299
+ already runs the batch path and cannot by itself distinguish that path from the
300
+ fallback. That test asserts the kit's two renderer defaults render a corpus
301
+ byte-identically, that a pinned `SITE_KIT_RENDERER` suppresses the batch default,
302
+ that the batch path and the per-document fallback return the same verdict on the
303
+ same pages, and that a wrong document count and an unresolvable batch command
304
+ each exit 2. The count case uses a stub that always emits two documents, so it
305
+ passes the two-document probe and is caught only by the corpus count — a stub the
306
+ probe already rejected would never reach the assertion under test.
237
307
  The positional form `check-docs-render-fidelity.sh [docs-dir] [config-file]`
238
- lets a fixture point the docs dir and renderer at a synthetic tree without
308
+ lets a fixture point the docs dir and renderer knobs at a synthetic tree without
239
309
  touching consumer config. `precommit` tier, coupling the docs tree.
240
310
 
241
311
  Parser-version fidelity (a second honest limit). The oracle is faithful to the
@@ -247,19 +317,41 @@ introduced between the two versions. The exact-pin recipe closes that gap for a
247
317
  consumer that needs it: point `SITE_KIT_RENDERER` at a version-locked bundle —
248
318
  a `bundle exec ruby …Kramdown…` invocation whose `Gemfile.lock` pins kramdown
249
319
  (and `kramdown-parser-gfm`) to the versions the `github-pages` gem resolves — so
250
- the oracle and the deploy render byte-for-byte the same parser build. The kit
251
- does not auto-resolve that pin: fetching the Pages-locked gemset at gate time
252
- would break the hermetic no-network render contract the oracle depends on (a
253
- gate must run offline and deterministically), so the pin stays a consumer's
254
- deliberate `SITE_KIT_RENDERER` override, not kit-run machinery.
320
+ the oracle and the deploy render byte-for-byte the same parser build. Pin
321
+ `SITE_KIT_RENDERER_BATCH` in the same motion, at the batch form of that same
322
+ locked bundle, or leave it unset: those are the two states in which the gate runs
323
+ the parser build the pin names. Overriding only the per-document knob already
324
+ leaves the batch knob empty by its fill rule, so a half-applied pin costs speed
325
+ rather than fidelity — but a consumer who set a batch renderer earlier and pins
326
+ only the per-document one afterwards has pinned the knob the gate will not use.
327
+ The kit does not auto-resolve the pin: fetching the Pages-locked gemset at gate
328
+ time would break the hermetic no-network render contract the oracle depends on (a
329
+ gate must run offline and deterministically), so it stays a consumer's deliberate
330
+ override, not kit-run machinery.
331
+
332
+ Renderer agreement (a third honest limit). Where a consumer sets both renderer
333
+ knobs, the kit cannot verify that their batch renderer agrees document-for-
334
+ document with their per-document one; a divergent pair yields a divergent oracle,
335
+ and nothing in the framing contract can detect that. What the kit does hold is
336
+ its own pair: the two defaults are asserted byte-identical over a corpus by
337
+ fixture, so the zero-config path is covered by construction rather than by
338
+ assumption.
255
339
 
256
340
  ## lib/site.sh
257
341
 
258
342
  The sourced config loader: it loads `SITE_KIT_CONFIG_FILE` (or the gates-dir
259
- `site-config.sh` when that env is unset), then fills every knob's default, so a
343
+ `site-config.sh` when that env is unset), then fills each knob's default, so a
260
344
  gate and a fixture read one resolved configuration. It carries no gate logic —
261
345
  structure stays in the check, values in config, defaults here.
262
346
 
347
+ Every knob's default is filled whenever the consumer left it unset, with one
348
+ exception the loader is the only place to state: `SITE_KIT_RENDERER_BATCH` is
349
+ filled only where the loader also owns `SITE_KIT_RENDERER` — where the consumer
350
+ overrode neither. A consumer who overrode the per-document renderer and left the
351
+ batch knob unset gets an empty batch array instead of a default, so the gate
352
+ keeps running the oracle they chose; §Layout and configuration states the rule
353
+ with the false clean it exists to prevent.
354
+
263
355
  ## templates/site-health.yml
264
356
 
265
357
  The scheduled live-site probe, copied verbatim into a consumer's