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
A first version's public copy catches a short owner quote whose padding or quote marks are encoded (#4778)
Garry Tanbb6d13ea30a7
diff --git a/changelog.d/public-copy-redacts-encoded-padded-quotes.md b/changelog.d/public-copy-redacts-encoded-padded-quotes.mdnew file mode 100644index 000000000..39de25df1--- /dev/null+++ b/changelog.d/public-copy-redacts-encoded-padded-quotes.md@@ -0,0 +1 @@+**A first version's public export now catches a short owner quote whose padding or quote marks are encoded.** `gstack-autoplan export --public` matched a short plan quote on the raw text only, so a copy that wrote the padding as ` ` or a zero-width space, the quote marks as `"` or `\"`, or a space as ` ` kept the owner's words, and `validate --public` passed it. Short quotes are now matched on the same decoded text the long-quote scan reads, and the redaction still covers the original characters.diff --git a/docs/troubleshooting.md b/docs/troubleshooting.mdindex fee8a5dbe..1ed2bc5fa 100644--- a/docs/troubleshooting.md+++ b/docs/troubleshooting.md@@ -6030,7 +6030,7 @@ Markdown markup, invisible format characters, contractions and case; repliesof 1 or 2 words are not scanned for, and words the owner echoed from earliertext he didn't write are not his (the words a reply adds to an echo still are).A plan quote of any length is also one wherever it appears inside quote-marks, spaces just inside them included, and so is its `leave out:` reason after `leave out:`, `leave it out for+marks, padding just inside them and encoded characters included, and so is its `leave out:` reason after `leave out:`, `leave it out fornow:` or `reason to leave it out:`, in any case. See[the public copy](unattended.md#the-public-copy). `gstack-artifact validate --public <dir> --private<run>/run.json` reports each quote with file:line, and `gstack-autoplan exportdiff --git a/docs/unattended.md b/docs/unattended.mdindex ed0aa5639..d0d5acc67 100644--- a/docs/unattended.md+++ b/docs/unattended.md@@ -387,7 +387,7 @@ owner's own words: nothing a person wrote leaves without their click (GST-1243).quote too. Replies of 1 or 2 words ("yes", "do it") are not scanned for:they are codes or grammar, and the field itself is already dropped. A quoteunder the plan's `### Owner's words` heading is redacted at any length- wherever it appears inside quote marks (spaces just inside them included), and the reason on its+ wherever it appears inside quote marks (padding just inside them included, and the same after entities, JSON escapes and invisible characters are decoded), and the reason on its`leave out:` line wherever it follows `leave out:`, `leave it out for now:`or `reason to leave it out:`, in any case; a bare mention of a short quote'swords outside quote marks stays. A quotediff --git a/lib/autoplan-owner-words.ts b/lib/autoplan-owner-words.tsindex 551741ec5..eaf22a889 100644--- a/lib/autoplan-owner-words.ts+++ b/lib/autoplan-owner-words.ts@@ -10,7 +10,8 @@* quote in a `### Owner's words` section of any plan text the run kept (plan-active.md, plan-source*.md,* plan-at-gate.r*.md, plan-file.*.md; lib/autoplan-owner-text.ts), so a quote a revision removed stays redacted,* and a reason a human gave for `close --deferred <reason> --by human`. A plan quote of any length, and a- * quote's `leave out: <reason>`, are also redacted wherever gstack renders them: the quote between quote marks,+ * quote's `leave out: <reason>`, are also redacted wherever gstack renders them: the quote between quote marks+ * (padding inside them, entities, JSON escapes and invisible characters decoded as the token scan decodes them),* the reason after `leave out:`, `leave it out for now:` or `reason to leave it out:` in any case (GST-3646). A reply that* parsed as gate grammar (`owner_reply_parsed`) is the decision code and is* not scanned for; `reply` and the agent's own `answer_words` stay.@@ -66,7 +67,7 @@ export const WINDOW = 8;export type Span = [number, number];export interface OwnerSource { text: string; parsed?: boolean; prior?: string[] }interface Indexed { keys: string[]; set: Set<string>; prior: string }-export interface OwnerWords { replies: Indexed[]; placements: RegExp[] }+export interface OwnerWords { replies: Indexed[]; placements: RegExp[]; decoded: RegExp[] }/** A normalized string with, per UTF-16 unit, the original [from, to) range it came from. */interface Mapped { s: string; from: number[]; to: number[] }@@ -154,6 +155,8 @@ export function tokens(text: string, rendered = true): Token[] {}const escape = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+/** A plan quote between quote marks, with any whitespace just inside them. */+const quoteMarks = (q: string) => `["“]\\s*(${escape(q)})\\s*["”]`;/** Where gstack renders a human's deferral reason (R): the voice detail, the consensus head, the gate title, a blocker's why, the run log. */const DEFERRAL_RENDERINGS = (r: string) => [`^deferred: (${r})$`, `\\((${r}); by human\\)`, `accepted-with-findings at round \\d+ \\((${r})\\): `, `closed deferred \\((${r})\\) with this finding open`, `, by human\\): (${r}); \\d+ open finding`];@@ -190,15 +193,22 @@ export function ownerIndex(replies: OwnerSource[], o: { deferred?: OwnerSource[]const placements = [...(o.deferred ?? []).flatMap(d => DEFERRAL_RENDERINGS(escape(d.text))),...(o.carried ?? []).map(w => `words=(${escape(JSON.stringify(w))})(?= by=|$)`),- ...(o.quoted ?? []).map(q => `["“]\\s*(${escape(q)})\\s*["”]`),+ ...(o.quoted ?? []).map(quoteMarks),].map(p => new RegExp(p, 'gd')).concat((o.reasons ?? []).map(r => new RegExp(`(?:leave out|leave it out for now|reason to leave it out)\\s*:\\s*(${escape(r)})`, 'gdi')));- return { replies: indexed, placements };+ const decoded = [...new Set((o.quoted ?? []).map(q => normalize(q, false).s.trim()).filter(Boolean))].map(q => new RegExp(quoteMarks(q).replace(/\s+/g, '\\s+'), 'gd'));+ return { replies: indexed, placements, decoded };}/** Every owner-words span in `text` (placements, then quotes less echoes, in both views), merged, as original [start, end) offsets. */export function ownerSpans(text: string, owner: OwnerWords): Span[] {const spans: Span[] = [];for (const re of owner.placements) for (const m of text.matchAll(re)) spans.push([m.indices![1]![0], m.indices![1]![1]]);+ for (const view of owner.decoded.length ? [normalize(text, false), normalize(text, true)] : []) {+ for (const re of owner.decoded) for (const m of view.s.matchAll(re)) {+ const [a, b] = m.indices![1]!;+ if (b > a) spans.push([view.from[a]!, view.to[b - 1]!]);+ }+ }for (const ts of owner.replies.length ? [tokens(text, false), tokens(text)] : []) {const keys = ts.map(t => t.key);for (const r of owner.replies) {diff --git a/test/autoplan-owner-words.test.ts b/test/autoplan-owner-words.test.tsindex 22bcab333..5a47d6dd3 100644--- a/test/autoplan-owner-words.test.ts+++ b/test/autoplan-owner-words.test.ts@@ -154,6 +154,25 @@ describe('redactOwnerWords', () => {for (const kept of ['deferred: no time to spare', 'eng closed accepted-with-findings at round 1 (no time left): 0 open', '(no time; by agent:x)', 'we had no time to spare']) expect(redactOwnerWords(kept, o).text).toBe(kept);});+ test('a short plan quote in quote marks is redacted however the padding or the text is encoded, and a bare mention stays (GST-3646)', () => {+ const o = ownerIndex([], { quoted: ['water alerts'] });+ const cases: Array<[string, string]> = [+ ['He said "water alerts".', `He said "${MARK}".`],+ ['He said " water alerts ".', `He said " ${MARK} ".`],+ ['He said " water alerts ".', `He said " ${MARK} ".`],+ ['He said "\u200bwater alerts\u200b".', `He said "\u200b${MARK}\u200b".`],+ ['He said "water alerts".', `He said "${MARK}".`],+ ['He said “water alerts”.', `He said “${MARK}”.`],+ ['He said “water alerts”.', `He said “${MARK}”.`],+ ['He said "water alerts".', `He said "${MARK}".`],+ ['{"title":"He said \\"water\\u00a0alerts\\""}', `{"title":"He said \\"${MARK}\\""}`],+ ['{"title":"He said \\"water alerts\\""}', `{"title":"He said \\"${MARK}\\""}`],+ ['Pick "panel" water alerts "toggle" here', `Pick "panel" ${MARK} "toggle" here`],+ ];+ expect(cases.filter(([text, want]) => redactOwnerWords(text, o).text !== want).map(([text]) => text)).toEqual([]);+ for (const kept of ['Turn on water alerts today.', 'He said "water alerts are noisy".']) expect(redactOwnerWords(kept, o).text).toBe(kept);+ });+test('every template that renders a deferral reason has a placement (add one to DEFERRAL_RENDERINGS with any new template)', () => {const root = path.resolve(import.meta.dir, '..');const count = Object.fromEntries(fs.readdirSync(path.join(root, 'lib')).filter(f => f.startsWith('autoplan-') && f.endsWith('.ts'))diff --git a/test/autoplan-public-owner-words.test.ts b/test/autoplan-public-owner-words.test.tsindex d9a73f470..29f1ed1e2 100644--- a/test/autoplan-public-owner-words.test.ts+++ b/test/autoplan-public-owner-words.test.ts@@ -466,6 +466,8 @@ describe("short owner quotes and leave-out reasons stay out of a first-version e['an emoji and a word', u => `🚀 ${u}`],['CJK', u => `毎朝ベル${u}`],['two words padded inside the quote marks', u => `skelvy ${u}`, ' '],+ ['two words padded with a no-break space entity', u => `drimble ${u}`, ' '],+ ['two words padded with a zero-width space', u => `frawny ${u}`, '\u200b'],];const LINES: Array<[string, (r: string) => string, boolean]> = [['does it', () => ' → does it', false],@@ -524,6 +526,8 @@ describe("short owner quotes and leave-out reasons stay out of a first-version econst ownerWordsAt = (added: string) => { fs.writeFileSync(record, before + added); return validate().stderr.includes('ARTIFACT_OWNER_WORDS'); };expect(ownerWordsAt(`The owner said “${ROWS[0]!.words}”.\n`)).toBe(true);expect(ownerWordsAt(`The owner said " ${ROWS[1]!.words} ".\n`)).toBe(true);+ expect(ownerWordsAt(`The owner said " ${ROWS[1]!.words} ".\n`)).toBe(true);+ expect(ownerWordsAt(`The owner said "\u200b${ROWS[1]!.words}\u200b".\n`)).toBe(true);expect(ownerWordsAt(`The plan's reason: leave out: ${ROWS[2]!.reason}\n`)).toBe(true);expect(ownerWordsAt(`A plain mention of ${ROWS[0]!.words} and ${ROWS[2]!.reason}.\n`)).toBe(false);fs.writeFileSync(record, before);