nx_evidence_audit.nx source
↩ module page · 126 lines · 6444 B
1// nx_evidence_audit.nx -- THE FLEET GROUNDING AUDIT: walk knowledge/compare/, and for EVERY head-to-head census
2// (<domain>.matrix) FORK nx_swcompare_evidence in json mode and roll up how many present claims LACK a real source
3// line (ungrounded = a fabricated/broken cell). This is the autonomous liar-catch: it is what found videocodec's
4// vv_enc_rct8 pointing at the wrong organ (2026-07-12). Exit 0 iff the whole surface is clean (0 ungrounded), else
5// RED naming each offending domain. Distinct from nx_evidence_fleet (that rolls up which domains HAVE a .gates
6// file; this one RUNS the grounding check on every claim). ⚠COORDINATION: fold this into nx_evidence_fleet as an
7// `audit` mode once that file's churn settles (it is a sibling's hot file today). Read-only except /tmp scratch.
8// license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10const EA_MAGIC_131072: i64 = 131072
11const EA_MAGIC_131071: i64 = 131071
12
13const EA_DIR: *u8 = "knowledge/compare"
14
15func ea_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func ea_wn(v0: i64) -> i64 {
17 if v0==0 { sys_write(1,"0" as *u8,1); return 0 }
18 var v: i64=v0; if v<0{sys_write(1,"-" as *u8,1);v=0-v}
19 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}
20 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
21}
22func ea_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
23func ea_ends(name: *u8, nl: i64, suf: *u8) -> i64 {
24 let sl: i64=ea_slen(suf); if sl>nl {return 0}
25 var i: i64=0; while i<sl { if name[nl-sl+i]!=suf[i]{return 0} i=i+1 } return 1
26}
27// read the decimal integer that follows `key` in ob[0..on); -1 if absent.
28func ea_num_after(ob: *u8, on: i64, key: *u8) -> i64 {
29 let kl: i64 = ea_slen(key)
30 var i: i64 = 0
31 while i + kl <= on {
32 var k: i64 = 0
33 var hit: i64 = 1
34 while k < kl { if ob[i+k] != key[k] { hit = 0; k = kl } else { k = k + 1 } }
35 if hit == 1 {
36 var bi: i64 = i + kl
37 var v: i64 = 0
38 var any: i64 = 0
39 var go: i64 = 1
40 while go == 1 {
41 if bi >= on { go = 0 } else { let c: i64 = ob[bi] as i64; if c >= 48 { if c <= 57 { v = v*10 + (c-48); any = 1; bi = bi + 1 } else { go = 0 } } else { go = 0 } }
42 }
43 if any == 1 { return v }
44 }
45 i = i + 1
46 }
47 return 0 - 1
48}
49// fork nx_swcompare_evidence <domain> json -> capture -> out[0]=present_axes out[1]=ungrounded out[2]=gates_ran
50func ea_domain(dom: *u8, out: *i64) -> i64 {
51 out[0]=0; out[1]=0; out[2]=0
52 let outp: *u8 = "/tmp/ea_fleet.out\x00" as *u8
53 let pid: i64 = sys_fork()
54 if pid == 0 {
55 let ofd: i64 = sys_openat_wr(outp, 0x1a4)
56 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) }
57 let argv: *i64 = sys_mmap(32) as *i64
58 argv[0] = "_offc/nx_swcompare_evidence.elf\x00" as *u8 as i64
59 argv[1] = dom as i64
60 argv[2] = "json\x00" as *u8 as i64
61 argv[3] = 0
62 let envp: *i64 = sys_mmap(16) as *i64; envp[0] = 0
63 sys_execve("_offc/nx_swcompare_evidence.elf\x00" as *u8, argv, envp)
64 sys_exit(127)
65 }
66 let stp: *i64 = sys_mmap(16) as *i64
67 sys_wait4(pid, stp, 0)
68 let fd: i64 = sys_openat_rd(outp)
69 if fd < 0 { return 0 - 1 }
70 let ob: *u8 = sys_mmap(EA_MAGIC_131072)
71 var on: i64 = 0
72 var r: i64 = sys_read(fd, ob, EA_MAGIC_131071)
73 while r > 0 { on = on + r; if on >= EA_MAGIC_131071 { r = 0 } else { r = sys_read(fd, (ob as i64 + on) as *u8, EA_MAGIC_131071 - on) } }
74 sys_close(fd)
75 let pa: i64 = ea_num_after(ob, on, "\"present_axes\":" as *u8)
76 let ug: i64 = ea_num_after(ob, on, "\"ungrounded\":" as *u8)
77 let gr: i64 = ea_num_after(ob, on, "\"gates_ran\":" as *u8)
78 if pa >= 0 { out[0] = pa }
79 if ug >= 0 { out[1] = ug }
80 if gr >= 0 { out[2] = gr }
81 return 0
82}
83
84func main(argc: i64, argv: *i64) -> i64 {
85 ea_w("=== NISHI FLEET GROUNDING AUDIT: does every /compare claim trace to real source? (forks nx_swcompare_evidence per domain) ===\n" as *u8)
86 let fd: i64 = sys_openat_rd(EA_DIR); if fd < 0 { ea_w("compare dir missing -- fail loud\n" as *u8); sys_exit(2); return 2 }
87 let gbuf: *u8 = sys_mmap(EA_MAGIC_131072)
88 let dom: *u8 = sys_mmap(128)
89 let out: *i64 = sys_mmap(32) as *i64
90 var doms: i64 = 0
91 var backed: i64 = 0
92 var tclaims: i64 = 0
93 var tung: i64 = 0
94 var liars: i64 = 0
95 var nread: i64 = sys_getdents64(fd, gbuf, EA_MAGIC_131072)
96 while nread > 0 {
97 var off: i64 = 0
98 while off < nread {
99 let rl: *u8 = ((gbuf as i64)+off+16) as *u8
100 let reclen: i64 = (rl[0] as i64) + ((rl[1] as i64)*256)
101 if reclen<=0 { off=nread } else {
102 let name: *u8 = ((gbuf as i64)+off+19) as *u8
103 var nl: i64=0; while name[nl]!=(0 as u8){nl=nl+1}
104 if ea_ends(name, nl, ".matrix\x00" as *u8)==1 {
105 var d: i64=0; while d < nl-7 { dom[d]=name[d]; d=d+1 } dom[d]=0 as u8
106 ea_domain(dom, out)
107 doms = doms + 1
108 tclaims = tclaims + out[0]
109 tung = tung + out[1]
110 if out[2] > 0 { backed = backed + 1 }
111 if out[1] > 0 {
112 liars = liars + 1
113 ea_w(" [UNGROUNDED] " as *u8); ea_w(dom); ea_w(" -- " as *u8); ea_wn(out[1]); ea_w(" of " as *u8); ea_wn(out[0]); ea_w(" present claims lack a source line (FABRICATED / broken cell -- fix the organ path or symbol, or mark _ABSENT_)\n" as *u8)
114 }
115 }
116 off = off + reclen
117 }
118 }
119 nread = sys_getdents64(fd, gbuf, EA_MAGIC_131072)
120 }
121 sys_close(fd)
122 ea_w("\n FLEET: " as *u8); ea_wn(tclaims); ea_w(" present claims across " as *u8); ea_wn(doms); ea_w(" head-to-head censuses; " as *u8); ea_wn(backed); ea_w(" have executed gates; UNGROUNDED=" as *u8); ea_wn(tung); ea_w("\n" as *u8)
123 if tung == 0 { ea_w(" VERDICT: GREEN -- every capability the whole /compare surface claims is grounded in real source on disk (0 fabricated). Autonomous + re-runnable.\n" as *u8); sys_exit(0); return 0 }
124 ea_w(" VERDICT: RED -- " as *u8); ea_wn(liars); ea_w(" domain(s) publish an ungrounded claim.\n" as *u8)
125 sys_exit(1); return 1
126}