Archilyzer · Source

archilyzer

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

commit 09154fce3b00ab106be50ccf430e83d600bcd6e4
parent ba28b7f6ece3b6aedc6e4e1ab8ebdb63159fb65f
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed,  4 Nov 2026 00:41:50 -0500

umtool: the thread read on the post bench and under test -- the read piece by piece (the text each reads, when; click: there), what each context post is on screen, the shrink/dim/seconds/pan, the guard's refusals shown before Save; Play's player names each tile's state; unit tests of the roles, the layout, the guard, the geometry and THE INVARIANT (every part's span inside its block's on-screen, lit interval: its tile in full, in the window), and of the writers (posts roles --write/--set, set-item thread.*, --cut thread.*, the import's roles). posts narrate --cut now takes dotted knobs (follow.dim= was read as an item)

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

Diffstat:
Mumtool/components/projects/PostBench.tsx | 6++++++
Mumtool/components/projects/PostFollowPanel.tsx | 7++++---
Aumtool/components/projects/PostThreadPanel.tsx | 169+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/components/projects/review/PostItemPlayer.tsx | 14+++++++++++++-
Mumtool/lib/report/postNarrationCli.mjs | 4++--
Aumtool/lib/report/postThread.test.mjs | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/postThreadCli.mjs | 4++--
Mumtool/report-to-video/post-thread.mjs | 8+++++++-
Aumtool/report-to-video/post-thread.test.mjs | 213+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 517 insertions(+), 9 deletions(-)

