@waq666/pneuma 0.0.0-stage → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (687) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -2
  3. package/bin/dsc.js +91 -0
  4. package/bin/headless.cjs +40 -0
  5. package/lib/adapter/core-runtime.d.ts +11 -0
  6. package/lib/adapter/core-runtime.js +259 -0
  7. package/lib/adapter/host.d.ts +18 -0
  8. package/lib/adapter/host.js +14 -0
  9. package/lib/adapter/runtime.d.ts +15 -0
  10. package/lib/adapter/runtime.js +290 -0
  11. package/lib/adapter/transcript.d.ts +184 -0
  12. package/lib/adapter/transcript.js +605 -0
  13. package/lib/app/AgentsOverlay.d.ts +18 -0
  14. package/lib/app/AgentsOverlay.js +63 -0
  15. package/lib/app/App.d.ts +13 -0
  16. package/lib/app/App.js +1498 -0
  17. package/lib/app/ApprovalCard.d.ts +12 -0
  18. package/lib/app/ApprovalCard.js +76 -0
  19. package/lib/app/AskCard.d.ts +20 -0
  20. package/lib/app/AskCard.js +45 -0
  21. package/lib/app/ChatView.d.ts +32 -0
  22. package/lib/app/ChatView.js +198 -0
  23. package/lib/app/Composer.d.ts +50 -0
  24. package/lib/app/Composer.js +282 -0
  25. package/lib/app/DiffBlock.d.ts +6 -0
  26. package/lib/app/DiffBlock.js +37 -0
  27. package/lib/app/MarkdownView.d.ts +6 -0
  28. package/lib/app/MarkdownView.js +99 -0
  29. package/lib/app/ModelPicker.d.ts +7 -0
  30. package/lib/app/ModelPicker.js +18 -0
  31. package/lib/app/PlanReviewCard.d.ts +13 -0
  32. package/lib/app/PlanReviewCard.js +54 -0
  33. package/lib/app/PresetPicker.d.ts +11 -0
  34. package/lib/app/PresetPicker.js +19 -0
  35. package/lib/app/PreviewOverlay.d.ts +14 -0
  36. package/lib/app/PreviewOverlay.js +22 -0
  37. package/lib/app/SessionPicker.d.ts +43 -0
  38. package/lib/app/SessionPicker.js +56 -0
  39. package/lib/app/SettingsOverlay.d.ts +32 -0
  40. package/lib/app/SettingsOverlay.js +157 -0
  41. package/lib/app/SkillsPicker.d.ts +7 -0
  42. package/lib/app/SkillsPicker.js +19 -0
  43. package/lib/app/StatusBar.d.ts +22 -0
  44. package/lib/app/StatusBar.js +272 -0
  45. package/lib/app/TaskStrips.d.ts +13 -0
  46. package/lib/app/TaskStrips.js +40 -0
  47. package/lib/app/ToolCard.d.ts +5 -0
  48. package/lib/app/ToolCard.js +40 -0
  49. package/lib/app/TranscriptOverlay.d.ts +12 -0
  50. package/lib/app/TranscriptOverlay.js +17 -0
  51. package/lib/app/Welcome.d.ts +6 -0
  52. package/lib/app/Welcome.js +66 -0
  53. package/lib/app/attach.d.ts +16 -0
  54. package/lib/app/attach.js +58 -0
  55. package/lib/app/click.d.ts +27 -0
  56. package/lib/app/click.js +89 -0
  57. package/lib/app/clipboard-image.d.ts +11 -0
  58. package/lib/app/clipboard-image.js +66 -0
  59. package/lib/app/cursor.d.ts +4 -0
  60. package/lib/app/cursor.js +24 -0
  61. package/lib/app/hello.d.ts +11 -0
  62. package/lib/app/hello.js +8 -0
  63. package/lib/app/history-store.d.ts +4 -0
  64. package/lib/app/history-store.js +41 -0
  65. package/lib/app/image-blocks.d.ts +12 -0
  66. package/lib/app/image-blocks.js +125 -0
  67. package/lib/app/markdown.d.ts +54 -0
  68. package/lib/app/markdown.js +189 -0
  69. package/lib/app/settings-model.d.ts +69 -0
  70. package/lib/app/settings-model.js +114 -0
  71. package/lib/app/theme.d.ts +166 -0
  72. package/lib/app/theme.js +141 -0
  73. package/lib/boot.d.ts +1 -0
  74. package/lib/boot.js +34 -0
  75. package/lib/commands.d.ts +49 -0
  76. package/lib/commands.js +115 -0
  77. package/lib/contract.d.ts +1973 -0
  78. package/lib/contract.js +36 -0
  79. package/lib/core/agent-roles.d.ts +52 -0
  80. package/lib/core/agent-roles.js +274 -0
  81. package/lib/core/approval-floor.d.ts +183 -0
  82. package/lib/core/approval-floor.js +679 -0
  83. package/lib/core/approval.d.ts +42 -0
  84. package/lib/core/approval.js +8 -0
  85. package/lib/core/audit.d.ts +61 -0
  86. package/lib/core/audit.js +59 -0
  87. package/lib/core/boot-notices.d.ts +6 -0
  88. package/lib/core/boot-notices.js +61 -0
  89. package/lib/core/cdp/actions.d.ts +182 -0
  90. package/lib/core/cdp/actions.js +649 -0
  91. package/lib/core/cdp/launch.d.ts +192 -0
  92. package/lib/core/cdp/launch.js +491 -0
  93. package/lib/core/cdp/snapshot.d.ts +139 -0
  94. package/lib/core/cdp/snapshot.js +316 -0
  95. package/lib/core/cdp/transport.d.ts +160 -0
  96. package/lib/core/cdp/transport.js +359 -0
  97. package/lib/core/command-policy.d.ts +108 -0
  98. package/lib/core/command-policy.js +580 -0
  99. package/lib/core/commands-completion.d.ts +78 -0
  100. package/lib/core/commands-completion.js +167 -0
  101. package/lib/core/compact-anchors.d.ts +76 -0
  102. package/lib/core/compact-anchors.js +284 -0
  103. package/lib/core/compact.d.ts +110 -0
  104. package/lib/core/compact.js +210 -0
  105. package/lib/core/config-store.d.ts +38 -0
  106. package/lib/core/config-store.js +307 -0
  107. package/lib/core/config.d.ts +36 -0
  108. package/lib/core/config.js +124 -0
  109. package/lib/core/connection-test.d.ts +60 -0
  110. package/lib/core/connection-test.js +84 -0
  111. package/lib/core/desktop-control.d.ts +298 -0
  112. package/lib/core/desktop-control.js +1311 -0
  113. package/lib/core/diff-text.d.ts +74 -0
  114. package/lib/core/diff-text.js +257 -0
  115. package/lib/core/dock-browser.d.ts +137 -0
  116. package/lib/core/dock-browser.js +146 -0
  117. package/lib/core/dock-ops.d.ts +59 -0
  118. package/lib/core/dock-ops.js +104 -0
  119. package/lib/core/dock-session.d.ts +39 -0
  120. package/lib/core/dock-session.js +28 -0
  121. package/lib/core/dsh-compat/hook.d.ts +18 -0
  122. package/lib/core/dsh-compat/hook.js +52 -0
  123. package/lib/core/dsh-compat/resolve-hook.d.ts +5 -0
  124. package/lib/core/dsh-compat/resolve-hook.js +59 -0
  125. package/lib/core/dsh-compat/tools-facade.d.ts +47 -0
  126. package/lib/core/dsh-compat/tools-facade.js +108 -0
  127. package/lib/core/err-text.d.ts +13 -0
  128. package/lib/core/err-text.js +15 -0
  129. package/lib/core/events.d.ts +149 -0
  130. package/lib/core/events.js +1 -0
  131. package/lib/core/git-exec.d.ts +23 -0
  132. package/lib/core/git-exec.js +72 -0
  133. package/lib/core/git-info.d.ts +47 -0
  134. package/lib/core/git-info.js +157 -0
  135. package/lib/core/goal.d.ts +89 -0
  136. package/lib/core/goal.js +189 -0
  137. package/lib/core/hooks.d.ts +272 -0
  138. package/lib/core/hooks.js +818 -0
  139. package/lib/core/host-browser-link.d.ts +59 -0
  140. package/lib/core/host-browser-link.js +9 -0
  141. package/lib/core/host-methods.d.ts +25 -0
  142. package/lib/core/host-methods.js +103 -0
  143. package/lib/core/image-diet.d.ts +77 -0
  144. package/lib/core/image-diet.js +127 -0
  145. package/lib/core/learnings/ledger.d.ts +73 -0
  146. package/lib/core/learnings/ledger.js +273 -0
  147. package/lib/core/learnings/skill-write.d.ts +250 -0
  148. package/lib/core/learnings/skill-write.js +854 -0
  149. package/lib/core/learnings/store.d.ts +102 -0
  150. package/lib/core/learnings/store.js +266 -0
  151. package/lib/core/lifecycle-hooks.d.ts +189 -0
  152. package/lib/core/lifecycle-hooks.js +576 -0
  153. package/lib/core/llm.d.ts +272 -0
  154. package/lib/core/llm.js +548 -0
  155. package/lib/core/lockfile.d.ts +17 -0
  156. package/lib/core/lockfile.js +110 -0
  157. package/lib/core/loop.d.ts +185 -0
  158. package/lib/core/loop.js +587 -0
  159. package/lib/core/lsp/client.d.ts +189 -0
  160. package/lib/core/lsp/client.js +690 -0
  161. package/lib/core/lsp/framing.d.ts +84 -0
  162. package/lib/core/lsp/framing.js +181 -0
  163. package/lib/core/lsp/line-shift.d.ts +28 -0
  164. package/lib/core/lsp/line-shift.js +127 -0
  165. package/lib/core/lsp/manager.d.ts +93 -0
  166. package/lib/core/lsp/manager.js +418 -0
  167. package/lib/core/lsp/normalize.d.ts +32 -0
  168. package/lib/core/lsp/normalize.js +139 -0
  169. package/lib/core/lsp/servers.d.ts +106 -0
  170. package/lib/core/lsp/servers.js +352 -0
  171. package/lib/core/lsp/uri.d.ts +76 -0
  172. package/lib/core/lsp/uri.js +179 -0
  173. package/lib/core/market.d.ts +51 -0
  174. package/lib/core/market.js +358 -0
  175. package/lib/core/mcp.d.ts +201 -0
  176. package/lib/core/mcp.js +836 -0
  177. package/lib/core/memory-eval.d.ts +158 -0
  178. package/lib/core/memory-eval.js +215 -0
  179. package/lib/core/memory.d.ts +266 -0
  180. package/lib/core/memory.js +703 -0
  181. package/lib/core/mention.d.ts +57 -0
  182. package/lib/core/mention.js +129 -0
  183. package/lib/core/microcompact.d.ts +48 -0
  184. package/lib/core/microcompact.js +79 -0
  185. package/lib/core/migrate.d.ts +56 -0
  186. package/lib/core/migrate.js +134 -0
  187. package/lib/core/model-caps.d.ts +83 -0
  188. package/lib/core/model-caps.js +150 -0
  189. package/lib/core/model-discovery.d.ts +19 -0
  190. package/lib/core/model-discovery.js +69 -0
  191. package/lib/core/modes.d.ts +72 -0
  192. package/lib/core/modes.js +152 -0
  193. package/lib/core/native-bridge.d.ts +135 -0
  194. package/lib/core/native-bridge.js +563 -0
  195. package/lib/core/path-policy.d.ts +32 -0
  196. package/lib/core/path-policy.js +248 -0
  197. package/lib/core/permission-presets.d.ts +67 -0
  198. package/lib/core/permission-presets.js +75 -0
  199. package/lib/core/plugin-loader.d.ts +36 -0
  200. package/lib/core/plugin-loader.js +294 -0
  201. package/lib/core/plugin-registry.d.ts +113 -0
  202. package/lib/core/plugin-registry.js +256 -0
  203. package/lib/core/prefs.d.ts +82 -0
  204. package/lib/core/prefs.js +372 -0
  205. package/lib/core/presets.d.ts +80 -0
  206. package/lib/core/presets.js +373 -0
  207. package/lib/core/pricing.d.ts +90 -0
  208. package/lib/core/pricing.js +126 -0
  209. package/lib/core/prompt.d.ts +92 -0
  210. package/lib/core/prompt.js +339 -0
  211. package/lib/core/ptc.d.ts +66 -0
  212. package/lib/core/ptc.js +70 -0
  213. package/lib/core/remote/frames.d.ts +91 -0
  214. package/lib/core/remote/frames.js +174 -0
  215. package/lib/core/remote/notify.d.ts +54 -0
  216. package/lib/core/remote/notify.js +77 -0
  217. package/lib/core/remote/owner.d.ts +32 -0
  218. package/lib/core/remote/owner.js +75 -0
  219. package/lib/core/remote/pairing.d.ts +104 -0
  220. package/lib/core/remote/pairing.js +261 -0
  221. package/lib/core/remote/push.d.ts +80 -0
  222. package/lib/core/remote/push.js +222 -0
  223. package/lib/core/remote/store.d.ts +18 -0
  224. package/lib/core/remote/store.js +59 -0
  225. package/lib/core/remote/tickets.d.ts +20 -0
  226. package/lib/core/remote/tickets.js +49 -0
  227. package/lib/core/remote/uploads.d.ts +63 -0
  228. package/lib/core/remote/uploads.js +161 -0
  229. package/lib/core/request-attribution.d.ts +26 -0
  230. package/lib/core/request-attribution.js +86 -0
  231. package/lib/core/request-invariant.d.ts +61 -0
  232. package/lib/core/request-invariant.js +199 -0
  233. package/lib/core/sandbox/backends.d.ts +64 -0
  234. package/lib/core/sandbox/backends.js +194 -0
  235. package/lib/core/sandbox/execpolicy.d.ts +93 -0
  236. package/lib/core/sandbox/execpolicy.js +452 -0
  237. package/lib/core/sandbox/net-proxy.d.ts +31 -0
  238. package/lib/core/sandbox/net-proxy.js +162 -0
  239. package/lib/core/sandbox/policy.d.ts +211 -0
  240. package/lib/core/sandbox/policy.js +559 -0
  241. package/lib/core/sandbox/win/abi.d.ts +161 -0
  242. package/lib/core/sandbox/win/abi.js +169 -0
  243. package/lib/core/sandbox/win/account.d.ts +71 -0
  244. package/lib/core/sandbox/win/account.js +206 -0
  245. package/lib/core/sandbox/win/acl.d.ts +54 -0
  246. package/lib/core/sandbox/win/acl.js +339 -0
  247. package/lib/core/sandbox/win/backend.d.ts +61 -0
  248. package/lib/core/sandbox/win/backend.js +249 -0
  249. package/lib/core/sandbox/win/doctor.d.ts +24 -0
  250. package/lib/core/sandbox/win/doctor.js +272 -0
  251. package/lib/core/sandbox/win/ffi.d.ts +107 -0
  252. package/lib/core/sandbox/win/ffi.js +166 -0
  253. package/lib/core/sandbox/win/net-abi.d.ts +154 -0
  254. package/lib/core/sandbox/win/net-abi.js +316 -0
  255. package/lib/core/sandbox/win/runner-entry.d.ts +35 -0
  256. package/lib/core/sandbox/win/runner-entry.js +391 -0
  257. package/lib/core/sandbox/win/setup.d.ts +60 -0
  258. package/lib/core/sandbox/win/setup.js +986 -0
  259. package/lib/core/sandbox/win/token.d.ts +35 -0
  260. package/lib/core/sandbox/win/token.js +238 -0
  261. package/lib/core/sandbox/win/wfp.d.ts +41 -0
  262. package/lib/core/sandbox/win/wfp.js +200 -0
  263. package/lib/core/sandbox/win/workspace-sid.d.ts +9 -0
  264. package/lib/core/sandbox/win/workspace-sid.js +45 -0
  265. package/lib/core/schedule/rule.d.ts +184 -0
  266. package/lib/core/schedule/rule.js +745 -0
  267. package/lib/core/schedule/runner.d.ts +185 -0
  268. package/lib/core/schedule/runner.js +678 -0
  269. package/lib/core/schedule/store.d.ts +182 -0
  270. package/lib/core/schedule/store.js +455 -0
  271. package/lib/core/secrets.d.ts +41 -0
  272. package/lib/core/secrets.js +150 -0
  273. package/lib/core/session-export.d.ts +18 -0
  274. package/lib/core/session-export.js +73 -0
  275. package/lib/core/session-index.d.ts +159 -0
  276. package/lib/core/session-index.js +683 -0
  277. package/lib/core/session-meta.d.ts +41 -0
  278. package/lib/core/session-meta.js +97 -0
  279. package/lib/core/session.d.ts +356 -0
  280. package/lib/core/session.js +998 -0
  281. package/lib/core/skills.d.ts +60 -0
  282. package/lib/core/skills.js +171 -0
  283. package/lib/core/spill.d.ts +159 -0
  284. package/lib/core/spill.js +329 -0
  285. package/lib/core/surface-registry.d.ts +45 -0
  286. package/lib/core/surface-registry.js +67 -0
  287. package/lib/core/team-board.d.ts +95 -0
  288. package/lib/core/team-board.js +316 -0
  289. package/lib/core/throughput.d.ts +46 -0
  290. package/lib/core/throughput.js +40 -0
  291. package/lib/core/todo-reminder.d.ts +44 -0
  292. package/lib/core/todo-reminder.js +55 -0
  293. package/lib/core/todo.d.ts +81 -0
  294. package/lib/core/todo.js +222 -0
  295. package/lib/core/token-estimate.d.ts +55 -0
  296. package/lib/core/token-estimate.js +82 -0
  297. package/lib/core/tool-guards.d.ts +103 -0
  298. package/lib/core/tool-guards.js +77 -0
  299. package/lib/core/tool-search.d.ts +152 -0
  300. package/lib/core/tool-search.js +311 -0
  301. package/lib/core/tools/bash.d.ts +281 -0
  302. package/lib/core/tools/bash.js +871 -0
  303. package/lib/core/tools/command-runner.d.ts +84 -0
  304. package/lib/core/tools/command-runner.js +68 -0
  305. package/lib/core/tools/fs-tools.d.ts +23 -0
  306. package/lib/core/tools/fs-tools.js +247 -0
  307. package/lib/core/tools/index.d.ts +8 -0
  308. package/lib/core/tools/index.js +4 -0
  309. package/lib/core/tools/sandbox-args.d.ts +51 -0
  310. package/lib/core/tools/sandbox-args.js +90 -0
  311. package/lib/core/tools/search-tools.d.ts +3 -0
  312. package/lib/core/tools/search-tools.js +153 -0
  313. package/lib/core/tools.d.ts +96 -0
  314. package/lib/core/tools.js +53 -0
  315. package/lib/core/ui-boot-source.d.ts +71 -0
  316. package/lib/core/ui-boot-source.js +121 -0
  317. package/lib/core/ui-bundles.d.ts +249 -0
  318. package/lib/core/ui-bundles.js +830 -0
  319. package/lib/core/ui-combo.d.ts +49 -0
  320. package/lib/core/ui-combo.js +55 -0
  321. package/lib/core/ui-events.d.ts +81 -0
  322. package/lib/core/ui-events.js +364 -0
  323. package/lib/core/ui-hmr.d.ts +36 -0
  324. package/lib/core/ui-hmr.js +128 -0
  325. package/lib/core/ui-methods.d.ts +69 -0
  326. package/lib/core/ui-methods.js +341 -0
  327. package/lib/core/ui-route.d.ts +69 -0
  328. package/lib/core/ui-route.js +122 -0
  329. package/lib/core/ui-server.d.ts +75 -0
  330. package/lib/core/ui-server.js +369 -0
  331. package/lib/core/ui-trust.d.ts +47 -0
  332. package/lib/core/ui-trust.js +164 -0
  333. package/lib/core/untrusted.d.ts +30 -0
  334. package/lib/core/untrusted.js +48 -0
  335. package/lib/core/update-check.d.ts +81 -0
  336. package/lib/core/update-check.js +177 -0
  337. package/lib/core/usage-log.d.ts +82 -0
  338. package/lib/core/usage-log.js +306 -0
  339. package/lib/core/version.d.ts +1 -0
  340. package/lib/core/version.js +37 -0
  341. package/lib/core/web-http.d.ts +57 -0
  342. package/lib/core/web-http.js +137 -0
  343. package/lib/core/web-static.d.ts +31 -0
  344. package/lib/core/web-static.js +75 -0
  345. package/lib/headless.d.ts +1 -0
  346. package/lib/headless.js +31 -0
  347. package/lib/host/kernel.d.ts +33 -0
  348. package/lib/host/kernel.js +451 -0
  349. package/lib/index.d.ts +41 -0
  350. package/lib/index.js +35 -0
  351. package/lib/plugins/agent.d.ts +2 -0
  352. package/lib/plugins/agent.js +274 -0
  353. package/lib/plugins/approval-floor.d.ts +2 -0
  354. package/lib/plugins/approval-floor.js +223 -0
  355. package/lib/plugins/approval.d.ts +16 -0
  356. package/lib/plugins/approval.js +674 -0
  357. package/lib/plugins/ask.d.ts +2 -0
  358. package/lib/plugins/ask.js +245 -0
  359. package/lib/plugins/browser.d.ts +68 -0
  360. package/lib/plugins/browser.js +1341 -0
  361. package/lib/plugins/commands.d.ts +23 -0
  362. package/lib/plugins/commands.js +498 -0
  363. package/lib/plugins/compact.d.ts +21 -0
  364. package/lib/plugins/compact.js +274 -0
  365. package/lib/plugins/computer-use.d.ts +47 -0
  366. package/lib/plugins/computer-use.js +539 -0
  367. package/lib/plugins/desktop-dock.d.ts +2 -0
  368. package/lib/plugins/desktop-dock.js +626 -0
  369. package/lib/plugins/dock-browser.d.ts +34 -0
  370. package/lib/plugins/dock-browser.js +765 -0
  371. package/lib/plugins/dsh-compat.d.ts +25 -0
  372. package/lib/plugins/dsh-compat.js +37 -0
  373. package/lib/plugins/file-review.d.ts +108 -0
  374. package/lib/plugins/file-review.js +393 -0
  375. package/lib/plugins/git.d.ts +26 -0
  376. package/lib/plugins/git.js +132 -0
  377. package/lib/plugins/goal.d.ts +20 -0
  378. package/lib/plugins/goal.js +245 -0
  379. package/lib/plugins/guards.d.ts +14 -0
  380. package/lib/plugins/guards.js +18 -0
  381. package/lib/plugins/hooks.d.ts +19 -0
  382. package/lib/plugins/hooks.js +583 -0
  383. package/lib/plugins/host-stdio.d.ts +88 -0
  384. package/lib/plugins/host-stdio.js +317 -0
  385. package/lib/plugins/image-diet.d.ts +17 -0
  386. package/lib/plugins/image-diet.js +85 -0
  387. package/lib/plugins/lifecycle-hooks.d.ts +26 -0
  388. package/lib/plugins/lifecycle-hooks.js +338 -0
  389. package/lib/plugins/llm.d.ts +13 -0
  390. package/lib/plugins/llm.js +215 -0
  391. package/lib/plugins/lsp.d.ts +54 -0
  392. package/lib/plugins/lsp.js +608 -0
  393. package/lib/plugins/mcp.d.ts +16 -0
  394. package/lib/plugins/mcp.js +673 -0
  395. package/lib/plugins/memory.d.ts +17 -0
  396. package/lib/plugins/memory.js +858 -0
  397. package/lib/plugins/microcompact.d.ts +18 -0
  398. package/lib/plugins/microcompact.js +119 -0
  399. package/lib/plugins/mode.d.ts +18 -0
  400. package/lib/plugins/mode.js +115 -0
  401. package/lib/plugins/permission-presets.d.ts +18 -0
  402. package/lib/plugins/permission-presets.js +135 -0
  403. package/lib/plugins/plan.d.ts +2 -0
  404. package/lib/plugins/plan.js +192 -0
  405. package/lib/plugins/plugin-manager.d.ts +2 -0
  406. package/lib/plugins/plugin-manager.js +165 -0
  407. package/lib/plugins/presets.d.ts +2 -0
  408. package/lib/plugins/presets.js +182 -0
  409. package/lib/plugins/prompt.d.ts +2 -0
  410. package/lib/plugins/prompt.js +264 -0
  411. package/lib/plugins/ptc.d.ts +2 -0
  412. package/lib/plugins/ptc.js +272 -0
  413. package/lib/plugins/remote/http.d.ts +11 -0
  414. package/lib/plugins/remote/http.js +11 -0
  415. package/lib/plugins/remote/routes.d.ts +24 -0
  416. package/lib/plugins/remote/routes.js +384 -0
  417. package/lib/plugins/remote/types.d.ts +135 -0
  418. package/lib/plugins/remote/types.js +87 -0
  419. package/lib/plugins/remote.d.ts +17 -0
  420. package/lib/plugins/remote.js +1028 -0
  421. package/lib/plugins/runtime-api.d.ts +16 -0
  422. package/lib/plugins/runtime-api.js +99 -0
  423. package/lib/plugins/runtime.d.ts +10 -0
  424. package/lib/plugins/runtime.js +451 -0
  425. package/lib/plugins/sandbox.d.ts +2 -0
  426. package/lib/plugins/sandbox.js +761 -0
  427. package/lib/plugins/schedule.d.ts +26 -0
  428. package/lib/plugins/schedule.js +538 -0
  429. package/lib/plugins/self-improve.d.ts +61 -0
  430. package/lib/plugins/self-improve.js +953 -0
  431. package/lib/plugins/session-search.d.ts +16 -0
  432. package/lib/plugins/session-search.js +308 -0
  433. package/lib/plugins/session-title.d.ts +19 -0
  434. package/lib/plugins/session-title.js +109 -0
  435. package/lib/plugins/session.d.ts +7 -0
  436. package/lib/plugins/session.js +296 -0
  437. package/lib/plugins/settings.d.ts +3 -0
  438. package/lib/plugins/settings.js +705 -0
  439. package/lib/plugins/skills.d.ts +2 -0
  440. package/lib/plugins/skills.js +360 -0
  441. package/lib/plugins/spill.d.ts +16 -0
  442. package/lib/plugins/spill.js +200 -0
  443. package/lib/plugins/subagent.d.ts +2 -0
  444. package/lib/plugins/subagent.js +862 -0
  445. package/lib/plugins/surfaces.d.ts +11 -0
  446. package/lib/plugins/surfaces.js +20 -0
  447. package/lib/plugins/team.d.ts +16 -0
  448. package/lib/plugins/team.js +149 -0
  449. package/lib/plugins/todo.d.ts +19 -0
  450. package/lib/plugins/todo.js +188 -0
  451. package/lib/plugins/tool-search.d.ts +2 -0
  452. package/lib/plugins/tool-search.js +425 -0
  453. package/lib/plugins/tools-default.d.ts +12 -0
  454. package/lib/plugins/tools-default.js +275 -0
  455. package/lib/plugins/tools.d.ts +16 -0
  456. package/lib/plugins/tools.js +62 -0
  457. package/lib/plugins/transcript.d.ts +15 -0
  458. package/lib/plugins/transcript.js +311 -0
  459. package/lib/plugins/tui.d.ts +2 -0
  460. package/lib/plugins/tui.js +98 -0
  461. package/lib/plugins/waiting.d.ts +12 -0
  462. package/lib/plugins/waiting.js +34 -0
  463. package/lib/plugins/web-search.d.ts +14 -0
  464. package/lib/plugins/web-search.js +263 -0
  465. package/lib/plugins/webserver.d.ts +48 -0
  466. package/lib/plugins/webserver.js +228 -0
  467. package/lib/remote/assets/app-DAcUCOEn.js +14 -0
  468. package/lib/remote/assets/icon-192.png +0 -0
  469. package/lib/remote/assets/icon-512.png +0 -0
  470. package/lib/remote/assets/index.html +34 -0
  471. package/lib/remote/assets/manifest.json +27 -0
  472. package/lib/remote/assets/style-DIB6729x.css +1 -0
  473. package/lib/remote/assets/sw.js +66 -0
  474. package/lib/services/types.d.ts +1228 -0
  475. package/lib/services/types.js +1 -0
  476. package/lib/tools/config-cli.d.ts +1 -0
  477. package/lib/tools/config-cli.js +89 -0
  478. package/lib/ui/arrival.d.ts +72 -0
  479. package/lib/ui/arrival.js +105 -0
  480. package/lib/ui/assets/app-B70nVIKd.js +69 -0
  481. package/lib/ui/assets/chunk-2UxHyX5q.js +1 -0
  482. package/lib/ui/assets/chunk-B1dDrJ26.js +1 -0
  483. package/lib/ui/assets/chunk-B6aJPvgy.js +1 -0
  484. package/lib/ui/assets/chunk-BEwlwnbL.js +1 -0
  485. package/lib/ui/assets/chunk-BGcgwlCI.js +12 -0
  486. package/lib/ui/assets/chunk-BIGW1oBm.js +1 -0
  487. package/lib/ui/assets/chunk-BPQ3VLAy.js +1 -0
  488. package/lib/ui/assets/chunk-BRH0KZbk.js +141 -0
  489. package/lib/ui/assets/chunk-BX6H_ySx.js +1 -0
  490. package/lib/ui/assets/chunk-B_P3UbPa.js +1 -0
  491. package/lib/ui/assets/chunk-B_TYUkTI.js +1 -0
  492. package/lib/ui/assets/chunk-B_vNuMnf.js +1 -0
  493. package/lib/ui/assets/chunk-BajyYBss.js +10 -0
  494. package/lib/ui/assets/chunk-BdnUsdx6.js +1 -0
  495. package/lib/ui/assets/chunk-Buea-lGh.js +1 -0
  496. package/lib/ui/assets/chunk-C0PvZCCE.js +1 -0
  497. package/lib/ui/assets/chunk-C0m74zRD.js +1 -0
  498. package/lib/ui/assets/chunk-C27-OAKa.js +1 -0
  499. package/lib/ui/assets/chunk-C2oV4EkX.js +1 -0
  500. package/lib/ui/assets/chunk-C7zT0LnQ.js +1 -0
  501. package/lib/ui/assets/chunk-C9GSunVT.js +1 -0
  502. package/lib/ui/assets/chunk-C9tS-k6U.js +1 -0
  503. package/lib/ui/assets/chunk-CHLpvVh8.js +1 -0
  504. package/lib/ui/assets/chunk-CLxacb5B.js +1 -0
  505. package/lib/ui/assets/chunk-COt5Ahok.js +1 -0
  506. package/lib/ui/assets/chunk-CPTIWCL2.js +1 -0
  507. package/lib/ui/assets/chunk-CQLl-L-p.js +1 -0
  508. package/lib/ui/assets/chunk-CUWRgxuq.js +55 -0
  509. package/lib/ui/assets/chunk-CWanVSXC.js +1 -0
  510. package/lib/ui/assets/chunk-Cf5RLm7j.js +1 -0
  511. package/lib/ui/assets/chunk-CickPsom.js +1 -0
  512. package/lib/ui/assets/chunk-Cj5Yp3dK.js +1 -0
  513. package/lib/ui/assets/chunk-Cmh6b_Ma.js +1 -0
  514. package/lib/ui/assets/chunk-Cp-IABpG.js +1 -0
  515. package/lib/ui/assets/chunk-CqE71os6.js +1 -0
  516. package/lib/ui/assets/chunk-CtKP3W-j.js +1 -0
  517. package/lib/ui/assets/chunk-Cvjx9yec.js +1 -0
  518. package/lib/ui/assets/chunk-CxGP3dtY.js +1 -0
  519. package/lib/ui/assets/chunk-CylS5w8V.js +1 -0
  520. package/lib/ui/assets/chunk-D38fbIBN.js +1 -0
  521. package/lib/ui/assets/chunk-D97Zzqfu.js +1 -0
  522. package/lib/ui/assets/chunk-DAi9KRSo.js +1 -0
  523. package/lib/ui/assets/chunk-DHK4yRfg.js +1 -0
  524. package/lib/ui/assets/chunk-DJeabLx-.js +1 -0
  525. package/lib/ui/assets/chunk-DNRxmY5a.js +1 -0
  526. package/lib/ui/assets/chunk-DNSN1z5r.js +1 -0
  527. package/lib/ui/assets/chunk-DNasK_ZG.js +1 -0
  528. package/lib/ui/assets/chunk-DPvrY3IQ.js +1 -0
  529. package/lib/ui/assets/chunk-DXmwc3jG.js +1 -0
  530. package/lib/ui/assets/chunk-Dd0kTxKP.js +1 -0
  531. package/lib/ui/assets/chunk-De0Btta0.js +1 -0
  532. package/lib/ui/assets/chunk-Des-eS-w.js +1 -0
  533. package/lib/ui/assets/chunk-Df6bDoY_.js +1 -0
  534. package/lib/ui/assets/chunk-DijEV5ha.js +1 -0
  535. package/lib/ui/assets/chunk-DkvoVjww.js +1 -0
  536. package/lib/ui/assets/chunk-DlC-OlHO.js +1 -0
  537. package/lib/ui/assets/chunk-DnzrXTVv.js +1 -0
  538. package/lib/ui/assets/chunk-Dualf0xi.js +1 -0
  539. package/lib/ui/assets/chunk-EXT84bkm.js +1 -0
  540. package/lib/ui/assets/chunk-GwR3hkPK.js +1 -0
  541. package/lib/ui/assets/chunk-P80f7IUj.js +1 -0
  542. package/lib/ui/assets/chunk-VOosw3JB.js +1 -0
  543. package/lib/ui/assets/chunk-YQ4lDkt_.js +140 -0
  544. package/lib/ui/assets/chunk-Yzrsuije.js +1 -0
  545. package/lib/ui/assets/chunk-Z72CF80r.js +1 -0
  546. package/lib/ui/assets/chunk-g9-lgVsj.js +1 -0
  547. package/lib/ui/assets/chunk-vGWfd6FD.js +1 -0
  548. package/lib/ui/assets/chunk-wDzz0qaB.js +1 -0
  549. package/lib/ui/assets/chunk-ySF7HWmS.js +1 -0
  550. package/lib/ui/assets/icon.png +0 -0
  551. package/lib/ui/assets/index.html +14 -0
  552. package/lib/ui/assets/pdf.worker.min-CjEcRF4W.mjs +28 -0
  553. package/lib/ui/assets/style-Bq01xH_b.css +1 -0
  554. package/lib/ui/frames.d.ts +67 -0
  555. package/lib/ui/frames.js +146 -0
  556. package/lib/ui/index.d.ts +59 -0
  557. package/lib/ui/index.js +50 -0
  558. package/lib/ui/manifest.d.ts +172 -0
  559. package/lib/ui/manifest.js +158 -0
  560. package/lib/ui/plugin.d.ts +161 -0
  561. package/lib/ui/plugin.js +7 -0
  562. package/lib/ui/plugins/browser/client.js +290 -0
  563. package/lib/ui/plugins/browser/icon.png +0 -0
  564. package/lib/ui/plugins/composer/client.js +1843 -0
  565. package/lib/ui/plugins/composer/icon.png +0 -0
  566. package/lib/ui/plugins/files/client.js +646 -0
  567. package/lib/ui/plugins/files/icon.png +0 -0
  568. package/lib/ui/plugins/manifest.json +107 -0
  569. package/lib/ui/plugins/plugins/client.js +682 -0
  570. package/lib/ui/plugins/plugins/icon.png +0 -0
  571. package/lib/ui/plugins/preview/client.js +197 -0
  572. package/lib/ui/plugins/preview/icon.png +0 -0
  573. package/lib/ui/plugins/prompt/client.js +653 -0
  574. package/lib/ui/plugins/prompt/icon.png +0 -0
  575. package/lib/ui/plugins/sessions/client.js +1577 -0
  576. package/lib/ui/plugins/sessions/icon.png +0 -0
  577. package/lib/ui/plugins/settings/client.js +5470 -0
  578. package/lib/ui/plugins/settings/icon.png +0 -0
  579. package/lib/ui/plugins/skills/client.js +485 -0
  580. package/lib/ui/plugins/skills/icon.png +0 -0
  581. package/lib/ui/plugins/status/client.js +1420 -0
  582. package/lib/ui/plugins/status/icon.png +0 -0
  583. package/lib/ui/plugins/statusbar/client.js +504 -0
  584. package/lib/ui/plugins/statusbar/icon.png +0 -0
  585. package/lib/ui/plugins/tasks/client.js +52 -0
  586. package/lib/ui/plugins/tasks/icon.png +0 -0
  587. package/lib/ui/plugins/team/client.js +527 -0
  588. package/lib/ui/plugins/team/icon.png +0 -0
  589. package/lib/ui/plugins/terminal/client.js +232 -0
  590. package/lib/ui/plugins/terminal/icon.png +0 -0
  591. package/lib/ui/plugins/trace/client.js +1376 -0
  592. package/lib/ui/plugins/trace/icon.png +0 -0
  593. package/lib/ui/plugins/transcript/client.js +2661 -0
  594. package/lib/ui/plugins/transcript/icon.png +0 -0
  595. package/lib/ui/scoped-slots.d.ts +20 -0
  596. package/lib/ui/scoped-slots.js +21 -0
  597. package/lib/ui/sdk/@dsc/ui/index.d.ts +242 -0
  598. package/lib/ui/sdk/@dsc/ui/package.json +16 -0
  599. package/lib/ui/sdk/@dsc/ui-core/contract.d.ts +1973 -0
  600. package/lib/ui/sdk/@dsc/ui-core/core/diff-text.d.ts +74 -0
  601. package/lib/ui/sdk/@dsc/ui-core/core/dock-browser.d.ts +137 -0
  602. package/lib/ui/sdk/@dsc/ui-core/core/dock-ops.d.ts +59 -0
  603. package/lib/ui/sdk/@dsc/ui-core/core/model-caps.d.ts +83 -0
  604. package/lib/ui/sdk/@dsc/ui-core/core/native-bridge.d.ts +135 -0
  605. package/lib/ui/sdk/@dsc/ui-core/core/token-estimate.d.ts +55 -0
  606. package/lib/ui/sdk/@dsc/ui-core/package.json +16 -0
  607. package/lib/ui/sdk/@dsc/ui-core/ui/arrival.d.ts +72 -0
  608. package/lib/ui/sdk/@dsc/ui-core/ui/frames.d.ts +67 -0
  609. package/lib/ui/sdk/@dsc/ui-core/ui/index.d.ts +59 -0
  610. package/lib/ui/sdk/@dsc/ui-core/ui/manifest.d.ts +172 -0
  611. package/lib/ui/sdk/@dsc/ui-core/ui/plugin.d.ts +161 -0
  612. package/lib/ui/sdk/@dsc/ui-core/ui/scoped-slots.d.ts +20 -0
  613. package/lib/ui/sdk/@dsc/ui-core/ui/services-react.d.ts +27 -0
  614. package/lib/ui/sdk/@dsc/ui-core/ui/services.d.ts +63 -0
  615. package/lib/ui/sdk/@dsc/ui-core/ui/slots-react.d.ts +28 -0
  616. package/lib/ui/sdk/@dsc/ui-core/ui/slots.d.ts +481 -0
  617. package/lib/ui/sdk/@dsc/ui-core/ui/store.d.ts +89 -0
  618. package/lib/ui/sdk/@dsc/ui-dockkit/dock-model.d.ts +238 -0
  619. package/lib/ui/sdk/@dsc/ui-dockkit/dock-state.d.ts +163 -0
  620. package/lib/ui/sdk/@dsc/ui-dockkit/dock.d.ts +24 -0
  621. package/lib/ui/sdk/@dsc/ui-dockkit/index.d.ts +15 -0
  622. package/lib/ui/sdk/@dsc/ui-dockkit/package.json +16 -0
  623. package/lib/ui/sdk/@dsc/ui-layout/app.d.ts +74 -0
  624. package/lib/ui/sdk/@dsc/ui-layout/appearance.d.ts +70 -0
  625. package/lib/ui/sdk/@dsc/ui-layout/host-channel.d.ts +112 -0
  626. package/lib/ui/sdk/@dsc/ui-layout/index.d.ts +34 -0
  627. package/lib/ui/sdk/@dsc/ui-layout/package.json +16 -0
  628. package/lib/ui/sdk/@dsc/ui-layout/page-state.d.ts +14 -0
  629. package/lib/ui/sdk/@dsc/ui-layout/review-pane.d.ts +21 -0
  630. package/lib/ui/sdk/@dsc/ui-layout/runtime-context.d.ts +44 -0
  631. package/lib/ui/sdk/@dsc/ui-layout/thread-view.d.ts +28 -0
  632. package/lib/ui/sdk/@dsc/ui-layout/update-button.d.ts +21 -0
  633. package/lib/ui/sdk/@dsc/ui-primitives/code-file-icon-artwork.d.ts +53 -0
  634. package/lib/ui/sdk/@dsc/ui-primitives/code-view.d.ts +15 -0
  635. package/lib/ui/sdk/@dsc/ui-primitives/compat.d.ts +27 -0
  636. package/lib/ui/sdk/@dsc/ui-primitives/completion-sound.d.ts +24 -0
  637. package/lib/ui/sdk/@dsc/ui-primitives/confirm.d.ts +33 -0
  638. package/lib/ui/sdk/@dsc/ui-primitives/css.d.ts +47 -0
  639. package/lib/ui/sdk/@dsc/ui-primitives/diff-rows.d.ts +20 -0
  640. package/lib/ui/sdk/@dsc/ui-primitives/file-icons.d.ts +38 -0
  641. package/lib/ui/sdk/@dsc/ui-primitives/file-type-classify.d.ts +66 -0
  642. package/lib/ui/sdk/@dsc/ui-primitives/file-type-icon.d.ts +57 -0
  643. package/lib/ui/sdk/@dsc/ui-primitives/highlight.d.ts +24 -0
  644. package/lib/ui/sdk/@dsc/ui-primitives/hover-delay.d.ts +17 -0
  645. package/lib/ui/sdk/@dsc/ui-primitives/icons.d.ts +109 -0
  646. package/lib/ui/sdk/@dsc/ui-primitives/index.d.ts +55 -0
  647. package/lib/ui/sdk/@dsc/ui-primitives/lang-table.d.ts +10 -0
  648. package/lib/ui/sdk/@dsc/ui-primitives/markdown.d.ts +20 -0
  649. package/lib/ui/sdk/@dsc/ui-primitives/native.d.ts +41 -0
  650. package/lib/ui/sdk/@dsc/ui-primitives/package.json +16 -0
  651. package/lib/ui/sdk/@dsc/ui-primitives/panels.d.ts +86 -0
  652. package/lib/ui/sdk/@dsc/ui-primitives/paths.d.ts +11 -0
  653. package/lib/ui/sdk/@dsc/ui-primitives/pdf-view.d.ts +13 -0
  654. package/lib/ui/sdk/@dsc/ui-primitives/plugin-text.d.ts +15 -0
  655. package/lib/ui/sdk/@dsc/ui-primitives/select.d.ts +35 -0
  656. package/lib/ui/sdk/@dsc/ui-primitives/table-view.d.ts +23 -0
  657. package/lib/ui/sdk/@dsc/ui-primitives/thread-resizer.d.ts +22 -0
  658. package/lib/ui/sdk/@dsc/ui-primitives/time.d.ts +33 -0
  659. package/lib/ui/sdk/@dsc/ui-primitives/toast.d.ts +16 -0
  660. package/lib/ui/sdk/@dsc/ui-primitives/tokens.d.ts +14 -0
  661. package/lib/ui/sdk/@dsc/ui-primitives/tool-args.d.ts +49 -0
  662. package/lib/ui/sdk/@dsc/ui-primitives/tool-summary.d.ts +64 -0
  663. package/lib/ui/sdk/@dsc/ui-renderer/boot.d.ts +121 -0
  664. package/lib/ui/sdk/@dsc/ui-renderer/hmr.d.ts +43 -0
  665. package/lib/ui/sdk/@dsc/ui-renderer/index.d.ts +20 -0
  666. package/lib/ui/sdk/@dsc/ui-renderer/package.json +16 -0
  667. package/lib/ui/sdk/@dsc/ui-slots/index.d.ts +19 -0
  668. package/lib/ui/sdk/@dsc/ui-slots/package.json +16 -0
  669. package/lib/ui/sdk/@dsc/ui-slots/slots-react.d.ts +48 -0
  670. package/lib/ui/sdk/@dsc/ui-slots/slots.d.ts +102 -0
  671. package/lib/ui/services-react.d.ts +27 -0
  672. package/lib/ui/services-react.js +32 -0
  673. package/lib/ui/services.d.ts +63 -0
  674. package/lib/ui/services.js +121 -0
  675. package/lib/ui/slots-ink.d.ts +26 -0
  676. package/lib/ui/slots-ink.js +78 -0
  677. package/lib/ui/slots-react.d.ts +28 -0
  678. package/lib/ui/slots-react.js +88 -0
  679. package/lib/ui/slots.d.ts +481 -0
  680. package/lib/ui/slots.js +550 -0
  681. package/lib/ui/store.d.ts +89 -0
  682. package/lib/ui/store.js +62 -0
  683. package/lib/ui/tui-plugin-api.d.ts +23 -0
  684. package/lib/ui/tui-plugin-api.js +23 -0
  685. package/lib/ui/tui-plugins.d.ts +47 -0
  686. package/lib/ui/tui-plugins.js +220 -0
  687. package/package.json +58 -6
