code wiki / _hdl_build / nx_vizsla_gate.nx
nx_vizsla_gate.nx source
↩ module page · 271 lines · 13256 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"
18
19func vg_slen(s: *u8) -> i64 {
20 var n: i64 = 0
21 while s[n] != (0 as u8) { n = n + 1 }
22 return n
23}
24
25func vg_p(s: *u8) -> i64 {
26 sys_write(1, s, vg_slen(s))
27 return 0
28}
29
30func vg_pn(v: i64) -> i64 {
31 let bb: *u8 = sys_mmap(28)
32 var m: i64 = v
33 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
34 let t: *u8 = sys_mmap(28)
35 var k: i64 = 0
36 if m == 0 { t[0] = 48 as u8; k = 1 }
37 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
38 var i: i64 = 0
39 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 }
40 sys_write(1, bb, k)
41 return 0
42}
43
44func vg_write(path: *u8, content: *u8) -> i64 {
45 let fd: i64 = sys_openat_wr(path, 0x1a4)
46 if fd < 0 { return 0 - 1 }
47 sys_write(fd, content, vg_slen(content))
48 sys_close(fd)
49 return 0
50}
51
52func vg_readall(path: *u8, szout: *i64) -> *u8 {
53 let fd: i64 = sys_openat_rd(path)
54 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 }
55 let sz: i64 = sys_lseek(fd, 0, 2)
56 sys_lseek(fd, 0, 0)
57 let buf: *u8 = sys_mmap(sz + 64)
58 var got: i64 = 0
59 var n: i64 = 1
60 while n > 0 {
61 n = sys_read(fd, (buf as i64 + got) as *u8, 65536)
62 if n > 0 { got = got + n }
63 }
64 sys_close(fd)
65 szout[0] = got
66 return buf
67}
68
69// run elf with up to 3 args, stdout -> outpath; returns WEXITSTATUS or 128+sig
70func vg_run(elf: *u8, a1: *u8, a2: *u8, a3: *u8, outpath: *u8) -> i64 {
71 let pid: i64 = sys_fork()
72 if pid == 0 {
73 if (outpath as i64) != 0 {
74 let ofd: i64 = sys_openat_wr(outpath, 0x1a4)
75 if ofd >= 0 { sys_dup3(ofd, 1, 0) }
76 }
77 let argv: *i64 = sys_mmap(64) as *i64
78 argv[0] = elf as i64
79 var i: i64 = 1
80 if (a1 as i64) != 0 { argv[i] = a1 as i64; i = i + 1 }
81 if (a2 as i64) != 0 { argv[i] = a2 as i64; i = i + 1 }
82 if (a3 as i64) != 0 { argv[i] = a3 as i64; i = i + 1 }
83 argv[i] = 0
84 let envp: *i64 = sys_mmap(16) as *i64
85 envp[0] = 0
86 sys_execve(elf, argv, envp)
87 sys_exit(127)
88 }
89 let st: *i64 = sys_mmap(16) as *i64
90 sys_wait4(pid, st, 0)
91 let sig: i64 = st[0] & 0x7f
92 if sig != 0 { return 128 + sig }
93 return (st[0] >> 8) & 0xff
94}
95
96func vg_has(path: *u8, needle: *u8) -> i64 {
97 let szp: *i64 = sys_mmap(16) as *i64
98 let b: *u8 = vg_readall(path, szp)
99 let sz: i64 = szp[0]
100 let n: i64 = vg_slen(needle)
101 if sz < n { return 0 }
102 var i: i64 = 0
103 while i + n <= sz {
104 var ok: i64 = 1
105 var j: i64 = 0
106 while j < n {
107 if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 }
108 }
109 if ok == 1 { return 1 }
110 i = i + 1
111 }
112 return 0
113}
114
115func vg_fileeq(p1: *u8, p2: *u8) -> i64 {
116 let s1: *i64 = sys_mmap(16) as *i64
117 let s2: *i64 = sys_mmap(16) as *i64
118 let b1: *u8 = vg_readall(p1, s1)
119 let b2: *u8 = vg_readall(p2, s2)
120 if s1[0] != s2[0] { return 0 }
121 if s1[0] <= 0 { return 0 }
122 var i: i64 = 0
123 while i < s1[0] {
124 if b1[i] != b2[i] { return 0 }
125 i = i + 1
126 }
127 return 1
128}
129
130func vg_row(name: *u8, pass: i64) -> i64 {
131 vg_p("ROW " as *u8)
132 vg_p(name)
133 if pass == 1 { vg_p(" PASS\n" as *u8) } else { vg_p(" FAIL\n" as *u8) }
134 return pass
135}
136
137func main(argc: i64, argv: *i64) -> i64 {
138 vg_p("=== VIZSLA GATE: archetype gap profiler KATs (construction-known fixtures) ===\n" as *u8)
139 var prof: *u8 = "/tmp/nx_vizsla_profile.sov.elf" as *u8
140 if argc > 1 { prof = argv[1] as *u8 }
141 // self-heal: rebuild the instrument via the durable runner if /tmp was wiped
142 let pr: i64 = sys_openat_rd(prof)
143 if pr >= 0 { sys_close(pr) }
144 else {
145 vg_p(" instrument missing -> rebuilding via durable runner\n" as *u8)
146 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)
147 }
148
149 // fixture matrix: 3 archetypes x 5 traits @200, thr 500, 2 domains, 6 needs
150 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
151 vg_write("/tmp/vz_fix_matrix.txt" as *u8, fixm)
152
153 // 4-archetype matrix = fixm + steward rows (DATA edit only, same binary)
154 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
155 vg_write("/tmp/vz_fix_matrix4.txt" as *u8, fixm4)
156
157 // full coverage: one pure member per archetype
158 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
159 vg_write("/tmp/vz_fix_hfull.txt" as *u8, hfull)
160
161 // the operator's marriage KAT: ada=author(1000)+architect(200);
162 // bea=editor(1000)+architect(400) => gap=architect nearest=bea 400
163 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
164 vg_write("/tmp/vz_fix_hcouple.txt" as *u8, hcouple)
165
166 // solo author => architect + editor both gapped
167 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
168 vg_write("/tmp/vz_fix_hsolo.txt" as *u8, hsolo)
169
170 let fm: *u8 = "/tmp/vz_fix_matrix.txt" as *u8
171 let fm4: *u8 = "/tmp/vz_fix_matrix4.txt" as *u8
172 let flog: *u8 = "/tmp/vz_fix.log" as *u8
173 var pass: i64 = 0
174
175 // row 1: loud-fail on missing matrix
176 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)
177 var r: i64 = 0
178 if rc1 == 1 { r = 1 }
179 pass = pass + vg_row("loud-fail-missing-matrix" as *u8, r)
180
181 // row 2: full coverage => gaps=0
182 let rc2: i64 = vg_run(prof, fm, "/tmp/vz_fix_hfull.txt" as *u8, flog, "/tmp/vz_out2.txt" as *u8)
183 r = 0
184 if rc2 == 0 {
185 if vg_has("/tmp/vz_out2.txt" as *u8, "VIZSLA-COVERAGE archetypes=3 covered=3 gaps=0" as *u8) == 1 { r = 1 }
186 }
187 pass = pass + vg_row("full-coverage-no-gap" as *u8, r)
188
189 // row 3: marriage KAT => architect gap, nearest=bea 400
190 let rc3: i64 = vg_run(prof, fm, "/tmp/vz_fix_hcouple.txt" as *u8, flog, "/tmp/vz_out3.txt" as *u8)
191 r = 0
192 if rc3 == 0 {
193 if vg_has("/tmp/vz_out3.txt" as *u8, "VIZSLA-GAP archetype=architect nearest=bea nearest_permil=400" as *u8) == 1 { r = 1 }
194 }
195 pass = pass + vg_row("marriage-kat-architect-gap" as *u8, r)
196
197 // row 4: fill plan row names capability + partner
198 r = vg_has("/tmp/vz_out3.txt" as *u8, "VIZSLA-FILL domain=finance gap=architect capability=financial-plan-builder partner=bea" as *u8)
199 pass = pass + vg_row("fill-row-capability-partner" as *u8, r)
200
201 // row 5: solo author => 2 gaps
202 let rc5: i64 = vg_run(prof, fm, "/tmp/vz_fix_hsolo.txt" as *u8, flog, "/tmp/vz_out5.txt" as *u8)
203 r = 0
204 if rc5 == 0 {
205 if vg_has("/tmp/vz_out5.txt" as *u8, "VIZSLA-VERDICT coverage=GAPPED gaps=2" as *u8) == 1 { r = 1 }
206 }
207 pass = pass + vg_row("solo-author-two-gaps" as *u8, r)
208
209 // row 6: determinism -- same inputs again, byte-identical stdout
210 vg_run(prof, fm, "/tmp/vz_fix_hcouple.txt" as *u8, flog, "/tmp/vz_out6.txt" as *u8)
211 r = vg_fileeq("/tmp/vz_out3.txt" as *u8, "/tmp/vz_out6.txt" as *u8)
212 pass = pass + vg_row("determinism-byte-identical" as *u8, r)
213
214 // rows 7+8: DATA-DRIVEN -- steward archetype exists only in fixture DATA
215 let rc7: i64 = vg_run(prof, fm4, "/tmp/vz_fix_hsolo.txt" as *u8, flog, "/tmp/vz_out7.txt" as *u8)
216 r = 0
217 if rc7 == 0 {
218 if vg_has("/tmp/vz_out7.txt" as *u8, "VIZSLA-GAP archetype=steward" as *u8) == 1 { r = 1 }
219 }
220 pass = pass + vg_row("data-driven-new-archetype" as *u8, r)
221 r = 0
222 if rc7 == 0 {
223 if vg_has("/tmp/vz_out7.txt" as *u8, "VIZSLA-VERDICT coverage=GAPPED gaps=3" as *u8) == 1 { r = 1 }
224 }
225 pass = pass + vg_row("data-driven-gap-count" as *u8, r)
226
227 let permil: i64 = (pass * 1000) / 8
228 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4)
229 var fdi: i64 = 0
230 while fdi < 2 {
231 var fd: i64 = 1
232 if fdi == 1 { fd = logfd }
233 if fd > 0 {
234 let line: *u8 = sys_mmap(256)
235 var o: i64 = 0
236 var i2: i64 = 0
237 let s1: *u8 = "VIZSLA-GATE epoch=" as *u8
238 while s1[i2] != (0 as u8) { line[o] = s1[i2]; o = o + 1; i2 = i2 + 1 }
239 var m: i64 = sys_now_realtime_sec()
240 let t: *u8 = sys_mmap(28)
241 var k: i64 = 0
242 if m == 0 { t[0] = 48 as u8; k = 1 }
243 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
244 var i3: i64 = 0
245 while i3 < k { line[o] = t[k - 1 - i3]; o = o + 1; i3 = i3 + 1 }
246 let s2: *u8 = " rows=8 pass=" as *u8
247 i2 = 0
248 while s2[i2] != (0 as u8) { line[o] = s2[i2]; o = o + 1; i2 = i2 + 1 }
249 line[o] = (48 + pass) as u8
250 o = o + 1
251 let s3: *u8 = " permil=" as *u8
252 i2 = 0
253 while s3[i2] != (0 as u8) { line[o] = s3[i2]; o = o + 1; i2 = i2 + 1 }
254 m = permil
255 k = 0
256 if m == 0 { t[0] = 48 as u8; k = 1 }
257 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
258 i3 = 0
259 while i3 < k { line[o] = t[k - 1 - i3]; o = o + 1; i3 = i3 + 1 }
260 var s4: *u8 = " verdict=RED\n" as *u8
261 if pass == 8 { s4 = " verdict=GREEN\n" as *u8 }
262 i2 = 0
263 while s4[i2] != (0 as u8) { line[o] = s4[i2]; o = o + 1; i2 = i2 + 1 }
264 sys_write(fd, line, o)
265 }
266 fdi = fdi + 1
267 }
268 if logfd > 0 { sys_close(logfd) }
269 if pass == 8 { return 0 }
270 return 1
271}