code wiki / (root) / nx_site_adapters.nx

nx_site_adapters.nx source

↩ module page · 126 lines · 6396 B

1// nx_site_adapters.nx -- THE ADAPTER CENSUS (/compare/mediaingest R8; contract symbol sa_count). 2// 3// WHY: the board's "extractor breadth" row was a CLAIM (yt-dlp 1800+, Harvestr 32 patterns + 39 scrapers) with no 4// number of our own. This organ COUNTS what we actually have and names each, so breadth becomes a measured figure a 5// campaign can drive up -- never a vibe. It counts TWO kinds of adapter, because the estate has two: 6// 1. DATA-TABLE album adapters -- rows in the runtime seg-store plane knowledge/store/mvfetch- (key ad:<host>), 7// each describing where the links live on an album/item page. A new site is an INSERT, not code (nx_mvault_fetch). 8// 2. PER-SOURCE ingester ORGANS -- first-class programs for a named source (nx_4chan), declared as DATA in 9// knowledge/status/source_adapters.conf (organ|source|verified_sites), so adding one is an INSERT there too. 10// 11// Every number is DERIVED (reg_index_len over the plane + a line count of the conf), never hardcoded -- a census that 12// prints a constant is the fabricated-measurement defect. Honest by construction: today the count is small, and the 13// organ says so rather than flattering it. license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 14import "nx_syscalls.nx" 15import "nx_registry.nx" 16 17const SA_PFX: *u8 = "knowledge/store/mvfetch-\x00" // the album-adapter plane (matches nx_mvault_fetch MVF_PFX) 18const SA_IDS: *u8 = "ad:ids\x00" // its newline-separated host index (MVF_IDS) 19const SA_CONF: *u8 = "knowledge/status/source_adapters.conf" 20const SA_CONF_CAP: i64 = 262144 21const SA_HASH: i64 = 35 // '#' 22const SA_NL: i64 = 10 23const SA_PIPE: i64 = 124 24 25func sa_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 26func sa_n(v: i64) -> i64 { 27 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 28 var m: i64 = v 29 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 30 let t: *u8 = sys_mmap(32); var k: i64 = 0 31 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 32 let o: *u8 = sys_mmap(32); var i: i64 = 0 33 while i < k { o[i] = t[k-1-i]; i = i + 1 } 34 sys_write(1, o, k); return 0 35} 36func sa_wslice(buf: *u8, off: i64, len: i64) -> i64 { sys_write(1, ((buf as i64)+off) as *u8, len); return 0 } 37 38// count of registered album-adapter rows: newline-separated ids in the plane index. reg_index_len returns the index 39// byte length; the row count is the number of newline terminators (each id ends in one; sts writers append '\n'). 40func sa_album_count(idxbuf: *u8, cap: i64, out_bytes: *i64) -> i64 { 41 let n: i64 = reg_index(SA_PFX, SA_IDS, idxbuf, cap) 42 out_bytes[0] = n 43 if n <= 0 { return 0 } // 0 = empty plane; -1 = did-not-fit (reg_index refuses a short read) -> report as 0 rows, bytes carries the signal 44 var rows: i64 = 0 45 var i: i64 = 0 46 while i < n { if idxbuf[i] == (SA_NL as u8) { rows = rows + 1 } i = i + 1 } 47 // a final id without a trailing newline still counts as a row 48 if n > 0 { if idxbuf[n-1] != (SA_NL as u8) { rows = rows + 1 } } 49 return rows 50} 51 52// count of DECLARED source organs: non-comment, non-blank rows in the conf, each printed with its source + verified sites. 53func sa_source_count(verbose: i64, out_verified: *i64) -> i64 { 54 let szp: *i64 = sys_mmap(16) as *i64 55 szp[0] = 0 56 let buf: *u8 = sys_read_file(SA_CONF, szp) 57 out_verified[0] = 0 58 if (buf as i64) == 0 { return 0 } 59 let n: i64 = szp[0] 60 if n <= 0 { return 0 } 61 var rows: i64 = 0 62 var ls: i64 = 0 63 var i: i64 = 0 64 while i <= n { 65 var eol: i64 = 0 66 if i == n { eol = 1 } else { if buf[i] == (SA_NL as u8) { eol = 1 } } 67 if eol == 1 { 68 let len: i64 = i - ls 69 if len > 0 { 70 let c0: i64 = buf[ls] as i64 71 if c0 != SA_HASH { // not a comment 72 // find the two pipes to isolate organ | source | verified_sites 73 var p1: i64 = 0 - 1 74 var p2: i64 = 0 - 1 75 var j: i64 = ls 76 while j < i { 77 if buf[j] == (SA_PIPE as u8) { if p1 < 0 { p1 = j } else { if p2 < 0 { p2 = j } } } 78 j = j + 1 79 } 80 if p1 > 0 { if p2 > p1 { 81 rows = rows + 1 82 // parse verified_sites (decimal after the 2nd pipe) 83 var v: i64 = 0 84 var q: i64 = p2 + 1 85 while q < i { let d: i64 = buf[q] as i64; if d >= 48 { if d <= 57 { v = v*10 + (d-48) } } q = q + 1 } 86 out_verified[0] = out_verified[0] + v 87 if verbose == 1 { 88 sa_w(" organ " as *u8); sa_wslice(buf, ls, p1 - ls) 89 sa_w(" source=" as *u8); sa_wslice(buf, p1+1, p2 - p1 - 1) 90 sa_w(" verified_sites=" as *u8); sa_n(v); sa_w("\n" as *u8) 91 } 92 } } 93 } 94 } 95 ls = i + 1 96 } 97 i = i + 1 98 } 99 return rows 100} 101 102// The census: album-adapter rows + declared source organs, each named, total derived. Returns the total adapter count. 103func sa_count(verbose: i64) -> i64 { 104 let idxbuf: *u8 = sys_mmap(1048576) 105 let ab: *i64 = sys_mmap(16) as *i64 106 let album: i64 = sa_album_count(idxbuf, 1048576, ab) 107 let sv: *i64 = sys_mmap(16) as *i64 108 if verbose == 1 { sa_w(" per-source ingester organs (declared, verified):\n" as *u8) } 109 let sources: i64 = sa_source_count(verbose, sv) 110 let total: i64 = album + sources 111 if verbose == 1 { 112 sa_w(" album-adapter rows (runtime plane knowledge/store/mvfetch-): " as *u8); sa_n(album) 113 sa_w(" (index bytes=" as *u8); sa_n(ab[0]); sa_w(")\n" as *u8) 114 sa_w(" ADAPTERS total=" as *u8); sa_n(total) 115 sa_w(" (album=" as *u8); sa_n(album); sa_w(" + source-organs=" as *u8); sa_n(sources) 116 sa_w(") verified-sites=" as *u8); sa_n(sv[0]); sa_w("\n" as *u8) 117 } 118 return total 119} 120 121func main(argc: i64, argv: *i64) -> i64 { 122 sa_w("=== nx_site_adapters -- adapter census (/compare/mediaingest R8) ===\n" as *u8) 123 let total: i64 = sa_count(1) 124 sa_w("SITE-ADAPTERS total=" as *u8); sa_n(total); sa_w("\n" as *u8) 125 return 0 126}