@kodelyth/acpx 2026.5.39

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,6 @@
1
+ export function formatErrorMessage(error) {
2
+ if (error instanceof Error) {
3
+ return error.message || error.name || "Error";
4
+ }
5
+ return String(error);
6
+ }
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "../../../dist/extensions/acpx/index.js";
2
+ import defaultModule from "../../../dist/extensions/acpx/index.js";
3
+ let defaultExport = defaultModule;
4
+ for (let index = 0; index < 4 && defaultExport && typeof defaultExport === "object" && "default" in defaultExport; index += 1) {
5
+ defaultExport = defaultExport.default;
6
+ }
7
+ export { defaultExport as default };
@@ -0,0 +1,189 @@
1
+ {
2
+ "id": "acpx",
3
+ "activation": {
4
+ "onStartup": true
5
+ },
6
+ "enabledByDefault": true,
7
+ "name": "ACPX Runtime",
8
+ "description": "Embedded ACP runtime backend with plugin-owned session and transport management.",
9
+ "skills": [
10
+ "./skills"
11
+ ],
12
+ "configSchema": {
13
+ "type": "object",
14
+ "additionalProperties": false,
15
+ "properties": {
16
+ "cwd": {
17
+ "type": "string",
18
+ "minLength": 1
19
+ },
20
+ "stateDir": {
21
+ "type": "string",
22
+ "minLength": 1
23
+ },
24
+ "probeAgent": {
25
+ "type": "string",
26
+ "minLength": 1
27
+ },
28
+ "permissionMode": {
29
+ "type": "string",
30
+ "enum": [
31
+ "approve-all",
32
+ "approve-reads",
33
+ "deny-all"
34
+ ]
35
+ },
36
+ "nonInteractivePermissions": {
37
+ "type": "string",
38
+ "enum": [
39
+ "deny",
40
+ "fail"
41
+ ]
42
+ },
43
+ "pluginToolsMcpBridge": {
44
+ "type": "boolean"
45
+ },
46
+ "openClawToolsMcpBridge": {
47
+ "type": "boolean"
48
+ },
49
+ "strictWindowsCmdWrapper": {
50
+ "type": "boolean"
51
+ },
52
+ "timeoutSeconds": {
53
+ "type": "number",
54
+ "minimum": 0.001,
55
+ "default": 120
56
+ },
57
+ "queueOwnerTtlSeconds": {
58
+ "type": "number",
59
+ "minimum": 0
60
+ },
61
+ "mcpServers": {
62
+ "type": "object",
63
+ "additionalProperties": {
64
+ "type": "object",
65
+ "properties": {
66
+ "command": {
67
+ "type": "string",
68
+ "minLength": 1,
69
+ "description": "Command to run the MCP server"
70
+ },
71
+ "args": {
72
+ "type": "array",
73
+ "items": {
74
+ "type": "string"
75
+ },
76
+ "description": "Arguments to pass to the command"
77
+ },
78
+ "env": {
79
+ "type": "object",
80
+ "additionalProperties": {
81
+ "type": "string"
82
+ },
83
+ "description": "Environment variables for the MCP server"
84
+ }
85
+ },
86
+ "required": [
87
+ "command"
88
+ ]
89
+ }
90
+ },
91
+ "agents": {
92
+ "type": "object",
93
+ "additionalProperties": {
94
+ "type": "object",
95
+ "properties": {
96
+ "command": {
97
+ "type": "string",
98
+ "minLength": 1
99
+ },
100
+ "args": {
101
+ "type": "array",
102
+ "items": {
103
+ "type": "string"
104
+ }
105
+ }
106
+ },
107
+ "required": [
108
+ "command"
109
+ ]
110
+ }
111
+ }
112
+ }
113
+ },
114
+ "uiHints": {
115
+ "cwd": {
116
+ "label": "Default Working Directory",
117
+ "help": "Default working directory for embedded ACP session operations when not set per session."
118
+ },
119
+ "stateDir": {
120
+ "label": "State Directory",
121
+ "help": "Directory used for embedded ACP session state and persistence."
122
+ },
123
+ "permissionMode": {
124
+ "label": "Permission Mode",
125
+ "help": "Default permission policy for embedded ACP runtime prompts."
126
+ },
127
+ "nonInteractivePermissions": {
128
+ "label": "Non-Interactive Permission Policy",
129
+ "help": "Policy when interactive permission prompts are unavailable."
130
+ },
131
+ "pluginToolsMcpBridge": {
132
+ "label": "Plugin Tools MCP Bridge",
133
+ "help": "Default off. When enabled, inject the built-in Klaw plugin-tools MCP server into embedded ACP sessions so ACP agents can call plugin-registered tools.",
134
+ "advanced": true
135
+ },
136
+ "openClawToolsMcpBridge": {
137
+ "label": "Klaw Tools MCP Bridge",
138
+ "help": "Default off. When enabled, inject the built-in Klaw core-tools MCP server into embedded ACP sessions so ACP agents can call selected built-in tools such as cron.",
139
+ "advanced": true
140
+ },
141
+ "strictWindowsCmdWrapper": {
142
+ "label": "Strict Windows cmd Wrapper",
143
+ "help": "Legacy compatibility field. The current embedded acpx/runtime package uses its own Windows command resolution behavior. Setting this to false is accepted for compatibility and logged as ignored.",
144
+ "advanced": true
145
+ },
146
+ "timeoutSeconds": {
147
+ "label": "Runtime Operation Timeout Seconds",
148
+ "help": "Timeout for embedded ACP runtime startup and control operations. ACP turns use Klaw agent/run timeouts.",
149
+ "advanced": true
150
+ },
151
+ "queueOwnerTtlSeconds": {
152
+ "label": "Queue Owner TTL Seconds",
153
+ "help": "Reserved compatibility field for the older embedded ACPX queue-owner path. Accepted for compatibility and logged as ignored.",
154
+ "advanced": true
155
+ },
156
+ "probeAgent": {
157
+ "label": "Health Probe Agent",
158
+ "help": "Agent id used for the embedded ACP runtime health probe. Defaults to the first `acp.allowedAgents` entry when that allowlist is set, otherwise to the runtime built-in probe agent (codex). Set this explicitly (for example `opencode` or `claude`) when the default probe agent is not installed or not authenticated, so the whole embedded ACP backend does not get marked unavailable.",
159
+ "advanced": true
160
+ },
161
+ "mcpServers": {
162
+ "label": "MCP Servers",
163
+ "help": "Named MCP server definitions to inject into embedded ACP session bootstrap. Each entry needs a command and can include args and env.",
164
+ "advanced": true
165
+ },
166
+ "agents": {
167
+ "label": "Agent Commands",
168
+ "help": "Optional per-agent command overrides for the embedded ACP runtime.",
169
+ "advanced": true
170
+ }
171
+ },
172
+ "configContracts": {
173
+ "dangerousFlags": [
174
+ {
175
+ "path": "permissionMode",
176
+ "equals": "approve-all"
177
+ }
178
+ ],
179
+ "secretInputs": {
180
+ "bundledDefaultEnabled": false,
181
+ "paths": [
182
+ {
183
+ "path": "mcpServers.*.env.*",
184
+ "expected": "string"
185
+ }
186
+ ]
187
+ }
188
+ }
189
+ }
@@ -0,0 +1,123 @@
1
+ const WINDOWS_DIRECT_EXECUTABLE_PATH_RE =
2
+ /^(?<command>(?:[A-Za-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+[\\/]).*?\.(?:exe|com))(?=\s|$)(?:\s+(?<rest>.*))?$/i;
3
+
4
+ // Windows wrapper scripts need their host shell or interpreter (`cmd.exe`,
5
+ // `powershell.exe`, or `node`) instead of direct spawning.
6
+ const WINDOWS_WRAPPER_PATH_RE =
7
+ /^(?:[A-Za-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+[\\/]).*?\.(?:bat|cmd|cjs|js|mjs|ps1)$/i;
8
+
9
+ function splitCommandParts(value, platform = process.platform) {
10
+ const parts = [];
11
+ let current = "";
12
+ let quote = null;
13
+ let escaping = false;
14
+
15
+ for (let index = 0; index < value.length; index += 1) {
16
+ const ch = value[index];
17
+ const next = value[index + 1];
18
+ if (escaping) {
19
+ current += ch;
20
+ escaping = false;
21
+ continue;
22
+ }
23
+ if (ch === "\\") {
24
+ if (quote === "'") {
25
+ current += ch;
26
+ continue;
27
+ }
28
+ if (platform === "win32") {
29
+ if (quote === '"') {
30
+ if (next === '"' || next === "\\") {
31
+ escaping = true;
32
+ continue;
33
+ }
34
+ current += ch;
35
+ continue;
36
+ }
37
+ if (!quote) {
38
+ current += ch;
39
+ continue;
40
+ }
41
+ }
42
+ escaping = true;
43
+ continue;
44
+ }
45
+ if (quote) {
46
+ if (ch === quote) {
47
+ quote = null;
48
+ } else {
49
+ current += ch;
50
+ }
51
+ continue;
52
+ }
53
+ if (ch === "'" || ch === '"') {
54
+ quote = ch;
55
+ continue;
56
+ }
57
+ if (/\s/.test(ch)) {
58
+ if (current.length > 0) {
59
+ parts.push(current);
60
+ current = "";
61
+ }
62
+ continue;
63
+ }
64
+ current += ch;
65
+ }
66
+
67
+ if (escaping) {
68
+ current += "\\";
69
+ }
70
+ if (quote) {
71
+ throw new Error("Invalid agent command: unterminated quote");
72
+ }
73
+ if (current.length > 0) {
74
+ parts.push(current);
75
+ }
76
+ return parts;
77
+ }
78
+
79
+ function splitWindowsExecutableCommand(value, platform = process.platform) {
80
+ if (platform !== "win32") {
81
+ return null;
82
+ }
83
+ const trimmed = value.trim();
84
+ if (!trimmed || trimmed.startsWith('"') || trimmed.startsWith("'")) {
85
+ return null;
86
+ }
87
+ const match = trimmed.match(WINDOWS_DIRECT_EXECUTABLE_PATH_RE);
88
+ if (!match?.groups?.command) {
89
+ return null;
90
+ }
91
+ const rest = match.groups.rest?.trim() ?? "";
92
+ return {
93
+ command: match.groups.command,
94
+ args: rest ? splitCommandParts(rest, platform) : [],
95
+ };
96
+ }
97
+
98
+ function assertSupportedWindowsCommand(command, platform = process.platform) {
99
+ if (platform !== "win32" || !WINDOWS_WRAPPER_PATH_RE.test(command)) {
100
+ return;
101
+ }
102
+ throw new Error(
103
+ `Unsupported Windows agent command wrapper: ${command}. ` +
104
+ "Invoke wrapper scripts through their shell or interpreter instead " +
105
+ "(for example `cmd.exe /c`, `powershell.exe -File`, or `node <script>`).",
106
+ );
107
+ }
108
+
109
+ export function splitCommandLine(value, platform = process.platform) {
110
+ const windowsCommand = splitWindowsExecutableCommand(value, platform);
111
+ const parts = windowsCommand ?? splitCommandParts(value, platform);
112
+ if (parts.length === 0) {
113
+ throw new Error("Invalid agent command: empty command");
114
+ }
115
+ const parsed = Array.isArray(parts)
116
+ ? {
117
+ command: parts[0],
118
+ args: parts.slice(1),
119
+ }
120
+ : parts;
121
+ assertSupportedWindowsCommand(parsed.command, platform);
122
+ return parsed;
123
+ }
package/mcp-proxy.mjs ADDED
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import path from "node:path";
5
+ import { createInterface } from "node:readline";
6
+ import { pathToFileURL } from "node:url";
7
+ import { formatErrorMessage } from "./error-format.mjs";
8
+ import { splitCommandLine } from "./mcp-command-line.mjs";
9
+
10
+ function decodePayload(argv) {
11
+ const payloadIndex = argv.indexOf("--payload");
12
+ if (payloadIndex < 0) {
13
+ throw new Error("Missing --payload");
14
+ }
15
+ const encoded = argv[payloadIndex + 1];
16
+ if (!encoded) {
17
+ throw new Error("Missing MCP proxy payload value");
18
+ }
19
+ const parsed = JSON.parse(Buffer.from(encoded, "base64url").toString("utf8"));
20
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
21
+ throw new Error("Invalid MCP proxy payload");
22
+ }
23
+ if (typeof parsed.targetCommand !== "string" || parsed.targetCommand.trim() === "") {
24
+ throw new Error("MCP proxy payload missing targetCommand");
25
+ }
26
+ const mcpServers = Array.isArray(parsed.mcpServers) ? parsed.mcpServers : [];
27
+ return {
28
+ targetCommand: parsed.targetCommand,
29
+ mcpServers,
30
+ };
31
+ }
32
+
33
+ function shouldInject(method) {
34
+ return method === "session/new" || method === "session/load" || method === "session/fork";
35
+ }
36
+
37
+ function rewriteLine(line, mcpServers) {
38
+ if (!line.trim()) {
39
+ return line;
40
+ }
41
+ try {
42
+ const parsed = JSON.parse(line);
43
+ if (
44
+ !parsed ||
45
+ typeof parsed !== "object" ||
46
+ Array.isArray(parsed) ||
47
+ !shouldInject(parsed.method) ||
48
+ !parsed.params ||
49
+ typeof parsed.params !== "object" ||
50
+ Array.isArray(parsed.params)
51
+ ) {
52
+ return line;
53
+ }
54
+ const next = {
55
+ ...parsed,
56
+ params: {
57
+ ...parsed.params,
58
+ mcpServers,
59
+ },
60
+ };
61
+ return JSON.stringify(next);
62
+ } catch {
63
+ return line;
64
+ }
65
+ }
66
+
67
+ export function createTargetSpawnOptions(platform = process.platform) {
68
+ const options = {
69
+ stdio: ["pipe", "pipe", "inherit"],
70
+ env: process.env,
71
+ };
72
+ if (platform === "win32") {
73
+ options.windowsHide = true;
74
+ }
75
+ return options;
76
+ }
77
+
78
+ function isMainModule() {
79
+ const mainPath = process.argv[1];
80
+ if (!mainPath) {
81
+ return false;
82
+ }
83
+ return import.meta.url === pathToFileURL(path.resolve(mainPath)).href;
84
+ }
85
+
86
+ function main() {
87
+ const { targetCommand, mcpServers } = decodePayload(process.argv.slice(2));
88
+ const target = splitCommandLine(targetCommand);
89
+ const child = spawn(target.command, target.args, createTargetSpawnOptions());
90
+
91
+ if (!child.stdin || !child.stdout) {
92
+ throw new Error("Failed to create MCP proxy stdio pipes");
93
+ }
94
+
95
+ const input = createInterface({ input: process.stdin });
96
+ input.on("line", (line) => {
97
+ child.stdin.write(`${rewriteLine(line, mcpServers)}\n`);
98
+ });
99
+ input.on("close", () => {
100
+ child.stdin.end();
101
+ });
102
+
103
+ child.stdout.pipe(process.stdout);
104
+
105
+ child.on("error", (error) => {
106
+ process.stderr.write(`${formatErrorMessage(error)}\n`);
107
+ process.exit(1);
108
+ });
109
+
110
+ child.on("close", (code, signal) => {
111
+ if (signal) {
112
+ process.kill(process.pid, signal);
113
+ return;
114
+ }
115
+ process.exit(code ?? 0);
116
+ });
117
+ }
118
+
119
+ if (isMainModule()) {
120
+ main();
121
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@kodelyth/acpx",
3
+ "version": "2026.5.39",
4
+ "description": "Klaw ACP runtime backend",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/kodelyth/klaw"
8
+ },
9
+ "type": "module",
10
+ "dependencies": {
11
+ "@agentclientprotocol/claude-agent-acp": "0.33.1",
12
+ "@zed-industries/codex-acp": "0.14.0",
13
+ "acpx": "0.7.0",
14
+ "zod": "4.4.3"
15
+ },
16
+ "devDependencies": {
17
+ "@kodelyth/plugin-sdk": "1.0.1"
18
+ },
19
+ "klaw": {
20
+ "extensions": [
21
+ "./index.js"
22
+ ],
23
+ "install": {
24
+ "npmSpec": "@kodelyth/acpx",
25
+ "defaultChoice": "npm",
26
+ "minHostVersion": ">=2026.4.25"
27
+ },
28
+ "compat": {
29
+ "pluginApi": ">=2026.5.39"
30
+ },
31
+ "build": {
32
+ "klawVersion": "2026.5.39",
33
+ "staticAssets": [
34
+ {
35
+ "source": "./src/runtime-internals/mcp-proxy.mjs",
36
+ "output": "mcp-proxy.mjs"
37
+ },
38
+ {
39
+ "source": "./src/runtime-internals/error-format.mjs",
40
+ "output": "error-format.mjs"
41
+ },
42
+ {
43
+ "source": "./src/runtime-internals/mcp-command-line.mjs",
44
+ "output": "mcp-command-line.mjs"
45
+ }
46
+ ]
47
+ },
48
+ "release": {
49
+ "publishToClawHub": true,
50
+ "publishToNpm": true
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,7 @@
1
+ export * from "../../../dist/extensions/acpx/register.runtime.js";
2
+ import * as module from "../../../dist/extensions/acpx/register.runtime.js";
3
+ let defaultExport = "default" in module ? module.default : module;
4
+ for (let index = 0; index < 4 && defaultExport && typeof defaultExport === "object" && "default" in defaultExport; index += 1) {
5
+ defaultExport = defaultExport.default;
6
+ }
7
+ export { defaultExport as default };
package/runtime-api.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "../../../dist/extensions/acpx/runtime-api.js";
2
+ import * as module from "../../../dist/extensions/acpx/runtime-api.js";
3
+ let defaultExport = "default" in module ? module.default : module;
4
+ for (let index = 0; index < 4 && defaultExport && typeof defaultExport === "object" && "default" in defaultExport; index += 1) {
5
+ defaultExport = defaultExport.default;
6
+ }
7
+ export { defaultExport as default };
package/setup-api.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "../../../dist/extensions/acpx/setup-api.js";
2
+ import defaultModule from "../../../dist/extensions/acpx/setup-api.js";
3
+ let defaultExport = defaultModule;
4
+ for (let index = 0; index < 4 && defaultExport && typeof defaultExport === "object" && "default" in defaultExport; index += 1) {
5
+ defaultExport = defaultExport.default;
6
+ }
7
+ export { defaultExport as default };
@@ -0,0 +1,248 @@
1
+ ---
2
+ name: acp-router
3
+ description: Route plain-language requests for Pi, Claude Code, Cursor, Copilot, Klaw ACP, OpenCode, Gemini CLI, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either Klaw 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/Klaw/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 Klaw to:
16
+
17
+ - run something in Pi / Claude Code / Cursor / Copilot / Klaw / 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 `Klaw 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. Klaw 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 Klaw 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
+ - "klaw" -> `agentId: "klaw"`
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
+ ## Klaw 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 `@klaw/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
+ - `klaw`
205
+ - `opencode`
206
+ - `pi`
207
+ - `qwen`
208
+
209
+ ### Built-in adapter commands in acpx
210
+
211
+ Defaults are:
212
+
213
+ - `klaw -> klaw acp`
214
+ - `claude -> bundled @agentclientprotocol/claude-agent-acp@0.32.0`
215
+ - `codex -> bundled @zed-industries/codex-acp@0.13.0 through Klaw'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.