@@ -221,7 +221,11 @@ import {
221221import { appendPreviewAnnotationPrompt } from "../lib/previewAnnotation" ;
222222import { appendReviewCommentsToPrompt , type ReviewCommentContext } from "../reviewCommentContext" ;
223223import { environmentCatalog } from "../connection/catalog" ;
224- import { selectThreadTerminalUiState , useTerminalUiStateStore } from "../terminalUiStateStore" ;
224+ import {
225+ selectThreadTerminalCustomLabels ,
226+ selectThreadTerminalUiState ,
227+ useTerminalUiStateStore ,
228+ } from "../terminalUiStateStore" ;
225229import { useKnownTerminalSessions , useThreadRunningTerminalIds } from "../state/terminalSessions" ;
226230import { projectEnvironment } from "../state/projects" ;
227231import { useEnvironmentQuery } from "../state/query" ;
@@ -658,6 +662,7 @@ interface PersistentThreadTerminalDrawerProps {
658662 newShortcutLabel : string | undefined ;
659663 closeShortcutLabel : string | undefined ;
660664 keybindings : ResolvedKeybindingsConfig ;
665+ onHide : ( ) => void ;
661666 onAddTerminalContext : ( selection : TerminalContextSelection ) => void ;
662667}
663668
@@ -672,6 +677,7 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
672677 newShortcutLabel,
673678 closeShortcutLabel,
674679 keybindings,
680+ onHide,
675681 onAddTerminalContext,
676682} : PersistentThreadTerminalDrawerProps ) {
677683 const openTerminal = useAtomCommand ( terminalEnvironment . open , "terminal open" ) ;
@@ -787,8 +793,14 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
787793 ) {
788794 return ;
789795 }
790- reconcileTerminalIds ( threadRef , serverOrderedTerminalIds ) ;
791- } , [ reconcileTerminalIds , serverOrderedTerminalIds , terminalUiState . terminalIds , threadRef ] ) ;
796+ reconcileTerminalIds ( threadRef , serverOrderedTerminalIds , [ ...panelTerminalIds ] ) ;
797+ } , [
798+ panelTerminalIds ,
799+ reconcileTerminalIds ,
800+ serverOrderedTerminalIds ,
801+ terminalUiState . terminalIds ,
802+ threadRef ,
803+ ] ) ;
792804 const [ localFocusRequestId , setLocalFocusRequestId ] = useState ( 0 ) ;
793805 const worktreePath = serverThread ?. worktreePath ?? draftThread ?. worktreePath ?? null ;
794806 const effectiveWorktreePath = useMemo ( ( ) => {
@@ -995,6 +1007,7 @@ const PersistentThreadTerminalDrawer = memo(function PersistentThreadTerminalDra
9951007 onSplitTerminal = { splitTerminal }
9961008 onSplitTerminalVertical = { splitTerminalVertical }
9971009 onNewTerminal = { createNewTerminal }
1010+ onHide = { onHide }
9981011 splitShortcutLabel = { visible ? splitShortcutLabel : undefined }
9991012 splitVerticalShortcutLabel = { visible ? splitVerticalShortcutLabel : undefined }
10001013 newShortcutLabel = { visible ? newShortcutLabel : undefined }
@@ -1557,6 +1570,16 @@ function ChatViewContent(props: ChatViewProps) {
15571570 const canCheckoutPullRequestIntoThread = isLocalDraftThread ;
15581571 const activeThreadId = activeThread ?. id ?? null ;
15591572 const activeThreadEnvironmentId = activeThread ?. environmentId ?? null ;
1573+ const activeThreadRef = useMemo (
1574+ ( ) =>
1575+ activeThreadEnvironmentId && activeThreadId
1576+ ? scopeThreadRef ( activeThreadEnvironmentId , activeThreadId )
1577+ : null ,
1578+ [ activeThreadEnvironmentId , activeThreadId ] ,
1579+ ) ;
1580+ const activeTerminalCustomLabels = useTerminalUiStateStore ( ( state ) =>
1581+ selectThreadTerminalCustomLabels ( state . terminalCustomLabelsByThreadKey , activeThreadRef ) ,
1582+ ) ;
15601583 const runningTerminalIds = useThreadRunningTerminalIds ( {
15611584 environmentId : activeThread ?. environmentId ?? null ,
15621585 threadId : activeThreadId ,
@@ -1586,18 +1609,15 @@ function ChatViewContent(props: ChatViewProps) {
15861609 for ( const session of activeThreadKnownSessions ) {
15871610 labels . set (
15881611 session . target . terminalId ,
1589- resolveTerminalSessionLabel ( session . target . terminalId , session . state . summary ) ,
1612+ activeTerminalCustomLabels [ session . target . terminalId ] ??
1613+ resolveTerminalSessionLabel ( session . target . terminalId , session . state . summary ) ,
15901614 ) ;
15911615 }
1616+ for ( const [ terminalId , label ] of Object . entries ( activeTerminalCustomLabels ) ) {
1617+ if ( ! labels . has ( terminalId ) ) labels . set ( terminalId , label ) ;
1618+ }
15921619 return labels ;
1593- } , [ activeThreadKnownSessions ] ) ;
1594- const activeThreadRef = useMemo (
1595- ( ) =>
1596- activeThreadEnvironmentId && activeThreadId
1597- ? scopeThreadRef ( activeThreadEnvironmentId , activeThreadId )
1598- : null ,
1599- [ activeThreadEnvironmentId , activeThreadId ] ,
1600- ) ;
1620+ } , [ activeTerminalCustomLabels , activeThreadKnownSessions ] ) ;
16011621 const activeThreadKey = activeThreadRef ? scopedThreadKey ( activeThreadRef ) : null ;
16021622 const changeRequestSnapshotByKey = useAtomValue ( threadChangeRequestSnapshotsAtom ) ;
16031623 const [ timelineAnchor , setTimelineAnchor ] = useState < {
@@ -2826,6 +2846,7 @@ function ChatViewContent(props: ChatViewProps) {
28262846 } ,
28272847 [ activeThreadRef , storeSetTerminalOpen ] ,
28282848 ) ;
2849+ const hideTerminal = useCallback ( ( ) => setTerminalOpen ( false ) , [ setTerminalOpen ] ) ;
28292850 const toggleTerminalVisibility = useCallback ( ( ) => {
28302851 if ( ! activeThreadRef ) return ;
28312852 const nextOpen = ! terminalUiState . terminalOpen ;
@@ -6603,6 +6624,7 @@ function ChatViewContent(props: ChatViewProps) {
66036624 newShortcutLabel = { newTerminalShortcutLabel ?? undefined }
66046625 closeShortcutLabel = { closeTerminalShortcutLabel ?? undefined }
66056626 keybindings = { keybindings }
6627+ onHide = { hideTerminal }
66066628 onAddTerminalContext = { addTerminalContextToDraft }
66076629 />
66086630 ) ) }
0 commit comments