@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
@@ -32,12 +32,19 @@ import { argsSummary, callFacts, stripBaseline } from '../core/tools.js';
32
32
  import { summarizeChange } from '../core/tools/fs-tools.js';
33
33
  import { SANDBOX_PERMISSION_EFFECT, readSandboxRequest } from '../core/tools/sandbox-args.js';
34
34
  import { REJECTED_TOOL_TEXT } from '../core/session.js';
35
+ import { permissionOf, writePermissions } from '../core/permission-scope.js';
35
36
  import { resolvePluginConfig } from '../core/plugin-registry.js';
36
37
  import { toolApprovalGuard } from '../core/tool-guards.js';
37
38
  import { activeRules, appendRule, classifyCommand, reloadActiveRules } from '../core/command-policy.js';
38
39
  import { isInsideCwd, isProtectedInstruction, writeHardBlockReason } from '../core/path-policy.js';
39
40
  import { audit } from '../core/audit.js';
40
41
  import { redact } from '../core/secrets.js';
42
+ import { callMeaning } from '../core/call-meaning.js';
43
+ import { appendUsageRecord } from '../core/usage-log.js';
44
+ import { SUMMARY_BANNER } from '../core/compact-anchors.js';
45
+ import { TEAMMATE_REPORT_OPEN } from '../core/team-board.js';
46
+ import { TODO_REMINDER_TEXT } from '../core/todo-reminder.js';
47
+ import { contentText } from '../core/llm.js';
41
48
  /** 配置键(`~/.dsc/plugins.json` 条目树里 `file` 等于这个名字那一项的 `config`)。 */
42
49
  const CONFIG_KEY = 'approval';
43
50
  /** 审批卡等多久没人答就按拒处理(抄 Hermes 的 approvals.timeout 默认 300s);配置没给时用这个。 */
@@ -71,17 +78,6 @@ const REVIEWER_OPTIONS = [
71
78
  hint: '要问的事先给模型判官看:判放行就直接过,判高风险或判不出来再落回你的审批卡',
72
79
  },
73
80
  ];
74
- /** 权限模式的中文长说法(通知、审计与设置回执共用一份,免得三处各写一套)。 */
75
- function policyLabel(policy) {
76
- switch (policy) {
77
- case 'readonly':
78
- return '仅查看(读类操作放行,写/执行类一律拒绝)';
79
- case 'auto-edit':
80
- return '工作区自动编辑(工作区内写操作自动放行,其余审批)';
81
- default:
82
- return '完全访问(全部工具自动放行,灾难性命令仍然拒)';
83
- }
84
- }
85
81
  /** 写类工具里「目标在工作区内就能自动放行」的那几个。 */
86
82
  const PATH_WRITE_TOOLS = new Set(['write', 'edit']);
