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

Commit 830fe33

Browse files
committed
fix(grunt/tui): #N ticket-hover — single shared floating card, no per-ref overlap flicker (#15)
Refs hivemind anomalyco#233. v2 of the hover fix after Nik flagged: 'hovers broken like flickering and nothing loaded'. ## v1 bug (root cause) The v1 TicketRef rendered its tooltip as a child <box position='absolute'> inside the same column as the trigger <text>. Without explicit top/left, opentui placed the tooltip in the natural flow position — directly below or overlapping the trigger text. Mouse over text fired onMouseOver → tooltip showed → mouse was no longer on the text (now on tooltip area or in the gap) → onMouseOut fired → tooltip hid → mouse back on text → onMouseOver again → flicker loop. Also blocked the fetch from completing visibly: even if the data loaded, the tooltip vanished before render. ## v2 architecture Single global tooltip, screen-anchored, fed by a global signal: 1. **Hivemind context** owns: - hoveredTicketId signal (number | null) - setHoveredTicket(id) — also kicks off lazy fetch + populates cache - ticketCache (Map<number, TicketDetail | null>) - ticketDetail(id) — reactive read of cache - fetchTicket(id) — dedup'd in-flight, AbortController timeout 2. **TicketRef** is now ONLY a colored clickable text. No tooltip child. onMouseOver/Out call hive.setHoveredTicket(props.id) / setHoveredTicket(null). onMouseUp opens hivemind-ui via the existing 'open' npm pkg. 3. **TicketHoverCard** is a NEW single-instance component rendered once at app root (in app.tsx). Reads hive.hoveredTicketId() — when set, renders the detail at position='absolute' top=1 right=2. Far from any mouse-interactive surface, so hover state doesn't ping-pong. Result: - TicketRef stays inline with text flow (just a <text>, not a <box>) - Tooltip renders ONCE at a fixed location, fed by whichever ref is hovered - Cache shared across all refs, fetch fires on first hover of each id - onMouseOver/Out events stay stable — no overlap, no flicker ## Files | File | Change | |---|---| | packages/opencode/src/cli/cmd/tui/context/hivemind.tsx | + hoveredTicketId / setHoveredTicket / ticketDetail / fetchTicket + cache | | packages/opencode/src/cli/cmd/tui/component/ticket-ref.tsx | Stripped tooltip; just colored clickable <text> | | packages/opencode/src/cli/cmd/tui/component/ticket-hover-card.tsx | NEW single-instance floating tooltip | | packages/opencode/src/cli/cmd/tui/app.tsx | Renders <TicketHoverCard /> once at app root | ## Verified bun typecheck clean. Local install reports 1.15.10-grunt.7+local.8b07799be.dirty.
1 parent 6178db0 commit 830fe33

4 files changed

