commit cade127d35e4ebf57543e8c24851b911cd4a336e
parent 6e5558c6a79ee2ee2a2c26c2f0d83cbf0d781a5d
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 10:21:39 -0500
sweep-pipeline: an on-topic gate in code, and "nothing usable found" (D2 item 2)
With nothing on the subject read, the extractor still marked 100-200 items
on topic and grouping gave them section names (D0: 39 of the Acolyte run's
40 kept claims were off the question). The model's on_topic flag is now
advisory: code keeps an item only when its quote, or the 300 characters of
transcript before it, holds one of the question's rare terms (the
nominating terms at most 5% of the scope, and always the rarest) or the
topic the model named. The window's own words around each quote (400
before, 150 after) are kept on the item for the meaning check.
Fewer than three items on the question is the result "nothing usable
found": one sentence saying what was searched and read, the coverage, no
grouping call, never padded. A restricted sweep (a refresh's) keeps even
one.
Replayed over the D0 sample (177 claims graded by Fable): the gate drops
92 of the 113 off-topic claims (all 39 in the Acolyte run, all 9 in the
coffee run) and 23 of the 47 supported ones (mostly the Magic question,
where a quote says "Wizards" or "Magic" alone).
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
6 files changed, 255 insertions(+), 16 deletions(-)
diff --git a/common/lib/report/draft/tasks/claimChecks.test.ts b/common/lib/report/draft/tasks/claimChecks.test.ts
@@ -0,0 +1,36 @@
+// Item 2's gate and the text around a quote (demo epic D2), on cases from the
+// D0 sample.
+
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { onTopicBy, quoteContext } from "./claimChecks";
+
+const WIN: [number, string][] = [
+ [0, "so let's check in on the Rotten Tomato score for the acolyte"],
+ [3, "we see it is sitting at a Wonder"],
+ [8, "26% audience score not shocking at all"],
+ [12, "um the show is you know basically"],
+ [15, "getting mocked into Oblivion by anybody"],
+];
+
+test("quoteContext: the transcript's own words before and after a verbatim quote, cut at a word", () => {
+ const c = quoteContext(WIN, "26% audience score not shocking at all um the show", { before: 40, after: 20 })!;
+ assert.equal(c.before, "acolyte we see it is sitting at a Wonder");
+ assert.equal(c.after, "is you know");
+ // Punctuation and case do not matter; a quote that is not there is null.
+ assert.ok(quoteContext(WIN, "Getting mocked into oblivion"));
+ assert.equal(quoteContext(WIN, "never said this"), null);
+});
+
+test("onTopicBy: the rare term in the quote or the 300 characters before it; the topic counts too", () => {
+ const before = quoteContext(WIN, "26% audience score not shocking at all")!.before;
+ assert.equal(onTopicBy({ quote: "26% audience score not shocking at all", before, terms: ["acolyte"] }), "acolyte");
+ // 300 characters of something else in between: off the question.
+ const far = `the acolyte ${"word ".repeat(70)}`;
+ assert.equal(onTopicBy({ quote: "26% audience score not shocking at all", before: far, terms: ["acolyte"] }), null);
+ // A 2019 Ghostbusters video naming Star Wars in passing (D0 d k01): no.
+ assert.equal(onTopicBy({ quote: "maybe it was Jurassic Park maybe it was Star Wars", before: "think about your favorite film franchise", terms: ["acolyte"] }), null);
+ assert.equal(onTopicBy({ quote: "Disney's new show The Acolyte is out", before: "", terms: ["lightsaber"], topic: "the acolyte" }), "the acolyte");
+ // Words, not substrings.
+ assert.equal(onTopicBy({ quote: "the acolytes of the cult", before: "", terms: ["acolyte"] }), null);
+});
diff --git a/common/lib/report/draft/tasks/claimChecks.ts b/common/lib/report/draft/tasks/claimChecks.ts
@@ -0,0 +1,84 @@
+// What code checks of a local sweep's item once its quote is verbatim (demo
+// epic D2): the text around the quote in its transcript window, and whether
+// the item is ON the question (item 2's gate).
+//
+// D0 (11 Nov 2026): with nothing on the subject read, the extractor still
+// marked 100-200 items on topic, and grouping named sections for them; 39 of
+// the Acolyte run's 40 kept claims were off the question. The model's own
+// `on_topic` is advisory: an item is kept only when its quote, or the 300
+// characters before it, holds one of the question's rare terms (or the topic
+// the model named) — what code can see.
+
+import { strictNormalize } from "../../../citations/verify";
+
+type Win = readonly (readonly [number, string])[];
+
+// The window's words, each with its normalized tokens (a raw word may
+// normalize to none, or to two: "rock-bottom").
+function tokensOf(win: Win): { raw: string[]; norm: string[]; owner: number[] } {
+ const raw: string[] = [];
+ const norm: string[] = [];
+ const owner: number[] = [];
+ for (const [, text] of win) {
+ for (const w of text.split(/\s+/)) {
+ if (!w) continue;
+ raw.push(w);
+ for (const t of strictNormalize(w).split(" ")) {
+ if (!t) continue;
+ norm.push(t);
+ owner.push(raw.length - 1);
+ }
+ }
+ }
+ return { raw, norm, owner };
+}
+
+export type QuoteContext = { before: string; after: string };
+
+// The transcript's own words before and after a verbatim quote in its window
+// (at most `before` / `after` characters, cut at a word); null when the quote
+// is not in it.
+export function quoteContext(win: Win, quote: string, o: { before?: number; after?: number } = {}): QuoteContext | null {
+ const q = strictNormalize(quote).split(" ").filter(Boolean);
+ if (!q.length) return null;
+ const { raw, norm, owner } = tokensOf(win);
+ let at = -1;
+ for (let i = 0; i + q.length <= norm.length && at < 0; i++) {
+ let ok = true;
+ for (let j = 0; j < q.length && ok; j++) ok = norm[i + j] === q[j];
+ if (ok) at = i;
+ }
+ if (at < 0) return null;
+ const first = owner[at]!;
+ const last = owner[at + q.length - 1]!;
+ const take = (words: string[], max: number, fromEnd: boolean) => {
+ const out: string[] = [];
+ let n = 0;
+ const list = fromEnd ? [...words].reverse() : words;
+ for (const w of list) {
+ if (n + w.length + (out.length ? 1 : 0) > max) break;
+ out.push(w);
+ n += w.length + (out.length > 1 ? 1 : 0);
+ }
+ return (fromEnd ? out.reverse() : out).join(" ");
+ };
+ return { before: take(raw.slice(0, first), o.before ?? 400, true), after: take(raw.slice(last + 1), o.after ?? 150, false) };
+}
+
+export const GATE_CHARS = 300;
+
+// The question's term (or the topic) the item shows, in its quote or the
+// GATE_CHARS before it; null when it shows none — the item is off the question.
+export function onTopicBy(o: { quote: string; before: string; terms: readonly string[]; topic?: string }): string | null {
+ const before = o.before.length > GATE_CHARS ? o.before.slice(o.before.length - GATE_CHARS).replace(/^\S*\s/, "") : o.before;
+ const text = ` ${strictNormalize(`${before} ${o.quote}`)} `;
+ for (const t of [...o.terms, ...(o.topic ? [o.topic] : [])]) {
+ const k = strictNormalize(t);
+ if (k && text.includes(` ${k} `)) return t;
+ }
+ return null;
+}
+
+// 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;
diff --git a/common/lib/report/draft/tasks/selection.ts b/common/lib/report/draft/tasks/selection.ts
@@ -152,12 +152,12 @@ export function termStats(counts: readonly TermCount[], scopeSize: number): Term
export const usableTerms = (stats: readonly TermStat[]) => stats.filter((s) => s.videos > 0 && !s.common);
// The terms a kept item must show (item 2's gate): the nominating terms at
-// most RARE_SHARE of the scope, and always the rarest nominating one.
+// most RARE_SHARE of the scope, and always the rarest nominating one(s).
export function rareTermsOf(stats: readonly TermStat[]): string[] {
const nom = stats.filter((s) => s.nominates);
const rare = nom.filter((s) => s.share <= RARE_SHARE).map((s) => s.term);
- const rarest = [...nom].sort((a, b) => a.videos - b.videos)[0];
- if (rarest && !rare.includes(rarest.term)) rare.push(rarest.term);
+ const least = Math.min(...nom.map((s) => s.videos));
+ for (const s of nom) if (s.videos === least && !rare.includes(s.term)) rare.push(s.term);
return rare;
}
diff --git a/common/lib/report/draft/tasks/sweep-pipeline.ts b/common/lib/report/draft/tasks/sweep-pipeline.ts
@@ -26,8 +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 {
cleanTerms,
+ normalizeTerm,
readingSet,
readingSize,
rareTermsOf,
@@ -301,6 +303,11 @@ type Kept = {
sec: number;
strength: number;
flags: string[];
+ // The transcript around the quote (400 characters before, 150 after) and
+ // the question's term the gate found in it (D2 item 2).
+ before: string;
+ after: string;
+ gate: string;
};
export async function sweepPipeline(input: SweepPipelineInput, deps: TaskDeps): Promise<TaskResult> {
@@ -447,6 +454,8 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
terms = usable.map((s) => s.term);
if (!terms.length) return { status: "failed", summary: `no usable search terms (${droppedTerms.map((d) => `${d.term}: ${d.why}`).join("; ")})` };
const statMap = new Map(usable.map((st) => [st.term, st]));
+ // The topic the model named, as the gate reads it (the subject's names off).
+ topic = normalizeTerm(topic, names);
const rare = rareTermsOf(usable);
h.trace({
t: "note",
@@ -611,6 +620,12 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
else if (raw.on_topic === false || (Number(raw.strength) || 2) < 2) why = "model: not on topic";
const key = norm(quote);
if (!why && kept.some((k) => k.video === v.id && (norm(k.quote).includes(key) || key.includes(norm(k.quote))))) why = "duplicate";
+ // The gate (D2 item 2): the question's rare term (or the topic)
+ // in the quote or the 300 characters before it — code's call,
+ // whatever the model's on_topic said.
+ const around = !why ? quoteContext(win, quote, { before: 400, after: 150 }) : null;
+ const gate = around ? onTopicBy({ quote, before: around.before, terms: rare, ...(topic ? { topic } : {}) }) : null;
+ if (!why && !gate) why = `off the question: no ${rare.map((t) => `“${t}”`).join(" or ")}${topic && !rare.includes(topic) ? ` or “${topic}”` : ""} in the quote or the 300 characters before it`;
const at = sec ?? ch[0]![0];
batchLines.push(`${v.id} @ ${mmss(at)} “${quote}” — ${claim || "(no claim)"}${why ? ` [dropped: ${why}]` : ""}`);
if (why) {
@@ -631,6 +646,9 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
sec: sec!,
strength: Math.round(Number(raw.strength) || 2),
flags: lintClaim(claim, quote),
+ before: around!.before,
+ after: around!.after,
+ gate: gate!,
});
}
}
@@ -643,9 +661,39 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T
h.trace({ t: "batch", k, of: batches, ids: batch.map((v) => v.id), lines: batchLines, model, usd });
h.trace({ t: "cost", step: `batch ${k}`, usd, model, total: h.meter.usd });
}
- if (!kept.length) {
- h.check({ name: "evidence", ok: false, detail: `${nEnum} matched, ${readIds.length} read, ${dropped.length} quote(s) dropped` });
- return { status: "failed", summary: "no verbatim evidence found — nothing to report" };
+ // Too little on the question is a result, said in one sentence — never a
+ // 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 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)` : ""}, ` +
+ `fewer than the ${minKept} a report needs.`;
+ h.check({ name: "evidence", ok: true, detail: sentence });
+ h.trace({ t: "note", text: sentence });
+ const title = question.replace(/["“”#]/g, "").trim().slice(0, 90);
+ const md = writeNothing(sentence, {
+ question,
+ title,
+ channels,
+ terms,
+ since,
+ until,
+ nEnum,
+ read: readIds.length,
+ nChunks,
+ nRelevant,
+ dropped: dropped.length,
+ partial,
+ todo: todo.length,
+ model,
+ });
+ 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 };
}
// 4. group and title (the model); counts, balance and caps in code
@@ -904,3 +952,44 @@ function yearSpread(vids: readonly { date: string }[]): string {
}
return [...by.entries()].sort().map(([y, n]) => `${y}:${n}`).join(" ");
}
+
+// "Nothing usable found": the question, the one sentence, and what was
+// searched and read.
+function writeNothing(
+ sentence: string,
+ c: {
+ question: string;
+ title: string;
+ channels: string[];
+ terms: string[];
+ since?: string;
+ until?: string;
+ nEnum: number;
+ read: number;
+ nChunks: number;
+ nRelevant: number;
+ dropped: number;
+ partial: string[];
+ todo: number;
+ model: string;
+ },
+): string {
+ const scope = c.channels.join(", ") + (c.since ? `, from ${c.since}` : "") + (c.until ? ` to ${c.until}` : "");
+ return [
+ `# ${c.title}`,
+ "",
+ `Question: ${c.question}`,
+ "",
+ "## Nothing usable found",
+ "",
+ sentence,
+ "",
+ "## Coverage",
+ "",
+ `Searched ${scope} for ${c.terms.join(", ")}. ${c.nEnum} video(s) matched; ${c.read} read (${c.nChunks} excerpt(s), ` +
+ `${c.nRelevant} judged relevant); ${c.dropped} quote(s) dropped. Drafted by ${c.model}.` +
+ (c.partial.length ? ` COVERAGE PARTIAL for: ${c.partial.join(", ")}.` : "") +
+ (c.nEnum > c.todo ? ` Only ${c.todo} of the ${c.nEnum} matching videos were read.` : ""),
+ "",
+ ].join("\n");
+}
diff --git a/common/testing/draft/runs/sweep-pipeline.json b/common/testing/draft/runs/sweep-pipeline.json
@@ -16,7 +16,7 @@
{
"message": {
"role": "assistant",
- "content": "{\"relevant\":true,\"items\":[{\"quote\":\"I did not enter the contest this year\",\"claim\":\"She says she did not enter the contest this year.\",\"on_topic\":true,\"strength\":3},{\"quote\":\"the judges were friends of mine so it felt wrong\",\"claim\":\"She says the judges were her friends, so entering felt wrong.\",\"on_topic\":true,\"strength\":3},{\"quote\":\"I entered the contest and I won it this year\",\"claim\":\"She says she won.\",\"on_topic\":true,\"strength\":3}]}"
+ "content": "{\"relevant\": true, \"items\": [{\"quote\": \"I did not enter the contest this year\", \"claim\": \"She says she did not enter the contest this year.\", \"on_topic\": true, \"strength\": 3}, {\"quote\": \"the judges were friends of mine so it felt wrong\", \"claim\": \"She says the judges were her friends, so entering felt wrong.\", \"on_topic\": true, \"strength\": 3}, {\"quote\": \"next year maybe I will enter again\", \"claim\": \"She says she may enter again next year.\", \"on_topic\": true, \"strength\": 2}]}"
},
"done": true
},
diff --git a/mcp/src/draftTasks.test.ts b/mcp/src/draftTasks.test.ts
@@ -321,14 +321,13 @@ test("sweep-pipeline: terms, enumerate, windows, extract (a non-verbatim quote d
assert.match(md, /^# The baker and the pie contest/);
assert.match(md, /## Why she stayed out/);
assert.ok(md.includes(`${ORIGIN}/?v=synth-kitchen%2Fpie-stream-02&t=10`));
- assert.ok(!md.includes("I entered the contest and I won"), "the invented quote never made it");
+ assert.ok(md.includes("next year maybe I will enter again"));
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 }]);
const report = JSON.parse((await readIterationFile("synth-pipe", it.n, "report.json", paths))!);
- assert.equal(Object.keys(report.citations).length, 2);
+ assert.equal(Object.keys(report.citations).length, 3);
const turns = (await readIterationFile("synth-pipe", it.n, "turns.jsonl", paths))!.trim().split("\n").map((l) => JSON.parse(l));
- assert.ok(turns.some((t) => t.kind === "dropped" && t.why === "not verbatim in its window"));
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);
@@ -343,16 +342,47 @@ test("sweep-pipeline: terms, enumerate, windows, extract (a non-verbatim quote d
assert.deepEqual(trace.filter((e) => e.t === "enumerate").map((e) => e.query), ["contest", "judges"]);
const batch = trace.find((e) => e.t === "batch")!;
assert.deepEqual([batch.k, batch.of, batch.ids], [1, 1, ["pie-stream-02"]]);
- assert.ok(batch.lines.some((l: string) => l.includes("[dropped: not verbatim in its window]")));
- const drop = trace.find((e) => e.t === "check" && e.dropped)!;
- assert.deepEqual([drop.stage, drop.reason, drop.cite.video], ["extract", "not verbatim in its window", "pie-stream-02"]);
- assert.ok(drop.quote.includes("I entered the contest and I won"));
- assert.equal(trace.filter((e) => e.t === "check" && e.stage === "final").length, 2);
- assert.equal(trace.filter((e) => e.t === "finding").length, 2);
+ assert.equal(trace.filter((e) => e.t === "check" && e.stage === "final").length, 3);
+ assert.equal(trace.filter((e) => e.t === "finding").length, 3);
assert.deepEqual(trace.at(-1)!.status, "done");
assert.deepEqual(after.coverage, { matched: 1, read: 1, partial: false, unreached: [] });
});
+test("sweep-pipeline gate (D2 item 2): an item with no rare term in its quote or the 300 characters before it is dropped; fewer than three is 'nothing usable found', said in one sentence, with no grouping call", async () => {
+ const r = await run("sweep-pipeline");
+ // The terms are given ("judges"): the model is asked to extract only.
+ const turns = structuredClone(r.turns).slice(1, 2);
+ turns[0].message.content = JSON.stringify({
+ relevant: true,
+ items: [
+ { quote: "I did not enter the contest this year", claim: "She says she did not enter the contest this year.", on_topic: true, strength: 3 },
+ { quote: "the judges were friends of mine so it felt wrong", claim: "She says the judges were her friends.", on_topic: true, strength: 3 },
+ { quote: "I entered the contest and I won it this year", claim: "She says she won.", on_topic: true, strength: 3 },
+ ],
+ });
+ ol.push(...turns);
+ const it = await createIteration("synth-gate", { kind: "sweep", model: r.model, question: r.question, scope: { channels: r.channels } }, paths);
+ const d = deps();
+ const out = await runTask({ task: "sweep-pipeline", article: "synth-gate", n: it.n, origin: ORIGIN, terms: ["judges"] }, d);
+ assert.equal(out.status, "done", `${out.summary}\n${d.lines.join("\n")}`);
+ assert.equal(
+ out.summary,
+ "Nothing usable found: 1 recording(s) read of 1 matching judges; 1 passage(s) were verbatim and on the question (1 more were verbatim but off it), fewer than the 3 a report needs.",
+ );
+ assert.equal(ol.remaining(), 0, "no grouping call");
+ const trace = await traceOf("synth-gate", it.n);
+ const drops = trace.filter((e) => e.t === "check" && e.dropped).map((e) => [e.quote, e.reason]);
+ assert.deepEqual(drops, [
+ ["I did not enter the contest this year", "off the question: no “judges” in the quote or the 300 characters before it"],
+ ["I entered the contest and I won it this year", "not verbatim in its window"],
+ ]);
+ const md = (await readIterationFile("synth-gate", it.n, "sweep.md", paths))!;
+ assert.match(md, /## Nothing usable found\n\nNothing usable found: /);
+ assert.ok(!md.includes("the judges were friends"), "never padded with the one item");
+ const report = JSON.parse((await readIterationFile("synth-gate", it.n, "report.json", paths))!);
+ assert.equal(Object.keys(report.citations ?? {}).length, 0);
+});
+
test("sweep-pipeline selection (D2 item 1): the subject's own name and generic words are never searched; the read is traced with its reasons", async () => {
const r = await run("sweep-pipeline");
const turns = structuredClone(r.turns);