@@ -0,0 +1,674 @@
1
+ /**
2
+ * approval 插件:provide `approval` 服务——工具执行的裁决引擎 + 审批卡。
3
+ *
4
+ * 一次判定按这个顺序走,前面的层一旦说话,后面的层不再有机会放宽:
5
+ * 1. 硬地板 —— 灾难性命令与关键系统路径,任何权限模式都拒(含完全访问);
6
+ * 2. 路径护栏 —— 说明书类文件(AGENTS.md、dsc 配置)必须当面确认一次,不许任何自动档代劳;
7
+ * 3. 命令策略 —— 用户前缀规则 + 内置危险模式(`~/.dsc/policy.rules`);
8
+ * 4. 已给授权 —— 本会话内的同类授权(按会话 id 键控,切会话即失效);
9
+ * 5. 权限模式 —— readonly / auto-edit / full-access 的自动放行集;
10
+ * 5.5 审阅者 —— user / auto-review:要问的事先给谁看(复核跑在自动放行**之前**);
11
+ * 6. 人工审批卡 —— 四档决定(这次允许 / 本会话允许 / 永久允许 / 拒绝),超时按拒处理。
12
+ *
13
+ * 两个前置判断插在中间:命中灾难地板白名单的命令免卡放行(地板自己不 return pass,
14
+ * 那样会跳掉 order 20 / 25 的安全钩子,所以免卡这一步落在这里);没有人能回答审批卡时
15
+ * 直接按拒处理,不白等一次超时——脚本与 CI 场景没人会来点那张卡。
16
+ *
17
+ * 顺序照两家成熟做法:Hermes 的 hardline 与用户 deny 表在 yolo 之前求值
18
+ * (`tools/approval_floors.py:5`),Codex 的命令分段与 `PermissionGrantScope{Turn,Session}`
19
+ * 决定授权档位(`protocol/src/request_permissions.rs:12`)。DSH 的
20
+ * `approval/asked` + `approval/decided` 成对审计也照搬(`user-approval/src/index.ts:215-234`)。
21
+ *
22
+ * 这一整套裁决挂在守卫链的 order 30 上(协作模式那道闸门排在 order 10,先问模式再问审批),
23
+ * 所以循环不必认识「审批」这件事。等卡期间这张卡登记在「正在等人」的表里。
24
+ * 等多久没人答算超时是插件配置(`approval.approvalTimeoutMs`)。
25
+ *
26
+ * @module dsc/plugins/approval
27
+ */
28
+ import { randomUUID } from 'node:crypto';
29
+ import { promises as fsp } from 'node:fs';
30
+ import { isAbsolute, resolve } from 'node:path';
31
+ import { argsSummary, callFacts, stripBaseline } from '../core/tools.js';
32
+ import { summarizeChange } from '../core/tools/fs-tools.js';
33
+ import { SANDBOX_PERMISSION_EFFECT, readSandboxRequest } from '../core/tools/sandbox-args.js';
34
+ import { REJECTED_TOOL_TEXT } from '../core/session.js';
35
+ import { resolvePluginConfig } from '../core/plugin-registry.js';
36
+ import { toolApprovalGuard } from '../core/tool-guards.js';
37
+ import { activeRules, appendRule, classifyCommand, reloadActiveRules } from '../core/command-policy.js';
38
+ import { isInsideCwd, isProtectedInstruction, writeHardBlockReason } from '../core/path-policy.js';
39
+ import { audit } from '../core/audit.js';
40
+ import { redact } from '../core/secrets.js';
41
+ /** 配置键(`~/.dsc/plugins.json` 条目树里 `file` 等于这个名字那一项的 `config`)。 */
42
+ const CONFIG_KEY = 'approval';
43
+ /** 审批卡等多久没人答就按拒处理(抄 Hermes 的 approvals.timeout 默认 300s);配置没给时用这个。 */
44
+ const DEFAULT_APPROVAL_TIMEOUT_MS = 300_000;
45
+ /**
46
+ * 取审批卡的等待时限:夹在 10 秒到 1 小时之间(再短一点就来不及答,再长等于不超时)。
47
+ * @param passed - 装配时直接传进来的配置(内核挂载时的第二参数)。
48
+ */
49
+ function readTimeout(passed) {
50
+ const raw = resolvePluginConfig(CONFIG_KEY, passed);
51
+ const num = Number(raw.approvalTimeoutMs);
52
+ if (!Number.isFinite(num))
53
+ return DEFAULT_APPROVAL_TIMEOUT_MS;
54
+ return Math.min(Math.max(Math.round(num), 10_000), 3_600_000);
55
+ }
56
+ /** 权限模式三档的界面文案(界面画档位按钮时读这份,不再自己抄一份)。 */
57
+ const POLICY_OPTIONS = [
58
+ { id: 'readonly', label: '仅查看', hint: '只读模式:读类操作放行,写/执行类一律拒绝' },
59
+ { id: 'auto-edit', label: '自动编辑', hint: '工作区内写操作自动放行,其余需审批' },
60
+ { id: 'full-access', label: '完全访问', hint: '全部工具自动放行,谨慎使用' },
61
+ ];
62
+ /**
63
+ * 审阅者两档的界面文案。这一轴与权限模式正交(参考实现的 `approvals_reviewer`):
64
+ * 档位决定「哪些事要问」,审阅者决定「要问的事先给谁看」。
65
+ */
66
+ const REVIEWER_OPTIONS = [
67
+ { id: 'user', label: '本人审阅', hint: '要问的事弹审批卡,等你点' },
68
+ {
69
+ id: 'auto-review',
70
+ label: 'AI 复核',
71
+ hint: '要问的事先给模型判官看:判放行就直接过,判高风险或判不出来再落回你的审批卡',
72
+ },
73
+ ];
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
+ /** 写类工具里「目标在工作区内就能自动放行」的那几个。 */
86
+ const PATH_WRITE_TOOLS = new Set(['write', 'edit']);
87
+ /**
88
+ * write / edit 审批卡的「将做的改动」(codex 审批弹窗内嵌 diff 的同位能力):
89
+ * 读盘上现值、按工具语义推演写后的全文、走 summarizeChange 同一套算法截断。
90
+ * 与渲染层工具卡的推演(intended-diff.ts)同一套语义,两处分头实现——宿主这份
91
+ * 在弹卡前算好随视图下发,渲染层那份等服务期里自己读盘,环境不同没有共享面。
92
+ *
93
+ * 三种降级:盘上读不到(工作区外 / 文件还不存在)→ write 从空串、edit 用 old→new
94
+ * 的参数差异,标 `fellBack`;edit 的 old 对不上盘(missing / 多处)→ 执行必然失败,
95
+ * 给参数差异并标 `mismatch`,卡片上要提示;完全算不出(非这两类工具、参数不齐、
96
+ * 内容一致)→ null,卡片回到只有参数摘要的常态。
97
+ */
98
+ export async function approvalDiffOf(request) {
99
+ if (request.toolName !== 'write' && request.toolName !== 'edit')
100
+ return null;
101
+ const args = request.args ?? {};
102
+ const rawPath = typeof args.path === 'string' ? args.path : '';
103
+ if (rawPath === '')
104
+ return null;
105
+ // 绝对路径不需要基准;相对路径必须有 cwd 才算得出在看哪一份文件。都没有就不给
106
+ // 差异预览(卡片退回参数摘要那条常态),**不**拿 process.cwd() 猜——猜出来的
107
+ // 差异是另一个目录里的同名文件,比没有更糟。
108
+ if (!isAbsolute(rawPath) && (request.cwd === undefined || request.cwd === ''))
109
+ return null;
110
+ const abs = isAbsolute(rawPath) ? rawPath : resolve(request.cwd ?? '', rawPath);
111
+ const content = typeof args.content === 'string' ? args.content : null;
112
+ const oldText = typeof args.old === 'string' ? args.old : null;
113
+ const newText = typeof args.new === 'string' ? args.new : null;
114
+ if (request.toolName === 'write' ? content === null : oldText === null || newText === null)
115
+ return null;
116
+ const read = await fsp.readFile(abs, 'utf8').catch(() => null);
117
+ let effectiveBefore;
118
+ let after;
119
+ let mismatch;
120
+ if (request.toolName === 'write') {
121
+ effectiveBefore = read ?? '';
122
+ after = content;
123
+ }
124
+ else if (read === null) {
125
+ effectiveBefore = oldText;
126
+ after = newText;
127
+ }
128
+ else {
129
+ const at = read.indexOf(oldText);
130
+ if (at < 0) {
131
+ mismatch = 'missing';
132
+ effectiveBefore = oldText;
133
+ after = newText;
134
+ }
135
+ else if (read.indexOf(oldText, at + 1) >= 0) {
136
+ mismatch = 'ambiguous';
137
+ effectiveBefore = oldText;
138
+ after = newText;
139
+ }
140
+ else {
141
+ effectiveBefore = read;
142
+ after = read.slice(0, at) + newText + read.slice(at + oldText.length);
143
+ }
144
+ }
145
+ const changes = summarizeChange(abs, effectiveBefore, after);
146
+ // 内容一致(覆盖写了个寂寞)也给一份空 diff:卡片上「不会有实际改动」比「没有信息」好。
147
+ const clean = changes === undefined
148
+ ? { path: abs, added: 0, removed: 0, hunks: [], status: 'modified' }
149
+ : stripBaseline(changes);
150
+ return {
151
+ ...clean,
152
+ // hunks 的行文本会摊到卡上:密钥形状的字符串过一遍遮红,别让审批动作本身泄密
153
+ hunks: clean.hunks.map((hunk) => ({
154
+ ...hunk,
155
+ lines: hunk.lines.map((line) => ({ ...line, text: redact(line.text) })),
156
+ })),
157
+ ...(read === null ? { fellBack: true } : {}),
158
+ ...(mismatch !== undefined ? { mismatch } : {}),
159
+ };
160
+ }
161
+ export const approvalPlugin = {
162
+ name: 'approval',
163
+ inject: ['llm', 'session', 'guards', 'surfaces', 'waiting'],
164
+ provide: 'approval',
165
+ apply(ctx, passed) {
166
+ let policy = 'auto-edit';
167
+ /**
168
+ * 「要问的事先给谁看」——与权限模式正交的一根轴。
169
+ * `user` = 弹卡等用户点(出厂默认);`auto-review` = 先给模型判官,判不出来再落人工卡。
170
+ */
171
+ let reviewer = 'user';
172
+ // 每次弹卡现读:改了等待时限不必重启宿主,下一张卡就用新值。
173
+ const timeoutMs = () => readTimeout(passed);
174
+ /**
175
+ * 当前协作模式,只进审批卡的说明文字与审计记录。
176
+ * 听 `dsc/mode-changed` 而不是反过来依赖模式服务:mode 已经依赖 approval(审计要写当时的权限模式),
177
+ * 两头互相依赖在依赖图上就是环。
178
+ */
179
+ let modeForCard = 'build';
180
+ /** 本会话内的同类授权:sessionId → 授权键集合。 */
181
+ const sessionGrants = new Map();
182
+ /** 卡 id → 卡。插入序 = 弹卡序;界面取最老的一张展示。 */
183
+ const pendings = new Map();
184
+ /** 规则文件重新读一遍(写在永久规则之后,让下一条判定立刻看到它)。 */
185
+ const reloadRules = () => {
186
+ for (const problem of reloadActiveRules().problems)
187
+ ctx.emit('dsc/notice', `规则文件:${problem}`);
188
+ };
189
+ reloadRules();
190
+ /** 当前会话 id(授权键与审计都挂在它下面)。 */
191
+ const sessionId = () => ctx.session.current().meta.id;
192
+ /** 这次判定属于哪个会话:请求带了发起方就按发起方(0.6.48 多 agent),否则看当前查看的。 */
193
+ const sidOf = (request) => request.sessionId ?? sessionId();
194
+ /** 这次判定的会话 jsonl 路径(侧栏状态点的键口径)。 */
195
+ const pathOf = (request) => request.sessionPath ?? ctx.session.current().filePath;
196
+ /**
197
+ * 这次判定的路径基准:请求自带 `cwd` 优先(工具那条路都带着会话目录),
198
+ * 没带就退到**当前会话的目录**。
199
+ *
200
+ * 为什么不再用 `process.cwd()`:目录是会话自己的数据(多工作区并用之后,进程目录
201
+ * 已经没有用户意义)——拿它当基准既会把别的会话的合法目标判成越界,也会让卡片上
202
+ * 那句「工作目录」说谎。
203
+ */
204
+ const baseCwd = (request) => {
205
+ if (request.cwd !== undefined && request.cwd !== '')
206
+ return request.cwd;
207
+ try {
208
+ return ctx.session.current().meta.cwd;
209
+ }
210
+ catch {
211
+ return '';
212
+ }
213
+ };
214
+ /** 当前查看会话的最老一张挂起卡;没有就 undefined(pendingView/answer 同用它定口径)。 */
215
+ const currentForHere = () => {
216
+ const here = ctx.session.current().filePath;
217
+ for (const card of pendings.values()) {
218
+ if (card.sessionPath === here)
219
+ return card;
220
+ }
221
+ return undefined;
222
+ };
223
+ /** 这次调用属于哪个「同类」:同一会话里再出现就不再问的粒度。 */
224
+ function grantKeyOf(toolName, suggested, insideCwd) {
225
+ if (suggested !== null)
226
+ return `${toolName}:${suggested.join(' ')}`;
227
+ if (PATH_WRITE_TOOLS.has(toolName))
228
+ return `${toolName}:${insideCwd ? 'inside-cwd' : 'outside-cwd'}`;
229
+ return toolName;
230
+ }
231
+ /**
232
+ * 现在有没有人能回答审批卡。
233
+ *
234
+ * 有界面入口登记(tui / host-stdio)就以它为准;没有登记时看这一进程是不是终端直连。
235
+ * 两者都没有就是脚本、CI、无头调用——没人能点那张卡,等满超时只是白等 5 分钟。
236
+ */
237
+ const someoneCanAnswer = () => {
238
+ const ui = ctx.get('interactive');
239
+ if (ui !== undefined)
240
+ return ui.reachable();
241
+ return process.stdin.isTTY === true;
242
+ };
243
+ /** 挂起人工审批卡:等到答案、等到超时、或等到本轮被打断。 */
244
+ const askHuman = (request, signal, input) => new Promise((resolveDone) => {
245
+ // 没人能回答就不弹卡:超时按拒是同一条结论,只是早 300 秒给出,并且理由说清了为什么。
246
+ if (!someoneCanAnswer()) {
247
+ autoLog('auto-deny', request, '当前没有界面能回答审批卡(没有终端界面,也没有桌面客户端),按拒处理');
248
+ resolveDone('reject');
249
+ return;
250
+ }
251
+ const id = randomUUID();
252
+ const sid = sidOf(request);
253
+ const view = {
254
+ id,
255
+ toolName: request.toolName,
256
+ argsSummary: redact(request.argsSummary),
257
+ reason: input.reason,
258
+ risk: input.risk,
259
+ suggestedRule: input.suggestedRule,
260
+ hardline: input.hardline,
261
+ scopes: input.scopes,
262
+ ...(input.escalation === null ? {} : { escalation: input.escalation }),
263
+ policy,
264
+ reviewer,
265
+ mode: modeForCard,
266
+ // 发起会话归属(0.6.49):卡片是全局渲染的,后台会话的卡弹出来时界面要标得清是谁家的
267
+ sessionPath: pathOf(request),
268
+ ...(input.diff === null ? {} : { diff: input.diff }),
269
+ };
270
+ audit({
271
+ ts: Date.now(),
272
+ kind: 'approval',
273
+ id,
274
+ phase: 'asked',
275
+ tool: request.toolName,
276
+ summary: view.argsSummary,
277
+ reason: input.reason,
278
+ policy,
279
+ mode: view.mode,
280
+ sessionId: sid,
281
+ cwd: request.cwd,
282
+ });
283
+ const done = (decision, phase = 'decided') => {
284
+ const card = pendings.get(id);
285
+ if (card === undefined)
286
+ return;
287
+ pendings.delete(id);
288
+ // 来源要在清掉挂起之前取出来:下面这行之后这个对象就没人持有了。
289
+ // 超时与被打断没人答过,card.source 还是 undefined,审计里就不写这一栏。
290
+ const source = card.source;
291
+ clearTimeout(card.timer);
292
+ ctx.emit('dsc/changed');
293
+ // 卡收了,那个会话要是还在跑回合就回到 working(转录层的状态点跟着翻回来)
294
+ ctx.emit('dsc/agent-status', { sessionId: sid, path: card.sessionPath, state: 'working' });
295
+ audit({
296
+ ts: Date.now(),
297
+ kind: 'approval',
298
+ id,
299
+ phase,
300
+ tool: request.toolName,
301
+ summary: view.argsSummary,
302
+ decision: decision === 'reject' ? (phase === 'decided' ? 'reject' : phase) : decision,
303
+ reason: input.reason,
304
+ policy,
305
+ mode: view.mode,
306
+ sessionId: sid,
307
+ ...(source === undefined ? {} : { source }),
308
+ });
309
+ resolveDone(decision);
310
+ };
311
+ const timer = setTimeout(() => done('reject', 'timeout'), timeoutMs());
312
+ pendings.set(id, {
313
+ view,
314
+ grantKey: input.grantKey,
315
+ suggestedRule: input.suggestedRule,
316
+ done,
317
+ timer,
318
+ sessionId: sid,
319
+ sessionPath: pathOf(request),
320
+ sandboxSessionRoot: input.sandboxSessionRoot,
321
+ });
322
+ ctx.emit('dsc/changed');
323
+ // 后台会话的卡也要让侧栏状态点亮起来(当前查看会话的状态走 turnState,转录层会忽略同路径)
324
+ ctx.emit('dsc/agent-status', { sessionId: sid, path: pathOf(request), state: 'awaiting-approval' });
325
+ signal.addEventListener('abort', () => done('reject', 'cancelled'), { once: true });
326
+ });
327
+ /** 自动裁决落一条审计(放行的原因必须写清是谁放的)。 */
328
+ const autoLog = (kind, request, reason, extra = {}) => {
329
+ audit({
330
+ ts: Date.now(),
331
+ kind,
332
+ tool: request.toolName,
333
+ summary: redact(request.argsSummary),
334
+ reason,
335
+ policy,
336
+ mode: modeForCard,
337
+ sessionId: sidOf(request),
338
+ cwd: request.cwd,
339
+ ...extra,
340
+ });
341
+ };
342
+ /**
343
+ * AI 自动审查:让模型出一份结构化裁决,而不是一个 ALLOW/DENY 词。
344
+ * 风险分类照 Codex 的 guardian policy(数据外泄 / 凭据探测 / 持久性安全弱化 /
345
+ * 破坏性动作 / 低风险白名单,`prompts/templates/guardian/policy.md`)。
346
+ * 判到 high 或 critical 一律回落到人工卡——AI 不许替用户承担这个责任。
347
+ */
348
+ const aiReview = async (request, signal) => {
349
+ try {
350
+ const route = ctx.llm.route();
351
+ const result = await ctx.llm.stream(route.api, {
352
+ baseUrl: route.baseUrl,
353
+ apiKey: route.apiKey,
354
+ model: route.model,
355
+ // 这次审查是**发起调用的那条会话**的请求(审批卡按它归属,归因头跟着走)
356
+ ...(request.sessionId === undefined ? {} : { sessionId: request.sessionId }),
357
+ maxTokens: 300,
358
+ thinking: 'disabled',
359
+ signal,
360
+ messages: [
361
+ {
362
+ role: 'system',
363
+ content: '你是工具执行的自动安全审查器,不参与完成任务,只判断这一次操作该不该放行。\n' +
364
+ '风险分类:\n' +
365
+ '- 数据外泄:把本地文件、环境变量、仓库内容发到外部地址;\n' +
366
+ '- 凭据探测:读取或打印密钥、token、私钥、浏览器/SSH 凭据;\n' +
367
+ '- 持久性安全弱化:关杀毒/防火墙、改注册表启动项、建账号或计划任务、放开文件权限;\n' +
368
+ '- 破坏性动作:递归删除、强推、清库、销毁基础设施、覆盖未读过的文件;\n' +
369
+ '- 低风险:读文件、查状态、跑测试、工作目录内的常规改动。\n' +
370
+ '判断要点:用户这一轮有没有明确要求做这件事?范围有没有被扩大?\n' +
371
+ '只输出一个 JSON:{"risk":"low|medium|high|critical","authorized":true|false,"reason":"一句话中文理由"}',
372
+ },
373
+ {
374
+ role: 'user',
375
+ content: redact(`工具:${request.toolName}\n参数:${JSON.stringify(request.args ?? request.argsSummary)}\n工作目录:${baseCwd(request)}`),
376
+ },
377
+ ],
378
+ }, { onDelta: () => { } });
379
+ const raw = result.text.slice(result.text.indexOf('{'), result.text.lastIndexOf('}') + 1);
380
+ 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; // 回落到人工卡
385
+ }
386
+ if (verdict.authorized === false)
387
+ return null;
388
+ return 'allow-once';
389
+ }
390
+ catch {
391
+ return null;
392
+ }
393
+ };
394
+ const service = {
395
+ get policy() {
396
+ return policy;
397
+ },
398
+ setPolicy(next) {
399
+ policy = next;
400
+ // dsc/notice → transcript 写 system 条目(避免与 transcript 的循环依赖)
401
+ ctx.emit('dsc/notice', `权限模式切换为「${policyLabel(next)}」`);
402
+ audit({
403
+ ts: Date.now(),
404
+ kind: 'mode-change',
405
+ reason: `权限模式 → ${next}`,
406
+ policy: next,
407
+ mode: modeForCard,
408
+ sessionId: sessionId(),
409
+ });
410
+ },
411
+ get reviewer() {
412
+ return reviewer;
413
+ },
414
+ 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' ? ':要问的事先给模型判官,判不出来仍会问你' : ''}`);
418
+ audit({
419
+ ts: Date.now(),
420
+ kind: 'mode-change',
421
+ reason: `审批审阅者 → ${next}`,
422
+ policy,
423
+ mode: modeForCard,
424
+ sessionId: sessionId(),
425
+ });
426
+ },
427
+ async decide(request, signal, options) {
428
+ const cwd = baseCwd(request);
429
+ // 安全钩子可以要求「这一次必须问人」:非空时下面所有自动放行档一律跳过。
430
+ const forced = options?.forceAskReason?.trim() ?? '';
431
+ const facts = callFacts(request.args ?? {}, cwd);
432
+ const target = facts.target ?? null;
433
+ const command = facts.command ?? null;
434
+ const insideCwd = target !== null && isInsideCwd(cwd, target);
435
+ const verdict = command === null ? null : classifyCommand(command, { rules: activeRules() });
436
+ // 模型这次有没有在请求放宽沙箱(工具参数那条路)。有就摊到卡上,并据此收窄授权档位。
437
+ const request0 = readSandboxRequest(request.args ?? {});
438
+ const escalation = request0.kind === 'ok'
439
+ ? {
440
+ permission: request0.permission,
441
+ scope: request0.scope,
442
+ justification: request0.justification,
443
+ effect: SANDBOX_PERMISSION_EFFECT[request0.permission],
444
+ }
445
+ : null;
446
+ // 「本会话允许」要并进可写根的那个路径:只有「留在沙箱内放宽写边界 + 写类工具 + 认得出目标」
447
+ // 三者同时成立才给——命令类没有能静态界定的目标,给它 session 档等于永久放宽一个说不清的边界。
448
+ const sandboxSessionRoot = escalation !== null && escalation.permission === 'workspace-write' && target !== null && PATH_WRITE_TOOLS.has(request.toolName)
449
+ ? target
450
+ : null;
451
+ // 第 1 层:硬地板。灾难性命令与关键系统路径,任何模式都拒,连卡都不弹。
452
+ if (target !== null) {
453
+ const hard = writeHardBlockReason(target);
454
+ if (hard !== null) {
455
+ autoLog('auto-deny', request, hard);
456
+ return 'reject';
457
+ }
458
+ }
459
+ if (verdict !== null && verdict.hardline) {
460
+ autoLog('auto-deny', request, `硬地板拒绝:${verdict.reason}`);
461
+ return 'reject';
462
+ }
463
+ // 第 2 层:说明书类文件(AGENTS.md / CLAUDE.md / .cursorrules / dsc 配置)。
464
+ // 模型改自己的规则是最省事的作弊路径,所以这一条压过所有自动档。
465
+ const protectedWhy = target === null ? null : isProtectedInstruction(target, cwd);
466
+ // 第 3 层:已给授权。同会话同类动作不再问第二次;永久规则命中 exec 时也在此放行。
467
+ // 0.6.48:按发起调用的会话记账(后台 agent 的授权不看当前查看的会话)。
468
+ const suggested = verdict?.prefixRule ?? null;
469
+ const grants = sessionGrants.get(sidOf(request));
470
+ const key = grantKeyOf(request.toolName, suggested, insideCwd);
471
+ const grantHit = protectedWhy === null && forced === '' && (grants?.has(key) ?? false);
472
+ if (grantHit) {
473
+ autoLog('auto-allow', request, '本会话已允许同类操作', { scope: 'session' });
474
+ return 'allow-once';
475
+ }
476
+ if (forced === '' &&
477
+ verdict !== null &&
478
+ verdict.decision === 'allow' &&
479
+ verdict.matchedRule !== null &&
480
+ protectedWhy === null) {
481
+ autoLog('auto-allow', request, `规则允许:${verdict.reason}`, { rule: verdict.matchedRule.pattern });
482
+ return 'allow-once';
483
+ }
484
+ // 灾难地板的白名单:地板判过「这条命令不需要有人回答」,但它自己不 return pass
485
+ // (那样会把 order 20 的安全钩子与 order 25 的生命周期钩子一起跳掉),免卡这一步落在审批层。
486
+ // 钩子要求当面看一次(forced)或目标是指明书类文件(protectedWhy)时白名单不生效。
487
+ const floor = ctx.get('approvalFloor');
488
+ if (forced === '' && protectedWhy === null && command !== null && floor !== undefined) {
489
+ const prefix = floor.whitelist(command);
490
+ if (prefix !== null) {
491
+ autoLog('auto-allow', request, `命中审批灾难地板白名单「${prefix.join(' ')}」,免审批卡`);
492
+ return 'allow-once';
493
+ }
494
+ }
495
+ // 第 5 层:权限模式自己的裁决(protected 文件不参与,强制走人工卡)。
496
+ if (protectedWhy === null && forced === '') {
497
+ if (policy === 'readonly') {
498
+ // 「仅查看」的字面意思就是只读:策略引擎判成 allow 的命令(查看目录、看 git 状态、
499
+ // 管道里只做筛选与格式化)原样放行,只有写与执行类才一律拒。
500
+ // 少了这一条,`Get-ChildItem | Format-Table` 这种纯查看也会被这档拒掉,用户要读代码都没法读。
501
+ if (verdict !== null && verdict.decision === 'allow') {
502
+ autoLog('auto-allow', request, '仅查看模式:只读命令放行');
503
+ return 'allow-once';
504
+ }
505
+ autoLog('auto-deny', request, '当前是「仅查看」权限模式,写与执行类工具一律拒绝');
506
+ return 'reject';
507
+ }
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, '工作区内的文件改动,按「工作区自动编辑」放行');
515
+ return 'allow-once';
516
+ }
517
+ if (verdict !== null && verdict.decision === 'allow') {
518
+ autoLog('auto-allow', request, `只读命令:${verdict.reason}`);
519
+ return 'allow-once';
520
+ }
521
+ }
522
+ }
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
+ // 第 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';
543
+ const scopes = ['once'];
544
+ if (escalation === null) {
545
+ if (protectedWhy === null)
546
+ scopes.push('session');
547
+ if (suggested !== null && protectedWhy === null)
548
+ scopes.push('always');
549
+ }
550
+ else if (sandboxSessionRoot !== null) {
551
+ // 升权卡只给「这次允许 / 本会话允许」:这里没有可持久化的前缀规则(always 不适用),
552
+ // 而「出沙箱」那一档连 session 都不给——跨调用的无围栏状态没人能替用户担保。
553
+ scopes.push('session');
554
+ }
555
+ // 弹卡前把「将做的改动」算好随视图下发(write/edit 才有;一次读盘 + LCS,
556
+ // 只有真要等人点卡的时刻才付这个成本)。
557
+ const diff = await approvalDiffOf(request);
558
+ return askHuman(request, signal, {
559
+ reason,
560
+ risk,
561
+ suggestedRule: suggested,
562
+ scopes,
563
+ grantKey: key,
564
+ hardline: false,
565
+ diff,
566
+ escalation,
567
+ sandboxSessionRoot,
568
+ });
569
+ },
570
+ surface() {
571
+ return {
572
+ current: policy,
573
+ options: [...POLICY_OPTIONS],
574
+ reviewer,
575
+ reviewerOptions: [...REVIEWER_OPTIONS],
576
+ };
577
+ },
578
+ pendingView() {
579
+ // 只返回当前查看会话的卡(0.6.50 对齐 dsh 的「卡只在归属会话的视图里」):
580
+ // 后台会话的卡留在它自己的会话里,侧栏的橙点引导你切过去答。
581
+ // 多卡并存时取最老的一张(插入序):答完一张,下一张自动顶上来。
582
+ const current = currentForHere();
583
+ return current === undefined ? null : current.view;
584
+ },
585
+ /** 这个会话现在有没有挂着审批卡(agent 切走时重发状态点用)。 */
586
+ pendingFor(filePath) {
587
+ for (const card of pendings.values()) {
588
+ if (card.sessionPath === filePath)
589
+ return true;
590
+ }
591
+ return false;
592
+ },
593
+ answer(answer, source = 'app') {
594
+ // 与 pendingView 同口径:答的就是界面上显示的那张——当前查看会话的最老一张。
595
+ // 以前取全局最老,答卡可能答到别的会话头上去。
596
+ const current = currentForHere();
597
+ if (current === undefined)
598
+ return;
599
+ // 来源挂在挂起对象上,`done` 里落审计时取用;手机浏览器点的那一下因此查得到(source='web')。
600
+ current.source = source;
601
+ const finish = current.done;
602
+ if (answer === 'allow-always' && current.suggestedRule !== null) {
603
+ appendRule({
604
+ pattern: current.suggestedRule,
605
+ decision: 'allow',
606
+ justification: `用户在审批卡上选了永久允许(${current.view.toolName})`,
607
+ });
608
+ reloadRules();
609
+ audit({
610
+ ts: Date.now(),
611
+ kind: 'rule-added',
612
+ tool: current.view.toolName,
613
+ rule: current.suggestedRule,
614
+ reason: '用户在审批卡上永久允许',
615
+ policy,
616
+ sessionId: current.sessionId,
617
+ source,
618
+ });
619
+ finish('allow-always');
620
+ return;
621
+ }
622
+ if (answer === 'allow-session') {
623
+ // 授权记在卡片所属的那个会话名下(0.6.48:卡的归属不再跟着「当前查看」走)
624
+ const grants = sessionGrants.get(current.sessionId) ?? new Set();
625
+ grants.add(current.grantKey);
626
+ sessionGrants.set(current.sessionId, grants);
627
+ // 这张卡带着沙箱放宽(模型走了 sandbox_permissions 那条路)时,把目标路径
628
+ // 并进**这个会话**的可写根:不然「本会话允许」只免了问,写还是被沙箱当场拦。
629
+ if (current.sandboxSessionRoot !== null) {
630
+ ctx.get('sandbox')?.grantSession(current.sessionPath, [current.sandboxSessionRoot]);
631
+ }
632
+ finish('allow-session');
633
+ return;
634
+ }
635
+ finish(answer === 'reject' ? 'reject' : 'allow-once');
636
+ },
637
+ };
638
+ ctx.provide('approval', service);
639
+ // 这套裁决挂在守卫链上(模式那道闸门在先,审批在後),循环因此不认识「审批」这个功能。
640
+ ctx.guards.register(toolApprovalGuard({
641
+ id: 'approval',
642
+ approve: (input) => service
643
+ .decide({
644
+ toolName: input.toolName,
645
+ argsSummary: argsSummary(input.args),
646
+ args: input.args,
647
+ cwd: input.cwd,
648
+ // 发起调用的会话身份:授权记账、审计与卡片归属都按它(0.6.48 多 agent)
649
+ sessionId: input.sessionId,
650
+ sessionPath: input.sessionPath,
651
+ }, input.signal)
652
+ .then((decision) => decision !== 'reject'),
653
+ // 用户点「拒绝」时回给模型的原话:老会话日志按这句话认「被拒」,不能改。
654
+ deniedReason: REJECTED_TOOL_TEXT,
655
+ }));
656
+ // 工具结果里的密钥形状字符串不落盘、不进上下文:遮红挂在结果观察者链上。
657
+ const redactObserver = { id: 'approval', order: 10, observe: (_toolName, text) => redact(text) };
658
+ ctx.guards.registerObserver(redactObserver);
659
+ ctx.surfaces.register('policy', () => service.surface());
660
+ ctx.surfaces.register('pendingApproval', () => service.pendingView());
661
+ ctx.waiting.register('approval', () => pendings.size > 0);
662
+ ctx.on('dsc/mode-changed', (mode) => {
663
+ modeForCard = mode;
664
+ });
665
+ // 0.6.48 起切换会话不再清授权与读取台账:它们本来就按会话 id 键控,天然互不串台;
666
+ // 后台常驻 agent 正跑着的时候清它的账,反而会把跑到一半的授权状态抹掉。
667
+ ctx.on('dsc/exit', () => {
668
+ for (const card of [...pendings.values()]) {
669
+ clearTimeout(card.timer);
670
+ card.done('reject', 'cancelled');
671
+ }
672
+ });
673
+ },
674
+ };