Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge PR #609: report ZCode configs it rejects instead of 'up to date' (#600)
AkitaOnRailsd94a62c28435
diff --cc CHANGELOG.mdindex 5b7e8619,c9089f09..2dd800e4--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -8,32 -8,23 +8,49 @@@ and this project adheres to [Semantic V## [Unreleased]### Fixed+- Local-embedding model download (`fetch_model`) now bounds a stalled+ connection instead of hanging startup forever (#602): a 30s connect+ timeout and a generous 600s overall ceiling (large model files, so+ not the inference clients' flat 120s that would fail a slow download).+- The OKF v0.2 migration no longer crash-loops on startup with a+ libgit2 `invalid object specified … class=Tree` error that left the+ server unable to boot (#594). The wiki commit re-hashed files through+ libgit2's index, whose stat cache could trust a cached blob OID absent+ from the object database (a store carried across libgit2/git versions,+ or an interrupted earlier operation) — `write_tree` then aborted and,+ because the migration commits through that path, every restart failed.+ The commit now clears the index before staging so every file is+ re-hashed from the working tree. (The Docker runtime ships no `git`,+ so the fix is in-library, not a CLI fallback.)+- HTTP headers that carry a credential in an opaque value are now redacted+ before reaching durable storage. Previously such a header matched no+ built-in pattern unless it used the `Bearer` keyword or an+ `UPPER_SNAKE_TOKEN=` shape. The bearer rule requires the literal keyword,+ and the generic env-var rule requires `[A-Z][A-Z0-9_]*_TOKEN`, which never+ matches a kebab-case header name. `X-Amz-Security-Token` (AWS SigV4),+ `X-Api-Key`, `Private-Token` (GitLab), and `Ocp-Apim-Subscription-Key`+ (Azure) all fall in that gap, and tool output echoing a `curl` invocation+ is a common way they reach capture. A `key` or `token` suffix on its own+ does not imply a secret, so it must be qualified by an auth word:+ `Idempotency-Key`, `Continuation-Token` and storage partition keys are+ left intact and stay readable in captured output.+ - `install-hooks --agent zcode --apply` no longer reports a hooks block+ ZCode has thrown away as `no-op … (already up to date)` (#600). ZCode+ validates `hooks.events` strictly and rejects the whole block, including+ ai-memory's own entries, over a single key it does not recognize, so+ capture never ran (`hookCount: 0`). Apply only ever merged the six event+ keys it writes, so a key it does not write was neither inspected nor+ reported, the file kept matching byte for byte, and the report claimed+ the install was current. Apply now also withdraws ai-memory's own+ entries from event keys it no longer writes, wherever they sit, and+ reports what it found: a warning naming any key it withdrew from, and a+ note for a key left unable to run anything, both naming the config file.+ **Changed output:** an unchanged ZCode config with such a key now reports+ `no-op … (unchanged; see the notes below)` instead of `already up to+ date`, so a redirected stdout no longer carries the reassurance without+ the cause. Event keys are never deleted and hooks ai-memory did not write+ are never removed, so a key holding someone else's hook is reported, not+ touched.- `as_of` time-travel queries and the entity retrieval stream now workon real stores. Both read the entity index, which was populated onlyfrom an LLM consolidator's `entities:` frontmatter — absent on thediff --cc crates/ai-memory-cli/src/commands/install_hooks.rsindex af1cbd40,f85b7041..078999c2--- a/crates/ai-memory-cli/src/commands/install_hooks.rs+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs@@@ -6411,6 -6525,120 +6529,119 @@@ command = "AI_MEMORY_HOOK_URL=http://h);}}-+ #[test]+ fn zcode_apply_withdraws_our_hooks_from_foreign_keys_and_keeps_the_rest() {+ let tmp = TempDir::new().unwrap();+ let path = tmp.path().join("config.json");+ // Keys outside `ZCODE_EVENTS`. ZCode rejects the whole block over+ // ones it does not recognize, which is how #600 stayed invisible.+ // `SessionEnd` runs nothing, `PreCompact` holds only our entry, and+ // `Notification` mixes our entry with a hook we did not write.+ fs::write(+ &path,+ r#"{+ "hooks": {+ "enabled": true,+ "events": {+ "SessionEnd": [],+ "PreCompact": [+ {"hooks": [+ {"type": "process", "command": "/old/ai-memory", "args": [],+ "enabled": true, "statusMessage": "ai-memory capture"}+ ]}+ ],+ "Notification": [+ {"hooks": [+ {"type": "process", "command": "/old/ai-memory", "args": [],+ "enabled": true, "statusMessage": "ai-memory capture"},+ {"type": "process", "command": "/usr/bin/true", "args": [], "enabled": true}+ ]}+ ]+ }+ }+ }"#,+ )+ .unwrap();+ let args = InstallHooksArgs {+ agent: AgentChoice::Zcode,+ capture_assistant: false,+ config_file: Some(path.clone()),+ ..default_hook_args()+ };++ apply_to_zcode_hooks(+ "http://127.0.0.1:49374",+ Some("tok-test"),+ Path::new("/data"),+ &args,+ )+ .unwrap();++ let first = fs::read_to_string(&path).unwrap();+ let root: serde_json::Value = serde_json::from_str(&first).unwrap();+ let events = root["hooks"]["events"].as_object().unwrap();++ // Event keys are never deleted: they are not ai-memory's to remove.+ assert!(events.contains_key("SessionEnd"));+ assert!(events.contains_key("PreCompact"));+ // Our own stale entry is withdrawn wherever it sits.+ assert_eq!(+ events["PreCompact"][0]["hooks"].as_array().unwrap().len(),+ 0,+ "our entry under a key we no longer write must be withdrawn"+ );+ // The mixed group is the only case where the ownership filter+ // decides anything: the foreign hook survives, ours does not.+ let notification = events["Notification"][0]["hooks"].as_array().unwrap();+ assert_eq!(notification.len(), 1, "the hook we did not write must stay");+ assert_eq!(+ notification[0]["command"],+ serde_json::json!("/usr/bin/true")+ );+ for (zcode_event, _) in super::super::render_shared::ZCODE_EVENTS {+ assert!(+ root["hooks"]["events"][zcode_event].is_array(),+ "missing {zcode_event}"+ );+ }++ // Re-apply is still a no-op once the withdrawal has happened.+ apply_to_zcode_hooks(+ "http://127.0.0.1:49374",+ Some("tok-test"),+ Path::new("/data"),+ &args,+ )+ .unwrap();+ assert_eq!(first, fs::read_to_string(&path).unwrap());+ }++ #[test]+ fn zcode_event_runs_nothing_covers_degenerate_matcher_groups() {+ // Each of these leaves the key present but unable to run anything,+ // which is what makes ZCode reject the block while the file still+ // looks settled (#600).+ for shape in [+ serde_json::json!([]),+ serde_json::json!([{}]),+ serde_json::json!([{"matcher": "*"}]),+ serde_json::json!([{"hooks": []}]),+ serde_json::json!([{"hooks": null}]),+ ] {+ assert!(+ zcode_event_runs_nothing(&shape),+ "expected {shape} to run nothing"+ );+ }+ assert!(!zcode_event_runs_nothing(&serde_json::json!([+ {"hooks": [{"type": "process", "command": "/usr/bin/true"}]}+ ])));+ // A value that is not a matcher-group array cannot run hooks either,+ // and is doubly invalid to ZCode. It is left unmodified, but it is+ // still reported: staying quiet about it is the #600 failure.+ assert!(zcode_event_runs_nothing(&serde_json::json!(42)));+ }+#[test]fn zcode_apply_flags_a_user_disabled_hooks_block() {let tmp = TempDir::new().unwrap();