Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(routing): keep home routes portable across runtimes (#1033)

AkitaOnRails0a2e82863c32
diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rs
index 09217aba..5c3cf710 100644
--- a/crates/ai-memory-cli/src/commands/install_hooks.rs
+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs
@@ -13201,8 +13201,13 @@ mod identity_parity_tests {
let tmp = tempfile::TempDir::new().unwrap();
let home = tmp.path().join("home");
std::fs::create_dir_all(&home).unwrap();
+ let route_home = if cfg!(windows) {
+ std::path::Path::new("C:/Users/ai-memory-test")
+ } else {
+ home.as_path()
+ };
for case in home_route_cases() {
- let (text, cwd) = expanded_route_case(&case, &home);
+ let (text, cwd) = expanded_route_case(&case, route_home);
let marker = home.join(".ai-memory.toml");
std::fs::write(&marker, text).unwrap();
let output = Command::new("sh")
@@ -13210,10 +13215,11 @@ mod identity_parity_tests {
.arg(r#". "$1"; _amhome="$2"; ai_memory_home_route "$3" "$4" "$5""#)
.arg("sh")
.arg(repo_file("hooks/_lib.sh"))
- .arg(&home)
+ .arg(route_home)
.arg(&marker)
.arg(&cwd)
.arg(case["identity"].as_str().unwrap_or(""))
+ .env("MSYS2_ARG_CONV_EXCL", "*")
.output()
.unwrap();
assert!(
@@ -13280,6 +13286,7 @@ mod identity_parity_tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", &home)
+ .env("USERPROFILE", &home)
.output()
.unwrap();
assert!(
@@ -13350,6 +13357,7 @@ mod identity_parity_tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", &home)
+ .env("USERPROFILE", &home)
.output()
.unwrap();
assert!(
@@ -13399,6 +13407,7 @@ mod identity_parity_tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", &home)
+ .env("USERPROFILE", &home)
.output()
.unwrap();
assert!(
@@ -13447,6 +13456,7 @@ mod identity_parity_tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", &home)
+ .env("USERPROFILE", &home)
.output()
.unwrap();
assert!(
@@ -13543,6 +13553,7 @@ mod identity_parity_tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", tmp.path())
+ .env("USERPROFILE", tmp.path())
.output()
.unwrap();
assert!(
diff --git a/crates/ai-memory-cli/src/commands/mod.rs b/crates/ai-memory-cli/src/commands/mod.rs
index 8f1fdd9f..fd63fdac 100644
--- a/crates/ai-memory-cli/src/commands/mod.rs
+++ b/crates/ai-memory-cli/src/commands/mod.rs
@@ -534,7 +534,7 @@ mod tests {
home.join(".ai-memory.toml"),
format!(
"[routes.path.\"{}\"]\nroute_workspace=\"oss\"\nroute_project=\"acme-api\"\n",
- repo.display()
+ repo.to_string_lossy().replace('\\', "/")
),
)
.unwrap();
diff --git a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs b/crates/ai-memory-cli/src/commands/openclaw_plugin.rs
index 3eaaff6e..3eae9354 100644
--- a/crates/ai-memory-cli/src/commands/openclaw_plugin.rs
+++ b/crates/ai-memory-cli/src/commands/openclaw_plugin.rs
@@ -697,6 +697,7 @@ mod tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", &home)
+ .env("USERPROFILE", &home)
.output()
.unwrap();
assert!(
@@ -830,6 +831,7 @@ mod tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", &home)
+ .env("USERPROFILE", &home)
.output()
.unwrap();
assert!(
@@ -969,6 +971,7 @@ mod tests {
.args(["--experimental-strip-types", "--no-warnings"])
.arg(&module)
.env("HOME", &home)
+ .env("USERPROFILE", &home)
.output()
.unwrap();
assert!(
diff --git a/crates/ai-memory-cli/src/marker.rs b/crates/ai-memory-cli/src/marker.rs
index 568052f4..f3a48441 100644
--- a/crates/ai-memory-cli/src/marker.rs
+++ b/crates/ai-memory-cli/src/marker.rs
@@ -496,10 +496,10 @@ fn recognizable_malformed_root_line(line: &str) -> bool {
| "identity"
| "identity_style"
| "server"
- ) && !value
+ ) && value
.strip_prefix('"')
.and_then(|inner| inner.strip_suffix('"'))
- .is_some_and(|inner| !inner.contains('"'))
+ .is_none_or(|inner| inner.contains('"'))
}
fn parse_route_header(line: &str) -> Option<(RouteKind, String)> {
@@ -1632,7 +1632,7 @@ route_project = "unc"
&home,
&format!(
"workspace = \"fallback\"\nproject = \"fallback\"\n[routes.path.\"{}\"]\nroute_workspace = \"routed\"\nroute_project = \"outside\"\n",
- outside.display()
+ outside.to_string_lossy().replace('\\', "/")
),
);
let selected = routing_selection_with_home(
diff --git a/hooks/_lib.sh b/hooks/_lib.sh
index 2e6b4e65..31208b29 100644
--- a/hooks/_lib.sh
+++ b/hooks/_lib.sh
@@ -496,7 +496,7 @@ ai_memory_home_route() {
if (selector == identity) { identity_found = 1; identity_ws = route_workspace; identity_pr = route_project; identity_style = route_identity_style; identity_aliases = route_aliases }
} else {
normalized = cleanpath(selector)
- if (!normalized || normalized == "posix" || normalized ~ /^drive:[^/]+$/ || normalized ~ /^unc:[^/]+\/[^/]+$/ || path_seen[normalized]++) invalid()
+ if (!normalized || normalized == "posix" || normalized ~ /^drive:[^\/]+$/ || normalized ~ /^unc:[^\/]+\/[^\/]+$/ || path_seen[normalized]++) invalid()
target = cleanpath(cwd)
if (normalized == target || index(target, normalized "/") == 1) {
n = split(normalized, parts, "/")
diff --git a/tests/hooks/test_lib.sh b/tests/hooks/test_lib.sh
index f6332c79..61107204 100755
--- a/tests/hooks/test_lib.sh
+++ b/tests/hooks/test_lib.sh
@@ -335,6 +335,19 @@ assert_eq "malformed home routes fail closed instead of root fallback" "&ai_memo
printf 'workspace = wrong\n' >"$HOME/.ai-memory.toml"
assert_eq "malformed root-only home marker keeps legacy parser behavior" "yes" \
"$(case "$(ai_memory_marker_qs "$HOME/src/api")" in *'&ai_memory_invalid_home_routes=1'*) printf no ;; *) printf yes ;; esac)"
+ai_memory_home
+ROUTE_FS=$(printf '\034')
+printf '[routes.path."C:/Work/API"]\nroute_workspace="windows"\nroute_project="drive"\n[routes.path."//Server/Share/API"]\nroute_workspace="windows"\nroute_project="unc"\n' >"$HOME/.ai-memory.toml"
+assert_eq "home drive route matches components" "windows${ROUTE_FS}drive${ROUTE_FS}${ROUTE_FS}" \
+ "$(ai_memory_home_route "$HOME/.ai-memory.toml" 'c:/work/api/lib' '')"
+assert_eq "home UNC route matches components" "windows${ROUTE_FS}unc${ROUTE_FS}${ROUTE_FS}" \
+ "$(ai_memory_home_route "$HOME/.ai-memory.toml" '//server/share/api/lib' '')"
+printf '[routes.path."C:/"]\nroute_workspace="windows"\nroute_project="drive"\n' >"$HOME/.ai-memory.toml"
+assert_eq "home drive root route is rejected" "invalid" \
+ "$(ai_memory_home_route "$HOME/.ai-memory.toml" 'C:/child' '')"
+printf '[routes.path."//server/share"]\nroute_workspace="windows"\nroute_project="unc"\n' >"$HOME/.ai-memory.toml"
+assert_eq "home UNC root route is rejected" "invalid" \
+ "$(ai_memory_home_route "$HOME/.ai-memory.toml" '//server/share/child' '')"
HOME="$TMP"
export HOME