Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Merge PR #1071: feat(mcp): let memory_write_page cite a session
AkitaOnRails0d098aa565c6
diff --cc CHANGELOG.mdindex 9f194ee2,9c95ccf9..458e3e35--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -128,64 -125,15 +128,73 @@@ and this project adheres to [Semantic Vor distinct extensions, including backfill).Mixed-source counts preserve scope, session ownership and time-window filters;older servers leave unsupported fields unknown. (#1016)+- Added bounded, sanitized native-record and adapter correlation provenance to+ managed-workstream search/tail results and the CLI's text/JSON output, with+ compatible optional fields and sanitization of legacy provenance on reads. (#1057)+- Added Portuguese history phrases to the existing opt-in session-recall+ router (`[retrieval] query_intent`), including accented and unaccented spellings of+ "última sessão", "onde paramos ontem", and "decisão anterior". Word+ boundaries and explicit history phrases keep technical session queries+ unchanged; routing remains off by default. (#1056)+- Added shared, typed and bounded `entities`, `abstract`, and `relations`+ metadata to MCP `memory_write_page` and admin `/admin/write-page`, plus bounded+ MCP `kind` while preserving the admin's legacy `kind` adapter. Kept existing+ request shapes, entity normalization, authenticated attribution and the wiki+ write pipeline. Documented whole-page replacement, raw-input metadata bounds+ and trimmed relation scope components. (#1055)+- Added structured results for the existing auto-improvement eval execution in+ review reports, staged run metadata, and accepted proposal sidecars, with+ server-generated eval IDs, evaluated request/body digests, checker invocation+ identity, observed success/rejection/failure/timeout, and sanitized bounded+ reasons. Report deserialization discarded supplied eval observations. (#1053)+- Added `grizzybot` as a recognised agent (wire value `grizzybot`, alias+ `grizzy-bot`), so GrizzyBot's lifecycle events are attributed to it instead+ of `other` and its tool calls are captured as closed-schema tool families,+ like other Claude Code-shaped agents. GrizzyBot posts to `/hook` and+ `/mcp` itself, so there is nothing to install. Adds migration V72 to extend+ the `sessions.agent_kind` CHECK constraint. (#1036)+- Added GitHub Copilot CLI as a hooked agent: `install-hooks --agent+ copilot-cli` writes `$COPILOT_HOME/hooks/ai-memory.json` (default+ `~/.copilot/hooks/ai-memory.json`) with Copilot's flat, matcher-less entries+ and PascalCase event names, so Copilot sends its VS Code/Claude-compatible+ payload. Ten events — Claude Code's nine plus `PostToolUseFailure` — with+ native commands enforcing capture exclusions; tool output is read from+ `tool_result.text_result_for_llm` and the outcome from+ `tool_result.result_type`. The `SessionStart` hook delivers the prior+ session's handoff through Copilot's top-level `additionalContext` (ported+ from #1069). There is deliberately no `--scope project`. The bare+ `install-mcp --client copilot` alias keeps meaning VS Code Copilot;+ `install-mcp --client copilot-cli` and `ai-memory run copilot` follow+ separately. (#1040)+- Added GitHub Copilot CLI as a hooked agent: `install-hooks --agent+ copilot-cli` writes `$COPILOT_HOME/hooks/ai-memory.json` (default+ `~/.copilot/hooks/ai-memory.json`) with Copilot's flat, matcher-less entries+ and PascalCase event names, so Copilot sends its VS Code/Claude-compatible+ payload. Ten events — Claude Code's nine plus `PostToolUseFailure` — with+ native commands enforcing capture exclusions; tool output is read from+ `tool_result.text_result_for_llm` and the outcome from+ `tool_result.result_type`. The `SessionStart` hook delivers the prior+ session's handoff through Copilot's top-level `additionalContext` (ported+ from #1069). There is deliberately no `--scope project`. The bare+ `install-mcp --client copilot` alias keeps meaning VS Code Copilot;+ `ai-memory run copilot` follows separately. (#1040)+- Added `install-mcp --client copilot-cli`, which merges ai-memory's remote+ entry (`type: "http"`, `url`, bearer `headers`, `tools: ["*"]`) into the root+ `mcpServers` map of `$COPILOT_HOME/mcp-config.json` (default+ `~/.copilot/mcp-config.json`), preserving other servers. `install-hooks+ --agent copilot-cli` without `--server-url` now reads the server URL and+ bearer back from that entry, and `uninstall` removes it. (#1040)++- Added an optional `session_id` to `memory_write_page`, so an agent can++ write a session's page with its own model and keep it traceable to the++ session. The session must belong to the project the page is written to, and++ the page records it as session evidence. A page that cites a session does++ not overwrite a pinned page. Writing `sessions/<id>.md` also stamps the++ frontmatter `memory_consolidate` writes there (`session_id`, `agent`,++ `consolidated`, plus `consolidated_by: agent`), defaults the tier to++ `episodic`, applies the same duplicate-title suffix, and marks the session's++ queued SessionEnd consolidation job completed. (#1038)### Changed-- The SessionEnd consolidation worker leaves a session page alone when the- agent wrote it through `memory_write_page` and no observation arrived after- it: the page records the session's observation count as- `observation_generation`, and the worker completes a job whose generation- that count reaches instead of replacing the page with the server's- provider. A page written before the session's last observation is- consolidated as before. (#1038)- Documented FutureInfra as an endpoint for the existing `openai-compat`provider. (#1026)- `.github/workflows/nix.yml` builds the flake on `x86_64-linux` for path-@@@ -193,12 -141,6 +202,19 @@@sandbox-parity). The `aarch64-darwin` package smoke and the privilegedNixOS container smoke run only on schedule, `workflow_dispatch`, or a PRlabelled `nix` / `full-ci`. (#989)+- Restricted managed-workstream provenance to scrubbed source labels and an+ explicit scalar metadata allowlist, with 512-byte string bounds. Client event+ ids beginning with `managed-run:` are reserved for server checkpoints and+ extraction-loss annotations. Active-run retries reject changes to an existing+ event's agent, native session or kind, and retain its first indexed content+ and provenance across sanitizer changes. (#1057)++- The SessionEnd consolidation worker leaves a session page alone when the++ agent wrote it through `memory_write_page` and no observation arrived after++ it: the page records the session's observation count as++ `observation_generation`, and the worker completes a job whose generation++ that count reaches instead of replacing the page with the server's++ provider. A page written before the session's last observation is++ consolidated as before. (#1038)### Fixed- Fixed completed retries and no-op session endings advancingdiff --cc crates/ai-memory-mcp/src/server.rsindex e51f35be,120d618e..585917e9--- a/crates/ai-memory-mcp/src/server.rs+++ b/crates/ai-memory-mcp/src/server.rs@@@ -3944,8 -4074,12 +4103,12 @@@ impl AiMemoryServer));}};+ if let Some(session_id) = session_id {+ self.require_session_in_scope(session_id, ws, proj).await?;+ Self::refuse_pinned_page_overwrite(wiki, ws, proj, &path)?;+ }- let mut fm = serde_json::Map::new();+ let mut fm = metadata;if let Some(title) = &args.title {fm.insert("title".into(), serde_json::Value::String(title.clone()));}diff --cc docs/security-boundaries.mdindex b46dfb63,0a118b26..c2270b69--- a/docs/security-boundaries.md+++ b/docs/security-boundaries.md@@@ -74,9 -67,9 +74,10 @@@ boundary not yet built| 14b | Repository identity routing (#708) | `ai-memory-store/src/ops.rs` `resolve_project_by_identity` — one transaction; an identity already on a project is never overwritten; an unclaimed project is claimed only when the capturing user may write it (the choke point's `resolve_project_authz` on the same transaction), otherwise it is returned unclaimed; a different identity under the same name splits into a new project with no shared `repo_path`; `ai-memory-hooks/src/router.rs` `cache_key_for` keys the path cache by identity too; `ai-memory-core/src/repository_identity.rs` strips credentials from remote URLs client-side, and the server accepts only the routing rungs (`explicit`, `git_remote`) from the wire | `tests/suite/identity_resolution.rs` `an_outsider_cannot_take_an_unclaimed_projects_identity` (control: `an_existing_project_is_claimed_in_place`), `two_unrelated_repositories_with_one_folder_name_stay_apart`, `a_created_or_split_project_admits_its_creator`; `router.rs` `one_path_with_two_remotes_is_two_projects`, `two_api_checkouts_with_different_remotes_get_two_projects` (a manifest rung on the wire is ignored); `repository_identity.rs` credential and normalisation tables — the claim guard and the cache key each proven to fail their test when removed | STRONG — first claimant wins: in a restricted workspace a user who creates a project under a remote identity first holds it until root grants others || 14c | Client-supplied event time is bounded and self-scoped (#919) | `ai-memory-hooks/src/payload.rs` `HookEnvelope::occurred_at_micros` — a `/hook` caller's optional `occurred_at` must be `> 0` and `<= now + 5min`; it only sets the caller's *own* admitted session's `started_at`/`ended_at`/`created_at`, never another session/project/user, and the ingest dedup `seen_at`/TTL stays on `now` | `payload.rs` `occurred_at_micros_rejects_a_far_future_timestamp`, `…_rejects_non_positive_values`, `…_rejects_garbage_strings` | MEDIUM — self-scoped numeric bound; no cross-tenant surface (a client already controls its own content) || 14d | `include_related` shows and walks only readable projects (#708) | `ai-memory-store/src/reader.rs` `related_walk(.., viewer)` — both the outgoing and incoming hop queries carry `readable_repository_predicate("pg.project_id", viewer)`, the same far-end filter `page_links` applies, so a page in a project the viewer cannot read is neither returned nor expanded; `ai-memory-mcp/src/server.rs` `memory_read_page` passes `viewer_from_parts`, and the access bump only touches the filtered nodes | `related_walk.rs` `the_walk_hides_and_does_not_cross_projects_the_viewer_cannot_read` (an outgoing and an incoming neighbour in an ungranted restricted project are absent, and so is a granted page reachable only through one; control: a granted restricted project is shown, and no viewer walks the whole graph) — fails with the predicate removed; `ai-memory-mcp` `server.rs` `bob_does_not_see_restricted_pages_through_the_related_walk` (an ungranted user's `memory_read_page{include_related}` omits the restricted page; control: no viewer still reaches it) — fails with `memory_read_page` passing `None` instead of `viewer_from_parts` | STRONG |+ | 14e | `memory_write_page` session evidence cites only a session of the target project (#708) | `ai-memory-mcp/src/server.rs` `memory_write_page` — a `session_id` is accepted only when `require_session_in_scope` resolves the session (where its observations landed, else its session row, as `Consolidator::session_target` does) to the same `(workspace_id, project_id)` the write grant was checked against; unknown and foreign ids get one refusal, so the error is no existence oracle; `scope: "global"` with a `session_id` is refused; `refuse_pinned_page_overwrite` keeps a write that cites a session off a pinned page; only a write to `sessions/<id>.md` reconciles the session's queued SessionEnd job | `server.rs` `write_page_refuses_a_session_from_another_project` (a foreign and an unknown session refused, no evidence row written, the foreign job still queued; control: the project's own session accepted), `session_evidence_write_leaves_a_pinned_page_alone` (control: the same write without `session_id` edits the page), `session_evidence_on_another_path_leaves_the_job_queued`, `write_page_rejects_a_malformed_or_global_session_id` — each of the scope check, the pinned check and the session-page-only reconcile proven to fail its test when removed | STRONG |-| 15 | Agent-archive restore path confinement, resource bounds, and consistency | `ai-memory-cli/src/commands/restore_agents.rs` stages only bounded regular UTF-8 entries; requires a one-to-one manifest/body/checksum/target mapping; allowlists destinations by scope; rejects symlinked descendants; writes each file atomically and rolls back earlier writes after a later failure. `backup_agents.rs` skips direct and directory-root source symlinks, bounds individual assets, and atomically replaces a private archive only after gzip completion | `backup_agents.rs` `restore_agents_rejects_path_traversal`, `restore_agents_rejects_unauthorized_destination_path`, `restore_agents_verifies_sha256_integrity`, `restore_agents_requires_a_complete_one_to_one_manifest`, `restore_agents_rejects_oversized_entries_from_the_header`, `restore_agents_rejects_a_symlinked_destination_parent`, `backup_agents_does_not_follow_config_or_asset_root_symlinks`, and `failed_backup_leaves_the_previous_archive_intact`; `backup_and_restore_agents_round_trip` is the valid-path control; `restore_agents::tests::rollback_removes_new_files_and_restores_overwrites` covers recovery | STRONG |+| 16 | Relay queue identity, migration, and private filesystem state | `companions/ai-memory-relay/src/queue.rs` `Queue::open_inner` performs read-only identity preflight, rechecks under `IMMEDIATE`, commits schema and metadata together; `configure` checks the presence of user objects and rechecks `identity`/`schema_version` metadata on the same connection before every bounded BUSY/LOCKED retry; `fsguard.rs` checks existing paths and creates owner-only files before SQLite opens them | `tests/relay.rs` `a_foreign_database_is_refused_byte_for_byte`, `unknown_schemas_refuse_without_mutation`, `a_foreign_database_with_a_writer_is_refused_before_write_coordination`, `a_foreign_identity_after_preflight_is_refused_without_mutation`, `a_foreign_identity_during_journal_retry_is_refused_without_mutation`, `journal_retry_refuses_a_changed_version_or_empty_database_without_mutation`; controls: `journal_transition_retries_sqlite_lock_without_losing_v1_values`, `fresh_queue_init_and_v1_reopens_work_across_processes`; recovery: `interrupted_and_failed_migrations_roll_back_and_recover`, `journal_reclassification_busy_preserves_committed_migration_and_retries_same_queue`; diagnostics: `classification_read_failures_display_the_sqlite_cause_once_and_preserve_foreign_bytes`; Unix privacy: `the_queue_database_and_its_sidecars_are_owner_only` and the contended migration control | Guard-removal proof covers preflight, locked recheck, and journal retry identity/version checks; full table structure is outside this classification. Windows path rejection is preserved; Windows ACL hardening remains operator-owned |+## Keeping this current (the standing protocol)