Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(usage): group each provider's account, meters and action into one block (#912) (#970)

ezwep9199faa12a24
diff --git a/src/renderer/components/UsageIndicator.grouping.test.tsx b/src/renderer/components/UsageIndicator.grouping.test.tsx
new file mode 100644
index 000000000..f93bbd2d3
--- /dev/null
+++ b/src/renderer/components/UsageIndicator.grouping.test.tsx
@@ -0,0 +1,132 @@
+// @vitest-environment jsdom
+// Issue #912: one block per provider that carries its own account, meters and action, with a
+// failure as one line. These pin the grouping, not the styling.
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { DEFAULT_SETTINGS, type ClaudeUsage, type ProviderUsage, type UsageLimit } from '@shared/types'
+import { useSettings } from '../state/settings'
+import { UsageIndicator } from './UsageIndicator'
+
+const limit = (kind: UsageLimit['kind'], usedPercent: number): UsageLimit => ({
+ kind, group: kind === 'session' ? 'session' : 'weekly', usedPercent, severity: null,
+ resetsAt: null, windowMinutes: 300, scopeLabel: null, isActive: false
+})
+const EMAIL = '[email protected]'
+const claude = (org?: string): ClaudeUsage => ({
+ status: 'ok', limits: [limit('session', 5), limit('weekly', 71)], session: null, weekly: null,
+ email: EMAIL, updatedAt: 0, ...(org ? { organization: { name: org } } : {})
+})
+const codex: ProviderUsage = { provider: 'codex', account: null, status: 'ok', limits: [limit('session', 74)], updatedAt: 0 }
+const grokOk: ProviderUsage = { provider: 'grok', account: null, status: 'ok', limits: [limit('weekly', 1)], updatedAt: 0 }
+
+let host: HTMLDivElement
+let root: Root
+
+beforeEach(() => {
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ root = createRoot(host)
+ useSettings.setState({ settings: { ...DEFAULT_SETTINGS, usagePercentMode: 'remaining' } })
+})
+
+afterEach(() => {
+ act(() => root.unmount())
+ host.remove()
+ useSettings.setState({ settings: DEFAULT_SETTINGS })
+ vi.unstubAllGlobals()
+})
+
+async function open(system: ClaudeUsage, providers: ProviderUsage[], managed?: ClaudeUsage) {
+ vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true)
+ vi.stubGlobal('nodeTerminal', { usage: {
+ fetch: async (id?: string) => (id && managed ? managed : system),
+ providers: async () => providers,
+ onUpdate: () => () => {}
+ } })
+ await act(async () => root.render(<UsageIndicator />))
+ await act(async () => host.querySelector('.usage-indicator')!.dispatchEvent(
+ new MouseEvent('mouseover', { bubbles: true })
+ ))
+}
+
+const headings = (): string[] =>
+ [...host.querySelectorAll('.usage-account__label')].map((el) => el.textContent ?? '')
+const switchButton = (): HTMLButtonElement | null =>
+ host.querySelector<HTMLButtonElement>('.usage-popover__switch')
+/** The block a provider's heading opens — its nearest enclosing grouping element. */
+const blockOf = (heading: string): Element => {
+ const el = [...host.querySelectorAll('.usage-account__label')].find((h) => h.textContent === heading)
+ if (!el?.parentElement) throw new Error(`no block headed ${heading}`)
+ return el.parentElement
+}
+
+describe('usage popover groups each provider into one block (issue #912)', () => {
+ it('puts the Claude account inside the Claude block, not under a fourth peer heading', async () => {
+ await open(claude('Acme'), [codex, grokOk])
+ expect(headings()).toEqual(['Claude', 'Codex', 'Grok'])
+ const block = blockOf('Claude')
+ expect(block.textContent).toContain(EMAIL)
+ expect(block.textContent).toContain('Organization: Acme')
+ expect(block.querySelectorAll('.usage-row').length).toBeGreaterThanOrEqual(2)
+ expect(host.textContent).not.toContain('Claude Account')
+ })
+
+ it('puts "Switch Claude account…" inside the Claude block, before any other provider', async () => {
+ await open(claude(), [codex, grokOk])
+ const btn = switchButton()
+ expect(btn).not.toBeNull()
+ expect(blockOf('Claude').contains(btn)).toBe(true)
+ expect(blockOf('Grok').contains(btn)).toBe(false)
+ // Document order: the action is read before the Codex heading, never after Grok's rows.
+ const codexHeading = [...host.querySelectorAll('.usage-account__label')].find((h) => h.textContent === 'Codex')!
+ expect(btn!.compareDocumentPosition(codexHeading) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
+ })
+
+ it('keeps the switch with the system account when managed accounts are listed', async () => {
+ useSettings.setState({ settings: { ...DEFAULT_SETTINGS, usagePercentMode: 'remaining',
+ claudeAccounts: [{ id: 'work', label: 'Work', email: EMAIL, createdAt: 0 }] } })
+ await open(claude(), [grokOk], claude())
+ const blocks = [...host.querySelectorAll('.usage-popover__body > .usage-account')]
+ const btn = switchButton()
+ expect(btn).not.toBeNull()
+ expect(blocks[0].contains(btn)).toBe(true)
+ expect(blocks.slice(1).some((b) => b.contains(btn))).toBe(false)
+ })
+
+ it('prints an identical per-view failure once for the provider', async () => {
+ await open(claude(), [{ provider: 'grok', account: null, status: 'error', limits: [], updatedAt: 0,
+ diagnostics: [
+ { view: 'credits', reason: 'http', httpStatus: 401 },
+ { view: 'default', reason: 'http', httpStatus: 401 }
+ ] }])
+ const text = blockOf('Grok').textContent ?? ''
+ expect(text.split('Grok authentication failed (HTTP 401)')).toHaveLength(2)
+ expect(text).toContain('Credits view and Default view: Grok authentication failed (HTTP 401)')
+ })
+
+ it('still prints differing per-view failures separately', async () => {
+ await open(claude(), [{ provider: 'grok', account: null, status: 'error', limits: [], updatedAt: 0,
+ diagnostics: [
+ { view: 'credits', reason: 'http', httpStatus: 401 },
+ { view: 'default', reason: 'timeout' }
+ ] }])
+ const text = blockOf('Grok').textContent ?? ''
+ expect(text).toContain('Credits view: Grok authentication failed (HTTP 401)')
+ expect(text).toContain('Default view: Usage request timed out')
+ })
+
+ it('keeps the organization line, de-emphasising only a name derived from the email above it', async () => {
+ await open(claude(`${EMAIL}'s Organization`), [codex])
+ const org = host.querySelector('.usage-account__organization')
+ expect(org?.textContent).toBe(`Organization: ${EMAIL}'s Organization`)
+ expect(org?.classList.contains('usage-account__organization--derived')).toBe(true)
+ })
+
+ it('does not de-emphasise a real organization name', async () => {
+ await open(claude('Acme Corp'), [codex])
+ const org = host.querySelector('.usage-account__organization')
+ expect(org?.textContent).toBe('Organization: Acme Corp')
+ expect(org?.classList.contains('usage-account__organization--derived')).toBe(false)
+ })
+})
diff --git a/src/renderer/components/UsageIndicator.organization.test.tsx b/src/renderer/components/UsageIndicator.organization.test.tsx
index 4cfed9d17..f103dbd91 100644
--- a/src/renderer/components/UsageIndicator.organization.test.tsx
+++ b/src/renderer/components/UsageIndicator.organization.test.tsx
@@ -38,7 +38,7 @@ async function open() {
}
it('shows the active organization beside the system email and keeps the raw tier in the tooltip', async () => {
await open()
- const row = host.querySelector('.usage-account')!
+ const row = host.querySelector('.usage-claude__account')!
expect(row.textContent).toContain('[email protected]')
expect(row.textContent).toContain('Organization: Personal')
expect(row.textContent).not.toContain('default_raven')
@@ -58,11 +58,12 @@ it('keeps same-email organizations in separate account rows and prefers the fetc
it('keeps the email-only block when organization metadata is unavailable', async () => {
system = snapshot()
await open()
- expect(host.querySelector('.usage-account')?.textContent).toBe('Claude [email protected]')
+ // Issue #912: the account is a row of the Claude block, not a "Claude Account" peer section.
+ expect(host.querySelector('.usage-claude__account')?.textContent).toBe('[email protected]')
expect(host.querySelector('.usage-account__organization')).toBeNull()
})
it('shows an available organization even when no email was found', async () => {
system.email = null
await open()
- expect(host.querySelector('.usage-account')?.textContent).toContain('Organization: Personal')
+ expect(host.querySelector('.usage-claude__account')?.textContent).toContain('Organization: Personal')
})
diff --git a/src/renderer/components/UsageIndicator.test.tsx b/src/renderer/components/UsageIndicator.test.tsx
index ae9f0cd5a..7da82b1ce 100644
--- a/src/renderer/components/UsageIndicator.test.tsx
+++ b/src/renderer/components/UsageIndicator.test.tsx
@@ -87,7 +87,7 @@ describe('Claude usage failure readout', () => {
it('still attributes the Claude failure when another provider has data', async () => {
await open(snapshot('error'), undefined, [{ provider: 'codex', account: null, status: 'ok', limits: [limit], updatedAt: 0 }])
expect(host.querySelector('.usage-popover__empty')?.textContent).toBe('Could not read usage.')
- expect(host.querySelector('.usage-popover__body > .usage-account__label')?.textContent).toBe('Claude')
+ expect(host.querySelector('.usage-claude > .usage-account__label')?.textContent).toBe('Claude')
expect(host.querySelectorAll('.usage-row')).toHaveLength(1)
})
diff --git a/src/renderer/components/UsageIndicator.tsx b/src/renderer/components/UsageIndicator.tsx
index fc50d62c4..2df03f7c6 100644
--- a/src/renderer/components/UsageIndicator.tsx
+++ b/src/renderer/components/UsageIndicator.tsx
@@ -1,4 +1,4 @@
-import { usageDiagnosticText } from '../lib/usageDiagnostic'
+import { usageDiagnosticLines } from '../lib/usageDiagnostic'
import { useEffect, useMemo, useRef, useState } from 'react'
import { UsageOrganization } from './UsageOrganization'
import { IconReload } from './icons'
@@ -215,7 +215,8 @@ function AccountUsageBlock({
mode,
isDefault = false,
onUse,
- move
+ move,
+ action
}: {
label: string
email?: string
@@ -224,7 +225,10 @@ function AccountUsageBlock({
isDefault?: boolean
onUse?: () => void
move?: React.ReactNode
+ /** An action that belongs to THIS account (the system row's "Switch Claude account…"). */
+ action?: React.ReactNode
}) {
+ const shownEmail = u?.email ?? email
return (
<div className="usage-account">
<div className="usage-account__label">
@@ -232,8 +236,8 @@ function AccountUsageBlock({
<DefaultAccountMark isDefault={isDefault} onUse={onUse} />
{move}
</div>
- {(u?.email ?? email) && <div className="usage-account__email">{u?.email ?? email}</div>}
- <UsageOrganization organization={u?.organization} />
+ {shownEmail && <div className="usage-account__email">{shownEmail}</div>}
+ <UsageOrganization organization={u?.organization} email={shownEmail} />
{u?.limits.map((l) => (
<LimitRow key={limitKey(l)} limit={l} mode={mode} />
))}
@@ -244,6 +248,7 @@ function AccountUsageBlock({
</div>
)}
{!u && <div className="usage-popover__empty usage-pill__pulse">···</div>}
+ {action}
</div>
)
}
@@ -320,9 +325,11 @@ function ProviderBlock({ u, mode, hostKey }: { u: ProviderUsage; mode: 'used' |
{u.limits.map((l) => (
<LimitRow key={limitKey(l)} limit={l} mode={mode} />
))}
- {u.diagnostics?.map((diagnostic, index) => (
- <div className="usage-popover__empty" key={index}>
- {usageDiagnosticText(label, diagnostic)}
+ {/* One line per distinct reason (issue #912): two views failing the same way are one
+ failure of this provider, not two paragraphs of the same sentence. */}
+ {usageDiagnosticLines(label, u.diagnostics).map((line) => (
+ <div className="usage-popover__empty" key={line}>
+ {line}
</div>
))}
{u.limits.length === 0 && !u.diagnostics?.length && (
@@ -653,6 +660,41 @@ export function UsageIndicator({
}
}
+ // Issue #420 — "Switch account" where the limit is displayed: opens a terminal running the
+ // SYSTEM-scoped `claude /login` (createSystemLoginNode), so picking the other org is one click
+ // from the panel that said you need to. Nothing changes until the user completes the login IN
+ // that terminal — the CLI's own org picker + OAuth — which is why there is no confirm dialog in
+ // front of it: the terminal is the confirmation surface, and the tooltip names what completing
+ // it changes. LOCAL scope only: on an SSH project a system login would rewrite the HOST's
+ // ~/.claude, and saying "switch account" while meaning another machine's identity is the kind of
+ // ambiguity this popover exists to avoid. Hidden with the Claude provider — a switch button for
+ // numbers the user chose not to see would be an orphan.
+ // Issue #912: it is rendered INSIDE the block of the account it switches (the Claude block, or
+ // the System row when managed accounts are listed). As a popover footer it sat under whichever
+ // provider happened to be last, and read as that provider's action.
+ const switchAction =
+ scope.kind === 'local' && !hidden.has('claude') ? (
+ <button
+ type="button"
+ className="usage-popover__switch"
+ title={
+ 'Opens a terminal running `claude /login` for the system account (~/.claude). ' +
+ 'Completing it switches the org/account all system sessions use — running ' +
+ 'sessions carry on under the new one. Managed accounts keep their own logins.'
+ }
+ onClick={() => {
+ setOpen(false)
+ window.dispatchEvent(new CustomEvent('nodeterm:switch-system-account'))
+ }}
+ >
+ ⇄ Switch Claude account…
+ </button>
+ ) : null
+ // The single-account Claude block: its meters, its account and its action together. The
+ // heading appears once another provider shares the panel, exactly as before.
+ const claudeAccountShown = !!(claudeUsage?.email || claudeUsage?.organization)
+ const claudeHasContent = limits.length > 0 || claudeError || claudeAccountShown
+
let pillBody: JSX.Element
if (!hasData && fetching) {
pillBody = <span className="usage-pill__dim usage-pill__pulse">···</span>
@@ -728,11 +770,12 @@ export function UsageIndicator({
<span className="usage-popover__ago">Updated {formatTimeAgo(updatedAt)}</span>
)}
</div>
- {/* Issue #503: the account blocks SCROLL, the heading and the footer action do not.
- Each account is a tall block (name + Session/Weekly/Opus meters), so past about
- four accounts the popover grew off the top of the window — the first account's
- header and meter were clipped with no way to reach them. Same rule as the session
- memory panel's row list: every row is rendered, the list scrolls. */}
+ {/* Issue #503: the account blocks SCROLL, the heading does not. Each account is a tall
+ block (name + Session/Weekly/Opus meters), so past about four accounts the popover
+ grew off the top of the window — the first account's header and meter were clipped
+ with no way to reach them. Same rule as the session memory panel's row list: every
+ row is rendered, the list scrolls. The switch action scrolls WITH its block since
+ issue #912 — it belongs to the Claude/System block, which is always first. */}
<div className="usage-popover__body">
{/* The local Claude section belongs to a LOCAL project only. On an SSH project the
remote blocks below carry the same limits, and rendering both would print the
@@ -748,6 +791,7 @@ export function UsageIndicator({
u={claudeUsage}
{...rowMark(null)}
move={moveFor(null)}
+ action={switchAction}
/>
{scoped.accounts.map((a) => (
<AccountUsageBlock
@@ -762,10 +806,10 @@ export function UsageIndicator({
))}
</>
) : (
- <>
+ <div className="usage-claude">
{/* Claude's rows are bare when it is the only provider; once others share the
panel they need a heading of their own to stay attributable. */}
- {enabled.length > 0 && (limits.length > 0 || claudeError) && (
+ {enabled.length > 0 && claudeHasContent && (
<div className="usage-account__label">Claude</div>
)}
{limits.map((l) => (
@@ -779,14 +823,23 @@ export function UsageIndicator({
{claudeError ? usageFailureText(claudeUsage) : 'No usage data.'}
</div>
)}
- {(claudeUsage?.email || claudeUsage?.organization) && (
- <div className="usage-account">
- <div className="usage-account__label">Claude Account</div>
- <div className="usage-account__email">{claudeUsage.email}</div>
- <UsageOrganization organization={claudeUsage.organization} />
+ {/* Issue #912: the account is part of Claude's block, set like a meter row
+ under the provider heading — not a fourth peer section between Claude's
+ meters and the next provider. */}
+ {claudeAccountShown && (
+ <div className="usage-row usage-claude__account">
+ <div className="usage-row__title">Account</div>
+ {claudeUsage?.email && (
+ <div className="usage-account__email">{claudeUsage.email}</div>
+ )}
+ <UsageOrganization
+ organization={claudeUsage?.organization}
+ email={claudeUsage?.email}
+ />
</div>
)}
- </>
+ {switchAction}
+ </div>
))}
{/* On an SSH project these are the whole panel; the host badge is what says the numbers
were read somewhere other than this machine. */}
@@ -815,33 +868,6 @@ export function UsageIndicator({
<ProviderBlock key={providerRowKey(p)} u={p} mode={percentMode} />
))}
</div>
- {/* Issue #420 — "Switch account" where the limit is displayed: opens a terminal
- running the SYSTEM-scoped `claude /login` (createSystemLoginNode), so picking the
- other org is one click from the panel that said you need to. Nothing changes until
- the user completes the login IN that terminal — the CLI's own org picker + OAuth —
- which is why there is no confirm dialog in front of it: the terminal is the
- confirmation surface, and the tooltip names what completing it changes. LOCAL scope
- only: on an SSH project a system login would rewrite the HOST's ~/.claude, and
- saying "switch account" while meaning another machine's identity is the kind of
- ambiguity this popover exists to avoid. Hidden with the Claude provider — a switch
- button for numbers the user chose not to see would be an orphan. */}
- {scope.kind === 'local' && !hidden.has('claude') && (
- <button
- type="button"
- className="usage-popover__switch"
- title={
- 'Opens a terminal running `claude /login` for the system account (~/.claude). ' +
- 'Completing it switches the org/account all system sessions use — running ' +
- 'sessions carry on under the new one. Managed accounts keep their own logins.'
- }
- onClick={() => {
- setOpen(false)
- window.dispatchEvent(new CustomEvent('nodeterm:switch-system-account'))
- }}
- >
- ⇄ Switch Claude account…
- </button>
- )}
</div>
)}
{/* The SSH pill is visually identical to the local one — same labels, same bar — so the
diff --git a/src/renderer/components/UsageOrganization.tsx b/src/renderer/components/UsageOrganization.tsx
index fc2081d93..221e15205 100644
--- a/src/renderer/components/UsageOrganization.tsx
+++ b/src/renderer/components/UsageOrganization.tsx
@@ -1,15 +1,29 @@
import type { ClaudeUsageOrganization } from '@shared/types'
-/** Optional identity detail: old snapshots and unreadable metadata keep the email-only view. */
-export function UsageOrganization({ organization }: { organization?: ClaudeUsageOrganization }) {
+/**
+ * Optional identity detail: old snapshots and unreadable metadata keep the email-only view.
+ * A personal organization is named after the account's email ("<email>'s Organization"), so
+ * beside that email the line only repeats it — it stays (it is the real name), just quieter.
+ */
+export function UsageOrganization({
+ organization,
+ email
+}: {
+ organization?: ClaudeUsageOrganization
+ email?: string | null
+}) {
if (!organization?.name) return null
const detail = [
organization.type && `Type: ${organization.type}`,
organization.rateLimitTier && `Rate limit tier: ${organization.rateLimitTier}`,
organization.uuid && `Organization ID: ${organization.uuid}`
].filter(Boolean).join('\n')
+ const derived = !!email && organization.name === `${email}'s Organization`
return (
- <div className="usage-account__organization" title={detail || undefined}>
+ <div
+ className={`usage-account__organization${derived ? ' usage-account__organization--derived' : ''}`}
+ title={detail || undefined}
+ >
Organization: {organization.name}
</div>
)
diff --git a/src/renderer/lib/usageDiagnostic.test.ts b/src/renderer/lib/usageDiagnostic.test.ts
new file mode 100644
index 000000000..0977d2e1f
--- /dev/null
+++ b/src/renderer/lib/usageDiagnostic.test.ts
@@ -0,0 +1,40 @@
+import { describe, expect, it } from 'vitest'
+import { usageDiagnosticLines, usageDiagnosticText } from './usageDiagnostic'
+
+describe('usageDiagnosticLines (issue #912)', () => {
+ it('prints one line per view when the reasons differ', () => {
+ expect(usageDiagnosticLines('Grok', [
+ { view: 'credits', reason: 'http', httpStatus: 401 },
+ { view: 'default', reason: 'timeout' }
+ ])).toEqual([
+ usageDiagnosticText('Grok', { view: 'credits', reason: 'http', httpStatus: 401 }),
+ usageDiagnosticText('Grok', { view: 'default', reason: 'timeout' })
+ ])
+ })
+
+ it('prints an identical reason ONCE, naming every view it applies to', () => {
+ const lines = usageDiagnosticLines('Grok', [
+ { view: 'credits', reason: 'http', httpStatus: 401 },
+ { view: 'default', reason: 'http', httpStatus: 401 }
+ ])
+ expect(lines).toHaveLength(1)
+ expect(lines[0]).toMatch(/^Credits view and Default view: Grok authentication failed \(HTTP 401\)/)
+ })
+
+ it('keeps a single diagnostic byte-identical to the per-view text', () => {
+ const d = { view: 'credits', reason: 'network' } as const
+ expect(usageDiagnosticLines('Grok', [d])).toEqual([usageDiagnosticText('Grok', d)])
+ })
+
+ it('does not name a view twice when it reports the same reason twice', () => {
+ expect(usageDiagnosticLines('Grok', [
+ { view: 'credits', reason: 'timeout' },
+ { view: 'credits', reason: 'timeout' }
+ ])).toEqual([usageDiagnosticText('Grok', { view: 'credits', reason: 'timeout' })])
+ })
+
+ it('returns nothing for no diagnostics', () => {
+ expect(usageDiagnosticLines('Grok', undefined)).toEqual([])
+ expect(usageDiagnosticLines('Grok', [])).toEqual([])
+ })
+})
diff --git a/src/renderer/lib/usageDiagnostic.ts b/src/renderer/lib/usageDiagnostic.ts
index d3c7ced78..26d56e275 100644
--- a/src/renderer/lib/usageDiagnostic.ts
+++ b/src/renderer/lib/usageDiagnostic.ts
@@ -1,24 +1,53 @@
import type { UsageDiagnostic } from '@shared/types'
-/** Static copy only: diagnostics never carry provider response text or credential details. */
-export function usageDiagnosticText(provider: string, diagnostic: UsageDiagnostic): string {
- const view = diagnostic.view === 'credits' ? 'Credits view' : 'Default view'
- let message: string
+function viewLabel(view: UsageDiagnostic['view']): string {
+ return view === 'credits' ? 'Credits view' : 'Default view'
+}
+
+/** The reason sentence alone, without the view it was read from. */
+function usageDiagnosticMessage(provider: string, diagnostic: UsageDiagnostic): string {
switch (diagnostic.reason) {
- case 'timeout': message = 'Usage request timed out. Try again later.'; break
- case 'network': message = `Could not reach ${provider}. Check the connection and try again.`; break
- case 'invalid-response': message = 'Usage response could not be read. Try again later.'; break
+ case 'timeout': return 'Usage request timed out. Try again later.'
+ case 'network': return `Could not reach ${provider}. Check the connection and try again.`
+ case 'invalid-response': return 'Usage response could not be read. Try again later.'
case 'http': {
const status = diagnostic.httpStatus
- message = status === 401 || status === 403
+ return status === 401 || status === 403
? `${provider} authentication failed (HTTP ${status}). Check the CLI authentication on the machine running this project.`
: status === 429
? 'Usage request rate limited (HTTP 429). Try again later.'
: status >= 500
? `${provider} returned HTTP ${status}. Try again later.`
: `Usage request failed (HTTP ${status}). Check the provider service and CLI configuration.`
- break
}
}
- return `${view}: ${message}`
+}
+
+/** Static copy only: diagnostics never carry provider response text or credential details. */
+export function usageDiagnosticText(provider: string, diagnostic: UsageDiagnostic): string {
+ return `${viewLabel(diagnostic.view)}: ${usageDiagnosticMessage(provider, diagnostic)}`
+}
+
+/**
+ * The lines a provider's failed views print (issue #912). Views stay distinct — they are different
+ * reads — but an IDENTICAL reason is printed once, naming every view it came from, instead of the
+ * same sentence verbatim per view (which made a provider with no data the tallest block).
+ */
+export function usageDiagnosticLines(
+ provider: string,
+ diagnostics: readonly UsageDiagnostic[] | undefined
+): string[] {
+ const groups = new Map<string, string[]>()
+ for (const d of diagnostics ?? []) {
+ const message = usageDiagnosticMessage(provider, d)
+ const views = groups.get(message) ?? []
+ const label = viewLabel(d.view)
+ groups.set(message, views.includes(label) ? views : [...views, label])
+ }
+ return [...groups].map(([message, views]) => `${joinViews(views)}: ${message}`)
+}
+
+function joinViews(views: readonly string[]): string {
+ if (views.length <= 1) return views[0] ?? ''
+ return `${views.slice(0, -1).join(', ')} and ${views[views.length - 1]}`
}
diff --git a/src/renderer/styles.css b/src/renderer/styles.css
index a4ff0308f..eb845609c 100644
--- a/src/renderer/styles.css
+++ b/src/renderer/styles.css
@@ -8366,14 +8366,13 @@ button.group-node__setup:disabled {
margin-left: 0;
}
-/* Popover-footer action (issue #420): opens the system-scoped `claude /login` terminal. A quiet
- full-width row, styled with the same tint/accent tokens as `.usage-account__use` so it reads
- in both themes. */
+/* "Switch Claude account…" (issue #420): opens the system-scoped `claude /login` terminal. A
+ quiet full-width row, styled with the same tint/accent tokens as `.usage-account__use` so it
+ reads in both themes. It sits INSIDE the Claude / System block it acts on (issue #912) — as a
+ popover footer it read as the action of whichever provider happened to be listed last. */
.usage-popover__switch {
display: block;
width: 100%;
- /* Stays put below the scrolling account list (issue #503). */
- flex: none;
margin-top: 10px;
padding: 5px 8px;
border: none;
@@ -8670,6 +8669,9 @@ button.group-node__setup:disabled {
color: rgba(var(--tint-rgb), 0.65);
overflow-wrap: anywhere;
}
+/* A personal organization's name is derived from the email printed right above it
+ ("<email>'s Organization"): kept (it is the real name), but quieter, since it repeats (#912). */
+.usage-account__organization--derived { color: rgba(var(--tint-rgb), 0.45); }
.seg-pill {
display: inline-flex;
diff --git a/src/renderer/styles.usage-popover.test.ts b/src/renderer/styles.usage-popover.test.ts
index 2bcb6de94..7701645e8 100644
--- a/src/renderer/styles.usage-popover.test.ts
+++ b/src/renderer/styles.usage-popover.test.ts
@@ -11,10 +11,14 @@ import { join } from 'node:path'
* account was the only workaround.
*
* The fix is structural, not cosmetic, and every part of it is load-bearing:
- * - the popover is capped and is a flex COLUMN, so the heading and the footer action stay put;
+ * - the popover is capped and is a flex COLUMN, so the heading stays put;
* - `__body` is the scroll container, and needs `min-height: 0` or a flex child refuses to
- * shrink below its content height and the cap does nothing;
- * - the "Switch account…" button lives OUTSIDE `__body`, or it scrolls away with the accounts.
+ * shrink below its content height and the cap does nothing.
+ *
+ * The "Switch Claude account…" button used to be a fixed footer OUTSIDE `__body`. Issue #912 moved
+ * it into the Claude / System block it acts on: as a footer it sat under whichever provider was
+ * listed last and read as that provider's action. That block is always first, so it scrolls with
+ * the account it belongs to rather than away from it.
*
* None of that renders in CI, and all of it is one "simplification" away from being undone.
*/
@@ -63,23 +67,20 @@ describe('.usage-popover is bounded and scrolls (issue #503)', () => {
expect(body).not.toMatch(/max-height/)
})
- it('holds the heading and the switch-account action out of the scrolling area', () => {
+ it('holds the heading out of the scrolling area', () => {
expect(ruleBody('.usage-popover__head')).toMatch(/flex:\s*none/)
- expect(ruleBody('.usage-popover__switch')).toMatch(/flex:\s*none/)
})
})
-describe('UsageIndicator wraps only the account blocks in the scroll container', () => {
- it('opens __body after the head and closes it before the switch-account button', () => {
+describe('UsageIndicator keeps the switch action with the account it switches (issue #912)', () => {
+ it('opens __body after the head and renders the switch action inside it, not as a footer', () => {
const head = TSX.indexOf('className="usage-popover__head"')
const bodyOpen = TSX.indexOf('className="usage-popover__body"')
- const switchBtn = TSX.indexOf('className="usage-popover__switch"')
expect(head).toBeGreaterThan(-1)
expect(bodyOpen).toBeGreaterThan(head)
- expect(switchBtn).toBeGreaterThan(bodyOpen)
- // The wrapper is closed before the footer button — otherwise "Switch account…" scrolls away
- // with the accounts it is meant to sit under.
- const closeBeforeSwitch = TSX.lastIndexOf('</div>', switchBtn)
- expect(closeBeforeSwitch).toBeGreaterThan(bodyOpen)
+ // Rendered by the Claude block and the System account row, both inside __body.
+ const uses = [...TSX.matchAll(/switchAction\}/g)].map((m) => m.index ?? -1)
+ expect(uses.length).toBeGreaterThanOrEqual(2)
+ for (const at of uses) expect(at).toBeGreaterThan(bodyOpen)
})
})