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,16 +1,3 @@
1
- /**
2
- * server/workspace-snapshot.ts
3
- *
4
- * 工作区版本影子快照机制(Workspace Snapshot / Dual-State Rollback)。
5
- *
6
- * 每次用户发起新任务或运行关键操作前,为当前工作区记录轻量快照引用(Git commit SHA)。
7
- * 机制:
8
- * - 利用独立的临时 GIT_INDEX_FILE,通过 `git add -A -- .` + `git write-tree` + `git commit-tree` 生成独立 commit;
9
- * - 快照只覆盖对话 cwd 的**子树**(而非整个工作区),commit-tree 的顶层因此只有该子目录一个条目;
10
- * - 绝不改变用户现有的 HEAD、branch 指针、工作区文件或 .git/index;
11
- * - 回滚时若启用 restoreWorkspace,通过 `git checkout <snapshotRef> -- <prefix>` 与 `git clean -fd -- <prefix>`
12
- * 只还原/清理 cwd 子树,绝不触碰同仓库的兄弟目录。
13
- */
14
1
  import { execFile, spawn } from "node:child_process";
15
2
  import { createHash, randomUUID } from "node:crypto";
16
3
  import { copyFile, rm } from "node:fs/promises";
@@ -19,12 +6,8 @@ import { join, resolve } from "node:path";
19
6
  import { promisify } from "node:util";
20
7
  import { gitDirOf } from "./scm.js";
21
8
  const exec = promisify(execFile);
22
- /** 单次 git 快照/还原命令超时时间(毫秒)。 */
23
9
  const GIT_SNAPSHOT_TIMEOUT_MS = 15_000;
24
- /** 物理还原互斥链(#697):同一 cwd 的 git read-tree/clean 序列串行执行,
25
- * 杜绝并发回滚交错破坏 index/工作区;key 为 resolve 后的 cwd。 */
26
10
  const pendingRestores = new Map();
