diff --git a/src/cortex-cli/src/acp_cmd.rs b/src/cortex-cli/src/acp_cmd.rs index ff6a586c..951d2cf8 100644 --- a/src/cortex-cli/src/acp_cmd.rs +++ b/src/cortex-cli/src/acp_cmd.rs @@ -3,6 +3,7 @@ //! The ACP protocol enables IDE integration (like Zed) with Cortex. //! Supports both stdio and HTTP transports for flexible integration. +use crate::utils::paths::get_cortex_home; use anyhow::{Result, bail}; use clap::Parser; use cortex_common::resolve_model_alias; @@ -58,9 +59,7 @@ impl AcpCli { pub async fn run(self) -> Result<()> { // Validate agent exists early if specified (Issue #1958) if let Some(ref agent_name) = self.agent { - let cortex_home = dirs::home_dir() - .map(|h| h.join(".cortex")) - .ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?; + let cortex_home = acp_agent_registry_home(); let cwd = std::env::current_dir().ok(); let registry = cortex_engine::AgentRegistry::new(&cortex_home, cwd.as_deref()); // Scan for agents in standard locations @@ -125,6 +124,10 @@ impl AcpCli { } } +fn acp_agent_registry_home() -> PathBuf { + get_cortex_home() +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/cortex-cli/tests/acp_cortex_home.rs b/src/cortex-cli/tests/acp_cortex_home.rs new file mode 100644 index 00000000..1ebaf6f3 --- /dev/null +++ b/src/cortex-cli/tests/acp_cortex_home.rs @@ -0,0 +1,42 @@ +use std::process::Command; + +use tempfile::tempdir; + +#[test] +fn acp_agent_lookup_uses_cortex_home() { + let temp_dir = tempdir().unwrap(); + let agent_dir = temp_dir.path().join("agents").join("testacpagent"); + std::fs::create_dir_all(&agent_dir).unwrap(); + std::fs::write( + agent_dir.join("AGENT.md"), + r#"--- +name: testacpagent +description: Test ACP agent +--- + +Test prompt +"#, + ) + .unwrap(); + + let output = Command::new(env!("CARGO_BIN_EXE_Cortex")) + .args([ + "acp", + "--agent", + "testacpagent", + "--port", + "1", + "--host", + "not a socket address", + ]) + .env("CORTEX_HOME", temp_dir.path()) + .output() + .unwrap(); + + let stderr = String::from_utf8_lossy(&output.stderr); + assert!(!output.status.success()); + assert!( + !stderr.contains("Agent not found"), + "ACP ignored CORTEX_HOME and failed agent lookup: {stderr}" + ); +}