fix(reference): Fix line attribution accuracy and add Claude Code model extraction #7
+198
−10
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
This PR fixes two correctness issues in the reference implementation affecting Claude Code trace accuracy:
model_idProblem Details
Issue 1: Line Attribution
Claude Code's
Edittool includes context lines in bothold_stringandnew_string. The previous implementation attributed the entirenew_string, incorrectly claiming ownership of unchanged lines.Before: Adding 1 line →
ranges: [{start_line: 1, end_line: 3}]After: Adding 1 line →
ranges: [{start_line: 2, end_line: 2}]Issue 2: Model Identification
Unlike Cursor, Claude Code does not include
modelin hook payloads. The model must be extracted from the transcript JSONL file atentry.message.model.Solution
trace-store.ts
diffToFindChangedLines()- Compares old/new strings to identify only changed linesextractModelFromTranscript()- Reads model from transcript tail (4KB initial read, doubles if needed)trace-hook.ts
resolveModel()- Transparently resolves model from payload (Cursor) or transcript (Claude Code)PostToolUse,SessionStart,SessionEndhandlersTest Results
Tested with alternating Cursor and Claude Code edits in a sample repository:
All traces correctly captured:
Backward Compatibility
afterFileEditunchanged (uses explicit ranges from payload)old_stringandnew_stringare present