---
name: amq-bridge
description: On-demand AMQ bridge for live Pi sessions. Use when a running Pi session needs to attach to another live Pi/Codex/OpenCode session without restart.
---

# AMQ Bridge

## Use

Run inside live Pi session. Type `/amq-bridge ` to see subcommand completions.

```text
/amq-bridge attach bob
/amq-bridge status
/amq-bridge send hello
/amq-bridge inbox
/amq-bridge read <msg-id>
/amq-bridge resolve <msg-id>
/amq-bridge reply <msg-id> pong
/amq-bridge detach
```

## Commands

- `/amq-bridge help` — show usage
- `/amq-bridge attach <peer> [self]` — attach local session to peer handle
- `/amq-bridge status` — show bridge state (pending count, active id, owner mode)
- `/amq-bridge discover` — discover available AMQ agents via AMQ CLI (`who`, `presence list`)
- `/amq-bridge connect` — open a TUI picker to choose an available agent and add it as a peer
- `/amq-bridge peers` — show connected peers and primary peer
- `/amq-bridge peer add <handle>` — add another peer to the running session
- `/amq-bridge peer remove <handle>` — remove peer from local roster
- `/amq-bridge peer primary <handle>` — set default send target
- `/amq-bridge send [--to <peer>] [--kind <kind>] [--priority <priority>] <body>` — send to primary or explicit peer; default kind `question` (actionable); priority `urgent|normal|low` (default `normal`)
- `/amq-bridge inbox [--all] [--limit N]` — show pending inbox envelopes (no bodies); `--all` shows read history
- `/amq-bridge read <id>` — read message body by id (marks read)
- `/amq-bridge resolve <id>` — resolve a message without replying (marks read, removes from active queue)
- `/amq-bridge reply <id> <body>` — reply to specific inbound message (message id required)
- `/amq-bridge detach` — detach current session

## Setup

Prereqs:

macOS:
```bash
brew install avivsinai/tap/amq
```

macOS/Linux:
```bash
curl -fsSL https://raw.githubusercontent.com/avivsinai/agent-message-queue/main/scripts/install.sh | bash
```

Verify:
```bash
amq --version
```

1. Publish this package to npm.
2. Install package in Pi:

```bash
pi install npm:amq-bridge
```

4. In Pi session:
   - trust project if prompted
   - run `/reload`
   - use `/amq-bridge attach bob`
   - send with `/amq-bridge send hello`
   - check inbox with `/amq-bridge inbox`
   - read a message with `/amq-bridge read <msg-id>`
   - resolve with `/amq-bridge resolve <msg-id>`
   - reply with `/amq-bridge reply <msg-id> pong`

## Notes

- Default AMQ root is `~/.amq-bridge/mail`, so sessions launched from different folders still meet on the same bus.
- Override with `PI_AMQ_ROOT` or `.pi/amq-bridge.json` when a project-local queue is required.
- Keep bridge core in repo.
- Keep runtime glue thin.
- Same core can later back Codex/OpenCode.
- Attach on demand; no restart required.
- Attached session **watches the mailbox** (`amq watch`, fsnotify) and injects new message **envelopes** into Pi chat — no polling, no bodies.
- Read/resolve/reply take explicit message ids: `read <id>`, `resolve <id>`, `reply <id> <body>`. Reply without an id lists pending envelopes instead of guessing.
- Sends default to kind `question` (actionable); pass `--priority urgent` for urgent messages (urgent wake is trust-gated — handshake-discovered senders never wake the turn).
- Attach persists identity in the Pi session (`amq-bridge-state`) so it survives reload/restart.
- The extension adds factual AMQ context before model calls: `You are <self>; peers are <peers>; root is <root>`.
- Peer messages are injected as untrusted AMQ peer data. Agents should reply to peers via AMQ tools, not normal user-facing prose.
