Skip to content

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

Rust

fix(wrapper): route Windows helper commands at the host server

Matheus Silva6d26c3931be0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f86e6e2..2dc03d62 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+- The Windows Docker wrapper's thin-client commands now reach a
+ loopback-published server instead of failing with `Connection refused (os
+ error 111)`. `ai-memory status`, `search`, `bootstrap` and every other
+ thin-client command runs inside a short-lived helper container, where the
+ CLI's default `http://127.0.0.1:49374` resolves to that helper rather than
+ to the Windows host, so a healthy `docker run -p 127.0.0.1:49374:49374`
+ server was unreachable from the wrapper while `curl` from PowerShell worked.
+ The wrapper now injects `AI_MEMORY_SERVER_URL=http://host.docker.internal:49374`
+ for those commands, matching what the POSIX wrapper has done on macOS since
+ (#107) — Docker Desktop gives Linux containers no host networking on either
+ platform. `install-mcp`, `install-hooks` and `setup-agent` still render
+ `http://127.0.0.1:49374` into host-side agent config, because
+ `host.docker.internal` does not resolve on the Windows host, and an explicit
+ `AI_MEMORY_SERVER_URL` (homelab or remote server) is still honoured. (#464)
+
## [1.31.0] - 2026-08-22
### Fixed
diff --git a/bin/ai-memory.ps1 b/bin/ai-memory.ps1
index f610ae86..cd361416 100644
--- a/bin/ai-memory.ps1
+++ b/bin/ai-memory.ps1
@@ -26,6 +26,26 @@ function Get-EnvOrDefault {
return $value
}
+# Resolve the real subcommand, skipping the global options that may precede
+# it. `--config` and `--data-dir` take a separate value, so their argument has
+# to be stepped over as well or it would be mistaken for the subcommand.
+function Get-WrapperSubcommand {
+ param([string[]]$WrapperArgs)
+
+ $Index = 0
+ while ($Index -lt $WrapperArgs.Count) {
+ $Arg = $WrapperArgs[$Index]
+ if ($Arg -eq "--config" -or $Arg -eq "--data-dir") {
+ $Index += 2
+ } elseif ($Arg -like "--*") {
+ $Index += 1
+ } else {
+ return $Arg
+ }
+ }
+ return ""
+}
+
$Image = Get-EnvOrDefault "AI_MEMORY_IMAGE" "akitaonrails/ai-memory:latest"
$Docker = Get-EnvOrDefault "AI_MEMORY_DOCKER" "docker"
$DataVolume = Get-EnvOrDefault "AI_MEMORY_DATA_VOLUME" "ai-memory-data"
@@ -130,6 +150,26 @@ foreach ($Name in @(
}
}
+# Docker Desktop gives Windows no host networking for Linux containers, so a
+# thin-client command (status, search, bootstrap, ...) reaches the loopback-
+# published server from this helper container through Docker Desktop's host
+# alias; 127.0.0.1 would mean the helper container itself and the call dies
+# with "Connection refused". But install-mcp/install-hooks/setup-agent RENDER
+# the URL into the *host* agent config, and host.docker.internal does NOT
+# resolve on the Windows host: baking it in silently breaks MCP and every
+# capture hook. So for those commands leave AI_MEMORY_SERVER_URL unset, letting
+# the CLI render its host-reachable default (http://127.0.0.1:49374).
+# (issue #107)
+$RendersHostConfig = (Get-WrapperSubcommand $CommandArgs) -in @(
+ "install-mcp",
+ "install-hooks",
+ "setup-agent"
+)
+if (-not $RendersHostConfig -and
+ [string]::IsNullOrEmpty([Environment]::GetEnvironmentVariable("AI_MEMORY_SERVER_URL"))) {
+ $DockerArgs += @("-e", "AI_MEMORY_SERVER_URL=http://host.docker.internal:49374")
+}
+
$DockerArgs += $Image
$DockerArgs += $CommandArgs
diff --git a/crates/ai-memory-cli/tests/packaging.rs b/crates/ai-memory-cli/tests/packaging.rs
index dd599af2..6805f0e8 100644
--- a/crates/ai-memory-cli/tests/packaging.rs
+++ b/crates/ai-memory-cli/tests/packaging.rs
@@ -1444,6 +1444,102 @@ fn powershell_wrapper_trims_paths_with_single_character_separators() {
);
}
+// The PowerShell counterpart of run_wrapper_on_fake_macos: a fake `docker.cmd`
+// records the argv the wrapper built. No `uname` shadowing is needed because
+// the Windows arm under test is selected by running on Windows at all.
+#[cfg(windows)]
+fn run_powershell_wrapper(args: &[&str]) -> String {
+ run_powershell_wrapper_with_server_url(args, None)
+}
+
+#[cfg(windows)]
+fn run_powershell_wrapper_with_server_url(args: &[&str], server_url: Option<&str>) -> String {
+ let tmp = tempfile::tempdir().unwrap();
+ let docker_args = tmp.path().join("docker-args.txt");
+ let docker = tmp.path().join("docker.cmd");
+ std::fs::write(
+ &docker,
+ "@echo off\r\n>\"%AI_MEMORY_TEST_DOCKER_ARGS%\" echo %*\r\nexit /b 0\r\n",
+ )
+ .unwrap();
+
+ let mut command = Command::new("powershell.exe");
+ // See the execution-policy note on the OAuth-token test below.
+ command
+ .args([
+ "-NoLogo",
+ "-NoProfile",
+ "-NonInteractive",
+ "-ExecutionPolicy",
+ "Bypass",
+ "-File",
+ ])
+ .arg(repo_root().join("bin/ai-memory.ps1"))
+ .args(args)
+ .env("AI_MEMORY_DOCKER", &docker)
+ .env("AI_MEMORY_TEST_DOCKER_ARGS", &docker_args)
+ .env("AI_MEMORY_DATA_VOLUME", "test-ai-memory-data")
+ .env_remove("AI_MEMORY_DATA_DIR");
+ match server_url {
+ Some(url) => command.env("AI_MEMORY_SERVER_URL", url),
+ None => command.env_remove("AI_MEMORY_SERVER_URL"),
+ };
+ let output = command.output().unwrap();
+ assert!(
+ output.status.success(),
+ "PowerShell wrapper failed: stdout={} stderr={}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ std::fs::read_to_string(docker_args).unwrap()
+}
+
+// The Windows mirror of macos_wrapper_routes_urls_by_real_subcommand: Docker
+// Desktop gives Linux containers no host networking on Windows either, so the
+// helper container cannot reach the host-published server over loopback.
+#[cfg(windows)]
+#[test]
+fn windows_wrapper_routes_urls_by_real_subcommand() {
+ for subcommand in ["install-mcp", "install-hooks", "setup-agent"] {
+ let args = run_powershell_wrapper(&[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_powershell_wrapper(&["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_powershell_wrapper(&["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_powershell_wrapper(&["--config", "C:\\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}"
+ );
+
+ // A homelab/remote server is configured through the environment, and the
+ // helper container must not be redirected back at the local Docker host.
+ let args =
+ run_powershell_wrapper_with_server_url(&["status"], Some("http://192.168.1.50:49374"));
+ assert!(
+ !args.contains("AI_MEMORY_SERVER_URL=http://host.docker.internal:49374"),
+ "an explicit AI_MEMORY_SERVER_URL must win over the Docker Desktop alias; got {args}"
+ );
+ assert!(
+ args.contains("-e AI_MEMORY_SERVER_URL"),
+ "an explicit AI_MEMORY_SERVER_URL must still be forwarded by name; got {args}"
+ );
+}
+
#[cfg(windows)]
#[test]
fn powershell_wrapper_forwards_subscription_oauth_tokens_without_putting_values_in_argv() {
diff --git a/docs/windows.md b/docs/windows.md
index 93764e81..db3d4b79 100644
--- a/docs/windows.md
+++ b/docs/windows.md
@@ -69,7 +69,13 @@ inside WSL2, no Windows wrapper is involved.
## Scenario B: Native Windows With Docker Desktop
Use this when the agent CLI runs as a native Windows process and you want
-the ai-memory server to run from the Docker image.
+the ai-memory server to run from the Docker image. The wrapper renders
+host-side agent config with `http://127.0.0.1:49374`, but its own thin-client
+commands reach the server from inside a helper container via Docker Desktop's
+`host.docker.internal` alias, because Docker Desktop gives Linux containers no
+host networking on Windows. Set `AI_MEMORY_SERVER_URL` only when the server
+lives somewhere else (a homelab or remote host); the wrapper honours it and
+skips the alias.
```powershell
# Install the Windows Docker wrapper.
@@ -106,7 +112,9 @@ if (($UserPath -split ';') -notcontains $UserBin) {
$env:Path = "$env:Path;$UserBin"
}
-# Start the server with Docker Desktop.
+# Start the server with Docker Desktop. The image default allowlist includes
+# host.docker.internal so wrapper thin-client commands (status, search, …) are
+# not rejected with 403.
docker run -d --name ai-memory `
--restart unless-stopped `
-p 127.0.0.1:49374:49374 `