Skip to content

Conversation

@fran
Copy link

@fran fran commented Oct 18, 2025

Changes

  • Introduced CopilotAgent class for GitHub Copilot integration
  • Enhanced CLI commands to check for Copilot installation
  • Updated agent creation logic to include Copilot
  • Added necessary environment variable checks and configurations for Copilot
  • Add COPILOT.md file with custom informatin about how use it.

Notes

I haven't integrated with gh copilot as copilot extension for gh does not allow -p argument aka no user prompt so , makes impossible integrate it with rover as it stop when detect a wait.
what can be integrated is copilot directly.

It is not clear to me what should have COPILOT.md file, the reason all other agents files are a copy of AGENTS.md file.

Closes #223

fran added 3 commits October 19, 2025 00:34
- Introduced CopilotAgent class for GitHub Copilot integration
- Enhanced CLI commands to check for Copilot installation
- Updated agent creation logic to include Copilot
- Added necessary environment variable checks and configurations for Copilot
- Revised description to mention Copilot alongside existing agents
- Updated features list to reflect the inclusion of Copilot
- Added installation link for GitHub Copilot CLI
- Introduced a new COPILOT.md file providing comprehensive guidance for using the GitHub Copilot agent within the Rover workspace.
- Included installation instructions, authentication methods, environment variables, usage examples, best practices, troubleshooting tips, and security considerations.
- Enhanced documentation to support developers in effectively utilizing the Copilot agent for AI-powered code assistance.
Copy link
Collaborator

@ereslibre ereslibre left a comment

Choose a reason for hiding this comment

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

This is amazing, thank you @fran!

Added some comments, this one seems to be the trickiest one in terms of authentication compared to the other agents.

Comment on lines 73 to 118
try {
// Clean the response to extract JSON from various formats
let cleanedResult = result;

// Remove bullet points and other formatting characters from the start
cleanedResult = cleanedResult.replace(/^[*\-+]\s*/, '');

// Remove common conversational prefixes
cleanedResult = cleanedResult.replace(/^(I understand|Here's|Here is|The JSON|Response:|Answer:)\s*/i, '');

// Find JSON object in markdown code blocks (```json ... ```)
const jsonCodeBlockMatch = cleanedResult.match(/```json\s*([\s\S]*?)\s*```/);
if (jsonCodeBlockMatch) {
cleanedResult = jsonCodeBlockMatch[1].trim();
} else {
// Look for JSON object directly - find the first { and last }
const firstBrace = cleanedResult.indexOf('{');
const lastBrace = cleanedResult.lastIndexOf('}');
if (firstBrace !== -1 && lastBrace !== -1 && lastBrace > firstBrace) {
cleanedResult = cleanedResult.substring(firstBrace, lastBrace + 1);
}
}

// Clean up whitespace and fix JSON formatting issues
cleanedResult = cleanedResult.trim();

// Fix common JSON formatting issues from Copilot's multiline responses
// First, handle newlines within JSON strings properly
// We need to be careful to only escape newlines that are inside string values
cleanedResult = cleanedResult.replace(/\n\s*/g, '\\n');

// Remove any remaining control characters that could break JSON parsing
// Keep only printable ASCII characters and essential JSON characters
cleanedResult = cleanedResult.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, '');

// Additional cleanup for common formatting issues
cleanedResult = cleanedResult.replace(/\s+/g, ' '); // Normalize whitespace

const parsed = JSON.parse(cleanedResult);
return JSON.stringify(parsed);
} catch (jsonErr) {
// If JSON parsing fails, log the issue and return the raw result for parseJsonResponse to handle
console.error('Copilot JSON parsing failed:', jsonErr.message);
console.error('Cleaned result that failed to parse:', JSON.stringify(cleanedResult));
return result;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this despite being explicit in the prompt?

Copy link
Author

Choose a reason for hiding this comment

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

The main reason I added was I was getting a lot of errors due to copilot was returning formatted code and I don't see any flat to allow copilot to force to be a valid json output. Anyhow, with the change in the prompt where it was added "Nothing else" we may avoid the problem.
I'm playing a bit with it, I will get something tomorrow.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks a lot for the effort @fran!

Copy link
Author

Choose a reason for hiding this comment

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

What I have tried

  1. Find a flag for copilot to avoid some symbols, bullets points and formatting characters
    I didn't find anything in Copilot cli doc.
  2. Improve the prompt
    I changed the current prompt specifying the symbols , bullets and characters to avoid but we have the same output.
  3. add a parser to remove symbols, bullets and special characters.
    I moved the code to json-parser.ts and keep it simple.
iShot_2025-10-21_21 48 04

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you @fran! I think this will do for now. Just for reference, it seems they have an issue open regarding the JSON output: github/copilot-cli#52.

Comment on lines +27 to +35
// GitHub Copilot CLI config directory
const copilotConfigDir = join(process.env.HOME || '~', '.copilot');
if (existsSync(copilotConfigDir)) {
credentials.push({
path: copilotConfigDir,
description: 'GitHub Copilot CLI configuration directory',
required: true,
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one seems that will be closer to Claude's implementation since it also uses the Keychain in Mac OS X.

  • Mac OS X: security find-generic-password -s copilot-cli -w (or security find-generic-password -s gh:github.com -w if you logged in with gh auth): in this case we need to implement a similar logic to the one implemented with Claude, so that we read the token from the Mac OS X Keychain to a temporary file. What differs here from the Claude implementation is that on the container guest, it will expect /.copilot/config.json with .copilot_tokens."https://github.com:<username>", so there needs to be a bit of massaging of the mounted configuration.
  • Linux: /.copilot/config.json

@fran
Copy link
Author

fran commented Oct 20, 2025

thanks for review @ereslibre!. I will take care of all your comments.

fran and others added 6 commits October 20, 2025 20:53
Co-authored-by: Rafael Fernández López <ereslibre@gmail.com>
Co-authored-by: Rafael Fernández López <ereslibre@gmail.com>
Co-authored-by: Rafael Fernández López <ereslibre@gmail.com>
- Removed extensive JSON parsing logic from the Copilot agent, streamlining the response handling process.
- Added bullet point and formatting character cleanup to the json-parser utility for improved consistency in JSON responses.
- Removed unnecessary bullet point and formatting character cleanup from the json-parser utility.

getInstallCommand(): string {
// Install GitHub Copilot CLI standalone
return 'npm install -g @github/copilot';
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on github/copilot-cli#287 (comment), we need to use a prerelease version to fix an error related to missing modules (sharp).

Suggested change
return 'npm install -g @github/copilot';
// @see https://github.com/github/copilot-cli/issues/287#issuecomment-3434844899
return 'npm install -g @github/copilot@0.0.354-29';

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.

Add GitHub Copilot CLI as new AI agent provider

3 participants