feat: add --full flag to disable column truncation#919
feat: add --full flag to disable column truncation#919BuluBulugege wants to merge 2 commits intoryoppippi:mainfrom
Conversation
Add Hit Rate as a first-class metric alongside Input/Output/Cache columns in daily, monthly, weekly, and session reports. The hit rate is calculated as CacheRead / (Input + CacheCreate + CacheRead), color-coded green (>=70%), yellow (>=40%), or red (<40%). Also included in compact mode and JSON output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When terminal width is insufficient, ResponsiveTable normally scales column widths proportionally and wraps text within cells. The --full flag disables this behavior: columns use their full content width, compact mode is overridden, and word wrapping is disabled. The table may overflow horizontally but all data is displayed without truncation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR adds a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
packages/terminal/src/table.ts (1)
477-484:⚠️ Potential issue | 🟡 MinorSeparate hit-rate value formatting from coloring.
formatCacheHitRate()now returns a pre-colored string, but the new breakdown and totals rows want the same percentage in gray/yellow row styling. As written, those cells will render with the hit-rate color instead of the row color. Return a plain percentage from the shared helper, or let callers pass the final colorizer.Also applies to: 529-544, 669-678
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/terminal/src/table.ts` around lines 477 - 484, The hit-rate helper formatCacheHitRate currently returns a colored string which prevents row-level coloring (e.g. in the breakdown and totals rows around the row pushing at table.ts lines shown); change formatCacheHitRate to return a plain percentage string (or add an optional colorizer parameter) and then update callers (e.g. the places that call formatCacheHitRate(breakdown) in the rows near the shown diffs and the other regions around the 529-544 and 669-678 areas) to apply the desired color themselves (wrap the returned plain string with pc.gray(...) or pc.yellow(...) as appropriate) so the row coloring is preserved.apps/ccusage/src/commands/daily.ts (1)
102-125:⚠️ Potential issue | 🟠 Major
daily --instances --jsonoutput missingcacheHitRatefield in grouped schemaThe grouped JSON path (when
--instancesis enabled) usesgroupByProject(dailyData)which returnsDailyProjectOutput[]objects. This type does not includecacheHitRate, unlike the flatdailyJSON branch which explicitly adds it viacalculateCacheHitRate(data). UpdateDailyProjectOutputtype in_json-output-types.tsto includecacheHitRate, and updategroupByProject()in_daily-grouping.tsto calculate and include it.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/ccusage/src/commands/daily.ts` around lines 102 - 125, The grouped JSON path when using --instances omits cacheHitRate because DailyProjectOutput (in _json-output-types.ts) lacks that field and groupByProject (in _daily-grouping.ts) does not compute it; update the DailyProjectOutput type to include cacheHitRate: number (or nullable as appropriate) and modify groupByProject(dailyData) to compute cacheHitRate for each DailyProjectOutput by calling the existing calculateCacheHitRate(data) logic (or replicating its calculation) for each project grouping so the grouped JSON includes cacheHitRate alongside other fields.apps/ccusage/src/commands/monthly.ts (1)
69-85:⚠️ Potential issue | 🟡 MinorAdd
cacheHitRateto totals JSON to match per-row entries.Per-month JSON entries now expose
cacheHitRate, but thetotalsobject does not. This creates schema inconsistency across the same JSON response. Update both the hardcoded empty-output totals (lines 44–51) and the call tocreateTotalsObject()(line 84) to include the aggregate cache hit rate.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/ccusage/src/commands/monthly.ts` around lines 69 - 85, The totals JSON is missing cacheHitRate causing schema mismatch; update the hardcoded empty totals object (the one returned when no data) to include cacheHitRate (e.g., 0 or null) and modify createTotalsObject so its returned totals include an aggregate cacheHitRate computed consistently (use calculateCacheHitRate or compute from totals.inputTokens/ totals.outputTokens/ cache read/creation counts as your existing logic does) so the totals key in the JSON matches the per-month entries; ensure the call that builds jsonOutput.totals still uses createTotalsObject(totals) but that createTotalsObject and the empty totals value both produce a cacheHitRate field.
🧹 Nitpick comments (1)
apps/ccusage/src/_shared-args.ts (1)
113-116: Mention the--compactoverride in--fullhelp text.
--fullalso disables compact mode, but the description only talks about truncation. Calling that out in--helpmakes--compact --fullbehavior discoverable.✏️ Suggested wording
- description: 'Show all columns at full width without truncation (allows horizontal overflow)', + description: + 'Show all columns at full width without truncation (allows horizontal overflow and overrides --compact)',🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/ccusage/src/_shared-args.ts` around lines 113 - 116, Update the description for the "full" option in the options object (the property named full in _shared-args.ts) to mention that it disables compact mode (i.e., it overrides --compact). Edit the description string to combine the existing text about showing all columns/full width with a short clause like "This also disables compact mode and overrides --compact" so the behavior is discoverable in --help output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/ccusage/src/commands/daily.ts`:
- Around line 102-125: The grouped JSON path when using --instances omits
cacheHitRate because DailyProjectOutput (in _json-output-types.ts) lacks that
field and groupByProject (in _daily-grouping.ts) does not compute it; update the
DailyProjectOutput type to include cacheHitRate: number (or nullable as
appropriate) and modify groupByProject(dailyData) to compute cacheHitRate for
each DailyProjectOutput by calling the existing calculateCacheHitRate(data)
logic (or replicating its calculation) for each project grouping so the grouped
JSON includes cacheHitRate alongside other fields.
In `@apps/ccusage/src/commands/monthly.ts`:
- Around line 69-85: The totals JSON is missing cacheHitRate causing schema
mismatch; update the hardcoded empty totals object (the one returned when no
data) to include cacheHitRate (e.g., 0 or null) and modify createTotalsObject so
its returned totals include an aggregate cacheHitRate computed consistently (use
calculateCacheHitRate or compute from totals.inputTokens/ totals.outputTokens/
cache read/creation counts as your existing logic does) so the totals key in the
JSON matches the per-month entries; ensure the call that builds
jsonOutput.totals still uses createTotalsObject(totals) but that
createTotalsObject and the empty totals value both produce a cacheHitRate field.
In `@packages/terminal/src/table.ts`:
- Around line 477-484: The hit-rate helper formatCacheHitRate currently returns
a colored string which prevents row-level coloring (e.g. in the breakdown and
totals rows around the row pushing at table.ts lines shown); change
formatCacheHitRate to return a plain percentage string (or add an optional
colorizer parameter) and then update callers (e.g. the places that call
formatCacheHitRate(breakdown) in the rows near the shown diffs and the other
regions around the 529-544 and 669-678 areas) to apply the desired color
themselves (wrap the returned plain string with pc.gray(...) or pc.yellow(...)
as appropriate) so the row coloring is preserved.
---
Nitpick comments:
In `@apps/ccusage/src/_shared-args.ts`:
- Around line 113-116: Update the description for the "full" option in the
options object (the property named full in _shared-args.ts) to mention that it
disables compact mode (i.e., it overrides --compact). Edit the description
string to combine the existing text about showing all columns/full width with a
short clause like "This also disables compact mode and overrides --compact" so
the behavior is discoverable in --help output.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 604e66d3-6746-4d1f-bcd3-08a5c4ac143a
📒 Files selected for processing (6)
apps/ccusage/src/_shared-args.tsapps/ccusage/src/commands/daily.tsapps/ccusage/src/commands/monthly.tsapps/ccusage/src/commands/session.tsapps/ccusage/src/commands/weekly.tspackages/terminal/src/table.ts
Summary
--fullCLI flag to all report commands (daily, monthly, weekly, session)7,669,754instead of7,669,7…)Depends on #918
Test plan
COLUMNS=80 ccusage daily— verify normal truncation/compact behaviorCOLUMNS=80 ccusage daily --full— verify all columns at full width, no truncationccusage daily --full— verify works on wide terminal tooccusage session --full— verify session columns including Last Activity🤖 Generated with Claude Code
Summary by CodeRabbit
--fullcommand-line option to display all columns at full width without truncation.