@waq666/pneuma 0.7.1 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (416) hide show
  1. package/README.md +242 -206
  2. package/bin/dsc.js +9 -3
  3. package/bin/headless.cjs +1 -1
  4. package/lib/adapter/transcript.d.ts +19 -2
  5. package/lib/adapter/transcript.js +71 -14
  6. package/lib/app/AgentsOverlay.js +7 -6
  7. package/lib/app/App.js +1 -1
  8. package/lib/app/ApprovalCard.js +15 -9
  9. package/lib/app/ChatView.d.ts +3 -1
  10. package/lib/app/ChatView.js +21 -17
  11. package/lib/app/Composer.js +22 -4
  12. package/lib/app/MarkdownView.js +2 -1
  13. package/lib/app/ModelPicker.js +7 -6
  14. package/lib/app/PickerFrame.d.ts +4 -0
  15. package/lib/app/PickerFrame.js +18 -0
  16. package/lib/app/PlanReviewCard.js +2 -1
  17. package/lib/app/PresetPicker.js +8 -7
  18. package/lib/app/SessionPicker.js +21 -20
  19. package/lib/app/SettingsOverlay.js +1 -1
  20. package/lib/app/SkillsPicker.js +7 -6
  21. package/lib/app/StatusBar.js +3 -15
  22. package/lib/app/TaskStrips.js +1 -4
  23. package/lib/app/TimelineRail.js +2 -1
  24. package/lib/app/ToolCard.js +2 -6
  25. package/lib/app/Welcome.d.ts +1 -0
  26. package/lib/app/Welcome.js +1 -4
  27. package/lib/app/click.d.ts +0 -2
  28. package/lib/app/click.js +2 -21
  29. package/lib/app/display-width.d.ts +16 -0
  30. package/lib/app/display-width.js +33 -0
  31. package/lib/app/markdown.d.ts +1 -3
  32. package/lib/app/markdown.js +2 -19
  33. package/lib/app/scroll-model.js +1 -1
  34. package/lib/contract/approval.d.ts +91 -0
  35. package/lib/contract/approval.js +1 -0
  36. package/lib/contract/mode.d.ts +69 -0
  37. package/lib/contract/mode.js +1 -0
  38. package/lib/contract/plugin.d.ts +240 -0
  39. package/lib/contract/plugin.js +1 -0
  40. package/lib/contract/runtime.d.ts +282 -0
  41. package/lib/contract/runtime.js +1 -0
  42. package/lib/contract/session.d.ts +208 -0
  43. package/lib/contract/session.js +36 -0
  44. package/lib/contract/settings.d.ts +242 -0
  45. package/lib/contract/settings.js +1 -0
  46. package/lib/contract/snapshot.d.ts +453 -0
  47. package/lib/contract/snapshot.js +1 -0
  48. package/lib/contract/task.d.ts +189 -0
  49. package/lib/contract/task.js +10 -0
  50. package/lib/contract/transcript.d.ts +358 -0
  51. package/lib/contract/transcript.js +1 -0
  52. package/lib/contract/usage.d.ts +132 -0
  53. package/lib/contract/usage.js +10 -0
  54. package/lib/contract.d.ts +20 -1968
  55. package/lib/contract.js +19 -30
  56. package/lib/core/agent-roles.d.ts +1 -1
  57. package/lib/core/agent-roles.js +6 -5
  58. package/lib/core/approval-floor.d.ts +9 -0
  59. package/lib/core/approval-floor.js +152 -25
  60. package/lib/core/attachments.d.ts +185 -0
  61. package/lib/core/attachments.js +425 -0
  62. package/lib/core/bytes.d.ts +14 -0
  63. package/lib/core/bytes.js +28 -0
  64. package/lib/core/call-meaning.d.ts +20 -0
  65. package/lib/core/call-meaning.js +347 -0
  66. package/lib/core/cdp/actions.js +6 -0
  67. package/lib/core/cdp/launch.js +2 -2
  68. package/lib/core/cdp/report.d.ts +27 -0
  69. package/lib/core/cdp/report.js +50 -0
  70. package/lib/core/cdp/ring-buffer.d.ts +25 -0
  71. package/lib/core/cdp/ring-buffer.js +44 -0
  72. package/lib/core/cdp/snapshot.js +5 -9
  73. package/lib/core/cdp/transport.js +1 -1
  74. package/lib/core/clamp.d.ts +20 -0
  75. package/lib/core/clamp.js +24 -0
  76. package/lib/core/clock.d.ts +16 -0
  77. package/lib/core/clock.js +20 -0
  78. package/lib/core/command-policy.js +33 -1
  79. package/lib/core/commands-completion.d.ts +28 -0
  80. package/lib/core/commands-completion.js +108 -30
  81. package/lib/core/compact.d.ts +36 -6
  82. package/lib/core/compact.js +89 -17
  83. package/lib/core/desktop-control.js +1 -3
  84. package/lib/core/dsh-compat/llm-usage-event.d.ts +78 -0
  85. package/lib/core/dsh-compat/llm-usage-event.js +91 -0
  86. package/lib/core/dsh-compat/presentation.d.ts +84 -0
  87. package/lib/core/dsh-compat/presentation.js +105 -0
  88. package/lib/core/dsh-compat/resolve-hook.d.ts +3 -3
  89. package/lib/core/dsh-compat/resolve-hook.js +41 -13
  90. package/lib/core/dsh-compat/service-map.d.ts +52 -0
  91. package/lib/core/dsh-compat/service-map.js +87 -0
  92. package/lib/core/dsh-compat/session-bridge.d.ts +107 -0
  93. package/lib/core/dsh-compat/session-bridge.js +376 -0
  94. package/lib/core/dsh-compat/session-events.d.ts +54 -0
  95. package/lib/core/dsh-compat/session-events.js +297 -0
  96. package/lib/core/dsh-compat/shims/credentials.d.ts +62 -0
  97. package/lib/core/dsh-compat/shims/credentials.js +86 -0
  98. package/lib/core/dsh-compat/shims/home-paths.d.ts +77 -0
  99. package/lib/core/dsh-compat/shims/home-paths.js +143 -0
  100. package/lib/core/dsh-compat/tools-facade.d.ts +31 -1
  101. package/lib/core/dsh-compat/tools-facade.js +207 -3
  102. package/lib/core/err-text.d.ts +5 -0
  103. package/lib/core/err-text.js +5 -0
  104. package/lib/core/events.d.ts +31 -2
  105. package/lib/core/git-info.d.ts +127 -15
  106. package/lib/core/git-info.js +315 -34
  107. package/lib/core/git-surface.d.ts +17 -0
  108. package/lib/core/git-surface.js +7 -0
  109. package/lib/core/hooks.d.ts +19 -2
  110. package/lib/core/hooks.js +57 -13
  111. package/lib/core/host-methods.d.ts +1 -1
  112. package/lib/core/host-methods.js +4 -0
  113. package/lib/core/image-diet.js +1 -4
  114. package/lib/core/json-text.d.ts +11 -0
  115. package/lib/core/json-text.js +18 -0
  116. package/lib/core/learnings/skill-write.d.ts +1 -7
  117. package/lib/core/learnings/skill-write.js +3 -37
  118. package/lib/core/lifecycle-hooks.d.ts +11 -3
  119. package/lib/core/lifecycle-hooks.js +33 -42
  120. package/lib/core/llm.d.ts +42 -0
  121. package/lib/core/llm.js +40 -25
  122. package/lib/core/loop.d.ts +11 -1
  123. package/lib/core/loop.js +95 -28
  124. package/lib/core/lsp/client.js +30 -17
  125. package/lib/core/lsp/normalize.d.ts +0 -2
  126. package/lib/core/lsp/normalize.js +1 -6
  127. package/lib/core/lsp/servers.js +1 -4
  128. package/lib/core/mcp.d.ts +18 -0
  129. package/lib/core/mcp.js +60 -16
  130. package/lib/core/microcompact.d.ts +45 -0
  131. package/lib/core/microcompact.js +128 -0
  132. package/lib/core/native-bridge.js +2 -10
  133. package/lib/core/path-policy.d.ts +13 -1
  134. package/lib/core/path-policy.js +87 -18
  135. package/lib/core/permission-presets.d.ts +9 -5
  136. package/lib/core/permission-presets.js +14 -7
  137. package/lib/core/permission-scope.d.ts +65 -0
  138. package/lib/core/permission-scope.js +109 -0
  139. package/lib/core/plugin-bundle.d.ts +95 -0
  140. package/lib/core/plugin-bundle.js +137 -0
  141. package/lib/core/plugin-loader.d.ts +36 -1
  142. package/lib/core/plugin-loader.js +336 -12
  143. package/lib/core/plugin-patch.d.ts +64 -0
  144. package/lib/core/plugin-patch.js +146 -0
  145. package/lib/core/plugin-registry.d.ts +14 -0
  146. package/lib/core/plugin-registry.js +2 -0
  147. package/lib/core/prefs.js +40 -2
  148. package/lib/core/presets.d.ts +11 -0
  149. package/lib/core/presets.js +61 -22
  150. package/lib/core/profile-dir.d.ts +5 -0
  151. package/lib/core/profile-dir.js +40 -0
  152. package/lib/core/prompt.js +55 -19
  153. package/lib/core/ptc.d.ts +8 -2
  154. package/lib/core/ptc.js +18 -4
  155. package/lib/core/records.d.ts +16 -0
  156. package/lib/core/records.js +22 -0
  157. package/lib/core/remote/notify.js +1 -3
  158. package/lib/core/remote/push.js +2 -6
  159. package/lib/core/sandbox/execpolicy.js +27 -3
  160. package/lib/core/sandbox/net-proxy.js +2 -2
  161. package/lib/core/sandbox/policy.d.ts +1 -1
  162. package/lib/core/sandbox/policy.js +21 -15
  163. package/lib/core/sandbox/win/account.js +1 -4
  164. package/lib/core/sandbox/win/acl.js +1 -6
  165. package/lib/core/sandbox/win/backend.d.ts +24 -3
  166. package/lib/core/sandbox/win/backend.js +73 -23
  167. package/lib/core/sandbox/win/doctor.js +1 -4
  168. package/lib/core/sandbox/win/runner-entry.js +1 -6
  169. package/lib/core/sandbox/win/setup.js +1 -4
  170. package/lib/core/sandbox/win/utf16.d.ts +11 -0
  171. package/lib/core/sandbox/win/utf16.js +15 -0
  172. package/lib/core/sandbox/win/wfp.js +1 -4
  173. package/lib/core/schedule/rule.d.ts +0 -17
  174. package/lib/core/schedule/rule.js +1 -3
  175. package/lib/core/schedule/runner.d.ts +5 -2
  176. package/lib/core/schedule/runner.js +32 -9
  177. package/lib/core/schedule/store.d.ts +0 -2
  178. package/lib/core/schedule/store.js +2 -9
  179. package/lib/core/session-index.d.ts +50 -0
  180. package/lib/core/session-index.js +169 -3
  181. package/lib/core/session.d.ts +89 -13
  182. package/lib/core/session.js +385 -32
  183. package/lib/core/shell-quote.d.ts +21 -0
  184. package/lib/core/shell-quote.js +24 -0
  185. package/lib/core/side-ask.d.ts +52 -0
  186. package/lib/core/side-ask.js +89 -0
  187. package/lib/core/skills.d.ts +16 -0
  188. package/lib/core/skills.js +45 -8
  189. package/lib/core/snapshot-throttle.d.ts +8 -0
  190. package/lib/core/snapshot-throttle.js +24 -0
  191. package/lib/core/spill.d.ts +11 -5
  192. package/lib/core/spill.js +35 -36
  193. package/lib/core/strings.d.ts +21 -0
  194. package/lib/core/strings.js +33 -0
  195. package/lib/core/terminal-env.d.ts +61 -0
  196. package/lib/core/terminal-env.js +327 -0
  197. package/lib/core/text-format.d.ts +17 -0
  198. package/lib/core/text-format.js +26 -0
  199. package/lib/core/todo-reminder.d.ts +19 -14
  200. package/lib/core/todo-reminder.js +14 -23
  201. package/lib/core/token-estimate.d.ts +18 -2
  202. package/lib/core/token-estimate.js +10 -2
  203. package/lib/core/tool-result-prune.d.ts +42 -0
  204. package/lib/core/tool-result-prune.js +47 -0
  205. package/lib/core/tool-search.d.ts +3 -2
  206. package/lib/core/tool-search.js +3 -2
  207. package/lib/core/tools/bash.d.ts +35 -3
  208. package/lib/core/tools/bash.js +168 -41
  209. package/lib/core/tools/fs-tools.js +18 -17
  210. package/lib/core/tools/image-tool.d.ts +2 -0
  211. package/lib/core/tools/image-tool.js +59 -0
  212. package/lib/core/tools/path-args.d.ts +4 -0
  213. package/lib/core/tools/path-args.js +22 -0
  214. package/lib/core/tools/search-tools.d.ts +30 -0
  215. package/lib/core/tools/search-tools.js +321 -34
  216. package/lib/core/tools.d.ts +82 -0
  217. package/lib/core/tools.js +21 -0
  218. package/lib/core/transcript-text.d.ts +19 -0
  219. package/lib/core/transcript-text.js +44 -0
  220. package/lib/core/ui-boot-source.d.ts +5 -0
  221. package/lib/core/ui-boot-source.js +10 -3
  222. package/lib/core/ui-bundles.d.ts +80 -6
  223. package/lib/core/ui-bundles.js +700 -76
  224. package/lib/core/ui-events.d.ts +10 -0
  225. package/lib/core/ui-events.js +25 -0
  226. package/lib/core/ui-methods.d.ts +1 -1
  227. package/lib/core/ui-methods.js +42 -13
  228. package/lib/core/ui-route.js +11 -7
  229. package/lib/core/ui-server.d.ts +6 -0
  230. package/lib/core/ui-server.js +106 -1
  231. package/lib/core/unified-diff.d.ts +35 -0
  232. package/lib/core/unified-diff.js +86 -0
  233. package/lib/core/usage-log.js +39 -0
  234. package/lib/core/web-http.d.ts +1 -1
  235. package/lib/core/web-http.js +1 -3
  236. package/lib/host/kernel.js +57 -41
  237. package/lib/plugins/agent.js +101 -20
  238. package/lib/plugins/approval-floor.js +12 -8
  239. package/lib/plugins/approval.js +252 -80
  240. package/lib/plugins/ask.js +60 -8
  241. package/lib/plugins/browser.js +32 -84
  242. package/lib/plugins/commands.js +167 -57
  243. package/lib/plugins/compact.d.ts +2 -2
  244. package/lib/plugins/compact.js +200 -30
  245. package/lib/plugins/computer-use.js +34 -18
  246. package/lib/plugins/dock-browser.js +24 -65
  247. package/lib/plugins/dsh-compat.js +7 -0
  248. package/lib/plugins/file-review.js +59 -15
  249. package/lib/plugins/git.js +16 -8
  250. package/lib/plugins/goal.js +9 -8
  251. package/lib/plugins/hooks.js +4 -2
  252. package/lib/plugins/host-stdio.js +14 -16
  253. package/lib/plugins/lifecycle-hooks.d.ts +5 -4
  254. package/lib/plugins/lifecycle-hooks.js +12 -10
  255. package/lib/plugins/llm.js +74 -33
  256. package/lib/plugins/lsp.js +22 -27
  257. package/lib/plugins/mcp.js +16 -17
  258. package/lib/plugins/memory.js +3 -24
  259. package/lib/plugins/microcompact.d.ts +4 -1
  260. package/lib/plugins/microcompact.js +117 -19
  261. package/lib/plugins/mode.js +30 -11
  262. package/lib/plugins/permission-presets.d.ts +2 -1
  263. package/lib/plugins/permission-presets.js +55 -35
  264. package/lib/plugins/plugin-manager.js +4 -6
  265. package/lib/plugins/presets.js +56 -27
  266. package/lib/plugins/prompt.js +54 -11
  267. package/lib/plugins/ptc.d.ts +13 -0
  268. package/lib/plugins/ptc.js +121 -24
  269. package/lib/plugins/remote/types.d.ts +1 -1
  270. package/lib/plugins/remote/types.js +11 -0
  271. package/lib/plugins/remote.js +14 -15
  272. package/lib/plugins/runtime.js +91 -14
  273. package/lib/plugins/sandbox.js +181 -60
  274. package/lib/plugins/schedule.js +12 -11
  275. package/lib/plugins/self-improve.js +28 -18
  276. package/lib/plugins/session-search.js +18 -13
  277. package/lib/plugins/session-title.js +1 -1
  278. package/lib/plugins/session.js +103 -25
  279. package/lib/plugins/settings.js +16 -40
  280. package/lib/plugins/skills.js +18 -1
  281. package/lib/plugins/spill.js +18 -11
  282. package/lib/plugins/subagent.js +208 -42
  283. package/lib/plugins/team.js +11 -5
  284. package/lib/plugins/todo.d.ts +1 -1
  285. package/lib/plugins/todo.js +25 -19
  286. package/lib/plugins/tool-search.js +47 -28
  287. package/lib/plugins/tools-default.js +89 -5
  288. package/lib/plugins/tools.js +3 -3
  289. package/lib/plugins/transcript.js +116 -9
  290. package/lib/plugins/web-search.d.ts +1 -1
  291. package/lib/plugins/web-search.js +25 -16
  292. package/lib/plugins/webserver.js +40 -7
  293. package/lib/remote/assets/app-B3Id1EBq.js +14 -0
  294. package/lib/remote/assets/index.html +2 -2
  295. package/lib/remote/assets/{style-DIB6729x.css → style-NtlpbKOI.css} +1 -1
  296. package/lib/services/types.d.ts +247 -29
  297. package/lib/tools/plugin-cli.d.ts +1 -0
  298. package/lib/tools/plugin-cli.js +209 -0
  299. package/lib/ui/assets/app-B-Jx5dnh.js +90 -0
  300. package/lib/ui/assets/{chunk-BajyYBss.js → chunk-Bfdlo8Me.js} +1 -1
  301. package/lib/ui/assets/chunk-DGX-i4eb.js +12 -0
  302. package/lib/ui/assets/index.html +62 -14
  303. package/lib/ui/assets/style-WzxwEPaE.css +1 -0
  304. package/lib/ui/frames.js +1 -3
  305. package/lib/ui/index.d.ts +30 -1
  306. package/lib/ui/index.js +29 -0
  307. package/lib/ui/manifest.d.ts +24 -6
  308. package/lib/ui/manifest.js +3 -2
  309. package/lib/ui/plugins/actions/bundle.json +8 -0
  310. package/lib/ui/plugins/actions/client.js +43 -0
  311. package/lib/ui/plugins/ask/bundle.json +8 -0
  312. package/lib/ui/plugins/ask/client.js +415 -0
  313. package/lib/ui/plugins/browser/bundle.json +8 -0
  314. package/lib/ui/plugins/composer/bundle.json +9 -0
  315. package/lib/ui/plugins/composer/client.js +1806 -1087
  316. package/lib/ui/plugins/files/bundle.json +8 -0
  317. package/lib/ui/plugins/files/client.js +13 -98
  318. package/lib/ui/plugins/manifest.json +1 -104
  319. package/lib/ui/plugins/palette/bundle.json +8 -0
  320. package/lib/ui/plugins/palette/client.js +360 -0
  321. package/lib/ui/plugins/plugins/bundle.json +8 -0
  322. package/lib/ui/plugins/plugins/client.js +116 -38
  323. package/lib/ui/plugins/preview/bundle.json +8 -0
  324. package/lib/ui/plugins/preview/client.js +6 -16
  325. package/lib/ui/plugins/prompt/bundle.json +8 -0
  326. package/lib/ui/plugins/prompt/client.js +81 -47
  327. package/lib/ui/plugins/sessions/bundle.json +8 -0
  328. package/lib/ui/plugins/sessions/client.js +157 -111
  329. package/lib/ui/plugins/settings/bundle.json +8 -0
  330. package/lib/ui/plugins/settings/client.js +184 -170
  331. package/lib/ui/plugins/skills/bundle.json +8 -0
  332. package/lib/ui/plugins/skills/client.js +161 -79
  333. package/lib/ui/plugins/status/bundle.json +8 -0
  334. package/lib/ui/plugins/status/client.js +165 -26
  335. package/lib/ui/plugins/statusbar/bundle.json +9 -0
  336. package/lib/ui/plugins/statusbar/client.js +100 -144
  337. package/lib/ui/plugins/tasks/bundle.json +8 -0
  338. package/lib/ui/plugins/team/bundle.json +8 -0
  339. package/lib/ui/plugins/team/client.js +60 -58
  340. package/lib/ui/plugins/terminal/bundle.json +8 -0
  341. package/lib/ui/plugins/terminal/client.js +1 -7
  342. package/lib/ui/plugins/trace/bundle.json +11 -0
  343. package/lib/ui/plugins/trace/client.js +86 -179
  344. package/lib/ui/plugins/transcript/bundle.json +8 -0
  345. package/lib/ui/plugins/transcript/client.js +1608 -1243
  346. package/lib/ui/sdk/@dsc/ui/index.d.ts +54 -16
  347. package/lib/ui/sdk/@dsc/ui/package.json +1 -1
  348. package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +20 -1968
  349. package/lib/ui/sdk/@dsc/ui-core/core/attachments.d.ts +185 -0
  350. package/lib/ui/sdk/@dsc/ui-core/core/bytes.d.ts +14 -0
  351. package/lib/ui/sdk/@dsc/ui-core/core/err-text.d.ts +18 -0
  352. package/lib/ui/sdk/@dsc/ui-core/core/git-surface.d.ts +17 -0
  353. package/lib/ui/sdk/@dsc/ui-core/core/json-text.d.ts +11 -0
  354. package/lib/ui/sdk/@dsc/ui-core/core/path-policy.d.ts +44 -0
  355. package/lib/ui/sdk/@dsc/ui-core/core/records.d.ts +16 -0
  356. package/lib/ui/sdk/@dsc/ui-core/core/throughput.d.ts +46 -0
  357. package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +18 -2
  358. package/lib/ui/sdk/@dsc/ui-core/core/unified-diff.d.ts +35 -0
  359. package/lib/ui/sdk/@dsc/ui-core/package.json +1 -1
  360. package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +30 -1
  361. package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +24 -6
  362. package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +19 -8
  363. package/lib/ui/sdk/@dsc/ui-core/ui/signal.d.ts +49 -0
  364. package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +17 -3
  365. package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +1 -1
  366. package/lib/ui/sdk/@dsc/ui-dockkit/package.json +1 -1
  367. package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +4 -0
  368. package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +6 -1
  369. package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +21 -0
  370. package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +1 -0
  371. package/lib/ui/sdk/@dsc/ui-layout/package.json +1 -1
  372. package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +1 -1
  373. package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +10 -1
  374. package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +1 -1
  375. package/lib/ui/sdk/@dsc/ui-layout/usage-today.d.ts +11 -0
  376. package/lib/ui/sdk/@dsc/ui-primitives/dialog-focus.d.ts +30 -0
  377. package/lib/ui/sdk/@dsc/ui-primitives/error-text.d.ts +12 -0
  378. package/lib/ui/sdk/@dsc/ui-primitives/git-surface.d.ts +9 -0
  379. package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +23 -0
  380. package/lib/ui/sdk/@dsc/ui-primitives/humanize-error.d.ts +35 -0
  381. package/lib/ui/sdk/@dsc/ui-primitives/icons-workspace.d.ts +33 -0
  382. package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +21 -3
  383. package/lib/ui/sdk/@dsc/ui-primitives/image-lightbox.d.ts +21 -0
  384. package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +16 -0
  385. package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +10 -14
  386. package/lib/ui/sdk/@dsc/ui-primitives/package.json +1 -1
  387. package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +31 -8
  388. package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +2 -0
  389. package/lib/ui/sdk/@dsc/ui-primitives/review-findings-card.d.ts +25 -0
  390. package/lib/ui/sdk/@dsc/ui-primitives/review-findings.d.ts +64 -0
  391. package/lib/ui/sdk/@dsc/ui-primitives/review-notice-card.d.ts +27 -0
  392. package/lib/ui/sdk/@dsc/ui-primitives/review-notice.d.ts +80 -0
  393. package/lib/ui/sdk/@dsc/ui-primitives/signal.d.ts +9 -0
  394. package/lib/ui/sdk/@dsc/ui-primitives/sizes.d.ts +15 -0
  395. package/lib/ui/sdk/@dsc/ui-primitives/skeleton.d.ts +39 -0
  396. package/lib/ui/sdk/@dsc/ui-primitives/snapshot.d.ts +46 -0
  397. package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +3 -3
  398. package/lib/ui/sdk/@dsc/ui-primitives/throughput.d.ts +13 -0
  399. package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +9 -0
  400. package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +1 -1
  401. package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +30 -6
  402. package/lib/ui/sdk/@dsc/ui-primitives/unified-diff.d.ts +10 -0
  403. package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +10 -1
  404. package/lib/ui/sdk/@dsc/ui-renderer/cordis-host.d.ts +113 -0
  405. package/lib/ui/sdk/@dsc/ui-renderer/package.json +1 -1
  406. package/lib/ui/sdk/@dsc/ui-slots/package.json +1 -1
  407. package/lib/ui/services.d.ts +19 -8
  408. package/lib/ui/services.js +20 -12
  409. package/lib/ui/signal.d.ts +49 -0
  410. package/lib/ui/signal.js +57 -0
  411. package/lib/ui/tui-plugins.js +36 -16
  412. package/package.json +71 -58
  413. package/lib/remote/assets/app-DAcUCOEn.js +0 -14
  414. package/lib/ui/assets/app-B70nVIKd.js +0 -69
  415. package/lib/ui/assets/chunk-BGcgwlCI.js +0 -12
  416. package/lib/ui/assets/style-Bq01xH_b.css +0 -1
