@waq666/pneuma 0.7.1 → 0.8.1

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 (416) hide show
  1. package/README.md +242 -206
  2. package/bin/dsc.js +9 -3
  3. package/bin/headless.cjs +1 -1
  4. package/lib/adapter/transcript.d.ts +19 -2
  5. package/lib/adapter/transcript.js +71 -14
  6. package/lib/app/AgentsOverlay.js +7 -6
  7. package/lib/app/App.js +1 -1
  8. package/lib/app/ApprovalCard.js +15 -9
  9. package/lib/app/ChatView.d.ts +3 -1
  10. package/lib/app/ChatView.js +21 -17
  11. package/lib/app/Composer.js +22 -4
  12. package/lib/app/MarkdownView.js +2 -1
  13. package/lib/app/ModelPicker.js +7 -6
  14. package/lib/app/PickerFrame.d.ts +4 -0
  15. package/lib/app/PickerFrame.js +18 -0
  16. package/lib/app/PlanReviewCard.js +2 -1
  17. package/lib/app/PresetPicker.js +8 -7
  18. package/lib/app/SessionPicker.js +21 -20
  19. package/lib/app/SettingsOverlay.js +1 -1
  20. package/lib/app/SkillsPicker.js +7 -6
  21. package/lib/app/StatusBar.js +3 -15
  22. package/lib/app/TaskStrips.js +1 -4
  23. package/lib/app/TimelineRail.js +2 -1
  24. package/lib/app/ToolCard.js +2 -6
  25. package/lib/app/Welcome.d.ts +1 -0
  26. package/lib/app/Welcome.js +1 -4
  27. package/lib/app/click.d.ts +0 -2
  28. package/lib/app/click.js +2 -21
  29. package/lib/app/display-width.d.ts +16 -0
  30. package/lib/app/display-width.js +33 -0
  31. package/lib/app/markdown.d.ts +1 -3
  32. package/lib/app/markdown.js +2 -19
  33. package/lib/app/scroll-model.js +1 -1
  34. package/lib/contract/approval.d.ts +91 -0
  35. package/lib/contract/approval.js +1 -0
  36. package/lib/contract/mode.d.ts +69 -0
  37. package/lib/contract/mode.js +1 -0
  38. package/lib/contract/plugin.d.ts +240 -0
  39. package/lib/contract/plugin.js +1 -0
  40. package/lib/contract/runtime.d.ts +282 -0
  41. package/lib/contract/runtime.js +1 -0
  42. package/lib/contract/session.d.ts +208 -0
  43. package/lib/contract/session.js +36 -0
  44. package/lib/contract/settings.d.ts +242 -0
  45. package/lib/contract/settings.js +1 -0
  46. package/lib/contract/snapshot.d.ts +453 -0
  47. package/lib/contract/snapshot.js +1 -0
  48. package/lib/contract/task.d.ts +189 -0
  49. package/lib/contract/task.js +10 -0
  50. package/lib/contract/transcript.d.ts +358 -0
  51. package/lib/contract/transcript.js +1 -0
  52. package/lib/contract/usage.d.ts +132 -0
  53. package/lib/contract/usage.js +10 -0
  54. package/lib/contract.d.ts +20 -1968
  55. package/lib/contract.js +19 -30
  56. package/lib/core/agent-roles.d.ts +1 -1
  57. package/lib/core/agent-roles.js +6 -5
  58. package/lib/core/approval-floor.d.ts +9 -0
  59. package/lib/core/approval-floor.js +152 -25
  60. package/lib/core/attachments.d.ts +185 -0
  61. package/lib/core/attachments.js +425 -0
  62. package/lib/core/bytes.d.ts +14 -0
  63. package/lib/core/bytes.js +28 -0
  64. package/lib/core/call-meaning.d.ts +20 -0
  65. package/lib/core/call-meaning.js +347 -0
  66. package/lib/core/cdp/actions.js +6 -0
  67. package/lib/core/cdp/launch.js +2 -2
  68. package/lib/core/cdp/report.d.ts +27 -0
  69. package/lib/core/cdp/report.js +50 -0
  70. package/lib/core/cdp/ring-buffer.d.ts +25 -0
  71. package/lib/core/cdp/ring-buffer.js +44 -0
  72. package/lib/core/cdp/snapshot.js +5 -9
  73. package/lib/core/cdp/transport.js +1 -1
  74. package/lib/core/clamp.d.ts +20 -0
  75. package/lib/core/clamp.js +24 -0
  76. package/lib/core/clock.d.ts +16 -0
  77. package/lib/core/clock.js +20 -0
  78. package/lib/core/command-policy.js +33 -1
  79. package/lib/core/commands-completion.d.ts +28 -0
  80. package/lib/core/commands-completion.js +108 -30
  81. package/lib/core/compact.d.ts +36 -6
  82. package/lib/core/compact.js +89 -17
  83. package/lib/core/desktop-control.js +1 -3
  84. package/lib/core/dsh-compat/llm-usage-event.d.ts +78 -0
  85. package/lib/core/dsh-compat/llm-usage-event.js +91 -0
  86. package/lib/core/dsh-compat/presentation.d.ts +84 -0
  87. package/lib/core/dsh-compat/presentation.js +105 -0
  88. package/lib/core/dsh-compat/resolve-hook.d.ts +3 -3
  89. package/lib/core/dsh-compat/resolve-hook.js +41 -13
  90. package/lib/core/dsh-compat/service-map.d.ts +52 -0
  91. package/lib/core/dsh-compat/service-map.js +87 -0
  92. package/lib/core/dsh-compat/session-bridge.d.ts +107 -0
  93. package/lib/core/dsh-compat/session-bridge.js +376 -0
  94. package/lib/core/dsh-compat/session-events.d.ts +54 -0
  95. package/lib/core/dsh-compat/session-events.js +297 -0
  96. package/lib/core/dsh-compat/shims/credentials.d.ts +62 -0
  97. package/lib/core/dsh-compat/shims/credentials.js +86 -0
  98. package/lib/core/dsh-compat/shims/home-paths.d.ts +77 -0
  99. package/lib/core/dsh-compat/shims/home-paths.js +143 -0
  100. package/lib/core/dsh-compat/tools-facade.d.ts +31 -1
  101. package/lib/core/dsh-compat/tools-facade.js +207 -3
  102. package/lib/core/err-text.d.ts +5 -0
  103. package/lib/core/err-text.js +5 -0
  104. package/lib/core/events.d.ts +31 -2
  105. package/lib/core/git-info.d.ts +127 -15
  106. package/lib/core/git-info.js +315 -34
  107. package/lib/core/git-surface.d.ts +17 -0
  108. package/lib/core/git-surface.js +7 -0
  109. package/lib/core/hooks.d.ts +19 -2
  110. package/lib/core/hooks.js +57 -13
  111. package/lib/core/host-methods.d.ts +1 -1
  112. package/lib/core/host-methods.js +4 -0
  113. package/lib/core/image-diet.js +1 -4
  114. package/lib/core/json-text.d.ts +11 -0
  115. package/lib/core/json-text.js +18 -0
  116. package/lib/core/learnings/skill-write.d.ts +1 -7
  117. package/lib/core/learnings/skill-write.js +3 -37
  118. package/lib/core/lifecycle-hooks.d.ts +11 -3
  119. package/lib/core/lifecycle-hooks.js +33 -42
  120. package/lib/core/llm.d.ts +42 -0
  121. package/lib/core/llm.js +40 -25
  122. package/lib/core/loop.d.ts +11 -1
  123. package/lib/core/loop.js +95 -28
  124. package/lib/core/lsp/client.js +30 -17
  125. package/lib/core/lsp/normalize.d.ts +0 -2
  126. package/lib/core/lsp/normalize.js +1 -6
  127. package/lib/core/lsp/servers.js +1 -4
  128. package/lib/core/mcp.d.ts +18 -0
  129. package/lib/core/mcp.js +60 -16
  130. package/lib/core/microcompact.d.ts +45 -0
  131. package/lib/core/microcompact.js +128 -0
  132. package/lib/core/native-bridge.js +2 -10
  133. package/lib/core/path-policy.d.ts +13 -1
  134. package/lib/core/path-policy.js +87 -18
  135. package/lib/core/permission-presets.d.ts +9 -5
  136. package/lib/core/permission-presets.js +14 -7
  137. package/lib/core/permission-scope.d.ts +65 -0
  138. package/lib/core/permission-scope.js +109 -0
  139. package/lib/core/plugin-bundle.d.ts +95 -0
  140. package/lib/core/plugin-bundle.js +137 -0
  141. package/lib/core/plugin-loader.d.ts +36 -1
  142. package/lib/core/plugin-loader.js +336 -12
  143. package/lib/core/plugin-patch.d.ts +64 -0
  144. package/lib/core/plugin-patch.js +146 -0
  145. package/lib/core/plugin-registry.d.ts +14 -0
  146. package/lib/core/plugin-registry.js +2 -0
  147. package/lib/core/prefs.js +40 -2
  148. package/lib/core/presets.d.ts +11 -0
  149. package/lib/core/presets.js +61 -22
  150. package/lib/core/profile-dir.d.ts +5 -0
  151. package/lib/core/profile-dir.js +40 -0
  152. package/lib/core/prompt.js +55 -19
  153. package/lib/core/ptc.d.ts +8 -2
  154. package/lib/core/ptc.js +18 -4
  155. package/lib/core/records.d.ts +16 -0
  156. package/lib/core/records.js +22 -0
  157. package/lib/core/remote/notify.js +1 -3
  158. package/lib/core/remote/push.js +2 -6
  159. package/lib/core/sandbox/execpolicy.js +27 -3
  160. package/lib/core/sandbox/net-proxy.js +2 -2
  161. package/lib/core/sandbox/policy.d.ts +1 -1
  162. package/lib/core/sandbox/policy.js +21 -15
  163. package/lib/core/sandbox/win/account.js +1 -4
  164. package/lib/core/sandbox/win/acl.js +1 -6
  165. package/lib/core/sandbox/win/backend.d.ts +24 -3
  166. package/lib/core/sandbox/win/backend.js +73 -23
  167. package/lib/core/sandbox/win/doctor.js +1 -4
  168. package/lib/core/sandbox/win/runner-entry.js +1 -6
  169. package/lib/core/sandbox/win/setup.js +1 -4
  170. package/lib/core/sandbox/win/utf16.d.ts +11 -0
  171. package/lib/core/sandbox/win/utf16.js +15 -0
  172. package/lib/core/sandbox/win/wfp.js +1 -4
  173. package/lib/core/schedule/rule.d.ts +0 -17
  174. package/lib/core/schedule/rule.js +1 -3
  175. package/lib/core/schedule/runner.d.ts +5 -2
  176. package/lib/core/schedule/runner.js +32 -9
  177. package/lib/core/schedule/store.d.ts +0 -2
  178. package/lib/core/schedule/store.js +2 -9
  179. package/lib/core/session-index.d.ts +50 -0
  180. package/lib/core/session-index.js +169 -3
  181. package/lib/core/session.d.ts +89 -13
  182. package/lib/core/session.js +385 -32
  183. package/lib/core/shell-quote.d.ts +21 -0
  184. package/lib/core/shell-quote.js +24 -0
  185. package/lib/core/side-ask.d.ts +52 -0
  186. package/lib/core/side-ask.js +89 -0
  187. package/lib/core/skills.d.ts +16 -0
  188. package/lib/core/skills.js +45 -8
  189. package/lib/core/snapshot-throttle.d.ts +8 -0
  190. package/lib/core/snapshot-throttle.js +24 -0
  191. package/lib/core/spill.d.ts +11 -5
  192. package/lib/core/spill.js +35 -36
  193. package/lib/core/strings.d.ts +21 -0
  194. package/lib/core/strings.js +33 -0
  195. package/lib/core/terminal-env.d.ts +61 -0
  196. package/lib/core/terminal-env.js +327 -0
  197. package/lib/core/text-format.d.ts +17 -0
  198. package/lib/core/text-format.js +26 -0
  199. package/lib/core/todo-reminder.d.ts +19 -14
  200. package/lib/core/todo-reminder.js +14 -23
  201. package/lib/core/token-estimate.d.ts +18 -2
  202. package/lib/core/token-estimate.js +10 -2
  203. package/lib/core/tool-result-prune.d.ts +42 -0
  204. package/lib/core/tool-result-prune.js +47 -0
  205. package/lib/core/tool-search.d.ts +3 -2
  206. package/lib/core/tool-search.js +3 -2
  207. package/lib/core/tools/bash.d.ts +35 -3
  208. package/lib/core/tools/bash.js +168 -41
  209. package/lib/core/tools/fs-tools.js +18 -17
  210. package/lib/core/tools/image-tool.d.ts +2 -0
  211. package/lib/core/tools/image-tool.js +59 -0
  212. package/lib/core/tools/path-args.d.ts +4 -0
  213. package/lib/core/tools/path-args.js +22 -0
  214. package/lib/core/tools/search-tools.d.ts +30 -0
  215. package/lib/core/tools/search-tools.js +321 -34
  216. package/lib/core/tools.d.ts +82 -0
  217. package/lib/core/tools.js +21 -0
  218. package/lib/core/transcript-text.d.ts +19 -0
  219. package/lib/core/transcript-text.js +44 -0
  220. package/lib/core/ui-boot-source.d.ts +5 -0
  221. package/lib/core/ui-boot-source.js +10 -3
  222. package/lib/core/ui-bundles.d.ts +80 -6
  223. package/lib/core/ui-bundles.js +700 -76
  224. package/lib/core/ui-events.d.ts +10 -0
  225. package/lib/core/ui-events.js +25 -0
  226. package/lib/core/ui-methods.d.ts +1 -1
  227. package/lib/core/ui-methods.js +42 -13
  228. package/lib/core/ui-route.js +11 -7
  229. package/lib/core/ui-server.d.ts +6 -0
  230. package/lib/core/ui-server.js +106 -1
  231. package/lib/core/unified-diff.d.ts +35 -0
  232. package/lib/core/unified-diff.js +86 -0
  233. package/lib/core/usage-log.js +39 -0
  234. package/lib/core/web-http.d.ts +1 -1
  235. package/lib/core/web-http.js +1 -3
  236. package/lib/host/kernel.js +57 -41
  237. package/lib/plugins/agent.js +101 -20
  238. package/lib/plugins/approval-floor.js +12 -8
  239. package/lib/plugins/approval.js +252 -80
  240. package/lib/plugins/ask.js +60 -8
  241. package/lib/plugins/browser.js +32 -84
  242. package/lib/plugins/commands.js +167 -57
  243. package/lib/plugins/compact.d.ts +2 -2
  244. package/lib/plugins/compact.js +200 -30
  245. package/lib/plugins/computer-use.js +34 -18
  246. package/lib/plugins/dock-browser.js +24 -65
  247. package/lib/plugins/dsh-compat.js +7 -0
  248. package/lib/plugins/file-review.js +59 -15
  249. package/lib/plugins/git.js +16 -8
  250. package/lib/plugins/goal.js +9 -8
  251. package/lib/plugins/hooks.js +4 -2
  252. package/lib/plugins/host-stdio.js +14 -16
  253. package/lib/plugins/lifecycle-hooks.d.ts +5 -4
  254. package/lib/plugins/lifecycle-hooks.js +12 -10
  255. package/lib/plugins/llm.js +74 -33
  256. package/lib/plugins/lsp.js +22 -27
  257. package/lib/plugins/mcp.js +16 -17
  258. package/lib/plugins/memory.js +3 -24
  259. package/lib/plugins/microcompact.d.ts +4 -1
  260. package/lib/plugins/microcompact.js +117 -19
  261. package/lib/plugins/mode.js +30 -11
  262. package/lib/plugins/permission-presets.d.ts +2 -1
  263. package/lib/plugins/permission-presets.js +55 -35
  264. package/lib/plugins/plugin-manager.js +4 -6
  265. package/lib/plugins/presets.js +56 -27
  266. package/lib/plugins/prompt.js +54 -11
  267. package/lib/plugins/ptc.d.ts +13 -0
  268. package/lib/plugins/ptc.js +121 -24
  269. package/lib/plugins/remote/types.d.ts +1 -1
  270. package/lib/plugins/remote/types.js +11 -0
  271. package/lib/plugins/remote.js +14 -15
  272. package/lib/plugins/runtime.js +91 -14
  273. package/lib/plugins/sandbox.js +181 -60
  274. package/lib/plugins/schedule.js +12 -11
  275. package/lib/plugins/self-improve.js +28 -18
  276. package/lib/plugins/session-search.js +18 -13
  277. package/lib/plugins/session-title.js +1 -1
  278. package/lib/plugins/session.js +103 -25
  279. package/lib/plugins/settings.js +16 -40
  280. package/lib/plugins/skills.js +18 -1
  281. package/lib/plugins/spill.js +18 -11
  282. package/lib/plugins/subagent.js +208 -42
  283. package/lib/plugins/team.js +11 -5
  284. package/lib/plugins/todo.d.ts +1 -1
  285. package/lib/plugins/todo.js +25 -19
  286. package/lib/plugins/tool-search.js +47 -28
  287. package/lib/plugins/tools-default.js +89 -5
  288. package/lib/plugins/tools.js +3 -3
  289. package/lib/plugins/transcript.js +116 -9
  290. package/lib/plugins/web-search.d.ts +1 -1
  291. package/lib/plugins/web-search.js +25 -16
  292. package/lib/plugins/webserver.js +40 -7
  293. package/lib/remote/assets/app-B3Id1EBq.js +14 -0
  294. package/lib/remote/assets/index.html +2 -2
  295. package/lib/remote/assets/{style-DIB6729x.css → style-NtlpbKOI.css} +1 -1
  296. package/lib/services/types.d.ts +247 -29
  297. package/lib/tools/plugin-cli.d.ts +1 -0
  298. package/lib/tools/plugin-cli.js +209 -0
  299. package/lib/ui/assets/app-B-Jx5dnh.js +90 -0
  300. package/lib/ui/assets/{chunk-BajyYBss.js → chunk-Bfdlo8Me.js} +1 -1
  301. package/lib/ui/assets/chunk-DGX-i4eb.js +12 -0
  302. package/lib/ui/assets/index.html +62 -14
  303. package/lib/ui/assets/style-WzxwEPaE.css +1 -0
  304. package/lib/ui/frames.js +1 -3
  305. package/lib/ui/index.d.ts +30 -1
  306. package/lib/ui/index.js +29 -0
  307. package/lib/ui/manifest.d.ts +24 -6
  308. package/lib/ui/manifest.js +3 -2
  309. package/lib/ui/plugins/actions/bundle.json +8 -0
  310. package/lib/ui/plugins/actions/client.js +43 -0
  311. package/lib/ui/plugins/ask/bundle.json +8 -0
  312. package/lib/ui/plugins/ask/client.js +415 -0
  313. package/lib/ui/plugins/browser/bundle.json +8 -0
  314. package/lib/ui/plugins/composer/bundle.json +9 -0
  315. package/lib/ui/plugins/composer/client.js +1806 -1087
  316. package/lib/ui/plugins/files/bundle.json +8 -0
  317. package/lib/ui/plugins/files/client.js +13 -98
  318. package/lib/ui/plugins/manifest.json +1 -104
  319. package/lib/ui/plugins/palette/bundle.json +8 -0
  320. package/lib/ui/plugins/palette/client.js +360 -0
  321. package/lib/ui/plugins/plugins/bundle.json +8 -0
  322. package/lib/ui/plugins/plugins/client.js +116 -38
  323. package/lib/ui/plugins/preview/bundle.json +8 -0
  324. package/lib/ui/plugins/preview/client.js +6 -16
  325. package/lib/ui/plugins/prompt/bundle.json +8 -0
  326. package/lib/ui/plugins/prompt/client.js +81 -47
  327. package/lib/ui/plugins/sessions/bundle.json +8 -0
  328. package/lib/ui/plugins/sessions/client.js +157 -111
  329. package/lib/ui/plugins/settings/bundle.json +8 -0
  330. package/lib/ui/plugins/settings/client.js +184 -170
  331. package/lib/ui/plugins/skills/bundle.json +8 -0
  332. package/lib/ui/plugins/skills/client.js +161 -79
  333. package/lib/ui/plugins/status/bundle.json +8 -0
  334. package/lib/ui/plugins/status/client.js +165 -26
  335. package/lib/ui/plugins/statusbar/bundle.json +9 -0
  336. package/lib/ui/plugins/statusbar/client.js +100 -144
  337. package/lib/ui/plugins/tasks/bundle.json +8 -0
  338. package/lib/ui/plugins/team/bundle.json +8 -0
  339. package/lib/ui/plugins/team/client.js +60 -58
  340. package/lib/ui/plugins/terminal/bundle.json +8 -0
  341. package/lib/ui/plugins/terminal/client.js +1 -7
  342. package/lib/ui/plugins/trace/bundle.json +11 -0
  343. package/lib/ui/plugins/trace/client.js +86 -179
  344. package/lib/ui/plugins/transcript/bundle.json +8 -0
  345. package/lib/ui/plugins/transcript/client.js +1608 -1243
  346. package/lib/ui/sdk/@dsc/ui/index.d.ts +54 -16
  347. package/lib/ui/sdk/@dsc/ui/package.json +1 -1
  348. package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +20 -1968
  349. package/lib/ui/sdk/@dsc/ui-core/core/attachments.d.ts +185 -0
  350. package/lib/ui/sdk/@dsc/ui-core/core/bytes.d.ts +14 -0
  351. package/lib/ui/sdk/@dsc/ui-core/core/err-text.d.ts +18 -0
  352. package/lib/ui/sdk/@dsc/ui-core/core/git-surface.d.ts +17 -0
  353. package/lib/ui/sdk/@dsc/ui-core/core/json-text.d.ts +11 -0
  354. package/lib/ui/sdk/@dsc/ui-core/core/path-policy.d.ts +44 -0
  355. package/lib/ui/sdk/@dsc/ui-core/core/records.d.ts +16 -0
  356. package/lib/ui/sdk/@dsc/ui-core/core/throughput.d.ts +46 -0
  357. package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +18 -2
  358. package/lib/ui/sdk/@dsc/ui-core/core/unified-diff.d.ts +35 -0
  359. package/lib/ui/sdk/@dsc/ui-core/package.json +1 -1
  360. package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +30 -1
  361. package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +24 -6
  362. package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +19 -8
  363. package/lib/ui/sdk/@dsc/ui-core/ui/signal.d.ts +49 -0
  364. package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +17 -3
  365. package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +1 -1
  366. package/lib/ui/sdk/@dsc/ui-dockkit/package.json +1 -1
  367. package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +4 -0
  368. package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +6 -1
  369. package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +21 -0
  370. package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +1 -0
  371. package/lib/ui/sdk/@dsc/ui-layout/package.json +1 -1
  372. package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +1 -1
  373. package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +10 -1
  374. package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +1 -1
  375. package/lib/ui/sdk/@dsc/ui-layout/usage-today.d.ts +11 -0
  376. package/lib/ui/sdk/@dsc/ui-primitives/dialog-focus.d.ts +30 -0
  377. package/lib/ui/sdk/@dsc/ui-primitives/error-text.d.ts +12 -0
  378. package/lib/ui/sdk/@dsc/ui-primitives/git-surface.d.ts +9 -0
  379. package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +23 -0
  380. package/lib/ui/sdk/@dsc/ui-primitives/humanize-error.d.ts +35 -0
  381. package/lib/ui/sdk/@dsc/ui-primitives/icons-workspace.d.ts +33 -0
  382. package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +21 -3
  383. package/lib/ui/sdk/@dsc/ui-primitives/image-lightbox.d.ts +21 -0
  384. package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +16 -0
  385. package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +10 -14
  386. package/lib/ui/sdk/@dsc/ui-primitives/package.json +1 -1
  387. package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +31 -8
  388. package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +2 -0
  389. package/lib/ui/sdk/@dsc/ui-primitives/review-findings-card.d.ts +25 -0
  390. package/lib/ui/sdk/@dsc/ui-primitives/review-findings.d.ts +64 -0
  391. package/lib/ui/sdk/@dsc/ui-primitives/review-notice-card.d.ts +27 -0
  392. package/lib/ui/sdk/@dsc/ui-primitives/review-notice.d.ts +80 -0
  393. package/lib/ui/sdk/@dsc/ui-primitives/signal.d.ts +9 -0
  394. package/lib/ui/sdk/@dsc/ui-primitives/sizes.d.ts +15 -0
  395. package/lib/ui/sdk/@dsc/ui-primitives/skeleton.d.ts +39 -0
  396. package/lib/ui/sdk/@dsc/ui-primitives/snapshot.d.ts +46 -0
  397. package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +3 -3
  398. package/lib/ui/sdk/@dsc/ui-primitives/throughput.d.ts +13 -0
  399. package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +9 -0
  400. package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +1 -1
  401. package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +30 -6
  402. package/lib/ui/sdk/@dsc/ui-primitives/unified-diff.d.ts +10 -0
  403. package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +10 -1
  404. package/lib/ui/sdk/@dsc/ui-renderer/cordis-host.d.ts +113 -0
  405. package/lib/ui/sdk/@dsc/ui-renderer/package.json +1 -1
  406. package/lib/ui/sdk/@dsc/ui-slots/package.json +1 -1
  407. package/lib/ui/services.d.ts +19 -8
  408. package/lib/ui/services.js +20 -12
  409. package/lib/ui/signal.d.ts +49 -0
  410. package/lib/ui/signal.js +57 -0
  411. package/lib/ui/tui-plugins.js +36 -16
  412. package/package.json +71 -58
  413. package/lib/remote/assets/app-DAcUCOEn.js +0 -14
  414. package/lib/ui/assets/app-B70nVIKd.js +0 -69
  415. package/lib/ui/assets/chunk-BGcgwlCI.js +0 -12
  416. package/lib/ui/assets/style-Bq01xH_b.css +0 -1
