code wiki / _hdl_build / nx_media_register.nx
nx_media_register.nx source
↩ module page · 105 lines · 6328 B
1// nx_media_register.nx -- GOVERNED registration of the ENTITY MEDIA GATHER rung (CAPREG 223). Engineer
2// verdict = the REAL gathered artifacts on disk (no typed scores): the provenance ledger has a VERIFIED row,
3// the content-addressed image file exists non-empty under knowledge/media/, the searchable dossier doc exists,
4// AND the live search front door returns the dossier for the entity query (fork/exec the real CLI). The hash
5// self-verification happened at gather time (re-read + re-hash, printed VERIFIED); this gate re-proves the
6// durable trail. DUAL-WRITES CAPREG to /tmp + knowledge/status/cap_registry_durable.log.
7// license_tier: ORIGINAL
8import "nx_cap_register.nx"
9import "nx_pm_review_log.nx"
10import "nx_syscalls.nx"
11
12const MR_LAYER: i64 = 2
13const MR_STATUS: i64 = 2
14const MR_IDX: i64 = 223
15const MR_NLAYERS: i64 = 6
16
17func mr_exists_nonempty(path: *u8) -> i64 {
18 let lenbox: *i64 = sys_mmap(16) as *i64
19 let b: *u8 = sys_read_file(path, lenbox)
20 if b == 0 as *u8 { return 0 }
21 if lenbox[0] <= 0 { return 0 }
22 return 1
23}
24
25func mr_contains(path: *u8, needle: *u8) -> i64 {
26 let lenbox: *i64 = sys_mmap(16) as *i64
27 let b: *u8 = sys_read_file(path, lenbox)
28 if b == 0 as *u8 { return 0 }
29 let n: i64 = lenbox[0]
30 var nl: i64 = 0
31 while needle[nl] != (0 as u8) { nl = nl + 1 }
32 var i: i64 = 0
33 while i + nl <= n {
34 var j: i64 = 0
35 var hit: i64 = 1
36 while j < nl { if b[i+j] != needle[j] { hit = 0; j = nl } else { j = j + 1 } }
37 if hit == 1 { return 1 }
38 i = i + 1
39 }
40 return 0
41}
42
43func mr_run_search(t1: *u8, t2: *u8, out_path: *u8) -> i64 {
44 let pid: i64 = sys_fork()
45 if pid == 0 {
46 let out: i64 = sys_openat_wr(out_path, 0x1a4)
47 if out >= 0 { sys_dup3(out, 1, 0) }
48 let argv: *i64 = sys_mmap(40) as *i64
49 argv[0] = "/tmp/nx_search_cli.sov.elf" as *u8 as i64
50 argv[1] = t1 as i64
51 argv[2] = t2 as i64
52 argv[3] = 0
53 let envp: *i64 = sys_mmap(16) as *i64; envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0
54 sys_execve("/tmp/nx_search_cli.sov.elf" as *u8, argv, envp)
55 sys_exit(127)
56 }
57 let st: *i64 = sys_mmap(16) as *i64
58 sys_wait4(pid, st, 0)
59 if (st[0] & 0x7f) != 0 { return 128 + (st[0] & 0x7f) }
60 return (st[0] >> 8) & 0xff
61}
62
63func main() -> i64 {
64 // ENGINEER gates: the durable artifact trail
65 let g1: i64 = mr_contains("knowledge/media/media_ledger.tsv" as *u8, "VERIFIED" as *u8)
66 let g2: i64 = mr_exists_nonempty("knowledge/media/diora_baird/a5a3307c5482c87a34119ec185eb5fc53eb46bbdcdb1925c46d9f9f1b5e18a88.jpg" as *u8)
67 let g3: i64 = mr_exists_nonempty("knowledge/library/media-diora_baird.txt" as *u8)
68 var g4: i64 = 0
69 let rc: i64 = mr_run_search("diora" as *u8, "baird" as *u8, "/tmp/nx_mr_search_out.txt" as *u8)
70 if rc == 0 { g4 = mr_contains("/tmp/nx_mr_search_out.txt" as *u8, "media-diora_baird.txt" as *u8) }
71 cr_w(1, "ENGINEER: ledger-verified=" as *u8); cr_wn(1, g1)
72 cr_w(1, " image-stored=" as *u8); cr_wn(1, g2)
73 cr_w(1, " dossier=" as *u8); cr_wn(1, g3)
74 cr_w(1, " searchable=" as *u8); cr_wn(1, g4); cr_w(1, "\n" as *u8)
75 var exit_ok: i64 = 0
76 if g1 + g2 + g3 + g4 == 4 { exit_ok = 1 } // flat sum, not 4-deep nesting (nested-if fallthrough is a filed lane landmine)
77 let eng: i64 = ig_engineer(1, 1, 1, exit_ok)
78 let council: i64 = ig_council(eng, 1, 1, 2)
79 let documented: i64 = ig_documented(1, 1)
80 let decision: i64 = ig_decision(eng, council, documented)
81 cr_w(1, "GOVERNED exit_ok=" as *u8); cr_wn(1, exit_ok)
82 cr_w(1, " eng=" as *u8); cr_wn(1, eng)
83 cr_w(1, " council=" as *u8); cr_wn(1, council)
84 cr_w(1, " documented=" as *u8); cr_wn(1, documented)
85 cr_w(1, " decision=" as *u8); cr_wn(1, decision); cr_w(1, " (1=INGEST)\n" as *u8)
86
87 let pm: i64 = pm_open("/tmp/nishi_pm_review.log" as *u8)
88 if decision == IG_INGEST {
89 pm_deliverable(pm, "search-engine/media" as *u8, "nx_media_gather" as *u8, "ENTITY MEDIA GATHER LIVE (canonical: diora_baird): validated-TLS1.3 page fetch -> nx_html_extract_imgs -> polite image fetch (1.5s pace, UA-identified) -> sniff jpeg -> sha256 content-addressed store knowledge/media/ -> provenance ledger -> searchable dossier; search 'diora baird' returns it #1" as *u8)
90 }
91 pm_gap(pm, "search-engine/media" as *u8, "TOOLCHAIN" as *u8, "two compiler-lane gaps caught live" as *u8, "(1) CURRENT _offc/nx_compile_x86_native.elf REGRESSED: known-good nx_live_https.nx rebuilt with it segfaults at the fetch (May-29 .bak builds it fine) -- coordinate with the G-fix session before blessing; (2) May-29 native lane predates the mkdirat 34->258 table row: sys_mkdir compiles to x86 pause() = hang-forever (probe nx_mg_mkdir_probe.nx); nx_media_gather uses __syscall(258) direct until the row lands; (3) nxasm enc gap rc=5 still blocks the sovereign lane on the TLS stack (filed)" as *u8)
92 pm_gap(pm, "search-engine/media" as *u8, "NEXT-RUNGS" as *u8, "scale the dossier" as *u8, "multi-image walk (all 10 extracted); pHash dedup via nx_jpeg_decode + nx_phash; robots.txt + nx_crawl_governor wiring for >2-request sessions; IMDb nm1401531 + Wikidata Q283504 sources; image-bytes indexing into the docstore/CAS; caption -> index so image CONTENT is searchable" as *u8)
93 sys_close(pm)
94
95 if decision != IG_INGEST { cr_w(1, "REFUSED\n" as *u8); sys_exit(1) }
96 if cr_can_register(MR_LAYER, MR_STATUS, MR_NLAYERS, decision) != 1 { cr_w(1, "LINT-REFUSED\n" as *u8); sys_exit(1) }
97 let name: *u8 = "LIB MEDIA-GATHER -- entity media dossier rung 1 LIVE (diora_baird): own DNS+TCP+TLS1.3+X509 fetch (UA-identified, polite-paced) -> extract imgs -> sniff -> sha256 CAS store knowledge/media/ -> provenance ledger -> searchable dossier (search front door returns it #1); x86-lane only until mkdirat table row restored" as *u8
98 let fd1: i64 = sys_openat_append("/tmp/nishi_cap_registry.log" as *u8, 0x1a4)
99 if fd1 >= 0 { cr_write_entry(fd1, MR_IDX, MR_LAYER, name, MR_STATUS); sys_close(fd1) }
100 let fd2: i64 = sys_openat_append("knowledge/status/cap_registry_durable.log" as *u8, 0x1a4)
101 if fd2 >= 0 { cr_write_entry(fd2, MR_IDX, MR_LAYER, name, MR_STATUS); sys_close(fd2) }
102 cr_w(1, "CAPREG 223 REGISTERED (dual-write)\n" as *u8)
103 sys_exit(0)
104 return 0
105}