commit 3c9fc6c81d32f4a8b9cabe52bee1e5d71e068197
parent 369253471b63cdd7c10878ff76da0c1ce3ef04f8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 4 Nov 2026 12:14:40 -0500
umtool: posts set-item edits a thread by hand -- parent.<i>=<json ref>|@file|off (an ancestor added, replaced or dropped, nearest first), parent.<i>.media=<file>, media.add=<file> / media.<i>=off (an attachment from a project file, measured), link.add=<ref> / link.<i>.media|transcript (a post its words link to), thread.group=<name>, thread.map=, panel=
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
5 files changed, 269 insertions(+), 21 deletions(-)
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -2356,11 +2356,13 @@ export async function insertEntries(dir, afterId, specs, { token = null, op = "i
}
/** The knobs of a post item a write may set (post-item.mjs; knobs.md, "A post item"). */
-export const POST_ITEM_KNOBS = Object.freeze(["hold", "mediaLayout", "redact", "follow", "thread", "scene"]);
+export const POST_ITEM_KNOBS = Object.freeze(["hold", "mediaLayout", "panel", "redact", "follow", "thread", "scene"]);
/** A post item attachment's knobs: its trim, its sound, its crop, the push-in, its transcript, its censoring blur. */
export const POST_MEDIA_KNOBS = Object.freeze(["start", "end", "mute", "crop", "push", "words", "blur"]);
/** A context post's knobs (`quoted`, `parents[i]`): the operator's paraphrase of its words. */
-export const POST_CONTEXT_KNOBS = Object.freeze(["paraphrase"]);
+export const POST_CONTEXT_KNOBS = Object.freeze(["paraphrase", "ref", "media", "transcript"]);
+/** The fields a context post (a parent, a linked post) is given by hand (`parent.<i>=<ref>`, post-item.mjs refErrors). */
+const POST_REF_FIELDS = Object.freeze(["id", "author", "handle", "badge", "date", "text", "url", "media", "paraphrase", "transcript", "via"]);
/**
* SET A POST ITEM's KNOBS (the post bench, `umtool posts set-item`): `patch`
@@ -2380,7 +2382,7 @@ export const POST_CONTEXT_KNOBS = Object.freeze(["paraphrase"]);
export async function updatePostItem(dir, id, patch, { token = null } = {}) {
if (!isObj(patch)) throw new Error("a post item's patch is an object");
for (const k of Object.keys(patch)) {
- if (!["media", "quoted", "parents"].includes(k) && !POST_ITEM_KNOBS.includes(k)) throw new Error(`${k} is not a post item knob (${[...POST_ITEM_KNOBS, "media", "quoted", "parents"].join(", ")})`);
+ if (!["media", "mediaAdd", "quoted", "parents", "links", "linksAdd"].includes(k) && !POST_ITEM_KNOBS.includes(k)) throw new Error(`${k} is not a post item knob (${[...POST_ITEM_KNOBS, "media", "mediaAdd", "quoted", "parents", "links", "linksAdd"].join(", ")})`);
}
return structural(dir, "post-item", token, (m) => {
const i = entryIndex(m.timeline, id);
@@ -2418,6 +2420,7 @@ export async function updatePostItem(dir, id, patch, { token = null } = {}) {
for (const [key, mp] of Object.entries(patch.media)) {
const n = Number(key);
if (!Number.isInteger(n) || !media[n]) throw new Error(`${id} has no attachment ${key} (0–${media.length - 1})`);
+ if (mp === null) continue; // removed below, once every index has been read
if (!isObj(mp)) throw new Error(`media.${key} is an object of knobs`);
for (const k of Object.keys(mp)) if (!POST_MEDIA_KNOBS.includes(k)) throw new Error(`media.${key}.${k} is not an attachment knob (${POST_MEDIA_KNOBS.join(", ")})`);
for (const k of POST_MEDIA_KNOBS) {
@@ -2440,7 +2443,20 @@ export async function updatePostItem(dir, id, patch, { token = null } = {}) {
if (Number.isFinite(media[n].seconds) && Number.isFinite(media[n].end) && Math.abs(media[n].end - media[n].seconds) < 0.02) delete media[n].end;
}
}
- // A context post's paraphrase (`quoted`, `parents[i]`): its text is never touched.
+ // Attachments removed (`media.<i>=off`) and added from project files (`media.add=`, measured by the caller).
+ if (isObj(patch.media)) {
+ const drop = new Set(Object.entries(patch.media).filter(([, v]) => v === null).map(([k2]) => Number(k2)));
+ if (drop.size) {
+ e.media = (e.media ?? []).filter((_, n) => !drop.has(n));
+ if (!e.media.length) delete e.media;
+ }
+ }
+ if (patch.mediaAdd !== undefined) {
+ if (!Array.isArray(patch.mediaAdd)) throw new Error("mediaAdd is a list of attachments");
+ e.media = [...(Array.isArray(e.media) ? e.media : []), ...patch.mediaAdd];
+ }
+ // A context post's paraphrase (`quoted`, `parents[i]`): its text is never touched. A hand-made ref (`ref`), its
+ // attachments (`media`) and the words read off its picture (`transcript`) are set here too.
const setContext = (ref, cp, what) => {
if (!isObj(cp)) throw new Error(`${what} is an object of knobs`);
for (const k of Object.keys(cp)) if (!POST_CONTEXT_KNOBS.includes(k)) throw new Error(`${what}.${k} is not a context knob (${POST_CONTEXT_KNOBS.join(", ")})`);
@@ -2449,25 +2465,63 @@ export async function updatePostItem(dir, id, patch, { token = null } = {}) {
if (v !== null && v !== undefined && typeof v !== "string") throw new Error(`${what}.paraphrase is a string (or null: its own words)`);
set(ref, "paraphrase", typeof v === "string" && v.trim() ? v.trim() : null);
}
+ if ("media" in cp) {
+ if (cp.media !== null && !Array.isArray(cp.media)) throw new Error(`${what}.media is a list of attachments (or null: none)`);
+ set(ref, "media", cp.media?.length ? cp.media : null);
+ }
+ if ("transcript" in cp) {
+ if (cp.transcript !== null && typeof cp.transcript !== "string") throw new Error(`${what}.transcript is the words read off its picture (or null)`);
+ set(ref, "transcript", typeof cp.transcript === "string" && cp.transcript.trim() ? cp.transcript.trim() : null);
+ }
+ };
+ const cleanRef = (r, what) => {
+ if (!isObj(r)) throw new Error(`${what} is a post ({ id, author, handle, date, text, … })`);
+ const bad = Object.keys(r).filter((k) => !POST_REF_FIELDS.includes(k));
+ if (bad.length) throw new Error(`${what}: ${bad.join(", ")} not a post's field (${POST_REF_FIELDS.join(", ")})`);
+ return JSON.parse(JSON.stringify(r));
+ };
+ // A list of refs (`parents`, `links`) patched by index: `ref` replaces (the next index appends) or (null) drops one.
+ const patchRefs = (field, rp) => {
+ if (!isObj(rp)) throw new Error(`${field} is an object of { <i>: knobs }`);
+ let list = Array.isArray(e[field]) ? e[field] : [];
+ const drop = new Set();
+ for (const [key, cp] of Object.entries(rp).sort((a, b) => Number(a[0]) - Number(b[0]))) {
+ const n = Number(key);
+ if (!isObj(cp)) throw new Error(`${field}.${key} is an object of knobs`);
+ if ("ref" in cp) {
+ if (cp.ref === null) {
+ if (!isObj(list[n])) throw new Error(`${id} has no ${field === "parents" ? "parent" : "linked post"} ${key}`);
+ drop.add(n);
+ continue;
+ }
+ if (!Number.isInteger(n) || n < 0 || n > list.length) throw new Error(`${field}.${key}: the next one is ${list.length} (nearest first)`);
+ list[n] = cleanRef(cp.ref, `${field}.${key}`);
+ }
+ if (!Number.isInteger(n) || !isObj(list[n])) throw new Error(list.length ? `${id} has no ${field === "parents" ? "parent" : "linked post"} ${key} (0–${list.length - 1}${field === "parents" ? ", nearest first" : ""})` : `${id} ${field === "parents" ? "answers no post it carries" : "links no post"}`);
+ const { ref: _r, ...rest } = cp;
+ void _r;
+ if (Object.keys(rest).length) setContext(list[n], rest, `${field}.${key}`);
+ }
+ list = list.filter((_, n) => !drop.has(n));
+ if (list.length) e[field] = list;
+ else delete e[field];
};
if (patch.quoted !== undefined) {
if (!isObj(e.quoted)) throw new Error(`${id} quotes no post`);
setContext(e.quoted, patch.quoted, "quoted");
}
- if (patch.parents !== undefined) {
- if (!isObj(patch.parents)) throw new Error("parents is an object of { <i>: knobs }");
- const parents = Array.isArray(e.parents) ? e.parents : [];
- for (const [key, cp] of Object.entries(patch.parents)) {
- const n = Number(key);
- if (!Number.isInteger(n) || !isObj(parents[n])) throw new Error(parents.length ? `${id} has no parent ${key} (0–${parents.length - 1}, nearest first)` : `${id} answers no post it carries`);
- setContext(parents[n], cp, `parents.${key}`);
- }
+ if (patch.parents !== undefined) patchRefs("parents", patch.parents);
+ // Added first, so `link.add=… link.<n>.transcript=…` in one call names the one just added.
+ if (patch.linksAdd !== undefined) {
+ if (!Array.isArray(patch.linksAdd)) throw new Error("linksAdd is a list of posts");
+ e.links = [...(Array.isArray(e.links) ? e.links : []), ...patch.linksAdd.map((r, n) => cleanRef(r, `linksAdd[${n}]`))];
}
+ if (patch.links !== undefined) patchRefs("links", patch.links);
const errors = validatePostItem(e);
if (errors.length) throw new StructureRefused(errors);
// NEVER NARRATE HIDDEN TEXT (post-thread.mjs): a change to what the card shows that leaves a part of its read
// off the screen is refused, with the fix (one it had before is the guard's, not this write's).
- if ("thread" in patch || "follow" in patch) {
+ if ("thread" in patch || "follow" in patch || "parents" in patch || "links" in patch || "linksAdd" in patch) {
// With the item before it and the scene its run leaves on screen (post-conversation.mjs; a fresh list, so never
// a context worked out before this write).
const ctx = planContext(m.timeline.slice(), i, m.render);
diff --git a/umtool/lib/report/postThreadScenes.test.mjs b/umtool/lib/report/postThreadScenes.test.mjs
@@ -0,0 +1,77 @@
+// lane/thread-scenes, the writers: `posts set-item` parent.<i>=<ref> (a whole thread, by hand), parent.<i>.media,
+// media.add / media.<i>=off (an attachment from a project file, measured), link.add (a linked post), thread.group
+// (a manual thread), panel=, thread.map=; and `timeline threads --write` gathering a group in date order.
+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 { postItemPatchOf, postsCommand } from "./postsCli.mjs";
+
+const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-thread-scenes-"));
+after(() => rm(ROOT, { recursive: true, force: true }));
+const REPORTS = path.join(ROOT, "reports");
+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: `Words of post ${id}.`, ...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") };
+};
+let ffmpeg = true;
+try {
+ execFileSync("ffmpeg", ["-version"], { stdio: "ignore" });
+} catch {
+ ffmpeg = false;
+}
+
+test("set-item parent.<i>=<ref>: an ancestor added at the next index, replaced, dropped; parent.<i>.media and media.add measured from project files", { skip: !ffmpeg && "no ffmpeg" }, async () => {
+ const p = await project("chain", [item("1", { parents: [{ id: "900", handle: "grok", author: "Grok", date: "2026-10-30T09:00:00.000Z", text: "An answer." }] })]);
+ await mkdir(path.join(p.dir, "posts-media", "x", "1"), { recursive: true });
+ execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=red:s=692x141", "-frames:v", "1", path.join(p.dir, "posts-media/x/1/wide.png")]);
+ const justin = JSON.stringify({ id: "800", handle: "@JustinInYT1", author: "Justin", date: "2026-10-30T08:00:00.000Z", text: "@grok is that a threat?" });
+ assert.deepEqual(postItemPatchOf([`parent.1=${justin}`]).parents["1"].ref.handle, "JustinInYT1");
+ const add = await cli(["set-item", "chain", "p-1", `parent.1=${justin}`, "parent.1.media=posts-media/x/1/wide.png", "media.add=posts-media/x/1/wide.png", "panel=top", "thread.group=grok", "thread.map=both"]);
+ assert.equal(add.code, 0, add.err);
+ let e = (await manifest(p)).timeline[0];
+ assert.deepEqual(e.parents.map((x) => x.id), ["900", "800"]);
+ assert.deepEqual(e.parents[1].media, [{ src: "posts-media/x/1/wide.png", kind: "image", width: 692, height: 141 }]);
+ assert.deepEqual(e.media, [{ src: "posts-media/x/1/wide.png", kind: "image", width: 692, height: 141 }]);
+ assert.equal(e.panel, "top");
+ assert.deepEqual(e.thread, { group: "grok", map: "both" });
+ // Past the next index: refused; a field a post has not: refused; a file not there: refused.
+ assert.match((await cli(["set-item", "chain", "p-1", `parent.5=${justin}`])).err, /the next one is 2/);
+ assert.match((await cli(["set-item", "chain", "p-1", 'parent.2={"id":"7","likes":3}'])).err, /likes is not a post's field/);
+ assert.match((await cli(["set-item", "chain", "p-1", "media.add=posts-media/none.png"])).err, /not in the project/);
+ // Replaced, then dropped; the attachment removed.
+ assert.equal((await cli(["set-item", "chain", "p-1", 'parent.0={"id":"901","handle":"grok","text":"Another answer.","date":"2026-10-30T09:30:00.000Z"}', "media.0=off", "thread.group=off"])).code, 0);
+ e = (await manifest(p)).timeline[0];
+ assert.deepEqual(e.parents.map((x) => [x.id, x.text]), [["901", "Another answer."], ["800", "@grok is that a threat?"]]);
+ assert.equal(e.media, undefined);
+ assert.deepEqual(e.thread, { map: "both" });
+ assert.equal((await cli(["set-item", "chain", "p-1", "parent.1=off"])).code, 0);
+ assert.deepEqual((await manifest(p)).timeline[0].parents.map((x) => x.id), ["901"]);
+});
+
+test("set-item link.add: a post its words link to, with a picture and the words read off it; link.<i>=off drops it", { skip: !ffmpeg && "no ffmpeg" }, async () => {
+ const p = await project("links", [item("2", { text: "this you? https://x.com/Infinity_Virus_/status/2116805001309823299" })]);
+ await mkdir(path.join(p.dir, "posts-media", "iv"), { recursive: true });
+ execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=blue:s=600x4029", "-frames:v", "1", path.join(p.dir, "posts-media/iv/1.jpg")]);
+ const ref = JSON.stringify({ id: "2116805001309823299", handle: "Infinity_Virus_", author: "Infinity", date: "2026-11-01T08:10:15.000Z", text: "Ya try to be civil and they go insane", media: ["posts-media/iv/1.jpg"] });
+ const r = await cli(["set-item", "links", "p-2", `link.add=${ref}`, "link.0.transcript=Line one of the messages.\n\nLine two of them."]);
+ assert.equal(r.code, 0, r.err);
+ const e = (await manifest(p)).timeline[0];
+ assert.equal(e.links[0].media[0].height, 4029);
+ assert.equal(e.links[0].transcript, "Line one of the messages.\n\nLine two of them.");
+ assert.equal((await cli(["set-item", "links", "p-2", "link.0=off"])).code, 0);
+ assert.equal((await manifest(p)).timeline[0].links, undefined);
+});
diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs
@@ -28,6 +28,7 @@
// replaced (its attachTo kept unless --attach says otherwise).
//
// Plain ESM: the CLI runs under bare node.
+import { readFileSync } from "node:fs";
import { copyFile, mkdir, readFile, readdir, realpath, stat } from "node:fs/promises";
import path from "node:path";
import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs";
@@ -90,7 +91,11 @@ export const POSTS_USAGE = [
" [media.<i>.blur=on|off] [media.<i>.blur.strength=1–10] [media.<i>.blur.label=\"…\"|off]",
" [media.<i>.blur.boxes=x,y,w,h;…|off] [media.<i>.blur.band=below:<f>|above:<f>|between:<a>,<b>[:left:<f>|:right:<f>]|off]",
" [media.<i>.blur.style=blur|black|pixelate|off] [media.<i>.censor=<edge>:<f>[:<style>][:<strength>]|off]",
- " [parent.<i>.paraphrase=\"…\"|off] [narration.rate=0.8–1.5|narration.<mix knob>=…] [--json]",
+ " [parent.<i>.paraphrase=\"…\"|off] [narration.rate=0.8–1.5|narration.<mix knob>=…]",
+ " [panel=auto|side|top|bottom] [media.add=<posts-media/…file>] [media.<i>=off]",
+ " [parent.<i>=<json ref>|@<file.json>|off] [parent.<i>.media=<file>[,<file>…]|off]",
+ " [link.add=<json ref>|@<file.json>] [link.<i>=<json ref>|off] [link.<i>.media=<file>|off] [link.<i>.transcript=\"…\"|off]",
+ " [thread.group=<name>|off] [thread.map=auto|on|off|map|label|both] [--json]",
" a post item's knobs (the post bench's writer, updatePostItem): its hold, its images' grid, the blur of other authors,",
" an attachment's trim, sound, crop (fractions of its picture) and push-in; fit=read[:linger] (a narrated post: its",
" video cut to its best part for the read, `posts fit`). quoted.paraphrase / parent.<i>.paraphrase (nearest first):",
@@ -108,6 +113,15 @@ export const POSTS_USAGE = [
" the conversation, each post read shown in full and shrunk/dimmed as the next comes in: what each context post is",
" on screen (auto: full when read, carried in when it is the item before, else context), the shrink, dim and their",
" seconds, the pan's seconds. A setting that would narrate a post the card hides is refused (umtool posts roles).",
+ " parent.<i>=<ref>: a WHOLE-THREAD read -- an ancestor added (i = the next one) or replaced, nearest first, as JSON",
+ " {\"id\",\"handle\",\"author\",\"date\",\"text\",\"media\":[\"posts-media/…\"]} (or @<file>.json); off drops it. parent.<i>.media=",
+ " the attachments a context post carries (shown in the slot while it is on screen; measured as they go in).",
+ " media.add=<file>: an attachment from a project file (kind and size measured); media.<i>=off removes one.",
+ " link.add=<ref>: a post its words link to (a LINK VISIT: the pointer clicks the link, the post opens); its",
+ " transcript (words read off its picture, in his voice) scrolls its picture as it is read (role linked:<i>).",
+ " thread.group=<name>: a MANUAL THREAD -- consecutive items of one group are one scene (timeline threads --write",
+ " gathers them in date order). thread.map: the BRANCH MAP drawn when the scene changes branch (post-branch-map.mjs).",
+ " panel=: where the attachments sit -- beside the card, or at full width above (top) or below it (a wide one: auto).",
...ROLES_LINES,
...REREAD_LINES,
" umtool posts narrate <project> … a post item's narration: script, takes (the editor's tts), pick, approve, mix",
@@ -227,6 +241,7 @@ export function postEntryOf(row, { slug, postId, manifest = null, attach = null,
const ON = new Set(["on", "true", "yes", "1"]);
const OFF = new Set(["off", "false", "no", "0"]);
+const readFileSyncText = (f) => readFileSync(f, "utf8");
/**
* `posts set`'s words as the Posts table's patch: `thread=on|off`,
@@ -637,6 +652,33 @@ const onOff = (v, k) => {
};
/** A paraphrase's words, or null for `off` / empty (its own words again). */
+/** A project file named by a knob (`posts-media/…`): kept as a marker the command measures (attachmentOf). */
+const fileArg = (raw, k) => {
+ const f = String(raw).trim();
+ if (!f || f.startsWith("/") || f.split(/[\\/]/).includes("..")) throw new CliError(`${k}= takes a file of the project (posts-media/…), not ${raw}`);
+ return { file: f };
+};
+
+/** The ref keys a context post may carry (post-item.mjs refErrors). */
+const REF_KEYS = ["id", "author", "handle", "badge", "date", "text", "url", "media", "paraphrase", "transcript", "via"];
+
+/** A context post given on the command line: JSON, or `@<file>.json`. Its `media` may name project files. */
+const refArg = (raw, k) => {
+ let j;
+ try {
+ j = JSON.parse(raw.trim().startsWith("@") ? readFileSyncText(raw.trim().slice(1)) : raw);
+ } catch (e) {
+ throw new CliError(`${k}= takes a post as JSON ({"id","handle","author","date","text"}) or @<file>.json -- ${e.message}`);
+ }
+ if (!j || typeof j !== "object" || Array.isArray(j)) throw new CliError(`${k}= takes a post as a JSON object`);
+ const bad = Object.keys(j).filter((x) => !REF_KEYS.includes(x));
+ if (bad.length) throw new CliError(`${k}: ${bad.join(", ")} ${bad.length === 1 ? "is" : "are"} not a post's field (${REF_KEYS.join(", ")})`);
+ if (j.id !== undefined) j.id = String(j.id);
+ if (typeof j.handle === "string") j.handle = j.handle.replace(/^@/, "");
+ if (Array.isArray(j.media)) j.media = j.media.map((m) => (typeof m === "string" ? fileArg(m, `${k}.media`) : m));
+ return j;
+};
+
const paraphraseOf = (raw) => (raw.trim() === "" || raw.trim().toLowerCase() === "off" ? null : raw);
/**
@@ -673,26 +715,58 @@ export function postItemPatchOf(pairs) {
else if (k === "thread") {
if (!(v === "auto" || v === "default" || v === "")) throw new CliError("thread= takes auto (the cut's knobs); set one with thread.<knob>=");
out.thread = null;
- } else if (/^thread\.(parent(\.\d)?|quoted|carry|reveal|shrink|dim|seconds|pan)$/.test(k)) {
+ } else if (k === "thread.group") {
+ // A MANUAL THREAD (post-conversation.mjs): consecutive items of one group play as one scene, in date order.
+ if (out.thread === null) throw new CliError("thread=auto goes alone");
+ const t = (out.thread ??= {});
+ t.group = OFF.has(v) || v === "" || v === "auto" ? null : raw.trim();
+ } else if (/^thread\.(parent(\.\d)?|quoted|carry|reveal|shrink|dim|seconds|pan|map)$/.test(k)) {
if (out.thread === null) throw new CliError("thread=auto goes alone");
const t = (out.thread ??= {});
const knob = k.split(".")[1];
- const clear = v === "default" || v === "" || (v === "auto" && knob !== "parent" && knob !== "quoted" && knob !== "carry");
+ const clear = v === "default" || v === "" || (v === "auto" && knob !== "parent" && knob !== "quoted" && knob !== "carry" && knob !== "map");
if (knob === "parent" && k.split(".").length === 3) {
const i = Number(k.split(".")[2]);
- const list = Array.isArray(t.parent) ? t.parent : typeof t.parent === "string" ? [t.parent, t.parent] : ["auto", "auto"];
+ const list = Array.isArray(t.parent) ? t.parent : typeof t.parent === "string" ? Array.from({ length: i + 1 }, () => t.parent) : Array.from({ length: i + 1 }, () => "auto");
+ while (list.length < i + 1) list.push("auto");
list[i] = clear ? "auto" : v;
- t.parent = list.slice(0, Math.max(1, i + 1, list.length)).slice(0, 2);
+ t.parent = list.slice(0, Math.max(1, i + 1, list.length)).slice(0, 8);
} else if (knob === "parent" || knob === "quoted") t[knob] = clear ? null : v;
else if (knob === "carry") t.carry = clear ? null : v === "auto" ? "auto" : onOff(v, k);
else if (knob === "reveal") t.reveal = clear ? null : onOff(v, k);
+ else if (knob === "map") {
+ // The branch map (post-branch-map.mjs): on|off, or its style map|label|both; auto: the cut's.
+ if (v === "auto" || clear) t.map = null;
+ else if (["map", "label", "both"].includes(v)) t.map = v;
+ else t.map = onOff(v, k);
+ }
else {
t[knob] = clear ? null : Number(raw);
if (typeof t[knob] === "number" && !Number.isFinite(t[knob])) throw new CliError(`${k}= takes a number`);
}
}
+ // Where the attachments sit (post-item.mjs postLayout): auto (beside the card; a wide one above it), side, top, bottom.
+ else if (k === "panel") {
+ if (!["auto", "side", "top", "bottom", ""].includes(v)) throw new CliError("panel= takes auto, side, top or bottom");
+ out.panel = v === "auto" || v === "" ? null : v;
+ }
+ // AN ATTACHMENT FROM A PROJECT FILE (operator, 4 Nov: "this needs to include the cat video"): measured when it goes in.
+ else if (k === "media.add") (out.mediaAdd ??= []).push(fileArg(raw, k));
+ else if (/^media\.\d+$/.test(k)) {
+ if (!OFF.has(v)) throw new CliError(`${k}= takes off (the attachment removed)`);
+ ((out.media ??= {})[k.split(".")[1]] = null);
+ }
+ // AN ANCESTOR, ADDED OR REPLACED (a whole-thread read): parent.<i>=<json ref>|@<file.json>|off, nearest first.
+ else if (/^parents?\.\d+$/.test(k)) (((out.parents ??= {})[k.split(".")[1]] ??= {}).ref = OFF.has(v) ? null : refArg(raw, k));
+ else if (/^parents?\.\d+\.media$/.test(k)) (((out.parents ??= {})[k.split(".")[1]] ??= {}).media = OFF.has(v) || v === "" ? null : raw.split(",").map((f) => fileArg(f, k)));
+ // A POST ITS WORDS LINK TO (a link visit): link.add=<json ref>, link.<i>=<json>|off, link.<i>.media=<file>|off,
+ // link.<i>.transcript=<words read off its picture>|off.
+ else if (k === "link.add") (out.linksAdd ??= []).push(refArg(raw, k));
+ else if (/^links?\.\d+$/.test(k)) (((out.links ??= {})[k.split(".")[1]] ??= {}).ref = OFF.has(v) ? null : refArg(raw, k));
+ else if (/^links?\.\d+\.media$/.test(k)) (((out.links ??= {})[k.split(".")[1]] ??= {}).media = OFF.has(v) || v === "" ? null : raw.split(",").map((f) => fileArg(f, k)));
+ else if (/^links?\.\d+\.transcript$/.test(k)) (((out.links ??= {})[k.split(".")[1]] ??= {}).transcript = OFF.has(v) || raw.trim() === "" ? null : raw);
else if (k === "quoted.paraphrase") out.quoted = { paraphrase: paraphraseOf(raw) };
- else if (/^parents?\.\d+\.paraphrase$/.test(k)) (out.parents ??= {})[k.split(".")[1]] = { paraphrase: paraphraseOf(raw) };
+ else if (/^parents?\.\d+\.paraphrase$/.test(k)) ((out.parents ??= {})[k.split(".")[1]] ??= {}).paraphrase = paraphraseOf(raw);
else if (/^media\.\d+\.blur(\.(strength|label|boxes|band|style))?$/.test(k)) {
// The censoring blur (post-censor.mjs): on|off, its strength, its label (off: none), its boxes (x,y,w,h;…|off),
// its band (below:0.38, between:0.2,0.6, left:0.5 … |off), its style (blur|black|pixelate|off: blur).
@@ -723,7 +797,7 @@ export function postItemPatchOf(pairs) {
}
} else {
const m = /^media\.(\d+)\.(start|end|mute|crop|push|trim)$/.exec(k);
- if (!m) throw new CliError(`${pair}: not a post item knob (hold=, layout=, redact=, scene=, follow=, follow.dim|ease=, thread=, thread.parent|quoted|carry|reveal|shrink|dim|seconds|pan=, media.<i>.start|end|mute|crop|push|trim=, media.<i>.blur[.strength|.label|.boxes|.band|.style]=, media.<i>.censor=, quoted.paraphrase=, parent.<i>.paraphrase=)`);
+ if (!m) throw new CliError(`${pair}: not a post item knob (hold=, layout=, panel=, redact=, scene=, follow=, follow.dim|ease=, thread=, thread.parent|quoted|carry|reveal|shrink|dim|seconds|pan|group|map=, media.add=, media.<i>=off, media.<i>.start|end|mute|crop|push|trim=, media.<i>.blur[.strength|.label|.boxes|.band|.style]=, media.<i>.censor=, quoted.paraphrase=, parent.<i>=<ref>|off, parent.<i>.media=, parent.<i>.paraphrase=, link.add=, link.<i>=<ref>|off, link.<i>.media=, link.<i>.transcript=)`);
const media = (out.media ??= {});
const one = (media[m[1]] ??= {});
if (m[2] === "start" || m[2] === "end") one[m[2]] = OFF.has(v) || v === "" ? null : Number(raw);
@@ -802,6 +876,40 @@ async function contextCommand(projectArg, { root, json, dryRun, out }) {
return 0;
}
+/**
+ * An attachment from a PROJECT FILE (`posts-media/…`), measured as `posts reel` measures one: `{ src, kind,
+ * width?, height?, seconds?, audio? }` -- refused when it is not there or a timed one cannot be measured.
+ */
+export async function attachmentOf(dir, rel) {
+ const file = path.join(dir, rel);
+ if (!(await stat(file).catch(() => null))) throw new CliError(`${rel} is not in the project (${file})`);
+ const { probeMediaFile, mediaKindOf } = await import("./postReel.mjs");
+ const probe = await probeMediaFile(file);
+ const kind = mediaKindOf(path.basename(rel), "", probe);
+ if (kind !== "image" && !Number.isFinite(probe.seconds)) throw new CliError(`${rel}: its length could not be measured (ffprobe)`);
+ return {
+ src: rel.split(path.sep).join("/"),
+ kind,
+ ...(probe.width ? { width: probe.width } : {}),
+ ...(probe.height ? { height: probe.height } : {}),
+ ...(kind !== "image" ? { seconds: probe.seconds } : {}),
+ ...(kind === "video" ? { audio: probe.audio === true } : {}),
+ };
+}
+
+/** Every `{ file }` marker of a set-item patch measured into an attachment (attachmentOf), in place. */
+async function resolveAttachments(patch, dir) {
+ const fix = async (list) => (Array.isArray(list) ? Promise.all(list.map((m) => (m && typeof m === "object" && typeof m.file === "string" && Object.keys(m).length === 1 ? attachmentOf(dir, m.file) : m))) : list);
+ if (patch.mediaAdd) patch.mediaAdd = await fix(patch.mediaAdd);
+ for (const group of [patch.parents, patch.links]) {
+ for (const v of Object.values(group ?? {})) {
+ if (Array.isArray(v.media)) v.media = await fix(v.media);
+ if (v.ref && Array.isArray(v.ref.media)) v.ref.media = await fix(v.ref.media);
+ }
+ }
+ for (const r of patch.linksAdd ?? []) if (Array.isArray(r.media)) r.media = await fix(r.media);
+}
+
/** `posts set-item`: a post item's knobs, through updatePostItem (`fit=read[:linger]`: posts fit, on this item). */
async function setItemCommand(projectArg, ref, pairs, { root, json, out, reread = true }) {
const fitPair = pairs.find((p) => /^fit=/.test(p));
@@ -839,6 +947,7 @@ async function setItemCommand(projectArg, ref, pairs, { root, json, out, reread
}
const patch = postItemPatchOf(pairs);
const project = await projectOf(projectArg, root);
+ await resolveAttachments(patch, project.dir);
const manifest = await readManifest(project.dir);
const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : [];
const hit = tl.find((e) => e?.type === "post" && (e.id === ref || String(e.post ?? "").split("/")[1] === ref));
diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs
@@ -43,6 +43,8 @@ import { validatePostScene, validatePostSceneRender } from "./post-media-scene.m
export const POST_ITEM_PLATFORMS = Object.freeze(["x", "bluesky", "web"]);
export const POST_MEDIA_KINDS = Object.freeze(["image", "video", "gif"]);
export const POST_MEDIA_LAYOUTS = Object.freeze(["sequence", "grid"]);
+/** Where an item's attachments sit (`panel`): beside the card, above it or below it at full width. */
+export const POST_PANELS = Object.freeze(["side", "top", "bottom"]);
/**
* THE DURATION RULE. A post item plays for the time it takes to read it, then
@@ -452,6 +454,8 @@ function refErrors(r, where) {
r.media.forEach((m, i) => errors.push(...mediaErrors(m, `${where}.media[${i}]`)));
}
}
+ // The words read off its picture (a linked post's screenshot, read in his voice): a block of the read with no card words.
+ if (r.transcript !== undefined && !(typeof r.transcript === "string" && r.transcript.length <= TEXT_MAX)) errors.push(`${where}.transcript must be the words read off its picture (a string)`);
if (r.paraphrase !== undefined) {
if (typeof r.paraphrase !== "string") errors.push(`${where}.paraphrase must be a string (your retelling of its words; absent: its own words)`);
else if (r.paraphrase.length > POST_PARAPHRASE_MAX) errors.push(`${where}.paraphrase is longer than ${POST_PARAPHRASE_MAX} characters (${r.paraphrase.length}): a paraphrase is short`);
@@ -518,6 +522,7 @@ export function validatePostItem(e) {
if (e.hold !== undefined && !(fin(e.hold) && e.hold >= POST_HOLD.min && e.hold <= POST_HOLD.max)) {
errors.push(`${w}.hold must be ${POST_HOLD.min}–${POST_HOLD.max} seconds (absent: the duration rule)`);
}
+ if (e.panel !== undefined && !POST_PANELS.includes(e.panel)) errors.push(`${w}.panel must be one of ${POST_PANELS.join(", ")} (where its attachments sit; absent: beside the card, a wide one above it)`);
if (e.mediaLayout !== undefined && !POST_MEDIA_LAYOUTS.includes(e.mediaLayout)) errors.push(`${w}.mediaLayout must be one of ${POST_MEDIA_LAYOUTS.join(", ")}`);
if (e.media !== undefined) {
if (!Array.isArray(e.media)) errors.push(`${w}.media must be a list of attachments`);
diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs
@@ -65,7 +65,9 @@ export const THREAD_CONTEXT_ROOM = 0.3;
/** `thread.group` (one item's): a MANUAL THREAD -- consecutive items of one group play as one scene (post-conversation.mjs). */
export const THREAD_GROUP_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,47}$/;
-const KEYS = new Set([...Object.keys(THREAD_DEFAULTS), "group"]);
+/** `thread.map`: the branch map (post-branch-map.mjs) -- on, off, or its style. */
+export const THREAD_MAP_VALUES = Object.freeze([true, false, "map", "label", "both"]);
+const KEYS = new Set([...Object.keys(THREAD_DEFAULTS), "group", "map"]);
const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
const fin = (v) => typeof v === "number" && Number.isFinite(v);
const str = (v) => (typeof v === "string" ? v : "");
@@ -91,6 +93,7 @@ export function threadKnobErrors(v, where) {
if (v.quoted !== undefined && !modeOk(v.quoted, false)) errors.push(`${where}.quoted must be one of ${THREAD_MODES.filter((m) => m !== "carry").join(", ")}`);
if (v.carry !== undefined && !(v.carry === "auto" || typeof v.carry === "boolean")) errors.push(`${where}.carry must be auto, true or false`);
if (v.reveal !== undefined && typeof v.reveal !== "boolean") errors.push(`${where}.reveal must be true or false`);
+ if (v.map !== undefined && !THREAD_MAP_VALUES.includes(v.map)) errors.push(`${where}.map must be true, false, "map", "label" or "both" (the branch map)`);
if (v.group !== undefined && !(typeof v.group === "string" && THREAD_GROUP_RE.test(v.group))) errors.push(`${where}.group must be a name (letters, digits, . _ -): the manual thread the item plays in`);
for (const k of ["shrink", "dim", "seconds", "pan"]) {
if (v[k] !== undefined && !(fin(v[k]) && v[k] >= THREAD_LIMITS[k][0] && v[k] <= THREAD_LIMITS[k][1])) {