code wiki / _hdl_build / nx_patch_guard.nx

nx_patch_guard.nx

buildroot/runtime/_hdl_build/nx_patch_guard.nx

7956 B176 linesdepth 5pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_patch_guard.nx -- F803 THE PATCH-CASCADE STRUCTURAL TOOTH (ecosystem-as-editor law, operator 2026-07-20). Mechanizes CLAUDE rule-3: "if the second fix does not resolve it, STOP patching -- rewrite the function or module from scratch with a clear understanding of the root cause." Patch-cascade was the editor coverage board's LAST original GAP: a known failure mode of EVERY model (keep poking at a symptom, each patch obscuring intent and adding regression traps) that was covered by process law ALONE -- no structural tooth. This is the READ-ONLY verdict organ over the patch-ledger plane knowledge/store/patchledger- (seats append rows via nx_store_put; SAME division as nx_debt_view over debt- and nx_route_diff over the live API: the plane is data, the organ is the verdict). A seat calls `check <target>` BEFORE its next fix; N consecutive patch-rows on that target since the last rewrite|gate row = REFUSE -> rewrite now. nx_patch_guard check <target> [plane-prefix] -> VERDICT=OK (exit 0) | VERDICT=REFUSE (exit 3) LEDGER ROW (appended via nx_store_put <prefix> put <actor> <id> <target> <kind> <session> <note>): col0 id | col1 target | col2 kind (config|patch|rewrite|gate) | col3 session | col4 note CONFIG row: id=0 target=__config__ kind=config note=<max-consecutive-patches integer> (rule-11: the threshold is DATA, never a magic number in code; absent/unreadable config -> PG_DEFMAX, fail-safe). A rewrite|gate row RESETS the counter -- that is the rule-3 escape hatch made mechanical: prove the rewrite (or a GREEN gate) and the guard opens again. Enforcement-wiring into the nx_ws_cycle debt-gate = filed rung. ENVELOPE (declared in output): 256KB plane read, 4096 rows scanned, 6 cols. Fixture gates prove correctness NEVER scale -- the scale tooth lives in the gate plan (ark v1 lesson). license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 2 imports · 0 importers

nx_store_seed_lib.nx nx_syscalls.nx nx_patch_guard.nx

imports: nx_store_seed_lib.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main pg_werr sys_write pg_slen sys_exit sys_mmap sts_load ss_open_cached ssc_init sys_mmap ↻ ssc_sig_of ss_cat sys_fstatat ssc_streq ss_open ss_open2 sys_mmap ↻ ss_manifest_dyn ss_manifest_file_dyn ss_cat ↻ ss_loadfile sys_map_file ss_readall ss_load_aux2 sys_mmap ↻ ss_cat ↻ ss_loadfile ↻ ss_r32 sys_munmap ssl_total_keys ss_r32 ↻ ssl_pow2 ssl_build ss_r32 ↻ ssl_hash_entry ssl_key_eq ss_r32 ↻ ssl_lookup ssl_hash_entry ↻ ssl_key_eq ↻

structs

none

consts

23const PG_PREFIX: *u8 = "knowledge/store/patchledger-" as *u8
24const PG_PLANECAP: i64 = 262144
25const PG_SLACK: i64 = 4096
26const PG_NL: i64 = 10
27const PG_TAB: i64 = 9
28const PG_NCOLMAX: i64 = 8
29const PG_PAIR: i64 = 2
30const PG_SPB: i64 = 128
31const PG_MAXROWS: i64 = 4096
32const PG_DEFMAX: i64 = 2
33const PG_OUTCAP: i64 = 4096
34const PG_STDOUT: i64 = 1
35const PG_STDERR: i64 = 2
36const PG_C_TARGET: i64 = 1
37const PG_C_KIND: i64 = 2
38const PG_C_NOTE: i64 = 4
39const PG_NCOL: i64 = 5
40const PG_EXIT_USAGE: i64 = 2
41const PG_EXIT_REFUSE: i64 = 3
42const PG_ZERO: i64 = 48
43const PG_NINE: i64 = 57

functions

45func pg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 2: pg_werrpg_span_is
46func pg_werr(s: *u8) -> i64 { sys_write(PG_STDERR, s, pg_slen(s)); return 0 }
called by 1: main calls 2: sys_writepg_slen
47func pg_puts(b: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var j: i64 = 0; while s[j] != (0 as u8) { b[o] = s[j]; o = o + 1; j = j + 1 } return o }
called by 1: main
48func pg_putsl(b: *u8, off: i64, q: *u8, a: i64, e: i64) -> i64 { var o: i64 = off; var i: i64 = a; while i < e { b[o] = q[i]; o = o + 1; i = i + 1 } return o }
49func pg_puti(b: *u8, off: i64, v: i64) -> i64
called by 1: main calls 1: sys_mmap
61func pg_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64
called by 1: main
76func pg_span_is(q: *u8, a: i64, b: i64, z: *u8) -> i64
called by 1: main calls 1: pg_slen
83func pg_atoi_span(q: *u8, a: i64, b: i64) -> i64
called by 1: main
95func main(argc: i64, argv: *i64) -> i64