opencode-agy-acp
v1.0.1
Published
OpenCode v2 plugin that exposes the Google Antigravity runtime (agy acp) as a tool, forwarding agent definitions, per-agent MCP servers and live progress.
Maintainers
Readme
opencode-agy-acp
An ACP client for OpenCode v2 that exposes the Google Antigravity runtime (agy acp) as a tool.
What this is, precisely: Zed ships an Agent Client Protocol client that agy was built and
tested against. This project reconstructs that client contract — handshake, session setup, config
options, prompt shape, update routing — inside OpenCode, so agy cannot tell the two apart. The
wire format is the specification; every behaviour below was observed against a live agy process
and, where it diverges from the published ACP spec, the divergence is recorded rather than hidden.
Verified against agy 1.5.20, OpenCode 2.4.3, Node 24.16.0. ACP v1 transport and the 19
sessionUpdate kinds are checked against @agentclientprotocol/[email protected].
Contents
- Model
- Install
- Configuration
- The
agytool - Slash command
- Model and reasoning selection
- What crosses the wire
- Progress visibility
- Inspecting the wire
- Verified limitations
- Tests
Model
| Concern | Behaviour |
| --- | --- |
| Transport | Newline-delimited JSON-RPC 2.0 over the child's stdin/stdout |
| Process | One long-lived agy acp process, many ACP sessions inside it |
| Session reuse | Keyed by cwd::agent, invalidated by a SHA-256 fingerprint of cwd, agent prompt, MCP servers, extra dirs |
| Agent identity | OpenCode's own Agent.Info.system + instructions, sent as _meta.antigravity.systemPrompt.append |
| Read-only detection | OpenCode permissions: an effective edit rule on * with effect: "deny" |
| MCP | opencode.json mcp.servers, filtered by global and per-agent rules |
| Concurrency | Turns serialised by an internal mutex so session/update streams never interleave |
| Cancellation | context.signal → session/cancel notification, process recycled after cancelGraceMs |
--agent is never passed. It is a process flag; using it would force one agy process per agent
and destroy the many-sessions-per-process model. The per-session prompt append replaces it.
Install
Requires Node ≥ 22.18 (native TypeScript type stripping; there is no build step), the agy binary
with an acp subcommand, and OpenCode v2.
opencode plugin add opencode-agy-acp@latestOr add it to the plugins array in opencode.json(c) yourself:
{
"$schema": "https://opencode.ai/config.json",
"plugins": [
"opencode-agy-acp@latest",
// ...or with options:
// { "package": "opencode-agy-acp@latest", "options": { "binary": "/home/you/.local/bin/agy" } }
]
}The key is plugins, an array. A singular "plugin" key is ignored without an error.
One entry loads both parts: the server part from exports["."], the TUI part from
exports["./tui"].
Configuration
All options are optional.
| Option | Type | Default | Meaning |
| --- | --- | --- | --- |
| binary | string | $AGY_BIN → ~/.local/bin/agy | Path to the ACP server. Point it at tools/acp-trace.ts to trace the wire. |
| args | string[] | $AGY_ARGS → ["--dangerously-skip-permissions","acp"] | Arguments used to spawn the process. |
| defaultModel | string | — | Model used when neither the tool call nor the agent config names one. |
| additionalDirectories | string[] | [] | Extra dirs passed to session/new when the server advertises support. |
| autoApprovePermissions | boolean | false | Auto-answer ACP permission requests. Only relevant without --dangerously-skip-permissions. |
| maxSessions | number | 12 | Live ACP sessions kept in memory (1–64, LRU). |
| controlTimeoutMs | number | 30000 | Timeout for initialize, session/new, set_config_option, session/close (2 000–120 000). |
| turnTimeoutMs | number | 600000 | Timeout for one session/prompt (5 000–3 600 000). |
| cancelGraceMs | number | 5000 | Wait after session/cancel before recycling the process (500–30 000). |
| progressThrottleMs | number | 250 | Minimum gap between progress updates (50–5 000). |
| maxOutputBytes | number | 2097152 | Assistant text cap per turn (16 KiB–16 MiB). |
| maxImageBytes | number | 10485760 | Per-image cap (64 KiB–50 MiB). |
| toolName | string | "agy" | Tool name registered in OpenCode. |
| defaultAgent | string | "default" | Agent used when neither the tool call nor the session provides one. |
| clientVersion | string | 1.30.2+stable.398.610ea4b8de1c6e887f03563f067278002f41256e | clientInfo.version sent in initialize. |
Out-of-range numbers are clamped, not rejected.
The agy tool
{
"prompt": "full task text", // required, non-empty
"agent": "debug", // optional; defaults to the running agent
"model": "gemini-4-hydrogen", // optional; `<id>` or `<id>-<level>`
"thought_level": "low", // optional; low | medium | high | xhigh | max
"mode": "accept-edits", // optional; default | accept-edits | plan
"image_paths": ["shot.png"], // optional; relative to the workspace
"new_session": false // optional; start a clean ACP session
}Returns { content, metadata }; metadata carries status, title, agent, sessionId,
model, thoughtLevel, mode, mcpCount, truncated, elapsedMs, usage.
prompt is the whole contract. agy receives nothing but this text and the forwarded agent
definition — no conversation history, no prior turns — so the prompt must carry the goal, the
paths, and the expected output.
Slash command
A commands entry makes delegation one keystroke and fixes the call shape, so the model cannot
invent a different one. In opencode.json(c):
{
"commands": {
"agy": {
"description": "Delegate a task to the native agy runtime (agy-acp plugin) instead of doing it yourself",
"template": "Delegate the task below to the `agy` tool by calling it **exactly once**. Do not read, edit, write, or run shell commands yourself.\n\nTask:\n$ARGUMENTS\n\nRequirements:\n1. Call `agy` exactly once, setting `prompt` to the full task text from the Task section, copied verbatim as one self-contained instruction.\n2. Do not pass `agent`.\n3. Pass `model` explicitly when the task implies one, in the form agy advertises it (e.g. `gemini-4-hydrogen-low`); the plugin splits the trailing level into `thought_level`. Set `thought_level` explicitly when only reasoning depth matters.\n4. `$ARGUMENTS` must already contain the full context to act on (plan, decisions, file paths) — agy cannot see this conversation, so paste the relevant plan text instead of referring to it.\n5. Report agy's returned text verbatim.\n"
}
}
}$ARGUMENTS is replaced with everything typed after the command name; $1…$N address a single
argument. Usage:
/agy Read /tmp/report.md and summarise the three risks it lists. Output: a bullet list.Notes on why each requirement is there:
- no
agentkey — the command has noagentfield, so it inherits whichever agent is running, and the plugin forwards that agent's definition. Adding"agent": "build"to the command would pin every delegation tobuild. promptverbatim — the template forbids reading and re-writing, which is how a model silently drops the half of the task it did not like.- explicit
model— without it the plugin falls back to the agent config, which usually names a provider model thatagydoes not advertise and therefore warns about. - context pasted in — the single most common failure: asking
agyto "continue the plan above" when it can see no plan. The plan text must be inside$ARGUMENTS.
A read-only calling agent stays read-only: mode is derived from OpenCode permissions unless the
tool call sets it, so /agy from plan investigates and writes nothing.
Model and reasoning selection
model: tool call `model` → agents[<agent>].model → options.defaultModel
thought_level: tool call `thought_level` → trailing suffix of that → agents[<agent>].model.variant
agent: tool call `agent` → the running agent → options.defaultAgentAn agent's own model in opencode.json always wins over defaultModel.
agy advertises two inconsistent model lists:
models.availableModels : gemini-4-hydrogen-{high,xhigh,medium,low} ← 4 values
configOptions.model : options=["gemini-4-hydrogen"] ← 1 valuesession/set_config_option model="gemini-4-hydrogen-low" returns OK but leaves
currentValue = "gemini-4-hydrogen". configOptions is the only channel the server honours, so
the plugin splits a trailing -low/-medium/-high/-xhigh off the id and applies it as
thought_level. gemini-4-hydrogen-low therefore means model gemini-4-hydrogen at level low.
A base id the server does not advertise is dropped by the server silently, so the plugin compares
against configOptions first and emits one warning progress instead.
thought_level: "max" is not an ACP value; it walks max → xhigh → high and only warns if none
are offered.
To read the authoritative lists from your own install:
AGY_BIN=/path/to/agy node --experimental-strip-types -e '
const { AgyAcpClient } = await import("./src/acp-client.ts")
const { normalizeOptions } = await import("./src/config.ts")
const c = new AgyAcpClient(normalizeOptions({ binary: process.env.AGY_BIN }))
await c.ensureReady()
const r = await c.request("session/new", { cwd: process.cwd(), mcpServers: [] }, 60000)
for (const o of r.configOptions) console.log(o.id, "=>", o.options.map((x) => x.value))
await c.shutdown()'What crosses the wire
- Spawn —
binary args, theninitializewith the captured Zed payload (protocolVersion: 1, full client capabilities, configurableclientInfo.version).agythen never calls back for filesystem or terminal work; it uses its own native tools. - Session — reuse the
cwd::agentsession when its fingerprint matches, otherwisesession/newwithcwd,mcpServers, optionaladditionalDirectories, and_meta.antigravity.systemPrompt.append. - Config —
session/set_config_optionformode,model,thought_level, each reporting what it could not apply. - Prompt —
session/promptwith[{ type: "text", text }]plus image blocks. - Stream —
usage_updateupdates counters,tool_call/tool_call_updateset the active tool,agent_thought_chunkemitsthinking,agent_message_chunkaccumulates output and emitsstreaming. - Finish —
stopReasonmaps tocompletedorcancelled.
Progress order: initializing → (warning) → requesting → (thinking) → (streaming) →
completed | cancelled. requesting exists because there is a real multi-second window between
config sync and the first token; without it a turn looks dead.
Progress visibility
context.progress() reaches the wire as session.tool.progress and the TUI writes it into the
running tool call's state.metadata. The generic tool renderer reads only input, so metadata is
invisible on its own. Two surfaces compensate: the TUI part (src/tui.ts) toasts status
transitions for events whose metadata.source is opencode.agy-acp, and the final result carries
the same fields as tool metadata.
Inspecting the wire
tools/acp-trace.ts is a transparent proxy: child stdout is forwarded byte for byte, exit codes
and signals propagate, and nothing is injected into the stream.
AGY_BIN=/path/to/agy-acp/tools/acp-trace.ts AGY_ACP_LOG=/tmp/agy-trace.jsonl opencode| Variable | Default | Meaning |
| --- | --- | --- |
| AGY_REAL_BIN | ~/.local/bin/agy | The real binary the proxy forwards to. |
| AGY_ACP_LOG | unset | Append a JSONL {direction,index,line} transcript. |
| AGY_ACP_STRICT | unset | 1 exits non-zero on the first protocol violation. |
An explicit binary option overrides AGY_BIN. Payloads over 512 bytes (base64 images) are
replaced with <redacted> in the log, but transcripts still contain prompts — treat them as
sensitive.
tools/acp-validate.ts holds the rules as pure functions: valid JSON, jsonrpc === "2.0", no
embedded newline, exactly one of request/response/notification, a known method, one of the 19 ACP
v1 sessionUpdate kinds, one of the 5 stopReason values.
import { validateLine } from "opencode-agy-acp/tools/acp-validate"
validateLine('{"jsonrpc":"2.0","id":1,"result":{"stopReason":"end_turn"}}') // []Verified limitations
Observed behaviours, not guesses. Each one names the evidence.
1. Reasoning tokens cannot be requested from the model. The ACP surface agy exposes has
three config options — model, thought_level, mode — and no reasoning_effort channel.
Reasoning depth is thought_level alone.
2. --agent is never used. See Model. The consequence: agent selection is a
per-session prompt append, so a name agy resolves on its own (via AGENTS.md or
.agents/agents/*.md) is not overridden.
3. Two prompt channels exist, and only one is controlled here. agy reads AGENTS.md
(walking up from cwd) and .agents/agents/*.md natively, and .agents wins on a name collision.
It never reads .opencode/agents/*.md. Agent definitions still reach it because OpenCode exposes
them as Agent.Info.system and the plugin forwards that text verbatim — verified end to end:
debug.md 19 567 bytes on disk, /api/agent serving 19 542 characters of system,
session/new carrying the same 19 542, and agy reciting that agent's role in an empty cwd.
4. If systemPrompt.append is not advertised, the prompt is not forwarded. The plugin emits a
warning progress and continues. It never concatenates a prefix into the user message.
5. Progress never renders as inline tool text. The generic renderer reads only input, and
ToolStateRunning has no title field, so no metadata value can become inline text. Toasts and
tool metadata are the only surfaces.
6. A toast cannot fire for a call made from Code Mode. The TUI drops session.tool.progress
when the ${sessionID}:${toolID} key is unknown, and a call made inside execute carries the
execute tool id.
7. A TUI part added while the TUI is running is not loaded. opencode service restart is
required. Symptom: grep -c "opencode.agy-acp.tui" on the OpenCode log returns 0.
8. Session reuse is fingerprint-based, not content-based. Editing an AGENTS.md that agy
reads natively does not change the fingerprint, so an existing session keeps the old prompt until
new_session: true or eviction.
9. Toast coalescing is global. Non-terminal statuses are suppressed within 3 s of the previous toast, across all sessions. Terminal statuses always show.
Tests
npm test # 74 tests, 10 files
npm run typecheck # tsc --strict over src, tools and testsBoth exit 0. No test needs the real binary or a network: test/fixtures/fake-agy.ts is a
complete ACP agent stand-in, and it honours session/set_config_option per session so tests
observe the applied config rather than a fixed snapshot.
| File | Covers |
| --- | --- |
| test/acp-validate.test.ts | Every accepted and rejected wire shape, all 19 kinds, redaction |
| test/agent-prompt.test.ts | Read-only detection from permissions, prompt composition |
| test/initialize-payload.test.ts | initialize parity with the captured handshake |
| test/model-variant.test.ts | Splitting <model-id>-<level> into model + thought level |
| test/thought-progress.test.ts | Progress ordering, think/stream separation, dead-binary rejection |
| test/tool-schema.test.ts | Every parameter keeps a real, caller-facing description |
| test/release-config.test.ts | Package is publishable, entrypoints exist, publish is gated |
| test/readme-command.test.ts | The documented slash command keeps its call shape |
| test/tui-toast.test.ts | Transition dedupe, coalescing, cleanup, foreign-event rejection |
| test/config-warning.test.ts | Unsupported values warn instead of dropping; suffix handling |
Two suites point process.env.HOME at an empty temp directory, because loadMergedOpenCodeConfig
would otherwise merge the developer's real ~/.config/opencode/opencode.json into the assertions.
MIT. Architecture detail lives in the source's JSDoc; CONTRIBUTING.md covers the gatekeeper
commands.
