Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 77ec863c79c28801796f39708aa47a4a4b232708
parent 5cc00608c2b9765a79fa5988b489fbf3afc188f9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 04:50:19 -0400

common: a new sweep takes a seed (a research board's cited markdown) and starts its report from it

report-draft's `seed` (a new sweep's, on a Claude model) is kept as the
iteration's seed.md; the agent's report file starts as the seed and its first
message says to verify and extend it. Refused with an iteration, a copy, or a
local model (the pipeline writes its report from scratch).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
MCOMMANDS.md | 2+-
Mcommon/controller/reportDraft.ts | 22++++++++++++++++++++++
Mcommon/lib/report/draft/tasks/sweep-agent.ts | 21+++++++++++++++++----
Mcommon/lib/report/iterations.ts | 3++-
Meditor/app/api/ops/_reportDraft.test.ts | 34+++++++++++++++++++++++++++++++++-
Mscripts/archilyzer-ops.mjs | 5++++-
6 files changed, 79 insertions(+), 8 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -145,7 +145,7 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run) | `archive-search` | archive-search searches archive.org (its advanced-search syntax) and answers the items: {"query", "limit"?: 50 (at most 500)} -&gt; {found, items: \[{identifier, title?}\]}, in identifier order. One request through the editor's archive.org client, paced and backed off as an import is. Read only; import-archive-org with "query" imports what a search finds. | `pnpm ops archive-search --json '{"query":"title:(kitchen) AND mediatype:movies","limit":20}'` | | `archive-item` | archive-item answers one archive.org item's files from its metadata: {"item"} -&gt; {item: {identifier, url, title?, date?, mediatype?, creator?, collections, restricted, mediaFiles, mediaBytes, files: \[{name, format?, source?, size?, seconds?, media, restricted, original?}\]}}. media marks the originals an import takes (one record each); restricted, what archive.org will not hand out. Read only; nothing is downloaded. | `pnpm ops archive-item --json '{"item":"example-item"}'` | | `import-post` | import-post imports ONE post by its URL into a posts channel of its platform: {"slug", "url"} — an X status (x.com/&lt;handle&gt;/status/&lt;id&gt;) or a Bluesky post (bsky.app/profile/&lt;handle&gt;/post/&lt;id&gt;, or its at:// URI). Read through the channel's own fetcher (gallery-dl for X, with the channel's login; the public AppView for Bluesky) as an import-post job on the platform's queue. Refused, before any job: a URL that is not a post, a channel that is not a posts channel of that platform or whose fetcher cannot read one post, a post the URL names as another account's, the platform held or cooling down. A post already archived is not read again; one the platform says is another account's is not written. The log ends with @@import-post {ok, slug, url, id, written, already?, post?, error?}. | `pnpm ops import-post --json '{"slug":"demo-x","url":"https://x.com/example/status/1700000000000000001"}' --wait` | -| `report-draft` | report-draft runs a generation over an article's iteration as a report-draft job: {"task": "sweep" \| "revise-report" \| "revise-video" \| "research" \| a media draft, "article", ...} -&gt; {jobId, iteration, warnings?}. A sweep takes "question" and "channels" (and "from"/"to"): a new iteration; a revision takes "iteration" (the one it revises) and "feedback": a new iteration. A media draft — "narrate", "cut", "onscreen", "teaser", "flips", "threads", "youtube" — takes "iteration" (a done one; "entries"? entry ids, "force"? re-drafts a field that is a draft already; narrate "cards"?) and is a step on it: it drafts fields of the iteration's video manifest, never one the operator wrote. "copyOf" N runs iteration N again on "model". "extractorModel" is an API sweep's extractor (a Claude model id; default settings.generation.models.extractor). "model" defaults to settings.generation's route for the task (one routed to code needs a model named). A Claude model runs on draft:api, capped at "maxUsd" (default by task, never above caps.max), and is refused when the day's API total has reached caps.daily; a local model runs on draft:local, through the GPU arbiter, and is unloaded when it ends. The corpus is "source" (a handle), "build" (a composed build), or the newest build holding the channels. `job cancel <id>` stops it. The log ends with @@report-draft {article, iteration, task, status, summary, usd, minutes}; --wait prints it. A research run takes "question" ("channels"? "from"/"to"?) and "autonomy" (propose \| limits \| auto; default settings.generation.research): it searches the corpus, the web and archive.org and proposes acquisitions (archive.org imports, videos, new channels — always on no site —, posts, transcription, persisting), each with its reason and evidence, enqueuing what its autonomy and the settings' caps allow through the editor's own actions; the rest waits in the iteration's proposals.json. A sweep with "iteration" N CONTINUES research run N: its question, over its channels and every channel a done acquisition wrote into, the sweep's parent N; refused while N still waits, unless "force" (what is done so far). | `pnpm ops report-draft --json '{"task":"sweep","article":"demo-article","question":"What does she say about the shop?","channels":["demo-channel"]}' --wait`<br>`pnpm ops report-draft --json '{"task":"revise-report","article":"demo-article","iteration":1,"feedback":"Drop the second finding."}'`<br>`pnpm ops report-draft --json '{"task":"research","article":"demo-article","question":"Where did the shop story start?","autonomy":"propose"}' --wait`<br>`pnpm ops report-draft --json '{"task":"sweep","article":"demo-article","iteration":1}'` | +| `report-draft` | report-draft runs a generation over an article's iteration as a report-draft job: {"task": "sweep" \| "revise-report" \| "revise-video" \| "research" \| a media draft, "article", ...} -&gt; {jobId, iteration, warnings?}. A sweep takes "question" and "channels" (and "from"/"to"): a new iteration; a revision takes "iteration" (the one it revises) and "feedback": a new iteration. A media draft — "narrate", "cut", "onscreen", "teaser", "flips", "threads", "youtube" — takes "iteration" (a done one; "entries"? entry ids, "force"? re-drafts a field that is a draft already; narrate "cards"?) and is a step on it: it drafts fields of the iteration's video manifest, never one the operator wrote. "copyOf" N runs iteration N again on "model". "extractorModel" is an API sweep's extractor (a Claude model id; default settings.generation.models.extractor). "model" defaults to settings.generation's route for the task (one routed to code needs a model named). A Claude model runs on draft:api, capped at "maxUsd" (default by task, never above caps.max), and is refused when the day's API total has reached caps.daily; a local model runs on draft:local, through the GPU arbiter, and is unloaded when it ends. The corpus is "source" (a handle), "build" (a composed build), or the newest build holding the channels. `job cancel <id>` stops it. The log ends with @@report-draft {article, iteration, task, status, summary, usd, minutes}; --wait prints it. A research run takes "question" ("channels"? "from"/"to"?) and "autonomy" (propose \| limits \| auto; default settings.generation.research): it searches the corpus, the web and archive.org and proposes acquisitions (archive.org imports, videos, new channels — always on no site —, posts, transcription, persisting), each with its reason and evidence, enqueuing what its autonomy and the settings' caps allow through the editor's own actions; the rest waits in the iteration's proposals.json. A sweep with "iteration" N CONTINUES research run N: its question, over its channels and every channel a done acquisition wrote into, the sweep's parent N; refused while N still waits, unless "force" (what is done so far). "seed" (a new sweep's, on a Claude model) is cited markdown in the /sweep shape — umtool's research board: kept as the iteration's seed.md, the report starts from it, and the sweep verifies and extends it. | `pnpm ops report-draft --json '{"task":"sweep","article":"demo-article","question":"What does she say about the shop?","channels":["demo-channel"]}' --wait`<br>`pnpm ops report-draft --json '{"task":"revise-report","article":"demo-article","iteration":1,"feedback":"Drop the second finding."}'`<br>`pnpm ops report-draft --json '{"task":"research","article":"demo-article","question":"Where did the shop story start?","autonomy":"propose"}' --wait`<br>`pnpm ops report-draft --json '{"task":"sweep","article":"demo-article","iteration":1}'` | | `research-approve` | research-approve settles a research run's acquisitions: {"article", "iteration", "ids"?: \["p01", …\], "approve"?: true \| false, "note"?} -&gt; {outcomes: \[{id, status?, jobId?, note?, error?}\], research: {phase, autonomy, limits, spent, proposals, waitingOn: {approval, jobs}, continuedBy, autoContinue?}}. It first refreshes every enqueued acquisition from its jobs (all done: done; one failed: failed, naming it). approve: true runs each proposal through the editor's own action (past the run's autonomy and caps, never past a standing rule); false rejects it, note saying why. No ids: the run's state now. The phase is wait (approvals or jobs pending), ready (nothing pending: continue with report-draft {"task": "sweep", "iteration": N}) or continued. An `auto` run is continued by the editor itself once ready; autoContinue says how (continued by, held for a build, refused by a cap, and why). Refused while the run's job is going. | `pnpm ops research-approve --json '{"article":"demo-article","iteration":1,"ids":["p01","p03"],"approve":true}'` | | `bench-verdicts` | bench-verdicts runs the verdict bench as a bench-verdicts job: {"models": \["…"\], "run"?, "reports"?: \["&lt;article&gt;"\], "window"? (seconds, default 60), "maxUsd"? (default 5), "limit"?} -&gt; {jobId, run}. Every claim of the registry's fact-checks (or of "reports") with the operator's verdict and a citation with cues is asked of each model, one claim per call (the claim, its quotes, the transcript within the window; never the findings or the verdict), and scored against the rulings. On draft:local when any model is local (through the GPU arbiter; unloaded at the end), else draft:api; the run stops at maxUsd, and an API run is refused past caps.daily. A "run" that exists continues (answered pairs are skipped). Results stay local, in .generation/bench/verdicts/&lt;run&gt;/ (umtool's /bench). The log ends with @@bench-verdicts {run, status, items, skipped, spentUsd, stopped?}. | `pnpm ops bench-verdicts --json '{"models":["claude-sonnet-5-5","qwen3:8b"],"maxUsd":5}' --wait` | diff --git a/common/controller/reportDraft.ts b/common/controller/reportDraft.ts @@ -14,6 +14,11 @@ // settings.generation.models.extractor): a Claude model id the // price table knows (release 28 F2) // question / channels / from / to a sweep's +// seed a NEW sweep's starting report: cited markdown in the /sweep +// shape (umtool's research board, R2), kept as the iteration's +// seed.md; the agent's report starts from it and the sweep +// verifies and extends it. API models only (the local pipeline +// writes its report from scratch) // feedback a revision's // copyOf run iteration N again on another model (same kind and inputs) // maxUsd the job's cap (default by task; never above caps.max) @@ -56,6 +61,7 @@ import { readIterationFile, reportSourceOf, updateIteration, + writeIterationFile, type Iteration, } from "../lib/report/iterations"; import { diskPostChannelOf } from "../lib/report/convert-server"; @@ -96,8 +102,12 @@ export const REPORT_DRAFT_BODY_KEYS = [ "entries", "force", "autonomy", + "seed", ] as const; +// A seed's size: a board of a few hundred quotes, with room. +export const SEED_MAX_CHARS = 200_000; + export class ReportDraftInputError extends Error {} export type ReportDraftBody = { @@ -119,6 +129,7 @@ export type ReportDraftBody = { entries?: string[]; force?: boolean; autonomy?: Autonomy; + seed?: string; }; // A Claude model the price table knows: one of its ids, or a dated id of one @@ -199,6 +210,12 @@ export function parseReportDraftBody(b: Record<string, unknown>): ReportDraftBod if (out.task !== "research") fail('"autonomy" is a research run\'s'); out.autonomy = b.autonomy as Autonomy; } + if (b.seed !== undefined && b.seed !== null) { + if (typeof b.seed !== "string" || !b.seed.trim()) fail('"seed" is markdown text'); + if (b.seed.length > SEED_MAX_CHARS) fail(`"seed" is at most ${SEED_MAX_CHARS} characters`); + if (out.task !== "sweep" || out.iteration !== undefined || out.copyOf !== undefined) fail('"seed" starts a new sweep: no "iteration", no "copyOf"'); + out.seed = b.seed; + } if (out.source && !/^(local|remote|hub):\S+/.test(out.source)) fail('"source" is a corpus handle: local:<dir>, remote:<url> or hub:<url>'); if (out.source && out.build) fail('give "source" or "build", not both'); // What each task needs. @@ -361,6 +378,9 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep } const model = modelFor(gen, body.task, body.model); const provider = providerOf(model); + if (body.seed && provider !== "api") { + return refuse(`a seeded sweep runs the agent on a Claude model, not ${model}: the local pipeline writes its report from scratch`); + } if (body.extractorModel && provider === "local") { warnings.push(`extractorModel ${body.extractorModel} is unused: a sweep on a local model runs the pipeline, which has no extractor`); } @@ -408,6 +428,8 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep paths, ) ).n; + // A seeded sweep's starting report, beside the iteration (the task reads it). + if (body.seed) await writeIterationFile(body.article, n, "seed.md", body.seed, paths); } const result = await runManagedFunction({ kind: REPORT_DRAFT_JOB_KIND, diff --git a/common/lib/report/draft/tasks/sweep-agent.ts b/common/lib/report/draft/tasks/sweep-agent.ts @@ -11,7 +11,7 @@ // finding whose quote still fails is dropped. import { providerOf, runAgent, type AgentTool } from "../../../llm"; -import { iterationLabel, writeIterationFile } from "../../iterations"; +import { iterationLabel, readIterationFile, writeIterationFile } from "../../iterations"; import { CLAIM_QUOTES_RULE, COVERAGE_RULE, @@ -105,6 +105,15 @@ function runPreamble(o: { origin: string; maxUsd: number; terms?: string[]; from ].join("\n"); } +// What a seeded sweep is told (the seed is already the report file). +export const SEED_NOTE = [ + "THE REPORT FILE ALREADY HOLDS THE OPERATOR'S RESEARCH BOARD (read_report): findings a person pinned after reading them, in sections, each a claim, a verbatim quote and its link, some with a `Note:` line.", + "- Start from it: keep its sections, its order and its claims. Check every quote against its transcript with get_transcripts like any other; correct a quote the transcript does not hold word for word, or remove it, and say which in the summary.", + "- A `Note:` line is the operator's: heed what it says (a speaker not checked, a drifted quote, a different en-orig track), then drop the Note lines from the final report.", + "- Its links may be on another origin: cite every finding as the rules say.", + "- Then sweep the plan for what the board does not cover, and merge it into the board's sections (or new ones).", +].join("\n"); + const REPAIR_SYSTEM = [ UNATTENDED_RULE, "", @@ -182,9 +191,13 @@ async function sweepAgentBody(h: TaskHandle, input: SweepAgentInput): Promise<Ta const batch = input.batchSize ?? 10; const resolver = slugResolver(deps.corpus, channels); const rewrite = (t: string) => rewriteMomentBases(t, resolver, origin); - const file = reportFile({ article: h.article, n: h.n, paths: h.paths }); + // A SEEDED sweep (reportDraft's `seed`, a research board): the report starts + // as the seed, and the agent verifies and extends it. + const seed = (await readIterationFile(h.article, h.n, "seed.md", h.paths).catch(() => null))?.trim() || null; + const file = reportFile({ article: h.article, n: h.n, paths: h.paths, ...(seed ? { initial: seed } : {}) }); + if (seed) await file.set(seed); // sweep.md holds it from the first turn, as a run cut short keeps it const extracts = { n: 0 }; - h.log(`${iterationLabel(h.n)} sweep on ${model} (extractor ${input.extractorModel}), corpus ${deps.corpus.source}, links on ${origin}`); + h.log(`${iterationLabel(h.n)} sweep on ${model} (extractor ${input.extractorModel}), corpus ${deps.corpus.source}, links on ${origin}${seed ? `, seeded (${seed.length} chars)` : ""}`); const request = `${question} channels=${channels.join(",")} batch_size=${batch} parse_model=${input.extractorModel} report=sweep.md`; @@ -216,7 +229,7 @@ async function sweepAgentBody(h: TaskHandle, input: SweepAgentInput): Promise<Ta llm: deps.llm, model, system: runPreamble({ origin, maxUsd: input.maxUsd, terms: input.terms, from, to }), - user: plan, + user: seed ? `${plan}\n\n${SEED_NOTE}` : plan, tools, meter: h.meter, maxUsd: input.maxUsd, diff --git a/common/lib/report/iterations.ts b/common/lib/report/iterations.ts @@ -66,7 +66,8 @@ export type IterationStepStatus = (typeof ITERATION_STEP_STATUSES)[number]; // The files writeIterationFile may write (iteration.json is written by // create/update only). A later slice adds a name here, never a path. -export const ITERATION_FILES = ["report.json", "sweep.md", "turns.jsonl", "proposals.json"] as const; +// `seed.md`: a seeded sweep's starting report (a research board, umtool R2). +export const ITERATION_FILES = ["report.json", "sweep.md", "turns.jsonl", "proposals.json", "seed.md"] as const; export type IterationFile = (typeof ITERATION_FILES)[number]; // A revision needs something to revise. diff --git a/editor/app/api/ops/_reportDraft.test.ts b/editor/app/api/ops/_reportDraft.test.ts @@ -11,7 +11,7 @@ import { enqueueReportDraft, parseReportDraftBody } from "yt-dlp-transcript-comm import { sanitizeGeneration, type GenerationSettings } from "yt-dlp-transcript-common/lib/generationSettings"; import { getRegistry } from "yt-dlp-transcript-common/jobs/registry"; import { readGenerationUsage } from "yt-dlp-transcript-common/controller/generationUsage"; -import { createIteration, projectOf, readIteration, updateIteration, writeIterationFile } from "yt-dlp-transcript-common/lib/report/iterations"; +import { createIteration, projectOf, readIteration, readIterationFile, updateIteration, writeIterationFile } from "yt-dlp-transcript-common/lib/report/iterations"; import type { Paths } from "yt-dlp-transcript-common/lib/paths"; // Run with: @@ -165,6 +165,38 @@ test("an API sweep with its own extractorModel: the batches are read on it, its assert.ok(it.usage["claude-haiku-5-5"]!.calls === 1); }); +test("seed (umtool R2): a new sweep's starting report — text, sized, a new sweep's only", () => { + const sweep = { task: "sweep", article: "a", question: "q", channels: ["x"] }; + assert.equal(parseReportDraftBody({ ...sweep, seed: "# Board\n" }).seed, "# Board\n"); + assert.throws(() => parseReportDraftBody({ ...sweep, seed: " " }), /"seed" is markdown text/); + assert.throws(() => parseReportDraftBody({ ...sweep, seed: "x".repeat(200_001) }), /"seed" is at most 200000 characters/); + assert.throws(() => parseReportDraftBody({ task: "sweep", article: "a", iteration: 1, seed: "# B" }), /"seed" starts a new sweep/); + assert.throws(() => parseReportDraftBody({ task: "revise-report", article: "a", iteration: 1, feedback: "f", seed: "# B" }), /"seed" starts a new sweep/); +}); + +test("a seeded sweep: refused on a local model; on the API the seed is kept as seed.md and the agent is told to start from it", async () => { + const seed = '# Board\n\n## Pinned\n\n- The pier was never approved: "the pier was never approved" — [Kitchen @ 0:10](https://example.test/?v=synth-kitchen%2Fk1&t=10)\n'; + const local = await enqueueReportDraft({ task: "sweep", article: "synth-seed-local", model: "qwen3:8b", question: "q", channels: ["synth-kitchen"], source, seed }, deps()); + assert.equal(local.result.ok, false); + assert.match((local.result as { error: string }).error, /a seeded sweep runs the agent on a Claude model/); + assert.equal(await readIteration("synth-seed-local", 1, paths), null); + + const r = await run("sweep-agent"); + api.push(...r.turns); + const before = api.requests.length; + const out = await enqueueReportDraft({ task: "sweep", article: "synth-seeded", model: r.model, question: r.question, channels: r.channels, source, seed }, deps()); + assert.ok(out.result.ok && "iteration" in out, (out.result as { error?: string }).error); + void out.result.stream.cancel(); + const done = await out.result.done; + const job = getRegistry().get(out.result.jobId)!; + const log = await readFile(job.logPath, "utf8"); + assert.equal(done.status, "done", log); + assert.match(log, /seeded \(\d+ chars\)/); + assert.equal(await readIterationFile("synth-seeded", out.iteration, "seed.md", paths), seed); + const first = JSON.stringify(api.requests[before]); + assert.match(first, /THE REPORT FILE ALREADY HOLDS THE OPERATOR'S RESEARCH BOARD/); +}); + test("the daily cap: a job that would start past the day's total is refused, naming it", async () => { const before = await readGenerationUsage(paths.generationUsageFile); const total = before.reduce((s, x) => s + x.usd, 0); diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -1244,7 +1244,10 @@ export function usage() { ' waits in the iteration\'s proposals.json. A sweep with "iteration" N', " CONTINUES research run N: its question, over its channels and every channel", ' a done acquisition wrote into, the sweep\'s parent N; refused while N still', - ' waits, unless "force" (what is done so far).', + ' waits, unless "force" (what is done so far). "seed" (a new sweep\'s, on a', + " Claude model) is cited markdown in the /sweep shape — umtool's research", + " board: kept as the iteration's seed.md, the report starts from it, and the", + " sweep verifies and extends it.", "", 'research-approve settles a research run\'s acquisitions: {"article",', ' "iteration", "ids"?: ["p01", …], "approve"?: true | false, "note"?} ->',