Skip to content

feat(source): add OpenClaw adapter #60

@ayagmar

Description

@ayagmar

Objective

Add an openclaw source adapter for current transcript-style agent session files.

Source shape to support

  • directory-backed JSONL transcripts under ~/.openclaw/agents/**/*.jsonl
  • model/provider can change over the lifetime of a transcript
  • only assistant messages with usage should emit events
  • timestamps may need a file-level fallback

Implementation plan

  1. Adapter file

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

    • follow the JSONL directory-backed pattern used by other adapters
    • discover transcript files deterministically
    • keep the first pass focused on the current transcript layout; avoid expanding scope into extra legacy index formats unless fixtures prove they are still required
  3. Parsing

    • stream JSONL rows with readJsonlObjects()
    • track in-file state when model/provider change rows appear
    • emit events only for assistant rows that include usage
    • preserve explicit cost if the transcript exposes it
    • fall back to file mtime when message timestamps are missing
    • ignore user/system/non-usage rows without failing the whole file
    • use diagnostics for malformed or unusable rows when helpful
  4. Wiring

    • register openclaw in src/sources/create-default-adapters.ts
    • keep it directory-backed via generic --source-dir openclaw=...
    • update supported-source count/order/help expectations
  5. Tests and docs

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

Code paths to touch

  • src/sources/openclaw/openclaw-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/openclaw-source-adapter.test.ts
  • tests/sources/create-default-adapters.test.ts
  • tests/cli/create-cli.test.ts
  • README.md

Verification

  • parser fixtures cover:
    • model/provider change rows updating parser state
    • assistant-only usage emission
    • explicit cost extraction
    • missing timestamp fallback to file mtime
    • irrelevant/non-usage rows ignored cleanly
  • llm-usage daily --source openclaw --source-dir openclaw=<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