Skip to content

feat: copilot-usage CLI tool#1

Merged
microsasa merged 1 commit intomainfrom
dev
Mar 13, 2026
Merged

feat: copilot-usage CLI tool#1
microsasa merged 1 commit intomainfrom
dev

Conversation

@microsasa
Copy link
Owner

@microsasa microsasa commented Mar 12, 2026

Local Copilot CLI session tracker. Parses ~/.copilot/session-state/*/events.jsonl for token usage, premium requests, model breakdowns, and cost data.

Closes #2

Features

  • Interactive mode with watchdog auto-refresh (FSEvents, 2s debounce)
  • Commands: summary, session, cost, live + interactive (no subcommand)
  • Shutdown aggregation: SUM all events (not last-only)
  • Active detection: resumed sessions, last_resume_time for running display
  • Premium requests: exact from shutdown data, N/A for active

Quality

  • 327 tests (272 unit @ 96% coverage + 55 e2e), 8 fixture scenarios
  • pyright strict, ruff, bandit — all clean
  • Pydantic v2, Click, Rich, watchdog, loguru

Docs

  • README with usage examples and pricing table
  • docs/architecture.md — data flow, components
  • docs/implementation.md — deep technical reference
  • docs/changelog.md — delivery history
  • docs/plan.md — roadmap

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new copilot-usage Python CLI tool (in the cli-tools monorepo) to parse local Copilot CLI session-state events.jsonl logs and render usage, session timelines, live sessions, and cost estimates.

Changes:

  • Introduces core implementation modules (models, parser, report, pricing, cli) plus packaging/entrypoint wiring.
  • Adds extensive unit + e2e test suites with anonymized fixture session data.
  • Adds project documentation (README + architecture/plan/changelog) and CI/dev tooling (Makefile, GitHub Actions, ruff/pyright/bandit config).

Reviewed changes

Copilot reviewed 26 out of 31 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/copilot_usage/cli.py Click command group for summary/session/cost/live and output wiring.
src/copilot_usage/models.py Pydantic event/data models and SessionSummary.
src/copilot_usage/parser.py Discovers sessions, parses events.jsonl, builds per-session summaries (active/resumed/completed).
src/copilot_usage/report.py Rich rendering: summary, session detail timeline, live sessions.
src/copilot_usage/pricing.py Model multiplier registry + premium-request estimation utilities.
src/copilot_usage/__init__.py Package marker.
src/copilot_usage/py.typed Declares the package as typed for type checkers.
tests/copilot_usage/test_cli.py Unit tests for CLI behaviors and error paths.
tests/copilot_usage/test_models.py Unit tests for Pydantic model validation/parsing.
tests/copilot_usage/test_parser.py Unit tests for discovery/parsing/summarization logic (incl. resumed sessions).
tests/copilot_usage/test_pricing.py Unit tests for pricing lookup + estimation.
tests/copilot_usage/test_report.py Unit tests for Rich rendering helpers/output.
tests/e2e/test_e2e.py End-to-end CLI tests against fixture data.
tests/e2e/__init__.py E2E test package marker.
tests/e2e/fixtures/0faecbdf-b889-4bca-a51a-5254f5488cb6/events.jsonl Anonymized session fixture data (completed session).
tests/e2e/fixtures/4a547040-0318-44a4-a514-7ac9cbecc17e/events.jsonl Anonymized session fixture data (active session).
tests/e2e/fixtures/b5df8a34-87f0-46d5-b865-83e89095b8dc/events.jsonl Anonymized session fixture data (completed session with tool calls).
tests/e2e/fixtures/corrupt-session/events.jsonl Fixture with malformed lines to validate robust parsing.
tests/e2e/fixtures/resumed-session/events.jsonl Fixture covering shutdown→resume and “active/resumed” detection.
pyproject.toml Project metadata, dependencies, scripts, and tooling config (ruff/pyright/pytest/coverage).
README.md End-user docs for installation and command usage, plus pricing info.
docs/architecture.md Design and data flow documentation.
docs/plan.md Monorepo/tooling structure and future roadmap.
docs/changelog.md Append-only history of delivered changes.
Makefile Local dev workflow targets (check/lint/typecheck/security/test).
.github/workflows/ci.yml PR gate workflow running lint/typecheck/security/tests.
.github/dependabot.yml Dependabot configuration for pip + GitHub Actions.
.editorconfig Editor defaults (indentation, newlines, etc.).
.gitignore Ignores virtualenv, caches, build artifacts, coverage, etc.
.python-version Pins local Python version to 3.12.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@microsasa microsasa force-pushed the dev branch 5 times, most recently from 8c419a1 to 2e2e9b2 Compare March 13, 2026 06:16
@microsasa
Copy link
Owner Author

Closes #2

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new copilot-usage CLI tool to parse local Copilot CLI session logs and present usage/cost reporting in the terminal, with comprehensive unit + e2e coverage and supporting docs.

Changes:

  • Implemented core parsing/models, Rich-based reporting, pricing multipliers, and Click CLI commands (summary, session, cost, live).
  • Added extensive unit and e2e tests, including anonymized fixture sessions (resumed + corrupt JSON lines).
  • Added repo scaffolding/automation: pyproject tooling, Makefile targets, CI workflow, and docs (README + architecture/plan/changelog).

Reviewed changes

Copilot reviewed 27 out of 32 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tests/e2e/test_e2e.py E2E CLI assertions against fixture session-state data
tests/e2e/init.py Marks e2e package
tests/e2e/fixtures/resumed-session/events.jsonl Fixture covering shutdown → resume → more events
tests/e2e/fixtures/corrupt-session/events.jsonl Fixture containing malformed JSON lines for robustness testing
tests/e2e/fixtures/b5df8a34-87f0-46d5-b865-83e89095b8dc/events.jsonl Realistic (anonymized) completed session fixture
tests/e2e/fixtures/4a547040-0318-44a4-a514-7ac9cbecc17e/events.jsonl Realistic (anonymized) active session fixture
tests/e2e/fixtures/0faecbdf-b889-4bca-a51a-5254f5488cb6/events.jsonl Realistic (anonymized) completed session fixture
tests/copilot_usage/test_report.py Unit tests for Rich rendering helpers (summary/live/detail/timeline)
tests/copilot_usage/test_pricing.py Unit tests for pricing registry, tiering, and estimation
tests/copilot_usage/test_parser.py Unit tests for discovery/parsing/summary building incl. resumed-session logic
tests/copilot_usage/test_models.py Unit tests for Pydantic models + typed payload parsing
tests/copilot_usage/test_cli.py CLI wiring tests via Click CliRunner
src/copilot_usage/report.py Rich rendering: summary, live sessions, session detail, event timeline
src/copilot_usage/pricing.py Pricing registry + model lookup + premium request estimation
src/copilot_usage/parser.py Session discovery, jsonl parsing, summary aggregation (active/resumed/completed)
src/copilot_usage/models.py Pydantic v2 models for event envelopes + payloads + summaries
src/copilot_usage/logging_config.py Loguru configuration for CLI console logging
src/copilot_usage/cli.py Click CLI entry point + commands + filtering + cost table
src/copilot_usage/init.py Package init
src/copilot_usage/py.typed Typing marker for PEP 561
pyproject.toml Project metadata, deps, tooling config (ruff/pyright/pytest/coverage)
README.md User-facing docs and examples for commands + pricing table
docs/architecture.md Design + data flow documentation
docs/changelog.md Append-only PR history and change log
docs/plan.md Forward-looking plan and repo/tool structure
Makefile Developer workflow: check/lint/typecheck/security/tests targets
.github/workflows/ci.yml PR-gated CI: lint/format/typecheck/bandit/pytest+coverage
.github/dependabot.yml Dependabot config for pip + GH Actions
.editorconfig Formatting/indent rules
.gitignore Python project ignores
.python-version Python version pin for local tooling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@microsasa microsasa force-pushed the dev branch 15 times, most recently from 2fe4f4e to eb28664 Compare March 13, 2026 20:20
@microsasa microsasa force-pushed the dev branch 4 times, most recently from ed911b6 to 713f449 Compare March 13, 2026 22:33
Parse local Copilot CLI session data for token usage, premium requests,
model breakdowns, and cost estimates.

- Rich interactive mode with watchdog auto-refresh (FSEvents on macOS)
- Commands: summary, session, cost, live + interactive (no subcommand)
- Shutdown aggregation (SUM all events, not last-only)
- Active vs historical session detection with last_resume_time
- Premium requests: exact from shutdown data, N/A for active
- 327 tests (272 unit @ 95% coverage + 55 e2e), 8 fixture scenarios
- Docs: README, architecture, changelog, implementation, plan

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsasa microsasa merged commit f9c5834 into main Mar 13, 2026
1 check passed
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