Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/cortex-cli/src/acp_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +124,10 @@ impl AcpCli {
}
}

fn acp_agent_registry_home() -> PathBuf {
get_cortex_home()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
42 changes: 42 additions & 0 deletions src/cortex-cli/tests/acp_cortex_home.rs
Original file line number Diff line number Diff line change
@@ -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}"
);
}