Skip to content

Commit a2332bc

Browse files
fix(client-runtime): an approved step no longer reads "and used 1 tool" (#45074)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent bf20a2e commit a2332bc

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎packages/client-runtime/src/work-log/presentation.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
resolveViewedImageAsset,
99
resolveWorkEntryToolPresentation,
1010
summarizeToolGroup,
11+
toolGroupSummaryKind,
1112
toolItemForDisplay,
1213
type WorkLogPresentationEntry,
1314
workEntryIndicatesToolFailure,
@@ -357,3 +358,33 @@ describe("summarizeToolGroup read counts", () => {
357358
).toBe("Read 2 files");
358359
});
359360
});
361+
362+
describe("summarizeToolGroup approvals", () => {
363+
const command: WorkLogPresentationEntry = {
364+
id: "command",
365+
createdAt: "2026-11-27T00:00:00.000Z",
366+
label: "pwd",
367+
tone: "tool",
368+
itemType: "command_execution",
369+
command: "pwd",
370+
toolLifecycleStatus: "completed",
371+
};
372+
const approval: WorkLogPresentationEntry = {
373+
id: "approval",
374+
createdAt: "2026-11-27T00:00:00.000Z",
375+
label: "Approval requested",
376+
tone: "tool",
377+
itemType: "approval_request",
378+
requestKind: "command",
379+
toolLifecycleStatus: "completed",
380+
};
381+
382+
it("does not count the approval for a step as a tool of its own", () => {
383+
expect(summarizeToolGroup([command, approval]).summary).toBe("Ran 1 command");
384+
expect(toolGroupSummaryKind([command, approval])).toBe("command");
385+
});
386+
387+
it("still summarizes a group that only holds an approval", () => {
388+
expect(summarizeToolGroup([approval]).summary).toBe("Used 1 tool");
389+
});
390+
});

‎packages/client-runtime/src/work-log/presentation.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,14 @@ function summaryActionPriority(action: ToolGroupAction | T3McpToolSummaryAction)
768768
}
769769
}
770770

771+
// An approval answers another step in the group; counting it would add a phantom "used 1 tool".
772+
function summarizedSteps(
773+
entries: ReadonlyArray<WorkLogPresentationEntry>,
774+
): ReadonlyArray<WorkLogPresentationEntry> {
775+
const steps = entries.filter((entry) => entry.itemType !== "approval_request");
776+
return steps.length > 0 ? steps : entries;
777+
}
778+
771779
export function summarizeToolGroup(
772780
entries: ReadonlyArray<WorkLogPresentationEntry>,
773781
resolve: MFunctionType = mFallback,
@@ -785,7 +793,7 @@ export function summarizeToolGroup(
785793
hasFailure: false,
786794
};
787795
}
788-
entries = toolEntries;
796+
entries = summarizedSteps(toolEntries);
789797
const groups = new Map<
790798
ToolGroupAction | T3McpToolSummaryAction,
791799
{
@@ -875,7 +883,7 @@ export function toolGroupSummaryKind(
875883
): ToolGroupSummaryKind {
876884
const toolEntries = entries.filter((entry) => entry.itemType !== "reasoning");
877885
if (entries.length > 0 && toolEntries.length === 0) return "reasoning";
878-
entries = toolEntries;
886+
entries = summarizedSteps(toolEntries);
879887
if (
880888
entries.length > 0 &&
881889
entries.every((entry) => resolveWorkEntryToolPresentation(entry)?.icon === "pull-request")

0 commit comments

Comments
 (0)