Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(live-links): chat drawer pinning, Escape and picker labels

reviewc7cf989541b4
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index a41de0599..584d67d19 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -439,7 +439,7 @@ import { opensInEditor } from '../lib/openTarget'
import { displacedFilesPatch } from '../lib/filesNode'
import { newEntryPath, parentDir } from '../lib/explorerCreate'
import {
- liveChatIsOpen,
+ liveChatShown,
nextLiveChat,
readLiveChatLink,
readLiveChatPinned,
@@ -3674,7 +3674,9 @@ export function Canvas() {
open: false,
linkId: readLiveChatLink()
}))
- const liveChatOpen = liveChatIsOpen(liveChat)
+ // A primitive count, not the list: a push about one link's viewers must not re-render the canvas.
+ // A pinned drawer is rendered only while a link is live (`liveChatShown`); the pin is kept.
+ const liveLinkCount = useWatchLinks((s) => s.links.length)
const liveChatRef = useRef(liveChat)
liveChatRef.current = liveChat
useEffect(() => {
@@ -19128,7 +19130,7 @@ export function Canvas() {
/>
)}
- {liveChatOpen && (
+ {liveChatShown(liveChat, liveLinkCount) && (
<LiveChatDrawer
linkId={liveChat.linkId}
pinned={liveChat.pinned}
diff --git a/src/renderer/canvas/live-link-wiring.test.ts b/src/renderer/canvas/live-link-wiring.test.ts
index d172f2505..ea7d22aed 100644
--- a/src/renderer/canvas/live-link-wiring.test.ts
+++ b/src/renderer/canvas/live-link-wiring.test.ts
@@ -130,7 +130,15 @@ describe('Canvas live-link wiring', () => {
it('the drawer is lazy-loaded like the Explorer and mounted only while open', () => {
const lazyImport = src.slice(0, src.indexOf("} from '../components/lazyPanels'"))
expect(lazyImport.slice(lazyImport.lastIndexOf('import {'))).toContain('LiveChatDrawer')
- expect(src).toMatch(/\{liveChatOpen && \(\s*<LiveChatDrawer/)
+ expect(src).toMatch(/\{liveChatShown\(liveChat, liveLinkCount\) && \(\s*<LiveChatDrawer/)
+ })
+
+ it('a pinned drawer is rendered only while a link is live (ruling, concern 3): Canvas reads the COUNT', () => {
+ // A primitive selector: a push about one link's viewers does not re-render the canvas.
+ expect(src).toContain('const liveLinkCount = useWatchLinks((s) => s.links.length)')
+ // `beside` follows the drawer actually on screen, not just the pin.
+ const mount = src.slice(src.indexOf('<LiveChatDrawer'))
+ expect(mount.slice(0, mount.indexOf('/>'))).toContain('beside={liveChat.pinned && explorerOpen && explorer.pinned}')
})
it('raised while a card modal is open, beside only when BOTH drawers are pinned', () => {
diff --git a/src/renderer/components/LiveChatDrawer.test.tsx b/src/renderer/components/LiveChatDrawer.test.tsx
index ede80e5d4..6873f2cdd 100644
--- a/src/renderer/components/LiveChatDrawer.test.tsx
+++ b/src/renderer/components/LiveChatDrawer.test.tsx
@@ -258,6 +258,25 @@ describe('LiveChatDrawer', () => {
expect(onPickLink).toHaveBeenCalledWith('M')
})
+ it('two links that would read the same are told apart in the picker (label, then start time)', () => {
+ setLinks([
+ link({ linkId: 'A', label: 'Ada', createdAt: Date.UTC(2026, 9, 3, 12, 5) }),
+ link({ linkId: 'B', label: 'Ada', createdAt: Date.UTC(2026, 9, 3, 13, 40) }),
+ link({ linkId: 'C', label: 'Team', createdAt: 9 })
+ ])
+ render(props({ linkId: 'A' }))
+ const texts = [...drawer().querySelectorAll('option')].map((o) => o.textContent)
+ expect(new Set(texts).size).toBe(3)
+ expect(texts[2]).toBe('build · Commenter · shown as Team')
+ expect(texts[0]).toMatch(/^build · Commenter · shown as Ada · since /)
+ })
+
+ it('marks itself as the Live chat drawer (the card modal leaves Escape typed inside it alone)', () => {
+ setLinks([link()])
+ render(props())
+ expect(drawer().hasAttribute('data-live-chat-drawer')).toBe(true)
+ })
+
it('a link that is not live any more falls back to the most recent one', () => {
setLinks([link({ linkId: 'A', createdAt: 1, title: 'old' }), link({ linkId: 'B', createdAt: 9, title: 'new' })])
render(props({ linkId: 'gone' }))
diff --git a/src/renderer/components/LiveChatDrawer.tsx b/src/renderer/components/LiveChatDrawer.tsx
index 1251957a4..caddc2dbf 100644
--- a/src/renderer/components/LiveChatDrawer.tsx
+++ b/src/renderer/components/LiveChatDrawer.tsx
@@ -8,7 +8,7 @@ import { ControlHold, ControlSection, hasChat, kickViewer } from './LiveLinkCont
import { IconClose, IconPin } from './icons'
import { CHAT_NOT_SENT_MESSAGE, KICK_NOTE, ROLE_NAME, statusLine, viewerName, waitingViewers } from '../lib/liveLink'
import { chatClock, chatNameColor, nearBottom, newMessagesLabel } from '../lib/liveChatLook'
-import { pickChatLink } from '../lib/liveChatPin'
+import { chatLinkOptionLabels, LIVE_CHAT_DRAWER_ATTR, pickChatLink } from '../lib/liveChatPin'
import { useLinkThread, useWatchLinks } from '../state/watchLinks'
const EMPTY_CHAT: WatchChatMessage[] = []
@@ -28,7 +28,7 @@ export interface LiveChatDrawerProps {
onGoToNode(nodeId: string): void
}
-/** "build" for the picker and the head: the node title as viewers see it, never empty. */
+/** "build" for the head: the node title as viewers see it, never empty. */
function linkTitle(l: Pick<WatchLinkView, 'title'>): string {
return stripBidiControls(l.title).trim() || 'Terminal'
}
@@ -129,6 +129,9 @@ export function LiveChatDrawer(p: LiveChatDrawerProps): React.JSX.Element {
role={pinned ? undefined : 'dialog'}
aria-label="Live chat"
tabIndex={-1}
+ // The kanban card modal leaves an Escape typed in here alone (it may be the top dialog while
+ // this drawer is docked over it).
+ {...{ [LIVE_CHAT_DRAWER_ATTR]: '' }}
onClick={(e) => e.stopPropagation()}
>
<div className="drawer__head">
@@ -168,9 +171,9 @@ export function LiveChatDrawer(p: LiveChatDrawerProps): React.JSX.Element {
p.onPickLink(e.target.value)
}}
>
- {links.map((l) => (
- <option key={l.linkId} value={l.linkId}>
- {`${linkTitle(l)} · ${ROLE_NAME[l.role]}`}
+ {chatLinkOptionLabels(links).map((text, i) => (
+ <option key={links[i].linkId} value={links[i].linkId}>
+ {text}
</option>
))}
</select>
diff --git a/src/renderer/components/kanban/CardModal.liveChatEscape.test.tsx b/src/renderer/components/kanban/CardModal.liveChatEscape.test.tsx
new file mode 100644
index 000000000..d2f6c5174
--- /dev/null
+++ b/src/renderer/components/kanban/CardModal.liveChatEscape.test.tsx
@@ -0,0 +1,115 @@
+// @vitest-environment jsdom
+/**
+ * Escape typed inside the Live chat drawer never closes the kanban card modal under it (ruling on
+ * Task 8 concern 4). The drawer is opened from the card's LIVE chip and sits RAISED above the modal.
+ * Pinned, it is not a dialog, so the card modal is the top dialog — and its capture-phase Escape used
+ * to close the modal while the owner was typing a reply. Escape in the drawer follows the drawer's
+ * own rule: unpinned, close the drawer (it is the top dialog); pinned, nothing.
+ */
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import type { ProjectKanban } from '@shared/types'
+import type { WatchLinkView } from '@shared/watch-link-types'
+import { resetDialogStack } from '../dialog-stack'
+import { LiveChatDrawer } from '../LiveChatDrawer'
+import { useWatchLinks } from '../../state/watchLinks'
+import { CardModal } from './CardModal'
+import type { KanbanSession } from './KanbanView'
+
+vi.mock('../../session/session', () => ({
+ useSession: () => ({ api: { pty: {}, shell: {} } })
+}))
+vi.mock('./BoardLogPanel', () => ({ BoardLogPanel: () => <textarea className="board-log__composer" /> }))
+vi.mock('./CardMetaBar', () => ({ CardMetaBar: () => null }))
+vi.mock('../ContextMeter', () => ({ ContextMeter: () => null }))
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+
+const board: ProjectKanban = { columns: [{ id: 'c', title: 'To Do', color: '#3b82f6' }], assignments: [] }
+const session: KanbanSession = { id: 'n1', title: 'Note', color: '#ffd60a', kind: 'sticky', text: 'x', spawn: {} }
+const link: WatchLinkView = {
+ linkId: 'L',
+ nodeId: 'n1',
+ role: 'commenter',
+ label: 'Ada',
+ title: 'build',
+ createdAt: 0,
+ expiresAt: null,
+ url: 'u',
+ status: 'live',
+ viewers: [],
+ control: null
+}
+
+let host: HTMLDivElement
+let root: Root
+beforeEach(() => {
+ resetDialogStack()
+ useWatchLinks.setState({ links: [], byNode: {}, chats: {}, unread: {}, hydrated: false })
+ useWatchLinks.getState().setLinks([link])
+ ;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = {
+ onMarkdownToggle: () => () => {},
+ watchLink: { chatHistory: vi.fn(async () => []), sendChat: vi.fn(), kick: vi.fn() },
+ clipboard: { writeText: vi.fn() }
+ }
+ host = document.createElement('div')
+ document.body.append(host)
+ root = createRoot(host)
+})
+afterEach(() => {
+ act(() => root.unmount())
+ resetDialogStack()
+ document.body.innerHTML = ''
+})
+
+const escapeOn = (el: HTMLElement): void => {
+ el.focus()
+ act(() => void el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, cancelable: true })))
+}
+
+async function open(pinned: boolean): Promise<{ closeModal: ReturnType<typeof vi.fn>; closeDrawer: ReturnType<typeof vi.fn> }> {
+ const closeModal = vi.fn()
+ const closeDrawer = vi.fn()
+ const modal = (
+ <CardModal projectId="p1" session={session} columnTitle={null} board={board} onChangeBoard={vi.fn()} onClose={closeModal}
+ onOpenCanvas={vi.fn()} onRename={vi.fn()} onEditSticky={vi.fn()} onBrowserNav={vi.fn()} onSetIcon={vi.fn()} />
+ )
+ // The card modal first; then Open chat on its LIVE chip raises the drawer over it.
+ await act(async () => root.render(<>{modal}</>))
+ await act(async () =>
+ root.render(
+ <>
+ {modal}
+ <LiveChatDrawer linkId="L" pinned={pinned} raised onPickLink={vi.fn()} onClose={closeDrawer} onTogglePin={vi.fn()} onGoToNode={vi.fn()} />
+ </>
+ )
+ )
+ expect(document.querySelector('.drawer-overlay--raised')).not.toBeNull()
+ return { closeModal, closeDrawer }
+}
+
+const composer = (): HTMLInputElement => document.querySelector<HTMLInputElement>('.live-chat__reply input')!
+
+describe('Escape in the Live chat drawer over a card modal', () => {
+ it('pinned: Escape in the drawer closes neither the drawer nor the card modal', async () => {
+ const { closeModal, closeDrawer } = await open(true)
+ escapeOn(composer())
+ expect(closeModal).not.toHaveBeenCalled()
+ expect(closeDrawer).not.toHaveBeenCalled()
+ })
+
+ it('unpinned (the top dialog): Escape in the drawer closes the drawer only', async () => {
+ const { closeModal, closeDrawer } = await open(false)
+ escapeOn(composer())
+ expect(closeDrawer).toHaveBeenCalledTimes(1)
+ expect(closeModal).not.toHaveBeenCalled()
+ })
+
+ it('Escape outside the drawer still closes the card modal when the docked drawer is up (unchanged)', async () => {
+ const { closeModal, closeDrawer } = await open(true)
+ escapeOn(document.querySelector<HTMLTextAreaElement>('.board-log__composer')!)
+ expect(closeModal).toHaveBeenCalledTimes(1)
+ expect(closeDrawer).not.toHaveBeenCalled()
+ })
+})
diff --git a/src/renderer/components/kanban/CardModal.tsx b/src/renderer/components/kanban/CardModal.tsx
index 82b486aab..4483843f4 100644
--- a/src/renderer/components/kanban/CardModal.tsx
+++ b/src/renderer/components/kanban/CardModal.tsx
@@ -60,6 +60,7 @@ import { ModalTerminal } from './ModalTerminal'
import { BrowserSurface } from '../../nodes/BrowserSurface'
import { BrowserDrivingIndicator } from '../../nodes/BrowserDrivingChip'
import { NoteMarkdown } from '../NoteMarkdown'
+import { inLiveChatDrawer } from '../../lib/liveChatPin'
import { relativeTime } from '../../lib/relativeTime'
import { TerminalMarkdownView } from '../../nodes/TerminalMarkdownView'
import { canChat } from '@shared/agents/config'
@@ -303,6 +304,10 @@ export function CardModal({ session, projectId, projectName, projectColor, colum
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key !== 'Escape' || !isTopDialog(id)) return
+ // An Escape typed in the Live chat drawer is the drawer's, never this modal's: docked over the
+ // modal (raised), the drawer is not a dialog, so this modal is still the top one. Not consumed —
+ // the drawer's own rule decides (unpinned: close the drawer; pinned: nothing).
+ if (inLiveChatDrawer(e.target) || inLiveChatDrawer(document.activeElement)) return
// A rename in progress owns Esc first (cancel the edit, not the modal).
if (editingTitleRef.current) {
e.preventDefault()
diff --git a/src/renderer/lib/liveChatLook.ts b/src/renderer/lib/liveChatLook.ts
index b699edd34..b3de8b9cd 100644
--- a/src/renderer/lib/liveChatLook.ts
+++ b/src/renderer/lib/liveChatLook.ts
@@ -1,13 +1,18 @@
// The live-link viewer page's chat look, for the owner's Live chat drawer. COPIED from nodeterm-web
// `src/lib/watch-viewer/chat-panel.ts` (chatNameColor, VIEWER_NAME_COLORS, nearBottom,
-// NEAR_BOTTOM_PX, newMessagesLabel, chatClock) — never imported across repositories. Keep the two in
-// step: a viewer must be drawn in the same colour on the owner's drawer as on every viewer's page
-// (`liveChatLook.test.ts` pins the hash against values computed with the web page's function).
+// NEAR_BOTTOM_PX, newMessagesLabel, chatClock) — never imported across repositories.
//
-// The hex table is the web page's, kept verbatim so the colours match; the drawer hands a colour to
-// CSS as `--live-name`, where the light theme darkens it toward the ink (styles.css). The sharer's
-// colour is NOT copied: the drawer marks the owner's lines with a token and the "Sharer" badge, and —
-// as on the page — no viewer name is ever drawn in it (the badge is the host's word, never a name's).
+// WHY the drawer and the web page must match: the same viewer gets the same colour on both. The owner
+// reads a viewer as "the orange one" in the drawer while everyone watching sees that viewer's lines in
+// orange on the page; a drift splits one person into two colours. `liveChatLook.test.ts` pins the
+// hash against values computed with the web page's own function — change either side and re-run it.
+//
+// The hex table is a deliberate exception to "semantic tokens only" (CLAUDE.md, Semantic colours), the
+// same class as the agent brand colours: it is ANOTHER surface's palette, and copying it verbatim is
+// the point. The drawer hands a colour to CSS as `--live-name`, where the light theme darkens it toward
+// the ink (styles.css). The sharer's colour is NOT copied: the drawer marks the owner's lines with a
+// token and the "Sharer" badge, and — as on the page — no viewer name is ever drawn in it (the badge is
+// the host's word, never a name's).
/** Viewer name colours, readable on the page's near-black. No green near the sharer's. */
export const VIEWER_NAME_COLORS = [
diff --git a/src/renderer/lib/liveChatPin.test.ts b/src/renderer/lib/liveChatPin.test.ts
index e7dd365cf..602b92cce 100644
--- a/src/renderer/lib/liveChatPin.test.ts
+++ b/src/renderer/lib/liveChatPin.test.ts
@@ -1,9 +1,13 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { WatchLinkView } from '@shared/watch-link-types'
+import { formatClock } from './liveLink'
import {
+ chatLinkOptionLabels,
+ inLiveChatDrawer,
LIVE_CHAT_LINK_KEY,
LIVE_CHAT_PINNED_KEY,
liveChatIsOpen,
+ liveChatShown,
nextLiveChat,
pickChatLink,
readLiveChatLink,
@@ -46,6 +50,22 @@ describe('liveChatIsOpen', () => {
})
})
+describe('liveChatShown (ruling on concern 3)', () => {
+ it('pinned: rendered only while at least one link is live — the pin is kept, the drawer comes back', () => {
+ expect(liveChatShown(docked, 0)).toBe(false)
+ expect(liveChatShown(launchPinned, 0)).toBe(false)
+ expect(liveChatShown(docked, 1)).toBe(true)
+ expect(liveChatShown(launchPinned, 3)).toBe(true)
+ // Dismissed stays hidden whatever the links.
+ expect(liveChatShown(dockedHidden, 2)).toBe(false)
+ })
+ it('unpinned: an explicit open shows even with no live link ("No live links.")', () => {
+ expect(liveChatShown(modal, 0)).toBe(true)
+ expect(liveChatShown(hidden, 0)).toBe(false)
+ expect(liveChatShown(hidden, 2)).toBe(false)
+ })
+})
+
describe('nextLiveChat', () => {
it('open shows the drawer, on the named link when there is one, and keeps the pin', () => {
expect(nextLiveChat(hidden, { kind: 'open', linkId: 'B' })).toEqual({ pinned: false, dismissed: false, open: true, linkId: 'B' })
@@ -92,6 +112,77 @@ describe('pickChatLink', () => {
})
})
+describe('chatLinkOptionLabels (ruling on concern 6: every option reads differently)', () => {
+ const l = (linkId: string, over: Partial<WatchLinkView> = {}): WatchLinkView => ({ ...link(linkId, 0), ...over })
+
+ it('a unique title and role reads "{title} · {role}"', () => {
+ expect(
+ chatLinkOptionLabels([
+ l('A', { title: 'build', role: 'commenter' }),
+ l('B', { title: 'build', role: 'controller' }),
+ l('C', { title: 'api-\u202Eserver', role: 'viewer' }),
+ l('D', { title: ' ', role: 'viewer' })
+ ])
+ ).toEqual(['build · Commenter', 'build · Control', 'api-server · Viewer', 'Terminal · Viewer'])
+ })
+
+ it('two that read the same are told apart by their own label, when that differs', () => {
+ expect(
+ chatLinkOptionLabels([
+ l('A', { title: 'build', label: 'Ada' }),
+ l('B', { title: 'build', label: 'Team \u202Edemo' })
+ ])
+ ).toEqual(['build · Commenter · shown as Ada', 'build · Commenter · shown as Team demo'])
+ })
+
+ it('still the same: the start time is appended ("· since 14:05")', () => {
+ const t1 = Date.UTC(2026, 9, 3, 12, 5)
+ const t2 = Date.UTC(2026, 9, 3, 13, 40)
+ expect(
+ chatLinkOptionLabels([
+ l('A', { title: 'build', label: 'Ada', createdAt: t1 }),
+ l('B', { title: 'build', label: 'Ada', createdAt: t2 }),
+ l('C', { title: 'logs', label: 'Ada', createdAt: t2 })
+ ])
+ ).toEqual([
+ // The same label tells nothing apart, so it is not added.
+ `build · Commenter · since ${formatClock(t1)}`,
+ `build · Commenter · since ${formatClock(t2)}`,
+ 'logs · Commenter'
+ ])
+ // A label that differs AND a start time, where only the time separates two of three.
+ expect(
+ chatLinkOptionLabels([
+ l('A', { title: 'build', label: 'Ada', createdAt: t1 }),
+ l('B', { title: 'build', label: 'Ada', createdAt: t2 }),
+ l('C', { title: 'build', label: 'Team', createdAt: t2 })
+ ])
+ ).toEqual([
+ `build · Commenter · shown as Ada · since ${formatClock(t1)}`,
+ `build · Commenter · shown as Ada · since ${formatClock(t2)}`,
+ 'build · Commenter · shown as Team'
+ ])
+ })
+
+ it('even started the same minute, every label is unique', () => {
+ const t = Date.UTC(2026, 9, 3, 12, 5)
+ const labels = chatLinkOptionLabels([l('A', { createdAt: t }), l('B', { createdAt: t }), l('C', { createdAt: t })])
+ expect(new Set(labels).size).toBe(3)
+ expect(labels).toEqual(['t · Commenter', 't · Commenter (2)', 't · Commenter (3)'])
+ })
+})
+
+describe('inLiveChatDrawer', () => {
+ it('anything inside the drawer, nothing outside; non-elements are outside', () => {
+ expect(inLiveChatDrawer(null)).toBe(false)
+ expect(inLiveChatDrawer({} as EventTarget)).toBe(false)
+ const inside = { closest: (sel: string) => (sel === '[data-live-chat-drawer]' ? {} : null) }
+ const outside = { closest: () => null }
+ expect(inLiveChatDrawer(inside as unknown as EventTarget)).toBe(true)
+ expect(inLiveChatDrawer(outside as unknown as EventTarget)).toBe(false)
+ })
+})
+
describe('storage', () => {
it('pin: reads and writes its own key as 1/0, off by default', () => {
const store: Record<string, string> = {}
diff --git a/src/renderer/lib/liveChatPin.ts b/src/renderer/lib/liveChatPin.ts
index 4e27b1962..47a4757d7 100644
--- a/src/renderer/lib/liveChatPin.ts
+++ b/src/renderer/lib/liveChatPin.ts
@@ -8,6 +8,8 @@
// linkId — the link the owner picked last (Open chat on a chip, the drawer's picker). The drawer
// shows it while it is live, else the most recent link (`pickChatLink`).
import type { WatchLinkView } from '@shared/watch-link-types'
+import { stripBidiControls } from '@shared/watch-link-types'
+import { formatClock, ROLE_NAME } from './liveLink'
export const LIVE_CHAT_PINNED_KEY = 'nodeterm.liveChatPinned'
export const LIVE_CHAT_LINK_KEY = 'nodeterm.liveChatLink'
@@ -26,6 +28,16 @@ export function liveChatIsOpen(s: LiveChatState): boolean {
return s.pinned ? !s.dismissed : s.open
}
+/**
+ * Whether the drawer is RENDERED. A pinned drawer is docked chrome: with no live link it would be an
+ * empty card taking canvas width (and inset every maximize for nothing), so it shows only while at
+ * least one link is live — the pin is kept and it comes back with the next link. An unpinned drawer
+ * the owner explicitly opened shows even with none ("No live links.").
+ */
+export function liveChatShown(s: LiveChatState, liveLinks: number): boolean {
+ return liveChatIsOpen(s) && (!s.pinned || liveLinks > 0)
+}
+
export function nextLiveChat(s: LiveChatState, a: LiveChatAction): LiveChatState {
switch (a.kind) {
case 'open':
@@ -52,6 +64,52 @@ export function pickChatLink(links: readonly WatchLinkView[], wanted: string | n
return best ? best.linkId : null
}
+/**
+ * The picker's option per link, in list order — every one reads differently. "{title} · {role}"; two
+ * that read the same add the link's own label ("· shown as Ada" — the name viewers see for the
+ * owner, so only where it differs between them); still the same, the start time ("· since 14:05");
+ * still the same (started the same minute), a counter. Titles and labels are bidi-stripped.
+ */
+export function chatLinkOptionLabels(links: readonly WatchLinkView[]): string[] {
+ /** Within each group of identical labels, append `extra` — unless it is the same for the whole
+ * group, where it would tell nothing apart. */
+ const disambiguate = (labels: string[], extra: (l: WatchLinkView) => string): string[] => {
+ const groups = new Map<string, Set<string>>()
+ labels.forEach((t, i) => groups.set(t, (groups.get(t) ?? new Set()).add(extra(links[i]))))
+ return labels.map((t, i) => {
+ const extras = groups.get(t)!
+ if (labels.filter((x) => x === t).length < 2 || extras.size < 2) return t
+ const more = extra(links[i])
+ return more ? `${t} · ${more}` : t
+ })
+ }
+ let labels = links.map((l) => `${stripBidiControls(l.title).trim() || 'Terminal'} · ${ROLE_NAME[l.role]}`)
+ labels = disambiguate(labels, (l) => {
+ const label = stripBidiControls(l.label).trim()
+ return label ? `shown as ${label}` : ''
+ })
+ labels = disambiguate(labels, (l) => `since ${formatClock(l.createdAt)}`)
+ const seen = new Map<string, number>()
+ return labels.map((t) => {
+ const n = (seen.get(t) ?? 0) + 1
+ seen.set(t, n)
+ return n === 1 ? t : `${t} (${n})`
+ })
+}
+
+/** The attribute that marks the drawer's root, so other surfaces can leave its keys alone. */
+export const LIVE_CHAT_DRAWER_ATTR = 'data-live-chat-drawer'
+
+/**
+ * Is this event target inside the Live chat drawer? The kanban card modal's capture-phase Escape asks:
+ * a raised, pinned drawer is not a dialog, so the card modal under it is the top dialog — and closed
+ * itself on an Escape the owner typed in the drawer's reply box.
+ */
+export function inLiveChatDrawer(target: EventTarget | null): boolean {
+ const el = target as { closest?: unknown } | null
+ return !!el && typeof el.closest === 'function' && (el as Element).closest(`[${LIVE_CHAT_DRAWER_ATTR}]`) !== null
+}
+
const getStored = (key: string): string | null => localStorage.getItem(key)
const setStored = (key: string, value: string): void => localStorage.setItem(key, value)