Objective
Add a mux source adapter for workspace session-usage summaries.
Source shape to support
- directory-backed JSON source under
~/.mux/sessions/**/session-usage.json
- one file can contain usage for multiple models in
byModel
- token buckets include input, cache read, cache write, output, and reasoning
- explicit cost may exist per bucket rather than as one top-level total
Implementation plan
-
Adapter file
- add
src/sources/mux/mux-source-adapter.ts
- implement
SourceAdapter with id = 'mux'
-
Discovery
- discover
session-usage.json files deterministically
- keep the source directory-backed and reachable via
--source-dir mux=...
-
Parsing
- parse the file once and emit one
UsageEvent per byModel entry
- map all available token buckets through
createUsageEvent, preserving reasoning/cache buckets intact
- if the model key is encoded as
provider:model, split provider and model before normalization
- sum explicit per-bucket costs into
costUsd for the emitted event and mark costMode: 'explicit'
- fall back to file mtime if
lastRequest.timestamp is missing
- derive
sessionId from the workspace/session directory name
- skip zero-token model entries so empty bookkeeping does not create rows
-
Wiring
- register
mux in src/sources/create-default-adapters.ts
- keep this on generic
--source-dir support
- update supported-source count/order/help expectations
-
Tests and docs
- add
tests/sources/mux-source-adapter.test.ts
- update shared registry/help tests and
README.md
Code paths to touch
src/sources/mux/mux-source-adapter.ts
src/sources/create-default-adapters.ts
src/utils/discover-files.ts
src/sources/parsing-utils.ts
src/domain/usage-event.ts
tests/sources/mux-source-adapter.test.ts
tests/sources/create-default-adapters.test.ts
tests/cli/create-cli.test.ts
README.md
Verification
- parser fixtures cover:
- multi-model
byModel files
- provider/model split from combined keys
- explicit cost summed from per-bucket cost fields
- missing
lastRequest.timestamp fallback
- zero-token entries skipped
llm-usage daily --source mux --source-dir mux=<fixture-dir> works
- full validation passes:
pnpm run lint
pnpm run typecheck
pnpm run test
pnpm run format:check
Objective
Add a
muxsource adapter for workspace session-usage summaries.Source shape to support
~/.mux/sessions/**/session-usage.jsonbyModelImplementation plan
Adapter file
src/sources/mux/mux-source-adapter.tsSourceAdapterwithid = 'mux'Discovery
session-usage.jsonfiles deterministically--source-dir mux=...Parsing
UsageEventperbyModelentrycreateUsageEvent, preserving reasoning/cache buckets intactprovider:model, split provider and model before normalizationcostUsdfor the emitted event and markcostMode: 'explicit'lastRequest.timestampis missingsessionIdfrom the workspace/session directory nameWiring
muxinsrc/sources/create-default-adapters.ts--source-dirsupportTests and docs
tests/sources/mux-source-adapter.test.tsREADME.mdCode paths to touch
src/sources/mux/mux-source-adapter.tssrc/sources/create-default-adapters.tssrc/utils/discover-files.tssrc/sources/parsing-utils.tssrc/domain/usage-event.tstests/sources/mux-source-adapter.test.tstests/sources/create-default-adapters.test.tstests/cli/create-cli.test.tsREADME.mdVerification
byModelfileslastRequest.timestampfallbackllm-usage daily --source mux --source-dir mux=<fixture-dir>workspnpm run lintpnpm run typecheckpnpm run testpnpm run format:check