Skip to content

feat(usage): aggregate token usage and expose in CLI view and across harnesses - #50

Open
Adityakk9031 wants to merge 2 commits into
skillsynchq:mainfrom
Adityakk9031:feat/usage-aggregation-and-reporting
Open

Adityakk9031 wants to merge 2 commits into
skillsynchq:mainfrom
Adityakk9031:feat/usage-aggregation-and-reporting

Conversation

@Adityakk9031

@Adityakk9031 Adityakk9031 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Most harnesses track token usage in some form, but txcript previously dropped it during conversions, and xcript view didn't show any token statistics.

This PR wires up token tracking from the transcript model all the way through harnesses and into the terminal view.

What changed:

  • Usage math & aggregation: Implemented Default, otal_tokens(), is_zero(), along with Add, AddAssign, and Sum for Usage. Added ranscript.total_usage() to sum token footprints across assistant turns.
  • Harness support:
    • x: parses otal_input_tokens and otal_output_tokens from history_turn_committed payloads, falling back to usage-v2.json / session.json. Re-synthesizes accurate usage stats on export.
    • cursor_desktop: pulls token metrics from both okenCount and okenUsage schemas (prompt, completion, cache read/write).
    • hermes: reads usage columns from SQLite/export files and preserves structured usage objects during export.
  • Terminal view ( xcript view):
    • Displays total session tokens in the header: \Tokens: ( in, out[, cached])\
    • Shows per-turn tokens in assistant message headers: \Message #N · Assistant · tokens\
  • Tests & docs:
    • Added test suite in ests/integration/usage.rs testing arithmetic, aggregation, and lossless export roundtrips.
    • Updated docs/usage.md.

All tests pass and clippy runs clean.

…harnesses

- Implement Default, total_tokens(), is_zero(), Add, AddAssign, and Sum for Usage in common.rs
- Implement Transcript<Common>::total_usage() in transcript.rs
- Preserve token usage in fx harness (events, session.json, and usage-v2.json)
- Support expanded token usage variants (promptTokens, completionTokens, cache tokens) in Cursor Desktop
- Parse and serialize token usage in Hermes harness message rows
- Display session token accounting and assistant turn token counts in CLI view
- Document token usage display in docs/usage.md
- Add comprehensive integration tests in tests/integration/usage.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant