pi-web-ui 0.117.0 → 0.118.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (512) hide show
  1. package/CHANGELOG.md +48 -2
  2. package/README.md +69 -138
  3. package/README.zh-CN.md +70 -179
  4. package/README.zh-TW.md +3 -1
  5. package/bin/device-hub-cli.mjs +147 -43
  6. package/bin/frp-manager.mjs +4 -80
  7. package/bin/hub-upgrade.mjs +561 -0
  8. package/bin/pi-device-hub.mjs +0 -1
  9. package/bin/pi-web-ui.mjs +56 -444
  10. package/deploy/nginx-subpath.conf +0 -33
  11. package/deploy/pi-web-ui.service +0 -20
  12. package/dist/server/agent-formatters.js +4 -38
  13. package/dist/server/agent-service-daemon.js +160 -374
  14. package/dist/server/agent-service.js +875 -2978
  15. package/dist/server/approval-audit.js +2 -23
  16. package/dist/server/approval-default-rules.js +0 -6
  17. package/dist/server/approval-rules.js +7 -105
  18. package/dist/server/ask-user-question-tool.js +1 -12
  19. package/dist/server/atomic-file.js +33 -5
  20. package/dist/server/attachment-store.js +0 -36
  21. package/dist/server/attachments.js +3 -112
  22. package/dist/server/auth-cookie.js +0 -21
  23. package/dist/server/bash-tool.js +1 -32
  24. package/dist/server/bg-servers.js +0 -96
  25. package/dist/server/browser-page-tool.js +11 -62
  26. package/dist/server/builtin-modules.js +7 -0
  27. package/dist/server/canvas/canvas-agent-tool.js +58 -47
  28. package/dist/server/canvas/canvas-cards.js +0 -14
  29. package/dist/server/canvas/canvas-dispatch.js +7 -4
  30. package/dist/server/canvas/canvas-orchestrator.js +167 -181
  31. package/dist/server/canvas/canvas-runtime-messages.js +30 -0
  32. package/dist/server/canvas/canvas-scheduled-task.js +0 -3
  33. package/dist/server/canvas/canvas-scheduler.js +5 -7
  34. package/dist/server/canvas/canvas-store.js +24 -35
  35. package/dist/server/canvas/canvas-validation.js +17 -14
  36. package/dist/server/canvas/canvas-workspace.js +26 -30
  37. package/dist/server/canvas/pstack-skills-data.js +0 -5
  38. package/dist/server/claim-files-tool.js +1 -15
  39. package/dist/server/claim-store.js +5 -49
  40. package/dist/server/client-id-utils.js +0 -16
  41. package/dist/server/client-state.js +6 -213
  42. package/dist/server/communicate-tool.js +0 -3
  43. package/dist/server/compact-context-tool.js +0 -30
  44. package/dist/server/compacted-history.js +0 -35
  45. package/dist/server/compaction-instructions.js +0 -13
  46. package/dist/server/compaction-markers.js +3 -76
  47. package/dist/server/compaction-state.js +0 -21
  48. package/dist/server/composer-drafts.js +0 -34
  49. package/dist/server/context-budget-runner.js +0 -11
  50. package/dist/server/context-budget.js +1 -70
  51. package/dist/server/context-evidence.js +0 -14
  52. package/dist/server/context-usage.js +0 -12
  53. package/dist/server/control-socket.js +4 -48
  54. package/dist/server/conversation-communication.js +0 -10
  55. package/dist/server/conversation-identity.js +0 -1
  56. package/dist/server/conversation-read-tool.js +0 -58
  57. package/dist/server/conversation-tool-names.js +0 -1
  58. package/dist/server/conversation-tool.js +0 -1
  59. package/dist/server/conversation-touches.js +4 -75
  60. package/dist/server/dangling-tools.js +0 -82
  61. package/dist/server/delegate-mode.js +0 -36
  62. package/dist/server/delegate-task.js +2 -28
  63. package/dist/server/device-center/approval-summary.js +0 -1
  64. package/dist/server/device-center/bot-catalog.js +0 -3
  65. package/dist/server/device-center/bot-execution.js +0 -8
  66. package/dist/server/device-center/bot-presets.js +0 -1
  67. package/dist/server/device-center/bots.js +0 -1
  68. package/dist/server/device-center/collab-service.js +1 -3
  69. package/dist/server/device-center/collab-tool.js +0 -10
  70. package/dist/server/device-center/connector.js +21 -11
  71. package/dist/server/device-center/delivery-authority.js +0 -3
  72. package/dist/server/device-center/delivery-subject.js +0 -1
  73. package/dist/server/device-center/desktop-linux.js +3 -15
  74. package/dist/server/device-center/desktop-native.js +1 -10
  75. package/dist/server/device-center/desktop-page.js +2 -3
  76. package/dist/server/device-center/desktop-setup.js +1 -3
  77. package/dist/server/device-center/desktop.js +1 -7
  78. package/dist/server/device-center/device-integration.js +1 -27
  79. package/dist/server/device-center/device-lan-access.js +403 -0
  80. package/dist/server/device-center/device-lan.js +484 -0
  81. package/dist/server/device-center/device-portals.js +0 -3
  82. package/dist/server/device-center/execution-failure.js +0 -2
  83. package/dist/server/device-center/execution-guides.js +0 -1
  84. package/dist/server/device-center/execution-instructions.js +0 -1
  85. package/dist/server/device-center/execution-settings.js +0 -1
  86. package/dist/server/device-center/execution-system-prompt.js +0 -3
  87. package/dist/server/device-center/execution-workspace.js +1 -4
  88. package/dist/server/device-center/executor.js +0 -27
  89. package/dist/server/device-center/file-sync-paths.js +0 -5
  90. package/dist/server/device-center/file-sync.js +0 -10
  91. package/dist/server/device-center/group-context-delta.js +0 -8
  92. package/dist/server/device-center/group-context-message.js +0 -14
  93. package/dist/server/device-center/group-context.js +0 -19
  94. package/dist/server/device-center/group-events.js +0 -2
  95. package/dist/server/device-center/group-plan-guard.js +1 -35
  96. package/dist/server/device-center/group-router-runtime.js +182 -0
  97. package/dist/server/device-center/group-router-worker.js +178 -0
  98. package/dist/server/device-center/group-router.js +359 -0
  99. package/dist/server/device-center/hub-auth.js +24 -2
  100. package/dist/server/device-center/hub-conversations.js +0 -12
  101. package/dist/server/device-center/hub-deliveries.js +0 -1
  102. package/dist/server/device-center/hub-integration.js +0 -8
  103. package/dist/server/device-center/hub-locks.js +1 -5
  104. package/dist/server/device-center/hub-mobile.js +147 -0
  105. package/dist/server/device-center/hub-orchestration.js +400 -0
  106. package/dist/server/device-center/hub-page.js +25 -7
  107. package/dist/server/device-center/hub-setup.js +0 -6
  108. package/dist/server/device-center/hub-transaction-log.js +0 -22
  109. package/dist/server/device-center/hub-upgrade.js +162 -0
  110. package/dist/server/device-center/hub-webhooks.js +1 -3
  111. package/dist/server/device-center/hub.js +210 -86
  112. package/dist/server/device-center/human-interaction.js +1 -4
  113. package/dist/server/device-center/integration-errors.js +0 -2
  114. package/dist/server/device-center/integration-verification.js +0 -2
  115. package/dist/server/device-center/local-hub.js +0 -2
  116. package/dist/server/device-center/local-publication.js +1 -8
  117. package/dist/server/device-center/local-verification-job.js +0 -2
  118. package/dist/server/device-center/local-verification.js +0 -1
  119. package/dist/server/device-center/local.js +267 -39
  120. package/dist/server/device-center/main.js +14 -1
  121. package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
  122. package/dist/server/device-center/native-desktop/macos.js +0 -1
  123. package/dist/server/device-center/native-desktop/windows.js +0 -1
  124. package/dist/server/device-center/partition-log.js +0 -31
  125. package/dist/server/device-center/path-portal.js +42 -12
  126. package/dist/server/device-center/publication-journal.js +0 -7
  127. package/dist/server/device-center/publish-intent.js +0 -5
  128. package/dist/server/device-center/relay.js +85 -30
  129. package/dist/server/device-center/report-upload.js +0 -1
  130. package/dist/server/device-center/runtime.js +1 -18
  131. package/dist/server/device-center/store.js +13 -33
  132. package/dist/server/device-center/task-context-budget.js +0 -3
  133. package/dist/server/device-center/task-error.js +0 -1
  134. package/dist/server/device-center/task-journal.js +6 -23
  135. package/dist/server/device-center/task-outcome.js +0 -13
  136. package/dist/server/device-center/task-plan.js +0 -1
  137. package/dist/server/device-center/task-progress.js +0 -16
  138. package/dist/server/device-center/task-recovery.js +5 -88
  139. package/dist/server/device-center/task-report-outbox.js +0 -4
  140. package/dist/server/device-center/task-report.js +2 -10
  141. package/dist/server/device-center/task-scheduler.js +1 -35
  142. package/dist/server/device-center/task-settlement.js +0 -18
  143. package/dist/server/device-center/task-state.js +0 -12
  144. package/dist/server/device-center/task-workspace.js +0 -50
  145. package/dist/server/device-center/transfer-stream.js +5 -45
  146. package/dist/server/device-center/transfers.js +2 -10
  147. package/dist/server/device-center/verification-limits.js +0 -1
  148. package/dist/server/device-center/work-contract.js +1 -73
  149. package/dist/server/device-center/work-items.js +317 -0
  150. package/dist/server/device-center/workspaces.js +0 -1
  151. package/dist/server/dispatch-domain-handlers.js +190 -32
  152. package/dist/server/dispatch-plugin-handlers.js +2 -19
  153. package/dist/server/dsh/dsh-agent-service.js +69 -599
  154. package/dist/server/dsh/dsh-client.js +7 -111
  155. package/dist/server/dsh/dsh-market-service.js +4 -25
  156. package/dist/server/dsh/dsh-serialize.js +0 -49
  157. package/dist/server/dsh/dsh-sessions.js +0 -37
  158. package/dist/server/dsh/dsh-usage.js +0 -37
  159. package/dist/server/dsh/preset-clones.js +1 -65
  160. package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
  161. package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
  162. package/dist/server/dsh/runtime/launcher.mjs +2 -53
  163. package/dist/server/dsh/runtime/override.patch.yml +0 -29
  164. package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
  165. package/dist/server/durable/durable-agent-service.js +5 -23
  166. package/dist/server/durable/durable-driver.js +12 -73
  167. package/dist/server/durable/durable-event-projector.js +1 -50
  168. package/dist/server/durable/durable-loader.js +0 -12
  169. package/dist/server/durable/durable-models.js +11 -80
  170. package/dist/server/durable/durable-storage.js +1 -17
  171. package/dist/server/durable/durable-tools.js +2 -20
  172. package/dist/server/durable/index.js +0 -3
  173. package/dist/server/edit-soft-tool.js +2 -81
  174. package/dist/server/engine-capabilities.js +0 -13
  175. package/dist/server/engine-catalog.js +74 -0
  176. package/dist/server/engine-cli.js +89 -0
  177. package/dist/server/engine-probe.js +35 -217
  178. package/dist/server/ensure-bash.js +2 -28
  179. package/dist/server/eval-tool.js +1 -50
  180. package/dist/server/evidence-tool-hooks.js +0 -2
  181. package/dist/server/file-archives.js +0 -10
  182. package/dist/server/file-save.js +1 -12
  183. package/dist/server/file-transfer-routes.js +0 -11
  184. package/dist/server/files-service.js +18 -271
  185. package/dist/server/global-loader.js +9 -89
  186. package/dist/server/goal-evidence.js +1 -35
  187. package/dist/server/goal-review-gate.js +0 -58
  188. package/dist/server/goal-service.js +19 -422
  189. package/dist/server/hashline-engine.js +8 -112
  190. package/dist/server/host-guard.js +0 -24
  191. package/dist/server/host-metrics.js +0 -6
  192. package/dist/server/http-proxy.js +1 -7
  193. package/dist/server/i18n.js +5 -72
  194. package/dist/server/icon-svg.js +0 -15
  195. package/dist/server/index.js +177 -680
  196. package/dist/server/json-utils.js +0 -12
  197. package/dist/server/launch-origin.js +0 -44
  198. package/dist/server/left-panel-running.js +0 -9
  199. package/dist/server/load-timing.js +1 -4
  200. package/dist/server/load-tools-tool.js +0 -20
  201. package/dist/server/locales.js +1 -46
  202. package/dist/server/lsp-tool.js +13 -126
  203. package/dist/server/managed.js +0 -48
  204. package/dist/server/marker-service.js +1 -22
  205. package/dist/server/markers/builtins/action.js +0 -19
  206. package/dist/server/markers/builtins/notify.js +1 -9
  207. package/dist/server/markers/builtins/rename.js +0 -13
  208. package/dist/server/markers/index.js +0 -3
  209. package/dist/server/markers/marker.js +0 -13
  210. package/dist/server/markers/registry.js +0 -3
  211. package/dist/server/markers/store.js +1 -12
  212. package/dist/server/market-service.js +7 -43
  213. package/dist/server/mcp-agent-tool.js +0 -10
  214. package/dist/server/mcp-bridge.js +6 -138
  215. package/dist/server/mcp-hot-reload.js +0 -25
  216. package/dist/server/mcp-manager.js +2 -44
  217. package/dist/server/mcp-oauth-login.js +0 -2
  218. package/dist/server/mcp-oauth-ui.js +1 -4
  219. package/dist/server/mcp-oauth.js +5 -79
  220. package/dist/server/mcp-project-runtime.js +0 -4
  221. package/dist/server/message-deletion.js +0 -2
  222. package/dist/server/message-entry-resolver.js +0 -8
  223. package/dist/server/message-window.js +0 -71
  224. package/dist/server/mobile-notification-events.js +16 -0
  225. package/dist/server/mobile-origin.js +79 -0
  226. package/dist/server/mobile-push.js +523 -0
  227. package/dist/server/model-admin.js +19 -358
  228. package/dist/server/model-enrich.js +0 -19
  229. package/dist/server/model-resolver.js +2 -61
  230. package/dist/server/native-cli-discovery.js +115 -0
  231. package/dist/server/native-cli-model.js +71 -0
  232. package/dist/server/native-cli-references.js +214 -0
  233. package/dist/server/native-cli-remote-cleanup.js +58 -0
  234. package/dist/server/native-cli-remote-files.js +282 -0
  235. package/dist/server/native-cli-routes.js +68 -0
  236. package/dist/server/native-cli-runtime.js +1 -0
  237. package/dist/server/native-cli-session-hooks.js +170 -0
  238. package/dist/server/native-cli-session.js +585 -0
  239. package/dist/server/native-cli-state.js +82 -0
  240. package/dist/server/native-cli.js +210 -0
  241. package/dist/server/net-guard.js +9 -71
  242. package/dist/server/office-parse.js +0 -50
  243. package/dist/server/orphan-manager.js +0 -18
  244. package/dist/server/patch-bash-process.js +0 -4
  245. package/dist/server/patch-executable-lookup.js +0 -77
  246. package/dist/server/patch-node-pty.js +3 -43
  247. package/dist/server/patch-remote-catalog.js +1 -32
  248. package/dist/server/patch-tool.js +0 -15
  249. package/dist/server/payload-limits.js +0 -5
  250. package/dist/server/pending-question.js +0 -5
  251. package/dist/server/permission-preset.js +4 -33
  252. package/dist/server/persona-chain.js +0 -26
  253. package/dist/server/pkg-info.js +1 -17
  254. package/dist/server/plan-manager.js +2 -49
  255. package/dist/server/plan-mode.js +0 -97
  256. package/dist/server/plan-update-tool.js +1 -15
  257. package/dist/server/plugin-api-catalog.js +6 -4
  258. package/dist/server/plugin-assets.js +1 -35
  259. package/dist/server/plugin-bundled.js +68 -0
  260. package/dist/server/plugin-catalog-sync.js +0 -37
  261. package/dist/server/plugin-catalog.js +13 -67
  262. package/dist/server/plugin-chat-attachments.js +0 -1
  263. package/dist/server/plugin-conversation-view.js +0 -20
  264. package/dist/server/plugin-dom.js +1 -23
  265. package/dist/server/plugin-facilities.js +4 -115
  266. package/dist/server/plugin-grants.js +2 -90
  267. package/dist/server/plugin-install-spec.js +0 -43
  268. package/dist/server/plugin-installer.js +34 -75
  269. package/dist/server/plugin-llm.js +4 -38
  270. package/dist/server/plugin-manifest-validate.js +0 -31
  271. package/dist/server/plugin-permissions.js +1 -24
  272. package/dist/server/plugin-project.js +7 -129
  273. package/dist/server/plugin-removal.js +1 -8
  274. package/dist/server/plugin-schedule.js +1 -38
  275. package/dist/server/plugin-secrets.js +3 -16
  276. package/dist/server/plugin-tool-guard.js +1 -28
  277. package/dist/server/plugin-ui-slots.js +0 -4
  278. package/dist/server/plugin-updater.js +15 -90
  279. package/dist/server/plugins.js +71 -619
  280. package/dist/server/present-files-tool.js +0 -57
  281. package/dist/server/preset-fields.js +9 -62
  282. package/dist/server/preset-plugin-dependencies.js +0 -2
  283. package/dist/server/preset-share.js +3 -172
  284. package/dist/server/process-utils.js +4 -80
  285. package/dist/server/prompt-assembler.js +2 -30
  286. package/dist/server/prompt-base-store.js +0 -47
  287. package/dist/server/prompt-composer.js +21 -98
  288. package/dist/server/prompt-templates.js +0 -2
  289. package/dist/server/protocol-version.js +1 -11
  290. package/dist/server/protocol.js +0 -5
  291. package/dist/server/queue-modes.js +0 -3
  292. package/dist/server/queue-utils.js +0 -40
  293. package/dist/server/quick-ask-context.js +384 -0
  294. package/dist/server/quick-ask-settings.js +34 -1
  295. package/dist/server/quick-ask.js +123 -27
  296. package/dist/server/read-tool.js +0 -65
  297. package/dist/server/reasoning-registry.js +1 -29
  298. package/dist/server/remote-cli-persistence.js +373 -0
  299. package/dist/server/remote-native-cli.js +78 -0
  300. package/dist/server/remote-ssh-service.js +481 -190
  301. package/dist/server/request-context.js +0 -9
  302. package/dist/server/resolve-global-sdk.js +0 -26
  303. package/dist/server/sandbox-data.js +0 -1
  304. package/dist/server/sandbox-engines.js +0 -1
  305. package/dist/server/sandbox-runtime-gate.js +0 -3
  306. package/dist/server/sandbox-service.js +0 -41
  307. package/dist/server/sandbox-tool.js +0 -20
  308. package/dist/server/schedule-agent-tool.js +2 -31
  309. package/dist/server/scheduler-tasks.js +3 -54
  310. package/dist/server/scm-commitmsg.js +0 -53
  311. package/dist/server/scm.js +3 -48
  312. package/dist/server/sdk-builtin-extensions.js +2 -29
  313. package/dist/server/sdk-origin.js +0 -45
  314. package/dist/server/serialize.js +2 -92
  315. package/dist/server/server-config.js +0 -11
  316. package/dist/server/session-branch.js +1 -87
  317. package/dist/server/session-list-scan.js +17 -25
  318. package/dist/server/session-open.js +2 -26
  319. package/dist/server/session-parser.js +1 -55
  320. package/dist/server/session-scan.js +1 -17
  321. package/dist/server/session-search.js +0 -56
  322. package/dist/server/settings-service.js +11 -126
  323. package/dist/server/setup-config.js +0 -2
  324. package/dist/server/setup-page.js +0 -9
  325. package/dist/server/skill-content-filler.js +0 -17
  326. package/dist/server/skill-discovery.js +5 -92
  327. package/dist/server/skill-maintenance.js +1 -28
  328. package/dist/server/skill-tool.js +0 -30
  329. package/dist/server/slash-commands.js +5 -50
  330. package/dist/server/soft-cap.js +0 -42
  331. package/dist/server/startup-banner.js +0 -8
  332. package/dist/server/subagent-handoff.js +0 -11
  333. package/dist/server/subagent-helpers.js +2 -17
  334. package/dist/server/subagent-notify.js +0 -19
  335. package/dist/server/subagent-security-gate.js +0 -50
  336. package/dist/server/subagent-task.js +0 -9
  337. package/dist/server/subagent-templates-hant.js +0 -10
  338. package/dist/server/subagent-templates.js +3 -103
  339. package/dist/server/subagents.js +1 -87
  340. package/dist/server/system-screenshot-windows.js +259 -0
  341. package/dist/server/system-screenshot.js +77 -0
  342. package/dist/server/tabs.js +3 -48
  343. package/dist/server/terminals.js +559 -586
  344. package/dist/server/text-quote.js +0 -12
  345. package/dist/server/text-sniff.js +2 -52
  346. package/dist/server/themes.js +2 -41
  347. package/dist/server/tool-approval.js +0 -47
  348. package/dist/server/tool-guards.js +0 -90
  349. package/dist/server/tool-host-factories.js +1 -16
  350. package/dist/server/tool-info.js +0 -13
  351. package/dist/server/tool-manager.js +1 -229
  352. package/dist/server/tool-overrides.js +1 -46
  353. package/dist/server/tool-prompt-overrides.js +1 -30
  354. package/dist/server/tool-prompts.js +0 -14
  355. package/dist/server/tool-signature.js +0 -25
  356. package/dist/server/transcript-prepare.js +1 -19
  357. package/dist/server/tts-routes.js +58 -0
  358. package/dist/server/tts-service.js +106 -0
  359. package/dist/server/tts-system.js +160 -0
  360. package/dist/server/turn-timing.js +0 -1
  361. package/dist/server/unauthorized-page.js +0 -8
  362. package/dist/server/universal/driver-base.js +2 -31
  363. package/dist/server/universal/drivers/claude-code.js +12 -172
  364. package/dist/server/universal/drivers/codex.js +12 -35
  365. package/dist/server/universal/drivers/mock-driver.js +1 -11
  366. package/dist/server/universal/index.js +0 -3
  367. package/dist/server/universal/session-store.js +4 -21
  368. package/dist/server/universal/universal-attachments.js +2 -36
  369. package/dist/server/universal/universal-service.js +5 -24
  370. package/dist/server/universal/universal-session.js +26 -148
  371. package/dist/server/universal/universal-types.js +0 -3
  372. package/dist/server/update-check.js +6 -182
  373. package/dist/server/uploads.js +4 -43
  374. package/dist/server/virtual-tui.js +2 -27
  375. package/dist/server/vision-bridge.js +0 -27
  376. package/dist/server/wait-subscription-scan.js +13 -115
  377. package/dist/server/webui-context.js +2 -87
  378. package/dist/server/workspace-handle.js +1 -56
  379. package/dist/server/workspace-snapshot.js +7 -113
  380. package/dist/server/worktree-service.js +2 -53
  381. package/dist/server/worktree-tool.js +0 -11
  382. package/dist/server/ws-client-id.js +0 -18
  383. package/dist/server/ws-pending-queue.js +0 -7
  384. package/dist/server/ws-unknown-types.js +0 -17
  385. package/docs/README.md +24 -17
  386. package/docs/architecture-plugins.md +37 -1
  387. package/docs/device-center.md +28 -2
  388. package/docs/device-desktop.md +3 -3
  389. package/docs/group-orchestration.md +142 -0
  390. package/docs/hub-upgrade-release-testing.md +46 -0
  391. package/extensions/webui.ts +3 -74
  392. package/package.json +7 -3
  393. package/plugin-sdk/README.md +6 -0
  394. package/plugin-sdk/client-utils.mjs +0 -7
  395. package/plugin-sdk/client.d.ts +0 -1
  396. package/plugin-sdk/client.mjs +1 -31
  397. package/plugin-sdk/import-check.mjs +4 -51
  398. package/plugin-sdk/index.d.ts +120 -119
  399. package/plugin-sdk/index.mjs +0 -6
  400. package/plugin-sdk/ssh-host-trust.mjs +0 -12
  401. package/plugin-sdk/testing.d.ts +0 -1
  402. package/plugin-sdk/testing.mjs +31 -86
  403. package/plugins/catalog.json +52 -4
  404. package/plugins/superagent/README.md +110 -0
  405. package/plugins/superagent/client/entry.mjs +21 -0
  406. package/plugins/superagent/index.mjs +8 -0
  407. package/plugins/superagent/main.mjs +218 -0
  408. package/plugins/superagent/manifest.json +15 -0
  409. package/plugins/superagent/server.mjs +572 -0
  410. package/plugins/superagent/style.css +167 -0
  411. package/themes/aetheris.css +1 -31
  412. package/themes/ayu-light.css +0 -1
  413. package/themes/bases/flow-base.css +2 -83
  414. package/themes/bases/obsidian-base.css +2 -37
  415. package/themes/bases/statusbar-flat-base.css +0 -1
  416. package/themes/bases/zhujian-base.css +0 -63
  417. package/themes/bases/zhupi-base.css +0 -64
  418. package/themes/catppuccin-latte.css +0 -1
  419. package/themes/catppuccin.css +0 -1
  420. package/themes/claude-code-dark.css +0 -1
  421. package/themes/codex.css +0 -1
  422. package/themes/dark-teal.css +22 -54
  423. package/themes/everforest-light.css +0 -1
  424. package/themes/flow-cristallo.css +1 -9
  425. package/themes/flow-ink.css +1 -10
  426. package/themes/flow-light.css +1 -10
  427. package/themes/flow-obsidian.css +1 -10
  428. package/themes/flow-zurich.css +1 -10
  429. package/themes/flow.css +1 -9
  430. package/themes/geist.css +0 -1
  431. package/themes/gruvbox-light.css +0 -1
  432. package/themes/kanagawa-lotus.css +0 -1
  433. package/themes/md-preview.css +1 -2
  434. package/themes/mist.css +0 -1
  435. package/themes/nord.css +0 -1
  436. package/themes/one-dark.css +0 -1
  437. package/themes/paper.css +0 -1
  438. package/themes/rose-pine-dawn.css +0 -1
  439. package/themes/sakura.css +0 -1
  440. package/themes/solarized-light.css +0 -1
  441. package/themes/tokyo-night.css +0 -1
  442. package/themes/translucent.css +4 -35
  443. package/themes/transparent.css +4 -41
  444. package/themes/vs-code-dark.css +0 -1
  445. package/themes/wallpaper-flow.css +3 -17
  446. package/themes/wallpaper-obsidian.css +1 -4
  447. package/themes/white.css +0 -1
  448. package/web/dist/.build-assets.json +1 -1
  449. package/web/dist/assets/{BgTasksModal-BjNRIUIc.js → BgTasksModal-D-x7kA63.js} +1 -1
  450. package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
  451. package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
  452. package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
  453. package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
  454. package/web/dist/assets/{Dropdown-CQtstPGv.js → Dropdown-CTgVLUbp.js} +1 -1
  455. package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
  456. package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
  457. package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
  458. package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
  459. package/web/dist/assets/{HintTip-ChTW8o1m.js → HintTip-Da6qc566.js} +1 -1
  460. package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
  461. package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
  462. package/web/dist/assets/{PiSetupModal-BX5rUuoI.js → PiSetupModal-DZKY5Wiw.js} +1 -1
  463. package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
  464. package/web/dist/assets/{SCMPanel-DPAyY2sW.js → SCMPanel-CuEgzAlO.js} +2 -2
  465. package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
  466. package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
  467. package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
  468. package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
  469. package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
  470. package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
  471. package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
  472. package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
  473. package/web/dist/assets/index-CQc3VrWa.css +1 -0
  474. package/web/dist/assets/index-D_AGu4Zv.js +404 -0
  475. package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
  476. package/web/dist/assets/{remote-ssh-client-Dzi-eEyE.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
  477. package/web/dist/assets/theme-DGL7hLUs.js +1 -0
  478. package/web/dist/index.html +11 -10
  479. package/web/dist/sw.js +15 -61
  480. package/web/public/sw.js +14 -60
  481. package/web/dist/assets/BgTasksModal-C0zuU8FE.js +0 -1
  482. package/web/dist/assets/CanvasStudio-BWvdmJ0M.js +0 -1579
  483. package/web/dist/assets/CanvasStudio-VQFjmTGq.js +0 -1579
  484. package/web/dist/assets/DeviceCenter-DI9_0aBB.js +0 -3
  485. package/web/dist/assets/DeviceCenter-DsNtXqzY.js +0 -3
  486. package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +0 -1
  487. package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +0 -1
  488. package/web/dist/assets/DeviceGroups-CP7CcyPD.js +0 -1
  489. package/web/dist/assets/FilePreview-BMB2tNyT.js +0 -2
  490. package/web/dist/assets/FilePreview-RGFQUbJo.js +0 -2
  491. package/web/dist/assets/GlobalSearchModal-BM5wxiqU.js +0 -1
  492. package/web/dist/assets/GlobalSearchModal-DGv_WINq.js +0 -1
  493. package/web/dist/assets/GroupConversation-B7SnuXj1.js +0 -61
  494. package/web/dist/assets/GroupConversation-Dda69q-2.js +0 -61
  495. package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +0 -2
  496. package/web/dist/assets/ModelConfigModal-yqeadyab.js +0 -2
  497. package/web/dist/assets/ProviderOAuthControls-DY4SCfXg.js +0 -1
  498. package/web/dist/assets/SCMPanel-C4KbQvvK.js +0 -2
  499. package/web/dist/assets/SettingsModal-DxZp6D_g.js +0 -32
  500. package/web/dist/assets/SettingsModal-WhQzaOPt.js +0 -32
  501. package/web/dist/assets/TerminalPanel-D4By_RVc.js +0 -3
  502. package/web/dist/assets/TerminalPanel-lZw8-i3j.js +0 -3
  503. package/web/dist/assets/TuiOverlayModal-C3pAVuC8.js +0 -1
  504. package/web/dist/assets/TuiOverlayModal-D7_rEXcJ.js +0 -1
  505. package/web/dist/assets/app-globals-KqOVtmp1.js +0 -123
  506. package/web/dist/assets/canvas-client-BY6ojmle.js +0 -1
  507. package/web/dist/assets/desktop-CV6KKp9R.js +0 -1
  508. package/web/dist/assets/index-BawF7ZP5.js +0 -397
  509. package/web/dist/assets/index-BoGCoq5X.js +0 -397
  510. package/web/dist/assets/index-CVW9FoY2.css +0 -1
  511. package/web/dist/assets/plugin-host-Dn8Dd6SC.js +0 -1
  512. package/web/dist/assets/theme-D_bihpdN.js +0 -1
@@ -1,10 +1,3 @@
1
- /**
2
- * Files service — 从 agent-service.ts 抽出(文件树列目录 / 预览读写 / 路径补全 /
3
- * SCM 只读查询 / 目录与 git-dir watcher)。
4
- *
5
- * 全部为无状态 fs 操作 + 两个自持的 watcher(当前列出目录、git dir),
6
- * 经 FilesHost 回调与 ClientSession 解耦。
7
- */
8
1
  import { Dirent, existsSync, mkdirSync, readFileSync, statSync, watch } from "node:fs";
9
2
  import { saveFilePreservingMetadata } from "./file-save.js";
10
3
  import { isUploadDataTooLong, uploadLimitBytes } from "./payload-limits.js";
@@ -17,11 +10,7 @@ import { extractOfficeText, isOfficeFile, OFFICE_MAX_FILE_BYTES } from "./office
17
10
  import { gitDirOf, isNotRepoError, scmStatus, scmHistory, scmFileDiff, scmCommitDetail } from "./scm.js";
18
11
  import { getGlobalRemoteSshService, isRemoteWorkspaceUri, parseRemoteWorkspaceUri, resolveRemoteWorkspacePath, } from "./remote-ssh-service.js";
19
12
  export const IS_WIN32 = process.platform === "win32";
20
- /** 机器根虚拟路径:工作区「上一级」到达此处,列出所有盘符(Windows)/ "/"(posix)。
21
- * 这是 wire 字面量,前端 web/src/components/{RightPanel,FooterBar}.tsx 里同值使用。 */
22
13
  export const MACHINE_ROOT = "@root";
23
- /** 桌面目录(wire 格式):存在且为目录才返回,否则空串(前端不渲染 🖥️)。
24
- * Linux 优先读 XDG user-dirs(中文环境可能是 ~/桌面),其余平台即 ~/Desktop。 */
25
14
  export function desktopDirWire(homeWire) {
26
15
  const cands = [];
27
16
  if (process.platform === "linux") {
@@ -34,9 +23,7 @@ export function desktopDirWire(homeWire) {
34
23
  cands.push(dir);
35
24
  }
36
25
  }
37
- catch {
38
- // 无 XDG 配置就回落 ~/Desktop
39
- }
26
+ catch { }
40
27
  }
41
28
  cands.push(`${homeWire}/Desktop`);
42
29
  for (const c of cands) {
@@ -44,33 +31,20 @@ export function desktopDirWire(homeWire) {
44
31
  if (statSync(wireToAbs(c)).isDirectory())
45
32
  return c;
46
33
  }
47
- catch {
48
- // 不存在就试下一个
49
- }
34
+ catch { }
50
35
  }
51
36
  return "";
52
37
  }
