commit 3b969412f00f60a88db950eabfd7322a728ee8eb
parent 6f46372016505887cbc4ab0902c6def11701fac0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Fri, 23 Oct 2026 01:34:08 -0400
umtool: the marks' writers -- updateMarks, op "marks", umtool set mark.add/remove/verdict, marks=
updateMarks adds (a new id: the clip's, else <clip>.2 …; a verdict by name or
this cut's label), removes, re-verdicts (every clip carrying the id) or sets a
clip's marks; one mark is written `claim`, in its place among the keys, so a
mark added and removed leaves the file the bytes it was. updateClaimKnobs takes
`mark`; the window rule covers every mark; the On-screen table edits the first.
The clip editor's view lists each clip's marks with where each stamps, and the
verdicts with this cut's words. `umtool show` prints the marks.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
10 files changed, 652 insertions(+), 50 deletions(-)
diff --git a/umtool/app/api/report/onscreen/route.ts b/umtool/app/api/report/onscreen/route.ts
@@ -21,7 +21,7 @@ export const dynamic = "force-dynamic";
// reads as saved.
type Claim = { id: string; verdict: string };
-type Entry = Record<string, unknown> & { id: string; type?: string; onscreen?: Record<string, string>; claim?: Claim };
+type Entry = Record<string, unknown> & { id: string; type?: string; onscreen?: Record<string, string>; claim?: Claim; claims?: Claim[] };
const noStore = { "cache-control": "no-store" };
@@ -56,7 +56,9 @@ export async function GET(request: Request) {
id: e.id,
type: e.type ?? "entry",
onscreen: onscreen ?? null,
- claim: e.claim ?? null,
+ // An entry with marks (`claims`) shows its first here; the clip editor's Marks box edits them all.
+ claim: e.claim ?? (Array.isArray(e.claims) ? (e.claims[0] ?? null) : null),
+ ...(Array.isArray(e.claims) ? { marks: e.claims.length } : {}),
auto: deckText(bare, metas[i] ?? null, provenance, deck, multi),
};
});
diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs
@@ -24,6 +24,7 @@
// [--correction TEXT] [--verdict confirmed|incorrect|'']
// [--cut-start S] [--cut-end E] [--lock-cut] the cut inside the extent
// umtool set <project> <clip> key=value … a clip's knobs: claim.at|hold|stamp|count|label,
+// marks=<json> mark.add=<verdict>[@<sec>] mark.remove=<id> mark.verdict=<v> [--mark <id>],
// audio.offset|gain|fadeIn|fadeOut (`key=` clears) (docs/knobs.md)
// umtool look <project> key=value … the cut's knobs: factcheck.stamp.*, factcheck.verdicts.<V>.*,
// deck.markers=<json>, deck.markerLayout, variants=<json>, the look's keys
@@ -710,7 +711,9 @@ function usage() {
" an empty value (--title '') deletes the field",
" umtool set <project> <clip> key=value … a clip's knobs (`key=` clears; umtool/docs/knobs.md):",
" claim.at (a source second: the stamp lands, the count steps) claim.hold claim.stamp",
- " claim.count claim.label · audio.offset (ms, + later) audio.gain (dB) audio.fadeIn audio.fadeOut",
+ " claim.count claim.label (the first mark's, or --mark <id>'s) · marks: mark.add=<verdict>[@<sec>]",
+ " mark.remove=<id> mark.verdict=<verdict> marks=<json> (≤ 8, each its own stamp and count)",
+ " · audio.offset (ms, + later) audio.gain (dB) audio.fadeIn audio.fadeOut",
" umtool look <project> key=value … the cut's knobs: factcheck.stamp.scale|motion|opacity|seconds,",
" factcheck.verdicts.<V>.stampLabel|label|color, deck.markers=<json>, deck.markerLayout,",
" variants=<json>, and the look's keys (transition=0.3, …)",
diff --git a/umtool/lib/report/clipEditor.mjs b/umtool/lib/report/clipEditor.mjs
@@ -36,9 +36,10 @@ import {
restoreClip,
splitClip,
updateClaimKnobs,
+ updateMarks,
updateClip,
} from "./manifest.mjs";
-import { CLAIM_KNOB_DEFAULTS, stampingEntryId } from "./knobs.mjs";
+import { CLAIM_KNOB_DEFAULTS, markVerdictsOf, rawMarksOf, stampingEntryId } from "./knobs.mjs";
import { resolveFactcheck } from "umtool-report-to-video/factcheck";
import { momentKeysOf, readRulingsState, setMontageRuling } from "./montageRulings.mjs";
import { readReactions, reproposeAvailable, REPROPOSE_UNAVAILABLE, setSpeakerLabel, setSpeakerRole, SPEAKER_ROLES } from "./clipEditorBridge.mjs";
@@ -125,8 +126,9 @@ export async function clipEditorView(project) {
roomEdges: roomEdgesOf(e, manifest.render),
// The video knobs: the claim as written (its id, verdict and knobs),
// the entry that stamps it (the last carrying its id), and the sound.
- claim: isObj(e.claim) && typeof e.claim.id === "string" ? e.claim : null,
- stampsOn: isObj(e.claim) && typeof e.claim.id === "string" ? stampingEntryId(manifest, e.claim.id) : null,
+ // `claim` / `stampsOn` are the FIRST mark's; `marks` every one, each
+ // with the entry that stamps it (plans/clip-marks.md).
+ ...marksView(manifest, e),
audio: isObj(e.audio) ? e.audio : null,
};
});
@@ -151,7 +153,22 @@ export async function clipEditorView(project) {
repropose: { available: reproposeAvailable, why: reproposeAvailable ? null : REPROPOSE_UNAVAILABLE },
shorts: Object.fromEntries(shorts.filter((x) => !x.gone).map((x) => [x.clip, { mtimeMs: x.mtimeMs, size: x.size, stale: x.stale }])),
room: roomViewOf(manifest.render),
- knobs: knobDefaultsOf(manifest.render),
+ knobs: { ...knobDefaultsOf(manifest.render), verdicts: markVerdictsOf(manifest) },
+ };
+}
+
+/**
+ * A clip's marks for the view: `claim` and `stampsOn` (its first mark's, as
+ * before marks), and `marks` -- each as written, with `stampsOn`, the entry
+ * that stamps it.
+ */
+function marksView(manifest, e) {
+ const marks = rawMarksOf(e).filter((m) => isObj(m) && typeof m.id === "string");
+ const first = marks[0] ?? null;
+ return {
+ claim: first,
+ stampsOn: first ? stampingEntryId(manifest, first.id) : null,
+ marks: marks.map((m) => ({ ...m, stampsOn: stampingEntryId(manifest, m.id) })),
};
}
@@ -297,8 +314,13 @@ const num = (v, what) => {
* vertical { clip, crop | null, aspect? } the clip's 9:16 box for its short
* room { clip, room: false | {tail?, head?} | null } room at this clip's edges
* (null: the cut's render.room again)
- * claim { clip, knobs: { at?, hold?, stamp?, count?, label? } } the claim's stamp and
- * count (null on a knob: its default again)
+ * claim { clip, mark?, knobs: { at?, hold?, stamp?, count?, label? } } a mark's stamp and
+ * count (null on a knob: its default again);
+ * `mark` its id (default: the clip's first)
+ * marks { clip, add: { verdict, at?, id?, … } } a new mark (a new id unless given)
+ * { clip, remove: <mark id> } one mark gone
+ * { clip, mark: <mark id>, verdict } a mark's verdict (every clip carrying the id)
+ * { clip, set: [mark, …] | null } all of them (manifest.mjs updateMarks)
* audio { clip, audio: { offset?, gain?, fadeIn?, fadeOut? } | null } the clip's sound
* (null on a key, or the whole: the default)
* with `token` (the manifest's, from the view) on every manifest edit.
@@ -440,7 +462,17 @@ export async function runClipEditorOp(project, body, { now = null } = {}) {
// whether it is drawn, how much it counts, what it says. Not structural: no clip moves.
const e = needClip();
if (!isObj(body.knobs)) throw new OpError("claim needs knobs: { at?, hold?, stamp?, count?, label? }");
- result = await updateClaimKnobs(dir, e.id, body.knobs, { token });
+ result = await updateClaimKnobs(dir, e.id, body.knobs, { token, mark: typeof body.mark === "string" ? body.mark : null });
+ structural = false;
+ break;
+ }
+ case "marks": {
+ // The clip's marks (plans/clip-marks.md): add, remove, a verdict, or all
+ // of them. Not structural: no clip moves.
+ const e = needClip();
+ const change = "add" in body ? { add: body.add } : "remove" in body ? { remove: body.remove } : "set" in body ? { set: body.set } : "mark" in body ? { mark: body.mark, verdict: body.verdict } : null;
+ if (!change) throw new OpError("marks needs add, remove, set, or mark with verdict");
+ result = await updateMarks(dir, e.id, change, { token });
structural = false;
break;
}
@@ -453,7 +485,7 @@ export async function runClipEditorOp(project, body, { now = null } = {}) {
break;
}
default:
- throw new OpError("op must be trim, restore, split, merge, add, bring-in, ruling, role, label, vertical, room, claim or audio");
+ throw new OpError("op must be trim, restore, split, merge, add, bring-in, ruling, role, label, vertical, room, claim, marks or audio");
}
let carried = null;
if (structural) {
@@ -472,6 +504,8 @@ function summarise(r) {
if (isObj(r.speaker)) out.speaker = r.speaker;
if (isObj(r.claim)) out.claim = r.claim;
if (typeof r.stamps === "boolean") out.stamps = r.stamps;
+ if (Array.isArray(r.marks)) out.marks = r.marks;
+ if (typeof r.added === "string") out.added = r.added;
if (r.ruling !== undefined) out.ruling = r.ruling;
return out;
}
diff --git a/umtool/lib/report/clipEditor.test.mjs b/umtool/lib/report/clipEditor.test.mjs
@@ -350,7 +350,11 @@ test("runClipEditorOp: the video knobs -- claim (Count & stamp) and audio; the v
m.render.chrome = { engine: "hyperframes", layout: "deck", factcheck: { stamp: { seconds: 4 }, verdicts: { CONTRADICTED: { label: "Seizures", stampLabel: "SEIZURE" } } } };
await writeFile(path.join(p.dir, MANIFEST_NAME), JSON.stringify(m, null, 2) + "\n");
const v0 = await clipEditorView(p);
- assert.deepEqual(v0.knobs, { hold: 4, stampShown: true, count: 1, labels: { ...v0.knobs.labels, CONTRADICTED: "SEIZURE" } });
+ const { verdicts, ...knobs0 } = v0.knobs;
+ assert.deepEqual(knobs0, { hold: 4, stampShown: true, count: 1, labels: { ...v0.knobs.labels, CONTRADICTED: "SEIZURE" } });
+ // The marks' verdicts: the cut's own (relabelled, or in use) first, with its words.
+ assert.deepEqual(verdicts[0], { verdict: "CONTRADICTED", label: "Seizures", stampLabel: "SEIZURE", color: "#e5534b", stock: true });
+ assert.equal(verdicts.length, 5);
assert.equal(v0.knobs.labels.PARTLY, "Partly true");
const r = await runClipEditorOp(p, { op: "claim", clip: "r003", token: v0.token, knobs: { at: 55.5, count: 2 } });
assert.deepEqual(r.result.claim, { id: "k7", verdict: "CONTRADICTED", at: 55.5, count: 2 });
@@ -367,3 +371,30 @@ test("runClipEditorOp: the video knobs -- claim (Count & stamp) and audio; the v
await rm(p.dir, { recursive: true, force: true });
}
});
+
+test("runClipEditorOp marks: add at a second (a new id), a mark's knobs and verdict, remove, clear; the view lists every mark", async () => {
+ const p = await project({ withReactions: false });
+ try {
+ const v0 = await clipEditorView(p);
+ assert.deepEqual(v0.clips.find((x) => x.id === "r003").marks, [], "a clip with no marks: an empty list (the box shows on every clip)");
+ const a = await runClipEditorOp(p, { op: "marks", clip: "r003", token: v0.token, add: { verdict: "PARTLY", at: 52 } });
+ assert.equal(a.result.added, "r003");
+ const b = await runClipEditorOp(p, { op: "marks", clip: "r003", token: a.view.token, add: { verdict: "PARTLY", at: 56 } });
+ assert.equal(b.result.added, "r003.2");
+ const c = b.view.clips.find((x) => x.id === "r003");
+ assert.deepEqual(c.marks.map((m) => [m.id, m.at, m.stampsOn]), [["r003", 52, "r003"], ["r003.2", 56, "r003"]]);
+ assert.equal(c.claim.id, "r003", "claim: the first mark");
+ const k = await runClipEditorOp(p, { op: "claim", clip: "r003", token: b.view.token, mark: "r003.2", knobs: { count: 2 } });
+ assert.equal(k.view.clips.find((x) => x.id === "r003").marks[1].count, 2);
+ const v = await runClipEditorOp(p, { op: "marks", clip: "r003", token: k.view.token, mark: "r003.2", verdict: "CONTRADICTED" });
+ assert.equal(v.view.clips.find((x) => x.id === "r003").marks[1].verdict, "CONTRADICTED");
+ await assert.rejects(runClipEditorOp(p, { op: "marks", clip: "r003", token: v.view.token, add: { verdict: "PARTLY", at: 53 } }), /overlap/);
+ const r = await runClipEditorOp(p, { op: "marks", clip: "r003", token: v.view.token, remove: "r003" });
+ assert.deepEqual(r.view.clips.find((x) => x.id === "r003").marks.map((m) => m.id), ["r003.2"]);
+ const z = await runClipEditorOp(p, { op: "marks", clip: "r003", token: r.view.token, set: null });
+ assert.deepEqual(z.view.clips.find((x) => x.id === "r003").marks, []);
+ await assert.rejects(runClipEditorOp(p, { op: "marks", clip: "r003" }), /marks needs add, remove, set, or mark/);
+ } finally {
+ await rm(p.dir, { recursive: true, force: true });
+ }
+});
diff --git a/umtool/lib/report/clipEditorTypes.ts b/umtool/lib/report/clipEditorTypes.ts
@@ -33,15 +33,21 @@ export type EditorClip = {
/** The video knobs: the claim as written (id, verdict, and its stamp's knobs), the entry that stamps it, the sound. */
claim?: ClaimKnobs | null;
stampsOn?: string | null;
+ /** Every mark (plans/clip-marks.md), in order, each with the entry that stamps it; `claim` is the first. */
+ marks?: MarkView[];
audio?: ClipAudio | null;
};
/** A claim with its knobs (plans/video-knobs-plan.md): `at` is a source second. */
export type ClaimKnobs = { id: string; verdict: string; at?: number; hold?: number; stamp?: boolean; count?: number; label?: string };
+/** A mark as the clip editor shows it: its knobs, and the clip that stamps it (the last carrying its id). */
+export type MarkView = ClaimKnobs & { stampsOn: string | null };
+/** A verdict a mark may take, with this cut's words and colour; `stock`: the cut's own (relabelled, or in use). */
+export type MarkVerdict = { verdict: string; label: string; stampLabel: string; color: string; stock: boolean };
/** A clip's sound at the encode: offset in ms (+ = later), gain in dB, fades in s. */
export type ClipAudio = { offset?: number; gain?: number; fadeIn?: number; fadeOut?: number };
/** What a claim knob is when absent: the cut's stamp seconds, whether stamps are drawn, the count, each verdict's stamp word. */
-export type KnobDefaults = { hold: number; stampShown: boolean; count: number; labels: Record<string, string> };
+export type KnobDefaults = { hold: number; stampShown: boolean; count: number; labels: Record<string, string>; verdicts?: MarkVerdict[] };
export type Speaker = { index: number; role?: "host" | "subject" | "other"; label?: string; seconds?: number; turns?: number; how?: "auto" | "operator"; sameAs?: number };
export type Proposal = { id: string; start: number; end: number; score?: number; why?: string; moments?: string[]; used?: boolean; clipId?: string | null };
diff --git a/umtool/lib/report/knobs.mjs b/umtool/lib/report/knobs.mjs
@@ -17,7 +17,9 @@
// and which entry's knobs the build reads.
//
// PURE: no fs. Plain ESM so `umtool set` runs it under bare node.
-import { CLAIM_KEYS, CLAIM_LIMITS, FACTCHECK_DEFAULTS, FACTCHECK_LIMITS, STAMP_MOTIONS } from "umtool-report-to-video/factcheck";
+import {
+ CLAIM_KEYS, CLAIM_LIMITS, CLAIM_MARKS_MAX, FACTCHECK_DEFAULTS, FACTCHECK_LIMITS, STAMP_MOTIONS, VERDICTS, rawMarksOf, resolveFactcheck,
+} from "umtool-report-to-video/factcheck";
import { MARKER_ALIGNS, MARKER_LAYOUTS } from "umtool-report-to-video/deck";
import { DEFAULT_VARIANTS, validateVariants, variantsOf } from "umtool-report-to-video/variants";
@@ -132,7 +134,7 @@ export function claimKnobsOf(claim) {
export function stampingEntryId(manifest, claimId, variant = null) {
let last = null;
for (const e of Array.isArray(manifest?.timeline) ? manifest.timeline : []) {
- if (!isObj(e) || !isObj(e.claim) || e.claim.id !== claimId) continue;
+ if (!isObj(e) || !rawMarksOf(e).some((m) => isObj(m) && m.id === claimId)) continue;
if (variant && e.variant && e.variant !== variant) continue;
last = e.id;
}
@@ -140,6 +142,109 @@ export function stampingEntryId(manifest, claimId, variant = null) {
}
// ---------------------------------------------------------------------------
+// An entry's MARKS (plans/clip-marks.md): `claims: [mark, …]`, or a lone
+// `claim` for one. Every writer stores one mark as `claim` -- so a manifest
+// with one mark per clip is the bytes it always was -- and two or more as
+// `claims`.
+// ---------------------------------------------------------------------------
+
+export { CLAIM_MARKS_MAX, rawMarksOf };
+
+/** An entry's marks as written, copied (a writer edits the copy, then setMarks). */
+export const marksCopyOf = (entry) => rawMarksOf(entry).filter(isObj).map((m) => ({ ...m }));
+
+/**
+ * Store `marks` on `entry`: none removes `claim` and `claims`; one is `claim`;
+ * two or more are `claims`. Mutates `entry`.
+ */
+export function setMarks(entry, marks) {
+ const list = Array.isArray(marks) ? marks.filter(isObj) : [];
+ const key = list.length === 0 ? null : list.length === 1 ? "claim" : "claims";
+ const value = list.length === 1 ? list[0] : list;
+ // In the place the marks had among the entry's keys (else last): a mark
+ // added and removed again leaves the entry the bytes it was.
+ const keys = Object.keys(entry);
+ const at = keys.findIndex((k) => k === "claim" || k === "claims");
+ if (at === -1) {
+ if (key) entry[key] = value;
+ return entry;
+ }
+ const after = keys.slice(at + 1).filter((k) => k !== "claim" && k !== "claims").map((k) => [k, entry[k]]);
+ for (const k of keys.slice(at)) delete entry[k];
+ if (key) entry[key] = value;
+ for (const [k, v] of after) entry[k] = v;
+ return entry;
+}
+
+/** Every mark id the manifest uses. */
+export function markIdsOf(manifest) {
+ const ids = new Set();
+ for (const e of Array.isArray(manifest?.timeline) ? manifest.timeline : []) {
+ for (const m of rawMarksOf(e)) if (isObj(m) && typeof m.id === "string") ids.add(m.id);
+ }
+ return ids;
+}
+
+/**
+ * A NEW mark id for a mark added to `entryId`: the entry's id when no mark
+ * uses it, else `<entryId>.2`, `.3`, … -- never an id another mark has (a
+ * shared id is one event, counted once).
+ */
+export function freshMarkId(manifest, entryId) {
+ const used = markIdsOf(manifest);
+ const base = String(entryId ?? "").replace(/[^A-Za-z0-9_.:-]/g, "-").replace(/^[^A-Za-z0-9]+/, "").slice(0, 56) || "mark";
+ if (!used.has(base)) return base;
+ for (let n = 2; ; n += 1) {
+ const id = `${base}.${n}`;
+ if (!used.has(id)) return id;
+ }
+}
+
+/**
+ * A verdict as typed: its name (`CORROBORATED`, any case) or its label in this
+ * cut (`Episodes`, any case -- the fact-check's `verdicts.<V>.label` or
+ * `stampLabel`). Throws a sentence naming the choices.
+ *
+ * @param {unknown} v
+ * @param {Record<string, any>} [render]
+ */
+export function verdictOfInput(v, render) {
+ const s = typeof v === "string" ? v.trim() : "";
+ const upper = s.toUpperCase().replace(/[\s-]+/g, "_");
+ if (VERDICTS.includes(upper)) return upper;
+ const fc = resolveFactcheck(render);
+ const given = isObj(render?.chrome?.factcheck?.verdicts) ? render.chrome.factcheck.verdicts : {};
+ for (const V of VERDICTS) {
+ const words = [fc.verdicts[V]?.label, isObj(given[V]) ? given[V].stampLabel : null].filter((x) => typeof x === "string");
+ if (words.some((w) => w.trim().toLowerCase() === s.toLowerCase())) return V;
+ }
+ const names = VERDICTS.map((V) => (fc.verdicts[V]?.label && fc.verdicts[V].label !== V ? `${V} (${fc.verdicts[V].label})` : V));
+ throw new Error(`${q(v)} is not a verdict: ${names.join(", ")}`);
+}
+
+/**
+ * The verdicts a mark is picked from, for the clip editor: each with its tally
+ * label, stamp word and colour, the cut's own first (`stock`: the ones the
+ * fact-check relabels, or any mark already uses), then the rest.
+ *
+ * @returns {Array<{ verdict: string, label: string, stampLabel: string, color: string, stock: boolean }>}
+ */
+export function markVerdictsOf(manifest) {
+ const render = manifest?.render;
+ const fc = resolveFactcheck(render);
+ const given = isObj(render?.chrome?.factcheck?.verdicts) ? render.chrome.factcheck.verdicts : {};
+ const used = new Set();
+ for (const e of Array.isArray(manifest?.timeline) ? manifest.timeline : []) {
+ for (const m of rawMarksOf(e)) if (isObj(m) && typeof m.verdict === "string") used.add(m.verdict);
+ }
+ const all = VERDICTS.map((V) => {
+ const own = isObj(given[V]) && typeof given[V].stampLabel === "string" && given[V].stampLabel.trim() ? given[V].stampLabel.trim() : null;
+ return { verdict: V, label: fc.verdicts[V].label, stampLabel: own ?? fc.verdicts[V].label, color: fc.verdicts[V].color, stock: V in given || used.has(V) };
+ });
+ return [...all.filter((x) => x.stock), ...all.filter((x) => !x.stock)];
+}
+
+// ---------------------------------------------------------------------------
// The fact-check's stamp knobs, for the editor's placeholders.
// ---------------------------------------------------------------------------
diff --git a/umtool/lib/report/knobsCli.mjs b/umtool/lib/report/knobsCli.mjs
@@ -5,6 +5,9 @@
// before it, so a write here beside an open page is refused rather than lost.
//
// umtool set <project> <clip> key=value … claim.at claim.hold claim.stamp claim.count claim.label
+// (a clip's first mark, or --mark <id>'s)
+// marks=<json> mark.add=<verdict>[@<sec>] mark.remove=<id>
+// mark.verdict=<verdict> (plans/clip-marks.md)
// audio.offset audio.gain audio.fadeIn audio.fadeOut
// umtool look <project> key=value … factcheck.stamp.<k>, factcheck.verdicts.<V>.<k>,
// deck.markers=<json>, deck.markerLayout=…, variants=<json>,
@@ -26,22 +29,29 @@ import {
updateClip,
updateDeckKeys,
updateFactcheck,
+ updateMarks,
updateRender,
updateVariants,
} from "./manifest.mjs";
-import { CLAIM_KNOBS, STAMP_KNOB_DEFAULTS, VARIANTS_DEFAULT, stampingEntryId, variantsOf } from "./knobs.mjs";
+import { CLAIM_KNOBS, STAMP_KNOB_DEFAULTS, VARIANTS_DEFAULT, rawMarksOf, stampingEntryId, variantsOf } from "./knobs.mjs";
import { variantsSteps } from "./driver.mjs";
import { outDirOf, variantsState } from "./variantsView.mjs";
export const AUDIO_KNOBS = Object.freeze(["offset", "gain", "fadeIn", "fadeOut"]);
-const SET_KEYS = [...CLAIM_KNOBS.map((k) => `claim.${k}`), ...AUDIO_KNOBS.map((k) => `audio.${k}`), "layout"];
+const MARK_KEYS = ["marks", "mark.add", "mark.remove", "mark.verdict"];
+const SET_KEYS = [...CLAIM_KNOBS.map((k) => `claim.${k}`), ...MARK_KEYS, ...AUDIO_KNOBS.map((k) => `audio.${k}`), "layout"];
export const SET_USAGE = [
- "usage: umtool set <project> <clip> key=value … [--json]",
+ "usage: umtool set <project> <clip> key=value … [--mark <id>] [--json]",
` keys: ${SET_KEYS.join(" ")}`,
" claim.at is a SOURCE second inside the clip's window: the stamp lands and the count steps there",
" (read from the last clip carrying the claim); claim.hold s (0.5–10); claim.stamp true|false;",
- " claim.count 1–99; claim.label ≤ 20 chars. audio.offset ms (-2000…2000, + = sound later),",
+ " claim.count 1–99; claim.label ≤ 20 chars. The claim.* keys set the clip's first mark, or --mark <id>'s.",
+ " Marks (a clip may carry up to 8, each its own stamp and count): mark.add=<verdict>[@<sec>] adds one",
+ " (the verdict by name or by this cut's label, e.g. Episodes@190.2; a JSON object for its knobs too);",
+ " mark.remove=<id>; mark.verdict=<verdict> (the first mark's, or --mark <id>'s; every clip carrying",
+ " the id); marks='[{\"id\":\"c1\",\"verdict\":\"CORROBORATED\",\"at\":190.2},…]' sets them all (`marks=` none).",
+ " audio.offset ms (-2000…2000, + = sound later),",
" audio.gain dB (-20…20), audio.fadeIn / audio.fadeOut s (0–5). layout=finale|clip (the deck's finale",
" layout for this clip; clip is the default). `key=` clears it (the default).",
].join("\n");
@@ -88,7 +98,7 @@ const splitArgs = (args) => {
const flags = new Map();
for (let i = 0; i < args.length; i += 1) {
const a = args[i];
- if (a === "--take") {
+ if (a === "--take" || a === "--mark") {
flags.set(a, args[i + 1] ?? "");
i += 1;
} else if (a.startsWith("--")) flags.set(a, true);
@@ -119,8 +129,13 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso
return 2;
}
const project = await projectOf(projectArg, root);
+ const markFlag = flags.get("--mark");
+ const mark = typeof markFlag === "string" && markFlag ? markFlag : null;
+ if (flags.has("--mark") && !mark) throw new CliError("--mark needs a mark id");
const claim = {};
const audio = {};
+ /** @type {Record<string, unknown>[]} the marks changes, in the order given */
+ const markChanges = [];
/** @type {Record<string, unknown>} */
const entryPatch = {};
for (const [key, value] of parseAssignments(rest)) {
@@ -129,15 +144,27 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso
entryPatch.layout = value;
continue;
}
+ if (MARK_KEYS.includes(key)) {
+ markChanges.push(markChangeOf(key, value, mark));
+ continue;
+ }
const [group, k] = key.split(".");
(group === "claim" ? claim : audio)[k] = value;
}
if (Object.keys(audio).length) entryPatch.audio = audio;
const results = {};
let notes = null;
+ for (const change of markChanges) {
+ const token = await manifestToken(project.dir);
+ const { result, editNotes } = await withEditNotes(project, () => updateMarks(project.dir, clipId, change, { token }));
+ results.marks = result.marks;
+ results.stampsOnByMark = result.stampsOn;
+ if (result.added) (results.added ??= []).push(result.added);
+ notes = editNotes ?? notes;
+ }
if (Object.keys(claim).length) {
const token = await manifestToken(project.dir);
- const { result, editNotes } = await withEditNotes(project, () => updateClaimKnobs(project.dir, clipId, claim, { token }));
+ const { result, editNotes } = await withEditNotes(project, () => updateClaimKnobs(project.dir, clipId, claim, { token, mark }));
results.claim = result.claim;
results.stamps = result.stamps;
results.stampsOn = result.stampsOn;
@@ -154,6 +181,10 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso
out(JSON.stringify({ ok: true, clip: clipId, ...results, editNotes: notes }, null, 2));
return 0;
}
+ if (results.marks) {
+ out(`${clipId}: ${results.marks.length ? `marks ${results.marks.map((m) => markLine(m, results.stampsOnByMark?.[m.id], clipId)).join(" | ")}` : "no marks"}`);
+ if (results.added) out(` added ${results.added.join(", ")}`);
+ }
if (results.claim) {
out(`${clipId}: claim ${JSON.stringify(results.claim)}`);
if (!results.stamps) out(` NOTE: ${results.claim.id} stamps on ${results.stampsOn} (the last clip carrying it) — these knobs are read there, not here`);
@@ -171,6 +202,44 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
+/**
+ * One `mark.*` / `marks` assignment as an updateMarks change: `mark.add=Episodes@190.2`
+ * (or a JSON object), `mark.remove=<id>`, `mark.verdict=<verdict>` (for --mark's
+ * id, else the clip's first mark), `marks=<json list>` (`marks=` none).
+ */
+export function markChangeOf(key, value, mark = null) {
+ switch (key) {
+ case "marks":
+ if (value !== null && !Array.isArray(value)) throw new CliError("marks= takes a JSON list of marks, or nothing for none");
+ return { set: value };
+ case "mark.add": {
+ if (isObj(value)) return { add: value };
+ if (typeof value !== "string" || !value.trim()) throw new CliError("mark.add= takes <verdict>[@<source second>], or a JSON object");
+ const [verdict, at, ...more] = value.split("@");
+ if (more.length) throw new CliError(`mark.add=${value}: one @ (the source second)`);
+ if (at === undefined || at === "") return { add: { verdict: verdict.trim() } };
+ const s = Number(at);
+ if (!Number.isFinite(s)) throw new CliError(`mark.add=${value}: ${at} is not a source second`);
+ return { add: { verdict: verdict.trim(), at: s } };
+ }
+ case "mark.remove":
+ if (value === null) throw new CliError("mark.remove= takes the mark's id");
+ return { remove: String(value) };
+ case "mark.verdict":
+ if (value === null) throw new CliError("mark.verdict= takes a verdict (its name or this cut's label)");
+ return { mark, verdict: String(value) };
+ default:
+ throw new CliError(`${key} is not a marks key`);
+ }
+}
+
+/** One mark for a line: `id VERDICT at=… (stamps on x)`. */
+function markLine(m, stampsOn, clipId) {
+ const knobs = CLAIM_KNOBS.filter((k) => m[k] !== undefined).map((k) => `${k}=${JSON.stringify(m[k])}`);
+ const where = stampsOn && stampsOn !== clipId ? ` (stamps on ${stampsOn})` : "";
+ return [m.id, m.verdict, ...knobs].join(" ") + where;
+}
+
/** Set (or with null, remove) `a.b.c` in a copy of `obj`, pruning objects left empty. */
function setPath(obj, keys, value) {
const root = structuredClone(isObj(obj) ? obj : {});
@@ -327,14 +396,18 @@ export function knobsOf(manifest) {
const clips = [];
for (const e of timeline) {
if (!isObj(e)) continue;
- const claim = isObj(e.claim) ? Object.fromEntries(CLAIM_KNOBS.filter((k) => e.claim[k] !== undefined).map((k) => [k, e.claim[k]])) : null;
+ // The first mark is `claim…` (as before marks); two or more are `marks` too.
+ const all = rawMarksOf(e).filter(isObj);
+ const first = all[0] ?? null;
+ const claim = first ? Object.fromEntries(CLAIM_KNOBS.filter((k) => first[k] !== undefined).map((k) => [k, first[k]])) : null;
const audio = isObj(e.audio) ? e.audio : null;
- if ((claim && Object.keys(claim).length) || audio || isObj(e.claim) || typeof e.layout === "string") {
+ if ((claim && Object.keys(claim).length) || audio || first || typeof e.layout === "string") {
clips.push({
id: e.id,
...(e.variant ? { variant: e.variant } : {}),
- ...(isObj(e.claim) ? { claimId: e.claim.id, verdict: e.claim.verdict, stamps: stampingEntryId(manifest, e.claim.id) === e.id } : {}),
+ ...(first ? { claimId: first.id, verdict: first.verdict, stamps: stampingEntryId(manifest, first.id) === e.id } : {}),
...(claim && Object.keys(claim).length ? { claim } : {}),
+ ...(all.length > 1 ? { marks: all.map((m) => ({ ...m, stampsOn: stampingEntryId(manifest, m.id) })) } : {}),
...(audio ? { audio } : {}),
...(typeof e.layout === "string" ? { layout: e.layout } : {}),
});
@@ -361,8 +434,11 @@ export function knobsLines(manifest) {
const lines = [];
for (const c of k.clips) {
const bits = [];
- if (c.claimId) bits.push(`claim ${c.claimId} ${c.verdict}${c.stamps ? " (stamps here)" : ""}`);
- if (c.claim) bits.push(Object.entries(c.claim).map(([a, b]) => `${a}=${JSON.stringify(b)}`).join(" "));
+ if (c.marks) bits.push(`marks ${c.marks.map((m) => markLine(m, m.stampsOn, c.id) + (m.stampsOn === c.id ? " (stamps here)" : "")).join(" | ")}`);
+ else {
+ if (c.claimId) bits.push(`claim ${c.claimId} ${c.verdict}${c.stamps ? " (stamps here)" : ""}`);
+ if (c.claim) bits.push(Object.entries(c.claim).map(([a, b]) => `${a}=${JSON.stringify(b)}`).join(" "));
+ }
if (c.layout) bits.push(`layout ${c.layout}`);
if (c.audio) bits.push(`audio ${Object.entries(c.audio).map(([a, b]) => `${a}=${b}`).join(" ")}`);
lines.push(` ${String(c.id).padEnd(8)} ${bits.join(" · ")}`);
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -40,7 +40,10 @@ import { applySectionEnter } from "./sections.mjs";
import { normalizeClaim, validateClaims } from "umtool-report-to-video/factcheck";
import { validateFinaleEntries } from "umtool-report-to-video/finale";
import { validateClipAudio } from "umtool-report-to-video/clip-audio";
-import { CLAIM_KNOBS, claimKnobsOf, claimKnobValue, normalizeClaimKnobPatch, stampingEntryId, variantsProblems } from "./knobs.mjs";
+import {
+ CLAIM_KNOBS, CLAIM_MARKS_MAX, claimKnobsOf, claimKnobValue, freshMarkId, marksCopyOf, normalizeClaimKnobPatch, rawMarksOf, setMarks, stampingEntryId,
+ variantsProblems, verdictOfInput,
+} from "./knobs.mjs";
import { validateNarration } from "umtool-report-to-video/narration";
import { parseMuteFrom } from "./playback.mjs";
import { DELIVERABLES_MODES } from "./storage.mjs";
@@ -347,13 +350,16 @@ export async function updateClip(dir, clipId, patch, { token = null, edit = "tri
// 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) && isObj(entry.claim) && typeof entry.claim.at === "number") {
- if (entry.claim.at < entry.start || entry.claim.at > entry.end) {
+ 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(
- `the stamp's second (claim.at ${entry.claim.at}) must lie inside the window ` +
- `${entry.start}–${entry.end} — widen the window, or clear claim.at`,
+ `${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) -------------------------------------
@@ -592,6 +598,7 @@ export async function splitClip(dir, clipId, at, { token = null, quotes = {}, no
if (typeof b.cite === "number") b.cite = t;
if (b.muteFrom != null && b.muteFrom < t) delete b.muteFrom;
delete b.claim;
+ delete b.claims;
const qb = textOr(quotes.second, b.quote ?? null);
if (qb) b.quote = qb;
else delete b.quote;
@@ -933,8 +940,13 @@ export async function updateOnscreen(dir, onscreen, { token = null } = {}) {
// A row that does not name the knobs keeps the entry's while the claim
// stays the same claim: the On-screen table edits the id and verdict,
// the clip editor the knobs, and neither may drop the other's work.
- const keep = c && !withKnobs.has(e.id) && isObj(e.claim) && e.claim.id === c.id ? claimKnobsOf(e.claim) : {};
- if (c) e.claim = { ...c, ...keep };
+ // On an entry with marks (`claims`) the row is its FIRST mark; the
+ // others stay as they are.
+ const marks = marksCopyOf(e);
+ const first = marks[0];
+ const keep = c && !withKnobs.has(e.id) && isObj(first) && first.id === c.id ? claimKnobsOf(first) : {};
+ if (marks.length > 1) setMarks(e, c ? [{ ...c, ...keep }, ...marks.slice(1)] : marks.slice(1));
+ else if (c) e.claim = { ...c, ...keep };
else delete e.claim;
}
}
@@ -1415,6 +1427,7 @@ export async function duplicateEntry(dir, id, { token = null, at = null } = {})
const copy = JSON.parse(JSON.stringify(m.timeline[i]));
copy.id = freshEntryId(m.timeline, `${id}-copy`);
delete copy.claim;
+ delete copy.claims;
m.timeline.splice(i + 1, 0, copy);
return { id: copy.id, at: i + 1, entry: copy };
});
@@ -1737,13 +1750,16 @@ export async function updateFactcheck(dir, factcheck, { token = null } = {}) {
* The build reads the knobs of the entry that STAMPS the claim -- the last
* carrying its id -- so `stamps` in the answer says whether this one does.
*
+ * On an entry with MARKS (`claims`), `mark` names the one patched (its id);
+ * without it, the first.
+ *
* @param {string} dir
* @param {string} entryId
* @param {Record<string, unknown>} patch
- * @param {{ token?: string | null }} [opts]
+ * @param {{ token?: string | null, mark?: string | null }} [opts]
* @returns {Promise<{ claim: Record<string, unknown>, stamps: boolean, stampsOn: string | null, token: string | null }>}
*/
-export async function updateClaimKnobs(dir, entryId, patch, { token = null } = {}) {
+export async function updateClaimKnobs(dir, entryId, patch, { token = null, mark = null } = {}) {
const next = normalizeClaimKnobPatch(patch);
return withManifestLock(async () => {
const current = await manifestToken(dir);
@@ -1751,20 +1767,145 @@ export async function updateClaimKnobs(dir, entryId, patch, { token = null } = {
const manifest = JSON.parse(await readFile(manifestFile(dir), "utf8"));
const entries = (manifest.timeline ?? []).filter((e) => isObj(e) && e.id === entryId);
if (!entries.length) throw new Error(`no timeline entry with id ${entryId}`);
- if (!isObj(entries[0].claim)) throw new Error(`${entryId} carries no claim — give it one (the On-screen table's claim column) before its stamp's knobs`);
+ const pick = (e) => rawMarksOf(e).find((m) => isObj(m) && (mark === null || m.id === mark));
+ if (!rawMarksOf(entries[0]).some(isObj)) throw new Error(`${entryId} carries no claim — add a mark (the clip editor's Marks, or mark.add=) before its stamp's knobs`);
+ if (!pick(entries[0])) throw new Error(`${entryId} carries no mark ${mark} (its marks: ${rawMarksOf(entries[0]).map((m) => m?.id).join(", ")})`);
+ // Edited in place: a lone claim keeps its keys' order, so its bytes are what they were.
for (const e of entries) {
- if (!isObj(e.claim)) continue;
+ const m = pick(e);
+ if (!m) continue;
for (const [k, v] of Object.entries(next)) {
- if (v === null) delete e.claim[k];
- else e.claim[k] = v;
+ if (v === null) delete m[k];
+ else m[k] = v;
}
}
- // The renderer's own check -- each knob, and `at` inside the entry's window -- on this entry's rows.
+ // The renderer's own check -- each knob, `at` inside the entry's window, no two stamps over each other -- on this entry's rows.
const bad = validateClaims(manifest).filter((e) => e.includes(`(${entryId})`));
if (bad.length) throw new Error(`${bad.join("; ")} — nothing was written`);
const nextToken = await writeManifestAtomic(dir, manifest);
- const stampsOn = stampingEntryId(manifest, entries[0].claim.id);
- return { claim: entries[0].claim, stamps: stampsOn === entryId, stampsOn, token: nextToken };
+ const claim = pick(entries[0]);
+ const stampsOn = stampingEntryId(manifest, claim.id);
+ return { claim, stamps: stampsOn === entryId, stampsOn, token: nextToken };
+ });
+}
+
+/**
+ * Change ONE entry's MARKS (plans/clip-marks.md) -- every entry carrying the
+ * id (a variant's twin) alike. `change` is one of:
+ *
+ * { add: { verdict, at?, id?, hold?, stamp?, count?, label? } }
+ * a new mark after the others; its id a NEW one unless given
+ * (freshMarkId: the entry's id, else `<id>.2`, …); `verdict` its name
+ * or its label in this cut ("Episodes")
+ * { remove: "<mark id>" }
+ * { mark: "<mark id>" | null, verdict } the mark's verdict (null: the
+ * first mark's) -- on every entry carrying the id (one claim, one verdict)
+ * { set: [mark, …] | null } all of them (null or []: none)
+ *
+ * One mark is stored as `claim`, two or more as `claims` (≤ 8). Refused, with
+ * the renderer's sentence, when the result would not build: a mark outside
+ * the window, two stamps over each other, one id given two verdicts.
+ *
+ * @param {string} dir
+ * @param {string} entryId
+ * @param {Record<string, unknown>} change
+ * @param {{ token?: string | null }} [opts]
+ * @returns {Promise<{ marks: Record<string, unknown>[], added: string | null, stampsOn: Record<string, string | null>, token: string | null }>}
+ */
+export async function updateMarks(dir, entryId, change, { token = null } = {}) {
+ if (!isObj(change)) throw new Error("a marks change is { add } | { remove } | { mark, verdict } | { set }");
+ const kinds = ["add", "remove", "mark", "set"].filter((k) => k in change);
+ if (kinds.length !== 1) throw new Error("a marks change names exactly one of add, remove, mark (with verdict), set");
+ return withManifestLock(async () => {
+ const current = await manifestToken(dir);
+ if (token !== null && current !== token) throw new StaleToken(token, current);
+ const manifest = JSON.parse(await readFile(manifestFile(dir), "utf8"));
+ const entries = (manifest.timeline ?? []).filter((e) => isObj(e) && e.id === entryId);
+ if (!entries.length) throw new Error(`no timeline entry with id ${entryId}`);
+ if (entries[0].type === "teaser") throw new Error(`${entryId} is a teaser: a teaser is not evidence for a claim`);
+ const before = new Set(validateClaims(manifest));
+ let added = null;
+ let marks = marksCopyOf(entries[0]);
+ switch (kinds[0]) {
+ case "add": {
+ const a = change.add;
+ if (!isObj(a)) throw new Error("add is { verdict, at?, id?, hold?, stamp?, count?, label? }");
+ if (marks.length >= CLAIM_MARKS_MAX) throw new Error(`${entryId} carries ${marks.length} marks already (at most ${CLAIM_MARKS_MAX})`);
+ const verdict = verdictOfInput(a.verdict, manifest.render);
+ const id = a.id === undefined || a.id === null || a.id === "" ? freshMarkId(manifest, entryId) : String(a.id).trim();
+ if (marks.some((m) => m.id === id)) throw new Error(`${entryId} carries the mark ${id} already`);
+ /** @type {Record<string, unknown>} */
+ const mark = { id, verdict };
+ for (const k of Object.keys(a)) {
+ if (k !== "id" && k !== "verdict" && !CLAIM_KNOBS.includes(k)) throw new Error(`add.${k} is not a mark field (id, verdict, ${CLAIM_KNOBS.join(", ")})`);
+ }
+ const given = Object.fromEntries(CLAIM_KNOBS.filter((k) => a[k] !== undefined && a[k] !== null && a[k] !== "").map((k) => [k, a[k]]));
+ const knobs = Object.keys(given).length ? normalizeClaimKnobPatch(given) : {};
+ for (const [k, v] of Object.entries(knobs)) if (v !== null) mark[k] = v;
+ marks.push(normalizeClaim(mark));
+ added = id;
+ break;
+ }
+ case "remove": {
+ const id = String(change.remove ?? "");
+ if (!marks.some((m) => m.id === id)) throw new Error(`${entryId} carries no mark ${id}`);
+ marks = marks.filter((m) => m.id !== id);
+ break;
+ }
+ case "mark": {
+ // null: the entry's first mark.
+ const id = change.mark === null || change.mark === undefined ? String(marks[0]?.id ?? "") : String(change.mark);
+ if (!marks.some((m) => m.id === id)) throw new Error(`${entryId} carries no mark ${id}`);
+ const verdict = verdictOfInput(change.verdict, manifest.render);
+ // One claim, one verdict: every entry carrying the id.
+ for (const e of manifest.timeline) {
+ if (!isObj(e) || e.id === entryId) continue;
+ for (const m of rawMarksOf(e)) if (isObj(m) && m.id === id) m.verdict = verdict;
+ }
+ marks = marks.map((m) => (m.id === id ? { ...m, verdict } : m));
+ break;
+ }
+ case "set": {
+ const v = change.set;
+ if (v === null || (Array.isArray(v) && !v.length)) marks = [];
+ else if (Array.isArray(v)) marks = normalizeMarksInput(v, manifest.render);
+ else throw new Error("set is a list of marks [{ id, verdict, … }], or null for none");
+ break;
+ }
+ }
+ for (const e of entries) setMarks(e, marks.map((m) => ({ ...m })));
+ // The renderer's own check: refused when this change adds a problem.
+ const bad = validateClaims(manifest).filter((x) => !before.has(x));
+ if (bad.length) throw new Error(`${bad.join("; ")} — nothing was written`);
+ const nextToken = await writeManifestAtomic(dir, manifest);
+ const stored = marksCopyOf(entries[0]);
+ return {
+ marks: stored,
+ added,
+ stampsOn: Object.fromEntries(stored.map((m) => [m.id, stampingEntryId(manifest, m.id)])),
+ token: nextToken,
+ };
+ });
+}
+
+/** A list of marks as typed (a verdict by its name or label, knobs as typed), normalised. */
+function normalizeMarksInput(list, render) {
+ if (list.length > CLAIM_MARKS_MAX) throw new Error(`claims holds ${list.length} marks (at most ${CLAIM_MARKS_MAX})`);
+ return list.map((m, k) => {
+ if (!isObj(m)) throw new Error(`claims[${k}] must be { id, verdict, … }`);
+ /** @type {Record<string, unknown>} */
+ const mark = { id: typeof m.id === "string" ? m.id.trim() : m.id, verdict: verdictOfInput(m.verdict, render) };
+ for (const k2 of Object.keys(m)) {
+ if (k2 === "id" || k2 === "verdict") continue;
+ if (!CLAIM_KNOBS.includes(k2)) throw new Error(`claims[${k}].${k2} is not a mark field (id, verdict, ${CLAIM_KNOBS.join(", ")})`);
+ const v = claimKnobValue(k2, m[k2]);
+ if (v !== null) mark[k2] = v;
+ }
+ try {
+ return normalizeClaim(mark);
+ } catch (e) {
+ throw new Error(String(e instanceof Error ? e.message : e).replace(/^claim\b/, `claims[${k}]`));
+ }
});
}
diff --git a/umtool/lib/report/marks.test.mjs b/umtool/lib/report/marks.test.mjs
@@ -0,0 +1,202 @@
+// MARKS, the writers (plans/clip-marks.md): updateMarks (add, remove, a
+// verdict, all), updateClaimKnobs on one mark, the On-screen table on the
+// first, the window rule over every mark, and `umtool set` / `umtool show`.
+// One mark is written `claim`, two or more `claims`; a mark added and removed
+// again leaves the file the bytes it was.
+//
+// Run with: pnpm test:scripts
+import assert from "node:assert/strict";
+import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import test from "node:test";
+
+const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-marks-"));
+process.env.REPORTS_DIR = ROOT;
+
+const { MANIFEST_NAME, StaleToken, manifestToken, updateClaimKnobs, updateClip, updateMarks, updateOnscreen } = await import("./manifest.mjs");
+const { freshMarkId, markVerdictsOf, setMarks, verdictOfInput } = await import("./knobs.mjs");
+const { knobsLines, knobsOf, setCommand } = await import("./knobsCli.mjs");
+
+const HUCK_FC = {
+ verdicts: {
+ CONTRADICTED: { label: "Grift", color: "#e3b23c", stampLabel: "Grift" },
+ CORROBORATED: { label: "Episodes", color: "#6fa8dc", stampLabel: "Seizure" },
+ },
+ stamp: { seconds: 3 },
+};
+const base = () => ({
+ schemaVersion: 1,
+ slug: "huck",
+ title: "Huck",
+ provenance: { siteOrigin: "https://example.test", channelSlug: "chan" },
+ render: { width: 1920, height: 1080, fps: 30, transition: 0.5, chrome: { engine: "hyperframes", layout: "deck", factcheck: HUCK_FC } },
+ timeline: [
+ { type: "clip", id: "first", video: "v1", start: 171.33, end: 211.78, claim: { id: "first", verdict: "CORROBORATED", at: 188.41 }, quote: "q" },
+ { type: "clip", id: "er", video: "v2", start: 275.2, end: 304.21, claim: { id: "er", verdict: "CORROBORATED" } },
+ { type: "clip", id: "dozen", video: "v3", start: 336.96, end: 385.89, claim: { id: "er", verdict: "CORROBORATED", at: 349.25 } },
+ { type: "clip", id: "fed", video: "v4", start: 6117, end: 6155.63 },
+ ],
+});
+
+let n = 0;
+async function project(manifest = base()) {
+ const name = `p${(n += 1)}`;
+ const dir = path.join(ROOT, name);
+ await mkdir(dir, { recursive: true });
+ await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest, null, 2) + "\n");
+ return { dir, name };
+}
+const readRaw = (dir) => readFile(path.join(dir, MANIFEST_NAME), "utf8");
+const read = async (dir) => JSON.parse(await readRaw(dir));
+const entry = (m, id) => m.timeline.find((e) => e.id === id);
+
+test.after(() => rm(ROOT, { recursive: true, force: true }));
+
+test("knobs: setMarks writes one as claim, two as claims, none as neither -- in the marks' place among the keys", () => {
+ const e = { id: "c", claim: { id: "a", verdict: "PARTLY" }, quote: "q" };
+ setMarks(e, [{ id: "a", verdict: "PARTLY" }, { id: "b", verdict: "PARTLY" }]);
+ assert.deepEqual(Object.keys(e), ["id", "claims", "quote"]);
+ setMarks(e, [{ id: "a", verdict: "PARTLY" }]);
+ assert.deepEqual(Object.keys(e), ["id", "claim", "quote"]);
+ setMarks(e, []);
+ assert.deepEqual(Object.keys(e), ["id", "quote"]);
+ setMarks(e, [{ id: "z", verdict: "PARTLY" }]);
+ assert.deepEqual(Object.keys(e), ["id", "quote", "claim"]);
+});
+
+test("knobs: a new mark's id is the clip's when free, else <clip>.2, .3 …; a verdict by name or this cut's label", () => {
+ const m = base();
+ assert.equal(freshMarkId(m, "fed"), "fed");
+ assert.equal(freshMarkId(m, "first"), "first.2");
+ m.timeline[0].claims = [{ id: "first", verdict: "CORROBORATED" }, { id: "first.2", verdict: "CORROBORATED" }];
+ delete m.timeline[0].claim;
+ assert.equal(freshMarkId(m, "first"), "first.3");
+ assert.equal(verdictOfInput("Episodes", m.render), "CORROBORATED");
+ assert.equal(verdictOfInput("grift", m.render), "CONTRADICTED");
+ assert.equal(verdictOfInput("Seizure", m.render), "CORROBORATED", "the stamp word too");
+ assert.equal(verdictOfInput("partly", m.render), "PARTLY");
+ assert.throws(() => verdictOfInput("nonsense", m.render), /"nonsense" is not a verdict: CORROBORATED \(Episodes\)/);
+ const v = markVerdictsOf(m);
+ assert.deepEqual(v.slice(0, 2).map((x) => [x.verdict, x.label, x.stampLabel, x.stock]), [["CORROBORATED", "Episodes", "Seizure", true], ["CONTRADICTED", "Grift", "Grift", true]]);
+ assert.equal(v.length, 5);
+});
+
+test("updateMarks add: a second mark on the clip gets a NEW id and makes claims; add then remove is the bytes it was", async () => {
+ const { dir } = await project();
+ const before = await readRaw(dir);
+ const r = await updateMarks(dir, "first", { add: { verdict: "Episodes", at: 180.5 } }, { token: await manifestToken(dir) });
+ assert.equal(r.added, "first.2");
+ const e = entry(await read(dir), "first");
+ assert.equal("claim" in e, false);
+ assert.deepEqual(e.claims, [{ id: "first", verdict: "CORROBORATED", at: 188.41 }, { id: "first.2", verdict: "CORROBORATED", at: 180.5 }]);
+ assert.deepEqual(r.stampsOn, { first: "first", "first.2": "first" });
+ await updateMarks(dir, "first", { remove: "first.2" });
+ assert.equal(await readRaw(dir), before, "back to one mark: `claim`, byte for byte");
+ // A first mark on a clip with none takes the clip's id.
+ const f = await updateMarks(dir, "fed", { add: { verdict: "CONTRADICTED", at: 6149.65, count: 2, stamp: true } });
+ assert.equal(f.added, "fed");
+ assert.deepEqual(entry(await read(dir), "fed").claim, { id: "fed", verdict: "CONTRADICTED", at: 6149.65, count: 2 });
+});
+
+test("updateMarks: refuses overlapping stamps, an at outside the window, a ninth mark, a stale token -- the file as it was", async () => {
+ const { dir } = await project();
+ const before = await readRaw(dir);
+ await assert.rejects(
+ updateMarks(dir, "first", { add: { verdict: "CORROBORATED", at: 189.5 } }),
+ /the marks first \(at 188\.41\) and first\.2 \(at 189\.5\) overlap -- first's stamp stays 3 s; land first\.2 at 191\.41 or later/,
+ );
+ await assert.rejects(updateMarks(dir, "first", { add: { verdict: "CORROBORATED", at: 250 } }), /claims\[1\]\.at 250 is outside the clip's window 171\.33–211\.78/);
+ await assert.rejects(updateMarks(dir, "first", { add: { verdict: "nope" } }), /is not a verdict/);
+ await assert.rejects(updateMarks(dir, "first", { add: { verdict: "PARTLY", colour: 1 } }), /add\.colour is not a mark field/);
+ await assert.rejects(updateMarks(dir, "first", { remove: "zz" }), /carries no mark zz/);
+ await assert.rejects(updateMarks(dir, "first", { add: { verdict: "PARTLY" } }, { token: "stale" }), StaleToken);
+ await assert.rejects(updateMarks(dir, "first", { add: {}, remove: "x" }), /exactly one of/);
+ assert.equal(await readRaw(dir), before);
+ const eight = Array.from({ length: 8 }, (_, i) => ({ id: `m${i}`, verdict: "PARTLY" }));
+ await updateMarks(dir, "fed", { set: eight });
+ await assert.rejects(updateMarks(dir, "fed", { add: { verdict: "PARTLY" } }), /carries 8 marks already \(at most 8\)/);
+});
+
+test("updateMarks set / mark-verdict: all at once (null: none); a verdict changes on every clip carrying the id", async () => {
+ const { dir } = await project();
+ await updateMarks(dir, "first", { set: [{ id: "first", verdict: "Episodes", at: 188.41 }, { id: "first.0", verdict: "Episodes", at: "175", label: "EARLIER" }] });
+ assert.deepEqual(entry(await read(dir), "first").claims[1], { id: "first.0", verdict: "CORROBORATED", at: 175, label: "EARLIER" });
+ await assert.rejects(updateMarks(dir, "first", { set: [{ id: "a", verdict: "PARTLY", when: 1 }] }), /claims\[0\]\.when is not a mark field/);
+ // "er" is one event on two clips: its verdict moves on both.
+ await updateMarks(dir, "er", { mark: "er", verdict: "Grift" });
+ const m = await read(dir);
+ assert.equal(entry(m, "er").claim.verdict, "CONTRADICTED");
+ assert.equal(entry(m, "dozen").claim.verdict, "CONTRADICTED");
+ await updateMarks(dir, "first", { set: null });
+ const e = entry(await read(dir), "first");
+ assert.equal("claim" in e || "claims" in e, false);
+});
+
+test("updateClaimKnobs: `mark` names the mark (default the first); a lone claim edited in place", async () => {
+ const { dir } = await project();
+ await updateMarks(dir, "first", { add: { verdict: "CORROBORATED", at: 195 } });
+ const r = await updateClaimKnobs(dir, "first", { count: 2, hold: 2 }, { mark: "first.2" });
+ assert.deepEqual(r.claim, { id: "first.2", verdict: "CORROBORATED", at: 195, count: 2, hold: 2 });
+ assert.equal(r.stamps, true);
+ const r1 = await updateClaimKnobs(dir, "first", { label: "ONE" });
+ assert.equal(r1.claim.id, "first");
+ await assert.rejects(updateClaimKnobs(dir, "first", { count: 2 }, { mark: "zz" }), /carries no mark zz/);
+ // Moving the second mark onto the first's stamp is refused.
+ await assert.rejects(updateClaimKnobs(dir, "first", { at: 189 }, { mark: "first.2" }), /overlap/);
+});
+
+test("updateClip: a window that leaves any mark outside is refused, naming the mark", async () => {
+ const { dir } = await project();
+ await updateMarks(dir, "first", { add: { verdict: "CORROBORATED", at: 205 } });
+ await assert.rejects(updateClip(dir, "first", { end: 200 }), /the mark first\.2's second \(claims\[1\]\.at 205\) must lie inside the window 171\.33–200/);
+ await updateClip(dir, "first", { end: 206 });
+});
+
+test("updateOnscreen: the table's claim is the FIRST mark; the others stay", async () => {
+ const { dir } = await project();
+ await updateMarks(dir, "first", { add: { verdict: "CORROBORATED", at: 195 } });
+ await updateOnscreen(dir, { first: { title: "First", claim: { id: "first", verdict: "CORROBORATED" } } });
+ let e = entry(await read(dir), "first");
+ assert.deepEqual(e.claims.map((m) => [m.id, m.at]), [["first", 188.41], ["first.2", 195]], "the first's knobs kept, the second untouched");
+ await updateOnscreen(dir, { first: { title: "First", claim: null } });
+ e = entry(await read(dir), "first");
+ assert.deepEqual(e.claim, { id: "first.2", verdict: "CORROBORATED", at: 195 }, "the first removed: one mark left, written as claim");
+});
+
+test("previewSchedule: a clip's marks stamp in the On-screen preview; a drafted row replaces only the first", async () => {
+ const { previewSchedule } = await import("./onscreen.mjs");
+ const m = base();
+ setMarks(m.timeline[0], [{ id: "first", verdict: "CORROBORATED", at: 188.41 }, { id: "first.2", verdict: "CONTRADICTED", at: 200 }]);
+ const ids = (s) => s.factcheck.stamps.map((x) => x.claim);
+ const plain = previewSchedule({ variantManifest: m, built: null, draft: new Map(), metas: [] });
+ assert.deepEqual(ids(plain), ["first", "first.2", "er"]);
+ const drafted = previewSchedule({ variantManifest: m, built: null, draft: new Map(), metas: [], claimsDraft: new Map([["first", { id: "lead", verdict: "PARTLY" }]]) });
+ assert.ok(ids(drafted).includes("lead") && ids(drafted).includes("first.2") && !ids(drafted).includes("first"));
+});
+
+test("umtool set: mark.add=<verdict>@<sec>, mark.remove, mark.verdict, marks=<json>, claim.* --mark; show prints the marks", async () => {
+ const { dir, name } = await project();
+ const lines = [];
+ const run = (...args) => setCommand(args, { root: ROOT, out: (s) => lines.push(s), err: (s) => lines.push(`ERR ${s}`) });
+ assert.equal(await run(name, "first", "mark.add=Episodes@176.2"), 0);
+ assert.match(lines.at(-2), /^first: marks first CORROBORATED at=188\.41 \| first\.2 CORROBORATED at=176\.2$/);
+ assert.match(lines.at(-1), /added first\.2/);
+ assert.equal(await run(name, "first", "claim.count=2", "--mark", "first.2"), 0);
+ assert.equal(entry(await read(dir), "first").claims[1].count, 2);
+ assert.equal(await run(name, "first", "mark.verdict=Grift", "--mark", "first.2"), 0);
+ assert.equal(entry(await read(dir), "first").claims[1].verdict, "CONTRADICTED");
+ const show = knobsLines(await read(dir)).find((l) => l.trim().startsWith("first "));
+ assert.match(show, /marks first CORROBORATED at=188\.41 \(stamps here\) \| first\.2 CONTRADICTED at=176\.2 count=2 \(stamps here\)/);
+ assert.equal(knobsOf(await read(dir)).clips.find((c) => c.id === "first").marks.length, 2);
+ assert.equal(await run(name, "first", "mark.add=Episodes@177"), 1);
+ assert.match(lines.at(-1), /^ERR .*overlap/);
+ assert.equal(await run(name, "first", "mark.add=Episodes@1@2"), 2);
+ assert.equal(await run(name, "first", "mark.remove=first.2"), 0);
+ assert.deepEqual(entry(await read(dir), "first").claim, { id: "first", verdict: "CORROBORATED", at: 188.41 });
+ assert.equal(await run(name, "fed", 'marks=[{"id":"fed","verdict":"Grift","at":6149.65},{"id":"fed.2","verdict":"Episodes","at":6130}]'), 0);
+ assert.equal(entry(await read(dir), "fed").claims.length, 2);
+ assert.equal(await run(name, "fed", "marks="), 0);
+ assert.equal("claims" in entry(await read(dir), "fed"), false);
+ assert.match(lines.at(-1), /fed: no marks/);
+});
diff --git a/umtool/lib/report/onscreen.mjs b/umtool/lib/report/onscreen.mjs
@@ -34,7 +34,8 @@ import {
resolveDeck,
roundPosts,
} from "umtool-report-to-video/deck";
-import { claimOf, roundStamps, stampSchedule } from "umtool-report-to-video/factcheck";
+import { marksOf, rawMarksOf, roundStamps, stampSchedule } from "umtool-report-to-video/factcheck";
+import { setMarks } from "./knobs.mjs";
import {
channelsDirFor,
cuePathFor,
@@ -197,8 +198,9 @@ export function previewSchedule({ variantManifest, built, draft, metas, postsDra
}
if (claimsDraft.has(e.id)) {
const c = claimsDraft.get(e.id);
- const { claim: _c, ...rest } = out;
- out = c ? { ...rest, claim: c } : rest;
+ // A row is the entry's FIRST mark; its others stay (plans/clip-marks.md).
+ const others = rawMarksOf(out).slice(1);
+ out = setMarks({ ...out }, c ? [c, ...others] : others);
}
return out;
};
@@ -236,14 +238,14 @@ export function previewSchedule({ variantManifest, built, draft, metas, postsDra
const moves = placed.length && !feed ? footageMoves({ posts: placed, segments, render }) : [];
// The claims as they are NOW, stamped over the build's segments.
const claimed = segments.map((s, i) => {
- const { claim: _c, ...bare } = s;
- const c = claimOf(patchedEntries[i]);
- return c ? { ...bare, claim: c } : bare;
+ const { claim: _c, claims: _cs, ...bare } = s;
+ const marks = marksOf(patchedEntries[i]);
+ return marks.length ? { ...bare, claim: marks[0], ...(marks.length > 1 ? { claims: marks } : {}) } : bare;
});
// A claim stamped at a source second (`claim.at`): the play window's start
// stands in for the cut record's (the build's is exact; snapping moves it).
const stamps = stampSchedule({
- segments: claimed.map((s, i) => (s.claim?.at !== undefined
+ segments: claimed.map((s, i) => (marksOf(patchedEntries[i]).some((c) => c.at !== undefined)
? { ...s, sourceFrom: s.sourceFrom ?? playWindow(patchedEntries[i], render).from }
: s)),
D: built.transition, total, render,