code wiki / (root) / nx_audit_dashboard.nx

nx_audit_dashboard.nx source

↩ module page · 167 lines · 5971 B

1// nx_audit_dashboard.nx -- aggregate substrate state surface. 2// 3// Per [[feedback-self-surfacing-intelligence-staged-autonomy]]: the 4// substrate must SURFACE its state to the operator, not hide it. 5// Dashboard is the snapshot primitive that aggregates ALL substrate 6// counters into one structured view: hunt kills, gather yields, 7// xeno alerts, twin-key pending, scam patterns flagged, treaty 8// breaches, immune colony health, host pressure. 9// 10// THE STRUCTURAL POINT: substrate KNOWS many things; operator can 11// only ACT on what the substrate SURFACES. Dashboard is the 12// surfacing surface. 13// 14// Composes: 15// nx_hunter -- kill counts by pillar 16// nx_gatherer -- yield totals 17// nx_xenocell -- intrusion event counts 18// nx_immune -- colony status + cell-count-in-status 19// nx_book -- unseen-alert count (family attention needed) 20// nx_organism -- host pressure aggregate 21// nx_pollinate -- pending federation events 22 23import "nx_syscalls.nx" 24import "nx_tier.nx" 25const NX_MAGIC_1024: i64 = 1024 26 27const NX_AD_OK: nx_int = 0 28const NX_AD_ERR_NULL: nx_int = 1 29 30// ===== Struct: NxAuditDashboardSnapshot ========================== 31 32struct NxAuditDashboardSnapshot { 33 captured_us: nx_size, 34 hunt_active_count: nx_int, 35 hunt_kill_count: nx_int, 36 gather_field_count: nx_int, 37 gather_total_yield_ms: nx_size, 38 xeno_evidence_count: nx_int, 39 twin_key_pending: nx_int, 40 book_unseen_alerts: nx_int, 41 scam_flagged_count: nx_int, 42 treaty_breached_count: nx_int, 43 colony_status: nx_int, // NX_COL_* 44 host_ram_pressure_q10: nx_int, 45 host_vram_pressure_q10: nx_int, 46} 47 48func nx_audit_dashboard_snapshot_new() -> *NxAuditDashboardSnapshot { 49 let s: *NxAuditDashboardSnapshot = (sys_mmap(112)) as *NxAuditDashboardSnapshot 50 s.captured_us = 0 51 s.hunt_active_count = 0 52 s.hunt_kill_count = 0 53 s.gather_field_count = 0 54 s.gather_total_yield_ms = 0 55 s.xeno_evidence_count = 0 56 s.twin_key_pending = 0 57 s.book_unseen_alerts = 0 58 s.scam_flagged_count = 0 59 s.treaty_breached_count = 0 60 s.colony_status = 0 61 s.host_ram_pressure_q10 = 0 62 s.host_vram_pressure_q10 = 0 63 return s 64} 65 66// Caller-driven setters (substrate composition layer fills these 67// from each sub-primitive's count query; dashboard doesn't import 68// every primitive itself). 69 70func nx_audit_dashboard_set_capture_ts(s: *NxAuditDashboardSnapshot, ts_us: nx_size) -> nx_int { 71 s.captured_us = ts_us 72 return NX_AD_OK 73} 74 75func nx_audit_dashboard_set_hunt(s: *NxAuditDashboardSnapshot, 76 active: nx_int, kills: nx_int) -> nx_int { 77 s.hunt_active_count = active 78 s.hunt_kill_count = kills 79 return NX_AD_OK 80} 81 82func nx_audit_dashboard_set_gather(s: *NxAuditDashboardSnapshot, 83 fields: nx_int, ms_saved: nx_size) -> nx_int { 84 s.gather_field_count = fields 85 s.gather_total_yield_ms = ms_saved 86 return NX_AD_OK 87} 88 89func nx_audit_dashboard_set_xeno(s: *NxAuditDashboardSnapshot, evidence: nx_int) -> nx_int { 90 s.xeno_evidence_count = evidence 91 return NX_AD_OK 92} 93 94func nx_audit_dashboard_set_twin_key_pending(s: *NxAuditDashboardSnapshot, n: nx_int) -> nx_int { 95 s.twin_key_pending = n 96 return NX_AD_OK 97} 98 99func nx_audit_dashboard_set_book_alerts(s: *NxAuditDashboardSnapshot, n: nx_int) -> nx_int { 100 s.book_unseen_alerts = n 101 return NX_AD_OK 102} 103 104func nx_audit_dashboard_set_scam(s: *NxAuditDashboardSnapshot, n: nx_int) -> nx_int { 105 s.scam_flagged_count = n 106 return NX_AD_OK 107} 108 109func nx_audit_dashboard_set_treaty_breaches(s: *NxAuditDashboardSnapshot, n: nx_int) -> nx_int { 110 s.treaty_breached_count = n 111 return NX_AD_OK 112} 113 114func nx_audit_dashboard_set_colony(s: *NxAuditDashboardSnapshot, status: nx_int) -> nx_int { 115 s.colony_status = status 116 return NX_AD_OK 117} 118 119func nx_audit_dashboard_set_pressure(s: *NxAuditDashboardSnapshot, 120 ram_q10: nx_int, vram_q10: nx_int) -> nx_int { 121 s.host_ram_pressure_q10 = ram_q10 122 s.host_vram_pressure_q10 = vram_q10 123 return NX_AD_OK 124} 125 126// ===== nx_audit_dashboard_attention_needed ======================== 127// 128// Predicate: does the operator need to look at the dashboard now? 129// Returns 1 if ANY of: 130// - book_unseen_alerts > 0 131// - twin_key_pending > 0 132// - scam_flagged_count > 0 133// - treaty_breached_count > 0 134// - colony_status >= ALERTED 135// - host pressure >= 90% (Q10 921) 136 137func nx_audit_dashboard_attention_needed(s: *NxAuditDashboardSnapshot) -> nx_int { 138 if s.book_unseen_alerts > 0 { return 1 } 139 if s.twin_key_pending > 0 { return 1 } 140 if s.scam_flagged_count > 0 { return 1 } 141 if s.treaty_breached_count > 0 { return 1 } 142 if s.colony_status >= 1 { return 1 } // ALERTED 143 if s.host_ram_pressure_q10 >= 921 { return 1 } 144 if s.host_vram_pressure_q10 >= 921 { return 1 } 145 return 0 146} 147 148// ===== nx_audit_dashboard_alert_score_q10 ========================= 149// 150// Continuous Q10 score of operator attention urgency. 0 = nothing 151// urgent; 1024 = highest urgency. Computed by weighted sum of 152// individual indicators. 153 154func nx_audit_dashboard_alert_score_q10(s: *NxAuditDashboardSnapshot) -> nx_int { 155 var score: nx_int = 0 156 if s.book_unseen_alerts > 0 { score = score + 256 } // alerts pending 157 if s.twin_key_pending > 0 { score = score + 128 } 158 if s.scam_flagged_count > 0 { score = score + 256 } 159 if s.treaty_breached_count > 0 { score = score + 128 } 160 if s.colony_status >= 1 { score = score + 64 } 161 if s.colony_status >= 2 { score = score + 128 } // RESPONDING 162 if s.colony_status >= 3 { score = score + 256 } // COMPROMISED 163 if s.host_ram_pressure_q10 >= 921 { score = score + 64 } 164 if s.host_vram_pressure_q10 >= 921 { score = score + 64 } 165 if score > NX_MAGIC_1024 { score = NX_MAGIC_1024 } 166 return score 167}