use super::*;
pub struct ToolContext {
pub workdir: PathBuf,
file_locks: Arc<Mutex<HashMap<PathBuf, Arc<tokio::sync::Mutex<()>>>>>,
}
impl ToolContext {
pub fn new(workdir: PathBuf) -> Self {
let workdir = std::fs::canonicalize(&workdir).unwrap_or(workdir);
Self {
workdir,
file_locks: Arc::new(Mutex::new(HashMap::new())),
}
}
pub(crate) fn lock_for(&self, path: &Path) -> Arc<tokio::sync::Mutex<()>> {
let mut map = self
.file_locks
.lock()
.unwrap_or_else(PoisonError::into_inner);
map.entry(path.to_path_buf())
.or_insert_with(|| Arc::new(tokio::sync::Mutex::new(())))
.clone()
}
}
pub const TOOL_ALIASES: &[(&str, &str)] = &[
("bash", "shell"),
];
pub fn canonical_tool_name(name: &str) -> &str {
for (alias, canonical) in TOOL_ALIASES {
if *alias == name {
return canonical;
}
}
name
}
pub trait ShellExecutor: Send + Sync {
fn build_command(&self, shell: &str, flag: &str, command: &str, workdir: &Path) -> Command;
}