@@ -3,11 +3,10 @@
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
4
4
  const jsxRuntime = require("react/jsx-runtime");
5
5
  const react = require("react");
6
- const reactDom = require("react-dom");
7
6
  const ui$1 = require("@dsc/ui");
8
7
  const uiPrimitives = require("@dsc/ui-primitives");
8
+ const reactDom = require("react-dom");
9
9
  function tsOf(entry) {
10
- if (entry === void 0) return null;
11
10
  const ts = entry.ts;
12
11
  return typeof ts === "number" && Number.isFinite(ts) && ts > 0 ? ts : null;
13
12
  }
@@ -70,47 +69,61 @@ function teammateReportLabel(text) {
70
69
  const verb = report.state === "已失败" ? "失败了" : report.state === "已停止" ? "停了下来" : "汇报了运行结果";
71
70
  return `${who} ${verb}`;
72
71
  }
73
- function roundDuration(round) {
74
- if (round.startTs === null || round.endTs === null) return null;
75
- const ms = round.endTs - round.startTs;
76
- return Number.isFinite(ms) && ms >= 0 ? ms : null;
77
- }
78
- function turnStartedAt(entries) {
79
- for (let index = entries.length - 1; index >= 0; index -= 1) {
80
- const entry = entries[index];
81
- if (entry !== void 0 && entry.kind === "user" && entry.steering !== true) return uiPrimitives.entryTs(entry);
72
+ function internalLabel(text) {
73
+ if (text.startsWith(TEAMMATE_REPORT_OPEN)) return teammateReportLabel(text);
74
+ const job = /^后台作业\s+(\S+?)\s*((|\(|启动失败|成功|失败)/.exec(text);
75
+ if (job !== null) {
76
+ const id = job[1] ?? "";
77
+ const failed = text.includes("失败");
78
+ return failed ? `后台作业 ${id} 失败了` : `后台作业 ${id} 完成了`;
82
79
  }
83
- return null;
80
+ return "运行时通知";
84
81
  }
85
82
  function liveActivity(entries, turnState) {
86
83
  if (turnState === "idle") return null;
87
84
  if (turnState === "awaiting-approval") {
88
- return { stage: "等待你的确认", activity: "有一条工具调用等你批准" };
85
+ return { text: "等待你的确认", covered: false };
89
86
  }
90
87
  const tail = entries[entries.length - 1];
91
88
  if (tail !== void 0 && tail.id < 0 && tail.kind === "thinking") {
92
- return { stage: "正在分析请求", activity: "正在思考" };
89
+ return { text: "正在分析请求", covered: false };
93
90
  }
94
91
  if (tail !== void 0 && tail.id < 0 && tail.kind === "text") {
95
- return { stage: "正在整理回复", activity: "正在输出回复" };
92
+ return { text: "正在整理回复", covered: false };
96
93
  }
97
94
  const running = [...entries].reverse().find(
98
95
  (entry) => entry.kind === "tool" && (entry.call.status === "running" || entry.call.status === "preparing")
99
96
  );
100
97
  if (running !== void 0) {
98
+ const name = typeof running.call.name === "string" && running.call.name !== "" ? running.call.name : "未知工具";
101
99
  return {
102
- stage: "正在执行工具",
103
100
  // 「准备中」是模型还在吐参数、「正在调用」是工具真的开跑了——两句话不同
104
- activity: running.call.status === "preparing" ? `正在准备 ${running.call.name}` : `正在调用 ${running.call.name}`
101
+ text: running.call.status === "preparing" ? `正在准备 ${name}` : `正在调用 ${name}`,
102
+ // 工具在跑 = 过程组头正在画同一件事(除非用户把过程折叠关成了竖排)
103
+ covered: true
105
104
  };
106
105
  }
107
- if (turnState === "working") return { stage: "正在执行工具", activity: "正在执行工具" };
108
- return { stage: "正在分析请求", activity: "正在思考" };
106
+ if (turnState === "working") return { text: "正在执行工具", covered: false };
107
+ return { text: "正在分析请求", covered: false };
108
+ }
109
+ function roundDuration(round) {
110
+ if (round.startTs === null || round.endTs === null) return null;
111
+ const ms = round.endTs - round.startTs;
112
+ return Number.isFinite(ms) && ms >= 0 ? ms : null;
109
113
  }
110
114
  const folds = /* @__PURE__ */ new Map();
111
115
  function readFold(key, fallback) {
112
- if (key === void 0) return fallback;
113
- return folds.get(key) ?? fallback;
116
+ return foldStateOf(key, fallback).open;
117
+ }
118
+ function foldStateOf(key, fallback) {
119
+ if (key === void 0) return { open: fallback, manual: false };
120
+ const stored = folds.get(key);
121
+ if (stored === void 0) return { open: fallback, manual: false };
122
+ return { open: stored, manual: true };
123
+ }
124
+ function followFallback(current, key, fallback) {
125
+ const state = foldStateOf(key, fallback);
126
+ return state.manual ? current : state.open;
114
127
  }
115
128
  function writeFold(key, open) {
116
129
  if (key === void 0) return;
@@ -123,7 +136,11 @@ function stepGroupFoldKey(sessionId, roundIndex, groupSeq) {
123
136
  return `${sessionId ?? ""}:step:${String(roundIndex)}:${String(groupSeq)}`;
124
137
  }
125
138
  const PROCESS_FOLD_POLICIES = {
126
- compact: { foldTurns: true, stepGrouping: "collapsed", liveDetail: false, reasoningPreview: false },
139
+ // 紧凑档也带摘要(2026-10-30 用户拍板):这一档管的是「定稿的回合收成一行用时」,
140
+ // 它不该顺手把行内摘要一起删掉——摘要回答的是「这条思考讲了什么」,与整轮折不折是两件事。
141
+ // 删掉之后紧凑档的过程行只剩「思考 ∨」「工具调用 · run_code」这种没有内容的标题,
142
+ // 用户的原话是「现在的思考行没有思考摘要显示」。
143
+ compact: { foldTurns: true, stepGrouping: "collapsed", liveDetail: false, reasoningPreview: true },
127
144
  standard: { foldTurns: true, stepGrouping: "collapsed", liveDetail: true, reasoningPreview: true },
128
145
  detailed: { foldTurns: true, stepGrouping: "history", liveDetail: true, reasoningPreview: true },
129
146
  verbose: { foldTurns: false, stepGrouping: "none", liveDetail: false, reasoningPreview: true }
@@ -227,103 +244,6 @@ function useFoldMemory() {
227
244
  }, []);
228
245
  return react.useMemo(() => ({ open, set, reset }), [open, set, reset]);
229
246
  }
230
- const MAX_DIFF_LINES = 800;
231
- function parseIntended(name, argsText) {
232
- if (name !== "write" && name !== "edit") return null;
233
- let parsed;
234
- try {
235
- parsed = JSON.parse(argsText);
236
- } catch {
237
- return null;
238
- }
239
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return null;
240
- const args = parsed;
241
- const path = typeof args.path === "string" ? args.path : "";
242
- if (path === "") return null;
243
- if (name === "write") {
244
- return typeof args.content === "string" ? { path, content: args.content } : null;
245
- }
246
- if (typeof args.old !== "string" || typeof args.new !== "string") return null;
247
- return { path, content: args.new, old: args.old };
248
- }
249
- function toAbsPath(path, cwd) {
250
- if (/^[A-Za-z]:[\\/]/.test(path) || path.startsWith("\\\\") || path.startsWith("/")) return path;
251
- if (cwd === "") return path;
252
- const sep = cwd.includes("\\") ? "\\" : "/";
253
- return `${cwd.replace(/[\\/]+$/, "")}${sep}${path}`;
254
- }
255
- function diffToView(path, before, after) {
256
- const result = ui$1.diffLines(before, after, 3);
257
- if (!result.ok || result.hunks.length === 0) return null;
258
- const hunks = [];
259
- let budget = MAX_DIFF_LINES;
260
- for (const hunk of result.hunks) {
261
- if (budget <= 0) break;
262
- const lines = hunk.lines.length <= budget ? hunk.lines : hunk.lines.slice(0, budget);
263
- hunks.push(lines.length === hunk.lines.length ? hunk : { ...hunk, lines });
264
- budget -= lines.length;
265
- }
266
- return {
267
- path,
268
- added: result.added,
269
- removed: result.removed,
270
- hunks,
271
- ...hunks.length < result.hunks.length ? { truncated: true } : {},
272
- status: before === "" ? "added" : "modified"
273
- };
274
- }
275
- function useIntendedDiff(call, workdir, enabled = true) {
276
- const channel = ui$1.useHostChannel();
277
- const input = react.useMemo(() => parseIntended(call.name, call.argsText), [call.name, call.argsText]);
278
- const [state, setState] = react.useState(null);
279
- const absPath = input === null ? null : toAbsPath(input.path, workdir);
280
- react.useEffect(() => {
281
- if (!enabled || input === null || absPath === null || call.status !== "running") {
282
- setState(null);
283
- return;
284
- }
285
- let on = true;
286
- setState(null);
287
- const apply = (before) => {
288
- if (before !== null && input.old !== void 0) {
289
- const at = before.indexOf(input.old);
290
- if (at < 0) {
291
- setState({ absPath, file: diffToView(absPath, input.old, input.content), fellBack: false, mismatch: "missing" });
292
- return;
293
- }
294
- if (before.indexOf(input.old, at + 1) >= 0) {
295
- setState({ absPath, file: diffToView(absPath, input.old, input.content), fellBack: false, mismatch: "ambiguous" });
296
- return;
297
- }
298
- }
299
- const fellBack = before === null;
300
- let after;
301
- let effectiveBefore;
302
- if (input.old === void 0) {
303
- effectiveBefore = before ?? "";
304
- after = input.content;
305
- } else if (before !== null) {
306
- const at = before.indexOf(input.old);
307
- effectiveBefore = before;
308
- after = before.slice(0, at) + input.content + before.slice(at + input.old.length);
309
- } else {
310
- effectiveBefore = input.old;
311
- after = input.content;
312
- }
313
- setState({ absPath, file: diffToView(absPath, effectiveBefore, after), fellBack });
314
- };
315
- void channel.invoke("dock", ["fs-read", { file: absPath }]).then((raw) => {
316
- if (!on) return;
317
- apply(raw.kind === "text" && typeof raw.text === "string" ? raw.text : null);
318
- }).catch(() => {
319
- if (on) apply(null);
320
- });
321
- return () => {
322
- on = false;
323
- };
324
- }, [absPath, call.status, enabled, input, channel]);
325
- return state;
326
- }
327
247
  function seatPlan(ats, grouping) {
328
248
  const items = [];
329
249
  for (const at of ats) {
@@ -339,8 +259,11 @@ function seatPlan(ats, grouping) {
339
259
  }
340
260
  return items;
341
261
  }
262
+ function needsGroupHeader(group) {
263
+ return group.size >= 2;
264
+ }
342
265
  function activityOf(name) {
343
- const tool = name.toLowerCase();
266
+ const tool = typeof name === "string" ? name.toLowerCase() : "";
344
267
  if (tool === "read") return "read";
345
268
  if (tool === "read_image") return "readImage";
346
269
  if (tool === "grep" || tool === "glob" || tool === "search" || tool === "session_search" || tool.endsWith("_inspect")) return "search";
@@ -456,6 +379,14 @@ function countActivities(entries, indexes) {
456
379
  }
457
380
  return [...counts].map(([kind, count]) => ({ kind, count })).sort((left, right) => right.count - left.count);
458
381
  }
382
+ function countFailures(entries, indexes) {
383
+ let failures = 0;
384
+ for (const index of indexes) {
385
+ const entry = entries[index];
386
+ if (entry !== void 0 && entry.kind === "tool" && entry.call.status === "failed") failures += 1;
387
+ }
388
+ return failures;
389
+ }
459
390
  function groupSteps(entries, rounds, isRunning, settledOnly = false) {
460
391
  const groups = [];
461
392
  for (const round of rounds) {
@@ -473,6 +404,7 @@ function groupSteps(entries, rounds, isRunning, settledOnly = false) {
473
404
  endIndex: last,
474
405
  size: pending.length,
475
406
  counts: countActivities(entries, pending),
407
+ failures: countFailures(entries, pending),
476
408
  closed
477
409
  };
478
410
  groups.push(group);
@@ -482,10 +414,14 @@ function groupSteps(entries, rounds, isRunning, settledOnly = false) {
482
414
  for (let at2 = round.startIndex + 1; at2 <= round.endIndex; at2 += 1) {
483
415
  const entry = entries[at2];
484
416
  if (entry === void 0) continue;
485
- if (entry.kind === "thinking" || entry.kind === "tool") {
417
+ if (entry.kind === "tool") {
486
418
  pending.push(at2);
487
419
  continue;
488
420
  }
421
+ if (entry.kind === "thinking") {
422
+ flush(true);
423
+ continue;
424
+ }
489
425
  if (entry.kind === "text" || entry.kind === "plan" || entry.kind === "user" || entry.kind === "turn-end" || entry.kind === "turn-max-tokens" || entry.kind === "model-retry") {
490
426
  flush(true);
491
427
  continue;
@@ -502,275 +438,64 @@ function groupSteps(entries, rounds, isRunning, settledOnly = false) {
502
438
  }
503
439
  return { groups, headAt, at };
504
440
  }
505
- const ACTIVITY_ICON = {
506
- thinking: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 12 }),
507
- read: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconFolder, { size: 12 }),
508
- readImage: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconFolder, { size: 12 }),
509
- search: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSearch, { size: 12 }),
510
- write: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 12 }),
511
- edit: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 12 }),
512
- commands: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconTerminal, { size: 12 }),
513
- code: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCode, { size: 12 }),
514
- webSearch: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconGlobe, { size: 12 }),
515
- webFetch: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconGlobe, { size: 12 }),
516
- browser: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconGlobe, { size: 12 }),
517
- subagents: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconTree, { size: 12 }),
518
- plan: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconQueue, { size: 12 }),
519
- questions: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconInfo, { size: 12 }),
520
- tools: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBolt, { size: 12 })
521
- };
522
- function useStableLiveTitle(desired, active) {
523
- const [shown, setShown] = react.useState(desired);
524
- const shownRef = react.useRef(shown);
525
- const wantedRef = react.useRef(desired);
526
- const shownAtRef = react.useRef(Date.now());
527
- react.useEffect(() => {
528
- wantedRef.current = desired;
529
- if (!active) return;
530
- const commit = (next) => {
531
- shownRef.current = next;
532
- shownAtRef.current = Date.now();
533
- setShown(next);
534
- };
535
- const decision = liveTitleDecision(shownRef.current, desired, Date.now() - shownAtRef.current);
536
- if (!decision.keep) {
537
- commit(desired);
538
- return;
539
- }
540
- if (decision.waitMs <= 0) return;
541
- const timer = setTimeout(() => {
542
- const next = wantedRef.current;
543
- if (sameLiveTitle(shownRef.current, next)) return;
544
- commit(next);
545
- }, decision.waitMs);
546
- return () => {
547
- clearTimeout(timer);
548
- };
549
- }, [active, desired.activity, desired.detail]);
550
- return active ? shown : desired;
441
+ function dedupeByRound(rows) {
442
+ const seen = /* @__PURE__ */ new Set();
443
+ const anchors = [];
444
+ for (const row of rows) {
445
+ if (seen.has(row.round)) continue;
446
+ seen.add(row.round);
447
+ anchors.push(row);
448
+ }
449
+ return anchors;
551
450
  }
552
- function StepGroupRow(props) {
553
- const closed = props.group.closed;
554
- const live = useStableLiveTitle(liveTitleOf(props.group), !closed);
555
- const activity = closed ? props.group.counts[0]?.kind ?? "thinking" : live.activity;
556
- const label = stepGroupTitle(
557
- props.group.counts,
558
- closed,
559
- activity === "thinking" ? void 0 : activity,
560
- // 「准备读取文件」与「正在读取文件」是两句不同的话:模型还在吐参数 vs 工具真的开跑了
561
- live.preparing
562
- );
563
- const detail = closed || !props.showDetail ? "" : live.detail;
564
- const counts = props.group.counts.map((item) => `${item.kind}=${String(item.count)}`).join(",");
565
- return /* @__PURE__ */ jsxRuntime.jsxs(
566
- "button",
567
- {
568
- type: "button",
569
- className: "step-fold",
570
- "data-open": props.open ? "1" : void 0,
571
- "data-step-group": `${String(props.group.roundIndex)}:${String(props.group.seq)}`,
572
- "data-step-activity": activity,
573
- "data-step-closed": closed ? "1" : void 0,
574
- "data-step-counts": counts,
575
- "data-step-detail": detail === "" ? void 0 : detail,
576
- "aria-expanded": props.open,
577
- "data-tip": props.open ? `收起这一阶段(${String(props.group.size)} 项思考与工具调用)` : `展开这一阶段,放出 ${String(props.group.size)} 项思考与工具调用`,
578
- onClick: (event) => {
579
- event.currentTarget.focus();
580
- props.onToggle();
581
- },
582
- children: [
583
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-leading", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-icon", "data-step-icon": true, children: ACTIVITY_ICON[activity] }) }),
584
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "step-fold-text", children: [
585
- /* @__PURE__ */ jsxRuntime.jsx(
586
- "span",
587
- {
588
- className: "step-fold-label",
589
- "data-shimmer": closed ? void 0 : label,
590
- children: label
591
- }
592
- ),
593
- detail !== "" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-detail", "data-shimmer": detail, children: detail })
594
- ] }),
595
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-count", "data-step-size": props.group.size, children: `${String(props.group.size)} 项` }),
596
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-chevron", "data-step-chevron": true, children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 }) })
597
- ]
598
- }
599
- );
451
+ function pickCurrentRound(probe) {
452
+ if (probe.atBottom && probe.lastRound >= 0) return probe.lastRound;
453
+ if (probe.hitRound !== null) return probe.hitRound;
454
+ if (probe.anchors.length === 0) return -1;
455
+ let current = -1;
456
+ for (const anchor of probe.anchors) {
457
+ if (anchor.top <= probe.probeTop) current = anchor.round;
458
+ else break;
459
+ }
460
+ return current === -1 ? probe.anchors[0]?.round ?? -1 : current;
600
461
  }
