garage44.eu/jeroen/midas

logclone: git clone https://garage44.eu/jeroen/midas.git

.. /docs/development.md

raw

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

A build machine and its node

Where agents work

Beside the code:

How a change reaches the machines

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:

And on the hub's machine, where root publishes what the hub's user built:

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.