Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(install-hooks): honor CODEX_HOME when locating codex hooks.json
AkitaOnRails75376ac3d8eb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 86e5d9c9..e3d6f1c8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- `install-hooks --agent codex` and `uninstall` now honor `CODEX_HOME`, instead+ of always writing to `~/.codex/hooks.json`. Codex loads hooks from its+ configured home, so on an install with `CODEX_HOME` set the hooks landed+ where Codex never reads them: the install reported success and capture+ silently did nothing. ai-memory already honored the variable when resolving+ Codex transcripts, so the two halves of one install disagreed about where+ that home was. Installs without `CODEX_HOME` set are unaffected.+### Added- Added `ai-memory move-session <session-id> --to <project> [--to-workspace][--pages move|regenerate] [--confirm] [--force] [--create]`, its batch formdiff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rsindex 597e69cf..032994be 100644--- a/crates/ai-memory-cli/src/commands/install_hooks.rs+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs@@ -57,8 +57,27 @@ fn claude_settings_path_in(.join("settings.json"))}+/// Codex's hooks file — `$CODEX_HOME/hooks.json` when the var is set, else/// `~/.codex/hooks.json`.+///+/// `CODEX_HOME` relocates Codex's whole config home, so hooks written to the+/// default path are simply never loaded by a Codex configured that way: capture+/// silently does nothing, with a successful-looking install. ai-memory already+/// honors the variable when it resolves that Codex's transcripts+/// (`ManagedHarness::Codex` in `ai-memory-workstream`), so ignoring it here left+/// one half of the same install pointing somewhere the other half did not.pub(crate) fn codex_hooks_path() -> anyhow::Result<std::path::PathBuf> {+ codex_hooks_path_in(std::env::var_os("CODEX_HOME"))+}++/// The env value comes in as a parameter so tests can exercise both branches+/// without mutating process env (mirrors [`claude_settings_path_in`]).+fn codex_hooks_path_in(+ env_override: Option<std::ffi::OsString>,+) -> anyhow::Result<std::path::PathBuf> {+ if let Some(dir) = crate::commands::path_util::agent_config_home(env_override) {+ return Ok(dir.join("hooks.json"));+ }Ok(home_dir().context("could not locate $HOME for ~/.codex/hooks.json")?.join(".codex")@@ -6714,6 +6733,34 @@ command = "AI_MEMORY_HOOK_URL=http://old:1 /old/ai-memory/hooks/kimi-code/sessio}}+ /// `CODEX_HOME` relocates Codex's entire config home, so hooks written to+ /// `~/.codex` are never loaded by a Codex configured that way — the install+ /// reports success and capture silently does nothing. ai-memory already+ /// honors the variable when resolving Codex transcripts, so the two halves+ /// of one install have to agree on where that home is.+ #[test]+ fn codex_hooks_path_honours_codex_home() {+ let custom = if cfg!(windows) {+ r"C:\custom\codex"+ } else {+ "/custom/codex"+ };+ let path = codex_hooks_path_in(Some(std::ffi::OsString::from(custom))).unwrap();+ assert_eq!(path, Path::new(custom).join("hooks.json"));++ // Unset and blank both fall back to ~/.codex/hooks.json. Blank counts as+ // unset because an exported-but-empty variable is nearly always a failed+ // shell expansion, not a request to install into the filesystem root.+ for env in [None, Some(std::ffi::OsString::new())] {+ let path = codex_hooks_path_in(env).unwrap();+ assert!(+ path.ends_with(Path::new(".codex").join("hooks.json")),+ "default must be ~/.codex/hooks.json, got {}",+ path.display()+ );+ }+ }+/// The test-only Claude Code wrapper must stage scripts under its injected/// data-local root and wire that stable path into the generated config.#[test]diff --git a/crates/ai-memory-cli/src/commands/path_util.rs b/crates/ai-memory-cli/src/commands/path_util.rsindex 9bec4ff5..c8430342 100644--- a/crates/ai-memory-cli/src/commands/path_util.rs+++ b/crates/ai-memory-cli/src/commands/path_util.rs@@ -14,11 +14,19 @@ pub(crate) fn home_dir() -> Option<PathBuf> {dirs::home_dir()}-/// Claude Code's relocated config root: `$CLAUDE_CONFIG_DIR` when set to a-/// non-empty, non-whitespace value, else `None` (callers fall back to the-/// `~/.claude*` defaults). The env value comes in as a parameter so tests-/// can exercise both branches without mutating process env.-pub(crate) fn claude_config_dir(env_override: Option<std::ffi::OsString>) -> Option<PathBuf> {+/// An agent's relocated config root from its own home variable, when that+/// variable is set to a non-empty, non-whitespace value; else `None`, and the+/// caller falls back to the agent's `~/...` default.+///+/// Blank is treated as unset on purpose: an exported-but-empty variable is far+/// more often an unset shell expansion than a deliberate request to install+/// into the filesystem root.+///+/// The env value comes in as a parameter so tests can exercise both branches+/// without mutating process env — which is not merely inconvenient here but+/// forbidden: `std::env::set_var` is `unsafe` under edition 2024 and this+/// workspace forbids `unsafe_code`.+pub(crate) fn agent_config_home(env_override: Option<std::ffi::OsString>) -> Option<PathBuf> {let value = env_override?;if value.to_str().is_some_and(|s| s.trim().is_empty()) {return None;@@ -26,6 +34,12 @@ pub(crate) fn claude_config_dir(env_override: Option<std::ffi::OsString>) -> OptSome(PathBuf::from(value))}+/// Claude Code's relocated config root: `$CLAUDE_CONFIG_DIR` when set, else+/// `None`. Named alias kept so Claude call sites read for what they resolve.+pub(crate) fn claude_config_dir(env_override: Option<std::ffi::OsString>) -> Option<PathBuf> {+ agent_config_home(env_override)+}+/// Candidate Claude Code paths for uninstall. The active relocated path comes/// first, followed by the legacy home path, with exact duplicates removed.pub(crate) fn claude_config_paths(