Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4cb928630e | ||
![]() |
cd0263bb85 | ||
![]() |
6d775db481 |
6 changed files with 150 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
||||||
mod claude;
|
mod claude;
|
||||||
|
mod codex;
|
||||||
mod gemini;
|
mod gemini;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod stdio_agent_server;
|
mod stdio_agent_server;
|
||||||
|
@ -7,6 +8,7 @@ mod stdio_agent_server;
|
||||||
mod e2e_tests;
|
mod e2e_tests;
|
||||||
|
|
||||||
pub use claude::*;
|
pub use claude::*;
|
||||||
|
pub use codex::*;
|
||||||
pub use gemini::*;
|
pub use gemini::*;
|
||||||
pub use settings::*;
|
pub use settings::*;
|
||||||
pub use stdio_agent_server::*;
|
pub use stdio_agent_server::*;
|
||||||
|
|
121
crates/agent_servers/src/codex.rs
Normal file
121
crates/agent_servers/src/codex.rs
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
use crate::stdio_agent_server::StdioAgentServer;
|
||||||
|
use crate::{AgentServerCommand, AgentServerVersion};
|
||||||
|
use anyhow::{Context as _, Result};
|
||||||
|
use gpui::{AsyncApp, Entity};
|
||||||
|
use project::Project;
|
||||||
|
use settings::SettingsStore;
|
||||||
|
|
||||||
|
use crate::AllAgentServersSettings;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Codex;
|
||||||
|
|
||||||
|
const ACP_ARG: &str = "experimental-acp";
|
||||||
|
|
||||||
|
impl StdioAgentServer for Codex {
|
||||||
|
fn name(&self) -> &'static str {
|
||||||
|
"Codex"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn empty_state_headline(&self) -> &'static str {
|
||||||
|
"Welcome to Codex"
|
||||||
|
}
|
||||||
|
|
||||||
|
fn empty_state_message(&self) -> &'static str {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
fn supports_always_allow(&self) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn logo(&self) -> ui::IconName {
|
||||||
|
ui::IconName::AiOpenAi
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn command(
|
||||||
|
&self,
|
||||||
|
project: &Entity<Project>,
|
||||||
|
cx: &mut AsyncApp,
|
||||||
|
) -> Result<AgentServerCommand> {
|
||||||
|
let settings = cx.read_global(|settings: &SettingsStore, _| {
|
||||||
|
settings.get::<AllAgentServersSettings>(None).codex.clone()
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if let Some(command) =
|
||||||
|
AgentServerCommand::resolve("codex", &[ACP_ARG], settings, &project, cx).await
|
||||||
|
{
|
||||||
|
return Ok(command);
|
||||||
|
};
|
||||||
|
|
||||||
|
let (fs, node_runtime) = project.update(cx, |project, _| {
|
||||||
|
(project.fs().clone(), project.node_runtime().cloned())
|
||||||
|
})?;
|
||||||
|
let node_runtime = node_runtime.context("codex not found on path")?;
|
||||||
|
|
||||||
|
let directory = ::paths::agent_servers_dir().join("codex");
|
||||||
|
fs.create_dir(&directory).await?;
|
||||||
|
node_runtime
|
||||||
|
.npm_install_packages(&directory, &[("@openai/codex", "latest")])
|
||||||
|
.await?;
|
||||||
|
let path = directory.join("node_modules/.bin/codex");
|
||||||
|
|
||||||
|
Ok(AgentServerCommand {
|
||||||
|
path,
|
||||||
|
args: vec![ACP_ARG.into()],
|
||||||
|
env: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn version(&self, command: &AgentServerCommand) -> Result<AgentServerVersion> {
|
||||||
|
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 {
|
||||||
|
Ok(AgentServerVersion::Supported)
|
||||||
|
} else {
|
||||||
|
Ok(AgentServerVersion::Unsupported {
|
||||||
|
error_message: format!(
|
||||||
|
"Your installed version of Codex {} doesn't support the Agentic Coding Protocol (ACP).",
|
||||||
|
current_version
|
||||||
|
).into(),
|
||||||
|
upgrade_message: "Upgrade Codex to Latest".into(),
|
||||||
|
upgrade_command: "npm install -g @openai/codex@latest".into(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) mod tests {
|
||||||
|
use super::*;
|
||||||
|
use crate::AgentServerCommand;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
crate::common_e2e_tests!(Codex);
|
||||||
|
|
||||||
|
pub fn local_command() -> AgentServerCommand {
|
||||||
|
let cli_path = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("../../../codex/codex-rs/target/debug/codex");
|
||||||
|
|
||||||
|
AgentServerCommand {
|
||||||
|
path: cli_path,
|
||||||
|
args: vec![],
|
||||||
|
env: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -307,6 +307,9 @@ pub async fn init_test(cx: &mut TestAppContext) -> Arc<FakeFs> {
|
||||||
claude: Some(AgentServerSettings {
|
claude: Some(AgentServerSettings {
|
||||||
command: crate::claude::tests::local_command(),
|
command: crate::claude::tests::local_command(),
|
||||||
}),
|
}),
|
||||||
|
codex: Some(AgentServerSettings {
|
||||||
|
command: crate::codex::tests::local_command(),
|
||||||
|
}),
|
||||||
gemini: Some(AgentServerSettings {
|
gemini: Some(AgentServerSettings {
|
||||||
command: crate::gemini::tests::local_command(),
|
command: crate::gemini::tests::local_command(),
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -13,6 +13,7 @@ pub fn init(cx: &mut App) {
|
||||||
pub struct AllAgentServersSettings {
|
pub struct AllAgentServersSettings {
|
||||||
pub gemini: Option<AgentServerSettings>,
|
pub gemini: Option<AgentServerSettings>,
|
||||||
pub claude: Option<AgentServerSettings>,
|
pub claude: Option<AgentServerSettings>,
|
||||||
|
pub codex: Option<AgentServerSettings>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, JsonSchema, Debug)]
|
#[derive(Deserialize, Serialize, Clone, JsonSchema, Debug)]
|
||||||
|
@ -29,9 +30,20 @@ impl settings::Settings for AllAgentServersSettings {
|
||||||
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
|
fn load(sources: SettingsSources<Self::FileContent>, _: &mut App) -> Result<Self> {
|
||||||
let mut settings = AllAgentServersSettings::default();
|
let mut settings = AllAgentServersSettings::default();
|
||||||
|
|
||||||
for value in sources.defaults_and_customizations() {
|
for AllAgentServersSettings {
|
||||||
if value.gemini.is_some() {
|
gemini,
|
||||||
settings.gemini = value.gemini.clone();
|
claude,
|
||||||
|
codex,
|
||||||
|
} in sources.defaults_and_customizations()
|
||||||
|
{
|
||||||
|
if gemini.is_some() {
|
||||||
|
settings.gemini = gemini.clone();
|
||||||
|
}
|
||||||
|
if claude.is_some() {
|
||||||
|
settings.claude = claude.clone();
|
||||||
|
}
|
||||||
|
if codex.is_some() {
|
||||||
|
settings.codex = codex.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1910,6 +1910,13 @@ impl AgentPanel {
|
||||||
}
|
}
|
||||||
.boxed_clone(),
|
.boxed_clone(),
|
||||||
)
|
)
|
||||||
|
.action(
|
||||||
|
"New Codex Thread",
|
||||||
|
NewExternalAgentThread {
|
||||||
|
agent: Some(crate::ExternalAgent::Codex),
|
||||||
|
}
|
||||||
|
.boxed_clone(),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
menu
|
menu
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -147,6 +147,7 @@ enum ExternalAgent {
|
||||||
#[default]
|
#[default]
|
||||||
Gemini,
|
Gemini,
|
||||||
ClaudeCode,
|
ClaudeCode,
|
||||||
|
Codex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExternalAgent {
|
impl ExternalAgent {
|
||||||
|
@ -154,6 +155,7 @@ impl ExternalAgent {
|
||||||
match self {
|
match self {
|
||||||
ExternalAgent::Gemini => Rc::new(agent_servers::Gemini),
|
ExternalAgent::Gemini => Rc::new(agent_servers::Gemini),
|
||||||
ExternalAgent::ClaudeCode => Rc::new(agent_servers::ClaudeCode),
|
ExternalAgent::ClaudeCode => Rc::new(agent_servers::ClaudeCode),
|
||||||
|
ExternalAgent::Codex => Rc::new(agent_servers::Codex),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue