Skip to content

Conversation

@jeffnash
Copy link
Contributor

Summary

Implements specialized handling for Gemini 3 Pro's reasoning capabilities via Copilot.

Changes

  • Capture reasoning_text from SSE model parts
  • Handle reasoning_opaque signature for tool calls
  • Re-inject reasoning context into subsequent requests

Credit

Reverse engineering insights adapted from https://github.com/aadishv/vscre

Stack

This is PR 4/5 in the Copilot feature stack:

  1. Infrastructure & Config (feat(copilot): add shared infrastructure and config [1/5] #380)
  2. Auth Flow (feat(copilot): implement GitHub Copilot authentication flow [2/5] #381)
  3. Executor & Models (feat(copilot): add Copilot request executor and model registry [3/5] #382)
  4. [This PR] Gemini Reasoning
  5. Tests

Depends on: #382 - merge that first

- Add auth directory management helper (GetAuthDir)
- Add random hex string generator for request IDs
- Add helper for generating unique machine identifiers
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@gemini-code-assist
Copy link

Summary of Changes

Hello @jeffnash, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the system's capabilities by adding full support for GitHub Copilot. It establishes a complete authentication and token management system for Copilot, integrates its diverse models into the existing framework, and specifically enhances interaction with Gemini 3 Pro by managing its unique reasoning context. These changes enable seamless and configurable access to Copilot's AI services, improving the system's overall utility and intelligence.

Highlights

  • Gemini 3 Pro Reasoning Support: Implemented specialized handling for Gemini 3 Pro's reasoning capabilities within Copilot, including capturing reasoning_text from SSE model parts, handling reasoning_opaque signatures for tool calls, and re-injecting reasoning context into subsequent requests.
  • Copilot Authentication Flow: Introduced a comprehensive authentication flow for GitHub Copilot using the OAuth device code method. This includes new CLI flags (-copilot-login), management API endpoints (/copilot-auth-url), and robust token management (exchange, refresh, and persistence).
  • Copilot Configuration: Added new configuration options for Copilot API keys in config.yaml, allowing specification of account type (individual, business, enterprise), proxy settings, and agent-initiator-persist behavior for rate limit management.
  • Management API Endpoints: Provided a full suite of management API endpoints (GET, PUT, PATCH, DELETE) for programmatic configuration and management of Copilot API keys.
  • Shared Caching for Models and Reasoning: Implemented shared caching mechanisms for Copilot models and Gemini reasoning data, ensuring efficient retrieval and state preservation across executor instances and re-authentications.
  • Copilot Executor and Model Registry Integration: Integrated a dedicated Copilot executor to handle API requests, including model name stripping, payload sanitization, and dynamic header application. Copilot models, including aliases and fallback options, are now part of the model registry.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces comprehensive support for GitHub Copilot, including a full OAuth device flow for authentication, configuration management, and a dedicated executor. The changes are extensive and well-structured, adding significant new functionality. My review has identified a few issues, primarily related to duplicated code in both the example configuration and the configuration struct definition, which will cause compilation errors. Additionally, there's a minor syntax error in the new Copilot authenticator. Once these issues are addressed, the PR will be in great shape.

Comment on lines 219 to 247
// CopilotKey represents the configuration for GitHub Copilot API access.
// Authentication is handled via device code OAuth flow, not API keys.
type CopilotKey struct {
// AccountType is the Copilot subscription type (individual, business, enterprise).
// Defaults to "individual" if not specified.
AccountType string `yaml:"account-type" json:"account-type"`

// ProxyURL overrides the global proxy setting for Copilot requests if provided.
ProxyURL string `yaml:"proxy-url,omitempty" json:"proxy-url,omitempty"`

// AgentInitiatorPersist, when true, forces subsequent Copilot requests sharing the
// same prompt_cache_key to send X-Initiator=agent after the first call. Default false.
AgentInitiatorPersist bool `yaml:"agent-initiator-persist" json:"agent-initiator-persist"`
}

// CopilotKey represents the configuration for GitHub Copilot API access.
// Authentication is handled via device code OAuth flow, not API keys.
type CopilotKey struct {
// AccountType is the Copilot subscription type (individual, business, enterprise).
// Defaults to "individual" if not specified.
AccountType string `yaml:"account-type" json:"account-type"`

// ProxyURL overrides the global proxy setting for Copilot requests if provided.
ProxyURL string `yaml:"proxy-url,omitempty" json:"proxy-url,omitempty"`

// AgentInitiatorPersist, when true, forces subsequent Copilot requests sharing the
// same prompt_cache_key to send X-Initiator=agent after the first call. Default false.
AgentInitiatorPersist bool `yaml:"agent-initiator-persist" json:"agent-initiator-persist"`
}

Choose a reason for hiding this comment

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

critical

The CopilotKey struct is defined multiple times. This will cause a compilation error due to redeclaration. Please remove the duplicate definitions.

Comment on lines +85 to +86
}
}

Choose a reason for hiding this comment

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

critical

There appears to be a syntax error here due to mismatched braces. The if statement from line 79 is not properly closed, which will cause a compilation error. Please correct the block structure.

Suggested change
}
}
}
}

