Repository navigation
feat: add GitHub Copilot provider - #705
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds GitHub Copilot as a model provider with OAuth device-flow authentication and runtime token exchange.
Changes:
- Implements GitHub Copilot provider with token exchange (GitHub token → Copilot API token) and caching
- Adds device-flow login command (
models auth login-github-copilot) and integrates with onboarding - Auto-injects Copilot provider configuration into models.json when GitHub token is available
- Updates embedded runner to exchange GitHub tokens for Copilot tokens at runtime
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/providers/github-copilot-token.ts | Token exchange and caching logic with baseUrl derivation |
| src/providers/github-copilot-token.test.ts | Unit tests for token functionality |
| src/providers/github-copilot-models.ts | Model definitions for Copilot models |
| src/providers/github-copilot-auth.ts | Device-flow OAuth authentication implementation |
| src/config/zod-schema.ts | Adds "github-copilot" to ModelApi schema |
| src/config/types.ts | Adds "github-copilot" to ModelApi type |
| src/commands/onboard-types.ts | Adds "github-copilot" to AuthChoice type |
| src/commands/auth-choice.ts | Integrates Copilot into onboarding flow with device login |
| src/commands/auth-choice-options.ts | Adds Copilot to auth menu |
| src/commands/auth-choice.test.ts | Tests for Copilot onboarding |
| src/commands/auth-choice-options.test.ts | Tests for auth options |
| src/commands/models/list.ts | Changes availability detection precedence for all providers |
| src/commands/models.ts | Exports githubCopilotLoginCommand |
| src/cli/models-cli.ts | Registers login-github-copilot CLI command |
| src/cli/models-cli.test.ts | Tests for CLI command registration |
| src/agents/pi-embedded-runner.ts | Token exchange integration for runtime execution |
| src/agents/pi-embedded-runner.test.ts | Tests for token exchange in runner |
| src/agents/models-config.ts | Auto-injection logic for Copilot provider |
| src/agents/models-config.test.ts | Tests for auto-injection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Our Copilot auth lives in Clawdbot's auth-profiles store instead, so we also | ||
| // write a runtime-only auth.json entry for pi-coding-agent to pick up. | ||
| // | ||
| // This is safe because it's (1) within Clawdbot's agent dir, (2) contains the | ||
| // GitHub token (not the exchanged Copilot token), and (3) matches existing | ||
| // patterns for OAuth-like providers in pi-coding-agent. | ||
| // Note: we deliberately do not write pi-coding-agent's `auth.json` here. | ||
| // Clawdbot uses its own auth store and exchanges tokens at runtime. | ||
| // `models list` uses Clawdbot's auth heuristics for availability. | ||
|
|
||
| // We intentionally do NOT define custom models for Copilot in models.json. |
There was a problem hiding this comment.
The comment at lines 72-82 is confusing and appears to be inaccurate. It states "we also write a runtime-only auth.json entry for pi-coding-agent to pick up" (line 75) but then contradicts itself by saying "we deliberately do not write pi-coding-agent's auth.json here" (line 80). Looking at the actual code, the function doesn't write any auth.json file - it only returns a provider configuration object with baseUrl and an empty models array. The comment should be clarified to accurately describe what the code does, or the code should be updated to match the comment's intent.
| // Our Copilot auth lives in Clawdbot's auth-profiles store instead, so we also | |
| // write a runtime-only auth.json entry for pi-coding-agent to pick up. | |
| // | |
| // This is safe because it's (1) within Clawdbot's agent dir, (2) contains the | |
| // GitHub token (not the exchanged Copilot token), and (3) matches existing | |
| // patterns for OAuth-like providers in pi-coding-agent. | |
| // Note: we deliberately do not write pi-coding-agent's `auth.json` here. | |
| // Clawdbot uses its own auth store and exchanges tokens at runtime. | |
| // `models list` uses Clawdbot's auth heuristics for availability. | |
| // We intentionally do NOT define custom models for Copilot in models.json. | |
| // Our Copilot auth lives in Clawdbot's auth-profiles store instead and is | |
| // resolved at runtime by the embedded runner. | |
| // | |
| // Note: we deliberately do not write pi-coding-agent's `auth.json` in this | |
| // helper. Clawdbot uses its own auth store and exchanges tokens at runtime. | |
| // `models list` uses Clawdbot's auth heuristics for availability; this helper | |
| // only influences the provider baseUrl and leaves model discovery to pi-ai. | |
| // We intentionally do NOT define custom models for Copilot in models.json. | |
| // We intentionally do NOT define custom models for Copilot in models.json. |
| vi.mocked(resolveCopilotApiToken).mockResolvedValue({ | ||
| token: "copilot-token", | ||
| expiresAt: Date.now() + 60_000, | ||
| source: "test", |
There was a problem hiding this comment.
The mock for resolveCopilotApiToken is missing the baseUrl property in its return value. The actual function returns an object with token, expiresAt, source, and baseUrl properties. The missing baseUrl property could cause runtime errors if the code consuming this mock expects all properties to be present.
| source: "test", | |
| source: "test", | |
| baseUrl: "https://copilot.example.test", |
| "gpt-4.1", | ||
| "gpt-4.1-mini", | ||
| "gpt-4.1-nano", |
There was a problem hiding this comment.
The model names "gpt-4.1", "gpt-4.1-mini", and "gpt-4.1-nano" don't correspond to actual OpenAI model names as of January 2025. OpenAI's actual model lineup includes "gpt-4o", "gpt-4o-mini", "gpt-4-turbo", etc., but not "gpt-4.1" models. While the comment states that "Copilot model ids vary by plan/org and can change," these specific model IDs appear to be fictional. If users try to use these models, they will likely receive errors from the Copilot API. Consider verifying the actual model names available through GitHub Copilot or documenting that these are example names.
| "gpt-4.1", | |
| "gpt-4.1-mini", | |
| "gpt-4.1-nano", | |
| "gpt-4o-mini", | |
| "gpt-4-turbo", |
| const available = | ||
| availableKeys?.has(modelKey(model.provider, model.id)) || | ||
| (cfg && authStore | ||
| cfg && authStore | ||
| ? hasAuthForProvider(model.provider, cfg, authStore) | ||
| : false); | ||
| : (availableKeys?.has(modelKey(model.provider, model.id)) ?? false); |
There was a problem hiding this comment.
This change reverses the precedence of availability detection for all providers, not just GitHub Copilot. Previously, if pi-coding-agent's registry marked a model as available (via availableKeys), it would be shown as available even without auth in Clawdbot's store. Now, when both cfg and authStore are present, it only checks Clawdbot's auth store via hasAuthForProvider. This means models that were previously shown as available through pi-coding-agent's auth.json will now show as unavailable unless they also have auth configured in Clawdbot's auth profiles. This is a breaking behavioral change that affects all providers. Consider whether this change should only apply to specific providers like github-copilot, or if there should be a migration path for existing users.
| await params.prompter.note( | ||
| `Default model set to ${model}`, | ||
| "Model configured", | ||
| ); |
There was a problem hiding this comment.
When setDefaultModel is false, this code path doesn't set agentModelOverride like other auth providers do (e.g., minimax-api sets it to "minimax/MiniMax-M2.1" at line 696). This means if a user selects GitHub Copilot during onboarding but doesn't opt to set it as the default model, the onboarding session won't use a Copilot model. Consider adding an agentModelOverride assignment (e.g., to "github-copilot/gpt-4o") when setDefaultModel is false, similar to how other providers handle this scenario.
| ); | |
| ); | |
| } else { | |
| const model = "github-copilot/gpt-4o"; | |
| agentModelOverride = model; | |
| await noteAgentModel(model); |
Copilot device login + onboarding option; model list auth detection.
86bec7c to
8afdf75
Compare
* Add Homebrew cask install option for macOS * cask link --------- Co-authored-by: CJ Pais <[email protected]>
feat: add GitHub Copilot provider
feat: add GitHub Copilot provider
feat: add GitHub Copilot provider
feat: add GitHub Copilot provider
Add GitHub Copilot as model provider.
github-copilotprovider + token exchange (GitHub token -> Copilot API token).models auth login github-copilot) storing auth profilegithub-copilot:github.models.jsonwithout replacing model list.github-copilot/gpt-4o.models list: mark availability via Clawdbot auth store (not pi-coding-agent auth.json).pnpm testgreen.