@waq666/pneuma 0.0.0-stage → 0.7.0

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 (687) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -2
  3. package/bin/dsc.js +91 -0
  4. package/bin/headless.cjs +40 -0
  5. package/lib/adapter/core-runtime.d.ts +11 -0
  6. package/lib/adapter/core-runtime.js +259 -0
  7. package/lib/adapter/host.d.ts +18 -0
  8. package/lib/adapter/host.js +14 -0
  9. package/lib/adapter/runtime.d.ts +15 -0
  10. package/lib/adapter/runtime.js +290 -0
  11. package/lib/adapter/transcript.d.ts +184 -0
  12. package/lib/adapter/transcript.js +605 -0
  13. package/lib/app/AgentsOverlay.d.ts +18 -0
  14. package/lib/app/AgentsOverlay.js +63 -0
  15. package/lib/app/App.d.ts +13 -0
  16. package/lib/app/App.js +1498 -0
  17. package/lib/app/ApprovalCard.d.ts +12 -0
  18. package/lib/app/ApprovalCard.js +76 -0
  19. package/lib/app/AskCard.d.ts +20 -0
  20. package/lib/app/AskCard.js +45 -0
  21. package/lib/app/ChatView.d.ts +32 -0
  22. package/lib/app/ChatView.js +198 -0
  23. package/lib/app/Composer.d.ts +50 -0
  24. package/lib/app/Composer.js +282 -0
  25. package/lib/app/DiffBlock.d.ts +6 -0
  26. package/lib/app/DiffBlock.js +37 -0
  27. package/lib/app/MarkdownView.d.ts +6 -0
  28. package/lib/app/MarkdownView.js +99 -0
  29. package/lib/app/ModelPicker.d.ts +7 -0
  30. package/lib/app/ModelPicker.js +18 -0
  31. package/lib/app/PlanReviewCard.d.ts +13 -0
  32. package/lib/app/PlanReviewCard.js +54 -0
  33. package/lib/app/PresetPicker.d.ts +11 -0
  34. package/lib/app/PresetPicker.js +19 -0
  35. package/lib/app/PreviewOverlay.d.ts +14 -0
  36. package/lib/app/PreviewOverlay.js +22 -0
  37. package/lib/app/SessionPicker.d.ts +43 -0
  38. package/lib/app/SessionPicker.js +56 -0
  39. package/lib/app/SettingsOverlay.d.ts +32 -0
  40. package/lib/app/SettingsOverlay.js +157 -0
  41. package/lib/app/SkillsPicker.d.ts +7 -0
  42. package/lib/app/SkillsPicker.js +19 -0
  43. package/lib/app/StatusBar.d.ts +22 -0
  44. package/lib/app/StatusBar.js +272 -0
  45. package/lib/app/TaskStrips.d.ts +13 -0
  46. package/lib/app/TaskStrips.js +40 -0
  47. package/lib/app/ToolCard.d.ts +5 -0
  48. package/lib/app/ToolCard.js +40 -0
  49. package/lib/app/TranscriptOverlay.d.ts +12 -0
  50. package/lib/app/TranscriptOverlay.js +17 -0
  51. package/lib/app/Welcome.d.ts +6 -0
  52. package/lib/app/Welcome.js +66 -0
  53. package/lib/app/attach.d.ts +16 -0
  54. package/lib/app/attach.js +58 -0
  55. package/lib/app/click.d.ts +27 -0
  56. package/lib/app/click.js +89 -0
  57. package/lib/app/clipboard-image.d.ts +11 -0
  58. package/lib/app/clipboard-image.js +66 -0
  59. package/lib/app/cursor.d.ts +4 -0
  60. package/lib/app/cursor.js +24 -0
  61. package/lib/app/hello.d.ts +11 -0
  62. package/lib/app/hello.js +8 -0
  63. package/lib/app/history-store.d.ts +4 -0
  64. package/lib/app/history-store.js +41 -0
  65. package/lib/app/image-blocks.d.ts +12 -0
  66. package/lib/app/image-blocks.js +125 -0
  67. package/lib/app/markdown.d.ts +54 -0
  68. package/lib/app/markdown.js +189 -0
  69. package/lib/app/settings-model.d.ts +69 -0
  70. package/lib/app/settings-model.js +114 -0
  71. package/lib/app/theme.d.ts +166 -0
  72. package/lib/app/theme.js +141 -0
  73. package/lib/boot.d.ts +1 -0
  74. package/lib/boot.js +34 -0
  75. package/lib/commands.d.ts +49 -0
  76. package/lib/commands.js +115 -0
  77. package/lib/contract.d.ts +1973 -0
  78. package/lib/contract.js +36 -0
  79. package/lib/core/agent-roles.d.ts +52 -0
  80. package/lib/core/agent-roles.js +274 -0
  81. package/lib/core/approval-floor.d.ts +183 -0
  82. package/lib/core/approval-floor.js +679 -0
  83. package/lib/core/approval.d.ts +42 -0
  84. package/lib/core/approval.js +8 -0
  85. package/lib/core/audit.d.ts +61 -0
  86. package/lib/core/audit.js +59 -0
  87. package/lib/core/boot-notices.d.ts +6 -0
  88. package/lib/core/boot-notices.js +61 -0
  89. package/lib/core/cdp/actions.d.ts +182 -0
  90. package/lib/core/cdp/actions.js +649 -0
  91. package/lib/core/cdp/launch.d.ts +192 -0
  92. package/lib/core/cdp/launch.js +491 -0
  93. package/lib/core/cdp/snapshot.d.ts +139 -0
  94. package/lib/core/cdp/snapshot.js +316 -0
  95. package/lib/core/cdp/transport.d.ts +160 -0
  96. package/lib/core/cdp/transport.js +359 -0
  97. package/lib/core/command-policy.d.ts +108 -0
  98. package/lib/core/command-policy.js +580 -0
  99. package/lib/core/commands-completion.d.ts +78 -0
  100. package/lib/core/commands-completion.js +167 -0
  101. package/lib/core/compact-anchors.d.ts +76 -0
  102. package/lib/core/compact-anchors.js +284 -0
  103. package/lib/core/compact.d.ts +110 -0
  104. package/lib/core/compact.js +210 -0
  105. package/lib/core/config-store.d.ts +38 -0
  106. package/lib/core/config-store.js +307 -0
  107. package/lib/core/config.d.ts +36 -0
  108. package/lib/core/config.js +124 -0
  109. package/lib/core/connection-test.d.ts +60 -0
  110. package/lib/core/connection-test.js +84 -0
  111. package/lib/core/desktop-control.d.ts +298 -0
  112. package/lib/core/desktop-control.js +1311 -0
  113. package/lib/core/diff-text.d.ts +74 -0
  114. package/lib/core/diff-text.js +257 -0
  115. package/lib/core/dock-browser.d.ts +137 -0
  116. package/lib/core/dock-browser.js +146 -0
  117. package/lib/core/dock-ops.d.ts +59 -0
  118. package/lib/core/dock-ops.js +104 -0
  119. package/lib/core/dock-session.d.ts +39 -0
  120. package/lib/core/dock-session.js +28 -0
  121. package/lib/core/dsh-compat/hook.d.ts +18 -0
  122. package/lib/core/dsh-compat/hook.js +52 -0
  123. package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
  124. package/lib/core/dsh-compat/resolve-hook.js +59 -0
  125. package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
  126. package/lib/core/dsh-compat/tools-facade.js +108 -0
  127. package/lib/core/err-text.d.ts +13 -0
  128. package/lib/core/err-text.js +15 -0
  129. package/lib/core/events.d.ts +149 -0
  130. package/lib/core/events.js +1 -0
  131. package/lib/core/git-exec.d.ts +23 -0
  132. package/lib/core/git-exec.js +72 -0
  133. package/lib/core/git-info.d.ts +47 -0
  134. package/lib/core/git-info.js +157 -0
  135. package/lib/core/goal.d.ts +89 -0
  136. package/lib/core/goal.js +189 -0
  137. package/lib/core/hooks.d.ts +272 -0
  138. package/lib/core/hooks.js +818 -0
  139. package/lib/core/host-browser-link.d.ts +59 -0
  140. package/lib/core/host-browser-link.js +9 -0
  141. package/lib/core/host-methods.d.ts +25 -0
  142. package/lib/core/host-methods.js +103 -0
  143. package/lib/core/image-diet.d.ts +77 -0
  144. package/lib/core/image-diet.js +127 -0
  145. package/lib/core/learnings/ledger.d.ts +73 -0
  146. package/lib/core/learnings/ledger.js +273 -0
  147. package/lib/core/learnings/skill-write.d.ts +250 -0
  148. package/lib/core/learnings/skill-write.js +854 -0
  149. package/lib/core/learnings/store.d.ts +102 -0
  150. package/lib/core/learnings/store.js +266 -0
  151. package/lib/core/lifecycle-hooks.d.ts +189 -0
  152. package/lib/core/lifecycle-hooks.js +576 -0
  153. package/lib/core/llm.d.ts +272 -0
  154. package/lib/core/llm.js +548 -0
  155. package/lib/core/lockfile.d.ts +17 -0
  156. package/lib/core/lockfile.js +110 -0
  157. package/lib/core/loop.d.ts +185 -0
  158. package/lib/core/loop.js +587 -0
  159. package/lib/core/lsp/client.d.ts +189 -0
  160. package/lib/core/lsp/client.js +690 -0
  161. package/lib/core/lsp/framing.d.ts +84 -0
  162. package/lib/core/lsp/framing.js +181 -0
  163. package/lib/core/lsp/line-shift.d.ts +28 -0
  164. package/lib/core/lsp/line-shift.js +127 -0
  165. package/lib/core/lsp/manager.d.ts +93 -0
  166. package/lib/core/lsp/manager.js +418 -0
  167. package/lib/core/lsp/normalize.d.ts +32 -0
  168. package/lib/core/lsp/normalize.js +139 -0
  169. package/lib/core/lsp/servers.d.ts +106 -0
  170. package/lib/core/lsp/servers.js +352 -0
  171. package/lib/core/lsp/uri.d.ts +76 -0
  172. package/lib/core/lsp/uri.js +179 -0
  173. package/lib/core/market.d.ts +51 -0
  174. package/lib/core/market.js +358 -0
  175. package/lib/core/mcp.d.ts +201 -0
  176. package/lib/core/mcp.js +836 -0
  177. package/lib/core/memory-eval.d.ts +158 -0
  178. package/lib/core/memory-eval.js +215 -0
  179. package/lib/core/memory.d.ts +266 -0
  180. package/lib/core/memory.js +703 -0
  181. package/lib/core/mention.d.ts +57 -0
  182. package/lib/core/mention.js +129 -0
  183. package/lib/core/microcompact.d.ts +48 -0
  184. package/lib/core/microcompact.js +79 -0
  185. package/lib/core/migrate.d.ts +56 -0
  186. package/lib/core/migrate.js +134 -0
  187. package/lib/core/model-caps.d.ts +83 -0
  188. package/lib/core/model-caps.js +150 -0
  189. package/lib/core/model-discovery.d.ts +19 -0
  190. package/lib/core/model-discovery.js +69 -0
  191. package/lib/core/modes.d.ts +72 -0
  192. package/lib/core/modes.js +152 -0
  193. package/lib/core/native-bridge.d.ts +135 -0
  194. package/lib/core/native-bridge.js +563 -0
  195. package/lib/core/path-policy.d.ts +32 -0
  196. package/lib/core/path-policy.js +248 -0
  197. package/lib/core/permission-presets.d.ts +67 -0
  198. package/lib/core/permission-presets.js +75 -0
  199. package/lib/core/plugin-loader.d.ts +36 -0
  200. package/lib/core/plugin-loader.js +294 -0
  201. package/lib/core/plugin-registry.d.ts +113 -0
  202. package/lib/core/plugin-registry.js +256 -0
  203. package/lib/core/prefs.d.ts +82 -0
  204. package/lib/core/prefs.js +372 -0
  205. package/lib/core/presets.d.ts +80 -0
  206. package/lib/core/presets.js +373 -0
  207. package/lib/core/pricing.d.ts +90 -0
  208. package/lib/core/pricing.js +126 -0
  209. package/lib/core/prompt.d.ts +92 -0
  210. package/lib/core/prompt.js +339 -0
  211. package/lib/core/ptc.d.ts +66 -0
  212. package/lib/core/ptc.js +70 -0
  213. package/lib/core/remote/frames.d.ts +91 -0
  214. package/lib/core/remote/frames.js +174 -0
  215. package/lib/core/remote/notify.d.ts +54 -0
  216. package/lib/core/remote/notify.js +77 -0
  217. package/lib/core/remote/owner.d.ts +32 -0
  218. package/lib/core/remote/owner.js +75 -0
  219. package/lib/core/remote/pairing.d.ts +104 -0
  220. package/lib/core/remote/pairing.js +261 -0
  221. package/lib/core/remote/push.d.ts +80 -0
  222. package/lib/core/remote/push.js +222 -0
  223. package/lib/core/remote/store.d.ts +18 -0
  224. package/lib/core/remote/store.js +59 -0
  225. package/lib/core/remote/tickets.d.ts +20 -0
  226. package/lib/core/remote/tickets.js +49 -0
  227. package/lib/core/remote/uploads.d.ts +63 -0
  228. package/lib/core/remote/uploads.js +161 -0
  229. package/lib/core/request-attribution.d.ts +26 -0
  230. package/lib/core/request-attribution.js +86 -0
  231. package/lib/core/request-invariant.d.ts +61 -0
  232. package/lib/core/request-invariant.js +199 -0
  233. package/lib/core/sandbox/backends.d.ts +64 -0
  234. package/lib/core/sandbox/backends.js +194 -0
  235. package/lib/core/sandbox/execpolicy.d.ts +93 -0
  236. package/lib/core/sandbox/execpolicy.js +452 -0
  237. package/lib/core/sandbox/net-proxy.d.ts +31 -0
  238. package/lib/core/sandbox/net-proxy.js +162 -0
  239. package/lib/core/sandbox/policy.d.ts +211 -0
  240. package/lib/core/sandbox/policy.js +559 -0
  241. package/lib/core/sandbox/win/abi.d.ts +161 -0
  242. package/lib/core/sandbox/win/abi.js +169 -0
  243. package/lib/core/sandbox/win/account.d.ts +71 -0
  244. package/lib/core/sandbox/win/account.js +206 -0
  245. package/lib/core/sandbox/win/acl.d.ts +54 -0
  246. package/lib/core/sandbox/win/acl.js +339 -0
  247. package/lib/core/sandbox/win/backend.d.ts +61 -0
  248. package/lib/core/sandbox/win/backend.js +249 -0
  249. package/lib/core/sandbox/win/doctor.d.ts +24 -0
  250. package/lib/core/sandbox/win/doctor.js +272 -0
  251. package/lib/core/sandbox/win/ffi.d.ts +107 -0
  252. package/lib/core/sandbox/win/ffi.js +166 -0
  253. package/lib/core/sandbox/win/net-abi.d.ts +154 -0
  254. package/lib/core/sandbox/win/net-abi.js +316 -0
  255. package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
  256. package/lib/core/sandbox/win/runner-entry.js +391 -0
  257. package/lib/core/sandbox/win/setup.d.ts +60 -0
  258. package/lib/core/sandbox/win/setup.js +986 -0
  259. package/lib/core/sandbox/win/token.d.ts +35 -0
  260. package/lib/core/sandbox/win/token.js +238 -0
  261. package/lib/core/sandbox/win/wfp.d.ts +41 -0
  262. package/lib/core/sandbox/win/wfp.js +200 -0
  263. package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
  264. package/lib/core/sandbox/win/workspace-sid.js +45 -0
  265. package/lib/core/schedule/rule.d.ts +184 -0
  266. package/lib/core/schedule/rule.js +745 -0
  267. package/lib/core/schedule/runner.d.ts +185 -0
  268. package/lib/core/schedule/runner.js +678 -0
  269. package/lib/core/schedule/store.d.ts +182 -0
  270. package/lib/core/schedule/store.js +455 -0
  271. package/lib/core/secrets.d.ts +41 -0
  272. package/lib/core/secrets.js +150 -0
  273. package/lib/core/session-export.d.ts +18 -0
  274. package/lib/core/session-export.js +73 -0
  275. package/lib/core/session-index.d.ts +159 -0
  276. package/lib/core/session-index.js +683 -0
  277. package/lib/core/session-meta.d.ts +41 -0
  278. package/lib/core/session-meta.js +97 -0
  279. package/lib/core/session.d.ts +356 -0
  280. package/lib/core/session.js +998 -0
  281. package/lib/core/skills.d.ts +60 -0
  282. package/lib/core/skills.js +171 -0
  283. package/lib/core/spill.d.ts +159 -0
  284. package/lib/core/spill.js +329 -0
  285. package/lib/core/surface-registry.d.ts +45 -0
  286. package/lib/core/surface-registry.js +67 -0
  287. package/lib/core/team-board.d.ts +95 -0
  288. package/lib/core/team-board.js +316 -0
  289. package/lib/core/throughput.d.ts +46 -0
  290. package/lib/core/throughput.js +40 -0
  291. package/lib/core/todo-reminder.d.ts +44 -0
  292. package/lib/core/todo-reminder.js +55 -0
  293. package/lib/core/todo.d.ts +81 -0
  294. package/lib/core/todo.js +222 -0
  295. package/lib/core/token-estimate.d.ts +55 -0
  296. package/lib/core/token-estimate.js +82 -0
  297. package/lib/core/tool-guards.d.ts +103 -0
  298. package/lib/core/tool-guards.js +77 -0
  299. package/lib/core/tool-search.d.ts +152 -0
  300. package/lib/core/tool-search.js +311 -0
  301. package/lib/core/tools/bash.d.ts +281 -0
  302. package/lib/core/tools/bash.js +871 -0
  303. package/lib/core/tools/command-runner.d.ts +84 -0
  304. package/lib/core/tools/command-runner.js +68 -0
  305. package/lib/core/tools/fs-tools.d.ts +23 -0
  306. package/lib/core/tools/fs-tools.js +247 -0
  307. package/lib/core/tools/index.d.ts +8 -0
  308. package/lib/core/tools/index.js +4 -0
  309. package/lib/core/tools/sandbox-args.d.ts +51 -0
  310. package/lib/core/tools/sandbox-args.js +90 -0
  311. package/lib/core/tools/search-tools.d.ts +3 -0
  312. package/lib/core/tools/search-tools.js +153 -0
  313. package/lib/core/tools.d.ts +96 -0
  314. package/lib/core/tools.js +53 -0
  315. package/lib/core/ui-boot-source.d.ts +71 -0
  316. package/lib/core/ui-boot-source.js +121 -0
  317. package/lib/core/ui-bundles.d.ts +249 -0
  318. package/lib/core/ui-bundles.js +830 -0
  319. package/lib/core/ui-combo.d.ts +49 -0
  320. package/lib/core/ui-combo.js +55 -0
  321. package/lib/core/ui-events.d.ts +81 -0
  322. package/lib/core/ui-events.js +364 -0
  323. package/lib/core/ui-hmr.d.ts +36 -0
  324. package/lib/core/ui-hmr.js +128 -0
  325. package/lib/core/ui-methods.d.ts +69 -0
  326. package/lib/core/ui-methods.js +341 -0
  327. package/lib/core/ui-route.d.ts +69 -0
  328. package/lib/core/ui-route.js +122 -0
  329. package/lib/core/ui-server.d.ts +75 -0
  330. package/lib/core/ui-server.js +369 -0
  331. package/lib/core/ui-trust.d.ts +47 -0
  332. package/lib/core/ui-trust.js +164 -0
  333. package/lib/core/untrusted.d.ts +30 -0
  334. package/lib/core/untrusted.js +48 -0
  335. package/lib/core/update-check.d.ts +81 -0
  336. package/lib/core/update-check.js +177 -0
  337. package/lib/core/usage-log.d.ts +82 -0
  338. package/lib/core/usage-log.js +306 -0
  339. package/lib/core/version.d.ts +1 -0
  340. package/lib/core/version.js +37 -0
  341. package/lib/core/web-http.d.ts +57 -0
  342. package/lib/core/web-http.js +137 -0
  343. package/lib/core/web-static.d.ts +31 -0
  344. package/lib/core/web-static.js +75 -0
  345. package/lib/headless.d.ts +1 -0
  346. package/lib/headless.js +31 -0
  347. package/lib/host/kernel.d.ts +33 -0
  348. package/lib/host/kernel.js +451 -0
  349. package/lib/index.d.ts +41 -0
  350. package/lib/index.js +35 -0
  351. package/lib/plugins/agent.d.ts +2 -0
  352. package/lib/plugins/agent.js +274 -0
  353. package/lib/plugins/approval-floor.d.ts +2 -0
  354. package/lib/plugins/approval-floor.js +223 -0
  355. package/lib/plugins/approval.d.ts +16 -0
  356. package/lib/plugins/approval.js +674 -0
  357. package/lib/plugins/ask.d.ts +2 -0
  358. package/lib/plugins/ask.js +245 -0
  359. package/lib/plugins/browser.d.ts +68 -0
  360. package/lib/plugins/browser.js +1341 -0
  361. package/lib/plugins/commands.d.ts +23 -0
  362. package/lib/plugins/commands.js +498 -0
  363. package/lib/plugins/compact.d.ts +21 -0
  364. package/lib/plugins/compact.js +274 -0
  365. package/lib/plugins/computer-use.d.ts +47 -0
  366. package/lib/plugins/computer-use.js +539 -0
  367. package/lib/plugins/desktop-dock.d.ts +2 -0
  368. package/lib/plugins/desktop-dock.js +626 -0
  369. package/lib/plugins/dock-browser.d.ts +34 -0
  370. package/lib/plugins/dock-browser.js +765 -0
  371. package/lib/plugins/dsh-compat.d.ts +25 -0
  372. package/lib/plugins/dsh-compat.js +37 -0
  373. package/lib/plugins/file-review.d.ts +108 -0
  374. package/lib/plugins/file-review.js +393 -0
  375. package/lib/plugins/git.d.ts +26 -0
  376. package/lib/plugins/git.js +132 -0
  377. package/lib/plugins/goal.d.ts +20 -0
  378. package/lib/plugins/goal.js +245 -0
  379. package/lib/plugins/guards.d.ts +14 -0
  380. package/lib/plugins/guards.js +18 -0
  381. package/lib/plugins/hooks.d.ts +19 -0
  382. package/lib/plugins/hooks.js +583 -0
  383. package/lib/plugins/host-stdio.d.ts +88 -0
  384. package/lib/plugins/host-stdio.js +317 -0
  385. package/lib/plugins/image-diet.d.ts +17 -0
  386. package/lib/plugins/image-diet.js +85 -0
  387. package/lib/plugins/lifecycle-hooks.d.ts +26 -0
  388. package/lib/plugins/lifecycle-hooks.js +338 -0
  389. package/lib/plugins/llm.d.ts +13 -0
  390. package/lib/plugins/llm.js +215 -0
  391. package/lib/plugins/lsp.d.ts +54 -0
  392. package/lib/plugins/lsp.js +608 -0
  393. package/lib/plugins/mcp.d.ts +16 -0
  394. package/lib/plugins/mcp.js +673 -0
  395. package/lib/plugins/memory.d.ts +17 -0
  396. package/lib/plugins/memory.js +858 -0
  397. package/lib/plugins/microcompact.d.ts +18 -0
  398. package/lib/plugins/microcompact.js +119 -0
  399. package/lib/plugins/mode.d.ts +18 -0
  400. package/lib/plugins/mode.js +115 -0
  401. package/lib/plugins/permission-presets.d.ts +18 -0
  402. package/lib/plugins/permission-presets.js +135 -0
  403. package/lib/plugins/plan.d.ts +2 -0
  404. package/lib/plugins/plan.js +192 -0
  405. package/lib/plugins/plugin-manager.d.ts +2 -0
  406. package/lib/plugins/plugin-manager.js +165 -0
  407. package/lib/plugins/presets.d.ts +2 -0
  408. package/lib/plugins/presets.js +182 -0
  409. package/lib/plugins/prompt.d.ts +2 -0
  410. package/lib/plugins/prompt.js +264 -0
  411. package/lib/plugins/ptc.d.ts +2 -0
  412. package/lib/plugins/ptc.js +272 -0
  413. package/lib/plugins/remote/http.d.ts +11 -0
  414. package/lib/plugins/remote/http.js +11 -0
  415. package/lib/plugins/remote/routes.d.ts +24 -0
  416. package/lib/plugins/remote/routes.js +384 -0
  417. package/lib/plugins/remote/types.d.ts +135 -0
  418. package/lib/plugins/remote/types.js +87 -0
  419. package/lib/plugins/remote.d.ts +17 -0
  420. package/lib/plugins/remote.js +1028 -0
  421. package/lib/plugins/runtime-api.d.ts +16 -0
  422. package/lib/plugins/runtime-api.js +99 -0
  423. package/lib/plugins/runtime.d.ts +10 -0
  424. package/lib/plugins/runtime.js +451 -0
  425. package/lib/plugins/sandbox.d.ts +2 -0
  426. package/lib/plugins/sandbox.js +761 -0
  427. package/lib/plugins/schedule.d.ts +26 -0
  428. package/lib/plugins/schedule.js +538 -0
  429. package/lib/plugins/self-improve.d.ts +61 -0
  430. package/lib/plugins/self-improve.js +953 -0
  431. package/lib/plugins/session-search.d.ts +16 -0
  432. package/lib/plugins/session-search.js +308 -0
  433. package/lib/plugins/session-title.d.ts +19 -0
  434. package/lib/plugins/session-title.js +109 -0
  435. package/lib/plugins/session.d.ts +7 -0
  436. package/lib/plugins/session.js +296 -0
  437. package/lib/plugins/settings.d.ts +3 -0
  438. package/lib/plugins/settings.js +705 -0
  439. package/lib/plugins/skills.d.ts +2 -0
  440. package/lib/plugins/skills.js +360 -0
  441. package/lib/plugins/spill.d.ts +16 -0
  442. package/lib/plugins/spill.js +200 -0
  443. package/lib/plugins/subagent.d.ts +2 -0
  444. package/lib/plugins/subagent.js +862 -0
  445. package/lib/plugins/surfaces.d.ts +11 -0
  446. package/lib/plugins/surfaces.js +20 -0
  447. package/lib/plugins/team.d.ts +16 -0
  448. package/lib/plugins/team.js +149 -0
  449. package/lib/plugins/todo.d.ts +19 -0
  450. package/lib/plugins/todo.js +188 -0
  451. package/lib/plugins/tool-search.d.ts +2 -0
  452. package/lib/plugins/tool-search.js +425 -0
  453. package/lib/plugins/tools-default.d.ts +12 -0
  454. package/lib/plugins/tools-default.js +275 -0
  455. package/lib/plugins/tools.d.ts +16 -0
  456. package/lib/plugins/tools.js +62 -0
  457. package/lib/plugins/transcript.d.ts +15 -0
  458. package/lib/plugins/transcript.js +311 -0
  459. package/lib/plugins/tui.d.ts +2 -0
  460. package/lib/plugins/tui.js +98 -0
  461. package/lib/plugins/waiting.d.ts +12 -0
  462. package/lib/plugins/waiting.js +34 -0
  463. package/lib/plugins/web-search.d.ts +14 -0
  464. package/lib/plugins/web-search.js +263 -0
  465. package/lib/plugins/webserver.d.ts +48 -0
  466. package/lib/plugins/webserver.js +228 -0
  467. package/lib/remote/assets/app-DAcUCOEn.js +14 -0
  468. package/lib/remote/assets/icon-192.png +0 -0
  469. package/lib/remote/assets/icon-512.png +0 -0
  470. package/lib/remote/assets/index.html +34 -0
  471. package/lib/remote/assets/manifest.json +27 -0
  472. package/lib/remote/assets/style-DIB6729x.css +1 -0
  473. package/lib/remote/assets/sw.js +66 -0
  474. package/lib/services/types.d.ts +1228 -0
  475. package/lib/services/types.js +1 -0
  476. package/lib/tools/config-cli.d.ts +1 -0
  477. package/lib/tools/config-cli.js +89 -0
  478. package/lib/ui/arrival.d.ts +72 -0
  479. package/lib/ui/arrival.js +105 -0
  480. package/lib/ui/assets/app-B70nVIKd.js +69 -0
  481. package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
  482. package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
  483. package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
  484. package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
  485. package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
  486. package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
  487. package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
  488. package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
  489. package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
  490. package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
  491. package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
  492. package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
  493. package/lib/ui/assets/chunk-BajyYBss.js +10 -0
  494. package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
  495. package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
  496. package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
  497. package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
  498. package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
  499. package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
  500. package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
  501. package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
  502. package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
  503. package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
  504. package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
  505. package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
  506. package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
  507. package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
  508. package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
  509. package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
  510. package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
  511. package/lib/ui/assets/chunk-CickPsom.js +1 -0
  512. package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
  513. package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
  514. package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
  515. package/lib/ui/assets/chunk-CqE71os6.js +1 -0
  516. package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
  517. package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
  518. package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
  519. package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
  520. package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
  521. package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
  522. package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
  523. package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
  524. package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
  525. package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
  526. package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
  527. package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
  528. package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
  529. package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
  530. package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
  531. package/lib/ui/assets/chunk-De0Btta0.js +1 -0
  532. package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
  533. package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
  534. package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
  535. package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
  536. package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
  537. package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
  538. package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
  539. package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
  540. package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
  541. package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
  542. package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
  543. package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
  544. package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
  545. package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
  546. package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
  547. package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
  548. package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
  549. package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
  550. package/lib/ui/assets/icon.png +0 -0
  551. package/lib/ui/assets/index.html +14 -0
  552. package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
  553. package/lib/ui/assets/style-Bq01xH_b.css +1 -0
  554. package/lib/ui/frames.d.ts +67 -0
  555. package/lib/ui/frames.js +146 -0
  556. package/lib/ui/index.d.ts +59 -0
  557. package/lib/ui/index.js +50 -0
  558. package/lib/ui/manifest.d.ts +172 -0
  559. package/lib/ui/manifest.js +158 -0
  560. package/lib/ui/plugin.d.ts +161 -0
  561. package/lib/ui/plugin.js +7 -0
  562. package/lib/ui/plugins/browser/client.js +290 -0
  563. package/lib/ui/plugins/browser/icon.png +0 -0
  564. package/lib/ui/plugins/composer/client.js +1843 -0
  565. package/lib/ui/plugins/composer/icon.png +0 -0
  566. package/lib/ui/plugins/files/client.js +646 -0
  567. package/lib/ui/plugins/files/icon.png +0 -0
  568. package/lib/ui/plugins/manifest.json +107 -0
  569. package/lib/ui/plugins/plugins/client.js +682 -0
  570. package/lib/ui/plugins/plugins/icon.png +0 -0
  571. package/lib/ui/plugins/preview/client.js +197 -0
  572. package/lib/ui/plugins/preview/icon.png +0 -0
  573. package/lib/ui/plugins/prompt/client.js +653 -0
  574. package/lib/ui/plugins/prompt/icon.png +0 -0
  575. package/lib/ui/plugins/sessions/client.js +1577 -0
  576. package/lib/ui/plugins/sessions/icon.png +0 -0
  577. package/lib/ui/plugins/settings/client.js +5470 -0
  578. package/lib/ui/plugins/settings/icon.png +0 -0
  579. package/lib/ui/plugins/skills/client.js +485 -0
  580. package/lib/ui/plugins/skills/icon.png +0 -0
  581. package/lib/ui/plugins/status/client.js +1420 -0
  582. package/lib/ui/plugins/status/icon.png +0 -0
  583. package/lib/ui/plugins/statusbar/client.js +504 -0
  584. package/lib/ui/plugins/statusbar/icon.png +0 -0
  585. package/lib/ui/plugins/tasks/client.js +52 -0
  586. package/lib/ui/plugins/tasks/icon.png +0 -0
  587. package/lib/ui/plugins/team/client.js +527 -0
  588. package/lib/ui/plugins/team/icon.png +0 -0
  589. package/lib/ui/plugins/terminal/client.js +232 -0
  590. package/lib/ui/plugins/terminal/icon.png +0 -0
  591. package/lib/ui/plugins/trace/client.js +1376 -0
  592. package/lib/ui/plugins/trace/icon.png +0 -0
  593. package/lib/ui/plugins/transcript/client.js +2661 -0
  594. package/lib/ui/plugins/transcript/icon.png +0 -0
  595. package/lib/ui/scoped-slots.d.ts +20 -0
  596. package/lib/ui/scoped-slots.js +21 -0
  597. package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
  598. package/lib/ui/sdk/@dsc/ui/package.json +16 -0
  599. package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
  600. package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
  601. package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
  602. package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
  603. package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
  604. package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
  605. package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
  606. package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
  607. package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
  608. package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
  609. package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
  610. package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
  611. package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
  612. package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
  613. package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
  614. package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
  615. package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
  616. package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
  617. package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
  618. package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
  619. package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
  620. package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
  621. package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
  622. package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
  623. package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
  624. package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
  625. package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
  626. package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
  627. package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
  628. package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
  629. package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
  630. package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
  631. package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
  632. package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
  633. package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
  634. package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
  635. package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
  636. package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
  637. package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
  638. package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
  639. package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
  640. package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
  641. package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
  642. package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
  643. package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
  644. package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
  645. package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
  646. package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
  647. package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
  648. package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
  649. package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
  650. package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
  651. package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
  652. package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
  653. package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
  654. package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
  655. package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
  656. package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
  657. package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
  658. package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
  659. package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
  660. package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
  661. package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
  662. package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
  663. package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
  664. package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
  665. package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
  666. package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
  667. package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
  668. package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
  669. package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
  670. package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
  671. package/lib/ui/services-react.d.ts +27 -0
  672. package/lib/ui/services-react.js +32 -0
  673. package/lib/ui/services.d.ts +63 -0
  674. package/lib/ui/services.js +121 -0
  675. package/lib/ui/slots-ink.d.ts +26 -0
  676. package/lib/ui/slots-ink.js +78 -0
  677. package/lib/ui/slots-react.d.ts +28 -0
  678. package/lib/ui/slots-react.js +88 -0
  679. package/lib/ui/slots.d.ts +481 -0
  680. package/lib/ui/slots.js +550 -0
  681. package/lib/ui/store.d.ts +89 -0
  682. package/lib/ui/store.js +62 -0
  683. package/lib/ui/tui-plugin-api.d.ts +23 -0
  684. package/lib/ui/tui-plugin-api.js +23 -0
  685. package/lib/ui/tui-plugins.d.ts +47 -0
  686. package/lib/ui/tui-plugins.js +220 -0
  687. package/package.json +58 -6
