Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

Fix Windows drive letter path decoding in headroom learn (fixes #69)

chopratejasc7731b1d218f
diff --git a/headroom/learn/scanner.py b/headroom/learn/scanner.py
index a43d9535f..a32e3bde0 100644
--- a/headroom/learn/scanner.py
+++ b/headroom/learn/scanner.py
@@ -154,9 +154,15 @@ class ClaudeCodeScanner(ConversationScanner):
# Decode project path from escaped directory name. Fall back to a
# simple slash replacement for display if we can't recover the real
# on-disk path from the filesystem.
- project_path = _decode_project_path(entry.name) or Path(
- "/" + entry.name[1:].replace("-", "/")
- )
+ project_path = _decode_project_path(entry.name)
+ if project_path is None:
+ # Fallback: detect Windows drive letter pattern (e.g., -C-MQ2-macros)
+ fallback_parts = entry.name[1:].split("-")
+ if len(fallback_parts[0]) == 1 and fallback_parts[0].isalpha():
+ drive = fallback_parts[0].upper()
+ project_path = Path(f"{drive}:\\" + "\\".join(fallback_parts[1:]))
+ else:
+ project_path = Path("/" + entry.name[1:].replace("-", "/"))
# Derive human-readable name
name = project_path.name if project_path != Path("/") else entry.name
@@ -398,23 +404,45 @@ def _decode_project_path(escaped_name: str) -> Path | None:
if not escaped_name.startswith("-"):
return None
- # Simple approach: replace all - with / and check if path exists
+ parts = escaped_name[1:].split("-")
+ if len(parts) < 2:
+ return None
+
+ # Windows drive letter detection: -C-Users-foo or -D-MQ2-macros
+ # First part is a single letter → treat as drive letter (C:\...)
+ if len(parts[0]) == 1 and parts[0].isalpha():
+ drive = parts[0].upper()
+ win_path = Path(f"{drive}:\\" + "\\".join(parts[1:]))
+ if win_path.exists():
+ return win_path
+ # Try greedy decode for Windows paths with hyphens in dir names
+ win_base = Path(f"{drive}:\\{parts[1]}") if len(parts) > 1 else win_path
+ if win_base.exists() and len(parts) > 2:
+ result = _greedy_path_decode(win_base, parts[2:])
+ if result:
+ return result
+
+ # Unix: simple approach — replace all - with / and check if path exists
simple = Path("/" + escaped_name[1:].replace("-", "/"))
if simple.exists():
return simple
- # Try common patterns: /Users/username/...
- parts = escaped_name[1:].split("-")
+ # Try common Unix patterns: /Users/username/...
if len(parts) < 3:
return None
# Build path greedily: try joining with / and check existence
- # Start with /Users/username (first 2 components are almost always correct)
if parts[0] == "Users" and len(parts) > 2:
base = Path(f"/{parts[0]}/{parts[1]}")
remaining = parts[2:]
return _greedy_path_decode(base, remaining)
+ # Try /home/username/... (Linux)
+ if parts[0] == "home" and len(parts) > 2:
+ base = Path(f"/{parts[0]}/{parts[1]}")
+ remaining = parts[2:]
+ return _greedy_path_decode(base, remaining)
+
return None
diff --git a/tests/test_learn/test_scanner.py b/tests/test_learn/test_scanner.py
index 2aa1cd30e..0739c9a96 100644
--- a/tests/test_learn/test_scanner.py
+++ b/tests/test_learn/test_scanner.py
@@ -235,3 +235,26 @@ class TestDecodeProjectPath:
assert result == project
else:
assert result is None or result == project
+
+ def test_windows_drive_letter_pattern(self) -> None:
+ """Encoded name -C-MQ2-macros should detect Windows drive letter."""
+ import sys
+
+ result = _decode_project_path("-C-MQ2-macros")
+ if sys.platform == "win32":
+ # On Windows: tries C:\\MQ2\\macros, may or may not exist
+ assert result is None or str(result).startswith("C:")
+ else:
+ # On Unix: drive detection runs but path doesn't exist → falls through
+ # Then Unix paths tried → also don't exist → returns None
+ assert result is None
+
+ def test_windows_users_path(self) -> None:
+ """Encoded name -C-Users-foo-project detects drive letter."""
+ import sys
+
+ result = _decode_project_path("-C-Users-foo-project")
+ if sys.platform == "win32":
+ assert result is None or "Users" in str(result)
+ else:
+ assert result is None