Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge upstream/main into issue/801-native-cli-upgrade
Ruben Licio Reisd8b00bef108c
diff --cc CHANGELOG.mdindex 697f4717,cc5e182d..f7b85297--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -7,19 -7,65 +7,89 @@@ and this project adheres to [Semantic V## [Unreleased]+### Added+- Native `ai-memory upgrade` for GitHub-release Unix installs (Linux/macOS):+ downloads the matching release tarball, verifies the `.sha256` sidecar,+ atomically replaces the on-disk binary (and a sibling `hooks/` tree when+ present), then re-runs `install-hooks --apply` for staged agents. Refuses+ package-managed paths (Homebrew/AUR/`/usr`), containers, and Windows+ self-replace; the Docker wrapper's `upgrade` path is unchanged. Pin with+ `--version` / force a re-download with `--force`. Optional+ `AI_MEMORY_RELEASE_BASE_URL` / `release_base_url` overrides the Releases+ base for mirrors and hermetic tests (loaded via `Config`, not ad-hoc env).+ Downloads refuse bodies over 128 MiB (Content-Length and streamed cap).+ (#801)++ ### Fixed++- Native `ai-memory upgrade` no longer refuses every Linux install by probing++ the running executable for write (Linux `ETXTBSY`); it only requires the++ parent directory to be writable for rename-based replace. (#802)++- Native `ai-memory upgrade` accepts release archives whose entries are++ `./`-prefixed (`tar -C … -czf … .` as in `release.yml`), instead of++ rejecting `Component::CurDir` as an unsafe path. (#802)++- Native `ai-memory upgrade` treats Linuxbrew (`/home/linuxbrew/.linuxbrew/`)++ as package-managed and refuses self-replace there. (#802)++- Native `ai-memory upgrade` container refusal now uses the shared++ `running_in_container` helper (`AI_MEMORY_IN_CONTAINER`, `/.dockerenv`,++ `/run/.containerenv` / Podman), matching staged-hooks detection. (#802)+ - `memory_message_pop` and `memory_message_list` no longer return a silent+ empty result when the inbox scope was *inferred* rather than named. A caller+ with no explicit `workspace`/`project` and no forwarded hook-session id+ resolves the shared active-project slot (whichever project published last),+ so two same-operator agents can have a no-scope pop land on a different inbox+ than the on-start notice / `memory_briefing` counted — "you have mail"+ followed by an empty fetch, with no way to tell it was the wrong inbox. An+ empty read from an inferred scope now reports the `resolved_scope`+ (workspace + project), the `scope_source`, and a hint to re-run with explicit+ scope; an explicitly-scoped or session-bound empty read is unchanged. No+ message is lost — the mis-scoped pop consumes nothing. (#854)+ - `companions/ai-memory-macos/build.sh` no longer fails on machines whose+ active developer directory is Command Line Tools only: SwiftUI `@State`+ needs the `SwiftUIMacros` plugin shipped with full Xcode, so the script+ now exports `DEVELOPER_DIR` to Xcode (or a caller-set path) before+ `swift build`, with a clear error when no macOS platform is present. (#849)+ - `ai-memory serve` no longer leaked file descriptors from half-open HTTP+ connections until `EMFILE`, breaking the healthcheck (an unauthenticated+ availability/DoS). A hook or MCP client whose peer died without sending FIN+ (laptop sleep, a VPN/Tailscale flap, an abrupt kill) left its accepted+ socket `ESTABLISHED` forever, since the OS default has TCP keepalive off —+ each dead peer leaked one fd, exhausting the 1024-fd default in roughly 2-3+ days of normal churn. Accepted connections now get TCP keepalive via+ `socket2`, tunable with the new `tcp_keepalive_secs` config key (default+ 60s; `AI_MEMORY_TCP_KEEPALIVE_SECS=0` disables keepalive). This closes the+ half-open-socket half of the fd leak; the rmcp session-table half was+ already fixed in 2.4.0 by the rmcp 2.x bump. (#792)+ - `ai-memory bootstrap` no longer returns a 500 when the LLM emits a page+ path containing a Windows-illegal character (e.g. a `:` copied verbatim+ from a conventional-commit subject like `build(sandbox): orchestrate`).+ Such a path passed the deliberately tolerant `PagePath::new` and only+ failed later at `ensure_portable` inside the atomic wiki write batch,+ which aborted every page in the run, not just the offending one. Bad+ paths are now sanitized (illegal characters replaced with `-`, directory+ shape preserved) before validation, so the run and its other pages+ survive; a path `ensure_portable` still rejects after sanitizing is+ skipped with a warning instead of failing the batch. (#847)+ - Per-session consolidation (`consolidate_session_multi`) had the same+ Windows-illegal-path defect as `ai-memory bootstrap` (#847): an+ LLM-produced page path containing a character like `:` passed the+ deliberately tolerant `PagePath::new` and only failed later at+ `ensure_portable` inside the atomic wiki write batch, losing every other+ page from that session's consolidation run. The path is now sanitized+ the same way bootstrap's is, consistently across rule-routing, per-user+ slot placement, and the session-anchor comparison, before validation;+ a path `ensure_portable` still rejects after sanitizing is skipped with+ a warning instead of failing the batch. (#848)+ - The Windows release checksum (`ai-memory-windows-x86_64.zip.sha256`) is now+ written with a LF terminator instead of CRLF. `Out-File`'s Windows line+ ending made `sha256sum -c` fail with `No such file or directory` — the CR+ is read as part of the filename — on the WSL2 and Git Bash paths where that+ is the natural command, and placed a stray byte in the release body's+ checksum block, which concatenates every platform's file. The zip's smoke+ test now requires LF rather than tolerating either, so the format the+ release claims is the format it ships. (#838)++ ## [2.4.0] - 2026-09-21+### Security- Bumped `rmcp` to 2.x (2.2.0), resolving three MCP transport advisories:GHSA-9pj6-vhgr-3mwh (unauthenticated Streamable-HTTP session-table leak /diff --cc README.mdindex ff7d0da0,7805a6bd..9e4503a1--- a/README.md+++ b/README.md@@@ -259,11 -313,9 +313,12 @@@ wrapper automatically uses Podman whenOn Linux/macOS, that's it. Start a Claude Code session as usual - everyprompt and tool call now lands in ai-memory, and the next session youopen in this project will see a handoff with where you left off.- On macOS, the native release binary is also supported and recommended when you- do not need Docker; see [`docs/macos.md`](docs/macos.md). Later updates for that+ On macOS the native binary is the recommended path when you do not need+ Docker — either the [menu bar app](#macos-menu-bar-app) above or a-[release tarball / launchd agent](docs/macos.md).++[release tarball / launchd agent](docs/macos.md). Later updates for that+path use `ai-memory upgrade` (checksum-verified GitHub release replace + hook+refresh) — see+[`docs/install.md#keeping-ai-memory-up-to-date`](docs/install.md#keeping-ai-memory-up-to-date).Wiring another agent is the same two commands with a different name —`--client codex`, `--agent codex`, and so on for every row of the supportdiff --cc crates/ai-memory-cli/src/config.rsindex 3b378e36,1e3eae2e..a074c938--- a/crates/ai-memory-cli/src/config.rs+++ b/crates/ai-memory-cli/src/config.rs@@@ -159,15 -255,16 +255,23 @@@ pub struct Configpub data_dir: PathBuf,/// HTTP bind address used by `ai-memory serve`.pub bind: String,+ /// Idle-time (seconds) before the OS starts probing an accepted `serve`+ /// connection with TCP keepalive. `0` disables keepalive entirely. A+ /// hook client's peer can die without sending FIN (laptop sleep, a+ /// VPN/Tailscale flap, an abrupt kill); without keepalive the socket+ /// stays `ESTABLISHED` forever and leaks one fd per dead peer until+ /// `accept()` fails with `EMFILE` and the healthcheck breaks (#792). Set+ /// with `AI_MEMORY_TCP_KEEPALIVE_SECS`.+ pub tcp_keepalive_secs: u64,/// Base URL used by thin-client CLI commands to contact the running server.pub server_url: String,+ /// Optional override for the GitHub Releases base URL used by+ /// `ai-memory upgrade` (archive + `.sha256` download). Empty/unset+ /// means `https://github.com/akitaonrails/ai-memory/releases`. Set via+ /// `AI_MEMORY_RELEASE_BASE_URL` or `release_base_url` in config.toml —+ /// intended for hermetic tests and mirrors, not day-to-day installs.+ #[serde(default)]+ pub release_base_url: Option<String>,/// URL subpath the server is mounted under (e.g. `/wiki`). Thin-client/// CLI commands prepend it to every `/admin/*` request so deployments/// hosted behind a reverse proxy under a subpath don't 404. Settable via@@@ -747,8 -849,8 +856,9 @@@ impl Default for ConfigSelf {data_dir: default_data_dir(),bind: DEFAULT_BIND.into(),+ tcp_keepalive_secs: DEFAULT_TCP_KEEPALIVE_SECS,server_url: DEFAULT_SERVER_URL.into(),+ release_base_url: None,base_path: String::new(),home_dir: None,log_level: "info".into(),