@@ -0,0 +1,2661 @@
1
+ (globalThis.__DSC_UI_FACTORIES__ ??= {})["transcript"] = function (require, module, exports) {
2
+ "use strict";
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
4
+ const jsxRuntime = require("react/jsx-runtime");
5
+ const react = require("react");
6
+ const reactDom = require("react-dom");
7
+ const ui$1 = require("@dsc/ui");
8
+ const uiPrimitives = require("@dsc/ui-primitives");
9
+ function tsOf(entry) {
10
+ if (entry === void 0) return null;
11
+ const ts = entry.ts;
12
+ return typeof ts === "number" && Number.isFinite(ts) && ts > 0 ? ts : null;
13
+ }
14
+ function splitRounds(entries) {
15
+ const rounds = [];
16
+ entries.forEach((entry, index) => {
17
+ if (entry.kind === "user") {
18
+ const current2 = rounds[rounds.length - 1];
19
+ if (entry.steering === true && current2 !== void 0) {
20
+ current2.endIndex = index;
21
+ const steeringTs = tsOf(entry);
22
+ if (steeringTs !== null) current2.endTs = steeringTs;
23
+ return;
24
+ }
25
+ rounds.push({
26
+ index: rounds.length,
27
+ startIndex: index,
28
+ endIndex: index,
29
+ startTs: tsOf(entry),
30
+ endTs: null,
31
+ answered: false
32
+ });
33
+ return;
34
+ }
35
+ const current = rounds[rounds.length - 1];
36
+ if (current === void 0 || entry.kind === "system") return;
37
+ current.endIndex = index;
38
+ current.answered = true;
39
+ const ts = tsOf(entry);
40
+ if (ts !== null) current.endTs = ts;
41
+ });
42
+ for (const round of rounds) {
43
+ if (round.endTs !== null && round.startTs !== null && round.endTs < round.startTs) round.endTs = null;
44
+ }
45
+ const seats = rounds.map((round, i) => {
46
+ const next = rounds[i + 1];
47
+ const stop = next === void 0 ? entries.length - 1 : next.startIndex - 1;
48
+ const indices = [];
49
+ for (let at = round.startIndex; at <= stop; at += 1) indices.push(at);
50
+ return { round: round.index, indices };
51
+ });
52
+ const firstStart = rounds[0]?.startIndex ?? entries.length;
53
+ const leading = [];
54
+ for (let at = 0; at < firstStart; at += 1) leading.push(at);
55
+ return { rounds, seats, leading };
56
+ }
57
+ const TEAMMATE_REPORT_OPEN = "<teammate-report ";
58
+ function teammateReport(text) {
59
+ if (!text.startsWith(TEAMMATE_REPORT_OPEN)) return null;
60
+ const close = text.indexOf(">");
61
+ const head = close === -1 ? text : text.slice(0, close);
62
+ const from = /\bfrom="([^"]*)"/.exec(head)?.[1] ?? null;
63
+ const state = /\bstate="([^"]*)"/.exec(head)?.[1] ?? null;
64
+ return { from, state };
65
+ }
66
+ function teammateReportLabel(text) {
67
+ const report = teammateReport(text);
68
+ if (report === null) return "子任务汇报";
69
+ const who = report.from === null || report.from === "" ? "队友" : `队友 ${report.from}`;
70
+ const verb = report.state === "已失败" ? "失败了" : report.state === "已停止" ? "停了下来" : "汇报了运行结果";
71
+ return `${who} ${verb}`;
72
+ }
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);
82
+ }
83
+ return null;
84
+ }
85
+ function liveActivity(entries, turnState) {
86
+ if (turnState === "idle") return null;
87
+ if (turnState === "awaiting-approval") {
88
+ return { stage: "等待你的确认", activity: "有一条工具调用等你批准" };
89
+ }
90
+ const tail = entries[entries.length - 1];
91
+ if (tail !== void 0 && tail.id < 0 && tail.kind === "thinking") {
92
+ return { stage: "正在分析请求", activity: "正在思考" };
93
+ }
94
+ if (tail !== void 0 && tail.id < 0 && tail.kind === "text") {
95
+ return { stage: "正在整理回复", activity: "正在输出回复" };
96
+ }
97
+ const running = [...entries].reverse().find(
98
+ (entry) => entry.kind === "tool" && (entry.call.status === "running" || entry.call.status === "preparing")
99
+ );
100
+ if (running !== void 0) {
101
+ return {
102
+ stage: "正在执行工具",
103
+ // 「准备中」是模型还在吐参数、「正在调用」是工具真的开跑了——两句话不同
104
+ activity: running.call.status === "preparing" ? `正在准备 ${running.call.name}` : `正在调用 ${running.call.name}`
105
+ };
106
+ }
107
+ if (turnState === "working") return { stage: "正在执行工具", activity: "正在执行工具" };
108
+ return { stage: "正在分析请求", activity: "正在思考" };
109
+ }
110
+ const folds = /* @__PURE__ */ new Map();
111
+ function readFold(key, fallback) {
112
+ if (key === void 0) return fallback;
113
+ return folds.get(key) ?? fallback;
114
+ }
115
+ function writeFold(key, open) {
116
+ if (key === void 0) return;
117
+ folds.set(key, open);
118
+ }
119
+ function turnFoldKey(sessionId, roundIndex) {
120
+ return `${sessionId ?? ""}:turn:${String(roundIndex)}`;
121
+ }
122
+ function stepGroupFoldKey(sessionId, roundIndex, groupSeq) {
123
+ return `${sessionId ?? ""}:step:${String(roundIndex)}:${String(groupSeq)}`;
124
+ }
125
+ const PROCESS_FOLD_POLICIES = {
126
+ compact: { foldTurns: true, stepGrouping: "collapsed", liveDetail: false, reasoningPreview: false },
127
+ standard: { foldTurns: true, stepGrouping: "collapsed", liveDetail: true, reasoningPreview: true },
128
+ detailed: { foldTurns: true, stepGrouping: "history", liveDetail: true, reasoningPreview: true },
129
+ verbose: { foldTurns: false, stepGrouping: "none", liveDetail: false, reasoningPreview: true }
130
+ };
131
+ function processFoldPolicy(fold) {
132
+ return PROCESS_FOLD_POLICIES[fold ?? "standard"];
133
+ }
134
+ function buildRoundFolds(entries, rounds, options) {
135
+ const out = /* @__PURE__ */ new Map();
136
+ for (const round of rounds) {
137
+ let answerIndex = -1;
138
+ for (let at = round.endIndex; at > round.startIndex; at -= 1) {
139
+ const entry = entries[at];
140
+ if (entry !== void 0 && entry.kind === "text" && entry.id >= 0) {
141
+ answerIndex = at;
142
+ break;
143
+ }
144
+ }
145
+ let startIndex = -1;
146
+ let endIndex = -1;
147
+ let hasLiveEntry = false;
148
+ let hasSteering = false;
149
+ let endReason;
150
+ for (let at = round.startIndex + 1; at <= round.endIndex; at += 1) {
151
+ const entry = entries[at];
152
+ if (entry === void 0) continue;
153
+ if (entry.id < 0) hasLiveEntry = true;
154
+ if (entry.kind === "user" && entry.steering === true) hasSteering = true;
155
+ if (entry.kind === "turn-end") endReason = entry.reason;
156
+ if (entry.kind !== "thinking" && entry.kind !== "tool" && entry.kind !== "text") continue;
157
+ if (answerIndex >= 0 && at >= answerIndex) continue;
158
+ if (startIndex < 0) startIndex = at;
159
+ endIndex = at;
160
+ }
161
+ const hasContent = startIndex >= 0;
162
+ out.set(round.index, {
163
+ roundIndex: round.index,
164
+ startIndex,
165
+ endIndex,
166
+ hasContent,
167
+ foldable: options.foldTurns,
168
+ // 跑动中的两种形态都算「这一轮还没收尾」:出现了直播条目(id<0),或者这就是最后一轮
169
+ // 而回合还没结束,或者用户刚发完消息、助手一个字都还没回(answered 为假)。
170
+ running: hasLiveEntry || options.live && round.index === options.lastRoundIndex || !round.answered,
171
+ blocked: hasSteering || endReason === "aborted" || endReason === "error",
172
+ endReason
173
+ });
174
+ }
175
+ return out;
176
+ }
177
+ function TurnFoldRow(props) {
178
+ const used = uiPrimitives.formatDuration(roundDuration(props.round));
179
+ const label = props.endReason === "aborted" ? "已停止" : props.endReason === "error" ? "过程失败" : used === null ? "已完成" : `用时 ${used}`;
180
+ const toggle = (event) => {
181
+ if (event.key !== "Enter" && event.key !== " ") return;
182
+ event.preventDefault();
183
+ props.onToggle();
184
+ };
185
+ return /* @__PURE__ */ jsxRuntime.jsxs(
186
+ "button",
187
+ {
188
+ type: "button",
189
+ className: "turn-fold",
190
+ "data-open": props.open ? "1" : void 0,
191
+ "data-round-index": props.round.index,
192
+ "data-turn-blocked": props.disabled ? "1" : void 0,
193
+ disabled: props.disabled,
194
+ "aria-expanded": props.disabled ? void 0 : props.open,
195
+ "data-tip": props.disabled ? props.endReason === "aborted" ? "这一轮被中断,过程保持展开" : props.endReason === "error" ? "这一轮跑挂了,过程保持展开" : "这一轮没有可折叠的过程内容" : props.open ? "收起这一轮的过程(思考与工具调用)" : "展开这一轮的过程(思考与工具调用)",
196
+ onClick: props.onToggle,
197
+ onKeyDown: toggle,
198
+ children: [
199
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "turn-fold-label", children: label }),
200
+ props.disabled ? null : /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 11, className: "turn-fold-chevron" })
201
+ ]
202
+ }
203
+ );
204
+ }
205
+ function useFoldMemory() {
206
+ const [map, setMap] = react.useState({});
207
+ const open = react.useCallback(
208
+ (key, fallback) => map[key] ?? readFold(key, fallback),
209
+ [map]
210
+ );
211
+ const set = react.useCallback((key, next) => {
212
+ writeFold(key, next);
213
+ setMap((current) => ({ ...current, [key]: next }));
214
+ }, []);
215
+ const reset = react.useCallback((keys) => {
216
+ if (keys.length === 0) return;
217
+ for (const key of keys) writeFold(key, false);
218
+ setMap((current) => {
219
+ let next = current;
220
+ for (const key of keys) {
221
+ if (next[key] === void 0) continue;
222
+ if (next === current) next = { ...current };
223
+ delete next[key];
224
+ }
225
+ return next;
226
+ });
227
+ }, []);
228
+ return react.useMemo(() => ({ open, set, reset }), [open, set, reset]);
229
+ }
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
+ function seatPlan(ats, grouping) {
328
+ const items = [];
329
+ for (const at of ats) {
330
+ const head = grouping.headAt.get(at);
331
+ if (head !== void 0) {
332
+ const members = [];
333
+ for (let index = head.startIndex; index <= head.endIndex; index += 1) members.push(index);
334
+ items.push({ kind: "group", group: head, members });
335
+ continue;
336
+ }
337
+ if (grouping.at.has(at)) continue;
338
+ items.push({ kind: "row", at });
339
+ }
340
+ return items;
341
+ }
342
+ function activityOf(name) {
343
+ const tool = name.toLowerCase();
344
+ if (tool === "read") return "read";
345
+ if (tool === "read_image") return "readImage";
346
+ if (tool === "grep" || tool === "glob" || tool === "search" || tool === "session_search" || tool.endsWith("_inspect")) return "search";
347
+ if (tool === "write") return "write";
348
+ if (tool === "edit" || tool === "apply_patch") return "edit";
349
+ if (tool === "bash" || tool === "pwsh" || tool === "exec_command" || tool === "write_stdin" || tool.startsWith("terminal_")) return "commands";
350
+ if (tool === "run_code") return "code";
351
+ if (tool === "web_search") return "webSearch";
352
+ if (tool === "web_fetch") return "webFetch";
353
+ if (tool === "browser") return "browser";
354
+ if (tool === "subagent" || tool.startsWith("subagent_")) return "subagents";
355
+ if (tool === "todo_write" || tool === "create_goal" || tool === "update_goal" || tool === "get_goal" || tool === "exit_plan_mode") return "plan";
356
+ if (tool === "ask_user" || tool === "ask_user_question" || tool === "request_user_input") return "questions";
357
+ return "tools";
358
+ }
359
+ const DONE_LABEL = {
360
+ read: "已读取文件",
361
+ readImage: "已读取图片",
362
+ search: "已搜索代码",
363
+ write: "已写入文件",
364
+ edit: "修改了文件",
365
+ commands: "执行了命令",
366
+ code: "运行了代码",
367
+ webSearch: "已搜索网页",
368
+ webFetch: "已访问网页",
369
+ browser: "已浏览网页",
370
+ subagents: "已协调子智能体",
371
+ plan: "更新了计划",
372
+ questions: "向用户提出了问题",
373
+ tools: "已调用工具"
374
+ };
375
+ function liveTitleOf(group) {
376
+ return {
377
+ activity: group.running ?? "thinking",
378
+ detail: group.runningDetail ?? "",
379
+ preparing: group.preparing === true
380
+ };
381
+ }
382
+ function sameLiveTitle(left, right) {
383
+ return left.activity === right.activity && left.detail === right.detail && left.preparing === right.preparing;
384
+ }
385
+ const PROCESS_TITLE_MINIMUM_MS = 150;
386
+ function liveTitleDecision(shown, desired, heldMs) {
387
+ if (sameLiveTitle(shown, desired)) return { keep: true, waitMs: 0 };
388
+ const remaining = PROCESS_TITLE_MINIMUM_MS - heldMs;
389
+ if (remaining <= 0) return { keep: false, waitMs: 0 };
390
+ return { keep: true, waitMs: remaining };
391
+ }
392
+ const RUNNING_LABEL = {
393
+ read: "正在读取文件",
394
+ readImage: "正在读取图片",
395
+ search: "正在搜索代码",
396
+ write: "正在写入文件",
397
+ edit: "正在编辑文件",
398
+ commands: "正在运行命令",
399
+ code: "正在运行代码",
400
+ webSearch: "正在搜索网页",
401
+ webFetch: "正在访问网页",
402
+ browser: "正在浏览网页",
403
+ subagents: "正在协调子智能体",
404
+ plan: "正在更新计划",
405
+ questions: "等待你的操作",
406
+ tools: "正在调用工具"
407
+ };
408
+ const DONE_THINKING = "已完成分析";
409
+ const RUNNING_THINKING = "正在分析请求";
410
+ const PREPARE_LABEL = {
411
+ read: "准备读取文件",
412
+ readImage: "准备读取图片",
413
+ search: "准备搜索代码",
414
+ write: "准备写入文件",
415
+ edit: "准备编辑文件",
416
+ commands: "准备运行命令",
417
+ code: "准备运行代码",
418
+ webSearch: "准备搜索网页",
419
+ webFetch: "准备访问网页",
420
+ browser: "准备浏览网页",
421
+ subagents: "准备协调子智能体",
422
+ plan: "准备更新计划",
423
+ questions: "准备提问",
424
+ tools: "准备调用工具"
425
+ };
426
+ const COMMA = ",";
427
+ const JOIN_TWO = "并";
428
+ const SHARED_PREFIX = "已";
429
+ const MORE = "等";
430
+ const TITLE_MAX_KINDS = 3;
431
+ function stepGroupTitle(counts, closed, running, preparing) {
432
+ if (!closed) {
433
+ if (running === void 0) return RUNNING_THINKING;
434
+ return preparing === true ? PREPARE_LABEL[running] : RUNNING_LABEL[running];
435
+ }
436
+ const labels = counts.slice(0, TITLE_MAX_KINDS).map((item) => DONE_LABEL[item.kind]);
437
+ const first = labels[0];
438
+ if (first === void 0) return DONE_THINKING;
439
+ const second = labels[1];
440
+ if (second === void 0) return first;
441
+ if (labels.length === 2) {
442
+ const shared = first.startsWith(SHARED_PREFIX) && second.startsWith(SHARED_PREFIX);
443
+ const tail = shared ? second.slice(SHARED_PREFIX.length) : second;
444
+ return `${first}${JOIN_TWO}${tail}`;
445
+ }
446
+ const title = labels.join(COMMA);
447
+ return counts.length > TITLE_MAX_KINDS ? `${title}${MORE}` : title;
448
+ }
449
+ function countActivities(entries, indexes) {
450
+ const counts = /* @__PURE__ */ new Map();
451
+ for (const index of indexes) {
452
+ const entry = entries[index];
453
+ if (entry === void 0 || entry.kind !== "tool") continue;
454
+ const kind = activityOf(entry.call.name);
455
+ counts.set(kind, (counts.get(kind) ?? 0) + 1);
456
+ }
457
+ return [...counts].map(([kind, count]) => ({ kind, count })).sort((left, right) => right.count - left.count);
458
+ }
459
+ function groupSteps(entries, rounds, isRunning, settledOnly = false) {
460
+ const groups = [];
461
+ for (const round of rounds) {
462
+ if (settledOnly && isRunning(round.index)) continue;
463
+ let pending = [];
464
+ let seq = 0;
465
+ const flush = (closed) => {
466
+ const first = pending[0];
467
+ const last = pending[pending.length - 1];
468
+ if (first === void 0 || last === void 0) return;
469
+ const group = {
470
+ roundIndex: round.index,
471
+ seq,
472
+ startIndex: first,
473
+ endIndex: last,
474
+ size: pending.length,
475
+ counts: countActivities(entries, pending),
476
+ closed
477
+ };
478
+ groups.push(group);
479
+ seq += 1;
480
+ pending = [];
481
+ };
482
+ for (let at2 = round.startIndex + 1; at2 <= round.endIndex; at2 += 1) {
483
+ const entry = entries[at2];
484
+ if (entry === void 0) continue;
485
+ if (entry.kind === "thinking" || entry.kind === "tool") {
486
+ pending.push(at2);
487
+ continue;
488
+ }
489
+ if (entry.kind === "text" || entry.kind === "plan" || entry.kind === "user" || entry.kind === "turn-end" || entry.kind === "turn-max-tokens" || entry.kind === "model-retry") {
490
+ flush(true);
491
+ continue;
492
+ }
493
+ }
494
+ if (isRunning(round.index)) pending = [];
495
+ else flush(true);
496
+ }
497
+ const headAt = /* @__PURE__ */ new Map();
498
+ const at = /* @__PURE__ */ new Map();
499
+ for (const group of groups) {
500
+ headAt.set(group.startIndex, group);
501
+ for (let index = group.startIndex; index <= group.endIndex; index += 1) at.set(index, group);
502
+ }
503
+ return { groups, headAt, at };
504
+ }
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;
551
+ }
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
+ );
600
+ }
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
+ }), []);
610
+ }
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;
774
+ }
775
+ const PREVIEW_LIMITS = { prompt: 50, response: 120 };
776
+ function previewText(text, kind) {
777
+ return flatten(text, PREVIEW_LIMITS[kind]);
778
+ }
779
+ function JumpRail(props) {
780
+ const wrapRef = react.useRef(null);
781
+ const scrollerRef = react.useRef(null);
782
+ const scrollRef = react.useRef(null);
783
+ const [host, setHost] = react.useState(null);
784
+ const [current, setCurrent] = react.useState(-1);
785
+ const [wide, setWide] = react.useState(true);
786
+ const [edges, setEdges] = react.useState({ up: false, down: false });
787
+ const [preview, setPreview] = react.useState(null);
788
+ const [previewCenter, setPreviewCenter] = react.useState(0);
789
+ const [busy, setBusy] = react.useState(null);
790
+ const pointerInside = react.useRef(false);
791
+ react.useEffect(() => {
792
+ const wrap = wrapRef.current?.closest(".chat-wrap");
793
+ if (!(wrap instanceof HTMLElement)) return;
794
+ const scroller = wrap.querySelector(".chat");
795
+ setHost(wrap);
796
+ scrollerRef.current = scroller instanceof HTMLElement ? scroller : null;
797
+ }, []);
798
+ react.useEffect(() => {
799
+ const scroller = scrollerRef.current;
800
+ if (host === null || scroller === null) return void 0;
801
+ let raf = 0;
802
+ const measure = () => {
803
+ 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));
811
+ };
812
+ const schedule = () => {
813
+ if (raf === 0) raf = requestAnimationFrame(measure);
814
+ };
815
+ schedule();
816
+ scroller.addEventListener("scroll", schedule, { passive: true });
817
+ const observer = new ResizeObserver(schedule);
818
+ observer.observe(scroller);
819
+ const inner = scroller.firstElementChild;
820
+ if (inner !== null) observer.observe(inner);
821
+ return () => {
822
+ scroller.removeEventListener("scroll", schedule);
823
+ observer.disconnect();
824
+ if (raf !== 0) cancelAnimationFrame(raf);
825
+ };
826
+ }, [host, props.rounds.length, props.renderedFrom]);
827
+ react.useEffect(() => {
828
+ if (host === null) return void 0;
829
+ const measure = () => setWide(host.clientWidth >= RAIL_MIN_WIDTH);
830
+ measure();
831
+ const observer = new ResizeObserver(measure);
832
+ observer.observe(host);
833
+ return () => observer.disconnect();
834
+ }, [host]);
835
+ const syncEdges = react.useCallback(() => {
836
+ const scroll = scrollRef.current;
837
+ if (scroll === null) return;
838
+ const limit = scroll.scrollHeight - scroll.clientHeight;
839
+ const up = scroll.scrollTop > 1;
840
+ const down = limit > 0 && scroll.scrollTop < limit - 1;
841
+ setEdges((prev) => prev.up === up && prev.down === down ? prev : { up, down });
842
+ }, []);
843
+ react.useEffect(syncEdges, [syncEdges, props.rounds.length]);
844
+ react.useEffect(() => {
845
+ if (preview === null) return;
846
+ const scroll = scrollRef.current;
847
+ const tick = scroll?.querySelector(`[data-turn="${String(preview)}"]`);
848
+ if (scroll === null || tick === null || tick === void 0) return;
849
+ setPreviewCenter(tick.offsetTop + TICK_STEP / 2 - scroll.scrollTop);
850
+ }, [preview]);
851
+ react.useEffect(() => {
852
+ if (current < 0 || pointerInside.current) return;
853
+ const scroll = scrollRef.current;
854
+ const tick = scroll?.querySelector(`[data-turn="${String(current)}"]`);
855
+ if (scroll === null || tick === null || tick === void 0) return;
856
+ const height = scroll.clientHeight;
857
+ const limit = scroll.scrollHeight - height;
858
+ if (limit <= 0) return;
859
+ const center = tick.offsetTop + TICK_STEP / 2;
860
+ if (center >= scroll.scrollTop + FADE_PX && center <= scroll.scrollTop + height - FADE_PX) return;
861
+ const target = Math.max(0, Math.min(limit, center - height / 2));
862
+ scroll.scrollTo({ top: target, behavior: "smooth" });
863
+ }, [current]);
864
+ const jump = react.useCallback(
865
+ (round) => {
866
+ const scroller = scrollerRef.current;
867
+ if (scroller === null) return;
868
+ const find = () => scroller.querySelector(`[data-round="${String(round)}"] .entry-user`) ?? scroller.querySelector(`[data-round="${String(round)}"]`);
869
+ void (async () => {
870
+ let node = find();
871
+ if (node === null && round < props.renderedFrom) {
872
+ setBusy(round);
873
+ props.onReveal(round);
874
+ for (let i = 0; i < REVEAL_TRIES && node === null; i += 1) {
875
+ await new Promise((resolve) => requestAnimationFrame(resolve));
876
+ node = find();
877
+ }
878
+ setBusy(null);
879
+ }
880
+ node?.scrollIntoView({ behavior: "smooth", block: "start" });
881
+ })();
882
+ },
883
+ [props]
884
+ );
885
+ const previewRound = preview === null ? void 0 : props.rounds.find((item) => item.round === preview);
886
+ const visible = host !== null && wide && props.rounds.length >= 2;
887
+ const rail = /* @__PURE__ */ jsxRuntime.jsxs(
888
+ "div",
889
+ {
890
+ className: "jump-rail",
891
+ role: "navigation",
892
+ "aria-label": "回合刻度条",
893
+ hidden: !visible,
894
+ onPointerEnter: () => {
895
+ pointerInside.current = true;
896
+ },
897
+ onPointerLeave: () => {
898
+ pointerInside.current = false;
899
+ setPreview(null);
900
+ },
901
+ children: [
902
+ /* @__PURE__ */ jsxRuntime.jsx(
903
+ "div",
904
+ {
905
+ ref: scrollRef,
906
+ className: "jump-rail-scroll",
907
+ "data-fade-up": edges.up ? "" : void 0,
908
+ "data-fade-down": edges.down ? "" : void 0,
909
+ onScroll: syncEdges,
910
+ children: props.rounds.map((item) => {
911
+ const active = item.round === current;
912
+ const unloaded = item.round < props.renderedFrom;
913
+ return /* @__PURE__ */ jsxRuntime.jsx(
914
+ "button",
915
+ {
916
+ type: "button",
917
+ className: `jump-tick${active ? " on" : ""}${unloaded ? " is-unloaded" : ""}${busy === item.round ? " is-busy" : ""}`,
918
+ "data-turn": item.round,
919
+ "aria-label": `第 ${String(item.round + 1)} 轮${unloaded ? "(还没画出来,点了先放出来)" : ""}:${item.prompt}`,
920
+ "aria-current": active ? "true" : void 0,
921
+ "aria-busy": busy === item.round ? "true" : void 0,
922
+ onPointerEnter: () => setPreview(item.round),
923
+ onFocus: () => {
924
+ setPreview(item.round);
925
+ },
926
+ onBlur: () => setPreview(null),
927
+ onClick: () => {
928
+ jump(item.round);
929
+ }
930
+ },
931
+ item.round
932
+ );
933
+ })
934
+ }
935
+ ),
936
+ previewRound === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsxs(
937
+ "div",
938
+ {
939
+ className: "jump-preview",
940
+ role: "tooltip",
941
+ style: { "--jump-preview-center": `${String(previewCenter)}px` },
942
+ children: [
943
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "jump-preview-prompt", children: previewRound.prompt === "" ? `第 ${String(previewRound.round + 1)} 轮` : previewRound.prompt }),
944
+ previewRound.response === "" ? null : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "jump-preview-response", children: previewRound.response })
945
+ ]
946
+ }
947
+ )
948
+ ]
949
+ }
950
+ );
951
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
952
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: wrapRef, hidden: true }),
953
+ host === null ? null : reactDom.createPortal(rail, host)
954
+ ] });
955
+ }
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
+ const PAGE_MIN_ENTRIES = 50;
1031
+ const PAGE_MIN_ROUNDS = 2;
1032
+ const PAGE_MAX_ENTRIES = 500;
1033
+ function pageStartRound(roundSizes, beforeRound) {
1034
+ let start = beforeRound;
1035
+ let entries = 0;
1036
+ let rounds = 0;
1037
+ for (let index = beforeRound - 1; index >= 0; index -= 1) {
1038
+ const size = roundSizes[index] ?? 0;
1039
+ if (entries > 0 && entries + size > PAGE_MAX_ENTRIES) break;
1040
+ start = index;
1041
+ entries += size;
1042
+ rounds += 1;
1043
+ if (entries >= PAGE_MAX_ENTRIES) break;
1044
+ if (entries >= PAGE_MIN_ENTRIES && rounds >= PAGE_MIN_ROUNDS) break;
1045
+ }
1046
+ return start;
1047
+ }
1048
+ const TOOLCARD_FACTORY = "transcript.tool-card";
1049
+ const TOOLCARD_FOOTER_SLOT = "transcript.toolcard.footer";
1050
+ const BAR_MIN_CONTENT_H$1 = 400;
1051
+ function expandedContentHeight$1(body) {
1052
+ let total = 0;
1053
+ for (const child of Array.from(body.children)) {
1054
+ if (!(child instanceof HTMLElement)) continue;
1055
+ if (child.dataset.tcChrome !== void 0) continue;
1056
+ total += Math.max(child.scrollHeight, child.offsetHeight);
1057
+ }
1058
+ return total;
1059
+ }
1060
+ function registerToolCard(ui2) {
1061
+ ui2.slots.registerFactory(
1062
+ {
1063
+ name: TOOLCARD_FACTORY,
1064
+ children: { [TOOLCARD_FOOTER_SLOT]: "list" },
1065
+ slots: { preview: {}, statusDetail: {}, bodyExtra: {}, trailing: {} }
1066
+ },
1067
+ ToolCard
1068
+ );
1069
+ }
1070
+ function ToolCard(props) {
1071
+ const { entry, storeKey, persistKey, match: electedMatch, foldPrefs, cwd = "" } = props;
1072
+ const variant = props.variant ?? "chat";
1073
+ const call = entry.call;
1074
+ const [open, setOpen] = react.useState(() => readFold(persistKey, foldPrefs?.toolOpen ?? false));
1075
+ const [barVisible, setBarVisible] = react.useState(false);
1076
+ const expandable = call.status !== "preparing";
1077
+ const bodyOpen = open && expandable;
1078
+ const running = call.status === "running";
1079
+ const summary = uiPrimitives.toolSummary(call.name, call.argsText);
1080
+ const match = electedMatch ?? uiPrimitives.matchTool(call.name);
1081
+ const Icon = match.Icon;
1082
+ const targetPath = fileTargetOf(call.name, call.argsText, cwd);
1083
+ const intended = useIntendedDiff(call, cwd, variant === "chat");
1084
+ const bodyRef = react.useRef(null);
1085
+ const barRef = react.useRef(null);
1086
+ const Preview = props.useFactorySlot("preview", SummaryPreview);
1087
+ const StatusDetail = props.useFactorySlot("statusDetail", ChatStatus);
1088
+ const BodyExtra = props.useFactorySlot("bodyExtra", IntendedBody);
1089
+ const Trailing = props.useFactorySlot("trailing", NoTrailing);
1090
+ const patch = intended?.file ?? call.change ?? null;
1091
+ const argView = uiPrimitives.toolArgFields(call.name, call.argsText);
1092
+ const paramsAsFields = patch !== null && argView.mutating;
1093
+ const setOpenPersisted = (next) => {
1094
+ writeFold(persistKey, next);
1095
+ setOpen(next);
1096
+ };
1097
+ const toggle = () => {
1098
+ if (expandable) setOpenPersisted(!open);
1099
+ };
1100
+ react.useEffect(() => {
1101
+ const body = bodyRef.current;
1102
+ if (body === null || !bodyOpen || variant !== "chat") {
1103
+ setBarVisible(false);
1104
+ return void 0;
1105
+ }
1106
+ const measure = () => {
1107
+ setBarVisible(expandedContentHeight$1(body) > BAR_MIN_CONTENT_H$1);
1108
+ };
1109
+ measure();
1110
+ const observer = new ResizeObserver(measure);
1111
+ observer.observe(body);
1112
+ return () => {
1113
+ observer.disconnect();
1114
+ };
1115
+ }, [bodyOpen, variant, call.argsText, call.resultText, call.status]);
1116
+ react.useEffect(() => {
1117
+ if (!bodyOpen || !barVisible || variant !== "chat") return void 0;
1118
+ const bar = barRef.current;
1119
+ const body = bodyRef.current;
1120
+ if (bar === null || body === null) return void 0;
1121
+ const chat = body.closest(".chat");
1122
+ if (!(chat instanceof HTMLElement)) return void 0;
1123
+ const padTop = Number.parseFloat(getComputedStyle(chat).paddingTop);
1124
+ const threshold = (Number.isFinite(padTop) ? padTop : 12) + 1.5;
1125
+ const sync = () => {
1126
+ const gap = bar.getBoundingClientRect().top - chat.getBoundingClientRect().top;
1127
+ bar.classList.toggle("stuck", gap <= threshold);
1128
+ };
1129
+ sync();
1130
+ chat.addEventListener("scroll", sync, { passive: true });
1131
+ return () => {
1132
+ chat.removeEventListener("scroll", sync);
1133
+ };
1134
+ }, [bodyOpen, barVisible, variant, call.argsText, call.resultText, call.status]);
1135
+ const duration = uiPrimitives.formatDuration(call.durationMs ?? null);
1136
+ const barStatus = running || duration === null ? uiPrimitives.TOOL_STATUS_TEXT[call.status] ?? call.status : `${uiPrimitives.TOOL_STATUS_TEXT[call.status] ?? call.status} · 用时 ${duration}`;
1137
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `entry tool-card status-${call.status}${bodyOpen ? " open" : ""}`, children: [
1138
+ /* @__PURE__ */ jsxRuntime.jsxs(
1139
+ "div",
1140
+ {
1141
+ className: "tool-head",
1142
+ role: "button",
1143
+ tabIndex: expandable ? 0 : -1,
1144
+ ...expandable ? { "aria-expanded": bodyOpen } : {},
1145
+ "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
+ 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 }),
1158
+ /* @__PURE__ */ jsxRuntime.jsx(StatusDetail, { call }),
1159
+ /* @__PURE__ */ jsxRuntime.jsx(Trailing, { entry }),
1160
+ expandable ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 11, className: "tc-chevron" }) : null
1161
+ ]
1162
+ }
1163
+ ),
1164
+ bodyOpen ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tool-body", ref: bodyRef, children: [
1165
+ barVisible && variant === "chat" ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-bar", "data-tc-chrome": "1", ref: barRef, children: [
1166
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-bar-status", children: barStatus }),
1167
+ running ? null : /* @__PURE__ */ jsxRuntime.jsxs(
1168
+ "button",
1169
+ {
1170
+ type: "button",
1171
+ className: "tc-collapse",
1172
+ title: "收起这张工具卡",
1173
+ onClick: () => {
1174
+ setOpenPersisted(false);
1175
+ },
1176
+ children: [
1177
+ "收起",
1178
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronUp, { size: 11 })
1179
+ ]
1180
+ }
1181
+ )
1182
+ ] }) : null,
1183
+ /* @__PURE__ */ jsxRuntime.jsx(BodyExtra, { intended, change: call.change ?? null }),
1184
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "label", children: "参数" }),
1185
+ paramsAsFields ? (
1186
+ /* 会改文件的工具:正文已经在上面那块 diff 里,这里只列剩下的字段。
1187
+ dsh 对 write / edit 干脆一个参数字段都不印,壳多留一栏是因为
1188
+ dsc 的 write / edit 还带 justification / sandbox_permissions 这类
1189
+ 「这次为什么这么写」的元信息,扔掉可惜;形状仍是一行一字段,不是 JSON。 */
1190
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "args arg-fields", "data-tc-argfields": "", children: argView.fields.map((field) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "arg-field", children: [
1191
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "arg-key", children: field.key }),
1192
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "arg-value", children: field.value })
1193
+ ] }, field.key)) })
1194
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "args", children: uiPrimitives.prettyJson(call.argsText) }),
1195
+ call.resultText === void 0 || call.resultText === "" ? null : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1196
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "label", children: "结果" }),
1197
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "result", children: call.resultText })
1198
+ ] }),
1199
+ props.renderSlot(TOOLCARD_FOOTER_SLOT, { entry })
1200
+ ] }) : null
1201
+ ] });
1202
+ }
1203
+ function SummaryPreview(props) {
1204
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "preview", children: props.summary });
1205
+ }
1206
+ function ChatStatus(props) {
1207
+ const call = props.call;
1208
+ const duration = uiPrimitives.formatDuration(call.durationMs ?? null);
1209
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "status", children: [
1210
+ call.status === "running" ? /* @__PURE__ */ jsxRuntime.jsx("i", { className: "tc-spin", "aria-hidden": "true" }) : null,
1211
+ call.status === "done" ? "" : uiPrimitives.TOOL_STATUS_TEXT[call.status] ?? call.status,
1212
+ duration === null || call.status === "done" ? "" : ` · 用时 ${duration}`
1213
+ ] });
1214
+ }
1215
+ function NoTrailing() {
1216
+ return null;
1217
+ }
1218
+ function fileTargetOf(name, argsText, cwd) {
1219
+ if (name !== "read" && name !== "write" && name !== "edit") return null;
1220
+ try {
1221
+ const args = JSON.parse(argsText);
1222
+ const raw = [args.file_path, args.path].find(
1223
+ (value) => typeof value === "string" && value !== ""
1224
+ );
1225
+ if (raw === void 0) return null;
1226
+ if (raw.startsWith("/") || /^[A-Za-z]:[\\/]/.test(raw)) return raw;
1227
+ if (cwd === "") return raw;
1228
+ const sep = cwd.includes("\\") && !cwd.includes("/") ? "\\" : "/";
1229
+ return `${cwd.replace(/[\\/]+$/, "")}${sep}${raw.replace(/^[\\/]+/, "")}`;
1230
+ } catch {
1231
+ return null;
1232
+ }
1233
+ }
1234
+ function OpenPathButton({
1235
+ absPath,
1236
+ cwd,
1237
+ patch = null
1238
+ }) {
1239
+ const opensPatch = patch !== null;
1240
+ return /* @__PURE__ */ jsxRuntime.jsx(
1241
+ "button",
1242
+ {
1243
+ type: "button",
1244
+ className: "tc-path tc-path-btn",
1245
+ "data-tc-open": absPath,
1246
+ "data-tc-source": opensPatch ? "patch" : "file",
1247
+ title: opensPatch ? `${absPath}(在右侧边栏看这次改动)` : `${absPath}(在右侧边栏预览)`,
1248
+ onClick: (event) => {
1249
+ event.stopPropagation();
1250
+ ui$1.setDockPreview(opensPatch ? { path: absPath, cwd, patch } : { path: absPath, cwd });
1251
+ },
1252
+ onKeyDown: (event) => {
1253
+ event.stopPropagation();
1254
+ },
1255
+ children: uiPrimitives.displayPathOf(absPath, cwd)
1256
+ }
1257
+ );
1258
+ }
1259
+ function IntendedPreview(props) {
1260
+ const { intended, summary, cwd, targetPath, change } = props;
1261
+ const patch = intended?.file ?? change ?? null;
1262
+ const absPath = intended?.absPath ?? change?.path ?? targetPath;
1263
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "preview", children: absPath !== null ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1264
+ /* @__PURE__ */ jsxRuntime.jsx(OpenPathButton, { absPath, cwd, patch }),
1265
+ patch !== null && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-counts", children: [
1266
+ patch.status === "added" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "diff-badge", children: "新增" }),
1267
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-added", children: `+${String(patch.added)}` }),
1268
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-removed", children: `-${String(patch.removed)}` })
1269
+ ] }),
1270
+ intended?.mismatch === "missing" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 不在当前文件里" }),
1271
+ intended?.mismatch === "ambiguous" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 匹配多处" })
1272
+ ] }) : summary });
1273
+ }
1274
+ function IntendedBody(props) {
1275
+ const intended = props.intended;
1276
+ const change = props.change;
1277
+ if (intended !== null) {
1278
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-intended", children: [
1279
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-intended-head", children: [
1280
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-intended-title", children: "将做的改动" }),
1281
+ intended.fellBack && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "读不到文件当前内容,以下按参数推算" }),
1282
+ intended.mismatch === "missing" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 在文件中不存在,执行会失败" }),
1283
+ intended.mismatch === "ambiguous" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 匹配多处,执行会失败" })
1284
+ ] }),
1285
+ intended.file === null ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tc-intended-note", children: "两段内容一致,不会有实际改动。" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tc-intended-diff", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.DiffRows, { hunks: intended.file.hunks, path: intended.absPath }) })
1286
+ ] });
1287
+ }
1288
+ if (change === null) return null;
1289
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-intended", "data-tc-change": "", children: [
1290
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-intended-head", children: [
1291
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-intended-title", children: "这次改动" }),
1292
+ change.truncated === true && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "改动较大,这里只显示了前一部分" })
1293
+ ] }),
1294
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tc-intended-diff", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.DiffRows, { hunks: change.hunks, path: change.path }) })
1295
+ ] });
1296
+ }
1297
+ function TraceJumpButton(props) {
1298
+ return /* @__PURE__ */ jsxRuntime.jsx(
1299
+ "button",
1300
+ {
1301
+ type: "button",
1302
+ className: "tc-trace",
1303
+ "data-trace-jump": String(props.entry.id),
1304
+ "data-tip": "在轨迹页查看这条调用的时刻与耗时",
1305
+ "aria-label": "在轨迹中查看",
1306
+ onClick: (event) => {
1307
+ event.stopPropagation();
1308
+ ui$1.openTrace(props.entry.id);
1309
+ },
1310
+ onKeyDown: (event) => {
1311
+ event.stopPropagation();
1312
+ },
1313
+ children: "在轨迹中查看"
1314
+ }
1315
+ );
1316
+ }
1317
+ const FOLD_PREFS = { policy: processFoldPolicy("standard"), reasoningOpen: false, toolOpen: false };
1318
+ const FoldPrefsContext = react.createContext(FOLD_PREFS);
1319
+ const NO_ACTIONS = { editRefork: () => void 0, busy: false };
1320
+ const FlowActionsContext = react.createContext(NO_ACTIONS);
1321
+ const ShellCwdContext = react.createContext("");
1322
+ const ShellSessionContext = react.createContext(null);
1323
+ const NO_ENTRIES = Object.freeze([]);
1324
+ 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
+ const TURN_INDEPENDENT = /* @__PURE__ */ new Set(["user", "plan", "system", "turn-end", "turn-max-tokens"]);
1356
+ const EMPTY_STEP_GROUPING = { groups: [], headAt: /* @__PURE__ */ new Map(), at: /* @__PURE__ */ new Map() };
1357
+ function useFollowBottom(dep, sessionKey) {
1358
+ const [end, setEnd] = react.useState(null);
1359
+ const pinned = react.useRef(true);
1360
+ const [paused, setPaused] = react.useState(false);
1361
+ const pinnedFor = react.useRef("");
1362
+ react.useEffect(() => {
1363
+ const scroller = end?.closest(".chat");
1364
+ if (!(scroller instanceof HTMLElement)) return void 0;
1365
+ const onScroll = () => {
1366
+ const atBottom = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight < 160;
1367
+ pinned.current = atBottom;
1368
+ setPaused(!atBottom);
1369
+ };
1370
+ onScroll();
1371
+ scroller.addEventListener("scroll", onScroll, { passive: true });
1372
+ return () => {
1373
+ scroller.removeEventListener("scroll", onScroll);
1374
+ };
1375
+ }, [end]);
1376
+ react.useEffect(() => {
1377
+ const scroller = end?.closest(".chat");
1378
+ if (!(scroller instanceof HTMLElement)) return;
1379
+ if (pinnedFor.current !== sessionKey) {
1380
+ pinnedFor.current = sessionKey;
1381
+ pinned.current = true;
1382
+ setPaused(false);
1383
+ }
1384
+ if (!pinned.current) return;
1385
+ scroller.scrollTop = scroller.scrollHeight;
1386
+ }, [sessionKey, end, dep]);
1387
+ const resume = () => {
1388
+ pinned.current = true;
1389
+ setPaused(false);
1390
+ const scroller = end?.closest(".chat");
1391
+ if (scroller instanceof HTMLElement) scroller.scrollTop = scroller.scrollHeight;
1392
+ };
1393
+ const pause = () => {
1394
+ pinned.current = false;
1395
+ setPaused(true);
1396
+ };
1397
+ return { setEnd, paused, resume, pause };
1398
+ }
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
+ });
1418
+ 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);
1433
+ };
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);
1454
+ }
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]
1463
+ );
1464
+ const earlierRounds = react.useMemo(
1465
+ () => firstVisible - pageStartRound(roundSizes, firstVisible),
1466
+ [roundSizes, firstVisible]
1467
+ );
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
+ };
1488
+ 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
+ }
1529
+ }
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)}`);
1548
+ }
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)}`);
1571
+ }
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]
1591
+ );
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",
1615
+ {
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)} 轮)`
1625
+ }
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,
1630
+ {
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
1802
+ }
1803
+ )
1804
+ ] });
1805
+ }
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
+ }
1868
+ }
1869
+ }
1870
+ function UserRow({ entry }) {
1871
+ const actions = react.useContext(FlowActionsContext);
1872
+ const [draft, setDraft] = react.useState(null);
1873
+ if (entry.internal === true) {
1874
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entry-system", "data-internal": "1", title: entry.text, children: teammateReportLabel(entry.text) });
1875
+ }
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",
1882
+ {
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);
1890
+ },
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: [
1908
+ /* @__PURE__ */ jsxRuntime.jsx(
1909
+ "button",
1910
+ {
1911
+ type: "button",
1912
+ className: "dsc-btn",
1913
+ "data-variant": "ghost",
1914
+ "data-size": "xs",
1915
+ onClick: () => {
1916
+ setDraft(null);
1917
+ },
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: () => {
1930
+ const text = draft.trim();
1931
+ if (text === "") return;
1932
+ setDraft(null);
1933
+ actions.editRefork(entry, text);
1934
+ },
1935
+ children: "重发"
1936
+ }
1937
+ )
1938
+ ] })
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);
1951
+ },
1952
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconEdit, { size: 15 })
1953
+ }
1954
+ ) }) : null
1955
+ ] });
1956
+ }
1957
+ function firstLine(text) {
1958
+ const newline = text.indexOf("\n");
1959
+ return newline === -1 ? text : text.slice(0, newline);
1960
+ }
1961
+ function latestCompletedParagraphFirstLine(text) {
1962
+ let summary = "";
1963
+ let paragraphStart = 0;
1964
+ const separator = /\r?\n(?:[\t ]*\r?\n)+/g;
1965
+ while (true) {
1966
+ const nextParagraph = separator.exec(text);
1967
+ const paragraphEnd = nextParagraph === null ? text.length : nextParagraph.index + nextParagraph[0].indexOf("\n");
1968
+ const newline = text.indexOf("\n", paragraphStart);
1969
+ if (newline !== -1 && newline <= paragraphEnd) {
1970
+ const candidate = text.slice(paragraphStart, newline).trim();
1971
+ if (candidate !== "") summary = candidate;
1972
+ }
1973
+ if (nextParagraph === null) return summary;
1974
+ paragraphStart = nextParagraph.index + nextParagraph[0].length;
1975
+ }
1976
+ }
1977
+ function ThinkRow({
1978
+ entry,
1979
+ live,
1980
+ storeKey
1981
+ }) {
1982
+ const prefs = react.useContext(FoldPrefsContext);
1983
+ const [open, setOpen] = react.useState(() => readFold(storeKey, prefs.reasoningOpen));
1984
+ const [barVisible, setBarVisible] = react.useState(false);
1985
+ const bodyRef = react.useRef(null);
1986
+ const setOpenPersisted = (next) => {
1987
+ writeFold(storeKey, next);
1988
+ setOpen(next);
1989
+ };
1990
+ const toggle = () => {
1991
+ setOpenPersisted(!open);
1992
+ };
1993
+ const summary = (live ? latestCompletedParagraphFirstLine(entry.text) : firstLine(entry.text)).replaceAll("**", "");
1994
+ const preview = summary !== "" && (live || prefs.policy.reasoningPreview);
1995
+ react.useEffect(() => {
1996
+ const body = bodyRef.current;
1997
+ if (body === null || !open) {
1998
+ setBarVisible(false);
1999
+ return void 0;
2000
+ }
2001
+ const measure = () => {
2002
+ setBarVisible(expandedContentHeight(body) > BAR_MIN_CONTENT_H);
2003
+ };
2004
+ measure();
2005
+ const observer = new ResizeObserver(measure);
2006
+ observer.observe(body);
2007
+ return () => {
2008
+ observer.disconnect();
2009
+ };
2010
+ }, [open, entry.text]);
2011
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2012
+ "div",
2013
+ {
2014
+ className: `think-block${live ? " live" : ""}${open ? " open" : ""}`,
2015
+ "data-state": live ? "running" : "ok",
2016
+ "data-preview": preview ? "1" : void 0,
2017
+ children: [
2018
+ live ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-sr", children: "正在思考" }) : null,
2019
+ /* @__PURE__ */ jsxRuntime.jsxs(
2020
+ "div",
2021
+ {
2022
+ className: "think-head",
2023
+ role: "button",
2024
+ tabIndex: 0,
2025
+ "aria-expanded": open,
2026
+ "data-tip": open ? "收起这段思考过程" : "展开这段思考过程",
2027
+ onClick: toggle,
2028
+ onKeyDown: (event) => {
2029
+ if (event.key !== "Enter" && event.key !== " ") return;
2030
+ event.preventDefault();
2031
+ toggle();
2032
+ },
2033
+ children: [
2034
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconSpark, { size: 12, className: "think-star" }),
2035
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-label", children: "思考过程" }),
2036
+ preview ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-dot", "aria-hidden": "true" }) : null,
2037
+ 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
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "think-status", children: live ? /* @__PURE__ */ jsxRuntime.jsx("i", { className: "think-spin", "aria-hidden": "true" }) : null }),
2039
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 11, className: "think-chevron" })
2040
+ ]
2041
+ }
2042
+ ),
2043
+ open && barVisible ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "think-bar", "data-think-chrome": "1", children: [
2044
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "think-bar-status", children: [
2045
+ "思考过程 · ",
2046
+ live ? "进行中" : "已完成"
2047
+ ] }),
2048
+ /* @__PURE__ */ jsxRuntime.jsxs(
2049
+ "button",
2050
+ {
2051
+ type: "button",
2052
+ className: "think-collapse",
2053
+ title: "收起这段思考过程",
2054
+ onClick: () => {
2055
+ setOpenPersisted(false);
2056
+ },
2057
+ children: [
2058
+ "收起",
2059
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronUp, { size: 11 })
2060
+ ]
2061
+ }
2062
+ )
2063
+ ] }) : null,
2064
+ open ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "think-body", ref: bodyRef, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "think-body-clip", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "think-text", children: entry.text }) }) }) : null
2065
+ ]
2066
+ }
2067
+ );
2068
+ }
2069
+ function BuiltinToolView(props) {
2070
+ const prefs = react.useContext(FoldPrefsContext);
2071
+ const cwd = react.useContext(ShellCwdContext);
2072
+ return props.renderFactorySlot(
2073
+ TOOLCARD_FACTORY,
2074
+ {
2075
+ entry: props.entry,
2076
+ storeKey: props.storeKey,
2077
+ persistKey: props.storeKey,
2078
+ variant: "chat",
2079
+ match: props.matched,
2080
+ foldPrefs: prefs,
2081
+ cwd
2082
+ },
2083
+ {
2084
+ slots: {
2085
+ preview: IntendedPreview,
2086
+ statusDetail: ChatStatus,
2087
+ bodyExtra: IntendedBody,
2088
+ trailing: TraceJumpButton
2089
+ },
2090
+ fallback: /* @__PURE__ */ jsxRuntime.jsx(ToolRow, { entry: props.entry, matched: props.matched, storeKey: props.storeKey })
2091
+ }
2092
+ );
2093
+ }
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
+ function ToolRow({ entry, matched, storeKey }) {
2105
+ const call = entry.call;
2106
+ const prefs = react.useContext(FoldPrefsContext);
2107
+ const cwd = react.useContext(ShellCwdContext);
2108
+ const [open, setOpen] = react.useState(() => readFold(storeKey, prefs.toolOpen));
2109
+ const [barVisible, setBarVisible] = react.useState(false);
2110
+ const expandable = call.status !== "preparing";
2111
+ const bodyOpen = open && expandable;
2112
+ const running = call.status === "running";
2113
+ const summary = uiPrimitives.toolSummary(call.name, call.argsText);
2114
+ const match = matched ?? uiPrimitives.matchTool(call.name);
2115
+ const Icon = match.Icon;
2116
+ const targetPath = fileTargetOf(call.name, call.argsText, cwd);
2117
+ const intended = useIntendedDiff(call, cwd);
2118
+ const bodyRef = react.useRef(null);
2119
+ const barRef = react.useRef(null);
2120
+ const setOpenPersisted = (next) => {
2121
+ writeFold(storeKey, next);
2122
+ setOpen(next);
2123
+ };
2124
+ const toggle = () => {
2125
+ if (expandable) setOpenPersisted(!open);
2126
+ };
2127
+ react.useEffect(() => {
2128
+ const body = bodyRef.current;
2129
+ if (body === null || !bodyOpen) {
2130
+ setBarVisible(false);
2131
+ return void 0;
2132
+ }
2133
+ const measure = () => {
2134
+ setBarVisible(expandedContentHeight(body) > BAR_MIN_CONTENT_H);
2135
+ };
2136
+ measure();
2137
+ const observer = new ResizeObserver(measure);
2138
+ observer.observe(body);
2139
+ return () => {
2140
+ observer.disconnect();
2141
+ };
2142
+ }, [bodyOpen, call.argsText, call.resultText, call.status]);
2143
+ react.useEffect(() => {
2144
+ if (!bodyOpen || !barVisible) return void 0;
2145
+ const bar = barRef.current;
2146
+ const body = bodyRef.current;
2147
+ if (bar === null || body === null) return void 0;
2148
+ const chat = body.closest(".chat");
2149
+ if (!(chat instanceof HTMLElement)) return void 0;
2150
+ const padTop = Number.parseFloat(getComputedStyle(chat).paddingTop);
2151
+ const threshold = (Number.isFinite(padTop) ? padTop : 12) + 1.5;
2152
+ const sync = () => {
2153
+ const gap = bar.getBoundingClientRect().top - chat.getBoundingClientRect().top;
2154
+ bar.classList.toggle("stuck", gap <= threshold);
2155
+ };
2156
+ sync();
2157
+ chat.addEventListener("scroll", sync, { passive: true });
2158
+ return () => {
2159
+ chat.removeEventListener("scroll", sync);
2160
+ };
2161
+ }, [bodyOpen, barVisible, call.argsText, call.resultText, call.status]);
2162
+ const duration = uiPrimitives.formatDuration(call.durationMs ?? null);
2163
+ const barStatus = running || duration === null ? uiPrimitives.TOOL_STATUS_TEXT[call.status] ?? call.status : `${uiPrimitives.TOOL_STATUS_TEXT[call.status] ?? call.status} · 用时 ${duration}`;
2164
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `entry tool-card status-${call.status}${bodyOpen ? " open" : ""}`, children: [
2165
+ /* @__PURE__ */ jsxRuntime.jsxs(
2166
+ "div",
2167
+ {
2168
+ className: "tool-head",
2169
+ role: "button",
2170
+ tabIndex: expandable ? 0 : -1,
2171
+ ...expandable ? { "aria-expanded": bodyOpen } : {},
2172
+ "data-tip": expandable ? bodyOpen ? "收起参数与结果" : "展开参数与结果" : "正在准备参数",
2173
+ onClick: toggle,
2174
+ onKeyDown: (event) => {
2175
+ if (event.key !== "Enter" && event.key !== " ") return;
2176
+ event.preventDefault();
2177
+ toggle();
2178
+ },
2179
+ children: [
2180
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tool-dot", "aria-hidden": "true" }),
2181
+ /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 14, className: "tool-icon" }),
2182
+ /* @__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 }),
2184
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "preview", children: intended !== null ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2185
+ /* @__PURE__ */ jsxRuntime.jsx(OpenPathButton, { absPath: intended.absPath, cwd, patch: intended.file ?? call.change ?? null }),
2186
+ intended.file !== null && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-counts", children: [
2187
+ intended.file.status === "added" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "diff-badge", children: "新增" }),
2188
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-added", children: `+${String(intended.file.added)}` }),
2189
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-removed", children: `-${String(intended.file.removed)}` })
2190
+ ] }),
2191
+ intended.mismatch === "missing" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 不在当前文件里" }),
2192
+ intended.mismatch === "ambiguous" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 匹配多处" })
2193
+ ] }) : targetPath !== null ? /* @__PURE__ */ jsxRuntime.jsx(OpenPathButton, { absPath: targetPath, cwd, patch: call.change ?? null }) : summary }),
2194
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "status", children: [
2195
+ call.status === "running" ? /* @__PURE__ */ jsxRuntime.jsx("i", { className: "tc-spin", "aria-hidden": "true" }) : null,
2196
+ call.status === "done" ? "" : uiPrimitives.TOOL_STATUS_TEXT[call.status] ?? call.status,
2197
+ duration === null || call.status === "done" ? "" : ` · 用时 ${duration}`
2198
+ ] }),
2199
+ /* @__PURE__ */ jsxRuntime.jsx(
2200
+ "button",
2201
+ {
2202
+ type: "button",
2203
+ className: "tc-trace",
2204
+ "data-trace-jump": String(entry.id),
2205
+ "data-tip": "在轨迹页查看这条调用的时刻与耗时",
2206
+ "aria-label": "在轨迹中查看",
2207
+ onClick: (event) => {
2208
+ event.stopPropagation();
2209
+ ui$1.openTrace(entry.id);
2210
+ },
2211
+ children: "在轨迹中查看"
2212
+ }
2213
+ ),
2214
+ expandable ? /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronDown, { size: 11, className: "tc-chevron" }) : null
2215
+ ]
2216
+ }
2217
+ ),
2218
+ bodyOpen ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tool-body", ref: bodyRef, children: [
2219
+ barVisible ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-bar", "data-tc-chrome": "1", ref: barRef, children: [
2220
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-bar-status", children: barStatus }),
2221
+ running ? null : /* @__PURE__ */ jsxRuntime.jsxs(
2222
+ "button",
2223
+ {
2224
+ type: "button",
2225
+ className: "tc-collapse",
2226
+ title: "收起这张工具卡",
2227
+ onClick: () => {
2228
+ setOpenPersisted(false);
2229
+ },
2230
+ children: [
2231
+ "收起",
2232
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.IconChevronUp, { size: 11 })
2233
+ ]
2234
+ }
2235
+ )
2236
+ ] }) : null,
2237
+ intended !== null ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-intended", children: [
2238
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "tc-intended-head", children: [
2239
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-intended-title", children: "将做的改动" }),
2240
+ intended.fellBack && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "读不到文件当前内容,以下按参数推算" }),
2241
+ intended.mismatch === "missing" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 在文件中不存在,执行会失败" }),
2242
+ intended.mismatch === "ambiguous" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "tc-warn", children: "old 匹配多处,执行会失败" })
2243
+ ] }),
2244
+ intended.file === null ? /* @__PURE__ */ jsxRuntime.jsx("p", { className: "tc-intended-note", children: "两段内容一致,不会有实际改动。" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "tc-intended-diff", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.DiffRows, { hunks: intended.file.hunks, path: intended.absPath }) })
2245
+ ] }) : null,
2246
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "label", children: "参数" }),
2247
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "args", children: uiPrimitives.prettyJson(call.argsText) }),
2248
+ call.resultText === void 0 || call.resultText === "" ? null : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2249
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "label", children: "结果" }),
2250
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "result", children: call.resultText })
2251
+ ] })
2252
+ ] }) : null
2253
+ ] });
2254
+ }
2255
+ const SUB_STATE_TEXT = {
2256
+ working: "干活中",
2257
+ idle: "已收工",
2258
+ stopped: "被打断",
2259
+ failed: "过程失败"
2260
+ };
2261
+ function SubagentRow({ entry }) {
2262
+ const sub = entry.sub;
2263
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "shell-subagent", "data-state": sub.state, children: [
2264
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "shell-subagent-head", children: [
2265
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shell-subagent-name", children: sub.name }),
2266
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shell-subagent-role", children: sub.role }),
2267
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shell-subagent-state", children: SUB_STATE_TEXT[sub.state] ?? sub.state })
2268
+ ] }),
2269
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "shell-subagent-task", children: uiPrimitives.oneLine(sub.task, 160) }),
2270
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "shell-subagent-meta", children: [
2271
+ sub.rounds,
2272
+ " 轮 · ",
2273
+ sub.toolCalls,
2274
+ " 次工具",
2275
+ sub.tokens === void 0 ? "" : ` · ${uiPrimitives.formatTokens(sub.tokens)} tok`,
2276
+ sub.lastTool === void 0 ? "" : ` · 当前 ${sub.lastTool.name}`
2277
+ ] }),
2278
+ sub.error === void 0 ? null : /* @__PURE__ */ jsxRuntime.jsx("p", { className: "shell-subagent-error", children: sub.error })
2279
+ ] });
2280
+ }
2281
+ function mergeChanges(rows) {
2282
+ const turnDiff = uiPrimitives.findLast(rows, (row) => row.entry.kind === "turnDiff");
2283
+ if (turnDiff !== void 0 && turnDiff.entry.kind === "turnDiff") return turnDiff.entry.files;
2284
+ const byPath = /* @__PURE__ */ new Map();
2285
+ for (const row of rows) {
2286
+ if (row.entry.kind !== "changes") continue;
2287
+ const file = row.entry.file;
2288
+ const existing = byPath.get(file.path);
2289
+ byPath.set(
2290
+ file.path,
2291
+ existing === void 0 ? file : {
2292
+ ...existing,
2293
+ added: existing.added + file.added,
2294
+ removed: existing.removed + file.removed,
2295
+ hunks: [...existing.hunks, ...file.hunks],
2296
+ ...existing.truncated === true || file.truncated === true ? { truncated: true } : {}
2297
+ }
2298
+ );
2299
+ }
2300
+ return [...byPath.values()];
2301
+ }
2302
+ const COLLAPSED_ROWS = 4;
2303
+ function Counts({ added, removed }) {
2304
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-counts", children: [
2305
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-added", children: `+${String(added)}` }),
2306
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-removed", children: `-${String(removed)}` })
2307
+ ] });
2308
+ }
2309
+ function DiffHoverCard({
2310
+ file,
2311
+ anchor,
2312
+ cardWidth,
2313
+ cwd,
2314
+ onKeep,
2315
+ onLeave,
2316
+ onClose
2317
+ }) {
2318
+ react.useEffect(() => {
2319
+ const onKey = (event) => {
2320
+ if (event.key !== "Escape") return;
2321
+ event.stopPropagation();
2322
+ onClose();
2323
+ };
2324
+ window.addEventListener("keydown", onKey, true);
2325
+ return () => window.removeEventListener("keydown", onKey, true);
2326
+ }, [onClose]);
2327
+ const width = Math.max(320, Math.min(cardWidth - 48, window.innerWidth - 16));
2328
+ const maxHeight = Math.min(420, window.innerHeight - 24);
2329
+ const left = Math.min(Math.max(8, anchor.left - 24), Math.max(8, window.innerWidth - width - 8));
2330
+ const style = anchor.top - 12 >= maxHeight ? { left: `${String(left)}px`, bottom: `${String(window.innerHeight - anchor.top + 6)}px`, width: `${String(width)}px`, maxHeight: `${String(maxHeight)}px` } : { left: `${String(left)}px`, top: `${String(anchor.bottom + 6)}px`, width: `${String(width)}px`, maxHeight: `${String(maxHeight)}px` };
2331
+ return reactDom.createPortal(
2332
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "hover-preview", style, onMouseEnter: onKeep, onMouseLeave: onLeave, children: [
2333
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "hover-preview-head", children: [
2334
+ /* @__PURE__ */ jsxRuntime.jsx(ui$1.FileIcon, { name: file.path, size: 14 }),
2335
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "hover-preview-name", title: file.path, children: uiPrimitives.displayPathOf(file.path, cwd) }),
2336
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "hover-preview-stat", children: [
2337
+ file.status === "added" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "diff-badge", children: "新增" }),
2338
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-added", children: `+${String(file.added)}` }),
2339
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-removed", children: `-${String(file.removed)}` })
2340
+ ] })
2341
+ ] }),
2342
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "hover-preview-diff", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.DiffRows, { hunks: file.hunks, path: file.path }) })
2343
+ ] }),
2344
+ document.body
2345
+ );
2346
+ }
2347
+ function ChangesCard({ rows, cwd }) {
2348
+ const files = react.useMemo(() => mergeChanges(rows), [rows]);
2349
+ const [expanded, setExpanded] = react.useState(true);
2350
+ const cardRef = react.useRef(null);
2351
+ const hoverDelay = uiPrimitives.useHoverDelay();
2352
+ const { hover } = hoverDelay;
2353
+ react.useEffect(() => {
2354
+ setExpanded(files.length <= COLLAPSED_ROWS);
2355
+ }, [files.length]);
2356
+ if (files.length === 0) return null;
2357
+ const totalAdded = files.reduce((sum, file) => sum + file.added, 0);
2358
+ const totalRemoved = files.reduce((sum, file) => sum + file.removed, 0);
2359
+ const single = files.length === 1 ? files[0] : void 0;
2360
+ const visible = expanded ? files : files.slice(0, COLLAPSED_ROWS);
2361
+ const reviewAt = (index) => {
2362
+ ui$1.setDockReview({ files, index, cwd });
2363
+ };
2364
+ const openAt = (path) => {
2365
+ ui$1.setDockPreview({ path, cwd });
2366
+ };
2367
+ const armHover = (file, anchor) => {
2368
+ hoverDelay.arm(file, anchor, cardRef.current?.offsetWidth ?? 480);
2369
+ };
2370
+ return (
2371
+ // 不再包 `.entry-row`:旧版里 `.changes-card` 是 `.turn-seat` 的直接子项,间距靠
2372
+ // `.turn-seat > .changes-card` 那条规则给(多包一层会让选择器失配)。
2373
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "changes-card", ref: cardRef, "data-changed-files": "", ...single === void 0 ? {} : { "data-single": "1" }, children: [
2374
+ /* @__PURE__ */ jsxRuntime.jsxs(
2375
+ "button",
2376
+ {
2377
+ type: "button",
2378
+ className: "changes-head",
2379
+ onClick: () => {
2380
+ reviewAt(files.indexOf(single ?? files[0]));
2381
+ },
2382
+ children: [
2383
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-tile", children: /* @__PURE__ */ jsxRuntime.jsx(ui$1.FileIcon, { name: (single ?? files[0]).path, size: 20 }) }),
2384
+ /* @__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) }),
2386
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-stat", children: [
2387
+ /* @__PURE__ */ jsxRuntime.jsx(Counts, { added: totalAdded, removed: totalRemoved }),
2388
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-hint", children: "点击审查改动" })
2389
+ ] })
2390
+ ] })
2391
+ ]
2392
+ }
2393
+ ),
2394
+ single === void 0 ? /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "changes-list", children: visible.map((file) => /* @__PURE__ */ jsxRuntime.jsxs(
2395
+ "li",
2396
+ {
2397
+ className: "changes-row-wrap",
2398
+ onMouseEnter: (event) => armHover(file, event.currentTarget.getBoundingClientRect()),
2399
+ onMouseLeave: hoverDelay.disarm,
2400
+ children: [
2401
+ /* @__PURE__ */ jsxRuntime.jsxs(
2402
+ "button",
2403
+ {
2404
+ type: "button",
2405
+ className: "changes-row",
2406
+ onClick: () => {
2407
+ reviewAt(files.indexOf(file));
2408
+ },
2409
+ children: [
2410
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-path", title: file.path, children: [
2411
+ file.status === "added" && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "changes-badge", children: "新增" }),
2412
+ uiPrimitives.displayPathOf(file.path, cwd)
2413
+ ] }),
2414
+ /* @__PURE__ */ jsxRuntime.jsx(Counts, { added: file.added, removed: file.removed })
2415
+ ]
2416
+ }
2417
+ ),
2418
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "changes-act", children: [
2419
+ /* @__PURE__ */ jsxRuntime.jsx(
2420
+ "button",
2421
+ {
2422
+ type: "button",
2423
+ className: "changes-btn",
2424
+ onClick: () => {
2425
+ reviewAt(files.indexOf(file));
2426
+ },
2427
+ children: "审查"
2428
+ }
2429
+ ),
2430
+ /* @__PURE__ */ jsxRuntime.jsx(
2431
+ "button",
2432
+ {
2433
+ type: "button",
2434
+ className: "changes-btn",
2435
+ onClick: () => {
2436
+ openAt(file.path);
2437
+ },
2438
+ children: "打开"
2439
+ }
2440
+ )
2441
+ ] })
2442
+ ]
2443
+ },
2444
+ file.path
2445
+ )) }) : null,
2446
+ single === void 0 && files.length > COLLAPSED_ROWS ? /* @__PURE__ */ jsxRuntime.jsx(
2447
+ "button",
2448
+ {
2449
+ type: "button",
2450
+ className: "changes-toggle",
2451
+ onClick: () => {
2452
+ setExpanded((value) => !value);
2453
+ },
2454
+ children: expanded ? "收起" : `展开全部 ${String(files.length)} 个文件`
2455
+ }
2456
+ ) : null,
2457
+ single !== void 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "changes-act changes-act-single", children: [
2458
+ /* @__PURE__ */ jsxRuntime.jsx(
2459
+ "button",
2460
+ {
2461
+ type: "button",
2462
+ className: "changes-btn",
2463
+ onClick: () => {
2464
+ reviewAt(0);
2465
+ },
2466
+ children: "审查"
2467
+ }
2468
+ ),
2469
+ /* @__PURE__ */ jsxRuntime.jsx(
2470
+ "button",
2471
+ {
2472
+ type: "button",
2473
+ className: "changes-btn",
2474
+ onClick: () => {
2475
+ openAt(single.path);
2476
+ },
2477
+ children: "打开"
2478
+ }
2479
+ )
2480
+ ] }) : null,
2481
+ hover !== null ? /* @__PURE__ */ jsxRuntime.jsx(
2482
+ DiffHoverCard,
2483
+ {
2484
+ file: hover.item,
2485
+ anchor: hover.anchor,
2486
+ cardWidth: hover.cardWidth,
2487
+ cwd,
2488
+ onKeep: hoverDelay.keep,
2489
+ onLeave: hoverDelay.disarm,
2490
+ onClose: hoverDelay.close
2491
+ }
2492
+ ) : null
2493
+ ] })
2494
+ );
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
+ ]
2568
+ }
2569
+ )
2570
+ );
2571
+ }
2572
+ function TurnStatusLine(props) {
2573
+ const fallbackStart = react.useRef(Date.now());
2574
+ const [now, setNow] = react.useState(() => Date.now());
2575
+ 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
+ ] });
2614
+ }
2615
+ return this.props.children;
2616
+ }
2617
+ }
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)}`)) }) }) }) }) });
2650
+ }
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
+ ] }) });
2657
+ }
2658
+ exports.SUBAGENT_FLOW_SLOT = SUBAGENT_FLOW_SLOT;
2659
+ exports.TOOLVIEW_SLOT = TOOLVIEW_SLOT;
2660
+ exports.default = ui;
2661
+ };