Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: Run agent-ro tests
run: bash scripts/agent-ro/tests/run-tests.sh

- name: Run swm-macos-runner tests
run: bash scripts/swm-macos-runner/tests/run-tests.sh

- name: Run watchdog tests
run: npm --prefix workers/nos-runner-watchdog test

Expand Down
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

This repo is the **dev-env infrastructure repository** — it contains documentation, design plans, templates, and hook extensions for Andrew's Claude Code development environment. It is not an application codebase and there is no build step, but it is not command-free either:

- **Tests**: `bash scripts/org-migration/tests/run-tests.sh` runs the hermetic stub-`gh` suite for the org-migration tooling. Run it after any change under `scripts/org-migration/`. `bash scripts/dependabot-digest/tests/run-tests.sh` covers the Dependabot digest classifier and renderer; run it after any change under `scripts/dependabot-digest/`. `bash scripts/site-monitor/tests/run-tests.sh` covers the production-site monitor's alert transitions; run it after any change under `scripts/site-monitor/`. `bash scripts/nos-runner/tests/run-tests.sh` covers the NOS self-hosted runner supervisor, installer and pf guard; run it after any change under `scripts/nos-runner/`. `bash scripts/agent-ro/tests/run-tests.sh` covers the agent read-only ssh account (gate, sweep, installer); run it after any change under `scripts/agent-ro/`. `npm --prefix workers/nos-runner-watchdog test` covers the runner watchdog Worker; run it after any change under `workers/nos-runner-watchdog/`.
- **Tests**: `bash scripts/org-migration/tests/run-tests.sh` runs the hermetic stub-`gh` suite for the org-migration tooling. Run it after any change under `scripts/org-migration/`. `bash scripts/dependabot-digest/tests/run-tests.sh` covers the Dependabot digest classifier and renderer; run it after any change under `scripts/dependabot-digest/`. `bash scripts/site-monitor/tests/run-tests.sh` covers the production-site monitor's alert transitions; run it after any change under `scripts/site-monitor/`. `bash scripts/nos-runner/tests/run-tests.sh` covers the NOS self-hosted runner supervisor, installer and pf guard; run it after any change under `scripts/nos-runner/`. `bash scripts/agent-ro/tests/run-tests.sh` covers the agent read-only ssh account (gate, sweep, installer); run it after any change under `scripts/agent-ro/`. `bash scripts/swm-macos-runner/tests/run-tests.sh` covers the smartwatermelon macOS runner's fork-guard hook; run it after any change under `scripts/swm-macos-runner/`. `npm --prefix workers/nos-runner-watchdog test` covers the runner watchdog Worker; run it after any change under `workers/nos-runner-watchdog/`.
- **Lint**: `shellcheck -S info <script>` applies to every shell script in the repo, and must be clean with no `# shellcheck disable` directives.