53
- /** wire 路径统一用 "/"。绝对 = posix "/...";win32 还有 "C:/..." / 裸 "C:"。
54
- * 机器浏览(越过工作区根换盘符)发送这些路径;工作区相对树不会产生它们(Windows
55
- * 文件名不能含 ":",相对路径经 relative() 归一化后也不以 "/" 开头)。
56
- * win32 还必须把盘符相对路径("D:x",冒号后无分隔符 —— resolve 会落到该盘的
57
- * 当前目录)与 UNC("\\host\share";"//host/share" 已被上面的 "/" 前缀覆盖)
58
- * 判为绝对:这些形态若被当工作区相对路径处理,会在跨盘/UNC 下绕过 ".." 检查
59
- * 逃出工作区。posix 上 "C:x" 是合法文件名,故盘符检查必须限定在 win32。 */
60
38
  export function isAbsoluteWirePath(p) {
61
39
  if (p === MACHINE_ROOT || p.startsWith("/") || p.startsWith("\\\\"))
62
40
  return true;
63
41
  return IS_WIN32 && /^[A-Za-z]:/.test(p);
64
42
  }
65
- /** 去掉结尾 "/"(保留 posix 根 "/" 本身),归一成规范的 wire 形式。前端面包屑
66
- * 不产生结尾斜杠,这里只对补全/直接输入做防御性清理。 */
67
43
  export function normWirePath(p) {
68
44
  if (p.endsWith("/") && p !== "/")
69
45
  return p.replace(/\/+$/, "") || "/";
70
46
  return p;
71
47
  }
