code wiki / _hdl_build / nx_uigen_l2_gate.nx
nx_uigen_l2_gate.nx source
↩ module page · 95 lines · 6222 B
1import "nx_gate_gn.nx"
2// nx_uigen_l2_gate.nx -- MEASURES roadmap rung L2 (intent->mapping). Feeds a HELD-OUT set of natural-language
3// briefs and proves the system maps each to the APPROPRIATE structure: expected components PRESENT + wrong ones
4// ABSENT (a form brief -> a form and NOT a dashboard), correct topic-hue, still S-class craft. Appropriateness
5// is the metric that separates L2 from L1 (L1 varies by spec; L2 chooses structure from MEANING). Writes a
6// sample for the independent nx_ui_judge. GREEN only if every brief is appropriate. expect_exit: 0 license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_uigen_l2.nx"
9
10func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func contains(buf: *u8, len: i64, lit: *u8) -> i64 {
12 var ll: i64=0; while lit[ll]!=(0 as u8){ll=ll+1}
13 if ll==0 { return 1 }
14 var i: i64=0
15 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 1 } i=i+1 }
16 return 0
17}
18func countof(buf: *u8, len: i64, lit: *u8) -> i64 {
19 var ll: i64=0; while lit[ll]!=(0 as u8){ll=ll+1}
20 if ll==0 { return 0 }
21 var c: i64=0; var i: i64=0
22 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 { c=c+1; i=i+ll } else { i=i+1 } }
23 return c
24}
25
26// run one brief; print a row; return 1 if kind+hue+appropriate+craft all hold.
27func check_brief(buf: *u8, brief: *u8, title: *u8, exp_kind: i64, exp_hue: i64) -> i64 {
28 let kind: i64 = l2_kind(brief)
29 let hue: i64 = l2_hue(brief)
30 let off: i64 = l2_generate(buf, 0, brief, title, "Nishi" as *u8)
31 let has_score: i64 = contains(buf, off, "class=\"scorecard\"" as *u8)
32 let has_table: i64 = contains(buf, off, "class=\"dtable\"" as *u8)
33 let has_form: i64 = contains(buf, off, "<form" as *u8)
34 let has_label: i64 = contains(buf, off, "<label" as *u8)
35 let has_hero: i64 = contains(buf, off, "class=\"hero\"" as *u8)
36 let has_grid: i64 = contains(buf, off, "grid3" as *u8)
37 let has_lede: i64 = contains(buf, off, "class=\"lede\"" as *u8)
38 let h2n: i64 = countof(buf, off, "<h2" as *u8)
39 let dead_anchor: i64 = contains(buf, off, "action=\"#\"" as *u8)
40 let demo_marked: i64 = contains(buf, off, "<fieldset disabled" as *u8)
41 var approp: i64 = 0
42 if exp_kind==1 { if has_score==1 { if has_table==1 { if has_form==0 { if has_hero==0 { approp=1 } } } } }
43 // R0a (debt 1785934272): a form brief maps to a form that is HONEST -- no dead action="#",
44 // and the unwired demo is visibly disabled
45 if exp_kind==3 { if has_form==1 { if has_label==1 { if has_score==0 { if has_hero==0 { if dead_anchor==0 { if demo_marked==1 { approp=1 } } } } } } }
46 if exp_kind==0 { if has_hero==1 { if has_grid==1 { if has_form==0 { if has_table==0 { approp=1 } } } } }
47 if exp_kind==2 { if h2n>=2 { if has_lede==1 { if has_form==0 { if has_score==0 { if has_hero==0 { approp=1 } } } } } }
48 // craft
49 var craft: i64 = 1
50 if contains(buf,off,"var(--nx-" as *u8)==0 { craft=0 }
51 if contains(buf,off,"skip-link" as *u8)==0 { craft=0 }
52 if contains(buf,off,"@media" as *u8)==0 { craft=0 }
53 if contains(buf,off,"clamp(" as *u8)==0 { craft=0 }
54 if contains(buf,off,"focus-visible" as *u8)==0 { craft=0 }
55 let kind_ok: i64 = kind==exp_kind
56 let hue_ok: i64 = hue==exp_hue
57 var pass: i64 = 0
58 if kind_ok==1 { if hue_ok==1 { if approp==1 { if craft==1 { pass=1 } } } }
59 let kn: *u8 = "?" as *u8
60 gp(" brief=\"" as *u8); gp(brief); gp("\"\n -> kind=" as *u8); gn(kind); gp("(exp " as *u8); gn(exp_kind); gp(") hue=" as *u8); gn(hue); gp("(exp " as *u8); gn(exp_hue); gp(") appropriate=" as *u8); gn(approp); gp(" craft=" as *u8); gn(craft); gp(" bytes=" as *u8); gn(off)
61 if pass==1 { gp(" [PASS]\n" as *u8) } else { gp(" [FAIL]\n" as *u8) }
62 return pass
63}
64
65func main() -> i64 {
66 let cap: i64 = 262144; let buf: *u8 = sys_mmap(cap)
67 gp("=== NX-UIGEN-L2 GATE -- intent->mapping: natural-language briefs -> APPROPRIATE structure ===\n" as *u8)
68 gp("Appropriateness = expected components present AND inappropriate ones absent. This is the metric that\n" as *u8)
69 gp("separates L2 (choose structure from MEANING) from L1 (vary style from a spec).\n\n" as *u8)
70
71 var pass: i64 = 0
72 pass = pass + check_brief(buf, "a fintech dashboard for monitoring payment metrics" as *u8, "PayMetrics" as *u8, 1, 212)
73 pass = pass + check_brief(buf, "a contact form for a health clinic" as *u8, "Northside Clinic" as *u8, 3, 150)
74 pass = pass + check_brief(buf, "a landing page for a new coffee product launch" as *u8, "Bean Co" as *u8, 0, 30)
75 pass = pass + check_brief(buf, "a reference guide about our design studio api" as *u8, "Studio API" as *u8, 2, 275)
76 pass = pass + check_brief(buf, "a signup form for an eco garden app" as *u8, "GrowKit" as *u8, 3, 108)
77 pass = pass + check_brief(buf, "an analytics report of legal case statistics" as *u8, "CaseStats" as *u8, 1, 232)
78
79 let approp_permil: i64 = pass*1000/6
80 // write a sample (the form -- exercises the new kit component) for the INDEPENDENT judge
81 let soff: i64 = l2_generate(buf, 0, "a contact form for a health clinic" as *u8, "Northside Clinic" as *u8, "Nishi" as *u8)
82 let fd: i64 = sys_openat_wr("web_assets/uigen_l2_sample.html" as *u8, 420)
83 if fd>=0 { sys_write(fd, buf, soff); sys_close(fd) }
84
85 gp("\n-- L2 MEASUREMENT: briefs=6 appropriate+correct=" as *u8); gn(pass); gp("/6 => appropriateness=" as *u8); gn(approp_permil); gp("permil\n" as *u8)
86 gp("-- sample (health-clinic FORM) written web_assets/uigen_l2_sample.html (" as *u8); gn(soff); gp(" bytes) -> nx_ui_judge confirms >=800\n" as *u8)
87 if pass==6 {
88 gp("=== UIGEN-L2 verdict=GREEN: every brief mapped to the RIGHT structure + topic palette, all S-class. intent->ui\n" as *u8)
89 gp("+ component-selection move GAP->PARTIAL (rule-based). The system now chooses structure from meaning. This is L2.\n" as *u8)
90 sys_exit(0); return 0
91 }
92 gp("=== UIGEN-L2 verdict=RED (a brief mapped wrong -- see [FAIL] rows)\n" as *u8)
93 sys_exit(1)
94 return 1
95}