Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/mailhand/blob/main/src/cli.om # mailhand mailhand: agents look after a person's email in seeded Omega. Maildir + MIME parsing, JSONL CLI and MCP, rule triage, policy-gated sending, hash-chained audit. Free (Apache-2.0). Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `mailhand / src / cli.om` 242 lines ยท 4229 bytes Raw Blame History 1 note ======== src/cli.om: the command line, the op table, the audit hook ======== 2 note mailhand OP [--key value | --flag | word]... JSONL on stdout, diagnostics on stderr, exit code 3 note per README "Exit codes". Every op, from the CLI or from MCP, goes through cli_run: it runs with 4 note its output captured in store S_OUT, then appends the audit record, then the CLI prints S_OUT. 5 global gop uchar 64 6 const CL_OPN ulong 87 7 text kusage "usage: mailhand OP [--key value]... ; OP is one of setup list show thread search triage label move mark-read archive draft-reply draft-new drafts queue-send approve deliver book digest audit verify stats sync parse mcp version" 8 text kunknown "unknown_op" 9 text knotsetup "not_set_up" 10 text kversion "version" 11 text kvers "mailhand 1 (seeded Omega; compiler pinned in PIN)" 12 text kop_setup "setup" 13 text kop_list "list" 14 text kop_show "show" 15 text kop_thread "thread" 16 text kop_search "search" 17 text kop_triage "triage" 18 text kop_label "label" 19 text kop_move "move" 20 text kop_mr "mark-read" 21 text kop_arch "archive" 22 text kop_dr "draft-reply" 23 text kop_dn "draft-new" 24 text kop_drafts "drafts" 25 text kop_qs "queue-send" 26 text kop_appr "approve" 27 text kop_del "deliver" 28 text kop_book "book" 29 text kop_dig "digest" 30 text kop_aud "audit" 31 text kop_ver "verify" 32 text kop_stats "stats" 33 text kop_sync "sync" 34 text kop_parse "parse" 35 text kop_mcp "mcp" 36 text kauderr "could not append the audit record" 37 38 39 fn cl_is t view uchar * to bool 40 n = get gv CL_OPN 41 if ne n len t 42 ret false 43 end 44 for i ulong n bound 64 45 if ne get gop i get t i 46 ret false 47 end 48 end 49 ret true 50 end 51 52 note cl_dispatch: the op named in gop; -1 when there is no such op 53 fn cl_dispatch to int 54 if cl_is kop_list 55 ret op_list 56 end 57 if cl_is kop_show 58 ret op_show 59 end 60 if cl_is kop_thread 61 ret op_thread 62 end 63 if cl_is kop_search 64 ret op_search 65 end 66 if cl_is kop_triage 67 ret op_triage 68 end 69 if cl_is kop_label 70 ret op_label 71 end 72 if cl_is kop_move 73 ret op_move 74 end 75 if cl_is kop_mr 76 ret op_markread 77 end 78 if cl_is kop_arch 79 ret op_archive 80 end 81 ret cl_dispatch2 82 end 83 84 fn cl_dispatch2 to int 85 if cl_is kop_dr 86 ret op_draft_reply 87 end 88 if cl_is kop_dn 89 ret op_draft_new 90 end 91 if cl_is kop_drafts 92 ret op_drafts 93 end 94 if cl_is kop_qs 95 ret op_queue_send 96 end 97 if cl_is kop_appr 98 ret op_approve 99 end 100 if cl_is kop_del 101 ret op_deliver 102 end 103 if cl_is kop_book 104 ret op_book 105 end 106 if cl_is kop_dig 107 ret op_digest 108 end 109 if cl_is kop_aud 110 ret op_audit 111 end 112 if cl_is kop_stats 113 ret op_stats 114 end 115 if cl_is kop_ver 116 ret op_verify 117 end 118 if cl_is kop_sync 119 ret op_sync 120 end 121 ret -1 122 end 123 124 note cli_run: run the op named by store range [off, +n) with the request already in S_REQ. 125 note The op's JSONL ends up in S_OUT; the audit record is appended; returns the exit code. 126 fn cli_run s ulong off ulong n ulong to int 127 put gv CL_OPN 0 128 if le n 63 129 for i ulong n bound 64 130 put gop i s_get s add off i 131 end 132 put gv CL_OPN n 133 end 134 z = s_mem S_OUT 135 put gv VMODE 1 136 put gv VOL 0 137 put gv VDEP 0 138 put gv VAK 0 139 r = cl_dispatch 140 if lt r 0 141 o_ob 142 o_ks kopk kunknown 143 o_kb kokk false 144 o_oe 145 o_nl 146 r = EUSAGE 147 end 148 o_flush 149 k = cl_audit r 150 if lt k 0 151 diag kauderr 152 if eq r EOK 153 r = EIO 154 end 155 end 156 ret r 157 end 158 159 160 fn main to int 161 put gv VMCP 0 162 z = s_mem S_REQ 163 if lt argcnt 2 164 diag kusage 165 ret EUSAGE 166 end 167 b = new uchar 64 0 168 k = argread 1 b 0 64 169 if lt k 0 170 diag kusage 171 ret EUSAGE 172 end 173 if not q_from_argv 2 174 diag kusage 175 ret EUSAGE 176 end 177 s_reset S_Y 178 s_addt S_Y part b 0 ulong k 179 if s_eqt S_Y 0 s_len S_Y kversion 180 diag kvers 181 ret EOK 182 end 183 if s_eqt S_Y 0 s_len S_Y kop_parse 184 put gv VMODE 0 185 r = op_parse 186 o_flush 187 ret r 188 end 189 if s_eqt S_Y 0 s_len S_Y kop_setup 190 ret cl_setup 191 end 192 r = cf_init 193 if ne r EOK 194 cl_notsetup r 195 ret r 196 end 197 if s_eqt S_Y 0 s_len S_Y kop_mcp 198 put gv VMCP 1 199 put gv VMODE 0 200 ret op_mcp 201 end 202 s_reset S_TMP 203 s_adds S_TMP S_Y 0 s_len S_Y 204 r = cli_run S_TMP 0 s_len S_TMP 205 zl = s_wfd S_OUT 1 206 ret r 207 end 208 209 fn cl_notsetup r int to void 210 put gv VMODE 0 211 o_ob 212 o_kb kokk false 213 if eq r ENOSETUP 214 o_ks krefk knotsetup 215 end 216 o_oe 217 o_nl 218 o_flush 219 end 220 221 note cl_setup: setup runs before a config exists; its record starts the audit chain 222 fn cl_setup to int 223 z = s_mem S_OUT 224 put gv VMODE 1 225 put gv VOL 0 226 r = op_setup 227 o_flush 228 if eq r EOK 229 k = au_append kop_setup r 230 end 231 zl = s_wfd S_OUT 1 232 ret r 233 end 234 235 fn cl_audit r int to long 236 b = new uchar 64 0 237 n = get gv CL_OPN 238 for i ulong n bound 64 239 put b i get gop i 240 end 241 ret au_append part b 0 n r 242 end