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