use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::time::Duration;
use synaptic_core::SynapticError;
pub mod state;
pub mod store;
#[cfg(feature = "filesystem")]
pub mod filesystem;
pub use state::StateBackend;
pub use store::StoreBackend;
#[cfg(feature = "filesystem")]
pub use filesystem::FilesystemBackend;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DirEntry {
pub name: String,
pub is_dir: bool,
pub size: Option<u64>,
}
#[derive(Debug, Clone)]
pub struct ExecResult {
pub stdout: String,
pub stderr: String,
pub exit_code: i32,
}
#[derive(Debug, Clone)]
pub struct GrepMatch {
pub file: String,
pub line_number: usize,
pub line: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GrepOutputMode {
FilesWithMatches,
Content,
Count,
}
#[async_trait]
pub trait Backend: Send + Sync {
async fn ls(&self, path: &str) -> Result<Vec<DirEntry>, SynapticError>;
async fn read_file(
&self,
path: &str,
offset: usize,
limit: usize,
) -> Result<String, SynapticError>;
async fn write_file(&self, path: &str, content: &str) -> Result<(), SynapticError>;
async fn edit_file(
&self,
path: &str,
old_text: &str,
new_text: &str,
replace_all: bool,
) -> Result<(), SynapticError>;
async fn glob(&self, pattern: &str, base: &str) -> Result<Vec<String>, SynapticError>;
async fn grep(
&self,
pattern: &str,
path: Option<&str>,
file_glob: Option<&str>,
output_mode: GrepOutputMode,
) -> Result<String, SynapticError>;
async fn execute(
&self,
_command: &str,
_timeout: Option<Duration>,
) -> Result<ExecResult, SynapticError> {
Err(SynapticError::Tool(
"execution not supported by this backend".into(),
))
}
fn supports_execution(&self) -> bool {
false
}
}