Skip to content

Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA

TypeScript

Tests that copy their own bun no longer trip the review fetch check (GST-4112) (#4876)

Garry Tandfbdccf4c117
diff --git a/autoplan/bin/phase-publication-hook.ts b/autoplan/bin/phase-publication-hook.ts
index d09e8e6b5..e04b142bc 100644
--- a/autoplan/bin/phase-publication-hook.ts
+++ b/autoplan/bin/phase-publication-hook.ts
@@ -59,7 +59,7 @@ export const SCHEMA_STRIPPED: Record<string, readonly string[]> = { Agent: ['run
/** The reviewer dispatch input the guard accepts; snapshot manifests are unchanged by it. */
export const AGENT_KEYS: readonly string[] = ['prompt', 'description', 'subagent_type', 'run_in_background'];
/** The newest Claude Code release the pinned PTY runs and the schema canary have checked. */
-export const CHECKED_CLAUDE_CODE = '2.1.292';
+export const CHECKED_CLAUDE_CODE = '2.1.326';
/**
* Claude records the model's raw input in the journal but hands PreToolUse its
* schema-parsed form: file_path resolved (C:\x/y becomes C:\x\y) and keys the
diff --git a/bin/gstack-codex-probe b/bin/gstack-codex-probe
index c1e54a678..8866c9bdc 100755
--- a/bin/gstack-codex-probe
+++ b/bin/gstack-codex-probe
@@ -224,6 +224,21 @@ _gstack_codex_role_ready() {
return 0
}
+_gstack_codex_exclude_scratch() {
+ # Plan reviews write their Codex prompt in the working directory's .gstack/tmp/
+ # (#4851). Keep that folder out of git through git's own exclude path, which a
+ # linked worktree shares with its main checkout. Idempotent; a no-op outside
+ # git, without the folder, or when .gstack or .gstack/tmp is a symlink.
+ local _ex _ig
+ [ -d .gstack/tmp ] && [ ! -L .gstack ] && [ ! -L .gstack/tmp ] || return 0
+ _ex=$(git rev-parse --git-path info/exclude 2>/dev/null) && [ -n "$_ex" ] || return 0
+ _ig="/$(git rev-parse --show-prefix 2>/dev/null | sed 's/[][*?\\]/\\&/g').gstack/tmp/"
+ grep -qsxF "$_ig" "$_ex" && return 0
+ mkdir -p "${_ex%/*}" 2>/dev/null || return 0
+ { [ ! -s "$_ex" ] || [ -z "$(tail -c1 "$_ex")" ] || echo; printf '%s\n' "$_ig"; } >>"$_ex" 2>/dev/null
+ return 0
+}
+
# --- Sandbox (B1) -----------------------------------------------------------
_gstack_codex_sandbox_mode() {
@@ -1002,6 +1017,7 @@ _gstack_codex_main() {
return "$_rc" ;;
role-ready)
_gstack_codex_role_args ready "$@" || { _gstack_codex_usage >&2; return 64; }
+ _gstack_codex_exclude_scratch
_gstack_codex_role_ready "$_GSTACK_CODEX_ARG_KIND" "$_GSTACK_CODEX_ARG_CWD" "$_GSTACK_CODEX_ARG_MODEL" >&2
_rc=$?
[ "$_rc" -eq 0 ] || return "$_rc"
diff --git a/changelog.d/maintenance-sweep-runtime-copy-and-tmp-exclude.md b/changelog.d/maintenance-sweep-runtime-copy-and-tmp-exclude.md
new file mode 100644
index 000000000..3bc429640
--- /dev/null
+++ b/changelog.d/maintenance-sweep-runtime-copy-and-tmp-exclude.md
@@ -0,0 +1 @@
+**A test that copies its own `bun` binary no longer stops `/gstack-ship` with a fetch violation.** The review's fetch check now recognizes a new large file that is an exact copy of the Bun runtime it runs on (same size and SHA-256) and prints it as `FETCH_IGNORED: … reason=host-runtime`; a file named `bun` with any byte changed is still a fetch. Also: the Codex prompt files `/plan-ceo-review` and `/plan-eng-review` write in `.gstack/tmp/` are now kept out of git, from a subdirectory or a linked worktree too; the `/autoplan` guard treats Claude Code 2.1.326, the version CI runs, as checked, from a fresh capture of its hook payload; and `docs/skills.md` says `/review` always runs the Codex second-model review when Codex is ready and the Red Team on diffs over 200 lines.
diff --git a/docs/review-policy.md b/docs/review-policy.md
index 4733d254c..afd9c902c 100644
--- a/docs/review-policy.md
+++ b/docs/review-policy.md
@@ -853,6 +853,11 @@ The checkout's own build output is not a fetch either: a new big native executab
`FETCH_IGNORED: … reason=build-output`. A big file under an ignored directory or a
glob, a non-executable at that path, or a path only an uncommitted `.gitignore`
edit names still counts as a download.
+A copy of the runtime the sweep itself runs on (`process.execPath`, such as a test
+that copies its own `bun` into the temp dir) is not a fetch either: a new big file
+with exactly that binary's size and SHA-256 prints
+`FETCH_IGNORED: … reason=host-runtime`. A file named `bun` with any byte changed,
+added or removed, or a copy of any other binary, still counts as a download.
A `Bun.spawn` child given no `env` keeps the temp dir its test process started
with, so its fixtures land outside the marked root and still count.
diff --git a/docs/skills.md b/docs/skills.md
index 17025a79f..79ee17d74 100644
--- a/docs/skills.md
+++ b/docs/skills.md
@@ -10,7 +10,7 @@ Detailed guides for every gstack skill — philosophy, workflow, and examples.
| [`/plan-eng-review`](#plan-eng-review) | **Eng Manager** | Lock in architecture, data flow, diagrams, edge cases, and tests. Forces hidden assumptions into the open. |
| [`/plan-design-review`](#plan-design-review) | **Senior Designer** | Interactive plan-mode design review. Rates each dimension 0-10, explains what a 10 looks like, fixes the plan. Works in plan mode. |
| [`/design-consultation`](#design-consultation) | **Design Partner** | Build a complete design system from scratch. Knows the landscape, proposes creative risks, generates realistic product mockups. Design at the heart of all other phases. |
-| [`/review`](#review) | **Staff Engineer** | Looks for the bugs that pass CI but blow up in production. Auto-fixes the obvious ones. Flags completeness gaps. Advisory simplification lens flags over-built code — never blocks, never auto-applies. |
+| [`/review`](#review) | **Staff Engineer** | Looks for the bugs that pass CI but blow up in production. Auto-fixes the obvious ones. Flags completeness gaps. Advisory simplification lens flags over-built code — never blocks, never auto-applies. Always runs the Codex second-model review when Codex is ready (or its check is inconclusive), and the Red Team on every diff over 200 lines. |
| [`/build-check`](#build-check) | **Build Loop** | Run the repo's checks and the tests `/gstack-ship`'s pre-gate would pick for your change, fix, repeat until green, then hand off to `/gstack-ship`. Never green on an unmapped change. |
| [`/design-review`](#design-review) | **Designer Who Codes** | Live-site visual audit + fix loop. 80-item audit, then fixes what it finds. Atomic commits, before/after screenshots. |
| [`/design-shotgun`](#design-shotgun) | **Design Explorer** | Generate multiple AI design variants, open a comparison board in your browser, and iterate until you approve a direction. Taste memory biases toward your preferences. |
@@ -626,6 +626,10 @@ This is a structural audit, not a style nitpick pass. I want the model to look f
Findings get action, not just listed. Obvious mechanical fixes (dead code, stale comments, N+1 queries) are applied automatically — you see `[AUTO-FIXED] file:line Problem → what was done` for each one. Genuinely ambiguous issues (security, race conditions, design decisions) get surfaced for your call.
+### Second-model review and Red Team
+
+Standalone `/review` always runs a Codex second-model review when Codex is ready or its check is inconclusive, through `gstack-outside-voice`, and always runs the Red Team pass when the diff is over 200 lines (a smaller diff can still get one when a specialist finds something critical). The end-of-skill check refuses to finish without both. If Codex isn't installed or reviews are turned off, that is recorded as a skip and the review still finishes; a skip the model just claims in its own words does not count.
+
### Completeness gaps
`/review` now flags shortcut implementations where the complete version costs less than 30 minutes of CC time. If you chose the 80% solution and the 100% solution is a lake, not an ocean, the review will call it out.
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 144b9c4e8..eb0e4bf87 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -4253,8 +4253,9 @@ leave `merged.jsonl`, and it never reaches the Red Team, the judge, the
returned output or PR text. `verify` prints `FETCH_VIOLATION:` and refuses
until the stage has rerun and swept clean. A test run's fixtures (a root
carrying `.gstack-test-fixture`, or a repository whose remote resolves to a local
-path through `url.<base>.insteadOf`) and the checkout's own native build output at a
-path its committed root `.gitignore` names exactly print
+path through `url.<base>.insteadOf`), the checkout's own native build output at a
+path its committed root `.gitignore` names exactly, and a byte-identical copy
+(size and SHA-256) of the runtime the sweep runs on print
`FETCH_IGNORED:` and never count.
Capy's `~/.capy/drive` is never walked, and the drive sync database under
`~/.capy/drive-engine` (`state.db` and its `-wal`, `-shm` and `-journal` files)
diff --git a/lib/review-sweep.ts b/lib/review-sweep.ts
index 18318e37a..c1b914405 100644
--- a/lib/review-sweep.ts
+++ b/lib/review-sweep.ts
@@ -13,9 +13,11 @@
*
* Two kinds of new directory are not fetches and print FETCH_IGNORED instead (GST-1695): a test fixture root below a sweep
* root that carries FIXTURE_MARKER (test-setup.ts puts every test's temp paths under one), and a repository whose every
- * network remote resolves to a local path through url.<base>.insteadOf (the ship fixtures' fake GitHub origin).
+ * network remote resolves to a local path through url.<base>.insteadOf (the ship fixtures' fake GitHub origin). A new big file
+ * that is a byte-identical copy of the runtime running the sweep is not one either (FETCH_IGNORED host-runtime, GST-3959).
*/
import { spawnSync } from 'node:child_process';
+import { createHash } from 'node:crypto';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
@@ -34,7 +36,7 @@ const SCP = /^(?:[\w.-]+@)?[\w.-]+:(?!\/\/)[\w./-]+$/;
export interface Inventory { at: number; roots: string[]; repos: Record<string, string[]>; big: Record<string, number>; ignored?: Record<string, Omit<Ignored, 'path'>>; partial?: string }
export interface Found { path: string; kind: 'repo' | 'download'; remote?: string; bytes: number | null }
/** A new directory the sweep saw and did not count: a marked test fixture root, or a repository whose remote resolves locally. */
-export interface Ignored { path: string; reason: 'fixture-marker' | 'local-remote' | 'build-output'; remote?: string }
+export interface Ignored { path: string; reason: 'fixture-marker' | 'local-remote' | 'build-output' | 'host-runtime'; remote?: string }
export type SweepVerdict = 'clean' | 'violation' | 'partial';
export interface StageSweep {
attempt: number;
@@ -139,7 +141,17 @@ export function inventory(roots: readonly string[], checkout: string, skip: read
}
for (const d of list) {
const p = path.join(dir, d.name);
- if (d.isFile()) { if (ENGINE_DB.test(d.name) && dir.startsWith(engine)) continue; try { const s = fs.statSync(p); if (s.size >= BIG_BYTES) { if (buildOutput(home, p)) inv.ignored![p] = { reason: 'build-output' }; else inv.big[p] = s.size; } } catch { /* gone */ } continue; }
+ if (d.isFile()) {
+ if (ENGINE_DB.test(d.name) && dir.startsWith(engine)) continue;
+ try {
+ const s = fs.statSync(p);
+ if (s.size < BIG_BYTES) continue;
+ if (buildOutput(home, p)) inv.ignored![p] = { reason: 'build-output' };
+ else if (Date.now() <= deadline && hostRuntimeCopy(p, s.size)) inv.ignored![p] = { reason: 'host-runtime' };
+ else inv.big[p] = s.size;
+ } catch { /* gone */ }
+ continue;
+ }
if (d.isDirectory() && !SKIP.has(d.name) && depth < SWEEP_DEPTH) walk(p, depth + 1);
}
};
@@ -168,6 +180,27 @@ function buildOutput(checkout: string, file: string): boolean {
try { const fd = fs.openSync(file, 'r'); try { fs.readSync(fd, head, 0, 4, 0); } finally { fs.closeSync(fd); } } catch { return false; }
return NATIVE_MAGIC.some(m => m.every((b, i) => head[i] === b));
}
+function sha256File(file: string): string {
+ const hash = createHash('sha256'), buf = Buffer.alloc(1 << 20), fd = fs.openSync(file, 'r');
+ try { for (let n; (n = fs.readSync(fd, buf, 0, buf.length, null)) > 0;) hash.update(buf.subarray(0, n)); } finally { fs.closeSync(fd); }
+ return hash.digest('hex');
+}
+
+let hostRuntime: { exe: string; size: number; sha256?: string } | null | undefined;
+/**
+ * A copy of a binary already on the machine, not a fetch (GST-3959: gstack-evals#463's tests copy their own `bun` into /tmp):
+ * a file with exactly the size and SHA-256 of the runtime running this sweep (process.execPath, hashed at most once per process
+ * and only when a file of its size turns up). A name, a path, or any other binary never counts, and past the sweep's time budget
+ * no file is hashed, so it stays a download.
+ */
+function hostRuntimeCopy(file: string, size: number): boolean {
+ if (hostRuntime === undefined) {
+ try { const exe = fs.realpathSync(process.execPath); hostRuntime = { exe, size: fs.statSync(exe).size }; } catch { hostRuntime = null; }
+ }
+ if (!hostRuntime || size !== hostRuntime.size) return false;
+ try { hostRuntime.sha256 ??= sha256File(hostRuntime.exe); return sha256File(file) === hostRuntime.sha256; } catch { return false; }
+}
+
function du(p: string): number | null {
const r = spawnSync('du', ['-sk', p], { encoding: 'utf8', timeout: 10_000 });
const kb = Number(/^(\d+)/.exec(r.stdout ?? '')?.[1]);
@@ -226,7 +259,8 @@ export function foundLines(stage: Stage, attempt: number, found: readonly Found[
export function ignoredLines(stage: Stage, attempt: number, ignored: readonly Ignored[]): string[] {
return ignored.map(i => {
const remote = i.remote ? ` remote=${control(i.remote) ? JSON.stringify(i.remote) : i.remote}` : '';
- const why = i.reason === 'fixture-marker' ? `a test fixture root carrying ${FIXTURE_MARKER}` : i.reason === 'build-output' ? 'a native executable the checkout\'s committed .gitignore names exactly, which its own build writes' : 'its remote resolves to a local path through url.<base>.insteadOf';
+ const why = i.reason === 'fixture-marker' ? `a test fixture root carrying ${FIXTURE_MARKER}` : i.reason === 'build-output' ? 'a native executable the checkout\'s committed .gitignore names exactly, which its own build writes'
+ : i.reason === 'host-runtime' ? 'a byte-identical copy (size and SHA-256) of the runtime running this sweep, already on the machine' : 'its remote resolves to a local path through url.<base>.insteadOf';
return `FETCH_IGNORED: stage=${stage} attempt=${attempt} path=${shownPath(i.path)} reason=${i.reason}${remote} (${why}, so not a fetch; docs/review-policy.md#what-readers-may-fetch)`;
});
}
diff --git a/test/autoplan-guard-reasons.test.ts b/test/autoplan-guard-reasons.test.ts
index 6154d918f..a474cad05 100644
--- a/test/autoplan-guard-reasons.test.ts
+++ b/test/autoplan-guard-reasons.test.ts
@@ -21,9 +21,9 @@ describe('guard reason inventory', () => {
test('no denial advises a retry; transients say what to wait for; fallbacks print the runnable fallback', () => {
for (const [code, reason] of Object.entries(REASONS)) {
- const text = reasonText(code, sample, '2.1.292');
+ const text = reasonText(code, sample, '2.1.292'); // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' a sample version string for the reason text, not the checked pin
expect({ code, retry: /\bretry/i.test(text) }).toEqual({ code, retry: false });
- expect(text).toContain(`(code ${code}, Claude Code 2.1.292)`);
+ expect(text).toContain(`(code ${code}, Claude Code 2.1.292)`); // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' echoes the sample version passed in above
expect(text).toContain(`${GUIDE}#${anchor(code)}`);
if (reason.disposition === 'transient') expect(text).toMatch(/\bWait for\b/);
if (reason.disposition === 'fallback') expect(text).toContain(FALLBACK);
diff --git a/test/autoplan-publication-payload.test.ts b/test/autoplan-publication-payload.test.ts
index 6b8c93542..cc04f0e51 100644
--- a/test/autoplan-publication-payload.test.ts
+++ b/test/autoplan-publication-payload.test.ts
@@ -14,6 +14,7 @@ import { AGENT_KEYS, CHECKED_CLAUDE_CODE, evaluatePayloadPublication, nativeTool
import { readOwnedClaudePublicTranscript } from '../lib/claude-owned-journal';
import { nativePathSpelling } from '../lib/claude-public-transcript';
import captured from './fixtures/claude-agent-payload-2.1.292.json';
+import latest from './fixtures/claude-agent-payload-2.1.326.json';
import { OWNED_READ_APPROVAL } from '../autoplan/bin/owned-read';
const fixtures: GuardFixture[] = [];
@@ -21,7 +22,7 @@ afterEach(() => { for (const f of fixtures.splice(0)) f.cleanup(); });
const make = (...args: Parameters<typeof guardFixture>) => { const f = guardFixture(...args); fixtures.push(f); return f; };
const dispatch = (f: GuardFixture, extra: Record<string, unknown> = {}) =>
({ description: 'CEO review', subagent_type: 'general-purpose', prompt: f.snapshot.nativeDispatchPrompt, ...extra });
-/** The schema-parsed payload: what Claude Code 2.1.292 with the fork-subagent gate hands PreToolUse. */
+/** The schema-parsed payload: what Claude Code 2.1.292 with the fork-subagent gate hands PreToolUse. */ // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' names the release the original #3062 capture came from
const parsed = (input: Record<string, unknown>) => { const { run_in_background: _drop, ...rest } = input; return rest; };
describe('Cause A: the Agent schema strips run_in_background', () => {
@@ -32,7 +33,7 @@ describe('Cause A: the Agent schema strips run_in_background', () => {
f.use('review', 'Agent', raw); f.journal();
const output = await f.hook(f.input('review', 'Agent', parsed(raw)));
expect(output).toEqual({});
- expect(f.log().at(-1)).toMatchObject({ decision: 'allow', path: 'journal', claude_code_version: '2.1.292' });
+ expect(f.log().at(-1)).toMatchObject({ decision: 'allow', path: 'journal', claude_code_version: '2.1.292' }); // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' the fixture journal's default version, echoed into the log
});
test('journal-path negative controls stay denied: changed prompt, added model, changed description', async () => {
@@ -62,18 +63,37 @@ describe('Cause A: the Agent schema strips run_in_background', () => {
expect(JSON.stringify(f.log())).not.toContain('claude-opus-secret-value');
});
- test('the allowlist covers every Agent key Claude Code 2.1.292 hands PreToolUse', () => {
- for (const payload of captured.agentPayloads) for (const key of Object.keys(payload.tool_input)) expect(AGENT_KEYS).toContain(key);
- expect(CHECKED_CLAUDE_CODE).toBe(captured.claudeCodeVersion);
+ test('the allowlist covers every Agent key Claude Code 2.1.292 and 2.1.326 hand PreToolUse, and the checked release is the newest capture', () => { // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' names the older capture beside the checked one
+ for (const payload of [...captured.agentPayloads, ...latest.agentPayloads]) for (const key of Object.keys(payload.tool_input)) expect(AGENT_KEYS).toContain(key);
+ expect(CHECKED_CLAUDE_CODE).toBe(latest.claudeCodeVersion);
expect(nativeToolInput({ prompt: 'p', run_in_background: 'false' }, '/', 'Agent')).toEqual({ prompt: 'p' });
expect(nativeToolInput({ file_path: 'x', run_in_background: true }, '/', 'Read'))
.toEqual({ file_path: nativePathSpelling(path.resolve('/', 'x')), run_in_background: true });
});
+ // Value: protects=the guard on Claude Code 2.1.326 as captured (#4822 moved CI to it): its PreToolUse payload, with the new effort key beside the
+ // schema-parsed Agent input, passes for the forced run_in_background dispatch, and a strip of any other key is denied, not waved through as an
+ // unseen version; fails_when=the pin still reads 2.1.292, so every 2.1.326 strip is only a warning, or the new payload key breaks the hook; // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' describes the old pin this test guards against
+ // why_new=GST-4112 (#4822 follow-up); seam=runPublicationHook journal path; no_claim=interactive flush timing on 2.1.326
+ test('2.1.326 as captured: the forced dispatch passes the hook, and any other strip is denied', async () => {
+ const shape = Object.fromEntries(latest.payloadKeys.filter(key => !['session_id', 'transcript_path', 'cwd', 'hook_event_name', 'tool_name', 'tool_input', 'tool_use_id'].includes(key))
+ .map(key => [key, key === 'effort' ? { level: 'medium' } : key === 'permission_mode' ? 'default' : 'prompt-1']));
+ expect(Object.keys(shape).sort()).toEqual(['effort', 'permission_mode', 'prompt_id']);
+ const allowed = make('ceo', { version: '2.1.326' });
+ const raw = dispatch(allowed, { run_in_background: latest.forcedRunInBackground.journalInput.run_in_background });
+ allowed.use('review', 'Agent', raw); allowed.journal();
+ expect(await allowed.hook({ ...allowed.input('review', 'Agent', parsed(raw)), ...shape })).toEqual({});
+ expect(allowed.log().at(-1)).toMatchObject({ decision: 'allow', path: 'journal', claude_code_version: '2.1.326' });
+ const denied = make('ceo', { version: '2.1.326' });
+ const sent = dispatch(denied); denied.use('review', 'Agent', sent); denied.journal();
+ const { description: _gone, ...stripped } = sent;
+ expect(codeOf(await denied.hook({ ...denied.input('review', 'Agent', stripped), ...shape }))).toBe('current_mismatch');
+ });
+
test('UC1: a pure strip by a newer, unchecked Claude Code is unverified; the same strip on a checked version is denied', async () => {
- expect(newerThanChecked('2.1.300')).toBe(true);
+ expect(newerThanChecked('2.1.400')).toBe(true);
expect(newerThanChecked(CHECKED_CLAUDE_CODE)).toBe(false);
- for (const [version, expected] of [['2.1.300', 'unseen_version'], ['2.1.292', 'current_mismatch']] as const) {
+ for (const [version, expected] of [['2.1.400', 'unseen_version'], [CHECKED_CLAUDE_CODE, 'current_mismatch'], ['2.1.292', 'current_mismatch']] as const) { // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' an older known release, an input on purpose
const f = make('ceo', { version });
const raw = dispatch(f); f.use('review', 'Agent', raw); f.journal();
const { description: _gone, ...stripped } = raw;
@@ -82,7 +102,7 @@ describe('Cause A: the Agent schema strips run_in_background', () => {
if (expected === 'unseen_version') {
expect(output.hookSpecificOutput.permissionDecision).toBeUndefined();
expect(output.systemMessage).toContain('description');
- expect(f.log().at(-1)).toMatchObject({ decision: 'allow', disposition: 'unverified', code: 'unseen_version', claude_code_version: '2.1.300' });
+ expect(f.log().at(-1)).toMatchObject({ decision: 'allow', disposition: 'unverified', code: 'unseen_version', claude_code_version: '2.1.400' });
} else expect(denial(output)).toBeDefined();
}
});
@@ -152,7 +172,7 @@ describe('Publication flush: a report counts only once a later journaled record
test('ENG-2: the same publish-separately cause seen twice in one invocation switches to the fallback', async () => {
// The first report never reached the journal; after its denial the republished report is still the last record.
const f = make(); f.use('denied', 'Read', { file_path: section('design-phase.md') });
- f.result('denied', { isError: true, content: '[autoplan] The Phase 1 report ... (code publication_unflushed, Claude Code 2.1.292).' });
+ f.result('denied', { isError: true, content: '[autoplan] The Phase 1 report ... (code publication_unflushed, Claude Code 2.1.292).' }); // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' a recorded denial text from the older release
f.report(f.nextMessage()); f.journal();
const output = await f.hook(next(f));
expect(codeOf(output)).toBe('publication_repeat');
@@ -162,7 +182,7 @@ describe('Publication flush: a report counts only once a later journaled record
test('a denied call after the report proves the report was journaled, so the next attempt counts it', async () => {
const f = make(); const m = f.nextMessage(); f.report(m);
f.use('denied', 'Read', { file_path: section('design-phase.md') }, m);
- f.result('denied', { isError: true, content: '(code publication_unflushed, Claude Code 2.1.292)' }); f.journal();
+ f.result('denied', { isError: true, content: '(code publication_unflushed, Claude Code 2.1.292)' }); f.journal(); // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' a recorded denial text from the older release
expect(await f.hook(next(f))).toEqual(OWNED_READ_APPROVAL);
});
@@ -297,7 +317,7 @@ describe('Cause C: the hook runs before Claude Code flushes the turn it acts in
});
});
-test('the captured 2.1.292 evidence fixture records Cause A exactly', () => {
+test('the captured 2.1.292 evidence fixture records Cause A exactly', () => { // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' names the 2.1.292 evidence fixture
const forced = captured.forcedRunInBackground;
expect(forced.journalInput.run_in_background).toBe('false');
expect('run_in_background' in forced.payloadInput).toBe(false);
diff --git a/test/autoplan-schema-canary-compare.test.ts b/test/autoplan-schema-canary-compare.test.ts
index d07e5b913..4c673f1da 100644
--- a/test/autoplan-schema-canary-compare.test.ts
+++ b/test/autoplan-schema-canary-compare.test.ts
@@ -3,6 +3,7 @@ import { describe, expect, test } from 'bun:test';
import { schemaDrift, type HookPayload } from './helpers/schema-canary';
import { SCHEMA_STRIPPED, nativeToolInput } from '../autoplan/bin/phase-publication-hook.ts';
import captured from './fixtures/claude-agent-payload-2.1.292.json';
+import latest from './fixtures/claude-agent-payload-2.1.326.json';
const cwd = '/repo';
const read: HookPayload = { tool_name: 'Read', tool_use_id: 'toolu_read', cwd, tool_input: { file_path: '/repo/note.txt' } };
@@ -18,11 +19,16 @@ describe('autoplan-schema-canary comparison', () => {
expect(nativeToolInput(journalInput, cwd, 'Read')).not.toEqual(nativeToolInput(payloadInput, cwd, 'Read'));
});
- test('2.1.292 as captured: run_in_background stripped from the payload is the documented strip', () => {
+ test('2.1.292 as captured: run_in_background stripped from the payload is the documented strip', () => { // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' the older capture, kept beside the 2.1.326 one
const { payloadInput, journalInput } = captured.forcedRunInBackground;
expect(schemaDrift([read, agent(payloadInput)], journal(journalInput))).toEqual([]);
});
+ test('2.1.326 as captured: the same documented strip, and nothing else', () => {
+ const { payloadInput, journalInput } = latest.forcedRunInBackground;
+ expect(schemaDrift([read, agent(payloadInput)], journal(journalInput))).toEqual([]);
+ });
+
test('an injected strip of another key fails', () => {
const { payloadInput, journalInput } = captured.forcedRunInBackground;
const { description: _gone, ...stripped } = payloadInput;
diff --git a/test/fixtures/claude-agent-payload-2.1.326.json b/test/fixtures/claude-agent-payload-2.1.326.json
new file mode 100644
index 000000000..533974f61
--- /dev/null
+++ b/test/fixtures/claude-agent-payload-2.1.326.json
@@ -0,0 +1,65 @@
+{
+ "claudeCodeVersion": "2.1.326",
+ "captured": "2026-11-28, headless claude -p of the npm 2.1.326 linux-x64 binary (registry signatures verified, installed with --ignore-scripts), default permission mode, CLAUDE_CODE_FORK_SUBAGENT=1 as autoplan-schema-canary sets it, against a local scripted Messages API stub (no model call). The stub chose each tool call; Claude Code's own schema parse, PreToolUse payload and session journal are recorded as it wrote them. A PreToolUse hook recorded each payload and whether the journal held the call at hook entry.",
+ "payloadKeys": [
+ "session_id",
+ "transcript_path",
+ "cwd",
+ "prompt_id",
+ "permission_mode",
+ "effort",
+ "hook_event_name",
+ "tool_name",
+ "tool_input",
+ "tool_use_id"
+ ],
+ "agentSchemaProperties": [
+ "description",
+ "prompt",
+ "subagent_type",
+ "model",
+ "effort",
+ "isolation"
+ ],
+ "agentPayloads": [
+ {
+ "case": "lone dispatch, no run_in_background",
+ "tool_input": {
+ "description": "probe",
+ "prompt": "Reply with the single word OK.",
+ "subagent_type": "general-purpose"
+ }
+ },
+ {
+ "case": "forced run_in_background false",
+ "tool_input": {
+ "description": "probe2",
+ "prompt": "Reply with the single word OK.",
+ "subagent_type": "general-purpose"
+ }
+ }
+ ],
+ "forcedRunInBackground": {
+ "payloadInput": {
+ "description": "probe2",
+ "prompt": "Reply with the single word OK.",
+ "subagent_type": "general-purpose"
+ },
+ "journalInput": {
+ "description": "probe2",
+ "prompt": "Reply with the single word OK.",
+ "subagent_type": "general-purpose",
+ "run_in_background": "false"
+ }
+ },
+ "readPayload": {
+ "tool_input": {
+ "file_path": "<project>/note.txt",
+ "offset": 1,
+ "limit": 5
+ }
+ },
+ "journalAtHookEntry": {
+ "present": false
+ }
+}
diff --git a/test/helpers/autoplan-guard-fixture.ts b/test/helpers/autoplan-guard-fixture.ts
index 52abc1e97..41e21fe16 100644
--- a/test/helpers/autoplan-guard-fixture.ts
+++ b/test/helpers/autoplan-guard-fixture.ts
@@ -85,7 +85,7 @@ export function guardFixture(phase: Phase = 'ceo', opts: { methodologyLines?: nu
let parent: string | null = null, clock = Date.parse('2026-10-07T09:04:00Z');
const record = (type: string, message: Record_, extra: Record_ = {}) => {
const uuid = randomUUID(); const r = { uuid, parentUuid: parent, cwd, sessionId, isSidechain: false,
- version: opts.version ?? '2.1.292', timestamp: new Date(clock += 100).toISOString(), type, message, ...extra };
+ version: opts.version ?? '2.1.292', timestamp: new Date(clock += 100).toISOString(), type, message, ...extra }; // pregate-literal: CHECKED_CLAUDE_CODE='2.1.292' the journal's default version, an older checked release the guard must still judge normally
parent = uuid; return r;
};
const assistant = (messageId: string | undefined, content: unknown[], extra: Record_ = {}) =>
diff --git a/test/helpers/free-fixtures-data.ts b/test/helpers/free-fixtures-data.ts
index 0656e0ff1..3ea863500 100644
--- a/test/helpers/free-fixtures-data.ts
+++ b/test/helpers/free-fixtures-data.ts
@@ -56,6 +56,7 @@ export const FREE_FIXTURES: Readonly<Record<string, readonly string[]>> = {
'test/fixtures/ci-carry-rerun/**': ['test/ci-carry-rerun.test.ts'],
'test/fixtures/ci-gate/**': ['test/gstack-ci-gate.test.ts'],
'test/fixtures/claude-agent-payload-2.1.292.json': ['test/autoplan-publication-payload.test.ts', 'test/autoplan-schema-canary-compare.test.ts'],
+ 'test/fixtures/claude-agent-payload-2.1.326.json': ['test/autoplan-publication-payload.test.ts', 'test/autoplan-schema-canary-compare.test.ts'],
'test/fixtures/claude-native-journal-roots-2.1.284.json': ['test/autoplan-publication-hook.test.ts', 'test/plan-count-transcript.test.ts'],
'test/fixtures/codex-boundary-commands.json': ['test/codex-boundary-evidence.test.ts'],
'test/fixtures/codex-host/**': ['test/codex-host.test.ts'],
diff --git a/test/outside-prompt-file.test.ts b/test/outside-prompt-file.test.ts
index eee5e30f9..161122fe2 100644
--- a/test/outside-prompt-file.test.ts
+++ b/test/outside-prompt-file.test.ts
@@ -104,3 +104,65 @@ describe.skipIf(process.platform === 'win32')('plan-review prompt file lives in
});
}
});
+
+// Value: protects=the plan-review prompt file #4851 writes under .gstack/tmp/ is git-excluded by the Codex helper its own block runs
+// (gstack-codex-probe role-ready), wherever the session runs: the repository root, a subdirectory, and a linked worktree (whose exclude file
+// is the main checkout's), with each exclude line written once and an exclude file missing its final newline kept intact; outside git it does
+// nothing; fails_when=a leftover prompt shows in git status and can be committed; why_new=#4851 follow-up (GST-4112);
+// seam=the generated create command and gstack-codex-probe role-ready; no_claim=a .gitignore negation that overrides info/exclude
+describe.skipIf(process.platform === 'win32')('plan-review prompt file is git-excluded (#4851 follow-up)', () => {
+ const stub = path.join(scratch, 'stub-bin');
+ fs.mkdirSync(stub, { recursive: true });
+ fs.writeFileSync(path.join(stub, 'codex'), '#!/bin/sh\nexit 1\n', { mode: 0o755 });
+ const home = path.join(scratch, 'probe-home');
+ fs.mkdirSync(home, { recursive: true });
+ const env = { ...process.env, PATH: stub + path.delimiter + process.env.PATH, _TEL: 'off', HOME: home, GSTACK_HOME: path.join(home, '.gstack'), GSTACK_STATE_ROOT: path.join(home, '.gstack') };
+ const status = (cwd: string) => git(cwd, 'status', '--porcelain', '--untracked-files=all');
+ const session = (create: string, cwd: string) => {
+ const made = spawnSync('bash', ['-c', create], { cwd, env, encoding: 'utf8', timeout: 30_000 });
+ expect(made.status, made.stderr).toBe(0);
+ const prompt = made.stdout.trim();
+ expect(path.dirname(prompt)).toBe(path.join(cwd, '.gstack', 'tmp'));
+ fs.writeFileSync(prompt, 'review this plan');
+ spawnSync(path.join(ROOT, 'bin', 'gstack-codex-probe'), ['role-ready', 'exec'], { cwd, env, encoding: 'utf8', timeout: 30_000 });
+ };
+ for (const skill of ['plan-ceo-review', 'plan-eng-review']) {
+ test(skill, () => {
+ const text = fs.readFileSync(path.join(ROOT, skill, 'sections', 'review-sections.md'), 'utf8');
+ const at = text.indexOf('gstack-plan-prompt');
+ const create = [...text.matchAll(/`([^`\n]+)`/g)].map(m => m[1]).filter(s => s.includes('gstack-plan-prompt'))[0]!;
+ expect(text.slice(at, text.indexOf('\n```\n', text.indexOf('```bash', at)))).toContain(' role-ready exec');
+ const base = path.join(scratch, `excluded-${skill}`);
+ const main = path.join(base, 'main');
+ fs.mkdirSync(path.join(main, 'sub', 'dir'), { recursive: true });
+ git(main, 'init', '-q');
+ git(main, '-c', 'user.name=t', '-c', '[email protected]', 'commit', '-q', '--allow-empty', '-m', 'base');
+ const excludeFile = path.join(main, '.git', 'info', 'exclude');
+ fs.writeFileSync(excludeFile, '*.log');
+ const lines = () => fs.readFileSync(excludeFile, 'utf8').split('\n');
+ session(create, main); session(create, main);
+ expect(status(main)).toBe('');
+ expect(lines().filter(l => l === '/.gstack/tmp/')).toHaveLength(1);
+ expect(lines()).toContain('*.log');
+
+ session(create, path.join(main, 'sub', 'dir'));
+ expect(status(main)).toBe('');
+ expect(lines().filter(l => l === '/sub/dir/.gstack/tmp/')).toHaveLength(1);
+
+ fs.mkdirSync(path.join(main, 'pkg[1]', 'a*b'), { recursive: true });
+ session(create, path.join(main, 'pkg[1]', 'a*b'));
+ expect(status(main)).toBe('');
+ expect(lines()).toContain('/pkg\\[1\\]/a\\*b/.gstack/tmp/');
+
+ git(main, 'worktree', 'add', '-q', path.join(base, 'wt'));
+ session(create, path.join(base, 'wt')); session(create, path.join(base, 'wt'));
+ expect(status(path.join(base, 'wt'))).toBe('');
+ expect(lines().filter(l => l === '/.gstack/tmp/')).toHaveLength(1);
+
+ const plain = path.join(base, 'not-a-repo');
+ fs.mkdirSync(plain);
+ session(create, plain);
+ expect(fs.existsSync(path.join(plain, '.git'))).toBe(false);
+ });
+ }
+});
diff --git a/test/review-sweep.test.ts b/test/review-sweep.test.ts
index 813453bf2..203e6a3c8 100644
--- a/test/review-sweep.test.ts
+++ b/test/review-sweep.test.ts
@@ -140,6 +140,30 @@ describe('review-sweep inventory diff', () => {
expect(later.ignored ?? []).toEqual([]);
});
+ // Value: protects=a byte-identical copy of the runtime running the sweep (process.execPath; gstack-evals#463 copies its own bun to /tmp/hm-hold-*/.bun/bin/bun)
+ // is printed as FETCH_IGNORED host-runtime, not a download; fails_when=a test that copies the host's bun stops /ship with FETCH_VIOLATION and FETCH_RERUN_BLOCKED,
+ // or the exemption lets through a binary named bun whose bytes differ (one flipped byte, one appended byte) or a copy swapped for other bytes later;
+ // why_new=GST-3959; seam=inventory; no_claim=a copy of any other runtime, an older bun or a runtime whose own path was rewritten during the stage
+ test.skipIf(fs.statSync(process.execPath).size < BIG_BYTES)('a byte-identical copy of the host runtime is ignored; a modified binary named bun is still a download', async () => {
+ const root = tmp();
+ const checkout = path.join(root, 'checkout');
+ repoAt(checkout);
+ const start = inventory([root], checkout, []);
+ await Bun.sleep(30);
+ const bun = (hold: string) => { const p = path.join(root, hold, '.bun', 'bin', 'bun'); fs.mkdirSync(path.dirname(p), { recursive: true }); fs.copyFileSync(process.execPath, p); return p; };
+ const copy = bun('hm-hold-a'), flipped = bun('hm-hold-b'), grown = bun('hm-hold-c');
+ const fd = fs.openSync(flipped, 'r+');
+ try { const b = Buffer.alloc(1); fs.readSync(fd, b, 0, 1, BIG_BYTES - 1); b[0] = b[0]! ^ 0xff; fs.writeSync(fd, b, 0, 1, BIG_BYTES - 1); } finally { fs.closeSync(fd); }
+ fs.appendFileSync(grown, Buffer.from([0]));
+ const r = sweepResult(start, inventory([root], checkout, []));
+ expect(r.found.map(f => [f.path, f.kind]).sort()).toEqual([[flipped, 'download'], [grown, 'download']].sort());
+ expect(r.ignored).toEqual([{ path: copy, reason: 'host-runtime' }]);
+ expect(ignoredLines('specialists', 1, r.ignored!)[0]).toContain('reason=host-runtime');
+ const mid = inventory([root], checkout, []);
+ fs.rmSync(copy); fs.writeFileSync(copy, ''); fs.truncateSync(copy, BIG_BYTES);
+ expect(sweepResult(mid, inventory([root], checkout, [])).found.map(f => f.path)).toEqual([copy]);
+ });
+
// Value: protects=a build output already on disk when a stage starts is never counted, as on main where it sat in start.big;
// fails_when=an uncommitted .gitignore edit or a git timeout at the end walk moves it from ignored to big and the stage is voided as FETCH_VIOLATION;
// why_new=ship-4672 p1/red-team#1; seam=sweepDiff; no_claim=files the stage itself wrote
@@ -340,4 +364,25 @@ describe('review-sweep and Capy platform state (GST-3359)', () => {
]);
expect(out).toContain('FETCH_SWEEP: violation stage=specialists attempt=1 found=3');
});
+
+ // Value: protects=through the registered sweep command, a stage during which a test copies the runtime the command runs on into the temp dir sweeps clean
+ // with a FETCH_IGNORED host-runtime line, while the same copy with one appended byte is still a violation; fails_when=gstack-evals#463's hold test
+ // (GST-3959) stops /ship again, or the exemption reaches a binary that is not byte-identical; seam=gstack-review-dispatch sweep --phase start/end;
+ // no_claim=a copy of a runtime other than the one the sweep command runs on
+ test.skipIf(fs.statSync(process.execPath).size < BIG_BYTES)('a copy of the runtime the sweep runs on is not a download; the same copy with one more byte is', () => {
+ const { dir, env } = repo();
+ made.push(dir);
+ const real = fs.realpathSync(dir);
+ const h = home(real);
+ const runEnv = { ...env, HOME: h, GSTACK_SWEEP_ROOTS: real };
+ const exe = spawnSync('bash', ['-c', 'exec bun --no-env-file --config=/dev/null -e "process.stdout.write(process.execPath)"'], { cwd: real, env: runEnv, encoding: 'utf8', timeout: 30_000 }).stdout;
+ expect(fs.statSync(exe).size).toBeGreaterThanOrEqual(BIG_BYTES);
+ const copy = (hold: string) => { const p = path.join(real, hold, '.bun', 'bin', 'bun'); fs.mkdirSync(path.dirname(p), { recursive: true }); fs.copyFileSync(exe, p); return p; };
+ const clean = sweepStage(real, runEnv, () => copy('hm-hold-a'));
+ expect(clean).toContain('FETCH_SWEEP: clean stage=specialists attempt=1 found=0');
+ expect(clean).toContain(`FETCH_IGNORED: stage=specialists attempt=1 path='${path.join(real, 'hm-hold-a', '.bun', 'bin', 'bun')}' reason=host-runtime`);
+ const dirty = sweepStage(real, runEnv, () => fs.appendFileSync(copy('hm-hold-b'), Buffer.from([0])));
+ expect(dirty).toContain(`kind=download path='${path.join(real, 'hm-hold-b', '.bun', 'bin', 'bun')}'`);
+ expect(dirty).toContain('FETCH_SWEEP: violation stage=specialists attempt=1 found=1');
+ });
});