code wiki / wiki / nx_wiki_version.nx

nx_wiki_version.nx

buildroot/runtime/wiki/nx_wiki_version.nx

19025 B458 linesdepth 16pulls 47 transitivereach 1 importersview sourcekind librarytopic wiki
docsdependenciesstructsconstsfunctions

about

nx_wiki_version.nx -- wiki R2: page VERSIONING (history / diff / rollback). Builds the version-control surface ON TOP of the R1 save backbone (wiki/nx_wiki_page_save). R1 already writes, on EVERY authed save, two rows into the content-addressed append-only seg_store under the "knowledge/store/wikipage-" prefix: wikicur:<slug> = the current markdown bytes wikirev:<slug>:<epoch> = "author=<a>\nepoch=<e>\n" + the content The immutable wikirev:* rows ARE the history substrate this module walks. No new persistence model is invented: history is read from those rows, diff is computed over two of them, and rollback REUSES the R1 save path so it lands as a NEW revision (additive-data law / cardinal 13 -- a restore never deletes or mutates a prior revision; it appends one equal to the old content). ENUMERATION (schema-first, verified against nx_seg_store.nx): The seg_store exposes ss_get / ss_scan / ss_hget for ONE EXACT key, but no prefix-key enumerator. The on-disk .docs entry format is public and stable (kind:u8 | klen:u32be | key | vlen:u32be | val -- see ss_scan_seglist), and ss_manifest + ss_readall + ss_r32 are public top-level helpers. So this module walks the live manifest's segments and collects every entry whose key begins with "wikirev:<slug>:", parsing the epoch suffix for ordering. Each revision key is written exactly ONCE (additive), so it appears once. DIFF: no nx_diff organ exists in the wiki tree, so a small, correct line-level diff lives here: hash each line (FNV-1a), compute the LCS over the line-hash sequences (classic O(a*b) DP), then emit unified-ish "- removed" / "+ added" lines for the non-matching lines. Identical revisions => empty diff. COMPOSES (avoid-duplicate-primitives cardinal; each imported ONCE): hub/nx_modern_auth_flow nx_modern_auth_validate_session (rollback gate) wiki/nx_wiki_page_save nx_wiki_page_save (R1 save = additive rollback) + nx_wps_prefix / nx_wps_rev_key (key format) nx_seg_store ss_manifest / ss_readall / ss_r32 (enumerate) + ss_open / ss_hget (read one revision) COMPOSED BY: runtime/_hdl_build/_wiki_version_gate unit gate (history/diff/rollback + additive proof + unauth liar-kill)

dependencies 4 imports · 1 importers

nx_syscalls.nx nx_modern_auth_flow.nx nx_wiki_page_save.nx nx_seg_store.nx nx_wiki_version.nx _wiki_version_gate.nx

imports: nx_syscalls.nxnx_modern_auth_flow.nxnx_wiki_page_save.nxnx_seg_store.nx

imported by: _wiki_version_gate.nx

structs

none

consts

49const NX_WV_OK: i64 = 0
50const NX_WV_REFUSED: i64 = 2920 // rollback auth gate refused
51const NX_WV_BAD_INPUT: i64 = 2921
52const NX_WV_NOT_FOUND: i64 = 2922 // target revision absent
53const NX_WV_OVERFLOW: i64 = 2923
54const NX_WV_SAVE_FAILED: i64 = 2924 // R1 save path returned an error
57const NX_WV_MAX_REVS: i64 = 4096 // versions surfaced per slug per call
58const NX_WV_KEY_CAP: i64 = 320 // "wikirev:" + slug + ":" + epoch + NUL
59const NX_WV_SEG_CAP: i64 = 4096 // live-manifest segment slots scanned

functions

64func _wv_has_prefix(key: *u8, klen: i64, pfx: *u8, pn: i64) -> i64
called by 1: nx_wiki_revscan
73func _wv_parse_dec(b: *u8, off: i64, end: i64) -> i64
called by 1: nx_wiki_revscan
92func _wv_strip_header(val: *u8, vn: i64, out: *u8, cap: i64) -> i64
called by 1: nx_wiki_rev_get
124func nx_wiki_revscan(slug: *u8, slug_n: i64,
217func nx_wiki_history(slug: *u8, slug_n: i64,
242func nx_wiki_rev_get(slug: *u8, slug_n: i64, epoch: i64,
259func _wv_line_hash(b: *u8, off: i64, n: i64) -> i64
called by 1: _wv_split_lines
273func _wv_split_lines(buf: *u8, n: i64,
called by 1: nx_wiki_diff calls 1: _wv_line_hash
304func _wv_emit(out: *u8, off: i64, cap: i64, pfx: i64,
called by 1: nx_wiki_diff
334func nx_wiki_diff(slug: *u8, slug_n: i64, epoch_a: i64, epoch_b: i64,
423func nx_wiki_rollback(