commit 7ab65b91685f0e64dd37f03b78242c87ac768833
parent da9598e46fdb29b7ee36fe5624005f1d5bc11f95
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 4 Nov 2026 13:48:49 -0500
umtool: the post segment's cache key as postSegmentKeyOf -- the join (the item before's end, its box, its slot's last frame), the plan's context-media panel and a wide layout added only when an item has them, every other thread-scenes input riding on the plan's follow; an item they do not touch keeps main's key (post-render-key.test.mjs), and a card with no relation line or visited link draws main's page byte for byte (checked over mid-6: 60 items unchanged, 24 changed)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
3 files changed, 124 insertions(+), 8 deletions(-)
diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs
@@ -1145,7 +1145,13 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p
const tc = threaded ? threadCard(L.card) : null;
const body = strip ? `${stripHtml}${slot}` : `${tc ? tc.html : card(L.card)}${slot}`;
const minSize = tc ? size : follow ? followMin : Math.round(POST_TEXT_SIZES[POST_TEXT_SIZES.length - 1] * k);
- return `<!doctype html>
+ // A status link is marked (`data-link`, post-link-visit.mjs) only when it names a post the card draws -- a link to
+ // anything else draws as it always did.
+ const drawnIds = new Set([...parentsOf(entry).map((p) => str(p.id)), str(entry?.quoted?.id), ...linksOf(entry).map((l) => str(l.id))].filter(Boolean));
+ const qh = str(entry?.quoted?.handle).replace(/^@/, "").toLowerCase();
+ const keepLink = (id, url) => drawnIds.has(id) || (!!qh && !str(entry?.quoted?.id) && new RegExp(`(?:x|twitter)\\.com/${qh}/status/${id}`, "i").test(url));
+ const unmark = (html) => html.replace(/<span class="link" data-link="(\d+)">([^<]*)<\/span>/g, (all, id, url) => (keepLink(id, url) ? all : `<span class="link">${url}</span>`));
+ return unmark(`<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=${width}, height=${height}">
<style>
@font-face { font-family: 'PostSans'; src: url('${cssStr(fonts.regular ?? "")}'); }
@@ -1201,9 +1207,9 @@ b, .name, .mark { font-family: 'PostSansBold', sans-serif; font-weight: 400; }
.tparent { display: flex; gap: ${Math.round(16 * k)}px; position: relative; }
.tparent::after { content: ""; position: absolute; left: ${Math.round(27 * k)}px; top: ${Math.round(64 * k)}px; bottom: -${Math.round(20 * k)}px; width: 2px; background: ${line}; }
.tpost { display: flex; flex-direction: column; gap: ${Math.round(16 * k)}px; }
-.rel { color: ${pal.muted}; font-size: ${Math.round(18 * k)}px; margin-bottom: ${Math.round(4 * k)}px; letter-spacing: 0.01em; }
+${tiles?.some((t) => t?.rel) ? `.rel { color: ${pal.muted}; font-size: ${Math.round(18 * k)}px; margin-bottom: ${Math.round(4 * k)}px; letter-spacing: 0.01em; }
.rel::before { content: "\\21b3 "; }
-.tile .tt { display: block; -webkit-line-clamp: none; overflow: visible; line-height: ${LINE}; color: ${pal.fg}; margin-top: ${Math.round(6 * k)}px; }
+` : ""}.tile .tt { display: block; -webkit-line-clamp: none; overflow: visible; line-height: ${LINE}; color: ${pal.fg}; margin-top: ${Math.round(6 * k)}px; }
.twords { line-height: ${LINE}; overflow-wrap: anywhere; }
.tile.quoted .tt { color: ${mixHex(pal.fg, pal.bg, 0.08)}; }
.tile.quoted.tabove .tt { color: ${pal.fg}; }${tc.css}` : ""}${highlight ? `
@@ -1231,7 +1237,7 @@ ${BAR_CSS(pal.fg)}
}
if (document.fonts && document.fonts.ready) document.fonts.ready.then(fit); else fit();
})();
-</script></body></html>`;
+</script></body></html>`);
}
/**
diff --git a/umtool/report-to-video/post-render-key.test.mjs b/umtool/report-to-video/post-render-key.test.mjs
@@ -0,0 +1,72 @@
+// THE SEGMENT CACHE KEY (post-render.mjs postSegmentKeyOf; operator, 4 Nov: "make sure you handle caching well, we may
+// have a couple rerenders before shipping"): every thread-scenes input that changes a post segment's pixels or timing
+// changes its key; an item none of them touch keeps the key it had on main (645dafb7), so `umtool take --from` reuses it.
+import assert from "node:assert/strict";
+import { createHash } from "node:crypto";
+import { test } from "node:test";
+import { postItemPlan, postLayout } from "./post-item.mjs";
+import { planContext } from "./post-conversation.mjs";
+import { POST_SEGMENT_RV, postSegmentKey, postSegmentKeyOf } from "./post-render.mjs";
+
+const render = { fps: 30, palette: { bg: "#111111" }, fontRegular: "/f/r.ttf", fontBold: "/f/b.ttf", postNarration: { lead: 0.25 } };
+const box = { width: 1610, height: 906 };
+const at = (h) => `2026-11-02T${String(h).padStart(2, "0")}:00:00.000Z`;
+const take = (text, role) => ({ file: "narration/posts/1/take-1.wav", engine: "orpheus", voice: "zac", seconds: 4, script: text, parts: [{ n: 1, para: 0, text, start: 0, seconds: 3.5, ...(role ? { role } : {}) }] });
+const post = (id, text, o = {}) => ({ type: "post", id: `p-${id}`, post: `acct-x/${id}`, platform: "x", author: "Subject", handle: "subject", date: at(10), text, ...o });
+const narrated = (e, pieces) => ({ ...e, narration: { script: e.text, takes: [{ ...take(e.text), parts: pieces.map(([t, role], k) => ({ n: k + 1, para: k * 100, text: t, start: k * 4, seconds: 3.5, role })), seconds: pieces.length * 4 }], pick: 0 } });
+
+/** Main's key, verbatim (645dafb7 post-render.mjs buildPostSegment), for an item with no redaction, bleeps or slurs. */
+function mainKey({ entry, plan, take: tk, stamps = [] }) {
+ return createHash("sha256")
+ .update(JSON.stringify({ v: 1, entry, box, place: [], palette: render.palette, fonts: [render.fontRegular, render.fontBold], fps: render.fps, encode: [], stamps, ...(tk ? { narration: plan.narration, postNarration: render.postNarration ?? null } : {}), ...(plan.follow ? { follow: plan.follow } : {}) }))
+ .digest("hex");
+}
+const keyOf = (entry, ctx = {}, extra = {}) => {
+ const plan = postItemPlan(entry, render, ctx);
+ return { plan, key: postSegmentKey(postSegmentKeyOf({ entry, box, render, plan, take: entry.narration ? entry.narration.takes[0] : null, layout: postLayout(entry, box), ...extra })) };
+};
+
+test("a PLAIN item (no thread, no join, no wide attachment) keeps main's key: --from reuses its segment", () => {
+ assert.equal(POST_SEGMENT_RV, null, "no renderer salt: unchanged plans draw what they drew");
+ for (const e of [
+ post("1", "Just a post with words."),
+ narrated(post("2", "A narrated post read on its own."), [["A narrated post read on its own.", "post"]]),
+ post("3", "A post with its picture.", { media: [{ src: "posts-media/a/3.png", kind: "image", width: 800, height: 600 }] }),
+ ]) {
+ const { plan, key } = keyOf(e);
+ assert.equal(key, mainKey({ entry: e, plan, take: e.narration ? e.narration.takes[0] : null }), e.id);
+ }
+});
+
+test("every thread-scenes input changes the key: the join, context media, a wide layout, a manual thread and its relations, the branch map, link visits and linked posts, whole-thread pieces", () => {
+ const root = narrated(post("10", "You all have low testosterone, I become bestial.", { date: at(10) }), [["You all have low testosterone, I become bestial.", "post"]]);
+ const reply = narrated(post("11", "We high T guys have to watch ourselves.", { date: at(12), parents: [{ id: "5", handle: "ryobi", author: "Ryobi", date: at(11), text: "Three days is enough." }, { id: "10", handle: "subject", author: "Subject", date: at(10), text: root.text }] }), [["Three days is enough.", "parent:0"], ["We high T guys have to watch ourselves.", "post"]]);
+ const tl = [root, reply];
+ const base = keyOf(reply, { ...planContext(tl, 1, render), join: null }).key;
+ const keys = new Map();
+ // The join: its seconds in the plan (follow.join), the item before's end in joinFrom.
+ const j = keyOf(reply, planContext(tl, 1, render));
+ keys.set("join (plan)", j.key);
+ keys.set("join (the item before's end)", keyOf(reply, planContext(tl, 1, render), { from: { entry: root, plan: postItemPlan(root, render), media: [], fadeIn: false } }).key);
+ // A context post's media (the plan's panel, the entry's ref media).
+ const withMedia = { ...reply, parents: [{ ...reply.parents[0], media: [{ src: "posts-media/r/5.jpg", kind: "image", width: 600, height: 800 }] }, reply.parents[1]] };
+ keys.set("context media", keyOf(withMedia, { ...planContext([root, withMedia], 1, render), join: null }).key);
+ // A wide attachment: the top layout.
+ keys.set("wide", keyOf({ ...reply, media: [{ src: "posts-media/w/1.png", kind: "image", width: 692, height: 141 }] }, { ...planContext(tl, 1, render), join: null }).key);
+ // A manual thread: its group's stack and relations.
+ const g = (e) => ({ ...e, thread: { group: "g" } });
+ const lone = narrated(post("20", "Ready for more lessons?", { handle: "movail", date: at(9) }), [["Ready for more lessons?", "post"]]);
+ const gtl = [g(lone), g(reply)];
+ keys.set("manual thread", keyOf(gtl[1], { ...planContext(gtl, 1, render), join: null }).key);
+ // The branch map off.
+ keys.set("branch map knob", keyOf({ ...reply, thread: { map: false } }, { ...planContext(tl, 1, render), join: null }).key);
+ // A linked post (a link visit) and its transcript.
+ const linked = { ...reply, links: [{ id: "77", handle: "iv", author: "IV", date: at(8), text: "Ya try to be civil" }] };
+ keys.set("linked post", keyOf(linked, { ...planContext([root, linked], 1, render), join: null }).key);
+ keys.set("linked transcript", keyOf({ ...linked, links: [{ ...linked.links[0], transcript: "the messages" }] }, { ...planContext([root, linked], 1, render), join: null }).key);
+ // A whole-thread read: a third ancestor.
+ const deeper = { ...reply, parents: [...reply.parents, { id: "3", handle: "x", author: "X", date: at(9), text: "An older post." }] };
+ keys.set("whole thread", keyOf(deeper, { ...planContext([root, deeper], 1, render), join: null }).key);
+ for (const [what, k] of keys) assert.notEqual(k, base, what);
+ assert.equal(new Set(keys.values()).size, keys.size, "each input its own key");
+});
diff --git a/umtool/report-to-video/post-render.mjs b/umtool/report-to-video/post-render.mjs
@@ -637,6 +637,47 @@ export function postZoomPlan(entry, render, total = Infinity, schedule = undefin
}
/**
+ * THE SEGMENT's CACHE KEY's fields, pure (a build whose key matches keeps the segment it has): the entry as drawn
+ * (and as published), the box and framing, the palette and faces, the encode, every file's stamp, the avatars, the
+ * narration and its mix, the plan's follow -- which carries the thread's tiles and their schedule, their relations,
+ * the scene, a manual thread's stack, the branch map, the link visits and the join's seconds -- the slurs; and, only
+ * when an item has them (an item none of them touch keeps the key it had before them):
+ *
+ * joinFrom the join (post-join.mjs): the item before as its segment draws it, its follow, its length, what its slot
+ * ended on -- its card and box are drawn from these
+ * panel the plan's context media shows (post-thread.mjs panelSchedule)
+ * layout a wide attachment's top/bottom layout (postLayout's `panel`), and its boxes
+ * rv a renderer salt (POST_SEGMENT_RV), only when it is set: bump it (a string) when a card draws
+ * differently from an UNCHANGED plan, so a segment built before is rebuilt, never reused. Unset: every
+ * thread-scenes change to what a card draws rides on its plan (its follow: the tiles' relations, the
+ * scene, the map, the visits, the join) or on the fields above -- checked over the whole of mid-6
+ * (post-render-key.test.mjs; an item with an unchanged key draws the same page as main's)
+ */
+export function postSegmentKeyOf({ entry, redaction = null, box, place = [], render, encode = [], stamps = [], avatars = {}, take = null, plan, bleeps = null, layout = null, from = null }) {
+ return {
+ v: 1, entry,
+ // A redaction that changes what the card draws changes the key; none leaves it as it was.
+ ...(redactionOn(redaction) ? { published: redactEntry(entry, redaction), blank: termsFor(entry, redaction) } : {}),
+ box, place, palette: render.palette, fonts: [render.fontRegular, render.fontBold], fps: render.fps, encode, stamps,
+ ...(Object.keys(avatars).length ? { avatars } : {}),
+ ...(take ? { narration: plan.narration, postNarration: render.postNarration ?? null } : {}),
+ ...(plan.follow ? { follow: plan.follow } : {}),
+ ...(bleeps ? { bleeps } : {}),
+ ...(slursOn(redaction?.slurs) ? { slurs: redaction.slurs } : {}),
+ ...(from ? { joinFrom: { entry: from.entry, follow: from.plan.follow ?? null, total: from.plan.total, media: from.media.map((x) => [x.m.src, x.t, x.box]), fadeIn: from.fadeIn } } : {}),
+ ...(plan.panel ? { panel: plan.panel } : {}),
+ ...(layout?.panel === "top" || layout?.panel === "bottom" ? { layout: { panel: layout.panel, card: layout.card, slot: layout.slot } } : {}),
+ ...(POST_SEGMENT_RV ? { rv: POST_SEGMENT_RV } : {}),
+ };
+}
+
+/** The renderer's salt (postSegmentKeyOf `rv`): null keeps every key as it was; a string rebuilds every post segment. */
+export const POST_SEGMENT_RV = null;
+
+/** The key of postSegmentKeyOf's fields. */
+export const postSegmentKey = (fields) => createHash("sha256").update(JSON.stringify(fields)).digest("hex");
+
+/**
* Build post item `entry`'s segment. `ctx`: `{ render, outDir, manifestDir,
* box, place, encode, exec, ffmpeg, emit, avatars }` -- the box it fills (the
* deck's footage box, or the frame), the deck's framing after it,
@@ -706,10 +747,7 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box
const st = await stat(f).catch(() => null);
return st ? `${f}:${st.size}:${Math.round(st.mtimeMs)}` : `${f}:-`;
}));
- const key = createHash("sha256")
- // A redaction that changes what the card draws changes the key; none leaves it as it was.
- .update(JSON.stringify({ v: 1, entry, ...(redactionOn(redaction) ? { published: redactEntry(entry, redaction), blank: termsFor(entry, redaction) } : {}), box, place, palette: render.palette, fonts: [render.fontRegular, render.fontBold], fps: render.fps, encode, stamps, ...(Object.keys(avatars).length ? { avatars } : {}), ...(take ? { narration: plan.narration, postNarration: render.postNarration ?? null } : {}), ...(plan.follow ? { follow: plan.follow } : {}), ...(bleeps ? { bleeps } : {}), ...(slursOn(redaction?.slurs) ? { slurs: redaction.slurs } : {}), ...(from ? { joinFrom: { entry: from.entry, follow: from.plan.follow ?? null, total: from.plan.total, media: from.media.map((x) => [x.m.src, x.t]) } } : {}) }))
- .digest("hex");
+ const key = postSegmentKey(postSegmentKeyOf({ entry, redaction, box, place, render, encode, stamps, avatars, take, plan, bleeps, layout, from }));
const record = postRecordPath(seg);
const had = await readFile(record, "utf8").then((t) => JSON.parse(t), () => null);
if (had?.key === key && (await stat(seg).catch(() => null))) {