@@ -16,8 +16,8 @@ import { gate } from '../../../../system/decorators/gate';
1616import { debug , log } from '../../../../system/decorators/log' ;
1717import { Logger } from '../../../../system/logger' ;
1818import { getLogScope , setLogScopeExit } from '../../../../system/logger.scope' ;
19- import { compare } from '../../../../system/version' ;
20- import { getPlatform , isWeb } from '../../platform' ;
19+ import { compare , fromString , satisfies } from '../../../../system/version' ;
20+ import { getPlatform , isOffline , isWeb } from '../../platform' ;
2121import { CliCommandHandlers } from './commands' ;
2222import type { IpcServer } from './ipcServer' ;
2323import { createIpcServer } from './ipcServer' ;
@@ -32,6 +32,7 @@ const enum CLIInstallErrorReason {
3232 ProxyFetch ,
3333 GlobalStorageDirectory ,
3434 CoreInstall ,
35+ Offline ,
3536}
3637
3738const enum McpSetupErrorReason {
@@ -44,6 +45,7 @@ const enum McpSetupErrorReason {
4445 UnsupportedHost ,
4546 UnsupportedClient ,
4647 UnexpectedOutput ,
48+ Offline ,
4749}
4850
4951export interface CliCommandRequest {
@@ -118,6 +120,15 @@ export class GkCliIntegrationProvider implements Disposable {
118120 return ;
119121 }
120122
123+ // Reset the attempts count if GitLens extension version has changed
124+ if (
125+ reachedMaxAttempts ( cliInstall ) &&
126+ this . container . version !== this . container . previousVersion &&
127+ satisfies ( fromString ( this . container . version ) , '>= 17.6' )
128+ ) {
129+ void this . container . storage . store ( 'gk:cli:install' , undefined ) ;
130+ }
131+
121132 if ( ! mcpExtensionRegistrationAllowed ( ) || reachedMaxAttempts ( cliInstall ) ) {
122133 return ;
123134 }
@@ -164,6 +175,7 @@ export class GkCliIntegrationProvider implements Disposable {
164175 switch ( ex . reason ) {
165176 case McpSetupErrorReason . WebUnsupported :
166177 case McpSetupErrorReason . VSCodeVersionUnsupported :
178+ case McpSetupErrorReason . Offline :
167179 void window . showWarningMessage ( ex . message ) ;
168180 break ;
169181 case McpSetupErrorReason . InstallationFailed :
@@ -383,6 +395,12 @@ export class GkCliIntegrationProvider implements Disposable {
383395 message = 'Unable to locally install the GitKraken MCP server. Please try again.' ;
384396 telemetryReason = 'local installation failed' ;
385397 break ;
398+ case CLIInstallErrorReason . Offline :
399+ reason = McpSetupErrorReason . Offline ;
400+ message =
401+ 'Unable to setup the GitKraken MCP server when offline. Please try again when you are online.' ;
402+ telemetryReason = 'offline' ;
403+ break ;
386404 default :
387405 reason = McpSetupErrorReason . CLIUnknownError ;
388406 message = 'Unable to setup the GitKraken MCP: Unknown error.' ;
@@ -446,6 +464,21 @@ export class GkCliIntegrationProvider implements Disposable {
446464 }
447465
448466 try {
467+ if ( isWeb ) {
468+ void this . container . storage
469+ . store ( 'gk:cli:install' , {
470+ status : 'unsupported' ,
471+ attempts : cliInstallAttempts ,
472+ } )
473+ . catch ( ) ;
474+
475+ throw new CLIInstallError ( CLIInstallErrorReason . UnsupportedPlatform , undefined , 'web' ) ;
476+ }
477+
478+ if ( isOffline ) {
479+ throw new CLIInstallError ( CLIInstallErrorReason . Offline ) ;
480+ }
481+
449482 cliInstallAttempts += 1 ;
450483 if ( this . container . telemetry . enabled ) {
451484 this . container . telemetry . sendEvent ( 'cli/install/started' , {
@@ -461,17 +494,6 @@ export class GkCliIntegrationProvider implements Disposable {
461494 } )
462495 . catch ( ) ;
463496
464- if ( isWeb ) {
465- void this . container . storage
466- . store ( 'gk:cli:install' , {
467- status : 'unsupported' ,
468- attempts : cliInstallAttempts ,
469- } )
470- . catch ( ) ;
471-
472- throw new CLIInstallError ( CLIInstallErrorReason . UnsupportedPlatform , undefined , 'web' ) ;
473- }
474-
475497 // Map platform names for the API and get architecture
476498 let platformName : string ;
477499 let architecture : string ;
@@ -797,6 +819,9 @@ class CLIInstallError extends Error {
797819 case CLIInstallErrorReason . GlobalStorageDirectory :
798820 message = 'Failed to create global storage directory' ;
799821 break ;
822+ case CLIInstallErrorReason . Offline :
823+ message = 'Offline' ;
824+ break ;
800825 default :
801826 message = 'An unknown error occurred' ;
802827 break ;
0 commit comments