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