601
- const AT_BOTTOM_EPS$1 = 32;
602
- function useStableCallback(callback) {
603
- const ref = react.useRef(callback);
604
- react.useLayoutEffect(() => {
605
- ref.current = callback;
606
- }, [callback]);
607
- return react.useCallback(((...args) => {
608
- ref.current(...args);
609
- }), []);
462
+ const PROBE_INSET = 8;
463
+ const AT_BOTTOM_EPS = 32;
464
+ const RAIL_MIN_WIDTH = 900;
465
+ const TICK_STEP = 10;
466
+ const FADE_PX = 24;
467
+ const REVEAL_TRIES = 40;
468
+ function measureCurrent(scroller, rounds) {
469
+ const box = scroller.getBoundingClientRect();
470
+ const { scrollTop } = scroller;
471
+ const maxScroll = scroller.scrollHeight - scroller.clientHeight;
472
+ const rows = [];
473
+ for (const row of scroller.querySelectorAll("[data-round]")) {
474
+ const value = Number(row.getAttribute("data-round"));
475
+ if (!Number.isInteger(value) || value < 0) continue;
476
+ if (row.getClientRects().length === 0) continue;
477
+ rows.push({ round: value, top: row.getBoundingClientRect().top - box.top + scrollTop });
478
+ }
479
+ const probeY = box.top + PROBE_INSET;
480
+ const probeX = box.left + scroller.clientWidth / 2;
481
+ const hit = document.elementFromPoint(probeX, probeY);
482
+ let hitRound = null;
483
+ if (hit !== null && scroller.contains(hit)) {
484
+ const row = hit.closest("[data-round]");
485
+ const value = row === null ? Number.NaN : Number(row.getAttribute("data-round"));
486
+ if (Number.isInteger(value) && value >= 0) hitRound = value;
487
+ }
488
+ return pickCurrentRound({
489
+ atBottom: maxScroll > 0 && maxScroll - scrollTop <= AT_BOTTOM_EPS,
490
+ lastRound: rounds.at(-1)?.round ?? -1,
491
+ hitRound,
492
+ anchors: dedupeByRound(rows),
493
+ probeTop: scrollTop + PROBE_INSET
494
+ });
610
495
  }
611
- function foldHideDelayMs() {
612
- const raw = globalThis.getComputedStyle(document.documentElement).getPropertyValue("--dsc-dur-slow").trim();
613
- const value = Number.parseFloat(raw);
614
- if (!Number.isFinite(value) || value <= 0) return 180;
615
- return raw.endsWith("ms") ? value : value * 1e3;
616
- }
617
- function useSearchableHidden(hidden, reveal, options) {
618
- const ref = react.useRef(null);
619
- const delay = options?.delayMs ?? 0;
620
- react.useLayoutEffect(() => {
621
- const element = ref.current;
622
- if (element === null) return;
623
- if (!hidden) {
624
- element.removeAttribute("hidden");
625
- return;
626
- }
627
- if (element.contains(element.ownerDocument.activeElement)) {
628
- reveal();
629
- return;
630
- }
631
- if (delay <= 0) {
632
- element.setAttribute("hidden", "until-found");
633
- return;
634
- }
635
- const timer = globalThis.setTimeout(() => {
636
- element.setAttribute("hidden", "until-found");
637
- }, delay);
638
- return () => {
639
- globalThis.clearTimeout(timer);
640
- };
641
- }, [hidden, reveal, delay]);
642
- react.useLayoutEffect(() => {
643
- const element = ref.current;
644
- if (element === null) return;
645
- element.addEventListener("beforematch", reveal);
646
- return () => {
647
- element.removeEventListener("beforematch", reveal);
648
- };
649
- }, [reveal]);
650
- return ref;
651
- }
652
- const NO_EDGES = { up: false, down: false };
653
- function useProcessScroll(bodyRef, contentRef, open, live) {
654
- const follow = react.useRef(live);
655
- const [edges, setEdges] = react.useState(NO_EDGES);
656
- const wasOpen = react.useRef(false);
657
- react.useLayoutEffect(() => {
658
- const body = bodyRef.current;
659
- if (body === null || !open) {
660
- wasOpen.current = open;
661
- return;
662
- }
663
- if (!wasOpen.current) {
664
- follow.current = live;
665
- body.scrollTop = live ? body.scrollHeight : 0;
666
- }
667
- wasOpen.current = open;
668
- }, [bodyRef, open, live]);
669
- react.useLayoutEffect(() => {
670
- const body = bodyRef.current;
671
- const content = contentRef.current;
672
- if (body === null || !open) return;
673
- const measure = () => {
674
- const limit = body.scrollHeight - body.clientHeight;
675
- if (follow.current && limit > 0) body.scrollTop = body.scrollHeight;
676
- const top = body.scrollTop;
677
- const next = { up: top > 1, down: limit > 0 && top < limit - 1 };
678
- setEdges((previous) => previous.up === next.up && previous.down === next.down ? previous : next);
679
- };
680
- const onScroll = () => {
681
- const limit = body.scrollHeight - body.clientHeight;
682
- follow.current = limit <= 0 || limit - body.scrollTop <= AT_BOTTOM_EPS$1;
683
- measure();
684
- };
685
- measure();
686
- body.addEventListener("scroll", onScroll, { passive: true });
687
- const observer = typeof ResizeObserver === "function" ? new ResizeObserver(measure) : void 0;
688
- observer?.observe(body);
689
- if (content !== null) observer?.observe(content);
690
- return () => {
691
- body.removeEventListener("scroll", onScroll);
692
- observer?.disconnect();
693
- };
694
- }, [bodyRef, contentRef, open]);
695
- return edges;
696
- }
697
- function RowSeat(props) {
698
- const reveal = useStableCallback(props.onReveal);
699
- const ref = useSearchableHidden(props.hidden, reveal, { delayMs: foldHideDelayMs() });
700
- return /* @__PURE__ */ jsxRuntime.jsx(
701
- "div",
702
- {
703
- ref,
704
- className: "entry-row",
705
- "data-round": props.roundIndex === void 0 ? void 0 : props.roundIndex,
706
- children: props.children
707
- }
708
- );
709
- }
710
- function StepGroupSeat(props) {
711
- const revealTurn = useStableCallback(props.onRevealTurn);
712
- const seatRef = useSearchableHidden(props.turnCollapsed, revealTurn, { delayMs: foldHideDelayMs() });
713
- const revealGroup = useStableCallback(() => {
714
- if (!props.open) props.onToggle();
715
- });
716
- const bodyRef = useSearchableHidden(!props.open, revealGroup);
717
- const contentRef = react.useRef(null);
718
- const edges = useProcessScroll(bodyRef, contentRef, props.open, !props.group.closed);
719
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: seatRef, className: "step-seat", children: [
720
- /* @__PURE__ */ jsxRuntime.jsx(
721
- StepGroupRow,
722
- {
723
- group: props.group,
724
- open: props.open,
725
- showDetail: props.showDetail,
726
- onToggle: props.onToggle
727
- }
728
- ),
729
- /* @__PURE__ */ jsxRuntime.jsx(
730
- "div",
731
- {
732
- ref: bodyRef,
733
- className: "step-body",
734
- "data-step-body": true,
735
- "data-scroll-up": edges.up ? "1" : void 0,
736
- "data-scroll-down": edges.down ? "1" : void 0,
737
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentRef, className: "step-content", children: props.children })
738
- }
739
- )
740
- ] });
741
- }
742
- const PROBE_INSET = 8;
743
- const AT_BOTTOM_EPS = 32;
744
- const RAIL_MIN_WIDTH = 900;
745
- const TICK_STEP = 10;
746
- const FADE_PX = 24;
747
- const REVEAL_TRIES = 40;
748
- function readCurrent(scroller, anchors) {
749
- if (anchors.length === 0) return -1;
750
- const box = scroller.getBoundingClientRect();
751
- const { scrollTop } = scroller;
752
- const last = anchors[anchors.length - 1];
753
- const maxScroll = scroller.scrollHeight - scroller.clientHeight;
754
- if (maxScroll > 0 && maxScroll - scrollTop <= AT_BOTTOM_EPS && last !== void 0) return last.round;
755
- const probeY = box.top + PROBE_INSET;
756
- const probeX = box.left + scroller.clientWidth / 2;
757
- const hit = document.elementFromPoint(probeX, probeY);
758
- if (hit !== null && scroller.contains(hit)) {
759
- const row = hit.closest("[data-round]");
760
- const value = row === null ? Number.NaN : Number(row.getAttribute("data-round"));
761
- if (Number.isInteger(value) && value >= 0) return value;
762
- }
763
- let current = -1;
764
- for (const anchor of anchors) {
765
- const top = anchor.el.getBoundingClientRect().top - box.top + scrollTop;
766
- if (top <= scrollTop + PROBE_INSET) current = anchor.round;
767
- else break;
768
- }
769
- return current === -1 ? anchors[0]?.round ?? -1 : current;
770
- }
771
- function flatten(text, limit) {
772
- const flat = text.replace(/\s+/g, " ").trim();
773
- return flat.length > limit ? `${flat.slice(0, limit)}…` : flat;
496
+ function flatten(text, limit) {
497
+ const flat = text.replace(/\s+/g, " ").trim();
498
+ return flat.length > limit ? `${flat.slice(0, limit)}…` : flat;
774
499
  }
775
500
  const PREVIEW_LIMITS = { prompt: 50, response: 120 };
776
501
  function previewText(text, kind) {
@@ -801,13 +526,7 @@ function JumpRail(props) {
801
526
  let raf = 0;
802
527
  const measure = () => {
803
528
  raf = 0;
804
- const anchors = [];
805
- for (const el of scroller.querySelectorAll(".entry-user")) {
806
- const row = el.closest("[data-round]");
807
- const value = row === null ? Number.NaN : Number(row.getAttribute("data-round"));
808
- if (Number.isInteger(value) && value >= 0) anchors.push({ el, round: value });
809
- }
810
- setCurrent(readCurrent(scroller, anchors));
529
+ setCurrent(measureCurrent(scroller, props.rounds));
811
530
  };
812
531
  const schedule = () => {
813
532
  if (raf === 0) raf = requestAnimationFrame(measure);
@@ -953,80 +672,6 @@ function JumpRail(props) {
953
672
  host === null ? null : reactDom.createPortal(rail, host)
954
673
  ] });
955
674
  }
956
- const REVIEW_NOTICE_BANNER = "【文件更改预览·尚未落盘】";
957
- const REVIEW_ACTION_TEXT = {
958
- create: "新建",
959
- update: "修改"
960
- };
961
- function escapeRegExp(text) {
962
- return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
963
- }
964
- const HEAD_PATTERN = new RegExp(`^${escapeRegExp(REVIEW_NOTICE_BANNER)}(新建|修改) (.+)(([^()]*))$`);
965
- function parseCounts(text) {
966
- const match = /^\+(\d+) 行 \/ -(\d+) 行$/.exec(text);
967
- if (match === null) return null;
968
- const added = Number(match[1]);
969
- const removed = Number(match[2]);
970
- return Number.isFinite(added) && Number.isFinite(removed) ? { added, removed } : null;
971
- }
972
- function parseAction(verb) {
973
- if (verb === "新建") return "create";
974
- if (verb === "修改") return "update";
975
- return null;
976
- }
977
- function reviewLineKindOf(line) {
978
- if (line.startsWith("@@")) return "hunk";
979
- if (line.startsWith("+")) return "add";
980
- if (line.startsWith("-")) return "remove";
981
- if (line.startsWith(" ")) return "context";
982
- if (line.startsWith("(") || line.startsWith("…")) return "note";
983
- return line === "" ? "context" : "note";
984
- }
985
- function isReviewNotice(text) {
986
- return text.startsWith(REVIEW_NOTICE_BANNER);
987
- }
988
- function parseReviewNotice(text) {
989
- if (!isReviewNotice(text)) return null;
990
- const at = text.indexOf("\n");
991
- const head = at === -1 ? text : text.slice(0, at);
992
- const rest = at === -1 ? "" : text.slice(at + 1);
993
- const lines = (rest === "" ? [] : rest.split("\n")).map((line) => ({
994
- kind: reviewLineKindOf(line),
995
- text: line
996
- }));
997
- const match = HEAD_PATTERN.exec(head);
998
- if (match === null) {
999
- return { head, action: null, path: null, counts: null, countsText: null, lines };
1000
- }
1001
- const countsText = match[3] ?? "";
1002
- return {
1003
- head,
1004
- action: parseAction(match[1] ?? ""),
1005
- // 路径**不 trim**:它原样进 title 与展示,动一个字符就可能是另一个文件
1006
- path: match[2] ?? "",
1007
- counts: parseCounts(countsText),
1008
- countsText,
1009
- lines
1010
- };
1011
- }
1012
- function ReviewNoticeCard({ notice, cwd }) {
1013
- const path = notice.path;
1014
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-review", "data-review-notice": "", "data-action": notice.action ?? void 0, children: [
1015
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-review-head", children: [
1016
- /* @__PURE__ */ jsxRuntime.jsx(ui$1.FileIcon, { name: path ?? "", size: 14, className: "entry-review-icon" }),
1017
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "entry-review-path", title: path ?? notice.head, children: path === null ? notice.head : uiPrimitives.displayPathOf(path, cwd) }),
1018
- notice.action !== null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: notice.action === "create" ? "diff-badge" : "entry-review-badge", children: REVIEW_ACTION_TEXT[notice.action] }) : null,
1019
- notice.counts !== null ? /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-counts", children: [
1020
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-added", children: `+${String(notice.counts.added)} 行` }),
1021
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-removed", children: `-${String(notice.counts.removed)} 行` })
1022
- ] }) : notice.countsText === null || notice.countsText === "" ? null : (
1023
- // 算不出逐行 diff 时宿主写「逐行 diff 未给出」——中性一行,不装成计数。
1024
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "entry-review-counts", children: notice.countsText })
1025
- )
1026
- ] }),
1027
- notice.lines.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-review-diff", children: notice.lines.map((line, at) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-review-line", "data-kind": line.kind, children: line.text }, String(at))) })
1028
- ] });
1029
- }
1030
675
  const PAGE_MIN_ENTRIES = 50;
1031
676
  const PAGE_MIN_ROUNDS = 2;
1032
677
  const PAGE_MAX_ENTRIES = 500;
@@ -1045,6 +690,139 @@ function pageStartRound(roundSizes, beforeRound) {
1045
690
  }
1046
691
  return start;
1047
692
  }
693
+ function useFoldState(storeKey, fallback) {
694
+ const [open, setOpen] = react.useState(() => foldStateOf(storeKey, fallback).open);
695
+ react.useEffect(() => {
696
+ setOpen((current) => followFallback(current, storeKey, fallback));
697
+ }, [storeKey, fallback]);
698
+ const set = react.useCallback(
699
+ (next) => {
700
+ writeFold(storeKey, next);
701
+ setOpen(next);
702
+ },
703
+ [storeKey]
704
+ );
705
+ return [open, set];
706
+ }
707
+ const RESULT_TAIL_LINES = 0;
708
+ const PREVIEW_LINE_MAX_CHARS = 300;
709
+ function resultTail(text, limit = RESULT_TAIL_LINES) {
710
+ if (text === void 0 || text.trim() === "") return null;
711
+ const all = text.replace(/\r\n?/g, "\n").split("\n");
712
+ let end = all.length;
713
+ while (end > 0 && (all[end - 1] ?? "").trim() === "") end -= 1;
714
+ const kept = [];
715
+ for (let index = 0; index < end; index += 1) {
716
+ const line = (all[index] ?? "").replace(/[ \t]+$/, "");
717
+ if (line.trim() === "") continue;
718
+ kept.push(clipLine(line));
719
+ }
720
+ if (kept.length === 0) return null;
721
+ const cap = Math.max(0, limit);
722
+ const lines = cap === 0 ? [] : kept.slice(-cap);
723
+ return { lines, hidden: kept.length - lines.length };
724
+ }
725
+ function clipLine(line) {
726
+ if (line.length <= PREVIEW_LINE_MAX_CHARS) return line;
727
+ return `${Array.from(line).slice(0, PREVIEW_LINE_MAX_CHARS - 1).join("")}…`;
728
+ }
729
+ const MAX_DIFF_LINES = 800;
730
+ function parseIntended(name, argsText) {
731
+ if (name !== "write" && name !== "edit") return null;
732
+ let parsed;
733
+ try {
734
+ parsed = JSON.parse(argsText);
735
+ } catch {
736
+ return null;
737
+ }
738
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return null;
739
+ const args = parsed;
740
+ const path = typeof args.path === "string" ? args.path : "";
741
+ if (path === "") return null;
742
+ if (name === "write") {
743
+ return typeof args.content === "string" ? { path, content: args.content } : null;
744
+ }
745
+ if (typeof args.old !== "string" || typeof args.new !== "string") return null;
746
+ return { path, content: args.new, old: args.old };
747
+ }
748
+ function toAbsPath(path, cwd) {
749
+ if (/^[A-Za-z]:[\\/]/.test(path) || path.startsWith("\\\\") || path.startsWith("/")) return path;
750
+ if (cwd === "") return path;
751
+ const sep = cwd.includes("\\") ? "\\" : "/";
752
+ return `${cwd.replace(/[\\/]+$/, "")}${sep}${path}`;
753
+ }
754
+ function diffToView(path, before, after) {
755
+ const result = ui$1.diffLines(before, after, 3);
756
+ if (!result.ok || result.hunks.length === 0) return null;
757
+ const hunks = [];
758
+ let budget = MAX_DIFF_LINES;
759
+ for (const hunk of result.hunks) {
760
+ if (budget <= 0) break;
761
+ const lines = hunk.lines.length <= budget ? hunk.lines : hunk.lines.slice(0, budget);
762
+ hunks.push(lines.length === hunk.lines.length ? hunk : { ...hunk, lines });
763
+ budget -= lines.length;
764
+ }
765
+ return {
766
+ path,
767
+ added: result.added,
768
+ removed: result.removed,
769
+ hunks,
770
+ ...hunks.length < result.hunks.length ? { truncated: true } : {},
771
+ status: before === "" ? "added" : "modified"
772
+ };
773
+ }
774
+ function useIntendedDiff(call, workdir, enabled = true) {
775
+ const channel = ui$1.useHostChannel();
776
+ const input = react.useMemo(() => parseIntended(call.name, call.argsText), [call.name, call.argsText]);
777
+ const [state, setState] = react.useState(null);
778
+ const absPath = input === null ? null : toAbsPath(input.path, workdir);
779
+ react.useEffect(() => {
780
+ if (!enabled || input === null || absPath === null || call.status !== "running") {
781
+ setState(null);
782
+ return;
783
+ }
784
+ let on = true;
785
+ setState(null);
786
+ const apply = (before) => {
787
+ if (before !== null && input.old !== void 0) {
788
+ const at = before.indexOf(input.old);
789
+ if (at < 0) {
790
+ setState({ absPath, file: diffToView(absPath, input.old, input.content), fellBack: false, mismatch: "missing" });
791
+ return;
792
+ }
793
+ if (before.indexOf(input.old, at + 1) >= 0) {
794
+ setState({ absPath, file: diffToView(absPath, input.old, input.content), fellBack: false, mismatch: "ambiguous" });
795
+ return;
796
+ }
797
+ }
798
+ const fellBack = before === null;
799
+ let after;
800
+ let effectiveBefore;
801
+ if (input.old === void 0) {
802
+ effectiveBefore = before ?? "";
803
+ after = input.content;
804
+ } else if (before !== null) {
805
+ const at = before.indexOf(input.old);
806
+ effectiveBefore = before;
807
+ after = before.slice(0, at) + input.content + before.slice(at + input.old.length);
808
+ } else {
809
+ effectiveBefore = input.old;
810
+ after = input.content;
811
+ }
812
+ setState({ absPath, file: diffToView(absPath, effectiveBefore, after), fellBack });
813
+ };
814
+ void channel.invoke("dock", ["fs-read", { file: absPath }]).then((raw) => {
815
+ if (!on) return;
816
+ apply(raw.kind === "text" && typeof raw.text === "string" ? raw.text : null);
817
+ }).catch(() => {
818
+ if (on) apply(null);
819
+ });
820
+ return () => {
821
+ on = false;
822
+ };
823
+ }, [absPath, call.status, enabled, input, channel]);
824
+ return state;
825
+ }
1048
826
  const TOOLCARD_FACTORY = "transcript.tool-card";
1049
827
  const TOOLCARD_FOOTER_SLOT = "transcript.toolcard.footer";
1050
828
  const BAR_MIN_CONTENT_H$1 = 400;
@@ -1057,6 +835,24 @@ function expandedContentHeight$1(body) {
1057
835
  }
1058
836
  return total;
1059
837
  }
838
+ function dshPatchOf(presentation) {
839
+ const card = presentation?.result;
840
+ if (card === void 0 || card["card"] !== "diff") return null;
841
+ const diffs = card["diffs"];
842
+ if (!Array.isArray(diffs) || diffs.length === 0) return null;
843
+ const first = diffs[0];
844
+ if (typeof first.path !== "string" || typeof first.newText !== "string") return null;
845
+ const before = typeof first.oldText === "string" ? first.oldText : "";
846
+ const diff = ui$1.diffLines(before, first.newText, 3);
847
+ if (!diff.ok || diff.identical) return null;
848
+ return {
849
+ path: first.path,
850
+ added: diff.added,
851
+ removed: diff.removed,
852
+ hunks: diff.hunks,
853
+ status: first.oldText === null ? "added" : "modified"
854
+ };
855
+ }
1060
856
  function registerToolCard(ui2) {
1061
857
  ui2.slots.registerFactory(
1062
858
  {
@@ -1071,7 +867,7 @@ function ToolCard(props) {
1071
867
  const { entry, storeKey, persistKey, match: electedMatch, foldPrefs, cwd = "" } = props;
1072
868
  const variant = props.variant ?? "chat";
1073
869
  const call = entry.call;
1074
- const [open, setOpen] = react.useState(() => readFold(persistKey, foldPrefs?.toolOpen ?? false));
870
+ const [open, setOpenPersisted] = useFoldState(persistKey, foldPrefs?.toolOpen ?? false);
1075
871
  const [barVisible, setBarVisible] = react.useState(false);
1076
872
  const expandable = call.status !== "preparing";
1077
873
  const bodyOpen = open && expandable;
@@ -1087,13 +883,14 @@ function ToolCard(props) {
1087
883
  const StatusDetail = props.useFactorySlot("statusDetail", ChatStatus);
1088
884
  const BodyExtra = props.useFactorySlot("bodyExtra", IntendedBody);
1089
885
  const Trailing = props.useFactorySlot("trailing", NoTrailing);
1090
- const patch = intended?.file ?? call.change ?? null;
886
+ const dshPatch = dshPatchOf(call.presentation);
887
+ const patch = intended?.file ?? call.change ?? dshPatch;
1091
888
  const argView = uiPrimitives.toolArgFields(call.name, call.argsText);
1092
889
  const paramsAsFields = patch !== null && argView.mutating;
1093
- const setOpenPersisted = (next) => {
1094
- writeFold(persistKey, next);
1095
- setOpen(next);
1096
- };
890
+ const tail = react.useMemo(
891
+ () => bodyOpen || variant !== "chat" || running ? null : resultTail(call.resultText),
892
+ [bodyOpen, variant, running, call.resultText]
893
+ );
1097
894
  const toggle = () => {
1098
895
  if (expandable) setOpenPersisted(!open);
1099
896
  };
@@ -1139,22 +936,33 @@ function ToolCard(props) {
1139
936
  "div",
1140
937
  {
1141
938
  className: "tool-head",
1142
- role: "button",
1143
- tabIndex: expandable ? 0 : -1,
1144
- ...expandable ? { "aria-expanded": bodyOpen } : {},
1145
939
  "data-tip": expandable ? bodyOpen ? "收起参数与结果" : "展开参数与结果" : "正在准备参数",
1146
- onClick: toggle,
1147
- onKeyDown: (event) => {
1148
- if (event.key !== "Enter" && event.key !== " ") return;
1149
- event.preventDefault();
1150
- toggle();
1151
- },
1152
940
  children: [
1153
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tool-dot", "aria-hidden": "true" }),
1154
- /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 14, className: "tool-icon" }),
1155
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "verb", children: uiPrimitives.toolVerb(match.base, call.status) }),
1156
- match.known ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: call.name }),
1157
- /* @__PURE__ */ jsxRuntime.jsx(Preview, { intended, summary, cwd, targetPath, change: call.change ?? null }),
941
+ /* @__PURE__ */ jsxRuntime.jsxs(
942
+ "span",
943
+ {
944
+ className: `tool-click${expandable ? "" : " inert"}`,
945
+ role: expandable ? "button" : void 0,
946
+ tabIndex: expandable ? 0 : -1,
947
+ ...expandable ? { "aria-expanded": bodyOpen } : {},
948
+ onClick: expandable ? toggle : void 0,
949
+ onKeyDown: (event) => {
950
+ if (event.key !== "Enter" && event.key !== " ") return;
951
+ event.preventDefault();
952
+ toggle();
953
+ },
954
+ children: [
955
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "tool-leading", "aria-hidden": "true", children: [
956
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tool-dot" }),
957
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 12, className: "tool-icon" })
958
+ ] }),
959
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "verb", children: uiPrimitives.toolVerb(match.base, call.status) }),
960
+ match.known || call.name === "" ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: `· ${call.name}` }),
961
+ /* @__PURE__ */ jsxRuntime.jsx(Preview, { intended, summary, cwd, targetPath, change: call.change ?? null })
962
+ ]
963
+ }
964
+ ),
965
+ tail !== null && tail.hidden > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-more", title: `结果还有 ${String(tail.hidden)} 行,点开看全部`, children: `+${String(tail.hidden)} 行` }) : null,
1158
966
  /* @__PURE__ */ jsxRuntime.jsx(StatusDetail, { call }),
