Archilyzer · Source

archilyzer

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

commit ce730189ca56b8931abcdddfb3893ce28a2cc4ff
parent 80ee64bd70befb4f5598a8c5750f79c01fae36c3
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sat, 17 Oct 2026 16:47:16 -0400

umtool: report-to-video montage-styles.mjs — the named montage styles (the shared interface with the take maker)

MONTAGE_STYLES (straight, flash-count, accelerate, stutter, wall-finale, whip-years): a plain-words label and
summary and an RFC 7386 merge patch under render.montage that names every montage key, so one style over
another leaves exactly the second. montageStyle(name) is a deep copy; mergePatch and applyMontageStyle; a
list/apply CLI. The renderer that reads render.montage follows.

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

Diffstat:
Aumtool/report-to-video/montage-styles.mjs | 164+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/montage-styles.test.mjs | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 287 insertions(+), 0 deletions(-)

diff --git a/umtool/report-to-video/montage-styles.mjs b/umtool/report-to-video/montage-styles.mjs @@ -0,0 +1,164 @@ +#!/usr/bin/env node +// THE NAMED MONTAGE STYLES — `render.montage` settings worth auditioning, by name. +// +// node umtool/report-to-video/montage-styles.mjs list [--json] +// node umtool/report-to-video/montage-styles.mjs apply <style> <manifest.json> [--out <file>] +// +// Each style is an RFC 7386 JSON merge patch on `video.manifest.json`. Every +// style sets EVERY `render.montage` key (a feature it does not use is `null` +// or `false`), so applying one style over another leaves exactly the second: +// a merge patch keeps any key it does not name, and a stale `stutter` from the +// last audition would otherwise ride along. Nothing else in the manifest is +// touched. +// +// The shared interface with umtool's take maker (release 33 M1), which reads it +// through a dynamic import and works without it: +// +// MONTAGE_STYLES: Record<string, { label: string, summary: string, patch: object }> +// montageStyle(name) -> a deep copy of one style, or null +// +// The keys themselves are `montage.mjs` (validateMontage says what each takes) +// and README "Manifest shape", `render.montage`. + +import { readFile, writeFile } from "node:fs/promises"; + +/** Every `render.montage` key, off: the base each style patches over. */ +const OFF = Object.freeze({ + tighten: null, + phrasePad: null, + cut: "hard", + flashColor: null, + counter: null, + punch: null, + stutter: null, + ramp: null, + wall: null, + yearStamp: false, +}); + +const chip = { style: "chip", position: "top-left", of: false, showDate: true, showSource: true }; + +const style = (label, summary, montage) => ({ + label, + summary, + patch: { render: { montage: { ...OFF, tighten: "phrase", ...montage } } }, +}); + +/** + * The styles, in the order a take form lists them. Labels and summaries are + * plain words: they are what a person reads when choosing one. + */ +export const MONTAGE_STYLES = Object.freeze({ + straight: style( + "Straight", + "Each clip cut to the phrase, hard cuts, a small running count with the date and the source.", + { counter: chip }, + ), + "flash-count": style( + "Flash and count", + "A white flash on every cut and a big number that slams in on each clip.", + { cut: "flash", counter: { style: "big", position: "bottom-left", of: false, showDate: true, showSource: false } }, + ), + accelerate: style( + "Accelerate", + "Clips get shorter toward the end, a slow zoom on each, tally marks adding up.", + { + ramp: { from: 4, to: 1.4 }, + punch: { mode: "drift", scale: 1.08, anchor: "upper" }, + counter: { style: "tally", position: "top-left", of: false, showDate: true, showSource: false }, + }, + ), + stutter: style( + "Stutter", + "Every fifth clip repeats the end of the phrase, and each clip punches in as the phrase starts.", + { + stutter: { every: 5, times: 3, length: 0.35, step: 0.04 }, + punch: { mode: "snap", scale: 1.15, anchor: "upper" }, + counter: chip, + }, + ), + "wall-finale": style( + "Wall finale", + "Straight cuts, then a wall of sixteen clips filling in, all saying it together at the end.", + { counter: chip, wall: { at: "end", tiles: 16, build: 8, year: true } }, + ), + "whip-years": style( + "Whip and years", + "Fast sliding cuts, the year large in a corner when it changes, a small running count.", + { cut: "whip", yearStamp: true, counter: { ...chip, showDate: true, showSource: false } }, + ), +}); + +/** The style names, in their listed order. */ +export const MONTAGE_STYLE_NAMES = Object.freeze(Object.keys(MONTAGE_STYLES)); + +/** One style, as a deep copy (a caller may change it freely), or null. */ +export function montageStyle(name) { + const s = Object.hasOwn(MONTAGE_STYLES, name) ? MONTAGE_STYLES[name] : null; + return s ? structuredClone(s) : null; +} + +const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v); + +/** + * RFC 7386 JSON merge patch: `patch` applied to `target`, as a new value + * (neither argument is changed). An object patch merges key by key, `null` + * removes a key, and anything else replaces the target outright. + */ +export function mergePatch(target, patch) { + if (!isObject(patch)) return structuredClone(patch); + const out = isObject(target) ? structuredClone(target) : {}; + for (const [k, v] of Object.entries(patch)) { + if (v === null) delete out[k]; + else out[k] = mergePatch(out[k], v); + } + return out; +} + +/** A manifest with one named style applied. Throws, naming the styles, on an unknown name. */ +export function applyMontageStyle(manifest, name) { + const s = montageStyle(name); + if (!s) throw new Error(`no montage style "${name}" — the styles are ${MONTAGE_STYLE_NAMES.join(", ")}`); + return mergePatch(manifest, s.patch); +} + +async function main(argv) { + const [cmd, ...rest] = argv; + if (cmd === "list") { + if (rest.includes("--json")) { + process.stdout.write(`${JSON.stringify(MONTAGE_STYLES, null, 2)}\n`); + return 0; + } + for (const [name, s] of Object.entries(MONTAGE_STYLES)) process.stdout.write(`${name.padEnd(12)} ${s.label} — ${s.summary}\n`); + return 0; + } + if (cmd === "apply") { + const [name, manifestPath] = rest.filter((a, i) => !a.startsWith("--") && rest[i - 1] !== "--out"); + const oi = rest.indexOf("--out"); + const out = oi >= 0 ? rest[oi + 1] : null; + if (!name || !manifestPath) { + process.stderr.write("usage: montage-styles.mjs apply <style> <manifest.json> [--out <file>]\n"); + return 2; + } + const next = applyMontageStyle(JSON.parse(await readFile(manifestPath, "utf8")), name); + const text = `${JSON.stringify(next, null, 2)}\n`; + if (out) await writeFile(out, text, "utf8"); + else process.stdout.write(text); + return 0; + } + process.stderr.write( + "usage: montage-styles.mjs list [--json]\n" + + " montage-styles.mjs apply <style> <manifest.json> [--out <file>]\n", + ); + return 2; +} + +if (import.meta.url === `file://${process.argv[1]}`) { + main(process.argv.slice(2)).then( + (code) => process.exit(code), + (err) => { + process.stderr.write(`${err?.message ?? err}\n`); + process.exit(1); + }, + ); +} diff --git a/umtool/report-to-video/montage-styles.test.mjs b/umtool/report-to-video/montage-styles.test.mjs @@ -0,0 +1,123 @@ +// The named montage styles (release 33 M3): the shared interface with umtool's +// take maker -- names, plain-words labels, merge patches under render.montage, +// deep copies -- and RFC 7386 merge patching. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +import { applyMontageStyle, mergePatch, MONTAGE_STYLE_NAMES, MONTAGE_STYLES, montageStyle } from "./montage-styles.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); + +test("MONTAGE_STYLES: at least the six named styles, each a label, a summary and a patch under render.montage", () => { + for (const name of ["straight", "flash-count", "accelerate", "stutter", "wall-finale", "whip-years"]) { + assert.ok(MONTAGE_STYLES[name], name); + } + assert.ok(MONTAGE_STYLE_NAMES.length >= 6); + for (const [name, s] of Object.entries(MONTAGE_STYLES)) { + assert.equal(typeof s.label, "string", name); + assert.ok(s.label.length > 0 && s.label.length <= 40, name); + assert.ok(s.summary.length > 10 && !/[{}`]/.test(s.summary), `${name}: plain words`); + assert.deepEqual(Object.keys(s.patch), ["render"], name); + assert.deepEqual(Object.keys(s.patch.render), ["montage"], name); + assert.equal(s.patch.render.montage.tighten, "phrase", name); + } +}); + +test("every style names every montage key, so one style over another leaves exactly the second", () => { + const keys = (s) => Object.keys(s.patch.render.montage).sort(); + const first = keys(MONTAGE_STYLES.straight); + for (const s of Object.values(MONTAGE_STYLES)) assert.deepEqual(keys(s), first); + const base = { slug: "x", render: { fps: 30, montage: { stutter: { every: 2, times: 4 }, junkKeepsNothing: 1 } }, timeline: [] }; + for (const a of MONTAGE_STYLE_NAMES) { + for (const b of MONTAGE_STYLE_NAMES) { + assert.deepEqual( + applyMontageStyle(applyMontageStyle(base, a), b).render.montage, + { ...applyMontageStyle({ render: {} }, b).render.montage, junkKeepsNothing: 1 }, + `${a} then ${b}`, + ); + } + } +}); + +test("the styles say what the brief asks of each", () => { + const m = (n) => applyMontageStyle({}, n).render.montage; + assert.equal(m("straight").cut, "hard"); + assert.equal(m("straight").counter.style, "chip"); + assert.equal(m("flash-count").cut, "flash"); + assert.equal(m("flash-count").counter.style, "big"); + assert.deepEqual(m("accelerate").ramp, { from: 4, to: 1.4 }); + assert.equal(m("accelerate").punch.mode, "drift"); + assert.equal(m("accelerate").counter.style, "tally"); + assert.equal(m("stutter").stutter.every, 5); + assert.equal(m("stutter").punch.mode, "snap"); + assert.equal(m("wall-finale").wall.at, "end"); + assert.equal(m("wall-finale").wall.tiles, 16); + assert.equal(m("wall-finale").counter.style, "chip"); + assert.equal(m("whip-years").cut, "whip"); + assert.equal(m("whip-years").yearStamp, true); + assert.equal(m("whip-years").counter.style, "chip"); + // Off is absent (null removed the key) or false. + assert.equal("wall" in m("straight"), false); + assert.equal(m("straight").yearStamp, false); +}); + +test("montageStyle: a deep copy, or null", () => { + const a = montageStyle("straight"); + a.patch.render.montage.cut = "whip"; + a.label = "changed"; + assert.equal(MONTAGE_STYLES.straight.patch.render.montage.cut, "hard"); + assert.equal(MONTAGE_STYLES.straight.label, "Straight"); + assert.equal(montageStyle("nope"), null); + assert.equal(montageStyle("toString"), null, "not an inherited key"); + assert.throws(() => applyMontageStyle({}, "nope"), /no montage style "nope" — the styles are straight, /); +}); + +test("mergePatch: RFC 7386 -- objects merge, null removes, anything else replaces; inputs untouched", () => { + const target = { a: "b", c: { d: "e", f: "g" }, list: [1, 2] }; + const patch = { a: "z", c: { f: null, h: 1 }, list: [3], n: { deep: { x: 1 } } }; + assert.deepEqual(mergePatch(target, patch), { a: "z", c: { d: "e", h: 1 }, list: [3], n: { deep: { x: 1 } } }); + assert.deepEqual(target, { a: "b", c: { d: "e", f: "g" }, list: [1, 2] }); + // The RFC's own examples. + assert.deepEqual(mergePatch({ a: "b" }, { a: "c" }), { a: "c" }); + assert.deepEqual(mergePatch({ a: "b" }, { b: "c" }), { a: "b", b: "c" }); + assert.deepEqual(mergePatch({ a: "b" }, { a: null }), {}); + assert.deepEqual(mergePatch({ a: ["b"] }, { a: "c" }), { a: "c" }); + assert.deepEqual(mergePatch({ a: "c" }, { a: ["b"] }), { a: ["b"] }); + assert.deepEqual(mergePatch({ a: { b: "c" } }, { a: { b: "d", c: null } }), { a: { b: "d" } }); + assert.deepEqual(mergePatch(["a", "b"], ["c", "d"]), ["c", "d"]); + assert.deepEqual(mergePatch({ a: "b" }, ["c"]), ["c"]); + assert.equal(mergePatch({ a: "foo" }, null), null); + assert.deepEqual(mergePatch([1, 2], { a: "b", c: null }), { a: "b" }); +}); + +test("the CLI: list, and apply to a file", () => { + const list = spawnSync(process.execPath, [path.join(HERE, "montage-styles.mjs"), "list"]); + assert.equal(list.status, 0, String(list.stderr)); + assert.match(String(list.stdout), /^straight\s+Straight — /m); + const json = spawnSync(process.execPath, [path.join(HERE, "montage-styles.mjs"), "list", "--json"]); + assert.deepEqual(JSON.parse(String(json.stdout)), JSON.parse(JSON.stringify(MONTAGE_STYLES))); + const dir = mkdtempSync(path.join(tmpdir(), "montage-styles-")); + try { + const src = path.join(dir, "video.manifest.json"); + const out = path.join(dir, "styled.json"); + writeFileSync(src, JSON.stringify({ slug: "x", render: { fps: 30 }, timeline: [] })); + const r = spawnSync(process.execPath, [path.join(HERE, "montage-styles.mjs"), "apply", "flash-count", src, "--out", out]); + assert.equal(r.status, 0, String(r.stderr)); + const got = JSON.parse(readFileSync(out, "utf8")); + assert.equal(got.render.fps, 30); + assert.equal(got.render.montage.cut, "flash"); + assert.equal(JSON.parse(readFileSync(src, "utf8")).render.montage, undefined, "the source is untouched"); + const bad = spawnSync(process.execPath, [path.join(HERE, "montage-styles.mjs"), "apply", "nope", src]); + assert.equal(bad.status, 1); + assert.match(String(bad.stderr), /no montage style "nope"/); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +});