Read Cursor tokens and line changes from modern state schema#1503
Closed
1chooo wants to merge 5 commits into
Closed
Read Cursor tokens and line changes from modern state schema#15031chooo wants to merge 5 commits into
1chooo wants to merge 5 commits into
Conversation
Recent Cursor versions stopped writing per-bubble tokenCount/usage values (only zero placeholders remain) and no longer include streamingContent in edit_file_v2 params (noCodeblock=true), so AI token counts and line changes were always zero. Read the cumulative context window usage from contextWindowStatusAtCreation.tokensUsed on user bubbles as input token counter, and compute line changes by diffing the before/after file snapshots referenced by beforeContentId and afterContentId in edit tool results. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
|
Can't merge, this breaks several things:
|
Use source-aware token handling, bounded snapshot line counting, and a Cursor-specific checkpoint so schema drift degrades safely without misreporting usage or losing recoverable activity. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
Hi @alanhamlett can you please approve the ci/cd? |
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## develop #1503 +/- ##
===========================================
- Coverage 89.69% 89.64% -0.06%
===========================================
Files 417 417
Lines 20809 21079 +270
===========================================
+ Hits 18665 18896 +231
- Misses 1301 1324 +23
- Partials 843 859 +16
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Exercise malformed schema rows, checkpoint failures, edit-source fallbacks, and SQLite error paths so the stabilization behavior remains protected and patch coverage stays merge-ready. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
@alanhamlett just make a new push for fixing codecov |
Contributor
Author
|
@alanhamlett can you check with this fix because Cursor right now can not count AI usage anymore... |
alanhamlett
requested changes
Jul 15, 2026
| minAIHeartbeatTime, maxAIHeartbeatTime := minMaxAIHeartbeatTimes(heartbeats) | ||
|
|
||
| parsedAt := heartbeatTime(maxAIHeartbeatTime) | ||
| if parsedAt.Before(lastParsedAt) { |
Member
There was a problem hiding this comment.
Agent specific code doesn't belong in the ai.go file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
contextWindowStatusAtCreation.tokensUsed) on Cursor user bubbles as a cumulative input token counter, reusing the existing monotonic delta logicbeforeContentId/afterContentIdinedit_file_v2/edit_filetool results (stored undercomposer.content.<hash>keys), used whenstreamingContent/code_editis absent$.contextWindowStatusAtCreationand$.modelInforows in the SQLite query filtertokenCountplaceholders,noCodeblockedit params, content snapshot blobs)Root Cause
Recent Cursor versions (1.7.x) stopped persisting per-bubble token data entirely: every
bubbleId:row now carries a{"inputTokens":0,"outputTokens":0}placeholder and nousageobjects exist anywhere instate.vscdb, so #1496/#1499 could no longer recover tokens — the data source moved. Likewiseedit_file_v2params no longer includestreamingContent("noCodeblock":true), so AI line changes were always zero. The remaining local signals are the cumulative context window token usage on user bubbles and the before/after file content snapshots referenced by edit tool results.Note: Cursor no longer persists output token counts locally, so only input/context tokens can be reported for now.
Validation
go test ./pkg/ai -count=1state.vscdb: previouslyinputTokens=0 lineChanges=0across 254 heartbeats in 24h; with this changeinputTokens=462037 lineChanges=800Fixes wakatime/vscode-wakatime#489.
🤖 Generated with Claude Code