Objective
Add an augment source adapter for local Augment Code session files so Augment usage can flow through the existing reporting pipeline without introducing any auth or editor-integration logic.
Why this looks implementable
The local data under ~/.augment/ appears to contain a parseable session format already:
- session files live under
~/.augment/sessions/*.json
- each session has top-level metadata such as
sessionId, created, modified, and agentState.modelId
chatHistory[] contains exchanges with request_nodes and response_nodes
- per-turn usage signal appears on
response_nodes entries with type: 10 and a populated token_usage
- repo / cwd attribution appears in
request_nodes entries with ide_state_node.current_terminal.current_working_directory and workspace_folders[].repository_root
- provider can appear in sibling response metadata (for example
metadata.provider on nearby response nodes)
That is enough to support a first local adapter behind the current SourceAdapter boundary.
Source shape to support
- directory-backed source under
~/.augment/sessions/*.json
- one JSON file per session
- each exchange can contain multiple response nodes, but usage should be emitted only from the token-usage node(s)
- model is available at session level via
agentState.modelId
- explicit cost does not appear to be present in the session files, so cost should stay estimated unless a better local source is identified later
Implementation plan
-
Adapter file
- add
src/sources/augment/augment-source-adapter.ts
- implement
SourceAdapter with id = 'augment'
-
Discovery
- discover only
~/.augment/sessions/*.json
- keep this source directory-backed and selectable through generic
--source-dir augment=...
- validate explicit directory overrides consistently with the existing directory-backed adapters
-
Parsing
- parse one session JSON file at a time
- iterate
chatHistory[] exchanges and emit usage events from the response node that carries token_usage
- use the token-usage node timestamp (
timestamp_ms) as the event timestamp, with fallback to top-level session timestamps when required
- resolve model from
agentState.modelId
- resolve provider from sibling response metadata when present; otherwise leave it unset or map conservatively from the model only if the data is clearly reliable
- resolve repo attribution from request-side IDE state, preferring:
ide_state_node.current_terminal.current_working_directory
- then
workspace_folders[].repository_root
- map local usage buckets carefully into
createUsageEvent
input_tokens
output_tokens
cache_read_input_tokens
cache_creation_input_tokens
- do not invent explicit cost from auth/session files
- ignore non-usage response nodes (
thinking, final text nodes, tool-use nodes) and malformed exchanges without aborting the whole file
- use
parseFileWithDiagnostics() so malformed files / invalid timestamps can surface skipped-row reasons
-
Token semantics follow-up to settle during implementation
- the local
token_usage object also includes fields such as:
system_prompt_tokens
chat_history_tokens
current_message_tokens
tool_definitions_tokens
tool_result_tokens
assistant_response_tokens
- decide and document whether these should remain informational-only or contribute to canonical billable buckets / total tokens
- keep the first implementation simple and deterministic; if some counters are overlapping views rather than additive buckets, avoid double counting
-
Wiring
- register
augment in src/sources/create-default-adapters.ts
- update supported-source IDs and stable-order tests/help output
- keep the source on generic
--source-dir support; no bespoke flag needed
-
Tests and docs
- add
tests/sources/augment-source-adapter.test.ts
- update shared registry/help tests in:
tests/sources/create-default-adapters.test.ts
tests/cli/create-cli.test.ts
- update
README.md if the source is added to the supported-source list
Code paths to touch
src/sources/augment/augment-source-adapter.ts
src/sources/create-default-adapters.ts
src/sources/parsing-utils.ts
src/sources/parse-diagnostics.ts
src/utils/discover-files.ts
src/domain/usage-event.ts
tests/sources/augment-source-adapter.test.ts
tests/sources/create-default-adapters.test.ts
tests/cli/create-cli.test.ts
README.md
Verification
- parser fixtures cover:
- session-level model extraction
- per-exchange token-usage extraction
- repo-root / cwd extraction from IDE-state request nodes
- provider extraction from sibling response metadata when present
- invalid/missing timestamps and malformed exchanges surfaced via diagnostics
- non-usage nodes ignored without creating duplicate events
- stable handling of the extra prompt/context counters without double counting
llm-usage daily --source augment --source-dir augment=<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
augmentsource adapter for local Augment Code session files so Augment usage can flow through the existing reporting pipeline without introducing any auth or editor-integration logic.Why this looks implementable
The local data under
~/.augment/appears to contain a parseable session format already:~/.augment/sessions/*.jsonsessionId,created,modified, andagentState.modelIdchatHistory[]contains exchanges withrequest_nodesandresponse_nodesresponse_nodesentries withtype: 10and a populatedtoken_usagerequest_nodesentries withide_state_node.current_terminal.current_working_directoryandworkspace_folders[].repository_rootmetadata.provideron nearby response nodes)That is enough to support a first local adapter behind the current
SourceAdapterboundary.Source shape to support
~/.augment/sessions/*.jsonagentState.modelIdImplementation plan
Adapter file
src/sources/augment/augment-source-adapter.tsSourceAdapterwithid = 'augment'Discovery
~/.augment/sessions/*.json--source-dir augment=...Parsing
chatHistory[]exchanges and emit usage events from the response node that carriestoken_usagetimestamp_ms) as the event timestamp, with fallback to top-level session timestamps when requiredagentState.modelIdide_state_node.current_terminal.current_working_directoryworkspace_folders[].repository_rootcreateUsageEventinput_tokensoutput_tokenscache_read_input_tokenscache_creation_input_tokensthinking, final text nodes, tool-use nodes) and malformed exchanges without aborting the whole fileparseFileWithDiagnostics()so malformed files / invalid timestamps can surface skipped-row reasonsToken semantics follow-up to settle during implementation
token_usageobject also includes fields such as:system_prompt_tokenschat_history_tokenscurrent_message_tokenstool_definitions_tokenstool_result_tokensassistant_response_tokensWiring
augmentinsrc/sources/create-default-adapters.ts--source-dirsupport; no bespoke flag neededTests and docs
tests/sources/augment-source-adapter.test.tstests/sources/create-default-adapters.test.tstests/cli/create-cli.test.tsREADME.mdif the source is added to the supported-source listCode paths to touch
src/sources/augment/augment-source-adapter.tssrc/sources/create-default-adapters.tssrc/sources/parsing-utils.tssrc/sources/parse-diagnostics.tssrc/utils/discover-files.tssrc/domain/usage-event.tstests/sources/augment-source-adapter.test.tstests/sources/create-default-adapters.test.tstests/cli/create-cli.test.tsREADME.mdVerification
llm-usage daily --source augment --source-dir augment=<fixture-dir>workspnpm run lintpnpm run typecheckpnpm run testpnpm run format:check