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.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix(memory): use ONNX embedder for `wrap --memory` sync (#1092) (#1262)
Parideboy4f9fedaa7a02
diff --git a/headroom/cli/wrap.py b/headroom/cli/wrap.pyindex 4335940de..4b5ef2f1b 100644--- a/headroom/cli/wrap.py+++ b/headroom/cli/wrap.py@@ -3719,8 +3719,7 @@ def codex(try:import asyncio- from headroom.memory.backends.local import LocalBackend, LocalBackendConfig- from headroom.memory.sync import sync_import+ from headroom.memory.sync import _build_sync_backend, sync_importfrom headroom.memory.sync_adapters.claude_code import (ClaudeCodeAdapter,get_claude_memory_dir,@@ -3729,8 +3728,7 @@ def codex(claude_memory_dir = get_claude_memory_dir()async def _import_claude_memories() -> int:- config = LocalBackendConfig(db_path=db_path)- backend = LocalBackend(config)+ backend = _build_sync_backend(db_path)await backend._ensure_initialized()adapter = ClaudeCodeAdapter(claude_memory_dir)count = await sync_import(backend, adapter, mem_user)diff --git a/headroom/memory/sync.py b/headroom/memory/sync.pyindex 8f78e12c5..ce4f0c596 100644--- a/headroom/memory/sync.py+++ b/headroom/memory/sync.py@@ -343,6 +343,21 @@ async def sync_export(# ---------------------------------------------------------------------------+def _build_sync_backend(db_path: str) -> Any:+ """Build the memory backend used by the sync subprocess.++ Match the proxy MCP server (see ``headroom/memory/mcp_server.py``): use the+ torch-free ONNX embedder so ``wrap --memory`` sync works on the proxy extras+ without sentence-transformers/PyTorch (#1092). It loads the same+ ``all-MiniLM-L6-v2`` 384-dim model as the local embedder, so vectors stay+ compatible with what the proxy writes — no DB migration.+ """+ from headroom.memory.backends.local import LocalBackend, LocalBackendConfig++ config = LocalBackendConfig(db_path=db_path, embedder_backend="onnx")+ return LocalBackend(config)++def main() -> None:"""CLI entry point for running sync from a subprocess."""import argparse@@ -358,10 +373,7 @@ def main() -> None:import json as _jsonasync def _run() -> None:- from headroom.memory.backends.local import LocalBackend, LocalBackendConfig-- config = LocalBackendConfig(db_path=args.db)- backend = LocalBackend(config)+ backend = _build_sync_backend(args.db)await backend._ensure_initialized()if args.agent == "claude":diff --git a/tests/test_memory_sync.py b/tests/test_memory_sync.pyindex 903c63915..3ff0f0346 100644--- a/tests/test_memory_sync.py+++ b/tests/test_memory_sync.py@@ -23,6 +23,7 @@ from typing import Anyimport pytestfrom headroom.memory.sync import (+ _build_sync_backend,sync,sync_export,sync_import,@@ -675,3 +676,14 @@ class TestCrossAgentInterop:# AGENTS.md has both (from DB)agents_content = agents_md.read_text()assert "FastAPI" in agents_content or "8787" in agents_content+++def test_sync_backend_uses_onnx_embedder(tmp_path):+ """#1092: the sync subprocess must pick the torch-free ONNX embedder.++ Defaulting to the LOCAL (sentence-transformers) embedder makes+ `wrap --memory` crash with an ImportError on the proxy extras. The backend+ must match the proxy MCP server, which uses ONNX.+ """+ backend = _build_sync_backend(str(tmp_path / "memory.db"))+ assert backend._config.embedder_backend == "onnx"