synaptic_deep/backend/
mod.rs1use async_trait::async_trait;
2use serde::{Deserialize, Serialize};
3use std::time::Duration;
4use synaptic_core::SynapticError;
5
6pub mod state;
7pub mod store;
8
9#[cfg(feature = "filesystem")]
10pub mod filesystem;
11
12pub use state::StateBackend;
13pub use store::StoreBackend;
14
15#[cfg(feature = "filesystem")]
16pub use filesystem::FilesystemBackend;
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct DirEntry {
21 pub name: String,
22 pub is_dir: bool,
23 pub size: Option<u64>,
24}
25
26#[derive(Debug, Clone)]
28pub struct ExecResult {
29 pub stdout: String,
30 pub stderr: String,
31 pub exit_code: i32,
32}
33
34#[derive(Debug, Clone)]
36pub struct GrepMatch {
37 pub file: String,
38 pub line_number: usize,
39 pub line: String,
40}
41
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44pub enum GrepOutputMode {
45 FilesWithMatches,
46 Content,
47 Count,
48}
49
50#[async_trait]
55pub trait Backend: Send + Sync {
56 async fn ls(&self, path: &str) -> Result<Vec<DirEntry>, SynapticError>;
58
59 async fn read_file(
61 &self,
62 path: &str,
63 offset: usize,
64 limit: usize,
65 ) -> Result<String, SynapticError>;
66
67 async fn write_file(&self, path: &str, content: &str) -> Result<(), SynapticError>;
69
70 async fn edit_file(
72 &self,
73 path: &str,
74 old_text: &str,
75 new_text: &str,
76 replace_all: bool,
77 ) -> Result<(), SynapticError>;
78
79 async fn glob(&self, pattern: &str, base: &str) -> Result<Vec<String>, SynapticError>;
81
82 async fn grep(
84 &self,
85 pattern: &str,
86 path: Option<&str>,
87 file_glob: Option<&str>,
88 output_mode: GrepOutputMode,
89 ) -> Result<String, SynapticError>;
90
91 async fn execute(
93 &self,
94 _command: &str,
95 _timeout: Option<Duration>,
96 ) -> Result<ExecResult, SynapticError> {
97 Err(SynapticError::Tool(
98 "execution not supported by this backend".into(),
99 ))
100 }
101
102 fn supports_execution(&self) -> bool {
104 false
105 }
106}