Skip to content

[Feature]: Add optional metadata field to SessionUsageData #3

@nigel-dev

Description

@nigel-dev

Problem

Agent plugins that enrich token data from external sources (e.g. Cursor's CSV server export) have no way to signal to the core UI whether a session's data is estimated (local heuristic) or enriched (server-verified). The core renders all sessions identically, so users can't tell which token counts are approximate and which are accurate.

This came up building @tokentop/agent-cursor: sessions appear immediately with estimated tokens (text.length / 4), then get backfilled with accurate data from Cursor's server. During the gap, there's no visual distinction.

Proposed solution

Add an optional metadata field to SessionUsageData:

export interface SessionUsageData {
  // ... existing fields ...

  /**
   * Optional plugin-defined metadata passed through to the core.
   * Plugins can use this to signal data quality, enrichment status,
   * or other plugin-specific information the UI may choose to render.
   *
   * Known keys (convention, not enforced):
   *   - `isEstimated` (boolean) — true when token counts are local estimates
   */
  metadata?: Record<string, unknown>;
}

This is a non-breaking, additive change. Existing plugins that don't set metadata are unaffected. The core decides how (or whether) to render metadata — plugins just expose the data.

Alternatives considered

  • Prefix sessionName with a marker (e.g. "≈ Session Name") — hacky, mixes display concerns into data
  • Use absence of cacheRead/cacheWrite as implicit signal — fragile, breaks for sessions that genuinely have no cache usage
  • Add a dedicated isEstimated boolean — too narrow; metadata bag is more extensible for future plugin needs

Area

Type definitions

Scope

Small (config, tweak, single type)

Additional context

Downstream issues:

  • ttop: Propagate metadata through AgentSessionAggregate and render an indicator in SessionsTable (separate issue)
  • agent-cursor: Set metadata.isEstimated in enrichWithCsvData() (will be implemented once SDK ships the type)

Implementation is ~3 lines in src/types/agent.ts. No runtime behavior change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions