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
This commit is contained in:
Julius Marminge committed 2026-02-15 18:25:22 -08:00
1 parent b3e967e2cf
commit c11027be4d
3 files changed
+145 -77

No files matched your search

+2
View File
@@ -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}
+38 -56
View File
@@ -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 (
<button
<div
key={thread.id}
type="button"
role="button"
tabIndex={0}
className={`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors duration-150 ${
isActive
? "bg-accent text-foreground"
@@ -533,6 +524,14 @@ export default function Sidebar() {
threadId: thread.id,
})
}
onKeyDown={(event) => {
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
dispatch({
type: "SET_ACTIVE_THREAD",
threadId: thread.id,
});
}}
onContextMenu={(e) => {
e.preventDefault();
void handleThreadContextMenu(thread.id, {
@@ -558,52 +557,35 @@ export default function Sidebar() {
</div>
<div className="ml-2 flex shrink-0 items-center gap-1.5">
{terminalStatus && (
<span className="inline-flex items-center">
{terminalStatus.primaryWebPort !== null ? (
<span
role="link"
tabIndex={0}
aria-label={terminalStatus.label}
title={terminalStatus.label}
className={`inline-flex items-center justify-center ${terminalStatus.colorClass}`}
onClick={(event) =>
openWebPort(event, terminalStatus.primaryWebPort!)
}
onKeyDown={(event) => {
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
event.stopPropagation();
if (!api) return;
void api.shell
.openExternal(
`http://localhost:${terminalStatus.primaryWebPort!}`,
)
.catch(() => undefined);
}}
>
<GlobeIcon
className={`size-3 ${terminalStatus.pulse ? "animate-pulse" : ""}`}
/>
</span>
) : (
<span
role="img"
aria-label={terminalStatus.label}
title={terminalStatus.label}
className={`inline-flex items-center justify-center ${terminalStatus.colorClass}`}
>
<TerminalIcon
className={`size-3 ${terminalStatus.pulse ? "animate-pulse" : ""}`}
/>
</span>
)}
</span>
terminalStatus.primaryWebPort !== null ? (
<button
type="button"
aria-label={terminalStatus.label}
title={terminalStatus.label}
className="inline-flex items-center justify-center rounded p-0.5 text-sky-600 transition-colors hover:bg-accent hover:text-sky-700 dark:text-sky-300/90 dark:hover:text-sky-200"
onClick={(event) => openWebPort(event, terminalStatus.primaryWebPort!)}
onKeyDown={(event) =>
event.stopPropagation()
}
>
<GlobeIcon className="size-2.5 shrink-0" />
</button>
) : (
<span
role="img"
aria-label={terminalStatus.label}
title={terminalStatus.label}
className="inline-flex items-center justify-center text-teal-600 dark:text-teal-300/90"
>
<TerminalSquareIcon className="size-2.5 animate-pulse" />
</span>
)
)}
<span className="text-[10px] text-muted-foreground/40">
{formatRelativeTime(thread.createdAt)}
</span>
</div>
</button>
</div>
);
})}
+105 -21
View File
@@ -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<string>,
runningTerminalPorts: Record<string, number[]>,
): 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<string, number[]>;
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<HTMLDivElement>) => {
const handleResizePointerDown = useCallback((event: React.PointerEvent<HTMLDivElement>) => {
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<HTMLDivElement>) => {
const handleResizePointerMove = useCallback((event: React.PointerEvent<HTMLDivElement>) => {
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<HTMLDivElement>) => {
(event: React.PointerEvent<HTMLDivElement>) => {
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<HTMLButtonElement>, port: number) => {
event.preventDefault();
event.stopPropagation();
void api.shell.openExternal(`http://localhost:${port}`).catch(() => undefined);
},
[api],
);
return (
<aside
className="thread-terminal-drawer relative flex shrink-0 flex-col border-t border-border/80 bg-background"
@@ -841,6 +895,11 @@ export default function ThreadTerminalDrawer({
>
{terminalGroup.terminalIds.map((terminalId) => {
const isActive = terminalId === resolvedActiveTerminalId;
const runtimeStatus = terminalRuntimeStatus(
terminalId,
runningTerminalIdSet,
runningTerminalPorts,
);
return (
<div
key={terminalId}
@@ -863,20 +922,45 @@ export default function ThreadTerminalDrawer({
{terminalLabelById.get(terminalId) ?? "Terminal"}
</span>
</button>
{normalizedTerminalIds.length > 1 && (
<button
type="button"
className="rounded px-1 text-xs font-medium leading-none text-muted-foreground opacity-0 transition hover:bg-accent hover:text-foreground group-hover:opacity-100"
onClick={(event) => {
event.stopPropagation();
onCloseTerminal(terminalId);
}}
aria-label={`Close ${terminalLabelById.get(terminalId) ?? "terminal"}`}
title={`Close ${terminalLabelById.get(terminalId) ?? "terminal"}`}
>
×
</button>
)}
<div className="ml-auto inline-flex items-center gap-0.5">
{runtimeStatus &&
(runtimeStatus.primaryWebPort === null ? (
<span
role="img"
aria-label={runtimeStatus.label}
title={runtimeStatus.label}
className="inline-flex items-center justify-center text-teal-600 dark:text-teal-300/90"
>
<TerminalSquare className="size-2.5 animate-pulse" />
</span>
) : (
<button
type="button"
className="inline-flex items-center justify-center rounded p-0.5 text-sky-600 transition-colors hover:bg-accent hover:text-sky-700 dark:text-sky-300/90 dark:hover:text-sky-200"
onClick={(event) =>
openWebPort(event, runtimeStatus.primaryWebPort!)
}
aria-label={runtimeStatus.label}
title={runtimeStatus.label}
>
<Globe className="size-2.5 shrink-0" />
</button>
))}
{normalizedTerminalIds.length > 1 && (
<button
type="button"
className="rounded px-1 text-xs font-medium leading-none text-muted-foreground opacity-0 transition hover:bg-accent hover:text-foreground group-hover:opacity-100"
onClick={(event) => {
event.stopPropagation();
onCloseTerminal(terminalId);
}}
aria-label={`Close ${terminalLabelById.get(terminalId) ?? "terminal"}`}
title={`Close ${terminalLabelById.get(terminalId) ?? "terminal"}`}
>
×
</button>
)}
</div>
</div>
);
})}