Commit Graph
5 Commits
Author SHA1 Message Date
0d203db6b8 fix(copilot): keep new VS Code chats on the Local harness so they reach the proxy (#4899)
## Description

VS Code can run a Copilot chat on its "Copilot harness" (Agent Host, the
bundled Copilot SDK runtime) instead of the Local harness. That runtime
ignores `github.copilot.advanced.debug.overrideCapiUrl` /
`overrideProxyUrl`, so the chat goes straight to GitHub. Copilot's small
background calls (title, intent) still reach the proxy, so the proxy
looks connected while the main conversation never arrives. The harness
default (`chat.defaultToCopilotHarness`,
`chat.editor.preferCopilotHarness`) is tagged `experiment: startup` in
VS Code, so it can be flipped per user by rollout.

`headroom wrap vscode` now pins new chats to the Local harness.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- `headroom/providers/copilot/vscode.py`: the managed block also writes
`"chat.defaultToCopilotHarness": false` and
`"chat.editor.preferCopilotHarness": false`. Because they sit inside the
marker block, `headroom unwrap vscode` removes them. A harness setting
the user already set outside the block is left alone (no duplicate key).
New helper `copilot_harness_settings_enabled(path)` reports a user value
of `true`.
- `headroom/cli/wrap.py`: one line saying new chats stay on the Local
harness and existing chats keep their engine; a warning instead when the
user's own setting is `true`. `--no-configure` prints the two extra
settings.
- `docs/content/docs/vscode-copilot.mdx`: documents the harness settings
and the troubleshooting case.
- Blocks written by older versions (including ones with
`overrideAuthType`) are replaced by marker as before.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
tests/test_provider_copilot_vscode_config.py + tests/test_cli/test_wrap_vscode.py: 32 passed.
Against origin/main source: 7 of those fail (block contents, old-block upgrade, user-set key [True]/[False], wrap output, --no-configure output).
ruff 0.17.4 check + format --check on the 5 changed Python files: clean.
mypy on the changed source files: 8 errors, all in headroom/cache/prefix_tracker.py and headroom/ccr/mcp_server.py, identical on origin/main; none in changed files.
```

## Real Behavior Proof

- Environment: macOS 27.2.1, Python 3.12.13, VS Code 1.145.2 with GitHub
Copilot signed in, core run from this branch, real GitHub Copilot
upstream. Real user `settings.json` (backed up and restored afterwards).
- Exact command / steps:
  1. `headroom wrap vscode -p 8795` from this branch.
2. `code chat -n -m agent "Reply with the single word OK and nothing
else."` (opens a new VS Code window and sends one Agent-mode chat).
3. Read the proxy's `/stats`, VS Code's `agenthost.log`, then `headroom
unwrap vscode`.
- Observed result:
  ```text
VS Code Copilot proxy settings updated: ~/Library/Application
Support/Code/User/settings.json
Keep using Copilot's normal model picker; the selected model is
preserved.
New chats stay on VS Code's Local harness; a chat keeps the engine it
started with, so start a new chat.

  settings.json after wrap:
  {
  	// --- Headroom Copilot proxy ---
"github.copilot.advanced.debug.overrideProxyUrl":
"http://127.0.0.1:8795/p/win-local",
"github.copilot.advanced.debug.overrideCapiUrl":
"http://127.0.0.1:8795/p/win-local",
  	"chat.defaultToCopilotHarness": false,
  	"chat.editor.preferCopilotHarness": false
  	// --- end Headroom Copilot proxy ---
  }

  proxy requests before chat: 0 {}
proxy requests after one Agent-mode chat in a new VS Code window: 4
{'gpt-4o-mini-2024-07-18': 3, 'claude-opus-5.5': 1}
  agent host turns during the chat: 0

Removed Headroom Copilot proxy settings from ~/Library/Application
Support/Code/User/settings.json
  settings.json after unwrap:
  {
  }
  ```
Separately, on the same machine with the settings edited by hand (same
VS Code, same proxy, new window each time):
`"chat.defaultToCopilotHarness": true` -> the Agent-mode chat ran in the
Agent Host (provider `copilotcli`) and 0 requests reached the proxy;
`"chat.defaultToCopilotHarness": false` +
`"chat.editor.preferCopilotHarness": false` -> Local harness, 4 requests
reached the proxy including the main `/v1/messages` call.
`"chat.temporaryDefaultToLocalHarness": true` as a user setting had no
effect, so it is not written.
- Not tested: a VS Code where Microsoft's rollout has flipped the
default (the explicit user value is expected to win, but that could not
be reproduced); an organization that enforces managed sandbox settings,
where VS Code can require the Copilot harness regardless; VS Code
profiles, workspace-level settings, Insiders/VSCodium; Windows and
Linux; the persistent `headroom start --persistent --vscode` path in the
Enterprise client.

## Runtime Rollout Safety

- Rollout-managed feature(s): none.
- Minimum rollout channel: n/a.
- Stable/default behavior changed: `headroom wrap vscode` writes two
more VS Code user settings inside its managed block. No proxy behaviour
changes.
- Kill switch / disable path: `headroom unwrap vscode` removes them; a
user who sets either key themselves keeps their value.
- Unsafe override required: no.
- Qualification impact: none expected.
- Rollback path: revert this commit; `unwrap` removes blocks of either
format.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Additional Notes

- This keeps users off the Copilot harness; it does not route that
harness through Headroom. Supporting it is separate work.
- Only the configured settings file is checked for a user value. A
`true` in workspace settings, another profile, or policy is not
detected.
- After `unwrap` the keys return to VS Code's default, which a rollout
may move to the Copilot harness.
- Existing chats keep the harness they started with; the wrap output
says to start a new chat.
- `e2e/copilot_live.py` and `e2e/wrap/run.py` were not run.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4899"
target="_blank"><picture><source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img
src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4"
alt="Devin Review"></picture></a>
<!-- devin-review-badge-end -->

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: JD Davis <mxjerrett@gmail.com>
2026-11-16 23:19:43 -06:00
Ayush Kumar JhaandJD Davis 7b68fc263a fix(copilot): warn when a VS Code profile cannot see the proxy settings (#3919)
## Description

`headroom wrap vscode` writes Copilot's two endpoint overrides into the
Default profile's `settings.json` and reports success. A VS Code window
that uses a profile with its own settings reads only
`User/profiles/<id>/settings.json`, and Copilot takes these overrides
from user settings alone. In that window Copilot keeps talking to GitHub
directly: Copilot works, Headroom records nothing, and setup said it
succeeded. That is exactly what #3716 describes. The reporter hasn't
confirmed yet that they use a profile (I asked on the issue), so this
says "Refs" rather than "Closes".

After writing a VS Code user directory's `settings.json`, `wrap vscode`
now reads the profiles VS Code records in that directory's
`globalStorage/storage.json`. That file is either the Default one or one
named with `--settings-file`. For each profile that keeps its own
settings and doesn't define both overrides as live settings, it prints a
warning with the exact `--settings-file` command that routes it.

Nothing is written to profile files automatically. The docs already
scope profile-specific settings to `--settings-file`, and the block
persists and fails closed after the proxy stops. Routing every profile
silently would therefore change Copilot in profiles the user never meant
to proxy.

Refs #3716

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- `headroom/providers/copilot/vscode.py`:
`unrouted_vscode_profiles(user_dir)` returns `(name, settings.json)` for
each stored profile that has its own settings
(`useDefaultFlags.settings` unset) and doesn't define both endpoint
overrides as live settings.
- It parses the profile's JSONC with `_parse_settings`, split out of
`_validate_settings` so both share one parser. As a result, a marker or
keys that exist only in comments don't count.
- It accepts only a local folder name as a location (VS Code uses
`hash(uuid).toString(16)`, which can be negative). That skips remote
URIs and rules out path traversal.
  - Missing or unexpected VS Code state produces no warning.
- `headroom/cli/wrap.py`: after writing the settings file, `wrap vscode`
prints one `Warning:` line per such profile of the user directory that
holds that file.
- A profile's own `settings.json` has no profile state beside it, so
running the printed remedy produces no warning.
- A `--settings-file` in another user directory (Insiders, VSCodium,
portable) gets that directory's profiles checked.
  - There's no warning with `--no-configure`.
- `headroom/providers/copilot/__init__.py`: exports the helper alongside
the other VS Code helpers.
- `docs/content/docs/vscode-copilot.mdx`: adds a troubleshooting entry
for "no requests while Copilot keeps working".
- `tests/test_cli/test_wrap_vscode.py`:
`test_wrap_vscode_names_profiles_that_ignore_default_settings` walks the
whole flow. It warns by default and when the Default file is named
explicitly, stays silent for a shared-settings profile, and goes silent
once the printed remedy has run.
`test_wrap_vscode_checks_the_profiles_of_the_user_dir_it_configures`
covers another user directory.
- `tests/test_provider_copilot_vscode_config.py` covers:
  - own versus shared settings
  - a negative-hash folder
  - traversal and remote locations
- profiles that override both endpoints, whether managed or hand-written
- a marker-only file, commented-out keys, a single key, and unparseable
settings
  - a missing or malformed `storage.json`

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
# The new tests against the code before each commit.
# main (c46e74d0), before the first commit:
E   assert "VS Code profile 'Work'" in "  VS Code Copilot proxy settings added: ...\Code\User\settings.json\n  Keep using Copilot's normal model picker; ..."
# c887cbab, before the review follow-up. --settings-file naming the Default file printed no warning:
E   assert "VS Code profile 'Work'" in "  VS Code Copilot proxy settings updated: ...\Code\User\settings.json\n  Keep using Copilot's normal model picker; ..."
# ...and a profile whose settings only mention the marker in a comment counted as routed:
old code, marker-only profile -> []  (expected Work to be listed)
old code, commented-out keys profile -> []  (expected Work to be listed)

# With both commits:
$ pytest tests/test_cli/test_wrap_vscode.py tests/test_provider_copilot_vscode_config.py
27 passed in 1.19s

# Each mutation of the fix fails at least one test:
M1 ignore useDefaultFlags.settings: KILLED (2 failed, 25 passed)
M2 marker text counts as configured: KILLED (7 failed, 20 passed)
M3 one live key is enough: KILLED (1 failed, 26 passed)
M4 reject leading '-' in location: KILLED (2 failed, 25 passed)
M5 accept any location string: KILLED (1 failed, 26 passed)
M6 drop the CLI warning: KILLED (2 failed, 25 passed)
M7 scan only without --settings-file: KILLED (2 failed, 25 passed)
M8 always scan the Default user dir: KILLED (1 failed, 26 passed)

$ ruff check <changed files> && ruff format --check <changed files>   # ruff 0.16.8
All checks passed!
5 files left unchanged
$ mypy headroom/providers/copilot/vscode.py headroom/providers/copilot/__init__.py headroom/cli/wrap.py --ignore-missing-imports --follow-imports=silent   # mypy 1.19.1
Success: no issues found in 3 source files
# On the first commit, `mypy headroom --ignore-missing-imports` reported only
# headroom\fileperms.py:71 (Windows-only os.fchmod), a file this PR does not touch.

# Every test in the subsystems this touches, this branch vs its base (d5318ac2):
$ pytest tests/test_cli tests/test_copilot*.py tests/test_provider*.py -n 8
branch: 7 failed, 1621 passed, 8 skipped (14 more tests than base: the new ones)
base:  25 failed, 1589 passed, 8 skipped
# All 7 branch failures also fail on base: symlink, signal, service-supervisor and
# opencode-env tests that fail on this Windows machine. The other 18 base failures
# are test_wrap_persistent.py tests that vary from one xdist run to the next; that
# file passes serially (62 passed on both the branch and main).
```

## Real Behavior Proof

- Environment: Windows 11, Python 3.11.9, VS Code 1.140.0 (official zip,
isolated `--user-data-dir`), this branch
- Exact command / steps: wrote Headroom's block into an isolated VS Code
user dir. Then opened VS Code with a small probe extension that records
`getConfiguration("github.copilot").inspect(key).globalValue` for both
keys, once in the Default profile and once with `--profile=Repro` (VS
Code created the profile and recorded it in `storage.json`). Next I ran
the `wrap vscode` command against that user dir (`APPDATA` pointed at
it). Only the Copilot subscription lookup and the proxy watcher were
stubbed, because there's no Copilot account on this machine. I ran the
command the warning printed, re-probed the profile window, and ran plain
`wrap vscode` again. For the review follow-up I repeated the CLI runs
against the same VS Code-written state with the cases from the two
findings.
- Observed result: the profile window doesn't see Headroom's settings
until the warning's command is run.
- Default profile window:
`"overrideCapiUrl":{"globalValue":"http://127.0.0.1:8788/p/a11y"}`, and
the same for `overrideProxyUrl`
- `--profile=Repro` window: `{"globalValue":null}` for both, so Copilot
falls back to the endpoints from its token, i.e. GitHub directly
- `wrap vscode` printed: `Warning: VS Code profile 'Repro' keeps its own
settings, so Copilot there still bypasses Headroom. Route it with:
headroom wrap vscode --settings-file
"V:\ud1\Code\User\profiles\6c87cdb4\settings.json"`
- after running that command, the `Repro` window sees both overrides
(`"globalValue":"http://127.0.0.1:8788/p/headroom"`), and plain `wrap
vscode` no longer warns
- review follow-up: with `Repro`'s settings holding only `// ---
Headroom Copilot proxy ---`, plain `wrap vscode` warns about `Repro`.
`--settings-file` naming the Default file warns too.
- review follow-up: the printed remedy refuses that half-written file
with the existing `Error: Incomplete Headroom marker block in
...\profiles\6c87cdb4\settings.json; refusing to edit.` Once the stray
marker is removed, the remedy succeeds and plain `wrap vscode` prints no
warning.
- Not tested: real Copilot traffic, macOS and Linux, the reporter's own
setup, and a complete local run of the full suite.
- real Copilot traffic, because there's no Copilot subscription on this
machine. I separately checked that the bundled Copilot Chat 0.66.0,
0.67.0 and 0.68.0 all read both keys as user-scope-only settings, and
that a proxy built from `main` logs both Copilot paths at INFO.
- macOS and Linux. VS Code uses the same `User/profiles` layout there,
and the unit tests cover the logic.
  - the reporter's own setup.
- the full test suite. A local run stalled at 97% and was killed after
40 minutes on this Windows machine, so I compared the touched subsystems
against the base instead; CI runs the full suite.

## Runtime Rollout Safety

- Rollout-managed feature(s): none
- Minimum rollout channel: n/a
- Stable/default behavior changed: `wrap vscode` prints one extra
warning line for each VS Code profile that keeps its own settings and
doesn't define both overrides. No file it writes changes.
- Kill switch / disable path: none needed. The warning is informational,
and pointing `--settings-file` at a file outside a VS Code user
directory skips the scan.
- Unsafe override required: no
- Qualification impact: none
- Rollback path: revert this PR; no persisted state or format changes

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Additional Notes

- The second commit addresses both Devin Review findings: a commented
marker hid an unrouted profile, and an explicit Default path skipped the
scan.
- For the second finding I scan the user directory of the file being
configured rather than comparing against `vscode_settings_path()`. That
covers the explicit Default path, and it also checks profiles for
Insiders, VSCodium or portable user directories. It also avoids
resolving `APPDATA` when `--settings-file` is given.
- Question for maintainers: would you rather `wrap vscode` write the
block into every profile with its own settings, and `unwrap vscode`
remove it from all of them? It would be a small change on top of this
helper. I left it out because it changes which windows fail closed while
the proxy is down.
- `unwrap vscode` still cleans only the file it's given. A profile
configured with `--settings-file` needs the same flag to undo it, as the
docs already say.

---------

Co-authored-by: JD Davis <mxjerrett@gmail.com>
2026-10-05 10:03:08 -05:00
b77d612913 fix(copilot): send VS Code inline completions to the host that serves them (#3112)
## Description

#3077 stopped Copilot's inline completions being forwarded to
`api.openai.com` (the corporate-blocked host in the original report) —
but sent them to the **CAPI host**, which does not serve that endpoint.

Copilot has two surfaces on two different hosts, and GitHub's own client
library keeps them apart:

```js
_getCAPIUrl(t)  -> t?.endpoints.api   || "https://api.githubcopilot.com"
_getProxyUrl(t) -> t?.endpoints.proxy || DEFAULT_PROXY_BASE_URL
DEFAULT_PROXY_BASE_URL = "https://copilot-proxy.githubusercontent.com"
```

building completions as
`${proxyBaseURL}/v1/engines/<engine>/completions` (`@vscode/copilot-api`
0.5.2). Probed unauthenticated against the live hosts:

| host | `POST /v1/engines/<e>/completions` |
|---|---|
| `copilot-proxy.githubusercontent.com` | **401** — exists, needs auth |
| `proxy.individual.githubcopilot.com` | **401** — CNAME to the above |
| `api.githubcopilot.com` | **404** — does not serve this path |

So the destination #3077 chose could not have worked. Three separate
defects were in the way, each sufficient on its own to keep completions
broken.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- `copilot_auth.py`: added `DEFAULT_COMPLETIONS_PROXY_URL` and made it
the default in `copilot_completions_base_url()`, replacing the CAPI
host.
- `copilot_auth.py`: the "custom deployment keeps its own host" rule now
excludes public Copilot hosts. Without this, `headroom wrap vscode` —
the common setup, and the one that exports
`GITHUB_COPILOT_API_URL=<resolved subscription URL>` — resolved straight
back to the 404 host. **This was a bug in my own first cut of the fix,
found by testing the real `wrap vscode` environment rather than just the
routing table.**
- `copilot_auth.py`: added `is_copilot_completions_host()` and
`is_copilot_upstream_url()` (chat ∪ completions). The completions host
was recognised as Copilot **nowhere**, so `apply_copilot_api_auth`
attached no credentials (401 — routing correctly to a host we then
failed to authenticate against) and `build_copilot_upstream_url` skipped
`mark_request_routed_to_copilot()`, mislabelling the provider in
telemetry.
- The union is applied at exactly those two call sites.
`is_copilot_api_url` is left alone, so validation of a token payload's
`endpoints.api` and the Responses-API preference check keep their strict
chat-only meaning. All six call sites were read before choosing this.
- `proxy_targets.py`: the "already a Copilot host" guard now keys on the
*completions* host. A CAPI host is not a completions host, so it must
still be redirected; a genuine per-SKU completions host or operator
override is still left untouched.
- `providers/copilot/vscode.py`, `cli/wrap.py`,
`docs/…/vscode-copilot.mdx`: stop writing/printing
`github.copilot.advanced.debug.overrideAuthType`. No such setting exists
in the modern Copilot Chat extension — the only one left after
`GitHub.copilot` was deprecated in early 2026. Its full `advanced.*`
surface is `authPermissions`, `authProvider`, `debug.overrideCapiUrl`,
`debug.overrideProxyUrl`, `debug.use*Fetcher`. It is still *recognised*
so a stale hand-written copy is detected, just never emitted.

## Testing

- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
tests/test_copilot_vscode_completions_routing.py  59 passed
Copilot-related suites                           293 passed, 8 skipped

Full suite:
3 failed, 11250 passed, 581 skipped in 342.50s
```

The 3 failures are pre-existing and environmental, identical to a
plain-`main` baseline on this machine: no `cargo`
(`test_no_native_tls_in_wheel_build_tree`), no `codex` CLI
(`test_learn/test_integration.py`), and
`test_run_server_installs_cancelled_error_filter`, which fails under
full-suite ordering on `main` too.

## Real Behavior Proof

- Environment: macOS (darwin 25.4.0), Python 3.12.13, worktree off
`main` @ `139c7cbd`, `HEADROOM_SKIP_UPSTREAM_CHECK=1`
- Exact command / steps: (1) composed the real request path —
`select_passthrough_base_url(proxy, headers, path)` →
`build_copilot_upstream_url` → `apply_copilot_api_auth` — across 7
deployment shapes (no config, `wrap vscode`, advertised
`endpoints.proxy`, operator override, GHE `.ghe.com`, GHE custom domain,
target already a completions host); (2) probed the three candidate hosts
unauthenticated with `curl -X POST
/v1/engines/gpt-4o-copilot/completions`; (3) round-tripped
`settings.json` through empty / one-setting / comments+array / CRLF
shapes asserting valid JSON, idempotency and clean removal.
- Observed result: before — `api.githubcopilot.com/...` (404 host), and
with `GITHUB_COPILOT_API_URL` set as `wrap vscode` sets it,
`api.business.githubcopilot.com` (also 404); no `Authorization` header
on the completions host. After —
`copilot-proxy.githubusercontent.com/v1/engines/gpt-41-copilot/completions`
with credentials attached in every public-Copilot shape,
`endpoints.proxy` and the operator override still winning, and a GHE
tenant staying on its own host. `settings.json` stays valid JSON in all
four shapes with the dead key gone; the two `restored=False` cases are
pre-existing whitespace/CRLF normalisation, identical on `main`.
Reverting the source fails 14 of the new tests, including the credential
test on the completions host.
- Not tested: no live VS Code session and no authenticated completion —
the 401 proves the endpoint exists, not that GitHub accepts our
forwarded request, which needs a real Copilot token. Confirmation from
@rganesh-msys is still wanted. **Enterprise remains unresolved by
default**: a GHE tenant stays on its own CAPI host, which is likely
still the wrong surface for completions, but staying in-tenant beats
forwarding keystrokes to a public GitHub host —
`GITHUB_COPILOT_PROXY_URL` is the exact fix and now takes precedence
over everything.

## Runtime Rollout Safety

- Rollout-managed feature(s): None — no rollout channel gates this.
- Minimum rollout channel: n/a
- Stable/default behavior changed: Yes, and deliberately — the
completions destination moves from a host that answers 404 to the one
GitHub's own client defaults to. Only `/v1/engines/<engine>/completions`
is affected; every other path keeps its upstream, pinned by tests.
Copilot credentials now also reach the completions host, which is the
point.
- Kill switch / disable path: `GITHUB_COPILOT_PROXY_URL` pins the
destination explicitly and beats all inference.
- Unsafe override required: No.
- Qualification impact: None.
- Rollback path: Revert this commit; completions return to the CAPI host
(404) and the settings block regains the inert `overrideAuthType`.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Additional Notes

Two things found while reading the extension source, **not changed
here**:

1. `advanced.debug.overrideProxyUrl` is **not** deprecated — the report
that Copilot 0.60.0 stopped honouring it does not hold. The current
canonical key is `github.copilot.internal.completionsUrl`, and
`advanced.debug.overrideProxyUrl` is checked as its explicit legacy
fallback (`getEndpointOverrideUrl` in
`completions-core/lib/src/networkConfiguration.ts`), so what we write
still works. Worth migrating to the `internal.*` keys eventually, since
they take precedence.
2. `endpoints.proxy` is still only recorded during a token exchange,
which is opt-in via `GITHUB_COPILOT_USE_TOKEN_EXCHANGE`, and the base
URL is chosen before auth runs. With the default now correct this is a
refinement for per-SKU hosts rather than a correctness requirement, so
it is left as-is.

Closes #3076

---------

Co-authored-by: Tejas Chopra <tejas@Tejass-MacBook-Pro.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 15:21:22 -07:00
JD Davis 1aa701adaa fix(vscode): persist compatible Claude modes and route Copilot CAPI (#2986)
## Description

Fixes #2492, #2028, and #2827.

Claude daemon workers consume project settings rather than reliably
inheriting wrapper environment state, while the Claude VS Code webview
cannot render deferred-tool response blocks. Separately, recent Copilot
Chat versions use the whole CAPI override for generation; the legacy
proxy override alone only sends model discovery through Headroom.

This PR carries both integrations through to the actual consumers
instead of only changing their launch-time surface configuration.

## Type of Change

- [x] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] Build / CI

## Changes Made

- Persist the resolved Claude ENABLE_TOOL_SEARCH value into project
settings for daemon workers and restore it transactionally after wrap
exits.
- Use compatibility-safe Foundry and Claude VS Code defaults while
preserving explicit user choices.
- Configure both Copilot overrideProxyUrl and overrideCapiUrl in the
reversible managed VS Code settings block.
- Route Copilot unprefixed POST /chat/completions and HTTP /responses
requests through the real compression handlers.
- Keep /responses out of the Codex WebSocket aliases because Copilot and
Codex use different WebSocket wire protocols.
- Extend wrap E2E assertions for both the Claude webview mode and
Copilot CAPI routing.

## Testing

- [x] 127 combined Claude, Copilot, route-integration, and MCP
dependency-contract tests pass.
- [x] Ruff check passes on all changed Python files.
- [x] Ruff format check passes.
- [x] Python compilation and git diff --check pass.

## Runtime Safety

Standalone Claude CLI defaults remain unchanged. Explicit Claude
tool-search values retain precedence, and project settings are restored
through the existing cleanup path. Copilot model/session helper
endpoints continue through generic passthrough, while only validated
HTTP generation paths receive explicit compression routes. Existing
Codex WebSocket behavior is unchanged.

## Review Readiness

- [x] Current main and MCP v1 compatibility retained
- [x] Worker-facing Claude persistence covered
- [x] Reversible Copilot and Claude settings behavior covered
- [x] Copilot generation routes covered at registration and proxy
integration layers
- [x] Ready for review
2026-08-13 15:06:41 -05:00
JD DavisandJerrettDavis 007446c73a feat(copilot): proxy VS Code models transparently (#2687)
## Description

Make Headroom a transparent proxy for VS Code GitHub Copilot. Users keep
using Copilot's normal model picker—GPT-4.1, Claude Sonnet, Claude Opus,
and other models in their entitlement—while Headroom silently forwards
the selected model instead of registering or requiring a separate
"Headroom" model.

This also fixes GitHub's device OAuth exchange by sending form-encoded
request bodies, matching the endpoint contract.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- Add `headroom wrap vscode` to start a Copilot-seeded subscription
proxy and safely configure VS Code's shipped Copilot proxy override.
- Add `headroom unwrap vscode` for reversible cleanup.
- Preserve VS Code's selected model by changing only the proxy URL/auth
override; no custom model is registered and no model preference is
written.
- Support stable VS Code settings locations on macOS, Windows, and
Linux, plus `--settings-file` for Insiders, portable, and other
installations.
- Edit JSONC settings with a marker-owned block while preserving
unrelated bytes, comments, ordering, and trailing commas.
- Refuse malformed markers, invalid JSONC, or unmanaged existing Copilot
overrides instead of overwriting user configuration.
- Fix SIGINT cleanup so the managed settings block is removed and normal
shutdown exits successfully.
- Fix Copilot device OAuth start/poll requests to use
`application/x-www-form-urlencoded`.
- Add a compatibility matrix, setup/removal flow, credential behavior,
remote-development guidance, enterprise notes, troubleshooting, and
verification documentation.

## Testing

- [ ] Unit tests pass (`pytest`)
- [ ] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
$ .venv/bin/pytest -q tests/test_provider_copilot_vscode_config.py tests/test_cli/test_wrap_vscode.py tests/test_cli/test_wrap_helpers.py tests/test_copilot_auth.py tests/test_cli/test_copilot_auth.py tests/test_provider_copilot_wrap.py tests/test_cli/test_wrap_copilot.py tests/test_copilot_provider_label.py tests/test_copilot_subscription_smoke.py
244 passed in 0.59s

$ .venv/bin/ruff check <changed Python files and tests>
All checks passed!

$ .venv/bin/mypy headroom/providers/copilot/vscode.py
Success: no issues found in 1 source file

$ cd docs && npm run types:check
fumadocs-mdx && next typegen && tsc --noEmit
# exited 0

$ git diff --check
# exited 0
```

The full 10,179-test suite was also sampled through approximately 83%,
but was stopped because of its runtime. It exposed existing failures in
`test_recover_codex.py`, `test_wrap_stale_marker.py`, and
`test_proxy_health.py`; therefore the broad `pytest`, repository-wide
Ruff, and repository-wide mypy boxes are intentionally not checked.

## Real Behavior Proof

- Environment: macOS arm64, VS Code 1.131.0, built-in GitHub Copilot
0.59.0, Headroom 0.33.1-dev.
- Exact command / steps:
  1. Completed `headroom copilot login` with GitHub's device flow.
  2. Ran `.venv/bin/headroom wrap vscode --port 8788`.
3. Confirmed VS Code retained its ordinary Copilot model catalog and
made `GET /models` through Headroom with `GitHubCopilotChat/0.59.0` and
`editor-version: vscode/1.131.0`.
4. Sent native Copilot `/p/headroom/chat/completions` requests through
the same endpoint using `gpt-4.1`, `claude-sonnet-4.6`, and
`claude-opus-4.7`.
- Observed result:
  - All three completion requests returned HTTP 200.
- GPT-4.1 resolved upstream to `gpt-4.1-2025-04-14`; Sonnet and Opus
retained their exact selected IDs.
  - All returned the requested exact marker content.
- VS Code's settings contained only the Headroom proxy URL and token
auth override—no Headroom model or model-selection setting.
- The proxy health endpoint remained ready with `openai_api_url` set to
`https://api.githubcopilot.com`.
- Not tested:
- Physical Windows or Linux hosts (their path/config behavior is covered
by unit tests).
- WSL, dev containers, SSH remotes, VS Code Insiders, or enterprise
Copilot deployments end-to-end.
  - Every model in the live Copilot catalog.
- A fully submitted chat from VS Code's UI automation; the real
extension's catalog request and native completion paths were verified
separately.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing targeted unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Screenshots (if applicable)

Not applicable; this integration intentionally has no separate UI or
model entry.

## Additional Notes

The integration uses VS Code Copilot's shipped advanced/debug proxy
endpoint seam. The managed settings block is deliberately narrow and
reversible. Remote extension hosts may need their own reachable
proxy/configuration as documented.

---------

Co-authored-by: JerrettDavis <2610199+JerrettDavis@users.noreply.github.com>
2026-08-03 04:42:48 -07:00