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, useThreadShell, 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] truncate transition-opacity duration-180 ease-[cubic-bezier(0.32,0.72,0,1)] group-data-[compact]/composer-context:opacity-0 motion-reduce:transition-none"
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_LABEL_SELECTOR = "[data-composer-label]";
278
279function useLabelsOverflow(element: HTMLDivElement | null): boolean {
280 const [overflows, setOverflows] = useState(false);
281 const pendingLabelRectsRef = useRef<Map<HTMLElement, DOMRect> | null>(null);
282 const labelAnimationsRef = 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 // Subtract the visible width even during an animation. The content
348 // sum already includes it; only the hidden text needs reserving.
349 needed += Math.max(0, textWidth - label.getBoundingClientRect().width);
350 }
351 const nextOverflows = resolveContextStripLabelsCompact({
352 compact,
353 neededWidth: needed,
354 availableWidth: available,
355 });
356 if (nextOverflows !== compact) {
357 pendingLabelRectsRef.current = new Map(
358 Array.from(current.querySelectorAll<HTMLElement>(COMPOSER_CONTEXT_LABEL_SELECTOR)).map(
359 (label) => [label, label.getBoundingClientRect()],
360 ),
361 );
362 }
363 setOverflows(nextOverflows);
364 }, []);
365
366 useLayoutEffect(() => {
367 const previousRects = pendingLabelRectsRef.current;
368 if (!previousRects) return;
369 pendingLabelRectsRef.current = null;
370
371 for (const animation of labelAnimationsRef.current.values()) {
372 animation.cancel();
373 }
374 labelAnimationsRef.current.clear();
375
376 if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
377
378 for (const [label, previousRect] of previousRects) {
379 if (!label.isConnected) continue;
380 const nextWidth = label.getBoundingClientRect().width;
381 if (Math.abs(previousRect.width - nextWidth) < 0.5) continue;
382
383 // Animate the space occupied by each label so flex layout keeps the
384 // trailing controls anchored. Translating the whole group after its
385 // width snaps sends expanded text beyond the strip's right edge.
386 const animation = label.animate(
387 [
388 { width: `${previousRect.width}px`, maxWidth: `${previousRect.width}px` },
389 { width: `${nextWidth}px`, maxWidth: `${nextWidth}px` },
390 ],
391 {
392 duration: COMPOSER_CONTEXT_MOTION_DURATION_MS,
393 easing: COMPOSER_CONTEXT_MOTION_EASING,
394 fill: "backwards",
395 },
396 );
397 labelAnimationsRef.current.set(label, animation);
398 animation.addEventListener(
399 "finish",
400 () => {
401 if (labelAnimationsRef.current.get(label) === animation) {
402 labelAnimationsRef.current.delete(label);
403 }
404 },
405 { once: true },
406 );
407 }
408 }, [overflows]);
409
410 useEffect(
411 () => () => {
412 for (const animation of labelAnimationsRef.current.values()) {
413 animation.cancel();
414 }
415 },
416 [],
417 );
418
419 // Label widths can change without the strip box moving (font family or
420 // size preferences), so re-measure on every render as well as on resize
421 // and font loads.
422 useLayoutEffect(() => {
423 measure();
424 });
425
426 useEffect(() => {
427 if (!element) return;
428 const observer = new ResizeObserver(measure);
429 observer.observe(element);
430 document.fonts.addEventListener("loadingdone", measure);
431 return () => {
432 observer.disconnect();
433 document.fonts.removeEventListener("loadingdone", measure);
434 };
435 }, [element, measure]);
436
437 return overflows;
438}
439
440export const BranchToolbar = memo(function BranchToolbar({
441 environmentId,
442 threadId,
443 showGitControls,
444 draftId,
445 onEnvModeChange,
446 effectiveEnvModeOverride,
447 activeThreadBranchOverride,
448 onActiveThreadBranchOverrideChange,
449 startFromOrigin,
450 onStartFromOriginChange,
451 autoEnvironmentLabel,
452 onAutoEnvironment,
453 envLocked,
454 onCheckoutPullRequestRequest,
455 onComposerFocusRequest,
456 availableEnvironments,
457 onEnvironmentChange,
458 composerControlsHostRef,
459 contextStripVisible = true,
460}: BranchToolbarProps) {
461 const threadRef = useMemo(
462 () => scopeThreadRef(environmentId, threadId),
463 [environmentId, threadId],
464 );
465 const draftThread = useComposerDraftStore((store) =>
466 draftId ? store.getDraftSession(draftId) : store.getDraftThreadByRef(threadRef),
467 );
468 const serverThread = useThreadShell(threadRef);
469 const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
470 const activeProjectRef = serverThread
471 ? scopeProjectRef(serverThread.environmentId, serverThread.projectId)
472 : draftThread
473 ? scopeProjectRef(draftThread.environmentId, draftThread.projectId)
474 : null;
475 const activeProject = useProject(activeProjectRef);
476 const hasActiveThread = serverThread !== null || draftThread !== null;
477 const activeWorktreePath = serverThread?.worktreePath ?? draftThread?.worktreePath ?? null;
478 const effectiveEnvMode =
479 effectiveEnvModeOverride ??
480 resolveEffectiveEnvMode({
481 activeWorktreePath,
482 hasServerThread: serverThread !== null,
483 draftThreadEnvMode: draftThread?.envMode,
484 });
485 const envModeLocked = envLocked || (serverThread !== null && activeWorktreePath !== null);
486
487 // "Previous worktree" hops a draft into the most recently active worktree
488 // of this project — the "keep going where I just was" follow-up flow. Only
489 // drafts can hop; started server threads have their workspace pinned.
490 const canUsePreviousWorktree = draftThread !== null && serverThread === null && !envModeLocked;
491 const projectRefsForWorktreeLookup = useMemo(
492 () => (canUsePreviousWorktree && activeProjectRef ? [activeProjectRef] : []),
493 [canUsePreviousWorktree, activeProjectRef],
494 );
495 const projectThreads = useThreadShellsForProjectRefs(projectRefsForWorktreeLookup);
496 const previousWorktreeSeed = useMemo(
497 () =>
498 canUsePreviousWorktree
499 ? resolvePreviousWorktreeSeed({
500 threads: projectThreads,
501 currentWorktreePath: activeWorktreePath,
502 })
503 : null,
504 [activeWorktreePath, canUsePreviousWorktree, projectThreads],
505 );
506 const previousWorktreeLabel = previousWorktreeSeed
507 ? resolvePreviousWorktreeLabel(previousWorktreeSeed)
508 : null;
509 const onUsePreviousWorktree = useCallback(() => {
510 if (!previousWorktreeSeed || !activeProjectRef) return;
511 // Same shape the branch selector writes when picking a branch that
512 // already lives in a worktree: point the draft at the existing tree.
513 setDraftThreadContext(draftId ?? threadRef, {
514 branch: previousWorktreeSeed.branch,
515 worktreePath: previousWorktreeSeed.worktreePath,
516 envMode: "worktree",
517 projectRef: activeProjectRef,
518 });
519 }, [activeProjectRef, draftId, previousWorktreeSeed, setDraftThreadContext, threadRef]);
520
521 const showEnvironmentPicker = Boolean(
522 availableEnvironments && availableEnvironments.length > 1 && onEnvironmentChange,
523 );
524 const activeEnvironmentOption =
525 availableEnvironments?.find((env) => env.environmentId === environmentId) ?? null;
526 const showEnvironmentIndicator = shouldShowEnvironmentIndicator({
527 activeEnvironment: activeEnvironmentOption,
528 canPickEnvironment: showEnvironmentPicker,
529 });
530 const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);
531 const labelsOverflow = useLabelsOverflow(stripElement);
532
533 if (!hasActiveThread || !activeProject) return null;
534
535 return (
536 <ComposerSurface.ContextStrip
537 ref={setStripElement}
538 data-compact={labelsOverflow ? "" : undefined}
539 className={cn(
540 "gap-1 text-xs font-normal text-muted-foreground/70",
541 // A non-Git strip with no visible composer controls should occupy no
542 // space, but its host must retain a prospective width so controls can
543 // become visible again when the chat view grows.
544 !contextStripVisible && "pointer-events-none invisible absolute inset-x-0 top-full",
545 )}
546 >
547 {showGitControls ? (
548 <div className="contents @3xl/composer-surface:hidden">
549 <MobileRunContextSelector
550 autoEnvironmentLabel={autoEnvironmentLabel}
551 onAutoEnvironment={onAutoEnvironment}
552 envLocked={envLocked}
553 envModeLocked={envModeLocked}
554 environmentId={environmentId}
555 availableEnvironments={availableEnvironments}
556 showEnvironmentPicker={showEnvironmentPicker}
557 showEnvironmentIndicator={showEnvironmentIndicator}
558 onEnvironmentChange={onEnvironmentChange}
559 effectiveEnvMode={effectiveEnvMode}
560 activeWorktreePath={activeWorktreePath}
561 onEnvModeChange={onEnvModeChange}
562 previousWorktreeLabel={previousWorktreeLabel}
563 onUsePreviousWorktree={onUsePreviousWorktree}
564 />
565 </div>
566 ) : null}
567 {showGitControls || showEnvironmentIndicator ? (
568 <div
569 className={cn(
570 "min-h-7 min-w-10 items-center gap-1 sm:min-h-6",
571 showGitControls ? "hidden @3xl/composer-surface:flex" : "flex",
572 composerControlsHostRef ? "shrink" : "flex-1",
573 )}
574 >
575 {showEnvironmentIndicator && availableEnvironments && (
576 <>
577 <BranchToolbarEnvironmentSelector
578 autoEnvironmentLabel={autoEnvironmentLabel}
579 onAutoEnvironment={onAutoEnvironment}
580 envLocked={envLocked}
581 environmentId={environmentId}
582 availableEnvironments={availableEnvironments}
583 {...(showEnvironmentPicker && onEnvironmentChange ? { onEnvironmentChange } : {})}
584 />
585 {showGitControls ? (
586 <Separator
587 orientation="vertical"
588 className="mx-0.5 h-3.5!"
589 data-composer-context-control
590 />
591 ) : null}
592 </>
593 )}
594 {showGitControls ? (
595 <BranchToolbarEnvModeSelector
596 envLocked={envModeLocked}
597 effectiveEnvMode={effectiveEnvMode}
598 activeWorktreePath={activeWorktreePath}
599 onEnvModeChange={onEnvModeChange}
600 previousWorktreeLabel={previousWorktreeLabel}
601 onUsePreviousWorktree={onUsePreviousWorktree}
602 />
603 ) : null}
604 </div>
605 ) : null}
606
607 {composerControlsHostRef ? (
608 // The host takes whatever the workspace and branch controls leave
609 // over, in both strip layouts, so a collapsed composer can show its
610 // model and mode controls wherever they fit.
611 <div
612 ref={composerControlsHostRef}
613 data-composer-context-control
614 data-chat-resting-composer-controls-host="true"
615 className="flex min-w-0 flex-1 items-center justify-start overflow-x-clip overflow-y-visible"
616 />
617 ) : null}
618
619 {showGitControls ? (
620 <BranchToolbarBranchSelector
621 className="min-w-0 flex-initial justify-end @3xl/composer-surface:ml-auto"
622 environmentId={environmentId}
623 threadId={threadId}
624 {...(draftId ? { draftId } : {})}
625 envLocked={envLocked}
626 {...(effectiveEnvModeOverride ? { effectiveEnvModeOverride } : {})}
627 {...(activeThreadBranchOverride !== undefined ? { activeThreadBranchOverride } : {})}
628 {...(onActiveThreadBranchOverrideChange ? { onActiveThreadBranchOverrideChange } : {})}
629 startFromOrigin={startFromOrigin}
630 onStartFromOriginChange={onStartFromOriginChange}
631 {...(onCheckoutPullRequestRequest ? { onCheckoutPullRequestRequest } : {})}
632 {...(onComposerFocusRequest ? { onComposerFocusRequest } : {})}
633 />
634 ) : null}
635 </ComposerSurface.ContextStrip>
636 );
637});