fix(session-ui): simplify execute details dialog (#66295)

This commit is contained in:
Aarav Sareen 2026-11-25 12:23:41 +05:30 • committed by GitHub
parent 8d7477816f
commit 546a44d8fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 37 additions and 54 deletions

View file

@ -172,7 +172,6 @@ story("opens an execution's code and output from its View code action", async ({
const dialog = timeline.page().getByRole("dialog")
await expect(dialog.getByRole("heading", { name: "Execute" })).toBeVisible()
await expect(dialog).toContainText("Completed")
await expect(dialog).toContainText("2 calls")
await expect(dialog).toContainText('const tab = await tools.browser.tabs.open({ url: "http://localhost:4399" })')
await expect(dialog).toContainText('"tab": "tab_4f1c"')
await expect(dialog.getByRole("button", { name: "Copy code" })).toBeVisible()

View file

@ -1152,24 +1152,6 @@
align-items: center;
gap: 8px;
min-width: 0;
[data-slot="execute-details-status"] {
padding: 0 6px;
border-radius: 4px;
font-size: 12px;
line-height: var(--line-height-base);
color: var(--v2-text-text-muted);
background: var(--v2-background-bg-layer-02);
}
[data-slot="execute-details-status"][data-status="error"] {
color: var(--v2-state-fg-danger);
}
[data-slot="execute-details-meta"] {
font-size: 12px;
color: var(--v2-text-text-faint);
}
}
[data-component="execute-details"] {
@ -1207,11 +1189,6 @@
color: var(--v2-text-text-muted);
}
[data-slot="execute-details-section-meta"] {
font-size: 12px;
color: var(--v2-text-text-faint);
}
[data-slot="execute-details-source"] {
max-height: 360px;
overflow: auto;
@ -1228,16 +1205,8 @@
}
}
[data-slot="execute-details-error"] {
margin: 0;
padding: 12px 14px;
font-family: var(--v2-font-family-code);
font-size: 13px;
line-height: var(--line-height-base);
white-space: pre-wrap;
overflow-wrap: anywhere;
color: var(--v2-state-fg-danger);
background: var(--v2-background-bg-layer-01);
[data-tone="danger"] {
--opencode-diffs-fg: var(--v2-state-fg-danger);
}
}

View file

@ -31,6 +31,7 @@ export type DiffProps<T = {}> = FileDiffOptions<T, undefined> & {
const unsafeCSS = `
:host {
--diffs-bg: var(--opencode-diffs-bg, var(--color-background-stronger));
--diffs-fg: var(--opencode-diffs-fg, light-dark(var(--diffs-light, #000), var(--diffs-dark, #fff)));
/* Pierre mixes 15% in dark mode, which makes collapsed rows read as highlighted. */
--diffs-bg-separator-override: light-dark(
color-mix(in lab, var(--diffs-bg) 98%, var(--diffs-mixer)),
@ -151,6 +152,11 @@ const unsafeCSS = `
--mix-dark: 0%;
}
/* A host can set --opencode-diffs-fg to tint plain text lines (such as error output) across all browsers. */
[data-file] [data-line] span {
color: var(--opencode-diffs-fg, light-dark(var(--diffs-token-light, var(--diffs-light)), var(--diffs-token-dark, var(--diffs-dark))));
}
/* Syntax colors are inline styles on token spans, so emphasized text needs !important to stay legible on its highlight. */
[data-line-type='change-addition'] [data-diff-span],
[data-line-type='change-addition'] [data-diff-span] * {

View file

@ -40,6 +40,7 @@ import { useMarkdown } from "../context/markdown"
import { getDirectory, getFilename } from "@opencode/util/path"
import { checksum } from "@opencode/util/encode"
import { formatExecuteOutput } from "@opencode/util/execute-output"
import { Badge } from "@opencode/ui/badge"
import { Tooltip } from "@opencode/ui/tooltip"
import { useDialog } from "@opencode/ui/context/dialog"
import { Dialog, DialogBody, DialogHeader, DialogTitle } from "@opencode/ui/dialog"
@ -2090,9 +2091,7 @@ ToolRegistry.register({
const viewable = () => props.status !== "streaming" && !!code()
const openDetails = () =>
dialog.show(() => (
<ExecuteDetails code={code()} output={output()} error={error()} calls={count()} status={props.status} />
))
dialog.show(() => <ExecuteDetails code={code()} output={output()} error={error()} status={props.status} />)
return (
<BasicTool
@ -2155,39 +2154,42 @@ const executeCallsShown = 10
const executeCallsRevealed = 50
function ExecuteDetails(props: { code: string; output: string; error?: string; calls: number; status?: string }) {
function ExecuteDetails(props: { code: string; output: string; error?: string; status?: string }) {
const i18n = useI18n()
const fileComponent = useFileComponent()
const lineCount = (text: string) => text.split("\n").length
const lines = (text: string) => i18n.plural("ui.tool.execute.lines", lineCount(text))
// Code Mode returns structured results as compact JSON; show those indented, and highlight a bare JSON result.
const output = createMemo(() => formatExecuteOutput(props.output))
// Code and output share one number gutter, sized to the longer block, so their content starts on the same column.
// Code and output/error share one number gutter, sized to the longer block, so their content starts on the same column.
const numberDigits = () =>
String(Math.max(lineCount(props.code), props.output && !props.error ? lineCount(output().text) : 0)).length
String(
Math.max(
lineCount(props.code),
props.error ? lineCount(props.error) : props.output ? lineCount(output().text) : 0,
),
).length
const statusLabel = () =>
props.error
? i18n.t("ui.toolErrorCard.failed")
: props.status === "running"
? i18n.t("ui.tool.execute.running")
: i18n.t("ui.tool.execute.completed")
return (
<Dialog size="large" fit>
<DialogHeader>
<div data-slot="execute-details-title">
<DialogTitle>{i18n.t("ui.tool.execute")}</DialogTitle>
<span data-slot="execute-details-status" data-status={props.error ? "error" : props.status}>
{props.error
? i18n.t("ui.toolErrorCard.failed")
: props.status === "running"
? i18n.t("ui.tool.execute.running")
: i18n.t("ui.tool.execute.completed")}
</span>
<span data-slot="execute-details-meta">{i18n.plural("ui.tool.execute.calls", props.calls)}</span>
<Badge variant={props.error ? "danger" : "neutral"}>{statusLabel()}</Badge>
</div>
</DialogHeader>
<DialogBody class="min-h-0">
<div data-component="execute-details" style={{ "--execute-details-number-width": `${numberDigits()}ch` }}>
<ExecuteDetailsSection
label={i18n.t("ui.tool.execute.code")}
meta={lines(props.code)}
copy={props.code}
copyLabel={i18n.t("ui.tool.execute.copyCode")}
>
@ -2196,6 +2198,7 @@ function ExecuteDetails(props: { code: string; output: string; error?: string; c
mode="text"
file={{ name: "execute.js", contents: props.code, cacheKey: checksum(props.code) }}
overflow="wrap"
lineHoverHighlight="disabled"
/>
</ExecuteDetailsSection>
<Show
@ -2204,7 +2207,6 @@ function ExecuteDetails(props: { code: string; output: string; error?: string; c
<Show when={props.output}>
<ExecuteDetailsSection
label={i18n.t("ui.tool.execute.output")}
meta={lines(output().text)}
copy={output().text}
copyLabel={i18n.t("ui.tool.execute.copyOutput")}
>
@ -2217,6 +2219,7 @@ function ExecuteDetails(props: { code: string; output: string; error?: string; c
cacheKey: checksum(output().text),
}}
overflow="wrap"
lineHoverHighlight="disabled"
/>
</ExecuteDetailsSection>
</Show>
@ -2228,7 +2231,15 @@ function ExecuteDetails(props: { code: string; output: string; error?: string; c
copy={error()}
copyLabel={i18n.t("ui.toolErrorCard.copyError")}
>
<pre data-slot="execute-details-error">{error()}</pre>
<div data-tone="danger">
<Dynamic
component={fileComponent}
mode="text"
file={{ name: "error.txt", contents: error(), cacheKey: checksum(error()) }}
overflow="wrap"
lineHoverHighlight="disabled"
/>
</div>
</ExecuteDetailsSection>
)}
</Show>
@ -2240,7 +2251,6 @@ function ExecuteDetails(props: { code: string; output: string; error?: string; c
function ExecuteDetailsSection(props: {
label: string
meta?: string
copy: string
copyLabel: string
children: JSX.Element
@ -2252,7 +2262,6 @@ function ExecuteDetailsSection(props: {
<section data-slot="execute-details-section">
<header data-slot="execute-details-section-header">
<span data-slot="execute-details-section-label">{props.label}</span>
<Show when={props.meta}>{(meta) => <span data-slot="execute-details-section-meta">{meta()}</span>}</Show>
<Tooltip
value={copy.copied() ? i18n.t("ui.message.copied") : props.copyLabel}
placement="top"