Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
test(install): guard routing instruction backups
AkitaOnRails09e1a9db2c7e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 644e6aab..0b42e580 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Fixed+- Documented and regression-tested that `install-instructions` updates only the+ ai-memory marker block, preserves unrelated CLAUDE.md / AGENTS.md content,+ writes backups for existing files, and refuses unmanaged same-name skills+ unless explicitly forced.- Claude Code WindowsNative hook installs now use Claude's exec form(`command` executable plus `args` argv array) for the native `ai-memory.exe`hook, avoiding shell/Git Bash/PowerShell command-string mangling. Setdiff --git a/crates/ai-memory-cli/tests/routing_instructions.rs b/crates/ai-memory-cli/tests/routing_instructions.rsindex 47a65c0b..2023acfd 100644--- a/crates/ai-memory-cli/tests/routing_instructions.rs+++ b/crates/ai-memory-cli/tests/routing_instructions.rs@@ -111,6 +111,48 @@ fn no_skills_writes_only_instruction_snippet() {assert!(!project.path().join(".agents/skills").exists());}+#[test]+fn install_instructions_updates_only_markered_block_and_backs_up_original() {+ let project = tempfile::tempdir().unwrap();+ let home = tempfile::tempdir().unwrap();+ let target = project.path().join("CLAUDE.md");+ let original = format!(+ "# Project\n\nKeep this intro.\n\n{MARKER_START}\nold ai-memory block\n{MARKER_END}\n\nKeep this tail.\n"+ );+ fs::write(&target, &original).unwrap();++ let output = run_ai_memory(+ project.path(),+ home.path(),+ &["install-instructions", "--no-skills"],+ );+ assert_success(output);++ let updated = fs::read_to_string(&target).unwrap();+ assert!(updated.contains("Keep this intro."));+ assert!(updated.contains("Keep this tail."));+ assert!(updated.contains(MARKER_START));+ assert!(updated.contains("Use the installed ai-memory Agent Skills"));+ assert!(!updated.contains("old ai-memory block"));++ let backups: Vec<_> = fs::read_dir(project.path())+ .unwrap()+ .flatten()+ .map(|entry| entry.path())+ .filter(|path| {+ path.file_name()+ .and_then(|name| name.to_str())+ .is_some_and(|name| name.starts_with("CLAUDE.md.bak-"))+ })+ .collect();+ assert_eq!(+ backups.len(),+ 1,+ "install-instructions must back up updates"+ );+ assert_eq!(fs::read_to_string(&backups[0]).unwrap(), original);+}+#[test]fn print_shows_only_snippet_without_mutating() {let project = tempfile::tempdir().unwrap();diff --git a/docs/install.md b/docs/install.mdindex 3add467a..1f41f034 100644--- a/docs/install.md+++ b/docs/install.md@@ -1006,7 +1006,8 @@ default:Re-running the command is safe. If a project still has the old long ai-memoryblock between those markers, the refresh replaces that block in place with the-slim snippet and leaves unrelated instructions before and after it alone.+slim snippet, leaves unrelated instructions before and after it alone, and+writes a timestamped `.bak-*` backup before changing an existing file.Managed skill files contain an ai-memory ownership marker; same-name user skillswithout that marker are preserved unless you explicitly force replacement.`install-instructions --print` previews only the instruction snippet; rundiff --git a/docs/usage.md b/docs/usage.mdindex 7187056f..1b619048 100644--- a/docs/usage.md+++ b/docs/usage.md@@ -94,6 +94,8 @@ ai-memory install-instructions --no-skills`install-instructions` installs or updates managed skills by default. Use`--no-skills` only when you intentionally want a snippet-only refresh.+The CLI replaces only the markered ai-memory block, preserves unrelated content,+and writes a timestamped backup before changing an existing instruction file.`install-instructions --print` previews the instruction snippet only; use`install-skills --print` to preview skill payloads. Skill flags mirror`install-skills` with an `--skills-` prefix: