Working on midas
Building, testing and changing midas itself. What it is and how to use it: the README.
Build
cargo build # the CLI, hub and node in one binary
cargo build --release --target x86_64-unknown-linux-musl # what deploy.sh builds for the hub and the agent container
The hub's web page is embedded in the binary when it was built first:
cd web && bun install && bun run build # → web/dist/, which build.rs embeds
cd .. && cargo build
web/dist/ is not in git. Without it the binary builds anyway (cfg(midas_web)
is off) and its hub serves a note on how to build the page instead, which is
right for a node or an owner's build and wrong for a hub. midas --version
reports git describe of the checkout it was built from, -dirty included;
MIDAS_BUILD overrides it.
Test
cargo test # unit tests and the hub's rules, against a scratch state directory
cd web && bun run typecheck && bun test
tests/e2e/run.sh # a throwaway hub, node and agent: bot mode end to end (needs rootless podman; tests/e2e/README.md)
src/tests.rs points MIDAS_STATE at a temporary directory and runs one test
at a time behind a lock, since the state directory is a process-wide setting.
The suite is run on Linux: on macOS three tests fail for the platform, not the
code (setup::settings_need_only…, bot::a_stopped_bot…, and flush::…,
whose tar is BSD's), as of 2026-10-22.
Running a hub of your own
A hub needs only a state directory and a file of caller keys, and nothing of the real workspace:
mkdir -p /tmp/hub/state
echo '{"dev": {"key": "<32 characters or more>", "role": "admin"}}' > /tmp/hub/callers.json
MIDAS_STATE=/tmp/hub/state MIDAS_CALLERS=/tmp/hub/callers.json \
midas hub serve --listen 127.0.0.1:4799
# another shell: the CLI asks whichever hub MIDAS_HUB names
export MIDAS_HUB=http://127.0.0.1:4799 MIDAS_HUB_KEY=<that key>
midas status
midas sessions import ~/.claude/projects/<dir> --dry-run
Its page is at http://127.0.0.1:4799/. Reading needs no login there: a login is
asked only of requests that came through the web proxy (X-Forwarded-*). A key
shorter than 32 characters is never matched. A hub's key and address otherwise
come from ~/.config/midas/hub.env (MIDAS_HUB, MIDAS_HUB_KEY).
Its settings are /etc/midas/hub.conf's, none when there is none; MIDAS_HUB_CONF
names another file, for a scratch hub with projects ({"repos": ["you/app"]}):
sessions, templates and schedules need them.
For work on the page alone, bun run dev in web/ serves it on :3200 with
/v1/* forwarded to MIDAS_HUB, rebuilding on every change.
The code
src/main.rs declares every command (clap); each module's header says what it
is for and why it is that way. Grouped by where it runs:
The hub
hub.rs: the HTTP API, who may call what (caller keys, account roles), the Forgejo proxy.ws.rs: the board, live over a WebSocket.web.rs: the embedded page.registry.rs: the workspace's state and the rules that decide who gets a node.store.rs: a JSON file that threads and processes change together.events.rs: the event log.board.rs: every session as a card in its stage.collab.rs: sessions working together (notes, overlaps, decisions, reservations).memory.rs: agents' memory, shared by every machine.accounts.rs: the page's people.sessions.rs: sessions the hub keeps (hosted/<id>/), their runner, search over them.discuss.rs: talking one over by voice before it starts.autopilot.rs: answering a session for the person.focus.rs: what the person decides, counted, the limits they set on it, and the rules the autopilot may use.mirror.rs: git and LFS for nodes.warm.rs: keeping nodes' builds warm.deploy.rs:midas deploy.ship.rs: deploying what landed, in batches.push.rs: waking a person's phone when something needs them.builds.rs,stats.rs,chart.rs: the history kept for good.hubsetup.rs:sudo midas hub setup, which installs the binary and the units inunits/.
A build machine and its node
setup.rs,setup_macos.rs:sudo midas setup <node>: the node's user, the machine's firewall, the container (node/Containerfile, fenced bynode/entrypoint.sh) or the VM.node.rs: the node's sshd hooks and GPU readings.nodectl.rs:midas node …for its owner.forward.rs: the Mac's TCP forwarding for its VM.procs.rs: processes, on Linux and macOS.update.rs:midas update, an owner bringing their machines to the checkout's midas.botsetup.rs: a node's bot secret.
Where agents work
cli.rs: the commands people and agents type.client.rs: asking the hub.conf.rs: settings.util.rs: running commands, git.flush.rs: the node's checkout follows the worktree.sshcfg.rs:Hostblocks for every node.check.rs:midas check.acp.rs:midas acp, Claude Code as an Agent Client Protocol agent, which the runner, the bot host and an editor use.tap.rs:midas acp --mirror, which sits between an editor (Zed) and the agent and mirrors its sessions to the hub.import.rs:midas sessions import, Claude Code transcripts and claude.ai/code sessions to the hub.mcp.rs: the workspace's tools as an MCP server.bot.rs,host.rs,botsecrets.rs: bots, and bots with an agent of their own.
Beside the code:
web/: the page, Mithril on Bun.hooks/: Claude Code's session hooks, and git's post-receive for the forge.node/: what a node is built from.units/: the hub's systemd units.tests/e2e/: the end-to-end run.
How a change reaches the machines
- The hub, and the agent container on its machine:
deploy.sh, from the container, tests and builds the musl binary with the page in it, runssudo midas hub setupwith it (which restarts the hub), and installs the binary, and the shared skills and the hooks (midas claude install), for the agents. A runner (midas sessions run) restarted mid-turn cuts that turn off: restart it when its sessions are idle. - Nodes: the midas a node's sessions run follows the hub's by itself, once
nobody holds the node (
midas node update; deploy.sh gives the hub the Macs' build too). What fences a node — its container or VM, its user, the machine's firewall — never comes from the hub: when that recipe changes, each machine's owner runssudo midas setup <node>, ormidas updatefrom their own machine with their sudo;midas checknames the nodes that need it. - The shared skills and hooks (
skills/,hooks/): carried in the binary; each machine's session-start hook installs its midas's into~/.claude(usage.md). - The page's routes: a proxy in front of the hub that lists paths (Caddy,
for garage44.eu) needs any new
/v1/path the page calls, or the page gets a bare 404.
midas check and midas status show which build each machine runs.
Security, which code must keep
The hub's machine is assumed compromisable, since agents run there. So a node is untrusted, and what has to hold is the build machine, its owner's files and home network:
- The node runs as its own user, contained, with memory and CPU limits.
- A firewall on the machine, set by
sudo midas setup, lets the node reach the hub and the internet and nothing private: not the home network, not the machine itself, no IPv6. From the tunnel only the node's ssh port gets in. - Nothing from the hub runs on the machine. The owner builds the midas that
sets the machine up and runs as the node's root. What the hub decides (who
logs into a node, which repository it checks out, the midas its
builduser runs) reaches only inside the node. - Secrets stay off command lines: tokens go to
curlas a config on stdin (-K -), never as arguments.
And on the hub's machine, where root publishes what the hub's user built:
- Root trusts no path the hub's user, or an agent's container, can change.
What it reads from them it opens refusing a symbolic link at every level;
what it writes, it writes relative to a destination directory opened the
same way (
deploy.rs:open_nofollow,install_in,sync_into). A link swapped into a path between two calls is what this is about. - Root runs a build of midas only as
self_updatein hub.conf allows (release.rs): withsigned, only one the owner's release key signed; the key never leaves the owner's machine. - A posted event is believed only from whoever may say it: a kind the hub
acts on (
events::drives_state) is taken from a caller key, or from the node it names; the tunnel may post a log line and nothing more. - A project's hooks run as landed:
midas hook projectsruns a worktree's.claude/settings.jsonhooks only when that file is the one on the project's main, and neversettings.local.json. Nobody reviews a branch's hook change before it would run on the runner; landing is the review. - A node's secrets go to the node:
/v1/bot/secrets/foranswers the node named, from its own address, and logs the read; a caller key reads none.
A change that lets the hub, or anything inside a node, reach past that line is a bug, however convenient. Tested by switching the node's own inner firewall off: it still reached only the hub, the internet and the hub machine's public website.
Commits and docs
Conventional Commits, type(scope): subject in the imperative, with a body
saying why for anything but a trivial change; no co-author trailers. Sessions
land on main directly, rebased onto it.