Skip to main content

ai_agent/utils/
session_file_access_hooks.rs

1//! Session file access hooks.
2
3use std::path::Path;
4
5/// File access hook types
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum FileAccessHookType {
8    PreRead,
9    PostRead,
10    PreWrite,
11    PostWrite,
12}
13
14/// File access event
15#[derive(Debug, Clone)]
16pub struct FileAccessEvent {
17    pub path: String,
18    pub hook_type: FileAccessHookType,
19    pub session_id: String,
20}
21
22/// File access hook
23pub trait FileAccessHook: Send + Sync {
24    fn on_access(&self, event: FileAccessEvent);
25}
26
27/// File access hook registry
28pub struct FileAccessHookRegistry {
29    hooks: Vec<Box<dyn FileAccessHook>>,
30}
31
32impl FileAccessHookRegistry {
33    pub fn new() -> Self {
34        Self { hooks: Vec::new() }
35    }
36
37    pub fn register(&mut self, hook: Box<dyn FileAccessHook>) {
38        self.hooks.push(hook);
39    }
40
41    pub fn notify(&self, event: FileAccessEvent) {
42        for hook in &self.hooks {
43            hook.on_access(event.clone());
44        }
45    }
46}
47
48impl Default for FileAccessHookRegistry {
49    fn default() -> Self {
50        Self::new()
51    }
52}
53
54/// Check if a file is accessible in the current session context
55pub fn is_file_accessible(path: &Path) -> bool {
56    // For now, allow all file access
57    // In production, this would check against session permissions
58    true
59}