## Repository Structure
Expand All @@ -26,6 +26,7 @@ This repo is the **dev-env infrastructure repository** — it contains documenta
- `scripts/site-monitor/` — Every 15 minutes, checks each production Netlify site in `sites.json` and its latest `site-check` run; keeps one `site-down` issue and pushes ntfy.sh alerts. Run by `.github/workflows/site-monitor.yml`, which a launchd job on MIMOLETTE starts through `dispatch-monitor.sh` because GitHub's cron never fired. The `NTFY_TOPIC` secret and the dispatch token are installed by hand: see `docs/runbooks/site-monitor-ntfy.md`
- `scripts/nos-runner/` — Supervisor, installer, updater and pf guard for the self-hosted runner on MIMOLETTE: one Apple container VM per private nightowlstudiollc CI job, selected by the `NOS_RUNNER` org variable. Tests in `scripts/nos-runner/tests/run-tests.sh`. Credentials and the first install are by hand: see `docs/runbooks/nos-runner.md`
- `scripts/agent-ro/` — Installer, root gate and ACL sweep for `agentro`, a separate ssh account agents use instead of Andrew's admin login: it reads his home and queries his services but cannot change anything. Run by hand with sudo on each target: see `docs/runbooks/agent-ro.md`
- `scripts/swm-macos-runner/` — Tooling for the smartwatermelon macOS CI runner on MIMOLETTE (one Tart VM per job); the supervisor, image build, guest scripts (fork-guard hook), installer and LaunchAgent, with tests in `scripts/swm-macos-runner/tests/run-tests.sh`. Credentials and the first install are by hand: see `docs/runbooks/swm-macos-runner.md`
- `workers/nos-runner-watchdog/` — Cloudflare Worker (cron every 10 minutes) that moves `NOS_RUNNER` to `ubuntu-latest` when the runner is down, re-runs stuck runs and sends ntfy alerts; tests via `npm --prefix workers/nos-runner-watchdog test`. Deploy by hand through the Cloudflare API: see `docs/runbooks/nos-runner.md`
- `.project-hooks/pre-commit` and `.project-hooks/pre-push` — Project-specific git hook extensions, run by the global hooks at `~/.config/git/hooks/` when executable
- `.claude/` is ignored, as in every fleet repo (dev-env#178). The scaffold the post-checkout hook drops there (`config.sh.template`, `README.md`) comes from `smartwatermelon/dotfiles` `git/template/.claude-template/`; edit it there.
Expand Down
7 changes: 5 additions & 2 deletions docs/runbooks/nos-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ Run these in a terminal on MIMOLETTE, in a GUI login session.
git clone https://github.com/smartwatermelon/dev-env ~/.local/share/dev-env
```

2. Install the pf guard once, as root. It blocks job VMs from the LAN:
2. Install the pf guard once, as root. It blocks job VMs from the LAN.
The guard runs every 60 s and loads the NOS anchors and the Tart anchors (`swm-tart.pf`, `swm-tart-v6.pf`)
for the smartwatermelon macOS runner:

```bash
sudo /bin/bash ~/.local/share/dev-env/scripts/nos-runner/net/install-pf.sh
Expand Down Expand Up @@ -163,7 +165,8 @@ First deployed 2026-11-12.

## 8. Alerts

All alerts go to the ntfy topic.
All alerts go to the ntfy topic. The topic also carries the smartwatermelon macOS runner's alerts, which start with `macOS runner:`
(`docs/runbooks/swm-macos-runner.md`).

- **down.** The runner failed its checks. `NOS_RUNNER` is now `ubuntu-latest`. Runs stuck on `mimolette` are cancelled and re-run on GitHub.
- **recovered.** `NOS_RUNNER` is back on `mimolette` after healthy checks.
Expand Down
204 changes: 204 additions & 0 deletions docs/runbooks/swm-macos-runner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
# smartwatermelon macOS runner: install, operate, undo

smartwatermelon macOS CI jobs run on MIMOLETTE, in one Tart VM per job, one job at a time.
A workflow opts in with `runs-on: ${{ vars.SWM_MACOS_RUNNER || 'macos-latest' }}`.
The `SWM_MACOS_RUNNER` org variable picks the runner label:

| Value | Where jobs run |
|---|---|
| unset | GitHub-hosted `macos-latest` (the fail-safe) |
| `mimolette-macos` | This runner |
| `macos-26` | GitHub-hosted `macos-26`. This is the hold value (section 6) |

The supervisor never writes `SWM_MACOS_RUNNER`. You set it by hand.
Design: `docs/superpowers/specs/2026-11-17-swm-macos-tart-runner-design.md`.

Run every step in a terminal on MIMOLETTE, in a GUI login session.
launchd starts the supervisor in `gui/<uid>`, so Tart runs there too, never through ssh.

## 1. Credentials

- The GitHub App is `swm-runner`: App ID 5807971, installation 183107042.
It is already installed on smartwatermelon.
- Its key is in the MIMOLETTE login Keychain: service `swm-runner-app-key`, account `smartwatermelon`.
The item holds the PEM as base64 text on one line.
- Check the key. This prints nothing when it is a valid private key:

```bash
security find-generic-password -s swm-runner-app-key -a smartwatermelon -w | base64 -d | openssl pkey -noout
```

- Alerts reuse the NOS ntfy topic from `~/.config/nos-runner/env` (`NTFY_TOPIC=...`, mode 0600).
Every message starts with `macOS runner:`. The topic is a secret. Never commit it.

## 2. Install the pf guard (sudo)

The pf guard blocks job VMs from the LAN. The supervisor starts no VM until it sees the guard's ok files.
The NOS installer also loads the Tart anchors, and the guard checks them every 60 s:

```bash
sudo /bin/bash ~/.local/share/dev-env/scripts/nos-runner/net/install-pf.sh
```

Run it again after any change to a `.pf` file or the guard.
See `docs/runbooks/nos-runner.md` for the guard.

## 3. Install

Clone dev-env to `~/.local/share/dev-env` if it is not there yet (section 4 of the NOS runbook). Then, as the login user, not root:

```bash
/bin/bash ~/.local/share/dev-env/scripts/swm-macos-runner/install.sh
```

`install.sh` copies the supervisor, `config.sh`, `lib.sh`, `image/`, `guest/` and `github-app.sh`
to `~/.local/libexec/swm-macos-runner` on the internal disk. `guest/` must be there: `config.sh` hashes it into the image name,
and the name is empty without it. Nothing the supervisor runs lives under `/Volumes`.
It then renders `~/Library/LaunchAgents/com.smartwatermelon.swm-macos-runner.plist`, runs `launchctl bootout`, waits, and runs `bootstrap gui/<uid>`.

- The plist sets `TART_HOME=/Volumes/extra-vieille/Caches/tart`, `RunAtLoad`, `KeepAlive` and `ExitTimeOut` 300.
A stop takes at most about 230 s (stop 60, delete 120, runner DELETE 30, ntfy 20), so 300 leaves margin.
- `install.sh` refuses a topic with characters outside `A-Za-z0-9_.-`. It warns, and sends no alerts, when there is no topic.
- The updater (section 3a) installs a change under `scripts/swm-macos-runner/` by itself. Run `install.sh` by hand only when the change touches the updater's own plist.
The log is `~/Library/Logs/swm-macos-runner.log`.
- Optional env-file lines `SWM_<NAME>_S=<seconds>` (for example `SWM_CLONE_LIMIT_S=1` for the hang drill) go into the supervisor plist on the next `install.sh` run.
`install.sh` refuses any other `SWM_` line, and a knob set twice, before it installs anything.

`install.sh` also installs `update.sh` and loads a second job, `com.smartwatermelon.swm-macos-runner-update` (section 3a).

Drill the alert path (touches no VM):

```bash
/bin/bash ~/.local/libexec/swm-macos-runner/supervisor.sh test-alert
```

## 3a. The updater

The updater job runs `update.sh` at load and every 600 s. It always exits 0.

- It runs `git pull --ff-only` in `~/.local/share/dev-env`. A failed pull (network down, or the NOS updater holding the clone's lock) is logged and tried again on the next run.
- The version is the last commit that touched `scripts/swm-macos-runner/` or `scripts/nos-runner/github-app.sh`.
The installed version is in `~/.local/state/swm-macos-runner/installed`.
- A hand run of `install.sh` records the version it installs, so the updater's first run does not restart the supervisor a second time.
- On a new version it runs `install.sh`, which restarts the supervisor. It waits while the slot file `~/.local/state/swm-macos-runner/slot` says `job=1`, so a running job is never cut short.
`job=1` means the JIT config was handed over: the runner may be idle or busy. An idle JIT runner holds `job=1` for up to `SWM_JOB_MAX_S` (6 h).
The updater logs `a job is running; waiting`, writes `~/.local/state/swm-macos-runner/update-pending` and tries again in 600 s.
- The supervisor looks for `update-pending` at the start of each pass, before it clones a VM. While the file exists it waits (at most `SWM_UPDATE_WAIT_S`, 900 s) for the updater to install.
The updater removes the file after a good install, or when there is no new version.
So an update installs within one cycle: at most `SWM_JOB_MAX_S` + 600 s after the merge, and sooner when a job ends.
- If `install.sh` fails, the version stays unmarked and the next run tries again.
- The updater never reloads itself. When a change touches its own plist, run `install.sh` by hand.
- The log is `~/Library/Logs/swm-macos-runner-update.log`.

Stop the updater (the supervisor keeps running):

```bash
launchctl bootout gui/$(id -u)/com.smartwatermelon.swm-macos-runner-update
```

With the updater stopped, delete `~/.local/state/swm-macos-runner/update-pending` if it exists, or each supervisor pass waits 900 s.

`install.sh` loads it again. To remove it for good, delete `~/Library/LaunchAgents/com.smartwatermelon.swm-macos-runner-update.plist` after the bootout.

## 4. First build (about 15 min)

The first start builds a local runner image from the pinned base image, so jobs have no image to pull.
It needs 60 GB free on the Tart volume. Watch it:

```bash
tail -f ~/Library/Logs/swm-macos-runner.log
```

`image ... is missing; building it` starts the build. The limit is 2700 s.
A build that fails sends `macOS runner: image build failed: ...`. Fix the cause and wait: the next pass tries again.

## 5. The TCC Allow, and how a hang shows up

Tart reads and writes `/Volumes/extra-vieille/Caches/tart`. macOS asks once whether `tart` may use that removable volume.
Until someone clicks **Allow**, a launchd job hangs with no log line. The prompt shows on the GUI session only.

- Click **Allow** on the prompt when it shows.
The grant is keyed to tart's code signature, so it should survive upgrades (not proven until a real upgrade).
- A hang shows up as a start that does not finish in its time limit. The supervisor then sends
`macOS runner: tart is hung (...). The removable-volume TCC prompt may need Allow.`
- If the prompt is gone: System Settings, Privacy and Security, Files and Folders (or Full Disk Access), and turn `tart` on. Then restart the job:

```bash
launchctl kickstart -k gui/$(id -u)/com.smartwatermelon.swm-macos-runner
```

## 6. Hold, release and full stop

**Hold.** Send new jobs to GitHub-hosted runners without touching the supervisor:

```bash
gh variable set SWM_MACOS_RUNNER --org smartwatermelon --visibility all --body macos-26
```

**Release.** Send jobs to this runner:

```bash
gh variable set SWM_MACOS_RUNNER --org smartwatermelon --visibility all --body mimolette-macos
```

Unset the variable to go back to `macos-latest`:

```bash
gh variable delete SWM_MACOS_RUNNER --org smartwatermelon
```

**Full stop.** Hold first, so no job waits for a runner that is gone. Then stop the job:

```bash
launchctl bootout gui/$(id -u)/com.smartwatermelon.swm-macos-runner
```

A running job finishes its teardown first (up to about 230 s). The plist stays, so a login or `install.sh` starts it again.
To remove it for good, delete `~/Library/LaunchAgents/com.smartwatermelon.swm-macos-runner.plist` after the bootout.
Stop the updater too (section 3a): the next time it installs new code, `install.sh` loads the supervisor again.

There is no watchdog for this runner yet. If the supervisor is down while the variable says `mimolette-macos`, jobs wait. Hold first.

## 7. Alerts and logs

All alerts go to the NOS ntfy topic and start with `macOS runner:`:

- `pf LAN block not confirmed: ...`. No VM runs until the guard's ok files confirm the block. Check `/var/log/nos-runner-pf.log`.
- `disk check failed: ...`. Free space on the Tart volume is under 60 GB, or `df` did not answer.
- `image build failed: ...`. See section 4.
- `tart is hung (...)`. See section 5.
- `N starts failed in a row; last: ...`. Three failed starts in a row. Read the log.

The log is `~/Library/Logs/swm-macos-runner.log`. Key lines:

- `runner ... handed its JIT config`: the runner may be idle or busy; it is waiting for a job or running one (`job=1`).
- `update pending; waiting ...` / `update installed or withdrawn` / `update still pending after ...`: the supervisor held a pass for the updater.
- `runner ... finished its job`: a job ended.
- `pass failed (<kind>, try N): ...`: a failed pass and why.
- `fails in a row; next pass in N s`: the supervisor is backing off.
- `sweep: removing leftover VM ...`: it deleted a VM an earlier run left. Normal after a stop.
- `stopping on SIGTERM`: someone stopped the job.

## 8. Cleanup of the spike files and the internal image copy

Andrew's OK is needed first. The spike left two things on MIMOLETTE's internal disk:

- A copy of the base image in `~/.tart` (about 33 GB). `TART_HOME` is now on the external disk, so the copy is not used.
- Test files in `~/.local/state/tart-spike/`.

List both before you remove anything:

```bash
TART_HOME="$HOME/.tart" tart list
du -sh "$HOME/.tart"
ls -la "$HOME/.local/state/tart-spike/"
```

Check that the list shows only spike images and nothing the supervisor uses. Then delete each VM or image by the name `tart list` printed:

```bash
TART_HOME="$HOME/.tart" tart delete <name>
```

Delete the spike files with `rm` on the names `ls` printed, then remove the empty folder with `rmdir`.
The supervisor's own images are in `/Volumes/extra-vieille/Caches/tart`. Do not touch them.
21 changes: 17 additions & 4 deletions docs/superpowers/plans/2026-11-17-swm-macos-tart-runner.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,20 @@ pass in quick inet proto { udp tcp } from 192.168.65.0/24 to 192.168.65.1 port 5
block drop in quick inet from 192.168.65.0/24 to <swm_private>
```

`swm-tart-v6.pf` (needs `bridge101`):
`swm-tart-v6.pf` (names `bridge101`; Task 0 proved it loads while the
interface is absent and still applies to a new `bridge101`). No IPv6 DNS
pass: Task 0 showed a port-53 pass to the bridge's link-local address does
not match, and DNS works through `192.168.65.1`, which the v4 file passes.

```text
pass in quick on bridge101 inet6 proto { udp tcp } from any to (bridge101) port 53
block drop in quick on bridge101 inet6 from any to { fc00::/7, fe80::/10 }
```

- [ ] **Step 1: Failing tests** (stub `pfctl`, `rm`, `mv`):
`tart v4 load fails → NOS ok file kept, swm ok file removed, exit 1`;
`NOS load fails → swm ok files still written when swm loads`;
`swm v4 anchor lists 2 pass + 1 block → swm ok written`;
`swm v6 lists 2 pass + 2 block (the destination list expands) → v6 ok written`;
`swm v6 lists 0 pass + 2 block (the destination list expands) → v6 ok written`;
`swm v6 load fails → v6 ok removed, v4 ok kept, warning on stderr`;
`existing NOS cases unchanged`. `install-pf` installs both new rule files
`root:wheel 0644`.
Expand Down Expand Up @@ -278,7 +280,7 @@ Andrew re-runs `sudo bash scripts/nos-runner/net/install-pf.sh` after merge

**Interfaces:**

- Produces (`config.sh`): `SWM_BASE_IMAGE` (`ghcr.io/cirruslabs/macos-tahoe-base@sha256:<digest from Task 0>`),
- Produces (`config.sh`): `SWM_BASE_IMAGE` (`ghcr.io/cirruslabs/macos-tahoe-base@sha256:65c3133a633fda8753cf1f71f2d55727792d534a2125b0032466563dcc8e58fd`),
`SWM_RUNNER_VERSION=2.338.2`, `SWM_RUNNER_SHA256`, `SWM_IMAGE`
(`swm-macos-runner-<version>-<12 hex>`, hash over `guest/` files plus the
base digest, same method as NOS `_nos_image_hash`), `SWM_CPUS=4`,
Expand Down Expand Up @@ -452,6 +454,17 @@ Andrew's OK before each step. No org variable changes in this task.
`runs-on: mimolette-macos` on `bash-tests` plus a step that runs the LAN
probes and fails if any LAN target answers. Expected: tests pass, the log
shows `job-started hook: allowed pull_request`, the probes are blocked.
Also in this step, two probes from inside the job VM:
- IPv6: run `curl -6 -m 5` and `nc -6 -w 5 -z` to MIMOLETTE's global IPv6
address on port 22 and to the router's global IPv6 address. Expected: no
answer. If any answers: block all VM inet6 on bridge101, update the
pf-guard rule count and the spec, and tell Andrew before go-live.
- Hook env: run a same-repo job whose workflow sets
`env: {JQ_BIN: /nonexistent, ALLOWED_OWNERS: nobody}`. Expected: the job
is allowed as normal (workflow env does not reach the hook). If the hook
denies, or behaves differently: harden the hook (hard-coded jq path and
owner list in the installed copy; no imported functions) before go-live,
and tell Andrew.
- [ ] **Step 4:** Andrew opens a PR from his `twistedmelonman` fork against
the draft branch. Expected: the job fails at "Set up runner" with
`DENIED ... (fork PR)`.
Expand Down
Loading
Loading