Archilyzer · Source

archilyzer

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

commit b8a42f1391bfd59f34644291e819b62fe86d13c3
parent b45a59f0016134afa3b10140b49917e993de66b9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun,  1 Nov 2026 00:09:11 -0400

umtool: section bars and move-to-section on the Cut tab, flash-forward and Add to trailer in the clip editor, the Trailer page, take relabel/supersede in the takes list

The Cut tab draws a bar where each section opens (its colour, label, clip
count): dragged onto a clip, the boundary follows that clip; a clip dropped on
a bar opens that section; edit relabels and recolours it; remove boundary
joins it to the one before. Each clip row's menu has "move to section…" and
"new section here" (label and colour picker), and ticked clips move together.
POST /api/report/timeline section-move | section-add | section-boundary |
section-remove | section-set; GET returns the sections. CLI: umtool timeline
<p> sections | section-move | section-add | section-boundary |
section-remove | section-set, and split <id> <second>, flash-forward <id>
<from>-<to> (--after | --to-section) [--move].

Clip editor: "Flash-forward selection…" (where: the start of a section, or
after an entry; copy as a repeat, or move out of the clip) through the new
clip-editor op flash-forward (its quote read from the words), and "Add to
trailer" (the selection, else the cut).

/projects/<p>/trailer: the beats with each one's length and the running
length against the limit (X, Instagram, Shorts, TikTok, or seconds), the
crossfade and intro, beats outside their clip flagged with "fit to clip",
Order by the cut, add a beat, the walk's starred clips. GET/POST
/api/report/trailer-beats; CLI umtool trailer-beats. Linked from the Cut tab.

Takes list: relabel (pencil), Mark superseded (by a take) / Not superseded,
superseded takes folded away and shown dimmed on request (POST
/api/report/takes/housekeeping). CLI: umtool takes ls | relabel | supersede |
delete.

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

Diffstat:
Aumtool/app/api/report/takes/housekeeping/route.ts | 42++++++++++++++++++++++++++++++++++++++++++
Aumtool/app/api/report/trailer-beats/route.ts | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/bin/umtool.mjs | 14++++++++++++++
Mumtool/components/projects/ProjectView.tsx | 3+++
Mumtool/components/projects/TakesBench.tsx | 110++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Aumtool/components/projects/TrailerBeatsEditor.tsx | 313+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/TrailerPage.tsx | 24++++++++++++++++++++++++
Mumtool/components/projects/report/CutTab.tsx | 11++++++++++-
Mumtool/components/projects/review/ClipEditor.tsx | 42++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/review/CutEditing.tsx | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/hrefs.ts | 5+++++
Mumtool/lib/report/takeCli.mjs | 76+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mumtool/lib/report/trailerBeats.mjs | 35+++++++++++++++++++++++++++++++----
Aumtool/lib/report/trailerBeatsCli.mjs | 219+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14 files changed, 1127 insertions(+), 10 deletions(-)

