From e31f78af78da624dd0c9aa487cdf47509a6bd2d7 Mon Sep 17 00:00:00 2001 From: usrnk1 <7547651+usrnk1@users.noreply.github.com> Date: Thu, 24 Sep 2026 07:29:27 +0200 Subject: [PATCH] feat(desktop): refine tool count spacing (#50356) Co-authored-by: LukeParkerDev <10430890+Hona@users.noreply.github.com> --- .../app/e2e/regression/session-queue.spec.ts | 5 ++- .../session-timeline-collapse-state.spec.ts | 5 ++- ...session-timeline-locale-projection.spec.ts | 2 +- ...ession-timeline-reducer-projection.spec.ts | 10 ++++- .../component-tests/patch-group.spec.ts | 5 ++- .../component-tests/session-lifecycle.spec.ts | 12 ++++-- .../session-timeline-reasoning.spec.ts | 5 ++- .../session-tool-projection.spec.ts | 10 ++++- .../component-tests/tool-disclosure.spec.ts | 5 ++- .../component-tests/tool-group.spec.ts | 30 +++++++++++--- .../src/components/message-part.css | 37 ++++++++++++++--- .../session-ui/src/tools/tool-renderer.tsx | 41 +++++++++++++++++-- 12 files changed, 140 insertions(+), 27 deletions(-) diff --git a/packages/app/e2e/regression/session-queue.spec.ts b/packages/app/e2e/regression/session-queue.spec.ts index c83666f4df8..81ac9c88fd1 100644 --- a/packages/app/e2e/regression/session-queue.spec.ts +++ b/packages/app/e2e/regression/session-queue.spec.ts @@ -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([ diff --git a/packages/app/e2e/regression/session-timeline-collapse-state.spec.ts b/packages/app/e2e/regression/session-timeline-collapse-state.spec.ts index 50cdac2e422..bb489318dd5 100644 --- a/packages/app/e2e/regression/session-timeline-collapse-state.spec.ts +++ b/packages/app/e2e/regression/session-timeline-collapse-state.spec.ts @@ -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") diff --git a/packages/app/e2e/regression/session-timeline-locale-projection.spec.ts b/packages/app/e2e/regression/session-timeline-locale-projection.spec.ts index 754c7b14e4a..8a5d5441784 100644 --- a/packages/app/e2e/regression/session-timeline-locale-projection.spec.ts +++ b/packages/app/e2e/regression/session-timeline-locale-projection.spec.ts @@ -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) }) } diff --git a/packages/app/e2e/regression/session-timeline-reducer-projection.spec.ts b/packages/app/e2e/regression/session-timeline-reducer-projection.spec.ts index 35a88e1c437..51451574927 100644 --- a/packages/app/e2e/regression/session-timeline-reducer-projection.spec.ts +++ b/packages/app/e2e/regression/session-timeline-reducer-projection.spec.ts @@ -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") }) diff --git a/packages/session-ui/component-tests/patch-group.spec.ts b/packages/session-ui/component-tests/patch-group.spec.ts index 1356252c3a1..ecea8665cf5 100644 --- a/packages/session-ui/component-tests/patch-group.spec.ts +++ b/packages/session-ui/component-tests/patch-group.spec.ts @@ -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() diff --git a/packages/session-ui/component-tests/session-lifecycle.spec.ts b/packages/session-ui/component-tests/session-lifecycle.spec.ts index 0c3a69d39df..5560f8b014b 100644 --- a/packages/session-ui/component-tests/session-lifecycle.spec.ts +++ b/packages/session-ui/component-tests/session-lifecycle.spec.ts @@ -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) }) } diff --git a/packages/session-ui/component-tests/session-timeline-reasoning.spec.ts b/packages/session-ui/component-tests/session-timeline-reasoning.spec.ts index ddcaf3441e6..d83263a913f 100644 --- a/packages/session-ui/component-tests/session-timeline-reasoning.spec.ts +++ b/packages/session-ui/component-tests/session-timeline-reasoning.spec.ts @@ -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") diff --git a/packages/session-ui/component-tests/session-tool-projection.spec.ts b/packages/session-ui/component-tests/session-tool-projection.spec.ts index d4831867b03..e90c497acbf 100644 --- a/packages/session-ui/component-tests/session-tool-projection.spec.ts +++ b/packages/session-ui/component-tests/session-tool-projection.spec.ts @@ -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") diff --git a/packages/session-ui/component-tests/tool-disclosure.spec.ts b/packages/session-ui/component-tests/tool-disclosure.spec.ts index b47c2c49df3..cf8d0bbdad9 100644 --- a/packages/session-ui/component-tests/tool-disclosure.spec.ts +++ b/packages/session-ui/component-tests/tool-disclosure.spec.ts @@ -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 diff --git a/packages/session-ui/component-tests/tool-group.spec.ts b/packages/session-ui/component-tests/tool-group.spec.ts index 8e8566098bd..b980472c893 100644 --- a/packages/session-ui/component-tests/tool-group.spec.ts +++ b/packages/session-ui/component-tests/tool-group.spec.ts @@ -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) { diff --git a/packages/session-ui/src/components/message-part.css b/packages/session-ui/src/components/message-part.css index ee363856fed..c30c36b9115 100644 --- a/packages/session-ui/src/components/message-part.css +++ b/packages/session-ui/src/components/message-part.css @@ -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"] { diff --git a/packages/session-ui/src/tools/tool-renderer.tsx b/packages/session-ui/src/tools/tool-renderer.tsx index 8f43b82aad1..ba3f9084406 100644 --- a/packages/session-ui/src/tools/tool-renderer.tsx +++ b/packages/session-ui/src/tools/tool-renderer.tsx @@ -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={ -