commit 0d215526ef4a5d3809c7d375868ba416c9e98b06
parent 61e03863002e2da495c7ad5d7f1e5aaacf8cef83
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 2 Nov 2026 17:09:50 -0500
umtool trailer-beats: status, anchor, clamp, repoint, history -- what the page does with a reel's source, from a terminal
status [--take <t>] [--json] each beat against the take the reel plays
now (reelPlayView's classification) and the
reel's line
anchor [<n>…] --take <t> anchor beats to that take's master
clamp <n> | repoint <n> <clip> a clipped beat inside its clip's new limits;
an orphan's seconds on another clip
history [--json] promo/<name>-beats.history.json
--take <t> on any edit the beat is anchored to that take
On the Kirsche copy: anchored to draft-6, read against draft-7 (kf3c's end
moved 2773.55 → 2776.071): "cut against draft-6; take draft-7 changes beat 7"
-- the kf3c beat, nothing else.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 117 insertions(+), 5 deletions(-)
diff --git a/umtool/lib/report/trailerBeatsCli.mjs b/umtool/lib/report/trailerBeatsCli.mjs
@@ -10,6 +10,9 @@
// Plain ESM: the CLI runs under bare node.
import { editGaps } from "umtool-report-to-video/gaps";
import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs";
+import { clampPatch } from "./reelAnchor.mjs";
+import { readReelHistory } from "./reelHistory.mjs";
+import { anchorContextOf, reelPlayView } from "./reelPlay.mjs";
import { readManifest } from "../projects/report.mjs";
import {
BEAT_VERDICTS,
@@ -17,6 +20,7 @@ import {
DEFAULT_REEL,
TRAILER_LIMITS,
addTrailerBeat,
+ anchorTrailerBeats,
beatsToken,
clockOf,
createReel,
@@ -51,17 +55,24 @@ export const TRAILER_BEATS_USAGE = [
` umtool trailer-beats <project> verdict <n> ${BEAT_VERDICTS.join("|")}|clear the walk's word on beat n`,
" umtool trailer-beats <project> title <text>|none | take <take>|none the reel's name, the take it is cut from",
" umtool trailer-beats <project> undo the reel as it was before its last write (each write is an undo point)",
+ " umtool trailer-beats <project> status [--take <t>] [--json] each beat against the take the reel plays now:",
+ " unchanged, rerendered, edges, look, clipped, orphan, unanchored (what it was cut against)",
+ " umtool trailer-beats <project> anchor [<n>…] --take <t> anchor beats (all, or n…) to that take's master",
+ " umtool trailer-beats <project> clamp <n> [--take <t>] | repoint <n> <clip> [--take <t>]",
+ " a clipped beat pulled inside its clip's new limits; an orphan's seconds on another clip",
+ " umtool trailer-beats <project> history [--json] every write to the reel: what moved, old and new",
" umtool trailer-beats <project> reels [--json] the project's reels",
" umtool trailer-beats <project> new-reel <name> [--from <reel>] [--title T] a new reel (empty, or a copy)",
"",
"--reel <name> on any of these: that reel (promo/<name>-beats.json); the default is `trailer`, promo/trailer-beats.json.",
+ "--take <t> on an edit: the take it is made against -- the beat is anchored to that take's master.",
"`umtool trailer <p> --reel <name> [--take <t>]` cuts it.",
].join("\n");
class CliError extends Error {}
function parse(args) {
- const valued = new Set(["--at", "--to", "--label", "--reel", "--from", "--title"]);
+ const valued = new Set(["--at", "--to", "--label", "--reel", "--from", "--title", "--take"]);
/** @type {Record<string, string>} */
const flags = {};
const positional = [];
@@ -140,6 +151,11 @@ export async function trailerBeatsCommand(args, { root = REPORTS_ROOT, out = (s)
const label = p.has("--label") ? p.flags["--label"] : undefined;
const at = p.has("--at") ? beatNo(p.flags["--at"], "--at") : null;
let did = null;
+ // An edit made against a take (--take): the beats written are anchored to it (reelAnchor.mjs).
+ const anchorTake = p.has("--take") ? p.flags["--take"] : null;
+ const ctx = anchorTake && verb !== "status" ? await anchorContextOf(project.dir, anchorTake) : null;
+ if (anchorTake && verb !== "status" && !ctx) throw new CliError(`--take ${anchorTake}: no finished master to anchor to`);
+ const anchorFor = ctx?.anchorFor ?? null;
switch (verb) {
case "ls":
break;
@@ -149,7 +165,7 @@ export async function trailerBeatsCommand(args, { root = REPORTS_ROOT, out = (s)
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, reel });
+ const res = await addTrailerBeat(project.dir, { id, ...span, ...(label ? { label } : {}) }, { token, at, manifest, reel, anchorFor });
did = `added beat ${res.index + 1}: ${id} ${res.beat.start}–${res.beat.end}`;
break;
}
@@ -165,8 +181,9 @@ export async function trailerBeatsCommand(args, { root = REPORTS_ROOT, out = (s)
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, reel });
- did = `beat ${i + 1}: ${JSON.stringify(res.beat)}`;
+ const res = await updateTrailerBeat(project.dir, i, patch, { token, reel, anchorFor });
+ const { anchor: _a, ...shown } = res.beat;
+ did = `beat ${i + 1}: ${JSON.stringify(shown)}`;
break;
}
case "gap": {
@@ -186,7 +203,7 @@ export async function trailerBeatsCommand(args, { root = REPORTS_ROOT, out = (s)
next = editGaps(b.gaps ?? [], { remove: t });
} else if (op === "clear") next = [];
else throw new CliError("gap <n> add <from>-<to> | remove <second> | clear");
- const res = await updateTrailerBeat(project.dir, i, { gaps: next }, { token, reel });
+ const res = await updateTrailerBeat(project.dir, i, { gaps: next }, { token, reel, anchorFor });
did = `beat ${i + 1}: ${(res.beat.gaps ?? []).length ? `gaps ${res.beat.gaps.map((g) => `${g.from}–${g.to}`).join(", ")}` : "no gaps"}`;
break;
}
@@ -244,6 +261,55 @@ export async function trailerBeatsCommand(args, { root = REPORTS_ROOT, out = (s)
did = `beat ${i + 1}: ${v === "clear" ? "verdict cleared" : v}`;
break;
}
+ case "status": {
+ const v = await reelPlayView(project, { reel, take: anchorTake });
+ if (!v.status) throw new CliError(v.noMaster?.why ?? "no take to classify the beats against");
+ const rows = (v.rows ?? []).map((r) => ({ n: r.n, id: r.id, beat: r.beat, state: r.status?.state ?? null, why: r.status?.why ?? null, was: r.status?.was ?? null, now: r.status?.now ?? null }));
+ if (p.has("--json")) out(JSON.stringify({ project: project.id, reel, take: v.take?.id ?? null, ...v.status, rows }, null, 2));
+ else {
+ out(`reel ${reel} on take ${v.take?.id} (${v.take?.why}): ${v.status.line}`);
+ for (const r of rows) out(`${String(r.n).padStart(3)} ${(r.id ?? "(master)").padEnd(10)} ${(r.state ?? "?").padEnd(11)} ${r.why ?? ""}`);
+ }
+ return 0;
+ }
+ case "anchor": {
+ if (!anchorFor) throw new CliError("anchor [<n>…] --take <t>: the take whose master the beats are anchored to");
+ const only = rest.length ? rest.map((x) => beatNo(x)) : null;
+ await anchorTrailerBeats(project.dir, anchorFor, { token, reel, only, take: anchorTake ?? "" });
+ did = `anchored ${only ? `beat${only.length === 1 ? "" : "s"} ${only.map((k) => k + 1).join(", ")}` : "every beat"} to take ${anchorTake}`;
+ break;
+ }
+ case "clamp":
+ case "repoint": {
+ const i = beatNo(rest[0]);
+ const v = await reelPlayView(project, { reel, take: anchorTake });
+ const row = (v.rows ?? [])[i];
+ const doc = await readTrailerBeats(project.dir, { reel });
+ const b = doc.beats[i];
+ if (!row || !b) throw new CliError(`no beat ${i + 1}`);
+ const useFor = anchorFor ?? (v.take ? (await anchorContextOf(project.dir, v.take.id))?.anchorFor ?? null : null);
+ if (verb === "clamp") {
+ if (row.status?.state !== "clipped" || !row.status.now) throw new CliError(`beat ${i + 1} is ${row.status?.state ?? "not classified"}: only a clipped beat is clamped`);
+ const patch = clampPatch(b, { clip: row.status.now });
+ if (!patch) throw new CliError(`beat ${i + 1}: nothing of it is left inside ${b.id}'s new limits — re-place it (set) or remove it`);
+ await updateTrailerBeat(project.dir, i, patch, { token, reel, anchorFor: useFor });
+ did = `beat ${i + 1}: clamped to ${patch.start}–${patch.end}`;
+ } else {
+ const id = rest[1];
+ if (!id) throw new CliError("repoint <n> <clip>");
+ if (!(manifest.timeline ?? []).some((x) => x?.id === id && x.type === "clip")) throw new CliError(`no clip ${id} in the cut`);
+ await updateTrailerBeat(project.dir, i, { id }, { token, reel, anchorFor: useFor });
+ did = `beat ${i + 1}: re-pointed to ${id}`;
+ }
+ break;
+ }
+ case "history": {
+ const h = await readReelHistory(project.dir, reelFileOf(reel));
+ if (p.has("--json")) out(JSON.stringify({ project: project.id, reel, entries: h }, null, 2));
+ else if (!h.length) out(`no history for the reel ${reel} yet (it starts with the next write)`);
+ else for (const e of h) out(`${e.at} ${e.what}${e.take ? ` (take ${e.take})` : ""}${e.changes?.length ? `: ${e.changes.map((c) => (c.op ? `${c.op}${c.n ? ` ${c.n}` : ""}` : `${c.n}.${c.field} ${JSON.stringify(c.old)} → ${JSON.stringify(c.new)}`)).join("; ")}` : ""}`);
+ return 0;
+ }
case "undo": {
const u = await undoTrailerBeats(project.dir, { token, reel });
did = `undone: ${u.undone} (${u.left} undo point${u.left === 1 ? "" : "s"} left)`;
diff --git a/umtool/lib/report/trailerBeatsCli.test.mjs b/umtool/lib/report/trailerBeatsCli.test.mjs
@@ -41,3 +41,49 @@ test("gap <n> add / remove / clear: written through the writer, said, refused by
await rm(r, { recursive: true, force: true });
}
});
+
+test("status / anchor / clamp: a reel anchored to one take, read against another that moved a clip's end; the clipped beat clamped", async () => {
+ const r = await mkdtemp(path.join(tmpdir(), "umtool-tbcli-st-"));
+ const dir = path.join(r, "p1");
+ const takeOf = async (id, aEnd, builtAt) => {
+ const t = path.join(dir, "takes", id);
+ await mkdir(path.join(t, "out", "sourced", "segments"), { recursive: true });
+ await writeFile(path.join(t, "video.manifest.json"), JSON.stringify({ slug: "p1", render: { fps: 30 }, timeline: [] }));
+ await writeFile(path.join(t, "take.json"), JSON.stringify({ id, group: "takes", order: 1, label: id, kind: "reference", summary: "", changes: [], preview: "preview.mp4", seconds: 10, builtAt, style: null, patch: null, window: "full" }));
+ await writeFile(path.join(t, "out", "p1.mp4"), "x");
+ await writeFile(path.join(t, "out", "sourced", "schedule.json"), JSON.stringify({ version: 1, fps: 30, transition: 0, total: aEnd - 100 + 10, segments: [
+ { id: "a", type: "clip", start: 0, duration: aEnd - 100, end: aEnd - 100 },
+ { id: "b", type: "clip", start: aEnd - 100, duration: 10, end: aEnd - 90 },
+ ] }));
+ await writeFile(path.join(t, "out", "sourced", "segments", "a.cut.json"), JSON.stringify({ id: "a", start: 100, end: aEnd }));
+ await writeFile(path.join(t, "out", "sourced", "segments", "b.cut.json"), JSON.stringify({ id: "b", start: 200, end: 210 }));
+ };
+ await mkdir(path.join(dir, "promo"), { recursive: true });
+ await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ slug: "p1", title: "P1", timeline: [{ type: "clip", id: "a", video: "v", start: 100, end: 110 }, { type: "clip", id: "b", video: "v", start: 200, end: 210 }] }));
+ await writeFile(path.join(dir, "promo", "trailer-beats.json"), JSON.stringify([{ id: "a", start: 101, end: 109 }, { id: "b", start: 201, end: 205 }]));
+ await takeOf("t1", 110, "2026-11-01T00:00:00Z");
+ await takeOf("t2", 107, "2026-11-02T00:00:00Z");
+ const out = [];
+ const err = [];
+ const run = (...a) => trailerBeatsCommand(["p1", ...a], { root: r, out: (s) => out.push(s), err: (s) => err.push(s) });
+ try {
+ assert.equal(await run("anchor", "--take", "t1"), 0, err.join("\n"));
+ out.length = 0;
+ assert.equal(await run("status", "--take", "t2", "--json"), 0, err.join("\n"));
+ const st = JSON.parse(out.join("\n"));
+ assert.equal(st.line, "cut against t1; take t2 changes beat 1");
+ assert.deepEqual(st.rows.map((x) => x.state), ["clipped", "rerendered"]);
+ assert.deepEqual(st.rows[0].now, { start: 100, end: 107, gaps: [] });
+ assert.equal(await run("clamp", "1", "--take", "t2"), 0, err.join("\n"));
+ const beats = JSON.parse(await readFile(path.join(dir, "promo", "trailer-beats.json"), "utf8"));
+ assert.equal(beats[0].end, 107);
+ assert.equal(beats[0].anchor.take, "t2");
+ out.length = 0;
+ await run("history");
+ assert.match(out.join("\n"), /beat 1: start, end \(take t2\): 1\.end 109 → 107; 1\.anchor "t1" → "t2"/);
+ assert.equal(await run("clamp", "2", "--take", "t2"), 2);
+ assert.match(err.join("\n"), /only a clipped beat is clamped/);
+ } finally {
+ await rm(r, { recursive: true, force: true });
+ }
+});