code wiki / _hdl_build / nx_wiki_structure_regen.nx

nx_wiki_structure_regen.nx

buildroot/runtime/_hdl_build/nx_wiki_structure_regen.nx

31490 B614 linesdepth 10pulls 15 transitivereach 2 importersview sourcekind librarytopic wiki
docsdependenciesstructsconstsfunctions

about

nx_wiki_structure_regen.nx -- IMS arc rung A4b: the RE-PUBLISH-ON-PULSE engine (full-auto cron driver). WHAT IT DOES (one pulse): reads the DATA-DRIVEN managed-page registry knowledge/registry/wiki_pages.tsv, and for every managed page that HAS an emitter it (a) RE-EMITS the page (fork+exec the sovereign build- runner on the emitter organ -> web_assets/<emit_file>), (b) builds the WOULD-BE corpus and runs the A1 orphan/dead-link MONITOR over it -- if re-emitting would leave any managed page with 0 inbound links (orphan) or introduce a dead internal link, the offending page is marked REFUSE_ORPHAN and SKIPPED, (c) runs the A2 publish GUARD (pg_decide) -- a REJECT skips the page with the exact reason, (d) if apply_flag == 0 records a DRY-RUN plan row and PUSHES NOTHING; if apply_flag == 1 it APPLIES via the A4a versioned publish (snapshot-then-guarded-push, multi-rollback-point). Pages with emitter "-" are reported manual- only (counted, never silently dropped, never published). COMPOSITION (every safety property routes through a PROVEN organ -- nothing reinvented): nx_ims_monitor nx_ims_orphans / nx_ims_dead_links / nx_ims_collect_targets (A1: the SOLE orphan + link-rot authority; the regen NEVER rolls its own link scanner). nx_wiki_publish_guard pg_decide (A2: the SOLE pre-publish integrity authority, fail-closed). nx_wiki_versioned_publish vpub (A4a: snapshot-then-guarded-publish; the ONLY path that can write live, reached ONLY when apply_flag==1; do_push_flag is wired to apply_flag so a dry-run can NEVER push -- ADDITIVE-ONLY + multi-rollback-point by construction). nx_wiki_index_builder NxWikiDocStore (the in-memory corpus the monitor reads). nx_syscalls fork/exec/wait for the emitter; sys_read_file for bodies; fixed-epoch stamp. REFUSAL ATTRIBUTION (mechanical, so the gate can assert EXACT identities): R-DEAD a page whose WOULD-BE body is the SOURCE of a dead internal link -> RC_DEAD_LINK (it introduced the rot) -> would_publish=0. R-ORPH a page whose re-emit DROPPED an outbound link (present in its baseline body, absent in its would- be body) where the dropped target is now an ORPHAN in the would-be corpus -> RC_REFUSE_ORPHAN (its change orphaned a managed page) -> would_publish=0. Also: an orphaned page itself is held back (RC_REFUSE_ORPHAN) -- we never publish a page into a corpus where it is unreachable. NO WALL-CLOCK in the publish record: the caller passes a FIXED epoch (the versioned record is determin- istic/reproducible). (The emitter's own footer uses sys_now_realtime_sec for the freshness STAMP -- that is the page's "generated at" text, separate from the deterministic version-index epoch we control here.) Hygiene: M3 every while has a hard iter cap; M5 every buffer index bounded; M7 named constants; M8 verdicts propagated. ("loop" and "match" are reserved words -- never used as idents.) license_tier: ORIGINAL

dependencies 5 imports · 2 importers

nx_syscalls.nx nx_ims_monitor.nx nx_wiki_publish_guard.nx nx_wiki_versioned_publish.nx nx_wiki_index_builder.nx nx_wiki_structure_regen.nx nx_wiki_structure_regen_gate.nx nx_wiki_structure_regen_run.nx

imports: nx_syscalls.nxnx_ims_monitor.nxnx_wiki_publish_guard.nxnx_wiki_versioned_publish.nxnx_wiki_index_builder.nx

