code wiki / _hdl_build / nx_eco_graph_wiki.nx
nx_eco_graph_wiki.nx source
↩ module page · 55 lines · 4343 B
1// nx_eco_graph_wiki.nx -- R3: LIVING DOCUMENTATION of the living ecosystem graph. Renders the graph (loaded
2// from the SOVEREIGN seg_store) as a sovereign ZERO-JS WALKABLE HTML page: every organ anchored (id=name),
3// with links UP (imports → toward god) and DOWN (imported by → children) so you click through the lineage.
4// Reading the graph is sovereign; writing the .html to SERVE is legitimate interop@boundary. Composes
5// nx_eco_graph (store + queries). Usage: nx_eco_graph_wiki <store-prefix> [out.html]. license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_eco_graph.nx"
8
9func fw(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 }
10func fwn(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 }
11func fwname(fd: i64, g: *EcoGraph, idx: i64) -> i64 { let off:i64=g.node_off[idx]; var i:i64=0; while g.arena[off+i]!=(0 as u8){i=i+1} sys_write(fd, ((g.arena as i64)+off) as *u8, i); return 0 }
12
13// render the whole (finalized) graph as a walkable zero-JS page to fd. (node names have no spaces -> unquoted
14// HTML attrs are valid, sidestepping quote-escaping.)
15func egw_render(fd: i64, g: *EcoGraph) -> i64 {
16 fw(fd, "<!doctype html><html lang=en><head><meta charset=utf-8><title>Nishi Ecosystem Graph</title><style>body{font:14px/1.5 -apple-system,Segoe UI,sans-serif;background:#0d1018;color:#e8ecf6;margin:0;padding:20px}h1{color:#c9a0ff}.n{border-bottom:1px solid #26304a;padding:7px 0}.m{color:#93a0b8;font-size:12px}.orph{color:#ff9a6b}.up a{color:#7ee0a0}.down a{color:#c9a0ff}a{text-decoration:none}.up,.down{margin-left:14px;font-size:12px}b{color:#e8ecf6}:target{background:#1a2030}</style></head><body>" as *u8)
17 fw(fd, "<h1>Nishi Ecosystem Graph — living dependency lineage</h1><p class=m>nodes=" as *u8); fwn(fd, g.node_count)
18 fw(fd, " edges=" as *u8); fwn(fd, g.edge_count); fw(fd, " · each organ: ↑ imports (roots to god) · ↓ imported by (children). Sovereign, zero-JS, generated from the seg_store.</p>" as *u8)
19 var i: i64 = 0
20 while i < g.node_count {
21 fw(fd, "<div class=n id=" as *u8); fwname(fd, g, i); fw(fd, "><b>" as *u8); fwname(fd, g, i); fw(fd, "</b> <span class=m>Ca=" as *u8)
22 let ca: i64 = eg_ca(g, i); let ce: i64 = eg_ce(g, i)
23 fwn(fd, ca); fw(fd, " Ce=" as *u8); fwn(fd, ce); fw(fd, "</span>" as *u8)
24 if ca == 0 { fw(fd, " <span class=orph>[entry/orphan]</span>" as *u8) }
25 fw(fd, "<div class=up>↑ " as *u8)
26 var p: i64 = g.out_head[i]; let pe: i64 = g.out_head[i+1]
27 if p == pe { fw(fd, "(root/leaf)" as *u8) }
28 while p < pe { fw(fd, "<a href=#" as *u8); fwname(fd, g, g.out_list[p]); fw(fd, ">" as *u8); fwname(fd, g, g.out_list[p]); fw(fd, "</a> " as *u8); p = p + 1 }
29 fw(fd, "</div><div class=down>↓ " as *u8)
30 var q: i64 = g.in_head[i]; let ie: i64 = g.in_head[i+1]
31 let nin: i64 = ie - q
32 if nin == 0 { fw(fd, "(nothing imports it)" as *u8) }
33 var cnt: i64 = 0
34 while q < ie { if cnt < 60 { fw(fd, "<a href=#" as *u8); fwname(fd, g, g.in_list[q]); fw(fd, ">" as *u8); fwname(fd, g, g.in_list[q]); fw(fd, "</a> " as *u8) } cnt = cnt + 1; q = q + 1 }
35 if nin > 60 { fw(fd, "… (+" as *u8); fwn(fd, nin - 60); fw(fd, " more)" as *u8) }
36 fw(fd, "</div></div>" as *u8)
37 i = i + 1
38 }
39 fw(fd, "</body></html>" as *u8)
40 return 0
41}
42
43func main(argc: i64, argv: *i64) -> i64 {
44 if argc < 2 { fw(1, "usage: nx_eco_graph_wiki <store-prefix> [out.html]\n" as *u8); return 2 }
45 let g: *EcoGraph = eg_load(argv[1] as *u8)
46 if (g as i64) == 0 { fw(1, "ERROR: store not found\n" as *u8); return 3 }
47 var outp: *u8 = "knowledge/eco_graph.html\x00" as *u8
48 if argc >= 3 { outp = argv[2] as *u8 }
49 let fd: i64 = sys_openat_wr(outp, 0x1a4)
50 if fd < 0 { fw(1, "ERROR: cannot open out\n" as *u8); return 4 }
51 egw_render(fd, g)
52 sys_close(fd)
53 fw(1, "wrote living-doc HTML from the SOVEREIGN store -> " as *u8); fw(1, outp); fw(1, " (" as *u8); fwn(1, g.node_count); fw(1, " organs)\n" as *u8)
54 return 0
55}