From 5be4b1642bf8d84f69b3c53e24147b85637bba1c Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" <219766164+opencode-agent[bot]@users.noreply.github.com> Date: Sun, 25 Oct 2026 12:46:22 +0000 Subject: [PATCH] feat(session-ui): add a copy button to shell output (#58974) Co-authored-by: vimtor <36263538+vimtor@users.noreply.github.com> --- .../timeline-stability/lifecycle.spec.ts | 2 +- .../component-tests/session-lifecycle.spec.ts | 9 +- .../component-tests/session-shell.spec.ts | 17 ++++ .../session-timeline-mobile.spec.ts | 9 +- .../src/components/message-part.css | 25 ++++-- .../session-ui/src/tools/tool-renderer.tsx | 86 +++++++++++-------- packages/ui/src/i18n/en.ts | 1 + 7 files changed, 100 insertions(+), 49 deletions(-) diff --git a/packages/app/e2e/performance/timeline-stability/lifecycle.spec.ts b/packages/app/e2e/performance/timeline-stability/lifecycle.spec.ts index 9d79e0a35e9..257ef352341 100644 --- a/packages/app/e2e/performance/timeline-stability/lifecycle.spec.ts +++ b/packages/app/e2e/performance/timeline-stability/lifecycle.spec.ts @@ -93,7 +93,7 @@ test.describe("timeline visual lifecycle stability", () => { ), ) await expect( - page.locator(`[data-timeline-part-id="${renderedPartID(ids[2])}"] [data-slot="bash-pre"]`), + page.locator(`[data-timeline-part-id="${renderedPartID(ids[2])}"] [data-slot="bash-result"]`), ).toContainText("line 50") const short = page.locator(`[data-timeline-part-id="${renderedPartID(ids[1])}"]`) diff --git a/packages/session-ui/component-tests/session-lifecycle.spec.ts b/packages/session-ui/component-tests/session-lifecycle.spec.ts index 5c5b85e5d63..30fdd29f4f4 100644 --- a/packages/session-ui/component-tests/session-lifecycle.spec.ts +++ b/packages/session-ui/component-tests/session-lifecycle.spec.ts @@ -1,6 +1,10 @@ import { expect, story } from "../../storybook/playwright/story" -for (const tool of ["shell", "execute", "subagent"]) { +for (const [tool, title] of [ + ["shell", "Shell"], + ["execute", "Execute"], + ["subagent", "Agent"], +]) { for (const open of [false, true]) { story(`keeps ${tool} inside an existing ${open ? "open" : "closed"} group through execution`, async ({ mount }) => { const timeline = await mount("current-session-terminal-work--terminal-commands", { @@ -16,7 +20,6 @@ for (const tool of ["shell", "execute", "subagent"]) { await timeline.getByRole("button", { name: "Start tool", exact: true }).click() await expect(group).toHaveAttribute("data-timeline-part-ids", "tool_context_lifecycle,tool_shell_lifecycle") const original = await group.elementHandle() - const title = tool === "subagent" ? "Agent" : tool === "execute" ? "Execute" : "Shell" for (const action of [undefined, "Complete input", "Run command", "Complete command"]) { if (action) await timeline.getByRole("button", { name: action, exact: true }).click() @@ -109,7 +112,7 @@ story("shimmers and expands a running shell command", async ({ mount }) => { await expect(trigger).toHaveAttribute("aria-expanded", "false") await trigger.click() await expect(trigger).toHaveAttribute("aria-expanded", "true") - await expect(tool.locator('[data-slot="bash-pre"]')).toContainText("still running") + await expect(tool.locator('[data-slot="bash-result"]')).toContainText("still running") }) // Moved from packages/app/e2e/regression/session-timeline-lifecycle-state.spec.ts diff --git a/packages/session-ui/component-tests/session-shell.spec.ts b/packages/session-ui/component-tests/session-shell.spec.ts index 9587d9447cb..654700d728f 100644 --- a/packages/session-ui/component-tests/session-shell.spec.ts +++ b/packages/session-ui/component-tests/session-shell.spec.ts @@ -55,3 +55,20 @@ for (const [id, output] of [ await expect(root.locator('[data-component="session-shell-message"] [data-slot="bash-result"]')).toHaveText(output) }) } + +story("copies the shell command and its output separately", async ({ mount, page }) => { + const root = await mount("current-session-terminal-work--expanded-shell") + const shell = root.locator('[data-component="bash-output"]') + const command = (await shell.locator('[data-slot="bash-command"]').textContent())! + const output = (await shell.locator('[data-slot="bash-result"]').textContent())! + const clipboard = async () => (await page.evaluate(() => navigator.clipboard.readText())).replaceAll("\r\n", "\n") + await page.context().grantPermissions(["clipboard-read", "clipboard-write"]) + await shell.hover() + await shell.locator('[data-slot="bash-result"]').getByRole("button", { name: "Copy output", exact: true }).click() + await expect(shell.locator('[data-slot="bash-result"]').getByRole("button", { name: "Copied" })).toBeVisible() + expect(await clipboard()).toBe(output) + await shell.locator('[data-slot="bash-command"]').getByRole("button", { name: "Copy", exact: true }).click() + expect(await clipboard()).toBe(command) + expect(command).toContain("opencode2 api get /openapi.json") + expect(output).toContain('"name":"OpenCode"') +}) diff --git a/packages/session-ui/component-tests/session-timeline-mobile.spec.ts b/packages/session-ui/component-tests/session-timeline-mobile.spec.ts index 3fa5609136c..2cbeba53a2a 100644 --- a/packages/session-ui/component-tests/session-timeline-mobile.spec.ts +++ b/packages/session-ui/component-tests/session-timeline-mobile.spec.ts @@ -30,9 +30,12 @@ story.describe("touch timeline", () => { story("keeps shell copy visible without hover", async ({ mount }) => { const timeline = await mount("current-session-terminal-work--expanded-shell") const copy = timeline.locator('[data-slot="bash-copy"]') - await expect(copy).toHaveCount(1) - await expect(copy).toHaveCSS("opacity", "1") - await expect(copy).toHaveCSS("pointer-events", "auto") + await expect(copy).toHaveCount(2) + + for (const button of await copy.all()) { + await expect(button).toHaveCSS("opacity", "1") + await expect(button).toHaveCSS("pointer-events", "auto") + } }) story("keeps error copy visible without hover", async ({ mount, page }) => { diff --git a/packages/session-ui/src/components/message-part.css b/packages/session-ui/src/components/message-part.css index 1a1cec4e212..53524d16df7 100644 --- a/packages/session-ui/src/components/message-part.css +++ b/packages/session-ui/src/components/message-part.css @@ -479,21 +479,34 @@ &[data-variant="shell"] { background: var(--v2-background-bg-base); - [data-slot="bash-pre"] { - padding: 0; - } - [data-slot="bash-pre"] code { + display: block; font-family: var(--v2-font-family-code); font-weight: 440; line-height: var(--line-height-base); letter-spacing: -0.04px; } + /* Each section stacks its copy button over its text in one grid cell, so the sticky button stays in view + while that section scrolls and never leaves its own section. */ [data-slot="bash-command"], [data-slot="bash-result"] { - display: block; - padding: 12px; + display: grid; + grid-template-columns: minmax(0, 1fr); + } + + [data-slot="bash-pre"], + [data-slot="bash-copy"] { + grid-area: 1 / 1; + } + + [data-slot="bash-copy"] { + position: sticky; + top: 4px; + z-index: 1; + justify-self: end; + align-self: start; + margin: 4px; } [data-slot="bash-result"] { diff --git a/packages/session-ui/src/tools/tool-renderer.tsx b/packages/session-ui/src/tools/tool-renderer.tsx index 3150ad6aabd..55331cfc00e 100644 --- a/packages/session-ui/src/tools/tool-renderer.tsx +++ b/packages/session-ui/src/tools/tool-renderer.tsx @@ -1875,32 +1875,11 @@ ToolRegistry.register({ }, }) -function ConsoleOutput(props: { copy: string; children: JSX.Element; variant?: "shell" }) { +function ConsoleOutput(props: { command: string; output: string }) { const i18n = useI18n() - const [copied, setCopied] = createSignal(false) - - const copy = async () => { - if (!props.copy) return - - if (!(await writeClipboard(props.copy))) return - setCopied(true) - setTimeout(() => setCopied(false), 2000) - } return ( -
-
- - } - size="normal" - variant="ghost-muted" - onMouseDown={(event) => event.preventDefault()} - onClick={copy} - aria-label={copied() ? i18n.t("ui.message.copied") : i18n.t("ui.message.copy")} - /> - -
+
-
-          {props.children}
-        
+
+ +
+            {props.command}
+          
+
+ + {(output) => ( +
+ +
+                {output()}
+              
+
+ )} +
) } +// The button sits beside its section's
, not inside it, so selecting and copying text never picks it up.
+function ConsoleCopy(props: { text: string; label: string }) {
+  const i18n = useI18n()
+  const [copied, setCopied] = createSignal(false)
+  const label = () => (copied() ? i18n.t("ui.message.copied") : props.label)
+
+  const copy = async () => {
+    if (!props.text) return
+
+    if (!(await writeClipboard(props.text))) return
+    setCopied(true)
+    setTimeout(() => setCopied(false), 2000)
+  }
+
+  return (
+    
+ + } + size="normal" + variant="ghost-muted" + onMouseDown={(event) => event.preventDefault()} + onClick={copy} + aria-label={label()} + /> + +
+ ) +} + ToolRegistry.register({ name: "execute", render(props) { @@ -1946,10 +1968,7 @@ ToolRegistry.register({
)} > - - {code()} - {(value) => {value()}} - + ) }, @@ -1998,12 +2017,7 @@ ToolRegistry.register({ ), ) - return ( - - {command()} - {(value) => {value()}} - - ) + return } return ( diff --git a/packages/ui/src/i18n/en.ts b/packages/ui/src/i18n/en.ts index 7186c1f0f47..f4c50837089 100644 --- a/packages/ui/src/i18n/en.ts +++ b/packages/ui/src/i18n/en.ts @@ -252,6 +252,7 @@ const source = { "ui.message.voice": "Voice", "ui.message.deletePending": "Delete", "ui.message.copyResponse": "Copy response", + "ui.message.copyOutput": "Copy output", "ui.message.copied": "Copied", "ui.message.thought": "Thought", "ui.message.duration.seconds": "{{count}}s",