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 HEAD
AkitaOnRails2d8c473c5901
diff --cc CHANGELOG.mdindex 702b6e12,18dc1ec9..344fd15c--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -7,146 -7,66 +7,205 @@@ and this project adheres to [Semantic V## [Unreleased]+### Added+- The web UI shows pending cross-project mail. Project cards carry an amber+ `N inbox` badge when messages are waiting for an agent in that project, the+ home page summarises the total and links the projects holding mail, and the+ project page gains a read-only Mailbox section listing up to five of them+ (subject, sender, a snippet, age; "5 of N" when more are waiting), with an+ empty state when there are none. A sender the viewer may not read is shown as+ "a project you cannot read", and the page never pops or cancels a message.+ (#1202)+- `install-mcp --client prime-agent` registers ai-memory with Prime Agent+ (PrimeIntellect-ai/prime-agent), merging an HTTP entry into the `mcpServers`+ map of `$PRIME_AGENT_CODING_AGENT_DIR/settings.json` (default+ `~/.prime/agent/settings.json`) and preserving other settings and servers.+ With a token the entry names `"bearerTokenEnvVar": "AI_MEMORY_AUTH_TOKEN"`+ and the token is not written; Prime Agent 0.10 counts a user HTTP server as+ connected, and lists it to the model, only with that variable set (or an+ OAuth grant), so export it where you launch `prime-agent`. Without a token+ the server is still callable through `mcp.call_tool("ai-memory", ...)` but is+ not listed. MCP-only: Prime Agent 0.10 has no lifecycle hooks. (#1163)+- `memory_write_page` accepts `expected_page_id` (write only if that is still+ the page's latest version) or `create_only` (write only if the page does not+ exist), and `memory_delete_page` accepts `expected_page_id`. A precondition+ that no longer holds fails with `reason: "precondition_failed"` and the+ current version, and changes nothing. `memory_read_page` returns the version+ as `page_id` and `/api/v1` pages as `id`. This is the compare-and-write the+ team-wiki sync needed (#986).+- The `ai-memory-wikisync` companion gained CI and post-merge integration+ (#986, slice 5): `sync --check` writes nothing and exits 0 in sync, 3 on+ drift and 4 on conflicts or refusals (a clone without sync state compares+ the repository with the server directly), and `install-hook` /+ `uninstall-hook` manage a marked git `post-merge` block that runs `sync`+ after each merge: a dry-run report unless `--on-merge apply`, never with+ `--prefer`, and never with a stored token. The cookbook has a GitHub+ Actions recipe. (#986)+- The `ai-memory-wikisync` companion now propagates deletes with+ `sync --propagate-deletes` (#986, slice 4): a file deleted in the repository+ deletes its server page through `memory_delete_page`, and a page deleted on+ the server deletes its file, when the other side is unchanged since the last+ sync. A delete against an edit is a conflict that `--prefer` resolves, more+ than `--max-deletes` (default 10) refuses the run, and a pinned page is+ deleted only with `--prefer repo`. Every sync write and delete now carries+ the page version it was planned against, so a page changed during the run is+ reported and left alone while the rest apply, and `sync --apply` refuses a+ server older than 2.7. Without the flag deletes are still only reported.+ (#986)+- `ai-memory doctor` now reports three silent capture failures: an unreachable+ server (reported instead of aborting the check), a hook spool that is full and+ evicting undelivered events, and installed ai-memory Codex hooks that Codex+ skips because they are untrusted or changed since they were trusted (asked+ of Codex itself through `codex app-server`). `ai-memory status` no longer says+ queued events will be delivered once the spool has started evicting them.+- Added two-way sync to the `ai-memory-wikisync` companion (#986, slice 3):+ `sync` imports repository edits and new pages through the public+ `memory_write_page` MCP tool and exports server edits, comparing each+ page with the last sync. A page changed on both sides is a conflict until+ `--prefer repo` or `--prefer server`; deletes are reported, not synced.+ It is a dry-run without `--apply`, refuses files without frontmatter,+ refuses to overwrite server pages whose metadata a write would clear, and+ re-reads each page right before writing it. (#1164)+- `finalize-session --agent antigravity-cli` now replays the session's typed+ prompts from `agy`'s `history.jsonl` before its synthetic session-end, so+ live Antigravity sessions, whose hooks carry no prompt event, get a summary+ page titled by the first prompt, a handoff with "Started/Last", and prompts+ that `memory_query` and `memory_recent` can find. Only lines whose+ conversation and workspace match the session are read; each prompt carries+ the key `backfill` mints for it, so a repeated `--reopen` stores it once and a+ prompt typed after the first finalize arrives with the next one. A checkout+ the capture allowlist does not admit and `--all-owners` runs replay nothing,+ and a missing `history.jsonl` only warns. (#1160)+- `ai-memory run` accepts `copilot` (alias `copilot-cli`) and manages GitHub+ Copilot CLI as a workstream harness: a fresh session gets a generated+ `--session-id`, a returning one is resumed with `--resume=<id>`, user+ selectors (`--resume`, `--continue`, `--session-id`, `--connect`) win,+ utility subcommands pass through, and `--yolo` maps to Copilot's native+ `--yolo`. Visible messages, tool calls and results, and compaction summaries+ are imported read-only from `$COPILOT_HOME/session-state/<uuid>/events.jsonl`+ (system prompts, hidden reasoning, hook output, and telemetry are excluded),+ and the existing SessionStart hook delivers the workstream context. The+ first managed launch auto-wires Copilot's hooks and MCP, and `doctor` now+ counts its local sessions. Verified against Copilot CLI 1.0.92. (#1040)+- GitHub Copilot CLI is now a first-class routing target:+ `install-skills --agent copilot-cli` (and `install-instructions+ --skills-agent copilot-cli`) writes the managed Agent Skills to the+ repository's `.github/skills` or, globally, to `$COPILOT_HOME/skills`+ (default `~/.copilot/skills`); `memory_install_self_routing` returns+ `copilot_cli` filename and skill-root hints; the routing snippet, the+ routing-install skill, and the MCP instructions name Copilot CLI with+ `AGENTS.md`; and `uninstall` sweeps both Copilot roots, removing only+ marker-bearing ai-memory skills. (#1040)+- Added `ai-memory recover` and a bounded local recovery journal for server+ outages. Offline managed launches now record only uniquely correlated native+ session locators; recovery quarantines overlapping spool entries before exact+ `/hook/batch` transcript replay, journals harnesses without transcript export+ as spool-only without calling their exporter, retains bounded recovery dedup+ keys with their sessions,+ fails closed on terminal drops, and lets only the original owner finish an+ expired unsuperseded managed run through exact idempotent replay. Backfill+ and recovery replay now use reserved `recovery_*` idempotency keys, so+ re-running `backfill --force` over sessions imported by ai-memory ≤2.6.0 (or+ plain-backfilling a recovery-replayed session) can duplicate those older+ observations. (#1125)+- Added `AI_MEMORY_LLM_COMPAT_DISABLE_THINKING` for the `openai-compat`+ provider (opt-in, off by default, ignored by every other provider): when+ set, every chat request carries+ `chat_template_kwargs: {"enable_thinking": false}`, so thinking-capable+ local engines (vLLM / SGLang serving Qwen3-class models) spend the output+ budget on the structured payload instead of a reasoning pass. (#1130)+- Added the `cursor` LLM provider. Consolidation calls the logged-in Cursor+ Agent CLI (`agent --print --mode ask`) so a Cursor subscription can drive+ summaries without an API key. The default model is `cursor-grok-4.6-high`+ ("Grok 4.6"). `AI_MEMORY_CURSOR_AGENT` overrides the binary. The provider never passes+ `--yolo` or `--force`, because the prompt is captured session text. (#1127)+- Added `applies_to` and `enforced_by` arguments to `memory_write_page`, and+ `--applies-to` / `--enforced-by` to `ai-memory write-page`, for profile+ entries. Both fields were documented as profile-entry frontmatter, but no+ tool could set them, so scoping an entry to a stack or keeping it out of the+ digest meant editing the wiki file by hand, and the next tool rewrite of the+ entry dropped the value. A tag the profile cannot detect in any project+ (`typscript`) is refused instead of silently hiding the entry, and both+ arguments are refused on any page the digest does not read: one outside+ `profile/`, or a `profile/` path in an ordinary project. (#1178)++- Added the server version to the footer of every signed-in `/web` page (the+ public login and change-password pages leave it out), on the right+ side opposite "ai-memory · read-only", so you can tell which build a browser+ tab is talking to without running `ai-memory status`. (#1171)++- Added `install-mcp --client dsh` for the DeepSeek Harness (aliases+ `deepseek-harness` and `deepseek_harness`). DSH keeps its MCP client in+ a Cordis profile patch rather than a fixed config file, so the command prints a+ ready-to-merge `- insert:` fragment for `@deepseek-ai/dsh-mcp-client` and+ refuses `--apply`. (#1193)++### Changed+- Changed `ai-memory-wikisync` files to carry a small frontmatter (`title`,+ plus `tags`, `pinned` and a non-default `tier` when set) above the body,+ so metadata survives a round trip. The first run after upgrading rewrites+ unedited files of an earlier export in place. (#1164)+### Fixed+ - Fixed the cross-project profile harvester treating pages the auto-improve+ scheduler auto-approved as curated human input: model output nobody+ reviewed fed the profile like a hand-written rule. A page stamped from an+ auto-improve proposal is now skipped when the proposal's decider is the+ scheduler's auto-approve actor; a page a human approved still counts, and a+ page whose proposal id resolves to no row (legacy or imported) stays+ curated. (#1211)+ - Fixed the zero-LLM session page staying silent about abrupt endings. The+ rule-based synthesis now adds a deterministic terminal-state line reusing+ the automatic handoff's heuristics: "Session ended without a normal stop;+ the final prompt was never answered." when the log ends on an unanswered+ question, the equivalent line when file activity was never followed by a+ stop, and a mid-task-exit line when a stop was recorded but no session+ end arrived. A session with a normal stop and end gets no line. (#1221)+ - Fixed consolidation dropping the tail of a session from the compiled+ page. The single and batch prompts now carry explicit rules: say so when+ the observation log ends on an unanswered prompt or without a normal+ stop, and record in-flight work (background jobs, watchers, timers) as+ pending state; when a later observation corrects an earlier "done"+ milestone, state only the final state with the superseded claim as+ history at most; preserve the last reported metrics of in-flight work+ (sizes, rates, counts, ETAs) verbatim; carry operator "run X when Y"+ instructions verbatim, with their preconditions, into a+ Next steps / Pending section; and, for sessions that operated on+ external systems, emit an "Access and verification" section — hosts,+ the per-host auth mechanism (never secrets or tokens themselves),+ job-state marker locations, staged-script paths — grounded only in what+ the observations show. (#1221)+ - Softened the consolidation prompts' wikilink quota that pushed models to+ invent links. The single, batch and bootstrap prompts told the model "2-5+ well-chosen links per page beat exhaustive linking; zero links should be+ rare", which+ pressured it to add links just to hit the number. They now state that zero+ links is fine when nothing in the input genuinely relates, require a genuine+ reason visible in the input for every link, and forbid padding a page with+ links to hit a number; the #1207 restriction on cross-scope links whose+ target is not visible in the input is unchanged. The validated+ `consolidation.max_input_tokens` floor moved from 6,000 to 6,500 tokens so+ the larger prompts still leave room for observation evidence at the minimum.+ (#1219)+ - Fixed consolidation still writing invented `[[_global:…]]` / `[[project:…]]`+ wikilinks when a model ignored the #1207 prompt wording. The single-page,+ batch and bootstrap apply paths now resolve every cross-scope wikilink+ target against the store with no-create lookups before the write and+ rewrite an unresolvable one to its plain label text (an unresolvable+ `relations:` frontmatter entry is dropped), so a missing target+ can no longer mint the dangling cross-project edge that `ai-memory lint`+ reports as `broken_link`. Resolved cross-scope links survive+ byte-identical, and same-project pending links stay untouched by design.+ A link into a restricted project is always de-linked, so the result never+ reveals which pages exist there. (#1218)+ - Fixed consolidation inventing `[[_global:…]]` and `[[project:…]]` wikilinks to+ pages that never existed, which `ai-memory lint` then reported as+ `broken_link`. The single, batch and bootstrap prompts told the model that a+ missing link target was acceptable and gave it no list of cross-scope pages,+ so it invented targets to meet the 2-5 link guidance. They now allow a+ `project:` or `_global:` link only when the exact wiki page path appears in+ the input, which reduces but does not eliminate such links; a missing+ same-project target stays a pending link. (#1207)- Fixed the web UI answering HTTP 500 when a signed-in viewer opened a projector page by a name that two projects answer to. The page and project routesnow return a 400 that names the clash, matching the API and MCP surfaces.diff --cc crates/ai-memory-wiki/src/lib.rsindex 8a1be1e9,81b83cc7..e5df92e8--- a/crates/ai-memory-wiki/src/lib.rs+++ b/crates/ai-memory-wiki/src/lib.rs@@@ -26,13 -26,13 +26,16 @@@ pub use confinement::validate_wiki_treepub use error::{WikiError, WikiResult};pub use git::{COMMIT_AUTHOR_EMAIL, COMMIT_AUTHOR_NAME, GitAdapter};pub use ledger::is_rotated_event_ledger;- pub use markdown::{Markdown, derive_title, emit, parse, rewrite_local_wikilinks};+ pub use markdown::{+ Markdown, delink_wikilinks, derive_title, emit, extract_links, extract_relation_links, parse,+ rewrite_local_wikilinks,+ };pub use migrations::run_pending as run_wiki_migrations;pub use watcher::{DEBOUNCE_WINDOW, RECONCILE_INTERVAL, WatcherHandle};-pub use wiki::{MoveSessionOutcome, PurgeSessionOutcome, SessionPageFile, Wiki, WritePageRequest};+pub use wiki::{+ ConditionalWrite, MoveSessionOutcome, PurgeSessionOutcome, SessionPageFile, Wiki,+ WritePageRequest,+};// Integration tests compile into this crate's test harness instead of a// separate binary: every test binary is another link and, on macOS and