code wiki / _hdl_build / nx_reader_exceed_gate.nx
nx_reader_exceed_gate.nx source
↩ module page · 163 lines · 12586 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"
9import "nx_gate_verdict.nx"
10
11func xp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func 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 }
13func xslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
14
15func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 {
16 let pid: i64 = sys_fork()
17 if pid == 0 {
18 let fd: i64 = sys_openat_wr(redir, 420)
19 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) }
20 let argv: *i64 = sys_mmap(64) as *i64
21 var n: i64 = 0
22 argv[0] = path as i64; n = 1
23 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 }
24 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 }
25 argv[n] = 0
26 let envp: *i64 = sys_mmap(16) as *i64
27 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0
28 sys_execve(path, argv, envp)
29 sys_exit(127)
30 }
31 let st: *i64 = sys_mmap(16) as *i64
32 sys_wait4(pid, st, 0)
33 return (st[0] >> 8) & 0xff
34}
35
36func xfind(hay: *u8, hl: i64, needle: *u8) -> i64 {
37 let nl: i64 = xslen(needle)
38 if nl == 0 { return 0-1 }
39 var i: i64 = 0
40 while i + nl <= hl {
41 var k: i64 = 0; var hit: i64 = 1
42 while k < nl { if hay[i+k] != needle[k] { hit = 0; k = nl } else { k = k + 1 } }
43 if hit == 1 { return i }
44 i = i + 1
45 }
46 return 0-1
47}
48func xhas(hay: *u8, hl: i64, needle: *u8) -> i64 { if xfind(hay, hl, needle) >= 0 { return 1 } return 0 }
49
50// EXCEEDS(2) ONLY if axis is win-eligible AND its mechanical measurement passed; else 0 (not exceed). The liar-kill.
51func grade_exceed(win_eligible: i64, measured: i64) -> i64 {
52 if win_eligible == 1 { if measured == 1 { return 2 } }
53 return 0
54}
55func vword(v: i64) -> i64 {
56 if v == 2 { xp("EXCEEDS" as *u8) } else { if v == 1 { xp("PARITY " as *u8) } else { xp("BEHIND " as *u8) } }
57 return 0
58}
59func 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 }
60
61func main() -> i64 {
62 xp("=== nx_reader_exceed_gate: MEASURED exceed scorecard (organ-graded, never self-scored) ===\n" as *u8)
63 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8
64 let SCRATCH: *u8 = "knowledge/status/reader_exceed_scratch.log\x00" as *u8
65 // regenerate a real book.json to measure the Nishi side
66 spawn(RUNNER, "nx_epub_fixture_build\x00" as *u8, 0 as *u8, SCRATCH)
67 spawn(RUNNER, "nx_epub_book\x00" as *u8, 0 as *u8, SCRATCH)
68 spawn("_offc/nx_epub_book.elf\x00" as *u8, "knowledge/fixtures/nishi_fixture.epub\x00" as *u8, "nishi_fixture_xcd\x00" as *u8, SCRATCH)
69 spawn("_offc/nx_epub_book.elf\x00" as *u8, "knowledge/fixtures/nishi_fixture.epub\x00" as *u8, "nishi_fixture\x00" as *u8, SCRATCH)
70 spawn(RUNNER, "nx_reader_xray\x00" as *u8, 0 as *u8, SCRATCH) // book-intrinsic X-Ray (the aids axis) -- generate BEFORE render
71 spawn(RUNNER, "nx_reader_render\x00" as *u8, 0 as *u8, SCRATCH) // the ZERO-JS sovereign reader
72
73 // read the Nishi reader UI + a real book.json
74 let lr: *i64 = sys_mmap(8) as *i64; lr[0] = 0
75 let rh: *u8 = sys_read_file("knowledge/staging/media/reader.html\x00" as *u8, lr)
76 let rn: i64 = lr[0]
77 let lb: *i64 = sys_mmap(8) as *i64; lb[0] = 0
78 let bj: *u8 = sys_read_file("knowledge/staging/media/reader/nishi_fixture_xcd/book.json\x00" as *u8, lb)
79 let bn: i64 = lb[0]
80 let lz: *i64 = sys_mmap(8) as *i64; lz[0] = 0
81 let nojs: *u8 = sys_read_file("knowledge/staging/media/reader_static_nishi_fixture.html\x00" as *u8, lz)
82 let zn: i64 = lz[0]
83 let lx: *i64 = sys_mmap(8) as *i64; lx[0] = 0
84 let xr: *u8 = sys_read_file("knowledge/staging/media/reader/nishi_fixture/xray.json\x00" as *u8, lx)
85 let xrn: i64 = lx[0]
86 if (rh as i64) == 0 { xp("READER-EXCEED verdict=RED reason=reader.html-missing\n" as *u8); sys_exit(1); return 1 }
87 if (bj as i64) == 0 { xp("READER-EXCEED verdict=RED reason=book.json-missing\n" as *u8); sys_exit(1); return 1 }
88
89 // ---- MECHANICAL MEASUREMENTS of the Nishi side ----
90 var m_sov: i64 = 0
91 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
92 var m_sec: i64 = 0
93 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
94 let m_asset: i64 = xhas(bj, bn, "\"fp\":" as *u8) // assets content-fingerprinted (locally owned, not vendor-cloud)
95 let m_toc: i64 = xhas(bj, bn, "\"depth\":1" as *u8) // hierarchical TOC present
96 var m_nojs: i64 = 0
97 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
98 var m_xray: i64 = 0
99 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)
100 var m_xpanel: i64 = 0
101 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
102 var m_xwin: i64 = 0
103 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
104
105 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)
106
107 // ---- GRADE each axis (win-eligible axes use grade_exceed; parity/behind axes graded honestly) ----
108 let v_sov: i64 = grade_exceed(1, m_sov) // sovereignty: own engine, 0 ext deps vs Calibre-Web(epub.js)/Kindle(closed cloud)
109 let v_sec: i64 = grade_exceed(1, m_sec) // security-by-construction: cannot exec book-embedded code vs EPUB/PDF script-exec CVEs
110 let v_asset: i64 = grade_exceed(1, m_asset) // asset ownership: content-addressed local vs all vendor-cloud (link-rot on account loss)
111 var v_toc: i64 = 0 // hierarchical TOC: parity axis (foliate/Kindle also nest)
112 if m_toc == 1 { v_toc = 1 }
113 let v_fid: i64 = grade_exceed(0, 1) // render fidelity: BEHIND axis (NOT win-eligible) -- liar-kill input (measured=1 but not eligible)
114 let v_aids: i64 = grade_exceed(0, 1) // aids ecosystem (X-Ray/dict/TTS): BEHIND axis
115 let v_nojs: i64 = grade_exceed(1, m_nojs) // ZERO client code: the no-JS reader (0 <script>) vs ALL incumbents ship JS
116 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
117 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)
118
119 xp(" -- MEASURED exceed scorecard (incumbents = documented yardsticks, cited reader_*.raw; not run) --\n" as *u8)
120 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)
121 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)
122 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)
123 axis("asset ownership (content-addressed, local) " as *u8, v_asset, "assets carry fp + served locally vs vendor-cloud link-rot" as *u8)
124 axis("hierarchical TOC (nested nav-doc) " as *u8, v_toc, "we now nest == foliate/Kindle also nest (parity, not a win)" as *u8)
125 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)
126 axis("render fidelity " as *u8, v_fid, "Acrobat/Kindle decades-mature (honest: behind)" as *u8)
127 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)
128 axis("aids breadth (dictionary/TTS/translation) " as *u8, v_aids, "Kindle/Moon+ have many aids; we ship X-Ray only (honest: behind)" as *u8)
129
130 var nex: i64 = 0; var npar: i64 = 0; var nbeh: i64 = 0
131 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}
132 if v_toc==1 {npar=npar+1}
133 if v_fid==0 {nbeh=nbeh+1} ; if v_xrich==0 {nbeh=nbeh+1} ; if v_aids==0 {nbeh=nbeh+1}
134 xp(" TALLY EXCEEDS=" as *u8); xn(nex); xp(" PARITY=" as *u8); xn(npar); xp(" BEHIND=" as *u8); xn(nbeh); xp("\n" as *u8)
135
136 // ---- pass/fail: gate INTEGRITY (honest scorecard + intact liar-kill), NOT "we win all" ----
137 var pass: i64 = 0; var fail: i64 = 0
138 if v_sov == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL sovereignty-not-measured\n" as *u8) }
139 if v_nojs == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL zero-js-not-measured\n" as *u8) }
140 if v_sec == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL security-not-measured\n" as *u8) }
141 if v_asset == 2 { pass=pass+1 } else { fail=fail+1; xp(" FAIL asset-not-measured\n" as *u8) }
142 if v_toc == 1 { pass=pass+1 } else { fail=fail+1; xp(" FAIL toc-parity\n" as *u8) }
143 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) }
144 // LIAR-KILL teeth: a BEHIND axis fed measured=1 must NOT grade EXCEEDS
145 if grade_exceed(0, 1) == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL liar-kill behind-axis\n" as *u8) }
146 // LIAR-KILL teeth: a win-eligible axis with measured=0 must NOT grade EXCEEDS
147 if grade_exceed(1, 0) == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL liar-kill unmeasured\n" as *u8) }
148 // honesty: the behind axes must read BEHIND (we do NOT claim fidelity / X-Ray-richness / aids-breadth exceed)
149 if v_fid == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL fidelity-overclaim\n" as *u8) }
150 if v_xrich == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL xray-richness-overclaim\n" as *u8) }
151 if v_aids == 0 { pass=pass+1 } else { fail=fail+1; xp(" FAIL aids-breadth-overclaim\n" as *u8) }
152
153 xp("READER-EXCEED pass=" as *u8); xn(pass); xp(" fail=" as *u8); xn(fail)
154 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
155 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
156 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
157 let ctr__dry: *i64 = gv_ctr()
158 ctr__dry[0] = pass
159 ctr__dry[1] = pass + fail
160 let rc__dry: i64 = gv_verdict("READER-EXCEED-GATE" as *u8, ctr__dry, "honest measured scorecard; EXCEEDS only where mechanically proven; BEHIND stated, not hidden)" as *u8)
161 sys_exit(rc__dry)
162 return rc__dry
163}