fix(tui): TicketRef renders inline so text-wrap layout is correct (#250)#22
Merged
Conversation
…omalyco#250) Refs (anomalyco#229, anomalyco#243, anomalyco#246, ...) were landing on the wrong visual line in assistant messages with multiple inline refs. Root cause: the rendering path split each paragraph into per-segment widgets and laid them out under `<box flexDirection="row" flexWrap="wrap">`. Every segment — whether a markdown chunk or a TicketRef `<text>` — became its own flex item, and the flex-wrap engine reordered items per-item instead of flowing characters per-line. Result: `anomalyco#227` lands at end-of-next-line, `anomalyco#243` floats at end of an unrelated line, `anomalyco#246` duplicate-renders. Fix: render a paragraph containing #N refs as a single `<text>` block with inline `<span>` (text) and `<a href=...>` (ref) children. Both are OpenTUI `TextNodeRenderable`s — they participate in the parent `<text>`'s character-level wrap math, so refs flow correctly with surrounding prose. Trade-off (consistent with the original splitOnTicketRefs comment): paragraphs that contain a #N ref no longer render inline markdown formatting (bold/italic/code). Plain-text paragraphs (the fast-path) keep full markdown rendering as before. This was the trade-off the original code documented; the previous flex-row implementation didn't honor it because each markdown block was its own block-level item. Hover-card preview is dropped for now: OpenTUI TextNode (`<a>`, `<span>`) doesn't accept its own mouse-event listeners — they're part of the parent `<text>`'s render. The terminal still renders `#N` as a real OSC-8 hyperlink (⌘-click in iTerm opens hivemind-ui at /tasks/<id>), which preserves the click affordance. The hover-card component itself is left mounted but unused; reintroducing the hover via a coordinated overlay anchored to TextRenderable cursor coords is out of scope here. Closes anomalyco#250. Verified: - bun typecheck clean - All 50 TUI tests pass (test/cli/cmd/tui/) - All 399 cli tests pass (1 unrelated pre-existing help-snapshot failure from the opencode→gruntcode rebrand, not introduced here)
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
terrxo
added a commit
that referenced
this pull request
May 28, 2026
…omalyco#250) (#22) Refs (anomalyco#229, anomalyco#243, anomalyco#246, ...) were landing on the wrong visual line in assistant messages with multiple inline refs. Root cause: the rendering path split each paragraph into per-segment widgets and laid them out under `<box flexDirection="row" flexWrap="wrap">`. Every segment — whether a markdown chunk or a TicketRef `<text>` — became its own flex item, and the flex-wrap engine reordered items per-item instead of flowing characters per-line. Result: `anomalyco#227` lands at end-of-next-line, `anomalyco#243` floats at end of an unrelated line, `anomalyco#246` duplicate-renders. Fix: render a paragraph containing #N refs as a single `<text>` block with inline `<span>` (text) and `<a href=...>` (ref) children. Both are OpenTUI `TextNodeRenderable`s — they participate in the parent `<text>`'s character-level wrap math, so refs flow correctly with surrounding prose. Trade-off (consistent with the original splitOnTicketRefs comment): paragraphs that contain a #N ref no longer render inline markdown formatting (bold/italic/code). Plain-text paragraphs (the fast-path) keep full markdown rendering as before. This was the trade-off the original code documented; the previous flex-row implementation didn't honor it because each markdown block was its own block-level item. Hover-card preview is dropped for now: OpenTUI TextNode (`<a>`, `<span>`) doesn't accept its own mouse-event listeners — they're part of the parent `<text>`'s render. The terminal still renders `#N` as a real OSC-8 hyperlink (⌘-click in iTerm opens hivemind-ui at /tasks/<id>), which preserves the click affordance. The hover-card component itself is left mounted but unused; reintroducing the hover via a coordinated overlay anchored to TextRenderable cursor coords is out of scope here. Closes anomalyco#250. Verified: - bun typecheck clean - All 50 TUI tests pass (test/cli/cmd/tui/) - All 399 cli tests pass (1 unrelated pre-existing help-snapshot failure from the opencode→gruntcode rebrand, not introduced here)
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.
Fixes anomalyco#250:
#Nticket refs were landing on the wrong visual line in assistant messages with multiple inline refs.Bug
In Nik's screenshot, refs like
#227,#243,#246appeared on the wrong line, floating at end-of-unrelated-line, or duplicate-rendered. Visible examples:...awaiting next dispatch.#227→#227lands at end of the NEXT line#163 amendments → re-review → surface to you #243→#243floats with no source reason#246→#246duplicate-renderedRoot cause
packages/opencode/src/cli/cmd/tui/routes/session/index.tsx::TextPartrendered each paragraph segment as a separate widget under<box flexDirection="row" flexWrap="wrap">:Every segment — whether a
<markdown>block or the<text>-basedTicketRef— became its own flex item.flexWrap="wrap"then reordered items per-item (each flex item is atomic to the flex algorithm), not per-character. So the refs ended up wherever the flex layout placed them, not where the source text put them.Fix
Render a paragraph containing
#Nrefs as a single<text>block with inline<span>(text segments) and<a href={hivemind-url}>(refs) children. Both are OpenTUITextNodeRenderables — they participate in the parent<text>'s character-level wrap math, so refs flow correctly with surrounding prose.TicketRefitself was reshaped from a top-level<text>widget into an inline<a href={HIVEMIND_UI_BASE}/tasks/${id}>. The terminal emulator (iTerm, Ghostty, Kitty, modern Terminal.app) renders it as a real OSC-8 hyperlink — ⌘-click opens hivemind-ui at /tasks/, preserving the click affordance.Trade-offs (acknowledged in the original splitOnTicketRefs comment)
<markdown>rendering. This was the trade-off the original code documented; the previous flex-row implementation didn't honor it because each markdown block was its own block-level item.TextNode(<a>/<span>) doesn't accept its own mouse event listeners — they're part of the parent<text>'s render. The<TicketHoverCard>component is left mounted inapp.tsxbut no longer triggered (harmless dead path). A separate ticket can reintroduce a hover preview via a coordinated overlay anchored to<text>'s cursor position.Verified
bun typecheckcleantest/cli/cmd/tui/)help-snapshots.test.ts(opencode→gruntcode rebrand, not introduced by this PR — confirmed bygit stashthen re-running)Cross-references
Invalid schema for function 'context7_get-library-docs') anomalyco/opencode#250What this does NOT touch
<markdown>fast-path for ref-free paragraphs is unchanged)open()call)