Repository navigation
Zed integration - #4266
Zed integration#4266
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Summary of Changes
Hello @ConradIrwin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a significant architectural change by implementing an experimental Agent Communication Protocol (ACP) within the Gemini CLI. This protocol enables external graphical user interfaces, specifically the Zed editor, to seamlessly integrate with and control the Gemini agent. The core impact is a shift from a terminal-based interaction to a more robust, structured JSON-RPC communication, allowing for a richer and more integrated user experience within IDEs by providing detailed tool execution feedback, visual cues, and contextual file information.
Highlights
- Zed Integration: Implemented a new
--experimental-acpCLI flag that allows Gemini to run in a headless mode, communicating over stdin/stdout to power the Agent panel within the Zed editor, providing a tightly integrated user experience. - Enhanced Tooling Metadata: All core tools now include
iconandtoolLocationsproperties, enabling external UIs to display relevant visual cues and contextual file information (paths and line numbers) for tool actions. - Improved Diff Representation: Updated data structures for file diffs (
FileDiff,ToolEditConfirmationDetails) to explicitly includeoriginalContentandnewContent, facilitating richer and more accurate diff visualizations in integrated UIs.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This PR introduces a significant new feature: an experimental mode for integrating Gemini with the Zed editor via a JSON-RPC protocol. The changes are extensive, adding new files for the protocol (acp.ts) and the agent peer implementation (acpPeer.ts), and modifying many core tool files to support the new UI capabilities like icons and file locations.
The implementation of the JSON-RPC layer and the agent logic looks solid, but I've identified a critical issue with error handling in the communication channel that could lead to silent failures. I've also pointed out a high-risk area in the acpPeer where brittle string parsing could lead to correctness issues down the line.
Overall, this is a well-structured PR for a complex feature. Addressing the identified issues will improve the robustness and maintainability of this new integration.
There was a problem hiding this comment.
The current implementation of the .catch() block swallows errors from writer.write(). If the underlying stream is closed or encounters an error (e.g., the Zed process crashes), all subsequent attempts to send messages will fail silently.
This creates a failure mode that is very difficult to debug, as the agent will appear to be working but no messages will reach the client.
At a minimum, the error should be logged to stderr. A more robust solution might involve marking the connection as failed and stopping any further attempts to write to the broken stream.
.catch((error) => {
// Log the error to aid in debugging a broken pipe.
// This avoids silent failures if the client process has exited.
console.error('ACP write error:', error);
});There was a problem hiding this comment.
This logic for parsing the output of the read_many_files tool using a regular expression is quite brittle. It creates a tight coupling between this component and the specific string format produced by the tool. If the separator format in read_many_files changes in the future, this parsing logic will break, leading to malformed context being sent to the LLM.
A more robust approach would be for the read_many_files tool to return a more structured result (e.g., an array of {path: string, content: Part} objects) instead of a formatted string that needs to be parsed back into its components. This would make the communication between components more reliable and easier to maintain.
|
What's the reasoning behind using ACP versus A2A? |
|
@chrstnb A2A is designed for a very different use-case (potentially untrusted agents distributed across the internet. It mandates things that don't make sense (like https transport with valid certificates) and doesn't provide things that are necessary for a good user experience for coding agents (currently diffs in tool output, but we're working on a mode for proxied file system and other mode editor specific concerns). |
|
Amazing feature, attaching my recording to make it easier to understand how it works Screencast_20250716_153629.mp4 |
|
@LiberQuack yes! although not implemented in this PR, we're also working on Zed's MCP server support to allow this. |
|
Hey @ConradIrwin, that's awesome! Between us... I used same IDE for the last 10 years, but now my primary one is Zed, you guys are doing a brilliant job!!! ❤️ ❤️ ❤️ |
NTaylorMullen
left a comment
There was a problem hiding this comment.
Super excited for Zed's amplification here + that these changes are IDE agnostic and enable all IDEs to do the same. In addition I appreciate the effort in trying to limit the blast radius of a change like this.
All that said I can see some overlap between ACP and A2A but it's far too early to be able to understand which path makes the most sense. Because of this lets get this in and experiment! We may end up needing to swap to A2A OR swap more of our stack to ACP, experimentation will tell all!
There was a problem hiding this comment.
| Icon, // Import from core | |
| Icon, |
|
Looks like you'll need to address some conflicts as well before merge |
This PR introduces an experimental mode for Gemini to allow it to be used to power the Agent panel within Zed. This integration allows Zed to provide an alternative UI for Gemini that is tightly integrated with the editor, showing diffs and file changes in context, and letting the user edit files as they go. Zed takes responsibility for the life-cycle, and boots Gemini with `--experimental-acp`, before talking to it over our experimental ACP protocol. Based on our experience making this work with Gemini and Zed, we hope (in the future) to be able to re-use for multiple agents and IDEs. It currently covers just what we needed to make this work: initialization and authorization, and the ability to stream assistant messages and tool calls (including permission prompts) to the UI. Co-Authored-By: Agus Zubiaga <[email protected]> Co-Authored-By: Ben Brandt <[email protected]> Co-authored-by: mkorwel <[email protected]>
8ff65ae to
917d79f
Compare
Co-authored-by: Agus Zubiaga <[email protected]> Co-authored-by: Ben Brandt <[email protected]> Co-authored-by: mkorwel <[email protected]>
Co-authored-by: Agus Zubiaga <[email protected]> Co-authored-by: Ben Brandt <[email protected]> Co-authored-by: mkorwel <[email protected]>
hi, can you give a detailed guide on this ? I try to config it in ZED , but failed, Thanks |
|
@mymark21 if you build zed from scratch with the following git diff you'll see Gemini & Claude Code appear as options when creating a new agent thread diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs
index 7f2fbce189..055cef1753 100644
--- a/crates/agent_ui/src/agent_panel.rs
+++ b/crates/agent_ui/src/agent_panel.rs
@@ -1900,9 +1900,7 @@ impl AgentPanel {
let active_thread = active_thread.clone();
Some(ContextMenu::build(window, cx, |mut menu, _window, cx| {
menu = menu
- .when(cx.has_flag::<feature_flags::AcpFeatureFlag>(), |this| {
- this.header("Zed Agent")
- })
+ .header("Zed Agent")
.action("New Thread", NewThread::default().boxed_clone())
.action("New Text Thread", NewTextThread.boxed_clone())
.when_some(active_thread, |this, active_thread| {
@@ -1918,24 +1916,22 @@ impl AgentPanel {
this
}
})
- .when(cx.has_flag::<feature_flags::AcpFeatureFlag>(), |this| {
- this.separator()
- .header("External Agents")
- .action(
- "New Gemini Thread",
- NewExternalAgentThread {
- agent: Some(crate::ExternalAgent::Gemini),
- }
- .boxed_clone(),
- )
- .action(
- "New Claude Code Thread",
- NewExternalAgentThread {
- agent: Some(crate::ExternalAgent::ClaudeCode),
- }
- .boxed_clone(),
- )
- });
+ .separator()
+ .header("External Agents")
+ .action(
+ "New Gemini Thread",
+ NewExternalAgentThread {
+ agent: Some(crate::ExternalAgent::Gemini),
+ }
+ .boxed_clone(),
+ )
+ .action(
+ "New Claude Code Thread",
+ NewExternalAgentThread {
+ agent: Some(crate::ExternalAgent::ClaudeCode),
+ }
+ .boxed_clone(),
+ );
menu
}))
});
for gemini you can do this in your zed "agent_servers": {
"gemini": {
"command": "gemini",
"args": ["--experimental-acp"],
"env": { "GEMINI_API_KEY": "<key here>" }
}
}and for claude code support it should just work as long as your cli is already set up |
|
FYI this is likely to break again over the next few releases as we are making some big changes to how it works. |
|
@versecafe my approach is a little bit different, in case you are interested, that's the change I do locally. Im basically enabling all flags diff --git a/crates/feature_flags/src/feature_flags.rs b/crates/feature_flags/src/feature_flags.rs
--- a/crates/feature_flags/src/feature_flags.rs
+++ b/crates/feature_flags/src/feature_flags.rs
@@ -19,15 +19,7 @@ pub static ZED_DISABLE_STAFF: LazyLock<bool> = LazyLock::new(|| {
impl FeatureFlags {
fn has_flag<T: FeatureFlag>(&self) -> bool {
- if T::enabled_for_all() {
- return true;
- }
-
- if self.staff && T::enabled_for_staff() {
- return true;
- }
-
- self.flags.iter().any(|f| f.as_str() == T::NAME)
+ return true;
}
} |
Co-authored-by: Agus Zubiaga <[email protected]> Co-authored-by: Ben Brandt <[email protected]> Co-authored-by: mkorwel <[email protected]>
|
Hey there! @ConradIrwin or @agu-z Could you add me to the feature flag? |
Co-authored-by: Agus Zubiaga <[email protected]> Co-authored-by: Ben Brandt <[email protected]> Co-authored-by: mkorwel <[email protected]>
Co-authored-by: Agus Zubiaga <[email protected]> Co-authored-by: Ben Brandt <[email protected]> Co-authored-by: mkorwel <[email protected]>
Co-authored-by: Agus Zubiaga <[email protected]> Co-authored-by: Ben Brandt <[email protected]> Co-authored-by: mkorwel <[email protected]>

This PR introduces an experimental mode for Gemini to allow it to be used to
power the Agent panel within Zed.
Co-Authored-By: Agus Zubiaga [email protected]
Co-Authored-By: Ben Brandt [email protected]
Co-authored-by: mkorwel [email protected]
TLDR
This integration allows Zed to provide an alternative UI for Gemini that is
tightly integrated with the editor, showing diffs and file changes in context,
and letting the user edit files as they go.
Zed takes responsibility for the life-cycle, and boots Gemini with
--experimental-acp. In this mode Gemini will run a JSONRPC protocol overstdin/stdout instead of launching the existing terminal UI.
Dive Deeper
The primary change here is the new
--experimental-acpflag and the accompanyingacp/directory.There are two parts to the implementation:
acp.tscontains an experimental implementation of a JSONRPC protocol designed to allow UIs (like Zed) to control Agents (like Gemini). Based on feedback and improvements on how this works we would like to extract this out in the future, but for now we've just implemented the pieces we need to make the Zed/Gemini integration work.agentPeer.tscontains the logic that uses the existing core package to communicate over this protocol, replacing the existing terminal UI with one that can talk to Zed over stdin/stdout.The remaining changes are mostly to tools to add icons that we can show in the UI, and toolLocations
so that Zed can show the user where the agent's attention is focused.
Reviewer Test Plan
To fully test the integration, you'll need the latest version of Zed preview, and to add the following to your settings:
{ "agent_servers": { "gemini": { "command": "node", "args": ["/<PATH>/<TO>/gemini-cli/packages/cli", "--experimental-acp"] } }, }You will also need to be in the feature flag on the Zed side. Please ask @ConradIrwin, or @agu-z to be added.
To test this, you can open the Agent panel in Zed (the AI icon in the bottom right) and then click
+in the top right. You should see "New Gemini Thread". Once you click this, you can verify that Gemini works correctly, but that the Zed UI is used instead of the CLI.Testing Matrix
Linked issues / bugs
N/A