code wiki / _hdl_build / nx_archivist_durability.nx
nx_archivist_durability.nx source
↩ module page · 53 lines · 3156 B
1// nx_archivist_durability.nx -- the ARCHIVIST's first duty under the 2026-06-09 RACI clarification:
2// a log that grades or governs MUST be durable. The cap registry, PM plan, and issues log live in
3// /tmp and DIE ON REBOOT (observed: this session opened with the prior session's /tmp logs gone).
4// This organ snapshots each into knowledge/status/ with a dated marker line (ADDITIVE -- /tmp stays;
5// the dual-write law is the team's follow-on). Re-runnable; appends a fresh snapshot each run.
6// license_tier: ORIGINAL
7import "nx_syscalls.nx"
8const K_MAGIC_2097168: i64 = 2097168
9const K_MAGIC_2097152: i64 = 2097152
10func _p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func _pn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
12func _fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
13func _fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
14func ad_copy(src: *u8, dst: *u8) -> i64 {
15 let buf: *u8 = sys_mmap(K_MAGIC_2097168)
16 let fd: i64 = sys_openat_rd(src)
17 if fd < 0 { return 0 - 1 }
18 var total: i64 = 0
19 var go: i64 = 1
20 while go == 1 {
21 let base: i64 = buf as i64
22 let n: i64 = sys_read(fd, (base + total) as *u8, K_MAGIC_2097152 - total)
23 if n <= 0 { go = 0 } else { total = total + n }
24 if total >= K_MAGIC_2097152 { go = 0 }
25 }
26 sys_close(fd)
27 if total <= 0 { return 0 }
28 let ofd: i64 = sys_openat_append(dst, 0x1a4)
29 if ofd < 0 { return 0 - 2 }
30 _fp(ofd, "ARCHIVE-SNAPSHOT epoch=" as *u8); _fn(ofd, sys_now_realtime_sec())
31 _fp(ofd, " src=" as *u8); _fp(ofd, src)
32 _fp(ofd, " bytes=" as *u8); _fn(ofd, total); _fp(ofd, "\n" as *u8)
33 sys_write(ofd, buf, total)
34 sys_close(ofd)
35 return total
36}
37func main() -> i64 {
38 _p("=== ARCHIVIST durability snapshot (RACI clarification #3: governing logs must survive reboot) ===\n" as *u8)
39 var ok: i64 = 0
40 let b1: i64 = ad_copy("/tmp/nishi_cap_registry.log" as *u8, "knowledge/status/cap_registry_durable.log" as *u8)
41 _p(" cap-registry bytes=" as *u8); _pn(b1); _p("\n" as *u8)
42 if b1 > 0 { ok = ok + 1 }
43 let b2: i64 = ad_copy("/tmp/nishi_pm_plan.log" as *u8, "knowledge/status/pm_plan_durable.log" as *u8)
44 _p(" pm-plan bytes=" as *u8); _pn(b2); _p("\n" as *u8)
45 if b2 > 0 { ok = ok + 1 }
46 let b3: i64 = ad_copy("/tmp/nishi_issues.log" as *u8, "knowledge/status/issues_durable.log" as *u8)
47 _p(" issues bytes=" as *u8); _pn(b3); _p("\n" as *u8)
48 if b3 > 0 { ok = ok + 1 }
49 _p(" ARCHIVIST: " as *u8); _pn(ok); _p("/3 governing logs now reboot-safe in knowledge/status/\n" as *u8)
50 if ok == 3 { sys_exit(0); return 0 }
51 sys_exit(1)
52 return 1
53}