code wiki / _hdl_build / nx_uigen_refine_gate.nx

nx_uigen_refine_gate.nx source

↩ module page · 144 lines · 7075 B

1import "nx_gate_gn.nx" 2// nx_uigen_refine_gate.nx -- MEASURES the ITERATIVE-REFINE rung: spec-delta commands mutate a design and 3// re-emit deterministically. The refine metric pair is TARGETED CHANGE (the asked-for aspect changed) + 4// PRESERVATION (everything else stayed) -- checked on the emitted BYTES. Rule-based analog of the v0 chat 5// loop ("add a pricing table", "make it warmer"): feedback in, changed valid design out, nothing else broken. 6// expect_exit: 0 license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_uigen_l3.nx" 9import "nx_gate_verdict.nx" 10 11func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func litlen(lit: *u8) -> i64 { var n: i64=0; while lit[n]!=(0 as u8){n=n+1} return n } 13func idxof(buf: *u8, len: i64, lit: *u8) -> i64 { 14 let ll: i64=litlen(lit) 15 if ll==0 { return 0-1 } 16 var i: i64=0 17 while i+ll<=len { var j: i64=0; var ok: i64=1; while j<ll { if buf[i+j]!=lit[j] { ok=0; j=ll } else { j=j+1 } } if ok==1 { return i } i=i+1 } 18 return 0-1 19} 20func has(buf: *u8, len: i64, lit: *u8) -> i64 { if idxof(buf,len,lit)>=0 { return 1 } return 0 } 21// build "rgb(r,g,b)" for hsl(h,s,l) into dst (returns dst for convenience) 22func rgbstr(dst: *u8, h: i64, s: i64, l: i64) -> *u8 { 23 let n: i64 = l1_rgb(dst, 0, h, s, l) 24 dst[n] = 0 as u8 25 return dst 26} 27func craftok(buf: *u8, len: i64) -> i64 { 28 if has(buf,len,"var(--nx-" as *u8)==0 { return 0 } 29 if has(buf,len,"skip-link" as *u8)==0 { return 0 } 30 return 1 31} 32 33func main() -> i64 { 34 let cap: i64 = 524288 35 let buf: *u8 = sys_mmap(cap) 36 let spec: *i64 = sys_mmap(128) as *i64 37 let cstr: *u8 = sys_mmap(64) 38 var pass: i64 = 0 39 var total: i64 = 0 40 41 // handcrafted baseline: hue 208 blue, analogous, mid radius, mid density, 3 middles [features, split, faq] 42 spec[0]=208; spec[1]=0; spec[2]=1; spec[3]=1; spec[4]=3 43 spec[5]=0; spec[6]=1; spec[7]=5 44 spec[10]=0 45 46 gp("=== NX-UIGEN-REFINE GATE -- spec-delta refine: targeted change + preservation, on the emitted bytes ===\n" as *u8) 47 var off: i64 = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8) 48 gp(" baseline: bytes=" as *u8); gn(off) 49 var ok: i64 = 1 50 if has(buf,off,"class=\"sec faqband\"" as *u8)==0 { ok=0 } 51 if has(buf,off,"class=\"sec priceband\"" as *u8)==1 { ok=0 } 52 if has(buf,off,rgbstr(cstr,208,62,46))==0 { ok=0 } 53 if craftok(buf,off)==0 { ok=0 } 54 total=total+1; pass=pass+ok 55 if ok==1 { gp(" [PASS] faq present, no pricing, hue-208 primary, craft\n" as *u8) } else { gp(" [FAIL] baseline\n" as *u8) } 56 57 // 1) add pricing -> pricing appears BEFORE faq (grammar rule on insert); features+split preserved 58 var ap: i64 = l3_refine(spec, "add pricing" as *u8) 59 off = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8) 60 ok = 1 61 if ap != 1 { ok=0 } 62 let pat: i64 = idxof(buf,off,"class=\"sec priceband\"" as *u8) 63 let fat: i64 = idxof(buf,off,"class=\"sec faqband\"" as *u8) 64 if pat < 0 { ok=0 } 65 if fat < 0 { ok=0 } 66 if pat >= 0 { if fat >= 0 { if fat < pat { ok=0 } } } 67 if has(buf,off,"class=\"grid3\"" as *u8)==0 { ok=0 } 68 if has(buf,off,"class=\"sec splitband\"" as *u8)==0 { ok=0 } 69 if spec[4] != 4 { ok=0 } 70 if craftok(buf,off)==0 { ok=0 } 71 total=total+1; pass=pass+ok 72 if ok==1 { gp(" [PASS] add pricing: inserted before faq, others preserved, nmid=4\n" as *u8) } else { gp(" [FAIL] add pricing\n" as *u8) } 73 74 // 2) hue 300 -> palette changes to 300; old 208 primary gone; sections untouched 75 ap = l3_refine(spec, "hue 300" as *u8) 76 off = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8) 77 ok = 1 78 if ap != 1 { ok=0 } 79 if has(buf,off,rgbstr(cstr,300,62,46))==0 { ok=0 } 80 if has(buf,off,rgbstr(cstr,208,62,46))==1 { ok=0 } 81 if has(buf,off,"class=\"sec priceband\"" as *u8)==0 { ok=0 } 82 if has(buf,off,"class=\"sec faqband\"" as *u8)==0 { ok=0 } 83 total=total+1; pass=pass+ok 84 if ok==1 { gp(" [PASS] hue 300: palette retargeted, sections preserved\n" as *u8) } else { gp(" [FAIL] hue 300\n" as *u8) } 85 86 // 3) accent complement -> accent becomes hue+180 = 120 (light accent tone s72 l50) 87 ap = l3_refine(spec, "accent complement" as *u8) 88 off = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8) 89 ok = 1 90 if ap != 1 { ok=0 } 91 if has(buf,off,rgbstr(cstr,120,72,50))==0 { ok=0 } 92 total=total+1; pass=pass+ok 93 if ok==1 { gp(" [PASS] accent complement: accent at hue 120\n" as *u8) } else { gp(" [FAIL] accent complement\n" as *u8) } 94 95 // 4) compact -> section rhythm tightens to 56px 96 ap = l3_refine(spec, "compact" as *u8) 97 off = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8) 98 ok = 1 99 if ap != 1 { ok=0 } 100 if has(buf,off,".sec{padding:56px 0}" as *u8)==0 { ok=0 } 101 total=total+1; pass=pass+ok 102 if ok==1 { gp(" [PASS] compact: rhythm 56px\n" as *u8) } else { gp(" [FAIL] compact\n" as *u8) } 103 104 // 5) rounder -> radius 14 -> 26 105 ap = l3_refine(spec, "rounder" as *u8) 106 off = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8) 107 ok = 1 108 if ap != 1 { ok=0 } 109 if has(buf,off,"border-radius:26px}" as *u8)==0 { ok=0 } 110 total=total+1; pass=pass+ok 111 if ok==1 { gp(" [PASS] rounder: radius 26px\n" as *u8) } else { gp(" [FAIL] rounder\n" as *u8) } 112 113 // 6) drop pricing -> gone again, faq stays, nmid back to 3 114 ap = l3_refine(spec, "drop pricing" as *u8) 115 off = l3_emit_from_spec(buf, 0, spec, "Nova" as *u8, "Nishi" as *u8) 116 ok = 1 117 if ap != 1 { ok=0 } 118 if has(buf,off,"class=\"sec priceband\"" as *u8)==1 { ok=0 } 119 if has(buf,off,"class=\"sec faqband\"" as *u8)==0 { ok=0 } 120 if spec[4] != 3 { ok=0 } 121 if craftok(buf,off)==0 { ok=0 } 122 total=total+1; pass=pass+ok 123 if ok==1 { gp(" [PASS] drop pricing: removed, faq preserved, nmid=3\n" as *u8) } else { gp(" [FAIL] drop pricing\n" as *u8) } 124 125 // 7) grammar refusals: dropping below 3 middles / adding a duplicate must be REFUSED 126 var r1: i64 = l3_refine(spec, "drop faq" as *u8) 127 var r2: i64 = l3_refine(spec, "add split" as *u8) 128 ok = 1 129 if r1 != 0 { ok=0 } 130 if r2 != 0 { ok=0 } 131 total=total+1; pass=pass+ok 132 if ok==1 { gp(" [PASS] refusals: below-min drop refused, duplicate add refused\n" as *u8) } else { gp(" [FAIL] refusals\n" as *u8) } 133 134 gp("\n-- REFINE MEASUREMENT: " as *u8); gn(pass); gp("/" as *u8); gn(total); gp(" (targeted change + preservation + grammar-guarded)\n" as *u8) 135 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 136 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 137 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 138 let ctr__dry: *i64 = gv_ctr() 139 ctr__dry[0] = pass 140 ctr__dry[1] = total 141 let rc__dry: i64 = gv_verdict("UIGEN-REFINE-GATE" as *u8, ctr__dry, ": feedback commands change EXACTLY the asked-for aspect, preserve the rest," as *u8) 142 sys_exit(rc__dry) 143 return rc__dry 144}