code wiki / (root) / nx_cite_lib.nx

nx_cite_lib.nx

buildroot/runtime/nx_cite_lib.nx

8020 B159 linesdepth 7pulls 12 transitivereach 4 importersview sourcekind librarytopic cite
docsdependenciesstructsconstsfunctions

about

nx_cite_lib.nx -- F993 CITE-OR-ABSTAIN: deterministic citation verification, the legal flagship. THE 2026 WALL (measured, not rhetorical): independent benchmarks show ~24% of graded legal answers cite or misapply law that does NOT support the claim, and every model tested fabricated at least one citation. The sovereign answer is not a better-behaved chatbot -- it is a VERIFIER that structurally cannot pass a citation whose quoted text is not BYTE-PRESENT in the cited source. No LLM sits in the trust path: a citation is verified by exact substring containment against a stored, content-addressed source, so a fabricated or subtly-altered quote is caught by construction. FAIL-CLOSED, three honest outcomes: CITED (1) the quote is an exact span of a real source -> show the source ABSTAIN_NO_SOURCE (-1) the cited source does not exist (the "made-up case" failure) ABSTAIN_NO_SPAN (-2) the source exists but the quote is not in it (fabricated/altered/empty) An empty quote is ABSTAIN, never CITED -- "the empty string is a substring of everything" is exactly the hole a fabricator would drive through, so it is closed explicitly. BYTE-EXACT is the honest floor. Normalization (whitespace collapse, case-fold, smart-quote unify) is a DECLARED follow-on, not silently applied -- a verifier that quietly normalizes can be tricked into accepting a materially altered quote, so the strict floor ships first and any loosening is opt-in. SCALE ENVELOPE (declared): cite_verify is O(source-length) substring scan per call (Rabin-Karp/KMP is the speed rung); source retrieval inherits the seg-store read cost (see the finance-spine scale note). DRY: composes nx_matter_lib (reg_put/reg_get/mt_field/canon_encode). license_tier: ORIGINAL LIB.

dependencies 1 imports · 3 importers

nx_matter_lib.nx nx_cite_lib.nx nx_citator_lib.nx nx_cite_gate.nx nx_cite_redline_gate.nx

imports: nx_matter_lib.nx

imported by: nx_citator_lib.nxnx_cite_gate.nxnx_cite_redline_gate.nx

structs

none

consts

27const CITE_CITED: i64 = 1
28const CITE_ABSTAIN_NO_SOURCE: i64 = 0 - 1
29const CITE_ABSTAIN_NO_SPAN: i64 = 0 - 2
30const CITE_SRC_CAP: i64 = 65536 // max stored source length (declared)

functions

32func cite_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
36func cite_contains(hay: *u8, hl: i64, needle: *u8, nl: i64) -> i64
called by 1: cite_verify
52func cite_source_put(prefix: *u8, source_id: *u8, text: *u8) -> i64
called by 3: mainmainmain calls 2: canon_encodereg_put
63func cite_source_text(prefix: *u8, source_id: *u8, out: *u8) -> i64
74func cite_verify(prefix: *u8, source_id: *u8, quoted: *u8) -> i64
86func cite_ok(prefix: *u8, source_id: *u8, quoted: *u8) -> i64
100func cite_scan_doc(prefix: *u8, doc: *u8, report: *u8) -> i64
155func cite_doc_clean(prefix: *u8, doc: *u8) -> i64
called by 1: main calls 1: cite_scan_doc