Skip to content

fix(ccusage): accept period key from current ccusage#2732

Merged
aeppling merged 1 commit into
rtk-ai:developfrom
mvanhorn:fix/ccusage-period-key
Jul 7, 2026
Merged

fix(ccusage): accept period key from current ccusage#2732
aeppling merged 1 commit into
rtk-ai:developfrom
mvanhorn:fix/ccusage-period-key

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

rtk cc-economics currently fails with missing field month (serde: missing field month) because ccusage renamed its per-record key from month/date/week to period. The deserializer in src/analytics/ccusage.rs still required the old names, so every record fails to parse and the feature is unusable.

Changes

  • Add #[serde(alias = "period")] to the key field of DailyEntry, WeeklyEntry, and MonthlyEntry. This accepts the current period key while staying backward-compatible with older ccusage output that still emits month/date/week. No other behavior changes.

Tests

  • Added period-shape parse tests for daily, weekly, and monthly.
  • Existing legacy-key tests remain green.
  • cargo fmt --all, cargo clippy --all-targets, and cargo test --all all clean (2290 passed).
  • Verified end-to-end: cargo run -- cc-economics now renders against live ccusage with no parse error.

Closes #2731

@rtk-release-bot rtk-release-bot Bot added the wrong-base PR targets master instead of develop label Jun 29, 2026
@rtk-release-bot

Copy link
Copy Markdown
Contributor

Automatic message from CI checks : It seems like this branch is targeting the wrong branch, any contribution should target develop branch.

See CONTRIBUTING.md for details.

@rtk-release-bot

Copy link
Copy Markdown
Contributor

Automatic message from CI checks : It seems like this branch is targeting the wrong branch, any contribution should target develop branch.

See CONTRIBUTING.md for details.

ccusage renamed the per-record key from month/date/week to `period`, so
the deserializer's required old field names no longer match and
`rtk cc-economics` fails with "missing field `month`".

Add `#[serde(alias = "period")]` to the daily/weekly/monthly key fields
so both legacy and current ccusage output parse. Adds period-shape tests
for all three granularities; existing legacy-key tests stay green.
@mvanhorn mvanhorn changed the base branch from master to develop June 29, 2026 14:30
@mvanhorn mvanhorn force-pushed the fix/ccusage-period-key branch from 07d1e0d to d0a77cd Compare June 29, 2026 14:31
@aeppling

aeppling commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Hey @mvanhorn , could you please provide related docs ? Cannot find anything about period key in ccusage : https://ccusage.com/guide/all-reports

@aeppling aeppling self-assigned this Jul 2, 2026
@reneleonhardt

Copy link
Copy Markdown

I guess aggregation by period has been introduced in May, for example fn period_key() -> "month".
ccusage/ccusage#1137
https://github.com/ccusage/ccusage/releases/tag/v20.0.5

@aeppling

aeppling commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Hey @mvanhorn

Tested locally, issue is fixed.

Thanks for contributing to RTK !

@aeppling aeppling merged commit d823aaf into rtk-ai:develop Jul 7, 2026
11 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 7, 2026
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Appreciate it, @aeppling - rtk reads the new ccusage period key cleanly now.

RudrenduPaul added a commit to RudrenduPaul/teamspend that referenced this pull request Jul 12, 2026
ccusage silently renamed month/date/week to period upstream (rtk-ai/rtk#2732),
breaking rtk's deserializer with no graceful path. requireField() had the same
exposure: any renamed field from Cursor or Anthropic would hard-fail with
SchemaDriftError and no fallback. requireField now accepts an optional list of
legacy/alternate field names to check before giving up, and SchemaDriftError
reports which aliases were tried when the field is still missing. No adapter
opts in yet since neither vendor has renamed anything, but the mechanism is now
real and tested.
@mvanhorn

Copy link
Copy Markdown
Contributor Author

Thanks @aeppling! Accepting the period key keeps rtk compatible with current ccusage output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wrong-base PR targets master instead of develop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cc-economics: ccusage JSON parse fails (expects month, ccusage now emits period)

3 participants