Scope the drill-through fetch by the Projects filter and fix dead drill entries

Rebasing onto main put the new getSessionsContributions handler beside the
Projects-pane filter from #1307 without picking it up, so the drill-through
would have listed unfiltered sessions under a filtered headline.

- main.ts: add projectArgs() to the new handler, matching getSessions; the
  existing filter test now asserts the new channel too.
- usage-aggregator/day-aggregator: actually set categories[].rawCategory.
  menubar-json already declared and forwarded it, but no producer wrote it,
  so topActivities[].rawCategory was always undefined and the category
  drill entry was permanently disabled in both aggregation paths.
- Models.tsx: key the model drill off modelDisplayName. Contribution
  segments are keyed by canonical short name ("Fable 5"); the row's raw
  provider ids ("claude-fable-5") matched 0 of 19 segment keys on real data.
This commit is contained in:
torukmakto 2026-09-12 12:39:37 -07:00
parent 756af7fcdf
commit 989d953a78
5 changed files with 12 additions and 7 deletions

View file

@ -827,6 +827,8 @@ describe('project filter', () => {
const handlers = createBridgeHandlers(deps({ spawnCli, spawnCliAction, resolveCodeburnPath: () => '/bin/codeburn' }))
await handlers['codeburn:getSessions']!('week', 'all')
expect(calls[0]).toEqual(['sessions', '--format', 'json', '--period', 'week', '--project=my-company', '--exclude=scratch'])
await handlers['codeburn:getSessionsContributions']!('week', 'all')
expect(calls[1]).toEqual(['sessions', '--format', 'json', '--contributions', '--period', 'week', '--project=my-company', '--exclude=scratch'])
})
})

View file

@ -545,7 +545,10 @@ export function createBridgeHandlers(deps: Deps = { spawnCli, spawnCliAction, re
// segments (day/category/branch/model/PR). Same filtering semantics as
// getSessions — one filtering mechanism, additive payload fields only.
'codeburn:getSessionsContributions': run((period: string, provider: string, range?: DateRange) => [
'sessions', '--format', 'json', '--contributions', '--period', vPeriod(period), ...providerArgs(vProvider(provider)), ...rangeArgs(vRange(range)),
'sessions', '--format', 'json', '--contributions', '--period', vPeriod(period),
...providerArgs(vProvider(provider)),
...projectArgs(),
...rangeArgs(vRange(range)),
], 3),
'codeburn:getCompareModels': run((period: string, provider: string) => [
'compare', '--format', 'json', '--period', vPeriod(period),

View file

@ -293,9 +293,9 @@ function ModelTableRow({ row, onAddAlias, onInvestigate }: { row: ModelReportRow
background: seriesColorForModel(row.modelDisplayName || row.model),
marginRight: 8,
}
// The fold group's canonical short names: the row's own key plus every raw
// id folded into it, so the chip matches every session under this row.
const drillModelKeys = [row.model, ...row.rawModels].filter(Boolean)
// Contribution segments are keyed by the canonical short name, which is what
// modelDisplayName carries; the raw provider ids never match a segment.
const drillModelKeys = [row.modelDisplayName].filter(Boolean)
return (
<tr>
@ -328,7 +328,7 @@ function ModelGroupRow({ rows, onAddAlias, onInvestigate }: { rows: ModelReportR
const costUSD = rows.reduce((sum, row) => sum + row.costUSD, 0)
const savingsUSD = rows.reduce((sum, row) => sum + row.savingsUSD, 0)
const unpriced = costUSD === 0 && savingsUSD === 0
const drillModelKeys = [...new Set(rows.flatMap(row => [row.model, ...row.rawModels]))].filter(Boolean)
const drillModelKeys = [...new Set(rows.map(row => row.modelDisplayName))].filter(Boolean)
return (
<tr className="model-group-row">

View file

@ -300,7 +300,7 @@ export function buildPeriodDataFromDays(days: DailyEntry[], label: string): Peri
cacheWriteTokens,
categories: Object.entries(catTotals)
.sort(([, a], [, b]) => b.cost - a.cost)
.map(([cat, d]) => ({ name: CATEGORY_LABELS[cat as TaskCategory] ?? cat, ...d })),
.map(([cat, d]) => ({ name: CATEGORY_LABELS[cat as TaskCategory] ?? cat, rawCategory: cat, ...d })),
models: Object.entries(modelTotals)
.sort(([, a], [, b]) => b.cost - a.cost)
.map(([name, d]) => ({ name, ...d })),

View file

@ -114,7 +114,7 @@ export function buildPeriodData(label: string, projects: ProjectSummary[]): Peri
inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens,
categories: Object.entries(catTotals)
.sort(([, a], [, b]) => b.cost - a.cost)
.map(([cat, d]) => ({ name: CATEGORY_LABELS[cat as TaskCategory] ?? cat, ...d })),
.map(([cat, d]) => ({ name: CATEGORY_LABELS[cat as TaskCategory] ?? cat, rawCategory: cat, ...d })),
models: Object.entries(modelTotals)
.sort(([, a], [, b]) => b.cost - a.cost)
.map(([name, d]) => ({ name, calls: d.calls, cost: d.cost, savingsUSD: d.savingsUSD, estimatedCostUSD: d.estimatedCostUSD })),