feat(tui): honor display.* flags in turn renderer, status bar, and event handler

- turnController gates scheduleStreaming / reasoning recorders on
  streaming + showReasoning so disabling them keeps the buffer silent
  until message.complete flushes
- createGatewayEventHandler only surfaces inline_diff previews when
  inlineDiffs is on
- StatusRule takes a showCost prop and renders `· $X.XXXX` with the
  same toFixed(4) formatting as /usage when usage.cost_usd is present
- Usage grows cost_usd?: number to match the gateway payload
- Existing handler tests flip showReasoning on in beforeEach so
  reasoning-flow assertions keep their meaning
This commit is contained in:
Brooklyn Nicholson 2026-04-18 09:26:03 -05:00
parent 200c17433c
commit fd6ffc777f
6 changed files with 23 additions and 4 deletions

View file

@ -4,7 +4,7 @@ import { createGatewayEventHandler } from '../app/createGatewayEventHandler.js'
import { resetOverlayState } from '../app/overlayStore.js'
import { turnController } from '../app/turnController.js'
import { resetTurnState } from '../app/turnStore.js'
import { resetUiState } from '../app/uiStore.js'
import { patchUiState, resetUiState } from '../app/uiStore.js'
import { estimateTokensRough } from '../lib/text.js'
import type { Msg } from '../types.js'
@ -47,6 +47,7 @@ describe('createGatewayEventHandler', () => {
resetUiState()
resetTurnState()
turnController.fullReset()
patchUiState({ showReasoning: true })
})
it('persists completed tool rows when message.complete lands immediately after tool.complete', () => {

View file

@ -266,7 +266,7 @@ export function createGatewayEventHandler(ctx: GatewayEventHandlerContext): (ev:
case 'tool.complete':
turnController.recordToolComplete(ev.payload.tool_id, ev.payload.name, ev.payload.error, ev.payload.summary)
if (ev.payload.inline_diff) {
if (ev.payload.inline_diff && getUiState().inlineDiffs) {
sys(ev.payload.inline_diff)
}

View file

@ -11,7 +11,7 @@ import type { ActiveTool, ActivityItem, Msg, SubagentProgress } from '../types.j
import { resetOverlayState } from './overlayStore.js'
import { patchTurnState, resetTurnState } from './turnStore.js'
import { patchUiState } from './uiStore.js'
import { getUiState, patchUiState } from './uiStore.js'
const INTERRUPT_COOLDOWN_MS = 1500
const ACTIVITY_LIMIT = 8
@ -226,10 +226,17 @@ class TurnController {
}
this.bufRef = rendered ?? this.bufRef + text
this.scheduleStreaming()
if (getUiState().streaming) {
this.scheduleStreaming()
}
}
recordReasoningAvailable(text: string) {
if (!getUiState().showReasoning) {
return
}
const incoming = text.trim()
if (!incoming || this.reasoningText.trim()) {
@ -242,6 +249,10 @@ class TurnController {
}
recordReasoningDelta(text: string) {
if (!getUiState().showReasoning) {
return
}
this.reasoningText += text
this.scheduleReasoning()
this.pulseReasoningStreaming()

View file

@ -99,6 +99,7 @@ export function StatusRule({
usage,
bgCount,
sessionStartedAt,
showCost,
voiceLabel,
t
}: StatusRuleProps) {
@ -136,6 +137,9 @@ export function StatusRule({
) : null}
{voiceLabel ? <Text color={t.color.dim}> {voiceLabel}</Text> : null}
{bgCount > 0 ? <Text color={t.color.dim}> {bgCount} bg</Text> : null}
{showCost && typeof usage.cost_usd === 'number' ? (
<Text color={t.color.dim}> ${usage.cost_usd.toFixed(4)}</Text>
) : null}
</Text>
</Box>
@ -285,6 +289,7 @@ interface StatusRuleProps {
cwdLabel: string
model: string
sessionStartedAt?: number | null
showCost: boolean
status: string
statusColor: string
t: Theme

View file

@ -190,6 +190,7 @@ const ComposerPane = memo(function ComposerPane({
cwdLabel={status.cwdLabel}
model={ui.info?.model?.split('/').pop() ?? ''}
sessionStartedAt={status.sessionStartedAt}
showCost={ui.showCost}
status={ui.status}
statusColor={status.statusColor}
t={ui.theme}

View file

@ -68,6 +68,7 @@ export interface Usage {
context_max?: number
context_percent?: number
context_used?: number
cost_usd?: number
input: number
output: number
total: number