Skip to content

Commit 6ea9cff

Browse files
authored
refactor(chat): group adjacent tool calls uniformly (#286)
1 parent 1b73ba8 commit 6ea9cff

5 files changed

Lines changed: 14 additions & 153 deletions

File tree

src/renderer/components/thread/ChatPane/chatPaneSelectors.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ describe("chatPaneSelectors", () => {
481481
expect(selectActiveSubAgentParentItemIds(state, "t1")).toEqual(["sub:run-1"]);
482482
});
483483

484-
it("groups edits only with edits to the same file", () => {
484+
it("groups adjacent edits with the rest of the tool-call run", () => {
485485
const state = {
486486
runtimeItemIdsByThread: {
487487
t1: [
@@ -572,20 +572,18 @@ describe("chatPaneSelectors", () => {
572572
{
573573
kind: "tool_call_group",
574574
id: "tool-call-group:edit-1",
575-
itemIds: ["edit-1", "edit-2"],
575+
itemIds: ["edit-1", "edit-2", "command-1", "command-2"],
576576
},
577+
{ kind: "item", id: "assistant-2" },
577578
{
578579
kind: "tool_call_group",
579-
id: "tool-call-group:command-1",
580-
itemIds: ["command-1", "command-2"],
580+
id: "tool-call-group:edit-3",
581+
itemIds: ["edit-3", "edit-4"],
581582
},
582-
{ kind: "item", id: "assistant-2" },
583-
{ kind: "item", id: "edit-3" },
584-
{ kind: "item", id: "edit-4" },
585583
]);
586584
});
587585

588-
it("applies the same edit grouping rule to generic edit tool calls", () => {
586+
it("groups generic edit tool calls with adjacent tools", () => {
589587
const state = {
590588
runtimeItemIdsByThread: {
591589
t1: ["tool-edit-1", "tool-edit-2", "tool-read-1", "tool-edit-3"],
@@ -643,10 +641,8 @@ describe("chatPaneSelectors", () => {
643641
{
644642
kind: "tool_call_group",
645643
id: "tool-call-group:tool-edit-1",
646-
itemIds: ["tool-edit-1", "tool-edit-2"],
644+
itemIds: ["tool-edit-1", "tool-edit-2", "tool-read-1", "tool-edit-3"],
647645
},
648-
{ kind: "item", id: "tool-read-1" },
649-
{ kind: "item", id: "tool-edit-3" },
650646
]);
651647
});
652648
});

src/renderer/components/thread/ChatPane/chatPaneSelectors.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type {
44
} from "@/renderer/state/slices/runtimeEventSlice";
55
import type { AppStoreState } from "@/renderer/state/slices/shared";
66
import type { ToolCallPayload } from "@/shared/contracts";
7-
import { canShareRuntimeToolGroup } from "@/renderer/state/runtimeToolGrouping";
87
import { imageViewRendersInline } from "./parts/items/imageViewSource";
98
import {
109
isToolGroupItem as isGroupableItemType,
@@ -159,9 +158,6 @@ function buildTimelineEntries(
159158
if (!next || !isToolGroupItem(next) || childParentIds.has(nextId)) {
160159
break;
161160
}
162-
if (!canShareRuntimeToolGroup(item, next)) {
163-
break;
164-
}
165161
groupIds.push(nextId);
166162
idx += 1;
167163
}

src/renderer/state/chatRuntimePersister.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe("prepareRuntimeSnapshotForPersistence", () => {
9797
]);
9898
});
9999

100-
it("does not compact edits together with other tool calls", () => {
100+
it("compacts edits together with the rest of the tool-call run", () => {
101101
const snapshot = prepareRuntimeSnapshotForPersistence(
102102
[
103103
makeItem({ id: "assistant-1", type: "assistant_message" }),
@@ -130,19 +130,13 @@ describe("prepareRuntimeSnapshotForPersistence", () => {
130130
[makeTurn("edit-1"), makeTurn("edit-2"), makeTurn("command-1"), makeTurn("edit-3")],
131131
);
132132

133-
const editSummaryId = "tool-call-summary:edit-1:edit-2:2";
134-
const commandSummaryId = "tool-call-summary:command-1:command-2:2";
135-
expect(snapshot.items.map((item) => item.id)).toEqual([
136-
"assistant-1",
137-
editSummaryId,
138-
commandSummaryId,
139-
"edit-3",
140-
]);
133+
const summaryId = "tool-call-summary:edit-1:edit-3:5";
134+
expect(snapshot.items.map((item) => item.id)).toEqual(["assistant-1", summaryId]);
141135
expect(snapshot.turns.map((turn) => turn.anchorItemId)).toEqual([
142-
editSummaryId,
143-
editSummaryId,
144-
commandSummaryId,
145-
"edit-3",
136+
summaryId,
137+
summaryId,
138+
summaryId,
139+
summaryId,
146140
]);
147141
});
148142

src/renderer/state/chatRuntimePersister.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { imageViewRendersInline } from "../components/thread/ChatPane/parts/item
44
import { isSubAgentTool } from "../components/thread/ChatPane/parts/items/toolDisplay";
55
import { readBridge } from "../bridge";
66
import { useAppStore } from "./appStore";
7-
import { canShareRuntimeToolGroup } from "./runtimeToolGrouping";
87
import {
98
subscribeRuntimePersistenceDirtyThreads,
109
type CompletedTurnRecord,
@@ -272,7 +271,6 @@ function compactRuntimeItemsForPersistence(
272271
while (idx < items.length) {
273272
const next = items[idx]!;
274273
if (!isToolGroupItem(next) || next.state !== "completed") break;
275-
if (!canShareRuntimeToolGroup(run[0]!, next)) break;
276274
run.push(next);
277275
idx += 1;
278276
}

src/renderer/state/runtimeToolGrouping.ts

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)