Archilyzer · Source

archilyzer

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

commit d28e21a8fc2fee4f87cfb0accdbdac411c7b6cf4
parent 326d34ac796a16038bdeb7a0d02b3e6932b0bf13
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 11:20:16 -0400

umtool: one awaiting-review count, Reset undoes Extend, cite labels clear of the ends (P4b review)

The fields awaiting review are one source, lib/inbox/drafts.mjs awaitingReview:
a drafted field (its mark, or a task's draft file records it -- release 25's
narration) whose verdict is not given on its current value. The Inbox's
drafts card, the piece's Media tab count, its "to review" and Approve all,
and the review bench's status all read it. Reset on the clip bench undoes a
saved Extend (back to the window it replaced); a hand save forgets it. The
reader's cite thread holds the cite's label clear of 0:00 and the length
(lib/cite-thread.mjs, ch-measured). The Media tab's unlinked line is terse.

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

Diffstat:
Mumtool/components/articles/ArticlePage.tsx | 2+-
Mumtool/components/piece/PieceFrame.tsx | 2+-
Mumtool/components/projects/ClipBench.tsx | 45+++++++++++++++++++++++++++++++++------------
Mumtool/components/projects/MediaDrafts.tsx | 21++++++++++++---------
Mumtool/components/projects/ReportProject.tsx | 2+-
Mumtool/components/projects/ReviewPage.tsx | 4+++-
Mumtool/components/projects/report/ReportTabBody.tsx | 11+++++++----
Mumtool/components/ui/cite-thread.tsx | 16+++++++++++-----
Mumtool/e2e/bench-shell.spec.ts | 24++++++++++++++++++++++++
Mumtool/e2e/fixtures/bench-shell-fixture.mjs | 31+++++++++++++++++++------------
Mumtool/e2e/media-surfaces.spec.ts | 2+-
Mumtool/e2e/piece.spec.ts | 16++++++++++++++--
Aumtool/lib/cite-thread.mjs | 21+++++++++++++++++++++
Aumtool/lib/cite-thread.test.mjs | 18++++++++++++++++++
Mumtool/lib/inbox.ts | 9++++++---
Mumtool/lib/inbox/drafts.mjs | 22++++++++++++++++++++--
Mumtool/lib/inbox/drafts.test.mjs | 6+++++-
Mumtool/lib/report/draft-provenance.mjs | 16+++++++++++++++-
18 files changed, 212 insertions(+), 56 deletions(-)

