agent-relay-server 0.1.0 → 0.3.0

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,85 +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
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)
58
+ # terminal 1: central relay server
44
59
  bunx agent-relay-server
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 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
82
  ```bash
60
- claude plugin marketplace add edimuj/agent-relay
61
- claude plugin install agent-relay@agent-relay
83
+ bun install -g agent-relay-server
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:
97
+
98
+ ```bash
99
+ bunx -p agent-relay-server codex-relay
62
100
  ```
63
101
 
64
- Or for local development:
102
+ Non-interactive alias opt-in:
65
103
 
66
104
  ```bash
67
- claude --plugin-dir ./plugin
105
+ curl -fsSL https://raw.githubusercontent.com/edimuj/agent-relay/main/codex/install-codex.sh | bash -s -- --alias
68
106
  ```
69
107
 
70
- ### 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
+ ```
71
111
 
72
- Every Claude Code session now auto-registers as an agent. In any session:
112
+ ## What the Agent Sees
73
113
 
74
- > "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:
75
115
 
76
- > "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.0 | Plugin: 0.3.0
119
+ ```
77
120
 
78
- > "Send to cap:review please review src/db.ts"
121
+ Incoming messages arrive as monitor notifications. The agent sees them without being prompted:
79
122
 
80
- ## Message Targeting
123
+ ```
124
+ [msg:42] from backend-agent: Migration looks clean, tests pass. Ready to merge.
125
+ ```
81
126
 
82
- Messages can be addressed five ways:
127
+ ## Message Targeting
83
128
 
84
129
  | Target | Example | Behavior |
85
130
  |--------|---------|----------|
@@ -89,20 +134,75 @@ Messages can be addressed five ways:
89
134
  | Label | `"label:test writer"` | All agents with that human-set label |
90
135
  | Broadcast | `"broadcast"` | Everyone |
91
136
 
92
- ## Claim-Based Task Routing
137
+ ## Deployment
138
+
139
+ Single process, embedded SQLite, no external dependencies beyond Bun.
140
+
141
+ ```bash
142
+ bunx agent-relay-server # localhost only
143
+ PORT=8080 HOST=0.0.0.0 bunx agent-relay-server # remote access
144
+ ```
145
+
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
+ ```
151
+
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}`.
93
169
 
94
- For tasks that should be handled by exactly one agent:
170
+ ### Running as a systemd service
95
171
 
96
172
  ```bash
97
- # Send a claimable task to any agent with the "review" capability
98
- curl -X POST http://localhost:4850/api/messages \
99
- -H 'Content-Type: application/json' \
100
- -d '{"from":"user","to":"cap:review","body":"Review PR #42","claimable":true}'
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
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
101
191
  ```
102
192
 
103
- The first agent to claim it wins (atomic, 409 on conflict). Other agents never see it in their inbox.
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
+ ```
104
204
 
105
- ## API
205
+ ## API Reference
106
206
 
107
207
  Base URL: `http://localhost:4850/api`
108
208
 
@@ -131,70 +231,56 @@ Base URL: `http://localhost:4850/api`
131
231
  | `DELETE` | `/messages/:id` | Delete message |
132
232
  | `GET` | `/messages/cursor` | Latest message ID (for poller bootstrap) |
133
233
 
134
- ### Stats
234
+ ### Server-Sent Events
135
235
 
136
236
  | Method | Path | Purpose |
137
237
  |--------|------|---------|
138
- | `GET` | `/stats` | Agent counts, message counts |
139
-
140
- ## Plugin Configuration
141
-
142
- The plugin reads these environment variables:
238
+ | `GET` | `/events` | SSE stream (`?for=agentId` for filtered, omit for firehose) |
143
239
 
144
- | Variable | Default | Purpose |
145
- |----------|---------|---------|
146
- | `AGENT_RELAY_URL` | `http://localhost:4850` | Relay server URL |
147
- | `AGENT_RELAY_CAPS` | `chat` | Comma-separated agent capabilities |
240
+ Events: `message.new`, `message.claimed`, `message.deleted`, `agent.status`, `agent.removed`
148
241
 
149
- 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
150
243
 
151
- Agent IDs are deterministic: `{hostname}-{rig}-{project}-{session-hash}`.
244
+ | Method | Path | Purpose |
245
+ |--------|------|---------|
246
+ | `GET` | `/stats` | Version, agent counts, message counts |
152
247
 
153
248
  ## Architecture
154
249
 
155
250
  ```
156
251
  src/
157
- ├── index.ts # Bun.serve entry point, static files, CORS
252
+ ├── index.ts # Bun.serve entry, static files, CORS
158
253
  ├── routes.ts # HTTP router and API handlers
159
254
  ├── db.ts # SQLite schema, queries, CRUD
255
+ ├── sse.ts # Server-Sent Events
160
256
  └── types.ts # TypeScript interfaces
161
257
 
162
258
  public/
163
- └── index.html # Dashboard SPA
259
+ └── index.html # Dashboard SPA (Alpine.js + Tabler)
164
260
 
165
- plugin/
166
- ├── .claude-plugin/plugin.json # Plugin manifest
261
+ claude/ # Claude Code plugin
262
+ ├── .claude-plugin/plugin.json
263
+ ├── monitors/monitors.json # Auto-start inbox monitor
167
264
  └── hooks/
168
- ├── hooks.json # SessionStart + SessionEnd events
169
- ├── session-start.sh # Register agent, inject messaging context
170
- ├── session-end.sh # Mark agent offline
171
- └── poll-inbox.sh # Inbox poller for Monitor
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
172
273
  ```
173
274
 
174
- ## Deployment
175
-
176
- 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
177
276
 
178
277
  ```bash
179
- # one-liner
180
- bunx agent-relay-server
181
-
182
- # with options
183
- PORT=8080 HOST=0.0.0.0 bunx agent-relay-server
184
-
185
- # or install globally
186
- bun install -g agent-relay-server
187
- 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
188
282
  ```
189
283
 
190
- | Variable | Default | Purpose |
191
- |----------|---------|---------|
192
- | `PORT` | `4850` | Server port |
193
- | `HOST` | `127.0.0.1` | Bind address (`0.0.0.0` for remote access) |
194
- | `DB_PATH` | `agent-relay.db` | SQLite database path |
195
- | `RETENTION_DAYS` | `30` | Auto-prune messages older than this |
196
- | `AGENT_RELAY_LOG_REQUESTS` | `0` | Set to `1` to log all API requests |
197
-
198
284
  ## License
199
285
 
200
286
  MIT