1159
967
  /* @__PURE__ */ jsxRuntime.jsx(Trailing, { entry }),
1160
968
  expandable ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 11, className: "tc-chevron" }) : null
@@ -1180,7 +988,7 @@ function ToolCard(props) {
1180
988
  }
1181
989
  )
1182
990
  ] }) : null,
1183
- /* @__PURE__ */ jsxRuntime.jsx(BodyExtra, { intended, change: call.change ?? null }),
991
+ /* @__PURE__ */ jsxRuntime.jsx(BodyExtra, { intended, change: call.change ?? dshPatch }),
1184
992
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "label", children: "参数" }),
1185
993
  paramsAsFields ? (
1186
994
  /* 会改文件的工具:正文已经在上面那块 diff 里,这里只列剩下的字段。
@@ -1316,648 +1124,635 @@ function TraceJumpButton(props) {
1316
1124
  }
1317
1125
  const FOLD_PREFS = { policy: processFoldPolicy("standard"), reasoningOpen: false, toolOpen: false };
1318
1126
  const FoldPrefsContext = react.createContext(FOLD_PREFS);
1319
- const NO_ACTIONS = { editRefork: () => void 0, busy: false };
1127
+ const NO_ACTIONS = { editAndResend: () => void 0, busy: false };
1320
1128
  const FlowActionsContext = react.createContext(NO_ACTIONS);
1321
1129
  const ShellCwdContext = react.createContext("");
1322
1130
  const ShellSessionContext = react.createContext(null);
1323
- const NO_ENTRIES = Object.freeze([]);
1324
1131
  const TOOLVIEW_SLOT = "transcript.toolview";
1325
- const BUILTIN_TOOLVIEW_PRIORITY = 100;
1326
- const ui = ui$1.defineUiPlugin({
1327
- name: "消息流",
1328
- apply(ui2) {
1329
- registerToolCard(ui2);
1330
- ui2.slots.register(
1331
- "shell.main",
1332
- { id: "transcript.flow", order: 1, children: { [TOOLVIEW_SLOT]: "chain" } },
1333
- TranscriptFlow
1334
- );
1335
- ui2.slots.register(
1336
- TOOLVIEW_SLOT,
1337
- {
1338
- id: "transcript.toolview.builtin",
1339
- priority: BUILTIN_TOOLVIEW_PRIORITY,
1340
- // owner 的类型来自 SlotMap 的声明(D1):entry 就是渲染方传的那条工具调用,
1341
- // 不需要再对 unknown 做断言。
1342
- select: (owner) => uiPrimitives.matchTool(owner.entry.call.name)
1343
- },
1344
- BuiltinToolView
1345
- );
1346
- ui2.slots.declare(SUBAGENT_FLOW_SLOT, "list");
1347
- ui2.slots.register(
1348
- SUBAGENT_FLOW_SLOT,
1349
- { id: "transcript.subagent.flow", order: 1, children: { [TOOLVIEW_SLOT]: "chain" } },
1350
- SubagentFlow
1351
- );
1352
- ui2.provide("transcriptFlow", { Component: SubagentFlow, slot: SUBAGENT_FLOW_SLOT });
1353
- }
1354
- });
1355
1132
  const TURN_INDEPENDENT = /* @__PURE__ */ new Set(["user", "plan", "system", "turn-end", "turn-max-tokens"]);
1356
1133
  const EMPTY_STEP_GROUPING = { groups: [], headAt: /* @__PURE__ */ new Map(), at: /* @__PURE__ */ new Map() };
1134
+ function keyOf(row, sessionKey) {
1135
+ return `${sessionKey}|${String(row.entry.id)}`;
1136
+ }
1137
+ function buildSeats(entries, live) {
1138
+ const all = [...entries, ...live];
1139
+ const split = splitRounds(all);
1140
+ const rowOf = (at) => ({ entry: all[at], live: at >= entries.length, at });
1141
+ return {
1142
+ leading: split.leading.map(rowOf),
1143
+ rounds: split.seats.map((seat) => ({ round: seat.round, rows: seat.indices.map(rowOf) })),
1144
+ infos: split.rounds
1145
+ };
1146
+ }
1147
+ const FOLLOW_BOTTOM_PX = 24;
1148
+ const FOLLOW_SETTLE_MS = 180;
1149
+ const UP_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "PageUp", "Home"]);
1357
1150
  function useFollowBottom(dep, sessionKey) {
1358
1151
  const [end, setEnd] = react.useState(null);
1359
- const pinned = react.useRef(true);
1152
+ const following = react.useRef(true);
1153
+ const written = react.useRef(0);
1154
+ const settleTimer = react.useRef(null);
1155
+ const control = react.useRef(null);
1360
1156
  const [paused, setPaused] = react.useState(false);
1361
1157
  const pinnedFor = react.useRef("");
1362
1158
  react.useEffect(() => {
1363
1159
  const scroller = end?.closest(".chat");
1364
1160
  if (!(scroller instanceof HTMLElement)) return void 0;
1161
+ const floor = () => Math.max(0, scroller.scrollHeight - scroller.clientHeight);
1162
+ const pinnedHeight = { current: scroller.scrollHeight };
1163
+ const pin = () => {
1164
+ scroller.scrollTop = scroller.scrollHeight;
1165
+ written.current = scroller.scrollTop;
1166
+ pinnedHeight.current = scroller.scrollHeight;
1167
+ };
1168
+ const clearSettle = () => {
1169
+ if (settleTimer.current !== null) window.clearTimeout(settleTimer.current);
1170
+ settleTimer.current = null;
1171
+ };
1172
+ const settle = () => {
1173
+ clearSettle();
1174
+ if (following.current) {
1175
+ pin();
1176
+ return;
1177
+ }
1178
+ if (floor() - scroller.scrollTop <= FOLLOW_BOTTOM_PX) {
1179
+ following.current = true;
1180
+ setPaused(false);
1181
+ pin();
1182
+ }
1183
+ };
1184
+ const schedule = () => {
1185
+ clearSettle();
1186
+ settleTimer.current = window.setTimeout(settle, FOLLOW_SETTLE_MS);
1187
+ };
1365
1188
  const onScroll = () => {
1366
- const atBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 160;
1367
- pinned.current = atBottom;
1368
- setPaused(!atBottom);
1189
+ const top = scroller.scrollTop;
1190
+ const heightChanged = pinnedHeight.current !== scroller.scrollHeight;
1191
+ if (Math.abs(top - written.current) <= 1) {
1192
+ written.current = top;
1193
+ if (heightChanged) pinnedHeight.current = scroller.scrollHeight;
1194
+ return;
1195
+ }
1196
+ if (heightChanged) {
1197
+ pinnedHeight.current = scroller.scrollHeight;
1198
+ if (floor() - top <= FOLLOW_BOTTOM_PX) {
1199
+ written.current = top;
1200
+ if (!following.current) schedule();
1201
+ return;
1202
+ }
1203
+ }
1204
+ written.current = top;
1205
+ if (following.current) {
1206
+ following.current = false;
1207
+ setPaused(true);
1208
+ }
1209
+ schedule();
1210
+ };
1211
+ const onGesture = () => {
1212
+ following.current = false;
1213
+ schedule();
1214
+ };
1215
+ const onWheel = (event) => {
1216
+ if (event.ctrlKey || event.deltaY >= 0) return;
1217
+ onGesture();
1218
+ };
1219
+ const onKey = (event) => {
1220
+ if (UP_KEYS.has(event.key)) onGesture();
1221
+ };
1222
+ const onResize = () => {
1223
+ if (!following.current) return;
1224
+ if (floor() - scroller.scrollTop > 4) pin();
1225
+ };
1226
+ control.current = {
1227
+ pin,
1228
+ stop: () => {
1229
+ clearSettle();
1230
+ following.current = false;
1231
+ setPaused(true);
1232
+ }
1369
1233
  };
1370
- onScroll();
1371
1234
  scroller.addEventListener("scroll", onScroll, { passive: true });
1235
+ scroller.addEventListener("scrollend", settle);
1236
+ scroller.addEventListener("wheel", onWheel, { passive: true });
1237
+ scroller.addEventListener("keydown", onKey);
1238
+ const observer = typeof ResizeObserver === "function" ? new ResizeObserver(onResize) : void 0;
1239
+ observer?.observe(scroller);
1240
+ const content = scroller.firstElementChild;
1241
+ if (content !== null) observer?.observe(content);
1372
1242
  return () => {
1243
+ clearSettle();
1244
+ control.current = null;
1373
1245
  scroller.removeEventListener("scroll", onScroll);
1246
+ scroller.removeEventListener("scrollend", settle);
1247
+ scroller.removeEventListener("wheel", onWheel);
1248
+ scroller.removeEventListener("keydown", onKey);
1249
+ observer?.disconnect();
1374
1250
  };
1375
1251
  }, [end]);
1376
1252
  react.useEffect(() => {
1377
- const scroller = end?.closest(".chat");
1378
- if (!(scroller instanceof HTMLElement)) return;
1379
1253
  if (pinnedFor.current !== sessionKey) {
1380
1254
  pinnedFor.current = sessionKey;
1381
- pinned.current = true;
1255
+ following.current = true;
1382
1256
  setPaused(false);
1383
1257
  }
1384
- if (!pinned.current) return;
1385
- scroller.scrollTop = scroller.scrollHeight;
1258
+ if (!following.current) return;
1259
+ control.current?.pin();
1386
1260
  }, [sessionKey, end, dep]);
1387
1261
  const resume = () => {
1388
- pinned.current = true;
1262
+ following.current = true;
1389
1263
  setPaused(false);
1390
- const scroller = end?.closest(".chat");
1391
- if (scroller instanceof HTMLElement) scroller.scrollTop = scroller.scrollHeight;
1264
+ control.current?.pin();
1392
1265
  };
1393
1266
  const pause = () => {
1394
- pinned.current = false;
1395
- setPaused(true);
1267
+ control.current?.stop();
1396
1268
  };
1397
- return { setEnd, paused, resume, pause };
1269
+ return { setEnd, end, paused, resume, pause };
1398
1270
  }
1399
- function TranscriptFlow({
1400
- renderSlot
1401
- }) {
1402
- const entries = ui$1.useHostSelector(readEntries);
1403
- const live = ui$1.useHostSelector(readLive);
1404
- const turnState = ui$1.useHostSelector(readTurnState);
1405
- const sessionPath = ui$1.useHostSelector(readSessionPath);
1406
- const sessionId = ui$1.useHostSelector(readSessionId);
1407
- const cwd = ui$1.useHostSelector(readCwdValue);
1408
- const channel = ui$1.useHostChannel();
1409
- const sessionKey = sessionPath ?? sessionId ?? "";
1410
- const seats = react.useMemo(() => buildSeats(entries, live), [entries, live]);
1411
- const follow = useFollowBottom(entries.length + live.length, sessionKey);
1412
- const [prefs, setPrefs] = react.useState(FOLD_PREFS);
1413
- const [behavior, setBehavior] = react.useState({
1414
- sound: true,
1415
- variant: 1,
1416
- notify: true
1417
- });
1271
+ const ACTIVITY_ICON = {
1272
+ thinking: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 12 }),
1273
+ read: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconFolder, { size: 12 }),
1274
+ readImage: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconFolder, { size: 12 }),
1275
+ search: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSearch, { size: 12 }),
1276
+ write: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 12 }),
1277
+ edit: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 12 }),
1278
+ commands: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconTerminal, { size: 12 }),
1279
+ code: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCode, { size: 12 }),
1280
+ webSearch: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconGlobe, { size: 12 }),
1281
+ webFetch: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconGlobe, { size: 12 }),
1282
+ browser: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconGlobe, { size: 12 }),
1283
+ subagents: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconTree, { size: 12 }),
1284
+ plan: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconQueue, { size: 12 }),
1285
+ questions: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconInfo, { size: 12 }),
1286
+ tools: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBolt, { size: 12 })
1287
+ };
1288
+ function useStableLiveTitle(desired, active) {
1289
+ const [shown, setShown] = react.useState(desired);
1290
+ const shownRef = react.useRef(shown);
1291
+ const wantedRef = react.useRef(desired);
1292
+ const shownAtRef = react.useRef(Date.now());
1418
1293
  react.useEffect(() => {
1419
- const read = () => {
1420
- void channel.invoke("getUiPrefs", []).then((value) => {
1421
- setPrefs({
1422
- policy: processFoldPolicy(readFoldValue(value["processFold"])),
1423
- reasoningOpen: value["reasoningDefaultOpen"] === true,
1424
- toolOpen: value["toolDefaultOpen"] === true
1425
- });
1426
- const variant = value["turnCompleteSoundVariant"];
1427
- setBehavior({
1428
- sound: value["turnCompleteSound"] !== false,
1429
- variant: typeof variant === "number" && Number.isFinite(variant) ? variant : 1,
1430
- notify: value["turnCompleteNotify"] !== false
1431
- });
1432
- }).catch(() => void 0);
1294
+ wantedRef.current = desired;
1295
+ if (!active) return;
1296
+ const commit = (next) => {
1297
+ shownRef.current = next;
1298
+ shownAtRef.current = Date.now();
1299
+ setShown(next);
1433
1300
  };
1434
- read();
1435
- window.addEventListener("shell.uiprefs", read);
1436
- return () => window.removeEventListener("shell.uiprefs", read);
1437
- }, [channel]);
1438
- const prevState = react.useRef(turnState);
1439
- const behaviorRef = react.useRef(behavior);
1440
- behaviorRef.current = behavior;
1441
- const sessionRef = react.useRef(sessionPath);
1442
- react.useEffect(() => {
1443
- const was = prevState.current;
1444
- prevState.current = turnState;
1445
- if (was === "idle" || turnState !== "idle") return;
1446
- if (sessionRef.current !== sessionPath) return;
1447
- if (behaviorRef.current.sound) uiPrimitives.playCompletionSound(behaviorRef.current.variant);
1448
- const background = document.hidden || !document.hasFocus();
1449
- const native = ui$1.getHostNative();
1450
- if (background && behaviorRef.current.notify && native.available) {
1451
- const last = [...entries].reverse().find((entry) => entry.kind === "text");
1452
- const body = last !== void 0 && last.kind === "text" ? last.text.replace(/\s+/g, " ").trim().slice(0, 120) : "任务完成";
1453
- void native.invoke("notify", [{ title: "任务完成", body }]).catch(() => void 0);
1301
+ const decision = liveTitleDecision(shownRef.current, desired, Date.now() - shownAtRef.current);
1302
+ if (!decision.keep) {
1303
+ commit(desired);
1304
+ return;
1454
1305
  }
1455
- }, [turnState, sessionPath, entries]);
1456
- const [earliest, setEarliest] = react.useState(null);
1457
- const roundSizes = react.useMemo(() => seats.rounds.map((seat) => seat.rows.length), [seats.rounds]);
1458
- const tailStart = react.useMemo(() => pageStartRound(roundSizes, roundSizes.length), [roundSizes]);
1459
- const firstVisible = earliest === null ? tailStart : Math.min(earliest, tailStart);
1460
- const visibleSeats = react.useMemo(
1461
- () => seats.rounds.filter((seat) => seat.round >= firstVisible),
1462
- [seats.rounds, firstVisible]
1306
+ if (decision.waitMs <= 0) return;
1307
+ const timer = setTimeout(() => {
1308
+ const next = wantedRef.current;
1309
+ if (sameLiveTitle(shownRef.current, next)) return;
1310
+ commit(next);
1311
+ }, decision.waitMs);
1312
+ return () => {
1313
+ clearTimeout(timer);
1314
+ };
1315
+ }, [active, desired.activity, desired.detail]);
1316
+ return active ? shown : desired;
1317
+ }
1318
+ function StepGroupRow(props) {
1319
+ const closed = props.group.closed;
1320
+ const live = useStableLiveTitle(liveTitleOf(props.group), !closed);
1321
+ const activity = closed ? props.group.counts[0]?.kind ?? "thinking" : live.activity;
1322
+ const label = stepGroupTitle(
1323
+ props.group.counts,
1324
+ closed,
1325
+ activity === "thinking" ? void 0 : activity,
1326
+ // 「准备读取文件」与「正在读取文件」是两句不同的话:模型还在吐参数 vs 工具真的开跑了
1327
+ live.preparing
1463
1328
  );
1464
- const earlierRounds = react.useMemo(
1465
- () => firstVisible - pageStartRound(roundSizes, firstVisible),
1466
- [roundSizes, firstVisible]
1329
+ const detail = closed || !props.showDetail ? "" : live.detail;
1330
+ const counts = props.group.counts.map((item) => `${item.kind}=${String(item.count)}`).join(",");
1331
+ const failNote = props.group.failures > 0 ? `,其中 ${String(props.group.failures)} 项失败` : "";
1332
+ const tip = props.open ? `收起这一阶段(${String(props.group.size)} 次工具调用${failNote})` : `展开这一阶段,放出 ${String(props.group.size)} 次工具调用${failNote}`;
1333
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1334
+ "button",
1335
+ {
1336
+ type: "button",
1337
+ className: "step-fold",
1338
+ "data-open": props.open ? "1" : void 0,
1339
+ "data-step-group": `${String(props.group.roundIndex)}:${String(props.group.seq)}`,
1340
+ "data-step-activity": activity,
1341
+ "data-step-closed": closed ? "1" : void 0,
1342
+ "data-step-counts": counts,
1343
+ "data-step-detail": detail === "" ? void 0 : detail,
1344
+ "aria-expanded": props.open,
1345
+ "data-tip": tip,
1346
+ onClick: (event) => {
1347
+ event.currentTarget.focus();
1348
+ props.onToggle();
1349
+ },
1350
+ children: [
1351
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-leading", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-icon", "data-step-icon": true, children: ACTIVITY_ICON[activity] }) }),
1352
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "step-fold-text", children: [
1353
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "step-fold-line", children: [
1354
+ /* @__PURE__ */ jsxRuntime.jsx(
1355
+ "span",
1356
+ {
1357
+ className: "step-fold-label",
1358
+ "data-shimmer": closed ? void 0 : label,
1359
+ children: label
1360
+ }
1361
+ ),
1362
+ props.task === "" ? null : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1363
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-dot", "aria-hidden": "true" }),
1364
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-task", title: props.task, children: props.task })
1365
+ ] })
1366
+ ] }),
1367
+ detail !== "" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-detail", "data-shimmer": detail, children: detail })
1368
+ ] }),
1369
+ props.group.failures > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-fail", "data-step-failures": props.group.failures, children: props.group.failures === 1 ? "1 失败" : `${String(props.group.failures)} 失败` }) : null,
1370
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-count", "data-step-size": props.group.size, children: `${String(props.group.size)} 项` }),
1371
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "step-fold-chevron", "data-step-chevron": true, children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 12 }) })
1372
+ ]
1373
+ }
1467
1374
  );
