File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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;
67use anyhow:: { Result , bail} ;
78use clap:: Parser ;
89use 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) ]
129132mod tests {
130133 use super :: * ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments