Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge remote-tracking branch 'origin/main' into audit/pr-320
AkitaOnRails17d086e981e5
diff --cc CHANGELOG.mdindex 39d47792,966b9cb5..e4bd187b--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -8,36 -8,20 +8,30 @@@ and this project adheres to [Semantic V## [Unreleased]### Added+- Entity-match retrieval as a fourth RRF stream (V38 `entities` +- `entity_page_links`). Consolidation now emits an `entities` list per- page — the specific technologies, components, and domain nouns the- content names — which lands in the page's frontmatter (markdown stays- the source of truth; a reindex rebuilds the index) and is matched- lexically at query time: exact name, name-prefix, or a word inside a- multi-word entity, weighted by inverse entity frequency so a rare noun- outranks a ubiquitous one. This finds pages whose *wording* misses the- query — a note whose body says "the streaming broker" now answers a- query for "jetstream". No spaCy, no NLP dependency, and no LLM call at- query time: extraction happens only where an LLM already runs, so a- project that never consolidated has an empty table and the stream- contributes nothing — the zero-LLM default path is unchanged. With- `explain: true` each hit reports its `entity_rank` and- `matched_entities`. `entities.id` is deliberately shaped as the stable- anchor a future temporal-triples table could reference; that P2 item- stays deferred, and no graph database is involved either way.- - Optional post-RRF reranking for `memory_query`, off by default. Set- `AI_MEMORY_RERANKER=llm` (requires `AI_MEMORY_LLM_PROVIDER`) and the- query over-fetches `limit * 3` candidates (capped at 30) from the RRF- stage, then has the configured LLM provider score each one against the- query through JSON-schema structured output — no new provider dialect,- and it works across all eight existing providers. Scored candidates- sort by relevance and any the model skipped follow in RRF order.- Degrades rather than fails: a 20-second timeout, a provider error, or a- response covering fewer than half the candidates all fall back to plain- RRF order, matching the embedder's contract. With `explain: true` each- hit's `score_details` carries its `rerank_score`. An unknown- `AI_MEMORY_RERANKER` value, or `llm` without a provider, fails at- startup instead of silently disabling the feature.++ `entity_page_links`). Consolidation emits up to 10 normalized technologies,++ components, services, files, or domain nouns per page into frontmatter;++ manually edited `entities` use the same index path, and reindex rebuilds the++ derived tables from markdown. Project-scoped query tokens match exact names,++ name prefixes, or word prefixes inside compound names and are weighted by++ inverse entity frequency before RRF fusion and the existing authority and++ optional LLM reranking stages. Empty entity indexes add no query-time work or++ score, and entity matching makes no LLM call. `explain: true` reports the++ entity stream's rank, contribution, and matched names. (#320)+ - Optional post-RRF reranking for project and explicit-scope+ `memory_query`, off by default. Set `AI_MEMORY_RERANKER=llm` (requires+ `AI_MEMORY_LLM_PROVIDER`) to over-fetch candidates, fuse scopes, and+ make at most one structured-output call through any existing LLM+ provider. The prompt JSON-encodes untrusted input and sends the query+ (up to 1,000 bytes) plus at most 30 page titles (200 bytes each) and+ snippets (600 bytes each) to that provider. The requested result limit+ is preserved even above 30; only the first 30 candidates are judged.+ A partial/duplicate/unknown id set, invalid score, timeout, provider error,+ or four-call concurrency saturation preserves the pre-rerank order.+ `global=true` and supplemental+ global-preference hits keep their existing non-RRF ranking. With+ `explain: true`, judged hits include `rerank_score`. Unknown reranker+ values and `llm` without a provider fail at startup. (#319)- New MCP tool `memory_feedback` (17th tool) — the "finer-grainedreinforcement beyond access counts" P2 item. Record how useful arecalled page actually was by exact path: `helpful` / `not_helpful`diff --cc docs/ARCHITECTURE.mdindex 50e61edf,9cc9417a..c4c12dfe--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@@ -110,26 -110,26 +110,28 @@@ from hook pathstrust boundary and delimiters precede automatically injected handoffs,project briefs, and managed-workstream packets; current instructions andcheckout state remain authoritative.- 6. `memory_query` answers via FTS5 + entity-match + link-neighbour RRF;- when an embedder is configured, vector cosine over `page_embeddings`- joins the same RRF. Each stream contributes nothing when its input is- absent, so the zero-LLM default is FTS5 + entity + graph. Before final- truncation, a bounded authority multiplier adjusts the relevance score- using the canonical page kind, tier, `pinned`, and explicit- positive/negative frontmatter tags. It favors maintained rules,- decisions, procedures, and gotchas in close contests while keeping- episodic, historical, lint, and test evidence searchable. No- query-intent regex or hard exclusion participates. When- `AI_MEMORY_RERANKER=llm` is set the adjusted candidates get a final LLM- relevance pass (degrading to the adjusted order on error). If compiled- wiki pages miss entirely in default, explicit project, or explicit-6. `memory_query` answers via FTS5 + link-neighbour RRF; when an- embedder is configured, vector cosine over `page_embeddings` joins- the same RRF. Before final truncation, a bounded authority multiplier- adjusts the relevance score using the canonical page kind, tier,- `pinned`, and explicit positive/negative frontmatter tags. It favors- maintained rules, decisions, procedures, and gotchas in close contests- while keeping episodic, historical, lint, and test evidence searchable.- No query-intent regex or hard exclusion participates. An optional- `AI_MEMORY_RERANKER=llm` pass sends a bounded query plus up to 30 bounded- titles/snippets to the configured provider after project/scope fusion; it is- limited to one call per query and four calls in flight, and any invalid,- failed, timed-out, or saturated attempt preserves the local order. Global- and supplemental global-preference results do not take this path. If++6. `memory_query` answers via FTS5 + entity-match + link-neighbour RRF; when an++ embedder is configured, vector cosine over `page_embeddings` joins the same++ RRF. The entity index is derived from the canonical frontmatter `entities`++ list, and an empty index contributes no candidates or score. Before final++ truncation, a bounded authority multiplier adjusts relevance using canonical++ page kind, tier, `pinned`, and explicit positive/negative frontmatter tags.++ It favors maintained rules, decisions, procedures, and gotchas in close++ contests while keeping episodic, historical, lint, and test evidence++ searchable. No query-intent regex or hard exclusion participates. An++ optional `AI_MEMORY_RERANKER=llm` pass sends a bounded query plus up to 30++ bounded titles/snippets to the configured provider after project/scope++ fusion; it is limited to one call per query and four calls in flight, and any++ invalid, failed, timed-out, or saturated attempt preserves the local order.++ Global and supplemental global-preference results do not take this path. If+ compiled wiki pages miss entirely in default, explicit project, or explicit- `scopes` mode, bounded raw observation- FTS returns fallback `raw_hits`; `global=true` searches compiled wiki- pages across projects only. Page hits bump `access_count` +- `last_accessed_at` - the M8 reinforcement term. That bump is throttled- to at most once per page per minute, so a burst of overlapping searches- does not flood the writer actor with redundant reinforcement writes.+ `scopes` mode, bounded raw observation FTS returns fallback `raw_hits`;- `global=true` searches compiled wiki pages across projects only. Page- hits bump `access_count` + `last_accessed_at` - the M8 reinforcement- term, which `memory_feedback` complements with explicit per-page- salience. That bump is throttled to at most once per page per minute,- so a burst of overlapping searches does not flood the writer actor- with redundant reinforcement writes.++ `global=true` searches compiled wiki pages across projects only. Page hits++ bump `access_count` + `last_accessed_at` - the M8 reinforcement term, which++ `memory_feedback` complements with explicit per-page salience. That bump is++ throttled to at most once per page per minute, so a burst of overlapping++ searches does not flood the writer actor with redundant reinforcement++ writes.7. The forget sweep runs on demand and on the server's `[maintenance]`schedule: pages past their frontmatter `expires_at:` TTL arehard-deleted through the wiki layer (file + rows, pin or not);@@@ -255,8 -255,7 +257,8 @@@ separately gated Claude Code assistant/| `links` | Wikilink / markdown cross-references. `to_page_id` (a global PageId) is nullable for unresolved forward links. `to_workspace` / `to_project` carry a cross-project scope (NULL = the source page's own project). || `handoffs` | Typed cross-agent handoff records (open / accepted / expired). || `page_embeddings` | Optional vector rows for latest pages, with `(provider, model, dim)` denormalised so hybrid search can ignore stale vectors after an embedding config change and report missing-embedding diagnostics. |- | `page_feedback` | Append-only `memory_feedback` signals (`helpful` / `not_helpful` / `stale` / `wrong`) keyed by page *version*, with an optional reason. Source of truth for the derived `pages.salience`; the lint pass reads unresolved stale/wrong rows joined against `is_latest = 1`, so a rewrite retires the finding. |- | `entities`, `entity_page_links` | V38 noun index derived from the frontmatter `entities:` list the consolidator writes. Names are lowercase and unique per project; links are per page *version* and replaced on rewrite. Powers the 4th retrieval stream. `entities.id` is deliberately the stable anchor a future temporal-triples table could reference — that P2 item stays deferred. |+ | `page_feedback` | Append-only `memory_feedback` signals (`helpful` / `not_helpful` / `stale` / `wrong`) keyed by page *version*, with an optional sanitized reason and `salience_after`. Source of truth for the derived `pages.salience`; the lint pass reads unresolved stale/wrong rows joined against `is_latest = 1`, so a rewrite retires the finding. |++| `entities`, `entity_page_links` | V38 noun index derived from canonical frontmatter. Names are normalized and unique per project; links target page versions and are replaced transactionally on rewrite. Powers the fourth RRF retrieval stream. || `audit_log` | Every mutation, addressable by `at DESC`. |**Memory tiers (M8 policy):**