Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

docs: the why/when pass - adoption guidance over feature lists (item 8)

AkitaOnRails0b35ed873e62
diff --git a/README.md b/README.md
index 0f33dccb..331e441b 100644
--- a/README.md
+++ b/README.md
@@ -106,11 +106,10 @@ caveats is in [`docs/support-matrix.md`](docs/support-matrix.md).
| Grok Build CLI | Supported |
| Swival CLI | MCP-only |
| Zero | Supported |
-| ZCode | MCP-only |
+| ZCode | Supported |
| Kimi Code | Supported |
| Kiro CLI | Supported |
| Pool | Hooks-only |
-| ZCode | Hooks-only |
| VS Code Copilot | MCP-only |
| Zed | MCP-only |
| Hermes Agent | Community |
@@ -351,7 +350,6 @@ diagram, crate breakdown, schema notes, and invariants.
- [`docs/experience.md`](docs/experience.md) - the opt-in cross-session abstraction pass: knowledge visible only across trajectories.
- [`docs/MIGRATION-2.0.md`](docs/MIGRATION-2.0.md) - upgrading an existing store to 2.0: the backup-gated automatic migration and how to restore.
- [`docs/benchmarks/`](docs/benchmarks/README.md) - published retrieval-quality numbers with provenance, reproducible from the in-repo harness.
-- [`docs/ROADMAP-2.0.md`](docs/ROADMAP-2.0.md) - the 2.0 plan.
## Influences and prior art
diff --git a/crates/ai-memory-cli/templates/config.default.toml b/crates/ai-memory-cli/templates/config.default.toml
index 97fd2b26..32b01ab6 100644
--- a/crates/ai-memory-cli/templates/config.default.toml
+++ b/crates/ai-memory-cli/templates/config.default.toml
@@ -159,6 +159,9 @@ allowlist = []
# operator's bounded namespace and only shared plus own slots are injected into
# that operator's session brief and consolidation prompt. Exact page reads and
# searches remain project-wide: this is context-injection isolation, not RBAC.
+# Slots are the few always-loaded pages (project context, invariants)
+# injected into every session brief. Adjust only if briefs feel bloated
+# (lower the caps) or your project context page keeps getting clipped.
[slots]
per_user = false
@@ -166,6 +169,10 @@ per_user = false
# differ by provider and model. Their sum must fit the model's context window;
# leave additional headroom for tokenizer variance. Small local models must
# lower both values together. Startup minimums are 6000 input and 1000 output.
+# Consolidation turns a finished session's raw observations into wiki
+# pages. Off (zero-LLM) you still get session pages + search; with an
+# LLM you get distilled concept/gotcha/rule pages. Reach for these knobs
+# when summaries feel too chatty (lower max tokens) or truncated (raise).
[consolidation]
max_input_tokens = 100000
max_output_tokens = 32000
diff --git a/docs/auto-improvement-loop.md b/docs/auto-improvement-loop.md
index a51a1e01..239aeafd 100644
--- a/docs/auto-improvement-loop.md
+++ b/docs/auto-improvement-loop.md
@@ -1,4 +1,38 @@
-# Optional Auto-Improvement Loop Research
+# Auto-improvement
+
+## The 60-second version (read this first)
+
+When an LLM provider is configured, the server periodically reviews
+newly completed sessions and proposes small wiki edits — a new gotcha,
+a rule promotion, a patch to a stale concept page. Every proposal is
+validated (schema, confidence floor, size caps, eval gate) and staged
+into `_pending/auto-improve/` with a human-readable sidecar, then
+**auto-approved by default** through the normal wiki write path.
+
+What that means for you:
+
+- **Solo, zero-LLM install**: this never runs. Nothing to decide.
+- **Solo with an LLM**: the default is fine — proposals are small,
+ bounded, audited (every one lands in the pending-writes trail with
+ evidence quotes and a confidence score), and reversible via wiki
+ history. Watch `_pending/` for a week if you want to build trust.
+- **Shared / team server**: set `[auto_improve] require_approval =
+ true`. On a server several people trust, an LLM should not
+ auto-apply edits nobody reviewed — proposals then wait in
+ `_pending/` until a human approves each one.
+- **Cost**: one bounded LLM call per completed session that passes the
+ preflight filters (minimum observations/duration); prompt and output
+ sizes are capped in `[auto_improve]`.
+
+A typical staged proposal sidecar looks like: the target path, the
+operation (create or patch), a confidence like `0.86`, the rationale,
+bounded evidence quotes from the session, and the exact body or edits
+— enough to approve or reject without opening anything else.
+
+The rest of this page is the original design research plus
+implementation notes, kept for depth.
+
+---
> Status: research plus implemented production notes. The server schedules
> auto-improvement for newly completed sessions in every project when an LLM provider is
diff --git a/docs/auto-scope.md b/docs/auto-scope.md
index 02b43c5a..2cf95dae 100644
--- a/docs/auto-scope.md
+++ b/docs/auto-scope.md
@@ -70,7 +70,7 @@ isolation.
```toml
[auto_scope]
-mode = "single" # "single" (default) | "per_session" | "per_actor"
+mode = "per_actor" # "per_actor" (default since v1.39) | "per_session" | "single"
session_ttl_secs = 3600 # TTL for per-key entries (default 1 h)
max_entries = 4096 # hard cap; oldest insertions evicted first
```
diff --git a/docs/experience.md b/docs/experience.md
index c26f9f7b..74f351bd 100644
--- a/docs/experience.md
+++ b/docs/experience.md
@@ -33,6 +33,31 @@ young — cross-session patterns need sessions to cross — or when no LLM
is configured: the pass is LLM-hosted and the zero-LLM default path
never runs it.
+## What a proposal looks like
+
+After eight sessions in which the operator repeatedly rebuilt the
+release binary before running the eval harness, the pass might stage:
+
+```markdown
+# _pending/auto-improve/…-procedures-eval-run.md (confidence 0.86)
+
+## Proposed: procedures/eval-run.md
+
+Before benchmarking, rebuild the release server first — the harness
+spawns `target/release/ai-memory`, and a stale binary silently
+benchmarks old code.
+
+ cargo build --release -p ai-memory-cli
+ cargo run --release -p ai-memory-eval -- retrieval
+
+Evidence: sessions 2026-08-28 ("rebuilt release, numbers changed"),
+2026-08-30 ("forgot the rebuild again — rerun").
+```
+
+It stays in `_pending/` (with `require_approval = true`) until a human
+approves it — the same review flow as every other auto-improve
+proposal.
+
## What it costs and what guards it
One LLM call per project per cadence trigger, prompt-bounded like the
diff --git a/docs/managed-workstreams.md b/docs/managed-workstreams.md
index d1eb5437..1f513556 100644
--- a/docs/managed-workstreams.md
+++ b/docs/managed-workstreams.md
@@ -81,6 +81,23 @@ than its name, nothing else moves — including which workstream a bare
a rename deliberately does not touch `selected_at` or `updated_at`. A run that
is already live keeps displaying the name it launched with until it exits.
+## Do you need this?
+
+Probably not at first — hooks alone already carry most continuity.
+
+- **Skip it** when a handoff is all you want: you quit Claude Code
+ mid-task, open Codex in the same directory, and the next session
+ starts with "where you left off, what failed, what's open". That
+ works with nothing but `install-hooks`; no `ai-memory run` involved.
+- **Use it** when you want the harness's own native resume (`claude
+ --resume` / the picker) to survive a harness SWITCH — the managed
+ ledger records the visible event stream portably, so `ai-memory
+ continue` can reopen the same workstream in a different agent with
+ the exact tool-call history, not just a summary.
+
+If you never switch harnesses mid-workstream, the default path is
+simpler and loses you nothing.
+
## Project-first launcher
`ai-memory show` reverses the usual `cd` then `run` flow: choose a local
diff --git a/docs/okf.md b/docs/okf.md
index 3f92eea5..dcd6d37c 100644
--- a/docs/okf.md
+++ b/docs/okf.md
@@ -1,5 +1,28 @@
# OKF conformance (2.0)
+## What this buys you
+
+Your memory is portable beyond ai-memory. Hand a project bundle to a
+teammate who runs a *different* OKF-aware tool — or no tool at all —
+and they read your decisions, gotchas and procedures as ordinary
+markdown with standard metadata:
+
+```bash
+ai-memory export-okf --project myproject -o myproject-bundle.tar.gz
+```
+
+The receiving side unpacks a directory of `.md` files where every page
+declares its `type`, provenance (`generated`, `sources`) and freshness
+(`stale_after`) in the vocabulary Google's Open Knowledge Format
+standardized — greppable, Obsidian-openable, importable by anything
+OKF-aware. Nothing is held hostage: the export is a validated copy of
+the files ai-memory already lives on.
+
+The rest of this page is the design: how conformance is enforced and
+how existing stores migrate.
+
+---
+
ai-memory's wiki is natively an **Open Knowledge Format** bundle from
2.0 on: every page a consumer reads off disk is a conformant OKF
concept file, and a project's wiki directory is a conformant bundle.
diff --git a/docs/support-matrix.md b/docs/support-matrix.md
index cf21c7ed..5b62997c 100644
--- a/docs/support-matrix.md
+++ b/docs/support-matrix.md
@@ -27,11 +27,10 @@
| Grok Build CLI | Supported | MCP config (`install-mcp --client grok` → `$GROK_HOME/config.toml`, default `~/.grok/config.toml`) + lifecycle hooks (`install-hooks --agent grok` → `$GROK_HOME/hooks/ai-memory.json`, default `~/.grok/hooks/ai-memory.json`, Grok-specific hook bundle). Capture works; no hook handoff injection — Grok ignores `SessionStart` stdout, so recover handoffs via MCP `memory_handoff_accept`. `ai-memory run grok` adds managed workstream resume with the context packet delivered natively through `--rules`. Skills root: `.grok/skills` / `$GROK_HOME/skills` (default `~/.grok/skills`). |
| Swival CLI | MCP-only | `install-mcp --client swival --apply` merges a native HTTP entry into the project-root `.swival/mcp.json`, preserving sibling servers. Lifecycle and managed-workstream support are not claimed because Swival's callback contract does not expose a stable session identifier. |
| Zero | Supported | `install-mcp --client zero` (native HTTP + bearer in `~/.config/zero/config.json`) + lifecycle hooks via `install-hooks --agent zero --apply` (exec-form native commands in `~/.config/zero/hooks.json`, JSON payload on stdin, no shell). Capture works incl. specialist (subagent) events; no handoff injection — Zero discards `sessionStart` stdout, so recover handoffs via MCP `memory_handoff_accept`. |
-| ZCode | MCP-only | `install-mcp --client zcode --apply` merges a native HTTP entry (strict schema: `type`/`url`/`headers` only) into the `mcp.servers` map of `~/.zcode/cli/config.json`, preserving sibling servers. Lifecycle hooks are not yet available — see #512. |
+| ZCode | Supported | `install-mcp --client zcode --apply` merges a native HTTP entry (strict schema: `type`/`url`/`headers` only) into the `mcp.servers` map of `~/.zcode/cli/config.json`, preserving sibling servers. ZCode (z.ai, `zcode`, alias `zai`). Lifecycle-hook capture via `install-hooks --agent zcode --apply`: exec-form native commands (`type: "process"`, no shell) merged into the root `hooks` block of `~/.zcode/cli/config.json` around any third-party hooks; native commands enforce capture exclusions. Six documented triggers (`SessionStart`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `Stop`); `PostToolUseFailure` fires instead of `PostToolUse` when a tool throws and lands on the same capture channel with the error preserved. `PermissionRequest` is deliberately not installed — its hook chain races the interactive permission client, so passive capture of that event is unreliable by design. No true session-end — `Stop` is a per-turn boundary, so run `ai-memory finalize-session --agent zcode` after the final turn. Unlike Pool and Zero, `SessionStart` stdout injection works (`hookSpecificOutput.additionalContext`, verified live against the embedded engine v0.16.5), so the prior session's handoff is delivered automatically. No first-party `install-mcp` client and no managed workstream are claimed yet. |
| Kimi Code | Supported | MCP config (`url` entry in `~/.kimi-code/mcp.json`) + lifecycle hooks (`[[hooks]]` in `~/.kimi-code/config.toml`, 10 events including subagent start/stop and `PostToolUseFailure` for tool-failure capture); both paths honor `$KIMI_CODE_HOME`. Handoffs inject via `UserPromptSubmit` stdout (Kimi Code discards `SessionStart` hook stdout); `ai-memory run kimi` adds managed workstream resume. |
| Kiro CLI | Supported | MCP config uses `install-mcp --client kiro-cli` (alias `kiro`) and Kiro's Bedrock-compatible schema flavor. `install-hooks --agent kiro-cli` merges v2 hooks into existing agent configs; the explicit `--agent kiro-cli-v3` target writes the incompatible standalone v3 registration. Both preserve unrelated entries, honor `$KIRO_HOME`, enforce capture exclusions, and inject pending handoffs at session start. Kiro has no true SessionEnd hook; use `ai-memory finalize-session --agent kiro-cli`, with `--session-id <uuid>` for concurrent sessions. `ai-memory run kiro` manages v2; add `--v3`, `--mode`, or `--agent-engine v3` for version-safe v3 resume. |
| Pool | Hooks-only | Poolside Agent CLI (`pool`). Lifecycle-hook capture via `install-hooks --agent pool` (alias `poolside`): Pool reads project-scoped hooks from the repo-root `.poolside/settings.yaml`, so ai-memory stages the scripts and prints a ready-to-paste `hooks:` snippet rather than writing project-local files; native commands enforce capture exclusions. Five Claude-shaped events (`SessionStart`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, `Stop`) and no true session-end — `Stop` is a turn boundary, so run `ai-memory finalize-session --agent pool` after the final turn. `SessionStart` stdout injection is not demonstrated, so capture works but handoff injection does not — recover handoffs via MCP `memory_handoff_accept`. No first-party `install-mcp` client and no managed workstream (`ai-memory run pool`) are claimed: Pool's native session-store contract is not demonstrated (see [`docs/managed-harness-contributions.md`](docs/managed-harness-contributions.md)). Verified against Poolside CLI v1.0.16. |
-| ZCode | Hooks-only | ZCode (z.ai, `zcode`, alias `zai`). Lifecycle-hook capture via `install-hooks --agent zcode --apply`: exec-form native commands (`type: "process"`, no shell) merged into the root `hooks` block of `~/.zcode/cli/config.json` around any third-party hooks; native commands enforce capture exclusions. Six documented triggers (`SessionStart`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `Stop`); `PostToolUseFailure` fires instead of `PostToolUse` when a tool throws and lands on the same capture channel with the error preserved. `PermissionRequest` is deliberately not installed — its hook chain races the interactive permission client, so passive capture of that event is unreliable by design. No true session-end — `Stop` is a per-turn boundary, so run `ai-memory finalize-session --agent zcode` after the final turn. Unlike Pool and Zero, `SessionStart` stdout injection works (`hookSpecificOutput.additionalContext`, verified live against the embedded engine v0.16.5), so the prior session's handoff is delivered automatically. No first-party `install-mcp` client and no managed workstream are claimed yet. |
| VS Code Copilot | MCP-only | `.vscode/mcp.json` for Copilot agent mode; no lifecycle hooks (Copilot does not expose them yet). |
| Zed | MCP-only | Native remote MCP under `context_servers` in Zed's user `settings.json`; no lifecycle hooks or managed-workstream support. |
| Hermes Agent | Community | Core hook ingestion recognizes `agent=hermes` and Hermes' documented shell-hook `tool_name` / `tool_input` payload for concrete session attribution, tool-family titles, and capture exclusions. A community-maintained [`ai-memory-hermes-plugin`](https://github.com/MrLuciano/ai-memory-hermes-plugin) is available, but no first-party installer is shipped; review its compatibility matrix, install/uninstall scripts, and secret handling before using it. Hermes ignores session-start hook stdout, so recover handoffs through MCP. |
diff --git a/docs/temporal.md b/docs/temporal.md
index 540276f4..e2c12053 100644
--- a/docs/temporal.md
+++ b/docs/temporal.md
@@ -38,6 +38,30 @@ insert, and the supersede path closes the outgoing version's windows
in the same transaction — a link's window can never be open-ended in
a superseded version.
+## When to reach for it
+
+Ordinary `memory_query` answers "what do we know NOW" and is the right
+call 99% of the time. `as_of` is for audits and post-mortems: "what
+did the wiki say when that decision was made", "did we already know
+about this gotcha before the incident".
+
+## A worked example
+
+A project recorded `postgres` as its database, then migrated:
+
+```jsonc
+// June: notes/db.md says "we use postgres" (entity: postgres)
+// August: the page is superseded — "we migrated to sqlite" (entity: sqlite)
+
+memory_query { "query": "postgres" }
+// → no hits: current knowledge has moved on
+
+memory_query { "query": "postgres", "as_of": "2026-07-01T00:00:00Z" }
+// → the JUNE version of notes/db.md — the page that carried the
+// `postgres` entity when July began, even though it has since been
+// superseded
+```
+
## Query
`memory_query` accepts `as_of` (ISO-8601). When present the query is
diff --git a/docs/typed-edges.md b/docs/typed-edges.md
index a5b0b6bc..5eac1e16 100644
--- a/docs/typed-edges.md
+++ b/docs/typed-edges.md
@@ -12,6 +12,26 @@ relations:
---
```
+## When to bother — and when not to
+
+Plain `[[wikilinks]]` remain the default and are enough for "these
+pages are related". Typed edges earn their keep in one specific loop —
+**contradictions you want lint to chase**:
+
+1. A gotcha page exists: `gotchas/linker-oom.md` ("the linker OOMs on
+ machines under 32 GB").
+2. Months later a session fixes it; the consolidator (or you) writes
+ `notes/linker-fix.md` with `relations: { fixes:
+ ["gotchas/linker-oom.md"] }` — the gotcha's page history now shows
+ what resolved it.
+3. Later still, new evidence disagrees with a stored decision; the new
+ page declares `contradicts:` — and `memory_lint` reports the pair as
+ a `contradiction` finding until someone reconciles them. No LLM
+ involved: the declaration IS the signal.
+
+If you are not using lint and don't need fix/cause chains, skip the
+frontmatter entirely; nothing else changes.
+
## The vocabulary (closed)
| relation | meaning |