wip: global context for auto update for cli

This commit is contained in:
Dallin Romney 2025-09-03 10:53:39 -07:00
parent 75fd033d2c
commit a93aeda2e6
4 changed files with 29 additions and 38 deletions

View file

@ -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>,
): 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,

View file

@ -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({

View file

@ -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;

View file

@ -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";