Skip to content
Closed
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
43 changes: 38 additions & 5 deletions apps/mobile/src/features/threads/ThreadComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ import { VideoPreviewModal, type VideoPreviewSource } from "../../components/Vid
import { GlassSurface } from "../../components/ui/GlassSurface";
import { ComposerEditor, type ComposerEditorHandle } from "../../components/ComposerEditor";
import { fileRoutePathSegments } from "../files/filePath";
import { ComposerActionButton, ComposerToolbarRow } from "../../components/ComposerToolbar";
import {
ComposerActionButton,
ComposerInlineControl,
ComposerToolbarRow,
} from "../../components/ComposerToolbar";
import { ComposerModelControl } from "../../components/ComposerModelControl";
import {
composerStripAttachments,
Expand Down Expand Up @@ -254,6 +258,7 @@ export interface ThreadComposerProps {
readonly onShowUsageLimits: (report: UsageLimitsReport | null) => void;
readonly canSwitchProvider: boolean;
readonly onUpdateInteractionMode?: (interactionMode: ProviderInteractionMode) => void;
readonly persistedInteractionMode?: ProviderInteractionMode;
readonly onHeightChange?: (height: number) => void;
readonly onEditorFocusChange?: (focused: boolean) => void;
}
Expand Down Expand Up @@ -539,6 +544,11 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
return report !== null;
};

const onUpdateInteractionMode =
selectedProviderStatus?.showInteractionModeToggle === false
? undefined
: props.onUpdateInteractionMode;