87
83
  /**
@@ -158,17 +154,68 @@ export async function approvalDiffOf(request) {
158
154
  ...(mismatch !== undefined ? { mismatch } : {}),
159
155
  };
160
156
  }
157
+ /** 复核时最多带上多少字用户原话:再多读者就分不清这是「这一轮的请求」还是整篇文档。 */
158
+ const REVIEW_USER_QUOTE_CHARS = 500;
159
+ /**
160
+ * 发起这次调用的会话里,用户这一轮到底说了什么。
161
+ *
162
+ * 从最后一条往前找真人 user 消息,跳过程序注入的几类(环境快照、todo 提醒、
163
+ * 钩子产出、队友汇报、压缩摘要)。这些消息也是 user 角色,但它们是程序写的,
164
+ * 拿它们当「用户原话」会让判官把系统的提醒当成用户的要求。
165
+ *
166
+ * 环境快照的「这是程序自动附上」那句话在正文**末尾**(前面是环境正文),
167
+ * 所以这里用 includes 而不是 startsWith;其余几类都按开头认。
168
+ */
169
+ function lastUserWords(session) {
170
+ for (let i = session.messages.length - 1; i >= 0; i -= 1) {
171
+ const message = session.messages[i];
172
+ if (message.role !== 'user')
173
+ continue;
174
+ const text = contentText(message.content).trim();
175
+ if (text === '')
176
+ continue;
177
+ if (text === TODO_REMINDER_TEXT)
178
+ continue;
179
+ if (text.includes('(本条是程序在每次请求时自动附上的当前环境快照'))
180
+ continue;
181
+ if (text.startsWith('<external_content source="hook:'))
182
+ continue;
183
+ if (text.startsWith(TEAMMATE_REPORT_OPEN))
184
+ continue;
185
+ if (text.startsWith(SUMMARY_BANNER))
186
+ continue;
187
+ return text.length > REVIEW_USER_QUOTE_CHARS ? text.slice(0, REVIEW_USER_QUOTE_CHARS) : text;
188
+ }
189
+ return '';
190
+ }
161
191
  export const approvalPlugin = {
162
192
  name: 'approval',
163
193
  inject: ['llm', 'session', 'guards', 'surfaces', 'waiting'],
164
194
  provide: 'approval',
165
195
  apply(ctx, passed) {
166
- let policy = 'auto-edit';
196
+ /**
197
+ * 三项权限**按会话**读(2026-10-28):这里不再是进程级变量。
198
+ * 会话没钉过时用偏好里的默认值,并在第一次读时钉进会话(见 core/permission-scope)。
199
+ */
200
+ const defaultPolicy = () => ctx.get('settings')?.prefs().defaultPolicy ?? 'auto-edit';
167
201
  /**
168
202
  * 「要问的事先给谁看」——与权限模式正交的一根轴。
169
203
  * `user` = 弹卡等用户点(出厂默认);`auto-review` = 先给模型判官,判不出来再落人工卡。
170
204
  */
171
- let reviewer = 'user';
205
+ const defaultReviewer = () => ctx.get('settings')?.prefs().defaultReviewer ?? 'user';
206
+ /** 这次判定属于哪个会话:请求带了路径就找那个常驻会话,否则看当前查看的。 */
207
+ const sessionOf = (sessionPath) => {
208
+ if (sessionPath !== undefined && sessionPath !== '') {
209
+ const found = ctx.get('agent')?.sessionFor(sessionPath);
210
+ if (found !== undefined)
211
+ return found;
212
+ }
213
+ return ctx.session.current();
214
+ };
215
+ /** 某个会话现在生效的权限模式。 */
216
+ const policyOf = (session) => permissionOf(session, 'policy', defaultPolicy());
217
+ /** 某个会话现在生效的审阅者。 */
218
+ const reviewerOf = (session) => permissionOf(session, 'reviewer', defaultReviewer());
172
219
  // 每次弹卡现读:改了等待时限不必重启宿主,下一张卡就用新值。
173
220
  const timeoutMs = () => readTimeout(passed);
174
221
  /**
@@ -189,6 +236,17 @@ export const approvalPlugin = {
189
236
  reloadRules();
190
237
  /** 当前会话 id(授权键与审计都挂在它下面)。 */
191
238
  const sessionId = () => ctx.session.current().meta.id;
239
+ /**
240
+ * 只取一句话(到第一个句号或换行为止)。
241
+ *
242
+ * 沙箱守卫的越界说明里带着「可写根:D:\dsh、D:\dsc\…\tmp\<uuid>」这一长串——那是给
243
+ * 排查用的,摆在卡片上换来的是用户根本读不完的一行字。卡片要的是「哪个路径不在范围内」,
244
+ * 后面那一串留在工具结果里。
245
+ */
246
+ function firstSentence(text) {
247
+ const cut = text.search(/[。\n]/);
248
+ return cut < 0 ? text : text.slice(0, cut);
249
+ }
192
250
  /** 这次判定属于哪个会话:请求带了发起方就按发起方(0.6.48 多 agent),否则看当前查看的。 */
193
251
  const sidOf = (request) => request.sessionId ?? sessionId();
194
252
  /** 这次判定的会话 jsonl 路径(侧栏状态点的键口径)。 */
@@ -242,6 +300,12 @@ export const approvalPlugin = {
242
300
  };
243
301
  /** 挂起人工审批卡:等到答案、等到超时、或等到本轮被打断。 */
244
302
  const askHuman = (request, signal, input) => new Promise((resolveDone) => {
303
+ // 已经中止就是「这一轮已经取消」:这时再登记卡,abort 事件不会补发(EventTarget 语义),
304
+ // 卡要挂满超时才自解,用户看到的是一张没人管的幽灵卡。所以先看信号再决定要不要登记。
305
+ if (signal.aborted) {
306
+ resolveDone('reject');
307
+ return;
308
+ }
245
309
  // 没人能回答就不弹卡:超时按拒是同一条结论,只是早 300 秒给出,并且理由说清了为什么。
246
310
  if (!someoneCanAnswer()) {
247
311
  autoLog('auto-deny', request, '当前没有界面能回答审批卡(没有终端界面,也没有桌面客户端),按拒处理');
@@ -253,16 +317,17 @@ export const approvalPlugin = {
253
317
  const view = {
254
318
  id,
255
319
  toolName: request.toolName,
256
- argsSummary: redact(request.argsSummary),
320
+ argsSummary: redact(input.summary),
321
+ ...(input.meaning === null ? {} : { meaning: input.meaning }),
257
322
  reason: input.reason,
258
323
  risk: input.risk,
259
324
  suggestedRule: input.suggestedRule,
260
325
  hardline: input.hardline,
261
326
  scopes: input.scopes,
262
327
  ...(input.escalation === null ? {} : { escalation: input.escalation }),
263
- policy,
264
- reviewer,
265
- mode: modeForCard,
328
+ policy: input.policy,
329
+ reviewer: input.reviewer,
330
+ mode: input.mode,
266
331
  // 发起会话归属(0.6.49):卡片是全局渲染的,后台会话的卡弹出来时界面要标得清是谁家的
267
332
  sessionPath: pathOf(request),
268
333
  ...(input.diff === null ? {} : { diff: input.diff }),
@@ -275,8 +340,8 @@ export const approvalPlugin = {
275
340
  tool: request.toolName,
276
341
  summary: view.argsSummary,
277
342
  reason: input.reason,
278
- policy,
279
- mode: view.mode,
343
+ policy: input.policy,
344
+ mode: input.mode,
280
345
  sessionId: sid,
281
346
  cwd: request.cwd,
282
347
  });
@@ -301,8 +366,8 @@ export const approvalPlugin = {
301
366
  summary: view.argsSummary,
302
367
  decision: decision === 'reject' ? (phase === 'decided' ? 'reject' : phase) : decision,
303
368
  reason: input.reason,
304
- policy,
305
- mode: view.mode,
369
+ policy: input.policy,
370
+ mode: input.mode,
306
371
  sessionId: sid,
307
372
  ...(source === undefined ? {} : { source }),
308
373
  });
@@ -332,8 +397,8 @@ export const approvalPlugin = {
332
397
  tool: request.toolName,
333
398
  summary: redact(request.argsSummary),
334
399
  reason,
335
- policy,
336
- mode: modeForCard,
400
+ policy: policyOf(sessionOf(request.sessionPath)),
401
+ mode: ctx.get('mode')?.modeFor(sidOf(request)) ?? modeForCard,
337
402
  sessionId: sidOf(request),
338
403
  cwd: request.cwd,
339
404
  ...extra,
@@ -344,10 +409,21 @@ export const approvalPlugin = {
344
409
  * 风险分类照 Codex 的 guardian policy(数据外泄 / 凭据探测 / 持久性安全弱化 /
345
410
  * 破坏性动作 / 低风险白名单,`prompts/templates/guardian/policy.md`)。
346
411
  * 判到 high 或 critical 一律回落到人工卡——AI 不许替用户承担这个责任。
412
+ *
413
+ * 三种结局都要留痕:判官放行、判官否决、判官没跑完。少了任何一条,用户看到卡
414
+ * 就查不出「凭什么没自动过」——0.7.1 的实况是 91a667f5 会话弹了 3 张卡、审计里
415
+ * 0 条 auto-deny,连是不是判官挂了都答不上来。
347
416
  */
348
417
  const aiReview = async (request, signal) => {
349
418
  try {
350
- const route = ctx.llm.route();
419
+ // 判官跑在「发起这次调用的会话」的模型上(后台会话不拿当前视图的模型)
420
+ const reviewSession = sessionOf(request.sessionPath);
421
+ const route = ctx.llm.routeForSession(reviewSession);
422
+ // 判官要判断「用户有没有明确要求」,光看工具名与参数只能猜:把这一轮用户的原话
423
+ // 带上,它才知道这次调用是用户点名的、还是模型自己扩出来的。
424
+ const userWords = lastUserWords(reviewSession);
425
+ const startedAt = Date.now();
426
+ let firstDeltaAt = null;
351
427
  const result = await ctx.llm.stream(route.api, {
352
428
  baseUrl: route.baseUrl,
353
429
  apiKey: route.apiKey,
@@ -368,70 +444,128 @@ export const approvalPlugin = {
368
444
  '- 破坏性动作:递归删除、强推、清库、销毁基础设施、覆盖未读过的文件;\n' +
369
445
  '- 低风险:读文件、查状态、跑测试、工作目录内的常规改动。\n' +
370
446
  '判断要点:用户这一轮有没有明确要求做这件事?范围有没有被扩大?\n' +
447
+ '判断「用户有没有明确要求」以下面那段用户原话为准;用户自己点过名的本地路径,读它属于低风险。\n' +
371
448
  '只输出一个 JSON:{"risk":"low|medium|high|critical","authorized":true|false,"reason":"一句话中文理由"}',
372
449
  },
373
450
  {
374
451
  role: 'user',
375
- content: redact(`工具:${request.toolName}\n参数:${JSON.stringify(request.args ?? request.argsSummary)}\n工作目录:${baseCwd(request)}`),
452
+ content: redact(`工具:${request.toolName}\n参数:${JSON.stringify(request.args ?? request.argsSummary)}\n工作目录:${baseCwd(request)}` +
453
+ (userWords === '' ? '' : `\n用户这一轮的原话:${userWords}`)),
376
454
  },
377
455
  ],
378
- }, { onDelta: () => { } });
456
+ }, {
457
+ onDelta: () => {
458
+ if (firstDeltaAt === null)
459
+ firstDeltaAt = Date.now();
460
+ },
461
+ });
462
+ const finishedAt = Date.now();
463
+ // 判官这次请求也是真花掉的钱:有 usage 就按同一本账记一笔。记账放在解析裁决
464
+ // 之前(判官答非所问也照样计费),整段包在 try 里——少一条统计无所谓,
465
+ // 绝不能让记账改变复核结论或异常分支。
466
+ try {
467
+ if (result.usage) {
468
+ appendUsageRecord({
469
+ // route 里没有端点名,端点取这条会话现在生效的那一个(与请求实发的一路)
470
+ provider: ctx.llm.providerOf(reviewSession),
471
+ model: route.model,
472
+ i: result.usage.inputTokens,
473
+ o: result.usage.outputTokens,
474
+ ...(result.usage.cacheHitTokens === undefined ? {} : { ch: result.usage.cacheHitTokens }),
475
+ ...(result.usage.cacheMissTokens === undefined ? {} : { cm: result.usage.cacheMissTokens }),
476
+ sid: request.sessionId ?? reviewSession.meta.id,
477
+ lm: finishedAt - startedAt,
478
+ ...(firstDeltaAt === null ? {} : { ft: firstDeltaAt - startedAt, d: finishedAt - firstDeltaAt }),
479
+ });
480
+ }
481
+ }
482
+ catch {
483
+ // 记账失败(端点名取不到等)不打断复核
484
+ }
379
485
  const raw = result.text.slice(result.text.indexOf('{'), result.text.lastIndexOf('}') + 1);
380
486
  const verdict = JSON.parse(raw);
381
- const risk = verdict.risk === 'critical' || verdict.risk === 'high' ? 'high' : 'low';
382
- if (risk === 'high') {
383
- autoLog('auto-deny', request, `AI 审查判为高风险:${verdict.reason ?? '未说明'}`);
384
- return null; // 回落到人工卡
487
+ // 只有 high / critical 必须落回人工卡;medium 与 low 走同一条路(放行),
488
+ // 所以这里是个布尔而不是三档——别把它读成「medium 被降级」。
489
+ const highRisk = verdict.risk === 'critical' || verdict.risk === 'high';
490
+ if (highRisk) {
491
+ const why = verdict.reason ?? '未说明';
492
+ autoLog('auto-deny', request, `AI 审查判为高风险:${why}`);
493
+ return { decision: null, note: `AI 复核判为高风险:${why}`, failed: false };
494
+ }
495
+ if (verdict.authorized === false) {
496
+ const why = verdict.reason?.trim() ?? '';
497
+ const said = why === '' ? '判官没给理由' : why;
498
+ autoLog('auto-deny', request, `AI 复核判不放行:${said}`);
499
+ return { decision: null, note: `AI 复核判不放行:${said}`, failed: false };
385
500
  }
386
- if (verdict.authorized === false)
387
- return null;
388
- return 'allow-once';
501
+ autoLog('auto-allow', request, 'AI 复核放行');
502
+ return { decision: 'allow-once', note: 'AI 复核放行', failed: false };
389
503
  }
390
- catch {
391
- return null;
504
+ catch (error) {
505
+ const why = error instanceof Error ? error.message : String(error);
506
+ // 这一轮被用户打断:不是判官的问题,也别写成「回落到人工卡」——卡不会弹。
507
+ if (signal.aborted) {
508
+ autoLog('auto-deny', request, `AI 复核被这一轮的中止打断:${why}`);
509
+ return { decision: null, note: `AI 复核被中止(${why}),这次不执行`, failed: true };
510
+ }
511
+ // 判官超时、网络断、返回的不是 JSON:都算「没跑完」。这一类的去向由上面的调用方定
512
+ // (判官缺席就按权限档自己的结论走),这里只负责把原因写清楚。
513
+ autoLog('auto-deny', request, `AI 复核没跑完:${why}(这次不按复核否决处理)`);
514
+ return { decision: null, note: `AI 复核没跑完(${why}),这次交给你决定`, failed: true };
392
515
  }
393
516
  };
394
517
  const service = {
395
518
  get policy() {
396
- return policy;
519
+ return policyOf(ctx.session.current());
397
520
  },
398
521
  setPolicy(next) {
399
- policy = next;
400
- // dsc/notice → transcript 写 system 条目(避免与 transcript 的循环依赖)
401
- ctx.emit('dsc/notice', `权限模式切换为「${policyLabel(next)}」`);
522
+ writePermissions(ctx.session.current(), { policy: next });
523
+ // 不往对话里写「权限模式切换为…」(2026-10-28 用户报障):启动时 settings 与
524
+ // permission-presets 会各自按偏好复算一遍,同一组值能被写两三行;而这些值在输入框
525
+ // 那颗旋钮上一直看得见。要留痕的是审计(下一行),不是对话流。用户主动切换的回执
526
+ // 由调用方给:界面走 permission-presets 的那一句,斜杠命令由 commands 自己写。
402
527
  audit({
403
528
  ts: Date.now(),
404
529
  kind: 'mode-change',
405
530
  reason: `权限模式 → ${next}`,
406
531
  policy: next,
407
- mode: modeForCard,
532
+ mode: ctx.get('mode')?.modeFor(sessionId()) ?? modeForCard,
408
533
  sessionId: sessionId(),
409
534
  });
410
535
  },
411
536
  get reviewer() {
412
- return reviewer;
537
+ return reviewerOf(ctx.session.current());
413
538
  },
414
539
  setReviewer(next) {
415
- reviewer = next;
416
- const label = REVIEWER_OPTIONS.find((item) => item.id === next)?.label ?? next;
417
- ctx.emit('dsc/notice', `审批审阅者切换为「${label}」${next === 'auto-review' ? ':要问的事先给模型判官,判不出来仍会问你' : ''}`);
540
+ writePermissions(ctx.session.current(), { reviewer: next });
541
+ // 与 setPolicy 同一条理由:这行曾是「新会话一进来就刷四五行」的一半噪声。
418
542
  audit({
419
543
  ts: Date.now(),
420
544
  kind: 'mode-change',
421
545
  reason: `审批审阅者 → ${next}`,
422
- policy,
423
- mode: modeForCard,
546
+ policy: policyOf(ctx.session.current()),
547
+ mode: ctx.get('mode')?.modeFor(sessionId()) ?? modeForCard,
424
548
  sessionId: sessionId(),
425
549
  });
426
550
  },
427
551
  async decide(request, signal, options) {
428
552
  const cwd = baseCwd(request);
553
+ // 这个请求所属会话的三项权限:卡面、自动放行与审计都按它,不再读进程级变量。
554
+ const session = sessionOf(request.sessionPath);
555
+ const policy = permissionOf(session, 'policy', defaultPolicy());
556
+ const reviewer = permissionOf(session, 'reviewer', defaultReviewer());
557
+ // 卡面写「这次属于哪个模式」:按请求会话取,后台会话的卡不会标成当前视图的模式。
558
+ const cardMode = ctx.get('mode')?.modeFor(session.meta.id) ?? modeForCard;
429
559
  // 安全钩子可以要求「这一次必须问人」:非空时下面所有自动放行档一律跳过。
430
560
  const forced = options?.forceAskReason?.trim() ?? '';
431
561
  const facts = callFacts(request.args ?? {}, cwd);
432
562
  const target = facts.target ?? null;
433
563
  const command = facts.command ?? null;
434
564
  const insideCwd = target !== null && isInsideCwd(cwd, target);
565
+ // 卡片上给人看的两样东西:一行「这次要干什么」,一行命令原文。
566
+ // 命令原文直接当参数摘要用(不再套 JSON 壳),认不出命令时退回原来的摘要。
567
+ const meaning = callMeaning({ toolName: request.toolName, command, target });
568
+ const summary = command ?? request.argsSummary;
435
569
  const verdict = command === null ? null : classifyCommand(command, { rules: activeRules() });
436
570
  // 模型这次有没有在请求放宽沙箱(工具参数那条路)。有就摊到卡上,并据此收窄授权档位。
437
571
  const request0 = readSandboxRequest(request.args ?? {});
@@ -488,12 +622,19 @@ export const approvalPlugin = {
488
622
  if (forced === '' && protectedWhy === null && command !== null && floor !== undefined) {
489
623
  const prefix = floor.whitelist(command);
490
624
  if (prefix !== null) {
491
- autoLog('auto-allow', request, `命中审批灾难地板白名单「${prefix.join(' ')}」,免审批卡`);
625
+ autoLog('auto-allow', request, `命中危险命令硬拦截白名单「${prefix.join(' ')}」,免审批卡`);
492
626
  return 'allow-once';
493
627
  }
494
628
  }
629
+ // 第 4 层:沙箱边界。沙箱守卫(order 8)对「能问的越界」只 defer,
630
+ // 最后一道落在这里:越过沙箱的事一律跳过所有自动放行,直接弹卡(只给一次)。
631
+ // 这一层必须排在权限模式与审阅者之前——否则「完全访问」会把沙箱的拒绝吃掉。
632
+ const fence = ctx.get('sandbox')?.check(target ?? undefined, command ?? undefined, cwd, request.sessionPath);
633
+ const fenced = fence !== undefined && !fence.allowed;
634
+ /** 复核给出的「为什么没自动过」;null = 没跑复核,或复核放行了。要进卡片的理由。 */
635
+ let reviewNote = null;
495
636
  // 第 5 层:权限模式自己的裁决(protected 文件不参与,强制走人工卡)。
496
- if (protectedWhy === null && forced === '') {
637
+ if (protectedWhy === null && forced === '' && !fenced) {
497
638
  if (policy === 'readonly') {
498
639
  // 「仅查看」的字面意思就是只读:策略引擎判成 allow 的命令(查看目录、看 git 状态、
499
640
  // 管道里只做筛选与格式化)原样放行,只有写与执行类才一律拒。
@@ -505,43 +646,68 @@ export const approvalPlugin = {
505
646
  autoLog('auto-deny', request, '当前是「仅查看」权限模式,写与执行类工具一律拒绝');
506
647
  return 'reject';
507
648
  }
508
- if (policy === 'full-access') {
509
- autoLog('auto-allow', request, '当前是「完全访问」权限模式');
510
- return 'allow-once';
511
- }
512
- if (policy === 'auto-edit') {
513
- if (PATH_WRITE_TOOLS.has(request.toolName) && insideCwd) {
514
- autoLog('auto-allow', request, '工作区内的文件改动,按「工作区自动编辑」放行');
649
+ // 权限档自己会不会放行这一次:返回放行理由,不放行给 null。
650
+ // 单独抽出来是为了让「复核没跑完」能走同一份判断(见下),两处不必各写一遍。
651
+ const policyAutoReason = () => {
652
+ if (policy === 'full-access')
653
+ return '当前是「完全访问」权限模式';
654
+ if (policy !== 'auto-edit')
655
+ return null;
656
+ // 工作区内免卡还要沙箱同意:沙箱档位是 read-only 时,同一个路径也不许写。
657
+ // 少了这一半,只读档会先被审批放行、再被沙箱拒,模型拿到的是「自动放行失败」。
658
+ const writable = PATH_WRITE_TOOLS.has(request.toolName) && insideCwd && (fence?.allowed ?? true);
659
+ if (writable)
660
+ return '工作区内的文件改动,按「工作区自动编辑」放行';
661
+ if (verdict !== null && verdict.decision === 'allow')
662
+ return `只读命令:${verdict.reason}`;
663
+ return null;
664
+ };
665
+ // 第 5.5 层(顺序在自动放行之前,2026-10-28 修):审阅者 auto-review 时
666
+ // **每一次走到这里的事**都先给模型判官看一眼——包括「完全访问」本来会直接
667
+ // 放行的那些。判 allow 直接过;判高风险或判不放行落回第 6 层人工卡。
668
+ // 只读档在上面已经拒了,轮不到判官放宽。
669
+ if (reviewer === 'auto-review') {
670
+ const reviewed = await aiReview(request, signal);
671
+ if (reviewed.decision !== null)
672
+ return reviewed.decision;
673
+ reviewNote = reviewed.note;
674
+ // 判官**没给意见**(超时、网络断、返回的不是 JSON)不等于判官否决:
675
+ // 这时结论回到用户自己选的那一档,不能因为对方网络抖一下就让用户来点卡。
676
+ // 判官明确说不放行的(deny)不在此列,它照旧弹卡;这一轮被打断时也不放行。
677
+ const fallback = reviewed.failed && !signal.aborted ? policyAutoReason() : null;
678
+ if (fallback !== null) {
679
+ autoLog('auto-allow', request, `AI 复核没跑完,按权限档放行:${fallback}`);
515
680
  return 'allow-once';
516
681
  }
517
- if (verdict !== null && verdict.decision === 'allow') {
518
- autoLog('auto-allow', request, `只读命令:${verdict.reason}`);
682
+ }
683
+ else {
684
+ const allowed = policyAutoReason();
685
+ if (allowed !== null) {
686
+ autoLog('auto-allow', request, allowed);
519
687
  return 'allow-once';
520
688
  }
521
689
  }
522
690
  }
523
- // 第 5.5 层:审阅者。`auto-review` 时**每一次走到这里的事**都先给模型判官看一眼
524
- // ——这一步排在档位自动放行**之前**(等价于参考实现的 `strict_auto_review`),
525
- // 所以「完全访问 + AI 复核」就是旧版的「AI 审查」档:谁也不自动放行,全过模型。
526
- // 判 allow 直接过;判高风险或判不出来(含网络/超时/解析失败)落回第 6 层人工卡。
527
- if (reviewer === 'auto-review' && protectedWhy === null && forced === '') {
528
- const reviewed = await aiReview(request, signal);
529
- if (reviewed !== null) {
530
- autoLog('auto-allow', request, 'AI 复核放行');
531
- return reviewed;
532
- }
533
- }
534
691
  // 第 6 层:人工审批卡。钩子要求确认时卡片上的原因就用它,用户才知道这张卡为什么非弹不可。
535
- const reason = escalation !== null
536
- ? `模型请求放宽沙箱(${escalation.effect}):${escalation.justification}`
537
- : forced !== ''
538
- ? forced
539
- : protectedWhy !== null
540
- ? protectedWhy
541
- : (verdict?.reason ?? (insideCwd ? '工作区内的改动需要确认' : '工作区外的改动需要确认'));
542
- const risk = protectedWhy !== null ? 'high' : forced !== '' ? 'medium' : verdict?.decision === 'ask' ? 'medium' : insideCwd ? 'low' : 'medium';
692
+ const baseReason = fenced
693
+ ? `沙箱边界:${firstSentence(fence?.reason ?? '这次调用越界')}(允许这一次就破例执行,沙箱对这一次不再拦)`
694
+ : escalation !== null
695
+ ? `模型请求放宽沙箱(${escalation.effect}):${escalation.justification}`
696
+ : forced !== ''
697
+ ? forced
698
+ : protectedWhy !== null
699
+ ? protectedWhy
700
+ : (verdict?.reason ?? (insideCwd ? '工作区内的改动需要确认' : '工作区外的改动需要确认'));
701
+ // 卡上写「为什么现在才问你」:复核否决或没跑完时以它为准。命令层那句「需要授权」
702
+ // 是兜底说法,用户对着它猜不出是判官不放行还是判官挂了(0.7.1 的实况)。
703
+ const reason = reviewNote ?? baseReason;
704
+ const risk = fenced || protectedWhy !== null ? 'high' : forced !== '' ? 'medium' : verdict?.decision === 'ask' ? 'medium' : insideCwd ? 'low' : 'medium';
543
705
  const scopes = ['once'];
544
- if (escalation === null) {
706
+ // 沙箱越界只给「这一次」:放宽写边界是逐次决定,跨调用持久化没人能替用户担保。
707
+ if (fenced) {
708
+ // 只留 once
709
+ }
710
+ else if (escalation === null) {
545
711
  if (protectedWhy === null)
546
712
  scopes.push('session');
547
713
  if (suggested !== null && protectedWhy === null)
@@ -558,8 +724,13 @@ export const approvalPlugin = {
558
724
  return askHuman(request, signal, {
559
725
  reason,
560
726
  risk,
727
+ summary,
728
+ meaning,
561
729
  suggestedRule: suggested,
562
730
  scopes,
731
+ policy,
732
+ reviewer,
733
+ mode: cardMode,
563
734
  grantKey: key,
564
735
  hardline: false,
565
736
  diff,
@@ -568,10 +739,11 @@ export const approvalPlugin = {
568
739
  });
569
740
  },
570
741
  surface() {
742
+ const current = ctx.session.current();
571
743
  return {
572
- current: policy,
744
+ current: policyOf(current),
573
745
  options: [...POLICY_OPTIONS],
574
- reviewer,
746
+ reviewer: reviewerOf(current),
575
747
  reviewerOptions: [...REVIEWER_OPTIONS],
576
748
  };
577
749
  },
@@ -612,7 +784,7 @@ export const approvalPlugin = {
612
784
  tool: current.view.toolName,
613
785
  rule: current.suggestedRule,
614
786
  reason: '用户在审批卡上永久允许',
615
- policy,
787
+ policy: current.view.policy,
616
788
  sessionId: current.sessionId,
617
789
  source,
618
790
  });