Files
oh-my-pi/packages/coding-agent/src/modes/components/usage-row.ts
T
metaphorics 35307b60a7 fix: emit per-turn token-usage row as a standalone block
With display.showTokenUsage on, the usage row was rendered inside the
assistant block above the turn's tool blocks. Finalizing the assistant
block was therefore deferred, and the late append recommitted the
already-committed tool rows, duplicating them in scrollback (worst with
parallel tool calls).

The assistant block now always finalizes as soon as a tool-call appears,
and the usage row is emitted as a standalone finalized block below the
turn's tool blocks across all three render paths (live event-controller,
transcript rebuild, agent-hub). The now-dead setUsageInfo/#usageInfo path
on AssistantMessageComponent is removed.
2026-06-14 08:17:36 +09:00

19 lines
719 B
TypeScript

import type { Usage } from "@oh-my-pi/pi-ai";
import { Container, Spacer, Text } from "@oh-my-pi/pi-tui";
import { formatNumber } from "@oh-my-pi/pi-utils";
import { theme } from "../../modes/theme/theme";
export function createUsageRowBlock(usage: Usage): Container {
const totalInput = usage.input + usage.cacheWrite;
const parts: string[] = [];
parts.push(`${theme.icon.input} ${formatNumber(totalInput)}`);
parts.push(`${theme.icon.output} ${formatNumber(usage.output)}`);
if (usage.cacheRead > 0) {
parts.push(`cache: ${formatNumber(usage.cacheRead)}`);
}
const block = new Container();
block.addChild(new Spacer(1));
block.addChild(new Text(theme.fg("dim", parts.join(" ")), 1, 0));
return block;
}