Handle startup failure for gemini-cli (#35624)

Cole Miller and Agus created

This PR adds handling for the case where the user's gemini-cli binary
fails to start up because it's too old to support the
`--experimental-acp` flag. We previously had such handling, but it got
lost as part of #35578.

This doesn't yet handle the case where the server binary exits
unexpectedly after the connection is established; that'll be dealt with
in a follow-up PR since it needs different handling and isn't specific
to gemini-cli.

Release Notes:

- N/A

Co-authored-by: Agus <agus@zed.dev>

Change summary

crates/agent_servers/src/gemini.rs | 34 ++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 2 deletions(-)

Detailed changes

crates/agent_servers/src/gemini.rs 🔗

@@ -2,7 +2,7 @@ use std::path::Path;
 use std::rc::Rc;
 
 use crate::{AgentServer, AgentServerCommand};
-use acp_thread::AgentConnection;
+use acp_thread::{AgentConnection, LoadError};
 use anyhow::Result;
 use gpui::{Entity, Task};
 use project::Project;
@@ -53,7 +53,37 @@ impl AgentServer for Gemini {
                 anyhow::bail!("Failed to find gemini binary");
             };
 
-            crate::acp::connect(server_name, command, &root_dir, cx).await
+            let result = crate::acp::connect(server_name, command.clone(), &root_dir, cx).await;
+            if result.is_err() {
+                let version_fut = util::command::new_smol_command(&command.path)
+                    .args(command.args.iter())
+                    .arg("--version")
+                    .kill_on_drop(true)
+                    .output();
+
+                let help_fut = util::command::new_smol_command(&command.path)
+                    .args(command.args.iter())
+                    .arg("--help")
+                    .kill_on_drop(true)
+                    .output();
+
+                let (version_output, help_output) = futures::future::join(version_fut, help_fut).await;
+
+                let current_version = String::from_utf8(version_output?.stdout)?;
+                let supported = String::from_utf8(help_output?.stdout)?.contains(ACP_ARG);
+
+                if !supported {
+                    return Err(LoadError::Unsupported {
+                        error_message: format!(
+                            "Your installed version of Gemini {} doesn't support the Agentic Coding Protocol (ACP).",
+                            current_version
+                        ).into(),
+                        upgrade_message: "Upgrade Gemini to Latest".into(),
+                        upgrade_command: "npm install -g @google/gemini-cli@latest".into(),
+                    }.into())
+                }
+            }
+            result
         })
     }
 }