diff --git a/core/util/GlobalContext.ts b/core/util/GlobalContext.ts index 59daf21c9..0a1778395 100644 --- a/core/util/GlobalContext.ts +++ b/core/util/GlobalContext.ts @@ -44,9 +44,8 @@ export type GlobalContextType = { isSupportedLanceDbCpuTargetForLinux: boolean; sharedConfig: SharedConfigSchema; failedDocs: SiteIndexingConfig[]; - shownDeprecatedProviderWarnings: { - [providerTitle: string]: boolean; - }; + shownDeprecatedProviderWarnings: { [providerTitle: string]: boolean }; + autoUpdateCli: boolean; mcpOauthStorage: { [serverUrl: string]: { clientInformation?: OAuthClientInformationFull; @@ -66,16 +65,7 @@ export class GlobalContext { ) { const filepath = getGlobalContextFilePath(); if (!fs.existsSync(filepath)) { - fs.writeFileSync( - filepath, - JSON.stringify( - { - [key]: value, - }, - null, - 2, - ), - ); + fs.writeFileSync(filepath, JSON.stringify({ [key]: value }, null, 2)); } else { const data = fs.readFileSync(filepath, "utf-8"); @@ -113,10 +103,7 @@ export class GlobalContext { } // Recreate the file with salvaged values plus the new value - const newData = { - ...salvaged, - [key]: value, - }; + const newData = { ...salvaged, [key]: value }; fs.writeFileSync(filepath, JSON.stringify(newData, null, 2)); return; @@ -174,10 +161,7 @@ export class GlobalContext { newValues: Partial, ): SharedConfigSchema { const currentSharedConfig = this.getSharedConfig(); - const updatedSharedConfig = { - ...currentSharedConfig, - ...newValues, - }; + const updatedSharedConfig = { ...currentSharedConfig, ...newValues }; this.update("sharedConfig", updatedSharedConfig); return updatedSharedConfig; } @@ -189,10 +173,7 @@ export class GlobalContext { ): GlobalContextModelSelections { const currentSelections = this.get("selectedModelsByProfileId") ?? {}; const forProfile = currentSelections[profileId] ?? {}; - const newSelections = { - ...forProfile, - [role]: title, - }; + const newSelections = { ...forProfile, [role]: title }; this.update("selectedModelsByProfileId", { ...currentSelections, diff --git a/extensions/cli/src/services/UpdateService.ts b/extensions/cli/src/services/UpdateService.ts index 71e99ea57..24024aa9a 100644 --- a/extensions/cli/src/services/UpdateService.ts +++ b/extensions/cli/src/services/UpdateService.ts @@ -1,10 +1,13 @@ import { exec, spawn } from "child_process"; -import { logger } from "src/util/logger.js"; import { promisify } from "util"; + +import { logger } from "src/util/logger.js"; + import { compareVersions, getLatestVersion, getVersion } from "../version.js"; + +import { GlobalContext } from "core/util/GlobalContext.js"; import { serviceContainer } from "./ServiceContainer.js"; import { UpdateServiceState, UpdateStatus } from "./types.js"; - const execAsync = promisify(exec); /** @@ -16,7 +19,7 @@ export class UpdateService { constructor() { this.state = { - autoUpdate: true, // TODO make configurable + autoUpdate: false, status: UpdateStatus.IDLE, message: "", error: null, @@ -43,26 +46,33 @@ export class UpdateService { } private async checkAndAutoUpdate() { + const globalContext = new GlobalContext(); + const autoUpdate = globalContext.get("autoUpdateCli"); + if (autoUpdate === false) { + return; + } + await this.checkForUpdates(); if (this.state.currentVersion === "0.0.0-dev") { - return; // Uncomment to test update behavior + return; // Uncomment to test auto-update behavior in dev } // If update is available, automatically update - if ( - this.state.isUpdateAvailable && - this.state.autoUpdate && - this.state.status !== "updating" - ) { + if (this.state.isUpdateAvailable && this.state.status !== "updating") { if (process.env.CONTINUE_CLI_AUTO_UPDATED) { logger.debug("Already auto updated, preventing sequential auto-update"); - } else { - await this.performUpdate(true); + return; } + await this.performUpdate(true); } } + public async setAutoUpdate(value: boolean) { + const globalContext = new GlobalContext(); + globalContext.update("autoUpdateCli", value); + } + private async checkForUpdates() { try { this.updateState({ diff --git a/extensions/cli/src/ui/UpdateSelector.tsx b/extensions/cli/src/ui/UpdateSelector.tsx index 813c50b61..69a89d30b 100644 --- a/extensions/cli/src/ui/UpdateSelector.tsx +++ b/extensions/cli/src/ui/UpdateSelector.tsx @@ -3,10 +3,10 @@ import React, { useMemo, useState } from "react"; import { useService } from "../hooks/useService.js"; import { services } from "../services/index.js"; import { SERVICE_NAMES } from "../services/types.js"; +import type { UpdateServiceState } from "../services/types.js"; import { Selector, SelectorOption } from "./Selector.js"; -import type { UpdateServiceState } from "../services/types.js"; interface UpdateSelectorProps { onCancel: () => void; diff --git a/extensions/cli/src/ui/components/ScreenContent.tsx b/extensions/cli/src/ui/components/ScreenContent.tsx index 8f0d7da3f..00aa819aa 100644 --- a/extensions/cli/src/ui/components/ScreenContent.tsx +++ b/extensions/cli/src/ui/components/ScreenContent.tsx @@ -8,8 +8,8 @@ import { FreeTrialTransitionUI } from "../FreeTrialTransitionUI.js"; import { MCPSelector } from "../MCPSelector.js"; import { ModelSelector } from "../ModelSelector.js"; import { SessionSelector } from "../SessionSelector.js"; -import { UpdateSelector } from "../UpdateSelector.js"; import type { ConfigOption, ModelOption } from "../types/selectorTypes.js"; +import { UpdateSelector } from "../UpdateSelector.js"; import { UserInput } from "../UserInput.js"; import { ToolPermissionSelector } from "./ToolPermissionSelector.js";