1468
- const cleared = seats.rounds.length === 0;
1469
- react.useEffect(() => {
1470
- setEarliest(null);
1471
- }, [sessionKey, cleared]);
1472
- const earlierRef = react.useRef(null);
1473
- const pageAnchor = react.useRef(null);
1474
- const beginPaging = () => {
1475
- const button = earlierRef.current;
1476
- if (button === null) return;
1477
- const scroller = button.closest(".chat");
1478
- if (!(scroller instanceof HTMLElement)) return;
1479
- const seat = scroller.querySelector("[data-round-seat]");
1480
- pageAnchor.current = seat === null ? null : { node: seat, top: seat.getBoundingClientRect().top - scroller.getBoundingClientRect().top, from: firstVisible };
1481
- };
1482
- const release = (startRound) => {
1483
- if (startRound >= firstVisible) return;
1484
- beginPaging();
1485
- follow.pause();
1486
- setEarliest(startRound);
1487
- };
1375
+ }
1376
+ function useStableCallback(callback) {
1377
+ const ref = react.useRef(callback);
1488
1378
  react.useLayoutEffect(() => {
1489
- const anchor = pageAnchor.current;
1490
- if (anchor === null) return;
1491
- pageAnchor.current = null;
1492
- if (firstVisible >= anchor.from || !anchor.node.isConnected) return;
1493
- const scroller = anchor.node.closest(".chat");
1494
- if (!(scroller instanceof HTMLElement)) return;
1495
- const top = anchor.node.getBoundingClientRect().top - scroller.getBoundingClientRect().top;
1496
- scroller.scrollTop += top - anchor.top;
1497
- }, [firstVisible]);
1498
- const foldMemory = useFoldMemory();
1499
- const rounds = seats.infos;
1500
- const liveRoundIndex = rounds.length - 1;
1501
- const roundFolds = react.useMemo(
1502
- () => buildRoundFolds([...entries, ...live], rounds, { foldTurns: prefs.policy.foldTurns, live: turnState !== "idle", lastRoundIndex: liveRoundIndex }),
1503
- [entries, live, rounds, prefs.policy.foldTurns, turnState, liveRoundIndex]
1504
- );
1505
- const stepGrouping = react.useMemo(
1506
- () => prefs.policy.stepGrouping === "none" ? EMPTY_STEP_GROUPING : groupSteps(
1507
- [...entries, ...live],
1508
- rounds,
1509
- // running 谓词直接复用 roundFold——口径单点,别处不再重判
1510
- (roundIndex) => roundFolds.get(roundIndex)?.running ?? false,
1511
- prefs.policy.stepGrouping === "history"
1512
- ),
1513
- [entries, live, rounds, roundFolds, prefs.policy.stepGrouping]
1514
- );
1515
- const runningRounds = react.useMemo(() => {
1516
- const set = /* @__PURE__ */ new Set();
1517
- for (const fold of roundFolds.values()) if (fold.running) set.add(fold.roundIndex);
1518
- return set;
1519
- }, [roundFolds]);
1520
- const prevRunningRounds = react.useRef(/* @__PURE__ */ new Set());
1521
- react.useEffect(() => {
1522
- const settled = [];
1523
- for (const roundIndex of prevRunningRounds.current) {
1524
- if (runningRounds.has(roundIndex)) continue;
1525
- settled.push(turnFoldKey(sessionId, roundIndex));
1526
- for (const group of stepGrouping.groups) {
1527
- if (group.roundIndex === roundIndex) settled.push(stepGroupFoldKey(sessionId, roundIndex, group.seq));
1528
- }
1379
+ ref.current = callback;
1380
+ }, [callback]);
1381
+ return react.useCallback(((...args) => {
1382
+ ref.current(...args);
1383
+ }), []);
1384
+ }
1385
+ function foldHideDelayMs() {
1386
+ const raw = globalThis.getComputedStyle(document.documentElement).getPropertyValue("--dsc-dur-slow").trim();
1387
+ const value = Number.parseFloat(raw);
1388
+ if (!Number.isFinite(value) || value <= 0) return 180;
1389
+ return raw.endsWith("ms") ? value : value * 1e3;
1390
+ }
1391
+ function useSearchableHidden(hidden, reveal, options) {
1392
+ const ref = react.useRef(null);
1393
+ const delay = options?.delayMs ?? 0;
1394
+ react.useLayoutEffect(() => {
1395
+ const element = ref.current;
1396
+ if (element === null) return;
1397
+ if (!hidden) {
1398
+ element.removeAttribute("hidden");
1399
+ return;
1529
1400
  }
1530
- foldMemory.reset(settled);
1531
- prevRunningRounds.current = runningRounds;
1532
- }, [runningRounds, stepGrouping, sessionId]);
1533
- const forkRound = (seat) => {
1534
- if (sessionPath === null) return;
1535
- const roundNo = seat.round + 1;
1536
- void (async () => {
1537
- try {
1538
- const result = await channel.invoke("forkSession", [sessionPath, roundNo]);
1539
- if (result.ok !== true) {
1540
- ui$1.toastErr(result.error ?? "分叉失败");
1541
- return;
1542
- }
1543
- await channel.invoke("openSession", result.path === void 0 ? [] : [result.path]);
1544
- await channel.invoke("refreshSessions", []);
1545
- ui$1.toastOk("已从这一轮分叉出新会话");
1546
- } catch (reason) {
1547
- ui$1.toastErr(`分叉失败:${reason instanceof Error ? reason.message : String(reason)}`);
1401
+ if (element.contains(element.ownerDocument.activeElement)) {
1402
+ reveal();
1403
+ return;
1404
+ }
1405
+ if (delay <= 0) {
1406
+ element.setAttribute("hidden", "until-found");
1407
+ return;
1408
+ }
1409
+ const timer = globalThis.setTimeout(() => {
1410
+ element.setAttribute("hidden", "until-found");
1411
+ }, delay);
1412
+ return () => {
1413
+ globalThis.clearTimeout(timer);
1414
+ };
1415
+ }, [hidden, reveal, delay]);
1416
+ react.useLayoutEffect(() => {
1417
+ const element = ref.current;
1418
+ if (element === null) return;
1419
+ element.addEventListener("beforematch", reveal);
1420
+ return () => {
1421
+ element.removeEventListener("beforematch", reveal);
1422
+ };
1423
+ }, [reveal]);
1424
+ return ref;
1425
+ }
1426
+ const NO_EDGES = { up: false, down: false };
1427
+ const PROCESS_BOTTOM_EPS = 4;
1428
+ const PROCESS_SETTLE_MS = 140;
1429
+ const PROCESS_UP_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "PageUp", "Home"]);
1430
+ function useProcessScroll(bodyRef, contentRef, open, live) {
1431
+ const follow = react.useRef(live);
1432
+ const written = react.useRef(0);
1433
+ const settleTimer = react.useRef(null);
1434
+ const [edges, setEdges] = react.useState(NO_EDGES);
1435
+ const wasOpen = react.useRef(false);
1436
+ react.useLayoutEffect(() => {
1437
+ const body = bodyRef.current;
1438
+ if (body === null || !open) {
1439
+ wasOpen.current = open;
1440
+ return;
1441
+ }
1442
+ if (!wasOpen.current) {
1443
+ follow.current = live;
1444
+ body.scrollTop = live ? body.scrollHeight : 0;
1445
+ written.current = body.scrollTop;
1446
+ }
1447
+ wasOpen.current = open;
1448
+ }, [bodyRef, open, live]);
1449
+ react.useLayoutEffect(() => {
1450
+ const body = bodyRef.current;
1451
+ const content = contentRef.current;
1452
+ if (body === null || !open) return;
1453
+ const pin = () => {
1454
+ body.scrollTop = body.scrollHeight;
1455
+ written.current = body.scrollTop;
1456
+ };
1457
+ const readEdges = () => {
1458
+ const limit = body.scrollHeight - body.clientHeight;
1459
+ const top = body.scrollTop;
1460
+ const next = { up: top > 1, down: limit > 0 && top < limit - 1 };
1461
+ setEdges((previous) => previous.up === next.up && previous.down === next.down ? previous : next);
1462
+ };
1463
+ const clearSettle = () => {
1464
+ if (settleTimer.current !== null) window.clearTimeout(settleTimer.current);
1465
+ settleTimer.current = null;
1466
+ };
1467
+ const settle = () => {
1468
+ clearSettle();
1469
+ const limit = body.scrollHeight - body.clientHeight;
1470
+ follow.current = limit - body.scrollTop <= PROCESS_BOTTOM_EPS;
1471
+ if (follow.current && limit > 0) pin();
1472
+ readEdges();
1473
+ };
1474
+ const schedule = () => {
1475
+ clearSettle();
1476
+ settleTimer.current = window.setTimeout(settle, PROCESS_SETTLE_MS);
1477
+ };
1478
+ const onScroll = () => {
1479
+ const top = body.scrollTop;
1480
+ if (Math.abs(top - written.current) <= 1) {
1481
+ written.current = top;
1482
+ readEdges();
1483
+ return;
1548
1484
  }
1549
- })();
1550
- };
1551
- const editRefork = (entry, text) => {
1552
- const all = [...entries, ...live];
1553
- const at = all.findIndex((item) => item.id === entry.id);
1554
- const index = rounds.filter((round) => round.startIndex < at).length;
1555
- void (async () => {
1556
- try {
1557
- if (sessionPath === null || index === 0) {
1558
- await channel.invoke("openSession", []);
1559
- } else {
1560
- const result = await channel.invoke("forkSession", [sessionPath, index]);
1561
- if (result.ok !== true) {
1562
- ui$1.toastErr(result.error ?? "分叉失败");
1563
- return;
1564
- }
1565
- await channel.invoke("openSession", result.path === void 0 ? [] : [result.path]);
1566
- }
1567
- await channel.invoke("refreshSessions", []);
1568
- await channel.invoke("submit", [text]);
1569
- } catch (reason) {
1570
- ui$1.toastErr(`重发失败:${reason instanceof Error ? reason.message : String(reason)}`);
1485
+ follow.current = false;
1486
+ schedule();
1487
+ readEdges();
1488
+ };
1489
+ const onGesture = () => {
1490
+ follow.current = false;
1491
+ schedule();
1492
+ };
1493
+ const onWheel = (event) => {
1494
+ if (event.ctrlKey || event.deltaY >= 0) return;
1495
+ onGesture();
1496
+ };
1497
+ const onKey = (event) => {
1498
+ if (PROCESS_UP_KEYS.has(event.key)) onGesture();
1499
+ };
1500
+ const observe = () => {
1501
+ if (follow.current) {
1502
+ const limit = body.scrollHeight - body.clientHeight;
1503
+ if (limit > 0 && limit - body.scrollTop > 2) pin();
1571
1504
  }
1572
- })();
1573
- };
1574
- const actions = { editRefork, busy: turnState !== "idle" };
1575
- const activity = react.useMemo(() => liveActivity([...entries, ...live], turnState), [entries, live, turnState]);
1576
- const startedAt = react.useMemo(() => turnStartedAt([...entries, ...live]), [entries, live]);
1577
- const railRounds = react.useMemo(
1578
- () => seats.rounds.map((seat) => {
1579
- const user = seat.rows[0]?.entry;
1580
- const answer = seat.rows.map((row) => row.entry).filter((entry) => entry.kind === "text" && entry.id >= 0).at(-1);
1581
- return {
1582
- round: seat.round,
1583
- // 题面预览只在来源是**人**时才填(对照 dsh 的 turnOutline:非 user 来源不留题面)。
1584
- // internal 汇报(队友干完活)有刻度但不给原文,改给一句人话——绝不把
1585
- // `<teammate-report …>` 当题面塞进悬停卡。
1586
- prompt: user?.kind !== "user" ? "" : user.internal === true ? teammateReportLabel(user.text) : previewText(user.text, "prompt"),
1587
- response: answer === void 0 ? "" : previewText(answer.text, "response")
1588
- };
1589
- }),
1590
- [seats.rounds]
1505
+ readEdges();
1506
+ };
1507
+ onScroll();
1508
+ body.addEventListener("scroll", onScroll, { passive: true });
1509
+ body.addEventListener("scrollend", settle);
1510
+ body.addEventListener("wheel", onWheel, { passive: true });
1511
+ body.addEventListener("keydown", onKey);
1512
+ const observer = typeof ResizeObserver === "function" ? new ResizeObserver(observe) : void 0;
1513
+ observer?.observe(body);
1514
+ if (content !== null) observer?.observe(content);
1515
+ return () => {
1516
+ clearSettle();
1517
+ body.removeEventListener("scroll", onScroll);
1518
+ body.removeEventListener("scrollend", settle);
1519
+ body.removeEventListener("wheel", onWheel);
1520
+ body.removeEventListener("keydown", onKey);
1521
+ observer?.disconnect();
1522
+ };
1523
+ }, [bodyRef, contentRef, open]);
1524
+ return edges;
1525
+ }
1526
+ function RowSeat(props) {
1527
+ const reveal = useStableCallback(props.onReveal);
1528
+ const ref = useSearchableHidden(props.hidden, reveal, { delayMs: foldHideDelayMs() });
1529
+ return /* @__PURE__ */ jsxRuntime.jsx(
1530
+ "div",
1531
+ {
1532
+ ref,
1533
+ className: "entry-row",
1534
+ "data-round": props.roundIndex === void 0 ? void 0 : props.roundIndex,
1535
+ children: props.children
1536
+ }
1591
1537
  );
1592
- const revealRound = (round) => {
1593
- release(round);
1594
- };
1595
- if (seats.rounds.length === 0 && seats.leading.every((row) => row.entry.kind === "system")) {
1596
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "welcome", children: [
1597
- /* @__PURE__ */ jsxRuntime.jsx("h1", { children: "有什么可以帮忙的?" }),
1598
- /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
1599
- "输入 ",
1600
- /* @__PURE__ */ jsxRuntime.jsx("code", { children: "/" }),
1601
- " 查看可用指令 · 消息会携带当前工作目录上下文"
1602
- ] }),
1603
- seats.leading.map((row) => {
1604
- const text = row.entry.kind === "system" ? row.entry.text : "";
1605
- if (isSessionMarker(text)) return null;
1606
- const notice = parseReviewNotice(text);
1607
- return notice === null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "welcome-note", children: text }, keyOf(row, sessionKey)) : /* @__PURE__ */ jsxRuntime.jsx(ReviewNoticeCard, { notice, cwd }, keyOf(row, sessionKey));
1608
- })
1609
- ] });
1610
- }
1611
- return /* @__PURE__ */ jsxRuntime.jsx(ShellSessionContext.Provider, { value: sessionId, children: /* @__PURE__ */ jsxRuntime.jsx(ShellCwdContext.Provider, { value: cwd ?? "", children: /* @__PURE__ */ jsxRuntime.jsx(FoldPrefsContext.Provider, { value: prefs, children: /* @__PURE__ */ jsxRuntime.jsxs(FlowActionsContext.Provider, { value: actions, children: [
1612
- /* @__PURE__ */ jsxRuntime.jsx(JumpRail, { rounds: railRounds, renderedFrom: firstVisible, onReveal: revealRound }),
1613
- firstVisible > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
1614
- "button",
1538
+ }
1539
+ function StepGroupSeat(props) {
1540
+ const revealTurn = useStableCallback(props.onRevealTurn);
1541
+ const seatRef = useSearchableHidden(props.turnCollapsed, revealTurn, { delayMs: foldHideDelayMs() });
1542
+ const revealGroup = useStableCallback(() => {
1543
+ if (!props.open) props.onToggle();
1544
+ });
1545
+ const bodyRef = useSearchableHidden(!props.open, revealGroup);
1546
+ const contentRef = react.useRef(null);
1547
+ const edges = useProcessScroll(bodyRef, contentRef, props.open, !props.group.closed);
1548
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: seatRef, className: "step-seat", children: [
1549
+ /* @__PURE__ */ jsxRuntime.jsx(
1550
+ StepGroupRow,
1615
1551
  {
1616
- type: "button",
1617
- className: "chat-earlier",
1618
- ref: earlierRef,
1619
- "data-earlier-rounds": firstVisible,
1620
- "data-tip": "把更早的几轮画出来(一页至少 50 条且 2 轮),你现在看的位置不会动",
1621
- onClick: () => {
1622
- release(firstVisible - earlierRounds);
1623
- },
1624
- children: `加载更早的 ${String(earlierRounds)} 轮(上面还有 ${String(firstVisible)} 轮)`
1552
+ group: props.group,
1553
+ open: props.open,
1554
+ showDetail: props.showDetail,
1555
+ task: props.task,
1556
+ onToggle: props.onToggle
1625
1557
  }
1626
- ) : null,
1627
- seats.leading.map((row) => /* @__PURE__ */ jsxRuntime.jsx(RowBoundary, { entry: row.entry, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-row", children: /* @__PURE__ */ jsxRuntime.jsx(RowBody, { row, renderSlot }) }) }, keyOf(row, sessionKey))),
1628
- visibleSeats.map((seat) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "turn-seat", "data-round-seat": seat.round, children: /* @__PURE__ */ jsxRuntime.jsx(
1629
- SeatBody,
1558
+ ),
1559
+ /* @__PURE__ */ jsxRuntime.jsx(
1560
+ "div",
1630
1561
  {
1631
- seat,
1632
- round: rounds[seat.round],
1633
- running: turnState !== "idle" && seat.round === rounds.length - 1,
1634
- sessionId,
1635
- sessionKey,
1636
- cwd,
1637
- roundFolds,
1638
- foldMemory,
1639
- stepGrouping,
1640
- renderSlot,
1641
- onFork: sessionPath === null || seat.round === 0 ? void 0 : () => forkRound(seat)
1642
- }
1643
- ) }, seat.round)),
1644
- activity !== null ? /* @__PURE__ */ jsxRuntime.jsx(TurnStatusLine, { stage: activity.stage, activity: activity.activity, startedAt }) : null,
1645
- /* @__PURE__ */ jsxRuntime.jsx("div", { ref: follow.setEnd }),
1646
- follow.paused ? /* @__PURE__ */ jsxRuntime.jsx(
1647
- "button",
1648
- {
1649
- type: "button",
1650
- className: "chat-to-bottom",
1651
- title: "回到最新一条(自动跟随会重新打开)",
1652
- onClick: follow.resume,
1653
- children: "回到底部"
1654
- }
1655
- ) : null
1656
- ] }) }) }) });
1657
- }
1658
- function readFoldValue(value) {
1659
- return value === "compact" || value === "detailed" || value === "verbose" ? value : "standard";
1660
- }
1661
- function readSessionPath(snapshot) {
1662
- const status = snapshot?.["status"];
1663
- if (typeof status !== "object" || status === null) return null;
1664
- const value = status["sessionPath"];
1665
- return typeof value === "string" ? value : null;
1666
- }
1667
- function readSessionId(snapshot) {
1668
- const status = snapshot?.["status"];
1669
- if (typeof status !== "object" || status === null) return null;
1670
- const value = status["sessionId"];
1671
- return typeof value === "string" && value !== "" ? value : null;
1672
- }
1673
- function readCwdValue(snapshot) {
1674
- const status = snapshot?.["status"];
1675
- if (typeof status !== "object" || status === null) return "";
1676
- const value = status["cwd"];
1677
- return typeof value === "string" ? value : "";
1678
- }
1679
- function readTurnState(snapshot) {
1680
- const status = snapshot?.["status"];
1681
- if (typeof status !== "object" || status === null) return "idle";
1682
- const value = status["turnState"];
1683
- return typeof value === "string" ? value : "idle";
1684
- }
1685
- function SeatBody({
1686
- seat,
1687
- round,
1688
- running,
1689
- sessionId,
1690
- sessionKey,
1691
- cwd,
1692
- roundFolds,
1693
- foldMemory,
1694
- stepGrouping,
1695
- renderSlot,
1696
- onFork
1697
- }) {
1698
- const fold = roundFolds.get(seat.round);
1699
- const foldRunning = fold?.running === true;
1700
- const foldable = fold !== void 0 && fold.foldable && fold.hasContent && !foldRunning && !fold.blocked;
1701
- const turnKey = turnFoldKey(sessionId, seat.round);
1702
- const turnOpen = foldMemory.open(turnKey, false);
1703
- const collapsed = foldable && !turnOpen;
1704
- const reveal = () => {
1705
- foldMemory.set(turnKey, true);
1706
- };
1707
- const showFoldRow = fold !== void 0 && fold.foldable && !foldRunning;
1708
- const roundInfo = round ?? {
1709
- index: seat.round,
1710
- startIndex: seat.rows[0]?.at ?? 0,
1711
- endIndex: seat.rows[seat.rows.length - 1]?.at ?? 0,
1712
- startTs: null,
1713
- endTs: null,
1714
- answered: true
1715
- };
1716
- const answer = seat.rows.map((row) => row.entry).filter((entry) => entry.kind === "text" && entry.id >= 0).at(-1);
1717
- const tokens = seat.rows.reduce(
1718
- (sum, row) => row.entry.kind === "text" && row.entry.id >= 0 ? sum + ui$1.estimateTextTokens(row.entry.text) : sum,
1719
- 0
1720
- );
1721
- const usage = uiPrimitives.findLast(
1722
- seat.rows,
1723
- (row) => (row.entry.kind === "text" || row.entry.kind === "tool") && row.entry.usage !== void 0
1724
- )?.entry.usage;
1725
- const seatRow = (row, hidden) => /* @__PURE__ */ jsxRuntime.jsx(
1726
- RowSeat,
1727
- {
1728
- hidden,
1729
- onReveal: reveal,
1730
- roundIndex: seat.round,
1731
- children: /* @__PURE__ */ jsxRuntime.jsx(RowBoundary, { entry: row.entry, children: /* @__PURE__ */ jsxRuntime.jsx(RowBody, { row, renderSlot }) })
1732
- },
1733
- keyOf(row, sessionKey)
1734
- );
1735
- const groupOpen = (group) => foldMemory.open(stepGroupFoldKey(sessionId, group.roundIndex, group.seq), false);
1736
- const toggleGroup = (group) => {
1737
- foldMemory.set(stepGroupFoldKey(sessionId, group.roundIndex, group.seq), !groupOpen(group));
1738
- };
1739
- const liveDetail = react.useContext(FoldPrefsContext).policy.liveDetail;
1740
- const rowByAt = new Map(seat.rows.map((row) => [row.at, row]));
1741
- const processBlocks = [];
1742
- const afterBlocks = [];
1743
- for (const item of seatPlan(seat.rows.slice(1).map((row) => row.at), stepGrouping)) {
1744
- if (item.kind === "group") {
1745
- const head = item.group;
1746
- const members = item.members.map((at) => rowByAt.get(at)).filter((member) => member !== void 0);
1747
- processBlocks.push(
1748
- /* @__PURE__ */ jsxRuntime.jsx(
1749
- StepGroupSeat,
1750
- {
1751
- group: head,
1752
- turnCollapsed: collapsed,
1753
- open: groupOpen(head),
1754
- showDetail: liveDetail,
1755
- onToggle: () => toggleGroup(head),
1756
- onRevealTurn: reveal,
1757
- children: members.map((member) => seatRow(member, false))
1758
- },
1759
- `step-${String(head.roundIndex)}-${String(head.seq)}`
1760
- )
1761
- );
1762
- continue;
1763
- }
1764
- const row = rowByAt.get(item.at);
1765
- if (row === void 0) continue;
1766
- const inProcess = fold !== void 0 && fold.foldable && fold.hasContent && row.at >= fold.startIndex && row.at <= fold.endIndex;
1767
- if (inProcess && !TURN_INDEPENDENT.has(row.entry.kind)) processBlocks.push(seatRow(row, collapsed));
1768
- else afterBlocks.push(seatRow(row, false));
1769
- }
1770
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1771
- seat.rows.length === 0 ? null : seatRow(seat.rows[0], false),
1772
- showFoldRow && fold !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-row", "data-round": seat.round, children: /* @__PURE__ */ jsxRuntime.jsx(
1773
- TurnFoldRow,
1774
- {
1775
- open: !collapsed,
1776
- round: roundInfo,
1777
- disabled: !fold.hasContent || fold.blocked,
1778
- endReason: fold.endReason,
1779
- onToggle: () => {
1780
- foldMemory.set(turnKey, collapsed);
1781
- }
1782
- }
1783
- ) }) : null,
1784
- processBlocks.length === 0 ? null : (
1785
- // 过程区**包一层**再折:整轮收起是「这一片高度从 0 长回来 / 缩回 0」,一片一起动才行。
1786
- // 平铺在座位上折不了——收起的行是 `hidden`(不产生盒子),夹在它们之间的 6px flex gap
1787
- // 会留下来,几十行的轮收起来就是一片空白的间隙堆。包进一格之后,座位的 gap 只算这一格。
1788
- // 高度动画本身在 CSS:`.turn-process` 的 grid-template-rows 0fr↔1fr(不需要 JS 量高度)。
1789
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "turn-process", "data-fold": collapsed ? "closed" : "open", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "turn-process-body", children: processBlocks }) })
1790
- ),
1791
- afterBlocks,
1792
- /* @__PURE__ */ jsxRuntime.jsx(ChangesCard, { rows: seat.rows, cwd }),
1793
- /* @__PURE__ */ jsxRuntime.jsx(
1794
- RoundFoot,
1795
- {
1796
- round: roundInfo,
1797
- running,
1798
- copyText: answer?.text,
1799
- usage: usage ?? null,
1800
- tokens: tokens > 0 ? tokens : null,
1801
- onFork
1562
+ ref: bodyRef,
1563
+ className: "step-body",
1564
+ "data-step-body": true,
1565
+ "data-scroll-up": edges.up ? "1" : void 0,
1566
+ "data-scroll-down": edges.down ? "1" : void 0,
1567
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentRef, className: "step-content", children: props.children })
1802
1568
  }
1803
1569
  )
1804
1570
  ] });
1805
1571
  }
