use anyhow::Result;
use std::path::PathBuf;
pub const OLLAMA_AGENT: &str = include_str!("../../scripts/fix_agent_ollama.py");
pub const CLAUDE_AGENT: &str = include_str!("../../scripts/fix_agent.py");
pub fn get_scripts_dir() -> Result<PathBuf> {
let dir = dirs::data_local_dir()
.unwrap_or_else(|| PathBuf::from("."))
.join("repotoire")
.join("scripts");
std::fs::create_dir_all(&dir)?;
Ok(dir)
}
pub fn extract_scripts() -> Result<(PathBuf, PathBuf)> {
let dir = get_scripts_dir()?;
let ollama_path = dir.join("fix_agent_ollama.py");
let claude_path = dir.join("fix_agent.py");
std::fs::write(&ollama_path, OLLAMA_AGENT)?;
std::fs::write(&claude_path, CLAUDE_AGENT)?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let perms = std::fs::Permissions::from_mode(0o755);
std::fs::set_permissions(&ollama_path, perms.clone())?;
std::fs::set_permissions(&claude_path, perms)?;
}
Ok((ollama_path, claude_path))
}
pub fn get_script_paths(repo_path: &std::path::Path) -> Result<(PathBuf, PathBuf)> {
let local_ollama = repo_path.join("scripts/fix_agent_ollama.py");
let local_claude = repo_path.join("scripts/fix_agent.py");
if local_ollama.exists() && local_claude.exists() {
return Ok((local_ollama, local_claude));
}
extract_scripts()
}