@@ -79,7 +79,7 @@ import {
7979 rememberModelOptions ,
8080 withRememberedModelOptions ,
8181} from "../../state/use-model-option-memory" ;
82- import { useDebouncedValue , usePaginatedBranches } from "../../state/queries" ;
82+ import { useBranches , useDebouncedValue , usePaginatedBranches } from "../../state/queries" ;
8383import { vcsEnvironment } from "../../state/vcs" ;
8484import {
8585 flattenQueuedThreadMessages ,
@@ -119,6 +119,7 @@ import {
119119 filterNewTaskBranches ,
120120 resolveNewTaskBranchWorktreePath ,
121121 resolveNewTaskLocalWorkspaceSelection ,
122+ resolveNewTaskWorkspaceSelection ,
122123} from "./new-task-context-presentation" ;
123124import { resolveEnvironmentProjectMatch } from "./new-task-project-selection" ;
124125import { resolveProjectThreadCreationBranch } from "./projectThreadCreationValidation" ;
@@ -169,6 +170,8 @@ type NewTaskFlowContextValue = {
169170 readonly selectedProjectKey : string | null ;
170171 readonly selectedModelKey : string | null ;
171172 readonly workspaceMode : WorkspaceMode ;
173+ readonly isGitRepo : boolean ;
174+ readonly isGitRepoKnown : boolean ;
172175 readonly canChooseWorkspace : boolean ;
173176 readonly selectedBranchName : string | null ;
174177 readonly selectedWorktreePath : string | null ;
@@ -435,6 +438,22 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
435438 const selectedProjectDraft = useComposerDraft ( selectedProjectDraftKey ) ;
436439 const prompt = selectedProjectDraft . text ;
437440 const attachments = selectedProjectDraft . attachments ;
441+ const projectGitStatus = useEnvironmentQuery (
442+ selectedProject !== null && selectedProject . workspaceRoot !== ""
443+ ? vcsEnvironment . status ( {
444+ environmentId : selectedProject . environmentId ,
445+ input : { cwd : selectedProject . workspaceRoot } ,
446+ } )
447+ : null ,
448+ ) ;
449+ const currentCheckoutBranchName = projectGitStatus . data ?. refName ?? null ;
450+ // The unfiltered ref list also provides repository capability while offline.
451+ const projectBranches = useBranches ( {
452+ environmentId : selectedProject ?. environmentId ?? null ,
453+ cwd : selectedProject ?. workspaceRoot || null ,
454+ } ) ;
455+ const knownIsGitRepo = projectGitStatus . data ?. isRepo ?? projectBranches . data ?. isRepo ?? null ;
456+ const isGitRepo = knownIsGitRepo ?? true ;
438457 const fileAccessSession = useEnvironmentQuery (
439458 selectedProject !== null && selectedProject . workspaceRoot !== ""
440459 ? environmentSession . sessionStateAtom ( selectedProject . environmentId )
@@ -497,17 +516,20 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
497516 selectedProjectDraft . workspaceSelection ?. mode !== undefined ||
498517 projectSettings . sources . defaultThreadEnvMode !== "environment" ||
499518 ( ! t3ProjectFileQuery . isPending && ! fileAccessPending ) ;
500- const workspaceMode = canChooseWorkspace
501- ? ( selectedProjectDraft . workspaceSelection ?. mode ?? defaultWorkspaceMode )
502- : "local" ;
503- const selectedBranchName = selectedProjectDraft . workspaceSelection ?. branch ?? null ;
504- const selectedWorktreePath = selectedProjectDraft . workspaceSelection ?. worktreePath ?? null ;
519+ const workspaceSelection = resolveNewTaskWorkspaceSelection ( {
520+ selection : canChooseWorkspace ? selectedProjectDraft . workspaceSelection : undefined ,
521+ fallback : { mode : defaultWorkspaceMode , branch : null , worktreePath : null } ,
522+ isGitRepo,
523+ } ) ;
524+ const workspaceMode = workspaceSelection . mode ;
525+ const selectedBranchName = workspaceSelection . branch ;
526+ const selectedWorktreePath = workspaceSelection . worktreePath ;
505527 // Keep the user's explicit choice separate from the resolved display value:
506528 // only the explicit flag is ever written back to the draft, so the resolved
507529 // value keeps tracking the server setting when the config loads late.
508530 const draftStartFromOrigin = selectedProjectDraft . workspaceSelection ?. startFromOrigin ;
509531 const startFromOrigin =
510- draftStartFromOrigin ?? projectSettings . settings . newWorktreesStartFromOrigin ;
532+ isGitRepo && ( draftStartFromOrigin ?? projectSettings . settings . newWorktreesStartFromOrigin ) ;
511533 const defaultRuntimeMode = editingPendingTask
512534 ? ( editingPendingTask . runtimeMode ?? DEFAULT_RUNTIME_MODE )
513535 : projectSettings . settings . defaultRuntimeMode ;
@@ -662,15 +684,6 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
662684 allBranchRefs ,
663685 Arr . filter ( ( branch ) => ! branch . isRemote ) ,
664686 ) ;
665- const projectGitStatus = useEnvironmentQuery (
666- branchTarget . environmentId !== null && branchTarget . cwd !== null
667- ? vcsEnvironment . status ( {
668- environmentId : branchTarget . environmentId ,
669- input : { cwd : branchTarget . cwd } ,
670- } )
671- : null ,
672- ) ;
673- const currentCheckoutBranchName = projectGitStatus . data ?. refName ?? null ;
674687
675688 const filteredBranches = filterNewTaskBranches ( allBranchRefs , branchQuery ) ;
676689
@@ -971,8 +984,12 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
971984 ) {
972985 return null ;
973986 }
974- const workspaceSelection = canChooseWorkspace ? draft . workspaceSelection : undefined ;
975- const mode = workspaceSelection ?. mode ?? workspaceMode ;
987+ const workspaceSelection = resolveNewTaskWorkspaceSelection ( {
988+ selection : canChooseWorkspace ? draft . workspaceSelection : undefined ,
989+ fallback : { mode : workspaceMode , branch : null , worktreePath : null } ,
990+ isGitRepo,
991+ } ) ;
992+ const mode = workspaceSelection . mode ;
976993 // When the selection is the stand-in built from the queued snapshot,
977994 // persist the original (possibly absent) snapshot values — the
978995 // stand-in's placeholder title/workspaceRoot must never be written back
@@ -1131,6 +1148,8 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
11311148 selectedProjectKey,
11321149 selectedModelKey,
11331150 workspaceMode,
1151+ isGitRepo,
1152+ isGitRepoKnown : knownIsGitRepo !== null ,
11341153 canChooseWorkspace,
11351154 selectedBranchName,
11361155 selectedWorktreePath,
0 commit comments