Repository navigation
feat: add --format json to report, today, and month commands - #53
Conversation
|
How you could use this feature:
|
Outputs full dashboard data as structured JSON to stdout, including: overview, daily breakdown, projects, models with token counts, activities with one-shot rates, core tools, MCP servers, and shell commands. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
273525c to
09139b1
Compare
AgentSeal
left a comment
There was a problem hiding this comment.
Thanks for this, it's a genuinely useful feature and moves codeburn from "TUI" to "data source you can pipe into CI, Slack bots, or custom dashboards". Structure is clean and the README update is thorough.
One real bug to fix before merge (inline comment below). Also a small style point: the section-label comments (// daily, // projects, // models, etc.) should come out, since the repo CLAUDE.md says "No comments unless the WHY is non-obvious".
Nice-to-haves for a follow-up, not this PR:
- Expose a machine-readable period key alongside the display label (e.g.
"periodKey": "week"next to"period": "Last 7 Days"). Easier for programmatic consumers to match on. topSessionsfrom the recent TUI addition isn't in the JSON yet, even though the description says the output mirrors the dashboard. Fine to add later.
Appreciate the contribution.
| } | ||
| const models = Object.entries(modelMap) | ||
| .sort(([, a], [, b]) => b.cost - a.cost) | ||
| .map(([name, d]) => ({ name, cost: convertCost(d.cost), ...d, cost_usd: undefined })) |
There was a problem hiding this comment.
Currency bug: because ...d comes after cost: convertCost(d.cost), the spread resets cost back to d.cost (which is USD) and every models[].cost in the output ignores the selected currency. The two-step cost_usd strip on the next line is also dead code, there's no cost_usd key on d.
One-liner fix that matches the pattern used in projects and activities above:
.map(([name, d]) => ({ name, ...d, cost: convertCost(d.cost) }))There was a problem hiding this comment.
Fixed in fad21f3 — destructured cost out before the spread so convertCost result is no longer overwritten. Collapsed the two-step map into one while I was at it since the cost_usd strip was dead code as noted.
Also addressed the style feedback (section-label comments removed) and went ahead and added both nice-to-haves in 7a061ea — periodKey alongside period, and topSessions (top 5 by cost, same logic as the TUI panel).
|
heads up, your commit email ( |
|
Thanks for the heads up, I generally contribute with my personal email however my company has been looking to empower us to contribute to open source so this was my first step into the space on this account. |
AgentSeal
left a comment
There was a problem hiding this comment.
all three review items addressed, currency fix is correct. merging. the unused getCostColumnHeader import and the three near-identical json branches will get a small cleanup commit on main right after.
Summary
Adds
--format jsonto thereport,today, andmonthcommands, outputting full dashboard data as structured JSON to stdout.The existing JSON options (
status --format jsonandexport -f json) are limited — status only gives today/month cost+calls, and export writes to a file. This adds a comprehensive JSON output that mirrors everything in the TUI dashboard.JSON structure
{ "generated": "2026-04-16T...", "currency": "USD", "period": "Last 7 Days", "overview": { "cost", "calls", "sessions", "cacheHitPercent", "tokens": {...} }, "daily": [{ "date", "cost", "calls" }], "projects": [{ "name", "path", "cost", "calls", "sessions" }], "models": [{ "name", "cost", "calls", "inputTokens", "outputTokens", ... }], "activities": [{ "category", "cost", "turns", "editTurns", "oneShotTurns", "oneShotRate" }], "tools": [{ "name", "calls" }], "mcpServers": [{ "name", "calls" }], "shellCommands": [{ "name", "calls" }] }Usage
Changes
src/cli.ts—buildJsonReport()function +--formatoption onreport,today,monthREADME.md— documented JSON output with examplesTest plan
report --format jsonoutputs valid JSON with all sectionstoday --format jsonworksmonth --format jsonworks--format tuistill launches interactive dashboard--helpshows new optiontsup🤖 Generated with Claude Code