Repository navigation
fix(chat): preserve indentation and trailing newlines in structured transcript content - #50670
Conversation
…ranscript content Structured Claude/Grok/OMP transcript content (text, thinking and tool_result parts given as arrays or objects) went through the trimming extractString, so indented code lost its first-line indent and tool output lost its leading padding and final newline. Plain-string content was already kept raw. - Tool output parts keep their whitespace; blank parts are still dropped, and a part that already ends in a newline is not given another. - Text and thinking blocks keep the first content line's indentation but drop leading blank lines and trailing whitespace, so copied replies do not pick up extra blank lines. - Lone tool-result previews use the first non-blank line. Fixes #50564 Co-authored-by: Afloat <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
ELI5
Agents sometimes send a chat message or tool output as a structured list rather than one plain string. When they did, Orca cut all the spaces off the start and end. Indented code lost the indent on its first line, and file-read output lost its padding and its final newline. Orca now keeps that spacing, so structured messages look the same as plain ones.
What Changed
Before: in Chat view, Claude, Grok and OMP transcript rows built from structured blocks (
{type:'text'},thinking, andtool_resultarrays or objects) went throughextractString, which trims. A Read result like" 1\t..."lost its first-line padding, and an indented code reply lost its first indent. Plain-string content already kept its whitespace.After:
src/main/native-chat/transcript-decoding/transcript-record-blocks.tscontentString. It still drops blank parts but keeps everything else as-is. Array parts are joined with\nonly when the previous part does not already end in one, so a part's own final newline no longer turns into a blank line.blockText. It drops whitespace-only blocks and leading blank lines, keeps the first content line's indentation, and trims the end. Blocks are joined with\n\nand Copy does not trim, so keeping the edge blank lines would add stray blank lines to copied replies.extractString.src/shared/native-chat/tools/native-chat-tool-line-view.ts: the preview for a result with no matching call now uses the first non-blank line. Outputs that start with blank lines no longer show an empty preview. That also fixes plain-string outputs that already started with a newline on main.Why
The string path already sent raw text to the same renderers, so the structured path should do the same. Tool output needs exact whitespace because people copy it. Prose blocks only need their first-line indent. Keeping their edge blank lines would change Copy output and the matching of pending sends.
Linked Issue
Fixes #50564
Original fix by @Afloat16 in #50565
Visual Proof
N/A. There are no screenshots because this is a decoder change in the main process. The visible effect is the first-line indent and tool-output padding in chat rows, and that is pinned by decoder-level probes instead. With main's versions of the two source files restored, 7 of the 10 probe cases fail: text indent, thinking indent, CRLF leading blank lines, tool_result array and object whitespace, the new decoder test, and the preview test. The 3 guard cases (blank suppression, part joining, id trimming) pass on both. On this branch all 10 pass.
Testing
Reproduced on main by running the new tests against main's source.
transcript-record-blocks.test.tsgets"text": "indented()"and"output": "1\tx".native-chat-tool-line-view.test.tsgets an empty preview.Scanned about 300 local Claude JSONL files. 584 of 5540 text blocks have trailing whitespace and 14 of 2732 tool_result array parts have leading whitespace, so the trimming does happen on real data.
Ran targeted vitest under
src/main/native-chat/transcript-decodingandsrc/shared/native-chat/tools, which passes. An earlier wider run oversrc/main/native-chat,src/shared/native-chatandsrc/renderer/src/components/native-chatpassed 656 tests with 2 skipped.oxlint, oxfmt, anti-slop oxlint, code-quality oxlint, ast-grep and the changed-code quality gate are clean on the touched files.
Platform: macOS (unit level). The change is pure string handling with no platform-specific paths.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
This runs in the main process, once per decoded transcript line when a chat transcript is read or tailed. There is no new I/O, polling or subprocess work. Node benchmarks, best of 5, old / new:
JSON.parse.reducevariant was quadratic, at 49ms for 1000 parts, and was rejected.No case gets near 16ms.
Risk
Level: Low
Only chat transcript rendering and Copy are affected. A structured text block whose first line has 4 or more leading spaces now renders as a Markdown code block, the same as the plain-string path already did. Tool output keeps its edge whitespace. Pending-send matching, harness-injected detection and command-output regexes all tolerate edge whitespace already. Nothing is persisted and there is no IPC or remote format change, so a plain revert backs this out.
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)