@@ -18,8 +18,10 @@ import {
1818 describeRange ,
1919 formatCoverageDate ,
2020 formatEstimatedCostUsd ,
21+ formatModelCacheBreakdown ,
2122 formatTokenCountCompact ,
2223 formatTokenCountExact ,
24+ hasKnownCacheData ,
2325 isPartialField ,
2426 isUnknownField ,
2527 parseTokenCount ,
@@ -218,6 +220,8 @@ function AgentUsageFocusedTotals({
218220
219221 // Display total for the Total tokens stat.
220222 const displayTotal = deriveDisplayTotal ( agent . usage ) ;
223+ const { cacheReadTokens, cacheWriteTokens, freshInputTokens } = agent . usage ;
224+ const showCacheBreakdown = hasKnownCacheData ( agent . usage ) ;
221225
222226 return (
223227 < Card className = "space-y-4 p-6" data-testid = "agent-usage-focused-totals" >
@@ -236,6 +240,34 @@ function AgentUsageFocusedTotals({
236240 />
237241 </ div >
238242
243+ { showCacheBreakdown ? (
244+ < div
245+ className = "space-y-2 border-t border-border pt-4"
246+ data-testid = "agent-usage-focused-cache"
247+ >
248+ < h3 className = "text-sm font-medium text-foreground" >
249+ Input breakdown
250+ </ h3 >
251+ < div className = "grid grid-cols-2 gap-4 sm:grid-cols-3" >
252+ < TokenStat
253+ field = { cacheReadTokens }
254+ label = "Cache read"
255+ testId = "agent-usage-focused-cache-read-value"
256+ />
257+ < TokenStat
258+ field = { cacheWriteTokens }
259+ label = "Cache write"
260+ testId = "agent-usage-focused-cache-write-value"
261+ />
262+ < TokenStat
263+ field = { freshInputTokens }
264+ label = "Fresh input"
265+ testId = "agent-usage-focused-fresh-input-value"
266+ />
267+ </ div >
268+ </ div >
269+ ) : null }
270+
239271 { agent . buckets . length > 0 ? (
240272 < div
241273 className = "space-y-2 border-t border-border pt-4"
@@ -253,35 +285,10 @@ function AgentUsageFocusedTotals({
253285 >
254286 < h3 className = "text-sm font-medium text-foreground" > By model</ h3 >
255287 { models . map ( ( model ) => (
256- < div
257- className = "flex items-center justify-between gap-3 text-sm"
288+ < FocusedModelRow
258289 key = { `${ model . harness ?? "" } :${ model . model ?? "unknown" } ` }
259- >
260- < span className = "min-w-0 truncate text-muted-foreground" >
261- { model . model ?? "Unknown model" }
262- { model . harness !== null ? (
263- < span
264- className = "ml-1.5 text-xs text-muted-foreground/70"
265- data-testid = "agent-usage-model-harness-label"
266- >
267- { model . harness }
268- </ span >
269- ) : null }
270- </ span >
271- < span className = "shrink-0 font-medium text-foreground" >
272- { isUnknownField ( model . usage . totalTokens )
273- ? formatModelIndependentFields ( model )
274- : formatTokenCountExact (
275- parseTokenCount ( model . usage . totalTokens . value ) ?? 0n ,
276- ) }
277- { isPartialField ( model . usage . totalTokens ) ||
278- isModelIoPartial ( model ) ? (
279- < Badge className = "ml-2" variant = "outline" >
280- Partial
281- </ Badge >
282- ) : null }
283- </ span >
284- </ div >
290+ model = { model }
291+ />
285292 ) ) }
286293 </ div >
287294 ) : null }
@@ -318,16 +325,19 @@ function AgentUsageFocusedTotals({
318325function TokenStat ( {
319326 field,
320327 label,
328+ testId,
321329} : {
322330 field : { value : string | null ; incomplete : boolean } ;
323331 label : string ;
332+ testId ?: string ;
324333} ) {
325334 const parsed = parseTokenCount ( field . value ) ;
326335 return (
327336 < UsageStat
328337 display = { parsed !== null ? formatTokenCountExact ( parsed ) : null }
329338 isPartial = { isPartialField ( field ) }
330339 label = { label }
340+ testId = { testId }
331341 />
332342 ) ;
333343}
@@ -400,6 +410,55 @@ function formatCoverageRange(coverage: AgentUsageSeries["coverage"]): string {
400410 return `${ formatCoverageDate ( firstReportedAt ) } – ${ formatCoverageDate ( lastReportedAt ) } ` ;
401411}
402412
413+ /**
414+ * One "By model" row: the model/harness label with its display total and
415+ * Partial badge, plus a muted cache/fresh-input breakdown line beneath it
416+ * when any cache subset is known. The breakdown is computed once and omitted
417+ * entirely when no subset was reported, so old-harness models read no
418+ * differently than before.
419+ */
420+ function FocusedModelRow ( { model } : { model : AgentUsageModel } ) {
421+ const cacheBreakdown = formatModelCacheBreakdown ( model ) ;
422+ return (
423+ < div className = "space-y-0.5" >
424+ < div className = "flex items-center justify-between gap-3 text-sm" >
425+ < span className = "min-w-0 truncate text-muted-foreground" >
426+ { model . model ?? "Unknown model" }
427+ { model . harness !== null ? (
428+ < span
429+ className = "ml-1.5 text-xs text-muted-foreground/70"
430+ data-testid = "agent-usage-model-harness-label"
431+ >
432+ { model . harness }
433+ </ span >
434+ ) : null }
435+ </ span >
436+ < span className = "shrink-0 font-medium text-foreground" >
437+ { isUnknownField ( model . usage . totalTokens )
438+ ? formatModelIndependentFields ( model )
439+ : formatTokenCountExact (
440+ parseTokenCount ( model . usage . totalTokens . value ) ?? 0n ,
441+ ) }
442+ { isPartialField ( model . usage . totalTokens ) ||
443+ isModelIoPartial ( model ) ? (
444+ < Badge className = "ml-2" variant = "outline" >
445+ Partial
446+ </ Badge >
447+ ) : null }
448+ </ span >
449+ </ div >
450+ { cacheBreakdown !== null ? (
451+ < p
452+ className = "text-xs text-muted-foreground/70"
453+ data-testid = "agent-usage-model-cache-breakdown"
454+ >
455+ { cacheBreakdown }
456+ </ p >
457+ ) : null }
458+ </ div >
459+ ) ;
460+ }
461+
403462/**
404463 * Render known model I/O fields when the model total is unknown — never
405464 * collapses to "No usage reported" when input or output is actually known
0 commit comments