diff --git a/umtool/app/api/report/takes/housekeeping/route.ts b/umtool/app/api/report/takes/housekeeping/route.ts @@ -0,0 +1,42 @@ +import { projectRef } from "@/lib/projects"; +import { isTakeId, listTakes, setTakeSuperseded } from "@/lib/report/takes.mjs"; +import { relabelTake } from "@/lib/report/takeEdit.mjs"; +import { renderHolds } from "@/lib/report/takeHousekeeping.mjs"; + +export const dynamic = "force-dynamic"; + +// TAKE HOUSEKEEPING (UI notes 2026-10-30, item 19) -- the takes list's +// Relabel and Superseded; Delete is /api/report/takes/delete. +// +// POST { project, take, op: "relabel", label } take.json's label (an undo +// point of the take's own), +// refused while it renders +// POST { project, take, op: "supersede", by?: <take> } verdicts.json: folded away +// POST { project, take, op: "unsupersede" } the mark cleared +// +// The CLI's twins: `umtool takes relabel | supersede [--clear]`. +export async function POST(request: Request) { + const body = (await request.json().catch(() => null)) as { project?: string; take?: string; op?: string; label?: string; by?: string | null } | null; + if (!body || typeof body !== "object") return Response.json({ error: "bad json" }, { status: 400 }); + if (!isTakeId(body.take)) return Response.json({ error: "take must be a take id" }, { status: 400 }); + const take = body.take; + const project = await projectRef(String(body.project ?? "")); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + const known = (await listTakes(project.dir)).takes.map((t) => t.id); + if (!known.includes(take)) return Response.json({ error: "no such take" }, { status: 404 }); + try { + if (body.op === "relabel") { + const r = await relabelTake(project.dir, take, String(body.label ?? ""), { holds: await renderHolds(project.dir, take) }); + return Response.json({ ok: true, take, label: r.label, was: r.was, revision: r.revision?.rel ?? null }, { headers: { "cache-control": "no-store" } }); + } + if (body.op === "supersede" || body.op === "unsupersede") { + const by = typeof body.by === "string" && body.by ? body.by : null; + const r = await setTakeSuperseded(project.dir, take, { by, clear: body.op === "unsupersede", known }); + return Response.json({ ok: true, take, ...r }, { headers: { "cache-control": "no-store" } }); + } + return Response.json({ error: "op must be relabel, supersede or unsupersede" }, { status: 400 }); + } catch (e) { + const message = e instanceof Error ? e.message : String(e); + return Response.json({ error: message, ...(/changed since/.test(message) ? { stale: true } : {}) }, { status: /rendering now|being rendered/.test(message) ? 409 : 400 }); + } +} diff --git a/umtool/app/api/report/trailer-beats/route.ts b/umtool/app/api/report/trailer-beats/route.ts @@ -0,0 +1,96 @@ +import { resolveReport } from "@/lib/report/serve.mjs"; +import { refuseCaller } from "@/lib/report/caller"; +import { + BeatsStale, + TRAILER_LIMITS, + addTrailerBeat, + beatsToken, + introSecondsOf, + moveTrailerBeat, + orderTrailerBeats, + readTrailerBeats, + removeTrailerBeat, + setTrailerSettings, + trailerCandidatesOf, + trailerView, + updateTrailerBeat, +} from "@/lib/report/trailerBeats.mjs"; + +export const dynamic = "force-dynamic"; + +// THE TRAILER'S BEATS (UI notes 2026-10-30, item 11): promo/trailer-beats.json +// through its one writer (lib/report/trailerBeats.mjs), the Trailer page's and +// Add to trailer's -- `umtool trailer-beats` is the CLI's twin. +// +// GET ?project=<id> the view (each beat's length, the running length against +// the limit, beats outside their clip, the cut's order), the +// ★ candidates, the cut's clips, the platform limits, the token +// POST { project, token, op, … } +// add { beat: { id, start, end, label? } | { at, dur }, at? } (default: the cut's order) +// set { index, patch: { start?, end?, at?, dur?, label? } } +// remove { index } +// move { index, to } +// order {} the cut's order +// settings { limit?, xfade?, intro? } null: the default again +// A stale token is a 409. + +const noStore = { "cache-control": "no-store" }; + +async function view(dir: string, manifest: Record<string, unknown>) { + const doc = await readTrailerBeats(dir); + const v = trailerView(manifest, doc, { introSeconds: doc.settings?.intro ? await introSecondsOf(dir) : null }); + const clips = ((manifest.timeline ?? []) as Record<string, unknown>[]) + .filter((e) => e?.type === "clip") + .map((e) => ({ id: String(e.id), start: Number(e.cutStart ?? e.start), end: Number(e.cutEnd ?? e.end) })); + return { ...v, candidates: trailerCandidatesOf(manifest, doc.beats), clips, limits: TRAILER_LIMITS, token: await beatsToken(dir), exists: doc.exists }; +} + +export async function GET(request: Request) { + const url = new URL(request.url); + const r = await resolveReport(url.searchParams.get("project") ?? ""); + if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); + try { + return Response.json(await view(r.project.dir, r.manifest), { headers: noStore }); + } catch (e) { + return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400 }); + } +} + +export async function POST(request: Request) { + const refused = refuseCaller(request, "/api/report/trailer-beats"); + if (refused) return refused; + const body = (await request.json().catch(() => null)) as Record<string, unknown> | null; + if (!body || typeof body !== "object") return Response.json({ error: "expected JSON" }, { status: 400 }); + const r = await resolveReport(String(body.project ?? "")); + if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); + const dir = r.project.dir; + const token = typeof body.token === "string" ? body.token : null; + try { + switch (body.op) { + case "add": + await addTrailerBeat(dir, (body.beat ?? {}) as Record<string, unknown>, { token, at: typeof body.at === "number" ? body.at : null, manifest: r.manifest }); + break; + case "set": + await updateTrailerBeat(dir, Number(body.index), (body.patch ?? {}) as Record<string, unknown>, { token }); + break; + case "remove": + await removeTrailerBeat(dir, Number(body.index), { token }); + break; + case "move": + await moveTrailerBeat(dir, Number(body.index), Number(body.to), { token }); + break; + case "order": + await orderTrailerBeats(dir, r.manifest, { token }); + break; + case "settings": + await setTrailerSettings(dir, Object.fromEntries(["limit", "xfade", "intro"].filter((k) => k in body).map((k) => [k, body[k]])), { token }); + break; + default: + return Response.json({ error: "op must be add, set, remove, move, order or settings" }, { status: 400 }); + } + return Response.json({ ok: true, ...(await view(dir, r.manifest)) }, { headers: noStore }); + } catch (e) { + if (e instanceof BeatsStale) return Response.json({ error: e.message, stale: true }, { status: 409 }); + return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400 }); + } +} diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -70,9 +70,14 @@ // [--draft] record it without rendering (walk it first) · --id <id> --promote [--anyway] make it the cut // [--priority] render mode for the take's lifetime: the machine is the render's (AGENTS.md "Render mode") // umtool takes make <project> [--recipe F | --all-styles] | styles | pick <project> <take> [--anyway] +// | ls <project> | relabel <project> <take> <label> | supersede <project> <take> [--by T] [--clear] +// | delete <project> <take> [--dry-run] [--force] take housekeeping // umtool render-mode on [--for 90m] [--note T] | off [--force] | status [--json] render mode: a render gets the machine // umtool trailer <project> --take <t> (--beats F | --beats-json J) [--intro] [--finale S] [--xfade 0.3] // [--out NAME] [--dry-run] [--json] a trailer cut from the take's finished master +// umtool trailer-beats <project> [ls | add <clip> [<from>-<to>] | set <n> <from>-<to> | remove <n> | move <n> --to <m> +// | order | limit <s|m:ss|x> | xfade <s> | intro on|off | candidates [--add]] the trailer's beats +// (promo/trailer-beats.json): running length against the limit, beats outside their clip // umtool rulings <project> [import [--dry-run] | set <clip> <verdict> [--reason R] [--match M] | clear <clip>] // the clip deck's montage rulings (release 34) // umtool fetch <project> [--dry-run | --wait | --status | --body] [--reason R] the clip windows, asked of @@ -863,12 +868,19 @@ function usage() { " umtool take <project> --id <id> --promote [--anyway] make this the cut: the take's patch applied to the", " manifest, one undo point (revisions/…-auto-before-promote-take)", " umtool takes make <project> [--recipe F | --all-styles] | styles | pick <project> <take> [--anyway]", + " | ls <project> | relabel <project> <take> <label…> | supersede <project> <take> [--by <take>] [--clear]", + " | delete <project> <take> [--dry-run] [--force] take housekeeping: a label fixed, a take folded away", + " as superseded, a take deleted -- refused while a render names it", " umtool render-mode on [--for 90m] [--note T] | off [--force] | status [--json] render mode: a render the", " operator waits for gets the machine (other heavy jobs wait; the editor's transcription and", " download lanes held); `on` is a window for a chain of renders (default 2h)", " umtool trailer <project> --take <t> (--beats F | --beats-json J) [--intro] [--finale S] [--xfade 0.3] [--out NAME]", " a trailer cut from the take's finished master: the master's own frames, so the deck shows the", " whole timeline; beats are clip source seconds or master seconds ([--dry-run] the mapping only)", + " umtool trailer-beats <project> [ls] | add <clip> [<from>-<to>] [--at N] [--label L] | add-raw <at> <dur> | set <n> <from>-<to>", + " | remove <n> | move <n> --to <m> | order | limit <s|m:ss|x|instagram|shorts|tiktok> | xfade <s> | intro on|off", + " | candidates [--add] the trailer's beats (promo/trailer-beats.json, the Trailer page's file): each", + " beat's length, the running length against the platform limit (X 2:20), beats outside their clip", " umtool rulings <project> [--json] | import [--dry-run] | set <clip> keep|cut|not-him|read-aloud [--reason R] [--match M] | clear <clip>", " the clip deck's montage rulings (montage-rulings.json); a render leaves the ruled-out clips out", " umtool fetch <project> [--dry-run | --wait | --status | --body] [--reason R] [--json]", @@ -976,6 +988,8 @@ const COMMANDS = { links: async () => process.exit(await (await import("../lib/report/linksCli.mjs")).linksCommand(argv.slice(argv.indexOf("links") + 1))), // A take patch's markers back on the cut (UI notes #6): lib/report/linksCli.mjs. "patch-markers": async () => process.exit(await (await import("../lib/report/linksCli.mjs")).patchMarkersCommand(argv.slice(argv.indexOf("patch-markers") + 1))), + // The trailer's beats, edited (UI notes item 11): lib/report/trailerBeatsCli.mjs. + "trailer-beats": async () => process.exit(await (await import("../lib/report/trailerBeatsCli.mjs")).trailerBeatsCommand(argv.slice(argv.indexOf("trailer-beats") + 1))), // The clip deck's rulings (release 34): lib/report/rulingsCli.mjs. rulings: async () => process.exit(await (await import("../lib/report/rulingsCli.mjs")).rulingsCommand(argv.slice(argv.indexOf("rulings") + 1))), // Fetch windows and stand-ins (release 35 O1): lib/report/fetchCli.mjs, standInsCli.mjs. diff --git a/umtool/components/projects/ProjectView.tsx b/umtool/components/projects/ProjectView.tsx @@ -12,6 +12,7 @@ import ReviewPage from "./ReviewPage"; import ClipDeckPage from "./ClipDeckPage"; import PlayCutPage from "./PlayCutPage"; import TakeWalkPage from "./TakeWalkPage"; +import TrailerPage from "./TrailerPage"; import { isTakeId } from "@/lib/report/takes.mjs"; // --------------------------------------------------------------------------- @@ -80,6 +81,8 @@ export default async function ProjectView({ if (rest.length === 1 && rest[0] === "clips") return <ClipDeckPage project={project} show={search.show} mode={search.mode} clip={search.clip} />; // `/projects/<project>/play` -- the whole cut (or `?take=<id>`) played in // the browser in its final look, no render, with notes taken as it plays. + // `/projects/<project>/trailer` -- the trailer's beats (promo/trailer-beats.json). + if (rest.length === 1 && rest[0] === "trailer") return <TrailerPage project={project} />; if (rest.length === 1 && rest[0] === "play") return <PlayCutPage project={project} take={search.take} note={search.note} clip={search.clip} at={search.at} />; return notFound(); } diff --git a/umtool/components/projects/TakesBench.tsx b/umtool/components/projects/TakesBench.tsx @@ -76,7 +76,7 @@ type WorkPlan = { }; export type Verdict = "like" | "maybe" | "no"; -export type TakeVerdict = { verdict: Verdict | null; note: string; at: string; picked?: true }; +export type TakeVerdict = { verdict: Verdict | null; note: string; at: string; picked?: true; superseded?: { by: string | null; at: string } }; const KIND_TONE: Record<Take["kind"], BadgeVariants["variant"]> = { reference: "on", @@ -136,6 +136,9 @@ export default function TakesBench({ children?: React.ReactNode; }) { const [verdicts, setVerdicts] = useState(initial); + // Superseded takes (UI notes item 19) are folded away unless asked for. + const [showSuperseded, setShowSuperseded] = useState(false); + const allIds = groups.flatMap((g) => g.takes.map((t) => ({ id: t.id, label: t.label }))); const [listen, setListen] = useState<string | null>(null); const [ready, setReady] = useState(false); const videos = useRef(new Map<string, HTMLVideoElement>()); @@ -311,10 +314,23 @@ export default function TakesBench({ </button> </span> </div> + {(() => { + const hidden = g.takes.filter((t) => verdicts[t.id]?.superseded).length; + return hidden > 0 ? ( + <p className="mb-2 text-[11px] text-[var(--color-dim)]" data-superseded-count={hidden}> + {hidden} superseded take{hidden === 1 ? "" : "s"} {showSuperseded ? "shown, dimmed" : "folded away"} ·{" "} + <button type="button" data-action="show-superseded" aria-pressed={showSuperseded} onClick={() => setShowSuperseded((v) => !v)} className="ink-link"> + {showSuperseded ? "fold them away" : "show them"} + </button> + </p> + ) : null; + })()} <div className="grid grid-cols-1 gap-3 md:grid-cols-2 xl:grid-cols-3"> - {g.takes.map((t) => ( + {g.takes.filter((t) => showSuperseded || !verdicts[t.id]?.superseded).map((t) => ( <TakeCard key={t.id} + others={allIds.filter((o) => o.id !== t.id)} + onVerdicts={(v) => setVerdicts(v)} project={project} take={t} src={previewSrc(project, t)} @@ -462,6 +478,8 @@ function TakeWorkLine({ project, work: w, ready, onFreed }: { project: string; w } function TakeCard({ + others, + onVerdicts, project, take: t, src, @@ -477,6 +495,9 @@ function TakeCard({ work, onFreed, }: { + /** The project's other takes: what "superseded by" may name. */ + others: { id: string; label: string }[]; + onVerdicts: (verdicts: Record<string, TakeVerdict>) => void; project: string; take: Take; src: string; @@ -560,6 +581,32 @@ function TakeCard({ setBusy(false); if (r.error) setError(r.error); }; + // Housekeeping (UI notes item 19): relabel, superseded (POST /api/report/takes/housekeeping). + const [relabel, setRelabel] = useState<string | null>(null); + const [supBy, setSupBy] = useState<string>(verdict?.superseded?.by ?? ""); + const housekeeping = async (body: Record<string, unknown>) => { + setBusy(true); + setError(null); + try { + const r = await fetch("/api/report/takes/housekeeping", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, take: t.id, ...body }), + cache: "no-store", + }); + const j = (await r.json().catch(() => ({}))) as { error?: string; verdicts?: Record<string, TakeVerdict> }; + if (!r.ok) { + setError(j.error ?? `HTTP ${r.status}`); + return false; + } + if (j.verdicts) onVerdicts(j.verdicts); + router.refresh(); + return true; + } finally { + setBusy(false); + } + }; + const superseded = verdict?.superseded ?? null; const windowWords = t.window === "full" ? "full cut" : t.window ? `${t.window.at}–${t.window.at + t.window.dur} s` : null; // Walk a take: a draft is walked before it is rendered; a rendered take // walked since says its render is older than it (editedAt after builtAt). @@ -571,7 +618,8 @@ function TakeCard({ data-take={t.id} data-kind={t.kind} data-verdict={current ?? ""} - className="flex flex-col overflow-hidden rounded border bg-[var(--color-panel)]" + data-superseded={superseded ? (superseded.by ?? "") : undefined} + className={`flex flex-col overflow-hidden rounded border bg-[var(--color-panel)] ${superseded ? "opacity-60" : ""}`} style={{ borderColor: `var(--color-${hue ?? "line"})` }} > {t.previewSize != null ? ( @@ -604,7 +652,35 @@ function TakeCard({ )} <div className="flex flex-1 flex-col gap-1.5 px-3 py-2"> <div className="flex flex-wrap items-center gap-2"> - <h3 className="text-[13px] text-[var(--color-text)]">{t.label}</h3> + {relabel === null ? ( + <h3 className="text-[13px] text-[var(--color-text)]" data-take-label=""> + {t.label} + <button type="button" data-action="relabel" disabled={!ready || busy} onClick={() => setRelabel(t.label)} className="ml-1 text-[11px] text-[var(--color-dim)] hover:text-[var(--color-text)]" title="relabel this take (take.json's label)" aria-label={`relabel ${t.id}`}> + ✎ + </button> + </h3> + ) : ( + <span className="inline-flex flex-1 items-center gap-1"> + <input + autoFocus + data-take-relabel={t.id} + value={relabel} + maxLength={200} + onChange={(e) => setRelabel(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Escape") setRelabel(null); + if (e.key === "Enter") void housekeeping({ op: "relabel", label: relabel }).then((ok) => ok && setRelabel(null)); + }} + className="min-w-0 flex-1 rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 text-[12px] text-[var(--color-text)] outline-none focus:border-[var(--color-sel)]" + /> + <button type="button" data-action="relabel-save" disabled={busy || !relabel.trim()} onClick={() => void housekeeping({ op: "relabel", label: relabel }).then((ok) => ok && setRelabel(null))} className={buttonVariants({ variant: "go", size: "sm" })}> + Save + </button> + <button type="button" onClick={() => setRelabel(null)} className={buttonVariants({ variant: "quiet", size: "sm" })}> + Cancel + </button> + </span> + )} <span className={badgeVariants({ variant: KIND_TONE[t.kind], size: "sm" })}>{t.kind}</span> <span className="num text-[11px] text-[var(--color-dim)]" suppressHydrationWarning> {t.seconds != null && `${t.seconds.toFixed(1)} s`} @@ -617,6 +693,11 @@ function TakeCard({ picked </span> )} + {superseded && ( + <span data-take-superseded={superseded.by ?? ""} className={badgeVariants({ variant: "state", size: "sm" })}> + superseded{superseded.by ? ` by ${superseded.by}` : ""} + </span> + )} {t.draft && ( <span data-take-is-draft="" className={badgeVariants({ variant: "state", size: "sm" })}> draft @@ -749,6 +830,27 @@ function TakeCard({ </p> )} <TakeWorkLine project={project} work={work} ready={ready} onFreed={onFreed} /> + <div className="flex flex-wrap items-center gap-1.5 text-[11px]" data-take-housekeeping={t.id}> + {superseded ? ( + <button type="button" data-action="unsupersede" disabled={!ready || busy} onClick={() => void housekeeping({ op: "unsupersede" })} className={buttonVariants({ size: "sm" })}> + Not superseded + </button> + ) : ( + <> + <select data-take-superseded-by={t.id} value={supBy} disabled={!ready || busy || !!verdict?.picked} onChange={(e) => setSupBy(e.target.value)} className="rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1 py-0.5 text-[11px]" title={verdict?.picked ? "the picked take is not superseded" : "which take replaces this one"}> + <option value="">by (any later take)</option> + {others.map((o) => ( + <option key={o.id} value={o.id}> + {o.id} + </option> + ))} + </select> + <button type="button" data-action="supersede" disabled={!ready || busy || !!verdict?.picked} onClick={() => void housekeeping({ op: "supersede", by: supBy || null })} className={buttonVariants({ size: "sm" })}> + Mark superseded + </button> + </> + )} + </div> <div className="flex flex-wrap"> <DeletePlan label={`Delete take ${t.id}`} diff --git a/umtool/components/projects/TrailerBeatsEditor.tsx b/umtool/components/projects/TrailerBeatsEditor.tsx @@ -0,0 +1,313 @@ +"use client"; + +import { useCallback, useEffect, useState } from "react"; +import { buttonVariants } from "@/components/ui/button"; + +// The Trailer page's editor (TrailerPage.tsx): every write is POST +// /api/report/trailer-beats, the one writer `umtool trailer-beats` uses too. + +type Row = { + n: number; + kind: "clip" | "raw"; + id?: string; + start?: number; + end?: number; + at?: number; + dur?: number; + label: string | null; + seconds: number; + running: number; + over: boolean; + clip: { start: number; end: number; at: number; section: string | null; quote: string | null } | null; + problems: string[]; +}; +type View = { + file: string; + limit: number; + xfade: number; + intro: boolean; + introSeconds: number | null; + total: number; + remaining: number; + over: boolean; + inOrder: boolean; + outside: number; + rows: Row[]; + candidates: { id: string; start: number; end: number; quote: string | null; walkNote: string | null }[]; + clips: { id: string; start: number; end: number }[]; + limits: { id: string; label: string; seconds: number }[]; + token: string | null; + exists: boolean; +}; + +const clock = (s: number) => { + if (!Number.isFinite(s)) return "—"; + const m = Math.floor(Math.abs(s) / 60); + const r = Math.abs(s) - m * 60; + return `${s < 0 ? "−" : ""}${m}:${r < 10 ? "0" : ""}${r.toFixed(1)}`; +}; +const input = + "rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 font-mono text-[11px] text-[var(--color-text)] outline-none focus:border-[var(--color-sel)]"; + +export default function TrailerBeatsEditor({ project }: { project: string }) { + const [view, setView] = useState<View | null>(null); + const [error, setError] = useState<string | null>(null); + const [busy, setBusy] = useState(false); + const [addClip, setAddClip] = useState(""); + const [addFrom, setAddFrom] = useState(""); + const [addTo, setAddTo] = useState(""); + + const load = useCallback(async () => { + const r = await fetch(`/api/report/trailer-beats?project=${encodeURIComponent(project)}`, { cache: "no-store" }); + const j = await r.json().catch(() => ({})); + if (!r.ok) setError(j.error ?? `HTTP ${r.status}`); + else setView(j as View); + }, [project]); + useEffect(() => { + void load(); + }, [load]); + + const op = async (name: string, args: Record<string, unknown> = {}) => { + setBusy(true); + setError(null); + try { + const r = await fetch("/api/report/trailer-beats", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, token: view?.token ?? null, op: name, ...args }), + }); + const j = await r.json().catch(() => ({})); + if (!r.ok) { + setError(j.stale ? "the beats changed since this page read them — reloaded; try again" : (j.error ?? `HTTP ${r.status}`)); + if (j.stale) await load(); + return false; + } + setView(j as View); + return true; + } finally { + setBusy(false); + } + }; + + if (!view) return <p className="text-[12px] text-[var(--color-dim)]">{error ?? "reading the beats…"}</p>; + const pct = Math.min(100, (view.total / view.limit) * 100); + const preset = view.limits.find((l) => l.seconds === view.limit)?.id ?? "custom"; + const pickClip = (id: string) => { + setAddClip(id); + const c = view.clips.find((x) => x.id === id); + if (c) { + setAddFrom(String(c.start)); + setAddTo(String(c.end)); + } + }; + + return ( + <div data-testid="trailer-editor" className="space-y-3"> + {/* ---- the running length against the limit ---- */} + <section className="space-y-1.5 rounded border border-[var(--color-line)] bg-[var(--color-panel)] px-3 py-2"> + <div className="flex flex-wrap items-baseline gap-3"> + <span data-testid="trailer-total" data-over={view.over ? "1" : "0"} className={`num font-mono text-[20px] ${view.over ? "text-[var(--color-bad)]" : "text-[var(--color-text)]"}`}> + {clock(view.total)} + </span> + <span className="text-[12px] text-[var(--color-dim)]"> + of {clock(view.limit)} ·{" "} + {view.over ? <span className="text-[var(--color-bad)]">over by {(view.total - view.limit).toFixed(1)} s</span> : `${view.remaining.toFixed(1)} s to spare`} · {view.rows.length} beat + {view.rows.length === 1 ? "" : "s"} · crossfade {view.xfade} s{view.intro ? ` · intro ${view.introSeconds ?? "?"} s` : ""} + </span> + {view.outside > 0 && ( + <span data-testid="trailer-outside" className="text-[12px] text-[var(--color-bad)]"> + {view.outside} beat{view.outside === 1 ? "" : "s"} to fix + </span> + )} + </div> + <div className="h-2 w-full overflow-hidden rounded bg-[var(--color-ink)]" aria-hidden> + <div className="h-full" style={{ width: `${pct}%`, background: view.over ? "var(--color-bad)" : "var(--color-sel)" }} /> + </div> + <div className="flex flex-wrap items-center gap-2 text-[11px]"> + <label className="inline-flex items-center gap-1"> + limit + <select + data-testid="trailer-limit" + value={preset} + disabled={busy} + onChange={(e) => { + const l = view.limits.find((x) => x.id === e.target.value); + if (l) void op("settings", { limit: l.seconds }); + }} + className={input} + > + {view.limits.map((l) => ( + <option key={l.id} value={l.id}> + {l.label} + </option> + ))} + {preset === "custom" && <option value="custom">{clock(view.limit)} (custom)</option>} + </select> + </label> + <label className="inline-flex items-center gap-1"> + or seconds + <input + data-testid="trailer-limit-seconds" + defaultValue={view.limit} + key={`limit-${view.limit}`} + onKeyDown={(e) => e.key === "Enter" && void op("settings", { limit: Number((e.target as HTMLInputElement).value) })} + className={`${input} w-16`} + /> + </label> + <label className="inline-flex items-center gap-1"> + crossfade + <input + data-testid="trailer-xfade" + defaultValue={view.xfade} + key={`xfade-${view.xfade}`} + onKeyDown={(e) => e.key === "Enter" && void op("settings", { xfade: Number((e.target as HTMLInputElement).value) })} + className={`${input} w-12`} + /> + s + </label> + <label className="inline-flex items-center gap-1"> + <input type="checkbox" data-testid="trailer-intro" checked={view.intro} disabled={busy} onChange={(e) => void op("settings", { intro: e.target.checked })} /> + open on the brand intro + </label> + <button type="button" data-testid="trailer-order" disabled={busy || view.inOrder} onClick={() => void op("order")} className={buttonVariants({ size: "sm" })} title="put the beats in the order the cut plays their clips"> + {view.inOrder ? "in the cut's order" : "Order by the cut"} + </button> + {error && ( + <span data-testid="trailer-error" className="text-[var(--color-bad)]"> + {error} + </span> + )} + </div> + </section> + + {/* ---- the beats ---- */} + <section> + <h2 className="micro mb-1">beats — {view.file}</h2> + {view.rows.length === 0 ? ( + <p className="text-[12px] text-[var(--color-dim)]">No beats yet: add one below, from the ★ clips, or with Add to trailer in the clip editor.</p> + ) : ( + <ol className="m-0 list-none space-y-1 p-0"> + {view.rows.map((r, i) => ( + <BeatRow key={`${i}:${r.id ?? r.at}:${r.start ?? r.dur}`} row={r} index={i} last={i === view.rows.length - 1} busy={busy} op={op} /> + ))} + </ol> + )} + </section> + + {/* ---- add ---- */} + <section className="flex flex-wrap items-center gap-2 rounded border border-dashed border-[var(--color-line)] px-3 py-2 text-[11px]"> + <span className="micro">add a beat</span> + <select data-testid="trailer-add-clip" value={addClip} onChange={(e) => pickClip(e.target.value)} className={input}> + <option value="">clip…</option> + {view.clips.map((c, k) => ( + <option key={`${c.id}:${k}`} value={c.id}> + {c.id} ({c.start}–{c.end}) + </option> + ))} + </select> + <input data-testid="trailer-add-from" value={addFrom} placeholder="from" onChange={(e) => setAddFrom(e.target.value)} className={`${input} w-20`} /> + – + <input data-testid="trailer-add-to" value={addTo} placeholder="to" onChange={(e) => setAddTo(e.target.value)} className={`${input} w-20`} /> + <button + type="button" + data-testid="trailer-add" + disabled={busy || !addClip || !(Number(addTo) > Number(addFrom))} + onClick={() => void op("add", { beat: { id: addClip, start: Number(addFrom), end: Number(addTo) } }).then((ok) => ok && (setAddClip(""), setAddFrom(""), setAddTo("")))} + className={buttonVariants({ variant: "go", size: "sm" })} + > + Add + </button> + <span className="text-[var(--color-dim)]">it goes where the cut plays it</span> + </section> + + {/* ---- the walk's favourites ---- */} + <section data-testid="trailer-candidates"> + <h2 className="micro mb-1">★ from the walk — {view.candidates.length} not yet beats</h2> + {view.candidates.length === 0 ? ( + <p className="text-[11px] text-[var(--color-dim)]">Star a clip on the walk and it is offered here.</p> + ) : ( + <ul className="m-0 list-none space-y-1 p-0 text-[11.5px]"> + {view.candidates.map((c) => ( + <li key={c.id} data-candidate={c.id} className="flex flex-wrap items-baseline gap-2"> + <span className="font-mono">★ {c.id}</span> + <span className="num font-mono text-[var(--color-dim)]"> + {c.start}–{c.end} + </span> + {c.walkNote && <span className="text-[var(--color-text)]">{c.walkNote}</span>} + {c.quote && <span className="text-[var(--color-dim)]">&ldquo;{c.quote.slice(0, 100)}{c.quote.length > 100 ? "…" : ""}&rdquo;</span>} + <button type="button" disabled={busy} onClick={() => void op("add", { beat: { id: c.id, start: c.start, end: c.end } })} className={buttonVariants({ size: "sm" })}> + Add + </button> + </li> + ))} + </ul> + )} + </section> + <p className="text-[11px] text-[var(--color-dim)]"> + Cut it: <code className="font-mono">umtool trailer {project} --take &lt;take&gt;{view.intro ? " --intro" : ""} --beats &lt;project&gt;/{view.file} --xfade {view.xfade}</code> · the same edits:{" "} + <code className="font-mono">umtool trailer-beats {project}</code> + </p> + </div> + ); +} + +function BeatRow({ row: r, index: i, last, busy, op }: { row: Row; index: number; last: boolean; busy: boolean; op: (name: string, args?: Record<string, unknown>) => Promise<boolean> }) { + const [from, setFrom] = useState(String(r.kind === "clip" ? r.start : r.at)); + const [to, setTo] = useState(String(r.kind === "clip" ? r.end : r.dur)); + const save = () => { + const a = Number(from); + const b = Number(to); + if (!Number.isFinite(a) || !Number.isFinite(b)) return; + if (r.kind === "clip" && (a !== r.start || b !== r.end)) void op("set", { index: i, patch: { start: a, end: b } }); + if (r.kind === "raw" && (a !== r.at || b !== r.dur)) void op("set", { index: i, patch: { at: a, dur: b } }); + }; + const fit = () => { + if (!r.clip) return; + const a = Math.max(r.start ?? r.clip.start, r.clip.start); + const b = Math.min(r.end ?? r.clip.end, r.clip.end); + void op("set", { index: i, patch: b - a >= 0.5 ? { start: a, end: b } : { start: r.clip.start, end: r.clip.end } }); + }; + const bad = r.problems.length > 0; + return ( + <li + data-beat={r.n} + data-beat-id={r.id ?? ""} + data-beat-problem={bad ? "1" : "0"} + data-beat-over={r.over ? "1" : "0"} + className={`flex flex-wrap items-center gap-2 rounded border px-2 py-1 text-[11.5px] ${bad ? "border-[var(--color-bad)]" : "border-[var(--color-line)]"} bg-[var(--color-panel)]`} + > + <span className="num w-5 text-right font-mono text-[var(--color-dim)]">{r.n}</span> + <span className="w-14 font-mono text-[var(--color-text)]">{r.kind === "clip" ? r.id : "master"}</span> + <input data-beat-from={r.n} value={from} onChange={(e) => setFrom(e.target.value)} onBlur={save} onKeyDown={(e) => e.key === "Enter" && save()} className={`${input} w-20`} title={r.kind === "clip" ? "source second it starts at" : "master second"} /> + {r.kind === "clip" ? "–" : "for"} + <input data-beat-to={r.n} value={to} onChange={(e) => setTo(e.target.value)} onBlur={save} onKeyDown={(e) => e.key === "Enter" && save()} className={`${input} w-20`} title={r.kind === "clip" ? "source second it ends at" : "seconds"} /> + <span className="num w-14 text-right font-mono">{r.seconds.toFixed(2)} s</span> + <span className={`num w-14 text-right font-mono ${r.over ? "text-[var(--color-bad)]" : "text-[var(--color-dim)]"}`} title="the trailer's length at the end of this beat"> + {clock(r.running)} + </span> + {r.clip?.section && <span className="micro">{r.clip.section}</span>} + {bad && ( + <span data-beat-problems={r.n} className="text-[var(--color-bad)]"> + {r.problems.join("; ")} + </span> + )} + <span className="ml-auto flex items-center gap-1"> + {bad && r.clip && ( + <button type="button" data-beat-fit={r.n} disabled={busy} onClick={fit} className={buttonVariants({ size: "sm" })} title="pull the beat's edges inside the clip's window"> + fit to clip + </button> + )} + <button type="button" data-beat-up={r.n} disabled={busy || i === 0} onClick={() => void op("move", { index: i, to: i - 1 })} className={buttonVariants({ variant: "quiet", size: "sm" })}> + ↑ + </button> + <button type="button" data-beat-down={r.n} disabled={busy || last} onClick={() => void op("move", { index: i, to: i + 1 })} className={buttonVariants({ variant: "quiet", size: "sm" })}> + ↓ + </button> + <button type="button" data-beat-remove={r.n} disabled={busy} onClick={() => void op("remove", { index: i })} className={buttonVariants({ variant: "quiet", size: "sm" })}> + remove + </button> + </span> + {r.clip?.quote && <span className="basis-full truncate pl-7 text-[11px] text-[var(--color-dim)]">&ldquo;{r.clip.quote}&rdquo;</span>} + </li> + ); +} diff --git a/umtool/components/projects/TrailerPage.tsx b/umtool/components/projects/TrailerPage.tsx @@ -0,0 +1,24 @@ +import { BenchBody, BenchFrame, BenchTop } from "./bench/BenchShell"; +import { projectsHref } from "@/lib/hrefs"; +import { pieceHrefOfProject } from "@/lib/pieces/article"; +import type { ProjectRef } from "@/lib/project-types"; +import TrailerBeatsEditor from "./TrailerBeatsEditor"; + +// `/projects/<project>/trailer` -- the trailer's beats (UI notes 2026-10-30, +// item 11): promo/trailer-beats.json, its running length against the +// platform's limit, the beats outside their clips, the cut's order, the walk's +// ★ clips -- edited here, or by `umtool trailer-beats`. The trailer itself is +// cut by `umtool trailer <p> --take <t> --beats <that file>`. +export default async function TrailerPage({ project }: { project: ProjectRef }) { + const back = await pieceHrefOfProject(project.id, { tab: "cut" }); + return ( + <BenchFrame + kind="trailer" + top={<BenchTop trail={[{ href: projectsHref(), label: "Projects" }]} back={{ href: back, label: project.id }} kind="Trailer" here="beats" />} + > + <BenchBody workClassName="space-y-3"> + <TrailerBeatsEditor project={project.id} /> + </BenchBody> + </BenchFrame> + ); +} diff --git a/umtool/components/projects/report/CutTab.tsx b/umtool/components/projects/report/CutTab.tsx @@ -8,7 +8,8 @@ import { } from "@/lib/projects/report.mjs"; import { listTakes } from "@/lib/report/takes.mjs"; import { buttonVariants } from "@/components/ui/button"; -import { clipBenchHref, clipDeckHref, clipEditorHref, mixHref as toolsMixHref, playHref, projectHref, takeWalkHref, takesHref } from "@/lib/hrefs"; +import { clipBenchHref, clipDeckHref, clipEditorHref, mixHref as toolsMixHref, playHref, projectHref, takeWalkHref, takesHref, trailerHref } from "@/lib/hrefs"; +import { readTrailerBeats } from "@/lib/report/trailerBeats.mjs"; import { montageClipsOf, momentKeysOf, readRulingsState } from "@/lib/report/montageRulings.mjs"; import FetchUnfetchedButton from "../FetchUnfetchedButton"; import { clipRecord, storedUrlOf } from "@/lib/clips/stored"; @@ -66,6 +67,8 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor const walkStart = (readiness.readyIds[0] as string | undefined) ?? clips[0]?.id; const showAll = search.all === "1"; const takes = await listTakes(project.dir); + // The trailer's beats (promo/trailer-beats.json): how many, for the Trailer link. + const trailerBeats = await readTrailerBeats(project.dir).then((d) => d.beats.length, () => null); // A montage (clips carrying `montage`) is ruled on the clip deck (release 34): // how many of its instances have no ruling yet. const montage = montageClipsOf(m) as { id: string }[]; @@ -368,6 +371,12 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor Make takes </Link> )} + {/* The trailer's beats: the running length against the platform's limit (UI notes item 11). */} + {clips.length > 0 && ( + <Link href={trailerHref(project.id)} data-trailer-link={trailerBeats ?? ""} className={buttonVariants({ variant: trailerBeats ? "outline" : "quiet", size: trailerBeats ? "lg" : "sm" })}> + {trailerBeats ? `Trailer — ${trailerBeats} beat${trailerBeats === 1 ? "" : "s"}` : trailerBeats === null ? "Trailer (beats file unreadable)" : "Trailer beats"} + </Link> + )} {/* Walk a take: the drafts first -- a draft exists to be walked before it is rendered. */} {takes.takes.some((t: { draft?: boolean; baseHash?: string | null }) => t.draft || t.baseHash) && ( <span data-walk-takes="" className="flex flex-wrap items-center gap-1.5 text-[11.5px]"> diff --git a/umtool/components/projects/review/ClipEditor.tsx b/umtool/components/projects/review/ClipEditor.tsx @@ -8,6 +8,7 @@ import { useSharedNotes } from "@/components/notes/NotesProvider"; import { notesOn } from "@/components/notes/AnchoredNotes"; import { NoteThread } from "@/components/notes/NoteThread"; import type { CitedPlay } from "@/lib/clips/types"; +import { FlashForwardForm, addToTrailer } from "./CutEditing"; import { edgeClock, newClipEntry, nextFreeId, provenanceWords, quoteBetween, roleOf, snapCut, snapPoints, spanQuote } from "@/lib/report/clipEditorModel.mjs"; import type { EditorClip, EditorView, Neighbourhood, Proposal, RenderTarget, Speaker, Turn } from "@/lib/report/clipEditorTypes"; import { cn } from "@/lib/utils"; @@ -271,6 +272,40 @@ export default function ClipEditor({ if (id) choose(id); }); }; + // Flash-forward the selected span (a repeat elsewhere in the cut, or moved + // out of the clip), and Add to trailer (the selection, else the cut): UI + // notes 2026-10-30, items 2 and 11 (CutEditing.tsx). + const [flash, setFlash] = useState<{ from: number; to: number } | null>(null); + const selInClip = !!selection && selection.cutEnd - selection.cutStart >= 0.5 && selection.cutStart >= clip.start - 0.02 && selection.cutEnd <= clip.end + 0.02; + const openFlash = () => { + if (!selection || !selInClip) { + setError(`select the span to flash forward on the strip, inside ${clip.id}'s window (${edgeClock(clip.start)}–${edgeClock(clip.end)})`); + return; + } + setFlash({ from: r2(selection.cutStart), to: r2(selection.cutEnd) }); + }; + const goFlash = (body: Record<string, unknown>) => { + void flush() + .then(() => write(body, body.move ? `Moved ${edgeClock(Number(body.from))}–${edgeClock(Number(body.to))} out of ${clip.id}` : `Flash-forward: a copy of ${edgeClock(Number(body.from))}–${edgeClock(Number(body.to))} put earlier`)) + .then((j) => { + if (!j) return; + setFlash(null); + setSelection(null); + const id = (j.result as { id?: string } | null)?.id; + if (id) setStatus(`${body.move ? "Moved" : "Copied"} to ${id} (a repeat of ${clip.id}${body.move ? ", moved" : ""})`); + }); + }; + const trailer = () => { + const span = selInClip && selection ? { from: r2(selection.cutStart), to: r2(selection.cutEnd) } : { from: cut.cutStart, to: cut.cutEnd }; + void flush().then(async () => { + const r = await addToTrailer(project, clip.id, span); + if (r.ok) { + setError(null); + setStatus(r.message); + } else setError(r.message); + }); + }; + // New clip (from the selection, or the span after this clip): the form, then // the timeline route's `insert` after this clip -- snapshotted, checked by // the build's own validators, an edit note on a generated cut -- and the @@ -697,7 +732,14 @@ export default function ClipEditor({ <button type="button" data-action="new-clip" disabled={busy} onClick={openNewClip} className={buttonVariants({ size: "md" })} title="a new clip from this recording, inserted after this one (drag on the strip to select its span first, or type it)"> {selection ? "New clip from selection…" : "New clip…"} </button> + <button type="button" data-action="flash-forward" disabled={busy || !selInClip} onClick={openFlash} className={buttonVariants({ size: "md" })} title={selInClip ? "a tight copy of the selection earlier in the cut (its attribution and locks copied), or moved out of this clip" : `select a span inside ${clip.id} on the strip first`}> + Flash-forward selection… + </button> + <button type="button" data-action="add-to-trailer" disabled={busy} onClick={trailer} className={buttonVariants({ size: "md" })} title="the selection (else the cut) as a trailer beat — the Trailer page has the running length"> + Add to trailer + </button> </div> + {flash && <FlashForwardForm project={project} clipId={clip.id} span={flash} busy={busy} onCancel={() => setFlash(null)} onGo={goFlash} />} {newClip && ( <NewClipForm key={`${clip.id}:${newClip.cutStart}-${newClip.cutEnd}`} diff --git a/umtool/components/projects/review/CutEditing.tsx b/umtool/components/projects/review/CutEditing.tsx @@ -0,0 +1,147 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { buttonVariants } from "@/components/ui/button"; +import { edgeClock } from "@/lib/report/clipEditorModel.mjs"; + +// Two of the clip editor's edits on the CUT rather than the clip (UI notes +// 2026-10-30, items 2 and 11): +// +// Flash-forward this span… a tight copy of the selected seconds put +// earlier (after an entry, or into a section), its +// attribution and locks copied, as a repeat of +// this clip -- or moved out of it (POST +// /api/report/clip-editor { op: "flash-forward" }, +// manifest.mjs flashForward; `umtool timeline <p> +// flash-forward`) +// Add to trailer the selection (else the cut) as a trailer beat, +// in the cut's order (POST /api/report/trailer-beats, +// trailerBeats.mjs; `umtool trailer-beats <p> add`) + +type Section = { index: number; words: string; clips: string[] }; +type Entry = { id: string; type: string }; + +export function FlashForwardForm({ + project, + clipId, + span, + busy, + onCancel, + onGo, +}: { + project: string; + clipId: string; + span: { from: number; to: number }; + busy: boolean; + onCancel: () => void; + onGo: (body: Record<string, unknown>) => void; +}) { + const [entries, setEntries] = useState<Entry[]>([]); + const [sections, setSections] = useState<Section[]>([]); + const [where, setWhere] = useState<"after" | "section">("after"); + const [after, setAfter] = useState<string>(""); + const [section, setSection] = useState<string>(""); + const [move, setMove] = useState(false); + useEffect(() => { + let live = true; + void fetch(`/api/report/timeline?project=${encodeURIComponent(project)}`, { cache: "no-store" }) + .then((r) => r.json()) + .then((j: { timeline?: Entry[]; sections?: Section[] }) => { + if (!live) return; + const tl = Array.isArray(j.timeline) ? j.timeline : []; + setEntries(tl); + const secs = Array.isArray(j.sections) ? j.sections : []; + setSections(secs); + // A flash-forward goes EARLIER: by default, the start of the section this clip is in. + const mine = secs.find((s) => s.clips.includes(clipId)); + if (mine && secs.length > 1) { + setWhere("section"); + setSection(String(Math.max(0, mine.index - 1))); + } + }) + .catch(() => {}); + return () => { + live = false; + }; + }, [project, clipId]); + const input = "rounded border border-[var(--color-line)] bg-[var(--color-ink)] px-1.5 py-0.5 text-[11px] text-[var(--color-text)] outline-none focus:border-[var(--color-sel)]"; + const mineAt = entries.findIndex((e) => e.id === clipId); + const go = () => + onGo({ + op: "flash-forward", + clip: clipId, + from: span.from, + to: span.to, + move, + ...(where === "section" && section !== "" ? { section: Number(section), position: "start" } : { after: after || null }), + }); + return ( + <div data-testid="flash-forward-form" className="space-y-1.5 rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-2 text-[11.5px]"> + <div className="flex flex-wrap items-center gap-2"> + <span className="micro">flash-forward</span> + <span className="num font-mono"> + {clipId} {edgeClock(span.from)}–{edgeClock(span.to)} ({(span.to - span.from).toFixed(1)} s) + </span> + </div> + <div className="flex flex-wrap items-center gap-2"> + {sections.length > 1 && ( + <label className="inline-flex items-center gap-1"> + <input type="radio" name="ff-where" checked={where === "section"} onChange={() => setWhere("section")} data-testid="ff-where-section" /> + at the start of + <select data-testid="ff-section" value={section} onChange={(e) => (setSection(e.target.value), setWhere("section"))} className={input}> + {sections.map((s) => ( + <option key={s.index} value={s.index}> + {s.words} + </option> + ))} + </select> + </label> + )} + <label className="inline-flex items-center gap-1"> + <input type="radio" name="ff-where" checked={where === "after"} onChange={() => setWhere("after")} data-testid="ff-where-after" /> + after + <select data-testid="ff-after" value={after} onChange={(e) => (setAfter(e.target.value), setWhere("after"))} className={input}> + <option value="">(the start)</option> + {entries.map((e, i) => ( + <option key={`${e.id}:${i}`} value={e.id}> + {e.id} · {e.type} + {i >= mineAt && mineAt >= 0 ? " (later: a callback)" : ""} + </option> + ))} + </select> + </label> + </div> + <label className="inline-flex items-center gap-1" title="take the span out of this clip (it must sit at one of its edges); the clip keeps the rest — otherwise a copy, marked as a deliberate repeat"> + <input type="checkbox" data-testid="ff-move" checked={move} onChange={(e) => setMove(e.target.checked)} /> + move it out of {clipId} (not a repeat) + </label> + <div className="flex flex-wrap items-center gap-2"> + <button type="button" data-testid="ff-go" disabled={busy} onClick={go} className={buttonVariants({ variant: "go", size: "sm" })}> + {move ? "Move the span" : "Copy the span"} + </button> + <button type="button" disabled={busy} onClick={onCancel} className={buttonVariants({ variant: "quiet", size: "sm" })}> + Cancel + </button> + <span className="text-[var(--color-dim)]">the title, date, cite, QR link, quote, speakers and locks go with it</span> + </div> + </div> + ); +} + +/** Add the span to the trailer's beats; says where it landed and the running length. */ +export async function addToTrailer(project: string, clipId: string, span: { from: number; to: number }): Promise<{ ok: boolean; message: string }> { + const read = await fetch(`/api/report/trailer-beats?project=${encodeURIComponent(project)}`, { cache: "no-store" }).then((r) => r.json()).catch(() => ({})); + const r = await fetch("/api/report/trailer-beats", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, token: read.token ?? null, op: "add", beat: { id: clipId, start: span.from, end: span.to } }), + }); + const j = (await r.json().catch(() => ({}))) as { error?: string; rows?: { id?: string; start?: number; n: number }[]; total?: number; limit?: number; over?: boolean }; + if (!r.ok) return { ok: false, message: j.error ?? `HTTP ${r.status}` }; + const row = j.rows?.find((x) => x.id === clipId && Math.abs((x.start ?? 0) - span.from) < 0.01); + const clock = (s: number) => `${Math.floor(s / 60)}:${(s % 60).toFixed(1).padStart(4, "0")}`; + return { + ok: true, + message: `Added to the trailer${row ? ` as beat ${row.n}` : ""}: ${clock(j.total ?? 0)} of ${clock(j.limit ?? 140)}${j.over ? " — OVER the limit" : ""}`, + }; +} diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts @@ -292,6 +292,11 @@ export function claimBenchHref(project: string, claim: string, q: NoteOpt = {}): } /** Alternative renders of one part of a cut. */ +/** The trailer's beats (promo/trailer-beats.json). */ +export function trailerHref(project: string): string { + return `/projects/${encodePath(project)}/trailer`; +} + export function takesHref(project: string, q: NoteOpt = {}): string { return withQuery(`/projects/${encodePath(project)}/takes`, {}, q.note); } diff --git a/umtool/lib/report/takeCli.mjs b/umtool/lib/report/takeCli.mjs @@ -83,6 +83,12 @@ export const TAKES_USAGE = [ " umtool takes styles [--json] the montage styles: name, label, summary", " umtool takes pick <project> <take> [--anyway] use this take: its manifest over the project's", " umtool takes effects <project> [--json] the overlay effects this cut offers, for --effect", + " umtool takes ls <project> [--json] each take: label, length, picked / superseded / rendering", + " umtool takes relabel <project> <take> <label…> take.json's label (an undo point of the take's own;", + " refused while it renders)", + " umtool takes supersede <project> <take> [--by <take>] | --clear folded away in the takes list (verdicts.json)", + " umtool takes delete <project> <take> [--dry-run] [--force] takes/<take>/ whole (refused while it renders or a", + " render is made from it; --force only past the take the project's manifest is)", ].join("\n"); class CliError extends Error {} @@ -91,7 +97,7 @@ class CliError extends Error {} function parse(args) { const valued = new Set([ "--id", "--label", "--group", "--kind", "--summary", "--style", "--patch", "--patch-json", "--set", "--effect", - "--at", "--dur", "--recipe", "--only", "--progress", "--from", + "--at", "--dur", "--recipe", "--only", "--progress", "--from", "--by", ]); /** @type {Record<string, string[]>} */ const flags = {}; @@ -345,6 +351,74 @@ export async function takesCommand(args, { reportsRoot = REPORTS_ROOT, log = con else for (const x of effects) log(`${x.name.padEnd(16)} ${x.label} — ${x.summary}`); return 0; } + if (sub === "ls") { + const project = await pickProject(rest[0], reportsRoot); + const { takesOverview, takeLine } = await import("./takeHousekeeping.mjs"); + const o = await takesOverview(project.dir); + if (p.has("--json")) log(JSON.stringify({ project: project.id, ...o }, null, 2)); + else { + for (const r of o.rows) log(takeLine(r)); + for (const sk of o.skipped) err(`skipped takes/${sk.dir}: ${sk.why}`); + } + return 0; + } + if (sub === "relabel") { + const project = await pickProject(rest[0], reportsRoot); + const take = rest[1]; + const label = rest.slice(2).join(" "); + if (!take || !label) throw new CliError("umtool takes relabel <project> <take> <label…>"); + const { renderHolds } = await import("./takeHousekeeping.mjs"); + const { relabelTake } = await import("./takeEdit.mjs"); + const r = await relabelTake(project.dir, take, label, { holds: await renderHolds(project.dir, take) }); + if (p.has("--json")) log(JSON.stringify({ ok: true, ...r }, null, 2)); + else log(r.revision ? `${take}: "${r.label}" (was "${r.was}"; undo point takes/${take}/${r.revision.rel})` : `${take} is already "${r.label}"`); + return 0; + } + if (sub === "supersede") { + const project = await pickProject(rest[0], reportsRoot); + const take = rest[1]; + if (!take) throw new CliError("umtool takes supersede <project> <take> [--by <take>] | --clear"); + const { listTakes, setTakeSuperseded } = await import("./takes.mjs"); + const known = (await listTakes(project.dir)).takes.map((t) => t.id); + if (!known.includes(take)) throw new CliError(`${project.id} has no take ${take}`); + const r = await setTakeSuperseded(project.dir, take, { by: p.one("--by") ?? null, clear: p.has("--clear"), known }); + if (p.has("--json")) log(JSON.stringify({ ok: true, take, entry: r.entry }, null, 2)); + else log(p.has("--clear") ? `${take}: not superseded` : `${take}: superseded${r.entry?.superseded?.by ? ` by ${r.entry.superseded.by}` : ""} (folded away in the takes list; nothing deleted)`); + return 0; + } + if (sub === "delete") { + const project = await pickProject(rest[0], reportsRoot); + const take = rest[1]; + if (!take) throw new CliError("umtool takes delete <project> <take> [--dry-run] [--force]"); + const { DeleteRefused, deleteTake, planTakeDelete } = await import("./delete.mjs"); + const force = p.has("--force"); + const plan = await planTakeDelete(project, take, { force }); + const blocking = plan.refusals.filter((x) => !(force && x.forceable)); + if (p.has("--dry-run") || blocking.length) { + if (p.has("--json")) log(JSON.stringify({ ok: !blocking.length, dryRun: true, plan }, null, 2)); + else { + for (const x of plan.refusals) err(`${x.forceable ? "refused (--force passes it)" : "refused"}: ${x.reason}`); + for (const x of plan.remove ?? []) log(`would remove ${x.label} — ${x.what} (${x.files} file(s), ${(x.bytes / 1e6).toFixed(1)} MB)`); + for (const x of plan.kept ?? []) log(`kept: ${x.what} — ${x.why}`); + } + return blocking.length ? 1 : 0; + } + try { + const r = await deleteTake(project, take, { force }); + if (p.has("--json")) log(JSON.stringify({ ok: true, removed: r.removed, failed: r.failed }, null, 2)); + else { + for (const x of r.removed) log(`removed ${x}`); + for (const f of r.failed) err(`not removed ${f.path}: ${f.error}`); + } + return r.failed.length ? 1 : 0; + } catch (e) { + if (e instanceof DeleteRefused) { + err(e.message); + return 1; + } + throw e; + } + } if (sub === "pick") { const project = await pickProject(rest[0], reportsRoot); const take = rest[1]; diff --git a/umtool/lib/report/trailerBeats.mjs b/umtool/lib/report/trailerBeats.mjs @@ -54,6 +54,9 @@ export class BeatsStale extends Error { const beatsFile = (dir) => path.join(dir, TRAILER_BEATS_FILE); +/** @typedef {{ limit?: number, xfade?: number, intro?: boolean }} TrailerSettings */ +/** @typedef {{ token?: string | null }} BeatsWriteOpts */ + /** The file's mtime, the token a writer hands back; null when there is no file. */ export async function beatsToken(dir) { const st = await stat(beatsFile(dir)).catch(() => null); @@ -72,7 +75,7 @@ export async function readTrailerBeats(dir) { try { text = await readFile(beatsFile(dir), "utf8"); } catch { - return { exists: false, shape: /** @type {"array" | "object"} */ ("array"), beats: [], settings: {}, indent: 1, token: null }; + return { exists: false, shape: /** @type {"array" | "object"} */ ("array"), beats: /** @type {any[]} */ ([]), settings: /** @type {TrailerSettings} */ ({}), indent: 1, token: /** @type {string | null} */ (null), doc: null }; } let doc; try { @@ -82,6 +85,7 @@ export async function readTrailerBeats(dir) { } const beats = Array.isArray(doc) ? doc : Array.isArray(doc?.beats) ? doc.beats : null; if (!beats) throw new Error(`${TRAILER_BEATS_FILE} is neither a list of beats nor { "beats": [...] }`); + /** @type {TrailerSettings} */ const settings = {}; if (isObj(doc)) { if (typeof doc.limit === "number") settings.limit = doc.limit; @@ -173,7 +177,13 @@ export async function addTrailerBeat(dir, beat, { token = null, at = null, manif }); } -/** Change beat `i`'s seconds or label (a key given as null removes a label). */ +/** + * Change beat `i`'s seconds or label (a key given as null removes a label). + * @param {string} dir + * @param {number} i + * @param {Record<string, unknown>} patch + * @param {BeatsWriteOpts} [opts] + */ export async function updateTrailerBeat(dir, i, patch, { token = null } = {}) { return beatsWrite(dir, token, (beats) => { const n = indexIn(beats, i); @@ -189,7 +199,12 @@ export async function updateTrailerBeat(dir, i, patch, { token = null } = {}) { }); } -/** Remove beat `i`. */ +/** + * Remove beat `i`. + * @param {string} dir + * @param {number} i + * @param {BeatsWriteOpts} [opts] + */ export async function removeTrailerBeat(dir, i, { token = null } = {}) { return beatsWrite(dir, token, (beats) => { const n = indexIn(beats, i); @@ -198,7 +213,13 @@ export async function removeTrailerBeat(dir, i, { token = null } = {}) { }); } -/** Move beat `i` to index `to` (its place after the move). */ +/** + * Move beat `i` to index `to` (its place after the move). + * @param {string} dir + * @param {number} i + * @param {number} to + * @param {BeatsWriteOpts} [opts] + */ export async function moveTrailerBeat(dir, i, to, { token = null } = {}) { return beatsWrite(dir, token, (beats) => { const n = indexIn(beats, i); @@ -215,6 +236,9 @@ export async function moveTrailerBeat(dir, i, to, { token = null } = {}) { * the timeline (then by start), a raw `{ at, dur }` beat by its master second * among them as best it can -- kept after the clip beat before it. A beat * naming a clip no longer in the cut goes last, and is still flagged. + * @param {string} dir + * @param {Record<string, any>} manifest + * @param {BeatsWriteOpts} [opts] */ export async function orderTrailerBeats(dir, manifest, { token = null } = {}) { return beatsWrite(dir, token, (beats) => { @@ -237,6 +261,9 @@ export async function orderTrailerBeats(dir, manifest, { token = null } = {}) { * The trailer's settings: `limit` (seconds, the platform's), `xfade` (the * trailer's crossfade), `intro` (opens on the brand intro). null removes one * (its default again). + * @param {string} dir + * @param {Record<string, unknown>} patch + * @param {BeatsWriteOpts} [opts] */ export async function setTrailerSettings(dir, patch, { token = null } = {}) { return beatsWrite(dir, token, (_beats, settings) => { diff --git a/umtool/lib/report/trailerBeatsCli.mjs b/umtool/lib/report/trailerBeatsCli.mjs @@ -0,0 +1,219 @@ +// `umtool trailer-beats` (UI notes 2026-10-30, item 11): the project's trailer +// beats (promo/trailer-beats.json) from a terminal -- the same writer and the +// same reader as the Trailer page (lib/report/trailerBeats.mjs), so the running +// length, the platform limit and the beats outside their clips are said here +// before any encode. `umtool trailer <p> --take <t> --beats +// <project>/promo/trailer-beats.json` cuts the trailer from them. +// +// Beats are numbered from 1, as `umtool trailer`'s refusals number them. +// +// Plain ESM: the CLI runs under bare node. +import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; +import { readManifest } from "../projects/report.mjs"; +import { + BeatsStale, + TRAILER_BEATS_FILE, + TRAILER_LIMITS, + addTrailerBeat, + beatsToken, + clockOf, + introSecondsOf, + moveTrailerBeat, + orderTrailerBeats, + readTrailerBeats, + removeTrailerBeat, + setTrailerSettings, + trailerCandidatesOf, + trailerView, + updateTrailerBeat, +} from "./trailerBeats.mjs"; + +export const TRAILER_BEATS_USAGE = [ + "usage: umtool trailer-beats <project> [ls] [--json] the beats: length, running length against the limit,", + " beats outside their clip, the cut's order", + " umtool trailer-beats <project> add <clip> [<from>-<to>] [--at N] [--label L]", + " a clip beat (default: the clip's whole cut), in the cut's order unless --at N", + " umtool trailer-beats <project> add-raw <at> <dur> [--at N] [--label L] master seconds", + " umtool trailer-beats <project> set <n> <from>-<to> [--label L] beat n's source seconds", + " umtool trailer-beats <project> remove <n> | move <n> --to <m> | order (the cut's order)", + ` umtool trailer-beats <project> limit <seconds|m:ss|${TRAILER_LIMITS.map((l) => l.id).join("|")}> | xfade <s> | intro on|off`, + " umtool trailer-beats <project> candidates [--add] the walk's ★ clips not yet beats (--add: all of them)", + "", + `The file is <project>/${TRAILER_BEATS_FILE}; \`umtool trailer <p> --take <t> --beats <that file>\` cuts the trailer.`, +].join("\n"); + +class CliError extends Error {} + +function parse(args) { + const valued = new Set(["--at", "--to", "--label"]); + /** @type {Record<string, string>} */ + const flags = {}; + const positional = []; + for (let i = 0; i < args.length; i += 1) { + const a = args[i]; + if (a.startsWith("--")) { + if (valued.has(a)) { + if (i + 1 >= args.length) throw new CliError(`${a} needs a value`); + flags[a] = args[++i]; + } else if (["--json", "--help", "--add"].includes(a)) flags[a] = ""; + else throw new CliError(`unknown flag ${a}`); + } else positional.push(a); + } + return { flags, positional, has: (n) => n in flags }; +} + +const spanOf = (s) => { + const m = /^(\d+(?:\.\d+)?)-(\d+(?:\.\d+)?)$/.exec(String(s ?? "")); + if (!m) throw new CliError(`a span is <from>-<to> in source seconds (got ${s})`); + return { start: Number(m[1]), end: Number(m[2]) }; +}; +const beatNo = (s, what = "beat") => { + const n = Number(s); + if (!Number.isInteger(n) || n < 1) throw new CliError(`${what} is a beat's number, from 1 (\`umtool trailer-beats <project>\` lists them)`); + return n - 1; +}; +/** seconds, m:ss(.s), or a platform's id. */ +export function limitOf(s) { + const p = TRAILER_LIMITS.find((l) => l.id === String(s).toLowerCase()); + if (p) return p.seconds; + const m = /^(\d+):(\d{1,2}(?:\.\d+)?)$/.exec(String(s)); + if (m) return Number(m[1]) * 60 + Number(m[2]); + const n = Number(s); + if (!Number.isFinite(n)) throw new CliError(`limit is seconds, m:ss, or one of ${TRAILER_LIMITS.map((l) => l.id).join(", ")}`); + return n; +} + +/** The view as lines. */ +export function viewLines(v) { + const lines = []; + for (const r of v.rows) { + const what = r.kind === "clip" ? `${r.id.padEnd(8)} ${String(r.start).padStart(9)}–${String(r.end).padEnd(9)}` : `(master) at ${r.at} for ${r.dur}`.padEnd(29); + const flag = r.problems.length ? ` ! ${r.problems.join("; ")}` : ""; + lines.push(`${String(r.n).padStart(3)} ${what} ${`${r.seconds.toFixed(2)}s`.padStart(8)} ${clockOf(r.running).padStart(7)}${r.over ? " OVER" : ""}${r.clip?.section ? ` ${r.clip.section}` : ""}${r.label ? ` "${r.label}"` : ""}${flag}`); + } + lines.push( + `${v.rows.length} beat(s): ${clockOf(v.total)} of ${clockOf(v.limit)}${v.over ? ` — OVER by ${(v.total - v.limit).toFixed(1)} s` : ` (${v.remaining.toFixed(1)} s to spare)`}` + + ` · crossfade ${v.xfade} s${v.intro ? ` · intro ${v.introSeconds ?? "?"} s${v.introSeconds === null ? " (unknown until a take is built)" : ""}` : ""}` + + `${v.outside ? ` · ${v.outside} beat(s) to fix` : ""}${v.inOrder ? "" : " · not in the cut's order (`order`)"}`, + ); + return lines; +} + +/** + * @param {string[]} args the words after `trailer-beats` + * @param {{ root?: string, out?: (s: string) => void, err?: (s: string) => void }} [opts] + */ +export async function trailerBeatsCommand(args, { root = REPORTS_ROOT, out = (s) => console.log(s), err = (s) => console.error(s) } = {}) { + try { + const p = parse(args); + const [projectArg, verb = "ls", ...rest] = p.positional; + if (!projectArg || p.has("--help")) { + err(TRAILER_BEATS_USAGE); + return p.has("--help") ? 0 : 2; + } + const r = await resolveProject(projectArg, root); + if (r.ambiguous) throw new CliError(`"${projectArg}" is the name of ${r.ambiguous.length} projects — pass its id`); + if (!r.project) throw new CliError(`no project matches "${projectArg}"`); + const project = r.project; + const manifest = await readManifest(project.dir); + if (!manifest) throw new CliError(`${project.id} has no manifest`); + const token = await beatsToken(project.dir); + const label = p.has("--label") ? p.flags["--label"] : undefined; + const at = p.has("--at") ? beatNo(p.flags["--at"], "--at") : null; + let did = null; + switch (verb) { + case "ls": + break; + case "add": { + const id = rest[0]; + if (!id) throw new CliError("add <clip> [<from>-<to>]"); + const e = (manifest.timeline ?? []).find((x) => x?.id === id && x.type === "clip"); + if (!e) throw new CliError(`no clip ${id} in the cut`); + const span = rest[1] ? spanOf(rest[1]) : { start: e.cutStart ?? e.start, end: e.cutEnd ?? e.end }; + const res = await addTrailerBeat(project.dir, { id, ...span, ...(label ? { label } : {}) }, { token, at, manifest }); + did = `added beat ${res.index + 1}: ${id} ${res.beat.start}–${res.beat.end}`; + break; + } + case "add-raw": { + const a = Number(rest[0]); + const d = Number(rest[1]); + if (!Number.isFinite(a) || !Number.isFinite(d)) throw new CliError("add-raw <at> <dur>: master seconds"); + const res = await addTrailerBeat(project.dir, { at: a, dur: d, ...(label ? { label } : {}) }, { token, at }); + did = `added beat ${res.index + 1}: master ${a} for ${d} s`; + break; + } + case "set": { + const i = beatNo(rest[0]); + const patch = { ...(rest[1] ? spanOf(rest[1]) : {}), ...(label !== undefined ? { label } : {}) }; + if (!Object.keys(patch).length) throw new CliError("set <n> <from>-<to> [--label L]"); + const res = await updateTrailerBeat(project.dir, i, patch, { token }); + did = `beat ${i + 1}: ${JSON.stringify(res.beat)}`; + break; + } + case "remove": { + const i = beatNo(rest[0]); + const res = await removeTrailerBeat(project.dir, i, { token }); + did = `removed beat ${i + 1} (${res.removed.id ?? `master ${res.removed.at}`})`; + break; + } + case "move": { + const i = beatNo(rest[0]); + if (!p.has("--to")) throw new CliError("move <n> --to <m>"); + const to = beatNo(p.flags["--to"], "--to"); + await moveTrailerBeat(project.dir, i, to, { token }); + did = `moved beat ${i + 1} to ${to + 1}`; + break; + } + case "order": { + const res = await orderTrailerBeats(project.dir, manifest, { token }); + did = res.moved ? "the beats are in the cut's order now" : "the beats were already in the cut's order"; + break; + } + case "limit": + await setTrailerSettings(project.dir, { limit: rest[0] === "default" ? null : limitOf(rest[0]) }, { token }); + did = "limit set"; + break; + case "xfade": + await setTrailerSettings(project.dir, { xfade: rest[0] === "default" ? null : Number(rest[0]) }, { token }); + did = "crossfade set"; + break; + case "intro": + if (!["on", "off"].includes(rest[0])) throw new CliError("intro on|off"); + await setTrailerSettings(project.dir, { intro: rest[0] === "on" }, { token }); + did = `intro ${rest[0]}`; + break; + case "candidates": { + const doc = await readTrailerBeats(project.dir); + const cands = trailerCandidatesOf(manifest, doc.beats); + if (!p.has("--add")) { + if (p.has("--json")) out(JSON.stringify({ project: project.id, candidates: cands }, null, 2)); + else if (!cands.length) out("no ★ clips that are not beats already (star a clip on the walk)"); + else for (const c of cands) out(`★ ${c.id.padEnd(8)} ${c.start}–${c.end}${c.walkNote ? ` — ${c.walkNote}` : ""}${c.quote ? ` "${c.quote.slice(0, 90)}${c.quote.length > 90 ? "…" : ""}"` : ""}`); + return 0; + } + let tok = token; + for (const c of cands) tok = (await addTrailerBeat(project.dir, { id: c.id, start: c.start, end: c.end }, { token: tok, manifest })).token; + did = `added ${cands.length} ★ beat(s)`; + break; + } + default: + throw new CliError(`unknown: trailer-beats ${verb}\n${TRAILER_BEATS_USAGE}`); + } + const doc = await readTrailerBeats(project.dir); + const view = trailerView(manifest, doc, { introSeconds: doc.settings?.intro ? await introSecondsOf(project.dir) : null }); + if (p.has("--json")) { + out(JSON.stringify({ ok: true, project: project.id, ...(did ? { did } : {}), token: await beatsToken(project.dir), ...view }, null, 2)); + return 0; + } + if (did) out(did); + for (const line of viewLines(view)) out(line); + return 0; + } catch (e) { + if (e instanceof BeatsStale) { + err(`umtool trailer-beats: ${e.message} — somebody else wrote it; run it again`); + return 1; + } + err(`umtool trailer-beats: ${e instanceof Error ? e.message : String(e)}`); + return e instanceof CliError ? 2 : 1; + } +}