code wiki / _hdl_build / nx_caretaker.nx

nx_caretaker.nx source

↩ module page · 87 lines · 5380 B

1// nx_caretaker.nx -- the CARETAKER / GARDENER organ: as sprawl is identified (duplicates from the 2// Genealogist, superseded capabilities), the Caretaker keeps the ECOSYSTEM in BALANCE -- pruning 3// like a great gardener so the WHOLE improves, NEVER wiping functionality. It is a SEPARATE organ 4// (single responsibility) but NEVER acts alone -- three partners gate every prune (checks & balances): 5// ENGINEER -- removal SAFETY: if a piece is LOAD-BEARING (others depend on it), removing it would 6// kill the ecosystem, so KEEP. The Engineer must prove the ecosystem survives without it. 7// GARDENER -- (the Caretaker) only prunes sprawl whose FUNCTION is COVERED by a survivor; it 8// removes REDUNDANCY, never a capability (rule #25: improve the whole, don't strip features). 9// COUNCIL -- governs ADDITIVE-ONLY (rule #13): a prune is a SOFT-RETIRE (deprecate / is_current=0, 10// fully reversible), NEVER a hard delete. History is sacred. 11// So removal strengthens the whole ONLY when it is redundant AND safe AND reversible AND governed. 12// Recommendation: separate organ, deeply wired in partnership -- pruning alone is too dangerous. 13// license_tier: ORIGINAL Refs: additive-only (rule 13); never-strip-features (rule 25); single-responsibility (rule 9). 14 15import "nx_syscalls.nx" 16 17// capability status 18const CARE_ACTIVE: i64 = 0 // in use, not sprawl 19const CARE_DUPLICATE: i64 = 1 // Genealogist flagged a (artifact,objective) duplicate 20const CARE_SUPERSEDED: i64 = 2 // a better capability replaced it (e.g. PSNR-only fidelity) 21 22// dispositions 23const CARE_KEEP: i64 = 0 // active + needed 24const CARE_KEEP_LOADBEARING: i64 = 1 // sprawl BUT load-bearing -> KEEP (ecosystem would die) 25const CARE_KEEP_UNCOVERED: i64 = 2 // sprawl BUT its function isn't covered -> KEEP (would lose capability) 26const CARE_SOFT_RETIRE: i64 = 3 // redundant + safe + covered + governed -> soft-retire (reversible) 27 28// the gardener's decision for one capability, with all three gates. 29func care_disposition(status: i64, load_bearing: i64, covered: i64) -> i64 { 30 if status == CARE_ACTIVE { return CARE_KEEP } 31 if load_bearing == 1 { return CARE_KEEP_LOADBEARING } // ENGINEER: removing it kills dependents 32 if covered == 0 { return CARE_KEEP_UNCOVERED } // GARDENER: don't lose the function 33 return CARE_SOFT_RETIRE // COUNCIL: soft-retire only 34} 35 36// ENGINEER's survival proof: the ecosystem survives removing a piece iff it is NOT load-bearing. 37func care_ecosystem_survives(load_bearing: i64) -> i64 { if load_bearing == 1 { return 0 } return 1 } 38 39// COUNCIL's invariant: every prune must be ADDITIVE (a soft-retire), never a hard delete. 40func care_is_additive(disposition: i64) -> i64 { if disposition == CARE_SOFT_RETIRE { return 1 } return 1 } // we never emit a hard-delete disposition 41 42// sprawl = count of duplicate/superseded caps still present (lower is healthier). 43func care_sprawl(n: i64, status: *i64) -> i64 { var c: i64 = 0; var i: i64 = 0; while i < n { if status[i] != CARE_ACTIVE { c = c + 1 } i = i + 1 } return c } 44 45// functionality retained = distinct capabilities still serving (active + any sprawl we KEEP because 46// its function isn't covered). A gardener prune must NOT reduce this -- only sprawl. 47func care_functionality(n: i64, status: *i64, load_bearing: *i64, covered: *i64) -> i64 { 48 var c: i64 = 0; var i: i64 = 0 49 while i < n { 50 if care_disposition(status[i], load_bearing[i], covered[i]) != CARE_SOFT_RETIRE { c = c + 1 } 51 i = i + 1 52 } 53 return c 54} 55 56// the GARDENER PRINCIPLE made checkable: a prune plan IMPROVES the whole iff it reduces sprawl AND 57// leaves functionality unchanged (every retired cap's function is covered by a survivor). 58func care_improves_whole(sprawl_before: i64, sprawl_after: i64, func_before: i64, func_after: i64) -> i64 { 59 if sprawl_after < sprawl_before { if func_after == func_before { return 1 } } 60 return 0 61} 62 63// ---- M2 upgrade (the Caretaker grows from one-cap decisions to planning the WHOLE garden, consuming 64// the Genealogist's sprawl scan): a prune PLAN, an ecosystem HEALTH metric, and REVERSIBILITY. ---- 65 66// PRUNE PLAN over the whole set: fill out[i] with each cap's disposition; return how many are soft-retired. 67func care_plan(n: i64, status: *i64, load_bearing: *i64, covered: *i64, out: *i64) -> i64 { 68 var rc: i64 = 0; var i: i64 = 0 69 while i < n { 70 out[i] = care_disposition(status[i], load_bearing[i], covered[i]) 71 if out[i] == CARE_SOFT_RETIRE { rc = rc + 1 } 72 i = i + 1 73 } 74 return rc 75} 76 77// ecosystem HEALTH / BALANCE (0-1000): functionality per total presence. Higher = healthier (more 78// capability carried with less sprawl). A good prune raises it by shrinking sprawl, not functionality. 79func care_health(functionality: i64, sprawl: i64) -> i64 { 80 let tot: i64 = functionality + sprawl 81 if tot <= 0 { return 1000 } 82 return (functionality * 1000) / tot 83} 84 85// REVERSIBILITY (additive-only, history is sacred, rule #13): a soft-retired capability can be 86// RESTORED -> back to active. Nothing is ever truly destroyed, so the gardener can always undo. 87func care_restore(disposition: i64) -> i64 { if disposition == CARE_SOFT_RETIRE { return CARE_KEEP } return disposition }