code wiki / _hdl_build / nx_studio_pick_gate.nx

nx_studio_pick_gate.nx source

↩ module page · 68 lines · 5060 B

1// nx_studio_pick_gate.nx -- gate for the capability PICKER (web_assets/_studio/editor_pick.html), the studio 2// front door. Proves it lets the user SELECT by capability: it links all THREE tier editors (guided/blocks/ 3// freeform), labels + describes each by who it's for, resolves those links relative to where it's mounted (so it 4// works at / and at /webdev), and conveys the shared governed+portable core (no vendor lock). Static gate (the 5// picker is pure navigation). Appends a CMSGATE row to knowledge/status/cms_gate.log on all-pass. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7 8func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func pn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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%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 } 10func pcat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var k: i64=0; while s[k]!=(0 as u8){dst[o]=s[k];o=o+1;k=k+1} return o } 11func pcatn(dst: *u8, off: i64, v: i64) -> i64 { var o: i64=off; let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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}; var i: i64=0; while i<k{dst[o]=t[k-1-i];o=o+1;i=i+1} return o } 12func prow(id: i64, ok: i64, what: *u8) -> i64 { pw("PKROW " as *u8); pn(id); pw(" " as *u8); if ok==1 { pw("PASS " as *u8) } else { pw("FAIL " as *u8) } pw(what); pw("\n" as *u8); return ok } 13func pslurp(path: *u8, buf: *u8, cap: i64) -> i64 { 14 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } 15 var total: i64 = 0; var go: i64 = 1 16 while go == 1 { let r: i64 = sys_read(fd, buf + total, cap - total); if r <= 0 { go = 0 } if r > 0 { total = total + r } if total >= cap { go = 0 } } 17 sys_close(fd); return total 18} 19func phas(hay: *u8, hn: i64, needle: *u8) -> i64 { 20 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 21 if nl==0 { return 1 } if nl>hn { return 0 } 22 let last: i64=hn-nl; var i: i64=0 23 while i<=last { var j: i64=0; var hit: i64=1; while j<nl { if (hay[i+j] as i64)!=(needle[j] as i64){hit=0;j=nl} if hit==1{j=j+1} } if hit==1 { return 1 } i=i+1 } 24 return 0 25} 26 27func main() -> i64 { 28 let html: *u8 = sys_mmap(262144) 29 let hn: i64 = pslurp("web_assets/_studio/editor_pick.html" as *u8, html, 262143) 30 31 var rows: i64 = 0 32 var pass: i64 = 0 33 var ok: i64 = 0 34 35 // R0: links all three tier editors 36 ok = 0; if hn>0 { if phas(html,hn,"lk_guided" as *u8)==1 { if phas(html,hn,"lk_blocks" as *u8)==1 { if phas(html,hn,"lk_freeform" as *u8)==1 { if phas(html,hn,"/guided" as *u8)==1 { if phas(html,hn,"/blocks" as *u8)==1 { if phas(html,hn,"/freeform" as *u8)==1 { ok=1 } } } } } } } 37 rows=rows+1; pass=pass+prow(0, ok, "picker links all 3 tier editors (guided/blocks/freeform)" as *u8) 38 39 // R1: labels + describes each tier by capability (who it's for) 40 ok = 0; if phas(html,hn,"Guided" as *u8)==1 { if phas(html,hn,"Blocks" as *u8)==1 { if phas(html,hn,"Free-form" as *u8)==1 { if phas(html,hn,"Best if" as *u8)==1 { ok=1 } } } } 41 rows=rows+1; pass=pass+prow(1, ok, "picker labels + describes each tier by capability (Best if you...)" as *u8) 42 43 // R2: resolves links relative to where it is mounted (works at / and /webdev) 44 ok = 0; if phas(html,hn,"location.pathname" as *u8)==1 { ok=1 } 45 rows=rows+1; pass=pass+prow(2, ok, "picker resolves tier links relative to its mount (/ and /webdev)" as *u8) 46 47 // R3: conveys the shared governed + portable core (no vendor lock) -- the capability-adaptive ethos 48 ok = 0; if phas(html,hn,"sovereign engine" as *u8)==1 { if phas(html,hn,"export" as *u8)==1 { ok=1 } } 49 rows=rows+1; pass=pass+prow(3, ok, "picker conveys the shared governed+portable core (no vendor lock)" as *u8) 50 51 // R4: it is a chooser, not a builder -- no engine logic of its own 52 ok = 0; if phas(html,hn,"sg_build" as *u8)==0 { if phas(html,hn,"<section" as *u8)==0 { ok=1 } } 53 rows=rows+1; pass=pass+prow(4, ok, "picker is a chooser, not a builder (no engine logic)" as *u8) 54 55 pw("NX-STUDIO-PICK-GATE rows=" as *u8); pn(rows); pw(" pass=" as *u8); pn(pass); pw("\n" as *u8) 56 if pass == rows { 57 let line: *u8 = sys_mmap(256) 58 var off: i64 = pcat(line, 0, "CMSGATE row=nx_studio_pick capability-tier-picker rows=" as *u8) 59 off = pcatn(line, off, rows); off = pcat(line, off, " pass=" as *u8); off = pcatn(line, off, pass) 60 off = pcat(line, off, " verdict=PASS (front door: user selects tier by capability; 3 tiers linked)\n" as *u8) 61 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4) 62 if gf >= 0 { sys_write(gf, line, off); sys_close(gf) } 63 pw("NX-STUDIO-PICK-GATE verdict=PASS -- capability picker front door (users select their tier)\n" as *u8) 64 sys_exit(0); return 0 65 } 66 pw("NX-STUDIO-PICK-GATE verdict=FAIL -- NOT recorded (no fake-green)\n" as *u8) 67 sys_exit(1); return 1 68}