code wiki / _hdl_build / nx_vizsla_gate.nx

nx_vizsla_gate.nx source

↩ module page · 282 lines · 14108 B

1// nx_vizsla_gate.nx -- VIZSLA V0 gate: the archetype gap profiler is itself 2// gate-proven (construction-known KAT fixtures in /tmp, hand-computed expected 3// rows; fixture log isolated via the profiler's argv overrides -- site-gate 4// pattern, fixtures never pollute the real vizsla_profile.log). 5// Rows (oracle = hand-computed coverage/gap algebra): 6// 1 loud-fail missing matrix => exit 1 7// 2 full-coverage architect+author+editor household => covered=3 gaps=0, exit 0 8// 3 marriage KAT author+editor couple => gap=architect, nearest=bea permil=400 9// 4 fill row finance fill = financial-plan-builder, partner=bea 10// 5 single member one author alone => gaps=2 11// 6 determinism same inputs twice => byte-identical stdout 12// 7 DATA-DRIVEN 4th archetype (steward) added to the FIXTURE MATRIX ONLY 13// => participates as a gap with NO recompile (model is data) 14// 8 data-driven count 4-arch matrix + solo author => gaps=3 15// Evidence: VIZSLA-GATE line -> stdout + knowledge/status/vizsla_gate.log; exit 0 iff 8/8. 16// spec: knowledge/specs/2026-06-10-nishi-vizsla-ladder.md license_tier: ORIGINAL 17import "nx_syscalls.nx" 18import "nx_gate_verdict.nx" 19 20func vg_slen(s: *u8) -> i64 { 21 var n: i64 = 0 22 while s[n] != (0 as u8) { n = n + 1 } 23 return n 24} 25 26func vg_p(s: *u8) -> i64 { 27 sys_write(1, s, vg_slen(s)) 28 return 0 29} 30 31func vg_pn(v: i64) -> i64 { 32 let bb: *u8 = sys_mmap(28) 33 var m: i64 = v 34 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 35 let t: *u8 = sys_mmap(28) 36 var k: i64 = 0 37 if m == 0 { t[0] = 48 as u8; k = 1 } 38 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 39 var i: i64 = 0 40 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 41 sys_write(1, bb, k) 42 return 0 43} 44 45func vg_write(path: *u8, content: *u8) -> i64 { 46 let fd: i64 = sys_openat_wr(path, 0x1a4) 47 if fd < 0 { return 0 - 1 } 48 sys_write(fd, content, vg_slen(content)) 49 sys_close(fd) 50 return 0 51} 52 53func vg_readall(path: *u8, szout: *i64) -> *u8 { 54 let fd: i64 = sys_openat_rd(path) 55 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 56 let sz: i64 = sys_lseek(fd, 0, 2) 57 sys_lseek(fd, 0, 0) 58 let buf: *u8 = sys_mmap(sz + 64) 59 var got: i64 = 0 60 var n: i64 = 1 61 while n > 0 { 62 n = sys_read(fd, (buf as i64 + got) as *u8, 65536) 63 if n > 0 { got = got + n } 64 } 65 sys_close(fd) 66 szout[0] = got 67 return buf 68} 69 70// run elf with up to 3 args, stdout -> outpath; returns WEXITSTATUS or 128+sig 71func vg_run(elf: *u8, a1: *u8, a2: *u8, a3: *u8, outpath: *u8) -> i64 { 72 let pid: i64 = sys_fork() 73 if pid == 0 { 74 if (outpath as i64) != 0 { 75 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 76 if ofd >= 0 { sys_dup3(ofd, 1, 0) } 77 } 78 let argv: *i64 = sys_mmap(64) as *i64 79 argv[0] = elf as i64 80 var i: i64 = 1 81 if (a1 as i64) != 0 { argv[i] = a1 as i64; i = i + 1 } 82 if (a2 as i64) != 0 { argv[i] = a2 as i64; i = i + 1 } 83 if (a3 as i64) != 0 { argv[i] = a3 as i64; i = i + 1 } 84 argv[i] = 0 85 let envp: *i64 = sys_mmap(16) as *i64 86 envp[0] = 0 87 sys_execve(elf, argv, envp) 88 sys_exit(127) 89 } 90 let st: *i64 = sys_mmap(16) as *i64 91 sys_wait4(pid, st, 0) 92 let sig: i64 = st[0] & 0x7f 93 if sig != 0 { return 128 + sig } 94 return (st[0] >> 8) & 0xff 95} 96 97func vg_has(path: *u8, needle: *u8) -> i64 { 98 let szp: *i64 = sys_mmap(16) as *i64 99 let b: *u8 = vg_readall(path, szp) 100 let sz: i64 = szp[0] 101 let n: i64 = vg_slen(needle) 102 if sz < n { return 0 } 103 var i: i64 = 0 104 while i + n <= sz { 105 var ok: i64 = 1 106 var j: i64 = 0 107 while j < n { 108 if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } 109 } 110 if ok == 1 { return 1 } 111 i = i + 1 112 } 113 return 0 114} 115 116func vg_fileeq(p1: *u8, p2: *u8) -> i64 { 117 let s1: *i64 = sys_mmap(16) as *i64 118 let s2: *i64 = sys_mmap(16) as *i64 119 let b1: *u8 = vg_readall(p1, s1) 120 let b2: *u8 = vg_readall(p2, s2) 121 if s1[0] != s2[0] { return 0 } 122 if s1[0] <= 0 { return 0 } 123 var i: i64 = 0 124 while i < s1[0] { 125 if b1[i] != b2[i] { return 0 } 126 i = i + 1 127 } 128 return 1 129} 130 131func vg_row(name: *u8, pass: i64) -> i64 { 132 vg_p("ROW " as *u8) 133 vg_p(name) 134 if pass == 1 { vg_p(" PASS\n" as *u8) } else { vg_p(" FAIL\n" as *u8) } 135 return pass 136} 137 138func main(argc: i64, argv: *i64) -> i64 { 139 vg_p("=== VIZSLA GATE: archetype gap profiler KATs (construction-known fixtures) ===\n" as *u8) 140 var prof: *u8 = "buildroot/_build/nx_vizsla_profile.sov.elf" as *u8 141 if argc > 1 { prof = argv[1] as *u8 } 142 // self-heal: rebuild the instrument via the durable runner if _build/ was wiped. 143 // NOT /tmp: nx_sov_build_run writes <t>.sov.elf into _build/ (moved there 2026-07-30 by the flock 144 // change). ⚠It ANCHORS ITS OWN CWD to buildroot/ ("started in the serving root"), so parent and 145 // child do NOT share a CWD -- from this gate the artifact is buildroot/_build/, not _build/. 146 let pr: i64 = sys_openat_rd(prof) 147 if pr >= 0 { sys_close(pr) } 148 else { 149 vg_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 150 vg_run("_offc/nx_sov_build_run.elf" as *u8, "nx_vizsla_profile" as *u8, 0 as *u8, 0 as *u8, "/tmp/vz_rebuild.out" as *u8) 151 } 152 153 // fixture matrix: 3 archetypes x 5 traits @200, thr 500, 2 domains, 6 needs 154 let fixm: *u8 = "CONF threshold_permil 500\nARCH architect\nARCH author\nARCH editor\nTRAIT architect 200 plans_long_term\nTRAIT architect 200 designs_systems\nTRAIT architect 200 models_tradeoffs\nTRAIT architect 200 sets_budgets\nTRAIT architect 200 structures_decisions\nTRAIT author 200 starts_projects\nTRAIT author 200 generates_ideas\nTRAIT author 200 creates_content\nTRAIT author 200 initiates_contact\nTRAIT author 200 drives_change\nTRAIT editor 200 finishes_projects\nTRAIT editor 200 tracks_details\nTRAIT editor 200 maintains_schedules\nTRAIT editor 200 corrects_errors\nTRAIT editor 200 closes_loops\nDOMAIN finance\nDOMAIN career\nNEED finance architect financial-plan-builder\nNEED finance author income-pipeline-scout\nNEED finance editor ledger-reconciler\nNEED career architect career-path-mapper\nNEED career author job-search-engine\nNEED career editor application-tracker\n" as *u8 155 vg_write("/tmp/vz_fix_matrix.txt" as *u8, fixm) 156 157 // 4-archetype matrix = fixm + steward rows (DATA edit only, same binary) 158 let fixm4: *u8 = "CONF threshold_permil 500\nARCH architect\nARCH author\nARCH editor\nARCH steward\nTRAIT architect 200 plans_long_term\nTRAIT architect 200 designs_systems\nTRAIT architect 200 models_tradeoffs\nTRAIT architect 200 sets_budgets\nTRAIT architect 200 structures_decisions\nTRAIT author 200 starts_projects\nTRAIT author 200 generates_ideas\nTRAIT author 200 creates_content\nTRAIT author 200 initiates_contact\nTRAIT author 200 drives_change\nTRAIT editor 200 finishes_projects\nTRAIT editor 200 tracks_details\nTRAIT editor 200 maintains_schedules\nTRAIT editor 200 corrects_errors\nTRAIT editor 200 closes_loops\nTRAIT steward 200 tends_resources\nDOMAIN finance\nDOMAIN career\nNEED finance architect financial-plan-builder\nNEED finance author income-pipeline-scout\nNEED finance editor ledger-reconciler\nNEED finance steward resource-steward\nNEED career architect career-path-mapper\nNEED career author job-search-engine\nNEED career editor application-tracker\n" as *u8 159 vg_write("/tmp/vz_fix_matrix4.txt" as *u8, fixm4) 160 161 // full coverage: one pure member per archetype 162 let hfull: *u8 = "MEMBER arch_1\nANS arch_1 plans_long_term 1\nANS arch_1 designs_systems 1\nANS arch_1 models_tradeoffs 1\nANS arch_1 sets_budgets 1\nANS arch_1 structures_decisions 1\nMEMBER auth_1\nANS auth_1 starts_projects 1\nANS auth_1 generates_ideas 1\nANS auth_1 creates_content 1\nANS auth_1 initiates_contact 1\nANS auth_1 drives_change 1\nMEMBER edit_1\nANS edit_1 finishes_projects 1\nANS edit_1 tracks_details 1\nANS edit_1 maintains_schedules 1\nANS edit_1 corrects_errors 1\nANS edit_1 closes_loops 1\n" as *u8 163 vg_write("/tmp/vz_fix_hfull.txt" as *u8, hfull) 164 165 // the operator's marriage KAT: ada=author(1000)+architect(200); 166 // bea=editor(1000)+architect(400) => gap=architect nearest=bea 400 167 let hcouple: *u8 = "MEMBER ada\nANS ada starts_projects 1\nANS ada generates_ideas 1\nANS ada creates_content 1\nANS ada initiates_contact 1\nANS ada drives_change 1\nANS ada plans_long_term 1\nMEMBER bea\nANS bea finishes_projects 1\nANS bea tracks_details 1\nANS bea maintains_schedules 1\nANS bea corrects_errors 1\nANS bea closes_loops 1\nANS bea models_tradeoffs 1\nANS bea sets_budgets 1\n" as *u8 168 vg_write("/tmp/vz_fix_hcouple.txt" as *u8, hcouple) 169 170 // solo author => architect + editor both gapped 171 let hsolo: *u8 = "MEMBER cal\nANS cal starts_projects 1\nANS cal generates_ideas 1\nANS cal creates_content 1\nANS cal initiates_contact 1\nANS cal drives_change 1\n" as *u8 172 vg_write("/tmp/vz_fix_hsolo.txt" as *u8, hsolo) 173 174 let fm: *u8 = "/tmp/vz_fix_matrix.txt" as *u8 175 let fm4: *u8 = "/tmp/vz_fix_matrix4.txt" as *u8 176 let flog: *u8 = "/tmp/vz_fix.log" as *u8 177 var pass: i64 = 0 178 179 // row 1: loud-fail on missing matrix 180 let rc1: i64 = vg_run(prof, "/tmp/vz_fix_matrix_NOPE.txt" as *u8, "/tmp/vz_fix_hfull.txt" as *u8, flog, "/tmp/vz_out1.txt" as *u8) 181 var r: i64 = 0 182 if rc1 == 1 { r = 1 } 183 pass = pass + vg_row("loud-fail-missing-matrix" as *u8, r) 184 185 // row 2: full coverage => gaps=0 186 let rc2: i64 = vg_run(prof, fm, "/tmp/vz_fix_hfull.txt" as *u8, flog, "/tmp/vz_out2.txt" as *u8) 187 r = 0 188 if rc2 == 0 { 189 if vg_has("/tmp/vz_out2.txt" as *u8, "VIZSLA-COVERAGE archetypes=3 covered=3 gaps=0" as *u8) == 1 { r = 1 } 190 } 191 pass = pass + vg_row("full-coverage-no-gap" as *u8, r) 192 193 // row 3: marriage KAT => architect gap, nearest=bea 400 194 let rc3: i64 = vg_run(prof, fm, "/tmp/vz_fix_hcouple.txt" as *u8, flog, "/tmp/vz_out3.txt" as *u8) 195 r = 0 196 if rc3 == 0 { 197 if vg_has("/tmp/vz_out3.txt" as *u8, "VIZSLA-GAP archetype=architect nearest=bea nearest_permil=400" as *u8) == 1 { r = 1 } 198 } 199 pass = pass + vg_row("marriage-kat-architect-gap" as *u8, r) 200 201 // row 4: fill plan row names capability + partner 202 r = vg_has("/tmp/vz_out3.txt" as *u8, "VIZSLA-FILL domain=finance gap=architect capability=financial-plan-builder partner=bea" as *u8) 203 pass = pass + vg_row("fill-row-capability-partner" as *u8, r) 204 205 // row 5: solo author => 2 gaps 206 let rc5: i64 = vg_run(prof, fm, "/tmp/vz_fix_hsolo.txt" as *u8, flog, "/tmp/vz_out5.txt" as *u8) 207 r = 0 208 if rc5 == 0 { 209 if vg_has("/tmp/vz_out5.txt" as *u8, "VIZSLA-VERDICT coverage=GAPPED gaps=2" as *u8) == 1 { r = 1 } 210 } 211 pass = pass + vg_row("solo-author-two-gaps" as *u8, r) 212 213 // row 6: determinism -- same inputs again, byte-identical stdout 214 vg_run(prof, fm, "/tmp/vz_fix_hcouple.txt" as *u8, flog, "/tmp/vz_out6.txt" as *u8) 215 r = vg_fileeq("/tmp/vz_out3.txt" as *u8, "/tmp/vz_out6.txt" as *u8) 216 pass = pass + vg_row("determinism-byte-identical" as *u8, r) 217 218 // rows 7+8: DATA-DRIVEN -- steward archetype exists only in fixture DATA 219 let rc7: i64 = vg_run(prof, fm4, "/tmp/vz_fix_hsolo.txt" as *u8, flog, "/tmp/vz_out7.txt" as *u8) 220 r = 0 221 if rc7 == 0 { 222 if vg_has("/tmp/vz_out7.txt" as *u8, "VIZSLA-GAP archetype=steward" as *u8) == 1 { r = 1 } 223 } 224 pass = pass + vg_row("data-driven-new-archetype" as *u8, r) 225 r = 0 226 if rc7 == 0 { 227 if vg_has("/tmp/vz_out7.txt" as *u8, "VIZSLA-VERDICT coverage=GAPPED gaps=3" as *u8) == 1 { r = 1 } 228 } 229 pass = pass + vg_row("data-driven-gap-count" as *u8, r) 230 231 let permil: i64 = (pass * 1000) / 8 232 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 233 var fdi: i64 = 0 234 while fdi < 2 { 235 var fd: i64 = 1 236 if fdi == 1 { fd = logfd } 237 if fd > 0 { 238 let line: *u8 = sys_mmap(256) 239 var o: i64 = 0 240 var i2: i64 = 0 241 let s1: *u8 = "VIZSLA-GATE epoch=" as *u8 242 while s1[i2] != (0 as u8) { line[o] = s1[i2]; o = o + 1; i2 = i2 + 1 } 243 var m: i64 = sys_now_realtime_sec() 244 let t: *u8 = sys_mmap(28) 245 var k: i64 = 0 246 if m == 0 { t[0] = 48 as u8; k = 1 } 247 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 248 var i3: i64 = 0 249 while i3 < k { line[o] = t[k - 1 - i3]; o = o + 1; i3 = i3 + 1 } 250 let s2: *u8 = " rows=8 pass=" as *u8 251 i2 = 0 252 while s2[i2] != (0 as u8) { line[o] = s2[i2]; o = o + 1; i2 = i2 + 1 } 253 line[o] = (48 + pass) as u8 254 o = o + 1 255 let s3: *u8 = " permil=" as *u8 256 i2 = 0 257 while s3[i2] != (0 as u8) { line[o] = s3[i2]; o = o + 1; i2 = i2 + 1 } 258 m = permil 259 k = 0 260 if m == 0 { t[0] = 48 as u8; k = 1 } 261 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 262 i3 = 0 263 while i3 < k { line[o] = t[k - 1 - i3]; o = o + 1; i3 = i3 + 1 } 264 var s4: *u8 = " verdict=RED\n" as *u8 265 if pass == 8 { s4 = " verdict=GREEN\n" as *u8 } 266 i2 = 0 267 while s4[i2] != (0 as u8) { line[o] = s4[i2]; o = o + 1; i2 = i2 + 1 } 268 sys_write(fd, line, o) 269 } 270 fdi = fdi + 1 271 } 272 if logfd > 0 { sys_close(logfd) } 273 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 274 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 275 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 276 let ctr__dry: *i64 = gv_ctr() 277 ctr__dry[0] = pass 278 ctr__dry[1] = 8 279 let rc__dry: i64 = gv_verdict("VIZSLA-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 280 sys_exit(rc__dry) 281 return rc__dry 282}