Skip to content

feat(core): add the Google Antigravity provider - #65489

Open
AKOrojo wants to merge 6 commits into
anomalyco:devfrom
AKOrojo:feat/antigravity-provider-acp
Open

AKOrojo wants to merge 6 commits into
anomalyco:devfrom
AKOrojo:feat/antigravity-provider-acp

Conversation

@AKOrojo

@AKOrojo AKOrojo commented Nov 21, 2026 •

Copy link
Copy Markdown

Issue for this PR

Refs #28889 — the design question is asked there, and this is the implementation of the ACP route that question is about.

This replaces #65430, which was closed as bundling two unrelated changes; this one is only the Antigravity provider.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a built-in antigravity provider: OpenCode runs the Antigravity CLI on the user's machine and talks to it over the Agent Client Protocol, the way the Claude Agent provider runs Claude Code and talks to it through Anthropic's Agent SDK.

Why the ACP runtime and not the print mode. The Antigravity CLI has two headless surfaces, and only one of them may be driven by another program. agy -p is print mode, and Google's own FAQ says wrapping it inside a third-party coding agent "is not supported under consumer plans" — the Antigravity team has said it "violates Section 6 … and can trigger automated account suspension" of the Antigravity Additional Terms. agy acp is the unmodified antigravity-acp runtime, which Google names as usable for single-user interactive development with native oauth-personal sign-in. This provider drives agy acp and never agy -p. That is the difference between this and the requests that were closed as not planned.

The model list is discovered, not pinned. The CLI reports the models the signed-in account may use when it opens a session, and OpenCode registers exactly those, so a model Google adds shows up without a change here. The CLI names the reasoning effort as part of the model — gemini-3.8-flash-high, -medium and -low are one model at three effort levels — so one model is registered per model, with the effort levels as variants, the same shape the Claude Agent provider uses.

Sessions and models. Each OpenCode session gets its own CLI session, closed on session.deleted, and the CLI session is switched (session/set_model) to the model and effort level the user picked before each turn. Titles and other side requests run in a throwaway CLI session. Turns in one session are serialized, and if the CLI exits the next turn starts a new one.

Tools and permissions. The agent runs its own tools and reports them as tool calls. OpenCode surfaces each one as a single provider-executed call and result, emitted when the call completes or fails, so the run shows what the agent did, but OpenCode does not run them: it has no tools with those names. When the agent sends session/request_permission, OpenCode checks it against the session's permission rules for the agent running the turn (asking the user when a rule says to): edit/delete/move map to edit, execute to bash, read to read, search to grep, fetch to webfetch. So plan mode and deny rules apply to what the agent asks about; what it asks about is set by the CLI's own permission settings.

Startup. The model list is kept between starts. With a kept list the CLI is not started until the first turn; with none, it is asked for the list at startup only if agy is on PATH, so machines without it start silently. The CLI is closed when the plugin scope ends.

How did you verify your code works?

