Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge remote-tracking branch 'upstream/release/2.5' into feat/external-lifecycle-companion
Éverton Toffanettoc203ae662747
diff --cc .github/workflows/ci.ymlindex 4b079640,7d666440..16197305--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@@ -95,14 -83,51 +95,51 @@@ jobs# and it was `continue-on-error`, so those extra minutes gated nothing.# Add the `windows` label to a pull request that touches path handling,# file locking, or git plumbing.+ #+ # `windows-cross` below is the cheap per-merge complement: it cross-*builds*+ # the Windows target from Linux, so a `#[cfg(windows)]` compile or link break+ # is caught in this ~8-minute gate instead of at release time. It does NOT run+ # tests — cross-compiling proves the code builds and links for Windows, not+ # that it behaves correctly there. Wine is deliberately not used to fake a+ # runtime: it cannot faithfully reproduce native PowerShell, NTFS+ # case-folding, Win32 file-locking/sharing-violation semantics, or verbatim+ # (`\\?\`) path handling — exactly the surface windows.yml (and the local+ # dockur VM loop, see docs/design-windows-ci.md) exist to validate.+ windows-cross:+ name: windows cross-build (msvc)+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ # Pin to 1.95 to match rust-toolchain.toml: that file overrides the+ # active toolchain inside the repo, so the MSVC target's std must be added+ # to 1.95 (not `stable`) or the cross-build fails with "can't find crate+ # for `core`".+ - uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # 1.95+ with:+ toolchain: "1.95"+ targets: x86_64-pc-windows-msvc+ - uses: Swatinem/rust-cache@f0d9c3887740aee45f6153b24b3a6b815192ec16 # v2+ with:+ key: windows-cross+ # cargo-xwin drives clang-cl / lld-link against an auto-downloaded MSVC+ # CRT + Windows SDK, so bundled SQLite and vendored libgit2 (both C) build+ # for the target without a Windows host.+ - name: Install clang/lld toolchain+ run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang llvm lld+ - name: Install cargo-xwin+ run: cargo install cargo-xwin --locked+ # --all-targets so the `#[cfg(windows)]` test binaries compile too — that+ # is the class of break (a test that only compiles on Windows) this gate+ # is here to catch before it reaches windows.yml or a release.+ - run: cargo xwin build --workspace --all-targets --target x86_64-pc-windows-msvc- # The companion importer is deliberately outside the root workspace- # (its own [workspace] in companions/ai-memory-importer/Cargo.toml), so- # none of the jobs above compile it. Gate it here with the same- # fmt/clippy/test trio docs/companion-crates.md prescribes, or a- # toolchain bump / convention change rots it silently.+ # Companions have their own workspaces and need separate checks.companions:- name: companions (ai-memory-importer)+ name: companions (${{ matrix.companion }})+ strategy:+ fail-fast: false+ matrix:+ companion: [ai-memory-importer, ai-memory-relay]runs-on: ubuntu-lateststeps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1diff --cc .github/workflows/windows.ymlindex f089ebe1,8161d7a5..b58751d7--- a/.github/workflows/windows.yml+++ b/.github/workflows/windows.yml@@@ -66,24 -70,28 +70,49 @@@ jobs- uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable- uses: Swatinem/rust-cache@f0d9c3887740aee45f6153b24b3a6b815192ec16 # v2- run: cargo test --workspace --all-targets+ - name: Check the external lifecycle relay+ env:+ CARGO_TARGET_DIR: ${{ github.workspace }}/target+ run: |+ cargo fmt --check --manifest-path companions/ai-memory-relay/Cargo.toml+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+ cargo clippy --locked --manifest-path companions/ai-memory-relay/Cargo.toml --all-targets -- -D warnings+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+ cargo test --locked --manifest-path companions/ai-memory-relay/Cargo.toml+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+ cargo build --locked --manifest-path companions/ai-memory-relay/Cargo.toml+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }+ - uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0+ with:+ enable-cache: false+ - name: External lifecycle delivery against the real server+ run: >+ uv run --no-project python tests/e2e/external_relay_smoke.py+ --ai-memory-bin "${{ github.workspace }}/target/debug/ai-memory.exe"+ --relay-bin "${{ github.workspace }}/target/debug/ai-memory-relay.exe"+ --timeout-seconds 120++ # `ci.yml`'s `hooks-shell` job covers the POSIX bundle across four awks, all+ # on Linux. The suite also drives `hooks/lib/ai-memory-hook.ps1`, and that+ # half only ever executes where PowerShell is native — so the one platform+ # its PowerShell branch is written for was the one platform no job ran it on.+ #+ # Its own job so a Rust failure cannot stop the shell suite from reporting,+ # but gated behind the `windows` label like `test` above. The project keeps+ # Windows off per-PR feedback by default (see the header's cost argument), so+ # a pull request touching `hooks/` opts in with the `windows` label, the same+ # as any other platform-sensitive change; it also runs nightly and on manual+ # dispatch. (The job is cheap — a checkout and a few seconds of `sh` — but+ # consistency with the fast-CI-per-merge rule wins over an every-PR carve-out.)+ hooks:+ name: hook bundle (windows-latest)+ # On a pull request, only when explicitly opted in (same as `test`).+ if: >-+ github.event_name != 'pull_request' ||+ contains(github.event.pull_request.labels.*.name, 'windows')+ runs-on: windows-latest+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ - name: hook bundle (Git Bash)+ shell: bash+ run: sh tests/hooks/test_lib.shdiff --cc CHANGELOG.mdindex e3dc279b,6cbe8ce3..d1296a25--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -8,10 -8,25 +8,29 @@@ and this project adheres to [Semantic V## [Unreleased]### Added+- Added the optional `ai-memory-relay` companion for external lifecycle events.+ It queues events locally and sends ordered batches through the public hook API,+ using stable event identities for retries. The package has its own workspace+ and does not change the server's capture or storage defaults. (#823)+ - `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 lifecycleproducers. Updated native hooks, script bundles and generated integrationssuppress capture while preserving supported handoff delivery and MCP recall.@@@ -34,11 -349,43 +353,46 @@@`OPENCODE_API_KEY` as the only credential, Go as the default endpoint, Zenvia `AI_MEMORY_LLM_BASE_URL`, the built-in default model, per-cataloguemodel ids, and which model goes through the Responses endpoint (#763).+ - Refreshed the LongMemEval-S retrieval benchmarks on the 2.4 tree and+ populated the full-dataset R2 A/B (`docs/benchmarks/`): local embeddings add+ +0.149 hit@5 / +0.254 recall@10 over zero-LLM FTS, with a clean+ baseline-vs-baseline determinism check and **no default-ranking regression**+ vs 2.3.x (the 2.4 features are opt-in / off by default).### Fixed+- 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. (#823)+ - A failed scheduled `auto_improve` review no longer removes its session from+ the queue permanently. The scheduler claims a session before reviewing it,+ and the candidate query excludes any session that holds a claim — but nothing+ ever released one, so a review that failed (a hung provider call, or a+ proposal the reviewer could not stage) left a claim with no run row and that+ session was skipped by every later tick. The state was silent: the tick+ reported `errors=1` once and clean runs from then on, and the only exit was a+ hand-written `DELETE`. A claim now records the failure and releases, so the+ next tick retries it, and parks after 3 attempts with the last error kept so a+ deterministic failure stops costing a review every tick instead of vanishing.+ The tick summary counts `parked` separately from `errors`. (#833)+ - The auto-improve reviewer now excludes `sessions/` pages from its own+ recent-page context so those slots go to durable pages (`decisions/`,+ `gotchas/`, `_rules/`, …) it might otherwise re-propose. Session pages are+ never valid proposal targets and previously dominated the recency-ordered+ list, crowding durable knowledge out of the reviewer's view. The exclusion is+ scoped to the reviewer only — the SessionStart briefing and `memory_briefing`+ still include session pages. `docs/auto-improvement-loop.md` now documents+ that only `_rules/`/`procedures/` page bodies reach the reviewer and that the+ recent-page list is recency-ordered, with configurable patchable prefixes and+ embedding-nearest dedup noted as deferred future work. (#834)+ - Auto-improve proposal staging no longer discards an entire run when one+ proposal is a create/update misclassification. A `Create` whose target page+ already exists, or an `Update`/patch whose target is missing, previously+ aborted the staging transaction, dropping every sibling proposal and the run+ row over one probabilistic LLM mislabel. Those two cases now skip just the+ offending proposal (reported as `skipped`, like a pending-target collision)+ and keep the rest of the run. Two proposals in one run targeting the same+ path remain a hard error, and a create-on-existing is never coerced to an+ update (the page could be pinned). (#832)- The Windows Docker wrapper (`bin/ai-memory.ps1`) now forwards the sameprovider credentials and host-config env vars as the POSIX wrapper into thehelper container. A host-exported `GEMINI_API_KEY` / `GOOGLE_API_KEY`,