Archilyzer · Source

archilyzer

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

commit 4b0eb5ce775fcb4faa6a559a7c1be75e075b4c3a
parent 859d877501235c6f5ea5a17f82ebeb40acbea370
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 13 Oct 2026 23:17:02 -0400

umtool: Draft with <model> on the project page; drafts and Draft everything on the Iterations tab (r28 M9)

The project page's draft section: one row per media task (the cut, on-screen,
teaser, flips, threads, narration, YouTube) with Draft with <model> (the
policy's models, the route's preselected), force (re-drafts only what a model
drafted), the entries to limit a per-entry task to, the job's live progress
and cancel, then the task's last run from its draft file, the badge and the
alternatives with Use this. A project not made from an iteration says why
and offers none. The Iterations tab gains the six media drafts beside
Narrate and Draft everything (a chain panel of its own mode).
/api/articles/draft reads; the chain route takes draftAll and model;
report-draft bodies carry entries; job views carry progress.

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

Diffstat:
Mumtool/app/api/articles/chain/route.ts | 33+++++++++++++++++++++------------
Mumtool/app/api/articles/delete/route.ts | 7++++++-
Aumtool/app/api/articles/draft/route.ts | 21+++++++++++++++++++++
Mumtool/components/articles/ChainPanel.tsx | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mumtool/components/articles/IterationsTab.tsx | 70+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Aumtool/components/projects/DraftPanel.tsx | 355+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/ReportProject.tsx | 13+++++++++++++
Mumtool/lib/articles/generation.ts | 39+++++++++++++++++++++++++--------------
Aumtool/lib/articles/projectDraft.ts | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 797 insertions(+), 42 deletions(-)

