opencode-acp-provider 1.1.0 → 1.1.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.
- package/README.md +27 -19
- package/package.json +3 -2
- package/src/acp-client.ts +67 -4
- package/src/acp-tools/antigravity.ts +117 -0
- package/src/acp-tools/claude.ts +105 -0
- package/src/acp-tools/codex.ts +204 -0
- package/src/acp-tools/command-code.ts +135 -0
- package/src/acp-tools/fallback.ts +92 -0
- package/src/acp-tools/shared.ts +436 -0
- package/src/acp-tools.ts +119 -241
- package/src/agent-command.ts +1 -1
- package/src/agent-pool.ts +5 -1
- package/src/index.ts +132 -47
- package/src/inventory.ts +14 -0
- package/src/language-model.ts +27 -13
- package/src/mcp-server.ts +73 -55
- package/src/prompt.ts +22 -5
- package/src/server-manager.ts +517 -74
- package/src/shim.ts +75 -35
- package/src/unsolicited.ts +388 -0
- package/src/mcp-config.ts +0 -198
package/README.md
CHANGED
|
@@ -66,8 +66,8 @@ reuses the run, and a server restart runs it again.
|
|
|
66
66
|
// any command works, e.g. preparing a config file the agent reads at startup
|
|
67
67
|
{
|
|
68
68
|
"id": "agy",
|
|
69
|
-
"setup": "mkdir -p ~/.config
|
|
70
|
-
"command": ["agy", "acp"]
|
|
69
|
+
"setup": "mkdir -p ~/.gemini/config && cp ./agy-hooks.json ~/.gemini/config/hooks.json",
|
|
70
|
+
"command": ["agy", "acp", "--process-per-session"]
|
|
71
71
|
}
|
|
72
72
|
]
|
|
73
73
|
}
|
|
@@ -93,7 +93,7 @@ delegation and questions through the MCP bridge instead of a second hidden agent
|
|
|
93
93
|
| --- | --- | --- | --- |
|
|
94
94
|
| Claude Code (`claude`) | `["claude-agent-acp"]` | adapter's own login | `meta.claudeCode.options.disallowedTools` |
|
|
95
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 |
|
|
96
|
+
| Antigravity (`agy`) | `["agy", "acp", "--process-per-session"]` | `agy acp --login` or `GEMINI_API_KEY` | `PreToolUse` hook |
|
|
97
97
|
| Command Code (`cmd`) | `["cmd", "acp"]` | sign in with `cmd` itself | companion mod (automatic) |
|
|
98
98
|
|
|
99
99
|
### Claude Code (`claude`)
|
|
@@ -129,15 +129,21 @@ Ships its own ACP stdio server, so it needs no adapter package:
|
|
|
129
129
|
|
|
130
130
|
```jsonc
|
|
131
131
|
{
|
|
132
|
-
"servers": [{ "id": "agy", "setup": "agy update", "command": ["agy", "acp"] }]
|
|
132
|
+
"servers": [{ "id": "agy", "setup": "agy update", "command": ["agy", "acp", "--process-per-session"] }]
|
|
133
133
|
}
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
+
- **Session isolation.** `--process-per-session` isolates each session's worker process so the
|
|
137
|
+
`opencode` MCP server keeps its name across sessions (and is required for injected HTTP MCP
|
|
138
|
+
servers).
|
|
139
|
+
|
|
136
140
|
- **Model ids.** The session's `model` select lists base ids without the thinking level, while
|
|
137
141
|
`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
|
|
139
|
-
|
|
140
|
-
`
|
|
142
|
+
- **Reasoning effort.** Effort is not part of the model id: its `thought_level` select becomes the
|
|
143
|
+
model variants, so `acp-agy/<base-id>#high` sets it. The levels differ per model (some add
|
|
144
|
+
`xhigh`), and the orchestrator models offer none, so they show no variants and no effort is
|
|
145
|
+
sent. A model's own levels replace the default model's list once it is first selected, and are
|
|
146
|
+
cached. There is no `off` variant.
|
|
141
147
|
- **Mode.** Its `mode` select (`default`, `accept-edits`, `auto`, `plan`) is not a variant; pin it
|
|
142
148
|
with the server's `mode` option. Permission requests in `default` mode go through `autoApprove`.
|
|
143
149
|
- **Native tools.** `agy` keeps `ask_question` plus its own subagent family (`invoke_subagent`,
|
|
@@ -220,6 +226,7 @@ token per ACP session. Every tool is a 1:1 wrapper:
|
|
|
220
226
|
| --- | --- |
|
|
221
227
|
| `models` | OpenCode's `models` tool (search, variants, pagination) |
|
|
222
228
|
| `subagent` | builtin `subagent` (native child session; async with native `<subagent>` wake) |
|
|
229
|
+
| `subagent_list` | List available OpenCode subagents with IDs and descriptions on demand |
|
|
223
230
|
| `question` | builtin `question` (native session form) |
|
|
224
231
|
| `todowrite` | builtin `todowrite` (only with `experimental.todo`) |
|
|
225
232
|
| `session_create` | `session.create`, then `session.prompt` when `prompt` is set (independent top-level session) |
|
|
@@ -266,7 +273,7 @@ the agent in `session/new`'s `additionalDirectories`, so each agent reads them w
|
|
|
266
273
|
|
|
267
274
|
Skills already living in `.agents/skills` or `.claude/skills` belong to the agents and stay put.
|
|
268
275
|
Skipped: no description, `opencode/autoinvoke: false`, or an ID not portable lowercase kebab-case.
|
|
269
|
-
`"skills": false`
|
|
276
|
+
`"skills": false` on a server entry opts that server out; `"skills": ["opencode"]` at the plugin level allowlists specific skill IDs.
|
|
270
277
|
|
|
271
278
|
`cmd` ignores `additionalDirectories` and never applies `--skill` on the ACP path, so a companion mod
|
|
272
279
|
registers the directory itself; an explicit `--skill`, `--no-skills`, or `--safe-mode` wins. Native
|
|
@@ -308,6 +315,10 @@ plugin keeps one pre-started spare `cmd` process (about 180 MB) that the next ne
|
|
|
308
315
|
skipping its ~3 s startup, with its skills linked in on adoption. Set `"share": false` for other
|
|
309
316
|
agents that serve one directory per process.
|
|
310
317
|
|
|
318
|
+
Model discovery runs once per agent configuration per OpenCode service process. Per-model
|
|
319
|
+
variants are learned on first selection and shared across locations and plugin reloads.
|
|
320
|
+
Restarting the service refreshes discovery. Slash commands are still discovered per location.
|
|
321
|
+
|
|
311
322
|
## Server options
|
|
312
323
|
|
|
313
324
|
| Option | Type | Meaning |
|
|
@@ -333,7 +344,7 @@ agents that serve one directory per process.
|
|
|
333
344
|
| Option | Meaning |
|
|
334
345
|
| --- | --- |
|
|
335
346
|
| `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). |
|
|
336
|
-
| `includeSystem` | Include OpenCode's system message in the ACP prompt. Defaults to `false`; the agent uses its own instructions. |
|
|
347
|
+
| `includeSystem` | Include OpenCode's system message in the ACP prompt. Defaults to `false`; the agent uses its own instructions. Either way, the `<system-*>` blocks OpenCode puts in user messages (such as `<system-reminder>` and `<system-update>`) are always removed before the prompt reaches the agent. |
|
|
337
348
|
| `historyTurns` | Turns of history replayed into a brand new ACP session. Defaults to `16`. |
|
|
338
349
|
| `historyChars` | Characters of history replayed into a brand new ACP session. Defaults to `8192`. Also caps the recent conversation a `/compact` summary keeps. |
|
|
339
350
|
| `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. |
|
|
@@ -345,26 +356,23 @@ agents that serve one directory per process.
|
|
|
345
356
|
| `initTimeoutMs` | How long one agent may take to initialize. Defaults to `20000`; a failed server is retried in the background under the same bound. |
|
|
346
357
|
| `requestTimeoutMs` | Timeout for the ACP handshake and control calls such as `session/new`. Defaults to `15000`; raise it for agents that start slowly. |
|
|
347
358
|
| `promptTimeoutMs` | How long one ACP turn may run. Defaults to `1800000` (30 minutes); `0` disables the cap. |
|
|
348
|
-
| `toolCallDisplay` | `inline` (default) shows finished ACP tool calls as transcript lines; `off` hides them. |
|
|
359
|
+
| `toolCallDisplay` | `inline` (default) shows finished ACP tool calls as transcript lines on the fallback chat-completions route when OpenCode cannot render native tool cards; `off` hides them. |
|
|
349
360
|
| `mcp` | Expose OpenCode tools to ACP agents through the MCP bridge. Defaults to `true`. |
|
|
350
361
|
| `commands` | Register the agents' own slash commands as namespaced OpenCode commands. Defaults to `true`. See [Commands](#commands). |
|
|
351
362
|
| `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. |
|
|
352
363
|
| `mcpTransport` | `stdio` (default) or `http`. Use `http` only for an agent that accepts injected HTTP MCP servers. |
|
|
353
364
|
| `mcpRuntime` | Runtime that executes the stdio bridge, e.g. `bun`. Defaults to `node` from `PATH`. |
|
|
354
365
|
|
|
355
|
-
## MCP
|
|
366
|
+
## Sign-ins and external MCP servers
|
|
356
367
|
|
|
357
368
|
Each agent signs in on its own; the plugin holds no credentials for it. To pass an agent a key, set
|
|
358
369
|
it in that server's `env`.
|
|
359
370
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
agent's own CLI) and the next session picks the credential up. ACP cannot update headers on a live
|
|
366
|
-
session, so a grant that expires mid-session is not replaced until that session is recycled or a new
|
|
367
|
-
conversation starts.
|
|
371
|
+
In `session/new`, the plugin only supplies its own `opencode` MCP bridge; it does not forward
|
|
372
|
+
OpenCode's external MCP servers. Configure any additional MCP servers directly in each agent's own
|
|
373
|
+
MCP configuration (for example, `agy mcp add` / `~/.gemini/config/mcp_config.json`, `claude mcp add`,
|
|
374
|
+
`codex mcp add`, or `cmd mcp add`) so each agent handles its own credentials and tool loading (such
|
|
375
|
+
as Antigravity's native lazy loading).
|
|
368
376
|
|
|
369
377
|
## Limits
|
|
370
378
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-acp-provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "OpenCode plugin that acts as an Agent Client Protocol (ACP) client and exposes registered ACP agents as model providers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"node": ">=24"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@opencode/plugin": "latest"
|
|
31
|
+
"@opencode/plugin": "latest",
|
|
32
|
+
"effect": "4.1.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/node": "^26.0.0",
|
package/src/acp-client.ts
CHANGED
|
@@ -119,7 +119,7 @@ function readQuestionText(params: any, options: Array<{ optionId?: string }>): s
|
|
|
119
119
|
return question
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function readEffortConfig(configOptions: AcpConfigOption[]): AcpEffortConfig | undefined {
|
|
122
|
+
export function readEffortConfig(configOptions: AcpConfigOption[]): AcpEffortConfig | undefined {
|
|
123
123
|
const option =
|
|
124
124
|
configOptions.find((candidate) => candidate.id === "effort") ??
|
|
125
125
|
configOptions.find((candidate) => candidate.category === "thought_level")
|
|
@@ -181,6 +181,13 @@ interface SessionState {
|
|
|
181
181
|
/** Extra directories granted at session/new; readable through client fs. */
|
|
182
182
|
additionalDirectories?: string[]
|
|
183
183
|
configOptions: AcpConfigOption[]
|
|
184
|
+
/**
|
|
185
|
+
* The agent reported the session's options after its latest model change, so
|
|
186
|
+
* `configOptions` reflects the selected model's effort select (or its absence).
|
|
187
|
+
*/
|
|
188
|
+
optionsConfirmed: boolean
|
|
189
|
+
/** An effort was set in this session, so the current effort is no longer the model's default. */
|
|
190
|
+
effortSet: boolean
|
|
184
191
|
/**
|
|
185
192
|
* The object that opened this session, usually the server manager. A call
|
|
186
193
|
* matches the session when it passes no owner, when the session has no
|
|
@@ -193,7 +200,10 @@ interface SessionState {
|
|
|
193
200
|
*/
|
|
194
201
|
turn?: Promise<unknown>
|
|
195
202
|
onUpdate?: (update: SessionUpdate) => void
|
|
203
|
+
onUnsolicitedUpdate?: (update: SessionUpdate) => void
|
|
196
204
|
requestPermission?: PermissionHandler
|
|
205
|
+
defaultRequestPermission?: PermissionHandler
|
|
206
|
+
onPermissionChange?: (delta: 1 | -1) => void
|
|
197
207
|
/** Called when this session's command list is advertised. */
|
|
198
208
|
onCommands?: (commands: AcpCommand[]) => void
|
|
199
209
|
}
|
|
@@ -484,7 +494,9 @@ export class AcpClient {
|
|
|
484
494
|
`ACP context for ${sessionId}: ${update.used ?? "?"}/${update.size ?? "?"} tokens, cost ${JSON.stringify(update.cost ?? null)}`,
|
|
485
495
|
)
|
|
486
496
|
}
|
|
487
|
-
this.sessions.get(sessionId)
|
|
497
|
+
const session = this.sessions.get(sessionId)
|
|
498
|
+
if (session?.onUpdate) session.onUpdate(update)
|
|
499
|
+
else session?.onUnsolicitedUpdate?.(update)
|
|
488
500
|
}
|
|
489
501
|
|
|
490
502
|
private async onRequest(message: RpcMessage) {
|
|
@@ -515,12 +527,20 @@ export class AcpClient {
|
|
|
515
527
|
kind: params.toolCall?.kind,
|
|
516
528
|
detail: readToolCallText(params.toolCall?.content),
|
|
517
529
|
}
|
|
518
|
-
const
|
|
530
|
+
const session = this.sessions.get(params.sessionId)
|
|
531
|
+
const handler = session?.requestPermission ?? session?.defaultRequestPermission
|
|
519
532
|
const approved =
|
|
520
533
|
this.options.autoApprove !== false
|
|
521
534
|
? Boolean(allow)
|
|
522
535
|
: handler
|
|
523
|
-
? await
|
|
536
|
+
? await (async () => {
|
|
537
|
+
session?.onPermissionChange?.(1)
|
|
538
|
+
try {
|
|
539
|
+
return await handler(info).catch(() => false)
|
|
540
|
+
} finally {
|
|
541
|
+
session?.onPermissionChange?.(-1)
|
|
542
|
+
}
|
|
543
|
+
})()
|
|
524
544
|
: false
|
|
525
545
|
if (!approved || !allow?.optionId) {
|
|
526
546
|
this.reply(message.id!, { outcome: { outcome: "cancelled" } }, undefined, undefined, child)
|
|
@@ -674,6 +694,12 @@ export class AcpClient {
|
|
|
674
694
|
owner?: object
|
|
675
695
|
/** Called when this session's command list is advertised, including one that arrived before registration. */
|
|
676
696
|
onCommands?: (commands: AcpCommand[]) => void
|
|
697
|
+
/** Persistent listener for updates emitted when no `prompt()` turn is active. */
|
|
698
|
+
onUnsolicitedUpdate?: (update: SessionUpdate) => void
|
|
699
|
+
/** Fallback permission handler for unsolicited tool calls when `autoApprove` is false. */
|
|
700
|
+
requestPermission?: PermissionHandler
|
|
701
|
+
/** Notifies listeners when an unsolicited permission prompt starts (`1`) or settles (`-1`). */
|
|
702
|
+
onPermissionChange?: (delta: 1 | -1) => void
|
|
677
703
|
} = {},
|
|
678
704
|
) {
|
|
679
705
|
await this.start()
|
|
@@ -697,8 +723,13 @@ export class AcpClient {
|
|
|
697
723
|
cwd,
|
|
698
724
|
additionalDirectories: options.additionalDirectories,
|
|
699
725
|
configOptions,
|
|
726
|
+
optionsConfirmed: Array.isArray(result.configOptions),
|
|
727
|
+
effortSet: false,
|
|
700
728
|
owner: options.owner,
|
|
701
729
|
onCommands: options.onCommands,
|
|
730
|
+
onUnsolicitedUpdate: options.onUnsolicitedUpdate,
|
|
731
|
+
defaultRequestPermission: options.requestPermission,
|
|
732
|
+
onPermissionChange: options.onPermissionChange,
|
|
702
733
|
})
|
|
703
734
|
// The notification can arrive before the response that names the session.
|
|
704
735
|
const advertised = this.commands.get(sessionId)
|
|
@@ -749,6 +780,12 @@ export class AcpClient {
|
|
|
749
780
|
owner?: object
|
|
750
781
|
/** Called when this session's command list is advertised, including one that arrived before registration. */
|
|
751
782
|
onCommands?: (commands: AcpCommand[]) => void
|
|
783
|
+
/** Persistent listener for updates emitted when no `prompt()` turn is active. */
|
|
784
|
+
onUnsolicitedUpdate?: (update: SessionUpdate) => void
|
|
785
|
+
/** Fallback permission handler for unsolicited tool calls when `autoApprove` is false. */
|
|
786
|
+
requestPermission?: PermissionHandler
|
|
787
|
+
/** Notifies listeners when an unsolicited permission prompt starts (`1`) or settles (`-1`). */
|
|
788
|
+
onPermissionChange?: (delta: 1 | -1) => void
|
|
752
789
|
},
|
|
753
790
|
): Promise<"resumed" | "loaded" | undefined> {
|
|
754
791
|
// Restores of one session run one at a time, so a takeover cannot interleave
|
|
@@ -776,6 +813,9 @@ export class AcpClient {
|
|
|
776
813
|
meta?: Record<string, unknown>
|
|
777
814
|
owner?: object
|
|
778
815
|
onCommands?: (commands: AcpCommand[]) => void
|
|
816
|
+
onUnsolicitedUpdate?: (update: SessionUpdate) => void
|
|
817
|
+
requestPermission?: PermissionHandler
|
|
818
|
+
onPermissionChange?: (delta: 1 | -1) => void
|
|
779
819
|
},
|
|
780
820
|
): Promise<"resumed" | "loaded" | undefined> {
|
|
781
821
|
const capabilities = (await this.start()).agentCapabilities
|
|
@@ -803,8 +843,14 @@ export class AcpClient {
|
|
|
803
843
|
cwd: options.cwd,
|
|
804
844
|
additionalDirectories: options.additionalDirectories,
|
|
805
845
|
configOptions: result.configOptions ?? [],
|
|
846
|
+
optionsConfirmed: Array.isArray(result.configOptions),
|
|
847
|
+
// An earlier process may have changed the effort of a restored session.
|
|
848
|
+
effortSet: true,
|
|
806
849
|
owner: options.owner,
|
|
807
850
|
onCommands: options.onCommands,
|
|
851
|
+
onUnsolicitedUpdate: options.onUnsolicitedUpdate,
|
|
852
|
+
defaultRequestPermission: options.requestPermission,
|
|
853
|
+
onPermissionChange: options.onPermissionChange,
|
|
808
854
|
})
|
|
809
855
|
// The notification can arrive before the response that names the session.
|
|
810
856
|
const advertised = this.commands.get(sessionId)
|
|
@@ -840,6 +886,19 @@ export class AcpClient {
|
|
|
840
886
|
async setModel(sessionId: string, modelId: string, configId = "model") {
|
|
841
887
|
return this.setConfigOption(sessionId, this.configOption(sessionId, "model")?.id ?? configId, modelId)
|
|
842
888
|
}
|
|
889
|
+
/**
|
|
890
|
+
* The effort select the session's current model offers, as last reported by
|
|
891
|
+
* the agent. Undefined when the agent has not reported the options since the
|
|
892
|
+
* last model change; `config` is undefined when the model offers no effort.
|
|
893
|
+
* `defaultValue` is the model's own effort, known only until one is set.
|
|
894
|
+
*/
|
|
895
|
+
observedEffort(sessionId: string) {
|
|
896
|
+
const session = this.sessions.get(sessionId)
|
|
897
|
+
if (!session?.optionsConfirmed) return undefined
|
|
898
|
+
const config = readEffortConfig(session.configOptions)
|
|
899
|
+
return { config, defaultValue: session.effortSet ? undefined : config?.currentValue }
|
|
900
|
+
}
|
|
901
|
+
|
|
843
902
|
/** Set the agent's reasoning effort for a session. */
|
|
844
903
|
async setEffort(sessionId: string, effort: string, configId = "effort") {
|
|
845
904
|
return this.setConfigOption(sessionId, this.configOption(sessionId, "thought_level")?.id ?? configId, effort)
|
|
@@ -852,6 +911,10 @@ export class AcpClient {
|
|
|
852
911
|
if (option?.currentValue === value) return
|
|
853
912
|
const result = await this.request("session/set_config_option", { sessionId, configId, value })
|
|
854
913
|
if (session) {
|
|
914
|
+
if (option?.category === "model" || configId === "model") session.optionsConfirmed = Array.isArray(result.configOptions)
|
|
915
|
+
if (option?.category === "thought_level" || configId === readEffortConfig(session.configOptions)?.configId) {
|
|
916
|
+
session.effortSet = true
|
|
917
|
+
}
|
|
855
918
|
session.configOptions = Array.isArray(result.configOptions)
|
|
856
919
|
? result.configOptions
|
|
857
920
|
: session.configOptions.map((current) => {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { ResolvedTool, ToolContext } from "./shared.ts"
|
|
2
|
+
import {
|
|
3
|
+
booleanOf,
|
|
4
|
+
editInput,
|
|
5
|
+
finiteNumber,
|
|
6
|
+
isOpencodeQuestionName,
|
|
7
|
+
literal,
|
|
8
|
+
patchInput,
|
|
9
|
+
questionInput,
|
|
10
|
+
readInput,
|
|
11
|
+
record,
|
|
12
|
+
shellInput,
|
|
13
|
+
text,
|
|
14
|
+
websearchInput,
|
|
15
|
+
writeInput,
|
|
16
|
+
} from "./shared.ts"
|
|
17
|
+
|
|
18
|
+
export function resolveAntigravity(ctx: ToolContext): ResolvedTool | undefined {
|
|
19
|
+
const name = ctx.topName ?? (ctx.priorAgent === "antigravity" ? ctx.priorRawName : undefined)
|
|
20
|
+
if (!name) return undefined
|
|
21
|
+
|
|
22
|
+
const raw = ctx.raw
|
|
23
|
+
const resolved = (resolvedName: string, input: Record<string, unknown>): ResolvedTool => ({
|
|
24
|
+
agent: "antigravity",
|
|
25
|
+
rawName: name,
|
|
26
|
+
name: resolvedName,
|
|
27
|
+
input,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
switch (name) {
|
|
31
|
+
case "run_command":
|
|
32
|
+
// Command Code also names its shell tool `run_command`, but with a
|
|
33
|
+
// `command` field instead of Antigravity's `CommandLine`.
|
|
34
|
+
if (raw && "command" in raw && !("CommandLine" in raw)) return undefined
|
|
35
|
+
return resolved(
|
|
36
|
+
"shell",
|
|
37
|
+
shellInput({
|
|
38
|
+
command: text(raw?.CommandLine),
|
|
39
|
+
workdir: text(raw?.Cwd),
|
|
40
|
+
timeout: finiteNumber(raw?.WaitMsBeforeAsync),
|
|
41
|
+
background: raw?.IsDaemon === true ? true : undefined,
|
|
42
|
+
}),
|
|
43
|
+
)
|
|
44
|
+
case "read_file":
|
|
45
|
+
return resolved("read", readInput({ path: text(raw?.Path) ?? ctx.locationPath }))
|
|
46
|
+
case "write_file": {
|
|
47
|
+
if (raw?.Append === true) {
|
|
48
|
+
const diff = ctx.diffs[0]
|
|
49
|
+
return resolved(
|
|
50
|
+
"edit",
|
|
51
|
+
editInput({
|
|
52
|
+
path: diff?.path ?? text(raw?.Path) ?? ctx.locationPath,
|
|
53
|
+
oldString: diff ? (diff.oldText === null ? "" : diff.oldText) : undefined,
|
|
54
|
+
newString: diff?.newText,
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
return resolved("write", writeInput({ path: text(raw?.Path) ?? ctx.locationPath, content: literal(raw?.Content) }))
|
|
59
|
+
}
|
|
60
|
+
case "edit_file": {
|
|
61
|
+
const path = text(raw?.Path) ?? ctx.locationPath
|
|
62
|
+
const rawEdits = raw?.Edits
|
|
63
|
+
if (Array.isArray(rawEdits)) {
|
|
64
|
+
const valid = rawEdits
|
|
65
|
+
.map((item) => record(item))
|
|
66
|
+
.filter(
|
|
67
|
+
(item): item is Record<string, unknown> =>
|
|
68
|
+
item !== undefined &&
|
|
69
|
+
(typeof item.TargetContent === "string" || typeof item.ReplacementContent === "string"),
|
|
70
|
+
)
|
|
71
|
+
if (valid.length > 1) {
|
|
72
|
+
return resolved(
|
|
73
|
+
"patch",
|
|
74
|
+
path
|
|
75
|
+
? patchInput([
|
|
76
|
+
{
|
|
77
|
+
kind: "update",
|
|
78
|
+
path,
|
|
79
|
+
chunks: valid.map((edit) => ({
|
|
80
|
+
oldText: literal(edit.TargetContent) ?? "",
|
|
81
|
+
newText: literal(edit.ReplacementContent) ?? "",
|
|
82
|
+
})),
|
|
83
|
+
},
|
|
84
|
+
])
|
|
85
|
+
: {},
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
if (valid.length === 1) {
|
|
89
|
+
return resolved(
|
|
90
|
+
"edit",
|
|
91
|
+
editInput({
|
|
92
|
+
path,
|
|
93
|
+
oldString: literal(valid[0].TargetContent),
|
|
94
|
+
newString: literal(valid[0].ReplacementContent),
|
|
95
|
+
replaceAll: booleanOf(raw?.AllowMultiple),
|
|
96
|
+
}),
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
|
+
return resolved("edit", editInput({ path }))
|
|
100
|
+
}
|
|
101
|
+
return resolved(
|
|
102
|
+
"edit",
|
|
103
|
+
editInput({
|
|
104
|
+
path,
|
|
105
|
+
oldString: literal(raw?.Target),
|
|
106
|
+
newString: literal(raw?.Replacement),
|
|
107
|
+
replaceAll: booleanOf(raw?.AllowMultiple),
|
|
108
|
+
}),
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
case "search_web":
|
|
112
|
+
return resolved("websearch", websearchInput({ query: text(raw?.query) }))
|
|
113
|
+
default:
|
|
114
|
+
if (isOpencodeQuestionName(name)) return resolved("question", questionInput(raw))
|
|
115
|
+
return resolved(name, raw ? { ...raw } : {})
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { ResolvedTool, ToolContext } from "./shared.ts"
|
|
2
|
+
import {
|
|
3
|
+
booleanOf,
|
|
4
|
+
commandOf,
|
|
5
|
+
editInput,
|
|
6
|
+
finiteNumber,
|
|
7
|
+
firstText,
|
|
8
|
+
globInput,
|
|
9
|
+
grepInput,
|
|
10
|
+
isOpencodeQuestionName,
|
|
11
|
+
literal,
|
|
12
|
+
questionInput,
|
|
13
|
+
readInput,
|
|
14
|
+
record,
|
|
15
|
+
shellInput,
|
|
16
|
+
skillInput,
|
|
17
|
+
text,
|
|
18
|
+
webfetchInput,
|
|
19
|
+
websearchInput,
|
|
20
|
+
writeInput,
|
|
21
|
+
} from "./shared.ts"
|
|
22
|
+
|
|
23
|
+
export function resolveClaude(ctx: ToolContext): ResolvedTool | undefined {
|
|
24
|
+
const raw = ctx.raw
|
|
25
|
+
const toolName =
|
|
26
|
+
text(record(record(ctx.update._meta)?.claudeCode)?.toolName) ??
|
|
27
|
+
(ctx.priorAgent === "claude" ? ctx.priorRawName : undefined)
|
|
28
|
+
if (!toolName) return undefined
|
|
29
|
+
|
|
30
|
+
const resolved = (name: string, input: Record<string, unknown>): ResolvedTool => ({
|
|
31
|
+
agent: "claude",
|
|
32
|
+
rawName: toolName,
|
|
33
|
+
name,
|
|
34
|
+
input,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const path = firstText(raw?.file_path, raw?.path) ?? ctx.locationPath
|
|
38
|
+
const headLimit = finiteNumber(raw?.head_limit)
|
|
39
|
+
const caseInsensitive = raw?.["-i"]
|
|
40
|
+
|
|
41
|
+
switch (toolName) {
|
|
42
|
+
case "Bash":
|
|
43
|
+
case "PowerShell":
|
|
44
|
+
return resolved(
|
|
45
|
+
"shell",
|
|
46
|
+
shellInput({
|
|
47
|
+
command: commandOf(raw?.command),
|
|
48
|
+
timeout: finiteNumber(raw?.timeout),
|
|
49
|
+
background: booleanOf(raw?.run_in_background),
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
case "Read":
|
|
53
|
+
return resolved(
|
|
54
|
+
"read",
|
|
55
|
+
readInput({
|
|
56
|
+
path,
|
|
57
|
+
offset: finiteNumber(raw?.offset),
|
|
58
|
+
limit: finiteNumber(raw?.limit),
|
|
59
|
+
}),
|
|
60
|
+
)
|
|
61
|
+
case "Grep":
|
|
62
|
+
return resolved(
|
|
63
|
+
"grep",
|
|
64
|
+
grepInput({
|
|
65
|
+
pattern: text(raw?.pattern),
|
|
66
|
+
path: firstText(raw?.path, raw?.file_path) ?? ctx.locationPath,
|
|
67
|
+
include: text(raw?.glob),
|
|
68
|
+
caseSensitive: typeof caseInsensitive === "boolean" ? !caseInsensitive : undefined,
|
|
69
|
+
limit: headLimit !== undefined && headLimit > 0 ? headLimit : undefined,
|
|
70
|
+
}),
|
|
71
|
+
)
|
|
72
|
+
case "Glob":
|
|
73
|
+
return resolved(
|
|
74
|
+
"glob",
|
|
75
|
+
globInput({ pattern: text(raw?.pattern), path: firstText(raw?.path) ?? ctx.locationPath }),
|
|
76
|
+
)
|
|
77
|
+
case "WebFetch":
|
|
78
|
+
return resolved("webfetch", webfetchInput({ url: text(raw?.url), format: "markdown" }))
|
|
79
|
+
case "WebSearch":
|
|
80
|
+
return resolved("websearch", websearchInput({ query: text(raw?.query) }))
|
|
81
|
+
case "Write":
|
|
82
|
+
return resolved(
|
|
83
|
+
"write",
|
|
84
|
+
writeInput({
|
|
85
|
+
path,
|
|
86
|
+
content: literal(raw?.content) ?? literal(raw?.file_text) ?? literal(raw?.file_content),
|
|
87
|
+
}),
|
|
88
|
+
)
|
|
89
|
+
case "Edit":
|
|
90
|
+
return resolved(
|
|
91
|
+
"edit",
|
|
92
|
+
editInput({
|
|
93
|
+
path,
|
|
94
|
+
oldString: literal(raw?.old_string),
|
|
95
|
+
newString: literal(raw?.new_string),
|
|
96
|
+
replaceAll: booleanOf(raw?.replace_all),
|
|
97
|
+
}),
|
|
98
|
+
)
|
|
99
|
+
case "Skill":
|
|
100
|
+
return resolved("skill", skillInput({ id: text(raw?.skill) }))
|
|
101
|
+
default:
|
|
102
|
+
if (isOpencodeQuestionName(toolName)) return resolved("question", questionInput(raw))
|
|
103
|
+
return { agent: "claude", rawName: toolName, name: toolName, input: raw ? { ...raw } : {} }
|
|
104
|
+
}
|
|
105
|
+
}
|