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
/codex cleanup stops asking for /careful approval, and plan-mode Codex reviews start again (#4851)
Garry Tanbe64b102975a
diff --git a/changelog.d/fix-codex-prompt-cleanup-plan-mode-prompt-file.md b/changelog.d/fix-codex-prompt-cleanup-plan-mode-prompt-file.mdnew file mode 100644index 000000000..9406916cb--- /dev/null+++ b/changelog.d/fix-codex-prompt-cleanup-plan-mode-prompt-file.md@@ -0,0 +1,6 @@+---+important: regression+---+**`/codex challenge` and `/codex consult` no longer stop for a /careful delete warning at the end of every run.** Their cleanup deleted the prompt file through a variable the safety check could not resolve, so it asked every time; the cleanup now uses a guarded variable the check accepts. Thanks @dmfrede (#4841).++- **The Codex second-model review in `/plan-eng-review` and `/plan-ceo-review` works in Claude Code plan mode again.** The prompt file was created under `$TMPDIR`, where plan mode refuses Write, so Codex never started. It is now created in the project's `.gstack/tmp/` (never through a symlinked `.gstack` folder) and deleted with a plain `rm` of that one path. Thanks @mcp10 (#4842).diff --git a/codex/sections/challenge-mode.md b/codex/sections/challenge-mode.mdindex 4aa34b6b2..e0256727a 100644--- a/codex/sections/challenge-mode.md+++ b/codex/sections/challenge-mode.md@@ -113,7 +113,7 @@ if grep -qiE "auth|login|unauthorized" "$TMPERR" 2>/dev/null; then"$_CODEX_PROBE" log-event codex_auth_failedfibun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex challenge' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"-rm -f "$TMPRESP" "$TMPRESP.events" "$PROMPT_FILE"+rm -f "$TMPRESP" "$TMPRESP.events" "${PROMPT_FILE:?}"````VERDICT: unavailable` means the challenge did not run (its line names why, such as adiff --git a/codex/sections/challenge-mode.md.tmpl b/codex/sections/challenge-mode.md.tmplindex 7f5ac30ae..039cb9841 100644--- a/codex/sections/challenge-mode.md.tmpl+++ b/codex/sections/challenge-mode.md.tmpl@@ -99,7 +99,7 @@ if grep -qiE "auth|login|unauthorized" "$TMPERR" 2>/dev/null; then"$_CODEX_PROBE" log-event codex_auth_failedfibun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex challenge' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"-rm -f "$TMPRESP" "$TMPRESP.events" "$PROMPT_FILE"+rm -f "$TMPRESP" "$TMPRESP.events" "${PROMPT_FILE:?}"````VERDICT: unavailable` means the challenge did not run (its line names why, such as adiff --git a/codex/sections/consult-mode.md b/codex/sections/consult-mode.mdindex 2b616a41e..8367232c9 100644--- a/codex/sections/consult-mode.md+++ b/codex/sections/consult-mode.md@@ -173,7 +173,7 @@ elif [ "$_CODEX_EXIT" != "0" ]; then"$_CODEX_PROBE" log-event codex_nonzero_exit "$_LABEL:$_CODEX_EXIT"fibun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex consult' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"-rm -f "$PROMPT_FILE"+rm -f "${PROMPT_FILE:?}"````VERDICT: unavailable` means Codex did not answer from a workingdiff --git a/codex/sections/consult-mode.md.tmpl b/codex/sections/consult-mode.md.tmplindex d51562fdb..dff18854e 100644--- a/codex/sections/consult-mode.md.tmpl+++ b/codex/sections/consult-mode.md.tmpl@@ -159,7 +159,7 @@ elif [ "$_CODEX_EXIT" != "0" ]; then"$_CODEX_PROBE" log-event codex_nonzero_exit "$_LABEL:$_CODEX_EXIT"fibun --no-env-file --config=/dev/null ~/.claude/skills/gstack/lib/outside-review-result.ts --label 'Codex consult' --exit "$_CODEX_EXIT" --stderr "$TMPERR" --events "$TMPRESP.events" execution "$TMPRESP"-rm -f "$PROMPT_FILE"+rm -f "${PROMPT_FILE:?}"````VERDICT: unavailable` means Codex did not answer from a workingdiff --git a/plan-ceo-review/sections/review-sections.md b/plan-ceo-review/sections/review-sections.mdindex 6f9c07406..3155f4634 100644--- a/plan-ceo-review/sections/review-sections.md+++ b/plan-ceo-review/sections/review-sections.md@@ -451,12 +451,12 @@ THE PLAN:**If `CODEX_MODE: ready` — run Codex:**-Run this block for `ready`, in the one foreground Bash call described below.+Run this block for `ready`, in the one foreground Bash call.Its opening harness guard rechecks the fresh shell: exit 78 uses the same Nativefallback below, never a replacement provider. Finish termination before fallback and consume only-completed output. Use private temporary paths, with no background jobs.+completed output. No background jobs.-Create a private prompt file: run `umask 077; mktemp "${TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"` in Bash and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in that file. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.+Create a private prompt file: run `[ ! -L .gstack -a ! -L .gstack/tmp ] && mkdir -p -m700 .gstack/tmp && mktemp "$PWD/.gstack/tmp/gstack-plan-prompt.XXXXXX"` and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in it. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.```bash# GSTACK_ACTIVE_HOST names the harness, never the model.@@ -495,7 +495,7 @@ esacecho 'OUTSIDE_STATUS: completed provider=codex host=claude'```-Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, delete only your private prompt; scratch cleanup is automatic.+Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, run `rm -- '<prepared-prompt-file>'`; scratch cleanup is automatic.Present the full output verbatim:diff --git a/plan-eng-review/sections/review-sections.md b/plan-eng-review/sections/review-sections.mdindex f42d59a71..cee0f4f8c 100644--- a/plan-eng-review/sections/review-sections.md+++ b/plan-eng-review/sections/review-sections.md@@ -966,12 +966,12 @@ THE PLAN:**If `CODEX_MODE: ready` — run Codex:**-Run this block for `ready`, in the one foreground Bash call described below.+Run this block for `ready`, in the one foreground Bash call.Its opening harness guard rechecks the fresh shell: exit 78 uses the same Nativefallback below, never a replacement provider. Finish termination before fallback and consume only-completed output. Use private temporary paths, with no background jobs.+completed output. No background jobs.-Create a private prompt file: run `umask 077; mktemp "${TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"` in Bash and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in that file. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.+Create a private prompt file: run `[ ! -L .gstack -a ! -L .gstack/tmp ] && mkdir -p -m700 .gstack/tmp && mktemp "$PWD/.gstack/tmp/gstack-plan-prompt.XXXXXX"` and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in it. Substitute its shell-quoted path for `<prepared-prompt-file>`; never interpolate user text into shell source. Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.```bash# GSTACK_ACTIVE_HOST names the harness, never the model.@@ -1010,7 +1010,7 @@ esacecho 'OUTSIDE_STATUS: completed provider=codex host=claude'```-Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, delete only your private prompt; scratch cleanup is automatic.+Use Bash `timeout: 360000`; show the full response in a `tool-output` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing Recommendation: <action> because <reason> markers, timeout or CLI failure means `outside_status: unavailable`. P0/P1 findings block like native ones; `OUTSIDE_STATUS: unverified` is missing coverage. Use the caller's fallback; missing coverage is never clean/PASS. After either outcome, run `rm -- '<prepared-prompt-file>'`; scratch cleanup is automatic.Present the full output verbatim:diff --git a/scripts/resolvers/outside-voice-steps.ts b/scripts/resolvers/outside-voice-steps.tsindex 303abb854..819860dcd 100644--- a/scripts/resolvers/outside-voice-steps.ts+++ b/scripts/resolvers/outside-voice-steps.ts@@ -416,10 +416,10 @@ function codexPlanReviewRun(ctx: TemplateContext, ceo: boolean, needsApprovalRea// (gates 40477638211 and 40454750574: every judge sample read "(or unverified)" as a branch nothing can enter).return `**If \`CODEX_MODE: ready\` — run ${outsideVoiceFor(ctx).label}:**-${['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName) ? `Run this block for \`ready\`, in the one foreground Bash call described below.+${['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName) ? `Run this block for \`ready\`, in the one foreground Bash call.Its opening harness guard rechecks the fresh shell: exit 78 uses the same Nativefallback below, never a replacement provider. Finish termination before fallback and consume only-completed output. Use private temporary paths, with no background jobs.` : `Run the selected backend in the one foreground Bash invocation described below.+completed output. No background jobs.` : `Run the selected backend in the one foreground Bash invocation described below.Finish a failed attempt's termination before fallback; consume only its completedoutput. No background jobs or shared temporary paths.`}diff --git a/scripts/resolvers/outside-voice.ts b/scripts/resolvers/outside-voice.tsindex 15ca39e28..e95b56541 100644--- a/scripts/resolvers/outside-voice.ts+++ b/scripts/resolvers/outside-voice.ts@@ -177,8 +177,9 @@ export function outsideVoiceInvocation(ctx: TemplateContext, requested: OutsideC: planRecommendation? "Request severity (Critical, High, Medium or Low) per finding and the prompt's Recommendation and VERDICT lines.": `Request severity (Critical, High, Medium or Low) per finding, a Recommendation: <action> because <reason> line, and ${VERDICT_LAST_LINE}.`;- const preparation = `${['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName)- ? 'Create a private prompt file: run `umask 077; mktemp "${TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"` in Bash and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in that file'+ const planPrompt = ['plan-ceo-review', 'plan-eng-review'].includes(ctx.skillName);+ const preparation = `${planPrompt+ ? 'Create a private prompt file: run `[ ! -L .gstack -a ! -L .gstack/tmp ] && mkdir -p -m700 .gstack/tmp && mktemp "$PWD/.gstack/tmp/gstack-plan-prompt.XXXXXX"` and keep the returned path. Use Write to put the **complete prompt and context**, including actual plan/spec/source, in it': 'Write the **complete prompt and context**, including actual plan/spec/source, to a private file'}${outsideVoiceFor(ctx).id === 'claude-code' ? ' (Claude Code has no tools, git or path access)' : ''}. Substitute its shell-quoted path for \`<prepared-prompt-file>\`; never interpolate user text into shell source. ${completion}`;return `${preparation}@@ -186,7 +187,7 @@ export function outsideVoiceInvocation(ctx: TemplateContext, requested: OutsideC${outsideVoiceCommand(ctx, opts)}\`\`\`-Use Bash \`timeout: ${gateMs}\`; show the full response in a \`tool-output\` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing ${planRecommendation ? 'Recommendation: <action> because <reason>' : opts.purpose === 'design-direction' ? 'Recommendation' : 'score/severity/completion'} markers, timeout or CLI failure means \`outside_status: unavailable\`. P0/P1 findings block like native ones; \`OUTSIDE_STATUS: unverified\` is missing coverage. ${opts.purpose === 'design-direction' ? 'Continue completed proposals; native completion does not count as outside coverage.' : opts.nativeAlreadyRequired === 'dispatched' ? 'A dispatched native pass runs once either way; outside output cannot complete it.' : opts.nativeAlreadyRequired ? 'Retain the required native pass without duplicating it; it cannot complete outside coverage.' : "Use the caller's fallback; missing coverage is never clean/PASS."} After either outcome, delete only your private prompt; scratch cleanup is automatic.`;+Use Bash \`timeout: ${gateMs}\`; show the full response in a \`tool-output\` fence. Require successful execution and valid markers. Refusal, empty/malformed output, missing ${planRecommendation ? 'Recommendation: <action> because <reason>' : opts.purpose === 'design-direction' ? 'Recommendation' : 'score/severity/completion'} markers, timeout or CLI failure means \`outside_status: unavailable\`. P0/P1 findings block like native ones; \`OUTSIDE_STATUS: unverified\` is missing coverage. ${opts.purpose === 'design-direction' ? 'Continue completed proposals; native completion does not count as outside coverage.' : opts.nativeAlreadyRequired === 'dispatched' ? 'A dispatched native pass runs once either way; outside output cannot complete it.' : opts.nativeAlreadyRequired ? 'Retain the required native pass without duplicating it; it cannot complete outside coverage.' : "Use the caller's fallback; missing coverage is never clean/PASS."} After either outcome, ${planPrompt ? "run `rm -- '<prepared-prompt-file>'`" : 'delete only your private prompt'}; scratch cleanup is automatic.`;}/**diff --git a/test/autoplan-dual-voice-fixture.test.ts b/test/autoplan-dual-voice-fixture.test.tsindex 980b871bc..8e018f198 100644--- a/test/autoplan-dual-voice-fixture.test.ts+++ b/test/autoplan-dual-voice-fixture.test.ts@@ -5,6 +5,10 @@ import * as path from 'node:path';import { spawnSync } from 'node:child_process';const ROOT = path.resolve(import.meta.dir, '..');+// The plan skills' own prompt-file command (#4842): it creates the prompt in the project's .gstack/tmp/.+const PROMPT_CREATE = [...fs.readFileSync(path.join(ROOT, 'plan-ceo-review/sections/review-sections.md'), 'utf8')+ .matchAll(/`([^`\n]+)`/g)].map(m => m[1]).filter(s => s.includes('gstack-plan-prompt'));+if (PROMPT_CREATE.length !== 1) throw Error('expected one plan prompt-file command, found ' + PROMPT_CREATE.length);const ORIGINAL_PLAN = `# Test Plan: add /greet skill## Context@@ -175,13 +179,13 @@ mock.module(${JSON.stringify(path.join(ROOT, 'test/helpers/session-runner.ts'))}if (scenario === 'temp' || scenario === 'temp-retry') {const {hermeticChildEnv, getHermeticDirs} = await import(${JSON.stringify(path.join(ROOT, 'test/helpers/hermetic-env.ts'))});// Same final environment merge as session-runner. The original cf74- // command created its file in inherited shard TMPDIR, beside both roots.+ // command created its file in inherited shard TMPDIR, beside both roots;+ // the generated command now creates it inside the project (#4842).const env = hermeticChildEnv({GSTACK_HEADLESS: '1', ...opts.env});const defaults = getHermeticDirs();const cleanupFiles = [];try {- const command = 'umask 077; mktemp "$' + '{TMPDIR:-/tmp}/gstack-plan-prompt.XXXXXXXX"';- const made = spawnSync('bash', ['-c', command], {cwd, env, encoding: 'utf8', timeout: 5000});+ const made = spawnSync('bash', ['-c', ${JSON.stringify(PROMPT_CREATE[0])}], {cwd, env, encoding: 'utf8', timeout: 5000});if (made.error || made.status !== 0) throw Error('Actual prompt mktemp failed: ' + made.stderr);const prompt = made.stdout.trim();const freeRoot = fs.realpathSync(${JSON.stringify(directory)});@@ -277,7 +281,7 @@ await import(${JSON.stringify(path.join(ROOT, 'test/skill-e2e-autoplan-dual-voicconst temp = attempt.temp;const expected = path.join(attempt.env.HOME, 'tmp');expect(temp.env).toEqual({TMPDIR: expected, TEMP: expected, TMP: expected});- expect(path.dirname(temp.prompt)).toBe(expected);+ expect(path.dirname(temp.prompt)).toBe(path.join(attempt.cwd, '.gstack', 'tmp'));expect(temp.directoryMode).toBe(0o700);expect(temp.promptMode).toBe(0o600);expect(temp.owned.claudeVoiceFired).toBe(true);diff --git a/test/fixtures/skill-md-size-allowlist.json b/test/fixtures/skill-md-size-allowlist.jsonindex c9623d2e9..cb5d8fb67 100644--- a/test/fixtures/skill-md-size-allowlist.json+++ b/test/fixtures/skill-md-size-allowlist.json@@ -5,53 +5,53 @@"agy/gstack-autoplan": 109163,"agy/gstack-plan-design-review": 109100,"agy/gstack-plan-devex-review": 115130,- "agy/gstack-plan-eng-review": 143744,+ "agy/gstack-plan-eng-review": 143742,"agy/gstack-review": 104939,"codex/gstack-autoplan": 107431,"codex/gstack-plan-design-review": 110375,"codex/gstack-plan-devex-review": 114416,- "codex/gstack-plan-eng-review": 142687,+ "codex/gstack-plan-eng-review": 142685,"codex/gstack-review": 104273,"copilot/gstack-autoplan": 108606,"copilot/gstack-plan-design-review": 109366,"copilot/gstack-plan-devex-review": 114592,- "copilot/gstack-plan-eng-review": 143909,+ "copilot/gstack-plan-eng-review": 143907,"copilot/gstack-review": 104520,"cursor/gstack-autoplan": 107838,"cursor/gstack-plan-design-review": 107908,"cursor/gstack-plan-devex-review": 113862,- "cursor/gstack-plan-eng-review": 142499,+ "cursor/gstack-plan-eng-review": 142497,"cursor/gstack-review": 122992,"factory/gstack-autoplan": 110116,"factory/gstack-plan-design-review": 111006,"factory/gstack-plan-devex-review": 117225,- "factory/gstack-plan-eng-review": 145607,+ "factory/gstack-plan-eng-review": 145605,"factory/gstack-review": 126765,"gbrain/gstack-autoplan": 108245,"gbrain/gstack-plan-eng-review": 125054,"gemini/gstack-autoplan": 108396,"gemini/gstack-plan-design-review": 109194,"gemini/gstack-plan-devex-review": 114420,- "gemini/gstack-plan-eng-review": 143742,+ "gemini/gstack-plan-eng-review": 143740,"gemini/gstack-review": 104342,"hermes/gstack-autoplan": 108250,"hermes/gstack-plan-eng-review": 125007,"kiro/gstack-autoplan": 107612,"kiro/gstack-plan-design-review": 107754,"kiro/gstack-plan-devex-review": 113714,- "kiro/gstack-plan-eng-review": 142361,+ "kiro/gstack-plan-eng-review": 142359,"kiro/gstack-review": 122816,"openclaw/gstack-autoplan": 108068,"openclaw/gstack-plan-eng-review": 123553,"opencode/gstack-autoplan": 108587,"opencode/gstack-plan-design-review": 109222,"opencode/gstack-plan-devex-review": 114470,- "opencode/gstack-plan-eng-review": 143768,+ "opencode/gstack-plan-eng-review": 143766,"opencode/gstack-review": 123614,"slate/gstack-autoplan": 107725,"slate/gstack-plan-design-review": 107831,"slate/gstack-plan-devex-review": 113788,- "slate/gstack-plan-eng-review": 142430,+ "slate/gstack-plan-eng-review": 142428,"slate/gstack-review": 122904}}diff --git a/test/outside-prompt-file.test.ts b/test/outside-prompt-file.test.tsnew file mode 100644index 000000000..eee5e30f9--- /dev/null+++ b/test/outside-prompt-file.test.ts@@ -0,0 +1,106 @@+/**+ * Private prompt files for second-model reviews stay inside the project and clean up without a careful ask.+ *+ * #4841: /codex challenge and consult deleted their prompt with rm -f "$PROMPT_FILE". The assignment above it+ * holds a $, so careful/bin/check-careful.sh cannot resolve it and asks about a delete "through a variable that+ * may be empty" on every run. The cleanup now reads "${PROMPT_FILE:?}", which careful treats as guarded.+ *+ * #4842: /plan-ceo-review and /plan-eng-review created the prompt with mktemp under $TMPDIR, outside the project.+ * Claude Code's plan mode refuses a Write there, so Codex never started. The prompt now goes in the session folder's+ * .gstack/tmp/ (refusing a symlinked .gstack or .gstack/tmp), and its cleanup removes that one path without an ask.+ */+import { afterAll, describe, expect, test } from 'bun:test';+import { spawnSync } from 'child_process';+import * as fs from 'fs';+import * as os from 'os';+import * as path from 'path';+import { usePrivateStateRoot } from './helpers/private-state-root';++const ROOT = path.resolve(import.meta.dir, '..');+const CHECK = path.join(ROOT, 'careful', 'bin', 'check-careful.sh');+const scratch = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-prompt-file-')));+usePrivateStateRoot();+afterAll(() => fs.rmSync(scratch, { recursive: true, force: true }));++function bashFences(file: string): string[] {+ const text = fs.readFileSync(path.join(ROOT, file), 'utf8');+ return [...text.matchAll(/^```bash\n([\s\S]*?)\n```$/gm)].map(m => m[1]);+}++function careful(command: string, cwd: string): string {+ const r = spawnSync('bash', [CHECK], {+ cwd, encoding: 'utf8', timeout: 30_000,+ input: JSON.stringify({ tool_name: 'Bash', tool_input: { command } }),+ env: { ...process.env, GSTACK_HOOK_CWD: cwd },+ });+ expect(r.status, r.stderr).toBe(0);+ return r.stdout.trim();+}++function git(cwd: string, ...args: string[]): string {+ const r = spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 30_000 });+ expect(r.status, r.stderr).toBe(0);+ return r.stdout;+}++describe.skipIf(process.platform === 'win32')('/codex prompt cleanup passes careful (#4841)', () => {+ for (const file of ['codex/sections/challenge-mode.md', 'codex/sections/consult-mode.md']) {+ test(file, () => {+ const block = bashFences(file).find(b => /^PROMPT_FILE=/m.test(b) && /^rm -f .*PROMPT_FILE/m.test(b));+ expect(block).toBeDefined();+ const lines = block!.split('\n');+ const cleanup = lines.find(l => /^rm -f .*PROMPT_FILE/.test(l))!;+ const names = new Set([...cleanup.matchAll(/\$\{?([A-Z_]+)/g)].map(m => m[1]));+ const assignments = lines.filter(l => names.has(l.split('=')[0]));+ expect(assignments.some(l => l.startsWith('PROMPT_FILE='))).toBe(true);+ expect(careful([...assignments, cleanup].join('\n'), scratch)).toBe('{}');+ expect(cleanup).toContain('"${PROMPT_FILE:?}"');+ expect(careful(block!, scratch)).toBe('{}');+ });+ }+});++describe.skipIf(process.platform === 'win32')('plan-review prompt file lives in the project (#4842)', () => {+ 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 spans = [...text.matchAll(/`([^`\n]+)`/g)].map(m => m[1]);+ const create = spans.filter(s => s.includes('gstack-plan-prompt'));+ expect(create).toHaveLength(1);+ expect(create[0]).not.toContain('TMPDIR');+ const cleanup = spans.filter(s => s.startsWith('rm ') && s.includes('<prepared-prompt-file>'));+ expect(cleanup).toEqual(["rm -- '<prepared-prompt-file>'"]);++ const project = path.join(scratch, skill);+ fs.mkdirSync(project);+ git(project, 'init', '-q');+ const made = spawnSync('bash', ['-c', create[0]], { cwd: project, encoding: 'utf8', timeout: 30_000 });+ expect(made.status, made.stderr).toBe(0);+ const prompt = made.stdout.trim();+ expect(path.dirname(prompt)).toBe(path.join(project, '.gstack', 'tmp'));+ expect(path.basename(prompt).startsWith('gstack-plan-prompt.')).toBe(true);+ expect(fs.statSync(prompt).mode & 0o777).toBe(0o600);+ expect(fs.statSync(path.dirname(prompt)).mode & 0o777).toBe(0o700);+ fs.writeFileSync(prompt, 'review this plan');++ const remove = cleanup[0].replace('<prepared-prompt-file>', prompt);+ expect(careful(remove, project)).toBe('{}');+ const removed = spawnSync('bash', ['-c', remove], { cwd: project, encoding: 'utf8', timeout: 30_000 });+ expect(removed.status, removed.stderr).toBe(0);+ expect(fs.existsSync(prompt)).toBe(false);++ // A cloned repo can commit .gstack or .gstack/tmp as a symlink; the prompt must never land where it points.+ for (const link of ['.gstack', '.gstack/tmp']) {+ const linked = path.join(scratch, skill + '-link-' + link.replace(/\W/g, ''));+ const outside = path.join(linked, 'outside');+ fs.mkdirSync(outside, { recursive: true });+ fs.mkdirSync(path.join(linked, 'repo', path.dirname(link)), { recursive: true });+ fs.symlinkSync(outside, path.join(linked, 'repo', link));+ const refused = spawnSync('bash', ['-c', create[0]], { cwd: path.join(linked, 'repo'), encoding: 'utf8', timeout: 30_000 });+ expect(refused.status, link).not.toBe(0);+ expect(refused.stdout.trim(), link).toBe('');+ expect(fs.readdirSync(outside), link).toEqual([]);+ }+ });+ }+});