# midas — design How midas works and why. [README.md](README.md) introduces it; the guides in [docs/](docs/) say how to set it up and use it. ## Terms | term | meaning | |---|---| | **machine** | a computer in the workspace, on the workspace's WireGuard network | | **hub** | the one machine that holds the workspace's state and answers for it | | **node** | a contained checkout with a warm build directory on a machine, which one agent holds at a time; a machine may run several | | **agent** | a session that builds: it takes a node, works on it over ssh, gives it back | | **lease** | holding a node | | **caller** | a key that may change the workspace (take, release, add nodes), one per trust level | ## 1. Parts ``` agent's machine hub (user `midas`) node (on any machine) ┌────────────────────┐ ┌──────────────────────────┐ ┌──────────────────────┐ │ worktree │ HTTP │ nodes, leases, queue, │ HTTP │ rootless container │ │ midas │──────►│ readings, event log │◄──────│ OpenSSH + midas │ │ (one binary) │ │ git mirror + LFS cache │ │ guard + heartbeat │ │ ssh … ─────┼───────┼──────────────────────────┼──────►│ /work/checkout │ └────────────────────┘ ssh │ warmer (timer) │ git └──────────────────────┘ └──────────────────────────┘ all over WireGuard, system software on every machine ``` **One binary, three roles**: the CLI where agents run (also answering to `cargo`, to say where builds go), the hub, and the sshd hooks, guard and heartbeat inside every node. Each machine is set up by one root command — `midas hub setup`, `midas setup ` — that writes its settings to `/etc/midas` and is run again to update. **The hub owns the state** (`/srv/midas/state`): node definitions (`nodes.json`), leases and the queue (`registry.json`), each node's last heartbeat (`readings/`) and the event log (`log/`). Everything else asks its HTTP API. Reading is open to the tunnel; changing anything needs a caller key. ## 2. How an agent works ```bash midas take # any node; or: midas take gpu / midas take ssh gpu-1 'cargo test -p …' # build and run there scp gpu-1:/tmp/x.png . midas release # or the session-end hook does it ``` - **The node follows the worktree.** Every `ssh`, `scp` or `rsync` to a node first runs `midas holds` (a `Match … !exec` in the generated ssh config), which refuses a node the worktree does not hold and flushes one it does: the commits the node lacks (as a git bundle when unpushed) and every uncommitted change are sent, so the command runs on exactly the tree the agent sees. Not while another command from the worktree still runs there (a build in the background, a subagent's test): that sync would change files under it, so the node keeps it, and a build or test started meanwhile waits up to a minute for the running command, applies it, or is refused rather than build the old files; anything else runs at once (`MIDAS_SYNC=force` applies it under the running command anyway). - **Any repository.** The node's own checkout (`/work/checkout`, the first of hub.conf's `repos`, the one the warmer keeps warm) takes a worktree of that repository; a worktree of another one (its `origin` says which) lands in a checkout of its own, `/work/repos//`. The hub need not mirror it: a node that cannot get HEAD's history from the bundle and the mirror says so, and the flush sends the whole history once (midas's is 1 MB) — right for a small repository, while a large one with LFS files belongs in `repos`. Sessions start in the checkout last sent. Every project (§8, decision 22) uses the same nodes this way. - **Only the holder gets in.** `Match … !exec "midas holds %n"` refuses a worktree that does not hold the node, with the reason; the node's sshd admits the agent key only while the node is leased. Sessions sharing a key makes this a guard against mistakes, not against intent (`MIDAS_SSH_ANYWAY=1`). - **The queue is fair**: a freed node goes to whoever has waited longest, and the warmer never takes one somebody is waiting for. `take` waits 90 s (an agent's commands are cut off at two minutes), then exits 75 with the place kept; `midas wait`, run in the background, carries on. A place lasts two minutes without asking. - **Leases end by themselves.** A node with no ssh session open for 30 minutes is given back (nodes report open sessions in every heartbeat, and an open one renews the lease, so a long build is never cut short; so does a bot lease's running bot); a node that stops reporting is given back after two hours. - **An open session is not use when nothing runs in it** (`stall.rs`). s857's pipeline on mac-2 waited 20 hours on a pipe held open by a QEMU its xtask had orphaned, which renewed the lease and kept the agent waiting for a command that would never end (2026-11-27). So an agent's command runs in its own process group with its output relayed through midas: quiet — no output, under a second of CPU a minute for the group — for 30 minutes, the group is stopped, unless another command on the node is moving; and once the command ends, what it left holding its output gets two seconds, not the session. A background command ending is what wakes an idle agent, so stopping it is also how the session hears; the hub's note from the stop wakes it too, the one note of midas's own that does besides a decision. Both name what was still in the group and leave finding the cause to the agent, not the person. Terminal sessions, file transfers and a bot's relay are not watched. - **Builds do not run where agents are**: `cargo` there is midas and names the `ssh` to use instead (`MIDAS_LOCAL_BUILD=1` for a one-off); commands that only read the manifest (fmt, metadata, tree…) pass through. - **The node tells the session what matters**: shared GPU memory high, disk low, new files in /tmp (with the `scp`), a process killed by the memory limit, and what the previous holder left running, which it stops. ### Leases and their modes A lease has a mode: **build** (every lease before, and the default), **job** or **bot**. ### Jobs `midas run [machine] -- ` holds a node for one command: it takes the free node fastest at that command (`rank_by_speed`), runs it over ssh — the flush first, as always — and exits with its status. The lease is a **job lease**, given back a minute after the command when somebody waits for the node and ten minutes after when nobody does, so a session reading and editing between two builds holds nothing. Build leases were held nearly three times as long as anything ran on them: the Macs 102 h, of which 38 h in use, in the two weeks to 2026-11-14, while sessions waited 25 h for them (`registry::JOB_WAITED_IDLE_S`). - **Back to the node it left.** A run goes to the node its session ran on last when that is on the fastest free node's machine and nobody — a session or the warmer — has used it since: its checkout is still at the session's tree, so only what changed is rebuilt (`registry::prefer_last`). - **Up, never down.** `take` on a job lease makes it a build lease, `bot start` a bot lease; a `run` on a node held already uses it as it is. - **No notice when it goes.** A build lease given back tells its holder; a job lease's end is its design, and the next run takes a node by itself. ### Bots In bot mode the agent starts a long-running program on the node — a bot, built from the checkout, which follows the worktree as always — and talks to it over MCP: ```bash midas bot start gpu --mcp '' -- # take in bot mode, start, wait until it answers midas bot mcp # what the agent's MCP config runs midas bot stop # stop it, give the node back ``` - **MCP is stdio over an ssh session.** The bot serves MCP on a Unix socket on the node and brings its own stdio relay to it; `midas bot mcp` becomes `ssh midas node bot mcp`, which becomes the relay. midas runs the two commands it is given and nothing else (decision 14). - **On the node** (`midas node bot …`, as `build`): the bot runs detached in a session of its own, in the checkout, with the machine owner's secret (`/config/bot.env`) in its environment and its output in `/work/bot/bot.log`. `start` refuses unless the lease is a bot lease, and returns once an MCP `initialize` through the relay is answered (by default within 30 minutes: a first `cargo run` compiles for long). - **A bot lives exactly as long as its bot lease.** The heartbeat reports it, and a running bot renews its lease as an open session does — but only while its holder is in touch: an ssh session to the node, a command there or a `midas renew` within the last 30 minutes. A bot whose session has ended is given back like any idle lease (one held mac-2 for hours with nobody driving it, 2026-10-17). The same heartbeat stops a bot whose lease has gone — released, lapsed, or re-taken for building — and the next holder's handover clears what is left. `midas release` stops it directly. - **A worktree that holds a node for building may start a bot on it**: the lease becomes a bot lease. Never the other way: a `take` leaves a bot alone. **A hosted bot** has an agent of its own (decisions 18, 19): Claude Code, run by midas itself and fenced to the bot's tools, unless `--agent ''` names another ACP agent (with `--agent-meta` and `--agent-mode` for its fence): ```bash midas bot start --name scout --agent --brief --mcp '' -- midas bot log scout · midas bot tell --name scout "…" · midas bot stop --name scout ``` - **The host** runs where the agent's login is (the agent container), detached, and outlives the session that started it; the lease stays that worktree's, and the session-end hook's `release --keep-hosted` leaves it alone. Its files are `~/.local/state/midas/bots//` (configuration, session id, transcript). - **The agent's tools are the bot's**: one MCP server, `bot` (`midas bot mcp`); the host grants a permission to that server's tools only. - **Its prompts are the bot's inbox**: a second connection calls the bot's `--inbox` tool (default `inbox`) in a loop, and each non-empty answer — text and images, passed on unread — is a prompt, or joins the next while a turn runs. What the inbox holds when the host first asks is history: logged, not sent. - **It ends** when asked, after `--idle` (default 2 h) with nothing to answer, when the bot cannot be reached for about two minutes, or when the agent dies three times in ten minutes; ending gives the node back. A restarted agent loads its saved session, so the bot keeps what it knew. ## 3. A node - **Set up by the machine's owner**, with a midas they built: a user of its own (`midas-node`, never the owner's), a firewall on the machine keyed on that user, and the node. The firewall is the boundary relied on (§6). - **Rootless podman** as that user, with its own volume (`/work`: the checkout, its build directory, keys, its log), named after the node's uuid and not its name, which is a label the hub may change (`midas nodes rename`). pasta forwards one port, from the machine's WireGuard address, to the container's sshd. The container has an address of its own: with the machine's copied in, the machine's public address meant the container itself. - **OpenSSH** hooked into midas: `AuthorizedKeysCommand` (the hub's operator key always, the agent keys while leased) and `ForceCommand` (warnings, the handover, the session in the log, then the command as typed; SFTP passes straight through). - **Limits** through cgroups (memory, CPUs, processes), checked against what quadlet will really run, because quadlet once dropped them silently. A GPU's dedicated memory is capped through `dmem` where the machine delegates it. - **A heartbeat** every minute: memory against the limit, OOM kills, free disk, the build directory's size, load, GPU pools, open sessions, a running bot, what it is warm for and the midas build it runs. Three minutes of silence takes it out of the pool; the next heartbeat brings it back. - **It registers itself.** At every start it tells the hub its git key and its sshd's host key; the hub believes them because they come from the node's own WireGuard address. The hub then writes its `authorized_keys` (git for that key, nothing else), known hosts and the warmer's ssh config itself, and agents get the host keys with `midas ssh-config`. Heartbeats and lease renewals are held to the same address rule. - **No git credentials.** Its `origin` is the hub's mirror, over ssh with a key restricted to `midas hub git`; LFS objects come from the hub's cache. - **It follows the hub's midas, inside only.** Two copies of midas live in a node. The owner's, from their `midas setup` (`/usr/local/libexec/midas-owner`), is the only one the node's root runs: the entrypoint, registering, and `midas node update` every five minutes. The hub's is what everything run as `build` runs — the sshd hooks, sessions, the guard — at `/usr/local/bin/midas`: while nobody holds the node and nothing runs there, `node update` fetches the hub's build for its platform from the hub (from the node's own address only), runs it as `build` to ask which build it is, refuses one that does not say the build the hub promised, and renames it over. So a deployed hub reaches every node within minutes of it being free, with no owner's sudo, and the machine's side never runs a byte of it (§6, decision 23). What still needs the owner is a changed **recipe** — the container or VM, the node's user, the machine's firewall, as a hash of setup's files (`setup::recipe`): each node reports the one it was set up from, and `midas check` and the page name the nodes whose owner must run `sudo midas setup` (or `midas update`) again. ## 4. The GPU memory guard On an AMD APU the shared GPU pool (GTT) can fill: the kernel tries to swap GPU buffers out, everything touching the GPU stalls, and a killed process cannot exit — the whole machine freezes (2026-10-10). **GTT is not charged to the container's memory cgroup** (measured: GTT 568 → 4,235 MB during a capture while the container's own memory peaked at 2.4 GB), so only the guard protects against it. `midas node guard` runs in the node as `build`, the user that can read the sessions' `/proc//fdinfo`. Every 2 s it reads GTT: at 80 % sessions are warned, at 92 % the largest holder gets SIGTERM and the next session is told. The machine stays up first; the agent is told second. ## 5. The hub - **Settings**: `/etc/midas/hub.conf` — where it listens, the git server and its API, the repositories nodes may fetch, the agents' public keys, and what warming means (`warm`: a branch, build steps, optional steps). - **API** (`hub.rs`): reads — `/v1/health`, `/v1/state`, `/v1/events`, `/v1/watch`, `/v1/position`, `/v1/lease/`, `/v1/nodes//config`; from nodes, only from their own address — `/v1/renew/`, `/v1/readings/`, `/v1/nodes//register`, and `/v1/events`; with a caller key — `/v1/claim` (in a `mode`, build or bot), `/v1/release`, `/v1/renew`, `/v1/unqueue`, `/v1/drain`, `/v1/nodes/add`, `/v1/nodes/remove`, and `/v1/forgejo/…` (made with the caller's own Forgejo token, so Forgejo's permissions are the access). - **Confinement**: a systemd service as `midas` — read-only system, no capabilities, a syscall filter, 512 MB — because it answers nodes that run untrusted builds. - **The warmer** (every 15 minutes): a free node — never one held, in either mode — that is cold, over what its disk allows its build directory (as far as leaves 20 GB free on /work, 24 GB to 80 GB; trimmed by dropping the oldest profile or target first, the whole of it last) or three days stale is leased like any agent would, brought to the branch, and built with the configured steps, each step and its duration logged. Never cold rather than always current: a node warm at last week's commit costs only the workspace's own crates. A node somebody holds is trimmed by its own guard instead, after each measure of its build directory (every ten minutes) while no ssh session and no bot is on it: the same order, each part renamed aside in one step so no build sees it half gone. - **Nobody is mailed.** A problem midas can fix it fixes; what only a person can (a machine that is off, a setup to rerun as root) is on the Workspace page and in `midas check`, and a decision put to the person wakes their phone (`push.rs`). Mailing what lasted an hour sent 73 mails in 60 days, every one a held node's build directory that the warmer trimmed once it was free (2026-11-22). ## 6. Security The hub's machine is assumed to be compromisable — the agents and the git server live there too — so a node is untrusted and what must hold is the build machine, its owner's files and home network. That is set on the machine, by its owner, with a midas they built: the node's own user; a firewall keyed on that user (the hub and the internet yes; private addresses, the machine's own addresses but its public web ports, and IPv6 no; from the tunnel only the node's ssh port); nothing from the hub executed on the machine. What the hub decides — which keys log into the container, which repository it checks out — only reaches inside the container — the midas the node's `build` runs included (§3). Tested by switching the container's own fence off: the node still reached only the hub, the internet and the machine's public website. ## 7. Logs and checks **One log, on the hub** (`log/events-YYYY-MM-DD.jsonl`, 90 days): claims and refusals (with what was passed over and why), the queue, leases ending, ssh sessions with exit status and duration, flushes, handovers, OOM kills, guard actions, bots started, ready, failed and stopped (with why), heartbeats lost and regained, warms step by step, Forgejo calls by caller, errors. Nothing secret. `midas log`, `midas explain ` and `midas status` read it. **`midas check`**: the hub, every node's heartbeat, build, disk, build directory and warmth, the local ssh config, Forgejo through the hub, and the last day's failures. It prints what is wrong (`-v`: every check), and labels a problem that is an owner's — a node's machine, the warmer, the midas installed here — apart from the caller's own; its exit status is the number of the caller's. **`midas mcp`** offers the same as MCP tools, plus Forgejo. ## 8. Decisions 1. **The hub owns the state, everything else asks it.** The cost: with the hub down nobody can take a node. 2. **Node access is OpenSSH**, hooked through `AuthorizedKeysCommand` and `ForceCommand`; a protocol of midas's own and an embedded ssh server were designed and dropped. 3. **WireGuard is system software**: its roaming keeps sessions alive when a mobile machine's address changes. 4. **The hub is a confined service, not a container**: systemd already gives it its own user, a read-only system and a syscall filter. 5. **One binary, one command set.** `cargo` where agents work is midas by name. 6. **Leases on the hub, not claim files on a node's disk.** 7. **Nodes are data**: an entry in `nodes.json`; nothing in the code names a machine. 8. **GPU memory: the machine stays up first**, the agent is told second. 9. **Agents use plain `ssh`, `git` and `scp`**; no wrapper in front. 10. **No login on an owner's machine** (2026-10-11): an early node shared its owner's home, and agents left 29 GB there. 11. **Plan for a compromised hub machine** (2026-10-12): the boundary is set on each build machine by its owner. Nodes stopped updating themselves; signing updates on the hub's machine was rejected, since the key would be on the machine assumed compromised. 12. **Nodes register their own keys, by WireGuard address** (2026-10-12): copying keys by hand was a step every re-setup needed and every new machine got wrong once. 13. **One set of terms** (2026-10-13): machine, node, lease. The `slot` command went with the word. 14. **Bots: MCP as stdio over ssh, and the token on the machine** (2026-10-15). Nodes allow no forwarding (§3), so a bot is reached the way everything on a node is, through an ssh session — whose stdin and stdout are a pipe MCP already speaks. The bot brings its own relay from that pipe to its socket, so midas has no HTTP client, port or MCP token: it runs two commands it is given. The bot's credential is the machine owner's to give and is set on the machine (`sudo midas bot setup`), never on the hub, which is assumed compromisable (§6). Known limitation: anything running as `build` in the node — the holder's sessions, and the hub's operator key — can read a running bot's environment, token included. A separate user for bots would close that and is deliberately deferred: the holder is trusted with the bot it started, and the operator key is the workspace's own. 15. **Deploys without a CI system in between** (2026-10-16). The landing gate runs the tests on a node; the deploy workflows then built the same commit again on a CI runner — on this same machine, with three slots shared with everything else — to copy the result into a directory here. `midas deploy` builds on a node instead and publishes here, and keeps what CI gave: only a commit on the warm branch, only with the gate's receipt (or a logged reason), built in a checkout of exactly that commit. It is split where the privilege changes. The hub's user queues and builds; root publishes, taking every destination, check and user from the root-owned `hub.conf` and reading what the hub's user hands it refusing a symbolic link at every level, so a compromised hub can make root publish bytes only to the places that file names. Root reports by events sent to the hub, never by writing into the hub's directories. Known limitation: a node is less clean than a fresh CI container — its warm `target/` outlives its holders — which is acceptable while every holder is the workspace's own agent, and would call for a build directory of the deploy's own if it were not. Revised 2026-11-21, before the code went public: "only to the places that file names" did not hold where a place was root's own executable — midas's self-update ran the published binary as root, so the hub's user was root — nor where the place's directory belonged to someone else, who could swap a level of it for a link between root's calls. Root now writes relative to a destination directory opened without following links, and runs a published midas only as hub.conf's `self_update` says: `hub` (as before, the default), `signed` (the owner's key on it, never on the hub: `release.rs`), or `off`. The honest default is still `hub`: a workspace that has never made a release key must keep updating itself the day it takes this build. 16. **Bot secrets kept by the hub** (2026-10-16), revising 14. A bot's token was set on its machine by root (`sudo midas bot setup`), which meant a sudo session per machine, and a Mac node — a VM with no configuration directory of the machine's — could not have one at all. `midas bot token ` gives it to the hub instead, from anywhere with a caller key; the hub keeps it in a 0600 file of its own and `midas bot start` hands it to the bot over the ssh session's stdin, so it is on no node's disk, in no command line and in no log (only its name is). The price, accepted while every machine has one owner: a caller key reads it back, and a compromised hub has every one — no worse than its operator key, which could already read a running bot's environment. The per-machine way stays for a token that must not pass through the hub; where both set a name, the hub's wins. 17. **A landing queue, and the gate on the fastest node** (2026-10-17). The landing gate used to rebase, then wait for a VPS node, then test, then push — and in the week to 2026-10-17 every gate ran on one VPS node, one after another, each waiting 8–28 minutes. The landing ahead pushed the moment its gate ended, which was when the next one's started, so that one tested a base already gone and, green, was bounced at the push and run again: at least six times that week, while two Mac nodes that gate in half the time sat free. So the hub keeps one turn to land (`midas land`), taken before the rebase and held through the push; a landing in progress is never overtaken, and one that dies lapses after ten silent minutes. The turn is not a node, so the gate's node is still taken inside it — now by measured speed for that command (`take --fastest-for`). A git server on the hub's machine reports pushes through its post-receive hook, from the hub's own address, with no key: all it can do is make the hub fetch sooner. Writes to the branch stay with the git server, which keeps its own branch table and CI triggers. 18. **A bot's agent, hosted over the Agent Client Protocol** (2026-10-18). A bot was driven by the agent session holding its lease, which typed MCP JSON-RPC through `midas bot mcp` in a shell and kept a background `read_chat` waiting: a re-arm forgotten, and the chat went unanswered and the lease lapsed. Nothing wakes an idle session from outside but its own background work. So `bot start --agent` runs the agent itself, as an editor does: ACP is JSON-RPC on the agent's stdio, spoken by Gemini CLI and goose natively and by Claude Code and Codex through official adapters, and used by the chat-to-agent bridges of 2026. Rejected: Claude Code's `--channels` push (one vendor's, and a launch flag Remote Control spawns do not take); MCP sampling (deprecated in the 2026-07-28 spec, never in Claude Code); a model loop of our own (a whole agent, and an API key). The host passes the inbox's content on unread, grants permission only to the `bot` server's tools, sets the session mode at every start (an agent otherwise takes it from its user's settings — Claude Code took "auto" from the agent container's), and holds no credential: the agent logs in as it would anywhere. A subscription login is its owner's own use; a bot serving other people needs an API key in the agent's environment. 19. **Claude Code's ACP adapter is midas's own** (2026-10-21), revising 18. Claude Code's official ACP adapters are npm packages (one renamed and deprecated within weeks), so every agent meant Node, an `npx` download at start and a Claude Code bundled inside the package, older than the one installed. `midas acp` is that adapter in Rust (`acp.rs`): it runs the installed `claude` in the stream mode its SDKs drive (`--print`, JSON lines both ways, `--permission-prompt-tool stdio` for permission questions) and translates. Rejected: driving that stream from the runner and the host directly (two clients rewritten, and tied to one agent where ACP lets any other plug in); keeping the npm adapter (a runtime and a package nobody here wants). It refuses a `claudeCode.options` key it does not know rather than drop part of a fence, and offers no permission beyond the session. It is the agent a bare `bot start --agent` hosts too, with the bot's fence (no built-in tools, no settings files, only the bot's MCP server) and mode `default` set by midas: the bot needs no package and no settings file from the repository that runs it. 20. **An editor's session, mirrored** (2026-10-22). A session started in Zed on a workstation was invisible to the hub: nobody could follow it or answer its permission requests from a phone. `midas acp --mirror` (`tap.rs`) is the editor's agent: it runs the real agent (`midas acp`) behind it, passes every message through untouched, and attaches each session to the hub at its first prompt (`/v1/hosted/attach`, a key's route like a runner's push), found again by the agent's conversation id when the editor loads it. The page steers it as it steers a runner's — message, permission, cancel, mode, model, queue — through the runner's long poll with `take: false`, so a mirror never starts queued sessions. Whichever of the page and the editor answers a permission first wins; the other's answer is dropped. The agent and its conversation stay on the workstation, so a mirrored session cannot be reopened on the page: taking it over (its worktree's changes onto a branch, its transcript under the runner's project directory, one writer at a time) is the next step, not this one. Rejected: a hook-based mirror (hooks see tool calls, not the conversation, and cannot answer a permission); the editor as a thin client of a hub-run session (the agent would leave the workstation's checkout, which is the point of working there). 21. **A session moves between the editor and the runner** (2026-10-22), the step 20 left. Claude Code resumes a transcript moved to another machine's projects directory (named for the working directory) with the same id and knows its new directory — tried before building on it. So a session moves as three things: its work, as a branch; its transcript, through the hub; and which side runs it, which the hub records (`handed`, `handed_back`) and enforces — a status pushed by the side that no longer has it is not heard, so a late "waiting" from the editor cannot strand a session queued for the runner. One side runs it at a time: the editor's agent session is closed (ACP `session/close`) before anything moves, the runner's agent stopped before it goes back. The work is the working tree as a commit made through a throwaway index (`handoff.rs`), so the person's checkout, index and HEAD are never touched on the way out; coming back, it is restored into the working tree only when the checkout is exactly as it left, so nothing made meanwhile is overwritten — otherwise the person and the agent are told where it is. Rejected: moving the checkout's changes with a stash or a commit on the person's branch (both change their checkout behind them); `git bundle` or rsync of the worktree (the remote both sides already push to is simpler and keeps the history); the page loading the transcript into the runner's agent by replaying it as prompts (loses tool calls and costs a turn per message). `midas acp` gained what the round trip needs from Zed: `session/list` (Zed's thread history), history replay on `session/load`, `session/close`, and on the way edit diffs and slash commands. 22. **Projects** (2026-10-23). A project is a repository of hub.conf's `repos` (`owner/name`, named by its last segment): cartopolis, podium, midas. The machines are the workspace's, not a project's — every project's sessions take the same nodes, which keep a checkout per repository already (§2) — so a project adds nothing to define but its repository. A session records its project (`repo`): the page chooses one when it starts a session, the CLI takes the checkout's, an editor's mirror says its checkout's origin. The runner keeps a checkout per project, `MIDAS_SESSIONS_REPO` for its own and `repos//` under `MIDAS_SESSIONS_DIR` for the others, cloned when the first session of one comes. Seen on the way: a podium session handed over from Zed went to a runner that only had cartopolis's checkout, did not find its branch, and failed — closed in the editor, failed at the hub, run by neither. So the hub refuses a handover from a repository that is no project before the editor closes anything, and a session the runner cannot take over goes back to the editor as it left (`handed_back` with the editor's own snapshot and transcript). Rejected for now: projects with machines of their own, or settings beyond the repository (the warmer and deploys stay the first repository's; deploys no longer do, 25). The page never switches projects, as the work of several goes on at once: it names each session's project (a tag on its card and in the list, from its start's `repo` when midas neither runs nor mirrors it), and narrows Home and the list to one when asked, a view and never what runs; a node busy with another project's work still shows busy. 23. **Nodes follow the hub's midas, as `build` only** (2026-10-23), revising 11. Every change to the hooks, the heartbeat or the guard waited for each owner's sudo on each machine, so nodes ran a spread of builds and a fix reached the Macs days late. Everything that runs as `build` already obeys the hub — the code every build compiles and runs, and who may log in — so the hub's midas there grants a compromised hub nothing it lacked. It never runs as the node's root: the updater is the owner's copy, so a broken build from the hub cannot break the updater that takes its fix, and what fences the node — the node's user, the machine's firewall, the container or VM and its limits — stays the owner's, changed only by their `midas setup`. Updating the machine side from the hub's page as well was designed and deferred: it needs an approval the hub cannot forge (a passkey on the owner's phone, checked by a root updater on each machine) and a build the hub's machine does not control, and even then the page asking for it is served by the hub. 24. **A session spans the projects its work needs** (2026-10-25), revising 22. Asking the person to choose a project before a session starts was a click that knew less than the agent would a minute later, and it made a change across two projects (podium needing a midas feature) two sessions. A session started from the page now works in a folder of its own (`session-`, marked `.midas-session`), never a repository, and its agent adds projects with the `project_add` tool as the task turns out to need them — one, several, or none for a question: each a worktree at `./`, on branch `session/` off its main, its skills linked into the folder. The hub keeps the list (`repos`; `repo` stays the first, for the list and the board) and says each addition in the conversation. Everything per-worktree stayed per-worktree: a node keeps a checkout per repository already and follows whichever worktree the ssh runs from; a worktree in a session's folder is that session's (`flush::worktree_owner`), so its nodes, notes and landing gate are the session's; and each project lands on its own through finish-branch, the one depended on first, each landing standing on its own on main, `--finish` on each so the session finishes when all are live. Work in progress is kept per project (`podium:web/app.ts`): a session's build in one project no longer replaces what it changes in another, and the same path in two projects is no overlap. Rejected: picking the project with a small model before the session starts (built, and replaced the same day — the agent decides better with the task in front of it, and a pre-pick still allowed only one); one landing across repositories (Forgejo moves one main at a time, so it could only be emulated, and a half-landed pair is better prevented by order than repaired). What Claude Code keys by the agent's directory is carried by hand, as the folder is no project: a project's own hooks (`.claude/settings.json`) through one hook per event in the folder's settings, `midas hook projects`, which hands each event to the hooks of the projects it concerns (an edit's to its file's project) and puts their answers together — a project's start hooks run when it is added, their word in the tool's answer; and its memory, which Claude Code keeps per directory: the folder's syncs the workspace's notes, and its first project's once it has one, and the tool's answer lists each added project's. midas's own hooks treat the folder as the session's checkout. Sessions of one worktree (older ones, and those handed over from an editor) keep that form and cannot add projects. 25. **Every project deploys the same way** (2026-10-27), revising 22. Deploys stayed the first repository's, so a second project with something to serve (dardasha) was brought up to date by hand on the host, and its landings on the page waited on cartopolis's deploys ("apk deploying, atlas deploying" under a dardasha landing), as the page knew one set of targets. A project's targets now sit in its own `projects` entry in hub.conf (`deploy`), built from its own main in its checkout on the node (`/work/repos//` beside the node's own, where a session's flush puts it), and the hub ships and judges "live" per project: a landing waits on its project's deploys and no other's. The old top-level `deploy` section is still read, as the first repository's, so a hub.conf need not change on the day. Kept the workspace's: target names (`midas deploy ` takes a name alone, and one in two projects is refused until renamed), the hold (a person holding deploys means all of them), and the landing queue a deploy waits behind (one queue for every project). 26. **A session carries on at a time it sets** (2026-10-29). Asked to stop a long job at 3,500 of 4,500 and do the rest the next day, a session answered "tomorrow I do the last 1,000", and nothing would have woken it: its turn ended, and Home showed it under At work and then Idle like one forgotten. Claude Code's own wake-ups (`ScheduleWakeup`, cron) live in the agent's process, which a runner restart or a finished session ends, and the page cannot see them. So the hub keeps the time (`wake`: one per session, its words for then, who set it), sends it as a message "From midas" (`tell`), reopening an ended session first, and the page shows it as a state of its own (Scheduled) with Now, Move and Cancel. One time, not a list: work over days is a chain, each turn setting the next, so there is always one next step to show and to move. Times are said with their offset from UTC: the hub and the agent container run in UTC, and the person's clock is the page's, so the page moves a time in the browser's zone and the agent asks when it cannot tell. Rejected: a cron of prompts per session (repeating work is a routine, not a session's next step); the agent keeping a background `sleep` (gone with its process, and invisible). 27. **The person's decisions are counted, and capped by them** (2026-11-04, `focus.rs`). Steering several sessions a day from a phone wore the person out, and the research agrees (BCG's survey of 1,488 workers: how much oversight the AI needs best predicts mental fatigue, and output fell from a fourth agent on). So the hub keeps a ledger of what they decide, with points for what it likely cost (one per decision, more for an interruption, a switch between sessions, a long read, a landing, a late hour, words of their own), and lets them set a daily cap, decision blocks and quiet hours. The limits only change what wakes the phone and what the autopilot takes on: nothing is hidden, and every question can be answered on the page whenever they like. The autopilot learned to say whether what it leaves needs the person now or can wait for a block, and to decide by rules the person approved in their own words, which it proposes from their earlier answers. Points estimate effort and nothing more, so a one-tap check-in (fresh … fried) sits beside them and suggests a cap from the person's own days. Rejected: measuring attention from reading time on the page (a phone's page is open while nobody reads it, and it watches the person rather than the work); a cap that refuses new work (the person decides; at the cap the page asks, and only a schedule waits); learning rules silently from answers (a rule the person never saw decides in their name). 28. **Work is thought of from a goal, on a research tree** (2026-11-15, `tree.rs`). Every session began with the person thinking of it, and what midas had for the rest generated work from a kind of task rather than a goal: the self-filing autopilot (retired 2026-09-11) filed work nobody asked for, and templates run without direction gave vague performance sessions. So the person keeps goals, a scout fills in the techs on the way to each from the code and from what earlier sessions left open, and the tree shows how far a goal is and what is next, as Civilization's does — the form was the person's. What one move found stays in the fog until a second finds it too or the person keeps it; an icon is rebuilt from geometry before the page draws it. Rejected: sessions straight from a goal (the old filer with a better prompt); a roadmap written once (stale by the second landing); a backlog with priorities (the retired ticket workflow — the tree owes nothing, and its fog fades). 29. **What is deployed is watched, inside midas** (2026-11-18, `watch.rs`). A landing was live the moment it was published, and nothing looked after that: a target failing was found by whoever tripped over it. So the hub samples each deploy target with a `watch` once a minute — its systemd unit's state, memory, CPU and restarts, and probes that must answer — and the page charts them beside the deploys, each naming the landings it carried. Rejected: Grafana with Prometheus and Loki (three more services on the machine they would watch, with logins of their own, and none knows what a landing or a session is, which is what the first question after a failure asks). Only deploy targets, and only from the hub's own machine, so the machine going down is not seen (the person's choices). This is the first step of the proposal; incidents, rollback and agents put on them build on its `watch_changed` events. 30. **Root on the hub's machine only in a window the person signs** (2026-11-28, `admin.rs`). The agents reached the hub's machine as an account with passwordless sudo and the docker group, held by every session at all times: any wrong command, any instruction hidden in a page a session read, and the autopilot answering for the person all ran with root over the git server, the certificates and the deployed services. Now they log in as a user of their own, root only while a window is open: a session asks (`midas admin`), the person's passkey signs the grant (who, how long, why, when), and root checks that signature against a key the person installed from their own login before it writes the sudoers file. The hub carries the request and the signature and cannot make either, as with a release (decision 23's deferred updater asked the same). Root caps what it takes — one user, at most an hour, a grant used once and signed minutes ago — because the page asking for the tap is the hub's, and a person tricked into one should give one window, not a standing grant. Rejected: root trusting the hub's word that the person allowed it (the hub's sign-in would guard root); the window checked by the agents' own tools (an agent could skip them). A window is consent and a record, not a cage: closing it kills root processes from the user's logins, but what root started through systemd, or installed, outlasts it. ## 9. What went wrong, and what midas does about it | incident | what midas does | |---|---| | Build tools lost on a container recreate | versioned here; the binary on a volume, its names re-linked by the session hook | | The warmer took a node somebody had waited an hour for | a fair queue; the warmer yields | | An idle session held the only node, unnoticed | `status` shows holder, purpose, last command; idle leases end after 30 minutes | | A lease lapsed under a working agent and its checkout was reset | open sessions renew the lease; only the holder's flush and the next lease's handover touch a node | | A machine froze: shared GPU memory exhausted | the guard (§4), limits, the agent told | | A guard loop died, unnoticed | heartbeats; `midas check` in every session's first message | | A sync said "synced" after a git failure | the flush is checked on `take`; failures are logged | | Unpushed commits never reached a node | bundled from `HEAD` | | A session ran in another's checkout | `midas holds` refuses the connection | | A node shared its owner's home and network | its own user and a firewall on the machine (§6) | | Every session had root on the hub's machine, always | a user of the agents' own, root only in a window the person's passkey signs (decision 30) | | Every incident diagnosed from transcripts | one structured log (§7) | | Green gates rerun because another landing pushed while they waited | the landing queue (decision 17) |