Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(hooks): normalize capture working directories
AkitaOnRails2fe9626eec7f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 04a9bec7..6f3515ef 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -30,6 +30,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0including subdirectories and linked worktrees. (#259)### Fixed+- Capture exclusions now canonicalize an existing hook working directory+ before matching paths, so filesystem aliases such as macOS `/var` versus+ `/private/var` cannot turn an excluded file event into a spooled event.+ Marker discovery tests likewise accept the canonical path they request.+ (#265)- Opt-in SessionEnd LLM consolidation now runs from a durable, generation-idempotent queue instead of inside the hook batch request. The hook commitsits deterministic session page and handoff, persists the provider job, anddiff --git a/crates/ai-memory-cli/src/commands/hook.rs b/crates/ai-memory-cli/src/commands/hook.rsindex 8b80bfbe..d25cd9b1 100644--- a/crates/ai-memory-cli/src/commands/hook.rs+++ b/crates/ai-memory-cli/src/commands/hook.rs@@ -433,13 +433,14 @@ wherepayload = serde_json::to_string(&json)?;}let (policy_cwd, canonical_session_id) = hook_context(&args.agent, &json);+ let inspection_cwd = policy_cwd.as_deref().map(canonical_capture_cwd);let policy = policy_cwd.as_deref().map(capture_policy);let tool_event = is_tool_event(&args.event);let decision = policy.as_ref().filter(|_| tool_event).map(|policy| {policy.inspect(AgentKind::from_wire(&args.agent),&json,- policy_cwd.as_deref().unwrap_or(""),+ inspection_cwd.as_deref().unwrap_or(""),)});if args.check_capture {@@ -717,6 +718,14 @@ fn hook_context(agent: &str, raw: &serde_json::Value) -> (Option<String>, Option}}+fn canonical_capture_cwd(cwd: &str) -> String {+ Path::new(cwd)+ .canonicalize()+ .ok()+ .and_then(|path| path.into_os_string().into_string().ok())+ .unwrap_or_else(|| cwd.to_owned())+}+fn is_tool_event(event: &str) -> bool {matches!(event.to_ascii_lowercase().replace(['-', '_'], "").as_str(),@@ -1439,6 +1448,46 @@ mod tests {assert_eq!(hook_spool::spool_len(&hook_spool::spool_dir(&data_dir)), 0);}+ #[cfg(unix)]+ #[tokio::test]+ async fn capture_drop_handles_symlinked_cwd() {+ let tmp = tempfile::tempdir().unwrap();+ let project = tmp.path().join("project");+ std::fs::create_dir(&project).unwrap();+ std::fs::write(+ project.join(".ai-memory.toml"),+ "[capture]\nignore_paths = [\"secret/**\"]\n",+ )+ .unwrap();+ let alias = tmp.path().join("project-alias");+ std::os::unix::fs::symlink(&project, &alias).unwrap();++ let data_dir = tmp.path().join("data");+ let mut stdout = Vec::new();+ let called = std::cell::Cell::new(false);+ run_with_payload(+ Some(data_dir.clone()),+ devin_hook_args("post-tool-use"),+ serde_json::json!({+ "cwd": alias,+ "tool_name": "Edit",+ "tool_input": {"path": "secret/SENTINEL"}+ })+ .to_string(),+ &mut stdout,+ |_| {+ called.set(true);+ Ok(())+ },+ )+ .await+ .unwrap();++ assert_eq!(stdout, b"{}\n");+ assert!(!called.get());+ assert_eq!(hook_spool::spool_len(&hook_spool::spool_dir(&data_dir)), 0);+ }+#[tokio::test]async fn invalid_capture_marker_spools_only_metadata() {let tmp = tempfile::tempdir().unwrap();diff --git a/crates/ai-memory-cli/src/marker.rs b/crates/ai-memory-cli/src/marker.rsindex 5ac01d94..be626fab 100644--- a/crates/ai-memory-cli/src/marker.rs+++ b/crates/ai-memory-cli/src/marker.rs@@ -274,7 +274,7 @@ mod tests {assert_eq!(find_marker_with_home(nested.to_str().unwrap(), Some(&home)),- Some(repo_marker)+ Some(repo_marker.canonicalize().unwrap()));fs::remove_file(repo.join(".ai-memory.toml")).unwrap();assert_eq!(@@ -302,7 +302,7 @@ mod tests {let local = write_marker(&cwd, "workspace = \"right\"\n");assert_eq!(find_marker_with_home(cwd.to_str().unwrap(), Some(&home)),- Some(local)+ Some(local.canonicalize().unwrap()));}