// THE COPIES FILES of a source group (lane cross-source-dupes, slice 1). Pure: // the shapes and their guards; copies/file-server.ts reads and writes them. // // transcripts/copies/.json the scan's pairs, machine-written, // regenerated whole by each scan // transcripts/copies/.decisions.json a person's (or an agent's) word: // pairs confirmed or rejected, // videos released — written only // by copies-confirm, copies-reject // and copies-release, never by // the scan // // PRIVATE: nothing under transcripts/copies/ is read by the export build or // shipped to a site. Deleting the scan file restores today's lane behaviour; // the decisions only ever act on pairs the scan lists. import type { CopyLink, TextEvidence } from "./match"; import type { ChannelDating, DateFrom } from "./dating"; export const COPIES_DIRNAME = "copies"; export const COPIES_FORMAT = "archilyzer-copies"; export const COPIES_VERSION = 1; export const COPIES_DECISIONS_FORMAT = "archilyzer-copies-decisions"; export type CopyMember = { channel: string; dir: string; id: string; title: string; duration: number; date: string | null; // Where `date` came from: the channel's rule, the live stream's own day, a // date the titles carry, or the upload (lib/copies/dating.ts). dateFrom?: DateFrom | null; }; export type CopyPairRecord = { // `/|/`: a is the more preferred side. key: string; a: CopyMember; b: CopyMember; link: CopyLink; // On a part-of pair: which member is the part (inside the other). part?: "a" | "b"; // Both members on one channel: report only, the lanes never act on it. withinChannel: boolean; evidence: { // What decided the link: the words, or (no text on one side) metadata. kind: "text" | "metadata"; // How the pair was proposed: dated within the window, or by runtime (one // side had no date to go by; such a pair is always decided by its words). via?: "date" | "runtime"; // null: one side is undated. dateDeltaDays: number | null; durationOk: boolean; text?: TextEvidence; }; // When a scan first recorded this pair (ISO-8601), carried across scans: // a held copy's wait is counted from here (not from when a lane first held // it), so a pair older than its group's wait never holds; re-ordering the // group flips a and b, which is a new key and a new wait. firstSeenAt: string; }; export type CopiesTotals = { videos: Record; undated: number; candidates: number; confirmed: number; metadata: number; partOf: number; overlaps: number; // Candidates the words said were different recordings. rejected: number; withinChannel: number; // The runtime search (lib/copies/match.ts runtimeCandidates): videos // searched, the candidates it proposed, those the words rejected, and the // videos left unsearched by its cap. The date stage's figures above do not // include them. runtime?: { searched: number; candidates: number; rejected: number; capped: number }; }; export type CopiesFile = { format: typeof COPIES_FORMAT; version: typeof COPIES_VERSION; group: string; channels: string[]; // Members this corpus does not hold, skipped by the scan. missing?: string[]; generatedAt: string; jobId?: string; rules: { dateWindowDays: number; durationToleranceSeconds: number; durationToleranceRatio: number; withinChannels: boolean; }; pairs: CopyPairRecord[]; totals: CopiesTotals; // How each member's videos were dated, by channel. dating?: Record; // What the scan says about its own inputs: a channel lacking its // recorded-date rule (with the exact patch), videos it could date only by // their upload, a scan whose members' dates never meet. advice?: string[]; }; // Who gave a decision: the caller's word, as judge-trending takes it (the // route cannot tell who is asking). export type CopyDecisionBy = "operator" | "agent"; export type CopyDecision = { at: string; by: CopyDecisionBy; note?: string }; export type CopiesDecisionsFile = { format: typeof COPIES_DECISIONS_FORMAT; version: typeof COPIES_VERSION; group: string; // `/` → released: the lanes treat that video as they did // before the group existed. released: Record; // Pair key → a metadata-only pair a person says IS the same recording: the // lanes treat it as text-confirmed. confirmed: Record; // Pair key → a pair a person says is NOT: the lanes never act on it again. rejected: Record; }; export function copyVideoKey(channel: string, dir: string): string { return `${channel}/${dir}`; } export function copyPairKey(a: Pick, b: Pick): string { return `${copyVideoKey(a.channel, a.dir)}|${copyVideoKey(b.channel, b.dir)}`; } export function isCopiesFile(v: unknown): v is CopiesFile { if (!v || typeof v !== "object") return false; const f = v as Partial; return f.format === COPIES_FORMAT && f.version === COPIES_VERSION && typeof f.group === "string" && Array.isArray(f.pairs); } export function isCopiesDecisionsFile(v: unknown): v is CopiesDecisionsFile { if (!v || typeof v !== "object") return false; const f = v as Partial; const isMap = (m: unknown) => !!m && typeof m === "object" && !Array.isArray(m); return ( f.format === COPIES_DECISIONS_FORMAT && f.version === COPIES_VERSION && typeof f.group === "string" && isMap(f.released) && isMap(f.confirmed) && isMap(f.rejected) ); } // A member named `/` or `/`: a Rumble video's dir // (the URL slug, what the lanes' pending lists and units carry) is not its // id (the embed id the cues and the index carry), and a person may give // either. Both resolve to the member's DIR key, which is what pairs are kept // under. function memberMatches(m: CopyMember, ref: string): boolean { const slash = ref.indexOf("/"); if (slash <= 0) return false; const channel = ref.slice(0, slash); const name = ref.slice(slash + 1); return m.channel === channel && (m.dir === name || m.id === name); } /** The `/` key of a video the scan lists, named by dir or by id; null when it lists none. */ export function resolveCopyVideoRef(file: Pick | null, ref: string): string | null { for (const p of file?.pairs ?? []) { for (const m of [p.a, p.b]) if (memberMatches(m, ref)) return copyVideoKey(m.channel, m.dir); } return null; } /** * The pair a reference names: its key as the report prints it, or * `/|/` in either order. Null when the * scan lists no such pair. */ export function resolveCopyPairRef(file: Pick | null, ref: string): CopyPairRecord | null { const bar = ref.indexOf("|"); if (bar <= 0) return null; const x = ref.slice(0, bar); const y = ref.slice(bar + 1); for (const p of file?.pairs ?? []) { if (p.key === ref) return p; if ((memberMatches(p.a, x) && memberMatches(p.b, y)) || (memberMatches(p.a, y) && memberMatches(p.b, x))) return p; } return null; }