-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add GitHub Copilot CLI ACP provider #8113
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
Closed
vincenzopalazzo
wants to merge
2
commits into
aaif-goose:main
from
vincenzopalazzo:codex/copilot-acp-provider
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| use anyhow::Result; | ||
| use futures::future::BoxFuture; | ||
| use std::collections::HashMap; | ||
| use std::path::PathBuf; | ||
|
|
||
| use crate::acp::{ | ||
| extension_configs_to_mcp_servers, AcpProvider, AcpProviderConfig, PermissionMapping, | ||
| ACP_CURRENT_MODEL, | ||
| }; | ||
| use crate::config::search_path::SearchPaths; | ||
| use crate::config::{Config, GooseMode}; | ||
| use crate::model::ModelConfig; | ||
| use crate::providers::base::{ProviderDef, ProviderMetadata}; | ||
|
|
||
| const COPILOT_ACP_PROVIDER_NAME: &str = "copilot-acp"; | ||
| const COPILOT_ACP_DOC_URL: &str = | ||
| "https://docs.github.com/en/copilot/reference/copilot-cli-reference/acp-server"; | ||
| const ACP_AGENT_MODE: &str = "https://agentclientprotocol.com/protocol/session-modes#agent"; | ||
| const ACP_PLAN_MODE: &str = "https://agentclientprotocol.com/protocol/session-modes#plan"; | ||
| const ACP_AUTOPILOT_MODE: &str = "https://agentclientprotocol.com/protocol/session-modes#autopilot"; | ||
| const COPILOT_ALLOW_OPTION_ID: &str = "allow_once"; | ||
| const COPILOT_REJECT_OPTION_ID: &str = "reject_once"; | ||
|
|
||
| pub struct CopilotAcpProvider; | ||
|
|
||
| fn copilot_permission_mapping() -> PermissionMapping { | ||
| PermissionMapping { | ||
| allow_option_id: Some(COPILOT_ALLOW_OPTION_ID.to_string()), | ||
| reject_option_id: Some(COPILOT_REJECT_OPTION_ID.to_string()), | ||
| rejected_tool_status: sacp::schema::ToolCallStatus::Failed, | ||
| } | ||
| } | ||
|
|
||
| impl ProviderDef for CopilotAcpProvider { | ||
| type Provider = AcpProvider; | ||
|
|
||
| fn metadata() -> ProviderMetadata { | ||
| ProviderMetadata::new( | ||
| COPILOT_ACP_PROVIDER_NAME, | ||
| "GitHub Copilot CLI (ACP)", | ||
| "Use goose with your GitHub Copilot subscription via GitHub Copilot CLI.", | ||
| ACP_CURRENT_MODEL, | ||
| vec![], | ||
| COPILOT_ACP_DOC_URL, | ||
| vec![], | ||
| ) | ||
| .with_setup_steps(vec![ | ||
| "Install GitHub Copilot CLI: `brew install copilot-cli` or `npm install -g @github/copilot`", | ||
| "Run `copilot` once and authenticate with your GitHub account (`/login` if prompted)", | ||
| "Set in your goose config file (`~/.config/goose/config.yaml` on macOS/Linux):\n GOOSE_PROVIDER: copilot-acp\n GOOSE_MODEL: current", | ||
| "Restart goose for changes to take effect", | ||
| ]) | ||
| } | ||
|
|
||
| fn from_env( | ||
| model: ModelConfig, | ||
| extensions: Vec<crate::config::ExtensionConfig>, | ||
| ) -> BoxFuture<'static, Result<AcpProvider>> { | ||
| Box::pin(async move { | ||
| let config = Config::global(); | ||
| let command_name: String = config.get_copilot_cli_command().unwrap_or_default().into(); | ||
| let resolved_command = SearchPaths::builder().with_npm().resolve(&command_name)?; | ||
| let goose_mode = config.get_goose_mode().unwrap_or(GooseMode::Auto); | ||
|
|
||
| let permission_mapping = copilot_permission_mapping(); | ||
|
|
||
| let mut args = vec!["--acp".to_string()]; | ||
| if model.model_name != ACP_CURRENT_MODEL { | ||
| args.push("--model".to_string()); | ||
| args.push(model.model_name.clone()); | ||
| } | ||
|
|
||
| let mode_mapping = HashMap::from([ | ||
| (GooseMode::Auto, ACP_AUTOPILOT_MODE.to_string()), | ||
| (GooseMode::Approve, ACP_AGENT_MODE.to_string()), | ||
| (GooseMode::SmartApprove, ACP_AGENT_MODE.to_string()), | ||
| (GooseMode::Chat, ACP_PLAN_MODE.to_string()), | ||
| ]); | ||
|
|
||
| let provider_config = AcpProviderConfig { | ||
| command: resolved_command, | ||
| args, | ||
| env: vec![], | ||
| env_remove: vec![], | ||
| work_dir: std::env::current_dir().unwrap_or_else(|_| PathBuf::from(".")), | ||
| mcp_servers: extension_configs_to_mcp_servers(&extensions), | ||
| session_mode_id: Some(mode_mapping[&goose_mode].clone()), | ||
| mode_mapping, | ||
| permission_mapping, | ||
| notification_callback: None, | ||
| }; | ||
|
|
||
| let metadata = Self::metadata(); | ||
| AcpProvider::connect(metadata.name, model, goose_mode, provider_config).await | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_copilot_permission_mapping_uses_acp_option_ids() { | ||
| let permission_mapping = copilot_permission_mapping(); | ||
|
|
||
| assert_eq!( | ||
| permission_mapping.allow_option_id.as_deref(), | ||
| Some(COPILOT_ALLOW_OPTION_ID) | ||
| ); | ||
| assert_eq!( | ||
| permission_mapping.reject_option_id.as_deref(), | ||
| Some(COPILOT_REJECT_OPTION_ID) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test will fail on machines that actually have the
geminibinary installed, because the skip gate passes andcreate_with_named_model("gemini-acp", ...)is executed, but the registry setup incrates/goose/src/providers/init.rsdoes not register agemini-acpprovider (onlyGeminiCliProvider, i.e.gemini-cli). That makes the new test deterministically error withUnknown provider: gemini-acpin environments where it runs instead of being skipped.Useful? React with 👍 / 👎.