code wiki / (root) / nx_codereview_tool_register.nx

nx_codereview_tool_register.nx source

↩ module page · 93 lines · 10240 B

1// nx_codereview_tool_register.nx -- register the AUTOMATED CODE REVIEW capabilities into the sovereign tool 2// registry (operator 2026-07-06: "get this all integrated with our apis and mcp ... so when we use llms they 3// dont write garbage and also so we can audit whats already written to see if we can get it to SOTA"). The 4// registry IS what /api/tools + /mcp tools/list serve, so registration = discoverability for ANY engaging model 5// (Claude, the Nishi team agents, or an external orchestrator): they SEE that a review coordinator, a 6// pre-commit gate, an ecosystem audit, and the standards contract exist, and how to call them. 7// 8// DISCOVERY only (mirrors nx_genui_tool_register): making a tool RUNNABLE over /mcp stays a SEPARATE fail-closed 9// step (tool_allowlist.conf + cap token, operator-gated) -- so no LLM can be tricked into executing arbitrary 10// tools. This writes the LOCAL SSOT registry (knowledge/toolreg-); flipping the LIVE NAS registry behind 11// nishifamily.com/api/tools is a deploy step (operator-gated). Idempotent (reg_put additive, history kept). 12// Verifies by READBACK, not by claim (prove-not-assert). expect_exit: 0 license_tier: ORIGINAL 13import "nx_tool_registry.nx" 14 15func cr_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 16func cr_putn(v: i64) -> i64 { 17 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 18 var m: i64 = v 19 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 // buffer HOISTED out of the loop + written once -- was a per-char sys_mmap(1) inside the while (the 23 // RESOURCE_WASTE mmap-in-loop leak my OWN gate caught here; the leaky form came from the register template). 24 let o: *u8 = sys_mmap(24); var i: i64 = 0 25 while i < k { o[i] = d[k - 1 - i]; i = i + 1 } 26 sys_write(1, o, k) 27 return 0 28} 29 30// register one tool + read it back (prove-not-assert): registration counts only if tool_get returns it. 31func cr_reg1(name: *u8, desc: *u8, invoke: *u8, status: *u8) -> i64 { 32 let w: i64 = tool_register(name, desc, invoke, status) 33 let p: *i64 = sys_mmap(8) as *i64 34 let l: *i64 = sys_mmap(8) as *i64 35 let g: i64 = tool_get(name, p, l) 36 cr_puts(" " as *u8); cr_puts(name); cr_puts(" put-rc=" as *u8); cr_putn(w); cr_puts(" readback=" as *u8) 37 if g == 1 { if l[0] > 0 { cr_puts("OK len=" as *u8); cr_putn(l[0]); cr_puts("\n" as *u8); return 1 } } 38 cr_puts("MISSING -- REGISTER FAILED\n" as *u8) 39 return 0 40} 41 42func main() -> i64 { 43 cr_puts("=== nx_codereview_tool_register -- automated code review into the discovery registry (knowledge/toolreg-) ===\n" as *u8) 44 var ok: i64 = 0 45 ok = ok + cr_reg1("code_review" as *u8, 46 "sovereign automated code review coordinator: maps 12 axes -- 11 industry (linting/static-analysis, conventions/maintainability, defects, security+secret SAST, architecture-constraints, magic-numbers, evidence-not-assertion, license/provenance, CI-gate, cadence) + 1 Nishi-specific (NishiLang COMPILE-SAFETY = the differential/EMI oracle that catches silent miscompiles static lint cannot) -- to REAL Nishi organs opened on disk (prove-not-assert) and live-runs a discriminating scan (dirty trips findings, clean scores 0)" as *u8, 47 "nx_code_review (census + EVAL-COORD coverage=CODE-REVIEW); over /mcp: tools/call name=code_review" as *u8, 48 "GREEN (self-gating; 12/12 axes present; live scan discriminates; liar-killed; wired into team-pulse cadence)" as *u8) 49 ok = ok + cr_reg1("code_review_gate" as *u8, 50 "pre-commit code-review chokepoint so an LLM or build lane CANNOT ship garbage: reviews each file and BLOCKS (nonzero exit) on INCOMPLETE-work + non-SOVEREIGN 3rd-party-exec + RESOURCE-WASTE mmap-leak findings; magic-numbers reported as ADVISORY (often legit RFC consts)" as *u8, 51 "nx_code_review gate <file>... (exit 1 = reject the submission); over /mcp: tools/call name=code_review_gate args={files}" as *u8, 52 "GREEN (dirty control RED / clean + self-dogfood GREEN; exit-code enforced)" as *u8) 53 ok = ok + cr_reg1("code_review_audit" as *u8, 54 "ecosystem code-review SOTA scorecard: sweeps a directory via the installed scanner, reports SOVEREIGNTY + RESOURCE-WASTE candidate counts, a CONSERVATIVE clean-floor permille, and per-file worklists for owner routing -- the 'audit what is already written, drive it to SOTA' surface" as *u8, 55 "nx_code_review audit [dir] (default runtime); over /mcp: tools/call name=code_review_audit args={dir}" as *u8, 56 "GREEN (runtime: 9508 files, clean-floor 941 permille; mechanical = high-recall candidate generator, semantic tier confirms)" as *u8) 57 ok = ok + cr_reg1("code_review_nishisafety" as *u8, 58 "live NishiLang compile-safety check (SOTA for the nishi language): runs the differential witness nx_cc_health -- generates a 1000-function program, compiles it with nx_cc, runs it, verifies correctness -- so silent MISCOMPILES (code that looks fine but the compiler mistranslates = the worst garbage) are caught. Static lint provably cannot do this (the documented footguns do not reproduce statically); compile-CORRECTNESS is a differential problem" as *u8, 59 "nx_code_review nishisafety (exit 1 = compiler regression, do not ship NishiLang); over /mcp: tools/call name=code_review_nishisafety" as *u8, 60 "GREEN (nx_cc healthy at 1000-function scale; axis 12 rung-4 EXECUTING)" as *u8) 61 ok = ok + cr_reg1("gate_run" as *u8, 62 "sovereign gate-runner: build an organ through the sovereign lane (nx_sov_build_run) + run it + check its output, with NO shell -- retires the simple bench/gate_*.sh build+run+grep pattern (the agent-sovereignty debt where nx_engineer runs 7 gate scripts via a shell). Reproduces the doctor/eqsat/alu gate verdicts sovereignly" as *u8, 63 "nx_gate_run <organ> [expect-substring] (exit 0 = pass); over /mcp: tools/call name=gate_run" as *u8, 64 "GREEN (reproduces doctor/eqsat/alu-netlist gate verdicts + neg-control fails)" as *u8) 65 ok = ok + cr_reg1("elf_inspect" as *u8, 66 "sovereign ELF inspector: is a shipped binary truly sovereign = statically linked with 0 dynamic dependencies? Parses ELF program headers for an interpreter (PT_INTERP) + shared-lib entries (DT_NEEDED) with NO file/readelf shell tools -- the BINARY-level sovereignty check (source-scan proves no lib references; this proves the artifact has no lib dependencies)" as *u8, 67 "nx_elf_inspect <file> (exit 0 = STATIC/sovereign, 1 = DYNAMIC); over /mcp: tools/call name=elf_inspect" as *u8, 68 "GREEN (verified vs the readelf oracle: nishi organ STATIC / glibc binary DYNAMIC)" as *u8) 69 ok = ok + cr_reg1("parallelism_probe" as *u8, 70 "the CODEC-CATCH: measure whether a program actually uses multiple cores, so a silently single-threaded compute hot path (the wasted-months-on-a-serial-codec failure) is caught in seconds. Runs the target + reads CPU-time/wall-time (effective cores used) straight from wait4 rusage; verdict single-threaded / under-utilizing / fully-parallel vs the core count. No perf/top/shell" as *u8, 71 "nx_parallelism_probe <elf> [args] (read the EFFECTIVE-CORES line + verdict); over /mcp: tools/call name=parallelism_probe" as *u8, 72 "GREEN (verified: serial workload = 1.00 -> SINGLE-THREADED). NOTE: ecosystem thread-parallelism toolchain-blocked (3 layers); fork process-parallelism works 8x" as *u8) 73 ok = ok + cr_reg1("debt_cockpit" as *u8, 74 "the CODE-DEBT cockpit (nx_engineer doctrine for code quality): ONE command, sub-10s, RED/GREEN board of the debt across a watchlist of organs + the review-plane census -- so a fix is a 1-step tight loop (fix source -> re-run -> GREEN). Fast checks only; the slow audit/nishisafety/parallelism-census are periodic, not per-fix" as *u8, 75 "nx_debt_cockpit (read the BOARD + fix-speed clock); over /mcp: tools/call name=debt_cockpit" as *u8, 76 "GREEN (15/15 watchlist CLEAN, whole loop ~90ms << the 10s bar)" as *u8) 77 ok = ok + cr_reg1("fix_putn" as *u8, 78 "AUTO-FIXER that EATS the propagating leaky-putn anti-pattern (per-char sys_mmap(1) in a digit-print loop = a mmap-in-loop leak). BYTE-EXACT replace with the hoisted write-once form (a non-matching variant is left untouched, never a fuzzy edit). Single-file or sweep-a-dir" as *u8, 79 "nx_fix_putn <file> | nx_fix_putn sweep <dir>; over /mcp: tools/call name=fix_putn" as *u8, 80 "GREEN (swept runtime/: FIXED 144 organs in one command, all verified-building, leak eliminated)" as *u8) 81 ok = ok + cr_reg1("standards_contract" as *u8, 82 "the model-independent engagement contract: 10 core Nishi laws as DATA (prove-not-assert, evidence-not-assertion, the-critic-decides, existence-vs-liveness, serving-vs-working, no-resource-waste, sovereign-only, high-blast-needs-council, green-only-exec, nothing-ships-past-RED) EACH naming the sovereign organ that mechanically enforces it -- so any engaging LLM receives the rules AND the enforcer up front, not just prose" as *u8, 83 "nx_standards_contract (emits knowledge/standards_contract.txt); over /mcp: a 'standards' tool surfaced at session start" as *u8, 84 "GREEN (10/10 laws backed by a live enforcer organ; liar-killed; dogfood-clean)" as *u8) 85 86 cr_puts("registered+readback " as *u8); cr_putn(ok); cr_puts(" / 10\n" as *u8) 87 cr_puts("NOTE: LOCAL SSOT registry (knowledge/toolreg-). The LIVE NAS registry behind nishifamily.com/api/tools is a\n" as *u8) 88 cr_puts(" separate store -- flipping it live = a deploy step (operator-gated), as is any tool_allowlist.conf row that\n" as *u8) 89 cr_puts(" would make code_review_gate RUNNABLE over /mcp (fail-closed today = an LLM can DISCOVER but not auto-EXEC).\n" as *u8) 90 if ok == 10 { cr_puts("verdict=GREEN (10 code-review + sovereignty + resource + debt capabilities discoverable; gate + audit + NishiLang-compile-safety + gate-runner + ELF-inspector + parallelism codec-catch + debt-cockpit + putn-auto-fixer in the tool surface)\n" as *u8); sys_exit(0); return 0 } 91 cr_puts("verdict=RED\n" as *u8) 92 sys_exit(1); return 1 93}