omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / aienux / debugger / main.om
| 1 | note aienux/debugger/main.om: CLI entrypoint for spark-debugger watchdog & JSON-RPC stdio server |
| 2 | note Compose with: si/directives/om2.om aienux/debugger/lib.om aienux/debugger/main.om |
| 3 | |
| 4 | text dm_cmd_mcp "mcp" |
| 5 | text dm_cmd_rpc "rpc" |
| 6 | text dm_cmd_flag_mcp "--mcp" |
| 7 | text dm_cmd_check "check" |
| 8 | text dm_cmd_diag "diagnose" |
| 9 | text dm_cmd_triage "triage" |
| 10 | |
| 11 | text dm_hdr "=== SparkOS Sovereign Watchdog: System Diagnostic Audit ===\n" |
| 12 | text dm_l_sev "Severity: " |
| 13 | text dm_l_rsn "Reason Mask: " |
| 14 | text dm_l_load "Load (x100): " |
| 15 | text dm_l_mem "Memory Used %: " |
| 16 | text dm_l_disk "Disk Free %: " |
| 17 | text dm_l_gtemp "GPU Temp (C): " |
| 18 | text dm_l_gmem "GPU Mem %: " |
| 19 | text dm_l_svc "Services Up: " |
| 20 | text dm_l_env "Env Leaks: " |
| 21 | text dm_l_bld "Build Passed: " |
| 22 | text dm_l_ovr "Overall Status: " |
| 23 | text dm_s_green "ALL SYSTEMS GREEN\n" |
| 24 | text dm_s_attn "ATTENTION REQUIRED\n" |
| 25 | text dm_err_snap "spark-debugger: invalid metric snapshot\n" |
| 26 | text dm_usage "Usage: spark-debugger [check|diagnose|triage|mcp|rpc]\n" |
| 27 | text dm_slash "/" |
| 28 | text dm_nl "\n" |
| 29 | |
| 30 | fn dbg_read_stdin dst edit uchar * to ulong |
| 31 | cap = len dst |
| 32 | pos = ulong 0 |
| 33 | note bound 65536 caps stdin payload |
| 34 | while lt pos cap bound 65536 |
| 35 | remn = sub cap pos |
| 36 | k = read int 0 dst pos remn |
| 37 | if le k long 0 |
| 38 | break |
| 39 | end |
| 40 | pos = add pos ulong k |
| 41 | end |
| 42 | ret pos |
| 43 | end |
| 44 | |
| 45 | fn dbg_run_rpc_stdio to int |
| 46 | inp = new uchar 32768 0 |
| 47 | outbuf = new uchar 2048 0 |
| 48 | wd = new Watchdog 0 0 0 2 2 1 0 0 0 0 0 |
| 49 | dbg_wd_init wd ulong 2 ulong 2 ulong 1 |
| 50 | n = dbg_read_stdin inp |
| 51 | pos = ulong 0 |
| 52 | while lt pos n bound 32768 |
| 53 | ls = pos |
| 54 | while lt pos n bound 32768 |
| 55 | if eq get inp pos uchar 10 |
| 56 | break |
| 57 | end |
| 58 | pos = add pos ulong 1 |
| 59 | end |
| 60 | ll = sub pos ls |
| 61 | if lt pos n |
| 62 | pos = add pos ulong 1 |
| 63 | end |
| 64 | if gt ll ulong 0 |
| 65 | ol = dbg_rpc_dispatch part inp ls ll wd outbuf |
| 66 | if gt ol ulong 0 |
| 67 | if not dbg_write_all int 1 part outbuf 0 ol |
| 68 | ret 1 |
| 69 | end |
| 70 | end |
| 71 | end |
| 72 | end |
| 73 | ret 0 |
| 74 | end |
| 75 | |
| 76 | fn dbg_triage_one_line line view uchar * wd edit Watchdog step_no ulong to int |
| 77 | outbuf = new uchar 1024 0 |
| 78 | snap = new MetricSnap 0 0 100 40 0 5 5 0 1 0 |
| 79 | st = new StepOut 0 0 0 0 0 0 |
| 80 | idbuf = new uchar 16 0 |
| 81 | rc = dbg_parse_snapshot line snap |
| 82 | if ne rc DBG_OK |
| 83 | w = dbg_write_all int 2 dm_err_snap |
| 84 | if w |
| 85 | ret 1 |
| 86 | end |
| 87 | ret 1 |
| 88 | end |
| 89 | dbg_wd_step wd snap st |
| 90 | il = dbg_put_u64 idbuf ulong 0 step_no |
| 91 | ol = dbg_render_triage_json part idbuf 0 il st wd outbuf |
| 92 | if not dbg_write_all int 1 part outbuf 0 ol |
| 93 | ret 1 |
| 94 | end |
| 95 | ret 0 |
| 96 | end |
| 97 | |
| 98 | fn dbg_run_triage_stdio to int |
| 99 | inp = new uchar 32768 0 |
| 100 | wd = new Watchdog 0 0 0 2 2 1 0 0 0 0 0 |
| 101 | dbg_wd_init wd ulong 2 ulong 2 ulong 1 |
| 102 | n = dbg_read_stdin inp |
| 103 | pos = ulong 0 |
| 104 | step_no = ulong 0 |
| 105 | while lt pos n bound 32768 |
| 106 | ls = pos |
| 107 | while lt pos n bound 32768 |
| 108 | if eq get inp pos uchar 10 |
| 109 | break |
| 110 | end |
| 111 | pos = add pos ulong 1 |
| 112 | end |
| 113 | ll = sub pos ls |
| 114 | if lt pos n |
| 115 | pos = add pos ulong 1 |
| 116 | end |
| 117 | if gt ll ulong 0 |
| 118 | step_no = add step_no ulong 1 |
| 119 | rc = dbg_triage_one_line part inp ls ll wd step_no |
| 120 | if ne rc int 0 |
| 121 | ret rc |
| 122 | end |
| 123 | end |
| 124 | end |
| 125 | ret 0 |
| 126 | end |
| 127 | |
| 128 | fn dbg_render_report snap view MetricSnap tr view TriageRes dst edit uchar * to ulong |
| 129 | p = dbg_put_s dst ulong 0 dm_hdr |
| 130 | p = dbg_put_s dst p dm_l_sev |
| 131 | p = dbg_put_sev dst p get tr sev |
| 132 | p = dbg_put_s dst p dm_nl |
| 133 | p = dbg_put_s dst p dm_l_rsn |
| 134 | p = dbg_put_u64 dst p get tr reasons |
| 135 | p = dbg_put_s dst p dm_nl |
| 136 | p = dbg_put_s dst p dm_l_load |
| 137 | p = dbg_put_u64 dst p get snap load_x100 |
| 138 | p = dbg_put_s dst p dm_nl |
| 139 | p = dbg_put_s dst p dm_l_mem |
| 140 | p = dbg_put_u64 dst p get snap mem_pct |
| 141 | p = dbg_put_s dst p dm_nl |
| 142 | p = dbg_put_s dst p dm_l_disk |
| 143 | p = dbg_put_u64 dst p get snap disk_free |
| 144 | p = dbg_put_s dst p dm_nl |
| 145 | p = dbg_put_s dst p dm_l_gtemp |
| 146 | p = dbg_put_u64 dst p get snap gpu_temp |
| 147 | p = dbg_put_s dst p dm_nl |
| 148 | p = dbg_put_s dst p dm_l_gmem |
| 149 | p = dbg_put_u64 dst p get snap gpu_mem |
| 150 | p = dbg_put_s dst p dm_nl |
| 151 | p = dbg_put_s dst p dm_l_svc |
| 152 | p = dbg_put_u64 dst p get snap svc_up |
| 153 | p = dbg_put_s dst p dm_slash |
| 154 | p = dbg_put_u64 dst p get snap svc_total |
| 155 | p = dbg_put_s dst p dm_nl |
| 156 | p = dbg_put_s dst p dm_l_env |
| 157 | p = dbg_put_u64 dst p get snap env_leaks |
| 158 | p = dbg_put_s dst p dm_nl |
| 159 | p = dbg_put_s dst p dm_l_bld |
| 160 | p = dbg_put_bool dst p get snap build_ok |
| 161 | p = dbg_put_s dst p dm_nl |
| 162 | p = dbg_put_s dst p dm_l_ovr |
| 163 | if eq get tr healthy ulong 1 |
| 164 | p = dbg_put_s dst p dm_s_green |
| 165 | else |
| 166 | p = dbg_put_s dst p dm_s_attn |
| 167 | end |
| 168 | ret p |
| 169 | end |
| 170 | |
| 171 | fn dbg_run_check_stdio to int |
| 172 | inp = new uchar 4096 0 |
| 173 | outbuf = new uchar 2048 0 |
| 174 | snap = new MetricSnap 0 0 100 40 0 5 5 0 1 0 |
| 175 | tr = new TriageRes 0 0 0 |
| 176 | n = dbg_read_stdin inp |
| 177 | if gt n ulong 0 |
| 178 | rc = dbg_parse_snapshot part inp 0 n snap |
| 179 | if ne rc DBG_OK |
| 180 | w = dbg_write_all int 2 dm_err_snap |
| 181 | if w |
| 182 | ret 1 |
| 183 | end |
| 184 | ret 1 |
| 185 | end |
| 186 | else |
| 187 | dbg_snap_init snap |
| 188 | end |
| 189 | dbg_classify snap tr |
| 190 | ol = dbg_render_report snap tr outbuf |
| 191 | if not dbg_write_all int 1 part outbuf 0 ol |
| 192 | ret 1 |
| 193 | end |
| 194 | if eq get tr healthy ulong 1 |
| 195 | ret 0 |
| 196 | end |
| 197 | ret 1 |
| 198 | end |
| 199 | |
| 200 | fn main to int |
| 201 | arg1 = new uchar 64 0 |
| 202 | ac = argcnt |
| 203 | if le ac long 1 |
| 204 | ret dbg_run_check_stdio |
| 205 | end |
| 206 | n1 = argread ulong 1 arg1 ulong 0 ulong 64 |
| 207 | if le n1 long 0 |
| 208 | ret 2 |
| 209 | end |
| 210 | u1 = ulong n1 |
| 211 | if or dbg_eq part arg1 0 u1 dm_cmd_mcp or dbg_eq part arg1 0 u1 dm_cmd_rpc dbg_eq part arg1 0 u1 dm_cmd_flag_mcp |
| 212 | ret dbg_run_rpc_stdio |
| 213 | end |
| 214 | if or dbg_eq part arg1 0 u1 dm_cmd_check dbg_eq part arg1 0 u1 dm_cmd_diag |
| 215 | ret dbg_run_check_stdio |
| 216 | end |
| 217 | if dbg_eq part arg1 0 u1 dm_cmd_triage |
| 218 | ret dbg_run_triage_stdio |
| 219 | end |
| 220 | w = dbg_write_all int 2 dm_usage |
| 221 | if w |
| 222 | ret 2 |
| 223 | end |
| 224 | ret 2 |
| 225 | end |