@steerable/agent-ui 0.14.1 → 0.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,27 @@
1
1
  /**
2
2
  * `<ToolExecutionCard />`
3
3
  *
4
- * Unified renderer for a single tool / action invocation. Replaces both
5
- * deeppath's ActionSegment inline strip and deeppath-agent's
6
- * ExecutedActionsCard: one row per call with status / duration / expandable
7
- * args + output JSON. The optional `renderArgs` / `renderOutput` slots let an
8
- * app substitute a custom JSON viewer or rich payload renderer.
4
+ * Unified renderer for a single tool / action invocation: one compact row per
5
+ * call with status, duration, optional structured badge, and expandable
6
+ * details. Supports custom `renderBody` / `renderArgs` / `renderOutput` slots
7
+ * and localized `labels`.
9
8
  */
10
9
  import * as React from 'react';
11
10
  import type { ToolExecutionPayload } from '@steerable/agent-protocol';
11
+ export interface ToolExecutionCardLabels {
12
+ pending: string;
13
+ running: string;
14
+ succeeded: string;
15
+ failed: string;
16
+ cancelled: string;
17
+ expandDetails: string;
18
+ collapseDetails: string;
19
+ input: string;
20
+ output: string;
21
+ error: string;
22
+ }
23
+ export declare const DEFAULT_TOOL_EXECUTION_LABELS: ToolExecutionCardLabels;
24
+ export type ToolExecutionCardVariant = 'card' | 'embedded' | 'ghost';
12
25
  export interface ToolExecutionCardProps {
13
26
  payload: ToolExecutionPayload;
14
27
  className?: string;
@@ -17,12 +30,44 @@ export interface ToolExecutionCardProps {
17
30
  lead?: React.ReactNode;
18
31
  /** Header title; defaults to `payload.name`. */
19
32
  label?: string;
33
+ /** Structured inline badge rendered between `label` and `payload.summary` (e.g. sandbox posture). */
34
+ badge?: React.ReactNode;
35
+ /** Typography override for `payload.summary` (e.g. `font-mono text-[11px]`). */
36
+ summaryClassName?: string;
37
+ /** Native tooltip for untruncated single-line summary; defaults to `payload.summary`. */
38
+ summaryTitle?: string;
39
+ /**
40
+ * Visual container style:
41
+ * - `'card'` (default): standalone rounded bordered card
42
+ * - `'embedded'`: stacked row inside a bordered container (`border-t`, `first:border-t-0`)
43
+ * - `'ghost'`: Codex-style borderless tree row with left-indented detail rail
44
+ */
45
+ variant?: ToolExecutionCardVariant;
46
+ /** Render as a borderless stacked list row with top divider instead of a standalone rounded card. */
47
+ embedded?: boolean;
48
+ /** Visually hide the succeeded word ("Completed") while keeping check icon, sr-only status, and duration. */
49
+ compactStatus?: boolean;
50
+ /**
51
+ * Visually hide both the check icon and fast duration when `status === 'succeeded'`
52
+ * (keeping `.sr-only` status text and rendering `note` when provided).
53
+ */
54
+ quietSuccess?: boolean;
55
+ /** Inline semantic metadata rendered right before the status cluster (e.g. `+18 -5`, `92 lines`). */
56
+ trailingMeta?: React.ReactNode;
57
+ /** Localized copy overrides; defaults to English source strings. */
58
+ labels?: Partial<ToolExecutionCardLabels>;
59
+ /** Full custom body renderer when expanded; overrides default Input/Output/Error sections. */
60
+ renderBody?: (payload: ToolExecutionPayload) => React.ReactNode;
61
+ /** Compact inline preview rendered directly below the header row while collapsed (e.g. viewed image thumbnail). */
62
+ collapsedPreview?: (controls: {
63
+ expand: () => void;
64
+ }) => React.ReactNode;
20
65
  renderArgs?: (args: unknown) => React.ReactNode;
21
66
  renderOutput?: (output: unknown) => React.ReactNode;
22
- /** Header body click (chevron still toggles expand). */
67
+ /** Header body click (when set, renders a split left-chevron button + right-activate button). */
23
68
  onActivate?: () => void;
24
69
  activateTitle?: string;
25
- /** Short status suffix, such as a session-allow mark. */
70
+ /** Short status suffix, such as a session-allow mark or slow-call duration. */
26
71
  note?: string;
27
72
  }
28
73
  export declare const ToolExecutionCard: React.FC<ToolExecutionCardProps>;
@@ -1,21 +1,25 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
3
  * `<ToolExecutionCard />`
4
4
  *
5
- * Unified renderer for a single tool / action invocation. Replaces both
6
- * deeppath's ActionSegment inline strip and deeppath-agent's
7
- * ExecutedActionsCard: one row per call with status / duration / expandable
8
- * args + output JSON. The optional `renderArgs` / `renderOutput` slots let an
9
- * app substitute a custom JSON viewer or rich payload renderer.
5
+ * Unified renderer for a single tool / action invocation: one compact row per
6
+ * call with status, duration, optional structured badge, and expandable
7
+ * details. Supports custom `renderBody` / `renderArgs` / `renderOutput` slots
8
+ * and localized `labels`.
10
9
  */
11
10
  import * as React from 'react';
12
11
  import { CheckIcon, LoaderIcon, AlertIcon, ZapIcon, ChevronDownIcon, ChevronRightIcon, PlayIcon, StopIcon, } from './icons.js';
13
- const STATUS_LABEL = {
14
- pending: '待执行',
15
- running: '执行中',
16
- succeeded: '已完成',
17
- failed: '失败',
18
- cancelled: '已取消',
12
+ export const DEFAULT_TOOL_EXECUTION_LABELS = {
13
+ pending: 'Pending',
14
+ running: 'Running',
15
+ succeeded: 'Completed',
16
+ failed: 'Failed',
17
+ cancelled: 'Cancelled',
18
+ expandDetails: 'Expand details',
19
+ collapseDetails: 'Collapse details',
20
+ input: 'Input',
21
+ output: 'Output',
22
+ error: 'Error',
19
23
  };
20
24
  function formatToolDuration(ms) {
21
25
  if (!Number.isFinite(ms) || ms < 0)
@@ -56,22 +60,42 @@ function defaultRender(value) {
56
60
  catch {
57
61
  text = String(value);
58
62
  }
59
- return (_jsx("pre", { className: "whitespace-pre-wrap break-words rounded bg-[var(--agent-muted,#f3f4f6)] px-2 py-1.5 text-[11px] text-[var(--agent-foreground,#111827)]", children: text }));
63
+ return (_jsx("pre", { className: "max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-[var(--agent-muted,#f3f4f6)] px-2 py-1.5 text-[11px] text-[var(--agent-foreground,#111827)]", children: text }));
60
64
  }
61
- export const ToolExecutionCard = ({ payload, className, defaultExpanded = false, lead, label, renderArgs, renderOutput, onActivate, activateTitle, note, }) => {
65
+ const INTERACTIVE_BUTTON = 'cursor-pointer transition-colors hover:bg-[var(--agent-muted,#f3f4f6)]/60 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-[var(--agent-accent,#2563eb)]';
66
+ export const ToolExecutionCard = ({ payload, className, defaultExpanded = false, lead, label, badge, summaryClassName, summaryTitle, variant, embedded = false, compactStatus = false, quietSuccess = false, trailingMeta, labels, renderBody, collapsedPreview, renderArgs, renderOutput, onActivate, activateTitle, note, }) => {
67
+ const resolvedVariant = variant ?? (embedded ? 'embedded' : 'card');
68
+ const isGhost = resolvedVariant === 'ghost';
62
69
  const expandable = payload.expandable !== false;
63
70
  const [expanded, setExpanded] = React.useState(defaultExpanded);
64
71
  const status = (payload.status ?? 'pending');
65
72
  const title = label ?? payload.name;
66
73
  const duration = typeof payload.durationMs === 'number' ? formatToolDuration(payload.durationMs) : '';
67
- return (_jsxs("div", { className: [
68
- 'steerable-tool-execution rounded-lg border border-[var(--agent-border,#e5e7eb)] bg-[var(--agent-card-bg,#fff)] text-xs',
69
- className,
70
- ].filter(Boolean).join(' '), children: [_jsxs("div", { className: "flex w-full items-stretch", children: [expandable && (_jsx("button", { type: "button", onClick: () => setExpanded((v) => !v), className: "flex shrink-0 items-center text-[var(--agent-muted-foreground,#4b5563)]", "aria-expanded": expanded, "aria-label": expanded ? '收起详情' : '展开详情', children: _jsx("span", { className: "flex items-center px-2.5 py-1", children: expanded ? _jsx(ChevronDownIcon, { size: 12 }) : _jsx(ChevronRightIcon, { size: 12 }) }) })), _jsx("button", { type: "button", onClick: () => {
71
- if (onActivate)
72
- onActivate();
73
- else if (expandable)
74
- setExpanded((v) => !v);
75
- }, className: `flex min-w-0 flex-1 text-left ${onActivate ? 'cursor-pointer hover:bg-[var(--agent-muted,#f3f4f6)]/60' : ''}`, "aria-expanded": onActivate ? undefined : expanded, "aria-label": onActivate ? activateTitle : undefined, title: onActivate ? activateTitle : undefined, "data-testid": onActivate ? 'tool-activate' : undefined, children: _jsxs("span", { className: `flex min-w-0 flex-1 items-center gap-1.5 py-1 pr-2.5 ${expandable ? '' : 'pl-2.5'}`, children: [lead ?? (_jsx(ZapIcon, { size: 12, className: "shrink-0 text-[var(--agent-muted-foreground,#4b5563)]" })), _jsx("span", { className: "shrink-0 font-medium text-[var(--agent-foreground,#111827)]", children: title }), payload.summary && (_jsx("span", { className: "min-w-0 flex-1 truncate text-[var(--agent-muted-foreground,#4b5563)]", children: payload.summary })), _jsxs("span", { className: "ml-auto inline-flex shrink-0 items-center gap-1 whitespace-nowrap", children: [_jsx(StatusIcon, { status: status }), _jsx("span", { className: STATUS_TONE[status], children: STATUS_LABEL[status] }), duration && (_jsxs("span", { className: "text-[var(--agent-muted-foreground,#4b5563)]", children: ["\u00B7 ", duration] })), note && (_jsx("span", { className: "text-[var(--agent-muted-foreground,#4b5563)]", children: note }))] })] }) })] }), expandable && expanded && (_jsxs("div", { className: "space-y-1.5 border-t border-[var(--agent-border,#e5e7eb)] px-2.5 py-1.5", children: [payload.args !== undefined && (_jsxs("section", { children: [_jsx("div", { className: "mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]", children: "\u8F93\u5165" }), renderArgs ? renderArgs(payload.args) : defaultRender(payload.args)] })), payload.output !== undefined && (_jsxs("section", { children: [_jsx("div", { className: "mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]", children: "\u8F93\u51FA" }), renderOutput ? renderOutput(payload.output) : defaultRender(payload.output)] })), payload.error && (_jsxs("section", { children: [_jsx("div", { className: "mb-1 text-[10px] uppercase tracking-wider text-rose-700", children: "\u9519\u8BEF" }), _jsx("pre", { className: "whitespace-pre-wrap break-words rounded bg-rose-50/60 px-2 py-1.5 text-[11px] text-rose-700", children: payload.error })] }))] }))] }));
74
+ const mergedLabels = labels
75
+ ? { ...DEFAULT_TOOL_EXECUTION_LABELS, ...labels }
76
+ : DEFAULT_TOOL_EXECUTION_LABELS;
77
+ const hasSummary = Boolean(payload.summary);
78
+ const resolvedSummaryTitle = summaryTitle ?? (payload.summary ? payload.summary : undefined);
79
+ const isQuietSucceeded = quietSuccess && status === 'succeeded';
80
+ const hideStatusWord = (compactStatus || quietSuccess) && status === 'succeeded';
81
+ const hasTrailingMeta = trailingMeta !== undefined && trailingMeta !== null && trailingMeta !== false;
82
+ const buttonInteractiveClass = isGhost ? `${INTERACTIVE_BUTTON} rounded-md` : INTERACTIVE_BUTTON;
83
+ const rowHorizontalPad = isGhost ? 'pl-1.5 pr-2' : 'pl-2.5 pr-2.5';
84
+ const bodyCells = (_jsxs(_Fragment, { children: [lead !== undefined ? (lead) : (_jsx(ZapIcon, { size: 12, className: "shrink-0 text-[var(--agent-muted-foreground,#4b5563)]" })), _jsx("span", { className: `shrink-0 font-medium ${hasSummary
85
+ ? 'text-[var(--agent-muted-foreground,#4b5563)]'
86
+ : 'text-[var(--agent-foreground,#111827)]'}`, children: title }), badge, payload.summary && (_jsx("span", { className: `min-w-0 flex-1 truncate ${summaryClassName ?? 'text-[var(--agent-foreground,#111827)]'}`, title: resolvedSummaryTitle, children: payload.summary })), hasTrailingMeta ? (_jsx("span", { className: `${hasSummary ? '' : 'ml-auto '}inline-flex shrink-0 items-center whitespace-nowrap`, children: trailingMeta })) : null, isQuietSucceeded && !note ? (_jsx("span", { className: "sr-only", children: mergedLabels.succeeded })) : (_jsxs("span", { className: `${hasSummary || hasTrailingMeta ? '' : 'ml-auto '}inline-flex shrink-0 items-center gap-1 whitespace-nowrap`, children: [!isQuietSucceeded && _jsx(StatusIcon, { status: status }), _jsx("span", { className: hideStatusWord ? 'sr-only' : STATUS_TONE[status], children: mergedLabels[status] }), !isQuietSucceeded && duration && (_jsx("span", { className: "tabular-nums text-[var(--agent-muted-foreground,#4b5563)]", children: hideStatusWord ? duration : `· ${duration}` })), note && (_jsx("span", { className: "tabular-nums text-[var(--agent-muted-foreground,#4b5563)]", children: note }))] }))] }));
87
+ const surfaceClass = resolvedVariant === 'ghost'
88
+ ? ''
89
+ : resolvedVariant === 'embedded'
90
+ ? 'border-0 border-t border-[var(--agent-border,#e5e7eb)] first:border-t-0 bg-[var(--agent-card-bg,#fff)]'
91
+ : 'rounded-lg border border-[var(--agent-border,#e5e7eb)] bg-[var(--agent-card-bg,#fff)]';
92
+ const detailsClass = isGhost
93
+ ? 'ml-3.5 mt-1 mb-1.5 space-y-1.5 border-l border-[var(--agent-border,#e5e7eb)] pl-2.5 py-0.5'
94
+ : 'space-y-1.5 border-t border-[var(--agent-border,#e5e7eb)] px-2.5 py-2';
95
+ return (_jsxs("div", { className: ['steerable-tool-execution text-xs', surfaceClass, className]
96
+ .filter(Boolean)
97
+ .join(' '), "data-variant": resolvedVariant, children: [_jsx("div", { className: "flex w-full items-stretch", children: onActivate ? (_jsxs(_Fragment, { children: [expandable && (_jsx("button", { type: "button", onClick: () => setExpanded((v) => !v), className: `flex shrink-0 items-center text-[var(--agent-muted-foreground,#4b5563)] ${buttonInteractiveClass}`, "aria-expanded": expanded, "aria-label": expanded ? mergedLabels.collapseDetails : mergedLabels.expandDetails, children: _jsx("span", { className: `flex items-center py-1 ${isGhost ? 'px-1.5' : 'px-2.5'}`, children: expanded ? _jsx(ChevronDownIcon, { size: 12 }) : _jsx(ChevronRightIcon, { size: 12 }) }) })), _jsx("button", { type: "button", onClick: onActivate, className: `flex min-w-0 flex-1 text-left ${buttonInteractiveClass}`, "aria-label": activateTitle, title: activateTitle, "data-testid": "tool-activate", children: _jsx("span", { className: `flex min-w-0 flex-1 items-center gap-1.5 py-1 ${isGhost ? 'pr-2' : 'pr-2.5'} ${expandable ? '' : isGhost ? 'pl-1.5' : 'pl-2.5'}`, children: bodyCells }) })] })) : expandable ? (_jsx("button", { type: "button", onClick: () => setExpanded((v) => !v), className: `flex min-w-0 flex-1 text-left ${buttonInteractiveClass}`, "aria-expanded": expanded, children: _jsxs("span", { className: `flex min-w-0 flex-1 items-center gap-1.5 py-1 ${rowHorizontalPad}`, children: [_jsx("span", { className: "flex shrink-0 items-center text-[var(--agent-muted-foreground,#4b5563)]", "aria-hidden": true, children: expanded ? _jsx(ChevronDownIcon, { size: 12 }) : _jsx(ChevronRightIcon, { size: 12 }) }), bodyCells] }) })) : (_jsx("div", { className: "flex min-w-0 flex-1 text-left", children: _jsx("span", { className: `flex min-w-0 flex-1 items-center gap-1.5 py-1 ${rowHorizontalPad}`, children: bodyCells }) })) }), expandable && !expanded && collapsedPreview
98
+ ? collapsedPreview({ expand: () => setExpanded(true) })
99
+ : null, expandable && expanded && (_jsx("div", { className: detailsClass, children: renderBody ? (renderBody(payload)) : (_jsxs(_Fragment, { children: [payload.args !== undefined && (_jsxs("section", { children: [_jsx("div", { className: "mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]", children: mergedLabels.input }), renderArgs ? renderArgs(payload.args) : defaultRender(payload.args)] })), payload.output !== undefined && (_jsxs("section", { children: [_jsx("div", { className: "mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]", children: mergedLabels.output }), renderOutput ? renderOutput(payload.output) : defaultRender(payload.output)] })), payload.error && (_jsxs("section", { children: [_jsx("div", { className: "mb-1 text-[10px] uppercase tracking-wider text-rose-700", children: mergedLabels.error }), _jsx("pre", { className: "max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-rose-50/60 px-2 py-1.5 text-[11px] text-rose-700", children: payload.error })] }))] })) }))] }));
76
100
  };
77
101
  export default ToolExecutionCard;
@@ -5,3 +5,5 @@ export default meta;
5
5
  type Story = StoryObj<typeof ToolExecutionCard>;
6
6
  export declare const Succeeded: Story;
7
7
  export declare const Failed: Story;
8
+ export declare const CompactListRow: Story;
9
+ export declare const GhostTreeRow: Story;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ToolExecutionCard } from './ToolExecutionCard.js';
3
3
  const meta = {
4
4
  title: 'Cards/ToolExecutionCard',
@@ -51,3 +51,43 @@ export const Failed = {
51
51
  },
52
52
  },
53
53
  };
54
+ export const CompactListRow = {
55
+ args: {
56
+ label: 'Terminal',
57
+ compactStatus: true,
58
+ summaryClassName: 'font-mono text-[11px] text-[var(--agent-foreground,#111827)]',
59
+ payload: {
60
+ id: 'tool-exec-3',
61
+ name: 'local_exec_shell',
62
+ status: 'succeeded',
63
+ summary: 'ls -la packages/agent-ui/ts/src/cards',
64
+ args: { command: 'ls -la packages/agent-ui/ts/src/cards' },
65
+ output: 'ToolExecutionCard.tsx\nActionSegmentCard.tsx',
66
+ error: null,
67
+ durationMs: 98,
68
+ icon: null,
69
+ expandable: true,
70
+ },
71
+ },
72
+ };
73
+ export const GhostTreeRow = {
74
+ args: {
75
+ variant: 'ghost',
76
+ quietSuccess: true,
77
+ label: 'Edited',
78
+ summaryClassName: 'font-mono text-[11px] text-[var(--agent-foreground,#111827)]',
79
+ trailingMeta: (_jsxs("span", { className: "inline-flex items-center gap-1 font-mono text-[11px] tabular-nums", children: [_jsx("span", { className: "text-emerald-700", children: "+18" }), _jsx("span", { className: "text-rose-700", children: "-5" })] })),
80
+ payload: {
81
+ id: 'tool-exec-4',
82
+ name: 'local_edit_file',
83
+ status: 'succeeded',
84
+ summary: 'src/components/chat/AssistantMessage.tsx',
85
+ args: { path: 'src/components/chat/AssistantMessage.tsx' },
86
+ output: '@@ -542,2 +542,2 @@\n-old\n+new',
87
+ error: null,
88
+ durationMs: 110,
89
+ icon: null,
90
+ expandable: true,
91
+ },
92
+ },
93
+ };
@@ -34,8 +34,8 @@ export { SummaryMessageCard } from './SummaryMessageCard.js';
34
34
  export type { SummaryMessageCardProps } from './SummaryMessageCard.js';
35
35
  export { ActionSegmentCard } from './ActionSegmentCard.js';
36
36
  export type { ActionSegmentCardProps } from './ActionSegmentCard.js';
37
- export { ToolExecutionCard } from './ToolExecutionCard.js';
38
- export type { ToolExecutionCardProps } from './ToolExecutionCard.js';
37
+ export { ToolExecutionCard, DEFAULT_TOOL_EXECUTION_LABELS } from './ToolExecutionCard.js';
38
+ export type { ToolExecutionCardProps, ToolExecutionCardLabels, ToolExecutionCardVariant, } from './ToolExecutionCard.js';
39
39
  export { OutcomeReconcileCard } from './OutcomeReconcileCard.js';
40
40
  export type { OutcomeReconcileCardProps, OutcomeReconcileDecision, } from './OutcomeReconcileCard.js';
41
41
  export { getUiSurfaceDraft, patchUiSurfaceDraft, clearUiSurfaceDraft, subscribeUiSurfaceDraft, resetAllUiSurfaceDraftsForTests, } from './ui-surface-draft.js';
@@ -23,7 +23,7 @@ export { PlanSelectorCard } from './PlanSelectorCard.js';
23
23
  export { SearchSourcesCard } from './SearchSourcesCard.js';
24
24
  export { SummaryMessageCard } from './SummaryMessageCard.js';
25
25
  export { ActionSegmentCard } from './ActionSegmentCard.js';
26
- export { ToolExecutionCard } from './ToolExecutionCard.js';
26
+ export { ToolExecutionCard, DEFAULT_TOOL_EXECUTION_LABELS } from './ToolExecutionCard.js';
27
27
  export { OutcomeReconcileCard } from './OutcomeReconcileCard.js';
28
28
  export { getUiSurfaceDraft, patchUiSurfaceDraft, clearUiSurfaceDraft, subscribeUiSurfaceDraft, resetAllUiSurfaceDraftsForTests, } from './ui-surface-draft.js';
29
29
  export { UiSurfaceCard } from './UiSurfaceCard.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-ui",
3
- "version": "0.14.1",
3
+ "version": "0.14.3",
4
4
  "description": "Steerable framework Tier 4 — headless React hooks (useAgentSession, useChatStream, useToolCallStatus) and Tailwind-themed components (ChatPanel, MessageList, OrchestrationPlanCard, ToolCallRenderer, SSEStreamView) for embedding Steerable agents in any React app.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://steerableframework.com/storybook/",
@@ -57,7 +57,7 @@
57
57
  "README.md"
58
58
  ],
59
59
  "dependencies": {
60
- "@steerable/agent-protocol": "0.14.1"
60
+ "@steerable/agent-protocol": "0.14.3"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": ">=18.0.0",
@@ -61,3 +61,50 @@ export const Failed: Story = {
61
61
  },
62
62
  },
63
63
  };
