Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge branch 'main' into release/2.5
AkitaOnRails98d0a9e4835b
diff --cc CHANGELOG.mdindex 653feca1,e31c1be8..765e46b7--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -8,102 -8,66 +8,153 @@@ and this project adheres to [Semantic V## [Unreleased]### Added+- `ai-memory run` accepts a repeatable `--env KEY=VALUE` and an `--env-file+ <path>` (blank lines and `#` comments skipped) to pass extra environment+ into the spawned harness — e.g. a per-account `CLAUDE_CONFIG_DIR` for+ callers who previously had to wrap the launch in `env KEY=VAL harness`.+ Both flags are wrapper-owned like `--yolo`/`--executable` and must precede+ the harness name; a `--env` entry overrides a same-key `--env-file` line.+ The resolved environment reaches both the spawned process and ai-memory's+ own native-session resolution, so the two agree on where a+ `CLAUDE_CONFIG_DIR`-style override points the session store. See+ `docs/managed-workstreams.md`. (#820)+- `contradiction_band_min` / `contradiction_band_max` config keys (env:+ `AI_MEMORY_CONTRADICTION_BAND_MIN` / `AI_MEMORY_CONTRADICTION_BAND_MAX`)+ make `memory_lint`'s A5 zero-LLM contradiction-detection cosine-similarity+ band configurable, defaulting to the historical fixed `0.4`–`0.75`. The+ band is a fixed absolute cosine value, but background similarity is+ corpus-dependent: on a single-language or single-domain store, unrelated+ pages already sit above the general-purpose floor, so the default band+ measures domain proximity more than conflict and produces noisy findings.+ Raising `contradiction_band_min` trims that noise. Rejected at config load+ unless `0.0 <= contradiction_band_min < contradiction_band_max <= 1.0` and+ both are finite. (#853)+- Fedora users can install prebuilt x86_64 and aarch64 RPMs from GitHub+ Releases, with the existing native systemd service assets. (#858)+- `embedding_query_prefix` / `embedding_document_prefix` config keys (env:+ `AI_MEMORY_EMBEDDING_QUERY_PREFIX` / `AI_MEMORY_EMBEDDING_DOCUMENT_PREFIX`)+ for the `openai` and `openai-compat` embedders: an optional string+ prepended to query / document text before the existing truncation, so+ truncation still bounds the whole input. Asymmetric embedding models need+ a query-side instruction their publisher specifies; the OpenAI-compatible+ `/v1/embeddings` wire format has no field for it.+ `nvidia/Nemotron-3-Embed-1B-BF16` and base E5 models use a simple+ `"query: "` / `"passage: "` pair; instruction-tuned E5 variants and+ Qwen3-Embedding instead need a task-instruction string on the query side+ only (documents stay plain). Empty by default — no behaviour change when+ unset, and not trimmed (nor is a present-but-empty env-var override, which+ now clears a `config.toml` value), so a publisher's trailing space is+ preserved. A non-empty `embedding_document_prefix` is folded into the+ stored embedding identity (`Embedder::model_identity`), so a document+ prefix change makes retrieval, backfill, and cleanup treat existing pages+ as stale and re-embed them automatically — an empty prefix keeps the+ pre-existing identity, so upgrading installs need no migration, and a+ query-only prefix change never needs a rebuild. See+ `docs/llm-providers.md`. (#859)+- `auto_improve.patchable_page_prefixes` makes the folders whose page bodies the+ reviewer reads configurable, defaulting to the historical `_rules/` and+ `procedures/`. Only those two folders' contents were ever sent; every other+ page reached the model as a single title line, so a project keeping its+ durable knowledge in `decisions/` or `gotchas/` — with no `_rules/` pages at+ all — sent no page bodies, and the reviewer re-proposed invariants that were+ already written down, at high confidence, indefinitely. Existing configs are+ unchanged. (#834)+- `ai-memory finalize-session --reopen --session-id <uuid>` re-finalizes a+ session that already ended, for agents without a true session-end event+ (Antigravity CLI, Kiro, ZCode, Pool) whose conversation continued after a+ first manual finalize: the discovery step now accepts `include_ended=true`+ on `GET /admin/open-sessions` for an exact session id (rejected without+ one, so reopening stays exact-id-only and never a bulk operation), and the+ server's normal session-end path re-runs over the new observations+ (updated summary page via supersession, new handoff, opt-in+ consolidation). Re-running with nothing new since the first end remains a+ harmless no-op. The default finalize behavior is unchanged: ended sessions+ stay invisible unless `--reopen` is passed. (#836)+- Added per-execution `AI_MEMORY_CAPTURE_OWNER` context for external lifecycle+ producers. Updated native hooks, script bundles and generated integrations+ suppress capture while preserving supported handoff delivery and MCP recall.+ Documented producer provenance and stable retries through the existing hook+ ingestion API, without changing its schema or standalone defaults. (#821)+- Builtin `/web` login and change-password pages for human password sessions:+ unauthenticated browser GETs to the wiki redirect to `{web_slug}/login`+ (not bare JSON 401), forms call existing `POST /auth/login` /+ `/auth/password` / `/auth/logout`, and `--web-ui-dir` custom SPAs stay+ unchanged. (#811)+ - `docs/jev-reranker-adapter.md` documents a stdlib-only adapter+ (`docs/examples/jev-reranker-adapter/jev_rerank_shim.py`) that serves the+ `AI_MEMORY_RERANKER=llm` request leg from a Jev `/v1/systemone` judge+ endpoint while reverse-proxying consolidation/lint/bootstrap traffic to+ the configured provider unchanged. In the contributor's own 102-query+ golden-set benchmark the judge matched the hosted reranker's+ hit@1/MRR/NDCG@10 (0.778/0.838/0.873 vs 0.778/0.840/0.875) at 0.205 s+ mean latency instead of 20.2 s — in that run the hosted mean sat on the+ server's 20 s completion timeout, which made the reranker stall every+ query before falling back. (#873)+### Changed+- Grok Build CLI shows a pending handoff, and an opted-in `[briefing]`, as+ `PostToolUse` `additionalContext` on the first tool of a session.+ `SessionStart` and `UserPromptSubmit` still do not accept the handoff (Grok+ discards that stdout); a session that never calls a tool leaves the handoff+ open for `memory_handoff_accept`. The note is clipped to 10,000 characters+ (Grok's own cap). Because Grok reuses one session id across a+ SessionEnd→restart, `memory_handoff_accept` now reopens an already-ended+ receiver session (clears `ended_at`) instead of rejecting it — but only for+ agents that reuse their session id across a restart (Grok); for every other+ agent an ended session stays final, so a lifecycle-only receiver still cannot+ reclaim after it released and ended. The reopen also only happens after the+ exactly-once claim guard, so a session that already took a baton still cannot+ take another (the multi-session claim-once invariant is preserved).+ Delivery of this PostToolUse handoff is exempt from `AI_MEMORY_CAPTURE_OWNER`+ capture suppression, like the other context-delivery events. (#840)+### Fixed+- `memory_query`'s vector stream called the generic `Embedder::embed`+ instead of `embed_query` on the configured embedder, so a+ query/document-asymmetric embedder (Google's task-typed embeddings, or+ the new query/document prefixes above) embedded the search query on the- document side instead of the query side. (#859)++ document side instead of the query side. Indexed writes are unchanged;++ only the query-side helper moves onto the query task. (#859, #861)+ - The Linux/macOS Docker wrapper now keeps its native host client in+ `${XDG_DATA_HOME:-~/.local/share}/ai-memory/native-runner` instead of+ `~/.cache/ai-memory/native-runner`. `ai-memory run` auto-wires hooks whose+ command is that client's path (Claude Code, Codex, Kimi Code, Command Code,+ Kiro CLI v3, Grok, Antigravity CLI), so flushing `~/.cache` left every hook of+ those harnesses pointing at a missing binary. The wrapper also keeps the+ release's `hooks/` bundle beside the client, so auto-wire no longer fails+ with "could not locate hooks directory" for script-based harnesses on a host+ where `install-hooks` never ran. (#874)+ - Fixed pre-push installation from linked worktrees and preserved the managed+ block's position during reinstallation. Configured `core.hooksPath` overrides+ and ambiguous markers are rejected without replacing the existing hook. The+ block now keeps its shell options and `SSL_CERT_FILE` inside its subshell and+ propagates a failure explicitly, so user hook commands after it keep their+ own semantics and a failing test run still blocks the push. (#824)+ - Isolated the pre-push test process from Git's repository environment and+ global/system configuration so fixture commands use their own repositories.+ Existing installations need to run `scripts/install-git-hooks.sh` again. (#824)-- `memory_query` now embeds the search text with `embed_query` rather than- the generic `embed()` method. Google's embedder implements `embed()` as- `embed_document` (`RETRIEVAL_DOCUMENT`), the same task type used when- indexing wiki pages, so hybrid search compared a document vector to- document vectors and the vector stream could not separate query from- passage. Indexed writes are unchanged; only the query-side helper moves- onto `RETRIEVAL_QUERY`. Symmetric embedders (OpenAI, Voyage, local) keep- the same vector they already returned from `embed()`. (#861)+ - A Windows service running as `LocalSystem` over a user-owned data+ directory no longer breaks the wiki git history silently. libgit2's+ dubious-ownership guard (CVE-2022-24765) fails every wiki commit with+ `code=Owner` when the process account does not own the repository, but+ the failure was WARN-only, so capture and search kept working while no+ wiki checkpoint was ever committed. The startup baseline checkpoint now+ surfaces an owner-check failure at ERROR with the remedy (run the+ service as the owning user), and `docs/windows.md` Scenario E documents+ running the service under a `<serviceaccount>`, corrects the claim that+ only the data directory is account-sensitive, and notes the WinSW+ error-1069 / stale-password gotcha for Microsoft-account / PIN / Hello+ users. The owner check itself is deliberately left enabled. (#872)+ - A Windows folder no longer splits into two projects. The hook router+ derived a project's *name* from the cwd after+ `normalize_project_path_key` had ASCII-lowercased the whole+ drive-letter/UNC path — basename included — so a session in+ `D:\...\Default Project` was captured under `default project` while the+ CLI (which keeps the raw basename) used `Default Project`. Because+ `get_or_create_project` matches names case-sensitively, one folder+ minted two projects. The router now takes the name from the raw cwd; the+ cache key and cwd-prefix match keep the case-folded path, so #806 handoff+ stickiness is unaffected. (#871)- Auto-improve review no longer stages a proposal whose LLM-produced pagepath contains a Windows-illegal character (e.g. a `:` copied from aconventional-commit subject). That path passed the deliberately tolerantdiff --cc crates/ai-memory-cli/src/commands/serve.rsindex 46c4184b,d89c8d0e..d73ffa5f--- a/crates/ai-memory-cli/src/commands/serve.rs+++ b/crates/ai-memory-cli/src/commands/serve.rs@@@ -26,11 -26,8 +26,11 @@@ use ai_memory_mcp::use ai_memory_store::{ReaderPool, Store, TokenPepper, WriterHandle, hash_session_secret, hash_token,};-use ai_memory_web::{WebMountSpec, normalize_prefix, split_web_routers, web_base_href};+use ai_memory_web::{+ HtmlAuthRedirectConfig, WebMountSpec, html_auth_redirect_mw, normalize_prefix,+ split_web_routers, web_base_href,+};- use ai_memory_wiki::{WatcherHandle, Wiki, migrations, run_wiki_migrations};+ use ai_memory_wiki::{WatcherHandle, Wiki, WikiError, WikiResult, migrations, run_wiki_migrations};use anyhow::{Context, Result};use axum::body::Body;use axum::extract::{DefaultBodyLimit, State};