The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): resolve version/update labels in one place
Brooklyn Nicholsoncb9e9b72725a
diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsxindex fb2aac6d2da..0aa3c69fe3b 100644--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx@@ -14,6 +14,7 @@ import type { RuntimeReadinessResult } from '@/lib/runtime-readiness'import { contextBarLabel, LiveDuration, usageContextLabel } from '@/lib/statusbar'import { useStoreSelector } from '@/lib/use-session-slice'import { cn } from '@/lib/utils'+import { resolveVersionStatus } from '@/lib/version-status'import { copyFilePath, revealFile } from '@/store/file-actions'import { revealFileInTree } from '@/store/layout'import { $activeGatewayProfile } from '@/store/profile'@@ -218,42 +219,33 @@ export function useStatusbarItems({: 'text-destructive hover:text-destructive'const clientVersionItem = useMemo<StatusbarItem>(() => {- const appVersion = desktopVersion?.appVersion- const sha = updateStatus?.currentSha?.slice(0, 7) ?? null- const behind = updateStatus?.behind ?? 0const applying = updateApply.applying || updateApply.stage === 'restart'- const remote = connection?.mode === 'remote'-- const version = appVersion ? `v${appVersion}` : (sha ?? copy.unknown)- const base = remote ? copy.clientLabel(appVersion ?? sha ?? copy.unknown) : version- const behindHint = !applying && behind > 0 ? ` (+${behind})` : ''-- const label = applying- ? `${base} · ${updateApply.stage === 'restart' ? copy.restart : copy.update}`- : `${base}${behindHint}`-- const tooltip = [- applying ? updateApply.message || copy.updateInProgress : null,- !applying && behind > 0 && copy.commitsBehind(behind, updateStatus?.branch ?? '...'),- appVersion && copy.desktopVersion(appVersion),- sha && copy.commit(sha),- updateStatus?.branch && copy.branch(updateStatus.branch)- ]- .filter(Boolean)- .join(' · ')++ const status = resolveVersionStatus({+ applying,+ applyMessage: updateApply.message,+ behind: updateStatus?.behind ?? 0,+ branch: updateStatus?.branch,+ copy,+ remote: connection?.mode === 'remote',+ restarting: updateApply.stage === 'restart',+ sha: updateStatus?.currentSha?.slice(0, 7) ?? null,+ target: 'client',+ version: desktopVersion?.appVersion+ })return {- className: !applying && behind > 0 ? 'text-primary hover:text-primary' : undefined,- detail: appVersion && sha && !applying && !remote ? sha : undefined,- hidden: !appVersion && !sha,+ className: status.hasUpdate ? 'text-primary hover:text-primary' : undefined,+ detail: status.detail,+ hidden: status.unknown,icon: applying ? <Loader2 className="size-3 animate-spin" /> : <Hash className="size-3" />,id: 'version-client',- label,+ label: status.label,// Update state is not a preference: hiding it is how a user misses that// their client is behind. Listed in the menu, but locked on.lockedVisible: true,onSelect: () => openUpdateOverlayFor('client'),- title: tooltip || undefined,+ title: status.tooltip,toggleLabel: copy.toggleVersion,variant: 'action'}@@ -274,38 +266,29 @@ export function useStatusbarItems({return null}- const backendVersion = statusSnapshot?.version- const behind = backendUpdateStatus?.behind ?? 0- const updateAvailable = backendUpdateStatus?.updateAvailable || behind > 0const applying = backendUpdateApply.applying || backendUpdateApply.stage === 'restart'- const base = copy.backendLabel(backendVersion ?? copy.unknown)-- const behindHint =- !applying && behind > 0 ? ` (+${behind})` : !applying && updateAvailable ? ` (${copy.update})` : ''-- const label = applying- ? `${base} · ${backendUpdateApply.stage === 'restart' ? copy.restart : copy.update}`- : `${base}${behindHint}`-- const tooltip = [- applying ? backendUpdateApply.message || copy.updateInProgress : null,- !applying && behind > 0 && copy.commitsBehind(behind, 'main'),- !applying && behind <= 0 && updateAvailable && copy.update,- backendVersion && copy.backendVersion(backendVersion)- ]- .filter(Boolean)- .join(' · ')+ const status = resolveVersionStatus({+ applying,+ applyMessage: backendUpdateApply.message,+ behind: backendUpdateStatus?.behind ?? 0,+ copy,+ remote: true,+ restarting: backendUpdateApply.stage === 'restart',+ target: 'backend',+ updateAvailable: backendUpdateStatus?.updateAvailable,+ version: statusSnapshot?.version+ })return {- className: !applying && updateAvailable ? 'text-primary hover:text-primary' : undefined,- hidden: !backendVersion,+ className: status.hasUpdate ? 'text-primary hover:text-primary' : undefined,+ hidden: status.unknown,icon: applying ? <Loader2 className="size-3 animate-spin" /> : <Hash className="size-3" />,id: 'version-backend',- label,+ label: status.label,lockedVisible: true,onSelect: () => openUpdateOverlayFor('backend'),- title: tooltip || undefined,+ title: status.tooltip,toggleLabel: copy.toggleBackendVersion,variant: 'action'}diff --git a/apps/desktop/src/lib/version-status.test.ts b/apps/desktop/src/lib/version-status.test.tsnew file mode 100644index 00000000000..54a4bb2d576--- /dev/null+++ b/apps/desktop/src/lib/version-status.test.ts@@ -0,0 +1,85 @@+import { describe, expect, it } from 'vitest'++import { en } from '@/i18n/en'++import { resolveVersionStatus } from './version-status'++const copy = en.shell.statusbar++const client = (over: Partial<Parameters<typeof resolveVersionStatus>[0]> = {}) =>+ resolveVersionStatus({ applying: false, copy, remote: false, restarting: false, target: 'client', ...over })++const backend = (over: Partial<Parameters<typeof resolveVersionStatus>[0]> = {}) =>+ resolveVersionStatus({ applying: false, copy, remote: true, restarting: false, target: 'backend', ...over })++describe('resolveVersionStatus', () => {+ it('labels a current local client with its version and sha detail', () => {+ const status = client({ sha: 'abc1234', version: '0.4.2' })++ expect(status.label).toBe('v0.4.2')+ expect(status.detail).toBe('abc1234')+ expect(status.hasUpdate).toBe(false)+ expect(status.unknown).toBe(false)+ })++ it('appends the commit diff when the client is behind', () => {+ const status = client({ behind: 12, branch: 'main', version: '0.4.2' })++ expect(status.label).toBe('v0.4.2 (+12)')+ expect(status.hasUpdate).toBe(true)+ expect(status.tooltip).toContain('12 commits behind main')+ })++ it('names the client as one of two versions in remote mode', () => {+ expect(client({ remote: true, version: '0.4.2' }).label).toBe('client v0.4.2')+ })++ it('falls back to the sha, then to unknown, when there is no version', () => {+ expect(client({ sha: 'abc1234' }).label).toBe('abc1234')+ expect(client({ sha: 'abc1234' }).unknown).toBe(false)+ expect(client().label).toBe(copy.unknown)+ expect(client().unknown).toBe(true)+ })++ it('drops the diff and the sha detail while an apply is in flight', () => {+ const applying = client({ applying: true, behind: 3, sha: 'abc1234', version: '0.4.2' })++ expect(applying.label).toBe('v0.4.2 · update')+ expect(applying.detail).toBeUndefined()+ expect(applying.hasUpdate).toBe(false)++ expect(client({ applying: true, restarting: true, version: '0.4.2' }).label).toBe('v0.4.2 · restart')+ })++ it('leads the tooltip with the apply message while applying', () => {+ expect(client({ applyMessage: 'Pulling…', applying: true, version: '0.4.2' }).tooltip).toBe(+ 'Pulling… · Hermes Desktop v0.4.2'+ )+ expect(client({ applying: true, version: '0.4.2' }).tooltip).toBe(+ `${copy.updateInProgress} · Hermes Desktop v0.4.2`+ )+ })++ it('labels the backend target distinctly and never claims a client sha', () => {+ const status = backend({ sha: 'abc1234', version: '0.4.2' })++ expect(status.label).toBe('backend v0.4.2')+ expect(status.detail).toBeUndefined()+ expect(status.tooltip).toBe('Backend v0.4.2')+ })++ it('falls back to (update) for a backend that cannot count commits', () => {+ const status = backend({ updateAvailable: true, version: '0.4.2' })++ expect(status.label).toBe('backend v0.4.2 (update)')+ expect(status.hasUpdate).toBe(true)+ })++ it('prefers the exact commit diff over the generic (update) hint', () => {+ expect(backend({ behind: 4, updateAvailable: true, version: '0.4.2' }).label).toBe('backend v0.4.2 (+4)')+ })++ it('hides a backend row that has no version at all', () => {+ expect(backend().unknown).toBe(true)+ })+})diff --git a/apps/desktop/src/lib/version-status.ts b/apps/desktop/src/lib/version-status.tsnew file mode 100644index 00000000000..030464e8eca--- /dev/null+++ b/apps/desktop/src/lib/version-status.ts@@ -0,0 +1,106 @@+/**+ * Pure derivation of how the app names an update target: the label+ * (`v0.4.2`, `backend v0.4.2 (+12)`, `v0.4.2 · update`), its tooltip, and+ * whether an update is waiting.+ *+ * The statusbar and the command palette both name the same two targets, so the+ * wording lives here once — a palette row and its statusbar item can't drift+ * into describing the same install differently.+ */++import type { UpdateTarget } from '@/lib/update-copy'++export interface VersionStatusCopy {+ backendLabel: (version: string) => string+ backendVersion: (version: string) => string+ branch: (branch: string) => string+ clientLabel: (version: string) => string+ commit: (sha: string) => string+ commitsBehind: (count: number, branch: string) => string+ desktopVersion: (version: string) => string+ restart: string+ unknown: string+ update: string+ updateInProgress: string+}++export interface VersionStatusInput {+ /** True while an apply is in flight (including the restart hand-off). */+ applying: boolean+ /** Latest line from the apply stream — leads the tooltip while applying. */+ applyMessage?: string+ behind?: number+ branch?: string+ copy: VersionStatusCopy+ /** Remote mode: the client is one of two versions on screen, so it says so. */+ remote: boolean+ /** The apply reached the restart stage — labels `restart`, not `update`. */+ restarting: boolean+ /** Client only: short commit sha of the running build. */+ sha?: null | string+ target: UpdateTarget+ /** Backend only: an update the commit count can't express (pip installs). */+ updateAvailable?: boolean+ version?: null | string+}++export interface VersionStatusResult {+ /** Secondary text beside the label — the commit sha, when it adds anything. */+ detail?: string+ /** An update is waiting: callers tint the row with it. */+ hasUpdate: boolean+ label: string+ tooltip?: string+ /** Nothing identifies this target yet — callers hide the row. */+ unknown: boolean+}++export function resolveVersionStatus({+ applyMessage,+ applying,+ behind = 0,+ branch,+ copy,+ remote,+ restarting,+ sha = null,+ target,+ updateAvailable,+ version = null+}: VersionStatusInput): VersionStatusResult {+ const client = target === 'client'+ const busy = applying || restarting+ const available = behind > 0 || (!client && !!updateAvailable)++ // A client with no version still identifies itself by sha; a backend can't.+ const named = version ?? (client ? sha : null) ?? copy.unknown++ const base = !client+ ? copy.backendLabel(named)+ : remote+ ? copy.clientLabel(named)+ : (version && `v${version}`) || named++ // Commits behind is the precise diff; `(update)` is the fallback for a+ // backend that knows it's stale but can't count (pip, non-git checkout).+ const hint = busy ? '' : behind > 0 ? ` (+${behind})` : available ? ` (${copy.update})` : ''++ const tooltip = [+ busy && (applyMessage || copy.updateInProgress),+ !busy && behind > 0 && copy.commitsBehind(behind, (client ? branch : 'main') || '...'),+ !busy && behind <= 0 && available && copy.update,+ version && (client ? copy.desktopVersion(version) : copy.backendVersion(version)),+ client && sha && copy.commit(sha),+ client && branch && copy.branch(branch)+ ]+ .filter(Boolean)+ .join(' · ')++ return {+ detail: client && version && sha && !busy && !remote ? sha : undefined,+ hasUpdate: !busy && available,+ label: busy ? `${base} · ${restarting ? copy.restart : copy.update}` : `${base}${hint}`,+ tooltip: tooltip || undefined,+ unknown: !version && !(client && sha)+ }+}