commit de25db037b1ffe12943a30f95b3eca46dc9375ac
parent 7cfb31184c2a448654c38dd9b2c7d5689a260cca
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 4 Nov 2026 12:55:28 -0500
umtool: timeline insert post-json:<json>|@<file> -- a post item made by hand (a post no archive holds, kept only as a picture: Kirsche's reply), its media measured from project files, refused as the build would
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/umtool/lib/report/postThreadScenes.test.mjs b/umtool/lib/report/postThreadScenes.test.mjs
@@ -75,3 +75,22 @@ test("set-item link.add: a post its words link to, with a picture and the words
assert.equal((await cli(["set-item", "links", "p-2", "link.0=off"])).code, 0);
assert.equal((await manifest(p)).timeline[0].links, undefined);
});
+
+test("timeline insert post-json: a post no archive holds (Kirsche's reply kept only as a picture) -- its author, handle, date, words and its picture, measured; refused as the build would", { skip: !ffmpeg && "no ffmpeg" }, async () => {
+ const { timelineCommand } = await import("./timelineCli.mjs");
+ const p = await project("synthetic", [item("1")]);
+ await mkdir(path.join(p.dir, "posts-media", "KirscheVerstahl-x", "2115523442074087838"), { recursive: true });
+ execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=gray:s=1127x500", "-frames:v", "1", path.join(p.dir, "posts-media/KirscheVerstahl-x/2115523442074087838/2115523442074087838_1.jpg")]);
+ const json = JSON.stringify({ post: "KirscheVerstahl-x/2115523442074087838", author: "Kirsche", handle: "@KirscheVerstahl", date: "2026-10-28T19:17:00.000Z", text: "@ObviousRises", media: ["posts-media/KirscheVerstahl-x/2115523442074087838/2115523442074087838_1.jpg"] });
+ const lines = [];
+ const errs = [];
+ const code = await timelineCommand(["synthetic", "insert", "--after", "p-1", `post-json:${json}`], { root: REPORTS, out: (s) => lines.push(s), err: (s) => errs.push(s) });
+ assert.equal(code, 0, errs.join("\n"));
+ const e = (await manifest(p)).timeline[1];
+ assert.equal(e.id, "p-2115523442074087838");
+ assert.equal(e.handle, "KirscheVerstahl");
+ assert.deepEqual(e.media, [{ src: "posts-media/KirscheVerstahl-x/2115523442074087838/2115523442074087838_1.jpg", kind: "image", width: 1127, height: 500 }]);
+ const bad = await timelineCommand(["synthetic", "insert", "--after", "p-1", 'post-json:{"post":"x","text":"a"}'], { root: REPORTS, out: () => {}, err: (s) => errs.push(s) });
+ assert.notEqual(bad, 0);
+ assert.match(errs.join("\n"), /post must be <channel>\/<postId>/);
+});
diff --git a/umtool/lib/report/timelineCli.mjs b/umtool/lib/report/timelineCli.mjs
@@ -105,6 +105,9 @@ export const TIMELINE_USAGE = [
" are dates gets --date as one too. The section is <id>'s unless --section says",
" umtool timeline <project> insert (--after <id|-> | --to-section N | --group G) post:<channel>/<postId> [--id ID]",
" a POST ITEM from the posts archive (its card and attachments; umtool posts reel makes many)",
+ " umtool timeline <project> insert (--after <id|-> | --to-section N | --group G) post-json:<json>|post-json:@<file> [--id ID]",
+ " a POST ITEM BY HAND (one no archive holds): {post: \"<channel>/<postId>\", author, handle, date, text,",
+ " media: [\"posts-media/…\"], parents?, quoted?, subjects?} -- its media measured; its avatar: umtool posts avatar",
" umtool timeline <project> insert (--to-section N | --group G) <channel>/<video>@<start>-<end> [same flags]",
" at the END of section N, or after group G's last clip and one of its clips (the run stays",
" together): one write, the marker after that clip re-anchored after the new one; the",
@@ -203,6 +206,29 @@ export function splitTimelineArgs(args) {
}
/** A JSON argument, or `@file` for one read from disk. */
+/**
+ * A POST ITEM made by hand (`insert post-json:…`): the fields as given -- `post` "<channel>/<postId>", `author`,
+ * `handle`, `date`, `text`, optional `url`, `parents`, `quoted`, `subjects`, `engagement` -- its `media` named as
+ * project files and measured (postsCli.mjs attachmentOf); its `id` p-<postId> unless --id; refused as the build would.
+ */
+async function handPostItem(project, manifest, raw, { id = null } = {}) {
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new CliError("post-json takes a post item as a JSON object");
+ const { attachmentOf } = await import("./postsCli.mjs");
+ const { validatePostItem } = await import("umtool-report-to-video/post-item");
+ const postId = String(raw.post ?? "").split("/")[1] ?? "";
+ const media = [];
+ for (const m of Array.isArray(raw.media) ? raw.media : []) media.push(typeof m === "string" ? await attachmentOf(project.dir, m) : m);
+ const { media: _m, id: _i, type: _t, ...rest } = raw;
+ void _m;
+ void _i;
+ void _t;
+ const entry = { type: "post", id: id ?? (typeof raw.id === "string" ? raw.id : `p-${postId}`), platform: "x", ...rest, ...(typeof rest.handle === "string" ? { handle: rest.handle.replace(/^@/, "") } : {}), ...(media.length ? { media } : {}) };
+ if ((manifest.timeline ?? []).some((e) => e?.id === entry.id)) throw new CliError(`${entry.id} is already in the cut (--id another)`);
+ const errors = validatePostItem(entry);
+ if (errors.length) throw new CliError(`post-json: ${errors.join("; ")}`);
+ return entry;
+}
+
async function jsonArg(raw, what) {
if (raw === undefined || raw === "") throw new CliError(`${what} needs a JSON value (or @file)`);
const text = raw.startsWith("@") ? await readFile(path.resolve(raw.slice(1)), "utf8") : raw;
@@ -545,7 +571,19 @@ export async function timelineCommand(args, { root = REPORTS_ROOT, out = (s) =>
if (flags.has("--after") && (toSection !== null || group !== null)) throw new CliError("insert takes --after, or --to-section / --group, not both");
const afterArg = flags.has("--after") ? String(flags.get("--after")) : "";
const after = afterArg === "-" || afterArg === "" ? null : afterArg;
- const spec = need(rest[0], "a clip: <channel>/<video>@<start>-<end> (or a post item: post:<channel>/<postId>)");
+ const spec = need(rest[0], "a clip: <channel>/<video>@<start>-<end> (or a post item: post:<channel>/<postId>, or post-json:<json>|@<file>)");
+ // A POST ITEM BY HAND (a post no archive holds: one kept only as a screenshot): post-json:<json> or
+ // post-json:@<file> -- { post: "<channel>/<postId>", author, handle, date, text, media: ["posts-media/…"], … }.
+ if (/^post-json:/.test(spec)) {
+ const raw = await jsonArg(spec.slice("post-json:".length), "post-json");
+ const entry = await handPostItem(project, manifest, raw, { id: flags.has("--id") ? String(flags.get("--id")) : null });
+ if (toSection !== null || group !== null) {
+ ({ result, editNotes } = await write((token) => insertInto(project.dir, entry, toSection !== null ? { section: toSection } : { group }, { token })));
+ } else {
+ ({ result, editNotes } = await write((token) => insertEntry(project.dir, after, entry, { token, at })));
+ }
+ break;
+ }
// A POST ITEM (post-item.mjs): `post:<channel>/<postId>` from the posts archive, as `posts reel` makes it.
if (/^post:/.test(spec)) {
const m = /^post:([A-Za-z0-9][A-Za-z0-9._-]*)\/([A-Za-z0-9_-]+)$/.exec(spec);