Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge PR #660: skip OKF-conformed event ledgers in the wiki indexer
AkitaOnRails92495c5f12a2
diff --cc CHANGELOG.mdindex 5f67f74a,d5d9d3e9..2cc5dccb--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -7,108 -7,7 +7,121 @@@ and this project adheres to [Semantic V## [Unreleased]++### Fixed++- OKF-conformed event ledgers are skipped by the indexer again, so a migrated++ store stops growing without bound. The reserved-file check treated any++ `log.md` / `log-YYYY-MM.md` carrying YAML frontmatter as an ordinary page,++ but the OKF v0.2 migration stamps frontmatter on every `.md` under `wiki/`,++ ledgers included. A migrated store therefore indexed its ledgers, and each++ hook `append_event` superseded them: one `pages` row per appended line,++ holding the whole multi-megabyte ledger body. One affected store reached++ 6,539 page versions and 14 GB from 101 live pages within four days of++ migrating. The check now reads past the frontmatter fence and classifies on++ the first body line, so a real page that happens to be named `log.md` is++ still indexed. (#660)+++## [2.1.0] - 2026-09-06++### 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+- 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])+- 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