Archilyzer · Source

archilyzer

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

commit 294fd1b66236674b9c6a32c6014e41ccf6028043
parent b31b4c56a1ed944d181f03fbb2089efcd6f0d7bc
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 10 Nov 2026 13:41:28 -0500

umtool: the review pass's store and CLI -- a post's or a card's Keep / Fix in review-pass.json (a clip's is its walk verdict), progress and where it resumes; the walk's verdict writer exposed for the workspace (bench/walkVerdict.ts), the bench's Undo of a Confirm through it

`umtool review-pass <p> [ls] [--json]` · `mark <block> keep|fix|clear [--note T]`; GET/POST /api/report/review-pass; verbs rows; cli.md regenerated.

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

Diffstat:
Aumtool/app/api/report/review-pass/route.ts | 41+++++++++++++++++++++++++++++++++++++++++
Mumtool/bin/umtool.mjs | 2++
Mumtool/components/projects/ClipBench.tsx | 20+++++---------------
Aumtool/components/projects/bench/walkVerdict.ts | 30++++++++++++++++++++++++++++++
Mumtool/docs/cli.md | 3+++
Mumtool/lib/cli/groups.mjs | 12++++++++++++
Mumtool/lib/cli/verbs.mjs | 6++++++
Aumtool/lib/report/reviewPass.mjs | 217+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/report/reviewPass.test.mjs | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 390 insertions(+), 15 deletions(-)

