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(copilot): detect COPILOT_API_URL in cli-main.js for Copilot CLI >= 1.0.93 (#4450)

danieldutu043fe09d8c62
diff --git a/headroom/providers/copilot/wrap.py b/headroom/providers/copilot/wrap.py
index e73ec3110..63edbc1eb 100644
--- a/headroom/providers/copilot/wrap.py
+++ b/headroom/providers/copilot/wrap.py
@@ -208,18 +208,21 @@ def native_api_url_supported(*, environ: Mapping[str, str] | None = None) -> boo
if not os.path.isdir(root):
continue
for dirpath, _dirnames, filenames in os.walk(root):
- if "app.js" not in filenames:
+ # Since Copilot CLI 1.0.93 app.js is a loader and the env read lives in cli-main.js.
+ names = [n for n in ("app.js", "cli-main.js") if n in filenames]
+ if not names:
continue
found_bundle = True
- try:
- with open(
- os.path.join(dirpath, "app.js"), encoding="utf-8", errors="replace"
- ) as bundle:
- while chunk := bundle.read(1 << 20):
- if COPILOT_NATIVE_API_URL_ENV in chunk:
- return True
- except OSError:
- continue
+ for name in names:
+ try:
+ with open(
+ os.path.join(dirpath, name), encoding="utf-8", errors="replace"
+ ) as bundle:
+ while chunk := bundle.read(1 << 20):
+ if COPILOT_NATIVE_API_URL_ENV in chunk:
+ return True
+ except OSError:
+ continue
return False if found_bundle else None
diff --git a/tests/test_copilot_native_mode.py b/tests/test_copilot_native_mode.py
index 72a7d7f77..18d5ce7cd 100644
--- a/tests/test_copilot_native_mode.py
+++ b/tests/test_copilot_native_mode.py
@@ -47,6 +47,18 @@ def test_native_support_probe_distinguishes_unknown_and_unsupported(tmp_path) ->
assert native_api_url_supported(environ={"LOCALAPPDATA": str(local)}) is True
+def test_native_support_probe_scans_cli_main_loader_layout(tmp_path) -> None:
+ local = tmp_path / "local"
+ version = local / "copilot" / "pkg" / "platform" / "1.0.102"
+ version.mkdir(parents=True)
+ (version / "app.js").write_text("loader only", encoding="utf-8")
+ (version / "cli-main.js").write_text("no override here", encoding="utf-8")
+ assert native_api_url_supported(environ={"LOCALAPPDATA": str(local)}) is False
+
+ (version / "cli-main.js").write_text("process.env.COPILOT_API_URL", encoding="utf-8")
+ assert native_api_url_supported(environ={"LOCALAPPDATA": str(local)}) is True
+
+
def test_native_support_probe_skips_unreadable_bundle(monkeypatch, tmp_path) -> None:
local = tmp_path / "local"
bundle = local / "copilot" / "pkg" / "platform" / "1.0" / "app.js"