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 / si / inquisitor / main.om
| 1 | note si/inquisitor/main.om: CLI entrypoint for pure-Omega spark-inquisitor gatekeeper |
| 2 | note Composed after si/directives/om2.om and si/inquisitor/lib.om. |
| 3 | note Reads patch/audit records on stdin, emits structured JSON verdict receipt on stdout. |
| 4 | note Exit 0 on PASS (or advisory WARN); exit 1 on BLOCK (or WARN with --strict); exit 2 on I/O error. |
| 5 | |
| 6 | text cli_strict "--strict" |
| 7 | text cli_io_err "inquisitor: stdin read error\n" |
| 8 | text cli_ovf_err "inquisitor: stdin exceeds 131072 byte limit\n" |
| 9 | text cli_wr_err "inquisitor: stdout write error\n" |
| 10 | text cli_arg_err "inquisitor: too many arguments (max 64)\n" |
| 11 | |
| 12 | fn cli_is_strict to bool |
| 13 | ac = argcnt |
| 14 | if or le ac 1 gt ac 64 |
| 15 | ret false |
| 16 | end |
| 17 | abuf = new uchar 64 0 |
| 18 | for i ulong ulong ac bound 64 |
| 19 | if gt i 0 |
| 20 | r = argread i abuf 0 64 |
| 21 | if eq r long len cli_strict |
| 22 | ok = true |
| 23 | for j ulong len cli_strict bound 64 |
| 24 | if ne get abuf j get cli_strict j |
| 25 | ok = false |
| 26 | break |
| 27 | end |
| 28 | end |
| 29 | if ok |
| 30 | ret true |
| 31 | end |
| 32 | end |
| 33 | end |
| 34 | end |
| 35 | ret false |
| 36 | end |
| 37 | |
| 38 | fn cli_read_stdin to long |
| 39 | probe = new uchar 1 0 |
| 40 | total = ulong 0 |
| 41 | while lt total INQ_MAX_IN bound 131072 |
| 42 | k = read 0 inq_in total sub INQ_MAX_IN total |
| 43 | if lt k 0 |
| 44 | ret k |
| 45 | end |
| 46 | if eq k 0 |
| 47 | break |
| 48 | end |
| 49 | total = add total ulong k |
| 50 | end |
| 51 | if eq total INQ_MAX_IN |
| 52 | more = read 0 probe 0 1 |
| 53 | if lt more 0 |
| 54 | ret more |
| 55 | end |
| 56 | if gt more 0 |
| 57 | ret long -1000 |
| 58 | end |
| 59 | end |
| 60 | put inq_in_len 0 total |
| 61 | ret long total |
| 62 | end |
| 63 | |
| 64 | fn main to int |
| 65 | ac = argcnt |
| 66 | if or lt ac 0 gt ac 64 |
| 67 | ea = write 2 cli_arg_err 0 len cli_arg_err |
| 68 | if lt ea 0 |
| 69 | ret 2 |
| 70 | end |
| 71 | ret 2 |
| 72 | end |
| 73 | strict = cli_is_strict |
| 74 | got = cli_read_stdin |
| 75 | if eq got long -1000 |
| 76 | eov = write 2 cli_ovf_err 0 len cli_ovf_err |
| 77 | if lt eov 0 |
| 78 | ret 2 |
| 79 | end |
| 80 | ret 2 |
| 81 | end |
| 82 | if lt got 0 |
| 83 | ew = write 2 cli_io_err 0 len cli_io_err |
| 84 | if lt ew 0 |
| 85 | ret 2 |
| 86 | end |
| 87 | ret 2 |
| 88 | end |
| 89 | v = inq_scan_input |
| 90 | rlen = inq_format_receipt |
| 91 | ok = inq_write_all 1 rlen |
| 92 | if not ok |
| 93 | ew2 = write 2 cli_wr_err 0 len cli_wr_err |
| 94 | if lt ew2 0 |
| 95 | ret 2 |
| 96 | end |
| 97 | ret 2 |
| 98 | end |
| 99 | if eq v SEV_BLOCK |
| 100 | ret 1 |
| 101 | end |
| 102 | if and strict eq v SEV_WARN |
| 103 | ret 1 |
| 104 | end |
| 105 | ret 0 |
| 106 | end |