Archilyzer · Source

archilyzer

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

commit 969ec546a1bb2841680d9764feb0fc0191cbd6c2
parent cb1a1c5ceba2288fd4afe9d8ed245b9c8d2f3445
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 22:10:25 -0400

report-draft: the media drafts are steps — cut, onscreen, teaser, flips, threads, youtube beside narrate (r28 step 0)

MEDIA_STEP_TASKS and isStepTask (generationSettings.ts) are the one list: the
controller, the job, the MCP's generate and the ops row ask it wherever narrate
was special-cased. Each new task has a route (narrate's in every preset; a
settings file routing release 27's tasks keeps its preset), a narration's cap,
and a report-draft body {task, article, iteration, model?, entries?, force?}.
The six new tasks are wired to the job and refuse there, as a failed step on
the iteration, "not implemented in this build"; their lanes replace that.
SETTINGS.md, settings.json.example and COMMANDS.md regenerated.

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

Diffstat:
MCOMMANDS.md | 2+-
MSETTINGS.md | 18+++++++++++++++---
Mcommon/bin/gen.test.ts | 8+++++---
Mcommon/controller/reportDraft.ts | 93++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
Mcommon/lib/generationSettings.test.ts | 30++++++++++++++++++++++++++++++
Mcommon/lib/generationSettings.ts | 48++++++++++++++++++++++++++++++++++++------------
Mcommon/lib/report/draft/tasks/index.ts | 24+++++++++++++++++++++++-
Mcommon/lib/report/draft/tasks/types.ts | 6+++++-
Meditor/app/api/ops/_reportDraft.test.ts | 34++++++++++++++++++++++++++++++++++
Meditor/app/api/ops/report-draft/route.ts | 8++++++--
Mmcp/src/generation.test.ts | 38++++++++++++++++++++++++++------------
Mmcp/src/generation.ts | 10++++++----
Mscripts/archilyzer-ops.mjs | 14+++++++++-----
Msettings.json.example | 8+++++++-
14 files changed, 262 insertions(+), 79 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -143,7 +143,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" \| "narrate" \| "research", "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 narration takes "iteration" (a done one; "cards"?, "force"?) and is a step on it. "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). | `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}}. 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. Refused while the run's job is going. | `pnpm ops research-approve --json '{"article":"demo-article","iteration":1,"ids":["p01","p03"],"approve":true}'` | ### Usage, flags and environment diff --git a/SETTINGS.md b/SETTINGS.md @@ -954,7 +954,7 @@ Report and video generation (release 27): where each task runs (`code` = Claude | Key | Default | Description | |---|---|---| -| `preset` | `"balanced"` | The balance knob: `code` (Claude Code does every task), `balanced` (sweeps in Claude Code, report revisions and research runs on the API, video revisions and narration on the local model), `api`, `local`. Named by `routes`: the preset whose routes they are, else `custom` — choosing a preset is writing its routes. | +| `preset` | `"balanced"` | The balance knob: `code` (Claude Code does every task), `balanced` (sweeps in Claude Code, report revisions and research runs on the API, video revisions, narration and the other media drafts on the local model), `api`, `local`. Named by `routes`: the preset whose routes they are, else `custom` — choosing a preset is writing its routes. | | `routes` | object — see below | Where each task runs: `code`, `api` or `local` (below). | | `models` | object — see below | The model each route runs (below). | | `caps` | object — see below | The spend caps in USD (below). | @@ -976,6 +976,12 @@ Report and video generation (release 27): where each task runs (`code` = Claude | `revise-video` | `"local"` | A video-cut iteration from feedback, through checked ops. | | `narrate` | `"local"` | Card narration for an iteration's cut, under the narration rules and the grounding checks. | | `research` | `"api"` | A research run: find what the corpus lacks (the web, archive.org) and propose acquisitions — archive.org imports, new channels, posts, transcription — through the editor, then continue into a sweep. `code` = Claude Code over the MCP. | +| `cut` | `"local"` | A media draft (a step on a done iteration, as narration): the cut's clips and their order, chosen from the report's citations. | +| `onscreen` | `"local"` | A media draft: each clip's on-screen title and subtitle. | +| `teaser` | `"local"` | A media draft: the teaser's lines. | +| `flips` | `"local"` | A media draft: THEN/NOW pairs over the cut's clips. | +| `threads` | `"local"` | A media draft: the cut's threads and each clip's thread. | +| `youtube` | `"local"` | A media draft: the YouTube title and description. | #### `generation.models` @@ -991,7 +997,7 @@ Report and video generation (release 27): where each task runs (`code` = Claude |---|---|---| | `sweep` | `5` | A sweep or research job's cap when it names none. The agent wraps up at 85% and stops at the cap. | | `revision` | `2` | A report or video revision job's cap when it names none. | -| `narration` | `1` | A narration job's cap when it names none. | +| `narration` | `1` | A narration (or other media draft) job's cap when it names none. | | `daily` | `20` | The API spend a day (UTC) may reach: a job that would start past it is refused, naming the day's total. 0 = no daily cap. | | `max` | `10` | The most a job may ask for: a larger `maxUsd` is refused. | @@ -1023,7 +1029,13 @@ Default: "revise-report": "api", "revise-video": "local", "narrate": "local", - "research": "api" + "research": "api", + "cut": "local", + "onscreen": "local", + "teaser": "local", + "flips": "local", + "threads": "local", + "youtube": "local" }, "models": { "api": "claude-sonnet-5-5", diff --git a/common/bin/gen.test.ts b/common/bin/gen.test.ts @@ -3,6 +3,7 @@ import assert from "node:assert/strict"; import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import os from "node:os"; import path from "node:path"; +import { GENERATION_PRESETS } from "../lib/generationSettings"; // `archilyzer gen` (release 27 S9). settings.json and the ledger are pinned to // a temp dir BEFORE anything reads getPaths() (it caches), so the offline @@ -73,11 +74,12 @@ test("gen preset writes the preset's routes; gen set writes one; nonsense is a u const m = memoryStore(); const deps = { store: async () => m.store, runOps: async () => 0, out: c.out }; assert.equal(await gen.setMain({ preset: "local" }, deps), 0); - assert.deepEqual(m.written[0], { sweep: "local", "revise-report": "local", "revise-video": "local", narrate: "local", research: "local" }); + // Every task, the media drafts (release 28) included. + assert.deepEqual(m.written[0], { ...GENERATION_PRESETS.local }); assert.equal(await gen.setMain({ task: "sweep", route: "api" }, deps), 0); - assert.deepEqual(m.written[1], { sweep: "api", "revise-report": "local", "revise-video": "local", narrate: "local", research: "local" }); + assert.deepEqual(m.written[1], { ...GENERATION_PRESETS.local, sweep: "api" }); assert.ok(c.lines.includes("(written to the editor at http://editor.test)")); - for (const o of [{ preset: "cheap" }, { task: "sweep", route: "cloud" }, { task: "sweep" }, { task: "teaser", route: "api" }]) { + for (const o of [{ preset: "cheap" }, { task: "sweep", route: "cloud" }, { task: "sweep" }, { task: "nope", route: "api" }]) { assert.equal(await gen.setMain(o, deps), 2, JSON.stringify(o)); } assert.equal(m.written.length, 2); diff --git a/common/controller/reportDraft.ts b/common/controller/reportDraft.ts @@ -2,7 +2,9 @@ // (release 27, S6; D6). `pnpm ops report-draft` → POST /api/ops/report-draft → // here. // -// task sweep | revise-report | revise-video | narrate | research +// task sweep | revise-report | revise-video | research, or a media +// draft: narrate | cut | onscreen | teaser | flips | threads | +// youtube (a STEP on a done iteration, MEDIA_STEP_TASKS) // article the article id (an article in the making is fine for a sweep) // iteration a revision's parent; the iteration a narration voices; for a // sweep, the research run it CONTINUES (S11: its question, and its @@ -18,6 +20,9 @@ // source / build the corpus (default: the newest build holding the channels) // cards / force a narration's (force: a continuation over a research // run that still waits, with what is done so far) +// entries a media draft's (cut, onscreen, teaser, flips, threads, +// youtube; narrate too): only these entry ids; `force` re-drafts +// a field that is a draft already (release 28) // autonomy a research run's: propose | limits | auto (default: // settings.generation.research.autonomy; the limits are the // settings') @@ -40,7 +45,7 @@ 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"; -import { capFor, type GenerationSettings, type GenerationTask } from "../lib/generationSettings"; +import { GENERATION_TASKS, capFor, isStepTask, type GenerationSettings, type GenerationTask } from "../lib/generationSettings"; import { PROJECT_URL } from "../lib/project"; import { PRICES, providerOf, unloadOllama, type LlmConfig } from "../lib/llm"; import { webTools } from "../lib/web/tools"; @@ -87,6 +92,7 @@ export const REPORT_DRAFT_BODY_KEYS = [ "source", "build", "cards", + "entries", "force", "autonomy", ] as const; @@ -109,6 +115,7 @@ export type ReportDraftBody = { source?: string; build?: string; cards?: string[]; + entries?: string[]; force?: boolean; autonomy?: Autonomy; }; @@ -119,7 +126,7 @@ export function isKnownApiModel(model: string): boolean { return model.startsWith("claude-") && Object.keys(PRICES).some((p) => model === p || model.startsWith(`${p}-`)); } -const TASKS: readonly GenerationTask[] = ["sweep", "revise-report", "revise-video", "narrate", "research"]; +const TASKS: readonly GenerationTask[] = GENERATION_TASKS; const ymd = /^\d{4}-\d{2}-\d{2}$/; function fail(msg: string): never { @@ -170,6 +177,7 @@ export function parseReportDraftBody(b: Record<string, unknown>): ReportDraftBod set("question", text("question")); set("channels", list("channels")); set("cards", list("cards")); + set("entries", list("entries")); set("source", text("source")); set("build", text("build")); for (const k of ["from", "to"] as const) { @@ -207,26 +215,24 @@ export function parseReportDraftBody(b: Record<string, unknown>): ReportDraftBod if (out.iteration === undefined) fail(`a ${out.task} names the iteration it revises ("iteration")`); if (!out.feedback) fail(`a ${out.task} needs feedback: say what to change`); } + // A media draft (narrate, cut, …) is a step on the iteration it names. if (out.task === "narrate" && out.iteration === undefined) fail('a narration names the iteration it voices ("iteration")'); if (out.task === "narrate" && out.copyOf !== undefined) fail("a narration is a step, not an iteration: it has no copy"); + if (isStepTask(out.task) && out.iteration === undefined) fail(`a ${out.task} draft names the iteration it drafts on ("iteration")`); + if (isStepTask(out.task) && out.copyOf !== undefined) fail(`a ${out.task} draft is a step, not an iteration: it has no copy`); + if (out.entries && !isStepTask(out.task)) fail('"entries" is a media draft\'s (narrate, cut, onscreen, teaser, flips, threads, youtube)'); return out; } -const KIND_OF: Record<GenerationTask, Iteration["kind"]> = { - sweep: "sweep", - "revise-report": "revise-report", - "revise-video": "revise-video", - narrate: "sweep", // (a step: no iteration of its own) - research: "research", -}; +// A step task (narrate, cut, …) has no iteration of its own, so no kind; its +// cap is a narration's. +function kindOf(task: GenerationTask): Iteration["kind"] { + if (isStepTask(task)) throw new ReportDraftInputError(`a ${task} draft is a step: it makes no iteration`); + return task === "revise-report" || task === "revise-video" || task === "research" ? task : "sweep"; +} -const CAP_OF: Record<GenerationTask, "sweep" | "revision" | "narration"> = { - sweep: "sweep", - "revise-report": "revision", - "revise-video": "revision", - narrate: "narration", - research: "sweep", -}; +const capOf = (task: GenerationTask): "sweep" | "revision" | "narration" => + isStepTask(task) ? "narration" : task === "revise-report" || task === "revise-video" ? "revision" : "sweep"; export function expandHome(p: string): string { return p === "~" ? os.homedir() : p.startsWith("~/") ? path.join(os.homedir(), p.slice(2)) : p; @@ -324,7 +330,7 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep const src = body.copyOf !== undefined ? await readIteration(body.article, body.copyOf, paths) : null; if (body.copyOf !== undefined) { if (!src) return refuse(`"${body.article}" has no iteration i${body.copyOf} to copy`); - if (src.kind !== KIND_OF[body.task]) return refuse(`i${body.copyOf} is a ${src.kind} iteration, not a ${body.task}`); + if (src.kind !== kindOf(body.task)) return refuse(`i${body.copyOf} is a ${src.kind} iteration, not a ${body.task}`); } if (body.task === "research" && !deps.researchEditor) { return refuse("a research run runs in the editor (its reads and acquisitions are the editor's actions)"); @@ -359,16 +365,17 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep } let maxUsd: number | undefined; if (provider === "api") { - maxUsd = capFor(gen.caps, CAP_OF[body.task], body.maxUsd); + maxUsd = capFor(gen.caps, capOf(body.task), body.maxUsd); const refusal = dailyCapRefusal(await dayUsage(paths.generationUsageFile, utcDay(deps.now?.())), gen.caps.daily); if (refusal) return refuse(refusal); } - // The iteration: a new one (or a copy), queued; a narration's is the one named. + // The iteration: a new one (or a copy), queued; a step's is the one named. let n: number; - if (body.task === "narrate") { + if (isStepTask(body.task)) { const it = await readIteration(body.article, body.iteration!, paths); if (!it) return refuse(`"${body.article}" has no iteration i${body.iteration}`); - if (it.status !== "done") return refuse(`"${body.article}" i${it.n} is ${it.status}: a narration runs over a done iteration`); + const what = body.task === "narrate" ? "a narration" : `a ${body.task} draft`; + if (it.status !== "done") return refuse(`"${body.article}" i${it.n} is ${it.status}: ${what} runs over a done iteration`); n = it.n; } else if (src) { n = (await copyIteration(body.article, src.n, { model }, paths)).n; @@ -391,7 +398,7 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep await createIteration( body.article, { - kind: KIND_OF[body.task], + kind: kindOf(body.task), model, ...(body.task === "sweep" || body.task === "research" ? { question: body.question, scope: { ...(body.channels ? { channels: body.channels } : {}), ...(body.from ? { from: body.from } : {}), ...(body.to ? { to: body.to } : {}) } } @@ -408,14 +415,14 @@ export async function enqueueReportDraft(raw: Record<string, unknown>, deps: Rep 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(() => {}); + if (!isStepTask(body.task)) await updateIteration(body.article, n, { status: "failed", error: result.error }, paths).catch(() => {}); return { result }; } - if (body.task !== "narrate") await updateIteration(body.article, n, { jobId: result.jobId }, paths).catch(() => {}); + if (!isStepTask(body.task)) await updateIteration(body.article, n, { jobId: result.jobId }, paths).catch(() => {}); if (cont) await markContinued(body.article, cont.research.n, n, paths).catch(() => {}); // A job cancelled (or refused) before it ran leaves its iteration queued: end it. void result.done.then(async (d) => { - if (body.task === "narrate") return; + if (isStepTask(body.task)) return; const it = await readIteration(body.article, n, paths).catch(() => null); if (it?.status === "queued") { await updateIteration(body.article, n, { status: d.status === "cancelled" ? "cancelled" : "failed", error: `the job ended ${d.status} before it ran` }, paths).catch(() => {}); @@ -449,12 +456,12 @@ async function runReportDraft( // Again at the job's turn: jobs ahead in the queue may have spent the day. const refusal = dailyCapRefusal(await dayUsage(paths.generationUsageFile, utcDay(deps.now?.())), gen.caps.daily); if (refusal) { - if (body.task !== "narrate") await updateIteration(body.article, n, { status: "failed", error: refusal }, paths).catch(() => {}); + if (!isStepTask(body.task)) await updateIteration(body.article, n, { status: "failed", error: refusal }, paths).catch(() => {}); throw new Error(refusal); } } const it = (await readIteration(body.article, n, paths))!; - const channels = body.task === "sweep" || body.task === "research" ? (it.scope?.channels ?? []) : await channelsOfReport(body.article, body.task === "narrate" ? n : (it.parent ?? n), paths); + const channels = body.task === "sweep" || body.task === "research" ? (it.scope?.channels ?? []) : await channelsOfReport(body.article, isStepTask(body.task) ? n : (it.parent ?? n), paths); let corpus: (CorpusToolsLike & { close(): Promise<void> }) | null = null; let result: TaskResult | null = null; try { @@ -526,12 +533,30 @@ async function runReportDraft( break; } case "narrate": - input = { task: "narrate", article: body.article, n, model, projectsRoot, ...(o.maxUsd ? { maxUsd: o.maxUsd } : {}), jobId: o.jobId, ...(body.cards ? { cards: body.cards } : {}), ...(body.force ? { force: true } : {}) }; + case "cut": + case "onscreen": + case "teaser": + case "flips": + case "threads": + case "youtube": { + // A media draft: a step on the done iteration n (./tasks/media.ts). + const step = { + article: body.article, + n, + model, + projectsRoot, + ...(o.maxUsd ? { maxUsd: o.maxUsd } : {}), + jobId: o.jobId, + ...(body.entries ? { entries: body.entries } : {}), + ...(body.force ? { force: true } : {}), + }; + input = body.task === "narrate" ? { task: "narrate", ...step, ...(body.cards ? { cards: body.cards } : {}) } : { task: body.task, ...step }; break; + } } result = await runTask(input, taskDeps); } catch (e) { - if (body.task !== "narrate") { + if (!isStepTask(body.task)) { const cur = await readIteration(body.article, n, paths).catch(() => null); if (cur && (cur.status === "queued" || cur.status === "running")) { await updateIteration(body.article, n, { status: signal.aborted ? "cancelled" : "failed", error: (e as Error).message }, paths).catch(() => {}); @@ -556,16 +581,16 @@ async function runReportDraft( if (result.status === "failed") throw new Error(result.summary); } -// The job's spend, per model, from the iteration's usage (a narration: the -// step's cost, on its model). +// The job's spend, per model, from the iteration's usage (a step — a +// narration, any media draft: the step's cost, on its model). async function recordUsage(body: ReportDraftBody, n: number, model: string, jobId: string, paths: Paths, now: Date) { const it = await readIteration(body.article, n, paths); if (!it) return; const day = utcDay(now); const base = { at: now.toISOString(), day, jobId, article: body.article, iteration: n, task: body.task }; let rows: GenerationUsageRow[]; - if (body.task === "narrate") { - const step = [...it.steps].reverse().find((s) => s.task === "narrate" && s.jobId === jobId); + if (isStepTask(body.task)) { + const step = [...it.steps].reverse().find((s) => s.task === body.task && s.jobId === jobId); rows = step?.cost ? [{ ...base, model, inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, usd: step.cost }] : []; } else { rows = Object.entries(it.usage) diff --git a/common/lib/generationSettings.test.ts b/common/lib/generationSettings.test.ts @@ -3,7 +3,10 @@ import assert from "node:assert/strict"; import { DEFAULT_GENERATION_SETTINGS, GENERATION_PRESETS, + GENERATION_TASKS, + MEDIA_STEP_TASKS, capFor, + isStepTask, looksLikeApiKey, presetOf, sanitizeGeneration, @@ -74,3 +77,30 @@ test("research (S11): a route of its own, a file from before it keeps its preset assert.deepEqual(r, { autonomy: "auto", maxItemsPerRun: 3, maxGbPerRun: 5, maxTranscribeHours: 6, newChannelsNeedApproval: false, postWalksNeedApproval: true }); assert.equal(sanitizeGeneration({ research: { autonomy: "yolo" } }).research.autonomy, "propose"); }); + +test("the media drafts (release 28): steps, each with narrate's route in every preset; a file from before keeps its preset", () => { + assert.deepEqual([...MEDIA_STEP_TASKS], ["narrate", "cut", "onscreen", "teaser", "flips", "threads", "youtube"]); + for (const t of MEDIA_STEP_TASKS) { + assert.ok(isStepTask(t)); + assert.ok((GENERATION_TASKS as readonly string[]).includes(t)); + for (const p of Object.values(GENERATION_PRESETS)) assert.equal(p[t], p.narrate, `${t} routes as narrate`); + } + for (const t of ["sweep", "revise-report", "revise-video", "research", "nope", undefined]) assert.equal(isStepTask(t), false); + assert.equal(sanitizeGeneration(undefined).routes.cut, "local", "balanced drafts media on the local model"); + // routes written before the media tasks had any (release 27's five). + const five = (p: keyof typeof GENERATION_PRESETS) => + Object.fromEntries(["sweep", "revise-report", "revise-video", "narrate", "research"].map((t) => [t, GENERATION_PRESETS[p][t as "sweep"]])); + for (const p of ["code", "balanced", "api", "local"] as const) { + const old = sanitizeGeneration({ routes: five(p) }); + assert.equal(old.preset, p); + assert.deepEqual(old.routes, GENERATION_PRESETS[p]); + } + // A custom five keep their own routes; the media tasks take the default's. + const custom = sanitizeGeneration({ routes: { ...five("api"), narrate: "local" } }); + assert.equal(custom.preset, "custom"); + assert.equal(custom.routes.youtube, "local"); + // A partial patch names no preset. + assert.equal(sanitizeGeneration({ routes: { narrate: "api" } }).routes.cut, "local"); + // One media task routed on its own is custom. + assert.equal(sanitizeGeneration({ routes: { ...GENERATION_PRESETS.api, teaser: "local" } }).preset, "custom"); +}); diff --git a/common/lib/generationSettings.ts b/common/lib/generationSettings.ts @@ -10,17 +10,30 @@ import type { FieldDocs } from "./fieldDocs"; import { AUTONOMIES, DEFAULT_RESEARCH_LIMITS, type Autonomy } from "./report/draft/research/decide"; -export const GENERATION_TASKS = ["sweep", "revise-report", "revise-video", "narrate", "research"] as const; +// The media tasks (release 28): each drafts fields of a done iteration's video +// manifest, and runs as a STEP on that iteration (recorded in its `steps`, +// never an iteration of its own), as narrate did first. THE one list: the +// controller, the job, the MCP and umtool ask `isStepTask`. +export const MEDIA_STEP_TASKS = ["narrate", "cut", "onscreen", "teaser", "flips", "threads", "youtube"] as const; +export type MediaStepTask = (typeof MEDIA_STEP_TASKS)[number]; +export const isStepTask = (t: unknown): t is MediaStepTask => typeof t === "string" && (MEDIA_STEP_TASKS as readonly string[]).includes(t); + +export const GENERATION_TASKS = ["sweep", "revise-report", "revise-video", "narrate", "research", "cut", "onscreen", "teaser", "flips", "threads", "youtube"] as const; export type GenerationTask = (typeof GENERATION_TASKS)[number]; +// The tasks every settings file since release 27 S6 routes. +const FIRST_TASKS: readonly GenerationTask[] = ["sweep", "revise-report", "revise-video", "narrate"]; export const GENERATION_ROUTES = ["code", "api", "local"] as const; export type GenerationRoute = (typeof GENERATION_ROUTES)[number]; +// The media tasks other than narrate take narrate's route in every preset. +const mediaRoutes = <R extends GenerationRoute>(r: R) => ({ cut: r, onscreen: r, teaser: r, flips: r, threads: r, youtube: r }) as const; + export const GENERATION_PRESETS = { - code: { sweep: "code", "revise-report": "code", "revise-video": "code", narrate: "code", research: "code" }, - balanced: { sweep: "code", "revise-report": "api", "revise-video": "local", narrate: "local", research: "api" }, - api: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" }, - local: { sweep: "local", "revise-report": "local", "revise-video": "local", narrate: "local", research: "local" }, + code: { sweep: "code", "revise-report": "code", "revise-video": "code", narrate: "code", research: "code", ...mediaRoutes("code") }, + balanced: { sweep: "code", "revise-report": "api", "revise-video": "local", narrate: "local", research: "api", ...mediaRoutes("local") }, + api: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api", ...mediaRoutes("api") }, + local: { sweep: "local", "revise-report": "local", "revise-video": "local", narrate: "local", research: "local", ...mediaRoutes("local") }, } as const satisfies Record<string, Record<GenerationTask, GenerationRoute>>; export type GenerationPreset = keyof typeof GENERATION_PRESETS; export const GENERATION_PRESET_NAMES = Object.keys(GENERATION_PRESETS) as GenerationPreset[]; @@ -78,7 +91,7 @@ export const DEFAULT_GENERATION_SETTINGS: GenerationSettings = { export const GENERATION_SETTINGS_FIELD_DOCS: FieldDocs<GenerationSettings> = { preset: - "The balance knob: `code` (Claude Code does every task), `balanced` (sweeps in Claude Code, report revisions and research runs on the API, video revisions and narration on the local model), `api`, `local`. Named by `routes`: the preset whose routes they are, else `custom` — choosing a preset is writing its routes.", + "The balance knob: `code` (Claude Code does every task), `balanced` (sweeps in Claude Code, report revisions and research runs on the API, video revisions, narration and the other media drafts on the local model), `api`, `local`. Named by `routes`: the preset whose routes they are, else `custom` — choosing a preset is writing its routes.", routes: "Where each task runs: `code`, `api` or `local` (below).", models: "The model each route runs (below).", caps: "The spend caps in USD (below).", @@ -102,6 +115,12 @@ export const GENERATION_ROUTES_FIELD_DOCS: FieldDocs<GenerationRoutes> = { narrate: "Card narration for an iteration's cut, under the narration rules and the grounding checks.", research: "A research run: find what the corpus lacks (the web, archive.org) and propose acquisitions — archive.org imports, new channels, posts, transcription — through the editor, then continue into a sweep. `code` = Claude Code over the MCP.", + cut: "A media draft (a step on a done iteration, as narration): the cut's clips and their order, chosen from the report's citations.", + onscreen: "A media draft: each clip's on-screen title and subtitle.", + teaser: "A media draft: the teaser's lines.", + flips: "A media draft: THEN/NOW pairs over the cut's clips.", + threads: "A media draft: the cut's threads and each clip's thread.", + youtube: "A media draft: the YouTube title and description.", }; export const GENERATION_MODELS_FIELD_DOCS: FieldDocs<GenerationModels> = { @@ -113,7 +132,7 @@ export const GENERATION_MODELS_FIELD_DOCS: FieldDocs<GenerationModels> = { export const GENERATION_CAPS_FIELD_DOCS: FieldDocs<GenerationCaps> = { sweep: "A sweep or research job's cap when it names none. The agent wraps up at 85% and stops at the cap.", revision: "A report or video revision job's cap when it names none.", - narration: "A narration job's cap when it names none.", + narration: "A narration (or other media draft) job's cap when it names none.", daily: "The API spend a day (UTC) may reach: a job that would start past it is refused, naming the day's total. 0 = no daily cap.", max: "The most a job may ask for: a larger `maxUsd` is refused.", }; @@ -161,11 +180,16 @@ export function sanitizeGeneration(value: unknown): GenerationSettings { const v = rr[t]; routes[t] = typeof v === "string" && (GENERATION_ROUTES as readonly string[]).includes(v) ? (v as GenerationRoute) : d.routes[t]; } - // A file from before research had a route (S11) keeps its preset: research - // takes the route of the preset the other tasks' routes are. - if (!(typeof rr.research === "string" && (GENERATION_ROUTES as readonly string[]).includes(rr.research))) { - const was = GENERATION_PRESET_NAMES.find((p) => GENERATION_TASKS.every((t) => t === "research" || routes[t] === GENERATION_PRESETS[p][t])); - if (was) routes.research = GENERATION_PRESETS[was].research; + // A file from before a task had a route (research, S11; the media tasks, + // release 28) keeps its preset: a task it does not name takes the route of + // the preset the tasks it names are routed by. + // (Only a file that routes release 27's first four names a preset this way; + // a partial patch is not one.) + const named = (t: GenerationTask) => typeof rr[t] === "string" && (GENERATION_ROUTES as readonly string[]).includes(rr[t] as string); + const unnamed = GENERATION_TASKS.filter((t) => !named(t)); + if (unnamed.length && FIRST_TASKS.every(named)) { + const was = GENERATION_PRESET_NAMES.find((p) => GENERATION_TASKS.every((t) => !named(t) || routes[t] === GENERATION_PRESETS[p][t])); + if (was) for (const t of unnamed) routes[t] = GENERATION_PRESETS[was][t]; } // The ROUTES are the truth; the preset names them (the preset whose routes // they are, else `custom`). Choosing a preset is writing its routes. diff --git a/common/lib/report/draft/tasks/index.ts b/common/lib/report/draft/tasks/index.ts @@ -1,12 +1,15 @@ // The generation tasks (release 27, S5), and one dispatcher the editor's // `report-draft` job runs (S6). +import type { MediaStepTask } from "../../../generationSettings"; +import type { MediaTaskInput } from "./media"; import { narrate, type NarrateInput } from "./narrate"; import { research, type ResearchInput } from "./research"; import { reviseReport, type ReviseReportInput } from "./revise-report"; import { reviseVideo, type ReviseVideoInput } from "./revise-video"; import { sweepAgent, type SweepAgentInput } from "./sweep-agent"; import { sweepPipeline, type SweepPipelineInput } from "./sweep-pipeline"; +import { TaskInputError, runOnIteration } from "./run"; import { TASK_NAMES, type TaskDeps, type TaskName, type TaskResult } from "./types"; export * from "./types"; @@ -49,7 +52,19 @@ export type TaskInput = | ({ task: "revise-report" } & ReviseReportInput) | ({ task: "revise-video" } & ReviseVideoInput) | ({ task: "narrate" } & NarrateInput) - | ({ task: "research" } & ResearchInput); + | ({ task: "research" } & ResearchInput) + | ({ task: Exclude<MediaStepTask, "narrate"> } & MediaTaskInput); + +// A media task this build does not have: the step is recorded on the +// iteration as failed, saying so (release 28 lanes D and E replace these). +export function notImplementedTask(input: { task: string } & MediaTaskInput, deps: TaskDeps): Promise<TaskResult> { + return runOnIteration( + { article: input.article, n: input.n, deps, step: { task: input.task, model: input.model, ...(input.jobId ? { jobId: input.jobId } : {}) } }, + async () => { + throw new TaskInputError(`${input.task} is not implemented in this build`); + }, + ); +} export function runTask(input: TaskInput, deps: TaskDeps): Promise<TaskResult> { switch (input.task) { @@ -65,6 +80,13 @@ export function runTask(input: TaskInput, deps: TaskDeps): Promise<TaskResult> { return narrate(input, deps); case "research": return research(input, deps); + case "cut": + case "onscreen": + case "teaser": + case "flips": + case "threads": + case "youtube": + return notImplementedTask(input, deps); } } diff --git a/common/lib/report/draft/tasks/types.ts b/common/lib/report/draft/tasks/types.ts @@ -8,6 +8,7 @@ // log and the job's AbortSignal. Nothing here reads settings: the editor job // (S6) builds the deps from `settings.generation`. +import { MEDIA_STEP_TASKS } from "../../../generationSettings"; import type { AgentTool, LlmConfig } from "../../../llm"; import type { CuesOf, PostChannelOf } from "../../convertShared"; import type { readIteration } from "../../iterations"; @@ -79,5 +80,8 @@ export type TaskResult = { minutes: number; }; -export const TASK_NAMES = ["sweep-agent", "sweep-pipeline", "revise-report", "revise-video", "narrate", "research"] as const; +// The media tasks (narrate first; release 28's cut, onscreen, teaser, flips, +// threads and youtube) are generationSettings' MEDIA_STEP_TASKS: each a step +// on a done iteration (./media.ts). +export const TASK_NAMES = ["sweep-agent", "sweep-pipeline", "revise-report", "revise-video", "research", ...MEDIA_STEP_TASKS] as const; export type TaskName = (typeof TASK_NAMES)[number]; diff --git a/editor/app/api/ops/_reportDraft.test.ts b/editor/app/api/ops/_reportDraft.test.ts @@ -81,6 +81,23 @@ test("the body: each task's needs, and the refusals in words", () => { assert.deepEqual(parseReportDraftBody({ task: "sweep", article: "a", question: " q ", channels: "x, y" }), { task: "sweep", article: "a", question: "q", channels: ["x", "y"] }); }); +test("a media draft (release 28): a step body as narrate's — its iteration, no copy; entries a step's; an unknown task refused", () => { + for (const task of ["narrate", "cut", "onscreen", "teaser", "flips", "threads", "youtube"]) { + assert.throws(() => parseReportDraftBody({ task, article: "a" }), task === "narrate" ? /names the iteration it voices/ : new RegExp(`a ${task} draft names the iteration it drafts on`)); + assert.throws(() => parseReportDraftBody({ task, article: "a", iteration: 1, copyOf: 1 }), /is a step, not an iteration: it has no copy/); + assert.deepEqual(parseReportDraftBody({ task, article: "a", iteration: 2, model: "qwen3:8b", entries: "c01, c02", force: true }), { + task, + article: "a", + iteration: 2, + model: "qwen3:8b", + entries: ["c01", "c02"], + force: true, + }); + } + assert.throws(() => parseReportDraftBody({ task: "revise-video", article: "a", iteration: 1, feedback: "f", entries: ["c01"] }), /"entries" is a media draft's/); + assert.throws(() => parseReportDraftBody({ task: "cuts", article: "a", iteration: 1 }), /"task" is one of .*cut, onscreen, teaser, flips, threads, youtube/); +}); + test("extractorModel (release 28 F2): a sweep's, a Claude model the price table knows", () => { const sweep = { task: "sweep", article: "a", question: "q", channels: ["x"] }; assert.equal(parseReportDraftBody({ ...sweep, extractorModel: "claude-haiku-5-5" }).extractorModel, "claude-haiku-5-5"); @@ -217,3 +234,20 @@ test("a local narration: draft:local, a step on the iteration, ollama unloaded w const m = JSON.parse(await readFile(path.join(dir, "video.manifest.json"), "utf8")); assert.ok(m.timeline.find((e: { id: string }) => e.id === "the-bakery").narration.text); }); + +test("a media draft this build does not have: a step on the done iteration, failed at the job, saying so", async () => { + // synth-basic i1 is done (the narration test above). + const out = await enqueueReportDraft({ task: "youtube", article: "synth-basic", iteration: 1, model: "qwen3:8b", source }, deps()); + assert.ok(out.result.ok && "iteration" in out, (out.result as { error?: string }).error); + assert.equal(out.iteration, 1); + void out.result.stream.cancel(); + const done = await out.result.done; + assert.equal(done.status, "failed"); + const it = (await readIteration("synth-basic", 1, paths))!; + assert.equal(it.status, "done", "the iteration is left as it was"); + const step = it.steps.find((s) => s.task === "youtube")!; + assert.equal(step.status, "failed"); + assert.match(step.detail ?? "", /youtube is not implemented in this build/); + const notDone = await enqueueReportDraft({ task: "cut", article: "synth-basic", iteration: 9, model: "qwen3:8b", source }, deps()); + assert.match((notDone.result as { error: string }).error, /has no iteration i9/); +}); diff --git a/editor/app/api/ops/report-draft/route.ts b/editor/app/api/ops/report-draft/route.ts @@ -9,7 +9,7 @@ export const dynamic = "force-dynamic"; // POST { task, article, iteration?, model?, extractorModel?, feedback?, // question?, channels?, from?, to?, copyOf?, maxUsd?, source?, build?, -// cards?, force?, autonomy? } +// cards?, entries?, force?, autonomy? } // -> { ok: true, jobId, iteration, warnings? } // // A generation over an article's iteration (release 27 S6), as a @@ -18,7 +18,11 @@ export const dynamic = "force-dynamic"; // `from`/`to`); the API model runs the agent, a local model the pipeline; // - "revise-report" / "revise-video": a new iteration revising `iteration` // from `feedback`; -// - "narrate": a step on the done iteration `iteration` (`cards`, `force`); +// - a media draft — "narrate", "cut", "onscreen", "teaser", "flips", +// "threads", "youtube" (release 28): a step on the done iteration +// `iteration` that drafts fields of its video manifest (`entries`: only +// these entry ids; `force`: re-draft a field that is a draft already — +// never one the operator wrote; narrate's `cards`); // - "research" (S11): a new research run from `question` (`channels` // optional, `autonomy` propose | limits | auto, default the settings'): // it discovers, proposes, and enqueues what its autonomy allows through diff --git a/mcp/src/generation.test.ts b/mcp/src/generation.test.ts @@ -1,6 +1,7 @@ import { test } from "node:test"; import assert from "node:assert/strict"; import { connectWith, fakeEditor, isError, textOf } from "./editorOps.testkit"; +import { GENERATION_PRESETS, sanitizeGeneration } from "yt-dlp-transcript-common/lib/generationSettings"; import { GENERATE_POLL_MS, GENERATE_TASKS, @@ -61,13 +62,8 @@ function editor(opts: { policy?: Record<string, unknown>; runPolls?: number; end if (u.pathname === "/api/ops/settings" && s.method === "GET") return { status: 200, body: { ok: true, key: "generation", value: policy } }; if (u.pathname === "/api/ops/settings" && s.method === "POST") { const routes = (s.body as { patch: { generation: { routes: Record<string, string> } } }).patch.generation.routes; - const presets: Record<string, string> = { - "code,code,code,code,code": "code", - "api,api,api,api,api": "api", - "local,local,local,local,local": "local", - "code,api,local,local,api": "balanced", - }; - policy = { ...policy, routes: routes as typeof policy.routes, preset: presets[Object.values(routes).join(",")] ?? "custom" }; + // The editor's own sanitizer names the preset the routes are. + policy = { ...policy, routes: routes as typeof policy.routes, preset: sanitizeGeneration({ routes }).preset }; return { status: 200, body: { ok: true, changed: ["generation"], value: { generation: policy } } }; } if (u.pathname === "/api/ops/generation-usage") return { status: 200, body: { ok: true, day: "2026-10-13", usd: 1.75, jobs: 2, daily: 20 } }; @@ -130,7 +126,24 @@ test("generation_policy sets a preset as its routes, and one route alone", async assert.equal(a.isError, undefined, a.text); const post = e.sentOf("/api/ops/settings").find((s) => s.method === "POST")!; assert.deepEqual(post.body, { - patch: { generation: { routes: { sweep: "api", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" } } }, + patch: { + generation: { + routes: { + sweep: "api", + "revise-report": "api", + "revise-video": "api", + narrate: "api", + research: "api", + // The media drafts (release 28) take narrate's route in every preset. + cut: "api", + onscreen: "api", + teaser: "api", + flips: "api", + threads: "api", + youtube: "api", + }, + }, + }, }); assert.match(a.text, /^Set preset api\./); assert.match(a.text, /preset \*\*api\*\*/); @@ -139,7 +152,7 @@ test("generation_policy sets a preset as its routes, and one route alone", async const post2 = e.sentOf("/api/ops/settings").filter((s) => s.method === "POST")[1]; // The whole routes object (the writer merges one level; a nested object replaces). assert.deepEqual(post2.body, { - patch: { generation: { routes: { sweep: "local", "revise-report": "api", "revise-video": "api", narrate: "api", research: "api" } } }, + patch: { generation: { routes: { ...GENERATION_PRESETS.api, sweep: "local" } } }, }); assert.match(one.text, /^Routed sweep to local\./); assert.match(one.text, /preset \*\*custom\*\*/); @@ -158,8 +171,8 @@ test("generation_policy refuses a muddle before it asks the editor", async () => assert.match(a.text, re); } assert.equal(e.sent.length, 0); - const unknown = await generationPolicyTool({ task: "teaser", route: "api" }, e.deps as never); - assert.match(unknown.text, /no task "teaser" — the policy routes sweep, revise-report, revise-video, narrate, research/); + const unknown = await generationPolicyTool({ task: "nope", route: "api" }, e.deps as never); + assert.match(unknown.text, /no task "nope" — the policy routes sweep, revise-report, revise-video, narrate, research/); assert.equal(e.sent.filter((s) => s.method === "POST").length, 0); const none = await generationPolicyTool({}, fakeEditor(() => ({ status: 200, body: {} }), {}).deps as never); assert.equal(none.isError, true); @@ -263,7 +276,8 @@ test("generate: the arguments are checked before any request; research is a task assert.ok(ex.ok && ex.request.kind === "start"); if (ex.ok && ex.request.kind === "start") assert.equal(ex.request.body.extractorModel, "claude-haiku-5-5"); for (const [args, re] of [ - [{ task: "teaser", article: "a" }, /task is one of sweep, revise-report, revise-video, narrate, research/], + [{ task: "nope", article: "a" }, /task is one of sweep, revise-report, revise-video, narrate, research, cut, onscreen, teaser, flips, threads, youtube/], + [{ task: "cut", article: "a", iteration: 1, entries: [] }, /entries is a non-empty list/], [{ task: "sweep", article: "Not An Id" }, /article is an article id/], [{ task: "sweep", article: "a", channels: [] }, /channels is a non-empty list/], [{ task: "sweep", article: "a", iteration: 0 }, /iteration is an iteration number/], diff --git a/mcp/src/generation.ts b/mcp/src/generation.ts @@ -3,6 +3,7 @@ import { GENERATION_PRESET_NAMES, GENERATION_ROUTES, GENERATION_TASKS, + isStepTask, type GenerationPreset, } from "yt-dlp-transcript-common/lib/generationSettings"; import { AUTONOMIES } from "yt-dlp-transcript-common/lib/report/draft/research/decide"; @@ -252,7 +253,7 @@ export function validateGenerateArgs(args: Record<string, unknown>): { ok: true; if (task !== "sweep") return bad("extractorModel is a sweep's (the extractor an API sweep reads batches with)"); if (!String(body.extractorModel).startsWith("claude-")) return bad("extractorModel is a Claude model id: an API sweep's extractor runs on the API"); } - for (const k of ["channels", "cards"] as const) { + for (const k of ["channels", "cards", "entries"] as const) { if (args[k] === undefined) continue; const v = args[k]; if (!Array.isArray(v) || v.length === 0 || v.some((x) => typeof x !== "string" || !x.trim())) { @@ -381,13 +382,13 @@ export function renderIterationSummary( o: { task: string; article: string; jobId: string; marker: Marker | null; iteration: IterationView; dir?: string; files?: Record<string, string | null> }, ): string { const it = o.iteration; - const step = o.task === "narrate" ? [...(it.steps ?? [])].reverse().find((s) => s.task === "narrate" && s.jobId === o.jobId) : undefined; + const step = isStepTask(o.task) ? [...(it.steps ?? [])].reverse().find((s) => s.task === o.task && s.jobId === o.jobId) : undefined; const status = step?.status ?? o.marker?.status ?? it.status; const lines: string[] = []; lines.push(`generate: ${o.task} of ${o.article} i${it.n} — **${status}** on ${step?.model ?? it.model} (job ${o.jobId})`); if (o.marker?.summary) lines.push(o.marker.summary); if (it.error && status !== "done") lines.push(`error: ${it.error}`); - if (step?.detail) lines.push(`narration: ${step.detail}`); + if (step?.detail) lines.push(`${o.task === "narrate" ? "narration" : o.task}: ${step.detail}`); const per = Object.entries(it.usage ?? {}).filter(([, u]) => u.usd > 0); const total = step ? (step.cost ?? 0) : per.reduce((s, [, u]) => s + u.usd, 0); const minutes = o.marker?.minutes ?? it.minutes; @@ -546,7 +547,7 @@ export async function generateTool( const warnings = Array.isArray(a.body.warnings) ? (a.body.warnings as unknown[]).map(String) : []; const head = `generate ${task}: queued as job ${jobId}` + - (n ? `, ${task === "narrate" ? "narrating" : "making"} ${article} i${n}` : ` for ${article}`) + + (n ? `, ${task === "narrate" ? "narrating" : isStepTask(task) ? `drafting its ${task} on` : "making"} ${article} i${n}` : ` for ${article}`) + (body.model ? ` on ${String(body.model)}` : " on the policy's model") + "." + warnings.map((w) => `\n⚠ ${w}`).join(""); @@ -631,6 +632,7 @@ export const GENERATION_TOOLS = [ via: { type: "string", enum: ["api", "local"], description: "Run on this route's model instead of the policy's route — only when the operator asks." }, maxUsd: { type: "number", description: "An API job's cap in USD (else the task's default; never above the settings' max)." }, cards: { type: "array", items: { type: "string" }, description: "narrate: only these card ids." }, + entries: { type: "array", items: { type: "string" }, description: "A media draft (narrate, cut, onscreen, teaser, flips, threads, youtube): only these entry ids." }, force: { type: "boolean", description: "narrate: redraft cards that already have narration; a sweep continuing a research run: continue while proposals still wait.", diff --git a/scripts/archilyzer-ops.mjs b/scripts/archilyzer-ops.mjs @@ -1190,12 +1190,16 @@ export function usage() { "", 'report-draft runs a generation over an article\'s iteration as a', ' report-draft job: {"task": "sweep" | "revise-report" | "revise-video" |', - ' "narrate" | "research", "article", ...} -> {jobId, iteration, warnings?}.', - ' A sweep takes "question"', + ' "research" | a media draft, "article", ...} -> {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', - ' narration takes "iteration" (a done one; "cards"?, "force"?) and is a step', - ' on it. "copyOf" N runs iteration N again on "model". "extractorModel" is', + ' "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", diff --git a/settings.json.example b/settings.json.example @@ -244,7 +244,13 @@ "revise-report": "api", "revise-video": "local", "narrate": "local", - "research": "api" + "research": "api", + "cut": "local", + "onscreen": "local", + "teaser": "local", + "flips": "local", + "threads": "local", + "youtube": "local" }, "models": { "api": "claude-sonnet-5-5",