Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 9226e550da217e360210354bbd0be148e1257032
parent 51c23fc9fcee8d756086eaea4c2629d17b4330b0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  2 Nov 2026 04:26:09 -0500

research cases: lane C's contract additions -- evidence.json, the audio check, the labels, a redaction, the word diff

caseTypes.ts gains what stages 7 and 10 need and lane 0 left open: CASE_FILES.evidence and the
CaseEvidence row (wayback | forum-attachment; planned/queued/captured/excluded/failed), the audio
check kept on a finding's verify (AudioCheck), FindingEvidence's evidence id and post position,
EXCLUDED_SENTENCE (kept equal to the editor's WAYBACK_EXCLUDED_PHRASE by a test) and
forumAttachmentLabel/evidenceLabel, so every surface says "forum attachment, post #N, unverified" the
same way. privateNames-server.ts gains redactPrivateNames (a snippet or a transcript shown on the case
page, a name replaced by [name withheld], matched as the gate matches). wordDiff.ts: a quote's words
aligned with what was heard (LCS), client-safe.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/lib/research/caseTypes.test.ts | 22++++++++++++++++++++++
Mcommon/lib/research/caseTypes.ts | 92++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mcommon/lib/research/privateNames-server.ts | 32+++++++++++++++++++++++++++++++-
Acommon/lib/research/wordDiff.test.ts | 32++++++++++++++++++++++++++++++++
Acommon/lib/research/wordDiff.ts | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 239 insertions(+), 2 deletions(-)

diff --git a/common/lib/research/caseTypes.test.ts b/common/lib/research/caseTypes.test.ts @@ -130,3 +130,25 @@ test("private names: stored as hashes, matched on words and 2–3-word phrases, assert.equal(privateNameHits("then Jane posted it", definition.privateNames.sha256), 0); assert.equal(privateNameHits("anything", []), 0); }); + +test("lane C: the evidence labels, the excluded sentence the editor says, and a redaction that never names", async () => { + const { EXCLUDED_SENTENCE, evidenceLabel, forumAttachmentLabel, isEvidenceKind, isEvidenceState } = await import("./caseTypes"); + const { WAYBACK_EXCLUDED_PHRASE } = await import("../waybackClient"); + const { redactPrivateNames } = await import("./privateNames-server"); + assert.equal(EXCLUDED_SENTENCE, WAYBACK_EXCLUDED_PHRASE, "one sentence in every surface"); + assert.equal(forumAttachmentLabel(14, "880011"), "forum attachment, post #14, unverified"); + assert.equal(forumAttachmentLabel(undefined, "880011"), "forum attachment, post #880011, unverified"); + assert.equal(evidenceLabel({ kind: "forum-attachment", position: 3 }), "forum attachment, post #3, unverified"); + assert.equal(evidenceLabel({ kind: "wayback", state: "excluded" }), EXCLUDED_SENTENCE); + assert.equal(evidenceLabel({ kind: "wayback", captureTs: "20140304120000" }), "Wayback capture, 2014-03-04"); + assert.ok(isEvidenceKind("wayback") && isEvidenceState("excluded")); + assert.equal(isEvidenceState("done"), false); + + const hashes = definition.privateNames.sha256; + const r = redactPrivateNames("then Jane Q Private posted it, and @jane posted too", hashes); + assert.equal(r.text, "then [name withheld] posted it, and @jane posted too"); + assert.equal(r.hits, 1); + const handle = redactPrivateNames("see x.com/QuietHandle for more", [privateNameHash("quiethandle")]); + assert.equal(handle.text, "see x.com/[name withheld] for more"); + assert.deepEqual(redactPrivateNames("nothing here", []), { text: "nothing here", hits: 0 }); +}); diff --git a/common/lib/research/caseTypes.ts b/common/lib/research/caseTypes.ts @@ -16,6 +16,7 @@ // <case>/findings.jsonl FindingRow, one per line, appended (stage 4; verify and merge rewrite whole) // <case>/leads.json CaseLead[] (stage 8) // <case>/date-checks.json DateCheck[] (stage 9) +// <case>/evidence.json CaseEvidence[] (stage 10; lane C's extension) // // PRIVATE NAMES ARE NEVER TEXT. A case's private terms are stored as `privateNames.sha256` (privateNameHash of // each term, privateNames-server.ts), so no file holds them. The gate hashes every word and every 2- and 3-word phrase of what it checks @@ -33,6 +34,7 @@ export const CASE_FILES = Object.freeze({ findings: "findings.jsonl", leads: "leads.json", dateChecks: "date-checks.json", + evidence: "evidence.json", } as const); /** A batch file's longest line. A reader's file tool truncates long lines and drops the densest windows silently. */ @@ -181,10 +183,34 @@ export type FindingVerify = { note?: string; /** "Corrected by hand" keeps what the reader wrote. */ original?: { quote: string; speaker?: string }; + /** Lane C: the last audio check -- the window transcribed through the editor and its words diffed with the quote. */ + audio?: AudioCheck; +}; + +/** An audio check's outcome: what the worker heard, and how much of the quote it holds. */ +export type AudioCheck = { + at: string; + /** The editor's transcribe-file job. */ + job: string; + /** The window's transcript (private names already NAME_WITHHELD). */ + text: string; + /** The quote's words found in order in the transcript, of all its words. */ + matched: number; + words: number; + /** The worker that heard it, as the editor names it. */ + worker?: string; }; /** A forum post's attachment or screenshot, shown everywhere as "forum attachment, post #N, unverified". */ -export type FindingEvidence = { kind: "forum-attachment" | "wayback"; post?: string; url: string; capturedAt?: string }; +export type FindingEvidence = { + kind: "forum-attachment" | "wayback"; + post?: string; + url: string; + capturedAt?: string; + /** Lane C: the CaseEvidence row it came from, and a forum post's position in its thread (the "#N"). */ + evidence?: string; + position?: number; +}; export type FindingRow = { /** `f<n>`: unique in the case, never reused. */ @@ -230,6 +256,68 @@ export type CaseLead = { channel?: string; }; +// --------------------------------------------------------------------------------------------------------------- +// Stage 10: evidence capture (lane C's extension: the contract named FindingEvidence but no file for the captures) + +/** Wayback captures at chosen dates; a forum post's attachments or screenshot. */ +export const EVIDENCE_KINDS = ["wayback", "forum-attachment"] as const; +export type EvidenceKind = (typeof EVIDENCE_KINDS)[number]; + +/** + * planned: not asked yet. queued: the editor's job is running. captured: held. excluded: the Wayback Machine answered + * 403 for the URL (EXCLUDED_SENTENCE). failed: the job or the editor said no (its words in `message`). + */ +export const EVIDENCE_STATES = ["planned", "queued", "captured", "excluded", "failed"] as const; +export type EvidenceState = (typeof EVIDENCE_STATES)[number]; + +export type CaseEvidence = { + /** `e<n>`: unique in the case, never reused. */ + id: string; + kind: EvidenceKind; + /** wayback: the page's own URL. forum-attachment: the post's permalink. */ + url: string; + /** wayback: the date chosen, YYYYMMDD (the capture nearest it). */ + at?: string; + /** The channel it went into (a Wayback pages channel), or the forum channel the post is in. */ + slug?: string; + /** forum-attachment: the post's id, and its "#N" in the thread when the forum gives one. */ + post?: string; + position?: number; + state: EvidenceState; + /** The editor's job (import-page, capture-posts). */ + job?: string; + /** wayback: the capture landed on, and the records it made. */ + captureTs?: string; + records?: string[]; + /** forum-attachment: the files captured, relative to the channel's posts-media/<post>/. */ + files?: string[]; + /** The refusal's code ("excluded", …) and the sentence shown for it. */ + refusal?: string; + message?: string; + /** The finding rows it is evidence for. */ + findings?: string[]; + note?: string; + createdAt: string; + updatedAt: string; +}; + +/** What a Wayback 403 means, in every surface (the editor's WAYBACK_EXCLUDED_PHRASE; a test keeps them equal). */ +export const EXCLUDED_SENTENCE = "excluded from the Wayback Machine (cause unknown)"; + +/** A forum attachment's label, in every surface: never shown as anything but unverified. */ +export function forumAttachmentLabel(position?: number | null, post?: string | null): string { + const n = typeof position === "number" && position > 0 ? String(position) : post ? post : "?"; + return `forum attachment, post #${n}, unverified`; +} + +/** The label a finding's evidence or an evidence row carries. */ +export function evidenceLabel(e: { kind: EvidenceKind; position?: number; post?: string; capturedAt?: string; captureTs?: string; state?: EvidenceState }): string { + if (e.kind === "forum-attachment") return forumAttachmentLabel(e.position, e.post); + if (e.state === "excluded") return EXCLUDED_SENTENCE; + const ts = e.captureTs ?? e.capturedAt; + return ts && /^\d{8}/.test(ts) ? `Wayback capture, ${ts.slice(0, 4)}-${ts.slice(4, 6)}-${ts.slice(6, 8)}` : "Wayback capture"; +} + export type DateCheck = { /** The key date checked, YYYY-MM-DD. */ date: string; @@ -249,6 +337,8 @@ const isOneOf = typeof value === "string" && (list as readonly string[]).includes(value); export const isVerifyStatus = isOneOf(VERIFY_STATUSES); +export const isEvidenceKind = isOneOf(EVIDENCE_KINDS); +export const isEvidenceState = isOneOf(EVIDENCE_STATES); export const isLeadDisposition = isOneOf(LEAD_DISPOSITIONS); export const isFindingBy = isOneOf(FINDING_BY); export const isCaseStatus = isOneOf(CASE_STATUSES); diff --git a/common/lib/research/privateNames-server.ts b/common/lib/research/privateNames-server.ts @@ -1,7 +1,7 @@ // A case's private names as stored (lib/research/caseTypes.ts, "PRIVATE NAMES ARE NEVER TEXT"): the sha256 of each // term, never the term. The gate hashes privateNameCandidates of what it checks and compares. import { createHash } from "node:crypto"; -import { normalizeTerm, privateNameCandidates } from "./caseTypes"; +import { NAME_WITHHELD, normalizeTerm, privateNameCandidates } from "./caseTypes"; /** A term's stored form: sha256 of normalizeTerm(term), lowercase hex. */ export function privateNameHash(term: string): string { @@ -14,3 +14,33 @@ export function privateNameHits(text: string, hashes: readonly string[]): number const set = new Set(hashes); return privateNameCandidates(text).filter((c) => set.has(privateNameHash(c))).length; } + +/** + * `text` with every word or 2–3-word phrase that hashes to one of `hashes` replaced by NAME_WITHHELD (lane C: a + * lead's context snippet, an audio check's transcript -- text from the corpus shown on the case page). The longest + * phrase wins; the words are matched as privateNameCandidates splits them. + */ +export function redactPrivateNames(text: string, hashes: readonly string[]): { text: string; hits: number } { + if (!hashes.length || !text) return { text, hits: 0 }; + const set = new Set(hashes); + const words = [...text.matchAll(/[\p{L}\p{N}'’\-]+/gu)].map((m) => ({ w: m[0], start: m.index ?? 0, end: (m.index ?? 0) + m[0].length })); + let out = ""; + let last = 0; + let hits = 0; + for (let i = 0; i < words.length; ) { + let took = 0; + for (let n = Math.min(3, words.length - i); n >= 1; n--) { + if (set.has(privateNameHash(words.slice(i, i + n).map((x) => x.w).join(" ")))) { + took = n; + break; + } + } + if (took) { + out += text.slice(last, words[i].start) + NAME_WITHHELD; + last = words[i + took - 1].end; + hits++; + i += took; + } else i++; + } + return { text: out + text.slice(last), hits }; +} diff --git a/common/lib/research/wordDiff.test.ts b/common/lib/research/wordDiff.test.ts @@ -0,0 +1,32 @@ +// Release 38 lane C: the audio check's word diff -- the quote's words aligned with what the worker heard. +// +// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/research/wordDiff.test.ts +import test from "node:test"; +import assert from "node:assert/strict"; +import { heardShare, quoteWordDiff } from "./wordDiff"; + +test("a quote heard whole: every word the same, the window's other words left out", () => { + const d = quoteWordDiff("the lighthouse keeper called in", "okay so the lighthouse keeper called in last night"); + assert.equal(d.matched, 5); + assert.equal(d.words, 5); + assert.deepEqual(d.ops.map((o) => o.op), ["same", "same", "same", "same", "same"]); + assert.equal(heardShare(d), 1); +}); + +test("a quote the captions rewrote: the missing and the extra words, in place", () => { + const d = quoteWordDiff("the lighthouse keeper rang in", "and then the lighthouse keeper called in again"); + assert.equal(d.matched, 4); + assert.deepEqual( + d.ops.map((o) => `${o.op[0]}:${o.word}`), + ["s:the", "s:lighthouse", "s:keeper", "m:rang", "e:called", "s:in"], + ); +}); + +test("punctuation and case do not count; nothing heard is all missing", () => { + assert.equal(quoteWordDiff("How much was it? You cut it all,", "how much was it you cut it all").matched, 8); + const none = quoteWordDiff("not said at all", ""); + assert.equal(none.matched, 0); + assert.deepEqual(none.ops.map((o) => o.op), ["missing", "missing", "missing", "missing"]); + assert.equal(quoteWordDiff("", "words").words, 0); + assert.equal(quoteWordDiff("alpha beta", "gamma delta").matched, 0); +}); diff --git a/common/lib/research/wordDiff.ts b/common/lib/research/wordDiff.ts @@ -0,0 +1,63 @@ +// A finding's quote against what was heard (release 38 lane C, stage 7's audio check): the quote's words aligned with +// a transcript's (a window transcribed through the editor, or another caption track) by longest common subsequence. +// Pure and client-safe: the case page draws the diff, the MCP's case_verify can say the same numbers. +import { wordsOf } from "../report/quoteWords"; + +export type WordOp = { op: "same" | "missing" | "extra"; word: string }; + +export type WordDiff = { + /** The quote's words found in order in the transcript. */ + matched: number; + /** The quote's words. */ + words: number; + /** + * The alignment over the stretch of the transcript the quote matched: `missing` is a quote word the transcript does + * not have there, `extra` a transcript word the quote does not have. Transcript words before the first match and + * after the last are left out (the window is wider than the quote). + */ + ops: WordOp[]; +}; + +const split = (s: string) => wordsOf(s).split(" ").filter(Boolean); + +/** How much of `quote` the `heard` text holds, in order, and where they differ. */ +export function quoteWordDiff(quote: string, heard: string): WordDiff { + const q = split(quote); + const h = split(heard); + const n = q.length; + const m = h.length; + if (n === 0) return { matched: 0, words: 0, ops: [] }; + if (m === 0) return { matched: 0, words: n, ops: q.map((word) => ({ op: "missing", word })) }; + // lcs[i][j]: the LCS of q[i..] and h[j..]. + const lcs: number[][] = Array.from({ length: n + 1 }, () => new Array<number>(m + 1).fill(0)); + for (let i = n - 1; i >= 0; i--) { + for (let j = m - 1; j >= 0; j--) { + lcs[i][j] = q[i] === h[j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]); + } + } + const ops: WordOp[] = []; + let i = 0; + let j = 0; + while (i < n && j < m) { + if (q[i] === h[j]) { + ops.push({ op: "same", word: q[i] }); + i++; + j++; + } else if (lcs[i + 1][j] >= lcs[i][j + 1]) { + ops.push({ op: "missing", word: q[i++] }); + } else { + ops.push({ op: "extra", word: h[j++] }); + } + } + while (i < n) ops.push({ op: "missing", word: q[i++] }); + // Trim the transcript's words outside the matched stretch. + const firstSame = ops.findIndex((o) => o.op === "same"); + if (firstSame < 0) return { matched: 0, words: n, ops: q.map((word) => ({ op: "missing", word })) }; + let lastSame = ops.length - 1; + while (lastSame > 0 && ops[lastSame].op !== "same") lastSame--; + const trimmed = ops.filter((o, k) => o.op !== "extra" || (k > firstSame && k < lastSame)); + return { matched: lcs[0][0], words: n, ops: trimmed }; +} + +/** The share of the quote heard, 0–1. */ +export const heardShare = (d: Pick<WordDiff, "matched" | "words">): number => (d.words ? d.matched / d.words : 0);