Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/web/src/components/BranchToolbar.panel.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ it("keeps machine choices usable when the combined row's workspace is locked", a
expect(onEnvironmentChange).toHaveBeenCalledWith("remote");
});

it("shows a started thread's primary machine as a static label in the composer", async () => {
await render({
layout: "composer",
showGitControls: false,
availableEnvironments: ["local", "remote"].map((id) => ({
environmentId: EnvironmentId.make(id),
projectId: ProjectId.make("project"),
label: id,
isPrimary: id === "local",
machine: "server",
})),
});
expect(container.textContent).toBe("local");
expect(container.querySelector("button")).toBeNull();
});

it.each([
["local", null, "/tmp/project"],
["worktree", null, null],
Expand Down
11 changes: 6 additions & 5 deletions apps/web/src/components/BranchToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,15 @@ export const BranchToolbar = memo(function BranchToolbar({
],
);

const showEnvironmentPicker = Boolean(
availableEnvironments && availableEnvironments.length > 1 && onEnvironmentChange,
);
const hasMultipleEnvironments = (availableEnvironments?.length ?? 0) > 1;
const showEnvironmentPicker = hasMultipleEnvironments && onEnvironmentChange !== undefined;
const activeEnvironmentOption =
availableEnvironments?.find((env) => env.environmentId === environmentId) ?? null;
// Started threads get no handler but still show which machine they run on,
// matching the strip visibility ChatView computes from the same inputs.
const showEnvironmentIndicator = shouldShowEnvironmentIndicator({
activeEnvironment: activeEnvironmentOption,
canPickEnvironment: showEnvironmentPicker,
canPickEnvironment: hasMultipleEnvironments,
});
const [stripElement, setStripElement] = useState<HTMLDivElement | null>(null);
const labelsOverflow = useLabelsOverflow(stripElement);
Expand Down Expand Up @@ -755,7 +756,7 @@ export const BranchToolbar = memo(function BranchToolbar({
envLocked={envLocked}
environmentId={environmentId}
availableEnvironments={availableEnvironments}
{...(showEnvironmentPicker && onEnvironmentChange ? { onEnvironmentChange } : {})}
{...(showEnvironmentPicker ? { onEnvironmentChange } : {})}
/>
{showGitControls ? (
<Separator
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,11 @@ export default function ChatView(props: ChatViewProps) {
? null
: clampFileAttachmentUploadBytes(advertisedFileAttachmentBytes);
const envLocked = Boolean(activeThread && (activeMessageCount > 0 || activeRuntime !== null));
// onEnvironmentChange only retargets an unsent draft. envLocked alone does not
// rule out a started thread: one whose machine is offline never loads its
// messages, so it would otherwise be offered a machine picker that does nothing.
const canChangeEnvironment =
hasMultipleEnvironments && !envLocked && draftId !== null && !draftThread?.promotedTo;

const loadBalancingSettings = useClientSettings((settings) => ({
loadBalancingEnabled: settings.loadBalancingEnabled,
Expand Down Expand Up @@ -5607,7 +5612,7 @@ export default function ChatView(props: ChatViewProps) {
"composer.mode": openComposerControl("composer.mode"),
"composer.workspace": openComposerControl("composer.workspace"),
"composer.cycleHost": ({ event }) => {
if (envLocked || !draftId || !hasMultipleEnvironments) return false;
if (!canChangeEnvironment) return false;
if (event.repeat) return;
const currentId = readPendingEnvironmentChange()?.environmentId ?? environmentId;
const index = logicalProjectEnvironments.findIndex(
Expand Down Expand Up @@ -8373,7 +8378,7 @@ export default function ChatView(props: ChatViewProps) {
{...(canCheckoutPullRequestIntoThread
? { onCheckoutPullRequestRequest: openPullRequestDialogStable }
: {})}
{...(hasMultipleEnvironments
{...(canChangeEnvironment
? { onEnvironmentChange: onEnvironmentChangeStable }
: {})}
autoEnvironmentLabel={autoEnvironmentLabel}
Expand Down Expand Up @@ -8453,7 +8458,7 @@ export default function ChatView(props: ChatViewProps) {
? onAutoEnvironmentStable
: undefined
}
onEnvironmentChange={onEnvironmentChangeStable}
{...(canChangeEnvironment ? { onEnvironmentChange: onEnvironmentChangeStable } : {})}
onEnvModeChange={onEnvModeChangeStable}
envMode={envMode}
{...(canOverrideServerThreadEnvMode
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/components/chat/ThreadDetailsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ThreadDetailsPanelProps extends Pick<
availableEnvironments: readonly EnvironmentOption[];
autoEnvironmentLabel?: string | undefined;
onAutoEnvironment?: (() => void) | undefined;
onEnvironmentChange: (environmentId: EnvironmentId) => void;
onEnvironmentChange?: (environmentId: EnvironmentId) => void;
onEnvModeChange: (mode: EnvMode) => void;
envMode: EnvMode;
activeThreadBranchOverride?: string | null;
Expand Down Expand Up @@ -113,7 +113,9 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
layout="panel"
panelSection="workspace"
availableEnvironments={props.availableEnvironments}
onEnvironmentChange={props.onEnvironmentChange}
{...(props.onEnvironmentChange
? { onEnvironmentChange: props.onEnvironmentChange }
: {})}
autoEnvironmentLabel={props.autoEnvironmentLabel}
onAutoEnvironment={props.onAutoEnvironment}
{...branchToolbarProps}
Expand Down
Loading