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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(usage): key Codex usage rows per account (U8, owed from PR 7)
Claude Coded36e28ec5dec
diff --git a/src/renderer/components/UsageIndicator.tsx b/src/renderer/components/UsageIndicator.tsxindex 5a42337e2..ead4dfbe7 100644--- a/src/renderer/components/UsageIndicator.tsx+++ b/src/renderer/components/UsageIndicator.tsx@@ -4,7 +4,14 @@ import { AGENT_CONFIG } from '@shared/agents/config'import { useSettings } from '../state/settings'import { useProjects } from '../state/projects'import { useSshConn } from '../state/sshConn'-import { accountRowAction, scopeFromKey, scopeUsage, usageScopeKey } from '../lib/usageScope'+import {+ accountRowAction,+ dedupeProviderRows,+ providerRowKey,+ scopeFromKey,+ scopeUsage,+ usageScopeKey+} from '../lib/usageScope'import {barFillPercent,formatResetCountdown,@@ -543,8 +550,11 @@ export function UsageIndicator({No usage from this host yet — it is read once the project connects.</div>)}- {visibleProviders.map((p) => (- <ProviderBlock key={p.provider} u={p} mode={percentMode} />+ {/* U8 (owed from PR 7): Codex emits one row per account, all `provider: 'codex'`.+ Key on provider+accountId so each account renders distinctly, and reduce true+ duplicates (two settings entries → the same underlying account) to one row. */}+ {dedupeProviderRows(visibleProviders).map((p) => (+ <ProviderBlock key={providerRowKey(p)} u={p} mode={percentMode} />))}</div>)}diff --git a/src/renderer/lib/usageScope.test.ts b/src/renderer/lib/usageScope.test.tsindex de79572a4..430cf579f 100644--- a/src/renderer/lib/usageScope.test.ts+++ b/src/renderer/lib/usageScope.test.ts@@ -1,6 +1,8 @@import { describe, it, expect } from 'vitest'import {accountRowAction,+ dedupeProviderRows,+ providerRowKey,scopeFromKey,scopeUsage,usageScopeFor,@@ -204,3 +206,45 @@ describe('accountRowAction', () => {expect(accountRowAction(null, [], undefined)).toBe('default')})})++describe('providerRowKey / dedupeProviderRows (U8 — per-account Codex rows)', () => {+ const codex = (over: Partial<ProviderUsage> = {}): ProviderUsage => ({+ provider: 'codex',+ limits: [limit()],+ account: null,+ updatedAt: 0,+ status: 'ok',+ ...over+ })++ it('keys each Codex account distinctly and the system row as system', () => {+ expect(providerRowKey(codex())).toBe('codex:system')+ expect(providerRowKey(codex({ accountId: 'acc-1' }))).toBe('codex:acc-1')+ expect(providerRowKey(codex({ accountId: 'acc-2' }))).toBe('codex:acc-2')+ })++ it('keeps distinct per-account rows instead of colliding them onto one key', () => {+ const rows = [+ codex({ account: 'sys@x' }),+ codex({ accountId: 'acc-1', account: 'a@x' }),+ codex({ accountId: 'acc-2', account: 'b@x' })+ ]+ const out = dedupeProviderRows(rows)+ expect(out).toHaveLength(3)+ expect(out.map(providerRowKey)).toEqual(['codex:system', 'codex:acc-1', 'codex:acc-2'])+ })++ it('collapses two rows with the same account key, keeping the informative one', () => {+ const empty = codex({ accountId: 'acc-1', limits: [], status: 'fetching' })+ const full = codex({ accountId: 'acc-1', account: 'a@x' })+ const out = dedupeProviderRows([empty, full])+ expect(out).toHaveLength(1)+ expect(out[0].status).toBe('ok')+ expect(out[0].limits).toHaveLength(1)+ })++ it('does not merge across different providers that happen to share a system slot', () => {+ const out = dedupeProviderRows([codex(), { ...codex(), provider: 'gemini' }])+ expect(out.map(providerRowKey)).toEqual(['codex:system', 'gemini:system'])+ })+})diff --git a/src/renderer/lib/usageScope.ts b/src/renderer/lib/usageScope.tsindex 6b8ede3db..3734af3a7 100644--- a/src/renderer/lib/usageScope.ts+++ b/src/renderer/lib/usageScope.ts@@ -140,3 +140,43 @@ export function scopeUsage(input: ScopeInput): ScopedUsage {pillLimits: leading?.usage.limits ?? []}}++/**+ * The React key for a provider usage row. `runProviders` emits ONE row per Codex account (the+ * system fetcher with no `accountId`, plus one per managed account), all carrying+ * `provider: 'codex'` — so keying on `provider` alone collides every Codex account onto one key+ * (U8, owed from PR 7). Keying on `provider` + `accountId` keeps each account's row distinct.+ */+export function providerRowKey(row: Pick<ProviderUsage, 'provider' | 'accountId'>): string {+ return `${row.provider}:${row.accountId ?? 'system'}`+}++/**+ * Collapse provider usage rows that share a `provider`+`accountId` key (U8 keyed reduce). Two+ * settings entries that resolve to the same underlying account would otherwise print twice; a+ * genuine per-account row keeps its own key and survives. Insertion order is preserved, and the+ * MORE INFORMATIVE duplicate wins — a row with limits, or a non-`fetching` status, beats an empty+ * placeholder — so a resolved reading is never dropped in favour of an in-flight one.+ */+export function dedupeProviderRows(rows: readonly ProviderUsage[]): ProviderUsage[] {+ const order: string[] = []+ const byKey = new Map<string, ProviderUsage>()+ for (const row of rows) {+ const key = providerRowKey(row)+ const existing = byKey.get(key)+ if (!existing) {+ order.push(key)+ byKey.set(key, row)+ continue+ }+ if (moreInformative(row, existing)) byKey.set(key, row)+ }+ return order.map((key) => byKey.get(key)!)+}++/** True when `candidate` carries strictly more usable information than `current`. */+function moreInformative(candidate: ProviderUsage, current: ProviderUsage): boolean {+ const rank = (r: ProviderUsage): number =>+ r.limits.length > 0 ? 2 : r.status === 'fetching' ? 0 : 1+ return rank(candidate) > rank(current)+}