@@ -2,6 +2,7 @@ import { arch } from 'process';
2
2
import type { ConfigurationChangeEvent } from 'vscode' ;
3
3
import { Disposable , env , ProgressLocation , Uri , window , workspace } from 'vscode' ;
4
4
import type { Container } from '../../../../container' ;
5
+ import type { SubscriptionChangeEvent } from '../../../../plus/gk/subscriptionService' ;
5
6
import { registerCommand } from '../../../../system/-webview/command' ;
6
7
import { configuration } from '../../../../system/-webview/configuration' ;
7
8
import { getContext } from '../../../../system/-webview/context' ;
@@ -27,6 +28,7 @@ export class GkCliIntegrationProvider implements Disposable {
27
28
this . _disposable = Disposable . from (
28
29
configuration . onDidChange ( e => this . onConfigurationChanged ( e ) ) ,
29
30
...this . registerCommands ( ) ,
31
+ this . container . subscription . onDidChange ( this . onSubscriptionChanged , this ) ,
30
32
) ;
31
33
32
34
this . onConfigurationChanged ( ) ;
@@ -71,12 +73,11 @@ export class GkCliIntegrationProvider implements Disposable {
71
73
72
74
private async installMCPIfNeeded ( silent ?: boolean ) : Promise < void > {
73
75
try {
74
- if ( silent && this . container . storage . get ( 'ai:mcp:attemptInstall' , false ) ) {
76
+ if ( silent && this . container . storage . get ( 'ai:mcp:attemptInstall' ) ) {
75
77
return ;
76
78
}
77
79
78
- // Store the flag to indicate that we have made the attempt
79
- await this . container . storage . store ( 'ai:mcp:attemptInstall' , true ) ;
80
+ await this . container . storage . store ( 'ai:mcp:attemptInstall' , 'attempted' ) ;
80
81
81
82
if ( configuration . get ( 'ai.enabled' ) === false ) {
82
83
const message = 'Cannot install MCP: AI is disabled in settings' ;
@@ -292,8 +293,7 @@ export class GkCliIntegrationProvider implements Disposable {
292
293
293
294
const gkAuth = ( await this . container . subscription . getAuthenticationSession ( ) ) ?. accessToken ;
294
295
if ( gkAuth != null ) {
295
- const output = await run ( 'gk.exe' , [ 'auth' , 'login' , '-t' , gkAuth ] , 'utf8' , { cwd : mcpExtractedFolderPath . fsPath } ) ;
296
- console . log ( output ) ;
296
+ await run ( 'gk.exe' , [ 'auth' , 'login' , '-t' , gkAuth ] , 'utf8' , { cwd : mcpExtractedFolderPath . fsPath } ) ;
297
297
}
298
298
} catch {
299
299
// Try alternative execution methods based on platform
@@ -377,6 +377,7 @@ export class GkCliIntegrationProvider implements Disposable {
377
377
}
378
378
379
379
// Show success notification if not silent
380
+ await this . container . storage . store ( 'ai:mcp:attemptInstall' , 'completed' ) ;
380
381
void window . showInformationMessage ( 'GitKraken MCP integration installed successfully' ) ;
381
382
} catch ( error ) {
382
383
Logger . error ( `Error during MCP installation: ${ error } ` ) ;
@@ -388,7 +389,24 @@ export class GkCliIntegrationProvider implements Disposable {
388
389
}
389
390
}
390
391
391
- private registerCommands ( ) : Disposable [ ] {
392
- return [ registerCommand ( 'gitlens.ai.mcp.install' , ( ) => this . installMCPIfNeeded ( ) ) ] ;
392
+ private async onSubscriptionChanged ( e : SubscriptionChangeEvent ) : Promise < void > {
393
+ const mcpInstallStatus = this . container . storage . get ( 'ai:mcp:attemptInstall' ) ;
394
+ if ( e . current ?. account ?. id !== e . previous ?. account ?. id && mcpInstallStatus === 'completed' ) {
395
+ try {
396
+ await run ( 'gk' , [ 'auth' , 'logout' ] , 'utf8' ) ;
397
+ } catch { }
398
+ if ( e . current ?. account ?. id !== null ) {
399
+ const currentSessionToken = ( await this . container . subscription . getAuthenticationSession ( ) ) ?. accessToken ;
400
+ if ( currentSessionToken != null ) {
401
+ try {
402
+ await run ( 'gk' , [ 'auth' , 'login' , '-t' , currentSessionToken ] , 'utf8' ) ;
403
+ } catch { }
404
+ }
405
+ }
393
406
}
407
+ }
408
+
409
+ private registerCommands ( ) : Disposable [ ] {
410
+ return [ registerCommand ( 'gitlens.ai.mcp.install' , ( ) => this . installMCPIfNeeded ( ) ) ] ;
411
+ }
394
412
}
0 commit comments