nx_mirrorintegrity_lib.nx
buildroot/runtime/nx_mirrorintegrity_lib.nx
about
nx_mirrorintegrity_lib.nx -- IS THE EVIDENCE WE PINNED ACTUALLY COMPLETE?
WHY THIS EXISTS. The /compare citation register mirrors every reference into knowledge/fetched/ and pins it
with a sha256. nx_compare_refs_gate then proves pin==filehash on every declared mirror. That proof is real
but it answers a NARROWER question than its name suggests:
A PIN PROVES THE BYTES ARE UNCHANGED SINCE THEY WERE STORED. IT CANNOT PROVE THEY WERE EVER COMPLETE.
A truncated body hashes perfectly and matches forever. Measured 2026-08-20: nx_research_fetch's TLS-1.2 leg
saved 255935 bytes of an 814052-byte PDF, twice, byte-identical, while printing status=200 and a SAVED line
that reads as success. That mirror would have passed the refs gate every day for the rest of its life.
A TRUNCATED MIRROR IS WORSE THAN NO MIRROR: IT IS A CITATION THAT READS AS VERIFIED.
WHAT IT DOES. For every file under a directory it reads only the HEAD and the TAIL (never the whole body, so
a 6 MB PDF costs two reads) and asks the body to describe its own completeness:
PDF -- a linearized PDF DECLARES ITS OWN TOTAL LENGTH in the header (/L <n>); if that exceeds the file
on disk the body is provably short. Otherwise a complete PDF ends in the EOF marker.
HTML -- a complete document closes its html element.
JSON -- a complete document closes the brace or bracket it opened.
PNG -- a complete stream ends with the IEND chunk type.
JPEG -- a complete stream ends with the EOI marker FF D9.
Anything whose format declares no length and carries no terminator is UNKNOWN. It is NOT counted as complete.
AN AXIS THAT CANNOT SEE MUST ABSTAIN, NOT ACQUIT.
THE PARTITION IS PRINTED AND MUST SUM: proven + suspect + complete + unknown == files.
CAP-EXACT is a SEPARATE AXIS, not a partition member, because a body can be complete AND land on a
power-of-two boundary by coincidence -- folding it in would silently break the reconciliation.
license_tier: ORIGINAL LIBRARY -- no main. nx_mirrorintegrity.nx and nx_mirrorintegrity_gate.nx BOTH
consume it, so the census and its gate share ONE ruler by construction and cannot drift apart.
dependencies 3 imports · 6 importers
imports: nx_syscalls.nxnx_lane_conf.nxnx_html_to_text.nx
imported by: nx_compare_refs_gate.nxnx_fetchfail.nxnx_fetchfail_gate.nxnx_mirrorintegrity.nxnx_mirrorintegrity_gate.nxnx_refdrift.nx
structs
| none |
consts
| 33 | const MI_DEF_DIR: *u8 = "knowledge/fetched\x00" |
| 34 | const MI_HEAD: i64 = 4096 // declared: bytes read from the head of every file |
| 35 | const MI_TAIL: i64 = 4096 // declared: bytes read from the tail of every file |
| 36 | const MI_PATHCAP: i64 = 4096 |
| 37 | const MI_DIRBUF: i64 = 131072 |
| 38 | const MI_MAXDEPTH: i64 = 8 |
| 39 | const MI_WORKCAP: i64 = 1048576 // worklist accumulation buffer, flushed when near full |
| 40 | const MI_WORKFLUSH: i64 = 1047000 // flush threshold, leaves room for one long row |
| 41 | const MI_CAP_FLOOR: i64 = 65536 // below this a power-of-two size is coincidence, not a cap |
| 42 | const MI_SEEK_SET: i64 = 0 |
| 43 | const MI_SEEK_END: i64 = 2 |
| 44 | const MI_DT_DIR: i64 = 4 |
| 46 | const MI_PROVEN: i64 = 0 |
| 47 | const MI_SUSPECT: i64 = 1 |
| 48 | const MI_COMPLETE: i64 = 2 |
| 49 | const MI_UNKNOWN: i64 = 3 |
| 147 | const MI_CH_GT: i64 = 62 // the byte a finished HTML element always ends on |
| 148 | const MI_CH_LT: i64 = 60 // opens a tag; met first while scanning BACK, it proves a cut |
| 149 | const MI_RC_HTML_MIDCONTENT: i64 = 4 |
| 150 | const MI_RC_HTML_OPENTAG: i64 = 10 |
| 151 | const MI_RC_HTML_OPTIONAL: i64 = 11 |
| 351 | const MI_CH_MINUS: i64 = 45 |
| 352 | const MI_CH_ZERO: i64 = 48 |
| 353 | const MI_CH_NINE: i64 = 57 |
| 355 | const MI_COUNTS_SLOTS: i64 = 16 |
| 356 | const MI_COUNTS_BYTES: i64 = 128 |
| 358 | const MI_AXISBUF: i64 = 4096 |
| 359 | const MI_CONTENT_CONF_REL: *u8 = "knowledge/mirror_content.conf\x00" |
| 360 | const MI_CONTENT_CONF_ABS: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/mirror_content.conf\x00" |
| 361 | const MI_PROSE_FLOOR_KEY: *u8 = "prose-floor-bytes\x00" |
| 365 | const MI_DEF_PROSE_FLOOR: i64 = 1 |
| 367 | const MC_OK: i64 = 0 |
| 368 | const MC_JS_SHELL: i64 = 1 |
| 369 | const MC_BOT_CHALLENGE: i64 = 2 |
| 370 | const MC_LOGIN_WALL: i64 = 3 |
| 371 | const MC_HTTP_ERROR: i64 = 4 |
| 372 | const MC_PROSE_EMPTY: i64 = 5 |
| 373 | const MC_NOT_HTML: i64 = 6 |
| 425 | const MI_RENDER_SLACK: i64 = 4096 |
functions
| 51 | func mi_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 52 | func mi_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 53 | func mi_cat(o: *u8, at: i64, s: *u8) -> i64 { var i: i64=0; var a: i64=at; while s[i]!=(0 as u8){o[a]=s[i]; a=a+1; i=i+1} return a } |
| 54 | func mi_catn(o: *u8, at: i64, v: i64) -> i64 { |
| 65 | func mi_find(buf: *u8, from: i64, end: i64, needle: *u8) -> i64 { |
| 80 | func mi_digits_at(buf: *u8, p: i64, end: i64) -> i64 {
called by 1: mi_classify |
| 91 | func mi_is_ws(c: i64) -> i64 { if c==32 { return 1 } if c==10 { return 1 } if c==13 { return 1 } if c==9 { return 1 } return 0 } |
| 92 | func mi_is_pow2(n: i64) -> i64 {
called by 1: mi_walk |
| 99 | func mi_isdotdot(nm: *u8) -> i64 { if nm[0]==(46 as u8){ if nm[1]==(0 as u8){return 1} if nm[1]==(46 as u8){ if nm[2]==(0 as u8){return 1} } } return 0 } |
| 100 | func mi_join(buf: *u8, base_n: i64, name: *u8) -> i64 { buf[base_n]=47 as u8; var o: i64=base_n+1; var i: i64=0; while name[i]!=(0 as u8){buf[o]=name[i];o=o+1;i=i+1} return o } |
| 103 | func mi_read_at(fd: i64, off: i64, buf: *u8, cap: i64) -> i64 { |
| 153 | func mi_html_tail_verdict(tbuf: *u8, tn: i64, rcode: *i64) -> i64 { |
| 185 | func mi_classify(path: *u8, hbuf: *u8, tbuf: *u8, rcode: *i64, sz: *i64, decl: *i64) -> i64 {
called by 4: crg_scancrg_url_skipmainmi_walk calls 8: sys_openat_rdsys_lseeksys_closemi_read_atmi_findmi_digits_at+2 |
| 305 | func mi_reason(rc: i64) -> *u8 { |
| 375 | func mi_prose_floor() -> i64 { return lc_geti(MI_CONTENT_CONF_REL as *u8, MI_CONTENT_CONF_ABS as *u8, MI_PROSE_FLOOR_KEY as *u8, MI_DEF_PROSE_FLOOR) } |
| 378 | func mi_atoi_arg(s: *u8) -> i64 {
called by 1: main |
| 392 | func mi_pc_lc(c: i64) -> i64 { if c>=65 { if c<=90 { return c+32 } } return c }
called by 1: mi_pc_find_ci |
| 395 | func mi_pc_find_ci(buf: *u8, from: i64, end: i64, needle: *u8) -> i64 { |
| 410 | func mi_has(src: *u8, n: i64, needle: *u8) -> i64 { if mi_pc_find_ci(src, 0, n, needle)>=0 { return 1 } return 0 } |
| 413 | func mi_is_html(src: *u8, n: i64) -> i64 { |
| 431 | func mi_prose_render(src: *u8, n: i64, out: *u8, cap: i64) -> i64 { |
| 436 | func mi_prose_bytes(src: *u8, n: i64) -> i64 { |
| 448 | func mi_content_class(path: *u8, floor: i64, prose: *i64, hb: *i64) -> i64 {
called by 3: ff_walkmainmi_content_walk calls 7: sys_mmapsys_read_filesys_munmapsys_free_filemi_is_htmlmi_prose_render+1 |
| 526 | func mi_content_reason(c: i64) -> *u8 { |
| 537 | func mi_content_remedy(c: i64) -> *u8 { |
| 551 | func mi_content_walk(p: *u8, pn: i64, depth: i64, floor: i64, ccounts: *i64, work: *u8, wo: *i64) -> i64 {
called by 2: mainmi_content_walk calls 16: sys_openat_rdsys_mmapsys_getdents64dirent_typedirent_namemi_isdotdot+10 |
| 612 | func mi_walk(p: *u8, pn: i64, depth: i64, hbuf: *u8, tbuf: *u8, counts: *i64, work: *u8, wo: *i64) -> i64 {
called by 3: mainmainmi_walk calls 15: sys_openat_rdsys_mmapsys_getdents64dirent_typedirent_namemi_isdotdot+9 |