code wiki / _hdl_build / nx_pub_library_handoff.nx
nx_pub_library_handoff.nx source
↩ module page · 51 lines · 3557 B
1// nx_pub_library_handoff.nx -- push the LIBRARY consumed-sources catalog to the Nishi Publisher (operator
2// 2026-06-20: "push to the publisher"). The library workstream REQUESTS; the publisher SHIPS (no direct
3// push -- the sites.elf-outage law). Mirrors nx_pub_teacher_handoff: imports the real publisher ONLY (small
4// object), submits web_assets/library-sources.html to an isolated library queue, and runs the publisher's
5// full pipeline (serialize -> idempotent sha-skip -> stage -> VERIFY-sha -> ATOMIC-promote -> ledger) to a
6// LOCAL liveroot. The OUTWARD transport liveroot -> nishifamily.com/library is OPERATOR-GATED (publisher R6
7// policy=outward + the R8 transport rung) -- not run in-sandbox (no egress). license_tier: ORIGINAL
8import "nx_publisher.nx"
9import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
10import "nx_syscalls.nx"
11
12func lh_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != 0 as u8 { n = n + 1 } sys_write(1, s, n); return 0 }
13// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
14// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
15// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
16// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
17func lh_putn(v: i64) -> i64 { nxi_out(v); return 0 }
18func lh_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
19
20func main() -> i64 {
21 lh_puts("=== NISHI PUBLISHER <- library catalog handoff: REQUEST (pub_submit) then the publisher SHIPS ===\n")
22 let page: *u8 = "web_assets/library-sources.html\x00" as *u8
23 let q: *u8 = "knowledge/publish/library-queue.tsv\x00" as *u8
24 let led: *u8 = "knowledge/publish/library-ledger.tsv\x00" as *u8
25 let stageroot: *u8 = "knowledge/publish/library-stage\x00" as *u8
26 let liveroot: *u8 = "knowledge/publish/library-live\x00" as *u8
27 let dest: *u8 = "library-sources.html\x00" as *u8
28 let live: *u8 = "knowledge/publish/library-live/library-sources.html\x00" as *u8
29
30 if lh_exists(page) == 0 { lh_puts(" FATAL: catalog not emitted -- run nx_library_sources first\n"); sys_exit(1); return 1 }
31 pub_init()
32 sys_mkdir(stageroot, 0x1ed)
33 sys_mkdir(liveroot, 0x1ed)
34
35 // 1. REQUEST -- the library submits a publish request (sha256 of the page content); decoupled, durable.
36 let sub: i64 = pub_submit_to(q, page, dest, "nishifamily\x00" as *u8, "nishi-library\x00" as *u8, "internal\x00" as *u8)
37 lh_puts(" [library] pub_submit -> "); lh_putn(sub)
38 if sub == 1 { lh_puts(" (PENDING request enqueued to the library queue)\n") } else { lh_puts(" (submit FAILED)\n") }
39
40 // 2. SHIP -- the publisher owns this: serialize -> idempotent -> stage -> VERIFY-sha -> ATOMIC-promote -> ledger.
41 let pubd: i64 = pub_run_full(q, led, stageroot, liveroot, "publish:library\x00" as *u8)
42 lh_puts(" [publisher] pub_run_full -> published_this_pass="); lh_putn(pubd); lh_puts("\n")
43
44 if lh_exists(live) == 1 {
45 lh_puts(" SHIPPED by the Nishi Publisher -> knowledge/publish/library-live/library-sources.html (sha-verified, ledgered)\n")
46 lh_puts(" COORDINATED: library REQUESTED, publisher SHIPPED (no direct push). OUTWARD live-root -> nishifamily.com/library = OPERATOR-GATED (R6 policy=outward + R8 transport).\n")
47 sys_exit(0); return 0
48 }
49 lh_puts(" publisher did not promote (idempotent if already live, or a verify hold)\n")
50 sys_exit(1); return 1
51}