@songsid/agend 2.4.0-alpha.1 → 2.4.0-alpha.2

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 (235) hide show
  1. package/README.md +1 -1
  2. package/README.zh-TW.md +1 -1
  3. package/dist/agent-whats-new.js +2 -0
  4. package/dist/agent-whats-new.js.map +1 -1
  5. package/dist/auth-api.js +3 -1
  6. package/dist/auth-api.js.map +1 -1
  7. package/dist/backend/claude-code.js +4 -0
  8. package/dist/backend/claude-code.js.map +1 -1
  9. package/dist/backend/types.d.ts +6 -0
  10. package/dist/backend/types.js.map +1 -1
  11. package/dist/backend-availability.d.ts +1 -1
  12. package/dist/backend-availability.js +28 -1
  13. package/dist/backend-availability.js.map +1 -1
  14. package/dist/browser-backend-signins.d.ts +7 -1
  15. package/dist/browser-backend-signins.js +8 -4
  16. package/dist/browser-backend-signins.js.map +1 -1
  17. package/dist/build-provenance.json +1 -1
  18. package/dist/channel/mcp-tools.js +1 -1
  19. package/dist/channel/mcp-tools.js.map +1 -1
  20. package/dist/config-validator.js +47 -7
  21. package/dist/config-validator.js.map +1 -1
  22. package/dist/daemon.d.ts +3 -0
  23. package/dist/daemon.js +4 -0
  24. package/dist/daemon.js.map +1 -1
  25. package/dist/fleet-manager.d.ts +33 -4
  26. package/dist/fleet-manager.js +143 -61
  27. package/dist/fleet-manager.js.map +1 -1
  28. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +19 -0
  29. package/dist/hub/audit/index.js +12 -5
  30. package/dist/hub/audit/index.js.map +1 -1
  31. package/dist/hub/catalog.d.ts +6 -0
  32. package/dist/hub/catalog.js +14 -4
  33. package/dist/hub/catalog.js.map +1 -1
  34. package/dist/hub/client.js +2 -0
  35. package/dist/hub/client.js.map +1 -1
  36. package/dist/hub/compose/member.d.ts +2 -0
  37. package/dist/hub/compose/member.js +11 -2
  38. package/dist/hub/compose/member.js.map +1 -1
  39. package/dist/hub/compose/server.js +2 -1
  40. package/dist/hub/compose/server.js.map +1 -1
  41. package/dist/hub/enrolment-code.d.ts +126 -0
  42. package/dist/hub/enrolment-code.js +266 -0
  43. package/dist/hub/enrolment-code.js.map +1 -0
  44. package/dist/hub/group-policy/admin-impact.js +4 -2
  45. package/dist/hub/group-policy/admin-impact.js.map +1 -1
  46. package/dist/hub/group-policy/admin-inventory.js +6 -6
  47. package/dist/hub/group-policy/admin-inventory.js.map +1 -1
  48. package/dist/hub/group-policy/authorization.d.ts +16 -2
  49. package/dist/hub/group-policy/authorization.js +69 -5
  50. package/dist/hub/group-policy/authorization.js.map +1 -1
  51. package/dist/hub/group-policy/impact-inventory.js +3 -3
  52. package/dist/hub/group-policy/impact-inventory.js.map +1 -1
  53. package/dist/hub/group-policy/resources.d.ts +40 -1
  54. package/dist/hub/group-policy/resources.js +51 -13
  55. package/dist/hub/group-policy/resources.js.map +1 -1
  56. package/dist/hub/group-policy/store.d.ts +6 -0
  57. package/dist/hub/group-policy/store.js +49 -4
  58. package/dist/hub/group-policy/store.js.map +1 -1
  59. package/dist/hub/http/compose.js +30 -6
  60. package/dist/hub/http/compose.js.map +1 -1
  61. package/dist/hub/init/text.js +2 -2
  62. package/dist/hub/init/text.js.map +1 -1
  63. package/dist/hub/init/web.d.ts +7 -0
  64. package/dist/hub/init/web.js +6 -1
  65. package/dist/hub/init/web.js.map +1 -1
  66. package/dist/hub/join/local.d.ts +27 -0
  67. package/dist/hub/join/local.js +70 -5
  68. package/dist/hub/join/local.js.map +1 -1
  69. package/dist/hub/join/receipt.d.ts +1 -0
  70. package/dist/hub/join/receipt.js +1 -1
  71. package/dist/hub/join/receipt.js.map +1 -1
  72. package/dist/hub/join/service.d.ts +92 -6
  73. package/dist/hub/join/service.js +199 -28
  74. package/dist/hub/join/service.js.map +1 -1
  75. package/dist/hub/join/store.d.ts +2 -1
  76. package/dist/hub/join/store.js +7 -7
  77. package/dist/hub/join/store.js.map +1 -1
  78. package/dist/hub/member/exposure-api.d.ts +2 -0
  79. package/dist/hub/member/exposure-api.js +3 -2
  80. package/dist/hub/member/exposure-api.js.map +1 -1
  81. package/dist/hub/member/exposures.d.ts +4 -0
  82. package/dist/hub/member/exposures.js +12 -2
  83. package/dist/hub/member/exposures.js.map +1 -1
  84. package/dist/hub/member/pairing-notices.js +8 -6
  85. package/dist/hub/member/pairing-notices.js.map +1 -1
  86. package/dist/hub/pairing-notices.d.ts +5 -2
  87. package/dist/hub/pairing-notices.js +38 -13
  88. package/dist/hub/pairing-notices.js.map +1 -1
  89. package/dist/hub/pairing.d.ts +7 -2
  90. package/dist/hub/protocol.d.ts +47 -0
  91. package/dist/hub/protocol.js +3 -1
  92. package/dist/hub/protocol.js.map +1 -1
  93. package/dist/hub/server.js +15 -1
  94. package/dist/hub/server.js.map +1 -1
  95. package/dist/hub/types.d.ts +12 -4
  96. package/dist/hub-pairing-summary.js +1 -1
  97. package/dist/hub-pairing-summary.js.map +1 -1
  98. package/dist/instance-config-impact.js +4 -0
  99. package/dist/instance-config-impact.js.map +1 -1
  100. package/dist/instance-lifecycle.js +4 -0
  101. package/dist/instance-lifecycle.js.map +1 -1
  102. package/dist/locale.js +6 -2
  103. package/dist/locale.js.map +1 -1
  104. package/dist/log-service.d.ts +62 -6
  105. package/dist/log-service.js +135 -28
  106. package/dist/log-service.js.map +1 -1
  107. package/dist/log-steps-agy-grok.d.ts +74 -0
  108. package/dist/log-steps-agy-grok.js +440 -0
  109. package/dist/log-steps-agy-grok.js.map +1 -0
  110. package/dist/log-steps.d.ts +62 -3
  111. package/dist/log-steps.js +188 -22
  112. package/dist/log-steps.js.map +1 -1
  113. package/dist/log-transcript-paths.d.ts +29 -0
  114. package/dist/log-transcript-paths.js +109 -0
  115. package/dist/log-transcript-paths.js.map +1 -0
  116. package/dist/login-controller.d.ts +17 -3
  117. package/dist/login-controller.js +57 -5
  118. package/dist/login-controller.js.map +1 -1
  119. package/dist/login-window-lock.d.ts +20 -8
  120. package/dist/login-window-lock.js +35 -16
  121. package/dist/login-window-lock.js.map +1 -1
  122. package/dist/outbound-handlers.d.ts +14 -0
  123. package/dist/outbound-handlers.js +49 -1
  124. package/dist/outbound-handlers.js.map +1 -1
  125. package/dist/profile-signins.d.ts +2 -0
  126. package/dist/profile-signins.js +1 -1
  127. package/dist/profile-signins.js.map +1 -1
  128. package/dist/settings-api.d.ts +34 -0
  129. package/dist/settings-api.js +184 -6
  130. package/dist/settings-api.js.map +1 -1
  131. package/dist/settings-change.js +38 -1
  132. package/dist/settings-change.js.map +1 -1
  133. package/dist/settings-effect.js +14 -0
  134. package/dist/settings-effect.js.map +1 -1
  135. package/dist/tool-progress.d.ts +7 -0
  136. package/dist/tool-progress.js +21 -9
  137. package/dist/tool-progress.js.map +1 -1
  138. package/dist/types.d.ts +13 -0
  139. package/dist/ui/accounts-view.js +14 -4
  140. package/dist/ui/agent-details-settings.js +2 -2
  141. package/dist/ui/agent-page-strings.js +2 -2
  142. package/dist/ui/backend-signin.js +47 -14
  143. package/dist/ui/chat-activity-groups.js +225 -0
  144. package/dist/ui/chat-activity.js +355 -0
  145. package/dist/ui/chat-popout-header.js +35 -0
  146. package/dist/ui/chat-popout-transport.js +80 -0
  147. package/dist/ui/chat-popout.js +63 -0
  148. package/dist/ui/chat-quote.js +3 -1
  149. package/dist/ui/chat-store.js +45 -4
  150. package/dist/ui/chat-workspace-gestures.js +177 -0
  151. package/dist/ui/chat-workspace-navigation.js +34 -10
  152. package/dist/ui/chat-workspace.js +96 -32
  153. package/dist/ui/host-install.js +2 -2
  154. package/dist/ui/hub-agent-copy.js +7 -7
  155. package/dist/ui/hub-chat-strings.js +3 -3
  156. package/dist/ui/hub-client.js +77 -17
  157. package/dist/ui/hub-company-join-strings.js +12 -10
  158. package/dist/ui/hub-company-join.js +52 -39
  159. package/dist/ui/hub-confirm-place.js +44 -0
  160. package/dist/ui/hub-directory-editor-strings.js +3 -3
  161. package/dist/ui/hub-directory-notice-strings.js +1 -1
  162. package/dist/ui/hub-enrolment-code-strings.js +44 -0
  163. package/dist/ui/hub-enrolment-code.js +159 -0
  164. package/dist/ui/hub-group-search.js +82 -0
  165. package/dist/ui/hub-group-strings.js +8 -8
  166. package/dist/ui/hub-join-approval.js +31 -0
  167. package/dist/ui/hub-join-code-input.js +66 -0
  168. package/dist/ui/hub-join-queue.js +62 -0
  169. package/dist/ui/hub-join-steps.js +231 -0
  170. package/dist/ui/hub-joincode-flow-strings.js +22 -0
  171. package/dist/ui/hub-owner-strings.js +9 -9
  172. package/dist/ui/hub-pairing-progress-strings.js +1 -1
  173. package/dist/ui/hub-quick-pairing.js +8 -4
  174. package/dist/ui/hub-quick-strings.js +11 -11
  175. package/dist/ui/hub-share-refused.js +17 -0
  176. package/dist/ui/hub-strings.js +61 -61
  177. package/dist/ui/hub-this-hub.js +2 -2
  178. package/dist/ui/hub-welcome.js +26 -5
  179. package/dist/ui/image-annotate.js +283 -0
  180. package/dist/ui/image-lightbox.js +26 -6
  181. package/dist/ui/log-row.js +327 -0
  182. package/dist/ui/panel-chat.js +151 -12
  183. package/dist/ui/panel-details.js +14 -6
  184. package/dist/ui/panel-hub.js +42 -13
  185. package/dist/ui/panel-log.js +9 -154
  186. package/dist/ui/panel-settings.js +48 -11
  187. package/dist/ui/search-dialog.js +1 -0
  188. package/dist/ui/settings-access-overview.js +1 -1
  189. package/dist/ui/settings-hub-browser-certificate.js +3 -3
  190. package/dist/ui/settings-hub-company-join.js +41 -30
  191. package/dist/ui/settings-hub-connection.js +8 -5
  192. package/dist/ui/settings-hub-membership.js +3 -3
  193. package/dist/ui/settings-hub-section.js +1 -1
  194. package/dist/ui/settings-hub-setup-strings.js +6 -6
  195. package/dist/ui/settings-hub-setup.js +44 -6
  196. package/dist/ui/settings-hub.js +35 -10
  197. package/dist/ui/settings-layout.js +6 -4
  198. package/dist/ui/settings-public-session-strings.js +37 -0
  199. package/dist/ui/settings-registry.js +4 -0
  200. package/dist/ui/settings-strings.js +2 -2
  201. package/dist/ui/shared/app-shell.js +16 -10
  202. package/dist/ui/shared/app.css +195 -30
  203. package/dist/ui/shared/app.js +8 -1
  204. package/dist/ui/shared/chat-render.js +11 -2
  205. package/dist/ui/shared/chat-thread.js +20 -3
  206. package/dist/ui/shared/chat-work-bar.css +7 -0
  207. package/dist/ui/shared/chat-workspace-model.js +39 -9
  208. package/dist/ui/shared/hub-owner.css +8 -0
  209. package/dist/ui/shared/identity-color.js +9 -3
  210. package/dist/ui/shared/image-annotate.css +45 -0
  211. package/dist/ui/shared/instance-nav.js +59 -22
  212. package/dist/ui/shared/pane-geometry.js +29 -0
  213. package/dist/ui/shared/signin.js +2 -2
  214. package/dist/ui/shared/tokens.css +14 -0
  215. package/dist/ui/shared/ui-menu.js +22 -7
  216. package/dist/ui/signin.html +1 -1
  217. package/dist/ui/structured-signin.js +11 -4
  218. package/dist/web-api.d.ts +1 -0
  219. package/dist/web-api.js +34 -4
  220. package/dist/web-api.js.map +1 -1
  221. package/dist/web-backend-login.d.ts +9 -3
  222. package/dist/web-backend-login.js +7 -4
  223. package/dist/web-backend-login.js.map +1 -1
  224. package/dist/web-chat-history.d.ts +11 -0
  225. package/dist/web-chat-history.js +9 -1
  226. package/dist/web-chat-history.js.map +1 -1
  227. package/dist/web-guest-access.js +2 -2
  228. package/dist/web-guest-access.js.map +1 -1
  229. package/dist/web-session.d.ts +31 -3
  230. package/dist/web-session.js +25 -4
  231. package/dist/web-session.js.map +1 -1
  232. package/dist/web-settings-patch.d.ts +8 -2
  233. package/dist/web-settings-patch.js +22 -10
  234. package/dist/web-settings-patch.js.map +1 -1
  235. package/package.json +1 -1
