code wiki / _hdl_build / nx_landmine_probe.nx

nx_landmine_probe.nx source

↩ module page · 143 lines · 6696 B

1// nx_landmine_probe.nx -- THE LANDMINE RETIREMENT ENGINE (seq291/seq711, 2026-07-23). 2// 3// THE STALL IT ENDS: LM-003/LM-007 were retired in June by writing a probe that PROVED the root fixed, 4// but that was never mechanized -- so 28 landmines sat un-re-probed for 36 days while nx_cc moved on and 5// the registry accumulated instead of draining. This organ makes re-probing a STANDING BEAT: it discovers 6// every lmprobe_<id>.elf in the deploy root, RUNS each (a probe is import-light so a BUILD FAILURE already 7// removed it = STILL-LIVE by construction; a runnable probe exits 0 = ROOT-FIXED), tallies, and appends ONE 8// append-only journal frame per probe so the ROOT-FIXED/STILL-LIVE state becomes a TREND (the same shape 9// nx_law_warden uses). A landmine that quietly gets fixed then shows ROOT-FIXED on the next beat -- visible, 10// zero-Claude. Retirement itself stays the documented reviewed one-liner (a registry mutation that could 11// re-introduce a trap must not be silent) -- but it is now backed by continuous runnable proof, not memory. 12// 13// SCALES BY CONSTRUCTION: a NEW landmine probe = one lmprobe_<id>.nx file; this engine finds and runs it 14// with ZERO code change. MCP-registered + schema'd (agent/API-callable); composed into a workflow via a 15// store row (nx_plan_run); cron-driven for the zero-Claude beat. 16// 17// COMPOSES the base classes (rule 15 / L010): nx_tool_run (fork+capture), nx_estr (the shared emit/itoa). 18// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 19import "nx_syscalls.nx" 20import "nx_tool_run.nx" 21import "nx_estr.nx" 22 23const LP_DIRBUF: i64 = 131072 24const LP_CAP: i64 = 65536 25const LP_NAME: i64 = 256 26const LP_ARGVB: i64 = 32 27const LP_LINE: i64 = 512 28const LP_MODE_644: i64 = 420 29const LP_TAB: i64 = 9 30const LP_LF: i64 = 10 31const LP_ROOT: *u8 = "/volume1/homes/elderwesto/nishihost/" 32const LP_JRNL: *u8 = "knowledge/status/landmine_probe.jrnl" 33 34// name starts with `pre`? 35func lp_pre(nm: *u8, pre: *u8) -> i64 { 36 var i: i64 = 0 37 while pre[i] != (0 as u8) { if nm[i] != pre[i] { return 0 } i = i + 1 } 38 return 1 39} 40// name ends with `.elf`? 41func lp_elf(nm: *u8) -> i64 { 42 var n: i64 = 0 43 while nm[n] != (0 as u8) { n = n + 1 } 44 if n < 4 { return 0 } 45 if nm[n-4] != (46 as u8) { return 0 } 46 if nm[n-3] != (101 as u8) { return 0 } 47 if nm[n-2] != (108 as u8) { return 0 } 48 if nm[n-1] != (102 as u8) { return 0 } 49 return 1 50} 51// does out[0..n) contain `needle`? (composes gg_last-style scan inline; small, one call site) 52func lp_has(buf: *u8, n: i64, needle: *u8) -> i64 { 53 var nn: i64 = 0 54 while needle[nn] != (0 as u8) { nn = nn + 1 } 55 var i: i64 = 0 56 while i + nn <= n { 57 var j: i64 = 0 58 var ok: i64 = 1 59 while j < nn { if buf[i+j] != needle[j] { ok = 0; j = nn } else { j = j + 1 } } 60 if ok == 1 { return 1 } 61 i = i + 1 62 } 63 return 0 64} 65 66// append one trend frame: <ts> TAB LANDMINE TAB <probe> TAB <ROOT-FIXED|STILL-LIVE|UNCLEAR> TAB rc=<n> 67func lp_frame(probe: *u8, verdict: *u8, rc: i64) -> i64 { 68 let fd: i64 = sys_openat_append(LP_JRNL, LP_MODE_644) 69 if fd < 0 { return 0 } 70 let ln: *u8 = sys_mmap(LP_LINE) 71 var o: i64 = es_catn(ln, 0, sys_now_realtime_sec()) 72 ln[o] = LP_TAB as u8; o = o + 1 73 o = es_cat(ln, o, "LANDMINE" as *u8) 74 ln[o] = LP_TAB as u8; o = o + 1 75 o = es_cat(ln, o, probe) 76 ln[o] = LP_TAB as u8; o = o + 1 77 o = es_cat(ln, o, verdict) 78 ln[o] = LP_TAB as u8; o = o + 1 79 o = es_cat(ln, o, "rc=" as *u8) 80 o = es_catn(ln, o, rc) 81 ln[o] = LP_LF as u8; o = o + 1 82 sys_write(fd, ln, o) 83 sys_close(fd) 84 return 0 85} 86 87func main() -> i64 { 88 es_puts("nx_landmine_probe -- standing landmine re-probe beat (seq291)\n" as *u8) 89 let fd: i64 = sys_openat_rd("." as *u8) 90 if fd < 0 { es_puts("verdict=RED (cannot open deploy root)\n" as *u8); sys_exit(1); return 1 } 91 let dbuf: *u8 = sys_mmap(LP_DIRBUF) 92 let path: *u8 = sys_mmap(LP_NAME) 93 let out: *u8 = sys_mmap(LP_CAP) 94 let outlen: *i64 = sys_mmap(16) as *i64 95 var probes: i64 = 0 96 var fixed: i64 = 0 97 var live: i64 = 0 98 var unclear: i64 = 0 99 var go: i64 = 1 100 while go == 1 { 101 let nr: i64 = sys_getdents64(fd, dbuf, LP_DIRBUF) 102 if nr <= 0 { go = 0 } else { 103 var off: i64 = 0 104 while off < nr { 105 let rec: *u8 = (dbuf as i64 + off) as *u8 106 let nm: *u8 = dirent_name(rec) 107 if lp_pre(nm, "lmprobe_" as *u8) == 1 { if lp_elf(nm) == 1 { 108 // absolute path per nx_tool_run's contract 109 var p: i64 = es_cat(path, 0, LP_ROOT) 110 p = es_cat(path, p, nm) 111 path[p] = 0 as u8 112 let argv: *i64 = sys_mmap(LP_ARGVB) as *i64 113 argv[0] = path as i64 114 argv[1] = 0 115 let rc: i64 = tr_run_capture(path, argv, out, LP_CAP, outlen) 116 let n: i64 = outlen[0] 117 probes = probes + 1 118 es_puts(" " as *u8); es_puts(nm); es_puts(" -> " as *u8) 119 if lp_has(out, n, "ROOT-FIXED" as *u8) == 1 { 120 if rc == 0 { fixed = fixed + 1; es_puts("ROOT-FIXED (retire candidate: ./nx_store_put.elf knowledge/store/landmine- put ...RETIRED-STALE)\n" as *u8); lp_frame(nm, "ROOT-FIXED" as *u8, rc) } 121 else { unclear = unclear + 1; es_puts("UNCLEAR (says ROOT-FIXED but rc!=0)\n" as *u8); lp_frame(nm, "UNCLEAR" as *u8, rc) } 122 } else { 123 if lp_has(out, n, "STILL-LIVE" as *u8) == 1 { live = live + 1; es_puts("STILL-LIVE\n" as *u8); lp_frame(nm, "STILL-LIVE" as *u8, rc) } 124 else { unclear = unclear + 1; es_puts("UNCLEAR (no verdict token)\n" as *u8); lp_frame(nm, "UNCLEAR" as *u8, rc) } 125 } 126 } } 127 off = off + dirent_reclen(rec) 128 } 129 } 130 } 131 sys_close(fd) 132 es_puts(" probes=" as *u8); es_putn(probes) 133 es_puts(" root_fixed=" as *u8); es_putn(fixed) 134 es_puts(" still_live=" as *u8); es_putn(live) 135 es_puts(" unclear=" as *u8); es_putn(unclear) 136 es_puts("\n" as *u8) 137 // envelope: coverage is WHATEVER lmprobe_*.elf exist in the deploy root; a landmine with no probe is 138 // INVISIBLE here (declared, not hidden -- L011). probes==0 is a RED: the beat found nothing to run. 139 if probes == 0 { es_puts("verdict=RED (no lmprobe_*.elf found -- coverage is zero, not clean)\n" as *u8); sys_exit(1); return 1 } 140 es_puts("verdict=GREEN (all discovered probes ran; root_fixed rows are reviewed retirement candidates)\n" as *u8) 141 sys_exit(0) 142 return 0 143}