import * as React from 'react'; import { useState } from 'react'; import { Box, Text } from '@anthropic/ink'; import { Dialog } from '../components/design-system/Dialog.js'; import { ListItem } from '../components/design-system/ListItem.js'; import { useRegisterOverlay } from '../context/overlayContext.js'; import { useKeybindings } from '../keybindings/useKeybinding.js'; import type { AssistantSession } from './sessionDiscovery.js'; interface Props { sessions: AssistantSession[]; onSelect: (id: string) => void; onCancel: () => void; } /** * Interactive session chooser for `claude assistant` when multiple * CCR sessions are discovered. Renders a Dialog with up/down navigation. * * Session IDs are in `session_*` compat format — passed directly to * createRemoteSessionConfig() for viewer attach. */ export function AssistantSessionChooser({ sessions, onSelect, onCancel }: Props): React.ReactNode { useRegisterOverlay('assistant-session-chooser'); const [focusIndex, setFocusIndex] = useState(0); useKeybindings( { 'select:next': () => setFocusIndex(i => (i + 1) % sessions.length), 'select:previous': () => setFocusIndex(i => (i - 1 + sessions.length) % sessions.length), 'select:accept': () => onSelect(sessions[focusIndex]!.id), }, { context: 'Select' }, ); return ( Multiple sessions found. Select one to attach: {sessions.map((s, i) => ( {s.title || s.id.slice(0, 20)} [{s.status}] ))} ↑↓ navigate · Enter select · Esc cancel ); }