code wiki / _hdl_build / nx_maint_council.nx

nx_maint_council.nx source

↩ module page · 76 lines · 3492 B

1// nx_maint_council.nx -- the MAINTAINER organ: reports ecosystem maintenance cost + technical debt to the 2// PM so we keep optimizing and avoid Y2K-style costly refactoring (operator: "flag the maintenance cost... 3// and the technical debt so we can keep optimizing the cost... this really is a team activity where all 4// the opinions... should work together to get a clear council viewpoint"). Each debt LENS is an organ's 5// INDEPENDENT opinion (no shared state); the council SYNTHESIZES them with agreement, so no single lens 6// dominates (separation of duties). license_tier: ORIGINAL Reports via nx_pm_review_log; pairs with 7// nx_update_winwinwin (the easy-cross-cutting-update gate). 8 9import "nx_syscalls.nx" 10 11// severity of one lens's independent opinion 12const SEV_NONE: i64 = 0 13const SEV_LOW: i64 = 1 14const SEV_MED: i64 = 2 15const SEV_HIGH: i64 = 3 16 17// the independent debt lenses (each forms its own opinion) 18const ML_DUPLICATION: i64 = 0 // DRY: a pattern repeated in 3+ places -> belongs in shared/ 19const ML_COUPLING: i64 = 1 // blast radius: one change forces edits across many modules 20const ML_MAGIC: i64 = 2 // magic numbers / hardcoded values not in config 21const ML_ABSTRACTION: i64 = 3 // missing base class / shared lib (copy-paste boilerplate) 22const ML_DRIFT: i64 = 4 // dead / stale / divergent copies 23const ML_NLENS: i64 = 5 24 25// council verdict actions 26const MC_OK: i64 = 0 // healthy -- monitor 27const MC_SCHEDULE: i64 = 1 // debt accruing -- schedule a refactor before it compounds 28const MC_REFACTOR: i64 = 2 // debt critical -- refactor now (the Y2K-avoidance trigger) 29 30// COUNCIL central opinion = MEDIAN severity (robust to a single outlier lens). 31func mc_council_severity(op: *i64, n: i64) -> i64 { 32 var c0: i64=0; var c1: i64=0; var c2: i64=0; var c3: i64=0; var i: i64=0 33 while i < n { 34 if op[i] == 0 { c0 = c0 + 1 } 35 if op[i] == 1 { c1 = c1 + 1 } 36 if op[i] == 2 { c2 = c2 + 1 } 37 if op[i] == 3 { c3 = c3 + 1 } 38 i = i + 1 39 } 40 let half: i64 = n / 2 41 var cum: i64 = c0 42 if cum > half { return 0 } 43 cum = cum + c1 44 if cum > half { return 1 } 45 cum = cum + c2 46 if cum > half { return 2 } 47 return 3 48} 49 50// COUNCIL action by AGREEMENT (majority), not any single lens. 51func mc_council_action(op: *i64, n: i64) -> i64 { 52 var highs: i64 = 0; var meds: i64 = 0; var i: i64 = 0 53 while i < n { 54 if op[i] >= SEV_HIGH { highs = highs + 1 } 55 if op[i] >= SEV_MED { meds = meds + 1 } 56 i = i + 1 57 } 58 if highs * 2 >= n { return MC_REFACTOR } 59 if meds * 2 >= n { return MC_SCHEDULE } 60 return MC_OK 61} 62 63// relative maintenance cost: modules*mod_w + loc_k*loc_w + avg_fanout*fan_w (weights are DATA, not magic). 64func mc_maint_cost(modules: i64, loc_k: i64, avg_fanout: i64, mod_w: i64, loc_w: i64, fan_w: i64) -> i64 { 65 return modules * mod_w + loc_k * loc_w + avg_fanout * fan_w 66} 67 68// UPDATE BLAST-RADIUS (permil): fraction of modules a cross-cutting change must touch. LOW = easy update. 69func mc_blast_radius_permil(touched: i64, total: i64) -> i64 { if total <= 0 { return 0 } return touched * 1000 / total } 70func mc_easy_update(blast_permil: i64, threshold_permil: i64) -> i64 { if blast_permil <= threshold_permil { return 1 } return 0 } 71 72func mc_action_label(a: i64) -> *u8 { 73 if a == MC_REFACTOR { return "REFACTOR-NOW" as *u8 } 74 if a == MC_SCHEDULE { return "SCHEDULE-REFACTOR" as *u8 } 75 return "OK-MONITOR" as *u8 76}