Skip to content

fix(pretty): prefer details.patch over details.diff for edit tool rendering - #1

Open
iamxeph wants to merge 1 commit into
pifydev:mainfrom
iamxeph:fix/support-pi-edit-diff
Open

iamxeph wants to merge 1 commit into
pifydev:mainfrom
iamxeph:fix/support-pi-edit-diff

Conversation

@iamxeph

@iamxeph iamxeph commented Sep 27, 2026

Copy link
Copy Markdown

Problem

When diffSplit: true is enabled, the edit tool diff never renders in side-by-side mode and silently falls back to a unified diff. Similarly, word-level diff emphasis and line-number gutters fail to activate for edit results, degrading to plain line-colored output.

Root Cause

In pi's core edit tool (packages/coding-agent/src/core/tools/edit.ts), EditToolDetails explicitly provides two diff representations:

export interface EditToolDetails {
	/** Display-oriented diff of the changes made */
	diff: string;
	/** Standard unified patch of the changes made */
	patch: string;
	firstChangedLine?: number;
}

When executing an edit:

const diffResult = generateDiffString(baseContent, newContent);
const patch = generateUnifiedPatch(path, baseContent, newContent);
return {
	content: [...],
	details: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },
};

extensions/pretty.ts previously read only result.details.diff (the display-oriented diff which lacks @@ hunk headers). Because details.diff does not contain @@ hunk headers, the inHunk state in both src/split.ts (parseRows) and src/diff.ts remained false across all lines. Consequently:

  • buildSplit treated every line as an unparsed full row, failing to split into columns.
  • colorizeDiff skipped paired word-diff analysis and line-number gutter formatting.

Solution

  • Added extractEditDiff(result) in extensions/pretty.ts to prefer details.patch when available, falling back to details.diff.
  • With details.patch (the standard unified patch) consumed, buildSplit and colorizeDiff receive the expected hunk headers, allowing side-by-side split rendering, word-level emphasis, and line gutters to work as originally designed without altering any core parser logic.

Verification

  • Added integration tests in test/wire.test.ts:
    • edit result prefers details.patch over details.diff (verifies split view separator │ is present when diffSplit is on)
    • edit result falls back to details.diff when details.patch is absent
  • Ran bun run typecheck: clean (0 errors).
  • Ran bun test: all 124 tests passed (0 failed).
  • Verified interactively in pi: side-by-side split diff and word-level emphasis render cleanly.

…dering

pi's edit tool result details provides both `patch` (standard unified diff with
hunk headers) and `diff` (pre-formatted line-numbered diff without hunk headers).
The edit renderer previously read only `details.diff`, causing both word-level
emphasis and side-by-side split (`diffSplit`) to silently fall back because
they require `@@` hunk headers to pair lines.

Add `extractEditDiff` to prefer `details.patch` when available, falling back to
`details.diff`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant