# pi-roam-code

[Pi](https://pi.dev) extension that wires [roam](https://roam-code.com) compile/verify hooks into every agent turn.

- **Compile** — before each turn, runs `roam compile` on your prompt and injects a pre-computed plan (procedure, files, facts) into the model context. Cuts navigation turns by ~80%.
- **Verify** — after each agent turn, runs `roam verify --auto --diff-only` on changed lines. If findings surface, queues an auto-fix follow-up message so the agent resolves them before moving on.

Everything is **fail-open**: a broken roam install never blocks a turn. If roam is missing, you get one warning notification at session start and the extension silently skips.

## Prerequisites

- [roam](https://roam-code.com) CLI installed and on `PATH`
- In your repo: `roam init` (one-time indexing)

## Install

```bash
pi install npm:pi-roam-code
```

Or add to your project's `.pi/settings.json`:

```json
{
  "packages": ["npm:pi-roam-code"]
}
```

## How it works

1. **Before the agent starts** (`before_agent_start`): classifies your prompt, runs `roam --json compile`, and injects the envelope as an invisible context message.
2. **After the agent finishes** (`agent_end`): runs `roam --json verify --auto --diff-only`. If violations exist, sends `[roam-verify-auto-fix] ...` as a `followUp` message — delivered only after the agent is fully idle, preventing loops.

## Configure

Environment variables (optional):

| Variable | Effect |
|----------|--------|
| `ROAM_COMPILE_TIMEOUT` | Compile timeout in ms (default: 6000) |
| `ROAM_VERIFY_TIMEOUT` | Verify timeout in ms (default: 90000) |

## License

MIT
