The best way to control Claude Code, Codex and more from any computer or phone

main
ts 90 lines 3.68 KB
Raw
1 import { isListedThreadLineage } from "@t3tools/contracts";
2
3 import type { EnvironmentProject, EnvironmentThreadShell } from "./models.ts";
4 import { mFallback, msg } from "gt-i18n";
5 import type { MFunctionType } from "gt-i18n/types";
6
7 export function planProjectRemoval<
8 Thread extends Pick<EnvironmentThreadShell, "environmentId" | "projectId" | "lineage">,
9 >(
10 options: {
11 readonly members: ReadonlyArray<
12 Pick<EnvironmentProject, "id" | "environmentId" | "title" | "workspaceRoot"> & {
13 readonly environmentLabel?: string | null;
14 }
15 >;
16 readonly groupMemberCount: number;
17 readonly hasOtherMembers: boolean;
18 readonly displayName: string;
19 readonly threads: ReadonlyArray<Thread>;
20 /** The members' threads this client does not hold: older settled threads its shell left out. */
21 readonly unloadedThreadCount?: number;
22 },
23 resolve: MFunctionType = mFallback,
24 ) {
25 const { members, groupMemberCount, hasOtherMembers, displayName, threads } = options;
26 const memberKeys = new Set(members.map((member) => `${member.environmentId}:${member.id}`));
27 const projectThreads = threads.filter((thread) =>
28 memberKeys.has(`${thread.environmentId}:${thread.projectId}`),
29 );
30 // Side chats and subagents go with their parent but never show in thread lists.
31 const threadCount =
32 projectThreads.filter((thread) => isListedThreadLineage(thread.lineage)).length +
33 (options.unloadedThreadCount ?? 0);
34 const isWholeGroup = members.length === groupMemberCount;
35 const targetKind = hasOtherMembers || !isWholeGroup ? "checkout" : "project";
36 const singleMember = members.length === 1 ? members[0]! : null;
37 const targetLabel = singleMember?.title ?? displayName;
38 const confirmationMessage = [
39 threadCount > 0
40 ? targetKind === "checkout"
41 ? resolve(
42 msg(
43 '{count, plural, one {Remove checkout "{label}" and delete its {count} thread?} other {Remove checkout "{label}" and delete its {count} threads?}}',
44 { count: threadCount, label: targetLabel },
45 ),
46 )
47 : resolve(
48 msg(
49 '{count, plural, one {Remove project "{label}" and delete its {count} thread?} other {Remove project "{label}" and delete its {count} threads?}}',
50 { count: threadCount, label: targetLabel },
51 ),
52 )
53 : targetKind === "checkout"
54 ? resolve(msg('Remove checkout "{label}"?', { label: targetLabel }))
55 : resolve(msg('Remove project "{label}"?', { label: targetLabel })),
56 ...(singleMember
57 ? [
58 resolve(msg("Path: {path}", { path: singleMember.workspaceRoot })),
59 ...(singleMember.environmentLabel
60 ? [
61 resolve(
62 msg("Environment: {environment}", {
63 environment: singleMember.environmentLabel,
64 }),
65 ),
66 ]
67 : []),
68 ]
69 : [resolve(msg("This removes {count} grouped project entries.", { count: members.length }))]),
70 ...(threadCount > 0
71 ? [
72 resolve(
73 msg(
74 "Those threads and any archived threads are deleted from T3 Code. Provider sessions are kept.",
75 ),
76 ),
77 ]
78 : [
79 resolve(
80 msg("Any archived threads are deleted from T3 Code. Provider sessions are kept."),
81 ),
82 ]),
83 isWholeGroup && !hasOtherMembers
84 ? resolve(msg("This removes only the project entries, not the files on disk."))
85 : resolve(msg("Other entries in this grouped project are unaffected.")),
86 resolve(msg("This action cannot be undone.")),
87 ].join("\n");
88
89 return { projectThreads, isWholeGroup, targetKind, confirmationMessage };
90 }