nx_lib_ingest.nx source
↩ module page · 38 lines · 2486 B
1// nx_lib_ingest.nx -- SOVEREIGN local-file ingest into the Nishi research library. Reads a source file and
2// writes it VERBATIM into knowledge/library/ (the research corpus). For binaries (e.g. a PDF), the PDF->text
3// CONVERSION is a SEPARATE workstream; this organ just brings the raw artifact into the library so that
4// workstream + the harvester can pick it up. Sovereign (sys_read_file + sys_write, no cp/coreutils).
5// args: nx_lib_ingest <src-abs-path> <dst-rel-path> (default = the operator-downloaded Nature paper).
6// expect_exit: 0 license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9func li_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
10func li_p(s: *u8) -> i64 { sys_write(1, s, li_slen(s)); return 0 }
11func li_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 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;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 }
12
13func main(argc: i64, argv: *i64) -> i64 {
14 var src: *u8 = "/mnt/c/Users/elder/Downloads/s41586-026-10265-5.pdf" as *u8
15 var dst: *u8 = "knowledge/library/s41586-026-10265-5.pdf" as *u8
16 if argc >= 3 { src = argv[1] as *u8; dst = argv[2] as *u8 }
17 let lb: *i64 = sys_mmap(16) as *i64
18 let buf: *u8 = sys_read_file(src, lb)
19 if (buf as i64) == 0 { li_p("LIB-INGEST-FAIL read " as *u8); li_p(src); li_p("\n" as *u8); sys_exit(1); return 1 }
20 let n: i64 = lb[0]
21 if n <= 0 { li_p("LIB-INGEST-FAIL empty " as *u8); li_p(src); li_p("\n" as *u8); sys_exit(1); return 1 }
22 let fd: i64 = sys_openat_wr(dst, 0x1a4)
23 if fd < 0 { li_p("LIB-INGEST-FAIL open-dst " as *u8); li_p(dst); li_p("\n" as *u8); sys_exit(1); return 1 }
24 var off: i64 = 0
25 while off < n {
26 let w: i64 = sys_write(fd, (buf as i64 + off) as *u8, n - off)
27 if w <= 0 { off = n } else { off = off + w }
28 }
29 sys_close(fd)
30 // verify the dest reads back the same byte count (integrity)
31 let vb: *i64 = sys_mmap(16) as *i64
32 let chk: *u8 = sys_read_file(dst, vb)
33 var okn: i64 = 0
34 if (chk as i64) != 0 { okn = vb[0] }
35 li_p("LIB-INGEST ok src_bytes=" as *u8); li_pn(n); li_p(" dst_bytes=" as *u8); li_pn(okn); li_p(" " as *u8); li_p(src); li_p(" -> " as *u8); li_p(dst); li_p("\n" as *u8)
36 if okn != n { li_p("LIB-INGEST-WARN size-mismatch\n" as *u8); sys_exit(1); return 1 }
37 sys_exit(0); return 0
38}