Skip to content

feat(cli,db,render): add row filters, cost sorting, run-rate projection, and CSV output - #9

Open
lorecanc wants to merge 1 commit into
rchardx:mainfrom
lorecanc:feat/filters-and-output
Open

feat(cli,db,render): add row filters, cost sorting, run-rate projection, and CSV output#9
lorecanc wants to merge 1 commit into
rchardx:mainfrom
lorecanc:feat/filters-and-output

Conversation

@lorecanc

@lorecanc lorecanc commented Aug 5, 2026

Copy link
Copy Markdown

Summary

Additive output/analysis features for run:

  • Row filters--provider, --model, --agent (all repeatable) and --exclude-provider. Implemented as a Filters dataclass + _filter_clause() applied to every query (_base_query, by_agent, by_session, totals), parameterized SQL only.
  • --sort tokens|cost|calls — sorts grouped rows by cost or calls instead of always tokens.
  • Run-rate projection — the summary panel shows ≈ $X/mo (cost projected onto a 30-day month at the observed pace); also emitted as run_rate_monthly in JSON.
  • --csv — row export to stdout (mutually exclusive with --json), with the agent view including the model column.

Cross-PR note

The Filters dataclass is identical to the one introduced by the granularity PR (feat/time-granularities) so the hunks deduplicate at merge; the granularity PR's by_time() already forwards a reserved filters parameter.

Changes

  • src/opencode_usage/db.py: Filters, _filter_clause(), filter/sort params on _base_query, daily, by_model, by_provider, by_agent, by_session, totals
  • src/opencode_usage/cli.py: filter/sort/csv flags, _build_filters, _compute_run_rate, JSON run_rate_monthly
  • src/opencode_usage/render.py: run-rate in render_summary, render_csv
  • tests/test_db.py, tests/test_cli.py: new tests (filters per query, exact-ID matching, sort order, flag parsing, exclusivity, run-rate math)
  • README.md: documented

Verification

  • uv run pytest tests/ — 390 passed
  • uvx ruff check . and uvx ruff format --check . — clean

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.

2 participants