feat(desktop): refine tool count spacing (#50356)

Co-authored-by: LukeParkerDev <10430890+Hona@users.noreply.github.com>
This commit is contained in:
usrnk1
2026-09-24 07:29:27 +02:00
committed by GitHub
Unverified
parent bc3669b97f
commit e31f78af78
12 changed files with 140 additions and 27 deletions
@@ -315,7 +315,10 @@ for (const delivery of ["steer", "queue"] as const) {
const tools = page.locator('[data-timeline-part-ids="tool_queue_read,tool_queue_grep"]')
await expect(tools).toBeVisible()
await expect(tools).toHaveText(/^Used\s*2\s*Read, Grep$/)
await expect(tools.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 2 Read, Grep")
await expect(tools.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 2 Read, Grep",
)
await expect(thinking).toHaveCount(0)
await expect(pending).toBeVisible()
expect(mock.rows.map((row) => ({ id: row.id, delivery: row.delivery }))).toEqual([
@@ -111,7 +111,10 @@ test.describe("regression: session timeline local row state", () => {
const id = `prt_patch_${count}`
events.push(...toolEvents({ ...part, id, callID: id }))
await expect(summary).toHaveAccessibleName(`Used ${count} Patch`)
await expect(summary.locator('[data-slot="context-tool-group-title"]')).toHaveText(`Used ${count} Patch`)
await expect(summary.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
`Used ${count} Patch`,
)
await expect(group).toHaveAttribute("data-timeline-part-ids", new RegExp(`${id}$`))
await expect(trigger).toHaveAttribute("aria-expanded", String(count === 2))
await expect(summary).toHaveAttribute("aria-expanded", "true")
@@ -18,7 +18,7 @@ for (const locale of ["de", "ar"] as const) {
const group = page.locator(`[data-timeline-part-ids="${ids.join(",")}"]`)
const label = locale === "de" ? "2 Lesen und Glob verwendet" : "استُخدمت 2 أداتان: \u2068قراءة وGlob\u2069"
await expect(group.getByRole("button")).toHaveAccessibleName(label)
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText(label)
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute("aria-label", label)
await expect(page.locator("html")).toHaveAttribute("lang", locale)
})
}
@@ -48,7 +48,10 @@ test("expands a mixed collapsed tool stack without expanding its individual call
const summary = group.getByRole("button", { name: "Used 4 Shell, Agent, Patch", exact: true })
await expect(summary).toHaveAttribute("aria-expanded", "false")
await expect(summary).toHaveCSS("height", "28px")
await expect(summary.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 4 Shell, Agent, Patch")
await expect(summary.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 4 Shell, Agent, Patch",
)
await expect(summary.locator('[data-component="tag"]')).toHaveCount(0)
await summary.click()
await expect(summary).toHaveAttribute("aria-expanded", "true")
@@ -76,7 +79,10 @@ test("leaves tools expanded by settings outside the collapsed stack", async ({ p
await expect(page.locator('[data-timeline-part-id="prt_expanded_shell"]')).toBeVisible()
const group = page.locator('[data-timeline-part-ids="prt_collapsed_patch,prt_collapsed_read"]')
await expect(group.getByRole("button", { name: "Used 2 Patch, Read", exact: true })).toBeVisible()
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 2 Patch, Read")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 2 Patch, Read",
)
await expect(page.locator('[data-timeline-spacing="tool"]')).toHaveCSS("padding-top", "8px")
})
@@ -41,7 +41,10 @@ story("merges follow-up patches into one stack with distinct files", async ({ mo
await first.click()
await expect(first).toHaveAttribute("aria-expanded", "true")
await root.getByRole("button", { name: "Start follow-up patch" }).click()
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 3 Shell, Patch")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 3 Shell, Patch",
)
await expect(patches).toHaveCount(1)
await expect(patches.locator('[data-slot="apply-patch-filename"]')).toHaveText(["a.ts", "b.ts"])
await root.getByRole("button", { name: "Finish follow-up patch" }).click()
@@ -18,7 +18,10 @@ for (const tool of ["shell", "execute", "subagent"]) {
for (const action of [undefined, "Complete input", "Run command", "Complete command"]) {
if (action) await timeline.getByRole("button", { name: action, exact: true }).click()
await expect(group).toHaveAttribute("data-timeline-part-ids", "tool_context_lifecycle,tool_shell_lifecycle")
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText(`Used 2 Read, ${title}`)
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
`Used 2 Read, ${title}`,
)
await expect(timeline.locator('[data-timeline-row="AssistantPart"]')).toHaveCount(1)
await expect(trigger).toHaveAttribute("aria-expanded", String(open))
expect(await original!.evaluate((node) => node.isConnected)).toBe(true)
@@ -138,7 +141,10 @@ for (const open of [false, true]) {
"aria-expanded",
String(open),
)
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 1 Shell")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 1 Shell",
)
await expect(timeline.locator('[data-timeline-row="Thinking"]')).toHaveCount(0)
await expect(used).toHaveAttribute("aria-expanded", "true")
if (!open) await thought.click()
@@ -186,7 +192,7 @@ for (const locale of ["de", "ar"] as const) {
const group = timeline.locator('[data-timeline-part-ids="tool_context_read,tool_context_glob"]')
const label = locale === "de" ? "2 Lesen und Glob verwendet" : "استُخدمت 2 أداتان: \u2068قراءة وGlob\u2069"
await expect(group.getByRole("button")).toHaveAccessibleName(label)
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText(label)
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute("aria-label", label)
await expect(page.locator("html")).toHaveAttribute("lang", locale)
})
}
@@ -52,7 +52,10 @@ for (const mode of ["hidden", "compact", "full"] as const) {
const trigger = group.locator(':scope > [data-component="collapsible"] > [data-slot="collapsible-trigger"]')
await expect(trigger).toHaveText(/^Used\s*1\s*Skill$/)
await expect(trigger).toHaveAttribute("aria-expanded", "false")
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 1 Skill")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 1 Skill",
)
await expect(timeline.getByText("Inspecting stability", { exact: true })).toBeHidden()
await trigger.click()
await expect(trigger).toHaveAttribute("aria-expanded", "true")
@@ -91,7 +91,10 @@ story("labels skill tools from IDs and result metadata", async ({ mount }) => {
const timeline = await mount("current-session-research-agents--agent-research", { args: { scenario: "skills" } })
const group = timeline.locator('[data-timeline-part-ids="tool_skill_id,tool_skill_name"]')
await expect(group.getByRole("button")).toHaveAccessibleName("Used 2 Skill")
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 2 Skill")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 2 Skill",
)
await group.getByRole("button").click()
const loaded = group.locator('[data-component="tool-loaded-item"]')
await expect(loaded).toHaveCount(1)
@@ -114,7 +117,10 @@ story("groups every collapsed tool until visible text separates the stack", asyn
)
await expect(group).toBeVisible()
await expect(group.getByRole("button")).toHaveAccessibleName("Used 4 Glob, Grep, Shell, List")
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 4 Glob, Grep, Shell, List")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 4 Glob, Grep, Shell, List",
)
await expect(timeline.locator('[data-timeline-row="AssistantPart"]')).toHaveCount(3)
await expect(timeline.locator('[data-timeline-spacing="content"]')).toHaveCount(2)
await expect(timeline.locator('[data-timeline-spacing="content"]').nth(0)).toHaveCSS("padding-top", "16px")
@@ -31,7 +31,10 @@ for (const open of [true, false]) {
const original = await patch.elementHandle()
for (const count of [3, 4]) {
await root.getByRole("button", { name: "Append tool call", exact: true }).click()
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText(`Used ${count} Shell, Patch`)
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
`Used ${count} Shell, Patch`,
)
await expect(trigger).toHaveAccessibleName(`Used ${count} Shell, Patch`)
await expect(diff).toBeVisible()
await root
@@ -11,7 +11,10 @@ for (const reasoningDefaultOpen of [false, true]) {
const second = group.locator('[data-timeline-part-id="reasoning_second"]')
await expect(used).toHaveAttribute("aria-expanded", "true")
await expect(used).toHaveAccessibleName("Used 4 Read, Skill")
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 4 Read, Skill")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 4 Read, Skill",
)
await expect(group.locator('[data-slot="context-tool-group-item"]')).toHaveText([
/Read.*group\.ts/,
/Thought/,
@@ -33,7 +36,10 @@ for (const reasoningDefaultOpen of [false, true]) {
await first.getByRole("button", { name: "Thought", exact: true }).click()
await root.getByRole("button", { name: "Append follow-up read", exact: true }).click()
await expect(used).toHaveAccessibleName("Used 5 Read, Skill")
await expect(group.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 5 Read, Skill")
await expect(group.locator('[data-component="context-tool-group-trigger"]')).toHaveAttribute(
"aria-label",
"Used 5 Read, Skill",
)
await expect(group.locator('[data-slot="context-tool-group-item"]')).toHaveText([
/Read.*group\.ts/,
/Thought/,
@@ -68,10 +74,24 @@ story("summarizes subagents as Agent while retaining their card titles", async (
const group = root.locator('[data-component="collapsed-tool-group"]')
await expect(group.getByRole("button", { name: "Used 4 Shell, Read, Agent", exact: true })).toBeVisible()
const header = group.locator('[data-component="context-tool-group-trigger"]')
const title = header.locator('[data-slot="context-tool-group-title"]')
await expect(title).toHaveText("Used 4 Shell, Read, Agent")
const prefix = header.locator('[data-slot="context-tool-group-prefix"]')
const count = header.locator('[data-slot="context-tool-group-count"]')
const title = header.locator('[data-slot="basic-tool-tool-title"]')
await expect(prefix).toHaveText("Used")
await expect(count).toHaveText("4")
await expect(title).toHaveText("Shell, Read, Agent")
await expect(title).toHaveCSS("white-space", "nowrap")
await expect(title).toHaveCSS("text-overflow", "ellipsis")
expect(await prefix.evaluate((node) => node.textContent)).toBe("Used")
expect(await count.evaluate((node) => node.textContent)).toBe("4")
expect(await prefix.locator("..").evaluate((node) => getComputedStyle(node).columnGap)).toBe("4px")
expect(await title.locator("..").evaluate((node) => getComputedStyle(node).columnGap)).toBe("4px")
expect(await count.evaluate((node) => getComputedStyle(node).fontVariantNumeric)).toBe("tabular-nums")
const colors = await Promise.all(
[prefix, count, title].map((part) => part.evaluate((node) => getComputedStyle(node).color)),
)
expect(colors[1]).toBe(colors[2])
expect(colors[0]).not.toBe(colors[1])
const gap = await group.evaluate((element) => {
const title = element.querySelector('[data-component="context-tool-group-trigger"]')!.getBoundingClientRect()
const arrow = element.querySelector('[data-slot="collapsible-arrow-icon"]')!.getBoundingClientRect()
@@ -88,7 +108,7 @@ for (const width of [840, 390]) {
const group = root.locator('[data-component="collapsed-tool-group"]')
const trigger = group.getByRole("button", { name: "Used 4 Shell, Read, Agent", exact: true })
const header = group.locator('[data-component="context-tool-group-trigger"]')
await expect(header.locator('[data-slot="context-tool-group-title"]')).toHaveText("Used 4 Shell, Read, Agent")
await expect(header).toHaveAttribute("aria-label", "Used 4 Shell, Read, Agent")
await expect(header.locator('[data-component="tag"]')).toHaveCount(0)
await expect(trigger).toHaveAttribute("aria-expanded", "true")
for (const action of ["click", "Enter", "Space"] as const) {
@@ -606,17 +606,44 @@
cursor: default;
[data-slot="context-tool-group-title"] {
flex: 0 1 auto;
display: flex;
align-items: center;
gap: 4px;
flex-shrink: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--v2-text-text-base);
}
[data-slot="context-tool-group-usage"] {
flex-shrink: 0;
display: flex;
align-items: center;
gap: 4px;
color: var(--v2-text-text-muted);
font-family: var(--v2-font-family-sans);
font-size: 13px;
font-weight: 440;
line-height: var(--line-height-compact);
letter-spacing: -0.04px;
& > [data-slot="context-tool-group-prefix"],
& > [data-slot="context-tool-group-count"] {
white-space: pre;
}
}
[data-slot="context-tool-group-count"] {
color: var(--v2-text-text-base);
font-variant-numeric: tabular-nums;
}
[data-slot="context-tool-group-prefix"] {
flex-shrink: 0;
}
[data-slot="basic-tool-tool-title"] {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
[data-slot="collapsible-arrow"] {
@@ -535,11 +535,26 @@ export function CurrentContextToolGroup(props: {
const label = createMemo(() => {
const thoughts = props.parts.filter((part) => part.type === "reasoning").length
if (!names() && !thoughts) {
return i18n.t("ui.messagePart.context.updates")
const text = i18n.t("ui.messagePart.context.updates")
return { text, title: "", before: text, count: "", between: "", after: "" }
}
const title = names() || i18n.plural("ui.messagePart.context.thought", thoughts)
const count = props.parts.filter((part) => part.type === "tool" || part.type === "shell").length || thoughts
return i18n.plural("ui.messagePart.tools.used", count, { tools: title })
const text = i18n.plural("ui.messagePart.tools.used", count, { tools: title })
const index = text.indexOf(title)
const before = text.slice(0, index).trim()
const countText = String(count)
const countIndex = before.indexOf(countText)
const after = text.slice(index + title.length).trim()
if (countIndex === -1) return { text, title, before, count: "", between: "", after }
return {
text,
title,
before: before.slice(0, countIndex).trim(),
count: countText,
between: before.slice(countIndex + countText.length).trim(),
after,
}
})
const items = createMemo(() =>
(props.open ? props.parts : []).reduce<
@@ -595,8 +610,26 @@ export function CurrentContextToolGroup(props: {
open={props.open}
onOpenChange={change}
trigger={
<div data-component="context-tool-group-trigger" aria-label={label()}>
<span data-slot="context-tool-group-title">{label()}</span>
<div data-component="context-tool-group-trigger" aria-label={label().text}>
<span data-slot="context-tool-group-title">
<Show when={label().before || label().count || label().between}>
<span data-slot="context-tool-group-usage">
<Show when={label().before}>
{(before) => <span data-slot="context-tool-group-prefix">{before()}</span>}
</Show>
<Show when={label().count}>
{(count) => <span data-slot="context-tool-group-count">{count()}</span>}
</Show>
<Show when={label().between}>
{(between) => <span data-slot="context-tool-group-prefix">{between()}</span>}
</Show>
</span>
</Show>
<Show when={label().title}>{(title) => <span data-slot="basic-tool-tool-title">{title()}</span>}</Show>
<Show when={label().after}>
{(after) => <span data-slot="context-tool-group-prefix">{after()}</span>}
</Show>
</span>
</div>
}
>