66import vscode from 'vscode' ;
77import { Repository } from '../api/api' ;
88import { AuthProvider } from '../common/authentication' ;
9+ import { COPILOT_LOGINS } from '../common/copilot' ;
10+ import { commands } from '../common/executeCommands' ;
911import { Disposable } from '../common/lifecycle' ;
1012import { Remote } from '../common/remote' ;
1113import { CODING_AGENT , CODING_AGENT_AUTO_COMMIT_AND_PUSH , CODING_AGENT_ENABLED } from '../common/settingKeys' ;
@@ -55,6 +57,28 @@ export class CopilotRemoteAgentManager extends Disposable {
5557 this . _register ( new CopilotPRWatcher ( this . repositoriesManager , this . _stateModel ) ) ;
5658 this . _register ( this . _stateModel . onDidChangeStates ( ( ) => this . _onDidChangeStates . fire ( ) ) ) ;
5759 this . _register ( this . _stateModel . onDidChangeNotifications ( ( ) => this . _onDidChangeNotifications . fire ( ) ) ) ;
60+
61+ this . _register ( this . repositoriesManager . onDidChangeFolderRepositories ( ( event ) => {
62+ if ( event . added ) {
63+ this . _register ( event . added . onDidChangeAssignableUsers ( ( ) => {
64+ this . updateAssignabilityContext ( ) ;
65+ } ) ) ;
66+ }
67+ this . updateAssignabilityContext ( ) ;
68+ } ) ) ;
69+ this . repositoriesManager . folderManagers . forEach ( manager => {
70+ this . _register ( manager . onDidChangeAssignableUsers ( ( ) => {
71+ this . updateAssignabilityContext ( ) ;
72+ } ) ) ;
73+ } ) ;
74+ this . _register ( vscode . workspace . onDidChangeConfiguration ( ( e ) => {
75+ if ( e . affectsConfiguration ( CODING_AGENT ) ) {
76+ this . updateAssignabilityContext ( ) ;
77+ }
78+ } ) ) ;
79+
80+ // Set initial context
81+ this . updateAssignabilityContext ( ) ;
5882 }
5983
6084 private _copilotApiPromise : Promise < CopilotApi | undefined > | undefined ;
@@ -79,6 +103,61 @@ export class CopilotRemoteAgentManager extends Disposable {
79103 . getConfiguration ( CODING_AGENT ) . get ( CODING_AGENT_ENABLED , false ) ;
80104 }
81105
106+ async isAssignable ( ) : Promise < boolean > {
107+ const repoInfo = await this . repoInfo ( ) ;
108+ if ( ! repoInfo ) {
109+ return false ;
110+ }
111+
112+ const { owner, repo } = repoInfo ;
113+ const folderManager = this . getFolderManagerForRepo ( owner , repo ) ;
114+
115+ try {
116+ // Ensure assignable users are loaded
117+ await folderManager . getAssignableUsers ( ) ;
118+ const allAssignableUsers = folderManager . getAllAssignableUsers ( ) ;
119+
120+ if ( ! allAssignableUsers ) {
121+ return false ;
122+ }
123+
124+ // Check if any of the copilot logins are in the assignable users
125+ return allAssignableUsers . some ( user => COPILOT_LOGINS . includes ( user . login ) ) ;
126+ } catch ( error ) {
127+ // If there's an error fetching assignable users, assume not assignable
128+ return false ;
129+ }
130+ }
131+
132+ async isAvailable ( ) : Promise < boolean > {
133+ // Check if the manager is enabled, copilot API is available, and it's assignable
134+ if ( ! this . enabled ( ) ) {
135+ return false ;
136+ }
137+
138+ const repoInfo = await this . repoInfo ( ) ;
139+ if ( ! repoInfo ) {
140+ return false ;
141+ }
142+
143+ const copilotApi = await this . copilotApi ;
144+ if ( ! copilotApi ) {
145+ return false ;
146+ }
147+
148+ return await this . isAssignable ( ) ;
149+ }
150+
151+ private async updateAssignabilityContext ( ) : Promise < void > {
152+ try {
153+ const available = await this . isAvailable ( ) ;
154+ commands . setContext ( 'copilotCodingAgentAssignable' , available ) ;
155+ } catch ( error ) {
156+ // Presume false
157+ commands . setContext ( 'copilotCodingAgentAssignable' , false ) ;
158+ }
159+ }
160+
82161 autoCommitAndPushEnabled ( ) : boolean {
83162 return vscode . workspace
84163 . getConfiguration ( CODING_AGENT ) . get ( CODING_AGENT_AUTO_COMMIT_AND_PUSH , false ) ;
@@ -114,6 +193,13 @@ export class CopilotRemoteAgentManager extends Disposable {
114193 }
115194
116195 async commandImpl ( args ?: any ) {
196+ // Check if the coding agent is available (enabled and assignable)
197+ const isAvailable = await this . isAvailable ( ) ;
198+ if ( ! isAvailable ) {
199+ vscode . window . showWarningMessage ( vscode . l10n . t ( 'GitHub Coding Agent is not available for this repository. Make sure the agent is enabled and assignable to this repository.' ) ) ;
200+ return ;
201+ }
202+
117203 // https://github.com/microsoft/vscode-copilot/issues/18918
118204 const userPrompt : string | undefined = args . userPrompt ;
119205 const summary : string | undefined = args . summary ;
0 commit comments