opencrates 3.0.1

Enterprise-grade AI-powered Rust development companion with comprehensive automation, monitoring, and deployment capabilities
use anyhow::Result;
use std::process::Command;
use std::path::Path;

/// Aider integration for OpenCrates
// TODO: document this
// TODO: document this
// TODO: document this
pub struct AiderIntegration {
    project_path: String,
    model: String,
}

impl AiderIntegration {
    // TODO: document this
    // TODO: document this
    // TODO: document this
    // TODO: document this
    pub fn new(project_path: impl Into<String>, model: impl Into<String>) -> Self {
        Self {
            project_path: project_path.into(),
            model: model.into(),
        }
    }

    /// Run aider on the project
    // TODO: document this
    // TODO: document this
    // TODO: document this
    // TODO: document this
    pub fn run_aider(&self, instructions: &str) -> Result<String> {
        let output = Command::new("aider")
            .arg("--model")
            .arg(&self.model)
            .arg("--message")
            .arg(instructions)
            .current_dir(&self.project_path)
            .output()?;

        if output.status.success() {
            Ok(String::from_utf8_lossy(&output.stdout).to_string())
        } else {
            anyhow::bail!("Aider command failed: {}", String::from_utf8_lossy(&output.stderr))
        }
    }

    /// Check if aider is installed
    // TODO: document this
    // TODO: document this
    // TODO: document this
    // TODO: document this
    pub fn is_available() -> bool {
        Command::new("aider")
            .arg("--version")
            .output()
            .map(|output| output.status.success())
            .unwrap_or(false)
    }
}