// THE REVIEW PASS's model (lib/report/reviewPass.mjs is the store and the CLI): what the pass walks, each block's // answer, the progress and where it resumes. Pure, no imports: the workspace's page reads it in the browser. export const REVIEW_MARKS = /** @type {const} */ (["keep", "fix"]); /** @typedef {{ mark: "keep" | "fix", note?: string, sig?: string, at: string, stale?: boolean }} ReviewMark */ /** * 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. null: not reviewed yet. * * a review-pass mark (review-pass.json), on any block keep, or fix ("needs work") with its note * a clip the BENCH ruled incorrect (a fact error, "ruled": answered, by the bench -- the pass never * wrong speaker), no mark overwrites it (its verdict and its words shown) * a clip whose walk verdict is confirmed, no mark keep * * Fix never writes a clip's verdict: `incorrect` is the fact-error verdict (a blocking check, `umtool corrections`). * * @param {{ id: string, type: string, verdict?: string | null, reason?: string | null, correction?: string | null, review?: { verdict?: string | null, reason?: string | null, correction?: string | null } | null }} e * @param {Record} marks * @returns {{ mark: "keep" | "fix" | "ruled", note: string | null, verdict?: string } | null} */ export function blockAnswer(e, marks) { // A mark whose block changed since it was reviewed (`stale`, reviewPass.mjs marksAgainst) is no answer. const m = marks?.[e.id]; if (m && !m.stale) return { mark: m.mark, note: m.note ?? null }; if (e.type !== "clip") return null; const v = clipVerdict(e); if (v === "confirmed") return { mark: "keep", note: null }; if (v === "incorrect") { const words = e.review?.correction ?? e.correction ?? e.review?.reason ?? e.reason ?? null; return { mark: "ruled", note: typeof words === "string" && words ? words : null, verdict: v }; } return null; } /** A clip's walk verdict, from either shape of an entry. */ export const clipVerdict = (e) => e?.review?.verdict ?? e?.verdict ?? null; /** * May the review pass's Keep write this clip's walk verdict (`confirmed`)? Only when it has none or is confirmed * already: a clip the bench ruled incorrect (a fact error, wrong speaker) is the bench's to change. */ export const clipKeepable = (e) => { const v = clipVerdict(e); return v === null || v === undefined || v === "" || v === "confirmed"; }; /** * 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[0]} entries * @param {Record} 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) }; }