code wiki / (root) / nx_evidence_fleet_t138.nx

nx_evidence_fleet_t138.nx source

↩ module page · 411 lines · 23306 B

1// nx_evidence_fleet.nx -- THE CENSUS-OF-CENSUSES HONESTY ROLLUP (operator 2026-07-10: "review again everything 2// and make sure our wiring of our systems is showing us a more real census iteratively so we can really get to 3// state of the art"). Every /compare/<domain> matrix publishes a coverage number, but a number is only as real 4// as its EVIDENCE: a domain with a <domain>.gates file has its capabilities FORKED-and-proven-GREEN by 5// nx_swcompare_evidence; a domain WITHOUT one is symbol-presence only (the weakest tier -- the code exists on 6// disk, unverified it works or is wired). This organ walks knowledge/compare/, and for every head-to-head census 7// (<domain>.matrix) reports EVIDENCE-BACKED (has .gates, N executable gates) vs SYMBOL-ONLY, and the FLEET 8// HONESTY permille = evidence-backed / total. It names exactly which domains still need a .gates file = the 9// rollout worklist. Read-only. See [[feedback-census-evidence-backed-not-symbol-presence]]. license_tier: ORIGINAL 10import "nx_syscalls.nx" 11import "nx_evprofile_lib.nx" 12import "nx_fio.nx" 13const EF_MAGIC_65536: i64 = 65536 14const EF_MAGIC_65535: i64 = 65535 15const EF_MAGIC_131072: i64 = 131072 16const EF_MAGIC_262144: i64 = 262144 17const EF_MAGIC_262143: i64 = 262143 18 19const EF_DIR: *u8 = "knowledge/compare" 20 21func ef_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 22func ef_wn(v0: i64) -> i64 { 23 if v0==0 { sys_write(1,"0" as *u8,1); return 0 } 24 var v: i64=v0; if v<0{sys_write(1,"-" as *u8,1);v=0-v} 25 let t: *u8=sys_mmap(24); var k: i64=0; while v>0{t[k]=(48+(v%10)) as u8;v=v/10;k=k+1} 26 let r: *u8=sys_mmap(24); var i: i64=0; while k>0{k=k-1;r[i]=t[k];i=i+1} sys_write(1,r,i); return 0 27} 28func ef_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 29func ef_ends(name: *u8, nl: i64, suf: *u8) -> i64 { 30 let sl: i64=ef_slen(suf); if sl>nl {return 0} 31 var i: i64=0; while i<sl { if name[nl-sl+i]!=suf[i]{return 0} i=i+1 } return 1 32} 33func ef_exists(path: *u8) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0{return 0} sys_close(fd); return 1 } 34// count non-comment, non-blank rows in a gates file (= number of executable proofs). 0 if absent. 35func ef_gate_rows(path: *u8) -> i64 { 36 let fd: i64=sys_openat_rd(path); if fd<0{return 0} 37 let buf: *u8=sys_mmap(EF_MAGIC_65536); var n: i64=0; var r: i64=sys_read(fd, buf, EF_MAGIC_65535) 38 while r>0 { n=n+r; if n>=EF_MAGIC_65535 {r=0} else { r=sys_read(fd, buf+n, EF_MAGIC_65535-n) } } 39 sys_close(fd) 40 var rows: i64=0; var ls: i64=0; var i: i64=0 41 while i<=n { 42 var eol: i64=0 43 if i==n { eol=1 } else { if buf[i]==(10 as u8) { eol=1 } } 44 if eol==1 { if i>ls { if buf[ls]!=(35 as u8) { rows=rows+1 } } ls=i+1 } 45 i=i+1 46 } 47 return rows 48} 49 50// walk EF_DIR; st[0]=matrix-domains(total census) st[1]=evidence-backed st[2]=total-gate-rows. 51// if verbose==1, prints each domain's status. returns total matrix domains. 52func ef_run(st: *i64, verbose: i64) -> i64 { 53 st[0]=0; st[1]=0; st[2]=0 54 let fd: i64 = sys_openat_rd(EF_DIR); if fd<0 { return 0 } 55 let gbuf: *u8 = sys_mmap(EF_MAGIC_131072) 56 let dom: *u8 = sys_mmap(128) 57 let gpath: *u8 = sys_mmap(256) 58 var nread: i64 = sys_getdents64(fd, gbuf, EF_MAGIC_131072) 59 while nread > 0 { 60 var off: i64 = 0 61 while off < nread { 62 let rl: *u8 = ((gbuf as i64)+off+16) as *u8 63 let reclen: i64 = (rl[0] as i64) + ((rl[1] as i64)*256) 64 if reclen<=0 { off=nread } else { 65 let name: *u8 = ((gbuf as i64)+off+19) as *u8 66 var nl: i64=0; while name[nl]!=(0 as u8){nl=nl+1} 67 if ef_ends(name, nl, ".matrix\x00" as *u8)==1 { 68 st[0]=st[0]+1 69 // domain = name without .matrix 70 var d: i64=0; while d < nl-7 { dom[d]=name[d]; d=d+1 } dom[d]=0 as u8 71 // gpath = knowledge/compare/<domain>.gates 72 var o: i64=0; let pre: *u8="knowledge/compare/\x00" as *u8 73 var pi: i64=0; while pre[pi]!=(0 as u8){gpath[o]=pre[pi];o=o+1;pi=pi+1} 74 var di: i64=0; while dom[di]!=(0 as u8){gpath[o]=dom[di];o=o+1;di=di+1} 75 let suf: *u8=".gates\x00" as *u8; var si: i64=0; while suf[si]!=(0 as u8){gpath[o]=suf[si];o=o+1;si=si+1} gpath[o]=0 as u8 76 let rows: i64 = ef_gate_rows(gpath) 77 if rows > 0 { 78 st[1]=st[1]+1; st[2]=st[2]+rows 79 if verbose==1 { ef_w(" [EVIDENCE ] "); ef_w(dom); ef_w(" -- "); ef_wn(rows); ef_w(" executable gates (declarations only; execution not measured)\n" as *u8) } 80 } else { 81 if verbose==1 { ef_w(" [symbol ] "); ef_w(dom); ef_w(" -- no .gates: coverage is symbol-presence only (needs executed evidence)\n" as *u8) } 82 } 83 } 84 off = off + reclen 85 } 86 } 87 nread = sys_getdents64(fd, gbuf, EF_MAGIC_131072) 88 } 89 sys_close(fd) 90 return st[0] 91} 92 93// find NUL-terminated needle in buf[from..to); -1 if absent. 94func ef_find(buf: *u8, from: i64, to: i64, needle: *u8) -> i64 { 95 let m: i64 = ef_slen(needle); if m==0 { return from } 96 var i: i64 = from 97 while i+m <= to { var j: i64=0; var hit: i64=1; while j<m { if buf[i+j]!=needle[j] { hit=0; j=m } else { j=j+1 } } if hit==1 { return i } i=i+1 } 98 return 0-1 99} 100 101// CLAIM-WEIGHTED fleet honesty: read the registry, and of the TOTAL published coverage-points, how many belong 102// to domains that are GATE-DECLARED (have a .gates file). A big unverified domain (e.g. 1000/1000 103// symbol-only) rightly drags the number down more than a small one. st[0]=total-cov st[1]=verified-cov st[2]=doms. 104func ef_claimweight(st: *i64) -> i64 { 105 st[0]=0; st[1]=0; st[2]=0 106 let buf: *u8 = sys_mmap(EF_MAGIC_262144) 107 let fd: i64 = sys_openat_rd("knowledge/compare/registry\x00" as *u8); if fd<0 { return 0 } 108 var n: i64=0; var r: i64=sys_read(fd, buf, EF_MAGIC_262143) 109 while r>0 { n=n+r; if n>=EF_MAGIC_262143 {r=0} else { r=sys_read(fd, buf+n, EF_MAGIC_262143-n) } } 110 sys_close(fd) 111 let dom: *u8 = sys_mmap(128); let gp: *u8 = sys_mmap(256) 112 var ls: i64=0; var i: i64=0 113 while i<=n { 114 var eol: i64=0 115 if i==n { eol=1 } else { if buf[i]==(10 as u8) { eol=1 } } 116 if eol==1 { 117 if i>ls { if buf[ls]!=(35 as u8) { 118 // coverage number: "coverage NNN" 119 let cpos: i64 = ef_find(buf, ls, i, "coverage \x00" as *u8) 120 // domain: after "/compare/" 121 let dpos: i64 = ef_find(buf, ls, i, "/compare/\x00" as *u8) 122 if cpos >= 0 { if dpos >= 0 { 123 // parse coverage digits after "coverage " (9 chars) 124 var p: i64 = cpos + 9; var cov: i64 = 0; var any: i64 = 0 125 while p < i { let c: i64 = buf[p] as i64; if c>=48 { if c<=57 { cov=cov*10+(c-48); any=1; p=p+1 } else { p=i } } else { p=i } } 126 // extract domain after "/compare/" (9 chars): [a-z0-9] until non 127 var q: i64 = dpos + 9; var d: i64 = 0 128 while q < i { let c: i64 = buf[q] as i64 129 var ok: i64=0; if c>=97 { if c<=122 { ok=1 } } if c>=48 { if c<=57 { ok=1 } } 130 if ok==1 { dom[d]=buf[q] as u8; d=d+1; q=q+1 } else { q=i } } 131 dom[d]=0 as u8 132 if any==1 { if d>0 { 133 st[0] = st[0] + cov; st[2] = st[2] + 1 134 var go: i64 = ef_slen("knowledge/compare/\x00" as *u8) 135 var o: i64=0; let pre: *u8="knowledge/compare/\x00" as *u8; var pi: i64=0 136 while pre[pi]!=(0 as u8){gp[o]=pre[pi];o=o+1;pi=pi+1} 137 var di: i64=0; while dom[di]!=(0 as u8){gp[o]=dom[di];o=o+1;di=di+1} 138 let suf: *u8=".gates\x00" as *u8; var si: i64=0; while suf[si]!=(0 as u8){gp[o]=suf[si];o=o+1;si=si+1} gp[o]=0 as u8 139 if go < 0 { } 140 if ef_exists(gp)==1 { st[1] = st[1] + cov } 141 } } 142 } } 143 } } 144 ls=i+1 145 } 146 i=i+1 147 } 148 return st[2] 149} 150 151// Evidence progression: observations, not a composite readiness score. 152// Explicit directory scope avoids silently merging different authored/published trees. 153static efp_output_error:i64 154static efp_output_fd:i64 155func efp_write(s:*u8)->i64 { 156 let n:i64=ef_slen(s);var p:i64=0 157 while p<n {var dst:i64=efp_output_fd;if dst<=0 {dst=1};let r:i64=sys_write(dst,s+p,n-p);if r==FIO_EINTR {continue};if r<=0 {efp_output_error=1;return 0-1};p=p+r} 158 return 0 159} 160func efp_num(v:i64)->i64 { 161 let b:*u8=sys_mmap_shared(32) 162 if (b as i64)<=0 {efp_output_error=1;return 0-1} 163 var x:i64=v;var n:i64=0 164 if x<0 {efp_write("-");x=0-x} 165 if x==0 {b[0]=48 as u8;n=1} 166 while x>0 {b[n]=(48+x%10) as u8;n=n+1;x=x/10} 167 var i:i64=0 168 while i<n/2 {let c:u8=b[i];b[i]=b[n-1-i];b[n-1-i]=c;i=i+1} 169 b[n]=0 as u8;efp_write(b);sys_munmap(b,32);return 0 170} 171func efp_json(s:*u8)->i64 { 172 efp_write("\"");var i:i64=0 173 let b:*u8=sys_mmap_shared(8) 174 if (b as i64)<=0 {efp_output_error=1;return 0-1} 175 let hex:*u8="0123456789abcdef" 176 while s[i]!=(0 as u8) { 177 let c:i64=s[i] as i64 178 if c==34 || c==92 {b[0]=92 as u8;b[1]=c as u8;b[2]=0 as u8;efp_write(b)} 179 else {if c<32 {b[0]=92 as u8;b[1]=117 as u8;b[2]=48 as u8;b[3]=48 as u8;b[4]=hex[c/16];b[5]=hex[c%16];b[6]=0 as u8;efp_write(b)} else {b[0]=c as u8;b[1]=0 as u8;efp_write(b)}} 180 i=i+1 181 } 182 sys_munmap(b,8);efp_write("\"");return 0 183} 184func efp_hex(d:*u8)->i64 { 185 let h:*u8="0123456789abcdef";let b:*u8=sys_mmap_shared(65) 186 if (b as i64)<=0 {efp_output_error=1;return 0-1} 187 var i:i64=0;while i<32 {b[i*2]=h[(d[i] as i64)/16];b[i*2+1]=h[(d[i] as i64)%16];i=i+1} 188 b[64]=0 as u8;efp_json(b);sys_munmap(b,65);return 0 189} 190func efp_path(dir:*u8,pre:*u8,dom:*u8,suf:*u8)->*u8 { 191 let n:i64=ef_slen(dir)+ef_slen(pre)+ef_slen(dom)+ef_slen(suf)+2 192 let p:*u8=sys_mmap_shared(n) 193 if (p as i64)<=0 {return 0 as *u8} 194 var o:i64=0;o=evp_cat(p,o,dir);p[o]=47 as u8;o=o+1;o=evp_cat(p,o,pre);o=evp_cat(p,o,dom);o=evp_cat(p,o,suf);p[o]=0 as u8 195 return p 196} 197func efp_release_path(p:*u8)->i64 {if (p as i64)>0 {return sys_munmap(p,ef_slen(p)+1)};return 0} 198// out: bytes, syntactically declared rows, malformed rows, raw error. 199// Buffer size is a transport chunk; reads continue to the entire captured file extent. 200func efp_snapshot(path:*u8,mode:i64,out:*i64,digest:*u8)->i64 { 201 out[0]=0;out[1]=0;out[2]=0;out[3]=0 202 let rw:*u8=sys_mmap_shared(72);let buf:*u8=sys_mmap_shared(4096) 203 let shn:i64=sha256_workspace_bytes();let sh:*u8=sys_mmap_shared(shn) 204 if (rw as i64)<=0 || (buf as i64)<=0 || (sh as i64)<=0 {out[3]=0-12} 205 else { 206 let r:*NxFileReadRegion=rw as *NxFileReadRegion;fio_region_init(r) 207 out[3]=fio_region_open(path,r) 208 if out[3]==0 { 209 out[0]=r.total;sha256_init_workspace(sh,shn) 210 var seen:i64=0;var skip:i64=0;var pipes:i64=0 211 var got:i64=fio_region_next(r,buf,4096) 212 while got>0 { 213 sha256_update(sh as *Sha256,buf,got) 214 var i:i64=0 215 while i<got { 216 let c:i64=buf[i] as i64 217 if c==10 { 218 if seen==1 && skip==0 {var need:i64=2;if mode==2 {need=8};if pipes>=need {out[1]=out[1]+1} else {out[2]=out[2]+1}} 219 seen=0;skip=0;pipes=0 220 } else { 221 if seen==0 && c!=32 && c!=9 && c!=13 {seen=1;if c==35 || (mode==2 && c==64) {skip=1}} 222 if c==124 {pipes=pipes+1} 223 } 224 i=i+1 225 } 226 got=fio_region_next(r,buf,4096) 227 } 228 if got<0 {out[3]=got} else { 229 if seen==1 && skip==0 {var need:i64=2;if mode==2 {need=8};if pipes>=need {out[1]=out[1]+1} else {out[2]=out[2]+1}} 230 sha256_final(sh as *Sha256,digest) 231 } 232 } 233 fio_region_close(r) 234 } 235 if (rw as i64)>0 {sys_munmap(rw,72)};if (buf as i64)>0 {sys_munmap(buf,4096)};if (sh as i64)>0 {sys_munmap(sh,shn)} 236 return out[3] 237} 238// Strict numeric field parser shares the existing stamp vocabulary. Missing -1; 239// duplicate, overflow, suffix junk or malformed pair -2. No prefix-number acceptance. 240func efp_field(buf:*u8,n:i64,key:*u8,pair:i64,out:*i64)->i64 { 241 out[0]=0-1;out[1]=0-1 242 var ks:i64=0;if key[0]==(32 as u8) {ks=1} 243 let kl:i64=ef_slen(key)-ks;var seen:i64=0;var i:i64=0 244 while i<n { 245 while i<n {let c:i64=buf[i] as i64;if c==32 || c==9 || c==10 || c==13 {i=i+1} else {break}} 246 let start:i64=i 247 while i<n {let c:i64=buf[i] as i64;if c==32 || c==9 || c==10 || c==13 {break};i=i+1} 248 let end:i64=i 249 var matched:i64=0 250 if end-start>=kl {matched=1;var j:i64=0;while j<kl {if buf[start+j]!=key[ks+j] {matched=0};j=j+1}} 251 if matched==1 { 252 seen=seen+1;if seen>1 {return 0-2} 253 var p:i64=start+kl;var part:i64=0 254 while part<=pair { 255 var v:i64=0;var any:i64=0 256 while p<end {let c:i64=buf[p] as i64;if c<48 || c>57 {break};if v>(9223372036854775807-(c-48))/10 {return 0-2};v=v*10+c-48;p=p+1;any=1} 257 if any==0 {return 0-2};out[part]=v 258 if part<pair {if p>=end {return 0-2};if buf[p]!=(47 as u8) {return 0-2};p=p+1} 259 part=part+1 260 } 261 if p!=end {return 0-2} 262 } 263 } 264 if seen==0 {return 0-1};return 0 265} 266// stamp fields: status,epoch,green,ran,declared,hashed,skipped,ok,unproven,errno. 267// status1 is a coherent retained record ONLY, never current-artifact or served proof. 268func efp_stamp(path:*u8,now:i64,f:*i64,digest:*u8)->i64 { 269 var i:i64=0;while i<10 {f[i]=0-1;i=i+1};f[9]=0 270 let rw:*u8=sys_mmap_shared(72) 271 if (rw as i64)<=0 {f[9]=0-12;return 0-1} 272 let r:*NxFileReadRegion=rw as *NxFileReadRegion;fio_region_init(r) 273 let rc:i64=fio_region_open(path,r) 274 if rc<0 {if rc==0-2 {f[0]=0};f[9]=rc;sys_munmap(rw,72);return f[0]} 275 let n:i64=r.total 276 if n<=0 || n>=9223372036854775807 {fio_region_close(r);sys_munmap(rw,72);sha256_digest_checked_native("" as *u8,0,digest);f[0]=0-2;return f[0]} 277 let b:*u8=sys_mmap_shared(n+1);let pair:*i64=sys_mmap_shared(16) as *i64 278 if (b as i64)<=0 || (pair as i64)<=0 {f[9]=0-12} 279 else { 280 let got:i64=fio_region_next(r,b,n) 281 if got!=n {f[9]=got} else { 282 b[n]=0 as u8 283 if sha256_digest_checked_native(b,n,digest)!=0 {f[9]=0-5} else { 284 var bad:i64=0 285 if efp_field(b,n,EVP_K_EPOCH,0,pair)!=0 {bad=1};f[1]=pair[0] 286 if efp_field(b,n,EVP_K_GATES,1,pair)!=0 {bad=1};f[2]=pair[0];f[3]=pair[1] 287 if efp_field(b,n,EVP_K_DECLARED,0,pair)!=0 {bad=1};f[4]=pair[0] 288 if efp_field(b,n,EVP_K_HASHED,0,pair)!=0 {bad=1};f[5]=pair[0] 289 if efp_field(b,n,EVP_K_SKIPPED,0,pair)!=0 {bad=1};f[6]=pair[0] 290 if efp_field(b,n,EVP_K_OK,0,pair)!=0 {bad=1};f[7]=pair[0] 291 if efp_field(b,n,EVP_K_UNPROVEN,0,pair)!=0 {bad=1};f[8]=pair[0] 292 if f[1]<=0 || f[1]>now || f[2]>f[3] || f[3]>f[4] || f[5]>f[4] || f[6]>f[3] {bad=1} 293 if f[7]>1 || f[8]>1 || (f[7]==1 && f[8]==1) {bad=1} 294 f[0]=1;if bad==1 {f[0]=0-2} 295 } 296 } 297 } 298 fio_region_close(r);sys_munmap(rw,72) 299 if (b as i64)>0 {sys_munmap(b,n+1)};if (pair as i64)>0 {sys_munmap(pair as *u8,16)} 300 return f[0] 301} 302func efp_progression(matrixdir:*u8,gatedir:*u8,statusdir:*u8)->i64 { 303 efp_output_error=0 304 let start:i64=sys_now_realtime_sec() 305 let fd:i64=sys_openat_directory(matrixdir) 306 if fd<0 {efp_write("{\"error\":\"matrix-directory-unreadable\",\"code\":");efp_num(fd);efp_write("}\n");return 2} 307 let buf:*u8=sys_mmap_shared(4096) 308 let stats:*i64=sys_mmap_shared(32) as *i64;let fields:*i64=sys_mmap_shared(80) as *i64 309 let digest:*u8=sys_mmap_shared(32) 310 if (buf as i64)<=0 || (stats as i64)<=0 || (fields as i64)<=0 || (digest as i64)<=0 {sys_close(fd);return 2} 311 efp_write("{\"schema\":\"estate-evidence-progression/v1\",\"observed_start_epoch\":");efp_num(start) 312 efp_write(",\"matrix_scope\":");efp_json(matrixdir);efp_write(",\"gate_scope\":");efp_json(gatedir);efp_write(",\"stamp_scope\":");efp_json(statusdir) 313 efp_write(",\"freshness_policy\":null,\"artifact_binding\":\"unknown: stamp does not retain current matrix/source identity\",\"served_acceptance\":\"not measured\",\"rows\":[") 314 var eligible:i64=0;var declarations:i64=0;var gate_unknown:i64=0;var matrix_unknown:i64=0 315 var valid:i64=0;var missing:i64=0;var invalid:i64=0;var unreadable:i64=0;var executed:i64=0;var green:i64=0 316 var age_min:i64=0-1;var age_max:i64=0-1;var err:i64=0 317 var got:i64=sys_getdents64(fd,buf,4096) 318 while got>0 { 319 var off:i64=0 320 while off<got { 321 if got-off<20 {err=1;break} 322 let len:i64=(buf[off+16] as i64)+(buf[off+17] as i64)*256 323 if len<20 || len>got-off {err=1;break} 324 let name:*u8=buf+off+19;var nl:i64=0 325 while nl<len-19 {if name[nl]==(0 as u8) {break};nl=nl+1} 326 if nl>=len-19 {err=1;break} 327 if ef_ends(name,nl,".matrix")==1 { 328 let dom:*u8=sys_mmap_shared(nl-7+1) 329 if (dom as i64)<=0 {err=1;break} 330 var j:i64=0;while j<nl-7 {dom[j]=name[j];j=j+1};dom[j]=0 as u8 331 let mp:*u8=efp_path(matrixdir,"",dom,".matrix");let gp:*u8=efp_path(gatedir,"",dom,".gates");let sp:*u8=efp_path(statusdir,"evstamp_",dom,".verdict") 332 if (mp as i64)==0 || (gp as i64)==0 || (sp as i64)==0 {err=1;sys_munmap(dom,nl-6);efp_release_path(mp);efp_release_path(gp);efp_release_path(sp);break} 333 if eligible>0 {efp_write(",")};eligible=eligible+1 334 efp_write("{\"domain\":");efp_json(dom) 335 let mc:i64=efp_snapshot(mp,2,stats,digest) 336 efp_write(",\"matrix_sha256\":");if mc==0 {efp_hex(digest)} else {efp_write("null")} 337 efp_write(",\"matrix_read_code\":");efp_num(mc);efp_write(",\"matrix_rows\":");efp_num(stats[1]);efp_write(",\"matrix_malformed_rows\":");efp_num(stats[2]) 338 if mc!=0 || stats[2]>0 {matrix_unknown=matrix_unknown+1} 339 let gc:i64=efp_snapshot(gp,1,stats,digest) 340 efp_write(",\"gate_declaration_sha256\":");if gc==0 {efp_hex(digest)} else {efp_write("null")} 341 efp_write(",\"gate_read_code\":");efp_num(gc);efp_write(",\"declared_gate_rows\":") 342 if gc==0 && stats[2]==0 {efp_num(stats[1]);if stats[1]>0 {declarations=declarations+1}} else {efp_write("null");if gc!=0-2 {gate_unknown=gate_unknown+1}} 343 let sc:i64=efp_stamp(sp,start,fields,digest) 344 efp_write(",\"stamp_state\":");efp_num(sc);efp_write(",\"stamp_read_code\":");efp_num(fields[9]);efp_write(",\"stamp_sha256\":") 345 if sc==1 || sc==0-2 {efp_hex(digest)} else {efp_write("null")} 346 efp_write(",\"stamp_epoch\":");if sc==1 {efp_num(fields[1])} else {efp_write("null")} 347 efp_write(",\"evidence_age_seconds\":") 348 if sc==1 { 349 valid=valid+1;let age:i64=start-fields[1];efp_num(age) 350 if age_min<0 || age<age_min {age_min=age};if age>age_max {age_max=age} 351 if fields[3]>0 {executed=executed+1};if fields[3]>0 && fields[2]==fields[3] && fields[6]==0 && fields[7]==1 && fields[8]==0 {green=green+1} 352 } else {efp_write("null");if sc==0 {missing=missing+1} else {if sc==0-2 {invalid=invalid+1} else {unreadable=unreadable+1}}} 353 efp_write(",\"recorded_green\":");if sc==1 {efp_num(fields[2])} else {efp_write("null")};efp_write(",\"recorded_runs\":");if sc==1 {efp_num(fields[3])} else {efp_write("null")};efp_write(",\"current_artifact_binding\":\"unknown\"}") 354 sys_munmap(dom,nl-6);efp_release_path(mp);efp_release_path(gp);efp_release_path(sp) 355 } 356 off=off+len 357 } 358 if err!=0 {break};got=sys_getdents64(fd,buf,4096) 359 } 360 if got<0 {err=1};if sys_close(fd)!=0 {err=1} 361 efp_write("],\"summary\":{\"eligible_matrix_domains\":");efp_num(eligible) 362 efp_write(",\"gate_declared_domains\":");efp_num(declarations);efp_write(",\"gate_declaration_unknown\":");efp_num(gate_unknown);efp_write(",\"matrix_unknown\":");efp_num(matrix_unknown) 363 efp_write(",\"retained_stamp_valid\":");efp_num(valid);efp_write(",\"retained_stamp_missing\":");efp_num(missing);efp_write(",\"retained_stamp_invalid\":");efp_num(invalid);efp_write(",\"retained_stamp_unreadable\":");efp_num(unreadable) 364 efp_write(",\"recorded_execution_domains\":");efp_num(executed);efp_write(",\"recorded_all_green_domains\":");efp_num(green);efp_write(",\"current_artifact_binding_unknown\":");efp_num(eligible) 365 efp_write(",\"age_min_seconds\":");if age_min<0 {efp_write("null")} else {efp_num(age_min)};efp_write(",\"age_max_seconds\":");if age_max<0 {efp_write("null")} else {efp_num(age_max)} 366 efp_write(",\"partition_reconciles\":");if eligible==valid+missing+invalid+unreadable {efp_write("true")} else {efp_write("false");err=1} 367 efp_write("},\"observed_end_epoch\":");efp_num(sys_now_realtime_sec());efp_write(",\"enumeration_complete\":");if err==0 {efp_write("true")} else {efp_write("false")};efp_write("}\n") 368 sys_munmap(buf,4096);sys_munmap(stats as *u8,32);sys_munmap(fields as *u8,80);sys_munmap(digest,32) 369 if err!=0 || efp_output_error!=0 {return 2};return 0 370} 371 372// Explicit immutable snapshot output closes the mgmt capture-size boundary. 373// O_EXCL refuses an existing path; a failed/incomplete artifact is retained for diagnosis. 374func efp_capture(matrixdir:*u8,gatedir:*u8,statusdir:*u8,path:*u8)->i64 { 375 let fd:i64=sys_openat_exclusive(path,420) 376 if fd<0 {efp_write("snapshot-open-refused code=");efp_num(fd);efp_write("\n");return 2} 377 efp_output_fd=fd 378 var rc:i64=efp_progression(matrixdir,gatedir,statusdir) 379 var synced:i64=sys_fsync(fd);while synced==FIO_EINTR {synced=sys_fsync(fd)} 380 let closed:i64=sys_close(fd);efp_output_fd=0 381 if synced!=0 || closed!=0 {rc=2} 382 let wr:*NxFileWriteResult=sys_mmap_shared(32) as *NxFileWriteResult 383 if (wr as i64)<=0 {rc=2} else {if fio_sync_parent(path,wr)!=0 {rc=2};sys_munmap(wr as *u8,32)} 384 efp_write("evidence_snapshot=");efp_write(path);efp_write(" rc=");efp_num(rc);efp_write(" fsync=");efp_num(synced);efp_write(" close=");efp_num(closed);efp_write("\n") 385 return rc 386} 387 388func main(argc: i64, argv: *i64) -> i64 { 389 if argc>1 {if evp_streq(argv[1] as *u8,"progression" as *u8)==1 {if argc==6 {return efp_capture(argv[2] as *u8,argv[3] as *u8,argv[4] as *u8,argv[5] as *u8)};if argc!=5 {efp_write("usage: nx_evidence_fleet progression <matrix-dir> <gates-dir> <status-dir> [exclusive-output.json]\n");return 2};return efp_progression(argv[2] as *u8,argv[3] as *u8,argv[4] as *u8)}} 390 391 let st: *i64 = sys_mmap(64) as *i64 392 ef_w("=== NISHI CENSUS-OF-CENSUSES: legacy gate declarations (use progression for retained execution evidence) ===\n" as *u8) 393 ef_run(st, 1) 394 let total: i64 = st[0] 395 let backed: i64 = st[1] 396 var permil: i64 = 0 397 if total > 0 { permil = (backed * 1000) / total } 398 ef_w("\n GATE DECLARATION COVERAGE (by domain count): "); ef_wn(backed); ef_w(" of "); ef_wn(total) 399 ef_w(" head-to-head censuses are GATE-DECLARED = "); ef_wn(permil); ef_w(" permille\n" as *u8) 400 ef_w(" ("); ef_wn(st[2]); ef_w(" executable gates across the backed domains; the rest publish symbol-presence numbers)\n" as *u8) 401 // claim-weighted: of the TOTAL published coverage-points, how many are executed-verified 402 let cw: *i64 = sys_mmap(64) as *i64 403 ef_claimweight(cw) 404 var cwpm: i64 = 0 405 if cw[0] > 0 { cwpm = (cw[1] * 1000) / cw[0] } 406 ef_w(" GATE DECLARATION COVERAGE (claim-weighted): of "); ef_wn(cw[0]); ef_w(" total published coverage-points across "); ef_wn(cw[2]) 407 ef_w(" domains, "); ef_wn(cw[1]); ef_w(" are gate-declared = "); ef_wn(cwpm); ef_w(" permille\n" as *u8) 408 ef_w(" (a big unverified domain drags this down more than a small one -- declaration coverage only, not current validation or SOTA readiness)\n" as *u8) 409 ef_w(" ROLLOUT: give each symbol-only domain a knowledge/compare/<domain>.gates file -> nx_swcompare_evidence -> /compare/<domain>/bench.\n" as *u8) 410 return 0 411}