// `umtool posts slurs` -- THE SLUR FILTER of a cut's post items // (umtool-report-to-video/post-slurs.mjs; umtool/docs/knobs.md, "The slur // filter"): what it would mask, and its knobs. // // umtool posts slurs

[ls] what the cut would mask: per slur, per post, and each read's state // umtool posts slurs

on | off the filter (off: the cut is the uncensored one) // umtool posts slurs

level strong|all only the strong slurs, or the mild ones too // umtool posts slurs

visual blackout|placeholder // umtool posts slurs

voice skip|beep|placeholder // umtool posts slurs

add | except | remove // umtool posts slurs

edges [--off] that slur EDGE-masked ("n***a"): its word, id or a form names it // // Every write goes through updatePostSlurs (one undo point each). Nothing // here prints a slur: a word is shown as its mask. // // Plain ESM: the CLI runs under bare node. import { isNarrated, pickedTake, rootTakeOf } from "umtool-report-to-video/post-narration"; import { SLURS_DEFAULTS, SLUR_LEVELS, SLUR_VISUALS, SLUR_VOICES, edgeMask, maskOfOwnWord, slurReport, takeBleeps } from "umtool-report-to-video/post-slurs"; import { cutSlurs, defaultSlurList } from "umtool-report-to-video/post-redact-files"; import { readManifest } from "../projects/report.mjs"; import { withEditNotes } from "./edit-guard.mjs"; import { manifestToken, updatePostSlurs } from "./manifest.mjs"; export const SLURS_USAGE = [ " umtool posts slurs [ls] | on | off | level strong|all | visual blackout|placeholder", " | voice skip|beep|placeholder | add | except | remove ", " | edges [--off] [--json]", " THE SLUR FILTER (render.posts.slurs; on by default): every slur on the list (umtool/report-to-video/slurs.json,", " strong and mild; `level strong` masks only the strong) masked in what the cut PUBLISHES -- matched whole-word,", " without case, through look-alike letters and a word spelt out. visual: placeholder (default: a dark pill with", " its mask, \"f*****\") or blackout (the redaction's bar); voice: beep (default: said, a tone over it by the take's", " word timings), skip (left out of a synthesized read) or placeholder (its stand-in said, \"f-slur\"). A take that SAYS one (a", " recording, a beep take, a take from before the filter) is silenced or beeped over it by its word timings, and", " a censored build refuses one with none. `ls` counts what the cut would mask (masks only, never the word), per", " slur and per post, and says which reads still need word timings. off -- or `umtool take … --uncensored` -- is", " the uncensored cut; the redaction and censored attachments stay on. add/except/remove: the project's own words.", " edges : that slur (its word, id or any form names it) EDGE-masked -- every form its first letter, stars and", " its LAST letter, in the case written (\"n***a\", \"f****t\": the form is told apart); --off back to the first letter.", ].join("\n"); export class SlursError extends Error { constructor(message) { super(message); this.name = "SlursError"; } } const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v); const lc = (v) => String(v ?? "").trim().toLowerCase(); /** The slur an edge names (a listed slur's id, word or form, or the project's own word), or null. */ function edgeEntryOf(name, cfg) { const w = lc(name); const listed = (defaultSlurList()?.entries ?? []).find((e) => e.id === w || e.word === w || (e.forms ?? []).includes(w)); if (listed) return listed; const own = (Array.isArray(cfg?.add) ? cfg.add : []).find((a) => [lc(typeof a === "string" ? a : a?.word), ...(Array.isArray(a?.forms) ? a.forms.map(lc) : [])].includes(w)); return own ? { forms: [lc(typeof own === "string" ? own : own.word), ...(Array.isArray(own?.forms) ? own.forms.map(lc) : [])] } : null; } /** An edge as shown (never the word): a slur's id as it is, else the word's edge mask. */ export const edgeShown = (name, cfg) => { const w = lc(name); const e = edgeEntryOf(w, cfg); return e?.id === w ? w : edgeMask(e ?? { forms: [w] }, w); }; /** What a cut's filter would mask, and the state of each read that holds a slur. */ export function slursListing(manifest) { const s = cutSlurs(manifest); const on = { ...s, on: true }; const tl = Array.isArray(manifest?.timeline) ? manifest.timeline : []; const report = slurReport(tl, s); const reads = []; for (const e of tl) { if (e?.type !== "post" || !isNarrated(e)) continue; const t = pickedTake(e); const root = rootTakeOf(e.narration.takes ?? [], t); const state = t.slurs ?? root?.slurs ?? "said"; const b = takeBleeps(t, on, { state, script: t.script ?? e.narration?.script }); if (state !== "said") { if (reportHas(report, e.id, "script")) reads.push({ id: e.id, take: t.file, state, covered: "left out of the read" }); continue; } if (!b) continue; reads.push({ id: e.id, take: t.file, state, ...(b.error ? { needs: "word timings", error: b.error } : { covered: b.mode === "beep" ? "beeped" : "silenced", spans: b.spans.length }) }); } return { slurs: s, report, reads }; } const reportHas = (report, id, where) => report.posts.some((p) => p.id === id && p.where.includes(where)); /** `umtool posts slurs

