Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge remote-tracking branch 'upstream/main' into feature/kimi-window-order
Lucas Oliveirac9eb264496fd
diff --cc CHANGELOG.mdindex b697f54d,ba7b17fc..a4af606d--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -7,51 -7,40 +7,84 @@@ and this project adheres to [Semantic V## [Unreleased]+### Added+- `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.++### 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.+- The `opencode` provider now sends `x-opencode-session` on every request,+ defaulting to one id per process when `AI_MEMORY_LLM_HEADERS` does not+ supply one. OpenCode's Go documentation covers third-party access to its+ endpoints and asks callers to identify themselves; both Go and Zen+ correlate requests by that header, and traffic without it is reported as+ unattributable.+ Set the header explicitly to keep the value stable across restarts or to+ tell several ai-memory instances apart.+### Fixed+ - `install-hooks --agent zcode --apply` now removes stale ai-memory+ hooks left under event keys this version no longer manages (e.g. a+ legacy `SessionEnd`), instead of reporting "already up to date" while+ a broken/orphaned entry lingered (#600). The dry-run printed snippet+ also now states plainly that `--apply` persists the auth token to+ `<data-dir>/auth-token` (0600) and writes token-less args, so the+ applied config differs from the embedded-token snippet by design.+ - Local-embedding model download (`fetch_model`) now bounds a stalled+ connection instead of hanging startup forever (#602): a 30s connect+ timeout and a generous 600s overall ceiling (large model files, so+ not the inference clients' flat 120s that would fail a slow download).+ - The OKF v0.2 migration no longer crash-loops on startup with a+ libgit2 `invalid object specified … class=Tree` error that left the+ server unable to boot (#594). The wiki commit re-hashed files through+ libgit2's index, whose stat cache could trust a cached blob OID absent+ from the object database (a store carried across libgit2/git versions,+ or an interrupted earlier operation) — `write_tree` then aborted and,+ because the migration commits through that path, every restart failed.+ The commit now clears the index before staging so every file is+ re-hashed from the working tree. (The Docker runtime ships no `git`,+ so the fix is in-library, not a CLI fallback.)+ - HTTP headers that carry a credential in an opaque value are now redacted+ before reaching durable storage. Previously such a header matched no+ built-in pattern unless it used the `Bearer` keyword or an+ `UPPER_SNAKE_TOKEN=` shape. The bearer rule requires the literal keyword,+ and the generic env-var rule requires `[A-Z][A-Z0-9_]*_TOKEN`, which never+ matches a kebab-case header name. `X-Amz-Security-Token` (AWS SigV4),+ `X-Api-Key`, `Private-Token` (GitLab), and `Ocp-Apim-Subscription-Key`+ (Azure) all fall in that gap, and tool output echoing a `curl` invocation+ is a common way they reach capture. A `key` or `token` suffix on its own+ does not imply a secret, so it must be qualified by an auth word:+ `Idempotency-Key`, `Continuation-Token` and storage partition keys are+ left intact and stay readable in captured output.+- `AI_MEMORY_LLM_BASE_URL` now works with `AI_MEMORY_LLM_PROVIDER=opencode`.+ The provider hardcoded OpenCode's **Go** endpoint and the factory dropped+ the configured base URL without a word, so Zen's general catalogue at+ `https://opencode.ai/zen/v1` was unreachable through it — Zen and Go are+ separate products, not two spellings of one. Go remains the default, so+ existing setups are unaffected; an override keeps the `x-opencode-session`+ default and the user agent, since both endpoints correlate requests the+ same way. Model ids are per catalogue, so set `AI_MEMORY_LLM_MODEL`+ explicitly when overriding. `OPENCODE_ZEN_BASE_URL` is deprecated in+ favour of `OPENCODE_GO_BASE_URL`: the constant named Zen but has always+ held Go's URL. It keeps its value, so code compiled against it is+ unaffected.- `as_of` time-travel queries and the entity retrieval stream now workon real stores. Both read the entity index, which was populated onlyfrom an LLM consolidator's `entities:` frontmatter — absent on the