code wiki / (root) / nx_atlas_traits.nx

nx_atlas_traits.nx source

↩ module page · 168 lines · 11889 B

1// nx_atlas_traits.nx -- the EXTENSIBLE trait engine for the Living Capability Atlas. 2// 3// Operator 2026-07-17: "full atlas scope immediately" + "make sure its extensible too on these traits 4// and other things so we dont get locked in and can grow them." 5// 6// DESIGN = ANTI-LOCK-IN BY CONSTRUCTION. Nothing about the trait set, the node kinds, or the computation 7// methods is hardcoded into the card struct. They are DATA-DRIVEN REGISTRIES: 8// * TRAIT REGISTRY -- each trait = (key, axis, computed_by, applies_to_kinds, glyph). Grow it by 9// adding ONE row (tr_def below) + optionally ONE dispatch arm. The GRADER LOOP IS 10// GENERIC over the registry -- it never names a specific trait. 11// * KIND REGISTRY -- node kinds span digital-organ + physical + STEM + bio + product + workflow + 12// agent (open enum; add a row). Full-scope from day one. 13// * CARD -- an OPEN trait-set (key->value bag), NOT fixed columns. Any registered trait 14// attaches to any applicable node. New traits appear on old cards for free. 15// * COMPUTED_BY -- a small dispatch (cb_eval): DISK / ALLOWLIST / POLICY today; MATERIAL / PROOF / 16// BIO / WMS / CREW / SWARM declared-but-pending (honest: a trait can exist in the 17// registry before its data source does -- that IS the growth path, not a blocker). 18// So the atlas grows by editing DATA (registry rows), never by re-cutting the card. That is the extensibility. 19// license_tier: ORIGINAL 20import "nx_gate.nx" 21 22// ---- axes (open; add a name) -------------------------------------------------------------------- 23const AX_EXPOSURE: i64 = 0 24const AX_PARTICIPATE: i64 = 1 25const AX_LINEAGE: i64 = 2 26const AX_PHYSICAL: i64 = 3 27const AX_STEM: i64 = 4 28const AX_BIO: i64 = 5 29func ax_name(a: i64) -> *u8 { 30 if a==AX_EXPOSURE { return "exposure " as *u8 } 31 if a==AX_PARTICIPATE { return "participate" as *u8 } 32 if a==AX_LINEAGE { return "lineage " as *u8 } 33 if a==AX_PHYSICAL { return "physical " as *u8 } 34 if a==AX_STEM { return "stem " as *u8 } 35 if a==AX_BIO { return "bio " as *u8 } 36 return "??? " as *u8 37} 38// ---- node kinds (open; add a name) -------------------------------------------------------------- 39const K_DIGITAL: i64 = 1 40const K_PHYSICAL: i64 = 2 41const K_STEM: i64 = 4 42const K_BIO: i64 = 8 43const K_PRODUCT: i64 = 16 44const K_WORKFLOW: i64 = 32 45const K_AGENT: i64 = 64 46const K_ALL: i64 = 127 47// ---- computed_by methods (the dispatch; add an arm to add a source) ----------------------------- 48const CB_DISK: i64 = 0 // organ opens on disk 49const CB_ALLOWLIST: i64 = 1 // node name present in tool_allowlist.conf = on-mcp / is-tool 50const CB_POLICY: i64 = 2 // exposure-policy name-classifier: primitive/gate -> internal-by-policy 51const CB_DEBT: i64 = 3 // DERIVED: built AND not on-mcp AND not internal-by-policy 52const CB_PENDING: i64 = 9 // declared trait, data source not wired yet (honest growth slot) 53 54// ---- THE TRAIT REGISTRY (grow by adding a tr_def row -- the whole point) ------------------------- 55// returns 1 and fills out-params for trait i; returns 0 past the end. axis/computed_by/applies/glyph. 56func tr_def(i: i64, ax: *i64, cb: *i64, applies: *i64, key: *i64, src: *i64) -> i64 { 57 // exposure axis 58 if i==0 { ax[0]=AX_EXPOSURE; cb[0]=CB_ALLOWLIST; applies[0]=K_DIGITAL|K_WORKFLOW|K_AGENT; key[0]=("on-mcp " as *u8) as i64; src[0]=("tool_allowlist.conf" as *u8) as i64; return 1 } 59 if i==1 { ax[0]=AX_EXPOSURE; cb[0]=CB_PENDING; applies[0]=K_DIGITAL; key[0]=("on-api " as *u8) as i64; src[0]=("mgmt/edge api reg" as *u8) as i64; return 1 } 60 if i==2 { ax[0]=AX_EXPOSURE; cb[0]=CB_POLICY; applies[0]=K_DIGITAL; key[0]=("internal-by-policy" as *u8) as i64; src[0]=("exposure_policy" as *u8) as i64; return 1 } 61 if i==3 { ax[0]=AX_EXPOSURE; cb[0]=CB_DEBT; applies[0]=K_DIGITAL; key[0]=("unexposed-debt " as *u8) as i64; src[0]=("derived" as *u8) as i64; return 1 } 62 // participation axis 63 if i==4 { ax[0]=AX_PARTICIPATE; cb[0]=CB_ALLOWLIST; applies[0]=K_DIGITAL; key[0]=("is-tool " as *u8) as i64; src[0]=("tool_allowlist.conf" as *u8) as i64; return 1 } 64 if i==5 { ax[0]=AX_PARTICIPATE; cb[0]=CB_PENDING; applies[0]=K_DIGITAL|K_WORKFLOW; key[0]=("in-workflow " as *u8) as i64; src[0]=("WMS registry" as *u8) as i64; return 1 } 65 if i==6 { ax[0]=AX_PARTICIPATE; cb[0]=CB_PENDING; applies[0]=K_DIGITAL|K_AGENT; key[0]=("has-agent " as *u8) as i64; src[0]=("crew roster" as *u8) as i64; return 1 } 66 if i==7 { ax[0]=AX_PARTICIPATE; cb[0]=CB_PENDING; applies[0]=K_DIGITAL; key[0]=("runs-on-swarm " as *u8) as i64; src[0]=("nx_swarm_beat" as *u8) as i64; return 1 } 67 // lineage axis 68 if i==8 { ax[0]=AX_LINEAGE; cb[0]=CB_PENDING; applies[0]=K_DIGITAL; key[0]=("roots-to-god " as *u8) as i64; src[0]=("nx_eco_graph" as *u8) as i64; return 1 } 69 if i==9 { ax[0]=AX_LINEAGE; cb[0]=CB_PENDING; applies[0]=K_ALL; key[0]=("maturity-band " as *u8) as i64; src[0]=("nx_maturity_census" as *u8) as i64; return 1 } 70 // ★FULL-SCOPE: physical / STEM / bio traits live in the SAME registry (proves it's not digital-locked). 71 if i==10 { ax[0]=AX_PHYSICAL; cb[0]=CB_PENDING; applies[0]=K_PHYSICAL|K_PRODUCT; key[0]=("food-safe " as *u8) as i64; src[0]=("material-db" as *u8) as i64; return 1 } 72 if i==11 { ax[0]=AX_PHYSICAL; cb[0]=CB_PENDING; applies[0]=K_PHYSICAL|K_PRODUCT; key[0]=("load-bearing " as *u8) as i64; src[0]=("mech-db" as *u8) as i64; return 1 } 73 if i==12 { ax[0]=AX_STEM; cb[0]=CB_PENDING; applies[0]=K_STEM|K_DIGITAL; key[0]=("has-formal-proof " as *u8) as i64; src[0]=("proof-ledger" as *u8) as i64; return 1 } 74 if i==13 { ax[0]=AX_BIO; cb[0]=CB_PENDING; applies[0]=K_BIO|K_PRODUCT; key[0]=("bio-compatible " as *u8) as i64; src[0]=("bio-db" as *u8) as i64; return 1 } 75 return 0 // <-- grow the atlas HERE: add case i==14 ... ; the grader below needs ZERO changes. 76} 77 78func at_have(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 79// substring search: is `needle` present in file `path`? (for ALLOWLIST membership) 80func at_file_has(path: *u8, needle: *u8) -> i64 { 81 let szp: *i64 = sys_mmap(16) as *i64 82 let buf: *u8 = sys_read_file(path, szp) 83 let n: i64 = szp[0] 84 if n <= 0 { return 0 } 85 var nl: i64 = 0; while needle[nl]!=(0 as u8){nl=nl+1} 86 var i: i64 = 0 87 while i + nl <= n { 88 var k: i64 = 0 89 while k < nl { if buf[i+k]!=needle[k] { k = nl + 9 } else { k = k + 1 } } 90 if k == nl { return 1 } 91 i = i + 1 92 } 93 return 0 94} 95// exposure-policy name classifier: a primitive (std_/fc_/sys_) or gate/test = internal-by-policy. 96func at_is_internal(name: *u8) -> i64 { 97 if name[0]==(115 as u8) { if name[1]==(116 as u8) { if name[2]==(100 as u8) { if name[3]==(95 as u8) { return 1 } } } } // std_ 98 if name[0]==(115 as u8) { if name[1]==(121 as u8) { if name[2]==(115 as u8) { if name[3]==(95 as u8) { return 1 } } } } // sys_ 99 if name[0]==(102 as u8) { if name[1]==(99 as u8) { if name[2]==(95 as u8) { return 1 } } } // fc_ 100 var i: i64=0; while name[i]!=(0 as u8){i=i+1} 101 if i>=5 { if name[i-5]==(95 as u8){ if name[i-4]==(103 as u8){ if name[i-3]==(97 as u8){ if name[i-2]==(116 as u8){ if name[i-1]==(101 as u8){ return 1 } } } } } } // _gate 102 return 0 103} 104// THE GENERIC DISPATCH -- add an arm to wire a new computed_by source. node_path used by DISK/POLICY. 105func cb_eval(cb: i64, node_name: *u8, node_path: *u8) -> *u8 { 106 if cb==CB_DISK { if at_have(node_path)==1 { return "yes" as *u8 } return "no" as *u8 } 107 if cb==CB_ALLOWLIST { if at_file_has("tool_allowlist.conf" as *u8, node_name)==1 { return "yes" as *u8 } return "no" as *u8 } 108 if cb==CB_POLICY { if at_is_internal(node_name)==1 { return "yes" as *u8 } return "no" as *u8 } 109 if cb==CB_DEBT { 110 let built: i64 = at_have(node_path) 111 let mcp: i64 = at_file_has("tool_allowlist.conf" as *u8, node_name) 112 let intl: i64 = at_is_internal(node_name) 113 if built==1 { if mcp==0 { if intl==0 { return "YES" as *u8 } } } 114 return "no" as *u8 115 } 116 return "pending" as *u8 // CB_PENDING: declared, source not wired -- the growth slot 117} 118 119// ---- THE GENERIC GRADER: never names a trait. iterates the registry, dispatches, emits the open card. 120func at_grade(node_name: *u8, node_path: *u8, node_kind: i64) -> i64 { 121 gw(" card " as *u8); gw(node_name); gw(" [kind=" as *u8); gn(node_kind); gw("]\n" as *u8) 122 let ax: *i64 = sys_mmap(8) as *i64 123 let cb: *i64 = sys_mmap(8) as *i64 124 let ap: *i64 = sys_mmap(8) as *i64 125 let ky: *i64 = sys_mmap(8) as *i64 126 let sc: *i64 = sys_mmap(8) as *i64 127 var i: i64 = 0 128 while tr_def(i, ax, cb, ap, ky, sc) == 1 { 129 if (ap[0] & node_kind) != 0 { // trait applies to this node kind 130 let key: *u8 = ky[0] as *u8 131 let val: *u8 = cb_eval(cb[0], node_name, node_path) 132 gw(" " as *u8); gw(ax_name(ax[0])); gw(" " as *u8); gw(key); gw(" = " as *u8); gw(val) 133 if cb[0]==CB_PENDING { gw(" (source: " as *u8); gw(sc[0] as *u8); gw(")" as *u8) } 134 gw("\n" as *u8) 135 } 136 i = i + 1 137 } 138 return 0 139} 140 141func main() -> i64 { 142 gw("=== nx_atlas_traits: the EXTENSIBLE, full-scope trait engine (registry-driven, anti-lock-in) ===\n" as *u8) 143 gw(" add a trait = ONE tr_def row (+ maybe ONE cb_eval arm); the grader loop below changes ZERO lines.\n\n" as *u8) 144 145 // count the registry (proves it's data-driven, not a fixed schema) 146 let ax: *i64 = sys_mmap(8) as *i64; let cb: *i64 = sys_mmap(8) as *i64; let ap: *i64 = sys_mmap(8) as *i64 147 let ky: *i64 = sys_mmap(8) as *i64; let sc: *i64 = sys_mmap(8) as *i64 148 var tn: i64 = 0; var live: i64 = 0 149 while tr_def(tn, ax, cb, ap, ky, sc) == 1 { if cb[0]!=CB_PENDING { live=live+1 } tn = tn + 1 } 150 gw(" registry: " as *u8); gn(tn); gw(" traits across 6 axes (exposure/participate/lineage/physical/stem/bio); " as *u8) 151 gw("computed live=" as *u8); gn(live); gw(", declared-pending=" as *u8); gn(tn-live); gw(" (grow by wiring their source)\n\n" as *u8) 152 153 // grade example nodes ACROSS KINDS -- proving full-scope + that the SAME engine cards a digital organ, 154 // a physical capability, a STEM capability, and a bio capability with ZERO per-kind code. 155 gw(" -- worked cards (one engine, every kind) --\n" as *u8) 156 at_grade("nx_quic_hs" as *u8, "runtime/nx_quic_hs.nx" as *u8, K_DIGITAL) 157 at_grade("nx_conn_catalog" as *u8, "runtime/nx_conn_catalog.nx" as *u8, K_DIGITAL) 158 at_grade("std_slen" as *u8, "runtime/nx_std.nx" as *u8, K_DIGITAL) 159 at_grade("food-safe-churn" as *u8, "" as *u8, K_PHYSICAL|K_PRODUCT) 160 at_grade("ml-kem-security-proof" as *u8, "" as *u8, K_STEM) 161 at_grade("bird-chirp-dog-toy" as *u8, "" as *u8, K_BIO|K_PRODUCT) 162 163 gw("\n=== extensible=YES (registry rows), full-scope=YES (digital+physical+stem+bio one engine), open-card=YES (trait-set not columns) ===\n" as *u8) 164 gw("NEXT: (1) walk the eco_graph 16k as digital nodes; (2) wire the PENDING sources one at a time (each is additive);\n" as *u8) 165 gw(" (3) persist trait registry + cards to knowledge/store/atlas_* (sovereign); (4) the transcript-review loop appends MISSING trait rows.\n" as *u8) 166 sys_exit(0) 167 return 0 168}