Skip to content

feat(cli): add opt-in ACP v2 preview - #56849

Open
razzeee wants to merge 2 commits into
anomalyco:devfrom
razzeee:acp-v2-preview
Open

razzeee wants to merge 2 commits into
anomalyco:devfrom
razzeee:acp-v2-preview

Conversation

@razzeee

@razzeee razzeee commented Oct 18, 2026 •

Copy link
Copy Markdown

Issue for this PR

Refs #44877. Related earlier implementation: #44524.

Type of change

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

What does this PR do?

Adds ACP v2 behind OPENCODE_EXPERIMENTAL_ACP_V2=1, using SDK 1.8.0's experimental entry point. Without the flag, clients still negotiate v1, including clients requesting v2.

The v2 adapter shares the existing session service. A session-scoped observer handles streaming and aggregate state independently of prompt requests, allowing steering and resumed parent output after idle. Regular prompt acknowledgments wait for durable delivery; cancelling an undelivered steer removes only that inbox item.

Ports the existing session lifecycle, replay, config options, terminal authentication, commands, compaction, MCP transports, permissions, elicitation, and child-session extension. V2 uses replacement messages during replay, tool-call upserts, and structured diffs with patches. Commands use live-only ACP user-message echoes; auth/logout closes the ACP connection without deleting shared credentials.

This is an opt-in draft-protocol implementation, not an unrestricted production rollout. External-editor/live-provider interoperability and Windows/macOS validation remain outstanding. V1 behavior stays on its existing execution path.

How did you verify your code works?

  • bun test test/acp in packages/cli: 124 pass, 0 fail on current dev.
  • An isolated subprocess test exercises the real CLI, private server, durable inbox, runner, steering, compaction, and replay against a local model endpoint, without user credentials.
  • Root bun run check: pass (repository warnings remain).
  • services/www: bun typecheck, bun run check:generated, and bun run build pass.
  • git diff --check: pass.

Screenshots / recordings

Not applicable: protocol and CLI changes.

Checklist

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

Added by the opencode bot (AI-generated).

Related: #44877, #53042

Public API: adds the OPENCODE_EXPERIMENTAL_ACP_V2=1 environment variable for opt-in ACP v2 negotiation and bumps @agentclientprotocol/sdk to 1.8.0 (backwards compatible)

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@opencode-agent opencode-agent 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 adapter is opt-in and well contained, and steering, prompt acknowledgement and replay look right to me. I'm asking for one structural change and one fix before merge. I ran bun test test/acp in packages/cli (124 pass, including the new v1-fallback, v2 wire and v2 subprocess tests) and bun run typecheck (passes). The subprocess test runs the real CLI through a v2 prompt, a mid-run steer, /compact and resume with replay.

Public API impact: adds the OPENCODE_EXPERIMENTAL_ACP_V2=1 environment variable, which enables ACP protocol v2 negotiation in opencode acp. It bumps @agentclientprotocol/sdk from 1.6.0 to 1.8.0. Without the flag, v1 clients and clients requesting v2 still get v1, so this is backwards compatible.

Concerns:

  • Every connection now goes through the SDK's experimental v2 code, even without the flag. The handler always uses the v2 ndJsonStream and agentProtocolRouter from @agentclientprotocol/sdk/experimental/v2. That contradicts "V1 behavior stays on its existing execution path", and it exposes default users to churn in an experimental SDK module (see inline).
  • v2 session/close can stop part-way. It doesn't ignore inbox-cancel failures and turns observer setup failures into crashes (see inline).

Related: #44877, #53042

Comment thread packages/cli/src/acp/turn.ts Resolved

@opencode-agent opencode-agent 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.

Both earlier concerns are fixed, and the follow-up commit adds no new problems. I re-ran bun test test/acp in packages/cli (126 pass, 0 fail) and bun run typecheck (passes).

Resolved:

  • v1 stays on the stable SDK. Without OPENCODE_EXPERIMENTAL_ACP_V2=1, the handler uses the stable ndJsonStream and ACP.connect. The experimental router and agent-v2 are loaded only on the opt-in path, and agent.ts keeps only a type import from the experimental module.
  • v2 close and cancel finish their cleanup. They now share stopObserver. It no longer crashes when observer setup fails, settles every pending acknowledgement before any calls to the server, logs individual inbox-cancel failures and still interrupts the session. The new test covers this with failing inbox cancels.

Public API impact is unchanged since my last review: adds the OPENCODE_EXPERIMENTAL_ACP_V2=1 environment variable for opt-in ACP v2 negotiation and bumps @agentclientprotocol/sdk from 1.6.0 to 1.8.0. It is backwards compatible.

No further concerns.

Related: #44877, #53042

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.

1 participant