The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): add project and checkout removal (#21409)
maria committed
Oct 21, 2026 at 00:03 UTC
0dc38c75f5704e2308bf93954910a6ab0c393a74
5 files changed
+325
-40
apps/mobile/src/features/settings/SettingsProjectOverviewRouteScreen.tsx
+201
-3
@@ -2,16 +2,38 @@ import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScroll
2
import { AppText as Text, AppTextInput } from "../../components/ui/AppText";
3
import { Button } from "../../components/ui/Button";
4
import { ProjectFavicon } from "../../components/ProjectFavicon";
5
+import * as Dialog from "../../components/ui/Dialog";
6
+import { AuthOrchestrationOperateScope } from "@t3tools/contracts";
7
+import { planProjectRemoval } from "@t3tools/client-runtime/state/projects";
8
+import {
9
+ isAtomCommandInterrupted,
10
+ squashAtomCommandFailure,
11
+} from "@t3tools/client-runtime/state/runtime";
12
import { deriveProjectGroupLabel } from "@t3tools/client-runtime/state/project-grouping";
13
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
7
-import { useState } from "react";
8
-import { Platform, View } from "react-native";
14
+import { useNavigation } from "@react-navigation/native";
15
+import { useEffect, useRef, useState } from "react";
16
+import { Platform, Pressable, View } from "react-native";
17
import { useSafeAreaInsets } from "react-native-safe-area-context";
18
19
import { projectEnvironment } from "../../state/projects";
20
+import { useThreadShells } from "../../state/entities";
21
+import { appAtomRegistry } from "../../state/atom-registry";
22
+import {
23
+ clearComposerDraft,
24
+ composerDraftsAtom,
25
+ findNewTaskDraftKeys,
26
+ waitForComposerDraftsLoaded,
27
+} from "../../state/use-composer-drafts";
28
+import {
29
+ readEnvironmentScope,
30
+ useEnvironmentScope,
31
+ useEnvironmentsWithScope,
32
+} from "../../state/session";
33
import { useAtomCommand } from "../../state/use-atom-command";
34
import { SettingsScreen } from "./components/SettingsScreen";
35
import { SettingsSection } from "./components/SettingsSection";
36
+import { SettingsActionRow } from "./components/SettingsActionRow";
37
import {
38
AndroidSettingsEnvironmentFilter,
39
SettingsEnvironmentFilterHeader,
@@ -20,7 +42,31 @@ import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-en
42
43
export function SettingsProjectOverviewRouteScreen() {
44
const insets = useSafeAreaInsets();
23
- const { selectedTargets, projectGroups, selectedProjectKey } = useSettingsEnvironmentFilter();
45
+ const [isRemoving, setIsRemoving] = useState(false);
46
+ const removalPending = useRef(false);
47
+ const startRemoval = () => {
48
+ if (removalPending.current) return false;
49
+ removalPending.current = true;
50
+ return true;
51
+ };
52
+ const finishRemoval = () => {
53
+ removalPending.current = false;
54
+ setIsRemoving(false);
55
+ };
56
+ const navigation = useNavigation();
57
+ const { selectedTargets, projectGroups, selectedProjectKey, selectProject } =
58
+ useSettingsEnvironmentFilter();
59
+ const latestProjectKey = useRef(selectedProjectKey);
60
+ useEffect(() => {
61
+ latestProjectKey.current = selectedProjectKey;
62
+ }, [selectedProjectKey]);
63
+ // The filter can move to another project while a removal is still running.
64
+ const finishProjectRemoval = (projectKey: string | null) => {
65
+ if (latestProjectKey.current !== projectKey) return;
66
+ if (navigation.isFocused()) navigation.goBack();
67
+ // Otherwise the filter keeps pointing at the removed project as an unavailable one.
68
+ selectProject(null);
69
+ };
70
const group = projectGroups.find((entry) => entry.key === selectedProjectKey);
71
const selectedEnvironmentIds = new Set(selectedTargets.map((entry) => entry.environmentId));
72
const members =
@@ -49,6 +95,13 @@ export function SettingsProjectOverviewRouteScreen() {
95
key={`${selectedProjectKey}:${members.map((member) => member.id).join(",")}`}
96
members={members}
97
environments={selectedTargets}
98
+ hasOtherMembers={members.length < (group?.members.length ?? 0)}
99
+ isRemoving={isRemoving}
100
+ setIsRemoving={setIsRemoving}
101
+ startRemoval={startRemoval}
102
+ finishRemoval={finishRemoval}
103
+ projectKey={selectedProjectKey}
104
+ onProjectRemoved={finishProjectRemoval}
105
/>
106
)}
107
</ScrollView>
@@ -60,11 +113,28 @@ export function SettingsProjectOverviewRouteScreen() {
113
function ProjectOverviewContent(props: {
114
readonly members: readonly EnvironmentProject[];
115
readonly environments: readonly SettingsTarget[];
116
+ readonly hasOtherMembers: boolean;
117
+ readonly isRemoving: boolean;
118
+ readonly setIsRemoving: (isRemoving: boolean) => void;
119
+ readonly startRemoval: () => boolean;
120
+ readonly finishRemoval: () => void;
121
+ readonly projectKey: string | null;
122
+ readonly onProjectRemoved: (projectKey: string | null) => void;
123
}) {
124
+ const { isRemoving, setIsRemoving, startRemoval, finishRemoval } = props;
125
const representative = props.members[0]!;
126
const displayName = deriveProjectGroupLabel({ representative, members: props.members });
127
const [draftName, setDraftName] = useState<string | null>(null);
128
const [isSaving, setIsSaving] = useState(false);
129
+ const threads = useThreadShells();
130
+ const removableEnvironments = useEnvironmentsWithScope(
131
+ props.members,
132
+ AuthOrchestrationOperateScope,
133
+ );
134
+ const canRemoveGroup = props.members.every((member) =>
135
+ removableEnvironments.has(member.environmentId),
136
+ );
137
+ const deleteProject = useAtomCommand(projectEnvironment.delete, { reportFailure: false });
138
const updateProject = useAtomCommand(projectEnvironment.update, {
139
label: "project name update",
140
reportFailure: true,
@@ -72,6 +142,85 @@ function ProjectOverviewContent(props: {
142
const nextName = (draftName ?? displayName).trim();
143
const canSave = !isSaving && nextName.length > 0 && nextName !== displayName;
144
145
+ const checkRemovalAccess = (members: readonly EnvironmentProject[]) => {
146
+ const denied = members.find(
147
+ (member) => !readEnvironmentScope(member.environmentId, AuthOrchestrationOperateScope),
148
+ );
149
+ if (!denied) return true;
150
+ const environment = props.environments.find(
151
+ (entry) => entry.environmentId === denied.environmentId,
152
+ );
153
+ Dialog.alert(
154
+ "Failed to remove project",
155
+ `This connection cannot change projects in ${environment?.label ?? "this environment"}.`,
156
+ );
157
+ return false;
158
+ };
159
+
160
+ const removeMembers = (members: readonly EnvironmentProject[]) => {
161
+ if (!checkRemovalAccess(members) || !startRemoval()) return;
162
+ const projectKey = props.projectKey;
163
+ const plan = planProjectRemoval({
164
+ members: members.map((member) => ({
165
+ ...member,
166
+ environmentLabel: props.environments.find(
167
+ (entry) => entry.environmentId === member.environmentId,
168
+ )?.label,
169
+ })),
170
+ groupMemberCount: props.members.length,
171
+ hasOtherMembers: props.hasOtherMembers,
172
+ displayName,
173
+ threads,
174
+ });
175
+ Dialog.confirm({
176
+ title: plan.targetKind === "checkout" ? "Remove checkout" : "Remove project",
177
+ message: plan.confirmationMessage,
178
+ confirmText: plan.targetKind === "checkout" ? "Remove checkout" : "Remove project",
179
+ destructive: true,
180
+ onCancel: finishRemoval,
181
+ onConfirm: () => {
182
+ void (async () => {
183
+ setIsRemoving(true);
184
+ if (!checkRemovalAccess(members)) return;
185
+ for (const member of members) {
186
+ if (!checkRemovalAccess([member])) return;
187
+ const result = await deleteProject({
188
+ environmentId: member.environmentId,
189
+ input: { projectId: member.id, force: true },
190
+ });
191
+ if (result._tag === "Failure") {
192
+ if (!isAtomCommandInterrupted(result)) {
193
+ const error = squashAtomCommandFailure(result);
194
+ Dialog.alert(
195
+ `Failed to remove "${member.title}"`,
196
+ error instanceof Error ? error.message : "An error occurred.",
197
+ );
198
+ }
199
+ return;
200
+ }
201
+ await waitForComposerDraftsLoaded()
202
+ .then(() => {
203
+ for (const draftKey of findNewTaskDraftKeys(
204
+ appAtomRegistry.get(composerDraftsAtom),
205
+ {
206
+ environmentId: member.environmentId,
207
+ projectId: member.id,
208
+ },
209
+ )) {
210
+ clearComposerDraft(draftKey);
211
+ }
212
+ })
213
+ .catch((error) => {
214
+ console.warn("[project-removal] could not clear composer drafts", error);
215
+ });
216
+ }
217
+ // Nothing is left to show once the whole project is gone.
218
+ if (plan.targetKind === "project") props.onProjectRemoved(projectKey);
219
+ })().finally(finishRemoval);
220
+ },
221
+ });
222
+ };
223
+
224
const saveName = () => {
225
if (!canSave) return;
226
setIsSaving(true);
@@ -162,10 +311,59 @@ function ProjectOverviewContent(props: {
311
<Text className="text-sm leading-normal text-foreground-muted" selectable>
312
{member.workspaceRoot}
313
</Text>
314
+ {props.members.length > 1 || props.hasOtherMembers ? (
315
+ <RemoveCheckoutAction
316
+ member={member}
317
+ disabled={isRemoving}
318
+ onPress={() => removeMembers([member])}
319
+ />
320
+ ) : null}
321
</View>
322
);
323
})}
324
</SettingsSection>
325
+ <SettingsSection title="Danger">
326
+ <SettingsActionRow
327
+ icon="trash"
328
+ label={
329
+ props.hasOtherMembers
330
+ ? "Remove checkout"
331
+ : props.members.length > 1
332
+ ? "Remove this project everywhere"
333
+ : "Remove project"
334
+ }
335
+ description={
336
+ props.hasOtherMembers
337
+ ? "Deletes the selected machine's checkout entries and their threads. Other machines and files on disk are not touched."
338
+ : props.members.length > 1
339
+ ? `Deletes all ${props.members.length} checkout entries and their threads on every machine. Files on disk are not touched.`
340
+ : "Deletes the project entry and its threads. Files on disk are not touched."
341
+ }
342
+ tone="danger"
343
+ disabled={!canRemoveGroup || isRemoving}
344
+ loading={isRemoving}
345
+ onPress={() => removeMembers(props.members)}
346
+ />
347
+ </SettingsSection>
348
</>
349
);
350
}
351
+
352
+function RemoveCheckoutAction(props: {
353
+ readonly member: EnvironmentProject;
354
+ readonly disabled: boolean;
355
+ readonly onPress: () => void;
356
+}) {
357
+ const canRemove = useEnvironmentScope(props.member.environmentId, AuthOrchestrationOperateScope);
358
+ return (
359
+ <Pressable
360
+ accessibilityRole="button"
361
+ accessibilityLabel={`Remove checkout ${props.member.workspaceRoot}`}
362
+ disabled={props.disabled || !canRemove}
363
+ onPress={props.onPress}
364
+ className="self-start rounded-full border border-border bg-card px-3 py-1.5 disabled:opacity-40"
365
+ >
366
+ <Text className="font-t3-medium text-xs text-danger-foreground">Remove checkout</Text>
367
+ </Pressable>
368
+ );
369
+}
apps/web/src/components/settings/ProjectSettingsPanel.logic.test.ts
+67
@@ -1,4 +1,6 @@
1
import { describe, expect, it } from "vite-plus/test";
2
+import { EnvironmentId, ProjectId } from "@t3tools/contracts";
3
+import { planProjectRemoval } from "@t3tools/client-runtime/state/projects";
4
5
import { projectGroupTitleNeedsUpdate } from "./ProjectSettingsPanel.logic";
6
@@ -21,3 +23,68 @@ describe("projectGroupTitleNeedsUpdate", () => {
23
);
24
});
25
});
26
+
27
+describe("project removal confirmation", () => {
28
+ const local = {
29
+ id: ProjectId.make("shared-id"),
30
+ environmentId: EnvironmentId.make("local"),
31
+ title: "Repo",
32
+ workspaceRoot: "/work/repo",
33
+ environmentLabel: "Local",
34
+ };
35
+ const remote = {
36
+ ...local,
37
+ environmentId: EnvironmentId.make("remote"),
38
+ environmentLabel: "Remote",
39
+ };
40
+
41
+ it("limits a checkout's thread count to its environment and project", () => {
42
+ const plan = planProjectRemoval({
43
+ members: [local],
44
+ groupMemberCount: 2,
45
+ hasOtherMembers: false,
46
+ displayName: "Repo",
47
+ threads: [
48
+ { environmentId: local.environmentId, projectId: local.id },
49
+ { environmentId: remote.environmentId, projectId: remote.id },
50
+ ],
51
+ });
52
+ expect(plan.projectThreads).toHaveLength(1);
53
+ expect(plan.confirmationMessage).toBe(
54
+ 'Remove checkout "Repo" and delete its 1 thread?\nPath: /work/repo\nEnvironment: Local\nThis permanently clears conversation history for those threads and any archived threads.\nOther entries in this grouped project are unaffected.\nThis action cannot be undone.',
55
+ );
56
+ });
57
+
58
+ it("keeps an environment-filtered group scoped to its selected checkout", () => {
59
+ const plan = planProjectRemoval({
60
+ members: [remote],
61
+ groupMemberCount: 1,
62
+ hasOtherMembers: true,
63
+ displayName: "Repo",
64
+ threads: [],
65
+ });
66
+ expect(plan.targetKind).toBe("checkout");
67
+ expect(plan.confirmationMessage).toContain("Environment: Remote");
68
+ expect(plan.confirmationMessage).toContain(
69
+ "Other entries in this grouped project are unaffected.",
70
+ );
71
+ expect(plan.confirmationMessage).toContain(
72
+ "This permanently clears any archived conversation history.",
73
+ );
74
+ });
75
+
76
+ it("states the full group count and preserves files when removing a project everywhere", () => {
77
+ const plan = planProjectRemoval({
78
+ members: [local, remote],
79
+ groupMemberCount: 2,
80
+ hasOtherMembers: false,
81
+ displayName: "Repo",
82
+ threads: [],
83
+ });
84
+ expect(plan.targetKind).toBe("project");
85
+ expect(plan.confirmationMessage).toContain("This removes 2 grouped project entries.");
86
+ expect(plan.confirmationMessage).toContain(
87
+ "This removes only the project entries, not the files on disk.",
88
+ );
89
+ });
90
+});
apps/web/src/components/settings/ProjectSettingsPanel.tsx
+9
-37
@@ -10,6 +10,7 @@ import {
10
type AtomCommandResult,
11
} from "@t3tools/client-runtime/state/runtime";
12
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
13
+import { planProjectRemoval } from "@t3tools/client-runtime/state/projects";
14
import { AsyncResult } from "effect/reactivity";
15
import { type EnvironmentId, type ProjectIconOverride } from "@t3tools/contracts";
16
import { useLocation, useNavigate } from "@tanstack/react-router";
@@ -55,10 +56,6 @@ const ProjectIconPickerDialog = lazy(() =>
56
})),
57
);
58
58
-function memberKey(member: { environmentId: string; id: string }): string {
59
- return `${member.environmentId}:${member.id}`;
60
-}
61
-
59
export type ProjectSettingsCategory = "general" | "source-control" | "project";
60
61
export function ProjectSettingsPanel({
@@ -319,40 +316,15 @@ function ProjectDetail({
316
const api = readLocalApi();
317
if (!api) return;
318
322
- const memberKeys = new Set(members.map(memberKey));
323
- const projectThreads = threads.filter((thread) =>
324
- memberKeys.has(`${thread.environmentId}:${thread.projectId}`),
325
- );
326
- const isWholeGroup = members.length === group.memberProjects.length;
327
- const targetKind = hasOtherMembers || !isWholeGroup ? "checkout" : "project";
328
- const singleMember = members.length === 1 ? members[0]! : null;
329
- const targetLabel = singleMember?.title ?? group.displayName;
319
+ const { projectThreads, isWholeGroup, confirmationMessage } = planProjectRemoval({
320
+ members,
321
+ groupMemberCount: group.memberProjects.length,
322
+ hasOtherMembers,
323
+ displayName: group.displayName,
324
+ threads,
325
+ });
326
const confirmed = await settlePromise(() =>
331
- api.dialogs.confirm(
332
- [
333
- projectThreads.length > 0
334
- ? `Remove ${targetKind} "${targetLabel}" and delete its ${projectThreads.length} thread${projectThreads.length === 1 ? "" : "s"}?`
335
- : `Remove ${targetKind} "${targetLabel}"?`,
336
- ...(singleMember
337
- ? [
338
- `Path: ${singleMember.workspaceRoot}`,
339
- ...(singleMember.environmentLabel
340
- ? [`Environment: ${singleMember.environmentLabel}`]
341
- : []),
342
- ]
343
- : [`This removes ${members.length} grouped project entries.`]),
344
- ...(projectThreads.length > 0
345
- ? [
346
- "This permanently clears conversation history for those threads and any archived threads.",
347
- ]
348
- : ["This permanently clears any archived conversation history."]),
349
- isWholeGroup && !hasOtherMembers
350
- ? "This removes only the project entries, not the files on disk."
351
- : "Other entries in this grouped project are unaffected.",
352
- "This action cannot be undone.",
353
- ].join("\n"),
354
- { variant: "destructive" },
355
- ),
327
+ api.dialogs.confirm(confirmationMessage, { variant: "destructive" }),
328
);
329
if (confirmed._tag === "Failure" || !confirmed.value) return;
330
if (checkProjectAccess(members, "Failed to remove project")) return;
packages/client-runtime/src/state/projectRemoval.ts
new
+47
@@ -0,0 +1,47 @@
1
+import type { EnvironmentProject, EnvironmentThreadShell } from "./models.ts";
2
+
3
+export function planProjectRemoval<
4
+ Thread extends Pick<EnvironmentThreadShell, "environmentId" | "projectId">,
5
+>(options: {
6
+ readonly members: ReadonlyArray<
7
+ Pick<EnvironmentProject, "id" | "environmentId" | "title" | "workspaceRoot"> & {
8
+ readonly environmentLabel?: string | null;
9
+ }
10
+ >;
11
+ readonly groupMemberCount: number;
12
+ readonly hasOtherMembers: boolean;
13
+ readonly displayName: string;
14
+ readonly threads: ReadonlyArray<Thread>;
15
+}) {
16
+ const { members, groupMemberCount, hasOtherMembers, displayName, threads } = options;
17
+ const memberKeys = new Set(members.map((member) => `${member.environmentId}:${member.id}`));
18
+ const projectThreads = threads.filter((thread) =>
19
+ memberKeys.has(`${thread.environmentId}:${thread.projectId}`),
20
+ );
21
+ const isWholeGroup = members.length === groupMemberCount;
22
+ const targetKind = hasOtherMembers || !isWholeGroup ? "checkout" : "project";
23
+ const singleMember = members.length === 1 ? members[0]! : null;
24
+ const targetLabel = singleMember?.title ?? displayName;
25
+ const confirmationMessage = [
26
+ projectThreads.length > 0
27
+ ? `Remove ${targetKind} "${targetLabel}" and delete its ${projectThreads.length} thread${projectThreads.length === 1 ? "" : "s"}?`
28
+ : `Remove ${targetKind} "${targetLabel}"?`,
29
+ ...(singleMember
30
+ ? [
31
+ `Path: ${singleMember.workspaceRoot}`,
32
+ ...(singleMember.environmentLabel
33
+ ? [`Environment: ${singleMember.environmentLabel}`]
34
+ : []),
35
+ ]
36
+ : [`This removes ${members.length} grouped project entries.`]),
37
+ ...(projectThreads.length > 0
38
+ ? ["This permanently clears conversation history for those threads and any archived threads."]
39
+ : ["This permanently clears any archived conversation history."]),
40
+ isWholeGroup && !hasOtherMembers
41
+ ? "This removes only the project entries, not the files on disk."
42
+ : "Other entries in this grouped project are unaffected.",
43
+ "This action cannot be undone.",
44
+ ].join("\n");
45
+
46
+ return { projectThreads, isWholeGroup, targetKind, confirmationMessage };
47
+}
packages/client-runtime/src/state/projects.ts
+1
@@ -205,3 +205,4 @@ export function canNavigateUp(currentPath: string): boolean {
205
206
export * from "./projectCommands.ts";
207
export * from "./projectEntities.ts";
208
+export * from "./projectRemoval.ts";