commit 27d208e463b2e56eed46f2bc1ff0b287a0797a3a
parent 3ad7e707c1ceff37e084b146ab025ad5d257beab
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 12 Oct 2026 17:03:21 -0400
umtool /drafts: any model on any step, a copy of a run on another model, and two runs side by side
Each run picks the model its sweep/revise and narrate steps (re)run on. 'copy with <model>'
makes a sibling version on the same base (the same question, or the same parent and
feedback), for comparing models while tuning; it touches the article only when its own
article/video step runs. Two runs tick into a side-by-side view (report or cut, cost,
ops) that links back to the article.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 135 insertions(+), 16 deletions(-)
diff --git a/umtool/app/api/drafts/route.ts b/umtool/app/api/drafts/route.ts
@@ -1,5 +1,5 @@
import {
- apiKeyReady, cancelStep, createRun, createVersion, listChannels, listRuns, PRESETS, readPolicy, runFile, startStep, STEPS, writePolicy,
+ apiKeyReady, cancelStep, compareHtml, copyRun, createRun, createVersion, listChannels, listRuns, PRESETS, readPolicy, runFile, startStep, STEPS, writePolicy,
type GenPolicy, type Step,
} from "@/lib/drafts";
@@ -7,7 +7,8 @@ export const dynamic = "force-dynamic";
// Report drafts with no Claude Code (lib/drafts.ts). GET: the runs, or one
// run's file (?run=&file=). POST {action:"create", …} makes a run and starts its
-// sweep; POST {action:"step", name, step, narrateModel?} starts a later step.
+// sweep; POST {action:"step", name, step, model?} (re)starts a step on that model; {action:"copy", name, model}
+// copies a run onto another model (compare: GET ?compare=a,b).
export async function GET(request: Request) {
const url = new URL(request.url);
const run = url.searchParams.get("run");
@@ -16,6 +17,11 @@ export async function GET(request: Request) {
const f = runFile(run, file);
return f ? new Response(f.body, { headers: { "content-type": f.type } }) : new Response("not found", { status: 404 });
}
+ const cmp = url.searchParams.get("compare");
+ if (cmp) {
+ const [a, b] = cmp.split(",");
+ return new Response(compareHtml(a, b), { headers: { "content-type": "text/html; charset=utf-8" } });
+ }
if (url.searchParams.get("channels")) return Response.json({ channels: listChannels() });
return Response.json({ runs: listRuns(), keyReady: apiKeyReady(), policy: readPolicy(), presets: PRESETS }, { headers: { "cache-control": "no-store" } });
}
@@ -46,6 +52,11 @@ export async function POST(request: Request) {
startStep(m.name, "sweep");
return Response.json({ ok: true, name: m.name });
}
+ if (b.action === "copy") {
+ const m = copyRun(String(b.name ?? ""), String(b.model ?? ""));
+ startStep(m.name, "sweep");
+ return Response.json({ ok: true, name: m.name });
+ }
if (b.action === "cancel" && (STEPS as readonly string[]).includes(b.step)) {
cancelStep(String(b.name), b.step as Step);
return Response.json({ ok: true });
@@ -54,7 +65,7 @@ export async function POST(request: Request) {
return Response.json({ ok: true, policy: writePolicy(b.policy as GenPolicy) });
}
if (b.action === "step" && (STEPS as readonly string[]).includes(b.step)) {
- startStep(String(b.name), b.step as Step, b.narrateModel ? String(b.narrateModel) : undefined);
+ startStep(String(b.name), b.step as Step, b.model ? String(b.model) : undefined);
return Response.json({ ok: true });
}
return Response.json({ error: "unknown action" }, { status: 400 });
diff --git a/umtool/components/drafts/DraftsPanel.tsx b/umtool/components/drafts/DraftsPanel.tsx
@@ -186,7 +186,8 @@ export default function DraftsPanel() {
const [err, setErr] = useState("");
const [channels, setChannels] = useState<string[]>([]);
const [form, setForm] = useState({ question: "", model: "", name: "", terms: "", maxUsd: "5" });
- const [narrateModel, setNarrateModel] = useState("");
+ const [runModel, setRunModel] = useState<Record<string, string>>({});
+ const [compare, setCompare] = useState<string[]>([]);
const [open, setOpen] = useState<string | null>(null);
const [iterating, setIterating] = useState<string | null>(null);
@@ -214,7 +215,6 @@ export default function DraftsPanel() {
const routeModel = (task: string) =>
policy ? (policy.routes[task] === "local" ? policy.models.local : policy.models.api) : "qwen3:8b";
const model = form.model || routeModel("sweep");
- const nModel = narrateModel || routeModel("narrate");
async function post(body: object) {
setErr("");
@@ -276,14 +276,19 @@ export default function DraftsPanel() {
{err && <div className="text-[12px] text-red-500">{err}</div>}
</form>
- <label className="flex items-center gap-2 text-[12px]">
- narration model
- <select className={input} value={nModel} onChange={(e) => setNarrateModel(e.target.value)}>
- {MODELS.map((m) => (
- <option key={m}>{m}</option>
- ))}
- </select>
- </label>
+ {compare.length > 0 && (
+ <div className="text-[12px]">
+ compare: {compare.join(" vs ")}{" "}
+ {compare.length === 2 && (
+ <a className="underline" href={`/api/drafts?compare=${compare.join(",")}`} target="_blank">
+ open side by side
+ </a>
+ )}{" "}
+ <button className={btn} onClick={() => setCompare([])}>
+ clear
+ </button>
+ </div>
+ )}
{groups.length === 0 && <div className="text-[13px] text-[var(--color-dim)]">No runs yet.</div>}
{groups.map(([id, versions]) => (
@@ -293,6 +298,7 @@ export default function DraftsPanel() {
</h2>
{versions.map((r) => {
const busy = STEPS.some((s) => r.steps[s].state === "running");
+ const m = runModel[r.name] ?? r.model;
return (
<div key={r.name} className="rounded border border-[var(--color-line)] p-3">
<div className="flex flex-wrap items-baseline gap-2">
@@ -301,6 +307,7 @@ export default function DraftsPanel() {
</button>
<span className="text-[12px] text-[var(--color-dim)]">
{r.kind && r.kind !== "sweep" ? `${r.kind} of ${r.parent} · ` : ""}
+ {r.copyOf ? `copy of ${r.copyOf} · ` : ""}
{r.model} · {r.channels}
{typeof r.usd === "number" ? ` · ~$${r.usd.toFixed(2)}` : ""}
</span>
@@ -317,7 +324,7 @@ export default function DraftsPanel() {
disabled={busy}
onClick={() => {
setOpen(r.name);
- post({ action: "step", name: r.name, step: s, narrateModel: nModel });
+ post({ action: "step", name: r.name, step: s, model: s === "sweep" || s === "narrate" ? m : undefined });
}}
>
{s === "sweep" && r.kind && r.kind !== "sweep" ? "revise" : s}
@@ -351,6 +358,35 @@ export default function DraftsPanel() {
article
</a>
)}
+ <select
+ className={input}
+ title="the model this run's sweep/revise and narrate steps use"
+ value={m}
+ onChange={(e) => setRunModel({ ...runModel, [r.name]: e.target.value })}
+ >
+ {MODELS.map((x) => (
+ <option key={x} value={x}>
+ {label(x)}
+ </option>
+ ))}
+ </select>
+ <button
+ className={btn}
+ title="a copy of this run on the model picked here: the same question or feedback, the same base"
+ onClick={() => post({ action: "copy", name: r.name, model: m })}
+ >
+ copy with {m.replace("claude-", "")}
+ </button>
+ <label className="flex items-center gap-1 text-[12px]">
+ <input
+ type="checkbox"
+ checked={compare.includes(r.name)}
+ onChange={(e) =>
+ setCompare(e.target.checked ? [...compare.filter((x) => x !== r.name)].slice(-1).concat(r.name) : compare.filter((x) => x !== r.name))
+ }
+ />
+ compare
+ </label>
<button className={btn} disabled={!policy} onClick={() => setIterating(iterating === r.name ? null : r.name)}>
new version…
</button>
diff --git a/umtool/lib/drafts.ts b/umtool/lib/drafts.ts
@@ -34,6 +34,8 @@ export type RunMeta = {
version?: number;
feedback?: string;
project?: string;
+ // A copy of another run (same base, another model) — to compare models on the same work.
+ copyOf?: string;
};
export type StepState = { state: "idle" | "running" | "done" | "failed" | "cancelled"; exit?: number; tail?: string };
@@ -155,6 +157,71 @@ export function createVersion(parentName: string, input: {
return meta;
}
+/** A copy of a run on another model: the same question (a sweep) or the same parent and feedback (a revision). It is
+ * a version of the same article, made current only when its own article/video step runs. */
+export function copyRun(name: string, model: string): RunMeta {
+ const src = JSON.parse(readFileSync(path.join(runDir(name), "ui.json"), "utf8")) as RunMeta;
+ if (!(MODELS as readonly string[]).includes(model)) throw new Error(`model: one of ${MODELS.join(", ")}`);
+ const root = src.name.replace(/-v\d+$/, "");
+ const taken = readdirSync(RUNS).filter((n) => n === root || n.startsWith(`${root}-v`));
+ const version = Math.max(1, ...taken.map((n) => Number(n.match(/-v(\d+)$/)?.[1] ?? 1))) + 1;
+ const newName = `${root}-v${version}`;
+ mkdirSync(runDir(newName), { recursive: true });
+ const meta: RunMeta = {
+ ...src,
+ name: newName,
+ model,
+ version,
+ project: newName,
+ copyOf: src.name,
+ kind: src.kind ?? "sweep",
+ createdAt: new Date().toISOString(),
+ };
+ writeFileSync(path.join(runDir(newName), "ui.json"), JSON.stringify(meta, null, 2));
+ return meta;
+}
+
+/** Two runs side by side: each one's report (or, for a video version, its cut), cost and ops. */
+export function compareHtml(a: string, b: string): string {
+ const esc = (t: string) => t.replace(/[&<>]/g, (c) => ({ "&": "&", "<": "<", ">": ">" })[c]!);
+ const col = (name: string) => {
+ const dir = runDir(name);
+ const m = JSON.parse(readFileSync(path.join(dir, "ui.json"), "utf8")) as RunMeta;
+ const read = (f: string) => (existsSync(f) ? readFileSync(f, "utf8") : "");
+ let body = read(path.join(dir, "sweep.md"));
+ const proj = path.join(LOCAL_REPORTS, "videos", projectOf(m));
+ if (m.kind === "revise-video" || !body) {
+ const man = read(path.join(proj, "video.manifest.json"));
+ if (man) {
+ const j = JSON.parse(man) as { title?: string; timeline?: { type: string; id: string; heading?: string; quote?: string; narration?: { text?: string } }[] };
+ body = `${body ? `${body}\n\n── video cut ──\n` : ""}TITLE: ${j.title ?? ""}\n` + (j.timeline ?? []).map((e) =>
+ e.type === "card" ? `▌ ${e.heading ?? e.id}${e.narration?.text ? `\n 🔊 ${e.narration.text}` : ""}` : ` ▶ ${e.id} “${e.quote ?? ""}”`).join("\n");
+ }
+ }
+ const rev = read(path.join(dir, "revise.json")) || read(path.join(proj, "revise.json"));
+ let cost = "";
+ for (const f of [path.join(dir, "run.json"), path.join(dir, "revise.json"), path.join(proj, "revise.json")]) {
+ try {
+ const u = JSON.parse(read(f)).usd_estimate;
+ if (typeof u === "number") cost = `~$${u.toFixed(2)}`;
+ } catch {}
+ }
+ let ops = "";
+ try {
+ const r = JSON.parse(rev);
+ ops = `${r.applied?.length ?? 0} op(s) applied, ${r.refused?.length ?? 0} refused`;
+ } catch {}
+ return `<section><h2>v${m.version ?? 1} · ${esc(m.name)}</h2><p class="m">${esc(m.model)} ${cost} ${ops}${m.feedback ? ` · “${esc(m.feedback)}”` : ""}${m.copyOf ? ` · copy of ${esc(m.copyOf)}` : ""}</p><pre>${esc(body || "(nothing yet)")}</pre></section>`;
+ };
+ const id = (JSON.parse(readFileSync(path.join(runDir(a), "ui.json"), "utf8")) as RunMeta).id;
+ return `<!doctype html><meta charset="utf-8"><title>compare ${esc(a)} · ${esc(b)}</title><style>
+body{font:13px/1.45 system-ui;margin:0;background:#111;color:#ddd}header{padding:8px 12px;border-bottom:1px solid #333}
+a{color:#8cf}main{display:grid;grid-template-columns:1fr 1fr;gap:12px;padding:12px}section{min-width:0}
+h2{font-size:14px;margin:0}.m{color:#999;margin:2px 0 8px}pre{white-space:pre-wrap;word-break:break-word;background:#1a1a1a;padding:8px;border-radius:4px}
+@media (max-width:800px){main{grid-template-columns:1fr}}</style>
+<header><a href="/drafts">← drafts</a> · <a href="/articles/${esc(id)}">the article (${esc(id)})</a></header><main>${col(a)}${col(b)}</main>`;
+}
+
/** The channels the composed builds hold (the sweeps read a build): slug, name, videos, which builds. */
export function listChannels(): { slug: string; name: string; videos: number; builds: string[] }[] {
const root = path.join(LOCAL_REPORTS_REPO(), "export/.export-builds");
@@ -280,11 +347,16 @@ function envFor(m: RunMeta): Record<string, string> {
return env;
}
-export function startStep(name: string, step: Step, narrateModel?: string): void {
+export function startStep(name: string, step: Step, model?: string): void {
const dir = runDir(name);
const meta = JSON.parse(readFileSync(path.join(dir, "ui.json"), "utf8")) as RunMeta;
if (stepState(dir, step).state === "running") throw new Error(`${step} is already running`);
- const nm = narrateModel && (MODELS as readonly string[]).includes(narrateModel) ? narrateModel : meta.model;
+ const pick = model && (MODELS as readonly string[]).includes(model) ? model : undefined;
+ if (pick && step === "sweep" && pick !== meta.model) {
+ meta.model = pick; // the run's draft (sweep or revision) is re-run on the model picked for it
+ writeFileSync(path.join(dir, "ui.json"), JSON.stringify(meta, null, 2));
+ }
+ const nm = pick ?? meta.model;
const argv = argvFor(step, meta, dir, nm);
const log = path.join(dir, `ui-${step}.log`);
const ex = path.join(dir, `ui-${step}.exit`);