imported by: nx_wiki_structure_regen_gate.nxnx_wiki_structure_regen_run.nx

structs

82struct RegRegistry
92struct RegPlan

consts

42const REG_MAGIC_1048576: i64 = 1048576
43const REG_MAGIC_4096: i64 = 4096
46const REG_OK: i64 = 0
47const REG_BAD_INPUT: i64 = 0 - 4960
48const REG_REGISTRY_READ: i64 = 0 - 4961 // could not read wiki_pages.tsv
49const REG_OVERFLOW: i64 = 0 - 4962 // more rows than REG_MAX_PAGES
52const RC_CLEAN: i64 = 0 // re-emit leaves no orphan / no dead link attributable to it
53const RC_REFUSE_ORPHAN: i64 = 1 // would orphan a managed page (R-ORPH) -> skipped, not published
54const RC_DEAD_LINK: i64 = 2 // would introduce a dead internal link (R-DEAD) -> skipped
55const RC_MANUAL_ONLY: i64 = 3 // no emitter -> not regenerated, not published (reported)
56const RC_NOT_RUN: i64 = 4 // emitter run failed -> not published
59const WP_NO: i64 = 0
60const WP_YES: i64 = 1
63const REG_MAX_PAGES: i64 = 64 // managed registry rows cap (corpus is small)
64const REG_SLUG_CAP: i64 = 256 // a single slug / emitter / file field cap
65const REG_LINE_CAP: i64 = 1024 // a single registry line cap
66const REG_MAX_LINKS_PP: i64 = 512 // outbound links scanned per page (mirrors A1)
67const REG_BODY_POOL: i64 = 8388608 // 8 MB doc-store body pool (real pages ~13 KB; generous)
68const REG_STR_POOL: i64 = 131072 // 128 KB url/title pool
69const REG_PATH_CAP: i64 = 1024 // web_assets/<file> path cap
70const REG_READ_CAP: i64 = 2097152 // 2 MB bounded read cap (pages ~13 KB; avoids 4 GB reservations)
71const REG_MODE_0644: i64 = 0x1a4
72const REG_TAB: i64 = 0x09 // '\t'
73const REG_HASH: i64 = 0x23 // '#'
74const REG_NL: i64 = 0x0A // '\n'
76const REG_BUILD_RUNNER: *u8 = "_offc/nx_sov_build_run.elf"
77const REG_WEB_ASSETS: *u8 = "web_assets/"
78const REG_WIKI_PREFIX: *u8 = "/wiki/" // for building each slug's served url
79const REG_REGISTRY_PATH: *u8 = "knowledge/registry/wiki_pages.tsv"

functions

103func reg_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
106func reg_eq(a: *u8, b: *u8) -> i64
117func reg_dup(src: *u8, off: i64, len: i64) -> *u8
called by 2: reg_loadreg_decide calls 1: sys_mmap
126func reg_cat(dst: *u8, off: i64, s: *u8) -> i64
138func reg_read_bounded(path: *u8, cap: i64, out_ptr: *i64) -> i64
167func reg_load(reg: *RegRegistry) -> i64
253func reg_emit(emitter: *u8) -> i64
272func reg_read_asset(file: *u8, out_ptr: *i64) -> i64
281func reg_read_asset_slug(slug: *u8, out_ptr: *i64) -> i64
315func reg_decide(store: *NxWikiDocStore, reg: *RegRegistry,
440func reg_guard_and_apply(reg: *RegRegistry, plan: *RegPlan, store: *NxWikiDocStore,
491func regen_ex(prefix: *u8, apply_flag: i64, epoch: i64, reg: *RegRegistry, plan: *RegPlan) -> i64
593func regen(apply_flag: i64, epoch: i64, reg: *RegRegistry, plan: *RegPlan) -> i64
called by 1: main calls 1: regen_ex
598func rc_name(c: i64) -> *u8
called by 2: mainmain
606func guard_name(v: i64) -> *u8
called by 2: mainmain