code wiki / _hdl_build / nx_srcguard.nx
nx_srcguard.nx
buildroot/runtime/_hdl_build/nx_srcguard.nx
about
nx_srcguard.nx -- CANONICAL-SOURCE REVERT DETECTOR (seq1439 sev9, the work-destroyer's last mile).
THE WOUND: on 2026-07-30 canonical daemon sources were silently reverted THREE times, each revert
erasing EATEN debts across three lanes with no error anywhere. seq1379 closed the two SOVEREIGN write
paths (nx_fs_write compare-and-swap; nx_treepack refuse-to-backdate) and both hold -- but the third
path is RAW scp/rsync over ssh, which never touches an API, so no API-side guard can ever see it.
★You cannot gate a door you do not own. What you CAN do is make the damage IMPOSSIBLE TO MISS.
★★★THE RULER IS SYMBOLS, NOT BYTES (v2, 2026-07-30 -- this organ's OWN first field failure).
v1 alarmed on any byte-count DECREASE. Within a day of shipping it, it fired twice and was WRONG BOTH
TIMES: once on a file sampled mid-rewrite (a truncate-then-write window read as 0 bytes, and I reported
the supervisor source as annihilated when it settled to 279688), and once on a sibling's legitimate
refactor of nx_hostctl.nx that removed 1294 bytes while keeping ALL 212 top-level symbols. A shrink is
not a revert. Dead code gets deleted, comments get tightened, duplication gets folded -- all of that is
the tree getting BETTER, and a guard that calls it destruction trains everyone to ignore the guard.
What actually distinguishes a revert is that WORK DISAPPEARS: a func/const/struct that existed is GONE.
So the verdict is symbol-set containment -- recorded symbols must all still be present, BY NAME.
Growth is silent, refactors are silent, and only a real loss speaks. Same instrument the sibling
arrived at independently in nx_treepack (REFUSED-WOULD-DROP-SYMBOLS, seq1467).
HONEST LIMITATION, stated because an unstated one is a lie: this tracks symbol EXISTENCE, not symbol
BODIES. Gutting a function while keeping its name is invisible here. Byte deltas are still reported
(advisory) precisely so that case has a signal to be noticed by -- but it is NOT claimed as covered.
WHY A STANDALONE ORGAN: measured in the incident forensics, the CASUALTIES were long-lived shared daemon
sources while every NEWLY CREATED file SURVIVED every revert. A guard living inside the file it guards
would be reverted with it. This one is clobber-resistant BY CONSTRUCTION.
nx_srcguard record [listfile] [statefile] [symsfile] -- snapshot the watched set at a known-good state
nx_srcguard check [listfile] [statefile] [symsfile] -- exit 0 clean · 4 = WORK LOST (named symbols)
Data-driven (rule 11): the watched set is knowledge/registry/srcguard.list, one path per line.
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_itoa_lib.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
| 36 | const SG_AT_FDCWD: i64 = 0 - 100 |
| 37 | const SG_SYS_NEWFSTATAT: i64 = 262 |
| 38 | const SG_STATBUF: i64 = 256 |
| 39 | const SG_OFF_SIZE: i64 = 48 |
| 40 | const SG_OFF_MTIME: i64 = 88 |
| 42 | const SG_CAP: i64 = 65536 |
| 43 | const SG_PATHCAP: i64 = 512 |
| 47 | const SG_FCAP: i64 = 4194304 |
| 49 | const SG_SYMSET_CAP: i64 = 262144 |
| 51 | const SG_SYMSTATE_CAP: i64 = 2097152 |
| 54 | const SG_SETTLE_MS: i64 = 400 |
| 57 | const SG_NAME_CAP: i64 = 24 |
functions
| 59 | func sg_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 64 | func sg_n(v: i64) -> i64 { nxi_out(v); return 0 } |
| 65 | func sg_eq(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 } |
| 68 | func sg_stat(path: *u8, outs: *i64) -> i64 |
| 78 | func sg_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 89 | func sg_line(buf: *u8, ls: i64, le: i64, dst: *u8, cap: i64) -> i64 |
| 97 | func sg_isid(c: i64) -> i64 called by 1: sg_syms_of |
| 106 | func sg_starts(buf: *u8, i: i64, le: i64, kw: *u8) -> i64 called by 1: sg_syms_of |
| 117 | func sg_set_has(set: *u8, setlen: i64, name: *u8) -> i64 |
| 133 | func sg_syms_of(path: *u8, fb: *u8, out: *u8, ocap: i64, outs: *i64) -> i64 |
| 170 | func sg_recorded(state: *u8, sn: i64, path: *u8, outs: *i64) -> i64 |
| 205 | func sg_emit_i(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } |
| 207 | func main(argc: i64, argv: *i64) -> i64 |