Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(handoff): treat Windows cwd paths as case-insensitive
kevin932787b2e0daf0a5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 08a74e62..e7c4317c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- Automatic handoff selection and cwd-prefix project matching now treat+ Windows drive-letter and UNC paths as case-insensitive. A Linux server+ (the Docker Desktop helper) comparing host cwds from Explorer, Git, and+ PowerShell previously required a byte-exact match, so `C:\Users\…\repo`+ vs `c:\users\…\repo` missed the pending auto-handoff and could mint a+ fragment project. Unix paths stay case-sensitive.+## [2.3.2] - 2026-09-20### Changeddiff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rsindex 46308ac6..e7de040c 100644--- a/crates/ai-memory-hooks/src/router.rs+++ b/crates/ai-memory-hooks/src/router.rs@@ -1976,10 +1976,21 @@ fn cache_key_for(fn normalize_project_path_key(path: &str) -> String {let normalized = path.replace('\\', "/");- if normalized.len() > 1 {+ let normalized = if normalized.len() > 1 {normalized.trim_end_matches('/').to_string()} else {normalized+ };+ // Same Windows-path folding as `ai_memory_store::normalize_cwd`: a Linux+ // server comparing host cwds from Docker Desktop must treat `C:\Repo`+ // and `c:\repo` as one tree, or session stickiness splits the project.+ let bytes = normalized.as_bytes();+ if (bytes.len() >= 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':')+ || normalized.starts_with("//")+ {+ normalized.to_ascii_lowercase()+ } else {+ normalized}}@@ -4245,6 +4256,19 @@ mod tests {None,Some("/home/user"),));++ // Windows host cwd reaching a Linux server (Docker Desktop): drive+ // letter and path case must not split one session into two projects.+ assert!(sticky_within_session_tree(+ Some(r"C:\Users\alice\repo"),+ Some(r"c:\users\alice\repo\src"),+ Some(r"C:\Users\alice"),+ ));+ assert!(!sticky_within_session_tree(+ Some(r"C:\Users\alice"),+ Some(r"c:\users\alice\repo"),+ Some(r"C:\Users\alice"),+ ));}// Out-of-tree stickiness is scoped to `repo-root` and keeps thediff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rsindex bafff718..bbb00efa 100644--- a/crates/ai-memory-store/src/reader.rs+++ b/crates/ai-memory-store/src/reader.rs@@ -8742,7 +8742,11 @@ fn telemetry_count_from_row(/// Normalize a cwd for comparison: treat Windows backslashes as path/// separators and trim trailing separators while keeping a bare root as `/`.-/// Pure and string-only; it does not touch the filesystem.+/// Drive-letter and UNC paths are ASCII-lowercased: the server often runs+/// on Linux (Docker Desktop) while the hook cwd is a Windows host path,+/// and Explorer/Git/PowerShell disagree on `C:` vs `c:`. Unix paths stay+/// byte-exact (`/Repo` is not `/repo`). Pure and string-only; it does not+/// touch the filesystem.pub(crate) fn normalize_cwd(p: &str) -> std::borrow::Cow<'_, str> {let replaced = if p.contains('\\') {std::borrow::Cow::Owned(p.replace('\\', "/"))@@ -8750,15 +8754,26 @@ pub(crate) fn normalize_cwd(p: &str) -> std::borrow::Cow<'_, str> {std::borrow::Cow::Borrowed(p)};let trimmed = replaced.trim_end_matches('/');- if trimmed.is_empty() {+ let core = if trimmed.is_empty() {std::borrow::Cow::Borrowed("/")} else if trimmed.len() == replaced.len() {replaced} else {std::borrow::Cow::Owned(trimmed.to_string())+ };+ if is_windows_style_path(&core) {+ std::borrow::Cow::Owned(core.to_ascii_lowercase())+ } else {+ core}}+fn is_windows_style_path(path: &str) -> bool {+ let bytes = path.as_bytes();+ (bytes.len() >= 2 && bytes[0].is_ascii_alphabetic() && bytes[1] == b':')+ || path.starts_with("//")+}+/// True when `descendant` is the same directory as `ancestor` or nested/// below it, with component-boundary awareness: `/repo` contains/// `/repo/api` but neither `/repo-other` nor `/repository`. Inputs are@@ -9511,6 +9526,27 @@ mod tests {assert!(!cwd_within(r"C:\repo", r"C:\repo-other"));}+ /// Docker Desktop runs the server on Linux while hook cwd is a Windows+ /// host path. Explorer, Git, and PowerShell disagree on drive-letter+ /// case, so a byte-exact compare misses the auto-handoff and the+ /// repo_path prefix match for the same directory.+ #[test]+ fn cwd_within_windows_drive_letter_is_case_insensitive() {+ use super::cwd_within;+ assert!(cwd_within(r"C:\Users\alice\repo", r"c:\users\alice\repo"));+ assert!(cwd_within(+ r"C:\Users\alice\repo",+ r"c:\Users\alice\repo\src"+ ));+ assert!(!cwd_within(+ r"C:\Users\alice\repo",+ r"c:\Users\alice\repo-other"+ ));+ // Unix paths stay case-sensitive: /Repo and /repo are different dirs.+ assert!(!cwd_within("/Repo", "/repo"));+ assert!(!cwd_within("/Repo", "/repo/src"));+ }+// The realistic scenario matrix (see the cwd the SessionEnd hook injects):// a manual handoff is cwd=NULL, an auto handoff carries the session cwd.