@@ -19,7 +19,6 @@ import type { IpcServer } from './ipcServer';
1919import { createIpcServer } from './ipcServer' ;
2020
2121const enum CLIInstallErrorReason {
22- WebEnvironmentUnsupported ,
2322 UnsupportedPlatform ,
2423 ProxyUrlFetch ,
2524 ProxyUrlFormat ,
@@ -147,10 +146,16 @@ export class GkCliIntegrationProvider implements Disposable {
147146 cancellable : false ,
148147 } ,
149148 async ( ) => {
150- const { cliVersion : installedVersion , cliPath : installedPath } = await this . installCLI (
151- false ,
152- source ,
153- ) ;
149+ const {
150+ cliVersion : installedVersion ,
151+ cliPath : installedPath ,
152+ status,
153+ } = await this . installCLI ( false , source ) ;
154+ if ( status === 'unsupported' ) {
155+ throw new CLIInstallError ( CLIInstallErrorReason . UnsupportedPlatform ) ;
156+ } else if ( status === 'attempted' ) {
157+ throw new CLIInstallError ( CLIInstallErrorReason . CoreInstall ) ;
158+ }
154159 cliVersion = installedVersion ;
155160 cliPath = installedPath ;
156161 } ,
@@ -159,12 +164,6 @@ export class GkCliIntegrationProvider implements Disposable {
159164 let failureReason = 'unknown error' ;
160165 if ( ex instanceof CLIInstallError ) {
161166 switch ( ex . reason ) {
162- case CLIInstallErrorReason . WebEnvironmentUnsupported :
163- void window . showErrorMessage (
164- 'GitKraken MCP installation is not supported on this platform.' ,
165- ) ;
166- failureReason = 'web environment unsupported' ;
167- break ;
168167 case CLIInstallErrorReason . UnsupportedPlatform :
169168 void window . showErrorMessage (
170169 'GitKraken MCP installation is not supported on this platform.' ,
@@ -306,50 +305,47 @@ export class GkCliIntegrationProvider implements Disposable {
306305 private async installCLI (
307306 autoInstall ?: boolean ,
308307 source ?: Sources ,
309- ) : Promise < { cliVersion ?: string ; cliPath ?: string } > {
310- let attempts = 0 ;
311- let cliVersion : string | undefined ;
312- let cliPath : string | undefined ;
308+ ) : Promise < { cliVersion ?: string ; cliPath ?: string ; status : 'completed' | 'unsupported' | 'attempted' } > {
313309 const cliInstall = this . container . storage . get ( 'gk:cli:install' ) ;
314- if ( autoInstall ) {
315- if ( cliInstall ?. status === 'completed' ) {
316- cliVersion = cliInstall . version ;
317- cliPath = this . container . storage . get ( 'gk:cli:path' ) ;
318- return { cliVersion : cliVersion , cliPath : cliPath } ;
319- } else if (
320- cliInstall ?. status === 'unsupported' ||
321- ( cliInstall ?. status === 'attempted' && cliInstall . attempts >= 5 )
322- ) {
323- return { cliVersion : undefined , cliPath : undefined } ;
324- }
310+ let cliInstallAttempts = cliInstall ?. attempts ?? 0 ;
311+ let cliInstallStatus = cliInstall ?. status ?? 'attempted' ;
312+ let cliVersion = cliInstall ?. version ;
313+ let cliPath = this . container . storage . get ( 'gk:cli:path' ) ;
314+
315+ if ( cliInstallStatus === 'completed' ) {
316+ cliVersion = cliInstall ?. version ;
317+ return { cliVersion : cliVersion , cliPath : cliPath , status : 'completed' } ;
318+ } else if ( cliInstallStatus === 'unsupported' ) {
319+ return { cliVersion : undefined , cliPath : undefined , status : 'unsupported' } ;
320+ } else if ( autoInstall && cliInstallStatus === 'attempted' && cliInstallAttempts >= 5 ) {
321+ return { cliVersion : undefined , cliPath : undefined , status : 'attempted' } ;
325322 }
326323
327324 try {
328- attempts = cliInstall ?. attempts ?? 0 ;
329- attempts += 1 ;
325+ cliInstallAttempts += 1 ;
330326 if ( this . container . telemetry . enabled ) {
331327 this . container . telemetry . sendEvent ( 'cli/install/started' , {
332328 source : source ,
333329 autoInstall : autoInstall ?? false ,
334- attempts : attempts ,
330+ attempts : cliInstallAttempts ,
335331 } ) ;
336332 }
337333 void this . container . storage
338334 . store ( 'gk:cli:install' , {
339335 status : 'attempted' ,
340- attempts : attempts ,
336+ attempts : cliInstallAttempts ,
341337 } )
342338 . catch ( ) ;
343339
344340 if ( isWeb ) {
345341 void this . container . storage
346342 . store ( 'gk:cli:install' , {
347343 status : 'unsupported' ,
348- attempts : attempts ,
344+ attempts : cliInstallAttempts ,
349345 } )
350346 . catch ( ) ;
351347
352- throw new CLIInstallError ( CLIInstallErrorReason . WebEnvironmentUnsupported ) ;
348+ throw new CLIInstallError ( CLIInstallErrorReason . UnsupportedPlatform , undefined , 'web' ) ;
353349 }
354350
355351 // Detect platform and architecture
@@ -385,7 +381,7 @@ export class GkCliIntegrationProvider implements Disposable {
385381 void this . container . storage
386382 . store ( 'gk:cli:install' , {
387383 status : 'unsupported' ,
388- attempts : attempts ,
384+ attempts : cliInstallAttempts ,
389385 } )
390386 . catch ( ) ;
391387 throw new CLIInstallError ( CLIInstallErrorReason . UnsupportedPlatform , undefined , platform ) ;
@@ -532,13 +528,18 @@ export class GkCliIntegrationProvider implements Disposable {
532528 }
533529
534530 Logger . log ( 'CLI install completed.' ) ;
531+ cliInstallStatus = 'completed' ;
535532 void this . container . storage
536- . store ( 'gk:cli:install' , { status : 'completed' , attempts : attempts , version : cliVersion } )
533+ . store ( 'gk:cli:install' , {
534+ status : cliInstallStatus ,
535+ attempts : cliInstallAttempts ,
536+ version : cliVersion ,
537+ } )
537538 . catch ( ) ;
538539 if ( this . container . telemetry . enabled ) {
539540 this . container . telemetry . sendEvent ( 'cli/install/succeeded' , {
540541 autoInstall : autoInstall ?? false ,
541- attempts : attempts ,
542+ attempts : cliInstallAttempts ,
542543 source : source ,
543544 version : cliVersion ,
544545 } ) ;
@@ -575,17 +576,20 @@ export class GkCliIntegrationProvider implements Disposable {
575576 if ( this . container . telemetry . enabled ) {
576577 this . container . telemetry . sendEvent ( 'cli/install/failed' , {
577578 autoInstall : autoInstall ?? false ,
578- attempts : attempts ,
579+ attempts : cliInstallAttempts ,
579580 'error.message' : ex instanceof Error ? ex . message : 'Unknown error' ,
580581 source : source ,
581582 } ) ;
582583 }
583- if ( ! autoInstall ) {
584+
585+ if ( CLIInstallError . is ( ex , CLIInstallErrorReason . UnsupportedPlatform ) ) {
586+ cliInstallStatus = 'unsupported' ;
587+ } else if ( ! autoInstall ) {
584588 throw ex ;
585589 }
586590 }
587591
588- return { cliVersion : cliVersion , cliPath : cliPath } ;
592+ return { cliVersion : cliVersion , cliPath : cliPath , status : cliInstallStatus } ;
589593 }
590594
591595 private async runCLICommand (
@@ -652,9 +656,6 @@ class CLIInstallError extends Error {
652656 private static buildErrorMessage ( reason : CLIInstallErrorReason , details ?: string ) : string {
653657 let message ;
654658 switch ( reason ) {
655- case CLIInstallErrorReason . WebEnvironmentUnsupported :
656- message = 'Web environment is not supported' ;
657- break ;
658659 case CLIInstallErrorReason . UnsupportedPlatform :
659660 message = 'Unsupported platform' ;
660661 break ;
0 commit comments