pi-web-ui 0.116.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 (529) hide show
  1. package/CHANGELOG.md +83 -3
  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 +163 -36
  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 +184 -504
  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 +203 -371
  14. package/dist/server/agent-service.js +1281 -3030
  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 +42 -114
  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 +36 -214
  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 +38 -92
  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 +142 -68
  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 +48 -9
  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 +27 -11
  69. package/dist/server/device-center/collab-tool.js +393 -27
  70. package/dist/server/device-center/connector.js +128 -48
  71. package/dist/server/device-center/delivery-authority.js +95 -0
  72. package/dist/server/device-center/delivery-subject.js +29 -0
  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 +452 -208
  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 +15 -6
  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 +46 -31
  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 +13 -15
  101. package/dist/server/device-center/hub-deliveries.js +119 -15
  102. package/dist/server/device-center/hub-integration.js +647 -334
  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 +28 -9
  107. package/dist/server/device-center/hub-setup.js +23 -7
  108. package/dist/server/device-center/hub-transaction-log.js +175 -0
  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 +946 -404
  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 +111 -0
  115. package/dist/server/device-center/local-hub.js +6 -4
  116. package/dist/server/device-center/local-publication.js +416 -0
  117. package/dist/server/device-center/local-verification-job.js +95 -0
  118. package/dist/server/device-center/local-verification.js +273 -0
  119. package/dist/server/device-center/local.js +341 -18
  120. package/dist/server/device-center/main.js +18 -2
  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 +52 -46
  125. package/dist/server/device-center/path-portal.js +42 -12
  126. package/dist/server/device-center/publication-journal.js +305 -0
  127. package/dist/server/device-center/publish-intent.js +374 -0
  128. package/dist/server/device-center/relay.js +217 -52
  129. package/dist/server/device-center/report-upload.js +0 -1
  130. package/dist/server/device-center/runtime.js +419 -52
  131. package/dist/server/device-center/store.js +223 -65
  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 +68 -0
  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 +569 -227
  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 +335 -0
  143. package/dist/server/device-center/task-state.js +0 -12
  144. package/dist/server/device-center/task-workspace.js +393 -0
  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 +9 -0
  148. package/dist/server/device-center/work-contract.js +923 -0
  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 +202 -29
  152. package/dist/server/dispatch-plugin-handlers.js +2 -19
  153. package/dist/server/dsh/dsh-agent-service.js +78 -601
  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 +199 -677
  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 +6 -45
  247. package/dist/server/patch-remote-catalog.js +4 -34
  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 +24 -61
  282. package/dist/server/preset-plugin-dependencies.js +0 -2
  283. package/dist/server/preset-share.js +4 -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 +61 -0
  295. package/dist/server/quick-ask.js +260 -0
  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 +55 -31
  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 +32 -56
  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 +215 -0
  318. package/dist/server/session-open.js +69 -0
  319. package/dist/server/session-parser.js +4 -54
  320. package/dist/server/session-scan.js +81 -45
  321. package/dist/server/session-search.js +0 -56
  322. package/dist/server/settings-service.js +19 -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 +3 -40
  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 +55 -0
  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 +98 -194
  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 +30 -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 +373 -0
  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 +55 -6
  387. package/docs/device-center.md +57 -23
  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 +9 -6
  393. package/plugin-sdk/README.md +22 -8
  394. package/plugin-sdk/client-utils.mjs +0 -7
  395. package/plugin-sdk/client.d.ts +26 -0
  396. package/plugin-sdk/client.mjs +52 -0
  397. package/plugin-sdk/import-check.mjs +4 -51
  398. package/plugin-sdk/index.d.ts +128 -117
  399. package/plugin-sdk/index.mjs +2 -687
  400. package/plugin-sdk/package.json +15 -4
  401. package/plugin-sdk/ssh-host-trust.mjs +0 -12
  402. package/plugin-sdk/testing.d.ts +9 -0
  403. package/plugin-sdk/testing.mjs +511 -0
  404. package/plugins/catalog.json +52 -4
  405. package/plugins/superagent/README.md +110 -0
  406. package/plugins/superagent/client/entry.mjs +21 -0
  407. package/plugins/superagent/index.mjs +8 -0
  408. package/plugins/superagent/main.mjs +218 -0
  409. package/plugins/superagent/manifest.json +15 -0
  410. package/plugins/superagent/server.mjs +572 -0
  411. package/plugins/superagent/style.css +167 -0
  412. package/themes/aetheris.css +1 -31
  413. package/themes/ayu-light.css +0 -1
  414. package/themes/bases/flow-base.css +2 -83
  415. package/themes/bases/obsidian-base.css +2 -37
  416. package/themes/bases/statusbar-flat-base.css +0 -1
  417. package/themes/bases/zhujian-base.css +0 -63
  418. package/themes/bases/zhupi-base.css +0 -64
  419. package/themes/catppuccin-latte.css +0 -1
  420. package/themes/catppuccin.css +0 -1
  421. package/themes/claude-code-dark.css +0 -1
  422. package/themes/codex.css +0 -1
  423. package/themes/dark-teal.css +22 -54
  424. package/themes/everforest-light.css +0 -1
  425. package/themes/flow-cristallo.css +160 -0
  426. package/themes/flow-ink.css +160 -0
  427. package/themes/flow-light.css +1 -10
  428. package/themes/flow-obsidian.css +160 -0
  429. package/themes/flow-zurich.css +160 -0
  430. package/themes/flow.css +1 -9
  431. package/themes/geist.css +0 -1
  432. package/themes/gruvbox-light.css +0 -1
  433. package/themes/kanagawa-lotus.css +0 -1
  434. package/themes/md-preview.css +1 -2
  435. package/themes/mist.css +0 -1
  436. package/themes/nord.css +0 -1
  437. package/themes/one-dark.css +0 -1
  438. package/themes/paper.css +0 -1
  439. package/themes/rose-pine-dawn.css +0 -1
  440. package/themes/sakura.css +0 -1
  441. package/themes/solarized-light.css +0 -1
  442. package/themes/tokyo-night.css +0 -1
  443. package/themes/translucent.css +4 -35
  444. package/themes/transparent.css +4 -41
  445. package/themes/vs-code-dark.css +0 -1
  446. package/themes/wallpaper-flow.css +3 -17
  447. package/themes/wallpaper-obsidian.css +1 -4
  448. package/themes/white.css +0 -1
  449. package/web/dist/.build-assets.json +1 -1
  450. package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-D-x7kA63.js} +1 -1
  451. package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
  452. package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
  453. package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
  454. package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
  455. package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CTgVLUbp.js} +1 -1
  456. package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
  457. package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
  458. package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
  459. package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
  460. package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-Da6qc566.js} +1 -1
  461. package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
  462. package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
  463. package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
  464. package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
  465. package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
  466. package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
  467. package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
  468. package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
  469. package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
  470. package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
  471. package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
  472. package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
  473. package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
  474. package/web/dist/assets/index-CQc3VrWa.css +1 -0
  475. package/web/dist/assets/index-D_AGu4Zv.js +404 -0
  476. package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
  477. package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
  478. package/web/dist/assets/theme-DGL7hLUs.js +1 -0
  479. package/web/dist/index.html +12 -11
  480. package/web/dist/sw.js +15 -61
  481. package/web/public/sw.js +14 -60
  482. package/dist/gh-comment-781.md +0 -5
  483. package/dist/server/device-center/local-page.js +0 -17
  484. package/dist/server/device-center/smoke-preview.js +0 -3
  485. package/dist/server/durable/durable-capabilities.js +0 -11
  486. package/dist/server/markers/builtins/services.js +0 -123
  487. package/dist/server/markers/builtins/todo.js +0 -189
  488. package/dist/server/markers-list-tool.js +0 -34
  489. package/dist/server/orchestrator.js +0 -109
  490. package/dist/server/patch-turn-end-boundary.js +0 -77
  491. package/dist/server/system-prompt-soul.js +0 -41
  492. package/dist/server/univer-service.js +0 -448
  493. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  494. package/dist/test-artifact.md +0 -9
  495. package/dist/test-preview-modal.md +0 -11
  496. package/dist/test-report.html +0 -20
  497. package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
  498. package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
  499. package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
  500. package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
  501. package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
  502. package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
  503. package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
  504. package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
  505. package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
  506. package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
  507. package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
  508. package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
  509. package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
  510. package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
  511. package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
  512. package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
  513. package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
  514. package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
  515. package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
  516. package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
  517. package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
  518. package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
  519. package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
  520. package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
  521. package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
  522. package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
  523. package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
  524. package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
  525. package/web/dist/assets/index-C6DwztqE.css +0 -1
  526. package/web/dist/assets/index-CuN802Sj.js +0 -93
  527. package/web/dist/assets/index-EH5Fw9fa.js +0 -93
  528. package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
  529. package/web/dist/assets/theme-D2l_mLNo.js +0 -1
