commit 25e733aba2dd0be2237084ef0505b057203b3ea0
parent 4069bd03dbc26c37a722f1ef4b6e0019b8aa2fe7
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Tue, 17 Nov 2026 18:19:25 -0500
the Reads page: a preview names the rows its Find counted; Apply goes with its preview's token; a read the queue cannot re-read is said, not ticked (review 2, N1, N2, N5, N9)
N1: a These-reads preview sent no ids, so a filtered view's preview (and its Apply) covered every match
of the video; the preview now sends the rows Find counted and the route requires them as for Apply.
N2: the preview returns the draft's token; Apply sends it back, and a draft changed since is refused,
409, the draft changed since the preview: preview again -- nothing written. N5: a stale read marked
not queueable has no tick box, is not counted in Re-read N changed lines, and says why in its row; the
notice says how many were not queued and why. N9: a tick lasts only while its row is shown and can
still be re-read.
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/umtool/components/projects/ReadsPanel.tsx b/umtool/components/projects/ReadsPanel.tsx
@@ -16,7 +16,7 @@ import { narrationHref, playHref, postBenchHref } from "@/lib/hrefs";
type Take = { index: number | null; takeFile?: string | null; file: string | null; files?: string[]; key: string | null; reading: number; tuning: Record<string, number> | null; tunedBy: string | null } | null;
type Read = {
id: string; kind: "post" | "thread" | "screen" | "card"; item: string; role: string | null; character: { id: string; name: string } | null; voice: string | null;
- spoken: string; said: string | null; storedAt: string | null; editable: boolean; why: string | null; state: string; because: string[]; take: Take; newTake: Take; matches?: { start: number; end: number }[];
+ spoken: string; said: string | null; storedAt: string | null; editable: boolean; why: string | null; queueable?: boolean; state: string; because: string[]; take: Take; newTake: Take; matches?: { start: number; end: number }[];
};
type QueueRow = { read: string; item: string; kind: string; qid: string; state: string; error: string | null; before: Take; batch: string };
type Queue = { rows: QueueRow[]; waiting: string | null; counts: Record<string, number>; batch: string | null };
@@ -24,7 +24,7 @@ type Undo = { scope: "reads" | "say"; available: boolean; why: string | null; en
type View = { counts: Record<string, number>; reads: Read[]; find?: { matches: number; lines: number }; queue: Queue; undo: Undo };
type Line = { id: string; kind: string; item: string; before: string; after: string; creates: string | null };
type Preview =
- | { scope: "reads"; lines: Line[]; skipped: { id: string; why: string }[]; notes: Record<string, string[]>; refused: Record<string, string[]>; matches: number }
+ | { scope: "reads"; lines: Line[]; skipped: { id: string; why: string }[]; notes: Record<string, string[]>; refused: Record<string, string[]>; matches: number; token: string }
| { scope: "say"; entry: { word: string; say: string }; was: string | null; stale: { id: string }[]; cards: string[]; matches: number };
const KIND: Record<Read["kind"], string> = { post: "post script", thread: "thread part", screen: "screen line", card: "card narration" };
@@ -119,7 +119,8 @@ export default function ReadsPanel({ project, initialState = "all", initialChara
}
};
const ask = (scope: "reads" | "say") => run(async () => {
- const j = await post({ project, op: "preview", from: find, to, scope, case: matchCase, word });
+ // These reads previews the rows Find counted in this view (its filter too) -- never every match of the video.
+ const j = await post({ project, op: "preview", from: find, to, scope, case: matchCase, word, ...(scope === "reads" ? { only: reads.map((r) => r.id) } : {}) });
setPreview({ ...(j as object), scope } as Preview);
setSkip(new Set());
});
@@ -127,7 +128,8 @@ export default function ReadsPanel({ project, initialState = "all", initialChara
if (!preview) return;
const only = preview.scope === "reads" ? preview.lines.map((l) => l.id).filter((id) => !skip.has(id)) : [];
if (preview.scope === "reads" && !only.length) throw new Error("no line is ticked");
- await post({ project, op: "replace", from: find, to, scope: preview.scope, case: matchCase, word, ...(preview.scope === "reads" ? { only } : {}) });
+ // Apply goes with its preview's token: the draft changed since, and it is refused ("preview again").
+ await post({ project, op: "replace", from: find, to, scope: preview.scope, case: matchCase, word, ...(preview.scope === "reads" ? { only, token: preview.token } : {}) });
setNotice(preview.scope === "reads" ? `rewritten: ${only.length} read${only.length === 1 ? "" : "s"} (the shown text untouched) -- they are stale now` : `"${preview.entry.word}" is said "${preview.entry.say}" in every read of a post now -- ${preview.stale.length} read${preview.stale.length === 1 ? "" : "s"} stale`);
setPreview(null);
});
@@ -141,13 +143,22 @@ export default function ReadsPanel({ project, initialState = "all", initialChara
});
const reads = useMemo(() => view?.reads ?? [], [view]);
- const changed = reads.filter((r) => r.state === "stale");
+ // What Re-read can queue: a stale read the queue can re-read (a piece from a synthesized take is re-read on the bench).
+ const queueableRow = (r: Read) => r.queueable !== false && (r.state === "stale" || r.state === "unpicked" || r.state === "none");
+ const changed = reads.filter((r) => r.state === "stale" && r.queueable !== false);
const toQueue = ticked.size ? [...ticked] : changed.map((r) => r.id);
+ // A tick lasts only while its row is shown and can still be re-read (a filter, a re-read landing, a replace).
+ const tickable = useMemo(() => new Set(reads.filter(queueableRow).map((r) => r.id)), [reads]);
+ useEffect(() => {
+ setTicked((t) => (([...t].every((id) => tickable.has(id))) ? t : new Set([...t].filter((id) => tickable.has(id)))));
+ }, [tickable]);
const reread = () => run(async () => {
// EXACTLY the reads the button counts -- never "every stale read of the video" (the route refuses an unscoped one).
const j = (await post({ project, op: "reread", only: toQueue })) as { steps?: { reads: string[] }[]; skipped?: { id: string; why: string }[] };
const n = (j.steps ?? []).reduce((a, s) => a + s.reads.length, 0);
- setNotice(n ? `${n} line${n === 1 ? "" : "s"} queued, one item at a time, in cut order -- each joins its list unpicked` : `nothing queued${j.skipped?.length ? `: ${j.skipped.map((s) => `${s.id} (${s.why})`).join(", ")}` : ""}`);
+ const skipped = j.skipped ?? [];
+ const why = skipped.length ? `${skipped.length} not queued: ${skipped.map((s) => `${s.id} (${s.why})`).join(", ")}` : "";
+ setNotice(n ? `${n} line${n === 1 ? "" : "s"} queued, one item at a time, in cut order -- each joins its list unpicked${why ? ` ยท ${why}` : ""}` : `nothing queued${why ? `: ${why}` : ""}`);
setTicked(new Set());
});
@@ -342,7 +353,7 @@ export default function ReadsPanel({ project, initialState = "all", initialChara
return (
<tr key={r.id} data-read={r.id} data-read-state={r.state}>
<td className={cn(cell, "px-1")}>
- {(r.state === "stale" || r.state === "unpicked" || r.state === "none") && (
+ {queueableRow(r) && (
<input type="checkbox" checked={ticked.has(r.id)} onChange={(e) => setTicked((s) => { const n = new Set(s); if (e.target.checked) n.add(r.id); else n.delete(r.id); return n; })} aria-label={`Re-read ${r.id}`} data-read-tick={r.id} />
)}
</td>
@@ -355,6 +366,7 @@ export default function ReadsPanel({ project, initialState = "all", initialChara
<Marked text={r.spoken} matches={r.matches} />
{r.said && r.said !== r.spoken && <span className="block text-[11px] text-muted">said as: {r.said}</span>}
{r.kind === "card" && r.state === "stale" && r.because.includes("words") && <span className="block text-[11px] text-doubt-text">its words changed with the replace: Re-read makes them play</span>}
+ {r.why && <span className="block text-[11px] text-muted" data-read-why={r.id}>{r.why}</span>}
</td>
<td className={cn(cell, STATE_CLASS[r.state])} data-read-because={r.because.join(",")}>
{r.state}{r.because.length ? <span className="block text-[11px]">{r.because.map((b) => BECAUSE[b] ?? b).join(", ")}</span> : null}
diff --git a/umtool/lib/report/readsApi.mjs b/umtool/lib/report/readsApi.mjs
@@ -6,6 +6,7 @@
//
// Plain ESM: tested without the app (readsApi.test.mjs).
import { READ_KINDS, filterReads, findInReads, projectReads, readIdsOf } from "./reads.mjs";
+import { manifestToken } from "./manifest.mjs";
const view = (x) => ({ id: x.id, kind: x.kind, item: x.item, role: x.role, character: x.character, voice: x.voice, spoken: x.spoken, said: x.said, storedAt: x.storedAt, editable: x.editable, why: x.why, queueable: x.queueable !== false, state: x.state, because: x.because, take: x.take, newTake: x.newTake, ...(x.matches ? { matches: x.matches } : {}) });
void READ_KINDS;
@@ -93,12 +94,22 @@ export async function readsPost(project, body, o) {
json = { scope: "say", entry: done.result.entry, changed: done.result.changed, was: done.plan.was, stale: done.plan.stale };
}
} else if (body.scope === "reads") {
- const only = onlyOf(body, op === "replace");
+ // The reads it acts on, on the preview as on Apply: the rows the page's Find counted.
+ const only = onlyOf(body, true);
if (op === "preview") {
+ // The draft's token as the preview read it: Apply writes only over that draft (409 otherwise).
+ const token = await manifestToken(project.dir);
const plan = await R.replacePlan(project, from, to, { ...opts, only });
- json = { scope: "reads", lines: plan.lines, skipped: plan.skipped, notes: plan.notes, refused: plan.refused, matches: plan.matches };
+ json = { scope: "reads", lines: plan.lines, skipped: plan.skipped, notes: plan.notes, refused: plan.refused, matches: plan.matches, token };
} else {
- const done = await R.applyReplace(project, from, to, { ...opts, only });
+ if (typeof body.token !== "string" || !body.token) throw new Refused("Apply goes with its preview's token (preview first)");
+ let done;
+ try {
+ done = await R.applyReplace(project, from, to, { ...opts, only, token: body.token });
+ } catch (err) {
+ if (err?.constructor?.name === "StaleToken") throw new Refused("the draft changed since the preview: preview again", 409);
+ throw err;
+ }
json = { scope: "reads", lines: done.plan.lines, token: done.result.token ?? null };
}
} else throw new Refused("scope is reads or say");
diff --git a/umtool/lib/report/readsApi.test.mjs b/umtool/lib/report/readsApi.test.mjs
@@ -52,9 +52,9 @@ test("MUST 1: pick and a replace of These reads name their reads; refused unscop
assert.equal((await readsPost(p, { op: "replace", scope: "reads", from: "north", to: "northern", only: ["c-1", "bad id"] }, o)).status, 400);
assert.deepEqual(await readManifestOf(p), before);
// The previewed ids: only those change.
- const prev = await readsPost(p, { op: "preview", scope: "reads", from: "north", to: "northern" }, o);
+ const prev = await readsPost(p, { op: "preview", scope: "reads", from: "north", to: "northern", only: ["p-1", "p-3", "c-1"] }, o);
assert.deepEqual(prev.json.lines.map((l) => l.id), ["p-1", "c-1"]);
- const done = await readsPost(p, { op: "replace", scope: "reads", from: "north", to: "northern", only: ["c-1"] }, o);
+ const done = await readsPost(p, { op: "replace", scope: "reads", from: "north", to: "northern", only: ["c-1"], token: prev.json.token }, o);
assert.equal(done.status, 200);
const m = await readManifestOf(p);
assert.match(m.timeline[3].narration.text, /northern/);