garage44.eu/jeroen/midas

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

cartopolis-agent · 2026-11-27T17:22:26Z

docs: a design for midas as the git host, in place of Forgejo

Proposal only. Measured what Forgejo does for the workspace (pushes, LFS,
Actions, anonymous HTTPS, API use) and set out what midas keeps, what it adds
for agent work, what it drops, the move and its risks.
docs/git-hosting.md | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 200 insertions(+)

diff --git a/docs/git-hosting.md b/docs/git-hosting.md
new file mode 100644
index 0000000..aa8e526
--- /dev/null
+++ b/docs/git-hosting.md
@@ -0,0 +1,200 @@
+# midas as the git host — a design
+
+Status: **proposal** (2026-11-27, session s874). Nothing here is built yet.
+
+midas hosts the workspace's repositories itself, and Forgejo goes. midas does not
+become a forge. It keeps what agents and the one person steering them use, and
+drops the rest: issues, pull requests, wikis, stars, organisations, web editing
+and user accounts.
+
+## Why
+
+Every new project waits on the person, and every landing goes through a server
+that midas cannot change:
+
+- `cartopolis-agent` is not an owner of `jeroen/*`. It cannot create a repository
+  there (s794: "token does not have … write:organization"), add the hub's mirror
+  key (s487: 403 "should be an owner or a collaborator with admin"), or change a
+  setting (s797). Each new project needs the person in Forgejo's web UI, and a
+  missing key shows up only at the first deploy.
+- Registering a project is a hand edit of `/etc/midas/hub.conf` over `ssh host
+  sudo`. It has more than 30 backups, one per session that changed it.
+- The hub already serves git to every node. `mirror.rs` keeps a copy of each
+  repository fetched from Forgejo with a deploy key, and an LFS cache in front of
+  Forgejo's LFS. The origin is one hop away from where the work is.
+- `main` is not protected. That the gate ran is a convention of the
+  `finish-branch` script, not something the server enforces.
+
+What Forgejo actually does for the workspace (measured 2026-11-27, last 30 days
+unless noted):
+
+| Use | Measure |
+|---|---|
+| Pushes | 2728 by `cartopolis-agent`, 20 by `jeroen` |
+| Repositories | 12, all under `jeroen`; 9 public, 3 private (about-cartopolis, stembewijs, pinnacle-website) |
+| LFS | 710 MB |
+| Actions | `cartopolis/ci.yml` nightly (30 runs), `mithril/test.yml` on push (15) |
+| Issues, pull requests | 0 issues; landing is a fast-forward, no pull request |
+| API calls by sessions | 40 over every session since s448: reading files, keys, branches |
+| Anonymous HTTPS | Cargo `git =` dependencies and a Bun tarball (`/archive/<sha>.tar.gz`) on `jeroen/mithril` |
+| Web views | about 2,400 requests a week, mostly crawlers (57.141.0.0/24) |
+
+## What midas keeps
+
+### 1. Repositories at the hub
+
+Bare repositories in `/srv/midas/git/<owner>/<name>.git`, on the same disk as
+the mirror they replace. A repository has an owner (the person), a visibility
+(private or public) and a project: its gate, gate nodes, pre-land check, main
+branch and deploy targets. Today these sit in hub.conf `projects`. They move to
+a file the hub itself writes (`/srv/midas/projects.json`), changed through the
+hub's API, with every change logged as an event. hub.conf keeps only the
+machine's own settings.
+
+### 2. Access by key, over the ssh login the hub already has
+
+`midas hub git`, the `authorized_keys` command nodes already log in through,
+learns to answer pushes too. Every key belongs to one of three principals:
+
+| Who | Read | Push |
+|---|---|---|
+| **The person's keys** | everything | everything, including `main`, deleting branches and force pushes |
+| **Agent keys** (the container, the Macs' editors) | everything | any branch except `main`; no force push to a branch another session holds |
+| **Nodes** | their checkout's repository | nothing, as today |
+
+**A push to `main` from an agent key is accepted only from a landing.** The pusher
+must hold the turn to land (`midas land take`), the new `main` must be a
+fast-forward, and the hub must have a gate pass on record for exactly that sha
+(`midas verified`). Today all three are only conventions of the land script. In
+this design they become the server's rule, so `main` is protected without a
+person watching. The person's keys bypass the rule, as they do today.
+
+The remote URL does not change. A small sshd on port 2222 with the user `git`
+runs the same forced command, so `ssh://git@code.garage44.eu:2222/jeroen/x.git`
+keeps working in every checkout, worktree and memory note.
+
+### 3. One call makes a project
+
+`midas project create <name>` (MCP `project_create`) does in one step everything
+a new project needs today:
+
+- makes the bare repository with an empty `main` (or imports a given repo or
+  bundle);
+- registers the project, with a gate if one is given;
+- makes it visible to the session's worktree tooling (`project_add`), and makes
+  it public if asked.
+
+Agents may create, configure and archive projects. **Deleting a repository,
+renaming one, and making a private one public** go to the person as a card on
+the page and happen only on their yes. These are the outward-facing or hard to
+reverse actions. `midas project set` changes a project's gate, nodes or deploy
+targets; it replaces the hand edits of hub.conf.
+
+### 4. LFS in the same place
+
+The hub's LFS cache becomes the store, under the same `/srv/midas` with its
+backups. Agents push LFS objects over ssh (`git-lfs-transfer`, which `mirror.rs`
+refuses today). Public repositories serve them over HTTPS. "LFS object must reach
+Forgejo before the gate" stops being a step: the object is where the node reads
+it.
+
+### 5. Public read-only HTTPS
+
+Kept, because builds depend on it. Caddy sends `code.garage44.eu` to the hub,
+which serves for public repositories only, without a login:
+
+- git's smart HTTP clone (`git http-backend`), for Cargo's `git =` dependencies;
+- `/<owner>/<name>/archive/<sha>.tar.gz`, for Bun's tarball dependency;
+- LFS downloads.
+
+The paths stay as Forgejo had them, so no `Cargo.toml` or `package.json`
+changes.
+
+A browsable view (files, README, log, one commit's diff) is the part to decide.
+It costs a page of the existing web app. Who reads it today is mostly crawlers.
+See open question 1.
+
+### 6. The hub knows every push itself
+
+Pushes go through midas, so it no longer has to learn of them:
+
+- no post-receive hook to install in Forgejo's directories;
+- no mirror fetch every 20 s;
+- no "the hub did not see the branch yet" at a gate.
+
+The page's view of branches, of who changes what, and of what landed reads the
+repositories directly.
+
+## What is new for agent work
+
+The part worth building beyond parity, each small:
+
+- **Reads without a checkout.** `midas git show <repo>:<path>[@rev]`, `midas git
+  log`, `midas git grep <pattern> [--repo …]` over every repository, as CLI and
+  MCP tools. These replace the `forgejo_api` raw-file calls and the `curl …
+  archive` workarounds (s708). A session can read another project's code before
+  deciding to `project_add` it.
+- **Branch hygiene by itself.** A `session/*` branch is deleted when its session
+  is finished and its work is on `main`. An unmerged one is listed on the page
+  with its session. Today branches pile up until someone deletes them through
+  the API.
+- **Refusals at push time, not at the gate.** A pushed file that looks like a
+  secret (a private key, a token by its known prefixes, a `.env`), or a binary
+  over 1 MB not tracked by LFS, is refused with the path and the reason. "No
+  secrets or private info in repos" then has a guard, not only a memory note.
+- **Scheduled gates replace Actions.** Cartopolis's nightly `ci.yml` becomes a
+  hub timer that runs the project's gate on `main` on a node (`midas run`). Its
+  result goes on the page, and a red one becomes a note to the next session in
+  that project. Mithril's `test.yml` is its gate. `forgejo-runner` goes. The
+  Forgejo deploy workflows were the fallback for when midas is down; after this,
+  midas being down means git is down too (see Risks), so they go with Forgejo.
+
+## What midas does not do
+
+There are no issues, pull requests, reviews, wikis, releases pages, stars,
+forks, organisations, teams, web editor, webhooks to third parties, OAuth apps,
+mirroring to other forges or user accounts with passwords. A principal is a key.
+If one of these turns out to be needed, it is added for the use that needs it.
+
+## Moving over
+
+The steps, each of which can be undone until Forgejo goes:
+
+1. **New projects first.** `project_create` makes them at the hub. Forgejo keeps
+   the existing twelve. This alone answers "a new project needs no hand work".
+2. **One repository, then the rest.** Make Forgejo's copy read-only, `git clone
+   --mirror` it with its LFS objects into the hub, switch the hub to serve it as
+   the origin, and check a push, a gate and a deploy. Start with a small one
+   (`fien` or `wakamonth`), then `mithril` (public HTTPS dependencies), then
+   `cartopolis` and `midas`.
+3. **Port 2222 and HTTPS.** Point them at midas once every repository is moved.
+   The URLs do not change.
+4. **Forgejo stays read-only for a month**, with a full dump, then goes:
+   `forgejo.service`, `forgejo-runner.service`, its database and its 710 MB of
+   LFS. Removing it is a data deletion on a production box, so it waits for the
+   person's go.
+
+## Risks
+
+- **One machine for git and the workshop.** Forgejo is on the same VPS today, so
+  the failure domain does not grow, but git now also depends on the hub's
+  process. Mitigations:
+  - the forced command serves reads and writes without the hub's HTTP service
+    (plain `git-upload-pack` / `git-receive-pack` on the bare repository, with the
+    landing rule read from the hub's state file);
+  - a nightly `git bundle` of every repository and a copy of its LFS objects go
+    off the machine (open question 2).
+- **Bugs in access rules are security bugs.** The rules stay few, as above, with
+  tests for each refusal. Anonymous access is read-only and public-only, served
+  by `git http-backend`, not by our own protocol code.
+- **Hosts outside the workspace** (the Macs, the deck) reach port 2222 as today.
+  Nothing on their side changes.
+
+## Open questions for the person
+
+1. **A browsable web view of public repositories**: needed (people reading the
+   code of an open-source project), or only clone and archive URLs?
+2. **Where the off-machine backup goes**: another machine of yours (the mini),
+   or storage you name.
+3. **Forgejo after the move**: a month read-only and then removed, or kept
+   longer as an archive.