Skip to content

Commit 908230a

Browse files
authored
fix(ui): keep tool-only turn details visible (#106791)
* fix(ui): keep tool-only turn details visible * refactor(ui): keep tool card component size neutral * style(ui): format tool turn e2e test * chore: leave release notes to release automation
1 parent 8592b87 commit 908230a

6 files changed

Lines changed: 150 additions & 32 deletions

File tree

‎ui/src/e2e/chat-tool-turn-outcome.e2e.test.ts‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ describeControlUiE2e("Control UI autonomous tool-turn outcomes", () => {
153153
});
154154

155155
await page.goto(`${server.baseUrl}chat`);
156-
await expandCompletedWorkGroups(page);
157156
const activity = page.locator(".chat-group--activity .chat-activity-group__summary");
158157
await activity.waitFor();
159158
expect(await activity.textContent()).toContain("Read a file, edited 2 files");
@@ -189,6 +188,57 @@ describeControlUiE2e("Control UI autonomous tool-turn outcomes", () => {
189188
await context.close();
190189
});
191190

191+
it("keeps a message-only turn visible with its first message line", async () => {
192+
const context = await browser.newContext({ viewport: { height: 800, width: 1200 } });
193+
const page = await context.newPage();
194+
const message = "Hello Molty, first claw-to-claw hello.";
195+
await installMockGateway(page, {
196+
historyMessages: [
197+
{ role: "user", content: "Send the Reef greeting.", timestamp: 1 },
198+
{
199+
role: "assistant",
200+
content: [
201+
{
202+
type: "toolCall",
203+
id: "call-message",
204+
name: "message",
205+
arguments: {
206+
action: "send",
207+
channel: "reef",
208+
target: "@molty",
209+
message: `${message}\nHidden second line.`,
210+
},
211+
},
212+
],
213+
timestamp: 2,
214+
},
215+
{
216+
role: "toolResult",
217+
toolCallId: "call-message",
218+
toolName: "message",
219+
content: [{ type: "text", text: '{"status":"sent"}' }],
220+
timestamp: 3,
221+
},
222+
],
223+
});
224+
225+
await page.goto(`${server.baseUrl}chat`);
226+
const row = page.locator(".chat-tool-msg-summary", { hasText: message });
227+
await row.waitFor();
228+
229+
expect(await page.locator(".chat-work-group").count()).toBe(0);
230+
expect(await row.locator(".chat-tool-msg-summary__label").textContent()).toBe("Message");
231+
expect(await row.locator(".chat-tool-msg-summary__names").textContent()).toBe(message);
232+
await captureToolActivityProof(page, "message-only-turn-visible");
233+
await row.click();
234+
await page.getByText("action:", { exact: true }).waitFor();
235+
expect(await page.getByText("send", { exact: true }).count()).toBe(1);
236+
expect(await page.getByText("Hidden second line.", { exact: false }).count()).toBeGreaterThan(
237+
0,
238+
);
239+
await context.close();
240+
});
241+
192242
it("sweeps a text wave over the active tool row and stops it on the result", async () => {
193243
const context = await browser.newContext({ viewport: { height: 800, width: 1200 } });
194244
const page = await context.newPage();

‎ui/src/lib/chat/tool-cards.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
isToolResultContentType,
1010
resolveToolUseId,
1111
} from "../../../../src/chat/tool-content.js";
12+
import { redactToolPayloadText } from "../browser-redact.ts";
1213
import type { ToolCard, ToolCardOutcome } from "./chat-types.ts";
1314
import { extractTextCached } from "./message-extract.ts";
1415
import { isToolResultMessage } from "./message-normalizer.ts";
@@ -261,6 +262,37 @@ export function formatCollapsedToolPreviewText(value: string | undefined): strin
261262
return truncateUtf16Safe(normalized, 120);
262263
}
263264

265+
const TOOL_ARGUMENT_PREVIEW_KEYS = [
266+
"message",
267+
"prompt",
268+
"task",
269+
"query",
270+
"text",
271+
"description",
272+
] as const;
273+
274+
/** First meaningful user-authored line for compact generic tool rows. */
275+
export function resolveCollapsedToolArgumentPreview(args: unknown): string | undefined {
276+
if (!args || typeof args !== "object" || Array.isArray(args)) {
277+
return undefined;
278+
}
279+
const record = args as Record<string, unknown>;
280+
for (const key of TOOL_ARGUMENT_PREVIEW_KEYS) {
281+
const value = record[key];
282+
if (typeof value !== "string") {
283+
continue;
284+
}
285+
const firstLine = value.split(/\r\n?|\n/).find((line) => line.trim().length > 0);
286+
const preview = formatCollapsedToolPreviewText(
287+
firstLine ? redactToolPayloadText(firstLine) : undefined,
288+
);
289+
if (preview) {
290+
return preview;
291+
}
292+
}
293+
return undefined;
294+
}
295+
264296
function findFirstUnmatchedCard(
265297
cards: ToolCard[],
266298
id: string,

‎ui/src/pages/chat/chat-thread.test.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,33 @@ describe("collapseCompletedTurnWork", () => {
122122
expect(items.some((item) => item.kind === "work-group")).toBe(false);
123123
});
124124

125-
it("collapses reply-less turns only once the run is idle", () => {
125+
it("keeps reply-less turns expanded after the run finishes", () => {
126126
const messages = [
127127
{ role: "user", content: "do it", timestamp: 1_000 },
128128
toolResult("call-1", 2_000),
129129
];
130130

131-
// Mid-run the executing turn can trail a queued send, so reply-less turns
132-
// stay expanded until the run reaches terminal.
131+
// A reply-less executing turn stays expanded while live and remains visible
132+
// after completion instead of becoming an opaque worked-for rollup.
133133
expect(collapsedItems({ messages }, true).some((item) => item.kind === "work-group")).toBe(
134134
false,
135135
);
136136

137137
const idle = collapsedItems({ messages });
138-
expect(idle.map((item) => item.kind)).toEqual(["group", "work-group"]);
139-
expect(requireWorkGroup(idle[1]).durationMs).toBe(1_000);
138+
expect(idle.map((item) => item.kind)).toEqual(["group", "group"]);
139+
expect(requireGroup(idle[1]).role).toBe("tool");
140140
});
141141

142-
it("flags failed work in turns that never replied", () => {
142+
it("keeps failed work visible in turns that never replied", () => {
143143
const items = collapsedItems({
144144
messages: [
145145
{ role: "user", content: "go", timestamp: 1_000 },
146146
toolResult("call-1", 2_000, true),
147147
],
148148
});
149149

150-
expect(requireWorkGroup(items[1]).hasError).toBe(true);
150+
expect(items.map((item) => item.kind)).toEqual(["group", "group"]);
151+
expect(requireGroup(items[1]).role).toBe("tool");
151152
});
152153

153154
it("does not flag errors once the turn recovered with a reply", () => {

‎ui/src/pages/chat/chat-thread.ts‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,16 +1786,6 @@ function isFinalReplyGroup(item: TurnRenderItem): boolean {
17861786
);
17871787
}
17881788

1789-
function groupLastTimestamp(group: MessageGroup): number {
1790-
for (let index = group.messages.length - 1; index >= 0; index -= 1) {
1791-
const timestamp = rawMessageTimestamp(group.messages[index]?.message);
1792-
if (timestamp != null) {
1793-
return timestamp;
1794-
}
1795-
}
1796-
return group.timestamp;
1797-
}
1798-
17991789
function workGroupHasError(groups: MessageGroup[]): boolean {
18001790
return groups.some(
18011791
(group) =>
@@ -1857,13 +1847,13 @@ export function collapseCompletedTurnWork(
18571847
break;
18581848
}
18591849
}
1860-
// A reply-less turn only collapses once the session is idle: mid-run it
1861-
// may still be the executing turn (e.g. behind a queued send).
1862-
if (finalReplyIndex === -1 && opts.runWorking) {
1850+
// Without a final reply, the tool rows are the turn's only visible result.
1851+
// Keep them exposed instead of replacing the result with an opaque rollup.
1852+
if (finalReplyIndex === -1) {
18631853
result.push(...turn);
18641854
continue;
18651855
}
1866-
const segmentEnd = finalReplyIndex === -1 ? turn.length - 1 : finalReplyIndex - 1;
1856+
const segmentEnd = finalReplyIndex - 1;
18671857
let segmentStart = segmentEnd + 1;
18681858
for (let index = segmentEnd; index >= 0; index -= 1) {
18691859
const candidate = turn[index];
@@ -1874,8 +1864,7 @@ export function collapseCompletedTurnWork(
18741864
}
18751865
const groups = turn.slice(segmentStart, segmentEnd + 1) as MessageGroup[];
18761866
const firstGroup = groups[0];
1877-
const lastGroup = groups[groups.length - 1];
1878-
if (!firstGroup || !lastGroup) {
1867+
if (!firstGroup) {
18791868
result.push(...turn);
18801869
continue;
18811870
}
@@ -1884,8 +1873,8 @@ export function collapseCompletedTurnWork(
18841873
boundary && boundary.kind === "group" && isTurnBoundaryGroup(boundary)
18851874
? boundary.timestamp
18861875
: firstGroup.timestamp;
1887-
const finalReply = finalReplyIndex >= 0 ? (turn[finalReplyIndex] as MessageGroup) : null;
1888-
const endTimestamp = finalReply ? finalReply.timestamp : groupLastTimestamp(lastGroup);
1876+
const finalReply = turn[finalReplyIndex] as MessageGroup;
1877+
const endTimestamp = finalReply.timestamp;
18891878
const durationMs = endTimestamp > startTimestamp ? endTimestamp - startTimestamp : null;
18901879
result.push(...turn.slice(0, segmentStart));
18911880
result.push({

‎ui/src/pages/chat/components/chat-tool-cards.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
formatDistinctCollapsedToolSummaryText,
88
formatCollapsedToolPreviewText,
99
formatCollapsedToolSummaryText,
10+
resolveCollapsedToolArgumentPreview,
1011
} from "../../../lib/chat/tool-cards.ts";
1112
import { renderToolCard, renderToolPreview } from "./chat-tool-cards.ts";
1213

@@ -488,6 +489,48 @@ describe("tool-cards", () => {
488489
expect(container.querySelector(".chat-tool-msg-body")).toBeNull();
489490
});
490491

492+
it("shows the first message line in collapsed message tool rows", () => {
493+
const container = document.createElement("div");
494+
render(
495+
renderToolCard(
496+
{
497+
id: "msg:5-message:call-5-message",
498+
name: "message",
499+
args: {
500+
action: "send",
501+
channel: "reef",
502+
target: "@molty",
503+
message: "Hello Molty, first claw-to-claw hello.\nSecond line stays in details.",
504+
},
505+
inputText: "message input",
506+
},
507+
{ expanded: false, onToggleExpanded: vi.fn() },
508+
),
509+
container,
510+
);
511+
512+
const summaryButton = container.querySelector("button.chat-tool-msg-summary");
513+
expect(summaryButton?.querySelector(".chat-tool-msg-summary__label")?.textContent).toBe(
514+
"Message",
515+
);
516+
expect(summaryButton?.querySelector(".chat-tool-msg-summary__names")?.textContent).toBe(
517+
"Hello Molty, first claw-to-claw hello.",
518+
);
519+
});
520+
521+
it("previews common intent arguments across generic tools", () => {
522+
expect(resolveCollapsedToolArgumentPreview({ task: "Review the PR" })).toBe("Review the PR");
523+
expect(resolveCollapsedToolArgumentPreview({ prompt: "Draw a crab" })).toBe("Draw a crab");
524+
expect(resolveCollapsedToolArgumentPreview({ text: "First line\nSecond line" })).toBe(
525+
"First line",
526+
);
527+
expect(resolveCollapsedToolArgumentPreview({ query: " \r\rSecond line" })).toBe("Second line");
528+
const credential = ["sk", "1234567890abcdef"].join("-");
529+
expect(
530+
resolveCollapsedToolArgumentPreview({ description: `OPENAI_API_KEY=${credential}` }),
531+
).not.toContain(credential);
532+
});
533+
491534
it("keeps tool display labels primary for collapsed result rows with action details", () => {
492535
const container = document.createElement("div");
493536
render(
@@ -571,6 +614,9 @@ describe("tool-cards", () => {
571614
it("keeps collapsed markdown previews bounded after display cleanup", () => {
572615
const preview = formatCollapsedToolPreviewText(`with ${"A".repeat(200)}`);
573616

617+
expect(formatCollapsedToolPreviewText("First line\nSecond line")).toBe(
618+
"First line Second line",
619+
);
574620
expect(preview).toHaveLength(120);
575621
expect(preview?.startsWith("A")).toBe(true);
576622
expect(preview).not.toContain("with ");

‎ui/src/pages/chat/components/chat-tool-cards.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import { t } from "../../../i18n/index.ts";
1010
import type { ToolCard, ToolCardOutcome } from "../../../lib/chat/chat-types.ts";
1111
import { resolveToolCallView, type ToolCallView } from "../../../lib/chat/tool-call-view.ts";
1212
import {
13-
formatDistinctCollapsedToolSummaryText,
13+
formatDistinctCollapsedToolSummaryText as distinctSummaryText,
1414
formatCollapsedToolPreviewText,
1515
formatCollapsedToolSummaryText,
1616
isToolCardError,
17+
resolveCollapsedToolArgumentPreview as toolArgumentPreview,
1718
resolveToolCardOutcome,
1819
type ToolPreview,
1920
} from "../../../lib/chat/tool-cards.ts";
@@ -467,7 +468,6 @@ function renderToolRowContent(card: ToolCard, view: ToolCallView, outcome: ToolC
467468
`;
468469
}
469470

470-
// Generic tools keep the resolver-driven label + detail.
471471
const display = resolveToolDisplay({ name: card.name, args: card.args, detailMode: "explain" });
472472
const summary = resolveCollapsedToolSummaryParts({
473473
card,
@@ -476,12 +476,13 @@ function renderToolRowContent(card: ToolCard, view: ToolCallView, outcome: ToolC
476476
isError: outcome === "failed",
477477
});
478478
const displayLabel = formatCollapsedToolSummaryText(summary.label) ?? summary.label;
479-
const displayName = formatDistinctCollapsedToolSummaryText(summary.name, displayLabel);
479+
const argumentPreview = outcome === "failed" ? undefined : toolArgumentPreview(card.args);
480+
const displayName = distinctSummaryText(argumentPreview ?? summary.name, displayLabel);
480481
const aiTitle = getToolCallTitle(card.name, card.args);
481482
if (aiTitle) {
482483
return html`
483484
<span class="chat-tool-row__title">${aiTitle}</span>
484-
<span class="chat-tool-row__detail">${displayLabel}</span>
485+
<span class="chat-tool-row__detail">${argumentPreview ?? displayLabel}</span>
485486
`;
486487
}
487488
return html`
@@ -731,7 +732,6 @@ export function isRunningToolCard(card: ToolCard, runActive: boolean | undefined
731732
return resolveToolCardOutcome(card, runActive) === "running";
732733
}
733734

734-
/** Plain-text row label, e.g. for the group header while a tool is running. */
735735
export function resolveToolRowText(card: ToolCard, runActive?: boolean): string {
736736
const view = resolveToolCallView({ name: card.name, args: card.args, details: card.details });
737737
if (view.kind === "command" && view.command) {
@@ -742,7 +742,7 @@ export function resolveToolRowText(card: ToolCard, runActive?: boolean): string
742742
return `${verb} ${view.target}`;
743743
}
744744
const display = resolveToolDisplay({ name: card.name, args: card.args, detailMode: "explain" });
745-
return display.label;
745+
return [display.label, toolArgumentPreview(card.args)].filter(Boolean).join(" ");
746746
}
747747

748748
export function renderToolCard(

0 commit comments

Comments
 (0)