@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
@@ -76,7 +76,7 @@ export function createNetProxy(options) {
76
76
  record({ at: Date.now(), host: parsed.host, port: parsed.port, allowed: one.allowed, why: one.allowed ? '在白名单里' : one.why });
77
77
  if (!one.allowed) {
78
78
  res.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' });
79
- res.end(`dsc 沙箱代理:${parsed.host} 被阻断 —— ${one.why}。要放行请在「设置 → 沙箱」把它加进出网白名单。`);
79
+ res.end(`dsc 沙箱代理:${parsed.host} 被阻断 —— ${one.why}。要放行请在「插件中心 → 文件与命令围栏」把它加进出网白名单。`);
80
80
  return;
81
81
  }
82
82
  // 放行:按原样转发(去代理语义的 URL 前缀),流式直通不缓存
@@ -107,7 +107,7 @@ export function createNetProxy(options) {
107
107
  const one = verdict(parsed.host);
108
108
  record({ at: Date.now(), host: parsed.host, port: parsed.port, allowed: one.allowed, why: one.allowed ? '在白名单里' : one.why });
109
109
  if (!one.allowed) {
110
- const body = `dsc 沙箱代理:${parsed.host} 被阻断 —— ${one.why}。要放行请在「设置 → 沙箱」把它加进出网白名单。`;
110
+ const body = `dsc 沙箱代理:${parsed.host} 被阻断 —— ${one.why}。要放行请在「插件中心 → 文件与命令围栏」把它加进出网白名单。`;
111
111
  socket.write(`HTTP/1.1 403 Forbidden\r\ncontent-type: text/plain; charset=utf-8\r\ncontent-length: ${Buffer.byteLength(body)}\r\n\r\n${body}`);
112
112
  socket.destroy();
113
113
  return;
@@ -106,7 +106,7 @@ export declare function sandboxTmpDir(dscHome: string, cwd: string, sessionId?:
106
106
  * 解析器当成设备路径。代价是 POSIX 上文件名里含反斜杠的极少数情况会被误拒——
107
107
  * 这是有意的:安全侧宁可误拒一次让人换普通路径。
108
108
  */
109
- export declare function ntNamespaceReason(raw: string): string | null;
109
+ export declare function ntNamespaceReason(raw: string, win32?: boolean): string | null;
110
110
  /**
111
111
  * NTFS 备选数据流(ADS):`f.txt:stream` 会写到另一个「看不见的」文件里,
112
112
  * `C:\ws\ok.txt:hidden` 的可见部分仍在可写根内,判定必须看真实落点。
@@ -20,7 +20,8 @@
20
20
  */
21
21
  import { realpathSync } from 'node:fs';
22
22
  import { createHash } from 'node:crypto';
23
- import { basename, dirname, isAbsolute, join, normalize, relative, resolve } from 'node:path';
23
+ import { basename, dirname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path';
24
+ import { isEnvFamily } from '../path-policy.js';
24
25
  /** 条目树里这个插件的键,同时是设置分区 id。 */
25
26
  export const SANDBOX_CONFIG_KEY = 'sandbox';
26
27
  /** 三档(形制照 codex 的 `sandbox_mode`)。 */
@@ -243,12 +244,20 @@ const NT_NAMESPACE = /\\\\[?.]\\|\\\?\?\\/i;
243
244
  * 解析器当成设备路径。代价是 POSIX 上文件名里含反斜杠的极少数情况会被误拒——
244
245
  * 这是有意的:安全侧宁可误拒一次让人换普通路径。
245
246
  */
246
- export function ntNamespaceReason(raw) {
247
- if (NT_NAMESPACE.test(raw)) {
247
+ export function ntNamespaceReason(raw, win32 = process.platform === 'win32') {
248
+ // 形状判定必须先做,而且要把正斜杠也算进来:`//?/C:/Windows` 经 win32 normalize
249
+ // 会变成 `\\?\C:\Windows`,只认反斜杠写法时它会溜过这一关、直接进 realpath。
250
+ const shaped = win32 ? raw.replace(/\//g, '\\') : raw;
251
+ if (NT_NAMESPACE.test(shaped)) {
248
252
  return '路径里出现 Windows NT 命名空间前缀(\\\\?\\ / \\\\.\\ / \\??\\):光解析它就可能触发一次 SMB 认证并泄漏 NTLM 凭据,因此直接拒';
249
253
  }
250
- if (/globalroot/i.test(raw))
254
+ if (/globalroot/i.test(shaped))
251
255
  return '路径里出现 GLOBALROOT(NT 设备命名空间):绕过所有路径校验,直接拒';
256
+ // UNC(\\\\服务器\\共享)同样会先解析、再认证:拒绝要发生在 realpath 之前,
257
+ // 否则即使事后按「不在可写根」拒掉,SMB 认证与 NTLM 泄漏已经发生了。
258
+ if (win32 && /^\\\\[^\\?.]/.test(shaped)) {
259
+ return '路径是 UNC 网络共享(\\\\服务器\\共享):解析它就会发起 SMB 认证,先把共享映射成盘符再用';
260
+ }
252
261
  return null;
253
262
  }
254
263
  /** 8.3 短名形状(只在其所在段无法用 realpath 验证时才拒)。 */
@@ -355,11 +364,6 @@ const CREDENTIAL_BASENAMES = new Set([
355
364
  const CREDENTIAL_EXTENSIONS = ['.pem', '.key', '.pfx', '.p12', '.ppk', '.kdbx', '.keystore', '.jks', '.p8'];
356
365
  /** dsc 自己家目录下的控制文件:它们决定沙箱与审批怎么跑,模型不该能写。 */
357
366
  const DSC_CONTROL_FILES = new Set(['config.yaml', 'config.yml', 'credentials.yaml', 'credentials.yml', 'policy.rules', 'plugins.json']);
358
- /** `.env` 家族(`.env.production` 这类都算);`.env.example` 一类模板放行。 */
359
- function isEnvFamily(name) {
360
- const base = name.toLowerCase();
361
- return base.startsWith('.env') && !base.includes('example') && !base.includes('sample') && !base.includes('template');
362
- }
363
367
  /** 路径按比较口径归一:Windows 下大小写不敏感,分隔符统一成 `\`。 */
364
368
  function compareKey(path, win32) {
365
369
  const unified = path.replace(/[\\/]+/g, '\\');
@@ -458,20 +462,22 @@ export function insideRoot(child, root, win32) {
458
462
  const rel = relative(a, b);
459
463
  if (rel === '')
460
464
  return true;
461
- // 跨盘符时 relative 会返回绝对路径;`..` 开头就是在外面
462
- return !isAbsolute(rel) && !rel.startsWith('..');
465
+ // 跨盘符时 relative 会返回绝对路径;只有 `..` 本身或以 `..` + 分隔符开头才是父目录,
466
+ // 不能笼统 startsWith('..')——根内名为 `..foo` 的文件会被误判成越界。
467
+ const parent = rel === '..' || rel.startsWith(`..${sep}`);
468
+ return !isAbsolute(rel) && !parent;
463
469
  }
464
470
  /** 「怎么合法地做」的一句人话:拒因最后带上它,模型才有自救路径。 */
465
471
  export function legalWay(rule) {
466
472
  switch (rule) {
467
473
  case 'outside-writable-roots':
468
- return '把目标改到可写根内,或在「设置 → 沙箱」里把这个目录加进附加可写根;确实必须写到范围外时,在这一次调用里同时带上 sandbox_permissions 与 justification 重试(会照常弹审批卡让人点)';
474
+ return '把目标改到可写根内,或在「插件中心 → 文件与命令围栏」里把这个目录加进附加可写根;确实必须写到范围外时,在这一次调用里同时带上 sandbox_permissions 与 justification 重试(会照常弹审批卡让人点)';
469
475
  case 'protected-metadata':
470
476
  return '这类文件即便落在可写根内也拒写;确需改动请让用户手工执行,或换一个不受保护的路径';
471
477
  case 'mode-read-only':
472
- return '当前档位禁止一切写盘:在「设置 → 沙箱」把档位切到 workspace-write(工作区可写)或 danger-full-access,或改做只读的动作';
478
+ return '当前档位禁止一切写盘:在「插件中心 → 文件与命令围栏」把档位切到 workspace-write(工作区可写)或 danger-full-access,或改做只读的动作';
473
479
  case 'read-only-subpath':
474
- return '这条子路径被用户在「设置 → 沙箱」的只读清单里标了只读:改到别的路径,或请用户把它从清单里去掉';
480
+ return '这条子路径被用户在「插件中心 → 文件与命令围栏」的只读清单里标了只读:改到别的路径,或请用户把它从清单里去掉';
475
481
  case 'nt-namespace':
476
482
  return '改用普通绝对路径(例如 C:\\Users\\me\\proj\\a.txt),不要带 \\\\?\\、\\\\.\\、\\??\\ 或 GLOBALROOT';
477
483
  case 'ads-stream':
@@ -496,7 +502,7 @@ export function legalWay(rule) {
496
502
  * (那一档根本没有可写根)。
497
503
  */
498
504
  export function checkWrite(policy, raw) {
499
- const nt = ntNamespaceReason(raw);
505
+ const nt = ntNamespaceReason(raw, policy.win32);
500
506
  if (nt !== null)
501
507
  return { allowed: false, rule: 'nt-namespace', reason: nt, resolved: raw };
502
508
  const ads = adsStreamReason(raw, policy.win32);
@@ -16,6 +16,7 @@
16
16
  import { readFileSync } from 'node:fs';
17
17
  import { join } from 'node:path';
18
18
  import { addressOf, throwLastError } from './ffi.js';
19
+ import { errText as errorText } from '../../err-text.js';
19
20
  /** DPAPI 标志:禁止弹任何 UI(后台无人值守路径必须给,否则可能静默失败或卡住)。 */
20
21
  export const CRYPTPROTECT_UI_FORBIDDEN = 0x1;
21
22
  /** DATA_BLOB 的 x64 字节数:cbData(u32) + 4 字节填充 + pbData(指针)。 */
@@ -200,7 +201,3 @@ function coerceSetupState(value) {
200
201
  function stripBom(text) {
201
202
  return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
202
203
  }
203
- /** 异常转一句话。 */
204
- function errorText(error) {
205
- return error instanceof Error ? error.message : String(error);
206
- }
@@ -31,12 +31,7 @@ import { join } from 'node:path';
31
31
  import { ACCESS_ALLOWED_ACE_TYPE, ACCESS_DENIED_ACE_TYPE, ACL_ACE_COUNT_OFFSET, ACL_FIRST_ACE_OFFSET, ACL_REVISION, ACE_MASK_OFFSET, ACE_SID_OFFSET, CONTAINER_INHERIT_ACE, DACL_SECURITY_INFORMATION, DENY_ACCESS, EXPLICIT_ACCESS_SIZE, FILE_ATTRIBUTE_NORMAL, FILE_DELETE_CHILD, FILE_GENERIC_EXECUTE, FILE_GENERIC_READ, FILE_SHARE_READ, FILE_SHARE_WRITE, GENERIC_READ, GENERIC_WRITE, GRANT_ACCESS, GRANT_MASK, LABEL_SECURITY_INFORMATION, LOCKFILE_EXCLUSIVE_LOCK, OBJECT_INHERIT_ACE, OPEN_ALWAYS, OVERLAPPED_SIZE, REVOKE_ACCESS, SE_FILE_OBJECT, SID_MAX_BYTES, SYSTEM_MANDATORY_LABEL_ACE_TYPE, SYSTEM_MANDATORY_LABEL_NO_WRITE_UP, WinLowLabelSid, WinWorldSid, } from './abi.js';
32
32
  import { addressOf, readMemory, slotUintPtr, throwLastError, throwWin32 } from './ffi.js';
33
33
  import { packExplicitAccessSid, sidStringToBuffer, wellKnownSidBuffer } from './token.js';
34
- /** 任意字符串 → NUL 结尾的 UTF-16 缓冲(Win32 的 str16 入参口径)。 */
35
- function utf16Buffer(text) {
36
- const buffer = Buffer.alloc(text.length * 2 + 2);
37
- buffer.write(text, 0, 'utf16le');
38
- return buffer;
39
- }
34
+ import { utf16Buffer } from './utf16.js';
40
35
  /** `(HANDLE)-1`:CreateFileW 的失败哨兵值。 */
41
36
  const INVALID_HANDLE_VALUE = 0xffffffffffffffffn;
42
37
  /** 锁文件名:小写路径的 sha256 前 16 位 hex(避开路径里不合法的文件名字符)。 */
@@ -14,10 +14,12 @@ export declare function probeWindowsToken(): {
14
14
  /** 执行器构造入参(路径都要求是 realpath 规范化后的绝对路径)。 */
15
15
  export interface WindowsTokenRunnerOptions {
16
16
  mode: 'read-only' | 'workspace-write';
17
- /** 会话工作目录(常驻可写根)。 */
17
+ /**
18
+ * 挂载时所在会话的工作目录:先把它授权好,第一次调用就不必等 ACL。
19
+ *
20
+ * 它只是**起点**:常驻多会话时每次调用都按 `run.cwd` 现算可写根(2026-10-30 修)。
21
+ */
18
22
  cwd: string;
19
- /** 沙箱私有临时目录(会话结束回收授权)。 */
20
- tmpDir: string;
21
23
  /** 附加可写根。 */
22
24
  extraRoots?: readonly string[];
23
25
  /** 网络开关(每次都现取,改设置立即生效)。 */
@@ -52,6 +54,25 @@ export interface WindowsTokenRunnerHandle {
52
54
  */
53
55
  readonly networkEnforced: boolean;
54
56
  }
57
+ /** 一次调用要授权的目录与它的能力 SID。 */
58
+ export interface SandboxWriteRoot {
59
+ path: string;
60
+ sid: string;
61
+ /** root = 工作区/附加根(常驻授权,不回收);temp = 该工作区的私有临时目录(收尾回收)。 */
62
+ side: 'root' | 'temp';
63
+ }
64
+ /**
65
+ * 一次命令调用该授权的可写根(2026-10-30 修:以前按挂载时那个会话钉死)。
66
+ *
67
+ * 常驻多会话时,后台会话的工作目录与当前查看的会话往往不是同一个:钉死之后,
68
+ * 后台会话在自己的工作区里写东西会被 ACL 挡住(错误地当成「越界」),而当前会话的
69
+ * 工作区反倒被永久授权。现在按 `run.cwd` 现算:工作区一个 root SID、它的私有临时目录
70
+ * 一个 temp SID,附加可写根照配置带进来。
71
+ *
72
+ * @param cwd - 这次调用所在会话的工作目录(realpath 后的绝对路径)。
73
+ * @param extraRoots - 配置里的附加可写根。
74
+ */
75
+ export declare function writeRootsFor(cwd: string, extraRoots?: readonly string[]): SandboxWriteRoot[];
55
76
  /**
56
77
  * 建一个受限令牌执行器。
57
78
  *
@@ -29,6 +29,8 @@ import { grantAccountAccess, grantWrite, revokeWrite } from './acl.js';
29
29
  import { bindAll, tryLoadFfi } from './ffi.js';
30
30
  import { rootWriteSid, tempWriteSid } from './workspace-sid.js';
31
31
  import { createNetProxy, proxyEnvVars } from '../net-proxy.js';
32
+ import { sandboxTmpDir } from '../policy.js';
33
+ import { errText as describeError } from '../../err-text.js';
32
34
  /** 执行器 id(宿主诊断与 `enforcement` 上报用这个键)。 */
33
35
  export const WINDOWS_TOKEN_RUNNER_ID = 'sandbox-windows-token';
34
36
  /** runner 自身失败的 stderr 签名:宿主与 win-token 冒烟探针靠它把「runner 挂了」与「命令失败了」分开。 */
@@ -73,9 +75,37 @@ export function probeWindowsToken() {
73
75
  }
74
76
  return { available: true, detail: '受限令牌后端可用(koffi FFI + runner 子进程)' };
75
77
  }
76
- /** 把错误转成一行可读文本(授权失败的「错误全文」要原样报给用户)。 */
77
- function describeError(error) {
78
- return error instanceof Error ? error.message : String(error);
78
+ /**
79
+ * 一次命令调用该授权的可写根(2026-10-30 修:以前按挂载时那个会话钉死)。
80
+ *
81
+ * 常驻多会话时,后台会话的工作目录与当前查看的会话往往不是同一个:钉死之后,
82
+ * 后台会话在自己的工作区里写东西会被 ACL 挡住(错误地当成「越界」),而当前会话的
83
+ * 工作区反倒被永久授权。现在按 `run.cwd` 现算:工作区一个 root SID、它的私有临时目录
84
+ * 一个 temp SID,附加可写根照配置带进来。
85
+ *
86
+ * @param cwd - 这次调用所在会话的工作目录(realpath 后的绝对路径)。
87
+ * @param extraRoots - 配置里的附加可写根。
88
+ */
89
+ export function writeRootsFor(cwd, extraRoots = []) {
90
+ const trim = (path) => path.replace(/[\\/]+$/, '');
91
+ const list = [];
92
+ /** 同一个目录只出现一次:尾巴分隔符不同、或附加根与工作区重合,都算同一个。 */
93
+ const add = (path, side) => {
94
+ const key = path.toLowerCase();
95
+ if (list.some((item) => item.path.toLowerCase() === key))
96
+ return;
97
+ list.push({ path, sid: side === 'root' ? rootWriteSid(path) : tempWriteSid(path), side });
98
+ };
99
+ const root = trim(cwd);
100
+ add(root, 'root');
101
+ add(sandboxTmpDir(DSC_HOME, root), 'temp');
102
+ for (const extra of extraRoots) {
103
+ const trimmed = trim(extra.trim());
104
+ if (trimmed === '')
105
+ continue;
106
+ add(trimmed, 'root');
107
+ }
108
+ return list;
79
109
  }
80
110
  /**
81
111
  * 建一个受限令牌执行器。
@@ -87,20 +117,27 @@ export function createWindowsTokenRunner(options) {
87
117
  // 目录清单:工作目录、私有临时目录、附加可写根(工作区与附加根用 rootWriteSid,
88
118
  // temp 用 tempWriteSid,两种派生前缀不同,永不撞号)
89
119
  const roots = [];
90
- const push = (path, sid) => {
120
+ /** 已经授权过的临时目录(收尾时逐个回收,见 dispose)。 */
121
+ const tempPaths = new Set();
122
+ const push = (path, sid, temp) => {
91
123
  const key = path.replace(/[\\/]+$/, '').toLowerCase();
92
124
  if (roots.some((root) => root.path.replace(/[\\/]+$/, '').toLowerCase() === key))
93
125
  return;
94
126
  roots.push({ path, sid });
127
+ if (temp)
128
+ tempPaths.add(path);
95
129
  };
96
- if (options.mode === 'workspace-write') {
97
- push(options.cwd, rootWriteSid(options.cwd));
98
- push(options.tmpDir, tempWriteSid(options.tmpDir));
99
- for (const extra of options.extraRoots ?? []) {
100
- if (extra.trim() !== '')
101
- push(extra, rootWriteSid(extra));
102
- }
103
- }
130
+ /**
131
+ * 把一次调用的可写根补进清单(常驻多会话:每个会话的工作目录各授权一次)。
132
+ * 已经在清单里的路径跳过,所以每次调用都调它也只有第一次付 ACL 的成本。
133
+ */
134
+ const scopeOf = (cwd) => {
135
+ if (options.mode !== 'workspace-write')
136
+ return;
137
+ for (const root of writeRootsFor(cwd, options.extraRoots ?? []))
138
+ push(root.path, root.sid, root.side === 'temp');
139
+ };
140
+ scopeOf(options.cwd);
104
141
  // read-only 刻意不做任何 ACL 授权:该档令牌不含能力 SID,写本来就全拒;
105
142
  // 授权只会「永久改用户工作区的 ACL + 强制标签」,是纯副作用零收益,违背最小惊扰
106
143
  const entry = runnerEntryPath();
@@ -110,24 +147,31 @@ export function createWindowsTokenRunner(options) {
110
147
  let degraded = false;
111
148
  /** 本地白名单代理(账号分支且开网时惰性起,dispose 时收)。 */
112
149
  let proxy = null;
113
- /** 惰性物化授权:true = 可以换执行体,false = 已降级(此后 plan 一律返回 null)。 */
150
+ /**
151
+ * 惰性物化授权:true = 可以换执行体,false = 已降级(此后 plan 一律返回 null)。
152
+ *
153
+ * 不能「授权过一次就短路」:清单会随着不同会话的调用继续增长(见 scopeOf),
154
+ * 新补进来的根必须在这一次调用之前授权好。已授权的根在 grants 里有记录,重复调用只花几次查找。
155
+ */
114
156
  const ensureAuthorized = () => {
115
157
  if (degraded)
116
158
  return false;
117
- if (authorized)
118
- return true;
119
159
  if (roots.length === 0) {
120
160
  // read-only:没有可授权目录,连 FFI 都不必加载(dispose 靠 bound===null 短路)
121
161
  authorized = true;
122
162
  return true;
123
163
  }
164
+ if (authorized && roots.every((root) => grants.has(root.path)))
165
+ return true;
124
166
  try {
125
- const loaded = tryLoadFfi();
126
- if (!loaded.ok)
127
- throw new Error(`Win32 FFI 底座不可用:${loaded.why}`);
128
- const boundNow = bindAll(loaded.ffi);
129
- bound = boundNow;
130
- mkdirSync(LOCK_DIR, { recursive: true });
167
+ if (bound === null) {
168
+ const loaded = tryLoadFfi();
169
+ if (!loaded.ok)
170
+ throw new Error(`Win32 FFI 底座不可用:${loaded.why}`);
171
+ bound = bindAll(loaded.ffi);
172
+ mkdirSync(LOCK_DIR, { recursive: true });
173
+ }
174
+ const boundNow = bound;
131
175
  for (const root of roots) {
132
176
  if (grants.has(root.path))
133
177
  continue;
@@ -182,6 +226,9 @@ export function createWindowsTokenRunner(options) {
182
226
  id: WINDOWS_TOKEN_RUNNER_ID,
183
227
  order: RUNNER_ORDER,
184
228
  async plan(run, current) {
229
+ // 先按这次调用所在会话的工作目录补齐可写根(常驻多会话:每个工作区各授权一次),
230
+ // 再物化授权——顺序反了就会用「上一个会话的工作区」去跑这一条命令。
231
+ scopeOf(run.cwd);
185
232
  if (!ensureAuthorized())
186
233
  return null;
187
234
  // 已经是本后端换过的计划(别人套第二次):不套两层
@@ -200,7 +247,8 @@ export function createWindowsTokenRunner(options) {
200
247
  const args = [
201
248
  entry,
202
249
  '--mode', options.mode,
203
- '--temp', options.tmpDir,
250
+ // 临时目录按这次调用的工作区取(与 roots 里的 temp 同源)
251
+ '--temp', sandboxTmpDir(DSC_HOME, run.cwd.replace(/[\\/]+$/, '')),
204
252
  ...roots.flatMap((root) => ['--root', `${root.sid}=${root.path}`]),
205
253
  ...(options.account === undefined ? [] : ['--account', options.account.name, '--dsc-home', options.account.dscHome]),
206
254
  '--',
@@ -223,7 +271,9 @@ export function createWindowsTokenRunner(options) {
223
271
  if (bound === null)
224
272
  return;
225
273
  try {
226
- revokeWrite(bound, options.tmpDir, tempWriteSid(options.tmpDir), LOCK_DIR);
274
+ // 每个工作区一个临时目录,逐个回收
275
+ for (const temp of tempPaths)
276
+ revokeWrite(bound, temp, tempWriteSid(temp), LOCK_DIR);
227
277
  }
228
278
  catch (error) {
229
279
  options.onDetail?.(`回收临时目录授权失败(不影响本次结果):${describeError(error)}`);
@@ -21,6 +21,7 @@ import { accountBlobPath, readSetupState, unprotectSecret } from './account.js';
21
21
  import { firewallRuleNames, DSC_WFP_SUBLAYER_GUID } from './net-abi.js';
22
22
  import { DSC_SANDBOX_ACCOUNT, DSC_SANDBOX_DEFAULT_PROXY_PORT } from './setup.js';
23
23
  import { probeWfpSublayer } from './wfp.js';
24
+ import { errText as errorText } from '../../err-text.js';
24
25
  /** 每项的超时(查防火墙/本地账号的 cmdlet 偶尔会慢,给足 20 秒)。 */
25
26
  const ITEM_TIMEOUT_MS = 20_000;
26
27
  /**
@@ -266,7 +267,3 @@ function runPowerShell(command, timeoutMs) {
266
267
  function quotePowerShell(value) {
267
268
  return `'${value.replace(/'/g, "''")}'`;
268
269
  }
269
- /** 异常转一句话。 */
270
- function errorText(error) {
271
- return error instanceof Error ? error.message : String(error);
272
- }
@@ -33,6 +33,7 @@ import { buildRestrictedToken } from './token.js';
33
33
  import { verifySidForPath } from './workspace-sid.js';
34
34
  import { accountBlobPath, unprotectSecret } from './account.js';
35
35
  import { readFileSync } from 'node:fs';
36
+ import { utf16Buffer } from './utf16.js';
36
37
  /** runner 自身失败签名(宿主诊断认这一行)。 */
37
38
  export const RUNNER_SIGNATURE = 'dsc-sandbox-run: ';
38
39
  /** runner 自身失败的退出码。 */
@@ -191,12 +192,6 @@ export function quoteArgv(arg) {
191
192
  out += '\\'.repeat(backslashes * 2) + '"';
192
193
  return out;
193
194
  }
194
- /** 任意字符串 → NUL 结尾的 UTF-16 缓冲(Win32 的 str16 入参口径)。 */
195
- function utf16Buffer(text) {
196
- const buffer = Buffer.alloc(text.length * 2 + 2);
197
- buffer.write(text, 0, 'utf16le');
198
- return buffer;
199
- }
200
195
  /** 手工打包 STARTUPINFOW(104 字节,偏移见 abi.SI_OFFSETS)。 */
201
196
  function packStartupInfo(stdinRead, stdoutWrite, stderrWrite) {
202
197
  const info = Buffer.alloc(STARTUPINFOW_SIZE);
@@ -22,6 +22,7 @@ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
22
22
  import { join } from 'node:path';
23
23
  import { DSC_WFP_FILTERS, DSC_WFP_PROVIDER_GUID, DSC_WFP_SUBLAYER_GUID, firewallRuleSpecs, } from './net-abi.js';
24
24
  import { sandboxDir, setupErrorPath, setupScriptPath, readSetupState } from './account.js';
25
+ import { errText as errorText } from '../../err-text.js';
25
26
  /** 固定的离线沙箱账号名(普通本地账号,不是服务账号)。 */
26
27
  export const DSC_SANDBOX_ACCOUNT = 'dsc-sandbox-offline';
27
28
  /** 沙箱账号组的名字(便于以后整体清理/识别)。 */
@@ -381,10 +382,6 @@ function readSetupErrorText(dscHome) {
381
382
  return '';
382
383
  }
383
384
  }
384
- /** 异常转一句话。 */
385
- function errorText(error) {
386
- return error instanceof Error ? error.message : String(error);
387
- }
388
385
  // ── 内嵌 C#:WFP 安装器 ──────────────────────────────────────────────────────
389
386
  //
390
387
  // 为什么用 C#(而不是 koffi 直接装):装持久 filter 要管理员 + 单事务 + 一堆手写结构体,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Win32 的字符串入参口径(全仓库唯一一份)。
3
+ *
4
+ * Win32 的 `PCWSTR` / `str16` 要的是 NUL 结尾的 UTF-16 缓冲;不结尾时 API 会
5
+ * 一路读到未映射内存。`sandbox/win/acl.ts` 与 `sandbox/win/runner-entry.ts`
6
+ * 此前各写了一份逐字相同的实现。
7
+ *
8
+ * @module dsc/core/sandbox/win/utf16
9
+ */
10
+ /** 任意字符串 → NUL 结尾的 UTF-16 缓冲(Win32 的 str16 入参口径)。 */
11
+ export declare function utf16Buffer(text: string): Buffer;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Win32 的字符串入参口径(全仓库唯一一份)。
3
+ *
4
+ * Win32 的 `PCWSTR` / `str16` 要的是 NUL 结尾的 UTF-16 缓冲;不结尾时 API 会
5
+ * 一路读到未映射内存。`sandbox/win/acl.ts` 与 `sandbox/win/runner-entry.ts`
6
+ * 此前各写了一份逐字相同的实现。
7
+ *
8
+ * @module dsc/core/sandbox/win/utf16
9
+ */
10
+ /** 任意字符串 → NUL 结尾的 UTF-16 缓冲(Win32 的 str16 入参口径)。 */
11
+ export function utf16Buffer(text) {
12
+ const buffer = Buffer.alloc(text.length * 2 + 2);
13
+ buffer.write(text, 0, 'utf16le');
14
+ return buffer;
15
+ }
@@ -21,6 +21,7 @@
21
21
  */
22
22
  import { bindAll, loadFfi, slotUintPtr } from './ffi.js';
23
23
  import { DSC_WFP_SUBLAYER_GUID, FWPM_LAYER_ALE_AUTH_CONNECT_V4, FWP_E_ALREADY_EXISTS, FWP_E_FILTER_NOT_FOUND, FWP_E_IN_USE, FWP_E_LAYER_NOT_FOUND, FWP_E_LOOKUP_MISSING, FWP_E_NOT_FOUND, FWP_E_PROVIDER_NOT_FOUND, FWP_E_SUBLAYER_NOT_FOUND, RPC_C_AUTHN_WINNT, } from './net-abi.js';
24
+ import { errText as errorText } from '../../err-text.js';
24
25
  let cachedBindings = null;
25
26
  /** 装载绑定;失败返回 `{ok:false}`(探测路径不抛)。 */
26
27
  function loadWfpBindings() {
@@ -194,7 +195,3 @@ function win32ErrorText(bound, code) {
194
195
  return '';
195
196
  }
196
197
  }
197
- /** 异常转一句话。 */
198
- function errorText(error) {
199
- return error instanceof Error ? error.message : String(error);
200
- }
@@ -1,20 +1,3 @@
1
- /**
2
- * 定时任务的选择器:六种触发规则的解析、下一次触发时刻的计算,以及「本地墙上时刻 ↔ 绝对时刻」
3
- * 的换算。整份文件是纯函数——不碰文件系统、不读 ctx、不缓存任何跨任务状态(时区格式化器除外),
4
- * 所以能脱离宿主单独跑自检。
5
- *
6
- * 为什么这么设计:
7
- * 1. **时间一律用绝对毫秒数(epoch ms)表示**,人读的「09:30」只在解析和显示时出现。
8
- * 存绝对时刻能让「机器睡了两小时」和「时区改了」这两件事都变成一次减法。
9
- * 2. **没有 Temporal**(Node 24 才有),所以用 `Intl.DateTimeFormat` 反解时区偏移:
10
- * 把某一瞬间按目标时区格式化出墙上时刻,再和 UTC 的同一串数字相减,差就是偏移。
11
- * 时区库(如 luxon)会引入 npm 依赖,dsc 插件不许带依赖,所以走内置 ICU。
12
- * 3. **DST 两条规则是入参,不是副作用**:gap(夏令时跳表里不存在的本地时刻)算「没有这一次」,
13
- * 返回 null 让调用方跳过;overlap(秋天重复的那一小时)只取较早的那一次。
14
- * 这两个规则写在 wallTimeToInstant 里,所有选择器共用,不许各自再判一遍。
15
- *
16
- * @module dsc/core/schedule/rule
17
- */
18
1
  /** 六种选择器。 */
19
2
  export type ScheduleRuleKind = 'after' | 'at' | 'every' | 'daily' | 'weekly' | 'cron';
20
3
  /** 六种选择器的名字(给工具描述与报错文案用)。 */
@@ -15,6 +15,7 @@
15
15
  *
16
16
  * @module dsc/core/schedule/rule
17
17
  */
18
+ import { isFiniteNumber } from '../clamp.js';
18
19
  /** 六种选择器的名字(给工具描述与报错文案用)。 */
19
20
  export const SCHEDULE_RULE_KINDS = ['after', 'at', 'every', 'daily', 'weekly', 'cron'];
20
21
  /** `every` 的间隔下限(秒):比一分钟更密的提醒用提醒本身没有意义,只会烧模型额度。 */
@@ -689,9 +690,6 @@ export function describeNext(rule, timeZone, nextMs) {
689
690
  return `下次 ${formatInstant(nextMs, timeZone)}(${timeZone})`;
690
691
  }
691
692
  // ── 反序列化 ──────────────────────────────────────────────────────────────────
692
- function isFiniteNumber(value) {
693
- return typeof value === 'number' && Number.isFinite(value);
694
- }
695
693
  /**
696
694
  * 把磁盘上读回来的东西收敛成一条合法规则;认不出就返回 null(调用方跳过这条任务并记账)。
697
695
  * 磁盘上的文件是用户能手改的,属于不可信输入,所以每个字段都要过一遍。
@@ -122,7 +122,10 @@ export declare class ScheduleRunner {
122
122
  private ticking;
123
123
  private lock;
124
124
  private lockNoticed;
125
- /** 已经投出去、还在等 `dsc/turn-end` 的那些投递(先进先出)。 */
125
+ /**
126
+ * 已经投出去、还在等 `dsc/turn-end` 的那些投递。按 sessionId 配对,
127
+ * 不能只看先后:后台会话的回合结束也会发这个事件,FIFO 会把别人的投递记账到自己头上。
128
+ */
126
129
  private readonly deliveries;
127
130
  /** 每条任务已经用掉几档重试。 */
128
131
  private readonly retryRungs;
@@ -150,7 +153,7 @@ export declare class ScheduleRunner {
150
153
  * error → 按错误原文分类,配额停到恢复点、瞬时错走阶梯;
151
154
  * aborted → 用户中断,既不清零也不升级。
152
155
  */
153
- noteTurnEnd(reason: 'completed' | 'aborted' | 'error'): void;
156
+ noteTurnEnd(reason: 'completed' | 'aborted' | 'error', sessionId?: string): void;
154
157
  /** 一句现状(设置分区、命令页脚共用)。 */
155
158
  describeState(): string;
156
159
  /** 悬空槽位补投:推进了却没投出去的那一次,只补一次。 */
@@ -29,7 +29,7 @@
29
29
  */
30
30
  import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
31
31
  import { formatDuration, formatInstant, graceMs, isOneShot, nextRunAt } from './rule.js';
32
- import { errorText } from './store.js';
32
+ import { errText as errorText } from '../err-text.js';
33
33
  /** 一次定时器最多睡多久:超长延迟分段,避开 setTimeout 的 32 位溢出。 */
34
34
  export const TIMER_SLICE_MS = 6 * 3600_000;
35
35
  /** 「完全没到模型」的瞬时网络错重试阶梯:5 / 15 / 30 分钟(照 Claude Cowork 那三级)。 */
@@ -226,7 +226,10 @@ export class ScheduleRunner {
226
226
  ticking = false;
227
227
  lock = null;
228
228
  lockNoticed = false;
229
- /** 已经投出去、还在等 `dsc/turn-end` 的那些投递(先进先出)。 */
229
+ /**
230
+ * 已经投出去、还在等 `dsc/turn-end` 的那些投递。按 sessionId 配对,
231
+ * 不能只看先后:后台会话的回合结束也会发这个事件,FIFO 会把别人的投递记账到自己头上。
232
+ */
230
233
  deliveries = [];
231
234
  /** 每条任务已经用掉几档重试。 */
232
235
  retryRungs = new Map();
@@ -337,8 +340,12 @@ export class ScheduleRunner {
337
340
  * error → 按错误原文分类,配额停到恢复点、瞬时错走阶梯;
338
341
  * aborted → 用户中断,既不清零也不升级。
339
342
  */
340
- noteTurnEnd(reason) {
341
- const delivery = this.deliveries.shift();
343
+ noteTurnEnd(reason, sessionId) {
344
+ // 带会话归属时只配同会话的投递;不带(旧调用点/自检)退回 FIFO。
345
+ const index = sessionId === undefined ? 0 : this.deliveries.findIndex((entry) => entry.sessionId === sessionId);
346
+ if (index < 0)
347
+ return;
348
+ const delivery = this.deliveries.splice(index, 1)[0];
342
349
  if (delivery === undefined)
343
350
  return;
344
351
  const task = this.deps.store.get(delivery.id);
@@ -458,11 +465,18 @@ export class ScheduleRunner {
458
465
  /** pre-dispatch 校验:返回非 null 就是**不能投**的原因(一次模型请求都不会发)。 */
459
466
  preflight(task) {
460
467
  let sessionId = '';
461
- try {
462
- sessionId = this.deps.sessionId();
468
+ // 任务自带目标会话时以它为准;老任务没存 sessionId 才回落到「当前会话」。
469
+ // 这里只判「有没有目标」,目标是不是还活着交给 deliver 时的 dormant 写入口处理。
470
+ if (task.sessionId !== '') {
471
+ sessionId = task.sessionId;
463
472
  }
464
- catch (error) {
465
- return `投递目标未知:读不到当前会话(${errorText(error)})`;
473
+ else {
474
+ try {
475
+ sessionId = this.deps.sessionId();
476
+ }
477
+ catch (error) {
478
+ return `投递目标未知:读不到当前会话(${errorText(error)})`;
479
+ }
466
480
  }
467
481
  if (sessionId === '')
468
482
  return '投递目标未知:当前没有打开的会话,定时任务没有地方投';
@@ -515,7 +529,16 @@ export class ScheduleRunner {
515
529
  this.note(`定时任务「${task.title}」投递失败:${message};${plan.detail}`);
516
530
  return;
517
531
  }
518
- this.deliveries.push({ id: task.id, at: now });
532
+ let targetSession = task.sessionId;
533
+ if (targetSession === '') {
534
+ try {
535
+ targetSession = this.deps.sessionId();
536
+ }
537
+ catch {
538
+ targetSession = '';
539
+ }
540
+ }
541
+ this.deliveries.push({ id: task.id, at: now, sessionId: targetSession });
519
542
  await this.deps.store.endSlot(task.id, { status: 'ok', error: null, delivered: true });
520
543
  await this.retireFinishedOneShot(task, next);
521
544
  await this.deps.store.appendRun({ at: now, id: task.id, title: task.title, slot, status: kind === 'manual' ? 'manual' : 'ok', detail: kind });
@@ -178,5 +178,3 @@ export declare class ScheduleStore {
178
178
  /** 读盘 / 落盘时顺手裁一下历史(老文件里可能积了很多)。 */
179
179
  private trimHistory;
180
180
  }
181
- /** 把 catch 到的东西变成一句话(`useUnknownInCatchVariables` 下不能直接当 Error 用)。 */
182
- export declare function errorText(error: unknown): string;
@@ -20,6 +20,8 @@ import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync, rena
20
20
  import { join } from 'node:path';
21
21
  import { isValidTimeZone, normalizeRule } from './rule.js';
22
22
  import { dscPath } from '../path-policy.js';
23
+ import { errText as errorText } from '../err-text.js';
24
+ import { isFiniteNumber } from '../clamp.js';
23
25
  /** 台账默认保留条数。再多也没人看,还会把文件撑到几兆。 */
24
26
  export const DEFAULT_RUN_LIMIT = 1_000;
25
27
  /** 投递历史默认保留条数。 */
@@ -31,9 +33,6 @@ export function scheduleDir() {
31
33
  const home = process.env.DSC_HOME ?? dscPath();
32
34
  return join(home, 'schedule');
33
35
  }
34
- function isFiniteNumber(value) {
35
- return typeof value === 'number' && Number.isFinite(value);
36
- }
37
36
  /** 建一个新任务 id:时间有序(列表好读)+ 4 位随机(同一毫秒也不会撞)。 */
38
37
  function newTaskId() {
39
38
  return `sched-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`;
@@ -447,9 +446,3 @@ export class ScheduleStore {
447
446
  return { ...task, deliveryHistory: kept.slice(Math.max(0, kept.length - this.historyLimit)) };
448
447
  }
449
448
  }
450
- /** 把 catch 到的东西变成一句话(`useUnknownInCatchVariables` 下不能直接当 Error 用)。 */
451
- export function errorText(error) {
452
- if (error instanceof Error)
453
- return error.message;
454
- return String(error);
455
- }