nx_nishi_coverage.nx source
↩ module page · 91 lines · 6305 B
1// nx_nishi_coverage.nx -- the MEASURED "use only our system" census. Reads the daily-driver tool
2// catalog (knowledge/registry/replacement_tools.tsv) and scores how much of the standard toolset
3// has a sovereign Nishi replacement: VERIFIED(3)/PARTIAL(2)/EXISTS(1)/GAP(0), coverage in per-mil.
4// Renders a CLI table AND an HTML "Nishi system status" window (the GUI half). Honest: counts the
5// real catalog, no fabrication; the catalog flags gaps as gaps. No hardware writes (Rule 26).
6// expect_exit: 0 license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
9const K_MAGIC_8192: i64 = 8192
10
11func cv_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
13// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
14// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
15// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
16func cv_putn(v: i64) -> i64 { nxi_out(v); return 0 }
17func cv_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while 1==1 { if a[i]!=b[i] { return 0 } if a[i]==(0 as u8) { return 1 } i=i+1 } return 1 }
18func wa(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ buf[off+i]=s[i]; i=i+1 } return off+i }
19func wn(buf: *u8, off: i64, v: i64) -> i64 { var o: i64=off; if v==0 { buf[o]=48 as u8; return o+1 } let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var i: i64=0; while i<k { buf[o+i]=t[k-1-i]; i=i+1 } return o+k }
20
21// extract field f (0-based) of line buf[ls..le) into out (NUL-term); returns length.
22func cv_field(buf: *u8, ls: i64, le: i64, f: i64, out: *u8) -> i64 {
23 var cur: i64=0
24 var i: i64=ls
25 var o: i64=0
26 while cur<f { if i>=le { out[0]=0 as u8; return 0 } if buf[i]==(9 as u8) { cur=cur+1 } i=i+1 }
27 var go: i64=1
28 while go==1 { if i>=le { go=0 } else { if buf[i]==(9 as u8) { go=0 } else { out[o]=buf[i]; o=o+1; i=i+1 } } }
29 out[o]=0 as u8
30 return o
31}
32
33func main() -> i64 {
34 let lenp: *i64 = sys_mmap(8) as *i64
35 let tsv: *u8 = sys_read_file("knowledge/registry/replacement_tools.tsv\x00" as *u8, lenp)
36 if (tsv as i64)==0 { cv_puts("replacement_tools.tsv not found\n" as *u8); sys_exit(1); return 1 }
37 let n: i64 = lenp[0]
38
39 var nv: i64=0
40 var np: i64=0
41 var ne: i64=0
42 var ng: i64=0
43 var nt: i64=0
44 let sbuf: *u8 = sys_mmap(64)
45
46 var i: i64=0
47 while i<n {
48 let ls: i64=i
49 var le: i64=i
50 var f: i64=1
51 while f==1 { if le>=n { f=0 } else { if tsv[le]==(0x0A as u8) { f=0 } else { le=le+1 } } }
52 var lineend: i64=le
53 if lineend>ls { if tsv[lineend-1]==(0x0D as u8) { lineend=lineend-1 } }
54 if lineend>ls { if tsv[ls]!=(0x23 as u8) {
55 cv_field(tsv, ls, lineend, 3, sbuf)
56 nt=nt+1
57 if cv_streq(sbuf, "VERIFIED\x00" as *u8)==1 { nv=nv+1 } else { if cv_streq(sbuf, "PARTIAL\x00" as *u8)==1 { np=np+1 } else { if cv_streq(sbuf, "EXISTS\x00" as *u8)==1 { ne=ne+1 } else { ng=ng+1 } } }
58 } }
59 i=le+1
60 }
61
62 var cov: i64 = 0
63 if nt>0 { cov = ((nv*3)+(np*2)+ne)*1000/(nt*3) }
64
65 cv_puts("NISHI 'USE ONLY OUR SYSTEM' COVERAGE CENSUS (measured, from the catalog)\n" as *u8)
66 cv_puts(" tools=" as *u8); cv_putn(nt); cv_puts(" VERIFIED=" as *u8); cv_putn(nv); cv_puts(" PARTIAL=" as *u8); cv_putn(np); cv_puts(" EXISTS=" as *u8); cv_putn(ne); cv_puts(" GAP=" as *u8); cv_putn(ng); cv_puts("\n" as *u8)
67 cv_puts(" coverage=" as *u8); cv_putn(cov); cv_puts(" permil (VERIFIED=3 PARTIAL=2 EXISTS=1 GAP=0, weighted)\n" as *u8)
68 cv_puts(" biggest GAPs to a bootable Nishi USB: gui-desktop, coreutils(ls/cat/cp), boot-usb(x86), editor, ai-assistant(Claude bridge)\n" as *u8)
69
70 // ---- HTML 'Nishi system status' window ----
71 let html: *u8 = sys_mmap(K_MAGIC_8192)
72 var o: i64 = 0
73 o = wa(html, o, "<!doctype html><html><head><meta charset=utf-8><title>Nishi system - use only our system</title><style>" as *u8)
74 o = wa(html, o, "body{background:#070707;color:#3f6;font-family:ui-monospace,monospace;margin:0;padding:28px}" as *u8)
75 o = wa(html, o, ".crt{max-width:760px;margin:0 auto;border:2px solid #1a5;border-radius:10px;padding:22px;box-shadow:0 0 30px #0f433a inset}" as *u8)
76 o = wa(html, o, "h1{color:#7fd;font-size:14px;letter-spacing:2px}.bar{height:22px;background:#022;border:1px solid #094;border-radius:4px;overflow:hidden;margin:10px 0}" as *u8)
77 o = wa(html, o, ".fill{height:100%;background:linear-gradient(90deg,#0a6,#5f8)}.hud{color:#9fb;font-size:13px;line-height:1.8}.dim{color:#6a8}</style></head><body><div class=crt>" as *u8)
78 o = wa(html, o, "<h1>NISHI · USE ONLY OUR SYSTEM · COVERAGE</h1>" as *u8)
79 o = wa(html, o, "<div class=bar><div class=fill style=width:" as *u8); o = wn(html, o, cov/10); o = wa(html, o, "%></div></div>" as *u8)
80 o = wa(html, o, "<div class=hud>coverage <b>" as *u8); o = wn(html, o, cov); o = wa(html, o, " permil</b> across " as *u8); o = wn(html, o, nt); o = wa(html, o, " daily-driver tools<br>" as *u8)
81 o = wa(html, o, "VERIFIED " as *u8); o = wn(html, o, nv); o = wa(html, o, " · PARTIAL " as *u8); o = wn(html, o, np); o = wa(html, o, " · EXISTS " as *u8); o = wn(html, o, ne); o = wa(html, o, " · GAP " as *u8); o = wn(html, o, ng); o = wa(html, o, "<br>" as *u8)
82 o = wa(html, o, "<span class=dim>biggest gaps to a bootable Nishi USB: gui-desktop · coreutils(ls/cat/cp) · x86-usb-boot · editor · Claude bridge</span><br>" as *u8)
83 o = wa(html, o, "<span class=dim>data layer = the UXF formats (content-addressed); kernel boots on the sovereign rv64 emu</span>" as *u8)
84 o = wa(html, o, "</div></div></body></html>" as *u8)
85 let fd: i64 = sys_openat_wr("knowledge/status/nishi_coverage.html\x00" as *u8, 0x1a4)
86 if fd>0 { sys_write(fd, html, o); sys_close(fd); cv_puts(" wrote knowledge/status/nishi_coverage.html (open in a browser)\n" as *u8) }
87
88 cv_puts("NISHI-COVERAGE verdict=GREEN (measured census, honest gaps)\n" as *u8)
89 sys_exit(0)
90 return 0
91}