feat: implement proactive daemon hooks for file saves

This commit is contained in:
Riz Ashraf committed 2026-09-30 09:54:06 +01:00
1 parent ec0472155f
commit 5870f37fbd
4 files changed
+221 -16

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher};
use std::path::Path;
use std::sync::Arc;
use crate::state::MemoryState;
use tracing::{info, error};
pub fn spawn_watcher(_state: Arc<MemoryState>) {
let watch_path = std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."));
info!("Spawning proactive daemon watcher on {:?}", watch_path);
tokio::spawn(async move {
let (tx, mut rx) = tokio::sync::mpsc::channel::<notify::Result<Event>>(100);
let mut watcher = match RecommendedWatcher::new(
move |res| {
let _ = tx.blocking_send(res);
},
Config::default(),
) {
Ok(w) => w,
Err(e) => {
error!("Failed to create watcher: {}", e);
return;
}
};
if let Err(e) = watcher.watch(&watch_path, RecursiveMode::Recursive) {
error!("Failed to watch path: {}", e);
return;
}
while let Some(res) = rx.recv().await {
match res {
Ok(event) => {
if event.kind.is_modify() {
for path in event.paths {
if should_review(&path) {
info!("Proactive Daemon Hooks: File modified: {:?}", path);
trigger_autonomous_review(&path).await;
}
}
}
}
Err(e) => error!("Watch error: {}", e),
}
}
});
}
fn should_review(path: &Path) -> bool {
let path_str = path.to_string_lossy();
if path_str.contains(".git") || path_str.contains("target") {
return false;
}
if let Some(ext) = path.extension() {
let ext_str = ext.to_string_lossy();
if ext_str == "rs" || ext_str == "md" || ext_str == "toml" || ext_str == "lua" {
return true;
}
}
false
}
async fn trigger_autonomous_review(path: &Path) {
info!("Triggering autonomous review for {:?}", path);
// Simulate invoking a Neovim Lua diagnostic via mcp-memory-win-nvim daemon
// MVP: Just write an info log if Neovim isn't reachable.
info!("Autonomous review complete for {:?}", path);
}