@@ -78,7 +78,7 @@ import {
7878 rememberModelOptions,
7979 withRememberedModelOptions,
8080} from "../../state/use-model-option-memory";
81- import { useDebouncedValue, usePaginatedBranches } from "../../state/queries";
81+ import { useBranches, useDebouncedValue, usePaginatedBranches } from "../../state/queries";
8282import { vcsEnvironment } from "../../state/vcs";
8383import {
8484 flattenQueuedThreadMessages,
@@ -118,6 +118,7 @@ import {
118118 filterNewTaskBranches,
119119 resolveNewTaskBranchWorktreePath,
120120 resolveNewTaskLocalWorkspaceSelection,
121+ resolveNewTaskWorkspaceSelection,
121122} from "./new-task-context-presentation";
122123import { resolveEnvironmentProjectMatch } from "./new-task-project-selection";
123124import { resolveProjectThreadCreationBranch } from "./projectThreadCreationValidation";
@@ -168,6 +169,7 @@ type NewTaskFlowContextValue = {
168169 readonly selectedProjectKey: string | null;
169170 readonly selectedModelKey: string | null;
170171 readonly workspaceMode: WorkspaceMode;
172+ readonly isGitRepo: boolean;
171173 readonly canChooseWorkspace: boolean;
172174 readonly selectedBranchName: string | null;
173175 readonly selectedWorktreePath: string | null;
@@ -434,6 +436,21 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
434436 const selectedProjectDraft = useComposerDraft(selectedProjectDraftKey);
435437 const prompt = selectedProjectDraft.text;
436438 const attachments = selectedProjectDraft.attachments;
439+ const projectGitStatus = useEnvironmentQuery(
440+ selectedProject !== null && selectedProject.workspaceRoot !== ""
441+ ? vcsEnvironment.status({
442+ environmentId: selectedProject.environmentId,
443+ input: { cwd: selectedProject.workspaceRoot },
444+ })
445+ : null,
446+ );
447+ const currentCheckoutBranchName = projectGitStatus.data?.refName ?? null;
448+ // The unfiltered ref list also provides repository capability while offline.
449+ const projectBranches = useBranches({
450+ environmentId: selectedProject?.environmentId ?? null,
451+ cwd: selectedProject?.workspaceRoot || null,
452+ });
453+ const isGitRepo = projectGitStatus.data?.isRepo ?? projectBranches.data?.isRepo ?? true;
437454 const fileAccessSession = useEnvironmentQuery(
438455 selectedProject !== null && selectedProject.workspaceRoot !== ""
439456 ? environmentSession.sessionStateAtom(selectedProject.environmentId)
@@ -492,17 +509,20 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
492509 selectedProjectDraft.workspaceSelection?.mode !== undefined ||
493510 projectSettings.sources.defaultThreadEnvMode !== "environment" ||
494511 (!t3ProjectFileQuery.isPending && !fileAccessPending);
495- const workspaceMode = canChooseWorkspace
496- ? (selectedProjectDraft.workspaceSelection?.mode ?? defaultWorkspaceMode)
497- : "local";
498- const selectedBranchName = selectedProjectDraft.workspaceSelection?.branch ?? null;
499- const selectedWorktreePath = selectedProjectDraft.workspaceSelection?.worktreePath ?? null;
512+ const workspaceSelection = resolveNewTaskWorkspaceSelection({
513+ selection: canChooseWorkspace ? selectedProjectDraft.workspaceSelection : undefined,
514+ fallback: { mode: defaultWorkspaceMode, branch: null, worktreePath: null },
515+ isGitRepo,
516+ });
517+ const workspaceMode = workspaceSelection.mode;
518+ const selectedBranchName = workspaceSelection.branch;
519+ const selectedWorktreePath = workspaceSelection.worktreePath;
500520 // Keep the user's explicit choice separate from the resolved display value:
501521 // only the explicit flag is ever written back to the draft, so the resolved
502522 // value keeps tracking the server setting when the config loads late.
503523 const draftStartFromOrigin = selectedProjectDraft.workspaceSelection?.startFromOrigin;
504524 const startFromOrigin =
505- draftStartFromOrigin ?? projectSettings.settings.newWorktreesStartFromOrigin;
525+ isGitRepo && ( draftStartFromOrigin ?? projectSettings.settings.newWorktreesStartFromOrigin) ;
506526 const defaultRuntimeMode = editingPendingTask
507527 ? (editingPendingTask.runtimeMode ?? DEFAULT_RUNTIME_MODE)
508528 : projectSettings.settings.defaultRuntimeMode;
@@ -657,15 +677,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
657677 allBranchRefs,
658678 Arr.filter((branch) => !branch.isRemote),
659679 );
660- const projectGitStatus = useEnvironmentQuery(
661- branchTarget.environmentId !== null && branchTarget.cwd !== null
662- ? vcsEnvironment.status({
663- environmentId: branchTarget.environmentId,
664- input: { cwd: branchTarget.cwd },
665- })
666- : null,
667- );
668- const currentCheckoutBranchName = projectGitStatus.data?.refName ?? null;
669680
670681 const filteredBranches = filterNewTaskBranches(allBranchRefs, branchQuery);
671682
@@ -957,8 +968,12 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
957968 if ((text.length === 0 && draft.attachments.length === 0) || !draftModelSelection) {
958969 return null;
959970 }
960- const workspaceSelection = canChooseWorkspace ? draft.workspaceSelection : undefined;
961- const mode = workspaceSelection?.mode ?? workspaceMode;
971+ const workspaceSelection = resolveNewTaskWorkspaceSelection({
972+ selection: canChooseWorkspace ? draft.workspaceSelection : undefined,
973+ fallback: { mode: workspaceMode, branch: null, worktreePath: null },
974+ isGitRepo,
975+ });
976+ const mode = workspaceSelection.mode;
962977 // When the selection is the stand-in built from the queued snapshot,
963978 // persist the original (possibly absent) snapshot values — the
964979 // stand-in's placeholder title/workspaceRoot must never be written back
@@ -1117,6 +1132,7 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
11171132 selectedProjectKey,
11181133 selectedModelKey,
11191134 workspaceMode,
1135+ isGitRepo,
11201136 canChooseWorkspace,
11211137 selectedBranchName,
11221138 selectedWorktreePath,
0 commit comments