code wiki / _hdl_build / nx_genealogist.nx

nx_genealogist.nx source

↩ module page · 93 lines · 4407 B

1// nx_genealogist.nx -- the GENEALOGIST: prevent capability DUPLICATION (operator: don't rebuild what 2// we already have). Before the Builder authors a capability, the Genealogist checks the registry for 3// an equivalent. A capability has a two-axis SIGNATURE: (artifact_kind, objective_kind). It is a 4// DUPLICATE only if BOTH match -- so "allocation optimizing IMPORTANCE" (imatrix) and "allocation 5// optimizing PERCEPTION" are DIFFERENT capabilities (same artifact, new objective = novel), but 6// proposing imatrix twice, or re-proposing PSNR fidelity, is caught and refused. This keeps the 7// 100+ caps from bloating into near-duplicates and forces REUSE of what exists. RACI: the 8// Genealogist guards lineage (it does not build or verify). license_tier: ORIGINAL Refs: code-hygiene organ. 9 10import "nx_syscalls.nx" 11 12// artifact kinds (what is produced) 13const ART_ALLOC: i64 = 1 // a bit/resource allocation 14const ART_FIDELITY: i64 = 2 // a fidelity/quality metric 15const ART_SEARCH: i64 = 3 // a search/synthesis engine 16const ART_KERNEL: i64 = 4 // a compute kernel 17const ART_ORGAN: i64 = 5 // a crew organ 18// objective kinds (what it optimizes / measures) 19const OBJ_IMPORTANCE: i64 = 1 20const OBJ_DISTORTION: i64 = 2 21const OBJ_PERCEPTION: i64 = 3 22const OBJ_ENERGY: i64 = 4 23const OBJ_GENERIC: i64 = 5 24const OBJ_COMPOSITE: i64 = 6 25 26const GEN_NOVEL: i64 = 0 27const GEN_DUPLICATE: i64 = 1 28 29// is the proposed (art, obj) already in the registry? duplicate iff BOTH axes match. 30func gen_is_duplicate(art: i64, obj: i64, reg_art: *i64, reg_obj: *i64, n: i64) -> i64 { 31 var i: i64 = 0 32 while i < n { 33 if reg_art[i] == art { if reg_obj[i] == obj { return GEN_DUPLICATE } } 34 i = i + 1 35 } 36 return GEN_NOVEL 37} 38 39// the guard the Builder calls before authoring: 1 = clear to build (novel), 0 = refuse (duplicate, reuse). 40func gen_clear_to_build(art: i64, obj: i64, reg_art: *i64, reg_obj: *i64, n: i64) -> i64 { 41 if gen_is_duplicate(art, obj, reg_art, reg_obj, n) == GEN_DUPLICATE { return 0 } 42 return 1 43} 44 45// register a newly-built capability's signature (additive -- history is sacred). 46func gen_register(art: i64, obj: i64, reg_art: *i64, reg_obj: *i64, n: i64) -> i64 { 47 reg_art[n] = art; reg_obj[n] = obj; return n + 1 48} 49 50// ---- M2 upgrade (the Genealogist grows from one-query exact-match to scanning + reporting + feeding 51// the Caretaker): NEAR-duplicate detection, whole-registry sprawl scan, supersession detection. ---- 52 53// are two objectives RELATED (near-duplicate territory)? importance is a distortion proxy, so 54// {IMPORTANCE, DISTORTION} overlap; perception/energy/generic are distinct objectives. 55func gen_obj_related(o1: i64, o2: i64) -> i64 { 56 if o1 == OBJ_IMPORTANCE { if o2 == OBJ_DISTORTION { return 1 } } 57 if o1 == OBJ_DISTORTION { if o2 == OBJ_IMPORTANCE { return 1 } } 58 return 0 59} 60 61// relatedness of two signatures: 3 = exact duplicate, 2 = near-duplicate (same artifact + related 62// objective, worth a human/Caretaker review), 1 = same artifact but distinct objective, 0 = unrelated. 63func gen_relatedness(a1: i64, o1: i64, a2: i64, o2: i64) -> i64 { 64 if a1 != a2 { return 0 } 65 if o1 == o2 { return 3 } 66 if gen_obj_related(o1, o2) == 1 { return 2 } 67 return 1 68} 69 70// SPRAWL SCAN: the Genealogist now sweeps the WHOLE registry (not one query) and reports the exact- 71// duplicate and near-duplicate pair counts -> a sprawl metric the Caretaker acts on. (M2 autonomy.) 72func gen_sprawl_scan(n: i64, reg_art: *i64, reg_obj: *i64, out_exact: *i64, out_near: *i64) -> i64 { 73 var ex: i64 = 0; var nr: i64 = 0; var i: i64 = 0 74 while i < n { 75 var j: i64 = i + 1 76 while j < n { 77 let rel: i64 = gen_relatedness(reg_art[i], reg_obj[i], reg_art[j], reg_obj[j]) 78 if rel == 3 { ex = ex + 1 } 79 if rel == 2 { nr = nr + 1 } 80 j = j + 1 81 } 82 i = i + 1 83 } 84 out_exact[0] = ex; out_near[0] = nr 85 return ex + nr 86} 87 88// SUPERSESSION: does a new capability supersede an old one (same signature AND strictly better)? 89// 1 -> hand the old cap to the Caretaker as a soft-retire candidate (the Genealogist->Caretaker wire). 90func gen_supersedes(art: i64, obj: i64, new_score: i64, old_art: i64, old_obj: i64, old_score: i64) -> i64 { 91 if art == old_art { if obj == old_obj { if new_score > old_score { return 1 } } } 92 return 0 93}