code wiki / _hdl_build / nx_research_fetch_cli.nx

nx_research_fetch_cli.nx source

↩ module page · 95 lines · 5260 B

1// nx_research_fetch_cli.nx -- the RUNNABLE DRIVER for rf_fetch_bank. 2// 3// WHY THIS EXISTS: runtime/nx_research_engine.nx carries a complete `rf_fetch_bank(url, name, store, 4// out, cap)` -- the exact symbol knowledge/compare/deepresearch.matrix names as grounding its 5// "Web fetch and bank pipeline" claim -- but the file's own entry point is `func main() -> i64 { return 0 }`, 6// a COMPILE SMOKE. So the capability is real, gated, and grounded, and yet cannot be RUN: no promoted 7// binary anywhere exposes a fetch+bank verb. Same shape as nx_https_get (a smoke main that needed a real 8// CLI beside it) and the ~dozen other build-what-already-exists cases banked this session. 9// ★★★★★A LIBRARY FUNCTION NOBODY CAN INVOKE IS A CAPABILITY ON PAPER: the claim grounds, the gate passes, 10// and the world is never actually touched. 11// 12// CONSEQUENCE THIS UNBLOCKS: deepresearch holds quorum + provenance + freshness + non-vacuity 13// (redseen 1/1) and is short exactly ONE method class. An EXPERIENTIAL row supplies both that class and 14// the require_human leg at once -- but only if the pipeline can be RUN against a real third-party server, 15// because a row whose `observed=` was never observed is prose. This driver is what makes that row honest. 16// 17// nx_research_fetch_cli <url> <name> 18// Fetches over our own TLS + Mozilla trust store, banks raw -> knowledge/fetched/<name>.raw and text -> 19// knowledge/library/<name>.txt, and prints a MACHINE-READABLE observation line for the attestation: 20// RFETCH url=<url> name=<name> rc=<n> banked_bytes=<n> verdict=OK|BANKED-SKIP|FAIL 21// ★EXIT CODE IS THE VERDICT (0 fetched+banked, 1 already banked, 2 usage, 3 trust store, 4 fetch failed) 22// so a caller never has to parse prose -- and, per this session's own law, two different failures never 23// share a code. 24// expect_exit: 0 license_tier: ORIGINAL No hw writes (Rule 26). 25import "nx_research_engine.nx" 26 27const RFC_OUTCAP: i64 = 1048576 28const RFC_MAGIC_4096: i64 = 4096 29const RFC_STORECAP: i64 = 4194304 30const RFC_CERTS: i64 = 512 31 32func rfc_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 33func rfc_putn(v: i64) -> i64 { 34 let t: *u8 = sys_mmap(32) 35 var m: i64 = v 36 if m < 0 { rfc_puts("-" as *u8); m = 0 - m } 37 var k: i64 = 0 38 if m == 0 { t[0] = 48 as u8; k = 1 } 39 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 40 let o: *u8 = sys_mmap(32) 41 var i: i64 = 0 42 while i < k { o[i] = t[k - 1 - i]; i = i + 1 } 43 sys_write(1, o, k) 44 sys_munmap(t, 32) 45 sys_munmap(o, 32) 46 return 0 47} 48 49func main(argc: i64, argv: *i64) -> i64 { 50 if argc < 3 { 51 rfc_puts("usage: nx_research_fetch_cli <url> <name>\n fetches over sovereign TLS, banks knowledge/fetched/<name>.raw + knowledge/library/<name>.txt\n" as *u8) 52 sys_exit(2); return 2 53 } 54 let url: *u8 = argv[1] as *u8 55 let name: *u8 = argv[2] as *u8 56 57 // Trust store from the SAME Mozilla certdata every other sovereign fetcher uses -- a fetch that 58 // skipped verification would make the observation worthless as evidence. 59 let sr: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, RFC_CERTS, RFC_STORECAP) 60 if sr == 0 { 61 rfc_puts("RFETCH verdict=FAIL reason=trust-store-load-failed (run from the serving root: data/mozilla_certdata.txt is CWD-relative)\n" as *u8) 62 sys_exit(3); return 3 63 } 64 let store: *TrustStore = sr as *TrustStore 65 66 // ⚠MEASURE, DO NOT INFER FROM rc. Caught on the FIRST live run: rf_fetch_bank returns 1 for BOTH 67 // "already banked, skipped" and "fetched and banked fresh" -- the same two-outcomes-one-code defect 68 // this session fixed in nx_gate_bite hours earlier, and my first draft duly mislabelled a genuine 69 // 337736-byte fetch as BANKED-SKIP. So the verdict is derived from the ARTIFACT: did the banked file 70 // exist BEFORE, does it exist AFTER, and how big is it. ★★★★★★WHEN A RETURN CODE IS AMBIGUOUS, THE 71 // FILESYSTEM IS THE ORACLE -- and for an evidence row that is the right oracle anyway, because the 72 // row must assert what LANDED, not what a function said. 73 let txt: *u8 = sys_mmap(RFC_MAGIC_4096) 74 rf_bpath(txt, "knowledge/library/" as *u8, name, ".txt" as *u8) 75 var before: i64 = 0 76 let f0: i64 = sys_openat_rd(txt) 77 if f0 >= 0 { before = 1; sys_close(f0) } 78 79 let out: *u8 = sys_mmap(RFC_OUTCAP) 80 let rc: i64 = rf_fetch_bank(url, name, store, out, RFC_OUTCAP) 81 82 var landed: i64 = 0 - 1 83 let f1: i64 = sys_openat_rd(txt) 84 if f1 >= 0 { landed = sys_lseek(f1, 0, 2); sys_close(f1) } 85 86 // ONE LINE, MACHINE-READABLE, carrying the values an experiential row needs verbatim. 87 rfc_puts("RFETCH url=" as *u8); rfc_puts(url) 88 rfc_puts(" name=" as *u8); rfc_puts(name) 89 rfc_puts(" rc=" as *u8); rfc_putn(rc) 90 rfc_puts(" banked_bytes=" as *u8); rfc_putn(landed) 91 if landed <= 0 { rfc_puts(" verdict=FAIL (nothing landed on disk)\n" as *u8); sys_exit(4); return 4 } 92 if before == 1 { rfc_puts(" verdict=BANKED-SKIP (present BEFORE this run -- NOT a fresh observation)\n" as *u8); sys_exit(1); return 1 } 93 rfc_puts(" verdict=FRESH-BANKED\n" as *u8) 94 sys_exit(0); return 0 95}