Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
Format managed routing changes
Thiago Silva17615e3a2678
diff --git a/crates/ai-memory-cli/src/commands/install_skills.rs b/crates/ai-memory-cli/src/commands/install_skills.rsindex a17eeeaa..a864dfb7 100644--- a/crates/ai-memory-cli/src/commands/install_skills.rs+++ b/crates/ai-memory-cli/src/commands/install_skills.rs@@ -75,8 +75,12 @@ fn resolve_target_roots(}let roots = match args.agent {- InstallSkillsAgent::ClaudeCode => vec![agent_root(args.scope, SkillRootKind::Claude, cwd, home)?],- InstallSkillsAgent::Agents => vec![agent_root(args.scope, SkillRootKind::Agents, cwd, home)?],+ InstallSkillsAgent::ClaudeCode => {+ vec![agent_root(args.scope, SkillRootKind::Claude, cwd, home)?]+ }+ InstallSkillsAgent::Agents => {+ vec![agent_root(args.scope, SkillRootKind::Agents, cwd, home)?]+ }InstallSkillsAgent::Both => vec![agent_root(args.scope, SkillRootKind::Claude, cwd, home)?,agent_root(args.scope, SkillRootKind::Agents, cwd, home)?,@@ -100,7 +104,9 @@ fn agent_root() -> Result<PathBuf> {let base = match scope {InstallSkillsScope::Project => cwd,- InstallSkillsScope::Global => home.context("could not locate $HOME for global skill install")?,+ InstallSkillsScope::Global => {+ home.context("could not locate $HOME for global skill install")?+ }};let agent_dir = match kind {SkillRootKind::Claude => ".claude",@@ -327,6 +333,10 @@ mod tests {.find(|report| report.path == unmanaged).expect("retrieval report");assert_eq!(overwritten.outcome, ApplyOutcome::Updated);- assert!(fs::read_to_string(unmanaged).unwrap().contains(MANAGED_MARKER));+ assert!(+ fs::read_to_string(unmanaged)+ .unwrap()+ .contains(MANAGED_MARKER)+ );}}diff --git a/crates/ai-memory-cli/src/commands/mod.rs b/crates/ai-memory-cli/src/commands/mod.rsindex 3ede65ae..71493aa8 100644--- a/crates/ai-memory-cli/src/commands/mod.rs+++ b/crates/ai-memory-cli/src/commands/mod.rs@@ -25,8 +25,8 @@ pub mod hook_spool;pub mod init;pub mod install_hooks;pub mod install_instructions;-pub mod install_skills;pub mod install_mcp;+pub mod install_skills;pub mod lint;pub mod llm_test;pub mod move_project;diff --git a/crates/ai-memory-cli/src/commands/uninstall.rs b/crates/ai-memory-cli/src/commands/uninstall.rsindex 0e36312f..423a6563 100644--- a/crates/ai-memory-cli/src/commands/uninstall.rs+++ b/crates/ai-memory-cli/src/commands/uninstall.rs@@ -235,7 +235,6 @@ fn build_plan(args: &UninstallArgs) -> anyhow::Result<Vec<PlannedChange>> {}}-// ---- Managed Agent Skills (project + global roots) ----if want(crate::cli::UninstallOnly::Skills) {let cwd = std::env::current_dir().context("getting CWD for skill removal")?;diff --git a/crates/ai-memory-cli/tests/install_instructions.rs b/crates/ai-memory-cli/tests/install_instructions.rsindex 578f320f..d1e56dd2 100644--- a/crates/ai-memory-cli/tests/install_instructions.rs+++ b/crates/ai-memory-cli/tests/install_instructions.rs@@ -76,7 +76,11 @@ fn skill_conflict_preflight_keeps_instruction_file_unchanged_until_force() {let updated = fs::read_to_string(&target).unwrap();assert!(updated.contains(MARKER_START));assert!(updated.contains("# Project"));- assert!(fs::read_to_string(&unmanaged).unwrap().contains(MANAGED_MARKER));+ assert!(+ fs::read_to_string(&unmanaged)+ .unwrap()+ .contains(MANAGED_MARKER)+ );assert!(project.path()@@ -90,7 +94,11 @@ fn no_skills_writes_only_instruction_snippet() {let project = tempfile::tempdir().unwrap();let home = tempfile::tempdir().unwrap();- let output = run_ai_memory(project.path(), home.path(), &["install-instructions", "--no-skills"]);+ let output = run_ai_memory(+ project.path(),+ home.path(),+ &["install-instructions", "--no-skills"],+ );assert_success(output);let claude_md = fs::read_to_string(project.path().join("CLAUDE.md")).unwrap();@@ -105,7 +113,11 @@ fn print_shows_snippet_and_skill_plan_without_mutating() {let project = tempfile::tempdir().unwrap();let home = tempfile::tempdir().unwrap();- let output = run_ai_memory(project.path(), home.path(), &["install-instructions", "--print"]);+ let output = run_ai_memory(+ project.path(),+ home.path(),+ &["install-instructions", "--print"],+ );let stdout = assert_success(output);assert!(stdout.contains("# Would write into:"));@@ -147,7 +159,12 @@ fn inferred_instruction_targets_select_matching_skill_agents() {let output = run_ai_memory(project.path(), home.path(), &["install-instructions"]);assert_success(output);- assert!(project.path().join(".agents/skills/ai-memory-retrieval/SKILL.md").exists());+ assert!(+ project+ .path()+ .join(".agents/skills/ai-memory-retrieval/SKILL.md")+ .exists()+ );assert!(!project.path().join(".claude/skills").exists());let both_project = tempfile::tempdir().unwrap();@@ -155,11 +172,25 @@ fn inferred_instruction_targets_select_matching_skill_agents() {fs::write(both_project.path().join("CLAUDE.md"), "# Claude\n").unwrap();fs::write(both_project.path().join("AGENTS.md"), "# Agents\n").unwrap();- let output = run_ai_memory(both_project.path(), both_home.path(), &["install-instructions"]);+ let output = run_ai_memory(+ both_project.path(),+ both_home.path(),+ &["install-instructions"],+ );assert_success(output);- assert!(both_project.path().join(".claude/skills/ai-memory-retrieval/SKILL.md").exists());- assert!(both_project.path().join(".agents/skills/ai-memory-retrieval/SKILL.md").exists());+ assert!(+ both_project+ .path()+ .join(".claude/skills/ai-memory-retrieval/SKILL.md")+ .exists()+ );+ assert!(+ both_project+ .path()+ .join(".agents/skills/ai-memory-retrieval/SKILL.md")+ .exists()+ );}#[test]@@ -182,7 +213,11 @@ fn explicit_skill_scope_and_agent_override_instruction_target_inference() {);assert_success(output);- assert!(home.path().join(".claude/skills/ai-memory-retrieval/SKILL.md").exists());+ assert!(+ home.path()+ .join(".claude/skills/ai-memory-retrieval/SKILL.md")+ .exists()+ );assert!(!home.path().join(".agents/skills").exists());assert!(!project.path().join(".claude/skills").exists());assert!(!project.path().join(".agents/skills").exists());@@ -195,7 +230,11 @@ fn explicit_skill_overrides_win_over_instruction_target_inference() {let custom_root = project.path().join("custom-skills");let unmanaged = custom_root.join("ai-memory-retrieval/SKILL.md");fs::create_dir_all(unmanaged.parent().unwrap()).unwrap();- fs::write(&unmanaged, "---\nname: ai-memory-retrieval\n---\nuser skill\n").unwrap();+ fs::write(+ &unmanaged,+ "---\nname: ai-memory-retrieval\n---\nuser skill\n",+ )+ .unwrap();let custom_root_arg = custom_root.to_str().unwrap();let output = run_ai_memory(@@ -234,7 +273,11 @@ fn legacy_long_marker_block_rerun_upgrades_in_place_to_slim_snippet() {);fs::write(project.path().join("CLAUDE.md"), original).unwrap();- let output = run_ai_memory(project.path(), home.path(), &["install-instructions", "--no-skills"]);+ let output = run_ai_memory(+ project.path(),+ home.path(),+ &["install-instructions", "--no-skills"],+ );assert_success(output);let updated = fs::read_to_string(project.path().join("CLAUDE.md")).unwrap();@@ -243,6 +286,12 @@ fn legacy_long_marker_block_rerun_upgrades_in_place_to_slim_snippet() {assert!(updated.contains("Use the installed ai-memory Agent Skills"));assert!(!updated.contains("When to reach for each tool"));assert!(!updated.contains("|User says / situation|Tool|"));- assert_eq!(updated.lines().filter(|line| *line == MARKER_START).count(), 1);- assert_eq!(updated.lines().filter(|line| *line == MARKER_END).count(), 1);+ assert_eq!(+ updated.lines().filter(|line| *line == MARKER_START).count(),+ 1+ );+ assert_eq!(+ updated.lines().filter(|line| *line == MARKER_END).count(),+ 1+ );}diff --git a/crates/ai-memory-cli/tests/install_skills.rs b/crates/ai-memory-cli/tests/install_skills.rsindex 95318889..bc41f09c 100644--- a/crates/ai-memory-cli/tests/install_skills.rs+++ b/crates/ai-memory-cli/tests/install_skills.rs@@ -27,7 +27,17 @@ fn install_skills_print_outputs_plan_without_mutating_target_dir() {String::from_utf8_lossy(&output.stderr));let stdout = String::from_utf8(output.stdout).unwrap();- assert!(stdout.contains(&target.join("ai-memory-retrieval/SKILL.md").display().to_string()));+ assert!(+ stdout.contains(+ &target+ .join("ai-memory-retrieval/SKILL.md")+ .display()+ .to_string()+ )+ );assert!(stdout.contains("<!-- ai-memory-managed: routing-skill -->"));- assert!(!target.exists(), "--print must not create the target directory");+ assert!(+ !target.exists(),+ "--print must not create the target directory"+ );}diff --git a/crates/ai-memory-cli/tests/uninstall.rs b/crates/ai-memory-cli/tests/uninstall.rsindex eaaf9dc6..67743f5c 100644--- a/crates/ai-memory-cli/tests/uninstall.rs+++ b/crates/ai-memory-cli/tests/uninstall.rs@@ -460,7 +460,11 @@ fn default_uninstall_removes_managed_skills_across_roots_and_preserves_user_contlet extra_file_in_managed_dir = managed_paths[1].parent().unwrap().join("notes.txt");write_file(&extra_file_in_managed_dir, "keep this sibling file\n");- let output = run_uninstall(project.path(), home.path(), &["uninstall", "--apply", "--yes"]);+ let output = run_uninstall(+ project.path(),+ home.path(),+ &["uninstall", "--apply", "--yes"],+ );assert!(output.status.success(),"uninstall failed: {}",@@ -468,14 +472,20 @@ fn default_uninstall_removes_managed_skills_across_roots_and_preserves_user_cont);for path in &managed_paths {- assert!(!path.exists(), "managed skill file should be removed: {path:?}");+ assert!(+ !path.exists(),+ "managed skill file should be removed: {path:?}"+ );}assert_eq!(std::fs::read_to_string(&unmanaged_same_name).unwrap(),unmanaged_content,"unmanaged same-name skill must be preserved");- assert!(unrelated_sibling.exists(), "unrelated sibling skill survives");+ assert!(+ unrelated_sibling.exists(),+ "unrelated sibling skill survives"+ );assert!(extra_file_in_managed_dir.exists(),"non-empty managed skill directory must not be removed"@@ -553,7 +563,11 @@ fn uninstall_skills_dry_run_reports_plan_without_mutating() {let original = managed_skill_content();write_file(&skill_path, &original);- let output = run_uninstall(project.path(), home.path(), &["uninstall", "--only", "skills"]);+ let output = run_uninstall(+ project.path(),+ home.path(),+ &["uninstall", "--only", "skills"],+ );assert!(output.status.success(),"dry-run failed: {}",@@ -561,7 +575,10 @@ fn uninstall_skills_dry_run_reports_plan_without_mutating() {);let stdout = String::from_utf8(output.stdout).unwrap();assert!(stdout.contains("would delete"), "stdout was: {stdout}");- assert!(stdout.contains("managed Agent Skill"), "stdout was: {stdout}");+ assert!(+ stdout.contains("managed Agent Skill"),+ "stdout was: {stdout}"+ );assert!(stdout.contains(&skill_path.display().to_string()),"stdout was: {stdout}"diff --git a/crates/ai-memory-mcp/src/server.rs b/crates/ai-memory-mcp/src/server.rsindex 703c3801..dd7a7b75 100644--- a/crates/ai-memory-mcp/src/server.rs+++ b/crates/ai-memory-mcp/src/server.rs@@ -2135,7 +2135,8 @@ impl AiMemoryServer {/// agent can land it via its own Write/Edit tool. No server-side/// state changes — the server can't reach the agent's host/// filesystem.- #[tool(description = "Returns the canonical ai-memory routing install payload: \+ #[tool(+ description = "Returns the canonical ai-memory routing install payload: \`markered_block` for the slim CLAUDE.md / AGENTS.md snippet, \`agent_filenames` for rules-file targets, `managed_skills` for \Agent Skill files, and `target_hints` for project/global \@@ -2149,7 +2150,8 @@ impl AiMemoryServer {read-only and is the source of truth for the snippet and skills. \Skill files are ai-memory-managed only when they contain the \managed marker; do not overwrite unmanaged same-name skills unless \- the human explicitly forces replacement.")]+ the human explicitly forces replacement."+ )]async fn memory_install_self_routing(&self) -> Result<CallToolResult, McpError> {let managed_skills: Vec<_> = ai_memory_core::routing_skills::MANAGED_SKILLS.iter()@@ -2460,7 +2462,10 @@ mod tests {fn assert_detailed_prompt_surfaces(mut assert_prompt: impl FnMut(&str, &str)) {assert_prompt("MCP handshake instructions", MEMORY_INSTRUCTIONS);let combined = combined_ai_memory_prompt_surface();- assert_prompt("combined MCP, snippet, and managed skill prompts", &combined);+ assert_prompt(+ "combined MCP, snippet, and managed skill prompts",+ &combined,+ );}fn call_tool_json(result: CallToolResult) -> serde_json::Value {@@ -2712,7 +2717,6 @@ mod tests {});}-#[test]fn prompts_route_permanent_annotations_to_write_page_not_handoff() {assert_detailed_prompt_surfaces(|label, prompt| {@@ -2796,7 +2800,10 @@ mod tests {.find(|skill| skill["name"].as_str() == Some(expected.name)).unwrap_or_else(|| panic!("missing managed skill {}", expected.name));assert_eq!(skill["description"].as_str().unwrap(), expected.description);- assert_eq!(skill["relative_path"].as_str().unwrap(), expected.relative_path);+ assert_eq!(+ skill["relative_path"].as_str().unwrap(),+ expected.relative_path+ );assert_eq!(skill["content"].as_str().unwrap(), expected.content);assert!(skill["content"]