Skip to content

Commit 440fff9

Browse files
committed
Improve merged worktree cleanup feedback
- Use the active thread to choose the cleanup project - Rename prune action for stale records - Show an error toast when merged thread auto-delete fails
1 parent cbe449f commit 440fff9

3 files changed

Lines changed: 14 additions & 7 deletions

File tree

apps/server/src/wsServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
13851385
args: ["worktree", "prune", "--expire", "now"],
13861386
timeoutMs: 15_000,
13871387
})
1388-
.pipe(Effect.provideService(RuntimeEnv, gitEnv));
1388+
.pipe(Effect.provideService(RuntimeEnv, gitEnv), Effect.asVoid);
13891389
}
13901390

13911391
case WS_METHODS.gitCreateBranch: {

apps/web/src/components/WorktreeCleanupDialog.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GitMergeIcon, LoaderCircleIcon, Trash2Icon } from "lucide-react";
44
import { useMemo } from "react";
55

66
import { useStore } from "~/store";
7+
import { useHandleNewThread } from "~/hooks/useHandleNewThread";
78
import {
89
gitMergedWorktreeCleanupCandidatesQueryOptions,
910
gitPruneWorktreesMutationOptions,
@@ -37,16 +38,16 @@ function resolveWorktreeUsageCount(
3738
export function WorktreeCleanupDialog() {
3839
const open = useWorktreeCleanupStore((state) => state.open);
3940
const closeDialog = useWorktreeCleanupStore((state) => state.closeDialog);
41+
const { activeThread } = useHandleNewThread();
4042
const threads = useStore((state) => state.threads);
4143
const projects = useStore((state) => state.projects);
4244
const queryClient = useQueryClient();
4345
const activeProject = useMemo(() => {
44-
const firstThread = threads[0];
45-
if (firstThread) {
46-
return projects.find((project) => project.id === firstThread.projectId) ?? projects[0] ?? null;
46+
if (activeThread) {
47+
return projects.find((project) => project.id === activeThread.projectId) ?? projects[0] ?? null;
4748
}
4849
return projects[0] ?? null;
49-
}, [projects, threads]);
50+
}, [activeThread, projects]);
5051
const cwd = activeProject?.cwd ?? null;
5152
const threadWorktreePaths = useMemo(
5253
() => threads.map((thread) => thread.worktreePath),
@@ -133,7 +134,7 @@ export function WorktreeCleanupDialog() {
133134
const usageCount = resolveWorktreeUsageCount(candidate, threadWorktreePaths);
134135
const displayPath = formatWorktreePathForDisplay(candidate.path);
135136
const canDelete = usageCount === 0;
136-
const actionLabel = candidate.pathExists ? "Delete worktree" : "Prune record";
137+
const actionLabel = candidate.pathExists ? "Delete worktree" : "Prune stale records";
137138

138139
return (
139140
<Card

apps/web/src/hooks/useAutoDeleteMergedThreads.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export function useAutoDeleteMergedThreads(settings: AppSettings) {
8181
const threadTitle = thread.title || `Thread ${thread.id.slice(0, 8)}`;
8282
const minutesLabel = delayMinutes === 1 ? "1 minute" : `${delayMinutes} minutes`;
8383
const threadProject = projects.find((project) => project.id === thread.projectId) ?? null;
84-
const displayWorktreePath = formatWorktreePathForDisplay(orphanedWorktreePath);
8584

8685
const toastId = toastManager.add({
8786
type: "info",
@@ -121,6 +120,13 @@ export function useAutoDeleteMergedThreads(settings: AppSettings) {
121120
title: "Merged thread deleted",
122121
description: `"${threadTitle}" was auto-deleted after its PR was merged.`,
123122
});
123+
} catch (error) {
124+
toastManager.add({
125+
type: "error",
126+
title: "Auto-delete failed",
127+
description:
128+
error instanceof Error ? error.message : "Could not delete the merged thread.",
129+
});
124130
} finally {
125131
timersRef.current.delete(thread.id);
126132
void queryClient.invalidateQueries({ queryKey: gitQueryKeys.all });

0 commit comments

Comments
 (0)