diff --git a/src/main/rate-limits/claude-active-usage-fetch.ts b/src/main/rate-limits/claude-active-usage-fetch.ts index f285ba13ce93..e469c08f9e5b 100644 --- a/src/main/rate-limits/claude-active-usage-fetch.ts +++ b/src/main/rate-limits/claude-active-usage-fetch.ts @@ -139,10 +139,24 @@ export async function fetchActiveClaudeRateLimits( const credentialClassification = classifyClaudeCredentialAbsence({ hasRefreshableCredentials: oauthCredentials.hasRefreshableCredentials, + hasEmptyStoredEntry: oauthCredentials.hasEmptyStoredEntry, keychainUnavailable: oauthCredentials.keychainUnavailable, managedRefreshDeferredByLivePty: options?.authPreparation?.managedRefreshDeferredByLivePty }) + // Why: terminal signed-out means there is no token to try and no CLI + // fallback is sanctioned — return before any refresh or PTY attempts. + if (credentialClassification.failureKind === 'signed-out') { + return makeClaudeUsageResult('error', 'Claude sign-in expired', { + ...metadataForClaudeUsageAttempt({ + attemptedSources: attempts.attemptedSources, + oauthCredentials, + authPreparation: options?.authPreparation, + failureKind: 'signed-out' + }) + }) + } + if (shouldDeferClaudeUsageForLiveSession(options?.authPreparation, credentialClassification)) { return makeLiveClaudeUsageDeferredResult({ attempts, diff --git a/src/main/rate-limits/claude-fetcher-keychain-credentials.test.ts b/src/main/rate-limits/claude-fetcher-keychain-credentials.test.ts index 9a75d3826e5c..11851d3d9273 100644 --- a/src/main/rate-limits/claude-fetcher-keychain-credentials.test.ts +++ b/src/main/rate-limits/claude-fetcher-keychain-credentials.test.ts @@ -452,6 +452,56 @@ describe('fetchClaudeRateLimits', () => { ) }) + it('reports signed-out instead of unavailable when the Keychain entry holds no tokens', async () => { + const configDir = '/Users/test/.claude' + const authPreparation: ClaudeRuntimeAuthPreparation = { + configDir, + runtime: 'host', + envPatch: {}, + stripAuthEnv: false, + provenance: 'system' + } + vi.mocked(readActiveClaudeKeychainCredentialsStrict) + .mockResolvedValueOnce(null) + .mockResolvedValueOnce( + JSON.stringify({ + claudeAiOauth: { accessToken: '', refreshToken: '', expiresAt: 0 } + }) + ) + + // Why: no allowPtyFallback override — signed-out must return before the + // generic CLI plan step even when the caller allows PTY fallback. + await expect(fetchClaudeRateLimits({ authPreparation })).resolves.toMatchObject({ + provider: 'claude', + status: 'error', + error: 'Claude sign-in expired', + usageMetadata: { + failureKind: 'signed-out', + credentialSource: 'legacy-keychain', + authProvenance: 'system' + } + }) + + expect(netFetchMock).not.toHaveBeenCalled() + expect(fetchViaPty).not.toHaveBeenCalled() + }) + + it('reports signed-out when only the credentials file holds an emptied entry', async () => { + readFileMock.mockResolvedValue( + JSON.stringify({ claudeAiOauth: { accessToken: '', refreshToken: '' } }) + ) + + await expect(fetchClaudeRateLimits({ allowPtyFallback: false })).resolves.toMatchObject({ + provider: 'claude', + status: 'error', + error: 'Claude sign-in expired', + usageMetadata: { failureKind: 'signed-out', credentialSource: 'credentials-file' } + }) + + expect(netFetchMock).not.toHaveBeenCalled() + expect(fetchViaPty).not.toHaveBeenCalled() + }) + it('tries OAuth usage even when local credential metadata is expired', async () => { const configDir = '/Users/test/.claude' const authPreparation: ClaudeRuntimeAuthPreparation = { diff --git a/src/main/rate-limits/claude-oauth-credentials.ts b/src/main/rate-limits/claude-oauth-credentials.ts index 3e14fb2909e7..f80a649d196f 100644 --- a/src/main/rate-limits/claude-oauth-credentials.ts +++ b/src/main/rate-limits/claude-oauth-credentials.ts @@ -26,6 +26,9 @@ export type ClaudeOAuthCredentialReadResult = { hasRefreshableCredentials: boolean source: ClaudeOAuthCredentialSource keychainUnavailable?: boolean + // Why: a stored entry with blank tokens means signed-out, not + // never-configured — the status bar shows a sign-in state instead of hiding. + hasEmptyStoredEntry?: boolean } type ClaudeOAuthCredentialReadOptions = { @@ -41,11 +44,24 @@ export function parseClaudeOAuthCredentialsJson( const oauth = (JSON.parse(raw) as ClaudeCredentials)?.claudeAiOauth const hasRefreshableCredentials = typeof oauth?.refreshToken === 'string' && oauth.refreshToken.trim() !== '' - if (!oauth?.accessToken || typeof oauth.accessToken !== 'string') { - return { token: null, hasRefreshableCredentials, source } + // Why: a whitespace-only token is unusable — treat it as absent so the + // entry counts as emptied (signed-out) instead of reaching the OAuth path. + const accessToken = + typeof oauth?.accessToken === 'string' && oauth.accessToken.trim() !== '' + ? oauth.accessToken.trim() + : null + if (accessToken == null) { + return { + token: null, + hasRefreshableCredentials, + source, + ...(oauth != null && !hasRefreshableCredentials + ? { hasEmptyStoredEntry: true as const } + : {}) + } } // Why: expiresAt is not authoritative for the usage endpoint; let the server decide. - return { token: oauth.accessToken, hasRefreshableCredentials, source } + return { token: accessToken, hasRefreshableCredentials, source } } catch { return emptyClaudeOAuthCredentialReadResult() } @@ -86,9 +102,10 @@ async function readFromKeychain(configDir?: string): Promise { }) }) + it('classifies a stored-but-empty entry as signed-out, not missing', () => { + expect( + classifyClaudeCredentialAbsence({ + hasRefreshableCredentials: false, + hasEmptyStoredEntry: true + }) + ).toMatchObject({ + failureKind: 'signed-out', + shouldAttemptCliFallback: false, + shouldAttemptDelegatedRefresh: false, + terminal: true + }) + }) + it('classifies live Claude ownership as a deferred state', () => { expect( classifyClaudeCredentialAbsence({ diff --git a/src/main/rate-limits/claude-usage-error-classification.ts b/src/main/rate-limits/claude-usage-error-classification.ts index 71c88c242bd8..b77e5ef28618 100644 --- a/src/main/rate-limits/claude-usage-error-classification.ts +++ b/src/main/rate-limits/claude-usage-error-classification.ts @@ -41,12 +41,16 @@ export function classifyClaudeOAuthUsageError(error: unknown): ClaudeUsageErrorC export function classifyClaudeCredentialAbsence(input: { hasRefreshableCredentials: boolean + hasEmptyStoredEntry?: boolean keychainUnavailable?: boolean managedRefreshDeferredByLivePty?: boolean }): ClaudeUsageErrorClassification { if (input.managedRefreshDeferredByLivePty) { return terminal('deferred-by-live-session') } + if (input.hasEmptyStoredEntry) { + return terminal('signed-out') + } if (input.keychainUnavailable) { return fallbackOnly('keychain-unavailable') } diff --git a/src/renderer/src/components/settings/AccountsPane.tsx b/src/renderer/src/components/settings/AccountsPane.tsx index 3af24a986fd0..8f0acdb48228 100644 --- a/src/renderer/src/components/settings/AccountsPane.tsx +++ b/src/renderer/src/components/settings/AccountsPane.tsx @@ -27,6 +27,7 @@ import { import { getRemoteAccountsPaneScope } from './provider-account-scope' import { ProviderHostScopeControl } from './ProviderHostScopeControl' import { matchesSettingsSearch } from './settings-search' +import { getClaudeSystemDefaultSignInWarning } from './claude-account-auth-warning' import { getCodexAccountAuthWarning } from './codex-account-auth-warning' import { getCodexConfigSyncWarning } from './codex-config-sync-warning' import { @@ -72,6 +73,8 @@ export function AccountsPane({ accountOwnerPlatform = null }: AccountsPaneProps): React.JSX.Element { const searchQuery = useAppStore((s) => s.settingsSearchQuery) + const claudeRateLimits = useAppStore((s) => s.rateLimits.claude) + const claudeRateLimitTarget = useAppStore((s) => s.rateLimits.claudeTarget) const codexRateLimits = useAppStore((s) => s.rateLimits.codex) const codexRateLimitTarget = useAppStore((s) => s.rateLimits.codexTarget) const miniMaxRateLimits = useAppStore((s) => s.rateLimits.minimax) @@ -143,6 +146,7 @@ export function AccountsPane({ const [codexAction, setCodexAction] = useState('idle') const [claudeAccounts, setClaudeAccounts] = useState(emptyClaudeAccountsState) + const [claudeAccountsLoaded, setClaudeAccountsLoaded] = useState(false) const [claudeAction, setClaudeAction] = useState('idle') // Why: capture the account's runtime slot when the dialog opens; the roster // can change underneath an open dialog and lose the slot to diff for restarts. @@ -213,6 +217,16 @@ export function AccountsPane({ const codexConfigSyncWarning = getCodexConfigSyncWarning(codexConfigSync) const systemCodexMissingSignIn = activeCodexAuthWarning === 'missing-sign-in' const systemCodexNeedsSignIn = activeCodexAccountId === null && Boolean(activeCodexAuthWarning) + // Why: remote snapshots own their system-default login, but the desktop's + // usage poll must not be misattributed to a remote account owner (#7973). + const systemClaudeNeedsSignIn = + claudeAccountsLoaded && + getClaudeSystemDefaultSignInWarning({ + limits: isRemoteAccountScope ? null : claudeRateLimits, + target: claudeRateLimitTarget, + runtime: accountRuntime, + systemActive: systemClaudeActive + }) const accountRuntimeUnavailable = accountRuntime.runtime === 'wsl' && !wslAvailable && !wslCapabilitiesLoading @@ -249,6 +263,10 @@ export function AccountsPane({ }, []) useEffect(() => { + // Why: a runtime switch replaces the roster underneath; keep the loaded + // gate shut until the new owner's snapshot arrives so empty-roster + // derivations (like the system-default warning) cannot flash stale state. + setClaudeAccountsLoaded(false) // Why: remote snapshots stream usage refreshes after the synchronous ready // message, so the watcher stays open for the pane's lifetime; the local // path resolves once and the close() is a no-op. @@ -264,6 +282,7 @@ export function AccountsPane({ } if (!snapshot.failedProviders?.includes('claude')) { setClaudeAccounts(snapshot.claude) + setClaudeAccountsLoaded(true) } }, onError: (error) => { @@ -299,6 +318,7 @@ export function AccountsPane({ isRemoteAccountScope, claudeAccounts, setClaudeAccounts, + setClaudeAccountsLoaded, setClaudeAction, fetchSettings, recordFeatureInteraction @@ -325,6 +345,7 @@ export function AccountsPane({ claudeAction, visibleClaudeAccounts, systemClaudeActive, + systemClaudeNeedsSignIn, setRemoveClaudeTarget, runClaudeAccountAction, codexAccounts, diff --git a/src/renderer/src/components/settings/accounts-pane-account-actions.ts b/src/renderer/src/components/settings/accounts-pane-account-actions.ts index 98ba3cac3f99..598e296d2227 100644 --- a/src/renderer/src/components/settings/accounts-pane-account-actions.ts +++ b/src/renderer/src/components/settings/accounts-pane-account-actions.ts @@ -144,6 +144,7 @@ type ClaudeActionContext = { isRemoteAccountScope: boolean claudeAccounts: ClaudeRateLimitAccountsState setClaudeAccounts: Dispatch> + setClaudeAccountsLoaded: Dispatch> setClaudeAction: Dispatch> fetchSettings: () => Promise recordFeatureInteraction: (featureId: FeatureInteractionId) => void @@ -159,10 +160,12 @@ export function createClaudeAccountActionRunner( isRemoteAccountScope, recordFeatureInteraction, setClaudeAccounts, + setClaudeAccountsLoaded, setClaudeAction } = context const syncClaudeAccounts = async (next: ClaudeRateLimitAccountsState): Promise => { setClaudeAccounts(next) + setClaudeAccountsLoaded(true) if (!isRemoteAccountScope) { await fetchSettings() } diff --git a/src/renderer/src/components/settings/accounts-pane-claude-section.tsx b/src/renderer/src/components/settings/accounts-pane-claude-section.tsx index e99758f0db54..70b202460115 100644 --- a/src/renderer/src/components/settings/accounts-pane-claude-section.tsx +++ b/src/renderer/src/components/settings/accounts-pane-claude-section.tsx @@ -27,6 +27,7 @@ export function renderClaudeAccountsSection(model: AccountsPaneSectionModel): Re setRemoveClaudeTarget, settings, systemClaudeActive, + systemClaudeNeedsSignIn, visibleClaudeAccounts, wslCapabilitiesLoading } = model @@ -131,9 +132,11 @@ export function renderClaudeAccountsSection(model: AccountsPaneSectionModel): Re } disabled={claudeAction !== 'idle' || accountRuntimeUnavailable} className={`flex w-full items-center justify-between gap-3 rounded-md border px-3 py-2.5 text-left transition-colors ${ - systemClaudeActive - ? 'border-foreground/20 bg-accent/15' - : 'border-border/70 hover:border-border hover:bg-accent/8' + systemClaudeNeedsSignIn + ? 'border-destructive/50 bg-destructive/5' + : systemClaudeActive + ? 'border-foreground/20 bg-accent/15' + : 'border-border/70 hover:border-border hover:bg-accent/8' } disabled:cursor-default disabled:opacity-100`} >
@@ -141,7 +144,8 @@ export function renderClaudeAccountsSection(model: AccountsPaneSectionModel): Re {translate('auto.components.settings.AccountsPane.f2a265f8c7', 'System default')} - {systemClaudeActive ? ( + {/* Why: a row cannot read as both selected-healthy and broken — the warning replaces Active, not joins it. */} + {systemClaudeActive && !systemClaudeNeedsSignIn ? ( ) : null} + {systemClaudeNeedsSignIn ? ( + + {translate('auto.components.settings.AccountsPane.93c47b333a', 'Needs sign-in')} + + ) : null}
- + {translate( 'auto.components.settings.AccountsPane.e05d0ff737', 'Use your current {{value0}} Claude login.', diff --git a/src/renderer/src/components/settings/accounts-pane-types.ts b/src/renderer/src/components/settings/accounts-pane-types.ts index 4828ec9ddc5c..8a8f78ff0a0c 100644 --- a/src/renderer/src/components/settings/accounts-pane-types.ts +++ b/src/renderer/src/components/settings/accounts-pane-types.ts @@ -81,6 +81,7 @@ export type AccountsPaneSectionModel = { claudeAction: ClaudeAccountAction visibleClaudeAccounts: ClaudeRateLimitAccountsState['accounts'] systemClaudeActive: boolean + systemClaudeNeedsSignIn: boolean setRemoveClaudeTarget: Dispatch> runClaudeAccountAction: ClaudeAccountActionRunner codexAccounts: CodexRateLimitAccountsState diff --git a/src/renderer/src/components/settings/claude-account-auth-warning.test.ts b/src/renderer/src/components/settings/claude-account-auth-warning.test.ts new file mode 100644 index 000000000000..54dd4fa7ac5d --- /dev/null +++ b/src/renderer/src/components/settings/claude-account-auth-warning.test.ts @@ -0,0 +1,100 @@ +import { describe, expect, it } from 'vitest' +import type { + ProviderRateLimits, + UsageRateLimitFailureKind +} from '../../../../shared/rate-limit-types' +import { + claudeRateLimitTargetMatchesAccountRuntime, + getClaudeSystemDefaultSignInWarning +} from './claude-account-auth-warning' + +function claudeLimits( + status: ProviderRateLimits['status'], + failureKind: UsageRateLimitFailureKind = 'signed-out' +): ProviderRateLimits { + return { + provider: 'claude', + session: null, + weekly: null, + updatedAt: 1, + error: 'Claude sign-in expired', + status, + usageMetadata: { failureKind } + } +} + +const hostTarget = { runtime: 'host', wslDistro: null } as const + +describe('claude system default sign-in warning', () => { + it('warns when the host snapshot reports signed-out', () => { + expect( + getClaudeSystemDefaultSignInWarning({ + limits: claudeLimits('error'), + target: hostTarget, + runtime: { runtime: 'host' }, + systemActive: true + }) + ).toBe(true) + }) + + it('stays quiet when a managed account is selected', () => { + expect( + getClaudeSystemDefaultSignInWarning({ + limits: claudeLimits('error'), + target: hostTarget, + runtime: { runtime: 'host' }, + systemActive: false + }) + ).toBe(false) + }) + + it('stays quiet for other failure kinds and non-error snapshots', () => { + const base = { + target: hostTarget, + runtime: { runtime: 'host' }, + systemActive: true + } as const + expect( + getClaudeSystemDefaultSignInWarning({ + ...base, + limits: claudeLimits('error', 'missing-credentials') + }) + ).toBe(false) + expect( + getClaudeSystemDefaultSignInWarning({ + ...base, + limits: claudeLimits('unavailable', 'signed-out') + }) + ).toBe(false) + expect(getClaudeSystemDefaultSignInWarning({ ...base, limits: null })).toBe(false) + }) + + it('stays quiet when the snapshot target does not match the viewed runtime', () => { + expect( + getClaudeSystemDefaultSignInWarning({ + limits: claudeLimits('error'), + target: hostTarget, + runtime: { runtime: 'wsl', wslDistro: 'Ubuntu' }, + systemActive: true + }) + ).toBe(false) + expect( + getClaudeSystemDefaultSignInWarning({ + limits: claudeLimits('error'), + target: { runtime: 'wsl', wslDistro: 'Ubuntu' }, + runtime: { runtime: 'wsl', wslDistro: 'Ubuntu' }, + systemActive: true + }) + ).toBe(true) + }) + + it('matches targets the same way the Codex warning does', () => { + expect(claudeRateLimitTargetMatchesAccountRuntime(hostTarget, { runtime: 'host' })).toBe(true) + expect( + claudeRateLimitTargetMatchesAccountRuntime(hostTarget, { + runtime: 'wsl', + wslDistro: 'Ubuntu' + }) + ).toBe(false) + }) +}) diff --git a/src/renderer/src/components/settings/claude-account-auth-warning.ts b/src/renderer/src/components/settings/claude-account-auth-warning.ts new file mode 100644 index 000000000000..2849edb347e7 --- /dev/null +++ b/src/renderer/src/components/settings/claude-account-auth-warning.ts @@ -0,0 +1,39 @@ +import type { + ProviderRateLimits, + RateLimitRuntimeTarget +} from '../../../../shared/rate-limit-types' + +type AccountRuntime = { + runtime: 'host' | 'wsl' + wslDistro?: string | null +} + +export function claudeRateLimitTargetMatchesAccountRuntime( + target: RateLimitRuntimeTarget, + runtime: AccountRuntime +): boolean { + if (target.runtime !== runtime.runtime) { + return false + } + if (runtime.runtime === 'host') { + return true + } + return !runtime.wslDistro || target.wslDistro === runtime.wslDistro +} + +// Why: the desktop usage snapshot describes the viewed login only when its +// target matches; otherwise the warning would blame the wrong environment. +export function getClaudeSystemDefaultSignInWarning(args: { + limits: ProviderRateLimits | null + target: RateLimitRuntimeTarget + runtime: AccountRuntime + systemActive: boolean +}): boolean { + if (!args.systemActive) { + return false + } + if (!claudeRateLimitTargetMatchesAccountRuntime(args.target, args.runtime)) { + return false + } + return args.limits?.status === 'error' && args.limits.usageMetadata?.failureKind === 'signed-out' +} 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 index 239c3314eb35..515f9d234885 100644 --- 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 @@ -291,6 +291,18 @@ describe('getVisibleUsageProvider', () => { ).toBe(unavailable) }) + it('keeps a signed-out provider visible without any managed account', () => { + // Why: an emptied credential store reports status error (not unavailable) + // so the bar shows a sign-in state instead of vanishing with no affordance. + const signedOut = provider('error', { + provider: 'claude', + error: 'Claude sign-in expired', + usageMetadata: { failureKind: 'signed-out' } + }) + + expect(getVisibleUsageProvider('claude', signedOut, usageSettings())).toBe(signedOut) + }) + it('hides providers with no live data or durable configuration', () => { expect(getVisibleUsageProvider('codex', null, usageSettings())).toBe(null) expect(getVisibleUsageProvider('grok', undefined, usageSettings())).toBe(null) diff --git a/src/renderer/src/components/status-bar/usage-error-copy.test.ts b/src/renderer/src/components/status-bar/usage-error-copy.test.ts index b68a2fb05f68..6f5153b26f65 100644 --- a/src/renderer/src/components/status-bar/usage-error-copy.test.ts +++ b/src/renderer/src/components/status-bar/usage-error-copy.test.ts @@ -4,12 +4,26 @@ vi.mock('@/i18n/i18n', () => ({ translate: (_key: string, fallback: string) => fallback })) +import type { ProviderRateLimits } from '../../../../shared/rate-limit-types' import { getProviderDisplayName, getProviderUsageErrorMessage, getProviderUsageStatusLabel } from './usage-error-copy' +function claudeError(overrides: Partial = {}): ProviderRateLimits { + return { + provider: 'claude', + session: null, + weekly: null, + updatedAt: 0, + error: 'Claude sign-in expired', + status: 'error', + usageMetadata: { failureKind: 'signed-out' }, + ...overrides + } +} + describe('getProviderDisplayName', () => { it('returns the Antigravity brand name', () => { expect(getProviderDisplayName('antigravity')).toBe('Antigravity') @@ -28,6 +42,14 @@ describe('getProviderDisplayName', () => { expect(getProviderDisplayName('grok')).toBe('Grok') }) + it('labels a signed-out Claude snapshot as not signed in', () => { + expect(getProviderUsageStatusLabel(claudeError())).toBe('not signed in') + }) + + it('surfaces the signed-out message instead of generic auth copy', () => { + expect(getProviderUsageErrorMessage(claudeError())).toBe('Claude sign-in expired') + }) + it('falls back to the raw provider id when no mapping exists', () => { // Why: provider id is a closed union, but TypeScript may not enforce // exhaustiveness on dynamic callers. Fallback keeps logging safe. diff --git a/src/renderer/src/components/status-bar/usage-error-copy.ts b/src/renderer/src/components/status-bar/usage-error-copy.ts index 8dd8ec7f2aa8..a11c53909775 100644 --- a/src/renderer/src/components/status-bar/usage-error-copy.ts +++ b/src/renderer/src/components/status-bar/usage-error-copy.ts @@ -85,6 +85,8 @@ export function getProviderUsageStatusLabel(p: ProviderRateLimits): string { } if (p.provider === 'claude') { switch (p.usageMetadata?.failureKind) { + case 'signed-out': + return translate('auto.components.status.bar.UsageRosterPanel.notSignedIn', 'not signed in') case 'deferred-by-live-session': return translate( 'auto.components.status.bar.tooltip.0d8d7cfe15', @@ -186,6 +188,10 @@ export function getProviderUsageErrorMessage(p: ProviderRateLimits): string { 'auto.components.status.bar.tooltip.a7517cccb6', 'Claude usage is unavailable right now.' ) + // Why: the main-process 'Claude sign-in expired' string is intentionally + // pattern-safe (matches no auth-error rewrite), so it surfaces verbatim. + case 'signed-out': + return p.error ?? fallback case 'missing-credentials': case 'no-subscription': case 'rate-limited': diff --git a/src/renderer/src/components/status-bar/usage-roster-row-state.test.ts b/src/renderer/src/components/status-bar/usage-roster-row-state.test.ts index b63a9a3ad5b1..7d9e7205fd47 100644 --- a/src/renderer/src/components/status-bar/usage-roster-row-state.test.ts +++ b/src/renderer/src/components/status-bar/usage-roster-row-state.test.ts @@ -57,6 +57,16 @@ describe('getUsageRosterRowState', () => { false ) ).toEqual({ kind: 'sign-in', statusLabel: 'not signed in' }) + expect( + getUsageRosterRowState( + provider({ + status: 'error', + error: 'Claude sign-in expired', + usageMetadata: { failureKind: 'signed-out' } + }), + false + ) + ).toEqual({ kind: 'sign-in', statusLabel: 'not signed in' }) expect( getUsageRosterRowState( provider({ diff --git a/src/renderer/src/components/status-bar/usage-roster-row-state.ts b/src/renderer/src/components/status-bar/usage-roster-row-state.ts index 687623275994..3c339f054073 100644 --- a/src/renderer/src/components/status-bar/usage-roster-row-state.ts +++ b/src/renderer/src/components/status-bar/usage-roster-row-state.ts @@ -18,7 +18,10 @@ const CONFIRMED_SIGN_OUT_PATTERNS = [ ] function isConfirmedSignedOut(provider: ProviderRateLimits): boolean { - if (provider.usageMetadata?.failureKind === 'missing-credentials') { + if ( + provider.usageMetadata?.failureKind === 'missing-credentials' || + provider.usageMetadata?.failureKind === 'signed-out' + ) { return true } // Why: credential refresh and network failures can mention auth while live diff --git a/src/renderer/src/components/ui/badge.test.tsx b/src/renderer/src/components/ui/badge.test.tsx new file mode 100644 index 000000000000..0c213725a286 --- /dev/null +++ b/src/renderer/src/components/ui/badge.test.tsx @@ -0,0 +1,34 @@ +import { renderToStaticMarkup } from 'react-dom/server' +import { describe, expect, it } from 'vitest' +import { Badge } from './badge' + +function classTokens(html: string): string[] { + return /class="([^"]*)"/.exec(html)?.[1].split(' ') ?? [] +} + +describe('Badge', () => { + it('keeps the pill geometry by default', () => { + const classes = classTokens(renderToStaticMarkup(Label)) + + expect(classes).toEqual(expect.arrayContaining(['rounded-full', 'px-2', 'text-xs'])) + expect(classes).not.toContain('h-4') + }) + + it('replaces the pill geometry with the compact square chip', () => { + const classes = classTokens( + renderToStaticMarkup( + + Label + + ) + ) + + expect(classes).toEqual( + expect.arrayContaining(['h-4', 'rounded', 'px-1.5', 'text-[10px]', 'leading-none']) + ) + expect(classes).not.toContain('rounded-full') + expect(classes).not.toContain('px-2') + expect(classes).not.toContain('text-xs') + expect(classes).toContain('bg-destructive') + }) +}) diff --git a/src/renderer/src/components/ui/badge.tsx b/src/renderer/src/components/ui/badge.tsx index 2d2d0027e5c9..9fab03185e39 100644 --- a/src/renderer/src/components/ui/badge.tsx +++ b/src/renderer/src/components/ui/badge.tsx @@ -22,10 +22,16 @@ const badgeVariants = cva( * so it reads as context beside a workspace name rather than as a status of its own. */ hostContext: 'h-4 rounded border-border bg-accent px-1.5 text-[10px] leading-none text-muted-foreground dark:border-border/50 dark:bg-accent/80' + }, + size: { + default: '', + /** Square 16px status chip that sits inline beside a row title (e.g. "Needs sign-in"). */ + compact: 'h-4 rounded px-1.5 text-[10px] leading-none' } }, defaultVariants: { - variant: 'default' + variant: 'default', + size: 'default' } } ) @@ -33,6 +39,7 @@ const badgeVariants = cva( function Badge({ className, variant = 'default', + size = 'default', asChild = false, ...props }: React.ComponentProps<'span'> & VariantProps & { asChild?: boolean }) { @@ -42,7 +49,7 @@ function Badge({ ) diff --git a/src/shared/rate-limit-types.ts b/src/shared/rate-limit-types.ts index dd89c9e8ec69..fa336302b862 100644 --- a/src/shared/rate-limit-types.ts +++ b/src/shared/rate-limit-types.ts @@ -19,6 +19,9 @@ export type UsageRateLimitSource = 'oauth' | 'cli' | 'web' | 'live-session' export type UsageRateLimitFailureKind = | 'missing-credentials' + // Why: a stored-but-empty credential entry proves the CLI was set up and + // lost its tokens (signed out), unlike never-configured (hide the bar). + | 'signed-out' | 'stale-token' | 'refreshable-credentials-without-token' | 'delegated-refresh-required'