Lines changed: 178 additions & 132 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/app.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { EditorContextProvider } from "@tui/context/editor"
3030
import { useEvent } from "@tui/context/event"
3131
import { SDKProvider, useSDK } from "@tui/context/sdk"
3232
import { StartupLoading } from "@tui/component/startup-loading"
33+
import { TicketHoverCard } from "@tui/component/ticket-hover-card"
3334
import { SyncProvider, useSync } from "@tui/context/sync"
3435
import { SyncProviderV2 } from "@tui/context/sync-v2"
3536
import { LocalProvider, useLocal } from "@tui/context/local"
@@ -1142,6 +1143,10 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
11421143
<TuiPluginRuntime.Slot name="app" />
11431144
</Show>
11441145
<StartupLoading ready={ready} />
1146+
{/* grunt-it: single floating hivemind ticket hover card (#233). Rendered once,
1147+
anchored at top-right. Reads the global hoveredTicketId signal so per-ref
1148+
tooltip overlap can't cause flicker. */}
1149+
<TicketHoverCard />
11451150
</box>
11461151
)
11471152
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// grunt-it: single floating tooltip for hivemind ticket-ref hovers (#233).
2+
//
3+
// Rendered ONCE at the app-root level (NOT as a child of any TicketRef). Reads the
4+
// global hoveredTicketId signal from the Hivemind context; when set, shows the ticket
5+
// detail at a fixed screen anchor (top of screen, right-aligned). When null, renders
6+
// nothing (and consumes no space).
7+
//
8+
// Architecture motivation: a per-ref tooltip box rendered inside the same column as
9+
// the ref's text caused a hover-flicker loop in v1 — the tooltip overlapped the text
10+
// region, mouse moved off the text onto the tooltip, onMouseOut fired, tooltip hid,
11+
// mouse was back on text, onMouseOver fired, tooltip showed again. By rendering the
12+
// tooltip at a screen anchor far from any mouse-interactive surface, the hover state
13+
// is stable.
14+
15+
import { Show } from "solid-js"
16+
import { useHivemind } from "../context/hivemind"
17+
import { useTheme } from "../context/theme"
18+
19+
export function TicketHoverCard() {
20+
const hive = useHivemind()
21+
const { theme } = useTheme()
22+
23+
return (
24+
<Show when={hive.hoveredTicketId() !== null}>
25+
<box
26+
position="absolute"
27+
top={1}
28+
right={2}
29+
backgroundColor={theme.backgroundPanel}
30+
border={true}
31+
borderColor={theme.border}
32+
paddingLeft={1}
33+
paddingRight={1}
34+
paddingTop={0}
35+
paddingBottom={0}
36+
zIndex={3000}
37+
maxWidth={70}
38+
>
39+
{(() => {
40+
const id = hive.hoveredTicketId()
41+
if (id === null) return null
42+
const d = hive.ticketDetail(id)
43+
if (d === undefined) {
44+
return <text fg={theme.textMuted}>loading #{id}...</text>
45+
}
46+
if (d === null) {
47+
return <text fg={theme.textMuted}>#{id}: not found</text>
48+
}
49+
return (
50+
<>
51+
<text fg={theme.text} wrapMode="word">
52+
<b>
53+
#{d.id} {d.title}
54+
</b>
55+
</text>
56+
<text fg={theme.textMuted}>
57+
<span>{d.status}</span>
58+
{" · "}
59+
<span>{d.priority}</span>
60+
<Show when={d.zone}>
61+
{" · "}
62+
<span>zone={d.zone}</span>
63+
</Show>
64+
<Show when={d.owner}>
65+
{" · "}
66+
<span>owner={d.owner}</span>
67+
</Show>
68+
</text>
69+
<Show when={d.scope}>
70+
<text fg={theme.textMuted} wrapMode="word">
71+
{(d.scope ?? "").slice(0, 220)}
72+
{(d.scope ?? "").length > 220 ? "..." : ""}
73+
</text>
74+
</Show>
75+
<text fg={theme.textMuted}>
76+
<span>click to open in hivemind-ui</span>
77+
</text>
78+
</>
79+
)
80+
})()}
81+
</box>
82+
</Show>
83+
)
84+
}
Lines changed: 19 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,36 @@
11
// grunt-it: clickable hivemind ticket-ref (#229) component for assistant chat (#233).
22
//
3-
// Renders `#229` colored + underlined inline. Hover lazily fetches the ticket detail
4-
// from hivemind-api (localhost:7890) and shows a tooltip overlay with title + status +
5-
// scope-preview. Click opens hivemind-ui at /tasks/<id> in the system browser.
3+
// v2 architecture (after v1 flicker bug):
4+
// - This component is just a colored clickable text. NO local tooltip — that was the source
5+
// of the flicker (per-ref tooltip box overlapped its own text, hover→unhover→hover loop).
6+
// - Hover/leave events set a SINGLE global "currentlyHoveredTicket" signal in the Hivemind
7+
// context. Detail fetch + caching also lives there (shared across all refs).
8+
// - The single floating <TicketHoverCard /> reads that signal and renders the detail at a
9+
// fixed screen anchor — no overlap with any text, so no flicker.
610
//
7-
// Why not markdown links: opentui's markdown component renders `[label](url)` literally
8-
// (with brackets + URL visible) and has no hover/click hooks for inline tokens. We bypass
9-
// it for ticket refs and render directly.
11+
// Click opens hivemind-ui at /tasks/<id> in the system browser.
1012

11-
import { createSignal, Show } from "solid-js"
1213
import open from "open"
1314
import { useTheme } from "../context/theme"
1415
import { useHivemind } from "../context/hivemind"
1516

