code wiki / _hdl_build / nx_hub_graft.nx

nx_hub_graft.nx source

↩ module page · 91 lines · 5692 B

1// nx_hub_graft.nx -- NON-REGRESSIVE hub card add (operator 2026-07-10: "eat the debt, deploy with rollback"). 2// The /compare hub is laptop-published from a multi-session-contended registry; my local copy is a stale 3// 11-domain subset while the LIVE hub carries ~30 cards. Regenerating from my stale registry would DROP ~19 4// workstreams' cards. Instead: fetch the LIVE hub over the sovereign TLS stack, INJECT the instrument card 5// before the footer (preserving every existing card), and emit (a) knowledge/compare/hub_backup.html = the 6// exact live bytes (the ROLLBACK point) and (b) knowledge/compare/hub_grafted.html = live + instrument card. 7// A downstream push + sovereign verify proves card-count did not regress; if it did, push the backup. 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_x509_trust_store.nx" 11import "nx_trust_store_load_from_certdata.nx" 12import "nx_https_fetch_follow.nx" 13const K_MAGIC_4194304: i64 = 4194304 14const K_MAGIC_4000: i64 = 4000 15 16func w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 17func wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(fd,bb,k); return 0 } 18func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 19// find first occurrence of needle in hay[0..n); -1 if absent 20func find_in(hay: *u8, n: i64, needle: *u8) -> i64 { 21 let m: i64 = slen(needle) 22 if m == 0 { return 0 - 1 } 23 var i: i64=0 24 while i + m <= n { 25 var j: i64=0; var ok: i64=1 26 while j < m { if hay[i+j] != needle[j] { ok=0; j=m } else { j=j+1 } } 27 if ok==1 { return i } 28 i=i+1 29 } 30 return 0 - 1 31} 32func count_in(hay: *u8, n: i64, needle: *u8) -> i64 { 33 let m: i64 = slen(needle); if m==0 { return 0 } 34 var c: i64=0; var i: i64=0 35 while i + m <= n { var j: i64=0; var ok: i64=1; while j<m { if hay[i+j]!=needle[j]{ok=0;j=m}else{j=j+1} } if ok==1{c=c+1} i=i+1 } 36 return c 37} 38func write_file(path: *u8, buf: *u8, n: i64) -> i64 { 39 let fd: i64 = sys_openat_wr(path, 420) 40 if fd < 0 { return 0 - 1 } 41 sys_write(fd, buf, n) 42 sys_close(fd) 43 return n 44} 45 46func main() -> i64 { 47 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 48 if r <= 0 { w(1, "GRAFT: certdata load failed\n" as *u8); return 1 } 49 let store: *TrustStore = r as *TrustStore 50 let cap: i64 = K_MAGIC_4194304 51 let out: *u8 = sys_mmap(cap) 52 let status: *i64 = sys_mmap(8) as *i64 53 54 w(1, "=== nx_hub_graft -- fetch LIVE /compare hub, inject instrument card, emit backup + grafted ===\n") 55 let n: i64 = nx_https_fetch_follow("https://nishifamily.com/compare" as *u8, store, out, cap, 6, status) 56 w(1, " live hub status="); wn(1, status[0]); w(1, " bytes="); wn(1, n); w(1, "\n") 57 if n < K_MAGIC_4000 { w(1, "GRAFT: RED live hub too small -- refusing to graft (would risk regression)\n" as *u8); return 1 } 58 let cards: i64 = count_in(out, n, "class='card'" as *u8) 59 w(1, " existing cards="); wn(1, cards); w(1, "\n") 60 if cards < 8 { w(1, "GRAFT: RED fewer than 8 cards on live hub -- refusing (looks wrong)\n" as *u8); return 1 } 61 // already grafted? idempotent 62 if find_in(out, n, "/compare/instrument" as *u8) >= 0 { 63 w(1, " live hub ALREADY has the instrument card -- writing backup only, no graft needed\n" as *u8) 64 write_file("knowledge/compare/hub_backup.html" as *u8, out, n) 65 w(1, "GRAFT: GREEN (already present)\n" as *u8) 66 return 0 67 } 68 // backup = exact live bytes (rollback point) 69 write_file("knowledge/compare/hub_backup.html" as *u8, out, n) 70 // find the footer anchor to insert before; fall back to </body> 71 var ins: i64 = find_in(out, n, "<p class='foot'" as *u8) 72 if ins < 0 { ins = find_in(out, n, "</body>" as *u8) } 73 if ins < 0 { w(1, "GRAFT: RED no insertion anchor found\n" as *u8); return 1 } 74 // build grafted buffer: out[0..ins) + card + out[ins..n) 75 let card: *u8 = "<a class='card' href='/compare/instrument'><h2>Evaluation Instrument <span class='pill'>live</span></h2><div class='stat'>Nishi's own evaluation methodology vs OpenSSF Scorecard &middot; CHAOSS &middot; Lighthouse &middot; SWE-bench &mdash; coverage 666/1000 by presence (eval-methodology census 625 by depth) &middot; 3 sovereign exceeds (keyless frontier banking &middot; self-audit &middot; drift + claim/proof gating) &middot; every /compare domain inherits these, new and retroactive</div></a>\n" as *u8 76 let cl: i64 = slen(card) 77 let g: *u8 = sys_mmap(cap + cl + 64) 78 var o: i64 = 0 79 var i: i64 = 0 80 while i < ins { g[o] = out[i]; o = o + 1; i = i + 1 } 81 var j: i64 = 0 82 while j < cl { g[o] = card[j]; o = o + 1; j = j + 1 } 83 while i < n { g[o] = out[i]; o = o + 1; i = i + 1 } 84 write_file("knowledge/compare/hub_grafted.html" as *u8, g, o) 85 let newcards: i64 = count_in(g, o, "class='card'" as *u8) 86 w(1, " grafted: cards " as *u8); wn(1, cards); w(1, " -> " as *u8); wn(1, newcards); w(1, " bytes " as *u8); wn(1, n); w(1, " -> " as *u8); wn(1, o); w(1, "\n") 87 // invariant: exactly one card added, all originals preserved 88 if newcards != cards + 1 { w(1, "GRAFT: RED card delta != 1 -- NOT writing (would regress); backup preserved\n" as *u8); return 1 } 89 w(1, "GRAFT: GREEN -- hub_grafted.html = all " as *u8); wn(1, cards); w(1, " live cards + instrument; hub_backup.html = rollback point\n" as *u8) 90 return 0 91}