paseo-dsh 0.2.20 → 0.2.22

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.
@@ -15,6 +15,8 @@ import type {
15
15
  PluginTimelineItemProps,
16
16
  } from "@getpaseo/plugin/client";
17
17
  import { useAgent, useRpc, useSettings } from "@getpaseo/plugin/client";
18
+ import { translateForLabel, useTranslation } from "./i18n";
19
+ import { FailedRow, guard, guardAsync, report, withPluginBoundary } from "./guard";
18
20
  import { Icon, copyText, useToast } from "@getpaseo/plugin/client/react-native";
19
21
  import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
20
22
  import * as ReactNative from "react-native";
@@ -44,8 +46,9 @@ const ImageView = (ReactNative as unknown as {
44
46
  }).Image;
45
47
 
46
48
  import { z } from "zod";
47
- import { imagePreviewRpc } from "../shared/image-preview";
49
+ import { imagePreviewRpc, type ImageErrorCode } from "../shared/image-preview";
48
50
  import { TIMELINE_STYLE_DEFAULTS, timelineStyleSettings, type TimelineStyleValues } from "../shared/settings";
51
+ import type { BrowserVerbKey, ToolVerb, ToolVerbKey } from "./messages";
49
52
 
50
53
  type Phase = "streaming" | "complete";
51
54
  type Theme = PluginTimelineItemProps<unknown>["theme"];
