Skip to content

feat(source): add Mux adapter #65

@ayagmar

Description

@ayagmar

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

  1. Adapter file

    • add src/sources/mux/mux-source-adapter.ts
    • implement SourceAdapter with id = 'mux'
  2. Discovery

    • discover session-usage.json files deterministically
    • keep the source directory-backed and reachable via --source-dir mux=...
  3. 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
  4. Wiring

    • register mux in src/sources/create-default-adapters.ts
    • keep this on generic --source-dir support
    • update supported-source count/order/help expectations
  5. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions