@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.
@@ -0,0 +1,666 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import {
3
+ LuCheck,
4
+ LuCircle,
5
+ LuCircleDot,
6
+ LuCircleSlash,
7
+ LuExternalLink,
8
+ LuImage,
9
+ } from 'react-icons/lu';
10
+ import { getLocalFileDownload, openLocalPath, resolveLocalPaths } from '@/lib/local-api';
11
+ import { hostToolCapability, hostToolChrome } from '@/lib/host-tools';
12
+ import { t } from '@/i18n';
13
+ import { UnifiedDiff } from './UnifiedDiff';
14
+ import {
15
+ parseImageAction,
16
+ truncateOutputMiddle,
17
+ type ExecutedActionLike,
18
+ type FileChangePreview,
19
+ type ImageActionPreview,
20
+ type MemoryActionView,
21
+ type TodoWriteActionView,
22
+ type WebFetchActionView,
23
+ type WebSearchActionView,
24
+ } from './executed-actions-model';
25
+
26
+ const MAX_IMAGE_CACHE_ENTRIES = 64;
27
+ const imageDataUrlCache = new Map<string, string>();
28
+ const resolvedPathCache = new Map<string, string>();
29
+ const inflightLoads = new Map<string, Promise<{ dataUrl: string | null; resolvedPath: string | null }>>();
30
+
31
+ function putLru<K, V>(map: Map<K, V>, key: K, value: V, limit: number): void {
32
+ if (map.has(key)) map.delete(key);
33
+ map.set(key, value);
34
+ if (map.size > limit) {
35
+ const oldest = map.keys().next().value;
36
+ if (oldest !== undefined) map.delete(oldest);
37
+ }
38
+ }
39
+
40
+ export function clearLocalImageCacheForTests(): void {
41
+ imageDataUrlCache.clear();
42
+ resolvedPathCache.clear();
43
+ inflightLoads.clear();
44
+ }
45
+
46
+ function looksAbsolutePath(raw: string): boolean {
47
+ return raw.startsWith('/') || /^[A-Za-z]:[\\/]/.test(raw);
48
+ }
49
+
50
+ async function resolveTargetFilePath(rawPath: string, chatId?: string | null): Promise<string> {
51
+ if (looksAbsolutePath(rawPath)) return rawPath;
52
+ const cacheKey = `${chatId ?? ''}:${rawPath}`;
53
+ const cached = resolvedPathCache.get(cacheKey);
54
+ if (cached) return cached;
55
+ if (typeof resolveLocalPaths === 'function') {
56
+ try {
57
+ const res = await resolveLocalPaths([rawPath], chatId);
58
+ const hit = res?.resolved?.[0]?.path;
59
+ if (hit) {
60
+ putLru(resolvedPathCache, cacheKey, hit, MAX_IMAGE_CACHE_ENTRIES);
61
+ return hit;
62
+ }
63
+ } catch {
64
+ // Fall back to raw path when resolution endpoint is unavailable or mocked.
65
+ }
66
+ }
67
+ return rawPath;
68
+ }
69
+
70
+ async function loadLocalImage(
71
+ chatId: string,
72
+ rawPath: string,
73
+ ): Promise<{ dataUrl: string | null; resolvedPath: string | null }> {
74
+ const cacheKey = `${chatId}:${rawPath}`;
75
+ const cachedUrl = imageDataUrlCache.get(cacheKey);
76
+ if (cachedUrl) {
77
+ return {
78
+ dataUrl: cachedUrl,
79
+ resolvedPath: resolvedPathCache.get(cacheKey) ?? rawPath,
80
+ };
81
+ }
82
+ const existing = inflightLoads.get(cacheKey);
83
+ if (existing) return existing;
84
+
85
+ const task = (async () => {
86
+ try {
87
+ const targetPath = await resolveTargetFilePath(rawPath, chatId);
88
+ const downloaded = await getLocalFileDownload(chatId, targetPath);
89
+ if (!downloaded?.base64) return { dataUrl: null, resolvedPath: targetPath };
90
+ const mime =
91
+ downloaded.mime && downloaded.mime.startsWith('image/')
92
+ ? downloaded.mime
93
+ : 'image/png';
94
+ const dataUrl = `data:${mime};base64,${downloaded.base64}`;
95
+ putLru(imageDataUrlCache, cacheKey, dataUrl, MAX_IMAGE_CACHE_ENTRIES);
96
+ putLru(resolvedPathCache, cacheKey, targetPath, MAX_IMAGE_CACHE_ENTRIES);
97
+ return { dataUrl, resolvedPath: targetPath };
98
+ } catch {
99
+ return { dataUrl: null, resolvedPath: looksAbsolutePath(rawPath) ? rawPath : null };
100
+ } finally {
101
+ inflightLoads.delete(cacheKey);
102
+ }
103
+ })();
104
+
105
+ inflightLoads.set(cacheKey, task);
106
+ return task;
107
+ }
108
+
109
+ function useImagePreviewSource(
110
+ preview: ImageActionPreview,
111
+ chatId?: string | null,
112
+ ): { dataUrl: string | null; resolvedPath: string | null } {
113
+ const canReadLocal = hostToolCapability('local-fs');
114
+ const cacheKey = chatId && preview.path ? `${chatId}:${preview.path}` : null;
115
+ const [state, setState] = useState<{ dataUrl: string | null; resolvedPath: string | null }>(() => {
116
+ if (preview.inlineDataUrl) {
117
+ return { dataUrl: preview.inlineDataUrl, resolvedPath: preview.path };
118
+ }
119
+ if (cacheKey && imageDataUrlCache.has(cacheKey)) {
120
+ return {
121
+ dataUrl: imageDataUrlCache.get(cacheKey) ?? null,
122
+ resolvedPath: resolvedPathCache.get(cacheKey) ?? preview.path,
123
+ };
124
+ }
125
+ return { dataUrl: null, resolvedPath: preview.path };
126
+ });
127
+
128
+ useEffect(() => {
129
+ if (preview.inlineDataUrl) {
130
+ setState({ dataUrl: preview.inlineDataUrl, resolvedPath: preview.path });
131
+ return;
132
+ }
133
+ if (!chatId || !preview.path || !canReadLocal) return;
134
+ if (cacheKey && imageDataUrlCache.has(cacheKey)) {
135
+ setState({
136
+ dataUrl: imageDataUrlCache.get(cacheKey) ?? null,
137
+ resolvedPath: resolvedPathCache.get(cacheKey) ?? preview.path,
138
+ });
139
+ return;
140
+ }
141
+ let cancelled = false;
142
+ void loadLocalImage(chatId, preview.path).then((res) => {
143
+ if (!cancelled) setState(res);
144
+ });
145
+ return () => {
146
+ cancelled = true;
147
+ };
148
+ }, [preview.inlineDataUrl, preview.path, preview.settled, chatId, cacheKey, canReadLocal]);
149
+
150
+ return state;
151
+ }
152
+
153
+ function computeCropOverlayStyle(
154
+ preview: ImageActionPreview,
155
+ naturalSize: { w: number; h: number } | null,
156
+ ): { left: string; top: string; width: string; height: string } | null {
157
+ const imgWidth = preview.width ?? naturalSize?.w ?? null;
158
+ const imgHeight = preview.height ?? naturalSize?.h ?? null;
159
+ if (!preview.region || !imgWidth || !imgHeight || imgWidth <= 0 || imgHeight <= 0) {
160
+ return null;
161
+ }
162
+ return {
163
+ left: `${Math.max(0, Math.min(100, (preview.region.x / imgWidth) * 100))}%`,
164
+ top: `${Math.max(0, Math.min(100, (preview.region.y / imgHeight) * 100))}%`,
165
+ width: `${Math.max(2, Math.min(100, (preview.region.w / imgWidth) * 100))}%`,
166
+ height: `${Math.max(2, Math.min(100, (preview.region.h / imgHeight) * 100))}%`,
167
+ };
168
+ }
169
+
170
+ export function ImageToolThumb({
171
+ preview,
172
+ chatId,
173
+ }: {
174
+ preview: ImageActionPreview;
175
+ chatId?: string | null;
176
+ }) {
177
+ const { dataUrl } = useImagePreviewSource(preview, chatId);
178
+ if (dataUrl) {
179
+ return (
180
+ <img
181
+ src={dataUrl}
182
+ alt=""
183
+ aria-hidden
184
+ data-testid="tool-image-thumb"
185
+ className="h-4 w-4 shrink-0 rounded-sm object-cover ring-1 ring-agent-border/70"
186
+ />
187
+ );
188
+ }
189
+ return <LuImage className="h-3 w-3 shrink-0 text-agent-muted-foreground" aria-hidden />;
190
+ }
191
+
192
+ export function ImageCollapsedPreview({
193
+ preview,
194
+ chatId,
195
+ inTimeline = true,
196
+ onExpand,
197
+ }: {
198
+ preview: ImageActionPreview;
199
+ chatId?: string | null;
200
+ inTimeline?: boolean;
201
+ onExpand: () => void;
202
+ }) {
203
+ const { dataUrl } = useImagePreviewSource(preview, chatId);
204
+ const [naturalSize, setNaturalSize] = useState<{ w: number; h: number } | null>(null);
205
+ if (!dataUrl) return null;
206
+
207
+ const cropStyle = computeCropOverlayStyle(preview, naturalSize);
208
+ return (
209
+ <div className={inTimeline ? 'ml-5 mt-0.5 mb-1.5' : 'px-2.5 pb-2'}>
210
+ <button
211
+ type="button"
212
+ onClick={onExpand}
213
+ data-testid="tool-image-inline-preview"
214
+ aria-label={preview.displayName}
215
+ title={preview.path ?? preview.displayName}
216
+ className="relative inline-block max-w-full cursor-pointer overflow-hidden rounded-md border border-agent-border/80 bg-agent-muted/30 shadow-2xs transition-all hover:border-agent-accent/60 hover:shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-agent-accent"
217
+ >
218
+ <img
219
+ src={dataUrl}
220
+ alt={preview.displayName}
221
+ data-testid="tool-image-thumb"
222
+ onLoad={(e) => {
223
+ const el = e.currentTarget;
224
+ if (el.naturalWidth && el.naturalHeight) {
225
+ setNaturalSize({ w: el.naturalWidth, h: el.naturalHeight });
226
+ }
227
+ }}
228
+ className="block max-h-24 max-w-[200px] object-contain"
229
+ />
230
+ {cropStyle ? (
231
+ <span
232
+ style={cropStyle}
233
+ className="pointer-events-none absolute border border-dashed border-amber-400 bg-amber-400/20"
234
+ />
235
+ ) : null}
236
+ </button>
237
+ </div>
238
+ );
239
+ }
240
+
241
+ const MAX_FOLD_STRIP_THUMBS = 6;
242
+
243
+ function RoundFoldStripThumb({
244
+ itemKey,
245
+ preview,
246
+ chatId,
247
+ onExpand,
248
+ onReady,
249
+ }: {
250
+ itemKey: string;
251
+ preview: ImageActionPreview;
252
+ chatId?: string | null;
253
+ onExpand: () => void;
254
+ onReady: (key: string, loaded: boolean) => void;
255
+ }) {
256
+ const { dataUrl } = useImagePreviewSource(preview, chatId);
257
+ const loaded = Boolean(dataUrl);
258
+ useEffect(() => {
259
+ onReady(itemKey, loaded);
260
+ }, [itemKey, loaded, onReady]);
261
+ if (!dataUrl) return null;
262
+ return (
263
+ <button
264
+ type="button"
265
+ onClick={onExpand}
266
+ title={preview.displayName}
267
+ aria-label={preview.displayName}
268
+ data-testid="round-fold-image-thumb"
269
+ className="relative shrink-0 cursor-pointer overflow-hidden rounded border border-agent-border/80 bg-agent-muted/30 shadow-2xs transition-all hover:border-agent-accent/60 hover:shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-agent-accent"
270
+ >
271
+ <img
272
+ src={dataUrl}
273
+ alt={preview.displayName}
274
+ className="block h-12 max-w-[96px] object-contain"
275
+ />
276
+ </button>
277
+ );
278
+ }
279
+
280
+ export function ImageRoundFoldStrip({
281
+ actions,
282
+ chatId,
283
+ onExpand,
284
+ }: {
285
+ actions: readonly ExecutedActionLike[];
286
+ chatId?: string | null;
287
+ onExpand: () => void;
288
+ }) {
289
+ const [loadedByKey, setLoadedByKey] = useState<Record<string, boolean>>({});
290
+ const handleThumbReady = useCallback((key: string, loaded: boolean) => {
291
+ setLoadedByKey((prev) => (prev[key] === loaded ? prev : { ...prev, [key]: loaded }));
292
+ }, []);
293
+ const seen = new Set<string>();
294
+ const unique: Array<{ key: string; preview: ImageActionPreview }> = [];
295
+ for (const action of actions) {
296
+ const parsed = parseImageAction(action);
297
+ if (!parsed) continue;
298
+ const key = parsed.inlineDataUrl ?? parsed.path ?? parsed.displayName;
299
+ if (seen.has(key)) continue;
300
+ seen.add(key);
301
+ unique.push({ key, preview: parsed });
302
+ }
303
+ if (unique.length === 0) return null;
304
+ const canLoadAny = unique.some(
305
+ ({ preview }) =>
306
+ Boolean(preview.inlineDataUrl) ||
307
+ Boolean(chatId && preview.path && hostToolCapability('local-fs')),
308
+ );
309
+ if (!canLoadAny) return null;
310
+
311
+ const visible = unique.slice(0, MAX_FOLD_STRIP_THUMBS);
312
+ const overflow = unique.length - visible.length;
313
+ const hasAnyLoaded = visible.some(({ key }) => loadedByKey[key] === true);
314
+
315
+ return (
316
+ <div
317
+ data-testid="round-fold-image-strip"
318
+ className="ml-5 flex flex-wrap items-center gap-1.5 empty:hidden"
319
+ >
320
+ {visible.map(({ key, preview }) => (
321
+ <RoundFoldStripThumb
322
+ key={key}
323
+ itemKey={key}
324
+ preview={preview}
325
+ chatId={chatId}
326
+ onExpand={onExpand}
327
+ onReady={handleThumbReady}
328
+ />
329
+ ))}
330
+ {overflow > 0 && hasAnyLoaded ? (
331
+ <button
332
+ type="button"
333
+ onClick={onExpand}
334
+ className="inline-flex h-12 cursor-pointer items-center rounded border border-agent-border/70 bg-agent-muted/40 px-2 font-mono text-[10px] text-agent-muted-foreground transition-colors hover:bg-agent-muted hover:text-agent-foreground"
335
+ >
336
+ +{overflow}
337
+ </button>
338
+ ) : null}
339
+ </div>
340
+ );
341
+ }
342
+
343
+ export function ImageTrailingMeta({ preview }: { preview: ImageActionPreview }) {
344
+ const parts: string[] = [];
345
+ if (preview.width && preview.height) {
346
+ parts.push(`${preview.width}×${preview.height}`);
347
+ }
348
+ if (preview.region) {
349
+ parts.push(t('cropped'));
350
+ }
351
+ if (parts.length === 0) return null;
352
+ return (
353
+ <span className="font-mono text-[10px] tabular-nums text-agent-muted-foreground">
354
+ {parts.join(' · ')}
355
+ </span>
356
+ );
357
+ }
358
+
359
+ export function ImageToolPreview({
360
+ preview,
361
+ chatId,
362
+ }: {
363
+ preview: ImageActionPreview;
364
+ chatId?: string | null;
365
+ }) {
366
+ const { dataUrl, resolvedPath } = useImagePreviewSource(preview, chatId);
367
+ const [naturalSize, setNaturalSize] = useState<{ w: number; h: number } | null>(null);
368
+ const allowOpen = hostToolChrome('local-fs') && Boolean(resolvedPath || preview.path);
369
+ const cropStyle = computeCropOverlayStyle(preview, naturalSize);
370
+
371
+ const handleOpen = async () => {
372
+ const raw = resolvedPath ?? preview.path;
373
+ if (!raw) return;
374
+ const target = await resolveTargetFilePath(raw, chatId);
375
+ await openLocalPath(target).catch(() => {});
376
+ };
377
+
378
+ return (
379
+ <div className="space-y-1.5 text-[11px]" data-testid="image-tool-preview">
380
+ <div className="flex items-center justify-between gap-2">
381
+ <span className="min-w-0 truncate font-mono text-[10px] text-agent-muted-foreground">
382
+ {preview.path ?? preview.displayName}
383
+ </span>
384
+ {allowOpen ? (
385
+ <button
386
+ type="button"
387
+ onClick={() => void handleOpen()}
388
+ 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"
389
+ >
390
+ <LuExternalLink className="h-3 w-3" />
391
+ <span>{t('Open image')}</span>
392
+ </button>
393
+ ) : null}
394
+ </div>
395
+ {dataUrl ? (
396
+ <div className="relative inline-block max-w-full overflow-hidden rounded-md border border-agent-border bg-agent-muted/30">
397
+ <img
398
+ src={dataUrl}
399
+ alt={preview.displayName}
400
+ onLoad={(e) => {
401
+ const el = e.currentTarget;
402
+ if (el.naturalWidth && el.naturalHeight) {
403
+ setNaturalSize({ w: el.naturalWidth, h: el.naturalHeight });
404
+ }
405
+ }}
406
+ className="block max-h-64 max-w-full object-contain"
407
+ />
408
+ {cropStyle ? (
409
+ <div
410
+ data-testid="image-crop-box"
411
+ style={cropStyle}
412
+ className="pointer-events-none absolute border-2 border-dashed border-amber-400 bg-amber-400/15 shadow-xs"
413
+ />
414
+ ) : null}
415
+ </div>
416
+ ) : (
417
+ <div className="text-[11px] italic text-agent-muted-foreground">
418
+ {preview.displayName}
419
+ </div>
420
+ )}
421
+ </div>
422
+ );
423
+ }
424
+
425
+ /**
426
+ * Reusable R4 output viewer: shows head 5 + expandable middle fold + tail 5
427
+ * when output exceeds 12 lines so both header context and trailing errors stay visible.
428
+ */
429
+ export function MiddleTruncatedPre({
430
+ text,
431
+ tone = 'neutral',
432
+ }: {
433
+ text: string;
434
+ tone?: 'neutral' | 'error';
435
+ }) {
436
+ const [showAll, setShowAll] = useState(false);
437
+ const sliced = truncateOutputMiddle(text, { headLines: 5, tailLines: 5, minTotalLines: 12 });
438
+ const toneClass =
439
+ tone === 'error'
440
+ ? 'bg-rose-50/60 text-rose-700 dark:bg-rose-950/25 dark:text-rose-300'
441
+ : 'bg-agent-muted/40 text-agent-foreground';
442
+
443
+ if (!sliced.truncated) {
444
+ return (
445
+ <pre
446
+ className={`max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded px-2 py-1.5 font-mono text-[11px] ${toneClass}`}
447
+ >
448
+ {text}
449
+ </pre>
450
+ );
451
+ }
452
+
453
+ if (showAll) {
454
+ return (
455
+ <div className="space-y-1">
456
+ <pre
457
+ className={`max-h-80 overflow-y-auto whitespace-pre-wrap break-words rounded px-2 py-1.5 font-mono text-[11px] ${toneClass}`}
458
+ >
459
+ {text}
460
+ </pre>
461
+ <button
462
+ type="button"
463
+ onClick={() => setShowAll(false)}
464
+ className="cursor-pointer rounded px-1.5 py-0.5 text-[10px] text-agent-muted-foreground transition-colors hover:bg-agent-muted hover:text-agent-foreground"
465
+ >
466
+ {t('Collapse middle lines')}
467
+ </button>
468
+ </div>
469
+ );
470
+ }
471
+
472
+ return (
473
+ <div className={`overflow-hidden rounded font-mono text-[11px] ${toneClass}`}>
474
+ <pre className="whitespace-pre-wrap break-words px-2 pt-1.5 pb-1">{sliced.head}</pre>
475
+ <button
476
+ type="button"
477
+ onClick={() => setShowAll(true)}
478
+ data-testid="expand-middle-lines"
479
+ className="flex w-full cursor-pointer items-center gap-1 border-y border-agent-border/50 bg-agent-muted/50 px-2 py-1 text-left font-sans text-[10px] text-agent-muted-foreground transition-colors hover:bg-agent-muted hover:text-agent-foreground"
480
+ >
481
+ <span>{t('… +{count} lines (show all)', { count: sliced.omittedLines })}</span>
482
+ </button>
483
+ <pre className="whitespace-pre-wrap break-words px-2 pt-1 pb-1.5">{sliced.tail}</pre>
484
+ </div>
485
+ );
486
+ }
487
+
488
+ export function FileChangeTrailingMeta({ preview }: { preview: FileChangePreview }) {
489
+ if (preview.isWrite && preview.totalLines !== null && preview.removedLines === 0 && !preview.diff) {
490
+ return (
491
+ <span className="font-mono text-[11px] tabular-nums text-agent-muted-foreground">
492
+ {t('{count} lines', { count: preview.totalLines })}
493
+ </span>
494
+ );
495
+ }
496
+ if (preview.addedLines === 0 && preview.removedLines === 0) return null;
497
+ return (
498
+ <span
499
+ data-testid="diff-stats"
500
+ className="inline-flex items-center gap-1 font-mono text-[11px] tabular-nums"
501
+ >
502
+ {preview.addedLines > 0 ? (
503
+ <span className="text-emerald-600 dark:text-emerald-400">+{preview.addedLines}</span>
504
+ ) : null}
505
+ {preview.removedLines > 0 ? (
506
+ <span className="text-rose-600 dark:text-rose-400">-{preview.removedLines}</span>
507
+ ) : null}
508
+ </span>
509
+ );
510
+ }
511
+
512
+ export function FileChangeDetailsView({
513
+ preview,
514
+ chatId,
515
+ }: {
516
+ preview: FileChangePreview;
517
+ chatId?: string | null;
518
+ }) {
519
+ const allowOpen = hostToolChrome('local-fs') && Boolean(preview.path);
520
+
521
+ const handleOpen = async () => {
522
+ const target = await resolveTargetFilePath(preview.path, chatId);
523
+ await openLocalPath(target).catch(() => {});
524
+ };
525
+
526
+ return (
527
+ <div className="space-y-1.5 text-[11px]">
528
+ <div className="flex items-center justify-between gap-2">
529
+ <span className="min-w-0 truncate font-mono text-[10px] text-agent-muted-foreground">
530
+ {preview.path}
531
+ </span>
532
+ {allowOpen ? (
533
+ <button
534
+ type="button"
535
+ onClick={() => void handleOpen()}
536
+ 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"
537
+ >
538
+ <LuExternalLink className="h-3 w-3" />
539
+ <span>{t('Open file')}</span>
540
+ </button>
541
+ ) : null}
542
+ </div>
543
+ {preview.error ? <MiddleTruncatedPre text={preview.error} tone="error" /> : null}
544
+ {preview.diff ? (
545
+ <UnifiedDiff diff={preview.diff} />
546
+ ) : preview.contentPreview ? (
547
+ <MiddleTruncatedPre text={preview.contentPreview} />
548
+ ) : null}
549
+ </div>
550
+ );
551
+ }
552
+
553
+ export function WebSearchResultsView({ view }: { view: WebSearchActionView }) {
554
+ if (view.results.length === 0) {
555
+ return (
556
+ <div className="text-[11px] italic text-agent-muted-foreground">
557
+ {t('no matches')}
558
+ </div>
559
+ );
560
+ }
561
+ return (
562
+ <ul className="space-y-1.5 text-[11px]" data-testid="web-search-results">
563
+ {view.results.map((item, idx) => (
564
+ <li
565
+ key={`${item.url}-${idx}`}
566
+ className="rounded bg-agent-muted/35 px-2 py-1.5"
567
+ >
568
+ <div className="flex items-center gap-1.5">
569
+ <span className="shrink-0 rounded bg-agent-muted px-1 py-0.5 font-mono text-[10px] text-agent-muted-foreground">
570
+ {item.host}
571
+ </span>
572
+ <a
573
+ href={item.url}
574
+ target="_blank"
575
+ rel="noopener noreferrer"
576
+ className="inline-flex min-w-0 flex-1 items-center gap-1 truncate font-medium text-agent-foreground hover:underline"
577
+ >
578
+ <span className="truncate">{item.title}</span>
579
+ <LuExternalLink className="h-3 w-3 shrink-0 text-agent-muted-foreground" />
580
+ </a>
581
+ </div>
582
+ {item.snippet ? (
583
+ <p className="mt-0.5 line-clamp-2 text-[11px] text-agent-muted-foreground">
584
+ {item.snippet}
585
+ </p>
586
+ ) : null}
587
+ </li>
588
+ ))}
589
+ </ul>
590
+ );
591
+ }
592
+
593
+ export function WebFetchDetailsView({ view }: { view: WebFetchActionView }) {
594
+ return (
595
+ <div className="space-y-1.5 text-[11px]" data-testid="web-fetch-details">
596
+ {view.url ? (
597
+ <div className="flex items-center justify-between gap-2">
598
+ <a
599
+ href={view.url}
600
+ target="_blank"
601
+ rel="noopener noreferrer"
602
+ className="inline-flex min-w-0 items-center gap-1 truncate font-mono text-[10px] text-agent-muted-foreground hover:text-agent-foreground hover:underline"
603
+ >
604
+ <span className="truncate">{view.url}</span>
605
+ <LuExternalLink className="h-3 w-3 shrink-0" />
606
+ </a>
607
+ <span className="shrink-0 font-mono text-[10px] text-agent-muted-foreground">
608
+ {[view.status ? String(view.status) : null, view.sizeLabel]
609
+ .filter(Boolean)
610
+ .join(' · ')}
611
+ </span>
612
+ </div>
613
+ ) : null}
614
+ {view.excerpt ? <MiddleTruncatedPre text={view.excerpt} /> : null}
615
+ </div>
616
+ );
617
+ }
618
+
619
+ export function TodoChecklistView({ view }: { view: TodoWriteActionView }) {
620
+ return (
621
+ <ul className="space-y-1 text-[11px]" data-testid="todo-checklist">
622
+ {view.items.map((item) => {
623
+ const isDone = item.status === 'completed';
624
+ const isActive = item.status === 'in_progress';
625
+ const isCancelled = item.status === 'cancelled';
626
+ return (
627
+ <li key={item.id} className="flex items-start gap-1.5">
628
+ {isDone ? (
629
+ <LuCheck className="mt-0.5 h-3.5 w-3.5 shrink-0 text-emerald-600 dark:text-emerald-400" />
630
+ ) : isActive ? (
631
+ <LuCircleDot className="mt-0.5 h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-400" />
632
+ ) : isCancelled ? (
633
+ <LuCircleSlash className="mt-0.5 h-3.5 w-3.5 shrink-0 text-agent-muted-foreground/60" />
634
+ ) : (
635
+ <LuCircle className="mt-0.5 h-3.5 w-3.5 shrink-0 text-agent-muted-foreground" />
636
+ )}
637
+ <span
638
+ className={
639
+ isDone || isCancelled
640
+ ? 'text-agent-muted-foreground line-through'
641
+ : isActive
642
+ ? 'font-medium text-agent-foreground'
643
+ : 'text-agent-foreground'
644
+ }
645
+ >
646
+ {item.content}
647
+ </span>
648
+ </li>
649
+ );
650
+ })}
651
+ </ul>
652
+ );
653
+ }
654
+
655
+ export function MemoryDetailsView({ view }: { view: MemoryActionView }) {
656
+ return (
657
+ <div className="space-y-1 text-[11px]" data-testid="memory-details">
658
+ {view.scope ? (
659
+ <div className="font-mono text-[10px] text-agent-muted-foreground">
660
+ scope: {view.scope}
661
+ </div>
662
+ ) : null}
663
+ {view.detail ? <MiddleTruncatedPre text={view.detail} /> : null}
664
+ </div>
665
+ );
666
+ }
@@ -141,6 +141,21 @@ function actionsFromTimeline(blocks: TurnBlock[] | undefined): ExecutedAction[]
141
141
  return actions;
142
142
  }
143
143
 
144
+ /**
145
+ * Composer meta-row visibility: keep active or incomplete task lists visible,
146
+ * and keep newly completed lists visible while the turn is still streaming;
147
+ * once the turn settles (`!isStreaming`), hide an all-completed list so stale
148
+ * finished checklists do not linger above the next prompt.
149
+ */
150
+ export function shouldShowComposerTodos(
151
+ todos: SessionTodo[] | null | undefined,
152
+ isStreaming: boolean,
153
+ ): todos is SessionTodo[] {
154
+ if (!todos || todos.length === 0) return false;
155
+ if (isStreaming) return true;
156
+ return todos.some((todo) => todo.status !== 'completed');
157
+ }
158
+
144
159
  /**
145
160
  * Newest `todo_write` list for the open chat. Live turn first, then
146
161
  * historical actions / timelines walking messages newest-first.