Skip to content
Open
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
6 changes: 6 additions & 0 deletions apps/mobile/src/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { AddProjectSourceRoute } from "./features/projects/AddProjectSourceRoute
import {
NewTaskBranchPickerRouteScreen,
NewTaskEnvironmentPickerRouteScreen,
NewTaskRepositoriesPickerRouteScreen,
} from "./features/threads/NewTaskContextPickerScreens";
import {
ExistingThreadSettingsRouteScreen,
Expand Down Expand Up @@ -572,6 +573,11 @@ const RootStackConfig = createWorkspaceStackNavigator({
screen: NewTaskBranchPickerRouteScreen,
options: pageRoute({ title: "Branch" }),
}),
NewTaskRepositories: createNativeStackScreen({
linking: "new/draft/repositories",
screen: NewTaskRepositoriesPickerRouteScreen,
options: pageRoute({ title: "Repositories" }),
}),
AddProject: createNativeStackScreen({
linking: "new/add-project",
screen: AddProjectSourceRoute,
Expand Down
14 changes: 12 additions & 2 deletions apps/mobile/src/components/ComposerToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function ComposerInlineControl(props: {
readonly accessibilityLabel?: string;
readonly disabled?: boolean;
readonly emphasized?: boolean;
/** The control asks for a decision; it stays usable. */
readonly tone?: "warning";
readonly icon?: ComponentProps<typeof SymbolView>["name"];
readonly renderIcon?: (size: number) => ReactNode;
readonly label: string;
Expand Down Expand Up @@ -80,7 +82,11 @@ export function ComposerInlineControl(props: {
name={props.icon}
size={iconSize}
tintColorClassName={
props.emphasized || props.selected ? "accent-icon" : "accent-icon-muted"
props.tone === "warning"
? "accent-warning-foreground"
: props.emphasized || props.selected
? "accent-icon"
: "accent-icon-muted"
}
type="monochrome"
/>
Expand All @@ -93,7 +99,11 @@ export function ComposerInlineControl(props: {
<Text
className={cn(
props.size === "large" ? "text-base font-t3-medium" : "text-sm font-t3-medium",
props.emphasized || props.selected ? "text-foreground" : "text-foreground-muted",
props.tone === "warning"
? "text-warning-foreground"
: props.emphasized || props.selected
? "text-foreground"
: "text-foreground-muted",
)}
numberOfLines={1}
ellipsizeMode={props.labelEllipsizeMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const LISTED_OVERLAY_ROUTES: ReadonlySet<string> = new Set([
"AddProjectNew",
"NewTaskEnvironment",
"NewTaskBranch",
"NewTaskRepositories",
"SettingsLegal",
"SettingsAuth",
"SettingsWaitlist",
Expand Down
95 changes: 95 additions & 0 deletions apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,101 @@ export function NewTaskBranchPickerRouteScreen() {
);
}

export function NewTaskRepositoriesPickerRouteScreen() {
const flow = useNewTaskFlow();
const navigation = useNavigation();
const insets = useSafeAreaInsets();
const choices = flow.worktreeRepositoryChoices;
const selection = flow.worktreeRepositorySelection;
const selected = new Set(selection.selected);
const toggle = (repositoryPath: string) => {
if (choices === null) return;
void Haptics.selectionAsync();
flow.setWorktreeRepositories(
choices.flatMap((choice) =>
(choice.repositoryPath === repositoryPath) !== selected.has(choice.repositoryPath)
? [choice.repositoryPath]
: [],
),
);
};
const header =
choices === null || choices.length === 0 ? null : (
<View className="gap-3 pb-3">
<Text textRole="footnote" className="px-1 text-foreground-muted">
{selection.needsChoice
? "Choose the repositories this thread works on."
: "Each gets its own worktree on the thread's branch."}
</Text>
<View className="flex-row gap-2">
<Button
label="Select all"
size="compact"
disabled={selected.size === choices.length}
onPress={() =>
flow.setWorktreeRepositories(choices.map((choice) => choice.repositoryPath))
}
/>
<Button
label="Select none"
size="compact"
disabled={!selection.needsChoice && selected.size === 0}
onPress={() => flow.setWorktreeRepositories([])}
/>
</View>
</View>
);
return (
<View className="flex-1 bg-sheet" collapsable={false}>
<AppBar title="Repositories" hideBottomBorder onBack={() => navigation.goBack()} />
<ScreenContent>
{choices === null || choices.length === 0 ? (
<View className="flex-1 items-center justify-center gap-3 px-4">
{choices === null ? <AppActivityIndicator /> : null}
<Text className="text-center text-sm text-foreground-muted">
{choices === null ? "Loading repositories…" : "This project tracks no repositories"}
</Text>
</View>
) : (
<LegendList
renderScrollComponent={NativeScrollView}
alwaysBounceVertical={false}
automaticallyAdjustsScrollIndicatorInsets
className="flex-1 bg-sheet android:bg-sheet-solid"
contentInsetAdjustmentBehavior="automatic"
contentContainerStyle={{
paddingBottom: Math.max(insets.bottom, 16) + 16,
paddingHorizontal: 16,
paddingTop: 16,
}}
data={choices}
extraData={selection.selected}
keyExtractor={(choice) => choice.repositoryPath}
ListHeaderComponent={header}
renderItem={({ item, index }) => (
<SelectionRow
icon="folder"
role="checkbox"
isFirst={index === 0}
isLast={index === choices.length - 1}
onPress={() => toggle(item.repositoryPath)}
selected={selected.has(item.repositoryPath)}
subtitle={
item.relativePath !== undefined && item.relativePath !== item.name
? item.relativePath
: undefined
}
title={item.name}
/>
)}
showsVerticalScrollIndicator={false}
/>
)}
</ScreenContent>
</View>
);
}

export function BranchPickerScreen(props: {
readonly title: string;
readonly project: EnvironmentProject | null;
Expand Down
61 changes: 45 additions & 16 deletions apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ export function NewTaskDraftScreen(props: {
!modelSelection ||
(initialMessageText.length === 0 && draft.attachments.length === 0) ||
flow.submitting ||
(workspaceMode === "worktree" && !selectedBranchName)
(workspaceMode === "worktree" && flow.isGitRepo && !selectedBranchName)
) {
return null;
}
Expand Down Expand Up @@ -703,7 +703,8 @@ export function NewTaskDraftScreen(props: {
? "Wait for the project clone to finish."
: flow.submitting
? "Starting the thread…"
: flow.workspaceMode === "worktree" && (!flow.selectedBranchName || !flow.isGitRepoKnown)
: flow.workspaceMode === "worktree" &&
(!flow.isGitRepoKnown || (flow.isGitRepo && !flow.selectedBranchName))
? "Choose a base branch before creating a worktree."
: null
: "Wait for shared content to finish importing.";
Expand All @@ -715,7 +716,9 @@ export function NewTaskDraftScreen(props: {
void KeyboardController.dismiss({ animated: true });
navigation.navigate("NewTaskProject", { incomingShareId: props.incomingShareId });
};
const openContextPicker = (routeName: "NewTaskBranch" | "NewTaskEnvironment") => {
const openContextPicker = (
routeName: "NewTaskBranch" | "NewTaskEnvironment" | "NewTaskRepositories",
) => {
if (isComposerInteractionLocked) {
return;
}
Expand Down Expand Up @@ -867,12 +870,15 @@ export function NewTaskDraftScreen(props: {
</View>
);

const startsNewWorktree = flow.workspaceMode === "worktree";
const offersRepositoryChoice =
startsNewWorktree && (flow.worktreeRepositoryChoices?.length ?? 0) > 0;
const workspaceControls = (
<View className="flex-row items-center gap-1 px-2">
<View className="flex-row flex-wrap items-center gap-x-1 px-2">
<ComposerInlineControl
accessibilityHint={`Switches to ${flow.workspaceMode === "local" ? "a new worktree" : "the current checkout"}`}
accessibilityLabel={workspaceLabel}
disabled={isComposerInteractionLocked || !flow.isGitRepo}
disabled={isComposerInteractionLocked || !(flow.isGitRepo || flow.tracksGitRepositories)}
renderIcon={(size) => (
<NewTaskWorkspaceIcon
workspaceMode={flow.workspaceMode}
Expand All @@ -886,17 +892,40 @@ export function NewTaskDraftScreen(props: {
showChevron={false}
/>

<View className="min-w-0 shrink">
<ComposerInlineControl
accessibilityLabel={`${flow.workspaceMode === "worktree" ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
chevronDirection="right"
disabled={isComposerInteractionLocked || !flow.isGitRepo}
icon="arrow.triangle.branch"
label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
maxWidth="100%"
onPress={() => openContextPicker("NewTaskBranch")}
/>
</View>
{offersRepositoryChoice ? (
<View className="min-w-0 shrink">
<ComposerInlineControl
accessibilityHint="Chooses the repositories the new worktree holds"
accessibilityLabel={`Repositories in the new worktree: ${flow.worktreeRepositorySelection.label}`}
chevronDirection="right"
disabled={isComposerInteractionLocked}
icon="folder.badge.plus"
label={flow.worktreeRepositorySelection.label}
maxWidth="100%"
onPress={() => openContextPicker("NewTaskRepositories")}
{...(flow.worktreeRepositorySelection.needsChoice ? { tone: "warning" as const } : {})}
/>
</View>
) : null}
{startsNewWorktree && !flow.isGitRepo ? (
<View className="min-h-8 min-w-0 shrink justify-center px-2">
<Text className="text-sm text-foreground-muted" numberOfLines={1}>
Each repository starts from its own default branch
</Text>
</View>
) : (
<View className="min-w-0 shrink">
<ComposerInlineControl
accessibilityLabel={`${startsNewWorktree ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
chevronDirection="right"
disabled={isComposerInteractionLocked || !flow.isGitRepo}
icon="arrow.triangle.branch"
label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
maxWidth="100%"
onPress={() => openContextPicker("NewTaskBranch")}
/>
</View>
)}
</View>
);

Expand Down
14 changes: 13 additions & 1 deletion apps/mobile/src/features/threads/ThreadGitControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,19 @@ export function useThreadGitMenuDefinition(props: ThreadGitMenuProps): AppBarMen
separateBackground: false,
items: [
...(repositoriesOnly
? []
? // A worktree thread of such a folder still has a branch: its repositories are on it.
props.currentBranch === null
? []
: [
{
id: "git-status",
title: compactMenuBranchLabel(props.currentBranch),
icon: "point.topleft.down.curvedto.point.bottomright.up",
disabled: true,
subtitle: "Repository worktrees",
onPress: () => {},
},
]
: [
{
id: "git-status",
Expand Down
29 changes: 23 additions & 6 deletions apps/mobile/src/features/threads/git/GitOverviewSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ScreenContent } from "../../../components/ui/ScreenContent";
import { SheetPane } from "../../../components/ui/SheetPane";
import { InspectorSheetContext } from "../../layout/workspace-inspector-sheet";
import { AppText as Text } from "../../../components/ui/AppText";
import { filesystemEnvironment } from "../../../state/filesystem";
import { useEnvironmentQuery } from "../../../state/query";
import {
gitRepositoryRouteParams,
Expand Down Expand Up @@ -123,26 +124,40 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
// A plain folder that tracks repositories has no branch of its own; its turns still have diffs.
const projectRepositoryCount = selectedThreadProject?.trackedFolders?.length ?? 0;
const trackedRepositoryCount = isRepo || repository !== undefined ? 0 : projectRepositoryCount;
// A thread in its own worktree reaches no tracked repository.
// A worktree thread reaches tracked repositories only through its own task folder.
const taskFolderQuery = useEnvironmentQuery(
selectedThread !== null && selectedThreadWorktreePath !== null && projectRepositoryCount > 0
? filesystemEnvironment.taskFolder({
environmentId: selectedThread.environmentId,
input: { worktreePath: selectedThreadWorktreePath },
})
: null,
);
const taskFolder = taskFolderQuery.data?.taskFolder ?? null;
const listsRepositories =
repository === undefined &&
selectedThreadProject !== null &&
projectRepositoryCount > 0 &&
selectedThreadWorktreePath === null;
(selectedThreadWorktreePath === null || taskFolder !== null);
const currentBranchLabel =
repository !== undefined
? repository.name
: trackedRepositoryCount > 0
? (selectedThreadProject?.title ?? "Repositories")
? // A task folder's plain project folder has no branch; its repositories are on the thread's.
((taskFolder === null ? null : selectedThread?.branch) ??
selectedThreadProject?.title ??
"Repositories")
: (gitStatus.data?.refName ?? selectedThread?.branch ?? "Detached HEAD");
const currentStatusSummary =
repository !== undefined
? gitStatus.data?.isRepo
? `${gitStatus.data.refName ?? "Detached HEAD"} · ${statusSummary(gitStatus.data)}`
: statusSummary(gitStatus.data)
: trackedRepositoryCount > 0
? `${trackedRepositoryCount} tracked ${trackedRepositoryCount === 1 ? "repository" : "repositories"}`
: statusSummary(gitStatus.data);
: taskFolder !== null && trackedRepositoryCount > 0
? `${taskFolder.repositories.length} repository ${taskFolder.repositories.length === 1 ? "worktree" : "worktrees"}`
: trackedRepositoryCount > 0
? `${trackedRepositoryCount} tracked ${trackedRepositoryCount === 1 ? "repository" : "repositories"}`
: statusSummary(gitStatus.data);
const currentWorktreePath = repository === undefined ? selectedThreadWorktreePath : null;
const gitOperationLabel = gitState.gitOperationLabel;
const busy = gitOperationLabel !== null;
Expand Down Expand Up @@ -394,6 +409,8 @@ function GitOverviewSheetContent(props: GitOverviewSheetProps) {
threadRef={threadRef}
projectId={selectedThreadProject.id}
threadCwd={selectedThreadCwd}
taskFolder={taskFolder}
onTaskFolderChange={taskFolderQuery.refresh}
explainsEmpty={!isRepo}
onOpen={openRepository}
/>
Expand Down
Loading
Loading