diff --git a/umtool/app/api/report/review-pass/route.ts b/umtool/app/api/report/review-pass/route.ts @@ -0,0 +1,41 @@ +import { projectRef } from "@/lib/projects"; +import { readManifest } from "@/lib/projects/report.mjs"; +import { readReviewPass, setReviewMark } from "@/lib/report/reviewPass.mjs"; +import { refuseCaller } from "@/lib/report/caller"; +import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs"; + +export const dynamic = "force-dynamic"; + +// THE REVIEW PASS's post and card marks (lib/report/reviewPass.mjs; the workspace's `?mode=review`). A clip's +// Keep / Fix is its walk verdict, written through the window writer (PUT /api/report/window); this is the store +// for what has none. +// +// GET ?project=<id> <project>/review-pass.json, as read +// POST { project, block, mark: "keep"|"fix"|null, note? } one block's mark (null clears it); a Fix says what +// needs fixing. Terminal twin: `umtool review-pass <p> mark`. +export async function GET(request: Request) { + const url = new URL(request.url); + const project = await projectRef(url.searchParams.get("project") ?? ""); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + return Response.json(await readReviewPass(project.dir), { headers: { "cache-control": "no-store" } }); +} + +export async function POST(request: Request) { + const refused = refuseCaller(request, "/api/report/review-pass"); + if (refused) return refused; + const cross = crossSiteRefusal(request.headers); + if (cross) return Response.json({ error: cross }, { status: 403 }); + const body = (await request.json().catch(() => null)) as { project?: string; block?: string; mark?: string | null; note?: string } | null; + if (!body || typeof body !== "object" || typeof body.block !== "string") return Response.json({ error: "bad json: { project, block, mark }" }, { status: 400 }); + const project = await projectRef(String(body.project ?? "")); + if (!project) return Response.json({ error: "no such project" }, { status: 404 }); + const manifest = await readManifest(project.dir); + if (!manifest) return Response.json({ error: "no video.manifest.json" }, { status: 404 }); + const mark = body.mark === null || body.mark === undefined || body.mark === "" ? null : body.mark; + try { + const r = await setReviewMark(project.dir, manifest, body.block, mark as "keep" | "fix" | null, { note: typeof body.note === "string" ? body.note : undefined }); + return Response.json({ ok: true, ...r }, { headers: { "cache-control": "no-store" } }); + } catch (e) { + return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 400 }); + } +} diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -885,6 +885,8 @@ const COMMANDS = { window: cmdWindow, // The clip bench's walk, of the cut or of a take (walk a take): lib/report/walkCli.mjs. walk: async () => process.exit(await (await import("../lib/report/walkCli.mjs")).walkCommand(argv.slice(argv.indexOf("walk") + 1))), + // The workspace's review pass: each block's answer, a post's or a card's mark (lib/report/reviewPass.mjs). + "review-pass": async () => process.exit(await (await import("../lib/report/reviewPass.mjs")).reviewPassCommand(argv.slice(argv.indexOf("review-pass") + 1))), // Present mode: the cut as slides (lib/report/presentCli.mjs). intro: async () => process.exit(await (await import("../lib/report/introCli.mjs")).introCommand(argv.slice(argv.indexOf("intro") + 1))), present: async () => process.exit(await (await import("../lib/report/presentCli.mjs")).presentCommand(argv.slice(argv.indexOf("present") + 1))), diff --git a/umtool/components/projects/ClipBench.tsx b/umtool/components/projects/ClipBench.tsx @@ -7,6 +7,7 @@ import AnchoredNotes, { notesOn } from "@/components/notes/AnchoredNotes"; import GeneratedBanner from "@/components/notes/GeneratedBanner"; import { useSharedNotes, wroteNotes } from "@/components/notes/NotesProvider"; import { announceManifestChanged } from "./timelineApi"; +import { writeClipPatch } from "./bench/walkVerdict"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { LatestLine, type WorkingCut } from "./review/WhatPlays"; import { createPortal } from "react-dom"; @@ -1241,14 +1242,6 @@ export default function ClipBench({ async (u: UndoRec) => { setUndo(null); const b = u.before; - const r = await fetch(`/api/report/clip?project=${encodeURIComponent(u.project)}&clip=${encodeURIComponent(u.clip)}`, { - cache: "no-store", - }); - if (!r.ok) { - setNote(`could not undo: ${r.status}`); - return; - } - const tok = ((await r.json()) as { token?: string }).token ?? null; const patch: Record<string, unknown> = { verdict: b.verdict === "confirmed" || b.verdict === "incorrect" ? b.verdict : "" }; if (u.moved) { patch.start = b.start; @@ -1257,16 +1250,13 @@ export default function ClipBench({ patch.cutEnd = b.cutEnd ?? ""; patch.muteFrom = b.muteFrom ?? ""; } - const w = await fetch("/api/report/window", { - method: "PUT", - headers: { "content-type": "application/json" }, - body: JSON.stringify({ project: u.project, clip: u.clip, token: tok, ...patch }), - }); - const j = (await w.json()) as Record<string, unknown>; + // The walk's verdict writer (bench/walkVerdict.ts): the clip's own token, then the window writer. + const w = await writeClipPatch(u.project, u.clip, patch); if (!w.ok) { - setNote(j.stale ? "could not undo: the manifest changed since — reload" : `could not undo: ${String(j.error ?? w.status)}`); + setNote(w.stale ? "could not undo: the manifest changed since — reload" : `could not undo: ${w.error}`); return; } + const j = w.json; if (wroteNotes(j)) void notes.reload(); if (u.clip === clip.id) { const next = fromEntry(clip, j.entry as Record<string, unknown>); diff --git a/umtool/components/projects/bench/walkVerdict.ts b/umtool/components/projects/bench/walkVerdict.ts @@ -0,0 +1,30 @@ +// THE WALK'S VERDICT WRITER, outside the bench (umtool redesign L7b): one clip's verdict -- `confirmed`, or +// `incorrect` with its `correction` -- written exactly as the clip bench writes it: the clip's own token read +// (GET /api/report/clip), then the window writer (PUT /api/report/window), one write and one undo point +// (lib/report/manifest.mjs updateClip). The bench's Undo of a Confirm writes through this, and the workspace's +// review pass (Keep · Fix) does; ClipBench's own Confirm keeps its in-component save, which carries a moved +// window in the same patch. Its terminal twin: `umtool window <p> <clip> --verdict confirmed|incorrect`. + +export type ClipWrite = + | { ok: true; entry: Record<string, unknown>; token: string; json: Record<string, unknown> } + | { ok: false; error: string; stale: boolean }; + +/** One clip's patch through the window writer, on the clip's token as it is now. */ +export async function writeClipPatch(project: string, clip: string, patch: Record<string, unknown>): Promise<ClipWrite> { + const r = await fetch(`/api/report/clip?project=${encodeURIComponent(project)}&clip=${encodeURIComponent(clip)}`, { cache: "no-store" }); + if (!r.ok) return { ok: false, error: `HTTP ${r.status}`, stale: false }; + const tok = ((await r.json().catch(() => ({}))) as { token?: string }).token ?? null; + const w = await fetch("/api/report/window", { + method: "PUT", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, clip, token: tok, ...patch }), + }); + const j = (await w.json().catch(() => ({}))) as Record<string, unknown>; + if (!w.ok) return { ok: false, error: String(j.error ?? `HTTP ${w.status}`), stale: !!j.stale }; + return { ok: true, entry: (j.entry ?? {}) as Record<string, unknown>, token: String(j.token ?? ""), json: j }; +} + +/** The walk's two answers a review pass gives: Keep (`confirmed`) and Fix (`incorrect`, saying what). */ +export function writeWalkVerdict(project: string, clip: string, v: { verdict: "confirmed" } | { verdict: "incorrect"; correction: string } | { verdict: "" }): Promise<ClipWrite> { + return writeClipPatch(project, clip, v); +} diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -42,6 +42,7 @@ Inbox cannot disagree about what is wrong with one. | `window <project> <clip> --align` · `--quote-ruled` / `--no-quote-ruled` | the cut snapped to the quote as HEARD (0.15 s before its first word, 0.3 s after its last, the extent widened to hold it, `lockCut`); a person's ruling on the quote check (a take renders a ruled clip) | | `window <project> <clip> --take <take> …` | a **take's** clip (walk a take): the same fields, written into the take's patch (`takes/<take>/take.json`) with an undo point first; the project's manifest is untouched ([clip-bench.md](clip-bench.md#walking-a-take)) | | `walk <project> [--take <take>] [--all] [--json]` | the clip bench's **walk**: every clip in walk order with its window, verdict and whether a fetched file holds it, and (→) the ones the walk visits — fetched and needing a verdict; `--all` every fetched one; `--take` walks a take (a draft too); the bench's address to start at. The intro (`render.intro`) is listed first, watched, not judged (`intro`, `stops` in `--json`) | +| `review-pass <project> [ls] [--json]` · `review-pass <project> mark <block> keep\|fix\|clear [--note T]` | the workspace's **review pass** (`?mode=review`): every block but the intro and a clip rejected for a cut reason, its answer and the block the pass resumes on; a clip's Keep · Fix is its walk verdict (`window --verdict confirmed\|incorrect --correction`), a post's or a card's lives in `<project>/review-pass.json` — `mark` writes one (a Fix needs `--note`, what needs fixing); a clip is refused here ([knobs.md](knobs.md#the-review-pass)) | | `present <project> [--take <take> \| --cut] [--json] [--public] [--open] [--url <origin>]` | **present mode**: the cut as slides, navigated like a deck (`/projects/<p>/present`) — prints the address and every slide (its kind, id — a post's `<channel>/<id>`, a clip's id, `section-<n>`, `day-<YYYY-MM-DD>` — date, words and censor counts); `--json` the payload (each post's card as Play draws it and its censor data by kind, each clip's spans, the dividers); `--public` the payload a public page would carry (censored, no reveal data); `--open` opens it; `<address>#<slide id>` opens a slide ([knobs.md](knobs.md#present-mode-the-cut-as-slides-navigated-like-a-deck)) | | `set <project> <clip> key=value …` | a clip's **knobs**: `claim.at` `claim.hold` `claim.stamp` `claim.count` `claim.label` (the first mark's, or `--mark <id>`'s), its **marks** `mark.add=<verdict>[@<sec>]` `mark.remove=<id>` `mark.verdict=<verdict>` `marks=<json>`, `audio.offset` `audio.gain` `audio.fadeIn` `audio.fadeOut`, its picture's **blur** `blur.on=true` `blur.caption=…` `blur.strength` `blur.from` `blur.to` (`blur.on=` clears it; [knobs.md](knobs.md#a-clips-picture-blurred)), its **effects** `fx.zoom=<json>` `fx.receipts=<json>` `fx.punch=…` `fx.quote` `fx.punchIn=<json>` `fx.speakers=<json>` (`fx=<json>` all of them, `fx=` clears them; a shot is a file in the project; [knobs.md](knobs.md#effects)); `key=` clears one ([knobs.md](knobs.md#marks)) | | `intro <project> [key=value …] [--off] [--json]` · `intro <project> --take <take> --off\|--on` | **the intro** the cut opens on (`render.intro`): with no key, prints it as written, what the cut opens with (a `title-card`'s words resolved) and each version's on/off; `key=value` writes it through the look writer (`style` `seconds` 3.5–8 `mark` `ground` `sound` (`false` silent) `site` `title` `lines` (`a\|b`, ≤ 3) and the brand's keys; `key=` clears one; a new intro starts as `boot-dark`); `--off` takes it off the cut; `--take <t> --off` that version opens on no intro (its patch's `render.intro: null`), `--on` on the cut's again. **Exit 1** on a value the build refuses ([knobs.md](knobs.md#the-intro-played-and-edited)) | @@ -190,6 +191,8 @@ draft (the project's manifest); *project*: a project's other files, or reads; *c | `link <project> [<article>] [--clear]` | the manifest names the article it is the video of | form · *draft* | | `window <project> <clip> [--start N] [--end N] [--lock] [--lock-end] [--no-lock-end] [--cut-start N] [--cut-end N] [--lock-cut] [--align] [--title TITLE] [--date DATE] [--cite N] [--cite-url CITE-URL] [--quote QUOTE] [--repeat-of REPEAT-OF] [--verdict confirmed\|incorrect] [--correction CORRECTION] [--reject not-matching\|wrong-speaker\|irrelevant\|repeats\|weak\|privacy\|other] [--note NOTE] [--walk-note WALK-NOTE] [--star] [--no-star] [--quote-ruled] [--no-quote-ruled] [--move-stamp MOVE-STAMP] [--clear-stamp] [--move-mute nearest] [--clear-mute] [--gap GAP…] [--gap-remove N] [--gaps GAPS] [--take TAKE]` | a clip's window, cut, attribution and verdict | form · *draft* | | `walk <project> [--take TAKE] [--all]` | the clip bench's walk: clips in walk order, verdicts, fetched | form · *project* | +| `review-pass <project> ls` | the review pass: each block's answer, and where it resumes | form · *project* | +| `review-pass <project> mark <block> keep\|fix\|clear [--note NOTE]` | a post's or a card's review-pass answer: keep, fix (with what) or clear | form · *project* | | `present <project> [--take TAKE] [--cut] [--public]` | present mode's address and slides | form · *project* | | `set <project> <clip> key=value… [--mark MARK] [--take TAKE]` | a clip's knobs: claim, marks, audio, blur, fx … | form · *draft* | | `intro <project> [key=value…] [--off] [--take TAKE] [--on]` | the intro the cut opens on (render.intro) | form · *draft* | diff --git a/umtool/lib/cli/groups.mjs b/umtool/lib/cli/groups.mjs @@ -254,6 +254,18 @@ export const GROUPS = [ ], }, { + cmd: "review-pass", + usage: [ + " umtool review-pass <project> [ls] [--json] the workspace's REVIEW PASS: each block's answer (a clip's is its", + " walk verdict; a post's or a card's review-pass.json) and the block it resumes on", + " umtool review-pass <project> mark <block> keep|fix|clear [--note T] a post's or a card's answer (a Fix says what)", + ], + docs: [ + ["`review-pass <project> [ls] [--json]` · `review-pass <project> mark <block> keep\\|fix\\|clear [--note T]`", + "the workspace's **review pass** (`?mode=review`): every block but the intro and a clip rejected for a cut reason, its answer and the block the pass resumes on; a clip's Keep · Fix is its walk verdict (`window --verdict confirmed\\|incorrect --correction`), a post's or a card's lives in `<project>/review-pass.json` — `mark` writes one (a Fix needs `--note`, what needs fixing); a clip is refused here ([knobs.md](knobs.md#the-review-pass))"], + ], + }, + { cmd: "present", usage: [ " umtool present <project> [--take <id> | --cut] [--json] [--public] [--open] PRESENT MODE: the cut as slides,", diff --git a/umtool/lib/cli/verbs.mjs b/umtool/lib/cli/verbs.mjs @@ -164,6 +164,12 @@ export const VERBS = Object.freeze([ takeOpt(), ]), form("walk", "project", "the clip bench's walk: clips in walk order, verdicts, fetched", [project(), takeOpt({ help: "walk a take (a draft too)" }), bool("--all", "every fetched clip")]), + // The workspace's review pass (umtool redesign L7b, lib/report/reviewPass.mjs): a clip's Keep / Fix is its walk + // verdict (`window --verdict`); a post's or a card's lives in review-pass.json. + form("review-pass ls", "project", "the review pass: each block's answer, and where it resumes", [project()], { shape: "review-pass <project> ls" }), + form("review-pass mark", "project", "a post's or a card's review-pass answer: keep, fix (with what) or clear", [ + project(), arg("block", { context: "post", help: "the post item's or the card's id" }), pick("mark", ["keep", "fix", "clear"], { required: true }), opt("--note", { type: "text", help: "a Fix: what needs fixing" }), + ], { shape: "review-pass <project> mark <block> <mark>" }), form("present", "project", "present mode's address and slides", [project(), takeOpt({ help: "that take's cut (default the latest)" }), bool("--cut", "the manifest alone"), bool("--public", "as a public page would carry it")]), form("set", "draft", "a clip's knobs: claim, marks, audio, blur, fx …", [project(), clip(), pairs({ help: "key=value, one per line (claim.at=190.2, audio.gain=-3, `key=` clears)" }), opt("--mark", { help: "the mark the claim.* keys set" }), takeOpt()]), form("intro", "draft", "the intro the cut opens on (render.intro)", [project(), pairs({ required: false, help: "key=value, one per line (style=boot-dark, seconds=4); none: print it" }), bool("--off", "take the intro off"), takeOpt({ help: "a version: --off opens it on no intro, --on on the cut's" }), bool("--on")]), diff --git a/umtool/lib/report/reviewPass.mjs b/umtool/lib/report/reviewPass.mjs @@ -0,0 +1,217 @@ +// THE REVIEW PASS (umtool redesign L7b; the workspace's `?mode=review`): the draft watched block by block, each +// block answered Keep · Fix · Note, and the draft (or a version) given a verdict at the end. It replaces the walk +// as the way through a cut; the clip bench stays the deep tool for one clip. +// +// Where each answer lands -- no new store for what already has one: +// +// a clip its WALK VERDICT, the bench's (the manifest, through the window writer): Keep is `confirmed`, +// Fix is `incorrect` with its correction (what needs fixing). Terminal twin: +// `umtool window <p> <clip> --verdict confirmed|incorrect --correction T`. +// a post, a card, `<project>/review-pass.json` (this file's): `{ mark: "keep" | "fix", note? }` per block id -- +// a video entry a post has no walk verdict. Twin: `umtool review-pass <p> mark <block> keep|fix|clear`. +// Note the notes store (notes.json), anchored to the block (`{ kind: "entry", entry }`): `umtool notes`. +// the end verdict takes/verdicts.json, L4's writer (`umtool takes verdict <p> <take> like|maybe|no`). +// +// What the pass walks: the cut's entries in order but the intro (watched, never judged -- the walk's own rule) and +// a clip rejected for a cut reason (it is out of the cut's playback already; the bench re-rules it). A clip ruled +// incorrect stays in the list: it is a Fix. Progress is "N / M reviewed", and the pass resumes on the first block +// with no answer. +// +// Plain ESM: the CLI runs under bare node; the app reads the same functions. +import { mkdir, readFile, rename, writeFile } from "node:fs/promises"; +import path from "node:path"; + +export const REVIEW_PASS_FILE = "review-pass.json"; +export const REVIEW_MARKS = /** @type {const} */ (["keep", "fix"]); +/** A Fix's note, at most (a correction is the bench's sixth field; this is its post-and-card twin). */ +export const REVIEW_NOTE_LIMIT = 2000; + +/** @typedef {{ mark: "keep" | "fix", note?: string, at: string }} ReviewMark */ +/** @typedef {{ version: 1, marks: Record<string, ReviewMark> }} ReviewPassDoc */ + +const empty = () => /** @type {ReviewPassDoc} */ ({ version: 1, marks: {} }); + +/** Keep only well-formed marks: a hand-edited file never breaks the pass, it loses the rows it garbled. */ +function clean(raw) { + const out = empty(); + const marks = raw && typeof raw === "object" && raw.marks && typeof raw.marks === "object" ? raw.marks : {}; + for (const [id, m] of Object.entries(marks)) { + if (!m || typeof m !== "object" || !REVIEW_MARKS.includes(m.mark)) continue; + out.marks[id] = { mark: m.mark, ...(typeof m.note === "string" && m.note.trim() ? { note: m.note } : {}), at: typeof m.at === "string" ? m.at : "" }; + } + return out; +} + +/** The project's review-pass.json; `{ version: 1, marks: {} }` when absent or unreadable. */ +export async function readReviewPass(dir) { + try { + return clean(JSON.parse(await readFile(path.join(dir, REVIEW_PASS_FILE), "utf8"))); + } catch { + return empty(); + } +} + +// One write at a time per file, in this process (the app's route and a CLI run are separate processes: the +// rename keeps a reader from ever seeing half a file, and the last write wins, as with the take verdicts). +const chains = new Map(); +function serial(file, fn) { + const prev = chains.get(file) ?? Promise.resolve(); + const run = prev.catch(() => {}).then(fn); + chains.set(file, run); + return run.finally(() => { + if (chains.get(file) === run) chains.delete(file); + }); +} + +/** The timeline entry kinds whose mark lives here (a clip's is its walk verdict). */ +const MARKED_HERE = new Set(["post", "card", "teaser", "video"]); + +/** + * Set (or clear) one block's mark. Refused: a clip (its mark is its walk verdict), a block the timeline does not + * hold, a Fix with no note (say what needs fixing -- the rule the walk's `incorrect` has). + * + * @param {string} dir + * @param {{ timeline?: Array<Record<string, any>> } | null} manifest + * @param {string} block + * @param {"keep" | "fix" | null} mark null clears it + * @param {{ note?: string, now?: Date }} [o] + * @returns {Promise<{ doc: ReviewPassDoc, mark: ReviewMark | null }>} + */ +export async function setReviewMark(dir, manifest, block, mark, { note, now = new Date() } = {}) { + const e = (manifest?.timeline ?? []).find((x) => x && x.id === block); + if (!e) throw new Error(`no block "${block}" in the cut`); + if (e.type === "clip") { + throw new Error(`${block} is a clip: its mark is its walk verdict (umtool window <p> ${block} --verdict confirmed | --verdict incorrect --correction "…")`); + } + if (!MARKED_HERE.has(String(e.type))) throw new Error(`${block} is a ${e.type}: the review pass does not mark it`); + if (mark !== null && !REVIEW_MARKS.includes(mark)) throw new Error(`mark must be one of ${REVIEW_MARKS.join(", ")} (or clear)`); + const text = typeof note === "string" ? note.trim().slice(0, REVIEW_NOTE_LIMIT) : ""; + if (mark === "fix" && !text) throw new Error("a Fix says what needs fixing (--note)"); + const file = path.join(dir, REVIEW_PASS_FILE); + return serial(file, async () => { + const doc = await readReviewPass(dir); + if (mark === null) delete doc.marks[block]; + else doc.marks[block] = { mark, ...(text ? { note: text } : {}), at: now.toISOString() }; + await mkdir(dir, { recursive: true }); + const tmp = `${file}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`; + await writeFile(tmp, JSON.stringify(doc, null, 2) + "\n", "utf8"); + await rename(tmp, file); + return { doc, mark: doc.marks[block] ?? null }; + }); +} + +/** + * What the pass walks, from either shape of an entry: the play view's (`type`, `review.verdict`) or the + * manifest's (`type`, `verdict`). The intro and a clip rejected for a cut reason are left out. + * + * @param {Array<{ id: string, type: string, verdict?: string | null, review?: { verdict?: string | null } | null }>} entries + */ +export function reviewBlocks(entries) { + return (Array.isArray(entries) ? entries : []).filter((e) => { + if (!e || typeof e.id !== "string" || e.type === "intro") return false; + const v = e.review?.verdict ?? e.verdict ?? null; + return !(e.type === "clip" && v === "rejected"); + }); +} + +/** + * One block's answer: a clip's from its walk verdict (confirmed → keep, incorrect → fix), anything else's from + * the marks. null: not reviewed yet. + * + * @param {{ id: string, type: string, verdict?: string | null, review?: { verdict?: string | null, correction?: string | null } | null, correction?: string | null }} e + * @param {Record<string, ReviewMark>} marks + * @returns {{ mark: "keep" | "fix", note: string | null } | null} + */ +export function blockAnswer(e, marks) { + if (e.type === "clip") { + const v = e.review?.verdict ?? e.verdict ?? null; + const correction = e.review?.correction ?? e.correction ?? null; + if (v === "confirmed") return { mark: "keep", note: null }; + if (v === "incorrect") return { mark: "fix", note: typeof correction === "string" ? correction : null }; + return null; + } + const m = marks?.[e.id]; + return m ? { mark: m.mark, note: m.note ?? null } : null; +} + +/** + * The pass's progress: how many of its blocks have an answer, and where it resumes (the first with none; null when + * every block has one -- the verdict at the end). + * + * @param {Parameters<typeof reviewBlocks>[0]} entries + * @param {Record<string, ReviewMark>} marks + */ +export function reviewProgress(entries, marks) { + const blocks = reviewBlocks(entries); + let done = 0; + let next = null; + for (const b of blocks) { + if (blockAnswer(b, marks)) done += 1; + else if (next === null) next = b.id; + } + return { done, total: blocks.length, next, ids: blocks.map((b) => b.id) }; +} + +export const REVIEW_PASS_USAGE = [ + "umtool review-pass <project> [ls] [--json]", + "umtool review-pass <project> mark <block> keep|fix|clear [--note T]", +]; + +/** + * `umtool review-pass`: the pass's blocks with their answers and where it resumes (`ls`), or one post / card mark + * (`mark`). A clip's answer is its walk verdict -- `umtool window` writes it. + * + * @param {string[]} args + * @param {{ resolve?: (p: string) => Promise<{ id: string, dir: string } | null>, log?: Function, err?: Function }} [o] + */ +export async function reviewPassCommand(args, { resolve, log = console.log, err = console.error } = {}) { + const json = args.includes("--json"); + const noteAt = args.indexOf("--note"); + const note = noteAt >= 0 ? args[noteAt + 1] : undefined; + const pos = args.filter((a, i) => !a.startsWith("--") && !(noteAt >= 0 && i === noteAt + 1)); + const [projectArg, verb = "ls", block, what] = pos; + if (!projectArg || args.includes("--help") || args.includes("-h")) { + (projectArg ? log : err)(REVIEW_PASS_USAGE.map((l) => `usage: ${l}`).join("\n")); + return projectArg ? 0 : 2; + } + const find = resolve ?? (async (a) => (await (await import("../projects/core.mjs")).resolveProject(a)).project ?? null); + const p = await find(projectArg); + if (!p) { + err(`no project "${projectArg}" (or more than one answers to that name: use its id)`); + return 2; + } + const manifest = JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); + if (verb === "mark") { + if (!block || !what || !["keep", "fix", "clear"].includes(what)) { + err(`usage: ${REVIEW_PASS_USAGE[1]}`); + return 2; + } + try { + const r = await setReviewMark(p.dir, manifest, block, what === "clear" ? null : /** @type {"keep" | "fix"} */ (what), { note }); + if (json) log(JSON.stringify({ project: p.id, block, mark: r.mark })); + else log(r.mark ? `${block}: ${r.mark.mark}${r.mark.note ? ` — ${r.mark.note}` : ""}` : `${block}: cleared`); + return 0; + } catch (e) { + err(e instanceof Error ? e.message : String(e)); + return 1; + } + } + if (verb !== "ls") { + err(`unknown: review-pass ${verb}\n${REVIEW_PASS_USAGE.map((l) => `usage: ${l}`).join("\n")}`); + return 2; + } + const doc = await readReviewPass(p.dir); + const timeline = Array.isArray(manifest.timeline) ? manifest.timeline : []; + const prog = reviewProgress(timeline, doc.marks); + const rows = reviewBlocks(timeline).map((e) => ({ id: e.id, type: e.type, answer: blockAnswer(e, doc.marks) })); + if (json) { + log(JSON.stringify({ project: p.id, done: prog.done, total: prog.total, next: prog.next, blocks: rows }, null, 2)); + return 0; + } + log(`${p.id}: ${prog.done} / ${prog.total} reviewed${prog.next ? ` · resumes at ${prog.next}` : " · every block answered: the verdict is next"}`); + for (const r of rows) { + const a = r.answer; + log(` ${r.id === prog.next ? "→" : " "} ${r.id.padEnd(10)} ${String(r.type).padEnd(6)} ${a ? a.mark : "—"}${a?.note ? ` ${a.note}` : ""}`); + } + return 0; +} diff --git a/umtool/lib/report/reviewPass.test.mjs b/umtool/lib/report/reviewPass.test.mjs @@ -0,0 +1,74 @@ +// THE REVIEW PASS's answers (lib/report/reviewPass.mjs): a clip's from its walk verdict, a post's or a card's from +// review-pass.json; what the pass walks, where it resumes, and the store's refusals. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdtempSync, readFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { blockAnswer, readReviewPass, reviewBlocks, reviewPassCommand, reviewProgress, setReviewMark, REVIEW_PASS_FILE } from "./reviewPass.mjs"; + +const timeline = [ + { type: "clip", id: "c01", verdict: "confirmed" }, + { type: "clip", id: "c02", verdict: "incorrect", correction: "the date is wrong" }, + { type: "post", id: "p-5" }, + { type: "card", id: "k01" }, + { type: "clip", id: "c03", verdict: "rejected", reason: "weak" }, + { type: "clip", id: "c04" }, +]; + +test("the pass walks every block but the intro and a clip rejected for a cut reason; an incorrect clip is a Fix", () => { + const view = [{ id: "intro", type: "intro" }, ...timeline.map((e) => ({ id: e.id, type: e.type, review: { verdict: e.verdict ?? null, correction: e.correction ?? null } }))]; + assert.deepEqual(reviewBlocks(view).map((b) => b.id), ["c01", "c02", "p-5", "k01", "c04"]); + assert.deepEqual(reviewBlocks(timeline).map((b) => b.id), ["c01", "c02", "p-5", "k01", "c04"]); + assert.deepEqual(blockAnswer(timeline[0], {}), { mark: "keep", note: null }); + assert.deepEqual(blockAnswer(timeline[1], {}), { mark: "fix", note: "the date is wrong" }); + assert.equal(blockAnswer(timeline[2], {}), null); + assert.deepEqual(blockAnswer(timeline[2], { "p-5": { mark: "keep", at: "" } }), { mark: "keep", note: null }); +}); + +test("progress counts the answered blocks and resumes on the first with none", () => { + assert.deepEqual(reviewProgress(timeline, {}), { done: 2, total: 5, next: "p-5", ids: ["c01", "c02", "p-5", "k01", "c04"] }); + const marks = { "p-5": { mark: "fix", note: "crop", at: "" }, k01: { mark: "keep", at: "" } }; + assert.deepEqual(reviewProgress(timeline, marks).next, "c04"); + assert.deepEqual(reviewProgress([...timeline.slice(0, 4)], marks), { done: 4, total: 4, next: null, ids: ["c01", "c02", "p-5", "k01"] }); +}); + +test("the store: a post's mark written and cleared; a clip, an unknown block and a Fix with no note refused", async () => { + const dir = mkdtempSync(path.join(tmpdir(), "review-pass-")); + try { + const m = { timeline }; + assert.deepEqual((await readReviewPass(dir)).marks, {}); + const r = await setReviewMark(dir, m, "p-5", "fix", { note: " the crop cuts his face ", now: new Date("2026-11-10T10:00:00Z") }); + assert.deepEqual(r.mark, { mark: "fix", note: "the crop cuts his face", at: "2026-11-10T10:00:00.000Z" }); + await setReviewMark(dir, m, "k01", "keep"); + assert.deepEqual(Object.keys((await readReviewPass(dir)).marks).sort(), ["k01", "p-5"]); + await setReviewMark(dir, m, "k01", null); + assert.deepEqual(Object.keys(JSON.parse(readFileSync(path.join(dir, REVIEW_PASS_FILE), "utf8")).marks), ["p-5"]); + await assert.rejects(setReviewMark(dir, m, "c04", "keep"), /walk verdict/); + await assert.rejects(setReviewMark(dir, m, "nope", "keep"), /no block/); + await assert.rejects(setReviewMark(dir, m, "k01", "fix"), /what needs fixing/); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +}); + +test("umtool review-pass: ls says where it resumes; mark writes a card's", async () => { + const dir = mkdtempSync(path.join(tmpdir(), "review-pass-cli-")); + try { + const { writeFileSync } = await import("node:fs"); + writeFileSync(path.join(dir, "video.manifest.json"), JSON.stringify({ timeline })); + const out = []; + const o = { resolve: async () => ({ id: "reports/x", dir }), log: (s) => out.push(String(s)), err: (s) => out.push(`ERR ${s}`) }; + assert.equal(await reviewPassCommand(["reports/x"], o), 0); + assert.match(out[0], /2 \/ 5 reviewed · resumes at p-5/); + assert.equal(await reviewPassCommand(["reports/x", "mark", "k01", "keep"], o), 0); + assert.equal(await reviewPassCommand(["reports/x", "mark", "c04", "keep"], o), 1); + out.length = 0; + assert.equal(await reviewPassCommand(["reports/x", "--json"], o), 0); + const j = JSON.parse(out.join("\n")); + assert.equal(j.done, 3); + assert.equal(j.next, "p-5"); + } finally { + rmSync(dir, { recursive: true, force: true }); + } +});