1use std::path::Path;
2use std::rc::Rc;
3
4use crate::{AgentServer, AgentServerCommand, acp_connection::AcpConnection};
5use acp_thread::AgentConnection;
6use anyhow::Result;
7use gpui::{Entity, Task};
8use project::Project;
9use settings::SettingsStore;
10use ui::App;
11
12use crate::AllAgentServersSettings;
13
14#[derive(Clone)]
15pub struct Gemini;
16
17const MCP_ARG: &str = "--experimental-mcp";
18
19impl AgentServer for Gemini {
20 fn name(&self) -> &'static str {
21 "Gemini"
22 }
23
24 fn empty_state_headline(&self) -> &'static str {
25 "Welcome to Gemini"
26 }
27
28 fn empty_state_message(&self) -> &'static str {
29 "Ask questions, edit files, run commands.\nBe specific for the best results."
30 }
31
32 fn logo(&self) -> ui::IconName {
33 ui::IconName::AiGemini
34 }
35
36 fn connect(
37 &self,
38 _root_dir: &Path,
39 project: &Entity<Project>,
40 cx: &mut App,
41 ) -> Task<Result<Rc<dyn AgentConnection>>> {
42 let project = project.clone();
43 let server_name = self.name();
44 let working_directory = project.read(cx).active_project_directory(cx);
45 cx.spawn(async move |cx| {
46 let settings = cx.read_global(|settings: &SettingsStore, _| {
47 settings.get::<AllAgentServersSettings>(None).gemini.clone()
48 })?;
49
50 let Some(command) =
51 AgentServerCommand::resolve("gemini", &[MCP_ARG], settings, &project, cx).await
52 else {
53 anyhow::bail!("Failed to find gemini binary");
54 };
55 // todo! check supported version
56
57 let conn = AcpConnection::stdio(server_name, command, working_directory, cx).await?;
58 Ok(Rc::new(conn) as _)
59 })
60 }
61}
62
63#[cfg(test)]
64pub(crate) mod tests {
65 use super::*;
66 use crate::AgentServerCommand;
67 use std::path::Path;
68
69 crate::common_e2e_tests!(Gemini, allow_option_id = "0");
70
71 pub fn local_command() -> AgentServerCommand {
72 let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
73 .join("../../../gemini-cli/packages/cli")
74 .to_string_lossy()
75 .to_string();
76
77 AgentServerCommand {
78 path: "node".into(),
79 args: vec![cli_path],
80 env: None,
81 }
82 }
83}