commit 31a120a06d1cf80c63aa7237371747cdfa99a235
parent ada9255062c8aa5efe7b6d59ed57cf840d4a9ca3
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 12 Nov 2026 18:09:17 -0500
umtool screens, review 1: nothing drawn or said that the operator did not choose -- stale reads, masks, excerpts refused
Must-fixes (each pinned by a test made failing first: post-screens-review.test.mjs,
lib/report/postScreens.test.mjs):
1 A line edited, removed or moved under a read is refused (post-thread.mjs
screenLineChanged: each part stores the line it was made from, `parts[k].line`); the
bench's x and line.<n>=off remap the read by one rule (post-screens.mjs withoutLines);
a read whose screens changed while it was made is not kept (postThreadRead.mjs
threadTake); line takes are re-attached only while their line is the same.
2 A screen's title, a line's time and its speaker are masked on the card; the lint names them.
3 One lineOfText (post-screens.mjs) for the CLI and the bench: a shape is never split
into a speaker ("Order number: 4419").
4 The shapes: phone-style runs of 9+ digits (any separator, fullwidth digits), local
numbers, spaced SSNs, "is"/"ending in" after a keyword, card/code/iban keywords,
non-ASCII and spelt-out e-mails; dates, decimals and amounts stay (should-fix e).
5 The redaction and anonymity passes rewrite excerpts as they rewrite lines; an excerpt
no longer in its line is never drawn whole (screenDrawErrors; the segment refused).
6 A --line-take whose take does not say its line is refused; its part's words are the
take's own.
Should-fixes: posts screen read keeps the playing read's options (screenReadOptions); a
post screenshot's author from a drawn line; the anonymity lint reads speakers, times and
titles; messages name lines, never values; per-screen memo (p8: plan 2.7 s -> 0.2 s);
the attachment guard only for items with screens; the CLI writes with the token it read;
attach: after is linted.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
15 files changed, 708 insertions(+), 167 deletions(-)
diff --git a/umtool/components/projects/PostScreensPanel.tsx b/umtool/components/projects/PostScreensPanel.tsx
@@ -1,9 +1,9 @@
"use client";
import { useMemo, useRef, useState } from "react";
-import { SCREEN_KINDS, screenReadLines, screenWarnings, shapeSpans, validateScreens } from "umtool-report-to-video/post-screens";
+import { SCREEN_KINDS, lineOfText, screenReadLines, screenWarnings, shapeSpans, validateScreens, withoutLines } from "umtool-report-to-video/post-screens";
import { isNarrated, pickedTake } from "umtool-report-to-video/post-narration";
-import { partRoles } from "umtool-report-to-video/post-thread";
+import { partRoles, threadReadErrors } from "umtool-report-to-video/post-thread";
import { postFileUrl } from "./review/PostItemPlayer";
// ---------------------------------------------------------------------------
@@ -24,35 +24,6 @@ type Entry = Record<string, unknown> & { id: string; media?: Media[]; screens?:
const r2 = (v: number) => Math.round(v * 100) / 100;
-/** One pasted line: `[right] who: words | time`, `- words`, `[redact] …` (postScreensCli.mjs lineOfText's rule). */
-function lineOfText(raw: string): Line | null {
- let t = raw.trim();
- if (!t) return null;
- const out: Line = { text: "" };
- for (;;) {
- const m = /^\[(left|right|redact)\]\s*/i.exec(t);
- if (!m) break;
- if (m[1].toLowerCase() === "redact") out.redact = true;
- else out.side = m[1].toLowerCase() as "left" | "right";
- t = t.slice(m[0].length);
- }
- const bar = t.lastIndexOf(" | ");
- if (bar > 0) {
- out.time = t.slice(bar + 3).trim();
- t = t.slice(0, bar).trim();
- }
- if (t.startsWith("- ")) t = t.slice(2);
- else {
- const c = /^([^:]{1,64}?):\s+(.*)$/s.exec(t);
- if (c && !/^https?$/i.test(c[1])) {
- out.who = c[1].trim();
- t = c[2];
- }
- }
- out.text = t.trim();
- return out;
-}
-
/** The read as a list of `{ line, text? }` (all: every line not redacted; none: none). */
const readList = (sc: Screen): Array<{ line: number; text?: string }> => (sc.read === "all" ? sc.lines.map((l, i) => (l.redact ? null : { line: i })).filter((x): x is { line: number } => !!x) : sc.read === "none" ? [] : sc.read);
@@ -60,6 +31,9 @@ export default function PostScreensPanel({ project, entry, setEntry }: { project
const screens = useMemo(() => (Array.isArray(entry.screens) ? entry.screens : []), [entry.screens]);
const media = Array.isArray(entry.media) ? entry.media : [];
const errors = useMemo(() => validateScreens(entry) as string[], [entry]);
+ // The build's guard on the read as it is (post-thread.mjs): a line edited, removed or moved under a read is refused
+ // until the read is made again -- Save keeps the screens; the build will not play the old read.
+ const refused = useMemo(() => (isNarrated(entry) ? (threadReadErrors(entry, {}) as string[]).filter((x) => /screen [a-z0-9-]+/.test(x)) : []), [entry]);
const warnings = useMemo(() => screenWarnings(entry, { narrated: isNarrated(entry), takeRoles: pickedTake(entry) ? (partRoles(entry) as Array<{ role: string | null }>).map((r) => r.role) : [] }) as string[], [entry]);
const [paste, setPaste] = useState<Record<string, string>>({});
const setScreens = (f: (list: Screen[]) => Screen[]) =>
@@ -121,6 +95,13 @@ export default function PostScreensPanel({ project, entry, setEntry }: { project
))}
</ul>
)}
+ {refused.length > 0 && (
+ <ul className="m-0 mt-1 list-disc pl-4 text-[var(--color-bad,#e5484d)]" data-post-screens-refused="">
+ {refused.map((er, i) => (
+ <li key={i}>{er}</li>
+ ))}
+ </ul>
+ )}
{warnings.length > 0 && (
<ul className="m-0 mt-1 list-disc pl-4 text-text-2" data-post-screens-warnings="">
{warnings.map((w, i) => (
@@ -295,7 +276,7 @@ function ScreenEditor({
</td>
<td>
<input type="checkbox" checked={!!l.redact} onChange={(e) => setLine(n, { redact: e.target.checked ? true : undefined })} data-post-screen-redact={n} aria-label={`redact line ${n}`} />
- <button type="button" className="ink-link ml-1" onClick={() => setLines((lines) => lines.filter((_, i) => i !== n))} title="remove the line" data-post-screen-line-remove={n}>
+ <button type="button" className="ink-link ml-1" onClick={() => setScreen((s) => { const { checked: _c, ...rest } = withoutLines(s, [n]) as Screen; void _c; return rest; })} title="remove the line (the read follows it)" data-post-screen-line-remove={n}>
×
</button>
</td>
@@ -318,7 +299,7 @@ function ScreenEditor({
className="ink-link"
disabled={!paste.trim()}
onClick={() => {
- const lines = paste.split(/\r?\n/).map(lineOfText).filter((x): x is Line => !!x);
+ const lines = paste.split(/\r?\n/).map((x) => lineOfText(x) as Line | null).filter((x): x is Line => !!x);
setLines((old) => [...old, ...lines]);
setPaste("");
}}
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -1839,9 +1839,11 @@ lint says so. Nothing in a screen is drawn that is not read, unless `unread: "di
| `checked: { by, at }` -- the transcription read against the screenshot (a screen not checked is a lint WARNING; new words take it away) | **checked** | `… check s1 [--by <name>]` · `--undo` | same |
| THE READ -- her words, then each read line in its speaker's voice; her own line from the take that plays (never made again); a line from an existing take | the command shown under the screens | `umtool posts screen <p> <item> read [--post-take n] [--line-take screen:s1:3=4]… [--dry-run]` (= `posts narrate <p> <item> --take --thread`, `--no-screens` leaves them out) | — |
-What is never drawn nor said, marked or not: an e-mail address, a phone number, an order / confirmation / invoice /
-tracking number, a "#1234", a run of six digits or more that is not an amount -- a bar on the card; the lint names the
-line (`line.<n>.redact=on` takes the whole line out). A speaker who is not the post's author is drawn under the item's
+What is never drawn nor said, marked or not -- in a line, a speaker, a time or a title: an e-mail address, a phone-style
+run of nine digits or more or a local number, an order / confirmation / tracking / account / card / code value, a
+"#1234", a token of six digits or more -- never an amount, a decimal, a date or a time -- a bar on the card; the lint
+names the line (`line.<n>.redact=on` takes the whole line out). A line edited, removed or moved under a read refuses the
+read until it is made again (`posts screen … read`, which keeps the playing read's options). A speaker who is not the post's author is drawn under the item's
privacy rule (named when a subject, or with the item's `redact: false`; else blurred -- the lint says so); an anonymous
character under its shown name (a `who` written as an anonymous author's display name is refused: write the handle).
diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md
@@ -1442,17 +1442,27 @@ as a real capture, even panned. A DM is bubbles (hers right in the accent, the o
use, the time small); an email or text a quiet letter block (a From line when the speaker changes); a post a post tile.
The page's own fonts and palette; lines at 30 px of a 1080 frame.
-**What is never drawn or said.** A line marked `redact: true`; and, marked or not, an e-mail address, a phone number,
-an order / confirmation / invoice / tracking number or "#1234", a run of six digits or more that is not an amount
-(`shapeSpans`: amounts, times and small numbers stay) -- masked with the redaction's bar, dropped from the read; the
-lint names the line. The project's redaction terms and slur filter mark a screen's words and speakers as a post's.
+**What is never drawn or said.** A line marked `redact: true`; and, marked or not, in a line's words, its speaker, its
+time and the screen's title: an e-mail address (any script, or spelt out "x at y dot com"), a phone-style run of nine
+digits or more (a card, a phone, a spaced SSN; dashes, dots, middle dots, slashes, fullwidth digits) or a local number
+(555 1234), the value after order / confirmation / tracking / reference / account / card / code ("is", ":", "#",
+"ending in" between) or a "#1234", a token of six digits or more -- never an amount ($104.90, 1,000,000), a decimal, a
+date (11/02/2026, 2026-11-02) or a time (`shapeSpans`) -- masked with the redaction's bar, dropped from the read; the
+lint names the line (never the value). A pasted `who: words` never splits a shape into a speaker ("Order number: 4419"
+stays one line). The project's redaction terms and slur filter mark a screen's words and speakers as a post's.
A speaker who is not the post's author is named when the item names them a subject or says `redact: false`, else
blurred (the lint says so); an anonymous one is drawn under the shown name and the words' @handles anonymised
(post-anon.mjs); a `who` written as an anonymous author's display name is an ERROR.
**The guard and the lint.** A part that reads a line the screen does not read (left out, redacted, `read: "none"`) or a
screen the item does not carry is REFUSED by the build (`threadReadErrors`), with the fix -- the writer lets the screen
-change first (the read is re-made from it). WARNINGS: a transcription not checked; a masked shape; read lines the picked
+change first (the read is re-made from it). So is a part whose line CHANGED since the read (`screenLineChanged`: each
+part stores the line it was made from, `parts[k].line`; edited, removed or moved, the old audio never plays under new
+lit text); a read whose screens changed while it was being made is not kept; a `--line-take` whose take does not say
+its line is refused (the part's words are the take's own, so every check reads what the audio says), and is re-attached
+on the next read only while its line says the same. An excerpt no longer in its line as drawn (after the redaction and
+anonymity passes, which rewrite excerpts as they rewrite lines) is never drawn whole: the line is left out and the
+segment refused (`screenDrawErrors`). WARNINGS: a transcription not checked; a masked shape; read lines the picked
take does not read ("make the read"); screens on an item not narrated (not drawn: a screen is drawn and read with the
item's read); a speaker blurred by the privacy rule; a screenshot of a post naming an archived one.
diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs
@@ -3101,7 +3101,9 @@ export async function updatePostItem(dir, id, patch, { token = null } = {}) {
}
// NEVER NARRATE HIDDEN TEXT (post-thread.mjs): a change to what the card shows that leaves a part of its read
// off the screen is refused, with the fix (one it had before is the guard's, not this write's).
- if ("thread" in patch || "follow" in patch || "parents" in patch || "links" in patch || "linksAdd" in patch || "screens" in patch || (isObj(patch.media) && Object.values(patch.media).includes(null)) || "mediaHide" in patch) {
+ // An attachment removed or hidden matters to the guard only for an item with SCREENS (it moves their indices).
+ const screensMoved = (Array.isArray(was.screens) && was.screens.length > 0) && ((isObj(patch.media) && Object.values(patch.media).includes(null)) || "mediaHide" in patch);
+ if ("thread" in patch || "follow" in patch || "parents" in patch || "links" in patch || "linksAdd" in patch || "screens" in patch || screensMoved) {
// With the item before it and the scene its run leaves on screen (post-conversation.mjs; a fresh list, so never
// a context worked out before this write).
const ctx = planContext(m.timeline.slice(), i, m.render);
diff --git a/umtool/lib/report/postScreens.test.mjs b/umtool/lib/report/postScreens.test.mjs
@@ -11,7 +11,8 @@ import { after, test } from "node:test";
import { encodeWav16 } from "yt-dlp-transcript-common/lib/montage/voiceMatch.mjs";
import { VOICE_A, VOICE_B, syntheticVoice, withSilence } from "yt-dlp-transcript-common/testing/audio/syntheticVoice.mjs";
import { postsCommand } from "./postsCli.mjs";
-import { applyPairs, defaultPostTake, lineOfText, linesOfText } from "./postScreensCli.mjs";
+import { applyPairs, defaultLineTakes, defaultPostTake, lineOfText, linesOfText, screenReadOptions } from "./postScreensCli.mjs";
+import { withoutLines } from "umtool-report-to-video/post-screens";
import { characterNames, joinTimes, readParts, threadReadPlan, threadTake } from "./postThreadRead.mjs";
import { threadArgsOf } from "./postSay.mjs";
import { threadArgvOf } from "./castProject.mjs";
@@ -157,7 +158,7 @@ test("the read made: her line from the take that plays (not made again), a line
const take = r.take;
assert.deepEqual(take.parts.map((x) => [x.role, x.take ?? null]), [["post", "take-1.recorded"], ["screen:s1:0", null], ["screen:s1:1", null], ["screen:s1:2", "take-2.recorded-tq"]]);
assert.equal(take.parts[3].text, "You can't be this dumb");
- assert.deepEqual(take.read.lineTakes, { "screen:s1:2": { n: 2, file: T2.file } });
+ assert.deepEqual(take.read.lineTakes, { "screen:s1:2": { n: 2, file: T2.file, line: "You can't be this dumb" } });
assert.equal(take.read.postTake.file, T1.file);
const after1 = (await read(p)).timeline[0];
assert.deepEqual(threadReadErrors(after1, {}), []);
@@ -181,3 +182,79 @@ test("the CLI's read: `posts screen <p> <item> read --dry-run` lists the pieces,
assert.deepEqual(j.pieces.map((x) => [x.role, x.take?.n ?? null]), [["post", 1], ["screen:s1:0", null]]);
assert.equal(j.pieces[1].voice, "am_michael");
});
+
+// ---------------------------------------------------------------------------
+// REVIEW 1 (12 Nov): the read's side of the must-fixes.
+// ---------------------------------------------------------------------------
+
+const DM = (lines, read = "all") => ({ id: "s1", media: 0, at: [3.5, 8], kind: "dm", read, lines });
+
+test("MUST 6: a --line-take whose take says something else than the line is REFUSED; one that says it records what the TAKE says", async () => {
+ const item = { ...ITEM, screens: [DM([{ who: "TheQuartering", text: "You can't be this dumb" }, { who: "TheQuartering", text: "something else said here" }])] };
+ const p = await project("m6", item);
+ const e = (await read(p)).timeline[0];
+ // Take 1 is the post's own read: not this line's words.
+ await assert.rejects(() => threadTake(p, e, { red: NO_RED, ask: stubAsk([]), lanes: null, lineTakes: { "screen:s1:0": 1 } }), /--line-take screen:s1:0=1: its take does not say line 0 of screen s1/);
+ // Take 2 says it (its script): the part's text is the TAKE's words, the line it stands for stored beside them.
+ const r = await threadTake(p, e, { red: NO_RED, ask: stubAsk([]), lanes: null, postTake: 1, lineTakes: { "screen:s1:0": 2 } });
+ const part = r.take.parts.find((x) => x.role === "screen:s1:0");
+ assert.equal(part.text, T2.script);
+ assert.equal(part.line, "You can't be this dumb");
+ assert.equal(r.take.read.lineTakes["screen:s1:0"].line, "You can't be this dumb");
+});
+
+test("MUST 1: each part of a screens read stores the line it was made from; the guard holds it to the line as it is now", async () => {
+ const item = { ...ITEM, screens: [DM([{ who: "TheQuartering", text: "hop on the scale fatso" }, { who: "MadamSavvy", text: "you first" }])] };
+ const p = await project("m1", item);
+ const r = await threadTake(p, (await read(p)).timeline[0], { red: NO_RED, ask: stubAsk([]), lanes: null, postTake: 1 });
+ assert.deepEqual(r.take.parts.filter((x) => x.role.startsWith("screen:")).map((x) => x.line), ["hop on the scale fatso", "you first"]);
+ const now = (await read(p)).timeline[0];
+ assert.deepEqual(threadReadErrors(now, {}), []);
+ const edited = structuredClone(now);
+ edited.screens[0].lines[1].text = "you first, big boy";
+ assert.ok(threadReadErrors(edited, {}).some((x) => /line 1 of screen s1 changed since the read/.test(x)));
+ // The line takes the read used are re-attached only while their line is the same.
+ const withLt = structuredClone(now);
+ withLt.narration.takes[withLt.narration.pick].read.lineTakes = { "screen:s1:1": { n: 2, file: T2.file, line: "you first" } };
+ assert.deepEqual(defaultLineTakes(withLt), { "screen:s1:1": 2 });
+ withLt.screens[0].lines[1].text = "you first, big boy";
+ assert.deepEqual(defaultLineTakes(withLt), {});
+});
+
+test("MUST 1 (race): the screens changed while the read was being made: it is not kept (run it again; its parts are cached)", async () => {
+ const item = { ...ITEM, screens: [DM([{ who: "TheQuartering", text: "hop on the scale fatso" }])] };
+ const p = await project("race", item);
+ const e = (await read(p)).timeline[0];
+ const ask = async (body) => {
+ // A bench edit lands while the tts is busy.
+ const m = await read(p);
+ m.timeline[0].screens[0].lines[0].text = "hop on the scale, fatso, now";
+ await writeFile(path.join(p.dir, "video.manifest.json"), JSON.stringify(m, null, 2));
+ return stubAsk([])(body);
+ };
+ await assert.rejects(() => threadTake(p, e, { red: NO_RED, ask, lanes: null, postTake: 1 }), /changed while its read was made/);
+ assert.equal((await read(p)).timeline[0].narration.takes.length, 2, "nothing kept");
+});
+
+test("SHOULD a: `posts screen … read` keeps the playing thread read's options (parents, skips, voices, quoted)", async () => {
+ const t = { ...T1, file: "narration/posts/2117/take-3.kokoro-thread.wav", read: { kind: "thread", parents: "all", skip: ["9"], quoted: false, linked: false, seen: true, voiceFor: { someone: "kokoro:bf_emma" }, voice: "af_bella", speed: 1.1 } };
+ const e = { ...ITEM, narration: { ...ITEM.narration, takes: [T1, T2, t], pick: 2 } };
+ assert.deepEqual(screenReadOptions(e, { flags: new Map(), flag: () => null, multi: () => [] }), { parents: "all", skip: ["9"], quoted: false, linked: false, readSeen: true, overrides: { someone: "kokoro:bf_emma" }, voice: "af_bella", speed: 1.1 });
+ // A flag given wins.
+ const o = screenReadOptions(e, { flags: new Map([["--no-quoted", true]]), flag: (n) => (n === "--parents" ? "0" : null), multi: (n) => (n === "--voice-for" ? ["someone=kokoro:am_adam"] : []) });
+ assert.equal(o.parents, "0");
+ assert.deepEqual(o.overrides, { someone: "kokoro:am_adam" });
+});
+
+test("bench and CLI: removing a line remaps the read (one rule: withoutLines)", () => {
+ const sc = DM([{ text: "a" }, { text: "b" }, { text: "c" }, { text: "d" }], [{ line: 0 }, { line: 2 }, { line: 3, text: "d" }]);
+ assert.deepEqual(withoutLines(sc, [0]).read, [{ line: 1 }, { line: 2, text: "d" }]);
+ assert.deepEqual(withoutLines(sc, [0]).lines.map((l) => l.text), ["b", "c", "d"]);
+ assert.deepEqual(withoutLines({ ...sc, read: "all" }, [1]).read, "all");
+});
+
+test("SHOULD g: an item WITHOUT screens: removing or hiding an attachment is not held to the thread-read guard (as before)", async () => {
+ const p = await project("g", { ...ITEM, narration: { ...ITEM.narration, takes: [{ ...T1, parts: [{ n: 1, para: 0, text: "words no card holds at all", start: 0, seconds: 1, role: "quoted" }] }], pick: 0 } });
+ await updatePostItem(p.dir, "p-2117", { media: { 1: null } });
+ assert.equal((await read(p)).timeline[0].media.length, 1);
+});
diff --git a/umtool/lib/report/postScreensCli.mjs b/umtool/lib/report/postScreensCli.mjs
@@ -22,10 +22,12 @@
// Plain ESM: the CLI runs it under bare node.
import { readFile } from "node:fs/promises";
import path from "node:path";
+import { draftScript } from "umtool-report-to-video/post-narration";
+import { voiceOverridesOf } from "umtool-report-to-video/post-say";
import { readManifest } from "../projects/report.mjs";
import { withEditNotes } from "./edit-guard.mjs";
import { manifestToken, updatePostItem } from "./manifest.mjs";
-import { SCREEN_KINDS, SCREEN_SIDES, SCREEN_UNREAD, screenReadLines, screenRows, screenWarnings, screensOf, validateScreens } from "umtool-report-to-video/post-screens";
+import { SCREEN_KINDS, SCREEN_SIDES, SCREEN_UNREAD, lineOfText, screenLineSaid, screenReadLines, withoutLines, screenRows, screenWarnings, screensOf, validateScreens } from "umtool-report-to-video/post-screens";
export const SCREEN_USAGE = [
"usage: umtool posts screen <project> <item> list [--json]",
@@ -63,35 +65,8 @@ const fail = (m) => {
throw new ScreenUsageError(m);
};
-/** One line of TEXT as a screen line: `[right] who: words | time`, `- words`, `[redact] …`. Null: a blank line. */
-export function lineOfText(raw) {
- let t = String(raw).trim();
- if (!t) return null;
- const out = {};
- for (;;) {
- const m = /^\[(left|right|redact)\]\s*/i.exec(t);
- if (!m) break;
- if (m[1].toLowerCase() === "redact") out.redact = true;
- else out.side = m[1].toLowerCase();
- t = t.slice(m[0].length);
- }
- const bar = t.lastIndexOf(" | ");
- if (bar > 0) {
- out.time = t.slice(bar + 3).trim();
- t = t.slice(0, bar).trim();
- }
- if (t.startsWith("- ")) t = t.slice(2);
- else {
- const c = /^([^:]{1,64}?):\s+(.*)$/s.exec(t);
- if (c && !/^https?$/i.test(c[1])) {
- out.who = c[1].trim();
- t = c[2];
- }
- }
- return { ...(out.who ? { who: out.who } : {}), ...(out.side ? { side: out.side } : {}), text: t.trim(), ...(out.time ? { time: out.time } : {}), ...(out.redact ? { redact: true } : {}) };
-}
-
/** Lines of TEXT as screen lines. */
+export { lineOfText };
export const linesOfText = (text) => String(text).split(/\r?\n/).map(lineOfText).filter(Boolean);
/** What `--from <file>` holds: `{ screen?: {…}, lines?: […] }` (JSON: a screen, { lines }, or a list of lines; else text lines). */
@@ -195,14 +170,8 @@ export function applyPairs(screen, pairs) {
else l[f] = v;
} else fail(`${key} is not a screen's knob (posts screen --help)`);
}
- if (drops.length) {
- // Lines removed: the read's line numbers follow them (a dropped line's read goes too).
- const gone = new Set(drops);
- const to = (n) => n - drops.filter((d) => d < n).length;
- if (Array.isArray(sc.read)) sc.read = sc.read.filter((x) => !gone.has(x?.line)).map((x) => ({ ...x, line: to(x.line) }));
- sc.lines = sc.lines.filter((_, n) => !gone.has(n));
- }
- return sc;
+ // Lines removed: the read's line numbers follow them (a dropped line's read goes too) -- the bench's rule too.
+ return drops.length ? withoutLines(sc, drops) : sc;
}
/** The next free screen id of an item: s1, s2, … */
@@ -235,6 +204,8 @@ export async function screenCommand(project, rest, { flags, str: flag, multi, js
out(SCREEN_USAGE);
return 2;
}
+ // The token of the manifest as READ here: a write after someone else's is refused (StaleToken), never laid over it.
+ const token0 = await manifestToken(project.dir);
const manifest = await readManifest(project.dir);
if (!manifest) throw new ScreenUsageError(`${project.id} has no manifest`);
const tl = Array.isArray(manifest.timeline) ? manifest.timeline : [];
@@ -242,7 +213,7 @@ export async function screenCommand(project, rest, { flags, str: flag, multi, js
if (!e) throw new ScreenUsageError(`no post item ${ref} in ${project.id} (its id, or the post's id)`);
const screens = screensOf(e);
const write = async (next, what) => {
- const { result, editNotes } = await withEditNotes(project, async () => updatePostItem(project.dir, e.id, { screens: next.length ? next : null }, { token: await manifestToken(project.dir) }));
+ const { result, editNotes } = await withEditNotes(project, async () => updatePostItem(project.dir, e.id, { screens: next.length ? next : null }, { token: token0 }));
const entry = result.entry;
const { pickedTake, isNarrated } = await import("umtool-report-to-video/post-narration");
const { partRoles } = await import("umtool-report-to-video/post-thread");
@@ -339,12 +310,10 @@ export async function screenCommand(project, rest, { flags, str: flag, multi, js
if (!screens.length) fail(`${e.id} has no screens to read (add one first)`);
const { threadCommand, parentsSelector } = await import("./postThreadRead.mjs");
const { lineTakesOf } = await import("./postNarrationCli.mjs");
- const { voiceOverridesOf } = await import("umtool-report-to-video/post-say");
const postTake = flag("--post-take") ?? defaultPostTake(e);
+ const o = screenReadOptions(e, { flags, flag, multi });
return threadCommand(project, e, {
- manifest, json, out, overrides: voiceOverridesOf(multi("--voice-for")), parents: parentsSelector(flag("--parents")),
- skip: multi("--skip-parent"), quoted: !flags.has("--no-quoted"), linked: !flags.has("--no-linked"), readSeen: flags.has("--read-seen"),
- voice: flag("--voice"), engine: flag("--engine"), note: flag("--note"), force: flags.has("--force"), hold: !flags.has("--no-hold"), dryRun,
+ manifest, json, out, ...o, parents: parentsSelector(o.parents), engine: flag("--engine"), note: flag("--note"), force: flags.has("--force"), hold: !flags.has("--no-hold"), dryRun,
postTake, lineTakes: { ...defaultLineTakes(e), ...lineTakesOf(multi("--line-take")) },
});
}
@@ -370,7 +339,11 @@ export function defaultPostTake(e) {
return at >= 0 ? at + 1 : null;
}
-/** The lines the playing thread read took from takes (`read.lineTakes`), found again by their files: `{ <role>: n }`. */
+/**
+ * The lines the playing thread read took from takes (`read.lineTakes`), found again by their files -- each ONLY while
+ * its line still says what it said then (`line`, stored with it): a line edited, removed or moved is read afresh, never
+ * with the old recording. `{ <role>: n }`.
+ */
export function defaultLineTakes(e) {
const takes = Array.isArray(e?.narration?.takes) ? e.narration.takes : [];
const k = Number.isInteger(e?.narration?.pick) ? e.narration.pick : 0;
@@ -379,7 +352,38 @@ export function defaultLineTakes(e) {
const out = {};
for (const [role, x] of Object.entries(lt)) {
const at = takes.findIndex((t) => str(t?.file) === str(x?.file));
- if (at >= 0) out[role] = at + 1;
+ const m = /^screen:([a-z0-9][a-z0-9-]{0,23}):(\d{1,2})$/.exec(role);
+ const sc = m ? screensOf(e).find((s) => s.id === m[1]) : null;
+ const now = sc ? lineWritten(screenLineSaid(sc, Number(m[2]))) : "";
+ if (at >= 0 && typeof x?.line === "string" && now && norm(x.line) === norm(now)) out[role] = at + 1;
}
return out;
}
+
+const norm = (t) => String(t ?? "").replace(/\s+/g, " ").trim();
+/** A line's words as a read writes them (post-narration.mjs draftScript). */
+const lineWritten = (t) => draftScript(String(t ?? "")).script;
+
+/**
+ * THE READ's OPTIONS for `posts screen … read`, pure: the playing thread read's own (`read`: its parents, skips,
+ * quoted / linked, seen, voices, voice, speed) -- so making the screens' read never quietly resets the read it
+ * replaces -- each flag given winning. `{ parents, skip, quoted, linked, readSeen, overrides, voice, speed }`.
+ */
+export function screenReadOptions(e, { flags, flag, multi }) {
+ const takes = Array.isArray(e?.narration?.takes) ? e.narration.takes : [];
+ const k = Number.isInteger(e?.narration?.pick) && e.narration.pick >= 0 && e.narration.pick < takes.length ? e.narration.pick : 0;
+ const r = takes[k]?.read?.kind === "thread" ? takes[k].read : {};
+ const vf = multi("--voice-for");
+ const overrides = vf.length ? voiceOverridesOf(vf) : {};
+ const skip = multi("--skip-parent");
+ return {
+ parents: flag("--parents") ?? (r.parents !== undefined ? String(r.parents) : "0"),
+ skip: skip.length ? skip : Array.isArray(r.skip) ? [...r.skip] : [],
+ quoted: flags.has("--no-quoted") ? false : r.quoted !== false,
+ linked: flags.has("--no-linked") ? false : r.linked !== false,
+ readSeen: flags.has("--read-seen") || r.seen === true,
+ overrides: vf.length ? overrides : isObj(r.voiceFor) ? { ...r.voiceFor } : {},
+ voice: flag("--voice") ?? (typeof r.voice === "string" ? r.voice : null),
+ speed: flag("--speed") !== null ? Number(flag("--speed")) : typeof r.speed === "number" ? r.speed : null,
+ };
+}
diff --git a/umtool/lib/report/postThreadRead.mjs b/umtool/lib/report/postThreadRead.mjs
@@ -230,13 +230,20 @@ export function threadReadPlan(manifest, e, { red = null, map = {}, cast = {}, i
}
const lt = lineTakes?.[p.role] ?? null;
if (lt) {
- // THE LINE FROM A TAKE (--line-take): that take's file is the line's piece -- its words the line's, as drawn.
- pieces.push({ role: p.role, handle, who: p.who, date: null, voice: takeVoiceOf(lt.take), from: "take", written, text: said.text.trim(), lexicon: [], slurs: lt.take.slurs ?? null, take: { n: lt.n, id: takeIdOf(lt.take), file: lt.take.file, ...(lt.take.engine ? { engine: lt.take.engine } : {}) } });
+ // THE LINE FROM A TAKE (--line-take): that take's file is the line's piece, and its words are what the TAKE says
+ // (`said`, else its script -- as --post-take's are), so every check that reads a read's words reads the audio's.
+ // A take that does not say the line is REFUSED, never played as it.
+ const words = norm(lt.take.said) || norm(lt.take.script);
+ if (!saysLine(words, said.text)) {
+ const sp = /^screen:([a-z0-9-]+):(\d+)$/.exec(p.role);
+ throw new ThreadReadError(`--line-take ${p.role}=${lt.n}: its take does not say line ${sp[2]} of screen ${sp[1]} (its words are another line's, or the line changed) -- record that line, or name the take that reads it`);
+ }
+ pieces.push({ role: p.role, handle, who: p.who, date: null, voice: takeVoiceOf(lt.take), from: "take", written, line: written, text: words, lexicon: [], slurs: lt.take.slurs ?? null, take: { n: lt.n, id: takeIdOf(lt.take), file: lt.take.file, ...(lt.take.engine ? { engine: lt.take.engine } : {}) } });
continue;
}
const v = resolvePieceVoice({ handle, role: sw.self ? "post" : p.role }, { map, cast, item, overrides, self: str(e.handle), voice: null, narrator, engine: eng });
const spd = readSpeedOf({ flag: speed, preset: v.speed ?? null, own: sw.self ? e.narration?.speed ?? null : null, engine: v.engine });
- pieces.push({ role: p.role, handle, who: p.who, date: null, voice: v.voice, engine: v.engine, from: v.from, ...(spd !== null ? { speed: spd } : {}), ...(v.character ? { character: v.character } : {}), written, text: said.text.trim(), lexicon: said.lexicon ?? [], slurs: said.slurs, ...(said.anonymised ? { anonymised: said.anonymised } : {}) });
+ pieces.push({ role: p.role, handle, who: p.who, date: null, line: written, voice: v.voice, engine: v.engine, from: v.from, ...(spd !== null ? { speed: spd } : {}), ...(v.character ? { character: v.character } : {}), written, text: said.text.trim(), lexicon: said.lexicon ?? [], slurs: said.slurs, ...(said.anonymised ? { anonymised: said.anonymised } : {}) });
continue;
}
const written = p.role === "post" ? own || script || "" : draftScript(p.text).script;
@@ -299,6 +306,25 @@ export function characterNames(L) {
return out;
}
+/**
+ * Whether a take's words SAY a line, pure: the line's words and the take's agree (normalized words, in either order of
+ * the two) on at least 60 % of the longer -- a take of another line, of the post, or of an older line does not.
+ */
+export function saysLine(takeWords, lineWords) {
+ const keys = (t) => str(t).toLowerCase().split(/\s+/).map((w) => w.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, "")).filter(Boolean);
+ const a = keys(takeWords);
+ const b = keys(lineWords);
+ if (!a.length || !b.length) return false;
+ const pool = new Map();
+ for (const w of a) pool.set(w, (pool.get(w) ?? 0) + 1);
+ let common = 0;
+ for (const w of b) if ((pool.get(w) ?? 0) > 0) {
+ common += 1;
+ pool.set(w, pool.get(w) - 1);
+ }
+ return common / Math.max(a.length, b.length) >= 0.6;
+}
+
/** A take's voice as a thread read's label says it: its voice (or recorded label) without an engine ("am_michael", "operator"). */
export function takeVoiceOf(t) {
const v = str(t?.voice) || str(t?.label) || (t?.engine === "recorded" ? "recorded" : "take");
@@ -323,9 +349,11 @@ export function postTakeOf(e, n) {
/** The read's PARTS, pure: each piece's parts (scriptParts) with its voice, engine, role and cache key, in order -- a take's line one part, its file. */
export function readParts(plan) {
return plan.pieces.flatMap((pc, piece) => {
- if (pc.take) return [{ piece, para: 0, role: pc.role, voice: pc.voice, text: pc.text, file: pc.take.file, take: pc.take.id, key: null }];
+ // A screen line's parts carry the line they were made from (`line`): the guard holds the read to the line as it is.
+ const line = typeof pc.line === "string" ? { line: pc.line } : {};
+ if (pc.take) return [{ piece, para: 0, role: pc.role, voice: pc.voice, text: pc.text, file: pc.take.file, take: pc.take.id, key: null, ...line }];
const eng = pc.engine ?? plan.engine;
- return scriptParts(pc.text).map((q) => ({ piece, para: q.para, role: pc.role, voice: pc.voice, engine: eng, ...(pc.speed !== undefined ? { speed: pc.speed } : {}), text: q.text, key: partKey(eng, pc.voice, q.text, pc.speed ?? null) }));
+ return scriptParts(pc.text).map((q) => ({ piece, para: q.para, role: pc.role, voice: pc.voice, engine: eng, ...(pc.speed !== undefined ? { speed: pc.speed } : {}), text: q.text, key: partKey(eng, pc.voice, q.text, pc.speed ?? null), ...line }));
});
}
@@ -347,7 +375,7 @@ export function joinTimes(parts, seconds, { fileOf = (p) => (p.take ? p.file : `
t += gap;
const s = Number(seconds[i]);
// A part from a take (--post-take) says which (`take`: its id); a synthesized one its parts-cache file and voice.
- const row = { n: i + 1, para: p.piece * 100 + p.para, text: p.text, voice: p.voice, ...(p.engine ? { engine: p.engine } : {}), ...(typeof p.speed === "number" ? { speed: p.speed } : {}), role: p.role, piece: p.piece, file: fileOf(p), ...(p.take ? { take: p.take } : {}), start: r3(t), seconds: r3(s), gapBefore: gap };
+ const row = { n: i + 1, para: p.piece * 100 + p.para, text: p.text, ...(typeof p.line === "string" ? { line: p.line } : {}), voice: p.voice, ...(p.engine ? { engine: p.engine } : {}), ...(typeof p.speed === "number" ? { speed: p.speed } : {}), role: p.role, piece: p.piece, file: fileOf(p), ...(p.take ? { take: p.take } : {}), start: r3(t), seconds: r3(s), gapBefore: gap };
t += s;
return row;
});
@@ -366,7 +394,8 @@ export function readRecordOf({ parents = "0", skip = [], quoted = true, linked =
...(postTake ? { postTake: { n: postTake.n, file: postTake.take.file } } : {}),
// Its screens (post-screens.mjs): left out; lines from takes (--line-take).
...(screens ? {} : { screens: false }),
- ...(Object.keys(lineTakes ?? {}).length ? { lineTakes: Object.fromEntries(Object.entries(lineTakes).map(([r, lt]) => [r, { n: lt.n, file: lt.take.file }])) } : {}),
+ // Each with the line it said then (`line`): it is re-attached only while the line says the same (defaultLineTakes).
+ ...(Object.keys(lineTakes ?? {}).length ? { lineTakes: Object.fromEntries(Object.entries(lineTakes).map(([r, lt]) => [r, { n: lt.n, file: lt.take.file, ...(typeof lt.line === "string" ? { line: lt.line } : {}) }])) } : {}),
};
}
@@ -431,6 +460,7 @@ export async function threadTake(project, e, opts = {}) {
// The characters' names (a screen's `who` may be one), to their handles.
const names = names0 !== undefined ? names0 : characterNames(L);
const plan = threadReadPlan(manifest, e, { red, map, cast, item, overrides, parents, skip, quoted, linked, readSeen, voice, engine, speed, postTake, screens, names, lineTakes });
+ for (const [r, lt] of Object.entries(lineTakes)) lt.line = plan.pieces.find((pc) => pc.role === r)?.line;
const parts = readParts(plan);
const cacheDir = path.join(project.dir, ...PARTS_CACHE.split("/"));
const wavOf = (p) => (p.take ? path.join(project.dir, ...p.file.split("/")) : path.join(cacheDir, `${p.key}.wav`));
@@ -544,6 +574,11 @@ export async function threadTake(project, e, opts = {}) {
read: readRecordOf({ parents, skip, quoted, linked, readSeen, overrides, voice, speed, postTake, screens, lineTakes }),
};
const patch = { addTake: take, ...(plan.script ? { script: plan.script } : {}) };
+ // THE ITEM CHANGED WHILE ITS READ WAS MADE (a bench edit during minutes of synthesis): what was read is not what it
+ // holds now -- refused, never kept as a stale read (the parts made are cached: running it again is quick).
+ const nowE = ((await readManifest(project.dir))?.timeline ?? []).find((x) => x?.id === e.id);
+ const sig = (x) => JSON.stringify([x?.screens ?? null, x?.text ?? null, x?.narration?.script ?? null]);
+ if ((Array.isArray(e.screens) || Array.isArray(nowE?.screens)) && (!nowE || sig(nowE) !== sig(e))) throw new ThreadReadError(`${e.id} changed while its read was made (its screens or its words): run it again -- the parts made are cached`);
const { result, editNotes } = await withEditNotes(project, async () => updatePostNarration(project.dir, e.id, patch, { token: await manifestToken(project.dir) }));
return { ...base, upToDate: false, fresh, jobs, lane, take, result, editNotes };
}
diff --git a/umtool/report-to-video/post-anon.mjs b/umtool/report-to-video/post-anon.mjs
@@ -324,15 +324,21 @@ export function anonymiseEntry(e0, set) {
const lines = sc.lines.map((l) => {
if (!isObj(l)) return l;
const s = typeof l.who === "string" ? of(l.who) : null;
+ // A speaker that is not the handle itself ("x.com/<handle>", "@<handle>") has its words anonymised as a post's are.
+ const who = s ?? anonymiseWords(l.who, set);
const text = anonymiseWords(l.text, set);
- if (!s && text === l.text) return l;
+ const time = anonymiseWords(l.time, set);
+ if (!s && text === l.text && who === l.who && time === l.time) return l;
mine = true;
- return { ...l, ...(s ? { who: s, anonymous: true } : {}), text };
+ return { ...l, ...(s ? { who: s, anonymous: true } : who !== undefined ? { who } : {}), text, ...(time !== undefined ? { time } : {}) };
});
const title = anonymiseWords(sc.title, set);
- if (!mine && title === sc.title) return sc;
+ // Each EXCERPT rewritten as its line is: still a run of the line's words as drawn.
+ const read = Array.isArray(sc.read) ? sc.read.map((x) => (isObj(x) && typeof x.text === "string" ? { ...x, text: anonymiseWords(x.text, set) } : x)) : sc.read;
+ const readChanged = Array.isArray(sc.read) && read.some((x, i) => x !== sc.read[i] && x.text !== sc.read[i].text);
+ if (!mine && title === sc.title && !readChanged) return sc;
changed = true;
- return { ...sc, lines, ...(title !== undefined ? { title } : {}) };
+ return { ...sc, lines, ...(title !== undefined ? { title } : {}), ...(readChanged ? { read } : {}) };
});
if (changed) edit().screens = screens;
}
@@ -519,9 +525,17 @@ export function anonymityProblems(manifest, doc, { set: given = null } = {}) {
// refused (write the handle: it is drawn under the shown name); their words are drawn as written, as a post's are.
const screens = (Array.isArray(e.screens) ? e.screens : []).filter((sc) => isObj(sc) && Array.isArray(sc.lines));
for (const sc of screens) {
- for (const l of sc.lines) {
- if (!isObj(l) || typeof l.who !== "string") continue;
- for (const [n, shown] of names) if (l.who.trim().toLowerCase() === n.toLowerCase()) errors.push(`timeline ${e.id}: screen ${str(sc.id)} names a speaker by ${shown}'s display name -- an anonymous author's: write their handle as the line's who (drawn as "${shown}")`);
+ // A SPEAKER, A TIME, THE TITLE: short fields drawn as written but for an exact handle -- any other form of an
+ // anonymous handle ("SecretKid (alt)", "x.com/secretkid", "@secretkid") or display name in one is an ERROR.
+ // A speaker that IS the handle (any case, an "@" before it) is the pass's: drawn under the shown name -- not an error.
+ const fields = [["its title", sc.title], ...sc.lines.flatMap((l, i) => (isObj(l) ? [[`line ${i}'s speaker`, l.who, l.anonymous === true || (typeof l.who === "string" && set.has(handleKey(l.who)))], [`line ${i}'s time`, l.time]] : []))];
+ for (const [where, v, flagged] of fields) {
+ if (typeof v !== "string" || !v.trim() || flagged) continue;
+ for (const [n, shown] of names) if (phraseRe(n).test(v)) errors.push(`timeline ${e.id}: screen ${str(sc.id)} ${where} writes ${shown}'s display name -- an anonymous author's: write their handle (a speaker is drawn as "${shown}") or leave it out`);
+ for (const [h, shown] of set) {
+ if (h === "postIds") continue;
+ if (phraseRe(h).test(v)) errors.push(`timeline ${e.id}: screen ${str(sc.id)} ${where} writes ${shown}'s handle -- an anonymous author's: write the handle alone as the speaker (drawn as "${shown}") or leave it out`);
+ }
}
}
const drawn = [...whoOf(e).flatMap((w) => [str(w.text), str(w.paraphrase)]), ...screens.flatMap((sc) => [str(sc.title), ...sc.lines.map((l) => str(l?.text))])].join("\n");
diff --git a/umtool/report-to-video/post-narration.mjs b/umtool/report-to-video/post-narration.mjs
@@ -202,7 +202,7 @@ const STEP_KEYS = new Set(["op", "engine", "voice", "pitch", "semitones", "param
// `tempo`: the part's reading speed in the take's file against its first read (a `tempo` step's; absent: 1).
// `speed`: the speed the part was synthesized at (its character's preset's, or the read's --speed; absent: 1).
// `take`: a thread read's part that IS one of the item's takes (postThreadRead.mjs --post-take): that take's id.
-const PART_KEYS = new Set(["n", "para", "text", "file", "start", "seconds", "gapBefore", "note", "at", "jobId", "role", "voice", "engine", "piece", "tempo", "speed", "take"]);
+const PART_KEYS = new Set(["n", "para", "text", "file", "start", "seconds", "gapBefore", "note", "at", "jobId", "role", "voice", "engine", "piece", "tempo", "speed", "take", "line"]);
const VOICE_RE = /^[A-Za-z0-9][A-Za-z0-9_.+-]{0,63}$/;
/** Orpheus's expressive tags (narration.mjs NARRATION_TAGS, the editor's list). */
const TAGS = ["laugh", "chuckle", "sigh", "cough", "sniffle", "groan", "yawn", "gasp"];
@@ -711,6 +711,7 @@ export function validatePostNarration(e) {
if (!(fin(p.start) && p.start >= 0)) errors.push(`${pw}.start must be where it starts in the take, seconds`);
if (!(fin(p.seconds) && p.seconds > 0)) errors.push(`${pw}.seconds must be its length`);
if (p.text !== undefined && typeof p.text !== "string") errors.push(`${pw}.text must be the words it reads`);
+ if (p.line !== undefined && typeof p.line !== "string") errors.push(`${pw}.line must be the screen line it was made from (its words)`);
if (p.speed !== undefined && !numIn(p.speed, POST_NARRATION_LIMITS.speed)) errors.push(`${pw}.speed must be ${POST_NARRATION_LIMITS.speed.join("–")} (the speed it was synthesized at)`);
if (p.tempo !== undefined && !numIn(p.tempo, POST_NARRATION_LIMITS.tempo)) errors.push(`${pw}.tempo must be ${POST_NARRATION_LIMITS.tempo.join("–")} (its reading speed in the take)`);
if (p.role !== undefined && !(typeof p.role === "string" && /^(post|quoted|parent:\d|media:\d|linked:\d|screen:[a-z0-9][a-z0-9-]{0,23}:\d{1,2})$/.test(p.role))) errors.push(`${pw}.role must be post, quoted, parent:<i>, linked:<i>, media:<i> or screen:<id>:<line> (the text it reads)`);
diff --git a/umtool/report-to-video/post-redact.mjs b/umtool/report-to-video/post-redact.mjs
@@ -342,10 +342,19 @@ export function slurEntry(entry, slurs) {
return out;
}
-/** A screens list (post-screens.mjs) with each line's words, its speaker and the title passed through `m` (a copy). */
+/**
+ * A screens list (post-screens.mjs) with each line's words, its speaker, its time and the title passed through `m` (a
+ * copy) -- and each EXCERPT the same way, so it is still a run of its line's words as drawn (else the card would have
+ * to draw the whole line: it draws none, and the build refuses -- screenDrawErrors).
+ */
function screensMarked(screens, m) {
return screens.map((sc) => (isObj(sc) && Array.isArray(sc.lines)
- ? { ...sc, ...("title" in sc ? { title: m(sc.title) } : {}), lines: sc.lines.map((l) => (isObj(l) ? { ...l, ...("text" in l ? { text: m(l.text) } : {}), ...("who" in l ? { who: m(l.who) } : {}) } : l)) }
+ ? {
+ ...sc,
+ ...("title" in sc ? { title: m(sc.title) } : {}),
+ lines: sc.lines.map((l) => (isObj(l) ? { ...l, ...("text" in l ? { text: m(l.text) } : {}), ...("who" in l ? { who: m(l.who) } : {}), ...("time" in l ? { time: m(l.time) } : {}) } : l)),
+ ...(Array.isArray(sc.read) ? { read: sc.read.map((x) => (isObj(x) && typeof x.text === "string" ? { ...x, text: m(x.text) } : x)) } : {}),
+ }
: sc));
}
diff --git a/umtool/report-to-video/post-render.mjs b/umtool/report-to-video/post-render.mjs
@@ -32,7 +32,7 @@ import { POST_PROGRESS_DRAW_V, measureProgressPlace, mountProgress, progressCss,
import { SLAM_BAR, SLAM_DUST, SLAM_FACE_STACK, SLAM_MOTION, mountSlams, slamBarOf, setSlamState, slamCss, slamCoverErrors, slamHits, slamLayout, slamListAt, slamPlan, slamShakeExpr, slamSize, slamVars } from "./post-slam.mjs";
import { TRAILER_AUDIO, TRAILER_HIT_TIERS, trailerHitsGraph } from "./trailer-hits.mjs";
import { panelReadErrors } from "./post-thread.mjs";
-import { POST_SCREEN_DRAW_V, hasScreens } from "./post-screens.mjs";
+import { POST_SCREEN_DRAW_V, hasScreens, screenDrawErrors } from "./post-screens.mjs";
import { applyJoinState, endMediaOf, joinClockOf } from "./post-join.mjs";
import { applyVisitState } from "./post-link-visit.mjs";
import { applyMapState, mapPageHtml, mapPlace, mapSize, mapStateAt } from "./post-branch-map.mjs";
@@ -1535,6 +1535,10 @@ export async function buildPostSegment(entry, { render, outDir, manifestDir, box
}
cardPics = { mediaUrl: (src) => pathToFileURL(path.resolve(manifestDir, src)).href, posters };
}
+ // ITS SCREENS AS DRAWN (post-screens.mjs, after the redaction and anonymity passes): an excerpt no longer in its line
+ // is never drawn whole -- the segment is refused, naming the line.
+ const screenErr = hasScreens(entry) ? screenDrawErrors(redactEntry(entry, redaction)) : [];
+ if (screenErr.length) throw new Error(`${entry.id}: a screen cannot be drawn as chosen:\n ${screenErr.join("\n ")}`);
const cards = await renderPostCards(entry, { box, render, dir: cardDir, manifestDir, layout, avatars, zooms: zoomPlan, pics: plan.pics ?? [], cardPics, redaction, follow: plan.follow ?? null, total: plan.total, joinFrom: from, captions: capPlan, clock: clk, obstacles: layout.slot ? plan.steps.flatMap((st) => stepBoxes(st, layout.slot)) : [], slams: slPlan, progress: prog });
// NO HIDDEN TEXT IS EVER NARRATED (operator, 4 Nov): a part whose words are not in view, whole and lit, while it
// is said -- or a context post drawn over its context size -- refuses the build (READ_IN_VIEW=warn: a note).
diff --git a/umtool/report-to-video/post-screens-review.test.mjs b/umtool/report-to-video/post-screens-review.test.mjs
@@ -0,0 +1,233 @@
+// lane/screen-reads REVIEW 1 (12 Nov): the reviewer's probes ($J/screen-reads/review/p1-p9) as tests, one a finding. Each
+// must-fix is a privacy leak or a wrong word in a read; the rule throughout: nothing is drawn or said that the operator
+// did not choose -- when an excerpt, a take or a line no longer matches, the build REFUSES, never falls back to more.
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { postCardHtml, postItemPlan, validatePostItem } from "./post-item.mjs";
+import { threadReadErrors, validateThreadReadWarnings } from "./post-thread.mjs";
+import { redactEntry } from "./post-redact.mjs";
+import { anonymiseEntry, anonymityProblems } from "./post-anon.mjs";
+import { REDACT_MARK } from "./post-redact.mjs";
+import {
+ lineOfText, maskShapes, screenDrawErrors, screenLineSaid, screenPieces, screenRows, screenTileHtml, screenWarnings, validateScreens,
+} from "./post-screens.mjs";
+
+const IMG = { src: "posts-media/savvy-x/2117/2117_2.jpg", kind: "image", width: 900, height: 1400 };
+const base = (screens, o = {}) => ({ type: "post", id: "p-1", post: "savvy-x/2117", platform: "x", author: "Savvy", handle: "MadamSavvy", date: "2026-11-02T01:40:36.000Z", text: "Your turn.", media: [IMG], screens, ...o });
+/** A thread read of `roles` ([id, n]…), each part saying the line as it is now (as the read would have said it). */
+function narr(e, roles) {
+ const parts = [{ n: 1, para: 0, text: "Your turn.", role: "post", start: 0, seconds: 1 }];
+ let t = 1.8;
+ roles.forEach(([id, n], i) => {
+ const sc = e.screens.find((s) => s.id === id);
+ const text = screenLineSaid(sc, n);
+ parts.push({ n: parts.length + 1, para: (i + 1) * 100, text, role: `screen:${id}:${n}`, start: t, seconds: 2 });
+ t += 2.8;
+ });
+ return { ...e, narration: { script: "Your turn.", pick: 0, takes: [{ file: "narration/posts/1/take-1.orpheus-thread.wav", engine: "orpheus", voice: "x", seconds: t, script: "x", parts }] } };
+}
+const shown = (t) => maskShapes(t).text.replace(new RegExp(REDACT_MARK, "g"), "█");
+const card = (e, o = {}) => {
+ const plan = postItemPlan(e, { postNarration: { lead: 0.4 } });
+ return postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow?.thread ?? null, ...o });
+};
+
+// ---------------------------------------------------------------------------
+// MUST 1: a stale take -- the line changed, removed or moved after the read -- is refused.
+// ---------------------------------------------------------------------------
+
+test("MUST 1 (p4): a line's words changed after the read: the guard refuses (old audio under new lit text)", () => {
+ const S = { id: "s1", media: 0, kind: "text", read: [{ line: 0, text: "Jenny said it was fine" }], lines: [{ text: "Long preamble nobody needs. Jenny said it was fine. And then a private aside about her family." }] };
+ const e = narr(base([S]), [["s1", 0]]);
+ assert.deepEqual(threadReadErrors(e, {}), []);
+ const e2 = structuredClone(e);
+ e2.screens[0].lines[0].text = "Long preamble. Jenny said it was NOT fine at all. aside";
+ e2.screens[0].read = [{ line: 0, text: "Jenny said it was NOT fine" }];
+ assert.deepEqual(validatePostItem(e2), []);
+ assert.ok(threadReadErrors(e2, {}).some((x) => /line 0 of screen s1 changed since the read/.test(x)), threadReadErrors(e2, {}).join("\n"));
+});
+
+test("MUST 1 (p6): a line removed (the bench's ×, or line.<n>=off) under a read: refused -- the take would SAY the removed line", () => {
+ const S = { id: "s1", media: 0, kind: "dm", read: [{ line: 0 }, { line: 2 }], lines: [{ who: "a", text: "my home address is 12 Elm Street Springfield" }, { who: "b", text: "ok" }, { who: "a", text: "see you there" }, { who: "b", text: "bye now" }] };
+ const e = narr(base([S]), [["s1", 0], ["s1", 2]]);
+ assert.deepEqual(threadReadErrors(e, {}), []);
+ // The probe's own case: the line filtered out, `read` left as it was -- each role now names another line.
+ const e1 = structuredClone(e);
+ e1.screens[0].lines = e1.screens[0].lines.slice(1);
+ const errs1 = threadReadErrors(e1, {});
+ assert.ok(errs1.some((x) => /line 0 of screen s1 changed since the read/.test(x)), errs1.join("\n"));
+ assert.ok(errs1.some((x) => /line 2 of screen s1 changed since the read/.test(x)), errs1.join("\n"));
+ // The read remapped as the bench's × and `line.<n>=off` now do: the roles name lines the screen no longer reads.
+ const e2 = structuredClone(e);
+ e2.screens[0].lines = e2.screens[0].lines.slice(1);
+ e2.screens[0].read = [{ line: 1 }];
+ const errs = threadReadErrors(e2, {});
+ assert.ok(errs.some((x) => /reads line 0 of screen s1, which the screen does not read/.test(x)), errs.join("\n"));
+ assert.ok(errs.some((x) => /reads line 2 of screen s1, which the screen does not read/.test(x)), errs.join("\n"));
+ // A part that stored the line it was made from is judged by it, exactly.
+ const e3 = structuredClone(e);
+ e3.narration.takes[0].parts[1].line = "my home address is 12 Elm Street";
+ assert.ok(threadReadErrors(e3, {}).some((x) => /line 0 of screen s1 changed since the read/.test(x)));
+});
+
+// ---------------------------------------------------------------------------
+// MUST 2: title, time and who are masked on the card.
+// ---------------------------------------------------------------------------
+
+test("MUST 2 (p3): an e-mail or phone number in a title, a time or a speaker never reaches the card; the lint names them", () => {
+ const S = { id: "s1", media: 0, kind: "email", title: "Email from savvy.r@gmail.com", read: "all", lines: [{ who: "savvy.r@gmail.com", text: "Hello there friend", time: "555-201-4477" }, { who: "+1 555 201 4477", text: "Card 4111 1111 1111 1111 please" }] };
+ for (const red of [undefined, false]) {
+ const e = narr(base([S], red === undefined ? {} : { redact: red }), [["s1", 0], ["s1", 1]]);
+ assert.deepEqual(validatePostItem(e), []);
+ const html = card(e);
+ for (const needle of ["savvy.r@gmail.com", "555-201-4477", "555 201 4477", "4111"]) assert.ok(!html.includes(needle), `${needle} (redact ${red})`);
+ assert.ok(!screenLineSaid(S, 1).includes("4111"));
+ }
+ const w = screenWarnings(base([S]), { narrated: false });
+ assert.ok(w.some((x) => /screen s1's title holds/.test(x)));
+ assert.ok(w.some((x) => /screen s1 line 0's time holds/.test(x)));
+ assert.ok(w.some((x) => /screen s1 line 1's speaker holds/.test(x)));
+ assert.ok(!w.some((x) => /savvy\.r|555|4111/.test(x)), "no value quoted");
+});
+
+// ---------------------------------------------------------------------------
+// MUST 3: a pasted line never splits a shape into a speaker.
+// ---------------------------------------------------------------------------
+
+test("MUST 3 (p7): `Order number: 4419`, `Ref: AB-1234`, `Tracking: 1Z999AA1`, `Order #: 48213` stay one line, masked", () => {
+ for (const raw of ["Confirmation code: 552-118", "Order #: 48213", "Order number: 4419", "Tracking: 1Z999AA1", "savvy@gmail.com: hi there", "Phone: 555 201 4477", "Ref: AB-1234"]) {
+ const l = lineOfText(raw);
+ assert.equal(l.who, undefined, `${raw}: no speaker split off`);
+ assert.equal(shown(l.text), shown(raw), `${raw}: masked as the whole line is`);
+ assert.ok(/█/.test(shown(l.text)), `${raw}: something masked`);
+ }
+ assert.deepEqual(lineOfText("TheQuartering: what's your email | 11:32 AM"), { who: "TheQuartering", text: "what's your email", time: "11:32 AM" });
+});
+
+// ---------------------------------------------------------------------------
+// MUST 4 + SHOULD e: the shapes.
+// ---------------------------------------------------------------------------
+
+test("MUST 4 (p1, p2): cards, spaced SSNs and local numbers, dash/dot separators, fullwidth digits, `is` after the keyword, non-ASCII e-mail -- all masked", () => {
+ const masked = [
+ ["card 4111 1111 1111 1111 exp 12/27", "card ████ ████ ████ ████ exp 12/27"],
+ ["Order: 1234 5678 9012 3456 7890", "Order: ████ ████ ████ ████ ████"],
+ ["call 555 – 123 – 4567", "call ███ █ ███ █ ████"],
+ ["call 555 · 123 · 4567", "call ███ █ ███ █ ████"],
+ ["call 555-123-4567", "call ████████████"],
+ ["Your order number is 48213", "Your order number is █████"],
+ ["confirmation code is 5521", "confirmation code is ████"],
+ ["ssn 123 45 6789", "ssn ███ ██ ████"],
+ ["call 555 1234", "call ███ ████"],
+ ["jöhn.doe@exämple.com", "████████████████████"],
+ ["tracking 1Z 999 AA1 01 2345 6784", "tracking ██ ███ ███ ██ ████ ████"],
+ ["Your order is 48213", "Your order is █████"],
+ ["code 12345", "code █████"],
+ ["account ending 4821", "account ending ████"],
+ ];
+ for (const [t, want] of masked) assert.equal(shown(t), want, t);
+ // Still shown: amounts, weights, years, times, DATES (should-fix e).
+ for (const t of ["Total $104.90 USD", "1,000,000 views", "$1,250.00 refund", "lost 12.5 lbs since 2024", "400 pounds", "290", "at 12:18 PM", "on 11/02/2026 at 10:42", "weighed 312.4 on 2026-11-02", "zip 90210"]) assert.equal(shown(t), t, t);
+});
+
+// ---------------------------------------------------------------------------
+// MUST 5: the redaction and anonymity passes keep excerpts -- and a broken excerpt is refused, never drawn whole.
+// ---------------------------------------------------------------------------
+
+test("MUST 5 (p4): a redaction term inside an excerpt: the card draws the excerpt (labelled), never the whole line", () => {
+ const S = { id: "s1", media: 0, kind: "text", read: [{ line: 0, text: "Jenny said it was fine" }], lines: [{ text: "Long preamble nobody needs. Jenny said it was fine. And then a private aside about her family." }] };
+ const e = narr(base([S]), [["s1", 0]]);
+ const red = { terms: ["Jenny"] };
+ const r = redactEntry(e, red);
+ const rows = screenRows(r.screens[0]);
+ assert.equal(rows.filter((x) => !x.gap).length, 1);
+ assert.ok(!rows[0].text.includes("private aside") && !rows[0].text.includes("preamble"), rows[0].text);
+ const html = card(e, { redaction: red });
+ assert.ok(!html.includes("private aside"));
+ assert.ok(html.includes("data-screen-excerpt"));
+ assert.ok(!html.includes("Jenny"));
+ assert.deepEqual(screenDrawErrors(r), []);
+});
+
+test("MUST 5 (p5): after the anonymity pass the excerpt is the excerpt (its @handle rewritten), never the whole line", () => {
+ const set = new Map([["secretkid", "Kid A"]]);
+ const S = { id: "s1", media: 0, kind: "dm", read: [{ line: 0, text: "ask @secretkid about it" }], lines: [{ who: "secretkid", text: "private stuff first. ask @secretkid about it. more private stuff" }] };
+ const a = anonymiseEntry(base([S]), set);
+ const rows = screenRows(a.screens[0]).filter((x) => !x.gap);
+ assert.equal(rows.length, 1);
+ assert.equal(rows[0].text, "ask @Kid_A about it.");
+ assert.deepEqual(screenDrawErrors(a), []);
+});
+
+test("MUST 5: an excerpt that no longer matches the line as drawn is NOT drawn whole: the line is left out and the build is told", () => {
+ const S = { id: "s1", media: 0, kind: "text", read: [{ line: 0, text: "said it was fine" }], lines: [{ text: "Preamble. He said it was fine. Private aside." }] };
+ const broken = structuredClone(S);
+ broken.lines[0].text = "Preamble. He said it was okay. Private aside.";
+ const rows = screenRows(broken);
+ assert.ok(!rows.some((r) => !r.gap && /Private aside/.test(r.text)), JSON.stringify(rows));
+ assert.equal(screenLineSaid(broken, 0), "");
+ assert.ok(screenDrawErrors(base([broken])).some((x) => /line 0 of screen s1: its excerpt is not in the line/.test(x)));
+ assert.ok(validateScreens(base([broken])).some((x) => /\.read\[0\]\.text is not a run of line 0's words/.test(x)));
+});
+
+// ---------------------------------------------------------------------------
+// SHOULD b, c, d, f.
+// ---------------------------------------------------------------------------
+
+test("SHOULD b (p9): a screenshot of a post names its author from a DRAWN line, never a redacted one", () => {
+ const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
+ const sc = { id: "s1", media: 0, kind: "post", read: [{ line: 1 }], lines: [{ who: "secret_person", text: "hidden words", redact: true }, { text: "visible words" }] };
+ const html = screenTileHtml({ author: "A", handle: "aa", media: [{ kind: "image" }], redact: false }, sc, { k: 1, size: 30, blocks: new Map(), shown: () => true, h: { esc } });
+ assert.ok(!html.includes("secret_person") && !html.includes("hidden words"));
+});
+
+test("SHOULD c (p5): the anonymity lint catches a speaker, title or time that writes an anonymous handle in any form", () => {
+ const S = { id: "s1", media: 0, kind: "dm", read: "all", title: "chat with secretkid", lines: [{ who: "SecretKid (alt)", text: "hi" }, { who: "x.com/secretkid", text: "yo", time: "@secretkid" }] };
+ const m = { timeline: [base([S])] };
+ const errs = anonymityProblems(m, {}, { set: new Map([["secretkid", "Kid A"]]) }).errors;
+ assert.ok(errs.filter((x) => /screen s1/.test(x)).length >= 3, errs.join("\n"));
+ assert.ok(!errs.some((x) => /secretkid/i.test(x)), "never the real handle");
+});
+
+test("SHOULD d: lint and validation name a line, never quote its value", () => {
+ const S = { id: "s1", media: 0, kind: "dm", read: [{ line: 0, text: "my secret words here" }], lines: [{ who: "privateperson", text: "something else entirely" }] };
+ const v = validateScreens(base([S]));
+ assert.ok(v.some((x) => /read\[0\]\.text is not a run of line 0's words/.test(x)));
+ assert.ok(!v.some((x) => /secret words/.test(x)));
+ const w = screenWarnings(base([{ ...S, read: "all" }]), { narrated: true, takeRoles: ["screen:s1:0"] });
+ assert.ok(w.some((x) => /line 0's speaker is drawn blurred/.test(x)), w.join("\n"));
+ assert.ok(!w.some((x) => /privateperson/.test(x)));
+});
+
+test("SHOULD f (p8): at the limits (8 screens × 60 long lines, each an excerpt) the plan and the card stay quick", () => {
+ const W = "the of and to in is you that it he was for on are as with his they I at be this have from or one had by word but not what all were we when your can said there use an each which she do how their if will up".split(" ");
+ const line = Array.from({ length: 110 }, (_, i) => W[(i * 7) % W.length]).join(" ").slice(0, 598);
+ const ex = line.split(" ").slice(40, 80).join(" ");
+ const mk = (id) => ({ id, media: 0, kind: "dm", read: Array.from({ length: 60 }, (_, n) => ({ line: n, text: ex })), lines: Array.from({ length: 60 }, (_, n) => ({ who: n % 2 ? "x" : "y", text: line })) });
+ const e0 = base(Array.from({ length: 8 }, (_, i) => mk(`s${i + 1}`)));
+ let t = performance.now();
+ const pcs = screenPieces(e0);
+ assert.equal(pcs.length, 480);
+ const parts = [{ n: 1, para: 0, text: "Your turn.", role: "post", start: 0, seconds: 1 }];
+ let s = 2;
+ pcs.forEach((p, i) => {
+ parts.push({ n: parts.length + 1, para: (i + 1) * 100, text: p.text, role: p.role, start: s, seconds: 1 });
+ s += 1.5;
+ });
+ const e = { ...e0, narration: { script: "Your turn.", pick: 0, takes: [{ file: "narration/posts/1/take-1.orpheus-thread.wav", engine: "orpheus", voice: "x", seconds: s, script: "x", parts }] } };
+ t = performance.now();
+ const plan = postItemPlan(e, { postNarration: { lead: 0.4 } });
+ const planMs = performance.now() - t;
+ t = performance.now();
+ postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow?.thread ?? null });
+ const cardMs = performance.now() - t;
+ assert.ok(planMs < 1500, `plan ${planMs.toFixed(0)} ms`);
+ assert.ok(cardMs < 1500, `card ${cardMs.toFixed(0)} ms`);
+});
+
+test("MINOR: a narration with attach: after does not play the screens' spans -- the lint says so", () => {
+ const S = { id: "s1", media: 0, kind: "dm", read: "all", lines: [{ who: "a", text: "hello" }] };
+ const e = narr(base([S]), [["s1", 0]]);
+ e.narration.attach = "after";
+ assert.ok(validateThreadReadWarnings({ timeline: [e], render: {} }).some((x) => /attach: after/.test(x)));
+});
diff --git a/umtool/report-to-video/post-screens.mjs b/umtool/report-to-video/post-screens.mjs
@@ -88,45 +88,85 @@ export const screenOf = (entry, id) => screensOf(entry).find((s) => s.id === id)
// THE SHAPES: what is never typeset nor read, marked or not.
// ---------------------------------------------------------------------------
-const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g;
-const PHONE_RE = /(?<![\w$.])\+?\(?\d[\d\s().-]{8,}\d(?![\w])/g;
-const ORDER_RE = /\b(?:order|confirmation|conf|invoice|tracking|reference|ref|account|acct)(?:\s+(?:number|no\.?|num|id|code))?\s*(?:#|:)?\s*([A-Za-z0-9-]*\d[A-Za-z0-9-]{2,})/gi;
-const HASHNUM_RE = /#\s?[A-Za-z0-9-]*\d{4,}[A-Za-z0-9-]*/g;
-// A token of six digits or more (separators inside it ignored), not an amount ("$1,000.00", "1,000,000").
+// Letters and digits of any script (`u`): "jöhn.doe@exämple.com", fullwidth digits "555".
+const EMAIL_RE = /[\p{L}\p{N}._%+-]+[@@](?:[\p{L}\p{N}-]+(?:\.[\p{L}\p{N}-]+)+|[\p{L}\p{N}-]{2,})/gu;
+const SPOKEN_EMAIL_RE = /[\p{L}\p{N}._-]+ (?:at) [\p{L}\p{N}-]+ (?:dot) (?:com|net|org|co|uk|io|me|us|edu|gov|ca|de|fr|au)\b/giu;
+/** A PHONE-STYLE RUN: digits joined by spaces, dashes, dots, middle dots, slashes or brackets (at most three between). */
+const RUN_RE = /[+(]?\p{Nd}(?:[ \t\-‐‑–—·./()]{0,3}\p{Nd})*/gu;
+/** A decimal (an amount, a weight: "99.95", "312.4") -- never part of a run. */
+const DECIMAL_RE = /\p{Nd}+[.,]\p{Nd}{1,2}(?!\p{Nd})/gu;
+/** A date: 11/02/2026, 2026-11-02, 02.11.26 -- shown. */
+const DATE_RE = /^\p{Nd}{1,4}[/.\-‐‑–—]\p{Nd}{1,2}[/.\-‐‑–—]\p{Nd}{1,4}$/u;
+/** Case-insensitive by letters (the `i` flag would make the IBAN's \p{Lu} match any letter). */
+const ci = (w) => w.replace(/[a-z]/g, (c) => `[${c}${c.toUpperCase()}]`);
+const KEYWORDS = "order|confirmation|conf|invoice|tracking|reference|ref|account|acct|card|iban|ssn|social security|code|pin|passcode|routing|member|customer|ticket|receipt|transaction|policy|booking|reservation|serial|id".split("|").map(ci).join("|");
+const GROUP = String.raw`[#]?[\p{L}\p{N}\-]*\p{Nd}[\p{L}\p{N}\-]*`;
+/** A keyword, "number" / "no." / "#", "is" / ":" / "ending in", then its value: groups with digits (an IBAN's capitals between them). */
+const ORDER_RE = new RegExp(String.raw`(?<![\p{L}\p{N}])(?:${KEYWORDS})(?:\s+(?:${["number", "no", "no.", "num", "id", "code"].map(ci).join("|").replace(/\./g, "\\.")}|#))?(?:\s*(?:${["is", "was", "ending in", "ending"].map(ci).join("|")}|=|:|#))*\s*(${GROUP}(?:[ \t](?:${GROUP}|\p{Lu}{1,4}(?=[ \t]${GROUP})))*)`, "gu");
+const HASHNUM_RE = /#\s?[\p{L}\p{N}-]*\p{Nd}{4,}[\p{L}\p{N}-]*/gu;
const TOKEN_RE = /[^\s]+/g;
-const AMOUNT_RE = /^[($]*\$?\d{1,3}(?:,\d{3})+(?:\.\d+)?[).,;:!?]*$|^[($]*\$\d+(?:\.\d+)?[).,;:!?]*$|^\d+\.\d{1,2}[).,;:!?]*$/;
+const AMOUNT_RE = /^[($]*\$?\p{Nd}{1,3}(?:,\p{Nd}{3})+(?:\.\p{Nd}+)?[).,;:!?]*$|^[($]*\$\p{Nd}{1,8}(?:\.\p{Nd}+)?[).,;:!?]*$|^\p{Nd}+\.\p{Nd}{1,2}[).,;:!?]*$/u;
+const digitsIn = (t) => (str(t).match(/\p{Nd}/gu) ?? []).length;
+const SHAPE_CACHE = new Map();
/**
- * THE SHAPES in a line, pure: `[{ start, end, kind }]` -- an e-mail address ("email"), a phone number of ten digits or
- * more ("phone"), an order / confirmation / invoice / tracking number, or a "#1234" ("order"), a run of six digits or
- * more that is not an amount ("number"). Merged, in order.
+ * THE SHAPES in a line, pure: `[{ start, end, kind }]` -- what is never drawn nor said, marked or not:
+ * "email" an e-mail address (any script; with or without its domain's ending), or one spelt out ("x at y dot com")
+ * "number" a phone-style run of nine digits or more (a card, an IBAN's digits, a phone, a spaced SSN), a local number
+ * (555 1234), a token of six digits or more -- never an amount ($104.90, 1,000,000), a decimal, a DATE
+ * (11/02/2026, 2026-11-02) or a time
+ * "order" the value after order / confirmation / tracking / reference / account / card / code … ("is", ":", "#",
+ * "ending in" between), or a "#1234"
+ * Merged, in order. Linear in the line (one pass a pattern).
*/
export function shapeSpans(text) {
const t = str(text);
+ if (!t) return [];
+ const hit = SHAPE_CACHE.get(t);
+ if (hit) return hit.map((x) => ({ ...x }));
const out = [];
- for (const m of t.matchAll(EMAIL_RE)) out.push({ start: m.index, end: m.index + m[0].length, kind: "email" });
- for (const m of t.matchAll(PHONE_RE)) if ([10, 11, 12, 13, 14, 15].includes((m[0].match(/\d/g) ?? []).length) && /[\s().+-]/.test(m[0])) out.push({ start: m.index, end: m.index + m[0].length, kind: "phone" });
+ for (const m of t.matchAll(EMAIL_RE)) {
+ // "@handle" alone is a mention (a local part is needed); a trailing dot is the sentence's.
+ const v = m[0].replace(/[.\-]+$/, "");
+ if (/^[@@]/.test(v)) continue;
+ out.push({ start: m.index, end: m.index + v.length, kind: "email" });
+ }
+ for (const m of t.matchAll(SPOKEN_EMAIL_RE)) out.push({ start: m.index, end: m.index + m[0].length, kind: "email" });
+ // Runs, the decimals blanked first (a list of weights is not a phone number).
+ const blank = t.replace(DECIMAL_RE, (d) => "x".repeat(d.length));
+ for (const m of blank.matchAll(RUN_RE)) {
+ const v = m[0].replace(/[ \t\-‐‑–—·./(]+$/, "");
+ const n = digitsIn(v);
+ if (n < 7 || DATE_RE.test(v.replace(/^[+(]/, ""))) continue;
+ const local = n <= 8 && /^\p{Nd}{3}[ \t\-‐‑–—·.]{1,3}\p{Nd}{4}$/u.test(v);
+ if (n >= 9 || local) out.push({ start: m.index, end: m.index + v.length, kind: "number" });
+ }
for (const m of t.matchAll(ORDER_RE)) {
- const v = m[1];
- if ((v.match(/\d/g) ?? []).length < 3) continue;
- const at = m.index + m[0].length - v.length;
+ const v = m[1].replace(/[.\-]+$/, "");
+ if (digitsIn(v) < 3) continue;
+ const at = m.index + m[0].length - m[1].length;
out.push({ start: at, end: at + v.length, kind: "order" });
}
for (const m of t.matchAll(HASHNUM_RE)) out.push({ start: m.index, end: m.index + m[0].length, kind: "order" });
for (const m of t.matchAll(TOKEN_RE)) {
const tok = m[0];
- if ((tok.match(/\d/g) ?? []).length < 6 || AMOUNT_RE.test(tok)) continue;
+ if (digitsIn(tok) < 6 || AMOUNT_RE.test(tok)) continue;
const lead = tok.match(/^[("'“[]*/)[0].length;
const trail = tok.match(/[)"'”\].,;:!?]*$/)[0].length;
+ const core = tok.slice(lead, tok.length - trail);
+ if (DATE_RE.test(core) || /^\p{Nd}{1,2}:\p{Nd}{2}(?::\p{Nd}{2})?$/u.test(core)) continue;
out.push({ start: m.index + lead, end: m.index + tok.length - trail, kind: "number" });
}
out.sort((a, b) => a.start - b.start || b.end - a.end);
const merged = [];
- for (const s of out) {
+ for (const sp of out) {
+ if (sp.end <= sp.start) continue;
const last = merged[merged.length - 1];
- if (last && s.start <= last.end) last.end = Math.max(last.end, s.end);
- else merged.push({ ...s });
+ if (last && sp.start <= last.end) last.end = Math.max(last.end, sp.end);
+ else merged.push({ ...sp });
}
+ if (SHAPE_CACHE.size > 20000) SHAPE_CACHE.clear();
+ SHAPE_CACHE.set(t, merged.map((x) => ({ ...x })));
return merged;
}
@@ -137,6 +177,9 @@ export function maskShapes(text) {
return { text: redactText(str(text), [], { spans }).text, kinds: [...new Set(spans.map((s) => s.kind))] };
}
+/** A short field (a title, a speaker, a time) as drawn: its shapes masked. */
+export const maskedField = (v) => maskShapes(str(v)).text;
+
// ---------------------------------------------------------------------------
// WHAT IS READ AND WHAT IS DRAWN of a screen.
// ---------------------------------------------------------------------------
@@ -169,50 +212,94 @@ export function excerptRun(line, excerpt) {
/** Whether a line can be read or drawn at all: not marked redact, with words. */
const lineOk = (l) => isObj(l) && l.redact !== true && !!str(l.text).trim();
-/**
- * A screen's READ LINES, pure, in the line order: `[{ n, start, end, cutBefore, cutAfter }]` -- each line read, the
- * run of its words read (the whole line, or its excerpt), and whether words were cut before or after it. "none", a
- * redacted line or a line with no words: none. An excerpt that is not in its line is read whole (the validation says so).
- */
-export function screenReadLines(screen) {
- const lines = Array.isArray(screen?.lines) ? screen.lines : [];
- const r = screen?.read;
+/** One screen worked out once (memoized by the screen object and what it holds): its read lines, its broken excerpts. */
+const VIEWS = new WeakMap();
+function viewOf(screen) {
+ if (!isObj(screen)) return { reads: [], broken: [] };
+ const lines = Array.isArray(screen.lines) ? screen.lines : [];
+ const key = JSON.stringify([screen.read, lines]);
+ const had = VIEWS.get(screen);
+ if (had && had.key === key) return had;
+ const r = screen.read;
const asked = r === "all" ? lines.map((_, n) => ({ line: n })) : Array.isArray(r) ? r.filter((x) => isObj(x) && Number.isInteger(x.line)) : [];
const seen = new Set();
- const out = [];
+ const reads = [];
+ const broken = [];
for (const x of asked) {
const l = lines[x.line];
if (!lineOk(l) || seen.has(x.line)) continue;
seen.add(x.line);
const t = str(l.text);
- const run = str(x.text).trim() ? excerptRun(t, x.text) : null;
const all = { start: t.search(/\S/), end: t.trimEnd().length };
- const span = run ?? all;
- out.push({ n: x.line, start: span.start, end: span.end, cutBefore: span.start > all.start, cutAfter: span.end < all.end });
+ let span = all;
+ if (str(x.text).trim()) {
+ const run = excerptRun(t, x.text);
+ // An excerpt that is not in the line (as drawn: after the redaction or anonymity passes) is NEVER read or drawn
+ // whole: the line is left out, and the build is told (screenDrawErrors).
+ if (!run) {
+ broken.push(x.line);
+ continue;
+ }
+ span = run;
+ }
+ const masked = maskShapes(t).text;
+ const cut = masked.slice(span.start, span.end);
+ reads.push({ n: x.line, start: span.start, end: span.end, cutBefore: span.start > all.start, cutAfter: span.end < all.end, said: cut.includes(REDACT_MARK) ? dropMarks(cut) : cut.trim(), shown: cut });
}
- return out.sort((a, b) => a.n - b.n);
+ reads.sort((a, b) => a.n - b.n);
+ const v = { key, reads, broken };
+ VIEWS.set(screen, v);
+ return v;
+}
+
+/**
+ * A screen's READ LINES, pure, in the line order: `[{ n, start, end, cutBefore, cutAfter }]` -- each line read, the
+ * run of its words read (the whole line, or its excerpt), and whether words were cut before or after it. "none", a
+ * redacted line, a line with no words, or an EXCERPT NOT IN ITS LINE: none (never the whole line instead).
+ */
+export function screenReadLines(screen) {
+ return viewOf(screen).reads.map(({ said: _s, shown: _w, ...r }) => r);
}
/** The screens the DATA says are read (a read line or more), in order. */
-export const readScreens = (entry) => screensOf(entry).filter((s) => screenReadLines(s).length > 0);
+export const readScreens = (entry) => screensOf(entry).filter((s) => viewOf(s).reads.length > 0);
-/** What a read line SAYS (before the thread read's spokenRead): its read run, its shapes left out. */
+/** What a read line SAYS (before the thread read's spokenRead): its read run, its shapes left out ("" when not read). */
export function screenLineSaid(screen, n) {
- const r = screenReadLines(screen).find((x) => x.n === n);
- if (!r) return "";
- const l = screen.lines[n];
- const masked = maskShapes(str(l.text)).text.slice(r.start, r.end);
- return masked.includes(REDACT_MARK) ? dropMarks(masked) : masked.trim();
+ return viewOf(screen).reads.find((x) => x.n === n)?.said ?? "";
+}
+
+/**
+ * A screen with lines `drops` (their indices) REMOVED, pure (a copy): its read follows them -- a removed line's read
+ * goes, the later lines' numbers move down (the CLI's `line.<n>=off`, the post bench's ×: one rule). A read the take
+ * already made is then held to the lines as they are (post-thread.mjs screenLineChanged).
+ */
+export function withoutLines(screen, drops) {
+ const gone = new Set(drops);
+ const to = (n) => n - [...gone].filter((d) => d < n).length;
+ const out = { ...screen, lines: (Array.isArray(screen?.lines) ? screen.lines : []).filter((_, n) => !gone.has(n)) };
+ if (Array.isArray(screen?.read)) out.read = screen.read.filter((x) => !gone.has(x?.line)).map((x) => ({ ...x, line: to(x.line) }));
+ return out;
+}
+
+/** Every reason the screens AS DRAWN (after the redaction and anonymity passes) cannot be drawn as the operator chose. */
+export function screenDrawErrors(entry) {
+ const out = [];
+ for (const sc of screensOf(entry)) for (const n of viewOf(sc).broken) out.push(`timeline ${entry?.id ?? "?"}: line ${n} of screen ${sc.id}: its excerpt is not in the line as drawn -- the line is left out (fix the excerpt: umtool posts screen <p> ${entry?.id ?? "<item>"} set ${sc.id} read.${n}=…)`);
+ return out;
}
/**
* A screen's DRAWN ROWS, pure: `[{ n, text, read, cutBefore, cutAfter } | { gap: true, lines }]` -- each line drawn
* (masked; a read excerpt alone, its cut sides marked "…"), whether it is read; the lines not read left out (a gap row
- * where they were) under `unread: "omit"`, drawn dim under "dim". A redacted line is never drawn (a gap row under omit).
+ * where they were) under `unread: "omit"`, drawn dim under "dim". A redacted line is never drawn (a gap row under omit);
+ * nor is a line whose excerpt is broken (screenDrawErrors).
*/
export function screenRows(screen) {
const lines = Array.isArray(screen?.lines) ? screen.lines : [];
- const reads = new Map(screenReadLines(screen).map((r) => [r.n, r]));
+ const v = viewOf(screen);
+ const reads = new Map(v.reads.map((r) => [r.n, r]));
+ const broken = new Set(v.broken);
const dim = screen?.unread === "dim";
const out = [];
let gap = 0;
@@ -222,13 +309,12 @@ export function screenRows(screen) {
};
lines.forEach((l, n) => {
const r = reads.get(n);
- if (!r && !(dim && lineOk(l))) {
+ if (!r && !(dim && lineOk(l) && !broken.has(n))) {
gap += 1;
return;
}
flush();
- const masked = maskShapes(str(l.text)).text;
- out.push({ n, text: r ? masked.slice(r.start, r.end) : masked.trim(), read: !!r, cutBefore: !!r?.cutBefore, cutAfter: !!r?.cutAfter });
+ out.push({ n, text: r ? r.shown : maskShapes(str(l.text)).text.trim(), read: !!r, cutBefore: !!r?.cutBefore, cutAfter: !!r?.cutAfter });
});
// A gap after the last row drawn: the screen goes on past what is shown.
if (gap && out.length) out.push({ gap: true, lines: gap });
@@ -267,6 +353,42 @@ export function screenWho(who, entry, names = {}) {
export const screenSide = (line, entry) => (SCREEN_SIDES.includes(line?.side) ? line.side : screenWho(line?.who, entry).self ? "right" : "left");
// ---------------------------------------------------------------------------
+// A LINE TYPED OR PASTED (the CLI's --from text, the post bench's paste box: one rule).
+// ---------------------------------------------------------------------------
+
+/** One line of TEXT as a screen line: `[right] who: words | time`, `- words`, `[redact] …`. Null: a blank line. */
+export function lineOfText(raw) {
+ let t = String(raw).trim();
+ if (!t) return null;
+ const out = {};
+ for (;;) {
+ const m = /^\[(left|right|redact)\]\s*/i.exec(t);
+ if (!m) break;
+ if (m[1].toLowerCase() === "redact") out.redact = true;
+ else out.side = m[1].toLowerCase();
+ t = t.slice(m[0].length);
+ }
+ const bar = t.lastIndexOf(" | ");
+ if (bar > 0) {
+ out.time = t.slice(bar + 3).trim();
+ t = t.slice(0, bar).trim();
+ }
+ if (t.startsWith("- ")) t = t.slice(2);
+ else {
+ const c = /^([^:]{1,64}?):\s+(.*)$/s.exec(t);
+ // NEVER a shape split into a speaker ("Order number: 4419", "Ref: AB-1234", "savvy@x.com: hi"): a "speaker" with a
+ // digit, an @, a shape keyword, or a shape of the whole line that reaches into it stays part of the line's words.
+ const keyword = new RegExp(`^(?:${KEYWORDS}|${["phone", "tel", "mobile", "cell", "fax", "email", "e-mail", "address", "zip", "postcode", "number", "no"].map(ci).join("|")})(?![\\p{L}\\p{N}])`, "u");
+ const splits = !!c && !/^https?$/i.test(c[1]) && !/[\p{Nd}@@#]/u.test(c[1]) && !keyword.test(c[1].trim()) && !shapeSpans(t).some((sp) => sp.start < c[1].length + 1);
+ if (c && splits) {
+ out.who = c[1].trim();
+ t = c[2];
+ }
+ }
+ return { ...(out.who ? { who: out.who } : {}), ...(out.side ? { side: out.side } : {}), text: t.trim(), ...(out.time ? { time: out.time } : {}), ...(out.redact ? { redact: true } : {}) };
+}
+
+// ---------------------------------------------------------------------------
// THE VALIDATION.
// ---------------------------------------------------------------------------
@@ -347,7 +469,7 @@ export function validateScreens(e) {
if (lines2[x.line].redact === true) errors.push(`${rw}: line ${x.line} is redacted -- it is never read`);
if (x.text !== undefined) {
if (typeof x.text !== "string" || !x.text.trim()) errors.push(`${rw}.text must be the words of the line to read (an excerpt)`);
- else if (!excerptRun(str(lines2[x.line].text), x.text)) errors.push(`${rw}.text "${x.text.slice(0, 40)}" is not a run of line ${x.line}'s words (an excerpt is the line's own words, in a row)`);
+ else if (!excerptRun(str(lines2[x.line].text), x.text)) errors.push(`${rw}.text is not a run of line ${x.line}'s words (an excerpt is the line's own words, in a row)`);
}
for (const k of Object.keys(x)) if (!["line", "text"].includes(k)) errors.push(`${rw}.${k} is not a read's field (line, text)`);
});
@@ -432,8 +554,10 @@ export function screenHeader(entry, screen, { authorHidden = false } = {}) {
const m = Array.isArray(entry?.media) ? entry.media[screen?.media] : null;
const where = m?.kind === "image" ? "picture" : "video";
const who = authorHidden || !str(entry?.author).trim() ? "the post's" : `${str(entry.author).trim()}'s`;
- const what = str(screen?.title).trim() || KIND_WORD[screen?.kind] || "Text";
- return { text: `${what} shown in ${who} ${where}`, badge: `${str(screen?.title).trim() || KIND_SHORT[screen?.kind] || "Text"} · transcribed` };
+ // A title's shapes masked as a line's are (an e-mail, a number in it never drawn).
+ const title = maskedField(str(screen?.title).trim());
+ const what = title || KIND_WORD[screen?.kind] || "Text";
+ return { text: `${what} shown in ${who} ${where}`, badge: `${title || KIND_SHORT[screen?.kind] || "Text"} · transcribed` };
}
/**
@@ -459,9 +583,10 @@ export function screenTileHtml(entry, screen, { k, size, blocks, shown, authorHi
const nameOf = (l) => {
const w = str(l?.who).trim();
if (!w) return "";
- return shown(l) ? `<span class="sname">${esc(w)}</span>` : '<span class="sname redact">xxxxxxxx</span>';
+ // A speaker's shapes masked whatever the privacy rule says (an e-mail or a phone number as a "name").
+ return shown(l) ? `<span class="sname">${esc(maskedField(w))}</span>` : '<span class="sname redact">xxxxxxxx</span>';
};
- const time = (l) => (str(l?.time).trim() ? `<span class="stime">${esc(l.time.trim())}</span>` : "");
+ const time = (l) => (str(l?.time).trim() ? `<span class="stime">${esc(maskedField(l.time.trim()))}</span>` : "");
let body;
if (screen.kind === "dm") {
const named = new Set();
@@ -484,7 +609,8 @@ export function screenTileHtml(entry, screen, { k, size, blocks, shown, authorHi
})
.join("");
} else if (screen.kind === "post") {
- const first = screen.lines.find((l) => str(l?.who).trim());
+ // Its author: the speaker of the first line DRAWN (never a redacted or left-out line's).
+ const first = rows.filter((r) => !r.gap).map((r) => screen.lines[r.n]).find((l) => str(l?.who).trim());
body = `<div class="spost">${first ? `<div class="sphead">${nameOf(first)}<span class="plabel" data-screen-shot="">screenshot</span></div>` : '<div class="sphead"><span class="plabel" data-screen-shot="">screenshot</span></div>'}${rows
.map((r) => (r.gap ? `<div class="sgap" data-screen-gap="${r.lines}">⋯</div>` : `<p class="sline${r.read ? "" : " sdim"}" data-screen-line="${r.n}"${blk(r.n)}>${words(r)}</p>`))
.join("")}</div>`;
@@ -538,9 +664,11 @@ export function screenCss({ k, pal, mixHex, rgbaOf, pad }) {
}
// ---------------------------------------------------------------------------
-// THE LINT's WARNINGS (lint.mjs; never refused).
+// THE LINT's WARNINGS (lint.mjs; never refused). They NAME a line, never quote a value.
// ---------------------------------------------------------------------------
+const kindWords = (kinds) => kinds.map((k) => (k === "email" ? "an e-mail address" : k === "order" ? "an order or reference number" : "a long number or a phone number")).join(" and ");
+
/**
* Post item `entry`'s screens WARNINGS, pure: a transcription no one checked, a line holding a shape the card masks, a
* screen on an item not narrated (not drawn), a screenshot of a post naming an archived one, a speaker the privacy rule
@@ -548,9 +676,9 @@ export function screenCss({ k, pal, mixHex, rgbaOf, pad }) {
* `narrated` whether it plays a take.
*
* @param {Record<string, any>} entry
- * @param {{ narrated?: boolean, takeRoles?: Array<string | null> }} [o]
+ * @param {{ narrated?: boolean, takeRoles?: Array<string | null>, attachAfter?: boolean }} [o]
*/
-export function screenWarnings(entry, { narrated = false, takeRoles = [] } = {}) {
+export function screenWarnings(entry, { narrated = false, takeRoles = [], attachAfter = false } = {}) {
const out = [];
const id = entry?.id ?? "?";
const w = `timeline ${id}`;
@@ -561,8 +689,15 @@ export function screenWarnings(entry, { narrated = false, takeRoles = [] } = {})
sc.lines.forEach((l, n) => {
if (!isObj(l) || l.redact === true) return;
const kinds = [...new Set(shapeSpans(str(l.text)).map((s) => s.kind))];
- if (kinds.length) out.push(`${w}: screen ${sc.id} line ${n} holds ${kinds.map((k) => (k === "email" ? "an e-mail address" : k === "phone" ? "a phone number" : k === "order" ? "an order or reference number" : "a long number")).join(" and ")} -- masked on the card and never said; mark the line redact (umtool posts screen <p> ${id} set ${sc.id} line.${n}.redact=on) if the rest of it should go too`);
+ if (kinds.length) out.push(`${w}: screen ${sc.id} line ${n} holds ${kindWords(kinds)} -- masked on the card and never said; mark the line redact (umtool posts screen <p> ${id} set ${sc.id} line.${n}.redact=on) if the rest of it should go too`);
+ // Its speaker and its time: masked on the card too.
+ for (const [f, what] of [["who", "speaker"], ["time", "time"]]) {
+ const k2 = [...new Set(shapeSpans(str(l[f])).map((x) => x.kind))];
+ if (k2.length) out.push(`${w}: screen ${sc.id} line ${n}'s ${what} holds ${kindWords(k2)} -- masked on the card; write it without (umtool posts screen <p> ${id} set ${sc.id} line.${n}.${f}=…)`);
+ }
});
+ const tk = [...new Set(shapeSpans(str(sc.title)).map((x) => x.kind))];
+ if (tk.length) out.push(`${w}: screen ${sc.id}'s title holds ${kindWords(tk)} -- masked on the card; write it without (umtool posts screen <p> ${id} set ${sc.id} title=…)`);
if (sc.kind === "post" && sc.ref) out.push(`${w}: screen ${sc.id} pictures ${sc.ref} -- drawn from its transcription; umtool posts set-item <p> ${id} link.add=… draws the archived post itself`);
const reads = screenReadLines(sc);
if (!reads.length) continue;
@@ -570,6 +705,8 @@ export function screenWarnings(entry, { narrated = false, takeRoles = [] } = {})
out.push(`${w}: screen ${sc.id} is drawn and read only on a narrated item -- make its read: umtool posts screen <p> ${id} read`);
continue;
}
+ // A read over the card first, the attachments after it (`attach: "after"`): the slot does not play the screen's span.
+ if (attachAfter) out.push(`${w}: screen ${sc.id}'s span is not played while it is read: the item's narration attaches its media after the read (attach: after) -- set attach=under to play it`);
const missing = reads.filter((r) => !roles.has(screenRole(sc.id, r.n)));
if (missing.length === reads.length) out.push(`${w}: its picked take does not read screen ${sc.id} (not drawn until it does) -- umtool posts screen <p> ${id} read`);
else if (missing.length) out.push(`${w}: its picked take does not read line${missing.length === 1 ? "" : "s"} ${missing.map((r) => r.n).join(", ")} of screen ${sc.id} -- umtool posts screen <p> ${id} read`);
@@ -577,9 +714,9 @@ export function screenWarnings(entry, { narrated = false, takeRoles = [] } = {})
for (const r of reads) {
const who = str(sc.lines[r.n].who).trim();
const s = screenWho(who, entry);
- if (who && !s.self && entry?.redact !== false && !subjects.has(handleKey(s.handle ?? "")) && !blurred.has(who.toLowerCase())) {
+ if (who && !s.self && entry?.redact !== false && sc.lines[r.n].anonymous !== true && !subjects.has(handleKey(s.handle ?? "")) && !blurred.has(who.toLowerCase())) {
blurred.add(who.toLowerCase());
- out.push(`${w}: screen ${sc.id}'s speaker ${who} is drawn blurred (the privacy rule: not a subject of the item) -- add them to its subjects or set redact: false to show the name`);
+ out.push(`${w}: screen ${sc.id} line ${r.n}'s speaker is drawn blurred (the privacy rule: not a subject of the item) -- add them to its subjects or set redact: false to show the name`);
}
}
}
diff --git a/umtool/report-to-video/post-screens.test.mjs b/umtool/report-to-video/post-screens.test.mjs
@@ -76,7 +76,7 @@ test("the data: a well-formed item with screens is taken; each wrong field is na
test("THE SHAPES: an e-mail, a phone number, an order or long number are masked -- absent from the card's page AND from what the part says", () => {
const kinds = (t) => shapeSpans(t).map((s) => s.kind);
assert.deepEqual(kinds("reply to support@coffeebrand.com"), ["email"]);
- assert.deepEqual(kinds("call +1 (555) 201-4477 today"), ["phone"]);
+ assert.deepEqual(kinds("call +1 (555) 201-4477 today"), ["number"]);
assert.deepEqual(kinds("Order number 4419283 shipped"), ["order"]);
assert.deepEqual(kinds("your code #88213 is ready"), ["order"]);
assert.deepEqual(kinds("id 2117069332987425196"), ["number"]);
@@ -227,7 +227,7 @@ test("anonymity: a speaker who is an anonymous handle is drawn under the shown n
// The lint: a speaker written as an anonymous author's display name is an ERROR.
const doc = { characters: [{ id: "tq", name: "Jeremy", handles: ["TheQuartering"], anonymous: true, shown: "Anon 1" }] };
const m = { timeline: [base({ screens: [{ ...S1, lines: [{ who: "Jeremy", text: "hi" }] }] }), { type: "post", id: "p-x", post: "tq-x/1", platform: "x", author: "Jeremy", handle: "TheQuartering", date: "2026-11-01T00:00:00Z", text: "x" }] };
- assert.ok(anonymityProblems(m, doc).errors.some((x) => /screen s1 names a speaker by Anon 1's display name/.test(x)));
+ assert.ok(anonymityProblems(m, doc).errors.some((x) => /screen s1 line 0's speaker writes Anon 1's display name/.test(x)));
});
test("the guard: a part reading a line the screen does not read, a redacted line, or a screen it does not carry is refused, with the fix", () => {
@@ -259,7 +259,7 @@ test("the lint's warnings: not checked, a masked shape, a read not made, a speak
assert.ok(w.some((x) => /screen s2 line 2 holds an e-mail address and an order or reference number/.test(x) || /screen s2 line 2 holds/.test(x)));
assert.ok(w.some((x) => /does not read lines 2, 3 of screen s1/.test(x)));
assert.ok(w.some((x) => /does not read screen s2/.test(x)));
- assert.ok(w.some((x) => /speaker TheQuartering is drawn blurred/.test(x)));
+ assert.ok(w.some((x) => /screen s1 line 0's speaker is drawn blurred/.test(x)));
const quiet = narrated(base({ redact: false, screens: [{ ...S1, checked: { by: "op", at: "2026-11-12T10:00:00Z" } }] }), [["s1", 0], ["s1", 1], ["s1", 2], ["s1", 3]]);
assert.deepEqual(screenWarnings(quiet, { narrated: true, takeRoles: partRoles(quiet).map((r) => r.role) }), []);
assert.ok(screenWarnings(base(), { narrated: false }).some((x) => /drawn and read only on a narrated item/.test(x)));
diff --git a/umtool/report-to-video/post-thread.mjs b/umtool/report-to-video/post-thread.mjs
@@ -49,13 +49,13 @@
// bench, the writers and the lint all read the same rules from here.
import { POST_PARENTS_MAX, cardText, contextText, linksOf, parentsOf, refMediaOf, refShown } from "./post-item.mjs";
-import { draftScript, isNarrated, isOnlyUrls, joinSplitLinks, pickedTake, scriptParts, spokenUrls } from "./post-narration.mjs";
+import { draftScript, isNarrated, isOnlyUrls, joinSplitLinks, pickedTake, postNarrationKnobs, scriptParts, spokenUrls } from "./post-narration.mjs";
import { normWord, scriptWordsOf } from "./word-zoom.mjs";
import { followKnobs } from "./read-follow.mjs";
import { planContext } from "./post-conversation.mjs";
import { branchMapOf, mapKnobs, mapTimes } from "./post-branch-map.mjs";
import { isPictureOnly, pictureBeatSeconds } from "./post-picture.mjs";
-import { isScreenScope, parseScreenRole, readScreens, screenLineProblem, screenLineSaid, screenOrder, screenPieces, screenReadLines, screenRole, screenScope, screenWarnings, tileOfRole } from "./post-screens.mjs";
+import { isScreenScope, parseScreenRole, readScreens, screenLineProblem, screenLineSaid, screenOrder, screenPieces, screenReadLines, screenRole, screenScope, screenWarnings, screensOf as screensOfEntry, tileOfRole } from "./post-screens.mjs";
/** What a context tile may be. */
export const THREAD_MODES = Object.freeze(["auto", "full", "excerpt", "context", "carry", "hidden"]);
@@ -545,6 +545,30 @@ function layoutMap(entry, tiles, roles, { prevId, group, knobs }) {
return branchMapOf(nodes, { prevId, nowId: now, subject: str(entry?.handle), style: knobs.style, group });
}
+const sayKeys = (t) => str(t).toLowerCase().split(/\s+/).map((x) => x.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, "")).filter(Boolean);
+const normText = (t) => str(t).replace(/\s+/g, " ").trim();
+
+/**
+ * Whether the picked take's parts for a screen line (`role`) say something else than the line says NOW: the line each
+ * part was made from (`parts[k].line`, stored by the thread read) is compared exactly with the line's words as a read
+ * would write them (draftScript of screenLineSaid); a part with none stored, by its own words, word for word.
+ */
+export function screenLineChanged(entry, role, roles = partRoles(entry)) {
+ const p = parseScreenRole(role);
+ const sc = p ? screensOfEntry(entry).find((x) => x.id === p.id) : null;
+ if (!sc) return false;
+ const said = screenLineSaid(sc, p.n);
+ const t = pickedTake(entry);
+ const parts = Array.isArray(t?.parts) && t.parts.length ? t.parts : scriptParts(str(t?.script).trim() ? t.script : str(entry?.narration?.script)).map((q) => ({ text: q.text }));
+ const mine = roles.map((r, k) => (r?.role === role ? parts[k] : null)).filter(Boolean);
+ if (!mine.length) return false;
+ const stored = mine.find((x) => typeof x.line === "string");
+ if (stored) return normText(stored.line) !== normText(draftScript(said).script);
+ const a = sayKeys(mine.map((x) => str(x.text)).join(" "));
+ const b = sayKeys(said);
+ return a.length !== b.length || a.some((x, i) => x !== b[i]);
+}
+
/** A tile's mode in a layout (null: no such tile). */
export const tileModeOf = (layout, scope) => layout?.tiles?.find((t) => t.scope === scope)?.mode ?? null;
@@ -568,6 +592,7 @@ export function threadReadErrors(entry, render = undefined, { prev = null, scene
const w = `timeline ${entry?.id ?? "?"}`;
const L = threadLayout(entry, render, { prev, scene });
const errors = [];
+ const changed = new Set();
const fix = `umtool posts set-item <p> ${entry?.id ?? "<item>"}`;
const remake = `or re-make the read without it (umtool posts narrate <p> ${entry?.id ?? "<item>"} --take, a script that leaves it out)`;
L.roles.forEach((r, k) => {
@@ -580,6 +605,13 @@ export function threadReadErrors(entry, render = undefined, { prev = null, scene
// A SCREEN's line (post-screens.mjs): drawn and lit only when the screen reads it.
const why = screenLineProblem(entry, r.role);
if (why) errors.push(`${w}: its take's part ${n} reads ${why} -- read it (umtool posts screen <p> ${entry?.id ?? "<item>"} set <screen> read=…) or re-make the read without it (umtool posts screen <p> ${entry?.id ?? "<item>"} read)`);
+ // The words it says are the line's AS IT IS NOW (operator's rule: nothing said the card does not show): a line edited,
+ // removed or moved since the read leaves the old audio under new lit text -- refused, never played.
+ else if (!changed.has(r.role) && screenLineChanged(entry, r.role, L.roles)) {
+ changed.add(r.role);
+ const p = parseScreenRole(r.role);
+ errors.push(`${w}: its take's part ${n}: line ${p.n} of screen ${p.id} changed since the read (its words are not what the take says) -- make the read again (umtool posts screen <p> ${entry?.id ?? "<item>"} read)`);
+ }
return;
}
if (r.role.startsWith("media:")) {
@@ -886,7 +918,7 @@ export function validateThreadReadWarnings(manifest) {
const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : [];
return tl.filter((e) => e?.type === "post").flatMap((e) => [
...threadReadWarnings(e),
- ...(Array.isArray(e.screens) ? screenWarnings(e, { narrated: isNarrated(e), takeRoles: isNarrated(e) ? partRoles(e).map((r) => r.role) : [] }) : []),
+ ...(Array.isArray(e.screens) ? screenWarnings(e, { narrated: isNarrated(e), takeRoles: isNarrated(e) ? partRoles(e).map((r) => r.role) : [], attachAfter: isNarrated(e) && postNarrationKnobs(e, manifest?.render).attach === "after" }) : []),
]);
}