code wiki / _hdl_build / nx_pm_cockpit.nx

nx_pm_cockpit.nx source

↩ module page · 111 lines · 4944 B

1// nx_pm_cockpit.nx -- THE PM COCKPIT CLI (operator 2026-07-18): one command that composes the 2// executive / management / operations layers + feedback + honest ROI from the live sovereign 3// planes. A READER-COMPOSER: zero forks, zero duplicated rollup logic -- each tier is measured 4// by the same code path its owning organ uses (see nx_pm_roi_lib.nx header for the laws). 5// argv[1] = mode: "json" (default -> stdout, the MCP/agent interchange) 6// "html" [argv[2] out path, default sites/nishifamily/pm.html] -> the /pm page 7// Runs on the NAS with CWD=nishihost (MCP fork-exec) or anywhere the planes exist. 8// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 9import "nx_pm_roi_lib.nx" 10 11const PMC_ROI_MAXLINES: i64 = 48 12const PMC_HTMLH: i64 = 104 // 'h' of "html" 13const PMC_ARGC_MODE: i64 = 2 14const PMC_ARGC_OUT: i64 = 3 15 16// GREEN rows in a <name>\t<elf>\t<status>[\t<pinned>] registry 17func pmc_count_green(buf: *u8, n: i64) -> i64 { 18 let sp: *i64 = sys_mmap(PM_MAXCOLS*2*8) as *i64 19 var cnt: i64 = 0 20 var i: i64 = 0 21 while i < n { 22 var le: i64 = i 23 var s: i64 = 1 24 while s == 1 { if le >= n { s = 0 } else { if buf[le] == (10 as u8) { s = 0 } else { le = le + 1 } } } 25 if le > i { if buf[i] != (35 as u8) { 26 let nc: i64 = pm_cols(buf, i, le, sp) 27 if nc >= 3 { if pm_slice_eq(buf, sp[4], sp[5], "GREEN" as *u8) == 1 { cnt = cnt + 1 } } 28 } } 29 i = le + 1 30 } 31 return cnt 32} 33 34func main(argc: i64, argv: *i64) -> i64 { 35 var html: i64 = 0 36 var outp: *u8 = "sites/nishifamily/pm.html" as *u8 37 if argc >= PMC_ARGC_MODE { let mo: *u8 = argv[1] as *u8; if mo[0] == (PMC_HTMLH as u8) { html = 1 } } 38 if argc >= PMC_ARGC_OUT { outp = argv[2] as *u8 } 39 40 let m: *i64 = sys_mmap(64*8) as *i64 41 var z: i64 = 0 42 while z < 64 { m[z] = 0; z = z + 1 } 43 44 // EXEC: the live maturity rollup (identical call to the maturity organ -- divergence impossible) 45 let eout: *i64 = sys_mmap(256) as *i64 46 em_rollup_store(ECOMAT_STORE, "knowledge/status/autonomy_meter.log" as *u8, eout, 0) 47 m[S_MAT] = eout[0] 48 m[S_LIAR] = eout[1] 49 m[S_DOM] = eout[2] 50 m[S_SCLASS] = eout[3] 51 m[S_AUT] = eout[5] 52 m[S_TRI] = eout[8] 53 m[S_CON] = eout[9] 54 m[S_SNG] = eout[10] 55 m[S_DNG] = eout[11] 56 57 // MGMT: frontier plane 58 let frbuf: *u8 = sys_mmap(PM_PLANE_CAP) 59 let fn_: i64 = sts_load("knowledge/store/frontier-" as *u8, frbuf, PM_PLANE_CAP) 60 let frtop: *i64 = sys_mmap(PM_TOP_ROCKS*5*8) as *i64 61 let nfr: i64 = pm_frontier_scan(frbuf, fn_, m, frtop) 62 63 // DEBT: merged ledger plane (both schemas) 64 let dbuf: *u8 = sys_mmap(PM_PLANE_CAP) 65 let dn: i64 = sts_load("knowledge/store/debt-" as *u8, dbuf, PM_PLANE_CAP) 66 let dbtop: *i64 = sys_mmap(PM_TOP_DEBTS*3*8) as *i64 67 let ndb: i64 = pm_debt_scan(dbuf, dn, m, dbtop) 68 69 // OPS: registry counts (bounded reads; missing file -> 0, never a crash) 70 let cbuf: *u8 = sys_mmap(PM_CONF_CAP) 71 var cn: i64 = pm_read("tool_allowlist.conf" as *u8, cbuf, PM_CONF_CAP) 72 if cn > 0 { m[S_TOOLS] = pmc_count_green(cbuf, cn) } 73 cn = pm_read("cron.reg" as *u8, cbuf, PM_CONF_CAP) 74 if cn > 0 { m[S_CRONS] = pm_count_rows(cbuf, cn) } 75 cn = pm_read("daemons.reg" as *u8, cbuf, PM_CONF_CAP) 76 if cn > 0 { m[S_FLEET] = pm_count_rows(cbuf, cn) } 77 cn = pm_read("knowledge/status/ws_sync.jrnl" as *u8, cbuf, PM_CONF_CAP) 78 if cn > 0 { m[S_JRNLB] = cn } 79 80 // ROI: sibling-owned roi- plane (fail-closed UNSEEDED when absent) 81 let roibuf: *u8 = sys_mmap(PM_PLANE_CAP) 82 let rn: i64 = sts_load("knowledge/store/roi-" as *u8, roibuf, PM_PLANE_CAP) 83 let roiline: *i64 = sys_mmap(PMC_ROI_MAXLINES*RR_STRIDE*8) as *i64 84 let nroi: i64 = pm_roi_scan(roibuf, rn, m, roiline, PMC_ROI_MAXLINES) 85 86 // FEEDBACK: maturity next-rungs 87 let nextv: *i64 = sys_mmap(PM_TOP_NEXT*2*8) as *i64 88 let nnext: i64 = pm_maturity_next(ECOMAT_STORE, nextv, PM_TOP_NEXT) 89 90 // RACI: ownership matrix from the raci- plane 91 let racibuf: *u8 = sys_mmap(PM_PLANE_CAP) 92 let racn: i64 = sts_load("knowledge/store/raci-" as *u8, racibuf, PM_PLANE_CAP) 93 let raciline: *i64 = sys_mmap(PM_TOP_RACI*RC_STRIDE*8) as *i64 94 let nraci: i64 = pm_raci_scan(racibuf, racn, m, raciline, PM_TOP_RACI) 95 96 let out: *u8 = sys_mmap(PM_OUT_CAP) 97 if html == 1 { 98 let n: i64 = pm_emit_html(out, m, frbuf, frtop, nfr, dbuf, dbtop, ndb, roibuf, roiline, nroi, ECOMAT_STORE, nextv, nnext, racibuf, raciline, nraci) 99 ss_writefile(outp, out, n) 100 _p("wrote " as *u8) 101 _p(outp) 102 _p(" bytes=" as *u8) 103 _fn(1, n) 104 _p("\nURL https://nishifamily.com/pm.html\n" as *u8) 105 } else { 106 let n: i64 = pm_emit_json(out, m, frbuf, frtop, nfr, dbuf, dbtop, ndb, roibuf, roiline, nroi, ECOMAT_STORE, nextv, nnext, racibuf, raciline, nraci) 107 sys_write(1, out, n) 108 } 109 sys_exit(0) 110 return 0 111}