const mentionableEnvironments = useMentionableEnvironments();
const composerMenu = useComposerCommandMenu({
draftMessage: draftMessage,
Expand All @@ -558,10 +568,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
hasThread: !props.isDraft,
hasCompactableConversation: props.hasCompactableConversation,
onChangeDraftMessage: props.onChangeDraftMessage,
onUpdateInteractionMode:
selectedProviderStatus?.showInteractionModeToggle === false
? undefined
: props.onUpdateInteractionMode,
onUpdateInteractionMode,
offersUsageLimits: usageLimitsOffered,
onUsageLimits:
usageLimitsOffered && draftAttachments.length === 0 ? openUsageLimits : undefined,
Expand Down Expand Up @@ -813,6 +820,31 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
</View>
);

// A thread already in Plan keeps the control with the Plan Mode setting off, so it can leave Plan.
const interactionMode = props.selectedThread.interactionMode;
const modeControl =
!props.isDraft &&
props.persistedInteractionMode === "plan" &&
onUpdateInteractionMode &&
queuedEdit === null ? (
<ComposerInlineControl
size={usesLargeControls ? "large" : "regular"}
accessibilityHint={`Switches to ${interactionMode === "plan" ? "Build" : "Plan"} mode`}
accessibilityLabel={`Interaction mode: ${interactionMode === "plan" ? "Plan" : "Build"}`}
disabled={props.interactionLocked === true}
emphasized
icon={
interactionMode === "plan"
? { ios: "list.bullet.clipboard", android: "auto_awesome" }
: { ios: "hammer", android: "construction" }
}
label={interactionMode === "plan" ? "Plan" : "Build"}
iconOnly={!compactEditor.isExpanded}
onPress={() => onUpdateInteractionMode(interactionMode === "plan" ? "default" : "plan")}
showChevron={false}
/>
) : null;

return (
<Animated.View
onLayout={(event) => props.onHeightChange?.(event.nativeEvent.layout.height)}
Expand Down Expand Up @@ -1093,6 +1125,7 @@ export const ThreadComposer = function ThreadComposer(props: ThreadComposerProps
compactEditor.isExpanded ? { flex: 1, justifyContent: "flex-end" } : undefined
}
>
{modeControl}
{modelControl}
<ComposerDictationStartAction
size={usesLargeControls ? "large" : "regular"}
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/features/threads/ThreadDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export interface ThreadDetailScreenProps {
readonly onReconnectEnvironment: () => void;
readonly canSwitchThreadProvider: boolean;
readonly onUpdateThreadInteractionMode?: (interactionMode: ProviderInteractionMode) => void;
readonly persistedInteractionMode?: ProviderInteractionMode;
readonly onRespondToApproval: ApprovalResponder;
readonly onSelectUserInputOption: (
requestId: RuntimeRequestId,
Expand Down Expand Up @@ -1934,6 +1935,7 @@ function ThreadDetailBody(
onShowUsageLimits={showUsageLimits}
canSwitchProvider={props.canSwitchThreadProvider}
onUpdateInteractionMode={props.onUpdateThreadInteractionMode}
persistedInteractionMode={props.persistedInteractionMode}
onHeightChange={handleComposerHeightChange}
onEditorFocusChange={handleOwnedInputFocusChange}
/>
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/features/threads/ThreadRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ function ThreadRouteContent(
}
canOperateThread={canOperateThread}
selectedThread={selectedThreadWithDraftSettings ?? selectedThread}
persistedInteractionMode={selectedThread.interactionMode}
selectedThreadDetailRef={selectedThreadDetailRef}
contentPresentation={contentPresentation}
screenTone={connectionTone(routeConnectionState)}
Expand Down
53 changes: 53 additions & 0 deletions apps/web/src/components/ChatView.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import type { Thread } from "../types";
import { makeThreadFixture, makeThreadProjectionFixture } from "../test-fixtures";
import {
getAntigravitySendBlockReason,
resolveComposerInteractionMode,
resolveComposerProviderSelection,
resolveWorktreeSetupProgress,
peekRememberedThreadTimeline,
Expand Down Expand Up @@ -670,6 +671,58 @@ describe("resolveComposerProviderSelection", () => {
});
});

describe("resolveComposerInteractionMode", () => {
const toggle = { showInteractionModeToggle: true };
const hidden = { showInteractionModeToggle: false };
it.each([
{
name: "setting off, stale plan draft on a new thread",
on: false,
provider: toggle,
draft: "plan",
persisted: undefined,
enabled: false,
mode: "default",
},
{
name: "setting off, persisted plan thread",
on: false,
provider: toggle,
draft: "plan",
persisted: "plan",
enabled: true,
mode: "plan",
},
{
name: "setting off, persisted plan thread switched to default",
on: false,
provider: toggle,
draft: "default",
persisted: "plan",
enabled: true,
mode: "default",
},
{
name: "setting off, persisted plan thread, provider hides the toggle",
on: false,
provider: hidden,
draft: "plan",
persisted: "plan",
enabled: false,
mode: "default",
},
] as const)("$name", ({ on, provider, draft, persisted, enabled, mode }) => {
expect(
resolveComposerInteractionMode({
planModeEnabled: on,
provider,
interactionMode: draft,
persistedInteractionMode: persisted,
}),
).toEqual({ enabled, interactionMode: mode });
});
});

describe("checkout Git memory", () => {
it("does not confuse an environment id containing the separator with a path", () => {
rememberCheckoutIsRepo(EnvironmentId.make("env"), "a:b", false);
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/components/ChatView.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,11 @@ export function resolveComposerInteractionMode(input: {
planModeEnabled: boolean;
provider: Pick<ServerProvider, "showInteractionModeToggle"> | null | undefined;
interactionMode: ProviderInteractionMode;
/** The server thread's mode. A thread already in plan keeps its mode controls so it can leave plan. */
persistedInteractionMode: ProviderInteractionMode | undefined;
}): { enabled: boolean; interactionMode: ProviderInteractionMode } {
const enabled =
input.planModeEnabled &&
(input.planModeEnabled || input.persistedInteractionMode === "plan") &&
input.provider != null &&
input.provider.showInteractionModeToggle !== false;
return {
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { useRightPanelActions } from "./chat/useRightPanelActions";
import { type TerminalLaunchContext, useChatTerminalActions } from "./chat/useChatTerminalActions";
import { useComposerSend } from "./chat/useComposerSend";
import { useComposerResume } from "./chat/useComposerResume";
import { useImplementPlanInNewThread } from "./chat/useProposedPlanSend";
import { useImplementPlanInNewThread, useThreadInteractionMode } from "./chat/useProposedPlanSend";
import { ThreadFind, ThreadFindCanvas } from "./chat/ThreadFindProvider";
import { closeThreadFind, openThreadFind, useThreadFindOpen } from "./chat/threadFindStore";
import { THREAD_FIND_BAR_RESERVED_HEIGHT } from "./chat/ThreadFindBar";
Expand Down Expand Up @@ -797,6 +797,7 @@ export default function ChatView(props: ChatViewProps) {
)
: undefined;
const isServerThread = serverThread !== null;
const serverThreadInteractionMode = useThreadInteractionMode(serverThread);
const activeThread = isServerThread ? serverThread : localDraftThread;
const serverLatestRun =
serverProjection === null ? null : deriveLatestThreadRun(serverProjection);
Expand Down Expand Up @@ -1316,7 +1317,11 @@ export default function ChatView(props: ChatViewProps) {
planModeEnabled: settings.planModeEnabled,
provider: activeProviderStatus,
interactionMode:
composerInteractionMode ?? activeThread?.interactionMode ?? DEFAULT_INTERACTION_MODE,
composerInteractionMode ??
serverThreadInteractionMode ??
activeThread?.interactionMode ??
DEFAULT_INTERACTION_MODE,
persistedInteractionMode: serverThreadInteractionMode,
});
const conversationProviderStatus =
providerStatuses.find((status) => status.instanceId === activeRuntime?.providerInstanceId) ??
Expand Down Expand Up @@ -2926,6 +2931,7 @@ export default function ChatView(props: ChatViewProps) {
draftId,
draftThread,
activeThread,
activeLatestRun,
activeThreadKey,
activeThreadBranch,
activeProject,
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ import {
usePreparingComposerImages,
} from "./preparingComposerImages";
import { ComposerControlsBar } from "./ComposerControlsBar";
import { useThreadInteractionMode } from "./useProposedPlanSend";
import { composerCommandKeyHandler } from "./composerCommandKey";

function consumePasteAsTextShortcut(deadline: { current: number }): boolean {
Expand Down Expand Up @@ -970,10 +971,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)

const selectedPromptEffort = composerProviderState.promptEffort;
const selectedModelOptionsForDispatch = composerProviderState.modelOptionsForDispatch;
const activeThreadInteractionMode = useThreadInteractionMode(props.activeThreadShell);
const { enabled: planModeUiEnabled, interactionMode } = resolveComposerInteractionMode({
planModeEnabled: settings.planModeEnabled,
provider: selectedProviderStatus,
interactionMode: requestedInteractionMode,
persistedInteractionMode: activeThreadInteractionMode,
});
const selectedModelSelection: ModelSelection = createModelSelection(
selectedInstanceId,
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/chat/chatViewSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ export function resolveMultipleModelTargets(input: {
planModeEnabled,
provider: provider.snapshot,
interactionMode: input.interactionMode,
persistedInteractionMode: undefined,
}).interactionMode,
};
});
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/components/chat/useComposerSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ interface ComposerSendInput {
readonly draftId: DraftId | null;
readonly draftThread: DraftSessionState | null;
readonly activeThread: EnvironmentThreadShell | undefined;
readonly activeLatestRun: EnvironmentThreadShell["latestRun"] | null;
readonly activeThreadKey: string | null;
readonly activeThreadBranch: string | null;
readonly activeProject: EnvironmentProject | null;
Expand Down Expand Up @@ -272,6 +273,7 @@ export function useComposerSend(input: ComposerSendInput) {
draftId,
draftThread,
activeThread,
activeLatestRun,
activeThreadKey,
activeThreadBranch,
activeProject,
Expand Down Expand Up @@ -380,6 +382,7 @@ export function useComposerSend(input: ComposerSendInput) {
environmentId,
routeThreadKey,
activeThread,
activeLatestRun,
activeThreadBranch,
activeProposedPlan,
isServerThread,
Expand Down
Loading
Loading