diff --git a/packages/session-ui/component-tests/shell-badge.spec.ts b/packages/session-ui/component-tests/shell-badge.spec.ts new file mode 100644 index 000000000000..a734987466f7 --- /dev/null +++ b/packages/session-ui/component-tests/shell-badge.spec.ts @@ -0,0 +1,39 @@ +import { expect, story } from "../../stories/playwright/story" + +story("keeps a failed shell badge on one line and truncates a long command", async ({ mount, page }) => { + const root = await mount("timeline-next-shell-badge--failed-badge") + + // Inter's metrics decide where the command wraps, so measure only once the font is ready. + await page.evaluate(() => document.fonts.ready.then(() => undefined)) + + // The call sits inside its collapsed "Ran 1 command" group; open the group to reach the row. + await root.getByRole("button", { name: "Ran 1 command" }).click() + + const group = root.locator('[data-component="context-tool-group-list"]') + const trigger = group.locator('[data-slot="collapsible-trigger"]') + const badge = trigger.locator('[data-component="tag"]') + const value = trigger.locator('[data-slot="shell-submessage-value"]') + + await expect(badge).toHaveText("Exit 1") + + // The badge is 16px tall: a wrapped second line overflows it instead of growing it. + const badgeOverflow = await badge.evaluate((element) => element.scrollHeight - element.clientHeight) + expect(badgeOverflow).toBe(0) + + // The command truncates inside its own box, with an ellipsis, rather than spilling past it. + const truncated = await value.evaluate((element) => element.scrollWidth > element.clientWidth) + expect(truncated).toBe(true) + + // The truncated command ends before the badge starts; it never runs into it. + const geometry = await trigger.evaluate((element) => { + const command = element.querySelector('[data-slot="shell-submessage-value"]') + const status = element.querySelector('[data-component="tag"]') + if (!command || !status) return null + return { + commandRight: command.getBoundingClientRect().right, + badgeLeft: status.getBoundingClientRect().left, + } + }) + expect(geometry).not.toBeNull() + expect(geometry?.commandRight).toBeLessThanOrEqual(geometry?.badgeLeft ?? 0) +}) diff --git a/packages/session-ui/src/components/shell-submessage.css b/packages/session-ui/src/components/shell-submessage.css index 59f0ae0cb421..73ab2a65b0ed 100644 --- a/packages/session-ui/src/components/shell-submessage.css +++ b/packages/session-ui/src/components/shell-submessage.css @@ -21,4 +21,11 @@ font-family: var(--v2-font-family-code); line-height: inherit; white-space: nowrap; + + /* The command is an atomic inline box inside the truncating subtitle, so the subtitle's own ellipsis never + reaches its text. Cap it at the subtitle's width and ellipsize it here, so a long command ends in "…" before + it reaches the status badge. */ + max-width: 100%; + overflow: hidden; + text-overflow: ellipsis; } diff --git a/packages/session-ui/src/timeline-next/stories/shell-badge.stories.tsx b/packages/session-ui/src/timeline-next/stories/shell-badge.stories.tsx new file mode 100644 index 000000000000..72a0c8856978 --- /dev/null +++ b/packages/session-ui/src/timeline-next/stories/shell-badge.stories.tsx @@ -0,0 +1,62 @@ +import type { SessionDocument } from "../../document" +import { CURRENT_SESSION_ID, STORY_MODEL, STORY_TIME } from "../../storybook/current-session-fixtures" +import { CurrentSessionProviders } from "../../storybook/current-session-story" +import { timelinePresets } from "../../timeline/detail" +import { NextSessionTimeline } from "./session-timeline" + +export default { + title: "OpenCode/Timeline/Shell badge", + id: "timeline-next-shell-badge", + component: NextSessionTimeline, + parameters: { layout: "fullscreen" }, +} + +const document = { + sessionID: CURRENT_SESSION_ID, + messages: [ + { + id: "msg_shell_badge_user", + type: "user", + text: "Run the build and tell me what failed.", + time: { created: STORY_TIME }, + metadata: { agent: "build", model: STORY_MODEL }, + }, + { + id: "msg_shell_badge_assistant", + type: "assistant", + agent: "build", + model: STORY_MODEL, + content: [ + { + type: "tool", + id: "tool_shell_badge", + name: "shell", + state: { + status: "completed", + input: { + command: "cd /very/long/path/to/the/project && bun run build --filter=@opencode/session-ui --force", + }, + content: [{ type: "text", text: "error: build failed" }], + metadata: { exit: 1 }, + }, + time: { created: STORY_TIME + 100, ran: STORY_TIME + 200, completed: STORY_TIME + 900 }, + }, + ], + time: { created: STORY_TIME + 100, completed: STORY_TIME + 1000 }, + }, + ], + status: { type: "idle" }, + diffs: [], +} satisfies SessionDocument + +const compact = timelinePresets.find((preset) => preset.id === "compact")!.value + +export const FailedBadge = { + render: () => ( +
+ + + +
+ ), +} diff --git a/packages/ui/src/data-display/badge/badge.css b/packages/ui/src/data-display/badge/badge.css index cb5d0f208cb8..aa806ae07f1b 100644 --- a/packages/ui/src/data-display/badge/badge.css +++ b/packages/ui/src/data-display/badge/badge.css @@ -20,6 +20,11 @@ letter-spacing: 0.05px; color: var(--v2-text-text-muted); font-variant-numeric: tabular-nums; + + /* A badge is an atomic label: it never wraps its text or shrinks in a flex row, so a squeezed row truncates the + text beside it instead of folding the badge onto a second line inside its fixed height. */ + white-space: nowrap; + flex-shrink: 0; } [data-component="tag"][data-high-contrast] {