Skip to main content

Module stats

Module stats 

Source
Expand description

Session summary for /usage.

One shared implementation of the aggregate view both front-ends print: the REPL’s text line and the TUI’s notice. Keeping it in the kernel means the tally and its wording live in one place; each front-end adds only its own surrounding chrome.

Why a new module rather than folding into message.rs: message.rs is the serde wire model (ContentBlock at message.rs:5, AgentMessage at message.rs:47); stats is analysis over that model. Keeping the model pure means the derived view can change (add fields, change the cap) without touching the wire format or its round-trip tests.

Source of the tool tally: AgentMessage::Assistant ContentBlock::ToolCall blocks (message.rs:11), i.e. the model’s intent, exactly once per call. We deliberately do NOT use the paired ToolResult.name (message.rs:63) for the CALL tally: the two are 1:1 by tool_call_id (the loop synthesizes an error ToolResult for every unexecuted/blocked call — loop_.rs:688, synthesize_unexecuted at loop_.rs:798), so they count the same calls, but the Assistant block is the canonical, dedup-free definition.

The ERROR tally DOES depend on that pairing, and says so: errors and result_bytes are attributed by tool_call_id — never by the result’s own name, which is the loop’s copy — so a call whose result the transcript lost (a compacted prefix, a mid-run snapshot) contributes its call but no error, and a result with no call contributes nothing at all.

Structs§

Cost
A partial cost: what we COULD price, and how many turns we could not. Micro-USD (1e-6 USD), integers only — so it stays Eq and serde-stable, and the $ a front-end prints is reproducible.
SessionStats
Aggregate view of a conversation for /usage: how many turns reported usage, the summed token counts, and which tools ran.
ToolStat
One tool’s tally: how many times it was called, how many of those calls did not succeed, and how many bytes its results fed the context.

Constants§

TOOL_LIST_CAP
How many tool names the rendered tools: segment lists before +K more. Many tools exist (crates/wcode-cli/src/tools/); the list is a glance, not a manifest.

Functions§

aggregate
Sum per-session views into a total (the /usage total row).
session_stats
Fold a conversation into a SessionStats.