Skip to content

feat(ai): refactor device code login for copilot#4788

Merged
badlogic merged 1 commit into
mainfrom
refactor-device-code-login
May 22, 2026
Merged

feat(ai): refactor device code login for copilot#4788
badlogic merged 1 commit into
mainfrom
refactor-device-code-login

Conversation

@vegarsti

@vegarsti vegarsti commented May 20, 2026

Copy link
Copy Markdown
Member

We're later adding a Codex login option for device code (#3424). In preparation for that, this adds a new device code oauth path and refactors the existing GitHub Copilot login to use it.

Also tested with the standalone pi-ai package login, e.g.

# npx tsx packages/ai/src/cli.ts login github-copilot
Logging in to github-copilot...
GitHub Enterprise URL/domain (blank for github.com) (company.ghe.com):

Open this URL in your browser:
https://github.com/login/device
Enter code: <snip>

@vegarsti vegarsti requested a review from mitsuhiko May 20, 2026 07:52
@vegarsti vegarsti force-pushed the refactor-device-code-login branch from 1a2cc95 to b9f146c Compare May 20, 2026 07:54
@vegarsti

Copy link
Copy Markdown
Member Author

We're still auto-opening the browser for the Copilot login, so headless login won't work. Should we instead print the URL?

@mitsuhiko

Copy link
Copy Markdown
Member

We're still auto-opening the browser for the Copilot login, so headless login won't work. Should we instead print the URL?

Yes. We should not try to open the browser here.

@vegarsti

Copy link
Copy Markdown
Member Author

Screenshots

CleanShot-2026-05-20-at-10 44 35@2x CleanShot-2026-05-20-at-10 44 41@2x CleanShot-2026-05-20-at-10 44 45@2x

@vegarsti

Copy link
Copy Markdown
Member Author

We're still auto-opening the browser for the Copilot login, so headless login won't work. Should we instead print the URL?

Yes. We should not try to open the browser here.

Ack, will make that change!

@vegarsti vegarsti force-pushed the refactor-device-code-login branch from b9f146c to 8b17aca Compare May 20, 2026 08:55
@vegarsti

Copy link
Copy Markdown
Member Author

Done

@vegarsti vegarsti force-pushed the refactor-device-code-login branch 4 times, most recently from e718c0f to 647854e Compare May 22, 2026 06:53
@vegarsti vegarsti changed the title feat(ai): add device code login callback and use for copilot feat(ai): refactor device code login for copilot May 22, 2026
@vegarsti vegarsti force-pushed the refactor-device-code-login branch from 647854e to c554364 Compare May 22, 2026 06:54
@badlogic badlogic added the inprogress Issue is being worked on label May 22, 2026
@badlogic badlogic merged commit 11e868b into main May 22, 2026
1 check passed
@vegarsti vegarsti deleted the refactor-device-code-login branch May 22, 2026 13:25
@badlogic

Copy link
Copy Markdown
Collaborator

Follow-up cleanup after merging:

  • Kept the public OAuthProviderInterface shape intact, including usesCallbackServer.
  • Made OAuthLoginCallbacks.onDeviceCode required. The callback object is supplied by pi, so providers can decide whether to call onAuth or onDeviceCode; callback availability should not be capability discovery.
  • Made OAuthLoginCallbacks.onSelect required and documented using it for provider-driven method selection, e.g. Browser OAuth vs Device Code.
  • Removed the Copilot runtime guard for missing onDeviceCode.
  • Restored device-code browser opening through openUrl(). Without this, GitHub Copilot login regresses in normal non-headless environments because it previously opened the browser.
  • Made openUrl() silently ignore launch failures. The URL remains visible, so headless/SSH users can still open it manually.
  • Updated the custom provider docs to show method selection and the device-code metadata.

This comment is AI-generated by /wr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inprogress Issue is being worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants