code wiki / (root) / nx_debt_cockpit.nx

nx_debt_cockpit.nx source

↩ module page · 96 lines · 6645 B

1// nx_debt_cockpit.nx -- THE CODE-DEBT COCKPIT (nx_engineer doctrine applied to code-quality debt): ONE 2// command, sub-10s, RED/GREEN board of the debt so a fix is a 1-step tight loop (fix source -> re-run -> GREEN). 3// (Name note: `nx_debt` is the FINANCIAL amortization organ; this is the CODE-debt cockpit.) Composes the fast 4// evaluators only: 5// (1) code-review CENSUS (14 axes present + live scan discriminates) -- is the review plane itself healthy? 6// (2) the pre-commit GATE on a WATCHLIST of organs we keep debt-free -- PASS iff no blocking finding 7// (incomplete-work / non-sovereign 3rd-party-exec / mmap-leak). 8// Prints per-item CLEAN/DEBT + ms, then a board + a fix-speed clock (<10000ms = GREEN, the doctrine's bar). 9// The SLOW checks (audit tree-sweep, nishisafety compile, parallelism census) are deliberately NOT here -- they 10// are periodic, not per-fix. Sovereign (fork+exec, no shell). Run from nxc2 root. license_tier: ORIGINAL 11import "nx_syscalls.nx" 12const DEBT_MAGIC_1000000: i64 = 1000000 13 14const DEBT_BUDGET_MS: i64 = 10000 // doctrine bar: the whole loop must fit under 10 seconds 15 16func db_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 17func db_putn(v: i64) -> i64 { 18 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 19 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 20 let d: *u8 = sys_mmap(24); var k: i64 = 0 21 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 22 let o: *u8 = sys_mmap(24); var i: i64 = 0 23 while i < k { o[i] = d[k - 1 - i]; i = i + 1 } sys_write(1, o, k); return 0 24} 25func db_ms() -> i64 { let ts: *i64 = sys_mmap(16) as *i64; sys_clock_gettime_mono(ts); return ts[0] * 1000 + ts[1] / DEBT_MAGIC_1000000 } 26 27// fork+exec _offc/nx_code_review.elf [a1] [a2], muted, PATH env; return WEXITSTATUS (0 = clean). 28func db_run(a1: *u8, a2: *u8) -> i64 { 29 let pid: i64 = sys_fork() 30 if pid == 0 { 31 let dn: i64 = sys_openat_wr("/dev/null\x00" as *u8, 0x1a4) 32 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) } 33 let elf: *u8 = "_offc/nx_code_review.elf\x00" as *u8 34 let av: *i64 = sys_mmap(32) as *i64 35 av[0] = elf as i64; var ai: i64 = 1 36 if (a1 as i64) != 0 { av[ai] = a1 as i64; ai = ai + 1 } 37 if (a2 as i64) != 0 { av[ai] = a2 as i64; ai = ai + 1 } 38 av[ai] = 0 39 let envp: *i64 = sys_mmap(16) as *i64; envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 40 sys_execve(elf, av, envp) 41 sys_exit(127) 42 } 43 let st: *i64 = sys_mmap(16) as *i64 44 sys_wait4(pid, st, 0) 45 if (st[0] % 128) != 0 { return 0 - 1 } 46 return (st[0] >> 8) & 0xff 47} 48 49// one timed check row. acc[0]=total acc[1]=clean. Returns the gate exit. 50func db_check(name: *u8, a1: *u8, a2: *u8, acc: *i64) -> i64 { 51 let t: i64 = db_ms() 52 let rc: i64 = db_run(a1, a2) 53 let dt: i64 = db_ms() - t 54 db_puts(" " as *u8); db_puts(name) 55 if rc == 0 { db_puts(" [CLEAN] " as *u8); acc[1] = acc[1] + 1 } else { db_puts(" [DEBT ] " as *u8) } 56 db_putn(dt); db_puts("ms\n" as *u8) 57 acc[0] = acc[0] + 1 58 return rc 59} 60 61func main() -> i64 { 62 db_puts("=== nx_debt_cockpit -- code-debt board (1 step, sub-10s; fix source -> re-run -> GREEN) ===\n" as *u8) 63 let t0: i64 = db_ms() 64 let acc: *i64 = sys_mmap(16) as *i64; acc[0] = 0; acc[1] = 0 65 66 // (1) review-plane health: the census (14 axes present + live scan discriminates) 67 db_check("code-review census (14 axes + live scan) " as *u8, 0 as *u8, 0 as *u8, acc) 68 69 // (2) gate the WATCHLIST -- organs we keep debt-free (blocking = incomplete / non-sovereign / mmap-leak) 70 db_check("gate nx_code_review " as *u8, "gate\x00" as *u8, "runtime/nx_code_review.nx\x00" as *u8, acc) 71 db_check("gate nx_gate_run " as *u8, "gate\x00" as *u8, "runtime/nx_gate_run.nx\x00" as *u8, acc) 72 db_check("gate nx_elf_inspect " as *u8, "gate\x00" as *u8, "runtime/nx_elf_inspect.nx\x00" as *u8, acc) 73 db_check("gate nx_sovereign_deps_gate " as *u8, "gate\x00" as *u8, "runtime/nx_sovereign_deps_gate.nx\x00" as *u8, acc) 74 db_check("gate nx_parallelism_probe " as *u8, "gate\x00" as *u8, "runtime/nx_parallelism_probe.nx\x00" as *u8, acc) 75 db_check("gate nx_parallelism_census " as *u8, "gate\x00" as *u8, "runtime/nx_parallelism_census.nx\x00" as *u8, acc) 76 db_check("gate nx_seng_rdtsc_gate " as *u8, "gate\x00" as *u8, "runtime/nx_seng_rdtsc_gate.nx\x00" as *u8, acc) 77 db_check("gate nx_seng_linkqual_gate " as *u8, "gate\x00" as *u8, "runtime/nx_seng_linkqual_gate.nx\x00" as *u8, acc) 78 db_check("gate nx_engineer (migrated off the shell) " as *u8, "gate\x00" as *u8, "runtime/nx_engineer.nx\x00" as *u8, acc) 79 db_check("gate nx_codereview_tool_register " as *u8, "gate\x00" as *u8, "runtime/nx_codereview_tool_register.nx\x00" as *u8, acc) 80 db_check("gate nx_genui_tool_register " as *u8, "gate\x00" as *u8, "runtime/nx_genui_tool_register.nx\x00" as *u8, acc) 81 db_check("gate nx_swapmotion_tool_register " as *u8, "gate\x00" as *u8, "runtime/nx_swapmotion_tool_register.nx\x00" as *u8, acc) 82 db_check("gate nx_ppdemo_serial " as *u8, "gate\x00" as *u8, "runtime/nx_ppdemo_serial.nx\x00" as *u8, acc) 83 db_check("gate nx_ppdemo_forkpar " as *u8, "gate\x00" as *u8, "runtime/nx_ppdemo_forkpar.nx\x00" as *u8, acc) 84 85 let total_ms: i64 = db_ms() - t0 86 db_puts("\n BOARD: " as *u8); db_putn(acc[1]); db_puts("/" as *u8); db_putn(acc[0]); db_puts(" CLEAN. " as *u8) 87 let debt: i64 = acc[0] - acc[1] 88 if debt > 0 { db_putn(debt); db_puts(" carry DEBT -> fix the source, re-run nx_debt_cockpit (1-step loop).\n" as *u8) } else { db_puts("zero debt in the watchlist.\n" as *u8) } 89 db_puts(" fix-speed clock: " as *u8); db_putn(total_ms); db_puts("ms " as *u8) 90 if total_ms < DEBT_BUDGET_MS { db_puts("(< 10s -- doctrine bar MET: one-step + fast)\n" as *u8) } else { db_puts("(>= 10s -- SLOW: trim the watchlist)\n" as *u8) } 91 92 if debt > 0 { db_puts("NX-DEBT-COCKPIT DEBT: watchlist has fixable debt (see [DEBT] rows) -- fix + re-run\n" as *u8); sys_exit(1); return 1 } 93 if total_ms >= DEBT_BUDGET_MS { db_puts("NX-DEBT-COCKPIT SLOW: zero debt but the loop exceeded the 10s bar\n" as *u8); sys_exit(2); return 2 } 94 db_puts("NX-DEBT-COCKPIT GREEN: watchlist zero-debt + sub-10s one-step loop\n" as *u8) 95 sys_exit(0); return 0 96}