code wiki / (root) / nx_verify.nx

nx_verify.nx source

↩ module page · 351 lines · 21498 B

1// nx_verify.nx -- CONSOLIDATED Nishi-unique verification tool (per NISHI_TOOL_ARCHITECTURE: 50+ 2// organs -> 15 verb-based tools; "new capability = a VERB, not a new micro-organ"). This is the 3// nx_verify tool: ONE entry point, verbs, that ABSORBS the session's separate self-analysis organs 4// so they stop sprawling as individual stubs. Imports the canonical nx_capability_triage_core (no 5// reinvention). SUPERSEDES the standalone nx_capability_triage.nx + nx_triage_ground.nx CLIs (their 6// cores stay as libs; these two verbs are now the interface). 7// nx_verify triage [registry] -> route/wire/build/measure per capability + operator proposals 8// (anti-navel-gazing: SOTA credited ONLY on 3rd-party bench) 9// nx_verify ground [registry] -> cross-check has_organ vs DISK FACTS (gate>organ>absent); flags 10// any claim the disk can't back (DISCREPANCY) 11// Future verify verbs (claim / crossval / census / adversary) fold in HERE, not as new organs. 12// Always exit 0; journals a summary. license_tier: ORIGINAL expect_exit: 0 13import "nx_syscalls.nx" 14import "nx_capability_triage_core.nx" // tr_decide / tr_proposal / tr_parse_row / verdict names + ccz_* 15const V_MAGIC_1048576: i64 = 1048576 16const V_MAGIC_1048575: i64 = 1048575 17const V_MAGIC_65536: i64 = 65536 18const V_MAGIC_65535: i64 = 65535 19const V_MAGIC_1024: i64 = 1024 20 21func v_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 22func v_putn(v: i64) -> i64 { nxi_out(v); return 0 } 23func v_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 } 24 25// --- shared: read registry + a per-row driver (verb-specific body via mode) --- 26// print the task_class (field 0) of a line 27func v_print_task(buf: *u8, ls: i64, le: i64) -> i64 { 28 var i: i64 = ls 29 while i < le { if buf[i] == (124 as u8) { i = le } else { sys_write(1, (buf as i64 + i) as *u8, 1); i = i + 1 } } 30 return 0 31} 32// copy the idx-th '|' field of buf[ls..le) into out; returns length or -1 33func v_field(buf: *u8, ls: i64, le: i64, idx: i64, out: *u8) -> i64 { 34 var f: i64 = 0; var s: i64 = ls; var i: i64 = ls; var go: i64 = 1 35 while go == 1 { go = 0 36 if i <= le { 37 var atend: i64 = 0; if i == le { atend = 1 } 38 var atbar: i64 = 0; if i < le { if buf[i] == (124 as u8) { atbar = 1 } } 39 if atend == 1 { if f == idx { var o: i64 = 0; var k: i64 = s; while k < i { out[o]=buf[k]; o=o+1; k=k+1 } out[o]=0 as u8; return o } f = f + 1 } 40 else { if atbar == 1 { if f == idx { var o2: i64=0; var k2: i64=s; while k2<i { out[o2]=buf[k2]; o2=o2+1; k2=k2+1 } out[o2]=0 as u8; return o2 } f=f+1; s=i+1 } i=i+1; go=1 } 41 } 42 } 43 return 0 - 1 44} 45func v_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 46 47// nth (0-based) space-delimited token of buf[ls..le) parsed as an unsigned int; -1 if absent. 48func v_line_int(buf: *u8, ls: i64, le: i64, tok: i64) -> i64 { 49 var t: i64 = 0 50 var i: i64 = ls 51 // skip leading spaces 52 var go: i64 = 1 53 while go == 1 { go = 0; if i < le { if buf[i] == (32 as u8) { i = i + 1; go = 1 } } } 54 while t < tok { 55 // advance past this token 56 go = 1 57 while go == 1 { go = 0; if i < le { if buf[i] != (32 as u8) { i = i + 1; go = 1 } } } 58 go = 1 59 while go == 1 { go = 0; if i < le { if buf[i] == (32 as u8) { i = i + 1; go = 1 } } } 60 t = t + 1 61 } 62 if i >= le { return 0 - 1 } 63 let ep: *i64 = sys_mmap(16) as *i64 64 return ccz_num_at(buf, le, i, ep) 65} 66// does buf[ls..le) start with prefix (after leading ws)? 67func v_starts(buf: *u8, ls: i64, le: i64, pre: *u8) -> i64 { 68 var i: i64 = ls 69 var go: i64 = 1 70 while go == 1 { go = 0; if i < le { if buf[i] == (32 as u8) { i = i + 1; go = 1 } } } 71 var k: i64 = 0 72 while pre[k] != (0 as u8) { if i + k >= le { return 0 } if buf[i+k] != pre[k] { return 0 } k = k + 1 } 73 return 1 74} 75 76// ground helpers (inlined disk-fact grade -- mirrors cc_our_grade: gate>organ>absent) 77func v_exists(path: *u8) -> i64 { let sb: *u8 = sys_mmap(256); if sys_fstatat(path, sb) < 0 { return 0 } return 1 } 78func v_probeable(name: *u8, n: i64) -> i64 { 79 if n < 4 { return 0 } 80 if name[0] != (110 as u8) { return 0 } 81 if name[1] != (120 as u8) { return 0 } 82 if name[2] != (95 as u8) { return 0 } 83 var i: i64 = 0 84 while i < n { let c: i64 = name[i] as i64; var ok: i64 = 0; if c >= 97 { if c <= 122 { ok = 1 } } if c >= 48 { if c <= 57 { ok = 1 } } if c == 95 { ok = 1 } if ok == 0 { return 0 } i = i + 1 } 85 return 1 86} 87func v_grade(name: *u8) -> i64 { 88 let p: *u8 = sys_mmap(512); var o: i64 = 0 89 o = ccz_cat_str(p, 0, "runtime/" as *u8); o = ccz_cat_str(p, o, name); o = ccz_cat_str(p, o, "_gate.nx" as *u8) 90 if v_exists(p) == 1 { return 4 } 91 o = ccz_cat_str(p, 0, "runtime/" as *u8); o = ccz_cat_str(p, o, name); o = ccz_cat_str(p, o, ".nx" as *u8) 92 if v_exists(p) == 1 { return 3 } 93 o = ccz_cat_str(p, 0, "runtime/" as *u8); o = ccz_cat_str(p, o, name); o = ccz_cat_str(p, o, "_core.nx" as *u8) 94 if v_exists(p) == 1 { return 3 } 95 return 0 96} 97 98// --- magic-number detector (rule-11 enforcement). Builds on the team's mask-51 predicate + adds the 99// ALLOWLIST the nx_magicnum_preventer header names as the "next rung": a numeric literal is a MAGIC 100// number unless it is on a const-line, part of an identifier, hex (0x), a cast (`N as T`), or a 101// mmap/syscall argument (buffer size / syscall number). Budget is a NAMED const (no magic threshold). 102const V_MAGIC_BUDGET: i64 = 0 // zero-tolerance default for a checked file/diff 103const V_DATA_DENS_X100: i64 = 80 // >=0.8 magic/line = a data table (bias/mesh/font/KAT), not logic -> EXEMPT 104const V_DATA_MIN_CNT: i64 = 50 // ...AND has many literals: floors out line-packed logic one-liners gaming density 105const V_DENS_SCALE: i64 = 100 // density is reported x100 (fixed-point, no floats) 106const V_RADIX10_LEN: i64 = 2 // "10" is two chars (the radix-extraction allowlist match) 107const V_ASCII_NL: i64 = 10 108const V_ASCII_SP: i64 = 32 109const V_ASCII_LP: i64 = 40 // '(' 110const V_ASCII_0: i64 = 48 111const V_ASCII_1: i64 = 49 112const V_ASCII_2: i64 = 50 113const V_ASCII_9: i64 = 57 114const V_ASCII_x: i64 = 120 115const V_ASCII_PCT: i64 = 37 // '%' 116const V_ASCII_SLASH: i64 = 47 // '/' 117const V_ASCII_DQ: i64 = 34 // '"' string delimiter -- numbers inside strings are text, not magic (skip like comments) 118const V_ASCII_BS: i64 = 92 // '\' escape -- an escaped quote does not close the string 119 120func v_isdig(c: u8) -> i64 { if c >= (V_ASCII_0 as u8) { if c <= (V_ASCII_9 as u8) { return 1 } } return 0 } 121func v_isaln(c: u8) -> i64 { 122 if c >= (V_ASCII_0 as u8) { if c <= (V_ASCII_9 as u8) { return 1 } } 123 if c >= (65 as u8) { if c <= (90 as u8) { return 1 } } 124 if c >= (97 as u8) { if c <= (122 as u8) { return 1 } } 125 if c == (95 as u8) { return 1 } 126 return 0 127} 128func v_matchat(buf: *u8, i: i64, n: i64, lit: *u8) -> i64 { var k: i64 = 0; while lit[k] != (0 as u8) { if i + k >= n { return 0 } if buf[i+k] != lit[k] { return 0 } k = k + 1 } return 1 } 129func v_scan_magic(buf: *u8, n: i64) -> i64 { 130 var count: i64 = 0; var i: i64 = 0; var incomm: i64 = 0; var lconst: i64 = 0; var instr: i64 = 0 131 while i < n { 132 let c: u8 = buf[i] 133 if c == (V_ASCII_NL as u8) { incomm = 0; lconst = 0; instr = 0; i = i + 1 } else { 134 if incomm == 1 { i = i + 1 } else { 135 if instr == 1 { 136 if c == (V_ASCII_DQ as u8) { var esc: i64 = 0; if i > 0 { if buf[i-1] == (V_ASCII_BS as u8) { esc = 1 } } if esc == 0 { instr = 0 } } 137 i = i + 1 138 } else { 139 if c == (V_ASCII_DQ as u8) { instr = 1; i = i + 1 } else { 140 if v_matchat(buf, i, n, "//" as *u8) == 1 { incomm = 1; i = i + 2 } else { 141 if v_matchat(buf, i, n, "const " as *u8) == 1 { lconst = 1; i = i + 6 } else { 142 if v_isdig(c) == 1 { 143 var prevaln: i64 = 0 144 if i > 0 { if v_isaln(buf[i-1]) == 1 { prevaln = 1 } } 145 var ishex: i64 = 0 146 if i >= 2 { if buf[i-1] == (V_ASCII_x as u8) { if buf[i-2] == (V_ASCII_0 as u8) { ishex = 1 } } } 147 let start: i64 = i 148 var go: i64 = 1 149 while go == 1 { go = 0; if i < n { if v_isdig(buf[i]) == 1 { i = i + 1; go = 1 } } } 150 let runlen: i64 = i - start 151 var v2: i64 = 0 152 if runlen >= 2 { v2 = 1 } else { if buf[start] >= (V_ASCII_2 as u8) { v2 = 1 } } 153 var j: i64 = i 154 var g2: i64 = 1 155 while g2 == 1 { g2 = 0; if j < n { if buf[j] == (V_ASCII_SP as u8) { j = j + 1; g2 = 1 } } } 156 var castnext: i64 = 0 157 if v_matchat(buf, j, n, "as " as *u8) == 1 { castnext = 1 } 158 var argctx: i64 = 0 159 if start >= 1 { if buf[start-1] == (V_ASCII_LP as u8) { 160 if start >= 5 { if v_matchat(buf, start-5, n, "mmap(" as *u8) == 1 { argctx = 1 } } 161 if start >= 8 { if v_matchat(buf, start-8, n, "syscall(" as *u8) == 1 { argctx = 1 } } 162 } } 163 // radix-10: `% 10` / `/ 10` is decimal-string conversion (structural radix, not a tunable 164 // threshold). allowlisting it keeps the gate from crying wolf on every putn -- a noisy gate 165 // gets disabled, which is exactly how the original preventer ended up off. 166 var radix10: i64 = 0 167 if runlen == V_RADIX10_LEN { if buf[start] == (V_ASCII_1 as u8) { if buf[start+1] == (V_ASCII_0 as u8) { 168 var p: i64 = start - 1 169 var gp: i64 = 1 170 while gp == 1 { gp = 0; if p >= 0 { if buf[p] == (V_ASCII_SP as u8) { p = p - 1; gp = 1 } } } 171 if p >= 0 { if buf[p] == (V_ASCII_PCT as u8) { radix10 = 1 } } 172 if p >= 0 { if buf[p] == (V_ASCII_SLASH as u8) { radix10 = 1 } } 173 } } } 174 var magic: i64 = 1 175 if lconst == 1 { magic = 0 } 176 if prevaln == 1 { magic = 0 } 177 if ishex == 1 { magic = 0 } 178 if castnext == 1 { magic = 0 } 179 if argctx == 1 { magic = 0 } 180 if radix10 == 1 { magic = 0 } 181 if v2 == 0 { magic = 0 } 182 if magic == 1 { count = count + 1 } 183 } else { i = i + 1 } } } } } } } 184 } 185 return count 186} 187 188func main(argc: i64, argv: *i64) -> i64 { 189 if argc < 2 { v_puts("usage: nx_verify triage|ground|lap|magic [args]\n" as *u8); return 2 } 190 let verb: *u8 = argv[1] as *u8 191 var reg: *u8 = "knowledge/capability_triage.reg" as *u8 192 // only triage/ground take an optional registry as argv[2]; for `lap`, argv[2] is the TARGET 193 if argc >= 3 { if v_streq(verb, "triage" as *u8) == 1 { reg = argv[2] as *u8 } if v_streq(verb, "ground" as *u8) == 1 { reg = argv[2] as *u8 } } 194 195 // magic: rule-11 gate. dispatched BEFORE the registry read -- it needs no registry and must run from 196 // ANY cwd (the pre-commit ratchet / build lane call it on arbitrary files). exit 1 = enforcement. 197 if v_streq(verb, "magic" as *u8) == 1 { 198 if argc < 3 { v_puts("usage: nx_verify magic <file> [budget]\n" as *u8); return 2 } 199 let mfile: *u8 = argv[2] as *u8 200 var mbudget: i64 = V_MAGIC_BUDGET 201 if argc >= 4 { let ep2: *i64 = sys_mmap(16) as *i64; let b: i64 = ccz_num_at(argv[3] as *u8, v_slen(argv[3] as *u8), 0, ep2); if b >= 0 { mbudget = b } } 202 let mbuf: *u8 = sys_mmap(V_MAGIC_1048576) 203 let mn: i64 = ccz_read(mfile, mbuf, V_MAGIC_1048575) 204 if mn <= 0 { v_puts("nx_verify magic: cannot read " as *u8); v_puts(mfile); v_puts("\n" as *u8); return 0 } 205 let cnt: i64 = v_scan_magic(mbuf, mn) 206 var lines: i64 = 1 207 var li: i64 = 0 208 while li < mn { if mbuf[li] == (V_ASCII_NL as u8) { lines = lines + 1 } li = li + 1 } 209 var dens: i64 = 0 210 if lines > 0 { dens = (cnt * V_DENS_SCALE) / lines } 211 var isdata: i64 = 0 212 if dens >= V_DATA_DENS_X100 { if cnt >= V_DATA_MIN_CNT { isdata = 1 } } 213 v_puts("VERIFY-MAGIC file=" as *u8); v_puts(mfile); v_puts(" magic_numbers=" as *u8); v_putn(cnt); v_puts(" lines=" as *u8); v_putn(lines); v_puts(" dens_x100=" as *u8); v_putn(dens); v_puts(" budget=" as *u8); v_putn(mbudget); v_puts(" -> " as *u8) 214 if isdata == 1 { v_puts("EXEMPT (data table, not logic thresholds)\n" as *u8); return 0 } 215 if cnt <= mbudget { v_puts("PASS (rule-11 clean)\n" as *u8); return 0 } 216 v_puts("FAIL (move each to a named const)\n" as *u8) 217 return 1 218 } 219 220 let buf: *u8 = sys_mmap(V_MAGIC_65536) 221 let n: i64 = ccz_read(reg, buf, V_MAGIC_65535) 222 if n <= 0 { v_puts("nx_verify no-registry\n" as *u8); return 0 } 223 224 let out5: *i64 = sys_mmap(64) as *i64 225 let organ: *u8 = sys_mmap(128) 226 let hstr: *u8 = sys_mmap(32) 227 let ep: *i64 = sys_mmap(16) as *i64 228 229 if v_streq(verb, "triage" as *u8) == 1 { 230 let cnt: *i64 = sys_mmap(80) as *i64 231 var k: i64 = 0; while k < 7 { cnt[k] = 0; k = k + 1 } 232 var rows: i64 = 0; var raises: i64 = 0 233 var ls: i64 = 0 234 while ls < n { 235 var le: i64 = ls; var go: i64 = 1 236 while go == 1 { go = 0; if le < n { if buf[le] != (10 as u8) { le = le + 1; go = 1 } } } 237 var i: i64 = ls; go = 1 238 while go == 1 { go = 0; if i < le { let c: i64 = buf[i] as i64; if c == 32 { i = i + 1; go = 1 } else { if c == 9 { i = i + 1; go = 1 } } } } 239 var skip: i64 = 0; if i >= le { skip = 1 } if skip == 0 { if buf[i] == (35 as u8) { skip = 1 } } 240 if skip == 0 { if tr_parse_row(buf, ls, le, out5) == 1 { 241 let v: i64 = tr_decide(out5[0], out5[1], out5[2], out5[3]) 242 let prop: i64 = tr_proposal(v, out5[4]) 243 cnt[v] = cnt[v] + 1; rows = rows + 1; if prop == 1 { raises = raises + 1 } 244 v_puts("VERIFY-TRIAGE " as *u8); v_print_task(buf, ls, le); v_puts(" -> " as *u8); v_puts(tr_verdict_name(v)) 245 if tr_routes_to_nishi(v) == 1 { v_puts(" [Nishi handles]" as *u8) } else { v_puts(" [GAP]" as *u8) } 246 if prop == 1 { v_puts(" ***PROPOSE-INVESTMENT***" as *u8) } 247 v_puts("\n" as *u8) 248 } } 249 ls = le + 1 250 } 251 v_puts("VERIFY-TRIAGE-SUM rows=" as *u8); v_putn(rows) 252 v_puts(" ROUTE=" as *u8); v_putn(cnt[5]); v_puts(" USE_IMPROVE=" as *u8); v_putn(cnt[4]) 253 v_puts(" MEASURE=" as *u8); v_putn(cnt[3]); v_puts(" WIRE=" as *u8); v_putn(cnt[2]) 254 v_puts(" BUILD=" as *u8); v_putn(cnt[1]); v_puts(" SUSPECT=" as *u8); v_putn(cnt[6]) 255 v_puts(" PROPOSALS=" as *u8); v_putn(raises); v_puts("\n" as *u8) 256 return 0 257 } 258 if v_streq(verb, "ground" as *u8) == 1 { 259 var rows: i64 = 0; var grounded: i64 = 0; var discrep: i64 = 0; var unprob: i64 = 0 260 var ls: i64 = 0 261 while ls < n { 262 var le: i64 = ls; var go: i64 = 1 263 while go == 1 { go = 0; if le < n { if buf[le] != (10 as u8) { le = le + 1; go = 1 } } } 264 var i: i64 = ls; go = 1 265 while go == 1 { go = 0; if i < le { let c: i64 = buf[i] as i64; if c == 32 { i = i + 1; go = 1 } else { if c == 9 { i = i + 1; go = 1 } } } } 266 var skip: i64 = 0; if i >= le { skip = 1 } if skip == 0 { if buf[i] == (35 as u8) { skip = 1 } } 267 if skip == 0 { if v_field(buf, ls, le, 1, organ) >= 0 { if v_field(buf, ls, le, 2, hstr) >= 0 { 268 let claimed: i64 = ccz_num_at(hstr, v_slen(hstr), 0, ep) 269 let prob: i64 = v_probeable(organ, v_slen(organ)) 270 var grade: i64 = 0; if prob == 1 { grade = v_grade(organ) } 271 var present: i64 = 0; if grade >= 3 { present = 1 } 272 rows = rows + 1 273 var verd: *u8 = "GROUNDED" as *u8 274 if prob == 0 { verd = "UNPROBEABLE" as *u8; unprob = unprob + 1 } else { 275 if claimed == 1 { if present == 1 { grounded = grounded + 1 } else { verd = "DISCREPANCY(claim>disk)" as *u8; discrep = discrep + 1 } } else { grounded = grounded + 1 } 276 } 277 v_puts("VERIFY-GROUND " as *u8); v_puts(organ); v_puts(" claim=" as *u8); v_putn(claimed); v_puts(" disk=" as *u8); v_putn(grade); v_puts(" -> " as *u8); v_puts(verd); v_puts("\n" as *u8) 278 } } } 279 ls = le + 1 280 } 281 v_puts("VERIFY-GROUND-SUM rows=" as *u8); v_putn(rows); v_puts(" grounded=" as *u8); v_putn(grounded); v_puts(" DISCREPANCY=" as *u8); v_putn(discrep); v_puts(" unprobeable=" as *u8); v_putn(unprob); v_puts("\n" as *u8) 282 return 0 283 } 284 // --- lap: the RACING-CREW loop. grade a target's progress toward SOTA across deploy laps --- 285 // ledger knowledge/lap-<target>.ledger: "SOTA <val> <dir 0=lower-better|1=higher-better>" + "LAP <val> <note>". 286 // nx_verify lap <target> -> where-was / where-is / where-to-go + verdict 287 // nx_verify lap <target> record <val> .. -> append a lap after a deploy 288 if v_streq(verb, "lap" as *u8) == 1 { 289 if argc < 3 { v_puts("usage: nx_verify lap <target> [record <val> <note>]\n" as *u8); return 2 } 290 let target: *u8 = argv[2] as *u8 291 let lp: *u8 = sys_mmap(V_MAGIC_1024); var lo: i64 = 0 292 lo = ccz_cat_str(lp, 0, "knowledge/lap-" as *u8); lo = ccz_cat_str(lp, lo, target); lo = ccz_cat_str(lp, lo, ".ledger" as *u8) 293 // NOTE: reg buf `n` above was for the triage registry; re-read the ledger here. 294 let lbuf: *u8 = sys_mmap(V_MAGIC_65536) 295 let ln: i64 = ccz_read(lp, lbuf, V_MAGIC_65535) 296 if argc >= 5 { if v_streq(argv[3] as *u8, "record" as *u8) == 1 { 297 let rec: *u8 = sys_mmap(V_MAGIC_1024); var ro: i64 = 0 298 ro = ccz_cat_str(rec, 0, "LAP " as *u8); ro = ccz_cat_str(rec, ro, argv[4] as *u8) 299 var a: i64 = 5; while a < argc { ro = ccz_cat_str(rec, ro, " " as *u8); ro = ccz_cat_str(rec, ro, argv[a] as *u8); a = a + 1 } 300 ro = ccz_cat_str(rec, ro, "\n" as *u8) 301 let fd: i64 = sys_openat_append(lp, 420) 302 if fd < 0 { v_puts("lap: cannot open ledger\n" as *u8); return 1 } 303 sys_write(fd, rec, ro); sys_close(fd) 304 v_puts("nx_verify lap: recorded -> " as *u8); v_puts(target); v_puts(" = " as *u8); v_puts(argv[4] as *u8); v_puts("\n" as *u8) 305 return 0 306 } } 307 if ln <= 0 { v_puts("nx_verify lap: no ledger for " as *u8); v_puts(target); v_puts(" (record the first lap)\n" as *u8); return 0 } 308 // parse SOTA + laps 309 var sota: i64 = 0 - 1; var dir: i64 = 0 310 let vals: *i64 = sys_mmap(8*512) as *i64 311 var nl: i64 = 0 312 var ls: i64 = 0 313 while ls < ln { 314 var le: i64 = ls; var go: i64 = 1 315 while go == 1 { go = 0; if le < ln { if lbuf[le] != (10 as u8) { le = le + 1; go = 1 } } } 316 if v_starts(lbuf, ls, le, "SOTA" as *u8) == 1 { sota = v_line_int(lbuf, ls, le, 1); let d: i64 = v_line_int(lbuf, ls, le, 2); if d >= 0 { dir = d } } 317 else { if v_starts(lbuf, ls, le, "LAP" as *u8) == 1 { let vv: i64 = v_line_int(lbuf, ls, le, 1); if vv >= 0 { if nl < 512 { vals[nl] = vv; nl = nl + 1 } } } } 318 ls = le + 1 319 } 320 if nl == 0 { v_puts("nx_verify lap: ledger has no LAP rows\n" as *u8); return 0 } 321 let first: i64 = vals[0] 322 let last: i64 = vals[nl-1] 323 var prev: i64 = last; if nl >= 2 { prev = vals[nl-2] } 324 v_puts("=== RACING-CREW LAP REPORT: " as *u8); v_puts(target); v_puts(" (laps=" as *u8); v_putn(nl) 325 if dir == 0 { v_puts(", lower=better" as *u8) } else { v_puts(", higher=better" as *u8) } 326 v_puts(") ===\n" as *u8) 327 v_puts(" WHERE-IT-WAS (lap " as *u8); v_putn(nl-1); v_puts("): " as *u8); v_putn(prev); v_puts("\n" as *u8) 328 v_puts(" WHERE-IT-IS (lap " as *u8); v_putn(nl); v_puts("): " as *u8); v_putn(last) 329 let delta: i64 = last - prev 330 var improving: i64 = 0 331 if dir == 0 { if delta < 0 { improving = 1 } } else { if delta > 0 { improving = 1 } } 332 v_puts(" [delta " as *u8); v_putn(delta); if improving == 1 { v_puts(" IMPROVING]" as *u8) } else { if delta == 0 { v_puts(" HELD]" as *u8) } else { v_puts(" REGRESSED]" as *u8) } } 333 v_puts("\n" as *u8) 334 v_puts(" WHERE-TO-GO (SOTA): " as *u8); v_putn(sota) 335 var gap: i64 = last - sota; if dir == 1 { gap = sota - last } 336 v_puts(" [gap " as *u8); v_putn(gap) 337 var atsota: i64 = 0 338 if dir == 0 { if last <= sota { atsota = 1 } } else { if last >= sota { atsota = 1 } } 339 v_puts("]\n" as *u8) 340 // progress permille of the original gap closed 341 var span: i64 = first - sota; if dir == 1 { span = sota - first } 342 if span > 0 { var closed: i64 = span - gap; if closed < 0 { closed = 0 } 343 v_puts(" PROGRESS: " as *u8); v_putn(closed * 1000 / span); v_puts("/1000 of the original gap closed since lap 1\n" as *u8) } 344 v_puts(" VERDICT: " as *u8) 345 if atsota == 1 { v_puts("AT-OR-BEYOND-SOTA (podium)\n" as *u8) } else { if improving == 1 { v_puts("APPROACHING-SOTA (converging -- attack the largest remaining gap next lap)\n" as *u8) } else { v_puts("STALLED/REGRESSED (change the lever -- re-run census+adversary for new information)\n" as *u8) } } 346 return 0 347 } 348 349 v_puts("usage: nx_verify triage|ground|lap|magic [args]\n" as *u8) 350 return 2 351}