interplane.Get Omega
Read in your language

omega-mcp

aien-dev/omega-mcp

Brought by drakestapleton

branch main Branches Tags History

omega-mcp / README.md

274 lines · 18970 bytes Raw Blame History Rendered
1# omega-mcp
2
3[![Omega MCP on mcprush](https://mcprush.com/badge/omega-mcp/score.svg)](https://mcprush.com/to/omega-mcp?ref=badge)
4
5An MCP server, written in Omega, that lets an agent compile and run Omega (`.om`) programs with the
6pinned seeded compiler and look up the language. It speaks MCP (protocol version `2025-06-18`) as
7newline-delimited JSON-RPC 2.0 over stdio.
8
9The pin is the file `PIN`: an omega-mv revision and the sha256 of its `seed/out/omc`. It is written
10nowhere else. `build.sh` takes the compiler from that revision, refuses any other, and generates
11everything else that names the pin; the server checks the sha256 of its compiler again at start-up and
12reports the pin in `initialize` and in every `compile` result. Repinning is an edit of `PIN` and nothing else:
13`build.sh` rewrites `data/` from the new revision, and that generated diff is committed with it.
14
15## Tools
16
17| Tool | Arguments | Result |
18|---|---|---|
19| `compile` | `source` | `ok`, binary size and sha256, or the compile error `{line, code, meaning, fix}` |
20| `run` | `source`, `stdin`, `timeout_ms` (1..30000, default 5000) | compile result, capped stdout/stderr, and the exit: `normal`, `trap` (with its meaning), or the `limit` that stopped it (`cpu_time`, `file_size`, `wall_clock`, `killed`) |
21| `explain_error` | `query`: an error code 1..30, an `omc: line N: error K` line, `trap T`, or an exit status 101..114 | meaning, cause, fix, a minimal example and citations into omega-mv at the pin |
22| `lookup` | `query`: a keyword or topic, or a substring | the entry (form, arity, types, result, example, citations), or up to 20 search hits |
23
24A compile diagnostic is a successful tool result (`isError: false`); `isError` is true when nothing
25could be run (sandbox failure, a refused compile stage) or when explain/lookup found no entry. Bad
26arguments are JSON-RPC errors (`-32602`).
27
28Request limits (`src/state.om`): `source` and `stdin` at most 524288 bytes each after JSON decoding
29(`maxsrc`; over it is `-32602`), one request line at most 983040 bytes (`maxline`; over it is `-32700`),
3016380 JSON tokens (the 65536-cell token tape, 4 cells a token after a 16-cell header) and 64
31nesting levels a request. They exist only because the server's buffers have fixed sizes (the
32input line `ib`, 1572864 bytes; the decoded source and the reply share `ob`, 787472 bytes), declared in
33`fn main` as sized local arrays rather than run-time pools. They are listed as defects to lift, not
34protections; `smoke.py` prints how close its largest case comes to each.
35
36## Isolation
37
38Each `compile` and `run` stage gets a fresh `/tmp/omega-mcp-<16 hex>` directory (mode 0700, removed
39after the reply) and runs under `bwrap --unshare-all --clearenv`. The sandbox sees only the compiler
40or the program (read-only), its in-sandbox reaper, the stage's own stdin file (`/i`, read-only) and
41stdout/stderr files (`/o`, `/e`), and a 16 MiB tmpfs working directory: no network, no other host
42files, an empty environment. The server sets the resource limits on the sandbox's pid 1 with the Omega
43`prlimit` host word (omega-mv keyword 235) before the sandbox starts, and it kills the whole sandbox at the wall clock. Since omega-mv #970, `execprog` closes
44every descriptor at or above 3, so bwrap gets its block, info and status pipes on fds 0..2 and the
45reaper opens the bound stage files onto fds 0..2 of the program; the program holds no other
46descriptor.
47
48| Stage | CPU | Address space | File size | Processes | Wall clock |
49|---|---|---|---|---|---|
50| run | 10 s | 256 MiB | 1 MiB | 5 | `timeout_ms` (default 5 s, max 30 s) |
51| compile | 20 s | 512 MiB | 16 MiB | 4 | 20 s |
52
53Both stages also get 64 open files and no core dumps. `--test-only-no-isolation` turns all of this
54off and exists only so the trust gate can prove it detects an escape; never give it to an agent.
55
56## Build and use
57
58```sh
59OMEGA_SRC=/path/to/omega-mv ./build.sh # any git clone of omega-mv that contains the PIN revision
60build/omega-mcp # reads JSON-RPC on stdin; logs one line per request on stderr
61```
62
63The server loads `data/reference.json` and `data/examples/` from beside its executable. Start-up
64exit codes: 2 bad arguments, 3 compiler not the pin, 4 data missing, 5 `bwrap` missing.
65`build.sh` exits 2 when the compiler or `PIN` disagree with the pin or the pin revision lacks a unit, and 1 when omc
66refuses a unit or when `build/pincheck` finds a tracked file that restates the pin or names a hash that is
67not derived from it (`gates/pincheck.om` lists what it reads).
68`mcp.json` is an example client configuration; point its `command` at your `build/omega-mcp`.
69
70## Install beside running servers
71
72A running server re-executes its own executable file as the in-sandbox reaper of every `compile` and
73`run`, and finds its compiler and data beside that file. Putting a different file at the path a running
74server started from breaks that server's `compile` and `run` (observed 2026-11-11: "the sandbox ended
75without a status record"). Install only by adding a release:
76
77```sh
78OMEGA_SRC=/path/to/omega-mv ./build.sh
79tools/install.sh PREFIX NAME # adds PREFIX/releases/NAME/{omega-mcp,omc,data}, switches PREFIX/current
80PREFIX/current/omega-mcp # the path an MCP client should start
81tools/releases.sh PREFIX # retire alarm: live pids per release; RETIRABLE = no live process, not current
82```
83
84`install.sh` overwrites and removes nothing: it refuses (exit 2) a release name that exists, naming the
85live processes that run from it, a `PREFIX/current` that is not a symlink, and a `build/omc` that is not
86the pin. Rollback is `mv -T PREFIX/current.rollback PREFIX/current`. `releases.sh` never deletes; remove a
87release only after it lists that release as RETIRABLE. A server installed the old way, directly as
88`PREFIX/omega-mcp`, stays in place and is listed as `legacy`.
89
90Which servers run from which release, and which client configurations still name the legacy path, is what
91`tools/releases.sh` prints; it is not recorded here.
92`tools/releases.sh PREFIX CONFIG[=PENDING]...` prints, for each configuration that still names the legacy
93path, `legacy path still configured in FILE:LINE`. The legacy files are retired only when that alarm
94shows no live process for them and no configuration naming them, and then by a manual `rm` by whoever sees
95it; nothing deletes them automatically.
96
97## Gates
98
99```sh
100export OMEGA_SRC=/path/to/omega-mv
101ev=evidence/$(sed -n 's/^omega-mv //p' PIN | cut -c1-8); mkdir -p $ev # results are filed per pin
102python3 gates/smoke.py --out $ev/smoke-transcript.jsonl
103python3 gates/trust.py --out $ev/trust-gate.json
104python3 tools/check-reference.py --omega-src $OMEGA_SRC --omc build/omc --self-test
105python3 gates/upgrade.py --out $ev/upgrade-gate.txt
106sh gates/pincheck-cases.sh
107```
108
109`pincheck-cases.sh` checks `build/pincheck` itself: restating the revision or the omc sha256 of `PIN` is
110refused; with a fixture `PIN` whose revision and sha256 start with 8 digits, 8-, 12- and 16-character,
111upper-case and full restatements and another hash-like word are refused while dates, counts, near misses
112and the hex alphabet pass; and five mutants of the prefix comparison, compiled with `build/omc`, are each
113caught.
114
115`smoke.py` also runs the pin case: a program with a 20-byte variable name and `for i ulong n bound 8`
116must compile and run through `tools/call` (exit 10), the same loop past its bound must trap 4, and the
117older omc named in `gates/fixtures/pin-case-refuser` (read from `$OMEGA_SRC` with `git show`) must
118refuse the program with `omc: line 3: error 13`. The no-caps case is a unit with 20,000 `text` records
119and a main with 20,000 calls: it must compile and run through `tools/call` (stdout `ok`, exit 36), and
120the omc named in `gates/fixtures/nocaps-case-refuser` (8192 names in scope) must refuse it with
121`omc: line 8193: error 14`. Each `evidence/<first 8 of the revision>/` holds the
122results at that pin; the files directly under `evidence/` are an older record. Evidence is never edited.
123
124`trust.py` sends, through the `run` tool, a read of a canary under `~/.local/state`, a fork bomb, an
125infinite loop and a 10 GiB write, and requires each to be refused or killed with no process left
126behind. A second server started with `--test-only-no-isolation` runs bounded versions of the same
127attacks and must see them succeed, so a gate that cannot see an escape fails. `check-reference.py`
128re-derives every keyword, error and trap entry from the pinned source, compiles and runs every example
129with the pinned omc, and runs three negative controls. `tools/gen-reference.py` writes that data from the
130source at the pin: it finds every cited quote by its text and writes the line numbers itself, and stops when
131a quote is missing or occurs more than once.
132
133These gates are host evidence on Linux arm64 (bubblewrap 0.9.0, util-linux 2.39.3); they say nothing
134about other kernels or about a sandbox configuration other than the one in `src/sandbox.om`.
135`upgrade.py` installs two releases with `tools/install.sh` under live servers and requires every server
136to keep compiling, refusals where the procedure must refuse, and the retire alarm to follow the live
137processes; its negative control replaces a running server's executable in place and must break it.
138
139There is no hosted CI. Run the gates above on Linux arm64 in a fresh `rad clone` of this repository
140with `OMEGA_SRC` set to a clone of omega-mv at the pin, after `./build.sh`; each gate exits 0 on PASS.
141
142## Agent-file maintenance MCP
143
144`sh build.sh` also builds a separate native executable from `maintenance/UNITS` with the same pinned
145compiler: `build/agent-maintenance-mcp --root /absolute/canonical/agent-directory`.
146It exposes `inventory`, `read_file`, `validate`, `propose`, `apply` and `rollback`.
147It never invokes a shell, a privileged updater, or the compiler sandbox.
148
149Default mode is read/propose only. `--allow-write` permits replacement of existing
150files in an explicitly selected unprotected directory. `/srv/aien-keep` and its
151descendants always refuse writable mode. Protected installations use their existing
152operator-approved update procedure; this MCP does not bypass their lock.
153
154Supported logical file IDs are `RULES.md`, `WATCHDOG.yml`, `config.yml`, and
155`agents/<slug>.md`. Slugs contain lowercase ASCII letters, digits, underscores and
156hyphens, start with a letter or digit, and have at most 64 bytes. Files are held in
157fixed buffers of `ammax` bytes (`maintenance/state.om`, 65536 today: Omega has no heap yet, so
158they cannot be sized from the file); a larger file or request is refused, never cut. The gate's
159size alarm fails when a real agent file passes three quarters of that. Absolute paths, traversal, symlinks, executable files,
160hardlinks and nonregular files refuse. The root and every traversed directory are
161descriptor-pinned. Linux procfs is required for privilege/capability checks.
162
163`propose` takes `file`, complete replacement `content`, and `expected_sha256`.
164Its structured result contains exact before/after content and hashes. Review this
165full replacement, including any removed settings, before invoking `apply` with the
166returned `proposal_id`. A new proposal invalidates the old proposal and rollback
167token, even when the new proposal refuses. Tokens and recovery bytes are
168connection-scoped; retain the before-content preview for recovery after disconnect.
169No file creation or deletion is exposed.
170
171Validation is structural, not a full OMP schema or policy audit. Existing YAML is
172readable. Proposed settings/rosters must be JSON objects, which are valid YAML.
173Proposed agent definitions use a JSON object between `---` frontmatter delimiters,
174with matching name, nonempty description and valid optional model/effort fields.
175Unknown model availability, credentials, effective policy and runtime compatibility
176are not verified. Non-JSON YAML proposals refuse rather than claiming validation.
177Saving a file does not prove the active CLI has reloaded it.
178
179Apply and rollback serialize cooperating writers, reread the expected bytes under
180the lock, stage and sync a replacement, recheck the target and rename atomically.
181Rollback restores the captured original bytes, including legacy YAML. An intervening
182edit refuses instead of being overwritten. Rename is the commit point: a later sync
183error reports committed state with uncertain durability, not an unchanged failure.
184These checks do not serialize nonparticipating writers or isolate hostile same-UID
185processes. Bind-mount aliases require trusted operator configuration. Crash-left
186lock/stage files require operator recovery; the MCP does not remove others' locks.
187Content and basic permissions are preserved; this is not an ACL/xattr backup system.
188
189Run `sh gates/maintenance-cases.sh [/absolute/agent-directory]` after `sh build.sh`. It compiles a
190mutant with the default read-only guard removed and runs `gates/maintenance.py` with it as the
191negative control: the oracle requires an actual fixture write by the mutant and failure of the
192normal read-only check. With a directory it also reads the real files (inventory and read only,
193never `--allow-write`) and runs the size alarm. All mutation scenarios use disposable fixture
194directories. Never register a mutant in a CLI.
195
196## Agent Q&A MCP
197
198Shared questions and answers for coding agents: a place where an agent that hits an error can look
199for a fix another agent already proved, and, if its person allows it, leave what it learned.
200`sh build.sh` builds `build/agent-qa-mcp --store /absolute/store-directory --agent NAME
201[--consent /absolute/consent-file]`.
202
203- **Reading is open.** `search` (every space-separated word must appear, letters compared without
204 case; an empty search lists entries) returns up to 50 matches with `matches`, `shown` and `more`;
205 `read` returns one entry's exact text.
206- **Contributing is the person's choice, per agent.** `ask`, `answer` and `check` work only while the
207 consent file holds the line `allow NAME` for this agent. The person writes that file; the server only
208 reads it, again at every contribution, so deleting the line stops sharing at once. No tool writes
209 it. `consent_status` returns one plain sentence the agent can hand to the person on how to turn
210 sharing on or off, and the server's start-up instructions tell the agent to say so once when it is off.
211 The server cannot stop a program that the person lets run as them from editing the file: the
212 guarantee is that the agent's MCP tools cannot opt it in.
213- **Answers carry their proof.** An answer names its question, the versions it was proven on, the
214 steps and one line of evidence (the command and what it printed). A `check` confirms (`works`) or
215 challenges (`fails`) an answer with its own evidence. An answer is a claim until it reproduces.
216- **Nothing private is stored.** A contribution is refused, never edited, when any field holds a
217 private key block, a home directory path (`/home/`, `/Users/`, `/root/`; write `~/...`), or a run of
218 24 or more letters, digits, `_` and `-` mixing upper case, lower case and digits (how keys and
219 tokens look; lowercase hex such as a sha256 passes). One-line fields refuse control characters;
220 `steps` and `body` allow line breaks and tabs. Only the entry text is stored: no chat, code or files.
221- **Entries are files named by their own SHA-256.** Each is plain text (`agent-qa 1`, `kind`, `agent`,
222 `ref`, `title`, `versions`, `result`, `evidence`, then length-prefixed `steps` and `body` blocks),
223 written to an exclusive temporary file, synced and renamed, so a store can be copied or merged by
224 any transport and a damaged copy is refused on read and counted as `skipped` in search. The same
225 entry posted twice is one file (`created: false`).
226- **Sizes.** Each field's limit is its `maxLength` in `tools/list` (`arcapof` in `qa/rpc.om`): a quota on
227 what one contribution may upload, chosen so every possible entry fits the server's read buffer
228 (`qmax` in `qa/store.om`).
229
230Not built yet: sharing between machines. The store is designed to be copied between machines over
231the private network, whose trust layer is omnet's Tailnet Lock work; no transport is in this
232repository.
233
234Registering both servers in the locked agent files (Drake, 2026-11-15) is
235`sh tools/register-locked.sh --keep /srv/aien-keep --prefix PREFIX/current` after `tools/install.sh`
236has put the two binaries in that release. The command stages the new JSON outside the lock and
237installs it only with `aien-keep update`, which keeps the previous copy. It writes
238`home/.omp/agent/mcp.json`, and `home/.claude.json` and `home/.claude/settings.json` when those
239already exist. The question store and the empty consent file are created under `$HOME`, outside
240the lock. Sharing stays off until the person adds `allow omp` or `allow claude` to the consent file.
241`sh gates/register-cases.sh` proves the previous copy restores and that a direct write is refused.
242
243Run `sh gates/qa-cases.sh` after `sh build.sh`: `gates/qa.py` (protocol, consent, privacy, entries,
244damage, paging) must pass on the server and fail on three mutants compiled with the pinned omc
245(consent line not needed, privacy filter skipped, hash check skipped).
246
247## Layout
248
249- `src/*.om`: the server (`src/UNITS` lists the concatenation order; `build.sh` builds it)
250- `qa/*.om`: the agent Q&A server (`qa/UNITS`; `build.sh` builds it too); `gates/qa-cases.sh` runs its gate
251- `maintenance/*.om`: the agent-file maintenance server (`maintenance/UNITS` lists its order; `build.sh` builds it too); `gates/maintenance-cases.sh` runs its gate
252- `PIN`: the omega-mv revision and omc sha256 everything is built and checked against
253- `src/UNITS` lines `omega-mv:PATH`: sha256 and JSON units read unchanged from omega-mv at the pin by `build.sh` (no copy is tracked)
254- `data/`: reference data and example programs, written by `build.sh` through `tools/gen-reference.py` and checked by
255 `tools/check-reference.py`
256- `gates/`, `evidence/`: verification oracles (including `gates/pincheck.om`) and their recorded results
257- `DEPENDENCIES.md`: every host tool in the build, runtime and verification paths
258
259License: Apache-2.0 (see `LICENSE` and `NOTICE`).
260
261<!-- mcp-name: io.github.aien-dev/omega-mcp -->
262
263## Human-Directed Agentic Engineering
264
265Development follows Human-Directed Agentic Engineering (HDAE): humans define goals,
266architecture, constraints, acceptance criteria, and stopping points; agents implement,
267execute checks, diagnose failures, and revise within those boundaries. Human review
268retains responsibility for claims, acceptance, and release decisions. This describes
269the development method, not a change to runtime autonomy or historical evidence.
270
271For the documented method and a systems-software case study, see Gregory M. Kurtzer
272(2026), *Ginux: Building an Independent Kernel That Runs Linux Userspace through
273Human-Directed Agentic Engineering*, technical report, v1, Zenodo,
274<https://doi.org/10.5281/zenodo.23682548>.