Archilyzer · Source

archilyzer

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

commit 0eb7da6dc6f705a70c2581a2eaed737fcc934f42
parent 22b3729aaacf07137dc67ae155f6e0b539805bdb
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue,  3 Nov 2026 09:30:11 -0500

Merge lane/post-paraphrase: a post item's context (its quoted post, each parent) may carry the operator's paraphrase -- drawn in its place with a PARAPHRASED label, the original kept, the reading time from the paraphrase; posts set-item quoted./parent.<i>.paraphrase, a box per context in the post bench

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

Diffstat:
Mumtool/components/projects/PostBench.tsx | 71++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mumtool/components/projects/review/PostItemPlayer.tsx | 6++++--
Mumtool/docs/cli.md | 2+-
Mumtool/docs/knobs.md | 1+
Mumtool/docs/report-video.md | 7++++++-
Mumtool/e2e/post-items.spec.ts | 30++++++++++++++++++++++++++++++
Mumtool/lib/report/manifest.mjs | 34+++++++++++++++++++++++++++++++---
Mumtool/lib/report/postReel.test.mjs | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/postsCli.mjs | 20++++++++++++++++----
Mumtool/report-to-video/post-item.mjs | 35++++++++++++++++++++++++++++++-----
Mumtool/report-to-video/post-item.test.mjs | 41++++++++++++++++++++++++++++++++++++++++-
11 files changed, 277 insertions(+), 20 deletions(-)

