Skip to content
TypeScript

fix(web): background command details open above their button (#28446)

Theo Browne8b74a69019e3
diff --git a/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx b/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx
index bf83b014b7f..4c9702abe5f 100644
--- a/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx
+++ b/apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx
@@ -1,6 +1,7 @@
import { InfoIcon } from "lucide-react";
import type { ReactNode } from "react";
import { expect, it, vi } from "vite-plus/test";
+import { page, userEvent } from "vite-plus/test/browser";
import "~/index.css";
@@ -123,3 +124,28 @@ it("shows the details button while text or nested text is cut, until it fits aga
await screen.rerender(<ComposerBanner.Root>{noticeRow("4rem", "Ready")}</ComposerBanner.Root>);
await expect.element(details).not.toBeInTheDocument();
});
+
+it("opens the details of a long notice right above its button", async () => {
+ const viewport = { width: window.innerWidth, height: window.innerHeight };
+ await page.viewport(1280, 800);
+ await using _viewport = {
+ [Symbol.asyncDispose]: () => page.viewport(viewport.width, viewport.height),
+ };
+ const script = Array.from({ length: 400 }, (_, line) => `echo "line ${line}"`).join("\n");
+ const container = document.createElement("div");
+ container.style.cssText = "position: fixed; bottom: 4rem; right: 4rem;";
+ await using screen = await render(noticeRow("40rem", script), { container });
+ const details = screen.getByRole("button", { name: "Show details" });
+ await userEvent.hover(details);
+ const popup = page.getByLabelText("Notice details");
+ await expect.element(popup).toBeVisible();
+
+ // A positioner sized to the unscrolled text flips beside the button and covers it.
+ await vi.waitFor(() => {
+ const gap =
+ details.element().getBoundingClientRect().top -
+ popup.element().getBoundingClientRect().bottom;
+ expect(gap).toBeGreaterThanOrEqual(0);
+ expect(gap).toBeLessThan(8);
+ });
+});
diff --git a/apps/web/src/components/chat/ComposerBannerStack.tsx b/apps/web/src/components/chat/ComposerBannerStack.tsx
index 61778f817dc..ee602dcdac1 100644
--- a/apps/web/src/components/chat/ComposerBannerStack.tsx
+++ b/apps/web/src/components/chat/ComposerBannerStack.tsx
@@ -155,9 +155,7 @@ export function NoticeText({
side="top"
className="max-w-[min(30rem,calc(100vw-2rem))] whitespace-normal wrap-anywhere [--inline-button-text-align:start] [--inline-button-white-space:normal] [&_[data-slot=inline-button]]:max-w-full"
>
- <ComposerBanner.Scroll className="max-h-[min(var(--available-height),24rem,40dvh)]">
- {children}
- </ComposerBanner.Scroll>
+ <ComposerBanner.Scroll>{children}</ComposerBanner.Scroll>
</PopoverPopup>
</Popover>
) : null}
diff --git a/apps/web/src/components/chat/ThreadActivityBanners.tsx b/apps/web/src/components/chat/ThreadActivityBanners.tsx
index 4c0af2d3472..5342bd09b3c 100644
--- a/apps/web/src/components/chat/ThreadActivityBanners.tsx
+++ b/apps/web/src/components/chat/ThreadActivityBanners.tsx
@@ -191,7 +191,14 @@ export function backgroundWorkNowItem(input: {
icon: rows.every(isCommand) ? <TerminalIcon /> : <CircleDashedIcon />,
title: only ? (
<>
- {verb} <span className={cn(isCommand(only) && "font-mono")}>{only.task.label}</span>
+ {verb}{" "}
+ <span
+ className={cn(
+ isCommand(only) && "font-mono in-data-[slot=popover-popup]:whitespace-pre-wrap",
+ )}
+ >
+ {only.task.label}
+ </span>
</>
) : (
presentation.title
diff --git a/packages/client-runtime/src/state/threadExecution.test.ts b/packages/client-runtime/src/state/threadExecution.test.ts
index 81afabbe8aa..ecb050d721a 100644
--- a/packages/client-runtime/src/state/threadExecution.test.ts
+++ b/packages/client-runtime/src/state/threadExecution.test.ts
@@ -25,6 +25,7 @@ import {
deriveRunlessWorkStartedAt,
deriveThreadActivityRun,
deriveThreadRuntime,
+ presentPendingBackgroundWork,
presentProviderGoal,
presentRunStop,
threadRuntimeHasInterruptibleRun,
@@ -488,3 +489,16 @@ describe("presentProviderGoal", () => {
).toBe("1m / 1m tokens");
});
});
+
+describe("presentPendingBackgroundWork", () => {
+ it("names a command by its script, not the shell that wraps it", () => {
+ const presentation = presentPendingBackgroundWork([
+ {
+ taskId: "call_1",
+ kind: "command",
+ description: `/bin/zsh -lc "mv a.ts b.ts\ncat > b.ts <<'EOF'\nexport {};\nEOF"`,
+ },
+ ]);
+ expect(presentation?.items[0]?.label).toBe("mv a.ts b.ts\ncat > b.ts <<'EOF'\nexport {};\nEOF");
+ });
+});
diff --git a/packages/client-runtime/src/state/threadExecution.ts b/packages/client-runtime/src/state/threadExecution.ts
index 951e5d06404..711f813a3b8 100644
--- a/packages/client-runtime/src/state/threadExecution.ts
+++ b/packages/client-runtime/src/state/threadExecution.ts
@@ -33,6 +33,7 @@ import {
type ThreadStructure,
type ThreadStructureRuntime,
} from "./models.ts";
+import { commandDisplayText } from "../work-log/commandLabel.ts";
import { formatSubagentDisplayTitle } from "./subagentDisplay.ts";
const ACTIVITY_RUN_STATUSES = new Set(["preparing", "starting", "running", "waiting"]);
@@ -370,9 +371,13 @@ export function presentPendingBackgroundWork(
.map((task): PendingBackgroundWorkItem => {
const description = task.description?.trim();
const label =
- task.kind === "subagent" && description !== undefined
- ? formatSubagentDisplayTitle(description).trim()
- : description;
+ description === undefined
+ ? undefined
+ : task.kind === "subagent"
+ ? formatSubagentDisplayTitle(description).trim()
+ : task.kind === "command" || task.kind === "monitor"
+ ? commandDisplayText(description)
+ : description;
return {
taskId: task.taskId,
kind: task.kind,