-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
The Cursor plugin uses a hybrid token strategy: sessions appear immediately with local estimates (text.length / 4), then get backfilled with accurate data from Cursor's CSV server export. During the gap (which can be minutes depending on cursor.com's processing lag), users see token counts that look authoritative but are actually rough approximations.
Once the plugin-sdk ships metadata?: Record<string, unknown> on SessionUsageData (tokentopapp/plugin-sdk#3) and the core renders it (tokentopapp/tokentop#38), this plugin needs to set the flag so estimated sessions display a ≈ indicator.
Proposed solution
Set metadata: { isEstimated: true } on SessionUsageData rows that haven't been enriched by CSV data, and omit it (or set false) on enriched rows.
Changes required
1. src/csv.ts — Set metadata in enrichWithCsvData()
The enrichWithCsvData() function (lines ~196-299) has three code paths that return SessionUsageData rows. Each needs the appropriate metadata:
// Path 1: Enriched from fresh CSV match (lines ~251-273)
// → metadata: { isEstimated: false } (or omit metadata entirely)
// Path 2: Enriched from sessionEnrichmentCache (lines ~291-296, applyCachedEnrichmentToRow)
// → metadata: { isEstimated: false } (cached enrichment is still accurate)
// Path 3: No CSV match, no cached enrichment — returned as-is (line ~253)
// → metadata: { isEstimated: true }2. src/parser.ts — Ensure metadata propagates through session building
The parseSessionsFromWorkspaces() function builds SessionUsageData[] rows (lines ~182-353). The initial rows (before enrichment) should all have metadata: { isEstimated: true } since they use local token estimation. After enrichWithCsvData() runs, enriched rows get their metadata updated to { isEstimated: false }.
Simplest approach: set isEstimated: true as default on all rows in the bubble-to-SessionUsageData mapping, then let enrichWithCsvData() override it on enriched rows.
Behavior
| Scenario | metadata.isEstimated |
UI shows |
|---|---|---|
| New session, no CSV data yet | true |
≈ prefix on token count |
| Session after CSV enrichment | false / omitted |
Normal token count |
| App restart, enrichment cache hydrated | false / omitted |
Normal token count |
| CSV enrichment disabled in settings | true |
≈ prefix (estimates only) |
Alternatives considered
None — this is the plugin-side implementation of the cross-repo metadata feature. The SDK type and core rendering are tracked separately.
Additional context
Depends on:
- [Feature]: Add optional metadata field to SessionUsageData plugin-sdk#3 —
metadatafield onSessionUsageData - [Feature]: Display estimated/enriched indicator for agent sessions tokentop#38 — Core propagation + UI rendering
Key files:
src/csv.ts:196—enrichWithCsvData()— three return paths need metadatasrc/csv.ts:314—applyCachedEnrichmentToRow()— cached enrichment pathsrc/parser.ts:182—parseSessionsFromWorkspaces()— session row constructionsrc/parser.ts:327— CSV enrichment call site