Skip to content

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

Rust

fix(macos): harden wrapper URL routing

AkitaOnRails624ed6e8b562
diff --git a/bin/ai-memory b/bin/ai-memory
index c227243a..79896465 100755
--- a/bin/ai-memory
+++ b/bin/ai-memory
@@ -269,14 +269,32 @@ USER_ARGS=(-u "$(id -u):$(id -g)")
# a host-reachable URL for config vs. a container-reachable URL for HTTP.
# (issue #107)
RENDERS_HOST_CONFIG=0
-for arg in "$@"; do
+WRAPPER_SUBCOMMAND=""
+WRAPPER_ARGS=("$@")
+idx=0
+while [ "${idx}" -lt "${#WRAPPER_ARGS[@]}" ]; do
+ arg="${WRAPPER_ARGS[$idx]}"
case "${arg}" in
- install-mcp | install-hooks | setup-agent)
- RENDERS_HOST_CONFIG=1
+ --data-dir | --config)
+ idx=$((idx + 2))
+ ;;
+ --data-dir=* | --config=*)
+ idx=$((idx + 1))
+ ;;
+ --*)
+ idx=$((idx + 1))
+ ;;
+ *)
+ WRAPPER_SUBCOMMAND="${arg}"
break
;;
esac
done
+case "${WRAPPER_SUBCOMMAND}" in
+ install-mcp | install-hooks | setup-agent)
+ RENDERS_HOST_CONFIG=1
+ ;;
+esac
case "$(uname -s 2>/dev/null || true)" in
Linux)
diff --git a/crates/ai-memory-cli/tests/packaging.rs b/crates/ai-memory-cli/tests/packaging.rs
index fc5666f7..73619a43 100644
--- a/crates/ai-memory-cli/tests/packaging.rs
+++ b/crates/ai-memory-cli/tests/packaging.rs
@@ -1,6 +1,7 @@
//! Packaging asset regression tests.
use std::path::{Path, PathBuf};
+use std::process::Command;
fn repo_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
@@ -16,6 +17,51 @@ fn read_repo(path: &str) -> String {
.unwrap_or_else(|e| panic!("failed to read {}: {e}", path.display()))
}
+fn run_wrapper_on_fake_macos(args: &[&str]) -> String {
+ let tmp = tempfile::tempdir().unwrap();
+ let docker_args = tmp.path().join("docker-args.txt");
+ let docker = tmp.path().join("docker");
+ let uname = tmp.path().join("uname");
+ std::fs::write(
+ &docker,
+ format!(
+ "#!/usr/bin/env bash\nprintf '%s\\n' \"$@\" > {}\n",
+ docker_args.display()
+ ),
+ )
+ .unwrap();
+ std::fs::write(&uname, "#!/usr/bin/env bash\nprintf 'Darwin\\n'\n").unwrap();
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt;
+ std::fs::set_permissions(&docker, std::fs::Permissions::from_mode(0o755)).unwrap();
+ std::fs::set_permissions(&uname, std::fs::Permissions::from_mode(0o755)).unwrap();
+ }
+
+ let path = format!(
+ "{}:{}",
+ tmp.path().display(),
+ std::env::var("PATH").unwrap_or_default()
+ );
+ let output = Command::new(repo_root().join("bin/ai-memory"))
+ .args(args)
+ .env("PATH", path)
+ .env("AI_MEMORY_DOCKER", &docker)
+ .env("AI_MEMORY_NO_VERSION_CHECK", "1")
+ .env("AI_MEMORY_DATA_VOLUME", "test-ai-memory-data")
+ .env("HOME", tmp.path())
+ .env_remove("AI_MEMORY_SERVER_URL")
+ .output()
+ .unwrap();
+ assert!(
+ output.status.success(),
+ "wrapper failed: stdout={} stderr={}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ std::fs::read_to_string(docker_args).unwrap()
+}
+
#[test]
fn systemd_units_use_explicit_native_paths() {
let system = read_repo("packaging/systemd/ai-memory.service");
@@ -106,3 +152,32 @@ fn docker_publish_jobs_use_prebuilt_binaries() {
assert!(ci.contains("runner: macos-15-intel"));
assert!(ci.contains("--target runtime-prebuilt-amd64"));
}
+
+#[test]
+fn macos_wrapper_routes_urls_by_real_subcommand() {
+ for subcommand in ["install-mcp", "install-hooks", "setup-agent"] {
+ let args = run_wrapper_on_fake_macos(&[subcommand]);
+ assert!(
+ !args.contains("AI_MEMORY_SERVER_URL=http://host.docker.internal:49374"),
+ "{subcommand} renders host-side config and must keep loopback defaults; got {args}"
+ );
+ }
+
+ let args = run_wrapper_on_fake_macos(&["status"]);
+ assert!(
+ args.contains("AI_MEMORY_SERVER_URL=http://host.docker.internal:49374"),
+ "thin-client commands must reach the host server through Docker Desktop; got {args}"
+ );
+
+ let args = run_wrapper_on_fake_macos(&["search", "install-hooks"]);
+ assert!(
+ args.contains("AI_MEMORY_SERVER_URL=http://host.docker.internal:49374"),
+ "only the actual subcommand should control URL routing; got {args}"
+ );
+
+ let args = run_wrapper_on_fake_macos(&["--config", "/tmp/config.toml", "install-hooks"]);
+ assert!(
+ !args.contains("AI_MEMORY_SERVER_URL=http://host.docker.internal:49374"),
+ "global options before install-hooks must not hide the real subcommand; got {args}"
+ );
+}
diff --git a/docs/install.md b/docs/install.md
index 51562833..f0bac564 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -680,7 +680,8 @@ Docker Desktop wrapper, or a source build. Native Claude Code uses direct
agents use PowerShell `.ps1` defaults.
When run from source, `install-hooks` finds the bundled scripts in
-the repo's `hooks/` automatically:
+the repo's `hooks/` automatically. Extracted release archives also
+auto-discover the sibling `hooks/` bundle beside the `ai-memory` binary:
```bash
./target/release/ai-memory install-hooks --agent claude-code --auth-token "$TOKEN"