Repository navigation
fix(director): Keep a reply's line breaks out of the bubble's ceiling - #702
Merged
Merged
Conversation
The parser normalises lines to find the Behavior name and rebuilt the dialogue from that same list, costing Chat and the Action Log their paragraphs. The bubble keeps the breaks it now receives. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Only the ones at the ends. Padding either side of a name cut from the middle survives as one wider gap; an assertion now pins that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Why
A reply that obeys the Behavior contract had every line break destroyed before any surface saw it — in
crates/core, by the parser that exists to find the Behavior name.parse_proposalnormalised lines to find the contract line, then rebuilt the dialogue from that same normalised list. Three losses in one expression:str::trimtook the indentation,filtertook the blank lines,join(" ")took the newlines. Soreached every surface as
Here's what I found: - the roster loads - the session resumed.Two things this contradicted:
src/bubble.jsis newline-aware and never saw a newline.wrapTextwraps paragraph by paragraph overtext.split("\n"); on this path the split always yielded one element.as_speechkeeps the text whole, so a reply that ignored the format contract kept its formatting while one that obeyed it was flattened. The obedient reply was the mangled one.It also blocks #677: a Markdown renderer handed a space-joined line cannot recover lists, paragraphs or fences.
What changed
The normalised list is gone rather than mapped. The issue proposed finding the index over the filtered list and mapping it back to the originals. That mapping is the obvious place for an off-by-one, so instead
atnow indexesreply.lines()directly and no mapping exists to get wrong:Two facts make dropping the filter safe:
contract_lineneeds the line trimmed, and it already rejects an empty line —identifierrequires an alphanumeric — so the old.filter(|l| !l.is_empty())only ever shortened the scan and could never change which line matched. Filtering preserves relative order, so the first match in the filtered list was always the first match in the original.Dialogue is then joined with
"\n"between the first and last non-blank lines. Blank lines inside the model's text survive as its paragraph breaks; blank padding at the ends does not.The signature is untouched, so
harness probeis unaffected, and the behavior-name parse is byte-identical.The bubble now sees newlines, and that is deliberate
src/bubble.jsis unchanged. It keeps the line breaks it now receives, sotruncatedgoes true more often and the #547 control into Chat appears more frequently.Collapsing them in
bubble.jswas considered and rejected: it would render a run-on line that reads worse than a clamped list, and it would hide the overflow instead of handing it off. The six-line clamp plus the control into Chat is the designed answer to content the bubble cannot hold (ADR-0019; the clamp matches the 8s reading limit). Adding a collapse would be a second, quieter ceiling on top ofMAX_LINES— which is the mistake this PR is about, moved one file over.A blank line costs nothing: an empty paragraph produces no line, so
Here's:\n\n- one\n- twois three lines, not four.Two
tests/bubble.test.jstests pin the change rather than leaving it to be discovered — one asserting the three-line shape withtruncated === false, one asserting the same reply fits when flattened and truncates when structured.How to verify
cargo test --workspace cargo clippy --workspace --all-targets -- -D warnings node --test tests/425 + 483 + 23 Rust tests pass, 126 node tests pass, clippy clean.
Differential check against the old implementation. The base
parse_proposalwas copied verbatim and run against the new one over 37 inputs. Behavior-name differences: none. The awkward cases:"\n\n\nwave\nHello"leading blanks"Hello""Hello"" wave\nHello"indented name"Hello""Hello""Hello there\nwave"name last"Hello there""Hello there""wave\nA\n\n\n\nB"consecutive blanks"A B""A\n\n\n\nB""wave"contract line onlyNoneNoneMutation results, each restored from a scratch copy:
a_reply_keeps_its_own_line_structure,the_contract_line_is_cut_from_the_middleblank_lines_at_the_ends_are_padding_not_speechbubble.jscollapses newlinesThat last row is worth reading twice:
text truncates with ellipsis past 6 linesandexactly six lines is not truncationhave been asserting newline behaviour on input the production path could never produce. They were dormant coverage; they are now live.The three tests the issue flagged as canaries —
director.rs:1305,:1620,:1643— are unchanged and pass as written. The banner test still seesstarts_with("pi v0.85.1")andends_with("Hello!"), now with the banner's own lines intact between them.Notes
as_speechparity is blank-line parity, not whitespace parity.as_speechtrims horizontal whitespace at the ends; this does not, so"wave\n Hello "keeps its spaces and a leading tab survives. Arguably desirable — an indented list item keeps its indent — and harmless in the bubble, wherewrapTextswallows empty words. Chat renders viatextContent, so a preserved four-space indent cannot turn a list into a code block.main.js,main.cssandchat-ui.css, not observed.<input type="text">, which strips LF/CR per the HTML spec. Together they are why a multi-line block currently survives in neither direction.Closes #701
— Claude Code agent, on @omesser's behalf.
🤖 Generated with Claude Code