acp/sync/adapters/
aider.rs1use std::path::Path;
4
5use crate::error::Result;
6use crate::sync::adapter::{BootstrapContext, DetectionResult, ToolAdapter};
7use crate::sync::content::generate_bootstrap_yaml;
8use crate::sync::tool::{MergeStrategy, Tool};
9
10pub struct AiderAdapter;
12
13impl ToolAdapter for AiderAdapter {
14 fn tool(&self) -> Tool {
15 Tool::Aider
16 }
17
18 fn detect(&self, project_root: &Path) -> DetectionResult {
19 let config_file = project_root.join(".aider.conf.yml");
20
21 DetectionResult {
22 tool: Tool::Aider,
23 detected: config_file.exists(),
24 reason: if config_file.exists() {
25 ".aider.conf.yml exists".into()
26 } else {
27 "Not detected".into()
28 },
29 existing_file: if config_file.exists() {
30 Some(config_file)
31 } else {
32 None
33 },
34 }
35 }
36
37 fn generate(&self, _context: &BootstrapContext) -> Result<String> {
38 Ok(generate_bootstrap_yaml(Tool::Aider))
39 }
40
41 fn validate(&self, content: &str) -> Result<()> {
42 serde_yaml::from_str::<serde_yaml::Value>(content)
43 .map_err(|e| crate::error::AcpError::Other(format!("Invalid YAML: {}", e)))?;
44 Ok(())
45 }
46
47 fn merge_strategy(&self) -> MergeStrategy {
48 MergeStrategy::Section
49 }
50
51 fn section_markers(&self) -> (&'static str, &'static str) {
52 (
53 "# BEGIN ACP GENERATED CONTENT - DO NOT EDIT",
54 "# END ACP GENERATED CONTENT",
55 )
56 }
57}