proxy-acpx-x 1.0.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 +231 -0
- package/dist/adapter.d.ts +13 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +305 -0
- package/dist/adapter.js.map +1 -0
- package/dist/protocol.d.ts +89 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +126 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# proxy-acpx-x
|
|
2
|
+
|
|
3
|
+
ACP ↔ Claude Code `stream-json` adapter. Routes OpenClaw/acpx traffic through the **Claude Code CLI**, enabling subscription-based authentication instead of requiring a separate API key.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
Before (API key required):
|
|
9
|
+
OpenClaw → acpx → @zed/claude-agent-acp → Anthropic API (API key)
|
|
10
|
+
|
|
11
|
+
After (subscription auth via CLI):
|
|
12
|
+
OpenClaw → acpx → proxy-acpx-x → claude CLI (stream-json) → Anthropic API (subscription OK)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The adapter is a thin NDJSON translator (~300 lines) that sits between acpx and the Claude Code CLI. Both protocols use stdin/stdout NDJSON, so only field-name mapping is needed.
|
|
16
|
+
|
|
17
|
+
### Protocol Mapping
|
|
18
|
+
|
|
19
|
+
**Input: ACP → Claude Code CLI stdin** (`--input-format stream-json`)
|
|
20
|
+
|
|
21
|
+
| ACP (from acpx) | Claude Code stream-json stdin |
|
|
22
|
+
| ----------------------------------------- | ------------------------------------------------------------------- |
|
|
23
|
+
| `session/prompt { prompt: [{text:"…"}] }` | `{"type":"user","message":{"role":"user","content":"…"}}` |
|
|
24
|
+
| `session/cancel` | SIGTERM to child process |
|
|
25
|
+
| `session/close` | Close stdin + SIGTERM |
|
|
26
|
+
|
|
27
|
+
**Output: Claude Code CLI stdout → ACP** (`--output-format stream-json`)
|
|
28
|
+
|
|
29
|
+
| Claude Code stream-json stdout | ACP (to acpx) |
|
|
30
|
+
| ------------------------------------------------------------------------------- | -------------------------------- |
|
|
31
|
+
| `stream_event { event: { type: "content_block_delta", delta: { text } } }` | `session/update { agent_message_chunk }` |
|
|
32
|
+
| `stream_event { event: { type: "content_block_start", content_block: { type: "tool_use" } } }` | (tracked internally) |
|
|
33
|
+
| `stream_event { event: { type: "content_block_stop" } }` (after tool_use) | `session/update { tool_call }` |
|
|
34
|
+
| `{ type: "result", subtype: "success" }` | prompt response (stopReason: end_turn) |
|
|
35
|
+
| `{ type: "system", subtype: "api_retry" }` | logged to stderr |
|
|
36
|
+
|
|
37
|
+
### CLI Flags Used
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
claude -p \
|
|
41
|
+
--input-format stream-json \
|
|
42
|
+
--output-format stream-json \
|
|
43
|
+
--verbose \
|
|
44
|
+
--include-partial-messages \
|
|
45
|
+
--bare \
|
|
46
|
+
--permission-mode bypassPermissions
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Flag | Purpose |
|
|
50
|
+
| ---- | ------- |
|
|
51
|
+
| `-p` | Non-interactive (print) mode |
|
|
52
|
+
| `--input-format stream-json` | Accept NDJSON messages on stdin |
|
|
53
|
+
| `--output-format stream-json` | Emit NDJSON streaming events on stdout |
|
|
54
|
+
| `--verbose` | Full turn-by-turn output |
|
|
55
|
+
| `--include-partial-messages` | Emit `stream_event` with real-time text/tool deltas |
|
|
56
|
+
| `--bare` | Skip hooks, plugins, MCP, CLAUDE.md for fast startup |
|
|
57
|
+
| `--permission-mode bypassPermissions` | Auto-approve all tools (required for non-interactive ACP) |
|
|
58
|
+
|
|
59
|
+
Reference: [Claude Code headless docs](https://code.claude.com/docs/en/headless)
|
|
60
|
+
|
|
61
|
+
## Prerequisites
|
|
62
|
+
|
|
63
|
+
- **Node.js** >= 18
|
|
64
|
+
- **Claude Code CLI** installed and authenticated (`claude` command in PATH)
|
|
65
|
+
- **OpenClaw** with acpx plugin
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# From npm (once published)
|
|
71
|
+
npm install -g proxy-acpx-x
|
|
72
|
+
|
|
73
|
+
# Or from source
|
|
74
|
+
git clone https://github.com/clonn/proxy-acpx-x.git
|
|
75
|
+
cd proxy-acpx-x
|
|
76
|
+
npm install
|
|
77
|
+
npm run build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Setup with OpenClaw / acpx
|
|
81
|
+
|
|
82
|
+
### Option 1: Register as an acpx agent
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# If installed globally
|
|
86
|
+
acpx config set agents.claude-native.command "proxy-acpx-x"
|
|
87
|
+
|
|
88
|
+
# If running from source
|
|
89
|
+
acpx config set agents.claude-native.command "node /path/to/proxy-acpx-x/dist/adapter.js"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then edit `~/.openclaw/config.json`:
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"acp": {
|
|
97
|
+
"enabled": true,
|
|
98
|
+
"dispatch": { "enabled": true },
|
|
99
|
+
"backend": "acpx",
|
|
100
|
+
"defaultAgent": "claude-native"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Option 2: Direct execution (testing)
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Pipe ACP messages manually
|
|
109
|
+
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | node dist/adapter.js
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Usage
|
|
113
|
+
|
|
114
|
+
Once configured, OpenClaw routes requests through the adapter automatically:
|
|
115
|
+
|
|
116
|
+
**Direct conversation:**
|
|
117
|
+
```
|
|
118
|
+
You: "Refactor this function using Claude Code"
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Manual spawn:**
|
|
122
|
+
```
|
|
123
|
+
/acp spawn claude-native --mode persistent --thread auto
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Common commands:**
|
|
127
|
+
|
|
128
|
+
| Command | Description |
|
|
129
|
+
| ------------------ | ------------------------- |
|
|
130
|
+
| `/acp status` | Check current session |
|
|
131
|
+
| `/acp steer <msg>` | Send follow-up instruction|
|
|
132
|
+
| `/acp cancel` | Cancel current turn |
|
|
133
|
+
| `/acp close` | Close session |
|
|
134
|
+
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
npm install # Install dependencies
|
|
139
|
+
npm run build # Compile TypeScript → dist/
|
|
140
|
+
npm run dev # Run directly with ts-node
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Testing
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm test # Run unit tests (vitest, 24 tests)
|
|
147
|
+
npm run test:watch # Run tests in watch mode
|
|
148
|
+
npm run test:smoke # Run E2E smoke tests against built adapter
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Unit tests** (`test/protocol.test.ts`) — test all pure protocol translation functions:
|
|
152
|
+
- ACP ↔ stream-json message building
|
|
153
|
+
- Tool classification, input extraction, summarization
|
|
154
|
+
- CLI argument construction
|
|
155
|
+
|
|
156
|
+
**Smoke tests** (`test/smoke.sh`) — test the actual adapter process:
|
|
157
|
+
- ACP `initialize` handshake
|
|
158
|
+
- `session/create` with custom session ID
|
|
159
|
+
- Empty prompt returns `end_turn` immediately
|
|
160
|
+
- Unknown method returns JSON-RPC error
|
|
161
|
+
- `session/close` graceful shutdown
|
|
162
|
+
|
|
163
|
+
### Manual E2E test (with real Claude CLI)
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# 1. Build
|
|
167
|
+
npm run build
|
|
168
|
+
|
|
169
|
+
# 2. Start the adapter
|
|
170
|
+
node dist/adapter.js
|
|
171
|
+
|
|
172
|
+
# 3. In the same terminal, paste these lines one by one:
|
|
173
|
+
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}
|
|
174
|
+
{"jsonrpc":"2.0","id":2,"method":"session/prompt","params":{"prompt":[{"type":"text","text":"What is 2+2? Reply with just the number."}]}}
|
|
175
|
+
|
|
176
|
+
# 4. Watch stdout for ACP responses and stderr for debug logs
|
|
177
|
+
# 5. Ctrl+C to stop
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## How It Works
|
|
181
|
+
|
|
182
|
+
The adapter has 4 parts:
|
|
183
|
+
|
|
184
|
+
### Part 1: CLI Spawn (~20 lines)
|
|
185
|
+
Starts `claude` as a child process with stream-json I/O flags. Uses `--bare` for fast startup and `--include-partial-messages` for real-time streaming events.
|
|
186
|
+
|
|
187
|
+
### Part 2: ACP → stream-json (~60 lines)
|
|
188
|
+
Reads NDJSON from stdin (ACP messages from acpx). Translates:
|
|
189
|
+
- `initialize` → spawn Claude CLI, return capabilities
|
|
190
|
+
- `session/prompt` → `{"type":"user","message":{"role":"user","content":"…"}}` to Claude's stdin
|
|
191
|
+
- `session/cancel` → SIGTERM the Claude process
|
|
192
|
+
- `session/close` → graceful stdin close + SIGTERM
|
|
193
|
+
|
|
194
|
+
### Part 3: stream-json → ACP (~120 lines)
|
|
195
|
+
Reads Claude's stdout stream events and translates:
|
|
196
|
+
- `stream_event` with `content_block_delta` (`text_delta`) → `session/update { agent_message_chunk }`
|
|
197
|
+
- `stream_event` with `content_block_start` (`tool_use`) → track tool name/id
|
|
198
|
+
- `stream_event` with `content_block_delta` (`input_json_delta`) → accumulate tool input
|
|
199
|
+
- `stream_event` with `content_block_stop` → emit `session/update { tool_call }` with complete input
|
|
200
|
+
- `result` → ACP prompt response with stop reason and usage stats
|
|
201
|
+
- `system` (`api_retry`) → logged to stderr
|
|
202
|
+
|
|
203
|
+
### Part 4: Utilities (~30 lines)
|
|
204
|
+
JSON emitters (`emitAcp`, `emitAcpResponse`, `emitAcpNotification`), prompt text extraction, input summarization, tool classification.
|
|
205
|
+
|
|
206
|
+
## Permission Handling
|
|
207
|
+
|
|
208
|
+
This adapter uses **Method A: pre-approved permissions** (`--permission-mode bypassPermissions`). ACP sessions are non-interactive, so all file writes and command executions are auto-approved.
|
|
209
|
+
|
|
210
|
+
For dynamic permission control (Method B), integrate the [Claude Agent SDK](https://platform.claude.com/docs/en/agent-sdk/overview)'s `permissionHandler` callback — see [concept.md](./concept.md) for details.
|
|
211
|
+
|
|
212
|
+
## Troubleshooting
|
|
213
|
+
|
|
214
|
+
**"Failed to spawn claude"** — Ensure `claude` CLI is in your PATH. Run `which claude` to verify.
|
|
215
|
+
|
|
216
|
+
**No output from Claude** — Check stderr logs (lines prefixed `[proxy-acpx-x]`). The adapter logs all lifecycle events to stderr.
|
|
217
|
+
|
|
218
|
+
**Permission errors** — The adapter runs with `bypassPermissions`. For finer control, modify the spawn args to use `--allowedTools` instead.
|
|
219
|
+
|
|
220
|
+
**Slow startup** — The adapter uses `--bare` to skip hooks/plugins/MCP discovery. If you need project context (CLAUDE.md, etc.), remove `--bare` from the spawn args.
|
|
221
|
+
|
|
222
|
+
## References
|
|
223
|
+
|
|
224
|
+
- [Claude Code headless mode](https://code.claude.com/docs/en/headless)
|
|
225
|
+
- [Agent SDK streaming output](https://platform.claude.com/docs/en/agent-sdk/streaming-output)
|
|
226
|
+
- [Agent SDK streaming input](https://platform.claude.com/docs/en/agent-sdk/streaming-vs-single-mode)
|
|
227
|
+
- [Claude Code CLI reference](https://code.claude.com/docs/en/cli-reference)
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* proxy-acpx-x: ACP ↔ Claude Code stream-json adapter
|
|
4
|
+
*
|
|
5
|
+
* Translates between ACP protocol (stdin/stdout NDJSON from acpx) and
|
|
6
|
+
* Claude Code CLI's --input-format stream-json / --output-format stream-json.
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* OpenClaw → acpx → [this adapter] → claude CLI (stream-json) → Anthropic API
|
|
10
|
+
* (subscription auth OK)
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* proxy-acpx-x: ACP ↔ Claude Code stream-json adapter
|
|
5
|
+
*
|
|
6
|
+
* Translates between ACP protocol (stdin/stdout NDJSON from acpx) and
|
|
7
|
+
* Claude Code CLI's --input-format stream-json / --output-format stream-json.
|
|
8
|
+
*
|
|
9
|
+
* Architecture:
|
|
10
|
+
* OpenClaw → acpx → [this adapter] → claude CLI (stream-json) → Anthropic API
|
|
11
|
+
* (subscription auth OK)
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const child_process_1 = require("child_process");
|
|
15
|
+
const readline_1 = require("readline");
|
|
16
|
+
const protocol_1 = require("./protocol");
|
|
17
|
+
// ─── State ───────────────────────────────────────────────────────────────────
|
|
18
|
+
let claudeProcess = null;
|
|
19
|
+
let currentRequestId = undefined;
|
|
20
|
+
let sessionId = null;
|
|
21
|
+
let accumulatedUsage = { inputTokens: 0, outputTokens: 0 };
|
|
22
|
+
// Tool streaming state
|
|
23
|
+
let currentToolName = null;
|
|
24
|
+
let currentToolId = null;
|
|
25
|
+
let currentToolInput = "";
|
|
26
|
+
// ─── Output helpers ──────────────────────────────────────────────────────────
|
|
27
|
+
function emit(obj) {
|
|
28
|
+
process.stdout.write(JSON.stringify(obj) + "\n");
|
|
29
|
+
}
|
|
30
|
+
function log(msg) {
|
|
31
|
+
process.stderr.write(`[proxy-acpx-x] ${msg}\n`);
|
|
32
|
+
}
|
|
33
|
+
// ─── Part 1: Spawn Claude Code CLI ───────────────────────────────────────────
|
|
34
|
+
function spawnClaude() {
|
|
35
|
+
const args = (0, protocol_1.buildClaudeArgs)();
|
|
36
|
+
log(`Spawning: claude ${args.join(" ")}`);
|
|
37
|
+
const proc = (0, child_process_1.spawn)("claude", args, {
|
|
38
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
39
|
+
env: { ...process.env },
|
|
40
|
+
});
|
|
41
|
+
proc.on("error", (err) => {
|
|
42
|
+
log(`Failed to spawn claude: ${err.message}`);
|
|
43
|
+
if (currentRequestId !== undefined) {
|
|
44
|
+
emit((0, protocol_1.buildAcpResponse)(currentRequestId, {
|
|
45
|
+
stopReason: "error",
|
|
46
|
+
error: `Failed to spawn claude CLI: ${err.message}`,
|
|
47
|
+
}));
|
|
48
|
+
currentRequestId = undefined;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
proc.on("exit", (code, signal) => {
|
|
52
|
+
log(`Claude exited (code=${code}, signal=${signal})`);
|
|
53
|
+
claudeProcess = null;
|
|
54
|
+
if (currentRequestId !== undefined) {
|
|
55
|
+
emit((0, protocol_1.buildAcpResponse)(currentRequestId, {
|
|
56
|
+
stopReason: "error",
|
|
57
|
+
error: `Claude process exited unexpectedly (code=${code})`,
|
|
58
|
+
}));
|
|
59
|
+
currentRequestId = undefined;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
if (proc.stdout)
|
|
63
|
+
setupClaudeOutputHandler(proc);
|
|
64
|
+
if (proc.stderr) {
|
|
65
|
+
const rl = (0, readline_1.createInterface)({ input: proc.stderr });
|
|
66
|
+
rl.on("line", (line) => process.stderr.write(`[claude-stderr] ${line}\n`));
|
|
67
|
+
}
|
|
68
|
+
return proc;
|
|
69
|
+
}
|
|
70
|
+
// ─── Part 3: Claude Code stream-json output → ACP events ────────────────────
|
|
71
|
+
function setupClaudeOutputHandler(proc) {
|
|
72
|
+
const rl = (0, readline_1.createInterface)({ input: proc.stdout });
|
|
73
|
+
rl.on("line", (line) => {
|
|
74
|
+
if (!line.trim())
|
|
75
|
+
return;
|
|
76
|
+
let msg;
|
|
77
|
+
try {
|
|
78
|
+
msg = JSON.parse(line);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
log(`Failed to parse Claude output: ${line}`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
handleClaudeMessage(msg);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function handleClaudeMessage(msg) {
|
|
88
|
+
switch (msg.type) {
|
|
89
|
+
case "stream_event":
|
|
90
|
+
handleStreamEvent(msg);
|
|
91
|
+
break;
|
|
92
|
+
case "assistant":
|
|
93
|
+
handleAssistantMessage(msg);
|
|
94
|
+
break;
|
|
95
|
+
case "result":
|
|
96
|
+
handleResultMessage(msg);
|
|
97
|
+
break;
|
|
98
|
+
case "system":
|
|
99
|
+
handleSystemMessage(msg);
|
|
100
|
+
break;
|
|
101
|
+
default: log(`Unknown message type: ${msg.type}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function handleStreamEvent(msg) {
|
|
105
|
+
const event = msg.event;
|
|
106
|
+
if (!event)
|
|
107
|
+
return;
|
|
108
|
+
switch (event.type) {
|
|
109
|
+
case "message_start": {
|
|
110
|
+
if (event.message?.usage) {
|
|
111
|
+
accumulatedUsage.inputTokens = event.message.usage.input_tokens ?? 0;
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case "content_block_start": {
|
|
116
|
+
const block = event.content_block;
|
|
117
|
+
if (block?.type === "tool_use") {
|
|
118
|
+
currentToolName = block.name ?? null;
|
|
119
|
+
currentToolId = block.id ?? null;
|
|
120
|
+
currentToolInput = "";
|
|
121
|
+
log(`Tool starting: ${currentToolName}`);
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case "content_block_delta": {
|
|
126
|
+
const delta = event.delta;
|
|
127
|
+
if (!delta)
|
|
128
|
+
break;
|
|
129
|
+
if (delta.type === "text_delta" && delta.text) {
|
|
130
|
+
emit((0, protocol_1.buildAgentMessageChunk)(sessionId, delta.text));
|
|
131
|
+
}
|
|
132
|
+
else if (delta.type === "input_json_delta" && delta.partial_json) {
|
|
133
|
+
currentToolInput += delta.partial_json;
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
case "content_block_stop": {
|
|
138
|
+
if (currentToolName && currentToolId) {
|
|
139
|
+
let parsedInput = currentToolInput;
|
|
140
|
+
try {
|
|
141
|
+
parsedInput = JSON.parse(currentToolInput);
|
|
142
|
+
}
|
|
143
|
+
catch { /* keep as string */ }
|
|
144
|
+
emit((0, protocol_1.buildToolCall)(sessionId, currentToolId, currentToolName, parsedInput));
|
|
145
|
+
log(`Tool call emitted: ${currentToolName}`);
|
|
146
|
+
currentToolName = null;
|
|
147
|
+
currentToolId = null;
|
|
148
|
+
currentToolInput = "";
|
|
149
|
+
}
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case "message_delta": {
|
|
153
|
+
if (event.delta?.stop_reason) {
|
|
154
|
+
log(`Stop reason: ${event.delta.stop_reason}`);
|
|
155
|
+
}
|
|
156
|
+
if (event.usage) {
|
|
157
|
+
accumulatedUsage.outputTokens += event.usage.output_tokens ?? 0;
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
case "message_stop":
|
|
162
|
+
log("Message complete");
|
|
163
|
+
break;
|
|
164
|
+
default:
|
|
165
|
+
log(`Unhandled stream event: ${event.type}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function handleAssistantMessage(msg) {
|
|
169
|
+
if (!msg.message?.content)
|
|
170
|
+
return;
|
|
171
|
+
for (const block of msg.message.content) {
|
|
172
|
+
if (block.type === "tool_result") {
|
|
173
|
+
emit((0, protocol_1.buildToolResult)(sessionId, block.id ?? "", block.text ?? ""));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function handleResultMessage(msg) {
|
|
178
|
+
log(`Result: subtype=${msg.subtype}`);
|
|
179
|
+
emit((0, protocol_1.buildPromptResponse)(currentRequestId, msg.subtype === "success" ? "end_turn" : "error", msg.result ?? "", accumulatedUsage));
|
|
180
|
+
currentRequestId = undefined;
|
|
181
|
+
accumulatedUsage = { inputTokens: 0, outputTokens: 0 };
|
|
182
|
+
}
|
|
183
|
+
function handleSystemMessage(msg) {
|
|
184
|
+
if (msg.subtype === "api_retry") {
|
|
185
|
+
log(`API retry: attempt=${msg.attempt}/${msg.max_retries}, error=${msg.error}`);
|
|
186
|
+
}
|
|
187
|
+
else if (msg.subtype === "init") {
|
|
188
|
+
log(`Claude session initialized: ${msg.session_id}`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
log(`System: ${JSON.stringify(msg)}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// ─── Part 2: ACP input → Claude Code stream-json ────────────────────────────
|
|
195
|
+
function sendToClaude(obj) {
|
|
196
|
+
if (!claudeProcess?.stdin?.writable) {
|
|
197
|
+
log("Claude stdin not writable");
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const line = JSON.stringify(obj) + "\n";
|
|
201
|
+
log(`→ Claude stdin: ${line.trim().slice(0, 120)}`);
|
|
202
|
+
claudeProcess.stdin.write(line);
|
|
203
|
+
}
|
|
204
|
+
function handleAcpMessage(raw) {
|
|
205
|
+
let msg;
|
|
206
|
+
try {
|
|
207
|
+
msg = JSON.parse(raw);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
log(`Failed to parse ACP input: ${raw}`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const method = msg.method;
|
|
214
|
+
log(`ACP ← ${method} (id=${msg.id})`);
|
|
215
|
+
switch (method) {
|
|
216
|
+
case "initialize": {
|
|
217
|
+
sessionId = `session-${Date.now()}`;
|
|
218
|
+
emit((0, protocol_1.buildAcpResponse)(msg.id, {
|
|
219
|
+
protocolVersion: "2024-11-05",
|
|
220
|
+
capabilities: { streaming: true, tools: true },
|
|
221
|
+
serverInfo: { name: "proxy-acpx-x", version: "1.0.0" },
|
|
222
|
+
}));
|
|
223
|
+
if (!claudeProcess)
|
|
224
|
+
claudeProcess = spawnClaude();
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
case "session/create": {
|
|
228
|
+
sessionId = msg.params?.sessionId ?? `session-${Date.now()}`;
|
|
229
|
+
emit((0, protocol_1.buildAcpResponse)(msg.id, { sessionId }));
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case "session/prompt": {
|
|
233
|
+
currentRequestId = msg.id;
|
|
234
|
+
accumulatedUsage = { inputTokens: 0, outputTokens: 0 };
|
|
235
|
+
const prompts = msg.params?.prompt ?? [];
|
|
236
|
+
const text = (0, protocol_1.extractTextFromPrompt)(prompts);
|
|
237
|
+
if (!text) {
|
|
238
|
+
emit((0, protocol_1.buildAcpResponse)(msg.id, {
|
|
239
|
+
stopReason: "end_turn",
|
|
240
|
+
usage: { inputTokens: 0, outputTokens: 0 },
|
|
241
|
+
}));
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
log(`Prompt: ${(0, protocol_1.summarizeInput)(text)}`);
|
|
245
|
+
if (!claudeProcess)
|
|
246
|
+
claudeProcess = spawnClaude();
|
|
247
|
+
sendToClaude((0, protocol_1.buildClaudeUserMessage)(text));
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case "session/cancel": {
|
|
251
|
+
if (claudeProcess) {
|
|
252
|
+
claudeProcess.kill("SIGTERM");
|
|
253
|
+
claudeProcess = null;
|
|
254
|
+
}
|
|
255
|
+
emit((0, protocol_1.buildAcpResponse)(msg.id, { cancelled: true }));
|
|
256
|
+
currentRequestId = undefined;
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
case "session/close": {
|
|
260
|
+
if (claudeProcess) {
|
|
261
|
+
claudeProcess.stdin?.end();
|
|
262
|
+
setTimeout(() => {
|
|
263
|
+
if (claudeProcess) {
|
|
264
|
+
claudeProcess.kill("SIGTERM");
|
|
265
|
+
claudeProcess = null;
|
|
266
|
+
}
|
|
267
|
+
}, 1000);
|
|
268
|
+
}
|
|
269
|
+
emit((0, protocol_1.buildAcpResponse)(msg.id, { closed: true }));
|
|
270
|
+
sessionId = null;
|
|
271
|
+
currentRequestId = undefined;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case "notifications/initialized":
|
|
275
|
+
break;
|
|
276
|
+
default: {
|
|
277
|
+
log(`Unhandled ACP method: ${method}`);
|
|
278
|
+
emit((0, protocol_1.buildAcpError)(msg.id, -32601, `Method not found: ${method}`));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// ─── Main ────────────────────────────────────────────────────────────────────
|
|
283
|
+
function main() {
|
|
284
|
+
log("Adapter started, waiting for ACP input...");
|
|
285
|
+
log("Using Claude Code CLI with stream-json I/O");
|
|
286
|
+
const rl = (0, readline_1.createInterface)({ input: process.stdin });
|
|
287
|
+
rl.on("line", (line) => { if (line.trim())
|
|
288
|
+
handleAcpMessage(line); });
|
|
289
|
+
rl.on("close", () => {
|
|
290
|
+
log("stdin closed, shutting down");
|
|
291
|
+
shutdown();
|
|
292
|
+
});
|
|
293
|
+
process.on("SIGINT", shutdown);
|
|
294
|
+
process.on("SIGTERM", shutdown);
|
|
295
|
+
}
|
|
296
|
+
function shutdown() {
|
|
297
|
+
log("Shutting down...");
|
|
298
|
+
if (claudeProcess) {
|
|
299
|
+
claudeProcess.stdin?.end();
|
|
300
|
+
claudeProcess.kill("SIGTERM");
|
|
301
|
+
}
|
|
302
|
+
process.exit(0);
|
|
303
|
+
}
|
|
304
|
+
main();
|
|
305
|
+
//# sourceMappingURL=adapter.js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a,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol translation utilities for ACP ↔ Claude Code stream-json.
|
|
3
|
+
* Pure functions — no side effects, no process I/O.
|
|
4
|
+
*/
|
|
5
|
+
export interface AcpPrompt {
|
|
6
|
+
type: string;
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AcpMessage {
|
|
10
|
+
jsonrpc: string;
|
|
11
|
+
id?: string | number;
|
|
12
|
+
method: string;
|
|
13
|
+
params?: {
|
|
14
|
+
prompt?: AcpPrompt[];
|
|
15
|
+
sessionId?: string;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface ClaudeStreamEvent {
|
|
20
|
+
type: string;
|
|
21
|
+
delta?: {
|
|
22
|
+
type: string;
|
|
23
|
+
text?: string;
|
|
24
|
+
partial_json?: string;
|
|
25
|
+
stop_reason?: string;
|
|
26
|
+
};
|
|
27
|
+
content_block?: {
|
|
28
|
+
type: string;
|
|
29
|
+
text?: string;
|
|
30
|
+
id?: string;
|
|
31
|
+
name?: string;
|
|
32
|
+
input?: unknown;
|
|
33
|
+
};
|
|
34
|
+
message?: {
|
|
35
|
+
usage?: {
|
|
36
|
+
input_tokens?: number;
|
|
37
|
+
output_tokens?: number;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
usage?: {
|
|
41
|
+
output_tokens?: number;
|
|
42
|
+
};
|
|
43
|
+
index?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ClaudeStreamOutput {
|
|
46
|
+
type: string;
|
|
47
|
+
subtype?: string;
|
|
48
|
+
event?: ClaudeStreamEvent;
|
|
49
|
+
message?: {
|
|
50
|
+
content?: Array<{
|
|
51
|
+
type: string;
|
|
52
|
+
text?: string;
|
|
53
|
+
id?: string;
|
|
54
|
+
name?: string;
|
|
55
|
+
input?: unknown;
|
|
56
|
+
}>;
|
|
57
|
+
};
|
|
58
|
+
result?: string;
|
|
59
|
+
session_id?: string;
|
|
60
|
+
uuid?: string;
|
|
61
|
+
attempt?: number;
|
|
62
|
+
max_retries?: number;
|
|
63
|
+
error?: string;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
export declare function buildAcpResponse(id: string | number | undefined, result: Record<string, unknown>): Record<string, unknown>;
|
|
67
|
+
export declare function buildAcpNotification(method: string, params: Record<string, unknown>): Record<string, unknown>;
|
|
68
|
+
export declare function buildAcpError(id: string | number | undefined, code: number, message: string): Record<string, unknown>;
|
|
69
|
+
export declare function extractTextFromPrompt(prompts: AcpPrompt[]): string;
|
|
70
|
+
export declare function buildClaudeUserMessage(text: string): Record<string, unknown>;
|
|
71
|
+
export declare function buildAgentMessageChunk(sessionId: string | null, textChunk: string): Record<string, unknown>;
|
|
72
|
+
export declare function buildToolCall(sessionId: string | null, toolCallId: string, toolName: string, input: unknown): Record<string, unknown>;
|
|
73
|
+
export declare function buildToolResult(sessionId: string | null, toolCallId: string, output: string): Record<string, unknown>;
|
|
74
|
+
export declare function buildPromptResponse(id: string | number | undefined, stopReason: string, result: string, usage: {
|
|
75
|
+
inputTokens: number;
|
|
76
|
+
outputTokens: number;
|
|
77
|
+
}): Record<string, unknown>;
|
|
78
|
+
export declare function classifyTool(name: string): "read" | "write" | "execute";
|
|
79
|
+
export declare function summarizeInput(text: string): string;
|
|
80
|
+
export declare function parseNdjsonLine(line: string): unknown | null;
|
|
81
|
+
/**
|
|
82
|
+
* Build the Claude CLI argument list.
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildClaudeArgs(options?: {
|
|
85
|
+
bare?: boolean;
|
|
86
|
+
permissionMode?: string;
|
|
87
|
+
allowedTools?: string[];
|
|
88
|
+
}): string[];
|
|
89
|
+
//# sourceMappingURL=protoc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
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Protocol translation utilities for ACP ↔ Claude Code stream-json.
|
|
4
|
+
* Pure functions — no side effects, no process I/O.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.buildAcpResponse = buildAcpResponse;
|
|
8
|
+
exports.buildAcpNotification = buildAcpNotification;
|
|
9
|
+
exports.buildAcpError = buildAcpError;
|
|
10
|
+
exports.extractTextFromPrompt = extractTextFromPrompt;
|
|
11
|
+
exports.buildClaudeUserMessage = buildClaudeUserMessage;
|
|
12
|
+
exports.buildAgentMessageChunk = buildAgentMessageChunk;
|
|
13
|
+
exports.buildToolCall = buildToolCall;
|
|
14
|
+
exports.buildToolResult = buildToolResult;
|
|
15
|
+
exports.buildPromptResponse = buildPromptResponse;
|
|
16
|
+
exports.classifyTool = classifyTool;
|
|
17
|
+
exports.summarizeInput = summarizeInput;
|
|
18
|
+
exports.parseNdjsonLine = parseNdjsonLine;
|
|
19
|
+
exports.buildClaudeArgs = buildClaudeArgs;
|
|
20
|
+
// ─── ACP output builders ─────────────────────────────────────────────────────
|
|
21
|
+
function buildAcpResponse(id, result) {
|
|
22
|
+
return { jsonrpc: "2.0", id, result };
|
|
23
|
+
}
|
|
24
|
+
function buildAcpNotification(method, params) {
|
|
25
|
+
return { jsonrpc: "2.0", method, params };
|
|
26
|
+
}
|
|
27
|
+
function buildAcpError(id, code, message) {
|
|
28
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
29
|
+
}
|
|
30
|
+
// ─── ACP → Claude Code stream-json ──────────────────────────────────────────
|
|
31
|
+
function extractTextFromPrompt(prompts) {
|
|
32
|
+
return prompts
|
|
33
|
+
.filter((p) => p.type === "text")
|
|
34
|
+
.map((p) => p.text)
|
|
35
|
+
.join("\n");
|
|
36
|
+
}
|
|
37
|
+
function buildClaudeUserMessage(text) {
|
|
38
|
+
return {
|
|
39
|
+
type: "user",
|
|
40
|
+
message: {
|
|
41
|
+
role: "user",
|
|
42
|
+
content: text,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// ─── Claude Code stream-json → ACP ──────────────────────────────────────────
|
|
47
|
+
function buildAgentMessageChunk(sessionId, textChunk) {
|
|
48
|
+
return buildAcpNotification("session/update", {
|
|
49
|
+
sessionId,
|
|
50
|
+
sessionUpdate: {
|
|
51
|
+
type: "agent_message_chunk",
|
|
52
|
+
textChunk,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function buildToolCall(sessionId, toolCallId, toolName, input) {
|
|
57
|
+
return buildAcpNotification("session/update", {
|
|
58
|
+
sessionId,
|
|
59
|
+
sessionUpdate: {
|
|
60
|
+
type: "tool_call",
|
|
61
|
+
toolCallId,
|
|
62
|
+
toolName,
|
|
63
|
+
toolCategory: classifyTool(toolName),
|
|
64
|
+
input,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function buildToolResult(sessionId, toolCallId, output) {
|
|
69
|
+
return buildAcpNotification("session/update", {
|
|
70
|
+
sessionId,
|
|
71
|
+
sessionUpdate: {
|
|
72
|
+
type: "tool_result",
|
|
73
|
+
toolCallId,
|
|
74
|
+
output,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function buildPromptResponse(id, stopReason, result, usage) {
|
|
79
|
+
return buildAcpResponse(id, { stopReason, result, usage });
|
|
80
|
+
}
|
|
81
|
+
// ─── Utilities ───────────────────────────────────────────────────────────────
|
|
82
|
+
function classifyTool(name) {
|
|
83
|
+
const readTools = ["Read", "Glob", "Grep", "WebFetch", "WebSearch"];
|
|
84
|
+
const writeTools = ["Write", "Edit", "NotebookEdit"];
|
|
85
|
+
if (writeTools.includes(name))
|
|
86
|
+
return "write";
|
|
87
|
+
if (readTools.includes(name))
|
|
88
|
+
return "read";
|
|
89
|
+
return "execute";
|
|
90
|
+
}
|
|
91
|
+
function summarizeInput(text) {
|
|
92
|
+
const firstLine = text.split("\n")[0] ?? "";
|
|
93
|
+
return firstLine.length > 80 ? firstLine.slice(0, 80) + "..." : firstLine;
|
|
94
|
+
}
|
|
95
|
+
function parseNdjsonLine(line) {
|
|
96
|
+
if (!line.trim())
|
|
97
|
+
return null;
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(line);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Build the Claude CLI argument list.
|
|
107
|
+
*/
|
|
108
|
+
function buildClaudeArgs(options) {
|
|
109
|
+
const args = [
|
|
110
|
+
"-p",
|
|
111
|
+
"--input-format", "stream-json",
|
|
112
|
+
"--output-format", "stream-json",
|
|
113
|
+
"--verbose",
|
|
114
|
+
"--include-partial-messages",
|
|
115
|
+
];
|
|
116
|
+
if (options?.bare !== false) {
|
|
117
|
+
args.push("--bare");
|
|
118
|
+
}
|
|
119
|
+
const mode = options?.permissionMode ?? "bypassPermissions";
|
|
120
|
+
args.push("--permission-mode", mode);
|
|
121
|
+
if (options?.allowedTools?.length) {
|
|
122
|
+
args.push("--allowedTools", ...options.allowedTools);
|
|
123
|
+
}
|
|
124
|
+
return args;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAkEH,4CAEC;AAED,oDAEC;AAED,sCAEC;AAID,sDAKC;AAED,wDAQC;AAID,wDAQC;AAED,sCAgBC;AAED,0CAaC;AAED,kDAOC;AAID,oCAMC;AAED,wCAGC;AAED,0CAOC;AAKD,0CAyBC;AA3ID,gFAAgF;AAEhF,SAAgB,gBAAgB,CAAC,EAA+B,EAAE,MAA+B;IAC/F,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,M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,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,OAI/B;IACC,MAAM,IAAI,GAAG;QACX,IAAI;QACJ,gBAAgB,EAAE,aAAa;QAC/B,iBAAiB,EAAE,aAAa;QAChC,WAAW;QACX,4BAA4B;KAC7B,CAAC;IAEF,IAAI,OAAO,EAAE,IAAI,KAAK,KAAK,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,EAAE,cAAc,IAAI,mBAAmB,CAAC;IAC5D,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;IAErC,IAAI,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "proxy-acpx-x",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "ACP ↔ Claude Code stream-json adapter — use Claude Code CLI subscription auth with OpenClaw/acpx",
|
|
5
|
+
"main": "dist/adapter.js",
|
|
6
|
+
"types": "dist/adapter.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"proxy-acpx-x": "dist/adapter.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "npm run build && npm test",
|
|
17
|
+
"start": "node dist/adapter.js",
|
|
18
|
+
"dev": "ts-node src/adapter.ts",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
21
|
+
"test:smoke": "bash test/smoke.sh"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/clonn/proxy-acpx-x.git"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/clonn/proxy-acpx-x#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/clonn/proxy-acpx-x/issues"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"claude-code",
|
|
33
|
+
"acp",
|
|
34
|
+
"acpx",
|
|
35
|
+
"openclaw",
|
|
36
|
+
"adapter",
|
|
37
|
+
"proxy",
|
|
38
|
+
"stream-json"
|
|
39
|
+
],
|
|
40
|
+
"author": "Caesar Chi",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^20.11.0",
|
|
44
|
+
"ts-node": "^10.9.0",
|
|
45
|
+
"typescript": "^5.3.0",
|
|
46
|
+
"vitest": "^3.2.4"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
}
|
|
51
|
+
}
|