1+ import { writeTextToClipboard } from "../hooks/useCopyToClipboard" ;
2+ import { readLocalApi } from "../localApi" ;
3+ import { stackedThreadToast , toastManager } from "./ui/toast" ;
14import { ComposerContextLabel } from "./ComposerContextLabel" ;
25import { scopeProjectRef , scopeThreadRef } from "@t3tools/client-runtime/environment" ;
36import type { EnvironmentId , ThreadId } from "@t3tools/contracts" ;
@@ -10,6 +13,7 @@ import {
1013} from "lucide-react" ;
1114import {
1215 type Ref ,
16+ type MouseEvent as ReactMouseEvent ,
1317 memo ,
1418 useImperativeHandle ,
1519 useCallback ,
@@ -41,6 +45,11 @@ import {
4145import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector" ;
4246import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector" ;
4347import { PreviousWorktreeItemContent } from "./PreviousWorktreeItemContent" ;
48+ import { ThreadDetailsControl } from "./chat/ThreadDetailsControl" ;
49+ import {
50+ THREAD_DETAILS_PANEL_ICON_CLASS ,
51+ THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS ,
52+ } from "./chat/threadDetailsPanelStyles" ;
4453import { ComposerControl } from "./chat/ComposerControl" ;
4554import {
4655 Menu ,
@@ -93,7 +102,44 @@ interface BranchToolbarProps {
93102 contextStripVisible ?: boolean ;
94103}
95104
96- interface MobileRunContextSelectorProps {
105+ function showWorkspaceContextMenu ( event : ReactMouseEvent , workspacePath : string ) {
106+ const api = readLocalApi ( ) ;
107+ if ( ! api ) return ;
108+ event . preventDefault ( ) ;
109+ event . stopPropagation ( ) ;
110+ void api . contextMenu
111+ . show ( [ { id : "copy-path" , label : "Copy full path" , icon : "copy" } ] , {
112+ x : event . clientX ,
113+ y : event . clientY ,
114+ } )
115+ . then ( ( action ) => {
116+ if ( action !== "copy-path" ) return ;
117+ void writeTextToClipboard ( workspacePath , "workspace path" ) . then (
118+ ( didCopy ) => {
119+ if ( didCopy ) {
120+ toastManager . add ( {
121+ type : "success" ,
122+ title : "Path copied" ,
123+ description : workspacePath ,
124+ } ) ;
125+ }
126+ } ,
127+ ( error : unknown ) => {
128+ toastManager . add (
129+ stackedThreadToast ( {
130+ type : "error" ,
131+ title : "Failed to copy path" ,
132+ description : error instanceof Error ? error . message : "An error occurred." ,
133+ } ) ,
134+ ) ;
135+ } ,
136+ ) ;
137+ } ) ;
138+ }
139+
140+ interface RunContextSelectorProps {
141+ displayMode ?: "toolbar" | "panel" ;
142+ workspaceRoot ?: string ;
97143 forceNewWorktree : boolean ;
98144 autoEnvironmentLabel ?: string | undefined ;
99145 onAutoEnvironment ?: ( ( ) => void ) | undefined ;
@@ -112,7 +158,9 @@ interface MobileRunContextSelectorProps {
112158 onUsePreviousWorktree : ( ) => void ;
113159}
114160
115- const MobileRunContextSelector = memo ( function MobileRunContextSelector ( {
161+ const RunContextSelector = memo ( function RunContextSelector ( {
162+ displayMode = "toolbar" ,
163+ workspaceRoot,
116164 forceNewWorktree,
117165 autoEnvironmentLabel,
118166 onAutoEnvironment,
@@ -129,7 +177,7 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
129177 previousWorktreeLabel,
130178 previousWorktreeBranch,
131179 onUsePreviousWorktree,
132- } : MobileRunContextSelectorProps ) {
180+ } : RunContextSelectorProps ) {
133181 const composerFloatingLayerProps = useComposerMenuProps ( ) ;
134182 const activeEnvironment = useMemo (
135183 ( ) => availableEnvironments ?. find ( ( env ) => env . environmentId === environmentId ) ?? null ,
@@ -148,13 +196,32 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
148196 : effectiveEnvMode === "worktree"
149197 ? resolveEnvModeLabel ( "worktree" )
150198 : resolveCurrentWorkspaceLabel ( activeWorktreePath ) ;
151- const isLocked = envLocked || envModeLocked ;
199+ const isPanel = displayMode === "panel" ;
200+ const isLocked = envLocked || ( envModeLocked && ( ! isPanel || ! showEnvironmentPicker ) ) ;
201+ const workspacePath = forceNewWorktree ? null : ( activeWorktreePath ?? workspaceRoot ) ;
202+ const handleContextMenu = ( event : ReactMouseEvent ) => {
203+ if ( isPanel && workspacePath ) {
204+ showWorkspaceContextMenu ( event , workspacePath ) ;
205+ }
206+ } ;
152207 const workspaceIcon = (
153208 < Tooltip >
154209 < TooltipTrigger render = { < span className = "inline-flex shrink-0" /> } >
155- < WorkspaceIcon className = { cn ( "size-3 shrink-0" , showEnvironmentIndicator && "mx-0!" ) } />
210+ < WorkspaceIcon
211+ className = {
212+ isPanel
213+ ? THREAD_DETAILS_PANEL_ICON_CLASS
214+ : cn ( "size-3 shrink-0" , showEnvironmentIndicator && "mx-0!" )
215+ }
216+ />
156217 </ TooltipTrigger >
157- < TooltipPopup > { workspaceLabel } </ TooltipPopup >
218+ < TooltipPopup >
219+ { isPanel
220+ ? forceNewWorktree
221+ ? "Each model starts in its own worktree."
222+ : ( workspacePath ?? workspaceLabel )
223+ : workspaceLabel }
224+ </ TooltipPopup >
158225 </ Tooltip >
159226 ) ;
160227 const icon = showEnvironmentIndicator ? (
@@ -164,11 +231,14 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
164231 < Tooltip >
165232 < TooltipTrigger render = { < span className = "inline-flex shrink-0" /> } >
166233 { autoEnvironmentLabel ? (
167- < ScaleIcon className = "size-3 shrink-0 mx-0!" aria-hidden = "true" />
234+ < ScaleIcon
235+ className = { isPanel ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3 shrink-0 mx-0!" }
236+ aria-hidden = "true"
237+ />
168238 ) : (
169239 < EnvironmentMachineIcon
170240 kind = { activeEnvironment ?. machine ?? "server" }
171- className = "size-3 shrink-0 mx-0!"
241+ className = { isPanel ? THREAD_DETAILS_PANEL_ICON_CLASS : "size-3 shrink-0 mx-0!" }
172242 />
173243 ) }
174244 </ TooltipTrigger >
@@ -182,7 +252,7 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
182252 const triggerContent = (
183253 < >
184254 { icon }
185- < ComposerContextLabel >
255+ < ComposerContextLabel displayMode = { displayMode } >
186256 { autoEnvironmentLabel ??
187257 ( showEnvironmentIndicator ? ( activeEnvironment ?. label ?? "Run on" ) : workspaceLabel ) }
188258 </ ComposerContextLabel >
@@ -192,7 +262,13 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
192262 if ( isLocked ) {
193263 return (
194264 < span
195- className = "inline-flex h-7 min-w-0 max-w-[48%] flex-initial items-center justify-start gap-1 rounded-md border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6"
265+ className = { cn (
266+ "inline-flex h-7 min-w-0 max-w-[48%] flex-initial items-center justify-start gap-1 rounded-md border border-transparent px-1.75 font-normal text-muted-foreground/70 text-xs sm:h-6" ,
267+ isPanel && "max-w-full" ,
268+ isPanel && THREAD_DETAILS_PANEL_LOCKED_ROW_CLASS ,
269+ ) }
270+ onContextMenu = { handleContextMenu }
271+ aria-label = { isPanel ? "Run context" : undefined }
196272 data-composer-context-control
197273 >
198274 { triggerContent }
@@ -203,22 +279,37 @@ const MobileRunContextSelector = memo(function MobileRunContextSelector({
203279 return (
204280 < Menu >
205281 < MenuTrigger
206- render = { < ComposerControl size = "xs" /> }
207- className = "min-w-0 max-w-[48%] flex-initial justify-start"
282+ render = { isPanel ? < ThreadDetailsControl part = "select" /> : < ComposerControl size = "xs" /> }
283+ className = { isPanel ? undefined : "min-w-0 max-w-[48%] flex-initial justify-start" }
284+ onContextMenu = { handleContextMenu }
285+ onMouseDownCapture = {
286+ isPanel
287+ ? ( event ) => {
288+ if ( event . button !== 0 || event . ctrlKey ) event . stopPropagation ( ) ;
289+ }
290+ : undefined
291+ }
292+ aria-label = { isPanel ? "Run context" : undefined }
208293 data-composer-context-control
209294 data-composer-shortcut = { [
210295 showEnvironmentPicker && ! envLocked ? "composer.host" : "" ,
211296 ! envModeLocked ? "composer.workspace" : "" ,
212297 ] . join ( " " ) }
213298 >
214299 { triggerContent }
215- < ChevronDownIcon className = "size-3 shrink-0 opacity-50" />
300+ { ! isPanel ? < ChevronDownIcon className = "size-3 shrink-0 opacity-50" /> : null }
216301 </ MenuTrigger >
217302 < MenuPopup
218303 align = "start"
219- side = "top"
220- className = { previousWorktreeLabel ? "w-[min(21rem,calc(100vw-2rem))]" : undefined }
221- { ...composerFloatingLayerProps }
304+ side = { isPanel ? "bottom" : "top" }
305+ className = {
306+ isPanel
307+ ? "w-(--anchor-width)"
308+ : previousWorktreeLabel
309+ ? "w-[min(21rem,calc(100vw-2rem))]"
310+ : undefined
311+ }
312+ { ...( ! isPanel ? composerFloatingLayerProps : { } ) }
222313 >
223314 { showEnvironmentPicker && availableEnvironments && onEnvironmentChange ? (
224315 < >
@@ -618,13 +709,25 @@ export const BranchToolbar = memo(function BranchToolbar({
618709 return (
619710 < div className = "flex w-full flex-col" data-thread-panel-run-context >
620711 { panelSection !== "branch" ? (
621- < BranchToolbarEnvModeSelector
712+ < RunContextSelector
622713 displayMode = "panel"
623- envLocked = { envModeLocked }
714+ workspaceRoot = { activeProject . workspaceRoot }
715+ forceNewWorktree = { forceNewWorktree }
716+ autoEnvironmentLabel = { autoEnvironmentLabel }
717+ onAutoEnvironment = { onAutoEnvironment }
718+ envLocked = { envLocked }
719+ envModeLocked = { envModeLocked }
720+ environmentId = { environmentId }
721+ availableEnvironments = { availableEnvironments }
722+ showEnvironmentPicker = { showEnvironmentPicker }
723+ showEnvironmentIndicator = { activeEnvironmentOption !== null }
724+ onEnvironmentChange = { onEnvironmentChange }
624725 effectiveEnvMode = { effectiveEnvMode }
625726 activeWorktreePath = { activeWorktreePath }
626- workspaceRoot = { activeProject . workspaceRoot }
627727 onEnvModeChange = { onEnvModeChange }
728+ previousWorktreeLabel = { previousWorktreeLabel }
729+ previousWorktreeBranch = { previousWorktreeSeed ?. branch ?? null }
730+ onUsePreviousWorktree = { onUsePreviousWorktree }
628731 />
629732 ) : null }
630733 { panelSection !== "workspace" ? (
@@ -662,7 +765,7 @@ export const BranchToolbar = memo(function BranchToolbar({
662765 >
663766 { showGitControls ? (
664767 < div className = "contents @3xl/composer-surface:hidden" >
665- < MobileRunContextSelector
768+ < RunContextSelector
666769 forceNewWorktree = { forceNewWorktree }
667770 autoEnvironmentLabel = { autoEnvironmentLabel }
668771 onAutoEnvironment = { onAutoEnvironment }
0 commit comments