diff --git a/app/renderer/App.tsx b/app/renderer/App.tsx index 7e3fbb0c..6924974e 100644 --- a/app/renderer/App.tsx +++ b/app/renderer/App.tsx @@ -196,7 +196,7 @@ export function App() { {section === 'overview' ? ( ) : section === 'sessions' ? ( - + ) : section === 'spend' ? ( ) : section === 'optimize' ? ( diff --git a/app/renderer/components/ListRow.tsx b/app/renderer/components/ListRow.tsx index 179e447f..43fed629 100644 --- a/app/renderer/components/ListRow.tsx +++ b/app/renderer/components/ListRow.tsx @@ -7,6 +7,8 @@ export { seriesColorForModel } from '../lib/modelSeries' * title + sub line `.lx`, an optional right-aligned `.val`. When `onClick` is * provided the row becomes a keyboard-operable button and shows the trailing * chevron; without it the row is inert and the chevron is omitted (honest). + * Pass `expanded` on an interactive row to reflect its open/closed state + * (`aria-expanded`, which also rotates the chevron). */ export function ListRow({ no, @@ -16,6 +18,7 @@ export function ListRow({ value, valueClass, onClick, + expanded, }: { no?: ReactNode dotColor?: string @@ -24,6 +27,7 @@ export function ListRow({ value?: ReactNode valueClass?: string onClick?: () => void + expanded?: boolean }) { const dot: CSSProperties | undefined = dotColor ? { background: dotColor } : undefined const interactive = onClick !== undefined @@ -39,6 +43,7 @@ export function ListRow({
{no !== undefined && {no}} {dotColor !== undefined && } diff --git a/app/renderer/sections/Sessions.test.tsx b/app/renderer/sections/Sessions.test.tsx index 46213012..2409e292 100644 --- a/app/renderer/sections/Sessions.test.tsx +++ b/app/renderer/sections/Sessions.test.tsx @@ -229,4 +229,45 @@ describe('Sessions', () => { render() expect(await screen.findByText('No sessions in this range yet.')).toBeInTheDocument() }) + + it('lifts provider quick-filter clicks to the app callback with the internal id', async () => { + const user = userEvent.setup() + getSessions.mockResolvedValue(rows) + const onProviderChange = vi.fn() + const detected = [ + { id: 'claude', label: 'Claude' }, + { id: 'codex', label: 'Codex' }, + ] + render() + await screen.findByText('6 sessions · $21.93 · 4.2M tokens') + + const filter = screen.getByRole('group', { name: /provider/i }) + expect(within(filter).getAllByRole('button')).toHaveLength(3) + + await user.click(within(filter).getByRole('button', { name: 'Codex' })) + expect(onProviderChange).toHaveBeenCalledWith('codex') + + await user.click(within(filter).getByRole('button', { name: 'All' })) + expect(onProviderChange).toHaveBeenLastCalledWith('all') + }) + + it('renders quick-filter buttons only for cost>0 providers and presses the active one', async () => { + getSessions.mockResolvedValue(rows) + // Mirror App.tsx: detectedProviders are built by dropping cost=0 entries. + const providerDetails = [ + { id: 'claude', label: 'Claude', cost: 12 }, + { id: 'codex', label: 'Codex', cost: 4 }, + { id: 'gemini', label: 'Gemini', cost: 0 }, + ] + const detected = providerDetails.filter(p => p.cost > 0).map(({ id, label }) => ({ id, label })) + render( {}} />) + await screen.findByText('6 sessions · $21.93 · 4.2M tokens') + + const filter = screen.getByRole('group', { name: /provider/i }) + expect(within(filter).getByRole('button', { name: 'Claude' })).toBeInTheDocument() + expect(within(filter).getByRole('button', { name: 'Codex' })).toBeInTheDocument() + expect(within(filter).queryByRole('button', { name: 'Gemini' })).not.toBeInTheDocument() + expect(within(filter).getByRole('button', { name: 'Codex' })).toHaveAttribute('aria-pressed', 'true') + expect(within(filter).getByRole('button', { name: 'All' })).toHaveAttribute('aria-pressed', 'false') + }) }) diff --git a/app/renderer/sections/Sessions.tsx b/app/renderer/sections/Sessions.tsx index ed04c0c9..a4a4880a 100644 --- a/app/renderer/sections/Sessions.tsx +++ b/app/renderer/sections/Sessions.tsx @@ -3,6 +3,7 @@ import { Fragment, useEffect, useMemo, useState } from 'react' import { CliErrorPanel } from '../components/CliErrorPanel' import { EmptyNote } from '../components/EmptyState' import { Panel } from '../components/Panel' +import { ProviderLogo } from '../components/ProviderLogo' import { SegTabs } from '../components/SegTabs' import { StaleBanner } from '../components/StaleBanner' import { Stat } from '../components/Stat' @@ -62,11 +63,15 @@ export function Sessions({ provider, range = null, refreshToken = 0, + detectedProviders = [], + onProviderChange = () => {}, }: { period: Period provider: string range?: DateRange | null refreshToken?: number + detectedProviders?: Array<{ id: string; label: string }> + onProviderChange?: (value: string) => void }) { const [selectedId, setSelectedId] = useState(null) const [query, setQuery] = useState('') @@ -158,6 +163,30 @@ export function Sessions({ return (
{report.error && } + {detectedProviders.length > 0 && ( +
+ + {detectedProviders.map(entry => ( + + ))} +
+ )}
{ const otherNode = container.querySelector('[data-testid="sankey-node"][data-node-id="__other__"]') expect(otherNode?.getAttribute('fill')).toBe('var(--s-other)') }) + + it('expands a project row inline to reveal its sessions, one open row at a time', async () => { + const user = userEvent.setup() + const payload = makePayload(new Date()) + payload.current.topProjects[0].sessionDetails = [ + { + cost: 120.5, savingsUSD: 0, calls: 40, inputTokens: 0, outputTokens: 0, date: '2026-07-09', + models: [ + { name: 'claude-opus-4', cost: 100, savingsUSD: 0 }, + { name: 'claude-haiku-4', cost: 20.5, savingsUSD: 0 }, + ], + }, + { + cost: 44.25, savingsUSD: 0, calls: 12, inputTokens: 0, outputTokens: 0, date: '2026-07-05', + models: [{ name: 'gpt-5.5-codex', cost: 44.25, savingsUSD: 0 }], + }, + ] + payload.current.topProjects[1].sessionDetails = [ + { + cost: 9.9, savingsUSD: 0, calls: 3, inputTokens: 0, outputTokens: 0, date: '2026-07-02', + models: [{ name: 'claude-sonnet-5', cost: 9.9, savingsUSD: 0 }], + }, + ] + getOverview.mockResolvedValue(payload) + getSpendFlow.mockResolvedValue(makeFlow()) + + render() + + const first = await screen.findByRole('button', { name: /codeburn/ }) + const second = screen.getByRole('button', { name: /agentseal-dash/ }) + expect(first).toHaveAttribute('aria-expanded', 'false') + expect(screen.queryByRole('region', { name: 'codeburn sessions' })).not.toBeInTheDocument() + + await user.click(first) + expect(first).toHaveAttribute('aria-expanded', 'true') + const detail = screen.getByRole('region', { name: 'codeburn sessions' }) + expect(within(detail).getByText('Jul 9')).toBeInTheDocument() + expect(within(detail).getByText('$120.50')).toBeInTheDocument() + expect(within(detail).getByText('claude-opus-4')).toBeInTheDocument() + expect(within(detail).getByText('Jul 5')).toBeInTheDocument() + expect(within(detail).getByText('$44.25')).toBeInTheDocument() + + // Expanding another project collapses the first (single open row). + await user.click(second) + expect(second).toHaveAttribute('aria-expanded', 'true') + expect(first).toHaveAttribute('aria-expanded', 'false') + expect(screen.queryByRole('region', { name: 'codeburn sessions' })).not.toBeInTheDocument() + expect(within(screen.getByRole('region', { name: 'agentseal-dash sessions' })).getByText('$9.90')).toBeInTheDocument() + + // Clicking the open row collapses it in place. + await user.click(second) + expect(second).toHaveAttribute('aria-expanded', 'false') + expect(screen.queryByRole('region', { name: 'agentseal-dash sessions' })).not.toBeInTheDocument() + }) }) diff --git a/app/renderer/sections/Spend.tsx b/app/renderer/sections/Spend.tsx index b8008f75..c61898eb 100644 --- a/app/renderer/sections/Spend.tsx +++ b/app/renderer/sections/Spend.tsx @@ -1,3 +1,5 @@ +import { Fragment, useState } from 'react' + import { CliErrorPanel, CliErrorText } from '../components/CliErrorPanel' import { EmptyNote } from '../components/EmptyState' import { ListRow } from '../components/ListRow' @@ -11,6 +13,14 @@ import { codeburn } from '../lib/ipc' import { contiguousDailyWindow, localDateKey } from '../lib/period' import type { CliError, DateRange, MenubarPayload, Period, SpendFlow } from '../lib/types' +type Project = MenubarPayload['current']['topProjects'][number] + +/** Date-only CLI strings ("2026-07-11") formatted at local noon so the calendar day never rolls across time zones. */ +function formatProjectDay(date: string): string { + const d = new Date(`${date}T12:00:00`) + return Number.isNaN(d.getTime()) ? '—' : d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }) +} + const SPEND_CHART_DAYS = 15 function providerLabel(provider: string): string { @@ -140,21 +150,7 @@ function SpendPage({ {chartHasSpend ? : No model spend in this range yet.} - - {projects.length ? ( - projects.map((project, i) => ( - - )) - ) : ( - No project spend in this range yet. - )} - +
@@ -178,6 +174,50 @@ function SpendPage({ ) } +function ProjectBreakdown({ projects }: { projects: Project[] }) { + const [expanded, setExpanded] = useState(null) + + return ( + + {projects.length ? ( + projects.map((project, i) => { + const open = expanded === project.name + return ( + + setExpanded(current => current === project.name ? null : project.name)} + /> + {open && ( +
+ {project.sessionDetails.length ? ( + project.sessionDetails.map((session, j) => ( +
+ {formatProjectDay(session.date)} + {session.models[0]?.name ?? '—'} + {session.calls.toLocaleString('en-US')} calls + {formatUsd(session.cost)} +
+ )) + ) : ( +
No session detail for this project.
+ )} +
+ )} +
+ ) + }) + ) : ( + No project spend in this range yet. + )} +
+ ) +} + function RowsPanel({ title, rows, diff --git a/app/renderer/styles/plain.css b/app/renderer/styles/plain.css index 80a2cce1..d2f3bd5f 100644 --- a/app/renderer/styles/plain.css +++ b/app/renderer/styles/plain.css @@ -402,6 +402,16 @@ td:first-child { font-size: var(--fs-body); font-weight: var(--fw-body); } .li-clickable { cursor: pointer; border-radius: 7px; } .li-clickable:hover, .li-clickable:focus-visible { background: var(--hover); outline: none; } .li-clickable:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); } +.li .chev { transition: transform 140ms ease; } +.li-clickable[aria-expanded="true"] .chev { transform: rotate(90deg); } + +/* Spend: a project row's inline session sub-list (indented, TUI-style). */ +.spend-proj-detail { display: flex; flex-direction: column; padding: 2px 0 8px 27px; } +.spend-proj-session { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto auto; align-items: baseline; column-gap: 10px; padding: 4px 0; font-size: 11px; color: var(--mut); font-variant-numeric: tabular-nums; } +.spend-proj-session + .spend-proj-session { border-top: 1px solid var(--line2); } +.spend-proj-session .sps-model { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); } +.spend-proj-session .sps-cost { color: var(--ink); font-family: var(--mono); } +.spend-proj-empty { padding: 4px 0 8px 27px; font-size: 11px; color: var(--mut2); } /* Models: grouped task lens. */ .models-by-task { min-width: 660px; } @@ -661,6 +671,11 @@ td:first-child { font-size: var(--fs-body); font-weight: var(--fw-body); } /* Sessions */ .sessions-list-view { display: flex; width: 100%; flex-direction: column; gap: 10px; } .sessions-toolbar { display: flex; align-items: center; align-self: flex-start; flex-wrap: wrap; gap: 8px; } +.session-provider-filter { align-self: flex-start; flex-wrap: wrap; } +.session-provider-filter button { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 5px; background: transparent; padding: 4px 9px; font: inherit; font-size: 11.5px; color: var(--mut); white-space: nowrap; cursor: pointer; } +.session-provider-filter button:hover { color: var(--ink); } +.session-provider-filter button.on { color: var(--ink); font-weight: 560; } +.session-provider-filter button:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; } .sessions-search { min-width: 240px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--ink); font: inherit; font-size: 12px; } .sessions-search::placeholder { color: var(--mut2); } .sessions-search:focus-visible { border-color: var(--accent); outline: 1px solid var(--accent); outline-offset: 1px; }