code wiki / _hdl_build / nx_webpub_extract.nx
nx_webpub_extract.nx source
↩ module page · 62 lines · 3212 B
1// nx_webpub_extract.nx -- SOVEREIGN render+extract half of the web-publishing best-practices research
2// (operator 2026-06-17 "use the nishi researcher on our web publishing, give honest feedback"). Reads the six
3// raw HTTP responses from nx_webpub_fetch, strips headers, renders HTML->text (nx_html_to_text), saves the
4// text, runs ce_extract (number+unit fact claims). Lives in _hdl_build/ for the nx_claim_extract + ../nx_html_to_text
5// import paths. expect_exit: 0 license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_claim_extract.nx"
8import "nx_html_to_text.nx"
9const K_MAGIC_4194304: i64 = 4194304
10const K_MAGIC_4194303: i64 = 4194303
11
12func we_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
13func we_putn(v: i64) -> i64 {
14 let bb: *u8 = sys_mmap(28); var m: i64 = v
15 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
16 let t: *u8 = sys_mmap(28); var k: i64 = 0
17 if m == 0 { t[0] = 48 as u8; k = 1 }
18 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
20}
21
22func render_one(raw_path: *u8, txt_path: *u8) -> i64 {
23 let raw: *u8 = sys_mmap(K_MAGIC_4194304)
24 let rn: i64 = ce_read_file(raw_path, raw, K_MAGIC_4194303)
25 if rn <= 0 { we_puts(" MISS raw "); we_puts(raw_path); we_puts("\n"); return 0 - 1 }
26 var bo: i64 = 0
27 var p: i64 = 0
28 while p + 3 < rn {
29 if raw[p] == (13 as u8) { if raw[p+1] == (10 as u8) { if raw[p+2] == (13 as u8) { if raw[p+3] == (10 as u8) {
30 bo = p + 4
31 p = rn
32 } } } }
33 p = p + 1
34 }
35 if bo == 0 { we_puts(" no header boundary\n"); return 0 - 2 }
36 let body_len: i64 = rn - bo
37 let txt: *u8 = sys_mmap(K_MAGIC_4194304)
38 let tn: i64 = nx_html_to_text((raw as i64 + bo) as *u8, body_len, txt, K_MAGIC_4194303)
39 if tn <= 0 { we_puts(" html_to_text empty\n"); return 0 - 3 }
40 let ofd: i64 = sys_openat_wr(txt_path, 0x1A4)
41 if ofd > 0 { sys_write(ofd, txt, tn); sys_close(ofd) }
42 let out: *i64 = sys_mmap(64) as *i64
43 ce_extract(txt, tn, out)
44 we_puts(" "); we_puts(txt_path)
45 we_puts(" text="); we_putn(tn)
46 we_puts(" sentences="); we_putn(out[0])
47 we_puts(" facts="); we_putn(out[1]); we_puts("\n")
48 return out[1]
49}
50
51func main() -> i64 {
52 we_puts("SOVEREIGN WEB-PUBLISHING EXTRACT (team fetch+render+extract):\n")
53 render_one("knowledge/fetched/webpub_cd.raw\x00" as *u8, "knowledge/fetched/webpub_cd.txt\x00" as *u8)
54 render_one("knowledge/fetched/webpub_revproxy.raw\x00" as *u8, "knowledge/fetched/webpub_revproxy.txt\x00" as *u8)
55 render_one("knowledge/fetched/webpub_ha.raw\x00" as *u8, "knowledge/fetched/webpub_ha.txt\x00" as *u8)
56 render_one("knowledge/fetched/webpub_devops.raw\x00" as *u8, "knowledge/fetched/webpub_devops.txt\x00" as *u8)
57 render_one("knowledge/fetched/webpub_hosting.raw\x00" as *u8, "knowledge/fetched/webpub_hosting.txt\x00" as *u8)
58 render_one("knowledge/fetched/webpub_sre.raw\x00" as *u8, "knowledge/fetched/webpub_sre.txt\x00" as *u8)
59 we_puts("WEBPUB-EXTRACT-DONE\n")
60 sys_exit(0)
61 return 0
62}