code wiki / _hdl_build / nx_vizsla_recruiter.nx

nx_vizsla_recruiter.nx source

↩ module page · 751 lines · 27066 B

1// nx_vizsla_recruiter.nx -- NISHI VIZSLA V2c: the recruiter-channel engine. 2// Operator directive 2026-06-10: "having a recruiter is a big deal as AI has 3// broken the standard process." Cold applications drown in AI-generated 4// slush and AI screeners; the human channel (recruiter, referral, warm intro) 5// is the high-yield path. That theory lives AS DATA in channels.txt -- 6// channel weights, agents, thresholds are all file content (law 11/25), so 7// refining it (new channel, new weight) is a data edit, never a recompile. 8// 9// Commands (argv[1]): 10// route <channels> <postings> [log] every posting -> the strongest 11// available relationship: best agent by 12// (channel weight, term overlap, file 13// order). An agent term "*" matches any 14// posting (the cold portal). Cold/weak 15// routes (weight < strong_permil) are 16// state=WEAK -- the broken standard 17// process NAMED per posting, not hidden. 18// touch <touchfile> <prefix> [segid] TOUCH rows -> canonical records -> CID 19// keys "tch:nxc1-..." on seg_store = 20// additive relationship history, 21// idempotent by construction (law 10). 22// warm <prefix> <channels> <today> keep-warm cadence over STRONG-channel 23// agents only (worth-tending = derived 24// from the same data): LATEST touch date 25// wins; <=stale_days FRESH/none, 26// >stale_days STALE/reconnect, never 27// touched COLD/introduce. `today` is an 28// argv date = deterministic stdout. 29// 30// File formats (line records, # comments): 31// channels: CONF stale_days <n> | CONF strong_permil <n> 32// CHANNEL <name> <weight_permil> 33// AGENT <channel> <id> <display> <terms...> ("*" = wildcard) 34// postings: POST <id> <pay_cents> <term> <term> ... (same as V2a) 35// touches: TOUCH <date> <agent-id> <member> <note> (date YYYY-MM-DD) 36// 37// Determinism: stdout has no clocks (warm takes today via argv; epoch headers 38// go to logs only; track/warm log derived from store prefix). Loud-fail law: 39// missing files, AGENT referencing unknown CHANNEL, malformed dates = exit 1. 40// EXCEED: job boards and ATS pipelines do not model the relationship channel 41// at all -- they ARE the broken channel; Vizsla routes around them and tends 42// the relationships before they are needed. Outreach DRAFTS (human sends, 43// V4 law) land with V4 relationships. 44// spec: knowledge/specs/2026-06-10-nishi-vizsla-ladder.md license_tier: ORIGINAL 45import "nx_syscalls.nx" 46import "nx_canon_cid.nx" 47import "nx_seg_store.nx" 48const K_MAGIC_1970: i64 = 1970 49const K_MAGIC_146097: i64 = 146097 50const K_MAGIC_719468: i64 = 719468 51const K_MAGIC_1024: i64 = 1024 52const K_MAGIC_131072: i64 = 131072 53const K_MAGIC_2048: i64 = 2048 54const K_MAGIC_4096: i64 = 4096 55const K_MAGIC_65536: i64 = 65536 56 57func vr_slen(s: *u8) -> i64 { 58 var n: i64 = 0 59 while s[n] != (0 as u8) { n = n + 1 } 60 return n 61} 62 63func vr_p(s: *u8) -> i64 { 64 sys_write(1, s, vr_slen(s)) 65 return 0 66} 67 68func vr_eq(a: *u8, b: *u8) -> i64 { 69 var i: i64 = 0 70 var go: i64 = 1 71 while go == 1 { 72 if a[i] != b[i] { return 0 } 73 if a[i] == (0 as u8) { return 1 } 74 i = i + 1 75 } 76 return 0 77} 78 79func vr_dup(s: *u8) -> *u8 { 80 let n: i64 = vr_slen(s) 81 let d: *u8 = sys_mmap(n + 2) 82 var i: i64 = 0 83 while i <= n { d[i] = s[i]; i = i + 1 } 84 return d 85} 86 87func vr_atoi(s: *u8) -> i64 { 88 var v: i64 = 0 89 var i: i64 = 0 90 while s[i] != (0 as u8) { 91 let d: i64 = (s[i] as i64) - 48 92 if d >= 0 { if d <= 9 { v = v * 10 + d } } 93 i = i + 1 94 } 95 return v 96} 97 98func vr_digits(s: *u8) -> i64 { 99 if s[0] == (0 as u8) { return 0 } 100 var i: i64 = 0 101 while s[i] != (0 as u8) { 102 let d: i64 = (s[i] as i64) - 48 103 if d < 0 { return 0 } 104 if d > 9 { return 0 } 105 i = i + 1 106 } 107 return 1 108} 109 110func vr_isws(c: i64) -> i64 { 111 if c == 32 { return 1 } 112 if c == 13 { return 1 } 113 if c == 9 { return 1 } 114 return 0 115} 116 117func vr_tok(b: *u8, off: i64, lend: i64, dst: *u8, cap: i64) -> i64 { 118 var p: i64 = off 119 var go: i64 = 1 120 while go == 1 { 121 if p >= lend { go = 0 } else { 122 if vr_isws(b[p] as i64) == 1 { p = p + 1 } else { go = 0 } 123 } 124 } 125 var t: i64 = 0 126 go = 1 127 while go == 1 { 128 if p >= lend { go = 0 } else { 129 if vr_isws(b[p] as i64) == 1 { go = 0 } else { 130 if t < cap - 1 { dst[t] = b[p]; t = t + 1 } 131 p = p + 1 132 } 133 } 134 } 135 dst[t] = 0 as u8 136 return p 137} 138 139func vr_cat(dst: *u8, off: i64, s: *u8) -> i64 { 140 var i: i64 = 0 141 while s[i] != (0 as u8) { dst[off + i] = s[i]; i = i + 1 } 142 return off + i 143} 144 145func vr_catn(dst: *u8, off: i64, v: i64) -> i64 { 146 var o: i64 = off 147 var m: i64 = v 148 if m < 0 { dst[o] = 45 as u8; o = o + 1; m = 0 - m } 149 let t: *u8 = sys_mmap(28) 150 var k: i64 = 0 151 if m == 0 { t[0] = 48 as u8; k = 1 } 152 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 153 var i: i64 = 0 154 while i < k { dst[o + i] = t[k - 1 - i]; i = i + 1 } 155 return o + k 156} 157 158func vr_find(list: *i64, n: i64, s: *u8) -> i64 { 159 var i: i64 = 0 160 while i < n { 161 if vr_eq(list[i] as *u8, s) == 1 { return i } 162 i = i + 1 163 } 164 return 0 - 1 165} 166 167func vr_kmemeq(b: *u8, off: i64, n: i64, s: *u8) -> i64 { 168 if vr_slen(s) != n { return 0 } 169 var i: i64 = 0 170 while i < n { 171 if b[off + i] != s[i] { return 0 } 172 i = i + 1 173 } 174 return 1 175} 176 177func vr_field(rec: *u8, rl: i64, want: *u8, out: *u8, cap: i64) -> i64 { 178 if rl < 8 { return 0 } 179 let nf: i64 = ss_r32(rec, 4) 180 var off: i64 = 8 181 var fi: i64 = 0 182 while fi < nf { 183 if off + 8 > rl { return 0 } 184 let kl: i64 = ss_r32(rec, off) 185 let koff: i64 = off + 4 186 let vl: i64 = ss_r32(rec, koff + kl) 187 let voff: i64 = koff + kl + 4 188 if vr_kmemeq(rec, koff, kl, want) == 1 { 189 var t: i64 = 0 190 while t < vl { 191 if t < cap - 1 { out[t] = rec[voff + t] } 192 t = t + 1 193 } 194 if t > cap - 1 { t = cap - 1 } 195 out[t] = 0 as u8 196 return 1 197 } 198 off = voff + vl 199 fi = fi + 1 200 } 201 return 0 202} 203 204// strict-better for route ranking: (channel weight, overlap); file order = no 205func vr_better(w: i64, bw: i64, ov: i64, bo: i64) -> i64 { 206 if w > bw { return 1 } 207 if w < bw { return 0 } 208 if ov > bo { return 1 } 209 return 0 210} 211 212func vr_istch(b: *u8, koff: i64, kl: i64) -> i64 { 213 if kl <= 4 { return 0 } 214 return vr_kmemeq(b, koff, 4, "tch:" as *u8) 215} 216 217func vr_log(lpath: *u8, tag: *u8, rep: *u8, o: i64) -> i64 { 218 let fd: i64 = sys_openat_append(lpath, 0x1a4) 219 if fd <= 0 { return 0 } 220 let hdr: *u8 = sys_mmap(256) 221 var ho: i64 = 0 222 ho = vr_cat(hdr, ho, "VIZSLA-RECRUIT epoch=" as *u8) 223 ho = vr_catn(hdr, ho, sys_now_realtime_sec()) 224 ho = vr_cat(hdr, ho, " cmd=" as *u8) 225 ho = vr_cat(hdr, ho, tag) 226 ho = vr_cat(hdr, ho, "\n" as *u8) 227 sys_write(fd, hdr, ho) 228 sys_write(fd, rep, o) 229 sys_close(fd) 230 return 0 231} 232 233func vr_prefixlog(prefix: *u8, out: *u8) -> i64 { 234 var o: i64 = 0 235 o = vr_cat(out, o, prefix) 236 o = vr_cat(out, o, "recruit.log" as *u8) 237 out[o] = 0 as u8 238 return o 239} 240 241// civil date "YYYY-MM-DD" -> days since 1970-01-01 (Hinnant days_from_civil); 242// -1 if malformed (needs 3 numbers, plausible ranges -- boundary law 12) 243func vr_datedays(s: *u8) -> i64 { 244 let nums: *i64 = sys_mmap(8 * 4) as *i64 245 var nn: i64 = 0 246 var cur: i64 = 0 247 var indig: i64 = 0 248 var i: i64 = 0 249 var go: i64 = 1 250 while go == 1 { 251 let c: i64 = s[i] as i64 252 var isd: i64 = 0 253 if c >= 48 { if c <= 57 { isd = 1 } } 254 if isd == 1 { cur = cur * 10 + (c - 48); indig = 1 } 255 if isd == 0 { 256 if indig == 1 { 257 if nn < 4 { nums[nn] = cur; nn = nn + 1 } 258 cur = 0 259 indig = 0 260 } 261 } 262 if c == 0 { go = 0 } 263 i = i + 1 264 } 265 if nn != 3 { return 0 - 1 } 266 var y: i64 = nums[0] 267 let m: i64 = nums[1] 268 let d: i64 = nums[2] 269 if y < K_MAGIC_1970 { return 0 - 1 } 270 if m < 1 { return 0 - 1 } 271 if m > 12 { return 0 - 1 } 272 if d < 1 { return 0 - 1 } 273 if d > 31 { return 0 - 1 } 274 if m <= 2 { y = y - 1 } 275 let era: i64 = y / 400 276 let yoe: i64 = y - era * 400 277 var mp: i64 = m - 3 278 if m <= 2 { mp = m + 9 } 279 let doy: i64 = (153 * mp + 2) / 5 + d - 1 280 let doe: i64 = yoe * 365 + yoe / 4 - yoe / 100 + doy 281 return era * K_MAGIC_146097 + doe - K_MAGIC_719468 282} 283 284// channels-file tables packed in one state block (heap-mmap idiom): 285// cf[0]=ch_name cf[1]=ch_w cf[2]=nch 286// cf[3]=ag_ch cf[4]=ag_id cf[5]=ag_disp cf[6]=ag_ts cf[7]=ag_tn cf[8]=nag 287// cf[9]=terms flat ptr-list cf[10]=nterm cf[11]=stale_days cf[12]=strong_permil 288func vr_load_channels(cpath: *u8) -> *i64 { 289 let szp: *i64 = sys_mmap(16) as *i64 290 let cb: *u8 = ss_readall(cpath, szp) 291 let csz: i64 = szp[0] 292 if csz <= 0 { return 0 as *i64 } 293 let cf: *i64 = sys_mmap(8 * 16) as *i64 294 cf[0] = sys_mmap(8 * 16) 295 cf[1] = sys_mmap(8 * 16) 296 cf[2] = 0 297 cf[3] = sys_mmap(8 * 64) 298 cf[4] = sys_mmap(8 * 64) 299 cf[5] = sys_mmap(8 * 64) 300 cf[6] = sys_mmap(8 * 64) 301 cf[7] = sys_mmap(8 * 64) 302 cf[8] = 0 303 cf[9] = sys_mmap(8 * K_MAGIC_1024) 304 cf[10] = 0 305 cf[11] = 30 306 cf[12] = 500 307 let ch_name: *i64 = cf[0] as *i64 308 let ch_w: *i64 = cf[1] as *i64 309 let ag_ch: *i64 = cf[3] as *i64 310 let ag_id: *i64 = cf[4] as *i64 311 let ag_disp: *i64 = cf[5] as *i64 312 let ag_ts: *i64 = cf[6] as *i64 313 let ag_tn: *i64 = cf[7] as *i64 314 let terms: *i64 = cf[9] as *i64 315 let t0: *u8 = sys_mmap(128) 316 let t1: *u8 = sys_mmap(128) 317 let t2: *u8 = sys_mmap(128) 318 let t3: *u8 = sys_mmap(128) 319 var i: i64 = 0 320 while i < csz { 321 var e: i64 = i 322 var go: i64 = 1 323 while go == 1 { 324 if e >= csz { go = 0 } else { 325 if cb[e] == (10 as u8) { go = 0 } else { e = e + 1 } 326 } 327 } 328 var p: i64 = vr_tok(cb, i, e, t0, 128) 329 if t0[0] == (35 as u8) { t0[0] = 0 as u8 } 330 if vr_eq(t0, "CONF" as *u8) == 1 { 331 p = vr_tok(cb, p, e, t1, 128) 332 p = vr_tok(cb, p, e, t2, 128) 333 if vr_eq(t1, "stale_days" as *u8) == 1 { cf[11] = vr_atoi(t2) } 334 if vr_eq(t1, "strong_permil" as *u8) == 1 { cf[12] = vr_atoi(t2) } 335 } 336 if vr_eq(t0, "CHANNEL" as *u8) == 1 { 337 p = vr_tok(cb, p, e, t1, 128) 338 p = vr_tok(cb, p, e, t2, 128) 339 if vr_digits(t2) == 0 { return 0 as *i64 } 340 if cf[2] < 16 { ch_name[cf[2]] = vr_dup(t1) as i64; ch_w[cf[2]] = vr_atoi(t2); cf[2] = cf[2] + 1 } 341 } 342 if vr_eq(t0, "AGENT" as *u8) == 1 { 343 p = vr_tok(cb, p, e, t1, 128) 344 p = vr_tok(cb, p, e, t2, 128) 345 p = vr_tok(cb, p, e, t3, 128) 346 let ci: i64 = vr_find(ch_name, cf[2], t1) 347 if ci < 0 { return 0 as *i64 } 348 if cf[8] < 64 { 349 ag_ch[cf[8]] = ci 350 ag_id[cf[8]] = vr_dup(t2) as i64 351 ag_disp[cf[8]] = vr_dup(t3) as i64 352 ag_ts[cf[8]] = cf[10] 353 var tn: i64 = 0 354 var more: i64 = 1 355 while more == 1 { 356 p = vr_tok(cb, p, e, t3, 128) 357 if t3[0] == (0 as u8) { more = 0 } else { 358 if cf[10] < K_MAGIC_1024 { terms[cf[10]] = vr_dup(t3) as i64; cf[10] = cf[10] + 1; tn = tn + 1 } 359 } 360 } 361 ag_tn[cf[8]] = tn 362 cf[8] = cf[8] + 1 363 } 364 } 365 i = e + 1 366 } 367 if cf[2] < 1 { return 0 as *i64 } 368 if cf[8] < 1 { return 0 as *i64 } 369 return cf 370} 371 372// agent availability vs a posting's term slice: -1 unavailable, else overlap 373// count ("*" wildcard term = available at overlap 0 + never counts) 374func vr_overlap(cf: *i64, ai: i64, pterms: *i64, pn: i64) -> i64 { 375 let ag_ts: *i64 = cf[6] as *i64 376 let ag_tn: *i64 = cf[7] as *i64 377 let terms: *i64 = cf[9] as *i64 378 var ov: i64 = 0 379 var wild: i64 = 0 380 var t: i64 = 0 381 while t < ag_tn[ai] { 382 let term: *u8 = terms[ag_ts[ai] + t] as *u8 383 if vr_eq(term, "*" as *u8) == 1 { wild = 1 } else { 384 if vr_find(pterms, pn, term) >= 0 { ov = ov + 1 } 385 } 386 t = t + 1 387 } 388 if ov > 0 { return ov } 389 if wild == 1 { return 0 } 390 return 0 - 1 391} 392 393// ---------------- ROUTE ---------------- 394func vr_cmd_route(argc: i64, argv: *i64) -> i64 { 395 if argc < 4 { vr_p("VIZSLA-RECRUIT route needs <channels> <postings> -- fail loud\n" as *u8); return 1 } 396 let cf: *i64 = vr_load_channels(argv[2] as *u8) 397 if (cf as i64) == 0 { vr_p("VIZSLA-RECRUIT channels MISSING/MALFORMED -- fail loud\n" as *u8); return 1 } 398 var lpath: *u8 = "knowledge/status/vizsla_recruit.log" as *u8 399 if argc > 4 { lpath = argv[4] as *u8 } 400 401 let szp: *i64 = sys_mmap(16) as *i64 402 let ob: *u8 = ss_readall(argv[3] as *u8, szp) 403 let osz: i64 = szp[0] 404 if osz <= 0 { vr_p("VIZSLA-RECRUIT postings MISSING/EMPTY -- fail loud\n" as *u8); return 1 } 405 406 let ch_name: *i64 = cf[0] as *i64 407 let ch_w: *i64 = cf[1] as *i64 408 let ag_ch: *i64 = cf[3] as *i64 409 let ag_id: *i64 = cf[4] as *i64 410 let strong: i64 = cf[12] 411 412 let rep: *u8 = sys_mmap(K_MAGIC_131072) 413 var o: i64 = 0 414 var nposts: i64 = 0 415 var nstrong: i64 = 0 416 var nweak: i64 = 0 417 var nunr: i64 = 0 418 let t0: *u8 = sys_mmap(128) 419 let t1: *u8 = sys_mmap(128) 420 let t2: *u8 = sys_mmap(128) 421 let t3: *u8 = sys_mmap(128) 422 let pterms: *i64 = sys_mmap(8 * 64) as *i64 423 424 var i: i64 = 0 425 while i < osz { 426 var e: i64 = i 427 var go: i64 = 1 428 while go == 1 { 429 if e >= osz { go = 0 } else { 430 if ob[e] == (10 as u8) { go = 0 } else { e = e + 1 } 431 } 432 } 433 var p: i64 = vr_tok(ob, i, e, t0, 128) 434 if t0[0] == (35 as u8) { t0[0] = 0 as u8 } 435 if vr_eq(t0, "POST" as *u8) == 1 { 436 p = vr_tok(ob, p, e, t1, 128) 437 p = vr_tok(ob, p, e, t2, 128) 438 if t1[0] == (0 as u8) { vr_p("VIZSLA-RECRUIT POST missing id -- fail loud\n" as *u8); return 1 } 439 var pn: i64 = 0 440 var more: i64 = 1 441 while more == 1 { 442 p = vr_tok(ob, p, e, t3, 128) 443 if t3[0] == (0 as u8) { more = 0 } else { 444 if pn < 64 { pterms[pn] = vr_dup(t3) as i64; pn = pn + 1 } 445 } 446 } 447 nposts = nposts + 1 448 // best agent: (channel weight, overlap, file order) 449 var bi: i64 = 0 - 1 450 var bw: i64 = 0 - 1 451 var bo: i64 = 0 - 1 452 var ai: i64 = 0 453 while ai < cf[8] { 454 let ov: i64 = vr_overlap(cf, ai, pterms, pn) 455 if ov >= 0 { 456 let w: i64 = ch_w[ag_ch[ai]] 457 if vr_better(w, bw, ov, bo) == 1 { bi = ai; bw = w; bo = ov } 458 } 459 ai = ai + 1 460 } 461 o = vr_cat(rep, o, "VIZSLA-RECRUIT-ROUTE post=" as *u8) 462 o = vr_cat(rep, o, t1) 463 if bi < 0 { 464 nunr = nunr + 1 465 o = vr_cat(rep, o, " channel=none via=none strength=0 overlap=0 state=UNROUTED\n" as *u8) 466 } else { 467 o = vr_cat(rep, o, " channel=" as *u8) 468 o = vr_cat(rep, o, ch_name[ag_ch[bi]] as *u8) 469 o = vr_cat(rep, o, " via=" as *u8) 470 o = vr_cat(rep, o, ag_id[bi] as *u8) 471 o = vr_cat(rep, o, " strength=" as *u8) 472 o = vr_catn(rep, o, bw) 473 o = vr_cat(rep, o, " overlap=" as *u8) 474 o = vr_catn(rep, o, bo) 475 if bw >= strong { 476 nstrong = nstrong + 1 477 o = vr_cat(rep, o, " state=STRONG\n" as *u8) 478 } else { 479 nweak = nweak + 1 480 o = vr_cat(rep, o, " state=WEAK\n" as *u8) 481 } 482 } 483 } 484 i = e + 1 485 } 486 if nposts < 1 { vr_p("VIZSLA-RECRUIT no POST rows -- fail loud\n" as *u8); return 1 } 487 o = vr_cat(rep, o, "VIZSLA-RECRUIT-ROUTE-VERDICT posts=" as *u8) 488 o = vr_catn(rep, o, nposts) 489 o = vr_cat(rep, o, " strong=" as *u8) 490 o = vr_catn(rep, o, nstrong) 491 o = vr_cat(rep, o, " weak=" as *u8) 492 o = vr_catn(rep, o, nweak) 493 o = vr_cat(rep, o, " unrouted=" as *u8) 494 o = vr_catn(rep, o, nunr) 495 o = vr_cat(rep, o, "\n" as *u8) 496 sys_write(1, rep, o) 497 vr_log(lpath, "route" as *u8, rep, o) 498 return 0 499} 500 501// ---------------- TOUCH (additive relationship history) ---------------- 502func vr_cmd_touch(argc: i64, argv: *i64) -> i64 { 503 if argc < 4 { vr_p("VIZSLA-RECRUIT touch needs <touchfile> <prefix> -- fail loud\n" as *u8); return 1 } 504 let tpath: *u8 = argv[2] as *u8 505 let prefix: *u8 = argv[3] as *u8 506 var segid: i64 = 0 507 if argc > 4 { segid = vr_atoi(argv[4] as *u8) } 508 if segid == 0 { segid = sys_now_us() } 509 510 let szp: *i64 = sys_mmap(16) as *i64 511 let b: *u8 = ss_readall(tpath, szp) 512 let sz: i64 = szp[0] 513 if sz <= 0 { vr_p("VIZSLA-RECRUIT touchfile MISSING/EMPTY -- fail loud\n" as *u8); return 1 } 514 515 let keys: *i64 = sys_mmap(8 * 8) as *i64 516 let vals: *i64 = sys_mmap(8 * 8) as *i64 517 keys[0] = "kind" as *u8 as i64 518 keys[1] = "date" as *u8 as i64 519 keys[2] = "agent" as *u8 as i64 520 keys[3] = "member" as *u8 as i64 521 keys[4] = "note" as *u8 as i64 522 vals[0] = "touch" as *u8 as i64 523 524 let t0: *u8 = sys_mmap(128) 525 let dt: *u8 = sys_mmap(128) 526 let ag: *u8 = sys_mmap(128) 527 let me: *u8 = sys_mmap(128) 528 let nt: *u8 = sys_mmap(256) 529 let pp: *i64 = sys_mmap(16) as *i64 530 let ll: *i64 = sys_mmap(16) as *i64 531 532 let w: *i64 = ss_begin() 533 let seen: *i64 = sys_mmap(8 * K_MAGIC_2048) as *i64 534 var nseen: i64 = 0 535 var scanned: i64 = 0 536 var added: i64 = 0 537 var dup_infile: i64 = 0 538 var dup_instore: i64 = 0 539 540 var i: i64 = 0 541 while i < sz { 542 var e: i64 = i 543 var go: i64 = 1 544 while go == 1 { 545 if e >= sz { go = 0 } else { 546 if b[e] == (10 as u8) { go = 0 } else { e = e + 1 } 547 } 548 } 549 var p: i64 = vr_tok(b, i, e, t0, 128) 550 if t0[0] == (35 as u8) { t0[0] = 0 as u8 } 551 if vr_eq(t0, "TOUCH" as *u8) == 1 { 552 scanned = scanned + 1 553 p = vr_tok(b, p, e, dt, 128) 554 p = vr_tok(b, p, e, ag, 128) 555 p = vr_tok(b, p, e, me, 128) 556 p = vr_tok(b, p, e, nt, 256) 557 if vr_datedays(dt) < 0 { vr_p("VIZSLA-RECRUIT TOUCH bad date (YYYY-MM-DD) -- fail loud\n" as *u8); return 1 } 558 if ag[0] == (0 as u8) { vr_p("VIZSLA-RECRUIT TOUCH missing agent -- fail loud\n" as *u8); return 1 } 559 if me[0] == (0 as u8) { vr_p("VIZSLA-RECRUIT TOUCH missing member -- fail loud\n" as *u8); return 1 } 560 if nt[0] == (0 as u8) { vr_p("VIZSLA-RECRUIT TOUCH missing note -- fail loud\n" as *u8); return 1 } 561 vals[1] = dt as i64 562 vals[2] = ag as i64 563 vals[3] = me as i64 564 vals[4] = nt as i64 565 let enc: *u8 = sys_mmap(K_MAGIC_2048) 566 let el: i64 = canon_encode(keys, vals, 5, enc) 567 let cid: *u8 = sys_mmap(96) 568 cid_of(enc, el, cid) 569 let kbuf: *u8 = sys_mmap(128) 570 var ko: i64 = 0 571 ko = vr_cat(kbuf, ko, "tch:" as *u8) 572 ko = vr_cat(kbuf, ko, cid) 573 kbuf[ko] = 0 as u8 574 var fresh: i64 = 1 575 if vr_find(seen, nseen, kbuf) >= 0 { fresh = 0; dup_infile = dup_infile + 1 } 576 if fresh == 1 { 577 if nseen < K_MAGIC_2048 { seen[nseen] = vr_dup(kbuf) as i64; nseen = nseen + 1 } 578 } 579 if fresh == 1 { 580 if ss_get_idx(prefix, kbuf, pp, ll) == 1 { fresh = 0; dup_instore = dup_instore + 1 } 581 } 582 if fresh == 1 { 583 if ss_add(w, 1, kbuf, enc, el) != 0 { vr_p("VIZSLA-RECRUIT writer full -- fail loud\n" as *u8); return 1 } 584 added = added + 1 585 } 586 } 587 i = e + 1 588 } 589 590 var committed: i64 = 0 591 if added > 0 { 592 if ss_commit(prefix, w, segid) != 0 { vr_p("VIZSLA-RECRUIT commit FAILED -- fail loud\n" as *u8); return 1 } 593 committed = 1 594 } 595 596 let rep: *u8 = sys_mmap(K_MAGIC_4096) 597 var o: i64 = 0 598 o = vr_cat(rep, o, "VIZSLA-RECRUIT-TOUCH scanned=" as *u8) 599 o = vr_catn(rep, o, scanned) 600 o = vr_cat(rep, o, " new=" as *u8) 601 o = vr_catn(rep, o, added) 602 o = vr_cat(rep, o, " dup_infile=" as *u8) 603 o = vr_catn(rep, o, dup_infile) 604 o = vr_cat(rep, o, " dup_instore=" as *u8) 605 o = vr_catn(rep, o, dup_instore) 606 o = vr_cat(rep, o, " segment=" as *u8) 607 if committed == 1 { 608 o = vr_cat(rep, o, "seg-" as *u8) 609 o = vr_catn(rep, o, segid) 610 } else { 611 o = vr_cat(rep, o, "none" as *u8) 612 } 613 o = vr_cat(rep, o, "\n" as *u8) 614 sys_write(1, rep, o) 615 let lp: *u8 = sys_mmap(512) 616 vr_prefixlog(prefix, lp) 617 vr_log(lp, "touch" as *u8, rep, o) 618 return 0 619} 620 621// ---------------- WARM (keep-warm cadence; LATEST date wins) ---------------- 622func vr_cmd_warm(argc: i64, argv: *i64) -> i64 { 623 if argc < 5 { vr_p("VIZSLA-RECRUIT warm needs <prefix> <channels> <today> -- fail loud\n" as *u8); return 1 } 624 let prefix: *u8 = argv[2] as *u8 625 let cf: *i64 = vr_load_channels(argv[3] as *u8) 626 if (cf as i64) == 0 { vr_p("VIZSLA-RECRUIT channels MISSING/MALFORMED -- fail loud\n" as *u8); return 1 } 627 let today: i64 = vr_datedays(argv[4] as *u8) 628 if today < 0 { vr_p("VIZSLA-RECRUIT bad today date (YYYY-MM-DD) -- fail loud\n" as *u8); return 1 } 629 630 let ch_name: *i64 = cf[0] as *i64 631 let ch_w: *i64 = cf[1] as *i64 632 let ag_ch: *i64 = cf[3] as *i64 633 let ag_id: *i64 = cf[4] as *i64 634 let stale: i64 = cf[11] 635 let strong: i64 = cf[12] 636 637 // last (latest-date) touch per agent; empty store = everyone COLD (bootstrap) 638 let a_days: *i64 = sys_mmap(8 * 64) as *i64 639 let a_date: *i64 = sys_mmap(8 * 64) as *i64 640 var ai0: i64 = 0 641 while ai0 < cf[8] { a_days[ai0] = 0 - 1; a_date[ai0] = "never" as *u8 as i64; ai0 = ai0 + 1 } 642 var unknown: i64 = 0 643 var touches: i64 = 0 644 645 let segs: *i64 = sys_mmap(8 * 260) as *i64 646 let ns: i64 = ss_manifest(prefix, segs) 647 let fag: *u8 = sys_mmap(128) 648 let fdt: *u8 = sys_mmap(128) 649 var s: i64 = 0 650 while s < ns { 651 let path: *u8 = sys_mmap(512) 652 var po: i64 = 0 653 po = vr_cat(path, po, prefix) 654 po = vr_cat(path, po, segs[s] as *u8) 655 po = vr_cat(path, po, ".docs" as *u8) 656 path[po] = 0 as u8 657 let szp: *i64 = sys_mmap(16) as *i64 658 let b: *u8 = ss_readall(path, szp) 659 let sz: i64 = szp[0] 660 var j: i64 = 0 661 while j + 9 <= sz { 662 let kind: i64 = b[j] 663 let kl: i64 = ss_r32(b, j + 1) 664 let koff: i64 = j + 5 665 let vl: i64 = ss_r32(b, koff + kl) 666 let voff: i64 = koff + kl + 4 667 var take: i64 = 0 668 if kind == 1 { take = vr_istch(b, koff, kl) } 669 if take == 1 { 670 let rec: *u8 = (b as i64 + voff) as *u8 671 var okf: i64 = vr_field(rec, vl, "agent" as *u8, fag, 128) 672 okf = okf + vr_field(rec, vl, "date" as *u8, fdt, 128) 673 if okf == 2 { 674 touches = touches + 1 675 let aix: i64 = vr_find(ag_id, cf[8], fag) 676 if aix < 0 { unknown = unknown + 1 } 677 if aix >= 0 { 678 let dd: i64 = vr_datedays(fdt) 679 if dd > a_days[aix] { a_days[aix] = dd; a_date[aix] = vr_dup(fdt) as i64 } 680 } 681 } 682 } 683 j = voff + vl 684 } 685 s = s + 1 686 } 687 688 // strong-channel agents only = relationships worth tending (from the data) 689 let rep: *u8 = sys_mmap(K_MAGIC_65536) 690 var o: i64 = 0 691 var nag: i64 = 0 692 var nfresh: i64 = 0 693 var nstale: i64 = 0 694 var ncold: i64 = 0 695 var ai: i64 = 0 696 while ai < cf[8] { 697 if ch_w[ag_ch[ai]] >= strong { 698 nag = nag + 1 699 o = vr_cat(rep, o, "VIZSLA-RECRUIT-WARM agent=" as *u8) 700 o = vr_cat(rep, o, ag_id[ai] as *u8) 701 o = vr_cat(rep, o, " channel=" as *u8) 702 o = vr_cat(rep, o, ch_name[ag_ch[ai]] as *u8) 703 o = vr_cat(rep, o, " last=" as *u8) 704 o = vr_cat(rep, o, a_date[ai] as *u8) 705 o = vr_cat(rep, o, " days=" as *u8) 706 if a_days[ai] < 0 { o = vr_catn(rep, o, 0 - 1) } else { o = vr_catn(rep, o, today - a_days[ai]) } 707 if a_days[ai] < 0 { 708 ncold = ncold + 1 709 o = vr_cat(rep, o, " state=COLD action=introduce\n" as *u8) 710 } else { 711 if today - a_days[ai] <= stale { 712 nfresh = nfresh + 1 713 o = vr_cat(rep, o, " state=FRESH action=none\n" as *u8) 714 } else { 715 nstale = nstale + 1 716 o = vr_cat(rep, o, " state=STALE action=reconnect\n" as *u8) 717 } 718 } 719 } 720 ai = ai + 1 721 } 722 o = vr_cat(rep, o, "VIZSLA-RECRUIT-WARM-VERDICT agents=" as *u8) 723 o = vr_catn(rep, o, nag) 724 o = vr_cat(rep, o, " fresh=" as *u8) 725 o = vr_catn(rep, o, nfresh) 726 o = vr_cat(rep, o, " stale=" as *u8) 727 o = vr_catn(rep, o, nstale) 728 o = vr_cat(rep, o, " cold=" as *u8) 729 o = vr_catn(rep, o, ncold) 730 o = vr_cat(rep, o, "\n" as *u8) 731 if unknown > 0 { 732 o = vr_cat(rep, o, "VIZSLA-RECRUIT-WARM-UNKNOWN touches=" as *u8) 733 o = vr_catn(rep, o, unknown) 734 o = vr_cat(rep, o, "\n" as *u8) 735 } 736 sys_write(1, rep, o) 737 let lp: *u8 = sys_mmap(512) 738 vr_prefixlog(prefix, lp) 739 vr_log(lp, "warm" as *u8, rep, o) 740 return 0 741} 742 743func main(argc: i64, argv: *i64) -> i64 { 744 if argc < 2 { vr_p("VIZSLA-RECRUIT usage: route|touch|warm -- fail loud\n" as *u8); return 1 } 745 let cmd: *u8 = argv[1] as *u8 746 if vr_eq(cmd, "route" as *u8) == 1 { return vr_cmd_route(argc, argv) } 747 if vr_eq(cmd, "touch" as *u8) == 1 { return vr_cmd_touch(argc, argv) } 748 if vr_eq(cmd, "warm" as *u8) == 1 { return vr_cmd_warm(argc, argv) } 749 vr_p("VIZSLA-RECRUIT unknown command (route|touch|warm) -- fail loud\n" as *u8) 750 return 1 751}