64
+
65
+ export const CompactListRow: Story = {
66
+ args: {
67
+ label: 'Terminal',
68
+ compactStatus: true,
69
+ summaryClassName: 'font-mono text-[11px] text-[var(--agent-foreground,#111827)]',
70
+ payload: {
71
+ id: 'tool-exec-3',
72
+ name: 'local_exec_shell',
73
+ status: 'succeeded',
74
+ summary: 'ls -la packages/agent-ui/ts/src/cards',
75
+ args: { command: 'ls -la packages/agent-ui/ts/src/cards' },
76
+ output: 'ToolExecutionCard.tsx\nActionSegmentCard.tsx',
77
+ error: null,
78
+ durationMs: 98,
79
+ icon: null,
80
+ expandable: true,
81
+ },
82
+ },
83
+ };
84
+
85
+ export const GhostTreeRow: Story = {
86
+ args: {
87
+ variant: 'ghost',
88
+ quietSuccess: true,
89
+ label: 'Edited',
90
+ summaryClassName: 'font-mono text-[11px] text-[var(--agent-foreground,#111827)]',
91
+ trailingMeta: (
92
+ <span className="inline-flex items-center gap-1 font-mono text-[11px] tabular-nums">
93
+ <span className="text-emerald-700">+18</span>
94
+ <span className="text-rose-700">-5</span>
95
+ </span>
96
+ ),
97
+ payload: {
98
+ id: 'tool-exec-4',
99
+ name: 'local_edit_file',
100
+ status: 'succeeded',
101
+ summary: 'src/components/chat/AssistantMessage.tsx',
102
+ args: { path: 'src/components/chat/AssistantMessage.tsx' },
103
+ output: '@@ -542,2 +542,2 @@\n-old\n+new',
104
+ error: null,
105
+ durationMs: 110,
106
+ icon: null,
107
+ expandable: true,
108
+ },
109
+ },
110
+ };
@@ -1,11 +1,10 @@
1
1
  /**
2
2
  * `<ToolExecutionCard />`
3
3
  *
4
- * Unified renderer for a single tool / action invocation. Replaces both
5
- * deeppath's ActionSegment inline strip and deeppath-agent's
6
- * ExecutedActionsCard: one row per call with status / duration / expandable
7
- * args + output JSON. The optional `renderArgs` / `renderOutput` slots let an
8
- * app substitute a custom JSON viewer or rich payload renderer.
4
+ * Unified renderer for a single tool / action invocation: one compact row per
5
+ * call with status, duration, optional structured badge, and expandable
6
+ * details. Supports custom `renderBody` / `renderArgs` / `renderOutput` slots
7
+ * and localized `labels`.
9
8
  */
