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
feat(usage): collapsed pill shows the project's "Use for new sessions" account
reviewdbec6699a907
diff --git a/src/renderer/components/UsageIndicator.tsx b/src/renderer/components/UsageIndicator.tsxindex b2df2671e..fc50d62c4 100644--- a/src/renderer/components/UsageIndicator.tsx+++ b/src/renderer/components/UsageIndicator.tsx@@ -40,6 +40,11 @@ import { systemAccountDisplay } from '../state/workspace'* gap (or clip a corner en route elsewhere) without the panel flickering shut. */const USAGE_HOVER_CLOSE_MS = 220+/** How often the collapsed pill re-asks for a MANAGED default account's snapshot. Only the system+ * account is polled + pushed by the service; the service caches managed reads for its own+ * debounce, so a re-ask inside that window is free. */+const DEFAULT_ACCOUNT_POLL_MS = 5 * 60 * 1000+/*** A single limit row in the popover: bar, "% left"/"% used", reset countdown. The bar's fill* honours the display mode (`barFillPercent`) so it tracks the same quantity as the number@@ -399,6 +404,14 @@ export function UsageIndicator({),[claudeAccounts, scopeHostKey])+ // The validated "Use for new sessions" account (undefined = system) — the identity the collapsed+ // pill describes. Same validation as the rows' ✓: a stale id falls back to the system account.+ const defaultAccountId =+ projectDefaultId && eligibleAccounts.some((a) => a.id === projectDefaultId)+ ? projectDefaultId+ : undefined+ const defaultAccountLabel = eligibleAccounts.find((a) => a.id === defaultAccountId)?.label+// One rule for every row, local and remote alike — `accountRowAction` (pure, tested) decides// default/offer/none; this pair just turns its answer into props. Absent handler / no project =// pure readout, exactly as before. null = the System row (clears the override).@@ -516,6 +529,25 @@ export function UsageIndicator({}}, [open, accounts, scope.kind])+ // The LOCAL managed default's snapshot, kept fresh while the popover is CLOSED too — the pill+ // spells it out. (The popover's per-account fetch above only runs while open.)+ const localDefaultId = scope.kind === 'local' ? defaultAccountId : undefined+ useEffect(() => {+ if (!localDefaultId) return+ let cancelled = false+ const load = (): void => {+ void window.nodeTerminal.usage.fetch(localDefaultId).then((u) => {+ if (!cancelled) setAcctUsage((m) => ({ ...m, [localDefaultId]: u }))+ })+ }+ load()+ const timer = window.setInterval(load, DEFAULT_ACCOUNT_POLL_MS)+ return () => {+ cancelled = true+ window.clearInterval(timer)+ }+ }, [localDefaultId])+// Close the popover on an outside click.useEffect(() => {if (!open) return@@ -553,7 +585,9 @@ export function UsageIndicator({providers: providers.filter((p) => !hidden.has(p.provider)),// Its own switch, not Claude's: hiding the local rows must not silently take the SSH hosts// down with them, and vice versa.- remote: remote.filter(r => !hidden.has(r.provider === 'codex' ? 'codex' : 'claude-remote'))+ remote: remote.filter(r => !hidden.has(r.provider === 'codex' ? 'codex' : 'claude-remote')),+ defaultAccountId,+ defaultUsage: localDefaultId && !hidden.has('claude') ? (acctUsage[localDefaultId] ?? null) : null})const claudeUsage = scoped.claudeconst visibleProviders = scoped.providers@@ -564,7 +598,17 @@ export function UsageIndicator({// Claude alone, which is what this did, left a Codex-only user with no pill at all.const enabled = enabledProviders([...visibleProviders,...visibleRemote.flatMap(r => r.provider === 'codex' ? [r.usage] : [])])- if (!hasAnyUsage(claudeUsage, visibleProviders, visibleRemote)) return null+ if (!hasAnyUsage(claudeUsage, visibleProviders, visibleRemote) && scoped.pillLimits.length === 0)+ return null+ // Name the identity when the pill shows a managed account, so its numbers are never read as the+ // system account's. The system identity stays unlabelled — exactly the pill as it always was.+ const pillAccountLabel =+ scoped.pillAccountId === null+ ? null+ : scope.kind === 'local'+ ? defaultAccountLabel+ : visibleRemote.find((r) => r.provider !== 'codex' && r.accountId === scoped.pillAccountId)+ ?.label// On an SSH project these are the HOST's limits — same shape, same labels, read somewhere else.const limits = scoped.pillLimits@@ -597,7 +641,12 @@ export function UsageIndicator({.catch((): RemoteAccountUsage[] => [])if (remoteScope.current === requestedScope) setRemote(rows)} else {- setUsage(await window.nodeTerminal.usage.refresh())+ const [sys, def] = await Promise.all([+ window.nodeTerminal.usage.refresh(),+ localDefaultId ? window.nodeTerminal.usage.refresh(localDefaultId) : Promise.resolve(null)+ ])+ setUsage(sys)+ if (localDefaultId && def) setAcctUsage((m) => ({ ...m, [localDefaultId]: def }))}} finally {setRefreshing(false)@@ -612,6 +661,18 @@ export function UsageIndicator({} else {pillBody = (<>+ {pillAccountLabel && (+ <span+ className="usage-pill__account"+ title={+ scoped.pillAccountId === defaultAccountId+ ? 'Account used for new sessions in this project'+ : 'Account these limits belong to'+ }+ >+ {pillAccountLabel}+ </span>+ )}{primary && (<span className="usage-pill__minibar" aria-hidden><spandiff --git a/src/renderer/lib/usageScope.test.ts b/src/renderer/lib/usageScope.test.tsindex 430cf579f..62c6c64af 100644--- a/src/renderer/lib/usageScope.test.ts+++ b/src/renderer/lib/usageScope.test.ts@@ -248,3 +248,44 @@ describe('providerRowKey / dedupeProviderRows (U8 — per-account Codex rows)',expect(out.map(providerRowKey)).toEqual(['codex:system', 'gemini:system'])})})++describe('scopeUsage — the pill follows the "Use for new sessions" default', () => {+ const sys = usage([limit({ usedPercent: 10 })])+ const work = usage([limit({ usedPercent: 80 })])++ it('local: spells out the managed default once it has data', () => {+ const out = scopeUsage({+ scope: LOCAL, claude: sys, accounts: ACCOUNTS, providers: [], remote: [],+ defaultAccountId: 'a1', defaultUsage: work+ })+ expect(out.pillLimits).toBe(work.limits)+ expect(out.pillAccountId).toBe('a1')+ })++ it('local: falls back to the system account while the default has not answered', () => {+ for (const defaultUsage of [null, usage([])]) {+ const out = scopeUsage({+ scope: LOCAL, claude: sys, accounts: ACCOUNTS, providers: [], remote: [],+ defaultAccountId: 'a1', defaultUsage+ })+ expect(out.pillLimits).toBe(sys.limits)+ expect(out.pillAccountId).toBeNull()+ }+ })++ it('local: no default = the system account, as before', () => {+ const out = scopeUsage({ scope: LOCAL, claude: sys, accounts: ACCOUNTS, providers: [], remote: [] })+ expect(out.pillLimits).toBe(sys.limits)+ expect(out.pillAccountId).toBeNull()+ })++ it('ssh: prefers the host row of the default account over the system row', () => {+ const scope: UsageScope = { kind: 'ssh', hostKey: 'root@h' }+ const rows = [remoteRow('root@h', null, [limit()]), remoteRow('root@h', 'r1', [limit({ usedPercent: 70 })])]+ const out = scopeUsage({ scope, claude: null, accounts: [], providers: [], remote: rows, defaultAccountId: 'r1' })+ expect(out.pillLimits).toBe(rows[1].usage.limits)+ expect(out.pillAccountId).toBe('r1')+ const plain = scopeUsage({ scope, claude: null, accounts: [], providers: [], remote: rows })+ expect(plain.pillAccountId).toBeNull()+ })+})diff --git a/src/renderer/lib/usageScope.ts b/src/renderer/lib/usageScope.tsindex b8d54696e..3f6ac238e 100644--- a/src/renderer/lib/usageScope.ts+++ b/src/renderer/lib/usageScope.ts@@ -64,6 +64,14 @@ export interface ScopeInput {providers: readonly ProviderUsage[]/** Every remote row the service answered with. */remote: readonly RemoteAccountUsage[]+ /**+ * The project's "Use for new sessions" account, ALREADY validated against the accounts this+ * project can launch (undefined = the system identity). The collapsed pill describes this+ * identity: it is the one the next session will spend.+ */+ defaultAccountId?: string+ /** LOCAL scope only: the snapshot of `defaultAccountId` (null while its fetch is in flight). */+ defaultUsage?: ClaudeUsage | null}export interface ScopedUsage {@@ -79,10 +87,16 @@ export interface ScopedUsage {* pill while its popover was full.** Managed accounts (local OR remote) never get their own pill segment: the pill has one line- * beside the canvas, and the popover is where per-account detail belongs. This is the rule the- * local side has always followed; the SSH side now matches it.+ * beside the canvas, and the popover is where per-account detail belongs. The ONE account the+ * pill spells out is the project's "Use for new sessions" default when it has data — that is the+ * identity new work is spent on, so it is the number worth watching while the popover is closed.+ * Until the default answers (or when it has nothing to say) the pill falls back to the rule+ * above, and `pillAccountId` says which one it is showing.*/pillLimits: ClaudeUsage['limits']+ /** Whose limits `pillLimits` are: a managed account id, or null for the machine's system+ * identity. The pill names a managed account so its numbers are never read as the system's. */+ pillAccountId: string | null}/**@@ -113,24 +127,30 @@ export function accountRowAction(}export function scopeUsage(input: ScopeInput): ScopedUsage {- const { scope, claude, accounts, providers, remote } = input+ const { scope, claude, accounts, providers, remote, defaultAccountId, defaultUsage } = inputif (scope.kind === 'local') {+ const useDefault = !!defaultAccountId && (defaultUsage?.limits.length ?? 0) > 0return {claude,accounts: [...accounts],providers: [...providers],// Remote hosts are another machine's story — not this project's.remote: [],- pillLimits: claude?.limits ?? []+ pillLimits: useDefault ? defaultUsage!.limits : (claude?.limits ?? []),+ pillAccountId: useDefault ? defaultAccountId! : null}}const rows = remote.filter((r) => r.hostKey === scope.hostKey)const claudeRows = rows.filter(r => r.provider !== 'codex')const system = claudeRows.find((r) => r.accountId === null)+ const preferred = defaultAccountId+ ? claudeRows.find((r) => r.accountId === defaultAccountId && r.usage.limits.length > 0)+ : undefinedconst leading =- system && system.usage.limits.length > 0+ preferred ??+ (system && system.usage.limits.length > 0? system- : (claudeRows.find((r) => r.usage.limits.length > 0) ?? system)+ : (claudeRows.find((r) => r.usage.limits.length > 0) ?? system))return {// The local machine's Claude, its managed accounts and the local billing providers are all// credentials you are NOT spending while you work on the host.@@ -138,7 +158,8 @@ export function scopeUsage(input: ScopeInput): ScopedUsage {accounts: [],providers: [],remote: rows,- pillLimits: leading?.usage.limits ?? []+ pillLimits: leading?.usage.limits ?? [],+ pillAccountId: leading?.accountId ?? null}}diff --git a/src/renderer/styles.css b/src/renderer/styles.cssindex d88c04259..e997a2e4d 100644--- a/src/renderer/styles.css+++ b/src/renderer/styles.css@@ -8086,6 +8086,15 @@ button.group-node__setup:disabled {/* Non-Claude provider segments read one step quieter than the Claude numbers, so a long pillstill scans as "Claude first, others after" without needing separate icons per provider. */.usage-pill__provider .usage-pill__num { color: rgba(var(--tint-rgb), 0.75); font-size: 11px; }+/* The managed account the pill describes (the project's "Use for new sessions" default). */+.usage-pill__account {+ max-width: 120px;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ font-size: 11px;+ color: rgba(var(--tint-rgb), 0.6);+}.usage-pill__dim,.sysres-pill__dim { color: rgba(var(--tint-rgb), 0.5); }.usage-pill__pulse,