1617
const HIVEMIND_UI_BASE = process.env.HIVEMIND_UI_BASE ?? "http://localhost:5173"
17-
const HIVEMIND_API_BASE = process.env.HIVEMIND_API_BASE ?? "http://127.0.0.1:7890"
18-
19-
type TicketDetail = {
20-
id: number
21-
title: string
22-
scope?: string | null
23-
status: string
24-
priority: string
25-
zone?: string | null
26-
owner?: string | null
27-
}
28-
29-
const cache = new Map<number, TicketDetail | null>()
30-
const inflight = new Map<number, Promise<TicketDetail | null>>()
31-
32-
function fetchTicket(id: number): Promise<TicketDetail | null> {
33-
if (cache.has(id)) return Promise.resolve(cache.get(id)!)
34-
const existing = inflight.get(id)
35-
if (existing) return existing
36-
const p = (async () => {
37-
try {
38-
const controller = new AbortController()
39-
const t = setTimeout(() => controller.abort(), 1500)
40-
const res = await fetch(`${HIVEMIND_API_BASE}/api/tasks/${id}`, { signal: controller.signal })
41-
clearTimeout(t)
42-
if (!res.ok) {
43-
cache.set(id, null)
44-
return null
45-
}
46-
const body = (await res.json()) as { task?: TicketDetail } | TicketDetail
47-
const task = (body as { task?: TicketDetail }).task ?? (body as TicketDetail)
48-
cache.set(id, task ?? null)
49-
return task ?? null
50-
} catch {
51-
cache.set(id, null)
52-
return null
53-
} finally {
54-
inflight.delete(id)
55-
}
56-
})()
57-
inflight.set(id, p)
58-
return p
59-
}
6018

