Archilyzer · Source

archilyzer

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

commit bfe860703b5bd3c84be4b95e5a2703fccaca673e
parent 7a4aafd567f13423bdb04e73e51a44f19c870536
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon, 26 Oct 2026 07:22:16 -0400

umtool timeline insert: the clip in the manifest's own convention; --section, --lock, --lock-end

Under the deck --title is onscreen.title (--stream-title the top-level title); a
cut whose deck titles are dates gets --date as one in their format. The clip takes
the section of the clip it goes after unless --section says, and from the same
recording its deck title and citation link moved to the new second, as the clip
editor's add does. Tested on the shape of a real deck cut.

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

Diffstat:
Mumtool/bin/umtool.mjs | 5+++--
Mumtool/lib/report/timelineCli.mjs | 162++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Mumtool/lib/report/timelineCli.test.mjs | 65++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 211 insertions(+), 21 deletions(-)

diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -788,8 +788,9 @@ function usage() { " --yes starts it, one editor job (needs WORKER_TOKEN and the editor)", " umtool refresh --check [<article>] [--force] [--json] the daily suggestion check, now", " umtool timeline <project> [ls] [--json] the cut: index, id, type, video, start–end, date title", - " umtool timeline <project> insert --after <id|-> <channel>/<video>@<start>-<end> [--id ID] [--title T]", - " [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U] a clip, then its attribution", + " umtool timeline <project> insert --after <id|-> <channel>/<video>@<start>-<end> [--id ID] [--section N]", + " [--lock] [--lock-end] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S]", + " [--cite-url U] a clip, then its attribution, in the manifest's convention (deck: onscreen.title)", " umtool timeline <project> move <id> --to <index> | remove <id> | duplicate <id> [--at <index>]", " umtool timeline <project> post <json|@file> | post-remove <id> | teaser <id> <patch-json|@file> | undo", " the Cut tab's structure (POST /api/report/timeline's writers): each write snapshots the", diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs @@ -10,7 +10,8 @@ // // umtool timeline <project> [ls] index, id, type, video, start–end, date title // umtool timeline <project> insert --after <id|-> <channel>/<video>@<start>-<end> -// [--id ID] [--title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U] +// [--id ID] [--section N] [--lock] [--lock-end] +// [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U] // umtool timeline <project> move <id> --to <index> // umtool timeline <project> remove <id> | duplicate <id> // umtool timeline <project> post <json|@file> | post-remove <id> @@ -22,14 +23,26 @@ // bench use, which is what validates it. The date is checked BEFORE the // insert, so a bad one refuses with nothing written. // +// IN THE MANIFEST'S OWN CONVENTION (insertConvention). Under the deck +// (render.chrome deck), the words on screen are `onscreen.title` -- the +// clip editor's and the On-screen table's field -- and `title` is the STREAM +// title the deck's subtitle names, so --title writes `onscreen.title` there +// (--stream-title is the stream's). A cut whose deck titles are DATES ("24 Oct +// 2020") gets --date as its deck title too, in that format; `date` itself is +// the header's date in either. The clip it goes after lends what the clip +// editor's add takes from it: its section (unless --section), and -- the same +// recording -- its deck title and its citation link moved to the new second. +// --lock / --lock-end are written on the clip itself, as `umtool window` does. +// // Plain ESM: the CLI runs under bare node. import { readFile } from "node:fs/promises"; import path from "node:path"; import { isCalendarDate } from "umtool-report-to-video/attribution"; +import { deckOn } from "umtool-report-to-video/deck"; import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { readManifest } from "../projects/report.mjs"; import { withEditNotes } from "./edit-guard.mjs"; -import { parseClipSpec } from "./clipEditorModel.mjs"; +import { citeUrlAt, parseClipSpec } from "./clipEditorModel.mjs"; import { StaleToken, StructureRefused, @@ -48,8 +61,11 @@ import { export const TIMELINE_USAGE = [ "usage: umtool timeline <project> [ls] [--json] the cut: index, id, type, video, start–end, date title", " umtool timeline <project> insert --after <id|-> <channel>/<video>@<start>-<end> [--id ID]", - " [--title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]", - " a clip after <id> (`-`: at the start); the attribution through `umtool window`'s writer", + " [--section N] [--lock] [--lock-end] [--title T] [--stream-title T]", + " [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]", + " a clip after <id> (`-`: at the start); the attribution through `umtool window`'s writer.", + " Under the deck --title is the deck's title (onscreen.title); a cut whose deck titles", + " are dates gets --date as one too. The section is <id>'s unless --section says", " umtool timeline <project> move <id> --to <index> <index> is its place AFTER the move (0 first)", " umtool timeline <project> remove <id> | duplicate <id> (--at <index> names one of an id's twins)", " umtool timeline <project> post <json|@file> add a post, or replace the one with its id", @@ -62,7 +78,7 @@ export const TIMELINE_USAGE = [ ].join("\n"); const VERBS = ["ls", "insert", "move", "remove", "duplicate", "post", "post-remove", "teaser", "undo"]; -const VALUED = new Set(["--after", "--to", "--at", "--id", "--title", "--date", "--quote", "--cite", "--cite-url"]); +const VALUED = new Set(["--after", "--to", "--at", "--id", "--section", "--title", "--stream-title", "--date", "--quote", "--cite", "--cite-url"]); class CliError extends Error {} @@ -155,11 +171,100 @@ const noted = (editNotes) => ? ` edit noted for ${editNotes.generatedBy} — port it into the generator's inputs` : ""; -/** The attribution flags of an insert, as updateClip's patch (an empty value deletes, as in `umtool window`). */ -export function attributionPatch(flags) { +const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; +/** The ways a deck title is written as a date, each with its test and its writer. */ +const DATE_TITLE_STYLES = [ + { name: "D Mon YYYY", re: new RegExp(`^\\d{1,2} (${MONTHS.join("|")}) \\d{4}$`), fmt: (y, m, d) => `${d} ${MONTHS[m - 1]} ${y}` }, + { name: "Mon D, YYYY", re: new RegExp(`^(${MONTHS.join("|")}) \\d{1,2}, \\d{4}$`), fmt: (y, m, d) => `${MONTHS[m - 1]} ${d}, ${y}` }, + { name: "YYYY-MM-DD", re: /^\d{4}-\d{2}-\d{2}$/, fmt: (y, m, d) => `${y}-${String(m).padStart(2, "0")}-${String(d).padStart(2, "0")}` }, +]; + +/** + * How this manifest writes an attributed clip (see the top of the file): + * whether the deck draws `onscreen.title`, and whether the cut's deck titles + * are dates -- most of its titled clips' titles in one of DATE_TITLE_STYLES -- + * and in which style. Pure. + * + * @param {Record<string, any>} manifest + * @returns {{ deck: boolean, dateTitles: { name: string, format: (iso: string) => string } | null }} + */ +export function insertConvention(manifest) { + const deck = deckOn(manifest?.render); + if (!deck) return { deck, dateTitles: null }; + const titles = (manifest.timeline ?? []) + .filter((e) => e?.type === "clip" && typeof e.onscreen?.title === "string") + .map((e) => e.onscreen.title.trim()); + let best = null; + for (const st of DATE_TITLE_STYLES) { + const n = titles.filter((t) => st.re.test(t)).length; + if (n > titles.length / 2 && (!best || n > best.n)) best = { st, n }; + } + if (!best) return { deck, dateTitles: null }; + const st = best.st; + return { + deck, + dateTitles: { + name: st.name, + format: (iso) => { + const [y, m, d] = iso.split("-").map(Number); + return st.fmt(y, m, d); + }, + }, + }; +} + +/** + * The entry an insert writes: the spec's clip, the section and locks, and -- + * from the clip it goes after, as the clip editor's add takes them -- its + * section, and (the same recording) its deck title and its citation link + * moved to the new second. Pure. + * + * @param {{ channel: string, video: string, start: number, end: number }} clip + * @param {Record<string, any> | null} like the clip the insert goes after (or the first, for `-`) + * @param {{ id?: string | null, section?: number | null, lock?: boolean, lockEnd?: boolean }} o + */ +export function insertedClip(clip, like, { id = null, section = null, lock = false, lockEnd = false } = {}) { + const same = !!like && like.type === "clip" && like.video === clip.video; + const cite = Math.floor(clip.start); + const sec = section ?? (like && Number.isInteger(like.section) ? like.section : null); + const title = same && typeof like.onscreen?.title === "string" && like.onscreen.title.trim() ? like.onscreen.title.trim() : null; + return { + type: "clip", + ...(id ? { id } : {}), + ...clip, + cite, + ...(same && typeof like.citeUrl === "string" && like.citeUrl ? { citeUrl: citeUrlAt(like.citeUrl, cite) } : {}), + ...(sec !== null ? { section: sec } : {}), + ...(title ? { onscreen: { title } } : {}), + ...(lock ? { lock: true } : {}), + ...(lockEnd ? { lockEnd: true } : {}), + }; +} + +/** The clip an insert after `after` takes its section from: that entry when it is a clip, else the nearest clip before it (after it, at the start). */ +export function insertNeighbour(timeline, after, at = null) { + const list = Array.isArray(timeline) ? timeline : []; + const clips = (xs) => xs.filter((e) => e?.type === "clip"); + if (after === null) return clips(list)[0] ?? null; + const i = at !== null && list[at]?.id === after ? at : list.findIndex((e) => e?.id === after); + if (i < 0) return null; + return clips(list.slice(0, i + 1)).at(-1) ?? clips(list.slice(i + 1))[0] ?? null; +} + +/** + * The attribution flags of an insert, as updateClip's patch (an empty value + * deletes, as in `umtool window`). `convention` (insertConvention) puts + * --title where the deck reads it, and a date where a dated deck title goes. + * + * @param {Map<string, string | true>} flags + * @param {ReturnType<typeof insertConvention>} [convention] + */ +export function attributionPatch(flags, convention = { deck: false, dateTitles: null }) { + /** @type {Record<string, any>} */ const patch = {}; for (const [flag, key] of [ - ["--title", "title"], + ["--title", convention.deck ? "onscreenTitle" : "title"], + ["--stream-title", "title"], ["--date", "date"], ["--quote", "quote"], ["--cite", "cite"], @@ -172,6 +277,15 @@ export function attributionPatch(flags) { if (patch.date && !isCalendarDate(String(patch.date).trim())) { throw new CliError(`date must be a real calendar date written YYYY-MM-DD (got \`${patch.date}\`)`); } + // The deck's words: --title, else a dated deck title from --date. + const deckTitle = + patch.onscreenTitle !== undefined + ? String(patch.onscreenTitle).trim() + : convention.dateTitles && patch.date + ? convention.dateTitles.format(String(patch.date).trim()) + : undefined; + delete patch.onscreenTitle; + if (deckTitle !== undefined) patch.onscreen = deckTitle ? { title: deckTitle } : null; if (patch.cite !== undefined && patch.cite !== "") { const n = Number(patch.cite); if (!Number.isFinite(n) || n < 0) throw new CliError("--cite must be a number of seconds ≥ 0"); @@ -234,16 +348,24 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) => switch (verb) { case "insert": { if (!flags.has("--after")) throw new CliError("insert needs --after <id> (or --after - for the start)"); - const after = String(flags.get("--after")); + const afterArg = String(flags.get("--after")); + const after = afterArg === "-" || afterArg === "" ? null : afterArg; const spec = need(rest[0], "a clip: <channel>/<video>@<start>-<end>"); - const patch = attributionPatch(flags); - let entry = spec; - if (flags.has("--id")) { - const c = parseClipSpec(spec); - if (!c) throw new CliError("a clip is <channel>/<video>@<start>-<end> in seconds"); - entry = { type: "clip", id: String(flags.get("--id")), ...c }; - } - ({ result, editNotes } = await write((token) => insertEntry(project.dir, after === "-" || after === "" ? null : after, entry, { token, at }))); + const convention = insertConvention(manifest); + const patch = attributionPatch(flags, convention); + const c = parseClipSpec(spec); + if (!c) throw new Error("a clip is <channel>/<video>@<start>-<end> in seconds"); + const section = intFlag(flags, "--section"); + if (section !== null && section < 0) throw new CliError("--section is a section's number, 0 or more"); + const entry = insertedClip(c, insertNeighbour(manifest.timeline, after, at), { + id: flags.has("--id") ? String(flags.get("--id")) : null, + section, + lock: flags.has("--lock"), + lockEnd: flags.has("--lock-end"), + }); + // A deck title the clip already took from the clip before it is not a change to write. + if (patch.onscreen !== undefined && JSON.stringify(patch.onscreen) === JSON.stringify(entry.onscreen ?? null)) delete patch.onscreen; + ({ result, editNotes } = await write((token) => insertEntry(project.dir, after, entry, { token, at }))); if (flags.has("--id") && result.id !== flags.get("--id")) { result.idTaken = String(flags.get("--id")); } @@ -331,12 +453,16 @@ function summaryOf(verb, r, attribution) { const e = attribution ?? r.entry; const head = `inserted ${r.id} at ${r.at}: ${e.channel ? `${e.channel}/` : ""}${e.video}@${e.start}-${e.end}`; const taken = r.idTaken ? `\n (${r.idTaken} was taken: it is ${r.id})` : ""; + const placed = + (e.section !== undefined ? `\n section ${e.section}` : "") + + (e.lock || e.lockEnd ? `${e.section !== undefined ? "," : "\n "} ${["lock", "lockEnd"].filter((k) => e[k]).join(", ")}` : "") + + (e.onscreen?.title ? `\n deck title: ${e.onscreen.title}` : ""); const attr = attribution ? `\n header: ${attribution.title ?? "(the record's own title)"} · ${attribution.date ?? "(the record's upload date)"} @ ${attribution.cite ?? attribution.start}` + (attribution.quote ? `\n quote: ${attribution.quote}` : "") + (attribution.citeUrl ? `\n QR: ${attribution.citeUrl}` : "") : ""; - return head + taken + attr; + return head + taken + placed + attr; } case "move": return `moved ${r.id}: ${r.from} -> ${r.to}`; diff --git a/umtool/lib/report/timelineCli.test.mjs b/umtool/lib/report/timelineCli.test.mjs @@ -11,7 +11,7 @@ import test from "node:test"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-timeline-cli-")); process.env.REPORTS_DIR = ROOT; -const { attributionPatch, splitTimelineArgs, timelineCommand, timelineLines, timelineRows } = await import("./timelineCli.mjs"); +const { attributionPatch, insertConvention, insertNeighbour, splitTimelineArgs, timelineCommand, timelineLines, timelineRows } = await import("./timelineCli.mjs"); const MANIFEST = { schemaVersion: 1, @@ -104,6 +104,69 @@ test("insert: a clip after an id (or `-`, the start), its attribution through up assert.equal(m.timeline.length, 5); }); +// The shape of a real deck cut (polemic-huck, 2026-10-26): every clip carries +// its channel, a citeUrl, a section, `lock`, and its deck title in +// `onscreen.title` -- a date, "24 Oct 2020" -- with no top-level title or date. +const DECK_CUT = { + schemaVersion: 1, + slug: "polemic", + title: "Polemic", + generatedBy: "polemics/video/make-videos.py polemic", + provenance: { channelSlug: "chan", siteOrigin: "https://example.test" }, + render: { width: 1920, height: 1080, fps: 30, chrome: { engine: "hyperframes", layout: "deck", deck: { qr: { links: "original" } } } }, + timeline: [ + { type: "clip", id: "arrive", video: "yt1", channel: "chan", start: 43.46, end: 62.05, cite: 42, quote: "he'll be here wednesday", onscreen: { title: "24 Oct 2020" }, section: 0, sectionEnter: true, citeUrl: "https://example.test/?v=chan%2Fyt1&t=42", lock: true, verdict: "confirmed" }, + { type: "clip", id: "fed", video: "v5slug", channel: "chan-rumble", start: 6141.71, end: 6155.91, cite: 6141, quote: "will not get fed", onscreen: { title: "2 Dec 2024" }, section: 1, sectionEnter: true, citeUrl: "https://example.test/?v=chan-rumble%2Fv5embed&t=6141", lock: true }, + { type: "clip", id: "first", video: "v6slug", channel: "chan-rumble", start: 171.92, end: 212.16, cite: 171, quote: "a massive seizure", onscreen: { title: "27 Feb 2025" }, section: 2, sectionEnter: true, citeUrl: "https://example.test/?v=chan-rumble%2Fv6embed&t=171", lock: true, lockEnd: true }, + ], +}; + +test("insertConvention: the deck draws onscreen.title; a cut whose deck titles are dates names the style", () => { + const c = insertConvention(DECK_CUT); + assert.equal(c.deck, true); + assert.equal(c.dateTitles?.name, "D Mon YYYY"); + assert.equal(c.dateTitles?.format("2025-03-07"), "7 Mar 2025"); + assert.deepEqual(insertConvention(MANIFEST), { deck: false, dateTitles: null }); + const worded = { ...DECK_CUT, timeline: DECK_CUT.timeline.map((e, i) => ({ ...e, onscreen: { title: i ? `Words ${i}` : "24 Oct 2020" } })) }; + assert.equal(insertConvention(worded).dateTitles, null, "one date among words is not the convention"); + assert.equal(insertNeighbour(DECK_CUT.timeline, "fed")?.id, "fed"); + assert.equal(insertNeighbour(DECK_CUT.timeline, null)?.id, "arrive"); + assert.equal(insertNeighbour([{ type: "card", id: "k" }, ...DECK_CUT.timeline], "k")?.id, "arrive"); +}); + +test("insert into a deck cut: --title is the deck's title, a dated cut's --date is one too, the section is the clip before's, --lock/--lock-end on the clip", async () => { + const dir = path.join(ROOT, "deck-cut"); + await mkdir(dir, { recursive: true }); + await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(DECK_CUT, null, 2) + "\n"); + const { lines, run } = runner(); + // --date only, in a cut of dated deck titles: the deck title in the cut's own format. + assert.equal(await run("deck-cut", "insert", "--after", "fed", "chan-rumble/v5x@100-112.5", "--id", "fed-b", "--date", "2024-12-09", "--lock", "--lock-end", "--quote", "more of it"), 0, lines.join("\n")); + let m = await read(dir); + assert.deepEqual(m.timeline.map((e) => e.id), ["arrive", "fed", "fed-b", "first"]); + assert.deepEqual(m.timeline[2], { + type: "clip", id: "fed-b", channel: "chan-rumble", video: "v5x", start: 100, end: 112.5, cite: 100, + section: 1, lock: true, lockEnd: true, onscreen: { title: "9 Dec 2024" }, date: "2024-12-09", quote: "more of it", + }); + assert.equal(m.timeline[2].title, undefined, "no top-level title: under the deck that is the stream's"); + assert.ok(lines.some((l) => /section 1, lock, lockEnd/.test(l)), lines.join("\n")); + assert.ok(lines.some((l) => /deck title: 9 Dec 2024/.test(l)), lines.join("\n")); + // --title wins; --section; --stream-title is the top-level title. + assert.equal(await run("deck-cut", "insert", "--after", "arrive", "chan/yt9@5-9", "--id", "aside", "--title", "Oct 2020, again", "--stream-title", "The stream", "--date", "2020-10-30", "--section", "0"), 0, lines.join("\n")); + m = await read(dir); + const aside = m.timeline.find((e) => e.id === "aside"); + assert.deepEqual([aside.onscreen, aside.title, aside.date, aside.section, aside.lock], [{ title: "Oct 2020, again" }, "The stream", "2020-10-30", 0, undefined]); + // The same recording as the clip before: its deck title and its citation link at the new second. + assert.equal(await run("deck-cut", "insert", "--after", "first", "chan-rumble/v6slug@300-310", "--id", "first-b"), 0, lines.join("\n")); + m = await read(dir); + const fb = m.timeline.find((e) => e.id === "first-b"); + assert.deepEqual([fb.onscreen, fb.section, fb.citeUrl, fb.lock], [{ title: "27 Feb 2025" }, 2, "https://example.test/?v=chan-rumble%2Fv6embed&t=300", undefined]); + // A section that is not a number refuses with nothing written. + const before = await read(dir); + assert.equal(await run("deck-cut", "insert", "--after", "first", "chan/yt1@1-5", "--section", "two"), 2); + assert.equal(await run("deck-cut", "insert", "--after", "first", "chan/yt1@1-5", "--section", "-1"), 2); + assert.deepEqual(await read(dir), before); +}); + test("move, duplicate, remove, and undo — each refused only for what it breaks", async () => { const dir = await project("move"); const { lines, run } = runner();