Skip to content
TypeScript

fix(web): simplify expanded tool details (#9549)

maria710f6dc417eb
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index 04e33914b62..cdca3328eb6 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -2886,27 +2886,47 @@ function workEntryRawCommand(
function buildToolCallExpandedBody(
workEntry: TimelineWorkEntry,
workspaceRoot: string | undefined,
+ visibleLabel: string,
+ viewedImagePath: string | null,
): string | null {
const blocks: string[] = [];
+ const seen = new Set<string>();
+ const addBlock = (value: string | null | undefined) => {
+ const text = value?.trim();
+ if (!text || seen.has(text)) return;
+ seen.add(text);
+ blocks.push(text);
+ };
if (workEntry.itemType === "mcp_tool_call" && workEntry.toolData !== undefined) {
- blocks.push(`MCP call\n${JSON.stringify(workEntry.toolData, null, 2)}`);
+ addBlock(`MCP call\n${JSON.stringify(workEntry.toolData, null, 2)}`);
}
+ const command = workEntry.command?.trim();
const raw = workEntryRawCommand(workEntry);
- if (raw?.trim()) {
- blocks.push(raw.trim());
- } else if (workEntry.command?.trim()) {
- blocks.push(workEntry.command.trim());
+ if (command === visibleLabel.trim()) {
+ seen.add(command);
+ } else {
+ addBlock(raw ?? command);
}
- if (workEntry.detail?.trim()) {
- blocks.push(workEntry.detail.trim());
+ const detail = workEntry.detail?.trim();
+ if (detail !== viewedImagePath?.trim()) {
+ addBlock(detail);
}
- const changedFiles = workEntry.changedFiles ?? [];
+ const viewedImagePaths = new Set(
+ viewedImagePath
+ ? [viewedImagePath.trim(), formatWorkspaceRelativePath(viewedImagePath, workspaceRoot)]
+ : [],
+ );
+ const changedFiles = (workEntry.changedFiles ?? []).flatMap((filePath) => {
+ const formattedPath = formatWorkspaceRelativePath(filePath, workspaceRoot);
+ return viewedImagePaths.has(filePath) ||
+ viewedImagePaths.has(formattedPath) ||
+ filePath.trim() === detail ||
+ formattedPath === detail
+ ? []
+ : [formattedPath];
+ });
if (changedFiles.length > 0) {
- blocks.push(
- changedFiles
- .map((filePath) => formatWorkspaceRelativePath(filePath, workspaceRoot))
- .join("\n"),
- );
+ addBlock([...new Set(changedFiles)].join("\n"));
}
return blocks.length > 0 ? blocks.join("\n\n") : null;
}
@@ -3092,19 +3112,7 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
? "circle-alert"
: workEntryIconName(workEntry);
const previewText = displayLabel ?? workEntryDisplayLabel(workEntry, workspaceRoot);
- const displayText =
- !toolPresentation && expanded && workEntry.command?.trim() ? "Command" : previewText;
const viewedImagePath = workEntryViewedImagePath(workEntry);
- const canExpand =
- (workEntry.itemType === "mcp_tool_call" && workEntry.toolData !== undefined) ||
- Boolean(
- workEntryRawCommand(workEntry) ||
- workEntry.command?.trim() ||
- workEntry.detail?.trim() ||
- workEntry.changedFiles?.length ||
- viewedImagePath,
- );
- const expandedBody = expanded ? buildToolCallExpandedBody(workEntry, workspaceRoot) : null;
const viewedImage =
viewedImagePath && threadRef
? resolveViewedImageAsset(viewedImagePath, {
@@ -3112,6 +3120,24 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
workspaceRoot,
})
: null;
+ const commandMatchesVisibleLabel = workEntry.command?.trim() === previewText.trim();
+ const canExpand =
+ (workEntry.itemType === "mcp_tool_call" && workEntry.toolData !== undefined) ||
+ Boolean(
+ (!commandMatchesVisibleLabel &&
+ (workEntryRawCommand(workEntry) || workEntry.command?.trim())) ||
+ workEntry.detail?.trim() ||
+ workEntry.changedFiles?.length ||
+ viewedImage,
+ );
+ const expandedBody = expanded
+ ? buildToolCallExpandedBody(
+ workEntry,
+ workspaceRoot,
+ previewText,
+ viewedImage ? viewedImagePath : null,
+ )
+ : null;
const showDestructiveRowStyle =
showFailedIndicator &&
(workEntrySignalsSevereFailure(workEntry) || !workLogEntryIsToolLike(workEntry));
@@ -3183,7 +3209,19 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
<div className="flex min-w-0 flex-1 items-center gap-1.5">
<div className="min-w-0 flex-1 overflow-hidden">
<p className="flex min-w-0 w-full items-baseline gap-1.5 text-sm leading-relaxed">
- <span className={cn("min-w-0 flex-1 truncate", headingClass)}>{displayText}</span>
+ <span
+ className={cn(
+ "min-w-0 flex-1",
+ expanded || (commandMatchesVisibleLabel && !canExpand)
+ ? "whitespace-pre-wrap break-words select-text"
+ : "truncate",
+ headingClass,
+ )}
+ onClick={expanded ? stopRowToggle : undefined}
+ onPointerDown={expanded ? stopRowToggle : undefined}
+ >
+ {previewText}
+ </span>
</p>
</div>
{showFailedIndicator && hasSpecialToolIcon ? (
@@ -3224,7 +3262,7 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
) : null}
{expanded && canExpand && expandedBody ? (
<div
- className="mt-1 ms-7 cursor-default border-s border-border/45 ps-3 pt-0.5"
+ className="mt-1 ms-7 cursor-default rounded-md bg-muted/40 px-3 py-2"
onClick={stopRowToggle}
onPointerDown={stopRowToggle}
>