@@ -0,0 +1,425 @@
1
+ /**
2
+ * 附件仓库:把用户贴进来的图片、视频与其它文件存成本机对象,消息里只留引用。
3
+ *
4
+ * ## 为什么不再往消息里塞 base64
5
+ *
6
+ * 原来界面把图片压成 data URL,经 `/api/invoke` 的 64KB 请求体塞进 `submit` 的第二参
7
+ * (`core/web-http.ts` 的 `MAX_BODY_BYTES`),所以单图只能有 32KB——普通截图压到那个
8
+ * 档位已经看不清了(这正是「贴图这一版还不支持」的根因)。会话 jsonl 也把 base64 原样
9
+ * 写进去,一个会话文件会膨胀到几十 MB。
10
+ *
11
+ * 现在照 dsh `dsh-attachment-local` 的做法拆成两步:
12
+ *
13
+ * 1. 字节先经 `POST /api/attachments` 落到这里,内容寻址(sha256),同字节只存一份;
14
+ * 2. 消息里带引用 `/api/attachments/<sha>`,**组装模型请求时**再读成 data URL。
15
+ *
16
+ * 于是请求体只装几个短引用,会话日志也只记引用;界面 `<img>` / `<video>` 直接吃同源
17
+ * 路由,不必再传 base64。
18
+ *
19
+ * ## 与 dsh 的口径对齐与差异
20
+ *
21
+ * 对齐:目录形状 `<DSC_HOME>/attachments/v1/objects/<sha 前 2 位>/<sha>`、内容寻址去重、
22
+ * 只收 PNG / JPEG / WebP / GIF 四类图片、非图片文件按字节原样存、单图 20MiB。
23
+ *
24
+ * 差异:dsh 在服务端用 sharp 做像素级规范化(EXIF、色彩空间、长边、质量阶梯)。本仓库
25
+ * 没有原生图像依赖,**规范化放在界面层**(`ui-shell/src/plugins/composer/attachments.ts`
26
+ * 用 canvas 做同样的事),落到这里的已经是 8-bit sRGB 光栅。所以这里的校验只看字节与
27
+ * 魔数:信不信扩展名/`Content-Type` 一律不信。
28
+ *
29
+ * ## 安全边界
30
+ *
31
+ * - sha 只认 64 位小写十六进制,路径拼接不接用户输入;
32
+ * - 文件名只用于展示,落盘名永远是 sha;
33
+ * - 单文件上限按类别分开(图片 20MiB、视频与其它文件 200MiB),上限在**写入过程中**
34
+ * 就生效,不会先写满盘再判;
35
+ * - 读取前校验对象仍是普通文件,长度与摘要由调用方(会话投影)自行决定要不要复核。
36
+ *
37
+ * @module dsc/core/attachments
38
+ */
39
+ import { createHash, randomBytes } from 'node:crypto';
40
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
41
+ import { open, rm, stat } from 'node:fs/promises';
42
+ import { extname, join } from 'node:path';
43
+ import { formatBytes } from './bytes.js';
44
+ import { dscPath } from './path-policy.js';
45
+ /** 单张图片上限(与 dsh `maxImageBytes` 的默认值一致)。 */
46
+ export const MAX_IMAGE_BYTES = 20 * 1024 * 1024;
47
+ /** 单个视频 / 其它文件上限。比 dsh 的「通用文件不设限」保守,理由是本机磁盘不是仓库。 */
48
+ export const MAX_MEDIA_BYTES = 200 * 1024 * 1024;
49
+ /** 一条消息最多带多少张图片(dsh 默认 20;这里按请求体与上下文成本收到 20)。 */
50
+ export const MAX_IMAGES_PER_MESSAGE = 20;
51
+ /** 落盘失败(上限 / 空文件 / 写盘错误)。 */
52
+ export class AttachmentError extends Error {
53
+ constructor(message) {
54
+ super(message);
55
+ this.name = 'AttachmentError';
56
+ }
57
+ }
58
+ /** 读文件头用的字节数:视频的 ftyp 在前 16 字节内,再留一点余量。 */
59
+ const HEAD_BYTES = 64;
60
+ /**
61
+ * 按文件头认类型。
62
+ *
63
+ * 只认常见、能给模型或播放器直接用的格式;认不出的按 `file` 原样存(模型拿路径自己看)。
64
+ * 图片四类与 dsh 一致:PNG / JPEG / WebP / GIF。
65
+ */
66
+ export function sniffMedia(head) {
67
+ if (head.length >= 8
68
+ && head[0] === 0x89 && head[1] === 0x50 && head[2] === 0x4e && head[3] === 0x47
69
+ && head[4] === 0x0d && head[5] === 0x0a && head[6] === 0x1a && head[7] === 0x0a) {
70
+ return { kind: 'image', mime: 'image/png' };
71
+ }
72
+ if (head.length >= 3 && head[0] === 0xff && head[1] === 0xd8 && head[2] === 0xff) {
73
+ return { kind: 'image', mime: 'image/jpeg' };
74
+ }
75
+ if (head.length >= 6) {
76
+ const gif = head.subarray(0, 6).toString('ascii');
77
+ if (gif === 'GIF87a' || gif === 'GIF89a')
78
+ return { kind: 'image', mime: 'image/gif' };
79
+ }
80
+ if (head.length >= 12 && head.subarray(0, 4).toString('ascii') === 'RIFF') {
81
+ const form = head.subarray(8, 12).toString('ascii');
82
+ if (form === 'WEBP')
83
+ return { kind: 'image', mime: 'image/webp' };
84
+ if (form === 'AVI ')
85
+ return { kind: 'video', mime: 'video/x-msvideo' };
86
+ }
87
+ // MP4 / MOV / M4V:`ftyp` 在偏移 4,品牌在偏移 8。
88
+ if (head.length >= 12 && head.subarray(4, 8).toString('ascii') === 'ftyp') {
89
+ const brand = head.subarray(8, 12).toString('ascii');
90
+ if (brand === 'qt ')
91
+ return { kind: 'video', mime: 'video/quicktime' };
92
+ if (brand === 'M4V ' || brand === 'M4VH' || brand === 'M4VP')
93
+ return { kind: 'video', mime: 'video/x-m4v' };
94
+ return { kind: 'video', mime: 'video/mp4' };
95
+ }
96
+ // Matroska / WebM 的 EBML 头;不再细分容器(浏览器按实际编码解)。
97
+ if (head.length >= 4 && head[0] === 0x1a && head[1] === 0x45 && head[2] === 0xdf && head[3] === 0xa3) {
98
+ return { kind: 'video', mime: 'video/webm' };
99
+ }
100
+ return { kind: 'file', mime: 'application/octet-stream' };
101
+ }
102
+ /** 按魔数结果判断一个对象是不是可渲染图片。 */
103
+ export function isImageMime(mime) {
104
+ return mime === 'image/png' || mime === 'image/jpeg' || mime === 'image/webp' || mime === 'image/gif';
105
+ }
106
+ /** 类别对应的单文件上限。 */
107
+ export function limitFor(kind) {
108
+ return kind === 'image' ? MAX_IMAGE_BYTES : MAX_MEDIA_BYTES;
109
+ }
110
+ /** sha 的合法形状:64 位小写十六进制。 */
111
+ const SHA = /^[0-9a-f]{64}$/;
112
+ /** 把原始文件名洗成可展示的一段(只展示,不参与落盘路径)。 */
113
+ export function displayName(raw) {
114
+ const last = raw.split(/[/\\]/).pop() ?? '';
115
+ const cleaned = last
116
+ .replace(/[\u0000-\u001f\u007f]/g, '')
117
+ .replace(/[<>:"|?*]/g, '')
118
+ .trim()
119
+ .slice(0, 120);
120
+ return cleaned === '' ? 'attachment' : cleaned;
121
+ }
122
+ /** 附件在界面通道里的读取地址。 */
123
+ export function attachmentUrl(sha, name) {
124
+ return name === undefined || name === ''
125
+ ? `/api/attachments/${sha}`
126
+ : `/api/attachments/${sha}?name=${encodeURIComponent(name)}`;
127
+ }
128
+ /** 从任意字符串里认出附件引用;不是引用就回 null。 */
129
+ export function parseAttachmentUrl(value) {
130
+ const match = /^\/api\/attachments\/([0-9a-f]{64})(?:\?|$)/.exec(value);
131
+ return match === null ? null : match[1];
132
+ }
133
+ /**
134
+ * 内容寻址附件仓库。
135
+ *
136
+ * 目录形状:`<root>/objects/<sha 前两位>/<sha>`,临时文件在 `<root>/tmp/`。
137
+ * 同一个字节序列落两次是同一个对象(第二次直接复用,不重写)。
138
+ */
139
+ export class AttachmentStore {
140
+ root;
141
+ constructor(options = {}) {
142
+ this.root = options.root ?? dscPath('attachments', 'v1');
143
+ }
144
+ /** 仓库根目录。 */
145
+ get dir() {
146
+ return this.root;
147
+ }
148
+ /** 对象的绝对路径(只接受合法 sha,别的一律抛)。 */
149
+ pathOf(sha) {
150
+ if (!SHA.test(sha))
151
+ throw new AttachmentError(`附件 id 不合法:${sha}`);
152
+ return join(this.root, 'objects', sha.slice(0, 2), sha);
153
+ }
154
+ /** 对象是否已经在仓库里。 */
155
+ has(sha) {
156
+ try {
157
+ return statSync(this.pathOf(sha)).isFile();
158
+ }
159
+ catch {
160
+ return false;
161
+ }
162
+ }
163
+ /** 落盘一段已知字节(浏览器上传的小文件、自检都走这条)。 */
164
+ save(name, bytes) {
165
+ const sniffed = sniffMedia(bytes.subarray(0, HEAD_BYTES));
166
+ const limit = limitFor(sniffed.kind);
167
+ if (bytes.length === 0)
168
+ throw new AttachmentError('空文件不能作为附件');
169
+ if (bytes.length > limit) {
170
+ throw new AttachmentError(`${sniffed.kind === 'image' ? '图片' : '文件'}超过 ${formatBytes(limit)} 上限`);
171
+ }
172
+ const sha = createHash('sha256').update(bytes).digest('hex');
173
+ const target = this.pathOf(sha);
174
+ if (!existsSync(target)) {
175
+ const tmpDirectory = join(this.root, 'tmp');
176
+ mkdirSync(tmpDirectory, { recursive: true });
177
+ mkdirSync(join(this.root, 'objects', sha.slice(0, 2)), { recursive: true });
178
+ const tmp = join(tmpDirectory, `${sha}.${randomBytes(4).toString('hex')}`);
179
+ writeFileSync(tmp, bytes);
180
+ this.publish(tmp, target);
181
+ }
182
+ return this.meta(sha, sniffed, name, bytes.length);
183
+ }
184
+ /**
185
+ * 把一条 HTTP 请求体流式落盘。
186
+ *
187
+ * 为什么要流式:视频动辄几十 MB,先 `readBodyBytes` 攒进内存会顶出一整份缓冲。
188
+ * 边写边算 sha,超限时立刻停写并删临时文件,客户端拿到 413。
189
+ */
190
+ async saveStream(req, name) {
191
+ const tmpDirectory = join(this.root, 'tmp');
192
+ mkdirSync(tmpDirectory, { recursive: true });
193
+ const tmp = join(tmpDirectory, `${Date.now().toString(36)}.${randomBytes(6).toString('hex')}`);
194
+ const hash = createHash('sha256');
195
+ const declared = Number(req.headers['content-length'] ?? '');
196
+ if (Number.isFinite(declared) && declared > MAX_MEDIA_BYTES) {
197
+ throw new AttachmentError(`文件超过 ${formatBytes(MAX_MEDIA_BYTES)} 上限`);
198
+ }
199
+ const handle = await open(tmp, 'w');
200
+ let bytes = 0;
201
+ try {
202
+ for await (const chunk of req) {
203
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
204
+ bytes += buffer.length;
205
+ if (bytes > MAX_MEDIA_BYTES)
206
+ throw new AttachmentError(`文件超过 ${formatBytes(MAX_MEDIA_BYTES)} 上限`);
207
+ hash.update(buffer);
208
+ await handle.write(buffer);
209
+ }
210
+ }
211
+ catch (error) {
212
+ await handle.close();
213
+ await rm(tmp, { force: true });
214
+ throw error;
215
+ }
216
+ await handle.close();
217
+ if (bytes === 0) {
218
+ await rm(tmp, { force: true });
219
+ throw new AttachmentError('空文件不能作为附件');
220
+ }
221
+ const sha = hash.digest('hex');
222
+ const head = await readHead(tmp);
223
+ const sniffed = sniffMedia(head);
224
+ const limit = limitFor(sniffed.kind);
225
+ if (bytes > limit) {
226
+ await rm(tmp, { force: true });
227
+ throw new AttachmentError(`${sniffed.kind === 'image' ? '图片' : '文件'}超过 ${formatBytes(limit)} 上限`);
228
+ }
229
+ const target = this.pathOf(sha);
230
+ mkdirSync(join(this.root, 'objects', sha.slice(0, 2)), { recursive: true });
231
+ if (!existsSync(target))
232
+ this.publish(tmp, target);
233
+ else
234
+ await rm(tmp, { force: true });
235
+ return this.meta(sha, sniffed, name, bytes);
236
+ }
237
+ /** 读整段字节(组装模型请求时用;只给图片,视频不走这条)。 */
238
+ read(sha) {
239
+ return readFileSync(this.pathOf(sha));
240
+ }
241
+ /** 对象的字节数与修改时间;对象不存在时回 null。 */
242
+ stat(sha) {
243
+ try {
244
+ const info = statSync(this.pathOf(sha));
245
+ return info.isFile() ? { size: info.size, mtimeMs: info.mtimeMs } : null;
246
+ }
247
+ catch {
248
+ return null;
249
+ }
250
+ }
251
+ /** 给 HTTP 路由用的类型判定:只读文件头。 */
252
+ async mimeOf(sha) {
253
+ const path = this.pathOf(sha);
254
+ try {
255
+ const info = await stat(path);
256
+ if (!info.isFile())
257
+ return null;
258
+ const head = await readHead(path);
259
+ return { mime: sniffMedia(head).mime, size: info.size };
260
+ }
261
+ catch {
262
+ return null;
263
+ }
264
+ }
265
+ /** 元数据组装(路径与 url 一处生成,避免两边漂移)。 */
266
+ meta(sha, sniffed, name, bytes) {
267
+ const safeName = displayName(name);
268
+ return {
269
+ sha,
270
+ kind: sniffed.kind,
271
+ name: safeName,
272
+ mime: sniffed.mime,
273
+ bytes,
274
+ url: attachmentUrl(sha, safeName),
275
+ path: this.pathOf(sha),
276
+ };
277
+ }
278
+ /** 把临时文件发布成正式对象:临时文件与目标同盘,改名是原子的。 */
279
+ publish(tmp, target) {
280
+ try {
281
+ renameSync(tmp, target);
282
+ }
283
+ catch (error) {
284
+ // Windows 上目标恰好被另一个并发写入创建时 rename 会失败:删掉临时文件,认对方那份。
285
+ try {
286
+ unlinkSync(tmp);
287
+ }
288
+ catch {
289
+ // 临时文件删不掉不影响结果
290
+ }
291
+ if (!existsSync(target))
292
+ throw error;
293
+ }
294
+ }
295
+ }
296
+ /** 进程级默认仓库:界面路由与会话投影共用一份。 */
297
+ let defaultStore = null;
298
+ /** 取(首次创建)默认仓库。 */
299
+ export function attachmentStore() {
300
+ defaultStore ??= new AttachmentStore();
301
+ return defaultStore;
302
+ }
303
+ /** 自检替换默认仓库(只给测试脚本用)。 */
304
+ export function setAttachmentStoreForTest(store) {
305
+ defaultStore = store;
306
+ }
307
+ /**
308
+ * 把一条图片引用读成 data URL(组装模型请求时用)。
309
+ *
310
+ * - `data:` 开头的老写法原样返回(老会话兼容);
311
+ * - `/api/attachments/<sha>` 读成 base64;文件不在了就抛错,让这一轮明确失败,
312
+ * 而不是把一条坏链接发给端点;
313
+ * - 其它字符串(远端 http 图)原样返回。
314
+ */
315
+ export function resolveImageForRequest(url) {
316
+ if (url.startsWith('data:'))
317
+ return url;
318
+ const sha = parseAttachmentUrl(url);
319
+ if (sha === null)
320
+ return url;
321
+ const store = attachmentStore();
322
+ const mimeOfFile = store.stat(sha);
323
+ if (mimeOfFile === null)
324
+ throw new AttachmentError(`附件不存在:${sha.slice(0, 12)}…`);
325
+ const head = readFileSync(store.pathOf(sha)).subarray(0, HEAD_BYTES);
326
+ const sniffed = sniffMedia(head);
327
+ if (sniffed.kind !== 'image')
328
+ throw new AttachmentError(`这个附件不是图片:${sha.slice(0, 12)}…`);
329
+ return `data:${sniffed.mime};base64,${store.read(sha).toString('base64')}`;
330
+ }
331
+ /**
332
+ * 文件类附件给模型看的那一段文字。
333
+ *
334
+ * 形状照 dsh 的文件句柄:一行说清「是什么、多大、摘要前缀、在哪」。模型拿到路径后
335
+ * 用文件工具自己读(视频自己没有解码能力的端点也读不懂,所以这里不承诺「能看画面」)。
336
+ */
337
+ export function fileHandleText(files) {
338
+ if (files.length === 0)
339
+ return '';
340
+ const lines = files.map((file) => {
341
+ const kind = file.kind === 'video' ? '视频' : '文件';
342
+ return `[${kind}附件] ${file.name}(${file.mime} · ${formatBytes(file.bytes)} · sha256:${file.sha.slice(0, 12)})\n只读路径:${file.path}`;
343
+ });
344
+ return lines.join('\n');
345
+ }
346
+ /** 按扩展名给一个「像不像图片」的提示(只用于界面提前选路,不参与安全判断)。 */
347
+ export function looksLikeImage(name) {
348
+ const ext = extname(name).toLowerCase();
349
+ return ext === '.png' || ext === '.jpg' || ext === '.jpeg' || ext === '.webp' || ext === '.gif';
350
+ }
351
+ /** 按扩展名给一个「像不像视频」的提示(同上)。 */
352
+ export function looksLikeVideo(name) {
353
+ const ext = extname(name).toLowerCase();
354
+ return ext === '.mp4' || ext === '.m4v' || ext === '.mov' || ext === '.webm' || ext === '.mkv' || ext === '.avi';
355
+ }
356
+ /**
357
+ * 校验并洗白「页面传来的文件引用」。
358
+ *
359
+ * 为什么必须在入口洗:界面通道的实参来自网络,页面(含第三方插件)可以编任意
360
+ * `path`——把 `C:\Users\…\credentials.yaml` 塞进来,宿主就会把那条路径写进模型
361
+ * 看得到的句柄里,等于把「模型可读范围」交给页面决定。所以路径一律不信:只认
362
+ * 仓库按 sha 算出来的那一条;其它字段只做类型与长度收口。
363
+ */
364
+ export function sanitizeFileRefs(value) {
365
+ if (!Array.isArray(value))
366
+ throw new AttachmentError('附件清单必须是数组');
367
+ if (value.length > 20)
368
+ throw new AttachmentError('一条消息最多带 20 个文件');
369
+ const store = attachmentStore();
370
+ const out = [];
371
+ for (const item of value) {
372
+ if (item === null || typeof item !== 'object')
373
+ throw new AttachmentError('附件项形状不对');
374
+ const record = item;
375
+ const sha = record['sha'];
376
+ if (typeof sha !== 'string' || !SHA.test(sha))
377
+ throw new AttachmentError('附件 id 不合法');
378
+ const kind = record['kind'];
379
+ if (kind !== 'video' && kind !== 'file')
380
+ throw new AttachmentError('附件类别只能是 video 或 file');
381
+ if (!store.has(sha))
382
+ throw new AttachmentError(`附件不存在:${sha.slice(0, 12)}…`);
383
+ const info = store.stat(sha);
384
+ if (info === null)
385
+ throw new AttachmentError(`附件不存在:${sha.slice(0, 12)}…`);
386
+ const name = typeof record['name'] === 'string' ? displayName(record['name']) : 'attachment';
387
+ const mime = typeof record['mime'] === 'string' ? record['mime'].slice(0, 100) : 'application/octet-stream';
388
+ // 视频关键帧:只认仓库里真的存在、且确实是图片的对象(页面给的顺序照收)。
389
+ const rawFrames = record['frames'];
390
+ const frames = [];
391
+ if (rawFrames !== undefined) {
392
+ if (!Array.isArray(rawFrames) || rawFrames.length > 12)
393
+ throw new AttachmentError('视频帧清单不合法');
394
+ for (const frame of rawFrames) {
395
+ const frameSha = typeof frame === 'string' ? (parseAttachmentUrl(frame) ?? (/^[0-9a-f]{64}$/.test(frame) ? frame : null)) : null;
396
+ if (frameSha === null || !store.has(frameSha))
397
+ continue;
398
+ frames.push(attachmentUrl(frameSha));
399
+ }
400
+ }
401
+ out.push({
402
+ sha,
403
+ kind,
404
+ name,
405
+ mime,
406
+ bytes: info.size,
407
+ path: store.pathOf(sha),
408
+ url: attachmentUrl(sha, name),
409
+ ...(frames.length === 0 ? {} : { frames }),
410
+ });
411
+ }
412
+ return out;
413
+ }
414
+ /** 读文件头(异步路由用)。 */
415
+ async function readHead(path) {
416
+ const handle = await open(path, 'r');
417
+ try {
418
+ const buffer = Buffer.alloc(HEAD_BYTES);
419
+ const { bytesRead } = await handle.read(buffer, 0, HEAD_BYTES, 0);
420
+ return buffer.subarray(0, bytesRead);
421
+ }
422
+ finally {
423
+ await handle.close();
424
+ }
425
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 字节数的人话读法(宿主侧唯一一份)。
3
+ *
4
+ * 同一件事此前散在五处,差异只在单位、标点与小数位:附件的「512 B」、暂存清理的
5
+ * 「1536 字节」、输入区附件的「1.2 MB」(把 `.0` 抹掉了)、对话流附件行自己又抄的一份、
6
+ * 文件树的「512B」(没有空格)。合并成两份:宿主这一份,与壳里 `ui-primitives/sizes.ts`
7
+ * 的同名函数——**层级上两边不许互相 import**(壳只经 `@dsc/ui*` 拿宿主的类型,不拿运行期
8
+ * 实现),所以各存一份实现,由 `scripts/ui-bytes-test.mjs` 逐字比对两份函数体,漂了要红。
9
+ *
10
+ * @module dsc/core/bytes
11
+ */
12
+ /** 1024 进制(KB / MB / GB):不到 1KB 给整数 B,一位小数但抹掉 `.0`,两位数以上取整;
13
+ * 非有限数或负数给破折号(界面上不显示 NaN)。 */
14
+ export declare function formatBytes(bytes: number): string;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 字节数的人话读法(宿主侧唯一一份)。
3
+ *
4
+ * 同一件事此前散在五处,差异只在单位、标点与小数位:附件的「512 B」、暂存清理的
5
+ * 「1536 字节」、输入区附件的「1.2 MB」(把 `.0` 抹掉了)、对话流附件行自己又抄的一份、
6
+ * 文件树的「512B」(没有空格)。合并成两份:宿主这一份,与壳里 `ui-primitives/sizes.ts`
7
+ * 的同名函数——**层级上两边不许互相 import**(壳只经 `@dsc/ui*` 拿宿主的类型,不拿运行期
8
+ * 实现),所以各存一份实现,由 `scripts/ui-bytes-test.mjs` 逐字比对两份函数体,漂了要红。
9
+ *
10
+ * @module dsc/core/bytes
11
+ */
12
+ /** 1024 进制(KB / MB / GB):不到 1KB 给整数 B,一位小数但抹掉 `.0`,两位数以上取整;
13
+ * 非有限数或负数给破折号(界面上不显示 NaN)。 */
14
+ export function formatBytes(bytes) {
15
+ if (!Number.isFinite(bytes) || bytes < 0)
16
+ return '—';
17
+ if (bytes < 1024)
18
+ return `${String(Math.round(bytes))} B`;
19
+ const units = ['KB', 'MB', 'GB'];
20
+ let value = bytes / 1024;
21
+ let unit = 0;
22
+ while (value >= 1024 && unit < units.length - 1) {
23
+ value /= 1024;
24
+ unit += 1;
25
+ }
26
+ const rounded = value >= 10 ? String(Math.round(value)) : value.toFixed(1).replace(/\.0$/, '');
27
+ return `${rounded} ${units[unit]}`;
28
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 一条命令的中文说法。
3
+ *
4
+ * @param command - 命令原文(可以是多行、带管道)
5
+ * @returns 一句中文(可能被截断);空命令给 null
6
+ */
7
+ export declare function commandMeaning(command: string): string | null;
8
+ /**
9
+ * 一次工具调用的中文说法:命令类解读命令,写类说清动哪个文件。
10
+ *
11
+ * @param input.toolName - 工具真名
12
+ * @param input.command - 这次要跑的命令(命令类工具才有)
13
+ * @param input.target - 这次要动的绝对路径(写类工具才有)
14
+ * @returns 一句话;认不出来给 null(界面就不画那一行)
15
+ */
16
+ export declare function callMeaning(input: {
17
+ toolName: string;
18
+ command?: string | null;
19
+ target?: string | null;
20
+ }): string | null;