Skip to content

Commit 6ad774d

Browse files
authored
track permissiveSessionAuth as context key and react to it in cloud-agent view (#1861) (#1865)
* track permissiveSessionAuth as context key and react to it in cloud-agent view * do not block if run and then cancelled * code review suggestion adding catch
1 parent c4a6974 commit 6ad774d

File tree

7 files changed

+55
-5
lines changed

7 files changed

+55
-5
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,11 @@
17141714
"when": "true",
17151715
"contents": "%github.copilot.viewsWelcome.agentsPlaceholder%"
17161716
},
1717+
{
1718+
"view": "workbench.view.chat.sessions.copilot-cloud-agent",
1719+
"when": "github.copilot.auth.missingPermissiveSession",
1720+
"contents": "%github.copilot.viewsWelcome.noPermissiveToken.contents%"
1721+
},
17171722
{
17181723
"view": "workbench.view.chat.sessions.copilot-cloud-agent",
17191724
"when": "workspaceFolderCount == 0",
@@ -1785,6 +1790,10 @@
17851790
}
17861791
],
17871792
"commands": [
1793+
{
1794+
"command": "github.copilot.chat.triggerPermissiveSignIn",
1795+
"title": "%github.copilot.command.triggerPermissiveSignIn%"
1796+
},
17881797
{
17891798
"command": "github.copilot.claude.sessions.refresh",
17901799
"title": "%github.copilot.command.refreshClaudeCodeSessions%",
@@ -3415,6 +3424,10 @@
34153424
}
34163425
],
34173426
"commandPalette": [
3427+
{
3428+
"command": "github.copilot.chat.triggerPermissiveSignIn",
3429+
"when": "false"
3430+
},
34183431
{
34193432
"command": "github.copilot.interactiveSession.feedback",
34203433
"when": "github.copilot-chat.activated && !github.copilot.interactiveSession.disabled"

package.nls.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@
100100
"{Locked='](command:workbench.action.chat.triggerSetupForceSignIn)'}"
101101
]
102102
},
103+
"github.copilot.viewsWelcome.noPermissiveToken.contents": {
104+
"message": "Additional GitHub permissions required to use GitHub Copilot Cloud Agent.\n\n[Sign in](command:github.copilot.chat.triggerPermissiveSignIn)",
105+
"comment": [
106+
"{Locked='['}",
107+
"{Locked='](command:github.copilot.chat.triggerPermissiveSignIn)'}"
108+
]
109+
},
103110
"github.copilot.viewsWelcome.noFolder.contents": {
104111
"message": "You have not yet opened a folder.\n[Open Folder](command:workbench.action.files.openFolder)",
105112
"comment": [
@@ -131,6 +138,7 @@
131138
"github.copilot.command.applySuggestionWithCopilot": "Apply Suggestion",
132139
"github.copilot.command.explainTerminalLastCommand": "Explain Last Terminal Command",
133140
"github.copilot.command.collectWorkspaceIndexDiagnostics": "Collect Workspace Index Diagnostics",
141+
"github.copilot.command.triggerPermissiveSignIn": "Login to GitHub with Full Permissions",
134142
"github.copilot.git.generateCommitMessage": "Generate Commit Message",
135143
"github.copilot.git.resolveMergeConflicts": "Resolve Conflicts with AI",
136144
"github.copilot.devcontainer.generateDevContainerConfig": "Generate Dev Container Configuration",

src/extension/authentication/vscode-node/authentication.contribution.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { window } from 'vscode';
5+
import { commands, window } from 'vscode';
66
import { IAuthenticationService } from '../../../platform/authentication/common/authentication';
77
import { IAuthenticationChatUpgradeService } from '../../../platform/authentication/common/authenticationUpgrade';
88
import { IVSCodeExtensionContext } from '../../../platform/extContext/common/extensionContext';
@@ -38,6 +38,9 @@ class AuthUpgradeAsk extends Disposable {
3838
@IAuthenticationChatUpgradeService private readonly _authenticationChatUpgradeService: IAuthenticationChatUpgradeService,
3939
) {
4040
super();
41+
this._register(commands.registerCommand('github.copilot.chat.triggerPermissiveSignIn', async () => {
42+
await this._authenticationChatUpgradeService.showPermissiveSessionModal(true);
43+
}));
4144
}
4245

4346
async run() {

src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export class CopilotCloudSessionsProvider extends Disposable implements vscode.C
100100
}
101101
}, BACKGROUND_REFRESH_INTERVAL_MS);
102102
this._register(toDisposable(() => clearInterval(interval)));
103+
this._register(this._authenticationService.onDidAuthenticationChange(() => {
104+
this.refresh();
105+
}));
103106
}
104107

