code wiki / (root) / nx_ui_judge.nx

nx_ui_judge.nx source

↩ module page · 156 lines · 8996 B

1// nx_ui_judge.nx -- the AUTONOMOUS UI competency judge. Reads a data-driven rubric (web_assets/ui_rubric.conf: 2// dim|weight|label|marker, grounded in the Awwwards axes + the banked aw_*/brand_* research), then SCORES every 3// page in the ship manifest (web_assets/ui_ship.conf) and AUTO-CERTIFIES pass/fail against a competency threshold 4// -- so an emitted page is judged WITHOUT a human reviewing it per-site. Composes nx_uxcx_grade's pure uxg_has. 5// REPRODUCIBLE: deterministic sovereign organ (nx_cc->nxasm), rubric is editable data. HONEST: it scores the 6// COMPUTABLE design-craft subset and certifies a FLOOR ("meets the measurable award-craft bar"), NOT subjective 7// award-winning beauty (that ceiling stays a human/jury). license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls_x86_64.nx" 9import "nx_uxcx_grade.nx" 10const K_MAGIC_1024: i64 = 1024 11 12const THRESH: i64 = 800 // S-class competency floor, in permil (0..1000) 13 14func jw(s: *u8) -> i64 { var n: i64=0; while s[n]!=0 { n=n+1 } sys_write(1,s,n); return 0 } 15func jn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} 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-(m/10)*10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 16func wslice(base: *u8, off: i64, len: i64) -> i64 { sys_write(1, ((base as i64)+off) as *u8, len); return 0 } 17func pmil(a: i64, b: i64) -> i64 { if b==0 { return 0 } return (a*1000)/b } 18 19func feq(base: *u8, off: i64, len: i64, lit: *u8) -> i64 { 20 var i: i64=0 21 while lit[i]!=0 { if i>=len { return 0 } if base[off+i]!=lit[i] { return 0 } i=i+1 } 22 if i!=len { return 0 } 23 return 1 24} 25func slice_z(base: *u8, off: i64, len: i64) -> *u8 { let out: *u8=sys_mmap(K_MAGIC_1024); var i: i64=0; while i<len { out[i]=base[off+i]; i=i+1 } out[i]=0 as u8; return out } 26func splitp(base: *u8, ls: i64, le: i64, foff: *i64, flen: *i64) -> i64 { 27 var fi: i64=0; var s: i64=ls; var i: i64=ls 28 while i<le { if (base[i] as i64)==0x7c { if fi<8 { foff[fi]=s; flen[fi]=i-s; fi=fi+1 } s=i+1 } i=i+1 } 29 if fi<8 { foff[fi]=s; flen[fi]=le-s; fi=fi+1 } 30 return fi 31} 32func atoi_sl(base: *u8, off: i64, len: i64) -> i64 { 33 var v: i64=0; var i: i64=0 34 while i<len { let c: i64=base[off+i] as i64; if c>=48 { if c<=57 { v=v*10+(c-48) } } i=i+1 } 35 return v 36} 37// map a 2-char dim code to index: DE0 US1 CR2 AX3 CO4, else -1 38func dim_idx(base: *u8, off: i64) -> i64 { 39 let a: i64=base[off] as i64; let b: i64=base[off+1] as i64 40 if a==68 { return 0 } // D 41 if a==85 { return 1 } // U 42 if a==67 { if b==82 { return 2 } if b==79 { return 4 } return 0-1 } // CR / CO 43 if a==65 { return 3 } // A 44 return 0-1 45} 46 47func main() -> i64 { 48 // ---- load rubric ---- 49 let rlen: *i64 = sys_mmap(8) as *i64 50 let rbuf: *u8 = sys_read_file_x86_64("web_assets/ui_rubric.conf" as *u8, rlen) 51 if rbuf == (0 as *u8) { jw("cannot read web_assets/ui_rubric.conf\n" as *u8); sys_exit(1); return 1 } 52 let rn: i64 = rlen[0] 53 let rdi: *i64 = sys_mmap(48*8) as *i64 54 let rw: *i64 = sys_mmap(48*8) as *i64 55 let rmo: *i64 = sys_mmap(48*8) as *i64 56 let rml: *i64 = sys_mmap(48*8) as *i64 57 let dt: *i64 = sys_mmap(48) as *i64 58 var z: i64=0; while z<6 { dt[z]=0; z=z+1 } 59 let foff: *i64 = sys_mmap(80) as *i64 60 let flen: *i64 = sys_mmap(80) as *i64 61 var nr: i64=0; var totw: i64=0 62 var ls: i64=0 63 while ls<rn { 64 var le: i64=0-1; var k: i64=ls 65 while k<rn { if le<0 { if (rbuf[k] as i64)==0x0a { le=k } } k=k+1 } 66 if le<0 { le=rn } 67 var skip: i64=0 68 if le<=ls { skip=1 } 69 if skip==0 { if (rbuf[ls] as i64)==0x23 { skip=1 } } 70 if skip==0 { 71 let nf: i64 = splitp(rbuf, ls, le, foff, flen) 72 if nf>=4 { if nr<48 { 73 let di: i64 = dim_idx(rbuf, foff[0]) 74 if di>=0 { 75 rdi[nr]=di; rw[nr]=atoi_sl(rbuf, foff[1], flen[1]); rmo[nr]=foff[3]; rml[nr]=flen[3] 76 dt[di]=dt[di]+rw[nr]; totw=totw+rw[nr]; nr=nr+1 77 } 78 } } 79 } 80 ls=le+1 81 } 82 83 jw("=== nx_ui_judge -- AUTONOMOUS UI competency judge ===\n" as *u8) 84 jw("rubric: " as *u8); jn(nr); jw(" rules, total weight " as *u8); jn(totw); jw(" (web_assets/ui_rubric.conf, data-driven)\n" as *u8) 85 jw("threshold=" as *u8); jn(THRESH); jw("permil = S-class competency FLOOR -> auto CERTIFY, no per-site human review.\n" as *u8) 86 jw("HONEST: scores the COMPUTABLE design-craft subset (grounded in aw_*/brand_* research); certifies the FLOOR, not subjective beauty.\n\n" as *u8) 87 88 // ---- judge every REQUIRE page in the ship manifest ---- 89 let slen: *i64 = sys_mmap(8) as *i64 90 let sbuf: *u8 = sys_read_file_x86_64("web_assets/ui_ship.conf" as *u8, slen) 91 if sbuf == (0 as *u8) { jw("cannot read ship manifest\n" as *u8); sys_exit(1); return 1 } 92 let sn: i64 = slen[0] 93 let de: *i64 = sys_mmap(48) as *i64 94 let tot: *i64 = sys_mmap(48) as *i64 95 tot[0]=0; tot[1]=0; tot[2]=0; tot[3]=0 96 var sls: i64=0 97 while sls<sn { 98 var sle: i64=0-1; var kk: i64=sls 99 while kk<sn { if sle<0 { if (sbuf[kk] as i64)==0x0a { sle=kk } } kk=kk+1 } 100 if sle<0 { sle=sn } 101 var sk: i64=0 102 if sle<=sls { sk=1 } 103 if sk==0 { if (sbuf[sls] as i64)==0x23 { sk=1 } } 104 if sk==0 { 105 let nf2: i64 = splitp(sbuf, sls, sle, foff, flen) 106 if nf2>=2 { 107 if feq(sbuf, foff[0], flen[0], "require" as *u8)==1 { 108 var is_hero: i64 = 0 109 if nf2>=4 { if feq(sbuf, foff[3], flen[3], "hero" as *u8)==1 { is_hero=1 } } 110 let pathz: *u8 = slice_z(sbuf, foff[1], flen[1]) 111 let plen: *i64 = sys_mmap(8) as *i64 112 let page: *u8 = sys_read_file_x86_64(pathz, plen) 113 var d2: i64=0; while d2<5 { de[d2]=0; d2=d2+1 } 114 jw(" " as *u8) 115 if nf2>=3 { wslice(sbuf, foff[2], flen[2]) } else { wslice(sbuf, foff[1], flen[1]) } 116 if is_hero==1 { jw(" [HERO]\n" as *u8) } else { jw(" [content]\n" as *u8) } 117 if page == (0 as *u8) { jw(" (missing)\n" as *u8); if is_hero==1 { tot[1]=tot[1]+1; tot[2]=tot[2]+1 } } 118 else { 119 let pn: i64 = plen[0] 120 var earned: i64=0; var i: i64=0 121 while i<nr { 122 if uxg_has(page, pn, ((rbuf as i64)+rmo[i]) as *u8, rml[i])==1 { earned=earned+rw[i]; let d: i64=rdi[i]; de[d]=de[d]+rw[i] } 123 i=i+1 124 } 125 let pm: i64 = pmil(earned, totw) 126 jw(" " as *u8); jn(pm); jw("permil DE:" as *u8); jn(pmil(de[0],dt[0])); jw(" US:" as *u8); jn(pmil(de[1],dt[1])); jw(" CR:" as *u8); jn(pmil(de[2],dt[2])); jw(" AX:" as *u8); jn(pmil(de[3],dt[3])); jw(" CO:" as *u8); jn(pmil(de[4],dt[4])); jw(" -> " as *u8) 127 if is_hero==1 { 128 tot[1]=tot[1]+1 129 if pm>=THRESH { jw("CERTIFY (hero >= competency)\n" as *u8); tot[0]=tot[0]+1 } else { jw("FAIL (hero BELOW competency -> BLOCKS ship)\n" as *u8); tot[2]=tot[2]+1 } 130 } else { 131 tot[3]=tot[3]+1 132 jw("content (compliance-gated; competency aspirational)\n" as *u8) 133 } 134 } 135 } 136 } 137 } 138 sls=sle+1 139 } 140 141 jw("\n--- FLEET VERDICT: HERO certified " as *u8); jn(tot[0]); jw(" / " as *u8); jn(tot[1]); jw(" (competency >= " as *u8); jn(THRESH); jw("permil) ; content pages " as *u8); jn(tot[3]); jw(" (compliance-gated) ---\n" as *u8) 142 jw(" => generation is AUTONOMOUSLY judged: HERO pages must clear competency, docs need only comply. NO human per-site.\n" as *u8) 143 144 // NEG-CONTROL: a bare page MUST fall below the floor (the judge is not vacuous) 145 let bare: *u8 = "<!doctype html><html><head><title>x</title></head><body><h1>hi</h1><p>p</p></body></html>" as *u8 146 var bnn: i64=0; while bare[bnn]!=0 { bnn=bnn+1 } 147 var earned2: i64=0; var j: i64=0 148 while j<nr { if uxg_has(bare, bnn, ((rbuf as i64)+rmo[j]) as *u8, rml[j])==1 { earned2=earned2+rw[j] } j=j+1 } 149 let bpm: i64 = pmil(earned2, totw) 150 jw(" NEG-CONTROL bare page = " as *u8); jn(bpm); jw("permil -> " as *u8) 151 if bpm<THRESH { jw("correctly BELOW floor (judge discriminates)\n" as *u8) } else { jw("FAIL: judge too lenient\n" as *u8) } 152 if tot[2]==0 { jw("VERDICT: GREEN (every HERO page auto-certifies above competency; generation judged with NO human per-site)\n" as *u8); sys_exit(0) } 153 jw("VERDICT: RED (a hero page fell below competency -> generation BLOCKED)\n" as *u8) 154 sys_exit(1) 155 return 1 156}