@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
@@ -1,13 +1,18 @@
1
1
  import { compactSession, DEFAULT_KEEP_RECENT, DEFAULT_PRUNE_OPTIONS, estimateTokens } from '../core/compact.js';
2
+ import { estimateTextTokens } from '../core/token-estimate.js';
2
3
  import { readSpillConfig } from '../core/spill.js';
3
4
  import { DEFAULT_ANCHOR_BUDGET_CHARS, DEFAULT_READ_STATE_BUDGET_CHARS, DEFAULT_READ_STATE_FILES, DEFAULT_USER_QUOTE_BUDGET_CHARS } from '../core/compact-anchors.js';
4
5
  import { errText } from '../adapter/transcript.js';
5
6
  import { resolvePluginConfig, writePluginConfig } from '../core/plugin-registry.js';
7
+ import { clampInt as clamp } from '../core/clamp.js';
6
8
  /** 配置键(`~/.dsc/plugins.json` 条目树里 `file` 等于这个名字那一项的 `config`)。 */
7
9
  const CONFIG_KEY = 'compact';
8
10
  const DEFAULTS = {
9
11
  keepRecent: DEFAULT_KEEP_RECENT,
10
12
  autoCompactPercent: 80,
13
+ headroomTokens: 0,
14
+ compactionRetries: 1,
15
+ retainPercent: 16,
11
16
  anchorBudgetChars: DEFAULT_ANCHOR_BUDGET_CHARS,
12
17
  userQuoteBudgetChars: DEFAULT_USER_QUOTE_BUDGET_CHARS,
13
18
  readStateFiles: DEFAULT_READ_STATE_FILES,
@@ -20,21 +25,33 @@ const USER_QUOTE_BUDGET_RANGE = { min: 1000, max: 40000 };
20
25
  const READ_STATE_FILES_RANGE = { min: 0, max: 20 };
21
26
  /** read-state 字符预算的区间(默认 1500,压得很紧)。 */
22
27
  const READ_STATE_BUDGET_RANGE = { min: 200, max: 10000 };
28
+ /**
29
+ * 安全余量的区间:0 = 自动(窗口的 6.4%,封顶 65536)。
30
+ * 上限给到 131072:再大的窗口配再大的余量也够用了,填得比窗口还大等于永远触发压缩。
31
+ */
32
+ const HEADROOM_RANGE = { min: 0, max: 131072 };
33
+ /** 补压次数的区间:0 = 只压一次(手动 `/compact` 就是这条口径),最多补 3 次。 */
34
+ const COMPACTION_RETRIES_RANGE = { min: 0, max: 3 };
35
+ /**
36
+ * 尾部保留占比的区间(百分比)。
37
+ * 低于 5% 等于几乎不留给下一个自己;高于 40% 时压完留下的比折掉的还多,压缩没意义。
38
+ * 缺省 16%:dsh 的 retainRatio 就是这个数(按它那边 1M 窗口留约 16 万 token)。
39
+ */
40
+ const RETAIN_PERCENT_RANGE = { min: 5, max: 40 };
23
41
  /**
24
42
  * 从插件配置取这些可调值,并把区间外的值夹回来。
25
43
  * @param passed - 装配时传进来的配置(内核挂载时的第二参数);没给就读磁盘。
26
44
  */
27
45
  function readConfig(passed) {
28
46
  const raw = resolvePluginConfig(CONFIG_KEY, passed);
29
- const clamp = (value, min, max, fallback) => {
30
- const num = Number(value);
31
- return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), min), max) : fallback;
32
- };
33
47
  return {
34
48
  // 少于 5 条等于没给下一个自己留上下文,多于 200 条基本压不出空间。
35
49
  keepRecent: clamp(raw.keepRecent, 5, 200, DEFAULTS.keepRecent),
36
50
  // 低于 50% 会在干活时频繁打断,高于 95% 等于等模型报错才压。
37
51
  autoCompactPercent: clamp(raw.autoCompactPercent, 50, 95, DEFAULTS.autoCompactPercent),
52
+ headroomTokens: clamp(raw.headroomTokens, HEADROOM_RANGE.min, HEADROOM_RANGE.max, DEFAULTS.headroomTokens),
53
+ compactionRetries: clamp(raw.compactionRetries, COMPACTION_RETRIES_RANGE.min, COMPACTION_RETRIES_RANGE.max, DEFAULTS.compactionRetries),
54
+ retainPercent: clamp(raw.retainPercent, RETAIN_PERCENT_RANGE.min, RETAIN_PERCENT_RANGE.max, DEFAULTS.retainPercent),
38
55
  anchorBudgetChars: clamp(raw.anchorBudgetChars, ANCHOR_BUDGET_RANGE.min, ANCHOR_BUDGET_RANGE.max, DEFAULTS.anchorBudgetChars),
39
56
  userQuoteBudgetChars: clamp(raw.userQuoteBudgetChars, USER_QUOTE_BUDGET_RANGE.min, USER_QUOTE_BUDGET_RANGE.max, DEFAULTS.userQuoteBudgetChars),
40
57
  readStateFiles: clamp(raw.readStateFiles, READ_STATE_FILES_RANGE.min, READ_STATE_FILES_RANGE.max, DEFAULTS.readStateFiles),
@@ -54,14 +71,30 @@ export const compactPlugin = {
54
71
  writePluginConfig(CONFIG_KEY, patch);
55
72
  config = readConfig();
56
73
  };
57
- /** 当前配置里的压缩上限,现读 config,保存后下一压就用新值。 */
58
- const limits = () => ({
59
- keepRecent: config.keepRecent,
60
- anchorChars: config.anchorBudgetChars,
61
- userQuoteChars: config.userQuoteBudgetChars,
62
- readStateFiles: config.readStateFiles,
63
- readStateChars: config.readStateChars,
64
- });
74
+ /**
75
+ * 当前配置里的压缩上限,现读 config,保存后下一压就用新值。
76
+ *
77
+ * 需要目标会话:尾部 token 预算按**这条会话**的模型窗口折算(后台会话按它自己的路由,
78
+ * 不看用户正在看的那条)。窗口拿不到时退回纯条数口径,不猜一个数。
79
+ *
80
+ * @param target - 要压的会话
81
+ * @param retain - 是否按窗口占比留尾巴。自动阈值压缩留(省下的空间还得放得下这一轮),
82
+ * 手动 `/compact` 与爆窗强压**不留**:这两条路的目的是尽快腾出空间,只保留条数下限。
83
+ * 不留这一档不是省事:100 万窗口的模型上,16% 的尾巴就是 16 万 token,短历史手动压
84
+ * 会因为「尾巴装得下整段」直接判成没得压——用户看到的是一句「历史不长,无需压缩」。
85
+ */
86
+ const limits = (target, retain = true) => {
87
+ const window = ctx.llm.contextWindowOf(target);
88
+ const retainTokens = retain ? Math.floor(window * (config.retainPercent / 100)) : 0;
89
+ return {
90
+ keepRecent: config.keepRecent,
91
+ ...(retainTokens > 0 ? { retainTokens } : {}),
92
+ anchorChars: config.anchorBudgetChars,
93
+ userQuoteChars: config.userQuoteBudgetChars,
94
+ readStateFiles: config.readStateFiles,
95
+ readStateChars: config.readStateChars,
96
+ };
97
+ };
65
98
  /** T19 前置裁剪口径:spill 配置复用 spill 插件的那份(目录与上限一致,模型可照常 read)。 */
66
99
  const prune = () => ({
67
100
  ...DEFAULT_PRUNE_OPTIONS,
@@ -77,8 +110,8 @@ export const compactPlugin = {
77
110
  * 0.6.48:按目标会话的 cwd 拼(后台常驻 agent 的压缩不能再看「当前查看的会话」)。
78
111
  */
79
112
  const requestContext = (target) => ({
80
- system: ctx.prompt.systemPrompt(target.meta.cwd),
81
- tools: ctx.tools.visible().map((tool) => ({
113
+ system: ctx.prompt.systemPrompt(target.meta.cwd, { sessionId: target.meta.id, cwd: target.meta.cwd }),
114
+ tools: ctx.tools.visible({ sessionId: target.meta.id }).map((tool) => ({
82
115
  name: tool.name,
83
116
  description: tool.description,
84
117
  parameters: tool.parameters,
@@ -91,6 +124,36 @@ export const compactPlugin = {
91
124
  .map((contribute) => contribute())
92
125
  .filter((part) => part !== '')
93
126
  .join('\n\n');
127
+ /**
128
+ * 包住一次压缩:开始与结束各广播一次状态,界面据此画 / 收起活动行。
129
+ *
130
+ * 为什么用 finally:摘要调用会失败(端点 500、用户打断),漏掉结束信号的话
131
+ * 界面那条「正在压缩」会一直转下去,比不显示更糟。
132
+ *
133
+ * @param target - 这次压缩的目标会话(后台会话的压缩不该画到当前视图里)。
134
+ * @param run - 真正干活的那段。
135
+ */
136
+ const whileCompacting = async (target, run) => {
137
+ ctx.emit('dsc/compacting', true, target.filePath);
138
+ try {
139
+ return await run();
140
+ }
141
+ finally {
142
+ ctx.emit('dsc/compacting', false, target.filePath);
143
+ }
144
+ };
145
+ /**
146
+ * 压完之后按新历史重算一次上下文占用(估算)。
147
+ *
148
+ * 为什么必须给一个数:`contextUsed` 的权威读数来自模型回来的用量,而压缩本身
149
+ * 不发对话请求——不补这一下,底部的百分比会一直停在压缩前(用户以为没压)。
150
+ * 口径与请求组装一致:对话消息 + 系统提示词 + 工具目录,下一次真实请求再校正。
151
+ */
152
+ const reportContextUsed = (target) => {
153
+ const { system, tools } = requestContext(target);
154
+ const used = estimateTokens(target.messages) + estimateTextTokens(system) + estimateTextTokens(JSON.stringify(tools));
155
+ ctx.emit('dsc/context-used', Math.round(used), target.filePath);
156
+ };
94
157
  // T41 /compact 运行守卫:回合跑着的时候手动压缩,摘要落库会和进行中的工具
95
158
  // 落库交错(jsonl 里 summary 插在 tool 记录中间,重放口径会乱)。数着回合。
96
159
  // 0.6.48 起按会话计数:后台常驻 agent 的回合不该挡住当前会话的 /compact
@@ -109,6 +172,28 @@ export const compactPlugin = {
109
172
  else
110
173
  runningTurnsBySid.set(sid, count - 1);
111
174
  });
175
+ /**
176
+ * 自动压缩的触发阈值(token)。
177
+ *
178
+ * 口径对齐 dsh:阈值 = min(窗口 × 触发比例, 窗口 − 输出预留 − 安全余量)。
179
+ * 为什么要减输出预留与安全余量:一次请求最多吐 maxTokens,这部分窗口不能拿去装历史;
180
+ * 余量留给「系统提示词 + 工具目录 + 本轮新增消息」的浮动空间,压到贴边的话
181
+ * 下一轮请求立刻又超。
182
+ * 余量为什么按窗口 6.4% 算并封顶 65536:dsh 那里是写死的 65536(按 1M 窗口设计),
183
+ * 照搬到 128k 窗口的模型上,阈值会掉到窗口的一半以下(131072 − 8192 输出 − 65536
184
+ * 只剩 57344,约 44%),活干到一半就被压一次。按窗口缩放才跟着窗口走。
185
+ *
186
+ * @param target - 要判定的会话(阈值跟这个会话的模型路由走,不看「当前查看的会话」)。
187
+ */
188
+ const thresholdOf = (target) => {
189
+ const window = ctx.llm.contextWindowOf(target);
190
+ const reserve = ctx.llm.routeForSession(target).maxTokens ?? 0;
191
+ const headroom = config.headroomTokens > 0 ? config.headroomTokens : Math.min(65_536, Math.floor(window * 0.064));
192
+ const byRatio = Math.floor(window * (config.autoCompactPercent / 100));
193
+ // 下限 1024:窗口配得很小、或 maxTokens 接近窗口时,阈值不能变成 0 甚至负数,
194
+ // 否则每次请求都判成「超了」,压缩会连着空转(每次都是 noop)。
195
+ return Math.max(1024, Math.min(byRatio, window - reserve - headroom));
196
+ };
112
197
  const service = {
113
198
  registerCarry(contribute) {
114
199
  carries.push(contribute);
@@ -118,28 +203,67 @@ export const compactPlugin = {
118
203
  carries.splice(at, 1);
119
204
  };
120
205
  },
121
- /** 当前模型路由 + 配置里的自动压缩触发线(缺省 contextWindow 的 80%)。 */
206
+ /** 当前模型路由 + 配置里的自动压缩触发线(缺省 min(窗口的 80%, 窗口 − 输出预留 − 余量))。 */
122
207
  async check(signal, target) {
123
208
  const session = target ?? ctx.session.current();
124
- const threshold = ctx.llm.contextWindow * (config.autoCompactPercent / 100);
125
- if (estimateTokens(session.messages) <= threshold)
209
+ const threshold = thresholdOf(session);
210
+ let used = estimateTokens(session.messages);
211
+ if (used <= threshold)
126
212
  return;
127
- const outcome = await compactSession(session, ctx.llm.route(), stream, signal ?? new AbortController().signal, carry(), limits(), undefined, prune(), requestContext(session));
128
- const compacted = outcome === 'compacted';
213
+ // 压完复量、还超就再压(对齐 dsh 的 compactionRetries):一次压缩的收缩率
214
+ // 跟摘要模型当时的输出质量有关,偶尔一次压不到线以下;补压一两次比直接放弃好。
215
+ // 手动 /compact 与 forceCompact 不循环——手动只压一次,爆窗重试也只看这一次的成败。
216
+ //
217
+ // 补压这一刀必须绕开「历史太短」守卫(force):第一次压完只剩摘要 + 条数下限那几条,
218
+ // 正常判定会认为没得压、直接 noop,可恰恰是「尾巴本身就超预算」才需要再压。
219
+ // 带 force 之后能折进上一份摘要本身,尾部按 token 预算重新收紧——这才是补压的意义。
220
+ let attempts = 0;
221
+ for (let attempt = 0; attempt <= config.compactionRetries; attempt += 1) {
222
+ const result = await whileCompacting(session, () => compactSession(session, ctx.llm.routeForSession(session), stream, signal ?? new AbortController().signal, carry(), limits(session), attempt > 0 ? true : undefined, prune(), requestContext(session)));
223
+ // 一轮都没压成(历史太短 / 整段都是工具结果)就别再试:再压还是同一个结果
224
+ if (result.outcome !== 'compacted')
225
+ break;
226
+ attempts += 1;
227
+ // 复量按新历史算:摘要 + 尾巴的实际估算(dsh 在同一处也用 token 计量器重量)
228
+ used = estimateTokens(session.messages);
229
+ if (used <= threshold)
230
+ break;
231
+ }
232
+ const compacted = attempts > 0;
129
233
  // 只有真压出结果才打压缩标记:noop 时这条提示照旧发(文案不动),
130
234
  // 但轨迹页不该凭空多出一段「压缩历史」
131
- ctx.emit('dsc/notice', '上下文接近模型上限,已自动压缩历史', compacted ? 'compaction' : undefined);
132
- if (compacted)
133
- ctx.emit('dsc/compacted');
235
+ // 带会话归属(0.6.68):后台会话自动压缩时,这句提示不该冒到用户正在看的视图里。
236
+ if (!compacted) {
237
+ ctx.emit('dsc/notice', '上下文接近模型上限,已自动压缩历史', undefined, session.filePath);
238
+ return;
239
+ }
240
+ if (used <= threshold) {
241
+ ctx.emit('dsc/notice', '上下文接近模型上限,已自动压缩历史', 'compaction', session.filePath);
242
+ }
243
+ else {
244
+ // 补压用完仍在阈值之上:说清「还超多少、压了几次」,用户才知道该不该手动收紧口径
245
+ ctx.emit('dsc/notice', `上下文仍接近模型上限(估算 ${used} tokens ≥ 阈值 ${threshold}),已连续压缩 ${attempts} 次`, 'compaction', session.filePath);
246
+ }
247
+ ctx.emit('dsc/compacted');
248
+ reportContextUsed(session);
134
249
  },
135
250
  /** 请求已经因爆窗失败,强制压一次(2026-09-29):压出空间返回 true,循环方重试请求。 */
136
251
  async forceCompact(signal, target) {
137
252
  const session = target ?? ctx.session.current();
138
- const outcome = await compactSession(session, ctx.llm.route(), stream, signal ?? new AbortController().signal, carry(), limits(), true, prune(), requestContext(session));
139
- if (outcome === 'compacted') {
253
+ // 先看微压缩(2026-11-02):旧工具结果换成占位符是**投影**,不落历史,
254
+ // 此时真正发出去的请求本来就是清理过的。若清理后已经装进窗口,就没必要
255
+ // 牺牲历史去压摘要——白白丢掉原文,还可能把工具配对切坏。直接让调用方重试。
256
+ const micro = ctx.get('microcompact');
257
+ if (micro !== undefined && micro.projectedTokens(session.messages) < ctx.llm.contextWindowOf(session)) {
258
+ ctx.emit('dsc/notice', '上下文超出模型窗口,但旧工具结果清理后已在窗口内,直接重试', undefined, session.filePath);
259
+ return false;
260
+ }
261
+ const result = await whileCompacting(session, () => compactSession(session, ctx.llm.routeForSession(session), stream, signal ?? new AbortController().signal, carry(), limits(session, false), true, prune(), requestContext(session)));
262
+ if (result.outcome === 'compacted') {
140
263
  // 打上 'compaction' 类别:transcript 据此把这条通知标成压缩落点(轨迹页切区段)
141
- ctx.emit('dsc/notice', '上下文超出模型窗口:已自动压缩历史并重试', 'compaction');
264
+ ctx.emit('dsc/notice', '上下文超出模型窗口:已自动压缩历史并重试', 'compaction', session.filePath);
142
265
  ctx.emit('dsc/compacted');
266
+ reportContextUsed(session);
143
267
  return true;
144
268
  }
145
269
  return false;
@@ -158,12 +282,15 @@ export const compactPlugin = {
158
282
  return;
159
283
  }
160
284
  try {
161
- const outcome = await compactSession(ctx.session.current(), ctx.llm.route(), stream, new AbortController().signal, carry(), limits(), undefined, prune(), requestContext(ctx.session.current()));
162
- const compacted = outcome === 'compacted';
285
+ const target = ctx.session.current();
286
+ const result = await whileCompacting(target, () => compactSession(target, ctx.llm.routeForSession(target), stream, new AbortController().signal, carry(), limits(target, false), undefined, prune(), requestContext(target)));
287
+ const compacted = result.outcome === 'compacted';
163
288
  ctx.emit('dsc/notice', compacted ? '上下文已压缩(任务清单与目标原样保留)' : '历史不长,无需压缩', compacted ? 'compaction' : undefined);
164
289
  // 压完等于换了半本历史:加载时冻结的东西该重算了(记忆栏就是这么挂上去的)
165
- if (compacted)
290
+ if (compacted) {
166
291
  ctx.emit('dsc/compacted');
292
+ reportContextUsed(target);
293
+ }
167
294
  }
168
295
  catch (error) {
169
296
  ctx.emit('dsc/notice', `压缩失败:${errText(error)}`);
@@ -171,7 +298,14 @@ export const compactPlugin = {
171
298
  ctx.emit('dsc/changed');
172
299
  },
173
300
  };
174
- ctx.commands.register({ name: 'compact', args: '', description: '压缩上下文' }, ({ runtime }) => void runtime.compact());
301
+ ctx.commands.register({ name: 'compact', args: '', description: '压缩上下文' }, ({ args, runtime, ui }) => {
302
+ // 与 dsh 同一条口径:这条命令不吃参数,多打的字是被截断的误操作,直说用法
303
+ if (args.length > 0) {
304
+ ui.notice('用法:/compact(不带参数)');
305
+ return;
306
+ }
307
+ void runtime.compact();
308
+ });
175
309
  ctx.provide('compact', service);
176
310
  const fields = [
177
311
  {
@@ -190,7 +324,34 @@ export const compactPlugin = {
190
324
  min: 50,
191
325
  max: 95,
192
326
  step: 5,
193
- help: '估算用量超过这个比例就自动压缩;/compact 手动压缩不受这条线限制。',
327
+ help: '估算用量超过这个比例就自动压缩;/compact 手动压缩不受这条线限制。阈值还会被「窗口减去输出预留与安全余量」压低,取两者中较小的那个。',
328
+ },
329
+ {
330
+ type: 'number',
331
+ key: 'headroomTokens',
332
+ label: '安全余量(token,0 = 按窗口自动)',
333
+ min: HEADROOM_RANGE.min,
334
+ max: HEADROOM_RANGE.max,
335
+ step: 1024,
336
+ help: '压到多早才开始动手:阈值会给输出预留(模型的 maxTokens 上限)再加这么多 token 的安全余量。0 = 自动(窗口的 6.4%,最多 65536)。调大 = 更早压缩、留给这一轮的空间更多;调小 = 压得更晚、更省历史。',
337
+ },
338
+ {
339
+ type: 'number',
340
+ key: 'compactionRetries',
341
+ label: '压一次还不够时最多再压几次',
342
+ min: COMPACTION_RETRIES_RANGE.min,
343
+ max: COMPACTION_RETRIES_RANGE.max,
344
+ step: 1,
345
+ help: '自动压缩后若估算用量仍在阈值之上,会再压一次,最多补这么多次。代价:每多压一次就多一次摘要模型调用(要等它写完才发真实请求),并且每次都把更早的原文折成摘要,细节会再丢一层。0 = 只压一次。',
346
+ },
347
+ {
348
+ type: 'number',
349
+ key: 'retainPercent',
350
+ label: '保留尾部(占模型窗口的百分比)',
351
+ min: RETAIN_PERCENT_RANGE.min,
352
+ max: RETAIN_PERCENT_RANGE.max,
353
+ step: 1,
354
+ help: '压缩后原样保留最近这些对话,按模型窗口折算成 token 预算,再退到「工具调用与结果不拆开」的安全边界;「压缩后保留最近多少条」仍是条数下限。为什么按 token 算:一条工具结果就可能几十万字符,只按条数留会在这种会话里压不动。调大 = 原文留得更多、省出的空间更少。',
194
355
  },
195
356
  {
196
357
  type: 'number',
@@ -241,6 +402,9 @@ export const compactPlugin = {
241
402
  return {
242
403
  keepRecent: config.keepRecent,
243
404
  autoCompactPercent: config.autoCompactPercent,
405
+ headroomTokens: config.headroomTokens,
406
+ compactionRetries: config.compactionRetries,
407
+ retainPercent: config.retainPercent,
244
408
  anchorBudgetChars: config.anchorBudgetChars,
245
409
  userQuoteBudgetChars: config.userQuoteBudgetChars,
246
410
  readStateFiles: config.readStateFiles,
@@ -256,6 +420,12 @@ export const compactPlugin = {
256
420
  applyConfig({ keepRecent: num });
257
421
  else if (key === 'autoCompactPercent')
258
422
  applyConfig({ autoCompactPercent: num });
423
+ else if (key === 'headroomTokens')
424
+ applyConfig({ headroomTokens: num });
425
+ else if (key === 'compactionRetries')
426
+ applyConfig({ compactionRetries: num });
427
+ else if (key === 'retainPercent')
428
+ applyConfig({ retainPercent: num });
259
429
  else if (key === 'anchorBudgetChars')
260
430
  applyConfig({ anchorBudgetChars: num });
261
431
  else if (key === 'userQuoteBudgetChars')
@@ -27,6 +27,8 @@ import { resolvePluginConfig, writePluginConfig } from '../core/plugin-registry.
27
27
  import { classifyCommand } from '../core/command-policy.js';
28
28
  import { redact } from '../core/secrets.js';
29
29
  import { wrapUntrusted } from '../core/untrusted.js';
30
+ import { clampInt as clamp } from '../core/clamp.js';
31
+ import { splitList } from '../core/strings.js';
30
32
  const CONFIG_KEY = 'computer-use';
31
33
  const DEFAULTS = {
32
34
  maxEdge: 1568,
@@ -41,13 +43,6 @@ const DEFAULTS = {
41
43
  };
42
44
  /** 只读性质的动作(看,不动手);免审批那一档就是它们。 */
43
45
  export const LOOK_ACTIONS = READ_ACTIONS;
44
- /** 拆逗号分隔清单(中英文逗号都认)。 */
45
- function splitList(text) {
46
- return text
47
- .split(/[,,\s]+/)
48
- .map((entry) => entry.trim())
49
- .filter((entry) => entry !== '');
50
- }
51
46
  /** 截图那条工具结果的文字开头,靠它认出「这是我们自己截的图」,不误伤别的插件带的图。 */
52
47
  const SHOT_MARK = '屏幕物理分辨率';
53
48
  /** 这条消息是不是我们放进去的截图(工具结果 + 带图 + 文字里有那个开头)。 */
@@ -172,14 +167,10 @@ export function computerLookParameters(actions) {
172
167
  }
173
168
  export const computerUsePlugin = {
174
169
  name: 'computer-use',
175
- inject: ['tools', 'prompt', 'settings'],
170
+ inject: ['tools', 'prompt', 'settings', 'guards'],
176
171
  apply(ctx, passed) {
177
172
  const readConfig = () => {
178
173
  const raw = resolvePluginConfig(CONFIG_KEY, passed);
179
- const clamp = (value, min, max, fallback) => {
180
- const num = Number(value);
181
- return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), min), max) : fallback;
182
- };
183
174
  return {
184
175
  maxEdge: clamp(raw.maxEdge, 640, 3840, DEFAULTS.maxEdge),
185
176
  format: raw.format === 'png' ? 'png' : 'jpeg',
@@ -249,19 +240,29 @@ export const computerUsePlugin = {
249
240
  const action = canonicalAction(actionName);
250
241
  if (action === null)
251
242
  throw new Error(`不认识的动作「${actionName}」。可选:${DESKTOP_ACTIONS.join(' / ')}`);
252
- // 急停永远可调(否则卡住后没法恢复);它杀子进程 + 关动作面。
243
+ // 只读入口的运行时闸门:computer_look 声明 risk=read(免审批),参数 schema 只告诉模型
244
+ // 「应该传哪些动作」,并不能阻止它传 click / type。少了这道判断,一条
245
+ // action=click 就能完全绕过审批卡——schema 是说明,不是强制。
246
+ // stop 也不放进来:它评的是 system 档(杀进程 + 关动作面),让一条 risk=read 的
247
+ // 工具能触发它,风险分级就名不副实了。急停走 computer 工具,那条通道永远留着。
248
+ if (viaLook && action !== 'screenshot' && !LOOK_ACTIONS.includes(action)) {
249
+ throw new Error(`computer_look 只能做只读动作(${LOOK_ACTIONS.join(' / ')} / screenshot);` +
250
+ `「${action}」会操作桌面或改变机器状态,请改用 computer 工具(急停也用它的 stop)`);
251
+ }
252
+ // 急停通道:动手工具里永远留着 stop(不受禁用清单与免审批档影响),否则卡住后没法恢复;
253
+ // 它杀子进程 + 关动作面,只读入口不放它(见上面的闸门)。
253
254
  if (action === 'stop') {
254
255
  const killed = killAllPowerShell();
255
256
  stopped = true;
256
257
  audit('stop', 'system', '急停', 'ok', true);
257
- return `已急停电脑操作:杀掉 ${killed} 个在跑的界面子进程,并暂停了电脑操作动作面。请在「设置 → 电脑操作」点「恢复电脑操作」再继续。`;
258
+ return `已急停电脑操作:杀掉 ${killed} 个在跑的界面子进程,并暂停了电脑操作动作面。请在「插件中心 → 操作电脑桌面」点「恢复电脑操作」再继续(终端里也可用设置里的同名分区)。`;
258
259
  }
259
260
  if (stopped) {
260
- throw new Error('电脑操作已急停(stop)。请在「设置 → 电脑操作」点「恢复电脑操作」再继续。');
261
+ throw new Error('电脑操作已急停(stop)。请在「插件中心 → 操作电脑桌面」点「恢复电脑操作」再继续(终端里也可用设置里的同名分区)。');
261
262
  }
262
263
  const risk = gradeDesktopAction(action, args);
263
264
  if (disabled().has(action)) {
264
- throw new Error(`动作「${action}」被你在设置「电脑操作」的「禁用动作」里关掉了`);
265
+ throw new Error(`动作「${action}」被你在「操作电脑桌面」的「禁用动作」里关掉了`);
265
266
  }
266
267
  try {
267
268
  if (action === 'screenshot') {
@@ -413,6 +414,17 @@ export const computerUsePlugin = {
413
414
  disposers.push(ctx.prompt.register('computer-use', promptText));
414
415
  };
415
416
  syncTools();
417
+ // 急停排在所有闸门之前(order 4):它是「停下来」,不是「做事」。
418
+ // 审批卡没人能答、或当前是计划/只读档时,stop 仍须可用,否则卡住之后没法恢复。
419
+ const offStopGuard = ctx.guards.register({
420
+ id: 'computer-use-stop',
421
+ order: 4,
422
+ decide(input) {
423
+ if (input.toolName !== 'computer')
424
+ return { action: 'defer' };
425
+ return canonicalAction(String(input.args.action ?? '')) === 'stop' ? { action: 'pass' } : { action: 'defer' };
426
+ },
427
+ });
416
428
  // 旧截图的图像卸载交给内核通用的 image-diet 投影(plugins/prompt.ts,order 550):
417
429
  // 它按 toolImageBudget 保留最近 N 张工具结果图,电脑控制的截图与别的工具结果同一口径。
418
430
  // 这里原有一条 `prune-stale-screenshots`(只留最新一张截图),与通用规则重叠——两条一起
@@ -442,8 +454,8 @@ export const computerUsePlugin = {
442
454
  ];
443
455
  const section = {
444
456
  id: 'computer-use',
445
- title: '电脑操作',
446
- subtitle: '让模型查看屏幕并代为点击、拖拽、输入,Windows 平台',
457
+ title: '操作电脑桌面',
458
+ subtitle: '看屏幕、点按钮、输入文字来操作 Windows 桌面;看可免审批,动手每次要确认',
447
459
  order: 45,
448
460
  fields,
449
461
  values: () => ({
@@ -531,9 +543,13 @@ export const computerUsePlugin = {
531
543
  const offSection = ctx.settings.registerSection(section);
532
544
  return () => {
533
545
  offSection();
546
+ offStopGuard();
534
547
  for (const off of disposers)
535
548
  off();
536
549
  disposers = [];
550
+ // 停用插件要收掉在跑的界面子进程:只退订工具不会让已经在跑的点击/输入停下,
551
+ // 它们会继续动鼠标键盘,直到脚本自己跑完。
552
+ killAllPowerShell();
537
553
  };
538
554
  },
539
555
  };
@@ -6,6 +6,9 @@ import { HOST_BROWSER_SERVICE } from '../core/host-browser-link.js';
6
6
  import { CLOUD_METADATA_HOSTS } from './browser.js';
7
7
  import * as actions from '../core/cdp/actions.js';
8
8
  import { lookupSnapshotRef, serializeAxTree, truncateByLines, } from '../core/cdp/snapshot.js';
9
+ import { clampInt as clamp } from '../core/clamp.js';
10
+ import { RingBuffer } from '../core/cdp/ring-buffer.js';
11
+ import { consoleLine, describeRef, networkLine, report, safeStringify, } from '../core/cdp/report.js';
9
12
  const CONFIG_KEY = 'dock-browser';
10
13
  /** 设置分区 id:与配置键同名,元数据 `settingsSection` 指向它。 */
11
14
  const SECTION_ID = 'dock-browser';
@@ -32,59 +35,6 @@ const DEFAULTS = {
32
35
  const OPEN_SETTLE_MS = 8_000;
33
36
  /** 没有桌面壳时给模型看的那句话(不抛栈,也不静默什么都不做)。 */
34
37
  const NO_SHELL_MESSAGE = '宿主里没有桌面壳,这条能力要在桌面端窗口里用:侧栏浏览器由桌面主进程提供(TUI / 无头 / 远程壳里拿不到它)。';
35
- // ── 小工具(与 browser.ts 同风格,便于两处输出读起来一致)─────────────────────
36
- /** 定长环形缓冲:满了丢最旧的(照 browser.ts 的 RingBuffer 思路)。 */
37
- class RingBuffer {
38
- capacity;
39
- items = [];
40
- constructor(capacity) {
41
- this.capacity = capacity;
42
- }
43
- push(item) {
44
- this.items.push(item);
45
- if (this.capacity > 0 && this.items.length > this.capacity) {
46
- this.items.splice(0, this.items.length - this.capacity);
47
- }
48
- }
49
- find(predicate) {
50
- return this.items.find(predicate);
51
- }
52
- toArray() {
53
- return [...this.items];
54
- }
55
- clear() {
56
- this.items = [];
57
- }
58
- }
59
- /** 一行人类可读摘要 + 一行结构化 JSON(照 browser.ts 的 report)。 */
60
- function report(summary, data) {
61
- return `${summary}\n${JSON.stringify(data)}`;
62
- }
63
- /** 时间戳 → HH:MM:SS。 */
64
- function clock(ts) {
65
- return new Date(ts).toISOString().slice(11, 19);
66
- }
67
- /** 变量值的兜底字符串化(控制台参数可能是对象或循环引用)。 */
68
- function safeStringify(value) {
69
- if (typeof value === 'string')
70
- return value;
71
- try {
72
- const text = JSON.stringify(value);
73
- return text === undefined ? String(value) : text;
74
- }
75
- catch {
76
- return String(value);
77
- }
78
- }
79
- /** ref 的人类可读描述(输出与错误信息里用)。 */
80
- function describeRef(ref) {
81
- return `${ref.role}${ref.name === '' ? '' : ` "${ref.name}"`}`;
82
- }
83
- /** 数字参数收敛到区间内;不是数字就取默认值。 */
84
- function clamp(value, min, max, fallback) {
85
- const num = Number(value);
86
- return Number.isFinite(num) ? Math.min(Math.max(Math.round(num), min), max) : fallback;
87
- }
88
38
  /**
89
39
  * 云元数据地址无条件拒。
90
40
  *
@@ -304,7 +254,17 @@ export const dockBrowserPlugin = {
304
254
  */
305
255
  const waitForDockPage = async (page, wanted, timeoutMs) => {
306
256
  const deadline = Date.now() + timeoutMs;
307
- const same = (left, right) => left.replace(/\/+$/, '') === right.replace(/\/+$/, '') || left.startsWith(right);
257
+ const same = (left, right) => {
258
+ const a = left.replace(/\/+$/, '');
259
+ const b = right.replace(/\/+$/, '');
260
+ if (a === b)
261
+ return true;
262
+ // 按 URL 边界比,不能只 startsWith:https://example.com.evil.com 会命中 example.com。
263
+ // 路径、查询串、锚点都算「到了这一页」。
264
+ if (b === '' || !a.startsWith(b))
265
+ return false;
266
+ return /^[\\/?#]/.test(a.slice(b.length));
267
+ };
308
268
  let seen = '';
309
269
  for (;;) {
310
270
  const state = await actions.readDocumentState(page).catch(() => null);
@@ -428,7 +388,7 @@ export const dockBrowserPlugin = {
428
388
  if (entries.length === 0) {
429
389
  return '这台视图的控制台还没有输出。(事件订阅是挂上之后才建立的,订阅之前的输出拿不到)';
430
390
  }
431
- const lines = entries.map((entry) => `[${clock(entry.ts)}] ${entry.level}: ${entry.text}`);
391
+ const lines = entries.map(consoleLine);
432
392
  return report(`视图 ${viewId} 控制台最近 ${entries.length} 条${clearing ? '(已清空缓冲)' : ''}:`, {
433
393
  action: 'console',
434
394
  viewId,
@@ -446,11 +406,7 @@ export const dockBrowserPlugin = {
446
406
  if (entries.length === 0) {
447
407
  return '这台视图还没有记录到网络请求。(事件订阅是挂上之后才建立的,之前的请求拿不到)';
448
408
  }
449
- const lines = entries.map((entry) => {
450
- const status = entry.failed === '' ? String(entry.status === 0 ? '进行中' : entry.status) : `失败:${entry.failed}`;
451
- const mime = entry.mimeType === '' ? '' : ` ${entry.mimeType}`;
452
- return `[${clock(entry.ts)}] ${entry.method} ${status}${mime} ${neutralizeInline(entry.url, 240)}`;
453
- });
409
+ const lines = entries.map(networkLine);
454
410
  return report(`视图 ${viewId} 网络最近 ${entries.length} 条${clearing ? '(已清空缓冲)' : ''}:`, {
455
411
  action: 'network',
456
412
  viewId,
@@ -618,6 +574,9 @@ export const dockBrowserPlugin = {
618
574
  if (scanned.sensitive.length > 0) {
619
575
  throw new Error(`表达式里用了敏感原语(${scanned.sensitive.join('、')})。页面里这些本来也不该出现,换个写法`);
620
576
  }
577
+ // 表达式里出现的地址也要过一道:与 browser.ts 同口径,至少挡住云元数据与 file:/javascript: 这类。
578
+ for (const url of scanned.urls)
579
+ assertHttpUrl(url);
621
580
  const outcome = await actions.evaluateInPage(page, expression);
622
581
  return `求值结果(视图 ${viewId}):\n${wrapUntrusted('browser', outcome.text)}`;
623
582
  }
@@ -714,21 +673,21 @@ export const dockBrowserPlugin = {
714
673
  const section = {
715
674
  id: SECTION_ID,
716
675
  title: '侧栏浏览器',
717
- subtitle: '让模型驱动桌面端侧栏那台浏览器(用户自己的持久会话,不是自管那台一次性 Chrome)',
676
+ subtitle: '驱动桌面端侧栏那台浏览器(你的持久登录会话,不是自管的一次性 Chrome)',
718
677
  order: 35,
719
678
  fields: () => [
720
679
  {
721
680
  type: 'switch',
722
681
  key: 'lookWithoutApproval',
723
682
  label: '看侧栏浏览器免审批',
724
- help: '打开后 browser_dock_look(views / snapshot / screenshot / console / network / wait_for)以只读档注册、不再逐次弹审批卡。' +
725
- '注意它看的是**你自己登录着的那台浏览器**(持久分区 persist:dsc-browser),页面上可能有你的登录态与隐私内容,按需打开。' +
726
- '点击、输入、求值这些动手动作(browser_dock)仍每次要确认。',
683
+ help: '打开后「看一眼」的工具(列视图、快照、截图、看控制台与网络、等文本出现)不再逐次弹审批卡。' +
684
+ '注意它看的是**你自己登录着的那台浏览器**,页面上可能有登录态与隐私内容,按需打开。' +
685
+ '点击、输入、求值这些动手动作仍每次要确认。',
727
686
  },
728
687
  {
729
688
  type: 'info',
730
689
  label: '说明',
731
- text: '这一档只决定「看」的工具是否注册(browser_dock_look);动手工具 browser_dock 恒为每次审批。',
690
+ text: '这一档只决定「看」的工具是否注册;动手工具恒为每次审批。',
732
691
  },
733
692
  ],
734
693
  values: () => ({ lookWithoutApproval: config.lookWithoutApproval }),
@@ -1,6 +1,7 @@
1
1
  import { Logger, defaultFormatters } from '@deepseek-ai/cordis';
2
2
  import { ensureResolveHook } from '../core/dsh-compat/resolve-hook.js';
3
3
  import { DSC_PLUGINS_DIR } from '../core/plugin-loader.js';
4
+ import { dscPath } from '../core/path-policy.js';
4
5
  export const dshCompatPlugin = {
5
6
  name: 'dsh-compat',
6
7
  inject: ['transcript'],
@@ -8,6 +9,12 @@ export const dshCompatPlugin = {
8
9
  apply(ctx) {
9
10
  // 钩子注册同步生效;loader 在挂载外部插件前还会调一次(幂等),这里兜底
10
11
  void ensureResolveHook([DSC_PLUGINS_DIR]);
12
+ // 路径归一:dsh 插件有一部分代码不走 home-paths 包,而是直接读 `$DSH_HOME`、
13
+ // 没有就拼 `~/.dsh`(cost-meter 的 store.js 就是)。兼容层开着就把 DSH_HOME
14
+ // 定到 Pneuma 的家,两种写法才落到同一个地方——否则插件的账本写进用户的 dsh 目录。
15
+ // 一律覆盖:从 dsh 终端里启动 Pneuma 会继承到 `DSH_HOME=~/.dsh`,照抄就等于
16
+ // 让插件写进 dsh 的家目录。想换 Pneuma 的家请设 `DSC_HOME`。
17
+ process.env['DSH_HOME'] = dscPath();
11
18
  // 内置 logger 管道上的桥:warn/error 镜像进 transcript(info/debug 不转,防刷屏)。
12
19
  // levels 显式放到 debug(3):exporter 缺省阈值是 info(1),warn/error 会被默认滤掉。
13
20
  // 文案经 Logger.format 还原 printf 占位符(dsh 插件习惯 warn('failed: %s', err))。