code wiki / _hdl_build / nx_pm_decision_demo.nx

nx_pm_decision_demo.nx source

↩ module page · 105 lines · 7143 B

1// nx_pm_decision_demo.nx -- the PM runs the decision matrix on the 9 roadmap items using the team's 2// per-dimension feedback (hardware/software/user value + time-criticality + effort), and emits a RANKED 3// INVESTMENT RECOMMENDATION (approve the sequence) instead of a this-or-that. Validates clean RACI and the 4// bounded back-and-forth. Writes the recommendation to /tmp/nishi_pm_plan.log. Exit 0 on 9/9. license_tier: ORIGINAL 5 6import "nx_pm_decision_matrix.nx" 7import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 8import "nx_raci_collab.nx" 9import "nx_syscalls.nx" 10 11func dd_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 13// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 14// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 15// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 16func dd_num(v: i64) -> i64 { nxi_out(v); return 0 } 17func dd_fw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,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 dd_fn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 } 23 24func main() -> i64 { 25 dd_puts("=== PM DECISION MATRIX -> ranked investment recommendation (WSJF / Cost-of-Delay / MCDA) ===\n" as *u8) 26 // MCDA weights (provisional; to be tuned by the /deep-research automated-prioritization findings). 27 let w_hw: i64 = 3; let w_sw: i64 = 3; let w_user: i64 = 4; let w_time: i64 = 2 28 29 let N: i64 = 9 30 let nm: *i64 = sys_mmap(8*N) as *i64 31 let hw: *i64 = sys_mmap(8*N) as *i64 32 let sw: *i64 = sys_mmap(8*N) as *i64 33 let usr: *i64 = sys_mmap(8*N) as *i64 34 let tc: *i64 = sys_mmap(8*N) as *i64 35 let eff: *i64 = sys_mmap(8*N) as *i64 36 // the team's per-dimension feedback (Consulted input), each 0..10; effort in BU from the plan. 37 nm[0]="x86 byte-exact S-class" as *u8 as i64; hw[0]=2; sw[0]=9; usr[0]=2; tc[0]=8; eff[0]=3 38 nm[1]="RV64 toolchain S-class" as *u8 as i64; hw[1]=8; sw[1]=7; usr[1]=2; tc[1]=5; eff[1]=6 39 nm[2]="ARM64 assembler harden" as *u8 as i64; hw[2]=6; sw[2]=5; usr[2]=5; tc[2]=3; eff[2]=6 40 nm[3]="linker/ELF harden" as *u8 as i64; hw[3]=2; sw[3]=7; usr[3]=2; tc[3]=5; eff[3]=2 41 nm[4]="harden TOY app layers" as *u8 as i64; hw[4]=1; sw[4]=5; usr[4]=8; tc[4]=4; eff[4]=2 42 nm[5]="sovereign filesystem" as *u8 as i64; hw[5]=5; sw[5]=7; usr[5]=3; tc[5]=3; eff[5]=16 43 nm[6]="sovereign TCP/IP stack" as *u8 as i64; hw[6]=5; sw[6]=7; usr[6]=4; tc[6]=3; eff[6]=16 44 nm[7]="sovereign kernel beachhead" as *u8 as i64; hw[7]=8; sw[7]=8; usr[7]=2; tc[7]=2; eff[7]=8 45 nm[8]="first-party hardware target" as *u8 as i64; hw[8]=10; sw[8]=5; usr[8]=2; tc[8]=2; eff[8]=8 46 47 let wsjf: *i64 = sys_mmap(8*N) as *i64 48 let okreg: *i64 = sys_mmap(8*N) as *i64 49 var i: i64 = 0 50 while i < N { 51 let cod: i64 = dm_cost_of_delay(hw[i], sw[i], usr[i], tc[i], w_hw, w_sw, w_user, w_time) 52 wsjf[i] = dm_wsjf(cod, eff[i]) 53 okreg[i] = dm_no_regression(hw[i], sw[i], usr[i]) 54 i = i + 1 55 } 56 57 // rank into an ORDERED portfolio (selection by WSJF among ready, no-regression, not-yet-picked items). 58 let picked: *i64 = sys_mmap(8*N) as *i64 59 let ready: *i64 = sys_mmap(8*N) as *i64 60 i = 0; while i < N { picked[i]=0; ready[i]=okreg[i]; i=i+1 } // all deps met here; regression disqualifies 61 let order: *i64 = sys_mmap(8*N) as *i64 62 63 let fd: i64 = sys_openat_append("/tmp/nishi_pm_plan.log" as *u8, 0x1a4) 64 dd_fw(fd, "\n# PM INVESTMENT RECOMMENDATION (WSJF ranked; weights hw=3 sw=3 user=4 time=2; APPROVE the sequence)\n" as *u8) 65 var rank: i64 = 0 66 while rank < N { 67 let pick: i64 = dm_next_pick(wsjf, picked, ready, N) 68 if pick < 0 { rank = N } 69 else { 70 picked[pick] = 1; order[rank] = pick 71 dd_puts(" #" as *u8); dd_num(rank+1); dd_puts(" wsjf=" as *u8); dd_num(wsjf[pick]); dd_puts(" " as *u8); dd_puts(nm[pick] as *u8); dd_puts("\n" as *u8) 72 dd_fw(fd, "INVEST rank=" as *u8); dd_fn(fd, rank+1); dd_fw(fd, " wsjf=" as *u8); dd_fn(fd, wsjf[pick]); dd_fw(fd, " effort=" as *u8); dd_fn(fd, eff[pick]); dd_fw(fd, "BU item=" as *u8); dd_fw(fd, nm[pick] as *u8); dd_fw(fd, "\n" as *u8) 73 rank = rank + 1 74 } 75 } 76 dd_fw(fd, "DECISION: approve this ranked investment (not a this-or-that); re-rank when weights/feedback change.\n" as *u8) 77 sys_close(fd) 78 79 // RACI + back-and-forth validation 80 let rounds: *i64 = sys_mmap(16) as *i64 81 let conv: i64 = collab_run(3, 1, 5, rounds) // 3 objections, 1 resolved/round, max 5 -> converge 82 let esc: i64 = collab_run(5, 1, 2, rounds) // 5 objections, max 2 -> escalate 83 dd_puts(" RACI: clean(1 accountable)=" as *u8); dd_num(raci_clean(1)); dd_puts(" blurred(2)=" as *u8); dd_num(raci_clean(2)); dd_puts(" collab(3,1,5)=" as *u8); dd_puts(collab_label(conv)); dd_puts(" collab(5,1,2)=" as *u8); dd_puts(collab_label(esc)); dd_puts("\n" as *u8) 84 85 let r: *i64 = sys_mmap(16*8) as *i64 86 r[0]=0; if order[0] == 4 { r[0]=1 } // top pick = harden TOY app (highest WSJF) 87 r[1]=0; if wsjf[4] > wsjf[0] { r[1]=1 } // matrix favors value/effort (app > byte-exact) 88 r[2]=0; if order[N-1] == 5 { r[2]=1 } // last = sovereign FS (huge effort, low WSJF) 89 r[3]=0; if raci_clean(1) == 1 { if raci_clean(2) == 0 { r[3]=1 } } // exactly-one-accountable invariant 90 r[4]=0; if raci_may_commit(RACI_ACCOUNTABLE) == 1 { if raci_may_commit(RACI_CONSULTED) == 0 { r[4]=1 } } 91 r[5]=0; if conv == COLLAB_CONVERGED { r[5]=1 } // bounded back-and-forth converges 92 r[6]=0; if esc == COLLAB_ESCALATE { r[6]=1 } // and escalates instead of looping forever 93 r[7]=0; if dm_no_regression(1, 1, 0 - 1) == 0 { r[7]=1 } // a user-regressing item is disqualified 94 var allranked: i64 = 1; i=0; while i<N { if picked[i]!=1 { allranked=0 } i=i+1 } 95 r[8]=allranked // every item placed in the portfolio 96 var pass: i64 = 0; i = 0 97 while i < 9 { pass = pass + r[i]; i = i + 1 } 98 dd_puts("---- passed " as *u8); dd_num(pass); dd_puts("/9 ----\n" as *u8) 99 if pass == 9 { 100 dd_puts(" The PM now recommends a RANKED INVESTMENT (approve the sequence), takes the team's feedback via\n" as *u8) 101 dd_puts(" clean-RACI back-and-forth, and balances hardware+software+user. Written to /tmp/nishi_pm_plan.log.\n" as *u8) 102 sys_exit(0); return 0 103 } 104 dd_puts(" FAIL\n" as *u8); sys_exit(1); return 1 105}