Skip to content
This repository was archived by the owner on Aug 17, 2026. It is now read-only.

Commit 8654031

Browse files
committed
fix(tui): TicketRef renders inline so text-wrap layout is correct (anomalyco#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)
1 parent 0ee497f commit 8654031

2 files changed

Lines changed: 35 additions & 42 deletions

File tree

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
11
// grunt-it: clickable hivemind ticket-ref (#229) component for assistant chat (#233).
22
//
3-
// shadcn-svelte HoverCard parity: hover the trigger → after a small open delay the card
4-
// appears near the trigger; cursor can move INTO the card and it stays open; close happens
5-
// after a small leave delay so a brief detour doesn't dismiss it. All the timer + sticky
6-
// behavior lives in the Hivemind context — this component just emits hover-enter / leave +
7-
// the cursor coords for anchoring.
3+
// **Inline-flowing rendering** (#250): TicketRef renders as an `<a>` (LinkRenderable)
4+
// — an OpenTUI TextNode that flows inline within a parent `<text>` block. Previously
5+
// this was a top-level `<text>` widget, which when interleaved with `<markdown>` text
6+
// segments under `<box flexDirection="row" flexWrap="wrap">` caused refs to land on
7+
// the wrong line: each segment became its own flex item and the flex-wrap engine
8+
// reordered them per-item instead of flowing per-character. As an inline TextNode
9+
// the ref takes part in TextRenderable's character-level wrap math.
810
//
9-
// Click opens hivemind-ui at /tasks/<id> in the system browser.
11+
// **OSC-8 hyperlink** via the `href` prop: the terminal emulator (iTerm, Ghostty,
12+
// Kitty, modern Terminal.app) renders the ref as a real clickable hyperlink that
13+
// opens hivemind-ui at /tasks/<id>. ⌘-click in iTerm; plain click in some others.
14+
// Trade-off (accepted for #250): we lose the previously-shipped React hover-card
15+
// preview because TextNodes (`<a>`/`<span>`) don't accept their own mouse-event
16+
// listeners — they're part of the parent `<text>`'s render. A separate ticket can
17+
// reintroduce a hover preview via a different rendering strategy (e.g. a coordinated
18+
// overlay anchored to the `<text>`'s cursor position).
1019

11-
import open from "open"
1220
import { useTheme } from "../context/theme"
13-
import { useHivemind } from "../context/hivemind"
1421

1522
const HIVEMIND_UI_BASE = process.env.HIVEMIND_UI_BASE ?? "http://localhost:5173"
1623

17-
type MouseEventLike = { x: number; y: number }
18-
1924
export function TicketRef(props: { id: number }) {
2025
const { theme } = useTheme()
21-
const hive = useHivemind()
2226

2327
return (
24-
<text
25-
fg={theme.markdownLink ?? theme.primary}
26-
attributes={1}
27-
onMouseOver={(evt: MouseEventLike) => {
28-
hive.triggerHoverEnter(props.id, evt.x, evt.y)
29-
}}
30-
onMouseOut={() => {
31-
hive.triggerHoverLeave()
32-
}}
33-
onMouseUp={() => {
34-
open(`${HIVEMIND_UI_BASE}/tasks/${props.id}`).catch(() => {})
35-
}}
28+
<a
29+
href={`${HIVEMIND_UI_BASE}/tasks/${props.id}`}
30+
style={{ fg: theme.markdownLink ?? theme.primary, attributes: 1 }}
3631
>
3732
#{props.id}
38-
</text>
33+
</a>
3934
)
4035
}

‎packages/opencode/src/cli/cmd/tui/routes/session/index.tsx‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,26 +1682,24 @@ function TextPart(props: { last: boolean; part: TextPart; message: AssistantMess
16821682
/>
16831683
}
16841684
>
1685-
<box flexDirection="row" flexWrap="wrap">
1685+
{/*
1686+
#250 fix: render the entire paragraph as a single `<text>` block with
1687+
inline `<span>` text segments and `<TicketRef>` (`<a href>`) refs.
1688+
Previous shape was `<box flexDirection="row" flexWrap="wrap">` with one
1689+
`<markdown>` per text segment + one `<text>` per ref — that made each
1690+
segment a separate flex item, so the flex-wrap engine reordered them
1691+
per-item and refs landed on the wrong visual line.
1692+
1693+
Trade-off (acknowledged in the original splitOnTicketRefs comment): we
1694+
lose inline markdown rendering (bold/italic/code) for paragraphs that
1695+
contain at least one #N ref. Refs themselves render correctly inline
1696+
with proper text-wrap, which is the priority for #250.
1697+
*/}
1698+
<text fg={theme.markdownText} bg={theme.background}>
16861699
<For each={segments()}>
1687-
{(seg) =>
1688-
seg.kind === "text" ? (
1689-
<markdown
1690-
syntaxStyle={syntax()}
1691-
streaming={true}
1692-
internalBlockMode="top-level"
1693-
content={seg.text}
1694-
tableOptions={{ style: "grid" }}
1695-
conceal={ctx.conceal()}
1696-
fg={theme.markdownText}
1697-
bg={theme.background}
1698-
/>
1699-
) : (
1700-
<TicketRef id={seg.id} />
1701-
)
1702-
}
1700+
{(seg) => (seg.kind === "text" ? <span>{seg.text}</span> : <TicketRef id={seg.id} />)}
17031701
</For>
1704-
</box>
1702+
</text>
17051703
</Show>
17061704
</box>
17071705
</Show>

0 commit comments

Comments
 (0)