opencode-acp-provider 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Armedi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,358 @@
1
- # Temporary Holding Version
1
+ # opencode-acp-provider
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An OpenCode plugin that makes OpenCode an **Agent Client Protocol (ACP) client**. It starts ACP
4
+ agents such as [`claude-agent-acp`](https://github.com/agentclientprotocol/claude-agent-acp) over
5
+ stdio and registers each as a provider, so selecting one of its models routes the turn to that agent,
6
+ which runs with its own harness and tools while OpenCode provides the session, history, and UI.
7
+
8
+ ```text
9
+ OpenCode session ──▶ ACP language model ──▶ chat shim ──▶ ACP client (JSON-RPC/stdio) ──▶ claude-agent-acp
10
+ ```
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ opencode plugin add opencode-acp-provider
16
+ ```
17
+
18
+ Or configure it directly:
19
+
20
+ ```jsonc
21
+ {
22
+ "$schema": "https://opencode.ai/config.json",
23
+ "plugins": [
24
+ {
25
+ "package": "opencode-acp-provider",
26
+ "options": {
27
+ "logLevel": "info",
28
+ "servers": [
29
+ {
30
+ "id": "claude",
31
+ "name": "Claude Code (ACP)",
32
+ "command": ["claude-agent-acp"],
33
+ "model": "sonnet"
34
+ }
35
+ ]
36
+ }
37
+ }
38
+ ]
39
+ }
40
+ ```
41
+
42
+ `opencode reload`, then `opencode models | grep '^acp-'` should list `acp-claude/sonnet`. Run a turn
43
+ with `opencode run -m acp-claude/sonnet "..."`; add `#high` to pick a reasoning effort.
44
+
45
+ ## setup
46
+
47
+ A server runs one shell command before its agent is first spawned. It is not specific to
48
+ installation: use it to install or update the agent, log in, prepare a config, or seed files. It runs
49
+ once per OpenCode server process; every location (including each worktree) and `opencode reload`
50
+ reuses the run, and a server restart runs it again.
51
+
52
+ ```jsonc
53
+ {
54
+ "servers": [
55
+ { "id": "cmd", "setup": "vp add -g command-code@latest", "command": ["cmd", "acp"] },
56
+ {
57
+ "id": "claude",
58
+ "setup": "vp add -g @agentclientprotocol/claude-agent-acp@latest && claude update",
59
+ "command": ["claude-agent-acp"]
60
+ },
61
+ {
62
+ "id": "codex",
63
+ "setup": "vp add -g @agentclientprotocol/codex-acp@latest && codex update",
64
+ "command": ["codex-acp"]
65
+ },
66
+ // any command works, e.g. preparing a config file the agent reads at startup
67
+ {
68
+ "id": "agy",
69
+ "setup": "mkdir -p ~/.config/agy && cp ./agy.json ~/.config/agy/config.json",
70
+ "command": ["agy", "acp"]
71
+ }
72
+ ]
73
+ }
74
+ ```
75
+
76
+ - Runs through `sh -c` in the home directory with OpenCode's environment.
77
+ - Identical commands share one run across the whole server process, even across locations; different
78
+ commands run in parallel.
79
+ - A failure (non-zero exit, signal, or a timeout after five minutes) is logged with the end of its
80
+ output and the agent still starts, so the command is never a hard dependency and an offline start
81
+ works.
82
+ - Not counted against `initTimeoutMs`. Pin a version with `command-code@0.6.0` instead of `@latest`.
83
+ - An installed program must land on the `PATH` OpenCode inherits. A desktop app launched from the GUI
84
+ may not see the shell's `PATH`; use an absolute path in `command` then.
85
+
86
+ ## Agents
87
+
88
+ Tested with the plugin. Each needs its launch command plus the agent-specific setting below; every
89
+ other section applies to all of them. Disabling an agent's own subagent and ask-user tools routes
90
+ delegation and questions through the MCP bridge instead of a second hidden agent loop.
91
+
92
+ | Server | Command | Auth | Native orchestration tools |
93
+ | --- | --- | --- | --- |
94
+ | Claude Code (`claude`) | `["claude-agent-acp"]` | adapter's own login | `meta.claudeCode.options.disallowedTools` |
95
+ | Codex (`codex`) | `["codex-acp"]` | adapter's own login | `CODEX_CONFIG` env |
96
+ | Antigravity (`agy`) | `["agy", "acp"]` | `agy acp --login` or `GEMINI_API_KEY` | `PreToolUse` hook |
97
+ | Command Code (`cmd`) | `["cmd", "acp"]` | sign in with `cmd` itself | companion mod (automatic) |
98
+
99
+ ### Claude Code (`claude`)
100
+
101
+ ```jsonc
102
+ {
103
+ "id": "claude",
104
+ "command": ["claude-agent-acp"],
105
+ "meta": { "claudeCode": { "options": { "disallowedTools": ["Task", "AskUserQuestion"] } } }
106
+ }
107
+ ```
108
+
109
+ The adapter accepts injected HTTP MCP servers, so `mcpTransport: "http"` works.
110
+
111
+ ### Codex (`codex`)
112
+
113
+ ```jsonc
114
+ {
115
+ "id": "codex",
116
+ "command": ["codex-acp"],
117
+ "env": {
118
+ "CODEX_CONFIG": "{\"agents\":{\"enabled\":false},\"tools\":{\"experimental_request_user_input\":{\"enabled\":false}}}"
119
+ }
120
+ }
121
+ ```
122
+
123
+ Codex drops injected HTTP MCP servers, so keep the stdio transport. It does not advertise `/compact`,
124
+ so a manual `/compact` reports that it cannot compact on request.
125
+
126
+ ### Antigravity (`agy`)
127
+
128
+ Ships its own ACP stdio server, so it needs no adapter package:
129
+
130
+ ```jsonc
131
+ {
132
+ "servers": [{ "id": "agy", "setup": "agy update", "command": ["agy", "acp"] }]
133
+ }
134
+ ```
135
+
136
+ - **Model ids.** The session's `model` select lists base ids without the thinking level, while
137
+ `agy models` appends it (`<model>-high`). Use the base ids the selector lists.
138
+ - **Reasoning effort.** Effort is not part of the model id: its `thought_level` select (`low`,
139
+ `medium`, `high`) becomes the model variants, so `acp-agy/<base-id>#high` sets it. There is no
140
+ `off` variant.
141
+ - **Mode.** Its `mode` select (`default`, `accept-edits`, `auto`, `plan`) is not a variant; pin it
142
+ with the server's `mode` option. Permission requests in `default` mode go through `autoApprove`.
143
+ - **Native tools.** `agy` keeps `ask_question` plus its own subagent family (`invoke_subagent`,
144
+ `define_subagent`, `manage_subagents`, `swarm`, `run_workflow`). ACP has no question method, so
145
+ `ask_question` prints the question into the turn and ends, which looks like a stalled prompt. Its
146
+ `permissions` block cannot gate these (it covers only `read_file`, `write_file`, `read_url`,
147
+ `execute_url`, `command`, and `mcp`), so deny them by tool name in `~/.gemini/config/hooks.json`
148
+ (every workspace) or `<workspace>/.agents/hooks.json`:
149
+
150
+ ```json
151
+ {
152
+ "opencode-orchestration": {
153
+ "PreToolUse": [
154
+ {
155
+ "matcher": "ask_question|invoke_subagent|define_subagent|manage_subagents|swarm|run_workflow",
156
+ "hooks": [
157
+ {
158
+ "command": "echo '{\"decision\":\"deny\",\"reason\":\"Use the OpenCode question and subagent tools instead.\"}'"
159
+ }
160
+ ]
161
+ }
162
+ ]
163
+ }
164
+ }
165
+ ```
166
+
167
+ ### Command Code (`cmd`)
168
+
169
+ ```jsonc
170
+ { "id": "cmd", "name": "Command Code (ACP)", "command": ["cmd", "acp"] }
171
+ ```
172
+
173
+ - **Auth.** Sign in with `cmd` itself; the plugin injects no credential. Use `env` to pass a key the
174
+ agent reads, e.g. `{ "COMMAND_CODE_API_KEY": "..." }`.
175
+ - **Skills and native tools.** Handled by companion mods, automatically: `cmd` ignores ACP
176
+ `additionalDirectories` and never applies the global `--skill` flag, and its docs mark `agent` as
177
+ always allowed so `permissions.deny` cannot block it. With the MCP bridge on, the plugin appends
178
+ `--mod` for [`no-native-orchestration.ts`](src/agents/cmd/mods/no-native-orchestration.ts) and
179
+ [`opencode-skills.ts`](src/agents/cmd/mods/opencode-skills.ts), resolved from its own install
180
+ location; `--safe-mode` disables all mods. The server entry needs no `--mod` and other `cmd` mods
181
+ keep their tools. Verify by asking the agent to call its `agent` tool: it should report the tool as
182
+ unavailable instead of delegating.
183
+ - **Runtime.** A launch such as
184
+ `["bun", "/absolute/path/to/node_modules/command-code/dist/index.mjs", "acp"]` is recognized and
185
+ keeps skill injection; use it if the agent repeatedly exits with native signals such as `SIGSEGV`.
186
+
187
+ Agent-specific code and companion files live under [`src/agents/`](src/agents/README.md).
188
+
189
+ ## Delegating to an ACP agent
190
+
191
+ The plugin adds no tools and needs no agent config. The builtin `subagent` tool takes an optional
192
+ `model` override, so a parent model can dispatch straight to an ACP model:
193
+
194
+ - `agent`: any subagent type, e.g. `general`, supplying the child session's agent config.
195
+ - `model`: `acp-claude/sonnet`, or `.../#high` to pin an effort. It is in the normal model list, so
196
+ the `models` tool can resolve it.
197
+
198
+ Each dispatch gets its own OpenCode session, hence its own ACP session and context. Optionally give it
199
+ a dedicated subagent name, after which the parent passes `agent: "claude"` and omits `model`:
200
+
201
+ ```jsonc
202
+ {
203
+ "agents": {
204
+ "claude": {
205
+ "description": "Delegate a self-contained task to the Claude Code ACP agent.",
206
+ "mode": "subagent",
207
+ "model": "acp-claude/sonnet"
208
+ }
209
+ }
210
+ }
211
+ ```
212
+
213
+ ## OpenCode tools inside ACP agents
214
+
215
+ ACP agents keep their own tools; what they lack is OpenCode's orchestration and UI layer. The plugin
216
+ serves that layer from a loopback MCP endpoint, passed to the agent in `session/new`, with one bearer
217
+ token per ACP session. Every tool is a 1:1 wrapper:
218
+
219
+ | Tool | Wraps |
220
+ | --- | --- |
221
+ | `models` | OpenCode's `models` tool (search, variants, pagination) |
222
+ | `subagent` | builtin `subagent` (native child session; async with native `<subagent>` wake) |
223
+ | `question` | builtin `question` (native session form) |
224
+ | `todowrite` | builtin `todowrite` (only with `experimental.todo`) |
225
+ | `session_create` | `session.create`, then `session.prompt` when `prompt` is set (independent top-level session) |
226
+ | `session_list` | `session.list` |
227
+ | `session_get` | `session.get` (defaults to the calling session) |
228
+ | `session_prompt` | `session.prompt` (`delivery: "steer"` joins a running turn; `"queue"` follows up) |
229
+ | `session_context` | `session.context` (defaults to the calling session; bounded to recent items) |
230
+ | `session_wait` | `session.wait` (timeout does not cancel the session) |
231
+ | `session_interrupt` | `session.interrupt` |
232
+
233
+ The wrapped builtins (`subagent`, `question`, `todowrite`) assert their own permissions. The
234
+ `session_*` tools are normally client-only, so they assert a `session` permission on the target id:
235
+ reads default to the calling session, while reading another session, `session_wait`, `session_prompt`,
236
+ and `session_interrupt` need permission for that id, and `session_list` and `session_create` assert
237
+ resource `*`:
238
+
239
+ ```jsonc
240
+ { "action": "session", "resource": "*", "effect": "allow" }
241
+ ```
242
+
243
+ MCP transport defaults to stdio, which runs `mcp-bridge.mjs` with `node` from `PATH`; set
244
+ `mcpRuntime` for another runtime, or `mcpTransport: "http"` for an agent that accepts injected HTTP
245
+ servers.
246
+
247
+ ## Skills
248
+
249
+ OpenCode registers skills in its own registry, out of reach of the ACP agent. Rather than bridging
250
+ OpenCode's `skill` tool, the plugin copies the usable skills into a temp directory and passes it to
251
+ the agent in `session/new`'s `additionalDirectories`, so each agent reads them with its own loader:
252
+
253
+ ```text
254
+ <tmp>/opencode-acp-provider-skills-*/
255
+ ├── .agents/skills/<id>/SKILL.md # Codex, Antigravity, other .agents-compatible agents
256
+ └── .claude/skills/<id>/SKILL.md # Claude Code
257
+ ```
258
+
259
+ Skills already living in `.agents/skills` or `.claude/skills` belong to the agents and stay put.
260
+ Skipped: no description, `opencode/autoinvoke: false`, or an ID not portable lowercase kebab-case.
261
+ `"skills": false` opts a server out; `{ "skills": ["opencode"] }` allowlists specific IDs.
262
+
263
+ `cmd` ignores `additionalDirectories` and never applies `--skill` on the ACP path, so a companion mod
264
+ registers the directory itself; an explicit `--skill`, `--no-skills`, or `--safe-mode` wins. Native
265
+ delivery runs no per-agent `skill` permission check, so a skill OpenCode hides from the current agent
266
+ can still reach the ACP agent: use `permissions` on the agent, `"skills": false`, or
267
+ `autoinvoke: false` where that matters. The mirror is rebuilt on plugin setup, so skills edited while
268
+ OpenCode stays open reach the agent after a reload.
269
+
270
+ ## Commands
271
+
272
+ Agents advertise slash commands via `session/update → available_commands_update`; the plugin registers
273
+ them in OpenCode's palette namespaced by server id, because a command belongs to the agent, not to one
274
+ of its models:
275
+
276
+ ```text
277
+ /claude:code-review Review the current diff, or a PR number/branch/path target…
278
+ /cmd:peek Peek recap diagram: draw one for the last task now, or turn it on or off
279
+ /codex:review Review the current diff
280
+ /agy:compact Compact the conversation now (summarize history to free up the context window)
281
+ ```
282
+
283
+ Arguments pass through verbatim: `/claude:code-review 123 --fix` sends `/code-review 123 --fix` as
284
+ the turn's prompt. Skills are skipped, since agents raise their own skills as commands and forwarding
285
+ them would duplicate every OpenCode skill. A command list is per location, not per model, so all
286
+ agents' commands are visible at once; running one on the wrong provider fails with a message naming
287
+ the agent to switch to. Set `"commands": false` to turn this off.
288
+
289
+ ## Server options
290
+
291
+ | Option | Type | Meaning |
292
+ | --- | --- | --- |
293
+ | `id` | `string` | Required. Stable id. Becomes the provider id `acp-<id>`. |
294
+ | `name` | `string` | Provider display name. Defaults to `<id> (ACP)`. |
295
+ | `command` | `string \| string[]` | Required. Command that starts the ACP agent, e.g. `["cmd", "acp"]`. |
296
+ | `setup` | `string` | Shell command run once before the agent is first spawned. See [setup](#setup). |
297
+ | `cwd` | `string` | Agent working directory. Defaults to the OpenCode location. |
298
+ | `env` | `object` | Extra environment variables for the agent process, including any API key the agent reads. |
299
+ | `models` | `string[]` | Optional allowlist of model ids to expose. An agent without a model selector only exposes `default`. |
300
+ | `model` | `string` | Default ACP model for the server. If the agent has no ACP model selector, omit this or use `default`. |
301
+ | `effort` | `string` | Default ACP reasoning effort for sessions without a `#variant`. `cmd` accepts `off`, `low`, `high`, `max`, or `default`. Lower is faster; `off` disables thinking. Per-model variants override this. |
302
+ | `mode` | `string` | ACP session mode applied to pooled sessions, e.g. `auto-accept` or `plan`. |
303
+ | `meta` | `object` | ACP `_meta` passed to `session/new`. Claude Code reads `meta.claudeCode.options`. |
304
+ | `autoApprove` | `boolean` | Auto-approve `session/request_permission` requests. Defaults to `true`. When `false`, each request goes through OpenCode's permission prompt (action `acp_tool`) and requests without an OpenCode session are denied. A question encoded as a permission request is never auto-approved and is declined instead. |
305
+ | `skills` | `boolean` | Expose OpenCode's skills through this agent's native skill discovery. Defaults to `true`. See [Skills](#skills). |
306
+ | `disabled` | `boolean` | Skip the server without deleting its configuration. |
307
+
308
+ ## Plugin options
309
+
310
+ | Option | Meaning |
311
+ | --- | --- |
312
+ | `logLevel` | `debug`, `info` (default), `warn`, or `error`. Debug logs also go to `$OPENCODE_ACP_PROVIDER_LOG` (default `opencode-acp-provider-<uid>.log` in the OS temp directory, truncated at 10 MB). |
313
+ | `includeSystem` | Include OpenCode's system message in the ACP prompt. Defaults to `false`; the agent uses its own instructions. |
314
+ | `historyTurns` | Turns of history replayed into a brand new ACP session. Defaults to `16`. |
315
+ | `historyChars` | Characters of history replayed into a brand new ACP session. Defaults to `8192`. Also caps the recent conversation a `/compact` summary keeps. |
316
+ | `maxSessions` | Pooled ACP sessions per location, including opening ones. Defaults to `32`. At capacity the least recently used idle session closes; if none is idle, a new conversation retries after a turn finishes. |
317
+ | `sessionIdleMs` | Idle time before a reused session closes. Defaults to `1800000` (30 minutes); `0` disables the sweep. |
318
+ | `allowPathsOutsideCwd` | Allow the agent's `fs/read_text_file` and `fs/write_text_file` outside the session directory. Defaults to `false`. |
319
+ | `maxFileBytes` | Largest file the client reads for the agent. Defaults to `16777216` (16 MB). |
320
+ | `maxBodyBytes` | Largest chat-completions body the shim accepts. Defaults to `33554432` (32 MB). |
321
+ | `outputLimit` | Output limit advertised for ACP models. Defaults to `32000`. |
322
+ | `initTimeoutMs` | How long one agent may take to initialize. Defaults to `20000`; a failed server is retried in the background under the same bound. |
323
+ | `requestTimeoutMs` | Timeout for the ACP handshake and control calls such as `session/new`. Defaults to `15000`; raise it for agents that start slowly. |
324
+ | `promptTimeoutMs` | How long one ACP turn may run. Defaults to `1800000` (30 minutes); `0` disables the cap. |
325
+ | `toolCallDisplay` | `inline` (default) shows finished ACP tool calls as transcript lines; `off` hides them. |
326
+ | `mcp` | Expose OpenCode tools to ACP agents through the MCP bridge. Defaults to `true`. |
327
+ | `commands` | Register the agents' own slash commands as namespaced OpenCode commands. Defaults to `true`. See [Commands](#commands). |
328
+ | `skills` | Mirror OpenCode's skills into the agents' native skill discovery. Defaults to `true`; `false` disables it, and an array such as `["opencode"]` is an allowlist. |
329
+ | `mcpTransport` | `stdio` (default) or `http`. Use `http` only for an agent that accepts injected HTTP MCP servers. |
330
+ | `mcpRuntime` | Runtime that executes the stdio bridge, e.g. `bun`. Defaults to `node` from `PATH`. |
331
+
332
+ ## MCP sign-ins
333
+
334
+ Each agent signs in on its own; the plugin holds no credentials for it. To pass an agent a key, set
335
+ it in that server's `env`.
336
+
337
+ Remote MCP servers configured in OpenCode are forwarded to every ACP agent. When OpenCode holds an
338
+ OAuth sign-in for one, the plugin resolves the active grant and passes it as an `Authorization:
339
+ Bearer` header on `session/new`, so the agent reuses the same login, refreshing an expired grant as it
340
+ resolves. A header set explicitly in the server's `headers` wins. A server not signed in to OpenCode
341
+ still starts but keeps its tools unavailable; run `opencode mcp auth <name>` (or sign in through the
342
+ agent's own CLI) and the next session picks the credential up. ACP cannot update headers on a live
343
+ session, so a grant that expires mid-session is not replaced until that session is recycled or a new
344
+ conversation starts.
345
+
346
+ ## Limits
347
+
348
+ - Text-only prompt content; images and resource blocks are not forwarded yet.
349
+ - ACP's `authenticate` method (OAuth-style sign-in) is unsupported, so an agent must be signed in
350
+ before OpenCode starts it (e.g. its own `--login`, or a key in `env`).
351
+ - MCP subagents are bounded by OpenCode's `experimental.subagent_depth` (default `1`); raise it for
352
+ deeper delegation.
353
+ - `session_context` returns up to roughly 60k characters; `session_wait` defaults to 45s and caps at
354
+ 120s.
355
+ - ACP models advertise an unknown context window, so OpenCode never auto-compacts them; each agent
356
+ compacts its own reused session. A manual `/compact` never runs OpenCode's summary turn.
357
+ - No token usage is reported and models register with an empty cost list, so OpenCode shows no
358
+ pricing or spend for them.
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "opencode-acp-provider",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "OpenCode plugin that acts as an Agent Client Protocol (ACP) client and exposes registered ACP agents as model providers.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.ts"
8
+ },
9
+ "files": [
10
+ "src",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/armedi/opencode-acp-provider.git"
17
+ },
18
+ "homepage": "https://github.com/armedi/opencode-acp-provider#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/armedi/opencode-acp-provider/issues"
21
+ },
22
+ "author": "Armedi",
23
+ "scripts": {
24
+ "typecheck": "tsc --noEmit",
25
+ "test": "bun test"
26
+ },
27
+ "engines": {
28
+ "node": ">=24"
29
+ },
30
+ "dependencies": {
31
+ "@opencode/plugin": "latest"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^26.0.0",
35
+ "typescript": "^5.9.3"
36
+ },
37
+ "keywords": [
38
+ "opencode",
39
+ "acp",
40
+ "agent-client-protocol"
41
+ ],
42
+ "license": "MIT"
43
+ }