@@ -117,6 +117,11 @@ import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries";
117117import { isCommandPaletteOpen } from "../commandPaletteBus" ;
118118import { buildTemporaryWorktreeBranchName } from "@t3tools/shared/git" ;
119119import { useMediaQuery } from "../hooks/useMediaQuery" ;
120+ import {
121+ clearPlanSidebarDismissal ,
122+ dismissPlanSidebarForTurn ,
123+ isPlanSidebarDismissedForTurn ,
124+ } from "../planSidebarDismissal" ;
120125import { RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY } from "../rightPanelLayout" ;
121126import {
122127 selectActiveRightPanel ,
@@ -1310,8 +1315,6 @@ function ChatViewContent(props: ChatViewProps) {
13101315 const [ pendingUserInputQuestionIndexByRequestId , setPendingUserInputQuestionIndexByRequestId ] =
13111316 useState < Record < string , number > > ( { } ) ;
13121317 const shouldUsePlanSidebarSheet = useMediaQuery ( RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY ) ;
1313- // Tracks whether the user explicitly dismissed the sidebar for the active turn.
1314- const planSidebarDismissedForTurnRef = useRef < string | null > ( null ) ;
13151318 // When set, the thread-change reset effect will open the sidebar instead of closing it.
13161319 // Used by "Implement in a new thread" to carry the sidebar-open intent across navigation.
13171320 const planSidebarOpenOnNextThreadRef = useRef ( false ) ;
@@ -3110,18 +3113,21 @@ function ChatViewContent(props: ChatViewProps) {
31103113 handleInteractionModeChange ( interactionMode === "plan" ? "default" : "plan" ) ;
31113114 } , [ handleInteractionModeChange , interactionMode ] ) ;
31123115 const dismissPlanSidebarForCurrentTurn = useCallback ( ( ) => {
3113- planSidebarDismissedForTurnRef . current =
3114- activePlan ?. turnId ?? sidebarProposedPlan ?. turnId ?? "__dismissed__" ;
3115- } , [ activePlan ?. turnId , sidebarProposedPlan ?. turnId ] ) ;
3116+ if ( ! activeThreadKey ) return ;
3117+ dismissPlanSidebarForTurn (
3118+ activeThreadKey ,
3119+ activePlan ?. turnId ?? sidebarProposedPlan ?. turnId ?? "__dismissed__" ,
3120+ ) ;
3121+ } , [ activeThreadKey , activePlan ?. turnId , sidebarProposedPlan ?. turnId ] ) ;
31163122 const togglePlanSidebar = useCallback ( ( ) => {
31173123 if ( ! activeThreadRef ) return ;
31183124 if ( planSidebarOpen ) {
31193125 dismissPlanSidebarForCurrentTurn ( ) ;
3120- } else {
3121- planSidebarDismissedForTurnRef . current = null ;
3126+ } else if ( activeThreadKey ) {
3127+ clearPlanSidebarDismissal ( activeThreadKey ) ;
31223128 }
31233129 useRightPanelStore . getState ( ) . toggle ( activeThreadRef , "plan" ) ;
3124- } , [ activeThreadRef , dismissPlanSidebarForCurrentTurn , planSidebarOpen ] ) ;
3130+ } , [ activeThreadKey , activeThreadRef , dismissPlanSidebarForCurrentTurn , planSidebarOpen ] ) ;
31253131 const closePlanSidebar = useCallback ( ( ) => {
31263132 if ( ! activeThreadRef ) return ;
31273133 setMaximizedRightPanelThreadKey ( null ) ;
@@ -3283,7 +3289,7 @@ function ChatViewContent(props: ChatViewProps) {
32833289 ( surface : RightPanelSurface ) => {
32843290 if ( ! activeThreadRef ) return ;
32853291 if ( surface . kind === "plan" ) {
3286- planSidebarDismissedForTurnRef . current = null ;
3292+ clearPlanSidebarDismissal ( scopedThreadKey ( activeThreadRef ) ) ;
32873293 } else if ( planSidebarOpen ) {
32883294 dismissPlanSidebarForCurrentTurn ( ) ;
32893295 }
@@ -3852,10 +3858,10 @@ function ChatViewContent(props: ChatViewProps) {
38523858 if ( planSidebarOpenOnNextThreadRef . current ) {
38533859 planSidebarOpenOnNextThreadRef . current = false ;
38543860 if ( activeThreadRef ) {
3861+ clearPlanSidebarDismissal ( scopedThreadKey ( activeThreadRef ) ) ;
38553862 useRightPanelStore . getState ( ) . open ( activeThreadRef , "plan" ) ;
38563863 }
38573864 }
3858- planSidebarDismissedForTurnRef . current = null ;
38593865 // activeThreadRef resets transitively with the active thread.
38603866 } , [ activeThread ?. id ] ) ;
38613867
@@ -3868,10 +3874,9 @@ function ChatViewContent(props: ChatViewProps) {
38683874 const latestTurnId = activeLatestTurn ?. turnId ?? null ;
38693875 if ( latestTurnId && activePlan . turnId !== latestTurnId ) return ;
38703876 const turnKey = activePlan . turnId ?? sidebarProposedPlan ?. turnId ?? "__dismissed__" ;
3871- if ( planSidebarDismissedForTurnRef . current === turnKey ) return ;
3872- if ( activeThreadRef ) {
3873- useRightPanelStore . getState ( ) . open ( activeThreadRef , "plan" ) ;
3874- }
3877+ if ( ! activeThreadRef ) return ;
3878+ if ( isPlanSidebarDismissedForTurn ( scopedThreadKey ( activeThreadRef ) , turnKey ) ) return ;
3879+ useRightPanelStore . getState ( ) . open ( activeThreadRef , "plan" ) ;
38753880 } , [
38763881 activePlan ,
38773882 activeLatestTurn ?. turnId ,
@@ -5412,8 +5417,8 @@ function ChatViewContent(props: ChatViewProps) {
54125417 // "default" mode here means the agent is executing the plan, which produces
54135418 // step-tracking activities that the sidebar will display.
54145419 if ( nextInteractionMode === "default" && autoOpenPlanSidebar ) {
5415- planSidebarDismissedForTurnRef . current = null ;
54165420 if ( activeThreadRef ) {
5421+ clearPlanSidebarDismissal ( scopedThreadKey ( activeThreadRef ) ) ;
54175422 useRightPanelStore . getState ( ) . open ( activeThreadRef , "plan" ) ;
54185423 }
54195424 }
0 commit comments