commit e47b78a89f5b69eca0ec35d94e150f60d6d12420
parent 5a172059743450a04e91c1f02c7d4c936d9721cc
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 12 Nov 2026 08:38:02 -0500
sweep-pipeline: the read-aloud cues are linear -- no pattern counts words with a regex (D2 round b review)
The after-quote reaction pattern `^(?:\W*\w+){0,10}?\W+(?:what a shame|…)`
let `\w+` cut one long word into up to ten pieces: on the text after a quote,
"a"x35 took 163 ms, "a"x40 1.3 s, "a"x60 never returned -- inside the editor,
on cue text nobody vetted. "Within the first ten words" is now read by
splitting the words and comparing the phrase list against them.
Audited every other pattern in readAloud.ts and neutralClaim.ts for the same
shape (a quantified group holding a quantified token that can match the same
characters): "likes" had `\s*(k|thousand|million)?\s*` (now one optional
group), "here" had `(?:see )+` (now at most three); the trailing-punctuation
trim of a label is a loop. The quote is read to 2000 characters, the text
before and after to twice their windows before lowercasing.
Tests: every place readAloudCues reads, on "a"x200, "a"x60, a 150-letter
word, "ha"x75, 150 digits and 100k-character adversarial strings (repeated
"see ", "jeremy ", "1, ", " .", "says ", a run of letters then the phrase):
each under 50 ms; the phrase found within ten words and not at the eleventh.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
2 files changed, 76 insertions(+), 8 deletions(-)
diff --git a/common/lib/report/draft/tasks/readAloud.test.ts b/common/lib/report/draft/tasks/readAloud.test.ts
@@ -94,3 +94,50 @@ test("a cue far back does not count for the near ones; each cue is reported once
assert.equal(cuesLine(got), "tweet (“tweet”), likes (“371 likes”)");
assert.ok(READ_ALOUD_FLAG.length <= 60, "a claim's flag is at most 60 characters");
});
+
+// The review of round b (12 Nov 2026): the after-quote pattern backtracked
+// for ever on one long word ("a"×60 never returned). Every pattern, at every
+// place it reads, on long and adversarial text: under 50 ms.
+test("the cues are linear: long words, repeated syllables, digits, 100k-character text", () => {
+ const big = (s: string) => s.repeat(Math.ceil(100_000 / s.length)).slice(0, 100_000);
+ const inputs = [
+ "a".repeat(200),
+ "a".repeat(60),
+ "x".repeat(150),
+ "ha".repeat(75),
+ "7".repeat(150),
+ "1,".repeat(75),
+ big("a "),
+ big("a"),
+ big("see "),
+ big("you see "),
+ big("1, "),
+ big(" ."),
+ big("jeremy "),
+ big("i'm jeremy "),
+ big("hey "),
+ big("@a"),
+ big("says "),
+ big("oh"),
+ big("mm"),
+ "a".repeat(100_000) + " what a shame",
+ ];
+ for (const s of inputs) {
+ for (const where of ["before", "quote", "after"] as const) {
+ const o = { before: "", quote: "the quote", after: "", hosts: ["jeremy", "jeremy hambly", "the quartering"], [where]: s };
+ const t0 = performance.now();
+ readAloudCues(o);
+ const ms = performance.now() - t0;
+ assert.ok(ms < 50, `${where} = ${JSON.stringify(s.slice(0, 12))}×${s.length}: ${ms.toFixed(1)} ms`);
+ }
+ }
+});
+
+test("'what a shame', 'goes on to say' within the first ten words after the quote, and not past them", () => {
+ assert.deepEqual(cues("", "the show is bad", "ah well what a shame I'll keep watching"), ["reaction (after)"]);
+ assert.deepEqual(cues("", "the show is bad", "and then he goes on to say more"), ["reaction (after)"]);
+ assert.deepEqual(cues("", "the show is bad", "one two three four five six seven eight nine ten imagine that"), ["reaction (after)"]);
+ assert.deepEqual(cues("", "the show is bad", "one two three four five six seven eight nine ten eleven imagine that"), []);
+ assert.deepEqual(cues("", "the show is bad", "a".repeat(60) + " what a shame"), ["reaction (after)"]);
+ assert.equal(readAloudCues({ before: "", quote: "q", after: "ah well what a shame I'll" })[0]!.match, "ah well what a shame");
+});
diff --git a/common/lib/report/draft/tasks/readAloud.ts b/common/lib/report/draft/tasks/readAloud.ts
@@ -47,7 +47,7 @@ const BEFORE: Pattern[] = [
// "one tweet that put it really good", "kurt tweeted along", "retweets"
{ cue: "tweet", re: /\b(?:re)?tweet(?:s|ed|ing)?\b|\bquote tweet/, near: 250 },
// "453 comments 371 likes", "19,000 likes here it is"
- { cue: "likes", re: /\b\d[\d,.]*\s*(?:k|thousand|million)?\s*(?:likes|retweets|replies|comments|reposts|upvotes)\b/ },
+ { cue: "likes", re: /\b\d[\d,.]*\s*(?:(?:k|thousand|million)\s*)?(?:likes|retweets|replies|comments|reposts|upvotes)\b/ },
// "here's another article", "you can see the article from just a few hours ago"
{ cue: "article", re: /\b(?:here'?s|see|saw|seen|read|reading|reads|whole|another|according to) (?:\w+ ){0,2}(?:article|headline|op-?ed|press release|blog post|write-?up|story|report)s?\b/ },
// "oh another comment mods made … made it clear that", "left a slanderous libel review"
@@ -80,7 +80,7 @@ const BEFORE: Pattern[] = [
{ cue: "via", re: /\b(?:this is|it'?s|that'?s) (?:via|from|by|over at|on)\b|\bvia\b/, near: 300 },
// "here you have end wokeness", "here's polygon again", "you see this from lucas",
// "here it is", "you can see"
- { cue: "here", re: /\bhere (?:you have|you got|we have|we got|it is|is)\b|\bhere'?s\b|\byou (?:can )?(?:see )+(?:this|here|from|that|the)\b|\b(?:take|taking) a look\b|\blisten to this\b|\bcheck this out\b|\blook at this\b/, near: 300 },
+ { cue: "here", re: /\bhere (?:you have|you got|we have|we got|it is|is)\b|\bhere'?s\b|\byou (?:can )?(?:see ){1,3}(?:this|here|from|that|the)\b|\b(?:take|taking) a look\b|\blisten to this\b|\bcheck this out\b|\blook at this\b/, near: 300 },
// "shout out dally here's bonfire legend"
{ cue: "shout out", re: /\bshout ?-?out\b/, near: 300 },
// chat: "sologamer5 says hey jeremy"
@@ -93,29 +93,48 @@ const BEFORE: Pattern[] = [
const AFTER: Pattern[] = [
// "… this is from roar ashley shout out good take"
{ cue: "from (after)", re: /\b(?:this (?:is )?(?:from|via|by)|shout ?-?out|good take|great take|liked this|likes this|\d[\d,.]*\s*(?:likes|retweets))\b/, near: 120 },
- // "this is a lie this is libel", "that is a really disingenuous interpretation of what he said",
- // "oh okay it's not productive", "what a shame", "imagine that"
+ // Straight after it: "this is a lie this is libel", "that is a really disingenuous interpretation of what
+ // he said", "oh okay it's not productive", "what a shame", "imagine that".
{
cue: "reaction (after)",
- re: /^(?:this is a lie|that is a (?:really |very |completely )?(?:disingenuous|dishonest|ridiculous|insane|wild|crazy)|what a shame|imagine that|oh+ ?okay|okay so (?:he|she|they)|mm+ that'?s|(?:he|she|they|it) (?:goes|go) on|(?:he|she|they) (?:also )?(?:say|says|said|write|writes|wrote)\b)|^(?:\W*\w+){0,10}?\W+(?:what a shame|imagine that|go(?:es|ing) on to say|went on to say)\b/,
+ re: /^(?:this is a lie|that is a (?:really |very |completely )?(?:disingenuous|dishonest|ridiculous|insane|wild|crazy)|what a shame|imagine that|oh+ ?okay|okay so (?:he|she|they)|mm+ that'?s|(?:he|she|they|it) (?:goes|go) on|(?:he|she|they) (?:also )?(?:say|says|said|write|writes|wrote)\b)/,
near: 120,
},
];
+// Within the first ten words after it: "ah well what a shame", "and he goes on to say". Read by
+// splitting the words, never by a regex that counts words: `(?:\W*\w+){0,10}` can cut one long
+// word into ten pieces and backtracks for ever on a run of letters (review of round b, 12 Nov).
+const AFTER_WORDS = 10;
+const AFTER_PHRASES: readonly (readonly string[])[] = ["what a shame", "imagine that", "goes on to say", "going on to say", "went on to say"].map((p) => p.split(" "));
+
+function phraseInFirstWords(after: string): string | null {
+ const words = after.split(/[^a-z0-9_]+/).filter(Boolean).slice(0, AFTER_WORDS + 4);
+ for (let i = 0; i <= Math.min(AFTER_WORDS, words.length - 1); i++) {
+ for (const p of AFTER_PHRASES) {
+ if (p.every((w, j) => words[i + j] === w)) return words.slice(0, i + p.length).join(" ");
+ }
+ }
+ return null;
+}
+
const esc = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const lower = (s: string) => s.toLowerCase().replace(/[’‘]/g, "'").replace(/\s+/g, " ").trim();
export const READ_ALOUD_BEFORE = 400;
export const READ_ALOUD_AFTER = 150;
+// A quote is at most 40 words in a sweep; the cap keeps a caller's long text linear and short.
+export const READ_ALOUD_QUOTE = 2000;
// The cues around one quote: none = nothing says it is read aloud.
// `hosts`: the names of the person the report is about (lowercase); a quote
// that names him in the third person is somebody else's words about him.
export function readAloudCues(o: { before: string; quote: string; after: string; hosts?: readonly string[] }): ReadAloudCue[] {
const out: ReadAloudCue[] = [];
- const before = lower(o.before).slice(-READ_ALOUD_BEFORE);
- const after = lower(o.after).slice(0, READ_ALOUD_AFTER);
- const quote = lower(o.quote);
+ // Sliced before `lower` too (whitespace runs collapse, so twice the window is read).
+ const before = lower(o.before.slice(-READ_ALOUD_BEFORE * 2)).slice(-READ_ALOUD_BEFORE);
+ const after = lower(o.after.slice(0, READ_ALOUD_AFTER * 2)).slice(0, READ_ALOUD_AFTER);
+ const quote = lower(o.quote.slice(0, READ_ALOUD_QUOTE * 2)).slice(0, READ_ALOUD_QUOTE);
const add = (cue: string, where: ReadAloudCue["where"], match: string) => {
if (!out.some((c) => c.cue === cue)) out.push({ cue, where, match: match.trim() });
};
@@ -128,6 +147,8 @@ export function readAloudCues(o: { before: string; quote: string; after: string;
const m = p.re.exec(p.near ? after.slice(0, p.near) : after);
if (m) add(p.cue, "after", m[0]);
}
+ const said = phraseInFirstWords(after.slice(0, 120));
+ if (said) add("reaction (after)", "after", said);
// In the quote: the host named in the third person ("jeremy hambly was
// banned by wizards", "hambly has in the past gone after"), a chat line
// ("sologamer5 says hey jeremy"), a "quote" spoken inside it.