# A Mac as an agent host

A Mac runs Bay as the logged-in user: it reports the machine to Lore and runs
Lore's agent jobs as that user, with the tools that user installed, Xcode and
the iOS simulator included. It deploys nothing: the deploy role stays on Linux.

The usual machine is a Mac mini that never sleeps and logs in on its own.

## What a job needs on the Mac

Install these by hand, as the user Bay runs as:

- **git**, from the Xcode command line tools (`xcode-select --install`) or
  Homebrew.
- **Claude Code** (`curl -fsSL https://claude.ai/install.sh | bash`, or npm).
  There is nothing to sign in: each job signs in with the project's agent
  account, which Lore sends with the job.
- **Xcode**, from the App Store, for jobs that build an iOS app or boot the
  simulator. Open it once to accept its license.
- What your projects use: Node, Bun, Docker Desktop, `playwright-cli`.

A job finds a tool on the PATH Bay records for jobs, not on the PATH of your
shell. If Claude Code or a credential in your `~/.claude/settings.json` would
sign in on its own, remove that credential: a job fails rather than use it
instead of its agent account.

For a repository that is not on GitHub, the job uses your own git
credentials: an SSH key that works without an agent (a key with no
passphrase, or `UseKeychain yes` and `IdentityFile` in `~/.ssh/config`), or a
credential helper in `~/.gitconfig`.

## Install

Run the installer as yourself, never with `sudo`, with the host's secret from
Lore:

```bash
curl -sSL https://alepha.dev/bay/install.sh | LORE_URL=https://lore.example.com LORE_ESTATE_SECRET=<the host secret> sh
```

It installs Bay under `~/.local/share/bay`, links `~/.local/bin/bay`, records
the PATH of the shell you ran it from as the jobs' PATH, writes a
**LaunchAgent** (`~/Library/LaunchAgents/dev.alepha.bay.plist`) and starts
it, then enrols the Mac. The log is `~/.local/share/bay/data/bay.log`.

A LaunchAgent and not a LaunchDaemon: a LaunchAgent runs in your logged-in
session, which is what the iOS simulator and anything with a window need.
launchd starts it at login and again whenever it stops, which is also how an
upgrade from Lore takes effect.

In Lore, open the host and switch **Run jobs** on, then make it an **Agent
host**. The host's page shows the Mac's CPU, memory and disk, and the Claude
Code version it found.

## The jobs' PATH

A LaunchAgent starts with a minimal PATH (`/usr/bin:/bin:/usr/sbin:/sbin`),
which has no Homebrew, nvm, `~/.bun/bin` or Xcode tools. That is why the
installer records the PATH of the shell it ran in. After you install a tool
somewhere new (a Node version through nvm, a Homebrew prefix), record it
again from a shell that finds it:

```bash
bay config jobs --root ~/.local/share/bay/data --path "$PATH"
```

`bay doctor --root ~/.local/share/bay/data` shows the jobs' PATH and every
tool it finds or misses.

## Keep it running

A job only runs while the Mac is awake and logged in:

- **Automatic login**: System Settings > Users & Groups > Automatically log in
  as. FileVault prevents automatic login: turn FileVault off on this machine,
  or log in by hand after each restart.
- **No sleep**: `sudo pmset -a sleep 0`, and in System Settings > Energy, start
  up automatically after a power failure.
- **Upgrades** come from Lore: the host page offers a newer Bay, which replaces
  the binary and lets launchd start it again.

## Remove it

```bash
launchctl bootout "gui/$(id -u)" ~/Library/LaunchAgents/dev.alepha.bay.plist
rm ~/Library/LaunchAgents/dev.alepha.bay.plist
rm -rf ~/.local/share/bay ~/.local/bin/bay
```

Then delete the host in Lore.
