Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export class Container {
this._context = context;
this._prerelease = prerelease;
this._version = version;
this._previousVersion = previousVersion;
this.ensureModeApplied();

this._disposables = [
Expand Down Expand Up @@ -747,6 +748,11 @@ export class Container {
return this._version;
}

private readonly _previousVersion: string | undefined;
get previousVersion(): string | undefined {
return this._previousVersion;
}

private readonly _views: Views;
get views(): Views {
return this._views;
Expand Down
1 change: 1 addition & 0 deletions src/env/browser/platform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Platform } from '../node/platform';

export const isWeb = true;
export const isOffline = false;

const _platform = (navigator as any)?.userAgentData?.platform;
const _userAgent = navigator.userAgent;
Expand Down
51 changes: 38 additions & 13 deletions src/env/node/gk/cli/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { gate } from '../../../../system/decorators/gate';
import { debug, log } from '../../../../system/decorators/log';
import { Logger } from '../../../../system/logger';
import { getLogScope, setLogScopeExit } from '../../../../system/logger.scope';
import { compare } from '../../../../system/version';
import { getPlatform, isWeb } from '../../platform';
import { compare, fromString, satisfies } from '../../../../system/version';
import { getPlatform, isOffline, isWeb } from '../../platform';
import { CliCommandHandlers } from './commands';
import type { IpcServer } from './ipcServer';
import { createIpcServer } from './ipcServer';
Expand All @@ -32,6 +32,7 @@ const enum CLIInstallErrorReason {
ProxyFetch,
GlobalStorageDirectory,
CoreInstall,
Offline,
}

const enum McpSetupErrorReason {
Expand All @@ -44,6 +45,7 @@ const enum McpSetupErrorReason {
UnsupportedHost,
UnsupportedClient,
UnexpectedOutput,
Offline,
}

export interface CliCommandRequest {
Expand Down Expand Up @@ -118,6 +120,15 @@ export class GkCliIntegrationProvider implements Disposable {
return;
}

// Reset the attempts count if GitLens extension version has changed
if (
reachedMaxAttempts(cliInstall) &&
this.container.version !== this.container.previousVersion &&
satisfies(fromString(this.container.version), '>= 17.6')
) {
void this.container.storage.store('gk:cli:install', undefined);
}

if (!mcpExtensionRegistrationAllowed() || reachedMaxAttempts(cliInstall)) {
return;
}
Expand Down Expand Up @@ -164,6 +175,7 @@ export class GkCliIntegrationProvider implements Disposable {
switch (ex.reason) {
case McpSetupErrorReason.WebUnsupported:
case McpSetupErrorReason.VSCodeVersionUnsupported:
case McpSetupErrorReason.Offline:
void window.showWarningMessage(ex.message);
break;
case McpSetupErrorReason.InstallationFailed:
Expand Down Expand Up @@ -383,6 +395,12 @@ export class GkCliIntegrationProvider implements Disposable {
message = 'Unable to locally install the GitKraken MCP server. Please try again.';
telemetryReason = 'local installation failed';
break;
case CLIInstallErrorReason.Offline:
reason = McpSetupErrorReason.Offline;
message =
'Unable to setup the GitKraken MCP server when offline. Please try again when you are online.';
telemetryReason = 'offline';
break;
default:
reason = McpSetupErrorReason.CLIUnknownError;
message = 'Unable to setup the GitKraken MCP: Unknown error.';
Expand Down Expand Up @@ -446,6 +464,21 @@ export class GkCliIntegrationProvider implements Disposable {
}

try {
if (isWeb) {
void this.container.storage
.store('gk:cli:install', {
status: 'unsupported',
attempts: cliInstallAttempts,
})
.catch();

throw new CLIInstallError(CLIInstallErrorReason.UnsupportedPlatform, undefined, 'web');
}

if (isOffline) {
throw new CLIInstallError(CLIInstallErrorReason.Offline);
}

cliInstallAttempts += 1;
if (this.container.telemetry.enabled) {
this.container.telemetry.sendEvent('cli/install/started', {
Expand All @@ -461,17 +494,6 @@ export class GkCliIntegrationProvider implements Disposable {
})
.catch();

if (isWeb) {
void this.container.storage
.store('gk:cli:install', {
status: 'unsupported',
attempts: cliInstallAttempts,
})
.catch();

throw new CLIInstallError(CLIInstallErrorReason.UnsupportedPlatform, undefined, 'web');
}

// Map platform names for the API and get architecture
let platformName: string;
let architecture: string;
Expand Down Expand Up @@ -797,6 +819,9 @@ class CLIInstallError extends Error {
case CLIInstallErrorReason.GlobalStorageDirectory:
message = 'Failed to create global storage directory';
break;
case CLIInstallErrorReason.Offline:
message = 'Offline';
break;
default:
message = 'An unknown error occurred';
break;
Expand Down
3 changes: 2 additions & 1 deletion src/env/node/platform.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { tmpdir } from 'os';
import { networkInterfaces, tmpdir } from 'os';
import { join } from 'path';
import { platform } from 'process';
import { env, UIKind } from 'vscode';

export const isWeb = env.uiKind === UIKind.Web;
export const isOffline = Object.values(networkInterfaces()).every(iface => iface?.every(addr => addr.internal));

export const isLinux = platform === 'linux';
export const isMac = platform === 'darwin';
Expand Down
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ async function showWhatsNew(

function showMcp(version: string, previousVersion: string | undefined): void {
if (
isWeb ||
previousVersion == null ||
version === previousVersion ||
compare(version, previousVersion) !== 1 ||
Expand Down
4 changes: 2 additions & 2 deletions src/plus/gk/utils/-webview/mcp.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { env, lm, version } from 'vscode';
import { isWeb } from '@env/platform';
import { isOffline, isWeb } from '@env/platform';
import type { Container } from '../../../../container';
import { configuration } from '../../../../system/-webview/configuration';
import { satisfies } from '../../../../system/version';
Expand All @@ -15,7 +15,7 @@ export function isMcpBannerEnabled(container: Container, showAutoRegistration =

const supportedApps = ['Visual Studio Code', 'Visual Studio Code - Insiders', 'Visual Studio Code - Exploration'];
export function supportsMcpExtensionRegistration(): boolean {
if (isWeb || !supportedApps.includes(env.appName)) {
if (isWeb || isOffline || !supportedApps.includes(env.appName)) {
return false;
}

Expand Down