code wiki / _hdl_build / nx_wiki_structure_regen.nx
nx_wiki_structure_regen.nx
buildroot/runtime/_hdl_build/nx_wiki_structure_regen.nx
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
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
| 82 | struct RegRegistry |
| 92 | struct RegPlan |
consts
| 42 | const REG_MAGIC_1048576: i64 = 1048576 |
| 43 | const REG_MAGIC_4096: i64 = 4096 |
| 46 | const REG_OK: i64 = 0 |
| 47 | const REG_BAD_INPUT: i64 = 0 - 4960 |
| 48 | const REG_REGISTRY_READ: i64 = 0 - 4961 // could not read wiki_pages.tsv |
| 49 | const REG_OVERFLOW: i64 = 0 - 4962 // more rows than REG_MAX_PAGES |
| 52 | const RC_CLEAN: i64 = 0 // re-emit leaves no orphan / no dead link attributable to it |
| 53 | const RC_REFUSE_ORPHAN: i64 = 1 // would orphan a managed page (R-ORPH) -> skipped, not published |
| 54 | const RC_DEAD_LINK: i64 = 2 // would introduce a dead internal link (R-DEAD) -> skipped |
| 55 | const RC_MANUAL_ONLY: i64 = 3 // no emitter -> not regenerated, not published (reported) |
| 56 | const RC_NOT_RUN: i64 = 4 // emitter run failed -> not published |
| 59 | const WP_NO: i64 = 0 |
| 60 | const WP_YES: i64 = 1 |
| 63 | const REG_MAX_PAGES: i64 = 64 // managed registry rows cap (corpus is small) |
| 64 | const REG_SLUG_CAP: i64 = 256 // a single slug / emitter / file field cap |
| 65 | const REG_LINE_CAP: i64 = 1024 // a single registry line cap |
| 66 | const REG_MAX_LINKS_PP: i64 = 512 // outbound links scanned per page (mirrors A1) |
| 67 | const REG_BODY_POOL: i64 = 8388608 // 8 MB doc-store body pool (real pages ~13 KB; generous) |
| 68 | const REG_STR_POOL: i64 = 131072 // 128 KB url/title pool |
| 69 | const REG_PATH_CAP: i64 = 1024 // web_assets/<file> path cap |
| 70 | const REG_READ_CAP: i64 = 2097152 // 2 MB bounded read cap (pages ~13 KB; avoids 4 GB reservations) |
| 71 | const REG_MODE_0644: i64 = 0x1a4 |
| 72 | const REG_TAB: i64 = 0x09 // '\t' |
| 73 | const REG_HASH: i64 = 0x23 // '#' |
| 74 | const REG_NL: i64 = 0x0A // '\n' |
| 76 | const REG_BUILD_RUNNER: *u8 = "_offc/nx_sov_build_run.elf" |
| 77 | const REG_WEB_ASSETS: *u8 = "web_assets/" |
| 78 | const REG_WIKI_PREFIX: *u8 = "/wiki/" // for building each slug's served url |
| 79 | const REG_REGISTRY_PATH: *u8 = "knowledge/registry/wiki_pages.tsv" |
functions
| 103 | func reg_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 106 | func reg_eq(a: *u8, b: *u8) -> i64 |
| 117 | func reg_dup(src: *u8, off: i64, len: i64) -> *u8 |
| 126 | func reg_cat(dst: *u8, off: i64, s: *u8) -> i64 |
| 138 | func reg_read_bounded(path: *u8, cap: i64, out_ptr: *i64) -> i64 |
| 167 | func reg_load(reg: *RegRegistry) -> i64 |
| 253 | func reg_emit(emitter: *u8) -> i64 |
| 272 | func reg_read_asset(file: *u8, out_ptr: *i64) -> i64 |
| 281 | func reg_read_asset_slug(slug: *u8, out_ptr: *i64) -> i64 |
| 290 | func reg_body_links_to(body: *u8, n: i64, slug: *u8) -> i64 |
| 315 | func reg_decide(store: *NxWikiDocStore, reg: *RegRegistry, called by 2: regen_exmain calls 10: nx_wiki_doc_store_countsys_mmapnx_ims_resolve_rootreg_lennx_ims_orphansnx_ims_dead_links+4 |
| 440 | func reg_guard_and_apply(reg: *RegRegistry, plan: *RegPlan, store: *NxWikiDocStore, called by 2: regen_exmain calls 7: nx_ims_resolve_rootreg_lensys_mmapnx_wiki_doc_store_lookuppg_decidereg_cat+1 |
| 491 | func regen_ex(prefix: *u8, apply_flag: i64, epoch: i64, reg: *RegRegistry, plan: *RegPlan) -> i64 called by 1: regen calls 11: reg_loadsys_mmapnx_wiki_doc_store_initreg_lenreg_catreg_read_asset_slug+5 |
| 593 | func regen(apply_flag: i64, epoch: i64, reg: *RegRegistry, plan: *RegPlan) -> i64 |
| 598 | func rc_name(c: i64) -> *u8 |
| 606 | func guard_name(v: i64) -> *u8 |