dsh-tidy-display 0.1.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 (402) hide show
  1. package/CHANGELOG.md +270 -0
  2. package/DESIGN.md +72 -0
  3. package/LICENSE +24 -0
  4. package/README.en.md +118 -0
  5. package/README.md +118 -0
  6. package/THIRD_PARTY_NOTICES.md +65 -0
  7. package/compat/harness-rc2.json +99 -0
  8. package/cordis.patch.yml +5 -0
  9. package/cordis.yml +4 -0
  10. package/docs/official-rendering-bridge.md +65 -0
  11. package/docs/plans/2026-09-28-merge/checklist.md +21 -0
  12. package/docs/plans/2026-09-28-merge/findings.md +24 -0
  13. package/docs/plans/2026-09-28-merge/spec.md +61 -0
  14. package/docs/plans/2026-09-28-merge/tasks.md +34 -0
  15. package/dshx.yml +5 -0
  16. package/lib/client.js +50207 -0
  17. package/lib/client.js.map +1 -0
  18. package/lib/dsh-tidy-display.js +254 -0
  19. package/lib/types/client/Blocks.d.ts +49 -0
  20. package/lib/types/client/Blocks.d.ts.map +1 -0
  21. package/lib/types/client/Blocks.js +143 -0
  22. package/lib/types/client/Blocks.js.map +1 -0
  23. package/lib/types/client/ChoreographedFlow.d.ts +22 -0
  24. package/lib/types/client/ChoreographedFlow.d.ts.map +1 -0
  25. package/lib/types/client/ChoreographedFlow.js +218 -0
  26. package/lib/types/client/ChoreographedFlow.js.map +1 -0
  27. package/lib/types/client/ClosedProcessSummary.d.ts +9 -0
  28. package/lib/types/client/ClosedProcessSummary.d.ts.map +1 -0
  29. package/lib/types/client/ClosedProcessSummary.js +16 -0
  30. package/lib/types/client/ClosedProcessSummary.js.map +1 -0
  31. package/lib/types/client/DiffPanel.d.ts +13 -0
  32. package/lib/types/client/DiffPanel.d.ts.map +1 -0
  33. package/lib/types/client/DiffPanel.js +115 -0
  34. package/lib/types/client/DiffPanel.js.map +1 -0
  35. package/lib/types/client/LiveFold.d.ts +10 -0
  36. package/lib/types/client/LiveFold.d.ts.map +1 -0
  37. package/lib/types/client/LiveFold.js +39 -0
  38. package/lib/types/client/LiveFold.js.map +1 -0
  39. package/lib/types/client/McpAppFrame.d.ts +32 -0
  40. package/lib/types/client/McpAppFrame.d.ts.map +1 -0
  41. package/lib/types/client/McpAppFrame.js +193 -0
  42. package/lib/types/client/McpAppFrame.js.map +1 -0
  43. package/lib/types/client/OfficialContent.d.ts +25 -0
  44. package/lib/types/client/OfficialContent.d.ts.map +1 -0
  45. package/lib/types/client/OfficialContent.js +53 -0
  46. package/lib/types/client/OfficialContent.js.map +1 -0
  47. package/lib/types/client/Reader.d.ts +3 -0
  48. package/lib/types/client/Reader.d.ts.map +1 -0
  49. package/lib/types/client/Reader.js +508 -0
  50. package/lib/types/client/Reader.js.map +1 -0
  51. package/lib/types/client/ReasoningCard.d.ts +11 -0
  52. package/lib/types/client/ReasoningCard.d.ts.map +1 -0
  53. package/lib/types/client/ReasoningCard.js +322 -0
  54. package/lib/types/client/ReasoningCard.js.map +1 -0
  55. package/lib/types/client/SettingsSection.d.ts +59 -0
  56. package/lib/types/client/SettingsSection.d.ts.map +1 -0
  57. package/lib/types/client/SettingsSection.js +93 -0
  58. package/lib/types/client/SettingsSection.js.map +1 -0
  59. package/lib/types/client/StickyLane.d.ts +8 -0
  60. package/lib/types/client/StickyLane.d.ts.map +1 -0
  61. package/lib/types/client/StickyLane.js +39 -0
  62. package/lib/types/client/StickyLane.js.map +1 -0
  63. package/lib/types/client/TimelineRail.d.ts +10 -0
  64. package/lib/types/client/TimelineRail.d.ts.map +1 -0
  65. package/lib/types/client/TimelineRail.js +168 -0
  66. package/lib/types/client/TimelineRail.js.map +1 -0
  67. package/lib/types/client/ToolActivity.d.ts +17 -0
  68. package/lib/types/client/ToolActivity.d.ts.map +1 -0
  69. package/lib/types/client/ToolActivity.js +244 -0
  70. package/lib/types/client/ToolActivity.js.map +1 -0
  71. package/lib/types/client/TurnMetrics.d.ts +11 -0
  72. package/lib/types/client/TurnMetrics.d.ts.map +1 -0
  73. package/lib/types/client/TurnMetrics.js +44 -0
  74. package/lib/types/client/TurnMetrics.js.map +1 -0
  75. package/lib/types/client/WaitClock.d.ts +16 -0
  76. package/lib/types/client/WaitClock.d.ts.map +1 -0
  77. package/lib/types/client/WaitClock.js +29 -0
  78. package/lib/types/client/WaitClock.js.map +1 -0
  79. package/lib/types/client/WaitingClock.d.ts +15 -0
  80. package/lib/types/client/WaitingClock.d.ts.map +1 -0
  81. package/lib/types/client/WaitingClock.js +30 -0
  82. package/lib/types/client/WaitingClock.js.map +1 -0
  83. package/lib/types/client/WaitingStatus.d.ts +6 -0
  84. package/lib/types/client/WaitingStatus.d.ts.map +1 -0
  85. package/lib/types/client/WaitingStatus.js +9 -0
  86. package/lib/types/client/WaitingStatus.js.map +1 -0
  87. package/lib/types/client/conversation-scroll.d.ts +19 -0
  88. package/lib/types/client/conversation-scroll.d.ts.map +1 -0
  89. package/lib/types/client/conversation-scroll.js +25 -0
  90. package/lib/types/client/conversation-scroll.js.map +1 -0
  91. package/lib/types/client/deliverables.d.ts +24 -0
  92. package/lib/types/client/deliverables.d.ts.map +1 -0
  93. package/lib/types/client/deliverables.js +104 -0
  94. package/lib/types/client/deliverables.js.map +1 -0
  95. package/lib/types/client/entry-policy.d.ts +10 -0
  96. package/lib/types/client/entry-policy.d.ts.map +1 -0
  97. package/lib/types/client/entry-policy.js +24 -0
  98. package/lib/types/client/entry-policy.js.map +1 -0
  99. package/lib/types/client/entry.d.ts +4 -0
  100. package/lib/types/client/entry.d.ts.map +1 -0
  101. package/lib/types/client/entry.js +34 -0
  102. package/lib/types/client/entry.js.map +1 -0
  103. package/lib/types/client/fold-choreography.d.ts +40 -0
  104. package/lib/types/client/fold-choreography.d.ts.map +1 -0
  105. package/lib/types/client/fold-choreography.js +48 -0
  106. package/lib/types/client/fold-choreography.js.map +1 -0
  107. package/lib/types/client/fold-intensity.d.ts +11 -0
  108. package/lib/types/client/fold-intensity.d.ts.map +1 -0
  109. package/lib/types/client/fold-intensity.js +32 -0
  110. package/lib/types/client/fold-intensity.js.map +1 -0
  111. package/lib/types/client/index.d.ts +7 -0
  112. package/lib/types/client/index.d.ts.map +1 -0
  113. package/lib/types/client/index.js +234 -0
  114. package/lib/types/client/index.js.map +1 -0
  115. package/lib/types/client/live-turn.d.ts +58 -0
  116. package/lib/types/client/live-turn.d.ts.map +1 -0
  117. package/lib/types/client/live-turn.js +144 -0
  118. package/lib/types/client/live-turn.js.map +1 -0
  119. package/lib/types/client/markdown/MarkdownText.d.ts +41 -0
  120. package/lib/types/client/markdown/MarkdownText.d.ts.map +1 -0
  121. package/lib/types/client/markdown/MarkdownText.js +178 -0
  122. package/lib/types/client/markdown/MarkdownText.js.map +1 -0
  123. package/lib/types/client/markdown/cjkFriendlyStrong.d.ts +9 -0
  124. package/lib/types/client/markdown/cjkFriendlyStrong.d.ts.map +1 -0
  125. package/lib/types/client/markdown/cjkFriendlyStrong.js +73 -0
  126. package/lib/types/client/markdown/cjkFriendlyStrong.js.map +1 -0
  127. package/lib/types/client/markdown/incremental.d.ts +69 -0
  128. package/lib/types/client/markdown/incremental.d.ts.map +1 -0
  129. package/lib/types/client/markdown/incremental.js +108 -0
  130. package/lib/types/client/markdown/incremental.js.map +1 -0
  131. package/lib/types/client/markdown/katex.d.ts +27 -0
  132. package/lib/types/client/markdown/katex.d.ts.map +1 -0
  133. package/lib/types/client/markdown/katex.js +88 -0
  134. package/lib/types/client/markdown/katex.js.map +1 -0
  135. package/lib/types/client/markdown/mathCompatibility.d.ts +11 -0
  136. package/lib/types/client/markdown/mathCompatibility.d.ts.map +1 -0
  137. package/lib/types/client/markdown/mathCompatibility.js +295 -0
  138. package/lib/types/client/markdown/mathCompatibility.js.map +1 -0
  139. package/lib/types/client/markdown/parse.d.ts +25 -0
  140. package/lib/types/client/markdown/parse.d.ts.map +1 -0
  141. package/lib/types/client/markdown/parse.js +42 -0
  142. package/lib/types/client/markdown/parse.js.map +1 -0
  143. package/lib/types/client/markdown/render.d.ts +121 -0
  144. package/lib/types/client/markdown/render.d.ts.map +1 -0
  145. package/lib/types/client/markdown/render.js +452 -0
  146. package/lib/types/client/markdown/render.js.map +1 -0
  147. package/lib/types/client/mcp-app.d.ts +50 -0
  148. package/lib/types/client/mcp-app.d.ts.map +1 -0
  149. package/lib/types/client/mcp-app.js +328 -0
  150. package/lib/types/client/mcp-app.js.map +1 -0
  151. package/lib/types/client/message-chrome.d.ts +19 -0
  152. package/lib/types/client/message-chrome.d.ts.map +1 -0
  153. package/lib/types/client/message-chrome.js +42 -0
  154. package/lib/types/client/message-chrome.js.map +1 -0
  155. package/lib/types/client/motion.d.ts +38 -0
  156. package/lib/types/client/motion.d.ts.map +1 -0
  157. package/lib/types/client/motion.js +453 -0
  158. package/lib/types/client/motion.js.map +1 -0
  159. package/lib/types/client/native/ContextBody.d.ts +130 -0
  160. package/lib/types/client/native/ContextBody.d.ts.map +1 -0
  161. package/lib/types/client/native/ContextBody.js +398 -0
  162. package/lib/types/client/native/ContextBody.js.map +1 -0
  163. package/lib/types/client/native/ContextInjectionRow.d.ts +35 -0
  164. package/lib/types/client/native/ContextInjectionRow.d.ts.map +1 -0
  165. package/lib/types/client/native/ContextInjectionRow.js +42 -0
  166. package/lib/types/client/native/ContextInjectionRow.js.map +1 -0
  167. package/lib/types/client/native/ReferenceIcon.d.ts +16 -0
  168. package/lib/types/client/native/ReferenceIcon.d.ts.map +1 -0
  169. package/lib/types/client/native/ReferenceIcon.js +16 -0
  170. package/lib/types/client/native/ReferenceIcon.js.map +1 -0
  171. package/lib/types/client/native/tool-call-model.d.ts +58 -0
  172. package/lib/types/client/native/tool-call-model.d.ts.map +1 -0
  173. package/lib/types/client/native/tool-call-model.js +219 -0
  174. package/lib/types/client/native/tool-call-model.js.map +1 -0
  175. package/lib/types/client/native/tool-update.d.ts +23 -0
  176. package/lib/types/client/native/tool-update.d.ts.map +1 -0
  177. package/lib/types/client/native/tool-update.js +22 -0
  178. package/lib/types/client/native/tool-update.js.map +1 -0
  179. package/lib/types/client/official-slots.d.ts +71 -0
  180. package/lib/types/client/official-slots.d.ts.map +1 -0
  181. package/lib/types/client/official-slots.js +183 -0
  182. package/lib/types/client/official-slots.js.map +1 -0
  183. package/lib/types/client/open-file.d.ts +29 -0
  184. package/lib/types/client/open-file.d.ts.map +1 -0
  185. package/lib/types/client/open-file.js +71 -0
  186. package/lib/types/client/open-file.js.map +1 -0
  187. package/lib/types/client/pending-submission.d.ts +28 -0
  188. package/lib/types/client/pending-submission.d.ts.map +1 -0
  189. package/lib/types/client/pending-submission.js +28 -0
  190. package/lib/types/client/pending-submission.js.map +1 -0
  191. package/lib/types/client/platform-media.d.ts +6 -0
  192. package/lib/types/client/platform-media.d.ts.map +1 -0
  193. package/lib/types/client/platform-media.js +18 -0
  194. package/lib/types/client/platform-media.js.map +1 -0
  195. package/lib/types/client/primitive-labels.d.ts +10 -0
  196. package/lib/types/client/primitive-labels.d.ts.map +1 -0
  197. package/lib/types/client/primitive-labels.js +38 -0
  198. package/lib/types/client/primitive-labels.js.map +1 -0
  199. package/lib/types/client/projection.d.ts +41 -0
  200. package/lib/types/client/projection.d.ts.map +1 -0
  201. package/lib/types/client/projection.js +112 -0
  202. package/lib/types/client/projection.js.map +1 -0
  203. package/lib/types/client/rail/RailView.d.ts +24 -0
  204. package/lib/types/client/rail/RailView.d.ts.map +1 -0
  205. package/lib/types/client/rail/RailView.js +540 -0
  206. package/lib/types/client/rail/RailView.js.map +1 -0
  207. package/lib/types/client/rail/colors.d.ts +43 -0
  208. package/lib/types/client/rail/colors.d.ts.map +1 -0
  209. package/lib/types/client/rail/colors.js +223 -0
  210. package/lib/types/client/rail/colors.js.map +1 -0
  211. package/lib/types/client/reasoning-follow.d.ts +10 -0
  212. package/lib/types/client/reasoning-follow.d.ts.map +1 -0
  213. package/lib/types/client/reasoning-follow.js +21 -0
  214. package/lib/types/client/reasoning-follow.js.map +1 -0
  215. package/lib/types/client/resource-address.d.ts +3 -0
  216. package/lib/types/client/resource-address.d.ts.map +1 -0
  217. package/lib/types/client/resource-address.js +33 -0
  218. package/lib/types/client/resource-address.js.map +1 -0
  219. package/lib/types/client/settings-copy.d.ts +7 -0
  220. package/lib/types/client/settings-copy.d.ts.map +1 -0
  221. package/lib/types/client/settings-copy.js +85 -0
  222. package/lib/types/client/settings-copy.js.map +1 -0
  223. package/lib/types/client/settings-slots.d.ts +34 -0
  224. package/lib/types/client/settings-slots.d.ts.map +1 -0
  225. package/lib/types/client/settings-slots.js +2 -0
  226. package/lib/types/client/settings-slots.js.map +1 -0
  227. package/lib/types/client/settings.d.ts +4 -0
  228. package/lib/types/client/settings.d.ts.map +1 -0
  229. package/lib/types/client/settings.js +60 -0
  230. package/lib/types/client/settings.js.map +1 -0
  231. package/lib/types/client/skill-status.d.ts +25 -0
  232. package/lib/types/client/skill-status.d.ts.map +1 -0
  233. package/lib/types/client/skill-status.js +44 -0
  234. package/lib/types/client/skill-status.js.map +1 -0
  235. package/lib/types/client/store.d.ts +66 -0
  236. package/lib/types/client/store.d.ts.map +1 -0
  237. package/lib/types/client/store.js +61 -0
  238. package/lib/types/client/store.js.map +1 -0
  239. package/lib/types/client/stream-buffer.d.ts +37 -0
  240. package/lib/types/client/stream-buffer.d.ts.map +1 -0
  241. package/lib/types/client/stream-buffer.js +150 -0
  242. package/lib/types/client/stream-buffer.js.map +1 -0
  243. package/lib/types/client/streaming.d.ts +18 -0
  244. package/lib/types/client/streaming.d.ts.map +1 -0
  245. package/lib/types/client/streaming.js +84 -0
  246. package/lib/types/client/streaming.js.map +1 -0
  247. package/lib/types/client/timeline.d.ts +26 -0
  248. package/lib/types/client/timeline.d.ts.map +1 -0
  249. package/lib/types/client/timeline.js +48 -0
  250. package/lib/types/client/timeline.js.map +1 -0
  251. package/lib/types/client/tool-activity.d.ts +98 -0
  252. package/lib/types/client/tool-activity.d.ts.map +1 -0
  253. package/lib/types/client/tool-activity.js +301 -0
  254. package/lib/types/client/tool-activity.js.map +1 -0
  255. package/lib/types/client/types.d.ts +91 -0
  256. package/lib/types/client/types.d.ts.map +1 -0
  257. package/lib/types/client/types.js +2 -0
  258. package/lib/types/client/types.js.map +1 -0
  259. package/lib/types/client/waiting-clock.d.ts +49 -0
  260. package/lib/types/client/waiting-clock.d.ts.map +1 -0
  261. package/lib/types/client/waiting-clock.js +80 -0
  262. package/lib/types/client/waiting-clock.js.map +1 -0
  263. package/lib/types/client/word-motion.d.ts +16 -0
  264. package/lib/types/client/word-motion.d.ts.map +1 -0
  265. package/lib/types/client/word-motion.js +90 -0
  266. package/lib/types/client/word-motion.js.map +1 -0
  267. package/lib/types/client/word-timeline.d.ts +32 -0
  268. package/lib/types/client/word-timeline.d.ts.map +1 -0
  269. package/lib/types/client/word-timeline.js +119 -0
  270. package/lib/types/client/word-timeline.js.map +1 -0
  271. package/lib/types/dsh-tidy-display.d.ts +17 -0
  272. package/lib/types/dsh-tidy-display.d.ts.map +1 -0
  273. package/lib/types/dsh-tidy-display.js +97 -0
  274. package/lib/types/dsh-tidy-display.js.map +1 -0
  275. package/lib/types/skill-roots.d.ts +22 -0
  276. package/lib/types/skill-roots.d.ts.map +1 -0
  277. package/lib/types/skill-roots.js +126 -0
  278. package/lib/types/skill-roots.js.map +1 -0
  279. package/lib/types/skill-status.d.ts +36 -0
  280. package/lib/types/skill-status.d.ts.map +1 -0
  281. package/lib/types/skill-status.js +51 -0
  282. package/lib/types/skill-status.js.map +1 -0
  283. package/package.json +141 -0
  284. package/scripts/build-motion-fixture.mjs +26 -0
  285. package/scripts/check-harness-compat.mjs +75 -0
  286. package/scripts/link-harness-dependencies.mjs +54 -0
  287. package/scripts/verify-auto-fold.mjs +114 -0
  288. package/scripts/verify-official-bridge.mjs +121 -0
  289. package/scripts/verify-tool-shimmer.mjs +62 -0
  290. package/skills/generative-mcpapps/SKILL.md +47 -0
  291. package/skills/generative-mcpapps/examples/interactive_quiz.html +153 -0
  292. package/skills/generative-mcpapps/references/html_boilerplate.md +122 -0
  293. package/skills/generative-mcpapps/references/sep1865_protocol.md +54 -0
  294. package/src/client/Blocks.tsx +213 -0
  295. package/src/client/ChoreographedFlow.tsx +232 -0
  296. package/src/client/ClosedProcessSummary.tsx +23 -0
  297. package/src/client/DiffPanel.tsx +124 -0
  298. package/src/client/LiveFold.tsx +43 -0
  299. package/src/client/McpAppFrame.module.css +210 -0
  300. package/src/client/McpAppFrame.tsx +317 -0
  301. package/src/client/OfficialContent.tsx +69 -0
  302. package/src/client/Reader.module.css +714 -0
  303. package/src/client/Reader.tsx +783 -0
  304. package/src/client/ReasoningCard.tsx +306 -0
  305. package/src/client/SettingsSection.module.css +184 -0
  306. package/src/client/SettingsSection.tsx +391 -0
  307. package/src/client/StickyLane.tsx +34 -0
  308. package/src/client/ToolActivity.tsx +274 -0
  309. package/src/client/TurnMetrics.module.css +139 -0
  310. package/src/client/TurnMetrics.tsx +160 -0
  311. package/src/client/WaitClock.tsx +33 -0
  312. package/src/client/WaitingStatus.tsx +13 -0
  313. package/src/client/conversation-scroll.ts +28 -0
  314. package/src/client/deliverables.ts +122 -0
  315. package/src/client/entry-policy.ts +20 -0
  316. package/src/client/entry.tsx +40 -0
  317. package/src/client/fold-choreography.ts +55 -0
  318. package/src/client/fold-intensity.ts +36 -0
  319. package/src/client/index.tsx +268 -0
  320. package/src/client/live-turn.ts +155 -0
  321. package/src/client/markdown/MarkdownText.module.css +304 -0
  322. package/src/client/markdown/MarkdownText.tsx +195 -0
  323. package/src/client/markdown/cjkFriendlyStrong.ts +84 -0
  324. package/src/client/markdown/incremental.ts +131 -0
  325. package/src/client/markdown/katex.tsx +91 -0
  326. package/src/client/markdown/mathCompatibility.ts +352 -0
  327. package/src/client/markdown/parse.ts +45 -0
  328. package/src/client/markdown/render.tsx +647 -0
  329. package/src/client/markdown/upstream.json +14 -0
  330. package/src/client/mcp-app.ts +323 -0
  331. package/src/client/message-chrome.ts +47 -0
  332. package/src/client/motion.tsx +410 -0
  333. package/src/client/native/ContextBody.module.css +161 -0
  334. package/src/client/native/ContextBody.tsx +591 -0
  335. package/src/client/native/ContextInjectionRow.module.css +66 -0
  336. package/src/client/native/ContextInjectionRow.tsx +106 -0
  337. package/src/client/native/ReferenceIcon.tsx +35 -0
  338. package/src/client/native/tool-call-model.ts +248 -0
  339. package/src/client/native/tool-update.ts +32 -0
  340. package/src/client/native/upstream.json +41 -0
  341. package/src/client/official-slots.tsx +211 -0
  342. package/src/client/open-file.ts +94 -0
  343. package/src/client/pending-submission.ts +49 -0
  344. package/src/client/platform-media.ts +17 -0
  345. package/src/client/primitive-labels.ts +54 -0
  346. package/src/client/projection.ts +118 -0
  347. package/src/client/rail/RailView.tsx +508 -0
  348. package/src/client/rail/colors.ts +212 -0
  349. package/src/client/reasoning-follow.ts +28 -0
  350. package/src/client/settings-copy.ts +128 -0
  351. package/src/client/settings-slots.ts +27 -0
  352. package/src/client/settings.tsx +73 -0
  353. package/src/client/skill-status.ts +78 -0
  354. package/src/client/store.ts +130 -0
  355. package/src/client/stream-buffer.ts +136 -0
  356. package/src/client/streaming.tsx +70 -0
  357. package/src/client/style.d.ts +4 -0
  358. package/src/client/timeline.ts +75 -0
  359. package/src/client/tool-activity.ts +298 -0
  360. package/src/client/types.ts +89 -0
  361. package/src/client/waiting-clock.ts +83 -0
  362. package/src/client/word-motion.tsx +92 -0
  363. package/src/client/word-timeline.ts +113 -0
  364. package/src/dsh-tidy-display.ts +112 -0
  365. package/src/skill-roots.ts +138 -0
  366. package/src/skill-status.ts +81 -0
  367. package/tests/browser-auto-fold.tsx +64 -0
  368. package/tests/browser-closed-gap.tsx +20 -0
  369. package/tests/browser-motion.tsx +65 -0
  370. package/tests/browser-official-bridge.tsx +152 -0
  371. package/tests/browser-sticky-lanes.tsx +22 -0
  372. package/tests/browser-waiting-clock.tsx +14 -0
  373. package/tests/chat-flow-hook.test.ts +66 -0
  374. package/tests/cloud-gate.test.ts +34 -0
  375. package/tests/context-tool-update.test.ts +33 -0
  376. package/tests/conversation-scroll.test.ts +47 -0
  377. package/tests/deliverables.test.ts +128 -0
  378. package/tests/entry.test.ts +42 -0
  379. package/tests/fixtures/maid-composer-hide.html +31 -0
  380. package/tests/fold-choreography.test.ts +54 -0
  381. package/tests/fold-intensity.test.ts +93 -0
  382. package/tests/footer-precedence.test.ts +129 -0
  383. package/tests/history-word-regression.test.ts +16 -0
  384. package/tests/live-turn.test.ts +218 -0
  385. package/tests/mcp-apps.test.ts +157 -0
  386. package/tests/message-chrome.test.ts +29 -0
  387. package/tests/official-slots.test.ts +112 -0
  388. package/tests/open-file.test.ts +114 -0
  389. package/tests/pending-submission.test.ts +45 -0
  390. package/tests/platform-media.test.ts +23 -0
  391. package/tests/projection.test.ts +184 -0
  392. package/tests/reasoning-follow.test.ts +34 -0
  393. package/tests/settings-copy.test.ts +63 -0
  394. package/tests/skill-status.test.ts +140 -0
  395. package/tests/stock-install.test.ts +58 -0
  396. package/tests/stream-buffer.test.ts +102 -0
  397. package/tests/timeline.test.ts +59 -0
  398. package/tests/tool-diff.test.ts +57 -0
  399. package/tests/waiting-clock.test.ts +83 -0
  400. package/tests/word-timeline.test.ts +146 -0
  401. package/tsconfig.json +11 -0
  402. package/tsdown.config.ts +51 -0
