Skip to content

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

Rust

fix(wrapper): route host commands after global options

Samir Hanna Verzaf20fa7e28e3f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c12c145..edb6869f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,13 @@ version in [`docs/changelog/`](docs/changelog/):
## [Unreleased]
+### Fixed
+
+- Fixed the POSIX Docker wrapper routing host commands into the helper
+ container when `--config` or `--data-dir` preceded the command. Managed
+ launches, MCP bridges and lifecycle hooks now retain their native host
+ route and complete argument list with either global-option syntax (#1602).
+
## [3.2.1] - 2026-10-22
### Fixed
diff --git a/README.md b/README.md
index 7f8a9077..1f0fbbf0 100644
--- a/README.md
+++ b/README.md
@@ -403,7 +403,9 @@ ai-memory install-hooks --agent claude-code --apply
```
On Linux and macOS, the Docker wrapper runs `install-hooks` through its
-checksum-verified native host client. The installed hooks therefore enforce
+checksum-verified native host client. Global options may precede the command,
+for example `ai-memory --config /path/to/config.toml run codex`; the native
+client receives the complete argument list. The installed hooks therefore enforce
client-side capture controls such as `[capture] ignore_paths` and allowlist
mode before an event reaches the spool or network. Set
`AI_MEMORY_HOOK_PLATFORM=posix` explicitly only when you need the legacy shell
diff --git a/bin/ai-memory b/bin/ai-memory
index d85d9292..d56747c5 100755
--- a/bin/ai-memory
+++ b/bin/ai-memory
@@ -651,18 +651,57 @@ refresh_volume_token() {
# ---- intercept wrapper-only subcommands ----------------------------------
-case "${1:-}" in
+# Resolve the command once for host interception and container URL routing.
+# Keep the original argv intact: the native client parses the same global options.
+WRAPPER_SUBCOMMAND=""
+EXPLICIT_HOST_CONFIG=0
+WRAPPER_ARGS=("$@")
+idx=0
+while [ "${idx}" -lt "${#WRAPPER_ARGS[@]}" ]; do
+ arg="${WRAPPER_ARGS[$idx]}"
+ case "${arg}" in
+ --config= | --data-dir=)
+ break
+ ;;
+ --config)
+ [ "$((idx + 1))" -lt "${#WRAPPER_ARGS[@]}" ] || break
+ case "${WRAPPER_ARGS[$((idx + 1))]}" in "" | -?*) break ;; esac
+ EXPLICIT_HOST_CONFIG=1
+ idx=$((idx + 2))
+ ;;
+ --config=*)
+ EXPLICIT_HOST_CONFIG=1
+ idx=$((idx + 1))
+ ;;
+ --data-dir)
+ [ "$((idx + 1))" -lt "${#WRAPPER_ARGS[@]}" ] || break
+ case "${WRAPPER_ARGS[$((idx + 1))]}" in "" | -?*) break ;; esac
+ idx=$((idx + 2))
+ ;;
+ --data-dir=*)
+ idx=$((idx + 1))
+ ;;
+ --*)
+ # Help, version and invalid options belong to the CLI parser. In
+ # particular, none may accidentally trigger the wrapper's upgrade.
+ break
+ ;;
+ *)
+ WRAPPER_SUBCOMMAND="${arg}"
+ break
+ ;;
+ esac
+done
+
+case "${WRAPPER_SUBCOMMAND}" in
upgrade)
- shift
cmd_upgrade
exit 0
;;
run | show | continue | resume | workstreams | rename-workstream)
- NATIVE_HOST_COMMAND=$1
- shift
NATIVE_HOST_BIN=$(native_host_binary)
use_volume_token
- exec "${NATIVE_HOST_BIN}" "${NATIVE_HOST_COMMAND}" "$@"
+ exec "${NATIVE_HOST_BIN}" "$@"
;;
install-hooks)
# Capture exclusions and allowlist mode are client-side privacy controls.
@@ -796,36 +835,6 @@ 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
-WRAPPER_SUBCOMMAND=""
-EXPLICIT_HOST_CONFIG=0
-WRAPPER_ARGS=("$@")
-idx=0
-while [ "${idx}" -lt "${#WRAPPER_ARGS[@]}" ]; do
- arg="${WRAPPER_ARGS[$idx]}"
- case "${arg}" in
- --config)
- EXPLICIT_HOST_CONFIG=1
- idx=$((idx + 2))
- ;;
- --config=*)
- EXPLICIT_HOST_CONFIG=1
- idx=$((idx + 1))
- ;;
- --data-dir)
- idx=$((idx + 2))
- ;;
- --data-dir=*)
- idx=$((idx + 1))
- ;;
- --*)
- idx=$((idx + 1))
- ;;
- *)
- WRAPPER_SUBCOMMAND="${arg}"
- break
- ;;
- esac
-done
WRITES_HOST_FILES=0
case "${WRAPPER_SUBCOMMAND}" in
install-mcp | install-hooks | setup-agent)
diff --git a/docs/security-boundaries.md b/docs/security-boundaries.md
index 2d435ee8..1539f569 100644
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@ -96,7 +96,7 @@ means the boundary is not built yet.
| 11e | Native self-upgrade archive confinement (#1025) | `ai-memory-cli/src/commands/upgrade.rs` normalizes every tar/zip path, rejects links and special entries, extracts only the binary and `hooks/`, accepts only the exact non-runtime support layout emitted by `release.yml`, and caps both entry count and declared expanded bytes before writing | `upgrade.rs` `release_workflow_support_assets_are_exact_and_ignored` (shipped support paths admitted, near-miss docs/packaging/template paths refused), `extracts_archive_built_like_release_yml` and `extracts_zip_happy_path_with_hooks` (real workflow-shaped archives succeed but support assets are not written), `validate_rejects_path_traversal`, `zip_extract_rejects_path_traversal`, `tar_extract_rejects_declared_expansion_past_limit`, with binary/hooks extraction as the legitimate control | STRONG |
| 11f | Native hook executable-path integrity after self-replacement (#1027) | `ai-memory-cli/src/commands/render_shared.rs` `hook_embedded_exe_path` is the single executable resolver for every persisted native hook form (POSIX/Windows command, Windows exec, Zero, ZCode, OpenCode 2 assistant capture): it prefers an existing literal path, strips Linux's trailing ` (deleted)` procfs marker only when the stripped installed binary exists, and otherwise falls back to the platform command name. A binary running from `/nix/store` always renders the bare command (#1275): the store path names one package version that garbage collection deletes, while the profile's `bin/` on `PATH` follows upgrades. Upgrade keeps the already-loaded config and refreshes in-process | `render_shared.rs` `embedded_exe_strips_the_marker_when_the_stripped_path_exists`, `embedded_exe_preserves_a_real_file_whose_name_has_the_marker_suffix`, `embedded_exe_falls_back_when_the_resolved_path_is_missing`, `hook_embedded_exe_path_names_an_existing_file_without_marker` (asserts the bare command only when the test binary itself runs from the Nix store), `hook_rendered_from_a_nix_store_exe_names_the_bare_command` (the existence probe reports the store binary present, so only the store-path guard yields the bare command in the rendered exec hook) with its control `hook_rendered_from_a_normal_exe_keeps_the_absolute_path` (`/usr/bin`, `~/.nix-profile/bin`, and a non-root `.../nix/store/...` keep the absolute path); `upgrade_e2e.rs` `native_upgrade_refreshes_hooks_without_a_deleted_path_or_losing_cli_data_dir` reproduces the replacement window through the shipped binary, plants the corrupt suffix, and proves refresh removes it while preserving a CLI-only data dir | STRONG on Linux reproduction plus platform-neutral resolver/render coverage; Windows path rendering remains covered by its existing command/exec tests and full Windows CI |
| 11g | Cross-project tool attribution cannot bypass source or destination capture, or destination server routing (#932, #1199) | `ai-memory-hooks/src/capture_policy.rs` `absolute_tool_location_paths` accepts only bounded, recognized, absolute locations: file-tool targets, a search/list tool's explicit `path`, or a shell command's structured `workdir` (command text is never parsed for a location); `ai-memory-cli/src/commands/hook.rs` `tool_location_routing_cwd` requires every path to prove the same repository/marker boundary, refuses the reroute when the payload cwd's own capture policy would not keep the event (source `ignore_paths` may name paths outside the source checkout, and a command may name source files while its `workdir` points elsewhere), and resolves that destination before capture policy, allowlist marker, server profile, scope hints, or spool credentials. Relative, mixed-project, unsupported, and arbitrary non-project paths keep the payload cwd. For Hermes, `hook.rs` `hermes_terminal_cwd` replaces the reported process cwd with `TERMINAL_CWD` (read from the captured `RuntimeEnv`) only when it names an existing absolute directory and, inside a gateway (`_HERMES_GATEWAY=1`), only for an event whose `profile` is `default`, the profile whose `terminal.cwd` a multiplexing gateway exports, before the location lookup above, so that checkout's capture policy, allowlist marker and server profile govern the event | `hook.rs` `absolute_file_target_uses_destination_scope_and_capture_policy` (hostile content under the destination exclusion is never spooled; a public control is routed there), `absolute_file_target_cannot_escape_a_destination_server_profile` (unregistered destination profile drops instead of falling back to source/install default), `file_target_routing_refuses_relative_external_and_mixed_project_paths`, `workdir_reroute_applies_the_destination_capture_policy` (a `workdir`-rerouted command reading a destination-excluded path is dropped, public control kept), **`a_reroute_cannot_escape_the_source_capture_exclusions`** (adversarial: a file read under a source pattern that names another project's directory, and a shell command naming an excluded source file with `workdir` in another project, are both refused; public file and shell controls still reroute; fails with the source-policy check removed), `hermes_tool_location_finds_the_marker_the_process_cwd_lacks` (Hermes `terminal` `workdir`, `read_file` `path` and `search_files` `path` reach the repository marker under allowlist; no-workdir, relative-workdir and relative-search controls stay with the unmarked process cwd), **`hermes_terminal_cwd_applies_the_selected_checkout_policy`** (adversarial: with `TERMINAL_CWD` selecting a checkout, a relative read of a path it excludes is never spooled and a marker naming an unregistered server profile drops the event; public control kept; fails with the `TERMINAL_CWD` routing removed), `hermes_terminal_cwd_routes_lifecycle_events` (allowlist: a prompt is captured only through an existing absolute `TERMINAL_CWD`; unset, relative and missing values stay with the unmarked process cwd), `hermes_gateway_terminal_cwd_routes_only_the_default_profile` (a multiplexed gateway's variable does not route another profile's event), `hermes_tool_events_prefer_their_locations_then_terminal_cwd`; `capture_policy.rs` `absolute_tool_location_paths_cover_search_dirs_and_shell_workdirs` (relative workdir, command-text paths, workdir without a command, and Hermes `process` yield no location) | STRONG for native `ai-memory hook`; generated and compatibility hooks retain cwd-only routing |
-| 11h | Docker-wrapper capture-policy capability (#1002) | `bin/ai-memory` routes ordinary Linux/macOS `install-hooks`, upgrade refreshes, and every `hook`/`hook-drain` invocation through the stable checksum-verified native host client, so the hook process executes the capture-policy boundary in 11b before spool/network; a hook config that calls the wrapper never runs in the helper container, and an unavailable client drops the event with exit 0 instead of falling back to it. Only an explicit `AI_MEMORY_HOOK_PLATFORM=posix|windows` retains the documented script compatibility path and its warning; `AI_MEMORY_NATIVE_BIN` may not point back to the wrapper. For a server initialized on the named volume, `bin/ai-memory` `refresh_volume_token` (run only by `install-hooks`) copies `/data/auth-tokens/default` (only when `/data/config.toml` names it) to an owner-only `native-runner/server-token` through the helper's stdout, and `use_volume_token` points the native client at that copy (the managed host commands and `mcp-bridge` only read it and never enter the container engine) with `AI_MEMORY_AUTH__BEARER_TOKEN_FILE`, so it is a file-sourced token (never rendered into a harness config) and never an argv; a refresh that reads no token from a reachable volume deletes the copy, and a successful full `uninstall --apply` deletes it after the container returns; a bind-mounted `AI_MEMORY_DATA_DIR` is read directly and an explicit `AI_MEMORY_AUTH_TOKEN` wins | `scripts/check-native-packaging.sh` `Checking host-launch wrapper routing`: a default allowlist install reaches the fake native client while a Docker executable that always fails proves no container fallback occurred; the explicit `posix` control reaches fake Docker and adds no native invocation; the self-referential native override is refused. `tests/wrapper_upgrade.sh` `lifecycle hook native host routing`: `hook --event session-start` and `hook-drain` reach the fake native client with the stdin payload while `docker`/`podman` stubs on PATH and in `AI_MEMORY_DOCKER` stay unused, and a non-executable `AI_MEMORY_NATIVE_BIN` exits 0 without reaching the engine; `Checking the wrapper hands host commands the volume's root bearer`: for `mcp-bridge`, `install-hooks` and `run` the fake native client receives the token file (mode 600, right content) and the token is absent from its argv; controls: a bind-mounted data dir and an explicit `AI_MEMORY_AUTH_TOKEN` make no copy and ask no container (bite: dropping the export fails the check); `Checking the host token copy goes with the volume's token and with uninstall`: a volume answering with no token removes the copy and hands none over, while an unreachable engine keeps it; a dry-run, `--only hooks` or failing `uninstall` keeps it and a successful `uninstall --apply` removes it (bite: without either removal the check fails); `auth_default_e2e.rs` `a_host_client_given_the_token_file_by_env_authenticates` (the native side of the handoff, with a no-variable control) | STRONG on the shipped Linux/macOS wrapper. Windows and remote/manual script installers remain explicitly outside capture-policy v1 |
+| 11h | Docker-wrapper capture-policy capability (#1002) | `bin/ai-memory` routes ordinary Linux/macOS `install-hooks`, upgrade refreshes, and every `hook`/`hook-drain` invocation through the stable checksum-verified native host client, so the hook process executes the capture-policy boundary in 11b before spool/network; a hook config that calls the wrapper never runs in the helper container, and an unavailable client drops the event with exit 0 instead of falling back to it. Only an explicit `AI_MEMORY_HOOK_PLATFORM=posix|windows` retains the documented script compatibility path and its warning; `AI_MEMORY_NATIVE_BIN` may not point back to the wrapper. For a server initialized on the named volume, `bin/ai-memory` `refresh_volume_token` (run only by `install-hooks`) copies `/data/auth-tokens/default` (only when `/data/config.toml` names it) to an owner-only `native-runner/server-token` through the helper's stdout, and `use_volume_token` points the native client at that copy (the managed host commands and `mcp-bridge` only read it and never enter the container engine) with `AI_MEMORY_AUTH__BEARER_TOKEN_FILE`, so it is a file-sourced token (never rendered into a harness config) and never an argv; a refresh that reads no token from a reachable volume deletes the copy, and a successful full `uninstall --apply` deletes it after the container returns; a bind-mounted `AI_MEMORY_DATA_DIR` is read directly and an explicit `AI_MEMORY_AUTH_TOKEN` wins | `scripts/check-native-packaging.sh` `Checking host-launch wrapper routing`: a default allowlist install reaches the fake native client while a Docker executable that always fails proves no container fallback occurred; the explicit `posix` control reaches fake Docker and adds no native invocation; the self-referential native override is refused. `tests/wrapper_upgrade.sh` global-option routing matrix: both separated and `=` forms of `--config`/`--data-dir` preserve native argv, stdin and exit status for all host commands, including hooks; a missing prefixed hook client drops the event without container fallback, while search and explicit script-compatibility controls still use the helper (bite: dispatching on `$1` fails these checks). `tests/wrapper_upgrade.sh` `lifecycle hook native host routing`: `hook --event session-start` and `hook-drain` reach the fake native client with the stdin payload while `docker`/`podman` stubs on PATH and in `AI_MEMORY_DOCKER` stay unused, and a non-executable `AI_MEMORY_NATIVE_BIN` exits 0 without reaching the engine; `Checking the wrapper hands host commands the volume's root bearer`: for `mcp-bridge`, `install-hooks` and `run` the fake native client receives the token file (mode 600, right content) and the token is absent from its argv; controls: a bind-mounted data dir and an explicit `AI_MEMORY_AUTH_TOKEN` make no copy and ask no container (bite: dropping the export fails the check); `Checking the host token copy goes with the volume's token and with uninstall`: a volume answering with no token removes the copy and hands none over, while an unreachable engine keeps it; a dry-run, `--only hooks` or failing `uninstall` keeps it and a successful `uninstall --apply` removes it (bite: without either removal the check fails); `auth_default_e2e.rs` `a_host_client_given_the_token_file_by_env_authenticates` (the native side of the handoff, with a no-variable control) | STRONG on the shipped Linux/macOS wrapper. Windows and remote/manual script installers remain explicitly outside capture-policy v1 |
| 11j | Offline recovery journal and transcript replay | `ai-memory-cli/src/commands/recovery.rs` keeps bounded locators, ordered semantic transcript digests, pre-launch cursors and persistent correlated-delivery/loss evidence in an atomic journal, refuses a symlinked data dir and any symlinked component inside it (ancestors above the data dir are trusted, so macOS `/var` → `/private/var` works), sanitizes/caps failure reasons, and bounds each replay plus the whole pass; `hook_spool` coordinates enqueue and quarantine with short filesystem locks, canonically resolves partial scope from the recorded cwd, bounds per-file reads and current global occupancy across the main spool and recovery directories, sweeps completed tombstones, and holds correlated events outside drain until replay succeeds or restores them on failure; degraded resumes use `ai-memory-workstream`'s adapter-validated delta export, whose blocking parse and baseline scans are capped by record, event-count, source-byte and serialized-byte totals; `backfill::import_exact_session` chunks by item and byte limits and requires per-item durable acknowledgements; `run.rs` journals every session launch, including explicit spool-only evidence for unsupported exporters, and journals a resumed export only after capturing its exact pre-launch cursor; `workstream.rs` `/recover/finish` retains owner/project authorization, rejects superseded runs, and validates a finished retry by durable transcript/native/cursor/exit identity without regenerating its checkpoint; validated recovery ingest keys bind session, agent, event kind and sanitized event identity until session purge | `transcript.rs` `persisted_baseline_exports_only_offline_append_and_rejects_rewrite`, parser/baseline cap and ordered-semantic digest tests; CLI `run_offline.rs` real degraded spool-only and overlap/idempotency tests; `recovery.rs` `spool_only_without_correlated_evidence_never_auto_clears`, `a_dropped_spool_event_stays_lost_on_the_next_empty_pass`, loss/time-budget tests, `symlinked_journal_and_ancestor_are_refused`, `a_symlinked_ancestor_of_the_data_dir_is_trusted`, `a_symlink_inside_a_data_dir_under_a_symlinked_ancestor_is_refused`; `hook_spool.rs` partial-scope late enqueue, completion-race, occupancy churn/active-cap, bounded-read and tombstone-sweep tests, plus interval isolation (`completed_tombstone_keeps_a_later_resume_of_the_same_session` proves a post-interval resume hook is delivered, `completing_one_recovery_interval_leaves_the_other_intervals_entries_intact` proves one interval's completion never consumes another's evidence and ambiguous entries fail closed into the main spool); `backfill.rs` `two_sequential_recovery_intervals_on_one_resumed_session_replay_exactly_once` proves the second interval's content and session-end are stored with end-of-session effects while reruns stay pure replays; `transcript.rs` `an_oversized_first_record_is_skipped_by_session_listing_caps` proves the first-record byte caps bite before allocation; store `insert_observation_ingest_dedups_on_key` rejects cross-session and changed-event preclaims; hooks `expired_run_recovery_is_owner_only_and_refuses_superseded_runs` proves changed transcript refusal and changed-checkpoint no-op | STRONG on Unix integration coverage; Unix lock opens use no-follow and atomic replacement rechecks the destination. Windows owner-only ACL/reparse and lock semantics require the PR `windows` lane |
| 11i | OpenCode executable probing and generated-config cleanup (#1097) | `ai-memory-cli/src/config.rs` captures the full process environment once in typed `RuntimeEnv`; `run.rs` overlays explicit `run --env` values with platform key semantics and uses that same effective environment for executable resolution, probing, and launch without rereading process environment; `opencode_dialect.rs` invokes only direct argv `--version`, caps output and time, and rejects malformed/future majors. Automatic launch skips only OpenCode on probe failure; explicit OpenCode fails. `install_hooks.rs` quarantines the incompatible sibling before reading its exact ownership markers, restores unowned content with an atomic no-replace link, and never deletes or overwrites a concurrent replacement; `install_mcp.rs` owns the shared dual-schema endpoint/token inference used by both installers, rejects conflicting generated V1/V2 entries before mutation, and migrates an alternate-major entry only when endpoint, generated shape, and absent-or-Authorization-only headers match, preserving custom headers and ambiguous entries; auto-wire migrates MCP before hooks infer from that exact config path and skips hook mutation when transition preflight fails | `run.rs` `automatic_opencode_probe_failure_keeps_another_harness_available`, `opencode_executable_probe_selects_v2_for_launch_and_autowire`, effective-child-environment PATH casing controls, fake V1/V2/env-derived-major/malformed/future/timeout executable tests, `setup-agent` V1/V2 no-probe integration controls; `install_hooks.rs` `opencode_plugin_cleanup_removes_only_exact_owned_incompatible_sibling`, `opencode_plugin_cleanup_preserves_a_concurrent_user_replacement`, `opencode_plugin_restore_moves_quarantine_when_destination_is_free`, `opencode_plugin_restore_preserves_an_existing_replacement`, `opencode_plugin_restore_does_not_replace_a_file_created_at_restore_window`, `opencode_plugin_cleanup_does_not_escape_custom_target_directory`; `install_mcp.rs` `opencode_install_reuses_owned_endpoint_and_token_across_major_transitions`, `opencode_install_refuses_conflicting_owned_transition_entries`, `opencode_install_does_not_infer_from_a_user_owned_transition_entry`, `opencode_mcp_migration_moves_only_owned_alternate_shape`, `opencode_mcp_migration_preserves_ambiguous_user_entry`, `opencode_mcp_migration_preserves_custom_headers`, `opencode_mcp_migration_accepts_only_historical_generated_headers` | STRONG for Unix process probes and platform-neutral ownership gates; exact Windows executable resolution remains covered by `run.rs` resolver tests and requires the PR `windows` label |
| 11k | Server-side ingest drop list: tool id/name lists (#1241) and whole event kinds (`[ingest] drop_events`) | `ai-memory-hooks/src/drop_list.rs` `IngestDropList`: `matches` for the tool lists (a tool-call id by prefix, a tool name exactly) and `matches_event_kind` for the whole kinds (every `[ingest] drop_events` value parsed with the typed `HookEvent::parse`; `session-start`/`session-end` and the `other` bucket rejected), both validated once in `Config::load` (tool lists: at most 64 entries of 128 printable characters each). Checked in `router.rs` `admit_hook` and the `handle_hook_batch` loop after the subagent exclusion (`should_drop_subagent`) and before the rate limiter, ingest semaphore, sanitizer, and storage, so a marked subagent event seeds the tracking set its unmarked tail is dropped against even when its tool id, tool name, or event kind is listed. The tool lists match only tool events and are read through the per-agent mapping `capture_policy::tool_payload_fields` that tool metadata uses. A drop answers 202 and counts as `dropped_by_policy`; the matched value is never logged | tool lists: `router.rs` `the_ingest_drop_list_drops_before_any_capacity_is_spent`, `the_ingest_drop_list_applies_to_hook_batches`, `marked_tool_policy_drops_seed_subagent_tracking_before_single_ingress_matching`, and `marked_tool_policy_drops_seed_subagent_tracking_before_batch_matching` cover capacity, batch acknowledgements, id-prefix and exact-name seeding order, unmarked tails, and stored controls; `drop_list.rs` unit tests cover bounds, exact matching, and each agent's native fields. Whole kinds: `router.rs` `the_ingest_drop_events_drops_the_named_kind_and_keeps_the_rest`, `the_ingest_drop_events_drops_before_any_capacity_is_spent`, `the_ingest_drop_events_consumes_no_rate_budget`, `the_ingest_drop_events_batch_reports_per_index_outcomes_and_only_stores_the_kept`, `the_ingest_drop_events_keeps_dropping_the_unmarked_subagent_tail`, `the_ingest_drop_events_keeps_dropping_the_unmarked_subagent_tail_in_batches`, and `a_marked_event_of_a_dropped_kind_still_seeds_subagent_tracking`; `drop_list.rs` `drop_events_*` tests cover typed matching and rejected state/unknown kinds. Moving any matcher before subagent exclusion fails its single/batch tail tests; removing either batch matcher fails its batch contract | STRONG. The list applies to every project on the server; it narrows what is stored and never widens access |
diff --git a/scripts/check-native-packaging.sh b/scripts/check-native-packaging.sh
index f86f1581..4cb389b1 100755
--- a/scripts/check-native-packaging.sh
+++ b/scripts/check-native-packaging.sh
@@ -164,6 +164,14 @@ main() {
AI_MEMORY_DOCKER="${fake_docker}" AI_MEMORY_NATIVE_BIN="${fake_native}" \
AI_MEMORY_WRAPPER_TEST_LOG="${wrapper_log}" \
bin/ai-memory install-hooks --agent claude-code --capture-mode allowlist --apply
+ AI_MEMORY_DOCKER="${fake_docker}" AI_MEMORY_NATIVE_BIN="${fake_native}" \
+ AI_MEMORY_WRAPPER_TEST_LOG="${wrapper_log}" \
+ bin/ai-memory --config '/tmp/ai memory.toml' run codex --yolo
+ AI_MEMORY_DOCKER="${fake_docker}" AI_MEMORY_NATIVE_BIN="${fake_native}" \
+ AI_MEMORY_WRAPPER_TEST_LOG="${wrapper_log}" \
+ bin/ai-memory --data-dir=/tmp/ai-memory show --json
+ assert_contains "${wrapper_log}" "--config /tmp/ai memory.toml run codex --yolo"
+ assert_contains "${wrapper_log}" "--data-dir=/tmp/ai-memory show --json"
assert_contains "${wrapper_log}" "run codex --yolo"
assert_contains "${wrapper_log}" "show --json --no-scan"
assert_contains "${wrapper_log}" "continue --workspace work --yolo"
diff --git a/tests/wrapper_upgrade.sh b/tests/wrapper_upgrade.sh
index 305d3a98..5ff394f3 100755
--- a/tests/wrapper_upgrade.sh
+++ b/tests/wrapper_upgrade.sh
@@ -73,21 +73,25 @@ chmod 0755 "${FAKE_DOCKER}"
run_upgrade_case() {
local name="$1" owns="$2" case_dir log output
+ shift 2
case_dir="${TMP_ROOT}/${name}"
log="${case_dir}/docker.log"
output="${case_dir}/output.log"
mkdir -p "${case_dir}/home" "${case_dir}/cache"
: >"${case_dir}/docker-compose.yml"
+ printf '%s\n' '#!/usr/bin/env bash' 'exit 0' >"${case_dir}/native-client"
+ chmod 0755 "${case_dir}/native-client"
(
cd "${case_dir}"
HOME="${case_dir}/home" \
XDG_CACHE_HOME="${case_dir}/cache" \
AI_MEMORY_DOCKER="${FAKE_DOCKER}" \
+ AI_MEMORY_NATIVE_BIN="${case_dir}/native-client" \
AI_MEMORY_SKIP_SELF_UPGRADE=1 \
AI_MEMORY_WRAPPER_TEST_LOG="${log}" \
AI_MEMORY_TEST_COMPOSE_OWNS="${owns}" \
- "${ROOT}/bin/ai-memory" upgrade >"${output}" 2>&1
+ "${ROOT}/bin/ai-memory" "$@" upgrade >"${output}" 2>&1
)
}
@@ -108,6 +112,9 @@ if [ -e "${TMP_ROOT}/compose/cache/ai-memory/recreate-ai-memory.sh" ]; then
fail "Compose-owned container unexpectedly produced a standalone recreation script"
fi
+run_upgrade_case prefixed 1 --config '/tmp/ai memory.toml'
+assert_contains "${TMP_ROOT}/prefixed/docker.log" "compose up -d"
+
# ---- multi-arch manifest version-check tests -----------------------------
if command -v python3 >/dev/null 2>&1; then
@@ -293,6 +300,8 @@ cat >"${HOOK_NATIVE}" <<'NATIVE'
#!/usr/bin/env bash
printf 'argv: %s\n' "$*" >>"${AI_MEMORY_WRAPPER_TEST_LOG}"
printf 'stdin: %s\n' "$(cat)" >>"${AI_MEMORY_WRAPPER_TEST_LOG}"
+printf 'arg: <%s>\n' "$@" >>"${AI_MEMORY_WRAPPER_TEST_LOG}"
+exit "${AI_MEMORY_TEST_NATIVE_EXIT:-0}"
NATIVE
chmod 0755 "${HOOK_NATIVE}"
@@ -337,12 +346,87 @@ run_hook_case "${HOOK_NATIVE}" hook-drain </dev/null
assert_contains "${HOOK_CASE_DIR}/native.log" "argv: hook-drain"
assert_no_container "hook-drain"
+# A global option before the command must not send host work or capture to a
+# helper container. Inspect each argument separately so paths with spaces and
+# harness arguments remain intact, and preserve the native child's exit code.
+for subcommand in run show continue resume workstreams rename-workstream install-hooks mcp-bridge hook hook-drain; do
+ for option in config data-dir; do
+ for form in separate equals; do
+ prefix=("--${option}" '/tmp/ai memory')
+ if [ "${form}" = equals ]; then
+ prefix=("--${option}=/tmp/ai memory")
+ fi
+ args=("${prefix[@]}" "${subcommand}" '--' 'argument with spaces')
+ : >"${HOOK_CASE_DIR}/native.log"
+ : >"${HOOK_CASE_DIR}/docker.log"
+ native_status=0
+ # The bind-mounted data directory needs no volume-token refresh during
+ # install-hooks; the entire invocation must stay on the host.
+ printf '{"session_id":"prefixed"}' | AI_MEMORY_DATA_DIR="${HOOK_CASE_DIR}/home" \
+ AI_MEMORY_TEST_NATIVE_EXIT=7 run_hook_case "${HOOK_NATIVE}" "${args[@]}" \
+ || native_status=$?
+ [ "${native_status}" -eq 7 ] || fail "${args[*]} returned ${native_status}, want native exit 7"
+ printf 'arg: <%s>\n' "${args[@]}" >"${HOOK_CASE_DIR}/expected-args"
+ grep '^arg: ' "${HOOK_CASE_DIR}/native.log" >"${HOOK_CASE_DIR}/actual-args"
+ cmp "${HOOK_CASE_DIR}/expected-args" "${HOOK_CASE_DIR}/actual-args" \
+ || fail "native argv changed for ${args[*]}"
+ assert_contains "${HOOK_CASE_DIR}/native.log" 'stdin: {"session_id":"prefixed"}'
+ assert_no_container "${args[*]}"
+ done
+ done
+done
+
+# A value or search query named like a host command is not the subcommand.
+: >"${HOOK_CASE_DIR}/native.log"
+: >"${HOOK_CASE_DIR}/docker.log"
+run_hook_case "${HOOK_NATIVE}" --config run search hook </dev/null
+[ ! -s "${HOOK_CASE_DIR}/native.log" ] || fail "a config value was intercepted as a host command"
+assert_contains "${HOOK_CASE_DIR}/docker.log" '--config run search hook'
+
+# Help, version and malformed arguments must reach the CLI without running
+# wrapper-only upgrade side effects, even when followed by that command name.
+for option in --help --version --not-an-option; do
+ for prefix in none config data-dir; do
+ args=("${option}" upgrade)
+ if [ "${prefix}" != none ]; then
+ args=("--${prefix}" "${args[@]}")
+ fi
+ : >"${HOOK_CASE_DIR}/native.log"
+ : >"${HOOK_CASE_DIR}/docker.log"
+ run_hook_case "${HOOK_NATIVE}" "${args[@]}" </dev/null
+ [ ! -s "${HOOK_CASE_DIR}/native.log" ] || fail "${args[*]} reached a host command"
+ assert_not_contains "${HOOK_CASE_DIR}/docker.log" 'pull '
+ assert_contains "${HOOK_CASE_DIR}/docker.log" "${args[*]}"
+ done
+done
+
+for option in config data-dir; do
+ for form in separate equals; do
+ args=("--${option}" '' upgrade)
+ if [ "${form}" = equals ]; then
+ args=("--${option}=" upgrade)
+ fi
+ : >"${HOOK_CASE_DIR}/docker.log"
+ run_hook_case "${HOOK_NATIVE}" "${args[@]}" </dev/null
+ assert_not_contains "${HOOK_CASE_DIR}/docker.log" 'pull '
+ assert_contains "${HOOK_CASE_DIR}/docker.log" "${args[*]}"
+ done
+done
+
+# The explicit compatibility path still uses the helper with a prefix.
+: >"${HOOK_CASE_DIR}/docker.log"
+AI_MEMORY_HOOK_PLATFORM=posix run_hook_case "${HOOK_NATIVE}" \
+ --data-dir '/tmp/ai memory' install-hooks --agent claude-code --apply </dev/null
+[ ! -s "${HOOK_CASE_DIR}/native.log" ] || fail "explicit compatibility install reached native client"
+assert_contains "${HOOK_CASE_DIR}/docker.log" 'install-hooks --agent claude-code --apply'
+: >"${HOOK_CASE_DIR}/docker.log"
+
# Without a usable native client the hook drops the event, says why on stderr,
# and still exits 0 at once; it never falls back to the container.
: >"${HOOK_CASE_DIR}/native.log"
hook_status=0
printf '{}' | run_hook_case "${HOOK_CASE_DIR}/missing-ai-memory" \
- hook --agent claude-code --event session-start 2>"${HOOK_CASE_DIR}/missing.err" \
+ --config /tmp/memory.toml hook --agent claude-code --event session-start 2>"${HOOK_CASE_DIR}/missing.err" \
|| hook_status=$?
[ "${hook_status}" -eq 0 ] || fail "hook without a native client exited ${hook_status}, want 0"
assert_contains "${HOOK_CASE_DIR}/missing.err" "AI_MEMORY_NATIVE_BIN is not executable"