code wiki / _hdl_build / nx_browser_os_census.nx

nx_browser_os_census.nx source

↩ module page · 203 lines · 14144 B

1// nx_browser_os_census.nx -- BROWSER-ON-ALL-OS arc, rung R0: the measured per-OS browser census. 2// 3// Operator (2026-07-02): "finish getting our nishi browser to s class exceed on all OSs including our 4// future nishi os." This organ is the MEASURE for that arc (no-wave: never claim before measuring): 5// a data-driven census of the Nishi browser per OS target -- linux-elf (nx_browser, X11/WSLg), 6// windows-pe (nishi.exe native PE), nishios (the sovereign OS) -- where every PRESENT cell is backed 7// by a MECHANICAL evidence probe (a real on-disk organ/artifact at a minimum size), every gap is an 8// honest ABSENT/PLAN row that NAMES its build organ (so the census self-flips as rungs land), and a 9// NEG control (a must-be-absent file) kills a lying census: if the negctl file exists the verdict is 10// RED regardless of score. Emits the operator-facing UI surface (browser_os_census.html) + a status 11// line (browser_os_census.log). The census reports permil scores; the VERDICT is about census 12// integrity (row count parsed, negctl absent, honesty rows intact), never about whitewashing the score. 13// NEVER-BRICK (Rule 26): reads evidence files, writes status artifacts only. 14// expect_exit: 0 license_tier: ORIGINAL 15import "nx_syscalls.nx" 16import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 17const K_MAGIC_65536: i64 = 65536 18 19func bc_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 20// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 21// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 22// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 23// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 24func bc_num(v: i64) -> i64 { nxi_out(v); return 0 } 25func bc_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 26 27// append a NUL-terminated string into buf at pos, return the new pos 28func bc_app(buf: *u8, pos: i64, s: *u8) -> i64 { 29 var p: i64 = pos 30 var i: i64 = 0 31 while s[i]!=(0 as u8) { buf[p]=s[i]; p=p+1; i=i+1 } 32 return p 33} 34// append a byte-span into buf at pos 35func bc_appn(buf: *u8, pos: i64, s: *u8, n: i64) -> i64 { 36 var p: i64 = pos 37 var i: i64 = 0 38 while i<n { buf[p]=s[i]; p=p+1; i=i+1 } 39 return p 40} 41// append a decimal number 42func bc_appd(buf: *u8, pos: i64, v: i64) -> i64 { 43 var p: i64 = pos 44 var m: i64 = v 45 if m<0 { buf[p]=45 as u8; p=p+1; m=0-m } 46 let t: *u8=sys_mmap(28) 47 var k: i64=0 48 if m==0 { t[0]=48 as u8; k=1 } 49 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 50 var i: i64=0 51 while i<k { buf[p]=t[k-1-i]; p=p+1; i=i+1 } 52 return p 53} 54func bc_write_file(path: *u8, data: *u8, n: i64) -> i64 { 55 let fd: i64 = sys_openat_wr(path, 0x1a4) 56 if fd<=0 { return 0 - 1 } 57 sys_write(fd, data, n) 58 sys_close(fd) 59 return n 60} 61// parse a decimal span 62func bc_parse_int(s: *u8, off: i64, len: i64) -> i64 { 63 var v: i64=0 64 var i: i64=0 65 while i<len { let c: i64=s[off+i] as i64; if c>=48 { if c<=57 { v=v*10+(c-48) } } i=i+1 } 66 return v 67} 68 69// THE CENSUS TABLE (data rows -- edit rows, not logic). os|axis|kind|path|min_bytes|build_organ 70// kind: FILE = PRESENT iff the file exists at >= min_bytes (mechanical evidence) 71// PLAN = honest ABSENT row counted against the score; build_organ names the rung that flips it 72// NEGCTL= liar-kill: this file must NOT exist; if it does, the whole census verdict is RED 73func bc_rows() -> *u8 { 74 return "linux|engine-gui-x11|FILE|runtime/_hdl_build/nx_browser.nx|30000|-\x0Alinux|render-core-shared|FILE|runtime/_hdl_build/nx_browser_render.nx|15000|-\x0Alinux|render-proof-png|FILE|_offc/nxrender.png|1000|-\x0Alinux|js-dom-tree|FILE|runtime/nx_domtree.nx|5000|-\x0Alinux|js-es-census|FILE|runtime/_hdl_build/nx_js_es_census.nx|1000|-\x0Alinux|net-tls13|FILE|runtime/nx_tls13_hello.nx|5000|-\x0Alinux|img-decode|FILE|runtime/nx_img_bytes_to_rgb.nx|1000|-\x0Awindows|gui-exe-pe|FILE|_offc/nishi.exe|400000|-\x0Awindows|fetch-exe-pe|FILE|_offc/nishi_fetch.exe|800000|-\x0Awindows|gui-keystone|FILE|runtime/nx_pe_compile_win_gui.nx|10000|-\x0Awindows|fetch-keystone|FILE|runtime/nx_pe_compile_win_nishi.nx|20000|-\x0Awindows|img-in-window-proof|FILE|knowledge/status/nishi_win_realimg.png|50000|-\x0Awindows|window-chrome|PLAN|-|0|nx_win_wndproc(drag/resize/X-close)\x0Anishios|os-desktop|FILE|knowledge/status/nishi_os_desktop.bmp|100000|-\x0Anishios|browser-render|FILE|knowledge/status/nishios_browser.bmp|500000|nx_nishios_browser\x0Anishios|browser-view|FILE|knowledge/status/nishios_browser.html|200|nx_nishios_browser\x0Anishios|nic-driver-on-os|FILE|knowledge/status/nishios_net.bmp|500000|nx_nishios_net\x0Anishios|net-realwire-on-os|FILE|knowledge/status/nishios_net_wire.bmp|500000|nx_nishios_net_wire\x0Anishios|input-on-os|FILE|knowledge/status/nishios_browser_click1.bmp|500000|nx_nishios_browser_input\x0Anishios|render-as-x86|FILE|knowledge/status/nishios_browser_x86.bmp|500000|nx_nishios_browser_x86\x0Anegctl|must-be-absent|NEGCTL|knowledge/status/__browser_os_census_negctl__.bmp|0|-\x0A\x00" as *u8 75} 76 77func main() -> i64 { 78 bc_puts("BROWSER-OS-CENSUS R0: the Nishi browser measured per OS (linux-elf / windows-pe / nishios)\n" as *u8) 79 let rows: *u8 = bc_rows() 80 let rlen: i64 = bc_slen(rows) 81 82 // per-OS tallies: 0=linux 1=windows 2=nishios 83 let present: *i64 = sys_mmap(64) as *i64 84 let total: *i64 = sys_mmap(64) as *i64 85 var nrows: i64 = 0 86 var nplan: i64 = 0 87 var negviol: i64 = 0 88 89 // html buffer 90 let hb: *u8 = sys_mmap(K_MAGIC_65536) 91 var hp: i64 = 0 92 hp = bc_app(hb, hp, "<!doctype html><html><head><title>Nishi Browser OS census</title></head><body style=\x27background:#0b1020;color:#dbe4ff;font-family:monospace;padding:24px\x27><h2>Nishi Browser -- per-OS census (browser-on-all-OS arc)</h2><table style=\x27border-collapse:collapse\x27><tr><th style=\x27text-align:left;padding:4px 12px\x27>OS</th><th style=\x27text-align:left;padding:4px 12px\x27>axis</th><th style=\x27text-align:left;padding:4px 12px\x27>status</th><th style=\x27text-align:left;padding:4px 12px\x27>evidence / build organ</th></tr>\x00" as *u8) 93 94 let pathbuf: *u8 = sys_mmap(512) 95 let lp: *i64 = sys_mmap(16) as *i64 96 var i: i64 = 0 97 while i < rlen { 98 // parse one row: 6 fields split by '|', row ends at '\n' 99 let f0: i64 = i 100 var fo: *i64 = sys_mmap(64) as *i64 101 var fl: *i64 = sys_mmap(64) as *i64 102 var fi: i64 = 0 103 var fs: i64 = i 104 var j: i64 = i 105 var done: i64 = 0 106 while done==0 { 107 let c: i64 = rows[j] as i64 108 if c==124 { fo[fi]=fs; fl[fi]=j-fs; fi=fi+1; fs=j+1 } 109 if c==10 { fo[fi]=fs; fl[fi]=j-fs; fi=fi+1; done=1 } 110 j = j + 1 111 } 112 i = j 113 if fi==6 { 114 nrows = nrows + 1 115 // which OS bucket 116 var osi: i64 = 0 - 1 117 if (rows[fo[0]] as i64)==108 { osi=0 } // 'l'inux 118 if (rows[fo[0]] as i64)==119 { osi=1 } // 'w'indows 119 if (rows[fo[0]] as i64)==110 { if (rows[fo[0]+1] as i64)==105 { osi=2 } } // 'ni'shios (not 'ne'gctl) 120 let kc: i64 = rows[fo[2]] as i64 // F/P/N 121 var st: i64 = 0 // 0=absent 1=present 122 var isneg: i64 = 0 123 if kc==78 { isneg=1 } // NEGCTL 124 // stat the evidence file for FILE + NEGCTL rows 125 var flen: i64 = 0 - 1 126 if kc==70 { var cp: i64=0; while cp<fl[3] { pathbuf[cp]=rows[fo[3]+cp]; cp=cp+1 } pathbuf[fl[3]]=0 as u8 127 lp[0]=0-1 128 let dat: *u8 = sys_read_file(pathbuf, lp) 129 flen = lp[0] 130 let minb: i64 = bc_parse_int(rows, fo[4], fl[4]) 131 if flen >= minb { if flen > 0 { st=1 } } 132 } 133 if isneg==1 { var cp2: i64=0; while cp2<fl[3] { pathbuf[cp2]=rows[fo[3]+cp2]; cp2=cp2+1 } pathbuf[fl[3]]=0 as u8 134 lp[0]=0-1 135 let dat2: *u8 = sys_read_file(pathbuf, lp) 136 if lp[0] > 0 { negviol=1 } 137 } 138 if kc==80 { nplan=nplan+1 } 139 if isneg==0 { if osi>=0 { 140 total[osi] = total[osi] + 1 141 if st==1 { present[osi] = present[osi] + 1 } 142 } } 143 // print the row 144 bc_puts(" " as *u8); sys_write(1, ((rows as i64)+fo[0]) as *u8, fl[0]); bc_puts("|" as *u8); sys_write(1, ((rows as i64)+fo[1]) as *u8, fl[1]); bc_puts(" = " as *u8) 145 if isneg==1 { if negviol==1 { bc_puts("NEG-VIOLATION(file exists!)" as *u8) } else { bc_puts("NEG-OK(absent)" as *u8) } } 146 else { if st==1 { bc_puts("PRESENT(" as *u8); bc_num(flen); bc_puts("B)" as *u8) } else { if kc==80 { bc_puts("ABSENT-PLAN -> " as *u8); sys_write(1, ((rows as i64)+fo[5]) as *u8, fl[5]) } else { bc_puts("ABSENT -> " as *u8); sys_write(1, ((rows as i64)+fo[5]) as *u8, fl[5]) } } } 147 bc_puts("\n" as *u8) 148 // html row 149 hp = bc_app(hb, hp, "<tr><td style=\x27padding:3px 12px\x27>\x00" as *u8) 150 hp = bc_appn(hb, hp, ((rows as i64)+fo[0]) as *u8, fl[0]) 151 hp = bc_app(hb, hp, "</td><td style=\x27padding:3px 12px\x27>\x00" as *u8) 152 hp = bc_appn(hb, hp, ((rows as i64)+fo[1]) as *u8, fl[1]) 153 hp = bc_app(hb, hp, "</td><td style=\x27padding:3px 12px;color:\x00" as *u8) 154 if isneg==1 { if negviol==1 { hp = bc_app(hb, hp, "#f43f5e\x27>NEG-VIOLATION\x00" as *u8) } else { hp = bc_app(hb, hp, "#7c8db5\x27>NEG-OK\x00" as *u8) } } 155 else { if st==1 { hp = bc_app(hb, hp, "#22c55e\x27>PRESENT\x00" as *u8) } else { hp = bc_app(hb, hp, "#f59e0b\x27>ABSENT\x00" as *u8) } } 156 hp = bc_app(hb, hp, "</td><td style=\x27padding:3px 12px;color:#9fb2dd\x27>\x00" as *u8) 157 if kc==70 { hp = bc_appn(hb, hp, ((rows as i64)+fo[3]) as *u8, fl[3]) } else { hp = bc_appn(hb, hp, ((rows as i64)+fo[5]) as *u8, fl[5]) } 158 hp = bc_app(hb, hp, "</td></tr>\x00" as *u8) 159 } 160 } 161 162 let tl: i64 = total[0]+total[1]+total[2] 163 let pr: i64 = present[0]+present[1]+present[2] 164 var permil: i64 = 0 165 if tl>0 { permil = (pr*1000)/tl } 166 bc_puts(" score: linux " as *u8); bc_num(present[0]); bc_puts("/" as *u8); bc_num(total[0]) 167 bc_puts(" windows " as *u8); bc_num(present[1]); bc_puts("/" as *u8); bc_num(total[1]) 168 bc_puts(" nishios " as *u8); bc_num(present[2]); bc_puts("/" as *u8); bc_num(total[2]) 169 bc_puts(" total " as *u8); bc_num(pr); bc_puts("/" as *u8); bc_num(tl); bc_puts(" = " as *u8); bc_num(permil); bc_puts(" permil\n" as *u8) 170 171 // census integrity gate (NOT the score): rows parsed, negctl clean, honesty rows intact 172 var pass: i64=0 173 var ttl: i64=0 174 ttl=ttl+1; bc_puts(" C1 all census rows parsed (21): " as *u8); if nrows==21 { pass=pass+1; bc_puts("PASS\n" as *u8) } else { bc_puts("FAIL\n" as *u8) } 175 ttl=ttl+1; bc_puts(" C2 NEG control absent (liar-kill armed, not fired): " as *u8); if negviol==0 { pass=pass+1; bc_puts("PASS\n" as *u8) } else { bc_puts("FAIL\n" as *u8) } 176 ttl=ttl+1; bc_puts(" C3 honesty intact (>=1 named PLAN gap remains; row count pinned by C1): " as *u8); if nplan>=1 { pass=pass+1; bc_puts("PASS\n" as *u8) } else { bc_puts("FAIL\n" as *u8) } 177 178 // finish + write the UI surface and the status line 179 hp = bc_app(hb, hp, "</table><p style=\x27margin-top:14px\x27>score: linux \x00" as *u8) 180 hp = bc_appd(hb, hp, present[0]); hp = bc_app(hb, hp, "/\x00" as *u8); hp = bc_appd(hb, hp, total[0]) 181 hp = bc_app(hb, hp, " -- windows \x00" as *u8); hp = bc_appd(hb, hp, present[1]); hp = bc_app(hb, hp, "/\x00" as *u8); hp = bc_appd(hb, hp, total[1]) 182 hp = bc_app(hb, hp, " -- nishios \x00" as *u8); hp = bc_appd(hb, hp, present[2]); hp = bc_app(hb, hp, "/\x00" as *u8); hp = bc_appd(hb, hp, total[2]) 183 hp = bc_app(hb, hp, " -- total \x00" as *u8); hp = bc_appd(hb, hp, pr); hp = bc_app(hb, hp, "/\x00" as *u8); hp = bc_appd(hb, hp, tl) 184 hp = bc_app(hb, hp, " = <b>\x00" as *u8); hp = bc_appd(hb, hp, permil) 185 hp = bc_app(hb, hp, " permil</b></p><p style=\x27color:#7c8db5\x27>Every PRESENT cell is a mechanical on-disk probe; every gap NAMES its build organ and self-flips when that rung lands. NishiOS browser proof: <a style=\x27color:#8ab4ff\x27 href=\x27nishios_browser.html\x27>nishios_browser.html</a></p></body></html>\x00" as *u8) 186 let hw: i64 = bc_write_file("knowledge/status/browser_os_census.html\x00" as *u8, hb, hp) 187 188 let lb: *u8 = sys_mmap(512) 189 var lpn: i64 = 0 190 lpn = bc_app(lb, lpn, "BROWSER-OS-CENSUS linux=\x00" as *u8); lpn = bc_appd(lb, lpn, present[0]); lpn = bc_app(lb, lpn, "/\x00" as *u8); lpn = bc_appd(lb, lpn, total[0]) 191 lpn = bc_app(lb, lpn, " windows=\x00" as *u8); lpn = bc_appd(lb, lpn, present[1]); lpn = bc_app(lb, lpn, "/\x00" as *u8); lpn = bc_appd(lb, lpn, total[1]) 192 lpn = bc_app(lb, lpn, " nishios=\x00" as *u8); lpn = bc_appd(lb, lpn, present[2]); lpn = bc_app(lb, lpn, "/\x00" as *u8); lpn = bc_appd(lb, lpn, total[2]) 193 lpn = bc_app(lb, lpn, " permil=\x00" as *u8); lpn = bc_appd(lb, lpn, permil) 194 lpn = bc_app(lb, lpn, " neg=\x00" as *u8); lpn = bc_appd(lb, lpn, negviol) 195 if pass==ttl { lpn = bc_app(lb, lpn, " verdict=GREEN\x0A\x00" as *u8) } else { lpn = bc_app(lb, lpn, " verdict=RED\x0A\x00" as *u8) } 196 let lw: i64 = bc_write_file("knowledge/status/browser_os_census.log\x00" as *u8, lb, lpn) 197 198 ttl=ttl+1; bc_puts(" C4 UI surface + status line written: " as *u8); if hw>0 { if lw>0 { pass=pass+1; bc_puts("PASS\n" as *u8) } else { bc_puts("FAIL\n" as *u8) } } else { bc_puts("FAIL\n" as *u8) } 199 200 bc_puts("BROWSER-OS-CENSUS-GATE passed " as *u8); bc_num(pass); bc_puts("/" as *u8); bc_num(ttl) 201 if pass==ttl { bc_puts(" verdict=GREEN (open knowledge/status/browser_os_census.html)\n" as *u8); sys_exit(0); return 0 } 202 bc_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1 203}