Archilyzer · Source

archilyzer

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

commit 405fbaed67078b2cb0e8445d6164a3c24ffe08fb
parent 573a508288188553a86ab3fed228633a490fa7bb
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 27 Oct 2026 13:45:20 -0400

umtool: a report video's post can draw a reply with the post it answers (posts[].thread)

A manifest post's `thread: true` draws its capture's shot-thread.png
(deck.mjs threadShotOf: beside its `shot`) in place of the shot, and its
own shot while the capture has taken none (compose-chrome.mjs
postThreadFile). validatePosts takes it as a boolean, only on a post with
a shot.

The feed draws a thread shot whole (feedShotWhole, carried only by a page
with one, so every other page stays byte for byte -- checked against the
previous chrome-feed.mjs): when it would not fit at its full height beside
the card under it, it takes the column and that card is pushed out, and
one taller than the column is scaled to fit by .shot's object-fit:
contain, never cut. The popup posts pan through it as through any tall
shot. In the Huck cut's column (778 px, image 530 px wide) the proof's
598x312 thread shot draws at 277 px, under the 292 px card cap.

Writers: updatePosts / normalizePostPatches / applyPostsDraft take
`thread` (false removes the key); upsertPost keeps it like attachTo.
`umtool posts add ... --thread`, and the new `umtool posts set <project>
<post> thread=on|off [hide=] [attach=]` (the Posts table's writer from a
terminal); the On-screen Posts table gains a thread box, shown once a
thread shot is on disk (GET /api/report/onscreen says hasThreadShot).

Docs: knobs.md row, cli.md, OPERATING.md (capture with "thread": true,
then posts set), CHANGELOG, COMMANDS.md regenerated.

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

Diffstat:
MCOMMANDS.md | 2+-
MOPERATING.md | 13+++++++++++++
Meditor/CHANGELOG.md | 2++
Mumtool/app/api/report/onscreen/route.ts | 14+++++++++++++-
Mumtool/app/api/report/posts/route.ts | 14++++++++------
Mumtool/bin/umtool.mjs | 10+++++++---
Mumtool/components/projects/OnscreenSection.tsx | 30++++++++++++++++++++++++++----
Mumtool/docs/cli.md | 3++-
Mumtool/docs/knobs.md | 1+
Mumtool/lib/report/manifest.mjs | 45++++++++++++++++++++++++++++-----------------
Mumtool/lib/report/manifest.test.mjs | 25++++++++++++++++++++++++-
Mumtool/lib/report/onscreen.mjs | 11++++++++++-
Mumtool/lib/report/onscreen.test.mjs | 19++++++++++++++++++-
Mumtool/lib/report/postsCli.mjs | 109+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mumtool/lib/report/postsCli.test.mjs | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/chrome-feed.mjs | 46++++++++++++++++++++++++++++++++++++++++++----
Mumtool/report-to-video/chrome-feed.test.mjs | 47++++++++++++++++++++++++++++++++++++++++++++++-
Mumtool/report-to-video/chrome-posts.test.mjs | 35++++++++++++++++++++++++++++++++++-
Mumtool/report-to-video/compose-chrome.mjs | 34++++++++++++++++++++++++++++------
Mumtool/report-to-video/deck.mjs | 28+++++++++++++++++++++++++++-
20 files changed, 491 insertions(+), 56 deletions(-)

