Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(profile): accept applies_to/enforced_by under scope "global"
AkitaOnRailsa8de64004181
diff --git a/crates/ai-memory-core/src/page.rs b/crates/ai-memory-core/src/page.rsindex 0d06dcd5..f6f7b576 100644--- a/crates/ai-memory-core/src/page.rs+++ b/crates/ai-memory-core/src/page.rs@@ -344,8 +344,10 @@ impl PageWriteMetadata {/// digest never reads, where the caller's intent would silently do nothing:/// one outside `profile/`, or one written to a project that cannot hold a/// profile. `profile_scope` says whether the write targets the profile-/// (`scope: "profile"`, or `_global` or a reserved profile project by name);-/// the caller decides it from the request, before any scope is created.+/// (`scope: "profile"` or `"global"`, or `_global` or a reserved profile+/// project by name); the caller decides it from the request, before any+/// scope is created. It looks at the project name only, not the workspace+/// or share mode, so it errs lenient.////// # Errors/// Returns `MalformedRecord` naming the first such key.diff --git a/crates/ai-memory-mcp/src/server.rs b/crates/ai-memory-mcp/src/server.rsindex 01505801..b2acbfc1 100644--- a/crates/ai-memory-mcp/src/server.rs+++ b/crates/ai-memory-mcp/src/server.rs@@ -4347,16 +4347,18 @@ impl AiMemoryServer {path.ensure_portable().map_err(|e| McpError::internal_error(format!("invalid path: {e}"), None))?;let path = self.place_slot_write(path, &parts).await?;- let profile_scope = args.scope.as_deref().map(str::trim) == Some("profile");+ let scope = args.scope.as_deref().map(str::trim);+ let profile_scope = scope == Some("profile");let path = if profile_scope {profile_page_path(path)?} else {path};+ // `scope: "global"` writes `default/_global`, the single-user profile.ai_memory_core::page::ensure_profile_metadata_placement(&metadata,&path,- profile_scope+ matches!(scope, Some("profile" | "global"))|| args.project.as_deref()@@ -15737,6 +15739,29 @@ mod tests {"refused before the scope is created");+ // `scope: "global"` writes `default/_global`, the single-user+ // profile, so a `profile/` path there is a profile entry.+ let mut global_entry = with_fields(&["rust"], None);+ global_entry.scope = Some("global".into());+ global_entry.path = "profile/style/x.md".into();+ server+ .memory_write_page(+ Parameters(global_entry),+ OptionalParts(test_parts_default()),+ )+ .await+ .expect("scope global takes applies_to on a profile/ path");+ let global_path = PagePath::new("profile/style/x.md").unwrap();+ let md = wiki.read_page(ws, global, &global_path).unwrap();+ assert_eq!(md.frontmatter["applies_to"], serde_json::json!(["rust"]));+ let mut global_note = with_fields(&["rust"], None);+ global_note.scope = Some("global".into());+ global_note.path = "notes/x.md".into();+ server+ .memory_write_page(Parameters(global_note), OptionalParts(test_parts_default()))+ .await+ .expect_err("scope global still refuses applies_to outside profile/");+server.memory_write_page(Parameters(with_fields(&[], None)),