Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(cli): probe relative share directory for bundled hook lookup
Bet4830ab9fecc8a
diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rsindex bdce0a89..50a07e3c 100644--- a/crates/ai-memory-cli/src/commands/install_hooks.rs+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs@@ -6247,7 +6247,7 @@ fn hook_source_candidates(exe_dir: Option<PathBuf>,data_dir: Option<PathBuf>,) -> Vec<PathBuf> {- let mut candidates = Vec::with_capacity(5);+ let mut candidates = Vec::with_capacity(6);// Cargo-run from the repo.if let Some(root) = repo_root {candidates.push(root.join(crate::install_layout::HOOKS_DIR_NAME).join(sub));@@ -6255,9 +6255,25 @@ fn hook_source_candidates(// Release tarball (macOS/Windows/Linux archive): the `hooks/` bundle// ships in the same directory as the binary, so it's reachable without// `--source` (issue #107).- if let Some(dir) = exe_dir {+ if let Some(dir) = exe_dir.as_ref() {candidates.push(dir.join(crate::install_layout::HOOKS_DIR_NAME).join(sub));}+ // Standard Unix prefix layout: binary at `<prefix>/bin/ai-memory`,+ // hooks installed under `<prefix>/share/ai-memory/hooks/<sub>` (Nix,+ // Homebrew, /opt/local, custom prefix installs).+ if let Some(dir) = exe_dir.as_ref() {+ if dir.file_name().is_some_and(|name| name == "bin") {+ if let Some(prefix) = dir.parent() {+ candidates.push(+ prefix+ .join("share")+ .join("ai-memory")+ .join(crate::install_layout::HOOKS_DIR_NAME)+ .join(sub),+ );+ }+ }+ }// Docker image lays them out under /usr/local/share/ai-memory/.candidates.push(PathBuf::from(format!("/usr/local/share/ai-memory/hooks/{sub}"@@ -10763,6 +10779,40 @@ model = "gpt-5");}+ #[test]+ fn hook_source_candidates_include_standard_prefix_share_dir() {+ let candidates = hook_source_candidates(+ "claude-code",+ None,+ Some(PathBuf::from("/nix/store/pkg/bin")),+ None,+ );++ assert!(+ candidates.contains(&PathBuf::from(+ "/nix/store/pkg/share/ai-memory/hooks/claude-code"+ )),+ "standard prefix share hooks/ dir must be probed; got {candidates:?}"+ );+ }++ #[test]+ fn hook_source_candidates_ignores_non_bin_parent_for_prefix_share() {+ let candidates = hook_source_candidates(+ "claude-code",+ None,+ Some(PathBuf::from("/opt/ai-memory")),+ None,+ );++ assert!(+ !candidates.contains(&PathBuf::from(+ "/opt/share/ai-memory/hooks/claude-code"+ )),+ "non-bin exe dir must not probe parent share dir; got {candidates:?}"+ );+ }+/// #546: `~/.local/bin/ai-memory -> <repo>/target/release/ai-memory` is/// what the quick start's `~/.local/bin` layout produces for a source/// build. Discovery is derived from the binary's own location, so thediff --git a/crates/ai-memory-cli/src/commands/setup_agent.rs b/crates/ai-memory-cli/src/commands/setup_agent.rsindex 43f9ed82..48a9e4a0 100644--- a/crates/ai-memory-cli/src/commands/setup_agent.rs+++ b/crates/ai-memory-cli/src/commands/setup_agent.rs@@ -725,6 +725,18 @@ fn source_candidates(explicit: Option<&Path>, sub: &str, exe: Option<PathBuf>) -// Release tarball: `hooks/` sits in the same dir as the binary.if let Some(dir) = exe.parent() {v.push(dir.join(crate::install_layout::HOOKS_DIR_NAME).join(sub));+ // Standard Unix prefix layout: `<prefix>/bin/<bin>` -> `<prefix>/share/ai-memory/hooks/<sub>`+ if dir.file_name().is_some_and(|name| name == "bin") {+ if let Some(prefix) = dir.parent() {+ v.push(+ prefix+ .join("share")+ .join("ai-memory")+ .join(crate::install_layout::HOOKS_DIR_NAME)+ .join(sub),+ );+ }+ }}// Repo-local fallback for `cargo run setup-agent` during dev:// target/<profile>/<bin> → repo root.@@ -778,6 +790,30 @@ mod tests {assert_eq!(candidates, vec![PathBuf::from("/custom/src/codex")]);}+ #[test]+ fn source_candidates_include_standard_prefix_share_dir() {+ let exe = PathBuf::from("/nix/store/pkg/bin/ai-memory");+ let candidates = source_candidates(None, "claude-code", Some(exe));+ assert!(+ candidates.contains(&PathBuf::from(+ "/nix/store/pkg/share/ai-memory/hooks/claude-code"+ )),+ "prefix share hooks/ dir must be probed; got {candidates:?}"+ );+ }++ #[test]+ fn source_candidates_ignores_non_bin_parent_for_prefix_share() {+ let exe = PathBuf::from("/opt/ai-memory/ai-memory");+ let candidates = source_candidates(None, "claude-code", Some(exe));+ assert!(+ !candidates.contains(&PathBuf::from(+ "/opt/share/ai-memory/hooks/claude-code"+ )),+ "flat tarball directory must not treat parent as prefix; got {candidates:?}"+ );+ }+#[test]fn pi_setup_prints_extension_hint_without_copying() {let tmp = tempfile::TempDir::new().unwrap();