Audit date: 2026-09-12 (Asia/Seoul)
Scope: Cursor, Grok Build, normalized token usage, reported/API-equivalent cost, USD/KRW FX, account aggregation, storage, API/UI integration, and tests.
QuotaDeck is a Python 3.11+ desktop/CLI application. Account discovery produces AccountRef objects, quota providers return UsageSnapshot/UsageWindow, and the separate quotadeck.usage package scans cumulative token observations into UsageDataset and UsageReport. CumulativeUsageService adapts the cumulative report into CumulativeSnapshot for the GUI, CLI, renderer, scheduler, and F108 LCD output.
The cumulative pipeline is currently:
AccountRef
-> provider-specific collector/import/local history
-> UsageObservation(TokenUsage)
-> UsageDataset (dedupe + coverage)
-> UsageReport (daily/monthly/model aggregation)
-> optional list-price estimate
-> CumulativeSnapshot
-> CLI / GUI / renderer
Quota and cumulative usage are separate at the top-level through MetricMode.QUOTA and MetricMode.CUMULATIVE. Quota code lives primarily under quotadeck.providers; token history, analytics, and pricing live under quotadeck.usage. This separation is sound and should be preserved.
There is no application usage database or migration layer. Transcript-derived datasets are retained only in a bounded in-memory TTL cache. Provider CLI/application history and token-stats cache files are the durable sources. App preferences and account aliases are stored in %APPDATA%/QuotaDeck/config.json; account entries store identifiers and source paths, not secrets.
| Provider | Quota/rate limit | Token usage | Cost |
|---|---|---|---|
| Codex | OAuth endpoint with app-server fallback; API-key quota is unavailable | Native retained JSONL, optional token-stats, ccusage fallback | Static official API list-price catalog, gated to explicit API billing |
| Claude | Official usage endpoint for supported OAuth accounts | Native retained JSONL, optional token-stats, ccusage fallback | Static official API list-price catalog, gated to explicit API billing |
| Cursor | usage-summary, then DashboardService fallback, authenticated by existing Cursor session |
Attributable CSV/JSON/token-stats cache import only | Base-model catalog exists, but the cumulative service normally treats subscriptions as unpriced |
| Grok Build | Billing/quota endpoint for stored Grok session; API-key quota unavailable | Strict grok usage <session-id> parser and external OTel adapter exist, but the application service does not load them |
Catalog entries and costUsdTicks parsing exist, but no normalized reported-cost output reaches the UI/API |
grok.com consumer Web Chat is not a supported cumulative source and must remain explicitly unsupported unless xAI provides an official export/API.
TokenUsagekeeps uncached input, cached input, cache writes, output, and reasoning-output metadata distinct; reasoning is not double-counted in totals.- Quota percentages and cumulative token counts use different contracts and different display modes.
- Local parsers are bounded, deduplicate stable events, reject malformed/oversized inputs, and avoid retaining prompt/response bodies.
- Cursor
state.vscdbis used only to discover authentication/quota context; itstokenCountis not treated as a token ledger. - Cursor export parsing requires account attribution and a real date/timestamp.
- Grok's official usage JSON has a strict parser with inclusive-input normalization, model/turn consistency checks, and
costUsdTickssupport. The existing fixture/parser nevertheless predates parts of the current official envelope: current source usesendedAt,primaryModelId,costIsPartial, andusageIsIncomplete; the project fixture'spromptIdis not an authoritative identifier. - External commands use
shell=False, bounded output/time, a reduced child environment, discarded stderr, and generic failure messages. - Pricing uses
Decimal, dated source URLs, provider/model normalization, cache-specific rates, and all-or-nothing validation. - Account discovery already supports separate Cursor IDE/CLI sessions and stable provider/account keys.
- UI rendering already supports USD and KRW presentation and keeps model detail outside the small LCD surface.
- Cursor does not initiate the token-stats
cursor syncflow. It only reads an already-created cache/import, so normal authenticated users receiveunsupporteduntil they manually prepare files. The currently documented token-stats JSON report is also undated; the authoritative integration artifact for calendar totals is its synced CSV cache. - The Cursor CSV reader does not recognize the current token-stats v1-v3 export headers (
Input (w/ Cache Write),Input (w/o Cache Write),Cache Read,Output Tokens). It also refuses the normal active-accountusage.csv, so even a successful upstream sync is usually unusable. - Cursor cache discovery does not expose a complete first-class multi-account inventory/aggregate contract. The active compatibility file (
usage.csv) can overlap named account caches and needs explicit deduplication/ownership rules. - Cursor credentials are read from local Cursor state for quota calls, while token-stats keeps separately supplied web-session credentials. QuotaDeck has no secure credential-store abstraction for credentials it owns; therefore it must not import/copy token-stats credentials.
- Grok session discovery and official-command parsing are disconnected from
UsageService;CumulativeUsageService.snapshot()unconditionally rejects Grok. - The current Grok scan intentionally emits no observations, so parsed token totals and reported cost cannot reach normalized per-session/provider totals.
- No incremental on-disk Grok cache exists; every scan invokes the CLI for every discovered session. Official command output is pretty JSON and
grok usage <session-id> <turn>is also supported. UsageObservationhas noaccount_id, turn identifier, optional reported cost, or explicit nullable unknown fields. Account scope exists outside the record and is therefore hard to aggregate safely.costUsdTicksis parsed but not exposed asreported_cost_usd; reported and API-equivalent cost do not share a public normalized result.- API-equivalent cost is incorrectly gated to explicitly API-billed history in the display service. That prevents showing the requested hypothetical equivalent for subscription usage, even though it is not reported spend.
- KRW conversion is a manually entered scalar only. There is no fetched rate, source/as-of metadata, last-known-good cache, staleness rule, or fallback chain.
- No persistent usage/history schema exists. This avoids secret leakage but also prevents incremental source cursors, last-known FX, and durable deduplication.
- Collector and UI contracts are coupled through
CumulativeSnapshot; there is no provider/account/global aggregate API independent of the LCD view. - Baseline test run with an isolated temp directory: 361 passed, 1 skipped, 16 failed. Most failures are caused by missing Windows
tzdata(not declared in dependencies). One Cursor test depends on the wall-clock date and changed behavior after midnight. The default pytest temp/cache roots on this host also have unrelated ACL errors.
- Live token-stats Cursor synchronization using its authenticated session and account-specific cache files.
- Safe Cursor multi-account inventory, per-account totals, provider total, and global total.
- Grok official CLI collection wired into the application, with version/capability detection and documented fallback order.
- Incremental Grok session cache keyed by session identity and source modification state.
- A normalized record that carries account, provider, model, timestamp/date, session/turn, nullable token categories, reported cost, and source provenance without credentials.
- Separate
reported_cost_usd,api_equivalent_cost_usd, andapi_equivalent_cost_krwsemantics. - FX rate acquisition with source, quote time/date, staleness, last-known-good persistence, and manual fallback.
- Machine-readable provider/account/global aggregation independent of the existing display snapshot.
- Fixtures for Grok tick conversion and official JSON envelopes, Cursor named-account cache behavior, cost separation, and FX fallback.
TokenUsage,UsageObservation,UsageCoverage,UsageDataset, and analytics aggregation.CollectorSettings,CollectorAttempt, strict mapping/parsing helpers, and bounded subprocess execution.- Cursor authentication discovery and quota clients, provided secrets remain
repr=Falseand are never serialized. - Cursor CSV/JSON and token-stats payload parsers.
- Grok usage envelope/summary/turn parser and safe session-ID discovery.
- Provider-aware pricing catalog, exact
Decimalarithmetic, and model alias resolution. - Account configuration/discovery and current GUI/CLI/renderer period/currency controls.
- Existing masking, diagnostics exclusion, and generic error reporting policies.
- Extend the normalized usage contract compatibly with account/session/turn identity and nullable reported cost. Preserve
TokenUsagearithmetic for known counters and never fabricate unavailable categories. - Add a service-level aggregate result for per-account, per-provider, and global totals. Do not overload quota
UsageSnapshot. - Add a Cursor sync adapter that calls the installed/configured token-stats executable, reads only its normalized cache/export, keeps named accounts isolated, and never reads or copies its credential file. Parse current CSV headers by name: uncached input is
Input (w/o Cache Write)and cache-write is the non-negative difference fromInput (w/ Cache Write). - Connect Grok discovery/parser to
UsageService; add a bounded incremental cache and explicitly label session-derived coverage limitations. Prefer the officialgrok usagecommand; add structured-headless and source-verified JSONL fallback only when their schemas are proven. - Split reported cost from hypothetical API-equivalent cost. API-equivalent estimates may be shown for subscription records when token/model/category coverage is complete; they must never be labeled as actual spend.
- Add an FX service and cache whose values carry rate, source, fetched/as-of time, and stale/fallback status. No API key or credential may enter config/history/logs.
- Keep the existing LCD adapter as a consumer of the normalized engine instead of embedding provider collection decisions in the renderer.
- Add
tzdatafor portable named-zone behavior on Windows and eliminate tests that depend on the current wall-clock date.
- Independently verify token-stats Cursor behavior, xAI Grok Build schemas/commands, pricing sources, and FX providers against current primary/source-level references.
- Implement normalized nullable cost/account metadata and aggregate APIs without breaking existing callers.
- Implement Cursor token-stats sync/cache ingestion and multi-account aggregation; keep current import support as a deterministic fallback.
- Implement Grok official CLI collection with incremental cache and strict conversion fixtures; expose session/account/provider results only at the granularity the source proves.
- Implement API-equivalent pricing independently of billing mode and retain a separate provider-reported cost field.
- Implement automatic USD/KRW lookup with last-known-good and manual fallback, plus source/as-of metadata.
- Wire provider results into
UsageService, the compatibility snapshot, CLI, and GUI labels while preserving quota mode. - Update security/provider/collector documentation and add focused fixtures/tests.
- Unit-test every nullable token/cost field and ensure unknown never becomes zero.
- Verify Cursor
state.vscdbtoken counters are never consulted and credentials never appear inrepr, output, cache, exceptions, or history. - Simulate token-stats sync success, missing executable, timeout, invalid JSON, named accounts, active
usage.csvoverlap, and stale cache fallback. - Validate Grok discovery, option-safe session IDs, official CLI precedence, command timeout/output bounds, unchanged-session cache hits, changed-session refresh, and fallback ordering.
- Fixture-test
costUsdTicks / 10^10with exactDecimalvalues and reject negative/non-integral/overflow inputs. - Test reported-cost and API-equivalent-cost independence for API and subscription accounts.
- Test pricing for every catalog row, unknown model/category refusal, aliases, cache rates, and exact rounding.
- Test live FX success, malformed response, timeout, stale/fresh last-known-good cache, and manual fallback; assert source/as-of metadata.
- Test per-account, provider-total, and global-total aggregation without double counting.
- Run focused usage/pricing/FX/provider tests, then the full pytest suite using a workspace-local basetemp and disabled pytest cache on this Windows host.
- Perform a credential-pattern scan and
git diff --checkbefore handoff.
The planned refactoring is now present in the working tree. cursor_export.py
parses token-stats dashboard CSV v1-v3, performs exclusive input/cache-write
normalization, supports named-account isolation, and optionally invokes the
bounded token-stats cursor sync --json adapter. grok.py invokes only the
official grok usage <session-id> command, caches credential-free results by
session/source fingerprint, converts positive costUsdTicks using 10^10 ticks
per USD, and exposes explicit unsupported coverage for grok.com Web Chat.
normalized.py and engine.py provide nullable provider-neutral records plus
account, provider, and global rollups. reported_cost_usd is never reused as
API spend; estimate_api_equivalent_cost is independent of subscription/API
billing mode and KRW conversion carries FX provenance and fallback metadata.
The machine-readable contract is available through quotadeck usage-engine --json.
The JSON and text outputs keep freshness separate from completeness: a retained
Admin dataset can remain confidence=exact while a separate stale issue carries
the account and refresh reason.
Focused usage/pricing/FX tests pass (108 tests); the full suite passes 416 tests with one pre-existing skip. Live authenticated Cursor token-stats and Grok CLI sessions were not available in this environment, so end-to-end provider calls remain source/fixture verified rather than credential-tested.
- Cursor token export implementation: https://github.com/Annihilater/token-stats
- Cursor documented team/admin usage API: https://cursor.com/docs/account/teams/admin-api
- Grok Build CLI source and usage command: https://github.com/xai-org/grok-build
- xAI API pricing catalog: https://docs.x.ai/developers/pricing
- Treasury reporting exchange-rate dataset: https://fiscaldata.treasury.gov/currency-exchange-rates-converter/