@steerable/agent-shell-web 0.14.2 → 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.
- package/package.json +4 -4
- package/src/components/chat/ApprovalModal.tsx +426 -124
- package/src/components/chat/AssistantMessage.tsx +27 -6
- package/src/components/chat/ChatInput.tsx +23 -41
- package/src/components/chat/ChatProjectBadge.tsx +4 -4
- package/src/components/chat/ContextUsagePill.tsx +73 -21
- package/src/components/chat/ExecPolicyPicker.tsx +2 -2
- package/src/components/chat/ExecutedActionsCard.tsx +886 -180
- package/src/components/chat/LocalChatPanel.tsx +6 -3
- package/src/components/chat/ModelPicker.tsx +5 -2
- package/src/components/chat/TurnProcessGroup.tsx +37 -3
- package/src/components/chat/TurnProcessTimeline.tsx +533 -50
- package/src/components/chat/executed-actions-model.ts +1103 -61
- package/src/components/chat/process-status.ts +72 -4
- package/src/components/chat/rich-tool-views.tsx +666 -0
- package/src/components/chat/todo-list-model.ts +15 -0
- package/src/components/chat/turn-timeline.ts +51 -4
- package/src/components/settings/LlmSettingsPanel.tsx +1 -1
- package/src/components/settings/llm-vendors.ts +1 -1
- package/src/lib/browser-dev-host-mock.ts +1 -1
- package/src/pages/AgentPage.tsx +1 -2
- package/src/styles/index.css +10 -25
|
@@ -1,29 +1,64 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { useEffect, useRef, useState, type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
LuBrain,
|
|
4
|
+
LuCheck,
|
|
5
|
+
LuChevronDown,
|
|
6
|
+
LuChevronRight,
|
|
7
|
+
LuCircleCheck,
|
|
8
|
+
LuCircleX,
|
|
9
|
+
LuCopy,
|
|
10
|
+
LuFileCode,
|
|
11
|
+
LuFilePen,
|
|
12
|
+
LuFileText,
|
|
13
|
+
LuFolderOpen,
|
|
14
|
+
LuGlobe,
|
|
15
|
+
LuImage,
|
|
16
|
+
LuListTodo,
|
|
17
|
+
LuMessageSquare,
|
|
18
|
+
LuSearch,
|
|
19
|
+
LuSparkles,
|
|
20
|
+
LuTerminal,
|
|
21
|
+
} from 'react-icons/lu';
|
|
22
|
+
import {
|
|
23
|
+
ToolExecutionCard,
|
|
24
|
+
type ToolExecutionCardLabels,
|
|
25
|
+
} from '@steerable/agent-ui/cards';
|
|
4
26
|
import type { ToolExecutionPayload } from '@steerable/agent-protocol';
|
|
5
27
|
import type { LocalChatAgent } from '@/lib/local-api';
|
|
6
28
|
import { t } from '@/i18n';
|
|
7
29
|
import { UnifiedDiff } from './UnifiedDiff';
|
|
8
30
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
31
|
+
askInlineSummary,
|
|
32
|
+
askReplay,
|
|
33
|
+
delegateSubagentDisplayName,
|
|
34
|
+
deriveActionStatusInfo,
|
|
11
35
|
expandRunCodeActions,
|
|
36
|
+
extractFileChangePreview,
|
|
37
|
+
extractSkillInvocation,
|
|
38
|
+
extractWebActionSummary,
|
|
39
|
+
filterRedundantPresentFiles,
|
|
40
|
+
humanizeDelegateError,
|
|
41
|
+
inspectableTaskFromAction,
|
|
42
|
+
isTaskFamilyTool,
|
|
12
43
|
parseDelegateSubagent,
|
|
13
|
-
|
|
14
|
-
|
|
44
|
+
parseImageAction,
|
|
45
|
+
parseJsonValue,
|
|
46
|
+
parseMemoryAction,
|
|
15
47
|
parseTaskRun,
|
|
16
48
|
parseTaskToolOutput,
|
|
49
|
+
parseTerminalExecution,
|
|
50
|
+
parseTodoWriteAction,
|
|
17
51
|
parseToolEnvelope,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
inspectableTaskFromAction,
|
|
52
|
+
parseWebFetchAction,
|
|
53
|
+
parseWebSearchAction,
|
|
54
|
+
resolveActionCard,
|
|
55
|
+
segmentTimelineToolRows,
|
|
23
56
|
shortTaskId,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
57
|
+
shouldShowInlineSandboxPill,
|
|
58
|
+
shouldShowSandboxBadge,
|
|
59
|
+
SLOW_TOOL_THRESHOLD_MS,
|
|
60
|
+
taskToolLabel,
|
|
61
|
+
type DisplayActionRow,
|
|
27
62
|
type InspectTaskInput,
|
|
28
63
|
} from './executed-actions-model';
|
|
29
64
|
import {
|
|
@@ -31,21 +66,28 @@ import {
|
|
|
31
66
|
matchChildForDelegation,
|
|
32
67
|
type ChildInfo,
|
|
33
68
|
} from './orchestration-children-model';
|
|
69
|
+
import {
|
|
70
|
+
FileChangeDetailsView,
|
|
71
|
+
FileChangeTrailingMeta,
|
|
72
|
+
ImageCollapsedPreview,
|
|
73
|
+
ImageToolPreview,
|
|
74
|
+
ImageTrailingMeta,
|
|
75
|
+
MemoryDetailsView,
|
|
76
|
+
MiddleTruncatedPre,
|
|
77
|
+
TodoChecklistView,
|
|
78
|
+
WebFetchDetailsView,
|
|
79
|
+
WebSearchResultsView,
|
|
80
|
+
} from './rich-tool-views';
|
|
34
81
|
|
|
35
82
|
/**
|
|
36
83
|
* ExecutedActionsCard — visual surface for the `executed_actions` SSE event
|
|
37
84
|
* emitted by local-backend after each tool-call round.
|
|
38
85
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* `
|
|
44
|
-
* 1. Maps the local-backend `ExecutedAction` shape to the framework's
|
|
45
|
-
* canonical `ToolExecutionPayload` (id / name / status / args / output).
|
|
46
|
-
* 2. Adds the "已自动执行 N 个操作" summary banner above the list — the
|
|
47
|
-
* framework intentionally leaves grouping policy to the host app since
|
|
48
|
-
* different products count successes / failures differently.
|
|
86
|
+
* Supports two presentation modes:
|
|
87
|
+
* 1. `ToolsFlow` (`compact={true}` inside `TurnProcessTimeline`): Codex-style
|
|
88
|
+
* borderless `ghost` tree rows with L1 routine group folding (`Explored files · ran N commands`),
|
|
89
|
+
* consecutive read merging, exception-only status/sandbox metadata, and rich artifact previews.
|
|
90
|
+
* 2. Standalone `ExecutedActionsCard`: summary banner + stacked `embedded` rows.
|
|
49
91
|
*/
|
|
50
92
|
|
|
51
93
|
export interface ExecutedAction {
|
|
@@ -66,8 +108,7 @@ export interface ExecutedAction {
|
|
|
66
108
|
/** Set when a session allow or an unattended allow covered this call, so the row can say so. */
|
|
67
109
|
approval?: { kind?: string; category?: string; cached?: boolean; waitMs?: number; auto?: boolean };
|
|
68
110
|
/**
|
|
69
|
-
*
|
|
70
|
-
* 不再按工具名猜测。旧事件没有这个字段,仍走原来的摘要。
|
|
111
|
+
* Declared presentation from the host tool registry.
|
|
71
112
|
*/
|
|
72
113
|
view?: {
|
|
73
114
|
card: 'generic' | 'terminal' | 'diff' | 'search' | 'read' | 'web';
|
|
@@ -84,68 +125,281 @@ export interface ExecutedActionsCardProps {
|
|
|
84
125
|
compact?: boolean;
|
|
85
126
|
/** Show args/output instead of a one-line summary. Defaults to collapsed. */
|
|
86
127
|
defaultExpanded?: boolean;
|
|
87
|
-
/** Used to map `delegate_subagent`
|
|
128
|
+
/** Used to map `delegate_subagent` profile names to the agent's display name + color. */
|
|
88
129
|
agents?: ReadonlyArray<Pick<LocalChatAgent, 'id' | 'slug' | 'name' | 'color'>>;
|
|
89
130
|
chatId?: string | null;
|
|
90
131
|
onInspectTask?: (task: InspectTaskInput) => void;
|
|
91
132
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
133
|
+
* Subagent runs in this turn; delegation rows match against these records to
|
|
134
|
+
* open the right-hand reasoning inspector.
|
|
94
135
|
*/
|
|
95
136
|
orchestrationChildren?: ChildInfo[];
|
|
137
|
+
/** Settled deliverable file paths rendered below the answer; deduplicates `present_files`. */
|
|
138
|
+
deliveredFilePaths?: ReadonlySet<string> | null;
|
|
96
139
|
}
|
|
97
140
|
|
|
98
141
|
function deriveStatus(action: ExecutedAction): ToolExecutionPayload['status'] {
|
|
99
|
-
|
|
100
|
-
if (result === undefined || result === null) return 'running';
|
|
101
|
-
const env = parseToolEnvelope(result);
|
|
102
|
-
if (env.success === false || env.error) return 'failed';
|
|
103
|
-
if (env.success === true) return 'succeeded';
|
|
104
|
-
if (typeof result !== 'object') return 'succeeded';
|
|
105
|
-
if ('error' in result) return 'failed';
|
|
106
|
-
return 'succeeded';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function summarizeArguments(args: unknown): string | null {
|
|
110
|
-
if (args === null || args === undefined) return null;
|
|
111
|
-
if (typeof args === 'string') return args.length > 60 ? args.slice(0, 57) + '…' : args;
|
|
112
|
-
if (typeof args !== 'object') return String(args);
|
|
113
|
-
const obj = args as Record<string, unknown>;
|
|
114
|
-
for (const key of ['command', 'cmd', 'url', 'query', 'path', 'file', 'target', 'message']) {
|
|
115
|
-
const v = obj[key];
|
|
116
|
-
if (typeof v === 'string' && v.length > 0) {
|
|
117
|
-
return v.length > 60 ? v.slice(0, 57) + '…' : v;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return null;
|
|
142
|
+
return deriveActionStatusInfo(action).status;
|
|
121
143
|
}
|
|
122
144
|
|
|
123
|
-
function
|
|
124
|
-
if (
|
|
145
|
+
function formatSlowDuration(ms: number): string {
|
|
146
|
+
if (ms < 10_000) return `${(Math.round(ms / 100) / 10).toFixed(1)}s`;
|
|
147
|
+
return `${Math.round(ms / 1000)}s`;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function localizedCardLabels(): ToolExecutionCardLabels {
|
|
151
|
+
return {
|
|
152
|
+
pending: t('Pending'),
|
|
153
|
+
running: t('Running'),
|
|
154
|
+
succeeded: t('Completed'),
|
|
155
|
+
failed: t('Failed'),
|
|
156
|
+
cancelled: t('Cancelled'),
|
|
157
|
+
expandDetails: t('Expand details'),
|
|
158
|
+
collapseDetails: t('Collapse details'),
|
|
159
|
+
input: t('Input'),
|
|
160
|
+
output: t('Output'),
|
|
161
|
+
error: t('Error'),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function SandboxPill({
|
|
166
|
+
sandbox,
|
|
167
|
+
}: {
|
|
168
|
+
sandbox: NonNullable<ExecutedAction['sandbox']>;
|
|
169
|
+
}) {
|
|
170
|
+
let label: string;
|
|
171
|
+
let tone: string;
|
|
125
172
|
switch (sandbox.enforcement) {
|
|
126
173
|
case 'full':
|
|
127
|
-
|
|
174
|
+
label = t('Sandboxed');
|
|
175
|
+
tone = 'bg-agent-muted text-agent-muted-foreground';
|
|
176
|
+
break;
|
|
128
177
|
case 'partial':
|
|
129
|
-
|
|
178
|
+
label = t('Sandboxed · partial');
|
|
179
|
+
tone = 'bg-agent-muted text-agent-muted-foreground';
|
|
180
|
+
break;
|
|
130
181
|
default:
|
|
131
|
-
|
|
182
|
+
label = t('Unsandboxed');
|
|
183
|
+
tone = 'border border-amber-500/25 bg-amber-500/10 text-amber-700 dark:text-amber-300';
|
|
184
|
+
break;
|
|
132
185
|
}
|
|
186
|
+
const tooltip = sandbox.backend ? `${label} (${sandbox.backend})` : label;
|
|
187
|
+
return (
|
|
188
|
+
<span
|
|
189
|
+
data-sandbox-pill={sandbox.enforcement}
|
|
190
|
+
title={tooltip}
|
|
191
|
+
className={`inline-flex shrink-0 items-center rounded px-1.5 py-0.5 text-[10px] leading-none ${tone}`}
|
|
192
|
+
>
|
|
193
|
+
{label}
|
|
194
|
+
</span>
|
|
195
|
+
);
|
|
133
196
|
}
|
|
134
197
|
|
|
135
|
-
function
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
198
|
+
function ApprovalPill({
|
|
199
|
+
approval,
|
|
200
|
+
}: {
|
|
201
|
+
approval: NonNullable<ExecutedAction['approval']>;
|
|
202
|
+
}) {
|
|
203
|
+
if (approval.auto === true || !approval.kind) return null;
|
|
204
|
+
const isDenied = approval.kind === 'deny' || approval.kind === 'declined' || approval.kind === 'reject';
|
|
205
|
+
const label = isDenied ? t('Declined') : t('Approved');
|
|
206
|
+
const tone = isDenied
|
|
207
|
+
? 'border border-rose-500/25 bg-rose-500/10 text-rose-700 dark:text-rose-300'
|
|
208
|
+
: 'bg-agent-muted text-agent-muted-foreground';
|
|
209
|
+
return (
|
|
210
|
+
<span className={`inline-flex shrink-0 items-center rounded px-1.5 py-0.5 text-[10px] leading-none ${tone}`}>
|
|
211
|
+
{label}
|
|
212
|
+
</span>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function CopySnippetButton({
|
|
217
|
+
text,
|
|
218
|
+
label,
|
|
219
|
+
}: {
|
|
220
|
+
text: string;
|
|
221
|
+
label: string;
|
|
222
|
+
}) {
|
|
223
|
+
const [copied, setCopied] = useState(false);
|
|
224
|
+
const timerRef = useRef<number | null>(null);
|
|
225
|
+
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
return () => {
|
|
228
|
+
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
229
|
+
};
|
|
230
|
+
}, []);
|
|
231
|
+
|
|
232
|
+
const handleCopy = () => {
|
|
233
|
+
try {
|
|
234
|
+
void navigator.clipboard?.writeText(text)?.catch(() => {});
|
|
235
|
+
} catch {
|
|
236
|
+
// Ignore clipboard failures in restricted test/webview contexts.
|
|
237
|
+
}
|
|
238
|
+
setCopied(true);
|
|
239
|
+
if (timerRef.current !== null) window.clearTimeout(timerRef.current);
|
|
240
|
+
timerRef.current = window.setTimeout(() => {
|
|
241
|
+
setCopied(false);
|
|
242
|
+
timerRef.current = null;
|
|
243
|
+
}, 1500);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<button
|
|
248
|
+
type="button"
|
|
249
|
+
onClick={handleCopy}
|
|
250
|
+
aria-label={copied ? t('Copied') : label}
|
|
251
|
+
className="inline-flex shrink-0 cursor-pointer items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-agent-muted-foreground transition-colors hover:bg-agent-muted hover:text-agent-foreground"
|
|
252
|
+
>
|
|
253
|
+
{copied ? (
|
|
254
|
+
<LuCheck className="h-3 w-3 text-emerald-600" />
|
|
255
|
+
) : (
|
|
256
|
+
<LuCopy className="h-3 w-3" />
|
|
257
|
+
)}
|
|
258
|
+
<span>{copied ? t('Copied') : label}</span>
|
|
259
|
+
</button>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function formatSandboxSubtitle(sandbox?: ExecutedAction['sandbox']): string | null {
|
|
264
|
+
if (!sandbox) return null;
|
|
265
|
+
if (sandbox.backend) return `${sandbox.backend} (${sandbox.enforcement})`;
|
|
266
|
+
return sandbox.enforcement;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function TerminalExecutionDetails({ action }: { action: ExecutedAction }) {
|
|
270
|
+
const parsed = parseTerminalExecution(action);
|
|
271
|
+
const isSnippet = action.tool === 'local_run_snippet';
|
|
272
|
+
const combinedOutput = [parsed.stdout, parsed.stderr, parsed.error]
|
|
273
|
+
.filter((part): part is string => Boolean(part && part.length > 0))
|
|
274
|
+
.join('\n');
|
|
275
|
+
const sandboxMeta = formatSandboxSubtitle(action.sandbox);
|
|
276
|
+
const metaParts = [
|
|
277
|
+
parsed.packages?.length ? `deps: ${parsed.packages.join(', ')}` : null,
|
|
278
|
+
parsed.cwd ? `cwd: ${parsed.cwd}` : null,
|
|
279
|
+
sandboxMeta,
|
|
280
|
+
].filter(Boolean);
|
|
281
|
+
|
|
282
|
+
return (
|
|
283
|
+
<div className="space-y-1.5 text-[11px] text-agent-foreground" data-testid="terminal-details">
|
|
284
|
+
{parsed.command ? (
|
|
285
|
+
<div className="rounded bg-agent-muted/50 px-2 py-1.5">
|
|
286
|
+
<div className="flex items-start justify-between gap-2">
|
|
287
|
+
<pre className="max-h-32 min-w-0 flex-1 overflow-y-auto whitespace-pre-wrap break-words font-mono text-[11px] text-agent-foreground">
|
|
288
|
+
{isSnippet ? parsed.command : `$ ${parsed.command}`}
|
|
289
|
+
</pre>
|
|
290
|
+
<div className="flex shrink-0 items-center gap-1.5">
|
|
291
|
+
{parsed.language ? (
|
|
292
|
+
<span className="rounded bg-agent-muted px-1 py-0.5 font-mono text-[10px] text-agent-muted-foreground">
|
|
293
|
+
{parsed.language}
|
|
294
|
+
</span>
|
|
295
|
+
) : null}
|
|
296
|
+
<CopySnippetButton text={parsed.command} label={t('Copy command')} />
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
{metaParts.length > 0 ? (
|
|
300
|
+
<div
|
|
301
|
+
className="mt-1 truncate font-mono text-[10px] text-agent-muted-foreground"
|
|
302
|
+
title={metaParts.join(' · ')}
|
|
303
|
+
>
|
|
304
|
+
{metaParts.join(' · ')}
|
|
305
|
+
</div>
|
|
306
|
+
) : null}
|
|
307
|
+
</div>
|
|
308
|
+
) : null}
|
|
309
|
+
{parsed.settled ? (
|
|
310
|
+
<section className="space-y-1">
|
|
311
|
+
<div className="flex items-center justify-between gap-2">
|
|
312
|
+
<div className="flex items-center gap-1.5">
|
|
313
|
+
<span className="text-[10px] uppercase tracking-wider text-agent-muted-foreground">
|
|
314
|
+
{t('Output')}
|
|
315
|
+
</span>
|
|
316
|
+
{parsed.exitCode !== null && parsed.exitCode !== 0 ? (
|
|
317
|
+
<span className="rounded bg-rose-500/10 px-1.5 py-0.5 font-mono text-[10px] text-rose-700">
|
|
318
|
+
{t('Exit code {code}', { code: parsed.exitCode })}
|
|
319
|
+
</span>
|
|
320
|
+
) : null}
|
|
321
|
+
</div>
|
|
322
|
+
{combinedOutput ? (
|
|
323
|
+
<CopySnippetButton text={combinedOutput} label={t('Copy output')} />
|
|
324
|
+
) : null}
|
|
325
|
+
</div>
|
|
326
|
+
{parsed.stdout ? <MiddleTruncatedPre text={parsed.stdout} /> : null}
|
|
327
|
+
{parsed.stderr ? <MiddleTruncatedPre text={parsed.stderr} tone="error" /> : null}
|
|
328
|
+
{parsed.error ? <MiddleTruncatedPre text={parsed.error} tone="error" /> : null}
|
|
329
|
+
{!parsed.stdout && !parsed.stderr && !parsed.error ? (
|
|
330
|
+
<div className="text-[11px] italic text-agent-muted-foreground">
|
|
331
|
+
{t('(No output)')}
|
|
332
|
+
</div>
|
|
333
|
+
) : null}
|
|
334
|
+
</section>
|
|
335
|
+
) : null}
|
|
336
|
+
</div>
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function MergedReadDetails({ actions }: { actions: readonly ExecutedAction[] }) {
|
|
341
|
+
return (
|
|
342
|
+
<div className="space-y-2 text-[11px]" data-testid="merged-read-details">
|
|
343
|
+
{actions.map((action, idx) => {
|
|
344
|
+
const term = parseTerminalExecution(action);
|
|
345
|
+
const env = parseToolEnvelope(action.result);
|
|
346
|
+
const args =
|
|
347
|
+
action.arguments && typeof action.arguments === 'object'
|
|
348
|
+
? (action.arguments as Record<string, unknown>)
|
|
349
|
+
: null;
|
|
350
|
+
const header =
|
|
351
|
+
(typeof args?.path === 'string' && args.path) ||
|
|
352
|
+
(typeof args?.file === 'string' && args.file) ||
|
|
353
|
+
term.command ||
|
|
354
|
+
action.tool;
|
|
355
|
+
const body =
|
|
356
|
+
term.stdout ||
|
|
357
|
+
(typeof env.fields.content === 'string' ? env.fields.content : '') ||
|
|
358
|
+
env.message ||
|
|
359
|
+
'';
|
|
360
|
+
return (
|
|
361
|
+
<section key={action.id ?? `${header}-${idx}`} className="space-y-1">
|
|
362
|
+
<div className="font-mono text-[10px] font-medium text-agent-muted-foreground">
|
|
363
|
+
{header}
|
|
364
|
+
</div>
|
|
365
|
+
{body ? <MiddleTruncatedPre text={body} /> : null}
|
|
366
|
+
</section>
|
|
367
|
+
);
|
|
368
|
+
})}
|
|
369
|
+
</div>
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function toolProgressNote(action: ExecutedAction, quietSuccess: boolean): string | undefined {
|
|
374
|
+
const status = deriveStatus(action);
|
|
375
|
+
const parts: string[] = [];
|
|
376
|
+
if (
|
|
377
|
+
quietSuccess &&
|
|
378
|
+
status === 'succeeded' &&
|
|
379
|
+
typeof action.durationMs === 'number' &&
|
|
380
|
+
action.durationMs >= SLOW_TOOL_THRESHOLD_MS
|
|
381
|
+
) {
|
|
382
|
+
parts.push(formatSlowDuration(action.durationMs));
|
|
141
383
|
}
|
|
142
|
-
if (action.approval?.
|
|
143
|
-
|
|
384
|
+
if (action.approval?.kind === 'allow_for_session' && action.approval.cached === true) {
|
|
385
|
+
parts.push(t('Allowed for this chat'));
|
|
386
|
+
} else if (
|
|
387
|
+
action.tool === 'ask_user' &&
|
|
388
|
+
askReplay(action.result)?.unattended &&
|
|
389
|
+
status !== 'failed'
|
|
390
|
+
) {
|
|
391
|
+
parts.push(t('Answered automatically'));
|
|
392
|
+
} else if (action.approval?.auto === true && status !== 'failed') {
|
|
393
|
+
parts.push(t('Auto'));
|
|
144
394
|
}
|
|
145
|
-
return undefined;
|
|
395
|
+
return parts.length > 0 ? parts.join(' · ') : undefined;
|
|
146
396
|
}
|
|
147
397
|
|
|
148
|
-
function actionToTool(
|
|
398
|
+
function actionToTool(
|
|
399
|
+
action: ExecutedAction,
|
|
400
|
+
idx: number,
|
|
401
|
+
summary: string | null,
|
|
402
|
+
): ToolExecutionPayload {
|
|
149
403
|
const status = deriveStatus(action);
|
|
150
404
|
const env = parseToolEnvelope(action.result);
|
|
151
405
|
const errorText =
|
|
@@ -154,29 +408,11 @@ function actionToTool(action: ExecutedAction, idx: number): ToolExecutionPayload
|
|
|
154
408
|
? humanizeDelegateError(env.error)
|
|
155
409
|
: env.error
|
|
156
410
|
: null;
|
|
157
|
-
// 追问行用第一条问题。出网行用主机名。已保存的 view.title 往往只是开场白或工具名。
|
|
158
|
-
const asked = askRowSummary(action);
|
|
159
|
-
const egress = egressRowSummary(action);
|
|
160
|
-
// 声明过的工具用 view.title。没有 view 的旧事件仍按工具名做摘要。
|
|
161
|
-
const summary = asked
|
|
162
|
-
|| egress
|
|
163
|
-
|| (action.view?.declared
|
|
164
|
-
? action.view.title
|
|
165
|
-
: ((action.tool === 'delegate_subagent'
|
|
166
|
-
? summarizeDelegateSubagent(action.arguments)
|
|
167
|
-
: null) ??
|
|
168
|
-
(isTaskFamilyTool(action.tool)
|
|
169
|
-
? summarizeTaskAction(action.tool, action.arguments, action.result)
|
|
170
|
-
: null) ??
|
|
171
|
-
summarizeRunCodeAction(action.tool, action.arguments, action.result) ??
|
|
172
|
-
summarizeWebAction(action.tool, action.arguments, action.result) ??
|
|
173
|
-
summarizeArguments(action.arguments)));
|
|
174
|
-
const badge = sandboxBadge(action.sandbox);
|
|
175
411
|
return {
|
|
176
412
|
id: action.id ?? `${action.tool}-${idx}`,
|
|
177
413
|
name: action.tool,
|
|
178
414
|
status,
|
|
179
|
-
summary
|
|
415
|
+
summary,
|
|
180
416
|
args: action.arguments,
|
|
181
417
|
output: action.result,
|
|
182
418
|
error: errorText,
|
|
@@ -186,11 +422,6 @@ function actionToTool(action: ExecutedAction, idx: number): ToolExecutionPayload
|
|
|
186
422
|
};
|
|
187
423
|
}
|
|
188
424
|
|
|
189
|
-
/**
|
|
190
|
-
* renderOutput slot for ToolExecutionCard: when a tool result carries a
|
|
191
|
-
* unified `diff` (local_edit_file), render it as a coloured diff; otherwise
|
|
192
|
-
* fall back to the default JSON/text view.
|
|
193
|
-
*/
|
|
194
425
|
function renderAskOutput(output: unknown): ReactNode {
|
|
195
426
|
const replay = askReplay(output);
|
|
196
427
|
if (!replay) return renderActionOutput(output);
|
|
@@ -206,32 +437,37 @@ function renderAskOutput(output: unknown): ReactNode {
|
|
|
206
437
|
}
|
|
207
438
|
|
|
208
439
|
function renderActionOutput(output: unknown): ReactNode {
|
|
209
|
-
if (output
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
440
|
+
if (output === undefined || output === null) return null;
|
|
441
|
+
const unwrapped = parseJsonValue(output);
|
|
442
|
+
if (unwrapped && typeof unwrapped === 'object' && !Array.isArray(unwrapped)) {
|
|
443
|
+
const obj = unwrapped as Record<string, unknown>;
|
|
444
|
+
const dataObj =
|
|
445
|
+
obj.data && typeof obj.data === 'object' && !Array.isArray(obj.data)
|
|
446
|
+
? (obj.data as Record<string, unknown>)
|
|
447
|
+
: null;
|
|
448
|
+
const diff =
|
|
449
|
+
typeof obj.diff === 'string' && obj.diff.length > 0
|
|
450
|
+
? obj.diff
|
|
451
|
+
: typeof dataObj?.diff === 'string' && dataObj.diff.length > 0
|
|
452
|
+
? dataObj.diff
|
|
453
|
+
: null;
|
|
454
|
+
if (diff) {
|
|
455
|
+
return <UnifiedDiff diff={diff} />;
|
|
456
|
+
}
|
|
457
|
+
const contentText =
|
|
458
|
+
typeof dataObj?.content === 'string'
|
|
459
|
+
? dataObj.content
|
|
460
|
+
: typeof obj.content === 'string'
|
|
461
|
+
? obj.content
|
|
462
|
+
: typeof obj.output === 'string'
|
|
463
|
+
? obj.output
|
|
464
|
+
: null;
|
|
465
|
+
if (contentText) {
|
|
466
|
+
return <MiddleTruncatedPre text={contentText} />;
|
|
226
467
|
}
|
|
227
468
|
}
|
|
228
|
-
if (output === undefined || output === null) return null;
|
|
229
469
|
const text = typeof output === 'string' ? output : JSON.stringify(output, null, 2);
|
|
230
|
-
return
|
|
231
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5 text-[11px] text-agent-foreground">
|
|
232
|
-
{text}
|
|
233
|
-
</pre>
|
|
234
|
-
);
|
|
470
|
+
return <MiddleTruncatedPre text={text} />;
|
|
235
471
|
}
|
|
236
472
|
|
|
237
473
|
const BUILTIN_DELEGATE_COLORS: Record<string, string> = {
|
|
@@ -272,6 +508,16 @@ function DelegateLead({
|
|
|
272
508
|
);
|
|
273
509
|
}
|
|
274
510
|
|
|
511
|
+
function CardLeadIcon({
|
|
512
|
+
icon: Icon,
|
|
513
|
+
className = 'text-agent-muted-foreground',
|
|
514
|
+
}: {
|
|
515
|
+
icon: ComponentType<{ className?: string }>;
|
|
516
|
+
className?: string;
|
|
517
|
+
}) {
|
|
518
|
+
return <Icon className={`h-3 w-3 shrink-0 ${className}`} />;
|
|
519
|
+
}
|
|
520
|
+
|
|
275
521
|
function renderDelegateArgs(
|
|
276
522
|
args: unknown,
|
|
277
523
|
agents: ReadonlyArray<Pick<LocalChatAgent, 'id' | 'slug' | 'name' | 'color'>>,
|
|
@@ -279,12 +525,11 @@ function renderDelegateArgs(
|
|
|
279
525
|
const { profile, task } = parseDelegateSubagent(args);
|
|
280
526
|
if (!profile && !task) {
|
|
281
527
|
return (
|
|
282
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5 text-[11px] text-agent-foreground">
|
|
528
|
+
<pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5 text-[11px] text-agent-foreground">
|
|
283
529
|
{typeof args === 'string' ? args : JSON.stringify(args, null, 2)}
|
|
284
530
|
</pre>
|
|
285
531
|
);
|
|
286
532
|
}
|
|
287
|
-
// 自建智能体没有 slug 时画像名是 `agent-<id 片段>`,对用户无意义——出中文名。
|
|
288
533
|
const displayName = delegateSubagentDisplayName(profile, agents);
|
|
289
534
|
return (
|
|
290
535
|
<div className="space-y-1.5 text-[11px] text-agent-foreground">
|
|
@@ -301,7 +546,7 @@ function renderDelegateArgs(
|
|
|
301
546
|
<div className="mb-0.5 text-[10px] uppercase tracking-wider text-agent-muted-foreground">
|
|
302
547
|
{t('Task')}
|
|
303
548
|
</div>
|
|
304
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
549
|
+
<pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
305
550
|
{task}
|
|
306
551
|
</pre>
|
|
307
552
|
</section>
|
|
@@ -317,7 +562,7 @@ function renderDelegateOutput(output: unknown): ReactNode {
|
|
|
317
562
|
<div className="space-y-1.5">
|
|
318
563
|
{kvBlock(
|
|
319
564
|
t('Report'),
|
|
320
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
565
|
+
<pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
321
566
|
{env.message}
|
|
322
567
|
</pre>,
|
|
323
568
|
)}
|
|
@@ -371,7 +616,7 @@ function renderTaskArgs(tool: string, args: unknown): ReactNode {
|
|
|
371
616
|
{parsed.task
|
|
372
617
|
? kvBlock(
|
|
373
618
|
t('Task'),
|
|
374
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
619
|
+
<pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
375
620
|
{parsed.task}
|
|
376
621
|
</pre>,
|
|
377
622
|
)
|
|
@@ -400,7 +645,7 @@ function renderTaskArgs(tool: string, args: unknown): ReactNode {
|
|
|
400
645
|
{message
|
|
401
646
|
? kvBlock(
|
|
402
647
|
t('Message'),
|
|
403
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
648
|
+
<pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
404
649
|
{message}
|
|
405
650
|
</pre>,
|
|
406
651
|
)
|
|
@@ -428,7 +673,7 @@ function renderTaskOutput(output: unknown): ReactNode {
|
|
|
428
673
|
{item.task
|
|
429
674
|
? kvBlock(
|
|
430
675
|
t('Task'),
|
|
431
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
676
|
+
<pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
432
677
|
{item.task}
|
|
433
678
|
</pre>,
|
|
434
679
|
)
|
|
@@ -438,7 +683,7 @@ function renderTaskOutput(output: unknown): ReactNode {
|
|
|
438
683
|
{item.answer
|
|
439
684
|
? kvBlock(
|
|
440
685
|
t('Result'),
|
|
441
|
-
<pre className="whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
686
|
+
<pre className="max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-agent-muted/40 px-2 py-1.5">
|
|
442
687
|
{item.answer}
|
|
443
688
|
</pre>,
|
|
444
689
|
)
|
|
@@ -453,37 +698,320 @@ function renderTaskOutput(output: unknown): ReactNode {
|
|
|
453
698
|
);
|
|
454
699
|
}
|
|
455
700
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
): {
|
|
701
|
+
const CODE_SUMMARY_CLASS = 'font-mono text-[11px] text-agent-foreground';
|
|
702
|
+
|
|
703
|
+
interface ResolvedActionPresentation {
|
|
460
704
|
label?: string;
|
|
461
705
|
lead?: ReactNode;
|
|
706
|
+
summary: string | null;
|
|
707
|
+
tooltip?: string;
|
|
708
|
+
summaryClassName?: string;
|
|
709
|
+
trailingMeta?: ReactNode;
|
|
710
|
+
collapsedPreview?: (controls: { expand: () => void }, inTimeline: boolean) => ReactNode;
|
|
711
|
+
renderBody?: () => ReactNode;
|
|
462
712
|
renderArgs?: (args: unknown) => ReactNode;
|
|
463
713
|
renderOutput?: (output: unknown) => ReactNode;
|
|
464
|
-
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function resolveActionPresentation(
|
|
717
|
+
action: ExecutedAction,
|
|
718
|
+
agents: ReadonlyArray<Pick<LocalChatAgent, 'id' | 'slug' | 'name' | 'color'>>,
|
|
719
|
+
chatId: string | null | undefined,
|
|
720
|
+
): ResolvedActionPresentation {
|
|
721
|
+
const statusInfo = deriveActionStatusInfo(action);
|
|
722
|
+
const isRunning = statusInfo.status === 'running';
|
|
723
|
+
const defaultSummary = extractWebActionSummary(action);
|
|
724
|
+
|
|
465
725
|
if (action.tool === 'delegate_subagent') {
|
|
466
726
|
const { profile } = parseDelegateSubagent(action.arguments);
|
|
467
727
|
const displayName = delegateSubagentDisplayName(profile, agents);
|
|
468
728
|
return {
|
|
469
729
|
label: t('Delegate · {name}', { name: displayName }),
|
|
470
730
|
lead: <DelegateLead name={displayName} color={delegateColor(profile, agents)} />,
|
|
731
|
+
summary: defaultSummary.summary,
|
|
732
|
+
tooltip: defaultSummary.tooltip,
|
|
471
733
|
renderArgs: (args) => renderDelegateArgs(args, agents),
|
|
472
734
|
renderOutput: renderDelegateOutput,
|
|
473
735
|
};
|
|
474
736
|
}
|
|
475
|
-
|
|
476
|
-
return { renderOutput: renderAskOutput };
|
|
477
|
-
}
|
|
737
|
+
|
|
478
738
|
if (isTaskFamilyTool(action.tool)) {
|
|
479
739
|
return {
|
|
480
740
|
label: taskToolLabel(action.tool, action.arguments) ?? undefined,
|
|
481
741
|
lead: <TaskLead />,
|
|
742
|
+
summary: defaultSummary.summary,
|
|
743
|
+
tooltip: defaultSummary.tooltip,
|
|
482
744
|
renderArgs: (args) => renderTaskArgs(action.tool, args),
|
|
483
745
|
renderOutput: renderTaskOutput,
|
|
484
746
|
};
|
|
485
747
|
}
|
|
486
|
-
|
|
748
|
+
|
|
749
|
+
const skill = extractSkillInvocation(action);
|
|
750
|
+
if (skill) {
|
|
751
|
+
return {
|
|
752
|
+
label: t('Used skill'),
|
|
753
|
+
lead: <CardLeadIcon icon={LuSparkles} className="text-violet-600 dark:text-violet-400" />,
|
|
754
|
+
summary: skill.skillName,
|
|
755
|
+
tooltip: skill.path ?? skill.skillName,
|
|
756
|
+
summaryClassName: 'font-medium text-[11px] text-agent-foreground',
|
|
757
|
+
renderBody: skill.path
|
|
758
|
+
? () => (
|
|
759
|
+
<div className="font-mono text-[10px] text-agent-muted-foreground">
|
|
760
|
+
{skill.path}
|
|
761
|
+
</div>
|
|
762
|
+
)
|
|
763
|
+
: undefined,
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
const imgPreview = parseImageAction(action);
|
|
768
|
+
if (imgPreview) {
|
|
769
|
+
return {
|
|
770
|
+
label: imgPreview.isCapture
|
|
771
|
+
? t('Captured screenshot')
|
|
772
|
+
: isRunning
|
|
773
|
+
? t('Viewing image')
|
|
774
|
+
: t('Viewed image'),
|
|
775
|
+
lead: <CardLeadIcon icon={LuImage} />,
|
|
776
|
+
summary: imgPreview.displayName,
|
|
777
|
+
tooltip: imgPreview.path ?? imgPreview.displayName,
|
|
778
|
+
trailingMeta: <ImageTrailingMeta preview={imgPreview} />,
|
|
779
|
+
collapsedPreview: ({ expand }, inTimeline) => (
|
|
780
|
+
<ImageCollapsedPreview
|
|
781
|
+
preview={imgPreview}
|
|
782
|
+
chatId={chatId}
|
|
783
|
+
inTimeline={inTimeline}
|
|
784
|
+
onExpand={expand}
|
|
785
|
+
/>
|
|
786
|
+
),
|
|
787
|
+
renderBody: () => <ImageToolPreview preview={imgPreview} chatId={chatId} />,
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
const fileChange = extractFileChangePreview(action);
|
|
792
|
+
if (fileChange) {
|
|
793
|
+
return {
|
|
794
|
+
label: fileChange.isWrite
|
|
795
|
+
? isRunning
|
|
796
|
+
? t('Writing')
|
|
797
|
+
: t('Wrote')
|
|
798
|
+
: isRunning
|
|
799
|
+
? t('Editing')
|
|
800
|
+
: t('Edited'),
|
|
801
|
+
lead: <CardLeadIcon icon={LuFilePen} />,
|
|
802
|
+
summary: fileChange.path,
|
|
803
|
+
tooltip: fileChange.path,
|
|
804
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
805
|
+
trailingMeta: <FileChangeTrailingMeta preview={fileChange} />,
|
|
806
|
+
renderBody: () => <FileChangeDetailsView preview={fileChange} chatId={chatId} />,
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
const todoView = parseTodoWriteAction(action);
|
|
811
|
+
if (todoView) {
|
|
812
|
+
return {
|
|
813
|
+
label: t('Updated plan · {done}/{total} done', {
|
|
814
|
+
done: todoView.completedCount,
|
|
815
|
+
total: todoView.totalCount,
|
|
816
|
+
}),
|
|
817
|
+
lead: <CardLeadIcon icon={LuListTodo} />,
|
|
818
|
+
summary: todoView.activeContent,
|
|
819
|
+
tooltip: todoView.activeContent ?? undefined,
|
|
820
|
+
renderBody: () => <TodoChecklistView view={todoView} />,
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
if (action.tool === 'ask_user') {
|
|
825
|
+
const inline = askInlineSummary(action);
|
|
826
|
+
return {
|
|
827
|
+
label: t('Asked you'),
|
|
828
|
+
lead: <CardLeadIcon icon={LuMessageSquare} />,
|
|
829
|
+
summary: inline || defaultSummary.summary,
|
|
830
|
+
tooltip: inline || defaultSummary.tooltip,
|
|
831
|
+
renderOutput: renderAskOutput,
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
const memoryView = parseMemoryAction(action);
|
|
836
|
+
if (memoryView) {
|
|
837
|
+
const label =
|
|
838
|
+
memoryView.kind === 'search'
|
|
839
|
+
? t('Searched memory')
|
|
840
|
+
: memoryView.kind === 'read'
|
|
841
|
+
? t('Read memory')
|
|
842
|
+
: t('Saved memory');
|
|
843
|
+
return {
|
|
844
|
+
label,
|
|
845
|
+
lead: <CardLeadIcon icon={LuBrain} />,
|
|
846
|
+
summary: memoryView.summary,
|
|
847
|
+
tooltip: memoryView.summary,
|
|
848
|
+
renderBody: () => <MemoryDetailsView view={memoryView} />,
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
const webSearch = parseWebSearchAction(action);
|
|
853
|
+
if (webSearch) {
|
|
854
|
+
const queryLabel = webSearch.query ? `"${webSearch.query}"` : null;
|
|
855
|
+
return {
|
|
856
|
+
label: isRunning ? t('Searching the web') : t('Searched the web'),
|
|
857
|
+
lead: <CardLeadIcon icon={LuGlobe} />,
|
|
858
|
+
summary: queryLabel,
|
|
859
|
+
tooltip: webSearch.query || undefined,
|
|
860
|
+
trailingMeta:
|
|
861
|
+
webSearch.resultCount !== null ? (
|
|
862
|
+
<span className="text-[10px] tabular-nums text-agent-muted-foreground">
|
|
863
|
+
{t('{count} results', { count: webSearch.resultCount })}
|
|
864
|
+
</span>
|
|
865
|
+
) : undefined,
|
|
866
|
+
renderBody: () => <WebSearchResultsView view={webSearch} />,
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
const webFetch = parseWebFetchAction(action);
|
|
871
|
+
if (webFetch) {
|
|
872
|
+
return {
|
|
873
|
+
label: isRunning ? t('Reading page') : t('Read page'),
|
|
874
|
+
lead: <CardLeadIcon icon={LuGlobe} />,
|
|
875
|
+
summary: webFetch.displayTarget,
|
|
876
|
+
tooltip: webFetch.url ?? webFetch.displayTarget,
|
|
877
|
+
renderBody: () => <WebFetchDetailsView view={webFetch} />,
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if (statusInfo.classifiedShell) {
|
|
882
|
+
const classified = statusInfo.classifiedShell;
|
|
883
|
+
if (classified.kind === 'list') {
|
|
884
|
+
const target = classified.paths.join(', ');
|
|
885
|
+
return {
|
|
886
|
+
label: isRunning ? t('Listing files in') : t('Listed files in'),
|
|
887
|
+
lead: <CardLeadIcon icon={LuFolderOpen} />,
|
|
888
|
+
summary: target,
|
|
889
|
+
tooltip: classified.rawCommand,
|
|
890
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
891
|
+
renderBody: () => <TerminalExecutionDetails action={action} />,
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
if (classified.kind === 'read') {
|
|
895
|
+
const target = classified.files.join(', ');
|
|
896
|
+
return {
|
|
897
|
+
label: isRunning ? t('Reading') : t('Read'),
|
|
898
|
+
lead: <CardLeadIcon icon={LuFileText} />,
|
|
899
|
+
summary: target,
|
|
900
|
+
tooltip: classified.rawCommand,
|
|
901
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
902
|
+
renderBody: () => <TerminalExecutionDetails action={action} />,
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
if (classified.kind === 'search') {
|
|
906
|
+
const target = classified.query
|
|
907
|
+
? classified.path
|
|
908
|
+
? `${classified.query} (${classified.path})`
|
|
909
|
+
: classified.query
|
|
910
|
+
: classified.path ?? '.';
|
|
911
|
+
return {
|
|
912
|
+
label: isRunning ? t('Searching for') : t('Searched for'),
|
|
913
|
+
lead: <CardLeadIcon icon={LuSearch} />,
|
|
914
|
+
summary: target,
|
|
915
|
+
tooltip: classified.rawCommand,
|
|
916
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
917
|
+
trailingMeta: statusInfo.benignNoMatch ? (
|
|
918
|
+
<span className="text-[10px] text-agent-muted-foreground">{t('no matches')}</span>
|
|
919
|
+
) : undefined,
|
|
920
|
+
renderBody: () => <TerminalExecutionDetails action={action} />,
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
const exitBadge =
|
|
924
|
+
statusInfo.status === 'failed' &&
|
|
925
|
+
statusInfo.terminal?.exitCode !== null &&
|
|
926
|
+
statusInfo.terminal?.exitCode !== undefined ? (
|
|
927
|
+
<span className="font-mono text-[10px] text-rose-600 dark:text-rose-400">
|
|
928
|
+
(exit {statusInfo.terminal.exitCode})
|
|
929
|
+
</span>
|
|
930
|
+
) : undefined;
|
|
931
|
+
const runText = classified.kind === 'run' ? classified.command : classified.rawCommand;
|
|
932
|
+
return {
|
|
933
|
+
label: isRunning ? t('Running') : t('Ran'),
|
|
934
|
+
lead: <CardLeadIcon icon={LuTerminal} />,
|
|
935
|
+
summary: runText || defaultSummary.summary,
|
|
936
|
+
tooltip: defaultSummary.tooltip ?? classified.rawCommand,
|
|
937
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
938
|
+
trailingMeta: exitBadge,
|
|
939
|
+
renderBody: () => <TerminalExecutionDetails action={action} />,
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
const card = resolveActionCard(action);
|
|
944
|
+
switch (card) {
|
|
945
|
+
case 'terminal': {
|
|
946
|
+
const term = parseTerminalExecution(action);
|
|
947
|
+
const pkgBadge =
|
|
948
|
+
term.packages && term.packages.length > 0 ? (
|
|
949
|
+
<span
|
|
950
|
+
data-testid="snippet-packages-badge"
|
|
951
|
+
className="rounded bg-agent-muted px-1.5 py-0.5 font-mono text-[10px] text-agent-muted-foreground"
|
|
952
|
+
title={term.packages.join(', ')}
|
|
953
|
+
>
|
|
954
|
+
+{term.packages.length === 1 ? term.packages[0] : `${term.packages[0]} +${term.packages.length - 1}`}
|
|
955
|
+
</span>
|
|
956
|
+
) : null;
|
|
957
|
+
return {
|
|
958
|
+
label:
|
|
959
|
+
action.tool === 'local_run_snippet'
|
|
960
|
+
? t('Run snippet')
|
|
961
|
+
: action.tool === 'local_run_script'
|
|
962
|
+
? t('Run script')
|
|
963
|
+
: isRunning
|
|
964
|
+
? t('Running')
|
|
965
|
+
: t('Ran'),
|
|
966
|
+
lead: (
|
|
967
|
+
<CardLeadIcon
|
|
968
|
+
icon={action.tool === 'local_run_snippet' ? LuFileCode : LuTerminal}
|
|
969
|
+
/>
|
|
970
|
+
),
|
|
971
|
+
summary: defaultSummary.summary,
|
|
972
|
+
tooltip: defaultSummary.tooltip,
|
|
973
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
974
|
+
trailingMeta: pkgBadge,
|
|
975
|
+
renderBody: () => <TerminalExecutionDetails action={action} />,
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
case 'read':
|
|
979
|
+
return {
|
|
980
|
+
label: isRunning ? t('Reading') : t('Read'),
|
|
981
|
+
lead: <CardLeadIcon icon={LuFileText} />,
|
|
982
|
+
summary: defaultSummary.summary,
|
|
983
|
+
tooltip: defaultSummary.tooltip,
|
|
984
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
985
|
+
renderOutput: renderActionOutput,
|
|
986
|
+
};
|
|
987
|
+
case 'diff':
|
|
988
|
+
return {
|
|
989
|
+
label:
|
|
990
|
+
action.tool === 'local_write_file' || action.tool === 'write_file'
|
|
991
|
+
? t('Wrote')
|
|
992
|
+
: t('Edited'),
|
|
993
|
+
lead: <CardLeadIcon icon={LuFilePen} />,
|
|
994
|
+
summary: defaultSummary.summary,
|
|
995
|
+
tooltip: defaultSummary.tooltip,
|
|
996
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
997
|
+
renderOutput: renderActionOutput,
|
|
998
|
+
};
|
|
999
|
+
case 'search':
|
|
1000
|
+
return {
|
|
1001
|
+
label: isRunning ? t('Searching for') : t('Searched for'),
|
|
1002
|
+
lead: <CardLeadIcon icon={LuSearch} />,
|
|
1003
|
+
summary: defaultSummary.summary,
|
|
1004
|
+
tooltip: defaultSummary.tooltip,
|
|
1005
|
+
summaryClassName: CODE_SUMMARY_CLASS,
|
|
1006
|
+
renderOutput: renderActionOutput,
|
|
1007
|
+
};
|
|
1008
|
+
default:
|
|
1009
|
+
return {
|
|
1010
|
+
summary: defaultSummary.summary,
|
|
1011
|
+
tooltip: defaultSummary.tooltip,
|
|
1012
|
+
renderOutput: renderActionOutput,
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
487
1015
|
}
|
|
488
1016
|
|
|
489
1017
|
function inspectActivate(
|
|
@@ -516,7 +1044,7 @@ function inspectActivate(
|
|
|
516
1044
|
};
|
|
517
1045
|
}
|
|
518
1046
|
|
|
519
|
-
/**
|
|
1047
|
+
/** Pair each delegate_subagent row with its matching child lifecycle in appearance order. */
|
|
520
1048
|
function delegationChildren(
|
|
521
1049
|
actions: readonly ExecutedAction[],
|
|
522
1050
|
children: readonly ChildInfo[],
|
|
@@ -538,6 +1066,142 @@ function delegationChildren(
|
|
|
538
1066
|
return paired;
|
|
539
1067
|
}
|
|
540
1068
|
|
|
1069
|
+
function renderDisplayRow({
|
|
1070
|
+
row,
|
|
1071
|
+
inTimeline,
|
|
1072
|
+
allActions,
|
|
1073
|
+
defaultExpanded,
|
|
1074
|
+
labels,
|
|
1075
|
+
agents,
|
|
1076
|
+
chatId,
|
|
1077
|
+
onInspectTask,
|
|
1078
|
+
childByIndex,
|
|
1079
|
+
}: {
|
|
1080
|
+
row: DisplayActionRow<ExecutedAction>;
|
|
1081
|
+
inTimeline: boolean;
|
|
1082
|
+
allActions: readonly ExecutedAction[];
|
|
1083
|
+
defaultExpanded: boolean;
|
|
1084
|
+
labels: ToolExecutionCardLabels;
|
|
1085
|
+
agents: ReadonlyArray<Pick<LocalChatAgent, 'id' | 'slug' | 'name' | 'color'>>;
|
|
1086
|
+
chatId: string | null | undefined;
|
|
1087
|
+
onInspectTask?: (task: InspectTaskInput) => void;
|
|
1088
|
+
childByIndex: ReadonlyMap<number, ChildInfo>;
|
|
1089
|
+
}) {
|
|
1090
|
+
if (row.kind === 'merged-read') {
|
|
1091
|
+
const joined = row.files.join(', ');
|
|
1092
|
+
const payload: ToolExecutionPayload = {
|
|
1093
|
+
id: `merged-read-${row.firstIndex}`,
|
|
1094
|
+
name: 'local_read_file',
|
|
1095
|
+
status: 'succeeded',
|
|
1096
|
+
summary: joined,
|
|
1097
|
+
args: null,
|
|
1098
|
+
output: null,
|
|
1099
|
+
error: null,
|
|
1100
|
+
durationMs: null,
|
|
1101
|
+
icon: null,
|
|
1102
|
+
expandable: true,
|
|
1103
|
+
};
|
|
1104
|
+
return (
|
|
1105
|
+
<ToolExecutionCard
|
|
1106
|
+
key={payload.id}
|
|
1107
|
+
payload={payload}
|
|
1108
|
+
defaultExpanded={defaultExpanded}
|
|
1109
|
+
variant={inTimeline ? 'ghost' : 'embedded'}
|
|
1110
|
+
compactStatus={!inTimeline}
|
|
1111
|
+
quietSuccess={inTimeline}
|
|
1112
|
+
labels={labels}
|
|
1113
|
+
label={t('Read')}
|
|
1114
|
+
lead={<CardLeadIcon icon={LuFileText} />}
|
|
1115
|
+
summaryClassName={CODE_SUMMARY_CLASS}
|
|
1116
|
+
summaryTitle={joined}
|
|
1117
|
+
renderBody={() => <MergedReadDetails actions={row.actions} />}
|
|
1118
|
+
/>
|
|
1119
|
+
);
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
const { action, originalIndex } = row;
|
|
1123
|
+
const pres = resolveActionPresentation(action, agents, chatId);
|
|
1124
|
+
const inspect = inspectActivate(action, chatId, onInspectTask, childByIndex.get(originalIndex));
|
|
1125
|
+
const showSandbox = inTimeline
|
|
1126
|
+
? shouldShowInlineSandboxPill(action)
|
|
1127
|
+
: shouldShowSandboxBadge(allActions, originalIndex);
|
|
1128
|
+
const inlineBadge =
|
|
1129
|
+
(showSandbox && action.sandbox) || action.approval ? (
|
|
1130
|
+
<>
|
|
1131
|
+
{showSandbox && action.sandbox ? <SandboxPill sandbox={action.sandbox} /> : null}
|
|
1132
|
+
{action.approval ? <ApprovalPill approval={action.approval} /> : null}
|
|
1133
|
+
</>
|
|
1134
|
+
) : undefined;
|
|
1135
|
+
|
|
1136
|
+
return (
|
|
1137
|
+
<ToolExecutionCard
|
|
1138
|
+
key={action.id ?? `${action.tool}-${originalIndex}`}
|
|
1139
|
+
payload={actionToTool(action, originalIndex, pres.summary)}
|
|
1140
|
+
defaultExpanded={defaultExpanded}
|
|
1141
|
+
variant={inTimeline ? 'ghost' : 'embedded'}
|
|
1142
|
+
compactStatus={!inTimeline}
|
|
1143
|
+
quietSuccess={inTimeline}
|
|
1144
|
+
labels={labels}
|
|
1145
|
+
label={pres.label}
|
|
1146
|
+
lead={pres.lead}
|
|
1147
|
+
badge={inlineBadge}
|
|
1148
|
+
trailingMeta={pres.trailingMeta}
|
|
1149
|
+
summaryClassName={pres.summaryClassName}
|
|
1150
|
+
summaryTitle={pres.tooltip}
|
|
1151
|
+
collapsedPreview={
|
|
1152
|
+
pres.collapsedPreview
|
|
1153
|
+
? (controls) => pres.collapsedPreview!(controls, inTimeline)
|
|
1154
|
+
: undefined
|
|
1155
|
+
}
|
|
1156
|
+
renderBody={pres.renderBody}
|
|
1157
|
+
renderArgs={pres.renderArgs}
|
|
1158
|
+
renderOutput={pres.renderOutput ?? renderActionOutput}
|
|
1159
|
+
onActivate={inspect.onActivate}
|
|
1160
|
+
activateTitle={inspect.activateTitle}
|
|
1161
|
+
note={toolProgressNote(action, inTimeline)}
|
|
1162
|
+
/>
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
function TimelineFoldGroup({
|
|
1167
|
+
summary,
|
|
1168
|
+
isSearchOnly,
|
|
1169
|
+
defaultExpanded,
|
|
1170
|
+
children,
|
|
1171
|
+
}: {
|
|
1172
|
+
summary: string;
|
|
1173
|
+
isSearchOnly: boolean;
|
|
1174
|
+
defaultExpanded: boolean;
|
|
1175
|
+
children: ReactNode;
|
|
1176
|
+
}) {
|
|
1177
|
+
const [open, setOpen] = useState(defaultExpanded);
|
|
1178
|
+
return (
|
|
1179
|
+
<div className="space-y-0.5">
|
|
1180
|
+
<button
|
|
1181
|
+
type="button"
|
|
1182
|
+
onClick={() => setOpen((v) => !v)}
|
|
1183
|
+
aria-expanded={open}
|
|
1184
|
+
data-testid="tool-group-fold"
|
|
1185
|
+
className="inline-flex max-w-full cursor-pointer items-center gap-1.5 rounded-md px-1.5 py-0.5 text-left text-xs text-agent-muted-foreground transition-colors hover:bg-agent-muted/55 hover:text-agent-foreground"
|
|
1186
|
+
>
|
|
1187
|
+
{open ? (
|
|
1188
|
+
<LuChevronDown className="h-3 w-3 shrink-0" />
|
|
1189
|
+
) : isSearchOnly ? (
|
|
1190
|
+
<LuSearch className="h-3 w-3 shrink-0" />
|
|
1191
|
+
) : (
|
|
1192
|
+
<LuChevronRight className="h-3 w-3 shrink-0" />
|
|
1193
|
+
)}
|
|
1194
|
+
<span className="truncate">{summary}</span>
|
|
1195
|
+
</button>
|
|
1196
|
+
{open ? (
|
|
1197
|
+
<div className="ml-3 space-y-0.5 border-l border-agent-border/50 pl-2">
|
|
1198
|
+
{children}
|
|
1199
|
+
</div>
|
|
1200
|
+
) : null}
|
|
1201
|
+
</div>
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
541
1205
|
/** Inline tool rows for a mixed think→act timeline (no summary banner). */
|
|
542
1206
|
export function ToolsFlow({
|
|
543
1207
|
actions,
|
|
@@ -547,54 +1211,101 @@ export function ToolsFlow({
|
|
|
547
1211
|
chatId = null,
|
|
548
1212
|
onInspectTask,
|
|
549
1213
|
orchestrationChildren = [],
|
|
1214
|
+
deliveredFilePaths = null,
|
|
550
1215
|
}: ExecutedActionsCardProps) {
|
|
551
1216
|
if (!actions || actions.length === 0) return null;
|
|
552
|
-
const expanded =
|
|
1217
|
+
const expanded = filterRedundantPresentFiles(
|
|
1218
|
+
expandRunCodeActions(actions),
|
|
1219
|
+
deliveredFilePaths,
|
|
1220
|
+
);
|
|
1221
|
+
if (expanded.length === 0) return null;
|
|
1222
|
+
|
|
553
1223
|
const childByIndex = delegationChildren(expanded, orchestrationChildren);
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
1224
|
+
const labels = localizedCardLabels();
|
|
1225
|
+
|
|
1226
|
+
if (compact) {
|
|
1227
|
+
const segments = segmentTimelineToolRows(expanded);
|
|
1228
|
+
return (
|
|
1229
|
+
<div className="space-y-0.5" data-testid="tools-flow-ghost">
|
|
1230
|
+
{segments.map((segment, segIdx) => {
|
|
1231
|
+
if (segment.kind === 'fold-group') {
|
|
1232
|
+
return (
|
|
1233
|
+
<TimelineFoldGroup
|
|
1234
|
+
key={`fold-${segIdx}`}
|
|
1235
|
+
summary={segment.summary}
|
|
1236
|
+
isSearchOnly={segment.isSearchOnly}
|
|
1237
|
+
defaultExpanded={defaultExpanded}
|
|
1238
|
+
>
|
|
1239
|
+
{segment.rows.map((row) =>
|
|
1240
|
+
renderDisplayRow({
|
|
1241
|
+
row,
|
|
1242
|
+
inTimeline: true,
|
|
1243
|
+
allActions: expanded,
|
|
1244
|
+
defaultExpanded,
|
|
1245
|
+
labels,
|
|
1246
|
+
agents,
|
|
1247
|
+
chatId,
|
|
1248
|
+
onInspectTask,
|
|
1249
|
+
childByIndex,
|
|
1250
|
+
}),
|
|
1251
|
+
)}
|
|
1252
|
+
</TimelineFoldGroup>
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
return renderDisplayRow({
|
|
1256
|
+
row: segment.row,
|
|
1257
|
+
inTimeline: true,
|
|
1258
|
+
allActions: expanded,
|
|
1259
|
+
defaultExpanded,
|
|
1260
|
+
labels,
|
|
1261
|
+
agents,
|
|
1262
|
+
chatId,
|
|
1263
|
+
onInspectTask,
|
|
1264
|
+
childByIndex,
|
|
1265
|
+
});
|
|
581
1266
|
})}
|
|
582
1267
|
</div>
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
return (
|
|
1272
|
+
<div className="my-2 overflow-hidden rounded-agent-md border border-agent-border bg-agent-canvas">
|
|
1273
|
+
{expanded.map((action, i) =>
|
|
1274
|
+
renderDisplayRow({
|
|
1275
|
+
row: { kind: 'single', action, originalIndex: i },
|
|
1276
|
+
inTimeline: false,
|
|
1277
|
+
allActions: expanded,
|
|
1278
|
+
defaultExpanded,
|
|
1279
|
+
labels,
|
|
1280
|
+
agents,
|
|
1281
|
+
chatId,
|
|
1282
|
+
onInspectTask,
|
|
1283
|
+
childByIndex,
|
|
1284
|
+
}),
|
|
1285
|
+
)}
|
|
583
1286
|
</div>
|
|
584
1287
|
);
|
|
585
1288
|
}
|
|
586
1289
|
|
|
587
1290
|
export function ExecutedActionsCard({
|
|
588
1291
|
actions,
|
|
1292
|
+
defaultExpanded = false,
|
|
589
1293
|
agents = [],
|
|
590
1294
|
chatId = null,
|
|
591
1295
|
onInspectTask,
|
|
592
1296
|
orchestrationChildren = [],
|
|
1297
|
+
deliveredFilePaths = null,
|
|
593
1298
|
}: ExecutedActionsCardProps) {
|
|
594
1299
|
if (!actions || actions.length === 0) return null;
|
|
595
1300
|
|
|
596
|
-
const expanded =
|
|
1301
|
+
const expanded = filterRedundantPresentFiles(
|
|
1302
|
+
expandRunCodeActions(actions),
|
|
1303
|
+
deliveredFilePaths,
|
|
1304
|
+
);
|
|
1305
|
+
if (expanded.length === 0) return null;
|
|
1306
|
+
|
|
597
1307
|
const childByIndex = delegationChildren(expanded, orchestrationChildren);
|
|
1308
|
+
const labels = localizedCardLabels();
|
|
598
1309
|
const successCount = expanded.filter((a) => deriveStatus(a) === 'succeeded').length;
|
|
599
1310
|
const failureCount = expanded.filter((a) => deriveStatus(a) === 'failed').length;
|
|
600
1311
|
const runningCount = expanded.filter((a) => deriveStatus(a) === 'running').length;
|
|
@@ -623,25 +1334,20 @@ export function ExecutedActionsCard({
|
|
|
623
1334
|
: t('All succeeded')}
|
|
624
1335
|
</span>
|
|
625
1336
|
</div>
|
|
626
|
-
<div
|
|
627
|
-
{expanded.map((action, i) =>
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
note={toolProgressNote(action)}
|
|
641
|
-
className="rounded-none border-0 border-t border-agent-border first:border-t-0"
|
|
642
|
-
/>
|
|
643
|
-
);
|
|
644
|
-
})}
|
|
1337
|
+
<div>
|
|
1338
|
+
{expanded.map((action, i) =>
|
|
1339
|
+
renderDisplayRow({
|
|
1340
|
+
row: { kind: 'single', action, originalIndex: i },
|
|
1341
|
+
inTimeline: false,
|
|
1342
|
+
allActions: expanded,
|
|
1343
|
+
defaultExpanded,
|
|
1344
|
+
labels,
|
|
1345
|
+
agents,
|
|
1346
|
+
chatId,
|
|
1347
|
+
onInspectTask,
|
|
1348
|
+
childByIndex,
|
|
1349
|
+
}),
|
|
1350
|
+
)}
|
|
645
1351
|
</div>
|
|
646
1352
|
</div>
|
|
647
1353
|
);
|