Skip to content

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

Rust

fix(wrapper): cover every host-backed invocation (#388)

AkitaOnRailsb7c17c1f5c6d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4df699b6..78e0e3bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,7 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Podman's `.Host.Security.*` keys are consulted when that probe comes back
empty. `bootstrap` is now covered as well: it only reads host files, but an
unmapped UID blocks reads just as hard, and it degraded silently to "no
- `.git` found" before dying (#388).
+ `.git` found" before dying. Restore archives, explicit config paths, and
+ commands using a host-backed `AI_MEMORY_DATA_DIR` now receive the same
+ host-file treatment (#388).
## [1.25.0] - 2026-08-07
diff --git a/README.md b/README.md
index 40e84497..d07ab1e0 100644
--- a/README.md
+++ b/README.md
@@ -578,7 +578,9 @@ one matching entry.
or relabel `$HOME`; do not add `:z`/`:Z` to the whole home bind. Rootless
engines also get `-u 0:0` for those commands. Docker and podman report
rootless mode and SELinux support under different `info` keys; both are
- read. See [`docs/install.md`](docs/install.md#selinux-enforcing-hosts).
+ read. The same treatment applies whenever `AI_MEMORY_DATA_DIR` selects a
+ host directory or an explicit `--config` reads a host file. See
+ [`docs/install.md`](docs/install.md#selinux-enforcing-hosts).
- **Windows:** use the Linux path inside WSL2, or the native Windows wrapper
from PowerShell/cmd. Local supported profiles default to host-native commands:
Claude Code may use its supported `ai-memory.exe` exec form, while other
diff --git a/bin/ai-memory b/bin/ai-memory
index 8cb2d062..c5e77ca0 100755
--- a/bin/ai-memory
+++ b/bin/ai-memory
@@ -406,15 +406,24 @@ USER_ARGS=(-u "$(id -u):$(id -g)")
# (issue #107)
RENDERS_HOST_CONFIG=0
WRAPPER_SUBCOMMAND=""
+EXPLICIT_HOST_CONFIG=0
WRAPPER_ARGS=("$@")
idx=0
while [ "${idx}" -lt "${#WRAPPER_ARGS[@]}" ]; do
arg="${WRAPPER_ARGS[$idx]}"
case "${arg}" in
- --data-dir | --config)
+ --config)
+ EXPLICIT_HOST_CONFIG=1
idx=$((idx + 2))
;;
- --data-dir=* | --config=*)
+ --config=*)
+ EXPLICIT_HOST_CONFIG=1
+ idx=$((idx + 1))
+ ;;
+ --data-dir)
+ idx=$((idx + 2))
+ ;;
+ --data-dir=*)
idx=$((idx + 1))
;;
--*)
@@ -449,12 +458,23 @@ esac
# cannot skip. So readers need the same treatment as writers.
READS_HOST_FILES=0
case "${WRAPPER_SUBCOMMAND}" in
- bootstrap)
+ bootstrap | restore)
READS_HOST_FILES=1
;;
esac
+if [ "${EXPLICIT_HOST_CONFIG}" -eq 1 ]; then
+ READS_HOST_FILES=1
+fi
+# A custom data directory is a host bind at /data, so every command that opens
+# the store touches host files even when it would otherwise be a thin client.
+HOST_DATA_BIND=0
+if [ -n "${AI_MEMORY_DATA_DIR:-}" ] && [ -d "${AI_MEMORY_DATA_DIR}" ]; then
+ HOST_DATA_BIND=1
+fi
TOUCHES_HOST_FILES=0
-if [ "${WRITES_HOST_FILES}" -eq 1 ] || [ "${READS_HOST_FILES}" -eq 1 ]; then
+if [ "${WRITES_HOST_FILES}" -eq 1 ] \
+ || [ "${READS_HOST_FILES}" -eq 1 ] \
+ || [ "${HOST_DATA_BIND}" -eq 1 ]; then
TOUCHES_HOST_FILES=1
fi
@@ -541,10 +561,10 @@ case "$(uname -s 2>/dev/null || true)" in
# "Permission denied" in the rolling file appender.
# Omitting -u lets the container run as its default (uid 1000)
# which matches the volume owner. Keep the earlier rootless-Docker
- # exception for commands that write host config: under rootless Docker,
+ # exception for commands that touch host binds: under rootless Docker,
# UID 0 maps back to the invoking host user and is the only mapping that
- # can write bind-mounted agent config reliably.
- if ! { [ "${ROOTLESS_DOCKER}" -eq 1 ] && [ "${WRITES_HOST_FILES}" -eq 1 ]; }; then
+ # can access bind-mounted host files reliably.
+ if ! { [ "${ROOTLESS_DOCKER}" -eq 1 ] && [ "${TOUCHES_HOST_FILES}" -eq 1 ]; }; then
USER_ARGS=()
fi
;;
@@ -555,7 +575,7 @@ esac
# same content the server sees. Bind-mount a host path if the user
# overrode AI_MEMORY_DATA_DIR; otherwise use the named volume.
DATA_ARGS=(-e "AI_MEMORY_DATA_DIR=/data")
-if [ -n "${AI_MEMORY_DATA_DIR:-}" ] && [ -d "${AI_MEMORY_DATA_DIR}" ]; then
+if [ "${HOST_DATA_BIND}" -eq 1 ]; then
DATA_ARGS+=(-v "${AI_MEMORY_DATA_DIR}:/data")
else
DATA_ARGS+=(-v "${DATA_VOLUME}:/data")
diff --git a/crates/ai-memory-cli/tests/packaging.rs b/crates/ai-memory-cli/tests/packaging.rs
index 66366b68..54fc2578 100644
--- a/crates/ai-memory-cli/tests/packaging.rs
+++ b/crates/ai-memory-cli/tests/packaging.rs
@@ -1266,9 +1266,11 @@ fn rootless_docker_uses_root_uid_only_for_host_config_commands() {
"install-instructions",
"install-skills",
// uninstall edits the same host agent-config files; backup writes
- // its tarball to a host path — same bind mounts, same UID rule.
+ // its tarball to a host path, and restore reads one — same bind
+ // mounts, same UID rule.
"uninstall",
"backup",
+ "restore",
] {
let args = run_wrapper_with_fake_docker(&[subcommand], rootless_info);
assert!(
@@ -1344,6 +1346,7 @@ fn selinux_enforcing_disables_labels_only_for_host_file_commands() {
"install-skills",
"uninstall",
"backup",
+ "restore",
] {
let args = run_wrapper_with_fake_selinux(&[subcommand], selinux_info, "Enforcing");
assert!(
@@ -1503,6 +1506,7 @@ fn podman_rootless_and_selinux_are_detected_without_the_docker_only_field() {
"install-skills",
"uninstall",
"backup",
+ "restore",
] {
let args = run_wrapper_with_fake_podman(&[subcommand], true, true, "Enforcing");
assert!(
@@ -1570,6 +1574,56 @@ fn bootstrap_gets_host_file_treatment_because_it_reads_the_repo() {
);
}
+#[cfg(unix)]
+#[test]
+fn explicit_config_gets_host_file_treatment() {
+ let args = run_wrapper_with_fake_podman(
+ &["--config", "/tmp/config.toml", "status"],
+ true,
+ true,
+ "Enforcing",
+ );
+ assert!(
+ args.contains("-u\n0:0") && args.contains("--security-opt\nlabel=disable"),
+ "an explicit config is read through a host bind and needs both adjustments; got {args}"
+ );
+
+ let args = run_wrapper_with_fake_podman(
+ &["--config=/tmp/config.toml", "status"],
+ true,
+ true,
+ "Enforcing",
+ );
+ assert!(
+ args.contains("-u\n0:0") && args.contains("--security-opt\nlabel=disable"),
+ "the equals form of --config must receive the same treatment; got {args}"
+ );
+}
+
+#[cfg(unix)]
+#[test]
+fn custom_data_dir_makes_thin_commands_touch_host_files() {
+ let args = run_wrapper_with_fake_docker_env(
+ &["status"],
+ FakeInfo::Podman {
+ rootless: true,
+ selinux: true,
+ },
+ Some("Linux"),
+ None,
+ Some("Enforcing"),
+ &[("AI_MEMORY_DATA_DIR", "/tmp")],
+ );
+ assert!(
+ args.contains("-u\n0:0") && args.contains("--security-opt\nlabel=disable"),
+ "a thin command backed by a host data directory needs both adjustments; got {args}"
+ );
+ assert!(
+ args.contains("/tmp:/data"),
+ "the custom data directory must remain the /data bind; got {args}"
+ );
+}
+
#[test]
fn macos_docs_use_valid_install_commands_and_release_body_points_to_them() {
let docs = read_repo("docs/macos.md");
diff --git a/docs/install.md b/docs/install.md
index a0930f47..33f37a0f 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -1727,10 +1727,13 @@ home-directory labels can prevent the helper container from reaching agent
config even when its UID and GID match the host user. The wrapper checks both
the host enforcement mode and the engine's advertised security options. For the
short-lived helper commands that touch host files (`install-*`, `setup-agent`,
-`uninstall`, `backup`, and `bootstrap`), it adds `--security-opt
-label=disable`; thin-client commands remain confined. This relaxes SELinux
-label confinement only for that trusted helper invocation. It does not modify
-the long-lived ai-memory server, which uses an engine-managed named volume.
+`uninstall`, `backup`, `restore`, and `bootstrap`), it adds `--security-opt
+label=disable`; thin-client commands remain confined when they use the named
+data volume and implicit configuration. An explicit `--config` path or a valid
+host-backed `AI_MEMORY_DATA_DIR` also activates the host-file treatment. This
+relaxes SELinux label confinement only for that trusted helper invocation. It
+does not modify the long-lived ai-memory server, which uses an engine-managed
+named volume.
`bootstrap` is in that list even though it only *reads* host files: an
unmapped UID and a confined label block reads just as hard, and the failure is