105108
public refresh(): void {

src/extension/contextKeys/vscode-node/contextKeys.contribution.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55
import { commands, extensions, window } from 'vscode';
6-
import { IAuthenticationService } from '../../../platform/authentication/common/authentication';
6+
import { IAuthenticationService, MinimalModeError } from '../../../platform/authentication/common/authentication';
77
import { ChatDisabledError, ContactSupportError, EnterpriseManagedError, NotSignedUpError, SubscriptionExpiredError } from '../../../platform/authentication/vscode-node/copilotTokenManager';
88
import { SESSION_LOGIN_MESSAGE } from '../../../platform/authentication/vscode-node/session';
99
import { ConfigKey, IConfigurationService } from '../../../platform/configuration/common/configurationService';
@@ -35,6 +35,8 @@ const previewFeaturesDisabledContextKey = 'github.copilot.previewFeaturesDisable
3535

3636
const debugContextKey = 'github.copilot.chat.debug';
3737

38+
const missingPermissiveSessionContextKey = 'github.copilot.auth.missingPermissiveSession';
39+
3840
export const prExtensionInstalledContextKey = 'github.copilot.prExtensionInstalled';
3941

4042
export class ContextKeysContribution extends Disposable {
@@ -54,6 +56,7 @@ export class ContextKeysContribution extends Disposable {
5456
super();
5557

5658
void this._inspectContext().catch(console.error);
59+
void this._updatePermissiveSessionContext().catch(console.error);
5760
this._register(_authenticationService.onDidAuthenticationChange(async () => await this._onAuthenticationChange()));
5861
this._register(commands.registerCommand('github.copilot.refreshToken', async () => await this._inspectContext()));
5962
this._register(commands.registerCommand('github.copilot.debug.showChatLogView', async () => {
@@ -154,6 +157,8 @@ export class ContextKeysContribution extends Disposable {
154157
commands.executeCommand('setContext', contextKey, false);
155158
}
156159
}
160+
161+
await this._updatePermissiveSessionContext();
157162
}
158163

159164
private async _updateQuotaExceededContext() {
@@ -203,5 +208,23 @@ export class ContextKeysContribution extends Disposable {
203208
this._updateQuotaExceededContext();
204209
this._updatePreviewFeaturesDisabledContext();
205210
this._updateShowLogViewContext();
211+
this._updatePermissiveSessionContext();
212+
}
213+
214+
private async _updatePermissiveSessionContext() {
215+
let hasPermissiveSession = false;
216+
let missingPermissiveSession = false;
217+
if (!this._authenticationService.isMinimalMode) {
218+
try {
219+
hasPermissiveSession = !!(await this._authenticationService.getPermissiveGitHubSession({ silent: true }));
220+
} catch (error) {
221+
if (!(error instanceof MinimalModeError)) {
222+
this._logService.trace(`[context keys] Failed to resolve permissive session: ${error instanceof Error ? error.message : String(error)}`);
223+
hasPermissiveSession = !!this._authenticationService.permissiveGitHubSession;
224+
}
225+
}
226+
missingPermissiveSession = !hasPermissiveSession;
227+
}
228+
commands.executeCommand('setContext', missingPermissiveSessionContextKey, missingPermissiveSession);
206229
}
207230
}

src/platform/authentication/common/authenticationUpgrade.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface IAuthenticationChatUpgradeService {
2525
* Displays a modal dialog requesting the user to grant an upgrade to a more permissive session.
2626
* @returns A promise that resolves to a boolean indicating whether the user granted the upgrade.
2727
*/
28-
showPermissiveSessionModal(): Promise<boolean>;
28+
showPermissiveSessionModal(skipRepeatCheck?: boolean): Promise<boolean>;
2929

3030
/**
3131
* Presents the upgrade prompt within the chat interface itself.

src/platform/authentication/common/authenticationUpgradeService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export class AuthenticationChatUpgradeService extends Disposable implements IAut
8383
}
8484
}
8585

86-
async showPermissiveSessionModal(): Promise<boolean> {
87-
if (this.hasRequestedPermissiveSessionUpgrade) {
86+
async showPermissiveSessionModal(skipRepeatCheck = false): Promise<boolean> {
87+
if (this.hasRequestedPermissiveSessionUpgrade && !skipRepeatCheck) {
8888
this.logService.trace('Already requested permissive session upgrade');
8989
return false;
9090
}

0 commit comments

Comments
 (0)