diff --git a/COMMANDS.md b/COMMANDS.md @@ -130,7 +130,7 @@ Drives a running editor over HTTP (`/api/ops/*`, the same actions its pages run) | `retry-bucket` | retry-bucket runs one bucket of a channel's report as one job, past any lane hold: {"slug", "bucket"}. "ids": \[...\] runs only those videos, and every one must be in the bucket (a stray id is refused, named); a job run with ids is not replayable, as a checkbox selection in the UI is not. "corruptFullSource" downloads again: the kept file is set aside, and comes back if the download fails; malformed again, the longer decode stays. A record that stores an Odysee media URL is read from that URL (as "only") until 2 such downloads are on record, then from the page. "storedUrl": "fallback" \| "only" reads each from the media URL its record stores, as on download-missing (a held platform's retry runs as "only"). "corruptHeldAudio" (held audio the audio audit found damaged) is refetched the same way, with the audio check on; the new file is audited again. | `pnpm ops retry-bucket --json '{"slug":"demo-odysee","bucket":"corruptHeldAudio"}' --wait` | | `transcribe-bucket` | transcribe-bucket transcribes a channel's "downloaded, not transcribed" bucket on the transcription queue, as the channel page's Transcribe button does: {"slug"}. "ids": \[...\] narrows it the same way as on retry-bucket. | | | `fetch-posts` | fetch-posts fetches a social channel's new posts: {"slug"}. "full": true re-walks the whole timeline; "older": true walks back from the oldest archived post through search (X; needs a login), saving its place for the next run, down to "floor": "YYYY-MM-DD" when given; "from": "YYYY-MM-DD" starts the walk afresh there, replacing its saved place (and a "complete") — for a gap above one surviving old post. "limit": N caps the posts one run reads; "pages": N caps the pages (a forum thread: its latest N pages). A forum thread keeps two positions: a run catches up from the last page, then continues the history where it stopped; "full": true is its full re-walk (every page, edits updated). "retryOnBlock": {"minutes": 30, "max": 12} (or true: the forum default in settings) waits out a challenge or refusal page and runs again, max tries in all. "full" and "older" together are refused. An older walk over an account that shows no posts (nothing archived, and the last timeline fetch read none) is refused unless "force": true. A drained fetch stops at its next resume point and the next run resumes. | | -| `capture-posts` | capture-posts captures archived posts of a social channel (X, forum, Bluesky): a screenshot of each through the connected X profile (a forum thread: its host's forum profile; Bluesky: a headless browser with no login on bsky.app, the shot cropped to the post), and its attached media through gallery-dl (a forum thread: the same profile; Bluesky: its images from the CDN), into the channel's posts-media/&lt;id&gt;/: {"slug", "ids": \[...\]}. Every id must be in the channel's posts archive. "shots": false or "media": false skips that half; posts already captured are skipped unless "force": true. A post that links to an X Article also gets the article (article.json, .md, .png and its images) unless "articles": false; both halves off with "articles": true reads only the articles. Paced like a post fetch, on its queue. | | +| `capture-posts` | capture-posts captures archived posts of a social channel (X, forum, Bluesky): a screenshot of each through the connected X profile (a forum thread: its host's forum profile; Bluesky: a headless browser with no login on bsky.app, the shot cropped to the post), and its attached media through gallery-dl (a forum thread: the same profile; Bluesky: its images from the CDN), into the channel's posts-media/&lt;id&gt;/: {"slug", "ids": \[...\]}. Every id must be in the channel's posts archive. "shots": false or "media": false skips that half; posts already captured are skipped unless "force": true. A post that links to an X Article also gets the article (article.json, .md, .png and its images) unless "articles": false; both halves off with "articles": true reads only the articles. "thread": true (X; default the channel's postCaptureThread) also shoots each reply with the post it answers above it, as shot-thread.png beside shot.png (a post shot before gets only that); the replied-to author's avatar, name and handle are blurred unless verified or the reply's own. "threadRedact": false turns the blur off, true blurs any author; {"&lt;id&gt;": false} sets it per post. Paced like a post fetch, on its queue. | | | `publish` | publish runs publish stages on the editor's publish queue, one at a time, under one run id: {"verb": …}. "index" updates the index; "build" builds "siteId"/"siteIds" (forced; the index first when stale; "runner": "docker" builds every site in containers; "allowMissingMedia": true lets a report citation with no prepared media through compose, local builds only); "deploy" ships their built bundles (production, "preview": "&lt;branch&gt;", or "to": "local"; "force" redeploys a bundle already shipped there); "hub" / "homepage" build them, {"deploy": true} deploys after; "now" is Publish now (the stale index, then each policy target); "stale" builds every stale site. The answer lists every job ({target, kind, jobId}) and --wait follows them all. A site never built is refused: "no build of &lt;id&gt; in &lt;dir&gt; — archilyzer publish build &lt;id&gt;". `get publish` is the status. | | | `build-index`, `build-site`, `build-deploy`, `deploy-site`, `build-hub`, `deploy-hub`, `build-homepage`, `deploy-homepage` | build-index, build-site, build-deploy, deploy-site, build-hub, deploy-hub, build-homepage and deploy-homepage are publish's aliases, with their old bodies and answers ("skipData" is accepted and ignored). | `pnpm ops build-deploy --json '{"siteIds":["anilyzer","jeralyzer"]}' --wait`<br>`pnpm ops build-site --json '{"siteId":"anilyzer"}' --wait`<br>`pnpm ops deploy-site --json '{"siteId":"anilyzer","preview":"tags-exclude"}' --wait`<br>`pnpm ops build-hub --wait`<br>`pnpm ops build-hub --json '{"deploy":true}' --wait`<br>`pnpm ops deploy-hub --wait`<br>`pnpm ops build-homepage --json '{"deploy":true}' --wait`<br>`pnpm ops deploy-homepage --json '{"preview":"refresh"}' --wait` | | `build-site`, `build-deploy`, `deploy-site` | build-site, build-deploy and deploy-site all take "siteId" (one) or "siteIds" (a list). | | diff --git a/OPERATING.md b/OPERATING.md @@ -369,6 +369,19 @@ pnpm ops capture-posts --json '{"slug":"example-x","ids":["<postId>"]}' --wait age in minutes, the limit, `allowed`, and the refusal an X job would get (`reason`). An agent asks it first and, when `allowed` is false, asks the operator for a refresh instead of queueing. - `capture-posts` saves a screenshot and the attached media of named posts (and a linked X Article). + **A reply with the post it answers**: `"thread": true` (X; a channel's `postCaptureThread` makes it the + default) also writes `shot-thread.png` beside `shot.png` — the immediate parent over the reply, one page + load for both, and a post shot before gets only that. The replied-to author's avatar, name and handle (and + any link to them in the reply) are blurred unless they carry an organisation's gold or a government's grey + check, or are the reply's own author; X Premium's blue check is bought, so a blue-checked person is blurred + too. `"threadRedact": false` (or `{"<id>": false}` for one post) takes it unblurred, for an author you have + judged public. `capture.json`'s `thread` records the parent, its badge and every blurred box. A report + video draws it with `umtool posts set <project> <post> thread=on` (or `posts add … --thread`): + + ```sh + pnpm ops capture-posts --json '{"slug":"example-x-replies","ids":["<postId>"],"thread":true}' --wait + umtool posts set <project> <postId> thread=on + ``` - A **forum thread** keeps two positions (`posts-state.json` `forum`): **Fetch posts** catches up from the last page to the newest held post, then continues the history from where it stopped, down to page 1 — `"pages": N` caps the pages that hold anything new (an all-held page is stepped past uncounted), and a capped catch-up never moves diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ## [Unreleased] +- **A reply can be captured with the post it answers above it.** `capture-posts` with `"thread": true` (X; or a channel's new `postCaptureThread`, or the Thread shot box under Capture posts on an X channel's page) also writes `shot-thread.png` beside the post's `shot.png`: the post it replies to over the reply, in the same page load — only the immediate parent, a longer chain cut to it. The parent is the post the archive says it answers; with no archive word, the post directly above it on the page; a post the archive says is no reply is not opened for it, and a post shot before gets only its thread shot. **The replied-to author is blurred** — avatar, name and handle, and any link to them in the reply — unless they carry an organisation's gold or a government's grey check, or are the reply's own author. X Premium's blue check is bought, so a blue-checked person is blurred like anyone else (the first live proof's parent was one). `"threadRedact": false` (or `{"<id>": false}`) takes it unblurred; a parent whose name cannot be found to blur gets no thread shot. capture.json records the parent, its badge and every blurred box. Proved on TheQuartering's reply 2114214000653414579. Needs a restart of the editor. +- **A report video can draw a reply with the post it answers.** A manifest post's `thread: true` draws its capture's `shot-thread.png` in place of its shot (its own shot while there is none) — set with `umtool posts set <project> <post> thread=on`, `umtool posts add … --thread`, or the **thread** box in the On-screen Posts table. In the feed a thread shot is drawn whole: the card under it leaves rather than the reply being squeezed, and one taller than the column is scaled to fit, never cut. A cut with no thread shot renders byte for byte as before. - **An X post's screenshot is of the post, not of a page in the middle of laying itself out.** On 2026-10-27 a forced capture of TheQuartering's post 2114859155022389342 came out shifted about 100 px: its left edge cut off, X's menu laid over its words and the gap beside the column showing; another post once came out as a strip of the post above it. The shot was a full-page capture, which resizes the page for the moment of the capture — in the X session profile the page saw its window go to 1×1 — and X laid itself out again for that size while it was being captured, so the shot was cut from a different layout than the one measured. A post is now shot from the window as it stands: scrolled into it, the window made taller first when the post is taller than it, so nothing is resized under the shot; and the post is measured again after the shot and shot again if it moved. An X Article's shot is taken the same way. Posts taller than the tallest window (16,384 px) are still shot from a full-page capture. Needs a restart of the editor. - **Use with AI is the homepage's.** A published site's header and slide-out menu no longer carry it (nor the hub's header); a site still reaches the homepage's AI and MCP doc from its footer and from Ask AI, and its corpus.json and llms.txt still name it. Rebuild a site to see it. - **The site-swap intro no longer shifts vertically on the chime.** With the URLs under MEDIA the drawing used to rise to stay centred; the lockup is now centred as the plain intro centres it and the URLs hang below it, so on the chime it only moves sideways. Intros without a site swap are unchanged. diff --git a/umtool/app/api/report/onscreen/route.ts b/umtool/app/api/report/onscreen/route.ts @@ -1,3 +1,5 @@ +import { stat } from "node:fs/promises"; +import path from "node:path"; import { withEditNotes } from "@/lib/report/guard"; import { StaleToken, manifestToken, updateOnscreen } from "@/lib/report/manifest.mjs"; import { postRows, scheduleForPreview } from "@/lib/report/onscreen.mjs"; @@ -50,6 +52,16 @@ export async function GET(request: Request) { const provenance = cut.provenance ?? {}; const multi = isMultiChannel(entries, provenance); const posts = postRows({ variantManifest: cut, metas, schedule }); + // Whether each post's thread shot (shot-thread.png beside its shot) is on + // disk: the Posts table's thread box draws it only then. + const withThreads = await Promise.all( + posts.posts.map(async (p: { threadShot: string | null }) => ({ + ...p, + hasThreadShot: p.threadShot + ? Boolean(await stat(path.resolve(/* turbopackIgnore: true */ r.project.dir, p.threadShot)).catch(() => null)) + : false, + })), + ); const rows = entries.map((e, i) => { const { onscreen, ...bare } = e; return { @@ -68,7 +80,7 @@ export async function GET(request: Request) { rows, maxChars: deck.title.maxChars, multiChannel: multi, - posts: posts.posts, + posts: withThreads, clips: posts.clips, postsShown: deck.posts.show, postsEstimated: schedule.estimated === true, diff --git a/umtool/app/api/report/posts/route.ts b/umtool/app/api/report/posts/route.ts @@ -5,13 +5,15 @@ import { refuseCaller } from "@/lib/report/caller"; export const dynamic = "force-dynamic"; -// The two decisions a person makes about a post once it is in the manifest: -// which clip it rides on (`attachTo`, null for the automatic one) and whether -// it is shown (`hide`). Adding, removing or rewording posts is not here -- -// they are written into the manifest by whoever cites them. +// The decisions a person makes about a post once it is in the manifest: +// which clip it rides on (`attachTo`, null for the automatic one), whether +// it is shown (`hide`), and -- a reply -- whether it is drawn with the post it +// answers above it (`thread`: its capture's shot-thread.png, when there is +// one). Adding, removing or rewording posts is not here -- they are written +// into the manifest by whoever cites them. // // PUT is the Posts table's one save: `{ project, posts: { <id>: { attachTo?, -// hide? } }, token }`. One unknown id, one bad value, or a result the build's +// hide?, thread? } }, token }`. One unknown id, one bad value, or a result the build's // validatePosts refuses fails the WHOLE batch and nothing is written. The // client sends a project id, never a path. Read through GET // /api/report/onscreen, which carries the rows and the token. @@ -35,7 +37,7 @@ export async function PUT(request: Request) { const { result: res, editNotes } = await withEditNotes(r.project, () => updatePosts( r.project.dir, - body.posts as Record<string, { attachTo?: string | null; hide?: boolean }>, + body.posts as Record<string, { attachTo?: string | null; hide?: boolean; thread?: boolean }>, { token: body.token === undefined ? null : String(body.token) }, ), ); diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -74,7 +74,8 @@ // [--date …] [--quote …] [--cite S] | move <id> --to <index> | remove <id> | duplicate <id> | // post <json|@file> | post-remove <id> | teaser <id> <patch-json> | undo] the cut's structure // umtool scenes <project> <clip> [--black-min 0.05] [--threshold 8] [--json] cuts + black spans, source seconds -// umtool posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag …] a post from the archive +// umtool posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag …] [--thread] a post from the archive +// set <project> <post> thread=on|off [hide=on|off] [attach=<clipId>|auto] the Posts table's writer import process from "node:process"; import { PROJECT_KINDS, @@ -807,9 +808,12 @@ function usage() { " umtool scenes <project> <clip> [--black-min 0.05] [--threshold 8] [--pix-th 0.10] [--pad 30 | --from S --to S] [--json]", " scene cuts (scdet) and black spans (blackdetect) in the clip's fetched window, in SOURCE", " seconds — for blur.from/blur.to and trims; nothing fetched (`umtool fetch` first)", - " umtool posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag F] [--author A] [--id ID] [--json]", + " umtool posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag F] [--author A] [--id ID] [--thread] [--json]", " a post entry from the corpus's posts archive, its screenshot copied into posts-media/;", - " refused when the post has no shot (`pnpm ops capture-posts` first)", + " refused when the post has no shot (`pnpm ops capture-posts` first); --thread: a reply drawn", + " with the post it answers above it (shot-thread.png, capture-posts \"thread\": true)", + " umtool posts set <project> <post> thread=on|off [hide=on|off] [attach=<clipId>|auto] [--json]", + " the Posts table's writer (updatePosts); <post> is x-<postId> or the bare <postId>", "", `reading ${REPORTS_ROOT} (set REPORTS_DIR to move it)`, "", diff --git a/umtool/components/projects/OnscreenSection.tsx b/umtool/components/projects/OnscreenSection.tsx @@ -113,7 +113,7 @@ export type DeckPreviewDoc = { verdictLabels?: Record<string, string>; }; /** An unsaved change to a post, as PUT /api/report/posts takes it. */ -export type PostPatch = { attachTo?: string | null; hide?: boolean }; +export type PostPatch = { attachTo?: string | null; hide?: boolean; thread?: boolean }; /** What each segment's panel should say right now, by entry id. */ export type DeckTexts = Record<string, { title: string; subtitle: string }>; export type Onscreen = { title?: string; subtitle?: string }; @@ -742,13 +742,16 @@ type PostRow = { url: string; attachTo: string | null; hide: boolean; + // Drawn with the post it answers above it (its thread shot), when there is one. + thread?: boolean; + hasThreadShot?: boolean; auto: PostWhere | null; effective: PostWhere | null; timing: { segment: string; slot: number; of: number; appear?: number; out?: [number, number]; in?: number } | null; }; type ClipOption = { id: string; label: string; day: string | null; from?: number }; /** A post's row as the form holds it: `attachTo` "" is the automatic clip. */ -type PostDraft = { attachTo: string; hide: boolean }; +type PostDraft = { attachTo: string; hide: boolean; thread: boolean }; type JobView = { id: string; state: "running" | "done" | "failed"; @@ -776,13 +779,14 @@ const claimValue = (d: Draft): Claim | null => d.claimId.trim() || d.verdict ? { id: d.claimId.trim(), verdict: d.verdict } : null; /** A row's draft as the writer takes it: the text, and the claim beside it. */ const rowValue = (d: Draft): OnscreenRow => ({ ...(onscreenValue(d) ?? {}), claim: claimValue(d) }); -const postDraftOf = (p: PostRow): PostDraft => ({ attachTo: p.attachTo ?? "", hide: p.hide }); -const samePost = (a: PostDraft, b: PostDraft) => a.attachTo === b.attachTo && a.hide === b.hide; +const postDraftOf = (p: PostRow): PostDraft => ({ attachTo: p.attachTo ?? "", hide: p.hide, thread: p.thread === true }); +const samePost = (a: PostDraft, b: PostDraft) => a.attachTo === b.attachTo && a.hide === b.hide && a.thread === b.thread; /** Only what changed, in the writer's shape. */ const postPatch = (d: PostDraft, saved: PostDraft): PostPatch => { const p: PostPatch = {}; if (d.attachTo !== saved.attachTo) p.attachTo = d.attachTo || null; if (d.hide !== saved.hide) p.hide = d.hide; + if (d.thread !== saved.thread) p.thread = d.thread; return p; }; const clipText = (id: string, label: string) => (label ? `${id} — ${label}` : id); @@ -1646,6 +1650,7 @@ export default function OnscreenSection({ <th className="px-1.5 py-0.5">words</th> <th className="w-72 px-1.5 py-0.5">rides on</th> <th className="w-12 px-1.5 py-0.5 text-center">hide</th> + <th className="w-14 px-1.5 py-0.5 text-center" title="a reply: drawn with the post it answers above it (its thread shot)">thread</th> </tr> </thead> <tbody> @@ -1749,6 +1754,23 @@ export default function OnscreenSection({ aria-label={`hide post ${p.id}`} /> </td> + <td className="px-1.5 py-1 text-center"> + {/* Only a post whose capture took a thread shot, or one already set (so it can be cleared). */} + {(p.hasThreadShot || d.thread || p.thread) && ( + <input + type="checkbox" + data-testid="onscreen-post-thread" + checked={d.thread} + onChange={(e) => set({ thread: e.target.checked })} + aria-label={`draw post ${p.id} with the post it answers`} + title={ + p.hasThreadShot + ? "draw the reply with the post it answers above it (shot-thread.png)" + : "no thread shot on disk: its own shot is drawn (pnpm ops capture-posts with \"thread\": true)" + } + /> + )} + </td> </tr> ); })} diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -56,7 +56,8 @@ Inbox cannot disagree about what is wrong with one. | `clips analyze <project> [--from <channel>/<id>] [--rescan] [--no-laughs] [--no-voices] [params] [--words FILE] [--progress ndjson] [--json]` · `clips propose <project> [--from <channel>/<id>] [--host N] [params] [--words FILE] [--dry] [--json]` · `clips show <project> [--json]` · `clips segments <project> [--json]` | the **clip finder** on a long recording ([report-video.md](report-video.md#highlights-the-clip-finder)): `analyze` runs the laugh scan (CED-mini) and a voice centroid per speaker on the recording's sound (cached in `<project>/scans/`), then proposes; `propose` proposes again from what is there (after a role flip, a param change, new words); `show` prints the speakers, laughs and the cut. Params `--target S` (600) `--laugh-min X` (0.25) `--merge-gap S` (6) `--setup-max S` (20) `--clip-max S` (75) and the scope `--scope FROM:TO` (either side may be empty; `all` clears it) or `--from S --to S` with numbers (a `--from` that is a `<channel>/<id>` names the recording), kept in `reactions.json`; `--host N` is your word on the host, kept. `--keep-cut` proposes without touching the cut (nothing moved, removed or added; the proposals are listed). **`--scope auto`** reads the narrated video auto-scope finds in the speaker turns (`--segment sN` names one, else the longest); `segments` lists them. A chat replay beside the recording (`live_chat.cues.json`) adds chat-burst moments and the log names the chat's lag. A channel on no site gets each clip linked to its platform page (`citeUrl`). A clip you edited, ruled, locked or added is never moved. **Exit 2** with no `diarization.json` (the message names the `archilyzer diarize backfill` to run) | | `timeline <project> [ls] [--json]` · `timeline <project> insert --after <id\|-> <channel>/<video>@<start>-<end> [--id ID] [--section N] [--lock] [--lock-end] [--title T] [--stream-title T] [--date YYYY-MM-DD] [--quote Q] [--cite S] [--cite-url U]` · `timeline <project> move <id> --to <index>` · `remove <id>` · `duplicate <id>` (`--at <index>` names one of an id's twins) · `post <json\|@file>` · `post-remove <id>` · `teaser <id> <patch-json\|@file>` · `undo` | the **structure** of the cut (the Cut tab's timeline, the On-screen section's teasers and posts) through the writers `POST /api/report/timeline` runs: `ls` prints index, id, type, video, start–end, date and title (`--json` adds the token and the posts); an insert's attribution is a second write through `window`'s writer, its date checked before anything is written; it is written in the manifest's own convention — under the deck `--title` is the deck's title (`onscreen.title`, `--stream-title` the stream's), a cut whose deck titles are dates gets `--date` as one in their format, and the clip takes the section of the clip it goes after (`--section N` names another) and, from the same recording, its deck title and its citation link. Every write snapshots the manifest first (`revisions/…-auto-before-<op>`), is refused only for what it breaks in the build's own words (**exit 1**), and on a generated manifest leaves an `edit` note ([report-video.md](report-video.md#structural-edits)) | | `scenes <project> <clip> [--black-min 0.05] [--threshold 8] [--pix-th 0.10] [--pad 30 \| --from S --to S] [--json]` | the picture's **scene cuts** (ffmpeg `scdet`, score ≥ threshold) and **black spans** (`blackdetect`) in the clip's fetched window, in SOURCE seconds — for `blur.from`/`blur.to` and trims ([knobs.md](knobs.md#a-clips-picture-blurred)). The window is the one the build would cut from (the project's `out/clips-raw`, the editor's `channels/<slug>/data/<id>/clips/`, a saved source); the extent ± `--pad` inside it is scanned. Nothing is fetched: **exit 1** with no window on disk (`fetch` first) | -| `posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag F] [--author A] [--id ID] [--dry-run] [--json]` | a **post card** from the corpus's posts archive (`channels/<slug>/posts/*.jsonl`): its words, date, link and handle; id `x-<postId>` (`bsky-`, `post-`); the author an earlier post by the same handle carries in the cut, else the archive's. Its capture (`posts-media/<postId>/`: `shot.png`, `capture.json`, the post's pictures) is copied to the project's `posts-media/<slug>/<postId>/` — or used where it is, when that folder links the channel's captures; never copied through a link anywhere else. Then `upsertPost` (a post with the id is replaced, its `attachTo` kept). **Exit 1** with no screenshot, naming the `pnpm ops capture-posts` to run | +| `posts set <project> <post> thread=on\|off [hide=on\|off] [attach=<clipId>\|auto] [--json]` | the Posts table's writer (`updatePosts`, `PUT /api/report/posts`) from a terminal: `<post>` is the manifest's id (`x-<postId>`) or the bare `<postId>`; `thread=on` draws a reply with the post it answers above it (`shot-thread.png` beside its `shot`, taken by `capture-posts` `"thread": true`; its own shot while there is none), `off` removes the key. Refused in the build's words (a post with no `shot`, an `attach` that is not a clip) — **exit 1** | +| `posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag F] [--author A] [--id ID] [--thread] [--dry-run] [--json]` | a **post card** from the corpus's posts archive (`channels/<slug>/posts/*.jsonl`): its words, date, link and handle; id `x-<postId>` (`bsky-`, `post-`); the author an earlier post by the same handle carries in the cut, else the archive's. Its capture (`posts-media/<postId>/`: `shot.png`, `capture.json`, the post's pictures) is copied to the project's `posts-media/<slug>/<postId>/` — or used where it is, when that folder links the channel's captures; never copied through a link anywhere else. Then `upsertPost` (a post with the id is replaced, its `attachTo` kept). **Exit 1** with no screenshot, naming the `pnpm ops capture-posts` to run. `--thread`: the entry gets `thread: true` (a reply drawn with the post it answers; `shot-thread.png` is copied with the rest, and with none yet it prints the `"thread": true` capture to run) | A project argument is an exact id, a directory, or a **unique** basename. Two projects answering to one name is reported, never resolved by picking one. diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -126,6 +126,7 @@ that mentions the seizure in question and one before it. The Marks box is on eve | `render.chrome.deck.<key>` — any of the deck's own keys (`finale`, `pip`, …), as JSON; refused in the build's words when it does not know the key or the value | On-screen settings (the ones it has a field for) | `umtool look <p> deck.finale='{…}'` | — | | `render.chrome.deck.markerLayout` — `stagger` or `truncate` when labels crowd (default: stagger only when a label would truncate) | markers, **layout** | `deck.markerLayout=truncate` | `PUT /api/report/chrome {project, token, markerLayout}` | | `render.chrome.deck.claims[]` — his explicit claims drawn against the record on the rail, at most 6: a `count` or a `goalpost` ([below](#claim-checks-on-the-rail)) | On-screen, **claim checks**: add a count / a goalpost, the clip picker, **use the playhead**, his words, the window's dates, the record's verdict, per, the claim; a goalpost's steps (**add a step**), each its from date and due durations; remove — the build's validator under each as it is typed | `umtool look <p> deck.claims='[…]'` (`deck.claims=` none) | `PUT /api/report/chrome {project, token, claims}` | +| `posts[].thread` — `true`: a reply drawn with the post it answers above it — the capture's `shot-thread.png` beside the post's `shot` (taken by `pnpm ops capture-posts --json '{"slug":…,"ids":[…],"thread":true}'`, the replied-to author's avatar, name and handle blurred unless gold- or grey-checked or the reply's own; `"threadRedact": false` takes it unblurred), the post's own shot while there is none; needs a `shot`. In the feed a thread shot is drawn whole: the card under it leaves rather than the reply being squeezed, and one taller than the column is scaled to fit, never cut; the popup posts pan through it as through any tall shot | Media, On-screen **Posts** table: **thread** (shown once a thread shot is on disk) | `umtool posts set <p> <post> thread=on` (`thread=off` clears it) · on add: `umtool posts add <p> <channel>/<postId> --thread` | `PUT /api/report/posts {project, token, posts: {<id>: {thread}}}` | | `render.blur` — `off`: every clip's picture as recorded, no caption (the uncensored variant); `on` (the default) blurs the clips that ask | Build, **Look**: **Blurred clips** | `umtool look <p> blur=off` · a take: `umtool take <p> --id uncensored --set render.blur=off` | `PUT /api/report/render {project, token, patch: {blur}}` | | `render.intro` — the brand sting the cut opens with: a style (`boot` `boot-wipe` `boot-dark` `boot-cascade` `boot-mark`) or `{style, ground?, mark?, sound?, seconds?, site?, swap?, url?, urlPlace?}`; absent is none ([report-video.md](report-video.md#the-brand-intro-renderintro)) | Build, **Look**: **Intro** | `umtool look <p> intro=boot-dark` (`intro=` none) · a take: `umtool take <p> --id intro-wipe --set render.intro=boot-wipe` | `PUT /api/report/render {project, token, patch: {intro}}` | | `render.intro.site` — on the chime, "Archi" becomes the cited site's name ("Jera"), "lyzer" stays, the colours go to its accent: `auto` (the site whose `siteUrl` is `provenance.siteOrigin`; none found, no swap), a site id, `{name, lead?, accent?, url?}`, or `none`/absent (the plain intro, byte for byte). `render.intro.swap` `swipe-down` (default) \| `roll` \| `wipe`; `render.intro.url` `both` (default: the site's, then archilyzer.pages.dev) \| `site` \| `project` \| `false`; `render.intro.urlPlace` `under` (default: one row under MEDIA) \| `replace` (MEDIA's place) | — (manifest or a take) | a take: `umtool take <p> --id intro-jera --set render.intro.style=boot-dark --set render.intro.mark=chime --set render.intro.site=auto` (`--set render.intro.swap=roll`, `--set render.intro.url=false`, `--set render.intro.urlPlace=replace`) · standalone: `node umtool/report-to-video/intro.mjs render --style boot-dark --mark chime --site auto --site-origin https://jeralyzer.pages.dev --swap wipe --out x.mp4` | `PUT /api/report/render {project, token, patch: {intro: {…, site}}}` | diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -1136,43 +1136,45 @@ export async function updateRender(dir, patch, { token = null } = {}) { } // --------------------------------------------------------------------------- -// POSTS: the two things a person decides about a post once an agent has put it -// in the manifest -- which clip it rides on, and whether it is shown at all. +// POSTS: the things a person decides about a post once an agent has put it +// in the manifest -- which clip it rides on, whether it is shown at all, and +// (a reply) whether it is drawn with the post it answers above it (`thread`: +// the capture's shot-thread.png in place of its shot, when there is one). // // Adding, removing or rewording a post is not here. A post is a quotation of // somebody else's words with a permalink; it is written by whoever cites it, // into the manifest, and this writer refuses to be a second way to do that. // --------------------------------------------------------------------------- -const POST_PATCH_KEYS = ["attachTo", "hide"]; +const POST_PATCH_KEYS = ["attachTo", "hide", "thread"]; /** * A batch of post patches, checked for shape before anything is read: post id - * → `{ attachTo?: string | null, hide?: boolean }`. `attachTo: ""` is the - * same as null (a select's "auto"). + * → `{ attachTo?: string | null, hide?: boolean, thread?: boolean }`. + * `attachTo: ""` is the same as null (a select's "auto"). * * @param {unknown} posts - * @returns {Record<string, { attachTo?: string | null, hide?: boolean }>} + * @returns {Record<string, { attachTo?: string | null, hide?: boolean, thread?: boolean }>} */ export function normalizePostPatches(posts) { if (!posts || typeof posts !== "object" || Array.isArray(posts)) { - throw new Error("posts must be an object of post id → { attachTo, hide }"); + throw new Error("posts must be an object of post id → { attachTo, hide, thread }"); } const ids = Object.keys(posts); if (!ids.length) throw new Error("nothing to change"); - /** @type {Record<string, { attachTo?: string | null, hide?: boolean }>} */ + /** @type {Record<string, { attachTo?: string | null, hide?: boolean, thread?: boolean }>} */ const out = {}; for (const id of ids) { const v = /** @type {Record<string, unknown>} */ (posts)[id]; if (!v || typeof v !== "object" || Array.isArray(v)) { - throw new Error(`${id}: a post patch must be an object with attachTo and/or hide`); + throw new Error(`${id}: a post patch must be an object with attachTo, hide and/or thread`); } for (const k of Object.keys(v)) { if (!POST_PATCH_KEYS.includes(k)) { - throw new Error(`${id}: ${k} is not something this writer changes (only attachTo and hide)`); + throw new Error(`${id}: ${k} is not something this writer changes (only attachTo, hide and thread)`); } } - /** @type {{ attachTo?: string | null, hide?: boolean }} */ + /** @type {{ attachTo?: string | null, hide?: boolean, thread?: boolean }} */ const p = {}; if ("attachTo" in v) { const a = /** @type {Record<string, unknown>} */ (v).attachTo; @@ -1185,15 +1187,20 @@ export function normalizePostPatches(posts) { if (typeof h !== "boolean") throw new Error(`${id}: hide must be true or false`); p.hide = h; } + if ("thread" in v) { + const t = /** @type {Record<string, unknown>} */ (v).thread; + if (typeof t !== "boolean") throw new Error(`${id}: thread must be true or false`); + p.thread = t; + } out[id] = p; } return out; } /** - * Patch the `attachTo` and `hide` of any number of posts, in one write. + * Patch the `attachTo`, `hide` and `thread` of any number of posts, in one write. * - * `attachTo: null` and `hide: false` DELETE the key -- the automatic clip and + * `attachTo: null`, `hide: false` and `thread: false` DELETE the key -- the automatic clip and * a shown post are what an absent key already says, and a manifest read by * humans should not carry `"hide": false` as if somebody decided it. A key the * patch does not name is left alone. @@ -1235,16 +1242,20 @@ export async function updatePosts(dir, posts, { token = null } = {}) { if (p.hide) post.hide = true; else delete post.hide; } + if ("thread" in p) { + if (p.thread) post.thread = true; + else delete post.thread; + } } const errors = validatePosts(manifest.posts, manifest.timeline ?? [], manifest.render); if (errors.length) throw new PostsRefused(errors); const nextToken = await writeManifestAtomic(dir, manifest); - /** @type {Record<string, { attachTo: string | null, hide: boolean }>} */ + /** @type {Record<string, { attachTo: string | null, hide: boolean, thread: boolean }>} */ const saved = {}; for (const id of ids) { const post = byId.get(id); - saved[id] = { attachTo: post.attachTo ?? null, hide: post.hide === true }; + saved[id] = { attachTo: post.attachTo ?? null, hide: post.hide === true, thread: post.thread === true }; } return { posts: saved, token: nextToken }; }); @@ -1745,7 +1756,7 @@ const POST_TEXT_KEYS = ["platform", "author", "handle", "date", "text", "url", " /** * Add a post, or replace the one with its id. The value is the post as it * should be stored: an empty optional string is dropped rather than written. - * `attachTo` and `hide` are kept from the stored post unless the value names + * `attachTo`, `hide` and `thread` are kept from the stored post unless the value names * them. Checked with the build's validatePosts. * * @param {string} dir @@ -1765,7 +1776,7 @@ export async function upsertPost(dir, post, { token = null } = {}) { if (v === undefined || v === null || (typeof v === "string" && !v.trim())) continue; next[k] = typeof v === "string" ? v.trim() : v; } - for (const k of ["attachTo", "hide"]) { + for (const k of ["attachTo", "hide", "thread"]) { const v = k in post ? post[k] : prev[k]; if (v === undefined || v === null || v === "" || v === false) continue; next[k] = v; diff --git a/umtool/lib/report/manifest.test.mjs b/umtool/lib/report/manifest.test.mjs @@ -21,6 +21,7 @@ import { updateClip, updateOnscreen, updatePosts, + upsertPost, } from "./manifest.mjs"; import { validateCutEdits } from "umtool-report-to-video/deck"; @@ -399,7 +400,7 @@ test("updatePosts: attachTo and hide round trip; null and false delete the key; try { const token = await manifestToken(dir); const res = await updatePosts(dir, { p1: { attachTo: "c02", hide: true }, p2: { attachTo: null, hide: false } }, { token }); - assert.deepEqual(res.posts, { p1: { attachTo: "c02", hide: true }, p2: { attachTo: null, hide: false } }); + assert.deepEqual(res.posts, { p1: { attachTo: "c02", hide: true, thread: false }, p2: { attachTo: null, hide: false, thread: false } }); assert.equal(res.token, await manifestToken(dir)); const raw = await readRaw(dir); assert.ok(raw.startsWith('{\n "slug"') && raw.endsWith("}\n"), "the CLI's formatting kept"); @@ -422,6 +423,28 @@ test("updatePosts: attachTo and hide round trip; null and false delete the key; } }); +test("updatePosts: thread round trips on a post with a shot (false deletes it); a post with no shot is refused it; upsertPost keeps it", async () => { + const m0 = withPosts(); + m0.posts[0].shot = "posts-media/acct/1/shot.png"; + const dir = await project(m0); + try { + const res = await updatePosts(dir, { p1: { thread: true } }); + assert.deepEqual(res.posts.p1, { attachTo: null, hide: false, thread: true }); + assert.equal(post(await read(dir), "p1").thread, true); + // Replaced by a writer that does not name it: kept, as attachTo is. + await upsertPost(dir, { ...m0.posts[0], text: "one, again" }); + assert.equal(post(await read(dir), "p1").thread, true); + await updatePosts(dir, { p1: { thread: false } }); + assert.ok(!("thread" in post(await read(dir), "p1")), "thread: false deletes the key"); + await assert.rejects(updatePosts(dir, { p1: { thread: "yes" } }), /thread must be true or false/); + const before = await readRaw(dir); + await assert.rejects(updatePosts(dir, { p2: { thread: true } }), /posts\[1\]\.thread draws the thread shot beside the post's shot/); + assert.equal(await readRaw(dir), before); + } finally { + await rm(dir, { recursive: true, force: true }); + } +}); + test("updatePosts: an unknown post id refuses the WHOLE batch and writes nothing", async () => { const dir = await project(withPosts()); try { diff --git a/umtool/lib/report/onscreen.mjs b/umtool/lib/report/onscreen.mjs @@ -36,6 +36,7 @@ import { postWindows, resolveDeck, roundPosts, + threadShotOf, transitionOf, } from "umtool-report-to-video/deck"; import { marksOf, rawMarksOf, roundStamps, stampSchedule } from "umtool-report-to-video/factcheck"; @@ -304,6 +305,10 @@ export function applyPostsDraft(posts, draft = {}) { if (d.hide) out.hide = true; else delete out.hide; } + if ("thread" in d) { + if (d.thread) out.thread = true; + else delete out.thread; + } return out; }); } @@ -351,7 +356,7 @@ export function postRows({ variantManifest, metas, schedule = null }) { const entries = variantManifest.timeline ?? []; const posts = Array.isArray(variantManifest.posts) ? variantManifest.posts : []; const labelOf = new Map(entries.map((e, i) => [e.id, clipLabel(e, metas[i] ?? null)])); - const bare = posts.map(({ attachTo: _a, hide: _h, ...p }) => p); + const bare = posts.map(({ attachTo: _a, hide: _h, thread: _t, ...p }) => p); const auto = new Map(attachPosts({ posts: bare, entries, metas }).map((a) => [a.id, a])); const effective = new Map(attachPosts({ posts, entries, metas }).map((a) => [a.id, a])); const timing = new Map((schedule?.posts ?? []).map((p) => [p.id, p])); @@ -369,6 +374,10 @@ export function postRows({ variantManifest, metas, schedule = null }) { url: p.url, attachTo: p.attachTo ?? null, hide: p.hide === true, + // A reply drawn with the post it answers (its thread shot, when the + // capture took one -- the route says whether it is on disk). + thread: p.thread === true, + threadShot: threadShotOf(p.shot), auto: where(auto.get(p.id)), effective: p.hide ? null : where(effective.get(p.id)), // A popup post's appear and leave, or a feed post's tick-in (`in`). diff --git a/umtool/lib/report/onscreen.test.mjs b/umtool/lib/report/onscreen.test.mjs @@ -229,7 +229,7 @@ test("applyPostsDraft: the writer's rule, on a copy", () => { assert.equal(applyPostsDraft(posts, {}), posts); assert.deepEqual(normalizePostsDraft(undefined), {}); assert.deepEqual(normalizePostsDraft({}), {}); - assert.throws(() => normalizePostsDraft({ p1: { text: "x" } }), /only attachTo and hide/); + assert.throws(() => normalizePostsDraft({ p1: { text: "x" } }), /only attachTo, hide and thread/); }); test("postRows: the automatic clip, the effective one, and the slot in the schedule", () => { @@ -261,6 +261,23 @@ test("postRows: the automatic clip, the effective one, and the slot in the sched assert.deepEqual(postRows({ variantManifest: cut(), metas }).posts, []); }); +test("postRows and the draft: a reply's thread choice and where its thread shot would be", () => { + const m = withPosts(); + m.posts[0].shot = "posts-media/acct/1/shot.png"; + m.posts[0].thread = true; + const by = Object.fromEntries(postRows({ variantManifest: m, metas }).posts.map((p) => [p.id, p])); + assert.equal(by.p1.thread, true); + assert.equal(by.p1.threadShot, "posts-media/acct/1/shot-thread.png"); + assert.equal(by.p2.thread, false); + assert.equal(by.p2.threadShot, null); + // The draft's thread, by the writer's rule: false removes the key. + const out = applyPostsDraft(m.posts, { p1: { thread: false }, p2: { thread: true } }); + assert.ok(!("thread" in out[0])); + assert.equal(out[1].thread, true); + assert.deepEqual(normalizePostsDraft({ p1: { thread: true } }), { p1: { thread: true } }); + assert.throws(() => normalizePostsDraft({ p1: { thread: "on" } }), /thread must be true or false/); +}); + test("clipLabel: deck title, then the quote, then the stream's title", () => { assert.equal(clipLabel({ onscreen: { title: "T" }, quote: "q" }, { title: "m" }), "T"); assert.equal(clipLabel({ quote: " q " }, { title: "m" }), "q"); diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs @@ -3,7 +3,13 @@ // link and handle as the archive holds them, and its screenshot. // // umtool posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag F] -// [--author A] [--id ID] [--dry-run] [--json] +// [--author A] [--id ID] [--thread] [--dry-run] [--json] +// umtool posts set <project> <post> thread=on|off [hide=on|off] [attach=<clipId>|auto] [--json] +// +// `--thread` / `thread=on` draws a reply with the post it answers above it: +// the capture's `shot-thread.png` beside its `shot.png` (capture-posts +// `"thread": true` takes it), the post's own shot while there is none. `set` +// is updatePosts -- the writer the Posts table's Save runs. // // The row is `channels/<slug>/posts/YYYY-MM.jsonl`'s (common/lib/posts-server.ts // owns that layout; an X id names its month, so its shard is read first). The @@ -27,16 +33,20 @@ import path from "node:path"; import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { channelsDirFor, readManifest } from "../projects/report.mjs"; import { withEditNotes } from "./edit-guard.mjs"; -import { StaleToken, StructureRefused, manifestToken, upsertPost } from "./manifest.mjs"; +import { PostsRefused, StaleToken, StructureRefused, manifestToken, updatePosts, upsertPost } from "./manifest.mjs"; export const POSTS_USAGE = [ "usage: umtool posts add <project> <archive-channel>/<postId> [--attach <clipId>] [--flag F] [--author A] [--id ID]", - " [--dry-run] [--json]", + " [--thread] [--dry-run] [--json]", + " umtool posts set <project> <post> thread=on|off [hide=on|off] [attach=<clipId>|auto] [--json]", " a post card from the corpus's posts archive (channels/<slug>/posts/*.jsonl): its words, date, link and handle,", " and its screenshot (channels/<slug>/posts-media/<postId>/shot.png) copied into the project's posts-media/.", " The id is x-<postId> (bsky-, post-) unless --id; --attach pins it to a clip; --author overrides the name", " (default: the name an earlier post by the same handle carries in this cut, else the archive's).", " A post with no screenshot is refused: `pnpm ops capture-posts --json '{\"slug\":…,\"ids\":[…]}'` first.", + " --thread (or `set … thread=on`): a reply drawn with the post it answers above it -- the capture's", + " shot-thread.png beside shot.png (capture-posts with \"thread\": true takes it); its own shot while there is none.", + " set: <post> is the manifest's post id (x-<postId>) or the bare <postId>; the Posts table's writer.", ].join("\n"); const VALUED = new Set(["--attach", "--flag", "--author", "--id"]); @@ -99,7 +109,7 @@ export const projectShotRel = (slug, postId) => `posts-media/${slug}/${postId}/s * name an earlier post by the same handle carries (the Huck cut's posts say * "Jeremy Hambly", the archive "TheQuartering"). */ -export function postEntryOf(row, { slug, postId, manifest = null, attach = null, flag = null, author = null, id = null }) { +export function postEntryOf(row, { slug, postId, manifest = null, attach = null, flag = null, author = null, id = null, thread = false }) { const platform = deckPlatformOf(row.platform); const handle = typeof row.author === "string" && row.author ? row.author.replace(/^@/, "") : null; const earlier = (Array.isArray(manifest?.posts) ? manifest.posts : []).find( @@ -121,10 +131,49 @@ export function postEntryOf(row, { slug, postId, manifest = null, attach = null, ...(attach ? { attachTo: attach } : {}), text: typeof row.text === "string" ? row.text : "", shot: projectShotRel(slug, postId), + ...(thread ? { thread: true } : {}), ...(flag ? { flag } : {}), }; } +const ON = new Set(["on", "true", "yes", "1"]); +const OFF = new Set(["off", "false", "no", "0"]); + +/** + * `posts set`'s words as the Posts table's patch: `thread=on|off`, + * `hide=on|off`, `attach=<clipId>|auto`. Throws on anything else. + * + * @param {string[]} pairs + * @returns {{ attachTo?: string | null, hide?: boolean, thread?: boolean }} + */ +export function postPatchOf(pairs) { + /** @type {{ attachTo?: string | null, hide?: boolean, thread?: boolean }} */ + const out = {}; + for (const pair of pairs) { + const eq = pair.indexOf("="); + const k = eq > 0 ? pair.slice(0, eq) : pair; + const v = eq > 0 ? pair.slice(eq + 1).toLowerCase() : ""; + if (k === "thread" || k === "hide") { + if (ON.has(v)) out[k] = true; + else if (OFF.has(v)) out[k] = false; + else throw new CliError(`${k}= takes on or off, not ${JSON.stringify(v)}`); + } else if (k === "attach") { + if (!v) throw new CliError("attach= takes a clip id, or auto"); + out.attachTo = v === "auto" ? null : pair.slice(eq + 1); + } else throw new CliError(`${pair}: not a post knob (thread=, hide=, attach=)`); + } + if (!Object.keys(out).length) throw new CliError("nothing to set: thread=on|off, hide=on|off or attach=<clipId>|auto"); + return out; +} + +/** The manifest's post `ref` names: its id, or an x-/bsky-/post- id with that native id. */ +export function findPostId(manifest, ref) { + const posts = Array.isArray(manifest?.posts) ? manifest.posts : []; + if (posts.some((p) => p?.id === ref)) return ref; + const hits = posts.filter((p) => typeof p?.id === "string" && ["x-", "bsky-", "post-"].some((pre) => p.id === pre + ref)); + return hits.length === 1 ? hits[0].id : null; +} + /** What of a capture's directory is copied beside the manifest: the shot, its record, the post's pictures. */ export const CAPTURE_COPY_RE = /^(?:shot\.png|capture\.json|.+\.(?:png|jpe?g|webp|gif))$/i; @@ -205,10 +254,11 @@ export async function postsCommand(args, { root = REPORTS_ROOT, out = (s) => con }; try { const [verb, projectArg, ref] = words; - if (verb !== "add" || !projectArg || !ref || flags.has("--help")) { + if ((verb !== "add" && verb !== "set") || !projectArg || !ref || flags.has("--help")) { err(POSTS_USAGE); return 2; } + if (verb === "set") return await setCommand(projectArg, ref, words.slice(3), { root, json, out }); const slash = ref.indexOf("/"); const slug = slash > 0 ? ref.slice(0, slash) : ""; const postId = slash > 0 ? ref.slice(slash + 1) : ""; @@ -240,7 +290,11 @@ export async function postsCommand(args, { root = REPORTS_ROOT, out = (s) => con if (attach && !(manifest.timeline ?? []).some((e) => e?.type === "clip" && e.id === attach)) { throw new CliError(`--attach ${attach}: no clip with that id in ${project.id}`); } - const post = postEntryOf(found.row, { slug, postId, manifest, attach, flag: str("--flag"), author: str("--author"), id: str("--id") }); + const thread = flags.has("--thread"); + const post = postEntryOf(found.row, { slug, postId, manifest, attach, flag: str("--flag"), author: str("--author"), id: str("--id"), thread }); + // A thread shot asked for and not taken: the card draws its own shot until a capture takes one. + const threadFrom = path.join(path.dirname(shotFrom), "shot-thread.png"); + const threadMissing = thread && !(await stat(threadFrom).catch(() => null)); const shotTo = path.join(project.dir, ...post.shot.split("/")); if (dryRun) { out(json ? JSON.stringify({ ok: true, dryRun: true, post, shard: found.shard, shotFrom, shotTo }, null, 2) : `would add ${post.id} (${found.shard}):\n${JSON.stringify(post, null, 2)}\n shot ${shotFrom} -> ${shotTo}`); @@ -259,12 +313,19 @@ export async function postsCommand(args, { root = REPORTS_ROOT, out = (s) => con upsertPost(project.dir, post, { token: await manifestToken(project.dir) }), ); if (json) { - out(JSON.stringify({ ok: true, ...result, shard: found.shard, shot: { from: shotFrom, to: shotTo, via: where }, copied, editNotes }, null, 2)); + out(JSON.stringify({ ok: true, ...result, shard: found.shard, shot: { from: shotFrom, to: shotTo, via: where }, copied, ...(thread ? { threadShot: !threadMissing } : {}), editNotes }, null, 2)); return 0; } out(`${result.created ? "added" : "replaced"} post ${result.post.id}${result.post.attachTo ? ` -> ${result.post.attachTo}` : ""} ${result.post.date}`); out(` ${result.post.author ?? ""}${result.post.handle ? ` @${result.post.handle}` : ""}: ${result.post.text.split("\n")[0].slice(0, 100)}`); out(` shot ${result.post.shot}${where === "linked" ? " (posts-media links the channel's captures)" : copied.length ? ` (copied: ${copied.join(", ")})` : " (already there)"}`); + if (threadMissing) { + out( + ` thread: no shot-thread.png yet -- its own shot is drawn until one is taken:\n` + + ` pnpm ops capture-posts --json '${JSON.stringify({ slug, ids: [postId], thread: true })}'` + + (where === "linked" ? "" : `\n then umtool posts add again (it copies the new shot in)`), + ); + } else if (thread) out(" thread: drawn with the post it answers (shot-thread.png)"); if (result.snapshot?.rel && !result.snapshot.skipped) out(` undo point: ${result.snapshot.rel}`); if (editNotes) { out( @@ -275,6 +336,10 @@ export async function postsCommand(args, { root = REPORTS_ROOT, out = (s) => con } return 0; } catch (e) { + if (e instanceof PostsRefused) { + err(`umtool posts: refused — the build would not take it:\n${e.errors.map((x) => ` ${x}`).join("\n")}`); + return 1; + } if (e instanceof StructureRefused) { err(`umtool posts: refused — the build would not take it:\n${e.errors.map((x) => ` ${x}`).join("\n")}`); return 1; @@ -287,3 +352,33 @@ export async function postsCommand(args, { root = REPORTS_ROOT, out = (s) => con return e instanceof CliError ? 2 : 1; } } + +/** `posts set`: the Posts table's writer (updatePosts), from the CLI. */ +async function setCommand(projectArg, ref, pairs, { root, json, out }) { + const patch = postPatchOf(pairs); + const r = await resolveProject(projectArg, root); + if (r.ambiguous) throw new CliError(`"${projectArg}" is the name of ${r.ambiguous.length} projects — pass its id`); + if (!r.project) throw new CliError(`no project matches "${projectArg}"`); + const project = r.project; + const manifest = await readManifest(project.dir); + if (!manifest) throw new CliError(`${project.id} has no manifest`); + const id = findPostId(manifest, ref); + if (!id) throw new CliError(`no post ${ref} in ${project.id} (its id, or x-<postId>)`); + const { result, editNotes } = await withEditNotes(project, async () => + updatePosts(project.dir, { [id]: patch }, { token: await manifestToken(project.dir) }), + ); + const saved = result.posts[id]; + const post = manifest.posts.find((p) => p?.id === id); + const threadFile = saved.thread && typeof post?.shot === "string" + ? path.join(project.dir, ...post.shot.split("/").slice(0, -1), "shot-thread.png") + : null; + const threadThere = threadFile ? Boolean(await stat(threadFile).catch(() => null)) : null; + if (json) { + out(JSON.stringify({ ok: true, id, post: saved, ...(threadThere === null ? {} : { threadShot: threadThere }), token: result.token, editNotes }, null, 2)); + return 0; + } + out(`set ${id}: thread ${saved.thread ? "on" : "off"}, ${saved.hide ? "hidden" : "shown"}, rides on ${saved.attachTo ?? "auto"}`); + if (threadThere === false) out(" no shot-thread.png beside its shot yet -- its own shot is drawn (capture-posts with \"thread\": true)"); + if (editNotes) out(` edit noted for ${editNotes.generatedBy}`); + return 0; +} diff --git a/umtool/lib/report/postsCli.test.mjs b/umtool/lib/report/postsCli.test.mjs @@ -166,3 +166,62 @@ test("posts add never copies through a link out of the project: linked captures assert.deepEqual(await readdir(away), []); assert.equal(await shotHome(other, path.join(other, "posts-media", "fresh", "1"), path.join(CHANNELS, "acct-X", "posts-media")), "project"); }); + +test("posts add --thread: the entry asks for the thread shot, copied beside its shot; with none yet it says which capture takes it", async () => { + // A reply with a thread shot, and one without. + const RID = "2114214000653414579"; + const NID = "2114580970087108886"; + const posts = path.join(CHANNELS, "acct-R", "posts"); + await mkdir(posts, { recursive: true }); + const row = (id, text) => JSON.stringify({ ...ROW, id, channelSlug: "acct-R", text, url: `https://x.com/Acct/status/${id}`, createdAt: "2026-10-25T04:34:32.000Z" }); + await writeFile(path.join(posts, "2026-10.jsonl"), [row(RID, "@someone Well.."), row(NID, "@other He eats raw"), ""].join("\n")); + for (const id of [RID, NID]) { + await mkdir(path.join(CHANNELS, "acct-R", "posts-media", id), { recursive: true }); + await writeFile(path.join(CHANNELS, "acct-R", "posts-media", id, "shot.png"), "PNG"); + } + await writeFile(path.join(CHANNELS, "acct-R", "posts-media", RID, "shot-thread.png"), "THREAD"); + const dir = await project("thread"); + const { lines, run } = runner(); + assert.equal(await run("add", "thread", `acct-R/${RID}`, "--thread", "--json"), 0); + const res = JSON.parse(lines.at(-1)); + assert.equal(res.post.thread, true); + assert.equal(res.threadShot, true); + assert.ok(res.copied.includes("shot-thread.png"), "the thread shot is copied in with the shot"); + assert.equal(await readFile(path.join(dir, "posts-media", "acct-R", RID, "shot-thread.png"), "utf8"), "THREAD"); + + assert.equal(await run("add", "thread", `acct-R/${NID}`, "--thread"), 0); + assert.ok(lines.some((l) => /no shot-thread\.png yet/.test(l))); + assert.ok(lines.some((l) => l.includes(`"thread":true`) && l.includes("capture-posts"))); + const m = await read(dir); + assert.equal(m.posts.find((p) => p.id === `x-${NID}`).thread, true, "asked for: drawn once a capture takes it"); + + // Replaced without --thread: the choice is kept, as attachTo is. + assert.equal(await run("add", "thread", `acct-R/${RID}`, "--json"), 0); + assert.equal(JSON.parse(lines.at(-1)).post.thread, true); +}); + +test("posts set: the Posts table's writer -- thread on/off by the post's id or its bare id; refusals in words", async () => { + const dir = await project("set"); + const { lines, run } = runner(); + assert.equal(await run("add", "set", `acct-X/${XID}`), 0); + assert.equal(await run("set", "set", XID, "thread=on", "--json"), 0); + const on = JSON.parse(lines.at(-1)); + assert.equal(on.id, `x-${XID}`); + assert.deepEqual(on.post, { attachTo: null, hide: false, thread: true }); + assert.equal(on.threadShot, false, "no thread shot beside its shot: its own is drawn"); + assert.equal((await read(dir)).posts.find((p) => p.id === `x-${XID}`).thread, true); + assert.equal(await run("set", "set", `x-${XID}`, "thread=off", "hide=on", "attach=c01"), 0); + const off = (await read(dir)).posts.find((p) => p.id === `x-${XID}`); + assert.equal("thread" in off, false, "off removes the key"); + assert.equal(off.hide, true); + assert.equal(off.attachTo, "c01"); + assert.equal(await run("set", "set", XID, "thread=maybe"), 2); + assert.match(lines.at(-1), /thread= takes on or off/); + assert.equal(await run("set", "set", "nope", "thread=on"), 2); + assert.match(lines.at(-1), /no post nope/); + assert.equal(await run("set", "set", XID, "attach=c99"), 1); + assert.match(lines.at(-1), /refused/); + // The build's check: a post with no shot cannot ask for a thread shot. + assert.equal(await run("set", "set", "x-1", "thread=on"), 1); + assert.match(lines.at(-1), /thread draws the thread shot beside the post's shot/); +}); diff --git a/umtool/report-to-video/chrome-feed.mjs b/umtool/report-to-video/chrome-feed.mjs @@ -264,6 +264,38 @@ export function feedShotLone({ heights, shots, column, gap = 16 }) { } /** + * feedShotLone, and a `whole` picture: a reply's THREAD SHOT (the post it + * answers over the reply, posts[].thread) must be read top to bottom, so one + * that would not be drawn at its full height beside the card under it takes + * the column instead -- that card is pushed out as feedCues pushes any card + * that no longer fits -- and one taller than the column is scaled down to + * it whole (`.shot` is object-fit: contain, so the reply is never cut off). + * Without a `whole` shot it is exactly feedShotLone. PURE and SELF-CONTAINED + * (embedded like feedCues); only a page with a thread shot carries it, so a + * page without one is byte-for-byte what it was. + * + * @returns {{ imgs: Array<number|null>, heights: number[] }} + */ +export function feedShotWhole({ heights, shots, column, gap = 16 }) { + const out = heights.slice(); + const imgs = heights.map(() => null); + for (let j = 0; j < out.length; j += 1) { + const s = shots[j]; + if (!s || !(s.full > s.drawn + 1)) continue; + const chrome = (heights[j] || 0) - s.drawn; + const stays = j > 0 && (heights[j] || 0) + gap + out[j - 1] <= column; + const fitsBeside = stays && Math.floor(column - out[j - 1] - gap - chrome) >= Math.round(s.full); + const beside = stays && (!s.whole || fitsBeside) ? out[j - 1] + gap : 0; + const room = Math.floor(column - beside - chrome); + const img = Math.min(Math.round(s.full), room); + if (img <= s.drawn) continue; + imgs[j] = img; + out[j] = chrome + img; + } + return { imgs, heights: out }; +} + +/** * Who the feed is, for its header: the one author's name and platform when * every post is theirs, else "Posts" and every platform there is. */ @@ -296,6 +328,7 @@ export function feedHtml(schedule, render, opts = {}) { const fonts = opts.fonts ?? {}; const qrSrcs = opts.qrSrcs ?? {}; const shotSrcs = opts.shotSrcs ?? {}; + const threadShots = new Set(opts.threadShots ?? []); const gsapSrc = opts.gsap ?? "assets/gsap.min.js"; const total = schedule.total; const from = Number(opts.from ?? 0); @@ -311,6 +344,9 @@ export function feedHtml(schedule, render, opts = {}) { // without a picture keeps feedShotRoom's text, so its bytes -- and the // render cache keyed on them -- are what they were. const anyShot = posts.some((p) => shotSrcs[p.id]); + // A thread shot drawn whole (feedShotWhole); only such a page carries it. + const anyThread = posts.some((p) => shotSrcs[p.id] && threadShots.has(p.id)); + const roomFn = anyThread ? "feedShotWhole" : anyShot ? "feedShotLone" : "feedShotRoom"; const panel = deck.background === "panel"; // The column's ground meets the deck's top edge in the deck's own colour, @@ -325,10 +361,12 @@ export function feedHtml(schedule, render, opts = {}) { const { name, platform } = postWho(p); const src = qrSrcs[p.id]; const shot = shotSrcs[p.id]; + // A thread shot is marked, so the page gives it the column (feedShotLone `whole`). + const whole = threadShots.has(p.id) ? ` data-thread="1"` : ""; return ( `<article class="post${shot ? " has-shot" : ""}" data-post="${esc(p.id)}" data-k="c${j}">` + (shot - ? `<div class="body shot-body"><img class="shot" src="${esc(shot)}" alt=""></div>` + ? `<div class="body shot-body"><img class="shot" src="${esc(shot)}"${whole} alt=""></div>` : `<div class="body">` + `<div class="meta">` + (who.single ? "" : (platform ? `<span class="platform">${esc(platform)}</span>` : "") + @@ -481,7 +519,7 @@ export function feedHtml(schedule, render, opts = {}) { const byK = {}; for (const el of document.querySelectorAll("[data-k]")) byK[el.dataset.k] = el; ${embedFn("feedCues", feedCues)} - ${anyShot ? embedFn("feedShotLone", feedShotLone) : embedFn("feedShotRoom", feedShotRoom)} + ${anyThread ? embedFn("feedShotWhole", feedShotWhole) : anyShot ? embedFn("feedShotLone", feedShotLone) : embedFn("feedShotRoom", feedShotRoom)} const params = new URLSearchParams(location.search); // A window plays the cut's [from, from + dur]; the page is seeked in its own seconds. @@ -529,9 +567,9 @@ export function feedHtml(schedule, render, opts = {}) { const img = c.querySelector("img.shot"); if (!img || !img.naturalWidth) return null; const full = (img.parentElement.clientWidth - 2 * F.shotPad) * img.naturalHeight / img.naturalWidth; - return { drawn: img.offsetHeight, full }; + return ${anyThread ? "img.dataset.thread ? { drawn: img.offsetHeight, full, whole: true } : " : ""}{ drawn: img.offsetHeight, full }; }); - const room = ${anyShot ? "feedShotLone" : "feedShotRoom"}({ heights: cards.map((c) => c.offsetHeight), shots, column: F.column, gap: F.motion.gap }); + const room = ${roomFn}({ heights: cards.map((c) => c.offsetHeight), shots, column: F.column, gap: F.motion.gap }); room.imgs.forEach((h, j) => { if (h != null) cards[j].querySelector("img.shot").style.maxHeight = h + "px"; }); const heights = cards.map((c) => c.offsetHeight); document.documentElement.dataset.shots = room.imgs.map((h) => h ?? "").join(","); diff --git a/umtool/report-to-video/chrome-feed.test.mjs b/umtool/report-to-video/chrome-feed.test.mjs @@ -11,7 +11,7 @@ import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; -import { FEED_MOTION, feedCues, feedHtml, feedLayout, feedShotLone, feedShotRoom, feedWho } from "./chrome-feed.mjs"; +import { FEED_MOTION, feedCues, feedHtml, feedLayout, feedShotLone, feedShotRoom, feedShotWhole, feedWho } from "./chrome-feed.mjs"; import { deckChoreography, deckGeometry, deckSchedule, estimateSchedule, feedGeometry, feedOn, postHolds, postSchedule, postsGeometry, postWindows, validateChrome, validatePosts, @@ -515,3 +515,48 @@ test("the page: the screenshot rule rides in the page and sizes the pictures bef assert.ok(grow > 0 && plan > grow, "pictures are sized before the stack is planned from the heights"); assert.match(html, /"shotPad":10/); }); + +test("feedShotWhole: without a thread shot it is exactly feedShotLone", () => { + for (const args of [ + { heights: [200, 310], shots: [null, { drawn: 290, full: 900 }], column: 700, gap: 16 }, + { heights: [310, 310, 310], shots: [{ drawn: 290, full: 900 }, { drawn: 290, full: 900 }, { drawn: 290, full: 470 }], column: 760 }, + { heights: [600, 310], shots: [null, { drawn: 290, full: 470 }], column: 760, gap: 16 }, + { heights: [120, 310, 130, 310], shots: [null, { drawn: 290, full: 380 }, null, { drawn: 290, full: 330 }], column: 760 }, + ]) { + assert.deepEqual(feedShotWhole(args), feedShotLone(args), JSON.stringify(args)); + } +}); + +test("feedShotWhole: a thread shot is drawn whole -- the card under it leaves rather than the reply being squeezed", () => { + // Card 0 words (200); card 1 a thread shot drawn at 290 of a full 620 (chrome 20); column 760. + // Beside the card under it: 760 - 216 - 20 = 524 < 620, so feedShotLone draws it at 524; + // a whole one takes the column and is drawn at its full 620, the card under it pushed out. + const args = { heights: [200, 310], shots: [null, { drawn: 290, full: 620 }], column: 760, gap: 16 }; + assert.deepEqual(feedShotLone(args).imgs, [null, 524]); + const whole = { ...args, shots: [null, { drawn: 290, full: 620, whole: true }] }; + const r = feedShotWhole(whole); + assert.deepEqual(r.imgs, [null, 620]); + const plan = feedCues({ posts: [{ id: "a", in: 1 }, { id: "b", in: 5 }], heights: r.heights, column: 760 }); + assert.deepEqual(plan.gone, [5, null], "the card under the thread shot leaves as it lands"); + // One that fits beside the card under it keeps that card. + const fits = { heights: [200, 310], shots: [null, { drawn: 290, full: 480, whole: true }], column: 760, gap: 16 }; + assert.deepEqual(feedShotWhole(fits).imgs, [null, 480]); + assert.ok(200 + 16 + 20 + 480 <= 760); + // Taller than the column: drawn at the column's height (scaled to fit by object-fit: contain, never cut). + const tall = feedShotWhole({ heights: [200, 310], shots: [null, { drawn: 290, full: 1500, whole: true }], column: 760, gap: 16 }); + assert.deepEqual(tall.imgs, [null, 740]); + assert.deepEqual(tall.heights, [200, 760]); +}); + +test("the page: a thread shot is marked and carries feedShotWhole; the .shot rule scales it to fit, never crops", () => { + const posts = POSTS.map((p) => (p.id === "b" ? { ...p, shot: "shots/b.png", thread: true } : p)); + const { html } = page(posts, { shotSrcs: { b: "assets/shot00.png" }, threadShots: ["b"] }); + assert.ok(html.includes('<img class="shot" src="assets/shot00.png" data-thread="1" alt="">')); + assert.match(html, /const feedShotWhole = /); + assert.match(html, /const room = feedShotWhole\(\{ heights/); + assert.match(html, /img\.dataset\.thread \? \{ drawn: img\.offsetHeight, full, whole: true \}/); + assert.match(html, /\.shot \{[^}]*object-fit: contain/); + // Named but its picture is the post's own (no thread shot on disk): a plain shot page. + const plain = page(posts, { shotSrcs: { b: "assets/shot00.png" } }).html; + assert.doesNotMatch(plain, /feedShotWhole|data-thread/); +}); diff --git a/umtool/report-to-video/chrome-posts.test.mjs b/umtool/report-to-video/chrome-posts.test.mjs @@ -15,7 +15,8 @@ import { fileURLToPath } from "node:url"; import { postDate, postParagraphs, postsCues, postsHtml, postWho, snapWindow, windowPosts, } from "./chrome-posts.mjs"; -import { postSchedule, postsGeometry, postWindows, validatePosts } from "./deck.mjs"; +import { postSchedule, postsGeometry, postWindows, threadShotOf, validatePosts } from "./deck.mjs"; +import { postThreadFile } from "./compose-chrome.mjs"; import { applyChromeArgs, chromeOverlayChain, chromeRegions, postsRegions } from "./build-video.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); @@ -548,3 +549,35 @@ test("postsHtml: a screenshot sits in a viewport at the card's width, and the pa assert.doesNotMatch(html, /\.shot \{[^}]*object-fit/, "never shrunk to fit"); assert.match(html, /const pans = cards\.map/); }); + +test("thread: a reply's thread shot is asked for on a post with a shot, placed with it, and found beside the shot", async () => { + const shot = "posts-media/acct-x-replies/2114214000653414579/shot.png"; + assert.deepEqual(validatePosts([POST("a", "2026-01-01", { shot, thread: true })]), []); + assert.deepEqual(validatePosts([POST("a", "2026-01-01", { shot, thread: false })]), []); + assert.match(validatePosts([POST("a", "2026-01-01", { shot, thread: "yes" })]).join(" | "), /posts\[0\]\.thread must be true or false/); + assert.match(validatePosts([POST("a", "2026-01-01", { thread: true })]).join(" | "), /posts\[0\]\.thread draws the thread shot beside the post's shot/); + assert.equal(threadShotOf(shot), "posts-media/acct-x-replies/2114214000653414579/shot-thread.png"); + assert.equal(threadShotOf("shot.png"), "shot-thread.png"); + assert.equal(threadShotOf(undefined), null); + // Placed: the schedule carries it beside the shot; a post without one places as it always did. + const placed = postSchedule({ + posts: [POST("a", "2024-10-19", { shot, thread: true }), POST("b", "2024-10-20", { thread: true }), POST("c", "2024-10-21", { shot })], + entries: CLIPS, segments: SEGS, D: 0.5, total: 28.5, render: RENDER, + }); + const by = Object.fromEntries(placed.map((p) => [p.id, p])); + assert.equal(by.a.thread, true); + assert.ok(!("thread" in by.b) && !("thread" in by.c)); + // The composer draws the thread shot only when it is on disk; else the post's own. + const dir = mkdtempSync(path.join(tmpdir(), "thread-shot-")); + try { + const at = path.join(dir, "posts-media", "acct-x-replies", "2114214000653414579"); + mkdirSync(at, { recursive: true }); + writeFileSync(path.join(at, "shot.png"), "PNG"); + assert.equal(await postThreadFile({ shot, thread: true }, dir), null, "none taken yet: its own shot"); + writeFileSync(path.join(at, "shot-thread.png"), "PNG2"); + assert.equal(await postThreadFile({ shot, thread: true }, dir), path.join(at, "shot-thread.png")); + assert.equal(await postThreadFile({ shot }, dir), null, "not asked for"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); diff --git a/umtool/report-to-video/compose-chrome.mjs b/umtool/report-to-video/compose-chrome.mjs @@ -31,7 +31,7 @@ // and the crossfade -- so the build writes the schedule and this reads it. // Recomputing it here would be a second implementation of segmentOffsets() and // would drift the first time the transition changed. -import { copyFile, link, mkdir, readdir, readFile, rename, rm, writeFile } from "node:fs/promises"; +import { copyFile, link, mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises"; import { execFile, spawn } from "node:child_process"; import { promisify } from "node:util"; import path from "node:path"; @@ -52,7 +52,7 @@ import { threadsHtml } from "./chrome-threads.mjs"; import { flipsHtml } from "./chrome-flips.mjs"; import { statsHtml } from "./chrome-stats.mjs"; import { finaleHtml, finaleLayout } from "./chrome-finale.mjs"; -import { fxGeometry } from "./deck.mjs"; +import { fxGeometry, threadShotOf } from "./deck.mjs"; import { FRAME_KEY_REGIONS, frameKeys } from "./frame-keys.mjs"; const run = promisify(execFile); @@ -621,6 +621,23 @@ async function copyFonts(render, assetsDir, names, { strict }) { } /** + * A placed post's thread shot on disk (`thread: true`, deck.mjs threadShotOf: + * `shot-thread.png` beside its shot), or null: not asked for, or the capture + * took none (not a reply, no parent shown) -- the post's own shot is drawn + * instead, as before. + * + * @returns {Promise<string|null>} + */ +export async function postThreadFile(p, manifestDir) { + if (p?.thread !== true) return null; + const rel = threadShotOf(p.shot); + if (!rel) return null; + const file = path.resolve(manifestDir, rel); + const st = await stat(file).catch(() => null); + return st?.isFile() ? file : null; +} + +/** * The posts' screenshots (`posts[].shot`, relative to the manifest) -- or, * with `key` "logo", their logos (`posts[].logo`) -- copied * in beside the page as `shotNN<ext>` (`logoNN<ext>`), one per distinct file. Returns @@ -628,12 +645,14 @@ async function copyFonts(render, assetsDir, names, { strict }) { * the region: a card drawn without the picture its post names is not the * card the manifest asks for. */ -async function copyShots(posts, manifestDir, assetsDir, key = "shot") { +async function copyShots(posts, manifestDir, assetsDir, key = "shot", threads = null) { const out = {}; const byFile = new Map(); for (const p of posts) { if (typeof p[key] !== "string" || !p[key]) continue; - const file = path.resolve(manifestDir, p[key]); + const thread = key === "shot" ? await postThreadFile(p, manifestDir) : null; + if (thread) threads?.add(p.id); + const file = thread ?? path.resolve(manifestDir, p[key]); if (!byFile.has(file)) { const name = `${key}${String(byFile.size).padStart(2, "0")}${path.extname(file).toLowerCase()}`; try { @@ -786,8 +805,11 @@ async function regionHtml(region, { manifest, manifestDir, base, projDir, assets : await qrPngsFor(posts.map((p) => p.qrUrl), render, resolveDeck(render).posts.qrSize, assetsDir); const qrSrcs = {}; for (const p of posts) if (p.qrUrl) qrSrcs[p.id] = byUrl.get(p.qrUrl); - const shotSrcs = await copyShots(posts, manifestDir, assetsDir); - return feedHtml(schedule, render, { fonts, qrSrcs, shotSrcs, from, duration }); + // A thread shot (a reply over the post it answers) is drawn whole: the + // feed gives it the column rather than the room beside the card under it. + const threads = new Set(); + const shotSrcs = await copyShots(posts, manifestDir, assetsDir, "shot", threads); + return feedHtml(schedule, render, { fonts, qrSrcs, shotSrcs, threadShots: [...threads], from, duration }); } if (region === "stamp") { // The fact-check stamps (chrome-stamp.mjs): the deck's faces, no QR. diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -1847,13 +1847,31 @@ const POST_VARIANTS = Object.freeze(["sourced", "full"]); export const POST_LAYOUTS = Object.freeze(["popup", "feed"]); /** Where a post's QR links (`posts.links`): its page on the archive, or the platform's own link. */ export const POST_LINKS = Object.freeze(["archive", "original"]); -const POST_KEYS = ["id", "platform", "author", "handle", "date", "text", "url", "attachTo", "hide", "siteChannel", "siteUrl", "postId", "shot", "variant", "accent", "logo", "flag"]; +const POST_KEYS = ["id", "platform", "author", "handle", "date", "text", "url", "attachTo", "hide", "siteChannel", "siteUrl", "postId", "shot", "thread", "variant", "accent", "logo", "flag"]; /** A post's `flag`: at most this many characters. */ export const POST_FLAG_MAX = 60; /** The pictures a post's `shot` may be. */ export const POST_SHOT_EXTS = Object.freeze([".png", ".jpg", ".jpeg", ".webp"]); +/** A reply's thread shot (capture-posts `thread`): beside the post's own shot, under this name. */ +export const THREAD_SHOT_NAME = "shot-thread.png"; + +/** + * Where a post's thread shot would be: `shot-thread.png` in its `shot`'s + * folder (the capture's layout, common/social/postCapture.ts), or null for a + * post with no shot. Whether the file is there is the composer's to check + * (compose-chrome.mjs postShotFile): a post with `thread: true` and none + * draws its own shot, as it did. + * + * @returns {string|null} + */ +export function threadShotOf(shot) { + if (typeof shot !== "string" || !shot) return null; + const i = shot.lastIndexOf("/"); + return (i < 0 ? "" : shot.slice(0, i + 1)) + THREAD_SHOT_NAME; +} + /** * Why a post's `shot` cannot be drawn, or null: a path to a screenshot of the * post, RELATIVE to the manifest (it is checked in beside it, as an image @@ -1924,6 +1942,12 @@ export function validatePosts(posts, timeline = [], render = null) { } // A screenshot drawn instead of the text card; the text stays the post's words. if (p.shot != null && shotError(p.shot)) errors.push(`${w}.shot ${shotError(p.shot)}`); + // The reply drawn with the post it answers above it: its thread shot, when + // the capture took one beside the shot (threadShotOf). + if (p.thread !== undefined && typeof p.thread !== "boolean") errors.push(`${w}.thread must be true or false`); + else if (p.thread === true && (typeof p.shot !== "string" || !p.shot)) { + errors.push(`${w}.thread draws the thread shot beside the post's shot, and the post has no shot`); + } // The card's own marks: a colour for its rail and rim, a logo in its corner, // a short flag above its words -- so one kind of card reads apart from another. if (p.accent != null && (typeof p.accent !== "string" || !/^#[0-9a-fA-F]{6}$/.test(p.accent))) { @@ -2104,6 +2128,8 @@ function postFieldsOf(p, provenance, links) { qrUrl: postQrUrl(p, provenance, { links }), // Only with a screenshot, so a post without one places as it always did. ...(typeof p.shot === "string" && p.shot ? { shot: p.shot } : {}), + // The thread shot is asked for; the composer draws it when it is on disk. + ...(typeof p.shot === "string" && p.shot && p.thread === true ? { thread: true } : {}), ...(typeof p.accent === "string" && p.accent ? { accent: p.accent } : {}), ...(typeof p.logo === "string" && p.logo ? { logo: p.logo } : {}), ...(typeof p.flag === "string" && p.flag.trim() ? { flag: p.flag.trim() } : {}),