Skip to content

fix(chat): show a patch in one column on a phone - #1325

Merged
agegr merged 6 commits into
agegr:mainfrom
brynne8:fix/chat-patch-single-column
Oct 20, 2026
Merged

agegr merged 6 commits into
agegr:mainfrom
brynne8:fix/chat-patch-single-column

Conversation

@brynne8

@brynne8 brynne8 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

What it does

A tool card's patch — an apply_patch call, or a result carrying details.patch / details.diff — now takes the columns the viewport has. On a desktop it is unchanged: two code columns, before on the left, after on the right. At or below the mobile breakpoint (640px) it renders as one column instead, each removed line above the line that replaces it, one gutter, context lines printed once.

  • SplitFilesView() reads useIsMobile() and hands PatchDiffFiles a layout ("split" / "stacked"). Both the apply_patch card and a result's patch render through that dispatcher, so a phone never gets one view of each.
  • unifiedDiffLines() (lib/patch.ts) turns a file's paired split rows back into patch order — a removed line above the line that replaces it, a context row once rather than twice. components/FileViewer.tsx's diff reads the same rows through it, so the card's one-column view and the file viewer's diff cannot drift; FileViewer's own flattening is now that call, and its "unchanged" line type became "context".
  • One gutter, because a second costs the width the code needed: a removed line keeps its old number, every other line the new one, the rule FileViewer's gutter already used. Hunk headers stay dropped as in the two-column view. A multi-file patch names each section by the file's own path (its new path, the one that survives) instead of the Before / After labels, which over a single column would read as two columns.

Why it matters

Two columns of code need two code columns, and a phone does not have two. At a 390px viewport each half is about 150px, so every changed line of a real edit wraps inside its own half and the two halves have to be compared from memory. The one column is what the file viewer's diff has always been; a patch card now matches it where the screen is narrow, and nothing changes where it is not.

Reproduction

On today's main: open a session with an apply_patch (or edit) tool call whose result carries a patch, expand the card, and size the viewport to about 390px. Each of the two columns is roughly 150px wide, every changed line wraps within its own half, and the before/after pair can only be compared from memory. At desktop width the two-column view is what is wanted and is untouched by this change.

Scope

One change split out of a Bun-running fork (brynne8/pi-web-bun) into a single-purpose branch on today's main; one feature per PR.

Testing

Added assertions pin both layouts, and count the context lines the two columns pay for by printing twice:

  • lib/patch.test.mjs: unifiedDiffLines() flattens a file's rows to one column in patch order (removed above added, context once, exact line numbers), and drops hunk headers and the padded empty rows a one-sided change leaves in the split view.
  • components/MessageView.test.mjs: an edit card's patch still reaches the two-column view while there is room; the same patch in one column prints no line twice and puts the removed line above what replaces it; one column names each file section by its path and never emits the Before / After labels; and the layout is taken once, in the dispatcher both call sites go through.

Baseline on origin/main (b017cd4), with these two test files dropped in unchanged: 5 fail — the 5 new assertions (unifiedDiffLines is not a function; PatchDiffFiles not exported), while the desktop-pinning test passes. On the branch all 5 pass.

Commands run on the branch (Node v26.7.0):

  • npm test — 2784 tests, 2783 pass, 0 fail, 1 skipped. The origin/main baseline is 2778 tests, 2777 pass, 0 fail, 1 skipped; failures, not totals, are the comparison.
  • bun test lib/patch.test.mjs components/MessageView.test.mjs — 48 pass, 0 fail.
  • bun x tsc --noEmit — clean.
  • bun run lint — clean.
  • bun test (whole suite) does not complete on this machine: it stalls after lib/mcp-sign-in.test.mjs on origin/main and on the branch alike, and the partial failure sets are the same pre-existing families (node:module.findPackageJSON missing under Bun, global-state ordering), 109 on origin/main vs 110 on the branch, differing only in unrelated integration tests. Upstream's test script is Node-only (node --test), so these are not introduced by this change; the touched files are green under Bun.