@@ -0,0 +1,298 @@
1
+ import type { AssistantBlock, ToolCallBlock, TurnLocation } from '@deepseek-ai/dsh-client-ui-conversation/client';
2
+ import type { ChatConversationViewNode } from '@deepseek-ai/dsh-client-ui-chat/client';
3
+ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client';
4
+ import type { ReaderGroup } from './projection.js';
5
+
6
+ export type ToolDraft = Extract<AssistantBlock, { kind: 'tool-call' }>;
7
+ export type ToolPhase = 'preparing' | 'running' | 'returned' | 'succeeded' | 'failed' | 'interrupted';
8
+ export type ToolCategory = 'write' | 'read' | 'terminal' | 'search' | 'web' | 'code' | 'other';
9
+ export interface ToolActivityEntry {
10
+ kind: 'tool'; key: string; callId: string; step: number; order: number;
11
+ draft?: ToolDraft; block?: ToolCallBlock;
12
+ }
13
+ export type ReaderFlowEntry = ToolActivityEntry | { kind: 'node'; key: string; nodeKey: string; order: number };
14
+
15
+ /** Public Step data includes tool-only model output before a chat node exists. */
16
+ export function readerFlow(group: ReaderGroup, turn: TurnLocation | undefined, get: (key: string) => ChatConversationViewNode | undefined): ReaderFlowEntry[] {
17
+ const flow: ReaderFlowEntry[] = [];
18
+ const calls = new Map<string, ToolActivityEntry>();
19
+ const assistantOrder = new Map<number, number>();
20
+ for (const key of group.keys) {
21
+ const node = get(key);
22
+ if (!node || node.visibility === 'hidden') continue;
23
+ const step = node.location.kind === 'step' ? node.location.step.step : 0;
24
+ if (node.kind === 'tool-call') {
25
+ const block = (node.data as { root: ToolCallBlock }).root;
26
+ calls.set(block.callId, { kind: 'tool', key: `reader-tool:${block.callId}`, callId: block.callId, step, block, order: node.anchorSeq });
27
+ } else {
28
+ flow.push({ kind: 'node', key, nodeKey: key, order: node.anchorSeq });
29
+ if (node.kind === 'assistant-step') assistantOrder.set(step, node.anchorSeq);
30
+ }
31
+ }
32
+ for (const step of turn?.steps ?? []) {
33
+ const data = step.data.get('assistant-step');
34
+ let index = 0;
35
+ for (const draft of data?.blocks ?? []) {
36
+ if (draft.kind !== 'tool-call' || !draft.callId) continue;
37
+ const previous = calls.get(draft.callId);
38
+ calls.set(draft.callId, previous ? { ...previous, draft } : {
39
+ kind: 'tool', key: `reader-tool:${draft.callId}`, callId: draft.callId, step: step.step, draft,
40
+ order: (assistantOrder.get(step.step) ?? step.start?.seq ?? 0) + .01 + index++ / 10000,
41
+ });
42
+ }
43
+ }
44
+ flow.push(...calls.values());
45
+ return flow.sort((left, right) => left.order - right.order);
46
+ }
47
+
48
+ export function objectValue(value: unknown): Record<string, unknown> | null {
49
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value as Record<string, unknown> : null;
50
+ }
51
+ export function stringValue(record: Record<string, unknown> | null, ...keys: string[]): string | undefined {
52
+ for (const key of keys) if (typeof record?.[key] === 'string' && record[key]) return record[key] as string;
53
+ return undefined;
54
+ }
55
+
56
+ /** Read only top-level JSON string values, including an unfinished final string.
57
+ * This never executes input or mistakes escaped/nested content for a path field. */
58
+ export function inputFields(raw: string): Record<string, unknown> {
59
+ try { return objectValue(JSON.parse(raw)) ?? {}; } catch { /* an in-flight argument is normally incomplete */ }
60
+ const fields: Record<string, unknown> = Object.create(null);
61
+ const prefix = raw.slice(0, 262144);
62
+ let depth = 0;
63
+ let key: string | undefined;
64
+ for (let index = 0; index < prefix.length; index++) {
65
+ const char = prefix[index];
66
+ if (char === '{' || char === '[') { depth++; continue; }
67
+ if (char === '}' || char === ']') { depth--; continue; }
68
+ if (char !== '"') continue;
69
+ const start = index;
70
+ let closed = false;
71
+ for (index++; index < prefix.length; index++) {
72
+ if (prefix[index] === '\\') { index++; continue; }
73
+ if (prefix[index] === '"') { closed = true; break; }
74
+ }
75
+ if (depth !== 1) continue;
76
+ const token = prefix.slice(start, closed ? index + 1 : prefix.length);
77
+ let value: string;
78
+ try { value = JSON.parse(token); } catch {
79
+ if (closed) continue;
80
+ // Strip only an unfinished trailing escape/unicode escape, not content.
81
+ let body = token.slice(1);
82
+ const unicode = /(?<!\\)(?:\\\\)*\\u[\da-f]{0,3}$/i.exec(body);
83
+ if (unicode) body = body.slice(0, unicode.index) + unicode[0].replace(/\\u[\da-f]{0,3}$/i, '');
84
+ let slashes = 0; for (let end = body.length - 1; end >= 0 && body[end] === '\\'; end--) slashes++;
85
+ if (slashes % 2) body = body.slice(0, -1);
86
+ try { value = JSON.parse(`"${body}"`); } catch { continue; }
87
+ }
88
+ if (closed && /^\s*:/.test(prefix.slice(index + 1))) key = value;
89
+ else if (key !== undefined) { fields[key] = value; key = undefined; }
90
+ }
91
+ return fields;
92
+ }
93
+
94
+ export function toolIdentity(entry: Pick<ToolActivityEntry, 'block' | 'draft'>) {
95
+ const block = entry.block;
96
+ return {
97
+ name: block ? 'kind' in block ? block.call?.name ?? entry.draft?.name ?? '工具调用' : block.name : entry.draft?.name ?? '工具调用',
98
+ raw: block ? 'kind' in block ? block.call?.argsRaw ?? entry.draft?.argsRaw ?? '' : ('argsRaw' in block ? block.argsRaw : '') : entry.draft?.argsRaw ?? '',
99
+ };
100
+ }
101
+
102
+ /** Name and raw arguments of any call block, whether it has landed or is pending. */
103
+ function childIdentity(block: ToolCallBlock): { name?: string; raw: string } {
104
+ if (!block || !('kind' in block)) return { name: block?.name, raw: block && 'argsRaw' in block ? block.argsRaw : '' };
105
+ return { name: block.call?.name, raw: block.call?.argsRaw ?? '' };
106
+ }
107
+
108
+ export function executionFacts(block: ToolCallBlock | undefined): { exitCode?: number; signal?: string } {
109
+ if (!block || !('kind' in block)) return {};
110
+ const meta = objectValue(block.meta);
111
+ const code = meta?.exitCode ?? meta?.exit_code;
112
+ const text = block.content.length === 1 && block.content[0]?.type === 'text' ? block.content[0].text : '';
113
+ const exit = /\n\[exit code: (\d+)\]$/.exec(text);
114
+ const signal = /\n\[killed by signal: ([^\]\n]+)\]$/.exec(text);
115
+ const parsedCode = exit?.[1] === undefined ? undefined : Number(exit[1]);
116
+ return {
117
+ exitCode: typeof code === 'number' && Number.isFinite(code) ? code : parsedCode,
118
+ signal: stringValue(meta, 'signal') ?? signal?.[1],
119
+ };
120
+ }
121
+
122
+ /** Line counts of one text side; a trailing newline does not start a line. */
123
+ function lineCount(text: string | null): number {
124
+ if (text === null) return 0;
125
+ const body = text.endsWith('\n') ? text.slice(0, -1) : text;
126
+ return body === '' ? 0 : body.split('\n').length;
127
+ }
128
+
129
+ /** Argument fields that carry the text a call is about to write. */
130
+ const NEW_TEXT_FIELDS = ['content', 'new_string', 'new_str', 'newText', 'file_text'] as const;
131
+ /** Argument fields that carry the text a call is about to replace. */
132
+ const OLD_TEXT_FIELDS = ['old_string', 'old_str', 'oldText'] as const;
133
+
134
+ /**
135
+ * Added/removed line counts for a mutation call, or null when there is no diff
136
+ * to show.
137
+ *
138
+ * The result metadata is preferred when the host attaches one. Not every host
139
+ * build does — a session log may carry no hunk payload at all — so the call's own
140
+ * arguments are read as the fallback, which is also what the official row uses
141
+ * while a write is still pending. A call whose arguments hold none of these
142
+ * fields (a read, a listing) yields null and shows no badge.
143
+ */
144
+ /**
145
+ * One changed file, in the exact shape the official `DiffBlock` primitive takes:
146
+ * `oldText` is null for a pure insertion, and `newText` is always a string. Line
147
+ * counts are derived from these two sides, never stored alongside them.
148
+ */
149
+ export interface DiffHunk {
150
+ path: string;
151
+ oldText: string | null;
152
+ newText: string;
153
+ }
154
+
155
+ /** Argument fields that name the file a mutation call targets. */
156
+ const PATH_FIELDS = ['file_path', 'path', 'filePath'] as const;
157
+
158
+ function firstString(source: Record<string, unknown> | undefined, fields: readonly string[]): string | null {
159
+ if (!source) return null;
160
+ for (const field of fields) {
161
+ const value = source[field];
162
+ if (typeof value === 'string' && value !== '') return value;
163
+ }
164
+ return null;
165
+ }
166
+
167
+ /**
168
+ * The changed files of a mutation call.
169
+ *
170
+ * Result metadata is preferred when the host attaches it. Not every host build
171
+ * does, so the call's own arguments are the fallback — the same source the
172
+ * official row reads while a write is still pending. A call whose arguments hold
173
+ * none of these fields (a read, a listing) yields nothing and shows no counts.
174
+ */
175
+ /** Only these tools change a file, so only these may fall back to their arguments. */
176
+ export const DIFF_FALLBACK_TOOLS = ['write', 'edit', 'str_replace_editor'] as const;
177
+ const MUTATION_TOOLS = new Set<string>(DIFF_FALLBACK_TOOLS);
178
+
179
+ export function callDiffHunks(
180
+ block: ToolCallBlock | undefined,
181
+ args?: Record<string, unknown>,
182
+ name?: string,
183
+ ): DiffHunk[] {
184
+ // A parent call owns whatever its children changed: a script that writes files
185
+ // reports those writes itself rather than through its own arguments, and the
186
+ // digest must see them too. Without this the counts only ever appeared on the
187
+ // nested row, which is what a reader noticed as a missing badge.
188
+ // Each child contributes through its own arguments, not the parent's: a nested
189
+ // write/edit records its hunks in `argsRaw`, and passing nothing here silently
190
+ // dropped them from the parent total. Errors are contained so one unreadable
191
+ // child cannot blank the whole row.
192
+ const nested = block && 'kind' in block && Array.isArray(block.subCalls)
193
+ ? block.subCalls.flatMap(child => {
194
+ try { return callDiffHunks(child, inputFields(childIdentity(child).raw), childIdentity(child).name); }
195
+ catch { return []; }
196
+ })
197
+ : [];
198
+ if (block && 'kind' in block) {
199
+ const diffs = objectValue(block.meta)?.diffs;
200
+ if (Array.isArray(diffs) && diffs.length > 0) {
201
+ const hunks: DiffHunk[] = [];
202
+ for (const raw of diffs) {
203
+ const entry = objectValue(raw);
204
+ if (!entry) continue;
205
+ const oldText = typeof entry.oldText === 'string' ? entry.oldText : null;
206
+ const newText = typeof entry.newText === 'string' ? entry.newText : '';
207
+ if (!lineCount(newText) && !lineCount(oldText)) continue;
208
+ hunks.push({ path: firstString(entry, PATH_FIELDS) ?? '', oldText, newText });
209
+ }
210
+ if (hunks.length) return [...hunks, ...nested];
211
+ }
212
+ }
213
+ // Several unrelated tools take a field named `content` (a memory note, a typed
214
+ // message). Reading it as a file body invented counts for calls that changed no
215
+ // file at all, so the name decides whether arguments may be read this way.
216
+ if (!name || !MUTATION_TOOLS.has(name)) return nested;
217
+ const path = firstString(args, PATH_FIELDS);
218
+ if (!path) return nested;
219
+ const oldText = firstString(args, OLD_TEXT_FIELDS);
220
+ const newText = firstString(args, NEW_TEXT_FIELDS) ?? '';
221
+ if (!lineCount(newText) && !lineCount(oldText)) return nested;
222
+ return [{ path, oldText, newText }, ...nested];
223
+ }
224
+
225
+ /** Added/removed line counts for one call, or null when there is nothing to show. */
226
+ export function diffTotals(
227
+ block: ToolCallBlock | undefined,
228
+ args?: Record<string, unknown>,
229
+ name?: string,
230
+ ): { added: number; removed: number } | null {
231
+ const hunks = callDiffHunks(block, args, name);
232
+ if (!hunks.length) return null;
233
+ return diffLineTotals(hunks);
234
+ }
235
+
236
+ /** Counts the lines on each side, under the same rule the official block uses. */
237
+ export function diffLineTotals(hunks: readonly DiffHunk[]): { added: number; removed: number } {
238
+ return hunks.reduce((total, hunk) => ({
239
+ added: total.added + lineCount(hunk.newText),
240
+ removed: total.removed + lineCount(hunk.oldText),
241
+ }), { added: 0, removed: 0 });
242
+ }
243
+
244
+ /** Every changed file across a folded run of steps, in the order they ran. */
245
+ export function foldDiffHunks(steps: readonly { kind: string; entry?: ToolActivityEntry }[]): DiffHunk[] {
246
+ const hunks: DiffHunk[] = [];
247
+ for (const step of steps) {
248
+ if (step.kind !== 'tool' || !step.entry) continue;
249
+ const model = activitySummary(step.entry);
250
+ hunks.push(...callDiffHunks(step.entry.block, model.args, model.name));
251
+ }
252
+ return hunks;
253
+ }
254
+
255
+ export function activityPhase(entry: Pick<ToolActivityEntry, 'block' | 'draft'>, turnClosed = false): ToolPhase {
256
+ if (!entry.block) return turnClosed ? 'interrupted' : 'preparing';
257
+ if (!('kind' in entry.block)) return turnClosed ? 'interrupted' : 'running';
258
+ // RC1 publishes canonical cancellation as an error result with a typed code.
259
+ if (entry.block.error?.code === 'ABORTED' || entry.block.error?.code === 'interrupted') return 'interrupted';
260
+ const facts = executionFacts(entry.block);
261
+ if (entry.block.isError || facts.signal || (facts.exitCode !== undefined && facts.exitCode !== 0)
262
+ || entry.block.subCalls.some(block => activityPhase({ block }, turnClosed) === 'failed')) return 'failed';
263
+ if (facts.exitCode === 0) return 'succeeded';
264
+ return 'returned';
265
+ }
266
+
267
+ export function activitySummary(entry: Pick<ToolActivityEntry, 'block' | 'draft'>) {
268
+ const { name, raw } = toolIdentity(entry);
269
+ const args = inputFields(raw);
270
+ const target = stringValue(args, 'file_path', 'path', 'filename', 'filePath');
271
+ const command = stringValue(args, 'command', 'cmd', 'script');
272
+ const description = stringValue(args, 'description');
273
+ const file = target?.split(/[/\\]/).at(-1);
274
+ const category: ToolCategory = /^(write|edit|apply_patch|patch|str_replace_editor)$/.test(name) ? 'write'
275
+ : /^(read|read_file)$/.test(name) ? 'read'
276
+ : /^(bash|shell|terminal|terminal_send|exec_command|pwsh)$/.test(name) ? 'terminal'
277
+ : /^(grep|glob|find|search)$/.test(name) ? 'search'
278
+ : /^(web_search|web_fetch|web_open)$/.test(name) ? 'web'
279
+ // Code interpreters: no file, no shell, no query — the call is a program.
280
+ // Without this branch `run_code` fell through to `other`, which has no
281
+ // renderer of its own, so its result text was emitted as ordinary prose
282
+ // and stayed outside every fold.
283
+ : /^(run_code|execute_code|code_interpreter|python|node|eval|repl)$/.test(name) ? 'code'
284
+ : 'other';
285
+ const title = category === 'write' ? `${name === 'write' ? '写入' : '修改'}${file ? ` ${file}` : name === 'apply_patch' ? '代码补丁' : '文件'}`
286
+ : category === 'read' ? `读取${file ? ` ${file}` : '文件'}`
287
+ : category === 'terminal' ? description || '运行命令'
288
+ : category === 'search' ? name === 'glob' ? '查找文件' : '搜索内容'
289
+ : category === 'web' ? name === 'web_search' ? '搜索网页' : '读取网页'
290
+ : category === 'code' ? (description || '运行代码')
291
+ : name;
292
+ return { name, raw, args, category, title, target: target ?? command ?? stringValue(args, 'query', 'pattern', 'url'), command,
293
+ cwd: stringValue(args, 'workdir', 'cwd'), content: stringValue(args, 'content', 'new_string', 'newText', 'file_text') };
294
+ }
295
+
296
+ export function preparingLabel(name: string): string {
297
+ return /^(write|edit|apply_patch)$/.test(name) ? '正在生成文件内容' : /^(bash|shell|exec_command|pwsh)$/.test(name) ? '正在准备命令' : '正在准备工具输入';
298
+ }
@@ -0,0 +1,89 @@
1
+ import type { ImageAttachmentRef } from '@deepseek-ai/dsh-attachment';
2
+ import type { AssistantBlock, MessageImageLoader } from '@deepseek-ai/dsh-client-ui-conversation/client';
3
+ import type { MarkdownFileMentions } from '@deepseek-ai/dsh-client-ui-primitives';
4
+ import type { PropsLocale, PropsRenderSlots, PropsRuntime, PropsStore } from '@deepseek-ai/dsh-client-ui-slots';
5
+ import type {} from '@deepseek-ai/dsh-client-ui-chat/client';
6
+ import type {} from '@deepseek-ai/dsh-client-ui-conversation/client';
7
+ import type {} from '@deepseek-ai/dsh-client-ui-session/client';
8
+ import type { createReaderStore } from './store.js';
9
+ import type { OfficialSeat } from './official-slots.js';
10
+ import type { OpenFileOptions, TurnTailOwnerProps } from '@deepseek-ai/dsh-client-ui-chat/client';
11
+ import type {} from '@deepseek-ai/dsh-client-ui-tool/client';
12
+
13
+ export interface ReaderBlockOwner {
14
+ block: AssistantBlock;
15
+ streaming: boolean;
16
+ source: 'assistant' | 'user' | 'tool';
17
+ }
18
+
19
+ declare module '@deepseek-ai/dsh-client-ui-slots' {
20
+ interface SlotMap {
21
+ /** Trusted installed renderers may opt in; unknown model payloads never execute code. */
22
+ 'dsh-tidy-display.block': { kind: 'chain'; scope: 'session'; owner: ReaderBlockOwner };
23
+ }
24
+ }
25
+
26
+ export interface ReaderInjected {
27
+ loadOlder: () => Promise<void>;
28
+ loadImage: (attachment: ImageAttachmentRef) => Promise<{ data: Uint8Array; mediaType: string }>;
29
+ /**
30
+ * Writes text into this session's composer draft via the sanctioned
31
+ * conversation input face, with a DOM fallback. Returns true when the
32
+ * composer accepted the text.
33
+ */
34
+ fillComposer: (text: string) => boolean;
35
+ /** Open a workspace file or directory; mode comes from the Tidy Display setting. */
36
+ openFile: (path: string, options?: OpenFileOptions) => Promise<void> | void;
37
+ officialImageLoader: MessageImageLoader;
38
+ officialFileMentions: (owner: TurnTailOwnerProps) => MarkdownFileMentions | undefined;
39
+ officialPreviewFile: (path: string) => void;
40
+ officialHost: { getSnapshot: () => { home?: string }; subscribe: (listener: () => void) => () => void };
41
+ /** Root-scoped Tidy Display prefs (`dsh.reader.v1`), shared with Settings. */
42
+ openPrefs?: {
43
+ getSnapshot: () => {
44
+ deliverableOpenMode?: import('./open-file.js').DeliverableOpenMode;
45
+ frostedGlass?: boolean;
46
+ bubbles?: boolean;
47
+ foldIntensity?: import('./fold-intensity.js').FoldIntensity;
48
+ autoFold?: boolean;
49
+ processOnly?: boolean;
50
+ };
51
+ subscribe: (fn: () => void) => () => void;
52
+ actions?: {
53
+ setFoldIntensity?: (value: import('./fold-intensity.js').FoldIntensity) => void;
54
+ setAutoFold?: (value: boolean) => void;
55
+ setFrostedGlass?: (value: boolean) => void;
56
+ setBubbles?: (value: boolean) => void;
57
+ setDeliverableOpenMode?: (value: import('./open-file.js').DeliverableOpenMode) => void;
58
+ };
59
+ };
60
+ /** Reveal and highlight a workspace file in macOS Finder or Windows Explorer. */
61
+ revealFile?: (path: string) => Promise<void> | void;
62
+ /** Fork the conversation at a specific message sequence into a new branch session. */
63
+ forkAt?: (seq: number) => void;
64
+ /** Load session history through a target sequence number. */
65
+ loadThrough?: (seq: unknown) => Promise<void>;
66
+ }
67
+ export type ReaderProps = PropsRuntime<'conversation.view'>
68
+ & PropsLocale<'chat'>
69
+ & PropsRenderSlots<'dsh-tidy-display.block' | OfficialSeat>
70
+ & PropsStore<ReturnType<typeof createReaderStore>>
71
+ & ReaderInjected;
72
+ export type BlockRenderProps = Pick<ReaderProps, 'renderSlotChain' | 'loadImage' | 'fillComposer'> & {
73
+ official?: Pick<ReaderProps, 'renderSlot' | 'renderSlotChain' | 'officialImageLoader' | 'officialFileMentions' | 'officialPreviewFile' | 'officialHost' | 'openView'>;
74
+ cwd?: string;
75
+ openFile?: (path: string, options?: OpenFileOptions) => Promise<void> | void;
76
+ revealFile?: (path: string) => Promise<void> | void;
77
+ forkAt?: (seq: number) => void;
78
+ /** Durable closing-message seq of this turn (turn-tail closing), used as the fork anchor. */
79
+ forkSeq?: number;
80
+ fileMentions?: MarkdownFileMentions;
81
+ metrics?: {
82
+ usage?: NonNullable<import('@deepseek-ai/dsh-client-ui-chat/client').TurnTailChatData['tokenUsage']>;
83
+ runMs?: number;
84
+ tokensPerSecond?: number;
85
+ ttftMs?: number;
86
+ /** Closing assistant-message time (turn-tail `closing.time`). */
87
+ endedAt?: number;
88
+ };
89
+ };
@@ -0,0 +1,83 @@
1
+ import type { ChatNodeKind } from '@deepseek-ai/dsh-client-ui-chat/client';
2
+
3
+ export interface WaitingAnchor { key: string; time: number | null }
4
+ type InputNode = { kind: string; data: unknown };
5
+ type Submission = { requestId: string; time?: number; placement?: string };
6
+ const timestamp = (value: number | undefined): number | null => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
7
+
8
+ /**
9
+ * Chat-layer kinds that hand the turn back to the model unconditionally.
10
+ *
11
+ * These are `ChatNodeDataMap` keys, NOT conversation-layer `ConversationNode` kinds.
12
+ * The two layers name the same idea differently: a returned tool is `tool-result`
13
+ * in the conversation contract, but the row the reader sees is the `tool-call` node.
14
+ * A name copied from the wrong layer silently disables the branch it guards, so
15
+ * the `satisfies` below makes the compiler reject any name that is not a real kind.
16
+ */
17
+ export const WAIT_AFTER = new Set<ChatNodeKind>(['context', 'model-retry']);
18
+
19
+ /**
20
+ * Every chat-kind the handover logic reasons about, checked against the host's own
21
+ * kind union at compile time. Adding a name here that the host does not register
22
+ * fails `tsc` instead of failing silently at runtime.
23
+ */
24
+ export const HANDOVER_KINDS = [
25
+ 'user', 'steering', 'context', 'model-retry', 'tool-call', 'command',
26
+ ] as const satisfies readonly ChatNodeKind[];
27
+
28
+ /**
29
+ * Mirrors the host's `isSettledTool`: a running call has no `kind`, a settled one
30
+ * carries `kind: 'tool-result'`. Kept local so this module stays dependency-free,
31
+ * and pinned by a test against the host's own helper contract.
32
+ */
33
+ function toolSettled(data: unknown): boolean {
34
+ const root = (data as { root?: unknown } | undefined)?.root;
35
+ return typeof root === 'object' && root !== null && (root as { kind?: unknown }).kind === 'tool-result';
36
+ }
37
+
38
+ /** A command that is still executing has no outcome yet; only a settled one hands over. */
39
+ function commandSettled(data: unknown): boolean {
40
+ return (data as { outcome?: unknown } | undefined)?.outcome != null;
41
+ }
42
+
43
+ /**
44
+ * Does this node leave the model on the hook for the next move?
45
+ *
46
+ * A tool or command that is *still running* is not a wait — the tool is the one
47
+ * working. Only its returned form hands control back, which is exactly the moment
48
+ * the model can stall.
49
+ */
50
+ export function handsBackToModel(node: InputNode): boolean {
51
+ if (node.kind === 'user' || node.kind === 'steering') return true;
52
+ if (node.kind === 'tool-call') return toolSettled(node.data);
53
+ if (node.kind === 'command') return commandSettled(node.data);
54
+ return WAIT_AFTER.has(node.kind as ChatNodeKind);
55
+ }
56
+
57
+ /**
58
+ * The moment the current wait began.
59
+ *
60
+ * This is the time of the **last** node that handed control to the model — a
61
+ * returned tool, an injected context, or the user's own message. Anchoring on the
62
+ * user's message alone made the readout count the entire turn, so a wait that had
63
+ * only just begun showed the minutes the tools had already spent.
64
+ */
65
+ export function waitingAnchor(order: readonly string[], get: (key: string) => InputNode | undefined, pending: readonly Submission[] = []): WaitingAnchor {
66
+ let anchor: WaitingAnchor = { key: 'unresolved', time: null };
67
+ for (let i = order.length - 1; i >= 0; i--) {
68
+ const node = get(order[i]);
69
+ if (!node) continue;
70
+ if (!handsBackToModel(node)) continue;
71
+ const time = node.data && typeof node.data === 'object' && 'time' in node.data && typeof node.data.time === 'number' ? node.data.time : undefined;
72
+ anchor = { key: order[i], time: timestamp(time) };
73
+ break;
74
+ }
75
+ for (let i = pending.length - 1; i >= 0; i--) {
76
+ const input = pending[i];
77
+ if (input.placement === 'queued') continue;
78
+ const time = timestamp(input.time);
79
+ if (time === null || anchor.time === null || time >= anchor.time) return { key: `pending:${input.requestId}`, time };
80
+ break;
81
+ }
82
+ return anchor;
83
+ }
@@ -0,0 +1,92 @@
1
+ import { createContext, useContext, useLayoutEffect, useMemo, useRef } from 'react';
2
+ import type { ReactNode, RefObject } from 'react';
3
+ import type { MarkdownFileMentions } from '@deepseek-ai/dsh-client-ui-primitives';
4
+ import { MarkdownText } from './markdown/MarkdownText.js';
5
+ import { readerPathImages } from './platform-media.js';
6
+ import { WORD_MOTION, WordTimeline } from './word-timeline.js';
7
+ import css from './Reader.module.css';
8
+
9
+ const WordScope = createContext({ enabled: false, generation: 0 });
10
+ const CODE_LABELS = { copyLabel: '复制代码', copiedLabel: '已复制' };
11
+
12
+ function useSourceReveal(element: RefObject<HTMLElement>, born: number | null, generation: number) {
13
+ const scope = useContext(WordScope);
14
+ const cancelled = useRef(false);
15
+ useLayoutEffect(() => {
16
+ const target = element.current;
17
+ if (!target) return;
18
+ target.dataset.wordState = 'settled';
19
+ if (!scope.enabled || scope.generation !== generation) { cancelled.current = true; return; }
20
+ if (cancelled.current || born === null || document.hidden) return;
21
+ const age = Number(document.timeline.currentTime ?? performance.now()) - born;
22
+ if (age >= WORD_MOTION.duration || typeof target.animate !== 'function') return;
23
+ // The reference opacity + blur frames, applied only to this new word.
24
+ // No color interpolation, stylesheet mutation, or whole-paragraph wipe.
25
+ const animation = target.animate([
26
+ { opacity: 0, filter: `blur(${WORD_MOTION.blur}px)` },
27
+ { opacity: 1, filter: 'blur(0px)' },
28
+ ], { duration: WORD_MOTION.duration, easing: WORD_MOTION.easing, fill: 'backwards' });
29
+ // One absolute clock prevents newly mounted/resegmented leaves from getting
30
+ // a fresh delay or running ahead because their layout effects ran later.
31
+ animation.startTime = born;
32
+ target.dataset.wordState = 'resolving';
33
+ const finish = () => { animation.cancel(); target.dataset.wordState = 'settled'; document.removeEventListener('visibilitychange', hidden); };
34
+ animation.onfinish = finish;
35
+ const hidden = () => { if (document.hidden) { cancelled.current = true; finish(); } };
36
+ document.addEventListener('visibilitychange', hidden);
37
+ return () => { animation.cancel(); document.removeEventListener('visibilitychange', hidden); target.dataset.wordState = 'settled'; };
38
+ }, [element, born, generation, scope.enabled, scope.generation]);
39
+ }
40
+
41
+ function Word({ children, born, generation, offset, inline }: { children: string; born: number | null; generation: number; offset: number; inline: boolean }) {
42
+ const element = useRef<HTMLSpanElement>(null);
43
+ useSourceReveal(element, born, generation);
44
+ return <span ref={element} className={inline ? css.streamInlineWord : css.streamWord} data-reader-word data-source-start={offset} data-source-birth={born ?? undefined}>{children}</span>;
45
+ }
46
+
47
+ /** A native code block enters on the same clock, without rebuilding its text. */
48
+ function MotionAtom({ children, born, generation, offset }: { children: ReactNode; born: number | null; generation: number; offset: number }) {
49
+ const element = useRef<HTMLDivElement>(null);
50
+ useSourceReveal(element, born, generation);
51
+ return <div ref={element} className={css.streamAtom} data-reader-atom data-source-start={offset} data-source-birth={born ?? undefined}>{children}</div>;
52
+ }
53
+
54
+ /** Native Think is literal text, not Markdown. Spans never alter its bytes. */
55
+ export function MotionPlainText({ text, enabled, revision }: { text: string; enabled: boolean; revision: number }) {
56
+ const timeline = useRef<WordTimeline>();
57
+ timeline.current ??= new WordTimeline();
58
+ timeline.current.begin(text, enabled, revision, Number(document.timeline.currentTime ?? performance.now()));
59
+ const current = timeline.current;
60
+ const generation = current.generation;
61
+ const scope = useMemo(() => ({ enabled, generation }), [enabled, generation]);
62
+ return <WordScope.Provider value={scope}><div className={css.reasonPlain}>
63
+ {current.hasLiveText ? current.words(text, 0).map(word => word.text.trim()
64
+ ? <Word key={word.key} born={word.born} generation={generation} offset={word.key} inline>{word.text}</Word>
65
+ : word.text) : text}
66
+ </div></WordScope.Provider>;
67
+ }
68
+
69
+ /** Native DSH Markdown semantics with a stable text-leaf animation hook. */
70
+ export function MotionMarkdown({ text, streaming, enabled, revision, fileMentions }: {
71
+ text: string; streaming: boolean; enabled: boolean; revision: number; fileMentions?: MarkdownFileMentions;
72
+ }) {
73
+ const timeline = useRef<WordTimeline>();
74
+ timeline.current ??= new WordTimeline();
75
+ timeline.current.begin(text, enabled, revision, Number(document.timeline.currentTime ?? performance.now()));
76
+ const generation = timeline.current.generation;
77
+ const scope = useMemo(() => ({ enabled, generation }), [enabled, generation]);
78
+ const renderText = useMemo(() => (value: string, offset: number, inline = false): ReactNode => {
79
+ const current = timeline.current!;
80
+ if (!current.hasLiveText) return value;
81
+ return current.words(value, offset).map(word => word.text.trim()
82
+ ? <Word key={word.key} born={word.born} generation={current.generation} offset={word.key} inline={inline || /^\p{P}+$/u.test(word.text)}>{word.text}</Word>
83
+ : word.text);
84
+ }, []);
85
+ const renderAtom = useMemo(() => (children: ReactNode, offset: number): ReactNode => {
86
+ const current = timeline.current!;
87
+ return current.hasLiveText ? <MotionAtom born={current.bornAt(offset)} generation={current.generation} offset={offset}>{children}</MotionAtom> : children;
88
+ }, []);
89
+ return <WordScope.Provider value={scope}>
90
+ <MarkdownText text={text} streaming={streaming} codeLabels={CODE_LABELS} fileMentions={fileMentions} pathImages={readerPathImages} renderText={renderText} renderAtom={renderAtom} />
91
+ </WordScope.Provider>;
92
+ }