Merge pull request #2260 from insodimension/fix/usage-active-oauth-account-upstream

Show active OAuth account in usage
This commit is contained in:
Can Bölük
2026-06-12 04:24:51 +02:00
committed by GitHub
9 changed files with 363 additions and 10 deletions
@@ -36,9 +36,10 @@ import { computeContextBreakdown, renderContextUsage } from "../../modes/utils/c
import { buildHotkeysMarkdown } from "../../modes/utils/hotkeys-markdown";
import { buildToolsMarkdown } from "../../modes/utils/tools-markdown";
import type { AsyncJobSnapshotItem } from "../../session/agent-session";
import type { AuthStorage } from "../../session/auth-storage";
import type { AuthStorage, OAuthAccountIdentity } from "../../session/auth-storage";
import type { NewSessionOptions } from "../../session/session-manager";
import { formatShakeSummary, type ShakeMode, type ShakeResult } from "../../session/shake-types";
import { limitMatchesActiveAccount } from "../../slash-commands/helpers/active-oauth-account";
import { outputMeta } from "../../tools/output-meta";
import { resolveToCwd, stripOuterDoubleQuotes } from "../../tools/path-utils";
import { replaceTabs } from "../../tools/render-utils";
@@ -404,7 +405,16 @@ export class CommandController {
}
const availableWidth = Math.max(40, (this.ctx.ui.terminal.columns ?? 100) - 2);
const output = renderUsageReports(usageReports, theme, Date.now(), availableWidth);
const currentProvider = this.ctx.session.model?.provider;
const activeAccount = currentProvider
? this.ctx.session.modelRegistry.authStorage.getOAuthAccountIdentity(
currentProvider,
this.ctx.session.sessionId,
)
: undefined;
const output = renderUsageReports(usageReports, theme, Date.now(), availableWidth, provider =>
provider === currentProvider ? activeAccount : undefined,
);
this.ctx.present([new Spacer(1), new Text(output, 1, 0)]);
}
@@ -1311,12 +1321,17 @@ function formatAccountHeaderRow(
nowMs: number,
columnWidth: number,
uiTheme: typeof theme,
activeAccount?: OAuthAccountIdentity,
): string[] {
const parts = limits.map((limit, index) => {
const reset = formatResetShort(limit, nowMs);
const report = reports[index];
const active = report !== undefined && limitMatchesActiveAccount(report, limit, activeAccount);
const label = formatAccountLabel(limit, report, index);
return {
label: formatAccountLabel(limit, reports[index], index),
label: active ? `● ${label}` : label,
suffix: reset ? `(${reset})` : "",
active,
};
});
const maxSuffixWidth = parts.reduce((max, p) => Math.max(max, visibleWidth(p.suffix)), 0);
@@ -1327,16 +1342,18 @@ function formatAccountHeaderRow(
if (prefixBudget < 2) {
return parts.map(p => {
const full = p.suffix ? `${p.label} ${p.suffix}` : p.label;
return padColumn(truncateJobLabel(full, columnWidth), columnWidth);
const cell = padColumn(truncateJobLabel(full, columnWidth), columnWidth);
return p.active ? uiTheme.fg("accent", cell) : cell;
});
}
return parts.map(p => {
const prefix = truncateJobLabel(p.label, prefixBudget);
const prefixCell = prefix + " ".repeat(prefixBudget - visibleWidth(prefix));
if (!p.suffix) return prefixCell + " ".repeat(maxSuffixWidth + gap);
const styledPrefix = p.active ? uiTheme.fg("accent", prefixCell) : prefixCell;
if (!p.suffix) return styledPrefix + " ".repeat(maxSuffixWidth + gap);
const suffixPad = " ".repeat(maxSuffixWidth - visibleWidth(p.suffix));
return `${prefixCell} ${suffixPad}${uiTheme.fg("dim", p.suffix)}`;
return `${styledPrefix} ${suffixPad}${uiTheme.fg("dim", p.suffix)}`;
});
}
@@ -1456,6 +1473,7 @@ function renderUsageReports(
uiTheme: typeof theme,
nowMs: number,
availableWidth: number,
resolveActiveAccount?: (provider: string) => OAuthAccountIdentity | undefined,
): string {
const lines: string[] = [];
const latestFetchedAt = Math.max(...reports.map(report => report.fetchedAt ?? 0));
@@ -1481,6 +1499,7 @@ function renderUsageReports(
for (const { provider, providerReports } of providerEntries) {
lines.push("");
const providerName = formatProviderName(provider);
const activeAccount = resolveActiveAccount?.(provider);
const limitGroups = new Map<
string,
@@ -1504,6 +1523,10 @@ function renderUsageReports(
}
lines.push(uiTheme.bold(uiTheme.fg("accent", providerName)));
const activeAccountLabel = activeAccount?.email ?? activeAccount?.accountId ?? activeAccount?.projectId;
if (activeAccountLabel) {
lines.push(` ${uiTheme.fg("accent", "in use by this session:")} ${activeAccountLabel}`);
}
const renderableGroups = Array.from(limitGroups.values()).map(group => {
const entries = group.limits.map((limit, index) => ({
@@ -1533,7 +1556,14 @@ function renderUsageReports(
const windowSuffix = formatWindowSuffix(group.label, group.windowLabel, uiTheme);
lines.push(`${statusIcon} ${uiTheme.bold(group.label)} ${windowSuffix}`.trim());
const accountLabels = formatAccountHeaderRow(sortedLimits, sortedReports, nowMs, sectionColumnWidth, uiTheme);
const accountLabels = formatAccountHeaderRow(
sortedLimits,
sortedReports,
nowMs,
sectionColumnWidth,
uiTheme,
activeAccount,
);
lines.push(` ${accountLabels.join(" ")}`.trimEnd());
const bars = sortedLimits.map(limit =>
padColumn(renderUsageBar(limit, uiTheme, sectionColumnWidth), sectionColumnWidth),