@@ -1,20 +1,3 @@
1
- /**
2
- * 插件宿主设施:插件私有 KV 存储 + 加密 secrets,从 plugins.ts 抽出的纯设施。
3
- *
4
- * storage —— <pluginDir>/storage.json 单文件 JSON KV:
5
- * - 全内存缓存、写入 tmp+rename 原子落盘(同 client-state.ts 的做法);
6
- * - 供插件存非敏感配置(窗口布局、上次选中项…),替代各家手搓的
7
- * read/write config.json 样板;
8
- * - 生命周期跟插件目录绑定(uninstall 即删除),跨升级保留。
9
- *
10
- * secrets —— AES-256-GCM 加密的机密存储(密码/API key/token):
11
- * - 密钥文件 <dataDir>/secrets.key(随机 32 字节,首次生成;chmod 0600 仅对
12
- * POSIX 有意义,Windows 上 NTFS 权限继承用户目录默认 ACL);
13
- * - 密文文件随插件目录 <pluginDir>/secrets.bin——拷到别的机器因无密钥解不开
14
- * (fail closed);卸载插件即连密文一起删除;
15
- * - 威胁模型:防「 casually 复制/查看文件」(混淆级保护)与「密文外泄」,
16
- * 不能防同一用户账号下的完整进程妥协——本地个人工具的合理折衷。
17
- */
18
1
  import { existsSync, readFileSync } from "node:fs";
19
2
  import { readFile as fspReadFile, readdir as fspReaddir, rm as fspRm, mkdir as fspMkdir, writeFile as fspWriteFile, appendFile as fspAppendFile, stat as fspStat, } from "node:fs/promises";
20
3
  import { dirname, join, relative, resolve } from "node:path";
@@ -22,32 +5,11 @@ import { writeAtomicSync } from "./atomic-file.js";
22
5
  import { SETTINGS_SECRETS_KEY } from "./plugin-secrets.js";
23
6
  import { createRequire } from "node:module";
24
7
  import { spawnSync } from "node:child_process";
25
- // 与 plugin-project 共用同一套 realpath 越界复核(isInsideRoot / realPathOfNearest),
26
- // 避免「同一个安全语义、两份实现」漂移。
27
8
  import { isInsideRoot, realPathOfNearest } from "./plugin-project.js";
28
- /** tmp+rename 原子写(错误由调用方隔离——插件设施的 IO 一律尽力而为)。 */
29
9
  function atomicWrite(file, data) {
30
10
  writeAtomicSync(file, data);
31
11
  }
32
- // ---------------------------------------------------------------------------
33
- // storage.json 的进程内「读-改-写」互斥
34
- // ---------------------------------------------------------------------------
35
- /** 按文件路径的 RMW 互斥链(key = resolve 后的绝对路径)。 */
36
12
  const rmwChains = new Map();