bun run check passes (lint and typecheck). bun test test/plugin/provider-antigravity.test.ts passes (18 tests): tool calls reported once across tool_call/tool_call_update, failed and incomplete calls, finish-reason mapping, one CLI session per OpenCode session with set_model only on a change, throwaway sessions for side requests, close on delete, replacing a dead CLI, permission mapping and option choice, and the grouping rules (three effort levels become one model with three variants; a single-level model keeps the CLI's name and has no variants; the suffix rule, so claude-opus-4-6-thinking groups under claude-opus-4-6 while claude-sonnet-4-6 does not), the slug resolution, and the stream parts for a message, a tool call and a failed tool call.

Against the real CLI (Antigravity 1.5.14, a Google AI Pro account) the provider connects, opens a session, reports the account's models, and runs a turn:

agent: Antigravity ACP Server 1.5.14
session: 88896779-2e40-4364-9f9e-553832102b83
models: gemini-3.8-flash[high,medium,low] claude-sonnet-4-6[thinking] claude-opus-4-6[thinking] gpt-oss-120b[medium]
turn: end_turn {"input":12923,"output":79,"thought":76,"cacheRead":0,"cacheWrite":0,"total":13002}

The adapter's own stream, through the same session, produces the text and the finish part with the CLI's stop reason and usage.

The session layer against the same CLI: a read_file turn produced exactly one tool call and one tool result, a second turn in the same OpenCode session remembered the first, and a shell command whose permission check was denied (agent plan, action bash) was refused by the CLI and the file was not created.

Not tested: a full opencode run against a ChatGPT-signed-in account is not what this is; what is not tested is the provider inside a running opencode server, which needs a build of this branch.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #65419, #28889, #53530

Public API: adds the antigravity provider ID and a built-in provider that turns on automatically (backwards compatible)

Copilot AI balanced review requested due to automatic review settings November 21, 2026 23:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests pass and typecheck:tsc is clean, but there are blocking problems, and I could not run it end to end (it needs the Antigravity CLI and a Google account).

Policy first: #28889, the issue this builds on, was closed by a maintainer as "not allowed". Whether driving agy acp is acceptable still needs a maintainer's answer. The description's quotes about Google's terms aren't something this review can check.

Public API: adds the antigravity provider ID to packages/schema/src/provider.ts and adds a built-in provider that turns on automatically. This doesn't break anything existing. It also adds the @agentclientprotocol/sdk dependency to @opencode/core.

Blockers (details inline):

  • Turns where the agent uses a tool crash with Duplicate tool call.
  • The model and effort the user picks are never sent to the CLI.
  • Every OpenCode session in a directory shares one CLI conversation and one listener slot, so chats get mixed up.
  • The CLI is started in the background every time OpenCode starts, which contradicts "started on first use". The process is never stopped, and it isn't restarted if it dies.

Also: permission requests are always refused (Client.start({}) passes no handler). That doesn't match your comment on #28889 that they are answered from OpenCode's permission rules. Anything the agent does without asking also skips OpenCode's rules and plan mode (compare #53530). finishReason is always stop, even for max_tokens and refusal.

The tests only check render on single updates. A test that feeds tool_call and then tool_call_update for the same id through the stream would have caught the crash.

Related: #65419, #28889, #53530

if (update.kind === "thought") {
return [{ type: "reasoning-delta", id: "reasoning", delta: update.text }]
}
if (update.kind === "tool-call" || update.kind === "tool-call-update") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every tool_call_update sends another tool-call and tool-result with the same toolCallId. ACP agents send tool_call first and then one or more tool_call_updates. When the same id comes twice, session/runner/publish-llm-event.ts stops the turn with Duplicate tool call / Duplicate tool result. A pending call is also settled right away with a result. The tool name can change between updates (name ?? title), which also stops the turn. Send the call once and the result once, when the status becomes completed or failed, and keep the tool name fixed.

groups = ready.groups
return groups
},
run: async (request, onUpdate, signal) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request.model is ignored, and resolveSlug and the variant slug/effort settings are never used outside the tests. Every turn runs on the CLI's current model, whatever the user picked. Also, opened is one CLI session for the plugin's whole lifetime. Every OpenCode session in the directory continues the same conversation, and Client.prompt stores its listener by CLI sessionId, so two turns running at once overwrite each other's listener. The Claude Agent provider keeps one session per OpenCode session and cleans up on session.deleted; this needs the same.

No permission handler is passed here, so every session/request_permission is refused. Your comment on #28889 says they are answered from OpenCode's permission rules, and this doesn't do that. If the agent can't get approval at all, normal edits and shell commands will fail. And anything the agent does without asking skips OpenCode's rules and plan mode (the problem reported in #53530).

yield* AntigravityProvider.register(ctx, known.length > 0 ? known : session.groups())
yield* AntigravityAISDK.register(ctx, session)

