From c11027be4d9183c9028f91bf68c0abb5934b103b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sun, 15 Feb 2026 18:25:22 -0800 Subject: [PATCH] Show terminal runtime status and web port actions in thread UI - Pass running terminal IDs/ports from `ChatView` into `ThreadTerminalDrawer` - Add runtime badges/icons for running terminals and localhost web ports - Make sidebar thread rows keyboard-activatable and add web-port quick open button --- apps/web/src/components/ChatView.tsx | 2 + apps/web/src/components/Sidebar.tsx | 94 ++++++------- .../src/components/ThreadTerminalDrawer.tsx | 126 +++++++++++++++--- 3 files changed, 145 insertions(+), 77 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 5114a24468..b9e38527c2 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -1448,6 +1448,8 @@ export default function ChatView() { activeTerminalId={activeThread.activeTerminalId} terminalGroups={activeThread.terminalGroups} activeTerminalGroupId={activeThread.activeTerminalGroupId} + runningTerminalIds={activeThread.runningTerminalIds} + runningTerminalPorts={activeThread.runningTerminalPorts} focusRequestId={terminalFocusRequestId} onSplitTerminal={splitTerminal} onNewTerminal={createNewTerminal} diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index aed7909a84..2cbe226639 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -1,4 +1,4 @@ -import { GlobeIcon, MonitorIcon, MoonIcon, SunIcon, TerminalIcon } from "lucide-react"; +import { GlobeIcon, MonitorIcon, MoonIcon, SunIcon, TerminalIcon, TerminalSquareIcon } from "lucide-react"; import { type MouseEvent, useCallback, useEffect, useMemo, useState } from "react"; import type { ResolvedKeybindingsConfig } from "@t3tools/contracts"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; @@ -47,12 +47,7 @@ interface ThreadStatusPill { pulse: boolean; } -interface TerminalStatusIndicator { - label: string; - colorClass: string; - pulse: boolean; - primaryWebPort: number | null; -} + function hasUnseenCompletion(thread: Thread): boolean { if (!thread.latestTurnCompletedAt) return false; @@ -105,7 +100,7 @@ function threadStatusPill(thread: Thread, hasPendingApprovals: boolean): ThreadS return null; } -function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null { +function terminalStatusIndicator(thread: Thread){ if (thread.runningTerminalIds.length === 0) { return null; } @@ -127,11 +122,6 @@ function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null return { label, - colorClass: - runningPorts.length >= 1 - ? "text-sky-600 dark:text-sky-300/90" - : "text-teal-600 dark:text-teal-300/90", - pulse: true, primaryWebPort: runningPorts[0] ?? null, }; } @@ -519,9 +509,10 @@ export default function Sidebar() { ); const terminalStatus = terminalStatusIndicator(thread); return ( - + ) : ( + + + + ) )} {formatRelativeTime(thread.createdAt)} - + ); })} diff --git a/apps/web/src/components/ThreadTerminalDrawer.tsx b/apps/web/src/components/ThreadTerminalDrawer.tsx index d9e544ab94..41cb7c5e16 100644 --- a/apps/web/src/components/ThreadTerminalDrawer.tsx +++ b/apps/web/src/components/ThreadTerminalDrawer.tsx @@ -1,10 +1,8 @@ import { FitAddon } from "@xterm/addon-fit"; -import { Plus, SquareSplitHorizontal, TerminalSquare, Trash2 } from "lucide-react"; +import { Globe, Plus, SquareSplitHorizontal, TerminalSquare, Trash2 } from "lucide-react"; import { type NativeApi } from "@t3tools/contracts"; import { Terminal, type ITheme } from "@xterm/xterm"; import { - type PointerEvent as ReactPointerEvent, - type ReactNode, useCallback, useEffect, useMemo, @@ -43,6 +41,45 @@ function writeSystemMessage(terminal: Terminal, message: string): void { terminal.write(`\r\n[terminal] ${message}\r\n`); } +interface TerminalRuntimeStatus { + label: string; + primaryWebPort: number | null; + extraWebPortCount: number; +} + +function normalizeRunningPorts(rawPorts: number[] | undefined): number[] { + if (!rawPorts) return []; + return [...new Set(rawPorts)] + .filter((port) => Number.isInteger(port) && port > 0 && port <= 65_535) + .toSorted((left, right) => left - right); +} + +function terminalRuntimeStatus( + terminalId: string, + runningTerminalIds: Set, + runningTerminalPorts: Record, +): TerminalRuntimeStatus | null { + if (!runningTerminalIds.has(terminalId)) { + return null; + } + + const runningPorts = normalizeRunningPorts(runningTerminalPorts[terminalId]); + const primaryWebPort = runningPorts[0] ?? null; + const extraWebPortCount = runningPorts.length > 1 ? runningPorts.length - 1 : 0; + const label = + runningPorts.length === 0 + ? "Terminal process running" + : runningPorts.length === 1 + ? `Open web server: http://localhost:${primaryWebPort}` + : `Open web server: http://localhost:${primaryWebPort} (detected web ports: ${runningPorts.join(", ")})`; + + return { + label, + primaryWebPort, + extraWebPortCount, + }; +} + function terminalThemeFromApp(): ITheme { const isDark = document.documentElement.classList.contains("dark"); const bodyStyles = getComputedStyle(document.body); @@ -413,6 +450,8 @@ interface ThreadTerminalDrawerProps { activeTerminalId: string; terminalGroups: ThreadTerminalGroup[]; activeTerminalGroupId: string; + runningTerminalIds: string[]; + runningTerminalPorts: Record; focusRequestId: number; onSplitTerminal: () => void; onNewTerminal: () => void; @@ -427,7 +466,7 @@ interface TerminalActionButtonProps { label: string; className: string; onClick: () => void; - children: ReactNode; + children: React.ReactNode; } function TerminalActionButton({ label, className, onClick, children }: TerminalActionButtonProps) { @@ -467,6 +506,8 @@ export default function ThreadTerminalDrawer({ activeTerminalId, terminalGroups, activeTerminalGroupId, + runningTerminalIds, + runningTerminalPorts, focusRequestId, onSplitTerminal, onNewTerminal, @@ -587,6 +628,10 @@ export default function ThreadTerminalDrawer({ ), [normalizedTerminalIds], ); + const runningTerminalIdSet = useMemo( + () => new Set(runningTerminalIds.map((terminalId) => terminalId.trim())), + [runningTerminalIds], + ); useEffect(() => { onHeightChangeRef.current = onHeightChange; @@ -610,7 +655,7 @@ export default function ThreadTerminalDrawer({ lastSyncedHeightRef.current = clampedHeight; }, [height, threadId]); - const handleResizePointerDown = useCallback((event: ReactPointerEvent) => { + const handleResizePointerDown = useCallback((event: React.PointerEvent) => { if (event.button !== 0) return; event.preventDefault(); event.currentTarget.setPointerCapture(event.pointerId); @@ -622,7 +667,7 @@ export default function ThreadTerminalDrawer({ }; }, []); - const handleResizePointerMove = useCallback((event: ReactPointerEvent) => { + const handleResizePointerMove = useCallback((event: React.PointerEvent) => { const resizeState = resizeStateRef.current; if (!resizeState || resizeState.pointerId !== event.pointerId) return; event.preventDefault(); @@ -638,7 +683,7 @@ export default function ThreadTerminalDrawer({ }, []); const handleResizePointerEnd = useCallback( - (event: ReactPointerEvent) => { + (event: React.PointerEvent) => { const resizeState = resizeStateRef.current; if (!resizeState || resizeState.pointerId !== event.pointerId) return; resizeStateRef.current = null; @@ -679,6 +724,15 @@ export default function ThreadTerminalDrawer({ }; }, [syncHeight]); + const openWebPort = useCallback( + (event: React.MouseEvent, port: number) => { + event.preventDefault(); + event.stopPropagation(); + void api.shell.openExternal(`http://localhost:${port}`).catch(() => undefined); + }, + [api], + ); + return (