Skip to content

feat(cli): sync pi-agent usage via ccusage#26

Open
JaceThings wants to merge 2 commits into
851-labs:mainfrom
JaceThings:feat/pi-agent-source
Open

feat(cli): sync pi-agent usage via ccusage#26
JaceThings wants to merge 2 commits into
851-labs:mainfrom
JaceThings:feat/pi-agent-source

Conversation

@JaceThings

@JaceThings JaceThings commented Jul 2, 2026

Copy link
Copy Markdown

What

Register the pi ccusage subcommand as a sync source so Pi (https://pi.dev) usage rolls up under a pi source tag.

ccusage already ships ccusage pi daily; the CLI shells out to one ccusage <subcommand> daily run per source and tags rows with source. The aggregator/schema already handle ccusage's per-source dialects, and source is a free-form string server-side — so sources.ts is the single registration point:

{ source: "pi", subcommand: "pi" },

The --sources help text and unknown-source error auto-include pi via DEFAULT_SOURCE_NAMES.

Changes

  • apps/cli/src/ccusage/sources.ts — register the pi source
  • apps/cli/src/ccusage/sources.test.ts — guard the registration + subcommand mapping + unknown-source rejection
  • README.md, apps/cli/README.md — document Pi

Prerequisite: timezone-stable test fix

A pre-existing test (serviceScheduledSyncSince) asserted a machine-local date string against UTC instants, so it only passed in UTC/US zones and blocked CI. Fixed as a separate commit: the bucket key is now injectable (default unchanged) and the test uses a UTC key. Happy to split into its own PR if you'd prefer this one stay focused on the source addition.

serviceScheduledSyncSince bucketed lastSuccessAt/now via localDateKey,
which reads machine-local date parts — so a test feeding UTC instants
(2026-06-16T23:30Z) asserted a local-date string that only held in UTC
or US (UTC-) zones, failing on UTC+ hosts. Make the bucket key injectable
(default localDateKey, so runtime is unchanged) and rewrite the test to
pass a UTC key. Replace previousLocalDateKey with previousDateKey, which
derives yesterday from the key string via UTC normalization (timezone-
independent, handles month/year rollover).
Register the `pi` ccusage subcommand as a sync source so Pi coding
agent usage rolls up under the `pi` source tag. The aggregator and
schema already handle ccusage's per-source dialects, and `source` is
a free-form string server-side, so sources.ts is the single registration
point. Add a sources test guarding the registration and subcommand
name, and document Pi in the READMEs.
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.

1 participant