# Rev Webhooks for Toes

Deploy Toes apps by saving to rev.host — no manual deploy step, no rsync scripts.

## How It Works

```
rev save "fix combat"  →  rev.host  →  relay (sneaker.toes.space)  →  toes.local pulls + deploys
```

toes.local can't receive inbound connections (home NAT), so it maintains an outbound connection to a relay — same tunnel infrastructure used by `toes share`.

## Setup Flow

1. In the Toes dashboard (or `toes` CLI via SSH), enable rev webhooks for an app
2. Toes connects to the relay and gets a stable webhook URL
3. Add that URL in rev.host project settings as a webhook endpoint
4. Done — `rev save` and `rev merge` now trigger deploys

## What Toes Does on Webhook

1. Receives event from relay (repo, ref, timestamp)
2. Pulls latest from rev.host (needs a rev auth token stored in Toes env)
3. Runs `scripts.predeploy` if defined in package.json (type-check, build, etc.)
4. Runs `bun install`
5. Restarts the app

## CLI

```bash
# Enable/disable rev webhooks
toes webhook enable [name]    # Shows the relay URL to paste into rev.host
toes webhook disable [name]

# Manual trigger (pull latest and deploy now)
toes deploy [name]

# Check webhook status
toes webhook status [name]
```

## Settings UI

App settings page gets a "Rev Webhooks" section:
- Toggle to enable/disable
- Displays the relay URL (copy button)
- Field for rev.host auth token
- Last deploy timestamp + status
- "Deploy Now" button (manual trigger)

## Auth

Toes needs read access to pull from rev.host. Store a rev API token per-app (or globally):

```bash
toes env set -g REV_TOKEN rt_abc123
# or per-app
toes env set my-app REV_TOKEN rt_abc123
```

## Predeploy Scripts

Project-specific build steps go in package.json:

```json
{
  "scripts": {
    "toes": "bun run --watch index.tsx",
    "predeploy": "bunx tsc --noEmit && bun build client/main.tsx --outdir dist --minify"
  }
}
```

Toes runs `predeploy` after pulling but before restarting. If it exits non-zero, the deploy is aborted and the previous version stays running.

## Open Questions

- Should the relay URL be per-app or per-Toes-instance? (Per-instance with app routing via path seems simpler: `https://sneaker.toes.space/hooks/<instance-id>/<app-name>`)
- Webhook secret/signature verification — rev.host should sign payloads so the relay can't be spoofed
- Should `toes deploy` work without webhooks enabled? (Just pull from rev.host on demand — useful as a migration path from deploy.sh)
- Rollback: `toes rollback [name]` to revert to previous rev version?