37
- /**
38
- * 进程内「读-改-写」互斥(按文件路径的 promise 链锁)。
39
- *
40
- * storage.json 有两个读-改-写者:PluginStorage(插件 KV)与宿主 settings 面板的
41
- * saveSettingsValues(plugins.ts,直写同一文件的 settings 键)。两段 RMW 必须互斥
42
- * —— 现在两段关键区都是同步的(单线程下本就不会交错),但只要将来任何一处把
43
- * 「读」和「写」之间插进 await,就会退回「旧快照整份回写、抹掉对方刚写的键」的
44
- * 丢更新。两处统一收进这把锁:
45
- * - 空链 + 同步 fn:原地直跑(不引入微任务延迟,set() 后同步 get() 立即可见,
46
- * 语义与未加锁完全一致);fn 若返回 promise(异步写者)则占住链尾,后续排队;
47
- * - 链忙:挂到链尾串行(前一个成功/失败都放行下一个)。
48
- * 每个链尾完成后仅在仍是当前尾部时清理,避免删掉后续排队任务的锁。
49
- */
50
- /** Synchronous settings commits cannot report success while queued behind an async writer. */
51
13
  export function withFileRmwLockSync(file, fn) {
52
14
  if (rmwChains.has(resolve(file)))
53
15
  throw new Error("Plugin storage is busy; retry settings save");
@@ -65,20 +27,13 @@ export function withFileRmwLock(file, fn) {
65
27
  rmwChains.delete(key);
66
28
  });
67
29
  rmwChains.set(key, tail);
68
- // Return after cleanup, preserving the caller's result or rejection.
69
30
  return tail.then(() => result);
70
31
  }
71
32
  return result;
72
33
  }
73
- // ---------------------------------------------------------------------------
74
- // storage
75
- // ---------------------------------------------------------------------------
76
- /** 每插件的同步 JSON KV。读写都重读权威文件,拒绝损坏/不可读文件;
77
- * 写入使用独立候选,原子提交成功后才发布缓存。同步 API 遇异步写锁占用直接抛错。 */
78
34
  export class PluginStorage {
79
35
  file;
80
36
  cache;
81
- /** Only ENOENT means an empty store; unreadable or malformed data must never be overwritten. */
82
37
  constructor(file) {
83
38
  this.file = file;
84
39
  }
@@ -98,7 +53,6 @@ export class PluginStorage {
98
53
  return parsed;
99
54
  }
100
55
  load() {
101
- // Re-read to observe settings commits even when filesystem timestamps are unchanged.
102
56
  const committed = this.readFromDisk();
103
57
  this.cache = committed;
104
58
  return this.cache;
@@ -157,19 +111,8 @@ export class PluginStorage {
157
111
  });
158
112
  }
159
113
  }
160
- // ---------------------------------------------------------------------------
161
- // secrets
162
- // ---------------------------------------------------------------------------
163
114
  export { PluginSecrets } from "./plugin-secrets.js";
