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 ACP_ARG: &str = "--experimental-acp";
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 cx.spawn(async move |cx| {
45 let settings = cx.read_global(|settings: &SettingsStore, _| {
46 settings.get::<AllAgentServersSettings>(None).gemini.clone()
47 })?;
48
49 let Some(command) =
50 AgentServerCommand::resolve("gemini", &[ACP_ARG], settings, &project, cx).await
51 else {
52 anyhow::bail!("Failed to find gemini binary");
53 };
54 // todo! check supported version
55
56 let conn = AcpConnection::stdio(server_name, command, cx).await?;
57 Ok(Rc::new(conn) as _)
58 })
59 }
60}
61
62#[cfg(test)]
63pub(crate) mod tests {
64 use super::*;
65 use crate::AgentServerCommand;
66 use std::path::Path;
67
68 crate::common_e2e_tests!(Gemini, allow_option_id = "0");
69
70 pub fn local_command() -> AgentServerCommand {
71 let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
72 .join("../../../gemini-cli/packages/cli")
73 .to_string_lossy()
74 .to_string();
75
76 AgentServerCommand {
77 path: "node".into(),
78 args: vec![cli_path],
79 env: None,
80 }
81 }
82}