Archilyzer · Source

archilyzer

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

commit cc24a9a97722239decbaacacd783a40071f221c5
parent 923da42d00776d6f63d1c174e30c7d78abc25767
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 15 Oct 2026 17:17:09 -0400

umtool: a frame scan → a draft supercut (release 30, lane P) — report-to-video/frames-cut.mjs (pure, ledger-totals' pattern): the scan's events as clips (a window around each, widened to the cues' sentence edges within widen's budgets, overlapping windows merged, at most 20, the most important kept), each clip's on-screen subtitle the running stats there, and the `frameScan` overlay block (the stats at each clip's start and every change inside it) a stats region can draw; `frameTotals` reads the running stats at any second; `umtool new <slug> --from <channel>/<id> --seed frames` scaffolds the project from the video's frame-scan.poker.json; no render

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

Diffstat:
Mumtool/bin/umtool.mjs | 10++++++----
Mumtool/lib/projects/scaffold.mjs | 46++++++++++++++++++++++++++++++++++++++++++++--
Aumtool/lib/scaffold-frames.test.mjs | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/frames-cut.mjs | 156+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/frames-cut.test.mjs | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/package.json | 1+
6 files changed, 343 insertions(+), 6 deletions(-)

diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -33,7 +33,7 @@ // --deck adds the on-screen deck to a cut with none before the flips // umtool index [--rebuild] [--prune] [--since MS] [--json] // umtool new <slug> [--kind report-video] [--from <report.md>|<share URL>|<channel>/<id>] -// [--site-origin URL] [--seed chapters] [--brand archilyzer-media] +// [--site-origin URL] [--seed chapters|frames] [--brand archilyzer-media] // umtool doctor [--json] exit 1 if the report pipeline is missing a tool // or the media root is set and not there // umtool storage [move-out|move-back <project>|--all] [--dry-run] [--json] @@ -691,7 +691,9 @@ function usage() { " each draft a report-draft job on --model (else its route); a draft that fails does not stop it;", " --deck adds a step before the flips: the minimal on-screen deck on a cut with none", " umtool index [--rebuild] [--prune] [--since MS] [--json]", - " umtool new <slug> [--from <report.md>|<share URL>|<channel>/<id>] [--site-origin URL] [--seed chapters]", + " umtool new <slug> [--from <report.md>|<share URL>|<channel>/<id>] [--site-origin URL] [--seed chapters|frames]", + " --seed frames: a draft supercut from the video's frame scan (pnpm ops frame-scan) — a clip", + " around each event, the running stats as each clip's subtitle and the frameScan overlay block", " [--brand archilyzer-media] render.brand: the report-to-video brand preset", " umtool doctor [--json] exit 1 if the report pipeline is missing a tool", " or the media root is set and not there; the roots, and a leftover old cache", @@ -1087,7 +1089,7 @@ async function cmdNew() { die( "usage: umtool new <slug> [--kind report-video] [--title T]\n" + " [--from <sweep-report.md> | <share URL> | <channel>/<videoId>]\n" + - " [--site-origin <url>] [--seed chapters] [--brand archilyzer-media]", + " [--site-origin <url>] [--seed chapters|frames] [--brand archilyzer-media]", ); } const kind = val("--kind") ?? "report-video"; @@ -1112,7 +1114,7 @@ async function cmdNew() { console.log(`${r.dir}`); if (r.seeded) { - console.log(` video.manifest.json ${r.seeded} clip(s) SEEDED from digest chapters — review each`); + console.log(` video.manifest.json ${r.seeded} clip(s) SEEDED from ${val("--seed") === "frames" ? "the frame scan's events" : "digest chapters"} — review each`); } else { console.log(` video.manifest.json an EMPTY timeline — see README.md`); } diff --git a/umtool/lib/projects/scaffold.mjs b/umtool/lib/projects/scaffold.mjs @@ -6,6 +6,7 @@ import { mkdir, readFile, stat, writeFile } from "node:fs/promises"; import path from "node:path"; import { BRAND_IDS } from "umtool-report-to-video/brand-ids"; +import { framesCut } from "umtool-report-to-video/frames-cut"; import { GLOBAL_CHANNELS_DIR, MANIFEST_NAME } from "./report.mjs"; export const SLUG_RE = /^[a-z0-9][a-z0-9-]*$/; @@ -171,6 +172,23 @@ export async function chaptersAsClips({ channelsDir, channel, video }) { } /** + * A frame scan's events, as a draft supercut (release 30): the video's + * `frame-scan.<profile>.json` (`pnpm ops frame-scan`) through framesCut — + * a clip around each event, cut on the cues' sentence edges — and the scan's + * running stats as the manifest's `frameScan` overlay block. + */ +export async function framesAsClips({ channelsDir, channel, video, profile = "poker" }) { + const dir = path.join(channelsDir, channel, "data", video); + const scan = await readJson(path.join(dir, `frame-scan.${profile}.json`)); + if (!scan) throw new Error(`${channel}/${video} has no frame-scan.${profile}.json — run pnpm ops frame-scan first`); + const cuesDoc = await readJson(path.join(dir, "transcript.cues.json")); + const cues = Array.isArray(cuesDoc?.cues) + ? cuesDoc.cues.filter((c) => c && Number.isFinite(c.start) && Number.isFinite(c.end) && typeof c.text === "string").sort((a, b) => a.start - b.start) + : null; + return framesCut(scan, { channel, video, cues }); +} + +/** * Write the project. Refuses an existing directory and a slug that will not * route; everything else it cannot know is written EMPTY so `check` blocks. * @@ -196,8 +214,8 @@ export async function scaffoldReportVideo({ root, slug, title, from = null, site `could not tell what --from is: "${from}" is neither a .md report, a viewer share URL (…/?v=<channel>%2F<id>&t=<s>), nor a <channel>/<videoId> ref`, ); } - if (seed && seed !== "chapters") throw new Error(`--seed must be "chapters", not "${seed}"`); - if (seed && src?.kind !== "video") throw new Error("--seed chapters needs --from to be a video ref"); + if (seed && seed !== "chapters" && seed !== "frames") throw new Error(`--seed must be "chapters" or "frames", not "${seed}"`); + if (seed && src?.kind !== "video") throw new Error(`--seed ${seed} needs --from to be a video ref`); if (timeline && (seed || src)) throw new Error("a board's timeline is the whole timeline: give it without --from or --seed"); if (timeline && (!Array.isArray(timeline) || !timeline.every(isBoardClip))) { throw new Error("a timeline is a list of clips, each { type: \"clip\", id, channel, video, start, end }"); @@ -239,6 +257,17 @@ export async function scaffoldReportVideo({ root, slug, title, from = null, site if (!clips.length) notes.push("the digest has no enabled chapters, so the timeline is empty"); } + let framesSeeded = false; + if (seed === "frames") { + const cut = await framesAsClips({ channelsDir, channel: src.channel, video: src.video }); + doc.timeline = cut.timeline; + doc.frameScan = cut.frameScan; + seeded = cut.timeline.length; + framesSeeded = true; + if (cut.skipped) notes.push(`${cut.skipped} lesser event(s) left out (the most important kept)`); + if (!cut.timeline.length) notes.push("the frame scan found no events worth a clip, so the timeline is empty"); + } + if (timeline) { doc.timeline = timeline.map((c) => ({ ...c })); seeded = doc.timeline.length; @@ -268,6 +297,19 @@ export async function scaffoldReportVideo({ root, slug, title, from = null, site "", ...doc.timeline.map((c) => `- [ ] ${c.id} ${c.channel}/${c.video} ${c.start}–${c.end} ${String(c.quote ?? "").slice(0, 80)}`), ); + } else if (seeded && framesSeeded) { + lines.push( + "## Clips seeded from the frame scan — review each", + "", + "Every window below is a moment the frame scan derived (a double-up, a bust,", + "the final table…) with a margin either side, widened to the transcript's", + "sentence edges. The scan reads a model's readings of sampled frames, so an", + "event can be wrong: check each in the bench before you keep it. Each clip's", + "on-screen subtitle is the running stats there; `frameScan.overlay` holds them", + "for a stats overlay (not rendered yet).", + "", + ...doc.timeline.map((c) => `- [ ] ${c.id} ${c.channel}/${c.video} ${c.start}–${c.end} ${c.onscreen?.title ?? ""}: ${c.onscreen?.subtitle ?? ""}`), + ); } else if (seeded) { lines.push( "## Clips seeded from digest chapters — review each", diff --git a/umtool/lib/scaffold-frames.test.mjs b/umtool/lib/scaffold-frames.test.mjs @@ -0,0 +1,55 @@ +// `umtool new <slug> --from <channel>/<id> --seed frames` (release 30, lane P): +// the draft supercut from a synthetic frame-scan sidecar in a temp tree. + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { scaffoldReportVideo } from "./projects/scaffold.mjs"; + +const SCAN = { + format: "archilyzer-frame-scan", + profile: "poker", + source: { savedVideo: "source-media.mp4", durationSeconds: 300 }, + sampling: { everySeconds: 10, from: 0, to: 300 }, + derived: { + tournaments: [{ key: "synthetic cup", name: "Synthetic Cup", from: 30, to: 200, series: { stack: [[30, 20000], [90, 41000], [180, 0]], playersLeft: [[30, 85]] }, facts: {} }], + events: [ + { t: 90, kind: "double-up", detail: "20,000 → 41,000 chips (2.1×)", source: "series" }, + { t: 180, kind: "bust", detail: "out from 41,000 chips", source: "series" }, + ], + segments: [], + flags: [], + }, +}; + +test("--seed frames: a clip per event, the stats as subtitles, the overlay block, a README checklist", async () => { + const tmp = await mkdtemp(path.join(os.tmpdir(), "umtool-frames-seed-")); + try { + const channelsDir = path.join(tmp, "channels"); + const dir = path.join(channelsDir, "synth-poker", "data", "synthstream1"); + await mkdir(dir, { recursive: true }); + await writeFile(path.join(dir, "frame-scan.poker.json"), JSON.stringify(SCAN)); + await writeFile(path.join(dir, "transcript.cues.json"), JSON.stringify({ cues: [{ start: 66, end: 70, text: "Here we go." }, { start: 70, end: 80, text: "all in" }] })); + const r = await scaffoldReportVideo({ root: path.join(tmp, "reports"), slug: "poker-cut", from: "synth-poker/synthstream1", seed: "frames", channelsDir }); + assert.equal(r.seeded, 2); + const doc = JSON.parse(await readFile(path.join(r.dir, "video.manifest.json"), "utf8")); + assert.deepEqual(doc.timeline.map((c) => [c.id, c.channel, c.video, c.onscreen.title]), [ + ["f01", "synth-poker", "synthstream1", "Doubles up"], + ["f02", "synth-poker", "synthstream1", "Busts out"], + ]); + assert.equal(doc.timeline[0].onscreen.subtitle, "85 left · 41,000 chips"); + assert.equal(doc.frameScan.file, "frame-scan.poker.json"); + assert.equal(doc.frameScan.overlay.length, 2); + const readme = await readFile(path.join(r.dir, "README.md"), "utf8"); + assert.match(readme, /Clips seeded from the frame scan/); + await assert.rejects( + scaffoldReportVideo({ root: path.join(tmp, "reports"), slug: "poker-cut-2", from: "synth-poker/none", seed: "frames", channelsDir }), + /no frame-scan\.poker\.json — run pnpm ops frame-scan first/, + ); + await assert.rejects(scaffoldReportVideo({ root: path.join(tmp, "reports"), slug: "poker-cut-3", seed: "frames", channelsDir }), /--seed frames needs --from/); + } finally { + await rm(tmp, { recursive: true, force: true }); + } +}); diff --git a/umtool/report-to-video/frames-cut.mjs b/umtool/report-to-video/frames-cut.mjs @@ -0,0 +1,156 @@ +// A frame scan → a DRAFT supercut (release 30, lane P): the events a frame +// scan derived (frame-scan.<profile>.json beside the video) become clips of a +// `video.manifest.json` timeline — a window around each event, cut on the +// transcript's sentence edges where cues exist, overlapping windows merged — +// and the scan's running stats become the manifest's `frameScan` block: what +// a stats overlay draws over each clip (chips, big blinds, players left, +// level), read at any second by `frameTotals`. +// +// Plain ESM with no I/O, ledger-totals.mjs's pattern: the scaffold (`umtool +// new --seed frames`) calls it with the parsed sidecar, a future chrome region +// calls `frameTotals` for its numbers, and `node --test` runs it with literals. +// Every consumer gets the same arithmetic. No render here: the clips are a +// draft to review in the bench, and the overlay is data until a region draws it. + +import { widen } from "yt-dlp-transcript-common/lib/cueWiden.mjs"; + +/** Events worth a clip, most important first; the rest are left out. */ +export const CUT_EVENT_KINDS = ["won", "bust", "final-table", "double-up", "big-loss", "all-in", "eliminated"]; + +const TITLES = { + won: "Wins it", + bust: "Busts out", + eliminated: "Eliminated", + "final-table": "Final table", + "double-up": "Doubles up", + "big-loss": "Loses half the stack", + "all-in": "All in", +}; + +export const FRAMES_CUT_DEFAULTS = Object.freeze({ pre: 20, post: 25, maxClips: 20, mergeGap: 5 }); + +const fmt = (v) => (Number.isInteger(v) ? v.toLocaleString("en-US") : String(Math.round(v * 10) / 10)); +const round2 = (v) => Math.round(v * 100) / 100; + +/** The last value of a series at or before `t` (a series is [[t, v, …], …] sorted by t). */ +export function valueAt(series, t) { + let out = null; + for (const p of series ?? []) { + if (p[0] > t) break; + out = p[1]; + } + return out; +} + +/** + * The running stats at second `t`: the tournament the moment is in and the + * last value of each of its series (null where none was read yet). The one + * reducer the overlay and the clips' subtitles share. + */ +export function frameTotals(scan, t) { + const tours = scan?.derived?.tournaments ?? []; + const tour = tours.find((x) => t >= x.from && t < x.to) ?? [...tours].reverse().find((x) => x.from <= t) ?? null; + if (!tour) return null; + const s = tour.series ?? {}; + return { + tournament: tour.key, + name: tour.name ?? tour.key, + stack: valueAt(s.stack, t), + stackBB: valueAt(s.stackBB, t), + playersLeft: valueAt(s.playersLeft, t), + level: valueAt(s.level, t), + }; +} + +/** "Level 4 · 60 left · 41,000 chips (137 BB)". */ +export function statsLine(totals) { + if (!totals) return ""; + const parts = []; + if (totals.level !== null) parts.push(`Level ${fmt(totals.level)}`); + if (totals.playersLeft !== null) parts.push(`${fmt(totals.playersLeft)} left`); + if (totals.stack !== null) parts.push(`${fmt(totals.stack)} chips${totals.stackBB !== null ? ` (${fmt(totals.stackBB)} BB)` : ""}`); + else if (totals.stackBB !== null) parts.push(`${fmt(totals.stackBB)} BB`); + return parts.join(" · "); +} + +/** + * The draft: `{ timeline, frameScan, skipped }`. `scan` is the parsed + * sidecar; `cues` the video's cues (sorted), or none. A window is + * `[t - pre, t + post]`, widened to sentence edges where cues exist, clamped + * to the video; windows within `mergeGap` of each other are one clip. At most + * `maxClips`, the most important events kept, in time order. + */ +export function framesCut(scan, { channel, video, cues = null, ...o } = {}) { + const opt = { ...FRAMES_CUT_DEFAULTS, ...o }; + if (!channel || !video) throw new Error("framesCut needs the channel and the video"); + const duration = scan?.source?.durationSeconds ?? scan?.sampling?.to ?? Infinity; + const rank = (k) => CUT_EVENT_KINDS.indexOf(k); + const events = (scan?.derived?.events ?? []) + .filter((e) => rank(e.kind) >= 0) + // A bust and the "eliminated" banner on the same moment are one event. + .filter((e, _, all) => !(e.kind === "eliminated" && all.some((x) => x.kind === "bust" && Math.abs(x.t - e.t) <= 60))); + const chosen = [...events].sort((a, b) => rank(a.kind) - rank(b.kind) || a.t - b.t).slice(0, opt.maxClips); + const skipped = events.length - chosen.length; + chosen.sort((a, b) => a.t - b.t); + + const windows = chosen.map((e) => { + let start = Math.max(0, e.t - opt.pre); + let end = Math.min(duration, e.t + opt.post); + if (cues?.length) { + // Only ever WIDER, and only as far as widen's own budgets (8 s before, + // 12 s after): a cue past a silence is not this moment's sentence. + const w = widen(cues, start, end, { maxLead: 8, maxTail: 12 }); + if (w.start <= start && w.start >= start - 8) start = Math.max(0, w.start); + if (w.end >= end && w.end <= end + 12) end = Math.min(duration, w.end); + } + return { start, end, events: [e] }; + }); + const merged = []; + for (const w of windows) { + const last = merged[merged.length - 1]; + if (last && w.start <= last.end + opt.mergeGap) { + last.end = Math.max(last.end, w.end); + last.events.push(...w.events); + } else merged.push({ ...w, events: [...w.events] }); + } + + const timeline = merged.map((w, i) => { + const lead = [...w.events].sort((a, b) => rank(a.kind) - rank(b.kind))[0]; + const totals = frameTotals(scan, lead.t); + return { + type: "clip", + id: `f${String(i + 1).padStart(2, "0")}`, + channel, + video, + start: round2(w.start), + end: round2(w.end), + cite: Math.floor(lead.t), + quote: "", + onscreen: { title: TITLES[lead.kind] ?? lead.kind, subtitle: statsLine(totals) || lead.detail }, + frameEvents: w.events.map((e) => ({ t: e.t, kind: e.kind, detail: e.detail })), + }; + }); + + // The overlay track: the running stats at each clip's start and at every + // change inside it, in SOURCE seconds — what a stats region draws. + const overlay = timeline.map((c) => { + const changes = new Set([c.start]); + const tour = frameTotals(scan, c.cite); + const t = (scan?.derived?.tournaments ?? []).find((x) => x.key === tour?.tournament); + for (const series of Object.values(t?.series ?? {})) for (const p of series) if (p[0] > c.start && p[0] < c.end) changes.add(p[0]); + return { clip: c.id, points: [...changes].sort((a, b) => a - b).map((at) => ({ at, ...frameTotals(scan, at) })) }; + }); + + return { + timeline, + frameScan: { + profile: scan?.profile ?? null, + file: scan?.profile ? `frame-scan.${scan.profile}.json` : null, + channel, + video, + tournaments: (scan?.derived?.tournaments ?? []).map((t) => ({ key: t.key, name: t.name ?? t.key, from: t.from, to: t.to })), + overlay, + }, + skipped, + }; +} diff --git a/umtool/report-to-video/frames-cut.test.mjs b/umtool/report-to-video/frames-cut.test.mjs @@ -0,0 +1,81 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { framesCut, frameTotals, statsLine, valueAt } from "./frames-cut.mjs"; + +// A synthetic frame-scan sidecar (the shape common/lib/frameScan-server.ts writes). +const scan = () => ({ + format: "archilyzer-frame-scan", + profile: "poker", + source: { savedVideo: "source-media.mp4", durationSeconds: 400 }, + sampling: { everySeconds: 10, from: 0, to: 400 }, + derived: { + tournaments: [ + { + key: "synthetic cup", + name: "Synthetic Cup", + from: 30, + to: 200, + series: { stack: [[30, 20000], [90, 41000], [120, 9000], [180, 0]], stackBB: [[30, 100], [90, 136.7], [120, 22.5]], playersLeft: [[30, 85], [90, 60], [120, 9]], level: [[30, 3], [90, 4], [120, 5]] }, + facts: {}, + }, + { key: "viewer $1000", name: "Viewer $1000", from: 250, to: 400, series: { stack: [[250, 1500], [300, 3100, "spoken"]] }, facts: {} }, + ], + events: [ + { t: 35, kind: "buy-in", detail: "said", source: "spoken" }, + { t: 90, kind: "double-up", detail: "20,000 → 41,000 chips (2.1×)", source: "series" }, + { t: 120, kind: "big-loss", detail: "41,000 → 9,000 chips", source: "series" }, + { t: 120, kind: "final-table", detail: "9 players left", source: "series" }, + { t: 180, kind: "bust", detail: "out from 9,000 chips", source: "series" }, + { t: 180, kind: "eliminated", detail: "shown on screen", source: "frame" }, + ], + segments: [], + flags: [], + }, +}); + +test("valueAt, frameTotals, statsLine: the running stats at a second", () => { + assert.equal(valueAt([[30, 1], [90, 2]], 89), 1); + assert.equal(valueAt([[30, 1]], 10), null); + const at100 = frameTotals(scan(), 100); + assert.deepEqual(at100, { tournament: "synthetic cup", name: "Synthetic Cup", stack: 41000, stackBB: 136.7, playersLeft: 60, level: 4 }); + assert.equal(statsLine(at100), "Level 4 · 60 left · 41,000 chips (136.7 BB)"); + assert.equal(frameTotals(scan(), 310).stack, 3100); + assert.equal(frameTotals(scan(), 5), null); + assert.equal(statsLine(null), ""); +}); + +test("framesCut: a clip around each event, overlapping windows merged, the most important event titles it", () => { + const { timeline, frameScan, skipped } = framesCut(scan(), { channel: "synth", video: "s1" }); + assert.equal(skipped, 0); + // 90 (70–115) and 120 (100–145) overlap: one clip; 180 alone (the banner folded into the bust). + assert.deepEqual(timeline.map((c) => [c.id, c.start, c.end, c.cite, c.onscreen.title]), [ + ["f01", 70, 145, 120, "Final table"], + ["f02", 160, 205, 180, "Busts out"], + ]); + assert.deepEqual(timeline[0].frameEvents.map((e) => e.kind), ["double-up", "final-table", "big-loss"]); + assert.equal(timeline[0].onscreen.subtitle, "Level 5 · 9 left · 9,000 chips (22.5 BB)"); + assert.equal(timeline[1].quote, ""); + assert.equal(frameScan.file, "frame-scan.poker.json"); + assert.deepEqual(frameScan.overlay[0].points.map((p) => [p.at, p.stack]), [[70, 20000], [90, 41000], [120, 9000]]); + assert.equal(frameScan.tournaments.length, 2); +}); + +test("framesCut: cut on sentence edges where cues exist, clamped to the video", () => { + const cues = [ + { start: 60, end: 66, text: "so I shove." }, + { start: 66, end: 72, text: "He calls with" }, + { start: 72, end: 80, text: "queens and I hold." }, + { start: 140, end: 150, text: "nine left now" }, + { start: 150, end: 152, text: "here we go." }, + ]; + const { timeline } = framesCut(scan(), { channel: "synth", video: "s1", cues, pre: 20, post: 25 }); + assert.equal(timeline[0].start, 66); + assert.equal(timeline[0].end, 152); +}); + +test("framesCut: at most maxClips, the most important kept, in time order", () => { + const { timeline, skipped } = framesCut(scan(), { channel: "synth", video: "s1", maxClips: 2, pre: 1, post: 1 }); + assert.equal(skipped, 2); + assert.deepEqual(timeline.map((c) => c.onscreen.title), ["Final table", "Busts out"]); + assert.throws(() => framesCut(scan(), {}), /channel and the video/); +}); diff --git a/umtool/report-to-video/package.json b/umtool/report-to-video/package.json @@ -26,6 +26,7 @@ "./deck": "./deck.mjs", "./drafts-review": "./drafts-review.mjs", "./factcheck": "./factcheck.mjs", + "./frames-cut": "./frames-cut.mjs", "./ledger-totals": "./ledger-totals.mjs", "./lint": "./lint.mjs", "./local-media": "./local-media.mjs",