acp/sync/
adapter.rs

1//! @acp:module "Tool Adapter Trait"
2//! @acp:summary "Trait definition for tool-specific adapters"
3//! @acp:domain cli
4//! @acp:layer service
5
6use std::path::{Path, PathBuf};
7
8use super::tool::{MergeStrategy, Tool};
9use crate::error::Result;
10
11/// Result of tool detection
12#[derive(Debug)]
13pub struct DetectionResult {
14    pub tool: Tool,
15    pub detected: bool,
16    pub reason: String,
17    pub existing_file: Option<PathBuf>,
18}
19
20/// Context for bootstrap content generation
21#[derive(Debug)]
22pub struct BootstrapContext<'a> {
23    pub project_root: &'a Path,
24    pub tool: Tool,
25}
26
27/// Tool adapter trait - implement for each supported tool
28pub trait ToolAdapter: Send + Sync {
29    /// Get the tool identifier
30    fn tool(&self) -> Tool;
31
32    /// Detect if this tool is in use in the project
33    fn detect(&self, project_root: &Path) -> DetectionResult;
34
35    /// Generate bootstrap content for this tool
36    fn generate(&self, context: &BootstrapContext) -> Result<String>;
37
38    /// Validate generated content
39    fn validate(&self, content: &str) -> Result<()> {
40        let _ = content;
41        Ok(())
42    }
43
44    /// Get the merge strategy for existing files
45    fn merge_strategy(&self) -> MergeStrategy {
46        MergeStrategy::Section
47    }
48
49    /// Get section markers for content preservation
50    fn section_markers(&self) -> (&'static str, &'static str) {
51        (
52            "<!-- BEGIN ACP GENERATED CONTENT - DO NOT EDIT -->",
53            "<!-- END ACP GENERATED CONTENT -->",
54        )
55    }
56}