commit 7041fa1a3ae05eb696e9ea100ecd27a4cdfb711c
parent e6a89d54e14926d18112669392ca94b39337a2e7
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 4 Nov 2026 22:47:05 -0500
umtool: the surfaces -- /jobs, the Takes panel's render records and queue, the rail's link
- /jobs (app/jobs/page.tsx): the queue (each step: state, label, what it waits on, its
error, its full log, Cancel / Retry -- steps are added from a terminal, never here), every
take render recorded in the last 7 days across projects (render.json via the queue dir's
pointers), and the app's own jobs. Refreshed while something runs, silent otherwise.
- The Takes page: a take's card shows its render record when it says more than the take
(rendering now: stage, percent, segments; or a later render that failed or was
cancelled: the error, the log's last lines, the log); a first render that FAILED is
listed in the open with its error and Delete (takeWorkDirs' `failed`); the project's
queue steps, when it has any.
- GET/POST /api/queue (cancel, retry), GET /api/queue/log, GET /api/report/takes/render
(the record, or ?log=1 the full render.log).
- The rail's "Running" heading links /jobs.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
15 files changed, 574 insertions(+), 10 deletions(-)
diff --git a/umtool/app/api/queue/log/route.ts b/umtool/app/api/queue/log/route.ts
@@ -0,0 +1,18 @@
+import { readFile } from "node:fs/promises";
+import { queueDir } from "@/lib/queue/runner";
+import { isQid, logFileOf } from "@/lib/queue/store.mjs";
+
+export const dynamic = "force-dynamic";
+
+// GET ?qid=<qid>[&attempt=<n>] a queue step's FULL log, as text (what
+// `umtool queue log <qid>` prints). The path is built from the qid alone.
+export async function GET(request: Request) {
+ const url = new URL(request.url);
+ const qid = url.searchParams.get("qid");
+ if (!isQid(qid)) return new Response("?qid=<qid>", { status: 400 });
+ const n = url.searchParams.get("attempt");
+ const attempt = n && /^[1-9][0-9]{0,3}$/.test(n) ? Number(n) : null;
+ const text = await readFile(/* turbopackIgnore: true */ logFileOf(queueDir(), qid, attempt), "utf8").catch(() => null);
+ if (text === null) return new Response(`no log for ${qid}${attempt ? ` attempt ${attempt}` : ""} (yet)`, { status: 404, headers: { "content-type": "text/plain; charset=utf-8" } });
+ return new Response(text, { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" } });
+}
diff --git a/umtool/app/api/queue/route.ts b/umtool/app/api/queue/route.ts
@@ -0,0 +1,40 @@
+import { kickQueue } from "@/lib/queue/runner";
+import { cancelStep, isQid, retryStep } from "@/lib/queue/store.mjs";
+import { queueDir } from "@/lib/queue/runner";
+import { queueView } from "@/lib/queue/view";
+
+export const dynamic = "force-dynamic";
+
+// THE DURABLE QUEUE (lib/queue/store.mjs), for /jobs and the Takes panel.
+//
+// GET [?project=<id>][&all=1] { dir, runner, steps }: the runner (is the app
+// running the queue, and since when) and the
+// steps, newest first (not finished, or finished
+// in the last day; all=1 every one)
+// POST ?cancel=<qid> | ?retry=<qid> what `umtool queue cancel|retry` do
+//
+// Steps are ADDED from a terminal (`umtool queue add -- <argv…>`), never here:
+// a step is a command line, and a page that took one would run whatever it was
+// sent.
+const noStore = { "cache-control": "no-store" };
+
+export async function GET(request: Request) {
+ const url = new URL(request.url);
+ const view = await queueView({ project: url.searchParams.get("project"), all: url.searchParams.get("all") === "1" });
+ return Response.json(view, { headers: noStore });
+}
+
+export async function POST(request: Request) {
+ const url = new URL(request.url);
+ const cancel = url.searchParams.get("cancel");
+ const retry = url.searchParams.get("retry");
+ const qid = cancel ?? retry;
+ if (!isQid(qid)) return Response.json({ error: "?cancel=<qid> or ?retry=<qid>" }, { status: 400 });
+ try {
+ const r = cancel ? await cancelStep(queueDir(), qid, { by: "the umtool app (/jobs)" }) : await retryStep(queueDir(), qid);
+ kickQueue();
+ return Response.json({ ok: true, said: r.said }, { headers: noStore });
+ } catch (e) {
+ return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 409 });
+ }
+}
diff --git a/umtool/app/api/report/takes/render/route.ts b/umtool/app/api/report/takes/render/route.ts
@@ -0,0 +1,30 @@
+import { readFile } from "node:fs/promises";
+import path from "node:path";
+import { projectRef } from "@/lib/projects";
+import { RENDER_LOG } from "@/lib/report/renderRecord.mjs";
+import { isTakeId } from "@/lib/report/takes.mjs";
+import { takeRender } from "@/lib/queue/view";
+
+export const dynamic = "force-dynamic";
+
+// A TAKE'S RENDER RECORD (lib/report/renderRecord.mjs), what `umtool take
+// status` reads:
+//
+// GET ?project=<id>&take=<id> the record, resolved (a running one whose
+// process is gone reads failed), or 404
+// GET ?project=<id>&take=<id>&log=1 takes/<id>/render.log, FULL, as text
+export async function GET(request: Request) {
+ const url = new URL(request.url);
+ const project = await projectRef(url.searchParams.get("project") ?? "");
+ if (!project) return Response.json({ error: "no such project" }, { status: 404 });
+ const take = url.searchParams.get("take");
+ if (!isTakeId(take)) return Response.json({ error: "not a take id" }, { status: 400 });
+ if (url.searchParams.get("log") === "1") {
+ const text = await readFile(/* turbopackIgnore: true */ path.join(project.dir, "takes", take, RENDER_LOG), "utf8").catch(() => null);
+ if (text === null) return new Response(`take ${take} has no render log`, { status: 404, headers: { "content-type": "text/plain; charset=utf-8" } });
+ return new Response(text, { headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" } });
+ }
+ const rec = await takeRender(project.dir, take);
+ if (!rec) return Response.json({ error: `take ${take} has no render record` }, { status: 404 });
+ return Response.json(rec, { headers: { "cache-control": "no-store" } });
+}
diff --git a/umtool/app/jobs/page.tsx b/umtool/app/jobs/page.tsx
@@ -0,0 +1,51 @@
+import type { Metadata } from "next";
+import AppShell from "@/components/shell/AppShell";
+import LiveRefresh from "@/components/queue/LiveRefresh";
+import QueuePanel from "@/components/queue/QueuePanel";
+import RenderRecord from "@/components/queue/RenderRecord";
+import { ActivityPanel } from "@/components/system/Status";
+import { Panel } from "@/components/ui/panel";
+import { listActivity, runningActivity } from "@/lib/activity";
+import { queueView, rendersView } from "@/lib/queue/view";
+
+export const dynamic = "force-dynamic";
+export const metadata: Metadata = { title: "Jobs · umtool" };
+
+// JOBS (4 Nov 2026, "the apps do the work"): what `umtool jobs` prints, on a
+// page -- the durable queue (lib/queue/: each step, its state, its error, its
+// full log, Cancel and Retry), every recent take render's own record (takes/
+// <id>/render.json, whoever started it: a terminal, the Takes page, the queue),
+// and the app's in-memory jobs. Read from disk on every request; refreshed
+// while something runs, silent when nothing does.
+
+export default async function JobsPage() {
+ const [queue, renders] = await Promise.all([queueView(), rendersView()]);
+ const running = runningActivity();
+ const recent = listActivity(12);
+ const live = renders.some((r) => r.state === "running" || r.state === "waiting");
+ return (
+ <div className="flex h-full flex-col">
+ <AppShell active="jobs" crumbs={[{ label: "Jobs" }]} />
+ <LiveRefresh live={live} />
+ <main className="deck-main flex-1 space-y-3 p-4" data-jobs-page="">
+ <Panel title="Queue" data-panel="queue" aside={<span className="text-muted-2">{queue.steps.length} step{queue.steps.length === 1 ? "" : "s"} · umtool queue ls</span>}>
+ <QueuePanel initial={{ runner: queue.runner, steps: queue.steps }} emptyText="Nothing queued, running or finished in the last day." />
+ </Panel>
+ <Panel title="Take renders" data-panel="renders" aside={<span className="text-muted-2">the last 7 days · umtool take status</span>}>
+ {renders.length === 0 ? (
+ <p className="m-0 text-[12px] text-[var(--color-dim)]" data-renders-empty="">
+ No take render recorded in the last 7 days.
+ </p>
+ ) : (
+ <div className="space-y-1.5">
+ {renders.map((r) => (
+ <RenderRecord key={`${r.project}:${r.take}`} project={r.project ?? ""} rec={r} showProject compact={r.state === "done"} />
+ ))}
+ </div>
+ )}
+ </Panel>
+ <ActivityPanel running={running} recent={recent} />
+ </main>
+ </div>
+ );
+}
diff --git a/umtool/components/projects/TakeVariants.tsx b/umtool/components/projects/TakeVariants.tsx
@@ -4,6 +4,8 @@ import Link from "next/link";
import { useRouter } from "next/navigation";
import { useState } from "react";
import DeletePlan from "@/components/DeletePlan";
+import RenderRecord from "@/components/queue/RenderRecord";
+import type { RenderView } from "@/lib/queue/view";
import { buttonVariants } from "@/components/ui/button";
import { takesCompareHref, takesHref } from "@/lib/hrefs";
@@ -19,6 +21,8 @@ export type CompareOption = { ref: string; label: string };
export type WorkDirs = {
rendering: Array<{ id: string; label: string | null; pid: number | null; startedAt: string | null; from: string | null }>;
cancelled: Array<{ id: string; label: string | null; at: string; by: string }>;
+ /** First renders that failed: their own record says so (lib/report/renderRecord.mjs). */
+ failed?: Array<{ id: string; label: string | null; record: RenderView }>;
};
const sm = buttonVariants({ size: "sm" });
@@ -184,7 +188,8 @@ export function TakeWorkDirs({ project, dirs, ready }: { project: string; dirs:
const router = useRouter();
const [show, setShow] = useState(false);
const [said, setSaid] = useState<CancelSaid | null>(null);
- if (!dirs.rendering.length && !dirs.cancelled.length && !said) return null;
+ const failed = dirs.failed ?? [];
+ if (!dirs.rendering.length && !dirs.cancelled.length && !failed.length && !said) return null;
return (
<section data-take-workdirs="" className="space-y-1.5 text-[12px]">
<CancelSaidLine said={said} />
@@ -203,6 +208,23 @@ export function TakeWorkDirs({ project, dirs, ready }: { project: string; dirs:
</span>
</div>
))}
+ {failed.map((f) => (
+ // A first render that failed: never a take, its error and its log in the open (not folded).
+ <div key={f.id} data-take-failed={f.id} className="space-y-1">
+ <div className="flex flex-wrap items-center gap-2">
+ <span className="micro text-reject-text">first render failed</span>
+ <span className="font-mono">{f.id}</span>
+ {f.label && <span className="text-text-2">{f.label}</span>}
+ <span className="text-[11px] text-[var(--color-dim)]">
+ never finished: no take · <code className="font-mono">umtool take status {project} --id {f.id}</code>
+ </span>
+ <span className="ml-auto">
+ <DeletePlan label={`Delete take ${f.id}`} subject={`the failed take ${f.id}`} endpoint="/api/report/takes/delete" body={{ project, take: f.id }} onDone={() => router.refresh()} />
+ </span>
+ </div>
+ <RenderRecord project={project} rec={f.record} />
+ </div>
+ ))}
{dirs.cancelled.length > 0 && (
<p className="m-0 text-[11px] text-[var(--color-dim)]" data-cancelled-count={dirs.cancelled.length}>
{dirs.cancelled.length} cancelled render{dirs.cancelled.length === 1 ? "" : "s"} {show ? "shown" : "folded away"} ·{" "}
diff --git a/umtool/components/projects/TakesBench.tsx b/umtool/components/projects/TakesBench.tsx
@@ -11,6 +11,8 @@ import { badgeVariants, type BadgeVariants } from "@/components/ui/badge";
import { buttonVariants } from "@/components/ui/button";
import { fmtAgo, fmtBytes } from "@/lib/format";
import { playHref, takeWalkHref } from "@/lib/hrefs";
+import RenderRecord from "@/components/queue/RenderRecord";
+import type { RenderView } from "@/lib/queue/view";
import { BenchBody, VerdictBar } from "./bench/BenchShell";
import { startTakeJob } from "./NewTakePanel";
import TakeActions from "./TakeActions";
@@ -59,6 +61,12 @@ export type Take = {
latest?: boolean;
/** Its last render was cancelled (takes/<id>/cancelled.json, lib/report/takeCancel.mjs): the take kept is the one before. */
cancelled?: { at: string; by: string } | null;
+ /**
+ * Its render record (lib/report/renderRecord.mjs) when it says more than the
+ * take does: a render running now, or a last render that failed or was
+ * cancelled after this take was built (the take kept is the one before).
+ */
+ render?: RenderView | null;
};
/** A take's work files, as `GET /api/report/takes/prune` measures them (lib/report/takePrune.mjs). */
@@ -763,6 +771,7 @@ function TakeCard({
</button>
</div>
{t.summary && <p className="text-[12px] text-[var(--color-text)]">{t.summary}</p>}
+ {t.render && <RenderRecord project={project} rec={t.render} compact />}
{t.changes.length > 0 && (
<ul className="list-disc pl-4 text-[11px] text-[var(--color-dim)]">
{t.changes.map((c, i) => (
diff --git a/umtool/components/projects/TakesPage.tsx b/umtool/components/projects/TakesPage.tsx
@@ -18,6 +18,9 @@ import { readCancelled, takeWorkDirs } from "@/lib/report/takeCancel.mjs";
import { variantFamily } from "@/lib/report/variantFork.mjs";
import { REPORTS_ROOT } from "@/lib/paths.mjs";
import { TakeWorkDirs, type CompareOption } from "./TakeVariants";
+import QueuePanel from "@/components/queue/QueuePanel";
+import LiveRefresh from "@/components/queue/LiveRefresh";
+import { queueView, takeRender } from "@/lib/queue/view";
// `/browse/<project>/takes` -- alternative renders of one part of the cut,
// watched side by side and judged like / maybe / no.
@@ -49,10 +52,13 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
const working = await readWorkingCut(project.dir, { manifestText, resolveNow: async (id) => (await resolveTakeManifest(project.dir, id)).manifest }).catch(() => null);
// Cancel, fork, compare (UI notes item 19): first renders in progress or cancelled, each take's
// last-render-cancelled mark, and every take of the project and its variants (variantFork.mjs).
- const [workDirs, cancelledMarks, family] = await Promise.all([
+ // Every render records itself (lib/report/renderRecord.mjs), and the queue holds what waits to run (lib/queue/).
+ const [workDirs, cancelledMarks, family, renders, queue] = await Promise.all([
takeWorkDirs(project.dir),
Promise.all((listing.takes as Take[]).map(async (t) => [t.id, await readCancelled(project.dir, t.id)] as const)).then((xs) => new Map(xs)),
variantFamily(project, { root: REPORTS_ROOT }).catch(() => ({ parent: project.id, members: [] })),
+ Promise.all((listing.takes as Take[]).map(async (t) => [t.id, await takeRender(project.dir, t.id)] as const)).then((xs) => new Map(xs)),
+ queueView({ project: project.id }),
]);
const compareOptions: CompareOption[] = family.members.flatMap((m) =>
(m.takes as Array<{ id: string; label: string; draft?: boolean }>).map((t) => ({
@@ -66,7 +72,12 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
const c = cancelledMarks.get(t.id);
// A cancel after the take was last built (a rebuild stopped): the take kept is the one from before.
const cancelled = c && (!t.builtAt || c.at > t.builtAt) ? { at: String(c.at), by: String(c.by ?? "") } : null;
- return { ...t, stale: t.baseHash ? t.baseHash !== current : null, holds: holds.get(t.id) ?? [], latest: t.id === working?.latest?.id, cancelled };
+ // The record, when it says more than the take: rendering now, or a later render that did not make it.
+ const rec = renders.get(t.id) ?? null;
+ const live = rec && (rec.state === "running" || rec.state === "waiting");
+ const later = rec && (rec.state === "failed" || rec.state === "cancelled") && (!t.builtAt || rec.startedAt > t.builtAt);
+ const render = live || later ? rec : null;
+ return { ...t, stale: t.baseHash ? t.baseHash !== current : null, holds: holds.get(t.id) ?? [], latest: t.id === working?.latest?.id, cancelled, render };
});
const byId = new Map(takes.map((t) => [t.id, t]));
const panel =
@@ -80,6 +91,15 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
/>
) : null;
const judged = takes.filter((t) => verdicts[t.id]?.verdict).length;
+ // The project's queue steps (lib/queue/): shown when it has any.
+ const liveRenders = [...renders.values()].some((r) => r && (r.state === "running" || r.state === "waiting"));
+ const queuePanel =
+ queue.steps.length > 0 ? (
+ <section data-takes-queue="" className="space-y-1">
+ <h2 className="micro m-0">Queue — {project.id}</h2>
+ <QueuePanel initial={{ runner: queue.runner, steps: queue.steps }} project={project.id} />
+ </section>
+ ) : null;
// The piece this view belongs to: the article's when an article claims the project (P4a-2).
const back = await pieceHrefOfProject(project.id, { tab: "cut" });
@@ -113,7 +133,9 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
>
{takes.length === 0 ? (
<BenchBody workClassName="space-y-4">
+ <LiveRefresh live={liveRenders} />
{panel}
+ {queuePanel}
<TakeWorkDirs project={project.id} dirs={workDirs} ready />
<p data-takes-empty="" className="text-[12px] text-[var(--color-dim)]">
No takes yet.{" "}
@@ -165,7 +187,9 @@ export default async function TakesPage({ project }: { project: ProjectRef }) {
)}
</p>
)}
+ <LiveRefresh live={liveRenders} />
{panel}
+ {queuePanel}
</>
}
>
diff --git a/umtool/components/queue/LiveRefresh.tsx b/umtool/components/queue/LiveRefresh.tsx
@@ -0,0 +1,19 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { useEffect } from "react";
+
+// Refresh the server-rendered page every `ms` while `live` (a render records
+// itself as it goes: its stage and percent move on disk). An idle page makes no
+// requests at all, as NowLive's rule says.
+export default function LiveRefresh({ live, ms = 4000 }: { live: boolean; ms?: number }) {
+ const router = useRouter();
+ useEffect(() => {
+ if (!live) return;
+ const t = setInterval(() => {
+ if (document.visibilityState !== "hidden") router.refresh();
+ }, ms);
+ return () => clearInterval(t);
+ }, [live, ms, router]);
+ return null;
+}
diff --git a/umtool/components/queue/QueuePanel.tsx b/umtool/components/queue/QueuePanel.tsx
@@ -0,0 +1,151 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { useEffect, useRef, useState } from "react";
+import { badgeVariants, type BadgeVariants } from "@/components/ui/badge";
+import { buttonVariants } from "@/components/ui/button";
+import { queueLogHref } from "@/lib/hrefs";
+import type { RunnerView, StepView } from "@/lib/queue/view";
+
+// THE DURABLE QUEUE (lib/queue/store.mjs), as a list: the runner (is the umtool
+// app running it), then each step -- its qid, state, label, what it waits on,
+// its error, its full log, and Cancel / Retry. Steps are added from a terminal
+// (`umtool queue add -- <argv…>`), never here.
+//
+// Polls GET /api/queue every 3 s ONLY while a step is queued or running (an
+// idle page makes no requests), and asks the page to refresh when a step
+// finishes, so the render records beside it catch up.
+
+export const QUEUE_POLL_MS = 3000;
+
+const TONE: Record<StepView["state"], BadgeVariants["variant"]> = {
+ queued: "info",
+ running: "meter",
+ done: "on",
+ failed: "blocking",
+ blocked: "open",
+ cancelled: "state",
+};
+
+type View = { runner: RunnerView; steps: StepView[] };
+
+const clock = (iso: string | null) => (iso ? iso.slice(11, 16) : "");
+
+export default function QueuePanel({ initial, project = null, emptyText = "Nothing queued." }: { initial: View; project?: string | null; emptyText?: string }) {
+ const router = useRouter();
+ const [view, setView] = useState<View>(initial);
+ const [said, setSaid] = useState<{ text: string; ok: boolean } | null>(null);
+ const [ready, setReady] = useState(false);
+ const inflight = useRef(false);
+ const current = useRef(view);
+ current.current = view;
+ useEffect(() => setReady(true), []);
+ useEffect(() => setView(initial), [initial]);
+
+ const live = view.steps.some((s) => s.state === "queued" || s.state === "running");
+ useEffect(() => {
+ if (!live) return;
+ const t = setInterval(async () => {
+ if (inflight.current || document.visibilityState === "hidden") return;
+ inflight.current = true;
+ try {
+ const r = await fetch(`/api/queue${project ? `?${new URLSearchParams({ project })}` : ""}`, { cache: "no-store" });
+ if (!r.ok) return;
+ const next = (await r.json()) as View;
+ const moved = current.current.steps.some((s) => (s.state === "running" || s.state === "queued") && next.steps.find((n) => n.qid === s.qid)?.state !== s.state);
+ setView(next);
+ if (moved) router.refresh();
+ } catch {
+ /* the next tick asks again */
+ } finally {
+ inflight.current = false;
+ }
+ }, QUEUE_POLL_MS);
+ return () => clearInterval(t);
+ }, [live, project, router]);
+
+ const act = async (op: "cancel" | "retry", qid: string) => {
+ const r = await fetch(`/api/queue?${new URLSearchParams({ [op]: qid })}`, { method: "POST", cache: "no-store" });
+ const j = (await r.json().catch(() => ({}))) as { said?: string; error?: string };
+ setSaid({ text: j.said ?? j.error ?? `HTTP ${r.status}`, ok: r.ok });
+ const v = await fetch(`/api/queue${project ? `?${new URLSearchParams({ project })}` : ""}`, { cache: "no-store" }).then((x) => (x.ok ? x.json() : null)).catch(() => null);
+ if (v) setView(v as View);
+ router.refresh();
+ };
+
+ const runner = view.runner;
+ return (
+ <div className="space-y-1.5" data-queue="" data-queue-project={project ?? ""}>
+ <p className="m-0 text-[11.5px] text-text-2" data-queue-runner={runner.live ? "live" : "none"}>
+ {runner.live ? (
+ <>
+ Run by the umtool app (pid {runner.pid}) one step at a time.
+ {runner.waiting ? <span className="text-[var(--color-dim)]"> {runner.waiting}.</span> : null}
+ </>
+ ) : (
+ <span className="text-reject-text">No runner: nothing in the queue runs until the umtool app is up (archilyzer-umtool.service).</span>
+ )}{" "}
+ <span className="text-[var(--color-dim)]">
+ Add steps from a terminal: <code className="font-mono">umtool queue add -- <command…></code>
+ </span>
+ </p>
+ {said && (
+ <p className={`m-0 text-[11.5px] ${said.ok ? "text-text-2" : "text-reject-text"}`} data-queue-said="">
+ {said.text}
+ </p>
+ )}
+ {view.steps.length === 0 ? (
+ <p className="m-0 text-[12px] text-[var(--color-dim)]" data-queue-empty="">
+ {emptyText}
+ </p>
+ ) : (
+ <ul className="m-0 list-none space-y-1 p-0">
+ {view.steps.map((s) => (
+ <li
+ key={s.qid}
+ data-queue-step={s.qid}
+ data-queue-state={s.state}
+ className={`space-y-0.5 rounded border px-2.5 py-1.5 text-[11.5px] ${s.state === "failed" || s.state === "blocked" ? "border-[var(--color-bad)]" : "border-seam"} bg-[var(--color-panel)]`}
+ >
+ <div className="flex flex-wrap items-baseline gap-2">
+ <span className="font-mono text-text">{s.qid}</span>
+ <span className={badgeVariants({ variant: TONE[s.state], size: "sm" })}>{s.state}</span>
+ <span className="min-w-0 truncate" title={`umtool ${s.argv.join(" ")}`} data-queue-label="">
+ {s.label}
+ </span>
+ {s.after && <span className="text-[11px] text-[var(--color-dim)]">after {s.after}</span>}
+ <span className="num text-[11px] text-[var(--color-dim)]" suppressHydrationWarning>
+ {s.startedAt ? `${clock(s.startedAt)}${s.endedAt ? `→${clock(s.endedAt)}` : ""}` : `queued ${clock(s.createdAt)}`}
+ {s.exitCode != null ? ` · exit ${s.exitCode}` : ""}
+ {s.attempts > 1 ? ` · attempt ${s.attempts}` : ""}
+ </span>
+ <span className="ml-auto inline-flex items-center gap-1.5">
+ {s.startedAt && (
+ <a href={queueLogHref(s.qid)} target="_blank" rel="noreferrer" className="ink-link text-[11px]" data-queue-log="">
+ log
+ </a>
+ )}
+ {(s.state === "queued" || s.state === "blocked" || (s.state === "running" && !s.cancelRequested)) && (
+ <button type="button" disabled={!ready} data-action="queue-cancel" className={buttonVariants({ variant: "outline", size: "sm" })} onClick={() => void act("cancel", s.qid)}>
+ Cancel
+ </button>
+ )}
+ {(s.state === "failed" || s.state === "cancelled") && (
+ <button type="button" disabled={!ready} data-action="queue-retry" className={buttonVariants({ variant: "outline", size: "sm" })} onClick={() => void act("retry", s.qid)}>
+ Retry
+ </button>
+ )}
+ </span>
+ </div>
+ {s.error && (
+ <p className="m-0 font-mono text-[11px] text-reject-text" data-queue-error="">
+ {s.error}
+ </p>
+ )}
+ </li>
+ ))}
+ </ul>
+ )}
+ </div>
+ );
+}
diff --git a/umtool/components/queue/RenderRecord.tsx b/umtool/components/queue/RenderRecord.tsx
@@ -0,0 +1,86 @@
+import Link from "next/link";
+import { badgeVariants, type BadgeVariants } from "@/components/ui/badge";
+import { takeRenderLogHref, takesHref } from "@/lib/hrefs";
+import type { RenderView } from "@/lib/queue/view";
+
+// A take's render RECORD (lib/report/renderRecord.mjs: takes/<id>/render.json,
+// written by every render whoever started it), as one block: its state, its
+// stage and percent while it runs, and when it failed the error, the log's
+// last lines (folded) and the full log. Server-safe: no hooks. Used by the
+// Takes panel (a take's card, a first render that failed) and /jobs.
+
+const TONE: Record<RenderView["state"], BadgeVariants["variant"]> = {
+ queued: "info",
+ waiting: "meter",
+ running: "meter",
+ done: "on",
+ failed: "blocking",
+ cancelled: "state",
+};
+
+const clock = (iso: string | null) => (iso ? iso.slice(0, 16).replace("T", " ") : "");
+
+export default function RenderRecord({
+ project,
+ rec,
+ showProject = false,
+ compact = false,
+}: {
+ project: string;
+ rec: RenderView;
+ /** /jobs: the project's takes page, linked. */
+ showProject?: boolean;
+ /** A take's card: one line, the tail folded. */
+ compact?: boolean;
+}) {
+ const live = rec.state === "running" || rec.state === "waiting";
+ const bad = rec.state === "failed" || rec.state === "cancelled";
+ return (
+ <div
+ data-render-record={rec.take}
+ data-render-project={project}
+ data-render-state={rec.state}
+ className={`space-y-1 rounded border px-2.5 py-1.5 text-[11.5px] ${bad ? "border-[var(--color-bad)]" : "border-seam"} bg-[var(--color-panel)]`}
+ >
+ <div className="flex flex-wrap items-baseline gap-2">
+ <span className={badgeVariants({ variant: TONE[rec.state], size: "sm" })} data-render-state-badge="">
+ {rec.state === "failed" ? "render failed" : rec.state === "cancelled" ? "render cancelled" : `render ${rec.state}`}
+ </span>
+ {showProject && (
+ <Link href={takesHref(project)} prefetch={false} className="ink-link font-mono">
+ {project}
+ </Link>
+ )}
+ <span className="font-mono">{rec.take}</span>
+ {rec.label && !compact && <span className="text-text-2">{rec.label}</span>}
+ {live && (
+ <span className="text-text-2" data-render-stage="">
+ {rec.stage ?? "…"}
+ {rec.percent != null ? ` · ${rec.percent}%` : ""}
+ {rec.entries?.of ? ` · ${rec.entries.done}/${rec.entries.of} segments` : ""}
+ </span>
+ )}
+ <span className="num text-[11px] text-[var(--color-dim)]" suppressHydrationWarning>
+ {clock(rec.startedAt)}
+ {rec.endedAt ? ` → ${rec.endedAt.slice(11, 16)}` : ""}
+ {rec.exitCode != null ? ` · exit ${rec.exitCode}` : ""}
+ {rec.state === "done" && rec.seconds != null ? ` · ${rec.seconds.toFixed(1)} s` : ""}
+ </span>
+ <a href={takeRenderLogHref(project, rec.take)} target="_blank" rel="noreferrer" className="ink-link ml-auto text-[11px]" data-render-log="">
+ log
+ </a>
+ </div>
+ {rec.error && (
+ <p className="m-0 font-mono text-[11px] text-reject-text" data-render-error="">
+ {rec.error}
+ </p>
+ )}
+ {bad && rec.tail?.length > 0 && (
+ <details data-render-tail="" open={!compact}>
+ <summary className="cursor-pointer text-[11px] text-[var(--color-dim)]">the log’s last {Math.min(rec.tail.length, 40)} lines</summary>
+ <pre className="m-0 mt-1 max-h-56 overflow-auto whitespace-pre-wrap break-all rounded bg-panel-2 p-1.5 text-[10.5px] leading-snug">{rec.tail.slice(-40).join("\n")}</pre>
+ </details>
+ )}
+ </div>
+ );
+}
diff --git a/umtool/components/shell/RunningList.tsx b/umtool/components/shell/RunningList.tsx
@@ -4,6 +4,7 @@ import Link from "next/link";
import { useEffect, useRef, useState } from "react";
import type { ActivityItem, RunningView } from "@/lib/activity-types";
import { JobProgressBar, JobProgressText } from "@/components/ui/job-progress";
+import { jobsHref } from "@/lib/hrefs";
// ---------------------------------------------------------------------------
// The rail's foot (canvas `.running`): what is running, umtool's own and the
@@ -120,7 +121,9 @@ export default function RunningList({ initial }: { initial: RunningView }) {
>
<h2 className="micro flex justify-between px-5 pb-2">
<span>
- Running{" "}
+ <Link href={jobsHref()} prefetch={false} className="text-inherit no-underline hover:text-text" data-rail-jobs="" title="Jobs: the queue, every take render's record, the app's jobs">
+ Running
+ </Link>{" "}
<span className="font-mono normal-case tracking-normal text-meter" data-running-count={view.running}>
{view.running}
</span>
diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts
@@ -187,6 +187,21 @@ export function settingsHref(): string {
return "/settings";
}
+/** Jobs: the durable queue (lib/queue/), the take renders' records, and the app's own jobs. */
+export function jobsHref(): string {
+ return "/jobs";
+}
+
+/** A queue step's full log, as text (GET /api/queue/log). */
+export function queueLogHref(qid: string, attempt: number | null = null): string {
+ return withQuery("/api/queue/log", { qid, ...(attempt ? { attempt: String(attempt) } : {}) });
+}
+
+/** A take render's full log, takes/<take>/render.log, as text (GET /api/report/takes/render). */
+export function takeRenderLogHref(project: string, take: string): string {
+ return withQuery("/api/report/takes/render", { project, take, log: "1" });
+}
+
/** Settings: the machine -- tools, disk, index, sources, deliverables, recent jobs. */
export function systemHref(): string {
return "/settings/system";
diff --git a/umtool/lib/queue/store.mjs b/umtool/lib/queue/store.mjs
@@ -67,6 +67,7 @@ export const LEASE_STALE_MS = 60_000;
export const KEEP_DAYS = 30;
export const QID = /^q[1-9][0-9]{0,8}$/;
+/** @param {unknown} v @returns {v is string} */
export const isQid = (v) => typeof v === "string" && QID.test(v);
/**
@@ -77,6 +78,7 @@ export const queueDirOf = ({ reportsRoot, env = process.env }) => queueDirFor(re
const stepsDir = (dir) => path.join(dir, "steps");
export const stepFile = (dir, qid) => path.join(stepsDir(dir), `${qid}.json`);
+/** @param {string} dir @param {string} qid @param {number | null} [attempt] */
export const logFileOf = (dir, qid, attempt = null) => path.join(dir, "logs", attempt ? `${qid}.${attempt}.log` : `${qid}.log`);
const leaseFile = (dir) => path.join(dir, "runner.json");
diff --git a/umtool/lib/queue/view.ts b/umtool/lib/queue/view.ts
@@ -0,0 +1,85 @@
+import path from "node:path";
+import { readRenderRecord } from "@/lib/report/renderRecord.mjs";
+import { recentRenders } from "./cli.mjs";
+import { queueDir, queueRunnerStatus } from "./runner";
+import { listSteps, readLease, resolveStep, TERMINAL } from "./store.mjs";
+
+// ---------------------------------------------------------------------------
+// What the pages show of the queue and the render records (/jobs, the Takes
+// panel, GET /api/queue): read from the queue dir and the takes' own
+// render.json, resolved as the CLI resolves them (a running step or render
+// whose process is gone reads failed). SERVER ONLY.
+// ---------------------------------------------------------------------------
+
+export type StepView = {
+ qid: string;
+ label: string;
+ argv: string[];
+ state: "queued" | "running" | "done" | "failed" | "blocked" | "cancelled";
+ after: string | null;
+ target: { project: string | null; take: string | null } | null;
+ createdAt: string;
+ startedAt: string | null;
+ endedAt: string | null;
+ exitCode: number | null;
+ error: string | null;
+ blockedBy: string | null;
+ attempts: number;
+ cancelRequested: { at: string; by: string } | null;
+};
+
+export type RenderView = {
+ project: string | null;
+ take: string;
+ label: string | null;
+ state: "queued" | "waiting" | "running" | "done" | "failed" | "cancelled";
+ startedAt: string;
+ endedAt: string | null;
+ exitCode: number | null;
+ stage: string | null;
+ percent: number | null;
+ entries?: { done: number; of: number | null };
+ error: string | null;
+ tail: string[];
+ mp4: string | null;
+ seconds: number | null;
+ pid: number;
+ gone?: boolean;
+};
+
+export type RunnerView = { live: boolean; pid: number | null; since: string | null; here: boolean; waiting: string | null; lastError: string | null };
+
+const DAY_MS = 86_400_000;
+
+/** The queue: the runner, and the steps (not finished, or finished in the last day; `all` every one). */
+export async function queueView({ project = null, all = false }: { project?: string | null; all?: boolean } = {}) {
+ const dir = queueDir();
+ const status = queueRunnerStatus();
+ const owned = new Set(status.running);
+ const [lease, raw] = await Promise.all([readLease(dir), listSteps(dir)]);
+ const cutoff = Date.now() - DAY_MS;
+ const steps = (raw as StepView[])
+ .map((s) => resolveStep(s, { owned }) as StepView)
+ .filter((s) => all || !TERMINAL.has(s.state) || Date.parse(s.endedAt ?? s.createdAt) > cutoff)
+ .filter((s) => !project || s.target?.project === project)
+ .reverse();
+ const runner: RunnerView = {
+ live: !!lease?.live,
+ pid: lease?.pid ?? null,
+ since: lease?.since ?? null,
+ here: !!lease?.live && lease.pid === process.pid,
+ waiting: status.waiting,
+ lastError: status.lastError,
+ };
+ return { dir, runner, steps };
+}
+
+/** The recent take renders across projects (the queue dir's pointers). */
+export async function rendersView(): Promise<RenderView[]> {
+ return (await recentRenders(queueDir())) as unknown as RenderView[];
+}
+
+/** One take's render record, resolved, or null. */
+export async function takeRender(projectDir: string, take: string): Promise<RenderView | null> {
+ return (await readRenderRecord(path.join(/* turbopackIgnore: true */ projectDir, "takes", take))) as RenderView | null;
+}
diff --git a/umtool/lib/report/takeCancel.mjs b/umtool/lib/report/takeCancel.mjs
@@ -134,19 +134,23 @@ export async function readCancelled(projectDir, takeId) {
/**
* The take directories that are not (or not yet) takes: a first render in
- * progress (a live build lock, no take.json) and a first render cancelled
- * (cancelled.json, no take.json). What the Takes page lists beside the takes:
- * the first with Cancel, the second folded away with Delete.
+ * progress (a live build lock, no take.json), a first render cancelled
+ * (cancelled.json, no take.json) and a first render that FAILED (its own
+ * record, renderRecord.mjs, says failed -- or says running and its process is
+ * gone). What the Takes page lists beside the takes: the first with Cancel,
+ * the second folded away with Delete, the third in the open with its error.
*
* @param {string} projectDir
* @param {{ host?: string, alive?: (pid: number) => boolean }} [opts]
- * @returns {Promise<{ rendering: Array<{ id: string, label: string | null, pid: number | null, startedAt: string | null, from: string | null }>, cancelled: Array<{ id: string, label: string | null, at: string, by: string }> }>}
+ * @returns {Promise<{ rendering: Array<{ id: string, label: string | null, pid: number | null, startedAt: string | null, from: string | null }>, cancelled: Array<{ id: string, label: string | null, at: string, by: string }>, failed: Array<{ id: string, label: string | null, record: any }> }>}
*/
export async function takeWorkDirs(projectDir, opts = {}) {
const root = takesDirOf(projectDir);
const names = await readdir(root).catch(() => []);
const rendering = [];
const cancelled = [];
+ const failed = [];
+ const { readRenderRecord } = await import("./renderRecord.mjs");
for (const id of names.sort()) {
if (!isTakeId(id)) continue;
const dir = path.join(root, id);
@@ -158,9 +162,14 @@ export async function takeWorkDirs(projectDir, opts = {}) {
continue;
}
const c = await readCancelled(projectDir, id);
- if (c) cancelled.push({ id, label: c.label ?? null, at: c.at, by: c.by ?? "" });
+ if (c) {
+ cancelled.push({ id, label: c.label ?? null, at: c.at, by: c.by ?? "" });
+ continue;
+ }
+ const rec = await readRenderRecord(dir);
+ if (rec && rec.state === "failed") failed.push({ id, label: rec.label ?? null, record: rec });
}
- return { rendering, cancelled };
+ return { rendering, cancelled, failed };
}
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));