Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge PR #738: --flavor pins the schema dialect for any client (#735)
AkitaOnRails294b733e878b
diff --cc CHANGELOG.mdindex e5614fdb,85c23588..7a2ad2d3--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -8,102 -8,18 +8,114 @@@ and this project adheres to [Semantic V## [Unreleased]### Added+- Cross-project agent messaging: a directed, claim-once inbox/queue so an agent+ in one project can hand a self-contained request to an agent in another+ project without pulling that project's context into its own session. Four new+ MCP tools (`memory_message_send` / `memory_message_list` / `memory_message_pop`+ / `memory_message_cancel`, bringing the surface to 23) plus `ai-memory message+ send|list|pop|cancel` CLI subcommands and `/admin/messages*` routes, backed by+ the new `agent_messages` table (migration V64). Messages are addressed to a+ project (any session there can pop; claim-once); the sender can retract a+ pending message; an unknown recipient fails closed; each inbox is depth-capped.+ A popped message is treated as untrusted cross-project input — secret-scrubbed+ and size-capped on send, fenced with a security notice and sender provenance on+ pop, and never auto-injected into context. See `docs/agent-messaging.md`.+- The session-start "hot context" block now appends a non-consuming inbox notice+ (a static count only — never message text) when a project has pending+ cross-project mail, and `memory_briefing` reports `pending_message_count`.+- Added an independent `codex` LLM provider that follows the Codex CLI account+ selected by `CODEX_HOME`, reloads its read-only `auth.json` credentials before+ each operation, and delegates expired-token recovery to+ `codex app-server --stdio` (#716).+ - `install-mcp --flavor <moonshot|bedrock|gemini>` pins the tool-schema dialect+ in the URL written into a client's config. The installer already picks one for+ the clients whose upstream is fixed — Kimi Code is always Moonshot, Kiro always+ Bedrock — but a client that fronts several models cannot be pinned by its name+ alone, and there was no installer path to `?flavor=gemini` for any of them. A+ Command Code or OpenCode install routed to Vertex needed the marker added by+ hand or every model call 400'd at `tools/list`; the same client on a non-Google+ model does not, which is why this is an explicit choice rather than another+ per-client default. `vertex` is accepted as an alias. `uninstall` now matches+ every marker on every client, so an entry pinned this way is still removed+ (#735).+### Security+- Updated `rustls` 0.23.40 → 0.23.45 for [RUSTSEC-2026-0285](https://rustsec.org/advisories/RUSTSEC-2026-0285),+ in which a TLS 1.3 handshake message that follows a key-changing message in+ the same record can be accepted at the wrong encryption level. `rustls` is a+ direct dependency — it installs the process-wide crypto provider the MCP+ bridge needs for HTTPS — and is also the TLS implementation every outbound+ HTTPS call resolves to through reqwest, so the advisory failed `cargo audit`+ and `cargo deny check` on every open pull request that inherited `main`'s+ lockfile, including ones that change no Rust at all. `Cargo.toml` already+ allows compatible 0.23 patch releases, so this is a lockfile-only change+ needing no manifest or public-surface edit; the same resolution moves+ `rustls-webpki` 0.103.13 → 0.103.15 and nothing else (#731).++### Fixed+- The native `ai-memory hook` session-id state file+ (`<data_dir>/hook-state/<agent>-session-id`), introduced for Devin in #178,+ now also covers ZCode. ZCode's hook payloads do not reliably carry a session+ id, it fires `Stop` at the end of every turn, and it has no `SessionEnd`+ event — without a persisted id, each turn with an id-less payload opened a+ fresh server-side session that nothing ever closed (observed in production:+ 4 sessions with NULL `ended_at` and 398 observations stuck in episodic).+ ZCode events without a native id now share one stable stored id per agent+ session; events carrying a native id are passed through untouched. The stored+ id is cleared by `finalize-session --agent zcode` (which now also removes the+ state file) or overwritten by the next `session-start`; `Stop` never clears+ it. Other agents are unaffected: payloads that carry a session id short-circuit+ the state file exactly as before.+- `memory_feedback`'s `signal` (FeedbackKind) JSON schema now declares a+ top-level `type: "string"`, so strict function-calling gateways (Moonshot/Kimi+ and other schema validators) accept the `tools/list` surface instead of+ rejecting the enum for a missing type (#735, #741).+- Cursor lifecycle events are no longer stored twice on a host where both+ `install-hooks --agent cursor` and `install-hooks --agent claude-code` are+ applied. Cursor also runs the commands in Claude Code's settings, and since+ 2.1.0 that copy is re-attributed to `cursor` by its `cursor_version`, so it+ landed in the same session as the native event. The `--agent claude-code`+ hook now drops a Cursor-marked payload when `~/.cursor/hooks.json` already+ registers an ai-memory `--agent cursor` hook; without Cursor's own hooks the+ Claude Code path keeps capturing Cursor sessions as before (#721).+- `install-hooks --agent cursor --apply` now warns about existing+ `~/.cursor/hooks.json` entries that mention ai-memory but are not ai-memory+ hook entries, such as a pre-2.1.0 shim that injected `cwd`. Those entries+ are kept beside the native ones, so every event would otherwise be captured+ twice without any sign (#721).+- The POSIX shell hook bundle's spool reader no longer builds the decoded value+ in memory. `ai_memory_json_field` appended to a string that grows to the whole+ value, so reading a multi-megabyte entry — one large tool result is enough —+ took minutes of CPU, and a drain pass reads every entry three times (`url`,+ `body`, `token`) while one detached pass starts behind every delivery that+ succeeds. Once an outage had filled the spool, the passes accumulated faster+ than they retired and saturated the machine. The value is now bounded by a+ single regex pass over the JSON string grammar, unescaped with `gsub` over+ whole segments and written straight to stdout, for identical output and exit+ codes. A 2.2 MB entry of `grep` output — the shape that caused the incident,+ where every literal backslash is an escaped pair — goes from 732 s to 5.5 s+ under the awk macOS ships and from 9-10 s to about 1 s under mawk and gawk+ (#727).+- The POSIX shell hook bundle now assigns an `ingest_key` before its initial+ delivery and preserves that key when spooling the event, preventing a replay+ from creating a duplicate observation when the server committed the first+ request but its response was lost (#729).+- `install-hooks` reapply is idempotent again on Windows for agents whose+ native command uses an underscore executable name (`ai_memory`): the hook+ ownership predicate recognized only the hyphenated `ai-memory`, so a reapply+ reported `Updated` and failed to dedup its own prior Antigravity/Cursor/Kimi+ Code entries. It now matches both forms while still requiring the full+ `hook --event … --agent … --server-url …` argv signature (#740).+- The POSIX shell hook bundle's `ai_memory_json_string` now escapes every JSON+ control character (U+0000–U+001F) as `\u00XX`, not just backslash, quote, tab+ and CR. A replayed tool result carrying an ANSI colour escape (0x1b) reached+ stdout bare, so the managed-workstream SessionStart packet — and any handoff+ whose summary held a control byte — was rejected as invalid JSON and the+ resuming session started with no context. The escaping is linear and reuses+ the same BusyBox replacement-doubling probe as the four existing escapes+ (#732).++||||||| 74d2d31e+## [2.2.1] - 2026-09-12### Fixed