TypeScript
fix(web): show idle server updates on environment controls (#21950)
Julius Marminge89f0946efbc7
diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.tsindex 2b55b3f7198..5d68ff76c2d 100644--- a/apps/web/src/components/BranchToolbar.logic.test.ts+++ b/apps/web/src/components/BranchToolbar.logic.test.ts@@ -439,6 +439,37 @@ describe("shouldShowEnvironmentIndicator", () => {});describe("shouldShowComposerContextStrip", () => {+ it("keeps a sole primary server update reachable in a non-Git draft", () => {+ const environment = {+ activeEnvironment: { isPrimary: true },+ canPickEnvironment: false,+ serverUpdateAvailable: true,+ };+ const showEnvironmentIndicator = shouldShowEnvironmentIndicator(environment);+ expect(showEnvironmentIndicator).toBe(true);+ expect(+ shouldShowComposerContextStrip({+ isDraftHeroState: true,+ persistInActiveThreads: false,+ hasActiveProject: true,+ isGitRepo: false,+ showEnvironmentIndicator,+ hostsRestingComposerControls: false,+ }),+ ).toBe(true);+ expect(+ shouldShowComposerContextStrip({+ isDraftHeroState: false,+ persistInActiveThreads: false,+ hasActiveProject: true,+ isGitRepo: false,+ showEnvironmentIndicator,+ serverUpdateAvailable: true,+ hostsRestingComposerControls: false,+ }),+ ).toBe(true);+ });+it.each([false, true])("honors the active-thread preference with resting controls %s",(hostsRestingComposerControls) => {diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.tsindex 1b375c7bfe3..ee1c891f24d 100644--- a/apps/web/src/components/BranchToolbar.logic.ts+++ b/apps/web/src/components/BranchToolbar.logic.ts@@ -55,8 +55,9 @@ export function resolveEnvironmentOptionLabel(input: {export function shouldShowEnvironmentIndicator(input: {activeEnvironment: Pick<EnvironmentOption, "isPrimary"> | null;canPickEnvironment: boolean;+ serverUpdateAvailable?: boolean;}): boolean {- if (input.canPickEnvironment) return true;+ if (input.canPickEnvironment || input.serverUpdateAvailable) return true;return input.activeEnvironment !== null && !input.activeEnvironment.isPrimary;}@@ -67,10 +68,13 @@ export function shouldShowComposerContextStrip(input: {isGitRepo: boolean;showEnvironmentIndicator: boolean;hostsRestingComposerControls: boolean;+ serverUpdateAvailable?: boolean;}): boolean {return (input.hasActiveProject &&- (input.isDraftHeroState || input.persistInActiveThreads) &&+ (input.isDraftHeroState ||+ input.persistInActiveThreads ||+ input.serverUpdateAvailable === true) &&(input.isGitRepo || input.showEnvironmentIndicator || input.hostsRestingComposerControls));}diff --git a/apps/web/src/components/BranchToolbar.panel.browser.test.tsx b/apps/web/src/components/BranchToolbar.panel.browser.test.tsxindex 17121e17fec..82c26e01175 100644--- a/apps/web/src/components/BranchToolbar.panel.browser.test.tsx+++ b/apps/web/src/components/BranchToolbar.panel.browser.test.tsx@@ -19,6 +19,10 @@ vi.mock(import("../localApi"), async (original) => ({vi.mock(import("../hooks/useCopyToClipboard"), async (original) => ({...(await original()),writeTextToClipboard: state.writeTextToClipboard,+ useCopyToClipboard: ((options: { target: string }) => ({+ copyToClipboard: (command: string) => state.writeTextToClipboard(command, options.target),+ isCopied: false,+ })) as never,}));vi.mock(import("./BranchToolbarBranchSelector"), async (original) => ({...(await original()),@@ -36,6 +40,8 @@ vi.mock(import("../state/entities"), async (original) => ({}));import { BranchToolbar } from "./BranchToolbar";+import { ComposerSurface } from "./chat/ComposerSurface";+import type { ServerUpdateTarget } from "./ServerUpdateAction";let root: Root;let container: HTMLDivElement;@@ -59,19 +65,21 @@ afterEach(async () => {function render(props: Partial<ComponentProps<typeof BranchToolbar>>) {return act(async () =>root.render(- <BranchToolbar- layout="panel"- panelSection="workspace"- environmentId={EnvironmentId.make("local")}- threadId={ThreadId.make("thread")}- showGitControls- envMode="local"- envLocked={false}- startFromOrigin={false}- onStartFromOriginChange={vi.fn()}- onEnvModeChange={vi.fn()}- {...props}- />,+ <ComposerSurface.Shell>+ <BranchToolbar+ layout="panel"+ panelSection="workspace"+ environmentId={EnvironmentId.make("local")}+ threadId={ThreadId.make("thread")}+ showGitControls+ envMode="local"+ envLocked={false}+ startFromOrigin={false}+ onStartFromOriginChange={vi.fn()}+ onEnvModeChange={vi.fn()}+ {...props}+ />+ </ComposerSurface.Shell>,),);}@@ -146,3 +154,55 @@ it.each([}},);++it.each([+ { layout: "wide Git", width: 900, showGitControls: true },+ { layout: "narrow Git", width: 360, showGitControls: true },+ { layout: "sole primary non-Git", width: 360, showGitControls: false },+])(+ "copies the pending update from the $layout composer chip",+ async ({ width, showGitControls }) => {+ await page.viewport(1000, 700);+ container.style.width = `${width}px`;+ container.style.setProperty("--chat-content-max-width", `${width}px`);+ const serverUpdate = {+ environmentId: EnvironmentId.make("local"),+ serverLabel: "Build box",+ serverVersion: "0.0.30",+ targetVersion: "0.0.31",+ selfUpdate: null,+ installation: { kind: "npm-global", prefix: "/opt/node" },+ } satisfies ServerUpdateTarget & { serverVersion: string };+ await render({+ layout: "composer",+ envLocked: showGitControls,+ showGitControls,+ availableEnvironments: [+ {+ environmentId: serverUpdate.environmentId,+ projectId: ProjectId.make("project"),+ label: serverUpdate.serverLabel,+ isPrimary: true,+ machine: "server",+ },+ ],+ serverUpdate,+ });++ expect(+ container.querySelector('[data-slot="composer-shell"]')!.getBoundingClientRect().width,+ ).toBe(width);+ const chip = page.getByRole("button", { name: /Build box|Copy update command/ });+ await expect.element(chip).toBeVisible();+ await userEvent.hover(chip);+ await expect.element(page.getByRole("tooltip")).toMatchTextContent("0.0.30");+ await expect.element(page.getByRole("tooltip")).toMatchTextContent("0.0.31");+ await userEvent.click(chip);+ await vi.waitFor(() =>+ expect(state.writeTextToClipboard).toHaveBeenCalledWith(+ "npm install --global --prefix '/opt/node' [email protected]",+ "update command",+ ),+ );+ },+);diff --git a/apps/web/src/components/BranchToolbar.tsx b/apps/web/src/components/BranchToolbar.tsxindex f546658a377..eca987fe57f 100644--- a/apps/web/src/components/BranchToolbar.tsx+++ b/apps/web/src/components/BranchToolbar.tsx@@ -42,6 +42,7 @@ import {type BranchToolbarBranchSelectorHandle,} from "./BranchToolbarBranchSelector";import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";+import type { PendingServerUpdate } from "./ServerUpdateAction";import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector";import { PreviousWorktreeItemContent } from "./PreviousWorktreeItemContent";import { ThreadDetailsControl } from "./chat/ThreadDetailsControl";@@ -99,6 +100,7 @@ interface BranchToolbarProps {onEnvironmentChange?: (environmentId: EnvironmentId) => void;composerControlsHostRef?: (element: HTMLDivElement | null) => void;contextStripVisible?: boolean;+ serverUpdate?: PendingServerUpdate | null;}function showWorkspaceContextMenu(event: ReactMouseEvent, workspacePath: string) {@@ -586,6 +588,7 @@ export const BranchToolbar = memo(function BranchToolbar({onEnvironmentChange,composerControlsHostRef,contextStripVisible = true,+ serverUpdate = null,}: BranchToolbarProps) {const branchSelectorRef = useRef<BranchToolbarBranchSelectorHandle>(null);const threadRef = scopeThreadRef(environmentId, threadId);@@ -659,6 +662,7 @@ export const BranchToolbar = memo(function BranchToolbar({const showEnvironmentIndicator = shouldShowEnvironmentIndicator({activeEnvironment: activeEnvironmentOption,canPickEnvironment: hasMultipleEnvironments,+ serverUpdateAvailable: serverUpdate !== null,});const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);const labelsOverflow = useLabelsOverflow(stripElement);@@ -723,6 +727,17 @@ export const BranchToolbar = memo(function BranchToolbar({!contextStripVisible && "pointer-events-none invisible absolute inset-x-0 top-full",)}>+ {serverUpdate && availableEnvironments ? (+ <BranchToolbarEnvironmentSelector+ autoEnvironmentLabel={autoEnvironmentLabel}+ onAutoEnvironment={onAutoEnvironment}+ envLocked={envLocked}+ environmentId={environmentId}+ availableEnvironments={availableEnvironments}+ {...(showEnvironmentPicker ? { onEnvironmentChange } : {})}+ serverUpdate={serverUpdate}+ />+ ) : null}{showGitControls ? (<div className="contents @3xl/composer-surface:hidden"><RunContextSelector@@ -733,8 +748,8 @@ export const BranchToolbar = memo(function BranchToolbar({envModeLocked={envModeLocked}environmentId={environmentId}availableEnvironments={availableEnvironments}- showEnvironmentPicker={showEnvironmentPicker}- showEnvironmentIndicator={showEnvironmentIndicator}+ showEnvironmentPicker={showEnvironmentPicker && serverUpdate === null}+ showEnvironmentIndicator={showEnvironmentIndicator && serverUpdate === null}onEnvironmentChange={onEnvironmentChange}effectiveEnvMode={effectiveEnvMode}activeWorktreePath={activeWorktreePath}@@ -745,7 +760,7 @@ export const BranchToolbar = memo(function BranchToolbar({/></div>) : null}- {showGitControls || showEnvironmentIndicator ? (+ {showGitControls || (showEnvironmentIndicator && serverUpdate === null) ? (<divclassName={cn("min-h-7 min-w-10 items-center gap-1 sm:min-h-6",@@ -755,14 +770,16 @@ export const BranchToolbar = memo(function BranchToolbar({>{showEnvironmentIndicator && availableEnvironments && (<>- <BranchToolbarEnvironmentSelector- autoEnvironmentLabel={autoEnvironmentLabel}- onAutoEnvironment={onAutoEnvironment}- envLocked={envLocked}- environmentId={environmentId}- availableEnvironments={availableEnvironments}- {...(showEnvironmentPicker ? { onEnvironmentChange } : {})}- />+ {serverUpdate === null ? (+ <BranchToolbarEnvironmentSelector+ autoEnvironmentLabel={autoEnvironmentLabel}+ onAutoEnvironment={onAutoEnvironment}+ envLocked={envLocked}+ environmentId={environmentId}+ availableEnvironments={availableEnvironments}+ {...(showEnvironmentPicker ? { onEnvironmentChange } : {})}+ />+ ) : null}{showGitControls ? (<Separatororientation="vertical"diff --git a/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx b/apps/web/src/components/BranchToolbarEnvironmentSelector.tsxindex 038f33f02e9..e93094d7c32 100644--- a/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx+++ b/apps/web/src/components/BranchToolbarEnvironmentSelector.tsx@@ -1,14 +1,19 @@-import { ComposerSelectControl } from "./chat/ComposerControl";+import { ComposerControl, ComposerSelectControl } from "./chat/ComposerControl";import { ComposerContextLabel } from "./ComposerContextLabel";import { Tooltip, TooltipTrigger, TooltipPopup } from "./ui/tooltip";import { useAtomValue } from "@effect/atom-react";import { shortcutLabelForCommand } from "../keybindings";import { primaryServerKeybindingsAtom } from "../state/server";import type { EnvironmentId } from "@t3tools/contracts";-import { ScaleIcon } from "lucide-react";+import { CircleArrowUpIcon, ScaleIcon } from "lucide-react";import { memo } from "react";import type { EnvironmentOption } from "./BranchToolbar.logic";+import {+ ServerUpdateAction,+ type PendingServerUpdate,+ type ServerUpdateControl,+} from "./ServerUpdateAction";import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";import { useComposerMenuProps } from "./chat/composerEventScope";import {@@ -27,16 +32,39 @@ interface BranchToolbarEnvironmentSelectorProps {environmentId: EnvironmentId;availableEnvironments: readonly EnvironmentOption[];onEnvironmentChange?: (environmentId: EnvironmentId) => void;+ serverUpdate?: PendingServerUpdate | null;}-export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvironmentSelector({+// Action values cannot collide with server-minted environment IDs.+const AUTO_VALUE = "action:auto";+const UPDATE_VALUE = "action:update";+const environmentValue = (id: EnvironmentId) => `env:${id}`;++export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvironmentSelector(+ props: BranchToolbarEnvironmentSelectorProps,+) {+ return props.serverUpdate ? (+ <ServerUpdateAction+ {...props.serverUpdate}+ render={(updateControl) => <EnvironmentSelector {...props} updateControl={updateControl} />}+ />+ ) : (+ <EnvironmentSelector {...props} updateControl={null} />+ );+});++function EnvironmentSelector({autoEnvironmentLabel,onAutoEnvironment,envLocked,environmentId,availableEnvironments,onEnvironmentChange,-}: BranchToolbarEnvironmentSelectorProps) {+ serverUpdate,+ updateControl,+}: BranchToolbarEnvironmentSelectorProps & {+ updateControl: ServerUpdateControl | null;+}) {const composerFloatingLayerProps = useComposerMenuProps();const shortcutLabel = shortcutLabelForCommand(useAtomValue(primaryServerKeybindingsAtom),@@ -47,13 +75,39 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvirconst environmentItems = [...(onAutoEnvironment- ? [{ value: "auto", label: autoEnvironmentLabel ?? "Auto balance" }]+ ? [{ value: AUTO_VALUE, label: autoEnvironmentLabel ?? "Auto balance" }]: []),...availableEnvironments.map((env) => ({- value: env.environmentId,+ value: environmentValue(env.environmentId),label: env.label,})),+ ...(serverUpdate && updateControl+ ? [{ value: UPDATE_VALUE, label: `${updateControl.label} ${serverUpdate.serverLabel}` }]+ : []),];+ const updateTooltip = serverUpdate+ ? `${serverUpdate.serverLabel} ${serverUpdate.serverVersion} → ${serverUpdate.targetVersion}. ${+ serverUpdate.selfUpdate === "desktop-managed" && !serverUpdate.desktopAppUpdate+ ? "Update the desktop app on that machine."+ : (updateControl?.label ?? "Update")+ }`+ : null;+ const environmentIcon = serverUpdate ? (+ <CircleArrowUpIcon aria-hidden="true" className="size-3 shrink-0" />+ ) : (+ <EnvironmentMachineIcon+ kind={activeEnvironment?.machine ?? "server"}+ className="size-3 shrink-0"+ />+ );+ const chipBody = (+ <>+ {environmentIcon}+ <ComposerContextLabel>+ {activeEnvironment?.label ?? serverUpdate?.serverLabel ?? "Run on"}+ </ComposerContextLabel>+ </>+ );// The static label carries the xs control's height (h-7 sm:h-6) as well as// its padding: the composer context strip has no min-height of its own, and@@ -61,22 +115,41 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir// a shorter label would drag the seam out of line whenever this label is the// only thing in the strip.if (envLocked || onEnvironmentChange === undefined) {- const lockedRow = (+ const lockedRow = updateControl ? (+ <ComposerControl+ size="xs"+ className="min-w-0 max-w-full"+ aria-label={`${updateControl.label} ${serverUpdate?.serverLabel}`}+ disabled={updateControl.disabled}+ onClick={updateControl.onClick}+ data-composer-context-control+ >+ {chipBody}+ </ComposerControl>+ ) : (<spanclassName="inline-flex h-7 min-w-0 max-w-full items-center gap-1 border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6"data-composer-context-control>- <EnvironmentMachineIcon- kind={activeEnvironment?.machine ?? "server"}- className="size-3 shrink-0"- />- <ComposerContextLabel>{activeEnvironment?.label ?? "Run on"}</ComposerContextLabel>+ {chipBody}</span>);return (<Tooltip>- <TooltipTrigger render={lockedRow} />- <TooltipPopup>{activeEnvironment?.label ?? "Run on"}</TooltipPopup>+ <TooltipTrigger+ render={+ updateControl?.disabled ? (+ <span className="inline-flex min-w-0 max-w-full" data-composer-context-control>+ {lockedRow}+ </span>+ ) : (+ lockedRow+ )+ }+ />+ <TooltipPopup role={serverUpdate ? "tooltip" : undefined}>+ {updateTooltip ?? activeEnvironment?.label ?? "Run on"}+ </TooltipPopup></Tooltip>);}@@ -84,10 +157,16 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvirreturn (<Selectmodal={false}- value={autoEnvironmentLabel ? "auto" : environmentId}- onValueChange={(value) =>- value === "auto" ? onAutoEnvironment?.() : onEnvironmentChange(value as EnvironmentId)- }+ value={autoEnvironmentLabel ? AUTO_VALUE : environmentValue(environmentId)}+ onValueChange={(value) => {+ if (value === UPDATE_VALUE) {+ updateControl?.onClick();+ } else if (value === AUTO_VALUE) {+ onAutoEnvironment?.();+ } else if (value?.startsWith("env:")) {+ onEnvironmentChange(value.slice(4) as EnvironmentId);+ }+ }}items={environmentItems}><Tooltip>@@ -105,17 +184,14 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir{autoEnvironmentLabel ? (<ScaleIcon className="size-3 shrink-0" aria-hidden="true" />) : (- <EnvironmentMachineIcon- kind={activeEnvironment?.machine ?? "server"}- className="size-3 shrink-0"- />+ environmentIcon)}<ComposerContextLabel><SelectValue /></ComposerContextLabel></TooltipTrigger>- <TooltipPopup>- {autoEnvironmentLabel ?? activeEnvironment?.label ?? "Run on"}+ <TooltipPopup role={serverUpdate ? "tooltip" : undefined}>+ {updateTooltip ?? autoEnvironmentLabel ?? activeEnvironment?.label ?? "Run on"}{shortcutLabel ? ` · ${shortcutLabel}` : null}</TooltipPopup></Tooltip>@@ -124,7 +200,7 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir<SelectGroupLabel>Run on</SelectGroupLabel>{onAutoEnvironment && (<SelectItem- value="auto"+ value={AUTO_VALUE}onClick={() => {if (autoEnvironmentLabel) onAutoEnvironment?.();}}@@ -136,15 +212,30 @@ export const BranchToolbarEnvironmentSelector = memo(function BranchToolbarEnvir</SelectItem>)}{availableEnvironments.map((env) => (- <SelectItem key={env.environmentId} value={env.environmentId}>+ <SelectItem key={env.environmentId} value={environmentValue(env.environmentId)}><span className="inline-flex items-center gap-1.5">- <EnvironmentMachineIcon kind={env.machine} className="size-3" />+ {serverUpdate?.environmentId === env.environmentId ? (+ <CircleArrowUpIcon aria-hidden="true" className="size-3" />+ ) : (+ <EnvironmentMachineIcon kind={env.machine} className="size-3" />+ )}{env.label}</span></SelectItem>))}</SelectGroup>+ {serverUpdate && updateControl ? (+ <SelectGroup>+ <SelectGroupLabel>Server update</SelectGroupLabel>+ <SelectItem value={UPDATE_VALUE} disabled={updateControl.disabled}>+ <span className="inline-flex items-center gap-1.5">+ <CircleArrowUpIcon aria-hidden="true" className="size-3" />+ {updateControl.label} {serverUpdate.serverLabel}+ </span>+ </SelectItem>+ </SelectGroup>+ ) : null}</SelectPopup></Select>);-});+}diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 5821766aa9a..a1b5d3a5cfc 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -548,14 +548,10 @@ import {ComposerServerUpdateStatus,} from "./chat/ComposerServerUpdateStatus";import {- buildVersionMismatchDismissalKey,dismissServerUpdateFailure,- dismissVersionMismatch,isServerUpdateFailureDismissed,- isVersionMismatchDismissed,resolveServerConfigVersionMismatch,resolveServerSelfUpdateCapability,- serverUpdateGuidance,supportsDesktopAppUpdate,supportsServerUpdateThreadContinuation,} from "../versionSkew";@@ -2066,10 +2062,6 @@ export default function ChatView(props: ChatViewProps) {logicalProjectEnvironments.find((environment) => environment.environmentId === activeThread?.environmentId,) ?? null;- const showComposerEnvironmentIndicator = shouldShowEnvironmentIndicator({- activeEnvironment: activeEnvironmentOption,- canPickEnvironment: hasMultipleEnvironments,- });const openPullRequestDialog = (reference?: string) => {if (!canCheckoutPullRequestIntoThread) {return;@@ -2220,18 +2212,6 @@ export default function ChatView(props: ChatViewProps) {: EMPTY_AUTO_UPDATE_ENVIRONMENTS;const autoBalanceUpdateBanner = useAutoBalanceUpdateBanner(autoUpdateEnvironments);const versionMismatch = resolveServerConfigVersionMismatch(serverConfig);- const versionMismatchDismissKey =- versionMismatch && activeThread- ? buildVersionMismatchDismissalKey(activeThread.environmentId, versionMismatch)- : null;- const [dismissedVersionMismatchKey, setDismissedVersionMismatchKey] = useState<string | null>(- null,- );- const versionMismatchDismissed =- versionMismatchDismissKey === dismissedVersionMismatchKey ||- isVersionMismatchDismissed(versionMismatchDismissKey);- const showVersionMismatchBanner =- versionMismatch !== null && versionMismatchDismissKey !== null && !versionMismatchDismissed;const hasMultipleRegisteredEnvironments = environments.length > 1;const versionMismatchServerLabel =hasMultipleRegisteredEnvironments && activeThread@@ -2251,6 +2231,30 @@ export default function ChatView(props: ChatViewProps) {const serverUpdateFailureDismissed =serverUpdateState === dismissedServerUpdateState ||isServerUpdateFailureDismissed(serverUpdateState);+ const activeServerUpdate =+ !automaticEnvironment &&+ serverUpdateEnvironmentId &&+ versionMismatch &&+ serverUpdateState.status === "idle"+ ? {+ environmentId: serverUpdateEnvironmentId,+ serverLabel:+ activeEnvironmentOption?.label ??+ serverConfig?.environment.label ??+ versionMismatchServerLabel,+ serverVersion: versionMismatch.serverVersion,+ targetVersion: versionMismatch.clientVersion,+ selfUpdate: versionMismatchSelfUpdate,+ installation: versionMismatchInstallation,+ desktopAppUpdate: versionMismatchDesktopAppUpdate,+ threadContinuation: versionMismatchThreadContinuation,+ }+ : null;+ const showComposerEnvironmentIndicator = shouldShowEnvironmentIndicator({+ activeEnvironment: activeEnvironmentOption,+ canPickEnvironment: hasMultipleEnvironments,+ serverUpdateAvailable: activeServerUpdate !== null,+ });const systemComposerBannerItems = (() => {const items: ComposerBannerStackItem[] = [];const updateRunning = serverUpdateState.status === "running";@@ -2306,9 +2310,8 @@ export default function ChatView(props: ChatViewProps) {if (!automaticEnvironment &&serverUpdateEnvironmentId &&- (serverUpdateState.status === "idle"- ? showVersionMismatchBanner- : !serverUpdateFailureDismissed)+ serverUpdateState.status !== "idle" &&+ !serverUpdateFailureDismissed) {const updateInProgress = serverUpdateState.status === "running";const updateFailed = serverUpdateState.status === "failed";@@ -2317,39 +2320,12 @@ export default function ChatView(props: ChatViewProps) {variant: updateFailed ? "error" : "default",priority: updateInProgress ? "urgent" : "notice",icon: <ComposerServerUpdateIcon status={serverUpdateState.status} />,- title:- updateInProgress || updateFailed ? (- <ComposerServerUpdateStatus- state={serverUpdateState}- serverLabel={versionMismatchServerLabel}- />- ) : versionMismatch ? (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- className="block max-w-full cursor-help truncate rounded-sm text-left"- >- Server update available- </button>- }- />- <TooltipPopup side="top">- {versionMismatchServerLabel} {versionMismatch.serverVersion}{" "}- <span aria-hidden="true">→</span> {versionMismatch.clientVersion}- </TooltipPopup>- </Tooltip>- ) : (- "Server update available"- ),- description:- !updateInProgress &&- !updateFailed &&- versionMismatchSelfUpdate !== null &&- (versionMismatchSelfUpdate !== "desktop-managed" || !versionMismatchDesktopAppUpdate)- ? serverUpdateGuidance(versionMismatchSelfUpdate)- : undefined,+ title: (+ <ComposerServerUpdateStatus+ state={serverUpdateState}+ serverLabel={versionMismatchServerLabel}+ />+ ),actions: updateInProgress ? (disconnectAction) : !versionMismatch ||@@ -2367,19 +2343,15 @@ export default function ChatView(props: ChatViewProps) {variant="ghost"/>),- ...(updateInProgress || (!updateFailed && !versionMismatchDismissKey)- ? {}- : {+ ...(updateFailed+ ? {dismissLabel: "Dismiss update notice",onDismiss: () => {- if (updateFailed) {- dismissServerUpdateFailure(serverUpdateState);- setDismissedServerUpdateState(serverUpdateState);- }- dismissVersionMismatch(versionMismatchDismissKey);- setDismissedVersionMismatchKey(versionMismatchDismissKey);+ dismissServerUpdateFailure(serverUpdateState);+ setDismissedServerUpdateState(serverUpdateState);},- }),+ }+ : {}),});}if (autoBalanceUpdateBanner) items.push(autoBalanceUpdateBanner);@@ -3081,6 +3053,7 @@ export default function ChatView(props: ChatViewProps) {hasActiveProject: activeProject !== null && !showProviderSubagentBar,isGitRepo,showEnvironmentIndicator: showComposerEnvironmentIndicator,+ serverUpdateAvailable: activeServerUpdate !== null,hostsRestingComposerControls: routeKind === "server",});const showComposerContextStrip = shouldShowComposerContextStrip({@@ -3089,6 +3062,7 @@ export default function ChatView(props: ChatViewProps) {hasActiveProject: activeProject !== null && !showProviderSubagentBar,isGitRepo,showEnvironmentIndicator: showComposerEnvironmentIndicator,+ serverUpdateAvailable: activeServerUpdate !== null,hostsRestingComposerControls: routeKind === "server" && restingComposerControlsVisible,});const mountComposerModelStrip =@@ -8458,6 +8432,7 @@ export default function ChatView(props: ChatViewProps) {availableEnvironments={logicalProjectEnvironments}composerControlsHostRef={setRestingComposerControlsHost}contextStripVisible={showComposerContextStrip}+ serverUpdate={activeServerUpdate}/></div>)}diff --git a/apps/web/src/components/ServerUpdateAction.browser.test.tsx b/apps/web/src/components/ServerUpdateAction.browser.test.tsxindex 8a86d2d37bb..25d56d69dff 100644--- a/apps/web/src/components/ServerUpdateAction.browser.test.tsx+++ b/apps/web/src/components/ServerUpdateAction.browser.test.tsx@@ -3,9 +3,12 @@ import { AuthSessionState, type EnvironmentId, type ServerInstallation } from "@import * as Cause from "effect/Cause";import * as Schema from "effect/Schema";import { AsyncResult, Atom } from "effect/reactivity";-import { act, type ReactNode } from "react";+import { act, useState, type ReactNode } from "react";import { createRoot, type Root } from "react-dom/client";import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";+import { page, userEvent } from "vite-plus/test/browser";++import "~/index.css";type SessionResult = AsyncResult.AsyncResult<AuthSessionState, Error>;const testState = vi.hoisted(() => ({@@ -56,6 +59,7 @@ vi.mock(import("./ui/toast"), async (original) => {});import {+ completeConfirmDialogClose,readConfirmDialogState,registerConfirmDialogHost,resetConfirmDialogForTests,@@ -69,6 +73,8 @@ import {type ServerUpdateTarget,} from "./ServerUpdateAction";+import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";+const decodeSessionState = Schema.decodeUnknownSync(AuthSessionState);const legacyAuth = {@@ -509,3 +515,105 @@ describe("ServerUpdateProgress", () => {);});});++describe("server updates from the environment selector", () => {+ const localId = "env-test" as EnvironmentId;+ const otherId = "update-server" as EnvironmentId;+ const availableEnvironments = [+ { environmentId: localId, label: "Build box", isPrimary: true },+ { environmentId: otherId, label: "Other machine", isPrimary: false },+ ].map((environment) => ({ ...environment, projectId: null, machine: "server" as const }));+ const serverUpdate = {+ environmentId: localId,+ serverLabel: "Build box",+ serverVersion: "0.0.30",+ targetVersion: "0.0.31",+ selfUpdate: "desktop-managed",+ desktopAppUpdate: true,+ } satisfies ServerUpdateTarget & { serverVersion: string };++ it("confirms a locked chip update and honors cancellation before updating", async () => {+ registerConfirmDialogHost();+ testState.updateServer.mockResolvedValue(success("desktop-app"));+ await render(+ <BranchToolbarEnvironmentSelector+ environmentId={localId}+ availableEnvironments={availableEnvironments}+ envLocked+ serverUpdate={serverUpdate}+ />,+ );+ const chip = page.getByRole("button", { name: /Build box|Update/ });+ await userEvent.click(chip);+ expect(readConfirmDialogState()).toMatchObject({+ status: "confirming",+ message: expect.stringContaining("Build box"),+ });+ expect(testState.updateServer).not.toHaveBeenCalled();+ await act(async () => {+ respondToConfirmDialog(false);+ completeConfirmDialogClose();+ });+ expect(testState.updateServer).not.toHaveBeenCalled();+ await userEvent.click(chip);+ await act(async () => respondToConfirmDialog(true));+ expect(testState.updateServer).toHaveBeenCalledExactlyOnceWith({+ environmentId: localId,+ input: { targetVersion: "0.0.31" },+ });+ });++ it("copies from the picker without switching machines and still selects an action-like environment ID", async () => {+ const update = { ...serverUpdate, selfUpdate: null, installation: { kind: "npx" } } as const;+ function Picker() {+ const [environmentId, setEnvironmentId] = useState(localId);+ return (+ <BranchToolbarEnvironmentSelector+ environmentId={environmentId}+ availableEnvironments={availableEnvironments}+ envLocked={false}+ onEnvironmentChange={setEnvironmentId}+ serverUpdate={environmentId === localId ? update : null}+ />+ );+ }+ await render(<Picker />);+ const picker = page.getByRole("combobox", { name: "Run on" });+ await userEvent.click(picker);+ await expect.element(page.getByRole("option", { name: "Other machine" })).toBeVisible();+ expect(testState.clipboard).not.toHaveBeenCalled();+ await userEvent.click(page.getByRole("option", { name: /Copy relaunch command/ }));+ expect(testState.clipboard).toHaveBeenCalledExactlyOnceWith("npx [email protected]");+ expect(testState.updateServer).not.toHaveBeenCalled();+ await expect.element(picker).toHaveTextContent("Build box");+ await userEvent.click(picker);+ await expect+ .element(page.getByRole("option", { name: "Build box", exact: true }))+ .toHaveAttribute("aria-selected", "true");+ await userEvent.click(page.getByRole("option", { name: "Other machine" }));+ await expect.element(picker).toHaveTextContent("Other machine");+ expect(testState.clipboard).toHaveBeenCalledTimes(1);+ expect(testState.updateServer).not.toHaveBeenCalled();+ });++ it("explains an unsupported desktop update in the picker without offering a runnable action", async () => {+ registerConfirmDialogHost();+ await render(+ <BranchToolbarEnvironmentSelector+ environmentId={localId}+ availableEnvironments={availableEnvironments}+ envLocked={false}+ onEnvironmentChange={vi.fn()}+ serverUpdate={{ ...serverUpdate, desktopAppUpdate: false }}+ />,+ );+ await userEvent.click(page.getByRole("combobox", { name: "Run on" }));+ const instruction = page.getByRole("option", { name: /Update the desktop app/ });+ await expect.element(instruction).toBeVisible();+ await expect.element(instruction).toHaveAttribute("aria-disabled", "true");+ await userEvent.click(instruction, { force: true });+ expect(readConfirmDialogState().status).toBe("idle");+ expect(testState.updateServer).not.toHaveBeenCalled();+ expect(testState.clipboard).not.toHaveBeenCalled();+ });+});diff --git a/apps/web/src/components/ServerUpdateAction.tsx b/apps/web/src/components/ServerUpdateAction.tsxindex 3d809655e28..dd9ff5a147c 100644--- a/apps/web/src/components/ServerUpdateAction.tsx+++ b/apps/web/src/components/ServerUpdateAction.tsx@@ -18,7 +18,7 @@ import {squashAtomCommandFailure,} from "@t3tools/client-runtime/state/runtime";import { CircleArrowUpIcon } from "lucide-react";-import { type ComponentProps, useRef, useState } from "react";+import { type ComponentProps, type ReactNode, useRef, useState } from "react";import { requestConfirmDialog } from "~/confirmDialog";import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";@@ -57,6 +57,16 @@ export interface ServerUpdateTarget {readonly continueThreadsAfterServerUpdate?: boolean;}+export type PendingServerUpdate = Omit<ServerUpdateTarget, "continueThreadsAfterServerUpdate"> & {+ readonly serverVersion: string;+};++export interface ServerUpdateControl {+ readonly label: string;+ readonly disabled: boolean;+ readonly onClick: () => void;+}+type UpdateButtonProps = Pick<ComponentProps<typeof Button>, "variant" | "size" | "className"> & {readonly label?: string;readonly appearance?: "button" | "icon";@@ -215,8 +225,13 @@ export function ServerUpdateAction({size = "xs",className,appearance = "button",-}: Omit<ServerUpdateTarget, "continueThreadsAfterServerUpdate"> & UpdateButtonProps) {+ render,+}: Omit<ServerUpdateTarget, "continueThreadsAfterServerUpdate"> &+ UpdateButtonProps & {+ readonly render?: (control: ServerUpdateControl) => ReactNode;+ }) {const isDesktopAppUpdate = selfUpdate === "desktop-managed";+ const unsupportedDesktopUpdate = isDesktopAppUpdate && !desktopAppUpdate;const sessionStateAtom = environmentSession.sessionStateAtom(environmentId);const canUpdate = canUpdateServer(useAtomValue(sessionStateAtom));const continueThreadsAfterServerUpdate = useEnvironmentSettings(@@ -248,6 +263,7 @@ export function ServerUpdateAction({const handleUpdate = async () => {if (+ unsupportedDesktopUpdate ||!canUpdateServer(appAtomRegistry.get(sessionStateAtom)) ||pendingUpdateEnvironmentIds.has(environmentId)) {@@ -274,18 +290,11 @@ export function ServerUpdateAction({});};- if (selfUpdate === "desktop-managed" && !desktopAppUpdate) {- return (- <span className="text-muted-foreground text-xs">- Update the desktop app on that machine to update this server.- </span>- );- }-const manualCommand =selfUpdate === null ? manualServerUpdateCommand(targetVersion, installation) : null;- const actionLabel =- manualCommand !== null+ const actionLabel = unsupportedDesktopUpdate+ ? "Update the desktop app on"+ : manualCommand !== null? installation?.kind === "npm-global"? "Copy update command": "Copy relaunch command"@@ -294,6 +303,17 @@ export function ServerUpdateAction({manualCommand !== null? () => copyToClipboard(manualCommand, { command: manualCommand }): () => void handleUpdate();+ const disabled = unsupportedDesktopUpdate || (manualCommand === null && !canUpdate);++ if (render) return render({ label: actionLabel, disabled, onClick });++ if (unsupportedDesktopUpdate) {+ return (+ <span className="text-muted-foreground text-xs">+ Update the desktop app on that machine to update this server.+ </span>+ );+ }if (appearance === "icon") {return (@@ -305,7 +325,7 @@ export function ServerUpdateAction({variant="ghost-muted"className={className}aria-label={`${actionLabel} for ${serverLabel}`}- disabled={manualCommand === null && !canUpdate}+ disabled={disabled}onClick={onClick}/>}@@ -322,7 +342,7 @@ export function ServerUpdateAction({size={size}variant={variant}className={className}- disabled={manualCommand === null && !canUpdate}+ disabled={disabled}onClick={onClick}>{actionLabel}diff --git a/apps/web/src/versionSkew.test.ts b/apps/web/src/versionSkew.test.tsindex bfed9b8e081..3a3e27d0fb8 100644--- a/apps/web/src/versionSkew.test.ts+++ b/apps/web/src/versionSkew.test.ts@@ -17,7 +17,6 @@ import {resolveServerConfigVersionMismatch,resolveServerSelfUpdateCapability,resolveVersionMismatch,- serverUpdateGuidance,supportsDesktopAppUpdate,} from "./versionSkew";@@ -236,9 +235,4 @@ describe("versionSkew", () => {expect(supportsDesktopAppUpdate(descriptor())).toBe(false);expect(supportsDesktopAppUpdate(null)).toBe(false);});-- it("matches version-drift guidance to the advertised update path", () => {- expect(serverUpdateGuidance("respawn")).toBe("Update to stay in sync");- expect(serverUpdateGuidance("desktop-managed")).toBe("Update the desktop app");- });});diff --git a/apps/web/src/versionSkew.ts b/apps/web/src/versionSkew.tsindex bcf4a27b6cc..ec7118a2f69 100644--- a/apps/web/src/versionSkew.ts+++ b/apps/web/src/versionSkew.ts@@ -114,10 +114,6 @@ export function manualServerUpdateCommand(return `${runner} t3@${targetVersion}`;}-export function serverUpdateGuidance(capability: ServerSelfUpdateCapability): string {- return capability === "desktop-managed" ? "Update the desktop app" : "Update to stay in sync";-}-export function buildVersionMismatchDismissalKey(environmentId: EnvironmentId,mismatch: Pick<VersionMismatch, "clientVersion" | "serverVersion">,