1806
- function RowBody({
1807
- row,
1808
- renderSlot
1809
- }) {
1810
- const sessionId = react.useContext(ShellSessionContext);
1811
- const cwd = react.useContext(ShellCwdContext);
1812
- const entry = row.entry;
1813
- switch (entry.kind) {
1814
- case "user":
1815
- return /* @__PURE__ */ jsxRuntime.jsx(UserRow, { entry });
1816
- case "text":
1817
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: row.live ? "entry-text live" : "entry-text", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.MarkdownView, { text: entry.text, path: "" }) });
1818
- case "thinking":
1819
- return /* @__PURE__ */ jsxRuntime.jsx(
1820
- ThinkRow,
1821
- {
1822
- entry,
1823
- live: row.live,
1824
- storeKey: `${sessionId ?? ""}:think:${String(entry.id)}`
1825
- }
1826
- );
1827
- case "tool": {
1828
- const storeKey = `${sessionId ?? ""}:${String(row.at)}`;
1829
- return renderSlot?.(TOOLVIEW_SLOT, { entry, storeKey }) ?? /* @__PURE__ */ jsxRuntime.jsx(ToolRow, { entry, storeKey });
1830
- }
1831
- case "system": {
1832
- const notice = parseReviewNotice(entry.text);
1833
- return notice === null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", children: entry.text }) : /* @__PURE__ */ jsxRuntime.jsx(ReviewNoticeCard, { notice, cwd });
1834
- }
1835
- case "turn-max-tokens":
1836
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", "data-turn-notice": "max-tokens", children: "这一轮的输出达到长度上限,已被截断" });
1837
- case "model-retry":
1838
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-system", "data-turn-notice": "model-retry", children: [
1839
- "模型请求失败,正在重试(第 ",
1840
- entry.attempt,
1841
- " 次):",
1842
- entry.text
1843
- ] });
1844
- case "turn-end":
1845
- if (entry.reason === "completed") return null;
1846
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", children: entry.reason === "aborted" ? "这一轮被中断" : "这一轮过程失败" });
1847
- case "plan":
1848
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `plan-card ${entry.plan.decision === "pending" ? "pending" : "settled"}`, children: [
1849
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "plan-head", children: [
1850
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "plan-title", children: entry.plan.title }),
1851
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "plan-verdict", children: entry.plan.decision === "pending" ? "等你批" : entry.plan.decision === "approved" ? "已批准" : "未批准" })
1852
- ] }),
1853
- /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "plan-body", children: entry.plan.text }),
1854
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "plan-foot", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "plan-file", title: entry.plan.file, children: entry.plan.file }) })
1855
- ] });
1856
- case "subagent":
1857
- return /* @__PURE__ */ jsxRuntime.jsx(SubagentRow, { entry });
1858
- case "changes":
1859
- case "turnDiff":
1860
- return null;
1861
- default: {
1862
- const kind = entry.kind;
1863
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-system", children: [
1864
- "认不出的条目:",
1865
- String(kind)
1866
- ] });
1867
- }
1572
+ function UserFileCards({ files }) {
1573
+ if (files === void 0 || files.length === 0) return null;
1574
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-user-files", children: files.map(
1575
+ (file) => file.kind === "video" && file.url !== void 0 && file.url !== "" ? /* @__PURE__ */ jsxRuntime.jsxs("figure", { className: "user-file-card user-video-card", "data-file-kind": "video", children: [
1576
+ /* @__PURE__ */ jsxRuntime.jsx("video", { src: file.url, controls: true, playsInline: true, preload: "metadata", "aria-label": file.name }),
1577
+ /* @__PURE__ */ jsxRuntime.jsx("figcaption", { className: "user-file-name", title: file.path, children: file.name }),
1578
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "user-file-meta", children: uiPrimitives.formatBytes(file.bytes) })
1579
+ ] }, file.sha) : /* @__PURE__ */ jsxRuntime.jsx(FileAttachmentCard, { file }, file.sha)
1580
+ ) });
1581
+ }
1582
+ function FileAttachmentCard({ file }) {
1583
+ const body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1584
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.FileIcon, { name: file.name, size: 16 }),
1585
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "user-file-name", title: file.path, children: file.name }),
1586
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "user-file-meta", children: uiPrimitives.formatBytes(file.bytes) })
1587
+ ] });
1588
+ if (file.url === void 0 || file.url === "") {
1589
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "user-file-card", "data-file-kind": "file", children: body });
1868
1590
  }
1591
+ return /* @__PURE__ */ jsxRuntime.jsx("a", { className: "user-file-card", "data-file-kind": "file", href: file.url, target: "_blank", rel: "noreferrer", title: file.path, children: body });
1869
1592
  }
1870
1593
  function UserRow({ entry }) {
1871
1594
  const actions = react.useContext(FlowActionsContext);
1595
+ const cwd = react.useContext(ShellCwdContext);
1872
1596
  const [draft, setDraft] = react.useState(null);
1597
+ const [zoom, setZoom] = react.useState(null);
1598
+ const findings = uiPrimitives.parseReviewFindings(entry.text);
1599
+ if (findings !== null) {
1600
+ return /* @__PURE__ */ jsxRuntime.jsx(uiPrimitives.ReviewFindingsCard, { doc: findings, cwd, onOpenLocation: (path) => ui$1.setDockPreview({ path }) });
1601
+ }
1873
1602
  if (entry.internal === true) {
1874
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", "data-internal": "1", title: entry.text, children: teammateReportLabel(entry.text) });
1603
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", "data-internal": "1", title: entry.text, children: internalLabel(entry.text) });
1875
1604
  }
1876
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "user-turn", children: [
1877
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `entry-user${draft === null ? "" : " editing"}`, children: [
1878
- entry.images === void 0 || entry.images.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-user-images", children: entry.images.map((url, index) => /* @__PURE__ */ jsxRuntime.jsx("a", { href: url, target: "_blank", rel: "noreferrer", "data-tip": "点开看原图", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: url, alt: `第 ${String(index + 1)} 张贴图` }) }, index)) }),
1879
- draft === null ? entry.text : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "user-edit", children: [
1880
- /* @__PURE__ */ jsxRuntime.jsx(
1881
- "textarea",
1605
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1606
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "user-turn", children: [
1607
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `entry-user${draft === null ? "" : " editing"}`, children: [
1608
+ entry.images === void 0 || entry.images.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-user-images", children: entry.images.map((url, index) => /* @__PURE__ */ jsxRuntime.jsx(
1609
+ "button",
1882
1610
  {
1883
- className: "user-edit-box",
1884
- value: draft,
1885
- autoFocus: true,
1886
- rows: Math.min(10, Math.max(2, draft.split("\n").length)),
1887
- "aria-label": "编辑这条消息",
1888
- onChange: (event) => {
1889
- setDraft(event.target.value);
1611
+ type: "button",
1612
+ className: "entry-shot",
1613
+ "data-tip": "点开看原图",
1614
+ "aria-label": `放大第 ${String(index + 1)} 张贴图`,
1615
+ onClick: () => {
1616
+ setZoom(url);
1890
1617
  },
1891
- onKeyDown: (event) => {
1892
- if (event.key === "Escape") {
1893
- event.preventDefault();
1894
- setDraft(null);
1895
- return;
1896
- }
1897
- if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing) return;
1898
- event.preventDefault();
1899
- const text = draft.trim();
1900
- if (text === "") return;
1901
- setDraft(null);
1902
- actions.editRefork(entry, text);
1903
- }
1904
- }
1905
- ),
1906
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "user-edit-note", children: "Enter 重发(分叉出新会话,原会话保留) · Shift+Enter 换行 · Esc 取消" }),
1907
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "user-edit-actions", children: [
1618
+ children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: url, alt: `第 ${String(index + 1)} 张贴图` })
1619
+ },
1620
+ index
1621
+ )) }),
1622
+ /* @__PURE__ */ jsxRuntime.jsx(UserFileCards, { files: entry.files }),
1623
+ draft === null ? entry.text : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "user-edit", children: [
1908
1624
  /* @__PURE__ */ jsxRuntime.jsx(
1909
- "button",
1625
+ "textarea",
1910
1626
  {
1911
- type: "button",
1912
- className: "dsc-btn",
1913
- "data-variant": "ghost",
1914
- "data-size": "xs",
1915
- onClick: () => {
1916
- setDraft(null);
1627
+ className: "user-edit-box",
1628
+ value: draft,
1629
+ autoFocus: true,
1630
+ rows: Math.min(10, Math.max(2, draft.split("\n").length)),
1631
+ "aria-label": "编辑这条消息",
1632
+ onChange: (event) => {
1633
+ setDraft(event.target.value);
1917
1634
  },
1918
- children: "取消"
1919
- }
1920
- ),
1921
- /* @__PURE__ */ jsxRuntime.jsx(
1922
- "button",
1923
- {
1924
- type: "button",
1925
- className: "dsc-btn",
1926
- "data-variant": "primary",
1927
- "data-size": "xs",
1928
- disabled: draft.trim() === "",
1929
- onClick: () => {
1635
+ onKeyDown: (event) => {
1636
+ if (event.key === "Escape") {
1637
+ event.preventDefault();
1638
+ setDraft(null);
1639
+ return;
1640
+ }
1641
+ if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing) return;
1642
+ event.preventDefault();
1930
1643
  const text = draft.trim();
1931
1644
  if (text === "") return;
1932
1645
  setDraft(null);
1933
- actions.editRefork(entry, text);
1934
- },
1935
- children: "重发"
1646
+ actions.editAndResend(entry, text);
1647
+ }
1936
1648
  }
1937
- )
1649
+ ),
1650
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "user-edit-note", children: "Enter 重发(这条之后的回答会作废,在当前会话里重来) · Shift+Enter 换行 · Esc 取消" }),
1651
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "user-edit-actions", children: [
1652
+ /* @__PURE__ */ jsxRuntime.jsx(
1653
+ "button",
1654
+ {
1655
+ type: "button",
1656
+ className: "dsc-btn",
1657
+ "data-variant": "ghost",
1658
+ "data-size": "xs",
1659
+ onClick: () => {
1660
+ setDraft(null);
1661
+ },
1662
+ children: "取消"
1663
+ }
1664
+ ),
1665
+ /* @__PURE__ */ jsxRuntime.jsx(
1666
+ "button",
1667
+ {
1668
+ type: "button",
1669
+ className: "dsc-btn",
1670
+ "data-variant": "primary",
1671
+ "data-size": "xs",
1672
+ disabled: draft.trim() === "",
1673
+ onClick: () => {
1674
+ const text = draft.trim();
1675
+ if (text === "") return;
1676
+ setDraft(null);
1677
+ actions.editAndResend(entry, text);
1678
+ },
1679
+ children: "重发"
1680
+ }
1681
+ )
1682
+ ] })
1938
1683
  ] })
1939
- ] })
1940
- ] }),
1941
- draft === null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "user-actions", children: /* @__PURE__ */ jsxRuntime.jsx(
1942
- "button",
1943
- {
1944
- type: "button",
1945
- className: "user-act",
1946
- title: actions.busy ? "这一轮还在跑,先等它结束或打断再编辑" : "编辑这条消息并重发(会分叉出新会话,原会话保留)",
1947
- "aria-label": "编辑并重发这条消息",
1948
- disabled: actions.busy,
1949
- onClick: () => {
1950
- setDraft(entry.text);
1684
+ ] }),
1685
+ draft === null ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "user-actions", children: /* @__PURE__ */ jsxRuntime.jsx(
1686
+ "button",
1687
+ {
1688
+ type: "button",
1689
+ className: "user-act",
1690
+ title: actions.busy ? "这一轮还在跑,先等它结束或打断再编辑" : "编辑这条消息并重发(这条之后的回答会作废,在当前会话里重来)",
1691
+ "aria-label": "编辑并重发这条消息",
1692
+ disabled: actions.busy,
1693
+ onClick: () => {
1694
+ setDraft(entry.text);
1695
+ },
1696
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 15 })
1697
+ }
1698
+ ) }) : null
1699
+ ] }),
1700
+ zoom === null ? null : /* @__PURE__ */ jsxRuntime.jsx(uiPrimitives.ImageLightbox, { src: zoom, alt: "放大的贴图", onClose: () => {
1701
+ setZoom(null);
1702
+ } })
1703
+ ] });
1704
+ }
1705
+ function ReadonlyUserRow({ entry }) {
1706
+ const cwd = react.useContext(ShellCwdContext);
1707
+ const [zoom, setZoom] = react.useState(null);
1708
+ const findings = uiPrimitives.parseReviewFindings(entry.text);
1709
+ if (findings !== null) {
1710
+ return /* @__PURE__ */ jsxRuntime.jsx(uiPrimitives.ReviewFindingsCard, { doc: findings, cwd, onOpenLocation: (path) => ui$1.setDockPreview({ path }) });
1711
+ }
1712
+ if (entry.internal === true) return /* @__PURE__ */ jsxRuntime.jsx(UserRow, { entry });
1713
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1714
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "user-turn", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-user", children: [
1715
+ entry.images === void 0 || entry.images.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-user-images", children: entry.images.map((url, index) => /* @__PURE__ */ jsxRuntime.jsx(
1716
+ "button",
1717
+ {
1718
+ type: "button",
1719
+ className: "entry-shot",
1720
+ "data-tip": "点开看原图",
1721
+ "aria-label": `放大第 ${String(index + 1)} 张贴图`,
1722
+ onClick: () => {
1723
+ setZoom(url);
1724
+ },
1725
+ children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: url, alt: `第 ${String(index + 1)} 张贴图` })
1951
1726
  },
1952
- children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 15 })
1953
- }
1954
- ) }) : null
1727
+ index
1728
+ )) }),
1729
+ /* @__PURE__ */ jsxRuntime.jsx(UserFileCards, { files: entry.files }),
1730
+ entry.text
1731
+ ] }) }),
1732
+ zoom === null ? null : /* @__PURE__ */ jsxRuntime.jsx(uiPrimitives.ImageLightbox, { src: zoom, alt: "放大的贴图", onClose: () => {
1733
+ setZoom(null);
1734
+ } })
1955
1735
  ] });
1956
1736
  }
1737
+ const BAR_MIN_CONTENT_H = 400;
1738
+ function expandedContentHeight(body) {
1739
+ let total = 0;
1740
+ for (const child of Array.from(body.children)) {
1741
+ if (!(child instanceof HTMLElement)) continue;
1742
+ if (child.dataset.tcChrome !== void 0) continue;
1743
+ total += Math.max(child.scrollHeight, child.offsetHeight);
1744
+ }
1745
+ return total;
1746
+ }
1957
1747
  function firstLine(text) {
1958
1748
  const newline = text.indexOf("\n");
1959
1749
  return newline === -1 ? text : text.slice(0, newline);
1960
1750
  }
1751
+ const MAX_SUMMARY_CHARS = 80;
1752
+ function clipSummary(text) {
1753
+ const chars = Array.from(text);
1754
+ return chars.length > MAX_SUMMARY_CHARS ? `${chars.slice(0, MAX_SUMMARY_CHARS).join("")}…` : text;
1755
+ }
1961
1756
  function latestCompletedParagraphFirstLine(text) {
1962
1757
  let summary = "";
1963
1758
  let paragraphStart = 0;
@@ -1980,17 +1775,15 @@ function ThinkRow({
1980
1775
  storeKey
1981
1776
  }) {
1982
1777
  const prefs = react.useContext(FoldPrefsContext);
1983
- const [open, setOpen] = react.useState(() => readFold(storeKey, prefs.reasoningOpen));
1778
+ const [open, setOpenPersisted] = useFoldState(storeKey, prefs.reasoningOpen);
1984
1779
  const [barVisible, setBarVisible] = react.useState(false);
1985
1780
  const bodyRef = react.useRef(null);
1986
- const setOpenPersisted = (next) => {
1987
- writeFold(storeKey, next);
1988
- setOpen(next);
1989
- };
1990
1781
  const toggle = () => {
1991
1782
  setOpenPersisted(!open);
1992
1783
  };
1993
- const summary = (live ? latestCompletedParagraphFirstLine(entry.text) : firstLine(entry.text)).replaceAll("**", "");
1784
+ const summary = clipSummary(
1785
+ (live ? latestCompletedParagraphFirstLine(entry.text) : firstLine(entry.text)).replaceAll("**", "")
1786
+ );
1994
1787
  const preview = summary !== "" && (live || prefs.policy.reasoningPreview);
1995
1788
  react.useEffect(() => {
1996
1789
  const body = bodyRef.current;
@@ -2023,7 +1816,7 @@ function ThinkRow({
2023
1816
  role: "button",
2024
1817
  tabIndex: 0,
2025
1818
  "aria-expanded": open,
2026
- "data-tip": open ? "收起这段思考过程" : "展开这段思考过程",
1819
+ "data-tip": open ? "收起这段思考" : "展开这段思考",
2027
1820
  onClick: toggle,
2028
1821
  onKeyDown: (event) => {
2029
1822
  if (event.key !== "Enter" && event.key !== " ") return;
@@ -2031,8 +1824,8 @@ function ThinkRow({
2031
1824
  toggle();
2032
1825
  },
2033
1826
  children: [
2034
- /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 12, className: "think-star" }),
2035
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-label", children: "思考过程" }),
1827
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-leading", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 12, className: "think-star" }) }),
1828
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-label", children: "思考" }),
2036
1829
  preview ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-dot", "aria-hidden": "true" }) : null,
2037
1830
  preview ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-summary", "data-streaming": live ? "1" : void 0, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-summary-text", "data-shimmer": live ? summary : void 0, children: summary }) }) : null,
2038
1831
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-status", children: live ? /* @__PURE__ */ jsxRuntime.jsx("i", { className: "think-spin", "aria-hidden": "true" }) : null }),
@@ -2042,7 +1835,7 @@ function ThinkRow({
2042
1835
  ),
2043
1836
  open && barVisible ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "think-bar", "data-think-chrome": "1", children: [
2044
1837
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "think-bar-status", children: [
2045
- "思考过程 · ",
1838
+ "思考 · ",
2046
1839
  live ? "进行中" : "已完成"
2047
1840
  ] }),
2048
1841
  /* @__PURE__ */ jsxRuntime.jsxs(
@@ -2050,7 +1843,7 @@ function ThinkRow({
2050
1843
  {
2051
1844
  type: "button",
2052
1845
  className: "think-collapse",
2053
- title: "收起这段思考过程",
1846
+ title: "收起这段思考",
2054
1847
  onClick: () => {
2055
1848
  setOpenPersisted(false);
2056
1849
  },
@@ -2091,21 +1884,11 @@ function BuiltinToolView(props) {
2091
1884
  }
2092
1885
  );
2093
1886
  }
2094
- const BAR_MIN_CONTENT_H = 400;
2095
- function expandedContentHeight(body) {
2096
- let total = 0;
2097
- for (const child of Array.from(body.children)) {
2098
- if (!(child instanceof HTMLElement)) continue;
2099
- if (child.dataset.tcChrome !== void 0) continue;
2100
- total += Math.max(child.scrollHeight, child.offsetHeight);
2101
- }
2102
- return total;
2103
- }
2104
1887
  function ToolRow({ entry, matched, storeKey }) {
2105
1888
  const call = entry.call;
2106
1889
  const prefs = react.useContext(FoldPrefsContext);
2107
1890
  const cwd = react.useContext(ShellCwdContext);
2108
- const [open, setOpen] = react.useState(() => readFold(storeKey, prefs.toolOpen));
1891
+ const [open, setOpenPersisted] = useFoldState(storeKey, prefs.toolOpen);
2109
1892
  const [barVisible, setBarVisible] = react.useState(false);
2110
1893
  const expandable = call.status !== "preparing";
2111
1894
  const bodyOpen = open && expandable;
@@ -2117,10 +1900,6 @@ function ToolRow({ entry, matched, storeKey }) {
2117
1900
  const intended = useIntendedDiff(call, cwd);
2118
1901
  const bodyRef = react.useRef(null);
2119
1902
  const barRef = react.useRef(null);
2120
- const setOpenPersisted = (next) => {
2121
- writeFold(storeKey, next);
2122
- setOpen(next);
2123
- };
2124
1903
  const toggle = () => {
2125
1904
  if (expandable) setOpenPersisted(!open);
2126
1905
  };
@@ -2177,10 +1956,12 @@ function ToolRow({ entry, matched, storeKey }) {
2177
1956
  toggle();
2178
1957
  },
2179
1958
  children: [
2180
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tool-dot", "aria-hidden": "true" }),
2181
- /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 14, className: "tool-icon" }),
1959
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "tool-leading", "aria-hidden": "true", children: [
1960
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tool-dot" }),
1961
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 14, className: "tool-icon" })
1962
+ ] }),
2182
1963
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "verb", children: uiPrimitives.toolVerb(match.base, call.status) }),
2183
- match.known ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: call.name }),
1964
+ match.known || call.name === "" ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "name", children: `· ${call.name}` }),
2184
1965
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "preview", children: intended !== null ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2185
1966
  /* @__PURE__ */ jsxRuntime.jsx(OpenPathButton, { absPath: intended.absPath, cwd, patch: intended.file ?? call.change ?? null }),
2186
1967
  intended.file !== null && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-counts", children: [
@@ -2382,7 +2163,7 @@ function ChangesCard({ rows, cwd }) {
2382
2163
  children: [
2383
2164
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-tile", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.FileIcon, { name: (single ?? files[0]).path, size: 20 }) }),
2384
2165
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-titles", children: [
2385
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-title", children: single === void 0 ? `${String(files.length)} 个文件已更改` : uiPrimitives.baseNameOf(single.path) }),
2166
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-title", children: single === void 0 ? `已编辑 ${String(files.length)} 个文件` : uiPrimitives.baseNameOf(single.path) }),
2386
2167
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-stat", children: [
2387
2168
  /* @__PURE__ */ jsxRuntime.jsx(Counts, { added: totalAdded, removed: totalRemoved }),
2388
2169
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-hint", children: "点击审查改动" })
@@ -2492,168 +2273,752 @@ function ChangesCard({ rows, cwd }) {
2492
2273
  ) : null
2493
2274
  ] })
2494
2275
  );