6119
export function TicketRef(props: { id: number }) {
6220
const { theme } = useTheme()
6321
const hive = useHivemind()
64-
const [hovered, setHovered] = createSignal(false)
65-
const [detail, setDetail] = createSignal<TicketDetail | null | undefined>(cache.get(props.id))
66-
67-
function onEnter() {
68-
setHovered(true)
69-
if (detail() === undefined) {
70-
void fetchTicket(props.id).then((d) => setDetail(d))
71-
}
72-
}
73-
74-
function onLeave() {
75-
setHovered(false)
76-
}
77-
78-
function onClick() {
79-
open(`${HIVEMIND_UI_BASE}/tasks/${props.id}`).catch(() => {})
80-
}
8122

8223
return (
83-
<box flexDirection="column" flexShrink={0}>
84-
<text
85-
fg={theme.markdownLink ?? theme.primary}
86-
attributes={1}
87-
onMouseOver={onEnter}
88-
onMouseOut={onLeave}
89-
onMouseUp={onClick}
90-
>
91-
#{props.id}
92-
</text>
93-
<Show when={hovered() && hive.state.apiOnline}>
94-
<box
95-
position="absolute"
96-
backgroundColor={theme.backgroundPanel}
97-
border={true}
98-
borderColor={theme.border}
99-
paddingLeft={1}
100-
paddingRight={1}
101-
paddingTop={0}
102-
paddingBottom={0}
103-
zIndex={2000}
104-
maxWidth={60}
105-
>
106-
<Show
107-
when={detail() !== undefined}
108-
fallback={<text fg={theme.textMuted}>loading #{props.id}...</text>}
109-
>
110-
<Show
111-
when={detail()}
112-
fallback={<text fg={theme.textMuted}>#{props.id}: (not found)</text>}
113-
>
114-
{(d) => (
115-
<>
116-
<text fg={theme.text}>
117-
<b>#{d().id} {d().title}</b>
118-
</text>
119-
<text fg={theme.textMuted}>
120-
<span>{d().status}</span>
121-
{" · "}
122-
<span>{d().priority}</span>
123-
<Show when={d().zone}>
124-
{" · "}
125-
<span>zone={d().zone}</span>
126-
</Show>
127-
<Show when={d().owner}>
128-
{" · "}
129-
<span>owner={d().owner}</span>
130-
</Show>
131-
</text>
132-
<Show when={d().scope}>
133-
<text fg={theme.textMuted} wrapMode="word">
134-
{(d().scope ?? "").slice(0, 200)}
135-
{(d().scope ?? "").length > 200 ? "..." : ""}
136-
</text>
137-
</Show>
138-
<text fg={theme.textMuted}>
139-
<span>click to open in hivemind-ui</span>
140-
</text>
141-
</>
142-
)}
143-
</Show>
144-
</Show>
145-
</box>
146-
</Show>
147-
</box>
24+
<text
25+
fg={theme.markdownLink ?? theme.primary}
26+
attributes={1}
27+
onMouseOver={() => hive.setHoveredTicket(props.id)}
28+
onMouseOut={() => hive.setHoveredTicket(null)}
29+
onMouseUp={() => {
30+
open(`${HIVEMIND_UI_BASE}/tasks/${props.id}`).catch(() => {})
31+
}}
32+
>
33+
#{props.id}
34+
</text>
14835
)
14936
}

‎packages/opencode/src/cli/cmd/tui/context/hivemind.tsx‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ import { getPeerID } from "@opencode-ai/core/util/opencode-process"
2020
const DEFAULT_API = "http://127.0.0.1:7890"
2121
const POLL_INTERVAL_MS = 2000
2222

23+
// Cached + dedup'd ticket-detail fetches used by TicketRef hover (#233). Lives in the
24+
// context (not in the component) so multiple TicketRefs share a single fetch per id and
25+
// hover→unhover→hover doesn't refire the request.
26+
export type TicketDetail = {
27+
id: number
28+
title: string
29+
scope?: string | null
30+
status: string
31+
priority: string
32+
zone?: string | null
33+
owner?: string | null
34+
}
35+
2336
export type Peer = {
2437
id: string
2538
engine: string
@@ -204,11 +217,68 @@ export const { use: useHivemind, provider: HivemindProvider } = createSimpleCont
204217
poll().catch(() => {})
205218
}
206219

220+
// ----- ticket-hover state (#233) ---------------------------------------------------------
221+
// One global "currently-hovered ticket id" signal. TicketRefs set/clear it on
222+
// enter/leave; the single floating TicketHoverCard reads it and renders the detail.
223+
// No per-ref tooltip boxes overlapping their own text → no flicker.
224+
const [hoveredTicketId, setHoveredTicketId] = createSignal<number | null>(null)
225+
const ticketCache = new Map<number, TicketDetail | null>()
226+
const ticketInflight = new Map<number, Promise<TicketDetail | null>>()
227+
const [ticketCacheTick, setTicketCacheTick] = createSignal(0)
228+
229+
function ticketDetail(id: number): TicketDetail | null | undefined {
230+
// Read the tick so consumers re-render when the cache updates.
231+
ticketCacheTick()
232+
return ticketCache.get(id)
233+
}
234+
235+
function fetchTicket(id: number): Promise<TicketDetail | null> {
236+
if (ticketCache.has(id)) return Promise.resolve(ticketCache.get(id) ?? null)
237+
const existing = ticketInflight.get(id)
238+
if (existing) return existing
239+
const p = (async () => {
240+
try {
241+
const controller = new AbortController()
242+
const t = setTimeout(() => controller.abort(), 1500)
243+
const res = await fetch(`${apiBase}/api/tasks/${id}`, { signal: controller.signal })
244+
clearTimeout(t)
245+
if (!res.ok) {
246+
ticketCache.set(id, null)
247+
return null
248+
}
249+
const body = (await res.json()) as { task?: TicketDetail } | TicketDetail
250+
const task = (body as { task?: TicketDetail }).task ?? (body as TicketDetail)
251+
ticketCache.set(id, task ?? null)
252+
return task ?? null
253+
} catch {
254+
ticketCache.set(id, null)
255+
return null
256+
} finally {
257+
ticketInflight.delete(id)
258+
setTicketCacheTick((n) => n + 1)
259+
}
260+
})()
261+
ticketInflight.set(id, p)
262+
return p
263+
}
264+
265+
function setHoveredTicket(id: number | null) {
266+
setHoveredTicketId(id)
267+
if (id !== null && !ticketCache.has(id)) {
268+
void fetchTicket(id)
269+
}
270+
}
271+
207272
return {
208273
get state() {
209274
return state
210275
},
211276
refresh,
277+
// ticket-hover
278+
hoveredTicketId,
279+
setHoveredTicket,
280+
ticketDetail,
281+
fetchTicket,
212282
}
213283
},
214284
})

0 commit comments

Comments
 (0)