code wiki / _hdl_build / nx_goalmap_gate.nx

nx_goalmap_gate.nx source

↩ module page · 204 lines · 13760 B

1// nx_goalmap_gate.nx -- proves nx_goalmap_lib IN-PROCESS on fixture boards under /tmp/nx_goalmap_gate/ 2// (a fixture tree assembled at SETUP, never shared with a production beat; every path this gate authors is 3// rewritten wholesale each run). Teeth: match by title word, by symbol word, non-match excluded, score counts 4// DISTINCT words, dependency order (dependency before dependent), status OPEN from an _ABSENT_ watch and PRESENT 5// from a present symbol, PRESENT-REJECTED from a planted operator REJECT on the accept- plane, ledger count and 6// last epoch, gap rows with SOURCE probed 1 / BUILT 0 / PROMOTED 0, the scale bound (300 rungs -> out <= budget, 7// clipped announced, count still full), and three neg-controls: no-word-matches returns EMPTY not a guess, 8// a duplicate rung id is REFUSED by name, an unreadable domain returns NO-DOMAIN. Values emitted via gv_kv. 9// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 10// PROVENANCE 2026-09-05 rebuild-1: the first fossil (sha dc586dcb, 166,087 B) was DELETED by an admission-REFUSED run 11// of nx_sov_build_run while its build-cache sidecar survived (key 3dac65ef); this line moves the cache key so the 12// rebuild compiles instead of reporting a HIT that materialises nothing (CLAUDE.md 2026-09-04, debt 1787078015 recurrence). 13import "nx_syscalls.nx" 14import "nx_sovjson_lib.nx" 15import "nx_store_seed_lib.nx" 16import "nx_gate_verdict.nx" 17import "nx_goalmap_lib.nx" 18 19const GG_BASE: *u8 = "/tmp/nx_goalmap_gate/" 20const GG_MODE_DIR: i64 = 0x1ed 21const GG_MODE_FILE: i64 = 420 22// GG_OUT retired 2026-09-05: the out buffer is gm_outbuf(csv), sized by the lib for the largest csv this gate runs 23const GG_BIG: i64 = 262144 24const GG_NL: i64 = 10 25const GG_TAB: i64 = 9 26const GG_SCALE_N: i64 = 300 27const GG_WORDS: i64 = 64 28 29func gg_wr(path: *u8, buf: *u8, n: i64) -> i64 { 30 let fd: i64 = sys_openat_wr(path, GG_MODE_FILE) 31 if fd < 0 { return 0 - 1 } 32 sys_write(fd, buf, n) 33 sys_close(fd) 34 return n 35} 36 37func gg_row(b: *u8, o: i64, s: *u8) -> i64 { var p: i64 = sj_cat(b, o, s); b[p] = GG_NL as u8; return p + 1 } 38func gg_tab(b: *u8, o: i64) -> i64 { b[o] = GG_TAB as u8; return o + 1 } 39 40func gg_has(out: *u8, n: i64, lit: *u8) -> i64 { if gm_find(out, 0, n, lit) >= 0 { return 1 } return 0 } 41 42// integer after a JSON key literal such as "\"rungs_matched\":"; -1 when absent 43func gg_int(out: *u8, n: i64, key: *u8) -> i64 { 44 let p: i64 = gm_find(out, 0, n, key) 45 if p < 0 { return 0 - 1 } 46 let s: i64 = p + sj_vlen(key) 47 var e: i64 = s 48 var go: i64 = 1 49 while go == 1 { if e >= n { go = 0 } else { let c: i64 = out[e] as i64; if c >= 48 { if c <= 57 { e = e + 1 } else { go = 0 } } else { go = 0 } } } 50 return sj_atoi_span(out, s, e) 51} 52 53func gg_setup() -> i64 { 54 sys_mkdir("/tmp/nx_goalmap_gate" as *u8, GG_MODE_DIR) 55 sys_mkdir("/tmp/nx_goalmap_gate/buildroot" as *u8, GG_MODE_DIR) 56 sys_mkdir("/tmp/nx_goalmap_gate/buildroot/knowledge" as *u8, GG_MODE_DIR) 57 sys_mkdir("/tmp/nx_goalmap_gate/buildroot/knowledge/compare" as *u8, GG_MODE_DIR) 58 sys_mkdir("/tmp/nx_goalmap_gate/buildroot/runtime" as *u8, GG_MODE_DIR) 59 sys_mkdir("/tmp/nx_goalmap_gate/buildroot/_build" as *u8, GG_MODE_DIR) 60 sys_mkdir("/tmp/nx_goalmap_gate/knowledge" as *u8, GG_MODE_DIR) 61 sys_mkdir("/tmp/nx_goalmap_gate/knowledge/store" as *u8, GG_MODE_DIR) 62 let b: *u8 = sys_mmap(GG_BIG) 63 var o: i64 = 0 64 // plan gx 65 o = gg_row(b, o, "# fixture plan gx" as *u8) 66 o = gg_row(b, o, "rung|G1|Cast on the WebGPU door|rk_full_scene_door|done when the cast draws through the door|Organ|2|G2" as *u8) 67 o = gg_row(b, o, "rung|G2|WebGPU submission pipe|rk_webgpu_door|the world drawn through one door|Organ|1|-" as *u8) 68 o = gg_row(b, o, "rung|G3|Vegetation reads as vegetation|wc_veg_mesh|palms as instanced geometry|Organ|3|-" as *u8) 69 o = gg_row(b, o, "rung|G4|Gait locomotion|mob_step_gait|feet planted on sand|Organ|1|-" as *u8) 70 o = gg_row(b, o, "rung|G5|Ground truth reproducible from a seed|_ABSENT_:ws_gt|the runtime is the generator|Organ|2|-" as *u8) 71 o = gg_row(b, o, "log|1700000000|G1|queue|first" as *u8) 72 o = gg_row(b, o, "log|1700000100|G1|measure|second" as *u8) 73 gg_wr("/tmp/nx_goalmap_gate/buildroot/knowledge/compare/gx.plan" as *u8, b, o) 74 // matrix gx 75 o = 0 76 o = gg_row(b, o, "Cast door|runtime/nx_game_page_emit.nx|_ABSENT_:rk_full_scene_door|0|0|0|0|0|watch" as *u8) 77 o = gg_row(b, o, "World door|runtime/nx_game_page_emit.nx|rk_webgpu_door|1|0|0|0|0|present" as *u8) 78 o = gg_row(b, o, "Gait|runtime/nx_wasm_craft.nx|mob_step_gait|1|0|0|0|0|present" as *u8) 79 o = gg_row(b, o, "Ground truth|runtime/nx_worldgen.nx|_ABSENT_:ws_gt|0|0|0|0|0|watch" as *u8) 80 gg_wr("/tmp/nx_goalmap_gate/buildroot/knowledge/compare/gx.matrix" as *u8, b, o) 81 // a fixture SOURCE so the gap probe reads src=1 for one path and 0 for the other 82 o = 0 83 o = gg_row(b, o, "// fixture source" as *u8) 84 gg_wr("/tmp/nx_goalmap_gate/buildroot/runtime/nx_game_page_emit.nx" as *u8, b, o) 85 // plan gd: duplicate id 86 o = 0 87 o = gg_row(b, o, "rung|D1|First webgpu|sym_a|done|Organ|1|-" as *u8) 88 o = gg_row(b, o, "rung|D1|Second webgpu|sym_b|done|Organ|1|-" as *u8) 89 gg_wr("/tmp/nx_goalmap_gate/buildroot/knowledge/compare/gd.plan" as *u8, b, o) 90 // plan gs: scale 91 o = 0 92 var i: i64 = 0 93 while i < GG_SCALE_N { 94 o = sj_cat(b, o, "rung|S" as *u8); o = sj_catn(b, o, i) 95 o = sj_cat(b, o, "|scale rung webgpu|sym" as *u8); o = sj_catn(b, o, i) 96 o = sj_cat(b, o, "|done|Organ|1|-" as *u8) 97 b[o] = GG_NL as u8; o = o + 1 98 i = i + 1 99 } 100 gg_wr("/tmp/nx_goalmap_gate/buildroot/knowledge/compare/gs.plan" as *u8, b, o) 101 // accept plane: one planted operator REJECT naming gx:mob_step_gait 102 o = 0 103 o = sj_cat(b, o, "beach-feet" as *u8); o = gg_tab(b, o) 104 o = sj_cat(b, o, "world feet" as *u8); o = gg_tab(b, o) 105 o = sj_cat(b, o, "REJECT" as *u8); o = gg_tab(b, o) 106 o = sj_cat(b, o, "2026-08-30" as *u8); o = gg_tab(b, o) 107 o = sj_cat(b, o, "operator" as *u8); o = gg_tab(b, o) 108 o = sj_cat(b, o, "poorly done" as *u8); o = gg_tab(b, o) 109 o = sj_cat(b, o, "ga_accept_locomotion,gx:mob_step_gait" as *u8) 110 b[o] = GG_NL as u8; o = o + 1 111 sts_seed("/tmp/nx_goalmap_gate/knowledge/store/accept-" as *u8, b, o) 112 return 0 113} 114 115func main(argc: i64, argv: *i64) -> i64 { 116 let ctr: *i64 = gv_ctr() 117 gv_head("nx_goalmap_gate -- the goal mapper maps words onto rungs, statuses, ledgers, gaps and an order from DATA" as *u8) 118 gg_setup() 119 // v1.2: the output buffer is what the lib declares for the LARGEST csv this gate runs (four scale boards) -- never a guess 120 let out: *u8 = sys_mmap(gm_outbuf("gs,gs,gs,gs" as *u8)) 121 let w: *i64 = sys_mmap(GG_WORDS) as *i64 122 // A: webgpu cast 123 w[0] = ("webgpu" as *u8) as i64 124 w[1] = ("cast" as *u8) as i64 125 let na: i64 = gm_run(GG_BASE, "gx" as *u8, w, 2, out) 126 let ma: i64 = gg_int(out, na, "\"rungs_matched\":" as *u8) 127 gv_check_eq("T1 two rungs carry webgpu or cast (G1, G2); G3 and G4 do not" as *u8, ma, 2, ctr) 128 gv_check("T2 G1 scores 2 distinct words and G2 scores 1" as *u8, gg_has(out, na, "\"id\":\"G1\",\"score\":2" as *u8) * gg_has(out, na, "\"id\":\"G2\",\"score\":1" as *u8), ctr) 129 gv_check("T3 a rung carrying neither word is NOT emitted (G3)" as *u8, 1 - gg_has(out, na, "\"id\":\"G3\"" as *u8), ctr) 130 gv_check("T5 dependency order puts G2 (the dependency) before G1" as *u8, gg_has(out, na, "\"order\":[\"G2\",\"G1\"]" as *u8), ctr) 131 gv_check("T6 status: an _ABSENT_ watch reads OPEN, a present matrix symbol reads PRESENT" as *u8, gg_has(out, na, "\"id\":\"G1\",\"score\":2,\"status\":\"OPEN\"" as *u8) * gg_has(out, na, "\"id\":\"G2\",\"score\":1,\"status\":\"PRESENT\"" as *u8), ctr) 132 gv_check("T7 the ledger is counted per rung with its last epoch (G1: 2 rows, 1700000100)" as *u8, gg_has(out, na, "\"log_rows\":2,\"last_epoch\":1700000100" as *u8), ctr) 133 gv_check("T8 a matching watch row is a gap with SOURCE probed 1 and BUILT 0 PROMOTED 0" as *u8, gg_has(out, na, "\"label\":\"Cast door\"" as *u8) * gg_has(out, na, "\"src\":1,\"built\":0,\"promoted\":0" as *u8), ctr) 134 gv_check("T8b the plan was read whole and declared so (truncated 0, readable 1)" as *u8, gg_has(out, na, "\"readable\":1,\"truncated\":0" as *u8), ctr) 135 // A2: distinct words -- the same word twice does not double the score 136 w[0] = ("webgpu" as *u8) as i64 137 w[1] = ("webgpu" as *u8) as i64 138 w[2] = ("cast" as *u8) as i64 139 let na2: i64 = gm_run(GG_BASE, "gx" as *u8, w, 3, out) 140 gv_check("T4 score counts DISTINCT words: webgpu twice plus cast still scores G1 at 2" as *u8, gg_has(out, na2, "\"id\":\"G1\",\"score\":2" as *u8), ctr) 141 // B: the operator REJECT flips the status 142 w[0] = ("gait" as *u8) as i64 143 let nb: i64 = gm_run(GG_BASE, "gx" as *u8, w, 1, out) 144 gv_check("T9 a planted operator REJECT naming gx:mob_step_gait reads PRESENT-REJECTED and the verdict row is listed" as *u8, gg_has(out, nb, "\"status\":\"PRESENT-REJECTED\"" as *u8) * gg_has(out, nb, "\"id\":\"beach-feet\",\"verdict\":\"REJECT\"" as *u8), ctr) 145 // C: neg-control -- no word matches -> empty, never a guess 146 w[0] = ("zzqqxx" as *u8) as i64 147 let nc: i64 = gm_run(GG_BASE, "gx" as *u8, w, 1, out) 148 var t10: i64 = 0 149 if nc > 0 { if gg_int(out, nc, "\"rungs_matched\":" as *u8) == 0 { if gg_has(out, nc, "\"order\":[]" as *u8) == 1 { t10 = 1 } } } 150 gv_check("neg-control-no-word-matches-returns-EMPTY-not-a-guess" as *u8, t10, ctr) 151 // D: neg-control -- duplicate rung id refused by name 152 w[0] = ("webgpu" as *u8) as i64 153 let nd: i64 = gm_run(GG_BASE, "gd" as *u8, w, 1, out) 154 var t11: i64 = 0 155 if nd == 0 - 4 { if gg_has(out, sj_vlen(out), "duplicate-rung-id" as *u8) == 1 { if gg_has(out, sj_vlen(out), "\"id\":\"D1\"" as *u8) == 1 { t11 = 1 } } } 156 gv_check("neg-control-duplicate-rung-id-REFUSED-by-name-with-the-id" as *u8, t11, ctr) 157 // E: scale -- 300 matching rungs stay inside the budget, clipped is ANNOUNCED, the count stays full 158 let ne: i64 = gm_run(GG_BASE, "gs" as *u8, w, 1, out) 159 var t12: i64 = 0 160 if ne > 0 { if ne <= GM_OUTCAP { if gg_int(out, ne, "\"clipped\":" as *u8) == 1 { t12 = 1 } } } 161 gv_check("T12 300 matching rungs -> out_bytes within budget and clipped=1 announced" as *u8, t12, ctr) 162 gv_check_eq("T12b the matched COUNT is the population, not the emitted prefix" as *u8, gg_int(out, ne, "\"rungs_matched\":" as *u8), GG_SCALE_N, ctr) 163 // F: neg-control -- unreadable domain 164 let nf: i64 = gm_run(GG_BASE, "nope" as *u8, w, 1, out) 165 gv_check_eq("neg-control-unreadable-domain-returns-NO-DOMAIN(-3)" as *u8, nf, 0 - 3, ctr) 166 // G: a csv with one readable and one unreadable domain still answers, declaring domains_readable=1 167 let ng: i64 = gm_run(GG_BASE, "gx,nope" as *u8, w, 1, out) 168 var t14: i64 = 0 169 if ng > 0 { if gg_int(out, ng, "\"domains_readable\":" as *u8) == 1 { if gg_has(out, ng, "\"dom\":\"nope\",\"plan_bytes\":0,\"plan_read\":-1,\"readable\":0" as *u8) == 1 { t14 = 1 } } } 170 gv_check("T14 a mixed csv answers for the readable domain and names the unreadable one" as *u8, t14, ctr) 171 // H: v1.1 -- a rung whose symbol column carries the _ABSENT_: prefix joins its matrix watch by the CORE symbol 172 w[0] = ("reproducible" as *u8) as i64 173 let nh: i64 = gm_run(GG_BASE, "gx" as *u8, w, 1, out) 174 gv_check("T15 a rung symbol written with the _ABSENT_: prefix reads OPEN against its watch and is emitted as the core symbol" as *u8, gg_has(out, nh, "\"id\":\"G5\",\"score\":1,\"status\":\"OPEN\",\"symbol\":\"ws_gt\"" as *u8), ctr) 175 // I: v1.2 -- the overflow class that crashed the promoted binary (debt 1788626163): four copies of the scale board, 176 // every rung matching, so the row budget is spent inside the first domain and three more domains still emit their 177 // scaffolding. The digest must stay inside gm_outbuf(csv), close its JSON and announce the clip. 178 w[0] = ("webgpu" as *u8) as i64 179 let csv4: *u8 = "gs,gs,gs,gs" as *u8 180 let ni: i64 = gm_run(GG_BASE, csv4, w, 1, out) 181 var t17: i64 = 0 182 if ni > GM_OUTCAP { if ni <= gm_outbuf(csv4) { if gg_int(out, ni, "\"clipped\":" as *u8) == 1 { if out[ni - 2] == (125 as u8) { t17 = 1 } } } } 183 gv_check("T16 fixture-reached-the-condition: four clipped domains push out_bytes PAST the row budget" as *u8, (ni > GM_OUTCAP) as i64, ctr) 184 gv_check("T17 and the digest stays at or under gm_outbuf(csv), closes its JSON and announces clipped=1" as *u8, t17, ctr) 185 gv_check_eq("T18 gm_ndom counts non-empty comma tokens (an empty token and a trailing comma are not domains)" as *u8, gm_ndom("gx,,gs," as *u8), 2, ctr) 186 // J: the ONE declared reserve is MEASURED, never trusted: a zero-match domain's scaffolding from a real emit 187 w[0] = ("zzqqxx" as *u8) as i64 188 let n1: i64 = gm_run(GG_BASE, "gx" as *u8, w, 1, out) 189 let n2: i64 = gm_run(GG_BASE, "gx,gx" as *u8, w, 1, out) 190 let scaffold: i64 = n2 - n1 191 gv_check("T19 one domain's scaffolding, measured on a real emit, fits inside GM_DOM_RESERVE" as *u8, ((scaffold > 0) as i64) * ((scaffold < GM_DOM_RESERVE) as i64), ctr) 192 gv_values_head() 193 gv_kv("scaffold_bytes_measured" as *u8, scaffold) 194 gv_kv("scaffold_reserve" as *u8, GM_DOM_RESERVE) 195 gv_kv("out_bytes_four_domains" as *u8, ni) 196 gv_kv("outbuf_four_domains" as *u8, gm_outbuf(csv4)) 197 gv_kv("rungs_matched_a" as *u8, ma) 198 gv_kv("out_bytes_a" as *u8, na) 199 gv_kv("out_bytes_scale" as *u8, ne) 200 gv_kv("budget_bytes" as *u8, GM_OUTCAP) 201 let rc: i64 = gv_verdict("NX-GOALMAP-GATE" as *u8, ctr, "the goal mapper is proven on fixture boards in-process" as *u8) 202 sys_exit(rc) 203 return rc 204}