use std::sync::Arc;
use crate::session::{PromptManager, SessionManager};
use crate::types::AgentConfig;
#[derive(Debug)]
pub struct ClaudeAcpAgent {
config: AgentConfig,
sessions: Arc<SessionManager>,
prompt_manager: Arc<PromptManager>,
}
impl ClaudeAcpAgent {
pub fn new() -> Self {
let project_dir = std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."));
let config = AgentConfig::from_settings_or_env(&project_dir);
tracing::info!(
model = ?config.model,
base_url = ?config.base_url,
api_key = ?config.masked_api_key(),
"Agent initialized with configuration"
);
Self {
config,
sessions: Arc::new(SessionManager::new()),
prompt_manager: Arc::new(PromptManager::new()),
}
}
pub fn with_config(config: AgentConfig) -> Self {
Self {
config,
sessions: Arc::new(SessionManager::new()),
prompt_manager: Arc::new(PromptManager::new()),
}
}
pub fn config(&self) -> &AgentConfig {
&self.config
}
pub fn sessions(&self) -> &Arc<SessionManager> {
&self.sessions
}
pub fn prompt_manager(&self) -> &Arc<PromptManager> {
&self.prompt_manager
}
pub fn name(&self) -> &'static str {
"claude-code-acp-rs"
}
pub fn version(&self) -> &'static str {
env!("CARGO_PKG_VERSION")
}
}
impl Default for ClaudeAcpAgent {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_agent_new() {
let agent = ClaudeAcpAgent::new();
assert_eq!(agent.name(), "claude-code-acp-rs");
assert_eq!(agent.sessions().session_count(), 0);
}
#[test]
fn test_agent_with_config() {
let config = AgentConfig {
base_url: Some("https://api.example.com".to_string()),
api_key: Some("test-key".to_string()),
model: Some("claude-3-opus".to_string()),
small_fast_model: None,
max_thinking_tokens: Some(4096),
};
let agent = ClaudeAcpAgent::with_config(config);
assert_eq!(
agent.config().base_url,
Some("https://api.example.com".to_string())
);
assert_eq!(agent.config().max_thinking_tokens, Some(4096));
}
}