10
9
  import * as React from 'react';
11
10
  import type { ToolExecutionPayload } from '@steerable/agent-protocol';
@@ -22,12 +21,30 @@ import {
22
21
 
23
22
  type Status = 'pending' | 'running' | 'succeeded' | 'failed' | 'cancelled';
24
23
 
25
- const STATUS_LABEL: Record<Status, string> = {
26
- pending: '待执行',
27
- running: '执行中',
28
- succeeded: '已完成',
29
- failed: '失败',
30
- cancelled: '已取消',
24
+ export interface ToolExecutionCardLabels {
25
+ pending: string;
26
+ running: string;
27
+ succeeded: string;
28
+ failed: string;
29
+ cancelled: string;
30
+ expandDetails: string;
31
+ collapseDetails: string;
32
+ input: string;
33
+ output: string;
34
+ error: string;
35
+ }
36
+
37
+ export const DEFAULT_TOOL_EXECUTION_LABELS: ToolExecutionCardLabels = {
38
+ pending: 'Pending',
39
+ running: 'Running',
40
+ succeeded: 'Completed',
41
+ failed: 'Failed',
42
+ cancelled: 'Cancelled',
43
+ expandDetails: 'Expand details',
44
+ collapseDetails: 'Collapse details',
45
+ input: 'Input',
46
+ output: 'Output',
47
+ error: 'Error',
31
48
  };
32
49
 
33
50
  function formatToolDuration(ms: number): string {
@@ -44,6 +61,8 @@ const STATUS_TONE: Record<Status, string> = {
44
61
  cancelled: 'text-[var(--agent-muted-foreground,#4b5563)]',
45
62
  };
46
63
 
64
+ export type ToolExecutionCardVariant = 'card' | 'embedded' | 'ghost';
65
+
47
66
  export interface ToolExecutionCardProps {
48
67
  payload: ToolExecutionPayload;
49
68
  className?: string;
@@ -52,12 +71,42 @@ export interface ToolExecutionCardProps {
52
71
  lead?: React.ReactNode;
53
72
  /** Header title; defaults to `payload.name`. */
54
73
  label?: string;
74
+ /** Structured inline badge rendered between `label` and `payload.summary` (e.g. sandbox posture). */
75
+ badge?: React.ReactNode;
76
+ /** Typography override for `payload.summary` (e.g. `font-mono text-[11px]`). */
77
+ summaryClassName?: string;
78
+ /** Native tooltip for untruncated single-line summary; defaults to `payload.summary`. */
79
+ summaryTitle?: string;
80
+ /**
81
+ * Visual container style:
82
+ * - `'card'` (default): standalone rounded bordered card
83
+ * - `'embedded'`: stacked row inside a bordered container (`border-t`, `first:border-t-0`)
84
+ * - `'ghost'`: Codex-style borderless tree row with left-indented detail rail
85
+ */
86
+ variant?: ToolExecutionCardVariant;
87
+ /** Render as a borderless stacked list row with top divider instead of a standalone rounded card. */
88
+ embedded?: boolean;
89
+ /** Visually hide the succeeded word ("Completed") while keeping check icon, sr-only status, and duration. */
90
+ compactStatus?: boolean;
91
+ /**
92
+ * Visually hide both the check icon and fast duration when `status === 'succeeded'`
93
+ * (keeping `.sr-only` status text and rendering `note` when provided).
94
+ */
95
+ quietSuccess?: boolean;
96
+ /** Inline semantic metadata rendered right before the status cluster (e.g. `+18 -5`, `92 lines`). */
97
+ trailingMeta?: React.ReactNode;
98
+ /** Localized copy overrides; defaults to English source strings. */
99
+ labels?: Partial<ToolExecutionCardLabels>;
100
+ /** Full custom body renderer when expanded; overrides default Input/Output/Error sections. */
101
+ renderBody?: (payload: ToolExecutionPayload) => React.ReactNode;
102
+ /** Compact inline preview rendered directly below the header row while collapsed (e.g. viewed image thumbnail). */
103
+ collapsedPreview?: (controls: { expand: () => void }) => React.ReactNode;
55
104
  renderArgs?: (args: unknown) => React.ReactNode;
56
105
  renderOutput?: (output: unknown) => React.ReactNode;
57
- /** Header body click (chevron still toggles expand). */
106
+ /** Header body click (when set, renders a split left-chevron button + right-activate button). */
58
107
  onActivate?: () => void;
59
108
  activateTitle?: string;
60
- /** Short status suffix, such as a session-allow mark. */
109
+ /** Short status suffix, such as a session-allow mark or slow-call duration. */
61
110
  note?: string;
62
111
  }
63
112
 
@@ -86,114 +135,231 @@ function defaultRender(value: unknown): React.ReactNode {
86
135
  text = String(value);
87
136
  }
88
137
  return (
89
- <pre className="whitespace-pre-wrap break-words rounded bg-[var(--agent-muted,#f3f4f6)] px-2 py-1.5 text-[11px] text-[var(--agent-foreground,#111827)]">
138
+ <pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-[var(--agent-muted,#f3f4f6)] px-2 py-1.5 text-[11px] text-[var(--agent-foreground,#111827)]">
90
139
  {text}
91
140
  </pre>
92
141
  );
93
142
  }
94
143
 
144
+ const INTERACTIVE_BUTTON =
145
+ 'cursor-pointer transition-colors hover:bg-[var(--agent-muted,#f3f4f6)]/60 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-inset focus-visible:ring-[var(--agent-accent,#2563eb)]';
146
+
95
147
  export const ToolExecutionCard: React.FC<ToolExecutionCardProps> = ({
96
148
  payload,
97
149
  className,
98
150
  defaultExpanded = false,
99
151
  lead,
100
152
  label,
153
+ badge,
154
+ summaryClassName,
155
+ summaryTitle,
156
+ variant,
157
+ embedded = false,
158
+ compactStatus = false,
159
+ quietSuccess = false,
160
+ trailingMeta,
161
+ labels,
162
+ renderBody,
163
+ collapsedPreview,
101
164
  renderArgs,
102
165
  renderOutput,
103
166
  onActivate,
104
167
  activateTitle,
105
168
  note,
106
169
  }) => {
170
+ const resolvedVariant: ToolExecutionCardVariant = variant ?? (embedded ? 'embedded' : 'card');
171
+ const isGhost = resolvedVariant === 'ghost';
107
172
  const expandable = payload.expandable !== false;
108
173
  const [expanded, setExpanded] = React.useState(defaultExpanded);
109
174
  const status = (payload.status ?? 'pending') as Status;
110
175
  const title = label ?? payload.name;
111
176
  const duration = typeof payload.durationMs === 'number' ? formatToolDuration(payload.durationMs) : '';
177
+ const mergedLabels = labels
178
+ ? { ...DEFAULT_TOOL_EXECUTION_LABELS, ...labels }
179
+ : DEFAULT_TOOL_EXECUTION_LABELS;
180
+ const hasSummary = Boolean(payload.summary);
181
+ const resolvedSummaryTitle = summaryTitle ?? (payload.summary ? payload.summary : undefined);
182
+ const isQuietSucceeded = quietSuccess && status === 'succeeded';
183
+ const hideStatusWord = (compactStatus || quietSuccess) && status === 'succeeded';
184
+ const hasTrailingMeta = trailingMeta !== undefined && trailingMeta !== null && trailingMeta !== false;
185
+ const buttonInteractiveClass = isGhost ? `${INTERACTIVE_BUTTON} rounded-md` : INTERACTIVE_BUTTON;
186
+ const rowHorizontalPad = isGhost ? 'pl-1.5 pr-2' : 'pl-2.5 pr-2.5';
187
+
188
+ const bodyCells = (
189
+ <>
190
+ {lead !== undefined ? (
191
+ lead
192
+ ) : (
193
+ <ZapIcon size={12} className="shrink-0 text-[var(--agent-muted-foreground,#4b5563)]" />
194
+ )}
195
+ <span
196
+ className={`shrink-0 font-medium ${
197
+ hasSummary
198
+ ? 'text-[var(--agent-muted-foreground,#4b5563)]'
199
+ : 'text-[var(--agent-foreground,#111827)]'
200
+ }`}
201
+ >
202
+ {title}
203
+ </span>
204
+ {badge}
205
+ {payload.summary && (
206
+ <span
207
+ className={`min-w-0 flex-1 truncate ${
208
+ summaryClassName ?? 'text-[var(--agent-foreground,#111827)]'
209
+ }`}
210
+ title={resolvedSummaryTitle}
211
+ >
212
+ {payload.summary}
213
+ </span>
214
+ )}
215
+ {hasTrailingMeta ? (
216
+ <span
217
+ className={`${hasSummary ? '' : 'ml-auto '}inline-flex shrink-0 items-center whitespace-nowrap`}
218
+ >
219
+ {trailingMeta}
220
+ </span>
221
+ ) : null}
222
+ {isQuietSucceeded && !note ? (
223
+ <span className="sr-only">{mergedLabels.succeeded}</span>
224
+ ) : (
225
+ <span
226
+ className={`${
227
+ hasSummary || hasTrailingMeta ? '' : 'ml-auto '
228
+ }inline-flex shrink-0 items-center gap-1 whitespace-nowrap`}
229
+ >
230
+ {!isQuietSucceeded && <StatusIcon status={status} />}
231
+ <span className={hideStatusWord ? 'sr-only' : STATUS_TONE[status]}>
232
+ {mergedLabels[status]}
233
+ </span>
234
+ {!isQuietSucceeded && duration && (
235
+ <span className="tabular-nums text-[var(--agent-muted-foreground,#4b5563)]">
236
+ {hideStatusWord ? duration : `· ${duration}`}
237
+ </span>
238
+ )}
239
+ {note && (
240
+ <span className="tabular-nums text-[var(--agent-muted-foreground,#4b5563)]">
241
+ {note}
242
+ </span>
243
+ )}
244
+ </span>
245
+ )}
246
+ </>
247
+ );
248
+
249
+ const surfaceClass =
250
+ resolvedVariant === 'ghost'
251
+ ? ''
252
+ : resolvedVariant === 'embedded'
253
+ ? 'border-0 border-t border-[var(--agent-border,#e5e7eb)] first:border-t-0 bg-[var(--agent-card-bg,#fff)]'
254
+ : 'rounded-lg border border-[var(--agent-border,#e5e7eb)] bg-[var(--agent-card-bg,#fff)]';
255
+
256
+ const detailsClass = isGhost
257
+ ? 'ml-3.5 mt-1 mb-1.5 space-y-1.5 border-l border-[var(--agent-border,#e5e7eb)] pl-2.5 py-0.5'
258
+ : 'space-y-1.5 border-t border-[var(--agent-border,#e5e7eb)] px-2.5 py-2';
112
259
 
113
260
  return (
114
261
  <div
115
- className={[
116
- 'steerable-tool-execution rounded-lg border border-[var(--agent-border,#e5e7eb)] bg-[var(--agent-card-bg,#fff)] text-xs',
117
- className,
118
- ].filter(Boolean).join(' ')}
262
+ className={['steerable-tool-execution text-xs', surfaceClass, className]
263
+ .filter(Boolean)
264
+ .join(' ')}
265
+ data-variant={resolvedVariant}
119
266
  >
120
267
  <div className="flex w-full items-stretch">
121
- {expandable && (
268
+ {onActivate ? (
269
+ <>
270
+ {expandable && (
271
+ <button
272
+ type="button"
273
+ onClick={() => setExpanded((v) => !v)}
274
+ className={`flex shrink-0 items-center text-[var(--agent-muted-foreground,#4b5563)] ${buttonInteractiveClass}`}
275
+ aria-expanded={expanded}
276
+ aria-label={expanded ? mergedLabels.collapseDetails : mergedLabels.expandDetails}
277
+ >
278
+ {/* WKWebView ignores horizontal padding on a flex button. */}
279
+ <span className={`flex items-center py-1 ${isGhost ? 'px-1.5' : 'px-2.5'}`}>
280
+ {expanded ? <ChevronDownIcon size={12} /> : <ChevronRightIcon size={12} />}
281
+ </span>
282
+ </button>
283
+ )}
284
+ <button
285
+ type="button"
286
+ onClick={onActivate}
287
+ className={`flex min-w-0 flex-1 text-left ${buttonInteractiveClass}`}
288
+ aria-label={activateTitle}
289
+ title={activateTitle}
290
+ data-testid="tool-activate"
291
+ >
292
+ <span
293
+ className={`flex min-w-0 flex-1 items-center gap-1.5 py-1 ${
294
+ isGhost ? 'pr-2' : 'pr-2.5'
295
+ } ${expandable ? '' : isGhost ? 'pl-1.5' : 'pl-2.5'}`}
296
+ >
297
+ {bodyCells}
298
+ </span>
299
+ </button>
300
+ </>
301
+ ) : expandable ? (
122
302
  <button
123
303
  type="button"
124
304
  onClick={() => setExpanded((v) => !v)}
125
- className="flex shrink-0 items-center text-[var(--agent-muted-foreground,#4b5563)]"
305
+ className={`flex min-w-0 flex-1 text-left ${buttonInteractiveClass}`}
126
306
  aria-expanded={expanded}
127
- aria-label={expanded ? '收起详情' : '展开详情'}
128
307
  >
129
- {/* WKWebView ignores horizontal padding on a flex button. */}
130
- <span className="flex items-center px-2.5 py-1">
131
- {expanded ? <ChevronDownIcon size={12} /> : <ChevronRightIcon size={12} />}
308
+ {/* WKWebView ignores horizontal padding on a flex button; keep horizontal padding on the inner span. */}
309
+ <span className={`flex min-w-0 flex-1 items-center gap-1.5 py-1 ${rowHorizontalPad}`}>
310
+ <span
311
+ className="flex shrink-0 items-center text-[var(--agent-muted-foreground,#4b5563)]"
312
+ aria-hidden
313
+ >
314
+ {expanded ? <ChevronDownIcon size={12} /> : <ChevronRightIcon size={12} />}
315
+ </span>
316
+ {bodyCells}
132
317
  </span>
133
318
  </button>
134
- )}
135
- <button
136
- type="button"
137
- onClick={() => {
138
- if (onActivate) onActivate();
139
- else if (expandable) setExpanded((v) => !v);
140
- }}
141
- className={`flex min-w-0 flex-1 text-left ${onActivate ? 'cursor-pointer hover:bg-[var(--agent-muted,#f3f4f6)]/60' : ''}`}
142
- aria-expanded={onActivate ? undefined : expanded}
143
- aria-label={onActivate ? activateTitle : undefined}
144
- title={onActivate ? activateTitle : undefined}
145
- data-testid={onActivate ? 'tool-activate' : undefined}
146
- >
147
- <span className={`flex min-w-0 flex-1 items-center gap-1.5 py-1 pr-2.5 ${expandable ? '' : 'pl-2.5'}`}>
148
- {lead ?? (
149
- <ZapIcon size={12} className="shrink-0 text-[var(--agent-muted-foreground,#4b5563)]" />
150
- )}
151
- <span className="shrink-0 font-medium text-[var(--agent-foreground,#111827)]">
152
- {title}
153
- </span>
154
- {payload.summary && (
155
- <span className="min-w-0 flex-1 truncate text-[var(--agent-muted-foreground,#4b5563)]">
156
- {payload.summary}
157
- </span>
158
- )}
159
- <span className="ml-auto inline-flex shrink-0 items-center gap-1 whitespace-nowrap">
160
- <StatusIcon status={status} />
161
- <span className={STATUS_TONE[status]}>{STATUS_LABEL[status]}</span>
162
- {duration && (
163
- <span className="text-[var(--agent-muted-foreground,#4b5563)]">· {duration}</span>
164
- )}
165
- {note && (
166
- <span className="text-[var(--agent-muted-foreground,#4b5563)]">{note}</span>
167
- )}
319
+ ) : (
320
+ <div className="flex min-w-0 flex-1 text-left">
321
+ <span className={`flex min-w-0 flex-1 items-center gap-1.5 py-1 ${rowHorizontalPad}`}>
322
+ {bodyCells}
168
323
  </span>
169
- </span>
170
- </button>
324
+ </div>
325
+ )}
171
326
  </div>
327
+ {expandable && !expanded && collapsedPreview
328
+ ? collapsedPreview({ expand: () => setExpanded(true) })
329
+ : null}
172
330
  {expandable && expanded && (
173
- <div className="space-y-1.5 border-t border-[var(--agent-border,#e5e7eb)] px-2.5 py-1.5">
174
- {payload.args !== undefined && (
175
- <section>
176
- <div className="mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]">
177
- 输入
178
- </div>
179
- {renderArgs ? renderArgs(payload.args) : defaultRender(payload.args)}
180
- </section>
181
- )}
182
- {payload.output !== undefined && (
183
- <section>
184
- <div className="mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]">
185
- 输出
186
- </div>
187
- {renderOutput ? renderOutput(payload.output) : defaultRender(payload.output)}
188
- </section>
189
- )}
190
- {payload.error && (
191
- <section>
192
- <div className="mb-1 text-[10px] uppercase tracking-wider text-rose-700">错误</div>
193
- <pre className="whitespace-pre-wrap break-words rounded bg-rose-50/60 px-2 py-1.5 text-[11px] text-rose-700">
194
- {payload.error}
195
- </pre>
196
- </section>
331
+ <div className={detailsClass}>
332
+ {renderBody ? (
333
+ renderBody(payload)
334
+ ) : (
335
+ <>
336
+ {payload.args !== undefined && (
337
+ <section>
338
+ <div className="mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]">
339
+ {mergedLabels.input}
340
+ </div>
341
+ {renderArgs ? renderArgs(payload.args) : defaultRender(payload.args)}
342
+ </section>
343
+ )}
344
+ {payload.output !== undefined && (
345
+ <section>
346
+ <div className="mb-1 text-[10px] uppercase tracking-wider text-[var(--agent-muted-foreground,#4b5563)]">
347
+ {mergedLabels.output}
348
+ </div>
349
+ {renderOutput ? renderOutput(payload.output) : defaultRender(payload.output)}
350
+ </section>
351
+ )}
352
+ {payload.error && (
353
+ <section>
354
+ <div className="mb-1 text-[10px] uppercase tracking-wider text-rose-700">
355
+ {mergedLabels.error}
356
+ </div>
357
+ <pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-rose-50/60 px-2 py-1.5 text-[11px] text-rose-700">
358
+ {payload.error}
359
+ </pre>
360
+ </section>
361
+ )}
362
+ </>
197
363
  )}
198
364
  </div>
199
365
  )}
@@ -470,15 +470,15 @@ describe('CoverageReportCard selection mode', () => {
470
470
  });
471
471
 
472
472
  describe('ToolExecutionCard', () => {
473
- it('keeps the status label on one line when the summary is long', () => {
474
- render(
473
+ it('merges into a single interactive row button when onActivate is absent and keeps WKWebView inner-span padding', () => {
474
+ const { container } = render(
475
475
  <ToolExecutionCard
476
476
  payload={{
477
477
  id: 't',
478
478
  name: 'local_exec_shell',
479
479
  status: 'succeeded',
480
480
  summary: 'rm -f /tmp/r1.log; nohup /bin/zsh -c "sleep 999"',
481
- args: null,
481
+ args: { command: 'ls' },
482
482
  output: null,
483
483
  error: null,
484
484
  durationMs: 12,
@@ -487,7 +487,10 @@ describe('ToolExecutionCard', () => {
487
487
  }}
488
488
  />,
489
489
  );
490
- const label = screen.getByText('已完成');
490
+ const buttons = container.querySelectorAll('button');
491
+ expect(buttons).toHaveLength(1);
492
+ expect(buttons[0]?.className).toMatch(/cursor-pointer/);
493
+ const label = screen.getByText('Completed');
491
494
  expect(label.parentElement?.className).toMatch(/shrink-0/);
492
495
  expect(label.parentElement?.className).toMatch(/whitespace-nowrap/);
493
496
  const row = label.parentElement?.parentElement;
@@ -496,6 +499,26 @@ describe('ToolExecutionCard', () => {
496
499
  expect(label.closest('button')?.className ?? '').not.toMatch(/pr-2\.5/);
497
500
  });
498
501
 
502
+ it('renders a static header without buttons when expandable is false and onActivate is absent', () => {
503
+ const { container } = render(
504
+ <ToolExecutionCard
505
+ payload={{
506
+ id: 't-static',
507
+ name: 'local_exec_shell',
508
+ status: 'succeeded',
509
+ summary: 'echo ok',
510
+ args: null,
511
+ output: null,
512
+ error: null,
513
+ durationMs: 10,
514
+ icon: null,
515
+ expandable: false,
516
+ }}
517
+ />,
518
+ );
519
+ expect(container.querySelectorAll('button')).toHaveLength(0);
520
+ });
521
+
499
522
  it('expands to show args/output and renders error', () => {
500
523
  render(
501
524
  <ToolExecutionCard
@@ -535,37 +558,152 @@ describe('ToolExecutionCard', () => {
535
558
  expandable: true,
536
559
  }}
537
560
  onActivate={onActivate}
561
+ activateTitle="View run"
538
562
  />,
539
563
  );
540
564
  fireEvent.click(screen.getByText('search.web'));
541
565
  expect(onActivate).toHaveBeenCalledTimes(1);
542
566
  expect(screen.queryByText(/"q": "foo"/)).toBeNull();
543
- fireEvent.click(screen.getByRole('button', { name: '展开详情' }));
567
+ fireEvent.click(screen.getByRole('button', { name: 'Expand details' }));
544
568
  expect(screen.getByText(/"q": "foo"/)).toBeTruthy();
545
569
  });
546
570
 
547
- it('renders label and lead instead of the payload name', () => {
548
- render(
571
+ it('renders label, badge, compactStatus sr-only status, and localized labels', () => {
572
+ const { container } = render(
549
573
  <ToolExecutionCard
550
574
  payload={{
551
575
  id: 't',
552
576
  name: 'delegate_subagent',
553
- status: 'running',
577
+ status: 'succeeded',
554
578
  summary: '探环境',
555
579
  args: null,
556
580
  output: null,
557
581
  error: null,
558
- durationMs: null,
582
+ durationMs: 120,
559
583
  icon: null,
560
584
  expandable: true,
561
585
  }}
562
586
  label="委派 · 调研员"
563
587
  lead={<span data-testid="lead-dot" />}
588
+ badge={<span data-testid="sandbox-pill">沙箱</span>}
589
+ compactStatus
590
+ embedded
591
+ labels={{ succeeded: '已完成', expandDetails: '展开详情' }}
564
592
  />,
565
593
  );
566
594
  expect(screen.getByText('委派 · 调研员')).toBeTruthy();
567
595
  expect(screen.queryByText('delegate_subagent')).toBeNull();
568
596
  expect(screen.getByTestId('lead-dot')).toBeTruthy();
597
+ expect(screen.getByTestId('sandbox-pill')).toBeTruthy();
598
+ const statusText = screen.getByText('已完成');
599
+ expect(statusText.className).toBe('sr-only');
600
+ expect(screen.getByText('0.1s')).toBeTruthy();
601
+ expect(container.firstElementChild?.className).not.toMatch(/rounded-lg/);
602
+ });
603
+
604
+ it('T-UI-10 renders borderless ghost variant with trailingMeta, WKWebView inner-span padding, and left-rail details', () => {
605
+ const { container } = render(
606
+ <ToolExecutionCard
607
+ variant="ghost"
608
+ label="Edited"
609
+ lead={null}
610
+ trailingMeta={<span data-testid="diff-meta">+18 -5</span>}
611
+ payload={{
612
+ id: 't-ghost',
613
+ name: 'local_edit_file',
614
+ status: 'succeeded',
615
+ summary: 'src/components/chat/AssistantMessage.tsx',
616
+ args: null,
617
+ output: 'patched',
618
+ error: null,
619
+ durationMs: 90,
620
+ icon: null,
621
+ expandable: true,
622
+ }}
623
+ />,
624
+ );
625
+ const root = container.firstElementChild as HTMLElement;
626
+ expect(root.dataset.variant).toBe('ghost');
627
+ expect(root.className).not.toMatch(/border/);
628
+ expect(root.className).not.toMatch(/rounded-lg/);
629
+ const button = container.querySelector('button')!;
630
+ expect(button.className).not.toMatch(/pl-1\.5|pr-2/);
631
+ const innerSpan = button.firstElementChild as HTMLElement;
632
+ expect(innerSpan.tagName).toBe('SPAN');
633
+ expect(innerSpan.className).toMatch(/pl-1\.5/);
634
+ expect(innerSpan.className).toMatch(/pr-2/);
635
+ expect(screen.getByTestId('diff-meta').textContent).toBe('+18 -5');
636
+
637
+ fireEvent.click(button);
638
+ const details = root.lastElementChild as HTMLElement;
639
+ expect(details.className).toMatch(/border-l/);
640
+ expect(details.className).not.toMatch(/border-t/);
641
+ });
642
+
643
+ it('T-UI-11 hides check icon and fast duration under quietSuccess while keeping sr-only status and slow-call note', () => {
644
+ const { rerender } = render(
645
+ <ToolExecutionCard
646
+ variant="ghost"
647
+ quietSuccess
648
+ payload={{
649
+ id: 't-quiet',
650
+ name: 'local_exec_shell',
651
+ status: 'succeeded',
652
+ summary: 'ls -la',
653
+ args: null,
654
+ output: null,
655
+ error: null,
656
+ durationMs: 120,
657
+ icon: null,
658
+ expandable: true,
659
+ }}
660
+ />,
661
+ );
662
+ expect(screen.queryByText('0.1s')).toBeNull();
663
+ const srStatus = screen.getByText('Completed');
664
+ expect(srStatus.className).toBe('sr-only');
665
+
666
+ rerender(
667
+ <ToolExecutionCard
668
+ variant="ghost"
669
+ quietSuccess
670
+ note="6.2s"
671
+ payload={{
672
+ id: 't-quiet',
673
+ name: 'local_exec_shell',
674
+ status: 'succeeded',
675
+ summary: 'curl https://example.com',
676
+ args: null,
677
+ output: null,
678
+ error: null,
679
+ durationMs: 6200,
680
+ icon: null,
681
+ expandable: true,
682
+ }}
683
+ />,
684
+ );
685
+ expect(screen.getByText('6.2s')).toBeTruthy();
686
+
687
+ rerender(
688
+ <ToolExecutionCard
689
+ variant="ghost"
690
+ quietSuccess
691
+ payload={{
692
+ id: 't-quiet',
693
+ name: 'local_exec_shell',
694
+ status: 'failed',
695
+ summary: 'npm run build',
696
+ args: null,
697
+ output: null,
698
+ error: 'exit 2',
699
+ durationMs: 1400,
700
+ icon: null,
701
+ expandable: true,
702
+ }}
703
+ />,
704
+ );
705
+ expect(screen.getByText('Failed')).toBeTruthy();
706
+ expect(screen.getByText(/1\.4s/)).toBeTruthy();
569
707
  });
570
708
  });
571
709
 
@@ -56,8 +56,12 @@ export type { SummaryMessageCardProps } from './SummaryMessageCard.js';
56
56
  export { ActionSegmentCard } from './ActionSegmentCard.js';
57
57
  export type { ActionSegmentCardProps } from './ActionSegmentCard.js';
58
58
 
59
- export { ToolExecutionCard } from './ToolExecutionCard.js';
60
- export type { ToolExecutionCardProps } from './ToolExecutionCard.js';
59
+ export { ToolExecutionCard, DEFAULT_TOOL_EXECUTION_LABELS } from './ToolExecutionCard.js';
60
+ export type {
61
+ ToolExecutionCardProps,
62
+ ToolExecutionCardLabels,
63
+ ToolExecutionCardVariant,
64
+ } from './ToolExecutionCard.js';
61
65
 
62
66
  export { OutcomeReconcileCard } from './OutcomeReconcileCard.js';
63
67
  export type {