commit 50b456765b142f4c8a7c9d765880a012fec79768
parent 4883a601c9f2a0e74b3df229ebb96768aa2b96c5
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 11 Nov 2026 07:22:29 -0500
umtool: /settings/generation shows, per task, its route, the model it will run on, "no API key configured", and its last run's model (demo epic D3, item 3)
The policy's routes row becomes a table: each task's route (the same
selects, the same labels), the model the policy will run it on
(plannedModelOf: the route's model, a frame scan's vision model, "a Claude
Code session" on code), a "no API key configured" badge when it would call
the API with neither ANTHROPIC_API_KEY nor the key file there, and the
model(s) of its newest job in the usage ledger (lastRunsByTask; local runs
are in it since item 1). Nothing new is configured: the table reads what
the policy and the ledger already say.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat:
8 files changed, 168 insertions(+), 22 deletions(-)
diff --git a/common/controller/generationUsage.test.ts b/common/controller/generationUsage.test.ts
@@ -26,3 +26,19 @@ test("the usage ledger: rows appended, the day's total read back, a torn line sk
await rm(dir, { recursive: true, force: true });
}
});
+
+test("lastRunsByTask (demo epic D3): each task's newest job, its models and route; a frame scan's job is the frames task", async () => {
+ const { lastRunsByTask } = await import("./generationUsage");
+ const row = (task: string, jobId: string, model: string, at: string, route?: "local") => ({ at, day: at.slice(0, 10), jobId, article: "a", iteration: 1, task, model, inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, usd: 0, ...(route ? { route } : {}) });
+ const out = lastRunsByTask([
+ row("sweep", "j1", "claude-sonnet-5-5", "2026-11-01T10:00:00Z"),
+ row("sweep", "j1", "claude-haiku-4-5", "2026-11-01T10:00:00Z"),
+ row("sweep", "j2", "qwen3:8b", "2026-11-02T10:00:00Z", "local"),
+ row("narrate", "j3", "qwen3:8b", "2026-11-01T09:00:00Z", "local"),
+ row("frame-scan", "j4", "claude-haiku-4-5", "2026-11-03T09:00:00Z"),
+ ]);
+ assert.deepEqual(out.sweep, { at: "2026-11-02T10:00:00Z", jobId: "j2", models: ["qwen3:8b"], route: "local" });
+ assert.deepEqual(out.narrate!.models, ["qwen3:8b"]);
+ assert.deepEqual(out.frames, { at: "2026-11-03T09:00:00Z", jobId: "j4", models: ["claude-haiku-4-5"], route: "api" });
+ assert.equal(out["revise-report"], undefined);
+});
diff --git a/common/controller/generationUsage.ts b/common/controller/generationUsage.ts
@@ -98,3 +98,31 @@ export function usageModelsOf(rows: readonly GenerationUsageRow[]): UsageModel[]
}
return [...by.values()].map(({ ids, ...m }) => ({ ...m, jobs: ids.size })).sort((a, b) => a.route.localeCompare(b.route) || b.jobs - a.jobs || a.model.localeCompare(b.model));
}
+
+// The task a ledger row is of, as settings.generation names it (a frame
+// scan's job writes "frame-scan").
+const TASK_ALIASES: Record<string, string> = { "frame-scan": "frames" };
+
+// Each task's last run in the ledger (demo epic D3, the settings page): the
+// newest job of the task, the models it called and on which route.
+export type LastRun = { at: string; jobId: string; models: string[]; route: "api" | "local" | "mixed" };
+
+export function lastRunsByTask(rows: readonly GenerationUsageRow[]): Record<string, LastRun> {
+ const jobs = new Map<string, { task: string; at: string; models: Set<string>; routes: Set<"api" | "local"> }>();
+ for (const r of rows) {
+ if (!r.jobId || !r.task) continue;
+ const task = TASK_ALIASES[r.task] ?? r.task;
+ const j = jobs.get(`${task}\u0000${r.jobId}`) ?? { task, at: r.at, models: new Set<string>(), routes: new Set<"api" | "local">() };
+ j.models.add(r.model);
+ j.routes.add(isLocalUsage(r) ? "local" : "api");
+ if (r.at > j.at) j.at = r.at;
+ jobs.set(`${task}\u0000${r.jobId}`, j);
+ }
+ const out: Record<string, LastRun> = {};
+ for (const [key, j] of jobs) {
+ const jobId = key.slice(key.indexOf("\u0000") + 1);
+ if (out[j.task] && out[j.task]!.at >= j.at) continue;
+ out[j.task] = { at: j.at, jobId, models: [...j.models].sort(), route: j.routes.size > 1 ? "mixed" : [...j.routes][0]! };
+ }
+ return out;
+}
diff --git a/common/lib/generationSettings.test.ts b/common/lib/generationSettings.test.ts
@@ -196,3 +196,12 @@ test("claim groups for a cut (lane L4): local in every preset but api; a file fr
}
assert.equal(sanitizeGeneration({}).routes["propose-groups"], "local");
});
+
+test("plannedModelOf (demo epic D3): a task's route and the model it will run on; code has none; a frame scan's vision model; the API needs a key", async () => {
+ const { plannedModelOf, sanitizeGeneration } = await import("./generationSettings");
+ const gen = sanitizeGeneration({ routes: { sweep: "code", narrate: "local", "revise-report": "api", frames: "local" }, models: { api: "claude-sonnet-5-5", local: "qwen2.5:7b" } });
+ assert.deepEqual(plannedModelOf(gen, "sweep"), { route: "code", model: null, needsKey: false });
+ assert.deepEqual(plannedModelOf(gen, "narrate"), { route: "local", model: "qwen2.5:7b", needsKey: false });
+ assert.deepEqual(plannedModelOf(gen, "revise-report"), { route: "api", model: "claude-sonnet-5-5", needsKey: true });
+ assert.deepEqual(plannedModelOf(gen, "frames"), { route: "local", model: "qwen2.5vl:7b", needsKey: false });
+});
diff --git a/common/lib/generationSettings.ts b/common/lib/generationSettings.ts
@@ -406,6 +406,17 @@ function sanitizeVerdicts(v: unknown): GenerationVerdicts {
return { bar: { agreement: frac(b.agreement), contradictedRecall: frac(b.contradictedRecall), notFoundRecall: frac(b.notFoundRecall) }, models, window };
}
+// The model a task will run on as the policy stands (demo epic D3, the
+// settings page's per-task row): its route's model — a frame scan's the
+// vision model of its route — or none on `code` (a Claude Code session
+// answers it). `needsKey`: the Claude API is called, so a key must be there.
+export function plannedModelOf(gen: GenerationSettings, task: GenerationTask): { route: GenerationRoute; model: string | null; needsKey: boolean } {
+ const route = gen.routes[task];
+ if (route === "code") return { route, model: null, needsKey: false };
+ const model = task === "frames" ? (route === "api" ? gen.frames.apiModel : gen.frames.localModel) : route === "api" ? gen.models.api : gen.models.local;
+ return { route, model, needsKey: route === "api" };
+}
+
export function presetOf(routes: GenerationRoutes): GenerationPreset | "custom" {
return GENERATION_PRESET_NAMES.find((p) => GENERATION_TASKS.every((t) => routes[t] === GENERATION_PRESETS[p][t])) ?? "custom";
}
diff --git a/umtool/app/settings/generation/page.tsx b/umtool/app/settings/generation/page.tsx
@@ -1,5 +1,5 @@
import { getPaths } from "yt-dlp-transcript-common/lib/paths";
-import { readGenerationUsage, utcDay } from "yt-dlp-transcript-common/controller/generationUsage";
+import { lastRunsByTask, readGenerationUsage, utcDay } from "yt-dlp-transcript-common/controller/generationUsage";
import PolicyPanel from "@/components/articles/PolicyPanel";
import AppShell from "@/components/shell/AppShell";
import { Panel } from "@/components/ui/panel";
@@ -53,7 +53,7 @@ export default async function GenerationPage() {
<main className="deck-main flex-1 p-4">
<div className="grid items-start gap-3 xl:grid-cols-[minmax(0,1fr)_360px]">
{policy ? (
- <PolicyPanel initial={policy} today={today} />
+ <PolicyPanel initial={policy} today={today} lastRuns={lastRunsByTask(rows)} />
) : (
<Panel title="Policy">
<p role="alert" className="m-0 text-[12.5px] text-reject-text" data-policy-error="">
diff --git a/umtool/components/articles/PolicyPanel.tsx b/umtool/components/articles/PolicyPanel.tsx
@@ -4,6 +4,10 @@ import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { badgeVariants } from "@/components/ui/badge";
import type { PolicyView } from "@/lib/articles/generation";
+import { plannedModelOf, type GenerationTask } from "yt-dlp-transcript-common/lib/generationSettings";
+
+/** A task's last run, from the usage ledger (demo epic D3). */
+export type TaskLastRun = { at: string; jobId: string; models: string[]; route: "api" | "local" | "mixed" };
// THE GENERATION POLICY (release 27 S8): where each task runs (Claude Code,
// the API, the local model), the presets that set all four at once, the
@@ -22,10 +26,13 @@ export const usd = (v: number) => `$${v.toFixed(2)}`;
export default function PolicyPanel({
initial,
today: initialToday,
+ lastRuns = {},
onChange,
}: {
initial: PolicyView;
today: Today | null;
+ /** Each task's last run (the ledger's newest job of it). */
+ lastRuns?: Record<string, TaskLastRun>;
onChange?: (p: PolicyView) => void;
}) {
const [policy, setPolicy] = useState(initial);
@@ -86,27 +93,65 @@ export default function PolicyPanel({
</div>
<div className="mt-3 grid gap-x-6 gap-y-2 sm:grid-cols-[auto_1fr]">
+ {/* Per task (demo epic D3): the route, the model it will run on as the
+ policy stands, "no API key configured" when it would call the API
+ with none, and the model(s) of its last run in the ledger. */}
<div className="micro pt-1">routes</div>
- <div className="flex flex-wrap gap-x-4 gap-y-1">
- {policy.tasks.map((t) => (
- <label key={t} className="flex items-center gap-1.5">
- <span className="text-[var(--color-dim)]">{t}</span>
- <select
- aria-label={`route ${t}`}
- className={field}
- value={g.routes[t as keyof typeof g.routes]}
- disabled={busy}
- onChange={(e) => save({ routes: { ...g.routes, [t]: e.target.value } }, `route ${t}`)}
- >
- {policy.routes.map((r) => (
- <option key={r} value={r}>
- {ROUTE_LABEL[r] ?? r}
- </option>
- ))}
- </select>
- </label>
- ))}
- </div>
+ <table className="w-full border-collapse text-left" data-policy-tasks="">
+ <thead>
+ <tr className="text-[11px] text-[var(--color-dim)]">
+ <th className="py-0.5 pr-3 font-normal">task</th>
+ <th className="py-0.5 pr-3 font-normal">route</th>
+ <th className="py-0.5 pr-3 font-normal">will run on</th>
+ <th className="py-0.5 font-normal">last run</th>
+ </tr>
+ </thead>
+ <tbody>
+ {policy.tasks.map((t) => {
+ const plan = plannedModelOf(g, t as GenerationTask);
+ const noKey = plan.needsKey && !policy.apiKey.configured;
+ const last = lastRuns[t];
+ return (
+ <tr key={t} data-task={t} data-task-route={plan.route} className="border-t border-[var(--color-line)]">
+ <td className="py-0.5 pr-3 text-[var(--color-dim)]">{t}</td>
+ <td className="py-0.5 pr-3">
+ <select
+ aria-label={`route ${t}`}
+ className={field}
+ value={g.routes[t as keyof typeof g.routes]}
+ disabled={busy}
+ onChange={(e) => save({ routes: { ...g.routes, [t]: e.target.value } }, `route ${t}`)}
+ >
+ {policy.routes.map((r) => (
+ <option key={r} value={r}>
+ {ROUTE_LABEL[r] ?? r}
+ </option>
+ ))}
+ </select>
+ </td>
+ <td className="py-0.5 pr-3" data-task-model={plan.model ?? ""}>
+ {plan.model ? <span className="font-mono">{plan.model}</span> : <span className="text-[var(--color-dim)]">a Claude Code session</span>}
+ {noKey && (
+ <span data-task-no-key="" className={`ml-2 ${badgeVariants({ variant: "blocking", size: "sm" })}`}>
+ no API key configured
+ </span>
+ )}
+ </td>
+ <td className="py-0.5" data-task-last={last ? last.models.join(" ") : ""}>
+ {last ? (
+ <span title={`job ${last.jobId}`}>
+ <span className="font-mono">{last.models.join(", ")}</span>
+ <span className="text-[var(--color-dim)]"> · {last.at.slice(0, 10)}</span>
+ </span>
+ ) : (
+ <span className="text-[var(--color-dim)]">none in the ledger</span>
+ )}
+ </td>
+ </tr>
+ );
+ })}
+ </tbody>
+ </table>
<div className="micro pt-1">models</div>
<div className="flex flex-wrap gap-x-4 gap-y-1">
@@ -198,6 +243,8 @@ export default function PolicyPanel({
<span className={badgeVariants({ variant: policy.keyFile.exists ? "info" : "blocking", size: "sm" })}>
{policy.keyFile.exists ? "file found" : "no file"}
</span>
+ {policy.apiKey.from === "env" && <span className="text-[var(--color-dim)]">ANTHROPIC_API_KEY is set</span>}
+ {!policy.apiKey.configured && <span data-api-key-none="">no API key configured: an API route cannot run</span>}
</div>
</div>
diff --git a/umtool/e2e/model-log.spec.ts b/umtool/e2e/model-log.spec.ts
@@ -143,3 +143,27 @@ test("no call recorded: the panel says what will appear (no AI needed)", async (
await expect(log(page).locator("[data-model-log-empty]")).toContainText("No model call recorded. When a model works on this, each call appears here");
await expect(log(page).locator("[data-model-log-count]")).toHaveAttribute("data-model-log-count", "0");
});
+
+test("settings: per task its route, the model it will run on, no API key when there is none, its last run's model", async ({ page }) => {
+ await page.goto(urls.generationPolicyHref());
+ const policy = page.getByRole("region", { name: "generation policy" });
+ const rows = policy.locator("[data-policy-tasks] tbody tr");
+ await expect(rows).toHaveCount(17);
+ for (const t of ["sweep", "narrate", "frames", "revise-report"]) {
+ const row = policy.locator(`[data-task='${t}']`);
+ const route = await row.getByRole("combobox", { name: `route ${t}` }).inputValue();
+ await expect(row).toHaveAttribute("data-task-route", route);
+ const model = await row.locator("[data-task-model]").getAttribute("data-task-model");
+ if (route === "code") {
+ expect(model).toBe("");
+ await expect(row.locator("[data-task-model]")).toHaveText("a Claude Code session");
+ } else expect(model, `${t} on ${route}`).toMatch(route === "api" ? /^claude-/ : /^qwen/);
+ // No key on the e2e machine (its key file is never written): an API route says so.
+ const keyed = (await policy.locator("[data-key-file-exists]").getAttribute("data-key-file-exists")) === "yes";
+ await expect(row.locator("[data-task-no-key]")).toHaveCount(route === "api" && !keyed ? 1 : 0);
+ }
+ // The ledger's fixture row: the sweep's last run was on Sonnet 5.5.
+ await expect(policy.locator("[data-task='sweep'] [data-task-last]")).toHaveAttribute("data-task-last", "claude-sonnet-5-5");
+ await expect(policy.locator("[data-task='threads'] [data-task-last]")).toHaveText("none in the ledger");
+ await shot(page, "settings-generation");
+});
diff --git a/umtool/lib/articles/generation.ts b/umtool/lib/articles/generation.ts
@@ -181,6 +181,11 @@ export type PolicyView = {
routes: readonly string[];
/** The key file's path (as configured, `~` kept) and whether a file is there. Never its content. */
keyFile: { path: string; exists: boolean };
+ /**
+ * Whether an API key is there to use (demo epic D3): ANTHROPIC_API_KEY in
+ * this process's environment, else the key file. Never the key.
+ */
+ apiKey: { configured: boolean; from: "env" | "file" | null };
/** The models a picker offers: Claude's priced ones, and the local route's. */
models: { api: string[]; local: string[] };
};
@@ -210,6 +215,11 @@ function keyFileExists(p: string): boolean {
}
}
+function apiKeyOf(keyPath: string): PolicyView["apiKey"] {
+ if ((process.env.ANTHROPIC_API_KEY ?? "").trim()) return { configured: true, from: "env" };
+ return keyFileExists(keyPath) ? { configured: true, from: "file" } : { configured: false, from: null };
+}
+
export async function readPolicy(): Promise<PolicyView> {
const answer = await askEditor<{ value?: unknown }>("/api/ops/settings?key=generation");
const raw = (answer.value ?? {}) as Record<string, unknown>;
@@ -225,6 +235,7 @@ export async function readPolicy(): Promise<PolicyView> {
tasks: GENERATION_TASKS,
routes: GENERATION_ROUTES,
keyFile: { path: keyPath, exists: keyFileExists(keyPath) },
+ apiKey: apiKeyOf(keyPath),
models: { api, local },
};
}