Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix: rootless Docker UID remap breaks install-mcp/install-hooks/install-instructions/install-skills/setup-agent
paulo.rpereira743ecad86071
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c1c1a72d..ca3a7ee5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- `bin/ai-memory` no longer fails `install-mcp`, `install-hooks`,+ `setup-agent`, `install-instructions`, and `install-skills` under+ rootless Docker. Rootless Docker maps container UID 0 back to the real+ host user but routes any other UID (including the host UID the wrapper+ always passed via `-u`) through an unrelated subordinate-UID range, so+ every write to a bind-mounted host path (`~/.claude/settings.json`,+ the hook staging dir, `$PWD/CLAUDE.md`, skill directories) failed with+ `Permission denied` or a misleading "does not exist" error. The wrapper+ now detects rootless Docker via `docker info --format+ '{{.SecurityOptions}}'` and runs as `-u 0:0` for just the commands that+ write host-side files; thin-client commands (`status`, `bootstrap`, …)+ are unaffected since they only touch the `/data` named volume.+## [1.8.0] - 2026-07-04### Addeddiff --git a/bin/ai-memory b/bin/ai-memoryindex 79896465..a39587e5 100755--- a/bin/ai-memory+++ b/bin/ai-memory@@ -257,7 +257,8 @@ doneNETWORK_ARGS=()# Default: map the container process to the host user so files written# through bind mounts (~/.claude/settings.json, $PWD/, …) stay editable-# by the invoking user. macOS is the one exception (see Darwin arm).+# by the invoking user. macOS is one exception (see Darwin arm); rootless+# Docker is the other (see the WRITES_HOST_FILES check below).USER_ARGS=(-u "$(id -u):$(id -g)")# Does this invocation RENDER host-side agent config? install-mcp,@@ -290,12 +291,35 @@ while [ "${idx}" -lt "${#WRAPPER_ARGS[@]}" ]; do;;esacdone+WRITES_HOST_FILES=0case "${WRAPPER_SUBCOMMAND}" ininstall-mcp | install-hooks | setup-agent)RENDERS_HOST_CONFIG=1+ WRITES_HOST_FILES=1+ ;;+ install-instructions | install-skills)+ WRITES_HOST_FILES=1;;esac+# Rootless Docker runs the whole daemon inside its own user namespace, where+# container UID 0 maps back to the invoking host user, but any *non-zero*+# UID we pass (e.g. our own "$(id -u):$(id -g)" above) is instead routed+# through a separate subordinate-UID range (/etc/subuid, typically 100000+)+# that has no relation to real host file ownership. So under rootless+# Docker, "-u <host-uid>:<host-gid>" writes end up owned by an unmapped+# UID and every bind-mounted write (~/.claude/settings.json, the hook+# staging dir, $PWD/CLAUDE.md, skill directories, …) fails with+# EACCES/ENOENT. Running as UID 0 instead hits rootlesskit's primary+# mapping and lands as the real host user. Only do this for commands that+# write to a host bind mount: other commands only touch the /data named+# volume, which isn't host-visible and doesn't have this problem, so leave+# their UID mapping alone.+if [ "${WRITES_HOST_FILES}" -eq 1 ] \+ && "${DOCKER}" info --format '{{.SecurityOptions}}' 2>/dev/null | grep -q 'name=rootless'; then+ USER_ARGS=(-u 0:0)+fi+case "$(uname -s 2>/dev/null || true)" inLinux)if [ -z "${AI_MEMORY_SERVER_URL:-}" ]; thendiff --git a/crates/ai-memory-cli/tests/packaging.rs b/crates/ai-memory-cli/tests/packaging.rsindex 7a49921e..c5feb99c 100644--- a/crates/ai-memory-cli/tests/packaging.rs+++ b/crates/ai-memory-cli/tests/packaging.rs@@ -204,6 +204,96 @@ fn macos_wrapper_routes_urls_by_real_subcommand() {);}+// Unlike run_wrapper_on_fake_macos's docker fake (which only ever sees one+// meaningful call — the final `docker run`), the rootless-Docker UID check+// calls `docker info` *before* `docker run`, so this fake must dispatch on+// $1: real stdout for `info` (read by the wrapper's `grep -q rootless`) vs.+// logging argv to a file for `run` (read back by the test).+#[cfg(unix)]+fn run_wrapper_with_fake_docker(args: &[&str], docker_info_stdout: &str) -> String {+ let tmp = tempfile::tempdir().unwrap();+ let docker_args = tmp.path().join("docker-args.txt");+ let docker = tmp.path().join("docker");+ std::fs::write(+ &docker,+ format!(+ "#!/usr/bin/env bash\n\+ if [ \"$1\" = info ]; then\n printf '%s\\n' '{}'\n exit 0\nfi\n\+ if [ \"$1\" = run ]; then\n shift\n printf '%s\\n' \"$@\" > {}\n exit 0\nfi\n\+ exit 0\n",+ docker_info_stdout,+ shell_path(&docker_args)+ ),+ )+ .unwrap();+ #[cfg(unix)]+ {+ use std::os::unix::fs::PermissionsExt;+ std::fs::set_permissions(&docker, std::fs::Permissions::from_mode(0o755)).unwrap();+ }++ let mut command = shell_script_command(&repo_root().join("bin/ai-memory"));+ let output = command+ .args(args)+ .env("AI_MEMORY_DOCKER", shell_path(&docker))+ .env("AI_MEMORY_NO_VERSION_CHECK", "1")+ .env("AI_MEMORY_DATA_VOLUME", "test-ai-memory-data")+ .env("HOME", shell_path(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()+}++#[cfg(unix)]+#[test]+fn rootless_docker_uses_root_uid_only_for_host_config_commands() {+ let rootless_info = "[name=apparmor name=seccomp,profile=default name=rootless]";++ for subcommand in [+ "install-mcp",+ "install-hooks",+ "setup-agent",+ "install-instructions",+ "install-skills",+ ] {+ let args = run_wrapper_with_fake_docker(&[subcommand], rootless_info);+ assert!(+ args.contains("-u\n0:0"),+ "{subcommand} writes host bind-mounted files and must run as root \+ under rootless Docker so the write lands as the real host user \+ (rootlesskit only maps container UID 0 back to it); got {args}"+ );+ }++ let args = run_wrapper_with_fake_docker(&["status"], rootless_info);+ assert!(+ !args.contains("-u\n0:0"),+ "thin-client commands only touch the /data named volume, which isn't \+ host-visible, so they must keep the host-UID mapping; got {args}"+ );+}++#[cfg(unix)]+#[test]+fn rootful_docker_keeps_host_uid_for_host_config_commands() {+ let rootful_info = "[name=seccomp,profile=default]";++ let args = run_wrapper_with_fake_docker(&["install-hooks"], rootful_info);+ assert!(+ !args.contains("-u\n0:0"),+ "rootful Docker must not switch to root UID — that would write \+ ~/.local/share/ai-memory/hooks owned by root instead of the invoking \+ user; got {args}"+ );+}+#[test]fn macos_docs_use_valid_install_commands_and_release_body_points_to_them() {let docs = read_repo("docs/macos.md");