diff --git a/src/renderer/src/components/status-bar/StatusBar.tsx b/src/renderer/src/components/status-bar/StatusBar.tsx index 6de4255c0..3819fd1d3 100644 --- a/src/renderer/src/components/status-bar/StatusBar.tsx +++ b/src/renderer/src/components/status-bar/StatusBar.tsx @@ -44,6 +44,7 @@ import { UpdateStatusSegment } from './UpdateStatusSegment' import { ResourceUsageStatusSegment } from './ResourceUsageStatusSegment' import { PortsStatusSegment } from './PortsStatusSegment' import { isStatusBarItemAvailable } from './status-bar-agent-gating' +import { isProviderConfigured } from './status-bar-provider-visibility' import { shouldOpenStatusBarContextMenu } from './status-bar-context-menu-policy' import { PetStatusSegment } from './PetStatusSegment' import { TOGGLE_FLOATING_TERMINAL_EVENT } from '@/lib/floating-terminal' @@ -1542,31 +1543,27 @@ function StatusBarInner({ floatingTerminalOpen }: StatusBarProps): React.JSX.Ele const { claude, codex, gemini, opencodeGo } = rateLimits - // Why: hiding `unavailable` providers makes the status bar appear to lose a - // provider at random after refreshes or wake/resume. Keeping the slot visible - // preserves layout stability and makes it obvious that the provider is still - // configured but currently unavailable. Detection-gating (see - // status-bar-agent-gating) hides the per-CLI bars when the agent isn't - // installed on PATH — this is what stops a fresh install from showing - // "Gemini Usage" when Gemini isn't installed. + // Why: a provider only earns a bar once it's configured (isProviderConfigured + // drops the `unavailable` state — Gemini OAuth off, OpenCode Go cookie unset, + // Claude on API-key billing). A configured provider that fails transiently + // (`error`) keeps its slot so the bar doesn't flap on refresh hiccups. + // Detection-gating (see status-bar-agent-gating) additionally hides per-CLI + // bars when the agent isn't installed on PATH. const showClaude = - !!claude && + isProviderConfigured(claude) && statusBarItems.includes('claude') && isStatusBarItemAvailable('claude', detectedAgentIds) const showCodex = - !!codex && + isProviderConfigured(codex) && statusBarItems.includes('codex') && isStatusBarItemAvailable('codex', detectedAgentIds) - // Why: hide only when the state hasn't loaded yet (null), not when unavailable. - // Gemini shows if credentials exist; OpenCode Go shows always so users can see - // the provider and know to configure the cookie in Settings. const showGemini = - gemini !== null && + isProviderConfigured(gemini) && statusBarItems.includes('gemini') && isStatusBarItemAvailable('gemini', detectedAgentIds) // Why: OpenCode Go is a web/cookie-auth provider, not a CLI on PATH, so // detection-gating doesn't apply. - const showOpencodeGo = opencodeGo !== null && statusBarItems.includes('opencode-go') + const showOpencodeGo = isProviderConfigured(opencodeGo) && statusBarItems.includes('opencode-go') const showSsh = statusBarItems.includes('ssh') const showResourceUsage = statusBarItems.includes('resource-usage') const showPorts = statusBarItems.includes('ports') diff --git a/src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts b/src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts new file mode 100644 index 000000000..18c2899ad --- /dev/null +++ b/src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts @@ -0,0 +1,58 @@ +import { describe, expect, it } from 'vitest' +import type { + ProviderRateLimits, + ProviderRateLimitStatus +} from '../../../../shared/rate-limit-types' +import { isProviderConfigured } from './status-bar-provider-visibility' + +function provider( + status: ProviderRateLimitStatus, + overrides: Partial = {} +): ProviderRateLimits { + return { + provider: 'gemini', + session: null, + weekly: null, + updatedAt: 0, + error: null, + status, + ...overrides + } +} + +describe('isProviderConfigured', () => { + it('hides a provider whose state has not loaded yet', () => { + expect(isProviderConfigured(null)).toBe(false) + }) + + it('hides an unconfigured (unavailable) provider', () => { + // The bug: Gemini OAuth off / OpenCode Go cookie unset returns a non-null + // `unavailable` object, which previously slipped past the `!== null` gate + // and rendered a "--" bar for a provider the user never configured. + expect(isProviderConfigured(provider('unavailable'))).toBe(false) + }) + + it('hides a first-load fetching provider until it has proven usage data', () => { + // The initial fetch marks every provider as `fetching`; without prior data + // that state is not proof the user configured Gemini or OpenCode Go. + expect(isProviderConfigured(provider('fetching'))).toBe(false) + }) + + it('shows configured providers, including ones failing transiently', () => { + expect(isProviderConfigured(provider('ok'))).toBe(true) + expect(isProviderConfigured(provider('error'))).toBe(true) + expect( + isProviderConfigured( + provider('fetching', { + session: { + usedPercent: 25, + windowMinutes: 300, + resetsAt: null, + resetDescription: null + } + }) + ) + ).toBe(true) + expect(isProviderConfigured(provider('idle'))).toBe(true) + }) +}) diff --git a/src/renderer/src/components/status-bar/status-bar-provider-visibility.ts b/src/renderer/src/components/status-bar/status-bar-provider-visibility.ts new file mode 100644 index 000000000..a444e2886 --- /dev/null +++ b/src/renderer/src/components/status-bar/status-bar-provider-visibility.ts @@ -0,0 +1,28 @@ +import type { ProviderRateLimits } from '../../../../shared/rate-limit-types' + +function hasUsageData(provider: ProviderRateLimits): boolean { + return Boolean( + provider.session || + provider.weekly || + provider.monthly || + (provider.buckets && provider.buckets.length > 0) + ) +} + +// Why: a provider that returns `unavailable` is explicitly not configured +// (Gemini OAuth off, OpenCode Go cookie unset, Claude on API-key billing). Its +// fetch object is non-null, so a bare `!== null` check still renders a "--" +// bar for a provider the user never set up. `error` is kept visible on purpose +// — that's a *configured* provider failing transiently, and hiding it would +// make the bar flap on every refresh hiccup. +export function isProviderConfigured( + provider: ProviderRateLimits | null +): provider is ProviderRateLimits { + if (provider === null || provider.status === 'unavailable') { + return false + } + if (provider.status === 'fetching' && !hasUsageData(provider)) { + return false + } + return true +}