code wiki / _hdl_build / nx_optimism_audit.nx

nx_optimism_audit.nx source

↩ module page · 143 lines · 7167 B

1// nx_optimism_audit.nx -- the GRADER OF GRADERS. Operator 2026-07-24: make every grader/judge/census 2// cynical or incredibly accurate. This scans the instrument family and, DEFAULTING TO SUSPICIOUS, flags any 3// instrument that awards positive verdicts (PRESENT/HAVE/EXCEEDS/GREEN) without earning trust: 4// CYNICAL -- adopts the shared cynical bar (imports nx_honesty_grade_lib / calls hg_grade). Trusted. 5// SYNTH-BAR-- has a negative control BUT still grades on a synthetic bar and has NOT adopted hg_grade. 6// BARE -- awards positive verdicts with ZERO skepticism machinery. The worst; optimism unchecked. 7// It is itself a regression guard: a NEW optimistic instrument shows up here on the next run. 8// nx_optimism_audit [dir] (default runtime/_hdl_build) license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10const OA_MAGIC_262144: i64 = 262144 11const OA_MAGIC_4096: i64 = 4096 12 13const OA_CAP: i64 = 262144 14 15func 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 wn(v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; 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} let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 17func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 18 19// literal substring test 20func has(h: *u8, hn: i64, nd: *u8) -> i64 { 21 let nl: i64=slen(nd) 22 if nl==0 { return 0 } 23 var i: i64=0 24 while i+nl<=hn { 25 var k: i64=0; var hit: i64=1 26 while k<nl { if h[i+k]!=nd[k] { hit=0; k=nl } else { k=k+1 } } 27 if hit==1 { return 1 } 28 i=i+1 29 } 30 return 0 31} 32// name ends with ".nx" 33func ends_nx(nm: *u8) -> i64 { 34 let n: i64=slen(nm) 35 if n<3 { return 0 } 36 if nm[n-3]!=(46 as u8) { return 0 } 37 if nm[n-2]!=(110 as u8) { return 0 } 38 if nm[n-1]!=(120 as u8) { return 0 } 39 return 1 40} 41// is this an instrument filename (census/grade/grader/judge)? 42func is_instrument(nm: *u8) -> i64 { 43 let n: i64=slen(nm) 44 if has(nm, n, "census" as *u8)==1 { return 1 } 45 if has(nm, n, "grade" as *u8)==1 { return 1 } 46 if has(nm, n, "grader" as *u8)==1 { return 1 } 47 if has(nm, n, "judge" as *u8)==1 { return 1 } 48 return 0 49} 50 51func main(argc: i64, argv: *i64) -> i64 { 52 var dir: *u8 = "runtime/_hdl_build\x00" as *u8 53 if argc>=2 { dir = argv[1] as *u8 } 54 let dl: i64 = slen(dir) 55 56 let fd: i64 = sys_openat_rd(dir) 57 if fd<0 { w("AUDIT-FAIL: cannot open dir " as *u8); w(dir); w("\n" as *u8); sys_exit(2); return 2 } 58 let dbuf: *u8 = sys_mmap(OA_MAGIC_262144) 59 let path: *u8 = sys_mmap(OA_MAGIC_4096) 60 let fbuf: *u8 = sys_mmap(OA_CAP) 61 62 let cyn: *i64 = sys_mmap(8) as *i64 63 let syn: *i64 = sys_mmap(8) as *i64 64 let bare: *i64 = sys_mmap(8) as *i64 65 let scanned: *i64 = sys_mmap(8) as *i64 66 cyn[0]=0; syn[0]=0; bare[0]=0; scanned[0]=0 67 68 w("=== nx_optimism_audit -- grader-of-graders (default SUSPICIOUS) ===\n" as *u8) 69 w("dir=" as *u8); w(dir); w("\n" as *u8) 70 w("-- BARE instruments (positive verdicts, ZERO skepticism machinery) --\n" as *u8) 71 72 var go: i64=1 73 while go==1 { 74 let nr: i64 = sys_getdents64(fd, dbuf, OA_MAGIC_262144) 75 if nr<=0 { go=0 } else { 76 var off: i64=0 77 while off<nr { 78 let rec: *u8 = (dbuf as i64 + off) as *u8 79 let nm: *u8 = dirent_name(rec) 80 if ends_nx(nm)==1 { if is_instrument(nm)==1 { 81 // skip the honesty tooling itself + this auditor (they are the fix, not offenders) 82 let nn: i64 = slen(nm) 83 var skip: i64=0 84 if has(nm, nn, "honesty_grade" as *u8)==1 { skip=1 } 85 if has(nm, nn, "optimism_audit" as *u8)==1 { skip=1 } 86 if has(nm, nn, "maturity" as *u8)==1 { skip=1 } 87 if skip==0 { 88 // build path dir + "/" + nm 89 var p: i64=0 90 while p<dl { path[p]=dir[p]; p=p+1 } 91 path[p]=47 as u8; p=p+1 92 var q: i64=0 93 while nm[q]!=(0 as u8) { path[p]=nm[q]; p=p+1; q=q+1 } 94 path[p]=0 as u8 95 let ffd: i64 = sys_openat_rd(path) 96 if ffd>=0 { 97 var tot: i64=0 98 var rg: i64=1 99 while rg==1 { let r: i64=sys_read(ffd,(fbuf as i64+tot) as *u8, OA_CAP-1-tot); if r<=0 {rg=0} else {tot=tot+r; if tot>=OA_CAP-1 {rg=0}} } 100 sys_close(ffd) 101 // award-granting? 102 var pos: i64=0 103 if has(fbuf,tot,"PRESENT" as *u8)==1 { pos=1 } 104 if has(fbuf,tot,"EXCEEDS" as *u8)==1 { pos=1 } 105 if has(fbuf,tot,"HAVE" as *u8)==1 { pos=1 } 106 if pos==1 { 107 scanned[0]=scanned[0]+1 108 var cynical: i64=0 109 if has(fbuf,tot,"hg_grade" as *u8)==1 { cynical=1 } 110 if has(fbuf,tot,"nx_honesty_grade_lib" as *u8)==1 { cynical=1 } 111 var skept: i64=0 112 if has(fbuf,tot,"neg-control" as *u8)==1 { skept=1 } 113 if has(fbuf,tot,"NEG-CONTROL" as *u8)==1 { skept=1 } 114 if has(fbuf,tot,"adversarial" as *u8)==1 { skept=1 } 115 if has(fbuf,tot,"incumbent" as *u8)==1 { skept=1 } 116 if has(fbuf,tot,"liar" as *u8)==1 { skept=1 } 117 if has(fbuf,tot,"refute" as *u8)==1 { skept=1 } 118 if cynical==1 { cyn[0]=cyn[0]+1 } 119 else { if skept==1 { syn[0]=syn[0]+1 } 120 else { bare[0]=bare[0]+1; w(" [BARE] " as *u8); w(nm); w("\n" as *u8) } } 121 } 122 } 123 } 124 } } 125 off = off + dirent_reclen(rec) 126 } 127 } 128 } 129 sys_close(fd) 130 131 w("-- tally --\n" as *u8) 132 w(" award-granting instruments scanned=" as *u8); wn(scanned[0]); w("\n" as *u8) 133 w(" CYNICAL (adopt hg_grade, trusted) =" as *u8); wn(cyn[0]); w("\n" as *u8) 134 w(" SYNTH-BAR (neg-control, synthetic) =" as *u8); wn(syn[0]); w("\n" as *u8) 135 w(" BARE (optimism unchecked) =" as *u8); wn(bare[0]); w("\n" as *u8) 136 var risk: i64 = 0 137 if scanned[0]>0 { risk = (bare[0]*1000 + syn[0]*500) / scanned[0] } 138 w(" OPTIMISM_RISK=" as *u8); wn(risk); w("/1000 (0 only when every instrument adopts the cynical bar)\n" as *u8) 139 // honest verdict: this is a measurement, not a pass. It is GREEN (ran cleanly); the RISK is the payload. 140 w("VERDICT: verdict=GREEN (audit ran; optimism_risk is the honest payload, and it is HIGH by design until the sweep lands)\n" as *u8) 141 sys_exit(0) 142 return 0 143}