Archilyzer · Source

archilyzer

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

commit 4a84811d59642ffe92ba73644b6c69a294904b70
parent 9e89455caea86f05f15f10b42c589d5699b4c49b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 27 Oct 2026 14:44:06 -0400

umtool: walk a take in the app -- the bench on a take's clips, its saves into the take

- /projects/<p>/takes/<take>/walk: the take's clips in walk order with their
  verdicts and fetched state, where the walk starts, ?all=1 to walk every
  clip; /projects/<p>/takes/<take>/clip/<id>: the clip bench on the take's
  clip (walkData.mjs), playing from the cached windows.
- Every route the bench calls takes `take`: window and cut-to-quote save
  through updateTakeClip; clip, cues, peaks read the take's clip; fetch points
  the job at the take's manifest written beside the project's. The one-clip
  re-render and the project's segment are off on a take.
- The bench's take strip: walking take X, edits go to the take; earlier /
  later / remove from take / undo take edit (POST /api/report/takes/timeline).
- Takes page: a draft reads "draft -- walk / render"; every take maker take
  gets Walk this take, Render full / first 60 s, Make this the cut
  (POST /api/report/takes/promote); "edited since render" when walked after
  its render. Use this take is not offered on a draft. The Cut tab links the
  takes to walk.
- GET /api/report/walk: the walk as data, the bench page's own reading.

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

Diffstat:
Mumtool/app/api/report/clip/route.ts | 20++++++++++++--------
Mumtool/app/api/report/cues/route.ts | 6++++--
Mumtool/app/api/report/cut/route.ts | 16++++++++++++++--
Mumtool/app/api/report/fetch/route.ts | 15+++++++++++----
Mumtool/app/api/report/peaks/route.ts | 8+++++---
Aumtool/app/api/report/takes/promote/route.ts | 44++++++++++++++++++++++++++++++++++++++++++++
Aumtool/app/api/report/takes/timeline/route.ts | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/app/api/report/walk/route.ts | 28++++++++++++++++++++++++++++
Mumtool/app/api/report/window/route.ts | 15++++++++++++++-
Mumtool/components/projects/ClipBench.tsx | 136++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
Mumtool/components/projects/ClipBenchPage.tsx | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Mumtool/components/projects/ProjectView.tsx | 10++++++++++
Aumtool/components/projects/TakeActions.tsx | 136+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/components/projects/TakeWalkPage.tsx | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/TakesBench.tsx | 46++++++++++++++++++++++++++++++++++++++++++++--
Mumtool/components/projects/bench/RenderGhosts.tsx | 8+++++---
Aumtool/components/projects/bench/TakeWalkStrip.tsx | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/report/CutTab.tsx | 18+++++++++++++++++-
Mumtool/lib/hrefs.test.mjs | 7+++++++
Mumtool/lib/hrefs.ts | 18++++++++++++++++++
Mumtool/lib/projects/report.mjs | 16+++++++++++++---
Mumtool/lib/report/driver.mjs | 15+++++++++------
Mumtool/lib/report/serve.mjs | 3+++
Mumtool/lib/report/takeEdit.mjs | 17+++++++++++++++--
Mumtool/lib/report/walkData.mjs | 12+++++++++++-
25 files changed, 896 insertions(+), 101 deletions(-)

