fix(tui): show real-time cost total in sidebar and /cost commands

Sidebar cost line used displayed_cost_high_water for the total but
real values for the session/agent breakdown, so total did not equal
session + agents. Use real-time sums everywhere for internal
consistency.

/cost and /tokens commands now include sub-agent costs in the
displayed total, matching the footer chip.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
lbcheng
2026-05-08 18:48:23 +08:00
parent bd7c08ce3e
commit 5accda22d6
2 changed files with 8 additions and 3 deletions
+7 -2
View File
@@ -73,7 +73,10 @@ pub fn tokens(app: &mut App) -> CommandResult {
.replace("{total}", &app.session.total_tokens.to_string())
.replace(
"{cost}",
&app.format_cost_amount_precise(app.session_cost_for_currency(app.cost_currency)),
&app.format_cost_amount_precise(
app.session_cost_for_currency(app.cost_currency)
+ app.subagent_cost_for_currency(app.cost_currency),
),
)
.replace("{api_messages}", &message_count.to_string())
.replace("{chat_messages}", &chat_count.to_string())
@@ -83,9 +86,11 @@ pub fn tokens(app: &mut App) -> CommandResult {
/// Show session cost breakdown
pub fn cost(app: &mut App) -> CommandResult {
let total = app.session_cost_for_currency(app.cost_currency)
+ app.subagent_cost_for_currency(app.cost_currency);
let report = tr(app.ui_locale, MessageId::CmdCostReport).replace(
"{cost}",
&app.format_cost_amount_precise(app.session_cost_for_currency(app.cost_currency)),
&app.format_cost_amount_precise(total),
);
CommandResult::message(report)
}
+1 -1
View File
@@ -671,9 +671,9 @@ fn render_context_panel(f: &mut Frame, area: Rect, app: &App) {
)));
// ── Session cost ─────────────────────────────────────────────
let total_cost = app.displayed_session_cost_for_currency(app.cost_currency);
let session_cost = app.session_cost_for_currency(app.cost_currency);
let agent_cost = app.subagent_cost_for_currency(app.cost_currency);
let total_cost = session_cost + agent_cost;
lines.push(Line::from(Span::styled(
format!(
"cost: {} (session {} + agents {})",