fix(trace): record the net code changes of a session

Merged
JI
2d ago
+317-39

Fixes #3674.

chainloop trace recorded the code changes of a session as the sum of the diff of each session commit. When two or more session commits changed the same file, the line counts were too high, and a file that the session created had the status modified.

This change makes the code changes of a session net. It uses the same blame approach as the AI and human split, so the codebase has one definition of a net count:

  • The added and removed lines of each file are the sum of its AI and human lines. So ai_lines_added + human_lines_added is equal to lines_added, and the session totals are the sum of the files.
  • A session commit does not count a removed line that another commit of the session wrote. The blame of the parent commit finds these lines. The CLI blames the parent only for a file that two or more session commits changed.
  • A file that a session commit created keeps the status created when a later session commit changes it. If a later commit deletes the file, the status is deleted.

The set of session commits still selects the files and lines of the session, so commits that are not contiguous on the branch still work.

Behavior changes:

  • In spec issue-3639, Appendix case 3, the replaced line of the session no longer counts as a human removal. The spec gives "AI removed 0" for this case and does not state the human removals.
  • In a commit that two sessions share, a line that the ledger of the other session claims no longer counts in the lines_added of this session. Before this change, that line was in lines_added but in neither the AI count nor the human count.

AI disclosure: Claude Code assisted with this change.