// The review of a cut's narration script, card by card, before synthesis // (release 25, T5) -- since release 28 (M0) a view of the drafts review // (drafts-review.mjs), whose rows for a card's narration are // `narrate//narration`. // // /drafts.review.json every verdict, written here // /narration.review.json release 25's file, READ UNCHANGED: // { "": { "verdict": "approved" | "rejected" | null, "note": string, // "key": "", "text": "", "at": ISO } } // // The shape is takes/verdicts.json's (lib/report/takes.mjs): one row per item, // every row carrying every key, a row with no verdict and no note REMOVED // rather than stored, its own write queue, tmp + rename, and a file that does // not parse is an ERROR (never overwritten, never read as empty). // // A verdict is about THE WORDS AND THE VOICE IT WAS GIVEN ON: the row keeps // their key (narration.mjs `narrationKey`: text, engine, voice, speed), so an // edit -- of the words, or a change of voice -- leaves the row "edited": not // approved any more, without anything having to remember to clear it. The // writer that edits the words (umtool's narration page) clears it as well. // // The rule the build applies is drafts-review.mjs's `draftsReviewProblems`: // a narration with no drafted mark keeps this file's `reviewProblems` rule -- // with NO narration verdict anywhere, nothing is held (a warning); once there // is one, every narrated card must be approved on its current words, an // unreviewed or edited card refusing unless `--narration-unreviewed` and a // REJECTED card always. A DRAFTED narration (release 28) follows the drafts // rule: a warning until a `final` build, which refuses it unapproved. // // Pure but for the files' read and write. import { narrationsOf } from "./narration.mjs"; import { DRAFTS_REVIEW_FILE, NARRATION_REVIEW_FILE, REVIEW_NOTE_LIMIT, REVIEW_VERDICTS, cleanNarrationRows, narrationAddress, readDraftsReview, setDraftReview, } from "./drafts-review.mjs"; export { DRAFTS_REVIEW_FILE, NARRATION_REVIEW_FILE, REVIEW_NOTE_LIMIT, REVIEW_VERDICTS }; /** Rows that are not the contract's shape are dropped on read, never repaired on disk. */ export const cleanReview = cleanNarrationRows; /** A drafts review's narration rows, by card id. */ function narrationRowsOf(rows) { const out = {}; for (const [address, row] of Object.entries(rows ?? {})) { const m = /^narrate\/([^/]+)\/narration$/.exec(address); if (m && m[1] !== "*") out[m[1]] = row; } return out; } /** * The narration review of a cut: `{ exists, rows }` -- `exists` when any * narration verdict or note is kept (either file), `rows` by card id -- or * `{ exists: true, rows: {}, error }` when a file does not parse: a build must * not read that as "nothing approved", nor a writer overwrite it. */ export async function readNarrationReview(manifestDir) { const r = await readDraftsReview(manifestDir); if (r.error) return { exists: true, rows: {}, error: r.error }; const rows = narrationRowsOf(r.rows); return { exists: r.narration, rows }; } /** * One narration's review state: "approved" or "rejected" on its current words * and voice, "edited" when the verdict was given on others, else "unreviewed". * * @param {{ key: string }} n a narration (narration.mjs `narrationsOf`) * @param {{ verdict: string | null, key: string } | undefined} row */ export function reviewState(n, row) { if (!row?.verdict) return "unreviewed"; if (row.key !== n.key) return "edited"; return row.verdict; } /** Every narrated card of a cut with its review row and state, in timeline order. */ export function reviewRows(manifest, review) { return narrationsOf(manifest).map((n) => { const row = review?.rows?.[n.id] ?? null; return { ...n, row, state: reviewState(n, row) }; }); } /** * What the review says about building this cut: `errors` refuse it, `notes` * are said. `warnings` is the lint's: no review file for a narrated cut. * * @param {any} manifest the cut * @param {{ exists: boolean, rows: Record, error?: string } | null} review * @param {{ only?: string | null, allowUnreviewed?: boolean }} [opts] */ export function reviewProblems(manifest, review, { only = null, allowUnreviewed = false } = {}) { const errors = []; const notes = []; const warnings = []; const rows = reviewRows(manifest, review).filter((r) => !only || r.id === only); if (!rows.length || !review) return { errors, notes, warnings }; if (review.error) return { errors: [review.error], notes, warnings }; if (!review.exists) { warnings.push( `the narration (${rows.length} card${rows.length === 1 ? "" : "s"}) has no review — ${DRAFTS_REVIEW_FILE} has no narration verdicts; ` + "review it card by card on umtool's narration page before it is published", ); return { errors, notes, warnings }; } for (const r of rows) { if (r.state === "approved") continue; if (r.state === "rejected") { errors.push( `timeline ${r.id}: its narration was rejected${r.row?.note ? ` ("${r.row.note}")` : ""} — rewrite it and approve it, or take the narration out`, ); continue; } const why = r.state === "edited" ? "edited since it was approved" : "not reviewed"; if (allowUnreviewed) notes.push(`timeline ${r.id}: its narration is ${why} — built anyway (--narration-unreviewed)`); else errors.push(`timeline ${r.id}: its narration is ${why} — approve it on umtool's narration page, or build with --narration-unreviewed`); } return { errors, notes, warnings }; } /** * Set one card's review. `patch.verdict` "approved" | "rejected" | null (null * clears it); `note` replaces the note; `key` and `text` are the words and * voice the verdict is about (required with a verdict). A rejection needs its * note -- what is wrong with the words -- as an incorrect clip does. Returns * the row as stored (null when removed) and every narration row. Written to * drafts.review.json as `narrate//narration`. * * @param {string} manifestDir * @param {string} cardId * @param {{ verdict?: string | null, note?: string, key?: string, text?: string }} patch */ export async function setNarrationReview(manifestDir, cardId, patch) { if (!(typeof cardId === "string" && cardId.length > 0 && cardId.length <= 200 && !cardId.includes("/"))) throw new Error("not a card id"); const r = await setDraftReview(manifestDir, narrationAddress(cardId), patch); return { entry: r.entry, rows: narrationRowsOf(r.rows) }; }