diff --git a/apps/server/src/provider/AntigravityInstallation.test.ts b/apps/server/src/provider/AntigravityInstallation.test.ts index a9d98adf217ab..e889ff9ad203d 100644 --- a/apps/server/src/provider/AntigravityInstallation.test.ts +++ b/apps/server/src/provider/AntigravityInstallation.test.ts @@ -2,6 +2,7 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; import * as NodeServices from "@effect/platform-node/NodeServices"; import * as Layer from "effect/Layer"; import { expect, it } from "@effect/vitest"; +import { ProviderDriverKind } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Digest from "effect/crypto/Digest"; import * as Deferred from "effect/Deferred"; @@ -1324,3 +1325,30 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst }), ); }); + +it.each([ + { installedVersion: null, version: "1.6.0", expected: undefined }, + { installedVersion: "1.5.0", version: null, expected: "unknown" }, + { installedVersion: "1.5.0", version: "1.6.0", expected: "behind_latest" }, + { installedVersion: "1.10.0", version: "1.9.0", expected: "current" }, +] as const)( + "reports a $expected managed runtime version for $installedVersion against $version", + ({ installedVersion, version, expected }) => { + const advisory = AntigravityInstallation.managedRuntimeVersionAdvisory( + { + driver: ProviderDriverKind.make("antigravity"), + operationId: null, + phase: "idle", + downloadedBytes: 0, + totalBytes: null, + version, + installedVersion, + canRemove: true, + message: null, + }, + "2026-04-10T00:00:00.000Z", + ); + expect(advisory?.status).toBe(expected); + if (advisory) expect(advisory).toMatchObject({ canUpdate: true, updateCommand: null }); + }, +); diff --git a/apps/server/src/provider/AntigravityInstallation.ts b/apps/server/src/provider/AntigravityInstallation.ts index 7c33d909ad849..ffc942a1b989a 100644 --- a/apps/server/src/provider/AntigravityInstallation.ts +++ b/apps/server/src/provider/AntigravityInstallation.ts @@ -5,7 +5,11 @@ import { resolveProviderCompatibility } from "./providerCompatibility.ts"; import { cliArchiveTarCommand } from "@t3tools/shared/cliRelease"; import { compareSemverVersions } from "@t3tools/shared/semver"; import * as EffectNodeStream from "@effect/platform-node/NodeStream"; -import { ProviderDriverKind, type ProviderInstallState } from "@t3tools/contracts"; +import { + ProviderDriverKind, + type ProviderInstallState, + type ServerProviderVersionAdvisory, +} from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime"; import { resolveCommandPath } from "@t3tools/shared/shell"; @@ -173,6 +177,28 @@ function isAntigravityCli(...candidates: ReadonlyArray) { ); } +/** The managed runtime updates through installation, so it offers an update without a shell command. */ +export function managedRuntimeVersionAdvisory( + state: ProviderInstallState, + checkedAt: string, +): ServerProviderVersionAdvisory | undefined { + const currentVersion = state.installedVersion; + if (currentVersion === null) return undefined; + const latestVersion = state.version; + const behind = latestVersion !== null && compareSemverVersions(currentVersion, latestVersion) < 0; + return { + status: latestVersion === null ? "unknown" : behind ? "behind_latest" : "current", + currentVersion, + latestVersion, + updateCommand: null, + canUpdate: true, + checkedAt, + message: behind + ? `Install Antigravity ${latestVersion} now or review provider settings.` + : null, + }; +} + function isRunning(state: ProviderInstallState) { return ( state.phase === "downloading" || state.phase === "extracting" || state.phase === "verifying" diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts index 447745fc673a0..f23e75e6633b4 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.test.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.test.ts @@ -3,10 +3,12 @@ import * as NodeServices from "@effect/platform-node/NodeServices"; import { expect, it } from "@effect/vitest"; import { ANTIGRAVITY_DEFAULT_MODEL, + ProviderDriverKind, ProviderInstanceId, ProviderSessionId, ThreadId, type AntigravitySettings, + type ProviderInstallState, } from "@t3tools/contracts"; import * as HostProcess from "@t3tools/shared/HostProcess"; import * as Effect from "effect/Effect"; @@ -36,6 +38,17 @@ import * as ProviderHostLive from "../ProviderHostLive.ts"; import * as ServerSecretStore from "../../auth/ServerSecretStore.ts"; const hostPlatform = HostProcess.Platform.defaultValue(); +const idleInstallState: ProviderInstallState = { + driver: ProviderDriverKind.make("antigravity"), + operationId: null, + phase: "idle", + downloadedBytes: 0, + totalBytes: null, + version: null, + installedVersion: null, + canRemove: false, + message: null, +}; const windowsHost = hostPlatform === "win32"; const decodeRequest = Schema.decodeEffect( Schema.fromJsonString( @@ -147,6 +160,8 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* ( const layerInstallation = Layer.mock(AntigravityInstallation.AntigravityInstallation)({ managedDirectory: root, + state: Effect.succeed(idleInstallState), + checkForUpdate: Effect.void, resolve: () => Effect.gen(function* () { if (controls.failResolution) { @@ -570,6 +585,7 @@ it.layer(layerTest)("AntigravityDriver", (it) => { Effect.provide( Layer.mock(AntigravityInstallation.AntigravityInstallation)({ managedDirectory: config.stateDir, + state: Effect.succeed(idleInstallState), resolve: () => Effect.die("unused"), acquire: () => Effect.die("unused"), }), diff --git a/apps/server/src/provider/Drivers/AntigravityDriver.ts b/apps/server/src/provider/Drivers/AntigravityDriver.ts index 75bca5acc87be..3cc06d0a08ae3 100644 --- a/apps/server/src/provider/Drivers/AntigravityDriver.ts +++ b/apps/server/src/provider/Drivers/AntigravityDriver.ts @@ -192,10 +192,20 @@ export const AntigravityDriver: ProviderDriver< accentColor, continuationGroupKey: continuationIdentity.continuationKey, }); - const classifyModels = (draft: ServerProviderDraft) => - currentCatalog.pipe( - Effect.map((catalog) => stampIdentity(ModelCatalog.applyModelCatalog(draft, catalog))), + // `resolve` picks the managed runtime whenever no custom executable is set. + const usesManagedRuntime = settings.binaryPath.trim() === ""; + const classifyModels = Effect.fn("AntigravityDriver.classifyModels")(function* ( + draft: ServerProviderDraft, + ) { + const catalog = yield* currentCatalog; + const provider = stampIdentity(ModelCatalog.applyModelCatalog(draft, catalog)); + if (!usesManagedRuntime) return provider; + const versionAdvisory = AntigravityInstallation.managedRuntimeVersionAdvisory( + yield* installation.state, + provider.checkedAt, ); + return versionAdvisory ? { ...provider, versionAdvisory } : provider; + }); const makeRuntime = Effect.fn("AntigravityDriver.makeRuntime")(function* ( input: Omit, @@ -388,8 +398,11 @@ export const AntigravityDriver: ProviderDriver< // The probe must not spawn. The agent is a PyInstaller one-file bundle // that unpacks about 1 GB per launch, and the health check runs every // minute. + const driverScope = yield* Effect.scope; const probe = Effect.gen(function* () { yield* modelCatalog.refreshInBackground; + // Hourly at most; a newer release republishes this instance through its install state. + if (usesManagedRuntime) yield* Effect.forkIn(installation.checkForUpdate, driverScope); if (authConfigIssue !== null) { return yield* new ProviderSetupError({ instanceId, diff --git a/apps/server/src/provider/providerMaintenanceRunner.test.ts b/apps/server/src/provider/providerMaintenanceRunner.test.ts index 985347a66e96b..ad8e8cedc73f9 100644 --- a/apps/server/src/provider/providerMaintenanceRunner.test.ts +++ b/apps/server/src/provider/providerMaintenanceRunner.test.ts @@ -3,6 +3,7 @@ import { describe, it, assert } from "@effect/vitest"; import { ProviderDriverKind, ProviderInstanceId, + type ProviderInstallState, type ServerProvider, type ServerProviderUpdateState, } from "@t3tools/contracts"; @@ -29,6 +30,7 @@ import * as ServerSettings from "../serverSettings.ts"; import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts"; import * as TextGeneration from "../textGeneration/TextGeneration.ts"; import * as TextGenerators from "../textGeneration/TextGenerators.ts"; +import * as ProviderInstallation from "./providerInstallation.ts"; import * as ProviderInstallationGate from "./ProviderInstallationGate.ts"; import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts"; import * as ProviderRegistry from "./ProviderRegistry.ts"; @@ -37,11 +39,13 @@ import * as ProviderMaintenanceRunner from "./providerMaintenanceRunner.ts"; import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions"; import { enrichProviderSnapshotWithVersionAdvisory, + makeManualOnlyProviderMaintenanceCapabilities, makeProviderMaintenanceCapabilities, type ProviderMaintenanceCapabilities, } from "@t3tools/provider-core/server/maintenanceResolver"; const isServerProviderUpdateError = Schema.is(ServerProviderUpdateError); +const ANTIGRAVITY_DRIVER = ProviderDriverKind.make("antigravity"); const CODEX_DRIVER = ProviderDriverKind.make("codex"); const NATIVE_CLI_DRIVER = ProviderDriverKind.make("nativeCli"); const OPENCODE_DRIVER = ProviderDriverKind.make("opencode"); @@ -54,6 +58,9 @@ const encoder = new TextEncoder(); const layerNonWindowsPlatform = Layer.succeed(HostProcess.Platform, "linux"); function lifecycleFor(provider: ProviderDriverKind): ProviderMaintenanceCapabilities { + if (provider === ANTIGRAVITY_DRIVER) { + return makeManualOnlyProviderMaintenanceCapabilities({ provider, packageName: null }); + } if (provider === NATIVE_CLI_DRIVER) { return makeProviderMaintenanceCapabilities({ provider, @@ -249,6 +256,12 @@ const makeTestRunner = ( })), }, latestVersions: Layer.Layer = ProviderLatestVersions.layer, + installation: ProviderInstallation.ProviderInstallation["Service"] = { + start: () => Effect.die("unexpected managed install"), + cancel: () => Effect.die("unexpected managed install"), + subscribe: () => Stream.die("unexpected managed install"), + remove: () => Effect.die("unexpected managed install"), + }, ) => Effect.service(ProviderMaintenanceRunner.ProviderMaintenanceRunner).pipe( Effect.provide( @@ -264,6 +277,7 @@ const makeTestRunner = ( refreshInBackground: Effect.void, }), latestVersions, + Layer.succeed(ProviderInstallation.ProviderInstallation, installation), // Layers memoize by reference, so a test that provides the gate shares it. ProviderInstallationGate.layer, ), @@ -289,6 +303,87 @@ function layerFailingLatestLookupAfterFirst() { } describe("providerMaintenanceRunner", () => { + it.effect("updates a managed runtime by reinstalling it and reports the install outcome", () => + Effect.gen(function* () { + const antigravity: ServerProvider = { + ...baseProvider, + instanceId: ProviderInstanceId.make("antigravity"), + driver: ANTIGRAVITY_DRIVER, + versionAdvisory: { + status: "behind_latest", + currentVersion: "1.5.0", + latestVersion: "1.6.0", + updateCommand: null, + canUpdate: true, + checkedAt: baseProvider.checkedAt, + message: null, + }, + }; + const installState = ( + phase: ProviderInstallState["phase"], + message: string | null = null, + ): ProviderInstallState => ({ + driver: ANTIGRAVITY_DRIVER, + operationId: "op-1", + phase, + downloadedBytes: 0, + totalBytes: null, + version: "1.6.0", + installedVersion: "1.5.0", + canRemove: true, + message, + }); + const run = (ending: ProviderInstallState) => + Effect.gen(function* () { + const { registry, updateStatesRef } = yield* makeRegistry(antigravity); + const updater = yield* makeTestRunner(registry, undefined, undefined, { + start: () => Effect.succeed(installState("downloading")), + cancel: () => Effect.die("unused"), + // A stale operation and repeated byte progress must not reach the update state. + subscribe: () => + Stream.make( + { ...installState("succeeded"), operationId: "op-0" }, + installState("downloading"), + { ...installState("downloading"), downloadedBytes: 10 }, + installState("verifying"), + ending, + ), + remove: () => Effect.die("unused"), + }); + yield* updater.updateProvider({ + provider: ANTIGRAVITY_DRIVER, + instanceId: antigravity.instanceId, + }); + return (yield* Ref.get(updateStatesRef)).map((state) => [state.status, state.message]); + }); + + const progress = [ + ["queued", "Waiting for another provider update to finish."], + ["running", "Starting the update"], + ["running", "Downloading the update"], + ["running", "Verifying the update"], + ]; + assert.deepStrictEqual(yield* run(installState("succeeded")), [ + ...progress, + ["succeeded", "Provider updated."], + ]); + assert.deepStrictEqual(yield* run(installState("failed", "Checksum mismatch.")), [ + ...progress, + ["failed", "Checksum mismatch."], + ]); + }).pipe( + Effect.provide( + Layer.mergeAll( + layerNonWindowsPlatform, + layerLatestVersionHttpClient("1.0.0"), + layerMockSpawner(() => { + throw new Error("a managed runtime update must not run a command"); + }), + ), + ), + ), + ); + it.effect("runs the allowlisted provider update command and records success", () => { const calls: Array<{ command: string; args: ReadonlyArray }> = []; return Effect.gen(function* () { diff --git a/apps/server/src/provider/providerMaintenanceRunner.ts b/apps/server/src/provider/providerMaintenanceRunner.ts index 9ac62dca70419..efb149b4b2b58 100644 --- a/apps/server/src/provider/providerMaintenanceRunner.ts +++ b/apps/server/src/provider/providerMaintenanceRunner.ts @@ -2,6 +2,7 @@ import { defaultInstanceIdForDriver, ProviderDriverKind, ServerProviderUpdateError, + type ProviderInstallState, type ProviderInstanceId, type ServerProvider, type ServerProviderUpdatedPayload, @@ -25,6 +26,7 @@ import * as NodeUtil from "node:util"; import * as ModelManifest from "./ModelManifest.ts"; import { resolveProviderCompatibility } from "./providerCompatibility.ts"; +import * as ProviderInstallation from "./providerInstallation.ts"; import * as ProviderInstallationGate from "./ProviderInstallationGate.ts"; import * as ProviderRegistry from "./ProviderRegistry.ts"; import { makeProviderMaintenanceCommandCoordinator } from "./providerMaintenanceCommandCoordinator.ts"; @@ -301,6 +303,12 @@ function isStillInstalled(provider: ServerProvider): boolean { return provider.installed; } +const MANAGED_INSTALL_PHASE_MESSAGES: Partial> = { + downloading: "Downloading the update", + extracting: "Unpacking the update", + verifying: "Verifying the update", +}; + function makeUpdateState(input: { readonly status: ServerProviderUpdateState["status"]; readonly startedAt: string | null; @@ -325,6 +333,7 @@ export const make = Effect.fn("ProviderMaintenanceRunner.make")(function* () { const httpClient = yield* HttpClient.HttpClient; const latestVersions = yield* ProviderLatestVersions.ProviderLatestVersions; const installationGate = yield* ProviderInstallationGate.ProviderInstallationGate; + const providerInstallation = yield* ProviderInstallation.ProviderInstallation; const runMaintenanceCommand = ( update: ProviderMaintenanceCommandAction, onProgress: (line: string) => Effect.Effect, @@ -436,7 +445,15 @@ export const make = Effect.fn("ProviderMaintenanceRunner.make")(function* () { provider, ); const update = capabilities.update; - if (!update) { + // A runtime T3 Code installs itself updates by reinstalling, not through a command. + const updatesManagedRuntime = + update === null && + targetVersion === undefined && + (yield* providerRegistry.getProviders).some( + (candidate) => + candidate.instanceId === instanceId && candidate.versionAdvisory?.canUpdate === true, + ); + if (!update && !updatesManagedRuntime) { return yield* new ServerProviderUpdateError({ provider, reason: "This provider does not support one-click updates.", @@ -472,7 +489,7 @@ export const make = Effect.fn("ProviderMaintenanceRunner.make")(function* () { ); const runCommandAndVerify = Effect.fn("ProviderMaintenanceRunner.runCommandAndVerify")( - function* () { + function* (update: ProviderMaintenanceCommandAction) { const startedAt = yield* nowIso; yield* Ref.set(startedAtRef, startedAt); const setRunningMessage = (message: string) => @@ -684,14 +701,67 @@ export const make = Effect.fn("ProviderMaintenanceRunner.make")(function* () { }, ); - return yield* runCommandAndVerify().pipe(Effect.catchCause(recordFailedUpdate)); + const runManagedInstall = Effect.fn("ProviderMaintenanceRunner.runManagedInstall")( + function* () { + const startedAt = yield* nowIso; + yield* Ref.set(startedAtRef, startedAt); + const setRunningMessage = (message: string) => + setUpdateState( + makeUpdateState({ status: "running", startedAt, finishedAt: null, message }), + ).pipe(Effect.asVoid); + yield* setRunningMessage("Starting the update"); + const started = yield* providerInstallation.start({ instanceId }); + const ended = yield* providerInstallation.subscribe({ instanceId }).pipe( + Stream.filter((state) => state.operationId === started.operationId), + // Byte progress would resend the provider list to every client on each chunk. + Stream.changesWith((a, b) => a.phase === b.phase), + Stream.tap((state) => { + const message = MANAGED_INSTALL_PHASE_MESSAGES[state.phase]; + return message ? setRunningMessage(message) : Effect.void; + }), + Stream.filter( + (state) => + state.phase === "succeeded" || + state.phase === "failed" || + state.phase === "cancelled", + ), + Stream.runHead, + ); + const finishedAt = yield* nowIso; + if (Option.isNone(ended) || ended.value.phase !== "succeeded") { + return yield* finish( + makeUpdateState({ + status: "failed", + startedAt, + finishedAt, + message: + Option.getOrUndefined(ended)?.message ?? + "The update stopped before it finished.", + }), + ); + } + yield* providerRegistry.refreshInstance(instanceId); + return yield* finish( + makeUpdateState({ + status: "succeeded", + startedAt, + finishedAt, + message: "Provider updated.", + }), + ); + }, + ); + + return yield* (update ? runCommandAndVerify(update) : runManagedInstall()).pipe( + Effect.catchCause(recordFailedUpdate), + ); }, ); return yield* commandCoordinator .withCommandLock({ targetKey, - lockKey: update.lockKey, + lockKey: update?.lockKey ?? `${provider}-managed`, onQueued: setQueuedState, run: runProviderUpdate(), }) diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts index 01b659b0944ad..d39efec906d97 100644 --- a/apps/server/src/server.ts +++ b/apps/server/src/server.ts @@ -633,7 +633,10 @@ const layerProviderInstallationRefresh = Layer.effectDiscard( const providers = yield* ProviderRegistry.ProviderRegistry; yield* Stream.merge( antigravity.changes.pipe( - Stream.changesWith((a, b) => a.installedVersion === b.installedVersion), + // A newly offered release changes the managed runtime's version advisory. + Stream.changesWith( + (a, b) => a.installedVersion === b.installedVersion && a.version === b.version, + ), Stream.drop(1), ), codex.changes.pipe( diff --git a/apps/web/src/components/ProviderUpdateLaunchNotification.logic.test.ts b/apps/web/src/components/ProviderUpdateLaunchNotification.logic.test.ts index 764a76ba74f12..5cbad92363cde 100644 --- a/apps/web/src/components/ProviderUpdateLaunchNotification.logic.test.ts +++ b/apps/web/src/components/ProviderUpdateLaunchNotification.logic.test.ts @@ -130,6 +130,13 @@ describe("provider update launch notification logic", () => { ).toBe(true); }); + it("offers one-click updates for a managed runtime that has no shell command", () => { + const candidate = updateCandidate({ driver: driver("antigravity"), updateCommand: null }); + + expect(canOneClickUpdateProviderCandidate(candidate, [candidate])).toBe(true); + expect(isProviderSettingsUpdateCandidate(candidate)).toBe(true); + }); + it("keeps the inline update action available while a provider update is already running", () => { const candidate = updateCandidate({ driver: driver("codex"), diff --git a/apps/web/src/components/ProviderUpdateLaunchNotification.logic.ts b/apps/web/src/components/ProviderUpdateLaunchNotification.logic.ts index 9c9720d7e7e30..8cd302c7f39d4 100644 --- a/apps/web/src/components/ProviderUpdateLaunchNotification.logic.ts +++ b/apps/web/src/components/ProviderUpdateLaunchNotification.logic.ts @@ -19,10 +19,10 @@ export type ProviderUpdateCandidate = ServerProvider & { }; }; +// A managed runtime (Antigravity) updates without a shell command, so `updateCommand` may be null. export type ProviderSettingsUpdateCandidate = ServerProvider & { readonly versionAdvisory: NonNullable & { readonly canUpdate: true; - readonly updateCommand: string; }; }; @@ -144,8 +144,7 @@ export function isProviderSettingsUpdateCandidate( provider.compatibilityAdvisory?.latestVersionStatus !== "broken" && provider.compatibilityAdvisory?.latestVersionStatus !== "unsupported" && provider.versionAdvisory?.status === "behind_latest" && - provider.versionAdvisory.canUpdate === true && - provider.versionAdvisory.updateCommand !== null + provider.versionAdvisory.canUpdate === true ); } @@ -153,10 +152,7 @@ export function hasOneClickUpdateProviderCandidate( candidate: ProviderUpdateCandidate, providers: ReadonlyArray, ): boolean { - if ( - candidate.versionAdvisory.canUpdate !== true || - candidate.versionAdvisory.updateCommand === null - ) { + if (candidate.versionAdvisory.canUpdate !== true) { return false; } @@ -171,10 +167,10 @@ export function hasOneClickUpdateProviderCandidate( continue; } const advisory = provider.versionAdvisory; - if (!advisory || advisory.canUpdate !== true || advisory.updateCommand === null) { + if (!advisory || advisory.canUpdate !== true) { return false; } - updateCommands.add(advisory.updateCommand); + updateCommands.add(advisory.updateCommand ?? ""); } return updateCommands.size === 1;