Skip to content

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

Rust

fix(profile): judge page metadata by a closed ADR label list

AkitaOnRailsa70781197365
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bedf9cc0..4a4dc132 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,9 +21,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed `profile review` listing page metadata such as `Status:** Accepted` as
habits waiting for promotion: a curated page's statement was its first line
of prose, which on an ADR-style page is a `**Status:** Accepted` or
- `**Date:**` field. Statements now skip those fields (a labelled sentence
- such as `**Decision:** …` keeps its words), and fields harvested before the
- fix no longer reach `profile review` or the profile. (#1175)
+ `**Date:**` field. Statements now skip fields with an ADR metadata label
+ (Status, Date, Deciders, Supersedes and the like) whatever their value; a
+ labelled rule such as `**Package manager:** pnpm` is still a statement.
+ Fields harvested before the fix no longer reach `profile review`; an entry already admitted to the
+ profile stays until `ai-memory profile forget`. (#1175)
- Fixed `install-mcp --client claude-desktop` refusing to run on Linux:
Anthropic ships Claude Desktop for Linux as a beta, and the command now
writes `$XDG_CONFIG_HOME/Claude/claude_desktop_config.json` (default
diff --git a/crates/ai-memory-consolidate/src/profile.rs b/crates/ai-memory-consolidate/src/profile.rs
index 9dc286fa..7a6536ff 100644
--- a/crates/ai-memory-consolidate/src/profile.rs
+++ b/crates/ai-memory-consolidate/src/profile.rs
@@ -2502,6 +2502,17 @@ mod tests {
let waiting: Vec<&str> = plan.waiting.iter().map(|w| w.statement.as_str()).collect();
assert_eq!(waiting, ["Every store opens SQLite in WAL mode."]);
+ // The label decides, not the value's length: a long ADR template
+ // field is dropped, a terse labelled rule waits.
+ let template = page(
+ "alpha",
+ "Status:** accepted <!-- proposed | accepted | superseded by [[decisions/other]] -->",
+ );
+ let rule = page("beta", "Package manager:** pnpm");
+ let plan = converge(&[&template, &rule], &[], &[], 2, 1);
+ let waiting: Vec<&str> = plan.waiting.iter().map(|w| w.statement.as_str()).collect();
+ assert_eq!(waiting, ["Package manager:** pnpm"]);
+
// The same words from a prompt are not a page field and stay.
let said = row(
"alpha",
diff --git a/crates/ai-memory-core/src/profile.rs b/crates/ai-memory-core/src/profile.rs
index b9c69de8..743ad25d 100644
--- a/crates/ai-memory-core/src/profile.rs
+++ b/crates/ai-memory-core/src/profile.rs
@@ -540,44 +540,71 @@ fn first_prose_line(body: &str) -> Option<String> {
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with('#') && *line != "---")
.filter(|line| !is_metadata_field(line))
- .map(|line| {
- field_value(line)
- .unwrap_or_else(|| line.trim_start_matches(['-', '*', ' ']).trim())
- .to_owned()
+ .map(|line| match labelled_field(line) {
+ Some((_, value)) if is_sentence(value) => value.to_owned(),
+ Some((label, value)) if !value.is_empty() => format!("{label}: {value}"),
+ Some(_) => String::new(),
+ None => line.trim_start_matches(['-', '*', ' ']).trim().to_owned(),
})
.find(|line| !line.is_empty())
}
-/// The most words a field label has (`Status`, `Decision date`).
+/// The most words a field label has (`Status`, `Package manager`).
const FIELD_LABEL_MAX_WORDS: usize = 3;
-/// The most words a metadata value has (`Accepted`, `2026-10-01`,
-/// `Alice, Bob`); a longer value is a sentence.
+/// The most words a terse field value has (`pnpm`, `run cargo fmt`). A
+/// longer value is a sentence that reads on its own without its label.
const FIELD_VALUE_MAX_WORDS: usize = 4;
-/// Whether `line` is a page metadata field: an emphasized label with a short
-/// value, the way ADR-style pages open (`**Status:** Accepted`,
-/// `**Date**: 2026-10-01`). It describes the page, so it is never the page's
-/// statement. The form with the leading `**` already trimmed
-/// (`Status:** Accepted`), which candidates harvested before this check
-/// still carry, counts too.
+/// The labels ADR templates (MADR, Nygard, ai-memory's own durable-pages
+/// skill) put on a page's metadata, lowercase.
+const ADR_METADATA_LABELS: &[&str] = &[
+ "status",
+ "date",
+ "deciders",
+ "decision-makers",
+ "authors",
+ "author",
+ "owner",
+ "owners",
+ "supersedes",
+ "superseded by",
+ "consulted",
+ "informed",
+ "tags",
+ "last updated",
+ "reviewers",
+];
+
+/// Whether `line` is a page metadata field such as `**Status:** Accepted`
+/// or `**Date**: 2026-10-01`. It describes the page, so it is never the
+/// page's statement. Only the label decides: a terse labelled rule
+/// (`**Package manager:** pnpm`) is a statement, and a metadata value of
+/// any length (`**Status:** accepted <!-- proposed | ... -->`) is not. The
+/// form with the leading `**` already trimmed (`Status:** Accepted`), which
+/// candidates harvested before this check still carry, counts too.
#[must_use]
pub fn is_metadata_field(line: &str) -> bool {
- field_value(line).is_some_and(|value| {
- value.split_whitespace().count() <= FIELD_VALUE_MAX_WORDS && !value.ends_with(['.', '!'])
+ labelled_field(line).is_some_and(|(label, _)| {
+ let label = collapse_whitespace(label).to_ascii_lowercase();
+ ADR_METADATA_LABELS.contains(&label.as_str())
})
}
-/// The value of a line that opens with an emphasized label, `None` for any
-/// other line.
-fn field_value(line: &str) -> Option<&str> {
+fn is_sentence(value: &str) -> bool {
+ value.split_whitespace().count() > FIELD_VALUE_MAX_WORDS || value.ends_with(['.', '!'])
+}
+
+/// The label and value of a line that opens with an emphasized label,
+/// `None` for any other line.
+fn labelled_field(line: &str) -> Option<(&str, &str)> {
let rest = line.trim().trim_start_matches(['-', '*', '_', ' ']);
[":**", "**:", ":__", "__:"].iter().find_map(|close| {
let (label, value) = rest.split_once(close)?;
let words = label.split_whitespace().count();
let plain = !label.contains(['*', '_', '.', '!', '?', ':', '`']);
((1..=FIELD_LABEL_MAX_WORDS).contains(&words) && plain)
- .then(|| value.trim_start_matches(['*', '_']).trim())
+ .then(|| (label.trim(), value.trim_start_matches(['*', '_']).trim()))
})
}
@@ -1031,6 +1058,37 @@ mod tests {
)
.unwrap();
assert_eq!(e.statement, "Use WAL mode");
+ // ai-memory's own ADR template: the field carries an HTML comment
+ // listing the allowed values.
+ let e = ProfileEntry::from_page(
+ "decisions/wal.md",
+ "Use WAL mode",
+ "# Use WAL mode\n\n**Status:** accepted \
+ <!-- proposed | accepted | superseded by [[decisions/other]] -->\n\n\
+ ## Context\n\nReaders blocked the writer under load.\n",
+ &serde_json::Value::Null,
+ )
+ .unwrap();
+ assert_eq!(e.statement, "Readers blocked the writer under load.");
+ // A terse labelled rule is the rule, not page metadata.
+ for (body, statement) in [
+ ("**Package manager:** pnpm", "Package manager: pnpm"),
+ ("- **Always:** run cargo fmt", "Always: run cargo fmt"),
+ ("**Rule:** Never use npm", "Rule: Never use npm"),
+ (
+ "**Prefer:** composition over inheritance",
+ "Prefer: composition over inheritance",
+ ),
+ ] {
+ let e = ProfileEntry::from_page(
+ "_rules/tooling.md",
+ "Tooling",
+ &format!("# Tooling\n\n{body}\n"),
+ &serde_json::Value::Null,
+ )
+ .unwrap();
+ assert_eq!(e.statement, statement, "{body}");
+ }
let long = "x".repeat(600);
let e =
@@ -1047,7 +1105,10 @@ mod tests {
"**Date**: 2026-10-01",
"- **Deciders:** Alice, Bob",
"__Owner:__ platform team",
- "**Context:**",
+ "**Status:** accepted <!-- proposed | accepted | superseded by [[decisions/other]] -->",
+ "Status:** accepted <!-- proposed | accepted | superseded by [[decisions/other]] -->",
+ "**Last updated:** 2026-10-01, after the platform team reviewed it.",
+ "**SUPERSEDED BY:** decisions/queue-v2",
] {
assert!(is_metadata_field(line), "{line}");
}
@@ -1058,6 +1119,12 @@ mod tests {
"Use **pnpm**: it is faster.",
"Status: Accepted",
"Note: see the ADR for details.",
+ "**Context:**",
+ "**Package manager:** pnpm",
+ "Package manager:** pnpm",
+ "- **Always:** run cargo fmt",
+ "**Rule:** Never use npm",
+ "**Prefer:** composition over inheritance",
] {
assert!(!is_metadata_field(line), "{line}");
}
diff --git a/docs/security-boundaries.md b/docs/security-boundaries.md
index 5360eeb3..f44a5f9f 100644
--- a/docs/security-boundaries.md
+++ b/docs/security-boundaries.md
@@ -29,7 +29,7 @@ boundary not yet built.
| 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`, 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 |
+| 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`, `page_metadata_fields_are_never_candidates`, consolidate `profile::tests::a_stored_page_metadata_field_is_not_a_waiting_habit` (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 |