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(auth): support GitHub Enterprise Copilot OAuth domain (#2192)
Noam Asor5dbe3314a198
diff --git a/README.md b/README.mdindex 677fea96c..14450d96d 100644--- a/README.md+++ b/README.md@@ -258,13 +258,18 @@ This avoids relying on generic GitHub or Copilot CLI tokens that can readCopilot account metadata but may still be rejected by Copilot's token-exchangeendpoint.-For GitHub Enterprise Server or custom-domain Copilot deployments, set the-deployment domain before launching:+For GitHub Enterprise Server or custom-domain Copilot deployments, set one of+these before launching:```bashexport GITHUB_COPILOT_ENTERPRISE_DOMAIN=ghe.example.com+# or+export GITHUB_COPILOT_ENTERPRISE_URL=https://ghe.example.com```+Both variables are supported. If both are set,+`GITHUB_COPILOT_ENTERPRISE_URL` takes precedence.+For GitHub.com Enterprise Cloud URLs such as`github.com/enterprises/your-enterprise`, do not set an enterprise-domainoverride. Headroom uses GitHub's normal token-exchange endpoint and the Copilotdiff --git a/headroom/cli/copilot_auth.py b/headroom/cli/copilot_auth.pyindex f4baed26d..c72234686 100644--- a/headroom/cli/copilot_auth.py+++ b/headroom/cli/copilot_auth.py@@ -6,7 +6,7 @@ import clickfrom headroom.cli.main import mainfrom headroom.copilot_auth import (- DEFAULT_GITHUB_HOST,+ default_oauth_domain,headroom_copilot_auth_path,poll_copilot_device_authorization,read_headroom_copilot_oauth_token,@@ -24,16 +24,17 @@ def copilot_auth() -> None:@copilot_auth.command("login")@click.option("--domain",- default=DEFAULT_GITHUB_HOST,- show_default=True,+ default=None,help=(- "GitHub login domain. Use github.com for GitHub.com Enterprise Cloud; "- "only pass a custom hostname for GitHub Enterprise Server."+ "GitHub login domain. Defaults to GITHUB_COPILOT_ENTERPRISE_URL if set, "+ "otherwise github.com."),)-def login(domain: str) -> None:+def login(domain: str | None) -> None:"""Sign in with GitHub's Copilot OAuth device-code flow."""+ domain = domain or default_oauth_domain()+try:device = start_copilot_device_authorization(domain=domain)except Exception as exc:diff --git a/headroom/copilot_auth.py b/headroom/copilot_auth.pyindex 442cd3985..cd29f7a84 100644--- a/headroom/copilot_auth.py+++ b/headroom/copilot_auth.py@@ -171,6 +171,12 @@ def _configured_enterprise_domain() -> str | None:return _copilot_subdomain_enterprise_host(enterprise_url)+def default_oauth_domain() -> str:+ """Return the OAuth domain from GITHUB_COPILOT_ENTERPRISE_URL, or github.com."""+ domain = _configured_enterprise_domain()+ return domain if domain else DEFAULT_GITHUB_HOST++def _configured_api_url() -> str:api_url = os.environ.get("GITHUB_COPILOT_API_URL", "").strip()if api_url:diff --git a/tests/test_cli/test_copilot_auth.py b/tests/test_cli/test_copilot_auth.pyindex b9a87423a..1fbf1c271 100644--- a/tests/test_cli/test_copilot_auth.py+++ b/tests/test_cli/test_copilot_auth.py@@ -48,3 +48,38 @@ def test_copilot_auth_status_reports_missing_login(assert result.exit_code == 0, result.outputassert "Status: not logged in" in result.output+++def test_copilot_auth_login_domain_override_wins_over_enterprise_env(+ monkeypatch: pytest.MonkeyPatch,+ tmp_path: Path,+) -> None:+ auth_file = tmp_path / "copilot_auth.json"+ monkeypatch.setenv("HEADROOM_COPILOT_AUTH_FILE", str(auth_file))+ monkeypatch.setenv("GITHUB_COPILOT_ENTERPRISE_URL", "https://ghe.example.com")++ captured: dict[str, object] = {}++ def fake_start(domain: str) -> dict[str, object]:+ captured["domain"] = domain+ return {+ "verification_uri": "https://github.com/login/device",+ "user_code": "ABCD-1234",+ "device_code": "device-code",+ "interval": 1,+ "expires_in": 900,+ }++ monkeypatch.setattr(+ "headroom.cli.copilot_auth.start_copilot_device_authorization",+ fake_start,+ )+ monkeypatch.setattr(+ "headroom.cli.copilot_auth.poll_copilot_device_authorization",+ lambda device_code, *, domain, interval, expires_in: "gho-headroom",+ )++ result = CliRunner().invoke(main, ["copilot-auth", "login", "--domain", "github.com"])++ assert result.exit_code == 0, result.output+ assert captured["domain"] == "github.com"diff --git a/tests/test_copilot_auth.py b/tests/test_copilot_auth.pyindex 8412e44ad..2aa4667a9 100644--- a/tests/test_copilot_auth.py+++ b/tests/test_copilot_auth.py@@ -55,6 +55,21 @@ def test_read_cached_oauth_token_prefers_headroom_login(assert copilot_auth.read_cached_oauth_token() == "gho-headroom"+def test_default_oauth_domain_uses_enterprise_url_host(monkeypatch: pytest.MonkeyPatch) -> None:+ monkeypatch.setenv("GITHUB_COPILOT_ENTERPRISE_URL", "https://ghe.example.com")++ assert copilot_auth.default_oauth_domain() == "ghe.example.com"+++def test_default_oauth_domain_falls_back_to_github_com_when_env_blank(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ monkeypatch.setenv("GITHUB_COPILOT_ENTERPRISE_URL", " ")+ monkeypatch.setenv("GITHUB_COPILOT_ENTERPRISE_DOMAIN", "")++ assert copilot_auth.default_oauth_domain() == "github.com"++def test_read_cached_oauth_token_prefers_copilot_cli_before_generic_github_token(monkeypatch: pytest.MonkeyPatch,) -> None: