commit 3e708b06480756b905118deb2420bee00f118363
parent 53a2e6d2ca531dd5ee9ea9f8b1079f31ec5ca199
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 12 Oct 2026 13:36:45 -0400
umtool: /drafts — a report drafted with no Claude Code, on a local model or Claude on an API key (proof of concept)
The page runs the ~/reports/local-reports scripts (local-sweep or api-sweep, then
local-article, local-narrate, local-video) as detached steps whose log and exit
code live in the run's directory. Arguments are argv, never a shell string. Linked
from /articles. Typecheck only; no e2e yet.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
5 files changed, 400 insertions(+), 1 deletion(-)
diff --git a/umtool/app/api/drafts/route.ts b/umtool/app/api/drafts/route.ts
@@ -0,0 +1,43 @@
+import { apiKeyReady, createRun, listRuns, runFile, startStep, STEPS, type Step } from "@/lib/drafts";
+
+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.
+export async function GET(request: Request) {
+ const url = new URL(request.url);
+ const run = url.searchParams.get("run");
+ const file = url.searchParams.get("file");
+ if (run && file) {
+ const f = runFile(run, file);
+ return f ? new Response(f.body, { headers: { "content-type": f.type } }) : new Response("not found", { status: 404 });
+ }
+ return Response.json({ runs: listRuns(), keyReady: apiKeyReady() }, { headers: { "cache-control": "no-store" } });
+}
+
+export async function POST(request: Request) {
+ try {
+ const b = await request.json();
+ if (b.action === "create") {
+ const m = createRun({
+ name: String(b.name ?? ""),
+ question: String(b.question ?? ""),
+ channels: String(b.channels ?? "").replace(/\s+/g, ""),
+ model: String(b.model ?? ""),
+ id: b.id ? String(b.id) : undefined,
+ terms: b.terms ? String(b.terms) : undefined,
+ maxUsd: b.maxUsd ? Number(b.maxUsd) : undefined,
+ });
+ startStep(m.name, "sweep");
+ return Response.json({ ok: true, name: m.name });
+ }
+ 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);
+ return Response.json({ ok: true });
+ }
+ return Response.json({ error: "unknown action" }, { status: 400 });
+ } catch (e) {
+ return Response.json({ error: (e as Error).message }, { status: 400 });
+ }
+}
diff --git a/umtool/app/articles/page.tsx b/umtool/app/articles/page.tsx
@@ -49,7 +49,10 @@ export default async function ArticlesPage({ searchParams }: { searchParams: Pro
<span className="micro ml-3">notes</span>
<Chip href={qs({ notes: "" })} on={sp.notes !== "open"} label="all" />
<Chip href={qs({ notes: "open" })} on={sp.notes === "open"} label={`open ${count((a) => a.openNotes > 0)}`} />
- <Link href="/sites" className="ml-auto text-[12px] text-[var(--color-dim)] hover:text-[var(--color-text)]">
+ <Link href="/drafts" className="ml-auto text-[12px] text-[var(--color-dim)] hover:text-[var(--color-text)]">
+ draft a report
+ </Link>
+ <Link href="/sites" className="ml-2 text-[12px] text-[var(--color-dim)] hover:text-[var(--color-text)]">
site pages
</Link>
</div>
diff --git a/umtool/app/drafts/page.tsx b/umtool/app/drafts/page.tsx
@@ -0,0 +1,17 @@
+import BrowseHeader from "@/components/BrowseHeader";
+import DraftsPanel from "@/components/drafts/DraftsPanel";
+
+export const dynamic = "force-dynamic";
+
+// Report drafts with no Claude Code: a local model or Claude on an API key
+// (lib/drafts.ts; the scripts are ~/reports/local-reports, its RUNBOOK.html).
+export default function DraftsPage() {
+ return (
+ <div className="flex h-full flex-col">
+ <BrowseHeader active="articles" crumbs={[{ label: "articles", href: "/articles" }, { label: "draft a report" }]} />
+ <main className="deck-main flex-1 p-4">
+ <DraftsPanel />
+ </main>
+ </div>
+ );
+}
diff --git a/umtool/components/drafts/DraftsPanel.tsx b/umtool/components/drafts/DraftsPanel.tsx
@@ -0,0 +1,172 @@
+"use client";
+
+import { useCallback, useEffect, useState } from "react";
+import type { RunView, Step } from "@/lib/drafts";
+
+// The /drafts page (lib/drafts.ts): start a sweep on a local model or Claude on
+// an API key, then the article, narration and video, each a button; the runs
+// poll every 3 s off their logs.
+
+const MODELS = ["qwen3:8b", "claude-sonnet-5", "claude-opus-5-5"];
+const STEPS: Step[] = ["sweep", "article", "narrate", "video"];
+const NEXT_HINT: Record<Step, string> = {
+ sweep: "sweep → report.json (quotes checked)",
+ article: "private draft article + clip fetches + video project",
+ narrate: "card narration drafts — review them before the video",
+ video: "voices + cut + podcast, attached to the article",
+};
+
+const input = "rounded border border-[var(--color-line)] bg-transparent px-2 py-1 text-[13px]";
+const btn =
+ "rounded border border-[var(--color-line)] px-2 py-0.5 text-[12px] hover:bg-[var(--color-line)] disabled:opacity-40";
+const stateColor: Record<string, string> = {
+ idle: "text-[var(--color-dim)]",
+ running: "text-amber-500",
+ done: "text-emerald-500",
+ failed: "text-red-500",
+};
+
+export default function DraftsPanel() {
+ const [runs, setRuns] = useState<RunView[]>([]);
+ const [keyReady, setKeyReady] = useState<boolean | null>(null);
+ const [err, setErr] = useState("");
+ const [form, setForm] = useState({ question: "", channels: "", model: "qwen3:8b", name: "", terms: "", maxUsd: "5" });
+ const [narrateModel, setNarrateModel] = useState("claude-sonnet-5");
+ const [open, setOpen] = useState<string | null>(null);
+
+ const load = useCallback(async () => {
+ const r = await fetch("/api/drafts", { cache: "no-store" }).then((x) => x.json());
+ setRuns(r.runs);
+ setKeyReady(r.keyReady);
+ }, []);
+ useEffect(() => {
+ load();
+ const t = setInterval(load, 3000);
+ return () => clearInterval(t);
+ }, [load]);
+
+ async function post(body: object) {
+ setErr("");
+ const r = await fetch("/api/drafts", { method: "POST", body: JSON.stringify(body) }).then((x) => x.json());
+ if (r.error) setErr(r.error);
+ load();
+ return r;
+ }
+
+ const claude = form.model.startsWith("claude-");
+ const set = (k: keyof typeof form) => (e: { target: { value: string } }) => setForm({ ...form, [k]: e.target.value });
+
+ return (
+ <div className="flex max-w-5xl flex-col gap-6">
+ <form
+ className="flex flex-col gap-2 rounded border border-[var(--color-line)] p-3"
+ onSubmit={async (e) => {
+ e.preventDefault();
+ const r = await post({ action: "create", ...form });
+ if (r.ok) {
+ setOpen(r.name);
+ setForm({ ...form, question: "", name: "" });
+ }
+ }}
+ >
+ <div className="text-[13px] font-semibold">New report</div>
+ <textarea className={input} rows={2} placeholder="Question" value={form.question} onChange={set("question")} required />
+ <div className="flex flex-wrap gap-2">
+ <input className={input} placeholder="channels (slug,slug)" value={form.channels} onChange={set("channels")} required />
+ <input className={input} placeholder="run / article id (a-z0-9-)" value={form.name} onChange={set("name")} pattern="[a-z0-9][a-z0-9-]*" required />
+ <input className={input} placeholder="search terms (optional)" value={form.terms} onChange={set("terms")} />
+ <select className={input} value={form.model} onChange={set("model")}>
+ {MODELS.map((m) => (
+ <option key={m} value={m}>
+ {m.startsWith("claude-") ? `${m} (API key)` : `${m} (local)`}
+ </option>
+ ))}
+ </select>
+ {claude && (
+ <label className="flex items-center gap-1 text-[12px]">
+ max $<input className={`${input} w-16`} value={form.maxUsd} onChange={set("maxUsd")} />
+ </label>
+ )}
+ <button className={btn} type="submit">
+ Start sweep
+ </button>
+ </div>
+ {claude && keyReady === false && (
+ <div className="text-[12px] text-red-500">
+ No API key: put ANTHROPIC_API_KEY=… in ~/.config/archilyzer/anthropic.env (chmod 600).
+ </div>
+ )}
+ {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={narrateModel} onChange={(e) => setNarrateModel(e.target.value)}>
+ {MODELS.map((m) => (
+ <option key={m}>{m}</option>
+ ))}
+ </select>
+ </label>
+
+ <div className="flex flex-col gap-2">
+ {runs.length === 0 && <div className="text-[13px] text-[var(--color-dim)]">No runs yet.</div>}
+ {runs.map((r) => {
+ const busy = STEPS.some((s) => r.steps[s].state === "running");
+ return (
+ <div key={r.name} className="rounded border border-[var(--color-line)] p-3">
+ <div className="flex flex-wrap items-baseline gap-2">
+ <button className="text-[13px] font-semibold hover:underline" onClick={() => setOpen(open === r.name ? null : r.name)}>
+ {r.name}
+ </button>
+ <span className="text-[12px] text-[var(--color-dim)]">
+ {r.model} · {r.channels}
+ {r.usd !== undefined ? ` · ~$${r.usd.toFixed(2)}` : ""}
+ </span>
+ </div>
+ <div className="mb-2 text-[13px]">{r.question}</div>
+ <div className="flex flex-wrap items-center gap-3">
+ {STEPS.map((s) => (
+ <span key={s} className="flex items-center gap-1">
+ <button
+ className={btn}
+ title={NEXT_HINT[s]}
+ disabled={busy}
+ onClick={() => {
+ setOpen(r.name);
+ post({ action: "step", name: r.name, step: s, narrateModel });
+ }}
+ >
+ {s}
+ </button>
+ <span className={`text-[11px] ${stateColor[r.steps[s].state]}`}>{r.steps[s].state}</span>
+ </span>
+ ))}
+ {r.files.map((f) => (
+ <a key={f} className="text-[12px] underline" href={`/api/drafts?run=${r.name}&file=${f}`} target="_blank">
+ {f}
+ </a>
+ ))}
+ {r.steps.narrate.state === "done" && (
+ <a className="text-[12px] underline" href={r.narrationReview}>
+ review narration
+ </a>
+ )}
+ {r.steps.article.state === "done" && (
+ <a className="text-[12px] underline" href={`/articles/${r.id}`}>
+ article
+ </a>
+ )}
+ </div>
+ {open === r.name &&
+ STEPS.filter((s) => r.steps[s].tail).map((s) => (
+ <pre key={s} className="mt-2 max-h-64 overflow-auto rounded bg-black/30 p-2 text-[11px] leading-snug whitespace-pre-wrap">
+ {`[${s}]\n${r.steps[s].tail}`}
+ </pre>
+ ))}
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ );
+}
diff --git a/umtool/lib/drafts.ts b/umtool/lib/drafts.ts
@@ -0,0 +1,164 @@
+import { spawn } from "node:child_process";
+import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
+import os from "node:os";
+import path from "node:path";
+
+// Report drafts with no Claude Code (proof of concept, 2026-10-12). A page over
+// the scripts in ~/reports/local-reports (its RUNBOOK.html): a sweep by a local
+// model (bin/local-sweep, ollama) or by Claude on an API key (bin/api-sweep),
+// then the article, the narration draft and the video. Each step runs DETACHED,
+// its log and exit code in the run's directory, so a run outlives a restart and
+// its state is read off the disk, never kept in memory. Arguments reach the
+// scripts as argv, never through a shell string.
+
+export const LOCAL_REPORTS = process.env.LOCAL_REPORTS_DIR ?? path.join(os.homedir(), "reports/local-reports");
+const RUNS = path.join(LOCAL_REPORTS, "runs");
+
+export const MODELS = ["qwen3:8b", "claude-sonnet-5", "claude-opus-5-5"] as const;
+export const STEPS = ["sweep", "article", "narrate", "video"] as const;
+export type Step = (typeof STEPS)[number];
+
+export type RunMeta = {
+ name: string;
+ question: string;
+ channels: string;
+ model: string;
+ id: string;
+ terms?: string;
+ maxUsd?: number;
+ createdAt: string;
+};
+
+export type StepState = { state: "idle" | "running" | "done" | "failed"; exit?: number; tail?: string };
+export type RunView = RunMeta & {
+ steps: Record<Step, StepState>;
+ files: string[];
+ usd?: number;
+ narrationReview: string;
+};
+
+const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
+const CHANNELS = /^[a-z0-9_-]+(,[a-z0-9_-]+)*$/;
+
+export function runDir(name: string): string {
+ if (!NAME.test(name)) throw new Error(`bad run name: ${name}`);
+ return path.join(RUNS, name);
+}
+
+function stepState(dir: string, step: Step): StepState {
+ const log = path.join(dir, `ui-${step}.log`);
+ if (!existsSync(log)) return { state: "idle" };
+ const tail = readFileSync(log, "utf8").split("\n").slice(-14).join("\n");
+ const ex = path.join(dir, `ui-${step}.exit`);
+ if (!existsSync(ex)) return { state: "running", tail };
+ const exit = Number(readFileSync(ex, "utf8").trim());
+ return { state: exit === 0 ? "done" : "failed", exit, tail };
+}
+
+export function listRuns(): RunView[] {
+ if (!existsSync(RUNS)) return [];
+ const out: RunView[] = [];
+ for (const name of readdirSync(RUNS)) {
+ const dir = path.join(RUNS, name);
+ const metaFile = path.join(dir, "ui.json");
+ if (!existsSync(metaFile)) continue;
+ const meta = JSON.parse(readFileSync(metaFile, "utf8")) as RunMeta;
+ const steps = Object.fromEntries(STEPS.map((s) => [s, stepState(dir, s)])) as Record<Step, StepState>;
+ let usd: number | undefined;
+ try {
+ usd = JSON.parse(readFileSync(path.join(dir, "run.json"), "utf8")).usd_estimate;
+ } catch {}
+ out.push({
+ ...meta,
+ steps,
+ usd,
+ files: ["sweep.md", "review.html", "run.json"].filter((f) => existsSync(path.join(dir, f))),
+ narrationReview: `/browse/local-reports/videos/${meta.id}/narration`,
+ });
+ }
+ return out.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
+}
+
+export function createRun(input: {
+ name: string;
+ question: string;
+ channels: string;
+ model: string;
+ id?: string;
+ terms?: string;
+ maxUsd?: number;
+}): RunMeta {
+ const dir = runDir(input.name);
+ if (existsSync(path.join(dir, "ui.json"))) throw new Error(`run ${input.name} exists`);
+ if (!input.question.trim()) throw new Error("no question");
+ if (!CHANNELS.test(input.channels)) throw new Error("channels: comma-separated slugs");
+ if (!(MODELS as readonly string[]).includes(input.model)) throw new Error(`model: one of ${MODELS.join(", ")}`);
+ const id = input.id || input.name;
+ if (!NAME.test(id)) throw new Error(`bad article id: ${id}`);
+ mkdirSync(dir, { recursive: true });
+ const meta: RunMeta = {
+ name: input.name,
+ question: input.question.trim(),
+ channels: input.channels,
+ model: input.model,
+ id,
+ ...(input.terms ? { terms: input.terms } : {}),
+ ...(input.maxUsd ? { maxUsd: input.maxUsd } : {}),
+ createdAt: new Date().toISOString(),
+ };
+ writeFileSync(path.join(dir, "ui.json"), JSON.stringify(meta, null, 2));
+ return meta;
+}
+
+function argvFor(step: Step, m: RunMeta, dir: string, narrateModel: string): string[] {
+ const bin = (b: string) => path.join(LOCAL_REPORTS, "bin", b);
+ const claude = m.model.startsWith("claude-");
+ switch (step) {
+ case "sweep":
+ return claude
+ ? [bin("api-sweep"), m.question, "--channels", m.channels, "--id", m.id, "--out", dir, "--model", m.model,
+ "--max-usd", String(m.maxUsd ?? 5), ...(m.terms ? ["--terms", m.terms] : [])]
+ : [bin("local-sweep"), m.question, "--channels", m.channels, "--id", m.id, "--out", dir, "--model", m.model,
+ "--max-videos", "15", "--max-claims", "15", ...(m.terms ? ["--terms", m.terms] : [])];
+ case "article":
+ return [bin("local-article"), dir, m.id];
+ case "narrate":
+ return [bin("local-narrate"), path.join(LOCAL_REPORTS, "videos", m.id), "--model", narrateModel];
+ case "video":
+ return [bin("local-video"), m.id];
+ }
+}
+
+export function startStep(name: string, step: Step, narrateModel?: 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 argv = argvFor(step, meta, dir, nm);
+ const log = path.join(dir, `ui-${step}.log`);
+ const ex = path.join(dir, `ui-${step}.exit`);
+ rmSync(ex, { force: true });
+ writeFileSync(log, `$ ${argv.map((a) => a.replace(os.homedir(), "~")).join(" ")}\n`);
+ const tmp = path.join(os.homedir(), ".cache/local-reports");
+ mkdirSync(tmp, { recursive: true });
+ const child = spawn("bash", ["-c", '"$@" >> "$UI_LOG" 2>&1; echo $? > "$UI_EXIT"', "ui-step", ...argv], {
+ detached: true,
+ stdio: "ignore",
+ env: { ...process.env, UI_LOG: log, UI_EXIT: ex, TMPDIR: tmp, PYTHONDONTWRITEBYTECODE: "1" },
+ });
+ child.unref();
+}
+
+/** Whether Claude can be asked: a key in the env or the key file (claude_api.py reads the same two). */
+export function apiKeyReady(): boolean {
+ return !!process.env.ANTHROPIC_API_KEY || existsSync(path.join(os.homedir(), ".config/archilyzer/anthropic.env"));
+}
+
+/** A run's own output files, read for the page (sweep.md, review.html, run.json only). */
+export function runFile(name: string, file: string): { body: string; type: string } | null {
+ if (!["sweep.md", "review.html", "run.json"].includes(file)) return null;
+ const p = path.join(runDir(name), file);
+ if (!existsSync(p) || !statSync(p).isFile()) return null;
+ const type = file.endsWith(".html") ? "text/html" : file.endsWith(".json") ? "application/json" : "text/plain";
+ return { body: readFileSync(p, "utf8"), type: `${type}; charset=utf-8` };
+}