Skip to content

feat(source): add Augment Code adapter #66

@ayagmar

Description

@ayagmar

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

  1. Adapter file

    • add src/sources/augment/augment-source-adapter.ts
    • implement SourceAdapter with id = 'augment'
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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

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