codeburn/docs/providers/cursor-agent.md
Ilia Alshanetsky 4e22a8e09f
fix: count every Cursor Agent assistant message instead of one turn per user message (#1513)
* fix: count every Cursor Agent assistant message instead of one turn per user message

Agentic loops emit dozens of assistant messages per user message and
the parser kept only the first (on one real corpus: 247 of 4,946
messages, ~4% of assistant text). Each message now carries the last
user message forward, tool_use inputs join the output text, and input
tokens use the full user text while the display stays truncated at
500 chars. Parse version bumped so cached sessions re-parse.

* cursor-agent: a transcript that ended before any assistant message is not an unrecognized format

* cursor-agent: bill the user text once per user message, not once per assistant message

* cursor-agent: re-derive finalized days and cached sessions under the new accounting

---------

Co-authored-by: Resham Joshi <65915470+iamtoruk@users.noreply.github.com>
2026-09-24 21:02:00 +02:00

2.3 KiB

Cursor Agent

Cursor's background agent transcripts (separate from the regular chat).

  • Source: src/providers/cursor-agent.ts
  • Loading: lazy (src/providers/index.ts:62-87)
  • Test: tests/providers/cursor-agent.test.ts (243 lines)

Where it reads from

~/.cursor/projects/<projectId>/agent-transcripts/. Inside each project, two layouts coexist:

  1. Legacy: *.txt flat files.
  2. Composer 2: UUID-named subdirectories, each containing JSONL.

Subagents (delegated runs) live in subagents/ subdirectories under the parent (cursor-agent.ts:479-490). They are picked up too.

Storage format

  • Legacy: free-form text transcripts. The parser does line-based heuristic parsing (cursor-agent.ts:219-314).
  • Composer 2: JSONL (cursor-agent.ts:167-217).

Caching

None at the provider level. Conversation metadata is read from the same Cursor SQLite db (state.vscdb), specifically the conversation_summaries table (cursor-agent.ts:46-50). If the summary is missing, file mtime is used as the timestamp.

Deduplication

Per <provider>:<conversationId>:<turnIndex> (cursor-agent.ts:379).

Quirks

  • A file with a UUID-shaped name is treated as the conversation ID directly (cursor-agent.ts:142-143); other names are derived from the parent directory.
  • Token counts are estimated from char count (CHARS_PER_TOKEN = 4, cursor-agent.ts:35, :81-84). The legacy text format never reports real tokens.
  • Every assistant message counts as a turn: agentic loops emit dozens of assistant messages per user message, and each carries the last user message forward. Tool_use inputs are serialized into the output text; input tokens use the full user text, billed once on the first assistant message after it, while the displayed message stays truncated at 500 chars.
  • The text parser is regex-driven and brittle. It is easier to fix a Composer 2 (JSONL) bug than a legacy (text) bug.

When fixing a bug here

  1. Check which format the failing transcript uses before opening a fix.
  2. For text-format bugs, copy the redacted transcript verbatim into tests/fixtures/cursor-agent/ so the regex change can be regression-tested.
  3. If the bug is "wrong project", look at cursor-agent.ts:46-50 and whether a conversation_summaries row exists for the conversation.