Skip to content

Commit b6d7466

Browse files
committed
Clear the inline diff review automatically after a successful send
1 parent d557387 commit b6d7466

6 files changed

Lines changed: 60 additions & 13 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Short: Review clears itself after sending
2+
3+
Sending an inline diff review to the agent now clears the comments automatically, so "Reset review" and its confirmation are no longer part of every review cycle. A failed send keeps the comments intact for a retry, and the manual Reset button stays for dropping comments without sending.

src/mainview/components/TaskDiffViewer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,10 @@ function TaskDiffViewer({ task, project, request, onBack, navigationGuardRef }:
23302330
api.request.sendAgentMessageNow({ taskId: task.id, projectId: project.id, text: snapshot })
23312331
.then(() => {
23322332
setReviewSendState("sent");
2333+
// Delivered comments are dead weight: clear them here so the reviewer
2334+
// never has to run the destructive "Reset review" as a routine step.
2335+
setInlineComments({});
2336+
setEditingCommentId(null);
23332337
toast.success(t("infoPanel.diffReviewExportSendSuccess"));
23342338
})
23352339
.catch((err) => {

src/mainview/components/__tests__/TaskDiffViewer.test.tsx

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,16 +1807,6 @@ describe("TaskDiffViewer", () => {
18071807
expect(screen.getByRole("button", { name: "Copy to Clipboard" })).toHaveClass("w-full");
18081808
expect(screen.getByRole("button", { name: "Send to Agent" })).toBeEnabled();
18091809

1810-
await user.click(screen.getByRole("button", { name: "Send to Agent" }));
1811-
await waitFor(() => {
1812-
expect(api.request.sendAgentMessageNow).toHaveBeenCalledWith({
1813-
taskId: "t1",
1814-
projectId: "p1",
1815-
text: expect.stringContaining(`<comment>${longComment}</comment>`),
1816-
});
1817-
});
1818-
expect(screen.getByRole("button", { name: "Sent" })).toBeInTheDocument();
1819-
18201810
await user.click(screen.getByRole("button", { name: "Comment 1" }));
18211811
await waitFor(() => {
18221812
expect(scrollIntoViewMock).toHaveBeenCalled();
@@ -2477,6 +2467,56 @@ describe("TaskDiffViewer", () => {
24772467
expect(localStorage.getItem(reviewKey)).toBeNull();
24782468
});
24792469

2470+
it("clears the review after a successful send, and keeps it when the send fails", async () => {
2471+
const user = userEvent.setup();
2472+
const reviewKey = "dev3-inline-diff-review-v1:t1";
2473+
const showConfirm = vi.mocked(confirm);
2474+
vi.mocked(api.request.sendAgentMessageNow).mockRejectedValueOnce(new Error("no agent"));
2475+
2476+
render(
2477+
<I18nProvider>
2478+
<TaskDiffViewer
2479+
task={task}
2480+
project={project}
2481+
request={{ mode: "branch", compareRef: "origin/main", compareLabel: "origin/main" }}
2482+
onBack={vi.fn()}
2483+
/>
2484+
</I18nProvider>,
2485+
);
2486+
2487+
const diffs = await screen.findAllByTestId("mock-diff");
2488+
await user.click(within(diffs[0]).getByRole("button", { name: "Open inline comment composer" }));
2489+
await user.type(screen.getByPlaceholderText("Leave a comment on this line..."), "send me");
2490+
await user.click(screen.getByRole("button", { name: "Add comment" }));
2491+
2492+
await waitFor(() => {
2493+
expect(localStorage.getItem(reviewKey)).toContain("send me");
2494+
});
2495+
2496+
// Failed send: the comments must survive so the reviewer can retry.
2497+
await user.click(screen.getByTestId("review-send-button"));
2498+
await waitFor(() => {
2499+
expect(api.request.sendAgentMessageNow).toHaveBeenCalledWith({
2500+
taskId: "t1",
2501+
projectId: "p1",
2502+
text: expect.stringContaining("<comment>send me</comment>"),
2503+
});
2504+
});
2505+
expect(screen.getAllByText("send me").length).toBeGreaterThan(0);
2506+
expect(localStorage.getItem(reviewKey)).toContain("send me");
2507+
2508+
// Successful send: comments are delivered, so they clear without a confirm.
2509+
vi.mocked(api.request.sendAgentMessageNow).mockResolvedValueOnce(undefined as never);
2510+
await user.click(screen.getByTestId("review-send-button"));
2511+
2512+
await waitFor(() => {
2513+
expect(screen.queryAllByText("send me")).toHaveLength(0);
2514+
});
2515+
expect(showConfirm).not.toHaveBeenCalled();
2516+
expect(screen.queryByTestId("review-reset-button")).not.toBeInTheDocument();
2517+
expect(localStorage.getItem(reviewKey)).toBeNull();
2518+
});
2519+
24802520
it("still saves new comments when the existing localStorage entry is corrupt JSON", async () => {
24812521
const user = userEvent.setup();
24822522
const reviewKey = "dev3-inline-diff-review-v1:t1";

src/mainview/i18n/translations/en/infoPanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const infoPanel = {
176176
"infoPanel.diffReviewExportSend": "Send to Agent",
177177
"infoPanel.diffReviewExportSendSending": "Sending\u2026",
178178
"infoPanel.diffReviewExportSendSent": "Sent",
179-
"infoPanel.diffReviewExportSendSuccess": "Review sent to the agent",
179+
"infoPanel.diffReviewExportSendSuccess": "Review sent to the agent — comments cleared",
180180
"infoPanel.diffReviewExportSendFailed": "Could not send the review to the agent: {error}",
181181
"infoPanel.diffReviewExportCopyTooltipTitle": "Copy review as a prompt",
182182
"infoPanel.diffReviewExportCopyTooltip": "Copy the review as an XML prompt to your clipboard — paste it into any agent yourself.",

src/mainview/i18n/translations/es/infoPanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const infoPanel = {
176176
"infoPanel.diffReviewExportSend": "Enviar al agente",
177177
"infoPanel.diffReviewExportSendSending": "Enviando\u2026",
178178
"infoPanel.diffReviewExportSendSent": "Enviado",
179-
"infoPanel.diffReviewExportSendSuccess": "Review enviado al agente",
179+
"infoPanel.diffReviewExportSendSuccess": "Review enviado al agente — comentarios borrados",
180180
"infoPanel.diffReviewExportSendFailed": "No se pudo enviar el review al agente: {error}",
181181
"infoPanel.diffReviewExportCopyTooltipTitle": "Copiar el review como prompt",
182182
"infoPanel.diffReviewExportCopyTooltip": "Copia el review como prompt XML al portapapeles — pégalo tú mismo en cualquier agente.",

src/mainview/i18n/translations/ru/infoPanel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const infoPanel = {
186186
"infoPanel.diffReviewExportSend": "Отправить агенту",
187187
"infoPanel.diffReviewExportSendSending": "Отправка\u2026",
188188
"infoPanel.diffReviewExportSendSent": "Отправлено",
189-
"infoPanel.diffReviewExportSendSuccess": "Ревью отправлено агенту",
189+
"infoPanel.diffReviewExportSendSuccess": "Ревью отправлено агенту — комментарии очищены",
190190
"infoPanel.diffReviewExportSendFailed": "Не удалось отправить ревью агенту: {error}",
191191
"infoPanel.diffReviewExportCopyTooltipTitle": "Скопировать ревью как промпт",
192192
"infoPanel.diffReviewExportCopyTooltip": "Скопировать ревью как XML-промпт в буфер обмена — вставите в любого агента сами.",

0 commit comments

Comments
 (0)