2495
- }
2496
- function RoundFoot(props) {
2497
- const clock = props.running ? null : uiPrimitives.formatClock(props.round.startTs);
2498
- const used = props.running ? null : uiPrimitives.formatDuration(roundDuration(props.round));
2499
- const measured = props.running ? null : props.usage;
2500
- const real = measured !== null && measured.inputTokens + measured.outputTokens > 0 ? measured.inputTokens + measured.outputTokens : null;
2501
- const estimated = real !== null || props.running || props.tokens === null || props.tokens <= 0 ? null : props.tokens;
2502
- const copy = props.copyText !== void 0 && props.copyText !== "";
2503
- const fork = props.onFork !== void 0;
2504
- if (clock === null && !copy && !fork && real === null && estimated === null) return null;
2505
- return (
2506
- // 与 `.changes-card` 同理:不再包 `.entry-row`,让 `.turn-seat > .round-foot` 的
2507
- // 间距规则命中——包一层之后那条规则失配,回落到 `.round-foot` 自带的 -15px
2508
- // 负外边距(它本来是给旧版 `.chat-inner` 的 16px 间距设计的),会把这一行顶进
2509
- // 上面的改动卡里(截图里的「底部按钮与文件变更重叠」就是这么来的)。
2510
- /* @__PURE__ */ jsxRuntime.jsxs(
2511
- "div",
2512
- {
2513
- className: "round-foot",
2514
- title: used === null ? void 0 : `用时 ${used}(从发出这条消息到这一轮最后一次写入,中间的工具调用与思考都算在内)`,
2515
- children: [
2516
- copy ? /* @__PURE__ */ jsxRuntime.jsx(
2517
- "button",
2518
- {
2519
- type: "button",
2520
- className: "round-act",
2521
- title: "复制这条回复的原文",
2522
- "aria-label": "复制这条回复的原文",
2523
- onClick: () => {
2524
- void navigator.clipboard.writeText(props.copyText ?? "").catch(() => void 0);
2525
- },
2526
- children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCopy, { size: 17 })
2527
- }
2528
- ) : null,
2529
- fork ? /* @__PURE__ */ jsxRuntime.jsx(
2530
- "button",
2531
- {
2532
- type: "button",
2533
- className: "user-act",
2534
- title: "以这条消息为界分叉出新会话",
2535
- "aria-label": "以这条消息为界分叉出新会话",
2536
- disabled: props.running,
2537
- onClick: props.onFork,
2538
- children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBranch, { size: 15 })
2539
- }
2540
- ) : null,
2541
- real !== null ? /* @__PURE__ */ jsxRuntime.jsxs(
2542
- "span",
2543
- {
2544
- className: "round-tokens",
2545
- title: "这一轮所有模型请求的 prompt 与 completion 之和(宿主上报的真实用量)",
2546
- children: [
2547
- "用量 ",
2548
- uiPrimitives.formatTokens(real),
2549
- " tok"
2550
- ]
2551
- }
2552
- ) : null,
2553
- estimated !== null ? /* @__PURE__ */ jsxRuntime.jsxs(
2554
- "span",
2555
- {
2556
- className: "round-tokens",
2557
- title: "助手正文的 token 估算值(老会话无宿主上报用量)",
2558
- children: [
2559
- "~",
2560
- uiPrimitives.formatTokens(estimated),
2561
- " tok"
2562
- ]
2563
- }
2564
- ) : null,
2565
- clock !== null && (real !== null || estimated !== null) ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "round-sep", "aria-hidden": "true", children: "·" }) : null,
2566
- clock !== null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "round-clock", title: "这条消息发出的时刻(本机时区)", children: clock }) : null
2567
- ]
2276
+ }
2277
+ function RoundFoot(props) {
2278
+ const clock = props.running ? null : uiPrimitives.formatClock(props.round.startTs);
2279
+ const used = props.running ? null : uiPrimitives.formatDuration(roundDuration(props.round));
2280
+ const measured = props.running ? null : props.usage;
2281
+ const real = measured !== null && measured.inputTokens + measured.outputTokens > 0 ? measured.inputTokens + measured.outputTokens : null;
2282
+ const estimated = real !== null || props.running || props.tokens === null || props.tokens <= 0 ? null : props.tokens;
2283
+ const copy = !props.running && props.copyText !== void 0 && props.copyText !== "";
2284
+ const fork = !props.running && props.onFork !== void 0;
2285
+ if (clock === null && !copy && !fork && real === null && estimated === null) return null;
2286
+ return (
2287
+ // 与 `.changes-card` 同理:不再包 `.entry-row`,让 `.turn-seat > .round-foot` 的
2288
+ // 间距规则命中——包一层之后那条规则失配,回落到 `.round-foot` 自带的 -15px
2289
+ // 负外边距(它本来是给旧版 `.chat-inner` 的 16px 间距设计的),会把这一行顶进
2290
+ // 上面的改动卡里(截图里的「底部按钮与文件变更重叠」就是这么来的)。
2291
+ /* @__PURE__ */ jsxRuntime.jsxs(
2292
+ "div",
2293
+ {
2294
+ className: "round-foot",
2295
+ title: used === null ? void 0 : `用时 ${used}(从发出这条消息到这一轮最后一次写入,中间的工具调用与思考都算在内)`,
2296
+ children: [
2297
+ copy ? /* @__PURE__ */ jsxRuntime.jsx(
2298
+ "button",
2299
+ {
2300
+ type: "button",
2301
+ className: "round-act",
2302
+ title: "复制这条回复的原文",
2303
+ "aria-label": "复制这条回复的原文",
2304
+ onClick: () => {
2305
+ void navigator.clipboard.writeText(props.copyText ?? "").catch(() => void 0);
2306
+ },
2307
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconCopy, { size: 17 })
2308
+ }
2309
+ ) : null,
2310
+ fork ? /* @__PURE__ */ jsxRuntime.jsx(
2311
+ "button",
2312
+ {
2313
+ type: "button",
2314
+ className: "user-act",
2315
+ title: "以这条消息为界分叉出新会话",
2316
+ "aria-label": "以这条消息为界分叉出新会话",
2317
+ onClick: props.onFork,
2318
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconBranch, { size: 15 })
2319
+ }
2320
+ ) : null,
2321
+ real !== null ? /* @__PURE__ */ jsxRuntime.jsxs(
2322
+ "span",
2323
+ {
2324
+ className: "round-tokens",
2325
+ title: "这一轮所有模型请求的 prompt 与 completion 之和(宿主上报的真实用量)",
2326
+ children: [
2327
+ "用量 ",
2328
+ uiPrimitives.formatTokens(real),
2329
+ " tok"
2330
+ ]
2331
+ }
2332
+ ) : null,
2333
+ estimated !== null ? /* @__PURE__ */ jsxRuntime.jsxs(
2334
+ "span",
2335
+ {
2336
+ className: "round-tokens",
2337
+ title: "助手正文的 token 估算值(老会话无宿主上报用量)",
2338
+ children: [
2339
+ "~",
2340
+ uiPrimitives.formatTokens(estimated),
2341
+ " tok"
2342
+ ]
2343
+ }
2344
+ ) : null,
2345
+ clock !== null && (real !== null || estimated !== null) ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "round-sep", "aria-hidden": "true", children: "·" }) : null,
2346
+ clock !== null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "round-clock", title: "这条消息发出的时刻(本机时区)", children: clock }) : null
2347
+ ]
2348
+ }
2349
+ )
2350
+ );
2351
+ }
2352
+ function TurnStatusLine(props) {
2353
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "turn-status", children: [
2354
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "turn-status-spin", "aria-hidden": "true" }),
2355
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "turn-status-stage", role: "status", children: props.text }),
2356
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "turn-status-dots", "aria-hidden": "true", children: [
2357
+ /* @__PURE__ */ jsxRuntime.jsx("i", {}),
2358
+ /* @__PURE__ */ jsxRuntime.jsx("i", {}),
2359
+ /* @__PURE__ */ jsxRuntime.jsx("i", {})
2360
+ ] })
2361
+ ] });
2362
+ }
2363
+ function groupTask(members) {
2364
+ for (const member of members) {
2365
+ const entry = member.entry;
2366
+ if (entry.kind !== "tool") continue;
2367
+ const text = uiPrimitives.toolSummary(entry.call.name, entry.call.argsText);
2368
+ if (text !== "") return text;
2369
+ }
2370
+ return "";
2371
+ }
2372
+ function SeatBody({
2373
+ seat,
2374
+ round,
2375
+ running,
2376
+ sessionId,
2377
+ sessionKey,
2378
+ cwd,
2379
+ roundFolds,
2380
+ foldMemory,
2381
+ stepGrouping,
2382
+ renderSlot,
2383
+ onFork
2384
+ }) {
2385
+ const fold = roundFolds.get(seat.round);
2386
+ const foldRunning = fold?.running === true;
2387
+ const foldable = fold !== void 0 && fold.foldable && fold.hasContent && !foldRunning && !fold.blocked;
2388
+ const turnKey = turnFoldKey(sessionId, seat.round);
2389
+ const turnOpen = foldMemory.open(turnKey, false);
2390
+ const collapsed = foldable && !turnOpen;
2391
+ const reveal = () => {
2392
+ foldMemory.set(turnKey, true);
2393
+ };
2394
+ const showFoldRow = fold !== void 0 && fold.foldable && !foldRunning;
2395
+ const roundInfo = round ?? {
2396
+ index: seat.round,
2397
+ startIndex: seat.rows[0]?.at ?? 0,
2398
+ endIndex: seat.rows[seat.rows.length - 1]?.at ?? 0,
2399
+ startTs: null,
2400
+ endTs: null,
2401
+ answered: true
2402
+ };
2403
+ const answer = seat.rows.map((row) => row.entry).filter((entry) => entry.kind === "text" && entry.id >= 0).at(-1);
2404
+ const tokens = seat.rows.reduce(
2405
+ (sum, row) => row.entry.kind === "text" && row.entry.id >= 0 ? sum + ui$1.estimateTextTokens(row.entry.text) : sum,
2406
+ 0
2407
+ );
2408
+ const usage = uiPrimitives.findLast(
2409
+ seat.rows,
2410
+ (row) => (row.entry.kind === "text" || row.entry.kind === "tool") && row.entry.usage !== void 0
2411
+ )?.entry.usage;
2412
+ const seatRow = (row, hidden) => /* @__PURE__ */ jsxRuntime.jsx(
2413
+ RowSeat,
2414
+ {
2415
+ hidden,
2416
+ onReveal: reveal,
2417
+ roundIndex: seat.round,
2418
+ children: /* @__PURE__ */ jsxRuntime.jsx(RowBoundary, { entry: row.entry, children: /* @__PURE__ */ jsxRuntime.jsx(RowBody, { row, renderSlot }) })
2419
+ },
2420
+ keyOf(row, sessionKey)
2421
+ );
2422
+ const groupOpen = (group) => foldMemory.open(stepGroupFoldKey(sessionId, group.roundIndex, group.seq), false);
2423
+ const toggleGroup = (group) => {
2424
+ foldMemory.set(stepGroupFoldKey(sessionId, group.roundIndex, group.seq), !groupOpen(group));
2425
+ };
2426
+ const liveDetail = react.useContext(FoldPrefsContext).policy.liveDetail;
2427
+ const rowByAt = new Map(seat.rows.map((row) => [row.at, row]));
2428
+ const processBlocks = [];
2429
+ const afterBlocks = [];
2430
+ const inProcessOf = (row) => fold !== void 0 && fold.foldable && fold.hasContent && row.at >= fold.startIndex && row.at <= fold.endIndex;
2431
+ const pushRow = (row) => {
2432
+ if (inProcessOf(row) && !TURN_INDEPENDENT.has(row.entry.kind)) processBlocks.push(seatRow(row, collapsed));
2433
+ else afterBlocks.push(seatRow(row, false));
2434
+ };
2435
+ for (const item of seatPlan(seat.rows.slice(1).map((row) => row.at), stepGrouping)) {
2436
+ if (item.kind === "group") {
2437
+ const head = item.group;
2438
+ const members = item.members.map((at) => rowByAt.get(at)).filter((member) => member !== void 0);
2439
+ if (!needsGroupHeader(head)) {
2440
+ const only = members[0];
2441
+ if (only !== void 0) pushRow(only);
2442
+ continue;
2443
+ }
2444
+ processBlocks.push(
2445
+ /* @__PURE__ */ jsxRuntime.jsx(
2446
+ StepGroupSeat,
2447
+ {
2448
+ group: head,
2449
+ turnCollapsed: collapsed,
2450
+ open: groupOpen(head),
2451
+ showDetail: liveDetail,
2452
+ task: head.closed ? groupTask(members) : "",
2453
+ onToggle: () => toggleGroup(head),
2454
+ onRevealTurn: reveal,
2455
+ children: members.map((member) => seatRow(member, false))
2456
+ },
2457
+ `step-${String(head.roundIndex)}-${String(head.seq)}`
2458
+ )
2459
+ );
2460
+ continue;
2461
+ }
2462
+ const row = rowByAt.get(item.at);
2463
+ if (row === void 0) continue;
2464
+ pushRow(row);
2465
+ }
2466
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2467
+ seat.rows.length === 0 ? null : seatRow(seat.rows[0], false),
2468
+ showFoldRow && fold !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-row", "data-round": seat.round, children: /* @__PURE__ */ jsxRuntime.jsx(
2469
+ TurnFoldRow,
2470
+ {
2471
+ open: !collapsed,
2472
+ round: roundInfo,
2473
+ disabled: !fold.hasContent || fold.blocked,
2474
+ endReason: fold.endReason,
2475
+ onToggle: () => {
2476
+ foldMemory.set(turnKey, collapsed);
2477
+ }
2478
+ }
2479
+ ) }) : null,
2480
+ processBlocks.length === 0 ? null : (
2481
+ // 过程区**包一层**再折:整轮收起是「这一片高度从 0 长回来 / 缩回 0」,一片一起动才行。
2482
+ // 平铺在座位上折不了——收起的行是 `hidden`(不产生盒子),夹在它们之间的 6px flex gap
2483
+ // 会留下来,几十行的轮收起来就是一片空白的间隙堆。包进一格之后,座位的 gap 只算这一格。
2484
+ // 高度动画本身在 CSS:`.turn-process` 的 grid-template-rows 0fr↔1fr(不需要 JS 量高度)。
2485
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "turn-process", "data-fold": collapsed ? "closed" : "open", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "turn-process-body", children: processBlocks }) })
2486
+ ),
2487
+ afterBlocks,
2488
+ running ? null : /* @__PURE__ */ jsxRuntime.jsx(ChangesCard, { rows: seat.rows, cwd }),
2489
+ /* @__PURE__ */ jsxRuntime.jsx(
2490
+ RoundFoot,
2491
+ {
2492
+ round: roundInfo,
2493
+ running,
2494
+ copyText: answer?.text,
2495
+ usage: usage ?? null,
2496
+ tokens: tokens > 0 ? tokens : null,
2497
+ onFork
2498
+ }
2499
+ )
2500
+ ] });
2501
+ }
2502
+ function RowBody({
2503
+ row,
2504
+ renderSlot
2505
+ }) {
2506
+ const sessionId = react.useContext(ShellSessionContext);
2507
+ const cwd = react.useContext(ShellCwdContext);
2508
+ const entry = row.entry;
2509
+ switch (entry.kind) {
2510
+ case "user":
2511
+ return /* @__PURE__ */ jsxRuntime.jsx(UserRow, { entry });
2512
+ case "text":
2513
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: row.live ? "entry-text live" : "entry-text", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.MarkdownView, { text: entry.text, path: "", streaming: row.live }) });
2514
+ case "thinking":
2515
+ return /* @__PURE__ */ jsxRuntime.jsx(
2516
+ ThinkRow,
2517
+ {
2518
+ entry,
2519
+ live: row.live,
2520
+ storeKey: `${sessionId ?? ""}:think:${String(entry.id)}`
2521
+ }
2522
+ );
2523
+ case "tool": {
2524
+ const storeKey = `${sessionId ?? ""}:${String(row.at)}`;
2525
+ return renderSlot?.(TOOLVIEW_SLOT, { entry, storeKey }) ?? /* @__PURE__ */ jsxRuntime.jsx(ToolRow, { entry, storeKey });
2526
+ }
2527
+ case "system": {
2528
+ const notice = uiPrimitives.parseReviewNotice(entry.text);
2529
+ if (notice !== null) return /* @__PURE__ */ jsxRuntime.jsx(uiPrimitives.ReviewNoticeCard, { notice, cwd });
2530
+ return entry.command === true ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system-command", children: entry.text }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", children: entry.text });
2531
+ }
2532
+ case "turn-max-tokens":
2533
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", "data-turn-notice": "max-tokens", children: "这一轮的输出达到长度上限,已被截断" });
2534
+ case "model-retry":
2535
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-system", "data-turn-notice": "model-retry", children: [
2536
+ "模型请求失败,正在重试(第 ",
2537
+ entry.attempt,
2538
+ " 次):",
2539
+ entry.text
2540
+ ] });
2541
+ case "turn-end":
2542
+ if (entry.reason === "completed") return null;
2543
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", children: entry.reason === "aborted" ? "这一轮被中断" : "这一轮过程失败" });
2544
+ case "plan":
2545
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `plan-card ${entry.plan.decision === "pending" ? "pending" : "settled"}`, children: [
2546
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "plan-head", children: [
2547
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "plan-title", children: entry.plan.title }),
2548
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "plan-verdict", children: entry.plan.decision === "pending" ? "等你批" : entry.plan.decision === "approved" ? "已批准" : "未批准" })
2549
+ ] }),
2550
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "plan-body", children: entry.plan.text }),
2551
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "plan-foot", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "plan-file", title: entry.plan.file, children: entry.plan.file }) })
2552
+ ] });
2553
+ case "subagent":
2554
+ return /* @__PURE__ */ jsxRuntime.jsx(SubagentRow, { entry });
2555
+ case "changes":
2556
+ case "turnDiff":
2557
+ return null;
2558
+ default: {
2559
+ const kind = entry.kind;
2560
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-system", children: [
2561
+ "认不出的条目:",
2562
+ String(kind)
2563
+ ] });
2564
+ }
2565
+ }
2566
+ }
2567
+ class RowBoundary extends react.Component {
2568
+ state = { error: null };
2569
+ static getDerivedStateFromError(error) {
2570
+ return { error };
2571
+ }
2572
+ componentDidUpdate(previous) {
2573
+ if (this.state.error !== null && previous.entry !== this.props.entry) this.setState({ error: null });
2574
+ }
2575
+ render() {
2576
+ if (this.state.error !== null) {
2577
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-system", children: [
2578
+ "这一条没画出来:",
2579
+ this.state.error.message
2580
+ ] });
2581
+ }
2582
+ return this.props.children;
2583
+ }
2584
+ }
2585
+ const WELCOME_CARDS = [
2586
+ { id: "read", Icon: ui$1.IconCode, title: "看懂代码", hint: "解释一处实现的来龙去脉", prompt: "帮我讲清楚这段代码在做什么:\n" },
2587
+ { id: "build", Icon: ui$1.IconSpark, title: "做点东西", hint: "从需求一路写到能跑", prompt: "帮我实现:" },
2588
+ {
2589
+ id: "review",
2590
+ Icon: ui$1.IconDiff,
2591
+ title: "审查改动",
2592
+ hint: "看未提交的改动有没有坑",
2593
+ prompt: "审查当前未提交的改动,指出风险、遗漏和可以简化的地方。"
2594
+ },
2595
+ { id: "fix", Icon: ui$1.IconTarget, title: "排查问题", hint: "从一个报错查到根因", prompt: "帮我排查一下这个问题:\n" }
2596
+ ];
2597
+ const WELCOME_ICON_BY_ID = new Map(
2598
+ WELCOME_CARDS.map((card) => [`welcome.${card.id}`, card.Icon])
2599
+ );
2600
+ function elapsedLabel(at) {
2601
+ const minutes = Math.max(Math.round((Date.now() - at) / 6e4), 0);
2602
+ if (minutes < 1) return "刚刚";
2603
+ if (minutes < 60) return `${String(minutes)} 分钟前`;
2604
+ const hours = Math.round(minutes / 60);
2605
+ if (hours < 24) return `${String(hours)} 小时前`;
2606
+ return `${String(Math.round(hours / 24))} 天前`;
2607
+ }
2608
+ function WelcomeState({ cards, resume, leading, sessionKey, cwd, composerReady, onResume }) {
2609
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "welcome", children: [
2610
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { children: "有什么可以帮忙的?" }),
2611
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
2612
+ "输入 ",
2613
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: "/" }),
2614
+ " 查看可用指令 · 消息会携带当前工作目录上下文"
2615
+ ] }),
2616
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "welcome-cards", children: cards.map((card) => /* @__PURE__ */ jsxRuntime.jsxs(
2617
+ "button",
2618
+ {
2619
+ type: "button",
2620
+ className: "welcome-card",
2621
+ disabled: !composerReady,
2622
+ onClick: card.run,
2623
+ children: [
2624
+ /* @__PURE__ */ jsxRuntime.jsx(card.Icon, { size: 16 }),
2625
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "welcome-card-text", children: [
2626
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "welcome-card-title", children: card.title }),
2627
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "welcome-card-hint", children: card.hint })
2628
+ ] })
2629
+ ]
2630
+ },
2631
+ card.id
2632
+ )) }),
2633
+ resume === null ? null : /* @__PURE__ */ jsxRuntime.jsxs("button", { type: "button", className: "welcome-resume", onClick: () => onResume(resume.id), children: [
2634
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconClock, { size: 13 }),
2635
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "welcome-resume-title", children: [
2636
+ "接着上次:",
2637
+ resume.title
2638
+ ] }),
2639
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "welcome-resume-time", children: elapsedLabel(resume.updatedAt) })
2640
+ ] }),
2641
+ leading.map((row) => {
2642
+ if (row.entry.kind !== "system") return null;
2643
+ if (row.entry.command === true) {
2644
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system-command", children: row.entry.text }, keyOf(row, sessionKey));
2645
+ }
2646
+ const notice = uiPrimitives.parseReviewNotice(row.entry.text);
2647
+ if (notice === null) return null;
2648
+ return /* @__PURE__ */ jsxRuntime.jsx(uiPrimitives.ReviewNoticeCard, { notice, cwd }, keyOf(row, sessionKey));
2649
+ })
2650
+ ] });
2651
+ }
2652
+ const SUBAGENT_FLOW_SLOT = "shell.subagent.flow";
2653
+ function SubagentFlow(props) {
2654
+ const entries = props.entries ?? uiPrimitives.NO_ENTRIES;
2655
+ const cwd = props.cwd ?? "";
2656
+ const toolRender = props.renderSlot ?? ((_name, owner) => /* @__PURE__ */ jsxRuntime.jsx(ToolRow, { entry: owner.entry, storeKey: owner.storeKey }));
2657
+ const rows = react.useMemo(() => entries.map((entry, at) => ({ entry, live: false, at })), [entries]);
2658
+ return /* @__PURE__ */ jsxRuntime.jsx(ShellSessionContext.Provider, { value: props.sessionKey ?? null, children: /* @__PURE__ */ jsxRuntime.jsx(ShellCwdContext.Provider, { value: cwd, children: /* @__PURE__ */ jsxRuntime.jsx(FoldPrefsContext.Provider, { value: FOLD_PREFS, children: /* @__PURE__ */ jsxRuntime.jsx(FlowActionsContext.Provider, { value: NO_ACTIONS, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "chat-inner subagent-flow", children: rows.map((row) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-row", children: /* @__PURE__ */ jsxRuntime.jsx(RowBoundary, { entry: row.entry, children: row.entry.kind === "user" ? /* @__PURE__ */ jsxRuntime.jsx(ReadonlyUserRow, { entry: row.entry }) : /* @__PURE__ */ jsxRuntime.jsx(RowBody, { row, renderSlot: toolRender }) }) }, `sub|${row.entry.kind}|${String(row.entry.id)}`)) }) }) }) }) });
2659
+ }
2660
+ const BUILTIN_TOOLVIEW_PRIORITY = 100;
2661
+ const ui = ui$1.defineUiPlugin({
2662
+ name: "消息流",
2663
+ apply(ui2) {
2664
+ registerToolCard(ui2);
2665
+ ui2.slots.register(
2666
+ "shell.main",
2667
+ { id: "transcript.flow", order: 1, children: { [TOOLVIEW_SLOT]: "chain" } },
2668
+ TranscriptFlow
2669
+ );
2670
+ ui2.slots.register(
2671
+ TOOLVIEW_SLOT,
2672
+ {
2673
+ id: "transcript.toolview.builtin",
2674
+ priority: BUILTIN_TOOLVIEW_PRIORITY,
2675
+ // owner 的类型来自 SlotMap 的声明(D1):entry 就是渲染方传的那条工具调用,
2676
+ // 不需要再对 unknown 做断言。
2677
+ select: (owner) => uiPrimitives.matchTool(owner.entry.call.name)
2678
+ },
2679
+ BuiltinToolView
2680
+ );
2681
+ ui2.slots.declare(SUBAGENT_FLOW_SLOT, "list");
2682
+ ui2.slots.register(
2683
+ SUBAGENT_FLOW_SLOT,
2684
+ { id: "transcript.subagent.flow", order: 1, children: { [TOOLVIEW_SLOT]: "chain" } },
2685
+ SubagentFlow
2686
+ );
2687
+ ui2.provide("transcriptFlow", { Component: SubagentFlow, slot: SUBAGENT_FLOW_SLOT });
2688
+ }
2689
+ });
2690
+ function TranscriptFlow({
2691
+ renderSlot
2692
+ }) {
2693
+ const entries = ui$1.useHostSelector(uiPrimitives.readEntries);
2694
+ const live = ui$1.useHostSelector(uiPrimitives.readLive);
2695
+ const turnState = ui$1.useHostSelector(uiPrimitives.readTurnState);
2696
+ const compactingSince = ui$1.useHostSelector(uiPrimitives.readCompactingSince);
2697
+ const sessionPath = ui$1.useHostSelector(uiPrimitives.readSessionPath);
2698
+ const sessionId = ui$1.useHostSelector(readSessionId);
2699
+ const cwd = ui$1.useHostSelector(uiPrimitives.readCwd) ?? "";
2700
+ const channel = ui$1.useHostChannel();
2701
+ const sessionKey = sessionPath ?? sessionId ?? "";
2702
+ const seats = react.useMemo(() => buildSeats(entries, live), [entries, live]);
2703
+ const follow = useFollowBottom(entries.length + live.length, sessionKey);
2704
+ const [prefs, setPrefs] = react.useState(FOLD_PREFS);
2705
+ const [behavior, setBehavior] = react.useState({
2706
+ sound: true,
2707
+ variant: 1,
2708
+ notify: true
2709
+ });
2710
+ react.useEffect(() => {
2711
+ const read = () => {
2712
+ void channel.invoke("getUiPrefs", []).then((value) => {
2713
+ setPrefs({
2714
+ policy: processFoldPolicy(readFoldValue(value["processFold"])),
2715
+ reasoningOpen: value["reasoningDefaultOpen"] === true,
2716
+ toolOpen: value["toolDefaultOpen"] === true
2717
+ });
2718
+ const variant = value["turnCompleteSoundVariant"];
2719
+ setBehavior({
2720
+ sound: value["turnCompleteSound"] !== false,
2721
+ variant: typeof variant === "number" && Number.isFinite(variant) ? variant : 1,
2722
+ notify: value["turnCompleteNotify"] !== false
2723
+ });
2724
+ }).catch(() => void 0);
2725
+ };
2726
+ read();
2727
+ window.addEventListener("shell.uiprefs", read);
2728
+ return () => window.removeEventListener("shell.uiprefs", read);
2729
+ }, [channel]);
2730
+ const prevState = react.useRef(turnState);
2731
+ const behaviorRef = react.useRef(behavior);
2732
+ behaviorRef.current = behavior;
2733
+ const sessionRef = react.useRef(sessionPath);
2734
+ react.useEffect(() => {
2735
+ const was = prevState.current;
2736
+ prevState.current = turnState;
2737
+ if (was === "idle" || turnState !== "idle") return;
2738
+ if (sessionRef.current !== sessionPath) return;
2739
+ if (behaviorRef.current.sound) uiPrimitives.playCompletionSound(behaviorRef.current.variant);
2740
+ const background = document.hidden || !document.hasFocus();
2741
+ const native = ui$1.getHostNative();
2742
+ if (background && behaviorRef.current.notify && native.available) {
2743
+ const last = [...entries].reverse().find((entry) => entry.kind === "text");
2744
+ const body = last !== void 0 && last.kind === "text" ? last.text.replace(/\s+/g, " ").trim().slice(0, 120) : "任务完成";
2745
+ void native.invoke("notify", [{ title: "任务完成", body }]).catch(() => void 0);
2746
+ }
2747
+ }, [turnState, sessionPath, entries]);
2748
+ const [earliest, setEarliest] = react.useState(null);
2749
+ const roundSizes = react.useMemo(() => seats.rounds.map((seat) => seat.rows.length), [seats.rounds]);
2750
+ const tailStart = react.useMemo(() => pageStartRound(roundSizes, roundSizes.length), [roundSizes]);
2751
+ const firstVisible = earliest === null ? tailStart : Math.min(earliest, tailStart);
2752
+ const visibleSeats = react.useMemo(
2753
+ () => seats.rounds.filter((seat) => seat.round >= firstVisible),
2754
+ [seats.rounds, firstVisible]
2755
+ );
2756
+ const earlierRounds = react.useMemo(
2757
+ () => firstVisible - pageStartRound(roundSizes, firstVisible),
2758
+ [roundSizes, firstVisible]
2759
+ );
2760
+ const cleared = seats.rounds.length === 0;
2761
+ react.useEffect(() => {
2762
+ setEarliest(null);
2763
+ }, [sessionKey, cleared]);
2764
+ const earlierRef = react.useRef(null);
2765
+ const pageAnchor = react.useRef(null);
2766
+ const beginPaging = () => {
2767
+ const button = earlierRef.current;
2768
+ if (button === null) return;
2769
+ const scroller = button.closest(".chat");
2770
+ if (!(scroller instanceof HTMLElement)) return;
2771
+ const seat = scroller.querySelector("[data-round-seat]");
2772
+ pageAnchor.current = seat === null ? null : { node: seat, top: seat.getBoundingClientRect().top - scroller.getBoundingClientRect().top, from: firstVisible };
2773
+ };
2774
+ const release = (startRound) => {
2775
+ if (startRound >= firstVisible) return;
2776
+ beginPaging();
2777
+ follow.pause();
2778
+ setEarliest(startRound);
2779
+ };
2780
+ react.useLayoutEffect(() => {
2781
+ const anchor = pageAnchor.current;
2782
+ if (anchor === null) return;
2783
+ pageAnchor.current = null;
2784
+ if (firstVisible >= anchor.from || !anchor.node.isConnected) return;
2785
+ const scroller = anchor.node.closest(".chat");
2786
+ if (!(scroller instanceof HTMLElement)) return;
2787
+ const top = anchor.node.getBoundingClientRect().top - scroller.getBoundingClientRect().top;
2788
+ scroller.scrollTop += top - anchor.top;
2789
+ }, [firstVisible]);
2790
+ const foldMemory = useFoldMemory();
2791
+ const rounds = seats.infos;
2792
+ const liveRoundIndex = rounds.length - 1;
2793
+ const roundFolds = react.useMemo(
2794
+ () => buildRoundFolds([...entries, ...live], rounds, { foldTurns: prefs.policy.foldTurns, live: turnState !== "idle", lastRoundIndex: liveRoundIndex }),
2795
+ [entries, live, rounds, prefs.policy.foldTurns, turnState, liveRoundIndex]
2796
+ );
2797
+ const stepGrouping = react.useMemo(
2798
+ () => prefs.policy.stepGrouping === "none" ? EMPTY_STEP_GROUPING : groupSteps(
2799
+ [...entries, ...live],
2800
+ rounds,
2801
+ // running 谓词直接复用 roundFold——口径单点,别处不再重判
2802
+ (roundIndex) => roundFolds.get(roundIndex)?.running ?? false,
2803
+ prefs.policy.stepGrouping === "history"
2804
+ ),
2805
+ [entries, live, rounds, roundFolds, prefs.policy.stepGrouping]
2806
+ );
2807
+ const runningRounds = react.useMemo(() => {
2808
+ const set = /* @__PURE__ */ new Set();
2809
+ for (const fold of roundFolds.values()) if (fold.running) set.add(fold.roundIndex);
2810
+ return set;
2811
+ }, [roundFolds]);
2812
+ const prevRunningRounds = react.useRef(/* @__PURE__ */ new Set());
2813
+ react.useEffect(() => {
2814
+ const settled = [];
2815
+ for (const roundIndex of prevRunningRounds.current) {
2816
+ if (runningRounds.has(roundIndex)) continue;
2817
+ settled.push(turnFoldKey(sessionId, roundIndex));
2818
+ for (const group of stepGrouping.groups) {
2819
+ if (group.roundIndex === roundIndex) settled.push(stepGroupFoldKey(sessionId, roundIndex, group.seq));
2568
2820
  }
2569
- )
2821
+ }
2822
+ foldMemory.reset(settled);
2823
+ prevRunningRounds.current = runningRounds;
2824
+ }, [runningRounds, stepGrouping, sessionId]);
2825
+ const forkRound = (seat) => {
2826
+ if (sessionPath === null) return;
2827
+ const roundNo = seat.round + 1;
2828
+ void (async () => {
2829
+ try {
2830
+ const result = await channel.invoke("forkSession", [sessionPath, roundNo]);
2831
+ if (result.ok !== true) {
2832
+ ui$1.toastErr(result.error ?? "分叉失败");
2833
+ return;
2834
+ }
2835
+ await channel.invoke("openSession", result.path === void 0 ? [] : [result.path]);
2836
+ await channel.invoke("refreshSessions", []);
2837
+ ui$1.toastOk("已从这一轮分叉出新会话");
2838
+ } catch (reason) {
2839
+ ui$1.toastErr(`分叉失败:${reason instanceof Error ? reason.message : String(reason)}`);
2840
+ }
2841
+ })();
2842
+ };
2843
+ const editAndResend = (entry, text) => {
2844
+ const all = [...entries, ...live];
2845
+ const at = all.findIndex((item) => item.id === entry.id);
2846
+ if (at < 0) {
2847
+ ui$1.toastErr("这条消息已经不在会话里了,刷新后再试");
2848
+ return;
2849
+ }
2850
+ const keep = all.slice(0, at).filter((item) => item.kind === "user" && item.internal !== true).length;
2851
+ if (sessionPath === null) {
2852
+ ui$1.toastErr("这条会话还没落盘,先发一条消息再编辑");
2853
+ return;
2854
+ }
2855
+ void (async () => {
2856
+ try {
2857
+ const result = await channel.invoke("rewindSession", [sessionPath, keep, text]);
2858
+ if (result?.ok !== true) {
2859
+ ui$1.toastErr(result?.error ?? "编辑失败");
2860
+ return;
2861
+ }
2862
+ await channel.invoke("submit", [text]);
2863
+ await channel.invoke("refreshSessions", []);
2864
+ } catch (reason) {
2865
+ ui$1.toastErr(`重发失败:${reason instanceof Error ? reason.message : String(reason)}`);
2866
+ }
2867
+ })();
2868
+ };
2869
+ const actions = { editAndResend, busy: turnState !== "idle" };
2870
+ const activity = react.useMemo(() => liveActivity([...entries, ...live], turnState), [entries, live, turnState]);
2871
+ const railRounds = react.useMemo(
2872
+ () => seats.rounds.map((seat) => {
2873
+ const user = seat.rows[0]?.entry;
2874
+ const answer = seat.rows.map((row) => row.entry).filter((entry) => entry.kind === "text" && entry.id >= 0).at(-1);
2875
+ return {
2876
+ round: seat.round,
2877
+ // 题面预览只在来源是**人**时才填(对照 dsh 的 turnOutline:非 user 来源不留题面)。
2878
+ // internal 消息(队友汇报、后台作业通知……)有刻度但不给原文,改给一句人话——
2879
+ // 绝不把 `<teammate-report …>` 或作业通知原文当题面塞进悬停卡。
2880
+ prompt: user?.kind !== "user" ? "" : user.internal === true ? internalLabel(user.text) : previewText(user.text, "prompt"),
2881
+ response: answer === void 0 ? "" : previewText(answer.text, "response")
2882
+ };
2883
+ }),
2884
+ [seats.rounds]
2570
2885
  );
2571
- }
2572
- function TurnStatusLine(props) {
2573
- const fallbackStart = react.useRef(Date.now());
2574
- const [now, setNow] = react.useState(() => Date.now());
2886
+ const revealRound = (round) => {
2887
+ release(round);
2888
+ };
2889
+ const composerDraft = ui$1.useService("composerDraft");
2890
+ const actionsHandle = ui$1.useService(ui$1.ACTIONS_SERVICE);
2575
2891
  react.useEffect(() => {
2576
- const timer = setInterval(() => setNow(Date.now()), 1e3);
2577
- return () => clearInterval(timer);
2578
- }, []);
2579
- const elapsed = uiPrimitives.formatDuration(now - (props.startedAt ?? fallbackStart.current));
2580
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "turn-status", children: [
2581
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "turn-status-row", children: [
2582
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "turn-status-spin", "aria-hidden": "true" }),
2583
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "turn-status-stage", role: "status", children: props.stage })
2584
- ] }),
2585
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "turn-status-rule", "aria-hidden": "true" }),
2586
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "turn-status-row", children: [
2587
- /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 12, className: "turn-status-icon" }),
2588
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "turn-status-activity", children: [
2589
- props.activity,
2590
- elapsed === null ? null : `,用时 ${elapsed}`
2591
- ] }),
2592
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "turn-status-dots", "aria-hidden": "true", children: [
2593
- /* @__PURE__ */ jsxRuntime.jsx("i", {}),
2594
- /* @__PURE__ */ jsxRuntime.jsx("i", {}),
2595
- /* @__PURE__ */ jsxRuntime.jsx("i", {})
2596
- ] })
2597
- ] })
2598
- ] });
2599
- }
2600
- class RowBoundary extends react.Component {
2601
- state = { error: null };
2602
- static getDerivedStateFromError(error) {
2603
- return { error };
2604
- }
2605
- componentDidUpdate(previous) {
2606
- if (this.state.error !== null && previous.entry !== this.props.entry) this.setState({ error: null });
2607
- }
2608
- render() {
2609
- if (this.state.error !== null) {
2610
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-system", children: [
2611
- "这一条没画出来:",
2612
- this.state.error.message
2613
- ] });
2892
+ if (actionsHandle === void 0) return void 0;
2893
+ return actionsHandle.register(
2894
+ "transcript",
2895
+ WELCOME_CARDS.map((card) => ({
2896
+ id: `welcome.${card.id}`,
2897
+ label: card.title,
2898
+ hint: card.hint,
2899
+ group: "提示词",
2900
+ keywords: ["提示词", "prompt"],
2901
+ run: () => {
2902
+ composerDraft?.insert(card.prompt);
2903
+ }
2904
+ }))
2905
+ );
2906
+ }, [actionsHandle, composerDraft]);
2907
+ const sessions = ui$1.useHostSelector(uiPrimitives.readSessions);
2908
+ const resume = react.useMemo(() => {
2909
+ const now = Date.now();
2910
+ return [...sessions].filter(
2911
+ (session) => session.archivedAt === void 0 && session.id !== sessionPath && (session.title ?? "") !== "" && now - session.updatedAt < 7 * 24 * 60 * 60 * 1e3
2912
+ ).sort((a, b) => b.updatedAt - a.updatedAt)[0] ?? null;
2913
+ }, [sessions, sessionPath]);
2914
+ const registeredActions = ui$1.useActions();
2915
+ const promptActions = react.useMemo(
2916
+ () => registeredActions.filter((action) => action.group === "提示词"),
2917
+ [registeredActions]
2918
+ );
2919
+ const welcomeCards = react.useMemo(() => {
2920
+ if (promptActions.length > 0) {
2921
+ return promptActions.map((action) => ({
2922
+ id: action.id,
2923
+ Icon: WELCOME_ICON_BY_ID.get(action.id) ?? ui$1.IconSpark,
2924
+ title: action.label,
2925
+ hint: action.hint ?? "",
2926
+ run: action.run
2927
+ }));
2614
2928
  }
2615
- return this.props.children;
2929
+ return WELCOME_CARDS.map((card) => ({
2930
+ id: card.id,
2931
+ Icon: card.Icon,
2932
+ title: card.title,
2933
+ hint: card.hint,
2934
+ run: () => {
2935
+ composerDraft?.insert(card.prompt);
2936
+ }
2937
+ }));
2938
+ }, [promptActions, composerDraft]);
2939
+ const bootError = react.useMemo(() => {
2940
+ const row = seats.leading.find((item) => item.entry.kind === "system" && item.entry.level === "error");
2941
+ return row !== void 0 && row.entry.kind === "system" ? row.entry : null;
2942
+ }, [seats.leading]);
2943
+ react.useEffect(() => {
2944
+ if (bootError === null) return;
2945
+ ui$1.toastErr(bootError.text.split("\n")[0] ?? "启动时有问题需要处理");
2946
+ }, [bootError?.id, sessionKey]);
2947
+ if (seats.rounds.length === 0 && seats.leading.every((row) => row.entry.kind === "system")) {
2948
+ return /* @__PURE__ */ jsxRuntime.jsx(
2949
+ WelcomeState,
2950
+ {
2951
+ cards: welcomeCards,
2952
+ resume,
2953
+ leading: seats.leading,
2954
+ sessionKey,
2955
+ cwd,
2956
+ composerReady: composerDraft !== void 0,
2957
+ onResume: (id) => {
2958
+ void (async () => {
2959
+ await channel.invoke("openSession", [id]);
2960
+ await channel.invoke("refreshSessions", []);
2961
+ })();
2962
+ }
2963
+ }
2964
+ );
2616
2965
  }
