Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge main bug fixes into release/3.2
AkitaOnRails5739e03b0e09
diff --cc CHANGELOG.mdindex dadedae1,adf62336..a3e3857b--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -11,167 -11,61 +11,221 @@@ version in [`docs/changelog/`](docs/cha## [Unreleased]+### Added++- Added bounded local document extraction to the optional+ `ai-memory-importer` companion. Its dry-run-first `document` command accepts+ UTF-8 text/Markdown, text-layer PDF, DOCX, PPTX, XLSX, VTT, and+ SRT; emits attributed, client-sanitized markdown; caps source, archive,+ extracted text, PDF streams, sheets, and actual XLSX cells; and uses deterministic digest paths plus+ conditional MCP writes for idempotent reruns without overwriting an existing+ foreign page. OCR, images, and raw audio/video remain explicitly out of+ scope.+- Added passive per-workload LLM telemetry to `ai-memory status --json` and+ `GET /admin/status`. The closed workload set covers consolidation, reranking,+ auto-improvement, bootstrap, query answers, lint, profile maintenance, dream+ merges, and experience abstraction, with process-lifetime calls, outcomes,+ latency buckets, coarse token estimates, and provider-reported usage where available.+ It records no prompt or output text and does not change provider/model+ routing; public per-workload profiles remain deferred until measurements+ justify their configuration and authentication surface.+- Added structured pre-rank filters to `memory_query`: case-insensitive+ `kind` and exact-array `tag`, typed `tier`, and literal `path_prefix`.+ Filters apply consistently to project/scopes hybrid streams, cross-project+ global FTS, `as_of` history, supplemental profile hits, and `pin_first`.+ Filtered misses omit raw observations because those rows carry no page+ metadata.+- Added a read-only managed-workstream operations page at+ `/web/workstreams`. On multi-user servers it is root-only; single-operator+ installs retain their existing admin access. The bounded overview orders+ live and interrupted work first and derives `active`, `interrupted`,+ `completed`, and `empty` only from trusted run lifecycle fields and imported+ event counts. It exposes no checkout paths, repository fingerprints, lease+ owners, native session ids, source metadata, or transcript content, and it+ does not broaden checkout-local `resume` discovery.+- Added `ai-memory recent` and `GET /admin/recent` to list the most recently+ updated wiki pages, newest first. The listing is scoped to the current+ project by default (cwd / marker, or `--workspace`/`--project`); `--global`+ covers every project and labels each hit with its workspace and project.+ Each hit carries an RFC 3339 `updated_at` instead of an FTS rank. The admin+ route is root-only on a multi-user server, the same as `/admin/search`.+ ([#1379](https://github.com/akitaonrails/ai-memory/pull/1379))+- Added an explicit `serve --allow-insecure-human-auth` (or+ `AI_MEMORY_ALLOW_INSECURE_HUMAN_AUTH=true`) escape hatch for operators who+ knowingly run password login over plain HTTP on a private LAN.+ It is off by default, does not bypass the separate unauthenticated-exposure+ guard, and prints an unconditional warning that passwords, API credentials,+ session cookies, and memory data cross the network unencrypted. (#1383)+- Added first-party Cline CLI lifecycle and MCP support. `install-hooks+ --agent cline --apply` writes Cline's nine supported event files globally or+ per project, refuses user-owned and symlinked targets, and keeps embedded+ bearer credentials owner-only. `install-mcp --client cline --apply` writes+ Cline's top-level transport fields and explicitly selects Streamable HTTP.+ Detached start hooks recover handoffs through MCP; yolo mode disables hooks.+ Also added `install-mcp --client freebuff --apply`, which registers the+ sessionless stdio bridge in `~/.agents/mcp.json` without starting another+ ai-memory server. (#1335)+- Added `[ingest] drop_events` (env `AI_MEMORY_INGEST__DROP_EVENTS`), an+ opt-in list of hook event kinds the server drops before storing them, next+ to the existing `drop_tool_use_id_prefixes` and `drop_tool_names`. A dropped+ event gets the same 202, `dropped_by_policy` metric and log as the other+ policy drops, before the rate limiter, the ingest semaphore and the+ sanitizer. Subagent classification precedes every id, name, and kind matcher,+ so a matching marked event still seeds tracking for its unmarked tail. The+ default drops nothing. `Config::load` checks each value+ against the typed event kind and rejects unknown kinds and `session-start`+ and `session-end`, which open and close sessions. The motivating case is+ `pre-tool-use`: in one production store about 87% of those observations had+ an empty body, and each pairs with a `post-tool-use` that carries the+ content. With `pre-tool-use` dropped, a session whose only work was a tool+ call that never finished now ends as lifecycle-only. (#1339)+- Added opt-in `[sessions] idle_end_after_hours` (env+ `AI_MEMORY_SESSIONS__IDLE_END_AFTER_HOURS`; default `0`, off; range+ `1..=8760`). When it is set, the `serve` maintenance tick ends open sessions+ with no activity for that many hours, such as a harness that crashed or a+ terminal closed before `SessionEnd` fired. A substantive session gets its+ `sessions/<id>.md` summary page, attributed to the session's owner, and its+ consolidation job. A boundary-only session ends lifecycle-only and releases+ the handoff it had accepted. The tick creates no handoff of its own and skips+ sessions bound to an active managed run. A real `SessionEnd` or checkpoint+ that lands while the tick runs wins, and the tick leaves that session alone.+ `ended_at` is the time of the tick; the session's last activity goes in the+ audit row. (#1338)+- Added first-party DeepSeek Harness (DSH) lifecycle capture. `install-hooks+ --agent dsh` (aliases `deepseek-harness`, `deepseek_harness`) stages the+ new `hooks/dsh` bundle, writes a generated Claude Code `hooks.json`, and+ prints a Cordis patch fragment that mounts DSH's official+ `@deepseek-ai/dsh-hooks-claude-code` bridge on+ `$DSH_HOME/profiles/<profile>/cordis.patch.yml` (the patch file itself is+ never auto-written). DSH sessions are stored as `agent=dsh`, and its bridge+ forwards Claude Code-shaped tool payloads, so `[capture] ignore_paths`+ exclusions apply to its file, search and shell calls (Windows `pwsh`, POSIX+ `bash`) like any other Claude-shaped adapter; the reserved Code Mode+ `run_code` transport that its `headless` profile calls is treated as inline+ program source. The bridge+ delivers exactly seven events (no `PreCompact` or `SessionEnd`) and runs+ `SessionStart` detached, so finished sessions close with+ `finalize-session --agent dsh` and pending handoffs are recovered via+ `memory_handoff_list` / `memory_handoff_accept`. (#1337)+- Added an Antigravity skill root family. `install-skills --agent antigravity`+ (aliases `antigravity-cli`, `agy`; also `install-instructions+ --skills-agent antigravity`) writes the managed Agent Skills to both global+ roots Antigravity reads, `~/.gemini/config/skills` (App and IDE) and+ `~/.gemini/antigravity-cli/skills` (CLI), or to the workspace+ `.agents/skills` with `--scope project`. `ai-memory setup` now uses it for+ Antigravity, which until now got its skills only in `~/.agents/skills`, a+ directory Antigravity does not read globally, and `uninstall --only skills`+ sweeps both roots. MCP-driven routing refresh and `backup-agents` expose and+ preserve the same roots, including the shared project `.agents/skills`.+ (#1357)++- Added a read-only wiki link graph in `/web`. The header **Graph** link opens+ `/web/graph`, a server-rendered map of resolved wikilinks whose endpoints sit+ in different projects, plus a table of those edges. Each project page links+ to `/web/w/<workspace>/<project>/graph`, which shows that project's latest+ unexpired pages and the resolved same-project links between them as an SVG+ and a table. Both pages are HTML with no JavaScript.+ `GET /api/v1/graph` now accepts `workspace` and `project` together to return+ only edges that touch that project (passing only one of them is `400`), and+ `GET /api/v1/workspaces/{workspace}/projects/{project}/graph` returns the+ in-project node and edge lists. A project graph keeps at most 120 pages,+ preferring those with the most same-project neighbours and then the most+ recently updated; the store applies that cap before loading nodes or their+ selected edges into the process. Expired pages stay hidden. An edge still+ requires both ends to be readable.+- Added Antigravity hook parity with Claude Code and Codex for the `agy` CLI,+ the desktop App and the IDE. `install-hooks --agent antigravity-cli` now+ wires the native `SessionStart`, which injects the handoff as an+ `injectSteps` system message that stays in the conversation, where the+ ephemeral message it replaces was dropped after the first turn.+ `PreInvocation` gets its own `pre-invocation` handler: on builds without+ `SessionStart`, the first turn's call stands in for it, once per+ conversation. The native hook now reads each turn's prompts from the+ conversation's own transcript (`transcriptPath`, only under+ `~/.gemini/<app>/brain/<conversationId>/`, no symlinks out of it, 8 MiB per+ hook and a 100 ms filesystem deadline) and records them as user prompts,+ so summaries and handoffs carry them. A timed-out read leaves its cursor+ untouched and retries on the next hook. A `Stop` that finished the turn+ (`NO_TOOL_CALL` or `model_stop`) with+ `fullyIdle: true` writes a turn checkpoint, the path OpenCode 2 uses: the+ summary page and one handoff are refreshed and the conversation stays open,+ so `finalize-session` is no longer needed for normal use. It remains the+ explicit close, hands the baton over without the 10-minute quiet period,+ queues opt-in consolidation, and skips its `history.jsonl` prompt replay+ for a conversation whose prompts were already captured. Rerun+ `install-hooks --agent antigravity-cli --apply` to add `SessionStart`;+ existing native-hook installs get the prompts and checkpoints without it.+ A turn checkpoint never ends a conversation, even a turn with no captured+ prompt or tool call, so a handoff it claimed at start is never offered+ again; the conversation start is claimed atomically, so a concurrent+ `SessionStart` and first `PreInvocation` cannot both claim a handoff;+ prompt ingest keys include the prompt's time and text, so a rewind that+ reuses step numbers keeps its new prompts; and the transcript is opened+ with `O_NOFOLLOW | O_NONBLOCK` and, on Linux, checked against the opened+ descriptor's real path. (#1416)+### Fixed+- Reserved local-embedding capacity for interactive search queries instead of+ allowing concurrent page writes and backfill work to occupy every inference+ slot. Excess queries fall back immediately to non-vector retrieval, and a+ cancelled request retains its slot until its non-cancellable CPU inference+ actually ends. An opt-in real-model contention probe records idle,+ unbounded-load, and bounded-load p50/p95 query latency; hosted embedding+ providers are unchanged.+ - Repaired the exact migration checksum recorded by v2.2.1 for the original+ V62 page-window migration before running strict migration validation. This+ removes the false divergence error on every upgraded-server start while+ keeping unknown migration edits fatal. CI now rejects changes to migration+ files already present on a PR's base branch.+ ([#1443](https://github.com/akitaonrails/ai-memory/issues/1443))+ - Sent `response_format=json_schema` for structured OpenCode Chat Completions+ calls, with the existing tolerant fallback for models that reject it, so+ `memory_query answer=true` no longer receives unstructured prose by default.+ ([#1441](https://github.com/akitaonrails/ai-memory/issues/1441))+ - Preserved third-party commands that share an event matcher group with an+ ai-memory hook when `install-hooks` reapplies or removes its own entry.+ ([#1453](https://github.com/akitaonrails/ai-memory/pull/1453))+ - Accepted a UTF-8 byte-order mark before imported page frontmatter in the+ wiki sync companion.+ ([#1452](https://github.com/akitaonrails/ai-memory/pull/1452))+ - Skipped H1-like comment lines inside fenced code when the importer derives+ page titles, including AgentMemory vault imports.+ ([#1451](https://github.com/akitaonrails/ai-memory/pull/1451))+ - Recognized importer frontmatter whose closing fence is the final line of a+ file without a trailing newline.+ ([#1450](https://github.com/akitaonrails/ai-memory/pull/1450))+ - Encoded spaces as `%20` instead of `+` in importer URL path segments,+ preserving workspace, project, and page names that contain spaces.+ ([#1449](https://github.com/akitaonrails/ai-memory/pull/1449))+ - Recognized exclamation-mark punctuation in short automatic-handoff+ acknowledgments such as `thanks!` and `perfect!`.+ ([#1448](https://github.com/akitaonrails/ai-memory/pull/1448))+ - Treated a blank `session_id` as omitted when starting an automatic+ improvement review, matching the other session-scoped MCP tools.+ ([#1447](https://github.com/akitaonrails/ai-memory/pull/1447))+ - Returned MCP `invalid_params` for caller-supplied invalid page paths, tiers,+ and scopes instead of misreporting them as internal server errors.+ ([#1445](https://github.com/akitaonrails/ai-memory/pull/1445))+ - Parsed an empty Markdown frontmatter block (`---` followed immediately by+ its closing fence) as frontmatter instead of folding it and later thematic+ breaks into the page body. ([#1444](https://github.com/akitaonrails/ai-memory/pull/1444))+ - Kept hook events whose JSON payload contains half of a UTF-16 surrogate pair+ as a `\u` escape, such as tool output cut in the middle of an emoji. Native,+ shell, PowerShell and direct hook clients now share the bounded server-side+ repair, replacing the unpaired escape with U+FFFD instead of dropping the+ whole event.+ ([#1432](https://github.com/akitaonrails/ai-memory/pull/1432))+ - Model-produced page paths are now cleaned of the remaining shapes `ensure_portable`+ refuses, a component ending in a dot or space and a DOS device name like `aux.md`,+ so one such path no longer aborts every page in a consolidation or bootstrap batch.+ ([#1430](https://github.com/akitaonrails/ai-memory/pull/1430))+ - Preserved FTS5 column filters inside parenthesized groups, so queries such+ as `(title:handoff)` no longer broaden into a search for the literal word+ `title` across every indexed field. ([#1442](https://github.com/akitaonrails/ai-memory/pull/1442))+ - Revalidated session-purge tombstones inside the reindex write transaction,+ preventing a queued watcher update from recreating a deleted summary after+ file cleanup failed. Kept surviving manual replacements at the same path+ editable through the watcher (#1439).- Added exact hover timestamps to `/web` page metadata, made the OKF upgradedialog keyboard accessible, and added a labelled main-navigation landmarkwith current-page state and narrow-screen wrapping.diff --cc crates/ai-memory-hooks/src/lib.rsindex 5e3d594a,6be97b1c..7a859941--- a/crates/ai-memory-hooks/src/lib.rs+++ b/crates/ai-memory-hooks/src/lib.rs@@@ -27,7 -27,7 +27,8 @@@ mod brief_tierspub mod capture_policy;pub mod drop_list;mod grants;+pub mod idle_end;+ mod json_repair;pub mod log;pub mod payload;mod recap;@@@ -57,9 -55,7 +58,10 @@@ pub use capture_policy::glob_segment_matches, glob_walk, repository_admits_capture, tool_call_payload, valid_call_id,};pub use drop_list::IngestDropList;+pub use idle_end::{+ IDLE_END_BATCH, IDLE_END_INTERVAL_SECS, IdleEndTickInput, IdleEndTickOutcome, run_idle_end_tick,+};+ pub use json_repair::replace_lone_surrogate_escapes;pub use payload::{HookEnvelope, HookEvent, NOTIFICATION_EXCERPT_MAX_BYTES, POST_COMPACTION_EXCERPT_MAX_BYTES,USER_PROMPT_EXCERPT_MAX_BYTES, agent_from_payload, cap_lifecycle_body_for_client,