code wiki / _hdl_build / nx_capability_shape_audit.nx
nx_capability_shape_audit.nx source
↩ module page · 103 lines · 6196 B
1// nx_capability_shape_audit.nx -- the CAPABILITIES AUDIT on the SIZING/frontier axis (operator: "we need a
2// capabilities audit"; distinct from the existing nx_capability_audit which classifies design-system
3// exceed-vs-sovereignty-floor). ONE sovereign walk grades EVERY organ on the perfect-object axis
4// (nx_capability_shape) + counts un-consolidated GENERATIONS (shadow collisions) = the full curation map:
5// TOO_SMALL (merge) / PERFECT (right-sized, the climbed-capability count) / TOO_BIG (split), + collisions to
6// resolve. Writes the metrics to knowledge/status/capability_audit.log so the no-regression safeguard ratchets
7// them. READ-ONLY walk (one reused buffer + sys_munmap; never-brick). license_tier: ORIGINAL expect_exit: 0
8import "nx_capability_shape.nx" // cs_funccount, cs_grade, CS_TOO_SMALL/PERFECT/TOO_BIG
9import "nx_janitor_dupname.nx" // jdn_scan, jdn_collisions
10import "nx_organ_callers.nx" // oc_getdents, oc_isdir, oc_join, oc_ends, oc_eq, oc_slen, oc_read
11import "nx_syscalls.nx"
12const CSA_MAGIC_16384: i64 = 16384
13const CSA_MAGIC_65536: i64 = 65536
14const CSA_MAGIC_4194304: i64 = 4194304
15const CSA_MAGIC_32768: i64 = 32768
16
17const CSA_LOG: *u8 = "knowledge/status/capability_audit.log"
18
19func aw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
20func an(fd: i64, v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(fd,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(fd,b,k); return 0 }
21
22// walk `root`: grade every .nx by function-count; tally[0]=TOO_SMALL [1]=PERFECT [2]=TOO_BIG. returns graded count.
23func csa_walk(root: *u8, tally: *i64) -> i64 {
24 let qbuf: *u8=sys_mmap(768*CSA_MAGIC_16384); let gbuf: *u8=sys_mmap(CSA_MAGIC_65536); let stbuf: *u8=sys_mmap(256)
25 let fbuf: *u8=sys_mmap(CSA_MAGIC_4194304); let child: *u8=sys_mmap(768)
26 var qh: i64=0; var qt: i64=0
27 var ri: i64=0; while root[ri]!=(0 as u8){ qbuf[ri]=root[ri]; ri=ri+1 } qbuf[ri]=0 as u8; qt=1
28 var graded: i64=0
29 while qh<qt {
30 let dir: *u8=((qbuf as i64)+qh*768) as *u8; qh=qh+1
31 let fd: i64=sys_openat_rd(dir)
32 if fd<0 { } else {
33 var nread: i64=oc_getdents(fd, gbuf, CSA_MAGIC_65536)
34 while nread>0 {
35 var off: i64=0
36 while off<nread {
37 let reclen: i64=(gbuf[off+16] as i64)|((gbuf[off+17] as i64)<<8)
38 if reclen<=0 { off=nread } else {
39 let name: *u8=((gbuf as i64)+off+19) as *u8
40 var skip: i64=0
41 if oc_eq(name, "." as *u8)==1 { skip=1 }
42 if oc_eq(name, ".." as *u8)==1 { skip=1 }
43 if skip==0 {
44 oc_join(child, dir, name)
45 let isd: i64=oc_isdir(child, stbuf)
46 if isd==1 {
47 var vend: i64=0
48 if oc_eq(name, "node_modules" as *u8)==1 { vend=1 }
49 if oc_eq(name, ".git" as *u8)==1 { vend=1 }
50 if oc_eq(name, ".alelane" as *u8)==1 { vend=1 }
51 if vend==0 { if qt<CSA_MAGIC_16384 { let dst: *u8=((qbuf as i64)+qt*768) as *u8; var c: i64=0; while child[c]!=(0 as u8){ dst[c]=child[c]; c=c+1 } dst[c]=0 as u8; qt=qt+1 } }
52 } else { if isd==0 {
53 let pl: i64=oc_slen(child)
54 if oc_ends(child, pl, ".nx" as *u8)==1 {
55 let fn: i64=oc_read(child, fbuf, CSA_MAGIC_4194304)
56 if fn>0 { let g: i64=cs_grade(cs_funccount(fbuf, fn)); tally[g]=tally[g]+1; graded=graded+1 }
57 }
58 } }
59 }
60 off=off+reclen
61 }
62 }
63 nread=oc_getdents(fd, gbuf, CSA_MAGIC_65536)
64 }
65 sys_close(fd)
66 }
67 }
68 sys_munmap(qbuf, 768*CSA_MAGIC_16384); sys_munmap(gbuf, CSA_MAGIC_65536); sys_munmap(fbuf, CSA_MAGIC_4194304)
69 return graded
70}
71
72func main() -> i64 {
73 aw(1, "=== nx_capability_shape_audit: grade EVERY organ on the perfect-object axis (the curation map) ===\n" as *u8)
74 let tally: *i64=sys_mmap(64) as *i64; tally[0]=0; tally[1]=0; tally[2]=0
75 let graded: i64=csa_walk("runtime\x00" as *u8, tally)
76 // collisions = capabilities still split across generations
77 let fnames: *u8=sys_mmap(CSA_MAGIC_4194304); let fnoff: *i64=sys_mmap(8*CSA_MAGIC_32768) as *i64; let hc: *i64=sys_mmap(16) as *i64
78 let NF: i64=jdn_scan(fnames, fnoff, hc)
79 let coll: i64=jdn_collisions(fnames, fnoff, hc[0], NF)
80
81 aw(1, " graded=" as *u8); an(1, graded)
82 aw(1, " TOO_SMALL(merge)=" as *u8); an(1, tally[0])
83 aw(1, " PERFECT(right-sized)=" as *u8); an(1, tally[1])
84 aw(1, " TOO_BIG(split)=" as *u8); an(1, tally[2])
85 aw(1, " shadow-collisions(generations to merge)=" as *u8); an(1, coll); aw(1, "\n" as *u8)
86 var permil: i64=0
87 if graded>0 { permil = (tally[1]*1000)/graded }
88 aw(1, " perfect-fraction permil=" as *u8); an(1, permil); aw(1, " (the climbed-capability metric the no-regression safeguard ratchets)\n" as *u8)
89
90 // durable log for the no-regression safeguard
91 let lfd: i64=sys_openat_append(CSA_LOG, 420)
92 if lfd>=0 {
93 aw(lfd, "CAP-AUDIT graded=" as *u8); an(lfd, graded)
94 aw(lfd, " too_small=" as *u8); an(lfd, tally[0])
95 aw(lfd, " perfect=" as *u8); an(lfd, tally[1])
96 aw(lfd, " too_big=" as *u8); an(lfd, tally[2])
97 aw(lfd, " collisions=" as *u8); an(lfd, coll)
98 aw(lfd, " perfect_permil=" as *u8); an(lfd, permil); aw(lfd, "\n" as *u8)
99 sys_close(lfd)
100 }
101 if graded>0 { aw(1, "CAP-SHAPE-AUDIT=GREEN (full curation map written to capability_audit.log)\n" as *u8); sys_exit(0); return 0 }
102 aw(1, "CAP-SHAPE-AUDIT=RED (nothing graded)\n" as *u8); sys_exit(1); return 1
103}