commit 52031712c36df4442ab51854b89febbb6c21ed65
parent 8ca9345d5dbb2547e96928a5548c7bbb7c660ca3
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 27 Oct 2026 14:26:38 -0400
umtool manifest writer: patchClipEntry and applyStructural, the clip and structure rules over a manifest in memory
updateClip and the structural writers now run the same checks through two
pure functions (patchClipEntry, applyStructural, with moveIn/removeIn), so a
take's walk can apply a trim, a verdict or a move to the take's timeline with
the very sentences the project's file is checked by. No behaviour change.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
1 file changed, 391 insertions(+), 347 deletions(-)
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -186,361 +186,382 @@ export async function updateClip(dir, clipId, patch, { token = null, edit = "tri
// Re-read INSIDE the lock, every time. Nothing is held across requests.
const raw = await readFile(manifestFile(dir), "utf8");
const manifest = JSON.parse(raw);
- const entry = (manifest.timeline ?? []).find((e) => e.id === clipId);
- if (!entry) throw new Error(`no timeline entry with id ${clipId}`);
- // `!== "clip"`, not `=== "card"`. The timeline's vocabulary is open -- one
- // real manifest carries `scroll` and `chart` entries -- and the card-only
- // check would have let a window be written onto one of those.
- if (entry.type !== "clip") throw new Error(`${clipId} is a ${entry.type ?? "non-clip"} entry, not a clip`);
- // Restore (release 35 C2): the assistant's own edges, read inside the lock.
- if (patch === RESTORE_PATCH) {
- patch = restorePatchOf(entry);
- edit = "restore";
- }
+ const { entry, before } = patchClipEntry(manifest, clipId, patch, { edit, now, raw });
+ const nextToken = await writeManifestAtomic(dir, manifest);
+ return { entry, before, token: nextToken };
+ });
+}
- const before = { start: entry.start, end: entry.end };
- const cutBefore = cutOf(entry);
- for (const k of WINDOW_FIELDS) {
- if (patch[k] === undefined) continue;
- const v = Number(patch[k]);
- if (!Number.isFinite(v) || v < 0) throw new Error(`${k} must be a number ≥ 0`);
- entry[k] = round2(v);
- }
- if (entry.end - entry.start < 0.5) {
- throw new Error(`a clip must be at least half a second (${entry.start}–${entry.end})`);
- }
- for (const k of FLAG_FIELDS) {
- if (patch[k] === undefined) continue;
- // `false` REMOVES the key rather than writing it. The manifests are read
- // by humans, and `"lockEnd": false` is noise that reads like a decision.
- if (patch[k]) entry[k] = true;
- else delete entry[k];
- }
- if (patch.note !== undefined) {
- if (patch.note) entry.note = String(patch.note);
- else delete entry.note;
- }
+/**
+ * updateClip's rules over a manifest held in memory: the ONE place a clip
+ * patch is checked and applied. updateClip runs it on the project's file
+ * inside its lock; a take's walk (takeEdit.mjs) runs it on the take's
+ * timeline, so a trim, a verdict or an attribution edit is checked by the
+ * same sentences whichever file it lands in. Mutates `manifest`.
+ *
+ * @param {Record<string, any>} manifest
+ * @param {string} clipId
+ * @param {Record<string, unknown>} patch
+ * @param {{ edit?: string, now?: string | null, raw?: string | null }} [opts]
+ * `raw`: the manifest's text before the patch, when the caller has it (the
+ * finale check compares against it); else it is taken here.
+ * @returns {{ entry: Record<string, any>, before: { start: number, end: number } }}
+ */
+export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = null, raw = null } = {}) {
+ const original = patch.layout !== undefined ? (raw ?? JSON.stringify(manifest)) : null;
+ const entry = (manifest.timeline ?? []).find((e) => e.id === clipId);
+ if (!entry) throw new Error(`no timeline entry with id ${clipId}`);
+ // `!== "clip"`, not `=== "card"`. The timeline's vocabulary is open -- one
+ // real manifest carries `scroll` and `chart` entries -- and the card-only
+ // check would have let a window be written onto one of those.
+ if (entry.type !== "clip") throw new Error(`${clipId} is a ${entry.type ?? "non-clip"} entry, not a clip`);
+ // Restore (release 35 C2): the assistant's own edges, read inside the lock.
+ if (patch === RESTORE_PATCH) {
+ patch = restorePatchOf(entry);
+ edit = "restore";
+ }
- // ---- what the header will say -------------------------------------------
- //
- // `correction` is the odd one out and belongs here anyway: it is written in
- // the same sitting, by the same person, looking at the same clip. It says
- // what the REPORT got wrong -- wrong speaker, wrong addressee, wrong date --
- // and nothing renders it. It is a message to the next report pass.
- for (const k of ["title", "quote", "correction"]) {
- if (patch[k] === undefined) continue;
- const v = String(patch[k] ?? "").trim();
- if (v) entry[k] = v;
- else delete entry[k];
- }
+ const before = { start: entry.start, end: entry.end };
+ const cutBefore = cutOf(entry);
+ for (const k of WINDOW_FIELDS) {
+ if (patch[k] === undefined) continue;
+ const v = Number(patch[k]);
+ if (!Number.isFinite(v) || v < 0) throw new Error(`${k} must be a number ≥ 0`);
+ entry[k] = round2(v);
+ }
+ if (entry.end - entry.start < 0.5) {
+ throw new Error(`a clip must be at least half a second (${entry.start}–${entry.end})`);
+ }
+ for (const k of FLAG_FIELDS) {
+ if (patch[k] === undefined) continue;
+ // `false` REMOVES the key rather than writing it. The manifests are read
+ // by humans, and `"lockEnd": false` is noise that reads like a decision.
+ if (patch[k]) entry[k] = true;
+ else delete entry[k];
+ }
+ if (patch.note !== undefined) {
+ if (patch.note) entry.note = String(patch.note);
+ else delete entry.note;
+ }
- if (patch.date !== undefined) {
- const v = String(patch.date ?? "").trim();
- if (!v) delete entry.date;
- else if (!isCalendarDate(v)) {
- throw new Error(
- `date must be a real calendar date written YYYY-MM-DD (got \`${v}\`)`,
- );
- } else entry.date = v;
- }
+ // ---- what the header will say -------------------------------------------
+ //
+ // `correction` is the odd one out and belongs here anyway: it is written in
+ // the same sitting, by the same person, looking at the same clip. It says
+ // what the REPORT got wrong -- wrong speaker, wrong addressee, wrong date --
+ // and nothing renders it. It is a message to the next report pass.
+ for (const k of ["title", "quote", "correction"]) {
+ if (patch[k] === undefined) continue;
+ const v = String(patch[k] ?? "").trim();
+ if (v) entry[k] = v;
+ else delete entry[k];
+ }
- if (patch.cite !== undefined) {
- // null or empty means "no cite", and the header then falls back to the
- // clip's own start -- which is what `entry.cite ?? entry.start` has always
- // done. Rounded like a window, for the same reason.
- if (patch.cite === null || patch.cite === "") delete entry.cite;
- else {
- const v = Number(patch.cite);
- if (!Number.isFinite(v) || v < 0) {
- throw new Error("cite must be a number of seconds ≥ 0, or empty to use the clip's start");
- }
- entry.cite = round2(v);
- }
- }
+ if (patch.date !== undefined) {
+ const v = String(patch.date ?? "").trim();
+ if (!v) delete entry.date;
+ else if (!isCalendarDate(v)) {
+ throw new Error(
+ `date must be a real calendar date written YYYY-MM-DD (got \`${v}\`)`,
+ );
+ } else entry.date = v;
+ }
- if (patch.citeUrl !== undefined) {
- const v = String(patch.citeUrl ?? "").trim();
- if (!v) delete entry.citeUrl;
- else {
- // The QR target. A value that is not an http(s) URL encodes to something
- // a phone camera opens and nothing answers -- the same class of defect
- // as the 19 codes that shipped reading `undefined/?v=…`.
- let u = null;
- try {
- u = new URL(v);
- } catch {
- /* handled below */
- }
- if (!u || (u.protocol !== "http:" && u.protocol !== "https:")) {
- throw new Error(`citeUrl must be an http:// or https:// URL (got \`${v}\`)`);
- }
- entry.citeUrl = v;
+ if (patch.cite !== undefined) {
+ // null or empty means "no cite", and the header then falls back to the
+ // clip's own start -- which is what `entry.cite ?? entry.start` has always
+ // done. Rounded like a window, for the same reason.
+ if (patch.cite === null || patch.cite === "") delete entry.cite;
+ else {
+ const v = Number(patch.cite);
+ if (!Number.isFinite(v) || v < 0) {
+ throw new Error("cite must be a number of seconds ≥ 0, or empty to use the clip's start");
}
+ entry.cite = round2(v);
}
+ }
- // ---- the CUT, inside the extent ------------------------------------------
- //
- // `start`/`end` is the reviewed EXTENT -- how much of this recording is
- // worth having -- and `cutStart`/`cutEnd` is the tight cut the video
- // renders, derived from where the quote actually is. Two numbers, one
- // rule: a cut that is not inside its extent is not a cut, it is a second
- // window nobody reviewed.
- //
- // Both or neither. A lone `cutStart` reads like a decision and builds like
- // nothing, because the build only honours the pair.
- for (const k of ["cutStart", "cutEnd"]) {
- if (patch[k] === undefined) continue;
- const raw = patch[k];
- if (raw === null || raw === "") {
- delete entry[k];
- continue;
- }
- const v = Number(raw);
- if (!Number.isFinite(v) || v < 0) throw new Error(`${k} must be a number ≥ 0, or empty`);
- entry[k] = round2(v);
- }
- if (patch.cutStart !== undefined || patch.cutEnd !== undefined || patch.start !== undefined || patch.end !== undefined) {
- const hasStart = entry.cutStart != null;
- const hasEnd = entry.cutEnd != null;
- if (hasStart !== hasEnd) {
- throw new Error("a cut needs both cutStart and cutEnd, or neither");
+ if (patch.citeUrl !== undefined) {
+ const v = String(patch.citeUrl ?? "").trim();
+ if (!v) delete entry.citeUrl;
+ else {
+ // The QR target. A value that is not an http(s) URL encodes to something
+ // a phone camera opens and nothing answers -- the same class of defect
+ // as the 19 codes that shipped reading `undefined/?v=…`.
+ let u = null;
+ try {
+ u = new URL(v);
+ } catch {
+ /* handled below */
}
- if (hasStart) {
- if (entry.cutEnd - entry.cutStart < 0.5) {
- throw new Error(`a cut must be at least half a second (${entry.cutStart}–${entry.cutEnd})`);
- }
- if (
- entry.cutStart < entry.start - WIN_EPS ||
- entry.cutEnd > entry.end + WIN_EPS
- ) {
- throw new Error(
- `the cut ${entry.cutStart}–${entry.cutEnd} must lie inside the window ` +
- `${entry.start}–${entry.end} — widen the window, or clear the cut`,
- );
- }
+ if (!u || (u.protocol !== "http:" && u.protocol !== "https:")) {
+ throw new Error(`citeUrl must be an http:// or https:// URL (got \`${v}\`)`);
}
+ entry.citeUrl = v;
}
+ }
- // ---- the mute mark ------------------------------------------------------
- //
- // `muteFrom`: from this source second to the end of the clip the sound
- // fades out and the picture plays on -- set by ear, in the bench, at the
- // last silence before a finale's ending sound. Inside the EXTENT, like the
- // cut, and checked against the entry AFTER the patch: a window save that
- // leaves the mark outside is refused rather than keeping a mark that no
- // longer says anything about the clip. Empty or null deletes it.
- if (patch.muteFrom !== undefined) {
- const v = parseMuteFrom(patch.muteFrom, entry.start, entry.end);
- if (v == null) delete entry.muteFrom;
- else entry.muteFrom = v;
- } else if ((patch.start !== undefined || patch.end !== undefined) && entry.muteFrom != null) {
- // Clamped and STORED, as a patched mark is: a mark within the writer's
- // 0.02 s of the moved edge lands on it (past the new start it still
- // mutes the whole clip), and the build (validateMuteFrom, strict)
- // accepts every manifest saved here. Left as it was, a start moved from 10.00 to 10.01 under a mark at
- // 10.00 saved, and the next build refused the whole manifest.
- try {
- entry.muteFrom = parseMuteFrom(entry.muteFrom, entry.start, entry.end);
- } catch {
+ // ---- the CUT, inside the extent ------------------------------------------
+ //
+ // `start`/`end` is the reviewed EXTENT -- how much of this recording is
+ // worth having -- and `cutStart`/`cutEnd` is the tight cut the video
+ // renders, derived from where the quote actually is. Two numbers, one
+ // rule: a cut that is not inside its extent is not a cut, it is a second
+ // window nobody reviewed.
+ //
+ // Both or neither. A lone `cutStart` reads like a decision and builds like
+ // nothing, because the build only honours the pair.
+ for (const k of ["cutStart", "cutEnd"]) {
+ if (patch[k] === undefined) continue;
+ const raw = patch[k];
+ if (raw === null || raw === "") {
+ delete entry[k];
+ continue;
+ }
+ const v = Number(raw);
+ if (!Number.isFinite(v) || v < 0) throw new Error(`${k} must be a number ≥ 0, or empty`);
+ entry[k] = round2(v);
+ }
+ if (patch.cutStart !== undefined || patch.cutEnd !== undefined || patch.start !== undefined || patch.end !== undefined) {
+ const hasStart = entry.cutStart != null;
+ const hasEnd = entry.cutEnd != null;
+ if (hasStart !== hasEnd) {
+ throw new Error("a cut needs both cutStart and cutEnd, or neither");
+ }
+ if (hasStart) {
+ if (entry.cutEnd - entry.cutStart < 0.5) {
+ throw new Error(`a cut must be at least half a second (${entry.cutStart}–${entry.cutEnd})`);
+ }
+ if (
+ entry.cutStart < entry.start - WIN_EPS ||
+ entry.cutEnd > entry.end + WIN_EPS
+ ) {
throw new Error(
- `the mute mark ${entry.muteFrom} must lie inside the window ` +
- `${entry.start}–${entry.end} — widen the window, or clear the mark`,
+ `the cut ${entry.cutStart}–${entry.cutEnd} must lie inside the window ` +
+ `${entry.start}–${entry.end} — widen the window, or clear the cut`,
);
}
}
+ }
- // ---- a claim's `at` stays inside the window (video knobs) ---------------
- //
- // The source second its stamp lands, on the entry's clock: a window save
- // that leaves it outside is refused, as the mute mark's is, rather than
- // keeping a mark that no longer says anything about the clip.
- if (patch.start !== undefined || patch.end !== undefined) {
- const many = Array.isArray(entry.claims);
- rawMarksOf(entry).forEach((m, k) => {
- if (!isObj(m) || typeof m.at !== "number" || (m.at >= entry.start && m.at <= entry.end)) return;
- const name = many ? `the mark ${m.id}'s second (claims[${k}].at ${m.at})` : `the stamp's second (claim.at ${m.at})`;
- throw new Error(
- `${name} must lie inside the window ` +
- `${entry.start}–${entry.end} — widen the window, or clear ${many ? "that mark's at" : "claim.at"}`,
- );
- });
+ // ---- the mute mark ------------------------------------------------------
+ //
+ // `muteFrom`: from this source second to the end of the clip the sound
+ // fades out and the picture plays on -- set by ear, in the bench, at the
+ // last silence before a finale's ending sound. Inside the EXTENT, like the
+ // cut, and checked against the entry AFTER the patch: a window save that
+ // leaves the mark outside is refused rather than keeping a mark that no
+ // longer says anything about the clip. Empty or null deletes it.
+ if (patch.muteFrom !== undefined) {
+ const v = parseMuteFrom(patch.muteFrom, entry.start, entry.end);
+ if (v == null) delete entry.muteFrom;
+ else entry.muteFrom = v;
+ } else if ((patch.start !== undefined || patch.end !== undefined) && entry.muteFrom != null) {
+ // Clamped and STORED, as a patched mark is: a mark within the writer's
+ // 0.02 s of the moved edge lands on it (past the new start it still
+ // mutes the whole clip), and the build (validateMuteFrom, strict)
+ // accepts every manifest saved here. Left as it was, a start moved from 10.00 to 10.01 under a mark at
+ // 10.00 saved, and the next build refused the whole manifest.
+ try {
+ entry.muteFrom = parseMuteFrom(entry.muteFrom, entry.start, entry.end);
+ } catch {
+ throw new Error(
+ `the mute mark ${entry.muteFrom} must lie inside the window ` +
+ `${entry.start}–${entry.end} — widen the window, or clear the mark`,
+ );
}
+ }
- // ---- the clip's sound (video knobs) -------------------------------------
- //
- // `audio: { offset, gain, fadeIn, fadeOut }` -- applied at the segment
- // encode (report-to-video clip-audio.mjs, whose validateClipAudio is the
- // check). Each key is merged into what the clip has; a key set to null
- // removes it, and `audio: null` (or "") removes them all. A key at 0 is
- // removed (0 is what absent says), and nothing left removes `audio`:
- // absent is the build as it always was.
- if (patch.audio !== undefined) {
- const v = patch.audio;
- if (v === null || v === "") delete entry.audio;
- else {
- if (!isObj(v)) throw new Error("audio must be { offset?, gain?, fadeIn?, fadeOut? }, or null to clear it");
- const next = { ...(isObj(entry.audio) ? entry.audio : {}) };
- for (const [k, x] of Object.entries(v)) {
- if (x === null || x === "") delete next[k];
- else next[k] = typeof x === "string" ? Number(x) : x;
- }
- const errors = validateClipAudio(next);
- if (errors.length) throw new Error(errors.join("; "));
- if (typeof next.offset === "number") next.offset = Math.round(next.offset);
- if (typeof next.gain === "number") next.gain = Number(next.gain.toFixed(1));
- for (const k of ["fadeIn", "fadeOut"]) if (typeof next[k] === "number") next[k] = round2(next[k]);
- for (const k of Object.keys(next)) if (next[k] === 0) delete next[k];
- if (Object.keys(next).length) entry.audio = next;
- else delete entry.audio;
+ // ---- a claim's `at` stays inside the window (video knobs) ---------------
+ //
+ // The source second its stamp lands, on the entry's clock: a window save
+ // that leaves it outside is refused, as the mute mark's is, rather than
+ // keeping a mark that no longer says anything about the clip.
+ if (patch.start !== undefined || patch.end !== undefined) {
+ const many = Array.isArray(entry.claims);
+ rawMarksOf(entry).forEach((m, k) => {
+ if (!isObj(m) || typeof m.at !== "number" || (m.at >= entry.start && m.at <= entry.end)) return;
+ const name = many ? `the mark ${m.id}'s second (claims[${k}].at ${m.at})` : `the stamp's second (claim.at ${m.at})`;
+ throw new Error(
+ `${name} must lie inside the window ` +
+ `${entry.start}–${entry.end} — widen the window, or clear ${many ? "that mark's at" : "claim.at"}`,
+ );
+ });
+ }
+
+ // ---- the clip's sound (video knobs) -------------------------------------
+ //
+ // `audio: { offset, gain, fadeIn, fadeOut }` -- applied at the segment
+ // encode (report-to-video clip-audio.mjs, whose validateClipAudio is the
+ // check). Each key is merged into what the clip has; a key set to null
+ // removes it, and `audio: null` (or "") removes them all. A key at 0 is
+ // removed (0 is what absent says), and nothing left removes `audio`:
+ // absent is the build as it always was.
+ if (patch.audio !== undefined) {
+ const v = patch.audio;
+ if (v === null || v === "") delete entry.audio;
+ else {
+ if (!isObj(v)) throw new Error("audio must be { offset?, gain?, fadeIn?, fadeOut? }, or null to clear it");
+ const next = { ...(isObj(entry.audio) ? entry.audio : {}) };
+ for (const [k, x] of Object.entries(v)) {
+ if (x === null || x === "") delete next[k];
+ else next[k] = typeof x === "string" ? Number(x) : x;
}
+ const errors = validateClipAudio(next);
+ if (errors.length) throw new Error(errors.join("; "));
+ if (typeof next.offset === "number") next.offset = Math.round(next.offset);
+ if (typeof next.gain === "number") next.gain = Number(next.gain.toFixed(1));
+ for (const k of ["fadeIn", "fadeOut"]) if (typeof next[k] === "number") next[k] = round2(next[k]);
+ for (const k of Object.keys(next)) if (next[k] === 0) delete next[k];
+ if (Object.keys(next).length) entry.audio = next;
+ else delete entry.audio;
}
+ }
- // ---- the clip's picture, blurred (video knobs) ---------------------------
- //
- // `blur: { on: true, caption?, strength?, from?, to? }` -- applied at the
- // segment encode (report-to-video clip-blur.mjs, whose validateClipBlur is
- // the check, against the window as patched). Merged into what the clip
- // has, as `audio` is: a key set to null removes it; `blur: null` (or "",
- // or `on` null/false) removes it all. A caption or strength at its default
- // is removed (absent says it), and so are a caption's outer spaces.
- if (patch.blur !== undefined) {
- const v = patch.blur;
- if (v === null || v === "" || (isObj(v) && (v.on === null || v.on === false || v.on === ""))) delete entry.blur;
- else {
- if (!isObj(v)) throw new Error("blur must be { on: true, caption?, strength?, from?, to? }, or null to clear it");
- const next = { ...(isObj(entry.blur) ? entry.blur : {}) };
- for (const [k, x] of Object.entries(v)) {
- if (x === null || x === "") delete next[k];
- else if (k === "on" && x === "true") next.on = true;
- else if (["strength", "from", "to"].includes(k) && typeof x === "string") next[k] = Number(x);
- else next[k] = x;
- }
- if (typeof next.caption === "string") next.caption = next.caption.trim();
- if (next.caption === BLUR_CAPTION_DEFAULT || next.caption === "") delete next.caption;
- if (typeof next.strength === "number") next.strength = Number(next.strength.toFixed(1));
- if (next.strength === BLUR_STRENGTH.default) delete next.strength;
- for (const k of ["from", "to"]) if (typeof next[k] === "number" && Number.isFinite(next[k])) next[k] = round2(next[k]);
- const errors = validateClipBlur(next, "blur", entry);
- if (errors.length) throw new Error(errors.join("; "));
- // `on` first: the manifests are read by humans.
- const { on, ...rest } = next;
- entry.blur = { on, ...rest };
+ // ---- the clip's picture, blurred (video knobs) ---------------------------
+ //
+ // `blur: { on: true, caption?, strength?, from?, to? }` -- applied at the
+ // segment encode (report-to-video clip-blur.mjs, whose validateClipBlur is
+ // the check, against the window as patched). Merged into what the clip
+ // has, as `audio` is: a key set to null removes it; `blur: null` (or "",
+ // or `on` null/false) removes it all. A caption or strength at its default
+ // is removed (absent says it), and so are a caption's outer spaces.
+ if (patch.blur !== undefined) {
+ const v = patch.blur;
+ if (v === null || v === "" || (isObj(v) && (v.on === null || v.on === false || v.on === ""))) delete entry.blur;
+ else {
+ if (!isObj(v)) throw new Error("blur must be { on: true, caption?, strength?, from?, to? }, or null to clear it");
+ const next = { ...(isObj(entry.blur) ? entry.blur : {}) };
+ for (const [k, x] of Object.entries(v)) {
+ if (x === null || x === "") delete next[k];
+ else if (k === "on" && x === "true") next.on = true;
+ else if (["strength", "from", "to"].includes(k) && typeof x === "string") next[k] = Number(x);
+ else next[k] = x;
}
- } else if ((patch.start !== undefined || patch.end !== undefined) && isObj(entry.blur)) {
- // A window save that leaves a partial blur's span outside is refused, as
- // a claim's `at` is: the span no longer says anything about the clip.
- const errors = validateClipBlur(entry.blur, "blur", entry);
+ if (typeof next.caption === "string") next.caption = next.caption.trim();
+ if (next.caption === BLUR_CAPTION_DEFAULT || next.caption === "") delete next.caption;
+ if (typeof next.strength === "number") next.strength = Number(next.strength.toFixed(1));
+ if (next.strength === BLUR_STRENGTH.default) delete next.strength;
+ for (const k of ["from", "to"]) if (typeof next[k] === "number" && Number.isFinite(next[k])) next[k] = round2(next[k]);
+ const errors = validateClipBlur(next, "blur", entry);
if (errors.length) throw new Error(errors.join("; "));
+ // `on` first: the manifests are read by humans.
+ const { on, ...rest } = next;
+ entry.blur = { on, ...rest };
}
+ } else if ((patch.start !== undefined || patch.end !== undefined) && isObj(entry.blur)) {
+ // A window save that leaves a partial blur's span outside is refused, as
+ // a claim's `at` is: the span no longer says anything about the clip.
+ const errors = validateClipBlur(entry.blur, "blur", entry);
+ if (errors.length) throw new Error(errors.join("; "));
+ }
- // ---- how the deck lays this entry out -----------------------------------
- //
- // `layout: "finale"` (the deck's finale layout, render.chrome.deck.finale);
- // "clip" -- the default -- or null/"" removes the key. Only these two: a
- // layout the deck does not draw is refused here, not at the build.
- if (patch.layout !== undefined) {
- const v = patch.layout;
- if (v === null || v === "" || v === "clip") delete entry.layout;
- else if (v === "finale") entry.layout = "finale";
- else throw new Error(`layout must be "finale" or "clip" (the default), not ${JSON.stringify(v)}`);
- // The finale's run (finale.mjs): a write may not break it -- refused
- // when it adds a problem the file did not have. Mark from the last
- // clip back, unmark from the first on.
- const was = new Set(validateFinaleEntries(JSON.parse(raw)));
- const bad = validateFinaleEntries(manifest).filter((e) => !was.has(e));
- if (bad.length) throw new Error(`layout: ${bad.join("; ")}`);
- }
+ // ---- how the deck lays this entry out -----------------------------------
+ //
+ // `layout: "finale"` (the deck's finale layout, render.chrome.deck.finale);
+ // "clip" -- the default -- or null/"" removes the key. Only these two: a
+ // layout the deck does not draw is refused here, not at the build.
+ if (patch.layout !== undefined) {
+ const v = patch.layout;
+ if (v === null || v === "" || v === "clip") delete entry.layout;
+ else if (v === "finale") entry.layout = "finale";
+ else throw new Error(`layout must be "finale" or "clip" (the default), not ${JSON.stringify(v)}`);
+ // The finale's run (finale.mjs): a write may not break it -- refused
+ // when it adds a problem the file did not have. Mark from the last
+ // clip back, unmark from the first on.
+ const was = new Set(validateFinaleEntries(JSON.parse(/** @type {string} */ (original))));
+ const bad = validateFinaleEntries(manifest).filter((e) => !was.has(e));
+ if (bad.length) throw new Error(`layout: ${bad.join("; ")}`);
+ }
- // ---- the walk's verdict -------------------------------------------------
- //
- // Whether somebody has LOOKED at this clip and said the description is what
- // the clip actually is. Three states, and an absent key is the honest way
- // to say "nobody has been here":
- //
- // verdict: "confirmed" -> the description is accurate
- // verdict: "incorrect" -> it is not, and `correction` says how
- // neither -> not yet reviewed
- //
- // `correction` is OPTIONAL under a confirmed verdict and REQUIRED under an
- // incorrect one. The two are not the same sentence: a note on a good clip
- // is why its window moved or a caveat for the writers, while an incorrect
- // clip with no note is a complaint nobody can act on. So the rule is a
- // property of the ENTRY AFTER the patch, which makes both halves of it one
- // check -- setting `incorrect` with no note, and clearing the note off a
- // clip that is already `incorrect`, are the same error.
- //
- // LEGACY, and deliberately not migrated: a clip carrying a `correction` and
- // no `verdict` predates `incorrect` and READS as incorrect (clipVerdict()).
- // The requirement above is keyed on the explicit value, so those entries can
- // still be cleared -- a rule that refused to let somebody undo a note they
- // wrote before the rule existed would be a trap.
- if (patch.verdict !== undefined) {
- const v = String(patch.verdict ?? "").trim();
- if (!v) delete entry.verdict;
- else if (v !== "confirmed" && v !== "incorrect") {
- throw new Error(
- `verdict must be "confirmed" or "incorrect", or empty to clear it (got \`${v}\`)`,
- );
- } else entry.verdict = v;
- }
+ // ---- the walk's verdict -------------------------------------------------
+ //
+ // Whether somebody has LOOKED at this clip and said the description is what
+ // the clip actually is. Three states, and an absent key is the honest way
+ // to say "nobody has been here":
+ //
+ // verdict: "confirmed" -> the description is accurate
+ // verdict: "incorrect" -> it is not, and `correction` says how
+ // neither -> not yet reviewed
+ //
+ // `correction` is OPTIONAL under a confirmed verdict and REQUIRED under an
+ // incorrect one. The two are not the same sentence: a note on a good clip
+ // is why its window moved or a caveat for the writers, while an incorrect
+ // clip with no note is a complaint nobody can act on. So the rule is a
+ // property of the ENTRY AFTER the patch, which makes both halves of it one
+ // check -- setting `incorrect` with no note, and clearing the note off a
+ // clip that is already `incorrect`, are the same error.
+ //
+ // LEGACY, and deliberately not migrated: a clip carrying a `correction` and
+ // no `verdict` predates `incorrect` and READS as incorrect (clipVerdict()).
+ // The requirement above is keyed on the explicit value, so those entries can
+ // still be cleared -- a rule that refused to let somebody undo a note they
+ // wrote before the rule existed would be a trap.
+ if (patch.verdict !== undefined) {
+ const v = String(patch.verdict ?? "").trim();
+ if (!v) delete entry.verdict;
+ else if (v !== "confirmed" && v !== "incorrect") {
+ throw new Error(
+ `verdict must be "confirmed" or "incorrect", or empty to clear it (got \`${v}\`)`,
+ );
+ } else entry.verdict = v;
+ }
- if (entry.verdict === "incorrect" && !String(entry.correction ?? "").trim()) {
- throw new Error("an incorrect verdict needs its note: say what the report got wrong");
- }
+ if (entry.verdict === "incorrect" && !String(entry.correction ?? "").trim()) {
+ throw new Error("an incorrect verdict needs its note: say what the report got wrong");
+ }
- // ---- what the deck will say ---------------------------------------------
- //
- // The bench's On-screen fields, written in the same sitting as the header
- // fields above. setOnscreen is updateOnscreen's rule, so a clip edited here
- // and a row saved from the On-screen table cannot store different shapes.
- if (patch.onscreen !== undefined) setOnscreen(entry, patch.onscreen);
-
- // ---- the vertical short's framing (release 36 lane C) --------------------
- //
- // `vertical: {crop: [x, y, w, h], aspect?}` -- fractions of the source
- // picture, 9:16 on it (look.mjs verticalErrors, the build's own check).
- // null or "" removes it: the short is cut from the centre again.
- if (patch.vertical !== undefined) {
- const v = patch.vertical;
- if (v === null || v === "") delete entry.vertical;
- else {
- const errors = verticalErrors(v, "vertical");
- if (errors.length) throw new Error(errors.join("; "));
- const r4 = (n) => Number(Number(n).toFixed(4));
- const vv = /** @type {{ crop: number[], aspect?: number }} */ (v);
- entry.vertical = { crop: vv.crop.map(r4), ...(vv.aspect !== undefined ? { aspect: r4(vv.aspect) } : {}) };
- }
+ // ---- what the deck will say ---------------------------------------------
+ //
+ // The bench's On-screen fields, written in the same sitting as the header
+ // fields above. setOnscreen is updateOnscreen's rule, so a clip edited here
+ // and a row saved from the On-screen table cannot store different shapes.
+ if (patch.onscreen !== undefined) setOnscreen(entry, patch.onscreen);
+
+ // ---- the vertical short's framing (release 36 lane C) --------------------
+ //
+ // `vertical: {crop: [x, y, w, h], aspect?}` -- fractions of the source
+ // picture, 9:16 on it (look.mjs verticalErrors, the build's own check).
+ // null or "" removes it: the short is cut from the centre again.
+ if (patch.vertical !== undefined) {
+ const v = patch.vertical;
+ if (v === null || v === "") delete entry.vertical;
+ else {
+ const errors = verticalErrors(v, "vertical");
+ if (errors.length) throw new Error(errors.join("; "));
+ const r4 = (n) => Number(Number(n).toFixed(4));
+ const vv = /** @type {{ crop: number[], aspect?: number }} */ (v);
+ entry.vertical = { crop: vv.crop.map(r4), ...(vv.aspect !== undefined ? { aspect: r4(vv.aspect) } : {}) };
}
+ }
- // ---- room at the clip's edges (release 36 lane E) ------------------------
- //
- // `room: false` (none for this clip) or `{tail?, head?}` (that edge, whatever
- // the cut's render.room says) -- room.mjs validateRoom, the build's own
- // check. null or "" removes it: the cut's room again.
- if (patch.room !== undefined) {
- const v = patch.room;
- if (v === null || v === "") delete entry.room;
- else {
- const errors = validateRoom({ timeline: [{ ...entry, room: v }] });
- if (errors.length) throw new Error(errors.join("; "));
- const vv = /** @type {false | { tail?: boolean, head?: boolean }} */ (v);
- entry.room = vv === false ? false : { ...(typeof vv.tail === "boolean" ? { tail: vv.tail } : {}), ...(typeof vv.head === "boolean" ? { head: vv.head } : {}) };
- }
+ // ---- room at the clip's edges (release 36 lane E) ------------------------
+ //
+ // `room: false` (none for this clip) or `{tail?, head?}` (that edge, whatever
+ // the cut's render.room says) -- room.mjs validateRoom, the build's own
+ // check. null or "" removes it: the cut's room again.
+ if (patch.room !== undefined) {
+ const v = patch.room;
+ if (v === null || v === "") delete entry.room;
+ else {
+ const errors = validateRoom({ timeline: [{ ...entry, room: v }] });
+ if (errors.length) throw new Error(errors.join("; "));
+ const vv = /** @type {false | { tail?: boolean, head?: boolean }} */ (v);
+ entry.room = vv === false ? false : { ...(typeof vv.tail === "boolean" ? { tail: vv.tail } : {}), ...(typeof vv.head === "boolean" ? { head: vv.head } : {}) };
}
+ }
- // ---- an assistant's clip, edited by a person (release 35 C2) -------------
- //
- // A clip the clip finder proposed carries `assist`. The first human edit
- // of its cut flips `assist.by` to "operator" (a re-propose never touches
- // it again) and every edit is appended to `assist.edits`. Restore puts the
- // assistant's `original` back, and the clip is the assistant's again.
- const at = now ?? new Date().toISOString();
- noteAssistEdit(entry, edit, cutBefore, at);
- if (edit === "restore" && isObj(entry.assist) && entry.assist.proposal) entry.assist.by = "assistant";
-
- const nextToken = await writeManifestAtomic(dir, manifest);
- return { entry, before, token: nextToken };
- });
+ // ---- an assistant's clip, edited by a person (release 35 C2) -------------
+ //
+ // A clip the clip finder proposed carries `assist`. The first human edit
+ // of its cut flips `assist.by` to "operator" (a re-propose never touches
+ // it again) and every edit is appended to `assist.edits`. Restore puts the
+ // assistant's `original` back, and the clip is the assistant's again.
+ const at = now ?? new Date().toISOString();
+ noteAssistEdit(entry, edit, cutBefore, at);
+ if (edit === "restore" && isObj(entry.assist) && entry.assist.proposal) entry.assist.by = "assistant";
+
+ return { entry, before };
}
// ---------------------------------------------------------------------------
@@ -1440,6 +1461,51 @@ export class StructureRefused extends Error {
}
/**
+ * A structural edit over a manifest held in memory: `mutate` (which throws to
+ * refuse), then the build's checks -- refused only for what THIS edit breaks --
+ * then `sectionEnter` recomputed. Mutates `manifest`; returns mutate's result.
+ * The project's writers run it inside the lock (structural, below); a take's
+ * walk runs it on the take's timeline (takeEdit.mjs).
+ *
+ * @template T
+ * @param {Record<string, any>} manifest
+ * @param {(m: Record<string, any>) => T} mutate
+ * @returns {T}
+ */
+export function applyStructural(manifest, mutate) {
+ if (!Array.isArray(manifest.timeline)) manifest.timeline = [];
+ // Only what THIS edit breaks refuses it: a manifest that already carries a
+ // problem the build would name (somebody's hand edit) can still be
+ // re-ordered, and the problem is still the build's to report.
+ const already = new Set(structureErrors(manifest));
+ const result = mutate(manifest);
+ const errors = structureErrors(manifest).filter((e) => !already.has(e));
+ if (errors.length) throw new StructureRefused(errors);
+ applySectionEnter(manifest.timeline);
+ return result;
+}
+
+/** Move entry `id` to `toIndex` in `m.timeline` (moveEntry's rule, in memory). */
+export function moveIn(m, id, toIndex, at = null) {
+ const from = entryIndex(m.timeline, id, at);
+ const to = Number(toIndex);
+ if (!Number.isInteger(to) || to < 0 || to >= m.timeline.length) {
+ throw new Error(`toIndex must be 0–${m.timeline.length - 1}`);
+ }
+ if (to === from) throw new Error(`${id} is already at ${to}`);
+ const [e] = m.timeline.splice(from, 1);
+ m.timeline.splice(to, 0, e);
+ return { id, from, to };
+}
+
+/** Remove entry `id` from `m.timeline` (removeEntry's rule, in memory). */
+export function removeIn(m, id, at = null) {
+ const i = entryIndex(m.timeline, id, at);
+ const [removed] = m.timeline.splice(i, 1);
+ return { id, at: i, removed };
+}
+
+/**
* One structural write: token, read, `mutate` (which throws to refuse), the
* build's checks, the auto snapshot of the file as it still is, then the write.
*/
@@ -1448,15 +1514,7 @@ async function structural(dir, op, token, mutate) {
const current = await manifestToken(dir);
if (token !== null && current !== token) throw new StaleToken(token, current);
const manifest = JSON.parse(await readFile(manifestFile(dir), "utf8"));
- if (!Array.isArray(manifest.timeline)) manifest.timeline = [];
- // Only what THIS edit breaks refuses it: a manifest that already carries a
- // problem the build would name (somebody's hand edit) can still be
- // re-ordered, and the problem is still the build's to report.
- const already = new Set(structureErrors(manifest));
- const result = mutate(manifest);
- const errors = structureErrors(manifest).filter((e) => !already.has(e));
- if (errors.length) throw new StructureRefused(errors);
- applySectionEnter(manifest.timeline);
+ const result = applyStructural(manifest, mutate);
const snapshot = await autoSnapshot(dir, op);
const nextToken = await writeManifestAtomic(dir, manifest);
return { ...result, snapshot, token: nextToken };
@@ -1474,17 +1532,7 @@ async function structural(dir, op, token, mutate) {
* @param {{ token?: string | null, at?: number | null }} [opts]
*/
export async function moveEntry(dir, id, toIndex, { token = null, at = null } = {}) {
- return structural(dir, "move", token, (m) => {
- const from = entryIndex(m.timeline, id, at);
- const to = Number(toIndex);
- if (!Number.isInteger(to) || to < 0 || to >= m.timeline.length) {
- throw new Error(`toIndex must be 0–${m.timeline.length - 1}`);
- }
- if (to === from) throw new Error(`${id} is already at ${to}`);
- const [e] = m.timeline.splice(from, 1);
- m.timeline.splice(to, 0, e);
- return { id, from, to };
- });
+ return structural(dir, "move", token, (m) => moveIn(m, id, toIndex, at));
}
/**
@@ -1496,11 +1544,7 @@ export async function moveEntry(dir, id, toIndex, { token = null, at = null } =
* @param {{ token?: string | null, at?: number | null }} [opts]
*/
export async function removeEntry(dir, id, { token = null, at = null } = {}) {
- return structural(dir, "remove", token, (m) => {
- const i = entryIndex(m.timeline, id, at);
- const [removed] = m.timeline.splice(i, 1);
- return { id, at: i, removed };
- });
+ return structural(dir, "remove", token, (m) => removeIn(m, id, at));
}
/** Copy one entry to just after itself, under a fresh id. A copied claim is dropped (one claim, one entry). *