Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

BranchToolbar.tsx

682 lines25.6 KB

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