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,62 +1,22 @@
1
- /**
2
- * plugin-project — 插件「组装项目」的纯执行层(issue #146)。
3
- *
4
- * 插件(`plugins/<id>/`)希望能让宿主把**几个仓库 + 若干配置文件**拼成一个工作区:
5
- * 建目录、clone、写文件,可选在根目录 `git init`。本模块只做这一件事,并且假定
6
- * 「能不能在这个目录里动手」已经由上层判过 —— 授权由 `PluginGrantsStore` + 用户
7
- * 授权弹窗负责,**这里不做授权判断**,只兜住两件必须自己保证的事:
8
- *
9
- * 1. **执行**:spawn git(不走 shell)、写盘、逐行回报进度;失败即停,返回
10
- * `ok:false` + 第一个失败点的原因 + 已经走过的 log —— 绝不吞错、绝不假装成功
11
- * (插件会把日志原样展示给用户,一个半成品项目配上「成功」比直接报错更坏)。
12
- * 2. **路径越界防护**:任何相对路径(repo 的 subdir、files 的 key)resolve 之后
13
- * 都必须仍落在授权根目录 `dir` 之内。授权说的是「这个目录」,不等于它的父目录、
14
- * 也不等于它内部某个符号链接指向的对面,所以每个目标过三道:
15
- * ① 直接拒绝绝对路径(含 win32 盘符 / UNC);
16
- * ② `relative(root, abs)` 不得以 `..` 开头(win32 比较前统一小写 —— 该平台
17
- * 文件系统大小写不敏感,`E:\A` 与 `e:\a` 是同一个目录);
18
- * ③ 目标(或它最近一个已存在的祖先)的 **realpath** 仍必须在 root 的 realpath
19
- * 之内 —— 防 junction / 符号链接把写入引到目录之外。
20
- * 对用户给的路径不做任何「顺手规整」(trim / 归一):看不懂就直接拒绝。
21
- *
22
- * 校验全部在**动磁盘之前**做完(纯函数阶段):一个永远不可能成功的规格不应该先
23
- * 建出一半目录、clone 半个仓库再报错。
24
- */
25
1
  import { spawn } from "node:child_process";