Provenance

Source commit cbd6589 ("fix(chat): show a tool card's patch in one column on a phone"), carried over to this branch's base on today's main.

brynne8 and others added 5 commits October 18, 2026 09:07
Two columns of code need two code columns, and a phone does not have two: at
390px each half is about 150px, so every line of a real edit wrapped inside its
own half and the two halves had to be compared from memory. The patch now takes
the columns the viewport has.

- `SplitFilesView()` reads `useIsMobile()` and hands `PatchDiffFiles` a `layout`,
  so both the `apply_patch` card and a result's patch switch together and a phone
  never renders one view of each.
- `unifiedDiffLines()` (`lib/patch.ts`) turns a file's paired rows into patch
  order: a removed line above the line that replaces it, context lines printed
  once. `components/FileViewer.tsx` reads the same rows through it, so its diff
  and the card's cannot drift.
- One gutter, since a second costs the width the code needed: a removed line
  keeps the old number, every other line the new one, as FileViewer's gutter
  already did. Hunk headers stay dropped, and a multi-file patch names each
  section by its own path instead of `Before` / `After` over one column.
- Desktop layout is unchanged; tests pin both, and count the context lines the
  two columns pay for by printing twice.
Resolves the conflicts with agegr#1304's hunk-gap rows: unifiedDiffLines()
passes a file's gap rows through, so the file viewer's diff keeps its
"N unchanged lines" markers and the one-column card draws them too, with
the same row the two-column view uses (DiffGapRow).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
StackedDiffLineView took oldLineNo ?? newLineNo, so a context line, which
has both, showed its old number: after an added line the gutter repeated
or went backwards (added 12, then context 12 where the file has 13). A
removed line now keeps the old number and every other line the new one,
the rule the file viewer's gutter uses and the doc note describes.

A deleted file's section was named /dev/null; it now takes the old path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The demo copies of lib/patch.ts, FileViewer.tsx and MessageView.tsx get
the same change as the app: unifiedDiffLines() with its gap rows, the
file viewer's diff reading through it, and SplitFilesView choosing two
columns or one by useIsMobile().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr

agegr commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Thanks @brynne8, this is a real improvement. On main at 390px each code column of a patch card is about 110px (around 15 characters), so a changed line wraps to 5–9 rows; with your branch the single column is about 305px and the same lines take 2–3 rows. I pushed a few commits on top:

  • 54510a0c7 merges main, which conflicted with fix(chat): mark the lines a diff leaves out between hunks #1304's "⋯ N unchanged lines" rows. unifiedDiffLines() now passes the gap rows through, so the file viewer keeps its markers and the one-column card draws them too, with the same row the two-column view uses.
  • 7ad7727a5: the single gutter took oldLineNo ?? newLineNo, so context lines (which have both) showed their old number, and after an added line the gutter repeated a number (added 12, then done(); as 12 instead of 13). Removed lines now keep the old number and everything else the new one, as your description says. A deleted file's section was also named /dev/null; it now uses the old path. Tests for both.
  • c39134638 mirrors the change into demo/, and 5b71a4aed adjusts the doc note: a multi-line block interleaves pair by pair, as the file viewer always has, rather than listing every removed line first.

I also checked the FileViewer refactor against main's old flattening on 5,000 random patches: identical apart from the "unchanged" → "context" rename. tsc, lint and npm test are green.

