code wiki / (root) / nx_cap_census.nx

nx_cap_census.nx source

↩ module page · 639 lines · 41762 B

1// nx_cap_census.nx -- THE NISHI CAPABILITY DRIVER (unified, measurement-first). ONE engine measures how SOTA 2// any TARGET is, replacing the scattered per-lane census organs. Data-driven: a target T is defined by 3// knowledge/registry/T_capabilities.conf (cols: feature<TAB>surface<TAB>status<TAB>file<TAB>marker<TAB>note); 4// the set of targets is knowledge/registry/capability_targets.conf. SURFACES ARE DYNAMIC -- discovered from 5// the rows, so each target brings its own taxonomy (torrent: acquire..ops; protocol: core..advanced; the next 6// target: whatever it declares). LIAR-KILL: a HAVE/PARTIAL opens the repo-relative `file` and requires the 7// `marker` substring present (marker "-"=existence-only); a missing file OR absent marker flips the claim to 8// UNGROUNDED (counted as GAP + flagged) -- so a capability can never be asserted without the code on disk. 9// nx_cap_census -> ECOSYSTEM SCOREBOARD: one SOTA line per target + the overall number 10// nx_cap_census all -> same 11// nx_cap_census <target> -> full per-surface census + gap roadmap (the build order to 1000) for one target 12// Durable ecosystem log -> knowledge/status/capability_ecosystem_census.log. license_tier: ORIGINAL 13import "nx_str.nx" 14import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 15import "nx_syscalls.nx" 16import "nx_flatstore_flip.nx" // SSOT = sovereign seg-store on the info plane; the flat .conf is migrate-source only 17const CAP_MAGIC_4096: i64 = 4096 18const CAP_MAGIC_65536: i64 = 65536 19const CAP_MAGIC_65000: i64 = 65000 20const CAP_MAGIC_131072: i64 = 131072 21const CAP_MAGIC_131000: i64 = 131000 22const CAP_MAGIC_200000: i64 = 200000 23const CAP_MAGIC_524288: i64 = 524288 24const CAP_MAGIC_20000: i64 = 20000 25const CAP_MAGIC_16384: i64 = 16384 26const CAP_MAGIC_16000: i64 = 16000 27 28const CAP_MANIFEST: *u8 = "knowledge/registry/capability_targets.conf" 29const CAP_ROWKEY: *u8 = "cap:row:" 30const CAP_ECOLOG: *u8 = "knowledge/status/capability_ecosystem_census.log" 31 32func cp(s: *u8) -> i64 { sys_write(1, s, nx_str_len(s)); return 0 } 33// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 34// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 35// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 36// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 37func cnum(v: i64) -> i64 { nxi_out(v); return 0 } 38func cwf(fd: i64, s: *u8) -> i64 { if fd>=0 { sys_write(fd, s, nx_str_len(s)) } return 0 } 39// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 40// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 41// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 42// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 43func cwn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 44 45func cap_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if a[i]!=b[i] { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 } 46func cap_app(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8) { dst[off+i]=s[i]; i=i+1 } return off+i } 47func cap_field(buf: *u8, ls: i64, le: i64, n: i64, out: *u8) -> i64 { 48 var fi: i64=0; var i: i64=ls; var o: i64=0 49 while i<le { 50 if buf[i]==(9 as u8) { if fi==n { out[o]=0 as u8; return 1 } fi=fi+1 } else { if fi==n { out[o]=buf[i]; o=o+1 } } 51 i=i+1 52 } 53 if fi==n { out[o]=0 as u8; return 1 } 54 return 0 55} 56func cap_contains(hay: *u8, hn: i64, needle: *u8) -> i64 { 57 var nn: i64=0; while needle[nn]!=(0 as u8) { nn=nn+1 } 58 if nn==0 { return 1 } 59 var i: i64=0 60 while i+nn<=hn { 61 var j: i64=0; var ok: i64=1 62 while j<nn { if hay[i+j]!=needle[j] { ok=0; j=nn } else { j=j+1 } } 63 if ok==1 { return 1 } 64 i=i+1 65 } 66 return 0 67} 68// LIAR-KILL grounding: open the repo-relative file; require the marker substring (marker "-"=existence-only). 69func cap_grounded(file: *u8, marker: *u8, fbuf: *u8, fcap: i64) -> i64 { 70 if cap_streq(file,"-" as *u8)==1 { return 0 } 71 let fd: i64=sys_openat_rd(file); if fd<0 { return 0 } 72 var tot: i64=0; var r: i64=1 73 while r>0 { let dst: *u8=((fbuf as i64)+tot) as *u8; r=sys_read(fd,dst,fcap-tot); if r>0 { tot=tot+r } if tot>=fcap { r=0 } } 74 sys_close(fd) 75 if cap_streq(marker,"-" as *u8)==1 { return 1 } 76 return cap_contains(fbuf, tot, marker) 77} 78// dynamic surface registry: register-or-find a surface label, returns its index (cap 32). 79func cap_surf_reg(labs: *i64, nlab: *i64, s: *u8) -> i64 { 80 var i: i64=0 81 while i<nlab[0] { if cap_streq(labs[i] as *u8, s)==1 { return i } i=i+1 } 82 let idx: i64=nlab[0] 83 if idx>=32 { return 31 } 84 let cp2: *u8=sys_mmap(64); var k: i64=0; while s[k]!=(0 as u8) { if k<63 { cp2[k]=s[k] } k=k+1 } cp2[k]=0 as u8 85 labs[idx]=cp2 as i64; nlab[0]=idx+1 86 return idx 87} 88func cap_pct(h: i64, p: i64, g: i64) -> i64 { let t: i64=h+p+g; if t<=0 { return 0 } return (h*2+p)*1000/(t*2) } 89// find the byte index just AFTER `needle` in buf[0,n); -1 if absent. (drift-check log parsing) 90func cap_find_after(buf: *u8, n: i64, needle: *u8) -> i64 { 91 var nn: i64=0; while needle[nn]!=(0 as u8) { nn=nn+1 } 92 if nn==0 { return 0-1 } 93 var i: i64=0 94 while i+nn<=n { 95 var j: i64=0; var ok: i64=1 96 while j<nn { if buf[i+j]!=needle[j] { ok=0; j=nn } else { j=j+1 } } 97 if ok==1 { return i+nn } 98 i=i+1 99 } 100 return 0-1 101} 102func cap_int_at(buf: *u8, n: i64, pos: i64) -> i64 { 103 if pos<0 { return 0-1 } 104 var i: i64=pos; var v: i64=0; var any: i64=0 105 while i<n { let c: i64=buf[i] as i64; if c>=48 { if c<=57 { v=v*10+(c-48); any=1; i=i+1 } else { i=n } } else { i=n } } 106 if any==0 { return 0-1 } 107 return v 108} 109// the target's score recorded in a prior ecosystem log ("<target> score=<n> ..."); -1 if absent. 110func cap_prev_score(buf: *u8, n: i64, target: *u8) -> i64 { 111 let needle: *u8=sys_mmap(128); var o: i64=0; o=cap_app(needle,o,target); o=cap_app(needle,o," score=" as *u8); needle[o]=0 as u8 112 let p: i64=cap_find_after(buf,n,needle); if p<0 { return 0-1 } 113 return cap_int_at(buf,n,p) 114} 115// build "knowledge/registry/<target>_capabilities.conf" into out. 116func cap_conf_path(target: *u8, out: *u8) -> i64 { 117 var o: i64=0; o=cap_app(out,o,"knowledge/registry/" as *u8); o=cap_app(out,o,target); o=cap_app(out,o,"_capabilities.conf" as *u8); out[o]=0 as u8; return o 118} 119func cap_srcs_path(target: *u8, out: *u8) -> i64 { 120 var o: i64=0; o=cap_app(out,o,"knowledge/registry/" as *u8); o=cap_app(out,o,target); o=cap_app(out,o,"_sota_sources.conf" as *u8); out[o]=0 as u8; return o 121} 122// the sovereign seg-store (SSOT on the Nishi information plane) for a target's capability rows 123func cap_store_path(target: *u8, out: *u8) -> i64 { 124 var o: i64=0; o=cap_app(out,o,"knowledge/store/cap_" as *u8); o=cap_app(out,o,target); out[o]=0 as u8; return o 125} 126// SELF-LOCATE: grounding needs CWD = the repo root (has runtime/, knowledge/, sites/). A scheduler/tool execs us 127// from an arbitrary CWD but passes argv[0] = our absolute path. If our parent dir is named "runtime" (i.e. the 128// elf lives at <root>/runtime/<name>), chdir to <root> so all relative grounding paths resolve. A local run 129// (argv[0]=/tmp/<name>, parent "tmp") is left untouched, so CWD stays the repo we were launched from. 130func cap_self_locate(argv: *i64) -> i64 { 131 // A. buildroot visible from CWD (NAS tools daemon CWD=nishihost has buildroot/knowledge/registry) -- PREFER it 132 let fa: i64 = sys_openat_rd("buildroot/knowledge/registry" as *u8); if fa>=0 { sys_close(fa); sys_chdir("buildroot" as *u8); return 1 } 133 // B. already at a repo root (local run: CWD has knowledge/registry) 134 let fb: i64 = sys_openat_rd("knowledge/registry" as *u8); if fb>=0 { sys_close(fb); return 0 } 135 // C/D. derive from our own ABSOLUTE path argv[0] so a scheduler can launch us from ANY CWD. 136 let a0: *u8 = argv[0] as *u8 137 if (a0 as i64)==0 { return 0 } 138 var n: i64=0; while a0[n]!=(0 as u8) { n=n+1 } 139 var ls: i64=0-1; var k: i64=0; while k<n { if a0[k]==(47 as u8) { ls=k } k=k+1 } 140 if ls<0 { return 0 } 141 let ed: *u8=sys_mmap(CAP_MAGIC_4096); var i: i64=0; while i<ls { ed[i]=a0[i]; i=i+1 } ed[ls]=0 as u8 // exe dir 142 // C. <exedir>/buildroot (elf promoted next to buildroot -- the clockjob case) 143 let c1: *u8=sys_mmap(CAP_MAGIC_4096); var o: i64=0; o=cap_app(c1,o,ed); o=cap_app(c1,o,"/buildroot" as *u8); c1[o]=0 as u8 144 let c1r: *u8=sys_mmap(CAP_MAGIC_4096); var q: i64=0; q=cap_app(c1r,q,c1); q=cap_app(c1r,q,"/knowledge/registry" as *u8); c1r[q]=0 as u8 145 let fc: i64 = sys_openat_rd(c1r); if fc>=0 { sys_close(fc); sys_chdir(c1); return 3 } 146 // D. <exedir> itself is the repo root (elf at <root>/<name>) 147 let c2r: *u8=sys_mmap(CAP_MAGIC_4096); var r: i64=0; r=cap_app(c2r,r,ed); r=cap_app(c2r,r,"/knowledge/registry" as *u8); c2r[r]=0 as u8 148 let fd: i64 = sys_openat_rd(c2r); if fd>=0 { sys_close(fd); sys_chdir(ed); return 4 } 149 return 0 150} 151// count the EXTERNAL SOTA sources this target is measured against (non-comment, non-blank rows). 152func cap_count_sources(target: *u8) -> i64 { 153 let p: *u8=sys_mmap(512); cap_srcs_path(target, p) 154 let fd: i64=sys_openat_rd(p); if fd<0 { return 0 } 155 let b: *u8=sys_mmap(CAP_MAGIC_65536); var n: i64=0; var r: i64=1 156 while r>0 { let dst: *u8=((b as i64)+n) as *u8; r=sys_read(fd,dst,CAP_MAGIC_65000-n); if r>0 { n=n+r } if n>=CAP_MAGIC_65000 { r=0 } } 157 sys_close(fd) 158 var c: i64=0; var ls: i64=0 159 while ls<n { 160 var le: i64=ls; var eol: i64=0 161 while eol==0 { if le>=n { eol=1 } else { if b[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 162 if le>ls { if b[ls]!=(35 as u8) { if b[ls]!=(13 as u8) { c=c+1 } } } 163 ls=le+1 164 } 165 return c 166} 167// print the external SOTA frontier this target is measured against (the researcher's fetch targets). 168func cap_print_sources(target: *u8) -> i64 { 169 let p: *u8=sys_mmap(512); cap_srcs_path(target, p) 170 let fd: i64=sys_openat_rd(p); if fd<0 { cp("\n TARGET "); cp(target); cp(" -- (no SOTA sources registry)\n" as *u8); return 0 } 171 let b: *u8=sys_mmap(CAP_MAGIC_65536); var n: i64=0; var r: i64=1 172 while r>0 { let dst: *u8=((b as i64)+n) as *u8; r=sys_read(fd,dst,CAP_MAGIC_65000-n); if r>0 { n=n+r } if n>=CAP_MAGIC_65000 { r=0 } } 173 sys_close(fd) 174 cp("\n TARGET "); cp(target); cp(" -- measured against the external frontier:\n" as *u8) 175 let f0: *u8=sys_mmap(128); let f1: *u8=sys_mmap(256); let f2: *u8=sys_mmap(512); let f3: *u8=sys_mmap(256) 176 var ls: i64=0 177 while ls<n { 178 var le: i64=ls; var eol: i64=0 179 while eol==0 { if le>=n { eol=1 } else { if b[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 180 if le>ls { if b[ls]!=(35 as u8) { 181 if cap_field(b,ls,le,0,f0)==1 { cap_field(b,ls,le,1,f1); cap_field(b,ls,le,2,f2); cap_field(b,ls,le,3,f3) 182 cp(" - "); cp(f0); cp(" [establishes: "); cp(f3); cp("]\n "); cp(f1); cp("\n "); cp(f2); cp("\n" as *u8) 183 } 184 } } 185 ls=le+1 186 } 187 return 0 188} 189 190// census ONE target. detail=1 -> print per-surface + gap roadmap. out4[0..3]=H,P,G,UNG. returns score, or -1 if conf missing. 191func cap_census_one(target: *u8, detail: i64, fbuf: *u8, out4: *i64) -> i64 { 192 // READ FROM THE SOVEREIGN SEG-STORE (SSOT on the info plane); self-seed once from the migrate-source .conf. 193 let confp: *u8=sys_mmap(512); cap_conf_path(target, confp) 194 let store: *u8=sys_mmap(512); cap_store_path(target, store) 195 let cb: *u8=sys_mmap(CAP_MAGIC_131072) 196 var cn: i64=fsf_read_all(store, CAP_ROWKEY, cb, CAP_MAGIC_131000) 197 if cn<=0 { 198 let tp: *i64=sys_mmap(16) as *i64; let vp: *i64=sys_mmap(16) as *i64 199 fsf_migrate(confp, store, CAP_ROWKEY, tp, vp) 200 cn=fsf_read_all(store, CAP_ROWKEY, cb, CAP_MAGIC_131000) 201 } 202 if cn<=0 { out4[0]=0; out4[1]=0; out4[2]=0; out4[3]=0; return 0-1 } 203 204 let labs: *i64=sys_mmap(32*8) as *i64; let nlab: *i64=sys_mmap(8) as *i64; nlab[0]=0 205 let sh: *i64=sys_mmap(32*8) as *i64; let sp: *i64=sys_mmap(32*8) as *i64; let sg: *i64=sys_mmap(32*8) as *i64 206 var z: i64=0; while z<32 { sh[z]=0; sp[z]=0; sg[z]=0; z=z+1 } 207 var H: i64=0; var P: i64=0; var G: i64=0; var UNG: i64=0 208 let feat: *u8=sys_mmap(256); let surf: *u8=sys_mmap(64); let stat: *u8=sys_mmap(32); let file: *u8=sys_mmap(512); let mark: *u8=sys_mmap(256) 209 let gapbuf: *u8=sys_mmap(CAP_MAGIC_200000); var go: i64=0 210 let ungbuf: *u8=sys_mmap(CAP_MAGIC_65536); var uo: i64=0 211 212 var ls: i64=0 213 while ls<cn { 214 var le: i64=ls; var eol: i64=0 215 while eol==0 { if le>=cn { eol=1 } else { if cb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 216 if le>ls { if cb[ls]!=(35 as u8) { 217 if cap_field(cb,ls,le,0,feat)==1 { if cap_field(cb,ls,le,1,surf)==1 { if cap_field(cb,ls,le,2,stat)==1 { 218 cap_field(cb,ls,le,3,file); cap_field(cb,ls,le,4,mark) 219 let si: i64=cap_surf_reg(labs,nlab,surf) 220 var st: i64=2 221 if cap_streq(stat,"HAVE" as *u8)==1 { st=2 } else { if cap_streq(stat,"PARTIAL" as *u8)==1 { st=1 } else { st=0 } } 222 if st>0 { if cap_grounded(file,mark,fbuf,CAP_MAGIC_524288)==0 { 223 UNG=UNG+1; st=0 224 uo=cap_app(ungbuf,uo," !! UNGROUNDED " as *u8); uo=cap_app(ungbuf,uo,feat); uo=cap_app(ungbuf,uo," (" as *u8); uo=cap_app(ungbuf,uo,file); uo=cap_app(ungbuf,uo," :: " as *u8); uo=cap_app(ungbuf,uo,mark); uo=cap_app(ungbuf,uo,")\n" as *u8) 225 } } 226 if st==2 { sh[si]=sh[si]+1; H=H+1 } 227 if st==1 { sp[si]=sp[si]+1; P=P+1 } 228 if st==0 { sg[si]=sg[si]+1; G=G+1 229 go=cap_app(gapbuf,go,"[" as *u8); go=cap_app(gapbuf,go,surf); go=cap_app(gapbuf,go,"] " as *u8); go=cap_app(gapbuf,go,feat); go=cap_app(gapbuf,go,"\n" as *u8) 230 } 231 } } } 232 } } 233 ls=le+1 234 } 235 let TOT: i64=H+P+G 236 var score: i64=0; if TOT>0 { score=(H*2+P)*1000/(TOT*2) } 237 if detail==1 { 238 cp("\n== TARGET "); cp(target); cp(" == score="); cnum(score); cp("/1000 (HAVE "); cnum(H); cp(" / PARTIAL "); cnum(P); cp(" / GAP "); cnum(G); cp(" of "); cnum(TOT); cp(")\n" as *u8) 239 cp("-- per-surface (HAVE/PARTIAL/GAP -> permille), in declared order --\n" as *u8) 240 var t: i64=0; while t<nlab[0] { 241 cp(" "); cp(labs[t] as *u8); cp(" "); cnum(sh[t]); cp("/"); cnum(sp[t]); cp("/"); cnum(sg[t]); cp(" -> "); cnum(cap_pct(sh[t],sp[t],sg[t])); cp("/1000\n" as *u8) 242 t=t+1 243 } 244 if UNG>0 { cp("-- LIAR-KILL: "); cnum(UNG); cp(" UNGROUNDED --\n" as *u8); sys_write(1,ungbuf,uo) } 245 else { cp("-- LIAR-KILL: 0 ungrounded (every HAVE/PARTIAL grounded on disk) --\n" as *u8) } 246 cp("-- GAP ROADMAP (build order to 1000, "); cnum(G); cp(" items) --\n" as *u8); sys_write(1,gapbuf,go) 247 } 248 out4[0]=H; out4[1]=P; out4[2]=G; out4[3]=UNG 249 return score 250} 251 252// BEHAVIOR-PROOF grounding: a capability's optional probe (col 6) "gate:<name>" is PROVEN iff that gate/test 253// organ is on disk (runtime/<name>.nx or runtime/_hdl_build/<name>.nx) -- the behavior has a real GATE, not 254// just the code. (Escalation of presence-grounding; RUNNING the gate is the next tier.) 255func cap_probe_grounded(probe: *u8) -> i64 { 256 if probe[0]==(0 as u8) { return 0 } 257 let pre: *u8="gate:" as *u8; var i: i64=0; while i<5 { if probe[i]!=pre[i] { return 0 } i=i+1 } 258 let nm: *u8=((probe as i64)+5) as *u8 259 let p1: *u8=sys_mmap(512); var o: i64=0; o=cap_app(p1,o,"runtime/" as *u8); o=cap_app(p1,o,nm); o=cap_app(p1,o,".nx" as *u8); p1[o]=0 as u8 260 let f1: i64=sys_openat_rd(p1); if f1>=0 { sys_close(f1); return 1 } 261 let p2: *u8=sys_mmap(512); var o2: i64=0; o2=cap_app(p2,o2,"runtime/_hdl_build/" as *u8); o2=cap_app(p2,o2,nm); o2=cap_app(p2,o2,".nx" as *u8); p2[o2]=0 as u8 262 let f2: i64=sys_openat_rd(p2); if f2>=0 { sys_close(f2); return 1 } 263 return 0 264} 265// T2 RUN-THE-GATE: fork+exec the gate elf and check it PASSES (exit 0), not just that its source exists. 266// probe = "gate:<name>"; tries the built/deployed elf in a few locations. returns: -1 elf-not-found (can't run), 267// 0 ran-but-FAILED (nonzero exit), 1 ran-and-PASSED (exit 0). This is BEHAVIOR PROOF, not presence. 268func cap_gate_run(probe: *u8) -> i64 { 269 let pre: *u8="gate:" as *u8; var i: i64=0; while i<5 { if probe[i]!=pre[i] { return 0-1 } i=i+1 } 270 let nm: *u8=((probe as i64)+5) as *u8 271 let cand: *u8=sys_mmap(768); var found: i64=0 272 // 1. /tmp/<name>.sov.elf (LEGACY local build output) 1b. _build/<name>.sov.elf (where the builder 273 // ACTUALLY writes) 2. <name>.elf (nishihost live tool) 3. runtime/<name>.sov.elf 274 var o: i64=0; o=cap_app(cand,o,"/tmp/" as *u8); o=cap_app(cand,o,nm); o=cap_app(cand,o,".sov.elf" as *u8); cand[o]=0 as u8 275 let f1: i64=sys_openat_rd(cand); if f1>=0 { sys_close(f1); found=1 } 276 // ---- 1b ADDED 2026-08-17: THE CHAIN NEVER PROBED WHERE THE BUILDER WRITES ---- 277 // nx_sov_build_run anchors CWD to buildroot/ and emits _build/<name>.sov.elf; it has not written /tmp 278 // since 2026-07-30. This chain is NOT broken -- probes 2 and 4 still find PROMOTED gate elfs -- but a 279 // gate that is freshly BUILT and not yet promoted returned -1 "elf-not-found (can't run)" while a 280 // perfectly good artifact sat in _build/. Measured context: the estate has ~2,287 gate sources and 281 // ~135 deployed, so unpromoted is the COMMON case and this census under-reported runnable gates. 282 // * A FALLBACK CHAIN THAT OMITS THE PRIMARY LOCATION DEGRADES QUIETLY -- it keeps working for the 283 // already-shipped and goes blind exactly on the freshly-built, which is what a census is for. 284 // ORDERED AFTER /tmp DELIBERATELY: strictly additive, so any path that resolved before still resolves 285 // identically and this can only find MORE, never something different. 286 // NOT bp_artifact (nx_buildpath_lib): that resolver answers "where is the BUILD ARTIFACT", while this 287 // chain deliberately also accepts PROMOTED .elf locations -- a different contract, so composing it 288 // here would silently change precedence rather than extend reach. 289 if found==0 { o=0; o=cap_app(cand,o,"_build/" as *u8); o=cap_app(cand,o,nm); o=cap_app(cand,o,".sov.elf" as *u8); cand[o]=0 as u8; let f1b: i64=sys_openat_rd(cand); if f1b>=0 { sys_close(f1b); found=1 } } 290 if found==0 { o=0; o=cap_app(cand,o,nm); o=cap_app(cand,o,".elf" as *u8); cand[o]=0 as u8; let f2: i64=sys_openat_rd(cand); if f2>=0 { sys_close(f2); found=1 } } 291 if found==0 { o=0; o=cap_app(cand,o,"runtime/" as *u8); o=cap_app(cand,o,nm); o=cap_app(cand,o,".sov.elf" as *u8); cand[o]=0 as u8; let f3: i64=sys_openat_rd(cand); if f3>=0 { sys_close(f3); found=1 } } 292 // 4. ../<name>.elf : on the NAS the census self-locates to buildroot(=nishihost/buildroot), so .. = nishihost 293 // where promoted gate elfs live (nishihost/<name>.elf) 294 if found==0 { o=0; o=cap_app(cand,o,"../" as *u8); o=cap_app(cand,o,nm); o=cap_app(cand,o,".elf" as *u8); cand[o]=0 as u8; let f4: i64=sys_openat_rd(cand); if f4>=0 { sys_close(f4); found=1 } } 295 if found==0 { return 0-1 } 296 __syscall(90, cand as i64, 0x1ed, 0, 0, 0, 0) // chmod 0755 (shipped elfs aren't reliably +x) 297 let pid: i64=sys_fork() 298 if pid==0 { 299 let av: *i64=sys_mmap(32) as *i64; av[0]=cand as i64; av[1]=0 300 let ev: *i64=sys_mmap(16) as *i64; ev[0]="PATH=/usr/bin:/bin" as *u8 as i64; ev[1]=0 301 sys_execve(cand, av, ev); sys_exit(127) 302 } 303 let st: *i64=sys_mmap(16) as *i64; st[0]=0; sys_wait4(pid, st, 0) 304 let raw: i64=st[0]; let sig: i64=raw & 0x7f; let code: i64=(raw >> 8) & 0xff 305 if sig!=0 { return 0-100-sig } // crashed (signal): caller sees rr < -1 306 return code // 0 = PASS(GREEN); >0 = FAIL with that exit code 307} 308func cap_num_app(dst: *u8, off: i64, v: i64) -> i64 { 309 var o: i64=off 310 if v==0 { dst[o]=48 as u8; return o+1 } 311 var m: i64=v; if m<0 { dst[o]=45 as u8; o=o+1; m=0-m } 312 let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 313 while k>0 { k=k-1; dst[o]=t[k]; o=o+1 } 314 return o 315} 316// VERIFY one target: RUN every behavior-proven capability's gate, count how many PASS. out3[0]=have, 317// out3[1]=have-a-gate, out3[2]=gate-passes. returns verified permille (passing/have). 318func cap_verify_one(target: *u8, detail: i64, out3: *i64) -> i64 { 319 let confp: *u8=sys_mmap(512); cap_conf_path(target, confp) 320 let store: *u8=sys_mmap(512); cap_store_path(target, store) 321 let cb: *u8=sys_mmap(CAP_MAGIC_131072) 322 var cn: i64=fsf_read_all(store, CAP_ROWKEY, cb, CAP_MAGIC_131000) 323 if cn<=0 { let tp: *i64=sys_mmap(16) as *i64; let vp: *i64=sys_mmap(16) as *i64; fsf_migrate(confp, store, CAP_ROWKEY, tp, vp); cn=fsf_read_all(store, CAP_ROWKEY, cb, CAP_MAGIC_131000) } 324 if cn<=0 { out3[0]=0; out3[1]=0; out3[2]=0; return 0-1 } 325 var have: i64=0; var gated: i64=0; var passing: i64=0 326 let feat: *u8=sys_mmap(256); let stat: *u8=sys_mmap(32); let probe: *u8=sys_mmap(256) 327 let pbuf: *u8=sys_mmap(CAP_MAGIC_20000); var pbo: i64=0 328 var ls: i64=0 329 while ls<cn { 330 var le: i64=ls; var eol: i64=0 331 while eol==0 { if le>=cn { eol=1 } else { if cb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 332 if le>ls { if cb[ls]!=(35 as u8) { 333 if cap_field(cb,ls,le,0,feat)==1 { if cap_field(cb,ls,le,2,stat)==1 { 334 if cap_streq(stat,"HAVE" as *u8)==1 { 335 have=have+1 336 if cap_field(cb,ls,le,6,probe)==1 { if cap_probe_grounded(probe)==1 { 337 gated=gated+1 338 let rr: i64=cap_gate_run(probe) 339 pbo=cap_app(pbuf,pbo," " as *u8) 340 if rr==0 { pbo=cap_app(pbuf,pbo,"PASS " as *u8); passing=passing+1 } else { if rr==(0-1) { pbo=cap_app(pbuf,pbo,"NOELF " as *u8) } else { if rr<(0-1) { pbo=cap_app(pbuf,pbo,"CRASH sig=" as *u8); pbo=cap_num_app(pbuf,pbo,0-100-rr); pbo=cap_app(pbuf,pbo," " as *u8) } else { pbo=cap_app(pbuf,pbo,"FAIL exit=" as *u8); pbo=cap_num_app(pbuf,pbo,rr); pbo=cap_app(pbuf,pbo," " as *u8) } } } 341 pbo=cap_app(pbuf,pbo,feat); pbo=cap_app(pbuf,pbo," ["); pbo=cap_app(pbuf,pbo,probe); pbo=cap_app(pbuf,pbo,"]\n" as *u8) 342 } } 343 } 344 } } 345 } } 346 ls=le+1 347 } 348 var ver: i64=0; if have>0 { ver=passing*1000/have } 349 if detail==1 { 350 cp("\n== VERIFY "); cp(target); cp(" -- RUN the gates (behavior PASSES, not just gate-exists) ==\n" as *u8) 351 cp(" HAVE: "); cnum(have); cp(" gated: "); cnum(gated); cp(" gate PASSES: "); cnum(passing); cp("\n" as *u8) 352 sys_write(1, pbuf, pbo) 353 cp(" verified coverage: "); cnum(ver); cp("/1000 (gate ran + exited GREEN; NOELF = gate not built here)\n" as *u8) 354 let lfd: i64=sys_openat_wr("knowledge/status/capability_verify.log" as *u8, 420) 355 if lfd>=0 { cwf(lfd,"VERIFY "); cwf(lfd,target); cwf(lfd," have="); cwn(lfd,have); cwf(lfd," gated="); cwn(lfd,gated); cwf(lfd," passing="); cwn(lfd,passing); cwf(lfd," verified="); cwn(lfd,ver); cwf(lfd,"/1000\n"); sys_write(lfd,pbuf,pbo); sys_close(lfd) } 356 } 357 out3[0]=have; out3[1]=gated; out3[2]=passing 358 return ver 359} 360// JUDGE one target: of its HAVE capabilities, how many are behavior-PROVEN (cite a real gate)? out2[0]=have, 361// out2[1]=proven; returns coverage permille. Measures the "presence != works" gap the JUDGE tier closes. 362func cap_judge_one(target: *u8, detail: i64, out2: *i64) -> i64 { 363 let confp: *u8=sys_mmap(512); cap_conf_path(target, confp) 364 let store: *u8=sys_mmap(512); cap_store_path(target, store) 365 let cb: *u8=sys_mmap(CAP_MAGIC_131072) 366 var cn: i64=fsf_read_all(store, CAP_ROWKEY, cb, CAP_MAGIC_131000) 367 if cn<=0 { let tp: *i64=sys_mmap(16) as *i64; let vp: *i64=sys_mmap(16) as *i64; fsf_migrate(confp, store, CAP_ROWKEY, tp, vp); cn=fsf_read_all(store, CAP_ROWKEY, cb, CAP_MAGIC_131000) } 368 if cn<=0 { out2[0]=0; out2[1]=0; return 0-1 } 369 var have: i64=0; var proven: i64=0 370 let feat: *u8=sys_mmap(256); let stat: *u8=sys_mmap(32); let probe: *u8=sys_mmap(256) 371 let pbuf: *u8=sys_mmap(CAP_MAGIC_20000); var pbo: i64=0 372 var ls: i64=0 373 while ls<cn { 374 var le: i64=ls; var eol: i64=0 375 while eol==0 { if le>=cn { eol=1 } else { if cb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 376 if le>ls { if cb[ls]!=(35 as u8) { 377 if cap_field(cb,ls,le,0,feat)==1 { if cap_field(cb,ls,le,2,stat)==1 { 378 if cap_streq(stat,"HAVE" as *u8)==1 { 379 have=have+1 380 if cap_field(cb,ls,le,6,probe)==1 { if cap_probe_grounded(probe)==1 { proven=proven+1; pbo=cap_app(pbuf,pbo," + PROVEN " as *u8); pbo=cap_app(pbuf,pbo,feat); pbo=cap_app(pbuf,pbo," [" as *u8); pbo=cap_app(pbuf,pbo,probe); pbo=cap_app(pbuf,pbo,"]\n" as *u8) } } 381 } 382 } } 383 } } 384 ls=le+1 385 } 386 var cov: i64=0; if have>0 { cov=proven*1000/have } 387 if detail==1 { 388 cp("\n== JUDGE "); cp(target); cp(" -- behavior-proof coverage (does our HAVE actually WORK?) ==\n" as *u8) 389 cp(" HAVE capabilities: "); cnum(have); cp(" PROVEN (real behavior gate on disk): "); cnum(proven); cp(" PRESENT-ONLY: "); cnum(have-proven); cp("\n" as *u8) 390 sys_write(1, pbuf, pbo) 391 cp(" behavior-proof coverage: "); cnum(cov); cp("/1000 (presence-grounding = the code EXISTS; this = the behavior has a GATE)\n" as *u8) 392 } 393 out2[0]=have; out2[1]=proven 394 return cov 395} 396 397func main(argc: i64, argv: *i64) -> i64 { 398 cap_self_locate(argv) // chdir to the repo root so grounding + registries resolve from any launcher 399 sys_mkdir("knowledge/store" as *u8, 0x1ff) // ensure the sovereign-store dir exists (idempotent; NAS buildroot lacks it) 400 let fbuf: *u8=sys_mmap(CAP_MAGIC_524288) 401 let out4: *i64=sys_mmap(4*8) as *i64 402 // RESEED: (re)migrate every target's flat .conf -> its sovereign seg-store (run after editing a registry) 403 if argc>1 { let a1: *u8=argv[1] as *u8; if cap_streq(a1,"reseed" as *u8)==1 { 404 cp("=== nx_cap_census reseed: flat .conf -> sovereign seg-store (info-plane SSOT) ===\n" as *u8) 405 let mfd: i64=sys_openat_rd(CAP_MANIFEST); if mfd<0 { cp(" manifest unreadable\n" as *u8); sys_exit(1); return 1 } 406 let mb: *u8=sys_mmap(CAP_MAGIC_16384); var mn: i64=0; var r: i64=1 407 while r>0 { let dst: *u8=((mb as i64)+mn) as *u8; r=sys_read(mfd,dst,CAP_MAGIC_16000-mn); if r>0 { mn=mn+r } if mn>=CAP_MAGIC_16000 { r=0 } } 408 sys_close(mfd) 409 let tn2: *u8=sys_mmap(64); var ls: i64=0 410 while ls<mn { 411 var le: i64=ls; var eol: i64=0 412 while eol==0 { if le>=mn { eol=1 } else { if mb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 413 if le>ls { if mb[ls]!=(35 as u8) { 414 var o: i64=0; var i: i64=ls; while i<le { if mb[i]!=(13 as u8) { if mb[i]!=(32 as u8) { tn2[o]=mb[i]; o=o+1 } } i=i+1 } tn2[o]=0 as u8 415 if o>0 { 416 let confp: *u8=sys_mmap(512); cap_conf_path(tn2, confp) 417 let store: *u8=sys_mmap(512); cap_store_path(tn2, store) 418 let tp: *i64=sys_mmap(16) as *i64; let vp: *i64=sys_mmap(16) as *i64 419 fsf_migrate(confp, store, CAP_ROWKEY, tp, vp) 420 cp(" "); cp(tn2); cp(" rows="); cnum(tp[0]); cp(" verified="); cnum(vp[0]) 421 if vp[0]==tp[0] { if tp[0]>0 { cp(" OK\n" as *u8) } else { cp(" EMPTY\n" as *u8) } } else { cp(" !! MISMATCH\n" as *u8) } 422 } 423 } } 424 ls=le+1 425 } 426 sys_exit(0); return 0 427 } } 428 // JSON export: emit the scoreboard as JSON so the sovereign store interoperates OUT to other formats 429 if argc>1 { let a1: *u8=argv[1] as *u8; if cap_streq(a1,"json" as *u8)==1 { 430 let mfd: i64=sys_openat_rd(CAP_MANIFEST); if mfd<0 { cp("{\"error\":\"manifest\"}\n" as *u8); sys_exit(1); return 1 } 431 let mb: *u8=sys_mmap(CAP_MAGIC_16384); var mn: i64=0; var r: i64=1 432 while r>0 { let dst: *u8=((mb as i64)+mn) as *u8; r=sys_read(mfd,dst,CAP_MAGIC_16000-mn); if r>0 { mn=mn+r } if mn>=CAP_MAGIC_16000 { r=0 } } 433 sys_close(mfd) 434 cp("{\"targets\":[" as *u8) 435 let tn2: *u8=sys_mmap(64); var first: i64=1 436 var sumH: i64=0; var sumP: i64=0; var sumG: i64=0; var ls: i64=0 437 while ls<mn { 438 var le: i64=ls; var eol: i64=0 439 while eol==0 { if le>=mn { eol=1 } else { if mb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 440 if le>ls { if mb[ls]!=(35 as u8) { 441 var o: i64=0; var i: i64=ls; while i<le { if mb[i]!=(13 as u8) { if mb[i]!=(32 as u8) { tn2[o]=mb[i]; o=o+1 } } i=i+1 } tn2[o]=0 as u8 442 if o>0 { 443 let s: i64=cap_census_one(tn2, 0, fbuf, out4) 444 if s>=0 { 445 if first==0 { cp("," as *u8) } first=0 446 cp("{\"target\":\"" as *u8); cp(tn2); cp("\",\"score\":" as *u8); cnum(s) 447 cp(",\"have\":" as *u8); cnum(out4[0]); cp(",\"partial\":" as *u8); cnum(out4[1]); cp(",\"gap\":" as *u8); cnum(out4[2]); cp(",\"ungrounded\":" as *u8); cnum(out4[3]); cp("}" as *u8) 448 sumH=sumH+out4[0]; sumP=sumP+out4[1]; sumG=sumG+out4[2] 449 } 450 } 451 } } 452 ls=le+1 453 } 454 let ST: i64=sumH+sumP+sumG; var eco: i64=0; if ST>0 { eco=(sumH*2+sumP)*1000/(ST*2) } 455 cp("],\"ecosystem\":{\"score\":" as *u8); cnum(eco); cp(",\"have\":" as *u8); cnum(sumH); cp(",\"partial\":" as *u8); cnum(sumP); cp(",\"gap\":" as *u8); cnum(sumG); cp("}}\n" as *u8) 456 sys_exit(0); return 0 457 } } 458 // VERIFY mode: RUN the gates (T2 -- behavior actually PASSES, not just gate-on-disk) -- `verify <target>` = detail 459 if argc>1 { let a1: *u8=argv[1] as *u8; if cap_streq(a1,"verify" as *u8)==1 { 460 let o3: *i64=sys_mmap(24) as *i64 461 if argc>2 { cap_verify_one(argv[2] as *u8, 1, o3); sys_exit(0); return 0 } 462 cp("=== nx_cap_census VERIFY: gates RUN + PASS per target (T2 behavior proof) ===\n" as *u8) 463 let mfd: i64=sys_openat_rd(CAP_MANIFEST); if mfd<0 { cp(" manifest unreadable\n" as *u8); sys_exit(1); return 1 } 464 let mb: *u8=sys_mmap(CAP_MAGIC_16384); var mn: i64=0; var r: i64=1 465 while r>0 { let dst: *u8=((mb as i64)+mn) as *u8; r=sys_read(mfd,dst,CAP_MAGIC_16000-mn); if r>0 { mn=mn+r } if mn>=CAP_MAGIC_16000 { r=0 } } 466 sys_close(mfd) 467 let tn2: *u8=sys_mmap(64); var ls: i64=0 468 while ls<mn { 469 var le: i64=ls; var eol: i64=0 470 while eol==0 { if le>=mn { eol=1 } else { if mb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 471 if le>ls { if mb[ls]!=(35 as u8) { 472 var o: i64=0; var i: i64=ls; while i<le { if mb[i]!=(13 as u8) { if mb[i]!=(32 as u8) { tn2[o]=mb[i]; o=o+1 } } i=i+1 } tn2[o]=0 as u8 473 if o>0 { let ver: i64=cap_verify_one(tn2, 0, o3); if ver>=0 { 474 cp(" "); cp(tn2); var pad: i64=o; while pad<20 { cp(" " as *u8); pad=pad+1 } 475 cp("gates pass "); cnum(o3[2]); cp("/"); cnum(o3[1]); cp(" run, of "); cnum(o3[0]); cp(" HAVE -> "); cnum(ver); cp("/1000 verified\n" as *u8) 476 } } 477 } } 478 ls=le+1 479 } 480 sys_exit(0); return 0 481 } } 482 // JUDGE mode: behavior-proof coverage (does our HAVE actually WORK?) -- `judge <target>` = detail, else scoreboard 483 if argc>1 { let a1: *u8=argv[1] as *u8; if cap_streq(a1,"judge" as *u8)==1 { 484 let o2: *i64=sys_mmap(16) as *i64 485 if argc>2 { cap_judge_one(argv[2] as *u8, 1, o2); sys_exit(0); return 0 } 486 cp("=== nx_cap_census JUDGE: behavior-proof coverage per target (presence != works) ===\n" as *u8) 487 let mfd: i64=sys_openat_rd(CAP_MANIFEST); if mfd<0 { cp(" manifest unreadable\n" as *u8); sys_exit(1); return 1 } 488 let mb: *u8=sys_mmap(CAP_MAGIC_16384); var mn: i64=0; var r: i64=1 489 while r>0 { let dst: *u8=((mb as i64)+mn) as *u8; r=sys_read(mfd,dst,CAP_MAGIC_16000-mn); if r>0 { mn=mn+r } if mn>=CAP_MAGIC_16000 { r=0 } } 490 sys_close(mfd) 491 let tn2: *u8=sys_mmap(64); var sH: i64=0; var sPv: i64=0; var ls: i64=0 492 while ls<mn { 493 var le: i64=ls; var eol: i64=0 494 while eol==0 { if le>=mn { eol=1 } else { if mb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 495 if le>ls { if mb[ls]!=(35 as u8) { 496 var o: i64=0; var i: i64=ls; while i<le { if mb[i]!=(13 as u8) { if mb[i]!=(32 as u8) { tn2[o]=mb[i]; o=o+1 } } i=i+1 } tn2[o]=0 as u8 497 if o>0 { let cov: i64=cap_judge_one(tn2, 0, o2); if cov>=0 { 498 cp(" "); cp(tn2); var pad: i64=o; while pad<20 { cp(" " as *u8); pad=pad+1 } 499 cp("proven "); cnum(o2[1]); cp("/"); cnum(o2[0]); cp(" HAVE -> "); cnum(cov); cp("/1000 behavior-proof\n" as *u8) 500 sH=sH+o2[0]; sPv=sPv+o2[1] 501 } } 502 } } 503 ls=le+1 504 } 505 var eco: i64=0; if sH>0 { eco=sPv*1000/sH } 506 cp(" ---------------------------------------------------------------\n" as *u8) 507 cp(" ECOSYSTEM behavior-proof: "); cnum(sPv); cp("/"); cnum(sH); cp(" HAVE -> "); cnum(eco); cp("/1000\n" as *u8) 508 sys_exit(0); return 0 509 } } 510 // SOTA mode: list the external frontier each target is measured against (the researcher's fetch targets) 511 if argc>1 { let a1: *u8=argv[1] as *u8; if cap_streq(a1,"sota" as *u8)==1 { 512 cp("=== nx_cap_census SOTA: the external frontier each target is measured against (researcher fetch targets) ===\n" as *u8) 513 let mfd: i64=sys_openat_rd(CAP_MANIFEST) 514 if mfd<0 { cp(" manifest unreadable\n" as *u8); sys_exit(1); return 1 } 515 let mb: *u8=sys_mmap(CAP_MAGIC_16384); var mn: i64=0; var r: i64=1 516 while r>0 { let dst: *u8=((mb as i64)+mn) as *u8; r=sys_read(mfd,dst,CAP_MAGIC_16000-mn); if r>0 { mn=mn+r } if mn>=CAP_MAGIC_16000 { r=0 } } 517 sys_close(mfd) 518 let tn2: *u8=sys_mmap(64) 519 var ls: i64=0 520 while ls<mn { 521 var le: i64=ls; var eol: i64=0 522 while eol==0 { if le>=mn { eol=1 } else { if mb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 523 if le>ls { if mb[ls]!=(35 as u8) { 524 var o: i64=0; var i: i64=ls; while i<le { if mb[i]!=(13 as u8) { if mb[i]!=(32 as u8) { tn2[o]=mb[i]; o=o+1 } } i=i+1 } tn2[o]=0 as u8 525 if o>0 { cap_print_sources(tn2) } 526 } } 527 ls=le+1 528 } 529 sys_exit(0); return 0 530 } } 531 // CHECK mode: drift vs the last measurement -- the primitive a scheduler runs to ALERT on change (exit 1 = drift) 532 if argc>1 { let a1: *u8=argv[1] as *u8; if cap_streq(a1,"check" as *u8)==1 { 533 let pb: *u8=sys_mmap(CAP_MAGIC_65536); var pn: i64=0 534 let pfd: i64=sys_openat_rd(CAP_ECOLOG) 535 if pfd>=0 { var rr: i64=1; while rr>0 { let dst: *u8=((pb as i64)+pn) as *u8; rr=sys_read(pfd,dst,CAP_MAGIC_65000-pn); if rr>0 { pn=pn+rr } if pn>=CAP_MAGIC_65000 { rr=0 } } sys_close(pfd) } 536 cp("=== nx_cap_census CHECK: drift vs last measurement ===\n" as *u8) 537 let mfd: i64=sys_openat_rd(CAP_MANIFEST); if mfd<0 { cp(" manifest unreadable\n" as *u8); sys_exit(2); return 2 } 538 let mb: *u8=sys_mmap(CAP_MAGIC_16384); var mn: i64=0; var r2: i64=1 539 while r2>0 { let dst: *u8=((mb as i64)+mn) as *u8; r2=sys_read(mfd,dst,CAP_MAGIC_16000-mn); if r2>0 { mn=mn+r2 } if mn>=CAP_MAGIC_16000 { r2=0 } } 540 sys_close(mfd) 541 let o4: *i64=sys_mmap(4*8) as *i64; let tn3: *u8=sys_mmap(64) 542 var drift: i64=0 543 var ls: i64=0 544 while ls<mn { 545 var le: i64=ls; var eol: i64=0 546 while eol==0 { if le>=mn { eol=1 } else { if mb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 547 if le>ls { if mb[ls]!=(35 as u8) { 548 var oo: i64=0; var i: i64=ls; while i<le { if mb[i]!=(13 as u8) { if mb[i]!=(32 as u8) { tn3[oo]=mb[i]; oo=oo+1 } } i=i+1 } tn3[oo]=0 as u8 549 if oo>0 { 550 let cur: i64=cap_census_one(tn3, 0, fbuf, o4) 551 if cur>=0 { 552 cp(" "); cp(tn3); var pad: i64=oo; while pad<20 { cp(" " as *u8); pad=pad+1 } 553 let prev: i64=cap_prev_score(pb, pn, tn3) 554 if prev<0 { cp(" NEW target cur="); cnum(cur); cp("/1000"); drift=drift+1 } 555 else { if cur!=prev { cp(" DRIFT prev="); cnum(prev); cp(" -> cur="); cnum(cur); drift=drift+1 } else { cp(" stable "); cnum(cur); cp("/1000") } } 556 if o4[3]>0 { cp(" !! ungrounded "); cnum(o4[3]); drift=drift+1 } 557 cp("\n" as *u8) 558 } 559 } 560 } } 561 ls=le+1 562 } 563 if drift>0 { cp("\nDRIFT: "); cnum(drift); cp(" change(s) since last measurement -- rebaseline (run all) + review.\n" as *u8); sys_exit(1); return 1 } 564 cp("\nIN SYNC: capabilities match the last measurement.\n" as *u8); sys_exit(0); return 0 565 } } 566 var mode_all: i64=1 567 let tgt: *u8=sys_mmap(64); tgt[0]=0 as u8 568 if argc>1 { let a1: *u8=argv[1] as *u8; if cap_streq(a1,"all" as *u8)==0 { mode_all=0; var i: i64=0; while a1[i]!=(0 as u8) { if i<63 { tgt[i]=a1[i] } i=i+1 } tgt[i]=0 as u8 } } 569 570 if mode_all==0 { 571 let s: i64=cap_census_one(tgt, 1, fbuf, out4) 572 if s<0 { cp(" no registry: knowledge/registry/"); cp(tgt); cp("_capabilities.conf\n" as *u8); sys_exit(1) } 573 sys_exit(0); return 0 574 } 575 576 // ECOSYSTEM SCOREBOARD across every target in the manifest 577 cp("=== nx_cap_census: NISHI ECOSYSTEM CAPABILITY SCOREBOARD (source-grounded, liar-killed) ===\n" as *u8) 578 let mfd: i64=sys_openat_rd(CAP_MANIFEST) 579 if mfd<0 { cp(" manifest unreadable: knowledge/registry/capability_targets.conf\n" as *u8); sys_exit(1); return 1 } 580 let mb: *u8=sys_mmap(CAP_MAGIC_16384); var mn: i64=0; var r: i64=1 581 while r>0 { let dst: *u8=((mb as i64)+mn) as *u8; r=sys_read(mfd,dst,CAP_MAGIC_16000-mn); if r>0 { mn=mn+r } if mn>=CAP_MAGIC_16000 { r=0 } } 582 sys_close(mfd) 583 var sumH: i64=0; var sumP: i64=0; var sumG: i64=0; var ntar: i64=0 584 let lfd: i64=sys_openat_wr(CAP_ECOLOG, 420) 585 let tname: *u8=sys_mmap(64) 586 var ls: i64=0 587 var ngrounded: i64=0 588 while ls<mn { 589 var le: i64=ls; var eol: i64=0 590 while eol==0 { if le>=mn { eol=1 } else { if mb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 591 if le>ls { if mb[ls]!=(35 as u8) { 592 var o: i64=0; var i: i64=ls; while i<le { if mb[i]!=(13 as u8) { if mb[i]!=(32 as u8) { tname[o]=mb[i]; o=o+1 } } i=i+1 } tname[o]=0 as u8 593 if o>0 { 594 let s: i64=cap_census_one(tname, 0, fbuf, out4) 595 cp(" "); cp(tname) 596 var pad: i64=o; while pad<20 { cp(" " as *u8); pad=pad+1 } 597 if s<0 { cp(" (no registry)\n" as *u8) } 598 else { 599 let nsrc: i64=cap_count_sources(tname) 600 if nsrc<=0 { 601 cp(" UNGROUNDED"); cp(" HAVE "); cnum(out4[0]); cp(" / PARTIAL "); cnum(out4[1]); cp(" / GAP "); cnum(out4[2]) 602 cp(" vs 0 SOTA-src -- REFUSING to emit a score") 603 } else { 604 cp(" "); cnum(s); cp("/1000 HAVE "); cnum(out4[0]); cp(" / PARTIAL "); cnum(out4[1]); cp(" / GAP "); cnum(out4[2]) 605 cp(" vs "); cnum(nsrc); cp(" SOTA-src") 606 ngrounded=ngrounded+1 607 } 608 if out4[3]>0 { cp(" !! ungrounded "); cnum(out4[3]) } 609 cp("\n" as *u8) 610 sumH=sumH+out4[0]; sumP=sumP+out4[1]; sumG=sumG+out4[2]; ntar=ntar+1 611 cwf(lfd, tname); cwf(lfd, " score="); cwn(lfd, s); cwf(lfd, " H="); cwn(lfd, out4[0]); cwf(lfd, " P="); cwn(lfd, out4[1]); cwf(lfd, " G="); cwn(lfd, out4[2]); cwf(lfd, " ung="); cwn(lfd, out4[3]); cwf(lfd, "\n") 612 } 613 } 614 } } 615 ls=le+1 616 } 617 let ST: i64=sumH+sumP+sumG 618 var eco: i64=0; if ST>0 { eco=(sumH*2+sumP)*1000/(ST*2) } 619 cp(" ---------------------------------------------------------------\n" as *u8) 620 cp(" SCANNED-TARGETS ("); cnum(ntar); cp(", grounded "); cnum(ngrounded); cp(") ") 621 if ngrounded<=0 { 622 cp("UNGROUNDED") 623 } else { 624 cnum(eco); cp("/1000") 625 } 626 cp(" HAVE "); cnum(sumH); cp(" / PARTIAL "); cnum(sumP); cp(" / GAP "); cnum(sumG); cp("\n" as *u8) 627 if ngrounded<=0 { 628 cp(" L2 REFUSAL: not one target carries an external SOTA source, so this aggregate is graded\n" as *u8) 629 cp(" against NOTHING and is withheld. A self-referential score can only drift upward. HAVE/PARTIAL/GAP\n" as *u8) 630 cp(" above are PRESENCE counts and say nothing about quality: a toy and a SOTA impl both score HAVE.\n" as *u8) 631 } 632 if ntar<10 { 633 cp(" SCOPE: this is NOT the ecosystem -- nx_ecosystem_maturity_rollup tracks 26 domains and\n" as *u8) 634 cp(" nx_sota_status 40. Per-capability SHAPE (min/skew/starved) lives in nx_capaxes_derive.\n" as *u8) 635 } 636 cwf(lfd, "ECOSYSTEM targets="); cwn(lfd, ntar); cwf(lfd, " score="); cwn(lfd, eco); cwf(lfd, " H="); cwn(lfd, sumH); cwf(lfd, " P="); cwn(lfd, sumP); cwf(lfd, " G="); cwn(lfd, sumG); cwf(lfd, "\n") 637 if lfd>=0 { sys_close(lfd) } 638 sys_exit(0); return 0 639}