Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(profile): skip ADR metadata fields when harvesting a page statement
Felipe Neves Ricardoddea1bbabadd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b43a8edc..5ab214a2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0the placeholder id `empty-state-draft` and no workspace, and each launchappended another observation to that one empty session. The server nowacknowledges and drops that placeholder.+- 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). (#1175)- Fixed `install-mcp --client claude-desktop` refusing to run on Linux:Anthropic ships Claude Desktop for Linux as a beta, and the command nowwrites `$XDG_CONFIG_HOME/Claude/claude_desktop_config.json` (defaultdiff --git a/crates/ai-memory-consolidate/tests/suite/profile_harvest.rs b/crates/ai-memory-consolidate/tests/suite/profile_harvest.rsindex a7565ac3..605c0bd4 100644--- a/crates/ai-memory-consolidate/tests/suite/profile_harvest.rs+++ b/crates/ai-memory-consolidate/tests/suite/profile_harvest.rs@@ -379,6 +379,101 @@ async fn tool_output_is_never_a_candidate() {assert!(statements.iter().any(|s| s.contains("pnpm")));}+/// An ADR's metadata fields (`**Status:** Accepted`, `**Date:**`) are never+/// harvested as the page's statement, so `profile review` does not list them+/// as habits waiting for promotion. The decision itself is the candidate, and+/// a habit said in two projects is still admitted (controls).+#[tokio::test]+async fn page_metadata_fields_are_never_candidates() {+ let fx = fixture().await;+ let alpha = project(&fx, "alpha").await;+ let beta = project(&fx, "beta").await;+ for (proj, slug, context) in [+ (alpha, "wal-mode", "Readers blocked the writer under load."),+ (+ beta,+ "queue-backend",+ "Jobs were lost when the broker restarted.",+ ),+ ] {+ fx.wiki+ .write_page(WritePageRequest {+ workspace_id: fx.ws,+ project_id: proj,+ path: PagePath::new(format!("decisions/{slug}.md")).unwrap(),+ frontmatter: serde_json::json!({}),+ body: format!(+ "# {slug}\n\n\+ **Status:** Accepted\n\+ **Date:** 2026-10-01\n\+ **Deciders:** Alice, Bob\n\n\+ ## Context\n\n\+ {context}\n\n\+ ## Decision\n\n\+ We adopt it for every store.\n"+ ),+ tier: Tier::Semantic,+ pinned: false,+ title: None,+ admission_ctx: None,+ author_id: None,+ actor: ActorContext::anonymous(),+ evidence: Vec::new(),+ })+ .await+ .unwrap();+ }+ prompt(+ &fx,+ alpha,+ "I prefer small focused commits over big ones.",+ 1,+ )+ .await;+ prompt(+ &fx,+ beta,+ "I prefer small focused commits over big ones!",+ 3,+ )+ .await;++ let report = pass(&fx, &single_user()).await;+ let statements = candidate_statements(&fx);+ for field in ["Status", "Date", "Deciders", "Accepted"] {+ assert!(+ statements.iter().all(|s| !s.contains(field)),+ "a metadata field became a candidate: {statements:?}"+ );+ }+ assert!(+ statements+ .iter()+ .any(|s| s == "Readers blocked the writer under load."),+ "{statements:?}"+ );++ let review = ai_memory_consolidate::profile::profile_review(+ &fx.store.reader,+ &single_user(),+ None,+ None,+ )+ .await+ .unwrap();+ assert!(+ review+ .waiting+ .iter()+ .all(|w| !w.statement.contains("Accepted")),+ "{:?}",+ review.waiting+ );+ let pages = profile_pages(&fx, "_global");+ assert_eq!(pages.len(), 1, "{report:?} {pages:?}");+ assert!(pages[0].1.contains("small focused commits"), "{pages:?}");+}+/// `[profile] contribute = false` keeps a project out entirely; the same/// words in a contributing project are harvested (control).#[tokio::test]diff --git a/crates/ai-memory-core/src/profile.rs b/crates/ai-memory-core/src/profile.rsindex e6f87601..3d8d83de 100644--- a/crates/ai-memory-core/src/profile.rs+++ b/crates/ai-memory-core/src/profile.rs@@ -538,9 +538,44 @@ impl ProfileEntry {fn first_prose_line(body: &str) -> Option<String> {body.lines().map(str::trim)- .find(|line| !line.is_empty() && !line.starts_with('#') && *line != "---")- .map(|line| line.trim_start_matches(['-', '*', ' ']).trim().to_owned())- .filter(|line| !line.is_empty())+ .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()+ })+ .find(|line| !line.is_empty())+}++/// The most words a field label has (`Status`, `Decision date`).+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.+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.+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(['.', '!'])+ })+}++/// The value of a line that opens with an emphasized label, `None` for any+/// other line.+fn field_value(line: &str) -> Option<&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())+ })}fn collapse_whitespace(text: &str) -> String {@@ -972,6 +1007,28 @@ mod tests {assert_eq!(e.applies_to, vec!["rust"]);assert!(e.enforced_by);+ // An ADR opens with metadata fields; the statement is the first+ // sentence after them, and a labelled sentence keeps its words.+ let e = ProfileEntry::from_page(+ "decisions/wal.md",+ "Use WAL mode",+ "# Use WAL mode\n\n**Status:** Accepted\n**Date**: 2026-10-01\n\+ - **Deciders:** Alice, Bob\n**Context:**\n\n\+ **Decision:** Every store opens SQLite in WAL mode.\n",+ &serde_json::Value::Null,+ )+ .unwrap();+ assert_eq!(e.statement, "Every store opens SQLite in WAL mode.");+ // Nothing but metadata: the title states the page.+ let e = ProfileEntry::from_page(+ "decisions/wal.md",+ "Use WAL mode",+ "**Status:** Accepted\n**Date:** 2026-10-01\n\n## Context\n",+ &serde_json::Value::Null,+ )+ .unwrap();+ assert_eq!(e.statement, "Use WAL mode");+let long = "x".repeat(600);let e =ProfileEntry::from_page("profile/a.md", "A", &long, &serde_json::Value::Null).unwrap();@@ -979,6 +1036,30 @@ mod tests {assert_eq!(e.category(), "");}+ #[test]+ fn metadata_fields_are_told_from_sentences() {+ for line in [+ "**Status:** Accepted",+ "Status:** Accepted",+ "**Date**: 2026-10-01",+ "- **Deciders:** Alice, Bob",+ "__Owner:__ platform team",+ "**Context:**",+ ] {+ assert!(is_metadata_field(line), "{line}");+ }+ for line in [+ "**Rule:** Never use npm.",+ "**Decision:** Every store opens SQLite in WAL mode",+ "Always use pnpm for installs.",+ "Use **pnpm**: it is faster.",+ "Status: Accepted",+ "Note: see the ADR for details.",+ ] {+ assert!(!is_metadata_field(line), "{line}");+ }+ }+#[test]fn digest_orders_by_category_then_path_and_is_byte_stable() {let entries = vec![diff --git a/docs/cross-project-profile.md b/docs/cross-project-profile.mdindex b8a40151..7745d56b 100644--- a/docs/cross-project-profile.md+++ b/docs/cross-project-profile.md@@ -175,7 +175,9 @@ is new since the last one.task brief or a pasted review, not you. Your verbatim words are kept asevidence.- **Curated pages** of the project: `_rules/`, `decisions/`, `gotchas/` and- `procedures/`.+ `procedures/`. A page contributes its `summary`, or else its first line of+ prose; metadata fields such as `**Status:** Accepted` or `**Date:**` at the+ top of an ADR are skipped.- **Stack signals**: the languages the project's activity shows (from filenames such as `Cargo.toml` and source extensions).