code wiki / _hdl_build / nx_eco_graph_pedigree.nx

nx_eco_graph_pedigree.nx source

↩ module page · 280 lines · 17418 B

1// nx_eco_graph_pedigree.nx -- the FAMILY-TREE OVERVIEW of the whole ecosystem: generational from god, 2// SIMPLE (operator 2026-07-16: "a billion lines crossing over each other isn't useful -- it's the 3// generational from god, then deeper dives via cards"). One band per generation: how many organs live 4// there + the top hubs as linked chips into their CARDS. Zero edges drawn, zero JS -- counts + names + 5// links carry the story; the chaos lives in NO frame. Prints the chosen hub names to stdout so the 6// publisher can generate exactly those cards. Usage: nx_eco_graph_pedigree <store> <out.html> [topN] 7// license_tier: ORIGINAL expect_exit:0 8import "nx_syscalls.nx" 9import "nx_eco_graph.nx" 10 11func pslen2(s: *u8) -> i64 { var n:i64=0; while s[n]!=(0 as u8){n=n+1} return n } 12func pw2(fd: i64, s: *u8) -> i64 { sys_write(fd, s, pslen2(s)); return 0 } 13func pn2(fd: i64, v: i64) -> i64 { let b:*u8=sys_mmap(24); var m:i64=v; if m<0{sys_write(fd,"-" as *u8,1);m=0-m} let t:*u8=sys_mmap(24); 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 j:i64=0; while j<k{b[j]=t[k-1-j];j=j+1} sys_write(fd,b,k); return 0 } 14func pname(fd: i64, g: *EcoGraph, idx: i64) -> i64 { 15 let off: i64 = g.node_off[idx] 16 var n: i64 = 0 17 while g.arena[off+n] != (0 as u8) { n = n + 1 } 18 sys_write(fd, ((g.arena as i64)+off) as *u8, n) 19 return 0 20} 21func pshort(fd: i64, g: *EcoGraph, idx: i64) -> i64 { 22 let off: i64 = g.node_off[idx] 23 var n: i64 = 0 24 while g.arena[off+n] != (0 as u8) { n = n + 1 } 25 var e: i64 = n 26 if n > 3 { if g.arena[off+n-3]==(46 as u8) { if g.arena[off+n-2]==(110 as u8) { if g.arena[off+n-1]==(120 as u8) { e = n - 3 } } } } 27 sys_write(fd, ((g.arena as i64)+off) as *u8, e) 28 return 0 29} 30 31func p_eq(a: *u8, b: *u8) -> i64 { 32 var i: i64 = 0 33 while 1 == 1 { 34 if a[i] != b[i] { return 0 } 35 if a[i] == (0 as u8) { return 1 } 36 i = i + 1 37 } 38 return 0 39} 40 41func main(argc: i64, argv: *i64) -> i64 { 42 if argc < 2 { pw2(1, "usage: nx_eco_graph_pedigree <store> <out.html> [topN] [instfile] | --live (MCP: pinned paths)\n" as *u8); return 2 } 43 var storep: *u8 = 0 as *u8 44 var outp: *u8 = 0 as *u8 45 var instp: *u8 = 0 as *u8 46 var topn: i64 = 12 47 if p_eq(argv[1] as *u8, "--live\x00" as *u8) == 1 { 48 // SOVEREIGN ONE-CALL MODE (MCP, CWD=nishihost): regenerate the live family-tree page in place 49 storep = "knowledge/store/ecograph_full\x00" as *u8 50 outp = "sites/nishifamily/compare/atlas/tree/index.html\x00" as *u8 51 instp = "knowledge/status/installed_twins.txt\x00" as *u8 52 } else { 53 if argc < 3 { pw2(1, "usage: nx_eco_graph_pedigree <store> <out.html> [topN] [instfile] | --live\n" as *u8); return 2 } 54 storep = argv[1] as *u8 55 outp = argv[2] as *u8 56 if argc >= 4 { 57 let ts: *u8 = argv[3] as *u8 58 var tv: i64 = 0 59 var ti: i64 = 0 60 while ts[ti] != (0 as u8) { tv = tv*10 + ((ts[ti] as i64) - 48); ti = ti + 1 } 61 if tv >= 3 { if tv <= 40 { topn = tv } } 62 } 63 if argc >= 5 { instp = argv[4] as *u8 } 64 } 65 let g: *EcoGraph = eg_load(storep) 66 if (g as i64) == 0 { pw2(1, "ERROR store not found\n" as *u8); return 3 } 67 let n: i64 = g.node_count 68 69 // BFS generations from true roots (cycle-safe shortest hops) 70 let gen: *i64 = sys_mmap((n+2)*8) as *i64 71 let work: *i64 = sys_mmap((n+2)*8) as *i64 72 var i: i64 = 0 73 while i < n { gen[i] = 0 - 1; i = i + 1 } 74 var wt: i64 = 0 75 i = 0 76 while i < n { 77 if g.out_head[i] == g.out_head[i+1] { gen[i] = 0; work[wt] = i; wt = wt + 1 } 78 i = i + 1 79 } 80 var wh: i64 = 0 81 while wh < wt { 82 let v: i64 = work[wh] 83 var p: i64 = g.in_head[v]; let e: i64 = g.in_head[v+1] 84 while p < e { 85 let u: i64 = g.in_list[p] 86 if gen[u] < 0 { gen[u] = gen[v] + 1; work[wt] = u; wt = wt + 1 } 87 p = p + 1 88 } 89 wh = wh + 1 90 } 91 var maxgen: i64 = 0 92 i = 0 93 while i < n { if gen[i] < 0 { gen[i] = 0 } if gen[i] > maxgen { maxgen = gen[i] } i = i + 1 } 94 95 // per-gen counts 96 let gcount: *i64 = sys_mmap((maxgen+3)*8) as *i64 97 var l: i64 = 0 98 while l <= maxgen { gcount[l] = 0; l = l + 1 } 99 i = 0; while i < n { gcount[gen[i]] = gcount[gen[i]] + 1; i = i + 1 } 100 var edges: i64 = g.out_head[n] 101 102 // ---- INTELLIGENCE: real tree vs paperwork vs one-offs ---- 103 // validation artifact = name ends _test/_gate/_bench/_demo/_probe/_smoke .nx 104 let iste: *u8 = sys_mmap(n + 2) 105 i = 0 106 while i < n { 107 let off: i64 = g.node_off[i] 108 var ln: i64 = 0 109 while g.arena[off+ln] != (0 as u8) { ln = ln + 1 } 110 var t: i64 = 0 111 if ln > 8 { 112 // check the 6 suffixes byte-wise against arena tail (before ".nx") 113 let tail: i64 = off + ln - 8 114 if g.arena[tail]==(95 as u8) { if g.arena[tail+1]==(116 as u8) { if g.arena[tail+2]==(101 as u8) { if g.arena[tail+3]==(115 as u8) { if g.arena[tail+4]==(116 as u8) { t = 1 } } } } } // _test.nx 115 if g.arena[tail]==(95 as u8) { if g.arena[tail+1]==(103 as u8) { if g.arena[tail+2]==(97 as u8) { if g.arena[tail+3]==(116 as u8) { if g.arena[tail+4]==(101 as u8) { t = 1 } } } } } // _gate.nx 116 if g.arena[tail]==(95 as u8) { if g.arena[tail+1]==(100 as u8) { if g.arena[tail+2]==(101 as u8) { if g.arena[tail+3]==(109 as u8) { if g.arena[tail+4]==(111 as u8) { t = 1 } } } } } // _demo.nx (5) 117 } 118 if ln > 7 { 119 let t7: i64 = off + ln - 7 120 if g.arena[t7]==(95 as u8) { if g.arena[t7+1]==(107 as u8) { if g.arena[t7+2]==(97 as u8) { if g.arena[t7+3]==(116 as u8) { t = 1 } } } } // _kat.nx 121 } 122 if ln > 9 { 123 let t9: i64 = off + ln - 9 124 if g.arena[t9]==(95 as u8) { if g.arena[t9+1]==(98 as u8) { if g.arena[t9+2]==(101 as u8) { if g.arena[t9+3]==(110 as u8) { if g.arena[t9+4]==(99 as u8) { if g.arena[t9+5]==(104 as u8) { t = 1 } } } } } } // _bench.nx 125 if g.arena[t9]==(95 as u8) { if g.arena[t9+1]==(112 as u8) { if g.arena[t9+2]==(114 as u8) { if g.arena[t9+3]==(111 as u8) { if g.arena[t9+4]==(98 as u8) { if g.arena[t9+5]==(101 as u8) { t = 1 } } } } } } // _probe.nx 126 if g.arena[t9]==(95 as u8) { if g.arena[t9+1]==(115 as u8) { if g.arena[t9+2]==(109 as u8) { if g.arena[t9+3]==(111 as u8) { if g.arena[t9+4]==(107 as u8) { if g.arena[t9+5]==(101 as u8) { t = 1 } } } } } } // _smoke.nx 127 } 128 iste[i] = t as u8 129 i = i + 1 130 } 131 // real-children count per node (children that are NOT validation) 132 let rc: *i64 = sys_mmap((n+2)*8) as *i64 133 i = 0; while i < n { rc[i] = 0; i = i + 1 } 134 i = 0 135 while i < n { 136 if iste[i] == (0 as u8) { 137 var p2: i64 = g.out_head[i] 138 while p2 < g.out_head[i+1] { rc[g.out_list[p2]] = rc[g.out_list[p2]] + 1; p2 = p2 + 1 } 139 } 140 i = i + 1 141 } 142 // installed set from argv[4] (names with an installed elf twin) 143 let inst: *u8 = sys_mmap(n + 2) 144 i = 0; while i < n { inst[i] = 0 as u8; i = i + 1 } 145 if (instp as i64) != 0 { 146 let ilen: *i64 = sys_mmap(16) as *i64 147 let ibuf: *u8 = sys_read_file(instp, ilen) 148 if ilen[0] > 0 { 149 var s0: i64 = 0 150 var q0: i64 = 0 151 while q0 <= ilen[0] { 152 var iend: i64 = 0 153 if q0 == ilen[0] { iend = 1 } else { if ibuf[q0] == (10 as u8) { iend = 1 } } 154 if iend == 1 { 155 var e0: i64 = q0 156 if e0 > s0 { if ibuf[e0-1] == (13 as u8) { e0 = e0 - 1 } } 157 if e0 > s0 { 158 let ix0: i64 = eg_find(g, ((ibuf as i64)+s0) as *u8, e0 - s0) 159 if ix0 >= 0 { inst[ix0] = 1 as u8 } 160 } 161 s0 = q0 + 1 162 } 163 q0 = q0 + 1 164 } 165 } 166 } 167 // global class tallies: 0 trunk / 1 shipped-leaf / 2 validation / 3 tested-only / 4 orphan 168 var ctrunk: i64 = 0 169 var cship: i64 = 0 170 var cval: i64 = 0 171 var ctest: i64 = 0 172 var corph: i64 = 0 173 let stat: *u8 = sys_mmap(n + 2) 174 i = 0 175 while i < n { 176 var st: i64 = 4 177 if iste[i] == (1 as u8) { st = 2 } else { 178 if rc[i] > 0 { st = 0 } else { 179 if inst[i] == (1 as u8) { st = 1 } else { 180 // any test children? 181 var tc: i64 = 0 182 var p3: i64 = g.in_head[i] 183 while p3 < g.in_head[i+1] { if iste[g.in_list[p3]] == (1 as u8) { tc = tc + 1 } p3 = p3 + 1 } 184 if tc > 0 { st = 3 } 185 } 186 } 187 } 188 stat[i] = st as u8 189 if st == 0 { ctrunk = ctrunk + 1 } 190 if st == 1 { cship = cship + 1 } 191 if st == 2 { cval = cval + 1 } 192 if st == 3 { ctest = ctest + 1 } 193 if st == 4 { corph = corph + 1 } 194 i = i + 1 195 } 196 197 let fd: i64 = sys_openat_wr(outp, 0x1a4) 198 if fd < 0 { pw2(1, "ERROR cannot open out\n" as *u8); return 5 } 199 200 pw2(fd, "<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content=\"width=device-width,initial-scale=1\"><title>The Family Tree &mdash; Nishi Ecosystem</title><style>body{margin:0;background:#0b0e16;color:#e8ecf6;font:15px/1.6 -apple-system,Segoe UI,system-ui,sans-serif}.wrap{max-width:980px;margin:0 auto;padding:24px 18px 70px}.crumb{font-size:.8rem;color:#8a97ad;margin-bottom:10px}a{color:#c9a0ff;text-decoration:none}a:hover{text-decoration:underline}h1{font-size:28px;margin:0 0 4px}.sub{color:#8a97ad;margin:0 0 18px}.genband{background:#11172a;border:1px solid #222c44;border-radius:14px;padding:14px 18px;margin:10px 0}.genband.alt{background:#0d1220}.ghead{display:flex;align-items:baseline;gap:14px;margin-bottom:6px}.gname{font-size:17px;font-weight:700;color:#ffd479}.gcount{color:#8a97ad;font-size:.85rem}.chip{display:inline-block;background:#141a26;border:1px solid #26304a;border-radius:9px;padding:4px 10px;margin:3px 5px 3px 0;color:#cdd6e6;font-size:.86rem}.chip:hover{border-color:#c9a0ff}.gnote{color:#5c6b85;font-size:.8rem;margin-top:4px}.down{ text-align:center;color:#3c4a66;font-size:18px;margin:2px 0}</style></head><body><div class=wrap>" as *u8) 201 pw2(fd, "<p class=crumb><a href=/>Nishi Family</a> &rsaquo; <a href=/compare/atlas>Atlas</a> &rsaquo; Family Tree</p>" as *u8) 202 pw2(fd, "<h1>The Family Tree &mdash; generational from god</h1>" as *u8) 203 pw2(fd, "<p style=\"margin:6px 0 14px\"><a href=\"/compare/atlas/explore/\" style=\"display:inline-block;background:#1a2136;border:1.5px solid #c9a0ff;border-radius:11px;padding:10px 18px;font-weight:700\">&#10021; OPEN THE TREE EXPLORER &mdash; interactive: click any organ, walk parents/children, pan &amp; zoom</a></p>" as *u8) 204 pw2(fd, "<p class=sub>" as *u8); pn2(fd, n); pw2(fd, " organs &middot; " as *u8); pn2(fd, edges); pw2(fd, " import edges &middot; " as *u8); pn2(fd, maxgen+1); pw2(fd, " generations. Gen 0 = the god primitives; each generation builds on the ones above. Every name is a <b>card</b>: parents, children, partners, siblings, lineage.</p>" as *u8) 205 // the honest split: living tree vs paperwork vs one-offs 206 pw2(fd, "<div style=\"display:flex;gap:10px;flex-wrap:wrap;margin:0 0 18px\">" as *u8) 207 pw2(fd, "<div style=\"background:#1b2a14;border:1px solid #4a6a2e;border-radius:12px;padding:10px 16px\"><b style=\"font-size:20px;color:#a5e07a\">" as *u8); pn2(fd, ctrunk); pw2(fd, "</b><br><span style=\"color:#8a97ad;font-size:.78rem\">TRUNK &mdash; the living tree (real children)</span></div>" as *u8) 208 pw2(fd, "<div style=\"background:#14222e;border:1px solid #2e5a7a;border-radius:12px;padding:10px 16px\"><b style=\"font-size:20px;color:#7fd1ff\">" as *u8); pn2(fd, cship); pw2(fd, "</b><br><span style=\"color:#8a97ad;font-size:.78rem\">SHIPPED LEAVES &mdash; installed products</span></div>" as *u8) 209 pw2(fd, "<div style=\"background:#181d2c;border:1px solid #3a4a6a;border-radius:12px;padding:10px 16px\"><b style=\"font-size:20px;color:#8a97ad\">" as *u8); pn2(fd, cval); pw2(fd, "</b><br><span style=\"color:#8a97ad;font-size:.78rem\">VALIDATION &mdash; tests/gates (paperwork)</span></div>" as *u8) 210 pw2(fd, "<div style=\"background:#2a2416;border:1px solid #6a5a2e;border-radius:12px;padding:10px 16px\"><b style=\"font-size:20px;color:#e6c86a\">" as *u8); pn2(fd, ctest); pw2(fd, "</b><br><span style=\"color:#8a97ad;font-size:.78rem\">TESTED-ONLY &mdash; validated, unadopted</span></div>" as *u8) 211 pw2(fd, "<div style=\"background:#2a161c;border:1px solid #6a2e3a;border-radius:12px;padding:10px 16px\"><b style=\"font-size:20px;color:#e08a9a\">" as *u8); pn2(fd, corph); pw2(fd, "</b><br><span style=\"color:#8a97ad;font-size:.78rem\">ORPHANS &mdash; one-offs, nothing built on them</span></div>" as *u8) 212 pw2(fd, "</div>" as *u8) 213 pw2(fd, "<p class=sub>The bands below show the <b style=\"color:#a5e07a\">LIVING TREE ONLY</b> (trunk + shipped leaves) &mdash; validation paperwork and one-off orphans are counted, quarantined at the bottom, and never mixed into the family.</p>" as *u8) 214 215 // bands: gen 0 (god) first, downward 216 l = 0 217 while l <= maxgen { 218 pw2(fd, "<div class=\"genband" as *u8) 219 if l % 2 == 1 { pw2(fd, " alt" as *u8) } 220 // living-tree members of this gen (trunk or shipped) 221 var glive: i64 = 0 222 i = 0 223 while i < n { if gen[i] == l { if (stat[i] as i64) <= 1 { glive = glive + 1 } } i = i + 1 } 224 pw2(fd, "\"><div class=ghead><span class=gname>gen " as *u8); pn2(fd, l); pw2(fd, "</span><span class=gcount>" as *u8); pn2(fd, glive); pw2(fd, " living-tree organs (of " as *u8); pn2(fd, gcount[l]); pw2(fd, " total here)" as *u8) 225 if l == 0 { pw2(fd, " &mdash; the roots: import nothing, everything descends from them" as *u8) } 226 pw2(fd, "</span></div><div>" as *u8) 227 // top-N LIVING-TREE members of this gen by Ca (selection sort into small arrays) 228 let bi: *i64 = sys_mmap((topn+2)*8) as *i64 229 let bc: *i64 = sys_mmap((topn+2)*8) as *i64 230 var bn: i64 = 0 231 i = 0 232 while i < n { 233 if gen[i] == l { if (stat[i] as i64) <= 1 { 234 let ca: i64 = eg_ca(g, i) 235 if bn < topn { 236 bi[bn] = i; bc[bn] = ca; bn = bn + 1 237 } else { 238 // find min slot 239 var mn: i64 = 0 240 var k: i64 = 1 241 while k < bn { if bc[k] < bc[mn] { mn = k } k = k + 1 } 242 if ca > bc[mn] { bi[mn] = i; bc[mn] = ca } 243 } 244 } } 245 i = i + 1 246 } 247 // emit sorted desc (simple selection) 248 var emitted: i64 = 0 249 while emitted < bn { 250 var best: i64 = 0 251 var k2: i64 = 1 252 while k2 < bn { if bc[k2] > bc[best] { best = k2 } k2 = k2 + 1 } 253 if bc[best] >= 0 { 254 let idx: i64 = bi[best] 255 pw2(fd, "<a class=chip href=\"/compare/atlas/card/" as *u8); pname(fd, g, idx); pw2(fd, ".html\">" as *u8); pshort(fd, g, idx) 256 pw2(fd, " &middot; " as *u8); pn2(fd, bc[best]); pw2(fd, "</a>" as *u8) 257 // stdout: the chosen name for the card publisher 258 pname(1, g, idx); sys_write(1, "\n" as *u8, 1) 259 bc[best] = 0 - 1 260 } 261 emitted = emitted + 1 262 } 263 if glive > topn { pw2(fd, "<span class=gnote>top " as *u8); pn2(fd, topn); pw2(fd, " living-tree by descendants-reach &mdash; <a href=\"/compare/atlas/card/index.html\">all " as *u8); pn2(fd, glive); pw2(fd, " are in the directory</a> (every organ has a card)</span>" as *u8) } 264 pw2(fd, "</div></div>" as *u8) 265 if l < maxgen { pw2(fd, "<div class=down>&#8595;</div>" as *u8) } 266 l = l + 1 267 } 268 // ---- quarantine: the NOT-tree, honestly counted, never mixed in ---- 269 pw2(fd, "<div class=genband style=\"border-color:#6a2e3a;margin-top:22px\"><div class=ghead><span class=gname style=\"color:#e08a9a\">Not part of the living tree</span><span class=gcount>" as *u8) 270 pn2(fd, cval); pw2(fd, " validation artifacts (tests/gates &mdash; paperwork attached to their subjects) &middot; " as *u8) 271 pn2(fd, ctest); pw2(fd, " tested-only (validated but unadopted) &middot; " as *u8) 272 pn2(fd, corph); pw2(fd, " one-off orphans (nothing builds on them, not installed, untested)</span></div>" as *u8) 273 pw2(fd, "<div class=gnote>Every one still has a card (status badge on it) via the <a href=\"/compare/atlas/card/index.html\">directory</a> &mdash; separated here so the FAMILY view stays the family, and the janitor workstream gets an honest worklist of " as *u8) 274 pn2(fd, corph); pw2(fd, " orphans + " as *u8); pn2(fd, ctest); pw2(fd, " unadopted candidates.</div></div>" as *u8) 275 pw2(fd, "<p class=sub style=\"margin-top:24px\"><b><a href=/compare/atlas/card/index.html>&#9782; THE FULL DIRECTORY &mdash; every organ has a card</a></b> &middot; any card renders its lineage via one MCP call (<code>nx_eco_graph_png [seed]</code>) &middot; <a href=/compare/atlas/graph>&#9776; walkable graph</a> &middot; <a href=/compare/atlas>&#8592; Atlas home</a></p>" as *u8) 276 pw2(fd, "</div></body></html>" as *u8) 277 sys_close(fd) 278 pw2(2, "wrote pedigree\n" as *u8) 279 return 0 280}