use async_trait::async_trait;
#[derive(Clone, Debug)]
pub struct FileInfo {
pub path: String,
pub is_dir: bool,
pub size: u64,
pub modified_at: Option<u64>,
}
#[derive(Clone, Debug)]
pub struct WriteResult {
pub error: Option<String>,
pub path: Option<String>,
}
#[derive(Clone, Debug)]
pub struct EditResult {
pub error: Option<String>,
pub path: Option<String>,
pub occurrences: Option<u32>,
}
#[derive(Clone, Debug)]
pub struct GrepMatch {
pub path: String,
pub line: u32,
pub text: String,
}
#[async_trait]
pub trait FileBackend: Send + Sync {
async fn ls_info(&self, path: &str) -> Result<Vec<FileInfo>, String>;
async fn read(&self, file_path: &str, offset: u32, limit: u32) -> Result<String, String>;
async fn write(&self, file_path: &str, content: &str) -> Result<WriteResult, String>;
async fn edit(
&self,
file_path: &str,
old_string: &str,
new_string: &str,
replace_all: bool,
) -> Result<EditResult, String>;
async fn glob_info(&self, pattern: &str, path: &str) -> Result<Vec<FileInfo>, String>;
async fn grep_raw(
&self,
pattern: &str,
path: Option<&str>,
glob_pattern: Option<&str>,
) -> Result<Vec<GrepMatch>, String>;
}