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

BranchToolbar.tsx

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