27
- /** 执行单条 git 命令,返回 stdout。 */
28
11
  async function runGit(cwd, args, envExtra) {
29
12
  const { stdout } = await exec("git", ["-c", "core.quotepath=false", ...args], {
30
13
  cwd,
@@ -35,14 +18,12 @@ async function runGit(cwd, args, envExtra) {
35
18
  });
36
19
  return stdout.trim();
37
20
  }
38
- /** 向 git 标准输入写一段内容。用于 `update-index --index-info` 这类不能把数万路径塞进 argv 的命令。 */
39
21
  function runGitInput(cwd, args, input, envExtra) {
40
22
  return new Promise((resolvePromise, reject) => {
41
23
  const child = spawn("git", ["-c", "core.quotepath=false", ...args], {
42
24
  cwd,
43
25
  env: envExtra ? { ...process.env, ...envExtra } : process.env,
44
26
  windowsHide: true,
45
- // stdout 不读会把管道缓冲写满,git 可能一直不退出;也不要让它漏进测试进程的 console。
46
27
  stdio: ["pipe", "ignore", "pipe"],
47
28
  });
48
29
  let stderr = "";
@@ -54,7 +35,6 @@ function runGitInput(cwd, args, input, envExtra) {
54
35
  child.kill();
55
36
  reject(new Error(`git ${args[0] ?? ""} timed out`));
56
37
  }, GIT_SNAPSHOT_TIMEOUT_MS);
57
- // 防御 EPIPE:当子进程异常提早退出时,写管道不会引发未捕获异常崩溃 Node 进程
58
38
  child.stdin?.on("error", () => { });
59
39
  child.stderr?.on("data", (chunk) => {
60
40
  stderr += chunk.toString();
@@ -79,15 +59,9 @@ function runGitInput(cwd, args, input, envExtra) {
79
59
  try {
80
60
  child.stdin.end(input);
81
61
  }
82
- catch {
83
- // ignore synchronous pipe write error
84
- }
62
+ catch { }
85
63
  });
86
64
  }
87
- /**
88
- * 一次性获取仓库核心元数据:gitDir、indexFile 与 prefix。
89
- * 合并多次独立的 `rev-parse` 调用,减少 Windows 下子进程启动开销。
90
- */
91
65
  export async function probeGitRepo(cwd) {
92
66
  try {
93
67
  const out = await runGit(cwd, ["rev-parse", "--git-dir", "--git-path", "index", "--show-prefix"]);
@@ -109,17 +83,10 @@ export async function probeGitRepo(cwd) {
109
83
  return null;
110
84
  }
111
85
  }
112
- /** 影子 index 缓存文件路径(按 gitDir 与规范化 cwd 的哈希隔离)。 */
113
86
  export function snapshotCachePath(gitDir, cwd) {
114
87
  const hash = createHash("sha1").update(resolve(cwd)).digest("hex").slice(0, 16);
115
88
  return join(gitDir, `pi-snapshot-cache-${hash}`);
116
89
  }
117
- /**
118
- * 把持久化的影子 index 缓存或用户真实 index 拷贝为快照用的临时 index。
119
- *
120
- * 优化:若之前已有该 cwd 的影子 index 缓存且有效,直接复用拷贝它(无需重复扫描兄弟目录且保留上一轮已跟踪/未跟踪文件的 stat 缓存);
121
- * 若无缓存,拷贝用户真实 index 并剔除子树外条目;若出错则回退。
122
- */
123
90
  async function seedSnapshotIndex(cwd, tempIndex, repo, env) {
124
91
  const cachePath = snapshotCachePath(repo.gitDir, cwd);
125
92
  if (existsSync(cachePath)) {
@@ -128,7 +95,6 @@ async function seedSnapshotIndex(cwd, tempIndex, repo, env) {
128
95
  return { fromCache: true };
129
96
  }
130
97
  catch {
131
- // 缓存损坏或不可读,清理并回落到真实 index
132
98
  await rm(cachePath, { force: true }).catch(() => { });
133
99
  }
134
100
  }
@@ -172,7 +138,6 @@ async function seedSnapshotIndex(cwd, tempIndex, repo, env) {
172
138
  return { fromCache: false };
173
139
  }
174
140
  const lastSnapshotByCwd = new Map();
175
- /** 清理特定 cwd(或全部)的上次快照内存缓存(单测或工作区还原时调用)。 */
176
141
  export function clearWorkspaceSnapshotCaches(cwd) {
177
142
  if (cwd) {
178
143
  lastSnapshotByCwd.delete(resolve(cwd));
@@ -181,19 +146,12 @@ export function clearWorkspaceSnapshotCaches(cwd) {
181
146
  lastSnapshotByCwd.clear();
182
147
  }
183
148
  }
184
- /** 检查工作区是否由 Git 管理。 */
185
149
  export async function isGitWorkspace(cwd) {
186
150
  const info = await probeGitRepo(cwd);
187
151
  if (info)
188
152
  return true;
189
153
  return (await gitDirOf(cwd)) !== null;
190
154
  }
191
- /**
192
- * 为当前工作区创建轻量版本快照。
193
- * 若当前目录不在 Git 仓库内,返回 null。
194
- *
195
- * 该操作纯粹在临时 index 文件中完成,绝不影响用户的实际 index 或 HEAD。
196
- */
197
155
  export async function createWorkspaceSnapshot(cwd) {
198
156
  const repo = await probeGitRepo(cwd);
199
157
  if (!repo)
@@ -202,16 +160,13 @@ export async function createWorkspaceSnapshot(cwd) {
202
160
  const env = { GIT_INDEX_FILE: tempIndex };
203
161
  const cachePath = snapshotCachePath(repo.gitDir, cwd);
204
162
  try {
205
- // 1. 先种入 index(优先从持久化影子缓存拷贝,次选从真实 index 拷贝并剔除子树外条目)
206
163
  await seedSnapshotIndex(cwd, tempIndex, repo, env);
207
- // 2 & 3. 将 cwd 子树当前改动暂存到临时 index 并生成 tree 对象(若因 cache 损坏或脏索引失败,回退空 index 重试)
208
164
  let tree = null;
209
165
  try {
210
166
  await runGit(cwd, ["add", "-A", "--", "."], env);
211
167
  tree = await runGit(cwd, ["write-tree"], env);
212
168
  }
213
169
  catch (stageErr) {
214
- // 回退兜底:清理损坏的临时 index 和缓存 index,从纯空 index 重试一次
215
170
  await rm(tempIndex, { force: true }).catch(() => { });
216
171
  await rm(cachePath, { force: true }).catch(() => { });
217
172
  try {
@@ -224,18 +179,12 @@ export async function createWorkspaceSnapshot(cwd) {
224
179
  }
225
180
  if (!tree)
226
181
  return null;
227
- // 异步更新持久化影子 index 缓存供下轮秒级复用。必须 await 后再进 finally:
228
- // 否则 finally 里 rm(tempIndex) 会在拷贝中途删掉源文件,Windows 上拷贝要么
229
- // EBUSY 失败、要么把半截内容写进 cachePath(下轮读坏缓存再回落,缓存失效)。
230
182
  await copyFile(tempIndex, cachePath).catch(() => { });
231
- // 优化 3:检查 tree 是否与该 cwd 上次快照完全一致
232
183
  const normCwd = resolve(cwd);
233
184
  const last = lastSnapshotByCwd.get(normCwd);
234
185
  if (last && last.treeSha === tree) {
235
- // 工作区内容完全无变动:直接复用已有快照 SHA,省去 rev-parse HEAD + commit-tree
236
186
  return last.snapshotRef;
237
187
  }
238
- // 4. 检查是否有 HEAD commit 作为 parent
239
188
  let hasHead = false;
240
189
  try {
241
190
  await runGit(cwd, ["rev-parse", "--verify", "HEAD"]);
@@ -244,7 +193,6 @@ export async function createWorkspaceSnapshot(cwd) {
244
193
  catch {
245
194
  hasHead = false;
246
195
  }
247
- // 5. 创建轻量 commit 对象,不关联任何分支引用
248
196
  const commitArgs = ["commit-tree", tree];
249
197
  if (hasHead) {
250
198
  commitArgs.push("-p", "HEAD");
@@ -266,27 +214,12 @@ export async function createWorkspaceSnapshot(cwd) {
266
214
  return null;
267
215
  }
268
216
  finally {
269
- // 务必清理临时 index 文件
270
217
  try {
271
218
  await rm(tempIndex, { force: true });
272
219
  }
273
- catch {
274
- // ignore cleanup error
275
- }
220
+ catch { }
276
221
  }
277
222
  }
278
- /**
279
- * 将工作区物理文件还原到指定的快照状态,作用范围严格限定在 cwd 子树内。
280
- *
281
- * 执行步骤:
282
- * - 仓库根 cwd:使用原子 `git read-tree -u --reset` + `git clean -fd` 整仓还原(天然支持空仓库快照);
283
- * - 子目录 cwd(pathspec 以 `:(top)` 锚定到仓库根的 cwd 前缀):
284
- * 1. `git rm -r --cached -- <pathspec>` 把 cwd 子树移出 index(工作区文件不动),使快照中
285
- * 不存在的文件退回未跟踪状态——这一步让 checkout 之外的「快照后新增且已 add」的文件也能被回滚;
286
- * 2. `git checkout <snapshotRef> -- <pathspec>` 把快照内容写回 index 与工作区(恢复被修改/删除的跟踪文件,快照无该子树文件时容错跳过);
287
- * 3. `git clean -fd -- <pathspec>` 清理快照之后新增的未跟踪文件与空目录。
288
- * 同仓库的兄弟目录在以上任何一步都不受影响。
289
- */
290
223
  export async function restoreWorkspaceSnapshot(cwd, snapshotRef) {
291
224
  const key = resolve(cwd);
292
225
  const prev = pendingRestores.get(key);
@@ -300,9 +233,7 @@ export async function restoreWorkspaceSnapshot(cwd, snapshotRef) {
300
233
  try {
301
234
  await prev;
302
235
  }
303
- catch {
304
- // 前一还原失败不阻塞后继
305
- }
236
+ catch { }
306
237
  }
307
238
  try {
308
239
  return await restoreWorkspaceSnapshotInner(cwd, snapshotRef);
@@ -318,27 +249,20 @@ async function restoreWorkspaceSnapshotInner(cwd, snapshotRef) {
318
249
  if (!gitDir) {
319
250
  return { success: false, error: "Workspace is not a Git repository" };
320
251
  }
321
- // index 备份:子目录回滚的第 1 步 rm --cached 直接改真实 index,后续 checkout/clean
322
- // 中途失败时原子还原,暂存区不再留在损坏状态(见 catch 中的还原注释)
323
252
  let indexRealPath = "";
324
253
  let indexBackup = "";
325
254
  let indexBackedUp = false;
326
255
  try {
327
- // 验证 snapshotRef 合法性
328
256
  await runGit(cwd, ["rev-parse", "--verify", snapshotRef]);
329
- // cwd 相对仓库根的前缀(子目录形如 `proj/`,仓库根为空串)。
330
257
  const prefix = await runGit(cwd, ["rev-parse", "--show-prefix"]);
331
258
  if (!prefix) {
332
- // 仓库根 cwd:整仓还原,使用原子 read-tree --reset,旧实现经过长期验证且天然支持空仓库快照
333
259
  await runGit(cwd, ["read-tree", "-u", "--reset", snapshotRef]);
334
260
  await runGit(cwd, ["clean", "-fd"]);
335
- // 还原成功后,清除该 cwd 的上次快照缓存与影子 index
336
261
  lastSnapshotByCwd.delete(resolve(cwd));
337
262
  const cachePath = snapshotCachePath(gitDir, cwd);
338
263
  void rm(cachePath, { force: true }).catch(() => { });
339
264
  return { success: true };
340
265
  }
341
- // 子目录 cwd:作用域收敛到该子树,不误伤同仓兄弟目录与仓库根
342
266
  const pathspec = `:(top)${prefix}`;
343
267
  indexRealPath = resolve(cwd, (await runGit(cwd, ["rev-parse", "--git-path", "index"])).trim());
344
268
  indexBackup = join(gitDir, `temp-index-backup-${randomUUID()}`);
@@ -346,16 +270,8 @@ async function restoreWorkspaceSnapshotInner(cwd, snapshotRef) {
346
270
  await copyFile(indexRealPath, indexBackup);
347
271
  indexBackedUp = true;
348
272
  }
349
- catch {
350
- // 空仓库可能还没有 index 文件:rm --cached 无从破坏,无需备份
351
- }
352
- // 1. 把 cwd 子树移出 index(不删除工作区文件),快照里不存在的文件由此退回未跟踪状态
273
+ catch { }
353
274
  await runGit(cwd, ["rm", "-r", "--cached", "--quiet", "--ignore-unmatch", "--", pathspec]);
354
- // 2. 快照树内确有该子树文件时才 checkout(恢复被修改与被删除的跟踪文件)。
355
- // 先 ls-tree 判存在,替代老实现「捕获 checkout 的英文报错文案」的判空——
356
- // 本地化 git(zh_CN 等)下文案不匹配会把「快照为空」误当真失败抛出。
357
- // ls-tree 的 path 按 git 进程 cwd(= 本子目录)相对解析:用 :(top) 锚定
358
- // 到仓库根的子树前缀,与第 1/3 步的 pathspec 同口径。
359
275
  const listed = await runGit(cwd, [
360
276
  "ls-tree",
361
277
  "-r",
@@ -367,9 +283,7 @@ async function restoreWorkspaceSnapshotInner(cwd, snapshotRef) {
367
283
  if (listed.trim()) {
368
284
  await runGit(cwd, ["checkout", snapshotRef, "--", pathspec]);
369
285
  }
370
- // 3. 清理快照之后新增的未跟踪文件与空目录(含第 1 步退回未跟踪的那些)
371
286
  await runGit(cwd, ["clean", "-fd", "--", pathspec]);
372
- // 还原成功后,清除该 cwd 的上次快照缓存与影子 index,确保后续快照重新根据物理工作区生成
373
287
  lastSnapshotByCwd.delete(resolve(cwd));
374
288
  const cachePath = snapshotCachePath(gitDir, cwd);
375
289
  void rm(cachePath, { force: true }).catch(() => { });
@@ -377,17 +291,10 @@ async function restoreWorkspaceSnapshotInner(cwd, snapshotRef) {
377
291
  }
378
292
  catch (err) {
379
293
  if (indexBackedUp) {
380
- // 原子还原 index:第 1 步 rm --cached 已改真实 index,checkout 中途失败
381
- //(文件被占用 EBUSY、磁盘满…)不能把暂存区留在「整棵子树 staged-deleted」
382
- // 的损坏状态——回滚本身不能再制造新破坏。
383
- //(还原窗口内的并发 git 写操作会被覆盖:窗口毫秒级,且损坏的暂存区
384
- // 比丢一瞬间的暂存操作严重得多。)
385
294
  try {
386
295
  await copyFile(indexBackup, indexRealPath);
387
296
  }
388
- catch {
389
- // 还原失败:错误照常上报
390
- }
297
+ catch { }
391
298
  }
392
299
  const msg = err.message;
393
300
  console.error(`[workspace-snapshot] 还原快照失败 (${cwd}, ${snapshotRef}):`, msg);
@@ -397,15 +304,9 @@ async function restoreWorkspaceSnapshotInner(cwd, snapshotRef) {
397
304
  try {
398
305
  await rm(indexBackup, { force: true });
399
306
  }
400
- catch {
401
- // ignore cleanup error
402
- }
307
+ catch { }
403
308
  }
404
309
  }
405
- /**
406
- * 查找与指定消息 entryId/时间戳最匹配的工作区物理快照:
407
- * 优先匹配 exact entryId,其次查找该 entry 时间戳之前(或 +2000ms 内)的最近一份快照。
408
- */
409
310
  export function findMatchingWorkspaceSnapshot(snapshots, entryId, entryTs = 0) {
410
311
  if (!snapshots || snapshots.length === 0)
411
312
  return undefined;
@@ -420,7 +321,6 @@ export function findMatchingWorkspaceSnapshot(snapshots, entryId, entryTs = 0) {
420
321
  }
421
322
  return snapshots[0];
422
323
  }
423
- /** 从会话 sessionManager entries 回放恢复之前持久化的快照映射记录。 */
424
324
  export function readWorkspaceSnapshotsFromSession(sm) {
425
325
  try {
426
326
  const mgr = sm;
@@ -444,19 +344,13 @@ export function readWorkspaceSnapshotsFromSession(sm) {
444
344
  return [];
445
345
  }
446
346
  }
447
- /** 将快照映射记录持久化到会话转录中(以便会话重载或服务重启后支持双向回滚)。 */
448
347
  export function appendWorkspaceSnapshotToSession(sm, record) {
449
348
  try {
450
349
  const mgr = sm;
451
350
  mgr?.appendCustomEntry?.("pi-web-ui/workspace-snapshot", record);
452
351
  }
453
- catch {
454
- // ignore
455
- }
352
+ catch { }
456
353
  }
457
- /**
458
- * 为工具定义叠加影子快照门禁:在工具执行物理写操作之前,确保正在并发生成的快照已经完成。
459
- */
460
354
  export function withWorkspaceSnapshotGate(def, awaitPendingSnapshot) {
461
355
  const originalExecute = def.execute;
462
356
  return {
@@ -1,14 +1,3 @@
1
- /**
2
- * server/worktree-service.ts
3
- *
4
- * Git 工作树(Git Worktree)核心服务层。
5
- *
6
- * 功能:
7
- * 1. 结构化解析 `git worktree list --porcelain`,获取主工作树与所有子工作树(Linked Worktrees);
8
- * 2. 检测各工作树状态(分支名、HEAD SHA、未提交文件数、是否为当前工作区、是否为主仓库);
9
- * 3. 规范化创建(create)、清理(remove)、剪枝(prune)工作树;
10
- * 4. 组装 `WorktreeInfo` 上下文供 UI 横幅与 AI 工具消费。
11
- */
12
1
  import { execFile } from "node:child_process";
13
2
  import { resolve, normalize } from "node:path";
14
3
  import { promisify } from "node:util";
@@ -17,7 +6,6 @@ import { pick } from "./i18n.js";
17
6
  const exec = promisify(execFile);
18
7
  const GIT_TIMEOUT_MS = 15_000;
19
8
  const FAST_GIT_TIMEOUT_MS = 5_000;
20
- /** 统一路径分隔符为 '/',兼顾 Windows 盘符大小写归一化。 */
21
9
  export function normalizeWirePath(p) {
22
10
  const resolved = resolve(normalize(p)).replace(/\\/g, "/");
23
11
  if (process.platform === "win32" && /^[a-zA-Z]:/.test(resolved)) {
@@ -25,7 +13,6 @@ export function normalizeWirePath(p) {
25
13
  }
26
14
  return resolved;
27
15
  }
28
- /** 运行单条 git 命令,失败时抛出友好错误。 */
29
16
  async function runGit(cwd, args, timeoutMs = GIT_TIMEOUT_MS) {
30
17
  try {
31
18
  const { stdout } = await exec("git", ["-c", "core.quotepath=false", ...args], {
@@ -42,7 +29,6 @@ async function runGit(cwd, args, timeoutMs = GIT_TIMEOUT_MS) {
42
29
  throw new Error(detail || "Git command failed");
43
30
  }
44
31
  }
45
- /** 检查指定目录是否位于 Git 仓库中。 */
46
32
  export async function isInsideGitRepo(cwd) {
47
33
  try {
48
34
  const out = await runGit(cwd, ["rev-parse", "--is-inside-work-tree"], FAST_GIT_TIMEOUT_MS);
@@ -52,7 +38,6 @@ export async function isInsideGitRepo(cwd) {
52
38
  return false;
53
39
  }
54
40
  }
55
- /** 解析 `git worktree list --porcelain` 文本输出。 */
56
41
  export function parseWorktreePorcelain(text) {
57
42
  const items = [];
58
43
  const blocks = text.trim().split(/\n\s*\n/);
@@ -110,7 +95,6 @@ export function parseWorktreePorcelain(text) {
110
95
  }
111
96
  return items;
112
97
  }
113
- /** 快速检测指定工作树目录中的未提交更改数(status --porcelain)。 */
114
98
  async function getUncommittedCount(worktreePath) {
115
99
  if (!existsSync(worktreePath)) {
116
100
  return { isDirty: true, count: 0, error: `Worktree does not exist: ${worktreePath}` };
@@ -127,11 +111,9 @@ async function getUncommittedCount(worktreePath) {
127
111
  };
128
112
  }
129
113
  catch (error) {
130
- // Unknown status must never authorize removal, including in list consumers.
131
114
  return { isDirty: true, count: 0, error: error.message };
132
115
  }
133
116
  }
134
- /** 计算当前工作树相对于主分支领先的 commit 数。 */
135
117
  async function getAheadCount(worktreePath, mainBranch = "main") {
136
118
  if (!existsSync(worktreePath))
137
119
  return 0;
@@ -141,7 +123,6 @@ async function getAheadCount(worktreePath, mainBranch = "main") {
141
123
  return Number.isNaN(num) ? 0 : num;
142
124
  }
143
125
  catch {
144
- // 主分支名可能是 master
145
126
  if (mainBranch === "main") {
146
127
  try {
147
128
  const out = await runGit(worktreePath, ["rev-list", "--count", `HEAD`, `^master`], FAST_GIT_TIMEOUT_MS);
@@ -155,7 +136,6 @@ async function getAheadCount(worktreePath, mainBranch = "main") {
155
136
  return 0;
156
137
  }
157
138
  }
158
- /** 列出当前 Git 仓库的所有工作树,包含主工作树与关联子工作树。 */
159
139
  export async function listWorktrees(cwd) {
160
140
  const inside = await isInsideGitRepo(cwd);
161
141
  if (!inside)
@@ -188,7 +168,6 @@ export async function listWorktrees(cwd) {
188
168
  }
189
169
  return results;
190
170
  }
191
- /** 创建新的 Git 工作树。 */
192
171
  export async function createWorktree(cwd, opts, lang) {
193
172
  const l = lang?.() ?? "en";
194
173
  const inside = await isInsideGitRepo(cwd);
@@ -215,7 +194,6 @@ export async function createWorktree(cwd, opts, lang) {
215
194
  await runGit(cwd, args);
216
195
  return { path: targetPath, branch: branchName };
217
196
  }
218
- /** 移除指定 Git 工作树。 */
219
197
  export async function removeWorktree(cwd, targetPathInput, force = false, lang) {
220
198
  const l = lang?.() ?? "en";
221
199
  const inside = await isInsideGitRepo(cwd);
@@ -250,7 +228,6 @@ export async function removeWorktree(cwd, targetPathInput, force = false, lang)
250
228
  }
251
229
  throw lastErr;
252
230
  }
253
- /** 获取当前目录的完整工作树上下文元数据(用于 UI 横幅与快照)。 */
254
231
  export async function getWorktreeContext(cwd) {
255
232
  try {
256
233
  const inside = await isInsideGitRepo(cwd);
@@ -276,7 +253,6 @@ export async function getWorktreeContext(cwd) {
276
253
  return null;
277
254
  }
278
255
  }
279
- /** 仓库级异步操作互斥锁(防止多个子代理并发创建/删除工作树时碰撞 Git 内部文件锁)。 */
280
256
  const repoLocks = new Map();
281
257
  export async function withRepoLock(repoPath, task) {
282
258
  const key = normalizeWirePath(repoPath);
@@ -298,7 +274,6 @@ export async function withRepoLock(repoPath, task) {
298
274
  }
299
275
  }
300
276
  }
301
- /** 自动将 .worktrees/ 加入 .git/info/exclude(零污染:防止未在 .gitignore 忽略此目录的用户仓库出现 untracked 脏状态)。 */
302
277
  export async function ensureWorktreeExcluded(repoPath) {
303
278
  try {
304
279
  const gitCommonDir = (await runGit(repoPath, ["rev-parse", "--git-common-dir"], FAST_GIT_TIMEOUT_MS)).trim();
@@ -316,14 +291,8 @@ export async function ensureWorktreeExcluded(repoPath) {
316
291
  writeFileSync(excludeFile, "# pi-web-ui worktrees\n.worktrees/\n", "utf-8");
317
292
  }
318
293
  }
319
- catch {
320
- // non-fatal
321
- }
294
+ catch { }
322
295
  }
323
- /**
324
- * 为子代理创建专用的 Git 工作树与分支(issue #728)。
325
- * 自动从当前 HEAD 检出,并建立依赖软链接(node_modules/.venv 等),使子代理可立即执行测试。
326
- */
327
296
  export async function createSubagentWorktree(baseCwd, subagentId, lang) {
328
297
  const l = lang?.() ?? "en";
329
298
  const inside = await isInsideGitRepo(baseCwd);
@@ -335,9 +304,7 @@ export async function createSubagentWorktree(baseCwd, subagentId, lang) {
335
304
  const mainRepoPath = rawItems[0]?.path || normalizeWirePath(resolve(baseCwd));
336
305
  const worktreeDir = normalizeWirePath(resolve(mainRepoPath, ".worktrees", subagentId));
337
306
  const branchName = `subagent/${subagentId}`;
338
- // 获取创建时刻的当前 HEAD SHA 作为基准
339
307
  const baseCommit = (await runGit(baseCwd, ["rev-parse", "HEAD"])).trim();
340
- // 确定子代理的执行目录(若 baseCwd 在 mainRepoPath 的子目录中,则映射至工作树对应子目录)
341
308
  const normBase = normalizeWirePath(resolve(baseCwd));
342
309
  const normMain = normalizeWirePath(resolve(mainRepoPath));
343
310
  let subagentCwd = worktreeDir;
@@ -349,10 +316,7 @@ export async function createSubagentWorktree(baseCwd, subagentId, lang) {
349
316
  await ensureWorktreeExcluded(mainRepoPath);
350
317
  const { mkdirSync, existsSync, symlinkSync } = await import("node:fs");
351
318
  mkdirSync(resolve(mainRepoPath, ".worktrees"), { recursive: true });
352
- // 使用 -B 确保分支已存在时安全重置,HEAD 确保从当前状态检出
353
319
  await runGit(mainRepoPath, ["worktree", "add", "-B", branchName, worktreeDir, "HEAD"]);
354
- // 依赖桥接:若主仓库根有 node_modules 或 .venv,在工作树中建立目录软连接/Junction,
355
- // 这样子代理可立即运行 npm test / python 测试,无需耗时重装依赖
356
320
  for (const depDir of ["node_modules", ".venv"]) {
357
321
  const src = resolve(mainRepoPath, depDir);
358
322
  const dest = resolve(worktreeDir, depDir);
@@ -360,9 +324,7 @@ export async function createSubagentWorktree(baseCwd, subagentId, lang) {
360
324
  try {
361
325
  symlinkSync(src, dest, process.platform === "win32" ? "junction" : "dir");
362
326
  }
363
- catch {
364
- // 软链接失败不阻断工作树核心流程
365
- }
327
+ catch { }
366
328
  }
367
329
  }
368
330
  });
@@ -374,12 +336,6 @@ export async function createSubagentWorktree(baseCwd, subagentId, lang) {
374
336
  subagentCwd,
375
337
  };
376
338
  }
377
- /**
378
- * 终态判定与清理(issue #728):
379
- * 双重判定改动(未提交修改 + 领先 commit 数):
380
- * - 无改动:自动安全清理工作树并删除临时分支;
381
- * - 有改动:保留工作树与分支供父对话审阅、合并或清理。
382
- */
383
339
  export async function finalizeSubagentWorktree(wt, lang, canCleanup = () => true) {
384
340
  if (wt.finalized || !canCleanup())
385
341
  return wt;
@@ -396,18 +352,15 @@ export async function finalizeSubagentWorktree(wt, lang, canCleanup = () => true
396
352
  const currentHead = (await runGit(wt.worktreePath, ["rev-parse", "HEAD"])).trim();
397
353
  if (!currentHead)
398
354
  throw new Error("Cannot verify worktree HEAD");
399
- // A changed HEAD always requires review, even if it is not ahead of base.
400
355
  const aheadCount = currentHead === wt.baseCommit ? 0 : Math.max(1, await getAheadCount(wt.worktreePath, wt.baseCommit));
401
356
  wt.isDirty = isDirty;
402
357
  wt.uncommittedCount = uncommittedCount;
403
358
  wt.aheadCount = aheadCount;
404
359
  const hasChanges = isDirty || aheadCount > 0;
405
360
  if (!hasChanges) {
406
- // 没有改动 -> 自动清理工作树与临时分支
407
361
  await withRepoLock(wt.mainRepoPath, async () => {
408
362
  if (!canCleanup())
409
363
  throw new Error("Worktree acquired an active execution during finalization");
410
- // 先移除建立的软链接/Junction,防止 Windows 下锁死目录句柄
411
364
  for (const depDir of ["node_modules", ".venv"]) {
412
365
  const p = resolve(wt.worktreePath, depDir);
413
366
  if (existsSync(p)) {
@@ -418,7 +371,6 @@ export async function finalizeSubagentWorktree(wt, lang, canCleanup = () => true
418
371
  catch { }
419
372
  }
420
373
  }
421
- // Recheck under the repository lock and let Git reject concurrent changes.
422
374
  const head = (await runGit(wt.worktreePath, ["rev-parse", "HEAD"])).trim();
423
375
  if (head !== wt.baseCommit)
424
376
  throw new Error("Worktree HEAD changed during cleanup");
@@ -426,7 +378,6 @@ export async function finalizeSubagentWorktree(wt, lang, canCleanup = () => true
426
378
  throw new Error("Worktree acquired an active execution during finalization");
427
379
  await removeWorktree(wt.mainRepoPath, wt.worktreePath, false, lang);
428
380
  try {
429
- // Compare-and-delete: a concurrent commit must preserve its branch.
430
381
  await runGit(wt.mainRepoPath, ["update-ref", "-d", `refs/heads/${wt.branch}`, wt.baseCommit]);
431
382
  }
432
383
  catch { }
@@ -434,7 +385,6 @@ export async function finalizeSubagentWorktree(wt, lang, canCleanup = () => true
434
385
  wt.cleanedUp = true;
435
386
  }
436
387
  else {
437
- // 有改动 -> 完整保留,由父对话决定合并还是清理
438
388
  wt.cleanedUp = false;
439
389
  }
440
390
  wt.finalized = true;
@@ -446,7 +396,6 @@ export async function finalizeSubagentWorktree(wt, lang, canCleanup = () => true
446
396
  }
447
397
  return wt;
448
398
  }
449
- /** 剪枝清理已损坏或残留的孤儿工作树 */
450
399
  export async function pruneOrphanSubagentWorktrees(cwd) {
451
400
  try {
452
401
  const inside = await isInsideGitRepo(cwd);
@@ -1,14 +1,3 @@
1
- /**
2
- * server/worktree-tool.ts
3
- *
4
- * Git 工作树(worktree)管理工具。
5
- *
6
- * 支持动作:
7
- * - list: 列出当前仓库的所有工作树、分支、未提交文件数与领先状态;
8
- * - create: 创建新的工作树(支持基于已有分支或新分支,可选 switchTo 立即切换工作区);
9
- * - switch: 切换当前工作区至指定工作树;
10
- * - remove: 安全移除工作树(含未提交修改保护)。
11
- */
12
1
  import { Type } from "typebox";
13
2
  import { resolve } from "node:path";
14
3
  import { pick } from "./i18n.js";
@@ -1,23 +1,5 @@
1
- /**
2
- * WS hello 的 clientId 校验 —— 独立成模块是为了可单测
3
- * (`server/index.ts` 起 WS + SDK,不适合在单测里 import)。
4
- *
5
- * 背景:hello.clientId 原样进入 service.attach → ClientSession → saveUpload
6
- * (`<dataDir>/uploads/<clientId>/`,见 attachments.ts / dsh-agent-service.ts),
7
- * 无校验时外部可传对象/数字/路径穿越串。合法客户端用 uuid(含连字符,在字符集
8
- * 内);服务端伪客户端是 `scheduler:`/`plugin:` 前缀(冒号在字符集内),但那些
9
- * 不走 WS hello——收进字符集只是不挡未来的复用,不构成放行面。
10
- */
11
- /** clientId 长度上限:uuid 36 字符的数倍余量,防超长串写盘/进日志。 */
12
1
  export const MAX_CLIENT_ID_LEN = 128;
13
- /** clientId 字符集:uuid(含 -)、伪客户端前缀(含 :)、下划线。 */
14
2
  const CLIENT_ID_RE = /^[A-Za-z0-9:_-]+$/;
15
- /**
16
- * 校验 hello.clientId:必须是 string、1-128 字符、限定字符集。
17
- * 合法原样返回;不合法(类型不对/空串/超长/含非法字符)返回 null,
18
- * 调用方回退 randomUUID()——校验必须在 hello 入口统一做(服务端所有把
19
- * clientId 落盘/当目录名的路径都从 attach 这一条链来)。
20
- */
21
3
  export function validateClientId(input) {
22
4
  if (typeof input !== "string")
23
5
  return null;
@@ -4,9 +4,7 @@ export const MAX_PENDING_WS_MESSAGES = 256;
4
4
  export const MAX_PENDING_WS_BYTES = 8 * 1024 * 1024;
5
5
  export const MAX_PRE_HELLO_WS_BYTES = 16 * 1024;
6
6
  export const MAX_CONTROL_WS_BYTES = 1024 * 1024;
7
- /** Matches the 100MiB file upload's base64 expansion + JSON envelope allowance. */
8
7
  export const MAX_ATTACHMENT_WS_BYTES = WS_MAX_PAYLOAD_BYTES;
9
- /** Envelope check only; individual command handlers must still validate their payloads. */
10
8
  export function isClientMessageEnvelope(value) {
11
9
  if (value === null || typeof value !== "object" || Array.isArray(value))
12
10
  return false;
@@ -19,7 +17,6 @@ export function isClientMessageEnvelope(value) {
19
17
  value.type.length > 0 &&
20
18
  value.type.length <= 128);
21
19
  }
22
- /** Apply the pre-hello limit before parsing; then use the type budget after parsing. */
23
20
  export function clientMessageByteLimit(type, helloReceived = true) {
24
21
  if (!helloReceived || type === "hello")
25
22
  return MAX_PRE_HELLO_WS_BYTES;
@@ -35,7 +32,6 @@ export function clientMessageByteLimit(type, helloReceived = true) {
35
32
  export function isClientMessageWithinByteLimit(type, wireBytes, helloReceived = true) {
36
33
  return Number.isSafeInteger(wireBytes) && wireBytes >= 0 && wireBytes <= clientMessageByteLimit(type, helloReceived);
37
34
  }
38
- /** Legacy names retained for callers; drops now mean rejected incoming commands. */
39
35
  export const PENDING_DROP_WARN_INTERVAL_MS = 60_000;
40
36
  let lastWarnAt = Number.NEGATIVE_INFINITY;
41
37
  export function warnPendingDrop(totalDropped, log) {
@@ -48,7 +44,6 @@ export function warnPendingDrop(totalDropped, log) {
48
44
  export function resetPendingDropWarn() {
49
45
  lastWarnAt = Number.NEGATIVE_INFINITY;
50
46
  }
51
- /** Bounded attach-time FIFO. Callers must handle false explicitly (e.g. close with 1009). */
52
47
  export class PendingCommandQueue {
53
48
  cap;
54
49
  byteCap;
@@ -62,7 +57,6 @@ export class PendingCommandQueue {
62
57
  throw new RangeError("Pending queue limits must be non-negative safe integers");
63
58
  }
64
59
  }
65
- /** Supply the raw UTF-8 wire length to avoid allocating a second JSON serialization. */
66
60
  push(msg, wireBytes) {
67
61
  if (this.items.length >= this.cap)
68
62
  return this.reject();
@@ -93,7 +87,6 @@ export class PendingCommandQueue {
93
87
  this.items = [];
94
88
  this.queuedBytes = 0;
95
89
  }
96
- /** Lifetime count of rejected pushes (legacy property name). */
97
90
  get dropped() {
98
91
  return this.droppedTotal;
99
92
  }
@@ -1,23 +1,8 @@
1
- /**
2
- * Unknown inbound WS message-type counter —— 独立成模块是为了可单测
3
- * (`server/index.ts` 起 WS + SDK,不适合在单测里 import)。
4
- *
5
- * 背景:`dispatch` 的 `switch (msg.type)` 的 `default:` 分支原来是空的,
6
- * 版本错位(旧前端/新服务端)或插件发错 type 时静默丢弃,只能抓包排查。
7
- * 这里只做计数 + 节流 warn,不改变任何已知类型的行为。
8
- */
9
- /** 同一 type 两次 warn 之间最小间隔(防刷屏),可单测覆盖。 */
10
1
  export const UNKNOWN_WS_WARN_INTERVAL_MS = 60_000;
11
- /** 未知 type 种类上限:type 字符串远端可控,无上限则内存无界增长。
12
- * 超限后的新 type 不再建 key,只进溢出计数。 */
13
2
  export const MAX_UNKNOWN_WS_TYPES = 500;
14
3
  const counts = new Map();
15
4
  const lastWarnAt = new Map();
16
5
  let overflowed = 0;
17
- /**
18
- * 记录一次未知 type,计数永远 +1;同一 type 在 `UNKNOWN_WS_WARN_INTERVAL_MS`
19
- * 内只返回一次 `warn: true`(调用方决定是否 `console.warn`)。
20
- */
21
6
  export function recordUnknownWsType(type, now = Date.now()) {
22
7
  if (!counts.has(type) && counts.size >= MAX_UNKNOWN_WS_TYPES) {
23
8
  overflowed++;
@@ -32,11 +17,9 @@ export function recordUnknownWsType(type, now = Date.now()) {
32
17
  }
33
18
  return { count, warn: false };
34
19
  }
35
- /** 只读快照(排障用,返回拷贝,调用方改不动内部表)。 */
36
20
  export function unknownWsCounts() {
37
21
  return new Map(counts);
38
22
  }
39
- /** 单测隔离用。 */
40
23
  export function resetUnknownWsTypes() {
41
24
  counts.clear();
42
25
  lastWarnAt.clear();