code wiki / _hdl_build / nx_lineage_raci.nx

nx_lineage_raci.nx source

↩ module page · 125 lines · 8304 B

1// nx_lineage_raci.nx -- THE RESPONSIBILITY LINEAGE: marries the god-rooted genesis genealogy with team RACI 2// ownership. Operator 2026-06-25: "integrate the team from the god family history up -- who is responsible for 3// what kids in the whole lineage to the end." nx_genesis_trace proves every node ROOTS DOWN to god (orphans=0); 4// THIS organ proves every node ROOTS UP to exactly one accountable TEAM CHAIR (un-owned=0) -- responsibility 5// traceable god->leaf. It JOINS genesis_lineage.tsv (the family tree) with lineage_raci.tsv (the accountability 6// chart: axis|type -> chair), censuses ownership per chair, and NAMES any un-owned node (the actionable gap). 7// Anti-wave liar-kill: a synthetic node whose axis AND type are both unknown MUST flag un-owned, proving the 8// gap detector has teeth. Data-driven (Cardinal 11): a new lineage axis = a new chart row, no recompile. 9// Sovereign: nx_syscalls only (no gcc/sed/awk). main() is the self-validating gate. expect_exit: 0 license_tier: ORIGINAL 10import "nx_syscalls.nx" 11import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 12const LIN_MAGIC_1024: i64 = 1024 13 14const LIN_FILE: *u8 = "knowledge/registry/genesis_lineage.tsv" 15const CHART_FILE: *u8 = "knowledge/registry/lineage_raci.tsv" 16 17func lr_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 18// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 19// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 20// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 21// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 22func lr_putn(v: i64) -> i64 { nxi_out(v); return 0 } 23func lr_streq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } 24 25// copy TAB field f (0-based) of line[ls,le) into a fresh NUL-term mmap; returns ptr ("" if field absent). 26func lr_field(b: *u8, ls: i64, le: i64, f: i64) -> *u8 { 27 var cur: i64=0; var i: i64=ls 28 while cur < f { if i >= le { let e: *u8=sys_mmap(2); e[0]=0 as u8; return e } if b[i]==(9 as u8){cur=cur+1} i=i+1 } 29 let out: *u8=sys_mmap(256); var o: i64=0 30 while i < le { if b[i]==(9 as u8){i=le} else { if o<255{out[o]=b[i];o=o+1} i=i+1 } } 31 out[o]=0 as u8; return out 32} 33// split data[0..n) into rows (skip '#' comments + empty), fill rs[] (row start ptr) + rl[] (row len). returns count. 34func lr_rows(data: *u8, n: i64, rs: *i64, rl: *i64, cap: i64) -> i64 { 35 var k: i64=0; var ls: i64=0; var i: i64=0 36 while i <= n { 37 var atend: i64=0 38 if i==n { atend=1 } 39 if i<n { if data[i]==(10 as u8){atend=1} } 40 if atend==1 { if i>ls { if data[ls]!=(35 as u8){ if k<cap { rs[k]=(data as i64)+ls; rl[k]=i-ls; k=k+1 } } } ls=i+1 } 41 i=i+1 42 } 43 return k 44} 45// chart lookup: return the chair for `needle` (exact key match), or 0 if absent. 46func lr_lookup(keys: *i64, roles: *i64, nk: i64, needle: *u8) -> i64 { 47 var i: i64=0 48 while i < nk { if lr_streq(keys[i] as *u8, needle)==1 { return roles[i] } i=i+1 } 49 return 0 50} 51// resolve a node's accountable chair from (axis,type): axis row first, else type:<type>, else 0 (un-owned). 52func lr_resolve(keys: *i64, roles: *i64, nk: i64, axis: *u8, typ: *u8) -> i64 { 53 if lr_streq(axis, "-" as *u8)==0 { let r: i64=lr_lookup(keys, roles, nk, axis); if r!=0 { return r } } 54 let tk: *u8=sys_mmap(64); var o: i64=0; let p: *u8="type:" as *u8; var j: i64=0 55 while p[j]!=(0 as u8){ tk[o]=p[j]; o=o+1; j=j+1 } 56 var t2: i64=0; while typ[t2]!=(0 as u8){ tk[o]=typ[t2]; o=o+1; t2=t2+1 } 57 tk[o]=0 as u8 58 return lr_lookup(keys, roles, nk, tk) 59} 60 61func main() -> i64 { 62 lr_puts("=== nx_lineage_raci: WHO is responsible for every kid in the god-rooted lineage (ownership twin of nx_genesis_trace) ===\n" as *u8) 63 // --- load the accountability chart (axis|type -> chair) --- 64 let cb: *i64 = sys_mmap(16) as *i64 65 let cdata: *u8 = sys_read_file(CHART_FILE, cb) 66 if (cdata as i64)==0 { lr_puts("FATAL: lineage_raci.tsv unreadable\n" as *u8); sys_exit(2); return 2 } 67 let crs: *i64 = sys_mmap(8*256) as *i64; let crl: *i64 = sys_mmap(8*256) as *i64 68 let nk: i64 = lr_rows(cdata, cb[0], crs, crl, 256) 69 let keys: *i64 = sys_mmap(8*256) as *i64; let roles: *i64 = sys_mmap(8*256) as *i64 70 var ci: i64=0 71 while ci < nk { keys[ci]=lr_field(crs[ci] as *u8, 0, crl[ci], 0) as i64; roles[ci]=lr_field(crs[ci] as *u8, 0, crl[ci], 1) as i64; ci=ci+1 } 72 // --- load the god-rooted lineage (the family tree) --- 73 let lb: *i64 = sys_mmap(16) as *i64 74 let ldata: *u8 = sys_read_file(LIN_FILE, lb) 75 if (ldata as i64)==0 { lr_puts("FATAL: genesis_lineage.tsv unreadable\n" as *u8); sys_exit(2); return 2 } 76 let lrs: *i64 = sys_mmap(8*LIN_MAGIC_1024) as *i64; let lrl: *i64 = sys_mmap(8*LIN_MAGIC_1024) as *i64 77 let nn: i64 = lr_rows(ldata, lb[0], lrs, lrl, LIN_MAGIC_1024) 78 lr_puts(" chart_keys="); lr_putn(nk); lr_puts(" lineage_nodes="); lr_putn(nn); lr_puts("\n" as *u8) 79 80 // --- the 7 chairs we census (the ownership-map vocabulary) --- 81 let chairs: *i64 = sys_mmap(8*8) as *i64 82 chairs[0]="CONDUCTOR" as *u8 as i64; chairs[1]="ENGINEER" as *u8 as i64; chairs[2]="BUILDER" as *u8 as i64 83 chairs[3]="RESEARCHER" as *u8 as i64; chairs[4]="LIBRARIAN" as *u8 as i64; chairs[5]="REFEREE" as *u8 as i64 84 chairs[6]="PM" as *u8 as i64 85 let ccount: *i64 = sys_mmap(8*8) as *i64; var z: i64=0; while z<7 { ccount[z]=0; z=z+1 } 86 87 var owned: i64=0; var orphan: i64=0 88 var i: i64=0 89 while i < nn { 90 let id: *u8 = lr_field(lrs[i] as *u8, 0, lrl[i], 0) 91 let typ: *u8 = lr_field(lrs[i] as *u8, 0, lrl[i], 1) 92 let axis: *u8 = lr_field(lrs[i] as *u8, 0, lrl[i], 3) 93 let chair: i64 = lr_resolve(keys, roles, nk, axis, typ) 94 if chair==0 { 95 orphan=orphan+1 96 lr_puts(" [UN-OWNED] "); lr_puts(id); lr_puts(" axis="); lr_puts(axis); lr_puts(" type="); lr_puts(typ); lr_puts(" <- no chair claims this kid\n" as *u8) 97 } else { 98 owned=owned+1 99 var ch2: i64=0; while ch2<7 { if lr_streq(chairs[ch2] as *u8, chair as *u8)==1 { ccount[ch2]=ccount[ch2]+1 } ch2=ch2+1 } 100 } 101 i=i+1 102 } 103 104 lr_puts("-- OWNERSHIP CENSUS (accountable chair per node, god->leaf) --\n" as *u8) 105 var c3: i64=0 106 while c3<7 { lr_puts(" "); lr_puts(chairs[c3] as *u8); lr_puts(" owns "); lr_putn(ccount[c3]); lr_puts(" lineage nodes\n" as *u8); c3=c3+1 } 107 lr_puts(" owned="); lr_putn(owned); lr_puts(" UN-OWNED(orphan responsibility)="); lr_putn(orphan); lr_puts(" of "); lr_putn(nn); lr_puts("\n" as *u8) 108 109 // --- anti-wave LIAR-KILL: a node with a bogus axis AND bogus type MUST resolve to un-owned --- 110 let fake: i64 = lr_resolve(keys, roles, nk, "zzz-bogus-axis" as *u8, "zzz-bogus-type" as *u8) 111 var ok: i64=1 112 if fake!=0 { ok=0 } // the gap detector must NOT invent an owner for an unknown node 113 lr_puts("-- liar-kill: synthetic unknown node resolved owner="); if fake==0 { lr_puts("UN-OWNED (correct)\n" as *u8) } else { lr_puts(fake as *u8); lr_puts(" (WRONG -- detector blind)\n" as *u8) } 114 115 let lf: i64 = sys_openat_append("knowledge/status/lineage_raci.log" as *u8, 420) 116 if lf >= 0 { 117 sys_write(lf, "LINEAGE-RACI nodes=" as *u8, 19); let nb: *u8=sys_mmap(28); var m: i64=nn; let tt: *u8=sys_mmap(28); var kk: i64=0; if m==0{tt[0]=48 as u8;kk=1} while m>0{tt[kk]=(48+(m%10)) as u8;m=m/10;kk=kk+1} var ii: i64=0; while ii<kk{nb[ii]=tt[kk-1-ii];ii=ii+1} sys_write(lf, nb, kk) 118 if ok==1 { if orphan==0 { sys_write(lf, " un_owned=0 liarkill=fired verdict=GREEN\n" as *u8, 44) } else { sys_write(lf, " verdict=RED-unowned\n" as *u8, 20) } } else { sys_write(lf, " verdict=RED-liar\n" as *u8, 17) } 119 sys_close(lf) 120 } 121 122 if orphan != 0 { ok=0 } 123 if ok==1 { lr_puts("LINEAGE-RACI verdict=GREEN (every god-rooted node has exactly one accountable chair; responsibility traces god->leaf; liar-kill fired)\n" as *u8); sys_exit(0); return 0 } 124 lr_puts("LINEAGE-RACI verdict=RED (an un-owned node exists OR the detector is blind -> add a chair row to lineage_raci.tsv)\n" as *u8); sys_exit(1); return 1 125}