@keyou007/agent-bot 0.1.27-alpha.2 → 0.1.27-alpha.4

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +78 -13
  3. package/README.zh.md +78 -13
  4. package/assets/agent-bot.ico +0 -0
  5. package/assets/roboto-mono-OFL.txt +93 -0
  6. package/assets/roboto-mono-latin.woff2 +0 -0
  7. package/assets/workspace-drafts.js +88 -0
  8. package/assets/workspace-sessions.js +1935 -232
  9. package/assets/workspace.css +360 -35
  10. package/assets/workspace.js +2115 -249
  11. package/dist/cli/SelfUpdateObserver.js +124 -0
  12. package/dist/cli/SelfUpdateObserver.js.map +1 -0
  13. package/dist/cli/SelfUpdateRunner.js +267 -70
  14. package/dist/cli/SelfUpdateRunner.js.map +1 -1
  15. package/dist/cli/SelfUpdater.js +54 -15
  16. package/dist/cli/SelfUpdater.js.map +1 -1
  17. package/dist/cli/controlProtocol.js.map +1 -1
  18. package/dist/cli/help.js +6 -0
  19. package/dist/cli/help.js.map +1 -1
  20. package/dist/cli.js +85 -6
  21. package/dist/cli.js.map +1 -1
  22. package/dist/codex/CodexEventMapper.js +29 -5
  23. package/dist/codex/CodexEventMapper.js.map +1 -1
  24. package/dist/codex/CodexRuntime.js +3 -0
  25. package/dist/codex/CodexRuntime.js.map +1 -1
  26. package/dist/feishu/CardRenderer.js +45 -13
  27. package/dist/feishu/CardRenderer.js.map +1 -1
  28. package/dist/feishu/ConsoleFeishuClient.js +4 -0
  29. package/dist/feishu/ConsoleFeishuClient.js.map +1 -1
  30. package/dist/feishu/FeishuMarkdown.js +2 -14
  31. package/dist/feishu/FeishuMarkdown.js.map +1 -1
  32. package/dist/feishu/FeishuMessageClient.js +9 -0
  33. package/dist/feishu/FeishuMessageClient.js.map +1 -1
  34. package/dist/feishu/FeishuTurnPresenter.js +26 -14
  35. package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
  36. package/dist/index.js +47 -12
  37. package/dist/index.js.map +1 -1
  38. package/dist/local-files/DiagramPreview.js +11 -6
  39. package/dist/local-files/DiagramPreview.js.map +1 -1
  40. package/dist/local-files/GitDiffPreview.js +40 -10
  41. package/dist/local-files/GitDiffPreview.js.map +1 -1
  42. package/dist/local-files/LiveMarkup.js +104 -0
  43. package/dist/local-files/LiveMarkup.js.map +1 -0
  44. package/dist/local-files/LocalFileViewerServer.js +219 -129
  45. package/dist/local-files/LocalFileViewerServer.js.map +1 -1
  46. package/dist/local-files/MarkdownExport.js +54 -0
  47. package/dist/local-files/MarkdownExport.js.map +1 -0
  48. package/dist/local-files/PreviewCodeFont.js +11 -0
  49. package/dist/local-files/PreviewCodeFont.js.map +1 -0
  50. package/dist/local-files/PreviewSyntaxHighlight.js +73 -0
  51. package/dist/local-files/PreviewSyntaxHighlight.js.map +1 -1
  52. package/dist/local-files/ToolCommandDisplay.js +111 -0
  53. package/dist/local-files/ToolCommandDisplay.js.map +1 -0
  54. package/dist/local-files/TurnPreviewPage.js +23 -269
  55. package/dist/local-files/TurnPreviewPage.js.map +1 -1
  56. package/dist/local-files/WorkspaceFileEvents.js +206 -0
  57. package/dist/local-files/WorkspaceFileEvents.js.map +1 -0
  58. package/dist/local-files/WorkspaceFiles.js +79 -3
  59. package/dist/local-files/WorkspaceFiles.js.map +1 -1
  60. package/dist/local-files/WorkspaceImages.js +15 -0
  61. package/dist/local-files/WorkspaceImages.js.map +1 -0
  62. package/dist/local-files/WorkspacePage.js +20 -5
  63. package/dist/local-files/WorkspacePage.js.map +1 -1
  64. package/dist/local-files/WorkspaceSessions.js +881 -79
  65. package/dist/local-files/WorkspaceSessions.js.map +1 -1
  66. package/dist/local-files/WorkspaceTimeline.js +105 -0
  67. package/dist/local-files/WorkspaceTimeline.js.map +1 -0
  68. package/dist/presentation/OutboundRouter.js +13 -6
  69. package/dist/presentation/OutboundRouter.js.map +1 -1
  70. package/dist/presentation/TurnStateReducer.js +28 -21
  71. package/dist/presentation/TurnStateReducer.js.map +1 -1
  72. package/dist/proxy/ProxySessionController.js +229 -92
  73. package/dist/proxy/ProxySessionController.js.map +1 -1
  74. package/dist/proxy/TaskMetadata.js +86 -0
  75. package/dist/proxy/TaskMetadata.js.map +1 -0
  76. package/dist/scheduling/ScheduleCards.js +10 -4
  77. package/dist/scheduling/ScheduleCards.js.map +1 -1
  78. package/dist/scheduling/ScheduleCommand.js +4 -0
  79. package/dist/scheduling/ScheduleCommand.js.map +1 -1
  80. package/dist/scheduling/ScheduledTaskStore.js +51 -12
  81. package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
  82. package/dist/scheduling/types.js +18 -4
  83. package/dist/scheduling/types.js.map +1 -1
  84. package/dist/state/StateStore.js +145 -19
  85. package/dist/state/StateStore.js.map +1 -1
  86. package/dist/state/TurnPreviewJournal.js +143 -36
  87. package/dist/state/TurnPreviewJournal.js.map +1 -1
  88. package/dist/state/TurnToolText.js +172 -0
  89. package/dist/state/TurnToolText.js.map +1 -0
  90. package/dist/state/migrations.js +4 -0
  91. package/dist/state/migrations.js.map +1 -1
  92. package/dist/supervision/SafeRestartNotifier.js +9 -6
  93. package/dist/supervision/SafeRestartNotifier.js.map +1 -1
  94. package/dist/terminal/TerminalPage.js +5 -0
  95. package/dist/terminal/TerminalPage.js.map +1 -1
  96. package/dist/updates/AutomaticUpdatePreparer.js +63 -12
  97. package/dist/updates/AutomaticUpdatePreparer.js.map +1 -1
  98. package/dist/updates/ManualUpdateController.js +7 -2
  99. package/dist/updates/ManualUpdateController.js.map +1 -1
  100. package/dist/utils/promptAttachments.js +20 -0
  101. package/dist/utils/promptAttachments.js.map +1 -0
  102. package/dist/utils/toolTimestamp.js +6 -0
  103. package/dist/utils/toolTimestamp.js.map +1 -0
  104. package/npm-shrinkwrap.json +2 -2
  105. package/package.json +1 -1
  106. package/skills/agent-bot/SKILL.md +23 -2
  107. package/src/cli/SelfUpdateObserver.ts +111 -0
  108. package/src/cli/SelfUpdateRunner.ts +271 -85
  109. package/src/cli/SelfUpdater.ts +53 -16
  110. package/src/cli/controlProtocol.ts +1 -0
  111. package/src/cli/help.ts +6 -0
  112. package/src/cli.ts +71 -5
  113. package/src/codex/CodexEventMapper.ts +25 -5
  114. package/src/codex/CodexRuntime.ts +4 -0
  115. package/src/feishu/CardRenderer.ts +48 -13
  116. package/src/feishu/ConsoleFeishuClient.ts +6 -1
  117. package/src/feishu/FeishuMarkdown.ts +2 -14
  118. package/src/feishu/FeishuMessageClient.ts +10 -0
  119. package/src/feishu/FeishuTurnPresenter.ts +22 -8
  120. package/src/feishu/types.ts +1 -0
  121. package/src/index.ts +47 -12
  122. package/src/local-files/DiagramPreview.ts +11 -6
  123. package/src/local-files/GitDiffPreview.ts +38 -10
  124. package/src/local-files/LiveMarkup.ts +103 -0
  125. package/src/local-files/LocalFileViewerServer.ts +207 -132
  126. package/src/local-files/MarkdownExport.ts +54 -0
  127. package/src/local-files/PreviewCodeFont.ts +12 -0
  128. package/src/local-files/PreviewSyntaxHighlight.ts +75 -0
  129. package/src/local-files/ToolCommandDisplay.ts +104 -0
  130. package/src/local-files/TurnPreviewPage.ts +23 -254
  131. package/src/local-files/WorkspaceFileEvents.ts +186 -0
  132. package/src/local-files/WorkspaceFiles.ts +72 -5
  133. package/src/local-files/WorkspaceImages.ts +10 -0
  134. package/src/local-files/WorkspacePage.ts +20 -5
  135. package/src/local-files/WorkspaceSessions.ts +811 -82
  136. package/src/local-files/WorkspaceTimeline.ts +109 -0
  137. package/src/presentation/OutboundRouter.ts +15 -4
  138. package/src/presentation/TurnStateReducer.ts +27 -18
  139. package/src/presentation/turnViewTypes.ts +2 -0
  140. package/src/proxy/ProxySessionController.ts +226 -77
  141. package/src/proxy/TaskMetadata.ts +81 -0
  142. package/src/runtime/types.ts +2 -1
  143. package/src/scheduling/ScheduleCards.ts +10 -4
  144. package/src/scheduling/ScheduleCommand.ts +4 -0
  145. package/src/scheduling/ScheduledTaskStore.ts +54 -9
  146. package/src/scheduling/types.ts +24 -4
  147. package/src/state/StateStore.ts +157 -20
  148. package/src/state/TurnPreviewJournal.ts +138 -34
  149. package/src/state/TurnToolText.ts +156 -0
  150. package/src/state/migrations.ts +4 -0
  151. package/src/supervision/SafeRestartNotifier.ts +9 -6
  152. package/src/terminal/TerminalPage.ts +5 -0
  153. package/src/updates/AutomaticUpdatePreparer.ts +52 -11
  154. package/src/updates/ManualUpdateController.ts +8 -3
  155. package/src/utils/promptAttachments.ts +24 -0
  156. package/src/utils/toolTimestamp.ts +5 -0
