[PR #2947] Add ACP (Agent Client Protocol) support #10494

Closed
opened 2026-02-16 18:15:09 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2947

State: closed
Merged: Yes


Summary

Implements a clean, protocol-compliant ACP (Agent Client Protocol) server that enables opencode to work as an agent in Zed and other ACP-compatible clients. This is a massive improvement over the initial implementation https://github.com/sst/opencode/pull/2422

This is a complete rewrite of the previous ACP implementation, now using the official @zed-industries/agent-client-protocol library and following the ACP v1 specification.

Changes

Core Implementation

  • agent.ts: Full Agent interface implementation with proper protocol compliance
  • client.ts: Client interface for file operations and permission handling
  • session.ts: Session state management with working directory context
  • server.ts: Server lifecycle using official ACP library with stdio transport
  • types.ts: Type definitions for internal state

CLI Integration

  • New opencode acp command
  • Working directory support via --cwd flag
  • Graceful shutdown on SIGTERM/SIGINT

Testing

  • Comprehensive test suite in test/acp.test.ts
  • Tests protocol initialization and session creation
  • All tests passing

Protocol Compliance

Follows ACP specification v1 with proper:

  • Protocol version negotiation
  • Capability advertisement (agentCapabilities)
  • Session lifecycle (session/new, session/load)
  • Standard request/response formats
  • File operations via Client interface
  • Permission request handling

Architecture Benefits

Compared to previous implementation:

  • Uses official library instead of custom JSON-RPC handling
  • Protocol-compliant message formats (works with Zed out of the box)
  • Proper session management with working directory context
  • Clean separation of concerns (agent, client, session, server)
  • Foundation for streaming and tool call reporting

Usage

Command Line

# Start ACP server
opencode acp

# Start in specific directory
opencode acp --cwd /path/to/project

Integration with Zed

Add to ~/.config/zed/settings.json:

{
  "agent_servers": {
    "OpenCode": {
      "command": "opencode",
      "args": ["acp"]
    }
  }
}

Testing

cd packages/opencode
bun test test/acp.test.ts
# ✅ 2 pass, 0 fail, 5 expect() calls

Future Work

The foundation is in place for incremental improvements:

  • Streaming responses via session/update notifications
  • Tool call progress reporting
  • Session modes (ask, code, architect)
  • Full session persistence
  • Terminal integration

These can be added without breaking changes to the current implementation.

Documentation

See packages/opencode/src/acp/README.md for detailed architecture documentation, protocol compliance checklist, and usage examples.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2947 **State:** closed **Merged:** Yes --- ## Summary Implements a clean, protocol-compliant ACP (Agent Client Protocol) server that enables opencode to work as an agent in Zed and other ACP-compatible clients. This is a massive improvement over the initial implementation https://github.com/sst/opencode/pull/2422 This is a complete rewrite of the previous ACP implementation, now using the official `@zed-industries/agent-client-protocol` library and following the ACP v1 specification. ## Changes ### Core Implementation - **agent.ts**: Full `Agent` interface implementation with proper protocol compliance - **client.ts**: `Client` interface for file operations and permission handling - **session.ts**: Session state management with working directory context - **server.ts**: Server lifecycle using official ACP library with stdio transport - **types.ts**: Type definitions for internal state ### CLI Integration - New `opencode acp` command - Working directory support via `--cwd` flag - Graceful shutdown on SIGTERM/SIGINT ### Testing - Comprehensive test suite in `test/acp.test.ts` - Tests protocol initialization and session creation - All tests passing ✅ ## Protocol Compliance Follows ACP specification v1 with proper: - ✅ Protocol version negotiation - ✅ Capability advertisement (`agentCapabilities`) - ✅ Session lifecycle (`session/new`, `session/load`) - ✅ Standard request/response formats - ✅ File operations via Client interface - ✅ Permission request handling ## Architecture Benefits **Compared to previous implementation:** - Uses official library instead of custom JSON-RPC handling - Protocol-compliant message formats (works with Zed out of the box) - Proper session management with working directory context - Clean separation of concerns (agent, client, session, server) - Foundation for streaming and tool call reporting ## Usage ### Command Line ```bash # Start ACP server opencode acp # Start in specific directory opencode acp --cwd /path/to/project ``` ### Integration with Zed Add to `~/.config/zed/settings.json`: ```json { "agent_servers": { "OpenCode": { "command": "opencode", "args": ["acp"] } } } ``` ## Testing ```bash cd packages/opencode bun test test/acp.test.ts # ✅ 2 pass, 0 fail, 5 expect() calls ``` ## Future Work The foundation is in place for incremental improvements: - Streaming responses via `session/update` notifications - Tool call progress reporting - Session modes (ask, code, architect) - Full session persistence - Terminal integration These can be added without breaking changes to the current implementation. ## Documentation See `packages/opencode/src/acp/README.md` for detailed architecture documentation, protocol compliance checklist, and usage examples.
yindo added the pull-request label 2026-02-16 18:15:09 -05:00
yindo closed this issue 2026-02-16 18:15:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10494