Skip to content

feat(diff): rich side-by-side session comparison - #52

Merged
Siddhant-K-code merged 3 commits into
mainfrom
feat/issue-47-diff-compare
Apr 19, 2026
Merged

Siddhant-K-code merged 3 commits into
mainfrom
feat/issue-47-diff-compare

Conversation

@Siddhant-K-code

Copy link
Copy Markdown
Owner

Closes #47

What

Adds --compare to agent-strace diff — a structured side-by-side table comparing two sessions with a deterministic verdict.

Usage

$ agent-strace diff session-claude-opus session-gpt5 --compare

Session Comparison
─────────────────────────────────────────────────────────────────
                                session-a        session-b
─────────────────────────────────────────────────────────────────
Duration                             4m 32s           6m 18s
Total cost                          $0.3400          $0.5100
Tool calls                               47               63
Redundant reads                           5               12
Context resets                            1                3
Files modified                            6                6  (same)
Errors                                    0                0
─────────────────────────────────────────────────────────────────
Verdict: session-a was 33% cheaper, 28% faster
─────────────────────────────────────────────────────────────────

Changes

src/agent_trace/diff.py

  • CompareReport dataclass: holds all comparison metrics
  • compare_sessions(): computes redundant reads, context resets, files modified, approach divergence, and verdict
  • format_compare(): renders the table
  • _count_redundant_reads(): counts files read more than once per session
  • _count_context_resets(): counts LLM request gaps >120s
  • _build_label(): derives a short display label from session metadata
  • cmd_diff(): routes to compare_sessions when --compare is set

src/agent_trace/cli.py

  • --compare flag on diff subcommand

tests/test_diff_compare.py: 6 tests covering report structure, formatting, redundant read counting, context reset counting, and CLI flag.

Add --compare flag to agent-strace diff. Produces a structured table
comparing two sessions across cost, duration, tool calls, redundant reads,
context resets, files modified, and errors, with a deterministic verdict.

  agent-strace diff <session-a> <session-b> --compare

New metrics:
- Redundant reads: files read more than once in a session
- Context resets: LLM requests separated by >120s gap
- Approach divergence: first N phase pairs where behaviour differs
- Verdict: derived from cost/duration/error comparisons (no LLM)

Closes #47

Co-authored-by: Ona <no-reply@ona.com>
@Siddhant-K-code Siddhant-K-code added the enhancement New feature or request label Apr 19, 2026
Siddhant-K-code and others added 2 commits April 19, 2026 05:04
- format_compare: Duration and Cost rows now show a % change column.
  Previously _row received pre-formatted strings so _pct() never ran;
  now raw numeric values are passed separately for the change calculation.
- format_diff: when sessions share no aligned phases (divergence_index=0
  and phase_diffs is empty), print 'diverge from the start' instead of
  'Diverged at phase 1' which implied a specific phase existed.
- compare_sessions _verdict: remove dead lower_better variable; guard
  division by zero when vb==0 was already present but comment clarified.

Co-authored-by: Ona <no-reply@ona.com>
@Siddhant-K-code
Siddhant-K-code merged commit a5b6719 into main Apr 19, 2026
4 checks passed
@Siddhant-K-code
Siddhant-K-code deleted the feat/issue-47-diff-compare branch April 19, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session comparison: diff two agent sessions side by side

1 participant