@@ -0,0 +1,111 @@
1
+ import { displayToolCommand, formatShellCommandForDisplay } from "../feishu/CardRenderer.js";
2
+ export function previewToolHeading(tool, commandLabel) {
3
+ const repl = isReplTool(tool);
4
+ const command = tool.command || (tool.kind === "command" && shellPayload(tool.title) ? tool.title : undefined);
5
+ const display = renderableToolCommand(command, repl);
6
+ const fallback = repl ? "REPL" : command?.trim() ? (tool.kind === "command" ? commandLabel : tool.kind) : tool.title.trim() || tool.kind;
7
+ return { title: display ? summarizeToolCommand(display) : fallback, command: display ? true : undefined, repl: repl ? true : undefined };
8
+ }
9
+ export function summarizeToolCommand(command) {
10
+ const summary = command.replace(/[\\`^][ \t]*\r?\n/gu, " ").replace(/\s+/gu, " ").trim();
11
+ if (summary.length <= 160)
12
+ return summary;
13
+ return `${summary.slice(0, 157).trimEnd()}…`;
14
+ }
15
+ export function normalizeToolOutput(value) {
16
+ return value.replace(/\r\n?/gu, "\n").trim();
17
+ }
18
+ export function formatPreviewToolCommand(command) {
19
+ const normalized = (shellPayload(command) || command).replace(/\r\n?/gu, "\n").trim();
20
+ const newline = normalized.indexOf("\n");
21
+ if (newline >= 0) {
22
+ const name = normalized.slice(0, newline).trim();
23
+ const payload = normalized.slice(newline + 1).trim();
24
+ if (name) {
25
+ try {
26
+ const parsed = JSON.parse(payload);
27
+ if (parsed && typeof parsed === "object")
28
+ return `${name}\n${JSON.stringify(parsed, null, 2)}`;
29
+ }
30
+ catch {
31
+ // A multiline shell command need not contain JSON arguments.
32
+ }
33
+ }
34
+ }
35
+ return formatShellCommandForDisplay(normalized);
36
+ }
37
+ function shellPayload(command) {
38
+ const value = command.trim();
39
+ const unwrapped = displayToolCommand(value);
40
+ if (unwrapped !== undefined || !value.endsWith("…"))
41
+ return unwrapped;
42
+ // Saved summaries can end before the shell wrapper's closing quote.
43
+ return displayToolCommand(value + "'") ?? displayToolCommand(value + '"');
44
+ }
45
+ export function isReplTool(tool) {
46
+ const title = tool.title.trim();
47
+ const titleLooksLikeToolName = title.length <= 120 && !/[\s"'`]/u.test(title);
48
+ return tool.kind.toLowerCase().includes("repl")
49
+ || (titleLooksLikeToolName && /(?:^|[._-])repl(?:$|[._-])/iu.test(title));
50
+ }
51
+ export function renderableToolCommand(command, repl) {
52
+ if (!command)
53
+ return undefined;
54
+ if (!repl)
55
+ return formatPreviewToolCommand(command);
56
+ const normalized = (shellPayload(command) || command).trim();
57
+ const newline = normalized.indexOf("\n");
58
+ if (newline >= 0) {
59
+ try {
60
+ const parsed = JSON.parse(normalized.slice(newline + 1).trim());
61
+ if (parsed && typeof parsed === "object") {
62
+ for (const key of ["input", "code", "script", "javascript", "source"]) {
63
+ const value = parsed[key];
64
+ if (typeof value === "string" && value.trim())
65
+ return formatReplSource(value);
66
+ }
67
+ }
68
+ }
69
+ catch {
70
+ // Keep the original payload when a provider uses a non-JSON argument format.
71
+ }
72
+ }
73
+ return formatReplSource(newline >= 0 ? normalized.slice(0, newline) : normalized);
74
+ }
75
+ function formatReplSource(source) {
76
+ const normalized = source.replace(/\r\n?/gu, "\n").trim();
77
+ if (normalized.includes("\n"))
78
+ return normalized;
79
+ const lines = [];
80
+ let current = "";
81
+ let quote;
82
+ let escaped = false;
83
+ for (const character of normalized) {
84
+ current += character;
85
+ if (escaped) {
86
+ escaped = false;
87
+ continue;
88
+ }
89
+ if (character === "\\" && quote) {
90
+ escaped = true;
91
+ continue;
92
+ }
93
+ if (quote) {
94
+ if (character === quote)
95
+ quote = undefined;
96
+ continue;
97
+ }
98
+ if (character === "'" || character === "\"" || character === "`") {
99
+ quote = character;
100
+ continue;
101
+ }
102
+ if (character === ";") {
103
+ lines.push(current.trim());
104
+ current = "";
105
+ }
106
+ }
107
+ if (current.trim())
108
+ lines.push(current.trim());
109
+ return lines.join("\n");
110
+ }
111
+ //# sourceMappingURL=ToolCommandDisplay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolCommandDisplay.js","sourceRoot":"","sources":["../../src/local-files/ToolCommandDisplay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAW7F,MAAM,UAAU,kBAAkB,CAAC,IAAiB,EAAE,YAAoB;IACxE,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAC/G,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC;IACzI,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,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pB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,OAAO,IAAI,SAAS,CAAC;QACrB,IAAI,OAAO,EAAE,CAAC;YAAC,OAAO,GAAG,KAAK,CAAC;YAAC,SAAS;QAAC,CAAC;QAC3C,IAAI,SAAS,KAAK,IAAI,IAAI,KAAK,EAAE,CAAC;YAAC,OAAO,GAAG,IAAI,CAAC;YAAC,SAAS;QAAC,CAAC;QAC9D,IAAI,KAAK,EAAE,CAAC;YAAC,IAAI,SAAS,KAAK,KAAK;gBAAE,KAAK,GAAG,SAAS,CAAC;YAAC,SAAS;QAAC,CAAC;QACpE,IAAI,SAAS,KAAK,GAAG,IAAI,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YAAC,KAAK,GAAG,SAAS,CAAC;YAAC,SAAS;QAAC,CAAC;QAClG,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;YAC3B,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -5,12 +5,16 @@ import path from "node:path";
5
5
  import { enableDiagramFences, DIAGRAM_PREVIEW_CLIENT_SCRIPT, DIAGRAM_PREVIEW_CSS } from "./DiagramPreview.js";
6
6
  import MarkdownIt from "markdown-it";
7
7
  import { highlightPreviewCode, PREVIEW_SYNTAX_CSS } from "./PreviewSyntaxHighlight.js";
8
- import { displayFilePath, displayToolCommand, formatShellCommandForDisplay, toolStatusIcon } from "../feishu/CardRenderer.js";
8
+ import { displayFilePath, toolStatusIcon } from "../feishu/CardRenderer.js";
9
+ import { isReplTool, normalizeToolOutput, previewToolHeading, renderableToolCommand } from "./ToolCommandDisplay.js";
9
10
  import { turnReasoningItems } from "../presentation/turnReasoning.js";
10
11
  import { visibleTurnActivities } from "../presentation/visibleTurnActivities.js";
11
12
  import { formatModelQueueDuration, liveModelQueueActivity, systemActivityQuote, USER_ACTIVITY_ICON } from "../presentation/turnActivity.js";
12
13
  import { displayRuntimeError } from "../runtime/responseErrors.js";
13
14
  import { isFileUrl, rewriteMarkdownFileLinks } from "./MarkdownFileLinks.js";
15
+ import { toolTimestamp } from "../utils/toolTimestamp.js";
16
+ import { MARKDOWN_EXPORT_CLIENT_SCRIPT, turnAnswerFilename } from "./MarkdownExport.js";
17
+ import { LIVE_MARKUP_CLIENT_SCRIPT } from "./LiveMarkup.js";
14
18
  const MARKDOWN = new MarkdownIt({
15
19
  breaks: true,
16
20
  html: false,
@@ -137,7 +141,7 @@ export function detectTurnPreviewLanguage(acceptLanguage) {
137
141
  .sort((left, right) => right.quality - left.quality || left.index - right.index);
138
142
  return /^zh(?:[-_]|$)/iu.test(candidates[0]?.tag ?? "") ? "zh" : "en";
139
143
  }
140
- export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() => {
144
+ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + MARKDOWN_EXPORT_CLIENT_SCRIPT + LIVE_MARKUP_CLIENT_SCRIPT + `(() => {
141
145
  const eventsUrl = document.body.dataset.eventsUrl;
142
146
  const content = document.getElementById("turn-content");
143
147
  const metadata = document.getElementById("turn-metadata");
@@ -160,35 +164,6 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
160
164
  copyFailed: isChinese ? "复制失败,请检查浏览器剪贴板权限后重试。" : "Copy failed. Check clipboard permissions and retry.",
161
165
  downloadFailed: isChinese ? "下载失败,请重试。" : "Download failed. Please retry.",
162
166
  };
163
- const copyMarkdownFallback = (text) => {
164
- const active = document.activeElement;
165
- const selection = window.getSelection?.();
166
- const ranges = selection ? Array.from({ length: selection.rangeCount }, (_, i) => selection.getRangeAt(i).cloneRange()) : [];
167
- const textarea = document.createElement("textarea");
168
- textarea.value = text;
169
- textarea.readOnly = true;
170
- textarea.style.cssText = "position:fixed;top:0;left:0;width:1px;height:1px;opacity:0;pointer-events:none";
171
- document.body.append(textarea);
172
- try {
173
- textarea.focus({ preventScroll: true });
174
- textarea.select();
175
- textarea.setSelectionRange(0, text.length);
176
- if (!document.execCommand?.("copy")) throw new Error("Clipboard unavailable");
177
- } finally {
178
- textarea.remove();
179
- active?.focus?.({ preventScroll: true });
180
- if (selection) {
181
- selection.removeAllRanges();
182
- for (const range of ranges) selection.addRange(range);
183
- }
184
- }
185
- };
186
- const copyMarkdown = async (text) => {
187
- if (window.navigator?.clipboard?.writeText) {
188
- try { await window.navigator.clipboard.writeText(text); return; } catch {}
189
- }
190
- copyMarkdownFallback(text);
191
- };
192
167
  const answerActionsInFlight = new WeakSet();
193
168
  content.addEventListener("click", async (event) => {
194
169
  const button = event.target.closest?.("button[data-answer-action]");
@@ -202,21 +177,8 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
202
177
  button.disabled = true;
203
178
  try {
204
179
  const markdown = new TextDecoder("utf-8", { ignoreBOM: true }).decode(Uint8Array.from(atob(section.dataset.answerMarkdown), (char) => char.charCodeAt(0)));
205
- if (action === "copy") await copyMarkdown(markdown);
206
- else {
207
- const url = URL.createObjectURL(new Blob([markdown], { type: "text/markdown;charset=utf-8" }));
208
- const link = document.createElement("a");
209
- try {
210
- link.href = url;
211
- link.download = section.dataset.answerFilename;
212
- link.hidden = true;
213
- document.body.append(link);
214
- link.click();
215
- } finally {
216
- link.remove();
217
- setTimeout(() => URL.revokeObjectURL(url), 1000);
218
- }
219
- }
180
+ if (action === "copy") await window.agentBotMarkdown.copy(markdown);
181
+ else window.agentBotMarkdown.download(markdown, section.dataset.answerFilename);
220
182
  if (feedback) feedback.textContent = action === "copy" ? labels.copied : labels.downloaded;
221
183
  } catch {
222
184
  if (feedback) feedback.textContent = action === "copy" ? labels.copyFailed : labels.downloadFailed;
@@ -246,7 +208,7 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
246
208
  document.querySelectorAll("[data-live-tool-duration]").forEach((element) => {
247
209
  const startedAt = Number(element.dataset.startedAt);
248
210
  const completedAt = Number(element.dataset.completedAt) || Date.now();
249
- if (!Number.isFinite(startedAt)) return;
211
+ if (!Number.isFinite(startedAt) || startedAt <= 0) return;
250
212
  const seconds = Math.max(0, Math.floor((completedAt - startedAt) / 1000));
251
213
  const hours = Math.floor(seconds / 3600);
252
214
  const minutes = Math.floor((seconds % 3600) / 60);
@@ -304,106 +266,7 @@ export const TURN_PREVIEW_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() =
304
266
  }
305
267
  };
306
268
 
307
- const nodeKey = (node) => {
308
- if (node.nodeType !== 1) return undefined;
309
- for (const attribute of ["data-preview-key", "data-activity", "data-activity-id", "data-scroll-id", "data-reasoning-field", "data-reasoning-part"]) {
310
- if (node.hasAttribute(attribute)) return attribute + ":" + node.getAttribute(attribute);
311
- }
312
- if (node.tagName === "IMG") return "image:" + node.getAttribute("src");
313
- // Keep Markdown image paragraphs/links anchored when text is inserted before them.
314
- if (["P", "A", "FIGURE", "PICTURE"].includes(node.tagName)) {
315
- const image = node.querySelector("img");
316
- if (image) return node.tagName + ":image:" + image.getAttribute("src");
317
- }
318
- for (const name of ["markdown", "tool-command", "tool-image", "files", "tool-header", "tool-body", "tool-footer"]) {
319
- if (node.classList.contains(name)) return node.tagName + ":" + name;
320
- }
321
- return undefined;
322
- };
323
- const compatible = (current, next) => current.nodeType === next.nodeType && current.nodeName === next.nodeName;
324
- const patchNode = (current, next) => {
325
- if (!compatible(current, next)) {
326
- current.replaceWith(next.cloneNode(true));
327
- return;
328
- }
329
- // Summary snapshots never own a detail body that has already been fetched.
330
- if (current.nodeType === 1 && current.hasAttribute("data-detail-body") && next.hasAttribute("data-detail-body")) return;
331
- if (current.isEqualNode(next)) return;
332
- if (current.nodeType !== 1) {
333
- if (current.nodeValue !== next.nodeValue) current.nodeValue = next.nodeValue;
334
- return;
335
- }
336
- if (current.hasAttribute("data-diagram") && next.hasAttribute("data-diagram")) {
337
- const code = current.querySelector(".diagram-source code");
338
- const nextCode = next.querySelector(".diagram-source code");
339
- if (code && nextCode && code.textContent !== nextCode.textContent) {
340
- code.textContent = nextCode.textContent;
341
- window.agentBotDiagrams.refresh(current);
342
- }
343
- return;
344
- }
345
- const preserveOpen = current.tagName === "DETAILS";
346
- for (const attribute of Array.from(current.attributes)) {
347
- if (preserveOpen && attribute.name === "open") continue;
348
- if (!next.hasAttribute(attribute.name)) current.removeAttribute(attribute.name);
349
- }
350
- for (const attribute of Array.from(next.attributes)) {
351
- if (preserveOpen && attribute.name === "open") continue;
352
- if (current.getAttribute(attribute.name) !== attribute.value) current.setAttribute(attribute.name, attribute.value);
353
- }
354
- patchChildren(current, next);
355
- };
356
- const patchChildren = (parent, next) => {
357
- const nextChildren = Array.from(next.childNodes);
358
- const nextKeys = new Set(nextChildren.map(nodeKey).filter((key) => key !== undefined));
359
- const remaining = new Set(Array.from(parent.childNodes));
360
- const keyed = new Map();
361
- for (const child of remaining) {
362
- const key = nodeKey(child);
363
- if (key === undefined) continue;
364
- if (!nextKeys.has(key)) {
365
- child.remove();
366
- remaining.delete(child);
367
- continue;
368
- }
369
- const matches = keyed.get(key) || [];
370
- matches.push(child);
371
- keyed.set(key, matches);
372
- }
373
- let cursor = parent.firstChild;
374
- for (const child of nextChildren) {
375
- const key = nodeKey(child);
376
- const matches = key === undefined ? undefined : keyed.get(key);
377
- const current = key === undefined
378
- ? cursor && nodeKey(cursor) === undefined && compatible(cursor, child) ? cursor : undefined
379
- : matches?.find((candidate) => remaining.has(candidate) && compatible(candidate, child));
380
- if (current) {
381
- remaining.delete(current);
382
- // Drop obsolete text/markup before a retained block without detaching that block.
383
- while (cursor && cursor !== current && nodeKey(cursor) === undefined) {
384
- const obsolete = cursor;
385
- cursor = cursor.nextSibling;
386
- remaining.delete(obsolete);
387
- obsolete.remove();
388
- }
389
- if (current !== cursor) {
390
- if (typeof parent.moveBefore === "function" && current.isConnected) parent.moveBefore(current, cursor);
391
- else parent.insertBefore(current, cursor);
392
- }
393
- patchNode(current, child);
394
- cursor = current.nextSibling;
395
- } else {
396
- const added = child.cloneNode(true);
397
- parent.insertBefore(added, cursor);
398
- }
399
- }
400
- for (const child of remaining) child.remove();
401
- };
402
- const patchMarkup = (element, markup) => {
403
- const template = document.createElement("template");
404
- template.innerHTML = markup;
405
- patchChildren(element, template.content);
406
- };
269
+ const { nodeKey, patchNode, patchMarkup } = window.agentBotLiveMarkup;
407
270
  const detailStates = new WeakMap();
408
271
  const detailState = (details) => {
409
272
  if (!detailStates.has(details)) detailStates.set(details, {});
@@ -750,7 +613,7 @@ function renderApprovalNotice(request, renderText, language) {
750
613
  }
751
614
  function renderFinalAnswer(markdown, turnId, renderText, language) {
752
615
  const labels = previewLabels(language);
753
- const filename = `turn-${turnId.replace(/[^A-Za-z0-9_-]/gu, "_").slice(0, 80) || "answer"}.md`;
616
+ const filename = turnAnswerFilename(turnId);
754
617
  const icon = (paths) => `<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${paths}</svg>`;
755
618
  const button = (action, label, paths) => `<button type="button" class="answer-action" data-answer-action="${action}" title="${escapeAttribute(label)}" aria-label="${escapeAttribute(label)}">${icon(paths)}</button>`;
756
619
  const actions = button("download", labels.downloadMarkdown, '<path d="M12 3v12m-5-5 5 5 5-5M5 16v5h14v-5"/>')
@@ -892,15 +755,8 @@ function renderMessageImages(paths, localFileUrl, language) {
892
755
  }
893
756
  function renderToolActivity(activityId, tool, localFileUrl, fullToolOutputs, fullToolErrors, language = "zh", projectCwd, deferDetails = false) {
894
757
  const labels = previewLabels(language);
895
- const command = tool.command ? (displayToolCommand(tool.command) || tool.command.trim()) : undefined;
896
- const repl = isReplTool(tool);
897
- const displayCommand = repl
898
- ? formatReplCommand(command ?? "")
899
- : command
900
- ? formatToolCommand(command)
901
- : undefined;
902
- const title = displayCommand ? summarizeToolCommand(displayCommand) : toolTitle(tool, command, repl, language);
903
- const titleMarkup = displayCommand
758
+ const { title, command } = previewToolHeading(tool, labels.command);
759
+ const titleMarkup = command
904
760
  ? `<code class="tool-command-title">${escapeHtml(title)}</code>`
905
761
  : `<span class="tool-title">${escapeHtml(title)}</span>`;
906
762
  const timing = renderToolTiming(tool, "header");
@@ -915,13 +771,12 @@ function renderToolActivity(activityId, tool, localFileUrl, fullToolOutputs, ful
915
771
  }
916
772
  function renderToolBody(activityId, tool, localFileUrl, fullToolOutputs, fullToolErrors, language = "zh", projectCwd) {
917
773
  const labels = previewLabels(language);
918
- const command = tool.command ? (displayToolCommand(tool.command) || tool.command.trim()) : undefined;
919
774
  const repl = isReplTool(tool);
920
- const displayCommand = repl ? formatReplCommand(command ?? "") : command ? formatToolCommand(command) : undefined;
775
+ const displayCommand = renderableToolCommand(tool.command, repl);
921
776
  const status = `<span class="tool-state ${tool.status}">${escapeHtml(toolStatusLabel(tool.status, language))}</span>`;
922
777
  const output = fullToolOutputs?.[tool.id] ?? tool.output;
923
778
  const error = fullToolErrors?.[tool.id] ?? tool.error;
924
- const sameError = Boolean(output && error && normalizeOutput(output) === normalizeOutput(error));
779
+ const sameError = Boolean(output && error && normalizeToolOutput(output) === normalizeToolOutput(error));
925
780
  const displayOutput = output && repl && !sameError ? formatReplOutput(output) : output;
926
781
  const displayError = sameError ? undefined : error;
927
782
  const detailParts = [
@@ -943,117 +798,15 @@ function renderToolBody(activityId, tool, localFileUrl, fullToolOutputs, fullToo
943
798
  export function renderToolFooter(tool, characterCount, language) {
944
799
  const labels = previewLabels(language);
945
800
  const status = `<span class="tool-state ${tool.status}">${escapeHtml(toolStatusLabel(tool.status, language))}</span>`;
946
- const startedAt = tool.startedAt === undefined ? undefined : new Date(tool.startedAt);
801
+ const timestamp = toolTimestamp(tool.startedAt);
802
+ const startedAt = timestamp === undefined ? undefined : new Date(timestamp);
947
803
  const startTime = startedAt
948
804
  ? `<time datetime="${startedAt.toISOString()}" title="${escapeAttribute(labels.startingTime)}">${new Intl.DateTimeFormat(language === "zh" ? "zh-CN" : "en-GB", { hour: "2-digit", minute: "2-digit", second: "2-digit", hourCycle: "h23" }).format(startedAt)}</time>`
949
805
  : `<span title="${escapeAttribute(labels.startingTime)}">${escapeHtml(labels.unknown)}</span>`;
950
806
  return `${status}${startTime}${renderToolTiming(tool, "footer")}<span>${formatNumber(characterCount)} ${escapeHtml(labels.characters)}</span>`;
951
807
  }
952
- function toolTitle(tool, command, repl = false, language = "zh") {
953
- if (repl)
954
- return "REPL";
955
- if (command)
956
- return tool.kind === "command" ? previewLabels(language).command : tool.kind;
957
- const title = tool.title.trim();
958
- return title || tool.kind;
959
- }
960
- function summarizeToolCommand(command) {
961
- const summary = command.replace(/[\\`^][ \t]*\r?\n/gu, " ").replace(/\s+/gu, " ").trim();
962
- if (summary.length <= 160)
963
- return summary;
964
- return `${summary.slice(0, 157).trimEnd()}…`;
965
- }
966
- function isReplTool(tool) {
967
- const title = tool.title.trim();
968
- const titleLooksLikeToolName = title.length <= 120 && !/[\s"'`]/u.test(title);
969
- return tool.kind.toLowerCase().includes("repl")
970
- || (titleLooksLikeToolName && /(?:^|[._-])repl(?:$|[._-])/iu.test(title));
971
- }
972
- function formatReplCommand(command) {
973
- const normalized = command.trim();
974
- const newline = normalized.indexOf("\n");
975
- if (newline >= 0) {
976
- const payload = normalized.slice(newline + 1).trim();
977
- try {
978
- const parsed = JSON.parse(payload);
979
- if (parsed && typeof parsed === "object") {
980
- for (const key of ["input", "code", "script", "javascript", "source"]) {
981
- const value = parsed[key];
982
- if (typeof value === "string" && value.trim())
983
- return formatReplSource(value);
984
- }
985
- }
986
- }
987
- catch {
988
- // Keep the original payload when a provider uses a non-JSON argument format.
989
- }
990
- }
991
- return formatReplSource(newline >= 0 ? normalized.slice(0, newline) : normalized);
992
- }
993
- function formatToolCommand(command) {
994
- const normalized = command.replace(/\r\n?/gu, "\n").trim();
995
- const newline = normalized.indexOf("\n");
996
- if (newline >= 0) {
997
- const name = normalized.slice(0, newline).trim();
998
- const payload = normalized.slice(newline + 1).trim();
999
- const formattedPayload = formatJsonPayload(payload);
1000
- if (name && formattedPayload)
1001
- return `${name}\n${formattedPayload}`;
1002
- }
1003
- return formatShellCommandForDisplay(normalized);
1004
- }
1005
- function formatJsonPayload(value) {
1006
- try {
1007
- const parsed = JSON.parse(value);
1008
- if (parsed && typeof parsed === "object")
1009
- return JSON.stringify(parsed, null, 2);
1010
- }
1011
- catch {
1012
- // Keep non-JSON tool arguments in their original readable form.
1013
- }
1014
- return undefined;
1015
- }
1016
- function formatReplSource(source) {
1017
- const normalized = source.replace(/\r\n?/gu, "\n").trim();
1018
- if (normalized.includes("\n"))
1019
- return normalized;
1020
- const lines = [];
1021
- let current = "";
1022
- let quote;
1023
- let escaped = false;
1024
- for (const character of normalized) {
1025
- current += character;
1026
- if (escaped) {
1027
- escaped = false;
1028
- continue;
1029
- }
1030
- if (character === "\\" && quote) {
1031
- escaped = true;
1032
- continue;
1033
- }
1034
- if (quote) {
1035
- if (character === quote)
1036
- quote = undefined;
1037
- continue;
1038
- }
1039
- if (character === "'" || character === "\"" || character === "`") {
1040
- quote = character;
1041
- continue;
1042
- }
1043
- if (character === ";") {
1044
- lines.push(current.trim());
1045
- current = "";
1046
- }
1047
- }
1048
- if (current.trim())
1049
- lines.push(current.trim());
1050
- return lines.join("\n");
1051
- }
1052
- function normalizeOutput(value) {
1053
- return value.replace(/\r\n?/gu, "\n").trim();
1054
- }
1055
808
  function formatReplOutput(value) {
1056
- const normalized = normalizeOutput(value);
809
+ const normalized = normalizeToolOutput(value);
1057
810
  if (!normalized)
1058
811
  return normalized;
1059
812
  try {
@@ -1098,7 +851,7 @@ function renderToolTiming(tool, placement) {
1098
851
  if (duration === undefined) {
1099
852
  return `<span class="${className}">?</span>`;
1100
853
  }
1101
- const live = tool.status === "running" && tool.completedAt === undefined;
854
+ const live = tool.status === "running" && toolTimestamp(tool.completedAt) === undefined;
1102
855
  return `<span class="${className}"${live ? ` data-live-tool-duration data-started-at="${tool.startedAt}" data-short-duration="1"` : ""}>${formatShortDuration(duration)}</span>`;
1103
856
  }
1104
857
  function formatShortDuration(duration) {
@@ -1234,10 +987,11 @@ function toolStatusLabel(status, language) {
1234
987
  : previewLabels(language).toolStatuses.running;
1235
988
  }
1236
989
  function toolDuration(tool) {
1237
- if (tool.startedAt === undefined)
990
+ const start = toolTimestamp(tool.startedAt);
991
+ if (start === undefined)
1238
992
  return undefined;
1239
- const end = tool.completedAt ?? (tool.status === "running" ? Date.now() : undefined);
1240
- return end === undefined ? undefined : formatDuration(end - tool.startedAt);
993
+ const end = toolTimestamp(tool.completedAt) ?? (tool.status === "running" ? Date.now() : undefined);
994
+ return end === undefined ? undefined : formatDuration(end - start);
1241
995
  }
1242
996
  function formatDuration(durationMs) {
1243
997
  const seconds = Math.max(0, Math.floor(durationMs / 1_000));