code wiki / _hdl_build / nx_patch_guard.nx
nx_patch_guard.nx
buildroot/runtime/_hdl_build/nx_patch_guard.nx
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
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
structs
| none |
consts
| 23 | const PG_PREFIX: *u8 = "knowledge/store/patchledger-" as *u8 |
| 24 | const PG_PLANECAP: i64 = 262144 |
| 25 | const PG_SLACK: i64 = 4096 |
| 26 | const PG_NL: i64 = 10 |
| 27 | const PG_TAB: i64 = 9 |
| 28 | const PG_NCOLMAX: i64 = 8 |
| 29 | const PG_PAIR: i64 = 2 |
| 30 | const PG_SPB: i64 = 128 |
| 31 | const PG_MAXROWS: i64 = 4096 |
| 32 | const PG_DEFMAX: i64 = 2 |
| 33 | const PG_OUTCAP: i64 = 4096 |
| 34 | const PG_STDOUT: i64 = 1 |
| 35 | const PG_STDERR: i64 = 2 |
| 36 | const PG_C_TARGET: i64 = 1 |
| 37 | const PG_C_KIND: i64 = 2 |
| 38 | const PG_C_NOTE: i64 = 4 |
| 39 | const PG_NCOL: i64 = 5 |
| 40 | const PG_EXIT_USAGE: i64 = 2 |
| 41 | const PG_EXIT_REFUSE: i64 = 3 |
| 42 | const PG_ZERO: i64 = 48 |
| 43 | const PG_NINE: i64 = 57 |
functions
| 45 | func pg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 46 | func pg_werr(s: *u8) -> i64 { sys_write(PG_STDERR, s, pg_slen(s)); return 0 } |
| 47 | func 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 |
| 48 | func 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 } |
| 49 | func pg_puti(b: *u8, off: i64, v: i64) -> i64 |
| 61 | func pg_cols(q: *u8, ls: i64, le: i64, sp: *i64) -> i64 called by 1: main |
| 76 | func pg_span_is(q: *u8, a: i64, b: i64, z: *u8) -> i64 |
| 83 | func pg_atoi_span(q: *u8, a: i64, b: i64) -> i64 called by 1: main |
| 95 | func main(argc: i64, argv: *i64) -> i64 |