🙌 OpenHands: AI-Driven Development
Add workspace mode for local conversations (#1293)
Devin4ec694e86b49
diff --git a/__tests__/api/agent-server-adapter.test.ts b/__tests__/api/agent-server-adapter.test.tsindex 89c8dcf8a9..cb12c1030c 100644--- a/__tests__/api/agent-server-adapter.test.ts+++ b/__tests__/api/agent-server-adapter.test.ts@@ -302,7 +302,7 @@ describe("buildStartConversationRequest", () => {expect(payload.workspace.working_dir).toBe(workingDir);});- it("always requests a git worktree for new conversations", () => {+ it("requests a git worktree for new conversations by default", () => {const payload = buildStartConversationRequest({settings: {...DEFAULT_SETTINGS,@@ -316,6 +316,25 @@ describe("buildStartConversationRequest", () => {expect(payload.worktree).toBe(true);});+ it("can start a conversation without requesting a git worktree", () => {+ const payload = buildStartConversationRequest({+ settings: {+ ...DEFAULT_SETTINGS,+ agent_settings: {+ ...DEFAULT_SETTINGS.agent_settings,+ llm: { model: "nested-model" },+ },+ },+ workingDir: "/Users/devin/project-without-git",+ worktree: false,+ }) as { worktree: boolean; workspace: { working_dir: string } };++ expect(payload.worktree).toBe(false);+ expect(payload.workspace.working_dir).toBe(+ "/Users/devin/project-without-git",+ );+ });+it("forwards supported conversation runtime fields from nested settings", () => {const payload = buildStartConversationRequest({settings: {diff --git a/__tests__/api/agent-server-conversation-service.test.ts b/__tests__/api/agent-server-conversation-service.test.tsindex de7e97ab3c..e69b79afa6 100644--- a/__tests__/api/agent-server-conversation-service.test.ts+++ b/__tests__/api/agent-server-conversation-service.test.ts@@ -266,10 +266,12 @@ describe("AgentServerConversationService", () => {const firstPayload = firstCall[1] as {conversation_id: string;workspace: { working_dir: string };+ worktree: boolean;};const secondPayload = secondCall[1] as {conversation_id: string;workspace: { working_dir: string };+ worktree: boolean;};expect(firstPayload.conversation_id).toBeTruthy();@@ -285,6 +287,8 @@ describe("AgentServerConversationService", () => {expect(secondPayload.workspace.working_dir).toBe(`/state/workspaces/${secondHex}`,);+ expect(firstPayload.worktree).toBe(true);+ expect(secondPayload.worktree).toBe(true);});// @spec WUP-001 — When the default working_dir is relative, the@@ -362,8 +366,46 @@ describe("AgentServerConversationService", () => {const [payloadCall] = mockHttpPost.mock.calls;const payload = payloadCall[1] as {workspace: { working_dir: string };+ worktree: boolean;};expect(payload.workspace.working_dir).toBe("/Users/jane/projects/foo");+ expect(payload.worktree).toBe(false);+ });++ it("honors an explicit new-worktree mode for a selected workspace", async () => {+ mockGetSettings.mockResolvedValue({+ agent_settings: { llm: { model: "gpt-4o" } },+ conversation_settings: {},+ });+ mockGetSettingsForConversation.mockResolvedValue({+ agentSettings: { llm: { model: "gpt-4o" } },+ conversationSettings: {},+ secretsEncrypted: true,+ });+ mockHttpPost.mockResolvedValue({+ data: {+ id: "ignored-server-id",+ created_at: "2024-01-01",+ updated_at: "2024-01-01",+ },+ });++ await AgentServerConversationService.createConversation(+ undefined,+ undefined,+ undefined,+ undefined,+ "/Users/jane/projects/foo",+ "new_worktree",+ );++ const [payloadCall] = mockHttpPost.mock.calls;+ const payload = payloadCall[1] as {+ workspace: { working_dir: string };+ worktree: boolean;+ };+ expect(payload.workspace.working_dir).toBe("/Users/jane/projects/foo");+ expect(payload.worktree).toBe(true);});});@@ -841,6 +883,7 @@ describe("AgentServerConversationService", () => {undefined,null,undefined,+ undefined,"parent-conv-1","plan","sandbox-9",diff --git a/__tests__/api/use-create-conversation-metadata.test.ts b/__tests__/api/use-create-conversation-metadata.test.tsindex 52d45db7b4..5c4c45fb3f 100644--- a/__tests__/api/use-create-conversation-metadata.test.ts+++ b/__tests__/api/use-create-conversation-metadata.test.ts@@ -141,6 +141,7 @@ describe("useCreateConversation persists selected repository metadata", () => {selected_branch: "main",git_provider: "github",selected_workspace: null,+ workspace_mode: "new_worktree",});});@@ -161,6 +162,7 @@ describe("useCreateConversation persists selected repository metadata", () => {selected_branch: null,git_provider: null,selected_workspace: "/home/me/code/some-project",+ workspace_mode: "local_repo",});});@@ -190,6 +192,7 @@ describe("useCreateConversation persists selected repository metadata", () => {selected_branch: null,git_provider: null,selected_workspace: null,+ workspace_mode: null,active_profile: "team-default",});});diff --git a/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.ts b/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.tsindex 08343a1156..d688fec639 100644--- a/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.ts+++ b/__tests__/components/features/conversation-panel/conversation-panel-list-helpers.test.ts@@ -246,21 +246,16 @@ describe("conversation-panel-list-helpers", () => {expanded: false,activeConversationId: "c-5",});- expect(withActiveBeyondPreview.visibleConversations.map((c) => c.id)).toEqual([- "c-0",- "c-1",- "c-2",- "c-3",- "c-5",- ]);+ expect(+ withActiveBeyondPreview.visibleConversations.map((c) => c.id),+ ).toEqual(["c-0", "c-1", "c-2", "c-3", "c-5"]);expect(GROUP_CONVERSATIONS_PREVIEW_LIMIT).toBe(5);});it("groups local conversations by selected_workspace, collapsing per-conversation worktree paths", () => {- // Two conversations launched against the same workspace but with- // different per-conversation worktree dirs (the agent-server runs- // with worktree: true). They must end up in a single group keyed- // off the user-selected workspace, not split by the worktree dir.+ // Two worktree-mode conversations launched against the same workspace must+ // end up in a single group keyed off the user-selected workspace, not split+ // by the runtime worktree dir.const sameWsA: AppConversation = {...base,id: "1",diff --git a/__tests__/components/features/conversation-panel/local-new-conversation-menu.test.tsx b/__tests__/components/features/conversation-panel/local-new-conversation-menu.test.tsxindex 9f2da33f70..d3e84758d6 100644--- a/__tests__/components/features/conversation-panel/local-new-conversation-menu.test.tsx+++ b/__tests__/components/features/conversation-panel/local-new-conversation-menu.test.tsx@@ -186,6 +186,7 @@ describe("LocalNewConversationMenu", () => {"/workspace/project/repo1",undefined,undefined,+ undefined,);});await waitFor(() => {diff --git a/__tests__/components/features/conversation-panel/new-conversation-button-cloud.test.tsx b/__tests__/components/features/conversation-panel/new-conversation-button-cloud.test.tsxindex 158eee2735..9c924ede1b 100644--- a/__tests__/components/features/conversation-panel/new-conversation-button-cloud.test.tsx+++ b/__tests__/components/features/conversation-panel/new-conversation-button-cloud.test.tsx@@ -159,6 +159,7 @@ describe("NewConversationButton (cloud)", () => {undefined,undefined,undefined,+ undefined,);});await waitFor(() => {@@ -201,6 +202,7 @@ describe("NewConversationButton (cloud)", () => {undefined,undefined,undefined,+ undefined,);});});diff --git a/__tests__/components/features/home/home-chat-launcher.test.tsx b/__tests__/components/features/home/home-chat-launcher.test.tsxindex b86f6b2b04..c1230e4d05 100644--- a/__tests__/components/features/home/home-chat-launcher.test.tsx+++ b/__tests__/components/features/home/home-chat-launcher.test.tsx@@ -174,8 +174,27 @@ vi.mock("#/components/features/home/open-repository-dialog", () => ({// about for these tests. It's purely presentational once a selection is// confirmed, so a thin stub is sufficient.vi.mock("#/components/features/home/home-git-control-bar-preview", () => ({- HomeGitControlBarPreview: () => (- <div data-testid="stub-git-control-bar-preview" />+ HomeGitControlBarPreview: ({+ workspaceMode,+ backendKind,+ onWorkspaceModeChange,+ }: {+ workspaceMode: "local_repo" | "new_worktree";+ backendKind: "local" | "cloud";+ onWorkspaceModeChange: (mode: "local_repo" | "new_worktree") => void;+ }) => (+ <div data-testid="stub-git-control-bar-preview">+ <span data-testid="stub-workspace-mode">+ {backendKind}:{workspaceMode}+ </span>+ <button+ type="button"+ data-testid="stub-workspace-mode-new-worktree"+ onClick={() => onWorkspaceModeChange("new_worktree")}+ >+ New Worktree+ </button>+ </div>),}));@@ -284,6 +303,7 @@ describe("HomeChatLauncher", () => {undefined,undefined,undefined,+ undefined,);await waitFor(() =>expect(mockNavigate).toHaveBeenCalledWith("/conversations/conv-abc"),@@ -329,6 +349,7 @@ describe("HomeChatLauncher", () => {undefined,null,"/p/app",+ "local_repo",undefined,undefined,);@@ -337,6 +358,46 @@ describe("HomeChatLauncher", () => {);});+ it("passes the picked workspace path with new-worktree mode when selected", async () => {+ const createSpy = vi+ .spyOn(AgentServerConversationService, "createConversation")+ .mockResolvedValue(+ makeConversationResponse({ app_conversation_id: "conv-wt" }),+ );++ renderLauncher();+ const user = userEvent.setup();++ await user.click(screen.getByTestId("open-workspace-button"));+ await user.click(+ await screen.findByTestId("stub-workspace-dialog-confirm"),+ );+ expect(screen.getByTestId("stub-workspace-mode")).toHaveTextContent(+ "local:local_repo",+ );++ await user.click(screen.getByTestId("stub-workspace-mode-new-worktree"));+ expect(screen.getByTestId("stub-workspace-mode")).toHaveTextContent(+ "local:new_worktree",+ );+ await user.click(screen.getByTestId("stub-chat-submit"));++ await waitFor(() => expect(createSpy).toHaveBeenCalledTimes(1));+ expect(createSpy).toHaveBeenCalledWith(+ "hello world",+ undefined,+ undefined,+ null,+ "/p/app",+ "new_worktree",+ undefined,+ undefined,+ );+ await waitFor(() =>+ expect(mockNavigate).toHaveBeenCalledWith("/conversations/conv-wt"),+ );+ });+it("disables the local workspace launcher when the agent server is too old", async () => {vi.spyOn(WorkspacesService, "listWorkspaces").mockRejectedValue({code: "AGENT_SERVER_VERSION_TOO_OLD",@@ -386,6 +447,7 @@ describe("HomeChatLauncher", () => {undefined,undefined,undefined,+ undefined,);await waitFor(() =>expect(mockNavigate).toHaveBeenCalledWith("/conversations/conv-repo"),@@ -411,6 +473,7 @@ describe("HomeChatLauncher", () => {undefined,undefined,undefined,+ undefined,);await waitFor(() =>expect(sendMessageWithAttachments).toHaveBeenCalledTimes(1),@@ -491,6 +554,7 @@ describe("HomeChatLauncher", () => {undefined,undefined,undefined,+ undefined,);expect(sendMessageWithAttachments).not.toHaveBeenCalled();await waitFor(() =>diff --git a/__tests__/components/features/home/task-card.test.tsx b/__tests__/components/features/home/task-card.test.tsxindex 82ca471874..56207bf81e 100644--- a/__tests__/components/features/home/task-card.test.tsx+++ b/__tests__/components/features/home/task-card.test.tsx@@ -142,6 +142,7 @@ describe("TaskCard", () => {undefined,undefined,undefined,+ undefined,);});});diff --git a/__tests__/hooks/mutation/use-create-conversation.test.tsx b/__tests__/hooks/mutation/use-create-conversation.test.tsxindex ebc562b165..ddf61b6565 100644--- a/__tests__/hooks/mutation/use-create-conversation.test.tsx+++ b/__tests__/hooks/mutation/use-create-conversation.test.tsx@@ -94,6 +94,7 @@ describe("useCreateConversation", () => {undefined,undefined,undefined,+ undefined,);});});diff --git a/__tests__/hooks/mutation/use-new-conversation-command.test.tsx b/__tests__/hooks/mutation/use-new-conversation-command.test.tsxindex 83df06479e..5e26f959c1 100644--- a/__tests__/hooks/mutation/use-new-conversation-command.test.tsx+++ b/__tests__/hooks/mutation/use-new-conversation-command.test.tsx@@ -195,7 +195,7 @@ describe("useNewConversationCommand", () => {});await result.current.mutateAsync();- // Assert — sandbox_id is the 8th positional argument; parent_conversation_id+ // Assert — sandbox_id is the 9th positional argument; parent_conversation_id// and agent_type stay undefined because /new is NOT a sub-conversation.await waitFor(() => {expect(createSpy).toHaveBeenCalledWith(@@ -206,6 +206,7 @@ describe("useNewConversationCommand", () => {undefined,undefined,undefined,+ undefined,"sandbox-abc",);});diff --git a/src/api/agent-server-adapter.ts b/src/api/agent-server-adapter.tsindex 385dde9072..bf18f81adf 100644--- a/src/api/agent-server-adapter.ts+++ b/src/api/agent-server-adapter.ts@@ -807,7 +807,7 @@ type StartConversationPayload = Record<string, unknown> & {max_iterations: number;stuck_detection: true;autotitle: true;- worktree: true;+ worktree: boolean;secrets_encrypted?: true;conversation_id?: string;secrets?: Record<string, LookupSecret>;@@ -822,6 +822,7 @@ export interface StartConversationOptions {plugins?: PluginSpec[];conversationId?: string;workingDir?: string;+ worktree?: boolean;encryptedAgentSettings?: Record<string, SettingsValue>;encryptedConversationSettings?: Record<string, SettingsValue>;secretsEncrypted?: boolean;@@ -866,7 +867,7 @@ export function buildStartConversationRequest(: 500,stuck_detection: true,autotitle: true,- worktree: true,+ worktree: options.worktree ?? true,};if (acpServerTag) {@@ -954,6 +955,7 @@ export async function buildStartConversationRequestWithEncryptedSettings(optionsplugins?: PluginSpec[];conversationId?: string;workingDir?: string;+ worktree?: boolean;}): Promise<Record<string, unknown>> {const { SecretsService } = await import("./secrets-service");diff --git a/src/api/conversation-metadata-store.ts b/src/api/conversation-metadata-store.tsindex a9de5aa7b6..be02572e2c 100644--- a/src/api/conversation-metadata-store.ts+++ b/src/api/conversation-metadata-store.ts@@ -2,6 +2,8 @@ import { Provider } from "#/types/settings";const STORAGE_KEY = "openhands-agent-server-conversation-metadata";+export type WorkspaceMode = "local_repo" | "new_worktree";+export interface ConversationMetadata {selected_repository: string | null;selected_branch: string | null;@@ -15,6 +17,15 @@ export interface ConversationMetadata {* git baseline to compare against.*/selected_workspace?: string | null;+ /**+ * How the conversation should use `selected_workspace`.+ *+ * `local_repo` means the runtime should operate directly in the selected+ * folder, even when it is not a git checkout. `new_worktree` preserves the+ * historical agent-server behavior for conversations that should start in a+ * generated per-conversation worktree.+ */+ workspace_mode?: WorkspaceMode | null;/*** The LLM profile the conversation was created with (or last switched to).* Client-side only. Lets the chat-header switcher show the exact profilediff --git a/src/api/conversation-service/agent-server-conversation-service.api.ts b/src/api/conversation-service/agent-server-conversation-service.api.tsindex 6d0c263310..02fa86a181 100644--- a/src/api/conversation-service/agent-server-conversation-service.api.ts+++ b/src/api/conversation-service/agent-server-conversation-service.api.ts@@ -51,6 +51,7 @@ import {getStoredConversationMetadata,removeStoredConversationMetadata,setStoredConversationMetadata,+ type WorkspaceMode,} from "../conversation-metadata-store";import type {GetHooksResponse,@@ -345,6 +346,7 @@ class AgentServerConversationService {plugins?: PluginSpec[],metadata?: ConversationMetadata | null,workingDirOverride?: string,+ workspaceMode?: WorkspaceMode,parentConversationId?: string,agentType?: "default" | "plan",sandboxId?: string,@@ -385,6 +387,8 @@ class AgentServerConversationService {const workingDir = await resolveAbsoluteAgentServerPath(workingDirOverride ?? buildConversationWorkingDir(conversationId),);+ const resolvedWorkspaceMode =+ workspaceMode ?? (workingDirOverride ? "local_repo" : "new_worktree");// Use encrypted settings to avoid exposing secrets in the browserconst payload = await buildStartConversationRequestWithEncryptedSettings({@@ -394,6 +398,7 @@ class AgentServerConversationService {plugins,conversationId,workingDir,+ worktree: resolvedWorkspaceMode === "new_worktree",});const data = await new ConversationClient(@@ -414,6 +419,7 @@ class AgentServerConversationService {selected_branch: metadata?.selected_branch ?? null,git_provider: metadata?.git_provider ?? null,selected_workspace: workingDirOverride ?? null,+ workspace_mode: resolvedWorkspaceMode,});}diff --git a/src/api/conversation-service/agent-server-conversation-service.types.ts b/src/api/conversation-service/agent-server-conversation-service.types.tsindex 4db37da000..eb3b8c11ee 100644--- a/src/api/conversation-service/agent-server-conversation-service.types.ts+++ b/src/api/conversation-service/agent-server-conversation-service.types.ts@@ -167,8 +167,8 @@ export interface AppConversation {* The local workspace the user explicitly attached when creating this* conversation. Client-side only — never round-tripped to the agent-server* or cloud. Null/undefined for conversations created via "No workspace".- * Distinct from `workspace.working_dir` (the per-conversation worktree path- * the runtime actually operates in).+ * Distinct from `workspace.working_dir`, which is the runtime path and may+ * either match this folder directly or point at a per-conversation worktree.*/selected_workspace?: string | null;/**diff --git a/src/components/features/chat/workspace-mode-selector.tsx b/src/components/features/chat/workspace-mode-selector.tsxnew file mode 100644index 0000000000..d6aa4120a8--- /dev/null+++ b/src/components/features/chat/workspace-mode-selector.tsx@@ -0,0 +1,134 @@+import { useEffect, useRef, useState } from "react";+import { useTranslation } from "react-i18next";+import { ChevronDown, GitBranch } from "lucide-react";+import type { BackendKind } from "#/api/backend-registry/types";+import type { WorkspaceMode } from "#/api/conversation-metadata-store";+import { getWorkspaceModeI18nKey } from "#/utils/workspace-mode";+import { cn } from "#/utils/utils";+import {+ dropdownMenuListClassName,+ dropdownMenuRowClassName,+ dropdownMenuRowIconWrapperClassName,+} from "#/utils/dropdown-classes";+import RepoForkedIcon from "#/icons/repo-forked.svg?react";++interface WorkspaceModeSelectorProps {+ value: WorkspaceMode;+ backendKind: BackendKind;+ onChange: (value: WorkspaceMode) => void;+ disabled?: boolean;+ testId?: string;+}++const WORKSPACE_MODE_OPTIONS: WorkspaceMode[] = ["local_repo", "new_worktree"];++function WorkspaceModeIcon({ mode }: { mode: WorkspaceMode }) {+ if (mode === "new_worktree") {+ return <GitBranch className="size-3" strokeWidth={2} aria-hidden />;+ }++ return <RepoForkedIcon width={12} height={12} color="white" aria-hidden />;+}++export function WorkspaceModeSelector({+ value,+ backendKind,+ onChange,+ disabled = false,+ testId = "workspace-mode-selector",+}: WorkspaceModeSelectorProps) {+ const { t } = useTranslation("openhands");+ const [open, setOpen] = useState(false);+ const containerRef = useRef<HTMLDivElement>(null);+ const label = t(getWorkspaceModeI18nKey(value, backendKind));++ useEffect(() => {+ if (!open) return undefined;++ const onMouseDown = (event: MouseEvent) => {+ if (+ containerRef.current &&+ !containerRef.current.contains(event.target as Node)+ ) {+ setOpen(false);+ }+ };++ document.addEventListener("mousedown", onMouseDown);+ return () => document.removeEventListener("mousedown", onMouseDown);+ }, [open]);++ useEffect(() => {+ if (!open) return undefined;++ const onKeyDown = (event: KeyboardEvent) => {+ if (event.key === "Escape") setOpen(false);+ };++ window.addEventListener("keydown", onKeyDown);+ return () => window.removeEventListener("keydown", onKeyDown);+ }, [open]);++ return (+ <div ref={containerRef} className="relative inline-flex">+ <button+ type="button"+ data-testid={testId}+ aria-haspopup="menu"+ aria-expanded={open}+ aria-label={label}+ disabled={disabled}+ onClick={() => setOpen((next) => !next)}+ className={cn(+ "group flex flex-row items-center justify-between gap-2 pl-2.5 pr-2 py-1 rounded-[100px] truncate relative",+ "border border-[rgba(71,74,84,0.50)] bg-transparent text-white",+ disabled+ ? "cursor-not-allowed opacity-50"+ : "cursor-pointer hover:border-[var(--oh-border-subtle)]",+ )}+ >+ <span className="flex size-3 shrink-0 items-center justify-center">+ <WorkspaceModeIcon mode={value} />+ </span>+ <span className="min-w-0 flex-1 truncate text-sm font-normal leading-5">+ {label}+ </span>+ <ChevronDown className="size-3 shrink-0 text-white" aria-hidden />+ </button>++ {open ? (+ <div+ role="menu"+ data-testid={`${testId}-menu`}+ className={cn(+ "absolute left-0 top-full z-50 mt-1 min-w-[180px] rounded-lg border border-[var(--oh-border)] bg-[var(--oh-surface)] p-1 shadow-lg",+ dropdownMenuListClassName,+ )}+ >+ {WORKSPACE_MODE_OPTIONS.map((option) => {+ const optionLabel = t(getWorkspaceModeI18nKey(option, backendKind));+ return (+ <button+ key={option}+ type="button"+ role="menuitemradio"+ aria-checked={option === value}+ data-testid={`${testId}-option-${option}`}+ onClick={() => {+ onChange(option);+ setOpen(false);+ }}+ className={dropdownMenuRowClassName}+ >+ <span className={dropdownMenuRowIconWrapperClassName}>+ <WorkspaceModeIcon mode={option} />+ </span>+ <span className="truncate">{optionLabel}</span>+ </button>+ );+ })}+ </div>+ ) : null}+ </div>+ );+}diff --git a/src/components/features/home/home-chat-launcher.tsx b/src/components/features/home/home-chat-launcher.tsxindex 5e7bd432cb..f523496c23 100644--- a/src/components/features/home/home-chat-launcher.tsx+++ b/src/components/features/home/home-chat-launcher.tsx@@ -10,6 +10,7 @@ import { useLlmConfigured } from "#/hooks/use-llm-configured";import { HOME_PROMPT_DRAFT_KEY } from "#/hooks/chat/use-draft-persistence";import { useChatAttachmentUpload } from "#/hooks/chat/use-chat-attachment-upload";import { useConversationStore } from "#/stores/conversation-store";+import type { WorkspaceMode } from "#/api/conversation-metadata-store";import { setPendingTaskAttachments } from "#/stores/pending-task-attachments-store";import { enqueueHomeTaskPendingMessage } from "#/utils/enqueue-home-task-pending-message";import { sendMessageWithAttachments } from "#/utils/send-message-with-attachments";@@ -43,6 +44,8 @@ export function HomeChatLauncher() {useState<GitRepository | null>(null);const [pendingBranch, setPendingBranch] = useState<Branch | null>(null);const [pendingProvider, setPendingProvider] = useState<Provider | null>(null);+ const [workspaceMode, setWorkspaceMode] =+ useState<WorkspaceMode>("local_repo");const { mutate: createConversation, isPending } = useCreateConversation();const isCreatingElsewhere = useIsCreatingConversation();@@ -89,7 +92,11 @@ export function HomeChatLauncher() {query: hasAttachments ? undefined : trimmed || undefined,};if (isLocal && pendingWorkspace) {- variables = { ...variables, workingDir: pendingWorkspace.path };+ variables = {+ ...variables,+ workingDir: pendingWorkspace.path,+ workspaceMode,+ };} else if (!isLocal && pendingRepository && pendingBranch) {variables = {...variables,@@ -217,7 +224,10 @@ export function HomeChatLauncher() {repository={pendingRepository}branch={pendingBranch}provider={pendingProvider}+ workspaceMode={workspaceMode}+ backendKind={backend.kind}onRepoClick={() => setIsDialogOpen(true)}+ onWorkspaceModeChange={setWorkspaceMode}/>) : (<OpenLauncherButton@@ -238,6 +248,7 @@ export function HomeChatLauncher() {setPendingRepository(null);setPendingBranch(null);setPendingProvider(null);+ setWorkspaceMode("local_repo");}}/>) : (@@ -249,6 +260,7 @@ export function HomeChatLauncher() {setPendingBranch(branch);setPendingProvider(provider ?? repository.git_provider);setPendingWorkspace(null);+ setWorkspaceMode("local_repo");}}/>)}diff --git a/src/components/features/home/home-git-control-bar-preview.tsx b/src/components/features/home/home-git-control-bar-preview.tsxindex b58a0b2c59..93727d3ede 100644--- a/src/components/features/home/home-git-control-bar-preview.tsx+++ b/src/components/features/home/home-git-control-bar-preview.tsx@@ -1,5 +1,8 @@+import type { BackendKind } from "#/api/backend-registry/types";+import type { WorkspaceMode } from "#/api/conversation-metadata-store";import { GitControlBarRepoButton } from "#/components/features/chat/git-control-bar-repo-button";import { GitControlBarBranchButton } from "#/components/features/chat/git-control-bar-branch-button";+import { WorkspaceModeSelector } from "#/components/features/chat/workspace-mode-selector";import { Branch, GitRepository } from "#/types/git";import { Provider } from "#/types/settings";import { LocalWorkspace } from "#/types/workspace";@@ -9,7 +12,10 @@ interface HomeGitControlBarPreviewProps {repository?: GitRepository | null;branch?: Branch | null;provider?: Provider | null;+ workspaceMode: WorkspaceMode;+ backendKind: BackendKind;onRepoClick: () => void;+ onWorkspaceModeChange: (mode: WorkspaceMode) => void;}export function HomeGitControlBarPreview({@@ -17,7 +23,10 @@ export function HomeGitControlBarPreview({repository,branch,provider,+ workspaceMode,+ backendKind,onRepoClick,+ onWorkspaceModeChange,}: HomeGitControlBarPreviewProps) {const workspaceName = workspace? workspace.path.replace(/\/+$/, "").split("/").pop() || workspace.path@@ -34,6 +43,13 @@ export function HomeGitControlBarPreview({workspaceName={workspaceName}onClick={onRepoClick}/>+ {workspace ? (+ <WorkspaceModeSelector+ value={workspaceMode}+ backendKind={backendKind}+ onChange={onWorkspaceModeChange}+ />+ ) : null}{branch ? (<GitControlBarBranchButtonselectedBranch={branch.name}diff --git a/src/hooks/mutation/use-create-conversation.ts b/src/hooks/mutation/use-create-conversation.tsindex 41fedff3ce..166cc26e82 100644--- a/src/hooks/mutation/use-create-conversation.ts+++ b/src/hooks/mutation/use-create-conversation.ts@@ -8,6 +8,7 @@ import { useLlmProfiles } from "#/hooks/query/use-llm-profiles";import {getStoredConversationMetadata,setStoredConversationMetadata,+ type WorkspaceMode,} from "#/api/conversation-metadata-store";interface CreateConversationVariables {@@ -23,6 +24,7 @@ interface CreateConversationVariables {agentType?: "default" | "plan";plugins?: PluginSpec[];workingDir?: string;+ workspaceMode?: WorkspaceMode;}interface CreateConversationResponse {@@ -51,6 +53,7 @@ export const useCreateConversation = () => {plugins,repository,workingDir,+ workspaceMode,parentConversationId,agentType,} = variables;@@ -68,6 +71,7 @@ export const useCreateConversation = () => {}: null,workingDir,+ workspaceMode,parentConversationId,agentType,);@@ -85,6 +89,7 @@ export const useCreateConversation = () => {selected_branch: prev?.selected_branch ?? null,git_provider: prev?.git_provider ?? null,selected_workspace: prev?.selected_workspace ?? null,+ workspace_mode: prev?.workspace_mode ?? null,active_profile: llmProfiles.active_profile,});}diff --git a/src/hooks/mutation/use-new-conversation-command.ts b/src/hooks/mutation/use-new-conversation-command.tsindex 47b7fa40a7..897447de0c 100644--- a/src/hooks/mutation/use-new-conversation-command.ts+++ b/src/hooks/mutation/use-new-conversation-command.ts@@ -34,6 +34,7 @@ export const useNewConversationCommand = () => {undefined,undefined,undefined,+ undefined,conversation.sandbox_id ?? undefined,);diff --git a/src/hooks/use-has-attached-source.ts b/src/hooks/use-has-attached-source.tsindex c1636d9fd2..0c7b002a08 100644--- a/src/hooks/use-has-attached-source.ts+++ b/src/hooks/use-has-attached-source.ts@@ -9,11 +9,11 @@ import { useActiveConversation } from "#/hooks/query/use-active-conversation";* user came in to inspect, so the diff view is the more useful default.** We deliberately do *not* probe the filesystem here — the agent-server- * initialises every conversation workspace as an internal git worktree- * for change tracking, so a positive `git status` does not by itself- * imply the user attached a real source. That's why we read the- * explicit selection signals (`selected_repository` on the conversation,- * `selected_workspace` from the conversation-metadata store) instead.+ * can initialise conversations without an explicit selection in generated git+ * worktrees, so a positive `git status` does not by itself imply the user+ * attached a real source. That's why we read the explicit selection signals+ * (`selected_repository` on the conversation, `selected_workspace` from the+ * conversation-metadata store) instead.*/export function useHasAttachedSource(): {hasAttachedSource: boolean;diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex a682cc609e..dbc0c151df 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -22830,6 +22830,57 @@"uk": "Підключити репозиторій","ca": "Connecta el repositori"},+ "COMMON$WORKSPACE_MODE_LOCAL_REPO": {+ "en": "Local Repo",+ "ja": "ローカルリポジトリ",+ "zh-CN": "本地仓库",+ "zh-TW": "本機存放庫",+ "ko-KR": "로컬 저장소",+ "fr": "Dépôt local",+ "es": "Repositorio local",+ "de": "Lokales Repository",+ "it": "Repository locale",+ "pt": "Repositório local",+ "ar": "مستودع محلي",+ "no": "Lokalt repo",+ "tr": "Yerel Depo",+ "uk": "Локальний репозиторій",+ "ca": "Repositori local"+ },+ "COMMON$WORKSPACE_MODE_CLOUD_REPO": {+ "en": "Cloud Repo",+ "ja": "クラウドリポジトリ",+ "zh-CN": "云端仓库",+ "zh-TW": "雲端存放庫",+ "ko-KR": "클라우드 저장소",+ "fr": "Dépôt cloud",+ "es": "Repositorio en la nube",+ "de": "Cloud-Repository",+ "it": "Repository cloud",+ "pt": "Repositório na nuvem",+ "ar": "مستودع سحابي",+ "no": "Sky-repo",+ "tr": "Bulut Deposu",+ "uk": "Хмарний репозиторій",+ "ca": "Repositori al núvol"+ },+ "COMMON$WORKSPACE_MODE_NEW_WORKTREE": {+ "en": "New Worktree",+ "ja": "新規ワークツリー",+ "zh-CN": "新工作树",+ "zh-TW": "新工作樹",+ "ko-KR": "새 워크트리",+ "fr": "Nouveau worktree",+ "es": "Nuevo worktree",+ "de": "Neuer Worktree",+ "it": "Nuovo worktree",+ "pt": "Novo worktree",+ "ar": "شجرة عمل جديدة",+ "no": "Ny worktree",+ "tr": "Yeni Çalışma Ağacı",+ "uk": "Нове робоче дерево",+ "ca": "Nou worktree"+ },"COMMON$OPEN_REPOSITORY": {"en": "Open Repository","ja": "リポジトリを開く",diff --git a/src/utils/workspace-mode.ts b/src/utils/workspace-mode.tsnew file mode 100644index 0000000000..6375aaad5c--- /dev/null+++ b/src/utils/workspace-mode.ts@@ -0,0 +1,15 @@+import type { BackendKind } from "#/api/backend-registry/types";+import type { WorkspaceMode } from "#/api/conversation-metadata-store";+import { I18nKey } from "#/i18n/declaration";++export function getWorkspaceModeI18nKey(+ mode: WorkspaceMode,+ backendKind: BackendKind,+): I18nKey {+ if (mode === "new_worktree") {+ return I18nKey.COMMON$WORKSPACE_MODE_NEW_WORKTREE;+ }+ return backendKind === "cloud"+ ? I18nKey.COMMON$WORKSPACE_MODE_CLOUD_REPO+ : I18nKey.COMMON$WORKSPACE_MODE_LOCAL_REPO;+}