// The MEANING CHECK of a local sweep (demo epic D2, item 3): one small model // call per kept item, WITH the transcript around its quote, and rules in code // over the answer. // // D0 (11 Nov 2026): 46 of 177 kept quotes were not the host's words — an // article, a review, a tweet, a letter, a clip or chat he reads aloud — and the // sentence said "Jeremy claims". Reading an accusation to rebut it became a // reversal (the "banned for sexual harassment" line, wrong on both models). // The evidence is almost always in the ~300 characters BEFORE the quote, which // the lint cannot see. So the check reads 400 characters before, the quote, // 150 after and the drafted sentence, and answers four fields; code decides. import { lintClaim } from "./claimChecks"; export const SPEAKERS = ["host", "someone he reads or plays", "unclear"] as const; export const STANCES = ["asserts", "reads it out", "rebuts it", "sarcastic", "unclear"] as const; export const SENTENCES = ["supported", "overstated", "reversed"] as const; export type Speaker = (typeof SPEAKERS)[number]; export type Stance = (typeof STANCES)[number]; export type SentenceVerdict = (typeof SENTENCES)[number]; export type MeaningAnswer = { speaker: Speaker; stance: Stance; sentence: SentenceVerdict; fix: string | null }; export const MEANING_SYSTEM = "You check one finding of a report on what a streamer (the host) has said. You get the question, the transcript just " + "BEFORE the quote, the QUOTE, the transcript just AFTER it, and the drafted sentence. The transcript is automatic and " + "has no punctuation. Answer four things. speaker: is the QUOTE the host's own words (host), or words of someone else " + "he reads aloud or plays — an article, review, post, tweet, letter, chat message, donation, a clip of another person " + "(someone he reads or plays), or can you not tell (unclear)? Look for \"it says\", \"he wrote\", \"they said\", " + "\"listen to this\", a title read out, before the quote. stance: does the host assert it as his own view (asserts), " + "only read it out (reads it out), quote it to reject or mock it (rebuts it), say it sarcastically, meaning the " + "opposite (sarcastic), or unclear? sentence: does the drafted sentence say what the host means here (supported), say " + "more than the quote does — a dropped maybe or I think, someone else's words given as his, a guess stated as fact " + "(overstated), or the opposite of what he means (reversed)? fix: when the sentence is not supported or the words " + "are not his, a corrected sentence of at most 30 words in the third person (\"He says …\"); for words he reads or " + "plays, write both halves: \"He reads a that says …; he calls it …\" (what he says " + "of it, from the transcript). Use only what the transcript says. Otherwise an empty string."; export const MEANING_SCHEMA = { type: "object", properties: { speaker: { type: "string", enum: [...SPEAKERS] }, stance: { type: "string", enum: [...STANCES] }, sentence: { type: "string", enum: [...SENTENCES] }, fix: { type: "string" }, }, required: ["speaker", "stance", "sentence", "fix"], }; export function meaningPrompt(o: { question: string; host: string; before: string; quote: string; after: string; sentence: string }): string { return [ `Question: ${o.question}`, `The host: ${o.host}`, `Before the quote: …${o.before}`, `QUOTE: ${o.quote}`, `After the quote: ${o.after}…`, `Drafted sentence: ${o.sentence}`, ].join("\n\n"); } // The model's answer, read strictly: an unknown value is "unclear" (speaker, // stance) or "overstated" (sentence); an empty fix is null. export function readMeaning(raw: unknown): MeaningAnswer { const r = (raw && typeof raw === "object" ? raw : {}) as Record; const pick = (v: unknown, all: readonly T[], d: T): T => (typeof v === "string" && (all as readonly string[]).includes(v.trim()) ? (v.trim() as T) : d); const fix = typeof r.fix === "string" ? r.fix.replace(/\s+/g, " ").replace(/["“”]/g, "'").trim() : ""; return { speaker: pick(r.speaker, SPEAKERS, "unclear"), stance: pick(r.stance, STANCES, "unclear"), sentence: pick(r.sentence, SENTENCES, "overstated"), fix: fix && !/^(null|none|n\/a)$/i.test(fix) ? fix : null, }; } export const MAX_FIX_WORDS = 30; const words = (s: string) => s.split(/\s+/).filter(Boolean).length; // "He reads a review that says …; he calls it …": a reading half (reads, // plays, quotes, shows) and, after the semicolon, what he says of it. export function hasBothHalves(s: string): boolean { const parts = s.split(";").map((p) => p.trim()); if (parts.length < 2 || !parts[0] || !parts[1]) return false; const reading = /\b(reads?|reading|plays?|playing|quotes?|quoting|shows?|showing|cites?|citing)\b/i.test(parts[0]); const reaction = /^(he|she|they|and he|but he|then he)\b/i.test(parts[1]) && words(parts[1]) >= 3; return reading && reaction; } // What he says of what he reads must come from the transcript AROUND the // quote: the reaction half carries at least one word (four letters or more, // not a common one) found before or after the quote and not in it. A half that // only restates the read text, or invents a reaction, has none (D2 run // i123-d-q25: "he calls it crucial for consistency" of a tweet that said // "crucial … consistency"). const COMMON = new Set( "that this they them their there what when with from have says said calls call reads read thinks think about would could should just like really very also than then into over only more most much some such were been being does doesn't isn't it's he's she's".split(" "), ); const contentWords = (s: string) => s .toLowerCase() .replace(/[^a-z0-9' ]+/g, " ") .split(/\s+/) .map((w) => w.replace(/'s$/, "")) .filter((w) => w.length >= 4 && !COMMON.has(w)); export function reactionGrounded(sentence: string, o: { quote: string; before: string; after: string }): boolean { const reaction = sentence.split(";").slice(1).join(";"); // Compared by their first five letters ("slander" / "slanderous"). const stem = (w: string) => w.slice(0, 5); const inQuote = new Set(contentWords(o.quote).map(stem)); const around = new Set([...contentWords(o.before), ...contentWords(o.after)].map(stem)); return contentWords(reaction).some((w) => around.has(stem(w)) && !inQuote.has(stem(w))); } // "The host reads …" → "He reads …". export function heSentence(s: string): string { return s.replace(/^(the host|the streamer|the speaker)\b/i, "He").replace(/;\s*(the host|the streamer|the speaker)\b/gi, "; he"); } export type MeaningDecision = | { action: "keep"; sentence: string; why: string } | { action: "rewrite"; sentence: string; why: string } | { action: "mark"; sentence: string; why: string } | { action: "drop"; why: string }; // The rules, in code (spec D2 item 3): // - reversed → dropped; // - not his words, or he rebuts it or is sarcastic → rewritten as "He reads a // … that says …; he calls it …" ONLY if the fix (or the draft) carries both // halves, else dropped; // - overstated → the fix replaces the sentence if the lint passes, else dropped; // - speaker or stance unclear → kept, marked "check by ear" (and never in the // first section: the pipeline's grouping); // - else kept as drafted. export function decideMeaning(a: MeaningAnswer, o: { sentence: string; quote: string; before?: string; after?: string }): MeaningDecision { if (a.sentence === "reversed") return { action: "drop", why: "reversed: the sentence says the opposite of what he means" }; // "reads it out" is reading too: words he voices, not his view (D2 run // i123-d-q25: the model called the reader "host" with the stance "reads it // out" on 7 of 21 items, every one a headline or a tweet). const notHis = a.speaker === "someone he reads or plays" || a.stance === "reads it out"; if (notHis || a.stance === "rebuts it" || a.stance === "sarcastic") { const why = notHis ? "not his words" : a.stance === "sarcastic" ? "he is sarcastic" : "he rebuts it"; const ctx = { quote: o.quote, before: o.before ?? "", after: o.after ?? "" }; let ungrounded = false; for (const raw of [a.fix, o.sentence]) { const s = raw ? heSentence(raw) : raw; if (!s || words(s) > MAX_FIX_WORDS + 10 || !hasBothHalves(s)) continue; if (!reactionGrounded(s, ctx)) { ungrounded = true; continue; } return { action: "rewrite", sentence: s, why: `${why}: says what he reads and what he says of it` }; } return { action: "drop", why: ungrounded ? `${why}; what he says of it is not in the transcript around the quote` : `${why}, and no sentence says both what he reads and what he says of it`, }; } let sentence = o.sentence; let rewritten = false; if (a.sentence === "overstated") { if (!a.fix || words(a.fix) > MAX_FIX_WORDS) return { action: "drop", why: "overstated, with no usable fix" }; const flags = lintClaim(a.fix, o.quote); if (flags.length) return { action: "drop", why: `overstated; the fix fails the lint (${flags[0]})` }; sentence = heSentence(a.fix); rewritten = true; } if (a.speaker === "unclear" || a.stance === "unclear") return { action: "mark", sentence, why: `${a.speaker === "unclear" ? "speaker" : "stance"} unclear: check by ear` }; return rewritten ? { action: "rewrite", sentence, why: "overstated: the fix replaces it" } : { action: "keep", sentence, why: "supported, his own words" }; } export const CHECK_BY_EAR = "Check by ear:";