diff --git a/umtool/components/projects/PostBench.tsx b/umtool/components/projects/PostBench.tsx @@ -9,6 +9,7 @@ import { postBenchHref } from "@/lib/hrefs"; import { POST_HOLD, POST_MEDIA_MIN_SPAN, POST_PARAPHRASE_MAX, contextReadSeconds, postItemPlan, readingSeconds, ruleSeconds } from "umtool-report-to-video/post-item"; import PostItemPlayer, { type PostPlan } from "./review/PostItemPlayer"; import PostFollowPanel from "./PostFollowPanel"; +import PostThreadPanel from "./PostThreadPanel"; import BlurBoxPad from "./BlurBoxPad"; import PostNarrationPanel from "./PostNarrationPanel"; import PostComboPanel from "./PostComboPanel"; @@ -30,6 +31,8 @@ import { wordZoomTimes, zoomSpan } from "umtool-report-to-video/word-zoom"; // its sound, a crop of any attachment, an image's push-in, // and a video's words: Transcribe asks the EDITOR's // transcription (a job on a local worker), never ASR here +// thread a read of the post it answers or quotes: what each is on +// screen while it is read and after (PostThreadPanel) // context the post it quotes, the posts it answers: a paraphrase of // a long one, drawn in place of its words with a // "paraphrased" label (its own text kept, shown beside) @@ -142,6 +145,8 @@ export default function PostBench({ redact: typeof e.redact === "boolean" ? e.redact : null, // Its read-follow (read-follow.mjs): false is off; its knobs, each null when it is the cut's. follow: e.follow === false ? false : e.follow && typeof e.follow === "object" ? { on: null, dim: null, ease: null, ...(e.follow as Record<string, unknown>) } : null, + // Its thread read (post-thread.mjs): its knobs, each null when it is the cut's. + thread: e.thread && typeof e.thread === "object" ? { parent: null, quoted: null, carry: null, reveal: null, shrink: null, dim: null, seconds: null, pan: null, ...(e.thread as Record<string, unknown>) } : null, media: Object.fromEntries( (e.media ?? []).map((m, i) => [ i, @@ -310,6 +315,7 @@ export default function PostBench({ }} /> <PostFollowPanel entry={entry} plan={plan} render={render} s={s} setS={setS} setEntry={(f) => setEntry((e) => f(e) as Entry)} /> + <PostThreadPanel entry={entry} plan={plan} render={render} before={before} setS={setS} setEntry={(f) => setEntry((e) => f(e) as Entry)} /> <PostNarrationPanel project={project} entry={entry} diff --git a/umtool/components/projects/PostFollowPanel.tsx b/umtool/components/projects/PostFollowPanel.tsx @@ -17,7 +17,7 @@ import type { PostPlan } from "./review/PostItemPlayer"; type Entry = Record<string, unknown> & { id: string }; type Follow = false | { on?: boolean; dim?: number; ease?: number } | undefined; -const SCOPE_NAME = (s: string) => (s === "post" ? "post" : s === "quoted" ? "quoted" : s.replace("parent:", "parent ")); +const SCOPE_NAME = (s: string) => (s === "post" ? "post" : s === "quoted" ? "quoted" : s.startsWith("media:") ? "attachment" : s.replace("parent:", "parent ")); export default function PostFollowPanel({ entry, plan, render, s, setS, setEntry, @@ -105,7 +105,8 @@ export default function PostFollowPanel({ <ol className="m-0 max-h-56 list-none space-y-0.5 overflow-auto p-0" data-post-follow-map=""> {follow.blocks.map((b) => { const words = texts.get(b.scope) ?? []; - const head = words.slice(b.from, Math.min(b.to + 1, b.from + 8)).join(" "); + // A part read off an attachment (post-thread.mjs: a screenshot's words) has no words on the card. + const head = b.from === null || b.to === null ? "(read off the attachment)" : words.slice(b.from, Math.min(b.to + 1, b.from + 8)).join(" "); return ( <li key={b.k} data-post-follow-row={b.k} data-current={cur === b.k ? "1" : undefined} className={cur === b.k ? "rounded bg-white/10" : ""}> <button @@ -119,7 +120,7 @@ export default function PostFollowPanel({ <span className="w-14 shrink-0 text-text-2">{SCOPE_NAME(b.scope)}</span> <span className="min-w-0 truncate"> {head} - {b.to + 1 - b.from > 8 ? "…" : ""} + {b.from !== null && b.to !== null && b.to + 1 - b.from > 8 ? "…" : ""} </span> </button> </li> diff --git a/umtool/components/projects/PostThreadPanel.tsx b/umtool/components/projects/PostThreadPanel.tsx @@ -0,0 +1,169 @@ +"use client"; + +import { useMemo } from "react"; +import { THREAD_DEFAULTS, THREAD_LIMITS, THREAD_MODES, partRoles, readPieces, threadKnobs, threadLayout, threadReadErrors } from "umtool-report-to-video/post-thread"; +import { followKnobs } from "umtool-report-to-video/read-follow"; +import { pickedTake } from "umtool-report-to-video/post-narration"; +import type { PostPlan } from "./review/PostItemPlayer"; + +// --------------------------------------------------------------------------- +// A POST's THREAD READ ON THE BENCH (report-to-video/post-thread.mjs; +// knobs.md, "Thread reads"; operator, 4 Nov: "you're never narrating hidden +// text ... show the parent in full then transition in the reply as the parent +// shrinks and goes dim"): its read PIECE BY PIECE -- the text each piece reads +// (the post it answers, the post it quotes, his words, an attachment's), when +// it starts (click: the playhead there) -- and what each context post is on +// screen (full, excerpt, context, carry, hidden), the shrink, the dim and their +// seconds, the pan's. A setting that would narrate a post the card hides is +// shown here, and refused by Save (the writer's guard). The knobs are the +// bench's draft (its Save writes them, as hold and follow). +// --------------------------------------------------------------------------- + +type Entry = Record<string, unknown> & { id: string; parents?: Array<Record<string, unknown>>; quoted?: Record<string, unknown> }; +type Thread = Partial<{ parent: string | string[]; quoted: string; carry: "auto" | boolean; reveal: boolean; shrink: number; dim: number; seconds: number; pan: number }>; + +const ROLE_NAME = (r: string | null) => + r === null ? "no text on the card" : r === "post" ? "his words" : r === "quoted" ? "the post it quotes" : r === "parent:0" ? "the post it answers" : r.startsWith("parent:") ? "the post that answers" : `attachment ${Number(r.slice(6)) + 1}'s words`; + +export default function PostThreadPanel({ + entry, plan, render, before, setS, setEntry, +}: { + entry: Entry; + plan: PostPlan; + render: Record<string, unknown>; + before: Record<string, unknown> | null; + setS: (s: number) => void; + setEntry: (f: (e: Entry) => Entry) => void; +}) { + const own = (entry.thread ?? undefined) as Thread | undefined; + const k = threadKnobs(entry, render) as Required<Thread>; + const layout = useMemo(() => threadLayout(entry, render, { prev: before }), [entry, render, before]); + const roles = useMemo(() => partRoles(entry) as Array<{ role: string | null; source: string }>, [entry]); + const pieces = useMemo(() => readPieces(entry, roles) as Array<{ role: string | null; parts: number[] }>, [entry, roles]); + const errors = useMemo(() => threadReadErrors(entry, render, { prev: before, followOn: (followKnobs(entry, render) as { on: boolean }).on }) as string[], [entry, render, before]); + const take = pickedTake(entry) as { parts?: Array<{ start: number; text?: string }> } | null; + const startOf = (part: number) => plan.follow?.blocks.find((b) => b.part === part)?.start ?? null; + const setOwn = (patch: Thread) => + setEntry((e) => { + const next: Record<string, unknown> = { ...((e.thread as Thread | undefined) ?? {}), ...patch }; + for (const [kk, v] of Object.entries(next)) if (v === undefined || v === null || v === "") delete next[kk]; + const out = { ...e }; + if (Object.keys(next).length) out.thread = next; + else delete out.thread; + return out; + }); + const parents = Array.isArray(entry.parents) ? entry.parents : []; + const parentMode = (i: number) => { + const p = own?.parent; + return Array.isArray(p) ? p[i] ?? "" : typeof p === "string" ? p : ""; + }; + const setParent = (i: number, v: string) => { + const list = parents.map((_, j) => parentMode(j) || "auto"); + list[i] = v || "auto"; + setOwn({ parent: list.every((m) => m === "auto") ? undefined : list.length === 1 ? list[0] : list }); + }; + const modeShown = (scope: string) => layout.tiles.find((t: { scope: string; mode: string }) => t.scope === scope)?.mode ?? "—"; + const num = (key: "shrink" | "dim" | "seconds" | "pan", label: string, step: number) => ( + <label className="flex items-center gap-1"> + {label} + <input + type="number" + min={THREAD_LIMITS[key][0]} + max={THREAD_LIMITS[key][1]} + step={step} + className="w-16" + value={typeof own?.[key] === "number" ? (own[key] as number) : ""} + placeholder={String(k[key] ?? THREAD_DEFAULTS[key])} + onChange={(e) => setOwn({ [key]: e.target.value === "" ? undefined : Number(e.target.value) })} + data-post-thread-knob={key} + /> + </label> + ); + if (!parents.length && !entry.quoted) return null; + return ( + <section className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-3 text-[12px]" data-post-thread-panel="" data-threaded={layout.on ? "1" : "0"}> + <div className="mb-2 flex flex-wrap items-center gap-2"> + <h2 className="micro m-0">thread read</h2> + <span className="text-text-2" data-post-thread-summary=""> + {layout.on ? "the card draws the conversation: each post read is shown in full, then shrinks and dims as the next comes in" : roles.length ? "his words only: the posts it answers are context" : "not narrated: the card as it is"} + </span> + </div> + {pieces.length > 0 && ( + <ol className="m-0 mb-2 list-none space-y-0.5 p-0" data-post-thread-pieces=""> + {pieces.map((p, i) => { + const at = startOf(p.parts[0]); + const words = p.parts.map((n) => take?.parts?.[n]?.text ?? "").join(" ").trim(); + return ( + <li key={i} data-post-thread-piece={p.role ?? "none"} data-source={roles[p.parts[0]]?.source}> + <button type="button" disabled={at === null} className="flex w-full gap-2 px-1 text-left disabled:opacity-60" onClick={() => at !== null && setS(at)} title={`parts ${p.parts.map((n) => n + 1).join(", ")}`}> + <span className="w-12 shrink-0 font-mono tabular-nums">{at === null ? "—" : `${at.toFixed(1)}s`}</span> + <span className="w-32 shrink-0 text-text-2"> + {ROLE_NAME(p.role)} + {roles[p.parts[0]]?.source === "stored" ? "" : " ·"} + </span> + <span className="min-w-0 truncate">{words.split(/\s+/).slice(0, 10).join(" ")}…</span> + </button> + </li> + ); + })} + </ol> + )} + <div className="flex flex-wrap items-center gap-2"> + {parents.map((_, i) => ( + <label key={i} className="flex items-center gap-1"> + {i === 0 ? "the post it answers" : "its parent"} + <select value={parentMode(i)} onChange={(e) => setParent(i, e.target.value)} data-post-thread-mode={`parent:${i}`} aria-label={`what parent ${i} is on screen`}> + <option value="">the cut&apos;s ({modeShown(`parent:${i}`)})</option> + {THREAD_MODES.filter((m: string) => m !== "auto").map((m: string) => ( + <option key={m} value={m}> + {m} + </option> + ))} + </select> + </label> + ))} + {entry.quoted && ( + <label className="flex items-center gap-1"> + the quoted post + <select value={typeof own?.quoted === "string" ? own.quoted : ""} onChange={(e) => setOwn({ quoted: e.target.value || undefined })} data-post-thread-mode="quoted" aria-label="what the quoted post is on screen"> + <option value="">the cut&apos;s ({modeShown("quoted")})</option> + {THREAD_MODES.filter((m: string) => m !== "auto" && m !== "carry").map((m: string) => ( + <option key={m} value={m}> + {m} + </option> + ))} + </select> + </label> + )} + <label className="flex items-center gap-1"> + carry + <select + value={own?.carry === undefined ? "" : String(own.carry)} + onChange={(e) => setOwn({ carry: e.target.value === "" ? undefined : e.target.value === "auto" ? "auto" : e.target.value === "true" })} + data-post-thread-carry="" + aria-label="carry the item before in" + > + <option value="">the cut&apos;s ({String(k.carry)})</option> + <option value="auto">auto</option> + <option value="true">on</option> + <option value="false">off</option> + </select> + </label> + {num("shrink", "shrink", 0.02)} + {num("dim", "dim", 0.05)} + {num("seconds", "over", 0.1)} + {num("pan", "pan", 0.1)} + </div> + <p className="m-0 mt-1 text-text-2"> + full: in full while read · excerpt: only what is read · context: small and dim · carry: the item before, giving way · hidden: not drawn (never read). Hidden and excerpt redraw the card once saved. + </p> + {errors.length > 0 && ( + <ul className="m-0 mt-1 list-disc pl-4 text-[var(--color-bad,#e5484d)]" data-post-thread-errors=""> + {errors.map((er, i) => ( + <li key={i}>{er}</li> + ))} + </ul> + )} + </section> + ); +} diff --git a/umtool/components/projects/review/PostItemPlayer.tsx b/umtool/components/projects/review/PostItemPlayer.tsx @@ -30,6 +30,8 @@ import { WORD_ZOOM_HIGHLIGHT_ALPHA, findMatch, highlightAt, resolveWordZoom, tar // page carries the read's blocks and its flow; the pan's path is worked out // from the page's geometry once it is drawn, and each tick sets the state at // the item's second (followStateAt -- the build's frames are the same states). +// A THREADED card (post-thread.mjs) is the same: its tiles' sizes and +// strengths are part of the state (the page's slots and tiles set by it). // --------------------------------------------------------------------------- type Rect = { x: number; y: number; width: number; height: number }; @@ -82,7 +84,15 @@ export type FollowPlan = { ease: number; readEnd: number; source: string; - blocks: Array<{ k: number; scope: string; from: number; to: number; part: number | null; start: number | null; end: number | null }>; + blocks: Array<{ k: number; scope: string; from: number | null; to: number | null; part: number | null; start: number | null; end: number | null }>; + /** A threaded card (post-thread.mjs threadSchedule): each tile's size and strength on the item's clock. */ + thread?: { + shrink: number; + dim: number; + seconds: number; + pan: number; + tiles: Array<{ scope: string; mode: string; read: boolean; from: number[]; to: number[]; t0: number; t1: number }>; + }; }; export type PostPlan = { @@ -454,6 +464,8 @@ export default function PostItemPlayer({ data-post-follow-block={followNow?.current !== null && followNow?.current !== undefined ? String(followNow.current) : undefined} data-post-follow-offset={followNow && followRoute?.segments.length ? String(Math.round(followNow.offset)) : undefined} data-post-follow-pans={followRoute ? String(followRoute.segments.length) : undefined} + data-post-thread={follow?.thread ? String(follow.thread.tiles.length) : undefined} + data-post-thread-tiles={followNow?.tiles ? Object.entries(followNow.tiles).map(([sc, v]) => `${sc}=${v[0]}/${v[1]}`).join(" ") : undefined} className="pointer-events-none absolute inset-0 overflow-hidden" > {mix && voiceTake && ( diff --git a/umtool/lib/report/postNarrationCli.mjs b/umtool/lib/report/postNarrationCli.mjs @@ -350,8 +350,8 @@ export async function narrateCommand(project, words, flags, { json = false, dryR if (!manifest) throw new NarrateError(`${project.id} has no manifest`); const render = manifest.render ?? {}; const tl = (manifest.timeline ?? []).filter((e) => e?.type === "post"); - const pairs = words.filter((w) => /^[A-Za-z]+=/.test(w)); - const ref = words.find((w) => !/^[A-Za-z]+=/.test(w)) ?? null; + const pairs = words.filter((w) => /^[A-Za-z][A-Za-z.]*=/.test(w)); + const ref = words.find((w) => !/^[A-Za-z][A-Za-z.]*=/.test(w)) ?? null; const write = async (fn) => withEditNotes(project, async () => fn(await manifestToken(project.dir))); if (flags.has("--import")) { diff --git a/umtool/lib/report/postThread.test.mjs b/umtool/lib/report/postThread.test.mjs @@ -0,0 +1,101 @@ +// A THREAD READ's writers and CLI (post-thread.mjs; postThreadCli.mjs, +// postsCli.mjs set-item thread.*, posts narrate --cut thread.*, the import's +// roles, manifest.mjs updatePostItem's guard): the roles stored, what each +// context post is on screen set, and a setting that would narrate hidden text +// refused with the fix. +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { after, test } from "node:test"; +import { postsCommand } from "./postsCli.mjs"; +import { postItemPatchOf } from "./postsCli.mjs"; +import { mixPatchOf } from "./postNarrationCli.mjs"; + +const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-post-thread-")); +after(() => rm(ROOT, { recursive: true, force: true })); +const REPORTS = path.join(ROOT, "reports"); +const PARENT = "The first thing anyone notices is the noise from the street.\n\nThen the lights in the hall go out without warning."; +const REPLY = "That is exactly what I was saying yesterday morning."; + +const parts = () => [ + { n: 1, para: 0, text: "The first thing anyone notices is the noise from the street.", start: 0, seconds: 3.6 }, + { n: 2, para: 1, text: "Then the lights in the hall go out without warning.", start: 4.2, seconds: 3.2 }, + { n: 3, para: 100, text: REPLY, start: 8.2, seconds: 3.1 }, +]; +const item = (id, o = {}) => ({ + type: "post", id: `p-${id}`, post: `subj-x/${id}`, platform: "x", author: "THE SUBJECT", handle: "Subject", date: "2026-10-30T10:00:00.000Z", text: REPLY, + parents: [{ id: "900", author: "Neighbour", handle: "neighbour_one", date: "2026-10-29T10:00:00.000Z", text: PARENT }], + ...o, +}); +const narrated = (id, o = {}) => item(id, { narration: { script: REPLY, takes: [{ file: `narration/posts/${id}/take-1.orpheus-thread.wav`, engine: "orpheus", voice: "leo+zac", seconds: 11.3, parts: parts() }], pick: 0 }, ...o }); + +async function project(name, timeline) { + const dir = path.join(REPORTS, name); + await mkdir(dir, { recursive: true }); + await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, provenance: { siteOrigin: "" }, render: { width: 1920, height: 1080, fps: 30 }, timeline }, null, 2)); + return { id: name, dir }; +} +const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); +const cli = async (args) => { + const lines = []; + const errs = []; + const code = await postsCommand(args, { root: REPORTS, out: (s) => lines.push(s), err: (s) => errs.push(s) }); + return { code, out: lines.join("\n"), err: errs.join("\n") }; +}; + +test("posts roles: the read piece by piece (inferred), --write stores them, --set sets one by hand", async () => { + const p = await project("roles", [narrated("1")]); + const ls = await cli(["roles", "roles"]); + assert.equal(ls.code, 0, ls.err); + assert.match(ls.out, /1 narrated item\(s\) read in parts, 1 threaded, 0 refused/); + assert.match(ls.out, /parts 1,2 {2}parent:0 {2}inferred {2}shown full/); + assert.match(ls.out, /parts 3 {2}post {2}inferred {2}shown full/); + const w = await cli(["roles", "roles", "--write"]); + assert.match(w.out, /stored the roles of 1 read/); + assert.deepEqual((await manifest(p)).timeline[0].narration.takes[0].parts.map((x) => x.role), ["parent:0", "parent:0", "post"]); + assert.match((await cli(["roles", "roles", "--write"])).out, /stored already/); + const set = await cli(["roles", "roles", "p-1", "--set", "2=post"]); + assert.equal(set.code, 0, set.err); + assert.deepEqual((await manifest(p)).timeline[0].narration.takes[0].parts.map((x) => x.role), ["parent:0", "post", "post"]); + assert.match((await cli(["roles", "roles", "p-1", "--set", "9=post"])).err, /parts 1-3/); + assert.match((await cli(["roles", "roles", "p-1", "--set", "1=somewhere"])).err, /a role is post, quoted/); +}); + +test("set-item thread.*: the knobs merge; hiding a parent the read reads is REFUSED with the fix; context for an unread one is fine", async () => { + const p = await project("knobs", [narrated("1"), item("2", { narration: { script: REPLY, takes: [{ file: "narration/posts/2/take-1.orpheus-zac.wav", seconds: 3.1, parts: [{ n: 1, para: 0, text: REPLY, start: 0, seconds: 3.1 }] }], pick: 0 } })]); + assert.deepEqual(postItemPatchOf(["thread.shrink=0.5", "thread.parent.1=hidden", "thread.carry=off", "thread.reveal=on"]).thread, { shrink: 0.5, parent: ["auto", "hidden"], carry: false, reveal: true }); + assert.deepEqual(postItemPatchOf(["thread=auto"]), { thread: null }); + const ok = await cli(["set-item", "knobs", "p-1", "thread.shrink=0.5", "thread.dim=0.4"]); + assert.equal(ok.code, 0, ok.err); + assert.deepEqual((await manifest(p)).timeline[0].thread, { shrink: 0.5, dim: 0.4 }); + const bad = await cli(["set-item", "knobs", "p-1", "thread.parent=hidden"]); + assert.notEqual(bad.code, 0); + assert.match(bad.err, /part 1 reads the post it answers, which is drawn hidden.*thread\.parent=full/); + assert.equal((await manifest(p)).timeline[0].thread.parent, undefined); + // Follow off with a read parent: refused too. + assert.match((await cli(["set-item", "knobs", "p-1", "follow=off"])).err, /read-follow is off/); + // p-2 reads only his words: its parent may be context or hidden. + assert.equal((await cli(["set-item", "knobs", "p-2", "thread.parent=hidden"])).code, 0); + assert.equal((await manifest(p)).timeline[1].thread.parent, "hidden"); + assert.equal((await cli(["set-item", "knobs", "p-1", "thread=auto"])).code, 0); + assert.equal((await manifest(p)).timeline[0].thread, undefined); +}); + +test("the cut's thread knobs (posts narrate --cut thread.*), and the import stores each part's role", async () => { + assert.deepEqual(mixPatchOf(["thread.shrink=0.55", "thread.parent=excerpt", "thread.carry=auto", "thread.reveal=off"], { cut: true }).thread, { shrink: 0.55, parent: "excerpt", carry: "auto", reveal: false }); + const p = await project("cut", [item("1")]); + const r = await cli(["narrate", "cut", "--cut", "thread.shrink=0.55", "thread.pan=1.2"]); + assert.equal(r.code, 0, r.err); + assert.deepEqual((await manifest(p)).render.postNarration.thread, { shrink: 0.55, pan: 1.2 }); + assert.notEqual((await cli(["narrate", "cut", "--cut", "thread.shrink=9"])).code, 0); + // The import: a batch's take with its parts (no roles) comes in with each part's role stored. + await mkdir(path.join(p.dir, "narration", "posts", "1"), { recursive: true }); + execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "sine=f=220:d=11.3", "-ar", "48000", "-ac", "1", path.join(p.dir, "narration", "posts", "1", "take-1.orpheus-thread.wav")]); + await writeFile(path.join(p.dir, "narration", "posts", "index.json"), JSON.stringify([{ id: "1", entry: "p-1", script: REPLY, takes: [{ file: "narration/posts/1/take-1.orpheus-thread.wav", engine: "orpheus", voice: "leo+zac", seconds: 11.3, parts: parts().map((x, i) => ({ ...x, voice: i < 2 ? "leo" : "zac" })) }], pick: 0 }])); + const imp = await cli(["narrate", "cut", "--import"]); + assert.equal(imp.code, 0, imp.err); + const got = (await manifest(p)).timeline[0].narration.takes[0].parts; + assert.deepEqual(got.map((x) => [x.role, x.voice]), [["parent:0", "leo"], ["parent:0", "leo"], ["post", "zac"]]); +}); diff --git a/umtool/lib/report/postThreadCli.mjs b/umtool/lib/report/postThreadCli.mjs @@ -82,7 +82,7 @@ export async function rolesCommand(project, ids, { write = false, set = null, js if (role !== "off" && !ROLE_RE.test(role)) throw new RolesError(`--set ${pair}: a role is post, quoted, parent:<i>, media:<i> (or off: inferred)`); roles[n - 1] = role === "off" ? null : role; } - const take = e.narration.takes.indexOf(t); + const take = (Number.isInteger(t.index) ? t.index : e.narration.pick ?? 0); const { result } = await withEditNotes(project, async () => updatePostNarrations(project.dir, [{ id: e.id, patch: { partRoles: { take, roles } } }], { token: await manifestToken(project.dir) })); const now = await readManifest(project.dir); const after = (now?.timeline ?? []).find((x) => x?.id === e.id) ?? e; @@ -97,7 +97,7 @@ export async function rolesCommand(project, ids, { write = false, set = null, js const inferred = partRoles(e); const roles = t.parts.map((p, k) => (typeof p.role === "string" ? p.role : inferred[k]?.role ?? null)); if (roles.every((r, k) => r === (t.parts[k].role ?? null))) continue; - patches.push({ id: e.id, patch: { partRoles: { take: e.narration.takes.indexOf(t), roles } } }); + patches.push({ id: e.id, patch: { partRoles: { take: (Number.isInteger(t.index) ? t.index : e.narration.pick ?? 0), roles } } }); } if (!patches.length) { out(json ? JSON.stringify({ ok: true, written: 0 }, null, 2) : `every read's roles are stored already (${items.length} item(s))`); diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs @@ -103,6 +103,8 @@ const pick = (o) => (isObj(o) ? Object.fromEntries(Object.entries(o).filter(([k, /** * One post's thread knobs: its own, else the cut's (`render.postNarration.thread`), else the defaults. + * @param {Record<string, any> | null | undefined} entry + * @param {Record<string, any>} [render] * @returns {{ parent: string | string[], quoted: string, carry: "auto"|boolean, reveal: boolean, shrink: number, dim: number, seconds: number, pan: number }} */ export function threadKnobs(entry, render = undefined) { @@ -209,7 +211,11 @@ export function partRoles(entry, take = undefined) { return out; } -/** The read's PIECES in order: `[{ role, parts: [k…] }]` -- runs of parts of one role. */ +/** + * The read's PIECES in order: `[{ role, parts: [k…] }]` -- runs of parts of one role. + * @param {Record<string, any>} entry + * @param {Array<{ role: string | null, source?: string }>} [roles] + */ export function readPieces(entry, roles = partRoles(entry)) { const out = []; roles.forEach((r, k) => { diff --git a/umtool/report-to-video/post-thread.test.mjs b/umtool/report-to-video/post-thread.test.mjs @@ -0,0 +1,213 @@ +// post-thread.mjs: a post item's THREAD READ -- each part's role (the text it +// reads: the post it answers, the post it quotes, his words, an attachment's), +// what the card shows for each, the guard that refuses narrating hidden text, +// and THE INVARIANT: every part's time span lies inside its block's on-screen, +// highlighted interval -- its tile in full, its block lit, in the window. +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { postCardHtml, postItemPlan, validatePostItem } from "./post-item.mjs"; +import { validatePostNarrationRender } from "./post-narration.mjs"; +import { followPath, followStateAt, followStateKey } from "./read-follow.mjs"; +import { + THREAD_DEFAULTS, partRoles, readPieces, threadGeoAt, threadKnobs, threadLayout, threadReadErrors, threadStateAt, tileStateAt, validateThreadReads, +} from "./post-thread.mjs"; + +const PARENT = "The first thing anyone notices is the noise from the street.\n\nThen the lights in the hall go out without warning.\n\nNobody had planned for any of this at all."; +const REPLY = "That is exactly what I was saying yesterday morning.\n\nWe should have bought the generator in the spring."; +const QUOTED = "Here is the plan for the weekend repairs on the roof."; +const parentRef = (o = {}) => ({ id: "900", author: "Neighbour", handle: "neighbour_one", date: "2026-10-26T19:09:24.000Z", text: PARENT, ...o }); +const base = (o = {}) => ({ + type: "post", id: "p-1", post: "acct-x/1001", platform: "x", author: "Subject", handle: "subject", date: "2026-10-27T02:41:55.000Z", text: REPLY, ...o, +}); +/** A take as the batch assembles one: pieces in order (para = piece * 100 + paragraph), each paragraph a part. */ +function take(pieces, { roles = false } = {}) { + const parts = []; + let at = 0; + pieces.forEach(([text, role], pi) => { + text.split(/\n\n/).forEach((para, k) => { + const seconds = Math.round((para.split(/\s+/).length / 3) * 100) / 100; + at += parts.length ? (k === 0 ? 0.8 : 0.6) : 0; + parts.push({ n: parts.length + 1, para: pi * 100 + k, text: para, start: Math.round(at * 100) / 100, seconds, ...(roles ? { role } : {}) }); + at += seconds; + }); + }); + return { file: "narration/posts/1001/take-1.orpheus-thread.wav", engine: "orpheus", voice: "leo+zac", seconds: Math.round(at * 100) / 100, script: pieces.map((p) => p[0]).join("\n\n"), parts }; +} +const narrate = (e, pieces, o) => ({ ...e, narration: { script: e.text, takes: [take(pieces, o)], pick: 0 } }); + +test("roles: the parent read first (para 0..), his words after (100..), matched by word pairs -- not by a bag of common words", () => { + const e = narrate(base({ parents: [parentRef()] }), [[PARENT, "parent:0"], [REPLY, "post"]]); + assert.deepEqual(partRoles(e).map((r) => r.role), ["parent:0", "parent:0", "parent:0", "post", "post"]); + assert.ok(partRoles(e).every((r) => r.source === "inferred")); + assert.deepEqual(readPieces(e).map((p) => [p.role, p.parts]), [["parent:0", [0, 1, 2]], ["post", [3, 4]]]); + // A quoted post read first, then his words. + const q = narrate(base({ quoted: { author: "Other", handle: "other", text: QUOTED } }), [[QUOTED], [REPLY]]); + assert.deepEqual(partRoles(q).map((r) => r.role), ["quoted", "post", "post"]); + // A stored role wins. + const s = narrate(base({ parents: [parentRef()] }), [[PARENT, "quoted"], [REPLY, "post"]], { roles: true }); + assert.equal(partRoles(s)[0].role, "quoted"); + assert.equal(partRoles(s)[0].source, "stored"); +}); + +test("roles: words no text holds are an attachment's when the post has a picture (a screenshot read first), else no text's; a two-word reply that repeats its parent's words still reads his", () => { + const shot = "Someone wrote a long thing about the council meeting going sideways again."; + const withPic = narrate(base({ media: [{ src: "posts-media/a/1.png", kind: "image", width: 600, height: 700 }] }), [[shot], [REPLY]]); + assert.deepEqual(partRoles(withPic).map((r) => r.role), ["media:0", "post", "post"]); + const without = narrate(base(), [[shot], [REPLY]]); + assert.equal(partRoles(without)[0].role, null); + // His two words are in the parent too: a new piece reads the next text along. + const tiny = narrate(base({ text: "It wobbles.", parents: [parentRef({ text: "Look how it wobbles, oh my word." })] }), [["Look how it wobbles, oh my word."], ["It wobbles."]]); + assert.deepEqual(partRoles(tiny).map((r) => r.role), ["parent:0", "post"]); +}); + +test("the layout: a read parent full, an unread one context -- carried when it is the item before; hidden and excerpt are knobs", () => { + const e = narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]); + const L = threadLayout(e); + assert.equal(L.on, true); + assert.deepEqual(L.tiles.map((t) => [t.scope, t.mode, t.read]), [["parent:0", "full", true], ["post", "full", true]]); + // His own reply only: the parent unread -- context, or carried when it is the item before. + const own = narrate(base({ parents: [parentRef()] }), [[REPLY]]); + assert.equal(threadLayout(own).tiles[0].mode, "context"); + assert.equal(threadLayout(own, undefined, { prev: { type: "post", id: "p-0", post: "acct-x/900" } }).tiles[0].mode, "carry"); + assert.equal(threadLayout({ ...own, thread: { carry: false } }, undefined, { prev: { post: "acct-x/900" } }).tiles[0].mode, "context"); + assert.equal(threadLayout({ ...own, thread: { parent: "hidden" } }).tiles[0].mode, "hidden"); + // Un-narrated: never threaded (the card as it was). + assert.equal(threadLayout(base({ parents: [parentRef()] })).on, false); + // The cut's default, the post's own over it. + assert.equal(threadKnobs({}, { postNarration: { thread: { shrink: 0.5 } } }).shrink, 0.5); + assert.equal(threadKnobs({ thread: { shrink: 0.7 } }, { postNarration: { thread: { shrink: 0.5 } } }).shrink, 0.7); + assert.equal(threadKnobs({}).dim, THREAD_DEFAULTS.dim); +}); + +test("THE GUARD: a part read off a hidden or context post, off no text on the card, or a threaded read with follow off is refused, with the fix", () => { + const e = narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]); + assert.deepEqual(threadReadErrors(e), []); + const hidden = threadReadErrors({ ...e, thread: { parent: "hidden" } }); + assert.equal(hidden.length, 3); + assert.match(hidden[0], /part 1 reads the post it answers, which is drawn hidden.*thread\.parent=full.*re-make the read without it/); + assert.match(threadReadErrors({ ...e, thread: { parent: "context" } })[0], /drawn as context/); + assert.match(threadReadErrors(e, undefined, { followOn: false }).join(" "), /read-follow is off.*follow=on/); + const lost = narrate(base(), [["Words from somewhere nobody can see on the card."], [REPLY]]); + assert.match(threadReadErrors(lost)[0], /part 1 reads words the card does not show.*umtool posts roles/); + // Over a cut: each item with the one before it. + const m = { render: {}, timeline: [base({ id: "p-0", post: "acct-x/900", text: PARENT }), narrate(base({ parents: [parentRef()] }), [[REPLY]])] }; + assert.deepEqual(validateThreadReads(m), []); + // The knobs' own errors. + assert.match(validatePostItem({ ...e, thread: { parent: "huge", shrink: 2 } }).join(" "), /thread\.parent must be one of.*thread\.shrink must be 0\.3–1/); + assert.match(validatePostNarrationRender({ postNarration: { thread: { quoted: "carry" } } }).join(" "), /render\.postNarration\.thread\.quoted/); +}); + +test("the schedule: the parent in full while it is read, shrunk and dimmed as his reply comes in -- revealed under it; a carried parent gives way as the read starts", () => { + const e = narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]); + const plan = postItemPlan(e, { postNarration: { lead: 0.4 } }); + const th = plan.follow.thread; + const [par, post] = th.tiles; + assert.deepEqual([par.scope, par.from, par.to], ["parent:0", [1, 1], [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]]); + assert.deepEqual([post.scope, post.from, post.to], ["post", [1, 0], [1, 1]]); + // His first part starts at lead + its start in the take; the change begins FOLLOW_PAN.lead before it. + const replyStart = plan.follow.blocks.find((b) => b.scope === "post" && b.part === 3).start; + assert.equal(par.t0, Math.round((replyStart - 0.4) * 1000) / 1000); + assert.equal(par.t1, Math.round((par.t0 + THREAD_DEFAULTS.seconds) * 1000) / 1000); + assert.deepEqual(tileStateAt(par, 1), [1, 1]); + assert.deepEqual(tileStateAt(par, par.t1 + 0.01), [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]); + assert.deepEqual(threadStateAt(th, 1).post, [1, 0]); + // Carried: in full at the first frame, small and dim once the read is under way, his reply revealed. + const own = narrate(base({ parents: [parentRef()] }), [[REPLY]]); + const cp = postItemPlan(own, {}, { prev: { post: "acct-x/900" } }); + const carry = cp.follow.thread.tiles.find((t) => t.scope === "parent:0"); + assert.equal(carry.mode, "carry"); + assert.deepEqual(tileStateAt(carry, 0), [1, 1]); + assert.deepEqual(tileStateAt(carry, 2), [THREAD_DEFAULTS.shrink, THREAD_DEFAULTS.dim]); + assert.deepEqual(threadStateAt(cp.follow.thread, 0).post, [1, 0]); + assert.deepEqual(threadStateAt(cp.follow.thread, 2).post, [1, 1]); +}); + +test("the geometry: a tile shrunk about its corner closes the flow up under it", () => { + const geo = { H: 500, C: 1000, tiles: { "parent:0": { top: 0, height: 400 }, post: { top: 420, height: 580 } }, blocks: { 0: { top: 100, bottom: 200 }, 1: { top: 500, bottom: 600 } } }; + const g = threadGeoAt(geo, { "parent:0": 0.5 }); + assert.deepEqual(g.blocks[0], { top: 50, bottom: 100 }); + assert.deepEqual(g.blocks[1], { top: 300, bottom: 400 }); + assert.equal(g.C, 800); + assert.deepEqual(g.tiles.post, { top: 220, bottom: 800 }); +}); + +/** + * A page's geometry for an entry, as measureFollow reports it: each tile's blocks stacked at `line` px a + * paragraph's line (a block's words / 6 lines), a head over each tile, the window `H` tall. + */ +function fakeGeo(plan, { H = 520, line = 44 } = {}) { + const blocks = {}; + const tiles = {}; + let y = 0; + const order = plan.follow.thread.tiles.map((t) => t.scope); + for (const scope of order) { + const top = y; + y += 70; + for (const b of plan.follow.blocks.filter((x) => x.scope === scope)) { + const h = Math.max(1, Math.ceil((b.to - b.from + 1) / 6)) * line; + blocks[b.k] = { top: y, bottom: y + h }; + y += h + line; + } + tiles[scope] = { top, height: y - top }; + y += 22; + } + return { H, C: y, blocks, tiles }; +} + +test("THE INVARIANT: every part's time span lies inside its block's on-screen, highlighted interval -- its tile in full, its block lit, inside the window", () => { + const cases = [ + ["a parent read first", narrate(base({ parents: [parentRef()] }), [[PARENT], [REPLY]]), null], + ["a quoted post read first", narrate(base({ quoted: { author: "Other", handle: "other", text: `${QUOTED}\n\n${PARENT}` } }), [[`${QUOTED}\n\n${PARENT}`], [REPLY]]), null], + ["two parents, then him", narrate(base({ parents: [parentRef({ id: "901", handle: "second_one", text: "Is anyone else hearing the street noise again tonight?" }), parentRef()] }), [[PARENT], ["Is anyone else hearing the street noise again tonight?"], [REPLY]]), null], + ["a carried parent", narrate(base({ parents: [parentRef()] }), [[REPLY]]), { post: "acct-x/900" }], + ]; + for (const [what, e, prev] of cases) { + const render = { postNarration: { lead: 0.4 } }; + const plan = postItemPlan(e, render, { prev }); + assert.ok(plan.follow?.thread, `${what}: threaded`); + const geo = fakeGeo(plan); + const path = followPath(plan.follow, geo); + const t = e.narration.takes[0]; + const settle = 0.4 + Math.max(THREAD_DEFAULTS.pan, THREAD_DEFAULTS.seconds) - 0.4 + plan.follow.ease / 2 + 0.02; + t.parts.forEach((p, k) => { + const blk = plan.follow.blocks.find((b) => b.part === k); + assert.ok(blk, `${what}: part ${k + 1} has a block`); + const from = blk.start + settle; + const to = (t.parts[k + 1] ? plan.follow.blocks.find((b) => b.part === k + 1).start : plan.follow.readEnd) - 0.45; + for (let s = from; s <= to; s += 0.1) { + const st = followStateAt(plan.follow, path, s); + const [sc, op] = st.tiles[blk.scope]; + assert.equal(sc, 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its tile (${blk.scope}) in full`); + if (blk.scope !== "quoted") assert.equal(op, 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its tile at full strength`); + else assert.equal(st.tiles.post[1], 1, `${what}: the post the quoted post is in, shown`); + assert.equal(st.op[blk.k] ?? 1, 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its block lit`); + assert.equal(st.current, blk.k, `${what}: part ${k + 1} is the block being read`); + const g = threadGeoAt(geo, Object.fromEntries(Object.entries(st.tiles).map(([x, v]) => [x, v[0]]))); + const bb = g.blocks[blk.k]; + assert.ok(bb.top - st.offset >= -1 && bb.bottom - st.offset <= geo.H + 1, `${what}: part ${k + 1} at ${s.toFixed(2)} s -- its block in the window (${(bb.top - st.offset).toFixed(0)}–${(bb.bottom - st.offset).toFixed(0)} of ${geo.H})`); + } + }); + // A transition draws a different card every frame; a still read, one. + assert.notEqual(followStateKey(followStateAt(plan.follow, path, 0.5)), followStateKey(followStateAt(plan.follow, path, plan.follow.readEnd + 1))); + } +}); + +test("the card page: a threaded read draws the conversation as tiles in one flow -- each post whole (no clamp), a hidden one not at all, an excerpt without its unread paragraphs", () => { + const e = narrate(base({ parents: [parentRef()], quoted: { author: "Other", handle: "other", text: QUOTED } }), [[PARENT], [REPLY]]); + const plan = postItemPlan(e, {}); + const html = postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow.thread }); + assert.match(html, /data-post-thread="3"/); + for (const scope of ["parent:0", "post", "quoted"]) assert.ok(html.includes(`data-thread-slot="${scope}"`), scope); + assert.match(html, /data-w="parent:0:\d+">all\.<\/span>/, "the parent's last word is on the page"); + assert.match(html, /\.tile \.tt \{ display: block; -webkit-line-clamp: none;/); + const hid = postItemPlan({ ...e, thread: { quoted: "hidden" } }, {}); + assert.ok(!postCardHtml(e, { width: 1600, height: 900, follow: true, thread: hid.follow.thread }).includes('data-thread-slot="quoted"')); + // An excerpt: the parent read only in part -- its unread paragraph not drawn. + const part = narrate(base({ parents: [parentRef()] }), [["The first thing anyone notices is the noise from the street."], [REPLY]]); + const ex = postItemPlan({ ...part, thread: { parent: "excerpt" } }, {}); + const exHtml = postCardHtml({ ...part, thread: { parent: "excerpt" } }, { width: 1600, height: 900, follow: true, thread: ex.follow.thread }); + assert.match(exHtml, /data-thread-excerpt/); + assert.match(exHtml, /\[data-thread-tile="parent:0"\] \[data-post-block="\d+"\][^{]*\{ display: none; \}/); + // Not narrated: the card as it was (no tiles). + assert.ok(!postCardHtml(base({ parents: [parentRef()] }), { width: 1600, height: 900, follow: true, thread: null }).includes("data-thread-slot")); +});