fix(terminal): rejoin user prompts the PTY wrapped with an indent - #672
Open
RonenMars wants to merge 1 commit into
Open
fix(terminal): rejoin user prompts the PTY wrapped with an indent#672RonenMars wants to merge 1 commit into
RonenMars wants to merge 1 commit into
Conversation
The streamer spawns the PTY at a fixed 120 columns, so Claude Code word-wraps a long prompt across rows and indents each continuation row. collapseWrappedUserLines joined those rows with a single space and compared the result to the user_message ground truth as an exact string, so the surviving indent made the match fail and the prompt rendered as two unrelated transcript lines. Compare on collapsed whitespace instead, and match the prompt prefix on the trimmed row so left padding on the row carrying the chevron does not stop the collapse before it starts. The collapsed row now emits the ground-truth string verbatim rather than the space-joined reconstruction, which also restores prompts that were typed with newlines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A long prompt renders in the terminal view as two unrelated transcript lines, split mid-sentence.
The split itself is not ours to remove: the streamer spawns the PTY at a fixed
PTY_COLS = 120with no resize protocol, so Claude Code word-wraps its own render at 120 columns and emits each wrapped row separately.lib/collapseWrappedUserLines.tsexists precisely to stitch those rows back together using theuser_messagetext the streamer sends as ground truth, and it silently failed to fire.Verified state
Measured against the reported session on 2026-08-12: the first row is
❯plus 116 characters = 118 columns, and continuing with the next word would need 122 — over 120, so the CLI wrapped and indented the continuation row.Two whitespace holes stopped the rejoin, both reproduced before the fix:
collapseWrappedUserLines.ts:34joined rows with' ' + lines[j]untrimmed, butVirtualTerminal.getRawLines()onlytrimEnd()s — the continuation row's leading indent survived into the joined string and broke the exact-string comparison.collapseWrappedUserLines.ts:23matched the❯prefix against the untrimmed row, so any left padding on the prompt row stopped the collapse before it started.isUserLineinTerminalOutput.tsx:39trims first, so the two disagreed about what a user row is.Neither shape was covered — every fixture in the existing suite used unindented continuation rows.
Change
Compare joined rows against the ground truth on collapsed whitespace, and match the prompt prefix on the trimmed row.
The collapsed row now emits the ground-truth string verbatim instead of the space-joined reconstruction, which also restores prompts that were typed with newlines — broken before for the same reason.
Deliberately unchanged:
PTY_COLSstays at 120, and wrapping of non-user output (tool results, trees, tables) is still left alone, since the rejoin only engages on an exactuser_messagematch.Tests
Three regression cases added — indented continuation row (using the reported prompt verbatim), left-padded prompt row, and a newline-bearing prompt.
npx jest --ci --runInBand __tests__/unit/lib/collapseWrappedUserLines.test.ts→ 10 passed.npx jest --ci --runInBand --testPathPattern "TerminalOutput|TerminalView"→ 26 passed.npx tsc --noEmitclean on the changed files,npx eslintclean.