Skip to content

feat(source): add Kimi CLI adapter #61

@ayagmar

Description

@ayagmar

Objective

Add a kimi source adapter for Kimi CLI wire logs.

Source shape to support

  • directory-backed source under ~/.kimi/sessions/**/wire.jsonl
  • token usage arrives on StatusUpdate messages inside the wire stream
  • nearby config can improve model metadata
  • repeated status messages may need deduplication

Implementation plan

  1. Adapter file

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

    • discover only wire.jsonl files rather than every JSONL in the tree
    • keep the adapter directory-backed and reachable via --source-dir kimi=...
  3. Parsing

    • stream JSONL rows and process StatusUpdate messages only
    • derive sessionId from the path when the wire format does not supply a better stable identifier
    • if nearby config provides model metadata, load it in a narrow/safe way
    • expose that config file through getParseDependencies() so parse-cache invalidation stays correct when model config changes
    • normalize timestamps from numeric/float wire timestamps and fall back to file mtime when needed
    • skip zero-token updates
    • if the format can repeat identical message usage, deduplicate on a stable key rather than double counting
    • cost should stay estimated unless the source provides explicit cost
  4. Wiring

    • register kimi in src/sources/create-default-adapters.ts
    • keep source selection/help output in sync with the new source id
    • use generic --source-dir support; no dedicated flag needed
  5. Tests and docs

    • add tests/sources/kimi-source-adapter.test.ts
    • update registry/help tests and README.md

Code paths to touch

  • src/sources/kimi/kimi-source-adapter.ts
  • src/sources/create-default-adapters.ts
  • src/utils/discover-files.ts
  • src/utils/read-jsonl-objects.ts
  • src/sources/parsing-utils.ts
  • src/domain/usage-event.ts
  • tests/sources/kimi-source-adapter.test.ts
  • tests/sources/create-default-adapters.test.ts
  • tests/cli/create-cli.test.ts
  • README.md

Verification

  • parser fixtures cover:
    • single-turn and multi-turn StatusUpdate streams
    • zero-token updates skipped
    • numeric/float timestamp normalization
    • config-assisted model resolution
    • parse dependency invalidation for the nearby config file
    • deduplication if the same message usage repeats
  • llm-usage daily --source kimi --source-dir kimi=<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