@sabaiway/agent-workflow-kit 10.0.0 → 10.2.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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,46 @@ Semantically versioned ([semver](https://semver.org)), newest first. The `versio
4
4
  is the current release. `upgrade` mode reads a project's `docs/ai/.workflow-version` and applies
5
5
  every `migrations/<version>-<slug>.md` newer than it, in semver order.
6
6
 
7
+ ## 10.2.0 — a review can no longer pass a change it called broken (AD-122)
8
+
9
+ Ships antigravity-cli-bridge **5.4.0** in the bundled bridge tree. A consumer recorded a clean
10
+ `SHIP WITH NITS` receipt over a review body that named a correctness bug and a security violation
11
+ under `### Blocking` — the wrapper read the verdict line and nothing read the section. Now a
12
+ ship-class verdict beside a numbered Blocking item is a verdict-body contradiction and takes the
13
+ existing failed-review arm: exit 4, no receipt, both halves named, re-run the review. `REWORK` is
14
+ never refused — a veto needs no corroboration, only a pass does — an absent Blocking section is not
15
+ a contradiction, and a repeated heading terminates the scan, so exactly one section is ever judged.
16
+
17
+ The guard was written to a contract first (`docs/ai/specs/bridges/agy-review-verdict.md`, eight
18
+ scenarios), and the bridge's test suite was split in the same change: the shared fixture surface
19
+ moved to `bin/agy-review-harness.test.mjs`, the wrapper suite shrank to 2893 lines with all 213
20
+ existing arms green, and the new contract got its own topic file. Both new files ship with the
21
+ bridge tree, so the tarball count pin moves 257 → 259.
22
+
23
+ ## 10.1.0 — no work without a specification, and a ratchet that does not trust its own file (AD-121)
24
+
25
+ A shipped tool that no LIVE contract claims is now a REFUSAL, not a preference. `tools/spec-coverage.mjs`
26
+ (the rule) and `tools/spec-coverage-cli.mjs` (argv, fs and the one write) read each contract's own
27
+ `## Module` list as the coverage map — coverage is never declared twice — and a project declares the
28
+ check as a gate. Measured at adoption in this repo: 122 tool modules, 14 governed by a contract.
29
+
30
+ The other 108 are owed, and what is owed is never STORED — it is a subtraction. `adopted` is the set
31
+ measured once at adoption and never rewritten; `settled` names the adopted paths whose contract has
32
+ since been written; the debt is the difference. So there is no list a hand can edit into a lie: the
33
+ only editable claim is "this one was paid", and every run checks that claim against the contracts
34
+ themselves — a settled path no live contract covers refuses, and refuses twice, because the tool is
35
+ uncovered again. A stored debt list was the first design and a review killed it: `--write-debt`
36
+ refusing to add a path guaranteed nothing while nobody was obliged to use it.
37
+
38
+ The scope file is validated before it is used: a wrong schema, an empty `roots` or `extensions`, a
39
+ non-string entry, or a census of ZERO files all refuse — a gate that passes because it looked at
40
+ nothing is not a pass. Exclusions are path-component boundaries, so excluding `x/fixtures` never also
41
+ hides `x/fixtures-escape.mjs`. `draft` and `retired` contracts cover nothing.
42
+
43
+ Also in this release: `tools/spec-check.mjs` counts a scenario marker as a WHOLE ordinal, so a store
44
+ reaching ten scenarios no longer refuses a correct binding while naming the wrong scenario
45
+ (`spec:x/S1` used to occur twice the moment `spec:x/S11` was written beside it).
46
+
7
47
  ## 10.0.0 — a symlinked docs file gets named instead of skipped (AD-119)
8
48
 
9
49
  Mirrors the memory canon: `references/scripts/check-docs-size.mjs` no longer lets a symlinked docs
package/SKILL.md CHANGED
@@ -3,7 +3,7 @@ name: agent-workflow-kit
3
3
  description: Deploy or upgrade a portable AI-agent memory-and-workflow system in any project. Use when the user wants to bootstrap `docs/ai/` + an entry-point `AGENTS.md` (+ `CLAUDE.md` alias) + cap/archive/index enforcement in a new or existing repo, set up the Memory Map and session protocols, install the docs-rotation pre-commit hook, or run `/agent-workflow-kit` / `/agent-workflow-kit upgrade`. Triggers on phrases like "set up the memory system", "deploy the AI workflow here", "bootstrap docs/ai", "upgrade the workflow".
4
4
  disable-model-invocation: true
5
5
  metadata:
6
- version: '10.0.0'
6
+ version: '10.2.0'
7
7
  ---
8
8
 
9
9
  # agent-workflow-kit
@@ -2,7 +2,7 @@
2
2
  name: antigravity-cli-bridge
3
3
  description: Delegate work to Google's Antigravity CLI (`agy`) — the successor to Gemini CLI — to reach Gemini, Claude, and GPT-OSS models under a Google AI Pro/Ultra subscription from the terminal. Use when the user wants to run a headless `agy` prompt, hand a focused task or second-opinion review to `agy`, install or authenticate Antigravity CLI, check or economise its quota/models, bridge project context into `agy`, set up a second delegated-execution backend beside Codex, or troubleshoot `agy` flags, models, auth, conversations, or its headless behaviour.
4
4
  metadata:
5
- version: '5.3.0'
5
+ version: '5.4.0'
6
6
  ---
7
7
 
8
8
  # antigravity-cli-bridge
@@ -163,7 +163,9 @@ billed turn restating the model's own prose (16,585 → 33,446 tokens on a match
163
163
 
164
164
  **Honesty + posture (D4/D5):** a run with no recognized `### Verdict` section — empty output
165
165
  included — **exits 4 with NO receipt**: treat it as a *failed review to re-run*, never a fatal
166
- session error. One stderr banner states the actual posture (`review posture: model=… timeout=…`)
166
+ session error. The verdict vocabulary is closed (SHIP / SHIP WITH NITS / REWORK), and a
167
+ ship-class verdict arriving beside a numbered `### Blocking` finding is a verdict-body
168
+ contradiction: the same exit 4, NO receipt, both halves named. One stderr banner states the actual posture (`review posture: model=… timeout=…`)
167
169
  and the receipt records the same `posture {model}`; an attesting review with `AGY_MODEL` explicitly
168
170
  emptied refuses pre-spend (`AGY_PROBE=1` exempt), and control bytes in a model string refuse
169
171
  pre-spend in every mode. The `timeout=` field is **banner-only** (exactly the duration `agy-run`
@@ -0,0 +1,288 @@
1
+ // Shared harness for the agy-review wrapper suites. PORTING TRAP: agy takes the prompt as the
2
+ // `-p` ARGV value, NOT stdin — the fake captures the -p value from argv.
3
+ import assert from 'node:assert/strict';
4
+ import { after } from 'node:test';
5
+ import {
6
+ mkdtempSync, mkdirSync, writeFileSync, chmodSync, rmSync, readFileSync,
7
+ existsSync, readdirSync, symlinkSync, cpSync,
8
+ } from 'node:fs';
9
+ import { tmpdir } from 'node:os';
10
+ import { join, dirname, resolve } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { spawnSync, execFile } from 'node:child_process';
13
+
14
+ const HERE = dirname(fileURLToPath(import.meta.url));
15
+ export const WRAPPER = join(HERE, 'agy-review.sh');
16
+
17
+ const FAKE_ENVELOPE_ENCODER = [
18
+ 'const text = require("node:fs").readFileSync(0, "utf8");',
19
+ 'const [cid, status, shape] = process.argv.slice(1);',
20
+ 'const envelope = { conversation_id: cid, status, response: text, duration_seconds: 1.5, num_turns: 1,',
21
+ ' usage: { input_tokens: 10, output_tokens: 5, thinking_tokens: 0, cache_read_tokens: 0, total_tokens: 15 } };',
22
+ 'if (shape === "missing") delete envelope.conversation_id;',
23
+ 'if (shape === "number") envelope.conversation_id = 42;',
24
+ 'process.stdout.write(`${JSON.stringify(envelope)}\\n`);',
25
+ ].join('\n');
26
+
27
+ export const FAKE_AGY = [
28
+ '#!/usr/bin/env bash',
29
+ 'set -u',
30
+ // --help / --version answer BEFORE any capture file is touched — a probe is never a paid dispatch.
31
+ 'case "${1:-}" in',
32
+ ' --help|-h)',
33
+ ' if [[ -n "${AGY_FAKE_HELP_EXIT:-}" ]]; then echo "fake agy: help unavailable" >&2; exit "$AGY_FAKE_HELP_EXIT"; fi',
34
+ ' for f in --output-format --json-schema --disable-slash-commands --effort --mode; do',
35
+ ' if [[ "$f" == "${AGY_FAKE_HELP_OMIT:-}" ]]; then continue; fi',
36
+ ' printf " %s fake capability line\\n" "$f"',
37
+ ' done',
38
+ ' if [[ -n "${AGY_FAKE_HELP_EXTRA:-}" ]]; then printf "%s\\n" "$AGY_FAKE_HELP_EXTRA"; fi',
39
+ ' exit 0 ;;',
40
+ ' --version) printf "%s\\n" "${AGY_FAKE_VERSION:-1.1.13}"; exit 0 ;;',
41
+ 'esac',
42
+ ': "${AGY_FAKE_ARGV:=/dev/null}"',
43
+ ': "${AGY_FAKE_ENV:=/dev/null}"',
44
+ ': "${AGY_FAKE_PROMPT:=/dev/null}"',
45
+ ': "${AGY_FAKE_SENTINEL:=/dev/null}"',
46
+ 'printf invoked > "$AGY_FAKE_SENTINEL"',
47
+ 'printf "%s" "$PWD" > "${AGY_FAKE_CWD:-/dev/null}"',
48
+ '{ for a in "$@"; do printf "%s\\n" "$a"; done; } > "$AGY_FAKE_ARGV"',
49
+ '{ echo "FOO_API_KEY=${FOO_API_KEY:-<unset>}"; echo "ANTIGRAVITY_API_KEY=${ANTIGRAVITY_API_KEY:-<unset>}"; } > "$AGY_FAKE_ENV"',
50
+ 'prompt=""',
51
+ 'prev=""; for a in "$@"; do if [[ "$prev" == "-p" ]]; then prompt="$a"; printf "%s" "$a" > "$AGY_FAKE_PROMPT"; fi; prev="$a"; done',
52
+ 'aw_fmt=""',
53
+ 'prev=""; for a in "$@"; do if [[ "$prev" == "--output-format" ]]; then aw_fmt="$a"; fi; prev="$a"; done',
54
+ // AGY_FAKE_BAD_TURN scopes the transport-breaking knobs to ONE turn; AGY_FAKE_RAW_STDOUT bypasses
55
+ // the envelope encoder entirely.
56
+ 'aw_fake_emit() {',
57
+ ' local body="$1" aw_status="${AGY_FAKE_STATUS:-SUCCESS}" aw_raw=""',
58
+ ' if [[ -n "${AGY_FAKE_RAW_STDOUT+x}" ]]; then aw_raw=1; fi',
59
+ ' if [[ -n "${AGY_FAKE_BAD_TURN:-}" && "$turn" != "${AGY_FAKE_BAD_TURN}" ]]; then aw_status="SUCCESS"; aw_raw=""; fi',
60
+ ' if [[ -n "${AGY_FAKE_STDERR:-}" ]]; then printf "%s\\n" "$AGY_FAKE_STDERR" >&2; fi',
61
+ ' if [[ -n "$aw_raw" ]]; then printf "%s" "$AGY_FAKE_RAW_STDOUT"; return 0; fi',
62
+ ' if [[ "$aw_fmt" != "json" ]]; then printf "%s\\n" "$body"; return 0; fi',
63
+ ` printf "%s\\n" "$body" | node -e '${FAKE_ENVELOPE_ENCODER}' \\`,
64
+ ' "${AGY_FAKE_CONV_ID:-11111111-2222-3333-4444-555555555555}" "$aw_status" "${AGY_FAKE_CONV_SHAPE:-ok}"',
65
+ '}',
66
+ 'prev=""; for a in "$@"; do',
67
+ ' if [[ "$prev" == "--add-dir" ]]; then',
68
+ ' printf "%s" "$a" > "${AGY_FAKE_ADDDIR:-/dev/null}"',
69
+ ' stat -c "%a" "$a" > "${AGY_FAKE_ADDDIR_MODE:-/dev/null}" 2>/dev/null || true',
70
+ ' art="$a/precomputed-change-set"',
71
+ ' if [[ -f "$art" ]]; then stat -c "%a" "$art" > "${AGY_FAKE_ARTIFACT_MODE:-/dev/null}" 2>/dev/null || true; cp "$art" "${AGY_FAKE_ARTIFACT_COPY:-/dev/null}" 2>/dev/null || true; fi',
72
+ ' fi; prev="$a"',
73
+ 'done',
74
+ 'if [[ -n "${AGY_FAKE_SLEEP:-}" ]]; then sleep "$AGY_FAKE_SLEEP"; fi',
75
+ // The fed lane needs a PER-TURN record: each invocation writes prompt/argv to "<file>.<turn>".
76
+ 'turn=1',
77
+ 'if [[ -n "${AGY_FAKE_TURNS:-}" ]]; then',
78
+ ' if [[ -s "$AGY_FAKE_TURNS" ]]; then turn=$(( $(cat "$AGY_FAKE_TURNS") + 1 )); fi',
79
+ ' printf "%s" "$turn" > "$AGY_FAKE_TURNS"',
80
+ ' printf "%s" "$prompt" > "${AGY_FAKE_PROMPT}.$turn"',
81
+ ' { for a in "$@"; do printf "%s\\n" "$a"; done; } > "${AGY_FAKE_ARGV}.$turn"',
82
+ 'fi',
83
+ 'if [[ -n "${AGY_FAKE_FAIL_TURN:-}" && "$turn" == "${AGY_FAKE_FAIL_TURN}" ]]; then',
84
+ ' printf "FAKE_TURN_FAILURE\\n" >&2; exit 3',
85
+ 'fi',
86
+ // A FEED turn deliberately misbehaves (a premature verdict) so the isolation invariant is proven
87
+ // against the worst case.
88
+ 'if [[ -z "${AGY_FAKE_OUTPUT+x}" && "$prompt" == *"--- BEGIN CHANGE-SET PART "* && "$prompt" != *"Requested addresses"* ]]; then',
89
+ ' aw_fake_emit "$(printf "PREMATURE_FEED_CHATTER\\n### Verdict\\nREWORK")"; exit 0',
90
+ 'fi',
91
+ // The FINAL turn answers the delivery-proof request honestly: by reading the bodies it was fed.
92
+ 'if [[ -z "${AGY_FAKE_OUTPUT+x}" && "$prompt" == *"Requested addresses"* ]]; then',
93
+ ' req="$(printf "%s" "$prompt" | awk "/^Requested addresses/{f=1; next} f && /^###/{exit} f{print}")"',
94
+ ' entries=()',
95
+ ' mapfile -t _items <<< "$req"',
96
+ ' for _it in "${_items[@]}"; do',
97
+ ' [[ -n "$_it" ]] || continue',
98
+ ' k="$(printf "%s" "$_it" | awk "{print \\$2}")"; l="$(printf "%s" "$_it" | awk "{print \\$4}")"',
99
+ ' src="$k"',
100
+ ' if [[ "${AGY_FAKE_PROOF_DUP:-}" == "1" ]]; then src=1; fi',
101
+ ' if [[ "${AGY_FAKE_PROOF_OMIT:-}" == "$k" ]]; then continue; fi',
102
+ ' body="$(awk -v want="$l" "f && /^--- END CHANGE-SET PART /{exit} f{c++; if (c==want) {print; exit}} /^--- BEGIN CHANGE-SET PART /{f=1}" "${AGY_FAKE_PROMPT}.$src")"',
103
+ ' if [[ "${AGY_FAKE_PROOF_CORRUPT:-}" == "$k" ]]; then body="${body}X"; fi',
104
+ ' entry="$(printf "part %s line %s: %s" "$k" "$l" "$body")"',
105
+ ' if [[ "${AGY_FAKE_PROOF_BULLET:-}" == "1" ]]; then entry="- $entry"; fi',
106
+ ' if [[ "${AGY_FAKE_PROOF_NESTED:-}" == "$k" ]]; then entry="note: I believe $entry"; fi',
107
+ ' if [[ "${AGY_FAKE_PROOF_PAD:-}" == "1" ]]; then entry="$(printf "part %02d line %04d: %s" "$k" "$l" "$body")"; fi',
108
+ ' if [[ "${AGY_FAKE_PROOF_CASE:-}" == "1" ]]; then entry="$(printf "Part %s Line %s: %s" "$k" "$l" "$body")"; fi',
109
+ ' if [[ "${AGY_FAKE_PROOF_HUGE:-}" == "$k" ]]; then entry="$(printf "part %s line 99999999999999999999: %s" "$k" "$body")"; fi',
110
+ ' entries+=("$entry")',
111
+ ' if [[ "${AGY_FAKE_PROOF_TWICE:-}" == "1" ]]; then entries+=("$entry"); fi',
112
+ ' done',
113
+ ' if [[ "${AGY_FAKE_PROOF_EXTRA:-}" == "1" ]]; then entries+=("part 99 line 1: an address nobody asked for"); fi',
114
+ ' if [[ "${AGY_FAKE_PROOF_HUGE_EXTRA:-}" == "1" ]]; then entries+=("part 99999999999999999999 line 1: an invented giant address"); fi',
115
+ ' out="$( {',
116
+ ' if [[ "${AGY_FAKE_PROOF_LATE:-}" == "1" ]]; then printf "### Verdict\\nSHIP\\n"; fi',
117
+ ' if [[ "${AGY_FAKE_PROOF_CASE:-}" == "1" ]]; then printf "### Delivery Proof\\n"; else printf "### Delivery proof\\n"; fi',
118
+ ' if [[ "${AGY_FAKE_PROOF_OUTSIDE:-}" == "1" ]]; then',
119
+ ' printf "(nothing here)\\n### Verdict\\nSHIP\\n"',
120
+ ' if (( ${#entries[@]} > 0 )); then printf "%s\\n" "${entries[@]}"; fi',
121
+ ' else',
122
+ ' if (( ${#entries[@]} > 0 )); then printf "%s\\n" "${entries[@]}"; fi',
123
+ ' printf "### Verdict\\nSHIP\\n"',
124
+ ' fi',
125
+ ' if [[ -n "${AGY_FAKE_FINAL_APPEND:-}" ]]; then printf "%s\\n" "$AGY_FAKE_FINAL_APPEND"; fi',
126
+ ' } )"',
127
+ ' aw_fake_emit "$out"',
128
+ ' exit 0',
129
+ 'fi',
130
+ 'if [[ -z "${AGY_FAKE_OUTPUT+x}" ]]; then aw_fake_emit "$(printf "FAKE_AGY_REVIEW_OUTPUT\\n### Verdict\\nSHIP")"; else aw_fake_emit "$AGY_FAKE_OUTPUT"; fi',
131
+ 'exit "${AGY_FAKE_EXIT:-0}"',
132
+ '',
133
+ ].join('\n');
134
+
135
+ // A PATH whose entries are symlinks to the real PATH binaries EXCEPT the excluded names.
136
+ const makePathWithout = (root, exclude = []) => {
137
+ const skip = new Set(exclude);
138
+ const dir = mkdtempSync(join(root, 'nobin-'));
139
+ for (const d of (process.env.PATH || '').split(':').filter(Boolean)) {
140
+ let names;
141
+ try { names = readdirSync(d); } catch { continue; }
142
+ for (const name of names) {
143
+ if (skip.has(name)) continue;
144
+ const link = join(dir, name);
145
+ if (existsSync(link)) continue;
146
+ try { symlinkSync(resolve(d, name), link); } catch { /* dup / race — ignore */ }
147
+ }
148
+ }
149
+ return dir;
150
+ };
151
+
152
+ // Farms and the sandbox template are read-only per invocation, so both are built ONCE and shared.
153
+ const SHARED_ROOT = mkdtempSync(join(tmpdir(), 'agy-review-shared-'));
154
+ after(() => rmSync(SHARED_ROOT, { recursive: true, force: true }));
155
+ const farms = new Map();
156
+ export const farmFor = (exclude) => {
157
+ const key = exclude.join('|');
158
+ if (!farms.has(key)) farms.set(key, makePathWithout(SHARED_ROOT, exclude));
159
+ return farms.get(key);
160
+ };
161
+
162
+ const TEMPLATE_HOME = (() => {
163
+ const home = join(SHARED_ROOT, 'template-home');
164
+ const bin = join(home, '.local', 'bin');
165
+ mkdirSync(bin, { recursive: true });
166
+ writeFileSync(join(bin, 'agy'), FAKE_AGY, { mode: 0o755 });
167
+ const repo = join(home, 'repo');
168
+ mkdirSync(repo);
169
+ const g = (...args) => spawnSync('git', args, { cwd: repo, encoding: 'utf8' });
170
+ g('init', '-q');
171
+ g('config', 'user.email', 'probe@example.com');
172
+ g('config', 'user.name', 'probe');
173
+ writeFileSync(join(repo, 'base.txt'), 'committed base\n');
174
+ g('add', '-A');
175
+ g('commit', '-qm', 'base');
176
+ return home;
177
+ })();
178
+
179
+ // `clean: true` leaves a pristine committed tree; the default leaves one untracked file so `code`
180
+ // mode has a diff to review.
181
+ export const makeSandbox = ({ clean = false } = {}) => {
182
+ const home = mkdtempSync(join(tmpdir(), 'agy-review-test-'));
183
+ cpSync(TEMPLATE_HOME, home, { recursive: true });
184
+ const bin = join(home, '.local', 'bin');
185
+ chmodSync(join(bin, 'agy'), 0o755);
186
+ const repo = join(home, 'repo');
187
+ const g = (...args) => spawnSync('git', args, { cwd: repo, encoding: 'utf8' });
188
+ if (!clean) writeFileSync(join(repo, 'pending.txt'), 'PENDING_UNTRACKED_BODY\n');
189
+ return { home, bin, repo, g };
190
+ };
191
+
192
+ let runSeq = 0;
193
+ // Asynchronous on purpose: a blocking spawnSync pinned the whole suite to one core.
194
+ export const run = (sb, { args, env = {}, cwd, wrapper } = {}) => new Promise((settle) => {
195
+ const { home, bin, repo } = sb;
196
+ const farm = farmFor(['agy', 'agy-run']);
197
+ const tag = `cap-${++runSeq}`;
198
+ const cap = {
199
+ argv: join(home, `${tag}-argv`), env: join(home, `${tag}-env`), prompt: join(home, `${tag}-prompt`),
200
+ sentinel: join(home, `${tag}-sentinel`), adddir: join(home, `${tag}-adddir`),
201
+ adddirMode: join(home, `${tag}-adddir-mode`), artifactMode: join(home, `${tag}-artifact-mode`),
202
+ artifactCopy: join(home, `${tag}-artifact-copy`), turns: join(home, `${tag}-turns`),
203
+ dispatchCwd: join(home, `${tag}-dispatch-cwd`),
204
+ };
205
+ const child = execFile('bash', [wrapper || WRAPPER, ...args], {
206
+ cwd: cwd || repo,
207
+ encoding: 'utf8',
208
+ timeout: 30000,
209
+ maxBuffer: 64 * 1024 * 1024,
210
+ env: {
211
+ HOME: home,
212
+ PATH: `${bin}:${farm}`,
213
+ TMPDIR: process.env.TMPDIR ?? '/tmp',
214
+ AGY_FAKE_ARGV: cap.argv, AGY_FAKE_ENV: cap.env, AGY_FAKE_PROMPT: cap.prompt,
215
+ AGY_FAKE_SENTINEL: cap.sentinel, AGY_FAKE_ADDDIR: cap.adddir, AGY_FAKE_ADDDIR_MODE: cap.adddirMode,
216
+ AGY_FAKE_ARTIFACT_MODE: cap.artifactMode, AGY_FAKE_ARTIFACT_COPY: cap.artifactCopy,
217
+ AGY_FAKE_TURNS: cap.turns, AGY_FAKE_CWD: cap.dispatchCwd,
218
+ ...env,
219
+ },
220
+ }, (error, stdout, stderr) => {
221
+ const readIf = (p) => (existsSync(p) ? readFileSync(p, 'utf8') : '');
222
+ const turns = existsSync(cap.turns) ? Number(readFileSync(cap.turns, 'utf8')) : 0;
223
+ const prompts = [];
224
+ const argvs = [];
225
+ for (let i = 1; i <= turns; i += 1) {
226
+ prompts.push(readIf(`${cap.prompt}.${i}`));
227
+ argvs.push(readIf(`${cap.argv}.${i}`));
228
+ }
229
+ settle({
230
+ status: error ? (error.code ?? 1) : 0, signal: error?.signal ?? null, stdout, stderr,
231
+ invoked: existsSync(cap.sentinel),
232
+ argv: readIf(cap.argv), capEnv: readIf(cap.env), prompt: readIf(cap.prompt),
233
+ adddir: readIf(cap.adddir).trim(), adddirMode: readIf(cap.adddirMode).trim(),
234
+ artifactMode: readIf(cap.artifactMode).trim(), artifactCopy: readIf(cap.artifactCopy),
235
+ dispatchCwd: readIf(cap.dispatchCwd).trim(), turns, prompts, argvs,
236
+ });
237
+ });
238
+ // Only EPIPE is a refusal working — any other stdin write failure must reach the test.
239
+ child.stdin.on('error', (err) => { if (err.code !== 'EPIPE') throw err; });
240
+ child.stdin.end();
241
+ });
242
+
243
+ export const runAsync = run;
244
+
245
+ export const RECEIPTS_REL = join('.git', 'agent-workflow-review-receipts.jsonl');
246
+ export const readReceipts = (repo) => {
247
+ const p = join(repo, RECEIPTS_REL);
248
+ if (!existsSync(p)) return [];
249
+ return readFileSync(p, 'utf8').trim().split('\n').filter(Boolean).map((l) => JSON.parse(l));
250
+ };
251
+
252
+ // The chunked-feed lane: an over-cap change set is DELIVERED over turns and its delivery is PROVEN
253
+ // by verbatim line echoes the final answer must reproduce.
254
+ export const ARTIFACT_HEADER = '## The change set under review (assembled working-tree diff — repo-complete)';
255
+ export const SHAPE_HEADER = '\n## Output — Markdown, this exact shape, nothing else';
256
+ export const FED_CAP = 6000;
257
+ export const MAX_COUNTABLE_PROOF_ADDRESS = 40;
258
+ export const FED_WIDE_CAP = 24000;
259
+ export const isAssemblerBanner = (line) =>
260
+ /^=== (repo file map|git status|staged diff|unstaged diff|untracked)/.test(line) && line.endsWith(' ===');
261
+
262
+ export const seedFedChangeSet = (sb, { lines = 400, multibyte = false } = {}) => {
263
+ const body = Array.from({ length: lines }, (_, i) =>
264
+ multibyte
265
+ ? `line ${String(i).padStart(4, '0')} — multibyte marker ${'\u044e'.repeat(20)}`
266
+ : `unique change-set line ${String(i).padStart(4, '0')} — a distinctive body marker ${'x'.repeat(20)}`).join('\n');
267
+ writeFileSync(join(sb.repo, 'oversized.txt'), `${body}\n`);
268
+ };
269
+
270
+ export const inlineArtifactOf = (prompt) => prompt.slice(prompt.indexOf(ARTIFACT_HEADER), prompt.indexOf(SHAPE_HEADER));
271
+ export const bodyOf = (turnPrompt) => {
272
+ const begin = turnPrompt.match(/--- BEGIN CHANGE-SET PART \d+ OF \d+ ---\n/);
273
+ if (!begin) return null;
274
+ const start = begin.index + begin[0].length;
275
+ return turnPrompt.slice(start, turnPrompt.indexOf('\n--- END CHANGE-SET PART ', start));
276
+ };
277
+ export const requestedBlockOf = (finalPrompt) => {
278
+ const start = finalPrompt.indexOf('Requested addresses');
279
+ assert.notEqual(start, -1, 'the final turn states which lines it requires');
280
+ const after2 = finalPrompt.slice(finalPrompt.indexOf('\n', start) + 1);
281
+ return after2.slice(0, after2.indexOf('\n###')).split('\n').filter(Boolean);
282
+ };
283
+ export const requestedOf = (finalPrompt) => requestedBlockOf(finalPrompt).map((item) => {
284
+ const [, part, line] = item.match(/^part (\d+) line (\d+)$/);
285
+ return { part: Number(part), line: Number(line) };
286
+ });
287
+ export const fedRun = (sb, extraEnv = {}) =>
288
+ run(sb, { args: ['code', '--facts', 'grounded fact'], env: { AGY_MAX_PROMPT_BYTES: String(FED_CAP), ...extraEnv } });
@@ -0,0 +1,109 @@
1
+ // Contract under test: docs/ai/specs/bridges/agy-review-verdict.md (verdict-body honesty).
2
+ import { describe, it } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { rmSync, readFileSync } from 'node:fs';
5
+ import { dirname, resolve } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ import { makeSandbox, run, readReceipts, seedFedChangeSet, fedRun } from './agy-review-harness.test.mjs';
8
+
9
+ const HERE = dirname(fileURLToPath(import.meta.url));
10
+
11
+ const CONTRADICTION_OUTPUT = '### Verdict\nSHIP WITH NITS — solid, two nits.\n### Blocking\n1. correctness: drops the last chunk\n2. security: path traversal in the staging dir\n### Non-blocking\nnone\n### Questions\nnone';
12
+
13
+ describe('agy-review.sh — a ship-class verdict cannot ride numbered Blocking findings', { concurrency: 2 }, () => {
14
+ // spec:agy-review-verdict/S1
15
+ it('a ship-class verdict beside a numbered Blocking item exits 4 with NO receipt — fresh and fed lanes alike', async () => {
16
+ const fresh = makeSandbox();
17
+ const r = await run(fresh, { args: ['code', '--facts', 'a tiny fact'], env: { AGY_FAKE_OUTPUT: CONTRADICTION_OUTPUT } });
18
+ const freshReceipts = readReceipts(fresh.repo);
19
+ rmSync(fresh.home, { recursive: true, force: true });
20
+ assert.equal(r.status, 4, r.stderr);
21
+ assert.equal(r.invoked, true, 'the contradiction is judged AFTER the run — a failed review, not a pre-spend refusal');
22
+ assert.equal(freshReceipts.length, 0, 'a contradictory run mints nothing');
23
+ const sb = makeSandbox();
24
+ seedFedChangeSet(sb);
25
+ const fed = await fedRun(sb, { AGY_FAKE_FINAL_APPEND: '### Blocking\n1. a numbered blocker the verdict ignores' });
26
+ const fedReceipts = readReceipts(sb.repo);
27
+ rmSync(sb.home, { recursive: true, force: true });
28
+ assert.equal(fed.status, 4, fed.stderr);
29
+ assert.equal(fedReceipts.length, 0, 'the fed lane refuses the same shape after a PROVEN delivery');
30
+ });
31
+
32
+ // spec:agy-review-verdict/S2
33
+ it('a Blocking body of none — any case, trailing punctuation — mints exactly as today', async () => {
34
+ for (const noneForm of ['none', 'None.', 'NONE']) {
35
+ const sb = makeSandbox();
36
+ const output = `### Verdict\nSHIP WITH NITS — fine.\n### Blocking\n${noneForm}\n### Non-blocking\nnone\n### Questions\nnone`;
37
+ const r = await run(sb, { args: ['code', '--facts', 'a tiny fact'], env: { AGY_FAKE_OUTPUT: output } });
38
+ const receipts = readReceipts(sb.repo);
39
+ rmSync(sb.home, { recursive: true, force: true });
40
+ assert.equal(r.status, 0, `"${noneForm}" must pass: ${r.stderr}`);
41
+ assert.equal(receipts.length, 1);
42
+ assert.equal(receipts[0].verdict, 'SHIP WITH NITS');
43
+ }
44
+ });
45
+
46
+ // spec:agy-review-verdict/S3
47
+ it('REWORK is never refused by the cross-check, numbered Blocking items or not', async () => {
48
+ const sb = makeSandbox();
49
+ const output = '### Verdict\nREWORK — two real blockers.\n### Blocking\n1. the guard fails open\n2. the receipt lies\n### Non-blocking\nnone\n### Questions\nnone';
50
+ const r = await run(sb, { args: ['code', '--facts', 'a tiny fact'], env: { AGY_FAKE_OUTPUT: output } });
51
+ const receipts = readReceipts(sb.repo);
52
+ rmSync(sb.home, { recursive: true, force: true });
53
+ assert.equal(r.status, 0, r.stderr);
54
+ assert.equal(receipts.length, 1, 'a veto needs no corroboration');
55
+ assert.equal(receipts[0].verdict, 'REWORK');
56
+ });
57
+
58
+ // spec:agy-review-verdict/S4
59
+ it('an absent Blocking section is not a contradiction — the verdict-only read is unchanged', async () => {
60
+ const sb = makeSandbox();
61
+ const r = await run(sb, { args: ['code', '--facts', 'a tiny fact'], env: { AGY_FAKE_OUTPUT: '### Verdict\nSHIP — clean, no sections beyond this one.' } });
62
+ const receipts = readReceipts(sb.repo);
63
+ rmSync(sb.home, { recursive: true, force: true });
64
+ assert.equal(r.status, 0, r.stderr);
65
+ assert.equal(receipts.length, 1, 'the shape mandate lives in the prompt; absence is not judged here');
66
+ assert.equal(receipts[0].verdict, 'SHIP');
67
+ });
68
+
69
+ // spec:agy-review-verdict/S5
70
+ it('the continuation lane refuses a contradictory verdict before its informational receipt', async () => {
71
+ const sb = makeSandbox();
72
+ const r = await run(sb, { args: ['--continue'], env: { AGY_FAKE_OUTPUT: CONTRADICTION_OUTPUT } });
73
+ const receipts = readReceipts(sb.repo);
74
+ rmSync(sb.home, { recursive: true, force: true });
75
+ assert.equal(r.status, 4, r.stderr);
76
+ assert.equal(receipts.length, 0, 'a fresh:false receipt must not encode a contradiction either');
77
+ });
78
+
79
+ // spec:agy-review-verdict/S6
80
+ it('the refusal names both halves and the verdict is never rewritten or downgraded', async () => {
81
+ const sb = makeSandbox();
82
+ const r = await run(sb, { args: ['code', '--facts', 'a tiny fact'], env: { AGY_FAKE_OUTPUT: CONTRADICTION_OUTPUT } });
83
+ const receipts = readReceipts(sb.repo);
84
+ rmSync(sb.home, { recursive: true, force: true });
85
+ assert.equal(r.status, 4);
86
+ assert.match(r.stderr, /SHIP WITH NITS — solid, two nits\./, 'the RAW verdict line is named, reason text included');
87
+ assert.match(r.stderr, /drops the last chunk/, 'the first numbered Blocking item is named');
88
+ assert.match(r.stderr, /[Rr]e-run the review/, 'the recovery is the same as every failed review');
89
+ assert.equal(receipts.length, 0, 'no rewritten or downgraded verdict is ever minted');
90
+ });
91
+
92
+ // spec:agy-review-verdict/S8
93
+ it('a second Blocking heading terminates the scan — only the first section is judged', async () => {
94
+ const sb = makeSandbox();
95
+ const output = '### Verdict\nSHIP — clean.\n### Blocking\nnone\n### Blocking\n1. a numbered item under a duplicate heading\n### Questions\nnone';
96
+ const r = await run(sb, { args: ['code', '--facts', 'a tiny fact'], env: { AGY_FAKE_OUTPUT: output } });
97
+ const receipts = readReceipts(sb.repo);
98
+ rmSync(sb.home, { recursive: true, force: true });
99
+ assert.equal(r.status, 0, r.stderr);
100
+ assert.equal(receipts.length, 1, 'the first section said none — a later heading cannot suppress the receipt');
101
+ assert.equal(receipts[0].verdict, 'SHIP');
102
+ });
103
+
104
+ // spec:agy-review-verdict/S7
105
+ it('the loadable skill text names the closed verdict vocabulary', async () => {
106
+ const skill = readFileSync(resolve(HERE, '..', 'SKILL.md'), 'utf8');
107
+ assert.match(skill, /SHIP \/ SHIP WITH NITS \/ REWORK/, 'the closed vocabulary is spelled in SKILL.md, not only in --help and failure stderr');
108
+ });
109
+ });
@@ -338,7 +338,7 @@ DEFAULT_AGY_REVIEW_MODEL="Gemini 3.7 Flash (High)"
338
338
  # Review-receipt identity (AD-038). AW_BRIDGE_VERSION mirrors this bridge's SKILL.md/capability.json
339
339
  # version (drift-guarded by agy-review.test.mjs against capability.json).
340
340
  AW_RECEIPT_BACKEND="agy"
341
- AW_BRIDGE_VERSION="5.3.0" # aw-version-anchor
341
+ AW_BRIDGE_VERSION="5.4.0" # aw-version-anchor
342
342
  # `-` not `:-` so an EXPLICIT empty AGY_MODEL= survives (drop --model, use settings.json — agy.sh:52).
343
343
  AGY_MODEL="${AGY_MODEL-$DEFAULT_AGY_REVIEW_MODEL}"
344
344
  # D5 control-byte screen — IMMEDIATELY after resolution, BEFORE the off-frontier advisory (or any
@@ -1070,6 +1070,14 @@ parse_agy_verdict() { # $1 = captured-output file
1070
1070
  fi
1071
1071
  }
1072
1072
 
1073
+ parse_agy_verdict_line() { # $1 = captured-output file
1074
+ awk '/^### Verdict[[:space:]]*$/{flag=1; next} flag && NF {print; exit}' "$1" 2>/dev/null
1075
+ }
1076
+
1077
+ parse_agy_blocking_first_numbered() { # $1 = captured-output file
1078
+ awk 'flag && /^### /{exit} /^### Blocking[[:space:]]*$/{flag=1; next} flag && /^[0-9]+[.)]/{print; exit}' "$1" 2>/dev/null
1079
+ }
1080
+
1073
1081
  # The repo file map is a FIXED cost that scales with REPO SIZE, not change size (measured 28,735
1074
1082
  # bytes in the home repo — 24% of agy's 120000-byte single-argv ceiling), so an unbounded map taxes
1075
1083
  # the change budget of every review. AW_REVIEW_MAP_BUDGET_BYTES bounds it; the value is set by each
@@ -2111,6 +2119,16 @@ if [[ $rc -eq 0 ]]; then
2111
2119
  echo " the review; if it recurs, inspect the captured output for what the model produced." >&2
2112
2120
  exit 4
2113
2121
  fi
2122
+ if [[ "$verdict" == "SHIP" || "$verdict" == "SHIP WITH NITS" ]]; then
2123
+ first_blocking_item="$(parse_agy_blocking_first_numbered "$review_out_file")"
2124
+ if [[ -n "$first_blocking_item" ]]; then
2125
+ verdict_line="$(parse_agy_verdict_line "$review_out_file")"
2126
+ echo "error: verdict-body contradiction — '### Verdict' reads '$verdict_line' while '### Blocking'" >&2
2127
+ echo " carries a numbered finding ($first_blocking_item). A ship-class verdict cannot" >&2
2128
+ echo " ride blocking findings; NO receipt was written. Re-run the review." >&2
2129
+ exit 4
2130
+ fi
2131
+ fi
2114
2132
  if [[ -n "$resume_mode" ]]; then
2115
2133
  # A continuation never re-embeds the current artifact (agy holds the ORIGINAL round server-side;
2116
2134
  # --facts is rejected above), so it cannot attest the folded tree: fresh:false, artifact /