Open History to see the last commit
1import type { EnvironmentProject, EnvironmentThreadShell } from "./models.ts";
2
3export 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}