# Conflicts:
#	AGENTS.md
#	docs/agents/sessions.md
@agegr
agegr merged commit 408230c into agegr:main Oct 20, 2026
3 checks passed
Hwwwww-dev pushed a commit to Hwwwww-dev/pi-web that referenced this pull request Oct 22, 2026
Keeps the dev-side features (keepalive dock, turnRendered chat,
ThinkingRow paging, minimap, chat-only, mobile PWA) and takes main's
architecture where it superseded local copies (lease/reattach stream
model agegr#1328, applyLoadedAgentState, live active time agegr#1334, tool
argument rows agegr#1324, patch two-column view agegr#1325, search highlights).
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
* fix(chat): show a patch in one column on a phone

Two columns of code need two code columns, and a phone does not have two: at
390px each half is about 150px, so every line of a real edit wrapped inside its
own half and the two halves had to be compared from memory. The patch now takes
the columns the viewport has.

- `SplitFilesView()` reads `useIsMobile()` and hands `PatchDiffFiles` a `layout`,
  so both the `apply_patch` card and a result's patch switch together and a phone
  never renders one view of each.
- `unifiedDiffLines()` (`lib/patch.ts`) turns a file's paired rows into patch
  order: a removed line above the line that replaces it, context lines printed
  once. `components/FileViewer.tsx` reads the same rows through it, so its diff
  and the card's cannot drift.
- One gutter, since a second costs the width the code needed: a removed line
  keeps the old number, every other line the new one, as FileViewer's gutter
  already did. Hunk headers stay dropped, and a multi-file patch names each
  section by its own path instead of `Before` / `After` over one column.
- Desktop layout is unchanged; tests pin both, and count the context lines the
  two columns pay for by printing twice.

* fix(chat): number a one-column patch's context lines by the new file

StackedDiffLineView took oldLineNo ?? newLineNo, so a context line, which
has both, showed its old number: after an added line the gutter repeated
or went backwards (added 12, then context 12 where the file has 13). A
removed line now keeps the old number and every other line the new one,
the rule the file viewer's gutter uses and the doc note describes.

A deleted file's section was named /dev/null; it now takes the old path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(demo): mirror the one-column patch on a phone

The demo copies of lib/patch.ts, FileViewer.tsx and MessageView.tsx get
the same change as the app: unifiedDiffLines() with its gap rows, the
file viewer's diff reading through it, and SplitFilesView choosing two
columns or one by useIsMobile().

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(sessions): describe the one-column pair order and its gap rows

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
* fix(chat): show a patch in one column on a phone

Two columns of code need two code columns, and a phone does not have two: at
390px each half is about 150px, so every line of a real edit wrapped inside its
own half and the two halves had to be compared from memory. The patch now takes
the columns the viewport has.

- `SplitFilesView()` reads `useIsMobile()` and hands `PatchDiffFiles` a `layout`,
  so both the `apply_patch` card and a result's patch switch together and a phone
  never renders one view of each.
- `unifiedDiffLines()` (`lib/patch.ts`) turns a file's paired rows into patch
  order: a removed line above the line that replaces it, context lines printed
  once. `components/FileViewer.tsx` reads the same rows through it, so its diff
  and the card's cannot drift.
- One gutter, since a second costs the width the code needed: a removed line
  keeps the old number, every other line the new one, as FileViewer's gutter
  already did. Hunk headers stay dropped, and a multi-file patch names each
  section by its own path instead of `Before` / `After` over one column.
- Desktop layout is unchanged; tests pin both, and count the context lines the
  two columns pay for by printing twice.

* fix(chat): number a one-column patch's context lines by the new file

StackedDiffLineView took oldLineNo ?? newLineNo, so a context line, which
has both, showed its old number: after an added line the gutter repeated
or went backwards (added 12, then context 12 where the file has 13). A
removed line now keeps the old number and every other line the new one,
the rule the file viewer's gutter uses and the doc note describes.

A deleted file's section was named /dev/null; it now takes the old path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(demo): mirror the one-column patch on a phone

The demo copies of lib/patch.ts, FileViewer.tsx and MessageView.tsx get
the same change as the app: unifiedDiffLines() with its gap rows, the
file viewer's diff reading through it, and SplitFilesView choosing two
columns or one by useIsMobile().

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(sessions): describe the one-column pair order and its gap rows

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Alex Yang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants