Skip to content

Commit a364abe

Browse files
author
Marian Popeanga
committed
addressed review feedback for task rename
1 parent 29e1c39 commit a364abe

17 files changed

Lines changed: 214 additions & 36 deletions

‎src/core/webview/ClineProvider.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,14 +2455,26 @@ export class ClineProvider
24552455
* clears it so the history falls back to the original prompt.
24562456
*/
24572457
async renameTaskWithId(id: string, title: string | undefined) {
2458-
const historyItem = this.taskHistoryStore.get(id)
2459-
if (!historyItem) {
2458+
if (!this.taskHistoryStore.get(id)) {
24602459
this.log(`[renameTaskWithId] task ${id} not found in history`)
24612460
return
24622461
}
24632462

2463+
// Read and write under the store lock so a queued task save or delegation
2464+
// transition cannot be overwritten by a stale snapshot of the item.
24642465
const trimmed = title?.trim()
2465-
await this.updateTaskHistory({ ...historyItem, title: trimmed ? trimmed : undefined })
2466+
await this.taskHistoryStore.atomicReadAndUpdate(id, (historyItem) => ({
2467+
...historyItem,
2468+
title: trimmed ? trimmed : undefined,
2469+
}))
2470+
this.recentTasksCache = undefined
2471+
2472+
if (this.isViewLaunched) {
2473+
const updatedItem = this.taskHistoryStore.get(id)
2474+
if (updatedItem) {
2475+
await this.postMessageToWebview({ type: "taskHistoryItemUpdated", taskHistoryItem: updatedItem })
2476+
}
2477+
}
24662478
}
24672479

24682480
/* Condenses a task's message history to use fewer tokens. */

‎src/core/webview/__tests__/ClineProvider.taskHistory.spec.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,25 @@ describe("ClineProvider Task History Synchronization", () => {
640640
expect(getStored("task-keep")).toMatchObject({ title: "Renamed", tokensIn: 500 })
641641
})
642642

643+
it("keeps a concurrent task save that is queued before the rename", async () => {
644+
const item = createHistoryItem({ id: "task-race", task: "Original prompt", status: "active" })
645+
await provider.updateTaskHistory(item, { broadcast: false })
646+
647+
// Start the save without awaiting it, so the rename runs while the save is queued.
648+
const save = provider.updateTaskHistory({ ...item, tokensIn: 500 }, { broadcast: false })
649+
const rename = provider.renameTaskWithId("task-race", "Renamed")
650+
await Promise.all([save, rename])
651+
652+
expect(getStored("task-race")).toMatchObject({ title: "Renamed", tokensIn: 500 })
653+
})
654+
643655
it("does nothing for an unknown task", async () => {
656+
const logSpy = vi.spyOn(provider, "log")
657+
644658
await provider.renameTaskWithId("missing-task", "Renamed")
645659

646660
expect(getStored("missing-task")).toBeUndefined()
661+
expect(logSpy).toHaveBeenCalledWith("[renameTaskWithId] task missing-task not found in history")
647662
})
648663
})
649664

‎src/core/webview/__tests__/webviewMessageHandler.spec.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const mockClineProvider = {
132132
getCurrentTask: vi.fn(),
133133
getTaskWithId: vi.fn(),
134134
createTaskWithHistoryItem: vi.fn(),
135+
renameTaskWithId: vi.fn(),
135136
getSkillsManager: vi.fn(),
136137
cwd: "/mock/workspace",
137138
} as unknown as ClineProvider
@@ -3036,3 +3037,19 @@ describe("updateProfileModel", () => {
30363037
expect(updateProfileModel).not.toHaveBeenCalled()
30373038
})
30383039
})
3040+
3041+
describe("webviewMessageHandler - renameTaskWithId", () => {
3042+
beforeEach(() => {
3043+
vi.mocked(mockClineProvider.renameTaskWithId).mockClear()
3044+
})
3045+
3046+
it.each([
3047+
["forwards taskId and text", { taskId: "task-1", text: "New name" }, [["task-1", "New name"]]],
3048+
["forwards an empty title so the provider can clear it", { taskId: "task-1", text: "" }, [["task-1", ""]]],
3049+
["skips the call when taskId is missing", { text: "New name" }, []],
3050+
])("%s", async (_label, payload, expectedCalls) => {
3051+
await webviewMessageHandler(mockClineProvider, { type: "renameTaskWithId", ...payload })
3052+
3053+
expect(vi.mocked(mockClineProvider.renameTaskWithId).mock.calls).toEqual(expectedCalls)
3054+
})
3055+
})

‎webview-ui/playwright/gallery/stories.tsx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,43 @@ export const stories: Record<string, Story> = {
168168
</AppProviders>
169169
)
170170
},
171+
"history-rename": async () => {
172+
const [{ AppProviders }, { default: HistoryView }] = await Promise.all([
173+
import("../AppProviders"),
174+
import("@/components/history/HistoryView"),
175+
])
176+
// The visual test freezes the clock at this time so "time ago" labels stay stable.
177+
const now = new Date("2026-06-01T12:00:00Z").getTime()
178+
const workspace = "/workspace/demo"
179+
const baseItem = { tokensIn: 1200, tokensOut: 800, totalCost: 0.12, workspace }
180+
return (
181+
<AppProviders
182+
initialState={{
183+
cwd: workspace,
184+
taskHistory: [
185+
{
186+
...baseItem,
187+
id: "task-renamed",
188+
number: 2,
189+
ts: now - 2 * 60 * 60 * 1000,
190+
task: "Refactor the authentication middleware to use the new session store",
191+
title: "Auth refactor",
192+
},
193+
{
194+
...baseItem,
195+
id: "task-original",
196+
number: 1,
197+
ts: now - 26 * 60 * 60 * 1000,
198+
task: "Write unit tests for the billing service",
199+
},
200+
],
201+
}}>
202+
<div className="h-[640px] w-[480px] max-w-full bg-vscode-editor-background">
203+
<HistoryView onDone={() => undefined} />
204+
</div>
205+
</AppProviders>
206+
)
207+
},
171208
"ignored-disabled-tools-warning": async () => {
172209
const [{ AppProviders }, { ChatRowContent }] = await Promise.all([
173210
import("../AppProviders"),

‎webview-ui/src/components/chat/TaskHeader.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useCallback, useRef, useState, useMemo } from "react"
1+
import { memo, useRef, useState, useMemo } from "react"
22
import { useTranslation } from "react-i18next"
33
import {
44
ChevronUp,
@@ -68,8 +68,6 @@ const TaskHeader = ({
6868
const { id: modelId, info: model } = useSelectedModel(apiConfiguration)
6969
const [isTaskExpanded, setIsTaskExpanded] = useState(false)
7070
const [isRenaming, setIsRenaming] = useState(false)
71-
const startRename = useCallback(() => setIsRenaming(true), [])
72-
const stopRename = useCallback(() => setIsRenaming(false), [])
7371
const customTitle = currentTaskItem?.title
7472

7573
const textContainerRef = useRef<HTMLDivElement>(null)
@@ -186,7 +184,11 @@ const TaskHeader = ({
186184
<div className="grow min-w-0">
187185
{isTaskExpanded &&
188186
(isRenaming && currentTaskItem ? (
189-
<TaskTitleEditor item={currentTaskItem} onDone={stopRename} className="text-sm" />
187+
<TaskTitleEditor
188+
item={currentTaskItem}
189+
onDone={() => setIsRenaming(false)}
190+
className="text-sm"
191+
/>
190192
) : (
191193
<span className="font-bold">{customTitle || t("chat:task.title")}</span>
192194
))}
@@ -353,7 +355,7 @@ const TaskHeader = ({
353355
<TaskActions
354356
item={currentTaskItem}
355357
buttonsDisabled={buttonsDisabled}
356-
onRename={isRenaming ? undefined : startRename}
358+
onRename={isRenaming ? undefined : () => setIsRenaming(true)}
357359
/>
358360
</div>
359361

‎webview-ui/src/components/chat/__tests__/TaskActions.spec.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("TaskActions", () => {
8787
const onRename = vi.fn()
8888
render(<TaskActions item={mockItem} buttonsDisabled={false} onRename={onRename} />)
8989

90-
fireEvent.click(screen.getByTestId("rename-current-task-button"))
90+
fireEvent.click(screen.getByLabelText("history:renameTask"))
9191

9292
expect(onRename).toHaveBeenCalledTimes(1)
9393
})

‎webview-ui/src/components/chat/__tests__/TaskHeader.spec.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,30 @@ describe("TaskHeader", () => {
290290
expect(screen.queryByText("Test task")).not.toBeInTheDocument()
291291
})
292292

293+
it.each([
294+
["the custom title", "My title", "My title"],
295+
["the default label without a custom title", undefined, "chat:task.title"],
296+
])("shows %s as the expanded heading", (_label, title, expected) => {
297+
mockExtensionState.currentTaskItem = { id: "test-task-id", task: "Test task", title }
298+
renderTaskHeader()
299+
fireEvent.click(screen.getByText(title ?? "Test task"))
300+
301+
expect(screen.getByText(expected)).toHaveClass("font-bold")
302+
expect(screen.queryByTestId("task-title-input")).not.toBeInTheDocument()
303+
})
304+
305+
it("closes the header editor on Escape without saving", () => {
306+
renderTaskHeader()
307+
fireEvent.click(screen.getByText("Test task"))
308+
fireEvent.click(screen.getByTestId("rename-current-task-button"))
309+
310+
fireEvent.keyDown(screen.getByTestId("task-title-input"), { key: "Escape" })
311+
312+
expect(screen.queryByTestId("task-title-input")).not.toBeInTheDocument()
313+
expect(screen.getByText("chat:task.title")).toBeInTheDocument()
314+
expect(mockPostMessage).not.toHaveBeenCalled()
315+
})
316+
293317
it("renames from the expanded header without collapsing it", () => {
294318
renderTaskHeader()
295319
fireEvent.click(screen.getByText("Test task"))

‎webview-ui/src/components/history/RenameButton.tsx‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { useCallback } from "react"
2-
31
import { Button, StandardTooltip } from "@/components/ui"
42
import { useAppTranslation } from "@/i18n/TranslationContext"
53

@@ -9,23 +7,20 @@ type RenameButtonProps = {
97

108
export const RenameButton = ({ onRename }: RenameButtonProps) => {
119
const { t } = useAppTranslation()
12-
13-
const handleRenameClick = useCallback(
14-
(e: React.MouseEvent) => {
15-
e.stopPropagation()
16-
onRename()
17-
},
18-
[onRename],
19-
)
10+
const label = t("history:renameTask")
2011

2112
return (
22-
<StandardTooltip content={t("history:renameTask")}>
13+
<StandardTooltip content={label}>
2314
<Button
2415
data-testid="rename-task-button"
16+
aria-label={label}
2517
variant="ghost"
2618
size="icon"
2719
className="group-hover:opacity-100 opacity-50 transition-opacity"
28-
onClick={handleRenameClick}>
20+
onClick={(e) => {
21+
e.stopPropagation()
22+
onRename()
23+
}}>
2924
<span className="codicon codicon-edit scale-80" />
3025
</Button>
3126
</StandardTooltip>

‎webview-ui/src/components/history/TaskItem.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useCallback, useState } from "react"
1+
import { memo, useState } from "react"
22
import { ArrowRight, Folder } from "lucide-react"
33
import { getTaskDisplayTitle, type DisplayHistoryItem } from "./types"
44

@@ -34,8 +34,6 @@ const TaskItem = ({
3434
className,
3535
}: TaskItemProps) => {
3636
const [isRenaming, setIsRenaming] = useState(false)
37-
const startRename = useCallback(() => setIsRenaming(true), [])
38-
const stopRename = useCallback(() => setIsRenaming(false), [])
3937

4038
const handleClick = () => {
4139
if (isRenaming) {
@@ -81,7 +79,7 @@ const TaskItem = ({
8179
<div className="flex-1 min-w-0">
8280
<div className="flex items-start gap-1">
8381
{isRenaming ? (
84-
<TaskTitleEditor item={item} onDone={stopRename} />
82+
<TaskTitleEditor item={item} onDone={() => setIsRenaming(false)} />
8583
) : item.highlight ? (
8684
<div
8785
className={cn(
@@ -126,7 +124,7 @@ const TaskItem = ({
126124
isSelectionMode={isSelectionMode}
127125
isSubtask={item.isSubtask}
128126
onDelete={onDelete}
129-
onRename={isRenaming ? undefined : startRename}
127+
onRename={isRenaming ? undefined : () => setIsRenaming(true)}
130128
/>
131129
</div>
132130
</div>

‎webview-ui/src/components/history/TaskTitleEditor.tsx‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback, useState } from "react"
22
import type { HistoryItem } from "@roo-code/types"
33

4-
import { Input } from "@/components/ui"
4+
import { AutosizeTextarea } from "@/components/ui"
55
import { useAppTranslation } from "@/i18n/TranslationContext"
66
import { cn } from "@/lib/utils"
77
import { vscode } from "@/utils/vscode"
@@ -14,17 +14,22 @@ type TaskTitleEditorProps = {
1414
className?: string
1515
}
1616

17+
// Titles are a single line: line breaks and repeated whitespace collapse to one space.
18+
const normalizeTitle = (text: string) => text.replace(/\s+/g, " ").trim()
19+
1720
/**
18-
* Inline input for renaming a history item. Enter saves, Escape or blur cancels.
21+
* Inline editor for renaming a history item. Enter saves, Escape or blur cancels.
1922
* Saving a blank value, or the original prompt, clears the custom title.
23+
*
24+
* It wraps instead of scrolling sideways so a long title stays readable at narrow widths.
2025
*/
2126
export const TaskTitleEditor = ({ item, onDone, className }: TaskTitleEditorProps) => {
2227
const { t } = useAppTranslation()
23-
const [value, setValue] = useState(() => getTaskDisplayTitle(item))
28+
const [value, setValue] = useState(() => normalizeTitle(getTaskDisplayTitle(item)))
2429

2530
const save = useCallback(() => {
26-
const trimmed = value.trim()
27-
const nextTitle = trimmed && trimmed !== item.task.trim() ? trimmed : undefined
31+
const normalized = normalizeTitle(value)
32+
const nextTitle = normalized && normalized !== normalizeTitle(item.task) ? normalized : undefined
2833

2934
if (nextTitle !== item.title) {
3035
vscode.postMessage({ type: "renameTaskWithId", taskId: item.id, text: nextTitle ?? "" })
@@ -36,8 +41,12 @@ export const TaskTitleEditor = ({ item, onDone, className }: TaskTitleEditorProp
3641
// Let keydown keep bubbling: VS Code's webview host listens on `window` to run
3742
// clipboard and undo shortcuts, so stopping propagation breaks paste (Cmd/Ctrl+V).
3843
const handleKeyDown = useCallback(
39-
(e: React.KeyboardEvent<HTMLInputElement>) => {
44+
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
4045
if (e.key === "Enter") {
46+
// IME users press Enter to confirm a conversion candidate, not to save.
47+
if (e.nativeEvent.isComposing || e.keyCode === 229) {
48+
return
49+
}
4150
e.preventDefault()
4251
save()
4352
} else if (e.key === "Escape") {
@@ -49,18 +58,24 @@ export const TaskTitleEditor = ({ item, onDone, className }: TaskTitleEditorProp
4958
)
5059

5160
return (
52-
<Input
61+
<AutosizeTextarea
5362
data-testid="task-title-input"
5463
aria-label={t("history:renameTask")}
55-
placeholder={item.task}
64+
placeholder={normalizeTitle(item.task)}
5665
value={value}
66+
rows={1}
67+
minHeight={20}
68+
maxHeight={120}
5769
autoFocus
5870
onFocus={(e) => e.currentTarget.select()}
5971
onChange={(e) => setValue(e.target.value)}
6072
onKeyDown={handleKeyDown}
6173
onBlur={onDone}
6274
onClick={(e) => e.stopPropagation()}
63-
className={cn("flex-1 min-w-0 text-base rounded-md select-text", className)}
75+
className={cn(
76+
"flex-1 min-w-0 resize-none border rounded-md px-2 py-1 text-base select-text break-words",
77+
className,
78+
)}
6479
/>
6580
)
6681
}

0 commit comments

Comments
 (0)