Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/session-ui/component-tests/shell-badge.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
7 changes: 7 additions & 0 deletions packages/session-ui/src/components/shell-submessage.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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: () => (
<section class="mx-auto w-full max-w-[420px] p-6">
<CurrentSessionProviders document={document}>
<NextSessionTimeline document={document} timelineDetail={compact} />
</CurrentSessionProviders>
</section>
),
}
5 changes: 5 additions & 0 deletions packages/ui/src/data-display/badge/badge.css
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
Loading