Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/public-copy-redacts-encoded-padded-quotes.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -6030,7 +6030,7 @@ Markdown markup, invisible format characters, contractions and case; replies
of 1 or 2 words are not scanned for, and words the owner echoed from earlier
text 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 for
now:` 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 export
Expand Down
2 changes: 1 addition & 1 deletion docs/unattended.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 quote
under 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's
words outside quote marks stays. A quote
Expand Down
18 changes: 14 additions & 4 deletions lib/autoplan-owner-words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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[] }
Expand Down Expand Up @@ -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`];

Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions test/autoplan-owner-words.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "&nbsp;water alerts&nbsp;".', `He said "&nbsp;${MARK}&nbsp;".`],
['He said "\u200bwater alerts\u200b".', `He said "\u200b${MARK}\u200b".`],
['He said &quot;water alerts&quot;.', `He said &quot;${MARK}&quot;.`],
['He said “water&#32;alerts”.', `He said “${MARK}”.`],
['He said “water&nbsp;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'))
Expand Down
4 changes: 4 additions & 0 deletions test/autoplan-public-owner-words.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, '&nbsp;'],
['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],
Expand Down Expand Up @@ -524,6 +526,8 @@ describe("short owner quotes and leave-out reasons stay out of a first-version e
const 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 "&nbsp;${ROWS[1]!.words}&nbsp;".\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);
Expand Down
Loading