codeburn/tests
Resham Joshi f1a4e8cc4f
fix(cursor): use Cursor's real context tokens for input (#574) (#575)
* fix(cursor): use Cursor's real context tokens for input

Current Cursor builds leave the per-bubble tokenCount at {0,0}, so the provider
fell back to estimating input from visible text plus a second agentKv
content-char pass that double-counted the same conversation. Cursor records its
own tokenizer-accurate context size per conversation in
composerData.promptTokenBreakdown (the number behind the in-app context-window
bar); read that and credit it once per conversation for input instead.

Measured on a real local DB: today's Cursor input went 44,873 -> 168,486 tokens,
matching the sum of per-conversation context. The admin portal still counts
cumulative-per-turn plus cache, which are server-side only, so an opt-in Cursor
API stays the path to exact parity.

Output is a reply-text estimate; agentKv is retained for a tools/bash breakdown
in a follow-up.

* feat(cursor): add tools and bash-command breakdown from agentKv

Cursor logs the agent's tool calls (Read, Grep, Glob, Shell, ...) in agentKv
blobs. Join them to conversations via the turn requestId (carried on the bubble's
$.requestId and inherited positionally by the turn's agentKv rows) and attach each
conversation's tool list and Shell commands to the call that carries its input.

Measured on a real DB: Cursor now reports tools {Read, Grep, Glob, Shell,
SemanticSearch} and the executed shell commands, which were previously empty.

Removes the now-superseded parseAgentKv content-char estimate.

* fix(cursor): price composer-2.5 as Sonnet 4.6

composer-2.5 was missing from the built-in Cursor model aliases, so its usage
showed $0. Map it to claude-sonnet-4-6 like composer-2 (per cursor.com/blog).

* fix(cursor): cache version, model attribution, user message join, tool classification

- Bump CURSOR_CACHE_VERSION to 5: parser semantics changed (parseAgentKv
  removed, real context tokens from composerData.promptTokenBreakdown),
  stale v4 caches would show double-counted agentKv calls.
- Fix model attribution: real input tokens are credited on user bubbles
  (type=1) which carry no modelInfo. Add a pre-pass building composerId ->
  model from assistant bubbles so pricing/display uses the conversation's
  actual model instead of the default cursor-auto/sonnet-4.5.
- Fix buildUserMessageMap: was keying by JSON conversationId (empty in
  current Cursor builds). Now extracts composerId from the bubble key,
  matching parseBubbles.
- Add 'Shell' to BASH_TOOLS in classifier: Cursor's agent uses 'Shell'
  as the tool name, but it was missing from the bash tool set so Cursor
  agent turns with shell commands wouldn't classify as bash/build/test.
- Fix null coalescing in loadComposerInputTokens: r.used ?? r.ctx would
  fall through on a valid totalUsedTokens of 0. Use explicit null check.
- Decouple agentTools attachment from input credit: tools/bash were only
  attached on the first credited turn (creditedHere), silently dropping
  tool usage from subsequent turns in multi-turn conversations.
- Update stale comment about parseAgentKv being kept for a follow-up.
- Add tests for real token crediting, once-per-conversation, fallback,
  contextTokensUsed, tool/bash attribution, and model attribution.

* fix(cursor): avoid duplicating aggregated agent tools

* fix(cursor): price house composer models from Cursor's published rates

composer-1/1.5/2/2.5 were proxied to Claude Sonnet, overcounting cost
(~6x for composer-2/2.5). Use Cursor's published per-model rates instead,
and note in the parser why local reads undercount the admin console.

Co-authored-by: AgentSeal <hello@agentseal.org>

* fix(cursor): estimate non-Composer turn input from the agent stream

Non-Composer sessions (e.g. GPT) record no context-window meter and keep
the prompt in the agent stream, so the user bubble's own text is empty.
Those turns hit the 0/0-token fallback with text_length 0 and were dropped
entirely, so that model's traffic never appeared in the report.

loadAgentToolsByComposer now also sums the user-role stream text length per
conversation, and the meterless fallback estimates input from it (chars/4),
credited once per conversation, when the bubble text is empty. Turns with no
stream text are left untouched, so no phantom tokens are invented.

* fix(cursor): stable conversation crediting, restored stream coverage, and cache invalidation

Review fixes for the real-token accounting:

Conversation input now lands on one composer-anchored record
(cursor:composer-input:<id>) timestamped at composerData.createdAt, so
the credited day no longer depends on the parse window or cache floors,
daily-cache gap fills dedupe instead of multiplying, and each
conversation picks exactly one input source (real bubble tokenCounts,
the context meter, the agent stream, or visible text) so sources can
never stack or double count. A zero totalUsedTokens no longer shadows
contextTokensUsed.

The agent stream regained what the parseAgentKv removal dropped: tool
and system rows count as context, stream-only replies count as output,
and sessions with no bubble join are emitted again (DB mtime timestamp,
as before). Block-array content is measured by its text, not its JSON
envelope. Rows written before their requestId appears buffer forward
instead of inheriting the previous conversation, and a system row closes
the boundary. Tool names canonicalize to Bash and commands go through
extractBashCommands so cross-provider breakdowns merge; the classifier
no longer special-cases Shell (which also reclassified Copilot turns).
User bubbles consume their own queue entry so assistant replies pair
with the right question, and every cursor call is flagged
costIsEstimated.

The requestId and model joins ride the existing budgeted bubble scan
instead of two new unbounded full-table decodes, and the composerData
read seeks the key range. SQLITE_BUSY now propagates to the parser's
retry path instead of caching a silently degraded parse.

Upgrades actually take effect: the session cache gets a cursor parse
version, DAILY_CACHE_VERSION bumps to 10 so finalized days re-hydrate
under the new accounting, the cursor results cache bumps to v6, and the
builtin composer rates participate in the price config hash (rates now
cite cursor.com/docs/models).

Verified against a real Cursor store: all metered conversations match
the on-disk meter exactly, narrow and wide parse windows anchor
identically, repeat runs are byte-identical, and agentKv-only sessions
reappear.

---------

Co-authored-by: ozymandiashh <234437643+ozymandiashh@users.noreply.github.com>
2026-07-02 04:53:07 +02:00
..
fixtures feat(providers): add open-design provider for per-model usage tracking (#559) 2026-06-28 19:17:23 +02:00
providers fix(cursor): use Cursor's real context tokens for input (#574) (#575) 2026-07-02 04:53:07 +02:00
security fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
setup fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
sharing fix: scope cache read/write to the selected period (web + devices CLI) (#583) (#586) 2026-07-01 15:53:44 +02:00
antigravity-statusline.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
audit-report.test.ts feat: add codeburn audit token-source view (#578) 2026-07-01 13:02:29 +02:00
bash-commands.test.ts chore: hoist Pi model sort + cover bash-utils edge cases 2026-04-16 02:02:32 -07:00
blob-to-text.test.ts Merge main into feat/multi-provider-plans, remove dead tautology 2026-05-16 10:42:03 -07:00
classifier.test.ts File-aware retry detection with typed ToolCall (#379) 2026-05-22 01:21:42 -07:00
cli-date.test.ts fix(web): reject invalid dashboard periods without exiting (#554) 2026-06-28 19:35:46 +02:00
cli-deepseek-v4-pricing.test.ts fix: DeepSeek v4 Claude pricing through stale runtime cache (#367) 2026-05-21 00:34:53 -07:00
cli-devin-model-variants.test.ts fix(devin): report friendly GPT model names with effort tier (#585) 2026-07-01 16:01:49 +02:00
cli-export-date-range.test.ts feat(export): support custom date ranges 2026-05-05 23:18:48 -07:00
cli-json-daily.test.ts Add multi-day calendar selection with custom popover UI (#393) 2026-05-24 09:49:59 -07:00
cli-model-savings.test.ts feat(cli): track local-model cost savings against a paid baseline (#421) 2026-06-01 11:06:39 +03:00
cli-plan.test.ts Merge main into feat/multi-provider-plans, remove dead tautology 2026-05-16 10:42:03 -07:00
cli-price-override.test.ts feat(pricing): add user price overrides for models (#390) (#560) 2026-06-28 19:07:29 +02:00
cli-provider-validation.test.ts fix(cli): validate --provider and make non-TTY report deterministic (#501) 2026-06-18 12:39:22 +02:00
cli-proxy-path.test.ts test(cli-proxy-path): raise timeout for spawn-based tests to fix load flake (#504) 2026-06-18 12:57:44 +02:00
cli-status-menubar.test.ts feat(menubar): expose combined multi-device usage in menubar-json (#566) (#567) 2026-06-28 20:59:23 +02:00
codex-credits.test.ts feat(codex): compute Codex credit usage (#408, #495) (#510) 2026-06-18 17:03:46 +02:00
compare-stats.test.ts fix(classifier): surface skill name as subCategory for general turns (#203) 2026-05-04 06:26:45 +08:00
content-utils.test.ts fix(parser): tolerate string message content; isolate per-file parse failures (#441) (#450) 2026-06-06 04:01:12 +02:00
currency-rounding.test.ts Add CNY currency support 2026-06-03 10:45:39 +08:00
daily-cache.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
dashboard.test.ts Merge main into feat/multi-provider-plans, remove dead tautology 2026-05-16 10:42:03 -07:00
date-range-filter.test.ts Add multi-day calendar selection with custom popover UI (#393) 2026-05-24 09:49:59 -07:00
day-aggregator-savings.test.ts feat(cli): track local-model cost savings against a paid baseline (#421) 2026-06-01 11:06:39 +03:00
day-aggregator.test.ts feat(cli): track local-model cost savings against a paid baseline (#421) 2026-06-01 11:06:39 +03:00
export.test.ts feat(export): surface MCP server usage in JSON and CSV exports (#514) 2026-06-18 23:13:48 +02:00
fetch-utils.test.ts fix(network): add timeouts to critical-path fetches (#445) (#448) 2026-06-06 03:25:36 +02:00
fs-utils.test.ts Raise streaming session cap to 4GB so large Codex sessions are counted (#569) 2026-06-26 01:16:56 +02:00
local-model-savings.test.ts feat(cli): track local-model cost savings against a paid baseline (#421) 2026-06-01 11:06:39 +03:00
mcp-coverage.test.ts Add MCP project profile advisor (#356) 2026-05-24 01:57:59 -07:00
mcp-redact.test.ts fix(mcp): harden redaction, error responses, and pre-warm race 2026-06-03 00:56:30 +02:00
mcp-server.test.ts feat(mcp): get_usage + get_savings tools with annotations, schemas, coalescing 2026-06-02 02:16:10 -07:00
mcp-tables.test.ts feat(mcp): markdown table renderers for usage and savings 2026-06-02 02:13:51 -07:00
menubar-installer.test.ts fix(menubar): support installer HTTP proxies (#475) 2026-06-11 14:13:10 +02:00
menubar-json.test.ts fix: scope cache read/write to the selected period (web + devices CLI) (#583) (#586) 2026-07-01 15:53:44 +02:00
menubar-savings.test.ts feat(cli): track local-model cost savings against a paid baseline (#421) 2026-06-01 11:06:39 +03:00
minimax.test.ts feat(pricing): automatic gap-fill from models.dev and OpenRouter (#457) 2026-06-09 21:17:23 +02:00
model-efficiency.test.ts feat(report): add per-model efficiency metrics 2026-05-05 23:36:59 -07:00
models-hoist.test.ts Merge main into feat/multi-provider-plans, remove dead tautology 2026-05-16 10:42:03 -07:00
models-report.test.ts feat(codex): compute Codex credit usage (#408, #495) (#510) 2026-06-18 17:03:46 +02:00
models.test.ts fix(cursor): use Cursor's real context tokens for input (#574) (#575) 2026-07-02 04:53:07 +02:00
optimize-fs.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
optimize.test.ts Add JSON output for optimize and yield 2026-06-18 12:13:17 +02:00
otel-cache-aggregation.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
overview.test.ts Show real Claude project leaf names; stop stray-.git over-grouping (#540) 2026-06-21 22:42:19 +02:00
parser-claude-cwd.test.ts Show real Claude project leaf names; stop stray-.git over-grouping (#540) 2026-06-21 22:42:19 +02:00
parser-compact-entry.test.ts Merge main into feat/multi-provider-plans, remove dead tautology 2026-05-16 10:42:03 -07:00
parser-filter.test.ts test: cover filterProjectsByName include/exclude semantics 2026-04-16 15:49:57 -07:00
parser-gemini-cache.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
parser-large-json-scanner.test.ts Merge main into feat/multi-provider-plans, remove dead tautology 2026-05-16 10:42:03 -07:00
parser-large-session.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
parser-local-savings.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
parser-mcp-inventory.test.ts feat(optimize): MCP tool coverage detector with cache-aware costing 2026-05-05 04:13:04 +03:00
parser-number-helpers.test.ts feat: add devin provider (#444) 2026-06-09 21:58:31 +02:00
parser-proxy-codex-only.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
parser-proxy-merge.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
parser-proxy-pricing.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
parser-skip-line.test.ts Merge main into feat/multi-provider-plans, remove dead tautology 2026-05-16 10:42:03 -07:00
parser-subagent-collection.test.ts feat(report): Claude-scoped agent-type breakdown 2026-06-10 11:45:28 +02:00
parser.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
plan-usage.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
plans.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
pricing-fallback-data.test.ts feat(pricing): automatic gap-fill from models.dev and OpenRouter (#457) 2026-06-09 21:17:23 +02:00
provider-registry.test.ts feat(providers): add open-design provider for per-model usage tracking (#559) 2026-06-28 19:17:23 +02:00
provider-turn-grouping.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
session-cache.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
usage-aggregator.test.ts fix: fix and improve test isolation and collision with environment (#530) 2026-06-20 13:42:10 +02:00
web-dashboard.test.ts fix(web): reject invalid dashboard periods without exiting (#554) 2026-06-28 19:35:46 +02:00
yield.test.ts Add JSON output for optimize and yield 2026-06-18 12:13:17 +02:00