code wiki / (root) / nx_heal_lib.nx

nx_heal_lib.nx

buildroot/runtime/nx_heal_lib.nx

21093 B419 linesdepth 5pulls 9 transitivereach 2 importersview sourcekind librarytopic heal
docsdependenciesstructsconstsfunctions

about

nx_heal_lib.nx -- CONSOLIDATED heal-plane tool, LIBRARY half (importable: no main; the CLI is nx_heal.nx, the gate nx_heal_gate.nx asserts on these functions' RETURN VALUES directly). Tool #11 of the 15-tool architecture: one verb-router, composing what exists, ONE MCP stub. READ-ONLY first increment: surfaces the supervision + self-heal + remediation state of the NAS plane so an operator or workstream can SEE/MONITOR over MCP what tonight's prevention layer is doing (tools_selfheal / edge_selfheal / supervisor snap). Verbs: status -> one rollup: supervisor snapshot (UP/DOWN counts + every non-UP line), selfheal_status.tsv, last self-heal log line + remediation count per plane log tools|edge -> tail of that plane's self-heal log remediations -> per-plane remediation event counts + most recent epochs All verbs take an optional basedir (default "." = ~/nishihost on the NAS); the gate points it at a fixture dir. Mutating verbs (reconcile/reap) are a LATER increment behind a separate cap -- this increment is honestly read-only (schema ro=1). license_tier: ORIGINAL

dependencies 6 imports · 2 importers

nx_syscalls.nx nx_itoa_lib.nx nx_connect.nx nx_seg_store.nx nx_vsz_watchdog_core.nx nx_os_proc.nx nx_heal_lib.nx nx_heal.nx nx_heal_gate.nx

imports: nx_syscalls.nxnx_itoa_lib.nxnx_connect.nxnx_seg_store.nxnx_vsz_watchdog_core.nxnx_os_proc.nx

imported by: nx_heal.nxnx_heal_gate.nx

structs

none

consts

22const NH_BUF_CAP: i64 = 262144 // max bytes considered per surfaced file (logs stay small by design)
23const NH_TAIL_LINES: i64 = 20 // `log` verb: lines of tail shown
24const NH_RECENT_EVTS: i64 = 5 // `remediations`: most recent epochs echoed
25const NH_PATH_CAP: i64 = 512
26const NH_ASCII_0: i64 = 48 // '0' (decimal print)
212const NH_OLD_SECS: i64 = 600 // a pid older than this = stable long-lived parent
213const NH_RECENT_WIN: i64 = 3600 // remediation recency window (matches selfheal's per-hour accounting)
214const NH_MAX_PIDS: i64 = 64 // matched-pid table cap
215const NH_ALLPID_CAP: i64 = 4096 // max live pids enumerated per scan (via the nx_os_proc seam)
216const NH_CL_CAP: i64 = 4096 // argv0 read cap
217const NH_SUP_CAP: i64 = 262144 // supervisor-log read cap
219const NH_V_DOWN: i64 = 0 // no live process
220const NH_V_STABLE: i64 = 1 // long-lived parent; pid churn = worker children (monitor false-positive)
221const NH_V_LOOP_HEAL: i64 = 2 // young processes + recent heal-plane remediations = selfheal is bouncing it
222const NH_V_LOOP_UNTRACKED: i64 = 3 // young processes, NO heal remediations = something ELSE restarts it
364const NH_FETCH_CAP: i64 = 32768

functions

28func nh_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
33func nh_putn(v: i64) -> i64 { nxi_out(v); return 0 }
34func nh_streq(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 }
called by 3: mainnh_lognh_str_eq
35func nh_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i }
called by 1: nh_path
37func nh_path(out: *u8, base: *u8, name: *u8) -> i64
called by 2: hg_writenh_read calls 1: nh_cat
45func nh_read(base: *u8, name: *u8, bufp: *i64) -> i64
57func nh_tail(buf: *u8, n: i64, want: i64) -> i64
75func nh_lastline(buf: *u8, n: i64) -> i64
called by 1: nh_status calls 2: nh_putssys_write
87func nh_lines(buf: *u8, n: i64) -> i64
94func nh_match(buf: *u8, i: i64, end: i64, lit: *u8) -> i64
104func nh_line_has_up(buf: *u8, ls: i64, le: i64) -> i64
called by 1: nh_status calls 1: nh_match
112func nh_is_svc(buf: *u8, ls: i64, le: i64) -> i64
called by 1: nh_status calls 1: nh_match
117func nh_status(base: *u8) -> i64
194func nh_log(base: *u8, plane: *u8) -> i64
224func nh_str_eq(a: *u8, b: *u8) -> i64 { return nh_streq(a, b) }
called by 2: nh_scannh_diagnose calls 1: nh_streq
226func nh_wallclock() -> i64
234func nh_scan(daemon: *u8, pids: *i64, ages: *i64, ppids: *i64) -> i64
263func nh_recent_epochs(buf: *u8, n: i64, now: i64, win: i64) -> i64
called by 1: nh_diagnose calls 2: sys_mmapvw_num_at
283func nh_classify(npids: i64, oldest_age: i64, recent_remed: i64) -> i64
called by 2: mainnh_diagnose
292func nh_diagnose(daemon: *u8, plane: *u8, base: *u8) -> i64
365func nh_organ_body(port: i64) -> i64
407func nh_remediations(base: *u8) -> i64