@@ -66,6 +66,7 @@ export interface BranchToolbarHandle {
6666}
6767
6868interface BranchToolbarProps {
69+ forceNewWorktree ?: boolean ;
6970 ref ?: Ref < BranchToolbarHandle > ;
7071 environmentId : EnvironmentId ;
7172 threadId : ThreadId ;
@@ -89,6 +90,7 @@ interface BranchToolbarProps {
8990}
9091
9192interface MobileRunContextSelectorProps {
93+ forceNewWorktree : boolean ;
9294 autoEnvironmentLabel ?: string | undefined ;
9395 onAutoEnvironment ?: ( ( ) => void ) | undefined ;
9496 envLocked : boolean ;
@@ -106,6 +108,7 @@ interface MobileRunContextSelectorProps {
106108}
107109
108110const MobileRunContextSelector = memo ( function MobileRunContextSelector ( {
111+ forceNewWorktree,
109112 autoEnvironmentLabel,
110113 onAutoEnvironment,
111114 envLocked,
@@ -132,11 +135,13 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
132135 : activeWorktreePath
133136 ? FolderGitIcon
134137 : FolderIcon ;
135- const workspaceLabel = envModeLocked
136- ? resolveLockedWorkspaceLabel ( activeWorktreePath )
137- : effectiveEnvMode === "worktree"
138- ? resolveEnvModeLabel ( "worktree" )
139- : resolveCurrentWorkspaceLabel ( activeWorktreePath ) ;
138+ const workspaceLabel = forceNewWorktree
139+ ? resolveEnvModeLabel ( "worktree" )
140+ : envModeLocked
141+ ? resolveLockedWorkspaceLabel ( activeWorktreePath )
142+ : effectiveEnvMode === "worktree"
143+ ? resolveEnvModeLabel ( "worktree" )
144+ : resolveCurrentWorkspaceLabel ( activeWorktreePath ) ;
140145 const isLocked = envLocked || envModeLocked ;
141146 const workspaceIcon = (
142147 < Tooltip >
@@ -269,7 +274,7 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
269274 onEnvModeChange ( value as EnvMode ) ;
270275 } }
271276 >
272- < MenuRadioItem disabled = { envModeLocked } value = "local" >
277+ < MenuRadioItem disabled = { envModeLocked || forceNewWorktree } value = "local" >
273278 < span className = "flex min-w-0 items-center gap-1.5" >
274279 { activeWorktreePath ? (
275280 < FolderGitIcon className = "size-3" />
@@ -476,6 +481,7 @@ function useLabelsOverflow(element: HTMLDivElement | null): boolean {
476481}
477482
478483export const BranchToolbar = memo ( function BranchToolbar ( {
484+ forceNewWorktree = false ,
479485 ref,
480486 environmentId,
481487 threadId,
@@ -514,9 +520,11 @@ export const BranchToolbar = memo(function BranchToolbar({
514520 : null ;
515521 const activeProject = useProject ( activeProjectRef ) ;
516522 const hasActiveThread = serverThread !== null || draftThread !== null ;
517- const activeWorktreePath = serverThread ?. worktreePath ?? draftThread ?. worktreePath ?? null ;
523+ const activeWorktreePath = forceNewWorktree
524+ ? null
525+ : ( serverThread ?. worktreePath ?? draftThread ?. worktreePath ?? null ) ;
518526 const effectiveEnvMode =
519- effectiveEnvModeOverride ??
527+ ( forceNewWorktree ? "worktree" : effectiveEnvModeOverride ) ??
520528 resolveEffectiveEnvMode ( {
521529 activeWorktreePath,
522530 hasServerThread : serverThread !== null ,
@@ -527,7 +535,8 @@ export const BranchToolbar = memo(function BranchToolbar({
527535 // "Previous worktree" hops a draft into the most recently active worktree
528536 // of this project — the "keep going where I just was" follow-up flow. Only
529537 // drafts can hop; started server threads have their workspace pinned.
530- const canUsePreviousWorktree = draftThread !== null && serverThread === null && ! envModeLocked ;
538+ const canUsePreviousWorktree =
539+ draftThread !== null && serverThread === null && ! envModeLocked && ! forceNewWorktree ;
531540 const projectRefsForWorktreeLookup = useMemo (
532541 ( ) => ( canUsePreviousWorktree && activeProjectRef ? [ activeProjectRef ] : [ ] ) ,
533542 [ canUsePreviousWorktree , activeProjectRef ] ,
@@ -606,6 +615,7 @@ export const BranchToolbar = memo(function BranchToolbar({
606615 { showGitControls ? (
607616 < div className = "contents @3xl/composer-surface:hidden" >
608617 < MobileRunContextSelector
618+ forceNewWorktree = { forceNewWorktree }
609619 autoEnvironmentLabel = { autoEnvironmentLabel }
610620 onAutoEnvironment = { onAutoEnvironment }
611621 envLocked = { envLocked }
@@ -652,6 +662,7 @@ export const BranchToolbar = memo(function BranchToolbar({
652662 ) }
653663 { showGitControls ? (
654664 < BranchToolbarEnvModeSelector
665+ forceNewWorktree = { forceNewWorktree }
655666 envLocked = { envModeLocked }
656667 effectiveEnvMode = { effectiveEnvMode }
657668 activeWorktreePath = { activeWorktreePath }
@@ -677,13 +688,18 @@ export const BranchToolbar = memo(function BranchToolbar({
677688
678689 { showGitControls ? (
679690 < BranchToolbarBranchSelector
691+ forceNewWorktree = { forceNewWorktree }
680692 ref = { branchSelectorRef }
681693 className = "min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
682694 environmentId = { environmentId }
683695 threadId = { threadId }
684696 { ...( draftId ? { draftId } : { } ) }
685697 envLocked = { envLocked }
686- { ...( effectiveEnvModeOverride ? { effectiveEnvModeOverride } : { } ) }
698+ { ...( forceNewWorktree
699+ ? { effectiveEnvModeOverride : "worktree" }
700+ : effectiveEnvModeOverride
701+ ? { effectiveEnvModeOverride }
702+ : { } ) }
687703 { ...( activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : { } ) }
688704 { ...( onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange } : { } ) }
689705 startFromOrigin = { startFromOrigin }
0 commit comments