@openclaw/acpx 2026.5.2-beta.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.
@@ -0,0 +1,248 @@
1
+ ---
2
+ name: acp-router
3
+ description: Route plain-language requests for Pi, Claude Code, Cursor, Copilot, OpenClaw ACP, OpenCode, Gemini CLI, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either OpenClaw ACP runtime sessions or direct acpx-driven sessions ("telephone game" flow). For coding-agent thread requests, read this skill first, then use only `sessions_spawn` for thread creation. Codex chat binding defaults to the native Codex app-server plugin unless ACP is explicit or background spawn needs ACP.
4
+ user-invocable: false
5
+ ---
6
+
7
+ # ACP Harness Router
8
+
9
+ When user intent is "run this in Pi/Claude Code/Cursor/Copilot/OpenClaw/OpenCode/Gemini/Qwen/Kiro/Kimi/iFlow/Droid/Kilocode (ACP harness)", do not use subagent runtime or PTY scraping. Route through ACP-aware flows.
10
+
11
+ Codex is special: plain chat/conversation binding and control should use the native Codex app-server plugin (`/codex bind`, `/codex threads`, `/codex resume`) instead of the default ACP path. Use ACP for Codex only when the user explicitly names ACP/`/acp`/acpx, or when spawning background child sessions through `sessions_spawn` where a native Codex runtime spawn is not available yet.
12
+
13
+ ## Intent detection
14
+
15
+ Trigger this skill when the user asks OpenClaw to:
16
+
17
+ - run something in Pi / Claude Code / Cursor / Copilot / OpenClaw / OpenCode / Gemini / Qwen / Kiro / Kimi / iFlow / Droid / Kilocode
18
+ - run Codex explicitly through ACP, `/acp`, or acpx
19
+ - continue existing harness work
20
+ - relay instructions to an external coding harness
21
+ - keep an external harness conversation in a thread-like conversation
22
+
23
+ Mandatory preflight for coding-agent thread requests:
24
+
25
+ - Before creating any thread for ACP harness work, read this skill first in the same turn.
26
+ - After reading, follow `OpenClaw ACP runtime path` below; do not use `message(action="thread-create")` for ACP harness thread spawn.
27
+
28
+ ## Mode selection
29
+
30
+ Choose one of these paths:
31
+
32
+ 1. OpenClaw ACP runtime path (default): use `sessions_spawn` / ACP runtime tools.
33
+ 2. Direct `acpx` path (telephone game): use `acpx` CLI through `exec` to drive the harness session directly.
34
+
35
+ Use direct `acpx` when one of these is true:
36
+
37
+ - user explicitly asks for direct `acpx` driving
38
+ - ACP runtime/plugin path is unavailable or unhealthy
39
+ - the task is "just relay prompts to harness" and no OpenClaw ACP lifecycle features are needed
40
+
41
+ Do not use:
42
+
43
+ - `subagents` runtime for harness control
44
+ - `/acp` command delegation as a requirement for the user
45
+ - PTY scraping of supported ACP harness CLIs when `acpx` is available
46
+
47
+ ## AgentId mapping
48
+
49
+ Use these defaults when user names a harness directly:
50
+
51
+ - "pi" -> `agentId: "pi"`
52
+ - "openclaw" -> `agentId: "openclaw"`
53
+ - "claude" or "claude code" -> `agentId: "claude"`
54
+ - "codex" -> `agentId: "codex"` only for explicit ACP/acpx requests or background ACP runtime spawn
55
+ - "copilot" or "github copilot" -> `agentId: "copilot"`
56
+ - "cursor" or "cursor cli" -> `agentId: "cursor"`
57
+ - "droid" or "factory droid" -> `agentId: "droid"`
58
+ - "opencode" -> `agentId: "opencode"`
59
+ - "gemini" or "gemini cli" -> `agentId: "gemini"`
60
+ - "iflow" -> `agentId: "iflow"`
61
+ - "kilocode" -> `agentId: "kilocode"`
62
+ - "kimi" or "kimi cli" -> `agentId: "kimi"`
63
+ - "kiro" or "kiro cli" -> `agentId: "kiro"`
64
+ - "qwen" or "qwen code" -> `agentId: "qwen"`
65
+
66
+ These defaults match current acpx built-in aliases.
67
+
68
+ If policy rejects the chosen id, report the policy error clearly and ask for the allowed ACP agent id.
69
+
70
+ ## OpenClaw ACP runtime path
71
+
72
+ Required behavior:
73
+
74
+ 1. For ACP harness thread spawn requests, read this skill first in the same turn before calling tools.
75
+ 2. Use `sessions_spawn` with:
76
+ - `runtime: "acp"`
77
+ - `thread: true`
78
+ - `mode: "session"` (unless user explicitly wants one-shot)
79
+ 3. For ACP harness thread creation, do not use `message` with `action=thread-create`; `sessions_spawn` is the only thread-create path.
80
+ 4. Put requested work in `task` so the ACP session gets it immediately.
81
+ 5. Set `agentId` explicitly unless ACP default agent is known.
82
+ 6. Do not ask user to run slash commands or CLI when this path works directly.
83
+
84
+ Example:
85
+
86
+ User: "spawn a test codex ACP session in thread and tell it to say hi"
87
+
88
+ Call:
89
+
90
+ ```json
91
+ {
92
+ "task": "Say hi.",
93
+ "runtime": "acp",
94
+ "agentId": "codex",
95
+ "thread": true,
96
+ "mode": "session"
97
+ }
98
+ ```
99
+
100
+ ## Thread spawn recovery policy
101
+
102
+ When the user asks to start a coding harness in a thread, treat that as an ACP runtime request and try to satisfy it end-to-end.
103
+
104
+ Required behavior when ACP backend is unavailable:
105
+
106
+ 1. Do not immediately ask the user to pick an alternate path.
107
+ 2. First attempt automatic local repair:
108
+ - ensure plugin-local pinned acpx is installed in the ACPX plugin package
109
+ - verify `${ACPX_CMD} --version`
110
+ 3. After reinstall/repair, restart the gateway and explicitly offer to run that restart for the user.
111
+ 4. Retry ACP thread spawn once after repair.
112
+ 5. Only if repair+retry fails, report the concrete error and then offer fallback options.
113
+
114
+ When offering fallback, keep ACP first:
115
+
116
+ - Option 1: retry ACP spawn after showing exact failing step
117
+ - Option 2: direct acpx telephone-game flow
118
+
119
+ Do not default to subagent runtime for these requests.
120
+
121
+ ## ACPX install and version policy (direct acpx path)
122
+
123
+ For this repo, direct `acpx` calls must follow the same pinned policy as the `@openclaw/acpx` extension package.
124
+
125
+ 1. Prefer plugin-local binary, not global PATH:
126
+ - `${ACPX_PLUGIN_ROOT}/node_modules/.bin/acpx`
127
+ 2. Resolve pinned version from extension dependency:
128
+ - `node -e "console.log(require(process.env.ACPX_PLUGIN_ROOT + '/package.json').dependencies.acpx)"`
129
+ 3. If binary is missing or version mismatched, install plugin-local pinned version:
130
+ - `cd "$ACPX_PLUGIN_ROOT" && npm install --omit=dev --no-save acpx@<pinnedVersion>`
131
+ 4. Verify before use:
132
+ - `${ACPX_PLUGIN_ROOT}/node_modules/.bin/acpx --version`
133
+ 5. If install/repair changed ACPX artifacts, restart the gateway and offer to run the restart.
134
+ 6. Do not run `npm install -g acpx` unless the user explicitly asks for global install.
135
+
136
+ Set and reuse:
137
+
138
+ ```bash
139
+ ACPX_PLUGIN_ROOT="<bundled-acpx-plugin-root>"
140
+ ACPX_CMD="$ACPX_PLUGIN_ROOT/node_modules/.bin/acpx"
141
+ ```
142
+
143
+ ## Direct acpx path ("telephone game")
144
+
145
+ Use this path to drive harness sessions without `/acp` or subagent runtime.
146
+
147
+ ### Rules
148
+
149
+ 1. Use `exec` commands that call `${ACPX_CMD}`.
150
+ 2. Reuse a stable session name per conversation so follow-up prompts stay in the same harness context.
151
+ 3. Prefer `--format quiet` for clean assistant text to relay back to user.
152
+ 4. Use `exec` (one-shot) only when the user wants one-shot behavior.
153
+ 5. Keep working directory explicit (`--cwd`) when task scope depends on repo context.
154
+
155
+ ### Session naming
156
+
157
+ Use a deterministic name, for example:
158
+
159
+ - `oc-<harness>-<conversationId>`
160
+
161
+ Where `conversationId` is thread id when available, otherwise channel/conversation id.
162
+
163
+ ### Command templates
164
+
165
+ Persistent session (create if missing, then prompt):
166
+
167
+ ```bash
168
+ ${ACPX_CMD} codex sessions show oc-codex-<conversationId> \
169
+ || ${ACPX_CMD} codex sessions new --name oc-codex-<conversationId>
170
+
171
+ ${ACPX_CMD} codex -s oc-codex-<conversationId> --cwd <workspacePath> --format quiet "<prompt>"
172
+ ```
173
+
174
+ One-shot:
175
+
176
+ ```bash
177
+ ${ACPX_CMD} codex exec --cwd <workspacePath> --format quiet "<prompt>"
178
+ ```
179
+
180
+ Cancel in-flight turn:
181
+
182
+ ```bash
183
+ ${ACPX_CMD} codex cancel -s oc-codex-<conversationId>
184
+ ```
185
+
186
+ Close session:
187
+
188
+ ```bash
189
+ ${ACPX_CMD} codex sessions close oc-codex-<conversationId>
190
+ ```
191
+
192
+ ### Harness aliases in acpx
193
+
194
+ - `claude`
195
+ - `codex`
196
+ - `copilot`
197
+ - `cursor`
198
+ - `droid`
199
+ - `gemini`
200
+ - `iflow`
201
+ - `kilocode`
202
+ - `kimi`
203
+ - `kiro`
204
+ - `openclaw`
205
+ - `opencode`
206
+ - `pi`
207
+ - `qwen`
208
+
209
+ ### Built-in adapter commands in acpx
210
+
211
+ Defaults are:
212
+
213
+ - `openclaw -> openclaw acp`
214
+ - `claude -> npx -y @agentclientprotocol/claude-agent-acp@^0.31.0`
215
+ - `codex -> bundled @zed-industries/codex-acp@0.12.0 through OpenClaw's isolated CODEX_HOME wrapper`
216
+ - `copilot -> copilot --acp --stdio`
217
+ - `cursor -> cursor-agent acp`
218
+ - `droid -> droid exec --output-format acp`
219
+ - `gemini -> gemini --acp`
220
+ - `iflow -> iflow --experimental-acp`
221
+ - `kilocode -> npx -y @kilocode/cli acp`
222
+ - `kimi -> kimi acp`
223
+ - `kiro -> kiro-cli acp`
224
+ - `opencode -> npx -y opencode-ai acp`
225
+ - `pi -> npx pi-acp@^0.0.22`
226
+ - `qwen -> qwen --acp`
227
+
228
+ If `~/.acpx/config.json` overrides `agents`, those overrides replace defaults.
229
+ If your local Cursor install still exposes ACP as `agent acp`, set that as the `cursor` agent override explicitly.
230
+
231
+ ### Failure handling
232
+
233
+ - `acpx: command not found`:
234
+ - for thread-spawn ACP requests, install plugin-local pinned acpx in the ACPX plugin package immediately
235
+ - restart gateway after install and offer to run the restart automatically
236
+ - then retry once
237
+ - do not ask for install permission first unless policy explicitly requires it
238
+ - do not install global `acpx` unless explicitly requested
239
+ - adapter command missing (for example `claude-agent-acp` not found):
240
+ - for thread-spawn ACP requests, first restore built-in defaults by removing broken `~/.acpx/config.json` agent overrides
241
+ - then retry once before offering fallback
242
+ - if user wants binary-based overrides, install exactly the configured adapter binary
243
+ - `NO_SESSION`: run `${ACPX_CMD} <agent> sessions new --name <sessionName>` then retry prompt.
244
+ - queue busy: either wait for completion (default) or use `--no-wait` when async behavior is explicitly desired.
245
+
246
+ ### Output relay
247
+
248
+ When relaying to user, return the final assistant text output from `acpx` command result. Avoid relaying raw local tool noise unless user asked for verbose logs.
@@ -0,0 +1,62 @@
1
+ declare module "acpx/runtime" {
2
+ export const ACPX_BACKEND_ID: string;
3
+
4
+ export type AcpRuntimeDoctorReport = import("../runtime-api.js").AcpRuntimeDoctorReport;
5
+ export type AcpRuntimeEnsureInput = import("../runtime-api.js").AcpRuntimeEnsureInput;
6
+ export type AcpRuntimeEvent = import("../runtime-api.js").AcpRuntimeEvent;
7
+ export type AcpRuntimeHandle = import("../runtime-api.js").AcpRuntimeHandle;
8
+ export type AcpRuntimeCapabilities = import("../runtime-api.js").AcpRuntimeCapabilities;
9
+ export type AcpRuntimeStatus = import("../runtime-api.js").AcpRuntimeStatus;
10
+ export type AcpRuntimeTurnInput = import("../runtime-api.js").AcpRuntimeTurnInput;
11
+
12
+ export type AcpAgentRegistry = {
13
+ resolve(agent: string): string | undefined;
14
+ list(): string[];
15
+ };
16
+
17
+ export type AcpSessionRecord = Record<string, unknown>;
18
+
19
+ export type AcpSessionStore = {
20
+ load(sessionId: string): Promise<AcpSessionRecord | undefined>;
21
+ save(record: AcpSessionRecord): Promise<void>;
22
+ };
23
+
24
+ export type AcpRuntimeOptions = {
25
+ cwd: string;
26
+ sessionStore: AcpSessionStore;
27
+ agentRegistry: AcpAgentRegistry;
28
+ probeAgent?: string;
29
+ mcpServers?: unknown;
30
+ permissionMode?: unknown;
31
+ nonInteractivePermissions?: unknown;
32
+ timeoutMs?: number;
33
+ probeAgent?: string;
34
+ };
35
+
36
+ export class AcpxRuntime {
37
+ constructor(options: AcpRuntimeOptions, testOptions?: unknown);
38
+ isHealthy(): boolean;
39
+ probeAvailability(): Promise<void>;
40
+ doctor(): Promise<AcpRuntimeDoctorReport>;
41
+ ensureSession(input: AcpRuntimeEnsureInput): Promise<AcpRuntimeHandle>;
42
+ runTurn(input: AcpRuntimeTurnInput): AsyncIterable<AcpRuntimeEvent>;
43
+ getCapabilities(input?: {
44
+ handle?: AcpRuntimeHandle;
45
+ }): AcpRuntimeCapabilities | Promise<AcpRuntimeCapabilities>;
46
+ getStatus(input: { handle: AcpRuntimeHandle; signal?: AbortSignal }): Promise<AcpRuntimeStatus>;
47
+ setMode(input: { handle: AcpRuntimeHandle; mode: string }): Promise<void>;
48
+ setConfigOption(input: { handle: AcpRuntimeHandle; key: string; value: string }): Promise<void>;
49
+ cancel(input: { handle: AcpRuntimeHandle; reason?: string }): Promise<void>;
50
+ close(input: {
51
+ handle: AcpRuntimeHandle;
52
+ reason?: string;
53
+ discardPersistentState?: boolean;
54
+ }): Promise<void>;
55
+ }
56
+
57
+ export function createAcpRuntime(...args: unknown[]): AcpxRuntime;
58
+ export function createAgentRegistry(params: { overrides?: unknown }): AcpAgentRegistry;
59
+ export function createFileSessionStore(params: { stateDir: string }): AcpSessionStore;
60
+ export function decodeAcpxRuntimeHandleState(...args: unknown[]): unknown;
61
+ export function encodeAcpxRuntimeHandleState(...args: unknown[]): unknown;
62
+ }
@@ -0,0 +1,129 @@
1
+ import { ClaudeAcpAgent } from "@agentclientprotocol/claude-agent-acp";
2
+ import { describe, expect, it, vi } from "vitest";
3
+
4
+ type IteratorResultResolver = (value: IteratorResult<unknown>) => void;
5
+
6
+ class ManualAsyncIterator implements AsyncIterator<unknown> {
7
+ private readonly pending: IteratorResultResolver[] = [];
8
+ private readonly queued: IteratorResult<unknown>[] = [];
9
+
10
+ next(): Promise<IteratorResult<unknown>> {
11
+ const next = this.queued.shift();
12
+ if (next) {
13
+ return Promise.resolve(next);
14
+ }
15
+ return new Promise((resolve) => {
16
+ this.pending.push(resolve);
17
+ });
18
+ }
19
+
20
+ push(value: unknown): void {
21
+ this.resolve({ value, done: false });
22
+ }
23
+
24
+ end(): void {
25
+ this.resolve({ value: undefined, done: true });
26
+ }
27
+
28
+ private resolve(value: IteratorResult<unknown>): void {
29
+ const pending = this.pending.shift();
30
+ if (pending) {
31
+ pending(value);
32
+ return;
33
+ }
34
+ this.queued.push(value);
35
+ }
36
+ }
37
+
38
+ function makeResultMessage() {
39
+ return {
40
+ type: "result",
41
+ subtype: "success",
42
+ is_error: false,
43
+ result: "finished",
44
+ stop_reason: null,
45
+ total_cost_usd: 0,
46
+ usage: {
47
+ input_tokens: 1,
48
+ output_tokens: 1,
49
+ cache_read_input_tokens: 0,
50
+ cache_creation_input_tokens: 0,
51
+ },
52
+ modelUsage: [],
53
+ };
54
+ }
55
+
56
+ function makeIdleMessage() {
57
+ return {
58
+ type: "system",
59
+ subtype: "session_state_changed",
60
+ state: "idle",
61
+ session_id: "session-1",
62
+ };
63
+ }
64
+
65
+ async function flushMicrotasks(): Promise<void> {
66
+ await Promise.resolve();
67
+ await Promise.resolve();
68
+ }
69
+
70
+ describe("patched claude-agent-acp completion", () => {
71
+ it("does not resolve a prompt on idle before the result message", async () => {
72
+ const query = new ManualAsyncIterator();
73
+ const agent = new ClaudeAcpAgent({
74
+ sessionUpdate: vi.fn(),
75
+ extNotification: vi.fn(),
76
+ } as unknown as ConstructorParameters<typeof ClaudeAcpAgent>[0]);
77
+ agent.sessions["session-1"] = {
78
+ cancelled: false,
79
+ accumulatedUsage: {
80
+ inputTokens: 0,
81
+ outputTokens: 0,
82
+ cachedReadTokens: 0,
83
+ cachedWriteTokens: 0,
84
+ },
85
+ contextWindowSize: 200_000,
86
+ cwd: "/tmp",
87
+ emitRawSDKMessages: false,
88
+ input: {
89
+ push: vi.fn(),
90
+ end: vi.fn(),
91
+ },
92
+ nextPendingOrder: 0,
93
+ pendingMessages: new Map(),
94
+ promptRunning: false,
95
+ query,
96
+ settingsManager: {
97
+ dispose: vi.fn(),
98
+ },
99
+ } as unknown as (typeof agent.sessions)[string];
100
+
101
+ let resolved = false;
102
+ const promptPromise = agent
103
+ .prompt({
104
+ sessionId: "session-1",
105
+ prompt: [{ type: "text", text: "do work" }],
106
+ })
107
+ .then((value) => {
108
+ resolved = true;
109
+ return value;
110
+ });
111
+
112
+ query.push(makeIdleMessage());
113
+ await flushMicrotasks();
114
+ expect(resolved).toBe(false);
115
+
116
+ query.push(makeResultMessage());
117
+ await flushMicrotasks();
118
+ expect(resolved).toBe(false);
119
+
120
+ query.push(makeIdleMessage());
121
+ await expect(promptPromise).resolves.toMatchObject({
122
+ stopReason: "end_turn",
123
+ usage: {
124
+ inputTokens: 1,
125
+ outputTokens: 1,
126
+ },
127
+ });
128
+ });
129
+ });