yield* Effect.forkScoped(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs session.refresh() while the plugin loads, so agy acp is started and a session opened every time OpenCode starts. That contradicts "started on first use", and it logs a warning for everyone who doesn't have agy installed. Nothing closes the client when the scope ends, and if the child process dies, opened stays resolved to a dead client and is never restarted.

controller.enqueue({
type: "finish",
usage: usage(turn.usage),
finishReason: { unified: "stop", raw: turn.stopReason },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unified is always stop. Map max_tokens to length, refusal to content-filter and cancelled to other, so a cut-off or refused turn doesn't look like a normal finish.

@mscipio

mscipio commented Nov 21, 2026

Copy link
Copy Markdown

Looking forward to this being merged!!

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit fixes all four earlier points: one call and one result per tool call, the model and effort switched in with session/set_model, one CLI conversation per OpenCode session closed on delete, permission requests checked against OpenCode's rules, the CLI started lazily and closed when the plugin shuts down, and the finish reason mapped from the stop reason. The 18 unit tests pass and typecheck:tsc is clean. I still couldn't run it end to end (it needs the Antigravity CLI and a Google account).

The public API is the same as before: the new antigravity provider ID and a built-in provider that turns on automatically (backwards compatible), plus the @agentclientprotocol/sdk dependency.

New: Bun.which at startup will throw under Node (inline).

Still open: a maintainer needs to decide on #28889 whether driving agy acp is acceptable. Also, plan mode and deny rules only cover what the CLI asks permission for; anything its own settings let it do without asking is not checked.


// With a cached model list the CLI waits for the first turn. Without one it is asked now, and only
// when it is installed, so a machine without it logs nothing.
if (known.length > 0 || !Bun.which("agy")) return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@opencode/core also runs under Node and workerd (see the imports conditions in its package.json). Every other Bun-only call sits behind a .bun.ts variant. Under Node, Bun.which throws a ReferenceError the first time this runs with no saved model list, and the plugin fails to load. which from src/util/which.ts does the same job on every runtime. Along the same lines, acp.ts imports node:child_process directly, while the Claude Agent provider keeps its SDK behind a workerd stub (#claude-agent-sdk).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Launching unmodified agy acp interactively is permitted only in a thin client where Antigravity is the agent — meaning the human sends raw prompts directly to agy acp and Antigravity owns its sign-in, system prompt, tools, and session history. Wrapping agy acp inside an outer third-party coding agent harness (such as OpenCode) that injects system instructions, serialized tool definitions, replayed cross-model context, or automated loops is not permitted on oauth-personal — even without extracting OAuth tokens — and risks automated enforcement or suspension.

Maintainer would need to get Google permission like it is done with claude sdk

OpenCode runs the Antigravity CLI on the user's machine and talks to it over
the Agent Client Protocol, the way the Claude Agent provider runs Claude Code
and talks to it through Anthropic's Agent SDK.

The CLI's `agy acp` runtime is used, not its print mode: Google's Antigravity
FAQ says wrapping `agy -p` inside a third-party coding agent is not supported
on consumer plans, and section 6 of the Antigravity Additional Terms says using
third-party software to access the Service is a breach. The unmodified
`antigravity-acp` runtime with native `oauth-personal` sign-in is the
integration Google names as usable for single-user interactive development.

- The model list comes from the account, so it is never written down here.
- The CLI names the reasoning effort in the model, so one model is registered
  per model with the effort levels as variants, the same shape the Claude Agent
  provider uses.
- The agent runs its own tools, reported as provider-executed calls; a
  permission request is refused unless the host answers it.
- The CLI is started on first use, and the model list is kept between starts so
  the picker has the models before the CLI answers.

Refs anomalyco#28889
- Report each agent tool call once: a call keeps the name it first had and
  is emitted with its result when it completes or fails, so repeated
  tool_call_update events no longer stop the turn as duplicates. Calls still
  running when the turn ends are settled as incomplete.
- Map the CLI's stop reason to the finish reason (max_tokens and
  max_turn_requests to length, refusal to content-filter, cancelled to other).
- Give each OpenCode session its own CLI session, closed on session.deleted,
  and switch it to the picked model and effort level before each turn.
  Titles and other side requests run in a throwaway CLI session. Turns in a
  session are serialized, and a dead CLI is replaced on the next turn.
- Answer the agent's permission requests from OpenCode's permission rules for
  the session and agent running the turn.
- Start the CLI on first use when a model list is cached, close it when the
  plugin scope ends, and only probe for models at startup when agy is on PATH.
  The provider transform reads the current list, so a reload shows models the
  CLI reports later.
- Trim comments that restated the code, and correct the docs and spec.

Claude-Session: https://claude.ai/code/session_015bbujzQVqzVf6YWBFb95JT
`Bun.which` threw a ReferenceError under Node the first time the plugin ran
without a cached model list; use the cross-runtime `which` helper instead.
The ACP client, which spawns the CLI with `node:child_process`, now sits
behind the `#antigravity-acp` import with a workerd stub and is loaded on
first use, the way the Claude Agent SDK is.

Claude-Session: https://claude.ai/code/session_015bbujzQVqzVf6YWBFb95JT
@AKOrojo
AKOrojo force-pushed the feat/antigravity-provider-acp branch from 038fdc4 to 00abed1 Compare November 21, 2026 23:43

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Node/workerd point is fixed: Bun.which is replaced with the repo's own which(), and the code that spawns the CLI is now loaded on first use behind #antigravity-acp, with a workerd stub, the same way #claude-agent-sdk works. The 18 unit tests pass and typecheck:tsc is clean. I still couldn't run it end to end (it needs the Antigravity CLI and a Google account).

The public API is the same as before: it adds the antigravity provider ID and a built-in provider that turns on automatically (backwards compatible). The new #antigravity-acp entry in @opencode/core's imports is internal.

Nothing new to flag. Still open: a maintainer needs to decide on #28889 whether driving agy acp is acceptable.

@gfsaaser24

Copy link
Copy Markdown

@thdxr uh merge pls

@gnadlr

gnadlr commented Nov 29, 2026 •

Copy link
Copy Markdown

Hello, a quick check-in: While waiting for the merge, i cloned the fork and my agent spotted that the prompt implementation is text only. I did not verify as I instructed the agent to fix it right after. Can confirm antigravity is working with the fork, you might need to fix images ingestion.

Edit 1: The context token calculator is broken for ACP tool calls (it treated tool calls as a new turn and compound cached token as total context, so the app keep compacting). This would need to be fixed in both the cli and the desktop app. I did have a working fix but quality is not ensured since it was AI generated so not submitting a PR. Just a head up for everyone.

…vider-acp

# Conflicts:
#	packages/core/src/plugin/provider.ts
@AKOrojo

AKOrojo commented Dec 1, 2026

Copy link
Copy Markdown
Author

Thanks @gnadlr, both reports check out. Here's what I found in the code:

Images are dropped. readPrompt in language-model/antigravity-language-model.ts keeps only text parts of the last user message, and acp-client.ts sends the agent a single { type: "text" } block. Attached images never reach Antigravity. The fix is to forward image parts as ACP image content blocks, gated on the agent's promptCapabilities.image from initialize.

Context size is overcounted, so it keeps compacting. The provider reports the usage from the ACP prompt response as the step's usage. That usage covers the whole turn, and inside one turn the agent makes a model request per tool call, each resending the full context. So inputTokens and cachedReadTokens come back as sums over every request in the turn. OpenCode then computes context as input + cache.read + cache.write on that number, and the provider also passes inputTokens through as the non-cached count while adding cachedReadTokens on top, which double counts cached input if the agent's inputTokens already includes it. The result looks far larger than the real window and trips compaction. The client also ignores the usage_update session notification, whose used field is the agent's own count of tokens currently in context. That is the number OpenCode should be using.

I'll look at fixing both on this branch. Also merged the latest dev in to clear the conflict in packages/core/src/plugin/provider.ts; the antigravity tests and typecheck pass.

…count

The prompt sent to the agent was text only, so attached images were dropped.
Image parts now go as ACP image content when the agent accepts them, and the
models advertise image input.

The turn's ACP usage sums every model request the agent made, one per tool
call, so OpenCode read it as a context many times too large and kept
compacting. The context size now comes from the agent's usage_update.
@AKOrojo

AKOrojo commented Dec 1, 2026

Copy link
Copy Markdown
Author

Both are fixed in 495c8c3.

Images: image parts of the user's message now go to the agent as ACP image content when it says it accepts them (promptCapabilities.image), with a text note otherwise. Antigravity models now advertise image input so the app lets you attach them. Checked against agy 1.5.21: it reports image support and correctly described a test image.

Context / compaction: the provider no longer reports the turn's summed usage as input. It takes the context size from the agent's usage_update (used), which agy sends. On a live turn where the agent read three files, the real context was 10,832 tokens; the old math would have reported 41,481. The fix is in the shared provider code, so it should cover the desktop app too.

Thanks again for the report, @gnadlr.

@nicholaicascio

Copy link
Copy Markdown

Please merge this

@gnadlr

gnadlr commented Dec 2, 2026 •

Copy link
Copy Markdown

One more bug found: the session cannot send a "steer" message (even if the agent turn has finished chatting and only waiting for script running). It seems that connecting via ACP mean that you cannot inject a message during agent turn. Also, a cmd window pop up when initiate a conversation (closing it meaning closing the ACP connection and end the session immediately, cannot resume).

I'm not sure it is because ACP does not allow it, or because current implementation. You can take a look.

In Desktop UI, Orchestrator models show only 1 levels (carbon, neon,..) and thinking level not shown. In AGY, it show 2 level (model, then thinking level). This might be UI limitation

@EgilSandfeld

Copy link
Copy Markdown

Tested this on Windows with a local backport onto v2.4.3, the official agy ACP binary and Bun 1.4.4. Two findings:

1. Console windows on Windows

Adding windowsHide: true to the background child_process.spawn call for agy acp fixed the visible console windows. I kept stdio piped. In an isolated Windows test I saw zero visible windows, and tool calls still worked.

2. Follow-up continuity after a reload or provider switch

As far as I can tell, the provider only sends the latest user prompt and keeps the ACP conversation mapping in memory. After a server restart, or after switching to another provider and back, the agent loses earlier context.

I tested a change that restores a bounded, role-tagged history of user and assistant turns in two cases:

  • on a cold start, when no ACP conversation exists for the session
  • on return from another provider, but only the turns that ACP missed

It does not replay old tool calls.

What I verified:

  • After a cold server restart, Neon correctly recalled the earlier answers and a nonce from before the restart.
  • Separate sessions stay isolated (automated tests).
  • Switching models works (automated tests).

Limits:

  • It does not resume a command that was running when the server stopped.
  • Steering in the middle of a turn still gets serialized behind the current turn. I haven't checked whether ACP could support it, so I'm not claiming it can't.
  • I didn't test or fix the orchestrator variant selector issue.

If it helps review, I can split these into two small patches, one for windowsHide and one for history restoration.

@nicholaicascio

Copy link
Copy Markdown

#67447

Looks like official Google OAuth announcement is imminent, but limited to Ultra ($100+) tier subs. 💀 Pure greed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants