1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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)
}
}