@@ -9,7 +9,7 @@ import type { AgentSession } from "@earendil-works/pi-coding-agent";
99import { type Component , Input , matchesKey , type TUI , truncateToWidth , visibleWidth , wrapTextWithAnsi } from "@earendil-works/pi-tui" ;
1010import { extractText } from "../context.js" ;
1111import type { AgentRecord } from "../types.js" ;
12- import { getLifetimeTotal , getSessionContextPercent } from "../usage.js" ;
12+ import { formatCost , getLifetimeTotal , getSessionContextPercent } from "../usage.js" ;
1313import type { Theme } from "./agent-widget.js" ;
1414import { type AgentActivity , buildInvocationTags , describeActivity , fgPreservingNestedStyles , formatDuration , formatSessionTokens , getDisplayName , getPromptModeLabel } from "./agent-widget.js" ;
1515import { createViewerKeys , type ViewerKeybindings , type ViewerKeys } from "./viewer-keys.js" ;
@@ -45,6 +45,8 @@ export class ConversationViewer implements Component {
4545 keybindings ?: ViewerKeybindings ,
4646 /** Send a steering message to the agent. Omitted → no compose affordance. */
4747 private onSteer ?: ( message : string ) => void ,
48+ /** Read live cost-display preference. Omitted → hide reported cost. */
49+ private showCost : ( ) => boolean = ( ) => false ,
4850 ) {
4951 this . keys = createViewerKeys ( keybindings ) ;
5052 this . unsubscribe = session . subscribe ( ( ) => {
@@ -152,11 +154,15 @@ export class ConversationViewer implements Component {
152154 const headerParts : string [ ] = [ duration ] ;
153155 const toolUses = this . activity ?. toolUses ?? this . record . toolUses ;
154156 if ( toolUses > 0 ) headerParts . unshift ( `${ toolUses } tool${ toolUses === 1 ? "" : "s" } ` ) ;
155- const tokens = getLifetimeTotal ( this . activity ?. lifetimeUsage ) ;
157+ const usage = this . activity ?. lifetimeUsage ?? this . record . lifetimeUsage ;
158+ const tokens = getLifetimeTotal ( usage ) ;
156159 if ( tokens > 0 ) {
157160 const percent = getSessionContextPercent ( this . activity ?. session ) ;
158161 headerParts . push ( formatSessionTokens ( tokens , percent , th , this . record . compactionCount ) ) ;
159162 }
163+ if ( this . showCost ( ) && usage ?. cost !== undefined ) {
164+ headerParts . push ( formatCost ( usage . cost ) ) ;
165+ }
160166
161167 lines . push ( row (
162168 `${ statusIcon } ${ th . bold ( name ) } ${ modeTag } ${ th . fg ( "muted" , this . record . description ) } ${ th . fg ( "dim" , "·" ) } ${ fgPreservingNestedStyles ( th , "dim" , headerParts . join ( " · " ) ) } ` ,
0 commit comments