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(cli): keep non-ASCII working directory names out of the init profile slug (#3718)
Sebai Iyedf3d95ee275a3
diff --git a/headroom/cli/init.py b/headroom/cli/init.pyindex 0063d9d69..1f0e25caa 100644--- a/headroom/cli/init.py+++ b/headroom/cli/init.py@@ -120,9 +120,9 @@ def _enable_verbose_logging() -> None:def _local_profile(cwd: Path | None = None) -> str:root = (cwd or Path.cwd()).resolve()- slug = "".join(ch if ch.isalnum() or ch in "-._" else "-" for ch in root.name.lower()).strip(- "-"- )+ slug = "".join(+ ch if (ch.isascii() and ch.isalnum()) or ch in "-._" else "-" for ch in root.name.lower()+ ).strip("-")digest = sha1(str(root).encode("utf-8")).hexdigest()[:8]return validate_profile_name(f"init-{slug or 'repo'}-{digest}")diff --git a/tests/test_cli/test_init_cli.py b/tests/test_cli/test_init_cli.pyindex d8d53b931..42008ca5a 100644--- a/tests/test_cli/test_init_cli.py+++ b/tests/test_cli/test_init_cli.py@@ -6,6 +6,7 @@ import osimport sysimport typesfrom contextlib import contextmanager+from hashlib import sha1from pathlib import Pathfrom types import SimpleNamespace@@ -18,6 +19,8 @@ import clickimport pytestfrom click.testing import CliRunner+from headroom.install.paths import _PROFILE_RE as PROFILE_RE+def _load_init_module(monkeypatch):monkeypatch.delitem(sys.modules, "headroom.cli.init", raising=False)@@ -1594,3 +1597,50 @@ def test_init_codex_strip_removes_openai_base_url(monkeypatch, tmp_path: Path) -f"_strip_codex_init_block must remove orphaned openai_base_url:\n{orphan_stripped}")assert 'model = "gpt-4o"' in orphan_stripped+++ "dir_name",+ [+ "Мастеринг в HW",+ "项目",+ "café-app",+ "Ünicode Projekt",+ ],+)+def test_local_profile_accepts_non_ascii_directory_names(monkeypatch, tmp_path, dir_name) -> None:+ """A non-ASCII working directory must still yield a valid profile name.++ ``str.isalnum`` is Unicode-aware, so Cyrillic/CJK/accented letters survived+ into the slug and ``validate_profile_name`` then rejected it, making+ ``headroom init`` unusable from such a directory.+ """+ init_cli, _ = _load_init_module(monkeypatch)+ root = tmp_path / dir_name+ root.mkdir()++ profile = init_cli._local_profile(root)++ assert PROFILE_RE.fullmatch(profile), profile+ assert profile.startswith("init-")+++def test_local_profile_is_unchanged_for_ascii_directory_names(monkeypatch, tmp_path) -> None:+ """The ASCII slug path keeps its existing output."""+ init_cli, _ = _load_init_module(monkeypatch)+ root = tmp_path / "my-repo"+ root.mkdir()++ digest = sha1(str(root.resolve()).encode("utf-8")).hexdigest()[:8]+ assert init_cli._local_profile(root) == f"init-my-repo-{digest}"+++def test_local_profile_distinguishes_identical_non_ascii_names(monkeypatch, tmp_path) -> None:+ """Two folders sharing a fully non-ASCII name must not collide."""+ init_cli, _ = _load_init_module(monkeypatch)+ first = tmp_path / "a" / "项目"+ second = tmp_path / "b" / "项目"+ first.mkdir(parents=True)+ second.mkdir(parents=True)++ assert init_cli._local_profile(first) != init_cli._local_profile(second)