code wiki / _hdl_build / nx_wiki_lessons_push.nx
nx_wiki_lessons_push.nx source
↩ module page · 95 lines · 5200 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
17const WL_MODE_0644: i64 = 0x1a4
18
19func 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 }
20func 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 }
21
22func wl_write_file(path: *u8, content: *u8, clen: i64) -> i64 {
23 let fd: i64 = sys_openat_wr(path, WL_MODE_0644)
24 if fd < 0 { return 0 - 1 }
25 sys_write(fd, content, clen)
26 sys_close(fd)
27 return 0
28}
29
30// fork+exec the push elf with argv = [elf, src_spec, dst_spec]; wait; return child exit code.
31func wl_run(src_spec: *u8, dst_spec: *u8) -> i64 {
32 let pid: i64 = sys_fork()
33 if pid == 0 {
34 let argv: *i64 = sys_mmap(64) as *i64
35 argv[0] = WL_PUSH_ELF as i64
36 argv[1] = src_spec as i64
37 argv[2] = dst_spec as i64
38 argv[3] = 0
39 let envp: *i64 = sys_mmap(16) as *i64
40 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
41 sys_execve(WL_PUSH_ELF, argv, envp)
42 sys_exit(127)
43 }
44 let st: *i64 = sys_mmap(16) as *i64
45 sys_wait4(pid, st, 0)
46 return (st[0] >> 8) & 0xff
47}
48
49// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
50// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
51// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
52// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
53func wl_num(v: i64) -> i64 { nxi_out(v); return 0 }
54
55// push knowledge/wiki-content/<fname> -> <NASDIR>/<fname>. idx tags the spec files so calls don't share.
56func wl_push_one(fname: *u8, idx: i64) -> i64 {
57 let srcspec: *u8 = sys_mmap(256)
58 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
59 let dstspec: *u8 = sys_mmap(256)
60 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
61
62 // src content = knowledge/wiki-content/<fname>\n
63 let srcbuf: *u8 = sys_mmap(512)
64 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
65 if wl_write_file(srcspec, srcbuf, so) != 0 { wl_w(" src-spec write FAIL\n" as *u8); return 0 - 1 }
66
67 // dst content = mkdir -p <NASDIR>; cat > <NASDIR>/<fname>\n
68 let dstbuf: *u8 = sys_mmap(WL_MAGIC_1024)
69 var d: i64 = 0
70 d = wl_cat(dstbuf, d, "mkdir -p " as *u8); d = wl_cat(dstbuf, d, WL_NASDIR)
71 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)
72 dstbuf[d] = 10 as u8; d = d + 1; dstbuf[d] = 0 as u8
73 if wl_write_file(dstspec, dstbuf, d) != 0 { wl_w(" dst-spec write FAIL\n" as *u8); return 0 - 1 }
74
75 wl_w(" pushing " as *u8); wl_w(fname); wl_w(" -> " as *u8); wl_w(WL_NASDIR); wl_w("/\n" as *u8)
76 let rc: i64 = wl_run(srcspec, dstspec)
77 wl_w(" push rc="); wl_num(rc); wl_w("\n" as *u8)
78 return rc
79}
80
81func main() -> i64 {
82 wl_w("=== WIKI LESSONS PUSH: source .md -> live NAS wiki-content/ (additive) ===\n" as *u8)
83 var ok: i64 = 0
84 if wl_push_one("codec-arc-status.md" as *u8, 0) == 0 { ok = ok + 1 }
85 if wl_push_one("h264-bitexact-decode.md" as *u8, 1) == 0 { ok = ok + 1 }
86 if wl_push_one("h264-pframe-desync-hunt.md" as *u8, 2) == 0 { ok = ok + 1 }
87 if wl_push_one("h264-deblock-test-harness-bug.md" as *u8, 3) == 0 { ok = ok + 1 }
88 if wl_push_one("debugging-craft-bframe-traps.md" as *u8, 4) == 0 { ok = ok + 1 }
89 if wl_push_one("h264-bframe-header-sync-trap.md" as *u8, 5) == 0 { ok = ok + 1 }
90 if wl_push_one("h264-deblock-vs-recon-cordon.md" as *u8, 6) == 0 { ok = ok + 1 }
91 if wl_push_one("nishi-lessons.md" as *u8, 7) == 0 { ok = ok + 1 }
92 wl_w("=== pushed "); wl_num(ok); wl_w("/8 source files LIVE to NAS wiki-content/ ===\n" as *u8)
93 if ok == 8 { sys_exit(0); return 0 }
94 sys_exit(1); return 1
95}