@@ -63,6 +66,16 @@ const reasoningSchema = z.object({
63
66
 
64
67
  const toolDetailSchema = z.record(z.string(), z.unknown());
65
68
 
69
+ const todoSchema = z.object({
70
+ items: z.array(
71
+ z.object({
72
+ text: z.string(),
73
+ status: z.string(),
74
+ activeForm: z.string().optional(),
75
+ }),
76
+ ),
77
+ });
78
+
66
79
  const toolSchema = z.object({
67
80
  name: z.string(),
68
81
  status: z.string(),
@@ -73,6 +86,7 @@ const toolSchema = z.object({
73
86
  });
74
87
 
75
88
  type ReasoningData = z.infer<typeof reasoningSchema>;
89
+ type TodoData = z.infer<typeof todoSchema>;
76
90
  type ToolData = z.infer<typeof toolSchema>;
77
91
 
78
92
  function isRecord(value: unknown): value is Record<string, unknown> {
@@ -233,21 +247,27 @@ const runningDotPulse = Platform.OS === "web"
233
247
 
234
248
  /** The breathing accent dot that stands in for a running tool's glyph. */
235
249
  function RunningDot({ color }: { color: string }) {
250
+ const { t } = useTranslation();
236
251
  const pulseRef = useRef<{ interpolate(config: { inputRange: number[]; outputRange: number[] }): unknown } | null>(null);
237
252
  if (pulseRef.current === null) pulseRef.current = new RNAnimated.Animated.Value(0);
238
253
  const pulse = pulseRef.current;
239
254
  useEffect(() => {
240
255
  if (Platform.OS === "web") return;
241
- const loop = RNAnimated.Animated.loop(
242
- RNAnimated.Animated.timing(pulse, {
243
- toValue: 1,
244
- duration: RUNNING_DOT.periodMs,
245
- easing: RNAnimated.Easing.inOut(RNAnimated.Easing.ease),
246
- useNativeDriver: true,
247
- }),
248
- );
249
- loop.start();
250
- return () => loop.stop();
256
+ try {
257
+ const loop = RNAnimated.Animated.loop(
258
+ RNAnimated.Animated.timing(pulse, {
259
+ toValue: 1,
260
+ duration: RUNNING_DOT.periodMs,
261
+ easing: RNAnimated.Easing.inOut(RNAnimated.Easing.ease),
262
+ useNativeDriver: true,
263
+ }),
264
+ );
265
+ loop.start();
266
+ return () => loop.stop();
267
+ } catch (error) {
268
+ report("running dot animation", error);
269
+ return;
270
+ }
251
271
  }, [pulse]);
252
272
  const opacity = pulse.interpolate({ inputRange: [0, 0.5, 1], outputRange: [1, RUNNING_DOT.minOpacity, 1] });
253
273
  const shape = {
@@ -258,11 +278,11 @@ function RunningDot({ color }: { color: string }) {
258
278
  };
259
279
  if (Platform.OS === "web") {
260
280
  return (
261
- <View accessibilityRole="progressbar" accessibilityLabel="运行中" style={[shape, runningDotPulse as never]} />
281
+ <View accessibilityRole="progressbar" accessibilityLabel={t("timeline.row.running")} style={[shape, runningDotPulse as never]} />
262
282
  );
263
283
  }
264
284
  return (
265
- <AnimatedView accessibilityRole="progressbar" accessibilityLabel="运行中" style={[shape, { opacity }]} />
285
+ <AnimatedView accessibilityRole="progressbar" accessibilityLabel={t("timeline.row.running")} style={[shape, { opacity }]} />
266
286
  );
267
287
  }
268
288
 
@@ -294,32 +314,49 @@ function CommandBlock({ text, theme, maxHeight }: { text: string; theme: Theme;
294
314
 
295
315
  /** Image preview for a read_image tool call; bytes come from the daemon RPC. */
296
316
  function ImagePreview({ agentId, path, theme }: { agentId: string; path: string; theme: Theme }) {
317
+ const { t } = useTranslation();
297
318
  const cwd = useAgent(agentId, (agent) => agent.cwd) ?? "";
298
319
  const readImage = useRpc(imagePreviewRpc);
299
320
  const window = useWindowDimensions();
300
321
  const [state, setState] = useState<
301
322
  | { status: "loading" }
302
323
  | { status: "ready"; uri: string }
303
- | { status: "tooLarge"; error: string }
304
- | { status: "error"; error: string }
324
+ | { status: "tooLarge"; bytes: number; limit: number }
325
+ | { status: "error"; code: ImageErrorCode; detail: string | null }
305
326
  >({ status: "loading" });
306
327
 
307
328
  const load = useCallback(
308
329
  (allowLarge: boolean) => {
309
330
  setState({ status: "loading" });
310
- void readImage({ cwd, path, allowLarge })
311
- .then((result) => {
312
- if (result.dataUri !== null) {
313
- setState({ status: "ready", uri: result.dataUri });
314
- } else if (result.tooLarge) {
315
- setState({ status: "tooLarge", error: result.error ?? "图片较大" });
316
- } else {
317
- setState({ status: "error", error: result.error ?? "无法读取图片" });
318
- }
319
- })
320
- .catch((error: unknown) => {
321
- setState({ status: "error", error: error instanceof Error ? error.message : String(error) });
331
+ const failed = (error: unknown) => {
332
+ setState({
333
+ status: "error",
334
+ code: "unreadable",
335
+ detail: error instanceof Error ? error.message : String(error),
322
336
  });
337
+ };
338
+ // `readImage` can throw before it returns a promise (the host may not
339
+ // have the RPC ready yet); that throw would escape the effect and become
340
+ // a fatal error, so both shapes are absorbed here.
341
+ try {
342
+ void readImage({ cwd, path, allowLarge })
343
+ .then((result) => {
344
+ if (result.dataUri !== null) {
345
+ setState({ status: "ready", uri: result.dataUri });
346
+ } else if (result.tooLarge) {
347
+ setState({ status: "tooLarge", bytes: result.bytes ?? 0, limit: result.limit ?? 0 });
348
+ } else {
349
+ setState({ status: "error", code: result.errorCode ?? "unreadable", detail: result.errorDetail });
350
+ }
351
+ })
352
+ .catch((error: unknown) => {
353
+ report("image preview", error);
354
+ failed(error);
355
+ });
356
+ } catch (error) {
357
+ report("image preview", error);
358
+ failed(error);
359
+ }
323
360
  },
324
361
  [cwd, path, readImage],
325
362
  );
@@ -329,20 +366,38 @@ function ImagePreview({ agentId, path, theme }: { agentId: string; path: string;
329
366
  }, [load]);
330
367
 
331
368
  if (state.status === "loading") {
332
- return <Text style={[styles.imageHint, { color: theme.colors.foregroundMuted }]}>载入图片…</Text>;
369
+ return <Text style={[styles.imageHint, { color: theme.colors.foregroundMuted }]}>{t("timeline.row.loadingImage")}</Text>;
333
370
  }
334
371
  if (state.status === "tooLarge") {
335
372
  return (
336
373
  <View style={styles.imageTooLarge}>
337
- <Text style={[styles.imageHint, { color: theme.colors.foregroundMuted }]}>{state.error}</Text>
338
- <Pressable onPress={() => load(true)} accessibilityLabel="仍要加载" hitSlop={6}>
339
- <Text style={[styles.imageLoadAnyway, { color: theme.colors.accent }]}>仍要加载</Text>
374
+ <Text style={[styles.imageHint, { color: theme.colors.foregroundMuted }]}>
375
+ {t("timeline.image.tooLarge", {
376
+ size: (state.bytes / 1024 / 1024).toFixed(1),
377
+ limit: Math.round(state.limit / 1024 / 1024),
378
+ })}
379
+ </Text>
380
+ <Pressable onPress={() => load(true)} accessibilityLabel={t("timeline.row.loadAnyway")} hitSlop={6}>
381
+ <Text style={[styles.imageLoadAnyway, { color: theme.colors.accent }]}>{t("timeline.row.loadAnyway")}</Text>
340
382
  </Pressable>
341
383
  </View>
342
384
  );
343
385
  }
344
386
  if (state.status === "error") {
345
- return <Text style={[styles.imageHint, { color: theme.colors.statusDanger }]}>{state.error}</Text>;
387
+ const base = state.code === "unsupported-format"
388
+ ? t("timeline.image.unsupportedFormat")
389
+ : state.code === "not-file"
390
+ ? t("timeline.image.notFile")
391
+ : state.code === "too-large-hard"
392
+ ? t("timeline.image.tooLargeHard")
393
+ : t("timeline.image.unreadable");
394
+ return (
395
+ <Text style={[styles.imageHint, { color: theme.colors.statusDanger }]}>
396
+ {state.detail === null || state.detail === ""
397
+ ? base
398
+ : `${base} · ${t("timeline.image.detail", { message: state.detail })}`}
399
+ </Text>
400
+ );
346
401
  }
347
402
  return (
348
403
  <View
@@ -354,7 +409,7 @@ function ImagePreview({ agentId, path, theme }: { agentId: string; path: string;
354
409
  <ImageView
355
410
  source={{ uri: state.uri }}
356
411
  resizeMode="contain"
357
- accessibilityLabel="图片预览"
412
+ accessibilityLabel={t("timeline.row.imagePreview")}
358
413
  style={styles.image}
359
414
  />
360
415
  </View>
@@ -387,12 +442,18 @@ function SheetPanel({
387
442
  children: ReactNode;
388
443
  }) {
389
444
  const toast = useToast();
445
+ const { t } = useTranslation();
390
446
  const copy = useCallback(() => {
391
447
  if (copyValue === undefined) return;
392
- void copyText(copyValue)
393
- .then(() => toast.show("已复制"))
394
- .catch(() => toast.error("复制失败"));
395
- }, [copyValue, toast]);
448
+ guardAsync("copy text", async () => {
449
+ try {
450
+ await copyText(copyValue);
451
+ toast.show(t("timeline.row.copied"));
452
+ } catch {
453
+ toast.error(t("timeline.row.copyFailed"));
454
+ }
455
+ });
456
+ }, [copyValue, toast, t]);
396
457
  const window = useWindowDimensions();
397
458
  const style = useTimelineStyle();
398
459
  return (
@@ -402,14 +463,14 @@ function SheetPanel({
402
463
  <Icon name={icon} size={16} color={theme.colors.foregroundMuted} />
403
464
  <Text numberOfLines={1} style={[styles.sheetTitle, { color: theme.colors.foreground }]}>{title}</Text>
404
465
  {copyValue === undefined ? null : (
405
- <Pressable onPress={copy} accessibilityLabel="复制" hitSlop={8}>
466
+ <Pressable onPress={copy} accessibilityLabel={t("timeline.row.copy")} hitSlop={8}>
406
467
  <Icon name="Copy" size={16} color={theme.colors.foregroundMuted} />
407
468
  </Pressable>
408
469
  )}
409
470
  {onToggleFullscreen === undefined ? null : (
410
471
  <Pressable
411
472
  onPress={onToggleFullscreen}
412
- accessibilityLabel={fullscreen ? "退出全屏" : "全屏"}
473
+ accessibilityLabel={fullscreen ? t("timeline.row.exitFullscreen") : t("timeline.row.fullscreen")}
413
474
  hitSlop={8}
414
475
  >
415
476
  <Icon
@@ -419,7 +480,7 @@ function SheetPanel({
419
480
  />
420
481
  </Pressable>
421
482
  )}
422
- <Pressable onPress={onClose} accessibilityLabel="关闭" hitSlop={8}>
483
+ <Pressable onPress={onClose} accessibilityLabel={t("timeline.row.close")} hitSlop={8}>
423
484
  <Icon name="X" size={18} color={theme.colors.foregroundMuted} />
424
485
  </Pressable>
425
486
  </View>
@@ -469,6 +530,8 @@ function DetailSheet({
469
530
  children: ReactNode;
470
531
  }) {
471
532
  const [full, setFull] = useState(false);
533
+ const { t } = useTranslation();
534
+ const backdropLabel = t("timeline.row.close");
472
535
  useEffect(() => {
473
536
  if (!open) setFull(false);
474
537
  }, [open]);
@@ -476,7 +539,7 @@ function DetailSheet({
476
539
  return (
477
540
  <Modal visible={open} transparent animationType={Platform.OS === "web" ? "none" : "slide"} onRequestClose={onClose} statusBarTranslucent>
478
541
  <View style={styles.modalRoot}>
479
- <Pressable style={styles.backdrop} onPress={onClose} accessibilityLabel="关闭" />
542
+ <Pressable style={styles.backdrop} onPress={onClose} accessibilityLabel={backdropLabel} />
480
543
  <View
481
544
  style={[
482
545
  styles.nativeSheet,
@@ -507,12 +570,15 @@ function DetailSheet({
507
570
  }
508
571
 
509
572
  function ReasoningRow({ item, theme, layout }: PluginTimelineItemProps<ReasoningData>) {
573
+ const { t } = useTranslation();
510
574
  const streaming = item.data.phase === "streaming";
511
575
  const inline = layout.platform === "web";
512
576
  const [open, setOpen] = useState(false);
513
577
  const window = useWindowDimensions();
514
578
  const text = item.data.text;
515
- const preview = streaming ? lastSentence(text) || "思考中…" : firstSentence(text) || "已思考";
579
+ const preview = streaming
580
+ ? lastSentence(text) || t("timeline.thinking.live")
581
+ : firstSentence(text) || t("timeline.thinking.done");
516
582
  const revealed = usePacedText(text, streaming && open);
517
583
  const spacing = useTimelineStyle();
518
584
  // The live tail is laid out by the host with its own gap; a negative pull
@@ -530,7 +596,7 @@ function ReasoningRow({ item, theme, layout }: PluginTimelineItemProps<Reasoning
530
596
  <View>
531
597
  <Pressable
532
598
  accessibilityRole="button"
533
- accessibilityLabel={streaming ? "思考中" : "已思考"}
599
+ accessibilityLabel={streaming ? t("timeline.thinking.live") : t("timeline.thinking.done")}
534
600
  onPress={() => (inline ? setOpen((value) => !value) : setOpen(true))}
535
601
  hitSlop={6}
536
602
  style={({ pressed }: { pressed: boolean }) => [
@@ -541,7 +607,7 @@ function ReasoningRow({ item, theme, layout }: PluginTimelineItemProps<Reasoning
541
607
  <View style={styles.lead}>
542
608
  <Icon name="Brain" size={14} color={streaming ? theme.colors.accent : theme.colors.foregroundMuted} />
543
609
  </View>
544
- <Text style={[styles.verb, { color: theme.colors.foregroundMuted }]}>思考</Text>
610
+ <Text style={[styles.verb, { color: theme.colors.foregroundMuted }]}>{t("timeline.thinking.verb")}</Text>
545
611
  <Text numberOfLines={1} style={[styles.target, { color: theme.colors.foregroundMuted }]}>
546
612
  {preview}
547
613
  </Text>
@@ -572,7 +638,7 @@ function ReasoningRow({ item, theme, layout }: PluginTimelineItemProps<Reasoning
572
638
  <DetailSheet
573
639
  open={open}
574
640
  onClose={() => setOpen(false)}
575
- title="思考"
641
+ title={t("timeline.thinking.verb")}
576
642
  icon="Brain"
577
643
  theme={theme}
578
644
  copyValue={revealed}
@@ -584,11 +650,24 @@ function ReasoningRow({ item, theme, layout }: PluginTimelineItemProps<Reasoning
584
650
  );
585
651
  }
586
652
 
587
- type ToolKind = "shell" | "read" | "write" | "edit" | "search" | "fetch" | "mcp" | "browser" | "code" | "other";
653
+ type ToolKind =
654
+ | "shell"
655
+ | "read"
656
+ | "write"
657
+ | "edit"
658
+ | "search"
659
+ | "fetch"
660
+ | "mcp"
661
+ | "browser"
662
+ | "code"
663
+ | "todo"
664
+ | "question"
665
+ | "other";
588
666
 
589
667
  interface ToolLook {
590
668
  icon: string;
591
- verb: string;
669
+ /** Resolved when the row renders, so a language switch re-words it. */
670
+ verb: ToolVerb;
592
671
  target: string;
593
672
  mark?: string;
594
673
  }
@@ -666,6 +745,9 @@ function toolKindOf(name: string, detail: Record<string, unknown> | undefined):
666
745
  if (type === "edit") return "edit";
667
746
  if (type === "search") return "search";
668
747
  if (type === "fetch") return "fetch";
748
+ // These two carry no native detail shape, so their rows are chosen by name.
749
+ if (name === "todo_write") return "todo";
750
+ if (name === "ask_user_question") return "question";
669
751
  if (name.startsWith("mcp__")) return "mcp";
670
752
  if (name === "run_code") return "code";
671
753
  if (/(?:^|_)browser_/.test(name)) return "browser";
@@ -677,17 +759,17 @@ function toolKindOf(name: string, detail: Record<string, unknown> | undefined):
677
759
  return "other";
678
760
  }
679
761
 
680
- const BROWSER_VERBS: Readonly<Array<[RegExp, string]>> = [
681
- [/^(?:navigate|open|goto|go|new_tab|open_url)$/, "打开网页"],
682
- [/^(?:click|press|tap)$/, "点击"],
683
- [/^(?:type|fill|input|press_key|key)$/, "输入"],
684
- [/^(?:snapshot|screenshot|capture)$/, "截图"],
685
- [/^(?:scroll)$/, "滚动"],
686
- [/^(?:back|forward|reload)$/, "导航"],
687
- [/^(?:wait)$/, "等待"],
688
- [/^(?:close|close_tab)$/, "关闭"],
689
- [/^(?:evaluate|run|run_code)$/, "执行"],
690
- [/^(?:find|search)$/, "查找"],
762
+ const BROWSER_VERBS: Readonly<Array<[RegExp, BrowserVerbKey]>> = [
763
+ [/^(?:navigate|open|goto|go|new_tab|open_url)$/, "timeline.browser.open"],
764
+ [/^(?:click|press|tap)$/, "timeline.browser.click"],
765
+ [/^(?:type|fill|input|press_key|key)$/, "timeline.browser.type"],
766
+ [/^(?:snapshot|screenshot|capture)$/, "timeline.browser.snapshot"],
767
+ [/^(?:scroll)$/, "timeline.browser.scroll"],
768
+ [/^(?:back|forward|reload)$/, "timeline.browser.navigate"],
769
+ [/^(?:wait)$/, "timeline.browser.wait"],
770
+ [/^(?:close|close_tab)$/, "timeline.browser.close"],
771
+ [/^(?:evaluate|run|run_code)$/, "timeline.browser.run"],
772
+ [/^(?:find|search)$/, "timeline.browser.find"],
691
773
  ];
692
774
 
693
775
  /** Strip the server prefix and the `browser_` stem so verbs can match on the action. */
@@ -697,11 +779,11 @@ function browserAction(name: string): string {
697
779
  return bare;
698
780
  }
699
781
 
700
- function browserVerb(action: string): string {
782
+ function browserVerb(action: string): ToolVerbKey | BrowserVerbKey {
701
783
  for (const [pattern, verb] of BROWSER_VERBS) {
702
784
  if (pattern.test(action)) return verb;
703
785
  }
704
- return "浏览器";
786
+ return "timeline.tool.browser";
705
787
  }
706
788
 
707
789
  function firstLine(text: string | undefined): string | undefined {
@@ -725,7 +807,7 @@ function toolLook(data: ToolData): ToolLook {
725
807
  const mark = program === undefined ? undefined : PROGRAM_MARKS[program];
726
808
  return {
727
809
  icon: "SquareTerminal",
728
- verb: "命令",
810
+ verb: "timeline.tool.command",
729
811
  target: firstLine(command) ?? data.name,
730
812
  ...(mark === undefined ? {} : { mark }),
731
813
  };
@@ -734,7 +816,7 @@ function toolLook(data: ToolData): ToolLook {
734
816
  const image = data.name === "read_image";
735
817
  return {
736
818
  icon: image ? "Image" : "FileText",
737
- verb: image ? "看图" : "读取",
819
+ verb: image ? "timeline.tool.image" : "timeline.tool.read",
738
820
  target: stringField(detail, "filePath")
739
821
  ?? stringField(input, "file_path")
740
822
  ?? stringField(input, "path")
@@ -742,9 +824,9 @@ function toolLook(data: ToolData): ToolLook {
742
824
  };
743
825
  }
744
826
  case "write":
745
- return { icon: "Pencil", verb: "写入", target: stringField(detail, "filePath") ?? data.name };
827
+ return { icon: "Pencil", verb: "timeline.tool.write", target: stringField(detail, "filePath") ?? data.name };
746
828
  case "edit":
747
- return { icon: "Pencil", verb: "编辑", target: stringField(detail, "filePath") ?? data.name };
829
+ return { icon: "Pencil", verb: "timeline.tool.edit", target: stringField(detail, "filePath") ?? data.name };
748
830
  case "search": {
749
831
  const query = stringField(detail, "query")
750
832
  ?? stringField(input, "query")
@@ -752,14 +834,14 @@ function toolLook(data: ToolData): ToolLook {
752
834
  ?? data.name;
753
835
  return {
754
836
  icon: "Search",
755
- verb: stringField(detail, "toolName") === "web_search" ? "网页搜索" : "搜索",
837
+ verb: stringField(detail, "toolName") === "web_search" ? "timeline.tool.webSearch" : "timeline.tool.search",
756
838
  target: query,
757
839
  };
758
840
  }
759
841
  case "fetch":
760
842
  return {
761
843
  icon: "Globe",
762
- verb: "抓取",
844
+ verb: "timeline.tool.fetch",
763
845
  target: hostOf(stringField(detail, "url") ?? stringField(input, "url") ?? data.name),
764
846
  };
765
847
  case "mcp": {
@@ -767,7 +849,7 @@ function toolLook(data: ToolData): ToolLook {
767
849
  const browser = parsed !== undefined && parsed.tool.includes("browser_");
768
850
  return {
769
851
  icon: browser ? "Globe" : "Plug",
770
- verb: browser ? "浏览器" : "MCP",
852
+ verb: browser ? "timeline.tool.browser" : { text: "MCP" },
771
853
  target: parsed === undefined ? data.name : `${parsed.server} / ${parsed.tool}`,
772
854
  };
773
855
  }
@@ -786,13 +868,26 @@ function toolLook(data: ToolData): ToolLook {
786
868
  case "code":
787
869
  return {
788
870
  icon: "Code",
789
- verb: "运行代码",
871
+ verb: "timeline.tool.code",
790
872
  target: stringField(input, "description") ?? firstLine(stringField(input, "code")) ?? "run_code",
791
873
  };
874
+ case "todo": {
875
+ const items = todoEntries(input);
876
+ const done = items.filter((entry) => entry.status === "completed").length;
877
+ // A plain `done/total` keeps the target language-neutral: the verb is the
878
+ // only word this row needs.
879
+ return { icon: "ListChecks", verb: "timeline.tool.tasks", target: `${done}/${items.length}` };
880
+ }
881
+ case "question":
882
+ return {
883
+ icon: "HelpCircle",
884
+ verb: "timeline.tool.question",
885
+ target: firstLine(questionLines(input)) ?? data.name,
886
+ };
792
887
  default:
793
888
  return {
794
889
  icon: "Wrench",
795
- verb: data.name,
890
+ verb: { text: data.name },
796
891
  target: stringField(input, "url")
797
892
  ?? stringField(input, "file_path")
798
893
  ?? stringField(input, "path")
@@ -804,11 +899,11 @@ function toolLook(data: ToolData): ToolLook {
804
899
  }
805
900
  }
806
901
 
807
- function statusLabel(status: string): string {
808
- if (status === "running") return "运行中";
809
- if (status === "failed") return "失败";
810
- if (status === "canceled") return "已取消";
811
- return "完成";
902
+ function statusKey(status: string) {
903
+ if (status === "running") return "timeline.status.running" as const;
904
+ if (status === "failed") return "timeline.status.failed" as const;
905
+ if (status === "canceled") return "timeline.status.canceled" as const;
906
+ return "timeline.status.done" as const;
812
907
  }
813
908
 
814
909
  function statusColor(status: string, theme: Theme): string {
@@ -817,6 +912,73 @@ function statusColor(status: string, theme: Theme): string {
817
912
  return theme.colors.foregroundMuted;
818
913
  }
819
914
 
915
+ interface TodoEntry {
916
+ text: string;
917
+ status: string;
918
+ activeForm?: string;
919
+ }
920
+
921
+ const TODO_MARKS: Readonly<Record<string, string>> = {
922
+ completed: "✓",
923
+ in_progress: "◐",
924
+ pending: "○",
925
+ };
926
+
927
+ /** The `input` object of a tool detail, whichever detail shape it is. */
928
+ function detailInput(detail: unknown): Record<string, unknown> | undefined {
929
+ const record = isRecord(detail) ? detail : undefined;
930
+ return isRecord(record?.input) ? record.input : undefined;
931
+ }
932
+
933
+ /** The checklist a `todo_write` call carries, normalized for drawing. */
934
+ function todoEntries(input: Record<string, unknown> | undefined): TodoEntry[] {
935
+ const raw = input?.todos;
936
+ if (!Array.isArray(raw)) return [];
937
+ return raw.flatMap((entry) => {
938
+ if (!isRecord(entry)) return [];
939
+ const text = stringField(entry, "content") ?? stringField(entry, "text");
940
+ if (text === undefined) return [];
941
+ const activeForm = stringField(entry, "activeForm");
942
+ const status = stringField(entry, "status")
943
+ ?? (entry.completed === true ? "completed" : "pending");
944
+ return [{
945
+ text,
946
+ status: status === "in_progress" || status === "completed" ? status : "pending",
947
+ ...(activeForm === undefined ? {} : { activeForm }),
948
+ }];
949
+ });
950
+ }
951
+
952
+ function checklist(items: TodoEntry[]): string {
953
+ return items
954
+ .map((entry) => {
955
+ // The in-progress wording is what the model is doing right now; the rest
956
+ // stay in their plain form so the list reads as the model wrote it.
957
+ const label = entry.status === "in_progress" ? entry.activeForm ?? entry.text : entry.text;
958
+ return `${TODO_MARKS[entry.status] ?? "○"} ${label}`;
959
+ })
960
+ .join("\n");
961
+ }
962
+
963
+ /** The questions and option labels of an `ask_user_question` call. */
964
+ function questionLines(input: Record<string, unknown> | undefined): string {
965
+ const raw = input?.questions;
966
+ if (!Array.isArray(raw)) return stringField(input, "question") ?? "";
967
+ const lines: string[] = [];
968
+ for (const entry of raw) {
969
+ if (!isRecord(entry)) continue;
970
+ const question = stringField(entry, "question") ?? stringField(entry, "header");
971
+ if (question === undefined) continue;
972
+ lines.push(question);
973
+ const options = Array.isArray(entry.options) ? entry.options : [];
974
+ for (const option of options) {
975
+ const label = isRecord(option) ? stringField(option, "label") : typeof option === "string" ? option : undefined;
976
+ if (label !== undefined) lines.push(` - ${label}`);
977
+ }
978
+ }
979
+ return lines.join("\n");
980
+ }
981
+
820
982
  function readContent(content: string): string {
821
983
  const match = /<content>\n?([\s\S]*?)\n?<\/content>/.exec(content);
822
984
  const body = match?.[1] ?? content;
@@ -831,6 +993,17 @@ function toolContent(data: ToolData): string | undefined {
831
993
  if (detail === undefined) return undefined;
832
994
  const type = stringField(detail, "type");
833
995
  const input = isRecord(detail.input) ? detail.input : undefined;
996
+ const kind = toolKindOf(data.name, detail);
997
+ // These two have no detail type of their own, so their drawer body is built
998
+ // from the call's own input rather than from the generic JSON dump.
999
+ if (kind === "todo") {
1000
+ const items = todoEntries(input);
1001
+ return items.length === 0 ? undefined : checklist(items);
1002
+ }
1003
+ if (kind === "question") {
1004
+ const lines = questionLines(input);
1005
+ return lines === "" ? undefined : lines;
1006
+ }
834
1007
  const parts: string[] = [];
835
1008
  switch (type) {
836
1009
  case "shell": {
@@ -1126,12 +1299,13 @@ function CodeSurface({
1126
1299
  }) {
1127
1300
  const [wrap, setWrap] = useState(false);
1128
1301
  const toast = useToast();
1302
+ const { t } = useTranslation();
1129
1303
  const background = sheetBackground(theme);
1130
1304
  const copy = useCallback(() => {
1131
1305
  void copyText(text)
1132
- .then(() => toast.show("已复制"))
1133
- .catch(() => toast.error("复制失败"));
1134
- }, [text, toast]);
1306
+ .then(() => toast.show(t("timeline.row.copied")))
1307
+ .catch(() => toast.error(t("timeline.row.copyFailed")));
1308
+ }, [text, toast, t]);
1135
1309
  return (
1136
1310
  <View
1137
1311
  style={[
@@ -1144,12 +1318,16 @@ function CodeSurface({
1144
1318
  ]}
1145
1319
  >
1146
1320
  <View style={[styles.codeToolbar, { borderBottomColor: theme.colors.border }]}>
1147
- <Pressable onPress={() => setWrap((value) => !value)} accessibilityLabel={wrap ? "不换行" : "换行"} hitSlop={6}>
1321
+ <Pressable
1322
+ onPress={() => setWrap((value) => !value)}
1323
+ accessibilityLabel={wrap ? t("timeline.row.noWrap") : t("timeline.row.wrap")}
1324
+ hitSlop={6}
1325
+ >
1148
1326
  <Text style={[styles.codeToolbarText, { color: theme.colors.foregroundMuted }]}>
1149
- {wrap ? "不换行" : "换行"}
1327
+ {wrap ? t("timeline.row.noWrap") : t("timeline.row.wrap")}
1150
1328
  </Text>
1151
1329
  </Pressable>
1152
- <Pressable onPress={copy} accessibilityLabel="复制" hitSlop={6}>
1330
+ <Pressable onPress={copy} accessibilityLabel={t("timeline.row.copy")} hitSlop={6}>
1153
1331
  <Icon name="Copy" size={13} color={theme.colors.foregroundMuted} />
1154
1332
  </Pressable>
1155
1333
  </View>
@@ -1175,7 +1353,9 @@ function ToolRow({ item, theme, layout, agentId }: PluginTimelineItemProps<ToolD
1175
1353
  const inline = layout.platform === "web";
1176
1354
  const window = useWindowDimensions();
1177
1355
  const data = item.data;
1356
+ const { t } = useTranslation();
1178
1357
  const look = useMemo(() => toolLook(data), [data]);
1358
+ const verb = typeof look.verb === "string" ? t(look.verb) : look.verb.text;
1179
1359
  const content = useMemo(() => toolContent(data), [data]);
1180
1360
  const language = useMemo(() => toolLanguage(data), [data]);
1181
1361
  const subject = useMemo(() => toolSubject(data, look), [data, look]);
@@ -1203,7 +1383,7 @@ function ToolRow({ item, theme, layout, agentId }: PluginTimelineItemProps<ToolD
1203
1383
  <View>
1204
1384
  <Pressable
1205
1385
  accessibilityRole="button"
1206
- accessibilityLabel={`${look.verb}${look.target === "" ? "" : ` ${look.target}`}`}
1386
+ accessibilityLabel={`${verb}${look.target === "" ? "" : ` ${look.target}`}`}
1207
1387
  onPress={openSheet}
1208
1388
  hitSlop={6}
1209
1389
  style={({ pressed }: { pressed: boolean }) => [
@@ -1223,14 +1403,14 @@ function ToolRow({ item, theme, layout, agentId }: PluginTimelineItemProps<ToolD
1223
1403
  )}
1224
1404
  </View>
1225
1405
  <Text style={[styles.verb, { color: failed ? theme.colors.statusDanger : theme.colors.foregroundMuted }]}>
1226
- {look.verb}
1406
+ {verb}
1227
1407
  </Text>
1228
1408
  <Text numberOfLines={1} style={[styles.target, { color: theme.colors.foregroundMuted }]}>
1229
1409
  {look.target}
1230
1410
  </Text>
1231
1411
  {data.status === "running" || data.status === "completed" ? null : (
1232
1412
  <Text style={[styles.meta, { color: statusColor(data.status, theme) }]}>
1233
- {statusLabel(data.status)}
1413
+ {t(statusKey(data.status))}
1234
1414
  </Text>
1235
1415
  )}
1236
1416
  {content === undefined ? null : (
@@ -1267,7 +1447,7 @@ function ToolRow({ item, theme, layout, agentId }: PluginTimelineItemProps<ToolD
1267
1447
  <DetailSheet
1268
1448
  open={open}
1269
1449
  onClose={() => setOpen(false)}
1270
- title={look.verb}
1450
+ title={verb}
1271
1451
  subject={subject}
1272
1452
  subjectWrap={wrapSubject}
1273
1453
  icon={look.icon}
@@ -1289,68 +1469,207 @@ function ToolRow({ item, theme, layout, agentId }: PluginTimelineItemProps<ToolD
1289
1469
  );
1290
1470
  }
1291
1471
 
1472
+ /**
1473
+ * The checklist Paseo would draw itself, in the plugin's compact row shape.
1474
+ *
1475
+ * One `todo_write` call yields one of these, so the tool row that produced it is
1476
+ * dropped once it completes and the list never appears twice.
1477
+ */
1478
+ function TodoRow({ item, theme, layout }: PluginTimelineItemProps<TodoData>) {
1479
+ const { t } = useTranslation();
1480
+ const [open, setOpen] = useState(false);
1481
+ const inline = layout.platform === "web";
1482
+ const window = useWindowDimensions();
1483
+ const spacing = useTimelineStyle();
1484
+ const items = item.data.items;
1485
+ const total = items.length;
1486
+ const done = items.filter((entry) => entry.status === "completed").length;
1487
+ const content = checklist(items);
1488
+ const verb = t("timeline.tool.tasks");
1489
+ const row = {
1490
+ ...styles.row,
1491
+ marginTop: spacing.toolRowMarginY,
1492
+ marginBottom: 0,
1493
+ paddingVertical: spacing.toolRowPaddingY,
1494
+ minHeight: spacing.toolRowMinHeight,
1495
+ gap: spacing.toolRowGap,
1496
+ };
1497
+ return (
1498
+ <View>
1499
+ <Pressable
1500
+ accessibilityRole="button"
1501
+ accessibilityLabel={`${verb} ${done}/${total}`}
1502
+ onPress={() => (inline ? setOpen((value) => !value) : setOpen(true))}
1503
+ hitSlop={6}
1504
+ style={({ pressed }: { pressed: boolean }) => [
1505
+ row,
1506
+ pressed ? { backgroundColor: theme.colors.surface1, borderRadius: 6 } : null,
1507
+ ]}
1508
+ >
1509
+ <View style={styles.lead}>
1510
+ <Icon name="ListChecks" size={14} color={theme.colors.foregroundMuted} />
1511
+ </View>
1512
+ <Text style={[styles.verb, { color: theme.colors.foregroundMuted }]}>{verb}</Text>
1513
+ <Text numberOfLines={1} style={[styles.target, { color: theme.colors.foregroundMuted }]}>
1514
+ {`${done}/${total}`}
1515
+ </Text>
1516
+ <View style={{ transform: [{ rotate: inline && open ? "90deg" : "0deg" }] }}>
1517
+ <Icon name="ChevronRight" size={12} color={theme.colors.foregroundMuted} />
1518
+ </View>
1519
+ </Pressable>
1520
+ {inline && open ? (
1521
+ <View style={styles.inlineTool}>
1522
+ <ScrollView
1523
+ style={{ maxHeight: Math.max(160, Math.round(window.height * 0.35)) }}
1524
+ contentContainerStyle={styles.inlineReasoningContent}
1525
+ showsVerticalScrollIndicator
1526
+ >
1527
+ <Text selectable style={[styles.bodyText, { color: theme.colors.foreground }]}>{content}</Text>
1528
+ </ScrollView>
1529
+ </View>
1530
+ ) : null}
1531
+ {inline ? null : (
1532
+ <DetailSheet
1533
+ open={open}
1534
+ onClose={() => setOpen(false)}
1535
+ title={verb}
1536
+ icon="ListChecks"
1537
+ theme={theme}
1538
+ copyValue={content}
1539
+ >
1540
+ <Text selectable style={[styles.bodyText, { color: theme.colors.foreground }]}>{content}</Text>
1541
+ </DetailSheet>
1542
+ )}
1543
+ </View>
1544
+ );
1545
+ }
1546
+
1292
1547
  export function contributeTimeline(client: PluginClientContext): () => void {
1293
1548
  const cleanups = [
1294
1549
  client.addTimelineTransformer({
1295
1550
  id: "dsh-reasoning-row",
1296
1551
  query: { itemType: "reasoning" },
1297
1552
  transform({ item, phase }) {
1298
- if (item.type !== "reasoning" || item.text.trim() === "") return undefined;
1299
- return {
1300
- items: [{
1301
- type: "plugin" as const,
1302
- kind: "dsh-reasoning",
1303
- version: 1,
1304
- data: { text: item.text, phase },
1305
- }],
1306
- };
1553
+ return guard("timeline transformer dsh-reasoning", () => {
1554
+ if (item.type !== "reasoning" || item.text.trim() === "") return undefined;
1555
+ return {
1556
+ items: [{
1557
+ type: "plugin" as const,
1558
+ kind: "dsh-reasoning",
1559
+ version: 1,
1560
+ data: { text: item.text, phase },
1561
+ }],
1562
+ };
1563
+ }, undefined);
1307
1564
  },
1308
1565
  }),
1309
1566
  client.addTimelineRenderer({
1310
1567
  kind: "dsh-reasoning",
1311
1568
  version: 1,
1312
1569
  schema: reasoningSchema,
1313
- Component: ReasoningRow,
1570
+ Component: withPluginBoundary<PluginTimelineItemProps<ReasoningData>>(
1571
+ "dsh-reasoning",
1572
+ ReasoningRow,
1573
+ (props) => <FailedRow theme={props.theme} message={translateForLabel("timeline.row.renderFailed")} />,
1574
+ ),
1575
+ }),
1576
+ client.addTimelineTransformer({
1577
+ id: "dsh-todo-row",
1578
+ query: { itemType: "todo" },
1579
+ transform({ item }) {
1580
+ return guard("timeline transformer dsh-todo", () => {
1581
+ if (item.type !== "todo") return undefined;
1582
+ const items = item.items.flatMap((entry) => {
1583
+ const text = typeof entry.text === "string" ? entry.text : "";
1584
+ if (text === "") return [];
1585
+ const status = typeof entry.status === "string"
1586
+ ? entry.status
1587
+ : entry.completed
1588
+ ? "completed"
1589
+ : "pending";
1590
+ return [{
1591
+ text,
1592
+ status,
1593
+ ...(typeof entry.activeForm === "string" ? { activeForm: entry.activeForm } : {}),
1594
+ }];
1595
+ });
1596
+ if (items.length === 0) return undefined;
1597
+ return {
1598
+ items: [{
1599
+ type: "plugin" as const,
1600
+ kind: "dsh-todo",
1601
+ version: 1,
1602
+ data: { items },
1603
+ }],
1604
+ };
1605
+ }, undefined);
1606
+ },
1607
+ }),
1608
+ client.addTimelineRenderer({
1609
+ kind: "dsh-todo",
1610
+ version: 1,
1611
+ schema: todoSchema,
1612
+ Component: withPluginBoundary<PluginTimelineItemProps<TodoData>>(
1613
+ "dsh-todo",
1614
+ TodoRow,
1615
+ (props) => <FailedRow theme={props.theme} message={translateForLabel("timeline.row.renderFailed")} />,
1616
+ ),
1314
1617
  }),
1315
1618
  client.addTimelineTransformer({
1316
1619
  id: "dsh-tool-row",
1317
1620
  query: { itemType: "tool_call" },
1318
1621
  transform({ item, phase }) {
1319
- if (item.type !== "tool_call") return undefined;
1320
- const detail = isRecord(item.detail) ? item.detail : undefined;
1321
- const type = stringField(detail, "type");
1322
- // Keep Paseo's richer cards for semantic helpers; every other tool gets
1323
- // the shared row so a provider-specific name never shows up bare.
1324
- const nativeCard = type === "sub_agent"
1325
- || type === "worktree_setup"
1326
- || type === "plain_text"
1327
- || type === "plan";
1328
- if (nativeCard) return undefined;
1329
- const error = item.error === null || item.error === undefined ? undefined : String(
1330
- isRecord(item.error) && typeof item.error.message === "string" ? item.error.message : item.error,
1331
- );
1332
- return {
1333
- items: [{
1334
- type: "plugin" as const,
1335
- kind: "dsh-tool",
1336
- version: 1,
1337
- data: {
1338
- name: item.name,
1339
- status: item.status,
1340
- ...(detail === undefined ? {} : { detail: toJson(detail) }),
1341
- ...(item.callId === undefined ? {} : { callId: item.callId }),
1342
- ...(error === undefined ? {} : { error }),
1343
- phase,
1344
- },
1345
- }],
1346
- };
1622
+ return guard("timeline transformer dsh-tool", () => {
1623
+ if (item.type !== "tool_call") return undefined;
1624
+ const detail = isRecord(item.detail) ? item.detail : undefined;
1625
+ const type = stringField(detail, "type");
1626
+ // A finished `todo_write` is drawn by the checklist row above; keeping
1627
+ // its tool row too would show one call twice.
1628
+ if (
1629
+ item.name === "todo_write"
1630
+ && item.status === "completed"
1631
+ && todoEntries(detailInput(detail)).length > 0
1632
+ ) {
1633
+ return { items: [] };
1634
+ }
1635
+ // Keep Paseo's richer cards for semantic helpers; every other tool gets
1636
+ // the shared row so a provider-specific name never shows up bare, and an
1637
+ // unfamiliar tool falls back to the generic wrench row instead of the
1638
+ // host's own styling.
1639
+ const nativeCard = type === "sub_agent"
1640
+ || type === "worktree_setup"
1641
+ || type === "plan";
1642
+ if (nativeCard) return undefined;
1643
+ const error = item.error === null || item.error === undefined ? undefined : String(
1644
+ isRecord(item.error) && typeof item.error.message === "string" ? item.error.message : item.error,
1645
+ );
1646
+ return {
1647
+ items: [{
1648
+ type: "plugin" as const,
1649
+ kind: "dsh-tool",
1650
+ version: 1,
1651
+ data: {
1652
+ name: item.name,
1653
+ status: item.status,
1654
+ ...(detail === undefined ? {} : { detail: toJson(detail) }),
1655
+ ...(item.callId === undefined ? {} : { callId: item.callId }),
1656
+ ...(error === undefined ? {} : { error }),
1657
+ phase,
1658
+ },
1659
+ }],
1660
+ };
1661
+ }, undefined);
1347
1662
  },
1348
1663
  }),
1349
1664
  client.addTimelineRenderer({
1350
1665
  kind: "dsh-tool",
1351
1666
  version: 1,
1352
1667
  schema: toolSchema,
1353
- Component: ToolRow,
1668
+ Component: withPluginBoundary<PluginTimelineItemProps<ToolData>>(
1669
+ "dsh-tool",
1670
+ ToolRow,
1671
+ (props) => <FailedRow theme={props.theme} message={translateForLabel("timeline.row.renderFailed")} />,
1672
+ ),
1354
1673
  }),
1355
1674
  ];
1356
1675
  return () => {