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
Stop false phone-number holds on /ship run ids and name interactive /autoplan runs (#4747)
Garry Tan0d6cc1be5613
diff --git a/autoplan/SKILL.md b/autoplan/SKILL.mdindex b20173b01..be18e58eb 100644--- a/autoplan/SKILL.md+++ b/autoplan/SKILL.md@@ -428,7 +428,7 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '/' '-')DATETIME=$(date +%Y%m%d-%H%M%S)echo "SLUG=$SLUG"echo "RESTORE_PATH=$_AP/${BRANCH}-autoplan-restore-${DATETIME}.md"-echo "RUN_ID=${BRANCH}-${DATETIME}"; ~/.claude/skills/gstack/bin/gstack-autoplan-timing estimate --run "${BRANCH}-${DATETIME}" --out "$_AP"+_ID=${BRANCH}-autoplan-$DATETIME; echo "RUN_ID=$_ID"; ~/.claude/skills/gstack/bin/gstack-autoplan-timing estimate --run "$_ID" --out "$_AP"```Before scope/review:diff --git a/autoplan/SKILL.md.tmpl b/autoplan/SKILL.md.tmplindex 0491359ae..5379bd499 100644--- a/autoplan/SKILL.md.tmpl+++ b/autoplan/SKILL.md.tmpl@@ -202,7 +202,7 @@ BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '/' '-')DATETIME=$(date +%Y%m%d-%H%M%S)echo "SLUG=$SLUG"echo "RESTORE_PATH=$_AP/${BRANCH}-autoplan-restore-${DATETIME}.md"-echo "RUN_ID=${BRANCH}-${DATETIME}"; ~/.claude/skills/gstack/bin/gstack-autoplan-timing estimate --run "${BRANCH}-${DATETIME}" --out "$_AP"+_ID=${BRANCH}-autoplan-$DATETIME; echo "RUN_ID=$_ID"; ~/.claude/skills/gstack/bin/gstack-autoplan-timing estimate --run "$_ID" --out "$_AP"```Before scope/review:diff --git a/changelog.d/privacy-check-skips-run-ids.md b/changelog.d/privacy-check-skips-run-ids.mdnew file mode 100644index 000000000..c7352c211--- /dev/null+++ b/changelog.d/privacy-check-skips-run-ids.md@@ -0,0 +1,6 @@+---+important: blocker+---+**Posting a PR body that lists earlier /ship runs no longer stops for a phone number that isn't there.** `gstack-post` read the run id on each line of the `gstack-receipt-runs` block (`4242424-1700000000-deadbeef`) as a phone number, so every /ship that rewrote a PR body with earlier runs waited for a confirmation. The run id on a well-formed line of that block is now skipped for that check; a phone number anywhere else, including elsewhere on the same line, is still caught. About 1 in 10 run ids also reads as a card number and still asks; a follow-up fixes that. Reported by @dgrant (#4725), fix idea from @thomsjack (#4729).++**`gstack-approvals import --autoplan` records an interactive /autoplan run under its own run id.** Without a `run.json`, every interactive run was imported as `autoplan`, so the run id could not be cited and separate runs shared one gate state. A `Plan: approved:` line naming the run's folder resolves the same way while the folder holds one run; once it holds several, cite the run id instead. Approvals imported before this change under `autoplan` need importing again. New interactive run ids put `autoplan` between the branch name and the time stamp, so a branch name ending in digits no longer turns the id into something the privacy check reads as a phone or card number. Reported by @exGeni (#4402).diff --git a/docs/troubleshooting.md b/docs/troubleshooting.mdindex e0ac1bfe5..aecf0e6ad 100644--- a/docs/troubleshooting.md+++ b/docs/troubleshooting.md@@ -2304,10 +2304,12 @@ ruling after the run stops.uses). The line names the field and the detector rule, never the matched text. Exit 3.Nothing was written, locally or to the Drive mirror. `import --autoplan` skips a`pii.phone.e164` or `pii.cc` finding that starts inside the autoplan run id's-14-digit stamp, or the thread-code digits right before it, where import places+time stamp, or the thread-code digits right before it, where import placesthe id (the ask's `autoplan run <id>` and the source's `autoplan:<id>@`), whenthe id has the minted shape `<name>-<14 digits>` (GST-2047; since GST-3015 the-name ends in six random letters); a phone number in+name ends in six random letters) or the shape interactive /autoplan minted+before #4402, `<branch>-YYYYMMDD-HHMMSS` with a real calendar date and time;+a phone number inthe rest of the directory name, the same id anywhere else, and every otherfinding in the row still refuse.Likewise a `pii.phone.e164` finding that starts inside the `stop=` run id of a@@ -2430,8 +2432,10 @@ under `## Approvals`. A PR whose only changes are changelog fragments needs no l**Meaning.** `Plan: approved: <token>` names no approval row on this machine. A run id mustmatch a row source `autoplan:<id>@gate_rev=<n>` in any branch's file of the repository's-approval store (the state root plus every Drive mirror); a row id must exist and be a plan-approval, not a `ruled_note`, `review_loop_grant` or `test_lane_exception` row. A public+approval store (the state root plus every Drive mirror); a run folder path resolves to the+run id in its `run.json`, else, for an interactive /autoplan folder with no `run.json`, to the+one run its `decisions.jsonl` records (a folder holding several runs resolves to none, so cite+the run id instead); a row id must exist and be a plan approval, not a `ruled_note`, `review_loop_grant` or `test_lane_exception` row. A publicrepo's `Plan: approved (record r-<id>)` must hash from a row id this machine can read; when itis the redacted Approvals block's own id (a hash of a whole record), the message says so.@@ -3333,6 +3337,15 @@ exact tokens it finds in these positions:`1234567-1794900000-0a1b2c3d`), and the 12-hex shas in the `pregate` value(`@<tree> (<n> checks, current for <head>)`) and the `requires_remote`values (`heads=`, `tree=`) (#4480);+- in a closed `gstack-receipt-runs` block (the earlier /ship runs listed+ under the receipt) that opens outside any other fenced code block, the+ top-level `run` value of a line whose JSON matches its `JSON.stringify`+ rendering byte for byte, with a 40-hex `head` and a `run` shaped like that+ session id (#4725). A phone number in another field of the same line, a+ `run` of any other shape, a session id under another key, a spaced or+ reordered line, and a block inside another fence or left open still+ report. Only `pii.phone.e164` is skipped there: a session id that also+ reads as a card number still asks;- on a line outside any fenced code block that opens with `SHIP_RECEIPT:`,`CI_CARRY:`, `PREGATE:` or `READY_RECEIPT:` (bare, after `- `, `* ` or`> `, or after a backtick), thediff --git a/lib/approval-record.ts b/lib/approval-record.tsindex 4b002d84f..ccda80af4 100644--- a/lib/approval-record.ts+++ b/lib/approval-record.ts@@ -186,10 +186,14 @@ function validDate(d: string): boolean {export interface NewRow { ask: string; words: string; by: string; scope: string; pending?: string; outcome?: string; date?: string; source?: string }-/** An autoplan run id as gstack-autoplan mints it: the run directory's name, a hyphen, six random letters (since GST-3015), a hyphen, then a 14-digit time stamp. */-const MINTED_RUN_ID = /^[A-Za-z0-9._-]{1,64}-\d{14}$/;-/** The part of a minted run id the exemption covers: the 14-digit stamp and, when the name ends in a thread code, its digits. */-const RUN_ID_STAMP = /(?:(?<!\d)\d{1,6}-)?\d{14}$/;+/**+ * An autoplan run id as gstack-autoplan mints it: the run directory's name, a hyphen, six random letters (since GST-3015), a hyphen, then a+ * 14-digit time stamp; or as interactive /autoplan minted it before #4402: the branch name, a hyphen, then a YYYYMMDD-HHMMSS stamp that is+ * a real calendar time.+ */+const MINTED_RUN_ID = /^[A-Za-z0-9._-]{1,64}-(?:\d{14}|\d{4}(?:0[1-9]|1[0-2])(?:0[1-9]|[12]\d|3[01])-(?:[01]\d|2[0-3])[0-5]\d[0-5]\d)$/;+/** The part of a minted run id the exemption covers: the stamp and, when the name ends in a thread code or issue number, its digits. */+const RUN_ID_STAMP = /(?:(?<!\d)\d{1,6}-)?(?:\d{14}|\d{8}-\d{6})$/;/*** A fix-check round grant's scope as gstack-approvals round-grant writes it (lib/review-round-grant.ts): its stop= token is the@@ -389,11 +393,21 @@ export function approvalsGrantStopSpans(text: string): Array<{ line: number; froreturn spans;}-interface DecisionLike { id?: string; title?: string; status?: string; chosen?: string | null; recommended?: string | null; gate_rev?: number; answered_at?: string; answered_by?: string; reply?: string; owner_reply?: string; answer_words?: string; words_by?: string; carried_from?: string; label?: string; chosen_text?: string;+interface DecisionLike { id?: string; run?: string; title?: string; status?: string; chosen?: string | null; recommended?: string | null; gate_rev?: number; answered_at?: string; answered_by?: string; reply?: string; owner_reply?: string; answer_words?: string; words_by?: string; carried_from?: string; label?: string; chosen_text?: string;carried_gate_from?: string; carried_gate_rev?: number; carried_answered_by?: string; carried_under?: string; carry_check?: string }const stripRef = (t: string) => t.replace(/\s*\[[^\]]*\]\s*$/, '').trim();+/**+ * The run id an autoplan run directory answers to: run.json's, else the newest run its gate rows carry (an interactive+ * /autoplan writes no run.json and appends every run to the same directory, #4402), else the directory name.+ */+export function autoplanRunId(runDir: string, run: Record<string, any>, rows: readonly { run?: unknown }[]): string {+ if (run.run ?? run.id) return String(run.run ?? run.id);+ const newest = [...rows].reverse().find(r => typeof r.run === 'string' && r.run.length > 0)?.run;+ return typeof newest === 'string' ? newest : path.basename(runDir);+}+/*** Rows for every answered gate in an autoplan run: one row per answer event (gate_rev, time, answerer), covering* the items it settled. Item answers carried from an earlier revision were recorded when first given and are skipped;@@ -417,8 +431,9 @@ export function importAutoplan(runDir: string, branch: string, by?: string): Appconst plan = reviewedPlan(runDir, run);const planTitle = firstTitle(plan.text) ?? 'the plan';const planSha = plan.sha;- const runId = String(run.run ?? run.id ?? path.basename(runDir));- const answered = rows.filter(r => r.status && r.status !== 'pending' && r.answered_at && !r.carried_from);+ const runId = autoplanRunId(runDir, run, rows);+ const own = (run.run ?? run.id) || !rows.some(r => r.run === runId) ? rows : rows.filter(r => r.run === runId);+ const answered = own.filter(r => r.status && r.status !== 'pending' && r.answered_at && !r.carried_from);if (!answered.length) return { code: 'APPROVAL_IMPORT_UNANSWERED', message: `no answered gate in ${runDir}` };const groups = new Map<string, DecisionLike[]>();for (const r of answered) {@@ -433,7 +448,7 @@ export function importAutoplan(runDir: string, branch: string, by?: string): Appconst outcome: Outcome = !p1 ? 'pending' : p1.chosen === 'a' || p1.chosen === 'b' ? 'approved' : p1.chosen === 'e' ? 'rejected' : 'pending';const items = group.filter(r => r !== p1);const changed = items.filter(r => r.chosen && r.recommended && r.chosen !== r.recommended);- const stillPending = rows.filter(r => r.gate_rev === rev && r.status === 'pending');+ const stillPending = own.filter(r => r.gate_rev === rev && r.status === 'pending');const answerer = first.answered_by ?? 'unknown';const carried = p1?.carried_gate_from ? p1 : undefined;const relayed = carried?.carried_answered_by && carried.carried_answered_by !== 'human' ? `, relayed by ${carried.carried_answered_by}` : '';diff --git a/lib/gstack-post.ts b/lib/gstack-post.tsindex bc6eda8f1..990060d8b 100644--- a/lib/gstack-post.ts+++ b/lib/gstack-post.ts@@ -577,7 +577,9 @@ const lineIdSpans = (text: string, line: number): Span[] => RECEIPT_LINE_IDS.fla* span of each value below. In every closed ```gstack-ship-receipt``` block whose JSON passes the receipt schema and is byte-identical to* renderReceiptBlock's rendering of it: each ci_carried[].run, flaky_exception[].runs[] and issues.flakes[].run value that is a run id (11 to 20* digits, with an optional /attempt), the run value when it is a gstack-skill-start session id, and the RECEIPT_LINE_IDS values inside the- * pregate and requires_remote[] values. On every line outside a fenced code block that opens with a receipt-line prefix (RECEIPT_LINE), its RECEIPT_LINE_IDS values. Only+ * pregate and requires_remote[] values. In every closed ```gstack-receipt-runs``` block that opens outside any other fence (gstack#4725), the top-level run value of each line that is a+ * JSON object byte-identical to its JSON.stringify rendering, with a 40-hex head and a run that is a gstack-skill-start session id. On every line+ * outside a fenced code block that opens with a receipt-line prefix (RECEIPT_LINE), its RECEIPT_LINE_IDS values. Only* those writers' own output qualifies, so a hand-written, schema-invalid, malformed or unclosed block exempts nothing, and the same number in* prose, in any other code block (a receipt-prefixed line inside one included), on a line without a receipt prefix or under any other key still reports.*/@@ -585,10 +587,11 @@ function receiptIdSpans(text: string): Span[] {const lines = text.split("\n");const rows = (v: unknown): number => v !== null && typeof v === "object" && Object.keys(v).length ? 2 + Object.values(v).reduce((n: number, c) => n + rows(c), 0) : 1;let fence = "";+ const blocks: Array<{ open: number; close: number }> = [];const spans: Span[] = lines.flatMap((l, i) => {const f = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(l);- if (f && !fence) { fence = f[1]!; return []; }- if (f && f[1]![0] === fence[0] && f[1]!.length >= fence.length && !f[2]!.trim()) { fence = ""; return []; }+ if (f && !fence) { fence = f[1]!; blocks.push({ open: i, close: -1 }); return []; }+ if (f && f[1]![0] === fence[0] && f[1]!.length >= fence.length && !f[2]!.trim()) { fence = ""; blocks.at(-1)!.close = i; return []; }return !fence && RECEIPT_LINE.test(l) ? lineIdSpans(l, i + 1) : [];});for (let open = 0; open < lines.length; open++) {@@ -626,6 +629,17 @@ function receiptIdSpans(text: string): Span[] {receipt.issues?.flakes?.forEach((_, i) => span(["issues", "flakes", i, "run"]));open = close;}+ for (const { open, close } of blocks) {+ if (close < 0 || lines[open] !== "```" + RUNS_FENCE) continue;+ for (let i = open + 1; i < close; i++) {+ let entry: Record<string, unknown>;+ try { entry = JSON.parse(lines[i]!); if (entry === null || typeof entry !== "object" || Array.isArray(entry) || JSON.stringify(entry) !== lines[i]) continue; } catch { continue; }+ if (typeof entry.head !== "string" || !/^[0-9a-f]{40}$/.test(entry.head) || typeof entry.run !== "string" || !SESSION_ID.test(entry.run)) continue;+ const before = Object.keys(entry).slice(0, Object.keys(entry).indexOf("run"));+ const from = JSON.stringify(Object.fromEntries(before.map(k => [k, entry[k]]))).length + (before.length ? 1 : 0) + '"run":'.length;+ spans.push({ line: i + 1, from, to: from + JSON.stringify(entry.run).length - 1 });+ }+ }return spans;}diff --git a/lib/plan-record.ts b/lib/plan-record.tsindex 7169ff2f0..1d93c3759 100644--- a/lib/plan-record.ts+++ b/lib/plan-record.ts@@ -147,7 +147,14 @@ const rowSha = (r: ApprovalRow) => createHash('sha256').update(JSON.stringify(r)function runIdFor(token: string, cwd: string): string {const dir = path.resolve(cwd, token.replace(/^~(?=\/)/, process.env.HOME ?? '~'));if (!token.includes('/')) return token;- try { return String(JSON.parse(fs.readFileSync(path.join(dir, 'run.json'), 'utf8')).run ?? path.basename(dir)); } catch { return path.basename(dir); }+ let run: Record<string, any> = {};+ try { run = JSON.parse(fs.readFileSync(path.join(dir, 'run.json'), 'utf8')); } catch {}+ if (run.run ?? run.id) return String(run.run ?? run.id);+ const file = path.join(dir, 'decisions.jsonl');+ if (!fs.existsSync(file)) return path.basename(dir);+ let runs: Set<string>;+ try { runs = new Set(fs.readFileSync(file, 'utf8').split('\n').filter(l => l.trim()).map(l => JSON.parse(l)?.run).filter((r): r is string => typeof r === 'string' && !!r)); } catch { return ''; }+ return runs.size === 1 ? [...runs][0]! : runs.size ? '' : path.basename(dir);}/** Resolve a Plan line against the approval store; `changedOnly` lists the PR's changed paths for the changelog-only exemption. */diff --git a/test/approval-record.test.ts b/test/approval-record.test.tsindex 701d273b2..e733fc54f 100644--- a/test/approval-record.test.ts+++ b/test/approval-record.test.ts@@ -389,6 +389,105 @@ describe('import --autoplan', () => {expect(typed.status).not.toBe(0);});+ // Value: protects=a run id interactive /autoplan minted before #4402 (<branch>-<YYYYMMDD-HHMMSS>) imports on a branch whose name ends in+ // digits, as the 14-digit minted shape does (GST-2047), while a phone number in the same row, a run id of another shape, a phone number+ // in the name half of the id, or the same id typed into add --ask still refuses; fails_when=an approval answered before the upgrade cannot+ // be imported after it, or the exemption reaches past the stamp; why_new=the GST-2047 test covers only the 14-digit stamp; seam=none+ test('an interactive run id minted before #4402 imports on a numbered branch; a phone number elsewhere still refuses', () => {+ const importWith = (o: { runId: string; words?: string }) => {+ const run = tmp('appr-run-');+ autoplanRun(run, [{ by: 'agent:GSTA-36', words: o.words ?? 'do it', at: '2026-11-22T09:40:00.000Z', p1: 'a' }]);+ fs.writeFileSync(path.join(run, 'run.json'), JSON.stringify({ run: o.runId, status: 'complete' }));+ return importAutoplan(run, 'b', 'Garry');+ };+ for (const runId of ['fix-4402-20261122-093321', 'gsta-802-20261122-093321', 'fix-12-20261122-093321']) {+ const rows = importWith({ runId });+ expect([runId, 'code' in rows ? rows.message : rows[0]!.source]).toEqual([runId, `autoplan:${runId}@gate_rev=1`]);+ }+ const refused: Array<[{ runId: string; words?: string }, string]> = [+ [{ runId: 'fix-4402-20261122-093321', words: 'do it, call 14155552671 if it breaks' }, 'words'],+ [{ runId: 'fix-4402-20261122-0933' }, 'ask'],+ [{ runId: 'fix-4402-20261399-093321' }, 'ask'],+ [{ runId: 'fix-4402-20261122-993321' }, 'ask'],+ [{ runId: 'call-415-555-2671-20261122-093321' }, 'ask'],+ [{ runId: '14155552671-20261122-093321' }, 'source'],+ ];+ for (const [o, field] of refused) {+ const r = importWith(o);+ expect([o, 'code' in r && r.code, 'code' in r && r.message.startsWith(`field ${field}: `) && r.message.includes('pii.phone.e164')]).toEqual([o, 'APPROVAL_RECORD_SECRET', true]);+ }+ const typed = bin(['add', '--ask', 'Approve the plan (autoplan run fix-4402-20261122-093321, 2 decisions)', '--words', 'do it', '--by', 'Garry', '--scope', 'the plan'], { cwd: repo(), env: { GSTACK_STATE_ROOT: tmp('appr-state-') } });+ expect(typed.status).not.toBe(0);+ expect(typed.out + typed.err).toContain('field ask: pii');+ });++ // Value: protects=an interactive /autoplan run (no run.json; its gate rows carry the run id) imports under that run id,+ // so the id can be cited and two interactive runs never share one gate state; fails_when=the import falls back to the+ // shared directory name "autoplan"; why_new=every answered-gate import case wrote run.json (#4402); seam=none+ test('an interactive run without run.json imports under the run id its gate rows carry', () => {+ const run = path.join(tmp('appr-run-'), 'autoplan');+ fs.mkdirSync(run);+ const id = 'feature-x-20261122-104500';+ fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: id, id: `${id}-p1`, label: 'P1', title: 'Plan approval',+ options: ['a', 'b'], recommended: 'a', kind: 'approval', status: 'approved', gate_rev: 1, chosen: 'a', answered_at: '2026-11-22T10:50:00.000Z', reply: 'a' }) + '\n');+ const rows = importAutoplan(run, 'b', 'owner');+ if ('code' in rows) throw new Error(rows.message);+ expect(rows.map(r => r.source)).toEqual([`autoplan:${id}@gate_rev=1`]);+ expect(rows[0]!.ask).toContain(`autoplan run ${id}`);+ });++ // Value: protects=a second interactive run appended to the same autoplan directory imports under its own run id with only+ // its own answers; fails_when=mixed run ids fall back to the directory name and pool both runs' answers; why_new=the+ // interactive case held a single run; seam=none+ test('a second interactive run appended to the same directory imports under its own run id', () => {+ const run = path.join(tmp('appr-run-'), 'autoplan');+ fs.mkdirSync(run);+ const row = (id: string, at: string) => JSON.stringify({ schema_version: 1, run: id, id: `${id}-p1`, label: 'P1', title: 'Plan approval',+ options: ['a', 'b'], recommended: 'a', kind: 'approval', status: 'approved', gate_rev: 1, chosen: 'a', answered_at: at, reply: 'a' }) + '\n';+ const a = 'feature-x-20261122-104500', b = 'feature-y-20261122-114500';+ fs.writeFileSync(path.join(run, 'decisions.jsonl'), row(a, '2026-11-22T10:50:00.000Z'));+ const first = importAutoplan(run, 'b', 'owner');+ if ('code' in first) throw new Error(first.message);+ expect(first.map(r => r.source)).toEqual([`autoplan:${a}@gate_rev=1`]);+ fs.appendFileSync(path.join(run, 'decisions.jsonl'), row(b, '2026-11-22T11:50:00.000Z'));+ const second = importAutoplan(run, 'b', 'owner');+ if ('code' in second) throw new Error(second.message);+ expect(second.map(r => r.source)).toEqual([`autoplan:${b}@gate_rev=1`]);+ });++ // Value: protects=an abandoned older interactive run's pending rows do not mark a newer approved run as unanswered;+ // fails_when=stillPending counts pending rows from every run in the directory; why_new=the newest-run selection+ // left the pending count pooled; seam=none+ test('an abandoned older run leaves no unanswered decisions on the newer approved run', () => {+ const run = path.join(tmp('appr-run-'), 'autoplan');+ fs.mkdirSync(run);+ const a = 'feature-x-20261122-104500', b = 'feature-y-20261122-114500';+ fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: a, id: `${a}-d1`, label: 'D1', title: 'Abandoned decision', status: 'pending', gate_rev: 1 }) + '\n'+ + JSON.stringify({ schema_version: 1, run: b, id: `${b}-p1`, label: 'P1', title: 'Plan approval', options: ['a', 'b'], recommended: 'a', kind: 'approval',+ status: 'approved', gate_rev: 1, chosen: 'a', answered_at: '2026-11-22T11:50:00.000Z', reply: 'a' }) + '\n');+ const rows = importAutoplan(run, 'b', 'owner');+ if ('code' in rows) throw new Error(rows.message);+ expect(rows.map(r => [r.source, r.outcome, r.pending])).toEqual([[`autoplan:${b}@gate_rev=1`, 'approved', 'none']]);+ });++ // Value: protects=the run id interactive /autoplan mints (autoplan/SKILL.md.tmpl's RUN_ID line) imports on a branch whose name ends in+ // digits; fails_when=the id puts those digits straight before the date stamp, which pii.phone.e164 and pii.cc read as a phone or card+ // number, so the import is refused (#4402); why_new=the interactive cases above use branch names without digits; seam=none+ test('the run id interactive /autoplan mints on a numbered branch imports', () => {+ const tmpl = fs.readFileSync(path.join(ROOT, 'autoplan', 'SKILL.md.tmpl'), 'utf8');+ const stamp = /^DATETIME=\$\(date \+([^)]+)\)$/m.exec(tmpl)![1]!.replace(/%([YmdHMS])/g, (_, c: string) => ({ Y: '2026', m: '11', d: '22', H: '09', M: '33', S: '21' } as Record<string, string>)[c]!);+ const minted = (/^_ID=([^;\s]+);/m.exec(tmpl) ?? /^echo "RUN_ID=([^"]+)"/m.exec(tmpl))![1]!.replace(/\$\{?BRANCH\}?/, '<branch>').replace(/\$\{?DATETIME\}?/, stamp);+ const run = path.join(tmp('appr-run-'), 'autoplan');+ fs.mkdirSync(run);+ for (const branch of ['fix-4402', 'gsta-802', '4402']) {+ const id = minted.replace('<branch>', branch);+ fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: id, id: `${id}-p1`, label: 'P1', title: 'Plan approval',+ options: ['a', 'b'], recommended: 'a', kind: 'approval', status: 'approved', gate_rev: 1, chosen: 'a', answered_at: '2026-11-22T10:50:00.000Z', reply: 'a' }) + '\n');+ const rows = importAutoplan(run, 'b', 'owner');+ expect([branch, 'code' in rows ? rows.message : rows.map(r => r.source)]).toEqual([branch, [`autoplan:${id}@gate_rev=1`]]);+ }+ });+test('an unanswered gate imports nothing and says why', () => {const run = tmp('appr-run-');fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ schema_version: 1, run: 'run-1', id: 'run-1-p1', label: 'P1', status: 'pending', gate_rev: 1 }) + '\n');diff --git a/test/gstack-post.test.ts b/test/gstack-post.test.tsindex 43c138a2d..aee0d360d 100644--- a/test/gstack-post.test.ts+++ b/test/gstack-post.test.ts@@ -413,6 +413,53 @@ describe("gstack-post owns the redaction scan", () => {}});+ // Value: protects=a gstack-receipt-runs block's session ids (/ship's earlier runs) post through pr-comment and pr-body without a pii.phone.e164+ // confirmation (gstack#4725), while a phone number in another field of the same line, a phone number, a truncated id or a session id under+ // another key, a non-canonical line, a line whose head is missing or not a 40-hex sha, an unclosed block and the same id in prose still need+ // one; fails_when=every /ship that rewrites a PR body holding earlier runs gets a false MEDIUM hold, or the exemption reaches past the exact+ // run value of a canonical runs line; why_new=the #4480 test covers only the gstack-ship-receipt block; seam=fake gh; no_claim=real gh+ test("a runs block's session ids are not phone numbers; a phone number anywhere else in or around the block still is", () => {+ const HEAD_A = "abc123abc123abc123abc123abc123abc123abcd";+ const HEAD_B = "def456def456def456def456def456def456def0";+ const RUN_A = "4242424-1700000000-deadbeef";+ const RUN_B = "3454314-1795338725-c32255b8";+ const post = (args: string[], text: string, visibility: "public" | "private" = "private") => {+ const f = fakeEnv({ files: { "/b": text }, visibility });+ return { code: run([...args, "--body-file", "/b"], f), phones: f.stdout().split("\n").filter(l => l.startsWith("RULE: pii.phone.e164 ")), f };+ };+ const runsBlock = (...lines: string[]) => `Body.\n\n\`\`\`gstack-receipt-runs\n${lines.join("\n")}\n\`\`\`\n`;++ const comment = post(["pr-comment", "1"], runsBlock(JSON.stringify({ head: HEAD_A, version: "1.0.0.0", run: RUN_A }), JSON.stringify({ run: RUN_B, head: HEAD_B, mark: "stop" })));+ expect([comment.phones, comment.code, comment.f.posts().length]).toEqual([[], EXIT.posted, 1]);++ const first = placeReceipt("## What changed\n\nFirst run.\n", orderReceipt({ schema_version: 1, pr: 4725, head: HEAD_A, base: "main", version: "1.0.0.0", run: RUN_A }));+ const second = placeReceipt(first, orderReceipt({ schema_version: 1, pr: 4725, head: HEAD_B, base: "main", version: "1.0.0.0", run: RUN_B }));+ expect(second).toContain("```gstack-receipt-runs\n");+ const body = post(["pr-body", "4725", "--replace"], second, "public");+ expect([body.phones, body.code, body.f.posts().length]).toEqual([[], EXIT.posted, 1]);++ const holds: Array<[string, string, string]> = [+ ["a phone number in reason on a line with a valid run", runsBlock(JSON.stringify({ head: HEAD_A, run: RUN_A, mark: "abandoned", by: "ops", reason: "call +14155552671" })), "call +14155552671"],+ ["a phone number as the run", runsBlock(JSON.stringify({ head: HEAD_A, run: "+14155552671" })), '"+14155552671"'],+ ["a truncated session id", runsBlock(JSON.stringify({ head: HEAD_A, run: "4242424-1700000000" })), '"4242424-1700000000"'],+ ["a session id under another key", runsBlock(JSON.stringify({ head: HEAD_A, run: "ship-1", grant: RUN_A })), RUN_A],+ ["a session id nested under review_loop", runsBlock(JSON.stringify({ head: HEAD_A, review_loop: { run: RUN_A } })), RUN_A],+ ["a non-canonical spaced line", runsBlock(`{ "head": "${HEAD_A}", "run": "${RUN_A}" }`), RUN_A],+ ["a duplicated run key", runsBlock(`{"head":"${HEAD_A}","run":"${RUN_A}","run":"${RUN_B}"}`), RUN_A],+ ["a line missing head", runsBlock(JSON.stringify({ version: "1.0.0.0", run: RUN_A })), RUN_A],+ ["a head that is not a 40-hex sha", runsBlock(JSON.stringify({ head: "main", run: RUN_A })), RUN_A],+ ["an unclosed runs block", `Body.\n\n\`\`\`gstack-receipt-runs\n${JSON.stringify({ head: HEAD_A, run: RUN_A })}\n`, RUN_A],+ ["a session id in prose after the block", runsBlock(JSON.stringify({ head: HEAD_A, run: RUN_B })) + `\nRun ${RUN_A} failed.\n`, `Run ${RUN_A}`],+ ["a runs block inside another fence", `Body.\n\n\`\`\`\`markdown\n\`\`\`gstack-receipt-runs\n${JSON.stringify({ head: HEAD_A, run: RUN_A })}\n\`\`\`\n\`\`\`\`\n`, RUN_A],+ ["a session id in a json block", `Body.\n\n\`\`\`json\n${JSON.stringify({ head: HEAD_A, run: RUN_A })}\n\`\`\`\n`, RUN_A],+ ];+ for (const [name, text, needle] of holds) {+ const { code, phones, f } = post(["pr-comment", "1"], text);+ const line = text.split("\n").findIndex(l => l.includes(needle)) + 1;+ expect([name, [...new Set(phones)], code, f.posts()]).toEqual([name, [`RULE: pii.phone.e164 LINE: ${line} PART: body`], EXIT.confirm, []]);+ }+ });+// Value: protects=a private PR's Approvals table (renderRecord, full mode) posts through pr-body without a pii.phone.e164 confirmation when a// fix-check grant row's Covers cell names a run id like 507-7192673 (GST-3246, trail-read row 8), while the same digits in that row's// Asked or Exact words cell, in prose, or in a table no Source footer closes still need one; fails_when=every private /ship body with such adiff --git a/test/plan-record.test.ts b/test/plan-record.test.tsindex 84e300b63..4f744f13a 100644--- a/test/plan-record.test.ts+++ b/test/plan-record.test.ts@@ -41,6 +41,41 @@ function fixture(files: Record<string, Array<Partial<ApprovalRow> & { ask: strinreturn { cwd, env, ids };}+describe('an interactive /autoplan run cited by its directory (#4402)', () => {+ // Value: protects=a Plan line naming an interactive run's directory (no run.json) resolves through the run id its gate+ // rows carry, the id the import now records; fails_when=the path token still resolves to the shared directory name+ // "autoplan" and finds no row; why_new=path tokens were only resolved through run.json or the directory name; seam=none+ test('a path token resolves through the run its decision rows carry', () => {+ const id = 'feature-x-20261122-104500';+ const f = fixture({ b: [{ ask: `Approve the plan (autoplan run ${id}, 1 decisions)`, source: `autoplan:${id}@gate_rev=1` }] });+ const run = path.join(f.cwd, '.gstack', 'tmp', 'autoplan');+ fs.mkdirSync(run, { recursive: true });+ fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ run: id, id: `${id}-p1`, status: 'approved', gate_rev: 1 }) + '\n');+ const r = resolvePlan(parsePlanLine('Plan: approved: .gstack/tmp/autoplan'), { cwd: f.cwd, env: f.env });+ expect(r.ok ? 'resolved' : r.failure.message).toBe('resolved');+ });++ // Value: protects=a Plan line naming a shared interactive folder that holds more than one run resolves to no run, so a later /autoplan in+ // the same checkout, or an approval imported before #4402 under the shared id "autoplan", never turns an unchanged PR body's citation into+ // another plan's approval, while the run id still resolves;+ // fails_when=the folder token follows whichever run was written last; why_new=the case above holds a single run; seam=none+ test('a path token whose folder holds several runs resolves to none of them; the run id still does', () => {+ const a = 'feature-x-autoplan-20261122-104500', b = 'feature-y-autoplan-20261122-114500';+ const f = fixture({ b: [{ ask: `Approve the plan (autoplan run ${a}, 1 decisions)`, source: `autoplan:${a}@gate_rev=1` }, { ask: `Approve the plan (autoplan run ${b}, 1 decisions)`, source: `autoplan:${b}@gate_rev=1` }],+ old: [{ ask: 'Approve the plan (autoplan run autoplan, 1 decisions)', source: 'autoplan:autoplan@gate_rev=1' }] });+ const run = path.join(f.cwd, '.gstack', 'tmp', 'autoplan');+ fs.mkdirSync(run, { recursive: true });+ fs.writeFileSync(path.join(run, 'decisions.jsonl'), [a, b].map(id => JSON.stringify({ run: id, id: `${id}-p1`, status: 'approved', gate_rev: 1 })).join('\n') + '\n');+ const byFolder = resolvePlan(parsePlanLine('Plan: approved: .gstack/tmp/autoplan'), { cwd: f.cwd, env: f.env });+ expect(byFolder.ok ? 'resolved' : byFolder.failure.code).toBe('PLAN_UNRESOLVED');+ const byId = resolvePlan(parsePlanLine(`Plan: approved: ${a}`), { cwd: f.cwd, env: f.env });+ expect(byId.ok ? 'resolved' : byId.failure.message).toBe('resolved');+ fs.writeFileSync(path.join(run, 'decisions.jsonl'), JSON.stringify({ run: a, id: `${a}-p1`, status: 'approved', gate_rev: 1 }) + '\n{"run": "torn');+ const torn = resolvePlan(parsePlanLine('Plan: approved: .gstack/tmp/autoplan'), { cwd: f.cwd, env: f.env });+ expect(torn.ok ? 'resolved' : torn.failure.code).toBe('PLAN_UNRESOLVED');+ });+});+describe('parsePlanLine', () => {test('reads approved, exempt and required, tolerating spacing and bold, and ignores fenced text', () => {expect(parsePlanLine('x\nPlan: approved: ap-20261107055041\n')).toEqual({ kind: 'approved', line: 'Plan: approved: ap-20261107055041', token: 'ap-20261107055041' });