Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge main into release/2.1: pick up the #654/#658/#655 fix batch
AkitaOnRailscdd209785a06
diff --cc CHANGELOG.mdindex 00a0f277,8783abee..66d2e459--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -7,84 -7,14 +7,91 @@@ and this project adheres to [Semantic V## [Unreleased]+### Added+- Ordered LLM provider fallback chains (#648). `[[llm_fallbacks]]` in+ `config.toml` configures one or more additional providers, each with its+ own `provider`, `model`, optional `base_url`, and optional `api_key_env`+ (the environment-variable *name* holding that profile's key — never the+ key itself in config). The primary provider (`llm_provider`) always runs+ first; fallbacks run only after a transient failure+ (`LlmError::is_transient()`: 429, 5xx, timeout, connection error) advances+ past the current candidate, in declaration order, with the original+ request, JSON schema, and logical operation id preserved on every+ attempt. A deterministic failure (400/401/403/404/422, an unsupported+ schema, or a malformed response) still stops immediately — the same+ policy a single provider already had. Each candidate carries a 30s+ in-memory circuit: a transient failure opens it, a success closes it,+ and a restart clears all circuit state. `Config::load` validates every+ profile and resolves its credential once, at startup — a missing/empty+ provider or model, an unknown provider, or a `RequiredApiKey` provider+ with no resolved `api_key_env` fails startup rather than leaving a+ latent fallback that only fails once the primary is already down; a+ provider with a native credential source (OpenAI OAuth, Copilot) needs+ no `api_key_env`. `GET /admin/status` (and `ai-memory status`) now+ reports each candidate's provider/model label, last-selected/last+ success/error state, and circuit-open-until timestamp alongside the+ existing top-level LLM provider/model fields, which are unchanged for+ every existing single-provider deployment.+- `bootstrap --resume` recovers an interrupted run from durable per-chunk+ progress instead of re-paying for every LLM call (#621). Each chunk's pages+ are recorded (keyed by a fingerprint of the pruned sources + chunk budget, so+ a re-run after new commits re-chunks and starts fresh) and `--resume` seeds+ them and skips those chunks; the wiki write stays atomic (nothing lands until+ the whole run completes) and progress is cleared on success. It adopts only+ the **contiguous** prefix of completed chunks and re-runs from the first gap+ or unreadable row (#635), so a resumed run can never diverge from a clean one+ by seeding a later chunk with context an earlier, still-missing chunk never+ produced. Complements the transient-retry from 2.0.3 (#617): retry reduces+ how often you need resume; resume covers the crash / restart case.+- Added first-party OpenCode 2.0 beta (`opencode2`) support.+ `install-mcp --client opencode2` merges the V2 `mcp.servers` remote entry+ (no `enabled` field, `oauth: false` for header credentials);+ `install-hooks --agent opencode2` writes an `ai-memory-opencode2.ts`+ plugin in the beta `{ id, setup }` shape (no runtime dependency:+ `Plugin.define` is identity), with handoff injection through the+ `context` hook and the same `session.*` lifecycle coverage as v1;+ `ai-memory run opencode2` launches through the `opencode2` binary and+ imports the beta `session_v2`/`session_message` transcript. The beta+ shares v1's config dir, session store, and agent kind, so no store+ migration ships. Verified live against beta-18999 (hook capture,+ handoff loop, managed launch/resume/import, `opencode↔opencode2`+ session resume). Two beta caveats are documented: back up+ `~/.local/share/opencode` first (the beta has migrated the shared+ database in place before), and move its background service off port+ 49374 when ai-memory serves there. Managed ledger-delta+ acknowledgement does not fire through the shared background service+ (redelivery, never loss); see the managed-workstreams notes (#622).+- `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+ - The session-start brief's `[briefing] max_chars` now bounds the whole+ rendered brief, and its floor rose from 500 to 1500 chars. The scaffold the+ brief may never drop — the security notice plus both untrusted-history+ markers and the closing instruction — costs 832 chars by itself, so any+ budget under that could only ever have been honoured by dropping the+ boundary that marks the brief as untrusted. A project whose marker sets a+ smaller `max_chars` now gets 1500. (#657)- The build is self-contained on every platform: the vendored web stylesheetis now the default and `TAILWIND_BUILD=1 cargo build -p ai-memory-web`regenerates it, so no command needs `TAILWIND_SKIP=1` any more. CI