Skip to content

Commit 654eb2b

Browse files
committed
feat(web): regenerate selected thread titles
1 parent b5e391e commit 654eb2b

3 files changed

Lines changed: 98 additions & 5 deletions

File tree

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
22
import {
33
archiveSelectedThreadEntries,
4+
buildBulkTitleRegenerationContextMenuItem,
45
buildMultiSelectThreadContextMenuItems,
56
createThreadJumpHintVisibilityController,
67
getSidebarThreadIdsToPrewarm,
@@ -82,6 +83,42 @@ describe("isThreadTitleRegenerationPending", () => {
8283
});
8384
});
8485

86+
describe("buildBulkTitleRegenerationContextMenuItem", () => {
87+
it("counts only threads that can start a new regeneration", () => {
88+
expect(
89+
buildBulkTitleRegenerationContextMenuItem({
90+
supportedCount: 4,
91+
actionableCount: 3,
92+
}),
93+
).toEqual({
94+
id: "regenerate-title",
95+
label: "Regenerate titles (3)",
96+
});
97+
});
98+
99+
it("shows a disabled progress item when every supported thread is pending", () => {
100+
expect(
101+
buildBulkTitleRegenerationContextMenuItem({
102+
supportedCount: 2,
103+
actionableCount: 0,
104+
}),
105+
).toEqual({
106+
id: "regenerate-title",
107+
label: "Regenerating… (2)",
108+
disabled: true,
109+
});
110+
});
111+
112+
it("omits the action when no selected environment supports it", () => {
113+
expect(
114+
buildBulkTitleRegenerationContextMenuItem({
115+
supportedCount: 0,
116+
actionableCount: 0,
117+
}),
118+
).toBeNull();
119+
});
120+
});
121+
85122
describe("shouldNavigateAfterProjectRemoval", () => {
86123
const projectThreads = [{ environmentId: "environment-local", id: "thread-1" }];
87124

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ export function isThreadTitleRegenerationPending(
4242
): boolean {
4343
return threadTitleRegenerationRemainingMs(thread, nowMs) > 0;
4444
}
45+
46+
export function buildBulkTitleRegenerationContextMenuItem(input: {
47+
supportedCount: number;
48+
actionableCount: number;
49+
}): ContextMenuItem<"regenerate-title"> | null {
50+
if (input.supportedCount === 0) return null;
51+
if (input.actionableCount === 0) {
52+
return {
53+
id: "regenerate-title",
54+
label: `Regenerating… (${input.supportedCount})`,
55+
disabled: true,
56+
};
57+
}
58+
return {
59+
id: "regenerate-title",
60+
label: `Regenerate titles (${input.actionableCount})`,
61+
};
62+
}
63+
4564
type SidebarProject = {
4665
id: string;
4766
title: string;

‎apps/web/src/components/SidebarV2.tsx‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ import { formatRelativeTimeLabel, parseTimestampDate } from "../timestampFormat"
105105
import type { SidebarThreadSummary } from "../types";
106106
import { cn } from "~/lib/utils";
107107
import {
108+
buildBulkTitleRegenerationContextMenuItem,
108109
formatWorkingDurationLabel,
109110
firstValidTimestampMs,
110111
hasUnseenCompletion,
@@ -1881,16 +1882,28 @@ export default function SidebarV2() {
18811882
const count = threadKeys.length;
18821883
// Snooze (N) is offered when every selected thread can actually take
18831884
// it — a mixed selection with blocked-on-you work would half-apply.
1884-
const selectionNow = new Date().toISOString();
1885-
const snoozableThreads = threadKeys.flatMap((threadKey) => {
1885+
const selectionNow = new Date();
1886+
const selectedThreads = threadKeys.flatMap((threadKey) => {
18861887
const thread = threadByKeyRef.current.get(threadKey);
18871888
return thread ? [thread] : [];
18881889
});
1889-
const canSnoozeSelection = snoozableThreads.every(
1890+
const canSnoozeSelection = selectedThreads.every(
18901891
(thread) =>
18911892
serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSnooze === true &&
1892-
canSnooze(thread, { now: selectionNow }),
1893+
canSnooze(thread, { now: selectionNow.toISOString() }),
18931894
);
1895+
const titleRegenerationThreads = selectedThreads.filter(
1896+
(thread) =>
1897+
serverConfigs.get(thread.environmentId)?.environment.capabilities
1898+
.threadTitleRegeneration === true,
1899+
);
1900+
const regeneratableTitleThreads = titleRegenerationThreads.filter(
1901+
(thread) => !isThreadTitleRegenerationPending(thread, selectionNow.getTime()),
1902+
);
1903+
const titleRegenerationMenuItem = buildBulkTitleRegenerationContextMenuItem({
1904+
supportedCount: titleRegenerationThreads.length,
1905+
actionableCount: regeneratableTitleThreads.length,
1906+
});
18941907
const snoozePresets = resolveSnoozePresets(new Date());
18951908
const clicked = await settlePromise(() =>
18961909
api.contextMenu.show(
@@ -1908,6 +1921,7 @@ export default function SidebarV2() {
19081921
},
19091922
]
19101923
: []),
1924+
...(titleRegenerationMenuItem ? [titleRegenerationMenuItem] : []),
19111925
{ id: "mark-unread", label: `Mark unread (${count})` },
19121926
{ id: "delete", label: `Delete (${count})`, destructive: true },
19131927
],
@@ -1923,7 +1937,7 @@ export default function SidebarV2() {
19231937
// Post-snooze navigation must skip threads snoozing in this same
19241938
// batch — they are all leaving the card block together.
19251939
const coSnoozingKeys = new Set(threadKeys);
1926-
for (const thread of snoozableThreads) {
1940+
for (const thread of selectedThreads) {
19271941
attemptSnooze(scopeThreadRef(thread.environmentId, thread.id), preset, {
19281942
coSnoozingKeys,
19291943
});
@@ -1932,6 +1946,28 @@ export default function SidebarV2() {
19321946
}
19331947
return;
19341948
}
1949+
if (clicked.value === "regenerate-title") {
1950+
for (const thread of regeneratableTitleThreads) {
1951+
const result = await updateThreadMetadata({
1952+
environmentId: thread.environmentId,
1953+
input: { threadId: thread.id, regenerateTitle: true },
1954+
});
1955+
if (result._tag === "Success") continue;
1956+
if (!isAtomCommandInterrupted(result)) {
1957+
const error = squashAtomCommandFailure(result);
1958+
toastManager.add(
1959+
stackedThreadToast({
1960+
type: "error",
1961+
title: "Failed to regenerate thread titles",
1962+
description: error instanceof Error ? error.message : "An error occurred.",
1963+
}),
1964+
);
1965+
}
1966+
return;
1967+
}
1968+
clearSelection();
1969+
return;
1970+
}
19351971
if (clicked.value === "settle") {
19361972
// Post-settle navigation must skip threads settling in this same
19371973
// batch — they are all leaving the card block together. Rows that
@@ -2003,6 +2039,7 @@ export default function SidebarV2() {
20032039
markThreadUnread,
20042040
removeFromSelection,
20052041
serverConfigs,
2042+
updateThreadMetadata,
20062043
],
20072044
);
20082045

0 commit comments

Comments
 (0)