diff --git a/umtool/components/articles/ArticlePage.tsx b/umtool/components/articles/ArticlePage.tsx @@ -130,7 +130,7 @@ export default async function ArticlePage({ const tabHref: TabHref = (t, q = {}) => articleHref(a, { tab: t, all: q.all, project: q.project === undefined ? project : q.project || undefined }); const title = r?.title || frame.piece?.title || reportId; - const counts = { ...(detail ? reportCounts(detail) : {}), ...(iterations ? { iterations } : {}) }; + const counts = { ...(detail && videoRef ? await reportCounts(detail, videoRef.dir) : {}), ...(iterations ? { iterations } : {}) }; const openNotes = notes.doc?.notes.filter((n) => n.status === "open").length ?? 0; const gitDir = path.join(/* turbopackIgnore: true */ reportDirFor(site, reportId), REPORT_HISTORY_GIT_DIRNAME); const head = await readRevisionHead(gitDir).catch(() => null); diff --git a/umtool/components/piece/PieceFrame.tsx b/umtool/components/piece/PieceFrame.tsx @@ -52,7 +52,7 @@ export default function PieceFrame({ meta?: React.ReactNode; /** More of the head's foot row, after the stepper (the policy chip). */ head?: React.ReactNode; - /** A count beside a tab's name, in Meter (Cut: clips, Media: drafted fields, Sources: recordings). */ + /** A count beside a tab's name, in Meter (Cut: clips, Media: fields awaiting review, Sources: recordings). */ counts: Partial<Record<string, number>>; /** The page's one-line status, the head's last `.micro`. */ note?: React.ReactNode; diff --git a/umtool/components/projects/ClipBench.tsx b/umtool/components/projects/ClipBench.tsx @@ -423,6 +423,11 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { // it has something in it. An incorrect verdict with no note is a complaint // nobody can act on, so the bench asks for the note before it writes one. const [needNote, setNeedNote] = useState(false); + // The window an Extend (the verdict bar's) saved over, so Reset can put it + // back: Extend saves at once -- its button names its result -- and Reset is + // its undo. Null once undone, or after any other window save. + const [extendedFrom, setExtendedFrom] = useState<{ start: number; end: number } | null>(null); + const resetRef = useRef<() => void>(() => {}); // Defaults on the server and on the first paint, then whatever this browser // remembers. Reading localStorage during render would be a hydration // mismatch on the one prop that changes what you hear. @@ -1391,10 +1396,7 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { break; case "r": case "R": - setSel({ from: clip.start, to: clip.end }); - setDirty(false); - setMute(clip.muteFrom); - muteRef.current = clip.muteFrom; + resetRef.current(); break; // Walking the cut. Reviewing a whole video is nineteen clips in a row, // and going back to the project page between each one is nineteen round @@ -1707,6 +1709,8 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const patch = windowPatch(); void save(patch).then((ok) => { if (!ok) return; + // A window saved by hand is the one Reset keeps from now on. + setExtendedFrom(null); const cleared = [ patch.cutStart !== undefined ? "the cut" : null, patch.muteFrom === "" && mute != null ? "the mute mark" : null, @@ -1865,8 +1869,28 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { const pastCache = sentenceEnd != null && sentenceEnd > clampTo + 0.02; const extendTo = (t: number) => { const to = round2(t); + const was = { start: clip.start, end: clip.end }; void save({ start: round2(sel.from), end: to }).then((ok) => { - if (ok) setNote(`saved — ${clip.id} now ends at ${hms(to)}, the end of the sentence`); + if (!ok) return; + setExtendedFrom(was); + setNote(`saved — ${clip.id} now ends at ${hms(to)}, the end of the sentence; R undoes it`); + }); + }; + // Reset: an unsaved edit goes back to the saved window; with none, a saved + // Extend goes back to the window it replaced. + resetRef.current = () => { + if (unsaved || !extendedFrom) { + setSel({ from: clip.start, to: clip.end }); + setDirty(false); + setMute(clip.muteFrom); + muteRef.current = clip.muteFrom; + return; + } + const back = extendedFrom; + void save({ start: back.start, end: back.end }).then((ok) => { + if (!ok) return; + setExtendedFrom(null); + setNote(`the extension is undone — ${clip.id} ends at ${hms(back.end)} again`); }); }; const verdictBar = ( @@ -2218,13 +2242,10 @@ export default function ClipBench({ data }: { data: ClipBenchData }) { <button type="button" className={buttonVariants({ size: "sm" })} - disabled={!unsaved} - onClick={() => { - setSel({ from: clip.start, to: clip.end }); - setDirty(false); - setMute(clip.muteFrom); - muteRef.current = clip.muteFrom; - }} + data-reset="" + disabled={!unsaved && !extendedFrom} + title={!unsaved && extendedFrom ? `undo the extension: back to ${hms(extendedFrom.start)} – ${hms(extendedFrom.end)}` : undefined} + onClick={() => resetRef.current()} > reset </button> diff --git a/umtool/components/projects/MediaDrafts.tsx b/umtool/components/projects/MediaDrafts.tsx @@ -13,6 +13,7 @@ import { ReaderPane } from "@/components/ui/reader-pane"; import { narrationHref, reviewHref } from "@/lib/hrefs"; import { citationText } from "@/lib/research/facets.mjs"; import type { DraftRowView, DraftRunSummary, ProjectIteration } from "@/lib/articles/projectDraft"; +import { awaitingReview } from "@/lib/inbox/drafts.mjs"; import { DraftControl, modelsFor, usePolicy } from "./DraftPanel"; import { DraftAlternatives, announceDraftsChanged, useDrafts, type DraftAct, type DraftRow, type DraftsView } from "./drafts"; import { announceManifestChanged } from "./timelineApi"; @@ -374,11 +375,11 @@ export function GateLine({ view }: { view: DraftsView }) { } /** Approve every field still to review, one after another. */ -export function ApproveAll({ view, act }: { view: DraftsView; act: DraftAct }) { +export function ApproveAll({ view, act, provenance }: { view: DraftsView; act: DraftAct; provenance: Record<string, FieldProvenance> }) { const hydrated = useHydrated(); const [busy, setBusy] = useState(false); const [error, setError] = useState<string | null>(null); - const todo = view.rows.filter((r) => r.state === "unreviewed" || r.state === "edited"); + const todo = awaitingReview(view.rows, provenance); if (!todo.length) return null; return ( <> @@ -387,7 +388,7 @@ export function ApproveAll({ view, act }: { view: DraftsView; act: DraftAct }) { data-approve-all={todo.length} disabled={!hydrated || busy} className={buttonVariants({ variant: "outline", size: "md" })} - title="approve every field not yet reviewed, as it is now" + title="approve every drafted field awaiting review, as it is now" onClick={async () => { setBusy(true); setError(null); @@ -486,6 +487,8 @@ export default function MediaDrafts({ const total = view.rows.length; const counts = { approved: 0, rejected: 0, edited: 0, unreviewed: 0 }; for (const r of view.rows) counts[r.state] += 1; + // To review: the drafted fields awaiting a verdict -- the tab's count and the Inbox's (awaitingReview). + const waiting = awaitingReview(view.rows, provenance).length; const chips = MEDIA_SECTIONS.map((s) => ({ ...s, n: view.rows.filter((r) => sectionOf(r.address) === s.task).length })); return ( <section aria-label="Media drafts" data-draft-panel={link.ok ? `${link.article}/i${link.n}` : ""} className="space-y-3"> @@ -493,7 +496,7 @@ export default function MediaDrafts({ <span className="font-mono text-[12px] text-meter" data-media-counts=""> {total} field{total === 1 ? "" : "s"} · {counts.approved} approved {counts.rejected ? ` · ${counts.rejected} rejected` : ""} - {counts.unreviewed + counts.edited ? ` · ${counts.unreviewed + counts.edited} to review` : ""} + {waiting ? ` · ${waiting} to review` : ""} </span> {link.ok && ( <span className="text-[12px] text-muted"> @@ -529,17 +532,17 @@ export default function MediaDrafts({ </button> </> )} - <ApproveAll view={view} act={drafts.act} /> + <ApproveAll view={view} act={drafts.act} provenance={provenance} /> </span> </div> <GateLine view={view} /> {!link.ok ? ( - <p data-draft-unlinked="" className="m-0 text-[12px] text-muted"> - {link.why} + <p data-draft-unlinked="" title={link.why} className="m-0 text-[12px] text-muted"> + Not from an article iteration — Draft with is off here. </p> ) : link.status !== "done" ? ( <p data-draft-unlinked="" className="m-0 text-[12px] text-muted"> - {link.article} i{link.n} is {link.status}: a draft runs over a done iteration + {link.article} i{link.n} is {link.status} — Draft with waits for it to finish. </p> ) : ( policyError && ( @@ -601,7 +604,7 @@ export function MediaReview({ const [lit, setLit] = useState<string | null>(null); const hydrated = useHydrated(); const row = view.rows.find((r) => r.address === lit) ?? null; - const todo = view.rows.filter((r) => r.state === "unreviewed" || r.state === "edited"); + const todo = awaitingReview(view.rows, provenance); const ev = row?.entry ? (evidence[row.entry] ?? null) : null; const [error, setError] = useState<string | null>(null); const approve = async () => { diff --git a/umtool/components/projects/ReportProject.tsx b/umtool/components/projects/ReportProject.tsx @@ -62,7 +62,7 @@ export default async function ReportProject({ frame={frame} tab={tab} tabs={PIECE_TABS.map((t) => ({ ...t, href: projectHref(project.id, { tab: t.id }) }))} - counts={reportCounts(detail)} + counts={await reportCounts(detail, project.dir)} note={reportStatus(detail)} more={ <> diff --git a/umtool/components/projects/ReviewPage.tsx b/umtool/components/projects/ReviewPage.tsx @@ -5,6 +5,7 @@ import { manifestToken } from "@/lib/report/manifest.mjs"; import { draftsView } from "@/lib/report/drafts.mjs"; import { readFieldProvenance } from "@/lib/report/draft-provenance.mjs"; import { pieceHrefOfProject } from "@/lib/pieces/article"; +import { awaitingReview } from "@/lib/inbox/drafts.mjs"; import type { ProjectRef } from "@/lib/project-types"; import { BenchFrame, BenchTop } from "./bench/BenchShell"; import { MediaReview, type FieldEvidence, type FieldProvenance } from "./MediaDrafts"; @@ -53,7 +54,8 @@ export default async function ReviewPage({ project }: { project: ProjectRef }) { // The piece this view belongs to: the article's when an article claims the project (P4a-2). const back = await pieceHrefOfProject(project.id, { tab: "media" }); - const toReview = counts.edited + counts.unreviewed; + // To review: the drafted fields awaiting a verdict (the Media tab's count, the Inbox's). + const toReview = awaitingReview(view.rows, provenance).length; return ( <BenchFrame kind="review" diff --git a/umtool/components/projects/report/ReportTabBody.tsx b/umtool/components/projects/report/ReportTabBody.tsx @@ -2,7 +2,7 @@ import GeneratedBanner from "@/components/notes/GeneratedBanner"; import { NotesProvider } from "@/components/notes/NotesProvider"; import { channelFor, clipsOf } from "@/lib/projects/report.mjs"; import type { PieceFrame } from "@/lib/pieces/frame"; -import { draftedFields, isCodeDraft } from "yt-dlp-transcript-common/lib/report/drafted.mjs"; +import { awaitingReviewOf } from "@/lib/report/draft-provenance.mjs"; import BuildTab from "./BuildTab"; import CutTab from "./CutTab"; import DeliverTab from "./DeliverTab"; @@ -17,11 +17,14 @@ import { hms, type ClipDetail, type ReportTabProps } from "./shared"; // article piece that claims it (components/articles/ArticlePage.tsx). The // project's notes are the target of everything under it. -/** The tabs' counts: cheap, from the manifest already read (Cut: clips, Media: drafted fields, Sources: recordings). */ -export function reportCounts(detail: ClipDetail): { cut: number; media: number; sources: number } { +/** + * The tabs' counts (Cut: clips, Media: the fields awaiting review -- the Inbox's + * drafts card's number, lib/inbox/drafts.mjs awaitingReview -- Sources: recordings). + */ +export async function reportCounts(detail: ClipDetail, dir: string): Promise<{ cut: number; media: number; sources: number }> { const m = detail.manifest; const clips = detail.entries.filter((e) => e.kind === "clip").length; - const media = draftedFields(m).filter((d) => !isCodeDraft(d.provenance)).length; + const media = (await awaitingReviewOf(dir, m)).length; const sources = new Set(clipsOf(m).map((e: { video: string }) => `${channelFor(m, e)}/${e.video}`)).size; return { cut: clips, media, sources }; } diff --git a/umtool/components/ui/cite-thread.tsx b/umtool/components/ui/cite-thread.tsx @@ -1,4 +1,5 @@ import { cn } from "@/lib/utils"; +import { threadLabels } from "@/lib/cite-thread.mjs"; import { clock } from "./clock"; // Where a cited second sits in its source (canvas `.cthread` / `.pthread`): a @@ -32,16 +33,21 @@ export function CiteThread({ ); } -/** The reader's version: start, cite and end under the line. */ +/** The reader's version: start, cite and end under the line; the cite's label never on an end's (lib/cite-thread.mjs). */ export function ReaderThread({ at, duration, className }: { at: number; duration: number; className?: string }) { const pct = duration > 0 ? Math.min(100, Math.max(0, (at / duration) * 100)) : 0; + const cite = clock(at); + const end = clock(duration); + const l = threadLabels({ pct, citeChars: cite.length, startChars: "0:00".length, endChars: end.length }); return ( - <div className={cn("cite-thread mt-2.5", className)} role="img" aria-label={`Cited at ${clock(at)} of ${clock(duration)}`} data-cite-at={at}> + <div className={cn("cite-thread mt-2.5", className)} role="img" aria-label={`Cited at ${cite} of ${end}`} data-cite-at={at}> <i style={{ left: `${pct}%` }} /> {/* The ends give way when the cite's own label would sit on them. */} - {pct >= 12 && <span style={{ left: 0 }}>0:00</span>} - <span style={{ left: `clamp(0px, calc(${pct}% - 22px), calc(100% - 56px))` }}>{clock(at)}</span> - {pct <= 80 && <span style={{ left: "auto", right: 0 }}>{clock(duration)}</span>} + {l.showStart && <span style={{ left: 0 }}>0:00</span>} + <span data-cite-label="" style={{ left: l.citeLeft }}> + {cite} + </span> + {l.showEnd && <span style={{ left: "auto", right: 0 }}>{end}</span>} </div> ); } diff --git a/umtool/e2e/bench-shell.spec.ts b/umtool/e2e/bench-shell.spec.ts @@ -1,4 +1,7 @@ import { test, expect, type Page } from "@playwright/test"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- @@ -18,6 +21,12 @@ import * as urls from "./urls"; const SHELL = "reports/bench-shell-fixture"; const REVIEW = "reports/media-review-fixture"; const BENCH = "reports/bench-fixture"; +const EXTEND = "reports/bench-extend-fixture"; +const FIXTURE = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song"); +const endOf = (id: string) => + (JSON.parse(readFileSync(path.join(FIXTURE, "reports", "bench-extend-fixture", "video.manifest.json"), "utf8")) as { timeline: { id: string; end: number }[] }).timeline.find( + (e) => e.id === id, + )!.end; /** The page fits the laptop: no horizontal scroll, no vertical page scroll. */ async function fits(page: Page) { @@ -93,6 +102,21 @@ test("the clip bench's keys walk the cut: n and p", async ({ page }) => { await expect(page.locator("[data-bench=s01]")).toBeVisible(); }); +test("Extend saves the sentence's end at once, and Reset puts the window back", async ({ page }) => { + await page.goto(urls.clipBenchHref(EXTEND, "s01")); + const bar = page.locator("[data-verdict-bar]"); + await bar.locator("[data-verdict-extend]").click(); + await expect.poll(() => endOf("s01")).toBe(9); + // The clip now ends the sentence: the bar asks the walk's question. + await expect(bar.locator("[data-verdict-question]")).toHaveText("Is s01 what the report says it is?"); + await expect(page.locator("[data-bench-note]")).toContainText("R undoes it"); + // Reset (the button, as R) undoes the saved extension. + await page.locator("[data-reset]").click(); + await expect.poll(() => endOf("s01")).toBe(6); + await expect(bar.locator("[data-verdict-question]")).toHaveText("Extend s01 to the end of the sentence?"); + await expect(page.locator("[data-reset]")).toBeDisabled(); +}); + test("the claim bench: its context on the reader, the cited cue lit, j/k from anywhere, Save ruling in the verdict bar", async ({ page }) => { await page.goto(urls.claimBenchHref(BENCH, "k01")); await expect(page.locator("[data-bench-top] [data-bench-kind]")).toHaveText("Claim bench"); diff --git a/umtool/e2e/fixtures/bench-shell-fixture.mjs b/umtool/e2e/fixtures/bench-shell-fixture.mjs @@ -1,7 +1,8 @@ // What bench-shell.spec.ts and piece.spec.ts's Media test act on (P4b): their // own projects, so the other specs' writes never move what they assert. // -// reports/bench-shell-fixture/ READ-ONLY. vid1's run-on cue (3-6 s) and the +// reports/bench-shell-fixture/ READ-ONLY (bench-extend-fixture, the same, is +// written by the Extend-and-Reset test). vid1's run-on cue (3-6 s) and the // sentence that closes at 9 s: // s01 3.00-6.00 ends mid-sentence: the verdict bar asks to extend it // to 0:09.00, which would cover all of s02 @@ -35,17 +36,23 @@ const write = (dir, name, doc) => { * `cachedWindow` the vid1 0-9 s window the build fixtures share. */ export function makeBenchShellFixture({ reports, manifest, cachedWindow }) { - const bench = path.join(reports, "bench-shell-fixture"); - write( - bench, - "video.manifest.json", - manifest("bench-shell-fixture", "The Bench Shell Fixture", { siteOrigin: "https://archive.example" }, [ - { type: "clip", id: "s01", video: "vid1", start: 3.0, end: 6.0, cite: 3, section: 0, quote: "and because" }, - { type: "clip", id: "s02", video: "vid1", start: 6.0, end: 9.0, cite: 6, section: 0, lock: true, quote: "the rest of it" }, - ]), - ); - mkdirSync(path.join(bench, "out", "clips-raw"), { recursive: true }); - copyFileSync(cachedWindow, path.join(bench, "out", "clips-raw", path.basename(cachedWindow))); + // bench-shell-fixture is read-only; bench-extend-fixture, the same two clips, + // is written by the Extend-and-Reset test alone. + let bench = null; + for (const slug of ["bench-shell-fixture", "bench-extend-fixture"]) { + const dir = path.join(reports, slug); + write( + dir, + "video.manifest.json", + manifest(slug, "The Bench Shell Fixture", { siteOrigin: "https://archive.example" }, [ + { type: "clip", id: "s01", video: "vid1", start: 3.0, end: 6.0, cite: 3, section: 0, quote: "and because" }, + { type: "clip", id: "s02", video: "vid1", start: 6.0, end: 9.0, cite: 6, section: 0, lock: true, quote: "the rest of it" }, + ]), + ); + mkdirSync(path.join(dir, "out", "clips-raw"), { recursive: true }); + copyFileSync(cachedWindow, path.join(dir, "out", "clips-raw", path.basename(cachedWindow))); + bench ??= dir; + } const made = []; for (const slug of ["media-tab-fixture", "media-review-fixture"]) { diff --git a/umtool/e2e/media-surfaces.spec.ts b/umtool/e2e/media-surfaces.spec.ts @@ -97,7 +97,7 @@ test("Draft with <model> per section: the job followed, the badge, the last run, // A project made from no iteration offers no draft, and says why. await page.goto(urls.section("reports/youtube-fixture", "drafts")); - await expect(page.getByRole("region", { name: "Media drafts" }).locator("[data-draft-unlinked]")).toContainText("not made from an article's iteration"); + await expect(page.getByRole("region", { name: "Media drafts" }).locator("[data-draft-unlinked]")).toHaveText("Not from an article iteration — Draft with is off here."); }); test("Draft everything: every draft in order on the model chosen, a refused one passed, the panels skipped, then the fast build, the podcast and out/youtube.txt", async ({ page }) => { diff --git a/umtool/e2e/piece.spec.ts b/umtool/e2e/piece.spec.ts @@ -373,12 +373,15 @@ test("the Media tab: every drafted field with where it came from, approve per fi const P = "reports/media-tab-fixture"; await page.goto(urls.projectHref(P, { tab: "media" })); await expect(tab(page, "media")).toHaveAttribute("aria-current", "page"); - await expect(tab(page, "media")).toHaveText("Media2"); + // One number: the fields awaiting review -- the two drafted titles and the release-25 narration its + // draft file records -- on the tab, in the header and on the Inbox's drafts card. + await expect(tab(page, "media")).toHaveText("Media3"); const media = page.getByRole("region", { name: "Media drafts" }); + await expect(media.locator("[data-media-counts]")).toHaveText("3 fields · 0 approved · 3 to review"); await expect(media.locator("[data-draft-row]")).toHaveCount(3); // Made from no iteration, it drafts nothing: the sections with fields, in Draft everything's order. await expect(media.locator("[data-media-section]")).toHaveCount(2); - await expect(media.locator("[data-draft-unlinked]")).toContainText("not made from an article's iteration"); + await expect(media.locator("[data-draft-unlinked]")).toHaveText("Not from an article iteration — Draft with is off here."); const m01 = media.locator("[data-draft-row='onscreen/m01/onscreen']"); await expect(m01.locator("[data-draft-text]")).toContainText("She will not sell"); @@ -400,6 +403,10 @@ test("the Media tab: every drafted field with where it came from, approve per fi await media.locator("[data-media-chip=all]").click(); await expect(media.locator("[data-draft-row]")).toHaveCount(3); + // The Inbox's drafts card counts the same three fields. + const before = (await (await page.request.get("/api/browse/decisions")).json()) as { items: { kind: string; project?: string }[] }; + expect(before.items.filter((d) => d.kind === "drafts-unreviewed" && d.project === P)).toHaveLength(3); + // Approve one, then all the rest. const m02 = media.locator("[data-draft-row='onscreen/m02/onscreen']"); await m02.locator("[data-draft-action=approve]").click(); @@ -409,6 +416,11 @@ test("the Media tab: every drafted field with where it came from, approve per fi await expect(media.locator("[data-draft-row][data-state=approved]")).toHaveCount(3); await expect(media.locator("[data-drafts-gate]")).toHaveAttribute("data-drafts-gate", "passes"); await expect(media.locator("[data-approve-all]")).toHaveCount(0); + // Nothing awaits review: the tab says no number, and the Inbox has no drafts card for it. + await page.reload(); + await expect(tab(page, "media")).toHaveText("Media"); + const inbox = (await (await page.request.get("/api/browse/decisions")).json()) as { items: { kind: string; project?: string }[] }; + expect(inbox.items.filter((d) => d.kind === "drafts-unreviewed" && d.project === P)).toEqual([]); // The on-screen panel is Media's now; the Build tab is the build. await expect(page.getByTestId("onscreen-section")).toBeVisible(); diff --git a/umtool/lib/cite-thread.mjs b/umtool/lib/cite-thread.mjs @@ -0,0 +1,21 @@ +// The reader's cite thread labels (components/ui/cite-thread.tsx ReaderThread): +// 0:00 at the left, the cite under its notch, the length at the right -- and +// the cite's label never on top of an end's (P4b: "0:000:03" in a bench's +// reader). An end label gives way when the cite sits close to it; otherwise +// the cite's label is held clear of it, measured in `ch` (the labels are mono). +// +// Pure: `node --test` runs it. + +/** + * @param {{ pct: number, citeChars: number, startChars: number, endChars: number }} o + * pct: the cite's place, 0..100; the *Chars: each label's length + * @returns {{ showStart: boolean, showEnd: boolean, citeLeft: string }} + */ +export function threadLabels({ pct, citeChars, startChars, endChars }) { + const showStart = pct >= 12; + const showEnd = pct <= 80; + const gap = 1; + const lo = showStart ? `${startChars + gap}ch` : "0px"; + const hi = showEnd ? `calc(100% - ${endChars + gap + citeChars}ch)` : `calc(100% - ${citeChars}ch)`; + return { showStart, showEnd, citeLeft: `clamp(${lo}, calc(${pct}% - ${citeChars / 2}ch), ${hi})` }; +} diff --git a/umtool/lib/cite-thread.test.mjs b/umtool/lib/cite-thread.test.mjs @@ -0,0 +1,18 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { threadLabels } from "./cite-thread.mjs"; + +test("the cite's label is held clear of the end labels it shares the line with", () => { + // 0:03 of 0:21 (a bench's reader): 0:00 shows, and the cite starts past it. + const near = threadLabels({ pct: (3 / 21) * 100, citeChars: 4, startChars: 4, endChars: 4 }); + assert.equal(near.showStart, true); + assert.equal(near.showEnd, true); + assert.match(near.citeLeft, /^clamp\(5ch, calc\(14\.2\d+% - 2ch\), calc\(100% - 9ch\)\)$/); + // At the very start the 0:00 gives way and the cite may sit at the edge. + assert.equal(threadLabels({ pct: 3, citeChars: 4, startChars: 4, endChars: 7 }).showStart, false); + assert.match(threadLabels({ pct: 3, citeChars: 4, startChars: 4, endChars: 7 }).citeLeft, /^clamp\(0px,/); + // Near the end the length gives way. + const end = threadLabels({ pct: 98, citeChars: 7, startChars: 4, endChars: 7 }); + assert.equal(end.showEnd, false); + assert.match(end.citeLeft, /calc\(100% - 7ch\)\)$/); +}); diff --git a/umtool/lib/inbox.ts b/umtool/lib/inbox.ts @@ -9,7 +9,8 @@ import { openDecisions, projectRefs, summariseProject, type ProjectRef } from ". import { readManifest, reportSignature } from "./projects/report.mjs"; import { draftsView } from "./report/drafts.mjs"; import { reviewHref } from "./hrefs"; -import { draftsDecisions } from "./inbox/drafts.mjs"; +import { awaitingReview, draftsDecisions } from "./inbox/drafts.mjs"; +import { readFieldProvenance } from "./report/draft-provenance.mjs"; import { pieceOfDecision, readPieceGraph, type Piece, type PieceGraph } from "./pieces"; import { lifecycleOf, readLifecycle, type LifecycleRead } from "./lifecycle"; import { isMuted, readMutes } from "./mutes"; @@ -243,11 +244,13 @@ async function projectDrafts(ref: ProjectRef): Promise<Decision[]> { const manifest = await readManifest(ref.dir); if (manifest) { const view = await draftsView(ref.dir, manifest); - if (view.rows.some((r) => r.drafted && (r.state === "unreviewed" || r.state === "edited"))) { + // Who drafted a field with no mark: its task's draft file (release 25's narration). + const provenance = view.rows.some((r) => r.state === "unreviewed" || r.state === "edited") ? await readFieldProvenance(ref.dir, manifest) : {}; + if (awaitingReview(view.rows, provenance).length) { const title = (await summariseProject(ref)).title; // When: the manifest's mtime (reportSignature's first field) -- a draft is written there. const at = Number(sig.split(":")[0]) || Date.now(); - value = draftsDecisions({ project: ref.id, projectTitle: title, href: reviewHref(ref.id), at, view }).map((d) => ({ + value = draftsDecisions({ project: ref.id, projectTitle: title, href: reviewHref(ref.id), at, view, provenance }).map((d) => ({ ...d, projectKind: ref.kind, })) as Decision[]; diff --git a/umtool/lib/inbox/drafts.mjs b/umtool/lib/inbox/drafts.mjs @@ -13,6 +13,23 @@ export const WAITING = new Set(["unreviewed", "edited"]); /** + * THE fields awaiting review (P4b: one number, one meaning -- the Inbox's + * drafts card, the piece's Media tab count and its "to review"): a field a + * model drafted -- its `drafted` mark, or a task's draft file records it + * (release 25's narration-draft.json carries no mark) -- whose verdict is not + * given on its current value. A narration written by hand is listed and can + * be judged, but nothing waits on it. + * + * @template {{ address: string, state: string, drafted: unknown }} R + * @param {R[]} rows draftsView()'s rows + * @param {Record<string, unknown>} [provenance] readFieldProvenance()'s, by address + * @returns {R[]} + */ +export function awaitingReview(rows, provenance = {}) { + return (rows ?? []).filter((r) => WAITING.has(r.state) && (!!r.drafted || !!provenance?.[r.address])); +} + +/** * What a drafts card is about, the canvas's card title: which kinds of field * and how many ("Narration draft · 5 fields"). * @@ -48,10 +65,11 @@ export function draftsWhy(rows) { * @param {{ * project: string, projectTitle: string, href: string, at: number, * view: { rows: { address: string, label: string, state: string, drafted: { model?: string } | null }[] }, + * provenance?: Record<string, unknown>, * }} o */ -export function draftsDecisions({ project, projectTitle, href, at, view }) { - const waiting = (view?.rows ?? []).filter((r) => r.drafted && WAITING.has(r.state)); +export function draftsDecisions({ project, projectTitle, href, at, view, provenance = {} }) { + const waiting = awaitingReview(view?.rows ?? [], provenance); if (!waiting.length) return []; const what = draftsWhat(waiting); const why = draftsWhy(waiting); diff --git a/umtool/lib/inbox/drafts.test.mjs b/umtool/lib/inbox/drafts.test.mjs @@ -3,7 +3,7 @@ import assert from "node:assert/strict"; import { mkdtemp, rm, writeFile, utimes } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; -import { draftsDecisions, draftsWhy } from "./drafts.mjs"; +import { awaitingReview, draftsDecisions, draftsWhy } from "./drafts.mjs"; import { annotate, summarizeGroups } from "./groups.mjs"; import { reportSignature } from "../projects/report.mjs"; @@ -25,6 +25,10 @@ test("one row per waiting field; approved, rejected and the operator's own are n assert.equal(out[0].why, "Narration draft · 2 fields · by qwen3:8b · 1 changed since approved"); assert.equal(out[0].what, "Narration draft · 2 fields"); assert.deepEqual(draftsDecisions({ project: "p", projectTitle: "p", href: "/", at: 0, view: { rows: [row("a", "narration", "approved")] } }), []); + // A narration with no mark that a task's draft file records (release 25's narrate) waits too (P4b). + const withFile = draftsDecisions({ project: "reports/x", projectTitle: "X", href: "/", at: 5, view, provenance: { "narrate/k03/narration": { file: "narration-draft.json" } } }); + assert.deepEqual(withFile.map((d) => d.target), ["narrate/k01/narration", "narrate/k02/narration", "narrate/k03/narration"]); + assert.deepEqual(awaitingReview(view.rows).map((r) => r.address), ["narrate/k01/narration", "narrate/k02/narration"]); }); test("the sentence names the kinds of field and the models", () => { diff --git a/umtool/lib/report/draft-provenance.mjs b/umtool/lib/report/draft-provenance.mjs @@ -16,7 +16,8 @@ import { readdir, readFile, stat } from "node:fs/promises"; import path from "node:path"; import { draftedFields, reviewAddress, stableStringify } from "yt-dlp-transcript-common/lib/report/drafted.mjs"; -import { DRAFT_FILE_RE } from "./drafts.mjs"; +import { DRAFT_FILE_RE, draftsView } from "./drafts.mjs"; +import { awaitingReview } from "../inbox/drafts.mjs"; const strings = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === "string") : []); const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); @@ -117,3 +118,16 @@ export async function readFieldProvenance(projectDir, manifest) { } return provenanceFrom(files, manifest); } + +/** + * The fields of a project awaiting review (lib/inbox/drafts.mjs awaitingReview): + * the number the piece's Media tab shows, the same the Inbox's drafts card counts. + * + * @param {string} projectDir + * @param {any} manifest + */ +export async function awaitingReviewOf(projectDir, manifest) { + const view = await draftsView(projectDir, manifest); + if (!view.rows.some((r) => r.state === "unreviewed" || r.state === "edited")) return []; + return awaitingReview(view.rows, await readFieldProvenance(projectDir, manifest)); +}