citations: one shared in-text detector in citationKey.ts

↗ view on GitHub · Eli Ziff · 2026-07-30 · ebe0be43

Retires the recorded debt. `CITATION_IN_QUERY` in a2ajPassageSearch was a
bespoke in-consumer regex for spotting citation-shaped substrings of a
free-text query. The inventory found a real detector already in the tree:
citatorExcerpts' CITE_TOKEN, calibrated on 3,000 random citator edges and
a strict superset of CITATION_IN_QUERY (same neutral / [year]-reporter /
CanLII alternatives, plus volume-reporter-page and "(1985), 48 C.R. (3d)
226" first-instance reporters).

So CITE_TOKEN is promoted, not the query regex: citationKey.ts - the pure,
db-free corpus-identity module - now also exports `citationsInText` (matched
substrings with offsets) and `hasCitationInText`. citatorExcerpts and
a2ajPassageSearch both consume it; CITE_TOKEN and CITATION_IN_QUERY are
gone. Detection is now superset-or-equal for the passage lane: more
citation shapes reach the citation_lookup short-circuit, and residualTokens
blanks them out of the bm25 side by span.

Deliberately not folded in, and now recorded as such: the neutral-citation
parsers in canliiUrls.buildCanliiCaseUrl and legalSourceLinks
.answerCaseCitations, which need year/court/number capture groups and the
wider court-slug charset the CanLII route table gates - a different
contract, and merging them would drop the 9-character and hyphenated
datasets that table carries.

citationKey.test.ts pins the scanner: neutral cites, the French twin
"2015 CSC 5", [year] reporter cites with periods, CanLII ids, verbatim
offsets, alternation order, plain text, and the two reporter shapes the
excerpt classifier depends on (regression pin). No model calls, no network,
no real databases.

npx vitest run over citationKey, citatorExcerpts, a2ajPassageSearch,
a2ajPassageWiring, retrievalGate, caselawCitator, legalSourceLinks:
7 files, 79 tests passed, existing tests unmodified. tsc --noEmit clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012AgUm5EcRKbT3duVFMbrQD
Repository eliziff/Beaver
Author Eli Ziff <eliasziff@gmail.com>
Authored
Parents d1014660
Stats 5 files changed , +181 , -40
Part of SourceDoc / DOCX engine: redlines, tracked changes, editing benchmark

Capture this commit into my fork

Download a Markdown prompt that tells Claude how to port this exact commit into your working tree. Run it via claude -p < capture-commit-ebe0be43.md from inside the repo you want the change in.

⬇ Download capture-commit-ebe0be43.md