Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(cli): update inline server profile tables
Samir Hanna Verzaf1ab9c9a5e88
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e65cba04..f7c3b8c9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -13,6 +13,9 @@ version in [`docs/changelog/`](docs/changelog/):### Fixed+- Fixed `server add` rejecting valid inline tables in `servers.toml`, including+ token rotations and URL changes. Updates now accept the same table forms as+ reads and removal, preserving registered roots and other profiles (#PR).- Refused empty and whitespace-only `--workspace` and `--project` flags at theshared CLI scope-resolution choke point (`resolve_scope`,`resolve_scope_noting_marker_project`, `resolve_scope_with_marker`, anddiff --git a/crates/ai-memory-cli/src/server_profiles.rs b/crates/ai-memory-cli/src/server_profiles.rsindex ab8ed036..151fd07d 100644--- a/crates/ai-memory-cli/src/server_profiles.rs+++ b/crates/ai-memory-cli/src/server_profiles.rs@@ -403,7 +403,7 @@ pub(crate) fn add(table.set_implicit(true);toml_edit::Item::Table(table)})- .as_table_mut()+ .as_table_like_mut().with_context(|| format!("`servers` in {REGISTRY_FILE} must be a table"))?;let mut entry = toml_edit::Table::new();entry.insert("url", toml_edit::value(url));@@ -771,6 +771,82 @@ mod tests {assert!(!remove(dd.path(), &name("b")).unwrap());}+ #[test]+ fn add_to_an_inline_registry_preserves_the_other_profile() {+ let dd = tempfile::tempdir().unwrap();+ let root_a = under(dd.path(), "a");+ let root_b = under(dd.path(), "b");+ let encoded_root = toml_edit::Value::from(root_a.clone());+ std::fs::write(+ registry_path(dd.path()),+ format!(+ "# managed by hand\nservers = {{ a = {{ url = \"https://a.example\", roots = [{encoded_root}] }} }}\n"+ ),+ )+ .unwrap();+ store_token(dd.path(), &name("a"), "tok-a").unwrap();+ let before = load(dd.path()).unwrap();++ add(+ dd.path(),+ &name("b"),+ "https://b.example",+ &[root_b],+ Some("tok-b"),+ )+ .unwrap();++ let after = load(dd.path()).unwrap();+ assert_eq!(after.profiles.len(), 2);+ assert_eq!(after.profiles[&name("a")], before.profiles[&name("a")]);+ assert_eq!(read_token(dd.path(), &name("a")).as_deref(), Some("tok-a"));+ assert_eq!(read_token(dd.path(), &name("b")).as_deref(), Some("tok-b"));+ let text = std::fs::read_to_string(registry_path(dd.path())).unwrap();+ assert!(text.contains("# managed by hand"), "{text}");+ assert!(!text.contains("tok-a") && !text.contains("tok-b"), "{text}");+ assert!(remove(dd.path(), &name("b")).unwrap());+ assert_eq!(load(dd.path()).unwrap(), before);+ assert!(read_token(dd.path(), &name("b")).is_none());+ }++ #[test]+ fn inline_profile_updates_keep_roots_and_retire_only_replaced_url_tokens() {+ for changed_url in [false, true] {+ for replacement in [None, Some("tok-new")] {+ let dd = tempfile::tempdir().unwrap();+ let root = under(dd.path(), "a");+ let encoded_root = toml_edit::Value::from(root.clone());+ std::fs::write(+ registry_path(dd.path()),+ format!(+ "servers = {{ a = {{ url = \"https://old.example\", roots = [{encoded_root}] }} }}\n"+ ),+ )+ .unwrap();+ store_token(dd.path(), &name("a"), "tok-old").unwrap();+ assert_eq!(load(dd.path()).unwrap().profiles.len(), 1);+ let url = if changed_url {+ "https://new.example"+ } else {+ "https://old.example"+ };++ let outcome = add(dd.path(), &name("a"), url, &[], replacement).unwrap();++ let profile = &load(dd.path()).unwrap().profiles[&name("a")];+ assert_eq!(profile.url, url);+ assert_eq!(profile.roots, [root]);+ assert!(outcome.roots_kept);+ assert_eq!(+ outcome.token_discarded,+ changed_url && replacement.is_none()+ );+ let expected = replacement.or_else(|| (!changed_url).then_some("tok-old"));+ assert_eq!(read_token(dd.path(), &name("a")).as_deref(), expected);+ }+ }+ }+/// Moving a profile to a new URL without a new token must not pair the/// old server's token with the new server.#[test]diff --git a/docs/marker-file.md b/docs/marker-file.mdindex 9e34c917..d3f2652b 100644--- a/docs/marker-file.md+++ b/docs/marker-file.md@@ -432,7 +432,8 @@ Re-running `ai-memory server add` for an existing profile keeps its roots when`--root` is omitted, so rotating a token cannot lift the restriction. Changinga profile's `--url` without a new token discards the old token first: a tokenbelongs to the server it was issued for, so the profile refuses events until-you add one for the new URL.+you add one for the new URL. Both `[servers.<name>]` tables and an inline+`servers = { ... }` table can be read and updated by these commands.Check the decision for a directory without sending anything: