Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(install-hooks): recognize underscore executable name in hook ownership (#740)

AkitaOnRailse3b31d2eecd8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9dc73f02..282c59d1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,6 +68,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
delivery and preserves that key when spooling the event, preventing a replay
from creating a duplicate observation when the server committed the first
request but its response was lost (#729).
+- `install-hooks` reapply is idempotent again on Windows for agents whose
+ native command uses an underscore executable name (`ai_memory`): the hook
+ ownership predicate recognized only the hyphenated `ai-memory`, so a reapply
+ reported `Updated` and failed to dedup its own prior Antigravity/Cursor/Kimi
+ Code entries. It now matches both forms while still requiring the full
+ `hook --event … --agent … --server-url …` argv signature (#740).
## [2.2.1] - 2026-09-12
diff --git a/crates/ai-memory-cli/src/commands/uninstall.rs b/crates/ai-memory-cli/src/commands/uninstall.rs
index a178faf9..a9e90eaa 100644
--- a/crates/ai-memory-cli/src/commands/uninstall.rs
+++ b/crates/ai-memory-cli/src/commands/uninstall.rs
@@ -732,12 +732,21 @@ fn strip_legacy_orphan_tail(tail: &str) -> &str {
/// commands invoke the `ai-memory hook --event ... --server-url ...` subcommand.
/// Keep both signatures narrow so hook overlays and uninstall do not remove
/// unrelated hooks that happen to use the same event names or script basenames.
+///
+/// The executable name is matched in both its hyphenated (`ai-memory`) and
+/// underscored (`ai_memory`) forms: a native command uses the current
+/// executable's path, and on Windows a test binary (and some packaging) names
+/// it with an underscore, so recognizing only the hyphen made a reapply
+/// non-idempotent — it reported `Updated` and failed to dedup its own prior
+/// entries (#740). The full `hook --event … --agent … --server-url …` argv
+/// signature still gates the match, so this does not broaden to unrelated
+/// commands whose path merely contains the string.
pub(crate) fn hook_command_is_ours(command: &str) -> bool {
if command.contains("AI_MEMORY_HOOK_URL=") {
return true;
}
let lower = command.to_ascii_lowercase();
- lower.contains("ai-memory")
+ (lower.contains("ai-memory") || lower.contains("ai_memory"))
&& lower.contains(" hook --event ")
&& lower.contains(" --agent ")
&& lower.contains(" --server-url ")
@@ -1522,6 +1531,20 @@ mod tests {
assert!(hook_command_is_ours(cmd));
}
+ #[test]
+ fn hook_signature_matches_underscore_executable_name() {
+ // On Windows a test binary (and some packaging) names the executable
+ // `ai_memory` rather than `ai-memory`; the native command then uses that
+ // path. Recognizing only the hyphen made a reapply non-idempotent (#740).
+ let cmd = r#""C:\Users\alice\target\debug\ai_memory.exe" hook --event session-start --agent kimi-code --server-url "http://h:49374""#;
+ assert!(hook_command_is_ours(cmd));
+ // The argv signature still gates it: an unrelated `ai_memory`-named tool
+ // without our hook subcommand is not claimed.
+ assert!(!hook_command_is_ours(
+ r#""C:\bin\ai_memory_helper.exe" --do-something-else"#
+ ));
+ }
+
#[test]
fn hook_signature_rejects_third_party_with_generic_name() {
// A user's own hook that happens to be named stop.sh — no prefix.