Skip to content

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

Rust

fix(hooks): keep repo path aliases literal

AkitaOnRails391c2a538d69
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index 1e78b918..704fa55f 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -543,11 +543,14 @@ async fn resolve_project_ids(
project: &str,
strategy: ProjectStrategy,
) -> Option<String> {
- if matches!(strategy, ProjectStrategy::RepoRoot)
- && let Some((name, Some(root))) = derive_project_from_cwd(cwd, strategy)
- && name == project
- {
- return Some(root);
+ if matches!(strategy, ProjectStrategy::RepoRoot) {
+ let cwd_path = std::path::Path::new(cwd);
+ if let Ok(root) = ai_memory_consolidate::discover_main_repo_root(cwd_path) {
+ let visible_root = repo_root_in_cwd_namespace(cwd_path, &root);
+ if visible_root.file_name().and_then(|name| name.to_str()) == Some(project) {
+ return Some(visible_root.to_string_lossy().into_owned());
+ }
+ }
}
repo_path_from_cwd(cwd)
}
diff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rs
index a9d7fd38..a8007890 100644
--- a/crates/ai-memory-store/src/reader.rs
+++ b/crates/ai-memory-store/src/reader.rs
@@ -3386,9 +3386,9 @@ impl ReaderPool {
self.with_conn(move |conn| {
// Two-condition LIKE: exact match OR descendant (prefix +
// `/`). The boundary `/` on the descendant arm stops
- // `/foo/bar` from matching `/foo/ba`. The WHERE filters
- // reject any stored repo_path that would slip past the
- // boundary (empty, `/`, trailing-slash, LIKE wildcards).
+ // `/foo/bar` from matching `/foo/ba`. The LIKE arm escapes
+ // stored wildcard characters so real paths containing `%` or
+ // `_` stay literal instead of turning into broad matches.
let row_opt = conn
.query_row(
"SELECT id, name FROM projects \
@@ -3396,10 +3396,8 @@ impl ReaderPool {
AND repo_path IS NOT NULL \
AND length(repo_path) > 1 \
AND repo_path NOT LIKE '%/' \
- AND repo_path NOT LIKE '%\\%%' ESCAPE '\\' \
- AND repo_path NOT LIKE '%\\_%' ESCAPE '\\' \
AND (?3 IS NULL OR repo_path <> ?3) \
- AND (?2 = repo_path OR ?2 LIKE repo_path || '/%') \
+ AND (?2 = repo_path OR ?2 LIKE replace(replace(replace(repo_path, '\\', '\\\\'), '%', '\\%'), '_', '\\_') || '/%' ESCAPE '\\') \
ORDER BY length(repo_path) DESC \
LIMIT 1",
params![workspace_id.as_bytes(), cwd_norm, home],