Skip to content

feat: add GitHub Copilot Provider that support agent mode #7010 #7072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

NaccOll
Copy link

@NaccOll NaccOll commented Aug 14, 2025

Related GitHub Issue

Closes: #7010

Description

  • Implemented the Copilot component with authentication and model selection features.
  • Added tests for the Copilot component covering authentication states, error handling, and model management.
  • Updated localization files to include Copilot-related strings in multiple languages.
  • Enhanced the model validation functions to support Copilot models.
  • Modified the useSelectedModel hook to handle Copilot model selection.
  • Updated the index file to export the Copilot component.

VS Code LM API cannot achieve multiple use of the tool consuming only one premium requeusts. Therefore, I implemented a Copilot Provider, mimicking the Copilot authentication process found at https://github.com/BerriAI/litellm and https://github.com/sst/opencode.

In my own test, I chose claude-4 and had him write a web version of Angry Birds. This involved reading and writing eight files, requiring approximately 20 tool calls and consuming only one premium requeust.

Test Procedure

  1. Select Copilot as your service provider.
  2. Click Copilot Authentication.
  3. Copy the device code.
  4. Click Open Link.
  5. Enter the device code and wait for authentication to complete.
  6. Select a model and save.
  7. Start the task.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

image image

Documentation Updates

Additional Notes

Get in Touch


Important

Add GitHub Copilot Provider with agent mode support, including authentication, model selection, and validation, along with tests and localization updates.

  • Behavior:
    • Adds CopilotHandler in copilot.ts to handle GitHub Copilot API interactions, including authentication and model selection.
    • Updates webviewMessageHandler.ts to handle Copilot authentication and model requests.
    • Supports model validation for Copilot in validate.ts.
  • Tests:
    • Adds tests for CopilotHandler in copilot.spec.ts.
    • Adds tests for Copilot authentication and model fetching in copilot.test.ts.
    • Updates validate.test.ts to include Copilot model validation.
  • Localization:
    • Updates localization files to include Copilot-related strings in multiple languages.
  • UI:
    • Adds Copilot component in Copilot.tsx for UI interactions related to Copilot authentication and model selection.

This description was created by Ellipsis for 6e825b2. You can customize this summary. It will automatically update as commits are pushed.

@NaccOll NaccOll requested review from mrubens, cte and jr as code owners August 14, 2025 02:53
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Aug 14, 2025
Copy link

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! I've reviewed the GitHub Copilot Provider implementation and found it to be well-structured overall. The OAuth device flow authentication is properly implemented, and the TypeScript typing is comprehensive. However, there are some issues that need attention before merging.

/**
* Determine the X-Initiator header based on message roles
*/
private determineInitiator(messages: Anthropic.Messages.MessageParam[]): string {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this X-Initiator logic correct? The method seems complex and the logic for determining 'agent' vs 'user' might not cover all edge cases. Could you add more comments explaining the rationale, or consider simplifying this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. This method is mainly used to determine whether the last request was sent by the user. However, there is currently no such flag, which can only determine whether the text in the message has the specified tag.


private constructor() {
// Store tokens in user's home directory
this.tokenDir = join(homedir(), ".roo-code", "copilot")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security concern: Tokens are stored in plaintext at ~/.roo-code/copilot/tokens.json. Have you considered using VSCode's secret storage API instead for better security?

Example:

await context.secrets.store('copilot_access_token', accessToken)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is no different from other apiKeys. And it is difficult to get the context in a singleton object

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 14, 2025
@NaccOll NaccOll marked this pull request as draft August 14, 2025 04:36
@NaccOll NaccOll force-pushed the feature-copilot-provider branch from ae0ac5c to fcd4536 Compare August 14, 2025 10:11
- Implemented the Copilot component with authentication and model selection features.
- Added tests for the Copilot component covering authentication, error handling, and model management.
- Updated localization files to include Copilot-related strings in multiple languages.
- Enhanced model validation functions to support Copilot models.
- Integrated Copilot into the settings provider index and updated hooks to handle selected models.
@NaccOll NaccOll force-pushed the feature-copilot-provider branch from fcd4536 to 6e825b2 Compare August 14, 2025 14:16
@NaccOll NaccOll marked this pull request as ready for review August 14, 2025 14:19
@NaccOll NaccOll mentioned this pull request Aug 14, 2025
29 tasks
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @NaccOll. This looks good. My main concern is the TOS that we might be breaking by pretending we are Copilot:

Image Image

After the review comments are addressed, I will approve it and let the team decide if we should merge this.

@daniel-lxs daniel-lxs moved this from Triage to PR [Changes Requested] in Roo Code Roadmap Aug 14, 2025
@hannesrudolph hannesrudolph added PR - Changes Requested and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 14, 2025
@NaccOll NaccOll requested a review from daniel-lxs August 14, 2025 17:14
@daniel-lxs
Copy link
Collaborator

@NaccOll Thank you for addressing the review, it seems that a unit test is failing, can you take a look?

chang default model for copilot
refactor the message handler about copilot
remove useless console ouput
@NaccOll NaccOll force-pushed the feature-copilot-provider branch from e1c32ff to f3d35b3 Compare August 15, 2025 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR - Changes Requested size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: PR [Changes Requested]
Development

Successfully merging this pull request may close these issues.

Copilot premium requeusts via LM API
3 participants