Archilyzer · Source

archilyzer

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

commit c1db91b7f7b13e9299447eeb2fa26d9b25c38b19
parent 8d871c9f5da229a40cb20eef0ecc4c1df8408888
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu,  5 Nov 2026 17:31:20 -0500

umtool: Preview render and Render changes on the take card and Play -- queue steps of the fixed command (POST /api/report/takes/fast), their state inline, the output's local path with Copy, Play of the file

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

Diffstat:
Aumtool/app/api/report/takes/fast/route.ts | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/FastRenders.tsx | 158+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/TakesBench.tsx | 3+++
Mumtool/components/projects/review/PlayCut.tsx | 10++++++++++
4 files changed, 258 insertions(+), 0 deletions(-)

diff --git a/umtool/app/api/report/takes/fast/route.ts b/umtool/app/api/report/takes/fast/route.ts @@ -0,0 +1,87 @@ +import { readFile, stat } from "node:fs/promises"; +import path from "node:path"; +import { projectRef } from "@/lib/projects"; +import { kickQueue, queueDir } from "@/lib/queue/runner"; +import { addStep, listSteps, resolveStep } from "@/lib/queue/store.mjs"; +import { rangeResponse } from "@/lib/report/serve.mjs"; +import { fastKindOf, fastRenders, previewPaths } from "@/lib/report/takePreview.mjs"; +import { isTakeId } from "@/lib/report/takes.mjs"; + +export const dynamic = "force-dynamic"; + +// A TAKE'S FAST-FEEDBACK RENDERS (lib/report/takePreview.mjs): its preview at the preview tier and its +// changes reel, never its deliverable. +// +// GET ?project&take { preview, changes, from, steps }: each one's record and output +// (local path), the queue step still to run one, the take the +// reel compares with by default +// GET ?project&take&file=preview|changes the mp4, range-served (to a <video>) +// POST { project, take, kind: "preview" | "changes", from? } +// a queue step of the FIXED command (lib/queue/store.mjs addStep): +// umtool take <p> --id <t> --preview [--from <t0>] +// umtool take <p> --id <t> --changes [--from <t0>] +// built here from names, never a command line sent by the page +const noStore = { "cache-control": "no-store" }; + +async function slugOf(dir: string) { + return readFile(/* turbopackIgnore: true */ path.join(dir, "video.manifest.json"), "utf8").then((t) => String(JSON.parse(t).slug ?? ""), () => ""); +} + +async function takeDoc(dir: string, take: string) { + return readFile(/* turbopackIgnore: true */ path.join(dir, "takes", take, "take.json"), "utf8").then((t) => JSON.parse(t) as Record<string, unknown>, () => null); +} + +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 }); + const doc = await takeDoc(project.dir, take); + if (!doc) return Response.json({ error: `no take ${take}` }, { status: 404 }); + const slug = await slugOf(project.dir); + const file = url.searchParams.get("file"); + if (file) { + if (file !== "preview" && file !== "changes") return new Response("file is preview or changes", { status: 400 }); + const p = previewPaths(path.join(project.dir, "takes", take), slug); + const abs = file === "preview" ? p.previewMp4 : p.changesMp4; + const st = await stat(/* turbopackIgnore: true */ abs).catch(() => null); + if (!st?.isFile()) return new Response(`take ${take} has no ${file} render`, { status: 404 }); + return rangeResponse(request, { abs, size: st.size, headers: { "content-type": "video/mp4", "accept-ranges": "bytes", "cache-control": "private, no-store", "x-video-mtime": String(st.mtimeMs) } }); + } + const got = await fastRenders(path.join(project.dir, "takes", take), slug); + type Step = { qid: string; state: string; argv: string[]; error?: string | null; target?: { project?: string | null; take?: string | null } | null }; + const all = ((await listSteps(queueDir()).catch(() => [])) as Record<string, unknown>[]).map((s) => resolveStep(s) as unknown as Step); + const steps = all + .filter((s) => s.target?.project === project.id && s.target?.take === take && fastKindOf(s.argv)) + .map((s) => ({ qid: s.qid, state: s.state, kind: fastKindOf(s.argv), error: s.error ?? null })); + const from = typeof doc.from === "string" ? doc.from : typeof doc.draftedFrom === "string" ? doc.draftedFrom : null; + return Response.json({ take, from, ...got, steps }, { headers: noStore }); +} + +export async function POST(request: Request) { + const body = (await request.json().catch(() => null)) as { project?: unknown; take?: unknown; kind?: unknown; from?: unknown } | null; + const project = await projectRef(typeof body?.project === "string" ? body.project : ""); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + const take = body?.take; + if (!isTakeId(take)) return Response.json({ error: "not a take id" }, { status: 400 }); + const kind = body?.kind; + if (kind !== "preview" && kind !== "changes") return Response.json({ error: "kind is preview or changes" }, { status: 400 }); + const from = body?.from ?? null; + if (from !== null && (!isTakeId(from) || from === take)) return Response.json({ error: "from is another take's id" }, { status: 400 }); + if (!(await takeDoc(project.dir, take))) return Response.json({ error: `no take ${take}` }, { status: 404 }); + if (from && !(await takeDoc(project.dir, from))) return Response.json({ error: `no take ${from}` }, { status: 404 }); + const argv = ["take", project.id, "--id", take, kind === "preview" ? "--preview" : "--changes", ...(from ? ["--from", from] : [])]; + try { + const step = await addStep(queueDir(), { + argv, + label: `${kind === "preview" ? "preview" : "changes reel"} of ${take}${from ? ` (against ${from})` : ""}`, + target: { project: project.id, take }, + by: "the umtool app (Takes)", + }); + kickQueue(); + return Response.json({ ok: true, qid: step.qid, argv }, { headers: noStore }); + } catch (e) { + return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 409 }); + } +} diff --git a/umtool/components/projects/FastRenders.tsx b/umtool/components/projects/FastRenders.tsx @@ -0,0 +1,158 @@ +"use client"; + +import { useCallback, useEffect, useState } from "react"; +import { buttonVariants } from "@/components/ui/button"; + +// FAST FEEDBACK (lib/report/takePreview.mjs; operator, 5 Nov 2026): a take's two quick renders, each a +// step of the durable queue (POST /api/report/takes/fast, the fixed command `umtool take <p> --id <t> +// --preview | --changes [--from <t0>]`), their state inline, each output's local path with Copy, and the +// file itself played here. +// +// Preview render the whole take at the preview tier (1280×720, veryfast): out/<slug>.preview.mp4 +// Render changes only what changed against the take it was made from, each item ± 3 s, labelled +// with its time in the full cut: out/<slug>.changes.mp4 and changes.json +// +// Polls GET /api/report/takes/fast every 3 s only while a step is queued or a render runs. + +type Fast = { + state: string | null; + mp4: string | null; + mp4Bytes?: number | null; + seconds: number | null; + endedAt?: string | null; + error?: string | null; + log?: string | null; + list?: string | null; + items?: number | null; + from?: string | null; +} | null; + +type View = { take: string; from: string | null; preview: Fast; changes: Fast; steps: { qid: string; state: string; kind: "preview" | "changes"; error: string | null }[] }; + +const LIVE = new Set(["queued", "running", "waiting"]); + +function stateOf(kind: "preview" | "changes", v: View | null) { + const step = v?.steps.filter((s) => s.kind === kind).at(-1) ?? null; + const rec = v?.[kind] ?? null; + if (rec && (rec.state === "running" || rec.state === "waiting")) return { state: rec.state, step, rec }; + if (step && (step.state === "queued" || step.state === "running" || step.state === "blocked")) return { state: step.state, step, rec }; + return { state: rec?.state ?? null, step, rec }; +} + +function Copy({ text }: { text: string }) { + const [done, setDone] = useState(false); + return ( + <button + type="button" + data-action="copy-path" + className="ink-link text-[11px]" + onClick={() => { + void navigator.clipboard?.writeText(text).then(() => { + setDone(true); + setTimeout(() => setDone(false), 1500); + }, () => {}); + }} + > + {done ? "copied" : "Copy"} + </button> + ); +} + +export default function FastRenders({ project, take, compact = false }: { project: string; take: string; compact?: boolean }) { + const [view, setView] = useState<View | null>(null); + const [busy, setBusy] = useState<"preview" | "changes" | null>(null); + const [said, setSaid] = useState<string | null>(null); + const [playing, setPlaying] = useState<"preview" | "changes" | null>(null); + const [tick, setTick] = useState(0); + const load = useCallback(async () => { + const r = await fetch(`/api/report/takes/fast?${new URLSearchParams({ project, take })}`, { cache: "no-store" }).catch(() => null); + if (r?.ok) setView((await r.json()) as View); + }, [project, take]); + useEffect(() => { + void load(); + }, [load, tick]); + const live = (["preview", "changes"] as const).some((k) => LIVE.has(String(stateOf(k, view).state))); + useEffect(() => { + if (!live) return; + const t = setInterval(() => setTick((n) => n + 1), 3000); + return () => clearInterval(t); + }, [live]); + + const start = async (kind: "preview" | "changes") => { + setBusy(kind); + setSaid(null); + try { + const r = await fetch("/api/report/takes/fast", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, take, kind, ...(kind === "changes" && view?.from ? { from: view.from } : {}) }), + cache: "no-store", + }); + const j = (await r.json().catch(() => ({}))) as { error?: string; qid?: string }; + setSaid(r.ok ? `queued as ${j.qid}` : (j.error ?? `HTTP ${r.status}`)); + await load(); + } finally { + setBusy(null); + } + }; + + const row = (kind: "preview" | "changes", label: string, title: string) => { + const s = stateOf(kind, view); + const running = LIVE.has(String(s.state)); + const disabled = !!busy || running || (kind === "changes" && !view?.from); + return ( + <div key={kind} data-fast={kind} data-fast-state={s.state ?? "none"} className="flex flex-wrap items-center gap-1.5 text-[11px] text-[var(--color-dim)]"> + <button + type="button" + data-action={kind === "preview" ? "preview-render" : "render-changes"} + disabled={disabled} + title={kind === "changes" && !view?.from ? "this take does not record the take it was made from" : title} + onClick={() => void start(kind)} + className={buttonVariants({ size: "sm" })} + > + {label} + </button> + {s.state && ( + <span data-fast-said=""> + {s.step && running && s.step.state !== "running" ? `${s.state} (${s.step.qid})` : s.state} + {s.state === "failed" && s.rec?.error ? ` — ${s.rec.error}` : ""} + {s.state === "blocked" && s.step?.error ? ` — ${s.step.error}` : ""} + {s.state === "done" && s.rec?.seconds != null ? ` · ${Math.round(s.rec.seconds)} s` : ""} + {kind === "changes" && s.state === "done" && s.rec?.items != null ? ` · ${s.rec.items} piece(s) against ${s.rec.from}` : ""} + </span> + )} + {s.rec?.mp4 && !running && ( + <> + <code data-fast-path="" className="max-w-[28ch] truncate font-mono text-[10.5px]" title={s.rec.mp4}> + {s.rec.mp4} + </code> + <Copy text={s.rec.mp4} /> + <button type="button" data-action={`play-${kind}`} className="ink-link text-[11px]" onClick={() => setPlaying((p) => (p === kind ? null : kind))}> + {playing === kind ? "Hide" : "Play"} + </button> + </> + )} + </div> + ); + }; + + return ( + <div data-fast-renders={take} className={compact ? "flex flex-col gap-1" : "flex flex-col gap-1 border-t border-[var(--color-line)] pt-1.5"}> + {row("preview", "Preview render", "the whole take at 1280×720, fast: its full render untouched (umtool take … --preview)")} + {row("changes", "Render changes", `only what changed against ${view?.from ?? "its base"}, each item ± 3 s, labelled (umtool take … --changes)`)} + {said && <p data-fast-queued="" className="text-[11px] text-[var(--color-dim)]">{said}</p>} + {playing && view?.[playing]?.mp4 && ( + <video + data-fast-video={playing} + key={`${playing}-${view[playing]?.endedAt ?? ""}`} + src={`/api/report/takes/fast?${new URLSearchParams({ project, take, file: playing, v: String(view[playing]?.endedAt ?? "") })}`} + controls + autoPlay + preload="metadata" + playsInline + className="aspect-video w-full bg-black" + /> + )} + </div> + ); +} diff --git a/umtool/components/projects/TakesBench.tsx b/umtool/components/projects/TakesBench.tsx @@ -17,6 +17,7 @@ import type { RenderView } from "@/lib/queue/view"; import { BenchBody, VerdictBar } from "./bench/BenchShell"; import { startTakeJob } from "./NewTakePanel"; import TakeActions from "./TakeActions"; +import FastRenders from "./FastRenders"; import TakeTools from "./TakeTools"; import { Advanced, Options, PanelSlot } from "@/components/ui/disclosure"; import { CancelRender, CancelSaidLine, CompareWith, ForkVariant, TakeWorkDirs, type CancelSaid, type CompareOption, type WorkDirs } from "./TakeVariants"; @@ -832,6 +833,8 @@ function TakeCard({ compact /> )} + {/* Fast feedback (takePreview.mjs): a preview of the whole take, a reel of what changed -- queue steps. */} + <FastRenders project={project} take={t.id} /> {(t.holds ?? []).some((h) => h.startsWith("it is rendering")) && <CancelRender project={project} take={t.id} ready={ready} onSaid={setCancelSaid} />} <CancelSaidLine said={cancelSaid} /> {pickState?.stale && ( diff --git a/umtool/components/projects/review/PlayCut.tsx b/umtool/components/projects/review/PlayCut.tsx @@ -25,6 +25,7 @@ import { useWaveZoom, ZoomControls } from "../bench/GapsZoom"; import { followVis, itemSections } from "@/lib/report/stripDrag.mjs"; import RejectClip from "./RejectClip"; import WhatPlays, { type WorkingCut } from "./WhatPlays"; +import FastRenders from "../FastRenders"; import { useCutApp } from "../cutApp/CutApp"; import { ClipExportButtons, ClipExportStatus, useClipExport } from "../ClipExport"; import AddPost from "./AddPost"; @@ -1106,6 +1107,15 @@ export default function PlayCut({ <header className="flex flex-wrap items-center gap-x-4 gap-y-1.5 border-b border-seam px-4 py-2 max-md:-mx-4"> <h1 className="m-0 min-w-0 truncate font-display text-[17px] font-semibold tracking-[-0.01em] text-text">{view.title}</h1> <WhatPlays project={project} take={view.take} takes={view.takes} working={view.working ?? null} onNavigate={onNavigate} /> + {/* Fast feedback on the take playing (takePreview.mjs): its preview render and its changes reel, queued. */} + {view.take && ( + <details data-play-fast="" className="relative text-[11.5px]"> + <summary className="cursor-pointer text-muted hover:text-text">Fast render</summary> + <div className="absolute left-0 top-full z-30 mt-1 w-[min(420px,90vw)] rounded border border-seam bg-[var(--color-panel)] p-2 shadow-lg"> + <FastRenders project={project} take={view.take.id} compact /> + </div> + </details> + )} <span className="ml-auto font-mono text-[15px] tabular-nums text-text" data-play-clock=""> {runningTime(t)} <span className="text-muted">/ {runningTime(plan.total)}</span> </span>