…` */ export async function slursCommand(project, rest, { json = false, off = false, out = (s) => console.log(s) } = {}) { const [sub = "ls", arg] = rest; const write = async (change) => withEditNotes(project, async () => updatePostSlurs(project.dir, change, { token: await manifestToken(project.dir) })); const said = async (change, line) => { const { result } = await write(change); // The edges by their masks (edgeShown): a write's JSON never prints a slur it edged. const shown = Array.isArray(result.slurs?.edges) ? { ...result.slurs, edges: result.slurs.edges.map((w) => edgeShown(w, result.slurs)) } : result.slurs; out(json ? JSON.stringify({ ok: true, slurs: shown, token: result.token }, null, 2) : `${project.id}: ${line}`); return 0; }; const one = (list, what) => { if (!arg || !list.includes(arg)) throw new SlursError(`posts slurs ${sub} takes ${list.join(" or ")}${arg ? ` (not ${arg})` : ""}`); return arg; }; if (sub === "on") return said({ set: { on: null } }, "the slur filter is on (the default): the cut publishes its post items censored"); if (sub === "off") return said({ set: { on: false } }, "the slur filter is OFF: this is the uncensored cut (the redaction and censored attachments stay on)"); if (sub === "level") return said({ set: { level: one(SLUR_LEVELS) === SLURS_DEFAULTS.level ? null : arg } }, `level ${arg}: ${arg === "strong" ? "only the strong slurs are masked" : "strong and mild slurs are masked"}`); if (sub === "visual") return said({ set: { visual: one(SLUR_VISUALS) === SLURS_DEFAULTS.visual ? null : arg } }, `visual ${arg}: ${arg === "blackout" ? "a solid bar, as a redacted word" : "a dark pill with the masked form"}`); if (sub === "voice") return said({ set: { voice: one(SLUR_VOICES) === SLURS_DEFAULTS.voice ? null : arg } }, `voice ${arg}: ${arg === "skip" ? "left out of a synthesized read" : arg === "beep" ? "said, with a beep over it (the take's word timings)" : "its stand-in said in its place"}`); if (sub === "add" || sub === "except" || sub === "remove") { if (!arg || !/^[A-Za-z][A-Za-z-]{1,39}$/.test(arg)) throw new SlursError(`posts slurs ${sub} takes a word (letters, 2–40)`); const what = sub === "add" ? "masked in this cut" : sub === "except" ? "never masked in this cut" : "off the project's lists"; return said({ [sub]: arg }, `${maskOfOwnWord(arg)} is ${what}`); } if (sub === "edges") { if (!arg || !/^[A-Za-z][A-Za-z-]{1,39}$/.test(arg)) throw new SlursError("posts slurs edges takes a word, a slur's id or one of its forms (letters, 2–40)"); const m = await readManifest(project.dir); if (!m) throw new SlursError(`${project.id} has no manifest`); const cfg = isObj(m.render?.posts?.slurs) ? m.render.posts.slurs : {}; if (!off && !edgeEntryOf(arg, cfg)) throw new SlursError(`posts slurs edges: ${maskOfOwnWord(arg)} names no slur on the list or of the project's own (add it first)`); const shown = edgeShown(arg, cfg); return said(off ? { unedge: arg } : { edge: arg }, off ? `${shown}: back to the first-letter mask` : `${shown}: edge-masked -- every form its first letter, stars and its last letter, in the case written`); } if (sub !== "ls") throw new SlursError(`posts slurs: ls, on, off, level, visual, voice, add, except, remove or edges (not ${sub})`); const manifest = await readManifest(project.dir); if (!manifest) throw new SlursError(`${project.id} has no manifest`); const { slurs: s, report, reads } = slursListing(manifest); const cfg = isObj(manifest.render?.posts?.slurs) ? manifest.render.posts.slurs : {}; if (json) { out(JSON.stringify({ ok: true, on: s.on, level: s.level, visual: s.visual, voice: s.voice, listed: s.entries.length, add: (cfg.add ?? []).length, except: (cfg.except ?? []).length, edges: (cfg.edges ?? []).map((w) => edgeShown(w, cfg)), total: report.total, bySlur: report.bySlur, posts: report.posts, reads }, null, 2)); return 0; } out( `${project.id}: the slur filter is ${s.on ? "ON" : "OFF (the uncensored cut)"} -- level ${s.level}, visual ${s.visual}, voice ${s.voice}` + ` (${s.entries.length} slur(s) listed${cfg.add?.length ? `, ${cfg.add.length} of its own` : ""}${cfg.except?.length ? `, ${cfg.except.length} excepted` : ""})`, ); if (cfg.edges?.length) out(` edges: ${cfg.edges.map((w) => edgeShown(w, cfg)).join(", ")} (first letter, stars, last letter)`); if (!report.total) { out(" no post item of the cut holds a slur on the list"); return 0; } out(` it ${s.on ? "masks" : "would mask"} ${report.total} word(s) in ${report.posts.length} post item(s):`); const rows = Object.entries(report.bySlur).sort((a, b) => b[1].n - a[1].n); // A project's own word is named by its mask alone (its id would spell it). for (const [id, b] of rows) out(` ${b.mask.padEnd(10)} ${(b.added ? "(its own)" : id).padEnd(18)} ×${String(b.n).padEnd(4)} in ${b.posts.length} post(s): ${b.posts.slice(0, 8).join(", ")}${b.posts.length > 8 ? ", …" : ""}`); out(" per post item:"); for (const p of report.posts) out(` ${p.id.padEnd(22)} ${Object.entries(p.hits).map(([id, n]) => `${report.bySlur[id]?.mask ?? id} ×${n}`).join(", ")} (${p.where.join(", ")})`); if (reads.length) { const need = reads.filter((r) => r.needs); out(` the reads: ${reads.length} narrated post(s) hold a slur in their read -- ${reads.filter((r) => r.covered).length} covered, ${need.length} need word timings`); for (const r of reads) out(` ${r.id.padEnd(22)} ${r.needs ? `NEEDS WORD TIMINGS (a censored build refuses it): umtool posts narrate ${project.id} ${r.id} --words` : `${r.covered}${r.spans ? ` (${r.spans} span(s))` : ""}`}`); } return 0; }