Skip to content

feat(cursor): capture session metrics (duration, turns, model, attrib…#613

Merged
Soph merged 1 commit intomainfrom
cursor-session-metrics
Mar 5, 2026
Merged

feat(cursor): capture session metrics (duration, turns, model, attrib…#613
Soph merged 1 commit intomainfrom
cursor-session-metrics

Conversation

@peyton-alt
Copy link
Contributor

…ution) via hooks

Copilot AI review requested due to automatic review settings March 5, 2026 01:22
@cursor
Copy link

cursor bot commented Mar 5, 2026

PR Summary

Medium Risk
Touches core lifecycle/state persistence and checkpoint metadata schemas; mistakes could lead to incorrect session metrics or missing file-change attribution, but the changes are additive and covered by updated tests.

Overview
Adds hook-level session metrics capture for Cursor (turn count, session duration, and compaction context usage) and persists them through the lifecycle pipeline into session state and committed checkpoint metadata via the new SessionMetrics field.

Extends subagent completion handling to accept modified_files directly from Cursor hook payloads (and merge with transcript-based extraction), and tweaks Cursor transcript analysis to return the current transcript position even when no modified files can be derived.

Written by Cursor Bugbot for commit e0b458d. Configure here.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds session metrics capture (duration, turn count, context tokens, context window size) from Cursor's lifecycle hooks and passes them through to the checkpoint metadata. It also adds support for hook-provided modified_files on subagent-stop events, improving file change detection for Cursor subagents.

Changes:

  • Adds new fields to agent.Event, session.State, and checkpoint.SessionMetrics to carry hook-provided session metrics (duration, turns, context usage) through the data pipeline
  • Updates persistEventMetadataToState to persist metrics from events to session state, including self-counting turn logic for agents that don't report turn counts
  • Updates ExtractModifiedFilesFromOffset for Cursor to return transcript position (instead of always 0), and merges hook-provided modified_files with transcript-extracted files for subagent-end handling

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cmd/entire/cli/agent/event.go Adds ModifiedFiles, DurationMs, TurnCount, ContextTokens, ContextWindowSize fields to Event struct
cmd/entire/cli/agent/cursor/lifecycle.go Parses loop_count, duration_ms, context_tokens, context_window_size, and modified_files from Cursor hook payloads into Event fields
cmd/entire/cli/agent/cursor/lifecycle_test.go Adds test assertions for modified_files on SubagentEnd events
cmd/entire/cli/agent/cursor/transcript.go Updates ExtractModifiedFilesFromOffset to return actual transcript position via GetTranscriptPosition
cmd/entire/cli/agent/cursor/transcript_test.go Adds test for nonexistent file and fixes position assertion for existing test
cmd/entire/cli/agent/cursor/hooks.go Minor whitespace cleanup
cmd/entire/cli/session/state.go Adds SessionDurationMs, SessionTurnCount, ContextTokens, ContextWindowSize fields to session state
cmd/entire/cli/lifecycle.go Extends persistEventMetadataToState with metric persistence, adds event param to markSessionEnded, merges hook-provided ModifiedFiles in subagent-end handling
cmd/entire/cli/phase_wiring_test.go Updates markSessionEnded calls with new nil event parameter
cmd/entire/cli/checkpoint/checkpoint.go Defines SessionMetrics struct and adds it to WriteCommittedOptions and CommittedMetadata
cmd/entire/cli/checkpoint/committed.go Passes SessionMetrics through to committed checkpoint metadata
cmd/entire/cli/strategy/manual_commit_condensation.go Adds buildSessionMetrics helper to construct SessionMetrics from session state

@peyton-alt peyton-alt force-pushed the cursor-session-metrics branch 3 times, most recently from 69cb2e7 to e0b458d Compare March 5, 2026 05:24
@peyton-alt peyton-alt marked this pull request as ready for review March 5, 2026 05:31
@peyton-alt peyton-alt requested a review from a team as a code owner March 5, 2026 05:31
@peyton-alt
Copy link
Contributor Author

@cursor review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@peyton-alt peyton-alt force-pushed the cursor-session-metrics branch from e0b458d to e3d19aa Compare March 5, 2026 05:37
@Soph Soph merged commit 5893a0c into main Mar 5, 2026
3 checks passed
@Soph Soph deleted the cursor-session-metrics branch March 5, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants