code wiki / _hdl_build / nx_vizsla_recruiter_gate.nx

nx_vizsla_recruiter_gate.nx source

↩ module page · 317 lines · 14257 B

1// nx_vizsla_recruiter_gate.nx -- VIZSLA V2c gate: the recruiter-channel engine 2// is gate-proven against a HAND-ROUTED fixture corpus and HAND-COUNTED day 3// arithmetic (the oracle is this header, not the module under test). 4// 5// channels: recruiter=700 referral=550 cold-apply=100; strong_permil=500; 6// stale_days=30; agents r1(jane: compilers systems nishilang), 7// r2(sam: sales marketing), f1(cousin-max: writing editing), 8// portal(cold-apply: *) 9// postings: j1[compilers rust writing] j2[nishilang compilers systems] 10// j3[sales travel] j4[editing writing remote] j5[travel logistics] 11// hand routing: 12// j1: r1 ov=1 (700) beats f1 ov=1 (550) -> recruiter/r1 700 STRONG 13// j2: r1 ov=3 -> recruiter/r1 700 STRONG 14// j3: r2 ov=1 -> recruiter/r2 700 STRONG 15// j4: no recruiter overlap; f1 ov=2 -> referral/f1 550 STRONG 16// j5: only portal wildcard -> cold-apply/portal 100 WEAK 17// => posts=5 strong=4 weak=1 unrouted=0 18// touches (seg-3001): r1@2026-06-01, r2@2026-04-20, r1@2026-05-28 19// warm today=2026-06-10: r1 last=2026-06-01 days=9 FRESH (LATEST date wins, 20// not last-stored: 05-28 is stored AFTER 06-01); r2 days=51 STALE; f1 COLD; 21// portal EXCLUDED (cold-apply 100 < strong 500 = not worth tending, by data) 22// => agents=3 fresh=1 stale=1 cold=1 23// DATA-DRIVEN: stale_days 30->60 in fixture data only => r2 days=51 FRESH, 24// verdict fresh=2 stale=0 cold=1, same binary. 25// 26// Rows: 27// 1 loud-fail-missing-channels route on absent file => exit 1 28// 2 route-recruiter-strong j2 recruiter/r1 strength=700 overlap=3 STRONG 29// 3 route-referral-fallback j4 referral/f1 strength=550 overlap=2 STRONG 30// 4 cold-apply-weak-named j5 cold-apply/portal 100 WEAK + verdict 5/4/1/0 31// 5 best-channel-wins j1 via recruiter r1, not referral f1 32// 6 route-determinism byte-identical twice 33// 7 touch-load new=3 committed seg-3001 34// 8 idempotent-retouch new=0 dup_instore=3 segment=none (law 10) 35// 9 latest-date-wins r1 last=2026-06-01 days=9 FRESH 36// 10 stale-reconnect r2 days=51 STALE action=reconnect 37// 11 cold-introduce-weak-excluded f1 COLD action=introduce AND no portal row 38// 12 DATA-DRIVEN-stale-threshold stale_days=60 file => r2 FRESH, no recompile 39// 13 warm-determinism byte-identical twice 40// Evidence: VIZSLA-RECRUIT-GATE line -> stdout + knowledge/status/vizsla_gate.log; 41// exit 0 iff 13/13. 42// spec: knowledge/specs/2026-06-10-nishi-vizsla-ladder.md license_tier: ORIGINAL 43import "nx_syscalls.nx" 44 45func rg_slen(s: *u8) -> i64 { 46 var n: i64 = 0 47 while s[n] != (0 as u8) { n = n + 1 } 48 return n 49} 50 51func rg_p(s: *u8) -> i64 { 52 sys_write(1, s, rg_slen(s)) 53 return 0 54} 55 56func rg_cat(dst: *u8, off: i64, s: *u8) -> i64 { 57 var i: i64 = 0 58 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 59 return off + i 60} 61 62func rg_catn(dst: *u8, off: i64, v: i64) -> i64 { 63 var o: i64 = off 64 var m: i64 = v 65 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 66 let t: *u8 = sys_mmap(28) 67 var k: i64 = 0 68 if m == 0 { t[0] = 48 as u8; k = 1 } 69 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 70 var i: i64 = 0 71 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 72 return o + k 73} 74 75func rg_write(path: *u8, content: *u8) -> i64 { 76 let fd: i64 = sys_openat_wr(path, 0x1a4) 77 if fd < 0 { return 0 - 1 } 78 sys_write(fd, content, rg_slen(content)) 79 sys_close(fd) 80 return 0 81} 82 83func rg_readall(path: *u8, szout: *i64) -> *u8 { 84 let fd: i64 = sys_openat_rd(path) 85 if fd < 0 { szout[0] = 0 - 1; return 0 as *u8 } 86 let sz: i64 = sys_lseek(fd, 0, 2) 87 sys_lseek(fd, 0, 0) 88 let buf: *u8 = sys_mmap(sz + 64) 89 var got: i64 = 0 90 var n: i64 = 1 91 while n > 0 { 92 n = sys_read(fd, (buf as i64 + got) as *u8, 65536) 93 if n > 0 { got = got + n } 94 } 95 sys_close(fd) 96 szout[0] = got 97 return buf 98} 99 100func rg_run(elf: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, outpath: *u8) -> i64 { 101 let pid: i64 = sys_fork() 102 if pid == 0 { 103 if (outpath as i64) != 0 { 104 let ofd: i64 = sys_openat_wr(outpath, 0x1a4) 105 if ofd >= 0 { sys_dup3(ofd, 1, 0); sys_dup3(ofd, 2, 0) } 106 } 107 let argv: *i64 = sys_mmap(64) as *i64 108 argv[0] = elf as i64 109 var i: i64 = 1 110 if (a1 as i64) != 0 { argv[i] = a1 as i64; i = i + 1 } 111 if (a2 as i64) != 0 { argv[i] = a2 as i64; i = i + 1 } 112 if (a3 as i64) != 0 { argv[i] = a3 as i64; i = i + 1 } 113 if (a4 as i64) != 0 { argv[i] = a4 as i64; i = i + 1 } 114 argv[i] = 0 115 let envp: *i64 = sys_mmap(16) as *i64 116 envp[0] = 0 117 sys_execve(elf, argv, envp) 118 sys_exit(127) 119 } 120 let st: *i64 = sys_mmap(16) as *i64 121 sys_wait4(pid, st, 0) 122 let sig: i64 = st[0] & 0x7f 123 if sig != 0 { return 128 + sig } 124 return (st[0] >> 8) & 0xff 125} 126 127func rg_has(path: *u8, needle: *u8) -> i64 { 128 let szp: *i64 = sys_mmap(16) as *i64 129 let b: *u8 = rg_readall(path, szp) 130 let sz: i64 = szp[0] 131 let n: i64 = rg_slen(needle) 132 if sz < n { return 0 } 133 var i: i64 = 0 134 while i + n <= sz { 135 var ok: i64 = 1 136 var j: i64 = 0 137 while j < n { 138 if b[i + j] != needle[j] { ok = 0; j = n } else { j = j + 1 } 139 } 140 if ok == 1 { return 1 } 141 i = i + 1 142 } 143 return 0 144} 145 146func rg_fileeq(p1: *u8, p2: *u8) -> i64 { 147 let s1: *i64 = sys_mmap(16) as *i64 148 let s2: *i64 = sys_mmap(16) as *i64 149 let b1: *u8 = rg_readall(p1, s1) 150 let b2: *u8 = rg_readall(p2, s2) 151 if s1[0] != s2[0] { return 0 } 152 if s1[0] <= 0 { return 0 } 153 var i: i64 = 0 154 while i < s1[0] { 155 if b1[i] != b2[i] { return 0 } 156 i = i + 1 157 } 158 return 1 159} 160 161func rg_row(name: *u8, pass: i64) -> i64 { 162 rg_p("ROW " as *u8) 163 rg_p(name) 164 if pass == 1 { rg_p(" PASS\n" as *u8) } else { rg_p(" FAIL\n" as *u8) } 165 return pass 166} 167 168func main(argc: i64, argv: *i64) -> i64 { 169 rg_p("=== VIZSLA RECRUITER GATE: hand-routed channel KATs (relationship > cold-apply) ===\n" as *u8) 170 var rb: *u8 = "/tmp/nx_vizsla_recruiter.sov.elf" as *u8 171 if argc > 1 { rb = argv[1] as *u8 } 172 let pr: i64 = sys_openat_rd(rb) 173 if pr >= 0 { sys_close(pr) } 174 else { 175 rg_p(" instrument missing -> rebuilding via durable runner\n" as *u8) 176 rg_run("_offc/nx_sov_build_run.elf" as *u8, "nx_vizsla_recruiter" as *u8, 0 as *u8, 0 as *u8, 0 as *u8, "/tmp/vzr_rebuild.out" as *u8) 177 } 178 179 // epoch-unique virgin store prefix for the touch ledger 180 let pfx: *u8 = sys_mmap(128) 181 var po: i64 = 0 182 po = rg_cat(pfx, po, "/tmp/vzrG" as *u8) 183 po = rg_catn(pfx, po, sys_now_us()) 184 po = rg_cat(pfx, po, "-" as *u8) 185 pfx[po] = 0 as u8 186 187 let ch: *u8 = "CONF stale_days 30\nCONF strong_permil 500\nCHANNEL recruiter 700\nCHANNEL referral 550\nCHANNEL cold-apply 100\nAGENT recruiter r1 jane-doe compilers systems nishilang\nAGENT recruiter r2 sam-lee sales marketing\nAGENT referral f1 cousin-max writing editing\nAGENT cold-apply portal direct-application *\n" as *u8 188 rg_write("/tmp/vzr_ch.txt" as *u8, ch) 189 // same data, stale_days 60 (the ONLY change): the threshold is data, not code 190 let ch60: *u8 = "CONF stale_days 60\nCONF strong_permil 500\nCHANNEL recruiter 700\nCHANNEL referral 550\nCHANNEL cold-apply 100\nAGENT recruiter r1 jane-doe compilers systems nishilang\nAGENT recruiter r2 sam-lee sales marketing\nAGENT referral f1 cousin-max writing editing\nAGENT cold-apply portal direct-application *\n" as *u8 191 rg_write("/tmp/vzr_ch60.txt" as *u8, ch60) 192 let posts: *u8 = "POST j1 9000000 compilers rust writing\nPOST j2 12000000 nishilang compilers systems\nPOST j3 7500000 sales travel\nPOST j4 8000000 editing writing remote\nPOST j5 7000000 travel logistics\n" as *u8 193 rg_write("/tmp/vzr_posts.txt" as *u8, posts) 194 // r1 touched 06-01 then an OLDER 05-28 stored after it: latest date must win 195 let tch: *u8 = "TOUCH 2026-06-01 r1 ada coffee-chat\nTOUCH 2026-04-20 r2 ada conference-intro\nTOUCH 2026-05-28 r1 ada followup-email\n" as *u8 196 rg_write("/tmp/vzr_tch.txt" as *u8, tch) 197 198 let fch: *u8 = "/tmp/vzr_ch.txt" as *u8 199 let fpo: *u8 = "/tmp/vzr_posts.txt" as *u8 200 let flog: *u8 = "/tmp/vzr_fix.log" as *u8 201 var pass: i64 = 0 202 var r: i64 = 0 203 204 // row 1: loud-fail on missing channels 205 let rc1: i64 = rg_run(rb, "route" as *u8, "/tmp/vzr_ch_NOPE.txt" as *u8, fpo, flog, "/tmp/vzr_out1.txt" as *u8) 206 r = 0 207 if rc1 == 1 { r = 1 } 208 pass = pass + rg_row("loud-fail-missing-channels" as *u8, r) 209 210 // row 2: recruiter route with full overlap 211 let rc2: i64 = rg_run(rb, "route" as *u8, fch, fpo, flog, "/tmp/vzr_out2.txt" as *u8) 212 r = 0 213 if rc2 == 0 { 214 if rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j2 channel=recruiter via=r1 strength=700 overlap=3 state=STRONG" as *u8) == 1 { r = 1 } 215 } 216 pass = pass + rg_row("route-recruiter-strong" as *u8, r) 217 218 // row 3: referral fallback when no recruiter overlaps 219 r = rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j4 channel=referral via=f1 strength=550 overlap=2 state=STRONG" as *u8) 220 pass = pass + rg_row("route-referral-fallback" as *u8, r) 221 222 // row 4: the broken standard process NAMED per posting + verdict counts 223 r = 0 224 if rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j5 channel=cold-apply via=portal strength=100 overlap=0 state=WEAK" as *u8) == 1 { 225 if rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE-VERDICT posts=5 strong=4 weak=1 unrouted=0" as *u8) == 1 { r = 1 } 226 } 227 pass = pass + rg_row("cold-apply-weak-named" as *u8, r) 228 229 // row 5: equal overlap, higher channel weight wins (r1 over f1 on j1) 230 r = rg_has("/tmp/vzr_out2.txt" as *u8, "VIZSLA-RECRUIT-ROUTE post=j1 channel=recruiter via=r1 strength=700 overlap=1 state=STRONG" as *u8) 231 pass = pass + rg_row("best-channel-wins" as *u8, r) 232 233 // row 6: route determinism 234 rg_run(rb, "route" as *u8, fch, fpo, flog, "/tmp/vzr_out6.txt" as *u8) 235 r = rg_fileeq("/tmp/vzr_out2.txt" as *u8, "/tmp/vzr_out6.txt" as *u8) 236 pass = pass + rg_row("route-determinism" as *u8, r) 237 238 // row 7: touch 3 contacts into seg-3001 239 let rc7: i64 = rg_run(rb, "touch" as *u8, "/tmp/vzr_tch.txt" as *u8, pfx, "3001" as *u8, "/tmp/vzr_out7.txt" as *u8) 240 r = 0 241 if rc7 == 0 { 242 if rg_has("/tmp/vzr_out7.txt" as *u8, "VIZSLA-RECRUIT-TOUCH scanned=3 new=3 dup_infile=0 dup_instore=0 segment=seg-3001" as *u8) == 1 { r = 1 } 243 } 244 pass = pass + rg_row("touch-load" as *u8, r) 245 246 // row 8: idempotent re-touch (law 10) 247 let rc8: i64 = rg_run(rb, "touch" as *u8, "/tmp/vzr_tch.txt" as *u8, pfx, "3009" as *u8, "/tmp/vzr_out8.txt" as *u8) 248 r = 0 249 if rc8 == 0 { 250 if rg_has("/tmp/vzr_out8.txt" as *u8, "VIZSLA-RECRUIT-TOUCH scanned=3 new=0 dup_infile=0 dup_instore=3 segment=none" as *u8) == 1 { r = 1 } 251 } 252 pass = pass + rg_row("idempotent-retouch" as *u8, r) 253 254 // row 9: keep-warm -- LATEST date wins (06-01, not the later-stored 05-28) 255 let rc9: i64 = rg_run(rb, "warm" as *u8, pfx, fch, "2026-06-10" as *u8, "/tmp/vzr_out9.txt" as *u8) 256 r = 0 257 if rc9 == 0 { 258 if rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=r1 channel=recruiter last=2026-06-01 days=9 state=FRESH action=none" as *u8) == 1 { r = 1 } 259 } 260 pass = pass + rg_row("latest-date-wins" as *u8, r) 261 262 // row 10: hand-counted 51 days => STALE reconnect 263 r = rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=r2 channel=recruiter last=2026-04-20 days=51 state=STALE action=reconnect" as *u8) 264 pass = pass + rg_row("stale-reconnect" as *u8, r) 265 266 // row 11: never-touched referral COLD; weak-channel portal EXCLUDED by data 267 r = 0 268 if rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=f1 channel=referral last=never days=-1 state=COLD action=introduce" as *u8) == 1 { 269 if rg_has("/tmp/vzr_out9.txt" as *u8, "agent=portal" as *u8) == 0 { 270 if rg_has("/tmp/vzr_out9.txt" as *u8, "VIZSLA-RECRUIT-WARM-VERDICT agents=3 fresh=1 stale=1 cold=1" as *u8) == 1 { r = 1 } 271 } 272 } 273 pass = pass + rg_row("cold-introduce-weak-excluded" as *u8, r) 274 275 // row 12: DATA-DRIVEN threshold -- stale_days=60 file flips r2 to FRESH, same binary 276 let rc12: i64 = rg_run(rb, "warm" as *u8, pfx, "/tmp/vzr_ch60.txt" as *u8, "2026-06-10" as *u8, "/tmp/vzr_out12.txt" as *u8) 277 r = 0 278 if rc12 == 0 { 279 if rg_has("/tmp/vzr_out12.txt" as *u8, "VIZSLA-RECRUIT-WARM agent=r2 channel=recruiter last=2026-04-20 days=51 state=FRESH action=none" as *u8) == 1 { 280 if rg_has("/tmp/vzr_out12.txt" as *u8, "VIZSLA-RECRUIT-WARM-VERDICT agents=3 fresh=2 stale=0 cold=1" as *u8) == 1 { r = 1 } 281 } 282 } 283 pass = pass + rg_row("data-driven-stale-threshold" as *u8, r) 284 285 // row 13: warm determinism 286 rg_run(rb, "warm" as *u8, pfx, fch, "2026-06-10" as *u8, "/tmp/vzr_out13.txt" as *u8) 287 r = rg_fileeq("/tmp/vzr_out9.txt" as *u8, "/tmp/vzr_out13.txt" as *u8) 288 pass = pass + rg_row("warm-determinism" as *u8, r) 289 290 let permil: i64 = (pass * 1000) / 13 291 let logfd: i64 = sys_openat_append("knowledge/status/vizsla_gate.log" as *u8, 0x1a4) 292 var fdi: i64 = 0 293 while fdi < 2 { 294 var fd: i64 = 1 295 if fdi == 1 { fd = logfd } 296 if fd > 0 { 297 let line: *u8 = sys_mmap(256) 298 var o: i64 = 0 299 o = rg_cat(line, o, "VIZSLA-RECRUIT-GATE epoch=" as *u8) 300 o = rg_catn(line, o, sys_now_realtime_sec()) 301 o = rg_cat(line, o, " rows=13 pass=" as *u8) 302 o = rg_catn(line, o, pass) 303 o = rg_cat(line, o, " permil=" as *u8) 304 o = rg_catn(line, o, permil) 305 if pass == 13 { 306 o = rg_cat(line, o, " verdict=GREEN\n" as *u8) 307 } else { 308 o = rg_cat(line, o, " verdict=RED\n" as *u8) 309 } 310 sys_write(fd, line, o) 311 } 312 fdi = fdi + 1 313 } 314 if logfd > 0 { sys_close(logfd) } 315 if pass == 13 { return 0 } 316 return 1 317}