2966
+ return /* @__PURE__ */ jsxRuntime.jsx(ShellSessionContext.Provider, { value: sessionId, children: /* @__PURE__ */ jsxRuntime.jsx(ShellCwdContext.Provider, { value: cwd ?? "", children: /* @__PURE__ */ jsxRuntime.jsx(FoldPrefsContext.Provider, { value: prefs, children: /* @__PURE__ */ jsxRuntime.jsxs(FlowActionsContext.Provider, { value: actions, children: [
2967
+ /* @__PURE__ */ jsxRuntime.jsx(JumpRail, { rounds: railRounds, renderedFrom: firstVisible, onReveal: revealRound }),
2968
+ firstVisible > 0 ? /* @__PURE__ */ jsxRuntime.jsx(
2969
+ "button",
2970
+ {
2971
+ type: "button",
2972
+ className: "chat-earlier",
2973
+ ref: earlierRef,
2974
+ "data-earlier-rounds": firstVisible,
2975
+ "data-tip": "把更早的几轮画出来(一页至少 50 条且 2 轮),你现在看的位置不会动",
2976
+ onClick: () => {
2977
+ release(firstVisible - earlierRounds);
2978
+ },
2979
+ children: `加载更早的 ${String(earlierRounds)} 轮(上面还有 ${String(firstVisible)} 轮)`
2980
+ }
2981
+ ) : null,
2982
+ seats.leading.map((row) => /* @__PURE__ */ jsxRuntime.jsx(RowBoundary, { entry: row.entry, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-row", children: /* @__PURE__ */ jsxRuntime.jsx(RowBody, { row, renderSlot }) }) }, keyOf(row, sessionKey))),
2983
+ visibleSeats.map((seat) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "turn-seat", "data-round-seat": seat.round, children: /* @__PURE__ */ jsxRuntime.jsx(
2984
+ SeatBody,
2985
+ {
2986
+ seat,
2987
+ round: rounds[seat.round],
2988
+ running: turnState !== "idle" && seat.round === rounds.length - 1,
2989
+ sessionId,
2990
+ sessionKey,
2991
+ cwd,
2992
+ roundFolds,
2993
+ foldMemory,
2994
+ stepGrouping,
2995
+ renderSlot,
2996
+ onFork: sessionPath === null || seat.round === 0 ? void 0 : () => forkRound(seat)
2997
+ }
2998
+ ) }, seat.round)),
2999
+ compactingSince !== null ? /* @__PURE__ */ jsxRuntime.jsx(TurnStatusLine, { text: "正在压缩上下文" }) : null,
3000
+ activity !== null && compactingSince === null && !(activity.covered && stepGrouping.groups.length > 0) ? /* @__PURE__ */ jsxRuntime.jsx(TurnStatusLine, { text: activity.text }) : null,
3001
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: follow.setEnd }),
3002
+ follow.paused ? /* @__PURE__ */ jsxRuntime.jsx(
3003
+ "button",
3004
+ {
3005
+ type: "button",
3006
+ className: "chat-to-bottom",
3007
+ title: "回到最新一条(自动跟随会重新打开)",
3008
+ onClick: follow.resume,
3009
+ children: "回到底部"
3010
+ }
3011
+ ) : null
3012
+ ] }) }) }) });
2617
3013
  }
2618
- function keyOf(row, sessionKey) {
2619
- return `${sessionKey}|${String(row.entry.id)}`;
2620
- }
2621
- const SESSION_MARKER = /^会话 \S+ · 模型 \S+$/;
2622
- function isSessionMarker(text) {
2623
- return SESSION_MARKER.test(text.trim());
2624
- }
2625
- function buildSeats(entries, live) {
2626
- const all = [...entries, ...live];
2627
- const split = splitRounds(all);
2628
- const rowOf = (at) => ({ entry: all[at], live: at >= entries.length, at });
2629
- return {
2630
- leading: split.leading.map(rowOf),
2631
- rounds: split.seats.map((seat) => ({ round: seat.round, rows: seat.indices.map(rowOf) })),
2632
- infos: split.rounds
2633
- };
2634
- }
2635
- function readEntries(snapshot) {
2636
- const value = snapshot?.entries;
2637
- return Array.isArray(value) ? value : NO_ENTRIES;
2638
- }
2639
- function readLive(snapshot) {
2640
- const value = snapshot?.liveEntries;
2641
- return Array.isArray(value) ? value : NO_ENTRIES;
2642
- }
2643
- const SUBAGENT_FLOW_SLOT = "shell.subagent.flow";
2644
- function SubagentFlow(props) {
2645
- const entries = props.entries ?? NO_ENTRIES;
2646
- const cwd = props.cwd ?? "";
2647
- const toolRender = props.renderSlot ?? ((_name, owner) => /* @__PURE__ */ jsxRuntime.jsx(ToolRow, { entry: owner.entry, storeKey: owner.storeKey }));
2648
- const rows = react.useMemo(() => entries.map((entry, at) => ({ entry, live: false, at })), [entries]);
2649
- return /* @__PURE__ */ jsxRuntime.jsx(ShellSessionContext.Provider, { value: props.sessionKey ?? null, children: /* @__PURE__ */ jsxRuntime.jsx(ShellCwdContext.Provider, { value: cwd, children: /* @__PURE__ */ jsxRuntime.jsx(FoldPrefsContext.Provider, { value: FOLD_PREFS, children: /* @__PURE__ */ jsxRuntime.jsx(FlowActionsContext.Provider, { value: NO_ACTIONS, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "chat-inner subagent-flow", children: rows.map((row) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-row", children: /* @__PURE__ */ jsxRuntime.jsx(RowBoundary, { entry: row.entry, children: row.entry.kind === "user" ? /* @__PURE__ */ jsxRuntime.jsx(ReadonlyUserRow, { entry: row.entry }) : /* @__PURE__ */ jsxRuntime.jsx(RowBody, { row, renderSlot: toolRender }) }) }, `sub|${row.entry.kind}|${String(row.entry.id)}`)) }) }) }) }) });
3014
+ function readFoldValue(value) {
3015
+ return value === "compact" || value === "detailed" || value === "verbose" ? value : "standard";
2650
3016
  }
2651
- function ReadonlyUserRow({ entry }) {
2652
- if (entry.internal === true) return /* @__PURE__ */ jsxRuntime.jsx(UserRow, { entry });
2653
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "user-turn", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entry-user", children: [
2654
- entry.images === void 0 || entry.images.length === 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-user-images", children: entry.images.map((url, index) => /* @__PURE__ */ jsxRuntime.jsx("a", { href: url, target: "_blank", rel: "noreferrer", "data-tip": "点开看原图", children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: url, alt: `第 ${String(index + 1)} 张贴图` }) }, index)) }),
2655
- entry.text
2656
- ] }) });
3017
+ function readSessionId(snapshot) {
3018
+ const status = snapshot?.["status"];
3019
+ if (typeof status !== "object" || status === null) return null;
3020
+ const value = status["sessionId"];
3021
+ return typeof value === "string" && value !== "" ? value : null;
2657
3022
  }
2658
3023
  exports.SUBAGENT_FLOW_SLOT = SUBAGENT_FLOW_SLOT;
2659
3024
  exports.TOOLVIEW_SLOT = TOOLVIEW_SLOT;