code wiki / _hdl_build / nx_wiki_lessons_push.nx

nx_wiki_lessons_push.nx source

↩ module page · 94 lines · 5165 B

1// nx_wiki_lessons_push.nx -- push the live wiki SOURCE (lessons + codec-arc status) to the NAS 2// wiki-content/ dir the wiki daemon ingests, so the documentation is live + accurate as we work. 3// ADDITIVE by construction: each push is `mkdir -p <dir>; cat > <dir>/<f>` -- writes exactly that 4// one file, never deletes/clobbers anything else (CLAUDE.md #13 additive-only on production). 5// 6// REUSE (DRY #15): the proven sovereign push spine _offc/nx_aw_push.elf in argv mode (argc>=3: 7// src-spec-file + dst-cmd-file), exactly as nx_figures_data_push drives it -- per-file spec files so 8// it never collides with the page publisher's default awpush.src/.dst. Each push is a SEPARATE forked 9// process (its sys_read_file reservation lives in the child). license_tier: ORIGINAL 10import "nx_syscalls.nx" 11import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 12const WL_MAGIC_1024: i64 = 1024 13 14const WL_NASDIR: *u8 = "/volume1/homes/elderwesto/nishihost/wiki-content" as *u8 15const WL_LOCDIR: *u8 = "knowledge/wiki-content/" as *u8 16const WL_PUSH_ELF: *u8 = "_offc/nx_aw_push.elf" as *u8 17 18func wl_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 19func wl_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64 = off; var i: i64 = 0; while s[i] != 0 as u8 { dst[o] = s[i]; o = o + 1; i = i + 1 } return o } 20 21func wl_write_file(path: *u8, content: *u8, clen: i64) -> i64 { 22 let fd: i64 = sys_openat_wr(path, MODE_0644) 23 if fd < 0 { return 0 - 1 } 24 sys_write(fd, content, clen) 25 sys_close(fd) 26 return 0 27} 28 29// fork+exec the push elf with argv = [elf, src_spec, dst_spec]; wait; return child exit code. 30func wl_run(src_spec: *u8, dst_spec: *u8) -> i64 { 31 let pid: i64 = sys_fork() 32 if pid == 0 { 33 let argv: *i64 = sys_mmap(64) as *i64 34 argv[0] = WL_PUSH_ELF as i64 35 argv[1] = src_spec as i64 36 argv[2] = dst_spec as i64 37 argv[3] = 0 38 let envp: *i64 = sys_mmap(16) as *i64 39 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0 40 sys_execve(WL_PUSH_ELF, argv, envp) 41 sys_exit(127) 42 } 43 let st: *i64 = sys_mmap(16) as *i64 44 sys_wait4(pid, st, 0) 45 return (st[0] >> 8) & 0xff 46} 47 48// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 49// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 50// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 51// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 52func wl_num(v: i64) -> i64 { nxi_out(v); return 0 } 53 54// push knowledge/wiki-content/<fname> -> <NASDIR>/<fname>. idx tags the spec files so calls don't share. 55func wl_push_one(fname: *u8, idx: i64) -> i64 { 56 let srcspec: *u8 = sys_mmap(256) 57 var ss: i64 = 0; ss = wl_cat(srcspec, ss, "/tmp/wlpush_src_" as *u8); srcspec[ss] = (48 + idx) as u8; ss = ss + 1; srcspec[ss] = 0 as u8 58 let dstspec: *u8 = sys_mmap(256) 59 var ds: i64 = 0; ds = wl_cat(dstspec, ds, "/tmp/wlpush_dst_" as *u8); dstspec[ds] = (48 + idx) as u8; ds = ds + 1; dstspec[ds] = 0 as u8 60 61 // src content = knowledge/wiki-content/<fname>\n 62 let srcbuf: *u8 = sys_mmap(512) 63 var so: i64 = 0; so = wl_cat(srcbuf, so, WL_LOCDIR); so = wl_cat(srcbuf, so, fname); srcbuf[so] = 10 as u8; so = so + 1; srcbuf[so] = 0 as u8 64 if wl_write_file(srcspec, srcbuf, so) != 0 { wl_w(" src-spec write FAIL\n" as *u8); return 0 - 1 } 65 66 // dst content = mkdir -p <NASDIR>; cat > <NASDIR>/<fname>\n 67 let dstbuf: *u8 = sys_mmap(WL_MAGIC_1024) 68 var d: i64 = 0 69 d = wl_cat(dstbuf, d, "mkdir -p " as *u8); d = wl_cat(dstbuf, d, WL_NASDIR) 70 d = wl_cat(dstbuf, d, "; cat > " as *u8); d = wl_cat(dstbuf, d, WL_NASDIR); d = wl_cat(dstbuf, d, "/" as *u8); d = wl_cat(dstbuf, d, fname) 71 dstbuf[d] = 10 as u8; d = d + 1; dstbuf[d] = 0 as u8 72 if wl_write_file(dstspec, dstbuf, d) != 0 { wl_w(" dst-spec write FAIL\n" as *u8); return 0 - 1 } 73 74 wl_w(" pushing " as *u8); wl_w(fname); wl_w(" -> " as *u8); wl_w(WL_NASDIR); wl_w("/\n" as *u8) 75 let rc: i64 = wl_run(srcspec, dstspec) 76 wl_w(" push rc="); wl_num(rc); wl_w("\n" as *u8) 77 return rc 78} 79 80func main() -> i64 { 81 wl_w("=== WIKI LESSONS PUSH: source .md -> live NAS wiki-content/ (additive) ===\n" as *u8) 82 var ok: i64 = 0 83 if wl_push_one("codec-arc-status.md" as *u8, 0) == 0 { ok = ok + 1 } 84 if wl_push_one("h264-bitexact-decode.md" as *u8, 1) == 0 { ok = ok + 1 } 85 if wl_push_one("h264-pframe-desync-hunt.md" as *u8, 2) == 0 { ok = ok + 1 } 86 if wl_push_one("h264-deblock-test-harness-bug.md" as *u8, 3) == 0 { ok = ok + 1 } 87 if wl_push_one("debugging-craft-bframe-traps.md" as *u8, 4) == 0 { ok = ok + 1 } 88 if wl_push_one("h264-bframe-header-sync-trap.md" as *u8, 5) == 0 { ok = ok + 1 } 89 if wl_push_one("h264-deblock-vs-recon-cordon.md" as *u8, 6) == 0 { ok = ok + 1 } 90 if wl_push_one("nishi-lessons.md" as *u8, 7) == 0 { ok = ok + 1 } 91 wl_w("=== pushed "); wl_num(ok); wl_w("/8 source files LIVE to NAS wiki-content/ ===\n" as *u8) 92 if ok == 8 { sys_exit(0); return 0 } 93 sys_exit(1); return 1 94}