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
-
Adapter file
- add
src/sources/openclaw/openclaw-source-adapter.ts
- implement
SourceAdapter with id = 'openclaw'
-
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
-
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
-
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
-
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
Objective
Add an
openclawsource adapter for current transcript-style agent session files.Source shape to support
~/.openclaw/agents/**/*.jsonlImplementation plan
Adapter file
src/sources/openclaw/openclaw-source-adapter.tsSourceAdapterwithid = 'openclaw'Discovery
Parsing
readJsonlObjects()Wiring
openclawinsrc/sources/create-default-adapters.ts--source-dir openclaw=...Tests and docs
tests/sources/openclaw-source-adapter.test.tsREADME.mdCode paths to touch
src/sources/openclaw/openclaw-source-adapter.tssrc/sources/create-default-adapters.tssrc/utils/discover-jsonl-files.tssrc/utils/read-jsonl-objects.tssrc/sources/parsing-utils.tssrc/domain/usage-event.tstests/sources/openclaw-source-adapter.test.tstests/sources/create-default-adapters.test.tstests/cli/create-cli.test.tsREADME.mdVerification
llm-usage daily --source openclaw --source-dir openclaw=<fixture-dir>workspnpm run lintpnpm run typecheckpnpm run testpnpm run format:check