Skip to content

Commit 540ea12

Browse files
improve(ui): redesign tool calls as lightweight transcript activity (#125240)
* improve(ui): flatten transcript tool activity * improve(ui): complete tool activity redesign * improve(ui): normalize activity row typography * improve(ui): unify activity typography contract * improve(ui): standardize all activity row text * improve(ui): increase activity text size * improve(ui): underline activity filenames * improve(ui): tighten activity row spacing * improve(ui): standardize activity chevrons * improve(ui): reveal child chevrons on interaction * improve(ui): retain active child chevrons * improve(ui): space expanded child tools * improve(ui): remove idle activity fade and gap * fix(ui): preserve tool activity contracts * fix(ui): simplify activity basename lookup * fix(ui): preserve canonical tool row actions * fix(ui): record tool outcomes and repair transcript row regressions Neutral collapsed rows are the design, but this branch left failures with nowhere to land and shipped chrome whose styles it had already deleted. - Expanded standalone tool messages close with the outcome line, so an inline rows shape still reports the failure instead of dropping it. - Progress-card receipts drop the badge and the spinner: this branch removed both styles, leaving a 0x0 invisible running indicator, and the receipt label already names the state. - Single delete patches are non-navigable; their workspace target is gone, so the file action could only ever fail to load. - Flush command padding derives from the action-button size instead of a stale 42px constant, and the running text wave covers command rows again. - Activity lane returns to the tool-shell column width the rule claims. - Drop CSS nothing references: tool-card tabs, empty, plain-output, activity scroll masks, secondary command text. - renderToolDataBlock takes an optional label instead of comparing copy. - Split the oversized tool-card test file and refresh stale row assertions. * fix(ui): fold the tool action size into the card header rule Stylelint no-duplicate-selectors rejects the separate .chat-tool-card__header block; the custom property belongs in the existing rule. --------- Co-authored-by: RoboClaw <[email protected]>
1 parent 34c3d15 commit 540ea12

16 files changed

Lines changed: 944 additions & 577 deletions

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,18 @@ suite.define(() => {
9292
"Tool output",
9393
"Tool output",
9494
]);
95-
// Each failure keeps only its per-call badge even when its turn later
96-
// recovers; both row summaries otherwise render neutral.
95+
// Collapsed rows stay neutral even when the call failed; the failure is
96+
// recorded as the expanded body's outcome, with the reported exit code.
9797
const summaryClasses = await page
9898
.locator(".chat-tool-msg-summary")
9999
.evaluateAll((nodes) => nodes.map((node) => node.className));
100100
expect(summaryClasses).toHaveLength(2);
101101
expect(summaryClasses[0]).not.toContain("chat-tool-msg-summary--error");
102102
expect(summaryClasses[1]).not.toContain("chat-tool-msg-summary--error");
103-
expect(await page.locator(".chat-tool-row__badge").allTextContents()).toEqual([
104-
"failed",
105-
"failed",
106-
]);
103+
await page.locator(".chat-tool-msg-summary").first().click();
104+
await expect
105+
.poll(() => page.locator(".chat-tool-card__outcome").first().textContent())
106+
.toBe("Exit code 1");
107107
await context.close();
108108
});
109109

