// `transcripts/mirrors/.json` — a mirror scan's result (release 31, // lane D; written by controller/mirrorScan.ts, read by the editor's Mirror // stage and the MCP's `copies`). PRIVATE: corpus-side only, never published — // nothing in the export build reads `transcripts/mirrors/`. // // Shape: `{format: "archilyzer-mirror-scan", version: 1, mirror, of, missing?, // generatedAt, jobId?, rules, window, platforms, totals, videos, removed}` — // `videos`, `removed` and `totals` are lib/mirrors/match.ts's. // // Pure, client-safe (types and the copies index). import { MIRROR_DAYS_AFTER, MIRROR_DAYS_BEFORE, MIRROR_DURATION_TOLERANCE, MIRROR_LIVE_MIN_SECONDS, MIRROR_STRONG_DURATION_TITLE_JACCARD, MIRROR_STRONG_TITLE_JACCARD, MIRROR_TITLE_JACCARD, MIRROR_WEAK_TITLE_JACCARD, type MirrorMatchResult, type MirrorStatus, } from "./match"; export const MIRROR_SCAN_FORMAT = "archilyzer-mirror-scan"; export const MIRROR_SCAN_VERSION = 1; export const MIRRORS_DIRNAME = "mirrors"; export type MirrorRules = { daysBefore: number; daysAfter: number; titleJaccard: number; weakTitleJaccard: number; durationTolerance: number; liveMinSeconds: number; strongTitleJaccard: number; strongDurationTitleJaccard: number; }; export const MIRROR_RULES: MirrorRules = Object.freeze({ daysBefore: MIRROR_DAYS_BEFORE, daysAfter: MIRROR_DAYS_AFTER, titleJaccard: MIRROR_TITLE_JACCARD, weakTitleJaccard: MIRROR_WEAK_TITLE_JACCARD, durationTolerance: MIRROR_DURATION_TOLERANCE, liveMinSeconds: MIRROR_LIVE_MIN_SECONDS, strongTitleJaccard: MIRROR_STRONG_TITLE_JACCARD, strongDurationTitleJaccard: MIRROR_STRONG_DURATION_TITLE_JACCARD, }); export type MirrorScanFile = MirrorMatchResult & { format: typeof MIRROR_SCAN_FORMAT; version: typeof MIRROR_SCAN_VERSION; // The mirror channel's slug. mirror: string; // Its `mirror.of` at the scan, and those of them not found in the corpus. of: string[]; missing?: string[]; generatedAt: string; jobId?: string; rules: MirrorRules; }; export function isMirrorScanFile(v: unknown): v is MirrorScanFile { const f = v as Partial | null; return ( !!f && typeof f === "object" && f.format === MIRROR_SCAN_FORMAT && f.version === MIRROR_SCAN_VERSION && typeof f.mirror === "string" && Array.isArray(f.videos) && Array.isArray(f.removed) && !!f.totals ); } // What the corpus knows about a video's copies, across every scan. export type VideoCopies = // A mirror's video: its status and its strong matches. | { role: "mirror"; mirror: string; status: MirrorStatus; matches: { channel: string; id: string; gone?: string }[] } // A creator's video a mirror holds (a strong match of a mirror video). | { role: "creator"; copies: { mirror: string; id: string }[]; gone?: string }; // `${channel}/${id}` → what the scans say about it. A video both a mirror's // and a creator's (a mirror of a mirror) keeps the mirror reading. export function copiesIndex(files: readonly MirrorScanFile[]): Map { const out = new Map(); for (const f of files) { for (const v of f.videos) { out.set(`${f.mirror}/${v.id}`, { role: "mirror", mirror: f.mirror, status: v.status, matches: v.matches.filter((m) => m.strong).map((m) => ({ channel: m.channel, id: m.id, ...(m.gone ? { gone: m.gone } : {}) })), }); } } for (const f of files) { for (const v of f.videos) { for (const m of v.matches) { if (!m.strong) continue; const key = `${m.channel}/${m.id}`; const prev = out.get(key); if (prev?.role === "mirror") continue; const copies = prev?.role === "creator" ? prev.copies : []; if (!copies.some((c) => c.mirror === f.mirror && c.id === v.id)) copies.push({ mirror: f.mirror, id: v.id }); out.set(key, { role: "creator", copies, ...(m.gone ? { gone: m.gone } : {}) }); } } } return out; }