agy-pi-bridge_bridge
by Ayagikei
README.md
<div align="center">
<img src="assets/logo.svg" alt="agy-pi-bridge logo" width="76" />
# agy-pi-bridge
**Structured Pi CLI agent orchestration plugin for Google Antigravity**
Typed MCP tools · Zero-polling event waiter (`agy-pi wait`) · Streaming `--mode json` liveness watchdog · Visual **Roles Studio** & **Settings** Sidecar UI
English · [简体中文](README.zh-CN.md)
</div>
---
## Why `agy-pi-bridge`?
Calling `pi -p` through ad-hoc shell commands works for one-off prompts, but creates heavy friction in daily multi-agent workflows:
- Hand-crafting long CLI flags (`--model`, `--thinking`, `--exclude-tools`, `--append-system-prompt`, temp prompt files, output redirects) every turn.
- Text-mode `pi -p` buffers output until completion, leaving `/tmp/pi-*.md` at 0 bytes while the main agent burns turns on timers, `ps`, `pgrep`, and `tail` liveness checks.
- Antigravity enforces a 180s MCP call timeout and has no built-in push callback for long-running background MCP calls.
`agy-pi-bridge` solves this with a **hybrid architecture**:
1. **Typed MCP Control Plane (`agy-pi-bridge_bridge`)**: 6 eager tools (`pi_run`, `pi_batch_run`, `pi_status`, `pi_result`, `pi_cancel`, `pi_roles`). Short tasks (`mode: "auto"`, `syncWaitSec <= 140`) complete in **1 turn**; long tasks degrade gracefully to async without killing the run.
2. **Zero-Polling Event Waiter (`agy-pi wait`)**: Pairs with Antigravity's native background `run_command` Reactive Wakeup. Exits the exact moment Pi finishes (or triggers the stall detector) and prints a concise structured summary + incremental changed files—zero timer loops.
3. **Streaming `--mode json` + Smart Liveness Watchdog**: Strictly LF-framed JSONL parser tracks turns, active tools, retries, and child process tree CPU (distinguishes `busy_child` builds/tests from truly `stalled` runs), with full `PGID` tree termination on cancel or hard timeout.
4. **Native Sidecar Panel (`sidecar://agy-pi-bridge/bridge/`)**:
- **Runs**: Live run monitor, tool execution timeline, incremental changed files, Quick Run drawer, Cancel & Send to Chat.
- **Roles Studio**: Visually create, edit, duplicate, reset, or import/export role profiles with local `pi --list-models` autocomplete—persisted live to `profiles.json`.
- **Settings**: English / 简体中文 switcher (default English, persisted across sessions), polling cadence, runtime diagnostics, maintenance actions, and one-click Agent Role Setup prompt handoff.
5. **1x Quota Friendly**: Contains no Antigravity custom/plugin `agents/*.md` definitions; only MCP, CLI, rules, skill, and sidecar.
---
## Requirements
- **Node.js >= 22** (zero external runtime dependencies; `install.sh` / `install.ps1` also auto-detect Antigravity's bundled `agy-node`)
- **[Pi CLI](https://github.com/earendil-works/pi)** installed and authenticated (`pi --list-models`)
- **Google Antigravity** (Desktop / IDE / CLI)
---
## Installation
### Option 1: Clone & install script (recommended)
```bash
git clone https://github.com/Ayagikei/agy-pi-bridge.git
cd agy-pi-bridge
# Copy install into ~/.gemini/config/plugins/agy-pi-bridge
./install.sh
# Or symlink install for local development
./install.sh --link
```
Windows PowerShell:
```powershell
git clone https://github.com/Ayagikei/agy-pi-bridge.git
cd agy-pi-bridge
.\install.ps1
# Or junction link install:
.\install.ps1 --link
```
### Option 2: Direct clone into Antigravity's plugins folder
```bash
git clone https://github.com/Ayagikei/agy-pi-bridge.git ~/.gemini/config/plugins/agy-pi-bridge
```
### Option 3: Ask Antigravity to install it for you
Send this directly in Antigravity chat:
```text
Clone https://github.com/Ayagikei/agy-pi-bridge.git and run its install.sh (or install.ps1 on Windows), then show me the link to enable the plugin and open the Pi Bridge sidecar panel.
```
After installation:
1. Open **Customizations → Installed** (or click `customization://agy-pi-bridge`) and ensure **Pi Agent Bridge** is enabled.
2. Start a **new conversation** so Antigravity loads the 6 eager MCP tools and plugin routing rules.
3. Open the sidecar panel via `sidecar://agy-pi-bridge/bridge/` (you can switch between **English** and **简体中文** anytime in the **Settings** tab).
---
## Configuring Roles (Recommended First Step)
Because every user has different Pi providers and subscriptions, **all 10 built-in roles ship with safe guardrails and an empty `model: ""`** (inheriting your Pi CLI default model) so nothing breaks out-of-the-box.
You have **three easy ways** to assign models and thinking levels to each role:
### Way 1: Let Antigravity Configure Roles Automatically (Fastest)
Copy and send this prompt to Antigravity in a new conversation (also available as a one-click button inside **Pi Bridge → Settings**):
```text
Please inspect my local Pi models using pi_roles(operation: "models") (filter by provider if needed) and configure my agy-pi-bridge roles via pi_roles(operation: "upsert") so explore, implement, review, and accept_mobile roles each use my best available models and thinking levels.
```
You can also customize the mapping explicitly, for example:
```text
Inspect my local Pi models via pi_roles(operation: "models", provider: "openai") and configure agy-pi-bridge roles using pi_roles(operation: "upsert"):
- explore_fast / explore_deep: my fast / deep reasoning model (read-only)
- implement_logic / implement_complex: my coding model (leaf, no subagents)
- review_routine / review_deep: my independent code review model
- accept_mobile: my multimodal UI validation model (keep requireDeviceSerial: true)
Show me a summary table after saving.
```
> **Tip for Agent Authors**: Always call `pi_roles(operation: "models", provider: "...")` or `query: "..."` instead of dumping hundreds of models unfiltered. All `pi_roles(operation: "upsert")` edits write atomically to `~/.gemini/antigravity/plugin_state/agy-pi-bridge/profiles.json` and take effect immediately for MCP, CLI, and the Sidecar UI.
### Way 2: Visual Roles Studio (Sidecar UI)
Open **Pi Bridge** (`sidecar://agy-pi-bridge/bridge/`) → **Roles**:
- Pick any built-in role or click **+ New Role**.
- Click **Models** to fetch your local `pi --list-models` catalog for autocomplete.
- Configure primary model, thinking level, fallback model, session mode, read-only/subagent/device-lock toggles, excluded tools, watchdog timeouts, and appended system prompt.
- Click **Save** — changes apply live with zero restart. Use **JSON** to export/import or share profiles.
### Way 3: Edit `profiles.json` Directly
Overrides are stored in `~/.gemini/antigravity/plugin_state/agy-pi-bridge/profiles.json` (array of partial or full role objects merged onto built-in defaults):
```json
[
{
"id": "explore_fast",
"model": "your-provider/your-fast-model",
"thinking": "medium"
},
{
"id": "implement_logic",
"model": "your-provider/your-coding-model",
"thinking": "low",
"systemPromptAppend": "Perform all code edits and tests directly. Do not delegate edits to subagents. Do not commit or push."
},
{
"id": "review_deep",
"model": "your-provider/your-reasoning-model",
"thinking": "high"
},
{
"id": "accept_mobile",
"model": "your-provider/your-multimodal-model",
"thinking": "high"
}
]
```
---
## Built-in Roles
| Role ID | Category | Default Guardrails | Session |
| :--- | :--- | :--- | :--- |
| `explore_fast` / `explore_broad` / `explore_deep` | Explore | Read-only (`edit,write,bash` excluded), leaf (`no subagents`) | Ephemeral |
| `implement_logic` / `implement_complex` / `implement_hard` | Implement | Direct edits, leaf (`no subagents`) | Persistent |
| `review_routine` / `review_deep` | Review | Read-only, leaf, prioritized findings contract | Ephemeral |
| `accept_mobile` | Accept | Repo read-only (`edit,write` excluded), `bash` enabled, `deviceSerial` mutex lock | Persistent |
| `accept_orchestrator` | Accept | Repo read-only (`edit,write` excluded), subagents allowed | Persistent |
---
## MCP Tools & CLI Reference
### MCP Tools (`agy-pi-bridge_bridge`)
| Tool | Purpose |
| :--- | :--- |
| `pi_run` | Run a role or resume a finished persistent run via `resumeRunId` (`mode: "auto" \| "sync" \| "async"`, `syncWaitSec <= 140`, optional `sessionId`, `whitelist`, `deviceSerial`, `model`, `thinking`) |
| `pi_batch_run` | Launch multiple independent tasks concurrently (rejects duplicate `deviceSerial` before starting; rolls back cleanly on sibling conflict) |
| `pi_status` | Live health (`healthy` / `busy_child` / `stalled`), turns, tools, elapsed time, and active subprocess info |
| `pi_result` | Bounded (`<= 7.5 KB`) output by section (`summary` / `full_excerpt` / `errors` / `timeline`) + disk artifact paths |
| `pi_cancel` | Terminate the entire process group (`-PGID`) and report incremental changed files |
| `pi_roles` | `list`, `get`, `upsert`, `delete`, `reset`, or `models` (supports `provider` & `query` filters + provider-grouped overview) |
### CLI (`bin/agy-pi.mjs`)
```bash
# Zero-polling event wait (exit 0=done, 1=failed, 124=stalled alert, 130=cancelled)
node bin/agy-pi.mjs wait <runId...> [--mode all|any] [--no-stall-exit]
# Launch, inspect, or cancel from terminal
node bin/agy-pi.mjs run --role review_routine --cwd /path/to/repo --prompt "Review git diff"
node bin/agy-pi.mjs run --resume-run <runId> --prompt "Address P1-1 and re-run tests"
node bin/agy-pi.mjs status [runId]
node bin/agy-pi.mjs cancel <runId>
# Inspect roles or filter local Pi models
node bin/agy-pi.mjs roles list
node bin/agy-pi.mjs roles models
node bin/agy-pi.mjs roles models --provider openai --query mini
```
---
## Uninstall
```bash
./uninstall.sh
# Optionally also remove saved profiles.json, settings.json, and run history:
./uninstall.sh --purge-state
```
Windows PowerShell:
```powershell
.\uninstall.ps1
# Or with state cleanup:
.\uninstall.ps1 --purge-state
```
---
## Testing
```bash
npm test
```
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues