Skip to main content

Module diff_align

Module diff_align 

Source
Expand description

Session-to-session alignment. Pure-algorithm module with no TUI dependencies — all rendering lives in diff_tui.rs. Kept separate so the alignment logic can be unit-tested cleanly and reused for non-TUI diff modes later.

Algorithm: longest common subsequence (LCS) over a “structural signature” that ignores per-step content. Steps are considered equal for alignment purposes when they share the same StepKind and, for tool-related steps, the same tool_name. Content equality (text, tool input, tool output) is computed separately per aligned pair so the TUI can color rows by “match vs input-differs vs only-one-side”.

Why LCS over (kind, tool_name): real agent sessions that do “the same thing” often insert extra tool calls or assistant messages on one side. Position-based alignment fails immediately. Content-based alignment over-matches on boilerplate. Structural alignment gets you “the agents performed the same tool call sequence” which is the signal worth surfacing.

Complexity: O(N * M) time and space on the DP table. For typical session sizes (< 2000 steps) that’s trivial. Hunt-Szymanski or Myers would be needed if corpora push into the 10k+ range per session; not in scope yet.

Structs§

AlignRow
One row of the two-pane diff rendering. Exactly one of left / right is always populated for LeftOnly / RightOnly; both for Match / Differ.

Enums§

AlignKind
How an aligned row relates its left / right halves. The TUI maps these to foreground colors.

Functions§

align
Align two step sequences. Returns a sequence of rows suitable for rendering in a two-pane TUI. Rows are emitted in a consistent “walk both sides together” order so that row N on screen corresponds to row N in the timeline on both sides (with gaps shown as gray gutters).