feat(acp): Agent Client Protocol support for Zed editor - #338
Merged
Conversation
Implement ACP v1 (Agent Client Protocol) agent that enables Whale to work as an AI coding agent inside Zed editor and other ACP-compatible clients. Key features: - JSON-RPC 2.0 over stdio transport with single-dispatcher architecture - Full ACP lifecycle: initialize, session/new, session/load, session/prompt, session/cancel, session/set_mode - Streaming agent_message_chunk / agent_thought_chunk / tool_call updates - session/request_permission forwarding for editor-native approval dialogs - Per-session cwd with dynamic toolset root / policy workspace switching - Merged global -> project -> config.local permission policy loading - Cancellation support for active and queued prompts - Session persistence via JSONL store with message replay - Integration tests with real DeepSeek API
Fixes: - Reload per-workspace policy when switching ACP session cwd (policyLoader) - Use pendingCancels slice for multiple queued prompt cancels - Clear isPending flag after acquiring promptMu for proper cleanup - Return actual session mode on session/load - Write parse-error responses via configured t.writer instead of os.Stdout - Set PermissionRule.Action field correctly via ParsePermissionAction - Mutex-guard activeCancel access in CallClientMethod
Contributor
Author
|
Hi @lnnttoo. Would you like to review this PR? |
Contributor
Will have a look ASAP. |
Cleanup: - Simplify handler.go: remove pendingCancel slice logic, use single cancel - Remove SetToolPolicy from agent.go (unused) - Remove SetRoot from toolset.go (use SetWorktreeContext instead) - Merge config layers properly in loadPermissionPolicy
Protect sctx.cancel read with mutex in notification handlers. Replace single pendingCancel with pendingCancels slice. Use transport writer for parse error responses.
8 insertions, 3 deletions.
- Clear isPending after acquiring promptMu\n- Write parse errors via t.writer.Encode
Minor cleanup.
Protect sctx.cancel with mutex, pendingCancels slice, parse error output via t.writer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement ACP v1 (Agent Client Protocol) agent that enables Whale to work as an AI coding agent inside Zed editor and other ACP-compatible clients.
Key features
initialize,session/new,session/load,session/prompt,session/cancel,session/set_modeagent_message_chunk/agent_thought_chunk/tool_call/planupdatessession/request_permissionforwarding for editor-native approval dialogscwdwith dynamic toolset root and policy workspace switching.whale/config.tomlsession/loadFiles changed
cmd/whale-acp/main.gointernal/acp/types.gointernal/acp/transport.gointernal/acp/handler.gointernal/acp/adapter.gointernal/acp/smoke_test.gointernal/agent/agent.gointernal/tools/toolset.goMakefilescripts/acp_smoke_test.shHow to use in Zed
Add to
~/.zed/settings.json:{ "agent_servers": { "Whale (DeepSeek)": { "type": "custom", "command": "/path/to/bin/whale-acp", "env": { "DEEPSEEK_API_KEY": "sk-..." } } } }Or run
make build-acpand connect any ACP-compatible client tobin/whale-acp.Testing
make build-acp DEEPSEEK_API_KEY=sk-... WHALE_ACP_BIN=bin/whale-acp go test -v ./internal/acp/