code wiki / _hdl_build / nx_reader_exceed_gate.nx

nx_reader_exceed_gate.nx source

↩ module page · 155 lines · 12194 B

1// nx_reader_exceed_gate.nx -- MEASURED exceed scorecard for the Nishi reader (no-wave, organ-graded, never 2// self-scored). Mirrors the nx_pub_exceed_gate / nx_ws_exceed_gate doctrine: MECHANICALLY measure the Nishi side 3// (read reader.html + a real book.json), name the incumbents as documented yardsticks (Kindle/Calibre-Web/foliate 4// -- by-design, NOT run/fabricated, cited in knowledge/fetched/reader_*.raw), and grade each axis EXCEEDS / PARITY 5// / BEHIND. EXCEEDS is allowed ONLY on a win-eligible axis whose mechanical measurement passed; a LIAR-KILL refuses 6// EXCEEDS on a behind-axis or an unmeasured axis. GREEN = an honest measured scorecard + intact liar-kill, NOT 7// "we beat everyone". Self-contained + sovereign (fork/exec, no shell). expect_exit: 0 8import "nx_syscalls.nx" 9 10func xp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func xn(v0: i64) -> i64 { var v: i64=v0; if v<0 { sys_write(1,"-" as *u8,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48 as u8;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 } 12func xslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 13 14func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 { 15 let pid: i64 = sys_fork() 16 if pid == 0 { 17 let fd: i64 = sys_openat_wr(redir, 420) 18 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) } 19 let argv: *i64 = sys_mmap(64) as *i64 20 var n: i64 = 0 21 argv[0] = path as i64; n = 1 22 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 } 23 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 } 24 argv[n] = 0 25 let envp: *i64 = sys_mmap(16) as *i64 26 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 27 sys_execve(path, argv, envp) 28 sys_exit(127) 29 } 30 let st: *i64 = sys_mmap(16) as *i64 31 sys_wait4(pid, st, 0) 32 return (st[0] >> 8) & 0xff 33} 34 35func xfind(hay: *u8, hl: i64, needle: *u8) -> i64 { 36 let nl: i64 = xslen(needle) 37 if nl == 0 { return 0-1 } 38 var i: i64 = 0 39 while i + nl <= hl { 40 var k: i64 = 0; var hit: i64 = 1 41 while k < nl { if hay[i+k] != needle[k] { hit = 0; k = nl } else { k = k + 1 } } 42 if hit == 1 { return i } 43 i = i + 1 44 } 45 return 0-1 46} 47func xhas(hay: *u8, hl: i64, needle: *u8) -> i64 { if xfind(hay, hl, needle) >= 0 { return 1 } return 0 } 48 49// EXCEEDS(2) ONLY if axis is win-eligible AND its mechanical measurement passed; else 0 (not exceed). The liar-kill. 50func grade_exceed(win_eligible: i64, measured: i64) -> i64 { 51 if win_eligible == 1 { if measured == 1 { return 2 } } 52 return 0 53} 54func vword(v: i64) -> i64 { 55 if v == 2 { xp("EXCEEDS" as *u8) } else { if v == 1 { xp("PARITY " as *u8) } else { xp("BEHIND " as *u8) } } 56 return 0 57} 58func axis(name: *u8, v: i64, ev: *u8) -> i64 { xp(" [" as *u8); vword(v); xp("] " as *u8); xp(name); xp(" -- " as *u8); xp(ev); xp("\n" as *u8); return 0 } 59 60func main() -> i64 { 61 xp("=== nx_reader_exceed_gate: MEASURED exceed scorecard (organ-graded, never self-scored) ===\n" as *u8) 62 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8 63 let SCRATCH: *u8 = "knowledge/status/reader_exceed_scratch.log\x00" as *u8 64 // regenerate a real book.json to measure the Nishi side 65 spawn(RUNNER, "nx_epub_fixture_build\x00" as *u8, 0 as *u8, SCRATCH) 66 spawn(RUNNER, "nx_epub_book\x00" as *u8, 0 as *u8, SCRATCH) 67 spawn("_offc/nx_epub_book.elf\x00" as *u8, "knowledge/fixtures/nishi_fixture.epub\x00" as *u8, "nishi_fixture_xcd\x00" as *u8, SCRATCH) 68 spawn("_offc/nx_epub_book.elf\x00" as *u8, "knowledge/fixtures/nishi_fixture.epub\x00" as *u8, "nishi_fixture\x00" as *u8, SCRATCH) 69 spawn(RUNNER, "nx_reader_xray\x00" as *u8, 0 as *u8, SCRATCH) // book-intrinsic X-Ray (the aids axis) -- generate BEFORE render 70 spawn(RUNNER, "nx_reader_render\x00" as *u8, 0 as *u8, SCRATCH) // the ZERO-JS sovereign reader 71 72 // read the Nishi reader UI + a real book.json 73 let lr: *i64 = sys_mmap(8) as *i64; lr[0] = 0 74 let rh: *u8 = sys_read_file("knowledge/staging/media/reader.html\x00" as *u8, lr) 75 let rn: i64 = lr[0] 76 let lb: *i64 = sys_mmap(8) as *i64; lb[0] = 0 77 let bj: *u8 = sys_read_file("knowledge/staging/media/reader/nishi_fixture_xcd/book.json\x00" as *u8, lb) 78 let bn: i64 = lb[0] 79 let lz: *i64 = sys_mmap(8) as *i64; lz[0] = 0 80 let nojs: *u8 = sys_read_file("knowledge/staging/media/reader_static_nishi_fixture.html\x00" as *u8, lz) 81 let zn: i64 = lz[0] 82 let lx: *i64 = sys_mmap(8) as *i64; lx[0] = 0 83 let xr: *u8 = sys_read_file("knowledge/staging/media/reader/nishi_fixture/xray.json\x00" as *u8, lx) 84 let xrn: i64 = lx[0] 85 if (rh as i64) == 0 { xp("READER-EXCEED verdict=RED reason=reader.html-missing\n" as *u8); sys_exit(1); return 1 } 86 if (bj as i64) == 0 { xp("READER-EXCEED verdict=RED reason=book.json-missing\n" as *u8); sys_exit(1); return 1 } 87 88 // ---- MECHANICAL MEASUREMENTS of the Nishi side ---- 89 var m_sov: i64 = 0 90 if xhas(rh, rn, "<script src=" as *u8) == 0 { if xhas(rh, rn, "epub.js" as *u8) == 0 { m_sov = 1 } } // no external script dep / no epub.js 91 var m_sec: i64 = 0 92 if xhas(rh, rn, "createTextNode" as *u8) == 1 { if xhas(rh, rn, "eval(" as *u8) == 0 { if xhas(rh, rn, "new Function" as *u8) == 0 { m_sec = 1 } } } // book text + link/footnote text rendered via createTextNode (inert; never innerHTML of book data) + scheme-filtered hrefs; no code-exec path 93 let m_asset: i64 = xhas(bj, bn, "\"fp\":" as *u8) // assets content-fingerprinted (locally owned, not vendor-cloud) 94 let m_toc: i64 = xhas(bj, bn, "\"depth\":1" as *u8) // hierarchical TOC present 95 var m_nojs: i64 = 0 96 if (nojs as i64) != 0 { if zn > 0 { if xhas(nojs, zn, "<script" as *u8) == 0 { m_nojs = 1 } } } // sovereign reader ships 0 client code 97 var m_xray: i64 = 0 98 if (xr as i64) != 0 { if xrn > 0 { if xhas(xr, xrn, "\"source\":\"book-intrinsic\"" as *u8) == 1 { if xhas(xr, xrn, "\"terms\":[{" as *u8) == 1 { m_xray = 1 } } } } // X-Ray DERIVED from book text + non-empty (not provisioned) 99 var m_xpanel: i64 = 0 100 if (nojs as i64) != 0 { if zn > 0 { if xhas(nojs, zn, "<details class=\"xray\">" as *u8) == 1 { m_xpanel = 1 } } } // and surfaced in the zero-JS reader 101 var m_xwin: i64 = 0 102 if m_xray == 1 { if m_xpanel == 1 { m_xwin = 1 } } // the measured win: an X-Ray exists+rendered for a book with NO publisher X-Ray data 103 104 xp(" measured: m_sov=" as *u8); xn(m_sov); xp(" m_sec=" as *u8); xn(m_sec); xp(" m_asset=" as *u8); xn(m_asset); xp(" m_toc=" as *u8); xn(m_toc); xp(" m_nojs=" as *u8); xn(m_nojs); xp(" m_xray=" as *u8); xn(m_xray); xp(" m_xpanel=" as *u8); xn(m_xpanel); xp("\n" as *u8) 105 106 // ---- GRADE each axis (win-eligible axes use grade_exceed; parity/behind axes graded honestly) ---- 107 let v_sov: i64 = grade_exceed(1, m_sov) // sovereignty: own engine, 0 ext deps vs Calibre-Web(epub.js)/Kindle(closed cloud) 108 let v_sec: i64 = grade_exceed(1, m_sec) // security-by-construction: cannot exec book-embedded code vs EPUB/PDF script-exec CVEs 109 let v_asset: i64 = grade_exceed(1, m_asset) // asset ownership: content-addressed local vs all vendor-cloud (link-rot on account loss) 110 var v_toc: i64 = 0 // hierarchical TOC: parity axis (foliate/Kindle also nest) 111 if m_toc == 1 { v_toc = 1 } 112 let v_fid: i64 = grade_exceed(0, 1) // render fidelity: BEHIND axis (NOT win-eligible) -- liar-kill input (measured=1 but not eligible) 113 let v_aids: i64 = grade_exceed(0, 1) // aids ecosystem (X-Ray/dict/TTS): BEHIND axis 114 let v_nojs: i64 = grade_exceed(1, m_nojs) // ZERO client code: the no-JS reader (0 <script>) vs ALL incumbents ship JS 115 let v_xray: i64 = grade_exceed(1, m_xwin) // X-Ray COVERAGE: auto-derived from text -> works on ANY book; Kindle X-Ray provisioned-only -> "not available" otherwise 116 let v_xrich: i64 = grade_exceed(0, 1) // X-Ray RICHNESS: BEHIND axis (Kindle curated bios/graphs deeper) -- liar-kill input (measured=1 but not win-eligible) 117 118 xp(" -- MEASURED exceed scorecard (incumbents = documented yardsticks, cited reader_*.raw; not run) --\n" as *u8) 119 axis("sovereignty (own engine, 0 ext deps) " as *u8, v_sov, "no <script src=, no epub.js vs Calibre-Web wraps epub.js" as *u8) 120 axis("zero client code (no-JS reader) " as *u8, v_nojs, "static HTML+CSS, 0 <script> vs Kindle/Kobo/foliate all ship JS" as *u8) 121 axis("security-by-construction (no book-code exec)" as *u8, v_sec, "createTextNode + scheme-filtered links, no eval/Function vs EPUB/PDF script-exec CVEs" as *u8) 122 axis("asset ownership (content-addressed, local) " as *u8, v_asset, "assets carry fp + served locally vs vendor-cloud link-rot" as *u8) 123 axis("hierarchical TOC (nested nav-doc) " as *u8, v_toc, "we now nest == foliate/Kindle also nest (parity, not a win)" as *u8) 124 axis("X-Ray coverage (auto-derived, ANY book) " as *u8, v_xray, "derived from book text, 0 publisher data vs Kindle X-Ray provisioned-only (not-available otherwise)" as *u8) 125 axis("render fidelity " as *u8, v_fid, "Acrobat/Kindle decades-mature (honest: behind)" as *u8) 126 axis("X-Ray richness (curated bios/graphs) " as *u8, v_xrich, "Kindle X-Ray has Wikipedia bios + relationship graphs; ours = term+count (honest: behind)" as *u8) 127 axis("aids breadth (dictionary/TTS/translation) " as *u8, v_aids, "Kindle/Moon+ have many aids; we ship X-Ray only (honest: behind)" as *u8) 128 129 var nex: i64 = 0; var npar: i64 = 0; var nbeh: i64 = 0 130 if v_sov==2 {nex=nex+1} ; if v_sec==2 {nex=nex+1} ; if v_asset==2 {nex=nex+1} ; if v_nojs==2 {nex=nex+1} ; if v_xray==2 {nex=nex+1} 131 if v_toc==1 {npar=npar+1} 132 if v_fid==0 {nbeh=nbeh+1} ; if v_xrich==0 {nbeh=nbeh+1} ; if v_aids==0 {nbeh=nbeh+1} 133 xp(" TALLY EXCEEDS=" as *u8); xn(nex); xp(" PARITY=" as *u8); xn(npar); xp(" BEHIND=" as *u8); xn(nbeh); xp("\n" as *u8) 134 135 // ---- pass/fail: gate INTEGRITY (honest scorecard + intact liar-kill), NOT "we win all" ---- 136 var pass: i64 = 0; var fail: i64 = 0 137 if v_sov == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL sovereignty-not-measured\n" as *u8) } 138 if v_nojs == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL zero-js-not-measured\n" as *u8) } 139 if v_sec == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL security-not-measured\n" as *u8) } 140 if v_asset == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL asset-not-measured\n" as *u8) } 141 if v_toc == 1 { pass=pass+1 } else { fail=fail+1; xp(" FAIL toc-parity\n" as *u8) } 142 if v_xray == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL xray-coverage-not-measured (missing/empty xray.json or panel not rendered)\n" as *u8) } 143 // LIAR-KILL teeth: a BEHIND axis fed measured=1 must NOT grade EXCEEDS 144 if grade_exceed(0, 1) == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL liar-kill behind-axis\n" as *u8) } 145 // LIAR-KILL teeth: a win-eligible axis with measured=0 must NOT grade EXCEEDS 146 if grade_exceed(1, 0) == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL liar-kill unmeasured\n" as *u8) } 147 // honesty: the behind axes must read BEHIND (we do NOT claim fidelity / X-Ray-richness / aids-breadth exceed) 148 if v_fid == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL fidelity-overclaim\n" as *u8) } 149 if v_xrich == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL xray-richness-overclaim\n" as *u8) } 150 if v_aids == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL aids-breadth-overclaim\n" as *u8) } 151 152 xp("READER-EXCEED pass=" as *u8); xn(pass); xp(" fail=" as *u8); xn(fail) 153 if fail == 0 { xp(" verdict=GREEN (honest measured scorecard; EXCEEDS only where mechanically proven; BEHIND stated, not hidden)\n" as *u8); sys_exit(0); return 0 } 154 xp(" verdict=RED\n" as *u8); sys_exit(1); return 1 155}