# Studio Autonomy LaunchAgent

This directory contains the v1 launchd plist for `com.jt.studio-autonomy`. It fires `studio_autonomy_tick.sh` every 10 minutes with no `--shadow` flag, but the plist is only an artifact until JT manually installs it.

## Shadow Ritual

Run two shadow nights before enabling production dispatch:

1. Dry night: run `recoil/pipeline/tools/autonomy/studio_autonomy_tick.sh --shadow tier0` from the repo. This reads readiness and emits `autonomy.shadow_would_dispatch`, but it does not create a worktree or start the supervisor.
2. Spec-only night: run `recoil/pipeline/tools/autonomy/studio_autonomy_tick.sh --shadow tier1` from the repo. This exercises the handoff through spec generation, then stops before the build dispatch.
3. Review the morning artifact and events after each night before proceeding.

## Manual Load

After the two shadow nights pass review, install the LaunchAgent manually:

```bash
mkdir -p ~/Library/LaunchAgents ~/logs/studio-autonomy
cp recoil/pipeline/tools/autonomy/com.jt.studio-autonomy.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/com.jt.studio-autonomy.plist
```

Do not add `--shadow` to the plist for production. `RunAtLoad` is false, so launchd waits for the next 10-minute interval after load.

## Logs And Events

Launchd stdout/stderr land under `~/logs/studio-autonomy/`:

- `launchd.out.log`
- `launchd.err.log`
- `maintenance-<night_id>.md`

Autonomy events append to the shared Nightwatch ledger at `~/Dropbox/Claude_Config/maintenance/nightwatch/events.jsonl`. Local state, including the lease and claim ledger, lives under `~/.local/state/studio-autonomy/`.

## Morning Artifact

Read the rendered maintenance report for the night:

```bash
ls -t ~/logs/studio-autonomy/maintenance-*.md | head -1
sed -n '1,220p' "$(ls -t ~/logs/studio-autonomy/maintenance-*.md | head -1)"
```

For dispatch-specific history, scan the event ledger for `autonomy.*` records with the relevant `night_id`.

## Kill Switch

Stop scheduled ticks and remove the active autonomy lease:

```bash
launchctl unload ~/Library/LaunchAgents/com.jt.studio-autonomy.plist
rm -f ~/.local/state/studio-autonomy/autonomy.lease.json ~/.local/state/studio-autonomy/autonomy.lease.lock
```

The dollar gate is intentionally absent in v1 (REC-78); PR-babysitting and CI-repair are v1.1.
