mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 11:53:55 +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
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user