diff --git a/umtool/app/api/articles/chain/route.ts b/umtool/app/api/articles/chain/route.ts @@ -2,7 +2,7 @@ import { isReportId } from "yt-dlp-transcript-common/lib/report/schema"; import { cancelJob, getJob, startJob } from "@/lib/jobs"; import { ARTICLES_DIR } from "@/lib/paths"; import { planChain } from "@/lib/report/chain.mjs"; -import { chainKind, chainViewOf, errorResponse, projectsRootOf, readArticleIterations, readPolicy } from "@/lib/articles/generation"; +import { chainKind, chainViewOf, errorResponse, projectsRootOf, readArticleIterations, readPolicy, type ChainMode } from "@/lib/articles/generation"; export const dynamic = "force-dynamic"; @@ -12,9 +12,13 @@ export const dynamic = "force-dynamic"; // iteration's `steps`, so a start resumes at the first step not done, or at // `from`. The projects root is the editor's policy's (generation.projectsRoot). // -// GET ?article=<id>&n=<n> -> { chain } the steps, where it resumes, its job -// POST { article, n, from? } -> { ok, job } started -// POST { cancel: <jobId> } -> { cancelled } +// GET ?article=<id>&n=<n>[&mode=draft-all] -> { chain } the steps, where it resumes, its job +// POST { article, n, from?, draftAll?, model? } -> { ok, job } started +// POST { cancel: <jobId> } -> { cancelled } +// +// `draftAll` is Draft everything (release 28 M9): the chain with its +// generation steps — each a report-draft job on `model` (else the task's +// route) — and the fast build; a job of its own kind, resumed as the chain is. function parse(article: unknown, n: unknown): { article: string; n: number } | string { const a = String(article ?? ""); const k = Number(n); @@ -23,19 +27,21 @@ function parse(article: unknown, n: unknown): { article: string; n: number } | s return { article: a, n: k }; } -async function chainOf(article: string, n: number) { +async function chainOf(article: string, n: number, mode: ChainMode = "video") { const its = await readArticleIterations(article); const it = its.iterations.find((r) => r.n === n); if (!it) return null; - return chainViewOf(article, it); + return chainViewOf(article, it, mode); } +const modeOf = (v: unknown): ChainMode => (v === "draft-all" || v === true ? "draft-all" : "video"); + export async function GET(request: Request) { const url = new URL(request.url); const p = parse(url.searchParams.get("article"), url.searchParams.get("n")); if (typeof p === "string") return Response.json({ error: p }, { status: 400 }); try { - const chain = await chainOf(p.article, p.n); + const chain = await chainOf(p.article, p.n, modeOf(url.searchParams.get("mode"))); if (!chain) return Response.json({ error: `no iteration i${p.n}` }, { status: 404 }); return Response.json({ chain }, { headers: { "cache-control": "no-store" } }); } catch (err) { @@ -44,7 +50,7 @@ export async function GET(request: Request) { } export async function POST(request: Request) { - const body = (await request.json().catch(() => ({}))) as { article?: unknown; n?: unknown; from?: unknown; cancel?: unknown }; + const body = (await request.json().catch(() => ({}))) as { article?: unknown; n?: unknown; from?: unknown; cancel?: unknown; draftAll?: unknown; model?: unknown }; if (body.cancel !== undefined) { const id = String(body.cancel); if (!getJob(id)) return Response.json({ error: "no such job" }, { status: 404 }); @@ -60,10 +66,13 @@ export async function POST(request: Request) { projectsRoot = undefined; // the editor unreachable: the chain reads settings.json itself } const from = body.from ? String(body.from) : null; - const plan = planChain({ articlesDir: ARTICLES_DIR, article: p.article, n: p.n, from, ...(projectsRoot ? { projectsRoot } : {}) }); - if (plan.steps.length === 0) return Response.json({ error: "every step of the chain is done — pick a step to run from" }, { status: 400 }); - const job = startJob(chainKind(p.article, p.n), plan.steps); - return Response.json({ ok: true, job: { id: job.id }, chain: await chainOf(p.article, p.n) }); + const mode = modeOf(body.draftAll === true); + const model = typeof body.model === "string" && body.model.trim() ? body.model.trim() : undefined; + if (model && mode !== "draft-all") return Response.json({ error: "a model is Draft everything's (draftAll): the model its drafts run on" }, { status: 400 }); + const plan = planChain({ articlesDir: ARTICLES_DIR, article: p.article, n: p.n, from, mode, ...(model ? { model } : {}), ...(projectsRoot ? { projectsRoot } : {}) }); + if (plan.steps.length === 0) return Response.json({ error: `every step of ${mode === "draft-all" ? "Draft everything" : "the chain"} is done — pick a step to run from` }, { status: 400 }); + const job = startJob(chainKind(p.article, p.n, mode), plan.steps); + return Response.json({ ok: true, job: { id: job.id }, chain: await chainOf(p.article, p.n, mode) }); } catch (err) { return Response.json({ error: (err as Error).message }, { status: 400 }); } diff --git a/umtool/app/api/articles/delete/route.ts b/umtool/app/api/articles/delete/route.ts @@ -55,7 +55,12 @@ export async function POST(request: Request) { try { const plan: DeletePlan = n === null ? await planArticleDelete(article, opts) : await planIterationDelete(article, n, opts); const job = runningJob(); - if (job && (n === null ? job.kind.startsWith(`chain ${article} `) : job.kind === chainKind(article, n))) { + if ( + job && + (n === null + ? job.kind.startsWith(`chain ${article} `) || job.kind.startsWith(`draft-all ${article} `) + : job.kind === chainKind(article, n) || job.kind === chainKind(article, n, "draft-all")) + ) { plan.refusals.push({ reason: `${job.kind} is running here: cancel the chain, or wait for it`, forceable: false }); } if (n === null) { diff --git a/umtool/app/api/articles/draft/route.ts b/umtool/app/api/articles/draft/route.ts @@ -0,0 +1,21 @@ +import { resolveReport } from "@/lib/report/serve.mjs"; +import { draftRuns, projectIteration } from "@/lib/articles/projectDraft"; + +export const dynamic = "force-dynamic"; + +// A VIDEO PROJECT'S DRAFTS (release 28 M9): the iteration it was made from +// (the media tasks are report-draft steps on it; a project that names none +// has no "Draft with") and each task's last run, from its `<task>-draft.json`. +// A draft is STARTED through /api/articles/generate (the editor's +// report-draft), never here: this route reads. +// +// GET ?project=<id> -> { link: {ok, article, n, status} | {ok: false, why}, runs: {<task>: summary} } +export async function GET(request: Request) { + const url = new URL(request.url); + const r = await resolveReport(url.searchParams.get("project") ?? ""); + if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); + return Response.json( + { link: await projectIteration(r.project.dir), runs: await draftRuns(r.project.dir) }, + { headers: { "cache-control": "no-store" } }, + ); +} diff --git a/umtool/components/articles/ChainPanel.tsx b/umtool/components/articles/ChainPanel.tsx @@ -1,9 +1,9 @@ "use client"; -import { useCallback, useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { Button } from "@/components/ui/button"; import { badgeVariants } from "@/components/ui/badge"; -import type { ChainView } from "@/lib/articles/generation"; +import type { ChainMode, ChainView } from "@/lib/articles/generation"; // MAKE THE VIDEO for one iteration (release 27 S8): the pipeline chain's ten // steps (lib/report/chain.mjs) as a umtool job — what each step last did, where @@ -15,16 +15,33 @@ const STATUS_VARIANT: Record<string, "on" | "blocking" | "open" | "info" | "neut failed: "blocking", running: "open", cancelled: "info", + skipped: "neutral", }; -export default function ChainPanel({ article, n, label }: { article: string; n: number; label: string }) { +export default function ChainPanel({ + article, + n, + label, + mode = "video", + model, + autoStart = false, +}: { + article: string; + n: number; + label: string; + mode?: ChainMode; + model?: string; + autoStart?: boolean; +}) { + const draftAll = mode === "draft-all"; + const started = useRef(false); const [chain, setChain] = useState<ChainView | null>(null); const [from, setFrom] = useState<string>(""); const [error, setError] = useState(""); const [sending, setSending] = useState(false); const load = useCallback(async () => { - const r = await fetch(`/api/articles/chain?article=${encodeURIComponent(article)}&n=${n}`, { cache: "no-store" }); + const r = await fetch(`/api/articles/chain?article=${encodeURIComponent(article)}&n=${n}${draftAll ? "&mode=draft-all" : ""}`, { cache: "no-store" }); const b = await r.json(); if (!r.ok) { setError(b.error ?? `HTTP ${r.status}`); @@ -32,7 +49,7 @@ export default function ChainPanel({ article, n, label }: { article: string; n: } setChain(b.chain); return b.chain as ChainView; - }, [article, n]); + }, [article, n, draftAll]); const running = chain?.job?.state === "running"; useEffect(() => { @@ -44,11 +61,14 @@ export default function ChainPanel({ article, n, label }: { article: string; n: return () => clearInterval(t); }, [running, load]); - async function start() { + const start = useCallback(async () => { setError(""); setSending(true); try { - const r = await fetch("/api/articles/chain", { method: "POST", body: JSON.stringify({ article, n, ...(from ? { from } : {}) }) }); + const r = await fetch("/api/articles/chain", { + method: "POST", + body: JSON.stringify({ article, n, ...(from ? { from } : {}), ...(draftAll ? { draftAll: true, ...(model ? { model } : {}) } : {}) }), + }); const b = await r.json(); if (!r.ok) throw new Error(b.error ?? `HTTP ${r.status}`); if (b.chain) setChain(b.chain); @@ -58,7 +78,15 @@ export default function ChainPanel({ article, n, label }: { article: string; n: } finally { setSending(false); } - } + }, [article, n, from, draftAll, model, load]); + + useEffect(() => { + if (!autoStart || started.current) return; + started.current = true; + void start(); + // Once, on mount: a re-render must not start it again. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [autoStart]); async function cancel() { if (!chain?.job) return; @@ -68,16 +96,31 @@ export default function ChainPanel({ article, n, label }: { article: string; n: const startAt = from || chain?.resumeAt || ""; return ( - <section aria-label={`${label} video chain`} data-chain={label} className="mt-2 rounded border border-[var(--color-line)] bg-[var(--color-ink)] p-2 text-[12px]"> + <section + aria-label={`${label} ${draftAll ? "Draft everything" : "video chain"}`} + data-chain={label} + data-chain-mode={mode} + className="mt-2 rounded border border-[var(--color-line)] bg-[var(--color-ink)] p-2 text-[12px]" + > + {draftAll && ( + <p className="mb-1 text-[11px] text-[var(--color-dim)]"> + {model ? <span className="font-mono">{model}</span> : "each task's route"} · a draft that fails does not stop the chain · the build is the fast one · review the drafts before a final build + </p> + )} {chain && ( - <ol className="grid gap-x-4 gap-y-0.5 sm:grid-flow-col sm:grid-rows-5"> + <ol className={`grid gap-x-4 gap-y-0.5 sm:grid-flow-col ${draftAll ? "sm:grid-rows-8" : "sm:grid-rows-5"}`}> {chain.steps.map((s, i) => ( - <li key={s.name} data-chain-step={s.name} data-step-status={s.status} className="flex items-center gap-2"> + <li key={s.name} data-chain-step={s.name} data-step-status={s.status} title={s.detail ?? undefined} className="flex items-center gap-2"> <span className="num w-5 text-right text-[var(--color-dim)]">{i + 1}</span> - <span className={s.name === startAt && !running ? "text-[var(--color-sel)]" : ""}>{s.label}</span> + <span className={s.name === startAt && !running ? "text-[var(--color-sel)]" : s.optional ? "italic" : ""}>{s.label}</span> {s.status !== "pending" && ( <span className={badgeVariants({ variant: STATUS_VARIANT[s.status] ?? "neutral", size: "sm" })}>{s.status}</span> )} + {s.optional && s.status !== "pending" && s.status !== "running" && s.detail && ( + <span data-chain-step-detail="" className="truncate text-[11px] text-[var(--color-dim)]"> + {s.detail} + </span> + )} </li> ))} </ol> @@ -110,8 +153,8 @@ export default function ChainPanel({ article, n, label }: { article: string; n: ))} </select> </label> - <Button size="sm" variant="primary" disabled={sending || (!from && !chain?.resumeAt)} onClick={start}> - Run the chain + <Button size="sm" variant="primary" disabled={sending || (!from && !chain?.resumeAt)} onClick={() => void start()}> + {draftAll ? "Run Draft everything" : "Run the chain"} </Button> </> )} diff --git a/umtool/components/articles/IterationsTab.tsx b/umtool/components/articles/IterationsTab.tsx @@ -29,6 +29,17 @@ const STATUS_VARIANT: Record<string, "on" | "blocking" | "open" | "info" | "neut cancelled: "info", }; +// The media drafts beside narrate (release 28): each a report-draft STEP on a +// done iteration's video manifest. +const MEDIA_TASKS: { task: string; label: string }[] = [ + { task: "cut", label: "the cut" }, + { task: "onscreen", label: "on-screen titles" }, + { task: "teaser", label: "the teaser" }, + { task: "flips", label: "flips" }, + { task: "threads", label: "threads" }, + { task: "youtube", label: "YouTube text" }, +]; + // The report-draft task that made an iteration of this kind (a copy re-runs it). const TASK_OF: Record<string, string | null> = { sweep: "sweep", "revise-report": "revise-report", "revise-video": "revise-video", research: "research" }; @@ -197,8 +208,15 @@ function IterationCard({ comparing: boolean; onCompare: (on: boolean) => void; }) { - const [open, setOpen] = useState<"new" | "chain" | null>(null); + const [open, setOpen] = useState<"new" | "chain" | "draft-all" | null>(null); const g = ctx.policy?.generation; + const routeModel = (t: string) => (g?.routes[t as keyof typeof g.routes] === "api" ? g?.models.api : g?.models.local) ?? ""; + const [mediaTask, setMediaTask] = useState(MEDIA_TASKS[0].task); + const [mediaModel, setMediaModel] = useState(() => routeModel(MEDIA_TASKS[0].task)); + const [mediaForce, setMediaForce] = useState(false); + const [allModel, setAllModel] = useState(() => routeModel("onscreen")); + // Each press of Draft everything mounts a fresh panel that starts it. + const [allRun, setAllRun] = useState(0); const [copyModel, setCopyModel] = useState(() => ctx.allModels.find((m) => m !== it.model) ?? it.model); const [narrateModel, setNarrateModel] = useState(g?.routes.narrate === "api" ? g.models.api : (g?.models.local ?? "")); const [copyExtractor, setCopyExtractor] = useState(g?.models.extractor ?? ""); @@ -355,6 +373,53 @@ function IterationCard({ </Button> </span> )} + {done && it.hasManifest && !runningStep && ( + <span className="flex items-center gap-1" data-media-draft={it.n}> + <select + aria-label={`draft task for ${it.label}`} + className={field} + value={mediaTask} + onChange={(e) => { + setMediaTask(e.target.value); + setMediaModel(routeModel(e.target.value)); + }} + > + {MEDIA_TASKS.map((t) => ( + <option key={t.task} value={t.task}> + {t.label} + </option> + ))} + </select> + <ModelSelect label={`draft model for ${it.label}`} value={mediaModel} onChange={setMediaModel} models={ctx.allModels} /> + <label className="flex items-center gap-1 text-[11px] text-[var(--color-dim)]" title="re-draft fields a model drafted; a field you wrote or edited is never replaced"> + <input type="checkbox" checked={mediaForce} onChange={(e) => setMediaForce(e.target.checked)} aria-label={`force: re-draft drafted fields of ${it.label}`} /> + force + </label> + <Button + size="sm" + onClick={() => + void ctx.post({ task: mediaTask, article: ctx.article, iteration: it.n, model: mediaModel, ...(mediaForce ? { force: true } : {}) }) + } + > + Draft + </Button> + </span> + )} + {done && it.reportFrom !== null && ( + <span className="flex items-center gap-1"> + <ModelSelect label={`Draft everything model for ${it.label}`} value={allModel} onChange={setAllModel} models={ctx.allModels} /> + <Button + size="sm" + aria-expanded={open === "draft-all"} + onClick={() => { + setOpen("draft-all"); + setAllRun((k) => k + 1); + }} + > + Draft everything + </Button> + </span> + )} {done && it.reportFrom !== null && ( <Button size="sm" aria-expanded={open === "chain"} onClick={() => setOpen(open === "chain" ? null : "chain")}> Make the video @@ -376,6 +441,9 @@ function IterationCard({ </div> {open === "new" && <NewIterationForm it={it} ctx={ctx} onDone={() => setOpen(null)} />} {open === "chain" && <ChainPanel article={ctx.article} n={it.n} label={it.label} />} + {open === "draft-all" && ( + <ChainPanel key={allRun} article={ctx.article} n={it.n} label={it.label} mode="draft-all" model={allModel} autoStart={allRun > 0} /> + )} </article> ); } diff --git a/umtool/components/projects/DraftPanel.tsx b/umtool/components/projects/DraftPanel.tsx @@ -0,0 +1,355 @@ +"use client"; + +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { useCallback, useEffect, useRef, useState } from "react"; +import { badgeVariants } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { DraftAlternatives, DraftBadge, announceDraftsChanged, useDrafts } from "./drafts"; +import { announceManifestChanged } from "./timelineApi"; +import type { DraftRowView, DraftRunSummary, ProjectIteration } from "@/lib/articles/projectDraft"; + +// DRAFT WITH <MODEL> (release 28 M9): each draftable section of the cut — +// the cut, on-screen, teaser, flips, threads, narration, YouTube — drafted by +// a model as a `report-draft` step on the iteration the project was made +// from (umtool's /api/articles/generate → the editor). The models are the +// policy's, the task's route preselected; `force` re-drafts only fields a +// model drafted (a field you wrote or edited is never replaced — its draft is +// kept as an alternative); a per-entry task may be limited to the entries +// ticked. While the job runs its progress shows; when it ends the page is +// re-read: the badges, the alternatives with Use this, and what the task's +// draft file says it wrote, skipped and refused. + +type Policy = { generation: { routes: Record<string, string>; models: { api: string; local: string } }; models: { api: string[]; local: string[] } }; +type JobView = { status: string; queue: { key?: string; position?: number } | null; progress: { metric: string; current: number; target: number } | null; tail: string[] }; + +const field = "rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 text-[12px] text-[var(--color-text)]"; +const ENDED = ["done", "failed", "cancelled"]; + +function RunLine({ run }: { run: DraftRunSummary }) { + const c = run.counts; + const parts = [ + c.applied ? `${c.applied} written` : "", + c.kept ? `${c.kept} kept as an alternative` : "", + c.refused ? `${c.refused} refused by a check` : "", + c.skipped ? `${c.skipped} skipped` : "", + c.none ? `${c.none} with no draft` : "", + ].filter(Boolean); + const failing = run.checks.filter((ch) => !ch.ok); + const problems = run.units.filter((u) => u.outcome === "refused" || u.outcome === "kept" || u.outcome === "none"); + return ( + <div data-draft-run={run.task} className="mt-1 text-[11px] text-[var(--color-dim)]"> + <span> + last run{run.model ? <span className="font-mono"> {run.model}</span> : null} + {run.at ? `, ${new Date(run.at).toLocaleString()}` : ""}: {parts.join(" · ") || "nothing"} + </span> + {failing.map((ch) => ( + <p key={ch.name} data-draft-check={ch.name} className="text-[var(--color-dirty)]"> + check {ch.name}: {ch.detail ?? "failed"} + </p> + ))} + {problems.length > 0 && ( + <ul className="list-disc pl-4"> + {problems.slice(0, 8).map((u) => ( + <li key={u.id} data-draft-unit={u.id} data-draft-outcome={u.outcome}> + <span className="font-mono">{u.label ?? u.id}</span>: {u.why ?? u.outcome} + </li> + ))} + {problems.length > 8 && <li>… and {problems.length - 8} more ({run.file})</li>} + </ul> + )} + </div> + ); +} + +function DraftRow({ + project, + row, + link, + policy, + run, + runningJob, + view, + onEnded, +}: { + project: string; + row: DraftRowView; + link: Extract<ProjectIteration, { ok: true }>; + policy: Policy | null; + run: DraftRunSummary | undefined; + runningJob: string | null; + view: ReturnType<typeof useDrafts>; + onEnded: () => void | Promise<void>; +}) { + const g = policy?.generation; + const routeModel = g ? (g.routes[row.task] === "api" ? g.models.api : g.models.local) : ""; + const models = policy ? [...new Set([routeModel, ...policy.models.api, ...policy.models.local].filter(Boolean))] : []; + const [model, setModel] = useState(routeModel); + useEffect(() => { + if (!model && routeModel) setModel(routeModel); + }, [routeModel, model]); + const [force, setForce] = useState(false); + const [picked, setPicked] = useState<string[]>([]); + const [jobId, setJobId] = useState<string | null>(runningJob); + const [job, setJob] = useState<JobView | null>(null); + const [error, setError] = useState(""); + const [sending, setSending] = useState(false); + + useEffect(() => { + if (runningJob) setJobId(runningJob); + }, [runningJob]); + + // The latest callback, so the poll below depends on the job alone; and each + // job's end is told once (a re-render after the refresh must not tell it again). + const ended = useRef(onEnded); + ended.current = onEnded; + const told = useRef<string | null>(null); + useEffect(() => { + if (!jobId) return; + let alive = true; + let stop = false; + const tick = async () => { + if (stop) return; + try { + const r = await fetch(`/api/articles/job?id=${encodeURIComponent(jobId)}&tail=6`, { cache: "no-store" }); + const b = await r.json(); + if (!alive) return; + if (!r.ok) throw new Error(b.error ?? `HTTP ${r.status}`); + setJob(b.job); + if (ENDED.includes(b.job.status)) { + stop = true; + if (told.current !== jobId) { + told.current = jobId; + void ended.current(); + } + } + } catch (e) { + if (alive) setError((e as Error).message); + } + }; + void tick(); + const t = setInterval(tick, 2000); + return () => { + alive = false; + clearInterval(t); + }; + }, [jobId]); + + const active = !!jobId && !!job && !ENDED.includes(job.status); + const start = async () => { + setError(""); + setSending(true); + try { + const body = { + task: row.task, + article: link.article, + iteration: link.n, + ...(model ? { model } : {}), + ...(force ? { force: true } : {}), + ...(picked.length ? { entries: picked } : {}), + }; + const r = await fetch("/api/articles/generate", { method: "POST", body: JSON.stringify(body) }); + const b = await r.json().catch(() => ({})); + if (!r.ok) throw new Error(b.error ?? `HTTP ${r.status}`); + setJob(null); + setJobId(String(b.jobId)); + } catch (e) { + setError((e as Error).message); + } finally { + setSending(false); + } + }; + const cancel = async () => { + if (!jobId) return; + const r = await fetch("/api/articles/job", { method: "POST", body: JSON.stringify({ cancel: jobId }) }); + if (!r.ok) setError(((await r.json().catch(() => ({}))) as { error?: string }).error ?? `HTTP ${r.status}`); + }; + const p = job?.progress; + const queued = job?.status === "queued" && (job.queue?.position ?? 0) > 0; + + return ( + <li data-draft-task={row.task} data-draft-job={job?.status ?? (jobId ? "asking" : "")} className="border-t border-[var(--color-line)] py-1.5 first:border-t-0"> + <div className="flex flex-wrap items-baseline gap-x-3 gap-y-1"> + <h3 className="text-[13px] text-[var(--color-text)]">{row.label}</h3> + <span className="text-[11px] text-[var(--color-dim)]">{row.writes}</span> + <span data-draft-state="" className="ml-auto text-[11px]"> + {row.state} + </span> + </div> + {row.blocked ? ( + <p data-draft-blocked="" className="text-[11px] text-[var(--color-dim)]"> + {row.blocked} + </p> + ) : ( + <div className="mt-1 flex flex-wrap items-center gap-2"> + <Button size="sm" variant="primary" aria-label={`Draft ${row.label}`} disabled={!policy || sending || active} onClick={() => void start()}> + Draft with + </Button> + <select aria-label={`model for ${row.label}`} className={`${field} font-mono`} value={model} onChange={(e) => setModel(e.target.value)} disabled={!policy}> + {models.map((m) => ( + <option key={m} value={m}> + {m} + {m === routeModel ? " (route)" : ""} + </option> + ))} + </select> + <label className="flex items-center gap-1 text-[11px] text-[var(--color-dim)]"> + <input type="checkbox" checked={force} onChange={(e) => setForce(e.target.checked)} aria-label={`force: re-draft ${row.label}`} /> + force — re-drafts only what a model drafted; a field you wrote or edited is never replaced + </label> + {row.entries && row.entries.length > 0 && ( + <details className="text-[11px]"> + <summary className="cursor-pointer text-[var(--color-dim)]">{picked.length ? `${picked.length} of ${row.entries.length} entries` : `every entry (${row.entries.length})`}</summary> + <div className="mt-1 flex max-h-40 flex-col gap-0.5 overflow-auto"> + {row.entries.map((e) => ( + <label key={e.id} className="flex items-center gap-1"> + <input + type="checkbox" + aria-label={`only ${e.id} (${row.label})`} + checked={picked.includes(e.id)} + onChange={(ev) => setPicked(ev.target.checked ? [...picked, e.id] : picked.filter((x) => x !== e.id))} + /> + <span className="font-mono">{e.label}</span> + </label> + ))} + </div> + </details> + )} + </div> + )} + {jobId && job && !ENDED.includes(job.status) && ( + <div data-draft-progress={row.task} className="mt-1 flex flex-wrap items-center gap-2 text-[11px]"> + <span role="status" className="text-[var(--color-dirty)]"> + {queued ? `queued, ${job.queue?.position} ahead on ${job.queue?.key}` : job.status} + {p ? ` — ${p.metric} ${p.current}/${p.target}` : ""} + </span> + {job.tail.length > 0 && <span className="truncate font-mono text-[var(--color-dim)]">{job.tail[job.tail.length - 1]}</span>} + <Button size="sm" variant="destructive" aria-label={`Cancel the ${row.label} draft`} onClick={() => void cancel()}> + Cancel + </Button> + </div> + )} + {jobId && job && ENDED.includes(job.status) && ( + <p data-draft-ended={job.status} className={`mt-1 text-[11px] ${job.status === "done" ? "text-[var(--color-dim)]" : "text-[var(--color-bad)]"}`}> + the draft {job.status === "done" ? "is done" : job.status} + {job.status !== "done" && job.tail.length ? `: ${job.tail.filter((l) => !l.startsWith("@@")).slice(-1)[0] ?? ""}` : ""} + </p> + )} + {run && <RunLine run={run} />} + {row.address && ( + <div className="mt-1"> + <DraftBadge address={row.address} view={view.view} act={view.act} compact /> + <DraftAlternatives address={row.address} view={view.view} act={view.act} /> + </div> + )} + {!row.address && run && run.alternatives > 0 && ( + <Link href={`/browse/${project}/review`} className="text-[11px] text-[var(--color-sel)] hover:underline"> + {run.alternatives} alternative(s) kept — review them + </Link> + )} + {error && ( + <p role="alert" className="mt-1 text-[11px] text-[var(--color-bad)]"> + {error} + </p> + )} + </li> + ); +} + +export default function DraftPanel({ + project, + link, + rows, + runs: initialRuns, +}: { + project: string; + link: ProjectIteration; + rows: DraftRowView[]; + runs: Partial<Record<string, DraftRunSummary>>; +}) { + const router = useRouter(); + const view = useDrafts(project); + const [policy, setPolicy] = useState<Policy | null>(null); + const [policyError, setPolicyError] = useState(""); + const [runs, setRuns] = useState(initialRuns); + const [running, setRunning] = useState<Record<string, string>>(link.ok ? link.running : {}); + + useEffect(() => { + if (!link.ok) return; + let alive = true; + void (async () => { + const r = await fetch("/api/articles/policy", { cache: "no-store" }).catch(() => null); + const b = r ? await r.json().catch(() => ({})) : {}; + if (!alive) return; + if (r?.ok && b.policy) setPolicy(b.policy as Policy); + else setPolicyError(b.error ?? "the editor did not answer"); + })(); + return () => { + alive = false; + }; + }, [link.ok]); + + // A draft ended: the manifest changed under every section — re-read it all. + const onEnded = useCallback(async (): Promise<void> => { + const r = await fetch(`/api/articles/draft?project=${encodeURIComponent(project)}`, { cache: "no-store" }).catch(() => null); + if (r?.ok) { + const b = await r.json(); + setRuns(b.runs ?? {}); + if (b.link?.ok) setRunning(b.link.running ?? {}); + } + announceManifestChanged(project); + announceDraftsChanged(project); + router.refresh(); + }, [project, router]); + + return ( + <section aria-label="draft with a model" data-draft-panel={link.ok ? `${link.article}/i${link.n}` : ""} className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2"> + <div className="mb-1 flex flex-wrap items-baseline gap-3"> + <h2 className="micro">draft</h2> + {link.ok && ( + <span className="text-[11px] text-[var(--color-dim)]"> + steps on{" "} + <Link href={`/articles/${link.article}?tab=iterations`} className="font-mono text-[var(--color-sel)] hover:underline"> + {link.article} i{link.n} + </Link> + </span> + )} + {link.ok && ( + <span className={badgeVariants({ variant: "info", size: "sm" })}>a final build refuses a draft nobody approved</span> + )} + </div> + {!link.ok ? ( + <p data-draft-unlinked="" className="text-[12px] text-[var(--color-dim)]"> + {link.why} + </p> + ) : link.status !== "done" ? ( + <p data-draft-unlinked="" className="text-[12px] text-[var(--color-dim)]"> + {link.article} i{link.n} is {link.status}: a draft runs over a done iteration + </p> + ) : ( + <> + {policyError && ( + <p role="alert" className="text-[12px] text-[var(--color-bad)]"> + {policyError}: drafting needs the editor + </p> + )} + <ul> + {rows.map((row) => ( + <DraftRow + key={row.task} + project={project} + row={row} + link={link} + policy={policy} + run={runs[row.task]} + runningJob={running[row.task] ?? null} + view={view} + onEnded={onEnded} + /> + ))} + </ul> + </> + )} + </section> + ); +} diff --git a/umtool/components/projects/ReportProject.tsx b/umtool/components/projects/ReportProject.tsx @@ -23,6 +23,8 @@ import { narrationsOf } from "umtool-report-to-video/narration"; import { draftedFields } from "yt-dlp-transcript-common/lib/report/drafted.mjs"; import { readAlternatives } from "@/lib/report/drafts.mjs"; import DeliverSection from "./DeliverSection"; +import DraftPanel from "./DraftPanel"; +import { draftRowsOf, draftRuns, projectIteration } from "@/lib/articles/projectDraft"; import FetchUnfetchedButton from "./FetchUnfetchedButton"; import OnscreenSection from "./OnscreenSection"; import PodcastExport from "./PodcastExport"; @@ -155,6 +157,10 @@ export default async function ReportProject({ // The drafts review (release 28): drafted fields, and alternatives kept. const draftedCount = draftedFields(m).length; const alternativesCount = (await readAlternatives(project.dir)).length; + // "Draft with" (release 28 M9): the iteration the project was made from, and + // each media task's last run here. + const draftLink = await projectIteration(project.dir); + const draftRunsNow = draftLink.ok ? await draftRuns(project.dir) : {}; // Provenance splits by SHAPE: a scalar or a URL stays in the table; a long // string, or one with a newline, is prose the author wrote and reads as a @@ -476,6 +482,13 @@ export default async function ReportProject({ entries={entries.map((e) => ({ id: e.id, kind: e.kind }))} /> + {/* --- drafting it ----------------------------------------------- */} + {/* Each draftable section drafted by a model, as a step on the + iteration the project was made from. After the build chain (a + draft changes what the next build makes), before the sections it + writes into. */} + <DraftPanel project={project.id} link={draftLink} rows={draftRowsOf(m as Record<string, unknown>)} runs={draftRunsNow} /> + {/* --- what is drawn over it --------------------------------------- */} {/* The on-screen panel: its settings, its words and a live preview of both. After the build chain, because "re-render on-screen" is a run diff --git a/umtool/lib/articles/generation.ts b/umtool/lib/articles/generation.ts @@ -22,7 +22,7 @@ import { } from "yt-dlp-transcript-common/lib/generationSettings"; import { PRICES } from "yt-dlp-transcript-common/lib/llm/prices"; import { agentToken } from "@/lib/annotations/agentAuth.mjs"; -import { CHAIN_STEPS, DEFAULT_PROJECTS_ROOT, REPO_ROOT, chainStart, doneSteps } from "@/lib/report/chain.mjs"; +import { DEFAULT_PROJECTS_ROOT, REPO_ROOT, chainStart, chainStepsOf, doneSteps } from "@/lib/report/chain.mjs"; import { recentJobs, type Job } from "@/lib/jobs"; import { sitesPaths } from "./sites"; @@ -189,6 +189,8 @@ export type DraftJobView = { kind: string | null; status: string; queue: { key?: string; position?: number } | null; + /** The job's progress (release 28 F3: a draft's `turns`, `cards` or `entries`), when it reports one. */ + progress: { metric: string; current: number; target: number } | null; tail: string[]; }; @@ -200,11 +202,16 @@ export async function readDraftJob(id: string, tail = 12): Promise<DraftJobView> ); const job = answer.job ?? {}; const queue = (answer.queue ?? job.queue ?? null) as DraftJobView["queue"]; + const p = job.progress as { metric?: unknown; current?: unknown; target?: unknown } | undefined; return { id, kind: typeof job.kind === "string" ? job.kind : null, status: String(job.status ?? "unknown"), queue, + progress: + p && typeof p.current === "number" + ? { metric: typeof p.metric === "string" ? p.metric : "progress", current: p.current, target: typeof p.target === "number" ? p.target : p.current } + : null, tail: Array.isArray(answer.tail) ? answer.tail.map(String) : [], }; } @@ -216,7 +223,7 @@ export async function cancelDraftJob(id: string): Promise<void> { // The body umtool sends to `report-draft`: the action's own keys, nothing else // (the editor refuses an unknown key; this refuses it first, by name). -const DRAFT_KEYS = ["task", "article", "iteration", "model", "extractorModel", "feedback", "question", "channels", "from", "to", "copyOf", "maxUsd", "cards", "force", "autonomy"]; +const DRAFT_KEYS = ["task", "article", "iteration", "model", "extractorModel", "feedback", "question", "channels", "from", "to", "copyOf", "maxUsd", "cards", "entries", "force", "autonomy"]; export async function enqueueDraft(body: Record<string, unknown>): Promise<{ jobId: string; iteration: number }> { const out: Record<string, unknown> = {}; @@ -262,8 +269,10 @@ export type IterationRow = { currentVideo: boolean; }; +export type ChainMode = "video" | "draft-all"; export type ChainView = { - steps: { name: string; label: string; status: string }[]; + mode: ChainMode; + steps: { name: string; label: string; status: string; optional: boolean; detail: string | null }[]; /** Where a start resumes: the first step not done, or null (all done). */ resumeAt: string | null; job: { id: string; state: string; stepIndex: number; of: number; label: string; error: string | null; log: string[] } | null; @@ -372,26 +381,28 @@ export async function readToday(daily: number): Promise<{ day: string; usd: numb // ─── The chain ("make the video") ─── -/** The chain job's kind for an iteration, as lib/jobs.ts records it. */ -export const chainKind = (article: string, n: number) => `chain ${article} ${iterationLabel(n)}`; +/** The chain job's kind for an iteration, as lib/jobs.ts records it (Draft everything's is its own). */ +export const chainKind = (article: string, n: number, mode: ChainMode = "video") => + `${mode === "draft-all" ? "draft-all" : "chain"} ${article} ${iterationLabel(n)}`; /** The projects root the editor's policy names (`~` expanded), else the default. */ export function projectsRootOf(gen: GenerationSettings): string { return gen.projectsRoot ? expandHome(gen.projectsRoot) : DEFAULT_PROJECTS_ROOT; } -export function chainViewOf(article: string, it: IterationRow): ChainView { +export function chainViewOf(article: string, it: IterationRow, mode: ChainMode = "video"): ChainView { const done = new Set(doneSteps({ steps: it.steps })); - const byTask = new Map(it.steps.map((s) => [s.task, s.status])); - const job: Job | undefined = recentJobs(30).find((j) => j.kind === chainKind(article, it.n)); + const byTask = new Map(it.steps.map((s) => [s.task, s])); + const job: Job | undefined = recentJobs(30).find((j) => j.kind === chainKind(article, it.n, mode)); + const defs = chainStepsOf(mode) as { name: string; label: string; optional?: boolean }[]; return { - steps: CHAIN_STEPS.map((s: { name: string; label: string }) => ({ - name: s.name, - label: s.label, - status: byTask.get(`chain:${s.name}`) ?? "pending", - })), + mode, + steps: defs.map((s) => { + const rec = byTask.get(`chain:${s.name}`); + return { name: s.name, label: s.label, status: rec?.status ?? "pending", optional: s.optional === true, detail: rec?.detail ?? null }; + }), // chain.mjs's JSDoc types `done` by its default ([]), so it is cast. - resumeAt: (chainStart as (o: { done: string[] }) => string | null)({ done: [...done] }), + resumeAt: (chainStart as (o: { done: string[]; mode: string }) => string | null)({ done: [...done], mode }), job: job ? { id: job.id, diff --git a/umtool/lib/articles/projectDraft.ts b/umtool/lib/articles/projectDraft.ts @@ -0,0 +1,230 @@ +import { readFile } from "node:fs/promises"; +import path from "node:path"; +import { readIteration } from "yt-dlp-transcript-common/lib/report/iterations"; +import { draftedFields, ownerOf, reviewAddress } from "yt-dlp-transcript-common/lib/report/drafted.mjs"; +import { isReportId } from "yt-dlp-transcript-common/lib/report/schema"; +import { draftFileOf } from "@/lib/report/chain-draft.mjs"; +import { sitesPaths } from "./sites"; + +// "DRAFT WITH" ON A PROJECT PAGE (release 28 M9): which iteration a video +// project was made from — the media tasks are report-draft STEPS on a done +// iteration, so a project that names none has nothing to draft with — and +// what each task's last run left in its `<task>-draft.json` beside the +// manifest (what it wrote, what it skipped, what a check refused, what it +// kept as an alternative). Read only. SERVER-ONLY. + +/** The media tasks a project page drafts, in Draft everything's order. */ +export const PROJECT_DRAFT_TASKS = ["cut", "onscreen", "teaser", "flips", "threads", "narrate", "youtube"] as const; +export type ProjectDraftTask = (typeof PROJECT_DRAFT_TASKS)[number]; + +export type ProjectIteration = + | { ok: true; article: string; n: number; status: string; running: Record<string, string> } + | { ok: false; why: string }; + +/** + * The iteration a project directory belongs to: `<projectsRoot>/<article>/i<n>/` + * (common's projectOf), whose iteration exists and names this directory as its + * project (or names none). Else why not, in one line. + */ +export async function projectIteration(dir: string): Promise<ProjectIteration> { + const abs = path.resolve(dir); + const m = /^i(\d+)$/.exec(path.basename(abs)); + const article = path.basename(path.dirname(abs)); + if (!m || !isReportId(article)) { + return { ok: false, why: "this project was not made from an article's iteration (its folder is not <article>/i<n>), so no draft task can name one" }; + } + const n = Number(m[1]); + const it = await readIteration(article, n, sitesPaths()).catch(() => null); + if (!it) return { ok: false, why: `no iteration i${n} of the article "${article}": the drafts are steps on an iteration` }; + if (it.projectDir && path.resolve(it.projectDir) !== abs) { + return { ok: false, why: `${article} i${n} names another project (${it.projectDir})` }; + } + // A draft still running on it (a step with its job): the page follows it. + const running: Record<string, string> = {}; + for (const s of it.steps) if (s.status === "running" && s.jobId && !s.task.startsWith("chain:")) running[s.task] = s.jobId; + return { ok: true, article, n, status: it.status, running }; +} + +export type DraftUnitSummary = { + id: string; + label: string | null; + /** applied | skipped | refused (a hard check) | kept (an alternative: the field is the operator's, or a draft without force) | none */ + outcome: "applied" | "skipped" | "refused" | "kept" | "none"; + why: string | null; +}; +export type DraftRunSummary = { + task: ProjectDraftTask; + file: string; + model: string | null; + at: string | null; + units: DraftUnitSummary[]; + counts: Record<DraftUnitSummary["outcome"], number>; + checks: { name: string; ok: boolean; detail: string | null }[]; + alternatives: number; +}; + +type RawUnit = { + label?: unknown; + skipped?: unknown; + applied?: unknown; + chosen?: { hard?: unknown } | null; +}; + +const strings = (v: unknown) => (Array.isArray(v) ? v.filter((x): x is string => typeof x === "string") : []); + +/** One task's last run, from its draft file, or null (never run here, or unreadable). */ +export async function draftRunSummary(dir: string, task: ProjectDraftTask): Promise<DraftRunSummary | null> { + const file = draftFileOf(task); + let doc: Record<string, unknown>; + try { + doc = JSON.parse(await readFile(path.join(dir, file), "utf8")); + } catch { + return null; + } + if (!doc || typeof doc !== "object" || Array.isArray(doc)) return null; + const units: DraftUnitSummary[] = []; + const raw = doc.units && typeof doc.units === "object" ? (doc.units as Record<string, RawUnit>) : {}; + for (const [id, u] of Object.entries(raw)) { + const label = typeof u?.label === "string" ? u.label : null; + if (typeof u?.skipped === "string") units.push({ id, label, outcome: "skipped", why: u.skipped }); + else if (u?.applied === "applied") units.push({ id, label, outcome: "applied", why: null }); + else if (typeof u?.applied === "string") units.push({ id, label, outcome: "kept", why: u.applied === "operator" ? "the field is yours: kept as an alternative" : `kept as an alternative (${u.applied})` }); + else { + const hard = strings(u?.chosen?.hard); + units.push({ id, label, outcome: hard.length ? "refused" : "none", why: hard.length ? hard.join("; ") : u?.chosen ? null : "no draft" }); + } + } + const counts = { applied: 0, skipped: 0, refused: 0, kept: 0, none: 0 }; + for (const u of units) counts[u.outcome] += 1; + const checks = Array.isArray(doc.checks) + ? (doc.checks as { name?: unknown; ok?: unknown; detail?: unknown }[]) + .filter((c) => typeof c?.name === "string") + .map((c) => ({ name: String(c.name), ok: c.ok === true, detail: typeof c.detail === "string" ? c.detail : null })) + : []; + return { + task, + file, + model: typeof doc.model === "string" ? doc.model : null, + at: typeof doc.at === "string" ? doc.at : null, + units, + counts, + checks, + alternatives: Array.isArray(doc.alternatives) ? doc.alternatives.length : 0, + }; +} + +/** Every task's last run in this project. */ +export async function draftRuns(dir: string): Promise<Partial<Record<ProjectDraftTask, DraftRunSummary>>> { + const out: Partial<Record<ProjectDraftTask, DraftRunSummary>> = {}; + for (const t of PROJECT_DRAFT_TASKS) { + const s = await draftRunSummary(dir, t); + if (s) out[t] = s; + } + return out; +} + +// ─── The rows the project page's Draft section draws ─── + +export type DraftRowView = { + task: ProjectDraftTask; + /** The section's name. */ + label: string; + /** What the task writes, and the code's limits. */ + writes: string; + /** What the field holds now, in a few words. */ + state: string; + /** The review address of a whole-cut field (its badge and alternatives), else null (per entry: the review page). */ + address: string | null; + /** The entries a per-entry task may be limited to, else null. */ + entries: { id: string; label: string }[] | null; + /** Why it cannot draft on this cut (no deck for flips and threads), else null. */ + blocked: string | null; +}; + +type Entry = { id?: unknown; type?: unknown; heading?: unknown; onscreen?: { title?: unknown; subtitle?: unknown }; narration?: { text?: unknown }; lines?: unknown }; + +const ownerWords = (o: "empty" | "drafted" | "operator") => (o === "empty" ? "empty" : o === "drafted" ? "drafted" : "yours (never replaced)"); + +/** The Draft section's rows for a manifest, in Draft everything's order. */ +export function draftRowsOf(manifest: Record<string, unknown>): DraftRowView[] { + const tl = (Array.isArray(manifest.timeline) ? manifest.timeline : []) as Entry[]; + const drafted = draftedFields(manifest); + const nDrafted = (field: string) => drafted.filter((d) => d.field === field).length; + const ids = (es: Entry[]) => [...new Set(es.map((e) => (typeof e.id === "string" ? e.id : "")).filter(Boolean))]; + const labelOf = (e: Entry) => `${String(e.id)}${typeof e.heading === "string" && e.heading ? ` — ${e.heading}` : ""}`; + const listOf = (es: Entry[]) => ids(es).map((id) => ({ id, label: labelOf(es.find((e) => e.id === id)!) })); + const render = (manifest.render ?? {}) as { chrome?: unknown }; + const deck = !!render.chrome && typeof render.chrome === "object"; + const clips = tl.filter((e) => e.type === "clip"); + const cards = tl.filter((e) => e.type === "card"); + const teasers = tl.filter((e) => e.type === "teaser"); + const withOnscreen = tl.filter((e) => e.onscreen && (typeof e.onscreen.title === "string" || typeof e.onscreen.subtitle === "string")).length; + const narrated = cards.filter((e) => typeof e.narration?.text === "string" && e.narration.text.trim()).length; + const withLines = teasers.filter((e) => Array.isArray(e.lines) && e.lines.length > 0).length; + const whole = (field: string) => reviewAddress({ field }); + return [ + { + task: "cut", + label: "the cut", + writes: "which cited clips, in what order (ids from the citations only; windows untouched)", + state: `${clips.length} clip(s); the order is ${ownerWords(ownerOf(manifest, { field: "timeline" }))}`, + address: whole("timeline"), + entries: null, + blocked: null, + }, + { + task: "onscreen", + label: "on-screen titles", + writes: "a title (≤ 60) and a subtitle (≤ 90) per entry, grounded in its claim and quote", + state: `${withOnscreen} of ${tl.length} entries written, ${nDrafted("onscreen")} drafted`, + address: null, + entries: listOf(tl), + blocked: null, + }, + { + task: "teaser", + label: "the teaser", + writes: "3 to 5 lines of ≤ 70, no quote read out", + state: teasers.length ? `${withLines} of ${teasers.length} teaser(s) written, ${nDrafted("lines")} drafted` : "no teaser entry in the cut", + address: null, + entries: teasers.length ? listOf(teasers) : null, + blocked: null, + }, + { + task: "flips", + label: "flips", + writes: "THEN/NOW pairs over the cut's clips, of different dates (the left panel)", + state: deck ? `the flips are ${ownerWords(ownerOf(manifest, { field: "render.chrome.flips" }))}` : "no on-screen deck", + address: whole("render.chrome.flips"), + entries: null, + blocked: deck ? null : "flips are drawn by the on-screen deck, and this cut has none (render.chrome)", + }, + { + task: "threads", + label: "threads", + writes: "2 to 4 threads and each clip's thread (the left panel; not with flips)", + state: deck ? `the threads are ${ownerWords(ownerOf(manifest, { field: "render.chrome.threads" }))}` : "no on-screen deck", + address: whole("render.chrome.threads"), + entries: null, + blocked: deck ? null : "threads are drawn by the on-screen deck, and this cut has none (render.chrome)", + }, + { + task: "narrate", + label: "narration", + writes: "each card's narration, third person, every line grounded", + state: `${narrated} of ${cards.length} card(s) narrated, ${nDrafted("narration")} drafted`, + address: null, + entries: cards.length ? listOf(cards) : null, + blocked: null, + }, + { + task: "youtube", + label: "YouTube text", + writes: "a title (≤ 100) and a summary (≤ 900); the build adds chapters and sources to out/youtube.txt", + state: `the title and description are ${ownerWords(ownerOf(manifest, { field: "publish.youtube" }))}`, + address: whole("publish.youtube"), + entries: null, + blocked: null, + }, + ]; +}