26
2
  import { existsSync, mkdirSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
27
3
  import { readdir as fspReaddir } from "node:fs/promises";
28
4
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
29
5
  import { StringDecoder } from "node:string_decoder";
30
6
  import { killPidTree } from "./process-utils.js";
31
- /** 单条 git 命令的默认墙钟上限:大仓库 clone 可能很慢,给足 5 分钟。 */
32
7
  const DEFAULT_GIT_TIMEOUT_MS = 5 * 60_000;
33
- /** 单个文件内容上限(1MB)。 */
34
8
  const MAX_FILE_BYTES = 1024 * 1024;
35
- /** files 条目数上限。 */
36
9
  const MAX_FILES = 32;
37
- /** 单行日志上限:进度条 / 超长 URL 截断后再回给 UI。 */
38
10
  const MAX_LINE_CHARS = 400;
39
- /** 日志总行数上限:clone 输出可能很多,超出后不再追加(结果里标注已截断)。 */
40
11
  const MAX_LOG_LINES = 500;
41
- /** 失败时回传的 stderr 尾部长度。 */
42
12
  const MAX_STDERR_TAIL = 1200;
43
- /** realpath 向上找「已存在祖先」的层数上限(防病态路径原地打转)。 */
44
13
  const MAX_ANCESTOR_HOPS = 64;
45
- /**
46
- * win32 比较前统一小写:该平台文件系统大小写不敏感,`E:\A` 与 `e:\a` 指同一个目录,
47
- * 只按字符串比较会把「同一个目录」误判成「在目录之外」或反之。
48
- */
49
14
  function foldCase(p) {
50
15
  return process.platform === "win32" ? p.toLowerCase() : p;
51
16
  }
52
- /** 两个绝对路径是否指向同一位置(win32 大小写不敏感)。 */
53
17
  export function samePath(a, b) {
54
18
  return foldCase(resolve(a)) === foldCase(resolve(b));
55
19
  }
56
- /**
57
- * abs 是否落在 root 之内(含 root 自身)。用 `relative()` 判定:
58
- * `""` = root 本身;以 `..` 开头 = 越界;`relative()` 回一个绝对路径 = 跨盘符。
59
- */
60
20
  export function isInsideRoot(root, abs) {
61
21
  const rel = relative(foldCase(root), foldCase(abs));
62
22
  if (rel === "")
@@ -65,10 +25,6 @@ export function isInsideRoot(root, abs) {
65
25
  return false;
66
26
  return rel !== ".." && !rel.startsWith(`..${sep}`);
67
27
  }
68
- /**
69
- * 把调用方给的**相对路径**解析到 root 内:返回绝对路径,越界/非法返回 null。
70
- * 拒绝:非字符串、空串、含 NUL、绝对路径、解析后逃出 root。
71
- */
72
28
  export function resolveInsideRoot(root, raw) {
73
29
  if (typeof raw !== "string")
74
30
  return null;
@@ -79,7 +35,6 @@ export function resolveInsideRoot(root, raw) {
79
35
  const abs = resolve(root, raw);
80
36
  return isInsideRoot(root, abs) ? abs : null;
81
37
  }
82
- /** realpath,两条实现都试(`.native` 在少数环境缺失)。 */
83
38
  function realpathOf(p) {
84
39
  try {
85
40
  return realpathSync.native(p);
@@ -88,12 +43,6 @@ function realpathOf(p) {
88
43
  return realpathSync(p);
89
44
  }
90
45
  }
91
- /**
92
- * 目标自身(存在时)或它最近一个**已存在的祖先**的真实路径;一路到盘根都解析不出来 → null。
93
- * 用途是复核符号链接:`<root>/link/file.txt` 里 link 若是指向别处的 junction,
94
- * 单看字符串它「在 root 里」,realpath 之后就露馅了。
95
- * 导出给 plugin-facilities / plugins.ts 的写类操作复用(同一套越界复核语义)。
96
- */
97
46
  export function realPathOfNearest(abs) {
98
47
  let probe = abs;
99
48
  for (let i = 0; i < MAX_ANCESTOR_HOPS; i++) {
@@ -103,21 +52,15 @@ export function realPathOfNearest(abs) {
103
52
  catch {
104
53
  const parent = dirname(probe);
105
54
  if (parent === probe)
106
- return null; // 到盘根了还不存在
55
+ return null;
107
56
  probe = parent;
108
57
  }
109
58
  }
110
59
  return null;
111
60
  }
112
- /** 相对路径统一成 `/` 分隔(wire / 日志 / 前端都用正斜杠,Windows 的 path 会回 `\`)。 */
113
61
  function toSlash(p) {
114
62
  return p.split(sep).join("/");
115
63
  }
116
- /**
117
- * 递归列目录,返回树内全部符号链接 / junction 的绝对路径。
118
- * win32 上 Dirent.isSymbolicLink() 同样覆盖 junction(lstat 语义);只读不跟随。
119
- * 目录读不了(权限/竞态删除)返回空数组 —— 兜底交给写入前的逐目标 realpath 复核。
120
- */
121
64
  async function findSymlinks(dir) {
122
65
  const out = [];
123
66
  let entries;
@@ -138,13 +81,6 @@ async function findSymlinks(dir) {
138
81
  function errMessage(err) {
139
82
  return err instanceof Error ? err.message : String(err);
140
83
  }
141
- /**
142
- * git 运行环境:服务端没有 TTY,**任何交互式认证都会永久挂死**(工具看门狗只能杀
143
- * 进程,用户体验是「卡 20 分钟然后失败」)。所以一律关掉提问通道:
144
- * GIT_TERMINAL_PROMPT 管 git 自己的用户名/密码提示,GCM_INTERACTIVE 管 Windows
145
- * 凭据管理器(它不看前者),GIT_SSH_COMMAND 的 BatchMode 管 ssh 的密码/指纹确认。
146
- * 用户自己设的 GIT_SSH_COMMAND 优先(保留自定义 key / 代理配置)。
147
- */
148
84
  function gitEnv() {
149
85
  return {
150
86
  ...process.env,
@@ -154,12 +90,10 @@ function gitEnv() {
154
90
  GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND ?? "ssh -o BatchMode=yes",
155
91
  };
156
92
  }
157
- /** 把数据流按行喂给 onLine(跨 chunk 的半行缓存在闭包里,UTF-8 用 StringDecoder 拼接)。 */
158
93
  function makeLineReader(onLine) {
159
94
  const decoder = new StringDecoder("utf8");
160
95
  let rest = "";
161
96
  const emit = (raw) => {
162
- // git 的 `\r` 进度条("Receiving objects: 45%")压成一行,避免刷屏。
163
97
  const line = raw.replace(/\r/g, " ").trimEnd();
164
98
  if (line !== "")
165
99
  onLine(line);
@@ -180,7 +114,6 @@ function makeLineReader(onLine) {
180
114
  },
181
115
  };
182
116
  }
183
- /** 跑一条 git 命令:stdout/stderr 逐行进日志,超时连坐整棵进程树。 */
184
117
  async function runGit(bin, args, opts) {
185
118
  return await new Promise((settle) => {
186
119
  let child;
@@ -188,9 +121,6 @@ async function runGit(bin, args, opts) {
188
121
  child = spawn(bin, args, {
189
122
  cwd: opts.cwd,
190
123
  env: opts.env,
191
- // spawn 用 argv 数组,不过 shell(URL/ref 里的 `; rm -rf` 无效)。
192
- // POSIX 下让它自成进程组:超时要杀的是整棵树(git 会拉起 ssh /
193
- // credential helper 子进程),killPidTree 用 -pid 干活需要这一点。
194
124
  detached: process.platform !== "win32",
195
125
  stdio: ["ignore", "pipe", "pipe"],
196
126
  windowsHide: true,
@@ -207,7 +137,6 @@ async function runGit(bin, args, opts) {
207
137
  }
208
138
  const stderrLines = [];
209
139
  const stdout = makeLineReader((line) => opts.onLine(`git: ${line}`));
210
- // stderr 同时进日志(git 的进展、远端提示全在 stderr)和失败原因尾部。
211
140
  const stderr = makeLineReader((line) => {
212
141
  stderrLines.push(line);
213
142
  opts.onLine(`git: ${line}`);
@@ -236,32 +165,23 @@ async function runGit(bin, args, opts) {
236
165
  timedOut = true;
237
166
  if (typeof child.pid === "number" && child.pid > 0) {
238
167
  void killPidTree(child.pid);
239
- // On Windows taskkill is asynchronous and a child may not emit close
240
- // promptly. Directly kill the git process too, then force settlement
241
- // after a short grace period so callers never hang on close.
242
168
  try {
243
169
  child.kill("SIGKILL");
244
170
  }
245
- catch {
246
- /* already dead */
247
- }
171
+ catch { }
248
172
  }
249
173
  else {
250
174
  try {
251
175
  child.kill("SIGKILL");
252
176
  }
253
- catch {
254
- /* already dead */
255
- }
177
+ catch { }
256
178
  }
257
179
  graceTimer = setTimeout(() => {
258
180
  try {
259
181
  child.stdout?.destroy();
260
182
  child.stderr?.destroy();
261
183
  }
262
- catch {
263
- /* already closed */
264
- }
184
+ catch { }
265
185
  finish(-1);
266
186
  }, 500);
267
187
  }, opts.timeoutMs);
@@ -273,14 +193,9 @@ async function runGit(bin, args, opts) {
273
193
  child.on("close", (code) => finish(code));
274
194
  });
275
195
  }
276
- /**
277
- * 组装项目:mkdir 子目录 → clone 仓库 → 写文件 → 可选 git init。
278
- * 失败即停(返回 ok:false + 原因 + 已完成的 log),不吞错、不假装成功。
279
- */
280
196
  export async function createProject(spec, deps = {}) {
281
197
  const log = [];
282
198
  let truncated = false;
283
- /** 每步一行:先进 log(结果里原样带回),再回调上层(转发到浏览器 / 终端)。 */
284
199
  const emit = (line) => {
285
200
  const text = line.length > MAX_LINE_CHARS ? `${line.slice(0, MAX_LINE_CHARS)}…` : line;
286
201
  if (log.length >= MAX_LOG_LINES) {
@@ -291,9 +206,7 @@ export async function createProject(spec, deps = {}) {
291
206
  try {
292
207
  deps.onProgress?.(text);
293
208
  }
294
- catch {
295
- // 进度回调是 UI 层的事:它抛错不能中断组装(更不能把项目搞成半成品)。
296
- }
209
+ catch { }
297
210
  };
298
211
  let root = typeof spec?.dir === "string" ? spec.dir : "";
299
212
  const finish = (ok, error) => {
@@ -307,8 +220,6 @@ export async function createProject(spec, deps = {}) {
307
220
  emit(`失败:${error}`);
308
221
  return finish(false, error);
309
222
  };
310
- // ——— ① 校验根目录:必须是「已存在的绝对路径」。先判 isAbsolute 再 resolve:
311
- // resolve 会拿进程 cwd 把相对路径补成绝对,那会掩盖调用方的错误。
312
223
  const rawDir = spec?.dir;
313
224
  if (typeof rawDir !== "string" || rawDir === "")
314
225
  return fail("缺少项目根目录 dir(必须是非空绝对路径)");
@@ -322,9 +233,7 @@ export async function createProject(spec, deps = {}) {
322
233
  catch {
323
234
  return fail(`项目根目录不存在:${root}(本模块不创建新的根目录)`);
324
235
  }
325
- // 真实路径:后面每个写盘目标都要拿它复核(防符号链接/junction 逃逸)。
326
236
  const rootReal = realPathOfNearest(root) ?? root;
327
- // ——— ② 校验 repos(纯计算,不碰磁盘)———
328
237
  const rawRepos = spec?.repos;
329
238
  if (rawRepos !== undefined && !Array.isArray(rawRepos))
330
239
  return fail("repos 必须是数组");
@@ -335,9 +244,6 @@ export async function createProject(spec, deps = {}) {
335
244
  const url = typeof item?.url === "string" ? item.url.trim() : "";
336
245
  if (url === "")
337
246
  return fail(`repos[${i}].url 必须是非空字符串`);
338
- // spawn 不过 shell,但 git 自己会把以 "-" 开头的实参当**选项**解析:
339
- // `--upload-pack=<cmd>` / `-c core.sshCommand=…` 这类能让远端/本地执行任意
340
- // 命令,必须挡在解析之前(argv 数组只挡得住注入 shell,挡不住选项注入)。
341
247
  if (url.startsWith("-"))
342
248
  return fail(`repos[${i}].url 不能以 "-" 开头(防 git 选项注入):${url}`);
343
249
  const rawRef = item?.ref;
@@ -363,11 +269,8 @@ export async function createProject(spec, deps = {}) {
363
269
  }
364
270
  plannedRepos.push({ url, dest, destRel, replace: item?.replace === true, ...(ref ? { ref } : {}) });
365
271
  }
366
- // ③ 真实路径复核 + replace 的边界:任何一个目标解析后跑出 root 就整单拒绝。
367
272
  for (let i = 0; i < plannedRepos.length; i++) {
368
273
  const r = plannedRepos[i];
369
- // 缺省 subdir = 直接 clone 进根目录本身:根是调用方授权的那一层,
370
- // replace 删它等于删用户自己的项目目录(不是「清空一个子目录」),拒绝。
371
274
  if (r.replace && samePath(r.dest, root)) {
372
275
  return fail(`repos[${i}]: replace 不能用于项目根目录(拒绝删除 dir 本身)`);
373
276
  }
@@ -378,7 +281,6 @@ export async function createProject(spec, deps = {}) {
378
281
  return fail(`repos[${i}].subdir 路径越界(符号链接指向 dir 之外):${r.destRel}`);
379
282
  }
380
283
  }
381
- // ——— ④ 校验 files(纯计算)———
382
284
  const rawFiles = spec?.files;
383
285
  if (rawFiles !== undefined && (rawFiles === null || typeof rawFiles !== "object" || Array.isArray(rawFiles))) {
384
286
  return fail("files 必须是「相对路径 → 文本内容」的对象");
@@ -396,15 +298,12 @@ export async function createProject(spec, deps = {}) {
396
298
  const bytes = Buffer.byteLength(content, "utf8");
397
299
  if (bytes > MAX_FILE_BYTES)
398
300
  return fail(`files["${rel}"] 超过单文件上限 1MB(${bytes} 字节)`);
399
- // 目标自身(存在时)或其最近祖先的 realpath 也要在 root 里:
400
- // 目标可能是父目录里的 junction,也可能是「指向 /etc/passwd 的文件链接」。
401
301
  const real = realPathOfNearest(abs);
402
302
  if (real === null || !isInsideRoot(rootReal, real)) {
403
303
  return fail(`files 路径越界(符号链接指向 dir 之外):${rel}`);
404
304
  }
405
305
  plannedFiles.push({ rel: toSlash(relative(root, abs)), abs, content });
406
306
  }
407
- // ——— ⑤ 执行:校验全过了才动磁盘 ———
408
307
  const gitBin = deps.gitBin && deps.gitBin.trim() !== "" ? deps.gitBin : "git";
409
308
  const timeoutMs = deps.gitTimeoutMs && deps.gitTimeoutMs > 0 ? deps.gitTimeoutMs : DEFAULT_GIT_TIMEOUT_MS;
410
309
  const env = gitEnv();
@@ -418,8 +317,6 @@ export async function createProject(spec, deps = {}) {
418
317
  return undefined;
419
318
  };
420
319
  try {
421
- // 本轮真正 clone 出的目录(根目录本身除外 —— 它是授权目录,绝不清理)与
422
- // 已写入的文件,供「clone 后置复核命中」时回滚,不把半个带毒仓库留在盘上。
423
320
  const clonedThisRun = plannedRepos.filter((r) => !samePath(r.dest, root)).map((r) => r.dest);
424
321
  const writtenThisRun = [];
425
322
  const cleanupThisRun = () => {
@@ -427,25 +324,18 @@ export async function createProject(spec, deps = {}) {
427
324
  try {
428
325
  rmSync(f, { force: true });
429
326
  }
430
- catch {
431
- /* 清理尽力而为 */
432
- }
327
+ catch { }
433
328
  }
434
329
  for (const d of clonedThisRun) {
435
330
  try {
436
331
  rmSync(d, { recursive: true, force: true });
437
332
  }
438
- catch {
439
- /* 清理尽力而为 */
440
- }
333
+ catch { }
441
334
  }
442
335
  };
443
336
  for (const r of plannedRepos) {
444
337
  const atRoot = samePath(r.dest, root);
445
- // 根目录已存在是常态(它就是那个已存在的授权目录),既不 rm 也不 mkdir ——
446
- // 交给 git 判断它是否为空目录(非空时 git 自己会报 "not an empty directory")。
447
338
  if (!atRoot && existsSync(r.dest)) {
448
- // 目标已存在:只有显式 replace 才动它 —— 绝不静默覆盖用户数据。
449
339
  if (!r.replace)
450
340
  return fail(`目标目录已存在:${r.destRel}(要覆盖请显式 replace:true)`);
451
341
  emit(`rm -rf ${r.destRel}`);
@@ -459,20 +349,12 @@ export async function createProject(spec, deps = {}) {
459
349
  const args = ["clone", "--depth", "1"];
460
350
  if (r.ref)
461
351
  args.push("--branch", r.ref);
462
- // 目标用绝对路径 + cwd=root:相对路径交给 git 会被它按自己的规则再解释一遍。
463
352
  args.push(r.url, r.dest);
464
353
  const res = await runGit(gitBin, args, { cwd: root, timeoutMs, env, onLine: emit });
465
354
  const why = gitFailReason("git clone", res);
466
355
  if (why)
467
356
  return fail(`${why}${res.stderrTail === "" ? "" : `:${res.stderrTail}`}`);
468
357
  }
469
- // ——— ⑥ clone 后置复核(写文件前):前置校验(③④)都在 clone 之前,而恶意
470
- // 仓库可以在 clone 时落地指向 root 之外的符号链接,随后的文件写入就会跟着
471
- // 链接跑出授权目录(「先 clone 后校验」的逃逸窗口)。两道防线:
472
- // a. 扫描 clone 出的目录树,出现任何符号链接即视为恶意仓库整体拒绝
473
- // (clone --depth 1 不跑包管理器,正常仓库极少提交 symlink,宁可误杀);
474
- // b. 每个写入目标写前再做一次 realPathOfNearest 复核(覆盖 a 与写盘之间的窗口)。
475
- // 任一命中:清理本轮 clone 的目录(rmSync 不跟随符号链接,安全)与已写文件。
476
358
  for (const dest of clonedThisRun) {
477
359
  const offenders = await findSymlinks(dest);
478
360
  if (offenders.length > 0) {
@@ -481,8 +363,6 @@ export async function createProject(spec, deps = {}) {
481
363
  }
482
364
  }
483
365
  for (const f of plannedFiles) {
484
- // 写前复核目标仍解析在 rootReal 内:前置校验时它还不存在(最近祖先在 root 内),
485
- // clone 之后可能被仓库塞进来的符号链接顶掉。
486
366
  const real = realPathOfNearest(f.abs);
487
367
  if (real === null || !isInsideRoot(rootReal, real)) {
488
368
  cleanupThisRun();
@@ -503,8 +383,6 @@ export async function createProject(spec, deps = {}) {
503
383
  return finish(true);
504
384
  }
505
385
  catch (err) {
506
- // 兜底:fs 层意外错误(权限、盘满、目录被并发删掉)也走 ok:false,
507
- // 不让插件看到一个抛出来的异常(它只认 ok/error/log)。
508
386
  return fail(`组装失败:${errMessage(err)}`);
509
387
  }
510
388
  }
@@ -3,28 +3,23 @@ import { lstatSync, mkdirSync, readdirSync, renameSync, rmSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  const ID_RE = /^[a-z0-9][a-z0-9_-]*$/;
5
5
  const REMOVAL_RE = /^removed-[0-9a-f-]{36}$/;
6
- /** Move out of the loader's directory before deleting: Windows may keep native addons locked. */
7
6
  export function removePlugin(dataDir, id) {
8
7
  if (!ID_RE.test(id))
9
8
  throw new Error(`Invalid plugin id: ${id}`);
10
9
  const target = join(dataDir, "plugins", id);
11
- // Check before creating a tombstone; missing installations must still fail.
12
10
  lstatSync(target);
13
11
  const trash = join(dataDir, "plugin-trash");
14
12
  mkdirSync(trash, { recursive: true });
15
13
  const removed = join(trash, `removed-${randomUUID()}`);
16
- // If renaming fails, preserve the installed tree intact and report the error.
17
14
  renameSync(target, removed);
18
15
  try {
19
16
  rmSync(removed, { recursive: true, force: true });
20
17
  return { deferred: false };
21
18
  }
22
19
  catch {
23
- // Already uninstalled. Never restore a partially deleted tree to the loader.
24
20
  return { deferred: true };
25
21
  }
26
22
  }
27
- /** Retry only our tombstones on service startup, after the previous process released its DLLs. */
28
23
  export function cleanupRemovedPlugins(dataDir) {
29
24
  const trash = join(dataDir, "plugin-trash");
30
25
  let names;
@@ -42,8 +37,6 @@ export function cleanupRemovedPlugins(dataDir) {
42
37
  try {
43
38
  rmSync(join(trash, name), { recursive: true, force: true });
44
39
  }
45
- catch {
46
- // Another process may still hold the native module; retry on the next start.
47
- }
40
+ catch { }
48
41
  }
49
42
  }
@@ -1,15 +1,3 @@
1
- /**
2
- * 插件定时任务的 cron 解析与持久化(host.schedule 的底层,server/plugins.ts 调用)。
3
- *
4
- * 两部分:
5
- * 1. 全 5 字段 cron(分 时 日 月 周):`"*"` / `"*\/n"` / `"a-b"` / `"a-b/n"` /
6
- * `"a,b,c"` / 单数字;月/周支持英文名(jan/dec 不分大小写,sun..sat,7 视作 0)。
7
- * 日-周按标准 cron OR 语义(都受限取并集,一侧 `*` 时另一侧说了算)。
8
- * 时间一律按**服务器本地时区**算(文档写死,不做 TZ 配置)。
9
- * 2. 持久记录 `<pluginDir>/schedules.json`:只存声明(spec/catchUp/label)+
10
- * 上次触发 lastRun;fn 回调永远由插件代码在 activate 里重给(重启后重建)。
11
- * 坏文件当空表(不回写,避免一次磁盘抖动清空全部定时)。
12
- */
13
1
  import { readFileSync } from "node:fs";
14
2
  import { join } from "node:path";
15
3
  import { writeJsonAtomicSync } from "./atomic-file.js";
@@ -36,7 +24,6 @@ const DOW_NAMES = {
36
24
  fri: 5,
37
25
  sat: 6,
38
26
  };
39
- /** 单字段解析 → 升序去重数组;非法回 null。纯函数,单测覆盖。 */
40
27
  export function parseCronField(raw, min, max, names) {
41
28
  const src = String(raw ?? "")
42
29
  .trim()
@@ -54,7 +41,7 @@ export function parseCronField(raw, min, max, names) {
54
41
  return null;
55
42
  let n = Number(t);
56
43
  if (n === 7 && min === 0 && max === 6)
57
- n = 0; // 周日的 7 写法
44
+ n = 0;
58
45
  if (!Number.isInteger(n) || n < min || n > max)
59
46
  return null;
60
47
  return n;
@@ -63,7 +50,6 @@ export function parseCronField(raw, min, max, names) {
63
50
  const p = part.trim();
64
51
  if (!p)
65
52
  return null;
66
- // 步长:*/n 或 a-b/n(a 缺省 min,b 缺省 max)。
67
53
  const step = p.split("/");
68
54
  if (step.length === 2) {
69
55
  const every = num(step[1]);
@@ -118,7 +104,6 @@ export function parseCronField(raw, min, max, names) {
118
104
  return null;
119
105
  return [...out].sort((a, b) => a - b);
120
106
  }
121
- /** 5 字段 cron 解析;非法回 null。纯函数,单测覆盖。 */
122
107
  export function parseCronSpec(spec) {
123
108
  const fields = String(spec ?? "")
124
109
  .trim()
@@ -137,15 +122,6 @@ export function parseCronSpec(spec) {
137
122
  function isFull(values, min, max) {
138
123
  return values.length === max - min + 1;
139
124
  }
140
- /**
141
- * 下一次触发毫秒时间戳(从 fromMs 的下一分钟开始扫,上限约一年);**一年内没有下一次回 null**
142
- * (例如 `0 0 31 2 *` 这种永远不存在的日子)。
143
- *
144
- * 为什么不是回一个「一年后的哨兵值」:调用方 `armCron` 拿它做 `setTimeout(next - now)`,
145
- * 而 Node 的 setTimeout 延迟超过 2^31-1ms(≈24.8 天)会**溢出成 1ms** —— 哨兵值配上溢出
146
- * 就是「1ms 后触发 → 再排下一次」的死循环(每次触发还伴随插件回调与写盘)。回 null 之后,
147
- * 调用方能明确区分「还有很久」与「永远不会发生」。纯函数,单测覆盖。
148
- */
149
125
  export function nextCronFire(parts, fromMs) {
150
126
  const minuteSet = new Set(parts.minute);
151
127
  const hourSet = new Set(parts.hour);
@@ -162,7 +138,6 @@ export function nextCronFire(parts, fromMs) {
162
138
  continue;
163
139
  const domHit = domSet.has(d.getDate());
164
140
  const dowHit = dowSet.has(d.getDay());
165
- // 标准 OR 语义:都受限取并集;一侧通配时另一侧说了算;都不受限天天跑。
166
141
  const dayHit = domRestricted && dowRestricted ? domHit || dowHit : domRestricted ? domHit : dowRestricted ? dowHit : true;
167
142
  if (!dayHit)
168
143
  continue;
@@ -174,17 +149,7 @@ export function nextCronFire(parts, fromMs) {
174
149
  }
175
150
  return null;
176
151
  }
177
- /**
178
- * setTimeout 的安全延迟上限(毫秒):Node 与浏览器都按 32 位有符号整数存延迟,
179
- * 超过 2^31-1 会被截断(Node 会**静默变成 1ms** 并打一条 TimeoutOverflowWarning)。
180
- */
181
152
  export const MAX_TIMEOUT_MS = 2_147_483_647;
182
- /**
183
- * 把「距离下次触发的毫秒数」切成一段安全的 setTimeout 延迟(纯函数,单测覆盖)。
184
- *
185
- * 超过上限就只等一个分片(默认 6 小时)再重新计算 —— 重新计算这一步是关键:
186
- * 过期声明、时钟回拨、系统休眠回来都能自然纠正,比一次性排一个超长定时器稳。
187
- */
188
153
  export function armDelay(nextAtMs, nowMs, maxChunkMs = 6 * 60 * 60 * 1000) {
189
154
  const raw = Math.max(0, Number(nextAtMs) - Number(nowMs));
190
155
  if (!Number.isFinite(raw))
@@ -194,7 +159,6 @@ export function armDelay(nextAtMs, nowMs, maxChunkMs = 6 * 60 * 60 * 1000) {
194
159
  export function scheduleFile(pluginDir) {
195
160
  return join(pluginDir, "schedules.json");
196
161
  }
197
- /** 读持久记录;坏文件/形状不对当空表(且不在读路径回写)。 */
198
162
  export function loadScheduleRecords(pluginDir) {
199
163
  try {
200
164
  const parsed = JSON.parse(readFileSync(scheduleFile(pluginDir), "utf8"));
@@ -222,7 +186,6 @@ export function loadScheduleRecords(pluginDir) {
222
186
  return {};
223
187
  }
224
188
  }
225
- /** 写持久记录(tmp+rename 原子写;失败只记日志,内存态本次会话仍生效)。 */
226
189
  export function saveScheduleRecords(pluginDir, records) {
227
190
  try {
228
191
  writeJsonAtomicSync(scheduleFile(pluginDir), { v: 1, schedules: records });
@@ -14,13 +14,6 @@ function unseal(key, blob) {
14
14
  decipher.setAuthTag(Buffer.from(blob.tag, "hex"));
15
15
  return Buffer.concat([decipher.update(Buffer.from(blob.ct, "hex")), decipher.final()]).toString("utf8");
16
16
  }
17
- /** 读或创建全局密钥文件(懒加载一次)。
18
- *
19
- * 曾有一个 bug:`readFileSync` 拿到的缓冲直接 `.toString("hex")`(把 hex 文本
20
- * 又做了一次 hex 编码),导致重启后 key 变成 65 字节,AES-256-GCM 全线报
21
- * "Invalid key length”。此处按 UTF-8 读 hex 文本再解码,并校验 32 字节——
22
- * 长度不对即视为损坏,重新生成(旧 secrets.bin 用旧 key 解不开→按 fail closed
23
- * 丢弃,总比所有机密操作全炸好;见 tests/unit/plugin-facilities.test.ts 回归)。 */
24
17
  function loadOrCreateKey(dataDir) {
25
18
  const keyFile = join(dataDir, "secrets.key");
26
19
  try {
@@ -31,18 +24,15 @@ function loadOrCreateKey(dataDir) {
31
24
  console.warn(`[secrets] ${keyFile} 长度异常(${loaded.length} 字节),重新生成密钥(旧机密将不可读)`);
32
25
  }
33
26
  }
34
- catch {
35
- /* fallthrough → regenerate */
36
- }
27
+ catch { }
37
28
  const key = randomBytes(32);
38
29
  writeAtomicSync(keyFile, `${key.toString("hex")}\n`);
39
30
  try {
40
- chmodSync(keyFile, 0o600); // best-effort(win 无效,不抛错)
31
+ chmodSync(keyFile, 0o600);
41
32
  }
42
33
  catch { }
43
34
  return key;
44
35
  }
45
- /** 加密 KV:先原子落盘再发布;每次读取磁盘,跨实例不缓存失败候选。 */
46
36
  export class PluginSecrets {
47
37
  file;
48
38
  settingsFile;
@@ -87,7 +77,6 @@ export class PluginSecrets {
87
77
  throw err;
88
78
  }
89
79
  }
90
- /** Settings and their encrypted secrets share one atomic commit, avoiding two-file rollback. */
91
80
  commitSettings(settings, updates) {
92
81
  const storage = this.storage();
93
82
  const items = { ...this.settingsItems(storage) };
@@ -120,9 +109,7 @@ export class PluginSecrets {
120
109
  try {
121
110
  legacy = this.load().items;
122
111
  }
123
- catch {
124
- /* Unreadable legacy data must not hide migrated settings. */
125
- }
112
+ catch { }
126
113
  return { ...legacy, ...this.settingsItems() };
127
114
  }
128
115
  get(name) {
@@ -1,24 +1,5 @@
1
- /**
2
- * 插件工具拦截扩展点:类型化 Decision(DSH 对照 P1-5)。
3
- *
4
- * 只做 **pre + post 两阶段**、只覆盖**已接管**的工具(`bash` / `read`),
5
- * 不照搬 DSH 的五阶段 —— 工具执行在 pi SDK 内部,只有这两处有插手面
6
- * (`agent-service.ts` 的 customTools 覆盖 + 终端接管 bash)。
7
- *
8
- * - pre:`allow` 放行 / `deny` 拒绝(带原因)/ `ask` 需要用户确认。
9
- * 首个非 allow 胜出;handler 抛错或超时一律降级为弃权(allow),
10
- * 与 DSH chain 的「select 抛错降级为弃权」同源。
11
- * - post:变换内容(脱敏/改写)/ 附加 `additionalContext`(自动补上下文)。
12
- * 逐个顺序合并,抛错的那个被跳过。
13
- * - `ask` 的完整审批 UI(弹框等人点)本次不做:按阻断处理,原因里注明
14
- * 待确认,模型能看到、人能在诊断里看到;以后要做审批流只改
15
- * `plugins.ts#evaluateToolPre` 的 ask 分支,不用动类型。
16
- */
17
- /** 单个守卫的最长等待:超时按弃权处理(不能让一个插件挂住整轮工具调用)。 */
18
1
  export const GUARD_HANDLER_TIMEOUT_MS = 5000;
19
- /** 附加上下文的上限(字符):插件补的上下文不能无节制进 LLM 上下文。 */
20
2
  export const GUARD_CONTEXT_CAP = 2000;
21
- /** 归一 pre 返回:void/null/垃圾一律按 allow(弃权);只认三决策的形状。 */
22
3
  export function normalizePreDecision(raw) {
23
4
  if (!raw || typeof raw !== "object")
24
5
  return { decision: "allow" };
@@ -31,7 +12,6 @@ export function normalizePreDecision(raw) {
31
12
  }
32
13
  return { decision: "allow" };
33
14
  }
34
- /** 是否阻断执行(deny/ask 都算阻断;ask 只是原因不同)。 */
35
15
  export function isBlockingDecision(d) {
36
16
  return d.decision === "deny" || d.decision === "ask";
37
17
  }
@@ -40,14 +20,12 @@ function pickText(zh, en, fbZh, fbEn, lang) {
40
20
  return zh?.trim() ? zh.trim() : fbZh;
41
21
  return en?.trim() ? en.trim() : fbEn;
42
22
  }
43
- /** 阻断时给模型看的一句话(ask 注明待确认 + 按拒绝处理)。 */
44
23
  export function denialText(d, pluginId, lang) {
45
24
  if (d.decision === "ask") {
46
25
  return pickText(d.reason, d.reasonEn, `插件 ${pluginId} 要求先确认再执行,已按拒绝处理(审批 UI 尚未实现,ask 暂按 deny 执行)`, `Plugin ${pluginId} asked for confirmation before execution; treated as denied (approval UI not implemented yet, ask behaves as deny)`, lang);
47
26
  }
48
27
  return pickText(d.decision === "deny" ? d.reason : undefined, d.decision === "deny" ? d.reasonEn : undefined, `插件 ${pluginId} 拒绝了本次工具调用`, `Plugin ${pluginId} denied this tool call`, lang);
49
28
  }
50
- /** 归一 post 返回:void/null/垃圾 → undefined(无编辑);content 坏形状时只保留上下文。 */
51
29
  export function normalizePostEdit(raw) {
52
30
  if (!raw || typeof raw !== "object")
53
31
  return undefined;
@@ -82,7 +60,6 @@ export function normalizePostEdit(raw) {
82
60
  ...(additionalContextEn ? { additionalContextEn } : {}),
83
61
  };
84
62
  }
85
- /** 把一次 post 编辑合进执行结果(返回新对象,不改原结果)。 */
86
63
  export function applyPostEdit(result, edit, lang) {
87
64
  const ctx = lang === "zh"
88
65
  ? edit.additionalContext?.trim()
@@ -95,7 +72,6 @@ export function applyPostEdit(result, edit, lang) {
95
72
  return result;
96
73
  return { ...result, content: [...(result.content ?? []), ...tail] };
97
74
  }
98
- /** 带超时的守卫调用:超时按弃权(pre→allow,post→undefined),调用方再归一。 */
99
75
  export function withGuardTimeout(p, ms = GUARD_HANDLER_TIMEOUT_MS) {
100
76
  let timer;
101
77
  const timeout = new Promise((resolve) => {
@@ -106,15 +82,12 @@ export function withGuardTimeout(p, ms = GUARD_HANDLER_TIMEOUT_MS) {
106
82
  clearTimeout(timer);
107
83
  });
108
84
  }
109
- /** 封存请求参数:浅冻一层(插件拿到的是快照,改了也不影响执行)。 */
110
85
  export function freezeParams(params) {
111
86
  if (params && typeof params === "object" && !Object.isFrozen(params)) {
112
87
  try {
113
88
  Object.freeze(params);
114
89
  }
115
- catch {
116
- // 冻不住(如 sealed 变体)就原样给:决策只读快照,不依赖冻结成功。
117
- }
90
+ catch { }
118
91
  }
119
92
  return params;
120
93
  }
@@ -1,7 +1,3 @@
1
- /**
2
- * UI_SLOTS — 宿主支持的全部挂载点集合,用于运行态校验。
3
- * 抽离到独立文件以打破 client-state.ts 与 plugins.ts 之间的循环依赖。
4
- */
5
1
  export const UI_SLOTS = new Set([
6
2
  "topbar.primary",
7
3
  "topbar.overflow",