pi-web-ui 0.117.0 → 0.118.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 (512) hide show
  1. package/CHANGELOG.md +48 -2
  2. package/README.md +69 -138
  3. package/README.zh-CN.md +70 -179
  4. package/README.zh-TW.md +3 -1
  5. package/bin/device-hub-cli.mjs +147 -43
  6. package/bin/frp-manager.mjs +4 -80
  7. package/bin/hub-upgrade.mjs +561 -0
  8. package/bin/pi-device-hub.mjs +0 -1
  9. package/bin/pi-web-ui.mjs +56 -444
  10. package/deploy/nginx-subpath.conf +0 -33
  11. package/deploy/pi-web-ui.service +0 -20
  12. package/dist/server/agent-formatters.js +4 -38
  13. package/dist/server/agent-service-daemon.js +160 -374
  14. package/dist/server/agent-service.js +875 -2978
  15. package/dist/server/approval-audit.js +2 -23
  16. package/dist/server/approval-default-rules.js +0 -6
  17. package/dist/server/approval-rules.js +7 -105
  18. package/dist/server/ask-user-question-tool.js +1 -12
  19. package/dist/server/atomic-file.js +33 -5
  20. package/dist/server/attachment-store.js +0 -36
  21. package/dist/server/attachments.js +3 -112
  22. package/dist/server/auth-cookie.js +0 -21
  23. package/dist/server/bash-tool.js +1 -32
  24. package/dist/server/bg-servers.js +0 -96
  25. package/dist/server/browser-page-tool.js +11 -62
  26. package/dist/server/builtin-modules.js +7 -0
  27. package/dist/server/canvas/canvas-agent-tool.js +58 -47
  28. package/dist/server/canvas/canvas-cards.js +0 -14
  29. package/dist/server/canvas/canvas-dispatch.js +7 -4
  30. package/dist/server/canvas/canvas-orchestrator.js +167 -181
  31. package/dist/server/canvas/canvas-runtime-messages.js +30 -0
  32. package/dist/server/canvas/canvas-scheduled-task.js +0 -3
  33. package/dist/server/canvas/canvas-scheduler.js +5 -7
  34. package/dist/server/canvas/canvas-store.js +24 -35
  35. package/dist/server/canvas/canvas-validation.js +17 -14
  36. package/dist/server/canvas/canvas-workspace.js +26 -30
  37. package/dist/server/canvas/pstack-skills-data.js +0 -5
  38. package/dist/server/claim-files-tool.js +1 -15
  39. package/dist/server/claim-store.js +5 -49
  40. package/dist/server/client-id-utils.js +0 -16
  41. package/dist/server/client-state.js +6 -213
  42. package/dist/server/communicate-tool.js +0 -3
  43. package/dist/server/compact-context-tool.js +0 -30
  44. package/dist/server/compacted-history.js +0 -35
  45. package/dist/server/compaction-instructions.js +0 -13
  46. package/dist/server/compaction-markers.js +3 -76
  47. package/dist/server/compaction-state.js +0 -21
  48. package/dist/server/composer-drafts.js +0 -34
  49. package/dist/server/context-budget-runner.js +0 -11
  50. package/dist/server/context-budget.js +1 -70
  51. package/dist/server/context-evidence.js +0 -14
  52. package/dist/server/context-usage.js +0 -12
  53. package/dist/server/control-socket.js +4 -48
  54. package/dist/server/conversation-communication.js +0 -10
  55. package/dist/server/conversation-identity.js +0 -1
  56. package/dist/server/conversation-read-tool.js +0 -58
  57. package/dist/server/conversation-tool-names.js +0 -1
  58. package/dist/server/conversation-tool.js +0 -1
  59. package/dist/server/conversation-touches.js +4 -75
  60. package/dist/server/dangling-tools.js +0 -82
  61. package/dist/server/delegate-mode.js +0 -36
  62. package/dist/server/delegate-task.js +2 -28
  63. package/dist/server/device-center/approval-summary.js +0 -1
  64. package/dist/server/device-center/bot-catalog.js +0 -3
  65. package/dist/server/device-center/bot-execution.js +0 -8
  66. package/dist/server/device-center/bot-presets.js +0 -1
  67. package/dist/server/device-center/bots.js +0 -1
  68. package/dist/server/device-center/collab-service.js +1 -3
  69. package/dist/server/device-center/collab-tool.js +0 -10
  70. package/dist/server/device-center/connector.js +21 -11
  71. package/dist/server/device-center/delivery-authority.js +0 -3
  72. package/dist/server/device-center/delivery-subject.js +0 -1
  73. package/dist/server/device-center/desktop-linux.js +3 -15
  74. package/dist/server/device-center/desktop-native.js +1 -10
  75. package/dist/server/device-center/desktop-page.js +2 -3
  76. package/dist/server/device-center/desktop-setup.js +1 -3
  77. package/dist/server/device-center/desktop.js +1 -7
  78. package/dist/server/device-center/device-integration.js +1 -27
  79. package/dist/server/device-center/device-lan-access.js +403 -0
  80. package/dist/server/device-center/device-lan.js +484 -0
  81. package/dist/server/device-center/device-portals.js +0 -3
  82. package/dist/server/device-center/execution-failure.js +0 -2
  83. package/dist/server/device-center/execution-guides.js +0 -1
  84. package/dist/server/device-center/execution-instructions.js +0 -1
  85. package/dist/server/device-center/execution-settings.js +0 -1
  86. package/dist/server/device-center/execution-system-prompt.js +0 -3
  87. package/dist/server/device-center/execution-workspace.js +1 -4
  88. package/dist/server/device-center/executor.js +0 -27
  89. package/dist/server/device-center/file-sync-paths.js +0 -5
  90. package/dist/server/device-center/file-sync.js +0 -10
  91. package/dist/server/device-center/group-context-delta.js +0 -8
  92. package/dist/server/device-center/group-context-message.js +0 -14
  93. package/dist/server/device-center/group-context.js +0 -19
  94. package/dist/server/device-center/group-events.js +0 -2
  95. package/dist/server/device-center/group-plan-guard.js +1 -35
  96. package/dist/server/device-center/group-router-runtime.js +182 -0
  97. package/dist/server/device-center/group-router-worker.js +178 -0
  98. package/dist/server/device-center/group-router.js +359 -0
  99. package/dist/server/device-center/hub-auth.js +24 -2
  100. package/dist/server/device-center/hub-conversations.js +0 -12
  101. package/dist/server/device-center/hub-deliveries.js +0 -1
  102. package/dist/server/device-center/hub-integration.js +0 -8
  103. package/dist/server/device-center/hub-locks.js +1 -5
  104. package/dist/server/device-center/hub-mobile.js +147 -0
  105. package/dist/server/device-center/hub-orchestration.js +400 -0
  106. package/dist/server/device-center/hub-page.js +25 -7
  107. package/dist/server/device-center/hub-setup.js +0 -6
  108. package/dist/server/device-center/hub-transaction-log.js +0 -22
  109. package/dist/server/device-center/hub-upgrade.js +162 -0
  110. package/dist/server/device-center/hub-webhooks.js +1 -3
  111. package/dist/server/device-center/hub.js +210 -86
  112. package/dist/server/device-center/human-interaction.js +1 -4
  113. package/dist/server/device-center/integration-errors.js +0 -2
  114. package/dist/server/device-center/integration-verification.js +0 -2
  115. package/dist/server/device-center/local-hub.js +0 -2
  116. package/dist/server/device-center/local-publication.js +1 -8
  117. package/dist/server/device-center/local-verification-job.js +0 -2
  118. package/dist/server/device-center/local-verification.js +0 -1
  119. package/dist/server/device-center/local.js +267 -39
  120. package/dist/server/device-center/main.js +14 -1
  121. package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
  122. package/dist/server/device-center/native-desktop/macos.js +0 -1
  123. package/dist/server/device-center/native-desktop/windows.js +0 -1
  124. package/dist/server/device-center/partition-log.js +0 -31
  125. package/dist/server/device-center/path-portal.js +42 -12
  126. package/dist/server/device-center/publication-journal.js +0 -7
  127. package/dist/server/device-center/publish-intent.js +0 -5
  128. package/dist/server/device-center/relay.js +85 -30
  129. package/dist/server/device-center/report-upload.js +0 -1
  130. package/dist/server/device-center/runtime.js +1 -18
  131. package/dist/server/device-center/store.js +13 -33
  132. package/dist/server/device-center/task-context-budget.js +0 -3
  133. package/dist/server/device-center/task-error.js +0 -1
  134. package/dist/server/device-center/task-journal.js +6 -23
  135. package/dist/server/device-center/task-outcome.js +0 -13
  136. package/dist/server/device-center/task-plan.js +0 -1
  137. package/dist/server/device-center/task-progress.js +0 -16
  138. package/dist/server/device-center/task-recovery.js +5 -88
  139. package/dist/server/device-center/task-report-outbox.js +0 -4
  140. package/dist/server/device-center/task-report.js +2 -10
  141. package/dist/server/device-center/task-scheduler.js +1 -35
  142. package/dist/server/device-center/task-settlement.js +0 -18
  143. package/dist/server/device-center/task-state.js +0 -12
  144. package/dist/server/device-center/task-workspace.js +0 -50
  145. package/dist/server/device-center/transfer-stream.js +5 -45
  146. package/dist/server/device-center/transfers.js +2 -10
  147. package/dist/server/device-center/verification-limits.js +0 -1
  148. package/dist/server/device-center/work-contract.js +1 -73
  149. package/dist/server/device-center/work-items.js +317 -0
  150. package/dist/server/device-center/workspaces.js +0 -1
  151. package/dist/server/dispatch-domain-handlers.js +190 -32
  152. package/dist/server/dispatch-plugin-handlers.js +2 -19
  153. package/dist/server/dsh/dsh-agent-service.js +69 -599
  154. package/dist/server/dsh/dsh-client.js +7 -111
  155. package/dist/server/dsh/dsh-market-service.js +4 -25
  156. package/dist/server/dsh/dsh-serialize.js +0 -49
  157. package/dist/server/dsh/dsh-sessions.js +0 -37
  158. package/dist/server/dsh/dsh-usage.js +0 -37
  159. package/dist/server/dsh/preset-clones.js +1 -65
  160. package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
  161. package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
  162. package/dist/server/dsh/runtime/launcher.mjs +2 -53
  163. package/dist/server/dsh/runtime/override.patch.yml +0 -29
  164. package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
  165. package/dist/server/durable/durable-agent-service.js +5 -23
  166. package/dist/server/durable/durable-driver.js +12 -73
  167. package/dist/server/durable/durable-event-projector.js +1 -50
  168. package/dist/server/durable/durable-loader.js +0 -12
  169. package/dist/server/durable/durable-models.js +11 -80
  170. package/dist/server/durable/durable-storage.js +1 -17
  171. package/dist/server/durable/durable-tools.js +2 -20
  172. package/dist/server/durable/index.js +0 -3
  173. package/dist/server/edit-soft-tool.js +2 -81
  174. package/dist/server/engine-capabilities.js +0 -13
  175. package/dist/server/engine-catalog.js +74 -0
  176. package/dist/server/engine-cli.js +89 -0
  177. package/dist/server/engine-probe.js +35 -217
  178. package/dist/server/ensure-bash.js +2 -28
  179. package/dist/server/eval-tool.js +1 -50
  180. package/dist/server/evidence-tool-hooks.js +0 -2
  181. package/dist/server/file-archives.js +0 -10
  182. package/dist/server/file-save.js +1 -12
  183. package/dist/server/file-transfer-routes.js +0 -11
  184. package/dist/server/files-service.js +18 -271
  185. package/dist/server/global-loader.js +9 -89
  186. package/dist/server/goal-evidence.js +1 -35
  187. package/dist/server/goal-review-gate.js +0 -58
  188. package/dist/server/goal-service.js +19 -422
  189. package/dist/server/hashline-engine.js +8 -112
  190. package/dist/server/host-guard.js +0 -24
  191. package/dist/server/host-metrics.js +0 -6
  192. package/dist/server/http-proxy.js +1 -7
  193. package/dist/server/i18n.js +5 -72
  194. package/dist/server/icon-svg.js +0 -15
  195. package/dist/server/index.js +177 -680
  196. package/dist/server/json-utils.js +0 -12
  197. package/dist/server/launch-origin.js +0 -44
  198. package/dist/server/left-panel-running.js +0 -9
  199. package/dist/server/load-timing.js +1 -4
  200. package/dist/server/load-tools-tool.js +0 -20
  201. package/dist/server/locales.js +1 -46
  202. package/dist/server/lsp-tool.js +13 -126
  203. package/dist/server/managed.js +0 -48
  204. package/dist/server/marker-service.js +1 -22
  205. package/dist/server/markers/builtins/action.js +0 -19
  206. package/dist/server/markers/builtins/notify.js +1 -9
  207. package/dist/server/markers/builtins/rename.js +0 -13
  208. package/dist/server/markers/index.js +0 -3
  209. package/dist/server/markers/marker.js +0 -13
  210. package/dist/server/markers/registry.js +0 -3
  211. package/dist/server/markers/store.js +1 -12
  212. package/dist/server/market-service.js +7 -43
  213. package/dist/server/mcp-agent-tool.js +0 -10
  214. package/dist/server/mcp-bridge.js +6 -138
  215. package/dist/server/mcp-hot-reload.js +0 -25
  216. package/dist/server/mcp-manager.js +2 -44
  217. package/dist/server/mcp-oauth-login.js +0 -2
  218. package/dist/server/mcp-oauth-ui.js +1 -4
  219. package/dist/server/mcp-oauth.js +5 -79
  220. package/dist/server/mcp-project-runtime.js +0 -4
  221. package/dist/server/message-deletion.js +0 -2
  222. package/dist/server/message-entry-resolver.js +0 -8
  223. package/dist/server/message-window.js +0 -71
  224. package/dist/server/mobile-notification-events.js +16 -0
  225. package/dist/server/mobile-origin.js +79 -0
  226. package/dist/server/mobile-push.js +523 -0
  227. package/dist/server/model-admin.js +19 -358
  228. package/dist/server/model-enrich.js +0 -19
  229. package/dist/server/model-resolver.js +2 -61
  230. package/dist/server/native-cli-discovery.js +115 -0
  231. package/dist/server/native-cli-model.js +71 -0
  232. package/dist/server/native-cli-references.js +214 -0
  233. package/dist/server/native-cli-remote-cleanup.js +58 -0
  234. package/dist/server/native-cli-remote-files.js +282 -0
  235. package/dist/server/native-cli-routes.js +68 -0
  236. package/dist/server/native-cli-runtime.js +1 -0
  237. package/dist/server/native-cli-session-hooks.js +170 -0
  238. package/dist/server/native-cli-session.js +585 -0
  239. package/dist/server/native-cli-state.js +82 -0
  240. package/dist/server/native-cli.js +210 -0
  241. package/dist/server/net-guard.js +9 -71
  242. package/dist/server/office-parse.js +0 -50
  243. package/dist/server/orphan-manager.js +0 -18
  244. package/dist/server/patch-bash-process.js +0 -4
  245. package/dist/server/patch-executable-lookup.js +0 -77
  246. package/dist/server/patch-node-pty.js +3 -43
  247. package/dist/server/patch-remote-catalog.js +1 -32
  248. package/dist/server/patch-tool.js +0 -15
  249. package/dist/server/payload-limits.js +0 -5
  250. package/dist/server/pending-question.js +0 -5
  251. package/dist/server/permission-preset.js +4 -33
  252. package/dist/server/persona-chain.js +0 -26
  253. package/dist/server/pkg-info.js +1 -17
  254. package/dist/server/plan-manager.js +2 -49
  255. package/dist/server/plan-mode.js +0 -97
  256. package/dist/server/plan-update-tool.js +1 -15
  257. package/dist/server/plugin-api-catalog.js +6 -4
  258. package/dist/server/plugin-assets.js +1 -35
  259. package/dist/server/plugin-bundled.js +68 -0
  260. package/dist/server/plugin-catalog-sync.js +0 -37
  261. package/dist/server/plugin-catalog.js +13 -67
  262. package/dist/server/plugin-chat-attachments.js +0 -1
  263. package/dist/server/plugin-conversation-view.js +0 -20
  264. package/dist/server/plugin-dom.js +1 -23
  265. package/dist/server/plugin-facilities.js +4 -115
  266. package/dist/server/plugin-grants.js +2 -90
  267. package/dist/server/plugin-install-spec.js +0 -43
  268. package/dist/server/plugin-installer.js +34 -75
  269. package/dist/server/plugin-llm.js +4 -38
  270. package/dist/server/plugin-manifest-validate.js +0 -31
  271. package/dist/server/plugin-permissions.js +1 -24
  272. package/dist/server/plugin-project.js +7 -129
  273. package/dist/server/plugin-removal.js +1 -8
  274. package/dist/server/plugin-schedule.js +1 -38
  275. package/dist/server/plugin-secrets.js +3 -16
  276. package/dist/server/plugin-tool-guard.js +1 -28
  277. package/dist/server/plugin-ui-slots.js +0 -4
  278. package/dist/server/plugin-updater.js +15 -90
  279. package/dist/server/plugins.js +71 -619
  280. package/dist/server/present-files-tool.js +0 -57
  281. package/dist/server/preset-fields.js +9 -62
  282. package/dist/server/preset-plugin-dependencies.js +0 -2
  283. package/dist/server/preset-share.js +3 -172
  284. package/dist/server/process-utils.js +4 -80
  285. package/dist/server/prompt-assembler.js +2 -30
  286. package/dist/server/prompt-base-store.js +0 -47
  287. package/dist/server/prompt-composer.js +21 -98
  288. package/dist/server/prompt-templates.js +0 -2
  289. package/dist/server/protocol-version.js +1 -11
  290. package/dist/server/protocol.js +0 -5
  291. package/dist/server/queue-modes.js +0 -3
  292. package/dist/server/queue-utils.js +0 -40
  293. package/dist/server/quick-ask-context.js +384 -0
  294. package/dist/server/quick-ask-settings.js +34 -1
  295. package/dist/server/quick-ask.js +123 -27
  296. package/dist/server/read-tool.js +0 -65
  297. package/dist/server/reasoning-registry.js +1 -29
  298. package/dist/server/remote-cli-persistence.js +373 -0
  299. package/dist/server/remote-native-cli.js +78 -0
  300. package/dist/server/remote-ssh-service.js +481 -190
  301. package/dist/server/request-context.js +0 -9
  302. package/dist/server/resolve-global-sdk.js +0 -26
  303. package/dist/server/sandbox-data.js +0 -1
  304. package/dist/server/sandbox-engines.js +0 -1
  305. package/dist/server/sandbox-runtime-gate.js +0 -3
  306. package/dist/server/sandbox-service.js +0 -41
  307. package/dist/server/sandbox-tool.js +0 -20
  308. package/dist/server/schedule-agent-tool.js +2 -31
  309. package/dist/server/scheduler-tasks.js +3 -54
  310. package/dist/server/scm-commitmsg.js +0 -53
  311. package/dist/server/scm.js +3 -48
  312. package/dist/server/sdk-builtin-extensions.js +2 -29
  313. package/dist/server/sdk-origin.js +0 -45
  314. package/dist/server/serialize.js +2 -92
  315. package/dist/server/server-config.js +0 -11
  316. package/dist/server/session-branch.js +1 -87
  317. package/dist/server/session-list-scan.js +17 -25
  318. package/dist/server/session-open.js +2 -26
  319. package/dist/server/session-parser.js +1 -55
  320. package/dist/server/session-scan.js +1 -17
  321. package/dist/server/session-search.js +0 -56
  322. package/dist/server/settings-service.js +11 -126
  323. package/dist/server/setup-config.js +0 -2
  324. package/dist/server/setup-page.js +0 -9
  325. package/dist/server/skill-content-filler.js +0 -17
  326. package/dist/server/skill-discovery.js +5 -92
  327. package/dist/server/skill-maintenance.js +1 -28
  328. package/dist/server/skill-tool.js +0 -30
  329. package/dist/server/slash-commands.js +5 -50
  330. package/dist/server/soft-cap.js +0 -42
  331. package/dist/server/startup-banner.js +0 -8
  332. package/dist/server/subagent-handoff.js +0 -11
  333. package/dist/server/subagent-helpers.js +2 -17
  334. package/dist/server/subagent-notify.js +0 -19
  335. package/dist/server/subagent-security-gate.js +0 -50
  336. package/dist/server/subagent-task.js +0 -9
  337. package/dist/server/subagent-templates-hant.js +0 -10
  338. package/dist/server/subagent-templates.js +3 -103
  339. package/dist/server/subagents.js +1 -87
  340. package/dist/server/system-screenshot-windows.js +259 -0
  341. package/dist/server/system-screenshot.js +77 -0
  342. package/dist/server/tabs.js +3 -48
  343. package/dist/server/terminals.js +559 -586
  344. package/dist/server/text-quote.js +0 -12
  345. package/dist/server/text-sniff.js +2 -52
  346. package/dist/server/themes.js +2 -41
  347. package/dist/server/tool-approval.js +0 -47
  348. package/dist/server/tool-guards.js +0 -90
  349. package/dist/server/tool-host-factories.js +1 -16
  350. package/dist/server/tool-info.js +0 -13
  351. package/dist/server/tool-manager.js +1 -229
  352. package/dist/server/tool-overrides.js +1 -46
  353. package/dist/server/tool-prompt-overrides.js +1 -30
  354. package/dist/server/tool-prompts.js +0 -14
  355. package/dist/server/tool-signature.js +0 -25
  356. package/dist/server/transcript-prepare.js +1 -19
  357. package/dist/server/tts-routes.js +58 -0
  358. package/dist/server/tts-service.js +106 -0
  359. package/dist/server/tts-system.js +160 -0
  360. package/dist/server/turn-timing.js +0 -1
  361. package/dist/server/unauthorized-page.js +0 -8
  362. package/dist/server/universal/driver-base.js +2 -31
  363. package/dist/server/universal/drivers/claude-code.js +12 -172
  364. package/dist/server/universal/drivers/codex.js +12 -35
  365. package/dist/server/universal/drivers/mock-driver.js +1 -11
  366. package/dist/server/universal/index.js +0 -3
  367. package/dist/server/universal/session-store.js +4 -21
  368. package/dist/server/universal/universal-attachments.js +2 -36
  369. package/dist/server/universal/universal-service.js +5 -24
  370. package/dist/server/universal/universal-session.js +26 -148
  371. package/dist/server/universal/universal-types.js +0 -3
  372. package/dist/server/update-check.js +6 -182
  373. package/dist/server/uploads.js +4 -43
  374. package/dist/server/virtual-tui.js +2 -27
  375. package/dist/server/vision-bridge.js +0 -27
  376. package/dist/server/wait-subscription-scan.js +13 -115
  377. package/dist/server/webui-context.js +2 -87
  378. package/dist/server/workspace-handle.js +1 -56
  379. package/dist/server/workspace-snapshot.js +7 -113
  380. package/dist/server/worktree-service.js +2 -53
  381. package/dist/server/worktree-tool.js +0 -11
  382. package/dist/server/ws-client-id.js +0 -18
  383. package/dist/server/ws-pending-queue.js +0 -7
  384. package/dist/server/ws-unknown-types.js +0 -17
  385. package/docs/README.md +24 -17
  386. package/docs/architecture-plugins.md +37 -1
  387. package/docs/device-center.md +28 -2
  388. package/docs/device-desktop.md +3 -3
  389. package/docs/group-orchestration.md +142 -0
  390. package/docs/hub-upgrade-release-testing.md +46 -0
  391. package/extensions/webui.ts +3 -74
  392. package/package.json +7 -3
  393. package/plugin-sdk/README.md +6 -0
  394. package/plugin-sdk/client-utils.mjs +0 -7
  395. package/plugin-sdk/client.d.ts +0 -1
  396. package/plugin-sdk/client.mjs +1 -31
  397. package/plugin-sdk/import-check.mjs +4 -51
  398. package/plugin-sdk/index.d.ts +120 -119
  399. package/plugin-sdk/index.mjs +0 -6
  400. package/plugin-sdk/ssh-host-trust.mjs +0 -12
  401. package/plugin-sdk/testing.d.ts +0 -1
  402. package/plugin-sdk/testing.mjs +31 -86
  403. package/plugins/catalog.json +52 -4
  404. package/plugins/superagent/README.md +110 -0
  405. package/plugins/superagent/client/entry.mjs +21 -0
  406. package/plugins/superagent/index.mjs +8 -0
  407. package/plugins/superagent/main.mjs +218 -0
  408. package/plugins/superagent/manifest.json +15 -0
  409. package/plugins/superagent/server.mjs +572 -0
  410. package/plugins/superagent/style.css +167 -0
  411. package/themes/aetheris.css +1 -31
  412. package/themes/ayu-light.css +0 -1
  413. package/themes/bases/flow-base.css +2 -83
  414. package/themes/bases/obsidian-base.css +2 -37
  415. package/themes/bases/statusbar-flat-base.css +0 -1
  416. package/themes/bases/zhujian-base.css +0 -63
  417. package/themes/bases/zhupi-base.css +0 -64
  418. package/themes/catppuccin-latte.css +0 -1
  419. package/themes/catppuccin.css +0 -1
  420. package/themes/claude-code-dark.css +0 -1
  421. package/themes/codex.css +0 -1
  422. package/themes/dark-teal.css +22 -54
  423. package/themes/everforest-light.css +0 -1
  424. package/themes/flow-cristallo.css +1 -9
  425. package/themes/flow-ink.css +1 -10
  426. package/themes/flow-light.css +1 -10
  427. package/themes/flow-obsidian.css +1 -10
  428. package/themes/flow-zurich.css +1 -10
  429. package/themes/flow.css +1 -9
  430. package/themes/geist.css +0 -1
  431. package/themes/gruvbox-light.css +0 -1
  432. package/themes/kanagawa-lotus.css +0 -1
  433. package/themes/md-preview.css +1 -2
  434. package/themes/mist.css +0 -1
  435. package/themes/nord.css +0 -1
  436. package/themes/one-dark.css +0 -1
  437. package/themes/paper.css +0 -1
  438. package/themes/rose-pine-dawn.css +0 -1
  439. package/themes/sakura.css +0 -1
  440. package/themes/solarized-light.css +0 -1
  441. package/themes/tokyo-night.css +0 -1
  442. package/themes/translucent.css +4 -35
  443. package/themes/transparent.css +4 -41
  444. package/themes/vs-code-dark.css +0 -1
  445. package/themes/wallpaper-flow.css +3 -17
  446. package/themes/wallpaper-obsidian.css +1 -4
  447. package/themes/white.css +0 -1
  448. package/web/dist/.build-assets.json +1 -1
  449. package/web/dist/assets/{BgTasksModal-BjNRIUIc.js → BgTasksModal-D-x7kA63.js} +1 -1
  450. package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
  451. package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
  452. package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
  453. package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
  454. package/web/dist/assets/{Dropdown-CQtstPGv.js → Dropdown-CTgVLUbp.js} +1 -1
  455. package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
  456. package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
  457. package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
  458. package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
  459. package/web/dist/assets/{HintTip-ChTW8o1m.js → HintTip-Da6qc566.js} +1 -1
  460. package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
  461. package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
  462. package/web/dist/assets/{PiSetupModal-BX5rUuoI.js → PiSetupModal-DZKY5Wiw.js} +1 -1
  463. package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
  464. package/web/dist/assets/{SCMPanel-DPAyY2sW.js → SCMPanel-CuEgzAlO.js} +2 -2
  465. package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
  466. package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
  467. package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
  468. package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
  469. package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
  470. package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
  471. package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
  472. package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
  473. package/web/dist/assets/index-CQc3VrWa.css +1 -0
  474. package/web/dist/assets/index-D_AGu4Zv.js +404 -0
  475. package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
  476. package/web/dist/assets/{remote-ssh-client-Dzi-eEyE.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
  477. package/web/dist/assets/theme-DGL7hLUs.js +1 -0
  478. package/web/dist/index.html +11 -10
  479. package/web/dist/sw.js +15 -61
  480. package/web/public/sw.js +14 -60
  481. package/web/dist/assets/BgTasksModal-C0zuU8FE.js +0 -1
  482. package/web/dist/assets/CanvasStudio-BWvdmJ0M.js +0 -1579
  483. package/web/dist/assets/CanvasStudio-VQFjmTGq.js +0 -1579
  484. package/web/dist/assets/DeviceCenter-DI9_0aBB.js +0 -3
  485. package/web/dist/assets/DeviceCenter-DsNtXqzY.js +0 -3
  486. package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +0 -1
  487. package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +0 -1
  488. package/web/dist/assets/DeviceGroups-CP7CcyPD.js +0 -1
  489. package/web/dist/assets/FilePreview-BMB2tNyT.js +0 -2
  490. package/web/dist/assets/FilePreview-RGFQUbJo.js +0 -2
  491. package/web/dist/assets/GlobalSearchModal-BM5wxiqU.js +0 -1
  492. package/web/dist/assets/GlobalSearchModal-DGv_WINq.js +0 -1
  493. package/web/dist/assets/GroupConversation-B7SnuXj1.js +0 -61
  494. package/web/dist/assets/GroupConversation-Dda69q-2.js +0 -61
  495. package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +0 -2
  496. package/web/dist/assets/ModelConfigModal-yqeadyab.js +0 -2
  497. package/web/dist/assets/ProviderOAuthControls-DY4SCfXg.js +0 -1
  498. package/web/dist/assets/SCMPanel-C4KbQvvK.js +0 -2
  499. package/web/dist/assets/SettingsModal-DxZp6D_g.js +0 -32
  500. package/web/dist/assets/SettingsModal-WhQzaOPt.js +0 -32
  501. package/web/dist/assets/TerminalPanel-D4By_RVc.js +0 -3
  502. package/web/dist/assets/TerminalPanel-lZw8-i3j.js +0 -3
  503. package/web/dist/assets/TuiOverlayModal-C3pAVuC8.js +0 -1
  504. package/web/dist/assets/TuiOverlayModal-D7_rEXcJ.js +0 -1
  505. package/web/dist/assets/app-globals-KqOVtmp1.js +0 -123
  506. package/web/dist/assets/canvas-client-BY6ojmle.js +0 -1
  507. package/web/dist/assets/desktop-CV6KKp9R.js +0 -1
  508. package/web/dist/assets/index-BawF7ZP5.js +0 -397
  509. package/web/dist/assets/index-BoGCoq5X.js +0 -397
  510. package/web/dist/assets/index-CVW9FoY2.css +0 -1
  511. package/web/dist/assets/plugin-host-Dn8Dd6SC.js +0 -1
  512. package/web/dist/assets/theme-D_bihpdN.js +0 -1
@@ -1,4 +1,3 @@
1
- /** 校验引用元数据,保留原文的换行和缩进。 */
2
1
  export function readTextQuote(value) {
3
2
  if (!value || typeof value !== "object")
4
3
  return null;
@@ -17,7 +16,6 @@ export function readTextQuote(value) {
17
16
  ...(typeof q.sessionId === "string" && q.sessionId ? { sessionId: q.sessionId } : {}),
18
17
  };
19
18
  }
20
- /** JSON 字符串保留原文边界,引用中的换行不参与外层标记解析。 */
21
19
  export function formatTextQuote(quote) {
22
20
  return `<quoted-text>\n${JSON.stringify(quote)}\n</quoted-text>`;
23
21
  }
@@ -38,11 +36,6 @@ export function formatQuotedPrompt(text, quotes) {
38
36
  function escapeAttr(value) {
39
37
  return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
40
38
  }
41
- /**
42
- * 流式中排队/插队发送时把文本、文本附件(文件/目录/网页/对话引用/视觉桥)、
43
- * 引用与图片标记格式化到同一条提示词中,避免使用 SDK 的 _pendingNextTurnMessages
44
- * 造成排队消息丢失附件以及泄露到后续提问。
45
- */
46
39
  export function formatStreamingPrompt(text, textAsides = [], quotes = [], imageNames = []) {
47
40
  const parts = [];
48
41
  const trimmed = (text ?? "").trim();
@@ -62,10 +55,6 @@ export function formatStreamingPrompt(text, textAsides = [], quotes = [], imageN
62
55
  }
63
56
  return parts.join("\n\n");
64
57
  }
65
- /**
66
- * 将附件消息(asides)解构为流式排队/插队可消费的载荷。
67
- * 统一作为单源解析,杜绝空闲/流式分支错位造成的丢图、漏附件与非视觉模型静默丢弃。
68
- */
69
58
  export function extractStreamingPayload(asides, initialQuotes = [], mainSupportsVision = false, modelLabel = "unknown") {
70
59
  const promptImages = [];
71
60
  const textAsides = [];
@@ -123,7 +112,6 @@ export function extractStreamingPayload(asides, initialQuotes = [], mainSupports
123
112
  }
124
113
  return { promptImages, textAsides, imageNames, quotes };
125
114
  }
126
- /** 排队项把引用与附件随提问一起保存;展示时拆分末尾的引用块与附件标记。 */
127
115
  export function splitQuotedPrompt(value) {
128
116
  let text = value;
129
117
  const quotes = [];
@@ -1,10 +1,3 @@
1
- /**
2
- * text-sniff — 文件预览相关的纯函数:扩展名分类、内容嗅探、文本解码
3
- * (UTF-8 → GBK → latin1 回退)、十六进制视图、行数统计。
4
- *
5
- * 全部无副作用、不碰 fs —— 便于单元测试(tests/unit/text-sniff.test.ts)。
6
- * 从 agent-service.ts 抽出,行为保持不变。
7
- */
8
1
  const PREVIEW_IMAGE_EXTS = new Set([
9
2
  "png",
10
3
  "jpg",
@@ -20,12 +13,8 @@ const PREVIEW_IMAGE_EXTS = new Set([
20
13
  "tiff",
21
14
  ]);
22
15
  const PREVIEW_VIDEO_EXTS = new Set(["mp4", "webm", "mov", "mkv", "avi", "m4v", "ogv", "mpg", "mpeg", "wmv", "flv"]);
23
- /** 浏览器 <audio> 能直接播放的音频容器(present_files 的卡片与 /api/file 白名单
24
- * 共用这一份):不在表里的(wma/aiff/midi/…)一律按二进制处理,让用户下载或
25
- * 本地打开,而不是给一个永远播不出来的播放器。 */
26
16
  const PREVIEW_AUDIO_EXTS = new Set(["mp3", "wav", "wave", "ogg", "oga", "opus", "m4a", "aac", "flac", "weba"]);
27
17
  const PREVIEW_TEXT_EXTS = new Set([
28
- // code
29
18
  "ts",
30
19
  "tsx",
31
20
  "js",
@@ -98,7 +87,6 @@ const PREVIEW_TEXT_EXTS = new Set([
98
87
  "hrl",
99
88
  "ml",
100
89
  "mli",
101
- // markup / config / data
102
90
  "json",
103
91
  "jsonc",
104
92
  "json5",
@@ -138,14 +126,8 @@ const PREVIEW_TEXT_EXTS = new Set([
138
126
  "asm",
139
127
  "s",
140
128
  ]);
141
- /**
142
- * Classify a file name into its preview category. Files with no extension
143
- * (README, Makefile, .gitignore, …) are treated as text. Everything not in an
144
- * allowlist (exe, jar, dll, zip, …) is "none" — never previewed.
145
- */
146
129
  export function previewKind(name) {
147
130
  const dot = name.lastIndexOf(".");
148
- // A leading dot with nothing after it (.gitignore, .env) counts as no ext.
149
131
  const ext = dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
150
132
  if (PREVIEW_IMAGE_EXTS.has(ext))
151
133
  return "image";
@@ -157,22 +139,11 @@ export function previewKind(name) {
157
139
  return "text";
158
140
  return "none";
159
141
  }
160
- /**
161
- * 扩展名是否为浏览器可直接播放的音频。与 previewKind 分开:预览弹窗的媒体分支
162
- * 只关心 image/video,音频得单独判一次;而 /api/file 的媒体白名单与
163
- * present_files 的卡片只需要一个「能不能 inline 播」的布尔判断。
164
- */
165
142
  export function isAudioFile(name) {
166
143
  const dot = name.lastIndexOf(".");
167
144
  const ext = dot > 0 ? name.slice(dot + 1).toLowerCase() : "";
168
145
  return PREVIEW_AUDIO_EXTS.has(ext);
169
146
  }
170
- /**
171
- * Content sniff for the preview: any data that has no NUL bytes and no
172
- * meaningful control-char ratio is treated as text — so files with unknown
173
- * or absent extensions (jsonl, .log.1, …) still open as text. NULs catch
174
- * zip/sqlite/png/… even when the extension claims text.
175
- */
176
147
  export function looksLikeText(buf) {
177
148
  if (buf.length === 0)
178
149
  return true;
@@ -182,30 +153,18 @@ export function looksLikeText(buf) {
182
153
  let control = 0;
183
154
  for (const ch of text) {
184
155
  const c = ch.charCodeAt(0);
185
- // Keep \t \n \f \r; everything else < 0x20 (including \b and \v) is binary-ish.
186
156
  if (c < 0x20 && c !== 9 && c !== 10 && c !== 12 && c !== 13)
187
157
  control++;
188
158
  }
189
159
  return control / Math.max(text.length, 1) < 0.02;
190
160
  }
191
- /** Decode bytes: strict UTF-8 first (retrying with up to 3 truncated tail
192
- * bytes removed for excerpt/preview buffers cut mid-character), falling back
193
- * to GBK (Windows legacy Chinese files), then latin1 as a last resort — so
194
- * previews and inline attachments never show mojibake for GBK/GB2312 files
195
- * nor for truncated UTF-8 files (issue #392). */
196
161
  export function decodeText(buf) {
197
- // `cut < buf.length` keeps the truncated-tail retry from eating the whole
198
- // buffer: a 1–3 byte buffer of legacy bytes (GBK "中" = D6 D0) would
199
- // otherwise trim down to an empty slice, decode "successfully" as UTF-8 and
200
- // return "" — silently blanking every tiny non-UTF-8 preview.
201
162
  for (let cut = 0; cut < 4 && cut < buf.length; cut++) {
202
163
  const slice = cut === 0 ? buf : buf.subarray(0, buf.length - cut);
203
164
  try {
204
165
  return new TextDecoder("utf-8", { fatal: true }).decode(slice);
205
166
  }
206
- catch {
207
- // Tail byte might be cut mid-character; try trimming up to 3 bytes.
208
- }
167
+ catch { }
209
168
  }
210
169
  try {
211
170
  return new TextDecoder("gbk").decode(buf);
@@ -214,9 +173,6 @@ export function decodeText(buf) {
214
173
  return buf.toString("latin1");
215
174
  }
216
175
  }
217
- /** Sniff an image MIME type from magic bytes (extension is only a hint).
218
- * Returns null when the bytes don't look like a known raster format —
219
- * callers keep such files as plain path references. */
220
176
  export function sniffImageMime(buf, ext) {
221
177
  if (buf.length >= 8 && buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47) {
222
178
  return "image/png";
@@ -234,8 +190,6 @@ export function sniffImageMime(buf, ext) {
234
190
  }
235
191
  if (buf.length >= 2 && buf[0] === 0x42 && buf[1] === 0x4d)
236
192
  return "image/bmp";
237
- // Unknown but raster-looking extension — trust the extension so existing
238
- // image attachments keep working.
239
193
  const known = {
240
194
  ".png": "image/png",
241
195
  ".jpg": "image/jpeg",
@@ -246,7 +200,6 @@ export function sniffImageMime(buf, ext) {
246
200
  };
247
201
  return known[ext] ?? null;
248
202
  }
249
- /** First few KB of binary data as a classic hex + ASCII dump (preview only). */
250
203
  export function hexDump(buf, maxBytes = 4096) {
251
204
  const data = buf.subarray(0, Math.min(buf.length, maxBytes));
252
205
  const rows = [];
@@ -258,13 +211,10 @@ export function hexDump(buf, maxBytes = 4096) {
258
211
  }
259
212
  return rows.join("\n");
260
213
  }
261
- /** Count lines in a buffer; a trailing newline terminates the last line
262
- * instead of starting an empty one — matches the client preview's
263
- * split-based line numbering. */
264
214
  export function countLines(buf) {
265
215
  if (buf.length === 0)
266
216
  return 0;
267
- const hasTrailingNewline = buf[buf.length - 1] === 10; /* \n */
217
+ const hasTrailingNewline = buf[buf.length - 1] === 10;
268
218
  let lines = 0;
269
219
  for (let i = 0; i < buf.length; i++) {
270
220
  if (buf[i] === 10)
@@ -1,29 +1,9 @@
1
- /**
2
- * Theme management: pure `:root` palette overrides. The whole UI layout lives
3
- * in web/src/styles.css (single source); a theme is just a small CSS file that
4
- * overrides the :root CSS variables (--bg/--accent/--term-* plus derived ones
5
- * like --tooltip-bg/--code-bg). The frontend injects the theme file as a
6
- * <link> AFTER the bundled styles.css, so its :root variables win the cascade.
7
- * Builtin themes are generated by node make-light-theme.mjs.
8
- *
9
- * Theme sources (merged, user wins over builtin on id collision):
10
- * - builtin: <pkgRoot>/themes/*.css (ships with the npm package)
11
- * - user : <dataDir>/themes/*.css (drop a css file here to add a theme)
12
- */
13
1
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
14
2
  import { dirname, join, resolve } from "node:path";
15
- /** Only simple file ids — no path traversal. */
16
3
  const ID_RE = /^[A-Za-z0-9_-]+$/;
17
- /** Display-name marker inside a theme css file (first lines):
18
- * `/* theme-name: 中文名 *∕` — falls back to the file id when absent.
19
- * `/* theme-name-en: English Name *∕` — optional English label; falls back
20
- * to `name` when absent.
21
- * Lets built-in AND user themes carry a human-readable label while the
22
- * filename stays ASCII (id must match ID_RE). */
23
4
  const THEME_NAME_RE = /\/\*\s*theme-name:\s*(.+?)\s*\*\//;
24
5
  const THEME_NAME_EN_RE = /\/\*\s*theme-name-en:\s*(.+?)\s*\*\//;
25
6
  const THEME_GROUP_RE = /\/\*\s*theme-group:\s*(.+?)\s*\*\//;
26
- /** 从主题 CSS 头部读取 color-scheme(浅/暗),无法识别时返回 undefined。 */
27
7
  const THEME_SCHEME_RE = /color-scheme:\s*(dark|light)/i;
28
8
  function readScheme(path) {
29
9
  try {
@@ -32,9 +12,7 @@ function readScheme(path) {
32
12
  if (m && (m[1] === "dark" || m[1] === "light"))
33
13
  return m[1];
34
14
  }
35
- catch {
36
- // ignore
37
- }
15
+ catch { }
38
16
  return undefined;
39
17
  }
40
18
  function readDisplayName(path, fallback) {
@@ -62,9 +40,7 @@ function readGroup(path) {
62
40
  if (g === "classic")
63
41
  return "classic";
64
42
  }
65
- catch {
66
- // ignore
67
- }
43
+ catch { }
68
44
  return "builtin";
69
45
  }
70
46
  export function listThemes(builtinDir, userDir) {
@@ -98,7 +74,6 @@ export function listThemes(builtinDir, userDir) {
98
74
  .filter((t) => (seen.has(t.id) ? false : (seen.add(t.id), true)))
99
75
  .sort((a, b) => a.name.localeCompare(b.name));
100
76
  }
101
- /** Resolve a theme id to its css file path (user dir first). */
102
77
  export function resolveThemeFile(builtinDir, userDir, id) {
103
78
  if (!ID_RE.test(id))
104
79
  return null;
@@ -111,26 +86,12 @@ export function resolveThemeFile(builtinDir, userDir, id) {
111
86
  }
112
87
  return null;
113
88
  }
114
- /**
115
- * 读取主题 CSS,并安全展开其中的 `@import "./..."` 相对导入。
116
- * - 仅允许相对当前主题文件所在目录的子路径(或同级);
117
- * - 限制递归深度(默认 3 层)防循环引用;
118
- * - 仅允许引入 .css 文件;
119
- * - 确保生产/开发模式下均能无缝组合共享形态基底(如 bases/flow-base.css),免去客户端多次瀑布流请求。
120
- *
121
- * 返回的整份样式表会被包进 `@layer theme { ... }`(与 `web/src/styles.css` 的
122
- * `@layer guard, base, theme;` 声明配套:主题层永远压在 base 之上,主题之间不再靠
123
- * `!important` 抢权重)。只包**最外层一次**——递归内联的子文件必须原样返回,
124
- * 否则会形成嵌套层(嵌套层无法与顶层 base/theme 正确比较顺序)。
125
- * 调用方(`server/index.ts` 的 `/themes/:id.css`)行为不变:仍直接写回响应。
126
- */
127
89
  export function readThemeCss(filePath, visited = new Set(), depth = 0) {
128
90
  const css = inlineThemeImports(filePath, visited, depth);
129
91
  if (depth > 0 || !css.trim())
130
92
  return css;
131
93
  return `@layer theme {\n${css.trimEnd()}\n}\n`;
132
94
  }
133
- /** `readThemeCss` 的内联主体:递归调用自身(不包层,见上文)。 */
134
95
  function inlineThemeImports(filePath, visited, depth) {
135
96
  if (depth > 3 || visited.has(filePath))
136
97
  return "";
@@ -1,68 +1,35 @@
1
- /**
2
- * server/tool-approval.ts
3
- *
4
- * 人机协同拦截与「改写执行」(Human-in-the-Loop: Edit & Run)。
5
- *
6
- * 功能:
7
- * 1. 高危操作识别与规则裁决(Dangerous Tool Call & Rule Evaluation):
8
- * - 委托 server/approval-rules.ts 的规则引擎评估
9
- * - 支持三种动作:ask(弹窗审批)、deny(直接拒绝报错)、allow(白名单放行)
10
- * 2. 审批事件挂起与答复处理(askApproval / resolveApproval):
11
- * - 用户可「批准」(Approve)
12
- * - 用户可「拒绝」(Deny)
13
- * - 用户可就地修改参数后「修改并放行」(Edit & Run)
14
- * 3. 三档放行策略(省去反复弹窗):
15
- * - 全局关(设置 →「工具」页的「工具执行审批」总开关)→ 一律不弹;
16
- * - 本对话「全部允许」→ 该对话内一律不弹;
17
- * - 本对话「允许同类」→ 该对话内同一规则档位(category)不再弹。
18
- * 策略只活在内存里(挂在 Conversation 上,过户随对话搬走),重启/新对话即恢复询问。
19
- */
20
1
  import { DEFAULT_APPROVAL_RULES, evaluateApprovalRules, extractTargetPath, } from "./approval-rules.js";
21
- /** 策略为空(既没全部允许也没记同类):调用方据此不挂空策略、面板据此不显示撤销区。 */
22
2
  export function isApprovalPolicyEmpty(policy) {
23
3
  return !policy || (!policy.allowAll && policy.categories.size === 0);
24
4
  }
25
- /**
26
- * 判定某个工具调用是否属于超宽范围、全局根目录或系统级不可逆操作(Issue #722)。
27
- * 针对此类全局高危操作,即便用户之前曾为局部目录勾选过「允许同类」,
28
- * 同类记忆(category)亦强制失效,必须显式弹窗审批(除非用户选择了本对话「全部允许」)。
29
- */
30
5
  export function isWideScopeOrRootOperation(toolName, params) {
31
6
  if (!params || typeof params !== "object")
32
7
  return false;
33
8
  const obj = params;
34
9
  if (toolName === "bash") {
35
10
  const cmd = String(obj.command ?? "").trim();
36
- // 1. 递归/强制删除大范围根路径、家目录、父目录、盘符根目录或通配符
37
- // 形如 `rm -rf /`、`rm -rf ~`、`rm -rf ..`、`rm -rf *`、`rm -rf C:\`
38
11
  if (/\brm\s+.*(-[a-zA-Z0-9]*[rf]|--recursive)/i.test(cmd)) {
39
- // 匹配单独的危险目标 token:/、~、..、*、或 Windows 根盘如 C:\
40
12
  if (/(?:^|\s)(?:[/~*]|\.\.|[a-zA-Z]:[\\/])(?:\s|$)/.test(cmd)) {
41
13
  return true;
42
14
  }
43
15
  }
44
- // 2. Windows 强制递归删除系统/根盘目标
45
16
  if (/\b(del|rmdir|rd)\s+[/\\-][fsq]/i.test(cmd)) {
46
17
  if (/(?:^|\s)(?:[/~*]|\.\.|[a-zA-Z]:[\\/])(?:\s|$)/.test(cmd)) {
47
18
  return true;
48
19
  }
49
20
  }
50
- // 3. 磁盘格式化或底层写入 (format C:, mkfs, dd if=)
51
21
  if (/\b(mkfs|format\s+[a-zA-Z]:|dd\s+if=)/i.test(cmd)) {
52
22
  return true;
53
23
  }
54
- // 4. 重定向覆盖系统目录
55
24
  if (/>\s*(?:\/etc\/|\/boot\/|C:\\Windows)/i.test(cmd)) {
56
25
  return true;
57
26
  }
58
- // 5. 全局危险权限修改 chmod 777 -R / 或 chmod -R 777 /
59
27
  if (/\bchmod\s+.*?(?:777|000).*?(?:[/~]|[a-zA-Z]:[\\/])/i.test(cmd)) {
60
28
  return true;
61
29
  }
62
30
  }
63
31
  if (toolName === "write" || toolName === "edit" || toolName === "edit_soft" || toolName === "patch") {
64
32
  const p = extractTargetPath(params);
65
- // 敏感系统文件与密钥凭据(跨文件的同类不能随意扩散到系统或密钥)
66
33
  if (p.includes("/etc/") ||
67
34
  p.includes("/boot/") ||
68
35
  p.includes("C:\\Windows") ||
@@ -74,12 +41,6 @@ export function isWideScopeOrRootOperation(toolName, params) {
74
41
  }
75
42
  return false;
76
43
  }
77
- /**
78
- * 三档放行的纯判定:返回 null = 需要弹审批,否则返回放行的原因。
79
- * - `disabled`:全局开关关(设置 →「工具」页)→ 一切审批都不弹(插件显式 ask 也放行);
80
- * - `allow-all`:本对话已「全部允许」;
81
- * - `category`:本对话已记住该同类档位(但全局高危/根路径操作除外,见 isWideScopeOrRootOperation)。
82
- */
83
44
  export function approvalSuppressionReason(policy, enabled, categoryId, toolName, params) {
84
45
  if (!enabled)
85
46
  return "disabled";
@@ -88,9 +49,6 @@ export function approvalSuppressionReason(policy, enabled, categoryId, toolName,
88
49
  if (policy.allowAll)
89
50
  return "allow-all";
90
51
  if (categoryId && policy.categories.has(categoryId)) {
91
- // 特权边界收敛(Issue #722):
92
- // 即使已记住同类档位,若当前操作属于全局根路径、系统破坏性或敏感密钥写入等超宽操作,
93
- // 严禁凭同类记忆静默放行,必须强制弹窗要求显式确认。
94
52
  if (toolName && params && isWideScopeOrRootOperation(toolName, params)) {
95
53
  return null;
96
54
  }
@@ -98,7 +56,6 @@ export function approvalSuppressionReason(policy, enabled, categoryId, toolName,
98
56
  }
99
57
  return null;
100
58
  }
101
- /** 插件显式要求确认(pre guard 的 ask)对应的档位:按插件 id 分档,可「允许同类」。 */
102
59
  export function pluginApprovalCategory(pluginId) {
103
60
  return {
104
61
  id: `plugin:${pluginId}`,
@@ -106,10 +63,6 @@ export function pluginApprovalCategory(pluginId) {
106
63
  labelEn: `Plugin ${pluginId} requested confirmation`,
107
64
  };
108
65
  }
109
- /**
110
- * 检测某个工具调用是否属于高危操作,或命中用户自定义规则。
111
- * 可选接收 rules 规则集;缺省时以内置默认高危规则集判定。
112
- */
113
66
  export function checkDangerousToolCall(toolName, params, cwd, workspaceRoots = [], rules) {
114
67
  if (!params || typeof params !== "object") {
115
68
  return { dangerous: false };
@@ -1,15 +1,3 @@
1
- /**
2
- * 工具守卫与模式拦截门控(Tool Guards & Mode Gates)
3
- *
4
- * 包含:
5
- * - 计划模式硬闸门(withPlanModeGate)
6
- * - 目标审查回合闸门(withGoalReviewGate)
7
- * - 审查者委派模式闸门(withDelegationGate)
8
- * - 插件守卫与人机协同审批(withToolGuard / makeLateToolGuard)
9
- * - 只读 / 工作区沙箱权限包装器(wrapWriteToolWithPermission / wrapEditToolWithPermission 等)
10
- *
11
- * 从 agent-service.ts 抽出为独立模块。
12
- */
13
1
  import { resolve } from "node:path";
14
2
  import { createWriteToolDefinition, createEditToolDefinition, } from "@earendil-works/pi-coding-agent";
15
3
  import { pick } from "./i18n.js";
@@ -24,12 +12,6 @@ import { createRemoteSdkOperations, isRemoteWorkspaceUri, parseRemoteWorkspaceUr
24
12
  function checkCancellation(signal) {
25
13
  signal?.throwIfAborted();
26
14
  }
27
- /**
28
- * 计划模式闸门装饰(通用):套在任何工具定义外层,只在**执行前**判定一次。
29
- * 与权限沙箱/插件守卫平行且更靠外 —— 计划模式是会话级硬约束,不给任何
30
- * 「记住同类/全部允许」的口子(允许了就等于放开了实施)。
31
- * 关闭时零开销(返回原定义,不包 execute)。
32
- */
33
15
  export function withPlanModeGate(def, planMode, getLang) {
34
16
  return {
35
17
  ...def,
@@ -54,13 +36,6 @@ export function withPlanModeGate(def, planMode, getLang) {
54
36
  }),
55
37
  };
56
38
  }
57
- /**
58
- * 目标审查回合闸门(server/goal-review-gate.ts):主对话在 `awaitingVerdict`
59
- * 置位期间是审查者 —— 写类工具、非常规 bash、派发类工具、向用户提问一律拒。
60
- * 形状与 withPlanModeGate / withDelegationGate 同构,串在最外层(理由最贴合
61
- * 此刻:跟模型说「这是审查回合」比「这是计划/审查者模式」更有用)。闸门无状态
62
- * (每次执行只读 `awaitingVerdict`),verdict 落定即自动恢复,不存在钉死。
63
- */
64
39
  export function withGoalReviewGate(def, reviewTurn, getLang) {
65
40
  return {
66
41
  ...def,
@@ -82,17 +57,7 @@ export function withGoalReviewGate(def, reviewTurn, getLang) {
82
57
  }),
83
58
  };
84
59
  }
85
- /**
86
- * 标记某个工具已包含审批/安全规则防护(防重复包装)。
87
- */
88
60
  export const APPROVAL_GUARDED = Symbol.for("pi.approvalGuarded");
89
- /**
90
- * 通用工具审批门禁(Issue #722):
91
- * 对任意工具(包括插件工具、MCP 动态接入工具、自定义扩展工具)执行审批规则判定(checkDangerousToolCall)。
92
- * - 若命中 deny 规则,直接阻断并返回错误;
93
- * - 若命中 ask 规则,唤起人机协同审批(Human-in-the-Loop);
94
- * - 若命中 allow 规则或未命中高危规则,透传执行底层 execute。
95
- */
96
61
  export function withApprovalGate(def, opts) {
97
62
  if (def[APPROVAL_GUARDED]) {
98
63
  return def;
@@ -155,12 +120,6 @@ export function withApprovalGate(def, opts) {
155
120
  Object.assign(wrapped, { [APPROVAL_GUARDED]: true });
156
121
  return wrapped;
157
122
  }
158
- /**
159
- * 审查者模式闸门(server/delegate-mode.ts):主对话只审阅不施工 ——
160
- * 写类工具、非常规 bash、派发类工具一律拒。形状与 withPlanModeGate 同构,
161
- * 串在它**外层**(两者都开时,先问计划模式还是审查者模式都不影响结果:
162
- * 都是拒,只是理由不同)。
163
- */
164
123
  export function withDelegationGate(def, delegateMode, getLang) {
165
124
  return {
166
125
  ...def,
@@ -182,16 +141,6 @@ export function withDelegationGate(def, delegateMode, getLang) {
182
141
  }),
183
142
  };
184
143
  }
185
- /**
186
- * 把「可能晚一点才注入」的插件守卫包成**调用时解析**的代理。
187
- *
188
- * 为什么需要它(P1-5 的真实缺口):`withToolGuard` 在建工具定义时就把 `opts.guard`
189
- * 捕进了闭包,而 runtime 是在 `ClientSession.create()` 里建的、`cs.toolGuard` 却是在
190
- * `AgentService.attach()` 末尾才赋值 —— 直接传 `this.toolGuard` 会把 `undefined`
191
- * 永久固化进那条对话的工具里,于是「attach 时恢复出来的那条对话」永远不受
192
- * 插件 `onToolPre/onToolPost` 约束(只有新建/切换对话才带上)。代理每次调用才解析,
193
- * 与赋值时序无关;未注入时逐字等价于直通(allow / undefined)。
194
- */
195
144
  export function makeLateToolGuard(get) {
196
145
  return {
197
146
  pre: (req, lang) => get()?.pre(req, lang) ?? Promise.resolve({ verdict: { decision: "allow" } }),
@@ -219,12 +168,10 @@ export function withToolGuard(def, opts) {
219
168
  }
220
169
  checkCancellation(signal);
221
170
  }
222
- // 检查是否需要人工协同审批(Human-in-the-Loop)
223
171
  let needApproval = false;
224
172
  let approvalReason;
225
173
  let approvalReasonEn;
226
174
  let approvalCategory;
227
- // 1. 系统核心安全:内置高危操作检测与自定义审批规则先行(优先级最高,防短路)
228
175
  let danger;
229
176
  if (opts.cwd && opts.askApproval) {
230
177
  danger = checkDangerousToolCall(toolName, params, opts.cwd, opts.getRoots?.() ?? [], opts.getRules?.());
@@ -248,7 +195,6 @@ export function withToolGuard(def, opts) {
248
195
  };
249
196
  }
250
197
  }
251
- // 2. 插件前置守卫 deny 拦截(带 isError 标记)
252
198
  if (pre?.verdict.decision === "deny") {
253
199
  const text = denialText(pre.verdict, pre.pluginId ?? "plugin", lang);
254
200
  return {
@@ -257,7 +203,6 @@ export function withToolGuard(def, opts) {
257
203
  isError: true,
258
204
  };
259
205
  }
260
- // 3. 决定是否需要弹窗审批(系统高危 ask 优先于插件通用 ask,防止恶意或低危插件掩盖高危告警)
261
206
  let approvalHits;
262
207
  if (danger?.dangerous) {
263
208
  needApproval = true;
@@ -270,7 +215,6 @@ export function withToolGuard(def, opts) {
270
215
  needApproval = true;
271
216
  approvalReason = pre.verdict.reason ?? "插件要求确认本次操作";
272
217
  approvalReasonEn = pre.verdict.reasonEn ?? "Plugin requested confirmation for this operation";
273
- // 插件档位按插件 id 分:用户可以「允许同类」= 该插件的确认以后不再问。
274
218
  approvalCategory = pluginApprovalCategory(pre.pluginId ?? "plugin");
275
219
  }
276
220
  let effectiveParams = params;
@@ -298,7 +242,6 @@ export function withToolGuard(def, opts) {
298
242
  }
299
243
  }
300
244
  else if (pre?.verdict.decision === "ask") {
301
- // 无审批通道时回落至原先的阻断行为
302
245
  const text = denialText(pre.verdict, pre.pluginId ?? "plugin", lang);
303
246
  return {
304
247
  content: [{ type: "text", text }],
@@ -334,7 +277,6 @@ export function withToolGuard(def, opts) {
334
277
  [APPROVAL_GUARDED]: true,
335
278
  };
336
279
  }
337
- /** 校验目标路径是否在工作区(或多根工作区)内。严格规范化防止 ".." 逃逸与 Windows 盘符大小写不一致。 */
338
280
  export function isInsideWorkspaceRoots(targetPath, cwd, roots = []) {
339
281
  const effCwd = restoreWorkspaceUriFromSessionDir(cwd);
340
282
  if (isRemoteWorkspaceUri(effCwd)) {
@@ -347,11 +289,6 @@ export function isInsideWorkspaceRoots(targetPath, cwd, roots = []) {
347
289
  const allRoots = [resolve(cwd), ...roots.map((r) => resolve(r))];
348
290
  return allRoots.some((r) => isPathInsideRoot(abs, r));
349
291
  }
350
- /**
351
- * 为 write 工具包装会话级权限沙箱与人机协同审批。
352
- * `base` = 覆盖基底:第三方扩展注册的同名 write 优先(见 tool-overrides.ts),
353
- * 省略则是 SDK 内置实现 —— 于是权限门禁叠在扩展实现之上,而不是把它顶掉。
354
- */
355
292
  export function wrapWriteToolWithPermission(cwd, getPermission, getRoots, getLang, askApproval, getConversationId, getRules, base) {
356
293
  const remoteOps = !base ? createRemoteSdkOperations(cwd) : null;
357
294
  const effectiveBase = base ?? createWriteToolDefinition(cwd, remoteOps ? { operations: remoteOps.write } : undefined);
@@ -385,7 +322,6 @@ export function wrapWriteToolWithPermission(cwd, getPermission, getRoots, getLan
385
322
  };
386
323
  }
387
324
  }
388
- // 高危写操作人机协同审批拦截(如敏感配置修改)与规则匹配
389
325
  let effectiveParams = params;
390
326
  let userEdited = false;
391
327
  if (askApproval) {
@@ -439,24 +375,13 @@ export function wrapWriteToolWithPermission(cwd, getPermission, getRoots, getLan
439
375
  [APPROVAL_GUARDED]: true,
440
376
  };
441
377
  }
442
- /**
443
- * `edit` 的模型可见主描述(仅无扩展覆盖时的基底用;有扩展 edit 时保留它自己的文案)。
444
- *
445
- * SDK 自带的描述与其自带 guidelines 几乎逐条复述(oldText 要唯一匹配 / 多处改动合成一次调用 /
446
- * 不要垫大段未改区域都说两遍),单条信息重复进上下文。这里只留一句「做什么」,细节交给
447
- * guidelines(它们是 SDK 的,本模块不碰)。
448
- */
449
378
  export const EDIT_DESCRIPTION = "Edit a single file by exact text replacement: every edits[].oldText must uniquely match the original file.";
450
- /** `edit` 的精简 guidelines(同上:只用于无扩展覆盖的基底;与 SDK 四条规则一一对应,只去冗余措辞)。 */
451
379
  export const EDIT_GUIDELINES = [
452
380
  "Use edit for precise changes; oldText must match exactly",
453
381
  "When changing several separate locations in one file, put them in ONE call's edits[] instead of multiple calls",
454
382
  "Each oldText matches the original file, not earlier edits in the same call — never overlapping or nested",
455
383
  "Keep oldText small but unique; never pad with large unchanged regions",
456
384
  ];
457
- /**
458
- * 为 edit 工具包装会话级权限沙箱与人机协同审批(基底语义同 write)。
459
- */
460
385
  export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang, askApproval, getConversationId, getRules, base) {
461
386
  const remoteOps = !base ? createRemoteSdkOperations(cwd) : null;
462
387
  const effectiveBase = base ?? createEditToolDefinition(cwd, remoteOps ? { operations: remoteOps.edit } : undefined);
@@ -490,7 +415,6 @@ export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang
490
415
  };
491
416
  }
492
417
  }
493
- // 高危修改人机协同审批拦截与规则匹配
494
418
  let effectiveParams = params;
495
419
  let userEdited = false;
496
420
  if (askApproval) {
@@ -544,7 +468,6 @@ export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang
544
468
  [APPROVAL_GUARDED]: true,
545
469
  };
546
470
  }
547
- /** 为 edit_soft 工具包装会话级权限沙箱与人机协同审批。 */
548
471
  export function wrapEditSoftToolWithPermission(tool, cwd, getPermission, getRoots, getLang, askApproval, getConversationId, getRules) {
549
472
  return {
550
473
  ...tool,
@@ -576,7 +499,6 @@ export function wrapEditSoftToolWithPermission(tool, cwd, getPermission, getRoot
576
499
  };
577
500
  }
578
501
  }
579
- // 高危修改人机协同审批拦截与规则匹配
580
502
  let effectiveParams = params;
581
503
  let userEdited = false;
582
504
  if (askApproval) {
@@ -630,20 +552,12 @@ export function wrapEditSoftToolWithPermission(tool, cwd, getPermission, getRoot
630
552
  [APPROVAL_GUARDED]: true,
631
553
  };
632
554
  }
633
- /** 为 patch 工具包装会话级权限沙箱与人机协同审批。
634
- *
635
- * patch 的写目标(含 REM 删除与 MV 改名的目标路径)内嵌在补丁文本的 [path#TAG]
636
- * 段头里,规则引擎的 path 字段提取对它取到空串——若不单独解析,read-only /
637
- * workspace-write-never 权限预设与敏感文件规则(.env/SSH 密钥等)会被整体旁路:
638
- * write/edit 会拦的操作,模型改走 patch 即可原样落地(与 write/edit 同级的写面工具)。
639
- * 路径提取复用引擎自己的 parseHashlinePatch,保证与实际执行面一致、无漏判。 */
640
555
  export function wrapPatchToolWithPermission(tool, cwd, getPermission, getRoots, getLang, askApproval, getConversationId, getRules) {
641
556
  return {
642
557
  ...tool,
643
558
  execute: async (toolCallId, params, signal, onUpdate, ctx) => {
644
559
  checkCancellation(signal);
645
560
  const patchText = typeof params?.patch === "string" ? params.patch : "";
646
- // 解析失败/空补丁不拦:引擎自己会报错,不会发生任何写。
647
561
  let targets = [];
648
562
  try {
649
563
  const sections = parseHashlinePatch(patchText);
@@ -685,9 +599,6 @@ export function wrapPatchToolWithPermission(tool, cwd, getPermission, getRoots,
685
599
  };
686
600
  }
687
601
  }
688
- // 审批规则:逐目标路径以 { patch, path } 合成参数求值——path 规则
689
- // (敏感文件等)由此命中;field:params 规则仍能看到补丁全文。任一路径
690
- // 命中 deny 即整体阻断;命中 ask 只弹一次(合成参数带首个敏感路径与全文)。
691
602
  let effectiveParams = params;
692
603
  let userEdited = false;
693
604
  if (askApproval) {
@@ -758,7 +669,6 @@ export function wrapPatchToolWithPermission(tool, cwd, getPermission, getRoots,
758
669
  [APPROVAL_GUARDED]: true,
759
670
  };
760
671
  }
761
- /** 为 bash 工具包装只读拦截。 */
762
672
  export function wrapBashToolWithPermission(tool, getPermission, getLang) {
763
673
  return {
764
674
  ...tool,