mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-29 19:34:29 +01:00
A first version's public copy catches a short owner quote whose padding or quote marks are encoded (#4778)
A first version's public export now catches a short owner quote when its padding or quote marks are encoded, such as ` `, a zero-width space, `"` or a JSON `\"`. Why: those spellings kept the owner's words in the public copy and `validate --public` passed them; short quotes are now matched on the same decoded text the long-quote scan reads. Nothing to do: the redaction still replaces only the original characters of the quote. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/specialist-batched#1 reader=red-team
This commit is contained in:
1 parent
f3a89d2105
commit
bb6d13ea30
6 files changed
+40
-6
No files matched your search
@@ -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.
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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 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 " ${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);
|
||||
|
||||
Reference in new issue
Block a user