Skip to content

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

Rust

fix(install-hooks): honor PI_CODING_AGENT_DIR for Pi/OMP extensions

Aravind Rao05059afb5e93
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28fbefb4..1f1e9714 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+- `install-hooks --agent pi`, `--agent omp`, and `uninstall` now honor
+ `PI_CODING_AGENT_DIR`, instead of always writing to `~/.pi/agent/extensions/`
+ and `~/.omp/agent/extensions/`. Both agents relocate their whole agent
+ config home (`~/.pi/agent` / `~/.omp/agent`) through that variable, so on an
+ install with it set the extensions landed where the agent never loads them:
+ the install reported success and capture silently did nothing. ai-memory
+ already honored the variable when resolving Pi/OMP transcripts, so the two
+ halves of one install disagreed about where that home was. Installs without
+ `PI_CODING_AGENT_DIR` set are unaffected.
+
### Added
- The built-in sanitizer now redacts seven further credential shapes, completing
three vendor families it already covered only in part. **GitHub:** every
diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rs
index 032994be..24f83349 100644
--- a/crates/ai-memory-cli/src/commands/install_hooks.rs
+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs
@@ -162,8 +162,28 @@ pub(crate) fn opencode_plugin_path() -> anyhow::Result<std::path::PathBuf> {
.join("ai-memory.ts"))
}
+/// `$PI_CODING_AGENT_DIR/extensions/ai-memory.ts` when the var is set, else
/// `~/.omp/agent/extensions/ai-memory.ts` — OMP lifecycle extension.
+///
+/// `PI_CODING_AGENT_DIR` relocates OMP's whole agent config home
+/// (`~/.omp/agent`), so extensions written to the default path are never
+/// loaded by an OMP configured that way: capture silently does nothing, with
+/// a successful-looking install. ai-memory already honors the variable when
+/// it resolves OMP transcripts (`ManagedHarness::Omp` 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 omp_extension_path() -> anyhow::Result<std::path::PathBuf> {
+ omp_extension_path_in(std::env::var_os("PI_CODING_AGENT_DIR"))
+}
+
+/// The env value comes in as a parameter so tests can exercise both branches
+/// without mutating process env (mirrors [`codex_hooks_path_in`]).
+fn omp_extension_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("extensions").join("ai-memory.ts"));
+ }
Ok(home_dir()
.context("could not locate $HOME for ~/.omp/agent/extensions")?
.join(".omp")
@@ -172,8 +192,28 @@ pub(crate) fn omp_extension_path() -> anyhow::Result<std::path::PathBuf> {
.join("ai-memory.ts"))
}
+/// `$PI_CODING_AGENT_DIR/extensions/ai-memory.ts` when the var is set, else
/// `~/.pi/agent/extensions/ai-memory.ts` — Pi lifecycle + MCP bridge extension.
+///
+/// `PI_CODING_AGENT_DIR` relocates Pi's whole agent config home
+/// (`~/.pi/agent`), so extensions written to the default path are never
+/// loaded by a Pi configured that way: capture silently does nothing, with a
+/// successful-looking install. ai-memory already honors the variable when it
+/// resolves Pi transcripts (`ManagedHarness::Pi` 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 pi_extension_path() -> anyhow::Result<std::path::PathBuf> {
+ pi_extension_path_in(std::env::var_os("PI_CODING_AGENT_DIR"))
+}
+
+/// The env value comes in as a parameter so tests can exercise both branches
+/// without mutating process env (mirrors [`codex_hooks_path_in`]).
+fn pi_extension_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("extensions").join("ai-memory.ts"));
+ }
Ok(home_dir()
.context("could not locate $HOME for ~/.pi/agent/extensions")?
.join(".pi")
@@ -5912,6 +5952,73 @@ model = "gpt-5"
assert_generated_ts_uses_bounded_hook_queue(&extension);
}
+ /// `PI_CODING_AGENT_DIR` relocates Pi's whole agent config home
+ /// (`~/.pi/agent`), not just session storage, so the extension must follow
+ /// the variable or Pi never loads it — the install reports success and
+ /// capture silently does nothing.
+ #[test]
+ fn pi_extension_path_honours_pi_coding_agent_dir() {
+ let custom = if cfg!(windows) {
+ r"C:\custom\pi-agent"
+ } else {
+ "/custom/pi-agent"
+ };
+ let path = pi_extension_path_in(Some(std::ffi::OsString::from(custom))).unwrap();
+ assert_eq!(
+ path,
+ Path::new(custom).join("extensions").join("ai-memory.ts")
+ );
+
+ // Unset and blank both fall back to ~/.pi/agent/extensions/ai-memory.ts.
+ // 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 = pi_extension_path_in(env).unwrap();
+ assert!(
+ path.ends_with(
+ Path::new(".pi")
+ .join("agent")
+ .join("extensions")
+ .join("ai-memory.ts")
+ ),
+ "default must be ~/.pi/agent/extensions/ai-memory.ts, got {}",
+ path.display()
+ );
+ }
+ }
+
+ /// Same relocation contract as Pi: OMP honors `PI_CODING_AGENT_DIR` for
+ /// the default profile and moves `~/.omp/agent` wholesale, extensions
+ /// included.
+ #[test]
+ fn omp_extension_path_honours_pi_coding_agent_dir() {
+ let custom = if cfg!(windows) {
+ r"C:\custom\omp-agent"
+ } else {
+ "/custom/omp-agent"
+ };
+ let path = omp_extension_path_in(Some(std::ffi::OsString::from(custom))).unwrap();
+ assert_eq!(
+ path,
+ Path::new(custom).join("extensions").join("ai-memory.ts")
+ );
+
+ for env in [None, Some(std::ffi::OsString::new())] {
+ let path = omp_extension_path_in(env).unwrap();
+ assert!(
+ path.ends_with(
+ Path::new(".omp")
+ .join("agent")
+ .join("extensions")
+ .join("ai-memory.ts")
+ ),
+ "default must be ~/.omp/agent/extensions/ai-memory.ts, got {}",
+ path.display()
+ );
+ }
+ }
+
#[test]
fn omp_extension_is_directly_discoverable_by_omp() {
let tmp = TempDir::new().unwrap();
diff --git a/docs/install.md b/docs/install.md
index fb281c55..175ffe90 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -954,7 +954,9 @@ for hooks; both target OMP's native `.omp` integration surface.
Pi does not read a native `mcp.json`. ai-memory supports Pi through one
generated TypeScript extension at `~/.pi/agent/extensions/ai-memory.ts`; the
same file captures lifecycle events and bridges ai-memory's HTTP MCP tools into
-Pi with `pi.registerTool`.
+Pi with `pi.registerTool`. When `PI_CODING_AGENT_DIR` is set (it relocates
+Pi's whole `~/.pi/agent` home), the extension is written to
+`$PI_CODING_AGENT_DIR/extensions/ai-memory.ts` instead.
```bash
ai-memory install-hooks --agent pi --apply \
diff --git a/docs/mcp-install.md b/docs/mcp-install.md
index 5c40a442..f962feb8 100644
--- a/docs/mcp-install.md
+++ b/docs/mcp-install.md
@@ -1041,7 +1041,9 @@ ai-memory install-hooks --agent omp --apply
This writes `~/.omp/agent/extensions/ai-memory.ts`, which OMP discovers
as a direct TypeScript extension on startup. Restart `omp` after
-installing or changing the file.
+installing or changing the file. When `PI_CODING_AGENT_DIR` is set
+(it relocates OMP's whole `~/.omp/agent` home), the extension is written
+to `$PI_CODING_AGENT_DIR/extensions/ai-memory.ts` instead.
**Gotchas:**
- OMP extensions are TypeScript modules, not shell hooks; stdout is not
@@ -1053,7 +1055,9 @@ installing or changing the file.
**Status:** ✅ MCP and lifecycle capture supported via generated bridge
extension. Pi has no native `mcp.json`; use `install-hooks --agent pi --apply`
-to write `~/.pi/agent/extensions/ai-memory.ts`.
+to write `~/.pi/agent/extensions/ai-memory.ts`. When `PI_CODING_AGENT_DIR`
+is set (it relocates Pi's whole `~/.pi/agent` home), the extension is
+written to `$PI_CODING_AGENT_DIR/extensions/ai-memory.ts` instead.
```bash
ai-memory install-hooks --agent pi --apply