feat(auth): GitHub Enterprise Copilot support#6468
Conversation
Make all Copilot OAuth and API URLs configurable via environment variables, enabling Hermes to work with GitHub Enterprise (GHE) Copilot deployments in addition to public github.com. Changes: - copilot_auth.py: Make COPILOT_OAUTH_CLIENT_ID, COPILOT_DEVICE_CODE_URL, COPILOT_ACCESS_TOKEN_URL, COPILOT_TOKEN_EXCHANGE_URL, COPILOT_API_BASE_URL configurable via env vars (defaults unchanged for public GitHub) - copilot_auth.py: Add is_copilot_url() helper to match both public and custom GHE Copilot endpoints - copilot_auth.py: Add COPILOT_AUTH_MODE=oauth to force device-code flow, skipping env vars and gh CLI token lookup - copilot_auth.py: Add COPILOT_GH_HOST for host-aware gh auth token --hostname lookup (avoids picking up wrong host's token) - auth.py: Add base_url_env_var to copilot ProviderConfig so COPILOT_API_BASE_URL is respected by provider resolution - models.py: Read COPILOT_BASE_URL from env; add debug logging for catalog fetch attempts - run_agent.py: Add _is_copilot_base() helper; replace all 5 hardcoded api.githubcopilot.com checks to support custom GHE endpoints - main.py: Add re-auth prompt in hermes models setup when a Copilot token already exists (OAuth re-login or manual token entry) - config.py: Register COPILOT_API_BASE_URL, COPILOT_GH_HOST, COPILOT_AUTH_MODE in OPTIONAL_ENV_VARS (advanced/provider) - tests: Update test_copilot_env_vars to expect new base_url_env_var Env vars for GHE setup (in ~/.hermes/.env): COPILOT_API_BASE_URL=https://copilot-api.your-ghe.com COPILOT_DEVICE_CODE_URL=https://your-ghe.com/login/device/code COPILOT_ACCESS_TOKEN_URL=https://your-ghe.com/login/oauth/access_token COPILOT_GH_HOST=your-ghe.com # COPILOT_AUTH_MODE=oauth (optional, to force re-auth)
094fa61 to
24dedbd
Compare
Document all GHE-related env vars with placeholder values and explanatory comments so new users can discover the configuration without reading source.
|
Update: Added a second commit ( |
|
This PR would implement #6455 |
|
@HearthCore — thanks for the GHE support contribution. We merged a foundational Copilot auth overhaul in #15114 (cherry-picked #12876 token exchange, #10179 401 refresh, #12840 live context, #11285 HOME env). Your PR touches Key rebase targets:
No rush — leaving this open pending your rebase. |
|
checking in to see if there's anyway my team can contribute to getting this merged? Our team has been waiting to upgrade to enterprise solely on account of the lack of hermes support. |
Summary
Adds full GitHub Enterprise (GHE) Copilot support by making all Copilot OAuth and API URLs configurable via environment variables. All defaults remain unchanged — public github.com users are unaffected.
Motivation
Organizations using GitHub Enterprise with Copilot cannot use Hermes today because OAuth endpoints, API base URLs, and token exchange URLs are hardcoded to
github.com/api.githubcopilot.com. This PR makes all of those configurable.Changes
Core: configurable Copilot endpoints (
copilot_auth.py)COPILOT_API_BASE_URL,COPILOT_DEVICE_CODE_URL,COPILOT_ACCESS_TOKEN_URL,COPILOT_TOKEN_EXCHANGE_URL,COPILOT_OAUTH_CLIENT_ID— all read from env vars with public GitHub defaultsis_copilot_url()helper matches both public and custom GHE endpointsAuth improvements (
copilot_auth.py)COPILOT_AUTH_MODE=oauth— forces OAuth device-code flow, skipping env vars andgh auth token. Solves the problem where existing tokens from a different GitHub host block re-authenticationCOPILOT_GH_HOST— passes--hostnametogh auth tokenso the correct host's token is used when logged into both public GitHub and GHE simultaneouslyProvider resolution (
auth.py)base_url_env_var="COPILOT_API_BASE_URL"to copilotProviderConfigso the standard provider resolution pipeline picks up the custom base URLAgent endpoint matching (
run_agent.py)_is_copilot_base()helper replaces 5 hardcoded"api.githubcopilot.com" in ...checksSetup UX (
main.py)hermes models setupnow offers a re-auth prompt when a Copilot token already exists: continue / OAuth re-login / enter token manuallyModel catalog (
models.py)COPILOT_BASE_URLreads fromCOPILOT_API_BASE_URLenv varConfig (
config.py)COPILOT_API_BASE_URL,COPILOT_GH_HOST,COPILOT_AUTH_MODEinOPTIONAL_ENV_VARS(advanced/provider category)Documentation (
.env.example)GHE Setup Example
Then run
hermes models setup→ select Copilot → OAuth login targets the GHE instance automatically.Files Changed
hermes_cli/copilot_auth.pyis_copilot_url(),COPILOT_AUTH_MODE,COPILOT_GH_HOSThermes_cli/auth.pybase_url_env_varon copilot provider, env-aware base URL defaulthermes_cli/models.pyCOPILOT_BASE_URL, debug logginghermes_cli/main.pyhermes models setuphermes_cli/config.pyOPTIONAL_ENV_VARSentriesrun_agent.py_is_copilot_base()helper, 5 hardcoded checks replaced.env.exampletests/hermes_cli/test_api_key_providers.pybase_url_env_varTesting
pytest tests/ -q: 4446 passed, 3 pre-existing flaky skipped)test_copilot_env_varsto expect newbase_url_env_varPlatform
Tested on Linux (WSL2/Debian).