Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(profile): keep private profiles in place and document the trust model
AkitaOnRails6ec96121a066
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0eede3af..975160da 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,12 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0shared across every workspace, and off on a multi-user server until`[profile] enabled = true`, which gives each operator a private, restrictedprofile; `share = "global"` or `"workspace"` makes a team profile that is- read-open and write-gated like `_global`. The digest filters entries by the+ read-open and write-gated like `_global`, admits a habit only on evidence+ from at least two operators, and is presented as team defaults. The digest filters entries by thestack the project's activity shows, stays byte-identical between sessions,and gives a project with no memory yet a larger baseline. `memory_write_page`and `memory_delete_page` accept `scope: "profile"`, `memory_query` returnsprofile entries in `global_scope_hits`, a marker's `[profile] contribute` /- `consume` keys opt a project out of contributing or receiving, and+ `consume` keys opt a project out of contributing or receiving (an opt-out+ stays recorded until a marker says otherwise), and`ai-memory profile status | list | show | forget | review | rebuild`inspects and curates it, while `ai-memory profile apply` writes the entriesthat fit a repository into a managed block of its rules file (`--remove`diff --git a/crates/ai-memory-mcp/src/admin.rs b/crates/ai-memory-mcp/src/admin.rsindex 91c23ab9..a50d1b4f 100644--- a/crates/ai-memory-mcp/src/admin.rs+++ b/crates/ai-memory-mcp/src/admin.rs@@ -6118,6 +6118,21 @@ async fn move_project_core());}+ // A private profile is found as `default/_profile.<user id>`; moving it to+ // another workspace would orphan it. (A workspace `_profile` may move with+ // its workspace: it lands in, or merges into, the target's own profile.)+ if req+ .project+ .starts_with(ai_memory_core::profile::USER_PROFILE_PROJECT_PREFIX)+ {+ return Err((+ StatusCode::UNPROCESSABLE_ENTITY,+ Json(serde_json::json!({+ "error": "a private cross-project profile stays in the default workspace and cannot be moved"+ })),+ ));+ }+// Resolve the SOURCE without auto-creating — 404 on a typo.let (src_ws, src_proj) =lookup_ws_proj_no_create(state, &req.from_workspace, &req.project).await?;diff --git a/crates/ai-memory-mcp/tests/suite/admin_move.rs b/crates/ai-memory-mcp/tests/suite/admin_move.rsindex 7916af4d..30a25a9c 100644--- a/crates/ai-memory-mcp/tests/suite/admin_move.rs+++ b/crates/ai-memory-mcp/tests/suite/admin_move.rs@@ -435,6 +435,28 @@ async fn move_project_same_workspace_rejected() {assert_eq!(resp.status(), StatusCode::UNPROCESSABLE_ENTITY);}+/// A private profile (`default/_profile.<user id>`) cannot be moved out of+/// the default workspace: its owner finds it there, so a move would orphan it.+/// The refusal comes before any lookup, so nothing is touched.+#[tokio::test]+async fn move_project_refuses_a_private_profile() {+ let tmp = TempDir::new().unwrap();+ let (state, _store) = make_state(&tmp).await;++ let resp = post(+ state,+ "/admin/move-project",+ json!({+ "from_workspace": "default",+ "project": "_profile.00000000000000000000000000000001",+ "to_workspace": "elsewhere",+ "confirm": true+ }),+ )+ .await;+ assert_eq!(resp.status(), StatusCode::UNPROCESSABLE_ENTITY);+}+/// The move carries the source page's existing embedding over instead of/// recomputing it. Proven by overwriting the source embedding with a/// recognisable marker vector: if the move re-embedded, the destination woulddiff --git a/docs/cross-project-profile.md b/docs/cross-project-profile.mdindex aec1b198..2cd30811 100644--- a/docs/cross-project-profile.md+++ b/docs/cross-project-profile.md@@ -300,14 +300,31 @@ enabled = true # share stays "auto": a private profile per operatorEach operator authenticates with their own API key; their agents write and readtheir own `_profile.<user id>`. Requests made with the root token have no-private profile (there is no database user behind them). For a shared team-profile instead, set `share = "global"` (or `"workspace"`) and grant the-curators `write` on `_global` (or that workspace's `_profile`):+private profile (there is no database user behind them). The `_profile` and+`_profile.*` names are reserved: an operator can name only their own private+profile explicitly (`workspace = "default"`, `project = "_profile.<their id>"`),+so nobody can create another operator's profile ahead of them. Profile projects+cannot be renamed and their access mode is fixed.++For a shared team profile instead, set `share = "global"` (or `"workspace"`)+and grant the curators `write` on `_global` (or that workspace's `_profile`):```bashai-memory user grant --user alice --workspace default --project _global --level write```+**Team-profile trust model.** A team profile reaches every operator's session+start, so the harvester holds it to a higher bar than a personal one: a+statement is admitted only on evidence from **at least two distinct+operators**, on top of `min_projects` (or a general statement). One operator+repeating "always run X before tests" in two open projects is not enough;+`profile review` lists such an entry as waiting for another operator. The+digest is headed **"team defaults"** rather than "your usual choices", so the+agent knows the defaults are shared, not this user's own. Restricted projects+never feed a team profile. Stack entries (which only describe the languages+seen in file names) keep the plain project threshold. Entries written directly+with `scope: "profile"` still need root or a `write` grant on the scope.+## Per-project opt-outsIn a project's `.ai-memory.toml`:@@ -318,10 +335,13 @@ contribute = false # never learn from this project (client or NDA work)consume = false # no profile digest here, and no profile in this project's queries```-Both default to on. The hook clients forward them at session start and the-server records them on the project, so they apply to every harness, and-removing the key from the marker turns the setting back on at the next session-start. A marker that sets only `[profile]` keys is a settings boundary, like one+Both default to on. Whenever a hook client finds the project's marker it sends+both values explicitly (`0` or `1`) at session start, and the server records+them on the project, so they apply to every harness. Removing the key from the+marker turns the setting back on at the next session start. A session start+that sends no value at all (no marker found, an older hook bundle, a client not+yet regenerated) leaves the recorded setting as it is: an opt-out is never+undone by a client that did not say anything. A marker that sets only `[profile]` keys is a settings boundary, like onethat sets `[briefing]` keys: an outer marker's `workspace`/`project` do notapply through it. `ai-memory profile status` lists the projects that opted outof contributing.@@ -365,3 +385,22 @@ of contributing.`min_projects`.- **An entry stopped updating.** It was edited by hand, so the harvester leavesit alone (`profile review` says so). Delete it to hand it back.+- **An opt-out came back on.** Only an explicit value changes it: check that the+ project's marker still says `contribute = false` / `consume = false` and that+ the agent runs in a directory under that marker (`ai-memory profile status`+ lists the projects opted out of contributing).+- **A team entry is "waiting for another operator".** A team profile admits a+ statement only when at least two operators said it (see the trust model+ above). Have a second operator confirm it, or write the entry directly with+ `scope: "profile"` if you hold the grant.+- **A private profile is unreachable after `ai-memory reindex`.** Reindex+ rebuilds a clean database from the wiki, and users are database-only state:+ operators created again get new ids, so an old `_profile.<old id>` project+ belongs to nobody (only root can read it). Its entries are still markdown in+ that project's wiki directory, `wiki/<workspace id>/<project id>/profile/`+ (entries always live in a `profile/` folder, so+ `find <data_dir>/wiki -type d -name profile` lists them). To carry them over, have the+ operator write one entry with `scope: "profile"` (which creates their new+ `_profile.<new id>`), then copy the old `profile/` files into the new+ project's wiki directory while the server runs; the wiki watcher indexes+ them into the new profile.diff --git a/docs/security-boundaries.md b/docs/security-boundaries.mdindex de99a7ea..3075fad0 100644--- a/docs/security-boundaries.md+++ b/docs/security-boundaries.md@@ -25,11 +25,11 @@ boundary not yet built.| 1 | Per-project isolation (3-tuple) | `ai-memory-store/src/scope.rs` `ScopeResolver::resolve_read_args`/`resolve_write_args`, no-create `lookup_existing_scope`; reader queries filter by `(workspace_id, project_id)`; `reader.rs` `sessions_for_scope_filtered` joins only consolidation jobs in the requested workspace and project; `reader.rs` `incremental_pages` filters workspace and project before its keyset and limit; `reader.rs` `session_counts_by_agent` filters mixed-source observations by the requested workspace and project | `store` `scope.rs` read-resolution table tests; `tests/suite/multi_session.rs`; `session_observations.rs` `consolidation_summary_latest_generation_is_scope_and_owner_bound` (a foreign-scope job is absent; the own latest generation and owner controls pass), `incremental_pages_equal_timestamps_cutoff_expiry_and_foreign_scope` (foreign scope absent with a same-scope control), `mixed_capture_count_scopes_observations_and_preserves_owner_and_window` (foreign-scope observations cannot turn an own session into a mixed one; same-scope control can) | STRONG || 1b | Reserved `_global` scope union never leaks a foreign project (#930) | `ai-memory-mcp/src/server.rs` `memory_query` — the union runs for single-project queries (`scopes` empty) and searches **only** `lookup_global_scope`'s reserved `(workspace_id, project_id)`, never an arbitrary project; the double-search guard resolves the *queried* project (named or active) so it can't be tricked into skipping | `server.rs` `global_union_never_leaks_a_foreign_projects_pages` (a third real project's page must not surface via the union; reserved page must), `single_project_query_unions_global_scope_and_multi_scope_skips_it` | STRONG || 1c | Reserved `_global` scope is read-open, write-gated (GHSA-7qj3-7wqw-m5w6) | `ai-memory-store/src/project_authz.rs` `ProjectAuthz::authorize` (a write to `default/_global` needs root or a `write` grant in either access mode; creator ignored) fed by `resolve_project_authz`/`read_project_row` (`reserved_global`, grant read for the global scope regardless of mode); `ai-memory-mcp/src/server.rs` `memory_write_page` resolves `scope: "global"` through `write_target_ids_with_actor` like an explicit `default/_global` | `project_authz.rs` `the_global_scope_admits_writes_only_from_root_or_a_write_grant`; `server.rs` `a_user_without_a_global_grant_cannot_change_the_global_scope` (both spellings and delete refused for an ungranted user and for `_global`'s creator; page survives; reads stay open), `a_global_write_grant_admits_writes_and_the_union_stays_readable` (legitimate control: write grant admits both spellings, another user's restricted-project query still unions the page); bite-checked with the authz rule removed and with the raw `create_global_scope` path restored | STRONG |-| 1d | A private cross-project profile is readable and writable by its operator alone (`[profile] share = "user"`) | `ai-memory-store/src/ops.rs` `initial_access_mode` (a `_profile.<user id>` project is always created `restricted`, creator recorded in the same transaction); `ai-memory-store/src/scope.rs` `lookup_profile_scope` / `create_profile_scope` (the project name derives from the authenticated viewer's id; no database user, no private profile); `ai-memory-mcp/src/server.rs` `profile_target_ids` and the `memory_query` profile union (resolved per viewer through the per-project choke point) | store `integration::profile` `a_private_profile_refuses_every_other_operator` (another operator's read and write by name refused; owner control admitted), `reserved_profile_projects_get_their_fixed_access_modes`; `server.rs` `a_private_profile_is_private_to_its_operator` (no union leak; read, write and delete by name refused; owner and own-profile controls); `multi_session.rs` `two_harnesses_of_one_operator_share_one_private_profile`; both fail with the restricted-mode guard removed | STRONG |+| 1d | A private cross-project profile is readable and writable by its operator alone (`[profile] share = "user"`) | `ai-memory-store/src/ops.rs` `initial_access_mode` (a `_profile.<user id>` project is always created `restricted`, creator recorded in the same transaction); `ai-memory-store/src/scope.rs` `lookup_profile_scope` / `create_profile_scope` (the project name derives from the authenticated viewer's id; no database user, no private profile); `ai-memory-mcp/src/server.rs` `profile_target_ids` and the `memory_query` profile union (resolved per viewer through the per-project choke point); `scope.rs` `refuse_foreign_profile_name` (called by `ScopeResolver` explicit writes and `create_explicit_scope_guarded`: a database user may name only their own `default/_profile.<id>`, so nobody can create another operator's private profile first and lock its owner out); `ops.rs` `rename_project` (no rename onto or away from a profile name); `admin.rs` `handle_project_access` (a profile project's mode is fixed) and `move_project_core` (a private profile cannot leave `default`) | store `integration::profile` `a_private_profile_refuses_every_other_operator` (another operator's read and write by name refused; owner control admitted), `reserved_profile_projects_get_their_fixed_access_modes`; `server.rs` `a_private_profile_is_private_to_its_operator` (no union leak; read, write and delete by name refused; owner and own-profile controls); `multi_session.rs` `two_harnesses_of_one_operator_share_one_private_profile`; both fail with the restricted-mode guard removed; `server.rs` `a_user_cannot_squat_another_operators_private_profile` (another user's explicit write naming the owner's private profile refused and creates nothing; owner's profile and explicit own-name controls; fails with the name guard removed); `ops.rs` `rename_project_refuses_profile_names_both_ways`; `admin.rs` `project_access_sets_the_mode_and_refuses_what_it_must`; `admin_move.rs` `move_project_refuses_a_private_profile` | STRONG || 1e | The shared profile scopes are read-open, write-gated like `_global` | `ai-memory-store/src/project_authz.rs` `is_reserved_global` (a workspace `_profile` joins `default/_global`: on a server that distinguishes operators a write needs root or a `write` grant, creating it grants nothing); `ops.rs` `initial_access_mode` keeps `_profile` open | store `integration::profile` `shared_profiles_are_write_gated_for_database_users` (ungranted user refused for both shares; root and a write grant admitted; reads open); `server.rs` `a_workspace_profile_is_write_gated_and_read_open`; both fail with `_profile` dropped from the gate | STRONG || 1f | Event capture never lands in a profile project, and the sweep keeps them | `ai-memory-hooks/src/router.rs` project resolution refuses `ai_memory_core::profile::is_reserved_scope_project` (`_global`, `_profile`, `_profile.*`) from a directory or a marker override, falling back to the server default; `ops.rs` `sweep_hollow_projects` exempts `_profile` and `_profile.%` | `router.rs` `capture_is_never_attributed_to_a_profile_project` (override and directory spellings refused; ordinary `my_profile` control resolves), fails with the check narrowed to `_global`; store `integration::profile` `the_hollow_project_sweep_keeps_empty_profile_projects` | STRONG |-| 1g | The profile reaches only the sessions it is meant for: off by default on a multi-user server, suppressed by `[profile] consume = false` | `ai_memory_core::profile::ProfileSettings::effective_share` (`enabled = auto` is off once operators are distinguished); `router.rs` `render_requested_profile_digest`; `server.rs` `memory_query` drops `profile/` hits for a project whose stored `profile_consume` is off; `admin_profile.rs` `handle_apply` (`ai-memory profile apply`) returns no lines for such a project and sits behind the root-only `/admin/*` gate on a multi-user server | `router.rs` `a_multi_user_server_has_no_profile_digest_by_default`, `profile_digest_honours_consume_once_per_session_and_the_server_switch`; `server.rs` `the_single_user_profile_lives_in_global_and_honours_consume` (fails with the consume filter removed); `admin_profile_routes.rs` `apply_lists_the_lines_for_a_project_and_honours_consume`, `apply_is_root_only_on_a_multi_user_server` (database user refused, root control admitted); core `profile::tests::effective_share_matrix` | STRONG |-| 1h | The profile learns only from what it may: the user's own prompts and curated pages, from contributing projects, never another operator's words in a private profile and never a restricted project in a shared one; stored text stays data | `ai-memory-store/src/profile.rs` `profile_prompts_since` (only `user-prompt` observations), `profile_harvest_projects` / `profile_candidates` (`profile_contribute = 0` excluded, including candidates recorded before the opt-out); `ai-memory-consolidate/src/profile.rs` `convergence_targets` (a `user` target keeps only candidates whose `contributor` is that operator, from projects the per-project choke point lets them read; a `global`/`workspace` target on an operator-distinguishing server drops restricted projects), `converge` (never rewrites a page without its `generated_by` stamp or whose body changed; `profile_entry_ledger` keeps a forgotten entry out), `classify_batch` / `merge_entry` (sanitized, JSON-encoded input; the evidence quote is always the user's sentence) | consolidate `integration::profile_harvest` `tool_output_is_never_a_candidate`, `an_opted_out_project_is_never_harvested`, `a_private_profile_never_harvests_another_operator`, `a_team_profile_never_harvests_a_restricted_project`, `a_hand_edited_entry_is_never_clobbered`, `a_forgotten_entry_is_not_recreated_until_said_again`, `injected_instructions_stay_data` (each with a legitimate control; each fails with its guard removed); mcp `integration::admin_profile_routes` `review_and_rebuild_are_root_only_on_a_multi_user_server` | STRONG |+| 1g | The profile reaches only the sessions it is meant for: off by default on a multi-user server, suppressed by `[profile] consume = false`, and an opt-out is sticky | `ai_memory_core::profile::ProfileSettings::effective_share` (`enabled = auto` is off once operators are distinguished); `router.rs` `persist_profile_flags` (flags are tri-state: an absent forwarded value keeps the stored one, so a client that sends nothing never undoes an opt-out; every front door sends explicit `0`/`1` once a marker resolved) and `render_requested_profile_digest` (a team profile is headed "team defaults"); `server.rs` `memory_query` drops `profile/` hits for a project whose stored `profile_consume` is off; `admin_profile.rs` `handle_apply` (`ai-memory profile apply`) returns no lines for such a project and sits behind the root-only `/admin/*` gate on a multi-user server | `router.rs` `a_multi_user_server_has_no_profile_digest_by_default`, `profile_digest_honours_consume_once_per_session_and_the_server_switch`, `session_start_records_the_marker_profile_flags` (a session start with no flags after an opt-out keeps the project out of the harvest and the digest; fails when an absent flag defaults to on); `server.rs` `the_single_user_profile_lives_in_global_and_honours_consume` (fails with the consume filter removed); `admin_profile_routes.rs` `apply_lists_the_lines_for_a_project_and_honours_consume`, `apply_is_root_only_on_a_multi_user_server` (database user refused, root control admitted); core `profile::tests::effective_share_matrix` | STRONG |+| 1h | The profile learns only from what it may: the user's own prompts and curated pages, from contributing projects, never another operator's words in a private profile and never a restricted project in a shared one; stored text stays data | `ai-memory-store/src/profile.rs` `profile_prompts_since` (only `user-prompt` observations), `profile_harvest_projects` / `profile_candidates` (`profile_contribute = 0` excluded, including candidates recorded before the opt-out); `ai-memory-consolidate/src/profile.rs` `convergence_targets` (a `user` target keeps only candidates whose `contributor` is that operator, from projects the per-project choke point lets them read; a `global`/`workspace` target on an operator-distinguishing server drops restricted projects), `min_contributors` / `converge` (a team profile admits a statement only on evidence from at least two distinct operators, so one operator cannot plant a default in everyone's session start) (never rewrites a page without its `generated_by` stamp or whose body changed; `profile_entry_ledger` keeps a forgotten entry out), `classify_batch` / `merge_entry` (sanitized, JSON-encoded input; the evidence quote is always the user's sentence) | consolidate `integration::profile_harvest` `tool_output_is_never_a_candidate`, `an_opted_out_project_is_never_harvested`, `a_private_profile_never_harvests_another_operator`, `a_team_profile_never_harvests_a_restricted_project`, `a_team_profile_needs_more_than_one_operator` (one operator in two open projects not admitted; a second operator admits it; fails with the threshold at one), `a_personal_profile_admits_one_operators_habit` (control), `a_hand_edited_entry_is_never_clobbered`, `a_forgotten_entry_is_not_recreated_until_said_again`, `injected_instructions_stay_data` (each with a legitimate control; each fails with its guard removed); mcp `integration::admin_profile_routes` `review_and_rebuild_are_root_only_on_a_multi_user_server` | STRONG || 2 | Workspace isolation | same as #1; same-named project → distinct ids per workspace | `scope.rs` cross-workspace resolution rows; `multi_scope` dedup/validate | STRONG || 2b | Managed-workstream discovery stays checkout-local, including pagination | `ai-memory-workstream/src/repository.rs` `inspect_repository_fingerprints` shares the launch identity derivation without checkpoint scans; `ai-memory-cli/src/commands/resume.rs` `candidates_for_checkout` queries only the cwd, never registry links; the explicit `--all` walk (`candidates_across_checkouts`) lists each linked checkout through its own fingerprint-scoped request and applies `--workspace` before any request; `ai-memory-hooks/src/workstream.rs` `list_recent_workstreams` resolves an authorized explicit scope on every page; `ai-memory-store/src/workstream.rs` `list_recent` applies workspace/project/repository/worktree predicates before `LIMIT`/`OFFSET` | `resume.rs` `resume_lists_all_current_checkout_rows_not_registered_foreign_checkouts` (same scope/remote foreign checkout refused, 125 local rows visible), `empty_current_checkout_does_not_fall_back_to_the_registry`, `resume_all_walks_every_linked_checkout_and_honours_the_workspace_filter` (a foreign workspace filter sends no request; the default picker still ignores the registry); `workstream.rs` `recent_workstream_pages_reach_older_rows_without_crossing_checkout_or_scope` (foreign repo, worktree, project and workspace excluded on every page; 105 legitimate rows reach the client, huge offsets return nothing); store `recent_workstreams_are_checkout_local_and_include_linked_harnesses` (page two keeps native harness links); `repository.rs` `reports_origin_push_url_and_linked_worktree` verifies lightweight/full fingerprint parity and distinct worktree keys; CLI `resume_yolo_displays_picker_without_scanning_git_status` verifies listing skips status scans | STRONG || 3 | Multi-user auth ladder | `ai-memory-core/src/actor.rs` `AuthLevel::authorize`; `ai-memory-mcp/src/auth.rs` middleware; `admin.rs` `require_root_for_multiuser_admin` / `require_root`; `identity.rs` authorizes `NormalRead` behind the same machine bearer middleware as MCP; `serve.rs` mounts API-only and web+API protected routers behind `require_dual_auth` | `admin.rs` `multiuser_admin_routes_reject_db_user_tier` / `…reject_anonymous` / `create_user_as_user_tier_returns_403`; `auth.rs` unknown-bearer 401; `actor.rs` `skip_admission_chain_rejects_db_users`; `identity.rs` `identity_real_auth_isolates_users_root_and_revoked_keys`, `identity_anonymous_ignores_forged_headers_and_proxy_qualifies_oidc` (distinct users and root, invalid/revoked keys, forged headers, anonymous control); `serve.rs` `api_only_mode_keeps_data_authenticated_and_web_absent` (anonymous API read refused, authenticated control admitted, browser route absent; #986) | STRONG |