import { readDefinition } from "yt-dlp-transcript-common/lib/research/caseStore-server"; import { PrivacyBlocked, privacyGate } from "yt-dlp-transcript-common/lib/research/casePrivacy-server"; import { REPORTS_ROOT } from "../paths.mjs"; import { caseDir } from "./cases.mjs"; import type { CaseDoc } from "./case-types"; // The board's own exits behind the case pipeline's privacy gate (plans/release-38/research-cases-and-assist.md, // stage 6): a board whose case has private names (pipeline.json `privateNames.sha256`) neither exports nor hands // off a quote, claim or note that names one. The refusal is counts and quote ids, never the name. In a module of // its own so boards.ts and handoff.ts can ask without importing the pipeline. /** The case's private-name hashes; none when it has no pipeline (or it cannot be read: the pipeline says why). */ export async function casePrivateHashes(id: string): Promise { try { return (await readDefinition(caseDir(REPORTS_ROOT, id), id))?.privateNames.sha256 ?? []; } catch { return []; } } /** The gate over a board's quotes (their words, claims and notes): null when clear, else the refusal. */ export async function boardGate(doc: Pick, what: string): Promise { const hashes = await casePrivateHashes(doc.id); if (!hashes.length) return null; const r = privacyGate( [{ id: "the case's notes", text: `${doc.title}\n${doc.notes}` }, ...doc.quotes.map((q) => ({ id: q.id, text: [q.text, q.claim, q.note].join("\n") }))], hashes, ); return r.blocked ? new PrivacyBlocked(what, r) : null; }