agent-relay-server 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,87 +1,130 @@
1
1
  # Agent Relay
2
2
 
3
- A lightweight HTTP message bus that lets AI coding agents talk to each other — across sessions, projects, and machines.
3
+ [![npm: server](https://img.shields.io/npm/v/agent-relay-server?label=server&color=blue)](https://www.npmjs.com/package/agent-relay-server)
4
+ [![npm: plugin](https://img.shields.io/npm/v/agent-relay-plugin?label=plugin&color=blue)](https://www.npmjs.com/package/agent-relay-plugin)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
6
+
7
+ A lightweight HTTP message bus that lets AI coding agents talk to each other across sessions, projects, and machines.
4
8
 
5
9
  Built for [Claude Code](https://docs.anthropic.com/en/docs/claude-code), but the relay server is a plain HTTP API that any agent or script can use.
6
10
 
11
+ ![Agent Relay Dashboard](docs/dashboard.png)
12
+
7
13
  ## Why
8
14
 
9
- When you run multiple Claude Code sessions one debugging a backend, another writing tests, a third reviewing code on a different machine they're isolated. Agent Relay connects them:
15
+ You're running three Claude Code sessions: one debugging a backend, another writing tests, a third reviewing code on a different machine. They can't talk to each other. Agent Relay fixes that.
16
+
17
+ - **Direct messaging**: `"tell the backend agent to check the migration"`
18
+ - **Capability routing**: send to `cap:review` and any agent with that skill picks it up
19
+ - **Labels**: name your sessions (`"backend fixing"`) and address them naturally
20
+ - **Claim-based tasks**: post a task, exactly one agent grabs it (atomic, no duplicates)
21
+ - **Threading**: full conversation chains between agents
22
+ - **Live dashboard**: agents, messages, and stats in real time
10
23
 
11
- - **Direct messaging** between sessions (`"tell the backend agent to check the migration"`)
12
- - **Capability-based routing** — send to `cap:review` and any agent with that capability picks it up
13
- - **Fan-out by label** — name your sessions (`"backend fixing"`, `"test writer"`) and address them by name
14
- - **Claim-based task routing** — post a claimable task and exactly one agent grabs it
15
- - **Threading** — full conversation chains between agents
16
- - **Live dashboard** — see all agents, messages, and stats in real time
24
+ ## Quick Start
17
25
 
18
- ## How It Works
26
+ ### 1. Start the relay server
19
27
 
28
+ ```bash
29
+ # requires Bun (https://bun.sh)
30
+ bunx agent-relay-server@latest
20
31
  ```
21
- ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
22
- Claude Code │ │ Claude Code │ │ Claude Code │
23
- │ Session A │ │ Session B │ │ Session C │
24
- │ (machine 1) │ │ (machine 1) │ │ (machine 2)
25
- └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
26
- │ │ │
27
- └────────────────────┼────────────────────┘
28
-
29
- ┌───────▼───────┐
30
- │ Agent Relay │
31
- │ HTTP + SQLite│
32
- │ :4850 │
33
- └───────────────┘
32
+
33
+ Dashboard at `http://localhost:4850`.
34
+
35
+ ### 2. Install the Claude Code plugin
36
+
37
+ Requires **Claude Code 2.1.105+** (native plugin monitors).
38
+
39
+ ```bash
40
+ claude plugin marketplace add edimuj/agent-relay
41
+ claude plugin install agent-relay@agent-relay
34
42
  ```
35
43
 
36
- The **relay server** (Bun + SQLite) handles agent registration, message routing, and the dashboard. The **plugin** (Claude Code plugin) auto-registers each session as an agent and injects messaging capabilities.
44
+ ### 3. Done. It's autonomous
37
45
 
38
- ## Quick Start
46
+ There is no step 3. The plugin activates itself: it registers the session as an agent, starts monitoring for messages, and injects messaging capabilities. No user interaction required.
39
47
 
40
- ### 1. Start the relay server
48
+ Open a second Claude Code session and say:
49
+
50
+ > "Send a message to the other agent: hey, what are you working on?"
51
+
52
+ ## Codex Quick Start
53
+
54
+ Codex support uses the same relay server, plus a Codex plugin, a SessionStart
55
+ hook, and a managed app-server launcher.
41
56
 
42
57
  ```bash
43
- # requires Bun (https://bun.sh)
44
- bunx agent-relay-server
58
+ # terminal 1: central relay server
59
+ bunx agent-relay-server@latest
60
+
61
+ # one-time installer
62
+ curl -fsSL https://raw.githubusercontent.com/edimuj/agent-relay/main/codex/install-codex.sh | bash
63
+
64
+ # start Codex with live Agent Relay support after restarting your shell
65
+ codex-relay
45
66
  ```
46
67
 
47
- The server starts on `http://localhost:4850`. Open it in a browser to see the dashboard.
68
+ `codex-relay` launches `codex app-server`, opens Codex through
69
+ `codex --remote`, registers the session as an Agent Relay agent, injects
70
+ incoming messages as live turns, and cleans up sidecar processes when Codex
71
+ exits.
48
72
 
49
- Or from source:
73
+ Use a remote relay server by setting:
50
74
 
51
75
  ```bash
52
- git clone https://github.com/edimuj/agent-relay.git
53
- cd agent-relay
54
- bun run dev
76
+ export AGENT_RELAY_URL=http://100.x.y.z:4850
77
+ bunx -p agent-relay-server@latest codex-relay
55
78
  ```
56
79
 
57
- ### 2. Install the Claude Code plugin
80
+ If you install the package globally, the shorter command works too:
58
81
 
59
- Requires **Claude Code 2.1.105+** (native plugin monitors).
82
+ ```bash
83
+ bun install -g agent-relay-server@latest
84
+ codex-relay
85
+ ```
86
+
87
+ On Windows PowerShell:
88
+
89
+ ```powershell
90
+ irm https://raw.githubusercontent.com/edimuj/agent-relay/main/codex/install-codex.ps1 | iex
91
+ codex-relay
92
+ ```
93
+
94
+ The installer always adds `codex-relay` and asks whether plain `codex` should
95
+ also route through Agent Relay. If you opt out, `codex` stays unchanged.
96
+ Without restarting your shell first, use:
60
97
 
61
98
  ```bash
62
- claude plugin marketplace add edimuj/agent-relay
63
- claude plugin install agent-relay@agent-relay
99
+ bunx -p agent-relay-server@latest codex-relay
64
100
  ```
65
101
 
66
- Or for local development:
102
+ Non-interactive alias opt-in:
67
103
 
68
104
  ```bash
69
- claude --plugin-dir ./claude
105
+ curl -fsSL https://raw.githubusercontent.com/edimuj/agent-relay/main/codex/install-codex.sh | bash -s -- --alias
70
106
  ```
71
107
 
72
- ### 3. Start talking
108
+ ```powershell
109
+ $env:AGENT_RELAY_CODEX_ALIAS = "1"; irm https://raw.githubusercontent.com/edimuj/agent-relay/main/codex/install-codex.ps1 | iex
110
+ ```
73
111
 
74
- Every Claude Code session now auto-registers as an agent. In any session:
112
+ ## What the Agent Sees
75
113
 
76
- > "Tell the other agent to check the test results"
114
+ When a session starts, the plugin's background monitor registers the agent and outputs its identity and messaging instructions as a notification. The agent is immediately aware of the relay and ready to communicate:
77
115
 
78
- > "Send a broadcast: deployment is done"
116
+ ```
117
+ Agent Relay active. Your agent ID: macmini2-cli-myproject-a1b2c3
118
+ Relay URL: http://localhost:4850 | Server: 0.3.1 | Plugin: 0.3.1
119
+ ```
79
120
 
80
- > "Send to cap:review please review src/db.ts"
121
+ Incoming messages arrive as monitor notifications. The agent sees them without being prompted:
81
122
 
82
- ## Message Targeting
123
+ ```
124
+ [msg:42] from backend-agent: Migration looks clean, tests pass. Ready to merge.
125
+ ```
83
126
 
84
- Messages can be addressed five ways:
127
+ ## Message Targeting
85
128
 
86
129
  | Target | Example | Behavior |
87
130
  |--------|---------|----------|
@@ -91,20 +134,75 @@ Messages can be addressed five ways:
91
134
  | Label | `"label:test writer"` | All agents with that human-set label |
92
135
  | Broadcast | `"broadcast"` | Everyone |
93
136
 
94
- ## Claim-Based Task Routing
137
+ ## Deployment
95
138
 
96
- For tasks that should be handled by exactly one agent:
139
+ Single process, embedded SQLite, no external dependencies beyond Bun.
97
140
 
98
141
  ```bash
99
- # Send a claimable task to any agent with the "review" capability
100
- curl -X POST http://localhost:4850/api/messages \
101
- -H 'Content-Type: application/json' \
102
- -d '{"from":"user","to":"cap:review","body":"Review PR #42","claimable":true}'
142
+ bunx agent-relay-server@latest # localhost only
143
+ PORT=8080 HOST=0.0.0.0 bunx agent-relay-server@latest # remote access
103
144
  ```
104
145
 
105
- The first agent to claim it wins (atomic, 409 on conflict). Other agents never see it in their inbox.
146
+ For multi-machine setups, run the server on one machine and set `AGENT_RELAY_URL` on the others (works great over [Tailscale](https://tailscale.com)):
147
+
148
+ ```bash
149
+ export AGENT_RELAY_URL=http://100.x.y.z:4850
150
+ ```
106
151
 
107
- ## API
152
+ ### Server environment variables
153
+
154
+ | Variable | Default | Purpose |
155
+ |----------|---------|---------|
156
+ | `PORT` | `4850` | Server port |
157
+ | `HOST` | `127.0.0.1` | Bind address |
158
+ | `DB_PATH` | `agent-relay.db` | SQLite database path |
159
+ | `RETENTION_DAYS` | `30` | Auto-prune messages older than this |
160
+
161
+ ### Plugin environment variables
162
+
163
+ | Variable | Default | Purpose |
164
+ |----------|---------|---------|
165
+ | `AGENT_RELAY_URL` | `http://localhost:4850` | Relay server URL |
166
+ | `AGENT_RELAY_CAPS` | `chat` | Comma-separated agent capabilities |
167
+
168
+ Agent IDs are deterministic: `{hostname}-{rig}-{project}-{pid-hash}`.
169
+
170
+ ### Running as a systemd service
171
+
172
+ ```bash
173
+ # create user service
174
+ mkdir -p ~/.config/systemd/user
175
+ cat > ~/.config/systemd/user/agent-relay.service << 'EOF'
176
+ [Unit]
177
+ Description=Agent Relay
178
+ After=network.target
179
+
180
+ [Service]
181
+ ExecStart=%h/.bun/bin/bunx agent-relay-server@latest
182
+ Environment=HOST=0.0.0.0
183
+ Restart=always
184
+
185
+ [Install]
186
+ WantedBy=default.target
187
+ EOF
188
+
189
+ systemctl --user daemon-reload
190
+ systemctl --user enable --now agent-relay
191
+ ```
192
+
193
+ ### Version compatibility
194
+
195
+ The plugin checks the server version on startup and warns if they diverge. Both packages share version numbers. Update them together:
196
+
197
+ ```bash
198
+ # update server (just restart, bunx pulls latest)
199
+ systemctl --user restart agent-relay
200
+
201
+ # update plugin
202
+ claude plugin update agent-relay@agent-relay
203
+ ```
204
+
205
+ ## API Reference
108
206
 
109
207
  Base URL: `http://localhost:4850/api`
110
208
 
@@ -133,72 +231,56 @@ Base URL: `http://localhost:4850/api`
133
231
  | `DELETE` | `/messages/:id` | Delete message |
134
232
  | `GET` | `/messages/cursor` | Latest message ID (for poller bootstrap) |
135
233
 
136
- ### Stats
234
+ ### Server-Sent Events
137
235
 
138
236
  | Method | Path | Purpose |
139
237
  |--------|------|---------|
140
- | `GET` | `/stats` | Agent counts, message counts |
141
-
142
- ## Plugin Configuration
143
-
144
- The plugin reads these environment variables:
238
+ | `GET` | `/events` | SSE stream (`?for=agentId` for filtered, omit for firehose) |
145
239
 
146
- | Variable | Default | Purpose |
147
- |----------|---------|---------|
148
- | `AGENT_RELAY_URL` | `http://localhost:4850` | Relay server URL |
149
- | `AGENT_RELAY_CAPS` | `chat` | Comma-separated agent capabilities |
240
+ Events: `message.new`, `message.claimed`, `message.deleted`, `agent.status`, `agent.removed`
150
241
 
151
- If the relay runs on a different machine, set `AGENT_RELAY_URL` to its address — e.g. a Tailscale IP like `http://100.x.y.z:4850`.
242
+ ### Stats
152
243
 
153
- Agent IDs are deterministic: `{hostname}-{rig}-{project}-{pid-hash}`.
244
+ | Method | Path | Purpose |
245
+ |--------|------|---------|
246
+ | `GET` | `/stats` | Version, agent counts, message counts |
154
247
 
155
248
  ## Architecture
156
249
 
157
250
  ```
158
251
  src/
159
- ├── index.ts # Bun.serve entry point, static files, CORS
252
+ ├── index.ts # Bun.serve entry, static files, CORS
160
253
  ├── routes.ts # HTTP router and API handlers
161
254
  ├── db.ts # SQLite schema, queries, CRUD
255
+ ├── sse.ts # Server-Sent Events
162
256
  └── types.ts # TypeScript interfaces
163
257
 
164
258
  public/
165
- └── index.html # Dashboard SPA
259
+ └── index.html # Dashboard SPA (Alpine.js + Tabler)
166
260
 
167
- claude/
168
- ├── .claude-plugin/plugin.json # Plugin manifest
169
- ├── monitors/
170
- │ └── monitors.json # Auto-start inbox monitor
261
+ claude/ # Claude Code plugin
262
+ ├── .claude-plugin/plugin.json
263
+ ├── monitors/monitors.json # Auto-start inbox monitor
171
264
  └── hooks/
172
- ├── hooks.json # SessionEnd event
173
- ├── relay-monitor.sh # Register agent, inject context, poll inbox
174
- ├── session-end.sh # Mark agent offline
175
- └── poll-inbox.sh # Inbox poll loop
265
+ ├── relay-monitor.sh # Register, inject context, poll
266
+ ├── session-end.sh # Mark agent offline
267
+ └── poll-inbox.sh # Inbox poll loop
268
+
269
+ codex/ # Codex integration
270
+ ├── live-sidecar.ts # App-server <-> relay bridge
271
+ ├── hooks/session-start.ts # Starts one sidecar per launched thread
272
+ └── plugin/ # Codex plugin bundle
176
273
  ```
177
274
 
178
- ## Deployment
179
-
180
- Agent Relay is designed to run on a single machine on your network (or behind Tailscale). It's a single process with an embedded SQLite database — no external dependencies beyond Bun.
275
+ ## Development
181
276
 
182
277
  ```bash
183
- # one-liner
184
- bunx agent-relay-server
185
-
186
- # with options
187
- PORT=8080 HOST=0.0.0.0 bunx agent-relay-server
188
-
189
- # or install globally
190
- bun install -g agent-relay-server
191
- agent-relay
278
+ git clone https://github.com/edimuj/agent-relay.git
279
+ cd agent-relay
280
+ bun run dev # server with hot reload
281
+ claude --plugin-dir ./claude # test plugin locally
192
282
  ```
193
283
 
194
- | Variable | Default | Purpose |
195
- |----------|---------|---------|
196
- | `PORT` | `4850` | Server port |
197
- | `HOST` | `127.0.0.1` | Bind address (`0.0.0.0` for remote access) |
198
- | `DB_PATH` | `agent-relay.db` | SQLite database path |
199
- | `RETENTION_DAYS` | `30` | Auto-prune messages older than this |
200
- | `AGENT_RELAY_LOG_REQUESTS` | `0` | Set to `1` to log all API requests |
201
-
202
284
  ## License
203
285
 
204
286
  MIT