Skip to content

feat: /cost TUI slash command with usage dialog#11

Merged
e6qu merged 1 commit intodevfrom
feat/cost-dialog
Mar 17, 2026
Merged

feat: /cost TUI slash command with usage dialog#11
e6qu merged 1 commit intodevfrom
feat/cost-dialog

Conversation

@e6qu
Copy link
Copy Markdown
Owner

@e6qu e6qu commented Mar 17, 2026

Summary

  • Add /cost (alias /usage) TUI-only slash command that opens a compact usage dialog showing session, daily, and monthly API cost metrics with cache hit rates
  • Add GET /session/stats server endpoint reusing existing aggregateSessionStats logic
  • Extract pure cost-metrics module (cost-metrics.ts) for testability
  • Add 25 unit tests + 4 UI tests (first usage of @opentui/solid testRender in the codebase)

Dialog output

┌─ Usage ───────────────────┐
│ Sess  $0.4╱$1.9     ⟐85% │
│ ☼-ly  $12.3╱$34.5   ⟐72% │
│ ☽-ly  $148╱$412     ⟐68% │
└───────────────────────────┘

Columns: actual/no-cache cost pair, cache hit %. Ephemeral — no messages sent to LLM.

Test plan

  • 25 unit tests for formatCost, findModel, computeSessionMetrics, computeStatsMetrics, formatRow
  • 4 UI tests rendering DialogCost via testRender + captureCharFrame with mocked contexts
  • Full test suite passes (1376 tests, 0 failures)
  • Manual: bun run dev → open session → /cost → verify dialog renders → press esc → dialog dismisses
  • Manual: verify no messages added to session after /cost

Add a TUI-only /cost (alias /usage) dialog showing session, daily, and
monthly API cost metrics with cache hit rates. The dialog computes
actual vs no-cache cost using per-model pricing and displays a compact
three-row view.

- New GET /session/stats endpoint reusing aggregateSessionStats
- Pure cost-metrics module with formatCost, computeSessionMetrics, etc.
- 25 unit tests + 4 UI tests using @opentui/solid testRender
- Enable @opentui/solid/preload in test config for .tsx test support
@e6qu e6qu merged commit f919a00 into dev Mar 17, 2026
1 check passed
@e6qu e6qu deleted the feat/cost-dialog branch March 17, 2026 12:15
e6qu added a commit that referenced this pull request Mar 18, 2026
Add a TUI-only /cost (alias /usage) dialog showing session, daily, and
monthly API cost metrics with cache hit rates. The dialog computes
actual vs no-cache cost using per-model pricing and displays a compact
three-row view.

- New GET /session/stats endpoint reusing aggregateSessionStats
- Pure cost-metrics module with formatCost, computeSessionMetrics, etc.
- 25 unit tests + 4 UI tests using @opentui/solid testRender
- Enable @opentui/solid/preload in test config for .tsx test support

Co-authored-by: Adrian Mârza <adi11235 at gmail dot com>
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