feat: surface Copilot usage and quota data across the UI

Add three layers of usage visibility:

- ChatPane footer: premium request count, AIU consumed, and quota
  remaining below the existing context-window bar
- Settings / CopilotStatusCard: on-demand account quota section with
  progress bars, overage indicators, and reset dates fetched via
  the new get-quota sidecar command
- Activity Panel: per-agent token/cost/duration totals on each agent
  row and a Session Usage summary section between agents and timeline

Backend (sidecar):
- New get-quota command using SDK account.getQuota RPC
- New assistant-usage turn-scoped event from SDK assistant.usage
- QuotaSnapshotMapper for both typed and untyped SDK quota payloads
- DTOs: GetQuotaCommandDto, QuotaSnapshotDto, AccountQuotaResultEventDto,
  AssistantUsageEventDto

Frontend:
- Shared types: AssistantUsageEvent, QuotaSnapshot, GetQuotaCommand
- IPC bridge: getQuota channel, assistant-usage event dispatch
- State: SessionRequestUsageMap accumulator with per-agent breakdown
- 8 new tests for accumulator logic and formatting helpers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David KayaandCopilot committed 2026-03-29 00:46:09 +01:00
1 parent 48efbf36f9
commit 92832c6116
26 files changed
+978 -18

No files matched your search

+1
View File
@@ -52,4 +52,5 @@ export const ipcChannels = {
terminalExit: 'terminal:exit',
workspaceUpdated: 'workspace:updated',
sessionEvent: 'sessions:event',
getQuota: 'sidecar:get-quota',
} as const;
+2 -1
View File
@@ -1,5 +1,5 @@
import type { ApprovalDecision } from '@shared/domain/approval';
import type { SidecarCapabilities, InteractionMode, MessageMode } from '@shared/contracts/sidecar';
import type { SidecarCapabilities, InteractionMode, MessageMode, QuotaSnapshot } from '@shared/contracts/sidecar';
import type { PatternDefinition, ReasoningEffort } from '@shared/domain/pattern';
import type { ProjectRecord } from '@shared/domain/project';
import type { QuerySessionsInput, SessionQueryResult } from '@shared/domain/sessionLibrary';
@@ -202,6 +202,7 @@ export interface ElectronApi {
resizeTerminal(input: ResizeTerminalInput): void;
openAppDataFolder(): Promise<void>;
resetLocalWorkspace(): Promise<WorkspaceState>;
getQuota(): Promise<Record<string, QuotaSnapshot>>;
onTerminalData(listener: (data: string) => void): () => void;
onTerminalExit(listener: (info: TerminalExitInfo) => void): () => void;
onWorkspaceUpdated(listener: (workspace: WorkspaceState) => void): () => void;
+41 -1
View File
@@ -144,7 +144,8 @@ export type SidecarCommand =
| ResolveUserInputCommand
| ListSessionsCommand
| DeleteSessionCommand
| DisconnectSessionCommand;
| DisconnectSessionCommand
| GetQuotaCommand;
export interface RunTurnLocalMcpServerConfig {
id: string;
@@ -470,6 +471,43 @@ export interface CommandErrorEvent {
message: string;
}
export interface AssistantUsageEvent {
type: 'assistant-usage';
requestId: string;
sessionId: string;
agentId?: string;
agentName?: string;
model: string;
inputTokens?: number;
outputTokens?: number;
cacheReadTokens?: number;
cacheWriteTokens?: number;
cost?: number;
duration?: number;
totalNanoAiu?: number;
quotaSnapshots?: Record<string, QuotaSnapshot>;
}
export interface QuotaSnapshot {
entitlementRequests: number;
usedRequests: number;
remainingPercentage: number;
overage: number;
overageAllowedWithExhaustedQuota: boolean;
resetDate?: string;
}
export interface GetQuotaCommand {
type: 'get-quota';
requestId: string;
}
export interface QuotaResultEvent {
type: 'quota-result';
requestId: string;
quotaSnapshots: Record<string, QuotaSnapshot>;
}
export interface CommandCompleteEvent {
type: 'command-complete';
requestId: string;
@@ -494,5 +532,7 @@ export type SidecarEvent =
| SessionsListedEvent
| SessionsDeletedEvent
| SessionDisconnectedEvent
| AssistantUsageEvent
| QuotaResultEvent
| CommandErrorEvent
| CommandCompleteEvent;
+15 -1
View File
@@ -1,5 +1,7 @@
import type { SessionRunRecord } from '@shared/domain/runTimeline';
import type { QuotaSnapshot } from '@shared/contracts/sidecar';
export type SessionActivityType = 'thinking' | 'tool-calling' | 'handoff' | 'completed';
export type SessionEventKind =
@@ -14,7 +16,8 @@ export type SessionEventKind =
| 'hook-lifecycle'
| 'session-usage'
| 'session-compaction'
| 'pending-messages-modified';
| 'pending-messages-modified'
| 'assistant-usage';
export type SubagentEventKind = 'started' | 'completed' | 'failed' | 'selected' | 'deselected';
@@ -67,4 +70,15 @@ export interface SessionEventRecord {
preCompactionTokens?: number;
postCompactionTokens?: number;
tokensRemoved?: number;
// Assistant usage fields
usageModel?: string;
usageInputTokens?: number;
usageOutputTokens?: number;
usageCacheReadTokens?: number;
usageCacheWriteTokens?: number;
usageCost?: number;
usageDuration?: number;
usageTotalNanoAiu?: number;
usageQuotaSnapshots?: Record<string, QuotaSnapshot>;
}