diff --git a/umtool/app/api/report/clip/route.ts b/umtool/app/api/report/clip/route.ts @@ -1,5 +1,6 @@ import path from "node:path"; -import { ensureWindowFile, resolveClip, segmentFor, windowsFor } from "@/lib/report/serve.mjs"; +import { ensureWindowFile, projectCache, resolveClip, segmentFor, windowsFor } from "@/lib/report/serve.mjs"; +import { takeToken } from "@/lib/report/takeEdit.mjs"; import { manifestToken } from "@/lib/report/manifest.mjs"; import { cuesInWindow, readClipDetail, siblingsOf } from "@/lib/projects/report.mjs"; @@ -15,15 +16,18 @@ export async function GET(request: Request) { const url = new URL(request.url); const projectId = url.searchParams.get("project") ?? ""; const clipId = url.searchParams.get("clip") ?? ""; + // `take` (walk a take): the take's clip, and the TAKE's token -- its saves go into take.json. + const take = url.searchParams.get("take") || null; - const r = await resolveClip(projectId, clipId); + const r = await resolveClip(projectId, clipId, { take }); if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); const { project, manifest, clip } = r; - const windows = await windowsFor(project, clip); + const windows = await windowsFor(project, clip, take ? await projectCache(project, manifest) : null); // Re-read after a re-render: the segment lands on the SAME path, so its mtime - // is what tells the player it is looking at a different file. - const seg = await segmentFor(project, clipId); + // is what tells the player it is looking at a different file. A take's clip + // has none (the project's segments are the project's cut). + const seg = take ? null : await segmentFor(project, clipId); const detail = await readClipDetail(project.dir, { manifest }); const entry = detail?.entries.find((e: { id: string }) => e.id === clipId) ?? null; @@ -37,7 +41,7 @@ export async function GET(request: Request) { ? { from: widest.from, to: widest.to } : { from: Math.max(0, clip.start - 20), to: clip.end + 20 }; - const cues = await cuesInWindow(project.dir, clipId, view.from, view.to); + const cues = await cuesInWindow(project.dir, clipId, view.from, view.to, { manifest }); return Response.json( { @@ -79,7 +83,7 @@ export async function GET(request: Request) { // A record captured live has no length in its cues (`duration: 0`): unknown, // not zero -- a zero here capped every drag at second 0. sourceDuration: entry?.duration && entry.duration > 0 ? entry.duration : null, - segment: seg?.rel ?? entry?.segment ?? null, + segment: take ? null : (seg?.rel ?? entry?.segment ?? null), segmentMtime: seg?.mtimeMs ?? null, sourceTitle: entry?.sourceTitleClean ?? null, uploadDate: entry?.uploadDate ?? null, @@ -92,7 +96,7 @@ export async function GET(request: Request) { // is missing already in the cut, or is it a hole? siblings: siblingsOf(manifest, clipId), punctuationRate: cues?.punctuationRate ?? null, - token: await manifestToken(project.dir), + token: take ? await takeToken(project.dir, take) : await manifestToken(project.dir), fetchPad: manifest.render?.fetchPad ?? 3, outLabel: path.posix.join(project.id, "out"), }, diff --git a/umtool/app/api/report/cues/route.ts b/umtool/app/api/report/cues/route.ts @@ -30,10 +30,12 @@ export async function GET(request: Request) { return Response.json(got, { headers: { "cache-control": "no-store" } }); } - const r = await resolveClip(projectId, clipId); + // `take` (walk a take): the take's clip. + const take = url.searchParams.get("take") || null; + const r = await resolveClip(projectId, clipId, { take }); if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); - const cues = await cuesInWindow(r.project.dir, clipId, from, to); + const cues = await cuesInWindow(r.project.dir, clipId, from, to, { manifest: r.manifest }); if (!cues) return Response.json({ error: "no cue file for this source" }, { status: 404 }); return Response.json(cues, { headers: { "cache-control": "no-store" } }); } diff --git a/umtool/app/api/report/cut/route.ts b/umtool/app/api/report/cut/route.ts @@ -1,5 +1,6 @@ import { withEditNotes } from "@/lib/report/guard"; import { StaleToken, updateClip } from "@/lib/report/manifest.mjs"; +import { updateTakeClip } from "@/lib/report/takeEdit.mjs"; import { cleanRespellings } from "yt-dlp-transcript-common/lib/citations/respell.mjs"; import { cuesInWindow } from "@/lib/projects/report.mjs"; import { resolveClip } from "@/lib/report/serve.mjs"; @@ -28,8 +29,10 @@ export async function POST(request: Request) { const body = (await request.json().catch(() => ({}))) as Record<string, unknown>; const projectId = String(body.project ?? ""); const clipId = String(body.clip ?? ""); + // `take` (walk a take): the take's clip, and the cut written into the take's patch. + const take = typeof body.take === "string" && body.take ? body.take : null; - const r = await resolveClip(projectId, clipId); + const r = await resolveClip(projectId, clipId, { take }); if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); const { project, clip, manifest } = r; @@ -40,7 +43,7 @@ export async function POST(request: Request) { ); } - const doc = await cuesInWindow(project.dir, clipId, clip.start - LOOK, clip.end + LOOK); + const doc = await cuesInWindow(project.dir, clipId, clip.start - LOOK, clip.end + LOOK, { manifest }); if (!doc?.cues?.length) { return Response.json( { error: "no cue file for this source, so there is nothing to match against", ok: false }, @@ -71,6 +74,15 @@ export async function POST(request: Request) { } try { + if (take) { + const res = await updateTakeClip(project.dir, take, clipId, { cutStart: hit.cutStart, cutEnd: hit.cutEnd }, { + token: body.token === undefined ? null : String(body.token), + }); + return Response.json( + { ok: true, take, entry: res.entry, token: res.token, score: hit.score, matched: hit.matched }, + { headers: { "cache-control": "no-store" } }, + ); + } const { result: res, editNotes } = await withEditNotes(project, () => updateClip( project.dir, diff --git a/umtool/app/api/report/fetch/route.ts b/umtool/app/api/report/fetch/route.ts @@ -7,6 +7,7 @@ import { localFetch, } from "@/lib/report/driver.mjs"; import { projectCache, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; +import { writePlayManifest } from "@/lib/report/takeManifest.mjs"; export const dynamic = "force-dynamic"; @@ -67,7 +68,12 @@ export async function POST(request: Request) { ); } - const r = await resolveClip(projectId, clipId); + // `take` (walk a take): the clip is the take's. The fetch scripts read a + // manifest by path, so the take's is written beside the project's (its play + // manifest, takeManifest.mjs) and the job is pointed at it. The bytes land + // where every fetch's do: they are the recording's, not the take's. + const take = typeof body.take === "string" && body.take ? body.take : null; + const r = await resolveClip(projectId, clipId, { take }); if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); // ASK THE CACHE FIRST. @@ -137,11 +143,12 @@ export async function POST(request: Request) { // corpus where the next report reuses them instead of paying again. Running // yt-dlp from here has none of that, which is why it is now the opt-out // (UMTOOL_LOCAL_FETCH=1) rather than the default. + const manifestPath = take ? await writePlayManifest(r.project.dir, take, r.manifest) : null; const steps = wantFull - ? editorFullSourceSteps(r.project, clipId, { manifest: r.manifest }) + ? editorFullSourceSteps(r.project, clipId, { manifest: r.manifest, manifestPath }) : localFetch() - ? fetchSteps(r.project, clipId, { padBefore, padAfter }) - : editorFetchSteps(r.project, clipId, { padBefore, padAfter, storedUrl }); + ? fetchSteps(r.project, clipId, { padBefore, padAfter }, { manifestPath }) + : editorFetchSteps(r.project, clipId, { padBefore, padAfter, storedUrl }, { manifestPath }); const job = startJob( wantFull ? `fetch whole source ${projectId}/${clipId}` diff --git a/umtool/app/api/report/peaks/route.ts b/umtool/app/api/report/peaks/route.ts @@ -1,4 +1,4 @@ -import { absOf, ensureWindowFile, pickWindow, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; +import { absOf, ensureWindowFile, pickWindow, projectCache, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; import { ENV_RATE, analyseMedia } from "@/lib/media"; export const dynamic = "force-dynamic"; @@ -15,10 +15,12 @@ export const dynamic = "force-dynamic"; export async function GET(request: Request) { const url = new URL(request.url); - const r = await resolveClip(url.searchParams.get("project") ?? "", url.searchParams.get("clip") ?? ""); + // `take` (walk a take): the take's clip, its window as the take has it -- as /raw. + const take = url.searchParams.get("take") || null; + const r = await resolveClip(url.searchParams.get("project") ?? "", url.searchParams.get("clip") ?? "", { take }); if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); - const windows = await windowsFor(r.project, r.clip); + const windows = await windowsFor(r.project, r.clip, take ? await projectCache(r.project, r.manifest) : null); const win = pickWindow(windows, url.searchParams.get("file")); if (!win) return Response.json({ error: "no cached window for this clip" }, { status: 404 }); // A recording's excerpt is cut on first read (serve.mjs, "A RECORDING IS NOT A WINDOW"). diff --git a/umtool/app/api/report/takes/promote/route.ts b/umtool/app/api/report/takes/promote/route.ts @@ -0,0 +1,44 @@ +import { invalidateProjects, projectRef } from "@/lib/projects"; +import { pieceHrefOfProject } from "@/lib/pieces/article"; +import { refuseCaller } from "@/lib/report/caller"; +import { StaleToken, StructureRefused } from "@/lib/report/manifest.mjs"; +import { PromoteStale, promoteTake } from "@/lib/report/takeEdit.mjs"; +import { isTakeId } from "@/lib/report/takes.mjs"; + +export const dynamic = "force-dynamic"; + +// "MAKE THIS THE CUT" (walk a take). POST { project, take, anyway? } +// +// The take's manifest -- the project's as it is now with the take's patch +// applied, walked edits and all -- over the project's, through the manifest +// writer (replaceManifest: ONE auto snapshot `auto-before-promote-take`, so +// the Cut tab's "Undo last edit" takes the whole promotion back) inside the +// edit-notes guard; then the take's group's pick in takes/verdicts.json. +// The CLI twin is `umtool take <p> --id <take> --promote [--anyway]`. +// +// Not "Use this take" (/api/report/takes/pick), which copies the manifest a +// take was RENDERED from: this applies its patch now, so a draft promotes. +// +// 409 `{ stale: true }` when the take replaces the timeline and the project's +// manifest changed since the take was made, until `anyway`. +export async function POST(request: Request) { + const refused = refuseCaller(request, "/api/report/takes/promote"); + if (refused) return refused; + const body = (await request.json().catch(() => null)) as { project?: unknown; take?: unknown; anyway?: unknown } | 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 project = await projectRef(String(body.project ?? "")); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + try { + const r = await promoteTake(project, body.take, { anyway: body.anyway === true }); + invalidateProjects(); + const historyHref = await pieceHrefOfProject(project.id, { tab: "history" }); + return Response.json({ ok: true, ...r, historyHref }, { headers: { "cache-control": "no-store" } }); + } catch (e) { + if (e instanceof PromoteStale) return Response.json({ error: e.message, stale: true }, { status: 409 }); + if (e instanceof StaleToken) return Response.json({ error: e.message, stale: true }, { status: 409 }); + if (e instanceof StructureRefused) return Response.json({ error: e.message, errors: e.errors }, { status: 400 }); + const message = e instanceof Error ? e.message : String(e); + return Response.json({ error: message }, { status: /^no take /.test(message) ? 404 : 400 }); + } +} diff --git a/umtool/app/api/report/takes/timeline/route.ts b/umtool/app/api/report/takes/timeline/route.ts @@ -0,0 +1,52 @@ +import { projectRef } from "@/lib/projects"; +import { refuseCaller } from "@/lib/report/caller"; +import { StaleToken, StructureRefused } from "@/lib/report/manifest.mjs"; +import { moveTakeEntry, removeTakeEntry, undoTakeEdit } from "@/lib/report/takeEdit.mjs"; +import { isTakeId } from "@/lib/report/takes.mjs"; + +export const dynamic = "force-dynamic"; + +// A TAKE'S TIMELINE, walked (lib/report/takeEdit.mjs; the CLI twin is +// `umtool timeline <p> --take <id> move|remove|undo`). The writes go into the +// take's patch (takes/<id>/take.json), each with an undo point of the take's +// own; the project's manifest is never written here. +// +// POST { project, take, token?, op, ... } +// move { id, toIndex, at? } toIndex is the index AFTER the move +// remove { id, at? } +// undo {} the take's newest edit taken back +// +// A stale token is a 409; a structure the build would refuse is a 400 with its sentences. +export async function POST(request: Request) { + const refused = refuseCaller(request, "/api/report/takes/timeline"); + 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: "bad json" }, { status: 400 }); + if (!isTakeId(body.take)) return Response.json({ error: "take must be a take id" }, { status: 400 }); + const project = await projectRef(String(body.project ?? "")); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + const take = body.take; + const token = body.token === undefined || body.token === null ? null : String(body.token); + const at = body.at === undefined || body.at === null ? null : Number(body.at); + const id = typeof body.id === "string" ? body.id : ""; + try { + let r: Record<string, unknown>; + if (body.op === "move") { + if (!id) return Response.json({ error: "move needs an id" }, { status: 400 }); + r = await moveTakeEntry(project.dir, take, id, Number(body.toIndex), { token, at }); + } else if (body.op === "remove") { + if (!id) return Response.json({ error: "remove needs an id" }, { status: 400 }); + r = await removeTakeEntry(project.dir, take, id, { token, at }); + } else if (body.op === "undo") { + r = await undoTakeEdit(project.dir, take, { token }); + } else { + return Response.json({ error: "op must be move, remove or undo" }, { status: 400 }); + } + return Response.json({ ok: true, op: body.op, take, ...r }, { headers: { "cache-control": "no-store" } }); + } catch (e) { + if (e instanceof StaleToken) return Response.json({ error: e.message, expected: e.expected, got: e.got, stale: true }, { status: 409 }); + if (e instanceof StructureRefused) return Response.json({ error: e.message, errors: e.errors }, { status: 400 }); + const message = e instanceof Error ? e.message : String(e); + return Response.json({ error: message }, { status: /^no take /.test(message) ? 404 : 400 }); + } +} diff --git a/umtool/app/api/report/walk/route.ts b/umtool/app/api/report/walk/route.ts @@ -0,0 +1,28 @@ +import { projectRef } from "@/lib/projects"; +import { isTakeId } from "@/lib/report/takes.mjs"; +import { walkJson, walkOf } from "@/lib/report/walkData.mjs"; + +export const dynamic = "force-dynamic"; + +// THE WALK, as data (lib/report/walkData.mjs -- what the bench page and +// `umtool walk` read): every clip in walk order with its verdict, whether a +// fetched file holds it, and which ones the walk visits. +// +// GET ?project=<id>[&take=<take>][&all=1] +// take: walk a take -- the project's manifest with the take's patch applied +// (a draft too); `token` is then the take's (its saves go into take.json) +// all: the walk visits every fetched clip, judged or not +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") || null; + if (take !== null && !isTakeId(take)) return Response.json({ error: "take must be a take id" }, { status: 400 }); + try { + const w = await walkOf(project, { take, all: url.searchParams.get("all") === "1" }); + return Response.json(walkJson(w), { headers: { "cache-control": "no-store" } }); + } catch (e) { + const message = e instanceof Error ? e.message : String(e); + return Response.json({ error: message }, { status: /^no take |no video\.manifest/.test(message) ? 404 : 400 }); + } +} diff --git a/umtool/app/api/report/window/route.ts b/umtool/app/api/report/window/route.ts @@ -1,5 +1,6 @@ import { withEditNotes } from "@/lib/report/guard"; import { StaleToken, updateClip } from "@/lib/report/manifest.mjs"; +import { updateTakeClip } from "@/lib/report/takeEdit.mjs"; import { resolveClip } from "@/lib/report/serve.mjs"; import { refuseCaller } from "@/lib/report/caller"; @@ -27,7 +28,10 @@ export async function PUT(request: Request) { const projectId = String(body.project ?? ""); const clipId = String(body.clip ?? ""); - const r = await resolveClip(projectId, clipId); + // `take` (walk a take): the clip is the TAKE's, and the save goes into the + // take's patch (lib/report/takeEdit.mjs) -- never the project's manifest. + const take = typeof body.take === "string" && body.take ? body.take : null; + const r = await resolveClip(projectId, clipId, { take }); if ("error" in r) return Response.json({ error: r.error }, { status: r.status }); // The whitelist, mirrored from lib/report/manifest.mjs so a field nobody @@ -67,6 +71,15 @@ export async function PUT(request: Request) { if (!Object.keys(patch).length) return Response.json({ error: "nothing to change" }, { status: 400 }); try { + if (take) { + const res = await updateTakeClip(r.project.dir, take, clipId, patch, { + token: body.token === undefined ? null : String(body.token), + }); + return Response.json( + { ok: true, take, entry: res.entry, before: res.before, token: res.token, revision: res.revision.rel }, + { headers: { "cache-control": "no-store" } }, + ); + } const { result: res, editNotes } = await withEditNotes(r.project, () => updateClip(r.project.dir, clipId, patch, { token: body.token === undefined ? null : String(body.token), diff --git a/umtool/components/projects/ClipBench.tsx b/umtool/components/projects/ClipBench.tsx @@ -19,6 +19,7 @@ import { BenchBody, VerdictBar } from "./bench/BenchShell"; import CopyCitation from "./bench/CopyCitation"; import EdgeStrip from "./bench/EdgeStrip"; import RenderGhosts, { useRenderEdges } from "./bench/RenderGhosts"; +import TakeWalkStrip from "./bench/TakeWalkStrip"; // The renderer's own line, imported rather than re-written. A preview that // disagrees with the header by a character is worth less than no preview: you // would only find out twenty minutes into a build. @@ -284,6 +285,31 @@ export type ClipBenchData = { * if one was (its render does not change when this manifest does). */ fromPlay?: { href: string; take: string | null } | null; + /** + * WALKING A TAKE (/projects/<p>/takes/<take>/clip/<id>): the clip is the + * take's -- the project's manifest with the take's patch applied -- and + * every save goes into the take's patch (takes/<id>/take.json), never the + * project's manifest. Every route this bench calls is asked with `take`. + * `all`: the walk visits every fetched clip, judged or not. + */ + take?: { + id: string; + label: string; + draft: boolean; + /** take.json exists, so there is somewhere for an edit to land (a recipe-only take is read only). */ + editable: boolean; + all: boolean; + /** The Takes page, and this walk's own start (with `all` as it is). */ + takesHref: string; + walkHref: string; + /** The same clip on the walk of every clip / of the unjudged ones. */ + toggleAllHref: string; + /** Clip id -> its bench address on this take's walk (siblings link through it). */ + clipHref: Record<string, string>; + /** This clip's index in the take's timeline, and the timeline's length (the strip's moves). */ + at: number; + entries: number; + } | null; }; const hms = (t: number) => { @@ -332,6 +358,8 @@ type UndoRec = { before: Record<string, unknown>; /** The Confirm carried a moved window, so Undo puts the edges back too. */ moved: boolean; + /** Walking a take: the take the Confirm was written into. */ + take?: string | null; }; const readUndo = (): UndoRec | null => { try { @@ -460,6 +488,11 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { // The project's notes: this clip's row notes, and the edit notes a save on a // generated manifest leaves (the save says so, and they are re-read). const notes = useSharedNotes({ project: data.project }); + // Walking a take: every route is asked about the TAKE's clip, and every + // save lands in the take's patch (see ClipBenchData.take). + const takeId = data.take?.id ?? null; + const tq = takeId ? `&take=${encodeURIComponent(takeId)}` : ""; + const takeBody = takeId ? { take: takeId } : {}; const [clip, setClip] = useState<Clip>(data.clip); const [windows, setWindows] = useState<Win[]>(data.windows); const [cues, setCues] = useState<Cue[]>(data.cues); @@ -468,7 +501,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const [sel, setSel] = useState({ from: data.clip.start, to: data.clip.end }); // Where the render will actually cut the drafted selection (bench/RenderGhosts.tsx): the // desk's waveform and the phone's edge strip both draw it. - const renderEdges = useRenderEdges(data.project, clip, sel); + const renderEdges = useRenderEdges(data.project, clip, sel, takeId); // The mute mark as drafted. Like the edges it is unsaved until `save window` // or `y`, and it is what the bench's own playback mutes at -- so a mark is // heard before it is written. @@ -613,10 +646,10 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { } catch { /* nothing to clear */ } - if (u.project !== data.project || (u.next !== data.clip.id && u.clip !== data.clip.id)) return; + if (u.project !== data.project || (u.take ?? null) !== takeId || (u.next !== data.clip.id && u.clip !== data.clip.id)) return; if (Date.now() - u.at >= UNDO_MS) return; setUndo(u); - }, [data.project, data.clip.id]); + }, [data.project, data.clip.id, takeId]); useEffect(() => { if (!undo) return; const id = window.setTimeout(() => setUndo(null), Math.max(0, undo.at + UNDO_MS - Date.now())); @@ -648,7 +681,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { let live = true; void (async () => { const r = await fetch( - `/api/report/peaks?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}&file=${encodeURIComponent(cached.name)}`, + `/api/report/peaks?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}&file=${encodeURIComponent(cached.name)}${tq}`, { cache: "no-store" }, ); if (!r.ok || !live) return; @@ -657,7 +690,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { return () => { live = false; }; - }, [cached, data.project, clip.id]); + }, [cached, data.project, clip.id, tq]); // Follow the playhead in the reading pane, and ONLY while something is // playing: scrolling the words out from under somebody who is reading ahead @@ -685,7 +718,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { void (async () => { const r = await fetch( `/api/report/cues?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}` + - `&from=${(view.from - peekPad).toFixed(2)}&to=${(view.to + peekPad).toFixed(2)}`, + `&from=${(view.from - peekPad).toFixed(2)}&to=${(view.to + peekPad).toFixed(2)}${tq}`, { cache: "no-store" }, ); if (!r.ok || !live) return; @@ -695,7 +728,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { return () => { live = false; }; - }, [data.project, clip.id, view.from, view.to, peekPad]); + }, [data.project, clip.id, view.from, view.to, peekPad, tq]); // ---- playback preferences ------------------------------------------------ useEffect(() => setPlayback(readPlayback()), []); @@ -868,7 +901,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { setAudio({ state: "loading" }); const r = await fetch( `/api/report/audio?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}` + - `&file=${encodeURIComponent(cached.name)}&from=${span.from}&to=${span.to}`, + `&file=${encodeURIComponent(cached.name)}&from=${span.from}&to=${span.to}${tq}`, ); if (!r.ok) { const j = (await r.json().catch(() => null)) as { error?: string } | null; @@ -1345,7 +1378,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const r = await fetch("/api/report/window", { method: "PUT", headers: { "content-type": "application/json" }, - body: JSON.stringify({ project: data.project, clip: clip.id, token: token.current, ...patch }), + body: JSON.stringify({ project: data.project, clip: clip.id, ...takeBody, token: token.current, ...patch }), }); const j = (await r.json()) as Record<string, unknown>; lastSaved.current = j; @@ -1522,7 +1555,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { // A verdict is a state change, and a thumb lands where it did not mean to. const before = (lastSaved.current?.before ?? null) as Record<string, unknown> | null; if (before) { - const rec: UndoRec = { project: data.project, clip: clip.id, next: data.next, at: Date.now(), before, moved: !!win }; + const rec: UndoRec = { project: data.project, clip: clip.id, next: data.next, at: Date.now(), before, moved: !!win, take: takeId }; try { sessionStorage.setItem(UNDO_KEY, JSON.stringify(rec)); } catch { @@ -1543,7 +1576,8 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { async (u: UndoRec) => { setUndo(null); const b = u.before; - const r = await fetch(`/api/report/clip?project=${encodeURIComponent(u.project)}&clip=${encodeURIComponent(u.clip)}`, { + const uq = u.take ? `&take=${encodeURIComponent(u.take)}` : ""; + const r = await fetch(`/api/report/clip?project=${encodeURIComponent(u.project)}&clip=${encodeURIComponent(u.clip)}${uq}`, { cache: "no-store", }); if (!r.ok) { @@ -1562,11 +1596,11 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const w = await fetch("/api/report/window", { method: "PUT", headers: { "content-type": "application/json" }, - body: JSON.stringify({ project: u.project, clip: u.clip, token: tok, ...patch }), + body: JSON.stringify({ project: u.project, clip: u.clip, ...(u.take ? { take: u.take } : {}), token: tok, ...patch }), }); const j = (await w.json()) as Record<string, unknown>; if (!w.ok) { - setNote(j.stale ? "could not undo: the manifest changed since — reload" : `could not undo: ${String(j.error ?? w.status)}`); + setNote(j.stale ? `could not undo: the ${u.take ? "take" : "manifest"} changed since — reload` : `could not undo: ${String(j.error ?? w.status)}`); return; } if (wroteNotes(j)) void notes.reload(); @@ -1586,7 +1620,11 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const q = new URLSearchParams(window.location.search); q.delete("at"); const qs = q.toString(); - router.push(`/projects/${u.project}/clip/${encodeURIComponent(u.clip)}${qs ? `?${qs}` : ""}`); + router.push( + u.take + ? `/projects/${u.project}/takes/${encodeURIComponent(u.take)}/clip/${encodeURIComponent(u.clip)}${qs ? `?${qs}` : ""}` + : `/projects/${u.project}/clip/${encodeURIComponent(u.clip)}${qs ? `?${qs}` : ""}`, + ); }, // `notes.reload` is the stable part of `notes`. // eslint-disable-next-line react-hooks/exhaustive-deps @@ -1832,7 +1870,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const refresh = useCallback(async (): Promise<ClipBenchData | null> => { const r = await fetch( - `/api/report/clip?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}`, + `/api/report/clip?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}${tq}`, { cache: "no-store" }, ); if (!r.ok) return null; @@ -1875,6 +1913,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { body: JSON.stringify({ project: data.project, clip: clip.id, + ...takeBody, padBefore: round2(pads.padBefore), padAfter: round2(pads.padAfter), ...storedAsk, @@ -1945,7 +1984,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const r = await fetch("/api/report/fetch", { method: "POST", headers: { "content-type": "application/json" }, - body: JSON.stringify({ project: data.project, clip: clip.id, full: true }), + body: JSON.stringify({ project: data.project, clip: clip.id, ...takeBody, full: true }), }); if (!r.ok) { const j = (await r.json()) as { error?: string }; @@ -2032,7 +2071,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const r = await fetch("/api/report/cut", { method: "POST", headers: { "content-type": "application/json" }, - body: JSON.stringify({ project: data.project, clip: clip.id, token: token.current }), + body: JSON.stringify({ project: data.project, clip: clip.id, ...takeBody, token: token.current }), }); const j = (await r.json()) as { ok?: boolean; @@ -2176,7 +2215,8 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const padLabelForCue = (c: Cue) => c.end > view.to ? `+${padsForCue(c).padAfter} s` : `−${padsForCue(c).padBefore} s`; - const segSrc = segment + // A take's clip has no segment of the project's (ClipBenchPage passes none). + const segSrc = segment && !takeId ? `/api/report/segment?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}&v=${segmentMtime ?? 0}` : null; @@ -2822,11 +2862,24 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { {/* On a phone the banner is one muted line under Notes (phoneNotesHead). The wrapper only when there is a banner: an empty one would be a flex item, and a gap, on the desk. */} - {data.generatedBy && ( + {data.generatedBy && !data.take && ( <div className="max-md:hidden"> <GeneratedBanner generatedBy={data.generatedBy} /> </div> )} + {/* Walking a take: what is being walked, where the edits go, and the take's own structure. */} + {data.take && ( + <TakeWalkStrip + className="max-md:order-[22]" + project={data.project} + take={data.take} + clipId={clip.id} + index={data.take.at} + total={data.take.entries} + nextHref={hrefOf("next")} + getToken={() => token.current} + /> + )} {/* ---- where you are, where you can go, and what will be burned in ---- */} <div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] max-md:contents"> {/* On a phone both counts are the place bar's `50/51` and its hairline. */} @@ -2890,7 +2943,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { <video ref={video} data-testid="clip-video" - src={`/api/report/raw?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}&file=${encodeURIComponent(cached.name)}`} + src={`/api/report/raw?project=${encodeURIComponent(data.project)}&clip=${encodeURIComponent(clip.id)}&file=${encodeURIComponent(cached.name)}${tq}`} // object-contain, because the height is now whatever is left // rather than whatever 16:9 asks for. // The picture and the words SHARE what is left, 3:2, rather @@ -3555,20 +3608,33 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { nothing rendered for this clip yet </div> )} - <button - type="button" - data-rerender="" - className={buttonVariants({ variant: "outline", size: "sm" })} - disabled={!!busy} - onClick={() => void rerender()} - > - Re-render this clip - </button> - <p className="text-[11px] leading-snug text-[var(--color-dim)]"> - One clip, no crossfade, no chapters — it overwrites this clip&rsquo;s segment and - nothing else. The header is drawn by ffmpeg from a text file, so this is the only - place the line above can be checked rather than believed. - </p> + {data.take ? ( + // The one-clip render builds the PROJECT's segment; a take is rendered whole. + <p data-take-no-rerender="" className="text-[11px] leading-snug text-[var(--color-dim)]"> + A take is rendered as a whole, from its own patch:{" "} + <Link href={data.take.takesHref} className="ink-link"> + Render on the Takes page + </Link>{" "} + or <code className="font-mono">umtool take {data.project} --id {data.take.id} --full</code>. + </p> + ) : ( + <> + <button + type="button" + data-rerender="" + className={buttonVariants({ variant: "outline", size: "sm" })} + disabled={!!busy} + onClick={() => void rerender()} + > + Re-render this clip + </button> + <p className="text-[11px] leading-snug text-[var(--color-dim)]"> + One clip, no crossfade, no chapters — it overwrites this clip&rsquo;s segment and + nothing else. The header is drawn by ffmpeg from a text file, so this is the only + place the line above can be checked rather than believed. + </p> + </> + )} </div> {/* ---- lock, explained rather than labelled ---- */} @@ -3662,7 +3728,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { {siblings.map((sb) => ( <li key={sb.id} data-sibling={sb.id} className="leading-snug"> <Link - href={`/projects/${data.project}/clip/${sb.id}`} + href={data.take?.clipHref[sb.id] ?? `/projects/${data.project}/clip/${sb.id}`} className="font-mono ink-link" > {sb.id} diff --git a/umtool/components/projects/ClipBenchPage.tsx b/umtool/components/projects/ClipBenchPage.tsx @@ -1,17 +1,15 @@ import { notFound } from "next/navigation"; -import { projectsHref, clipBenchHref, playHref } from "@/lib/hrefs"; +import { projectsHref, clipBenchHref, playHref, takeClipHref, takeWalkHref, takesHref } from "@/lib/hrefs"; import { BenchFrame, BenchTop } from "./bench/BenchShell"; import ClipBench, { type ClipBenchData } from "./ClipBench"; -import { manifestToken } from "@/lib/report/manifest.mjs"; import { clipVerdict, cuesInWindow, - readClipDetail, - readManifest, siblingsOf, walkOrder, walkReadiness, } from "@/lib/projects/report.mjs"; +import { walkNeighbours, walkOf } from "@/lib/report/walkData.mjs"; import { projectCache, segmentFor, windowsFor } from "@/lib/report/serve.mjs"; import { FETCH_MAX_PAD } from "@/lib/report/driver.mjs"; import { deckOn } from "umtool-report-to-video/deck"; @@ -26,16 +24,28 @@ export default async function ClipBenchPage({ project, clipId, search = {}, + take = null, }: { project: ProjectRef; clipId: string; search?: Record<string, string | undefined>; + /** + * WALKING A TAKE (`/projects/<p>/takes/<take>/clip/<id>`): the clip is the + * take's -- the project's manifest with the take's patch applied + * (lib/report/walkData.mjs) -- and the bench's saves go into the take. + */ + take?: string | null; }) { - const manifest = await readManifest(project.dir); - if (!manifest) notFound(); - - const detail = await readClipDetail(project.dir, { manifest }); - if (!detail) notFound(); + // `?all=1`: the walk visits every fetched clip, judged or not. + const all = search.all === "1"; + let walk: Awaited<ReturnType<typeof walkOf>>; + try { + walk = await walkOf(project, { take, all }); + } catch { + notFound(); + } + const manifest = walk.manifest; + const detail = walk.detail; const entry = detail.entries.find( (e: { id: string; kind: string }) => e.id === clipId && e.kind === "clip", ); @@ -53,26 +63,24 @@ export default async function ClipBenchPage({ // judge and the only move is to press `n` again -- and one already answered is // the round trip a walk exists to remove. A URL still opens ANY clip: this // page renders it, says what it has (or has not) got, and points its links at - // the fetched, unjudged neighbours on either side. + // the fetched, unjudged neighbours on either side. (walkData.mjs, the + // reading `umtool walk` prints; `all` keeps the judged ones on it too.) const readiness = walkReadiness(clips); - const inWalk = new Set<string>(readiness.readyIds as string[]); - const onWalk = (e: { id: string }) => e.id !== clipId && inWalk.has(e.id); - const prev = - [...clips.slice(0, Math.max(0, i))].reverse().find(onWalk)?.id ?? null; - const next = clips.slice(i + 1).find(onWalk)?.id ?? null; + const { prev, next } = walkNeighbours(walk.order, walk.onWalk, clipId); // One listing of clips-raw for the page: readClipDetail already built one to // answer `fetched` for every clip, and this is the same question for this one. - const windows = await windowsFor(project, entry, await projectCache(project)); + const windows = await windowsFor(project, entry, await projectCache(project, manifest)); // The mtime rides along so a re-render busts the browser's cache: the segment // is written back to the SAME path, and without it the player would keep - // showing the cut from before the edit. - const seg = await segmentFor(project, clipId); + // showing the cut from before the edit. A take's clip has none: the + // project's segments are the project's cut. + const seg = take ? null : await segmentFor(project, clipId); const widest = windows[0] ?? null; const view = widest ? { from: widest.from, to: widest.to } : { from: Math.max(0, entry.start - 20), to: entry.end + 20 }; - const cues = await cuesInWindow(project.dir, clipId, view.from, view.to); + const cues = await cuesInWindow(project.dir, clipId, view.from, view.to, { manifest }); const data: ClipBenchData = { project: project.id, @@ -123,7 +131,7 @@ export default async function ClipBenchPage({ endsSentence: entry.endsSentence ?? null, noPunctuation: !!entry.noPunctuation, sourceDuration: entry.duration ?? null, - segment: seg?.rel ?? entry.segment ?? null, + segment: take ? null : (seg?.rel ?? entry.segment ?? null), segmentMtime: seg?.mtimeMs ?? null, // What the header would say with no overrides. Shown beside the fields that // replace it, because "the archive says 2019" is the whole reason `date` @@ -147,7 +155,8 @@ export default async function ClipBenchPage({ ).length, cues: cues?.cues ?? [], siblings: siblingsOf(manifest, clipId), - token: await manifestToken(project.dir), + // The project's manifest token, or -- walking a take -- the take's. + token: walk.token, fetchPad: manifest.render?.fetchPad ?? 3, // The widest the fetch route will go. The BUTTON has to know it: it names // the pad it will ask for, and "that is as wide as it goes" is a different @@ -171,7 +180,8 @@ export default async function ClipBenchPage({ }; // 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" }); + // Walking a take, Back is the take's walk (its overview), on the Takes page's side. + const back = take ? takeWalkHref(project.id, take, { all }) : await pieceHrefOfProject(project.id, { tab: "cut" }); // ---- opened from Play the cut ("Edit this clip") -------------------------- // // `?from=play` rides every walk link from here (p / n / Confirm's advance), @@ -181,17 +191,34 @@ export default async function ClipBenchPage({ // everything after this clip. A take's render does not change when the // project's manifest does, so a take's Back is the project's cut too, and // the bench says so (`take`). - const fromPlay = search.from === "play"; + const fromPlay = !take && search.from === "play"; const playTake = fromPlay && search.take ? search.take : null; const atRaw = Number(search.at); const at = fromPlay && Number.isFinite(atRaw) && atRaw > 0 ? atRaw : 0; - const href = (id: string) => clipBenchHref(project.id, id, fromPlay ? { play: { take: playTake } } : {}); + const href = (id: string) => + take ? takeClipHref(project.id, take, id, { all }) : clipBenchHref(project.id, id, fromPlay ? { play: { take: playTake } } : {}); data.walkHrefs = { prev: prev ? href(prev) : null, next: next ? href(next) : null, back, - backLabel: project.name, + backLabel: take ? `take ${take}` : project.name, }; + if (take && walk.take) { + const timeline = (manifest.timeline ?? []) as { id: string }[]; + data.take = { + id: take, + label: walk.take.label, + draft: walk.take.draft, + editable: walk.take.editable, + all, + takesHref: takesHref(project.id), + walkHref: takeWalkHref(project.id, take, { all }), + toggleAllHref: takeClipHref(project.id, take, clipId, { all: !all }), + clipHref: Object.fromEntries(data.siblings.map((sb: { id: string }) => [sb.id, takeClipHref(project.id, take, sb.id, { all })])), + at: timeline.findIndex((e) => e.id === clipId), + entries: timeline.length, + }; + } data.fromPlay = fromPlay ? { href: playHref(project.id, { clip: clipId, at }), take: playTake } : null; return ( // The bench shell (P4b): its top bar here, the body -- the work, the @@ -200,9 +227,13 @@ export default async function ClipBenchPage({ kind="clip" top={ <BenchTop - trail={[{ href: projectsHref(), label: "Projects" }]} - back={{ href: back, label: project.name }} - kind="Clip bench" + trail={ + take + ? [{ href: projectsHref(), label: "Projects" }, { href: takesHref(project.id), label: `${project.name} · takes` }] + : [{ href: projectsHref(), label: "Projects" }] + } + back={{ href: back, label: take ? `take ${take}` : project.name }} + kind={take ? "Take walk" : "Clip bench"} here={clipId} // The walk on a phone draws its own place bar (ClipBench). phone="hidden" diff --git a/umtool/components/projects/ProjectView.tsx b/umtool/components/projects/ProjectView.tsx @@ -11,6 +11,8 @@ import NarrationPage from "./NarrationPage"; import ReviewPage from "./ReviewPage"; import ClipDeckPage from "./ClipDeckPage"; import PlayCutPage from "./PlayCutPage"; +import TakeWalkPage from "./TakeWalkPage"; +import { isTakeId } from "@/lib/report/takes.mjs"; // --------------------------------------------------------------------------- // The one place a kind id is matched against a component. @@ -58,6 +60,14 @@ export default async function ProjectView({ // `/browse/<project>/takes` -- alternative renders of one part of the // cut, side by side, each judged like / maybe / no. if (rest.length === 1 && rest[0] === "takes") return <TakesPage project={project} />; + // `/projects/<project>/takes/<take>/walk` -- walk a take: its clips, and + // where the walk starts; `…/takes/<take>/clip/<id>` -- the bench on one + // of them, its saves going into the take's patch, never the manifest. + if (rest.length === 3 && rest[0] === "takes" && rest[2] === "walk") return <TakeWalkPage project={project} take={rest[1]} search={search} />; + if (rest.length === 4 && rest[0] === "takes" && rest[2] === "clip") { + if (!isTakeId(rest[1])) return notFound(); + return <ClipBenchPage project={project} clipId={rest[3]} take={rest[1]} search={search} />; + } // `/browse/<project>/narration` -- the narration script, card by card, // approved / edited / rejected before synthesis. if (rest.length === 1 && rest[0] === "narration") return <NarrationPage project={project} />; diff --git a/umtool/components/projects/TakeActions.tsx b/umtool/components/projects/TakeActions.tsx @@ -0,0 +1,136 @@ +"use client"; + +import { useEffect, useState } from "react"; +import Link from "next/link"; +import { useRouter } from "next/navigation"; +import { buttonVariants } from "@/components/ui/button"; +import { startTakeJob } from "./NewTakePanel"; + +// What a take offers once it can be walked (walk a take): walk it, render it +// (a draft's first render, or a walked take's again), and make it the cut. +// The Takes page's cards and the take's walk page both draw this; each button +// is the CLI's own command run the app's way: +// +// Render full / Render 60 s POST /api/report/takes/make { rebuild, window } +// = umtool take <p> --id <t> --rebuild [--full | --at 0 --dur 60] +// Make this the cut POST /api/report/takes/promote +// = umtool take <p> --id <t> --promote [--anyway] + +export default function TakeActions({ + project, + take, + draft, + walkHref, + edited, + compact = false, +}: { + project: string; + take: string; + draft: boolean; + walkHref: string | null; + /** Edited by the walk since its render (or never rendered). */ + edited: boolean; + compact?: boolean; +}) { + const router = useRouter(); + const [ready, setReady] = useState(false); + const [busy, setBusy] = useState(false); + const [said, setSaid] = useState<string | null>(null); + const [stale, setStale] = useState<string | null>(null); + const [done, setDone] = useState<string | null>(null); + useEffect(() => setReady(true), []); + + const render = async (window: "full" | { at: number; dur: number }) => { + setBusy(true); + setSaid(null); + const r = await startTakeJob({ project, rebuild: take, window }); + setBusy(false); + setSaid(r.error ?? "rendering — the job is on the jobs bar"); + }; + const promote = async (anyway: boolean) => { + setBusy(true); + setSaid(null); + try { + const r = await fetch("/api/report/takes/promote", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, take, anyway }), + cache: "no-store", + }); + const j = (await r.json().catch(() => ({}))) as { error?: string; errors?: string[]; stale?: boolean; historyHref?: string; clips?: number }; + if (r.status === 409 && j.stale) setStale(j.error ?? "the project changed since this take was made"); + else if (!r.ok) setSaid(j.errors?.join("; ") ?? j.error ?? `HTTP ${r.status}`); + else { + setStale(null); + setDone(j.historyHref ?? ""); + router.refresh(); + } + } finally { + setBusy(false); + } + }; + const off = !ready || busy; + const size = compact ? "sm" : "md"; + return ( + <div data-take-actions={take} className="flex flex-wrap items-center gap-1.5 text-[11.5px]"> + {walkHref && ( + <Link href={walkHref} data-take-walk-link={take} className={buttonVariants({ variant: draft ? "go" : "outline", size })}> + Walk this take + </Link> + )} + <button + type="button" + data-take-render="full" + disabled={off} + className={buttonVariants({ variant: "outline", size })} + title={`umtool take ${project} --id ${take} --rebuild --full`} + onClick={() => void render("full")} + > + {draft ? "Render full" : edited ? "Render again (full)" : "Render full"} + </button> + <button + type="button" + data-take-render="window" + disabled={off} + className={buttonVariants({ variant: "quiet", size })} + title={`umtool take ${project} --id ${take} --rebuild --at 0 --dur 60`} + onClick={() => void render({ at: 0, dur: 60 })} + > + Render the first 60 s + </button> + <button + type="button" + data-take-promote="" + disabled={off} + className={buttonVariants({ size })} + title={`the take's patch over the project's manifest, one undo point — umtool take ${project} --id ${take} --promote`} + onClick={() => void promote(false)} + > + Make this the cut + </button> + {stale && ( + <span data-take-promote-stale="" className="flex basis-full flex-wrap items-center gap-1.5 text-doubt-text"> + <span>{stale}.</span> + <button type="button" data-take-promote-anyway="" disabled={off} className={buttonVariants({ size: "sm" })} onClick={() => void promote(true)}> + Make it the cut anyway + </button> + </span> + )} + {done !== null && ( + <span data-take-promoted="" className="basis-full text-text-2"> + This take is the cut now — the Cut tab&apos;s Undo last edit takes it back.{" "} + {done && ( + <a href={done} className="ink-link"> + Revisions + </a> + )} + </span> + )} + {said && ( + <span data-take-said="" className="basis-full text-[var(--color-dim)]"> + {said} + </span> + )} + </div> + ); +} diff --git a/umtool/components/projects/TakeWalkPage.tsx b/umtool/components/projects/TakeWalkPage.tsx @@ -0,0 +1,124 @@ +import Link from "next/link"; +import { notFound } from "next/navigation"; +import { hms } from "umtool-report-to-video/attribution"; +import { badgeVariants } from "@/components/ui/badge"; +import { buttonVariants } from "@/components/ui/button"; +import { projectsHref, takeClipHref, takeWalkHref, takesHref } from "@/lib/hrefs"; +import { isTakeId } from "@/lib/report/takes.mjs"; +import { walkOf } from "@/lib/report/walkData.mjs"; +import type { ProjectRef } from "@/lib/project-types"; +import { BenchBody, BenchFrame, BenchTop } from "./bench/BenchShell"; +import TakeActions from "./TakeActions"; + +// `/projects/<project>/takes/<take>/walk` -- WALK A TAKE: the take's clips +// (the project's manifest with the take's patch applied, a draft too) in walk +// order, each with its verdict and whether a fetched file holds it, and where +// the walk starts. Each clip opens the clip bench on the TAKE +// (`…/takes/<take>/clip/<id>`), whose saves go into the take's patch. +// `umtool walk <project> --take <take>` prints the same reading. + +const VERDICT_TONE = { confirmed: "on", incorrect: "meter", unreviewed: "state" } as const; + +export default async function TakeWalkPage({ + project, + take, + search = {}, +}: { + project: ProjectRef; + take: string; + search?: Record<string, string | undefined>; +}) { + if (!isTakeId(take)) notFound(); + const all = search.all === "1"; + let w: Awaited<ReturnType<typeof walkOf>>; + try { + w = await walkOf(project, { take, all }); + } catch { + notFound(); + } + const start = w.first ? takeClipHref(project.id, take, w.first, { all }) : null; + const unfetched = w.clips.filter((c) => !c.fetched).length; + return ( + <BenchFrame + kind="take-walk" + top={ + <BenchTop + trail={[{ href: projectsHref(), label: "Projects" }]} + back={{ href: takesHref(project.id), label: `${project.name} · takes` }} + kind="Take walk" + here={take} + next={start ? { href: start, label: w.first ?? "", attrs: { "data-take-walk-start": w.first ?? "" } } : null} + note={`${w.total} clips · ${hms(w.seconds)} · ${w.reviewed} reviewed`} + /> + } + > + <BenchBody workClassName="space-y-3 overflow-y-auto"> + <section data-take-walk-head={take} className="space-y-1.5"> + <div className="flex flex-wrap items-center gap-2"> + <h1 className="text-[15px] text-text">{w.take?.label ?? take}</h1> + {w.take?.draft && <span className={badgeVariants({ variant: "state", size: "sm" })}>draft — not rendered</span>} + {!w.take?.editable && <span className={badgeVariants({ variant: "meter", size: "sm" })}>read only — a recipe&apos;s take, not made</span>} + </div> + <p className="text-[12px] text-text-2"> + Edits made while walking go into this take&apos;s patch (<code className="font-mono">takes/{take}/take.json</code>), never the + project&apos;s manifest. {w.needing} need a verdict, {w.ready} of them fetched + {unfetched ? ` · ${unfetched} not fetched` : ""}. + </p> + {w.note && <p className="text-[12px] text-doubt-text">{w.note}</p>} + <div className="flex flex-wrap items-center gap-2"> + {start ? ( + <Link href={start} data-take-walk-go="" className={buttonVariants({ variant: "go", size: "md" })}> + Walk → start at {w.first} + </Link> + ) : ( + <span className="text-[12px] text-[var(--color-dim)]"> + {all ? "Nothing fetched to walk." : "Every fetched clip has a verdict."} + </span> + )} + <Link href={takeWalkHref(project.id, take, { all: !all })} data-take-walk-all={all ? "1" : "0"} className="text-[12px] ink-link"> + {all ? "walk only the clips needing a verdict" : "walk every clip (judged ones too)"} + </Link> + </div> + {w.take?.editable && ( + <TakeActions project={project.id} take={take} draft={!!w.take?.draft} walkHref={null} edited compact /> + )} + </section> + <table data-take-walk-clips="" className="w-full border-collapse text-[12px]"> + <thead> + <tr className="micro text-left"> + <th className="py-1 pr-2">#</th> + <th className="py-1 pr-2">clip</th> + <th className="py-1 pr-2">window</th> + <th className="py-1 pr-2 text-right">s</th> + <th className="py-1 pr-2">verdict</th> + <th className="py-1 pr-2">quote</th> + </tr> + </thead> + <tbody> + {w.clips.map((c) => ( + <tr key={c.id} data-take-walk-clip={c.id} data-on-walk={c.onWalk ? "1" : "0"} className="border-t border-seam align-top"> + <td className="num py-1 pr-2 text-[var(--color-dim)]">{c.cut}</td> + <td className="py-1 pr-2"> + <Link href={takeClipHref(project.id, take, c.id, { all })} className="font-mono ink-link"> + {c.id} + </Link> + {c.onWalk && <span className="ml-1 text-meter" title="on the walk">→</span>} + </td> + <td className="num py-1 pr-2 whitespace-nowrap"> + {hms(c.start)}–{hms(c.end)} + {!c.fetched && <span className={`ml-1 ${badgeVariants({ variant: "state", size: "sm" })}`}>not fetched</span>} + </td> + <td className="num py-1 pr-2 text-right">{c.seconds.toFixed(1)}</td> + <td className="py-1 pr-2"> + <span className={badgeVariants({ variant: VERDICT_TONE[c.verdict as keyof typeof VERDICT_TONE] ?? "state", size: "sm" })}>{c.verdict}</span> + {c.correction && <span className="block text-[11px] text-doubt-text">{c.correction}</span>} + </td> + <td className="py-1 pr-2 text-text-2">{c.quote}</td> + </tr> + ))} + </tbody> + </table> + </BenchBody> + </BenchFrame> + ); +} diff --git a/umtool/components/projects/TakesBench.tsx b/umtool/components/projects/TakesBench.tsx @@ -10,9 +10,10 @@ import TimedNotes from "@/components/notes/TimedNotes"; import { badgeVariants, type BadgeVariants } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; import { fmtAgo } from "@/lib/format"; -import { playHref } from "@/lib/hrefs"; +import { playHref, takeWalkHref } from "@/lib/hrefs"; import { BenchBody, VerdictBar } from "./bench/BenchShell"; import { startTakeJob } from "./NewTakePanel"; +import TakeActions from "./TakeActions"; // The takes of one project, a group at a time, every preview on screen at once. // @@ -47,6 +48,10 @@ export type Take = { quick?: boolean; /** The project's manifest is not the one it was made from (null: it does not say). */ stale?: boolean | null; + /** Recorded, not rendered (`umtool take … --draft`): walk it, then render it. */ + draft?: boolean; + /** The walk's last edit to its patch (later than builtAt: the render is older than the take). */ + editedAt?: string | null; }; export type Verdict = "like" | "maybe" | "no"; @@ -397,6 +402,10 @@ function TakeCard({ if (r.error) setError(r.error); }; 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). + const editedSinceRender = !!t.editedAt && (!t.builtAt || t.editedAt > t.builtAt); + const walkable = !!t.draft || !!t.baseHash; return ( <article @@ -419,6 +428,16 @@ function TakeCard({ }} className="aspect-video w-full bg-black" /> + ) : t.draft ? ( + <div + data-take-draft={t.id} + className="flex aspect-video w-full flex-col items-center justify-center gap-1 bg-black px-3 text-center text-[12px] text-[var(--color-dim)]" + > + <span className="text-text-2">draft — walk / render</span> + <span className="text-[11px]"> + nothing rendered yet: walk its clips on the bench (edits go into this take), then render it + </span> + </div> ) : ( <div data-no-preview="" className="flex aspect-video w-full items-center justify-center bg-black text-[11px] text-[var(--color-dim)]"> no preview yet @@ -439,6 +458,16 @@ function TakeCard({ picked </span> )} + {t.draft && ( + <span data-take-is-draft="" className={badgeVariants({ variant: "state", size: "sm" })}> + draft + </span> + )} + {!t.draft && editedSinceRender && ( + <span data-take-edited="" className={badgeVariants({ variant: "meter", size: "sm" })} title="walked since its render: Render again to watch the edits"> + edited since render + </span> + )} <Link href={playHref(project, { take: t.id })} data-play-take={t.id} @@ -501,17 +530,30 @@ function TakeCard({ Both land in the project's notes.json, which the agent that made the takes reads back (`umtool notes`) beside verdicts.json. */} <AnchoredNotes notes={notes} pin={{ kind: "take", take: t.id }} label="take notes" /> + {walkable && ( + <TakeActions + project={project} + take={t.id} + draft={!!t.draft} + walkHref={takeWalkHref(project, t.id)} + edited={!!t.draft || editedSinceRender} + compact + /> + )} <div className="flex flex-wrap items-center gap-1.5"> + {!t.draft && ( <button type="button" data-action="pick" disabled={!ready || busy} className={buttonVariants({ size: "sm" })} + title="the manifest this take was RENDERED from, over the project's" onClick={() => void pick(false)} > Use this take </button> - {t.baseHash && ( + )} + {t.baseHash && !t.draft && ( <button type="button" data-action="rebuild" diff --git a/umtool/components/projects/bench/RenderGhosts.tsx b/umtool/components/projects/bench/RenderGhosts.tsx @@ -52,13 +52,15 @@ export function useRenderEdges( project: string, clip: { id: string; start: number; end: number; cutStart: number | null; cutEnd: number | null }, sel: { from: number; to: number }, + /** Walking a take: the clip is the take's (the cut-points route reads its manifest). */ + take: string | null = null, ): RenderEdges { const [got, setGot] = useState<{ key: string; row: Row | null; knobs: Got["knobs"]; leadIn: number } | null>(null); // Measured again when what was SAVED moves (the extent picks the file and the span). - const key = `${project}|${clip.id}|${clip.start}|${clip.end}|${clip.cutStart}|${clip.cutEnd}`; + const key = `${project}|${take ?? ""}|${clip.id}|${clip.start}|${clip.end}|${clip.cutStart}|${clip.cutEnd}`; useEffect(() => { let live = true; - const q = new URLSearchParams({ project, clip: clip.id }); + const q = new URLSearchParams({ project, clip: clip.id, ...(take ? { take } : {}) }); fetch(`/api/report/cut-points?${q}`, { cache: "no-store" }) .then((r) => (r.ok ? (r.json() as Promise<Got>) : null)) .then((j) => { @@ -68,7 +70,7 @@ export function useRenderEdges( return () => { live = false; }; - }, [key, project, clip.id]); + }, [key, project, clip.id, take]); const row = got?.row; if (!got || !row || !row.silences || row.fetchStart == null || row.montage) return null; const pw = playWindowOf(sel, clip, got.leadIn); diff --git a/umtool/components/projects/bench/TakeWalkStrip.tsx b/umtool/components/projects/bench/TakeWalkStrip.tsx @@ -0,0 +1,140 @@ +"use client"; + +import { useEffect, useState } from "react"; +import Link from "next/link"; +import { badgeVariants } from "@/components/ui/badge"; +import { buttonVariants } from "@/components/ui/button"; +import { cn } from "@/lib/utils"; + +// WALKING A TAKE: the line that says so, on the clip bench, and the take's +// own structure -- this clip out of the take, earlier or later in it, and the +// take's last edit taken back. Every one is POST /api/report/takes/timeline +// (lib/report/takeEdit.mjs), the writer `umtool timeline <p> --take <id>` +// runs; the project's manifest is never written from here. +// +// After a structural edit the page is LOADED again rather than refreshed: the +// bench holds its token and its drafts in state, and a remount is the honest +// way to show the take as it now is. + +export default function TakeWalkStrip({ + project, + take, + clipId, + index, + total, + nextHref, + getToken, + className, +}: { + project: string; + take: { id: string; label: string; draft: boolean; editable: boolean; all: boolean; takesHref: string; walkHref: string; toggleAllHref: string }; + clipId: string; + /** This clip's place in the take's timeline, 0-based, and the timeline's length. */ + index: number; + total: number; + /** Where the walk goes after this clip is removed. */ + nextHref: string | null; + getToken: () => string | null; + className?: string; +}) { + const [ready, setReady] = useState(false); + const [busy, setBusy] = useState(false); + const [said, setSaid] = useState<string | null>(null); + useEffect(() => setReady(true), []); + + const run = async (op: "move" | "remove" | "undo", extra: Record<string, unknown> = {}, then: string | null = null) => { + setBusy(true); + setSaid(null); + try { + const r = await fetch("/api/report/takes/timeline", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, take: take.id, op, token: getToken(), ...extra }), + cache: "no-store", + }); + const j = (await r.json().catch(() => ({}))) as { error?: string; errors?: string[]; stale?: boolean }; + if (!r.ok) { + setSaid(j.stale ? "the take changed since this page was read — reload" : (j.errors?.join("; ") ?? j.error ?? `HTTP ${r.status}`)); + return; + } + window.location.assign(then ?? window.location.href); + } finally { + setBusy(false); + } + }; + + const off = !ready || busy || !take.editable; + return ( + <div + data-take-walk={take.id} + className={cn( + "flex flex-wrap items-center gap-x-2 gap-y-1 rounded border border-[var(--color-sel)] bg-[var(--color-panel)] px-2 py-1 text-[11.5px]", + className, + )} + > + <span className="micro">walking take</span> + <span className="font-mono text-[var(--color-text)]">{take.id}</span> + <span className="truncate text-text-2">{take.label}</span> + {take.draft && <span className={badgeVariants({ variant: "state", size: "sm" })}>draft</span>} + <span className="text-[var(--color-dim)]"> + {take.editable ? "edits go to the take, not the cut" : "a recipe's take, not made yet: read only"} + </span> + <span className="ml-auto flex flex-wrap items-center gap-1.5"> + <span className="num text-[var(--color-dim)]"> + {index + 1}/{total} in the take + </span> + <button + type="button" + data-take-move="earlier" + disabled={off || index <= 0} + className={buttonVariants({ variant: "outline", size: "sm" })} + title="one place earlier in the take" + onClick={() => void run("move", { id: clipId, toIndex: index - 1 })} + > + ← earlier + </button> + <button + type="button" + data-take-move="later" + disabled={off || index >= total - 1} + className={buttonVariants({ variant: "outline", size: "sm" })} + title="one place later in the take" + onClick={() => void run("move", { id: clipId, toIndex: index + 1 })} + > + later → + </button> + <button + type="button" + data-take-remove={clipId} + disabled={off} + className={buttonVariants({ variant: "outline", size: "sm" })} + title="take this clip out of the take (Undo puts it back)" + onClick={() => void run("remove", { id: clipId }, nextHref ?? take.takesHref)} + > + Remove from take + </button> + <button + type="button" + data-take-undo="" + disabled={off} + className={buttonVariants({ size: "sm" })} + title="take back the take's last edit -- a verdict, a trim, a move or a removal" + onClick={() => void run("undo")} + > + Undo take edit + </button> + <Link href={take.toggleAllHref} data-take-walk-all={take.all ? "1" : "0"} className="ink-link"> + {take.all ? "walk the unjudged only" : "walk every clip"} + </Link> + <Link href={take.takesHref} className="ink-link"> + Takes + </Link> + </span> + {said && ( + <span data-take-said="" className="basis-full text-[var(--color-bad)]"> + {said} + </span> + )} + </div> + ); +} diff --git a/umtool/components/projects/report/CutTab.tsx b/umtool/components/projects/report/CutTab.tsx @@ -8,7 +8,7 @@ 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, takesHref } from "@/lib/hrefs"; +import { clipBenchHref, clipDeckHref, clipEditorHref, mixHref as toolsMixHref, playHref, projectHref, takeWalkHref, takesHref } from "@/lib/hrefs"; import { montageClipsOf, momentKeysOf, readRulingsState } from "@/lib/report/montageRulings.mjs"; import FetchUnfetchedButton from "../FetchUnfetchedButton"; import { clipRecord, storedUrlOf } from "@/lib/clips/stored"; @@ -199,6 +199,22 @@ export default async function CutTab({ project, detail, search, tabHref }: Repor Make takes </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]"> + <span className="micro">walk a take</span> + {[...takes.takes] + .filter((t: { draft?: boolean; baseHash?: string | null }) => t.draft || t.baseHash) + .sort((a: { draft?: boolean }, b: { draft?: boolean }) => Number(!!b.draft) - Number(!!a.draft)) + .slice(0, 6) + .map((t: { id: string; label: string; draft?: boolean }) => ( + <Link key={t.id} href={takeWalkHref(project.id, t.id)} data-walk-take={t.id} className="ink-link" title={t.label}> + {t.id} + {t.draft ? " (draft)" : ""} + </Link> + ))} + </span> + )} {clips.length > 0 && ( <VoiceMatchPanel project={project.id} diff --git a/umtool/lib/hrefs.test.mjs b/umtool/lib/hrefs.test.mjs @@ -23,6 +23,13 @@ test("note is always the last parameter", () => { } }); +test("walk a take: /projects/<p>/takes/<take>/walk and …/clip/<id>, `all` as 1, note last", () => { + assert.equal(H.takeWalkHref("a/b", "tight-1"), "/projects/a/b/takes/tight-1/walk"); + assert.equal(H.takeWalkHref("a/b", "tight-1", { all: true }), "/projects/a/b/takes/tight-1/walk?all=1"); + assert.equal(H.takeClipHref("a/b", "tight-1", "t01a"), "/projects/a/b/takes/tight-1/clip/t01a"); + assert.equal(H.takeClipHref("a/b", "tight-1", "t01a", { all: true, note: "n" }), "/projects/a/b/takes/tight-1/clip/t01a?all=1&note=n"); +}); + test("the clip deck: /projects/<p>/clips, its filter in `show`", () => { assert.equal(H.clipDeckHref("a/b"), "/projects/a/b/clips"); assert.equal(H.clipDeckHref("a/b", { show: "unruled" }), "/projects/a/b/clips?show=unruled"); diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts @@ -296,6 +296,24 @@ export function takesHref(project: string, q: NoteOpt = {}): string { return withQuery(`/projects/${encodePath(project)}/takes`, {}, q.note); } +/** + * Walk a take: the take's clips, the walk's start (an overview of every clip, + * and where the walk begins). `all`: the walk visits every fetched clip, judged + * or not, rather than only the ones still needing a verdict. + */ +export function takeWalkHref(project: string, take: string, q: NoteOpt & { all?: boolean } = {}): string { + return withQuery(`/projects/${encodePath(project)}/takes/${encodeURIComponent(take)}/walk`, { all: q.all }, q.note); +} + +/** The clip bench on one of a take's clips: its saves go into the take's patch, never the project's manifest. */ +export function takeClipHref(project: string, take: string, clip: string, q: NoteOpt & { all?: boolean } = {}): string { + return withQuery( + `/projects/${encodePath(project)}/takes/${encodeURIComponent(take)}/clip/${encodeURIComponent(clip)}`, + { all: q.all }, + q.note, + ); +} + /** What the clip deck (release 34) walks: every instance, the unruled, the doubtful first, the ruled. */ export const CLIP_DECK_SHOWS = ["all", "unruled", "doubtful", "ruled"] as const; export type ClipDeckShow = (typeof CLIP_DECK_SHOWS)[number]; diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -1541,9 +1541,19 @@ export async function readClipDetail(dir, { manifest = null } = {}) { return { manifest: m, build, channelsDir, shadowExists, entries }; } -/** The cues a clip bench draws, trimmed to a window. Absolute source seconds. */ -export async function cuesInWindow(dir, clipId, from, to) { - const m = await readManifest(dir); +/** + * The cues a clip bench draws, trimmed to a window. Absolute source seconds. + * `manifest`: the one the clip is in, when it is not the project's own (a + * take's, walking a take). + * + * @param {string} dir + * @param {string} clipId + * @param {number} from + * @param {number} to + * @param {{ manifest?: Record<string, any> | null }} [opts] + */ +export async function cuesInWindow(dir, clipId, from, to, { manifest = null } = {}) { + const m = manifest ?? (await readManifest(dir)); const e = clipsOf(m).find((x) => x.id === clipId); if (!e) return null; return cuesOfSource(dir, m, e, from, to); diff --git a/umtool/lib/report/driver.mjs b/umtool/lib/report/driver.mjs @@ -298,9 +298,11 @@ export const FETCH_MAX_PAD = 120; * @param {{ dir: string }} project * @param {string} clipId * @param {number | { padBefore: number, padAfter: number }} pad + * @param {{ manifestPath?: string | null }} [opts] the manifest the clip is in, when it + * is not the project's (a take's, written beside it: takeManifest.mjs writePlayManifest) * @returns {import("../trim").Step[]} */ -export function fetchSteps(project, clipId, pad) { +export function fetchSteps(project, clipId, pad, { manifestPath = null } = {}) { // A number is the symmetric shorthand; {padBefore, padAfter} is one edge at // a time, which is what extending a window actually is. const before = typeof pad === "object" && pad ? Number(pad.padBefore) : Number(pad); @@ -313,7 +315,7 @@ export function fetchSteps(project, clipId, pad) { argv: [ "node", script("build-video.mjs"), - path.join(project.dir, "video.manifest.json"), + manifestPath ?? path.join(project.dir, "video.manifest.json"), "--out", path.join(project.dir, "out"), "--fetch-only", @@ -348,9 +350,10 @@ export function fetchSteps(project, clipId, pad) { * @param {{ dir: string }} project * @param {string} clipId * @param {number | { padBefore: number, padAfter: number, storedUrl?: "fallback" | "only" | null }} pad + * @param {{ manifestPath?: string | null }} [opts] as fetchSteps * @returns {import("../trim").Step[]} */ -export function editorFetchSteps(project, clipId, pad) { +export function editorFetchSteps(project, clipId, pad, { manifestPath = null } = {}) { const before = typeof pad === "object" && pad ? Number(pad.padBefore) : Number(pad); const after = typeof pad === "object" && pad ? Number(pad.padAfter) : Number(pad); // Cut from the stored media URL (release 32 R6): `--stored-url <mode>`. @@ -370,7 +373,7 @@ export function editorFetchSteps(project, clipId, pad) { argv: [ "node", script("fetch-via-editor.mjs"), - path.join(project.dir, "video.manifest.json"), + manifestPath ?? path.join(project.dir, "video.manifest.json"), "--fetch-only", clipId, "--pad-before", @@ -414,7 +417,7 @@ export function editorFetchSteps(project, clipId, pad) { * * @param {{ dir: string }} project * @param {string} clipId - * @param {{ maxHeight?: unknown, manifest?: { render?: { maxHeightSource?: unknown } } | null }} [opts] + * @param {{ maxHeight?: unknown, manifest?: { render?: { maxHeightSource?: unknown } } | null, manifestPath?: string | null }} [opts] * @returns {import("../trim").Step[]} */ export function editorFullSourceSteps(project, clipId, opts = {}) { @@ -429,7 +432,7 @@ export function editorFullSourceSteps(project, clipId, opts = {}) { argv: [ "node", script("fetch-via-editor.mjs"), - path.join(project.dir, "video.manifest.json"), + opts.manifestPath ?? path.join(project.dir, "video.manifest.json"), "--fetch-only", clipId, "--full", diff --git a/umtool/lib/report/serve.mjs b/umtool/lib/report/serve.mjs @@ -85,6 +85,9 @@ export { rawCacheOf } from "./raw-cache.mjs"; * are the question. A bare rawCacheOf sees only out/clips-raw, so a window the * editor fetched reads as "nothing fetched for this clip yet" and the bench * offers to download bytes that are already on the disk. + * + * @param {any} project + * @param {Record<string, any> | null} [manifest] the manifest whose clips name the dirs (a take's, walking one); else the project's */ export async function projectCache(project, manifest = null) { const m = manifest ?? (await readManifest(project.dir)); diff --git a/umtool/lib/report/takeEdit.mjs b/umtool/lib/report/takeEdit.mjs @@ -198,12 +198,25 @@ export async function updateTakeClip(projectDir, id, clipId, patch, { token = nu ); } -/** Move one of the take's entries to `toIndex` (its index after the move). */ +/** + * Move one of the take's entries to `toIndex` (its index after the move). + * @param {string} projectDir + * @param {string} id the take + * @param {string} entryId + * @param {number} toIndex + * @param {{ token?: string | null, at?: number | null, now?: Date }} [opts] + */ export async function moveTakeEntry(projectDir, id, entryId, toIndex, { token = null, at = null, now = new Date() } = {}) { return editTakeTimeline(projectDir, id, "move", token, (m) => applyStructural(m, (x) => moveIn(x, entryId, toIndex, at)), { now }); } -/** Remove one of the take's entries (refused when something the take keeps still names it). */ +/** + * Remove one of the take's entries (refused when something the take keeps still names it). + * @param {string} projectDir + * @param {string} id the take + * @param {string} entryId + * @param {{ token?: string | null, at?: number | null, now?: Date }} [opts] + */ export async function removeTakeEntry(projectDir, id, entryId, { token = null, at = null, now = new Date() } = {}) { return editTakeTimeline(projectDir, id, "remove", token, (m) => applyStructural(m, (x) => removeIn(x, entryId, at)), { now }); } diff --git a/umtool/lib/report/walkData.mjs b/umtool/lib/report/walkData.mjs @@ -73,6 +73,15 @@ export function walkNeighbours(order, onWalk, clipId) { } /** + * @typedef {{ + * id: string, cut: number | null, channel: string | null, video: string, start: number, end: number, + * seconds: number, cutStart: number | null, cutEnd: number | null, + * verdict: "confirmed" | "incorrect" | "unreviewed", correction: string | null, quote: string | null, + * fetched: boolean, onWalk: boolean, + * }} WalkClip + */ + +/** * The walk of a project's cut or of a take. * * @param {{ id: string, dir: string }} project @@ -88,7 +97,8 @@ export async function walkOf(project, { take = null, all = false } = {}) { const cutIndex = new Map( (detail.entries ?? []).filter((e) => e.kind === "clip").map((e, i) => [e.id, i + 1]), ); - const clips = ordered.map((e) => ({ + /** @type {WalkClip[]} */ + const clips = ordered.map((/** @type {any} */ e) => ({ id: e.id, /** 1-based place among the cut's clips (the timeline's order). */ cut: cutIndex.get(e.id) ?? null,