72
- /** wire 绝对路径("C:/Users/x" / "/Users/x" / "C:")→ 原生绝对路径。
73
- * 裸盘符根("C:")在 win32 的 resolve 里会落到「C: 上的当前目录」,必须显式转 "C:\\"。 */
74
48
  export function wireToAbs(wire) {
75
49
  const w = normWirePath(wire);
76
50
  if (IS_WIN32) {
@@ -80,7 +54,6 @@ export function wireToAbs(wire) {
80
54
  }
81
55
  return resolve(w);
82
56
  }
83
- /** 机器浏览模式下某目录的父级 wire 路径:盘符根("C:")→ 机器根;posix "/" 无父级。 */
84
57
  export function absoluteParent(wire) {
85
58
  const s = normWirePath(wire);
86
59
  if (s === "" || s === MACHINE_ROOT || s === "/")
@@ -89,13 +62,11 @@ export function absoluteParent(wire) {
89
62
  if (i < 0)
90
63
  return /^[A-Za-z]:$/.test(s) ? MACHINE_ROOT : null;
91
64
  if (i === 0)
92
- return "/"; // posix "/a" → "/"
65
+ return "/";
93
66
  return s.slice(0, i);
94
67
  }
95
- /** 预览只读文件前 512KB。 */
96
68
  export const MAX_PREVIEW_BYTES = 512 * 1024;
97
69
  export { MAX_UPLOAD_BYTES, MAX_UPLOAD_BASE64_CHARS, WS_MAX_PAYLOAD_BYTES, isUploadDataTooLong, } from "./payload-limits.js";
98
- // mac/linux: hide build & dependency noise (original behavior).
99
70
  const IGNORED_ENTRIES = new Set([
100
71
  "node_modules",
101
72
  ".git",
@@ -113,51 +84,17 @@ const IGNORED_ENTRIES = new Set([
113
84
  ".DS_Store",
114
85
  "Thumbs.db",
115
86
  ]);
116
- // Windows: the file tree is the primary way to navigate a project, so only
117
- // hide what would flood or destabilize the panel (dependency trees, VCS
118
- // internals, session data) plus pure junk. Build output (dist/.next/…) and
119
- // local env dirs (venv/__pycache__/…) stay visible — "所有文件可查看".
120
87
  const IGNORED_ENTRIES_WIN = new Set(["node_modules", ".git", ".pi-web", ".DS_Store", "Thumbs.db", "desktop.ini"]);
121
- /** The ignore set for the current platform — keeps win/posix lists separate. */
122
88
  function ignoredEntries() {
123
89
  return IS_WIN32 ? IGNORED_ENTRIES_WIN : IGNORED_ENTRIES;
124
90
  }
125
- /**
126
- * Resolve a workspace-relative path against a root, refusing traversal
127
- * (".." escapes). Returns { abs, rel } — rel is normalized and slash-
128
- * separated — or null when the path leaves the workspace.
129
- */
130
91
  export function workspacePath(root, raw) {
131
92
  const abs = resolve(root, raw);
132
93
  const rawRel = relative(root, abs);
133
- // 只查 ".." 拦不住 Windows 的跨盘/UNC:relative("C:/a","D:/x") 与
134
- // relative("C:/a","//h/s") 返回绝对路径("D:\x"、"\\h\s\"),不以 ".." 开头;
135
- // 盘符相对路径("D:x")经 resolve 落到该盘当前目录后也归此形 —— 必须同时
136
- // 拒绝 isAbsolute 的结果,否则 "D:x" 这类输入可逃出工作区根。
137
94
  if (rawRel.startsWith("..") || rawRel.includes(`${sep}..`) || isAbsolute(rawRel))
138
95
  return null;
139
- // Normalize to forward slashes: the wire protocol and the frontend always
140
- // use "/", but relative() returns "\\" on Windows.
141
96
  return { abs, rel: rawRel.split(sep).join("/") };
142
97
  }
143
- /**
144
- * Read a directory for the file panel. The two platforms intentionally use
145
- * different strategies — do NOT unify them:
146
- *
147
- * darwin/linux (posix): hide build/dependency noise, small cap; a listing
148
- * failure (deleted/renamed dir → ENOENT/ENOTDIR, permission → EACCES/EPERM)
149
- * degrades to an empty listing plus a notice chosen by errorCode — the server
150
- * must NEVER crash on a vanished directory (issue #74).
151
- *
152
- * win32: stability and completeness first, preview second. ACL-protected
153
- * system dirs (C:\$Recycle.Bin, Program Files internals, OneDrive placeholders)
154
- * throw EPERM/EACCES on open — that must not kill the panel, so it degrades
155
- * to an empty listing plus a warning. Directory symlinks/junctions are
156
- * followed (all platforms — Android/Termux's ~/storage/* entries are symlinks
157
- * too) so folder links stay navigable; broken links still show as files
158
- * instead of vanishing. The cap is 4x posix and truncation is reported
159
- * via `truncated` instead of happening silently.
160
- */
161
98
  async function readDirForUI(abs, rel) {
162
99
  const { join } = await import("node:path");
163
100
  const fs = await import("node:fs/promises");
@@ -168,12 +105,6 @@ async function readDirForUI(abs, rel) {
168
105
  dirents = await fs.readdir(abs, { withFileTypes: true });
169
106
  }
170
107
  catch (err) {
171
- // 任何 readdir 失败都降级为“空列表 + notice”,绝不向上抛:listFiles 以
172
- // fire-and-forget(void …)调用,未处理的 rejection 会成为 unhandled
173
- // rejection 直接杀掉整个服务进程(issue #74:目录被删除/改名后刷新即崩)。
174
- // 缺失(ENOENT/ENOTDIR)、权限拒绝(EACCES/EPERM)、系统 ACL 目录全部归此,
175
- // 文案由 listFiles 按 errorCode 分类:缺失 = 软提示“目录不存在”,
176
- // 权限/其余 = posix 硬错误 notice / win32 软提示(ACL 系统目录是常态)。
177
108
  const e = err;
178
109
  return { entries: [], truncated: false, error: e.message, errorCode: e.code };
179
110
  }
@@ -183,9 +114,6 @@ async function readDirForUI(abs, rel) {
183
114
  continue;
184
115
  let type;
185
116
  if (d.isSymbolicLink()) {
186
- // Symlinks (mklink /D reparse points on win32, but also the directory
187
- // links under Termux's ~/storage) are followed on ALL platforms so
188
- // folder links stay navigable; broken links still show as files.
189
117
  try {
190
118
  const st = await fs.stat(join(abs, d.name));
191
119
  type = st.isDirectory() ? "dir" : "file";
@@ -197,7 +125,6 @@ async function readDirForUI(abs, rel) {
197
125
  else {
198
126
  type = d.isDirectory() ? "dir" : "file";
199
127
  }
200
- // 机器浏览(绝对路径)下 rel 是绝对 wire 路径;posix 根 "/" 特殊处理避免 "//name"。
201
128
  const entryPath = rel === "" ? d.name : rel.endsWith("/") ? `${rel.slice(0, -1)}/${d.name}` : `${rel}/${d.name}`;
202
129
  const entry = {
203
130
  name: d.name,
@@ -214,9 +141,6 @@ async function readDirForUI(abs, rel) {
214
141
  out.length = MAX;
215
142
  return { entries: out, truncated };
216
143
  }
217
- /** dirent → FileEntry classification: directory symlinks are resolved via
218
- * stat() on ALL platforms (#262 — Termux's ~/storage/* entries are symlinks;
219
- * the directory-only cwd picker renders an empty list if they type as files). */
220
144
  async function classifyDirent(d, absDir) {
221
145
  const fs = await import("node:fs/promises");
222
146
  const { join } = await import("node:path");
@@ -226,7 +150,7 @@ async function classifyDirent(d, absDir) {
226
150
  type = (await fs.stat(join(absDir, d.name))).isDirectory() ? "dir" : "file";
227
151
  }
228
152
  catch {
229
- type = "file"; // broken link
153
+ type = "file";
230
154
  }
231
155
  }
232
156
  else {
@@ -236,25 +160,18 @@ async function classifyDirent(d, absDir) {
236
160
  }
237
161
  export class FilesService {
238
162
  host;
239
- // ---- 当前列出目录的 watcher ----
240
163
  fsWatcher = null;
241
164
  watchPath = null;
242
165
  watchTimer = null;
243
- /** Recursive-watch state (win32/darwin): one native recursive watcher on the
244
- * workspace root covers the WHOLE tree; watchPath just tracks which listed
245
- * directory file_changed should refresh. */
246
166
  recursiveWatcher = false;
247
167
  watchRoot = null;
248
- /** 已对哪个工作区根提示过「实时监听不可用,已回落轮询」——只提示一次。 */
249
168
  degradedNoticedFor = null;
250
- // ---- git dir watcher ----
251
169
  gitWatcher = null;
252
170
  gitWatchCwd = null;
253
171
  gitDirtyTimer = null;
254
172
  constructor(host) {
255
173
  this.host = host;
256
174
  }
257
- /** 机器根列目录(此电脑/盘符列表);posix 上就是根 "/"。 */
258
175
  async machineRootEntries() {
259
176
  const fsp = await import("node:fs/promises");
260
177
  if (IS_WIN32) {
@@ -266,15 +183,10 @@ export class FilesService {
266
183
  if (st.isDirectory())
267
184
  out.push({ name: drive, path: drive, type: "dir" });
268
185
  }
269
- catch {
270
- // 空口/未挂载盘符 —— 跳过
271
- }
186
+ catch { }
272
187
  }
273
188
  return out;
274
189
  }
275
- // Android/Termux: "/" itself is not listable (even `ls /` is denied),
276
- // so fall back to $HOME + shared storage as the machine-root landing
277
- // spots — otherwise machine browsing is a dead end on Android.
278
190
  try {
279
191
  await fsp.readdir("/");
280
192
  }
@@ -285,20 +197,14 @@ export class FilesService {
285
197
  await fsp.readdir("/storage/emulated/0");
286
198
  out.push({ name: "/storage/emulated/0", path: "/storage/emulated/0", type: "dir" });
287
199
  }
288
- catch {
289
- // no shared storage
290
- }
200
+ catch { }
291
201
  return out;
292
202
  }
293
203
  return [{ name: "/", path: "/", type: "dir" }];
294
204
  }
295
- /** 单字段错误文本的语言(host 未接线时英文默认)。 */
296
205
  lang() {
297
206
  return this.host.getLang?.() ?? "en";
298
207
  }
299
- /** 目录列表失败的 notice:缺失路径(ENOENT/ENOTDIR)是删除/改名等正常场景,
300
- * 软提示“目录不存在”;其余(权限拒绝等)保留原平台语义——win32 软提示
301
- * (ACL 系统目录常见),posix 硬错误(error 级 notice,取代曾经的 throw)。 */
302
208
  emitListError(path, error, code) {
303
209
  if (code === "ENOENT") {
304
210
  this.host.emit({
@@ -335,13 +241,9 @@ export class FilesService {
335
241
  const { resolve, sep, relative } = await import("node:path");
336
242
  const root = resolve(rawCwd);
337
243
  let raw = relPath ?? "";
338
- // Expand a leading "~/" (path-bar input) to the home directory — same
339
- // rules as completePath/makeDir. The result is absolute, so it lands in
340
- // the machine-browse branch below; wire paths always use "/".
341
244
  if (raw === "~" || raw.startsWith("~/") || raw.startsWith("~\\")) {
342
245
  raw = (raw === "~" ? homedir() : homedir() + raw.slice(1)).split(sep).join("/");
343
246
  }
344
- // ---- 机器根(此电脑:盘符列表)—— 工作区之上的虚拟层 ----
345
247
  if (raw === MACHINE_ROOT || raw === MACHINE_ROOT + "/") {
346
248
  const entries = await this.machineRootEntries();
347
249
  this.host.emit({
@@ -354,8 +256,6 @@ export class FilesService {
354
256
  });
355
257
  return;
356
258
  }
357
- // ---- 绝对路径浏览(Windows 盘符 / posix "/"):允许越过工作区根 ----
358
- // 机器模式不设 watcher(工作区递归 watch 不覆盖别的盘),文件变动靠 10s 轮询。
359
259
  if (isAbsoluteWirePath(raw)) {
360
260
  const wire = normWirePath(raw);
361
261
  const abs = wireToAbs(wire);
@@ -372,17 +272,13 @@ export class FilesService {
372
272
  this.emitListError(wire, error, errorCode);
373
273
  return;
374
274
  }
375
- // ---- 工作区相对视图(原有行为) ----
376
275
  const target = raw ? resolve(root, raw) : root;
377
- // 若工作区根目录自身尚不存在,自动自愈创建,避免首帧报错
378
276
  if (raw === "") {
379
277
  try {
380
278
  const fsp = await import("node:fs/promises");
381
279
  await fsp.mkdir(target, { recursive: true });
382
280
  }
383
- catch {
384
- /* ignore if exists */
385
- }
281
+ catch { }
386
282
  }
387
283
  const rawRel = relative(root, target);
388
284
  if (rawRel.startsWith("..") || rawRel.includes(`${sep}..`)) {
@@ -394,12 +290,8 @@ export class FilesService {
394
290
  });
395
291
  return;
396
292
  }
397
- // Normalize to forward slashes: the wire protocol and the frontend
398
- // always use "/", but relative() returns "\\" on Windows.
399
293
  const rel = rawRel.split(sep).join("/");
400
294
  const { entries, truncated, error, errorCode } = await readDirForUI(target, rel);
401
- // Watch the listed directory only after a successful read — a missing
402
- // dir must not create a watcher on a phantom path (issue #74).
403
295
  if (error) {
404
296
  this.emitListError(rel === "" ? root : rel, error, errorCode);
405
297
  }
@@ -410,7 +302,6 @@ export class FilesService {
410
302
  this.host.emit({
411
303
  type: "files",
412
304
  path: rel === "" ? "" : rel,
413
- // 工作区根也允许「上一级」→ 项目文件夹的上一级(盘符根则到机器根,posix 根无父级)。
414
305
  parent: rel === "" ? absoluteParent(rootWire) : rel.includes("/") ? rel.slice(0, rel.lastIndexOf("/")) : "",
415
306
  entries,
416
307
  truncated,
@@ -446,7 +337,6 @@ export class FilesService {
446
337
  const results = [];
447
338
  let visited = 0;
448
339
  let truncated = false;
449
- // 1) 优先精确探测输入是否为已存在的绝对路径或相对路径
450
340
  const normQuery = rawQuery.replace(/\\/g, "/");
451
341
  const q = normQuery.toLowerCase();
452
342
  try {
@@ -486,11 +376,8 @@ export class FilesService {
486
376
  }
487
377
  }
488
378
  }
489
- catch {
490
- /* ignore probe failure */
491
- }
379
+ catch { }
492
380
  const budgetLeft = () => results.length < MAX_RESULTS && visited < MAX_VISITED && Date.now() - start < MAX_MS;
493
- // Breadth-first-ish iterative stack; depth cap is a symlink-cycle guard.
494
381
  const walk = async (abs, rel, depth) => {
495
382
  if (!budgetLeft() || depth > 24) {
496
383
  truncated = true;
@@ -501,7 +388,7 @@ export class FilesService {
501
388
  dirents = await fsp.readdir(abs, { withFileTypes: true });
502
389
  }
503
390
  catch {
504
- return; // unreadable dir (ACL/permissions) — skip silently
391
+ return;
505
392
  }
506
393
  for (const d of dirents) {
507
394
  visited++;
@@ -514,13 +401,11 @@ export class FilesService {
514
401
  const childRel = rel ? `${rel}/${d.name}` : d.name;
515
402
  let isDir = d.isDirectory();
516
403
  if (d.isSymbolicLink()) {
517
- // Follow directory symlinks (Termux's ~/storage/*); the depth
518
- // cap doubles as a symlink-cycle guard, budgets bound the cost.
519
404
  try {
520
405
  isDir = (await fsp.stat(join(abs, d.name))).isDirectory();
521
406
  }
522
407
  catch {
523
- isDir = false; // broken link — treat as file
408
+ isDir = false;
524
409
  }
525
410
  }
526
411
  const childRelLower = childRel.toLowerCase();
@@ -551,12 +436,6 @@ export class FilesService {
551
436
  this.host.emit({ type: "search_files_result", reqId, ok: false, results: [] });
552
437
  }
553
438
  }
554
- /**
555
- * Source-control panel: read-only git queries via server-side execFile
556
- * (no shell, no prompts). Always responds with an scm_data message echoing
557
- * reqId so the client's request matching never stalls. Also (re)arms the
558
- * git-dir watcher so external repo changes push scm_changed.
559
- */
560
439
  async scmQuery(kind, reqId, arg) {
561
440
  const cwd = this.host.getActiveCwd();
562
441
  const isRemote = isRemoteWorkspaceUri(cwd);
@@ -582,8 +461,6 @@ export class FilesService {
582
461
  }
583
462
  }
584
463
  else {
585
- // Path stays inside the workspace (defense in depth — paths come
586
- // from our own listing, and execFile passes args verbatim anyway).
587
464
  const { resolve, relative } = await import("node:path");
588
465
  const rel = relative(resolve(cwd), resolve(cwd, arg.path));
589
466
  if (rel.startsWith("..") || rel === "")
@@ -609,7 +486,6 @@ export class FilesService {
609
486
  }
610
487
  catch (err) {
611
488
  if (isNotRepoError(err)) {
612
- // Not a repo — a valid empty answer so the panel shows its hint.
613
489
  this.host.emit({
614
490
  type: "scm_data",
615
491
  reqId,
@@ -639,12 +515,6 @@ export class FilesService {
639
515
  });
640
516
  }
641
517
  }
642
- /**
643
- * Watch the active repo's git dir (HEAD / index / packed-refs live at the
644
- * top level, which covers commit / stage / checkout). Re-targets when the
645
- * queried workspace changes. Uses `git rev-parse --absolute-git-dir` so
646
- * worktrees and submodules resolve to the real dir.
647
- */
648
518
  async watchGitDir(cwd) {
649
519
  if (this.gitWatchCwd === cwd && this.gitWatcher)
650
520
  return;
@@ -657,19 +527,16 @@ export class FilesService {
657
527
  this.gitWatcher = watch(gitDir, { persistent: false }, () => {
658
528
  if (this.host.isDisposed() || this.gitDirtyTimer)
659
529
  return;
660
- // Debounce: one checkout/commit fires several fs events.
661
530
  this.gitDirtyTimer = setTimeout(() => {
662
531
  this.gitDirtyTimer = null;
663
532
  this.host.emit({ type: "scm_changed" });
664
533
  }, 600);
665
534
  });
666
535
  this.gitWatcher.on("error", () => {
667
- // Unsupported filesystem — silently fall back to manual refresh.
668
536
  this.unwatchGit();
669
537
  });
670
538
  }
671
539
  catch {
672
- // no .git here (or git missing) — watcher stays off; queries still work
673
540
  this.unwatchGit();
674
541
  }
675
542
  }
@@ -678,9 +545,7 @@ export class FilesService {
678
545
  try {
679
546
  this.gitWatcher.close();
680
547
  }
681
- catch {
682
- // already gone
683
- }
548
+ catch { }
684
549
  }
685
550
  this.gitWatcher = null;
686
551
  this.gitWatchCwd = null;
@@ -692,34 +557,24 @@ export class FilesService {
692
557
  watchDir(absPath, rel) {
693
558
  if (this.host.isDisposed())
694
559
  return;
695
- // ---- Recursive mode (native on win32 / darwin): watch the workspace
696
- // root once, so deep changes in NOT-listed subdirectories still refresh
697
- // the panel (the old per-directory watch only saw the current level).
698
560
  if (process.platform === "win32" || process.platform === "darwin") {
699
561
  const root = resolve(this.host.getCwd());
700
562
  if (this.recursiveWatcher) {
701
563
  if (this.watchRoot === root) {
702
- // Same workspace — only retarget the refresh path.
703
564
  this.watchPath = rel;
704
565
  return;
705
566
  }
706
- this.unwatchDir(); // cwd switched to another project
567
+ this.unwatchDir();
707
568
  }
708
569
  try {
709
570
  const w = watch(root, { persistent: false, recursive: true }, (_event, filename) => {
710
- // Skip high-churn subtrees (npm install storms); .git has its
711
- // own watcher for the SCM panel. filename may be null on some
712
- // platforms — let those through (debounce absorbs bursts).
713
571
  if (filename) {
714
572
  const f = String(filename).split("\\").join("/");
715
- // Single-segment names (e.g. the dir itself) have no "/" —
716
- // slice(0, -1) would corrupt them, so special-case that.
717
573
  const slash = f.indexOf("/");
718
574
  const top = slash === -1 ? f : f.slice(0, slash);
719
575
  if (top === "node_modules" || top === ".git")
720
576
  return;
721
577
  }
722
- // Burst events are debounced into a single refresh.
723
578
  if (this.watchTimer)
724
579
  return;
725
580
  this.watchTimer = setTimeout(() => {
@@ -731,7 +586,6 @@ export class FilesService {
731
586
  }, 400);
732
587
  });
733
588
  w.on("error", () => {
734
- // Directory deleted / unsupported — fall back to poll semantics.
735
589
  this.noticeDegraded(root);
736
590
  this.unwatchDir();
737
591
  });
@@ -742,23 +596,18 @@ export class FilesService {
742
596
  return;
743
597
  }
744
598
  catch {
745
- // recursive unsupported here — fall through to per-directory watch.
746
599
  this.fsWatcher = null;
747
600
  this.recursiveWatcher = false;
748
601
  this.watchRoot = null;
749
602
  this.noticeDegraded(root);
750
603
  }
751
604
  }
752
- // ---- Fallback: single non-recursive watch on the LISTED directory.
753
605
  if (!this.recursiveWatcher && this.watchPath === rel && this.fsWatcher)
754
606
  return;
755
607
  this.unwatchDir();
756
608
  this.watchPath = rel;
757
609
  try {
758
- // persistent: false — the watcher must not keep the process alive.
759
610
  this.fsWatcher = watch(absPath, { persistent: false }, () => {
760
- // Burst events (npm install, git ops, editor save→rename) are
761
- // debounced into a single refresh.
762
611
  if (this.watchTimer)
763
612
  return;
764
613
  this.watchTimer = setTimeout(() => {
@@ -767,20 +616,15 @@ export class FilesService {
767
616
  }, 400);
768
617
  });
769
618
  this.fsWatcher.on("error", () => {
770
- // Directory deleted / unsupported fs — stop watching; the poll (or
771
- // the next navigation) restores things.
772
619
  this.unwatchDir();
773
620
  });
774
621
  }
775
622
  catch {
776
- // fs.watch unsupported (some network mounts, containers) — poll covers it.
777
623
  this.fsWatcher = null;
778
624
  this.watchPath = null;
779
625
  this.noticeDegraded(absPath);
780
626
  }
781
627
  }
782
- /** 实时监听不可用(网络盘/WSL/受限目录):一次性告知用户已回落 10s 轮询,
783
- * 免得疑惑「面板为什么不实时」。每个工作区根只提示一次。 */
784
628
  noticeDegraded(root) {
785
629
  if (this.degradedNoticedFor === root)
786
630
  return;
@@ -801,16 +645,13 @@ export class FilesService {
801
645
  try {
802
646
  this.fsWatcher.close();
803
647
  }
804
- catch {
805
- // already closed
806
- }
648
+ catch { }
807
649
  this.fsWatcher = null;
808
650
  }
809
651
  this.recursiveWatcher = false;
810
652
  this.watchRoot = null;
811
653
  this.watchPath = null;
812
654
  }
813
- /** Read a workspace file for the preview panel (size-capped, binary-safe). */
814
655
  async readFile(relPath) {
815
656
  const root = this.host.getCwd();
816
657
  if (isRemoteWorkspaceUri(root)) {
@@ -823,7 +664,6 @@ export class FilesService {
823
664
  let abs;
824
665
  let rel;
825
666
  if (absWire) {
826
- // 机器浏览:绝对路径直接读;回显用绝对 wire 形式(前端按 path 匹配)。
827
667
  abs = wireToAbs(relPath);
828
668
  rel = abs.split(sep).join("/");
829
669
  }
@@ -852,8 +692,6 @@ export class FilesService {
852
692
  return;
853
693
  }
854
694
  const name = relPath.split(/[\\/]/).pop() ?? relPath;
855
- // Office 文档(docx/xlsx/xlsm):转 Markdown 文本下发,前端按 Markdown
856
- // 渲染表格/段落——文件树、附件、预览弹窗随处可看。失败回落到底下旧分支。
857
695
  if (isOfficeFile(name) && stat.size <= OFFICE_MAX_FILE_BYTES) {
858
696
  try {
859
697
  const data = await fs.readFile(abs);
@@ -874,13 +712,9 @@ export class FilesService {
874
712
  return;
875
713
  }
876
714
  }
877
- catch {
878
- /* 解析失败(加密/损坏/非预期结构)→ 回落旧的二进制嗅探分支 */
879
- }
715
+ catch { }
880
716
  }
881
717
  const kind = previewKind(name);
882
- // Media previews stream over the /api/file HTTP endpoint, so only
883
- // metadata is sent here — the raw bytes never touch the socket.
884
718
  if (kind === "image" || kind === "video" || kind === "audio") {
885
719
  this.host.emit({
886
720
  type: "file_content",
@@ -895,10 +729,6 @@ export class FilesService {
895
729
  });
896
730
  return;
897
731
  }
898
- // Everything else: read a capped prefix and sniff the content.
899
- // Anything that looks like text previews as text regardless of its
900
- // extension (jsonl, .log.1, weird suffixes, …); binary content gets
901
- // a hex dump of the first few KB instead of being refused.
902
732
  const handle = await fs.open(abs, "r");
903
733
  try {
904
734
  const buf = Buffer.alloc(Math.min(stat.size, MAX_PREVIEW_BYTES));
@@ -944,7 +774,6 @@ export class FilesService {
944
774
  });
945
775
  }
946
776
  }
947
- /** Save text from the file preview panel within the active workspace. */
948
777
  async writeFile(relPath, text) {
949
778
  const root = this.host.getCwd();
950
779
  if (isRemoteWorkspaceUri(root)) {
@@ -999,8 +828,6 @@ export class FilesService {
999
828
  text: `已保存:${rel}`,
1000
829
  textEn: `Saved: ${rel}`,
1001
830
  });
1002
- // Re-read through the same path as the preview request so the client
1003
- // gets the canonical content, line count and file size after saving.
1004
831
  await this.readFile(rel);
1005
832
  }
1006
833
  catch (err) {
@@ -1012,13 +839,6 @@ export class FilesService {
1012
839
  });
1013
840
  }
1014
841
  }
1015
- /**
1016
- * Upload a file (base64, no data: prefix) INTO a workspace directory —
1017
- * the file manager's right-click “upload here” action. The target dir may
1018
- * be nested and is created on demand; the name is basename-sanitized so a
1019
- * malicious payload can't escape the directory. Emits notice + file_changed
1020
- * for the target dir (the recursive watcher may not cover it on posix).
1021
- */
1022
842
  async uploadFile(relDir, name, data, uploadId) {
1023
843
  const root = this.host.getCwd();
1024
844
  if (isRemoteWorkspaceUri(root)) {
@@ -1041,15 +861,11 @@ export class FilesService {
1041
861
  }
1042
862
  }
1043
863
  else if (relDir) {
1044
- // 机器浏览的目录(可能是盘符根 "C:"):按绝对路径解析。
1045
864
  wp = { abs: wireToAbs(relDir), rel: wireToAbs(relDir).split(sep).join("/") };
1046
865
  }
1047
866
  else {
1048
867
  wp = { abs: root, rel: "" };
1049
868
  }
1050
- // 与 createEntry/renameEntry 同口径(this.sanitizeName):只取 basename,
1051
- // 空 / "." / ".." / Windows 保留名 / 尾点空格一律拒绝 —— 旧的内联替换
1052
- // 会放过 "con.txt"、"a.." 这类「建了删不掉」的名字。
1053
869
  const safe = this.sanitizeName(name);
1054
870
  if (!safe) {
1055
871
  emitErr(`文件名不合法:${name}`, `Invalid file name: ${name}`);
@@ -1058,7 +874,6 @@ export class FilesService {
1058
874
  const abs = resolve(wp.abs, safe);
1059
875
  let uploadRel;
1060
876
  if (absDir) {
1061
- // 绝对目录模式不再校验工作区归属(机器浏览)。
1062
877
  uploadRel = abs.split(sep).join("/");
1063
878
  }
1064
879
  else {
@@ -1088,9 +903,6 @@ export class FilesService {
1088
903
  emitErr(`已存在:${uploadRel}`, `Already exists: ${uploadRel}`);
1089
904
  return;
1090
905
  }
1091
- // wx:与预检之间存在窗口(TOCTOU),并发同名上传走 EEXIST 落到 catch
1092
- // 报错 —— 两个上传路径语义统一为「目标已存在拒绝」,绝不静默截断覆盖
1093
- // (/api/file-transfer/upload 一直是 open(dest, "wx") 拒绝)。
1094
906
  writeUploadExclusiveSync(abs, buf);
1095
907
  this.host.emit({
1096
908
  type: "notice",
@@ -1098,9 +910,6 @@ export class FilesService {
1098
910
  text: `已上传:${uploadRel}`,
1099
911
  textEn: `Uploaded: ${uploadRel}`,
1100
912
  });
1101
- // Emit for the target directory itself so the panel refreshes even
1102
- // when the active listing/preview isn't that dir (posix watcher only
1103
- // sees the LISTED directory).
1104
913
  this.host.emit({
1105
914
  type: "file_changed",
1106
915
  path: wp.rel,
@@ -1112,12 +921,6 @@ export class FilesService {
1112
921
  emitErr(`上传文件失败:${err.message}`, `Upload failed: ${err.message}`);
1113
922
  }
1114
923
  }
1115
- /**
1116
- * Create a folder. Accepts absolute, ~-prefixed or session-relative paths
1117
- * (same expansion rules as completePath — the cwd picker may browse outside
1118
- * the session root, and set_cwd itself accepts any directory). Answers
1119
- * with a notice; the picker refreshes its listing on its own.
1120
- */
1121
924
  async makeDir(input) {
1122
925
  const rawCwd = this.host.getCwd();
1123
926
  if (isRemoteWorkspaceUri(rawCwd) || isRemoteWorkspaceUri(input)) {
@@ -1190,10 +993,6 @@ export class FilesService {
1190
993
  return null;
1191
994
  }
1192
995
  }
1193
- /* ---- 文件树右键菜单的文件操作(`contextmenu.file`,见 protocol.ts file_*) ---- */
1194
- /** 右键文件操作共用的路径解析:绝对 wire(机器浏览)直接转原生绝对路径;
1195
- * 相对路径限定在工作区内(越界 → null,与 readFile/writeFile 同口径)。
1196
- * 空串(工作区根须由调用方特判)与机器根 "@root" 本身不可作为操作对象 → null。 */
1197
996
  resolveOpTarget(raw) {
1198
997
  const wire = normWirePath(raw.trim());
1199
998
  if (!wire || wire === MACHINE_ROOT)
@@ -1203,8 +1002,6 @@ export class FilesService {
1203
1002
  const w = workspacePath(resolve(this.host.getCwd()), wire);
1204
1003
  return w ? { abs: w.abs } : null;
1205
1004
  }
1206
- /** 文件名清洗(与 uploadFile 同口径再收紧):只取 basename,去 Windows 非法字符;
1207
- * 空/纯点/尾点空格/Windows 保留名 → null(建了删不掉的东西不如直接拒绝)。 */
1208
1005
  sanitizeName(name) {
1209
1006
  const base = name.split(/[\\/]/).pop() ?? "";
1210
1007
  const safe = base
@@ -1217,31 +1014,25 @@ export class FilesService {
1217
1014
  return null;
1218
1015
  return safe;
1219
1016
  }
1220
- /** wire 路径的父目录(wire 字符串层面切分,保证 file_changed 与前端 currentPath 同形)。
1221
- * 工作区根 "" / 机器根 / posix 根 "/" / 盘符根 → null(这些不可重命名/删除/作复制源)。 */
1222
1017
  wireParent(wire) {
1223
1018
  const w = normWirePath(wire.trim());
1224
1019
  if (!w || w === MACHINE_ROOT || w === "/" || /^[A-Za-z]:$/.test(w))
1225
1020
  return null;
1226
1021
  const i = w.lastIndexOf("/");
1227
1022
  if (i < 0)
1228
- return ""; // 工作区相对单层 → 工作区根
1023
+ return "";
1229
1024
  if (i === 0)
1230
- return "/"; // "/a" → "/"
1025
+ return "/";
1231
1026
  return w.slice(0, i);
1232
1027
  }
1233
- /** destDir(wire,空串 = 工作区根)→ 原生绝对目录;不存在/非目录 → null(调用方报错)。 */
1234
1028
  async resolveOpDir(dir) {
1235
1029
  const fsp = await import("node:fs/promises");
1236
1030
  if (!dir.trim()) {
1237
1031
  const rootAbs = resolve(this.host.getCwd());
1238
- // 工作区根目录在首次运行可能尚未落地,自愈创建以确保后续操作成功
1239
1032
  try {
1240
1033
  await fsp.mkdir(rootAbs, { recursive: true });
1241
1034
  }
1242
- catch {
1243
- /* ignore if exists */
1244
- }
1035
+ catch { }
1245
1036
  return { abs: rootAbs, wire: "" };
1246
1037
  }
1247
1038
  const t = this.resolveOpTarget(dir);
@@ -1252,7 +1043,6 @@ export class FilesService {
1252
1043
  return null;
1253
1044
  return { abs: t.abs, wire: normWirePath(dir.trim()) };
1254
1045
  }
1255
- /** 在 dir 下新建空文件或空文件夹。已存在不覆盖(报错);成功后对 dir 推 file_changed。 */
1256
1046
  async createEntry(dir, name, kind) {
1257
1047
  const rawCwd = this.host.getCwd();
1258
1048
  if (isRemoteWorkspaceUri(rawCwd)) {
@@ -1294,7 +1084,6 @@ export class FilesService {
1294
1084
  err(`新建失败:${e.message}`, `Create failed: ${e.message}`);
1295
1085
  }
1296
1086
  }
1297
- /** 同目录内重命名(newName 只取 basename,不跨目录)。成功后对父目录推 file_changed。 */
1298
1087
  async renameEntry(path, newName) {
1299
1088
  const rawCwd = this.host.getCwd();
1300
1089
  if (isRemoteWorkspaceUri(rawCwd)) {
@@ -1334,7 +1123,6 @@ export class FilesService {
1334
1123
  err(`重命名失败:${e.message}`, `Rename failed: ${e.message}`);
1335
1124
  }
1336
1125
  }
1337
- /** 删除文件或目录(目录递归删)。工作区根/机器根/盘符根拒绝;成功后对父目录推 file_changed。 */
1338
1126
  async deleteEntry(path) {
1339
1127
  const rawCwd = this.host.getCwd();
1340
1128
  if (isRemoteWorkspaceUri(rawCwd)) {
@@ -1363,8 +1151,6 @@ export class FilesService {
1363
1151
  err(`删除失败:${e.message}`, `Delete failed: ${e.message}`);
1364
1152
  }
1365
1153
  }
1366
- /** 复制或移动(move=true 即剪切粘贴)。destDir 与源同目录即「创建副本」;
1367
- * 重名自动加 " copy" 后缀;目录搬进自身/子目录拒绝;跨盘移动回落为复制+删源。 */
1368
1154
  async copyEntry(src, destDir, move) {
1369
1155
  const rawCwd = this.host.getCwd();
1370
1156
  if (isRemoteWorkspaceUri(rawCwd)) {
@@ -1386,7 +1172,6 @@ export class FilesService {
1386
1172
  err(`目标目录不存在:${destDir || "根目录"}`, `Target directory not found: ${destDir || "root"}`);
1387
1173
  return;
1388
1174
  }
1389
- // 目录搬进自身或子目录 → 无限递归,必须拒绝(文件无此问题,但统一判一次)。
1390
1175
  if (target.abs === s.abs || target.abs.startsWith(s.abs + sep)) {
1391
1176
  err("不可复制/移动到自身或子目录", "Cannot copy/move into itself");
1392
1177
  return;
@@ -1405,7 +1190,6 @@ export class FilesService {
1405
1190
  await fsp.rename(s.abs, dest);
1406
1191
  }
1407
1192
  catch (e) {
1408
- // 跨盘/跨挂载点 rename 报 EXDEV → 回落复制+删源(与文件管理器同行为)。
1409
1193
  if (e.code !== "EXDEV")
1410
1194
  throw e;
1411
1195
  await fsp.cp(s.abs, dest, { recursive: true, force: false });
@@ -1429,7 +1213,6 @@ export class FilesService {
1429
1213
  err(`${move ? "移动" : "复制"}失败:${e.message}`, `${move ? "Move" : "Copy"} failed: ${e.message}`);
1430
1214
  }
1431
1215
  }
1432
- /** 副本目标去重:"a.txt" → "a copy.txt" → "a copy 2.txt"…(目录/无后缀同理)。 */
1433
1216
  async dedupeCopyDest(dest) {
1434
1217
  const fsp = await import("node:fs/promises");
1435
1218
  const { join, dirname, basename, extname } = await import("node:path");
@@ -1446,9 +1229,6 @@ export class FilesService {
1446
1229
  }
1447
1230
  return join(dir, `${stem} copy ${Date.now()}${ext}`);
1448
1231
  }
1449
- /** 系统原生打开/定位的公共执行体(issue #187):cmd/args 已按平台组装好。
1450
- * spawn 成功即算送达(explorer/open 都是 daemon 式返回,exit code 不可信);
1451
- * ENOENT(headless/无桌面)等失败一律 warning notice,绝不抛。 */
1452
1232
  async spawnDetached(cmd, args, okText, okTextEn) {
1453
1233
  const fail = (detail) => this.host.emit({
1454
1234
  type: "notice",
@@ -1458,9 +1238,6 @@ export class FilesService {
1458
1238
  });
1459
1239
  try {
1460
1240
  const { spawn } = await import("node:child_process");
1461
- // ⚠ 这里绝不能加 windowsHide: true:它经 STARTF_USESHOWWINDOW + SW_HIDE 压住子进程首窗口,
1462
- // explorer/open 起的是 GUI(无控制台可藏),加了之后进程在、窗口永远不出来
1463
- // (2026-09 实测:notepad/explorer 同参数起,进程 session 1 正常、桌面无窗口;去掉即现)。
1464
1241
  const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
1465
1242
  if (typeof child.unref === "function")
1466
1243
  child.unref();
@@ -1474,7 +1251,6 @@ export class FilesService {
1474
1251
  };
1475
1252
  child.on("spawn", () => settle(true));
1476
1253
  child.on("error", () => settle(false));
1477
- // 极端平台无 spawn 事件时兜底放行(进程已脱离,成败不再可知)。
1478
1254
  setTimeout(() => settle(true), 3000);
1479
1255
  });
1480
1256
  if (!launched) {
@@ -1487,8 +1263,6 @@ export class FilesService {
1487
1263
  fail(e.message);
1488
1264
  }
1489
1265
  }
1490
- /** 在系统资源管理器中定位(issue #187):文件→打开目录并选中该文件,目录→直接打开。
1491
- * 只读操作(不改文件),保护根/盘符根也允许;@root 本体与越界路径拒绝。 */
1492
1266
  async revealEntry(path) {
1493
1267
  const err = (text, textEn) => this.host.emit({ type: "notice", level: "warning", text, textEn });
1494
1268
  try {
@@ -1510,15 +1284,12 @@ export class FilesService {
1510
1284
  const segs = trimmed.split("/");
1511
1285
  const base = !trimmed ? t.abs.split(/[\\/]/).pop() || t.abs : (segs[segs.length - 1] ?? trimmed);
1512
1286
  if (process.platform === "win32") {
1513
- // /select, 与路径分两个 argv 传(explorer 对此格式稳定支持,路径含空格也无碍)。
1514
- // 目录传 /n, 强制打开新窗口,防止若该目录已在后台打开时被 Windows 静默复用且因反抢焦点机制不置顶。
1515
1287
  await this.spawnDetached("explorer.exe", isDir ? ["/n,", abs] : ["/select,", abs], "已在资源管理器中显示:" + base, "Revealed in File Explorer: " + base);
1516
1288
  }
1517
1289
  else if (process.platform === "darwin") {
1518
1290
  await this.spawnDetached("open", isDir ? [abs] : ["-R", abs], "已在访达中显示:" + base, "Revealed in Finder: " + base);
1519
1291
  }
1520
1292
  else {
1521
- // Linux 无统一选中语义:打开其父目录(目录则打开自身)。
1522
1293
  await this.spawnDetached("xdg-open", [isDir ? abs : dirname(abs)], "已打开所在目录:" + base, "Opened containing folder: " + base);
1523
1294
  }
1524
1295
  }
@@ -1526,7 +1297,6 @@ export class FilesService {
1526
1297
  err("定位失败:" + e.message, "Reveal failed: " + e.message);
1527
1298
  }
1528
1299
  }
1529
- /** 用系统默认应用打开文件(issue #187):仅文件;目录请用 reveal。 */
1530
1300
  async openDefaultEntry(path) {
1531
1301
  const err = (text, textEn) => this.host.emit({ type: "notice", level: "warning", text, textEn });
1532
1302
  try {
@@ -1547,7 +1317,6 @@ export class FilesService {
1547
1317
  }
1548
1318
  const segs = path.split("/");
1549
1319
  const base = segs[segs.length - 1] ?? path;
1550
- // explorer 直接跟路径即走默认关联打开(含空格路径单 argv,无拆分问题)。
1551
1320
  const cmd = process.platform === "win32" ? "explorer.exe" : process.platform === "darwin" ? "open" : "xdg-open";
1552
1321
  await this.spawnDetached(cmd, [t.abs], "已用默认应用打开:" + base, "Opened with default app: " + base);
1553
1322
  }
@@ -1555,10 +1324,6 @@ export class FilesService {
1555
1324
  err("打开失败:" + e.message, "Open failed: " + e.message);
1556
1325
  }
1557
1326
  }
1558
- /**
1559
- * Path completion for the cwd input: expand ~/relative paths, list the parent
1560
- * directory, and return prefix matches (dirs first, capped).
1561
- */
1562
1327
  async completePath(input) {
1563
1328
  const empty = () => this.host.emit({ type: "path_completions", completions: [] });
1564
1329
  const cwd = this.host.getCwd();
@@ -1577,12 +1342,10 @@ export class FilesService {
1577
1342
  empty();
1578
1343
  return;
1579
1344
  }
1580
- // ---- 机器根(此电脑/盘符列表)----
1581
1345
  if (rawInput === MACHINE_ROOT || rawInput === MACHINE_ROOT + "/") {
1582
1346
  this.host.emit({ type: "path_completions", completions: await this.machineRootEntries() });
1583
1347
  return;
1584
1348
  }
1585
- // ---- Windows 盘符输入:"D"(补全到盘符,Tab 即换盘)/ "D:"(列盘根)----
1586
1349
  if (isWin && /^[A-Za-z]:?$/.test(rawInput)) {
1587
1350
  const letter = rawInput[0].toUpperCase();
1588
1351
  const drive = `${letter}:`;
@@ -1599,7 +1362,6 @@ export class FilesService {
1599
1362
  return;
1600
1363
  }
1601
1364
  if (rawInput.length === 2) {
1602
- // 已带冒号:直接列出盘根条目。
1603
1365
  const dirents = await fs.readdir(`${drive}\\`, { withFileTypes: true }).catch(() => null);
1604
1366
  if (!dirents) {
1605
1367
  empty();
@@ -1620,12 +1382,9 @@ export class FilesService {
1620
1382
  this.host.emit({ type: "path_completions", completions: items });
1621
1383
  return;
1622
1384
  }
1623
- // 只有字母:补全到盘符本身。
1624
1385
  this.host.emit({ type: "path_completions", completions: [{ name: drive, path: drive, type: "dir" }] });
1625
1386
  return;
1626
1387
  }
1627
- // Expand ~ and relative inputs to an absolute path. Windows users type
1628
- // backslashes (P:\agent) and ~\ — handle both separator styles.
1629
1388
  let expanded = rawInput;
1630
1389
  if (expanded === "~" || expanded === "~\\") {
1631
1390
  expanded = home;
@@ -1636,8 +1395,6 @@ export class FilesService {
1636
1395
  else if (!isAbsolute(expanded)) {
1637
1396
  expanded = resolve(cwd, expanded);
1638
1397
  }
1639
- // Split into parent dir + prefix on the LAST separator of either style
1640
- // (Windows accepts both / and \, so P:\agent/de must work too).
1641
1398
  const lastSlash = Math.max(expanded.lastIndexOf("/"), expanded.lastIndexOf("\\"));
1642
1399
  const dirPart = lastSlash >= 0 ? expanded.slice(0, lastSlash + 1) : "";
1643
1400
  const prefix = lastSlash >= 0 ? expanded.slice(lastSlash + 1) : expanded;
@@ -1652,8 +1409,6 @@ export class FilesService {
1652
1409
  .map((d) => classifyDirent(d, dirPart))))
1653
1410
  .map((e) => ({
1654
1411
  ...e,
1655
- // Windows users type backslashes — normalize the completion to the
1656
- // wire format ("/") so the picked path round-trips cleanly.
1657
1412
  path: IS_WIN32 ? join(dirPart, e.name).split(sep).join("/") : dirPart + e.name,
1658
1413
  }))
1659
1414
  .sort((a, b) => {
@@ -1672,9 +1427,6 @@ export class FilesService {
1672
1427
  empty();
1673
1428
  }
1674
1429
  }
1675
- // =========================================================================
1676
- // 远程 SSH 工作区 (ssh://...) 专属文件操作实现
1677
- // =========================================================================
1678
1430
  resolveRemoteTarget(rawCwd, p, allowRoot = false) {
1679
1431
  const parsed = parseRemoteWorkspaceUri(rawCwd);
1680
1432
  if (!parsed)
@@ -1820,7 +1572,6 @@ export class FilesService {
1820
1572
  const q = normQuery.toLowerCase();
1821
1573
  const results = [];
1822
1574
  let truncated = false;
1823
- // 优先精确检查直接目标
1824
1575
  const target = this.resolveRemoteTarget(rawCwd, normQuery);
1825
1576
  if (target) {
1826
1577
  try {
@@ -1832,9 +1583,7 @@ export class FilesService {
1832
1583
  type: st.isDirectory ? "dir" : "file",
1833
1584
  });
1834
1585
  }
1835
- catch {
1836
- /* ignore stat error */
1837
- }
1586
+ catch { }
1838
1587
  }
1839
1588
  const cmd = `find . -maxdepth 8 \\( -name node_modules -o -name .git -o -name .pi-web \\) -prune -o -print 2>/dev/null | head -n 5000`;
1840
1589
  const res = await sshSvc.execInWorkspace(rawCwd, cmd, { timeoutMs: 8000 });
@@ -1993,8 +1742,6 @@ export class FilesService {
1993
1742
  });
1994
1743
  return;
1995
1744
  }
1996
- // Preserve the existing SFTP file object (ACLs, xattrs and symlink target).
1997
- // Keep the established SFTP save path rather than GNU shell replacement.
1998
1745
  const info = await sshSvc.sftpStat(rawCwd, t.abs);
1999
1746
  if (!info.isFile || info.size > 2 * 1024 * 1024)
2000
1747
  throw new Error("Remote save target must be a regular file no larger than 2MB");