Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge main into release/2.1: 2.0.3 batch (#623,#624,#625,#626,#627,#628)
AkitaOnRails8f5abb00a4f0
diff --cc CHANGELOG.mdindex d850a37d,158469ae..ae9779aa--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -7,51 -7,46 +7,88 @@@ and this project adheres to [Semantic V## [Unreleased]+### Added+- `install-hooks --agent codex` now wires Codex's `SessionEnd` hook, so a+ finished Codex session gets the same automatic end-of-session summary+ and cross-agent handoff Claude Code already gets. Codex shipped a+ first-class `SessionEnd` event in Codex CLI 0.145.0 (openai/codex#33895);+ the `hooks/codex/session-end.{sh,ps1}` scripts already existed and only+ needed adding to the Codex hook profile. On older Codex the event key is+ inert; `ai-memory finalize-session --agent codex` remains the fallback.+ `merge_codex_payload` no longer strips a `SessionEnd` key on every apply+ — a third-party `SessionEnd` hook is preserved alongside ours. ([#604])+- `AI_MEMORY_LLM_HEADERS` (`llm_headers` in `config.toml`) attaches extra+ HTTP headers to every LLM chat request, for gateways that require a+ caller-identifying header. Entries are `Name=Value` or `Name: Value`,+ comma separated in the env var. Parsed and validated once at the+ configuration boundary, so a malformed entry fails at startup rather than+ on the first consolidation pass, and providers consume typed header+ material instead of operator strings. Headers ai-memory sets itself+ (`authorization`, `content-type`, `x-api-key`, `x-goog-api-key`,+ `anthropic-version`, `anthropic-beta`, `openai-beta`, `host`,+ `content-length`) are refused: `reqwest` appends rather than replaces, so a+ duplicate would break the request instead of overriding it. Values are+ marked sensitive on the wire and never logged — the `Debug` output carries+ header names only. ([#606])+### Changed+- Every LLM chat request now sends `User-Agent: ai-memory/<version>`.+ `reqwest` sends no user agent unless one is configured, so provider+ requests previously arrived anonymous, and gateways that require callers to+ identify themselves reported ai-memory as an unknown client. An+ `AI_MEMORY_LLM_HEADERS` entry for `user-agent` overrides it. The Copilot+ provider is unchanged: it keeps `GitHubCopilotChat/<version>`, the+ editor-plugin agent GitHub's Copilot API expects. ([#606])+- `x-opencode-session` and the `opencode` user agent, both shipped in 2.0.2,+ are now operator-overridable like any other header: an+ `AI_MEMORY_LLM_HEADERS` entry for either name takes precedence over the+ provider's default. The default remains 2.0.2's — one `LlmOperationId` per+ logical operation, stable across retries and the strict/tolerant fallback —+ so nothing changes unless an operator asks for it. Override the session+ header to tell several ai-memory instances apart in OpenCode's metrics.+ ([#606])+ - Release, Docker, and the `cargo install --git` snippet now build with+ `--locked` (#628). Without it `cargo install` re-resolves dependencies and+ ignores the committed `Cargo.lock`, so a source install could silently pull+ a different `schemars` than the one tested — a plausible source of+ build-to-build structured-output schema drift. A unit guard also asserts the+ strict-schema normalizer keeps `required` equal to `properties` (and closes+ open maps), catching that drift class at build time rather than in+ production.+ - The `_pending/auto-improve/` sidecar no longer renders a `status:` line+ (#624). It was written once at staging and could never change from+ `pending` — no code path updates or garbage-collects the sidecar — so it+ contradicted design principle 14 (SQLite owns approval status) and misled a+ human (or a second agent) reading the file. Status lives in+ `ai-memory pending-writes list` / SQLite; the sidecar is a staging-time+ snapshot.### Fixed+- The OpenCode provider now sends `gpt-5.6-luna` requests to OpenCode Go's+ Responses endpoint. Luna is not served through Chat Completions, where plain+ and structured ai-memory calls returned HTTP 500 (#618).+ - `finalize-session --agent hermes` (and `claude-desktop`, `crush`, `other`)+ is accepted again (#623). These agents are captured and stored, but+ `finalize-session` reused the install-oriented agent enum — which is+ deliberately limited to agents with a first-party installer — so it rejected+ them at parse time and their sessions could never be closed, summarised, or+ consolidated. `finalize-session` is agent-agnostic, so `--agent` now accepts+ any agent the store recognises (a genuine typo is still rejected);+ `install-hooks`/`setup-agent` stay limited. A drift guard keeps the two sets+ from diverging again.+ - generated TypeScript integrations (`--agent open-code`, `omp`, `pi`,+ `openclaw`) authenticate again under `install-hooks --apply`. Since #552+ the bearer is deliberately omitted from the rendered file and persisted to+ the 0600 `<data_dir>/auth-token` file, but only the native hook runtimes+ learned to read it back: the generated TS adapters kept rendering+ `TOKEN = null` with no runtime resolution, so every request they make+ (hook capture, spool drain, handoff fetch) goes out unauthenticated and is+ rejected by a Bearer-enabled server. The templates now render a+ `resolveToken()` helper (static embed, then `AI_MEMORY_AUTH_TOKEN`, then+ the auth-token file) used by `authHeaders()` and the spool writer.+ `fetchHandoff()` in the same adapters also ignored `response.ok`, so a+ 401 error body could be injected into model context as if it were a+ handoff; non-OK responses now return `undefined` like other failures.- `bootstrap` now retries a chunk's LLM call on a transient error beforegiving up, instead of letting one blip discard the whole multi-chunk run(#617). A provider `5xx`/`429` or a transport timeout/connect failure ondiff --cc docs/support-matrix.mdindex d88af38c,c1bb4fac..104d6544--- a/docs/support-matrix.md+++ b/docs/support-matrix.md@@@ -11,7 -11,7 +11,7 @@@| Windows via WSL2 | Supported | Use the Linux install path inside WSL2 when the agent runs there. || Native Windows | Experimental | Tagged releases publish `ai-memory-windows-x86_64.zip` with `ai-memory.exe`; Docker Desktop wrapper and source builds are also available. Local supported profiles default to host-native hook commands; Claude Code may use its Windows exec form, while other agents use native single command strings matching their hook schema. PowerShell/Git Bash scripts are compatibility fallbacks. See [`docs/windows.md`](docs/windows.md). || Claude Code | Supported | MCP config + lifecycle hooks; native commands enforce capture exclusions. `install-mcp --session-aware` optionally enables per-session auto-scope isolation through a local stdio bridge. Optionally captures the assistant's final turn on `Stop` when installed with `--capture-assistant` and the server enables `capture_assistant` (double opt-in, off by default). |- | Codex | Supported | MCP config + lifecycle hooks; native commands enforce capture exclusions. `SessionEnd` is wired since Codex CLI 0.145.0 (openai/codex#33895), so finished sessions get an automatic end-of-session summary/handoff; on older Codex the event is inert and `ai-memory finalize-session --agent codex` is the fallback. |-| Codex | Supported | MCP config + lifecycle hooks; native commands enforce capture exclusions. No automatic true session-end hook, so run `ai-memory finalize-session` when you need a final summary/handoff. Assistant-final-turn capture (`--capture-assistant`) is Claude Code + native-platform only and is refused for Codex — see `install.md`. |++| Codex | Supported | MCP config + lifecycle hooks; native commands enforce capture exclusions. `SessionEnd` is wired since Codex CLI 0.145.0 (openai/codex#33895), so finished sessions get an automatic end-of-session summary/handoff; on older Codex the event is inert and `ai-memory finalize-session --agent codex` is the fallback. Assistant-final-turn capture (`--capture-assistant`) is Claude Code + native-platform only and is refused for Codex — see `install.md`. || Command Code | Supported | MCP config (`~/.commandcode/mcp.json`) + its four stable lifecycle-hook events (`~/.commandcode/settings.json`); native commands enforce capture exclusions and `SessionStart` injects handoffs. `Stop` is only a turn boundary, so use `ai-memory finalize-session --agent command-code` after the final turn. `ai-memory run command-code` adds exact v3 native-session resume and visible-event import; experimental unsandboxed Mods remain excluded. || Devin CLI | Supported | MCP config + lifecycle hooks. Hooks use Devin's `PostCompaction` event, inject handoffs via `hookSpecificOutput.additionalContext`, and omit subagent events because Devin does not expose them. || OpenCode | Supported | Remote MCP config + generated TypeScript plugin; generated plugin enforces capture exclusions. |