Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(hooks): derive project name from raw cwd so Windows casing does not split projects (#871)
AkitaOnRails48c7d36392c8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 00f83a7e..3774e308 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Fixed+- A Windows folder no longer splits into two projects. The hook router+ derived a project's *name* from the cwd after+ `normalize_project_path_key` had ASCII-lowercased the whole+ drive-letter/UNC path — basename included — so a session in+ `D:\...\Default Project` was captured under `default project` while the+ CLI (which keeps the raw basename) used `Default Project`. Because+ `get_or_create_project` matches names case-sensitively, one folder+ minted two projects. The router now takes the name from the raw cwd; the+ cache key and cwd-prefix match keep the case-folded path, so #806 handoff+ stickiness is unaffected. (#871)- Auto-improve review no longer stages a proposal whose LLM-produced pagepath contains a Windows-illegal character (e.g. a `:` copied from aconventional-commit subject). That path passed the deliberately tolerantdiff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rsindex e7de040c..10ef6106 100644--- a/crates/ai-memory-hooks/src/router.rs+++ b/crates/ai-memory-hooks/src/router.rs@@ -2020,9 +2020,8 @@ async fn resolve_project_ids_inner(project_override: Option<&str>,project_strategy: ProjectStrategy,) -> anyhow::Result<(WorkspaceId, ProjectId)> {- let cwd_norm = cwd- .filter(|s| !s.is_empty())- .map(normalize_project_path_key);+ let cwd_raw = cwd.filter(|s| !s.is_empty());+ let cwd_norm = cwd_raw.map(normalize_project_path_key);// Without cwd AND without a project override, there's nothing to// resolve — fall through to the server defaults.@@ -2048,23 +2047,32 @@ async fn resolve_project_ids_inner(.unwrap_or(DEFAULT_WORKSPACE_NAME).to_string();- let (project_name, repo_path) = match (project_override, cwd_norm.as_deref()) {- (Some(p), Some(c)) => (+ // The project NAME must come from the RAW cwd: `normalize_project_path_key`+ // ASCII-lowercases the *entire* Windows drive-letter/UNC path — basename+ // included — so deriving the name from `cwd_norm` mints "default project"+ // for a folder the CLI (which keeps the raw basename) calls "Default+ // Project". `get_or_create_project` matches names case-sensitively, so one+ // folder becomes two projects (#871). The cache key and the cwd-prefix+ // match below deliberately keep `cwd_norm` (case-folded) so #806 handoff+ // stickiness is unaffected, and `derive_project_from_cwd` re-normalizes the+ // repo_path it returns regardless of the input casing.+ let (project_name, repo_path) = match (project_override, cwd_raw, cwd_norm.as_deref()) {+ (Some(p), _, Some(c)) => (p.to_string(),repo_path_from_project_override(c, p, project_strategy),),- (Some(p), None) => (p.to_string(), None),- (None, Some(c)) => match derive_project_from_cwd(c, project_strategy) {+ (Some(p), _, None) => (p.to_string(), None),+ (None, Some(raw), Some(_)) => match derive_project_from_cwd(raw, project_strategy) {Some(resolved) => resolved,None => return Ok((state.workspace_id, state.project_id)),},- (None, None) => {+ _ => {// The early-return at the top of the function guards- // against this branch; the explicit fallback here keeps- // the resolver panic-free if that guard ever moves or- // gets refactored. Same effect as `unreachable!`, but- // visible at compile time instead of inside the panic- // message.+ // against a cwd-less, override-less event; the explicit+ // fallback here keeps the resolver panic-free if that guard+ // ever moves or gets refactored. Same effect as+ // `unreachable!`, but visible at compile time instead of+ // inside the panic message.return Ok((state.workspace_id, state.project_id));}};@@ -11120,6 +11128,94 @@ mod tests {);}+ /// A Windows cwd whose basename carries uppercase letters must resolve+ /// to the SAME project the CLI would (which keeps the raw basename), not+ /// a lowercased twin. `normalize_project_path_key` folds the whole+ /// drive-letter path, so deriving the name from the normalized cwd used+ /// to mint "default project" beside the CLI's "Default Project" for one+ /// folder (#871). The cache key must stay case-folded so #806 handoff+ /// stickiness is not regressed.+ #[tokio::test]+ async fn windows_casing_does_not_split_project() {+ let tmp = TempDir::new().unwrap();+ let state = make_state(&tmp).await;+ let cwd_win = r"D:\path\to\Default Project";++ // What the CLI derives for the same raw cwd (original case).+ let (cli_name, _) = ai_memory_consolidate::derive_project_name(+ std::path::Path::new(cwd_win),+ ai_memory_consolidate::ProjectNameStrategy::Basename,+ )+ .expect("CLI derives a basename for a Windows path");+ assert_eq!(cli_name, "Default Project");++ let (_, proj_hook) = resolve_project_ids(+ &state,+ Some(cwd_win),+ None,+ None,+ ProjectStrategy::Basename,+ &ai_memory_core::ActorKey::default(),+ )+ .await+ .unwrap();++ // The hook-derived project must equal the one the CLI's name maps to.+ let (_, proj_cli) = resolve_project_ids(+ &state,+ Some(cwd_win),+ None,+ Some(&cli_name),+ ProjectStrategy::Basename,+ &ai_memory_core::ActorKey::default(),+ )+ .await+ .unwrap();+ assert_eq!(+ proj_hook, proj_cli,+ "hook must resolve the case-preserved CLI project, not a lowercased twin"+ );++ // Prove it bites: the lowercased name is a *different* project.+ let (_, proj_lower) = resolve_project_ids(+ &state,+ Some(cwd_win),+ None,+ Some("default project"),+ ProjectStrategy::Basename,+ &ai_memory_core::ActorKey::default(),+ )+ .await+ .unwrap();+ assert_ne!(+ proj_hook, proj_lower,+ "case-folded basename must NOT be the project the hook resolves"+ );++ // Paired assertion: the cache key stays case-folded (repo_path /+ // stickiness namespace unchanged) even though the NAME is preserved.+ let cache = state.project_cache.lock().await;+ let strat = ProjectStrategy::Basename.as_str().to_string();+ assert!(+ cache.contains_key(&(+ "d:/path/to/default project".to_string(),+ String::new(),+ String::new(),+ strat.clone(),+ )),+ "cache key must remain case-folded for #806 stickiness"+ );+ assert!(+ !cache.contains_key(&(+ "D:/path/to/Default Project".to_string(),+ String::new(),+ String::new(),+ strat,+ )),+ "cache key must not carry the original-case basename"+ );+ }+/// Two events resolved with overrides land in the same `(ws, proj)`/// pair as long as the override names match — even if the `cwd`/// differs. Confirms the override is the source of truth.