@@ -175,7 +175,7 @@ suite.define(() => {
175175
const activityGeometry = await activity.evaluate((node) => {
176176
const container = node.closest<HTMLElement>(".chat-activity-group");
177177
const label = node.querySelector<HTMLElement>(".chat-activity-group__label");
178-
const chevron = node.querySelector<HTMLElement>(".chat-inline-disclosure__chevron");
178+
const chevron = node.querySelector<HTMLElement>(".chat-tool-row__chevron");
179179
if (!container || !label || !chevron) {
180180
throw new Error("Expected compact activity disclosure parts");
181181
}
@@ -201,11 +201,13 @@ suite.define(() => {
201201

202202
const rows = page.locator(".chat-activity-group__body .chat-tool-msg-summary");
203203
expect(await rows.count()).toBe(2);
204-
expect(await rows.locator(".chat-inline-disclosure__chevron").count()).toBe(2);
204+
expect(await rows.locator(".chat-tool-row__chevron").count()).toBe(2);
205205
expect(await page.locator(".chat-tool-msg-summary__label", { hasText: "Tool" }).count()).toBe(
206206
0,
207207
);
208-
await rows.first().click();
208+
// File rows put the workspace link inside the row, so toggle from the icon
209+
// edge instead of the row centre to avoid opening the linked file.
210+
await rows.first().click({ position: { x: 4, y: 4 } });
209211
expect(await page.getByText("offset:", { exact: true }).count()).toBe(1);
210212
expect(await page.getByText("limit:", { exact: true }).count()).toBe(1);
211213
const patchRow = rows.filter({ hasText: "2 files" });
@@ -385,7 +387,8 @@ suite.define(() => {
385387
await card.waitFor();
386388
expect(await card.getByText("query:", { exact: true }).count()).toBe(1);
387389
expect(await card.getByText("example", { exact: true }).count()).toBe(1);
388-
await card.getByText("Tool output", { exact: true }).waitFor();
390+
// Plain output needs no "Tool output" header; the payload is the content.
391+
expect(await card.getByText("Tool output", { exact: true }).count()).toBe(0);
389392
await card.getByText("Native result payload", { exact: true }).waitFor();
390393
await captureToolActivityProof(page, "native-result-before-call-expanded");
391394
await context.close();

‎ui/src/i18n/locales/en.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5767,6 +5767,8 @@ export const en: TranslationMap = {
57675767
attemptedChanges: "Attempted changes",
57685768
failed: "failed",
57695769
running: "Running",
5770+
completed: "Completed",
5771+
exitCode: "Exit code {code}",
57705772
noOutputFailed: "No output — tool failed.",
57715773
noOutputSucceeded: "No output — tool completed successfully.",
57725774
noResult: "No result available.",

‎ui/src/lib/chat/chat-types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ export type ToolCard = {
243243
details?: unknown;
244244
/** Monotonic edit counts while a live tool call is still receiving input. */
245245
liveDiffStat?: { added: number; removed: number };
246+
/** Producer-reported process exit code, when the result supplies one. */
247+
exitCode?: number;
246248
isError?: boolean;
247249
/** True when the card comes from the live tool stream of the current run. */
248250
live?: boolean;

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ function coerceArgs(value: unknown): unknown {
5959
}
6060
}
6161

62+
function parseJsonRecord(value: string): Record<string, unknown> | null {
63+
const trimmed = value.trim();
64+
if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
65+
return null;
66+
}
67+
try {
68+
return readRecord(JSON.parse(trimmed));
69+
} catch {
70+
return null;
71+
}
72+
}
73+
6274
function extractToolText(item: Record<string, unknown>): string | undefined {
6375
if (typeof item.text === "string") {
6476
return item.text;
@@ -86,6 +98,17 @@ function readToolErrorFlag(value: Record<string, unknown>): boolean | undefined
8698
return typeof raw === "boolean" ? raw : undefined;
8799
}
88100

101+
function readToolExitCode(...values: unknown[]): number | undefined {
102+
for (const value of values) {
103+
const record = readRecord(value);
104+
const exitCode = record?.exitCode ?? record?.exit_code;
105+
if (typeof exitCode === "number" && Number.isInteger(exitCode)) {
106+
return exitCode;
107+
}
108+
}
109+
return undefined;
110+
}
111+
89112
const TOOL_NOT_FOUND_PATTERN = /^tool not found\.?$/i;
90113
const MAX_ERROR_DETECT_CHARS = 20_000;
91114
const TOOL_ERROR_STATUSES = new Set(["error", "failed", "timeout"]);
@@ -356,6 +379,7 @@ function extractToolCards(message: unknown, prefix = "tool"): ToolCard[] {
356379
const details = item.details ?? m.details;
357380
const preview = extractCanvasFromDetails(details) ?? extractToolPreview(text, name);
358381
const isError = readToolErrorFlag(item) ?? messageIsError;
382+
const exitCode = readToolExitCode(item, details, text ? parseJsonRecord(text) : undefined, m);
359383
if (existing) {
360384
fallbackMatchedCards.add(existing);
361385
existing.callId ??= callId;
@@ -374,6 +398,9 @@ function extractToolCards(message: unknown, prefix = "tool"): ToolCard[] {
374398
if (isError !== undefined) {
375399
existing.isError = isError;
376400
}
401+
if (exitCode !== undefined) {
402+
existing.exitCode = exitCode;
403+
}
377404
continue;
378405
}
379406
cards.push({
@@ -385,6 +412,7 @@ function extractToolCards(message: unknown, prefix = "tool"): ToolCard[] {
385412
...(details !== undefined ? { details } : {}),
386413
messageId: transcriptMessageId,
387414
...(isError !== undefined ? { isError } : {}),
415+
...(exitCode !== undefined ? { exitCode } : {}),
388416
preview,
389417
});
390418
}
@@ -405,6 +433,7 @@ function extractToolCards(message: unknown, prefix = "tool"): ToolCard[] {
405433
"tool";
406434
const text = extractTextCached(message) ?? undefined;
407435
const callId = resolveToolCallId({}, m);
436+
const exitCode = readToolExitCode(m, m.details, text ? parseJsonRecord(text) : undefined);
408437
cards.push({
409438
id: resolveToolCardId({}, m, 0, prefix),
410439
...(callId ? { callId } : {}),
@@ -414,6 +443,7 @@ function extractToolCards(message: unknown, prefix = "tool"): ToolCard[] {
414443
...(m.details !== undefined ? { details: m.details } : {}),
415444
messageId: transcriptMessageId,
416445
...(messageIsError !== undefined ? { isError: messageIsError } : {}),
446+
...(exitCode !== undefined ? { exitCode } : {}),
417447
preview: extractCanvasFromDetails(m.details) ?? extractToolPreview(text, name),
418448
});
419449
}

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,35 +203,39 @@ function activityAlignmentHtml() {
203203
<div class="chat-thread" role="log">
204204
<div class="chat-thread-inner">
205205
<div class="chat-group tool chat-group--activity">
206-
<div class="chat-avatar tool">A</div>
207206
<div class="chat-group-messages">
208207
<div class="chat-activity-group is-open">
209208
<button class="chat-inline-disclosure chat-activity-group__summary" type="button" aria-expanded="true">
210209
<span class="chat-activity-group__icon">${iconSvg()}</span>
211-
<span class="chat-activity-group__label">Activity: 2 tools</span>
212-
<span class="chat-inline-disclosure__chevron">${iconSvg()}</span>
210+
<span class="chat-tool-disclosure__content">
211+
<span class="chat-activity-group__label">Activity: 2 tools</span>
212+
</span>
213+
<span class="chat-tool-row__chevron">${iconSvg()}</span>
213214
</button>
214215
<div class="chat-activity-group__body">
215216
<div class="chat-bubble chat-bubble--tool-shell" data-activity-call-row>
216217
<div class="chat-tools-inline">
217218
<div class="chat-tool-msg-collapse">
218-
<button class="chat-inline-disclosure chat-tool-msg-summary" type="button" aria-expanded="false">
219+
<button class="chat-inline-disclosure chat-tool-msg-summary chat-tool-row" type="button" aria-expanded="false">
219220
<span class="chat-tool-msg-summary__icon">${iconSvg()}</span>
220-
<span class="chat-tool-msg-summary__label">Bash</span>
221-
<span class="chat-tool-msg-summary__names">search a deliberately long workspace path without extra card chrome</span>
222-
<span class="chat-inline-disclosure__chevron">${iconSvg()}</span>
221+
<span class="chat-tool-disclosure__content">
222+
<span class="chat-tool-msg-summary__label">Bash</span>
223+
<span class="chat-tool-msg-summary__names">search a deliberately long workspace path without extra card chrome</span>
224+
</span>
225+
<span class="chat-tool-row__chevron">${iconSvg()}</span>
223226
</button>
224227
</div>
225228
</div>
226229
</div>
227230
<div class="chat-bubble chat-bubble--tool-shell">
228231
<div class="chat-tool-msg-collapse">
229-
<button class="chat-inline-disclosure chat-tool-msg-summary" data-failed-call-row type="button" aria-expanded="false">
232+
<button class="chat-inline-disclosure chat-tool-msg-summary chat-tool-row" data-failed-call-row type="button" aria-expanded="false">
230233
<span class="chat-tool-msg-summary__icon">${iconSvg()}</span>
231-
<span class="chat-tool-msg-summary__label">Bash</span>
232-
<span class="chat-tool-msg-summary__names">Bash</span>
233-
<span class="chat-inline-disclosure__chevron">${iconSvg()}</span>
234-
<span class="chat-tool-row__badge">failed</span>
234+
<span class="chat-tool-disclosure__content">
235+
<span class="chat-tool-msg-summary__label">Bash</span>
236+
<span class="chat-tool-msg-summary__names">Bash</span>
237+
</span>
238+
<span class="chat-tool-row__chevron">${iconSvg()}</span>
235239
</button>
236240
</div>
237241
</div>
@@ -1198,7 +1202,7 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
11981202
const styles = await page.evaluate(() => {
11991203
const activity = document.querySelector<HTMLElement>(".chat-activity-group__summary")!;
12001204
const label = activity.querySelector<HTMLElement>(".chat-activity-group__label")!;
1201-
const chevron = activity.querySelector<HTMLElement>(".chat-inline-disclosure__chevron")!;
1205+
const chevron = activity.querySelector<HTMLElement>(".chat-tool-row__chevron")!;
12021206
return {
12031207
activity: getComputedStyle(activity).userSelect,
12041208
activityBackground: getComputedStyle(activity).backgroundColor,
@@ -1210,7 +1214,8 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
12101214
expect(styles).toEqual({
12111215
activity: "text",
12121216
activityBackground: "rgba(0, 0, 0, 0)",
1213-
chevronGap: 8,
1217+
// Summary gap (8px) less the chevron's own -3px inset.
1218+
chevronGap: 5,
12141219
tool: "text",
12151220
});
12161221
} finally {
@@ -1284,15 +1289,13 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
12841289
<div class="chat-thread chat-thread--direct" role="log">
12851290
<div class="chat-thread-inner">
12861291
<div class="chat-group tool">
1287-
<div class="chat-avatar tool">A</div>
12881292
<div class="chat-group-messages" data-tool-lane>
12891293
<div class="chat-bubble chat-bubble--tool-shell" data-tool-shell>
12901294
<div class="chat-tool-msg-collapse">Tool output</div>
12911295
</div>
12921296
</div>
12931297
</div>
12941298
<div class="chat-group tool chat-group--activity">
1295-
<div class="chat-avatar tool">A</div>
12961299
<div class="chat-group-messages" data-activity-lane>
12971300
<div class="chat-activity-group">Activity</div>
12981301
</div>

‎ui/src/pages/chat/components/chat-diff-render.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ import type { DiffLine, DiffStat } from "../../../lib/chat/tool-call-diff.ts";
99
export function renderDiffStatChips(stat: DiffStat & { modified?: number }) {
1010
// Tool cards omit `modified`; keep their original template byte-for-byte.
1111
if (stat.modified === undefined) {
12-
if (stat.added === 0 && stat.removed === 0) {
13-
return nothing;
14-
}
1512
return html`<span class="chat-diffstat">
16-
${stat.added > 0 ? html`<span class="chat-diffstat__add">+${stat.added}</span>` : nothing}
17-
${stat.removed > 0 ? html`<span class="chat-diffstat__del">-${stat.removed}</span>` : nothing}
13+
<span class="chat-diffstat__add">+${stat.added}</span>
14+
<span class="chat-diffstat__del">-${stat.removed}</span>
1815
</span>`;
1916
}
2017
if (stat.added === 0 && stat.removed === 0 && !stat.modified) {

‎ui/src/pages/chat/components/chat-message-bubble.ts‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ import {
6363
renderExpandedToolCardContent,
6464
renderRawOutputToggle,
6565
renderToolCard,
66+
renderToolOutcome,
6667
renderToolPreview,
68+
isRunningToolCard,
6769
resolveCollapsedToolDetail,
6870
shouldToggleSelectableDisclosure,
71+
syncToolDisclosureOverflow,
6972
} from "./chat-tool-cards.ts";
7073

7174
function renderChatIcon(name: string) {
@@ -326,10 +329,15 @@ export function renderGroupedMessage(
326329
}
327330

328331
const toolMessageDisclosureId = `toolmsg:${messageKey}`;
329-
const toolMessageExpanded = opts.isToolMessageExpanded?.(toolMessageDisclosureId) ?? false;
332+
const toolMessageExpanded =
333+
toolCards.some((card) => isRunningToolCard(card, opts.runActive)) ||
334+
(opts.isToolMessageExpanded?.(toolMessageDisclosureId) ?? false);
330335
const toolNames = [...new Set(toolCards.map((c) => c.name))];
331336
const singleToolCard = toolCards.length === 1 ? toolCards[0] : null;
332-
const toolMessageHasError = toolCards.some(isToolCardError);
337+
// One expanded card already closes with its own outcome line; every other
338+
// shape renders inline rows only, so the message body records the failure.
339+
const expandsSingleToolCard = Boolean(singleToolCard) && !markdown && !hasImages;
340+
const failedToolCard = expandsSingleToolCard ? undefined : toolCards.find(isToolCardError);
333341
const singleToolDisplay = singleToolCard
334342
? resolveToolDisplay({
335343
name: singleToolCard.name,
@@ -468,25 +476,24 @@ export function renderGroupedMessage(
468476
class="chat-inline-disclosure chat-tool-msg-summary"
469477
type="button"
470478
aria-expanded=${String(toolMessageExpanded)}
479+
@pointerenter=${syncToolDisclosureOverflow}
480+
@focus=${syncToolDisclosureOverflow}
471481
@click=${(event: MouseEvent) => {
472482
if (shouldToggleSelectableDisclosure(event)) {
473483
opts.onToggleToolMessageExpanded?.(toolMessageDisclosureId);
474484
}
475485
}}
476486
>
477487
<span class="chat-tool-msg-summary__icon">${toolMessageIcon}</span>
478-
<span class="chat-tool-msg-summary__label">${toolMessageLabel}</span>
479-
${toolSummaryLabel
480-
? html`<span class="chat-tool-msg-summary__names">${toolSummaryLabel}</span>`
481-
: toolPreview
482-
? html`<span class="chat-tool-msg-summary__preview">${toolPreview}</span>`
483-
: nothing}
484-
<span class="chat-inline-disclosure__chevron" aria-hidden="true"
485-
>${icons.chevronDown}</span
486-
>
487-
${toolMessageHasError
488-
? html`<span class="chat-tool-row__badge">${t("chat.toolCards.failed")}</span>`
489-
: nothing}
488+
<span class="chat-tool-disclosure__content">
489+
<span class="chat-tool-msg-summary__label">${toolMessageLabel}</span>
490+
${toolSummaryLabel
491+
? html`<span class="chat-tool-msg-summary__names">${toolSummaryLabel}</span>`
492+
: toolPreview
493+
? html`<span class="chat-tool-msg-summary__preview">${toolPreview}</span>`
494+
: nothing}
495+
</span>
496+
<span class="chat-tool-row__chevron" aria-hidden="true">${icons.chevronRight}</span>
490497
</button>
491498
${toolMessageExpanded
492499
? html`
@@ -527,7 +534,7 @@ export function renderGroupedMessage(
527534
? renderMarkdownText(markdown, opts.isStreaming, markdownRenderOptions)
528535
: nothing}
529536
${hasToolCards
530-
? singleToolCard && !markdown && !hasImages
537+
? expandsSingleToolCard && singleToolCard
531538
? renderExpandedToolCardContent(
532539
singleToolCard,
533540
opts.sessionKey,
@@ -552,6 +559,9 @@ export function renderGroupedMessage(
552559
allowExternalEmbedUrls: opts.allowExternalEmbedUrls ?? false,
553560
})
554561
: nothing}
562+
${failedToolCard
563+
? renderToolOutcome("failed", failedToolCard.exitCode)
564+
: nothing}
555565
</div>
556566
`
557567
: nothing}

0 commit comments

Comments
 (0)