@@ -0,0 +1,327 @@
1
+ // AGEND-181: one step of an instance's work as a row — shared by the Log tab (panel-log.js) and the chat's activity
2
+ // timeline (chat-activity.js), so a step looks and behaves the same in both: its icon, words, status, and its arguments
3
+ // and output on demand. Masking and cutting are the server's (log-steps.ts); this only shows what it is given.
4
+ import { html, useState } from "/assets/app-html.js";
5
+ import { register, t } from "/assets/app-i18n.js";
6
+ import { Icon } from "/assets/ui-icons.js";
7
+ import "/assets/chat-strings.js";
8
+ import { chatTime, chatTimeFull } from "/assets/chat-time.js";
9
+
10
+ register("log", {
11
+ en: {
12
+ user: "Asked", assistant: "Replied", error: "Error", errorCode: "Error {0}", turnEnd: "Turn ended", turnEndIn: "Turn ended · {0}",
13
+ compacted: "Conversation compacted", turn: "Turn",
14
+ running: "running", done: "done", failed: "failed", interrupted: "interrupted", exit: "exit {0}",
15
+ showScreen: "Show what was on screen", hideScreen: "Hide what was on screen",
16
+ showOutput: "Show output", hideOutput: "Hide output", args: "Arguments", output: "Output", noOutput: "No output.",
17
+ showAll: "Show all", showLess: "Show less", cut: "… {0} more characters not shown.", tooLarge: "Output of {0}: only its start is shown.",
18
+ times: "×{0}", newer: "{0} new",
19
+ cat_read: "Read", cat_edit: "Edit", cat_search: "Search", cat_run: "Run", cat_web: "Web", cat_mcp: "MCP", cat_agent: "Sub-agent",
20
+ cat_plan: "Plan", cat_message: "Message", cat_other: "Tool", plan_items: "{0} items",
21
+ said: "Said", thinking: "Thinking", thinkingMore: "Show all thinking", thinkingLess: "Show less",
22
+ expand: "Show details", collapse: "Hide details", command: "Command", removed: "Removed", added: "Added",
23
+ },
24
+ "zh-TW": {
25
+ user: "收到要求", assistant: "回覆", error: "錯誤", errorCode: "錯誤 {0}", turnEnd: "回合結束", turnEndIn: "回合結束 · {0}",
26
+ compacted: "對話已壓縮", turn: "回合",
27
+ running: "執行中", done: "完成", failed: "失敗", interrupted: "中斷", exit: "結束碼 {0}",
28
+ showScreen: "顯示當時的畫面", hideScreen: "隱藏當時的畫面",
29
+ showOutput: "顯示輸出", hideOutput: "隱藏輸出", args: "參數", output: "輸出", noOutput: "沒有輸出。",
30
+ showAll: "顯示全部", showLess: "收合", cut: "… 還有 {0} 個字元沒有顯示。", tooLarge: "輸出共 {0},只顯示開頭。",
31
+ times: "×{0}", newer: "{0} 則新的",
32
+ cat_read: "讀取", cat_edit: "編輯", cat_search: "搜尋", cat_run: "執行", cat_web: "網頁", cat_mcp: "MCP", cat_agent: "子 agent",
33
+ cat_plan: "計畫", cat_message: "訊息", cat_other: "工具", plan_items: "{0} 項",
34
+ said: "說了", thinking: "思考", thinkingMore: "顯示完整思考", thinkingLess: "收合",
35
+ expand: "顯示細節", collapse: "隱藏細節", command: "指令", removed: "移除", added: "新增",
36
+ },
37
+ });
38
+ const tl = (key, ...a) => t(`log.${key}`, ...a);
39
+ export { tl };
40
+
41
+ /** A text longer than this many lines is folded until opened. */
42
+ const FOLD_LINES = 8;
43
+ /** A thinking row shows this much of its text until opened. */
44
+ export const THINK_PREVIEW = 150;
45
+
46
+ /**
47
+ * AGEND-200 (the preview feedback, read against Multica's own transcript): what a step shows in the block is its one most
48
+ * informative thing, once. Display only — the step still holds the full text, which the row's title and the Log tab show.
49
+ */
50
+ /**
51
+ * `<shell> [-flags] '<script>'` or `"<script>"`, then optionally plain word arguments (`bash -lc 'cmd' name arg` — $0, $1…).
52
+ * The quoted script ends at ITS closing quote (not the last quote of the line: `bash -c 'a' && echo 'b'` is two commands, and is
53
+ * not unwrapped). Anything but plain words after it (`&&`, `;`, a pipe, a redirect, `$x`) leaves the command as it was.
54
+ */
55
+ const SHELL_WRAPPER = /^(?:\/[\w./-]*\/)?(?:zsh|bash|sh|fish)\s+(?:-[a-z]+\s+)*(?:'([^']*)'|"((?:[^"\\]|\\[\s\S])*)")((?:\s+[^\s;&|<>$`()'"\\]+)*)$/;
56
+ /** `bash -lc '<cmd>'` (what Codex runs every command through) is the command: the wrapper is noise in a one-line summary. */
57
+ export function stripShellWrapper(command) {
58
+ const m = SHELL_WRAPPER.exec(String(command || "").trim());
59
+ if (!m) return String(command || "");
60
+ return m[1] !== undefined ? m[1] : m[2].replace(/\\(["\\$`])/g, "$1");
61
+ }
62
+ /**
63
+ * A path with more than three parts as `.../parent/leaf`, so a row stays one line (a path inside the working directory is
64
+ * already relative). A Windows path (`C:\Users\me\proj\src\a.ts`, or a mix of both slashes) is cut the same way, and
65
+ * keeps its own separator.
66
+ */
67
+ export function shortPath(p) {
68
+ const text = String(p || "");
69
+ if (/\s/.test(text) || text.includes(",")) return text; // not one path (a Grep's "pattern in dir", several files)
70
+ const parts = text.split(/[\\/]/);
71
+ if (parts.length <= 3) return text;
72
+ return `...${text.includes("/") ? "/" : "\\"}${parts.slice(-2).join(text.includes("/") ? "/" : "\\")}`;
73
+ }
74
+ const NAMED_BY_SUBJECT = new Set(["file_path", "path", "notebook_path", "pattern", "url", "query", "description", "command", "cmd", "offset", "limit",
75
+ "timeout", "run_in_background", "replace_all", "output_mode", "glob", "type", "head_limit", "max_results", "subagent_type",
76
+ // antigravity (CommandLine, Path, Cwd…) and grok (target_file, target_directory, task_id…): what log-steps-agy-grok.ts names a step by
77
+ "CommandLine", "Cwd", "SafeToAutoRun", "WaitMsBeforeAsync", "Path", "Action", "target_file", "target_directory", "task_id", "task_ids"]);
78
+ /**
79
+ * What the arguments add to the row's title: a command (shown once, as code), an edit (old and new text), the rest as the
80
+ * server sent it — and nothing when the title already says it all (only a path, a pattern, a limit…). A raw JSON block is
81
+ * for a tool this does not recognise, or a text the server cut (which does not parse).
82
+ */
83
+ export function inputView(x, cat) {
84
+ const raw = x.input;
85
+ if (!raw) return null;
86
+ let o = null;
87
+ try { const v = JSON.parse(raw); if (v && typeof v === "object" && !Array.isArray(v)) o = v; } catch { /* cut or not JSON */ }
88
+ if (!o) return { raw };
89
+ const str = (v) => (typeof v === "string" ? v : null);
90
+ const cmd = cat === "run" ? str(o.command) ?? str(o.cmd) ?? str(o.CommandLine) : null;
91
+ if (cmd !== null) {
92
+ const extra = Object.keys(o).filter((k) => !NAMED_BY_SUBJECT.has(k));
93
+ return { code: stripShellWrapper(cmd), ...(extra.length ? { raw: JSON.stringify(Object.fromEntries(extra.map((k) => [k, o[k]])), null, 2) } : {}) };
94
+ }
95
+ if (str(o.old_string) !== null && str(o.new_string) !== null) return { diff: { old: o.old_string, next: o.new_string } };
96
+ const extra = Object.keys(o).filter((k) => !NAMED_BY_SUBJECT.has(k));
97
+ if (x.subject && !extra.length) return null;
98
+ return { raw };
99
+ }
100
+
101
+ const escRe = (x) => x.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
102
+ /**
103
+ * AGEND-181: a path under the instance's working directory shown relative, the home directory as `~` — display only
104
+ * (the step still holds the full text, which the row's title and the Log tab show). `paths`: { cwd?, home? }. A path
105
+ * that merely starts with the same letters (`/work/project-2` against `/work/project`) is left alone.
106
+ */
107
+ export function shortenPaths(text, paths) {
108
+ if (!text || !paths || (!paths.cwd && !paths.home)) return text;
109
+ let out = String(text);
110
+ for (const [base, bare, sub] of [[paths.cwd, ".", ""], [paths.home, "~", "~/"]]) {
111
+ if (!base || base.length < 2) continue;
112
+ const dir = base.replace(/[\\/]+$/, "");
113
+ if (!dir) continue;
114
+ // `<dir>/rest` → `rest` (or `~/rest`); `<dir>` alone → `.` (or `~`); never inside a longer name.
115
+ out = out.replace(new RegExp(`(^|[^A-Za-z0-9_.~-])${escRe(dir)}(?:[\\\\/]+|(?![A-Za-z0-9_.-]))`, "g"), (m, pre) => `${pre}${/[\\/]$/.test(m) ? sub : bare}`);
116
+ }
117
+ return out;
118
+ }
119
+
120
+ // The app's own SVG icons (never emoji: a device without an emoji font shows boxes).
121
+ export const CAT_ICON = { read: "file", edit: "edit", search: "search", run: "code", web: "globe", mcp: "plug", agent: "team", plan: "tasks", message: "send", other: "sliders" };
122
+ export const KIND_ICON = { user: "user", assistant: "bot", thinking: "wand", error: "alert", turn_end: "stop", state: "info", event: "bell" };
123
+
124
+ function size(bytes) {
125
+ if (bytes >= 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
126
+ if (bytes >= 1024) return `${Math.round(bytes / 1024)} KB`;
127
+ return `${bytes} B`;
128
+ }
129
+ function duration(ms) {
130
+ if (!(ms >= 0)) return "";
131
+ if (ms < 1000) return `${ms} ms`;
132
+ const s = ms / 1000;
133
+ if (s < 60) return `${s < 10 ? s.toFixed(1) : Math.round(s)} s`;
134
+ const m = Math.floor(s / 60);
135
+ return `${m} m ${Math.round(s - m * 60)} s`;
136
+ }
137
+ const eventLabel = (type) => { const k = `log.ev_${type}`; const v = t(k); return v === k ? String(type).replace(/_/g, " ") : v; };
138
+
139
+ /** The `turn` a merged step keeps: the one `first` names, else the one already known (`turn: ""` is "no evidence", not a turn). */
140
+ const kept = (first, known) => { const t = first || known; return t ? { turn: t } : {}; };
141
+
142
+ /**
143
+ * Merge `incoming` steps into `list` (array, in order): one with an id already there replaces it in place (a result
144
+ * completing its call); a new one is added — at the end, or before everything when `older`. Returns a new array.
145
+ */
146
+ export function mergeSteps(list, incoming, older = false) {
147
+ const at = new Map(list.map((s, i) => [s.id, i]));
148
+ const fresh = new Map();
149
+ const next = list.slice();
150
+ const added = [];
151
+ for (const s of incoming) {
152
+ const i = at.get(s.id);
153
+ if (i !== undefined) {
154
+ // An older page never overwrites what a newer read already said about the same step — except to name a call the
155
+ // newer page knew only by its result (the call's record was older than that page): its tool, subject and input.
156
+ // A newer read that saw only a call's result (the call was before where it read) never unnames the call: its tool,
157
+ // category and start time stay; the outcome is the newer read's.
158
+ // Prism #3709 R5: a read that saw only a call's result has no turn evidence (`turn: ""`) — it never erases the turn the
159
+ // call already gave (a fresh parser per cursor range), so a poll-by-poll Log groups exactly as a cold read does.
160
+ if (!older) next[i] = s.kind === "tool" && !s.tool && next[i].tool
161
+ ? { ...next[i], ...s, tool: next[i].tool, cat: next[i].cat, ts: next[i].ts, ...kept(s.turn, next[i].turn) }
162
+ : { ...next[i], ...s, ...kept(s.turn, next[i].turn) };
163
+ else if (next[i].kind === "tool" && !next[i].tool && s.tool) {
164
+ const { tool, cat, subject, input, ts } = s;
165
+ next[i] = { ...next[i], tool, cat, ...(subject !== undefined ? { subject } : {}), ...(input !== undefined ? { input } : {}), ...(ts ? { ts } : {}), ...kept(next[i].turn, s.turn) };
166
+ }
167
+ } else if (fresh.has(s.id)) {
168
+ // The same step twice in one answer (never from the server's parser, whose ids are unique): the later one wins.
169
+ added[fresh.get(s.id)] = { ...added[fresh.get(s.id)], ...s, ...kept(s.turn, added[fresh.get(s.id)].turn) };
170
+ } else { fresh.set(s.id, added.length); added.push(s); }
171
+ }
172
+ return older ? [...added, ...next] : [...next, ...added];
173
+ }
174
+
175
+ /** Steps and fleet events in one timeline: events placed by time among the steps (steps keep their file order). */
176
+ export function timeline(steps, events) {
177
+ const evs = events.slice().sort((a, b) => a.ts - b.ts || a.id - b.id);
178
+ const out = [];
179
+ let e = 0;
180
+ for (const s of steps) {
181
+ while (e < evs.length && s.ts > 0 && evs[e].ts <= s.ts) out.push({ kind: "event", ...evs[e++] });
182
+ out.push(s);
183
+ }
184
+ while (e < evs.length) out.push({ kind: "event", ...evs[e++] });
185
+ return out;
186
+ }
187
+
188
+ /** A step with an output to read (its text, or a result too large to keep). */
189
+ const hasOutput = (x) => !!(x.body || x.bodyBytes);
190
+ /**
191
+ * Consecutive identical finished tool steps (same tool, subject and status) as one row with a count: a loop shows. Only
192
+ * steps with nothing more to see are merged (AGEND-210): at `verbose` each run has its own output and arguments, and
193
+ * folding the later ones into the first would hide them — those stay one row each. At `standard` a step holds no output
194
+ * or arguments, so a loop still reads as one row.
195
+ */
196
+ export function collapse(items) {
197
+ const out = [];
198
+ for (const x of items) {
199
+ const prev = out[out.length - 1];
200
+ if (prev && x.kind === "tool" && prev.kind === "tool" && x.status !== "running" && prev.status === x.status
201
+ && prev.tool === x.tool && (prev.subject || "") === (x.subject || "") && prev.turn === x.turn
202
+ && !hasOutput(x) && !hasOutput(prev) && (prev.input || "") === (x.input || "")) {
203
+ prev.repeat = (prev.repeat || 1) + 1;
204
+ continue;
205
+ }
206
+ out.push({ ...x });
207
+ }
208
+ return out;
209
+ }
210
+
211
+
212
+ /** The one-line words of a step — its kind or category and what it acts on — for a header that names the current step. */
213
+ export function stepLine(x, paths) {
214
+ const short = (v) => shortenPaths(v, paths);
215
+ if (x.kind === "thinking") return tl("thinking");
216
+ if (x.kind === "assistant") return `${tl("said")}: ${short(String(x.body || "").replace(/\s+/g, " ").trim()).slice(0, 80)}`;
217
+ if (x.kind === "error") return x.note ? tl("errorCode", x.note) : tl("error");
218
+ const cat = x.cat || "other";
219
+ const subject = cat === "plan" && x.subject ? tl("plan_items", x.subject) : short(x.subject || x.tool || "");
220
+ return subject ? `${tl(`cat_${cat}`)} ${subject}` : tl(`cat_${cat}`);
221
+ }
222
+
223
+ /**
224
+ * One line of the Log. `chat`: in the chat's activity block (an assistant line is "Said"). `compact` (the block's rows,
225
+ * AGEND-197): no time column and no "done" word — a step line is its icon, its words, and only what is unusual about it
226
+ * (running, failed, interrupted, a non-zero exit); `latest` marks the newest step of a block still running.
227
+ */
228
+ export function LogRow({ x, prev, paths, chat, compact, latest }) {
229
+ const [open, setOpen] = useState(false);
230
+ const [full, setFull] = useState(false);
231
+ const short = (v) => shortenPaths(v, paths);
232
+ const time = x.ts ? chatTime(x.ts, { yesterday: (hm) => t("chat.yesterdayAt", hm) }) : "";
233
+ const title = x.ts ? chatTimeFull(x.ts) : "";
234
+ const newTurn = x.kind === "user" && prev && prev.turn !== x.turn;
235
+ const head = (icon, label, extra) => html`<div class="log-head"><span class="log-icon" aria-hidden="true"><${Icon} name=${icon} size=${14} /></span>
236
+ <span class="log-label">${label}</span>${extra || null}<span class="grow"></span>${compact ? null : html`<span class="log-time" title=${title}>${time}</span>`}</div>`;
237
+ const text = (raw, cut, bytes) => {
238
+ if (!raw) return null;
239
+ const body = short(raw);
240
+ const lines = body.split("\n").length;
241
+ const folded = !full && lines > FOLD_LINES;
242
+ return html`<div class=${`log-text${folded ? " folded" : ""}`}>${body}</div>
243
+ ${lines > FOLD_LINES ? html`<button type="button" class="link-btn log-more" onClick=${() => setFull(!full)}>${full ? tl("showLess") : tl("showAll")}</button>` : null}
244
+ ${cut ? html`<p class="note">${tl("cut", cut.toLocaleString())}</p>` : null}
245
+ ${bytes ? html`<p class="note">${tl("tooLarge", size(bytes))}</p>` : null}`;
246
+ };
247
+ // The chat's block (AGEND-200): a step is ONE line — icon on the timeline, what it did, its kind in a quiet word, its status,
248
+ // and a chevron when there is more; the whole line opens it (the same place for every step). Thinking and what the agent
249
+ // said show two lines of their text until opened. Nothing in here scrolls: a long output is cut per step ("Show all").
250
+ const chev = html`<span class="log-chev" aria-hidden="true"><${Icon} name="chevron" size=${12} /></span>`;
251
+ const line = (icon, label, tail, can, cls) => {
252
+ const inner = html`<span class="log-icon" aria-hidden="true"><${Icon} name=${icon} size=${14} /></span>${label}<span class="grow"></span>${tail || null}${can ? chev : html`<span class="log-chev none" aria-hidden="true"></span>`}`;
253
+ return can
254
+ ? html`<button type="button" class=${`log-head log-fold log-toggle${cls ? ` ${cls}` : ""}`} aria-expanded=${open ? "true" : "false"} onClick=${() => setOpen(!open)}>${inner}</button>`
255
+ : html`<div class="log-head">${inner}</div>`;
256
+ };
257
+ const note = (cut, bytes) => html`${cut ? html`<p class="note">${tl("cut", cut.toLocaleString())}</p>` : null}${bytes ? html`<p class="note">${tl("tooLarge", size(bytes))}</p>` : null}`;
258
+ let row;
259
+ if (compact && (x.kind === "thinking" || (x.kind === "assistant" && chat))) {
260
+ const think = x.kind === "thinking";
261
+ const body = think ? x.body || "" : short(x.body || "");
262
+ const more = body.length > 100 || body.includes("\n");
263
+ const shown = think && !open && more ? `${body.split("\n")[0].slice(0, THINK_PREVIEW)}…` : body;
264
+ row = html`${line(KIND_ICON[x.kind], html`<span class=${`log-sum ${think ? "log-think" : "log-said"}${open ? " open" : ""}`}>${shown}</span>`,
265
+ html`<span class="log-cat">${tl(think ? "thinking" : "said")}</span>`, more, "log-more")}
266
+ ${open && x.bodyCut ? html`<p class="note">${tl("cut", x.bodyCut.toLocaleString())}</p>` : null}`;
267
+ } else if (compact && x.kind === "tool") {
268
+ const cat = x.cat || "other";
269
+ const raw = x.subject || "";
270
+ const subject = cat === "plan" && raw ? tl("plan_items", raw) : cat === "run" ? stripShellWrapper(short(raw)) : cat === "read" || cat === "edit" ? shortPath(short(raw)) : short(raw);
271
+ const failed = x.status === "failed" || x.status === "interrupted" || (typeof x.exitCode === "number" && x.exitCode !== 0);
272
+ const running = x.status === "running";
273
+ const mark = running ? html`<span class="log-status running"><span class="spinner" aria-hidden="true"></span>${tl("running")}</span>`
274
+ : failed ? html`<span class=${`log-status ${x.status === "interrupted" ? "interrupted" : "failed"}`}>${tl(x.status === "interrupted" ? "interrupted" : "failed")}${typeof x.exitCode === "number" && x.exitCode !== 0 ? ` · ${tl("exit", x.exitCode)}` : ""}${x.durationMs ? ` · ${duration(x.durationMs)}` : ""}</span>` : null;
275
+ const view = inputView(x, cat);
276
+ const has = !!(x.body || x.bodyBytes || (view && (view.code || view.diff || view.raw)));
277
+ const middle = subject || x.tool || tl(`cat_${cat}`);
278
+ const kind = cat === "other" && x.tool ? (subject ? x.tool : "") : tl(`cat_${cat}`);
279
+ const label = html`<span class="log-sum"><span class="log-subject mono" title=${raw && subject !== raw ? raw : null}>${middle}</span>${x.repeat ? html` <span class="log-repeat">${tl("times", x.repeat)}</span>` : null}</span>`;
280
+ const tail = html`${kind ? html`<span class="log-cat">${kind}</span>` : null}${mark}`;
281
+ row = html`${line(CAT_ICON[cat] || CAT_ICON.other, label, tail, has)}
282
+ ${has && open ? html`<div class="log-detail">
283
+ ${view && view.code ? html`<pre class="log-code"><span class="log-prompt" aria-hidden="true">$ </span>${short(view.code)}</pre>${x.inputCut ? note(x.inputCut) : null}` : null}
284
+ ${view && view.diff ? html`<div class="log-diff">${view.diff.old ? html`<pre class="log-code rm" aria-label=${tl("removed")}>${short(view.diff.old)}</pre>` : null}${view.diff.next ? html`<pre class="log-code add" aria-label=${tl("added")}>${short(view.diff.next)}</pre>` : null}</div>` : null}
285
+ ${view && view.raw ? html`<div class="log-sec"><span class="log-sec-h">${tl("args")}</span><div class="log-text mono">${short(view.raw)}</div>${x.inputCut ? note(x.inputCut) : null}</div>` : null}
286
+ ${x.body || x.bodyBytes ? html`<div class="log-sec"><span class="log-sec-h">${tl("output")}</span>${text(x.body, x.bodyCut, x.bodyBytes)}</div>` : null}</div>` : null}`;
287
+ } else if (compact && x.kind === "error") {
288
+ row = html`${line(KIND_ICON.error, html`<span class="log-sum">${x.note ? tl("errorCode", x.note) : tl("error")}</span>`, null, false)}${text(x.body, x.bodyCut)}`;
289
+ } else if (x.kind === "event") {
290
+ // M-2269: a dialog or prompt AgEnD saw (the CLI never writes it to its transcript): its text as it was on screen,
291
+ // folded until asked for. Text only (a text node), masked by the server.
292
+ row = html`${head(KIND_ICON.event, eventLabel(x.type))}${x.detail ? html`<div class="log-text muted">${x.detail}</div>` : null}
293
+ ${x.screen ? html`<button type="button" class="link-btn log-toggle log-screen-toggle" aria-expanded=${open ? "true" : "false"} onClick=${() => setOpen(!open)}>${open ? tl("hideScreen") : tl("showScreen")}</button>` : null}
294
+ ${x.screen && open ? html`<div class="log-detail"><div class="log-text mono log-screen">${x.screen}</div></div>` : null}`;
295
+ } else if (x.kind === "user" || x.kind === "assistant") {
296
+ // In the chat's timeline an assistant line is what the agent said on the way (its replies are the bubbles): "Said".
297
+ row = html`${head(KIND_ICON[x.kind], x.kind === "assistant" && chat ? tl("said") : tl(x.kind))}${text(x.body, x.bodyCut)}`;
298
+ } else if (x.kind === "thinking") {
299
+ // AGEND-181: the model's thinking (admin only; the server sends it only then): folded to its start, opened on demand.
300
+ const body = x.body || "";
301
+ const more = body.length > THINK_PREVIEW || body.includes("\n");
302
+ row = html`${head(KIND_ICON.thinking, tl("thinking"))}
303
+ <div class=${`log-text log-think${open ? " open" : ""}`}>${open || !more ? body : `${body.split("\n")[0].slice(0, THINK_PREVIEW)}…`}</div>
304
+ ${more ? html`<button type="button" class="link-btn log-more" aria-expanded=${open ? "true" : "false"} onClick=${() => setOpen(!open)}>${open ? tl("thinkingLess") : tl("thinkingMore")}</button>` : null}
305
+ ${open && x.bodyCut ? html`<p class="note">${tl("cut", x.bodyCut.toLocaleString())}</p>` : null}`;
306
+ } else if (x.kind === "error") {
307
+ row = html`${head(KIND_ICON.error, x.note ? tl("errorCode", x.note) : tl("error"))}${text(x.body, x.bodyCut)}`;
308
+ } else if (x.kind === "turn_end") {
309
+ row = head(KIND_ICON.turn_end, x.durationMs ? tl("turnEndIn", duration(x.durationMs)) : tl("turnEnd"),
310
+ x.status && x.status !== "done" ? html`<span class=${`log-status ${x.status}`}>${tl(x.status)}</span>` : null);
311
+ } else if (x.kind === "state") {
312
+ row = head(KIND_ICON.state, x.note === "compacted" ? tl("compacted") : x.note || "");
313
+ } else {
314
+ const cat = x.cat || "other";
315
+ const subject = cat === "plan" && x.subject ? tl("plan_items", x.subject) : short(x.subject || "");
316
+ const quiet = compact && (x.status || "done") === "done" && !(typeof x.exitCode === "number" && x.exitCode !== 0);
317
+ const status = quiet ? null : html`<span class=${`log-status ${x.status || "done"}`}>${x.status === "running" ? html`<span class="spinner" aria-hidden="true"></span>` : null}${tl(x.status || "done")}${typeof x.exitCode === "number" && x.exitCode !== 0 ? ` · ${tl("exit", x.exitCode)}` : ""}${x.durationMs ? ` · ${duration(x.durationMs)}` : ""}</span>`;
318
+ const label = html`<span class="log-cat">${tl(`cat_${cat}`)}</span>${subject ? html` <span class="log-subject mono" title=${x.subject && subject !== x.subject ? x.subject : null}>${subject}</span>` : null}${x.tool && !subject ? html` <span class="log-tool mono muted">${x.tool}</span>` : null}`;
319
+ const has = !!(x.body || x.input || x.bodyBytes);
320
+ row = html`${head(CAT_ICON[cat] || CAT_ICON.other, label, html`${x.repeat ? html`<span class="log-repeat">${tl("times", x.repeat)}</span>` : null}${status}`)}
321
+ ${has ? html`<button type="button" class="link-btn log-toggle" aria-expanded=${open ? "true" : "false"} onClick=${() => setOpen(!open)}>${open ? tl("hideOutput") : tl("showOutput")}</button>` : null}
322
+ ${open ? html`<div class="log-detail">
323
+ ${x.input ? html`<div class="log-sec"><span class="log-sec-h">${tl("args")}</span><div class="log-text mono">${short(x.input)}</div>${x.inputCut ? html`<p class="note">${tl("cut", x.inputCut.toLocaleString())}</p>` : null}</div>` : null}
324
+ <div class="log-sec"><span class="log-sec-h">${tl("output")}</span>${x.body ? text(x.body, x.bodyCut, x.bodyBytes) : html`<p class="note">${tl("noOutput")}</p>`}</div></div>` : null}`;
325
+ }
326
+ return html`<li class=${`log-item k-${x.kind}${x.status ? ` s-${x.status}` : ""}${newTurn ? " turn-start" : ""}${compact ? " compact" : ""}${latest ? " latest" : ""}`}>${row}</li>`;
327
+ }
@@ -130,9 +130,42 @@ export function linkWorkBarCss(doc = typeof document !== "undefined" ? document
130
130
  }
131
131
  linkWorkBarCss();
132
132
 
133
+ import { activityInfo, activityInfoStore, activityOffered, activityPrefs, composeActivity, mountActivity, observeActivity, setActivityOn, setActivityThinking } from "./chat-activity.js";
133
134
  /** The composer's textarea (#2342: text put back into it is a step Ctrl+Z goes back from). */
134
135
  const composers = new Map(); // agent → current mounted refs, never a retained thread's stale closure
135
136
  const composerField = (name) => composers.get(name)?.input.current || null;
137
+ /**
138
+ * #3727 (M-2973): where the viewer's 「引用給 Agent」 can put a marked-up picture — this chat's composer (the new PNG as an
139
+ * attachment, and a reply to the message the picture is in), and in split chat the other pane's (the PNG, and a quote
140
+ * line naming the original, since a reply can only point into its own chat). Null when this chat has no composer to put
141
+ * it in (nothing to annotate for).
142
+ */
143
+ function annotateFor(name, img) {
144
+ if (!store || typeof File !== "function") return null;
145
+ const key = img?.closest?.(".msg[data-key]")?.getAttribute("data-key") || "";
146
+ const message = (store.state.msgs[name] || []).find((x) => msgKey(x) === key) || null;
147
+ const field = () => composerField(name);
148
+ const targets = [{ key: "self", label: t("lbAnnotateQuote.self"), quote: (file, live = () => true) => {
149
+ if (!field() || !live()) return false;
150
+ store.addFiles(name, [file]);
151
+ if (message) store.startReply(name, message);
152
+ field()?.focus();
153
+ return true;
154
+ } }];
155
+ const other = (appStore.get().chatWorkspace?.quoteTargets?.(name) || [])[0];
156
+ if (other && other.name) {
157
+ // insertPaneQuote heads the quote with the source chat's name itself: this is only what the message said (or the
158
+ // picture's name, for a message with no words).
159
+ const what = String(message?.text || "").replace(/\s+/g, " ").trim().slice(0, 160) || img?.querySelector?.("img")?.getAttribute("alt") || "📷";
160
+ // Prism on #3735: the picture and its quote go in under the pane's one live check (insert's commit) — a pane
161
+ // replaced or retired meanwhile gets neither, and the editor stays open.
162
+ targets.push({ key: "other", label: t("lbAnnotateQuote.other", other.name),
163
+ quote: async (file, live = () => true) => (await other.insert(what, () => store.addFiles(other.name, [file]), live)) === true });
164
+ }
165
+ return { targets, notice: (text) => toast(text, false) };
166
+ }
167
+ // #3727: the two quote targets' words, here so a page with an older chat dictionary still has them.
168
+ register("lbAnnotateQuote", { en: { self: "Quote to agent", other: "Quote to {0}" }, "zh-TW": { self: "引用給 Agent", other: "引用到 {0}" } });
136
169
  /** Cross-pane quote is plain draft text. It never copies a message id, executes a command or submits the composer. */
137
170
  export function insertPaneQuote(name, source, text, current = () => true) {
138
171
  const binding = composers.get(name), field = binding?.input.current;
@@ -159,12 +192,73 @@ export function insertPaneQuote(name, source, text, current = () => true) {
159
192
  }
160
193
  export const paneComposerReady = name => !!composerField(name);
161
194
 
195
+ /** A scoped pane can change width without changing text. Keep its existing 240px composer cap and IME ownership. */
196
+ function observeComposerWidth(field, current, composing) {
197
+ if (!field || typeof ResizeObserver !== "function") return () => {};
198
+ let alive = true, width = -1, deferred = false;
199
+ const resize = () => {
200
+ if (!alive || !current()) return;
201
+ const next = field.getBoundingClientRect().width;
202
+ if (next === width && !deferred) return;
203
+ if (composing()) { deferred = true; return; }
204
+ width = next; deferred = false;
205
+ field.style.height = "auto";
206
+ if (field.value) field.style.height = `${Math.min(field.scrollHeight, 240)}px`;
207
+ };
208
+ let frame = null;
209
+ const schedule = () => {
210
+ if (frame !== null || (field.getBoundingClientRect().width === width && !deferred)) return;
211
+ // Height writes happen outside ResizeObserver delivery, avoiding a self-generated resize loop.
212
+ frame = setTimeout(() => { frame = null; resize(); }, 0);
213
+ };
214
+ const ended = () => queueMicrotask(resize);
215
+ const observer = new ResizeObserver(schedule); observer.observe(field);
216
+ field.addEventListener("compositionend", ended); field.addEventListener("blur", ended); resize();
217
+ return () => { alive = false; clearTimeout(frame); observer.disconnect(); field.removeEventListener("compositionend", ended); field.removeEventListener("blur", ended); };
218
+ }
219
+
220
+
221
+ /** #3637: private, write-only local draft handoff; never send, upload or share an outgoing queue. */
222
+ export const popoutDraftVersion = 1;
223
+ export const popoutDraftReady = () => !!store && ["captureDraft", "draftCurrent", "clearCapturedDraft", "acceptDraft"].every(key => typeof store[key] === "function");
224
+ export function capturePaneDraft(name) {
225
+ const owner = store;
226
+ if (!popoutDraftReady() || guestPage() || composers.get(name)?.composing) return null;
227
+ const ticket = owner.captureDraft(name);
228
+ const sameField = () => !composers.get(name)?.composing && (!composerField(name) || composerField(name).value === ticket.payload.text);
229
+ if (!sameField()) return null;
230
+ return { payload: ticket.payload, current: () => store === owner && owner.draftCurrent(ticket) && sameField(),
231
+ clear: () => store === owner && owner.clearCapturedDraft(ticket) };
232
+ }
233
+ export function acceptPaneDraft(name, data) {
234
+ const field = composerField(name);
235
+ if (!popoutDraftReady() || guestPage() || composers.get(name)?.composing || !field || field.disabled || field.readOnly || field.isConnected === false) return false;
236
+ return store.acceptDraft(name, data);
237
+ }
238
+
239
+
162
240
  const R = () => globalThis.AgendChatRender;
163
241
  const P = () => globalThis.AgendPreview;
164
242
 
165
243
  /** The page's chat store (boot creates it). Exported for the tests. */
166
244
  export let store = null;
167
245
 
246
+ /**
247
+ * AGEND-181/197: the thread's rows with the activity block put in — each turn's steps above the reply they produced, the
248
+ * turn in progress at the end — for an admin session, when this browser shows activity. Else the rows. (Which agents have
249
+ * anything: each one's tool_progress, the feed's answer.)
250
+ */
251
+ const activityShown = () => activityOffered() && activityPrefs.get().on;
252
+ const agentBusy = (name) => R().isBusy(store.state.exec[name]);
253
+ /** Epoch ms the agent began working, by the working bar's own clock (a monotonic one), or null. */
254
+ const agentSince = (name) => { const t = store.state.workingSince[name]; return t == null ? null : Date.now() - (performance.now() - t); };
255
+ const rowsOf = (name) => (activityShown() ? composeActivity(name, store.threadRows(name), Date.now(), { busy: agentBusy(name), since: agentSince(name) }) : store.threadRows(name));
256
+ /** What a chat's activity blocks need to draw: its paths to shorten, and whether thinking is shown. */
257
+ const activityCtx = (name) => () => {
258
+ const info = activityInfo(name);
259
+ return { paths: info ? { cwd: info.cwd, home: info.home } : null, thinking: activityPrefs.get().thinking && !!info && info.thinking === true };
260
+ };
261
+
168
262
  // ── Announcements: one polite, visually hidden line for the coarse events only (a reply arrived, the agent started,
169
263
  // finished, or waits on you). Messages themselves are not read out as they arrive; the list is a log to browse.
170
264
  let announceTimer = null;
@@ -342,12 +436,21 @@ function useResolvedMode(lease) {
342
436
 
343
437
  function ChatView({ name, inst, lease, navKey, exec, awaiting }) {
344
438
  const pane = paneContext.usePane?.(), paneNow = useRef(pane); paneNow.current = pane;
345
- const bindings = useRef({ input: { current: null }, box: { current: null } }).current;
439
+ const bindings = useRef({ input: { current: null }, box: { current: null }, composing: false }).current;
346
440
  const ids = pane ? Object.fromEntries(["msgIn", "attachBtn", "stopBtn", "sendBtn", "cmdPalette"].map(key => [key, `pane-${pane.id}-${key}`])) : {};
347
441
  useLayoutEffect(() => {
348
442
  composers.set(name, bindings);
349
- return () => { if (composers.get(name) === bindings) composers.delete(name); };
443
+ const field = bindings.input.current, start = () => { bindings.composing = true; }, end = () => { bindings.composing = false; };
444
+ field?.addEventListener("compositionstart", start); field?.addEventListener("compositionend", end); field?.addEventListener("blur", end);
445
+ return () => {
446
+ field?.removeEventListener("compositionstart", start); field?.removeEventListener("compositionend", end); field?.removeEventListener("blur", end);
447
+ if (composers.get(name) === bindings) composers.delete(name);
448
+ };
350
449
  }, [name]);
450
+ useLayoutEffect(() => {
451
+ if (!pane && new URLSearchParams(location.search).get("presentation") !== "popout") return;
452
+ return observeComposerWidth(bindings.input.current, () => composers.get(name) === bindings, () => bindings.composing);
453
+ }, [name, !!pane]);
351
454
  const attachmentsSupported = supportsInstanceFeature(inst,"attachments");
352
455
  const names = useStore(namesStore); // #1722: which name leads (the title)
353
456
  // #1629: this agent's theme, on this surface only; redrawn when the themes, the viewer's switch or the mode move.
@@ -370,6 +473,7 @@ function ChatView({ name, inst, lease, navKey, exec, awaiting }) {
370
473
  };
371
474
  const [wrap, setWrap] = useState(codeWrap);
372
475
  const wide = useStore(chatWide).on;
476
+ useStore(activityPrefs); useStore(activityInfoStore); // AGEND-181: the ⋯ menu's Show activity / Show thinking
373
477
  const view = useRef(null), split = useRef(null), thread = useRef(null), bg = useRef(null), effectSurface = useRef(null);
374
478
  useLayoutEffect(() => { applyTheme(view.current, theme, mode); }, [themeKey, mode]);
375
479
  useLayoutEffect(() => {
@@ -436,6 +540,11 @@ function ChatView({ name, inst, lease, navKey, exec, awaiting }) {
436
540
  ...themeMenuItems(name),
437
541
  // #2117: its ambient — why it is not showing here (with the way to change that), and a person's Clear.
438
542
  ...ambientMenuItems(name, { publicLink: document.body.dataset.publicLink === "1", clear: clearAmbient }),
543
+ // AGEND-181: the activity timeline above each reply (this browser's choice), when the Log is on.
544
+ ...(activityOffered() && activityInfo(name)?.level !== "off" ? [
545
+ { key: "activity", checkbox: true, checked: activityPrefs.get().on, label: t("act.menuActivity"), onSelect: () => setActivityOn(!activityPrefs.get().on) },
546
+ ...(activityInfo(name)?.thinking ? [{ key: "thinking", checkbox: true, checked: activityPrefs.get().thinking, disabled: !activityPrefs.get().on, label: t("act.menuThinking"), onSelect: () => setActivityThinking(!activityPrefs.get().thinking) }] : []),
547
+ ] : []),
439
548
  narrowScreen() ? null : { key: "fullWidth", checkbox: true, checked: wide, label: t("chat.fullWidth"), onSelect: () => setChatWide(!wide) },
440
549
  { key: "delete", label: t("chat.delete"), icon: "trash", danger: true, onSelect: () => setDialog("delete") },
441
550
  ];
@@ -456,9 +565,6 @@ function ChatView({ name, inst, lease, navKey, exec, awaiting }) {
456
565
  return html`<div class=${`panel p-chat${wrap ? " wrap-code" : ""}`} data-width=${wide ? "full" : undefined} ref=${view}>
457
566
  <${PanelHeader} title=${inst.runtime === "windows" ? inst.display_name || name : headerName(namesOf(inst || { name }, names.primary))} sub=${sub}
458
567
  pageControls=${{ CardMenu, card, navKey, usage: supportsInstanceFeature(inst,"usage") }} pageActions=${[
459
- pane && !guest && supportsInstanceFeature(inst,"commands") ? { key: "pane-backend", label: `${mw("backend")}: ${backendLabel(inst.backend)}`, onSelect: () => inst.runtime === "windows" ? navigate(sectionPath("agents")) : pick("backend") } : null,
460
- pane && !guest && supportsInstanceFeature(inst,"commands") ? { key: "pane-model", label: t("chat.chipModel", modelText(inst)), onSelect: () => pick("model") } : null,
461
- pane && effortChip(inst) && supportsInstanceFeature(inst,"effort") ? { key: "pane-effort", label: t("chat.chipEffort", effortChip(inst)), onSelect: () => pick("effort") } : null,
462
568
  ...items]}
463
569
  nav=${guest ? (guestTrusted() ? html`<${InstanceSwitch} name=${name} instance=${inst} current="chat" guest=${true} />` : null) : html`<${InstanceSwitch} name=${name} instance=${inst} current="chat" />`}><${CardMenu} card=${card} /><${HeaderTools} navKey=${navKey} usage=${supportsInstanceFeature(inst,"usage")} />${guest ? null : html`<${Menu} items=${items} label=${t("app.more")} />`}</${PanelHeader}>
464
570
  <${ChatCard} key=${name} name=${name} card=${card} />
@@ -564,9 +670,10 @@ function threadEntry(name, doc) {
564
670
  serverNow: () => Date.now() + store.state.clockSkew, // #1823: the deadline is the server's
565
671
  panel: { shown: shownKey, open: (spec, o) => openPanel(spec, o), version: panelVersion, claim: claimPanel, claims: panelClaims, // #1481, #1704
566
672
  openMarkdown: (spec) => openMarkdown(spec) }, // M-2448: a Markdown file in the side panel
567
- openImage: openLightbox, // an image, full size, in the page
673
+ openImage: (links, img) => openLightbox(links, img, annotateFor(name, img)), // an image, full size, in the page (#3727: with 標註)
568
674
  emojis: (id) => !!emojiIndex && emojiIndex.known(id), // #1630: the fleet's server emoji
569
675
  mentions: (kind, id) => (mentionIndex ? mentionIndex.name(kind, id) : null), // #1682: mention names
676
+ activity: { mount: (node, group) => mountActivity(node, group, activityCtx(name)) }, // AGEND-181: the timeline's blocks
570
677
  });
571
678
  e.thread = thread;
572
679
  return e;
@@ -577,12 +684,40 @@ function follow(name, thread) {
577
684
  // #1682: the same for mention names — asked for the ids the messages carry; when names arrive, drawn again.
578
685
  const wantEmojis = (msgs) => { if (emojiIndex && emojiIndex.wants(msgs)) emojiIndex.ensure(); if (mentionIndex) mentionIndex.ensure(msgs); };
579
686
  const offs = [];
580
- if (emojiIndex) offs.push(emojiIndex.subscribe(() => thread.render(store.threadRows(name))));
581
- if (mentionIndex) offs.push(mentionIndex.subscribe(() => thread.render(store.threadRows(name))));
687
+ if (emojiIndex) offs.push(emojiIndex.subscribe(() => thread.render(rowsOf(name))));
688
+ if (mentionIndex) offs.push(mentionIndex.subscribe(() => thread.render(rowsOf(name))));
582
689
  wantEmojis(store.state.msgs[name]);
690
+ // AGEND-181/197: the activity feed — this instance's steps while the chat is shown (the Log's own read, live by steps_tick,
691
+ // or by a poll when the stream has fallen back to polling); switched by this browser's Show activity / Show thinking.
692
+ // Nothing is read for anyone but an admin session on the local dashboard.
693
+ let feed = null;
694
+ const sync = () => {
695
+ if (activityShown() && !feed) {
696
+ feed = observeActivity(name, {
697
+ changed: () => thread.render(rowsOf(name)),
698
+ streamOn: appStore.get().streamOn,
699
+ polling: () => globalThis.document?.body?.dataset?.webTransport === "poll" || appStore.get().connection === "polling",
700
+ wantThinking: () => activityPrefs.get().thinking,
701
+ working: () => agentBusy(name),
702
+ });
703
+ feed.start();
704
+ } else if (!activityShown() && feed) { feed.stop(); feed = null; }
705
+ thread.render(rowsOf(name));
706
+ };
707
+ if (activityShown()) sync();
708
+ offs.push(activityPrefs.subscribe(sync));
709
+ offs.push(() => { if (feed) { feed.stop(); feed = null; } });
710
+ // the agent starting or stopping work redraws the live line (a turn with nothing to show yet is only a "Working…"
711
+ // line, and the reply row that ends it may come first); a status poll that changes nothing here draws nothing.
712
+ let wasBusy = agentBusy(name);
583
713
  offs.push(store.subscribe((instance, kind) => {
714
+ // A fleet-wide status poll says `null`; an activity event, the instance.
715
+ if ((instance === null || instance === name) && wasBusy !== agentBusy(name)) {
716
+ wasBusy = !wasBusy;
717
+ if (feed) { thread.render(rowsOf(name)); feed.nudge(); }
718
+ }
584
719
  if (instance !== name) return;
585
- if (kind === "msgs") { thread.render(store.threadRows(name)); wantEmojis(store.state.msgs[name]); }
720
+ if (kind === "msgs") { thread.render(rowsOf(name)); wantEmojis(store.state.msgs[name]); if (feed) feed.nudge(); } // a message came or went: read the steps now
586
721
  else if (kind === "progress") thread.progress(); // an upload moved: its bar, in place
587
722
  else if (kind === "sent") thread.jumpLatest();
588
723
  }));
@@ -618,7 +753,7 @@ function Thread({ name, label = name, th, bindings }) {
618
753
  thread.attach(sc);
619
754
  th.current = thread;
620
755
  // Up to date, at the reader's place (the bottom unless they had scrolled up); a kept one's cards say what they can do.
621
- thread.render(store.threadRows(name), { restore: store.state.scrollMemo[name] ?? null });
756
+ thread.render(rowsOf(name), { restore: store.state.scrollMemo[name] ?? null });
622
757
  if (kept) thread.refreshCards();
623
758
  const unfollow = follow(name, thread);
624
759
  const onScroll = () => { store.state.scrollMemo[name] = thread.onScroll(); };
@@ -820,7 +955,11 @@ function PromptText({ p, action }) {
820
955
  </form>`;
821
956
  }
822
957
 
823
- /** "<name> is working… 0:42", "looks stuck", "Stopping…", or what it waits on at its terminal. Text only. */
958
+ /**
959
+ * "<name> is working… 0:42", "looks stuck", "Stopping…", or what it waits on at its terminal. Text only.
960
+ * #3724: the strip is always there — idle it keeps its height and shows nothing (no button), so a state change only changes
961
+ * what is inside it and never moves the thread or the composer (chat-work-bar.css fixes the height; long text stays one line).
962
+ */
824
963
  function WorkBar({ name, lease, exec, awaiting, workingLabel, ids }) {
825
964
  const s = store.state;
826
965
  const busy = R().isBusy(exec) ? exec : "";
@@ -831,7 +970,7 @@ function WorkBar({ name, lease, exec, awaiting, workingLabel, ids }) {
831
970
  const h = lease.interval(() => tick(n => n + 1), 1000); // ticks only while it shows, cleared with the lease
832
971
  return () => lease.clear(h);
833
972
  }, [kind, lease]);
834
- if (!kind) return null;
973
+ if (!kind) return html`<div class="work-bar idle" aria-hidden="true"></div>`;
835
974
  // #1629: the agent's own working label (its theme), shown as text — only for "working", never for the other states.
836
975
  const label = kind === "working" && workingLabel ? workingLabel
837
976
  : t(kind === "stuck" ? "chat.stuck" : kind === "stopping" ? "chat.stopping" : kind === "awaiting" ? "chat.awaiting" : "chat.working", name);