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(storage): parse absolute Windows paths from URLs (#3475)

Syamsul Alamdb5ed5822a34
diff --git a/headroom/storage/__init__.py b/headroom/storage/__init__.py
index 3645a6fa5..f2dac3493 100644
--- a/headroom/storage/__init__.py
+++ b/headroom/storage/__init__.py
@@ -1,5 +1,7 @@
"""Storage modules for Headroom SDK."""
+import os
+
from .base import Storage
from .jsonl import JSONLStorage
from .sqlite import SQLiteStorage
@@ -11,6 +13,21 @@ __all__ = [
]
+def _builtin_storage_path(store_url: str, scheme: str) -> str:
+ """Return the filesystem portion of a built-in storage URL."""
+ path = store_url.removeprefix(f"{scheme}://")
+ if (
+ os.name == "nt"
+ and len(path) >= 4
+ and path[0] == "/"
+ and path[1].isalpha()
+ and path[2] == ":"
+ and path[3] in ("/", "\\")
+ ):
+ return path[1:]
+ return path
+
+
def create_storage(store_url: str) -> Storage:
"""
Create a storage instance from URL.
@@ -29,15 +46,10 @@ def create_storage(store_url: str) -> Storage:
Storage instance.
"""
if store_url.startswith("sqlite://"):
- path = store_url.replace("sqlite://", "")
- # Handle sqlite:/// (3 slashes for absolute path)
- if path.startswith("/"):
- path = path # Already absolute
+ path = _builtin_storage_path(store_url, "sqlite")
return SQLiteStorage(path)
elif store_url.startswith("jsonl://"):
- path = store_url.replace("jsonl://", "")
- if path.startswith("/"):
- path = path
+ path = _builtin_storage_path(store_url, "jsonl")
return JSONLStorage(path)
else:
# Unknown scheme: try entry point headroom.storage_backend[name=scheme]