code wiki / _hdl_build / nx_cms_builder_attempt.nx
nx_cms_builder_attempt.nx source
↩ module page · 104 lines · 5821 B
1// nx_cms_builder_attempt.nx -- the BUILDER ATTEMPTS the CMS backlog by COMPOSITION (operator: "make sure you
2// arent doing but allowing the team to TRY and then if they RAISE THEIR HAND to tutor and build their
3// capabilities in the right teammates"). For each CMS task (a type-spec in->out), the Builder SEARCHES its
4// authored-primitive library for a chain using ONLY available primitives. COMPOSED = the team authored it
5// itself (autonomous, Claude monitors only). RAISED-HAND = a required primitive is MISSING -> that, and only
6// that, is the tutoring target, routed to the right teammate. This catches my own over-reach: I hand-authored
7// the secure token, but the Builder can compose it from urandom+hex it ALREADY has. license_tier: ORIGINAL
8import "nx_syscalls.nx"
9
10func ba_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11
12// types
13const T_NONE: i64 = 0
14const T_PATH: i64 = 1
15const T_BYTES: i64 = 2
16const T_HEX: i64 = 3
17const T_FIELD:i64 = 4
18const T_KDF: i64 = 5
19const T_SAFE: i64 = 6
20const T_DOM: i64 = 7
21const NTYPE: i64 = 8
22
23// the Builder's authored-primitive library: in-type, out-type, available?(authored module exists), name.
24const NP: i64 = 8
25// globals via mmap in main; helper search uses them through params.
26
27// DFS: can we reach `target` from `cur` using primitives (avail-only if useunavail==0), marking used[].
28func ba_reach(cur: i64, target: i64, useunavail: i64, pin: *i64, pout: *i64, pav: *i64, used: *i64, vis: *i64) -> i64 {
29 if cur == target { return 1 }
30 vis[cur] = 1
31 var p: i64 = 0
32 while p < NP {
33 if pin[p] == cur {
34 if pav[p] == 1 { } else { }
35 let ok: i64 = useunavail
36 var allow: i64 = 0
37 if pav[p] == 1 { allow = 1 } else { if useunavail == 1 { allow = 1 } }
38 if allow == 1 {
39 if vis[pout[p]] == 0 {
40 if ba_reach(pout[p], target, useunavail, pin, pout, pav, used, vis) == 1 { used[p] = 1; return 1 }
41 }
42 }
43 }
44 p = p + 1
45 }
46 return 0
47}
48
49func ba_try(name: *u8, tin: i64, tout: i64, pin: *i64, pout: *i64, pav: *i64, pname: *i64) -> i64 {
50 let used: *i64 = sys_mmap(8*NP) as *i64
51 let vis: *i64 = sys_mmap(8*NTYPE) as *i64
52 var i: i64 = 0; while i < NP { used[i]=0; i=i+1 }
53 i = 0; while i < NTYPE { vis[i]=0; i=i+1 }
54 let composed: i64 = ba_reach(tin, tout, 0, pin, pout, pav, used, vis) // avail-only attempt
55 ba_puts(" task " as *u8); ba_puts(name)
56 if composed == 1 { ba_puts(" -> COMPOSED (Builder authored it autonomously)\n" as *u8); return 1 }
57 // not composable with what we have -> find the missing primitive(s) on a full-graph path = the raised hand
58 i = 0; while i < NP { used[i]=0; i=i+1 }
59 i = 0; while i < NTYPE { vis[i]=0; i=i+1 }
60 let full: i64 = ba_reach(tin, tout, 1, pin, pout, pav, used, vis)
61 ba_puts(" -> RAISED HAND" as *u8)
62 if full == 1 {
63 ba_puts(" (needs: " as *u8)
64 var p: i64 = 0; var first: i64 = 1
65 while p < NP { if used[p] == 1 { if pav[p] == 0 { if first == 0 { ba_puts(" + " as *u8) } ba_puts(pname[p] as *u8); first = 0 } } p = p + 1 }
66 ba_puts(")\n" as *u8)
67 } else { ba_puts(" (no primitive chain at all)\n" as *u8) }
68 return 0
69}
70
71func main() -> i64 {
72 let pin: *i64 = sys_mmap(8*NP) as *i64
73 let pout: *i64 = sys_mmap(8*NP) as *i64
74 let pav: *i64 = sys_mmap(8*NP) as *i64
75 let pname:*i64 = sys_mmap(8*NP) as *i64
76 // the library the Builder ALREADY has (authored modules) + the missing primitives (avail=0).
77 pin[0]=T_PATH; pout[0]=T_BYTES; pav[0]=1; pname[0]="read(sys_read_file)" as *u8 as i64
78 pin[1]=T_NONE; pout[1]=T_BYTES; pav[1]=1; pname[1]="urandom(/dev/urandom)" as *u8 as i64
79 pin[2]=T_BYTES; pout[2]=T_HEX; pav[2]=1; pname[2]="hex(authored)" as *u8 as i64
80 pin[3]=T_BYTES; pout[3]=T_FIELD; pav[3]=1; pname[3]="form_parse(percent_decode authored)" as *u8 as i64
81 pin[4]=T_BYTES; pout[4]=T_FIELD; pav[4]=1; pname[4]="json_field(json_string authored)" as *u8 as i64
82 pin[5]=T_BYTES; pout[5]=T_KDF; pav[5]=0; pname[5]="ARGON2ID(needs BLAKE2b)" as *u8 as i64
83 pin[6]=T_BYTES; pout[6]=T_DOM; pav[6]=0; pname[6]="HTML_PARSE" as *u8 as i64
84 pin[7]=T_DOM; pout[7]=T_SAFE; pav[7]=0; pname[7]="HTML_SANITIZE(allowlist)" as *u8 as i64
85
86 ba_puts("=== BUILDER ATTEMPTS the CMS backlog (compose-or-raise-hand) ===\n" as *u8)
87 var auto: i64 = 0; var hands: i64 = 0
88 auto = auto + ba_try("secure-token (NONE->HEX) " as *u8, T_NONE, T_HEX, pin, pout, pav, pname)
89 auto = auto + ba_try("intake-form-parse (BYTES->FIELD)" as *u8, T_BYTES, T_FIELD,pin, pout, pav, pname)
90 auto = auto + ba_try("content-load (PATH->FIELD) " as *u8, T_PATH, T_FIELD,pin, pout, pav, pname)
91 let h1: i64 = ba_try("password-hash (BYTES->KDFHASH) " as *u8, T_BYTES, T_KDF, pin, pout, pav, pname)
92 let h2: i64 = ba_try("html-sanitize (BYTES->SAFEHTML) " as *u8, T_BYTES, T_SAFE, pin, pout, pav, pname)
93 hands = (1 - h1) + (1 - h2)
94
95 ba_puts("\n>>> AUTONOMOUS (team composed): " as *u8)
96 let nb: *u8 = sys_mmap(8); nb[0]=(48+auto) as u8; sys_write(1, nb, 1)
97 ba_puts(" RAISED HANDS (tutor these only): " as *u8)
98 let hb: *u8 = sys_mmap(8); hb[0]=(48+hands) as u8; sys_write(1, hb, 1); ba_puts("\n" as *u8)
99 ba_puts(">>> TUTORING TARGETS (build capability in the right teammate):\n" as *u8)
100 ba_puts(" - ARGON2ID + BLAKE2b -> ENGINEER/crypto lib (then password-hash composes)\n" as *u8)
101 ba_puts(" - HTML_PARSE + allowlist SANITIZE -> BUILDER (the keystone XSS control; then sanitize composes)\n" as *u8)
102 ba_puts(">>> NOTE: the secure-token I hand-authored was COMPOSABLE (urandom+hex) -- the team could have. Lesson logged.\n" as *u8)
103 sys_exit(0); return 0
104}