Show task tokens and usage estimates in the agent command center (#44970)

## What changed

- Display input/output token counts and estimated credits and USD cost in task details. Prefer live token totals, falling back to complete totals from usage breakdowns.
- Fetch estimates for the selected task on a one-minute cadence for supported Business and Enterprise plans. Cache results, preserve prior nonzero estimates when a response reports zero, and stop fetching when the capability is unavailable.
- Clear cached usage and discard pending results on account changes, reconnects, or missed server events. Prioritize activity and usage over the original prompt when space is limited.

## Testing

Add a rendering snapshot and tests covering caching, stale results, unavailable usage, token resets, and incomplete usage breakdowns.

GitOrigin-RevId: b72c96053557389fdc723a70fab0dab841a52e49
This commit is contained in:
Eric Traut
2026-09-12 04:29:48 +00:00
committed by copyberry
parent 7efb0262d6
commit aee8a55ab6
15 changed files with 533 additions and 4 deletions
@@ -480,6 +480,7 @@ impl AgentsOverviewView {
model_name(&row.thread).to_string().into(),
]),
];
lines.extend(row.details.usage_lines.clone());
if let Some(branch) = row
.thread
.git_info
@@ -491,6 +492,7 @@ impl AgentsOverviewView {
lines.push(branch.clone().into());
}
let preview = super::agents_overview_details::preview_markdown(&row.thread.preview);
let prompt_start = crate::wrapping::word_wrap_lines(lines.clone(), width).len();
lines.extend([Line::default(), Line::from("Prompt".dim())]);
let prompt = crate::markdown_render::render_markdown_text_with_width_and_cwd(
match preview.as_str() {
@@ -521,6 +523,12 @@ impl AgentsOverviewView {
);
}
let mut details = crate::wrapping::word_wrap_lines(details, width);
if !row.details.usage_lines.is_empty()
&& details.len() > usize::from(area.height).saturating_sub(lines.len())
{
// Activity and usage take precedence over repeating the original prompt.
lines.truncate(prompt_start);
}
let available = usize::from(area.height).saturating_sub(lines.len());
if details.len() > available {
details.truncate(available);