@agent-relay/acp-bridge 0.1.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 ADDED
@@ -0,0 +1,171 @@
1
+ # @agent-relay/acp-bridge
2
+
3
+ ACP (Agent Client Protocol) bridge for Agent Relay. Exposes relay agents to ACP-compatible editors like [Zed](https://zed.dev).
4
+
5
+ ## What is ACP?
6
+
7
+ The [Agent Client Protocol (ACP)](https://agentclientprotocol.com) is an open standard that enables AI agents to integrate with code editors. It's like LSP (Language Server Protocol) but for AI coding agents.
8
+
9
+ ## What does this bridge do?
10
+
11
+ This bridge allows ACP-compatible editors to communicate with Agent Relay agents:
12
+
13
+ ```
14
+ ┌─────────────────┐ ACP (stdio) ┌─────────────────┐
15
+ │ Zed Editor │ ◄────────────────► │ relay-acp │
16
+ │ (or other) │ JSON-RPC 2.0 │ (this bridge) │
17
+ └─────────────────┘ └────────┬────────┘
18
+
19
+ Relay Protocol
20
+
21
+ ┌────────▼────────┐
22
+ │ Relay Daemon │
23
+ └────────┬────────┘
24
+
25
+ ┌───────────────────────┼───────────────────────┐
26
+ │ │ │
27
+ ┌───────▼───────┐ ┌───────▼───────┐ ┌───────▼───────┐
28
+ │ Agent 1 │ │ Agent 2 │ │ Agent N │
29
+ │ (Claude Code) │ │ (Codex CLI) │ │ (any CLI) │
30
+ └───────────────┘ └───────────────┘ └───────────────┘
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ npm install @agent-relay/acp-bridge
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ### CLI
42
+
43
+ ```bash
44
+ # Start the bridge
45
+ relay-acp --name my-agent --debug
46
+
47
+ # With custom socket path
48
+ relay-acp --socket /tmp/relay/my-workspace/sockets/daemon.sock
49
+ ```
50
+
51
+ ### With Zed Editor
52
+
53
+ 1. Start the relay daemon:
54
+ ```bash
55
+ relay-daemon start
56
+ ```
57
+
58
+ 2. Start some relay agents:
59
+ ```bash
60
+ relay spawn Worker1 claude "Help with coding tasks"
61
+ ```
62
+
63
+ 3. Configure Zed to use the bridge. Add to your Zed settings:
64
+ ```json
65
+ {
66
+ "agent": {
67
+ "custom_agents": [
68
+ {
69
+ "name": "Agent Relay",
70
+ "command": "relay-acp",
71
+ "args": ["--name", "zed-bridge"]
72
+ }
73
+ ]
74
+ }
75
+ }
76
+ ```
77
+
78
+ 4. Open the Agent Panel in Zed (`Cmd+?` on macOS) and select "Agent Relay"
79
+
80
+ Or let the CLI configure Zed for you (writes `agent_servers` with the correct socket path):
81
+
82
+ ```bash
83
+ agent-relay up --zed
84
+ ```
85
+
86
+ This adds an entry similar to:
87
+
88
+ ```json
89
+ {
90
+ "agent_servers": {
91
+ "Agent Relay": {
92
+ "type": "custom",
93
+ "command": "relay-acp",
94
+ "args": ["--name", "zed-bridge", "--socket", "/path/to/project/.agent-relay/relay.sock"]
95
+ }
96
+ }
97
+ }
98
+ ```
99
+
100
+ ### Programmatic Usage
101
+
102
+ ```typescript
103
+ import { RelayACPAgent } from '@agent-relay/acp-bridge';
104
+
105
+ const agent = new RelayACPAgent({
106
+ agentName: 'my-agent',
107
+ socketPath: '/tmp/relay-daemon.sock',
108
+ debug: true,
109
+ capabilities: {
110
+ supportsSessionLoading: false,
111
+ modes: [
112
+ { slug: 'default', name: 'Default', description: 'Standard mode' },
113
+ { slug: 'review', name: 'Code Review', description: 'Focus on code review' },
114
+ ],
115
+ },
116
+ });
117
+
118
+ await agent.start();
119
+ ```
120
+
121
+ ### Relay CLI commands from the Agent Panel
122
+
123
+ The bridge intercepts basic `agent-relay` commands typed in the Zed Agent Panel, so you can manage agents without a shell:
124
+
125
+ - `agent-relay spawn Worker claude "Review the current changes"`
126
+ - `agent-relay release Worker`
127
+ - `agent-relay agents` (list connected agents)
128
+
129
+ Supported commands today: spawn/create-agent, release, agents/who. Others fall back to normal broadcast handling.
130
+ The panel shows a help block on first message; type `agent-relay help` anytime to see it again.
131
+
132
+ ## How it Works
133
+
134
+ 1. **Initialization**: When an editor connects, the bridge advertises its capabilities
135
+ 2. **Session Creation**: Each conversation creates a new session
136
+ 3. **Prompt Handling**: User prompts are broadcast to all relay agents
137
+ 4. **Response Streaming**: Agent responses are streamed back to the editor
138
+
139
+ ## Configuration
140
+
141
+ | Option | Type | Default | Description |
142
+ |--------|------|---------|-------------|
143
+ | `agentName` | string | `'relay-acp'` | Name used when connecting to relay daemon |
144
+ | `socketPath` | string | auto | Path to relay daemon socket |
145
+ | `debug` | boolean | `false` | Enable debug logging |
146
+ | `capabilities` | object | - | ACP capabilities to advertise |
147
+
148
+ Connections to the daemon go through `@agent-relay/sdk`, so socket discovery and reconnection match the rest of the Relay tooling. Provide `socketPath` to override detection when needed.
149
+
150
+ ## Environment Variables
151
+
152
+ | Variable | Description |
153
+ |----------|-------------|
154
+ | `WORKSPACE_ID` | Used to determine default socket path |
155
+
156
+ ## ACP Compatibility
157
+
158
+ This bridge implements ACP version `2025-03-26` and supports:
159
+
160
+ - Session management (new sessions)
161
+ - Prompt handling with streaming responses
162
+ - Cancellation
163
+
164
+ Not yet supported:
165
+ - Session loading/resumption
166
+ - Tool calls
167
+ - File operations via ACP (use relay agents directly)
168
+
169
+ ## License
170
+
171
+ Apache-2.0
@@ -0,0 +1,114 @@
1
+ /**
2
+ * ACP Agent Implementation
3
+ *
4
+ * Implements the ACP Agent interface to bridge relay agents to ACP clients.
5
+ */
6
+ import * as acp from '@agentclientprotocol/sdk';
7
+ import type { ACPBridgeConfig } from './types.js';
8
+ /**
9
+ * ACP Agent that bridges to Agent Relay
10
+ */
11
+ export declare class RelayACPAgent implements acp.Agent {
12
+ private readonly config;
13
+ private relayClient;
14
+ private connection;
15
+ private sessions;
16
+ private messageBuffer;
17
+ constructor(config: ACPBridgeConfig);
18
+ /**
19
+ * Start the ACP agent with stdio transport
20
+ */
21
+ start(): Promise<void>;
22
+ /**
23
+ * Stop the agent
24
+ */
25
+ stop(): Promise<void>;
26
+ /**
27
+ * Initialize the agent connection
28
+ */
29
+ initialize(_params: acp.InitializeRequest): Promise<acp.InitializeResponse>;
30
+ /**
31
+ * Authenticate with the client (no auth required for relay)
32
+ */
33
+ authenticate(_params: acp.AuthenticateRequest): Promise<acp.AuthenticateResponse>;
34
+ /**
35
+ * Create a new session
36
+ */
37
+ newSession(_params: acp.NewSessionRequest): Promise<acp.NewSessionResponse>;
38
+ /**
39
+ * Load an existing session (not supported)
40
+ */
41
+ loadSession(_params: acp.LoadSessionRequest): Promise<acp.LoadSessionResponse>;
42
+ /**
43
+ * Set session mode (optional)
44
+ */
45
+ setSessionMode(_params: acp.SetSessionModeRequest): Promise<acp.SetSessionModeResponse | void>;
46
+ /**
47
+ * Handle a prompt from the client
48
+ */
49
+ prompt(params: acp.PromptRequest): Promise<acp.PromptResponse>;
50
+ /**
51
+ * Cancel the current operation
52
+ */
53
+ cancel(params: acp.CancelNotification): Promise<void>;
54
+ /**
55
+ * Parse @mentions from a message.
56
+ * Returns { targets: string[], message: string } where targets are agent names
57
+ * and message is the text with @mentions removed.
58
+ *
59
+ * Examples:
60
+ * "@Worker hello" -> { targets: ["Worker"], message: "hello" }
61
+ * "@Worker @Reviewer review this" -> { targets: ["Worker", "Reviewer"], message: "review this" }
62
+ * "hello everyone" -> { targets: [], message: "hello everyone" }
63
+ */
64
+ private parseAtMentions;
65
+ /**
66
+ * Bridge a user prompt to relay agents and collect responses
67
+ */
68
+ private bridgeToRelay;
69
+ /**
70
+ * Handle incoming relay messages
71
+ */
72
+ private handleRelayMessage;
73
+ /**
74
+ * Handle system messages (crash notifications, etc.)
75
+ * These are displayed to all sessions regardless of processing state.
76
+ */
77
+ private handleSystemMessage;
78
+ /**
79
+ * Broadcast a message to all active sessions.
80
+ */
81
+ private broadcastToAllSessions;
82
+ /**
83
+ * Parse and handle agent-relay CLI-style commands coming from the editor.
84
+ */
85
+ private tryHandleCliCommand;
86
+ private handleSpawnCommand;
87
+ private handleReleaseCommand;
88
+ private handleListAgentsCommand;
89
+ private handleStatusCommand;
90
+ private sendTextUpdate;
91
+ private parseCliArgs;
92
+ private getHelpText;
93
+ /**
94
+ * Extract text content from ACP content blocks
95
+ */
96
+ private extractTextContent;
97
+ /**
98
+ * Convert Node.js readable stream to Web ReadableStream
99
+ */
100
+ private nodeToWebReadable;
101
+ /**
102
+ * Convert Node.js writable stream to Web WritableStream
103
+ */
104
+ private nodeToWebWritable;
105
+ /**
106
+ * Sleep utility
107
+ */
108
+ private sleep;
109
+ /**
110
+ * Debug logging
111
+ */
112
+ private debug;
113
+ }
114
+ //# sourceMappingURL=acp-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp-agent.d.ts","sourceRoot":"","sources":["../src/acp-agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,GAAG,MAAM,0BAA0B,CAAC;AAEhD,OAAO,KAAK,EACV,eAAe,EAIhB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,aAAc,YAAW,GAAG,CAAC,KAAK;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,UAAU,CAAwC;IAC1D,OAAO,CAAC,QAAQ,CAAmC;IACnD,OAAO,CAAC,aAAa,CAAqC;gBAE9C,MAAM,EAAE,eAAe;IAInC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkF5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IASjF;;OAEG;IACG,YAAY,CAAC,OAAO,EAAE,GAAG,CAAC,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IAIvF;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,iBAAiB,GAAG,OAAO,CAAC,GAAG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