diff --git a/umtool/components/projects/PostBench.tsx b/umtool/components/projects/PostBench.tsx @@ -6,7 +6,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { buttonVariants } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { postBenchHref } from "@/lib/hrefs"; -import { POST_HOLD, POST_MEDIA_MIN_SPAN, postItemPlan, readingSeconds, ruleSeconds } from "umtool-report-to-video/post-item"; +import { POST_HOLD, POST_MEDIA_MIN_SPAN, POST_PARAPHRASE_MAX, contextReadSeconds, postItemPlan, readingSeconds, ruleSeconds } from "umtool-report-to-video/post-item"; import PostItemPlayer, { type PostPlan } from "./review/PostItemPlayer"; import PostNarrationPanel from "./PostNarrationPanel"; @@ -23,12 +23,23 @@ import PostNarrationPanel from "./PostNarrationPanel"; // its sound, a crop of any attachment, an image's push-in, // and a video's words: Transcribe asks the EDITOR's // transcription (a job on a local worker), never ASR here +// context the post it quotes, the posts it answers: a paraphrase of +// a long one, drawn in place of its words with a +// "paraphrased" label (its own text kept, shown beside) // --------------------------------------------------------------------------- type Media = Record<string, unknown> & { src: string; kind: string; seconds?: number; start?: number; end?: number; mute?: boolean; crop?: number[]; push?: boolean; words?: string; audio?: boolean; width?: number; height?: number }; -type Entry = Record<string, unknown> & { id: string; media?: Media[]; hold?: number; mediaLayout?: string; redact?: boolean }; +type Ref = Record<string, unknown> & { author?: string; handle?: string; text?: string; paraphrase?: string }; +type Entry = Record<string, unknown> & { id: string; media?: Media[]; hold?: number; mediaLayout?: string; redact?: boolean; quoted?: Ref; parents?: Ref[] }; const r2 = (v: number) => Math.round(v * 100) / 100; +/** A context post with its paraphrase set (undefined: none, its own words). */ +const withParaphrase = (ref: Ref, paraphrase: string | undefined): Ref => { + const out = { ...ref }; + if (paraphrase === undefined) delete out.paraphrase; + else out.paraphrase = paraphrase; + return out; +}; const CROPS: Array<{ label: string; crop: number[] | null }> = [ { label: "none", crop: null }, { label: "centre 80%", crop: [0.1, 0.1, 0.8, 0.8] }, @@ -129,7 +140,24 @@ export default function PostBench({ }, ]), ), + ...(e.quoted && typeof e.quoted === "object" ? { quoted: { paraphrase: e.quoted.paraphrase?.trim() ? e.quoted.paraphrase : null } } : {}), + ...(Array.isArray(e.parents) && e.parents.length + ? { parents: Object.fromEntries(e.parents.map((p, i) => [i, { paraphrase: p?.paraphrase?.trim() ? p.paraphrase : null }])) } + : {}), }); + // The context posts the card draws: the one it quotes, the ones it answers (nearest first). + const contexts: Array<{ key: string; label: string; ref: Ref; set: (paraphrase: string | undefined) => void }> = [ + ...(Array.isArray(entry.parents) ? entry.parents : []).map((ref, i) => ({ + key: `parent.${i}`, + label: i === 0 ? "the post it answers" : `the post that answers (${i + 1} up)`, + ref, + set: (paraphrase: string | undefined) => + setEntry((x) => ({ ...x, parents: (x.parents ?? []).map((p, j) => (j === i ? withParaphrase(p, paraphrase) : p)) })), + })), + ...(entry.quoted && typeof entry.quoted === "object" + ? [{ key: "quoted", label: "the post it quotes", ref: entry.quoted, set: (paraphrase: string | undefined) => setEntry((x) => ({ ...x, quoted: withParaphrase(x.quoted ?? {}, paraphrase) })) }] + : []), + ]; const save = useCallback(async () => { setError(null); setStatus("saving…"); @@ -206,7 +234,7 @@ export default function PostBench({ </span> </div> <div className="relative w-full overflow-hidden rounded border border-seam bg-black" style={{ aspectRatio: `${box.width} / ${box.height}` }}> - <PostItemPlayer project={project} entry={entry} plan={plan} box={box} s={s} playing={playing} /> + <PostItemPlayer project={project} entry={entry} plan={plan} box={box} s={s} playing={playing} cardKey={token} /> </div> <div className="flex items-center gap-2 text-[12px]"> <button type="button" className={btn} data-post-bench-play="" onClick={() => (s >= total ? (setS(0), setPlaying(true)) : setPlaying((p) => !p))}> @@ -308,6 +336,43 @@ export default function PostBench({ </label> </section> + {contexts.map(({ key, label, ref, set }) => { + const para = typeof ref.paraphrase === "string" ? ref.paraphrase : ""; + return ( + <section key={key} className="rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-3" data-post-bench-context={key}> + <h2 className="micro mb-2"> + {label} · {ref.author || (ref.handle ? `@${ref.handle}` : "?")} + </h2> + <p className="m-0 mb-1 text-text-2">its words{para.trim() ? " (kept; the card shows the paraphrase)" : ""}</p> + <blockquote className="m-0 max-h-32 overflow-y-auto whitespace-pre-wrap border-l-2 border-[var(--color-line)] pl-2 text-[12px] text-text-2" data-post-bench-original={key}> + {ref.text || "(no words archived)"} + </blockquote> + <label className="mt-2 block"> + Paraphrase + <textarea + value={para} + maxLength={POST_PARAPHRASE_MAX} + rows={3} + placeholder="absent: its own words" + onChange={(e) => set(e.target.value === "" ? undefined : e.target.value)} + className="mt-1 block w-full rounded border border-seam bg-ground px-1.5 py-1" + data-post-bench-paraphrase={key} + /> + </label> + <div className="mt-1 flex items-center gap-2 text-[11.5px] text-text-2"> + <span> + {para.length} / {POST_PARAPHRASE_MAX} · read {contextReadSeconds(ref).toFixed(1)} s{para.trim() ? " · labelled “paraphrased” on the card" : ""} + </span> + {para !== "" && ( + <button type="button" className="ink-link ml-auto" onClick={() => set(undefined)} data-post-bench-paraphrase-clear={key}> + clear + </button> + )} + </div> + </section> + ); + })} + {media.map((m, i) => { const st = stepOf(i); const timed = m.kind === "video" || m.kind === "gif"; diff --git a/umtool/components/projects/review/PostItemPlayer.tsx b/umtool/components/projects/review/PostItemPlayer.tsx @@ -174,7 +174,7 @@ function MediaEl({ } export default function PostItemPlayer({ - project, take = null, entry, plan, box, s, playing, + project, take = null, entry, plan, box, s, playing, cardKey = null, }: { project: string; take?: string | null; @@ -184,6 +184,8 @@ export default function PostItemPlayer({ /** The item's own second (0: its first frame). */ s: number; playing: boolean; + /** Changes when the saved item does (the bench: its manifest token), so the card page is drawn again. */ + cardKey?: string | null; }) { const wrap = useRef<HTMLDivElement | null>(null); const [scale, setScale] = useState(0); @@ -217,7 +219,7 @@ export default function PostItemPlayer({ }, [box.width]); const layout = useMemo(() => postLayout(entry, box), [entry, box]); const pageUrl = (phase: "read" | "media") => - `/api/report/post-item?project=${encodeURIComponent(project)}&id=${encodeURIComponent(entry.id)}&w=${Math.round(box.width)}&h=${Math.round(box.height)}&phase=${phase}${take ? `&take=${encodeURIComponent(take)}` : ""}`; + `/api/report/post-item?project=${encodeURIComponent(project)}&id=${encodeURIComponent(entry.id)}&w=${Math.round(box.width)}&h=${Math.round(box.height)}&phase=${phase}${take ? `&take=${encodeURIComponent(take)}` : ""}${cardKey ? `&v=${encodeURIComponent(cardKey)}` : ""}`; const reading = s < plan.reading || !plan.steps.length; const current = stepAt(plan, s); // Beside the card, the first attachment is up (its first frame) while the words are read. diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -82,7 +82,7 @@ Inbox cannot disagree about what is wrong with one. | `posts set <project> <post> thread=on\|off [hide=on\|off] [attach=<clipId>\|auto] [crop=<px>\|off] [--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.; `crop=<px>` the post's own crop of its screenshot (`shotMaxHeight`, 120–1080: its top that tall, never panned; `off` removes it) ([knobs.md](knobs.md#add-post-a-post-card-from-play-the-cut)). 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] [--crop <px>] [--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). `--crop <px>`: the post's own crop (`shotMaxHeight`). A post that quotes another, reposts one or carries media is added with a `WARNING:` line (`--json`: `warnings`) — its screenshot shows them, by the post's own data. Play the cut's **Add post** runs this same write ([knobs.md](knobs.md#add-post-a-post-card-from-play-the-cut)) | | `posts reel <project> --channel <slug> [--channel <slug> …] [--since YYYY-MM-DD] [--until YYYY-MM-DD] [--own] [--with-media] [--replies include\|only\|exclude] [--order chrono\|reverse] [--limit N] [--after <id\|->] [--dry-run] [--json]` | **POST ITEMS** ([report-video.md](report-video.md#post-items-a-post-as-an-entry-of-the-cut)): each archived post an entry of the cut -- its card drawn from the archive row (snapshotted), its attachments copied into `posts-media/` and played in it. The channels are read as one archive, merged in time order, de-duplicated by post id (`--channel ObviousRises-x --channel ObviousRises-x-replies`); `--own` the accounts' own posts (their config's `socialHandle`, no reposts); `--with-media` only posts whose capture holds an attachment; `--replies` keeps, keeps only or drops replies (a reply carries the posts it answers from the archive, else the capture's thread shot, else a "Replying to" line; the quoted post and the parent the archive lacks come from the capture's `context`, as `posts context` fills them). A post the cut already plays (by its id, a repost's original, a repost of it) is skipped, so a **re-run adds only what is new**; the rest goes in in ONE write (one undo point: `timeline <p> undo`), at the end unless `--after` | -| `posts set-item <project> <item> [hold=<s>\|off] [layout=sequence\|grid] [redact=on\|off\|auto] [fit=read[:<linger>]] [media.<i>.start=<s>] [media.<i>.end=<s>] [media.<i>.trim=off] [media.<i>.mute=on\|off] [media.<i>.crop=x,y,w,h\|off] [media.<i>.push=on\|off] [--json]` | a **post item's knobs** (the post bench's writer, `updatePostItem`; [knobs.md](knobs.md#a-post-item-a-post-as-an-entry-of-the-cut)): `<item>` is its id or the post's id; refused in the build's words | +| `posts set-item <project> <item> [hold=<s>\|off] [layout=sequence\|grid] [redact=on\|off\|auto] [fit=read[:<linger>]] [media.<i>.start=<s>] [media.<i>.end=<s>] [media.<i>.trim=off] [media.<i>.mute=on\|off] [media.<i>.crop=x,y,w,h\|off] [media.<i>.push=on\|off] [quoted.paraphrase="…"\|off] [parent.<i>.paraphrase="…"\|off] [--json]` | a **post item's knobs** (the post bench's writer, `updatePostItem`; [knobs.md](knobs.md#a-post-item-a-post-as-an-entry-of-the-cut)): `<item>` is its id or the post's id; refused in the build's words. `quoted.paraphrase` / `parent.<i>.paraphrase`: your retelling of a long context post (≤ 600 characters), drawn in place of its words with a "paraphrased" label (its text kept); `off` or empty clears it | | `posts narrate <project> --import [--dry-run] [--json]` · `--list` · `<item> [--script "…"] [--pick <n>] [--approve\|--unapprove] [--off\|--on] [lead= tail= ramp= linger= clip=read\|full wet= lowpass= duck=on\|off short=hold\|loop attach=under\|after lufs=]` · `<item> --take [--note "…"] [--voice v] [--engine e] [--speed s] [--script "…"]` · `<item> --derive <n> --op enhance\|convert [--engine e] [--voice v]` · `<item> --delete <n>` · `--all --draft-scripts [--force]` · `--all --take [--limit N]` · `--cut <k=v>…` | a **narrated post item** ([report-video.md](report-video.md#narrated-post-items), [knobs.md](knobs.md#a-narrated-post-item)): `--import` reads `narration/posts/index.json` (`[{id, entry, script, takes: [{file, engine, voice, seconds}], pick}]`, and a take's `take-<n>.parts.json`) into the cut in ONE write, measuring each take (length, loudness); a re-run adds only takes not there. `--take` asks the EDITOR for a new take (`POST /api/ops/tts`, its `out` the next `narration/posts/<postId>/take-<n>.<engine>-<voice>.wav`; a job, waited for; `ARCHILYZER_EDITOR_URL`, `WORKER_TOKEN`) and picks it, its `--note` kept with it; `--pick <n>` is the take's number as `--list` shows it. `--derive <n>` makes a NEW take from take n through the editor's `voice-enhance` / `voice-convert` op (a stock synthetic voice; "not installed" until the editor has the engine), the original kept; `--delete <n>` moves a take's file to the post's `.trash/`. A new script or pick takes the approval away. `--all --draft-scripts` writes every post's words as its script, VERBATIM (cleaned only to be spoken: @handles, links, emoji dropped; `plan(s)` → plans, `w/` → with, `&` → and; paragraphs kept). `--cut` sets `render.postNarration`. Refused in the build's words (**exit 1**) | | `posts fit <project> [--all \| <item> …] [--linger <s>] [--dry-run] [--json]` · `posts set-item <project> <item> fit=read[:<linger>]` | narrated posts' video attachments cut to their **best part** for the read (lead + take + tail + linger): a scored scan of the sound (loudness, its peaks), the speech (a transcript) and the scene cuts, the start snapped to a pause or a cut, recorded with why (`narration.window`) -- ONE write; each post's old and new length printed. A video no longer than the read is left as it is | | `posts avatar <project> [<handle> <image-file> \| <handle> off] [--json]` · `posts avatars <project> [--dry-run] [--json]` | the **authors' pictures** (`postAvatars`): `avatar` copies a picture into `posts-media/_avatars/` for every card that draws that handle (manual; never replaced by the archive's), `off` clears it, no handle lists them; `avatars` copies the archive's (the channels' `posts-media/_avatars/avatars.json`, capture-posts') for every author the cut's cards draw unblurred that it has none of. A blurred author never shows one | diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -647,6 +647,7 @@ its knobs are one writer, `updatePostItem` (`lib/report/manifest.mjs`), refused | `hold` — the item's whole length in seconds (1–120; absent: the pacing rule, the item is its read) | post bench, **hold** | `umtool posts set-item <p> <item> hold=12` (`hold=off`) | `POST /api/report/post-item {project, op: "set", id, patch: {hold}, token}` | | `mediaLayout` — `grid`: its 2-4 images at once (one picture of the read); absent: one after another, cycling | post bench, **images** | `layout=grid` (`layout=sequence`) | same, `patch: {mediaLayout}` | | `redact` — other authors (the posts it answers, the one it quotes, a repost's original): absent, the privacy rule (blurred unless a subject or gold/grey verified); `false` shows them (judged public); `true` blurs even the verified | post bench, **other authors** | `redact=off` · `redact=on` · `redact=auto` | same, `patch: {redact}` | +| `quoted.paraphrase`, `parents[i].paraphrase` — your short retelling (≤ 600 characters) of a long context post (the post it quotes, the posts it answers, nearest first): the card (render, Play, the bench, the recording page) draws it in place of that post's words, in the same style, with a small **paraphrased** label beside its date; its read counts the paraphrase's words; the author stays under the blur rule; its `text` is never touched. Absent or empty: its own words | post bench, the context block's **Paraphrase** (its words shown above it; **clear**), then **Save** | `quoted.paraphrase="He reviewed three of the videos."` · `parent.0.paraphrase="…"` (`=off`) | same, `patch: {quoted: {paraphrase}, parents: {"0": {paraphrase}}}` | | `media[i].start`, `media[i].end` — a video's or a GIF's in and out, its own seconds (at least 0.5 s apart) | post bench, **in / out**, **In at playhead**, **Out at playhead**, **Whole** | `media.0.start=1.5 media.0.end=6` · `media.0.trim=off` | same, `patch: {media: {"0": {start, end}}}` | | `media[i].mute` — `true`: the video plays silent | post bench, **its sound** | `media.0.mute=on` (`=off`) | same | | `media[i].crop` — `[x, y, w, h]`, fractions of the picture: what of it is shown | post bench, **crop** (none, centre 80%, top half, bottom half) | `media.0.crop=0,0.1,1,0.8` (`=off`) | same | diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md @@ -428,6 +428,8 @@ the generator. "parentShot": "posts-media/<slug>/<id>/shot-thread.png", // …else the capture's thread shot "replyingTo": "handle", // …else a "Replying to @…" line "quoted": { "author": "…", "handle": "…", "text": "…" }, // the post it quotes + // a context post (quoted, parents[i]) may carry "paraphrase": "…" (≤ 600 + // chars): drawn in place of its text, labelled "paraphrased"; text kept "media": [{ "src": "posts-media/ObviousRises-x/2116052735661654457/…_1.mp4", // copied INTO the project "kind": "video", "seconds": 4.992, "width": 1080, "height": 1350, "audio": true, "start": 0.5, "end": 4, "mute": false, // a video's or a GIF's trim, its sound @@ -441,7 +443,10 @@ the generator. **How it plays.** A native card drawn from the snapshot — the author's name and handle, the date, the words, the counts, "reposted by", the posts it answers above it -(a thread line down to it), the post it quotes inside it — in the deck's palette and +(a thread line down to it), the post it quotes inside it (a context post the operator +PARAPHRASED drawn as the paraphrase, in the same style, with a small "paraphrased" label +beside its date — never as the author's words; its reading time counts the paraphrase) +— in the deck's palette and faces, by the browser the build already uses for the chrome (`postCardHtml`; never a screenshot of the platform). **One layout** (operator, 2 Nov: "the gallery cycle needs to be shown like a video and text stays on the screen the whole time"): no diff --git a/umtool/e2e/post-items.spec.ts b/umtool/e2e/post-items.spec.ts @@ -129,6 +129,36 @@ test("the post bench trims the video attachment and saves it; the cut's seconds await expect(page.locator('[data-entry="p-vid"] [data-post-seconds]')).toHaveText("4.7s"); }); +test("the post bench paraphrases a context post: the card draws it labelled, the read counts it, the original kept", async ({ page }) => { + await page.setViewportSize({ width: 1366, height: 1000 }); + await page.goto(urls.postBenchHref(PROJECT, "p-txt")); + await expect(page.locator('[data-post-bench="p-txt"]')).toBeVisible(); + // 12 words (5 s) + its parent's 7 (2.33 s). + await expect(page.locator("[data-post-bench-rule]")).toHaveText("7.3 s"); + const block = page.locator('[data-post-bench-context="parent.0"]'); + await expect(block.locator('[data-post-bench-original="parent.0"]')).toHaveText("The first thing I said about it."); + await block.locator('[data-post-bench-paraphrase="parent.0"]').fill("He said it first."); + // The read counts the paraphrase's 4 words (1.33 s), at once. + await expect(page.locator("[data-post-bench-rule]")).toHaveText("6.3 s"); + await page.locator("[data-post-bench-save]").click(); + await expect(page.locator("[data-post-bench-status]")).toHaveText("saved"); + const saved = timeline().find((e) => e.id === "p-txt") as Entry & { parents: { text: string; paraphrase?: string }[] }; + expect(saved.parents[0]).toMatchObject({ text: "The first thing I said about it.", paraphrase: "He said it first." }); + // The card (the build's page, drawn again after the save): the paraphrase, labelled; never the original words. + const card = page.frameLocator('[data-post-card-frame="read"]'); + await expect(card.locator('[data-post-parent="0"] [data-post-paraphrase]')).toHaveText("He said it first."); + await expect(card.locator('[data-post-parent="0"] [data-post-paraphrased]')).toHaveText(/paraphrased/i); + await expect(card.locator("body")).not.toContainText("The first thing I said about it."); + if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-items-paraphrase.png") }); + // Cleared (the terminal's writer): its own words again, no label. + umtool(["posts", "set-item", PROJECT, "p-txt", "parent.0.paraphrase=off"]); + expect((timeline().find((e) => e.id === "p-txt") as Entry & { parents: Record<string, unknown>[] }).parents[0].paraphrase).toBeUndefined(); + await page.reload(); + await expect(page.frameLocator('[data-post-card-frame="read"]').locator('[data-post-parent="0"]')).toContainText("The first thing I said about it."); + await expect(page.frameLocator('[data-post-card-frame="read"]').locator("[data-post-paraphrased]")).toHaveCount(0); + await expect(page.locator("[data-post-bench-rule]")).toHaveText("7.3 s"); +}); + test("umtool posts reel adds only what the cut does not play yet, in one write", async () => { const dry = JSON.parse(umtool(["posts", "reel", PROJECT, "--channel", "postchan-x", "--own", "--dry-run", "--json"])) as { entries: { id: string }[]; already: number }; // 0 is p-txt's parent (not an item yet), 1-3 are in the cut, 4 is new; 9 is not the subject's. diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -2353,12 +2353,17 @@ export async function insertEntries(dir, afterId, specs, { token = null, op = "i export const POST_ITEM_KNOBS = Object.freeze(["hold", "mediaLayout", "redact"]); /** A post item attachment's knobs: its trim, its sound, its crop, the push-in, its transcript. */ export const POST_MEDIA_KNOBS = Object.freeze(["start", "end", "mute", "crop", "push", "words"]); +/** A context post's knobs (`quoted`, `parents[i]`): the operator's paraphrase of its words. */ +export const POST_CONTEXT_KNOBS = Object.freeze(["paraphrase"]); /** * SET A POST ITEM's KNOBS (the post bench, `umtool posts set-item`): `patch` * is `{ hold?, mediaLayout?, redact?, media?: { <i>: { start?, end?, mute?, - * crop?, push?, words? } } }`; a null clears a knob (the default again). One - * structural write, refused in the build's words (validatePostItem). + * crop?, push?, words? } }, quoted?: { paraphrase? }, parents?: { <i>: + * { paraphrase? } } }`; a null clears a knob (the default again), and so + * does an empty paraphrase (the context's own words again; its `text` is + * never touched). One structural write, refused in the build's words + * (validatePostItem). * * @param {string} dir * @param {string} id @@ -2368,7 +2373,7 @@ export const POST_MEDIA_KNOBS = Object.freeze(["start", "end", "mute", "crop", " 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 (k !== "media" && !POST_ITEM_KNOBS.includes(k)) throw new Error(`${k} is not a post item knob (${[...POST_ITEM_KNOBS, "media"].join(", ")})`); + 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(", ")})`); } return structural(dir, "post-item", token, (m) => { const i = entryIndex(m.timeline, id); @@ -2396,6 +2401,29 @@ 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. + 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(", ")})`); + if ("paraphrase" in cp) { + const v = cp.paraphrase; + 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 (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}`); + } + } const errors = validatePostItem(e); if (errors.length) throw new StructureRefused(errors); return { id, at: i, entry: e }; diff --git a/umtool/lib/report/postReel.test.mjs b/umtool/lib/report/postReel.test.mjs @@ -148,3 +148,53 @@ test("a take's window times a post item by the duration rule, not a card's 4 s", assert.deepEqual(windowEntries(tl, { at: 0, dur: 20 }).ids, ["a", "b"]); assert.deepEqual(windowEntries(tl, { at: 44, dur: 2 }).ids, ["c", "c01"]); }); + +test("a context post's paraphrase: set and cleared by updatePostItem and posts set-item, its text never touched", async () => { + const p = await project("reel-para"); + const m0 = await manifest(p); + const quoted = { id: "900", author: "Someone Else", handle: "someone_else", badge: "blue", date: "2026-11-02T16:21:59.000Z", text: "the long original words of the quoted post" }; + const parent = { id: "901", author: "A Parent", handle: "a_parent", date: "2026-11-02T15:00:00.000Z", text: "the parent's own words" }; + m0.timeline.push({ type: "post", id: "p-1", post: "subj-x/1", platform: "x", author: "Subject", handle: "Subject", date: "2026-11-02T21:19:53.000Z", text: "the post", quoted, parents: [parent] }); + m0.timeline.push({ type: "post", id: "p-2", post: "subj-x/2", platform: "x", author: "Subject", handle: "Subject", date: "2026-11-02T21:19:53.000Z", text: "no context" }); + await writeFile(path.join(p.dir, "video.manifest.json"), JSON.stringify(m0, null, 2)); + const item = async (id) => (await manifest(p)).timeline.find((e) => e.id === id); + + await updatePostItem(p.dir, "p-1", { quoted: { paraphrase: " He reviewed three videos. " }, parents: { 0: { paraphrase: "A question." } } }); + let e = await item("p-1"); + assert.equal(e.quoted.paraphrase, "He reviewed three videos."); + assert.equal(e.quoted.text, quoted.text); + assert.equal(e.parents[0].paraphrase, "A question."); + assert.equal(e.parents[0].text, parent.text); + // Refused in words: too long, no such context, not a knob. + await assert.rejects(updatePostItem(p.dir, "p-1", { quoted: { paraphrase: "x".repeat(601) } }), /quoted\.paraphrase is longer than 600/); + await assert.rejects(updatePostItem(p.dir, "p-2", { quoted: { paraphrase: "x" } }), /quotes no post/); + await assert.rejects(updatePostItem(p.dir, "p-1", { parents: { 1: { paraphrase: "x" } } }), /no parent 1/); + await assert.rejects(updatePostItem(p.dir, "p-1", { quoted: { text: "rewritten" } }), /not a context knob/); + // An empty paraphrase (or null) clears it: the original again. + await updatePostItem(p.dir, "p-1", { parents: { 0: { paraphrase: "" } } }); + e = await item("p-1"); + assert.equal("paraphrase" in e.parents[0], false); + assert.equal(e.quoted.paraphrase, "He reviewed three videos."); + + // The CLI: quoted.paraphrase="…" and parent.<i>.paraphrase="…", off clears; one write each. + const run = async (...pairs) => { + const out = []; + const code = await postsCommand(["set-item", "reel-para", "p-1", ...pairs], { root: REPORTS, out: (s) => out.push(s), err: (s) => out.push(s) }); + return { code, out: out.join("\n") }; + }; + let r = await run("parent.0.paraphrase=Is it true? No."); + assert.equal(r.code, 0, r.out); + assert.match(r.out, /parent 0 \(@a_parent\): paraphrased -- "Is it true\? No\."/); + assert.equal((await item("p-1")).parents[0].paraphrase, "Is it true? No."); + r = await run("quoted.paraphrase=off"); + assert.equal(r.code, 0, r.out); + e = await item("p-1"); + assert.equal("paraphrase" in e.quoted, false); + assert.equal(e.quoted.text, quoted.text); + // "no" is a paraphrase, not off. + r = await run("quoted.paraphrase=no"); + assert.equal((await item("p-1")).quoted.paraphrase, "no"); + const { postItemPatchOf } = await import("./postsCli.mjs"); + assert.deepEqual(postItemPatchOf(["quoted.paraphrase=a = b", "parent.1.paraphrase=", "parents.0.paraphrase=OFF"]), { quoted: { paraphrase: "a = b" }, parents: { 1: { paraphrase: null }, 0: { paraphrase: null } } }); + assert.throws(() => postItemPatchOf(["quoted.text=x"]), /not a post item knob/); +}); diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs @@ -58,10 +58,13 @@ export const POSTS_USAGE = [ " adds only what is new -- in ONE write (one undo point), at the end unless --after.", " umtool posts set-item <project> <item> [hold=<s>|off] [layout=sequence|grid] [redact=on|off|auto]", " [media.<i>.start=<s>] [media.<i>.end=<s>] [media.<i>.mute=on|off] [media.<i>.crop=x,y,w,h|off]", - " [media.<i>.push=on|off] [media.<i>.trim=off] [--json]", + " [media.<i>.push=on|off] [media.<i>.trim=off] [quoted.paraphrase=\"…\"|off]", + " [parent.<i>.paraphrase=\"…\"|off] [--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`).", + " video cut to its best part for the read, `posts fit`). quoted.paraphrase / parent.<i>.paraphrase (nearest first):", + " your retelling of a long context post (at most 600 characters), drawn in place of its words and labelled", + " \"paraphrased\"; its own text is kept; off (or empty) shows its words again.", " umtool posts narrate <project> … a post item's narration: script, takes (the editor's tts), pick, approve, mix", " (umtool posts narrate --help)", " umtool posts fit <project> [--all|<item> …] [--linger s] [--dry-run] narrated posts' videos cut to their best part", @@ -529,10 +532,15 @@ const onOff = (v, k) => { throw new CliError(`${k}= takes on or off, not ${JSON.stringify(v)}`); }; +/** A paraphrase's words, or null for `off` / empty (its own words again). */ +const paraphraseOf = (raw) => (raw.trim() === "" || raw.trim().toLowerCase() === "off" ? null : raw); + /** * `posts set-item`'s words as updatePostItem's patch: `hold=<s>|off`, * `layout=sequence|grid`, `redact=on|off|auto`, `media.<i>.start|end=<s>`, - * `media.<i>.mute|push=on|off`, `media.<i>.crop=x,y,w,h|off`, `media.<i>.trim=off`. + * `media.<i>.mute|push=on|off`, `media.<i>.crop=x,y,w,h|off`, `media.<i>.trim=off`, + * `quoted.paraphrase=<words>|off`, `parent.<i>.paraphrase=<words>|off` (only + * `off` or empty clears a paraphrase: "no" is a paraphrase). */ export function postItemPatchOf(pairs) { /** @type {Record<string, any>} */ @@ -546,9 +554,11 @@ export function postItemPatchOf(pairs) { if (k === "hold") out.hold = OFF.has(v) || v === "" ? null : Number(raw); else if (k === "layout") out.mediaLayout = v === "sequence" ? null : v; else if (k === "redact") out.redact = v === "auto" || v === "" ? null : onOff(v, k); + 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 { 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=, media.<i>.start|end|mute|crop|push|trim=)`); + if (!m) throw new CliError(`${pair}: not a post item knob (hold=, layout=, redact=, media.<i>.start|end|mute|crop|push|trim=, quoted.paraphrase=, parent.<i>.paraphrase=)`); 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); @@ -612,6 +622,8 @@ async function setItemCommand(projectArg, ref, pairs, { root, json, out }) { } const { postItemSeconds } = await import("umtool-report-to-video/post-item"); out(`set ${hit.id}: ${postItemSeconds(result.entry).toFixed(1)} s${result.entry.hold ? ` (hold)` : ""}`); + const refs = [["quoted", patch.quoted ? result.entry.quoted : null], ...Object.keys(patch.parents ?? {}).map((i) => [`parent ${i}`, result.entry.parents?.[Number(i)]])]; + for (const [what, ref] of refs) if (ref) out(` ${what} (@${ref.handle ?? "?"}): ${ref.paraphrase ? `paraphrased -- "${ref.paraphrase}"` : "its own words"}`); return 0; } diff --git a/umtool/report-to-video/post-item.mjs b/umtool/report-to-video/post-item.mjs @@ -13,7 +13,10 @@ // mediaLayout?: "sequence"|"grid", hold?, redact?, onscreen? } // // where a <ref> (a post it quotes, the posts it answers, nearest first) is -// `{ id?, author?, handle?, badge?, date?, text?, url? }`. The archive row is +// `{ id?, author?, handle?, badge?, date?, text?, url?, paraphrase? }` -- +// `paraphrase` the operator's short retelling of a long context post +// (POST_PARAPHRASE_MAX characters), drawn in place of its words with a +// "paraphrased" label (contextText); `text` is kept untouched. The archive row is // SNAPSHOTTED into the entry when it goes in (postReel.mjs): a cut renders the // words and counts it was made with, not whatever the archive says next week. // @@ -38,6 +41,7 @@ export const POST_MEDIA_LAYOUTS = Object.freeze(["sequence", "grid"]); * reading = clamp(READ.lead + words / READ.wps, READ.min, READ.max) * + for each post it answers and the post it quotes: * clamp(words / READ.wps, CONTEXT_READ.min, CONTEXT_READ.max) -- 1-4 s: context, not the post + * (the words its card shows: its paraphrase's, when it has one) * media = a video: its trimmed length (end - start), its sound on; * a GIF: looped to at least GIF.min s (one pass when longer, at most GIF.max); * an image: IMAGE_SECONDS; a grid of 2-4 images: GRID.base + GRID.per × (n - 1) @@ -59,6 +63,8 @@ export const POST_HOLD = Object.freeze({ min: 1, max: 120 }); export const POST_MEDIA_MAX = 4; /** The posts it answers drawn above it (the reply chain), nearest first: at most this many. */ export const POST_PARENTS_MAX = 2; +/** A context post's paraphrase (`quoted.paraphrase`, `parents[i].paraphrase`): at most this many characters. */ +export const POST_PARAPHRASE_MAX = 600; /** A video attachment's shortest trimmed span, in seconds. */ export const POST_MEDIA_MIN_SPAN = 0.5; /** An image's slow push-in (`push: true`): this much larger by the end of its span. */ @@ -90,9 +96,21 @@ export function readSeconds(entry) { return clamp(POST_READ.lead + wordCount(cardText(entry)) / POST_READ.wps, POST_READ.min, POST_READ.max); } -/** Seconds to read one post of its context (a parent, the quoted post). */ +/** Whether a context post (a parent, the quoted post) is drawn as the operator's paraphrase. */ +export const isParaphrased = (ref) => !!str(ref?.paraphrase).trim(); + +/** + * The words a context post's card shows: the operator's PARAPHRASE when it + * has one (drawn with a "paraphrased" label -- never taken for the author's + * words), else its own text. + */ +export function contextText(ref) { + return isParaphrased(ref) ? str(ref.paraphrase).trim() : str(ref?.text); +} + +/** Seconds to read one post of its context (a parent, the quoted post): the words its card shows. */ export function contextReadSeconds(ref) { - return clamp(wordCount(ref?.text) / POST_READ.wps, POST_CONTEXT_READ.min, POST_CONTEXT_READ.max); + return clamp(wordCount(contextText(ref)) / POST_READ.wps, POST_CONTEXT_READ.min, POST_CONTEXT_READ.max); } /** The whole reading time: the post and its context. */ @@ -372,6 +390,10 @@ function refErrors(r, where) { if (r.handle !== undefined && (typeof r.handle !== "string" || !HANDLE_RE.test(r.handle))) errors.push(`${where}.handle must be a handle`); if (r.badge !== undefined && r.badge !== null && !BADGES.includes(r.badge)) errors.push(`${where}.badge must be one of ${BADGES.join(", ")}`); if (typeof r.text === "string" && r.text.length > TEXT_MAX) errors.push(`${where}.text is longer than ${TEXT_MAX} characters`); + 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`); + } return errors; } @@ -727,6 +749,8 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p .map(([k2, v]) => `<span class="count"><b>${countText(v)}</b> ${k2 === "replies" && v === 1 ? "reply" : k2 === "reposts" && v === 1 ? "repost" : k2 === "likes" && v === 1 ? "like" : k2 === "quotes" && v === 1 ? "quote" : k2}</span>`) .join(""); const ctx = []; + // A paraphrased context says so, beside its date: the viewer must not take the words for the author's. + const paraLabel = (ref) => (isParaphrased(ref) ? '<span class="plabel" data-post-paraphrased="">paraphrased</span>' : ""); // The posts it answers, oldest first, a thread line down to the post. const parents = parentsOf(entry); for (let i = parents.length - 1; i >= 0; i -= 1) { @@ -734,7 +758,7 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p const r = red(`parents[${i}]`); const subject = !r && subjectsOf(entry).some((h) => String(h).toLowerCase() === String(p.handle ?? "").replace(/^@/, "").toLowerCase()); ctx.push( - `<div class="parent" data-post-parent="${i}"${r ? ' data-redacted=""' : ""}>${avatarHtml(p, { redact: r, size: Math.round(44 * k), accent: subject ? pal.accent : undefined, img: pic(p) })}<div class="pbody"><div class="phead">${nameHtml(p, { redact: r })}<span class="pdate">${esc(cardDate(p.date).split(" · ")[0])}</span></div><div class="ptext">${wordsHtml(str(p.text) || (p.url ? "(not archived)" : ""), blurred)}</div></div></div>`, + `<div class="parent" data-post-parent="${i}"${r ? ' data-redacted=""' : ""}>${avatarHtml(p, { redact: r, size: Math.round(44 * k), accent: subject ? pal.accent : undefined, img: pic(p) })}<div class="pbody"><div class="phead">${nameHtml(p, { redact: r })}<span class="pdate">${esc(cardDate(p.date).split(" · ")[0])}</span>${paraLabel(p)}</div><div class="ptext"${isParaphrased(p) ? ' data-post-paraphrase=""' : ""}>${wordsHtml(contextText(p) || (p.url ? "(not archived)" : ""), blurred)}</div></div></div>`, ); } if (!parents.length && parentShotUrl) ctx.push(`<div class="pshot" data-post-parent-shot=""><img src="${esc(parentShotUrl)}" alt=""></div>`); @@ -743,7 +767,7 @@ export function postCardHtml(entry, { width, height, palette = {}, fonts = {}, p } const q = isObj(entry.quoted) ? entry.quoted : null; const quoted = q - ? `<div class="quoted" data-post-quoted=""${red("quoted") ? ' data-redacted=""' : ""}><div class="phead">${avatarHtml(q, { redact: red("quoted"), size: Math.round(30 * k), img: pic(q) })}${nameHtml(q, { redact: red("quoted") })}<span class="pdate">${esc(cardDate(q.date).split(" · ")[0])}</span></div><div class="qtext">${wordsHtml(str(q.text), blurred)}</div></div>` + ? `<div class="quoted" data-post-quoted=""${red("quoted") ? ' data-redacted=""' : ""}><div class="phead">${avatarHtml(q, { redact: red("quoted"), size: Math.round(30 * k), img: pic(q) })}${nameHtml(q, { redact: red("quoted") })}<span class="pdate">${esc(cardDate(q.date).split(" · ")[0])}</span>${paraLabel(q)}</div><div class="qtext"${isParaphrased(q) ? ' data-post-paraphrase=""' : ""}>${wordsHtml(contextText(q), blurred)}</div></div>` : ""; const repost = entry.repostedBy ? `<div class="repost" data-post-repost="">&#x21bb; ${esc(str(entry.repostedBy.author) || `@${entry.repostedBy.handle}`)} reposted</div>` @@ -788,6 +812,7 @@ b, .name, .mark { font-family: 'PostSansBold', sans-serif; font-weight: 400; } .pbody { min-width: 0; flex: 1; } .phead { display: flex; align-items: baseline; gap: ${Math.round(10 * k)}px; } .pdate { color: ${pal.muted}; font-size: ${Math.round(18 * k)}px; } +.plabel { margin-left: auto; align-self: center; flex: none; color: ${pal.muted}; font-size: ${Math.round(15 * k)}px; letter-spacing: 0.06em; text-transform: uppercase; border: 1px solid ${line}; border-radius: ${Math.round(6 * k)}px; padding: ${Math.round(1 * k)}px ${Math.round(7 * k)}px; } .ptext, .qtext { font-size: ${Math.round(22 * k)}px; line-height: 1.3; color: ${mixHex(pal.fg, pal.bg, 0.15)}; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; overflow-wrap: anywhere; } .qtext { -webkit-line-clamp: 5; margin-top: ${Math.round(8 * k)}px; } .quoted { border: 1px solid ${line}; border-radius: ${Math.round(14 * k)}px; padding: ${Math.round(16 * k)}px; } diff --git a/umtool/report-to-video/post-item.test.mjs b/umtool/report-to-video/post-item.test.mjs @@ -3,7 +3,7 @@ import assert from "node:assert/strict"; import { test } from "node:test"; import { - POST_GIF, POST_IMAGE_SECONDS, POST_PICTURE_MIN, POST_READ, authorRedaction, cardAuthors, cardText, mediaSeconds, mediaTimeAt, postCardHtml, + POST_GIF, POST_IMAGE_SECONDS, POST_PARAPHRASE_MAX, POST_PICTURE_MIN, POST_READ, authorRedaction, contextReadSeconds, contextText, cardAuthors, cardText, mediaSeconds, mediaTimeAt, postCardHtml, postDeckText, postItemPlan, postItemSeconds, postLayout, readingSeconds, ruleSeconds, stepAt, stepBoxes, validatePostItem, wordCount, } from "./post-item.mjs"; import { deckText, estimatedDuration, deckQrUrl, resolveDeck, validateDeckMarkers } from "./deck.mjs"; @@ -142,3 +142,42 @@ test("the deck: a post item's date is its title, its author and platform the sub const m = { render: { chrome: { engine: "hyperframes", layout: "deck", deck: { markers: [{ after: "p1", label: "Then" }] } } }, timeline: [base(), { ...base(), id: "p2" }] }; assert.deepEqual(validateDeckMarkers(m), []); }); + +test("a context post's PARAPHRASE: validated, drawn in place of its words with a label, its words counted for the read", () => { + const long = "So I thought I was done on this topic but I spent all morning watching three videos sent to me and here is my long review of all of them in detail"; + const quoted = { author: "Someone Else", handle: "someone_else", badge: "gold", date: "2026-11-02T16:21:59.000Z", text: long }; + const parent = { author: "A Parent", handle: "a_parent", badge: "gold", date: "2026-11-02T15:00:00.000Z", text: "the original parent words, quite a few of them here" }; + // Validation: a string, at most POST_PARAPHRASE_MAX characters; absent or empty is the original. + assert.deepEqual(validatePostItem(base({ quoted: { ...quoted, paraphrase: "He reviewed three videos." }, parents: [{ ...parent, paraphrase: "A question." }] })), []); + assert.match(validatePostItem(base({ quoted: { ...quoted, paraphrase: 3 } })).join(" "), /quoted\.paraphrase must be a string/); + assert.match(validatePostItem(base({ quoted: { ...quoted, paraphrase: "x".repeat(POST_PARAPHRASE_MAX + 1) } })).join(" "), /quoted\.paraphrase is longer than 600/); + assert.match(validatePostItem(base({ parents: [{ ...parent, paraphrase: "y".repeat(601) }] })).join(" "), /parents\[0\]\.paraphrase is longer than 600/); + assert.deepEqual(validatePostItem(base({ quoted: { ...quoted, paraphrase: "x".repeat(POST_PARAPHRASE_MAX) } })), []); + // contextText: the paraphrase, trimmed; blank or absent is the original. + assert.equal(contextText({ ...quoted, paraphrase: " He reviewed three videos. " }), "He reviewed three videos."); + assert.equal(contextText({ ...quoted, paraphrase: " " }), long); + assert.equal(contextText(quoted), long); + // The reading-time rule counts the paraphrase's words for that context. + const short = { ...quoted, paraphrase: "He reviewed three videos." }; // 4 words: 1.33 s + assert.equal(contextReadSeconds(quoted), 4); // 31 words: capped at 4 s + assert.equal(Math.round(contextReadSeconds(short) * 1000) / 1000, 1.333); + assert.equal(readingSeconds(base({ quoted: short })), Math.round((3 + 4 / 3) * 1000) / 1000); // its own read: 1 + 6 words / 3 + assert.ok(readingSeconds(base({ quoted: short })) < readingSeconds(base({ quoted }))); + // The card: the paraphrase and the label, never the original words. + const html = postCardHtml(base({ quoted: short, parents: [{ ...parent, paraphrase: "A parent asked a question." }] }), { width: 1920, height: 1080 }); + assert.ok(html.includes("He reviewed three videos.")); + assert.ok(html.includes("A parent asked a question.")); + assert.ok(!html.includes("spent all morning"), "the quoted post's original words are not on the card"); + assert.ok(!html.includes("the original parent words"), "the parent's original words are not on the card"); + assert.equal(html.match(/data-post-paraphrased=""[^>]*>paraphrased</g)?.length, 2); + assert.equal(html.match(/data-post-paraphrase=""/g)?.length, 2); + // Unparaphrased: the original, and no label. + const plain = postCardHtml(base({ quoted }), { width: 1920, height: 1080 }); + assert.ok(plain.includes("spent all morning")); + assert.ok(!plain.includes("data-post-paraphrased")); + // The author stays under the blur rule: a private quoted author is blurred over a paraphrase too. + const priv = postCardHtml(base({ quoted: { ...short, badge: "blue", handle: "private_person" } }), { width: 1920, height: 1080 }); + assert.ok(priv.includes('data-post-quoted="" data-redacted=""')); + assert.ok(!priv.includes("private_person")); + assert.ok(priv.includes("He reviewed three videos.")); +});