commit 347e3506999c4bbb7c4b8df8a38ae99ec57d6099
parent cade127d35e4ebf57543e8c24851b911cd4a336e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 10:42:33 -0500
sweep-pipeline: a meaning check per kept item, with its context (D2 item 3)
46 of D0's 177 kept quotes were not the host's words -- an article, review,
tweet, letter, clip or chat he reads aloud -- and the sentence said "Jeremy
claims"; reading an accusation to rebut it became a reversal. The evidence
is in the transcript before the quote, which the lint cannot see.
Now each kept item (at most 60, strongest first) gets its own small call:
the question, the 400 characters before the quote, the quote, the 150 after
and the drafted sentence; the answer is speaker / stance / sentence / fix,
and code decides (meaning.ts):
- reversed: dropped;
- not his words (or "reads it out", or he rebuts it, or sarcasm): rewritten
as "He reads a <review/post/...> that says ...; he calls it ..." only when
a sentence carries both halves AND what he says of it is grounded in the
transcript around the quote (a word from there, not from the quote); else
dropped;
- overstated: the fix replaces the sentence if the lint passes, else
dropped;
- speaker or stance unclear: kept as "Check by ear:", in a last section of
its own, never grouped.
Every answer is stored beside its item in the iteration's items.jsonl (the
prompt, the answer, the decision, the seconds) and traced as `meaning`.
Fewer than three items left after the check is "nothing usable found".
lintClaim moves to claimChecks.ts and accepts a hedge said in other words
("I think" kept as "he thinks", "maybe" as "may" or "might").
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
8 files changed, 423 insertions(+), 34 deletions(-)
diff --git a/common/lib/report/draft/tasks/claimChecks.ts b/common/lib/report/draft/tasks/claimChecks.ts
@@ -82,3 +82,47 @@ export function onTopicBy(o: { quote: string; before: string; terms: readonly st
// A full sweep needs this many items on the question to be a report; fewer is
// "nothing usable found" (never padded).
export const MIN_KEPT = 3;
+
+const HEDGES = ["allegedly", "reportedly", "claims", "claimed", "may", "might", "maybe", "if", "probably", "likely", "i think", "apparently", "supposedly", "rumor", "rumour"];
+// A hedge is kept when the sentence says it in its own words: "I think" is
+// "he thinks"; "maybe" is "may", "might" or "perhaps".
+const MAYBE = ["maybe", "may", "might", "perhaps", "possibly", "could"];
+const HEDGE_KEPT_BY: Record<string, string[]> = {
+ "i think": ["i think", "thinks?", "believes?", "feels?", "guess(?:es)?", "suspects?", "in his (?:view|opinion)"],
+ maybe: MAYBE,
+ may: MAYBE,
+ might: MAYBE,
+ probably: ["probably", "likely", "thinks?", "believes?", "expects?"],
+ likely: ["probably", "likely", "thinks?", "believes?", "expects?"],
+ allegedly: ["allegedly", "reportedly", "claims?", "claimed", "accused", "accusations?"],
+ reportedly: ["reportedly", "allegedly", "reports?", "claims?", "according to"],
+ apparently: ["apparently", "reportedly", "seems?", "appears?"],
+ supposedly: ["supposedly", "allegedly", "reportedly", "claims?"],
+};
+const NEGATIONS = /\b(never|not|no|nobody|nothing|none|neither|nor|cannot|without)\b|n't\b/i;
+
+// The drafted sentence against its quote: a negation or hedge lost or added,
+// a number not in the quote. Flags, never drops (the meaning check's fix of an
+// overstated sentence must pass it).
+export function lintClaim(claim: string, quote: string): string[] {
+ const flags: string[] = [];
+ const qn = quote.toLowerCase();
+ const cn = claim.toLowerCase();
+ if (NEGATIONS.test(qn) && !NEGATIONS.test(cn)) flags.push("negation: the quote has a not/never/no the claim does not");
+ if (!NEGATIONS.test(qn) && NEGATIONS.test(cn)) flags.push("negation: the claim has a not/never/no the quote does not");
+ for (const h of HEDGES) {
+ const re = new RegExp(`\\b${h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
+ const kept = new RegExp(`\\b(${(HEDGE_KEPT_BY[h] ?? [h]).join("|")})\\b`);
+ if (re.test(qn) && !kept.test(cn)) {
+ flags.push(`hedge dropped: the quote says “${h}”`);
+ break;
+ }
+ }
+ for (const num of claim.match(/\d[\d,.]*/g) ?? []) {
+ if (!quote.includes(num.replace(/[.,]+$/, ""))) {
+ flags.push(`number ${num} is not in the quote`);
+ break;
+ }
+ }
+ return flags;
+}
diff --git a/common/lib/report/draft/tasks/meaning.test.ts b/common/lib/report/draft/tasks/meaning.test.ts
@@ -0,0 +1,90 @@
+// The meaning check's rules in code (demo epic D2, item 3), on D0's own
+// cases.
+
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { decideMeaning, hasBothHalves, meaningPrompt, readMeaning, type MeaningAnswer } from "./meaning";
+
+const A = (o: Partial<MeaningAnswer>): MeaningAnswer => ({ speaker: "host", stance: "asserts", sentence: "supported", fix: null, ...o });
+
+// D0 a-qwen3-8b k01, reversed on both models: he reads a hostile business
+// review aloud and says at once "this is a lie this is liable this is slanderous".
+const REVIEW = {
+ sentence: "Jeremy Hambly was banned by Wizards of the Coast from sanctioned events due to constant sexual harassment.",
+ quote: "was banned by Wizards of the Coast from attending sanctioned events due to constant sexual harassment",
+ before: "let's look at the reviews of the coffee company one star it says Jeremy Hambly",
+ after: "this is a lie this is liable this is slanderous",
+};
+
+test("not his words / he rebuts it: rewritten only when the fix says what he reads AND what he says of it", () => {
+ const fix = "He reads a business review that says Wizards banned him for constant sexual harassment; he calls it a lie and slander.";
+ const d = decideMeaning(A({ speaker: "someone he reads or plays", stance: "rebuts it", sentence: "reversed", fix }), REVIEW);
+ assert.equal(d.action, "drop", "reversed comes first: the drafted sentence is gone either way");
+ const r = decideMeaning(A({ speaker: "someone he reads or plays", stance: "rebuts it", sentence: "overstated", fix }), REVIEW);
+ assert.deepEqual([r.action, r.action !== "drop" && r.sentence], ["rewrite", fix]);
+ const half = decideMeaning(A({ speaker: "someone he reads or plays", stance: "reads it out", sentence: "overstated", fix: "Jeremy reads a review saying he was banned for harassment." }), REVIEW);
+ assert.equal(half.action, "drop");
+ assert.match(half.action === "drop" ? half.why : "", /^not his words, and no sentence says both/);
+ // Sarcasm is the same rule.
+ assert.equal(decideMeaning(A({ stance: "sarcastic", fix: null }), REVIEW).action, "drop");
+ // A drafted sentence that already carries both halves stands.
+ const both = "He reads a tweet that says the show is a hit; he says nobody watched it.";
+ const k = decideMeaning(A({ speaker: "someone he reads or plays", stance: "rebuts it", sentence: "supported", fix: null }), { sentence: both, quote: "the show is a hit", before: "a tweet", after: "nobody watched this garbage" });
+ assert.deepEqual([k.action, k.action !== "drop" && k.sentence], ["rewrite", both]);
+ // What he says of it must be in the transcript around the quote, not a
+ // restatement of what he reads (D2 run i123-d-q25, the power-scaling tweet).
+ const shad = {
+ sentence: "Jeremy says episode 5 does not understand power scaling.",
+ quote: "the acolyte episode 5 doesn't understand power scaling at all which is crucial if you want consistency",
+ before: "Shad adversity",
+ after: "and investment in a fight great point",
+ };
+ const restated = decideMeaning(A({ speaker: "someone he reads or plays", sentence: "overstated", fix: "He reads a tweet that says episode 5 misses power scaling; he calls it crucial for consistency." }), shad);
+ assert.equal(restated.action, "drop");
+ assert.match(restated.action === "drop" ? restated.why : "", /not in the transcript around the quote/);
+ const grounded = decideMeaning(A({ speaker: "someone he reads or plays", sentence: "overstated", fix: "The host reads a tweet that says episode 5 misses power scaling; he calls it a great point." }), shad);
+ assert.deepEqual([grounded.action, grounded.action !== "drop" && grounded.sentence], ["rewrite", "He reads a tweet that says episode 5 misses power scaling; he calls it a great point."]);
+ // "reads it out" is reading: the same rule, even when the model says "host".
+ assert.equal(decideMeaning(A({ stance: "reads it out", sentence: "supported" }), shad).action, "drop");
+});
+
+test("reversed: dropped (D0 a k09: 'his coffee company dropped a sponsorship' — Trade Coffee dropped its sponsorship of him)", () => {
+ const d = decideMeaning(A({ sentence: "reversed", fix: "He says Trade Coffee dropped its sponsorship of him." }), {
+ sentence: "Jeremy states that his coffee company dropped a sponsorship worth thousands of dollars.",
+ quote: "trade coffees dropped a sponsorship",
+ });
+ assert.equal(d.action, "drop");
+});
+
+test("overstated: the fix replaces the sentence when the lint passes, else dropped", () => {
+ const o = { sentence: "Jeremy says the show will be cancelled.", quote: "I think the show is going to get cancelled" };
+ const good = decideMeaning(A({ sentence: "overstated", fix: "He says he thinks the show is going to get cancelled." }), o);
+ assert.deepEqual([good.action, good.action !== "drop" && good.sentence], ["rewrite", "He says he thinks the show is going to get cancelled."]);
+ // A fix that drops the hedge fails the lint.
+ const bad = decideMeaning(A({ sentence: "overstated", fix: "He says the show is going to get cancelled maybe." }), { ...o, quote: "I think the show might get cancelled" });
+ assert.equal(bad.action, "drop");
+ assert.equal(decideMeaning(A({ sentence: "overstated", fix: null }), o).action, "drop");
+ assert.equal(decideMeaning(A({ sentence: "overstated", fix: "word ".repeat(31).trim() }), o).action, "drop");
+});
+
+test("unclear: kept, marked check by ear; supported and his own: kept as drafted", () => {
+ const o = { sentence: "Jeremy says the show is tanking.", quote: "the show is tanking in the ratings" };
+ assert.deepEqual(decideMeaning(A({ speaker: "unclear" }), o), { action: "mark", sentence: o.sentence, why: "speaker unclear: check by ear" });
+ assert.equal(decideMeaning(A({ stance: "unclear" }), o).action, "mark");
+ assert.deepEqual(decideMeaning(A({}), o), { action: "keep", sentence: o.sentence, why: "supported, his own words" });
+
+});
+
+test("readMeaning: strict — an unknown value is unclear / overstated; an empty or 'null' fix is null", () => {
+ assert.deepEqual(readMeaning({ speaker: "Jeremy", stance: "maybe", sentence: "fine", fix: "null" }), { speaker: "unclear", stance: "unclear", sentence: "overstated", fix: null });
+ assert.deepEqual(readMeaning(null), { speaker: "unclear", stance: "unclear", sentence: "overstated", fix: null });
+ assert.equal(readMeaning({ speaker: "host", stance: "asserts", sentence: "supported", fix: ' He says "no". ' }).fix, "He says 'no'.");
+});
+
+test("hasBothHalves and the prompt", () => {
+ assert.ok(hasBothHalves("He plays a clip of Disney's CEO that says ratings are up; he says they are lying."));
+ assert.ok(!hasBothHalves("He reads a review that says it is bad."));
+ assert.ok(!hasBothHalves("He says it is bad; he calls it bad."));
+ const p = meaningPrompt({ question: "Q?", host: "Jeremy", before: "it says", quote: "the quote", after: "this is a lie", sentence: "S." });
+ assert.equal(p, "Question: Q?\n\nThe host: Jeremy\n\nBefore the quote: …it says\n\nQUOTE: the quote\n\nAfter the quote: this is a lie…\n\nDrafted sentence: S.");
+});
diff --git a/common/lib/report/draft/tasks/meaning.ts b/common/lib/report/draft/tasks/meaning.ts
@@ -0,0 +1,169 @@
+// 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 <review/post/letter/article/clip> 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<string, unknown>;
+ const pick = <T extends string>(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:";
diff --git a/common/lib/report/draft/tasks/sweep-pipeline.ts b/common/lib/report/draft/tasks/sweep-pipeline.ts
@@ -26,7 +26,10 @@ import { momentHref } from "./links";
import { checkQuotes, convertSweepText, dropFailedFindings } from "./quotes";
import { TaskInputError, runOnIteration, type TaskHandle, type TaskOutcome } from "./run";
import { CoverageTally, enumerateOf, traceReport } from "./trace";
-import { MIN_KEPT, onTopicBy, quoteContext } from "./claimChecks";
+import { lintClaim, MIN_KEPT, onTopicBy, quoteContext } from "./claimChecks";
+import { CHECK_BY_EAR, decideMeaning, MEANING_SCHEMA, MEANING_SYSTEM, meaningPrompt, readMeaning, type MeaningAnswer, type MeaningDecision } from "./meaning";
+
+export { lintClaim };
import {
cleanTerms,
normalizeTerm,
@@ -53,14 +56,14 @@ export const MAX_CLAIMS_PER_VIDEO = 6;
export const MIN_QUOTE_WORDS = 7;
export const MAX_QUOTE_WORDS = 60;
export const READ_BATCH = 8;
+// The meaning check's budget: one call per kept item, at most this many.
+export const MAX_MEANING_CHECKS = 60;
const STOP = new Set(
"what when where which about with from that this have said says their there they them were been into over under more most some such than then also just like make made making".split(
" ",
),
);
-const HEDGES = ["allegedly", "reportedly", "claims", "claimed", "may", "might", "maybe", "if", "probably", "likely", "i think", "apparently", "supposedly", "rumor", "rumour"];
-const NEGATIONS = /\b(never|not|no|nobody|nothing|none|neither|nor|cannot|without)\b|n't\b/i;
export const TERMS_SYSTEM =
"You plan keyword searches over automatic speech-recognition transcripts of streams and videos. Given a research " +
@@ -268,27 +271,6 @@ export function locate(quote: string, chunk: readonly [number, string][]): numbe
return sec;
}
-export function lintClaim(claim: string, quote: string): string[] {
- const flags: string[] = [];
- const qn = quote.toLowerCase();
- const cn = claim.toLowerCase();
- if (NEGATIONS.test(qn) && !NEGATIONS.test(cn)) flags.push("negation: the quote has a not/never/no the claim does not");
- if (!NEGATIONS.test(qn) && NEGATIONS.test(cn)) flags.push("negation: the claim has a not/never/no the quote does not");
- for (const h of HEDGES) {
- const re = new RegExp(`\\b${h.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
- if (re.test(qn) && !re.test(cn)) {
- flags.push(`hedge dropped: the quote says “${h}”`);
- break;
- }
- }
- for (const num of claim.match(/\d[\d,.]*/g) ?? []) {
- if (!quote.includes(num.replace(/[.,]+$/, ""))) {
- flags.push(`number ${num} is not in the quote`);
- break;
- }
- }
- return flags;
-}
// ─── The run ───
@@ -308,6 +290,10 @@ type Kept = {
before: string;
after: string;
gate: string;
+ // The meaning check's answer and what code made of it (D2 item 3); `mark`:
+ // kept, "check by ear".
+ meaning?: { answer: MeaningAnswer; decision: MeaningDecision; seconds: number; drafted: string };
+ mark?: boolean;
};
export async function sweepPipeline(input: SweepPipelineInput, deps: TaskDeps): Promise<TaskResult> {
@@ -665,11 +651,11 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
// report padded with what is off it (a restricted sweep, a refresh's, keeps
// even one).
const minKept = only?.length ? 1 : MIN_KEPT;
- if (kept.length < minKept) {
+ const nothingFound = async (stage: string) => {
const offQuestion = dropped.filter((d) => d.why.startsWith("off the question")).length;
const sentence =
`Nothing usable found: ${readIds.length} recording(s) read of ${nEnum} matching ${terms.join(", ")}; ` +
- `${kept.length} passage(s) were verbatim and on the question${offQuestion ? ` (${offQuestion} more were verbatim but off it)` : ""}, ` +
+ `${kept.length} passage(s) ${stage}${offQuestion ? ` (${offQuestion} more were verbatim but off it)` : ""}, ` +
`fewer than the ${minKept} a report needs.`;
h.check({ name: "evidence", ok: true, detail: sentence });
h.trace({ t: "note", text: sentence });
@@ -693,13 +679,60 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
await writeIterationFile(h.article, h.n, "sweep.md", md, h.paths);
const c = await convertSweepText(md, { id: h.article, title, cuesOf: deps.cuesOf, postChannelOf: deps.postChannelOf });
if (c.ok) await writeIterationFile(h.article, h.n, "report.json", c.report, h.paths);
- return { status: "done", summary: sentence };
+ return { status: "done" as const, summary: sentence };
+ };
+ if (kept.length < minKept) return nothingFound("were verbatim and on the question");
+
+ // 3b. the meaning check (D2 item 3): one call per kept item, with the
+ // transcript around its quote; code decides from the answer. Its answer is
+ // kept beside the item (items.jsonl: the prompt, the answer, the decision,
+ // the seconds).
+ kept.sort((a, b) => b.strength - a.strength || a.date.localeCompare(b.date) || a.video.localeCompare(b.video) || a.sec - b.sec);
+ const host = askedAboutName(question) ?? "the channel's host (its own voice)";
+ const toCheck = kept.slice(0, MAX_MEANING_CHECKS);
+ const unchecked = kept.length - toCheck.length;
+ const items: Record<string, unknown>[] = [];
+ const tally: Record<string, number> = {};
+ const passed: Kept[] = [];
+ for (const r of toCheck) {
+ deps.signal?.throwIfAborted();
+ const user = meaningPrompt({ question, host, before: r.before, quote: r.quote, after: r.after, sentence: r.claim });
+ const t0 = Date.now();
+ let answer: MeaningAnswer;
+ try {
+ answer = readMeaning(await ask(h, model, MEANING_SYSTEM, user, MEANING_SCHEMA, `meaning ${r.video}@${r.sec}`));
+ } catch (e) {
+ if (deps.signal?.aborted) throw e;
+ tally["check failed"] = (tally["check failed"] ?? 0) + 1;
+ dropped.push({ video: r.video, quote: r.quote, why: `meaning check failed: ${(e as Error).message}` });
+ items.push({ video: r.video, sec: r.sec, quote: r.quote, claim: r.claim, gate: r.gate, before: r.before, after: r.after, prompt: user, error: (e as Error).message, decision: { action: "drop", why: "the meaning check failed" } });
+ continue;
+ }
+ const seconds = Math.round((Date.now() - t0) / 100) / 10;
+ const decision = decideMeaning(answer, { sentence: r.claim, quote: r.quote, before: r.before, after: r.after });
+ tally[decision.action] = (tally[decision.action] ?? 0) + 1;
+ items.push({ video: r.video, sec: r.sec, quote: r.quote, claim: r.claim, gate: r.gate, before: r.before, after: r.after, prompt: user, answer, decision, seconds });
+ h.trace({ t: "meaning", video: r.video, sec: r.sec, quote: r.quote, answer, action: decision.action, why: decision.why, ...(decision.action !== "drop" && decision.sentence !== r.claim ? { from: r.claim, to: decision.sentence } : {}), seconds });
+ if (decision.action === "drop") {
+ dropped.push({ video: r.video, quote: r.quote, why: `meaning check: ${decision.why}` });
+ event({ kind: "dropped", why: `meaning check: ${decision.why}`, video: r.video, quote: r.quote, claim: r.claim });
+ continue;
+ }
+ passed.push({ ...r, claim: decision.sentence.replace(/"/g, "'"), meaning: { answer, decision, seconds, drafted: r.claim }, ...(decision.action === "mark" ? { mark: true } : {}) });
}
+ await writeIterationFile(h.article, h.n, "items.jsonl", items.map((x) => JSON.stringify(x)).join("\n") + (items.length ? "\n" : ""), h.paths);
+ const tallyLine = Object.entries(tally).map(([k, n]) => `${n} ${k === "mark" ? "marked check by ear" : k === "keep" ? "kept" : k === "rewrite" ? "rewritten" : k === "drop" ? "dropped" : k}`).join(", ");
+ h.log(`meaning check: ${toCheck.length} item(s): ${tallyLine}${unchecked ? `; ${unchecked} past the budget of ${MAX_MEANING_CHECKS} not checked (left out)` : ""}`);
+ h.check({ name: "meaning", ok: !tally["check failed"], detail: `${toCheck.length} checked: ${tallyLine}${unchecked ? `; ${unchecked} not checked` : ""}` });
+ kept.splice(0, kept.length, ...passed);
+ if (kept.length < minKept) return nothingFound("were verbatim, on the question and passed the meaning check");
// 4. group and title (the model); counts, balance and caps in code
- kept.sort((a, b) => b.strength - a.strength || a.date.localeCompare(b.date) || a.video.localeCompare(b.video) || a.sec - b.sec);
+ // "Check by ear" items are never grouped (never in the first section):
+ // they are a last section of their own.
+ const marked = kept.filter((r) => r.mark).slice(0, MAX_CLAIMS_PER_SECTION);
const perVideo = new Map<string, number>();
- const trimmed = kept.filter((r) => {
+ const trimmed = kept.filter((r) => !r.mark).filter((r) => {
perVideo.set(r.video, (perVideo.get(r.video) ?? 0) + 1);
return perVideo.get(r.video)! <= MAX_CLAIMS_PER_VIDEO;
});
@@ -708,7 +741,7 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
.sort((a, b) => a.date.localeCompare(b.date) || a.video.localeCompare(b.video) || a.sec - b.sec);
const listing = pool.map((r, i) => `${i + 1}. (${r.date}) ${r.claim}`).join("\n");
let best: { score: number; g: { title?: unknown; sections?: unknown } } | null = null;
- for (let attempt = 0; attempt < 2; attempt++) {
+ for (let attempt = 0; attempt < (pool.length ? 2 : 0); attempt++) {
let g: { title?: unknown; sections?: unknown };
try {
g = await ask(h, model, GROUP_SYSTEM, `Research question: ${question}\n\nFindings:\n${listing}`, GROUP_SCHEMA, `group#${attempt + 1}`, true);
@@ -744,7 +777,7 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
const rest = pool.map((_, i) => i + 1).filter((n) => !home.has(n));
if (rest.length) sections.push({ heading: "Other findings", nums: rest });
sections = sections.filter((s) => s.nums.length);
- let leftOut = kept.length - pool.length;
+ let leftOut = kept.length - pool.length - marked.length + unchecked;
for (const s of sections) {
s.nums.sort((a, b) => pool[b - 1]!.strength - pool[a - 1]!.strength || pool[a - 1]!.date.localeCompare(pool[b - 1]!.date) || pool[a - 1]!.sec - pool[b - 1]!.sec);
if (s.nums.length > MAX_CLAIMS_PER_SECTION) {
@@ -765,6 +798,7 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
secs = secs.map((s, si) => ({ heading: s.heading, recs: s.recs.filter((_, ri) => keep.has(`${si}:${ri}`)) })).filter((s) => s.recs.length);
leftOut += total - maxClaims;
}
+ if (marked.length) secs.push({ heading: "To check by ear", recs: marked });
for (const s of secs) s.recs.sort((a, b) => a.date.localeCompare(b.date) || a.sec - b.sec);
// 5. the markdown, convert, the strict check (a failing finding is dropped)
@@ -883,7 +917,7 @@ function writeMarkdown(
const md = [`# ${c.title}`, "", `Question: ${c.question}`, ""];
for (const s of secs) {
md.push(`## ${s.heading}`, "");
- for (const r of s.recs) md.push(`- ${r.claim} "${r.quote}" — [${citeLabel(r)}](${momentHref(c.origin, r.slug, r.video, r.sec)})`);
+ for (const r of s.recs) md.push(`- ${r.mark ? `${CHECK_BY_EAR} ` : ""}${r.claim} "${r.quote}" — [${citeLabel(r)}](${momentHref(c.origin, r.slug, r.video, r.sec)})`);
md.push("");
}
const scope = c.channels.join(", ") + (c.since ? `, from ${c.since}` : "") + (c.until ? ` to ${c.until}` : "");
@@ -993,3 +1027,9 @@ function writeNothing(
"",
].join("\n");
}
+
+// The person the question asks about, as written ("Jeremy"), or null.
+function askedAboutName(question: string): string | null {
+ const m = /\b(?:has|have|does|do|did|is|was)\s+((?:[A-Z][\w'’.-]*\s+){0,2}[A-Z][\w'’.-]*?)(?:['’]s)?\s+(?:ever\s+|really\s+)?(?:said|say|think|thought|felt|feel|talked|talk|claimed|argued|told|stated|reacted|commented)\b/.exec(question);
+ return m ? m[1]!.trim() : null;
+}
diff --git a/common/lib/report/draft/tasks/trace.ts b/common/lib/report/draft/tasks/trace.ts
@@ -14,6 +14,7 @@
// {t: "check", quote, cite, ok, reason?, stage, dropped?}
// {t: "finding", section, claim, cites}
// {t: "select", scope, terms, rare, candidates, read} what the pipeline reads and why (demo D2)
+// {t: "meaning", video, sec, quote, answer, action, why, from?, to?, seconds} an item's meaning check (D2)
// {t: "note", text}
// {t: "run", phase: "end", status, summary, usd, minutes, coverage?}
//
@@ -93,6 +94,18 @@ export type TraceInput =
}
| { t: "terms"; terms: string[]; extra?: boolean; topic?: string; dropped?: { term: string; why: string }[]; asked?: "again" }
| {
+ t: "meaning";
+ video: string;
+ sec: number;
+ quote: string;
+ answer: { speaker: string; stance: string; sentence: string; fix: string | null };
+ action: "keep" | "rewrite" | "mark" | "drop";
+ why: string;
+ from?: string;
+ to?: string;
+ seconds: number;
+ }
+ | {
t: "select";
scope: number;
terms: { term: string; videos: number; partial: boolean; idf: number; nominates: boolean }[];
diff --git a/common/lib/report/iterations.ts b/common/lib/report/iterations.ts
@@ -80,7 +80,10 @@ export type IterationStepStatus = (typeof ITERATION_STEP_STATUSES)[number];
// draft/tasks/trace.ts) — one JSON object a line, like turns.jsonl.
// `refresh.json`: a refresh's fetches, build and delta (umtool R4,
// draft/refresh/types.ts RefreshFile).
-export const ITERATION_FILES = ["report.json", "sweep.md", "turns.jsonl", "proposals.json", "seed.md", "trace.jsonl", "refresh.json"] as const;
+// `items.jsonl`: a local sweep's checked items, one a line — each quote with
+// the transcript around it, its gate, the meaning check's prompt, answer,
+// decision and seconds (demo epic D2; what the model log shows).
+export const ITERATION_FILES = ["report.json", "sweep.md", "turns.jsonl", "proposals.json", "seed.md", "trace.jsonl", "refresh.json", "items.jsonl"] as const;
export type IterationFile = (typeof ITERATION_FILES)[number];
// A revision needs something to revise (and feedback saying how); a refresh
diff --git a/common/testing/draft/runs/sweep-pipeline.json b/common/testing/draft/runs/sweep-pipeline.json
@@ -23,6 +23,27 @@
{
"message": {
"role": "assistant",
+ "content": "{\"speaker\": \"host\", \"stance\": \"asserts\", \"sentence\": \"supported\", \"fix\": \"\"}"
+ },
+ "done": true
+ },
+ {
+ "message": {
+ "role": "assistant",
+ "content": "{\"speaker\": \"host\", \"stance\": \"asserts\", \"sentence\": \"overstated\", \"fix\": \"She says the judges were friends of hers, so entering felt wrong to her.\"}"
+ },
+ "done": true
+ },
+ {
+ "message": {
+ "role": "assistant",
+ "content": "{\"speaker\": \"host\", \"stance\": \"unclear\", \"sentence\": \"supported\", \"fix\": \"\"}"
+ },
+ "done": true
+ },
+ {
+ "message": {
+ "role": "assistant",
"content": "{\"title\":\"The baker and the pie contest\",\"sections\":[{\"heading\":\"Why she stayed out\",\"findings\":[1,2]}]}"
},
"done": true
diff --git a/mcp/src/draftTasks.test.ts b/mcp/src/draftTasks.test.ts
@@ -322,6 +322,15 @@ test("sweep-pipeline: terms, enumerate, windows, extract (a non-verbatim quote d
assert.match(md, /## Why she stayed out/);
assert.ok(md.includes(`${ORIGIN}/?v=synth-kitchen%2Fpie-stream-02&t=10`));
assert.ok(md.includes("next year maybe I will enter again"));
+ // The meaning check (D2 item 3): one call per item; an overstated sentence
+ // replaced by its fix; an unclear stance marked, in a last section of its own.
+ assert.ok(md.includes("- She says the judges were friends of hers, so entering felt wrong to her. \"the judges were friends of mine so it felt wrong\""));
+ assert.match(md, /## To check by ear\n\n- Check by ear: She says she may enter again next year\. "next year maybe I will enter again"/);
+ assert.ok(md.indexOf("## Why she stayed out") < md.indexOf("## To check by ear"));
+ const items = (await readIterationFile("synth-pipe", it.n, "items.jsonl", paths))!.trim().split("\n").map((l) => JSON.parse(l));
+ assert.deepEqual(items.map((x) => x.decision.action), ["keep", "rewrite", "mark"]);
+ assert.match(items[0].prompt, /^Question: Did the baker enter the pie contest\?\n\nThe host: the channel's host \(its own voice\)\n\nBefore the quote: …good evening chat welcome to the pie stream a lot of you asked about the contest\n\nQUOTE: I did not enter the contest this year\n\nAfter the quote: the judges/);
+ assert.ok(items.every((x) => typeof x.seconds === "number" && x.answer.speaker === "host"));
assert.match(md, /## Coverage\n\nSearched synth-kitchen for contest, judges\. 1 video\(s\) matched; 1 read/);
// The job's progress: the recordings gone through, of the worklist (release 28 F3).
assert.deepEqual(d.progressed, [{ metric: "entries", current: 0, total: 1 }, { metric: "entries", current: 1, total: 1 }]);
@@ -331,7 +340,7 @@ test("sweep-pipeline: terms, enumerate, windows, extract (a non-verbatim quote d
assert.ok(turns.some((t) => t.kind === "enumerate" && t.term === "contest"));
const after = (await readIteration("synth-pipe", it.n, paths))!;
assert.equal(after.usage["qwen3:8b"]!.usd, 0);
- assert.equal(after.usage["qwen3:8b"]!.calls, 3);
+ assert.equal(after.usage["qwen3:8b"]!.calls, 6);
// The trace (umtool R3): scope, terms, an enumeration per term, the read
// batch with the model's lines, the quote dropped in its window and why,