164
- // ---------------------------------------------------------------------------
165
- // deps(宿主代插件自动补装运行时依赖)
166
- // ---------------------------------------------------------------------------
167
- const DEP_TIMEOUT_MS = 180_000; // 慢网安装兜底(含第一次拉取包元数据)
168
- /** spec(`name` / `name@range` / `@scope/name@range`)→ 裸包名。
169
- * require.resolve 不认 `@版本号` 后缀(`foo@1.2.3` 会被当成字面目录名,
170
- * 恒判缺失 → 带版本 pin 的 ensureDeps 永远装完还报缺,voice-input 踩过)。
171
- * 非标准形状(URL / 本地路径 / tag)原样返回,resolve 失败即判缺失,行为不变。
172
- * 纯函数,单测覆盖。 */
115
+ const DEP_TIMEOUT_MS = 180_000;
173
116
  export function depName(spec) {
174
117
  const m = /^(?:(@[^/\s]+\/[^/\s@]+)|([^/\s@:.]+))(?:@[^/\s]*)?$/.exec(str(spec));
175
118
  if (!m)
@@ -179,12 +122,9 @@ export function depName(spec) {
179
122
  function str(v) {
180
123
  return typeof v === "string" ? v.trim() : "";
181
124
  }
182
- /** 纯包名(`foo` / `@scope/foo`):能按 `node_modules/<name>/package.json` 判盘。
183
- * `node:path`、URL、相对/绝对路径、git spec 一律 false(交给 resolve 判)。 */
184
125
  function isPlainPackageName(name) {
185
126
  return /^(?:@[a-z\d](?:[a-z\d._-]*[a-z\d])?\/)?[a-z\d](?:[a-z\d._-]*[a-z\d])?$/i.test(name);
186
127
  }
187
- /** 从 fromDir 沿目录树向上找 `node_modules/<name>/package.json` 是否已落盘。 */
188
128
  function depOnDisk(fromDir, name) {
189
129
  let dir = fromDir;
190
130
  for (;;) {
@@ -192,26 +132,13 @@ function depOnDisk(fromDir, name) {
192
132
  if (existsSync(join(dir, "node_modules", ...name.split("/"), "package.json")))
193
133
  return true;
194
134
  }
195
- catch {
196
- /* 权限/坏路径:当作这一层没有,继续往上找 */
197
- }
135
+ catch { }
198
136
  const up = dirname(dir);
199
137
  if (!up || up === dir)
200
138
  return false;
201
139
  dir = up;
202
140
  }
203
141
  }
204
- /** 从插件目录出发能否解析到这个模块(模拟插件自身 import() 的查找链)。
205
- *
206
- * resolve 失败后再看一眼「文件是否已落盘」,这不是冗余判据而是**修 bug**(issue #383):
207
- * Node 的 CJS 解析会把 `node_modules/<pkg>/package.json` 不存在的**负结果**缓存在
208
- * 进程内存里(packageJsonReader 的路径缓存)。于是「探测缺失 → npm install 成功 →
209
- * 复查」这组三连里,最后一次复查永远命中那条负缓存,恒抛
210
- * `Cannot find module`,用户看到的是「装成功了却报 npm install 没跑通」,
211
- * 且非重启整个进程不能恢复。落盘判据不碰 CJS 缓存,天然免疫。
212
- *
213
- * 顺序保持「先 resolve 后判盘」:解析成功仍然是最强的信号(含 exports 映射等
214
- * 盘上判据覆盖不到的形状),判盘只是给解析的假阴性兜底,不会放宽真缺失。 */
215
142
  export function isDepAvailable(pluginDir, spec) {
216
143
  const name = depName(spec);
217
144
  try {
@@ -223,11 +150,6 @@ export function isDepAvailable(pluginDir, spec) {
223
150
  }
224
151
  }
225
152
  const depInstallLocks = new Map();
226
- /** 确保依赖就绪:先逐个解析,缺了才一次性 `npm install` 补装,装完复查。
227
- * 返回 true = 全部可用;false = 安装失败或超时。同目录并发调用单飞合并。
228
- *
229
- * 这是 webmail / db-client / vscode-editor 三家手搓 ensureXxxMod 的上收——
230
- * 之前每家都自己拼 spawn 参数、自己处理 win32 的 npm.cmd、自己等 install 完成。 */
231
153
  export function ensurePluginDeps(pluginDir, specs, onProgress) {
232
154
  if (specs.length === 0)
233
155
  return Promise.resolve(true);
@@ -239,8 +161,6 @@ export function ensurePluginDeps(pluginDir, specs, onProgress) {
239
161
  if (inflight)
240
162
  return inflight;
241
163
  const run = async () => {
242
- // 无 package.json 时 npm 会沿目录树向上找最近一个,可能把依赖装进父目录——
243
- // 先落一个最小 package.json 钉住安装位置。
244
164
  if (!existsSync(join(pluginDir, "package.json"))) {
245
165
  try {
246
166
  atomicWrite(join(pluginDir, "package.json"), JSON.stringify({ name: "plugin-runtime-deps", private: true }, null, 2));
@@ -248,8 +168,6 @@ export function ensurePluginDeps(pluginDir, specs, onProgress) {
248
168
  catch { }
249
169
  }
250
170
  onProgress?.(`正在安装依赖:${missing.join(", ")}…(首次约需几分钟)`);
251
- // win32 的 npm 是 .cmd——spawnSync 直接跑会被 EINVAL 拒绝;走 cmd.exe /d /s /c
252
- // 规避 DEP0190 与命令行注入,posix 不用 shell(路径不含空格假设成立,与宿主其它 spawn 一致)。
253
171
  const isWin = process.platform === "win32";
254
172
  const spawnCmd = isWin ? process.env.ComSpec || "cmd.exe" : "npm";
255
173
  const runNpmInstall = (extraFlags) => {
@@ -264,9 +182,6 @@ export function ensurePluginDeps(pluginDir, specs, onProgress) {
264
182
  });
265
183
  };
266
184
  let res = runNpmInstall([]);
267
- // 传递依赖(如 @xenova/transformers 拉进来的 sharp@0.32)在无编译环境或连不上
268
- // GitHub Release 拉 libvips 时,install 脚本会以非 0 退出拖垮整轮安装;
269
- // 用 --ignore-scripts 重试一次,让预打包二进制(如 onnxruntime-node)与纯 JS 包先落盘。
270
185
  if (res.error || res.status !== 0) {
271
186
  res = runNpmInstall(["--ignore-scripts"]);
272
187
  }
@@ -286,11 +201,8 @@ export function ensurePluginDeps(pluginDir, specs, onProgress) {
286
201
  depInstallLocks.set(lockKey, p);
287
202
  return p;
288
203
  }
289
- /** 深度/条数护栏:glob 递归遍历与结果都封顶,防大仓库扫爆内存。 */
290
204
  const GLOB_MAX_WALK = 2000;
291
205
  const GLOB_MAX_RESULTS = 500;
292
- /** 极简 glob 转 RegExp:只支持 `*`(单段任意)/`?`(单字符)/`**`(跨段任意)。
293
- * 纯函数,单测覆盖。 */
294
206
  export function globToRegExp(pattern) {
295
207
  const src = String(pattern ?? "")
296
208
  .trim()
@@ -300,7 +212,6 @@ export function globToRegExp(pattern) {
300
212
  const c = src[i];
301
213
  if (c === "*") {
302
214
  if (src[i + 1] === "*") {
303
- // `**`:跨段;`/**/` 整体可省(根下也命中)。
304
215
  if (src[i + 2] === "/") {
305
216
  re += "(?:.*/)?";
306
217
  i += 2;
@@ -325,11 +236,9 @@ export function globToRegExp(pattern) {
325
236
  }
326
237
  export class WorkspaceFS {
327
238
  root;
328
- /** root 是活值 getter(返回当前工作区绝对路径),跟随 set_cwd。 */
329
239
  constructor(root) {
330
240
  this.root = root;
331
241
  }
332
- /** 相对路径 → 活根下的绝对路径;越界抛错。空串 = 根本身。 */
333
242
  abs(rel) {
334
243
  const rootDir = resolve(this.root());
335
244
  const target = resolve(rootDir, typeof rel === "string" ? rel : "");
@@ -338,15 +247,8 @@ export class WorkspaceFS {
338
247
  }
339
248
  return target;
340
249
  }
341
- /**
342
- * 写类操作(write/append/mkdir/remove)的 realpath 复核:abs() 是纯字符串
343
- * 比较,工作区里的符号链接/junction 能把写入(或递归删除)引到工作区之外。
344
- * 取目标最近已存在祖先的 realpath,复核它仍在「活根」的 realpath 内。
345
- * 读/list/stat/glob 保持字符串校验(高频路径;读不存在「把内容写到别处」
346
- * 的风险,性能优先 —— 有意的取舍)。
347
- */
348
250
  assertRealInsideRoot(rel) {
349
- const target = this.abs(rel); // 字符串越界先拒绝(错误文案不变)
251
+ const target = this.abs(rel);
350
252
  const targetReal = realPathOfNearest(target);
351
253
  if (!targetReal)
352
254
  throw new Error(`路径越界:无法解析真实路径 ${String(rel)}`);
@@ -356,7 +258,6 @@ export class WorkspaceFS {
356
258
  throw new Error(`路径越界(符号链接指向工作区之外):${String(rel)}`);
357
259
  }
358
260
  }
359
- /** 单层目录列表(浅层;深度遍历请插件自行递归)。 */
360
261
  async list(relDir = "") {
361
262
  try {
362
263
  const dirents = await fspReaddir(this.abs(relDir), { withFileTypes: true });
@@ -368,36 +269,29 @@ export class WorkspaceFS {
368
269
  throw new Error(`读取目录失败:${err.message}`);
369
270
  }
370
271
  }
371
- /** 读文件(二进制)。声明为 async:路径校验失败以 rejected promise 表达
372
- * (非 async 版本会同步 throw,破坏调用方 .catch/.rejects 契约)。 */
373
272
  async read(relPath) {
374
273
  return fspReadFile(this.abs(relPath));
375
274
  }
376
- /** 读文本(默认上限 512KB,超出截断——预览同款约定)。 */
377
275
  async readText(relPath, maxBytes = 512 * 1024) {
378
276
  const buf = await this.read(relPath);
379
277
  return buf.subarray(0, maxBytes).toString("utf8");
380
278
  }
381
- /** 写文件(自动补父目录;注意相对路径锚定当前项目——切换 cwd 后写进新项目)。 */
382
279
  async write(relPath, data) {
383
280
  this.assertRealInsideRoot(relPath);
384
281
  const target = this.abs(relPath);
385
282
  await fspMkdir(dirname(target), { recursive: true });
386
283
  await fspWriteFile(target, data);
387
284
  }
388
- /** 追加写文件(日志/队列场景;父目录自动补;越界拒绝与 write 同口径)。 */
389
285
  async append(relPath, data) {
390
286
  this.assertRealInsideRoot(relPath);
391
287
  const target = this.abs(relPath);
392
288
  await fspMkdir(dirname(target), { recursive: true });
393
289
  await fspAppendFile(target, data);
394
290
  }
395
- /** 建目录(递归;已存在幂等成功;越界拒绝与 write 同口径)。 */
396
291
  async mkdir(relDir) {
397
292
  this.assertRealInsideRoot(relDir);
398
293
  await fspMkdir(this.abs(relDir), { recursive: true });
399
294
  }
400
- /** 文件元信息(size/mtime 供同步/缓存判断;不存在抛错)。 */
401
295
  async stat(relPath) {
402
296
  const target = this.abs(relPath);
403
297
  const st = await fspStat(target);
@@ -412,9 +306,6 @@ export class WorkspaceFS {
412
306
  mtime: Number(st.mtimeMs) || 0,
413
307
  };
414
308
  }
415
- /** 极简 glob 搜索(星号匹配如 `*.json`、双星匹配如 `foo/bar.md` 的父目录任意层):
416
- * 相对路径(`/` 分隔)按 pattern 过滤。walk 与结果双封顶,目录本身也参与
417
- * 匹配(`docs*` 能命中目录)。只返回相对路径字符串,调用方再 read/stat。 */
418
309
  async glob(pattern, relDir = "") {
419
310
  const pat = String(pattern ?? "")
420
311
  .trim()
@@ -433,7 +324,7 @@ export class WorkspaceFS {
433
324
  ents = await fspReaddir(dir, { withFileTypes: true });
434
325
  }
435
326
  catch {
436
- continue; // 无权限/中途删除:跳过该分支,不整单失败
327
+ continue;
437
328
  }
438
329
  for (const e of ents) {
439
330
  if (walked++ >= GLOB_MAX_WALK || out.length >= GLOB_MAX_RESULTS)
@@ -452,9 +343,7 @@ export class WorkspaceFS {
452
343
  }
453
344
  return out;
454
345
  }
455
- /** 删除文件/目录(递归;只允许删工作区内的路径)。 */
456
346
  async remove(relPath) {
457
- // remove 同样做 realpath 复核:递归删除跟着目录链接走,比写文件更危险。
458
347
  this.assertRealInsideRoot(relPath);
459
348
  await fspRm(this.abs(relPath), { recursive: true, force: false });
460
349
  }
@@ -1,47 +1,7 @@
1
- /**
2
- * plugin-grants —— 插件目录授权表(issue #146)。
3
- *
4
- * 插件服务端跑的是全权 Node 代码,宿主只能在「自己提供的 API」上做闸门
5
- * (见 server/plugins.ts 的 registerAgentTool / route / host.fs)。当插件要碰
6
- * **工作区之外**的目录时,宿主弹确认框问用户;用户同意后可以选「记住」——
7
- * 记住的东西就落在这个文件里:`<dataDir>/plugin-grants.json`
8
- * (`{ grants: { <pluginId>: [绝对目录…] } }`),设置面板可随时撤销。
9
- *
10
- * 为什么单独一个文件而不是塞进 client-state.json:授权是**安全语义**的持久化
11
- * 状态,与 UI 偏好/最近项目是两回事 —— 用户清 UI 状态、迁移设置预设时不该
12
- * 连带丢(或带上)一份授权;文件独立后也能被运维一眼看懂、手改、审计。
13
- *
14
- * 三条设计取舍(都有意为之,改动前请先读):
15
- *
16
- * 1. **父目录授权覆盖子目录**:`has()` 命中目录本身或其任一祖先。
17
- * 理由:目录授权天然是「子树授权」—— 用户批准 `/proj` 时的心理模型就是
18
- * 「这个项目目录随你用」,若还要求逐个 `/proj/src`、`/proj/docs` 再弹十次
19
- * 确认,用户只会一路盲点「同意」,闸门形同虚设(安全上反而更糟)。反之
20
- * **不成立**:只授权了 `/proj/a` 时访问 `/proj` 必须再问 —— 祖先目录里
21
- * 还躺着用户没打算交出去的东西。判定按路径分段边界做(`/proj` 不覆盖
22
- * `/project`),不做字符串前缀匹配。
23
- *
24
- * 2. **坏文件不覆盖**:读失败 / JSON 坏 / 形状不对一律当作空表(绝不抛给调用方,
25
- * 也绝不在读路径上回写)。因为「读不出来」与「确实是空的」在故障态下无法
26
- * 区分,若读失败就写一份空表回去,等于用一次磁盘抖动**静默清空用户全部授权**
27
- * (或更糟:把手工修了一半的文件冲掉)。只有真正发生变更的写操作
28
- * (grant / revoke 命中)才重写文件,此时以内存里的净化为准。
29
- *
30
- * 3. **文件 I/O 全部 best-effort**:磁盘错误不能让 server 崩(与
31
- * server/client-state.ts 同风格)。写失败 = 这次授权没落盘,下次再问用户;
32
- * 内存态仍然生效,本次会话可用。
33
- *
34
- * 路径归一:一律 `resolve()` 成绝对路径再存;相对路径直接拒绝(相对谁是个隐藏
35
- * 上下文,落盘后换个 cwd 就读出另一个目录,等于埋雷)。win32 上比较时忽略大小写
36
- * 与尾部分隔符(Windows 文件系统不区分大小写),但**存储保持用户写入时的形式**
37
- * (不 lowerCase),否则设置面板里 `C:\Users\Foo` 会显示成 `c:\users\foo`。
38
- */
39
1
  import { readFileSync } from "node:fs";
40
2
  import { isAbsolute, resolve, sep } from "node:path";
41
3
  import { writeJsonAtomicSync } from "./atomic-file.js";
42
- /** 合法插件 id(与 server/plugins.ts 的 ID_RE 一致,防路径穿越)。 */
43
4
  const ID_RE = /^[A-Za-z0-9_-]+$/;
44
- /** 去掉尾部分隔符(保留根:「C:\」/「/」不能退化)。 */
45
5
  function stripTrailingSep(p) {
46
6
  let out = p;
47
7
  for (;;) {
@@ -51,28 +11,21 @@ function stripTrailingSep(p) {
51
11
  if (last !== "/" && last !== "\\")
52
12
  return out;
53
13
  const trimmed = out.slice(0, -1);
54
- // 「C:\」→「C:」在 win32 上语义完全不同(后者是「C 盘当前目录」),不能削。
55
14
  if (/^[A-Za-z]:$/.test(trimmed))
56
15
  return out;
57
16
  out = trimmed;
58
17
  }
59
18
  }
60
- /** 比较用键:win32 折大小写(文件系统不区分大小写);尾部分隔符统一去掉
61
- * (`C:\a\` 与 `C:\a` 是同一目录,手改文件很容易多写一个斜杠)。 */
62
19
  function pathKey(p) {
63
20
  const s = stripTrailingSep(p);
64
21
  return process.platform === "win32" ? s.toLowerCase() : s;
65
22
  }
66
- /** 路径归一:绝对化 + 去尾分隔符;非法(空 / 非字符串 / 含 NUL / 相对 / 盘符怪)→ null。
67
- * 存储的也是这个形式(用户写入形式的绝对化版本)。 */
68
23
  export function normalizeGrantPath(p) {
69
24
  if (typeof p !== "string")
70
25
  return null;
71
26
  const raw = p.trim();
72
27
  if (!raw || raw.includes("\0"))
73
28
  return null;
74
- // 相对路径一律拒绝:授权必须是「明确的绝对目录」,不做 cwd 相对解析。
75
- // 顺带干掉 win32 上的怪盘符形式("C:relative"、"1:\x" 都是 isAbsolute=false)。
76
29
  if (!isAbsolute(raw))
77
30
  return null;
78
31
  let abs;
@@ -86,20 +39,15 @@ export function normalizeGrantPath(p) {
86
39
  return null;
87
40
  return stripTrailingSep(abs);
88
41
  }
89
- /** target 是否落在 ancestor 自身或它的子树上(按分段边界,不做裸前缀匹配:
90
- * `/proj` 不能覆盖 `/project`)。两边都须是 pathKey() 归一后的形式。 */
91
42
  function isSameOrInside(targetKey, ancestorKey) {
92
43
  if (targetKey === ancestorKey)
93
44
  return true;
94
45
  const prefix = ancestorKey.endsWith(sep) ? ancestorKey : ancestorKey + sep;
95
46
  return targetKey.startsWith(prefix);
96
47
  }
97
- /** 原子写:临时文件 + rename。 */
98
48
  function atomicWriteJson(filePath, data) {
99
49
  writeJsonAtomicSync(filePath, data);
100
50
  }
101
- /** 读文件并净化为内存表:任何异常(不存在 / 权限 / JSON 坏 / 形状不对)→ 空表。
102
- * 条目逐个过 normalizeGrantPath(顺手兼容手工写入的相对路径、重复项、坏 id)。 */
103
51
  function readGrantsFile(filePath) {
104
52
  let raw;
105
53
  try {
@@ -134,19 +82,12 @@ function readGrantsFile(filePath) {
134
82
  }
135
83
  return out;
136
84
  }
137
- /**
138
- * 插件目录授权表。全局共享(不是 per-client):授权是「这台机器上的这套插件
139
- * 配置允许它访问哪些目录」,任何浏览器/标签页看到的都该是同一份。
140
- */
141
85
  export class PluginGrantsStore {
142
86
  dataDir;
143
- /** 内存缓存 = 上次读盘结果(含净化)。null = 尚未读 / 已被 invalidate。 */
144
87
  cache = null;
145
- /** @param dataDir 数据目录;授权文件固定为 `<dataDir>/plugin-grants.json`。 */
146
88
  constructor(dataDir) {
147
89
  this.dataDir = dataDir;
148
90
  }
149
- /** 授权文件路径(测试 / 排障 / 审计用)。 */
150
91
  get filePath() {
151
92
  return resolve(this.dataDir, "plugin-grants.json");
152
93
  }
@@ -155,34 +96,23 @@ export class PluginGrantsStore {
155
96
  this.cache = readGrantsFile(this.filePath);
156
97
  return this.cache;
157
98
  }
158
- /** 落盘(best-effort):失败只丢持久化,不影响本次会话的内存态。 */
159
99
  save() {
160
100
  try {
161
101
  atomicWriteJson(this.filePath, { grants: this.load() });
162
102
  }
163
- catch {
164
- // best effort —— 磁盘故障不能弄崩 server
165
- }
103
+ catch { }
166
104
  }
167
- /** 全部授权,按插件聚合(设置面板展示用;路径保持写入时的形式)。
168
- * 按 pluginId 排序,保证界面顺序稳定(与本文件里的插入顺序无关)。 */
169
105
  list() {
170
106
  const all = this.load();
171
107
  return Object.keys(all)
172
108
  .sort()
173
109
  .map((pluginId) => ({ pluginId, paths: [...all[pluginId]] }));
174
110
  }
175
- /** 单个插件的授权目录(副本;不存在或 id 非法 → 空数组)。 */
176
111
  get(pluginId) {
177
112
  if (!ID_RE.test(pluginId))
178
113
  return [];
179
114
  return [...(this.load()[pluginId] ?? [])];
180
115
  }
181
- /**
182
- * 是否已授权:命中目录本身,**或它的任一祖先目录已被授权**(见文件头取舍 1)。
183
- * 纯字符串判定,不碰磁盘(目录可能还不存在,也可能已被删 —— 授权表是
184
- * 「用户批准过」,不是「磁盘现状」)。
185
- */
186
116
  has(pluginId, dir) {
187
117
  if (!ID_RE.test(pluginId))
188
118
  return false;
@@ -199,14 +129,6 @@ export class PluginGrantsStore {
199
129
  }
200
130
  return false;
201
131
  }
202
- /**
203
- * 记一条授权(幂等:同一目录不重复)。返回是否**新增**。
204
- *
205
- * 幂等按归一后的同一目录判(win32 大小写 / 尾部分隔符等价形式算同一个)。
206
- * 注意:父目录已授权时再显式 grant 子目录仍然会记下(返回 true)——
207
- * 授权表是「用户知情过什么」的记录,显式批准过的子目录值得留痕,之后撤销
208
- * 父目录时它不会莫名其妙一起消失(has 侧照样被父目录短路,不产生额外询问)。
209
- */
210
132
  grant(pluginId, dir) {
211
133
  if (!ID_RE.test(pluginId))
212
134
  return false;
@@ -222,20 +144,11 @@ export class PluginGrantsStore {
222
144
  this.save();
223
145
  return true;
224
146
  }
225
- /**
226
- * 撤销授权,三种粒度,返回删除的条数:
227
- * - `revoke()` 清空整张表
228
- * - `revoke(pluginId)` 清掉该插件全部
229
- * - `revoke(pluginId, dir)` 只清该目录(按归一后的同一目录精确匹配,
230
- * 不连带删除它下面的授权条目)
231
- * 只给 dir 不给 pluginId 是非法用法(不知道删谁的)→ 0,不动表。
232
- * 无变化时**不写盘**:坏文件/空表不该被一次空撤销顺手覆盖(见取舍 2)。
233
- */
234
147
  revoke(pluginId, dir) {
235
148
  const all = this.load();
236
149
  if (pluginId === undefined) {
237
150
  if (dir !== undefined)
238
- return 0; // 非法用法:只给目录无法定位插件
151
+ return 0;
239
152
  let total = 0;
240
153
  for (const list of Object.values(all))
241
154
  total += list.length;
@@ -271,7 +184,6 @@ export class PluginGrantsStore {
271
184
  this.save();
272
185
  return removed;
273
186
  }
274
- /** 磁盘文件变化(多进程 / 用户手改)后重读:丢缓存,下次访问重新读盘。 */
275
187
  reload() {
276
188
  this.cache = null;
277
189
  }
@@ -1,48 +1,23 @@
1
- /**
2
- * plugin-install-spec — 「安装前先读 spec」(DSH 对照清单 P0-3 / 引导式安装)。
3
- *
4
- * 背景:设置面板「添加到列表 / 从市场安装」原样把用户填的来源交给 CLI。打错字、
5
- * 已装过、根本不是插件包,全都要等 pnpm/git 跑完、用户在输出里自己找原因。
6
- * 这里在**动 CLI 之前**先做一次可解释的检查,把失败归到七种 problem 之一,
7
- * 每种都给一句人话 +(能给的)修复建议。
8
- *
9
- * 纪律:
10
- * - 本模块**不联网、不写盘**(纯分类 + 本地文件系统探测);真正的远端探测
11
- * (raw.githubusercontent 读 manifest.json)在 installer 的 inspect 里做,
12
- * 这样本文件可以离线单测、也可以被前端复用同一套文案 key。
13
- * - 分类结果只是**建议**,不是硬门禁:installer 仍会在真正安装前再校验一次,
14
- * 未知/疑似可用一律放行(宁可让 CLI 说话,也不要因为探测失败把能装的挡掉)。
15
- */
16
1
  import { existsSync, readFileSync, statSync } from "node:fs";
17
2
  import { isAbsolute, join } from "node:path";
18
3
  import { isValidSource } from "./plugin-catalog.js";
19
- /** npm 包名形状(宽松):可带 @scope/ 前缀与 @version 后缀;不含 `/` 之外的路径段。 */
20
4
  const NPM_RE = /^(?:@[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?\/)?[a-z0-9](?:[a-z0-9._-]*[a-z0-9])?(?:@[^\s/]+)?$/i;
21
- /**
22
- * 解析并按形状分类一个安装来源。纯函数、不碰网络与磁盘(除 `path` 分支的
23
- * 存在性判断——那是刻意让「本机路径 vs 形状不对」可区分)。
24
- */
25
5
  export function parseInstallSpec(rawSpec) {
26
6
  const raw = String(rawSpec ?? "").trim();
27
7
  if (!raw)
28
8
  return { kind: "invalid", normalized: "" };
29
- // 1) 本机路径:绝对路径、file:// 前缀、或当前存在的相对目录(CLI 自己的判据)。
30
9
  const localCandidate = raw.replace(/^file:\/\//i, "");
31
10
  if (isAbsolute(localCandidate) || safeExists(localCandidate))
32
11
  return { kind: "path", normalized: localCandidate };
33
- // 2) 完整 URL(git 仓库 / 目录文档)。
34
12
  if (/^https?:\/\//i.test(raw)) {
35
- // GitHub 的网页 URL 仍归 github(能拿 owner/repo/ref/subpath,可做远端探测)。
36
13
  const gh = parseGithubUrl(raw);
37
14
  if (gh)
38
15
  return gh;
39
16
  return { kind: "url", normalized: raw };
40
17
  }
41
- // 3) GitHub 的 owner/repo[/sub][#ref] 简写。
42
18
  const short = parseGithubShort(raw);
43
19
  if (short)
44
20
  return short;
45
- // 4) npm 包名。
46
21
  if (NPM_RE.test(raw))
47
22
  return { kind: "npm", normalized: raw };
48
23
  return { kind: "invalid", normalized: raw };
@@ -52,11 +27,9 @@ function safeExists(p) {
52
27
  return existsSync(p);
53
28
  }
54
29
  catch {
55
- // 非法路径字符(Windows 上的 `<` `>` 等)→ 当不存在。
56
30
  return false;
57
31
  }
58
32
  }
59
- /** 解析 https://github.com/owner/repo[/tree/<ref>[/<sub>]] 或 `owner/repo` 简写。 */
60
33
  function parseGithubUrl(raw) {
61
34
  const m = raw.match(/^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/#?]+)(?:\/(?:tree|blob)\/([^/]+)((?:\/[^#?]+)*))?/i);
62
35
  if (!m)
@@ -77,10 +50,7 @@ function parseGithubUrl(raw) {
77
50
  ...(subpath ? { subpath } : {}),
78
51
  };
79
52
  }
80
- /** 解析 owner/repo[/sub][#ref](cli 与 marketplace 的主写法)。 */
81
53
  function parseGithubShort(raw) {
82
- // 带 @ 前缀 = npm scope(@scope/pkg),GitHub 的 owner 不允许 @ —— 先摘出去,
83
- // 免得 `@scope/pkg` 被当成 owner=`@scope` 的仓库(分类错会让 UI 给错建议)。
84
54
  if (raw.startsWith("@"))
85
55
  return null;
86
56
  const hash = raw.indexOf("#");
@@ -92,7 +62,6 @@ function parseGithubShort(raw) {
92
62
  const [owner, repo, ...rest] = segs;
93
63
  if (!owner || !repo)
94
64
  return null;
95
- // URL 的 tree/blob 写法也可简写过来(owner/repo/tree/<ref>/<sub>)。
96
65
  let subpath = rest.join("/");
97
66
  let effectiveRef = ref;
98
67
  if (rest[0] === "tree" || rest[0] === "blob") {
@@ -108,9 +77,7 @@ function parseGithubShort(raw) {
108
77
  ...(subpath ? { subpath } : {}),
109
78
  };
110
79
  }
111
- /** 粗略的 id 字符集(与 server/plugins.ts 的 ID_RE 一致)。 */
112
80
  const ID_RE = /^[A-Za-z0-9_-]+$/;
113
- /** 由来源推导落盘 id(与 CLI / plugin-catalog 同规则:子目录末段 > 仓库名 > 末段)。 */
114
81
  export function suggestPluginId(spec, explicit) {
115
82
  if (explicit && ID_RE.test(explicit))
116
83
  return explicit;
@@ -127,10 +94,6 @@ function lastSegment(s) {
127
94
  const segs = body.split("/").filter(Boolean);
128
95
  return segs[segs.length - 1] ?? "";
129
96
  }
130
- /**
131
- * 本地检查:形状分类 + 已装判定。**不联网** —— 远端 manifest 探测由 installer
132
- * 的 `inspectRemote()` 补上(本函数是它的第一步,也可单独用于「添加到列表」)。
133
- */
134
97
  export function inspectLocalInstallSpec(rawSpec, deps) {
135
98
  const spec = parseInstallSpec(rawSpec);
136
99
  const suggestedId = suggestPluginId(spec, deps.explicitId);
@@ -152,7 +115,6 @@ export function inspectLocalInstallSpec(rawSpec, deps) {
152
115
  };
153
116
  return base;
154
117
  }
155
- /** 读本地目录里的 manifest.json(本地路径源用;失败返回 null,不抛)。 */
156
118
  export function readLocalManifest(dir) {
157
119
  try {
158
120
  const p = join(dir, "manifest.json");
@@ -165,7 +127,6 @@ export function readLocalManifest(dir) {
165
127
  return null;
166
128
  }
167
129
  }
168
- /** 从任意 manifest 对象里摘出可展示字段(顺带校验它是插件)。 */
169
130
  export function pickManifestFields(raw) {
170
131
  if (!raw || typeof raw !== "object")
171
132
  return null;
@@ -183,10 +144,6 @@ export function pickManifestFields(raw) {
183
144
  ...(permissions ? { permissions } : {}),
184
145
  };
185
146
  }
186
- /**
187
- * 远端 manifest 的候选 raw URL(按 ref 有无/子目录有无各一条)。
188
- * 只用 raw.githubusercontent.com —— 与 server/locales.ts 同一取用姿势,无需 API token。
189
- */
190
147
  export function manifestCandidateUrls(spec) {
191
148
  if (spec.kind !== "github" || !spec.owner || !spec.repo)
192
149
  return [];