code wiki / _hdl_build / nx_sovereignty_scorecard.nx

nx_sovereignty_scorecard.nx source

↩ module page · 45 lines · 2761 B

1// nx_sovereignty_scorecard.nx -- ONE unified, read-only view of the ecosystem's cleanliness, composing every 2// detector built this arc so "are we clean + staying clean?" is a single observable, not five scattered gates: 3// AXIS 1 THIRD-PARTY DEBT = the auditor's genuine_debt (by-extension contaminants), read from its log. 4// AXIS 2 SHADOW COLLISIONS = duplicate organ names where the wrong organ runs by name (nx_janitor_dupname). 5// AXIS 3 SCRATCH ACCUMULATION = build/test scratch piled up across the scratch zones (nx_janitor_scratch). 6// Each axis is the operator's "keep it gone" goal generalized: the debt-ratchet already locks AXIS 1; this 7// surfaces all three together so the whole sprawl picture can be tracked + ratcheted, not just one number. 8// READ-ONLY (never-brick): composes the existing detectors, writes nothing. Sovereign. license_tier: ORIGINAL 9import "nx_janitor_dupname.nx" // jdn_scan, jdn_collisions 10import "nx_janitor_scratch.nx" // jsc_total 11import "nx_syscalls.nx" 12const SSC_MAGIC_1048576: i64 = 1048576 13const SSC_MAGIC_1048560: i64 = 1048560 14const SSC_MAGIC_4194304: i64 = 4194304 15const SSC_MAGIC_32768: i64 = 32768 16 17const SSC_LOG: *u8 = "knowledge/status/sovereignty_audit.log" 18 19// AXIS 1: last "genuine_debt=N" in the auditor's log (-1 if the auditor has not run / no log). 20func ssc_debt() -> i64 { 21 let fd: i64 = sys_openat_rd(SSC_LOG); if fd < 0 { return 0 - 1 } 22 let buf: *u8 = sys_mmap(SSC_MAGIC_1048576) 23 var n: i64 = 0; var go: i64 = 1 24 while go == 1 { let r: i64 = sys_read(fd, (buf as i64 + n) as *u8, SSC_MAGIC_1048560 - n); if r <= 0 { go = 0 } else { n = n + r } if n >= SSC_MAGIC_1048560 { go = 0 } } 25 sys_close(fd) 26 let key: *u8 = "genuine_debt=" as *u8; var kl: i64 = 0; while key[kl] != (0 as u8) { kl = kl + 1 } 27 var last: i64 = 0 - 1; var i: i64 = 0 28 while i + kl <= n { 29 var k: i64 = 0; var hit: i64 = 1 30 while k < kl { if buf[i+k] != key[k] { hit = 0; k = kl } else { k = k + 1 } } 31 if hit == 1 { var p: i64 = i + kl; var v: i64 = 0; var any: i64 = 0; while p < n { if buf[p] < (48 as u8) { p = n } else { if buf[p] > (57 as u8) { p = n } else { v = v*10 + ((buf[p] as i64)-48); p = p + 1; any = 1 } } } if any == 1 { last = v } } 32 i = i + 1 33 } 34 return last 35} 36 37// AXIS 2: shadow collisions (runtime organs shadowed by an _hdl_build twin). 38func ssc_collisions() -> i64 { 39 let fnames: *u8 = sys_mmap(SSC_MAGIC_4194304); let fnoff: *i64 = sys_mmap(8*SSC_MAGIC_32768) as *i64; let hc: *i64 = sys_mmap(16) as *i64 40 let NF: i64 = jdn_scan(fnames, fnoff, hc) 41 return jdn_collisions(fnames, fnoff, hc[0], NF) 42} 43 44// AXIS 3: scratch accumulation across the standard scratch zones. 45func ssc_scratch() -> i64 { return jsc_total() }