Archilyzer · Source

archilyzer

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

commit 21d1a980fb3712b3e16368ea862730d48ae8227c
parent 9226e550da217e360210354bbd0be148e1257032
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  2 Nov 2026 04:47:01 -0500

research cases: a possessive never slips a private name past the gate or a redaction

privateNameCandidates kept the apostrophe, so "Jane's" hashed as "jane's" and a case's private name
written as a possessive passed the gate. A phrase whose last word is a possessive is now also
hashed without the "'s" (unpossessive); redactPrivateNames withholds the name and keeps its "'s".

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

Diffstat:
Mcommon/lib/research/caseTypes.test.ts | 4++++
Mcommon/lib/research/caseTypes.ts | 15+++++++++++++--
Mcommon/lib/research/privateNames-server.ts | 19+++++++++++++------
3 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/common/lib/research/caseTypes.test.ts b/common/lib/research/caseTypes.test.ts @@ -151,4 +151,8 @@ test("lane C: the evidence labels, the excluded sentence the editor says, and a 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 }); + // A possessive does not slip a name past the gate, nor past a redaction. + assert.equal(privateNameHits("ask QuietHandle’s friend", [privateNameHash("quiethandle")]), 1); + assert.equal(privateNameHits("Jane Q Private's post", hashes), 1); + assert.equal(redactPrivateNames("found QuietHandle's account", [privateNameHash("quiethandle")]).text, "found [name withheld]'s account"); }); diff --git a/common/lib/research/caseTypes.ts b/common/lib/research/caseTypes.ts @@ -347,14 +347,25 @@ export const isRelevance = (value: unknown): value is Relevance => value === 1 | /** A term's words NFKC-normalised, lowercased and single-spaced: what privateNameHash hashes. */ export const normalizeTerm = (s: string) => s.normalize("NFKC").toLowerCase().trim().split(/\s+/u).join(" "); -/** What the gate hashes: every word of `text` and every 2- and 3-word phrase, each normalizeTerm'd. */ +/** A possessive's name: "jane's" → "jane" (lane C: a possessive must not slip a name past the gate). */ +export const unpossessive = (word: string) => word.replace(/['’]s$/u, ""); + +/** + * What the gate hashes: every word of `text` and every 2- and 3-word phrase, each normalizeTerm'd -- and, when a + * phrase's last word is a possessive ("jane's"), the phrase without the "'s" as well. + */ export function privateNameCandidates(text: string): string[] { const words = normalizeTerm(text.replace(/[^\p{L}\p{N}'’\-\s]/gu, " ")) .split(" ") .filter(Boolean); const out = new Set<string>(); for (let i = 0; i < words.length; i++) { - for (let n = 1; n <= 3 && i + n <= words.length; n++) out.add(words.slice(i, i + n).join(" ")); + for (let n = 1; n <= 3 && i + n <= words.length; n++) { + const phrase = words.slice(i, i + n); + out.add(phrase.join(" ")); + const last = unpossessive(phrase[n - 1]); + if (last && last !== phrase[n - 1]) out.add([...phrase.slice(0, -1), last].join(" ")); + } } return [...out]; } 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 { NAME_WITHHELD, normalizeTerm, privateNameCandidates } from "./caseTypes"; +import { NAME_WITHHELD, normalizeTerm, privateNameCandidates, unpossessive } from "./caseTypes"; /** A term's stored form: sha256 of normalizeTerm(term), lowercase hex. */ export function privateNameHash(term: string): string { @@ -29,15 +29,22 @@ export function redactPrivateNames(text: string, hashes: readonly string[]): { t 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; + let keep = 0; + for (let n = Math.min(3, words.length - i); n >= 1 && !took; n--) { + const phrase = words.slice(i, i + n).map((x) => x.w); + if (set.has(privateNameHash(phrase.join(" ")))) took = n; + else { + // A possessive: the name is withheld, its "'s" kept. + const bare = unpossessive(phrase[n - 1]); + if (bare !== phrase[n - 1] && set.has(privateNameHash([...phrase.slice(0, -1), bare].join(" ")))) { + took = n; + keep = phrase[n - 1].length - bare.length; + } } } if (took) { out += text.slice(last, words[i].start) + NAME_WITHHELD; - last = words[i + took - 1].end; + last = words[i + took - 1].end - keep; hits++; i += took; } else i++;