Open History to see the last commit
1import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
2import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
3import {
4 ChevronDownIcon,
5 FolderGit2Icon,
6 FolderGitIcon,
7 FolderIcon,
8 HistoryIcon,
9 ScaleIcon,
10} from "lucide-react";
11import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
12
13import { useComposerDraftStore, type DraftId } from "../composerDraftStore";
14import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
15import { useProject, useThread, useThreadShellsForProjectRefs } from "../state/entities";
16import {
17 type EnvMode,
18 type EnvironmentOption,
19 resolveContextStripLabelsCompact,
20 resolveCurrentWorkspaceLabel,
21 resolveEnvModeLabel,
22 resolveEffectiveEnvMode,
23 resolveLockedWorkspaceLabel,
24 resolvePreviousWorktreeLabel,
25 resolvePreviousWorktreeSeed,
26 shouldShowEnvironmentIndicator,
27} from "./BranchToolbar.logic";
28import { BranchToolbarBranchSelector } from "./BranchToolbarBranchSelector";
29import { BranchToolbarEnvironmentSelector } from "./BranchToolbarEnvironmentSelector";
30import { BranchToolbarEnvModeSelector } from "./BranchToolbarEnvModeSelector";
31import { Button } from "./ui/button";
32import {
33 Menu,
34 MenuGroup,
35 MenuGroupLabel,
36 MenuPopup,
37 MenuRadioGroup,
38 MenuRadioItem,
39 MenuSeparator,
40 MenuTrigger,
41} from "./ui/menu";
42import { Separator } from "./ui/separator";
43import { ComposerSurface } from "./chat/ComposerSurface";
44import { composerFloatingLayerProps } from "./chat/composerEventScope";
45import { measureRestingComposerControls } from "./chat/restingComposerControlsMeasurement";
46import { resolveRestingComposerControlsNaturalWidth } from "./composerFooterLayout";
47import { cn } from "~/lib/utils";
48
49interface BranchToolbarProps {
50 environmentId: EnvironmentId;
51 threadId: ThreadId;
52 showGitControls: boolean;
53 draftId?: DraftId;
54 onEnvModeChange: (mode: EnvMode) => void;
55 effectiveEnvModeOverride?: EnvMode;
56 activeThreadBranchOverride?: string | null;
57 onActiveThreadBranchOverrideChange?: (branch: string | null) => void;
58 startFromOrigin: boolean;
59 onStartFromOriginChange: (startFromOrigin: boolean) => void;
60 autoEnvironmentLabel?: string | undefined;
61 onAutoEnvironment?: (() => void) | undefined;
62 envLocked: boolean;
63 onCheckoutPullRequestRequest?: (reference: string) => void;
64 onComposerFocusRequest?: () => void;
65 availableEnvironments?: readonly EnvironmentOption[];
66 onEnvironmentChange?: (environmentId: EnvironmentId) => void;
67 composerControlsHostRef?: (element: HTMLDivElement | null) => void;
68 contextStripVisible?: boolean;
69}
70
71interface MobileRunContextSelectorProps {
72 autoEnvironmentLabel?: string | undefined;
73 onAutoEnvironment?: (() => void) | undefined;
74 envLocked: boolean;
75 envModeLocked: boolean;
76 environmentId: EnvironmentId;
77 availableEnvironments: readonly EnvironmentOption[] | undefined;
78 showEnvironmentPicker: boolean;
79 showEnvironmentIndicator: boolean;
80 onEnvironmentChange: ((environmentId: EnvironmentId) => void) | undefined;
81 effectiveEnvMode: EnvMode;
82 activeWorktreePath: string | null;
83 onEnvModeChange: (mode: EnvMode) => void;
84 previousWorktreeLabel: string | null;
85 onUsePreviousWorktree: () => void;
86}
87
88const MobileRunContextSelector = memo(function MobileRunContextSelector({
89 autoEnvironmentLabel,
90 onAutoEnvironment,
91 envLocked,
92 envModeLocked,
93 environmentId,
94 availableEnvironments,
95 showEnvironmentPicker,
96 showEnvironmentIndicator,
97 onEnvironmentChange,
98 effectiveEnvMode,
99 activeWorktreePath,
100 onEnvModeChange,
101 previousWorktreeLabel,
102 onUsePreviousWorktree,
103}: MobileRunContextSelectorProps) {
104 const activeEnvironment = useMemo(
105 () => availableEnvironments?.find((env) => env.environmentId === environmentId) ?? null,
106 [availableEnvironments, environmentId],
107 );
108 const WorkspaceIcon =
109 effectiveEnvMode === "worktree"
110 ? FolderGit2Icon
111 : activeWorktreePath
112 ? FolderGitIcon
113 : FolderIcon;
114 const workspaceLabel = envModeLocked
115 ? resolveLockedWorkspaceLabel(activeWorktreePath)
116 : effectiveEnvMode === "worktree"
117 ? resolveEnvModeLabel("worktree")
118 : resolveCurrentWorkspaceLabel(activeWorktreePath);
119 const isLocked = envLocked || envModeLocked;
120 const icon = showEnvironmentIndicator ? (
121 // Button's base styles apply `-mx-0.5` to descendant SVGs, which eats 4px
122 // out of whatever gap we set. mx-0! cancels that so gap-0.5 reads as 2px.
123 <span className="inline-flex shrink-0 items-center gap-0.5">
124 {autoEnvironmentLabel ? (
125 <ScaleIcon className="size-3 shrink-0 mx-0!" aria-hidden="true" />
126 ) : (
127 <EnvironmentMachineIcon
128 kind={activeEnvironment?.machine ?? "server"}
129 className="size-3 shrink-0 mx-0!"
130 />
131 )}
132 <WorkspaceIcon className="size-3 shrink-0 mx-0!" />
133 </span>
134 ) : (
135 <WorkspaceIcon className="size-3 shrink-0" />
136 );
137 const triggerContent = (
138 <>
139 {icon}
140 <span
141 data-composer-label
142 className="min-w-0 max-w-[240px] group-data-[compact]/composer-context:max-w-0"
143 >
144 <span
145 data-composer-label-motion
146 className="block w-full min-w-0 max-w-[240px] origin-left truncate transition-[opacity,transform] duration-180 ease-[cubic-bezier(0.32,0.72,0,1)] group-data-[compact]/composer-context:[transform:translateX(-0.25rem)_scaleX(0.95)] group-data-[compact]/composer-context:opacity-0 motion-reduce:transform-none motion-reduce:transition-opacity"
147 >
148 {autoEnvironmentLabel ??
149 (showEnvironmentIndicator ? (activeEnvironment?.label ?? "Run on") : workspaceLabel)}
150 </span>
151 </span>
152 </>
153 );
154
155 if (isLocked) {
156 return (
157 <span
158 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-[calc(--spacing(2)-1px)] font-normal text-muted-foreground/70 text-xs sm:h-6"
159 data-composer-context-control
160 >
161 {triggerContent}
162 </span>
163 );
164 }
165
166 return (
167 <Menu>
168 <MenuTrigger
169 render={<Button variant="ghost" size="xs" />}
170 className="min-w-0 max-w-[48%] flex-initial justify-start font-normal text-muted-foreground/70 text-xs! hover:text-foreground/80"
171 data-composer-context-control
172 >
173 {triggerContent}
174 <ChevronDownIcon className="size-3 shrink-0 opacity-50" />
175 </MenuTrigger>
176 <MenuPopup align="start" side="top" className="w-64" {...composerFloatingLayerProps}>
177 {showEnvironmentPicker && availableEnvironments && onEnvironmentChange ? (
178 <>
179 <MenuGroup>
180 <MenuGroupLabel>Run on</MenuGroupLabel>
181 <MenuRadioGroup
182 value={autoEnvironmentLabel ? "auto" : environmentId}
183 onValueChange={(value) =>
184 value === "auto"
185 ? onAutoEnvironment?.()
186 : onEnvironmentChange(value as EnvironmentId)
187 }
188 >
189 {onAutoEnvironment && (
190 <MenuRadioItem
191 value="auto"
192 disabled={envLocked}
193 onClick={() => {
194 if (autoEnvironmentLabel) onAutoEnvironment?.();
195 }}
196 >
197 <span className="flex min-w-0 items-center gap-1.5">
198 <ScaleIcon className="size-3" aria-hidden="true" />
199 <span className="min-w-0 truncate">
200 {autoEnvironmentLabel ?? "Auto balance"}
201 </span>
202 </span>
203 </MenuRadioItem>
204 )}
205 {availableEnvironments.map((env) => (
206 <MenuRadioItem
207 key={env.environmentId}
208 disabled={envLocked}
209 value={env.environmentId}
210 >
211 <span className="flex min-w-0 items-center gap-1.5">
212 <EnvironmentMachineIcon kind={env.machine} className="size-3" />
213 <span className="min-w-0 truncate">{env.label}</span>
214 </span>
215 </MenuRadioItem>
216 ))}
217 </MenuRadioGroup>
218 </MenuGroup>
219 <MenuSeparator />
220 </>
221 ) : null}
222 <MenuGroup>
223 <MenuGroupLabel>Workspace</MenuGroupLabel>
224 <MenuRadioGroup
225 value={effectiveEnvMode}
226 onValueChange={(value) => {
227 if (value === "previous-worktree") {
228 onUsePreviousWorktree();
229 return;
230 }
231 onEnvModeChange(value as EnvMode);
232 }}
233 >
234 <MenuRadioItem disabled={envModeLocked} value="local">
235 <span className="flex min-w-0 items-center gap-1.5">
236 {activeWorktreePath ? (
237 <FolderGitIcon className="size-3" />
238 ) : (
239 <FolderIcon className="size-3" />
240 )}
241 <span className="min-w-0 truncate">
242 {resolveCurrentWorkspaceLabel(activeWorktreePath)}
243 </span>
244 </span>
245 </MenuRadioItem>
246 <MenuRadioItem disabled={envModeLocked} value="worktree">
247 <span className="flex min-w-0 items-center gap-1.5">
248 <FolderGit2Icon className="size-3" />
249 <span className="min-w-0 truncate">{resolveEnvModeLabel("worktree")}</span>
250 </span>
251 </MenuRadioItem>
252 {previousWorktreeLabel ? (
253 <MenuRadioItem disabled={envModeLocked} value="previous-worktree">
254 <span className="flex min-w-0 items-center gap-1.5">
255 <HistoryIcon className="size-3" />
256 <span className="min-w-0 truncate">{previousWorktreeLabel}</span>
257 </span>
258 </MenuRadioItem>
259 ) : null}
260 </MenuRadioGroup>
261 </MenuGroup>
262 </MenuPopup>
263 </Menu>
264 );
265});
266
267/**
268 * Collapse the strip's labels to icons only when the text no longer fits.
269 *
270 * Hidden labels stay measurable because their inner text keeps its natural
271 * width while the outer layout box collapses. This lets every pass recompute
272 * the expanded width without remembered values that could go stale or latch
273 * the strip compact. A small hysteresis keeps the boundary from flapping.
274 */
275const COMPOSER_CONTEXT_MOTION_DURATION_MS = 180;
276const COMPOSER_CONTEXT_MOTION_EASING = "cubic-bezier(0.32, 0.72, 0, 1)";
277const COMPOSER_CONTEXT_CONTROL_SELECTOR = "[data-composer-context-control]";
278
279function useLabelsOverflow(element: HTMLDivElement | null): boolean {
280 const [overflows, setOverflows] = useState(false);
281 const pendingControlRectsRef = useRef<Map<HTMLElement, DOMRect> | null>(null);
282 const controlAnimationsRef = useRef(new Map<HTMLElement, Animation>());
283 // A render-synced mirror instead of useEffectEvent: the compiler memoizes
284 // the event callback, which left observers reading the first render's null
285 // element forever.
286 const stateRef = useRef({ element, overflows });
287 stateRef.current = { element, overflows };
288
289 const measure = useCallback(() => {
290 const { element: current, overflows: compact } = stateRef.current;
291 if (!current) return;
292 const available = current.clientWidth;
293 if (available === 0) return;
294 // flex-1 stretches the groups to fill the strip, so their own boxes always
295 // measure "full". Sum the laid-out content instead, skipping hidden form
296 // artifacts and other out-of-flow nodes.
297 const contentWidth = (parent: Element): number => {
298 const gap = Number.parseFloat(getComputedStyle(parent).columnGap) || 0;
299 let width = 0;
300 let counted = 0;
301 for (const child of parent.children) {
302 if (!(child instanceof HTMLElement)) continue;
303 if (child.offsetWidth === 0) continue;
304 const style = getComputedStyle(child);
305 const position = style.position;
306 if (position === "absolute" || position === "fixed") continue;
307 width +=
308 child.offsetWidth +
309 (Number.parseFloat(style.marginInlineStart) || 0) +
310 (Number.parseFloat(style.marginInlineEnd) || 0);
311 counted += 1;
312 }
313 return width + gap * Math.max(0, counted - 1);
314 };
315 const stripGap = Number.parseFloat(getComputedStyle(current).columnGap) || 0;
316 let needed = 0;
317 let groups = 0;
318 for (const child of current.children) {
319 if (!(child instanceof HTMLElement)) continue;
320 // The host itself flexes into all remaining room. Reserve the natural
321 // width of the controls inside it, blocks in overflow included, so Git
322 // labels compact before squeezing out the model picker. Reserving only
323 // the visible controls would let the labels expand into room the
324 // composer just freed, shrink the host, and hide the controls again.
325 const hostedControls = child.matches('[data-chat-resting-composer-controls-host="true"]')
326 ? child.querySelector<HTMLElement>('[data-chat-composer-resting-controls="true"]')
327 : null;
328 const hostedMeasurement = hostedControls
329 ? measureRestingComposerControls(hostedControls)
330 : null;
331 const width = hostedMeasurement
332 ? resolveRestingComposerControlsNaturalWidth(hostedMeasurement)
333 : contentWidth(hostedControls ?? child);
334 if (width <= 1) continue;
335 groups += 1;
336 needed += width;
337 }
338 needed += stripGap * Math.max(0, groups - 1);
339 for (const label of current.querySelectorAll<HTMLElement>("[data-composer-label]")) {
340 // The clipping can happen below the marker (SelectValue truncates
341 // internally), where the outer span's scrollWidth matches its clipped
342 // box. The text's real width is the largest scrollWidth in the subtree.
343 let textWidth = label.scrollWidth;
344 for (const inner of label.querySelectorAll<HTMLElement>("*")) {
345 textWidth = Math.max(textWidth, inner.scrollWidth);
346 }
347 if (compact) {
348 // Compact: the label is squeezed to zero width but keeps reporting
349 // the full width it would need when expanded.
350 needed += textWidth;
351 } else {
352 // Expanded: the label is in flow; only the clipped remainder is
353 // missing from the content sum.
354 needed += Math.max(0, textWidth - label.clientWidth);
355 }
356 }
357 const nextOverflows = resolveContextStripLabelsCompact({
358 compact,
359 neededWidth: needed,
360 availableWidth: available,
361 });
362 if (nextOverflows !== compact) {
363 pendingControlRectsRef.current = new Map(
364 Array.from(current.querySelectorAll<HTMLElement>(COMPOSER_CONTEXT_CONTROL_SELECTOR)).map(
365 (control) => [control, control.getBoundingClientRect()],
366 ),
367 );
368 }
369 setOverflows(nextOverflows);
370 }, []);
371
372 useLayoutEffect(() => {
373 const previousRects = pendingControlRectsRef.current;
374 if (!previousRects) return;
375 pendingControlRectsRef.current = null;
376
377 for (const animation of controlAnimationsRef.current.values()) {
378 animation.cancel();
379 }
380 controlAnimationsRef.current.clear();
381
382 if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
383
384 for (const [control, previousRect] of previousRects) {
385 if (!control.isConnected) continue;
386 const nextRect = control.getBoundingClientRect();
387 const deltaX = previousRect.left - nextRect.left;
388 const deltaY = previousRect.top - nextRect.top;
389 if (Math.abs(deltaX) < 0.5 && Math.abs(deltaY) < 0.5) continue;
390
391 const animation = control.animate(
392 [
393 { transform: `translate3d(${deltaX}px, ${deltaY}px, 0)` },
394 { transform: "translate3d(0, 0, 0)" },
395 ],
396 {
397 duration: COMPOSER_CONTEXT_MOTION_DURATION_MS,
398 easing: COMPOSER_CONTEXT_MOTION_EASING,
399 fill: "backwards",
400 },
401 );
402 controlAnimationsRef.current.set(control, animation);
403 animation.addEventListener(
404 "finish",
405 () => {
406 if (controlAnimationsRef.current.get(control) === animation) {
407 controlAnimationsRef.current.delete(control);
408 }
409 },
410 { once: true },
411 );
412 }
413 }, [overflows]);
414
415 useEffect(
416 () => () => {
417 for (const animation of controlAnimationsRef.current.values()) {
418 animation.cancel();
419 }
420 },
421 [],
422 );
423
424 // Label widths can change without the strip box moving (font family or
425 // size preferences), so re-measure on every render as well as on resize
426 // and font loads.
427 useLayoutEffect(() => {
428 measure();
429 });
430
431 useEffect(() => {
432 if (!element) return;
433 const observer = new ResizeObserver(measure);
434 observer.observe(element);
435 document.fonts.addEventListener("loadingdone", measure);
436 return () => {
437 observer.disconnect();
438 document.fonts.removeEventListener("loadingdone", measure);
439 };
440 }, [element, measure]);
441
442 return overflows;
443}
444
445export const BranchToolbar = memo(function BranchToolbar({
446 environmentId,
447 threadId,
448 showGitControls,
449 draftId,
450 onEnvModeChange,
451 effectiveEnvModeOverride,
452 activeThreadBranchOverride,
453 onActiveThreadBranchOverrideChange,
454 startFromOrigin,
455 onStartFromOriginChange,
456 autoEnvironmentLabel,
457 onAutoEnvironment,
458 envLocked,
459 onCheckoutPullRequestRequest,
460 onComposerFocusRequest,
461 availableEnvironments,
462 onEnvironmentChange,
463 composerControlsHostRef,
464 contextStripVisible = true,
465}: BranchToolbarProps) {
466 const threadRef = useMemo(
467 () => scopeThreadRef(environmentId, threadId),
468 [environmentId, threadId],
469 );
470 const draftThread = useComposerDraftStore((store) =>
471 draftId ? store.getDraftSession(draftId) : store.getDraftThreadByRef(threadRef),
472 );
473 const serverThread = useThread(threadRef, { waitForShell: draftThread !== null });
474 const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
475 const activeProjectRef = serverThread
476 ? scopeProjectRef(serverThread.environmentId, serverThread.projectId)
477 : draftThread
478 ? scopeProjectRef(draftThread.environmentId, draftThread.projectId)
479 : null;
480 const activeProject = useProject(activeProjectRef);
481 const hasActiveThread = serverThread !== null || draftThread !== null;
482 const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
483 const effectiveEnvMode =
484 effectiveEnvModeOverride ??
485 resolveEffectiveEnvMode({
486 activeWorktreePath,
487 hasServerThread: serverThread !== null,
488 draftThreadEnvMode: draftThread?.envMode,
489 });
490 const envModeLocked = envLocked || (serverThread !== null && activeWorktreePath !== null);
491
492 // "Previous worktree" hops a draft into the most recently active worktree
493 // of this project — the "keep going where I just was" follow-up flow. Only
494 // drafts can hop; started server threads have their workspace pinned.
495 const canUsePreviousWorktree = draftThread !== null && serverThread === null && !envModeLocked;
496 const projectRefsForWorktreeLookup = useMemo(
497 () => (canUsePreviousWorktree && activeProjectRef ? [activeProjectRef] : []),
498 [canUsePreviousWorktree, activeProjectRef],
499 );
500 const projectThreads = useThreadShellsForProjectRefs(projectRefsForWorktreeLookup);
501 const previousWorktreeSeed = useMemo(
502 () =>
503 canUsePreviousWorktree
504 ? resolvePreviousWorktreeSeed({
505 threads: projectThreads,
506 currentWorktreePath: activeWorktreePath,
507 })
508 : null,
509 [activeWorktreePath, canUsePreviousWorktree, projectThreads],
510 );
511 const previousWorktreeLabel = previousWorktreeSeed
512 ? resolvePreviousWorktreeLabel(previousWorktreeSeed)
513 : null;
514 const onUsePreviousWorktree = useCallback(() => {
515 if (!previousWorktreeSeed || !activeProjectRef) return;
516 // Same shape the branch selector writes when picking a branch that
517 // already lives in a worktree: point the draft at the existing tree.
518 setDraftThreadContext(draftId ?? threadRef, {
519 branch: previousWorktreeSeed.branch,
520 worktreePath: previousWorktreeSeed.worktreePath,
521 envMode: "worktree",
522 projectRef: activeProjectRef,
523 });
524 }, [activeProjectRef, draftId, previousWorktreeSeed, setDraftThreadContext, threadRef]);
525
526 const showEnvironmentPicker = Boolean(
527 availableEnvironments && availableEnvironments.length > 1 && onEnvironmentChange,
528 );
529 const activeEnvironmentOption =
530 availableEnvironments?.find((env) => env.environmentId === environmentId) ?? null;
531 const showEnvironmentIndicator = shouldShowEnvironmentIndicator({
532 activeEnvironment: activeEnvironmentOption,
533 canPickEnvironment: showEnvironmentPicker,
534 });
535 const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);
536 const labelsOverflow = useLabelsOverflow(stripElement);
537
538 if (!hasActiveThread || !activeProject) return null;
539
540 return (
541 <ComposerSurface.ContextStrip
542 ref={setStripElement}
543 data-compact={labelsOverflow ? "" : undefined}
544 className={cn(
545 "gap-1 text-xs font-normal text-muted-foreground/70",
546 // A non-Git strip with no visible composer controls should occupy no
547 // space, but its host must retain a prospective width so controls can
548 // become visible again when the chat view grows.
549 !contextStripVisible && "pointer-events-none invisible absolute inset-x-0 top-full",
550 )}
551 >
552 {showGitControls ? (
553 <div className="contents @3xl/composer-surface:hidden">
554 <MobileRunContextSelector
555 autoEnvironmentLabel={autoEnvironmentLabel}
556 onAutoEnvironment={onAutoEnvironment}
557 envLocked={envLocked}
558 envModeLocked={envModeLocked}
559 environmentId={environmentId}
560 availableEnvironments={availableEnvironments}
561 showEnvironmentPicker={showEnvironmentPicker}
562 showEnvironmentIndicator={showEnvironmentIndicator}
563 onEnvironmentChange={onEnvironmentChange}
564 effectiveEnvMode={effectiveEnvMode}
565 activeWorktreePath={activeWorktreePath}
566 onEnvModeChange={onEnvModeChange}
567 previousWorktreeLabel={previousWorktreeLabel}
568 onUsePreviousWorktree={onUsePreviousWorktree}
569 />
570 </div>
571 ) : null}
572 {showGitControls || showEnvironmentIndicator ? (
573 <div
574 className={cn(
575 "min-h-7 min-w-10 items-center gap-1 sm:min-h-6",
576 showGitControls ? "hidden @3xl/composer-surface:flex" : "flex",
577 composerControlsHostRef ? "shrink" : "flex-1",
578 )}
579 >
580 {showEnvironmentIndicator && availableEnvironments && (
581 <>
582 <BranchToolbarEnvironmentSelector
583 autoEnvironmentLabel={autoEnvironmentLabel}
584 onAutoEnvironment={onAutoEnvironment}
585 envLocked={envLocked}
586 environmentId={environmentId}
587 availableEnvironments={availableEnvironments}
588 {...(showEnvironmentPicker && onEnvironmentChange ? { onEnvironmentChange } : {})}
589 />
590 {showGitControls ? (
591 <Separator
592 orientation="vertical"
593 className="mx-0.5 h-3.5!"
594 data-composer-context-control
595 />
596 ) : null}
597 </>
598 )}
599 {showGitControls ? (
600 <BranchToolbarEnvModeSelector
601 envLocked={envModeLocked}
602 effectiveEnvMode={effectiveEnvMode}
603 activeWorktreePath={activeWorktreePath}
604 onEnvModeChange={onEnvModeChange}
605 previousWorktreeLabel={previousWorktreeLabel}
606 onUsePreviousWorktree={onUsePreviousWorktree}
607 />
608 ) : null}
609 </div>
610 ) : null}
611
612 {composerControlsHostRef ? (
613 // The host takes whatever the workspace and branch controls leave
614 // over, in both strip layouts, so a collapsed composer can show its
615 // model and mode controls wherever they fit.
616 <div
617 ref={composerControlsHostRef}
618 data-composer-context-control
619 data-chat-resting-composer-controls-host="true"
620 className="flex min-w-0 flex-1 items-center justify-start overflow-x-clip overflow-y-visible"
621 />
622 ) : null}
623
624 {showGitControls ? (
625 <BranchToolbarBranchSelector
626 className="min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
627 environmentId={environmentId}
628 threadId={threadId}
629 {...(draftId ? { draftId } : {})}
630 envLocked={envLocked}
631 {...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
632 {...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
633 {...(onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange } : {})}
634 startFromOrigin={startFromOrigin}
635 onStartFromOriginChange={onStartFromOriginChange}
636 {...(onCheckoutPullRequestRequest ? { onCheckoutPullRequestRequest } : {})}
637 {...(onComposerFocusRequest ? { onComposerFocusRequest } : {})}
638 />
639 ) : null}
640 </ComposerSurface.ContextStrip>
641 );
642});