Skip to content

Commit 6303231

Browse files
author
Greyforge Admin
committed
Respect CORTEX_HOME for ACP agent lookup
1 parent 7954d02 commit 6303231

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

src/cortex-cli/src/acp_cmd.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! The ACP protocol enables IDE integration (like Zed) with Cortex.
44
//! Supports both stdio and HTTP transports for flexible integration.
55
6+
use crate::utils::paths::get_cortex_home;
67
use anyhow::{Result, bail};
78
use clap::Parser;
89
use cortex_common::resolve_model_alias;
@@ -58,9 +59,7 @@ impl AcpCli {
5859
pub async fn run(self) -> Result<()> {
5960
// Validate agent exists early if specified (Issue #1958)
6061
if let Some(ref agent_name) = self.agent {
61-
let cortex_home = dirs::home_dir()
62-
.map(|h| h.join(".cortex"))
63-
.ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?;
62+
let cortex_home = acp_agent_registry_home();
6463
let cwd = std::env::current_dir().ok();
6564
let registry = cortex_engine::AgentRegistry::new(&cortex_home, cwd.as_deref());
6665
// Scan for agents in standard locations
@@ -125,6 +124,10 @@ impl AcpCli {
125124
}
126125
}
127126

127+
fn acp_agent_registry_home() -> PathBuf {
128+
get_cortex_home()
129+
}
130+
128131
#[cfg(test)]
129132
mod tests {
130133
use super::*;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::process::Command;
2+
3+
use tempfile::tempdir;
4+
5+
#[test]
6+
fn acp_agent_lookup_uses_cortex_home() {
7+
let temp_dir = tempdir().unwrap();
8+
let agent_dir = temp_dir.path().join("agents").join("testacpagent");
9+
std::fs::create_dir_all(&agent_dir).unwrap();
10+
std::fs::write(
11+
agent_dir.join("AGENT.md"),
12+
r#"---
13+
name: testacpagent
14+
description: Test ACP agent
15+
---
16+
17+
Test prompt
18+
"#,
19+
)
20+
.unwrap();
21+
22+
let output = Command::new(env!("CARGO_BIN_EXE_Cortex"))
23+
.args([
24+
"acp",
25+
"--agent",
26+
"testacpagent",
27+
"--port",
28+
"1",
29+
"--host",
30+
"not a socket address",
31+
])
32+
.env("CORTEX_HOME", temp_dir.path())
33+
.output()
34+
.unwrap();
35+
36+
let stderr = String::from_utf8_lossy(&output.stderr);
37+
assert!(!output.status.success());
38+
assert!(
39+
!stderr.contains("Agent not found"),
40+
"ACP ignored CORTEX_HOME and failed agent lookup: {stderr}"
41+
);
42+
}

0 commit comments

Comments
 (0)