Skip to content

feat(source): add Qwen CLI adapter #62

@ayagmar

Description

@ayagmar

Objective

Add a qwen source adapter for Qwen CLI chat JSONL files.

Source shape to support

  • directory-backed source under ~/.qwen/projects/**/*.jsonl
  • assistant rows carry usageMetadata
  • reasoning tokens are exposed separately and should be preserved
  • sessionId may be absent or unreliable in the payload

Implementation plan

  1. Adapter file

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

    • discover JSONL files under the Qwen projects tree deterministically
    • keep the adapter directory-backed via generic --source-dir qwen=...
  3. Parsing

    • stream JSONL rows and emit usage events only for assistant rows with usageMetadata
    • map token fields carefully:
      • prompt tokens -> input
      • candidate tokens -> output
      • thoughts tokens -> reasoning
      • cached content tokens -> cache read
    • keep cache write at zero unless the format truly exposes it
    • normalize timestamps and fall back to file mtime when the row timestamp is missing/invalid
    • when payload sessionId is blank/missing, derive a stable fallback from the project path + filename so unrelated sessions do not collide
    • skip zero-token rows
    • avoid advertising fixedProviderRoots unless provider pruning has a real canonical root for this source
  4. Wiring

    • register qwen in src/sources/create-default-adapters.ts
    • update supported-source count/order/help expectations
    • keep the source on generic --source-dir support
  5. Tests and docs

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

Code paths to touch

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

Verification

  • parser fixtures cover:
    • reasoning-token capture
    • malformed-line tolerance
    • blank/missing payload session id fallback
    • timestamp fallback to file mtime
    • zero-token rows skipped
  • llm-usage daily --source qwen --source-dir qwen=<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