code wiki / _hdl_build / nx_cms_layered_spec.nx
nx_cms_layered_spec.nx source
↩ module page · 88 lines · 5996 B
1// nx_cms_layered_spec.nx -- the team SPECS the CMS and SPLITS it into HARDWARE-LAYER-UP tasks (operator: "make
2// sure its getting speced and split into hardware layer through each layer tasks up"). Drives the team's
3// nx_spec_layers synthesis: every task is research-CORROBORATED (deep-research wpq1btr1l, 25/25 confirmed, OWASP/
4// NIST/Craft primary -> nothing spec'd from thin air), ordered BOTTOM-UP by stack layer (L0 machine-code/syscalls
5// -> L8 app) via ss_build_rank, with IMPLEMENTATION-gap detection (HAVE in our sovereign stack vs must BUILD).
6// The lowest BUILD task is the team's next work item; gaps are surfaced as raised hands, not hidden. Claude
7// tutors the novel modules; the tutoring-ledger tracks the load down. license_tier: ORIGINAL
8import "nx_spec_layers.nx"
9import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
10import "nx_pm_review_log.nx"
11import "nx_syscalls.nx"
12
13func cl_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
14// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
15// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
16// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
17// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
18func cl_fputn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
19func cl_putn(v: i64) -> i64 { return cl_fputn(1, v) }
20
21const NL: i64 = 12
22
23func layer_label(l: i64) -> *u8 {
24 if l==0 { return "L0-syscall " as *u8 }
25 if l==3 { return "L3-crypto " as *u8 }
26 if l==7 { return "L7-http " as *u8 }
27 return "L8-app " as *u8
28}
29
30func main() -> i64 {
31 let name: *i64 = sys_mmap(8*NL) as *i64
32 let layer:*i64 = sys_mmap(8*NL) as *i64
33 let dep: *i64 = sys_mmap(8*NL) as *i64
34 let have: *i64 = sys_mmap(8*NL) as *i64 // 1 = already in the sovereign stack, 0 = must BUILD
35 let corr: *i64 = sys_mmap(8*NL) as *i64 // research corroboration (all 1 -> 25/25 confirmed)
36
37 // ---- CMS as STACK-LAYER tasks (bottom-up). Each cites the research that grounds it. ----
38 name[0]="atomic content write (sys_renameat temp->canonical)" as *u8 as i64; layer[0]=0; dep[0]=0; have[0]=1; corr[0]=1
39 name[1]="CSPRNG source (/dev/urandom read)" as *u8 as i64; layer[1]=0; dep[1]=1; have[1]=1; corr[1]=1
40 name[2]="secure token: 128-bit CSPRNG hex (session-id + CSRF) [NEXT]" as *u8 as i64; layer[2]=3; dep[2]=0; have[2]=0; corr[2]=1
41 name[3]="Argon2id password hash (m=19MiB,t=2,p=1; needs BLAKE2b)" as *u8 as i64; layer[3]=3; dep[3]=1; have[3]=0; corr[3]=1
42 name[4]="CSRF synchronizer token bind+verify (>=128b, per-session)" as *u8 as i64;layer[4]=3; dep[4]=2; have[4]=0; corr[4]=1
43 name[5]="HTTP POST body parse (urlencoded form fields)" as *u8 as i64; layer[5]=7; dep[5]=0; have[5]=0; corr[5]=1
44 name[6]="cookie I/O: Set-Cookie HttpOnly+Secure+SameSite + parse" as *u8 as i64; layer[6]=7; dep[6]=1; have[6]=0; corr[6]=1
45 name[7]="/admin/* routing + auth-guard + login lockout/backoff" as *u8 as i64; layer[7]=7; dep[7]=2; have[7]=0; corr[7]=1
46 name[8]="HTML allowlist sanitizer (KSES-style, run LAST=keystone)" as *u8 as i64; layer[8]=8; dep[8]=0; have[8]=0; corr[8]=1
47 name[9]="content model: content store + render-from-data (C2)" as *u8 as i64; layer[9]=8; dep[9]=1; have[9]=0; corr[9]=1
48 name[10]="editor UI: field-based admin + live preview (C3)" as *u8 as i64; layer[10]=8; dep[10]=2; have[10]=0; corr[10]=1
49 name[11]="draft/revision/publish: Craft-model, atomic, rollback (C5)" as *u8 as i64; layer[11]=8; dep[11]=3; have[11]=0; corr[11]=1
50
51 // ---- order BOTTOM-UP via the team's tool: build_rank = stack_layer*10 + dep_depth ----
52 let rank: *i64 = sys_mmap(8*NL) as *i64
53 var i: i64 = 0
54 while i < NL { rank[i] = ss_build_rank(layer[i], dep[i]); i = i + 1 }
55 let order: *i64 = sys_mmap(8*NL) as *i64
56 ss_order_build(rank, NL, order)
57
58 let research_gaps: i64 = ss_count_gaps(corr, NL) // research raised-hands (should be 0 -> all grounded)
59 let admissible: i64 = ss_spec_admissible(corr, NL, research_gaps)
60
61 cl_puts("=== CMS LAYERED SPEC -- hardware(L0)->app(L8), build order, gap-detected ===\n" as *u8)
62 cl_puts("(grounded: deep-research wpq1btr1l 25/25 confirmed; research-gaps=" as *u8); cl_putn(research_gaps)
63 cl_puts(" admissible=" as *u8); cl_putn(admissible); cl_puts(")\n\n" as *u8)
64
65 let fd: i64 = pm_open("/tmp/nishi_pm_plan.log" as *u8)
66 pm_w(fd, "\n# CMS LAYERED SPEC 2026-06-06 (bottom-up L0->L8; grounded wpq1btr1l; HAVE vs BUILD)\n" as *u8)
67
68 var build_gaps: i64 = 0; var first_build: i64 = 0 - 1
69 var step: i64 = 1; var k: i64 = 0
70 while k < NL {
71 let b: i64 = order[k]
72 cl_puts("#" as *u8); cl_putn(step); cl_puts(" [" as *u8); cl_puts(layer_label(layer[b])); cl_puts("] " as *u8)
73 if have[b]==1 { cl_puts("HAVE " as *u8) } else { cl_puts("BUILD " as *u8); build_gaps = build_gaps + 1; if first_build < 0 { first_build = b } }
74 cl_puts(name[b] as *u8); cl_puts("\n" as *u8)
75 pm_w(fd, " step=" as *u8); cl_fputn(fd, step); pm_w(fd, " L" as *u8); cl_fputn(fd, layer[b])
76 if have[b]==1 { pm_w(fd, " HAVE " as *u8) } else { pm_w(fd, " BUILD " as *u8) }
77 pm_w(fd, name[b] as *u8); pm_w(fd, "\n" as *u8)
78 step = step + 1; k = k + 1
79 }
80 sys_close(fd)
81
82 cl_puts("\n>>> HAVE=" as *u8); cl_putn(NL - build_gaps); cl_puts(" BUILD=" as *u8); cl_putn(build_gaps)
83 cl_puts(" (raised hands -> assigned tasks). NEXT (lowest BUILD): " as *u8)
84 if first_build >= 0 { cl_puts(name[first_build] as *u8) }
85 cl_puts("\n>>> Build bottom-up: L3 crypto primitives -> L7 http POST/cookie/route -> L8 sanitizer->content->editor->draft.\n" as *u8)
86 cl_puts(">>> Each layer hands a tested deliverable up. Logged to /tmp/nishi_pm_plan.log.\n" as *u8)
87 sys_exit(0); return 0
88}