Objective
Add an amp source adapter for local Amp thread files with support for both aggregated ledger usage and per-message fallback parsing.
Source shape to support
- directory-backed JSON source under
~/.local/share/amp/threads/
- thread files named
T-*.json
- preferred usage source is an aggregated ledger/event list when present
- fallback usage source is assistant message usage embedded in the same thread file
- explicit credits/cost may already be present in the source data
Implementation plan
-
Adapter file
- add
src/sources/amp/amp-source-adapter.ts
- implement
SourceAdapter with id = 'amp'
-
Discovery
- use
discoverFiles(..., { extension: '.json' }) plus a T-*.json filename filter or equivalent deterministic discovery helper
- keep the adapter directory-backed and reachable with
--source-dir amp=...
-
Parsing
- parse the thread JSON once per file
- prefer aggregated ledger/events when available because they represent the cleanest usage signal
- if no usable ledger events exist, fall back to assistant message usage records from the same file
- preserve explicit cost when present
- infer provider from model names conservatively
- use thread-created time and then file mtime as timestamp fallbacks when event timestamps are missing
- skip zero-token records so empty bookkeeping rows do not create usage events
- use
parseFileWithDiagnostics() if malformed thread files or invalid usage sections should surface skipped-row reasons
-
Wiring
- register
amp in src/sources/create-default-adapters.ts
- rely on generic
--source-dir support rather than adding a dedicated path flag
- update supported-source registry/help expectations
-
Tests and docs
- add
tests/sources/amp-source-adapter.test.ts
- cover both ledger-first and message-fallback behavior
- update shared registry/help tests and
README.md
Code paths to touch
src/sources/amp/amp-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/amp-source-adapter.test.ts
tests/sources/create-default-adapters.test.ts
tests/cli/create-cli.test.ts
README.md
Verification
- parser fixtures cover:
- ledger-backed usage events
- assistant-message fallback when no usable ledger exists
- timestamp fallback order
- zero-token rows skipped
- explicit cost preserved
llm-usage daily --source amp --source-dir amp=<fixture-dir> works
- supported-source help output and registry tests are updated
- full validation passes:
pnpm run lint
pnpm run typecheck
pnpm run test
pnpm run format:check
Objective
Add an
ampsource adapter for local Amp thread files with support for both aggregated ledger usage and per-message fallback parsing.Source shape to support
~/.local/share/amp/threads/T-*.jsonImplementation plan
Adapter file
src/sources/amp/amp-source-adapter.tsSourceAdapterwithid = 'amp'Discovery
discoverFiles(..., { extension: '.json' })plus aT-*.jsonfilename filter or equivalent deterministic discovery helper--source-dir amp=...Parsing
parseFileWithDiagnostics()if malformed thread files or invalid usage sections should surface skipped-row reasonsWiring
ampinsrc/sources/create-default-adapters.ts--source-dirsupport rather than adding a dedicated path flagTests and docs
tests/sources/amp-source-adapter.test.tsREADME.mdCode paths to touch
src/sources/amp/amp-source-adapter.tssrc/sources/create-default-adapters.tssrc/utils/discover-files.tssrc/sources/parsing-utils.tssrc/domain/usage-event.tstests/sources/amp-source-adapter.test.tstests/sources/create-default-adapters.test.tstests/cli/create-cli.test.tsREADME.mdVerification
llm-usage daily --source amp --source-dir amp=<fixture-dir>workspnpm run lintpnpm run typecheckpnpm run testpnpm run format:check