@@ -113,6 +113,11 @@ export function useSelectedThreadGitActions() {
113113 ) ,
114114 ) ;
115115 }
116+ const checkoutMove = checkoutMoveRequestFork ( thread , nextState , selectedThreadProject ) ; // fork-hook: zmux-estate/checkout-move-request
117+ if ( checkoutMove ) {
118+ // A new worktree moves through the server, so the thread's sessions follow it.
119+ return moveThreadCheckout ( { environmentId : thread . environmentId , input : checkoutMove } ) ;
120+ } // fork-hook: zmux-estate/checkout-move-update-result
116121 return updateThreadMetadata ( {
117122 environmentId : thread . environmentId ,
118123 input : {
@@ -122,7 +127,7 @@ export function useSelectedThreadGitActions() {
122127 } ,
123128 } ) ;
124129 } ,
125- [ updateThreadMetadata ] ,
130+ [ moveThreadCheckout , selectedThreadProject , updateThreadMetadata ] , // fork-hook: zmux-estate/checkout-move-update-result
126131 ) ;
127132
128133 const refreshSelectedThreadGitStatus = useCallback (
@@ -237,9 +242,13 @@ export function useSelectedThreadGitActions() {
237242 } ;
238243 } ) : Promise < AtomCommandResult < void , unknown > > => {
239244 // Git already changed; refresh even if metadata updates fail so the sheet shows the current branch.
240- const updateResult = input . nextThreadState
245+ const checkoutMoveRequested =
246+ input . nextThreadState !== undefined &&
247+ checkoutMoveRequestFork ( input . thread , input . nextThreadState , selectedThreadProject ) !==
248+ null ; // fork-hook: zmux-estate/checkout-move-request
249+ const updateResult : AtomCommandResult < unknown , unknown > = input . nextThreadState
241250 ? await updateThreadGitContext ( input . thread , input . nextThreadState )
242- : AsyncResult . success ( undefined ) ;
251+ : AsyncResult . success ( undefined ) ; // fork-hook: zmux-estate/checkout-move-update-result
243252 branchState . refresh ( ) ;
244253 if ( ! checkoutMoveRequested ) {
245254 await refreshSelectedThreadGitStatus ( { quiet : true , cwd : input . cwd } ) ;
@@ -248,13 +257,7 @@ export function useSelectedThreadGitActions() {
248257 ? AsyncResult . failure ( updateResult . cause )
249258 : AsyncResult . success ( undefined ) ;
250259 } ,
251- [
252- branchState ,
253- moveThreadCheckout ,
254- refreshSelectedThreadGitStatus ,
255- selectedThreadProject ,
256- updateThreadGitContext ,
257- ] ,
260+ [ branchState , refreshSelectedThreadGitStatus , selectedThreadProject , updateThreadGitContext ] , // fork-hook: zmux-estate/checkout-move-request
258261 ) ;
259262
260263 const onCheckoutSelectedThreadBranch = useCallback (
@@ -451,3 +454,21 @@ export function useSelectedThreadGitActions() {
451454 onRunSelectedThreadGitAction,
452455 } ;
453456}
457+
458+ function checkoutMoveRequestFork (
459+ thread : EnvironmentThreadShell ,
460+ nextState : { readonly worktreePath ?: string | null } ,
461+ project : EnvironmentProject | null ,
462+ ) {
463+ // The server checkout move a thread's next worktree needs, or null when it stays put.
464+ if ( ! project || nextState . worktreePath === undefined ) return null ;
465+ if ( nextState . worktreePath === thread . worktreePath ) return null ;
466+ return {
467+ threadId : thread . id ,
468+ requestedPath : nextState . worktreePath ?? project . workspaceRoot ,
469+ expectedCheckoutRoot :
470+ ( thread . checkoutMove ? checkoutMoveExpectedRoot ( thread . checkoutMove ) : null ) ??
471+ thread . worktreePath ??
472+ project . workspaceRoot ,
473+ } ;
474+ } // fork-hook: zmux-estate/checkout-move-request
0 commit comments