Comment on lines 110 to 149
# GitHub Copilot account configuration
# Note: Copilot uses OAuth device code authentication, NOT API keys or tokens.
# Do NOT paste your GitHub access token or Copilot bearer token here.
# Tokens are stored only in auth-dir JSON files, never in config.yaml.
#
# To authenticate:
# - CLI: run with -copilot-login flag
# - Web: use the /copilot-auth-url management endpoint
#
# After OAuth login, tokens are managed automatically and stored in auth-dir.
# The entries below only configure account type and optional proxy settings.
#copilot-api-key:
# - account-type: "individual" # Options: individual, business, enterprise
# proxy-url: "socks5://proxy.example.com:1080" # optional: proxy for Copilot requests

# # When set to true, this flag forces subsequent requests in a session (sharing the same prompt_cache_key)
# # to send the header "X-Initiator: agent" instead of "vscode". This mirrors VS Code's behavior for
# # long-running agent interactions and helps prevent hitting standard rate limits.
# agent-initiator-persist: true

# GitHub Copilot account configuration
# Note: Copilot uses OAuth device code authentication, NOT API keys or tokens.
# Do NOT paste your GitHub access token or Copilot bearer token here.
# Tokens are stored only in auth-dir JSON files, never in config.yaml.
#
# To authenticate:
# - CLI: run with -copilot-login flag
# - Web: use the /copilot-auth-url management endpoint
#
# After OAuth login, tokens are managed automatically and stored in auth-dir.
# The entries below only configure account type and optional proxy settings.
#copilot-api-key:
# - account-type: "individual" # Options: individual, business, enterprise
# proxy-url: "socks5://proxy.example.com:1080" # optional: proxy for Copilot requests

# # When set to true, this flag forces subsequent requests in a session (sharing the same prompt_cache_key)
# # to send the header "X-Initiator: agent" instead of "vscode". This mirrors VS Code's behavior for
# # long-running agent interactions and helps prevent hitting standard rate limits.
# agent-initiator-persist: true

Choose a reason for hiding this comment

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

medium

The configuration block for copilot-api-key is duplicated. Please remove the extra copies to avoid confusion for users.

Comment on lines +107 to +109
if _, err := rand.Read(b); err != nil {
panic(fmt.Sprintf("failed to generate random bytes for request ID: %v", err))
}

Choose a reason for hiding this comment

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

medium

This function panics if rand.Read fails. While this is a rare event on modern operating systems, a panic will crash the entire server. It would be more robust to return an error from this function and handle it gracefully in the calling code (e.g., by failing the request with a 500 error). This would prevent a potential denial-of-service scenario.

- Add Copilot section with agent-initiator-persist flag
- Add scanner buffer size configuration
- Add account type configuration option
- Add copilot types with account type validation
- Document configuration options in example config
- Add tests for util and copilot types
- Add device-code OAuth flow with GitHub token exchange
- Implement Copilot token acquisition and refresh logic
- Add account type handling (individual/business/enterprise)
- Add token persistence and storage management
- Add CLI login command (cliproxy-api copilot login)
- Register Copilot refresh handler in SDK
- Validate account_type with warning for invalid values
@jeffnash jeffnash force-pushed the feat/copilot-gemini branch from 7e02001 to c6f7a5a Compare November 30, 2025 21:48
- Implement Copilot executor with header injection
- Add VS Code version headers and integration IDs
- Add agent header logic (X-Initiator detection)
- Add vision request header for image inputs
- Add static model registry with raptor-mini and oswe-vscode-prime
- Add management API endpoints for auth files

Note: Full model list and dynamic fetching added in gemini branch
…tching

- Add full Copilot model registry (all GPT, Claude, Gemini, Grok models)
- Implement dynamic model fetching from Copilot API with caching
- Add Gemini reasoning capture and injection for tool calls
- Add reasoning_opaque and reasoning_text handling for Gemini 3 models
- Evict model and reasoning caches on auth removal
- Add 30-second retry delay for 429 quota errors

Credit: Reverse engineering insights adapted from github.com/aadishv/vscre
@jeffnash jeffnash force-pushed the feat/copilot-gemini branch from c6f7a5a to d4c3621 Compare November 30, 2025 23:09
@luispater luispater closed this Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants