code wiki / (root) / nx_frontier_watch.nx

nx_frontier_watch.nx source

↩ module page · 112 lines · 7373 B

1// nx_cap_harvest.nx -- the DAILY FRONTIER WATCH. For each topic in knowledge/registry/harvest_topics.conf it 2// fetches arXiv (POLITELY -- paces + backs off via nx_net_polite), records total-volume + newest-month recency 3// share (via nx_search_emerge), and APPENDS a timestamped row to the sovereign seg-store knowledge/store/harvest. 4// Over daily runs the DRIFT of volume/share per topic = the emergence signal (a field accelerating = worth 5// investing) -- this is the "stay abreast of the world (Kimi 3 etc.)" half, complementing the census which 6// re-measures OUR code. Self-locates to buildroot; loads the TLS trust store from data/ or ../data/. 7// license_tier: ORIGINAL 8import "nx_search_emerge.nx" // em_collect_yms / em_maxym / em_count_eq / em_int_after 9import "nx_search_extern.nx" // se_fetch (polite composed fetch over sovereign TLS) 10import "nx_net_polite.nx" // pol_pace, POL_ARXIV_MIN_SEC 11import "nx_flatstore_flip.nx" // fsf_count, fsf_key (+ ss_* via nx_seg_store) 12import "nx_x509_trust_store.nx" 13import "nx_trust_store_load_from_certdata.nx" 14import "nx_syscalls.nx" 15import "nx_estate_path.nx" // ep_anchor: the CWD must not decide this organ's verdict 16const K_MAGIC_4096: i64 = 4096 17const K_MAGIC_4194304: i64 = 4194304 18const K_MAGIC_16384: i64 = 16384 19const K_MAGIC_16000: i64 = 16000 20const K_MAGIC_1024: i64 = 1024 21 22func hp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 23func hn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m } let t: *u8=sys_mmap(28); var k: i64=0; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } while k>0 { k=k-1; sys_write(1,(((t as i64)+k) as *u8),1) } return 0 } 24func hv_app(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8) { dst[o]=s[i]; o=o+1; i=i+1 } return o } 25func hv_numto(dst: *u8, off: i64, v: i64) -> i64 { 26 var o: i64=off 27 if v==0 { dst[o]=48 as u8; return o+1 } 28 var m: i64=v; if m<0 { dst[o]=45 as u8; o=o+1; m=0-m } 29 let t: *u8=sys_mmap(28); var k: i64=0 30 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 31 while k>0 { k=k-1; dst[o]=t[k]; o=o+1 } 32 return o 33} 34func hv_self_locate(argv: *i64) -> i64 { 35 let fa: i64=sys_openat_rd("buildroot/knowledge/registry" as *u8); if fa>=0 { sys_close(fa); sys_chdir("buildroot" as *u8); return 1 } 36 let fb: i64=sys_openat_rd("knowledge/registry" as *u8); if fb>=0 { sys_close(fb); return 0 } 37 let a0: *u8=argv[0] as *u8; if (a0 as i64)==0 { return 0 } 38 var n: i64=0; while a0[n]!=(0 as u8) { n=n+1 } 39 var ls: i64=0-1; var k: i64=0; while k<n { if a0[k]==(47 as u8) { ls=k } k=k+1 } 40 if ls<0 { return 0 } 41 let ed: *u8=sys_mmap(K_MAGIC_4096); var i: i64=0; while i<ls { ed[i]=a0[i]; i=i+1 } ed[ls]=0 as u8 42 let c1: *u8=sys_mmap(K_MAGIC_4096); var o: i64=0; o=hv_app(c1,o,ed); o=hv_app(c1,o,"/buildroot" as *u8); c1[o]=0 as u8 43 let c1r: *u8=sys_mmap(K_MAGIC_4096); var qq: i64=0; qq=hv_app(c1r,qq,c1); qq=hv_app(c1r,qq,"/knowledge/registry" as *u8); c1r[qq]=0 as u8 44 let fc: i64=sys_openat_rd(c1r); if fc>=0 { sys_close(fc); sys_chdir(c1); return 3 } 45 return 0 46} 47 48func main(argc: i64, argv: *i64) -> i64 { 49 // ANCHOR FIRST (2026-08-04): run from buildroot this organ read an EMPTY/absent estate 50 // and fail-closed RED (or, worse, appended to a SECOND store). Its subject is the 51 // estate, so the caller's working directory must not decide its verdict. 52 ep_anchor() 53 hp("=== nx_cap_harvest: daily frontier watch (arXiv volume + velocity per topic, polite, sovereign persist) ===\n" as *u8) 54 hv_self_locate(argv) 55 sys_mkdir("knowledge/store" as *u8, 0x1ff) 56 var r: i64=nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 57 if r<=0 { r=nx_trust_store_load_from_certdata("../data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) } 58 if r<=0 { hp(" trust store load FAILED (data/ + ../data/)\n" as *u8); sys_exit(1); return 1 } 59 let ts: *TrustStore=r as *TrustStore 60 let tfd: i64=sys_openat_rd("knowledge/registry/harvest_topics.conf" as *u8) 61 if tfd<0 { hp(" no knowledge/registry/harvest_topics.conf\n" as *u8); sys_exit(1); return 1 } 62 let tb: *u8=sys_mmap(K_MAGIC_16384); var tn: i64=0; var rr: i64=1 63 while rr>0 { let dst: *u8=((tb as i64)+tn) as *u8; rr=sys_read(tfd,dst,K_MAGIC_16000-tn); if rr>0 { tn=tn+rr } if tn>=K_MAGIC_16000 { rr=0 } } 64 sys_close(tfd) 65 let now: i64=sys_now_realtime_sec() 66 let hstore: *u8="knowledge/store/harvest" as *u8 67 let base: i64=fsf_count(hstore, "harvest:row:" as *u8) 68 let w: *i64=ss_begin() 69 let cap: i64=K_MAGIC_4194304; let out: *u8=sys_mmap(cap) 70 let flat: *u8=sys_mmap(12*8); let newest: *u8=sys_mmap(8) 71 let url: *u8=sys_mmap(K_MAGIC_1024); let q: *u8=sys_mmap(512); let row: *u8=sys_mmap(512); let key: *u8=sys_mmap(128) 72 let lfd: i64=sys_openat_wr("knowledge/status/harvest_frontier.log" as *u8, 420) 73 var lasttime: i64=0; var added: i64=0 74 var ls: i64=0 75 while ls<tn { 76 var le: i64=ls; var eol: i64=0 77 while eol==0 { if le>=tn { eol=1 } else { if tb[le]==(10 as u8) { eol=1 } else { le=le+1 } } } 78 if le>ls { if tb[ls]!=(35 as u8) { 79 var qo: i64=0; var i: i64=ls 80 while i<le { let c: i64=tb[i] as i64; if c==13 { i=i } else { if c==32 { q[qo]=43 as u8; qo=qo+1 } else { q[qo]=tb[i]; qo=qo+1 } } i=i+1 } 81 q[qo]=0 as u8 82 if qo>0 { 83 lasttime=pol_pace(lasttime, POL_ARXIV_MIN_SEC) 84 var uo: i64=0; uo=hv_app(url,uo,"https://export.arxiv.org/api/query?search_query=all:" as *u8); uo=hv_app(url,uo,q); uo=hv_app(url,uo,"&max_results=12&sortBy=submittedDate&sortOrder=descending" as *u8); url[uo]=0 as u8 85 let n: i64=se_fetch(ts, url, out, cap, q) 86 if n>0 { 87 let nd: i64=em_collect_yms(out, n, "<published>" as *u8, flat, 12) 88 em_maxym(flat, nd, newest) 89 let recent: i64=em_count_eq(flat, nd, newest) 90 var share: i64=0; if nd>0 { share=recent*1000/nd } 91 let total: i64=em_int_after(out, n, "opensearch:totalResults>" as *u8) 92 var ro: i64=0 93 ro=hv_numto(row,ro,now); row[ro]=9 as u8; ro=ro+1 94 ro=hv_app(row,ro,q); row[ro]=9 as u8; ro=ro+1 95 ro=hv_numto(row,ro,total); row[ro]=9 as u8; ro=ro+1 96 ro=hv_numto(row,ro,share); row[ro]=9 as u8; ro=ro+1 97 ro=hv_app(row,ro,newest) 98 fsf_key("harvest:row:" as *u8, base+added, key) 99 ss_add(w, 1, key, row, ro) 100 added=added+1 101 if lfd>=0 { sys_write(lfd, row, ro); sys_write(lfd, "\n" as *u8, 1) } 102 hp(" "); sys_write(1, q, qo); hp(" vol="); hn(total); hp(" recent-share="); hn(share); hp("permille newest="); sys_write(1, newest, 7); hp("\n" as *u8) 103 } 104 } 105 } } 106 ls=le+1 107 } 108 ss_commit(hstore, w, now) 109 if lfd>=0 { sys_close(lfd) } 110 hp("\n harvested "); hn(added); hp(" topics -> appended to sovereign store knowledge/store/harvest (from base row "); hn(base); hp("); drift over daily runs = emergence.\n" as *u8) 111 sys_exit(0); return 0 112}