Archilyzer · Source

archilyzer

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

commit d30d40a2b29d4969fe8bf014ac1bfac878d6f5e1
parent 472189f49e8e0e7361425176190c8833151e848e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 21:37:49 -0400

report-draft: progress — turns for agent tasks, entries for the pipeline (r28 F3)

JobProgressMetric gains turns, cards and entries (the editor's bars label
them). TaskDeps.progress({metric, current, total?}) — TaskHandle.progress,
a listener that never stops the task — and the report-draft job maps it onto
its setProgress (target = total, the runner's own current). sweep-agent
(the repair round counted on), revise-report, revise-video and research
report turns against their turn cap; a local revision's one batch is 1/1;
sweep-pipeline reports the recordings gone through of its worklist. Media
tasks report cards or entries when they are wired (phase 2).

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

Diffstat:
Mcommon/controller/reportDraft.ts | 17+++++++++++++++--
Mcommon/jobs/registry.ts | 9++++++++-
Mcommon/lib/report/draft/tasks/research.ts | 6++++--
Mcommon/lib/report/draft/tasks/revise-report.ts | 5++++-
Mcommon/lib/report/draft/tasks/revise-video.ts | 4+++-
Mcommon/lib/report/draft/tasks/run.ts | 11++++++++++-
Mcommon/lib/report/draft/tasks/sweep-agent.ts | 11+++++++++--
Mcommon/lib/report/draft/tasks/sweep-pipeline.ts | 5+++++
Mcommon/lib/report/draft/tasks/types.ts | 9+++++++++
Meditor/app/api/ops/_reportDraft.test.ts | 2++
Meditor/app/jobs/components/JobProgressBars.tsx | 9+++++++++
Meditor/e2e/report-draft.spec.ts | 2++
Mmcp/src/draftTasks.test.ts | 12+++++++++++-
13 files changed, 91 insertions(+), 11 deletions(-)

diff --git a/common/controller/reportDraft.ts b/common/controller/reportDraft.ts @@ -36,6 +36,7 @@ import os from "node:os"; import path from "node:path"; import { runManagedFunction, type StreamActionResult } from "../jobs/streamCommand"; +import type { JobProgress } from "../jobs/registry"; import { DRAFT_API_QUEUE, DRAFT_LOCAL_QUEUE } from "../lib/queueKeys"; import type { Paths } from "../lib/paths"; import { getSettings } from "../lib/settings"; @@ -404,7 +405,7 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep kind: REPORT_DRAFT_JOB_KIND, queueKey: provider === "api" ? DRAFT_API_QUEUE : DRAFT_LOCAL_QUEUE, paths, - fn: (onLog, signal, _progress, ctx) => runReportDraft({ body, model, maxUsd, n, jobId: ctx.jobId, onLog, signal }, deps), + fn: (onLog, signal, setProgress, ctx) => runReportDraft({ body, model, maxUsd, n, jobId: ctx.jobId, onLog, signal, setProgress }, deps), }); if (!result.ok) { if (body.task !== "narrate") await updateIteration(body.article, n, { status: "failed", error: result.error }, paths).catch(() => {}); @@ -427,7 +428,16 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep } async function runReportDraft( - o: { body: ReportDraftBody; model: string; maxUsd?: number; n: number; jobId: string; onLog: (l: string) => void; signal: AbortSignal }, + o: { + body: ReportDraftBody; + model: string; + maxUsd?: number; + n: number; + jobId: string; + onLog: (l: string) => void; + signal: AbortSignal; + setProgress?: (snap: JobProgress) => void; + }, deps: ReportDraftDeps, ): Promise<void> { const { body, model, n, onLog, signal } = o; @@ -477,6 +487,9 @@ async function runReportDraft( .map((r) => ({ citation: r.citation, status: r.status, ...(r.message ? { message: r.message } : {}) })), paths, log: onLog, + // The task's count as the job's progress (release 28 F3): turns, cards + // or entries, the runner's own `current` (nothing on disk re-counts it). + progress: (p) => o.setProgress?.({ metric: p.metric, initial: 0, target: Math.max(p.total ?? p.current, p.current), current: p.current }), signal, ...(deps.now ? { now: deps.now } : {}), ...(body.task === "research" && deps.researchEditor ? { editor: deps.researchEditor, editorChannels: () => editorChannelsOf(paths) } : {}), diff --git a/common/jobs/registry.ts b/common/jobs/registry.ts @@ -26,7 +26,14 @@ export type JobProgressMetric = // Clip windows of a fetch-windows batch (controller/fetchWindows.ts). Spans // channels, so there is no channel count to re-count; the runner always sets // `current`. - | "clips"; + | "clips" + // A report-draft job (controller/reportDraft.ts, release 28 F3): an agent + // task's model turns (the target is its turn cap), a media task's cards, a + // pipeline's recordings read or a media task's entries. Nothing on disk to + // re-count; the runner always sets `current`. + | "turns" + | "cards" + | "entries"; export type JobProgress = { metric: JobProgressMetric; diff --git a/common/lib/report/draft/tasks/research.ts b/common/lib/report/draft/tasks/research.ts @@ -184,8 +184,10 @@ async function researchBody(h: TaskHandle, input: ResearchInput): Promise<TaskOu .filter(Boolean) .join(" "); const onEvent = (e: Parameters<NonNullable<Parameters<typeof runAgent>[0]["onEvent"]>>[0]) => { - if (e.type === "turn") h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); - else if (e.type === "wrap-up") h.log(`budget: 85% spent (~$${e.usd.toFixed(2)}) — wrapping up`); + if (e.type === "turn") { + h.progress({ metric: "turns", current: e.turn + 1, total: input.maxTurns ?? 60 }); + h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); + } else if (e.type === "wrap-up") h.log(`budget: 85% spent (~$${e.usd.toFixed(2)}) — wrapping up`); else if (e.type === "note") h.log(e.text); }; const run = await runAgent({ diff --git a/common/lib/report/draft/tasks/revise-report.ts b/common/lib/report/draft/tasks/revise-report.ts @@ -257,7 +257,9 @@ async function reviseReportBody(h: TaskHandle, input: ReviseReportInput): Promis ...(input.web !== false ? { serverWebSearch: { maxUses: input.webSearchMaxUses ?? 3 } } : {}), signal: deps.signal, onEvent: (e) => { - if (e.type === "turn") h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); + if (e.type !== "turn") return; + h.progress({ metric: "turns", current: e.turn + 1, total: input.maxTurns ?? 30 }); + h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); }, }); h.turns(run.transcript); @@ -361,5 +363,6 @@ export async function localOpsBatch( return null; }); h.turns([{ kind: "model", what: "ops batch", tokens: fitted.tokens, seconds: Math.round((Date.now() - t0) / 100) / 10, answer: asked }]); + h.progress({ metric: "turns", current: 1, total: 1 }); if (asked && Array.isArray(asked.ops) && asked.ops.length) await o.apply(asked.ops); } diff --git a/common/lib/report/draft/tasks/revise-video.ts b/common/lib/report/draft/tasks/revise-video.ts @@ -168,7 +168,9 @@ async function reviseVideoBody(h: TaskHandle, input: ReviseVideoInput): Promise< ...(input.web !== false ? { serverWebSearch: { maxUses: input.webSearchMaxUses ?? 3 } } : {}), signal: deps.signal, onEvent: (e) => { - if (e.type === "turn") h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); + if (e.type !== "turn") return; + h.progress({ metric: "turns", current: e.turn + 1, total: input.maxTurns ?? 30 }); + h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); }, }); h.turns(run.transcript); diff --git a/common/lib/report/draft/tasks/run.ts b/common/lib/report/draft/tasks/run.ts @@ -19,7 +19,7 @@ import { type IterationPatch, } from "../../iterations"; import { ArticleRegistryError } from "../../registry"; -import type { StorePaths, TaskDeps, TaskResult, TaskStatus } from "./types"; +import type { StorePaths, TaskDeps, TaskProgress, TaskResult, TaskStatus } from "./types"; export class TaskInputError extends Error {} @@ -38,6 +38,8 @@ export type TaskHandle = { deps: TaskDeps; paths: StorePaths | undefined; log(line: string): void; + // Progress for the job (deps.progress); a listener never stops the task. + progress(p: TaskProgress): void; // Turns for turns.jsonl (an agent's transcript, a pipeline's events). turns(entries: readonly unknown[]): void; check(c: IterationCheck): void; @@ -133,6 +135,13 @@ export async function runOnIteration( deps, paths, log, + progress: (p) => { + try { + deps.progress?.(p); + } catch { + // a listener never stops the task + } + }, turns: (entries) => turns.push(...entries), check: (c) => { const i = checks.findIndex((x) => x.name === c.name); diff --git a/common/lib/report/draft/tasks/sweep-agent.ts b/common/lib/report/draft/tasks/sweep-agent.ts @@ -200,8 +200,15 @@ async function sweepAgentBody(h: TaskHandle, input: SweepAgentInput): Promise<Ta const web = input.web === false ? [] : (deps.web ?? []); const tools = [...corpusTools, extractTool(h, input, rewrite, extracts), ...file.tools, ...web]; const isApi = providerOf(model) === "api"; + const maxTurns = input.maxTurns ?? 150; + // The job's progress: every model turn, the repair round's included. + let turnsTaken = 0; const onEvent = (e: Parameters<NonNullable<Parameters<typeof runAgent>[0]["onEvent"]>>[0]) => { - if (e.type === "turn") h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); + if (e.type === "turn") { + turnsTaken++; + h.progress({ metric: "turns", current: turnsTaken, total: Math.max(turnsTaken, maxTurns) }); + h.log(`turn ${e.turn}: ${e.calls.join(", ") || "done"} — ~$${h.meter.usd.toFixed(2)}`); + } else if (e.type === "wrap-up") h.log(`budget: 85% spent (~$${e.usd.toFixed(2)}) — wrapping up`); else if (e.type === "note") h.log(e.text); }; @@ -213,7 +220,7 @@ async function sweepAgentBody(h: TaskHandle, input: SweepAgentInput): Promise<Ta tools, meter: h.meter, maxUsd: input.maxUsd, - maxTurns: input.maxTurns ?? 150, + maxTurns, ...(isApi && input.web !== false ? { serverWebSearch: { maxUses: input.webSearchMaxUses ?? 5 } } : {}), signal: deps.signal, onEvent, diff --git a/common/lib/report/draft/tasks/sweep-pipeline.ts b/common/lib/report/draft/tasks/sweep-pipeline.ts @@ -366,6 +366,9 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T let nChunks = 0; let nRelevant = 0; const readIds: string[] = []; + // The job's progress: the recordings gone through, of the worklist. + let visited = 0; + h.progress({ metric: "entries", current: 0, total: todo.length }); for (let b = 0; b < todo.length; b += READ_BATCH) { deps.signal?.throwIfAborted(); const batch = todo.slice(b, b + READ_BATCH); @@ -380,6 +383,7 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T const p = parsed.get(v.id); if (!p || !p.lines.length) { event({ kind: "unread", video: v.id, why: "no windows returned" }); + h.progress({ metric: "entries", current: ++visited, total: todo.length }); continue; } readIds.push(v.id); @@ -470,6 +474,7 @@ async function pipelineBody(h: TaskHandle, input: SweepPipelineInput): Promise<T } } h.log(` read ${v.id} — kept so far ${kept.length}, dropped ${dropped.length}`); + h.progress({ metric: "entries", current: ++visited, total: todo.length }); } } if (!kept.length) { diff --git a/common/lib/report/draft/tasks/types.ts b/common/lib/report/draft/tasks/types.ts @@ -28,6 +28,13 @@ export type CorpusToolsLike = { // the corpus on disk, which also sees the en-orig track). export type ExternalQuoteProblem = { citation: string; status: string; message?: string }; +// How far a task has got (release 28 F3): an agent's turns, a media task's +// cards, a pipeline's recordings read (or a media task's entries). `total`, +// when known, is the target (an agent's: its turn cap). The editor job maps it +// onto its JobProgress. +export type TaskProgressMetric = "turns" | "cards" | "entries"; +export type TaskProgress = { metric: TaskProgressMetric; current: number; total?: number }; + export type TaskDeps = { llm: LlmConfig; corpus: CorpusToolsLike; @@ -52,6 +59,8 @@ export type TaskDeps = { paths?: StorePaths; now?: () => Date; log?: (line: string) => void; + // Progress, as the task counts it (the editor job's setProgress). + progress?: (p: TaskProgress) => void; signal?: AbortSignal; }; diff --git a/editor/app/api/ops/_reportDraft.test.ts b/editor/app/api/ops/_reportDraft.test.ts @@ -124,6 +124,8 @@ test("an API sweep: a report-draft job on draft:api, the iteration done with its const jobId = out.result.jobId; assert.ok(rows.every((x) => x.jobId === jobId && x.article === "synth-api" && x.iteration === 1)); assert.equal(api.requestHeaders.at(-1)!["x-api-key"], FAKE_KEY, "the key file's key"); + // The job's progress (release 28 F3): the agent's model turns, the runner's own count. + assert.deepEqual(job.progress, { metric: "turns", initial: 0, target: 150, current: 6 }); }); test("an API sweep with its own extractorModel: the batches are read on it, its spend in the ledger", async () => { diff --git a/editor/app/jobs/components/JobProgressBars.tsx b/editor/app/jobs/components/JobProgressBars.tsx @@ -159,6 +159,9 @@ const METRIC_LABELS: Record<JobProgressMetric, string> = { backfills: "Backfill", scans: "Metadata scan", clips: "Clip windows", + turns: "Model turns", + cards: "Cards", + entries: "Entries", }; // Per-metric glyph for the compact line ("↓ 5/10"). @@ -169,6 +172,9 @@ const METRIC_PREFIX: Record<JobProgressMetric, string> = { backfills: "\u21ba ", scans: "\u2315 ", clips: "\u2702 ", + turns: "\u21c4 ", + cards: "\u25a4 ", + entries: "\u2261 ", }; const METRIC_FILL: Record<JobProgressMetric, string> = { @@ -178,6 +184,9 @@ const METRIC_FILL: Record<JobProgressMetric, string> = { backfills: "bg-warning", scans: "bg-info/60", clips: "bg-success/60", + turns: "bg-info", + cards: "bg-success/60", + entries: "bg-success/60", }; // One-line textual summary of a job's batch progress, e.g. "↓ 5/10 · ~2m left" diff --git a/editor/e2e/report-draft.spec.ts b/editor/e2e/report-draft.spec.ts @@ -95,6 +95,8 @@ test("a sweep draft: enqueued over ops, followed to done, its iteration read bac expect(body.iteration).toBe(1); const job = await jobUntil(request, body.jobId!, (s) => ["done", "failed", "cancelled"].includes(s)); expect(job.job?.status ?? job.status, JSON.stringify(job.tail)).toBe("done"); + // The job's progress (release 28 F3): the agent's model turns, against its turn cap. + expect((job.job as { progress?: unknown } | undefined)?.progress).toMatchObject({ metric: "turns", initial: 0, current: 6, target: 150 }); const it = await iterationJson("synth-e2e", 1); expect(it.status).toBe("done"); expect(it.jobId).toBe(body.jobId); diff --git a/mcp/src/draftTasks.test.ts b/mcp/src/draftTasks.test.ts @@ -22,6 +22,7 @@ import { projectOf, } from "yt-dlp-transcript-common/lib/report/iterations"; import { runTask, type TaskDeps } from "yt-dlp-transcript-common/lib/report/draft/tasks/index"; +import type { TaskProgress } from "yt-dlp-transcript-common/lib/report/draft/tasks/types"; import { createCorpusTools, type CorpusTools } from "./callTool"; const RUNS = path.join(path.dirname(new URL(import.meta.url).pathname), "../../common/testing/draft/runs"); @@ -61,8 +62,9 @@ beforeEach(async () => { const postText = async (channel: string, id: string) => POSTS.find((p) => p.channelSlug === channel && p.id === id)?.text ?? null; -function deps(extra: Partial<TaskDeps> = {}): TaskDeps & { lines: string[] } { +function deps(extra: Partial<TaskDeps> = {}): TaskDeps & { lines: string[]; progressed: TaskProgress[] } { const lines: string[] = []; + const progressed: TaskProgress[] = []; return { llm: { anthropic: { baseUrl: api.url, env: { ANTHROPIC_API_KEY: FAKE_KEY }, sleep: async () => {} }, @@ -74,6 +76,8 @@ function deps(extra: Partial<TaskDeps> = {}): TaskDeps & { lines: string[] } { paths, log: (l) => lines.push(l), lines, + progress: (p) => progressed.push(p), + progressed, ...extra, }; } @@ -147,6 +151,9 @@ test("sweep-agent: the plan, the corpus tools, extract_batch, the report file; t const turns = (await readIterationFile("synth-contest", it.n, "turns.jsonl", paths))!.trim().split("\n").map((l) => JSON.parse(l)); assert.ok(turns.some((t) => t.kind === "tool" && t.name === "extract_batch")); assert.ok(turns.some((t) => t.kind === "note" && t.text === "repair round")); + // The job's progress: every model turn, the repair round's counted on (release 28 F3). + assert.deepEqual(d.progressed.map((p) => p.current), [1, 2, 3, 4, 5, 6]); + assert.ok(d.progressed.every((p) => p.metric === "turns" && p.total === 150)); }); test("sweep-agent: a quote the repair round does not fix is dropped, and the iteration is still done", async () => { @@ -246,6 +253,8 @@ test("sweep-pipeline: terms, enumerate, windows, extract (a non-verbatim quote d 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.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); const turns = (await readIterationFile("synth-pipe", it.n, "turns.jsonl", paths))!.trim().split("\n").map((l) => JSON.parse(l)); @@ -364,6 +373,7 @@ test("revise-report on a local model: no tool loop — one schema-bound ask for const out = await runTask({ task: "revise-report", article: "synth-basic", n: it.n, origin: ORIGIN, maxUsd: 1 }, d); assert.equal(out.status, "done", `${out.summary}\n${d.lines.join("\n")}`); assert.equal(ol.requests.length - before, 1, "one call"); + assert.deepEqual(d.progressed, [{ metric: "turns", current: 1, total: 1 }]); const req = ol.requests.at(-1); assert.ok(req.format, "schema-bound"); assert.ok(!req.tools, "no tools");