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,32 +1,7 @@
1
- /**
2
- * dsh-agent-service.ts — DeepSeek Harness (dsh) 引擎的 AgentService 等价物。
3
- *
4
- * 每个浏览器客户端(clientId)持有:
5
- * - 一个 DshRuntime 子进程(stdio JSON-RPC,模型在 initialize 固定 → 换模型 = 重启)
6
- * - 一个或多个 conversation(1:1 映射 DSH session id)
7
- * - 每 conversation 一个 TerminalManager
8
- *
9
- * 消息折叠(事件面 ground truth,见 docs/dsh-engine.md §2.1):
10
- * session.event 持久事件(user/message、assistant/message、tool/result、
11
- * assistant/chunk、turn/step、session/title …)→ 追加到 conversation 的
12
- * UiMessage[](回放 JSONL 初始化 + 增量追加,按消息 id 去重)。
13
- * assistant/chunk 增量累积 streamingMessage(reasoning→thinking、
14
- * text→text、tool-call→toolCall)。
15
- * session.status(running/idle)驱动 isStreaming。
16
- *
17
- * 协议面限制的处理:
18
- * - 中止 = kill 运行时进程树(JSONL 在磁盘,重建不丢)→ 自动重启保持可用
19
- * - 换模型 / 换项目 = 重启运行时(initialize 固定 model + cwd)
20
- * - 会话列表/回放 = 直读 JSONL(dsh-sessions.ts)
21
- * - queue 语义:DSH 无 mid-run steering —— isStreaming 时 prompt 走 followUp
22
- * (运行时 inbox 排队,当前 run 结束后消费)
23
- *
24
- * 引擎无关模块复用:FilesService(文件树/预览)、scm.ts(git 查询)、
25
- * BgServerTracker(后台任务)、TerminalManager(PTY)、uploads.ts。
26
- */
27
1
  import { startTurnTiming, finishTurnTiming } from "../turn-timing.js";
28
2
  import { DEFAULT_DSH_CAPABILITIES } from "../engine-capabilities.js";
29
3
  import { mergeQuickAskSettings, normalizeQuickAskSettings } from "../quick-ask-settings.js";
4
+ import { captureQuickAskConversation } from "../quick-ask-context.js";
30
5
  import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
31
6
  import { basename, dirname, join, resolve, sep } from "node:path";
32
7
  import { randomUUID } from "node:crypto";
@@ -69,19 +44,13 @@ import { exportPresetVia, importPresetFromUrlVia, importPresetVia, packageVersio
69
44
  import { getAppVersion } from "../pkg-info.js";
70
45
  import { getMaxOpenConversations } from "../agent-formatters.js";
71
46
  const SNAPSHOT_INTERVAL_MS = 60;
72
- /** 用户主目录(wire 格式):进程内不变,模块加载时求值一次(右栏 🏠)。 */
73
47
  const HOME_WIRE = homedir().replace(/\\/g, "/");
74
- /** 桌面目录(wire 格式):进程内不变,不存在则空串 → 前端不渲染 🖥️。 */
75
48
  const DESKTOP_WIRE = desktopDirWire(HOME_WIRE);
76
- /** 新会话默认权限预设(沙箱内 + 无审批弹窗;无头运行的当前行为,保持不变)。 */
77
49
  const PERMISSION_DEFAULT_PRESET = "workspace-write-never";
78
- /** 前端提供的三档(官方 workspace-write 走 ask,无应答者时是死路,不提供)。 */
79
50
  const PERMISSION_OFFERED = ["read-only", "workspace-write-never", "danger-full-access"];
80
51
  const DEFAULT_CONV_TITLE = "新对话";
81
52
  const DEFAULT_CONV_TITLE_EN = "New chat";
82
53
  const DEFAULT_MODEL = "deepseek-v4-flash";
83
- /** DSH 可选模型(顶栏模型选择器)。仅 deepseek-v4-flash-vision-exp 支持图片
84
- * (adapter 默认目录 inputModalities: [text, image]);flash/pro 是 text-only。 */
85
54
  const DSH_MODELS = [
86
55
  { id: "deepseek-v4-flash", name: "DeepSeek V4 Flash", provider: "deepseek", vision: false },
87
56
  { id: "deepseek-v4-pro", name: "DeepSeek V4 Pro", provider: "deepseek", vision: false },
@@ -92,12 +61,10 @@ const DSH_MODELS = [
92
61
  vision: true,
93
62
  },
94
63
  ];
95
- /** DeepSeek V4 context window + 官方每 1M token 定价(USD,api-docs.deepseek.com)。 */
96
64
  const DSH_CONTEXT_WINDOW = 1_000_000;
97
65
  const DSH_PRICE_INPUT = 0.14;
98
66
  const DSH_PRICE_CACHE_READ = 0.0028;
99
67
  const DSH_PRICE_OUTPUT = 0.28;
100
- /** 会话 root:<dataDir>/dsh-sessions(与 pi 引擎的会话目录隔离)。 */
101
68
  function dshSessionRoot(dataDir) {
102
69
  return join(dataDir, "dsh-sessions");
103
70
  }
@@ -109,9 +76,6 @@ function estimateCost(t) {
109
76
  t.output * DSH_PRICE_OUTPUT) /
110
77
  1e6);
111
78
  }
112
- /** 把插件工具 execute 的原始返回值归一化成模型可读文本。
113
- * 兼容:`{content:[{type:"text",text}...],details}` → text 拼接;string → 原串;
114
- * 其它对象 → JSON.stringify;null/undefined → 空串。 */
115
79
  function normalizeToolResult(result) {
116
80
  if (typeof result === "string")
117
81
  return result;
@@ -171,30 +135,20 @@ const DEFAULT_SETTINGS = {
171
135
  promptOverrides: {},
172
136
  promptDisabled: [],
173
137
  };
174
- // ---------------------------------------------------------------------------
175
- // DshClientSession — 一个浏览器客户端
176
- // ---------------------------------------------------------------------------
177
138
  export class DshClientSession {
178
139
  clientId;
179
140
  cwd;
180
- /** 当前项目的额外工作区根(宿主侧多根,见 protocol 的 set_workspace_roots)——
181
- * 按 cwd 存在 client-state 里,这里只存一份内存缓存给快照热路径读。 */
182
141
  roots = [];
183
142
  stateStore;
184
143
  sessionRoot;
185
144
  dataDir;
186
- /** pi 配置目录(auth.json 所在;尊重 PI_CODING_AGENT_DIR)。 */
187
145
  agentDir;
188
- /** 用户直接创建的交互式终端(按 CLIENT/工作区 存活,始终显示,不受单个对话切换、生命周期与过滤影响) */
189
146
  userTerminals;
190
147
  runtime;
191
148
  convs = new Map();
192
149
  activeId = "";
193
150
  convSeq = 0;
194
- /** 待答问卷快照(见 attachRuntimeEvents 的 question.pending 与
195
- * UiState.pendingQuestion):重连/刷新后由快照恢复对话框。 */
196
151
  pendingQuestion = null;
197
- /** 客户端级目标/审查偏好(跨会话共享的默认值,per-conversation goal 用它初始化)。 */
198
152
  goalPrefs = { reviewModel: null, maxRounds: 2, locked: false };
199
153
  sinks = new Set();
200
154
  pendingNotices = [];
@@ -212,35 +166,24 @@ export class DshClientSession {
212
166
  modelDisplayName = "DeepSeek V4 Flash";
213
167
  modelVision = false;
214
168
  thinkingLevel = "high";
215
- /** P0-1 watchdog:60s 窗口内最多自动重启 2 次,超限升级为报错 notice。 */
216
169
  static RUNTIME_RESTART_WINDOW_MS = 60_000;
217
170
  static RUNTIME_MAX_RESTARTS = 2;
218
171
  runtimeRestart = { count: 0, windowStart: 0 };
219
- /** P0-3 convs 内存回收:非活跃且非 streaming 的 conversation 定期回收(JSONL 在磁盘,回放可恢复)。 */
220
172
  static RECLAIM_INTERVAL_MS = 5 * 60_000;
221
- /** 未进左栏“运行的对话”的空闲上限。 */
222
173
  static CONV_RECLAIM_IDLE_MS = 30 * 60_000;
223
- /** 已在左栏“运行的对话”里的空闲上限(用户可见,给更长的保留期)。 */
224
174
  static CONV_RECLAIM_LISTED_IDLE_MS = 24 * 3600_000;
225
175
  reclaimTimer = null;
226
- /** P1-13 会话 JSONL 保留期(PI_WEB_DSH_SESSION_RETENTION_DAYS,默认 90 天)。 */
227
176
  static SESSION_RETENTION_MS = (Number(process.env.PI_WEB_DSH_SESSION_RETENTION_DAYS) || 90) * 24 * 3600_000;
228
177
  retentionTimer = null;
229
178
  retentionOnce = null;
230
179
  settings = { ...DEFAULT_SETTINGS };
231
- /** 最近一次从运行时拉取的技能清单(UiSkillInfo,含 enabled 由 disabledSkills 推导)。 */
232
180
  skillsCache = [];
233
- /** 运行时世代(每次 start 成功 +1;conv.assignedGen 用它判断 preset/assign 是否过期)。 */
234
181
  runtimeGen = 0;
235
- /** Agent 预设名录缓存(运行时 preset/list;unavailable/空 = legacy,UI 隐藏预设条)。 */
236
182
  agentPresets = [];
237
183
  agentPresetDefault = PRESET_DEFAULT_ID;
238
184
  agentPresetsAvailable = false;
239
- /** 权限选项表缓存(组合静态;空 = 未就绪/legacy,前端隐藏权限条)。 */
240
185
  permissionOptions = [];
241
- /** clone 出来的预设 id(roster 名录校验用;空 = 未生成,走 legacy)。 */
242
186
  presetCloneIds = [];
243
- /** 系统提示词缓存(从运行时 inspectPrompt 异步拉取;未就绪时兜底)。 */
244
187
  cachedEffectiveSystemPrompt = "";
245
188
  cachedToolsSchema = "";
246
189
  cachedPromptSections = [];
@@ -255,7 +198,6 @@ export class DshClientSession {
255
198
  }
256
199
  markerSvc;
257
200
  modelAdmin;
258
- /** 插件扩展点(index.ts 注入)。 */
259
201
  onToolEvent;
260
202
  pluginToolsProvider;
261
203
  pluginCommandsProvider;
@@ -264,14 +206,11 @@ export class DshClientSession {
264
206
  onQuit;
265
207
  isQuiesced;
266
208
  onCwdChanged;
267
- /** issue #145 跨客户端感知(DshAgentService.attach 接线,与 pi 引擎同语义;
268
- * DSH 的会话身份是 sessionId = JSONL 目录名)。 */
269
209
  findSessionOwnerById = undefined;
270
210
  listProjectRunners = undefined;
271
211
  listExternalRunning = undefined;
272
212
  notifyExternalClients = undefined;
273
213
  onRunningChanged = undefined;
274
- /** issue #145:上次 emit 时流式对话签名(变化才 poke 其他客户端,防循环)。 */
275
214
  lastRunningSig = "";
276
215
  constructor(clientId, cwd, stateStore, dataDir, agentDir) {
277
216
  this.clientId = clientId;
@@ -286,9 +225,7 @@ export class DshClientSession {
286
225
  try {
287
226
  mkdirSync(this.sessionRoot, { recursive: true });
288
227
  }
289
- catch {
290
- /* best effort */
291
- }
228
+ catch { }
292
229
  this.files = new FilesService({
293
230
  emit: (msg) => this.emit(msg),
294
231
  isDisposed: () => this.disposed,
@@ -338,8 +275,6 @@ export class DshClientSession {
338
275
  }
339
276
  static create(clientId, cwd, stateStore, dataDir, agentDir) {
340
277
  const cs = new DshClientSession(clientId, cwd, stateStore, dataDir, agentDir ?? join(homedir(), ".pi", "agent"));
341
- // 恢复上次使用的目标/审查偏好(全局记忆,跨重载存活;per-conversation
342
- // 目标用它初始化)。
343
278
  const gPrefs = stateStore.getGoalPrefs(clientId);
344
279
  if (gPrefs) {
345
280
  cs.goalPrefs = {
@@ -348,12 +283,10 @@ export class DshClientSession {
348
283
  locked: gPrefs.locked,
349
284
  };
350
285
  }
351
- // 恢复上次使用的模型(按 DSH 引擎独立记录:项目记忆 > 全局默认)
352
286
  const savedModel = stateStore.getProjectModel(clientId, cwd, "dsh") ?? stateStore.getDefaultModel("dsh");
353
287
  if (savedModel) {
354
288
  cs.applySavedModel(savedModel);
355
289
  }
356
- // 恢复上次使用的设置(跨重连存活;DSH 忽略无行为字段但回显保持 UI 一致)。
357
290
  const savedSettings = stateStore.getSettings(clientId);
358
291
  if (savedSettings) {
359
292
  cs.settings = {
@@ -395,7 +328,6 @@ export class DshClientSession {
395
328
  : PERMISSION_DEFAULT_PRESET,
396
329
  };
397
330
  }
398
- // 恢复最近会话(若有)或新建空白会话(避免刷新页面后丢失历史变成空白新对话)
399
331
  cs.makeRuntime();
400
332
  const recentFiles = findSessionFilesForCwd(cs.sessionRoot, cwd).filter((f) => !basename(dirname(f)).startsWith("review-"));
401
333
  let resumedConv = null;
@@ -425,8 +357,6 @@ export class DshClientSession {
425
357
  cs.activeId = first.id;
426
358
  }
427
359
  cs.attachRuntimeEvents();
428
- // 每次启动成功(含初次/换模型/watchdog 重启)后重新注册插件工具桥,
429
- // 因为重 spawn 后的 ctx.tools 是全新的,需要重新 sync 插件工具。
430
360
  cs.runtime.onStarted = () => {
431
361
  if (cs.switchingWorkspace)
432
362
  return;
@@ -439,14 +369,12 @@ export class DshClientSession {
439
369
  void cs.refreshActivePermission().catch(() => { });
440
370
  void cs.refreshPromptInfo().catch(() => { });
441
371
  };
442
- // P0-1 watchdog:意外退出(非 kill/close 主动触发)→ 限频自动重启,保持可用。
443
372
  cs.runtime.onExit = (code, signal, intentional) => {
444
373
  cs.cancelBridgedTools();
445
374
  if (intentional)
446
- return; // kill()/close() 主动触发,不重启
375
+ return;
447
376
  cs.handleRuntimeExit(code, signal);
448
377
  };
449
- // P0-5 启动重试:1s/3s/9s 指数退避,最终失败才发 notice。
450
378
  void cs.startWithRetry().catch((err) => {
451
379
  console.error(`[dsh] runtime.start 失败 (client=${clientId}): ${err.message}`);
452
380
  const errMsg = err.message || "";
@@ -464,10 +392,8 @@ export class DshClientSession {
464
392
  textEn: `DSH runtime failed to start: ${errMsg}. ${hintEn}`,
465
393
  });
466
394
  });
467
- // P0-3 convs 内存回收定时器(unref:不阻止进程退出)。
468
395
  cs.reclaimTimer = setInterval(() => cs.reclaimIdleConversations(), DshClientSession.RECLAIM_INTERVAL_MS);
469
396
  cs.reclaimTimer.unref?.();
470
- // P1-13 会话 JSONL 保留期清理:启动后 10s 首清 + 每 24h 一次(幂等)。
471
397
  cs.retentionOnce = setTimeout(() => void cs.cleanupExpiredSessions(), 10_000);
472
398
  cs.retentionOnce.unref?.();
473
399
  cs.retentionTimer = setInterval(() => void cs.cleanupExpiredSessions(), 24 * 3600_000);
@@ -475,7 +401,6 @@ export class DshClientSession {
475
401
  cs.bg.start();
476
402
  return cs;
477
403
  }
478
- /** P0-5 带指数退避的启动(1s/3s/9s,最终失败才抛)。 */
479
404
  async startWithRetry() {
480
405
  const delays = [1000, 3000, 9000];
481
406
  let lastErr;
@@ -493,17 +418,14 @@ export class DshClientSession {
493
418
  }
494
419
  throw lastErr;
495
420
  }
496
- /** P0-1 意外崩溃处理:重置进行中的 conv 状态 → 限频自动重启。 */
497
421
  handleRuntimeExit(code, signal) {
498
422
  if (this.disposed)
499
423
  return;
500
424
  console.error(`[dsh] runtime 意外退出 (client=${this.clientId}) code=${code} signal=${signal}`);
501
- // 进行中的 run 全部中断(pending RPC 已被 failPending reject)→ 复位 streaming。
502
425
  for (const conv of this.convs.values()) {
503
426
  finishTurnTiming(conv);
504
427
  conv.isStreaming = false;
505
428
  conv.streaming = null;
506
- // 直播帧能力跟着运行时进程走:重启后重新探测(换运行时版本也能回落到持久 assistant/chunk)。
507
429
  conv.liveChunks = false;
508
430
  }
509
431
  this.emitConversations();
@@ -548,7 +470,6 @@ export class DshClientSession {
548
470
  });
549
471
  this.flushSnapshot();
550
472
  }
551
- /** P0-3 回收长时间空闲的非活跃 conversation(磁盘 JSONL 在,回放即可恢复)。 */
552
473
  reclaimIdleConversations() {
553
474
  if (this.disposed)
554
475
  return;
@@ -559,7 +480,6 @@ export class DshClientSession {
559
480
  continue;
560
481
  if (conv.isStreaming)
561
482
  continue;
562
- // 只看“用过”的存活终端:没动过的空 shell 不阻止空闲回收。
563
483
  if (conv.terminals.countBlockingLive() > 0)
564
484
  continue;
565
485
  const idle = now - conv.lastEventAt;
@@ -574,8 +494,6 @@ export class DshClientSession {
574
494
  this.flushSnapshot();
575
495
  }
576
496
  }
577
- /** P1-13 清理超过保留期未活动的会话目录(<sessionRoot>/<projectKey>/<sessionId>/)。
578
- * 目录内最新文件 mtime 判活跃(JSONL 追加写不更新目录 mtime,不能看目录本身)。 */
579
497
  async cleanupExpiredSessions() {
580
498
  if (this.disposed)
581
499
  return;
@@ -601,14 +519,10 @@ export class DshClientSession {
601
519
  max = Math.max(max, m);
602
520
  }
603
521
  }
604
- catch {
605
- /* skip unreadable */
606
- }
522
+ catch { }
607
523
  }
608
524
  }
609
- catch {
610
- /* skip unreadable dir */
611
- }
525
+ catch { }
612
526
  return max;
613
527
  };
614
528
  let removed = 0;
@@ -626,7 +540,7 @@ export class DshClientSession {
626
540
  continue;
627
541
  const lastMod = dirLastModified(p, cutoff);
628
542
  if (lastMod === 0)
629
- continue; // 空目录不删
543
+ continue;
630
544
  if (lastMod < cutoff) {
631
545
  rmSync(p, { recursive: true, force: true });
632
546
  removed++;
@@ -642,13 +556,9 @@ export class DshClientSession {
642
556
  this.scheduleSessionsRefresh();
643
557
  }
644
558
  }
645
- catch {
646
- /* best effort */
647
- }
559
+ catch { }
648
560
  }
649
561
  makeRuntime() {
650
- // Agent 预设 clone(file: 改写 shipped 预设,供 preset-plane patch 的 roster 用)。
651
- // 成功 → 下发 patch(预设时代);失败/null → 不下发(回落 legacy 单组合)。
652
562
  let presetPatch;
653
563
  try {
654
564
  const clones = generatePresetClones(this.dataDir);
@@ -692,17 +602,13 @@ export class DshClientSession {
692
602
  this.handleSessionEvent(params);
693
603
  }
694
604
  else if (method === "assistant.stream") {
695
- // 新版运行时(0.1.1-rc.2 之后)的直播流:wrapper 把 agent/assistant-stream 帧转成
696
- // assistant.stream 通知(老运行时的持久 assistant/chunk 已不存在)。
697
605
  this.handleAssistantStream(params);
698
606
  }
699
607
  else if (method === "session.status") {
700
608
  this.handleSessionStatus(params);
701
609
  }
702
610
  else if (method === "question.pending") {
703
- // 模型 ask_user_question → 转发给浏览器对话框(deadline = 服务端超时时间戳)。
704
611
  const params0 = params;
705
- // 问卷开关(默认开):关 → 不弹框,立即取消让模型得知已禁用。
706
612
  if (this.settings.questionnaireEnabled === false) {
707
613
  void this.answerQuestion(params0.id, [], true);
708
614
  return;
@@ -727,9 +633,6 @@ export class DshClientSession {
727
633
  : {}),
728
634
  ...(q.multiSelect ? { multiSelect: true } : {}),
729
635
  }));
730
- // 记下待答问卷:`question_pending` 只推给「当时在线」的连接,刷新页面
731
- // /WS 重连后靠快照(UiState.pendingQuestion)把对话框恢复出来。
732
- // DSH 的提问桥是 runtime 级的(无 conversationId),故不分对话。
733
636
  const dshConv = this.convs.get(this.activeId);
734
637
  const conversationTitle = dshConv?.title;
735
638
  this.pendingQuestion = {
@@ -750,7 +653,6 @@ export class DshClientSession {
750
653
  this.flushSnapshot();
751
654
  }
752
655
  else if (method === "tools.call.request") {
753
- // 工具桥(#15):模型调了插件工具 → 服务端跑插件实现 → tools/call-result 回传。
754
656
  void this.handleToolCallRequest(params);
755
657
  }
756
658
  }
@@ -759,10 +661,6 @@ export class DshClientSession {
759
661
  }
760
662
  });
761
663
  }
762
- /** 快照侧的待答问卷(UiState.pendingQuestion):重连/刷新后靠它恢复对话框。
763
- * DSH 的提问自带超时(goal-rpc 到点 reject),deadline 已过的不再下发——
764
- * 否则已经没人等的问卷会被重连的客户端当成活的弹出来。标准引擎不限时,
765
- * 没有 deadline,生命周期由回答/取消/dispose 精确终止。 */
766
664
  pendingQuestionForSnapshot() {
767
665
  const p = this.pendingQuestion;
768
666
  if (!p)
@@ -771,10 +669,7 @@ export class DshClientSession {
771
669
  return null;
772
670
  return p;
773
671
  }
774
- /** 前端回答模型提问(question/answer → runtime 恢复工具结果)。 */
775
672
  async answerQuestion(id, answers, cancelled) {
776
- // 无论成功失败都清掉待答快照:同 id 不会再有下一次,留着会让重连的客户端
777
- // 恢复到一张已经没人在等的问卷。
778
673
  if (this.pendingQuestion?.id === id)
779
674
  this.pendingQuestion = null;
780
675
  this.flushSnapshot();
@@ -790,11 +685,6 @@ export class DshClientSession {
790
685
  });
791
686
  }
792
687
  }
793
- // -----------------------------------------------------------------------
794
- // 工具桥(#15 插件注入点):服务端把插件工具注册进运行时,并执行模型对
795
- // 桥接工具的调用(tools.call.request → 插件 execute → tools/call-result)。
796
- // -----------------------------------------------------------------------
797
- /** 桥接的插件工具最小形状(对齐 plugins.ts 的 PluginAgentTool,仅取桥接所需字段)。 */
798
688
  bridgedTool(t) {
799
689
  const tool = t;
800
690
  if (!tool ||
@@ -814,7 +704,6 @@ export class DshClientSession {
814
704
  mcpProjectCwds() {
815
705
  return [...new Set([this.cwd, ...[...this.convs.values()].map((conv) => conv.cwd)])];
816
706
  }
817
- /** 把当前插件工具(pluginToolsProvider)同步注册进运行时(幂等,可重复调用)。 */
818
707
  async syncPluginTools() {
819
708
  if (!this.runtime.alive)
820
709
  return;
@@ -836,13 +725,6 @@ export class DshClientSession {
836
725
  console.error(`[dsh] syncPluginTools 失败 (client=${this.clientId}):`, err);
837
726
  }
838
727
  }
839
- /**
840
- * 取一条工具的**定义说明**(工具卡右键 → 「显示工具详细信息」)→ `tool_info`。
841
- *
842
- * DSH 侧的定义来自运行时(`tools/list`:DSH 原生工具 + 桥接进来的插件工具)。
843
- * 拿不到(运行时没起来 / RPC 报错)回 `unsupported`,让前端说「当前引擎不支持」
844
- * 而不是「未找到工具定义」—— 后者会让用户以为工具名写错了。
845
- */
846
728
  async getToolInfo(name) {
847
729
  if (!this.runtime.alive) {
848
730
  this.emit({ type: "tool_info", ...unsupportedToolInfo(name) });
@@ -858,7 +740,6 @@ export class DshClientSession {
858
740
  this.emit({ type: "tool_info", ...unsupportedToolInfo(name) });
859
741
  }
860
742
  }
861
- /** 从运行时拉取技能清单 → 缓存 → 重推 settings_state(enabled 由 disabledSkills 推导)。 */
862
743
  async refreshSkillsFromRuntime() {
863
744
  if (!this.runtime.alive)
864
745
  return;
@@ -878,11 +759,8 @@ export class DshClientSession {
878
759
  try {
879
760
  this.pushSettings();
880
761
  }
881
- catch {
882
- /* best effort */
883
- }
762
+ catch { }
884
763
  }
885
- /** 把禁用技能集合同步给运行时(晚 pre-step 钩子据此过滤 skill-catalog 消息)。 */
886
764
  async pushDisabledSkillsToRuntime() {
887
765
  if (!this.runtime.alive)
888
766
  return;
@@ -893,7 +771,6 @@ export class DshClientSession {
893
771
  console.error(`[dsh] setDisabledSkills 失败 (client=${this.clientId}):`, err);
894
772
  }
895
773
  }
896
- /** 模型调用桥接工具:找插件 execute,归一化结果,tools/call-result 回传。 */
897
774
  async handleToolCallRequest(params) {
898
775
  const id = String(params?.id ?? "");
899
776
  const name = String(params?.name ?? "");
@@ -942,7 +819,6 @@ export class DshClientSession {
942
819
  nextConversationId() {
943
820
  return `c${++this.convSeq}-${randomUUID().slice(0, 8)}`;
944
821
  }
945
- /** 每个会话独立的目标状态(默认来自客户端级偏好)。 */
946
822
  makeGoalStatus() {
947
823
  return {
948
824
  conversationId: null,
@@ -957,15 +833,12 @@ export class DshClientSession {
957
833
  wizard: { active: false, draft: "", model: null, step: 0, maxSteps: 3, status: "" },
958
834
  };
959
835
  }
960
- /** 未命名对话的默认标题(issue #91:按客户端语言,英文默认)。 */
961
836
  defaultTitle() {
962
837
  return pick(this.getLang(), DEFAULT_CONV_TITLE, DEFAULT_CONV_TITLE_EN, "dsh.conv.default.title");
963
838
  }
964
- /** 是否仍是默认(未命名)标题——中英都认,跨语言切换不丢命名判断。 */
965
839
  static isDefaultTitle(title) {
966
840
  return title === DEFAULT_CONV_TITLE || title === DEFAULT_CONV_TITLE_EN;
967
841
  }
968
- /** 新建(或切换)一个 conversation。existing 的 sessionId 续聊最近 JSONL。 */
969
842
  addConversation(sessionId, cwd, replay = true, preset, sessionFilePath) {
970
843
  const id = this.nextConversationId();
971
844
  const conv = {
@@ -990,9 +863,7 @@ export class DshClientSession {
990
863
  lastEventAt: Date.now(),
991
864
  listed: false,
992
865
  promptedSinceActive: false,
993
- terminals: new TerminalManager((msg) => this.emit(msg), cwd,
994
- // issue #91:终端输入错误按客户端 UI 语言出中英(英文默认)。
995
- () => this.getLang()),
866
+ terminals: new TerminalManager((msg) => this.emit(msg), cwd, () => this.getLang()),
996
867
  toolStartTimes: new Map(),
997
868
  tokens: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
998
869
  usageSeen: false,
@@ -1001,7 +872,6 @@ export class DshClientSession {
1001
872
  streamTurn: 0,
1002
873
  };
1003
874
  if (replay) {
1004
- // 从磁盘 JSONL 回放历史消息(DSH 事件流不重放历史)。
1005
875
  try {
1006
876
  let targetFile = sessionFilePath && existsSync(sessionFilePath) ? sessionFilePath : null;
1007
877
  if (!targetFile) {
@@ -1016,26 +886,19 @@ export class DshClientSession {
1016
886
  for (const m of conv.messages)
1017
887
  conv.messageIds.add(m.id);
1018
888
  conv.title = firstUserText(events, this.getLang());
1019
- // 回放定预设:日志记录(selected 事件/header)> 调用方指定 > 默认。
1020
889
  const logged = sessionLogPreset({ header, events });
1021
890
  conv.agentPreset = this.resolvePreset(logged ?? preset);
1022
- // 权限预设同理:permission/preset 事件最后一条为准(无则 null,激活时拉取)。
1023
891
  conv.permissionPreset = sessionLogPermission({ header, events });
1024
- // 底栏统计:日志里最后一次 usage(新版在 assistant/message.usage,0.1.1 在
1025
- // assistant/chunk 的 usage chunk)→ 切回历史会话立刻有上下文 / 缓存命中数字。
1026
892
  const loggedUsage = lastUsageFromEvents(events);
1027
893
  if (loggedUsage) {
1028
894
  conv.tokens = loggedUsage;
1029
895
  conv.usageSeen = true;
1030
896
  }
1031
- // 有历史消息 = 已开始的会话,预设锁定(官方语义)。
1032
897
  if (conv.messages.length > 0)
1033
898
  conv.presetLocked = true;
1034
899
  }
1035
900
  }
1036
- catch {
1037
- /* best effort */
1038
- }
901
+ catch { }
1039
902
  }
1040
903
  this.convs.set(conv.id, conv);
1041
904
  return conv;
@@ -1043,9 +906,6 @@ export class DshClientSession {
1043
906
  get conv() {
1044
907
  return this.convs.get(this.activeId);
1045
908
  }
1046
- // -----------------------------------------------------------------------
1047
- // 事件管线
1048
- // -----------------------------------------------------------------------
1049
909
  findConv(sessionId) {
1050
910
  for (const conv of this.convs.values()) {
1051
911
  if (conv.sessionId === sessionId)
@@ -1056,17 +916,13 @@ export class DshClientSession {
1056
916
  handleSessionEvent(params) {
1057
917
  const conv = this.findConv(params.sessionId);
1058
918
  if (!conv)
1059
- return; // 非本客户端 conversation(并发其他客户端)→ 忽略
919
+ return;
1060
920
  conv.lastEventAt = Date.now();
1061
921
  const ev = params.event;
1062
922
  switch (ev.type) {
1063
923
  case "user/message": {
1064
- // DSH 会注入系统内部消息(workspace 指令 / 运行时上下文快照 / 目标轮次
1065
- // prompt)——前端不显示(pi 引擎的 asides 同理),只保留真正的用户消息。
1066
924
  const srcKind = ev.data.source?.kind;
1067
925
  if (srcKind === "goal") {
1068
- // 目标轮次承认:不渲染,但更新轮数显示(round 由 source.round 携带)。
1069
- // P1-10:轮次达上限且仍未完成 → 提示轮尽。
1070
926
  const round = ev.data.source?.round;
1071
927
  if (round && conv.goal.goal && conv.id === this.activeId) {
1072
928
  conv.goal.round = round;
@@ -1089,8 +945,6 @@ export class DshClientSession {
1089
945
  const cleanText = text
1090
946
  .replace(/\n\[(?:文件引用|File reference|上传文件|Uploaded file|图片附件|Image attachment):[\s\S]*$/u, "")
1091
947
  .trim();
1092
- // 1. 优先查找是否有暂存的本地乐观用户消息(u-pending- 开头)
1093
- // DSH 运行时回抛的消息往往带有 \n[File reference: ...] 附件说明,需要替换原乐观消息避免出现两条气泡
1094
948
  const pendingIdx = conv.messages.findIndex((m) => m.role === "user" && typeof m.id === "string" && m.id.startsWith("u-pending-"));
1095
949
  if (pendingIdx !== -1) {
1096
950
  const pendingMsg = conv.messages[pendingIdx];
@@ -1099,7 +953,6 @@ export class DshClientSession {
1099
953
  conv.messageIds.delete(pendingMsg.id);
1100
954
  conv.messageIds.add(msg.id);
1101
955
  conv.messages[pendingIdx] = msg;
1102
- // 图片附件异步补图处理
1103
956
  const imgRefs = (ev.data.content ?? [])
1104
957
  .filter((b) => b?.type === "image")
1105
958
  .map((b) => b.attachment)
@@ -1110,7 +963,6 @@ export class DshClientSession {
1110
963
  break;
1111
964
  }
1112
965
  }
1113
- // 2. 重复文本(DSH 有时重放同一用户消息)→ 去重。
1114
966
  if (cleanText &&
1115
967
  conv.messages.some((m) => {
1116
968
  if (m.role !== "user")
@@ -1121,8 +973,6 @@ export class DshClientSession {
1121
973
  break;
1122
974
  }
1123
975
  this.appendMessage(conv, msg);
1124
- // 图片附件异步补图:DSH 事件里的 image 块只有 ref 没有像素,回读后
1125
- // 填 dataUrl 供前端显示(回放/事件流的图片块在本地乐观消息中已显示过)。
1126
976
  const imgRefs = (ev.data.content ?? [])
1127
977
  .filter((b) => b?.type === "image")
1128
978
  .map((b) => b.attachment)
@@ -1144,7 +994,6 @@ export class DshClientSession {
1144
994
  case "assistant/message": {
1145
995
  const msg = assistantMessageEventToUiMessage(ev.data);
1146
996
  if (msg) {
1147
- // 完整消息落地 → streaming 清空(避免重复)。
1148
997
  conv.streaming = null;
1149
998
  this.appendMessage(conv, msg);
1150
999
  }
@@ -1152,7 +1001,6 @@ export class DshClientSession {
1152
1001
  if (rawText && rawText.includes("[[")) {
1153
1002
  void this.markerSvc.handleAssistantText(conv.id, rawText);
1154
1003
  }
1155
- // 新版运行时的 usage 挂在这条持久事件上(老运行时没有 → undefined 保持原统计)。
1156
1004
  this.applyUsage(conv, ev.data.usage);
1157
1005
  break;
1158
1006
  }
@@ -1163,7 +1011,6 @@ export class DshClientSession {
1163
1011
  const startedAt = conv.toolStartTimes.get(msg?.toolCallId ?? "");
1164
1012
  if (msg)
1165
1013
  conv.toolStartTimes.delete(msg.toolCallId ?? "");
1166
- // bash 工具结束 → 后台任务端口 diff。
1167
1014
  const toolName = ev.data.toolName;
1168
1015
  if (toolName === "bash")
1169
1016
  void this.bg.trackAfterBash();
@@ -1186,8 +1033,6 @@ export class DshClientSession {
1186
1033
  break;
1187
1034
  }
1188
1035
  case "assistant/chunk": {
1189
- // 老运行时(0.1.1-rc.2)的持久直播 chunk;新版运行时没有这个事件(改发
1190
- // agent/assistant-stream 直播帧)→ 过渡期两边都在时只认直播帧,避免喂两遍。
1191
1036
  if (conv.liveChunks)
1192
1037
  break;
1193
1038
  const chunk = ev.data?.chunk;
@@ -1207,22 +1052,16 @@ export class DshClientSession {
1207
1052
  break;
1208
1053
  }
1209
1054
  case "goal/change": {
1210
- // DSH 原生目标状态机事件(create/edit/resume/complete/block/clear),
1211
- // 全量快照 → 翻译成 GoalStatus 推前端。权威源在运行时,本地只镜像。
1212
1055
  this.applyGoalChange(conv, ev.data);
1213
1056
  break;
1214
1057
  }
1215
1058
  case "turn/end": {
1216
1059
  conv.streaming = null;
1217
- // DSH 无法恢复已持久化会话(id collision)——abort 重启运行时后
1218
- // 原会话也变 "磁盘有日志无 live"。检测到 error → 自动 fork + 重发。
1219
- // 目标轮次由 goal-round-driver 自动续,这里不需要审查钩子。
1220
1060
  const reason = ev.data?.reason ?? {};
1221
1061
  if (reason.kind === "error" && /id collision/i.test(reason.error?.message ?? "") && !conv.fromDisk) {
1222
1062
  this.forkAndReprompt(conv);
1223
1063
  }
1224
1064
  else if (conv.turnWaiter) {
1225
- // 调研向导等本轮结束(completed 正常 / error 中断)。
1226
1065
  const w = conv.turnWaiter;
1227
1066
  conv.turnWaiter = undefined;
1228
1067
  if (reason.kind === "completed")
@@ -1240,7 +1079,6 @@ export class DshClientSession {
1240
1079
  break;
1241
1080
  }
1242
1081
  case "agent/inbox/spliced": {
1243
- // 用户 prompt 注入 → 清理 followUp 队列中已消费的文本。
1244
1082
  const inserted = ev.data?.inserted ?? [];
1245
1083
  const texts = inserted.map((m) => m.content?.find((c) => c.type === "text")?.text ?? "").filter(Boolean);
1246
1084
  if (texts.length > 0) {
@@ -1255,7 +1093,6 @@ export class DshClientSession {
1255
1093
  default:
1256
1094
  break;
1257
1095
  }
1258
- // 事件驱动快照(60ms 节流;边界事件立即)。
1259
1096
  if (ev.type === "turn/end" ||
1260
1097
  ev.type === "tool/result" ||
1261
1098
  ev.type === "assistant/message" ||
@@ -1266,21 +1103,13 @@ export class DshClientSession {
1266
1103
  this.scheduleSnapshot();
1267
1104
  }
1268
1105
  }
1269
- /**
1270
- * 新版运行时的直播帧处理。运行时逐 chunk 发 `agent/assistant-stream`(agent scope,
1271
- * host 侧要 `{ global: true }` 才收得到),wrapper(goal-rpc.mjs)转成本通知:
1272
- * { type: "start" | "chunk" | "end", attemptId, revision, index, time, chunk }
1273
- * chunk 形状与老运行时的 `assistant/chunk.data.chunk` 同构 → 共用 applyStreamChunk。
1274
- */
1275
1106
  handleAssistantStream(params) {
1276
1107
  const conv = this.findConv(params.sessionId);
1277
1108
  const frame = params.frame;
1278
- // 别家客户端的会话 / 子代理会话(不在本客户端 convs 里)→ 忽略。
1279
1109
  if (!conv || !frame || typeof frame.type !== "string")
1280
1110
  return;
1281
1111
  conv.lastEventAt = Date.now();
1282
1112
  if (frame.type === "start") {
1283
- // 新 attempt(含重试)→ 换锚点,丢掉上一 attempt 的累计内容(与官方 dsh-web 一致)。
1284
1113
  conv.liveChunks = true;
1285
1114
  conv.streaming = null;
1286
1115
  conv.streamAnchor = typeof frame.time === "number" && Number.isFinite(frame.time) ? frame.time : Date.now();
@@ -1289,28 +1118,18 @@ export class DshClientSession {
1289
1118
  return;
1290
1119
  }
1291
1120
  if (frame.type !== "chunk")
1292
- return; // end:结算由 assistant/message / turn/end 清
1121
+ return;
1293
1122
  conv.liveChunks = true;
1294
1123
  const chunk = frame.chunk;
1295
1124
  if (!chunk)
1296
1125
  return;
1297
1126
  if (!conv.streamAnchor) {
1298
- // 没收到 start(重连晚到)→ 用首帧补锚点。
1299
1127
  conv.streamAnchor = typeof frame.time === "number" && Number.isFinite(frame.time) ? frame.time : Date.now();
1300
1128
  conv.streamTurn = typeof frame.turn === "number" ? frame.turn : 0;
1301
1129
  }
1302
1130
  this.applyStreamChunk(conv, chunk, conv.streamAnchor, conv.streamTurn);
1303
- // 60ms 节流快照:与持久事件那条路一样,让 isStreaming / streamingMessage 进快照
1304
- // (delta 通道只负责内容增量,靠它保证状态一致 + 背压时仍能收敛)。
1305
1131
  this.scheduleSnapshot();
1306
1132
  }
1307
- /**
1308
- * 一个 model stream chunk → 会话:usage 进底栏统计,其余进 streamingMessage 累计器 +
1309
- * 实时 delta 通道(message_delta)。两条投递路径(老 assistant/chunk / 新直播帧)共用。
1310
- *
1311
- * @param anchorId - streamingMessage id 的锚(老 = chunk 事件 seq;新版 = 首帧 time)。
1312
- * @param turn - 所属 turn(累计器 id 用)。
1313
- */
1314
1133
  applyStreamChunk(conv, chunk, anchorId, turn) {
1315
1134
  if (chunk.type === "usage") {
1316
1135
  this.applyUsage(conv, chunk.usage);
@@ -1319,9 +1138,6 @@ export class DshClientSession {
1319
1138
  if (!conv.streaming)
1320
1139
  conv.streaming = new DshStreamAccumulator(anchorId, turn);
1321
1140
  conv.streaming.apply(chunk);
1322
- // message_delta 实时通道:本机快速完成时 60ms 延迟快照总被 assistant/message 抢跑
1323
- // (streaming 从未被捕捉)→ delta 直接走独立通道,保证逐 token 渲染
1324
- // (前端 patch streamingMessage)。只推给当前对话,其他对话靠快照。
1325
1141
  if (conv.id === this.conv.id && (chunk.type === "text-delta" || chunk.type === "reasoning-delta")) {
1326
1142
  this.emit({
1327
1143
  type: "message_delta",
@@ -1337,7 +1153,6 @@ export class DshClientSession {
1337
1153
  });
1338
1154
  }
1339
1155
  }
1340
- /** usage → 底栏统计(最近一次模型调用口径;缺字段 / 非对象保持原值)。 */
1341
1156
  applyUsage(conv, usage) {
1342
1157
  const next = normalizeDshUsage(usage);
1343
1158
  if (!next)
@@ -1357,7 +1172,6 @@ export class DshClientSession {
1357
1172
  finishTurnTiming(conv);
1358
1173
  conv.lastEventAt = Date.now();
1359
1174
  if (was && !conv.isStreaming) {
1360
- // run 结束:清 streaming + 刷新会话列表。
1361
1175
  conv.streaming = null;
1362
1176
  this.refreshConversationTitle(conv);
1363
1177
  this.scheduleSessionsRefresh();
@@ -1374,7 +1188,6 @@ export class DshClientSession {
1374
1188
  refreshConversationTitle(conv) {
1375
1189
  if (!DshClientSession.isDefaultTitle(conv.title))
1376
1190
  return;
1377
- // 从消息列表取第一个用户文本。
1378
1191
  const t = conv.messages
1379
1192
  .find((m) => m.role === "user")
1380
1193
  ?.content?.map((c) => ("text" in c ? c.text : ""))
@@ -1385,10 +1198,6 @@ export class DshClientSession {
1385
1198
  this.emitConversations();
1386
1199
  }
1387
1200
  }
1388
- // -----------------------------------------------------------------------
1389
- // 快照
1390
- // -----------------------------------------------------------------------
1391
- /** 立即推送(节流 60ms 合并突发)。 */
1392
1201
  flushSnapshot(forceFull = false) {
1393
1202
  if (this.disposed)
1394
1203
  return;
@@ -1411,12 +1220,9 @@ export class DshClientSession {
1411
1220
  if (this.disposed)
1412
1221
  return;
1413
1222
  const conv = this.conv;
1414
- // 拷贝一份:appendMessage 直接 push conv.messages,若把引用存进
1415
- // emittedMessages,prev/cur 就是同一数组,slice(prev.length) 恒为空。
1416
1223
  const cur = [...conv.messages];
1417
1224
  const prev = this.emittedMessages;
1418
1225
  const rev = ++this.snapRev;
1419
- // 增量:同一 conversation 且纯 append 时发 snapshot_delta。
1420
1226
  let incremental = !forceFull && prev !== null && this.emittedRev > 0 && prev.length <= cur.length;
1421
1227
  if (incremental && prev) {
1422
1228
  for (let i = 0; i < prev.length; i++) {
@@ -1455,9 +1261,7 @@ export class DshClientSession {
1455
1261
  return files[0];
1456
1262
  }
1457
1263
  }
1458
- catch {
1459
- /* ignore */
1460
- }
1264
+ catch { }
1461
1265
  return undefined;
1462
1266
  }
1463
1267
  buildLightState(rev) {
@@ -1473,7 +1277,6 @@ export class DshClientSession {
1473
1277
  total: tokens.input + tokens.output + tokens.cacheRead + tokens.cacheWrite,
1474
1278
  },
1475
1279
  cost: estimateCost(tokens),
1476
- // 最近一次请求的 prompt + 输出(usageSeen=false → tokens=null,前端显示 `—`)。
1477
1280
  contextUsage: dshContextUsage(conv.usageSeen ? tokens : null, DSH_CONTEXT_WINDOW),
1478
1281
  };
1479
1282
  return {
@@ -1495,7 +1298,6 @@ export class DshClientSession {
1495
1298
  id: this.model,
1496
1299
  name: this.modelDisplayName || (DSH_MODELS.find((m) => m.id === this.model)?.name ?? this.model),
1497
1300
  provider: this.modelProvider || "deepseek",
1498
- // dsh-llm-deepseek adapter:仅 vision-exp 模型 inputModalities 含 image
1499
1301
  vision: this.modelVision,
1500
1302
  },
1501
1303
  thinkingLevel: this.thinkingLevel,
@@ -1509,7 +1311,6 @@ export class DshClientSession {
1509
1311
  tools: [],
1510
1312
  version: ++this.version,
1511
1313
  piConfigured: this.isDshConfigured(),
1512
- // DSH 不需要 pi CLI:报 true 让 PiSetupModal 跳过“安装 pi”步骤,直达填 key 表单。
1513
1314
  piAgentInstalled: true,
1514
1315
  stats,
1515
1316
  };
@@ -1517,9 +1318,6 @@ export class DshClientSession {
1517
1318
  getCapabilities() {
1518
1319
  return DEFAULT_DSH_CAPABILITIES;
1519
1320
  }
1520
- // -----------------------------------------------------------------------
1521
- // socket / 通知
1522
- // -----------------------------------------------------------------------
1523
1321
  attachSink(send) {
1524
1322
  this.sinks.add(send);
1525
1323
  for (const msg of this.pendingNotices)
@@ -1613,9 +1411,6 @@ export class DshClientSession {
1613
1411
  getTerminalCwd(conversationId) {
1614
1412
  return (conversationId ? this.convs.get(conversationId) : this.conv)?.cwd ?? this.cwd;
1615
1413
  }
1616
- // -----------------------------------------------------------------------
1617
- // 对话管理
1618
- // -----------------------------------------------------------------------
1619
1414
  activeConversations() {
1620
1415
  let n = 0;
1621
1416
  for (const conv of this.convs.values())
@@ -1626,18 +1421,15 @@ export class DshClientSession {
1626
1421
  pendingMessages() {
1627
1422
  return 0;
1628
1423
  }
1629
- /** issue #145:本实例连接的 socket 数(0 = 标签页全关了,会话残留)。 */
1630
1424
  sinkCount() {
1631
1425
  return this.sinks.size;
1632
1426
  }
1633
- /** issue #145:按 sessionId 找本实例持有的对话(跨客户端查重的本机一半)。 */
1634
1427
  findConversationBySessionId(sessionId) {
1635
1428
  for (const conv of this.convs.values())
1636
1429
  if (conv.sessionId === sessionId)
1637
1430
  return conv;
1638
1431
  return undefined;
1639
1432
  }
1640
- /** issue #145:本实例在某 cwd 下正在跑的对话摘要(同项目并行感知用)。 */
1641
1433
  streamingInCwd(cwd) {
1642
1434
  const out = [];
1643
1435
  for (const conv of this.convs.values()) {
@@ -1647,7 +1439,6 @@ export class DshClientSession {
1647
1439
  }
1648
1440
  return out;
1649
1441
  }
1650
- /** issue #145:本实例所有正在跑的对话摘要(elsewhere 列表的本机一半)。 */
1651
1442
  streamingSummariesAll() {
1652
1443
  const out = [];
1653
1444
  for (const conv of this.convs.values()) {
@@ -1657,23 +1448,17 @@ export class DshClientSession {
1657
1448
  }
1658
1449
  return out;
1659
1450
  }
1660
- /** issue #145:其他客户端重推 conversations 用(elsewhere 刷新)。 */
1661
1451
  refreshExternalRunning() {
1662
1452
  if (this.disposed)
1663
1453
  return;
1664
1454
  this.emitConversations();
1665
1455
  }
1666
- /** 左栏展示口径(issue #140,与 pi 引擎同义):listed 之外,当前对话只要有
1667
- * 内容(DSH 的对话消息全在内存里,直接数 messages)也在列表里;空白新对话
1668
- * 不入列。只影响展示,不动 listed 的语义。 */
1669
1456
  shownInRunningList(conv) {
1670
1457
  return conv.id === this.activeId && conv.messages.length > 0;
1671
1458
  }
1672
1459
  emitConversations() {
1673
1460
  const list = [];
1674
1461
  for (const conv of this.convs.values()) {
1675
- // 被置换到后台的会话 + 当前对话(一旦有内容就是用户正在聊的那条,
1676
- // 不该在列表里缺席——issue #140;空白新对话仍然不入列)。
1677
1462
  if (!conv.listed && !this.shownInRunningList(conv))
1678
1463
  continue;
1679
1464
  const sf = this.guessSessionFile(conv);
@@ -1690,12 +1475,10 @@ export class DshClientSession {
1690
1475
  isSubagent: false,
1691
1476
  pinned: isPinned,
1692
1477
  ...(conv.terminals.countUserBlockingLive() > 0 ? { hasUserTerminals: true } : {}),
1693
- // DSH Agent 预设(左栏徽标/详情用;pi 引擎不填)。
1694
1478
  agentPreset: conv.agentPreset,
1695
1479
  presetLocked: conv.presetLocked,
1696
1480
  });
1697
1481
  }
1698
- // issue #145:流式集合签名变化 → 通知其他客户端重推(左栏「另一处正在运行」近实时)
1699
1482
  const sig = JSON.stringify([...this.convs.values()]
1700
1483
  .filter((c) => c.isStreaming)
1701
1484
  .map((c) => c.id)
@@ -1709,7 +1492,6 @@ export class DshClientSession {
1709
1492
  type: "conversations",
1710
1493
  conversations: list,
1711
1494
  activeId: this.activeId,
1712
- // 为空时缺省(老快照字节一致)
1713
1495
  ...(elsewhere.length > 0 ? { elsewhere } : {}),
1714
1496
  });
1715
1497
  }
@@ -1724,9 +1506,6 @@ export class DshClientSession {
1724
1506
  return true;
1725
1507
  return false;
1726
1508
  }
1727
- /** 语义同 pi 引擎的 newChat:true = 当前活动对话是可接收首条的空白新对话
1728
- * (/new <prompt> 靠它决定要不要把首条提示发出去)。preset = 新会话预设
1729
- * (复用空白会话时等价一次空白切换)。 */
1730
1509
  async newChat(preset, _ephemeral, onReady) {
1731
1510
  if (this.switchingWorkspace)
1732
1511
  return false;
@@ -1767,7 +1546,6 @@ export class DshClientSession {
1767
1546
  });
1768
1547
  return false;
1769
1548
  }
1770
- // 旧对话保留(listed 生命周期简化:不主动移除)。
1771
1549
  const prevModel = this.model;
1772
1550
  active.listed = this.shouldRetainDshConversation(active);
1773
1551
  const conv = this.addConversation(`chat-${randomUUID().slice(0, 12)}`, this.cwd, false, preset);
@@ -1794,7 +1572,6 @@ export class DshClientSession {
1794
1572
  return;
1795
1573
  }
1796
1574
  const prev = this.conv;
1797
- // 只看“用过”的存活终端:没动过的空 shell 不钉住 listed(与 pi 的 displaceActive 同口径)。
1798
1575
  prev.listed = this.shouldRetainDshConversation(prev);
1799
1576
  this.activeId = id;
1800
1577
  this.emitConversations();
@@ -1802,7 +1579,6 @@ export class DshClientSession {
1802
1579
  this.pushTerminals();
1803
1580
  this.pushSettings();
1804
1581
  this.flushSnapshot(true);
1805
- // 切会话带上权限值(cwd 变化走运行时重启,onStarted 会重拉)。
1806
1582
  void this.refreshActivePermission().catch(() => { });
1807
1583
  }
1808
1584
  removeConversation(id) {
@@ -1812,9 +1588,6 @@ export class DshClientSession {
1812
1588
  this.convs.delete(id);
1813
1589
  conv.terminals.killAll();
1814
1590
  }
1815
- // -----------------------------------------------------------------------
1816
- // prompt / 附件
1817
- // -----------------------------------------------------------------------
1818
1591
  async prompt(text, attachments, queue = false) {
1819
1592
  if (this.switchingWorkspace)
1820
1593
  return;
@@ -1831,12 +1604,10 @@ export class DshClientSession {
1831
1604
  this.flushSnapshot();
1832
1605
  return;
1833
1606
  }
1834
- // 斜杠命令拦截(内置 NATIVE + 插件 registerCommand);带附件时不拦截。
1835
1607
  const parsed = parseSlash(text);
1836
1608
  if (parsed && !attachments?.length) {
1837
1609
  const handled = await this.execSlash(parsed.name, parsed.args);
1838
1610
  if (handled) {
1839
- // 与 pi 一致:命令执行后强制刷一次快照(notice/状态变化立即可见)。
1840
1611
  this.flushSnapshot();
1841
1612
  return;
1842
1613
  }
@@ -1844,7 +1615,6 @@ export class DshClientSession {
1844
1615
  if (this.conv !== conv || this.switchingWorkspace)
1845
1616
  return;
1846
1617
  this.markerSvc.clearActions(conv.id);
1847
- // issue #145:同文件守卫 —— 别处正在跑同一 sessionId 时拒绝发送(不造第二个 writer)。
1848
1618
  const fileOwner = this.findSessionOwnerById?.(conv.sessionId);
1849
1619
  if (fileOwner && fileOwner.isStreaming) {
1850
1620
  this.emit({
@@ -1856,9 +1626,6 @@ export class DshClientSession {
1856
1626
  this.flushSnapshot();
1857
1627
  return;
1858
1628
  }
1859
- // issue #145:同项目并行感知(与 pi 引擎同语义;DSH 无 display:false 的
1860
- // custom 消息通道,提醒以前置系统文本随本轮发给运行时,用户气泡保持原文)。
1861
- // parallelReminderEnabled=false 时整段跳过。
1862
1629
  let sysPrefix = "";
1863
1630
  if (!conv.isStreaming && this.settings.parallelReminderEnabled !== false) {
1864
1631
  const localTitles = [...this.convs.values()]
@@ -1890,7 +1657,6 @@ export class DshClientSession {
1890
1657
  }
1891
1658
  }
1892
1659
  }
1893
- // Restore persisted sessions without changing their conversation/session identity.
1894
1660
  if (conv.fromDisk) {
1895
1661
  const runtime = this.runtime;
1896
1662
  const sessionId = conv.sessionId;
@@ -1913,7 +1679,6 @@ export class DshClientSession {
1913
1679
  return;
1914
1680
  conv.fromDisk = false;
1915
1681
  }
1916
- // 命名对话(首个 prompt)。
1917
1682
  if (DshClientSession.isDefaultTitle(conv.title) && text.trim()) {
1918
1683
  const trimmed = text.trim().replace(/\s+/g, " ");
1919
1684
  conv.title = trimmed.length > 30 ? `${trimmed.slice(0, 30)}…` : trimmed;
@@ -1921,13 +1686,6 @@ export class DshClientSession {
1921
1686
  }
1922
1687
  await this.promptConv(conv, text, attachments, queue, sysPrefix);
1923
1688
  }
1924
- /**
1925
- * Remove ONE queued prompt (the ✕ on a pending bubble). DSH queues are
1926
- * display-only — the prompt was already handed to the runtime inbox, so this
1927
- * only drops the pending bubble from the UI (there is no per-item runtime
1928
- * cancel). `index` is the clicked bubble's position (duplicate texts need
1929
- * it); mismatch or omission falls back to first-occurrence text match.
1930
- */
1931
1689
  removeQueued(kind, text, index, _id) {
1932
1690
  const conv = this.conv;
1933
1691
  const arr = kind === "steer" ? conv.queue.steering : conv.queue.followUp;
@@ -1937,8 +1695,6 @@ export class DshClientSession {
1937
1695
  }
1938
1696
  this.flushSnapshot();
1939
1697
  }
1940
- /** 向指定会话发提示(审查注入/重发用;不处理 fromDisk fork 与命名)。 */
1941
- /** 排空期拒绝新工作(与 pi 引擎同文案;存量运行继续)。 */
1942
1698
  quiesceBlocked() {
1943
1699
  if (!this.isQuiesced?.())
1944
1700
  return false;
@@ -1951,7 +1707,6 @@ export class DshClientSession {
1951
1707
  this.flushSnapshot();
1952
1708
  return true;
1953
1709
  }
1954
- /** 回放补图:按 ref 读回图片字节 → 填入消息的 image 块 dataUrl(失败静默保持占位)。 */
1955
1710
  async hydrateImageBlocks(conv, msg, refs) {
1956
1711
  if (this.disposed)
1957
1712
  return;
@@ -1963,7 +1718,6 @@ export class DshClientSession {
1963
1718
  }
1964
1719
  if (this.disposed)
1965
1720
  return;
1966
- // 找到该消息(可能已被去重跳过/会话已切换),原地填块。
1967
1721
  const target = conv.messages.find((m) => m.id === msg.id);
1968
1722
  if (!target)
1969
1723
  return;
@@ -1976,13 +1730,9 @@ export class DshClientSession {
1976
1730
  if (i > 0)
1977
1731
  this.flushSnapshot();
1978
1732
  }
1979
- catch {
1980
- /* 补图失败保持占位 */
1981
- }
1733
+ catch { }
1982
1734
  }
1983
- async promptConv(conv, text, attachments, _queue = false,
1984
- // issue #145 同项目并行提醒:只进运行时上下文,不进用户气泡。
1985
- sysPrefix = "") {
1735
+ async promptConv(conv, text, attachments, _queue = false, sysPrefix = "") {
1986
1736
  if (this.switchingWorkspace)
1987
1737
  return;
1988
1738
  const generation = this.workspaceGeneration;
@@ -1995,20 +1745,15 @@ export class DshClientSession {
1995
1745
  startTurnTiming(conv);
1996
1746
  conv.promptedSinceActive = true;
1997
1747
  conv.lastEventAt = Date.now();
1998
- // Agent 预设:运行时世代过期 → 重登 preset/assign(创建时消费;
1999
- // 已存在会话的登记永不消费,重启后新运行时建会话时正好用上)。
2000
1748
  if (conv.assignedGen !== this.runtimeGen) {
2001
1749
  try {
2002
1750
  await this.runtime.assignPreset(conv.sessionId, conv.agentPreset);
2003
1751
  conv.assignedGen = this.runtimeGen;
2004
1752
  }
2005
- catch {
2006
- /* legacy/运行时未就绪:创建走默认;best effort */
2007
- }
1753
+ catch { }
2008
1754
  }
2009
1755
  if (this.switchingWorkspace || generation !== this.workspaceGeneration)
2010
1756
  return;
2011
- // 新会话默认权限预设(与当前一致时 apply 无事件零噪音)。
2012
1757
  await this.ensurePermissionDefault(conv);
2013
1758
  if (this.switchingWorkspace || generation !== this.workspaceGeneration)
2014
1759
  return;
@@ -2028,7 +1773,6 @@ export class DshClientSession {
2028
1773
  const blocks = await this.buildContentBlocks(sysPrefix ? `${sysPrefix}${promptText}` : promptText, effectiveAttachments);
2029
1774
  if (this.switchingWorkspace || generation !== this.workspaceGeneration || conv.cwd !== this.cwd)
2030
1775
  return;
2031
- // 乐观落地用户消息(id 用暂定值;user/message 事件到达时按内容去重)。
2032
1776
  const optimistic = {
2033
1777
  id: `u-pending-${Date.now()}-${conv.deltaSeq++}`,
2034
1778
  role: "user",
@@ -2049,8 +1793,6 @@ export class DshClientSession {
2049
1793
  optimisticId = optimistic.id;
2050
1794
  this.appendMessage(conv, optimistic);
2051
1795
  if (conv.isStreaming) {
2052
- // DSH 无 mid-run steering:isStreaming 时入队(followUp),
2053
- // 运行时 inbox 在 run 结束后消费。入队后立即 flushSnapshot 让排队气泡上屏。
2054
1796
  conv.queue.followUp.push(text);
2055
1797
  followUpAdded = true;
2056
1798
  this.flushSnapshot();
@@ -2064,7 +1806,6 @@ export class DshClientSession {
2064
1806
  this.flushSnapshot();
2065
1807
  await this.runtime.prompt(conv.sessionId, blocks);
2066
1808
  }
2067
- // 首轮用户发言送达 → 预设锁定(官方语义;回放会话建时已锁)。
2068
1809
  if (!conv.presetLocked) {
2069
1810
  conv.presetLocked = true;
2070
1811
  this.emitConversations();
@@ -2073,7 +1814,6 @@ export class DshClientSession {
2073
1814
  catch (err) {
2074
1815
  if (!conv.isStreaming)
2075
1816
  finishTurnTiming(conv);
2076
- // 发送失败事务补偿:回滚乐观用户消息与排队气泡
2077
1817
  if (optimisticId) {
2078
1818
  const optIdx = conv.messages.findIndex((m) => m.id === optimisticId);
2079
1819
  if (optIdx !== -1) {
@@ -2095,7 +1835,6 @@ export class DshClientSession {
2095
1835
  }
2096
1836
  this.flushSnapshot();
2097
1837
  }
2098
- /** 会话历史 → 上下文文本(fork 时注入)。 */
2099
1838
  histToContext(conv) {
2100
1839
  return conv.messages
2101
1840
  .map((m) => {
@@ -2105,15 +1844,12 @@ export class DshClientSession {
2105
1844
  .filter(Boolean)
2106
1845
  .join("\n");
2107
1846
  }
2108
- /** 新建 fork 会话并切换到它(DSH 无法原地续聊旧会话)。 */
2109
1847
  forkConversation(prev) {
2110
1848
  const fork = this.addConversation(`fork-${randomUUID().slice(0, 12)}`, this.cwd, false, prev.agentPreset);
2111
1849
  fork.title = prev.title;
2112
- // 继承原会话的所有消息历史,使得 UI 界面上完整保留所有轮次的历史消息
2113
1850
  fork.messages = [...prev.messages];
2114
1851
  fork.messageIds = new Set(prev.messageIds);
2115
1852
  this.activeId = fork.id;
2116
- // P2-19:原会话有 active goal(DSH same-session 语义)→ 提示随会话存档。
2117
1853
  const hadGoal = prev.goal.goal !== null && prev.goal.verdict === "pending";
2118
1854
  this.emitConversations();
2119
1855
  this.emit({
@@ -2128,11 +1864,9 @@ export class DshClientSession {
2128
1864
  });
2129
1865
  return fork;
2130
1866
  }
2131
- /** turn/end 报 id collision(abort 重启运行时后会话不再 live)→ fork + 重发最后提问。 */
2132
1867
  forkAndReprompt(conv) {
2133
1868
  if (this.disposed)
2134
1869
  return;
2135
- // 找最后一条用户消息作为重发文本。
2136
1870
  let lastUser = "";
2137
1871
  for (let i = conv.messages.length - 1; i >= 0; i--) {
2138
1872
  const m = conv.messages[i];
@@ -2158,8 +1892,6 @@ export class DshClientSession {
2158
1892
  });
2159
1893
  void this.prompt(text);
2160
1894
  }
2161
- /** 附件 → DSH contentBlocks(v1 简化:文本内联 / 路径引用 / 图片占位)。 */
2162
- /** dataUrl(data:image/png;base64,XXX)→ {mediaType, base64};无前缀按 PNG 处理。 */
2163
1895
  static splitImageDataUrl(data) {
2164
1896
  const m = /^data:([^;,]+);base64,([\s\S]*)$/u.exec(data);
2165
1897
  if (m && m[2])
@@ -2191,7 +1923,6 @@ export class DshClientSession {
2191
1923
  }
2192
1924
  const resolved = a.path ? workspacePath(this.cwd, a.path) : null;
2193
1925
  if (a.imageData) {
2194
- // 视觉桥:base64 图片 → attachment store → 真 image 块(模型可看图)。
2195
1926
  try {
2196
1927
  const { mediaType, base64 } = DshClientSession.splitImageDataUrl(a.imageData);
2197
1928
  const saved = await this.runtime.attachmentSave(mediaType, base64, a.name);
@@ -2205,7 +1936,6 @@ export class DshClientSession {
2205
1936
  }
2206
1937
  }
2207
1938
  else if (a.fileData) {
2208
- // 上传文件 → 落盘 + 路径引用。
2209
1939
  try {
2210
1940
  const maxBytes = (this.stateStore.getSettingsSnapshot(this.clientId).chatUploadMaxMb ?? 20) * 1024 * 1024;
2211
1941
  if (a.fileData.length > Math.ceil(maxBytes / 3) * 4)
@@ -2227,9 +1957,6 @@ export class DshClientSession {
2227
1957
  }
2228
1958
  }
2229
1959
  else if (resolved) {
2230
- // 一律只给路径引用:不再把文件内容注入 prompt(小文件也一样),模型用
2231
- // 自己的读取工具按需读。行范围模式带上行号提示。
2232
- // 工作区图片文件仍走 attachment store → 真 image 块(模型可看图)。
2233
1960
  const refText = pick(lang, `\n[文件引用: ${resolved.rel}]`, `\n[File reference: ${resolved.rel}]`, "dsh.attach.file.ref", {
2234
1961
  "resolved.rel": resolved.rel,
2235
1962
  }) +
@@ -2241,9 +1968,7 @@ export class DshClientSession {
2241
1968
  const st = statSync(resolved.abs);
2242
1969
  isImage = st.isFile() && st.size > 0 && st.size <= 512 * 1024 && previewKind(resolved.abs) === "image";
2243
1970
  }
2244
- catch {
2245
- /* 不存在/不可读 → 照样给路径引用,读取工具会自己报错 */
2246
- }
1971
+ catch { }
2247
1972
  if (isImage) {
2248
1973
  try {
2249
1974
  const buf = readFileSync(resolved.abs);
@@ -2278,7 +2003,6 @@ export class DshClientSession {
2278
2003
  }
2279
2004
  return blocks;
2280
2005
  }
2281
- /** 中止:kill 运行时进程树(所有 conversation 的运行停止)→ 自动重启保持可用。 */
2282
2006
  async abort() {
2283
2007
  this.cancelBridgedTools();
2284
2008
  if (!this.runtime.alive)
@@ -2288,15 +2012,11 @@ export class DshClientSession {
2288
2012
  conv.isStreaming = false;
2289
2013
  conv.streaming = null;
2290
2014
  this.emitConversations();
2291
- // 手动停止 → 清当前会话的 DSH 原生目标(半成品运行不该继续被轮次驱动)。
2292
- // 旧进程还活着,先 goal/clear 落盘,再重启运行时。
2293
2015
  if (conv.dsGoal || conv.goal.goal) {
2294
2016
  try {
2295
2017
  await this.runtime.goalClear(conv.sessionId);
2296
2018
  }
2297
- catch {
2298
- /* 进程可能已死,事件兜底 */
2299
- }
2019
+ catch { }
2300
2020
  conv.dsGoal = null;
2301
2021
  conv.goal.goal = null;
2302
2022
  conv.goal.conversationId = null;
@@ -2327,7 +2047,6 @@ export class DshClientSession {
2327
2047
  this.flushSnapshot(true);
2328
2048
  }
2329
2049
  async abortBash() {
2330
- // DSH 无 per-tool 取消;bash 工具由运行时管理,超时策略在运行时侧。
2331
2050
  this.emit({
2332
2051
  type: "notice",
2333
2052
  level: "info",
@@ -2335,9 +2054,6 @@ export class DshClientSession {
2335
2054
  textEn: "The DSH engine cannot stop bash alone (stop the whole conversation instead)",
2336
2055
  });
2337
2056
  }
2338
- /** 手动重试上次失败的模型调用:找到最后一条用户提问并重发一次
2339
- * (DSH 运行时以 prompt 驱动回合,无 triggerTurn 语义)。流式中 /
2340
- * 无可重试失败时只发 notice 拒绝。 */
2341
2057
  async retryLast() {
2342
2058
  const conv = this.conv;
2343
2059
  try {
@@ -2394,9 +2110,6 @@ export class DshClientSession {
2394
2110
  }
2395
2111
  this.flushSnapshot();
2396
2112
  }
2397
- // -----------------------------------------------------------------------
2398
- // 后台任务
2399
- // -----------------------------------------------------------------------
2400
2113
  async listBgServers() {
2401
2114
  await this.bg.listAndPush();
2402
2115
  }
@@ -2422,11 +2135,9 @@ export class DshClientSession {
2422
2135
  this.bg.push();
2423
2136
  return killed;
2424
2137
  }
2425
- /** 钉住 / 取消钉住(DSH 引擎同样有后台任务面板,行为与 pi 引擎一致)。 */
2426
2138
  setBackgroundKeep(port, keep) {
2427
2139
  return this.bg.setKeep(port, keep);
2428
2140
  }
2429
- /** 手动「立即清理」(阈值策略与 pi 引擎同源:设置里的 bgAutoCleanupMin,关时兼底 30 分钟)。 */
2430
2141
  async cleanBackgroundLeftovers(minutesOverride) {
2431
2142
  const override = Number(minutesOverride);
2432
2143
  const policy = Number(this.settings.bgAutoCleanupMin ?? 0);
@@ -2434,9 +2145,6 @@ export class DshClientSession {
2434
2145
  const thresholdMs = (minutes > 0 ? minutes : BG_CLEANUP_FALLBACK_MIN) * 60_000;
2435
2146
  return this.bg.cleanStale(thresholdMs, { manual: true });
2436
2147
  }
2437
- // -----------------------------------------------------------------------
2438
- // 会话列表 / 切换 / 删除
2439
- // -----------------------------------------------------------------------
2440
2148
  sessionsTimer = null;
2441
2149
  scheduleSessionsRefresh() {
2442
2150
  if (this.sessionsTimer)
@@ -2454,22 +2162,17 @@ export class DshClientSession {
2454
2162
  }
2455
2163
  async pushSessions() {
2456
2164
  try {
2457
- // 目录/会话文件被删除、改名或不可读都不许把异常抛出去:本方法以
2458
- // fire-and-forget(void …)方式调用,未处理的 rejection 会杀死服务进程
2459
- // (issue #74 同类)。失败降级为空列表,面板显示“暂无历史”。
2460
2165
  const files = findSessionFilesForCwd(this.sessionRoot, this.cwd);
2461
2166
  const summaries = [];
2462
2167
  for (const file of files) {
2463
2168
  try {
2464
2169
  const sessionId = basename(dirname(file));
2465
- // 审查会话(review-*)是内部工作会话,不进历史列表。
2466
2170
  if (sessionId.startsWith("review-"))
2467
2171
  continue;
2468
2172
  const { events } = readSessionLog(file);
2469
2173
  const count = events.filter((e) => (e.type === "user/message" && !isDshInternalUserMessage(e.data)) ||
2470
2174
  e.type === "assistant/message" ||
2471
2175
  e.type === "tool/result").length;
2472
- // 过滤无消息空会话(仅有初始化 preset 事件的空壳不展示在历史列表)
2473
2176
  if (count === 0)
2474
2177
  continue;
2475
2178
  const isPinned = Boolean(this.stateStore?.isSessionPinned(this.cwd, file) || this.stateStore?.isSessionPinned(this.cwd, sessionId));
@@ -2493,9 +2196,7 @@ export class DshClientSession {
2493
2196
  pinned: isPinned,
2494
2197
  });
2495
2198
  }
2496
- catch {
2497
- /* skip unreadable */
2498
- }
2199
+ catch { }
2499
2200
  }
2500
2201
  this.emit({ type: "sessions", sessions: summaries });
2501
2202
  }
@@ -2503,7 +2204,6 @@ export class DshClientSession {
2503
2204
  this.emit({ type: "sessions", sessions: [] });
2504
2205
  }
2505
2206
  }
2506
- /** 引擎自属的会话展示名解析回调(定制 DSH 的首条提取 + 模型自动总结命名 + 用户显式重命名记忆) */
2507
2207
  resolveSessionDisplayName(sessionId, explicitTitle, firstMsg) {
2508
2208
  const storedTitle = this.stateStore?.getSessionTitle(this.cwd, sessionId);
2509
2209
  if (storedTitle && !DshClientSession.isDefaultTitle(storedTitle)) {
@@ -2636,8 +2336,6 @@ export class DshClientSession {
2636
2336
  }
2637
2337
  }
2638
2338
  async dismissConversation(id, _withFinishedSubagents, force) {
2639
- // DSH 引擎无第一方子代理:withFinishedSubagents 恒为 no-op(签名与标准引擎对齐)。
2640
- // force 放行 active/终端限制;运行中仍拒绝(DSH 单 runtime 无法单独 abort 一个对话,请先点停止)。
2641
2339
  const conv = this.convs.get(id);
2642
2340
  if (!conv) {
2643
2341
  this.emit({
@@ -2670,7 +2368,6 @@ export class DshClientSession {
2670
2368
  });
2671
2369
  return;
2672
2370
  }
2673
- // issue #181:只看用户终端——AI bash 随对话一起释放,不得阻断移出。
2674
2371
  if (conv.terminals.countUserBlockingLive() > 0 && !force) {
2675
2372
  this.emit({
2676
2373
  type: "notice",
@@ -2680,8 +2377,6 @@ export class DshClientSession {
2680
2377
  });
2681
2378
  return;
2682
2379
  }
2683
- // 没动过的空 shell与 AI bash 不拦截:随对话一起释放。
2684
- // force + active:先让出 active(切到其他对话或新建),再移除。
2685
2380
  if (id === this.activeId) {
2686
2381
  const other = [...this.convs.values()].find((c) => c.id !== id);
2687
2382
  if (other)
@@ -2702,8 +2397,6 @@ export class DshClientSession {
2702
2397
  this.emitConversations();
2703
2398
  this.flushSnapshot();
2704
2399
  }
2705
- /** DSH 引擎无第一方子代理(emitConversations 恒 isSubagent:false):批量
2706
- * 关闭退化为空操作提示,保持与 pi 引擎同一 wire 行为。 */
2707
2400
  async dismissFinishedSubagents(_parentId) {
2708
2401
  this.emit({
2709
2402
  type: "notice",
@@ -2712,14 +2405,12 @@ export class DshClientSession {
2712
2405
  textEn: "No finished subagents to dismiss",
2713
2406
  });
2714
2407
  }
2715
- /** 切换会话:读 JSONL 回放 → 新建 conversation(同一 sessionId 续聊)。 */
2716
2408
  async switchSession(path, wantSessionId) {
2717
2409
  assertEngineWorkspaceSupported(this.sandboxes, this.cwd, "dsh");
2718
2410
  try {
2719
2411
  const resolvedPath = path.trim() ? resolve(path.trim()) : "";
2720
2412
  const explicitSid = wantSessionId?.trim() ?? "";
2721
2413
  const sessionId = explicitSid || (resolvedPath ? basename(dirname(resolvedPath)) : "");
2722
- // 同一 sessionId 已在运行 → 直接切过去。
2723
2414
  for (const conv of this.convs.values()) {
2724
2415
  if (conv.sessionId === sessionId || conv.id === sessionId) {
2725
2416
  await this.switchConversation(conv.id);
@@ -2748,7 +2439,6 @@ export class DshClientSession {
2748
2439
  return;
2749
2440
  }
2750
2441
  }
2751
- // issue #145:同 pi 引擎 —— 别处正在跑同一 sessionId 时不建第二个持有者。
2752
2442
  const owner = this.findSessionOwnerById?.(sessionId);
2753
2443
  if (owner && owner.isStreaming) {
2754
2444
  this.emit({
@@ -2761,7 +2451,6 @@ export class DshClientSession {
2761
2451
  return;
2762
2452
  }
2763
2453
  if (owner) {
2764
- // 对端已断开(标签页关了)只剩残留会话 —— 不打扰,直接开。
2765
2454
  if (owner.connected) {
2766
2455
  this.emit({
2767
2456
  type: "notice",
@@ -2772,10 +2461,9 @@ export class DshClientSession {
2772
2461
  }
2773
2462
  }
2774
2463
  const prev = this.conv;
2775
- // 只看“用过”的存活终端:没动过的空 shell 不钉住 listed(与 pi 的 displaceActive 同口径)。
2776
2464
  prev.listed = this.shouldRetainDshConversation(prev);
2777
2465
  const conv = this.addConversation(sessionId, this.cwd, true, undefined, resolvedPath || undefined);
2778
- conv.fromDisk = true; // 磁盘回放 → prompt 时 fork
2466
+ conv.fromDisk = true;
2779
2467
  if (resolvedPath)
2780
2468
  conv.sessionFile = resolvedPath;
2781
2469
  this.activeId = conv.id;
@@ -2811,14 +2499,9 @@ export class DshClientSession {
2811
2499
  });
2812
2500
  }
2813
2501
  }
2814
- // -----------------------------------------------------------------------
2815
- // 用户 patch 扩展缝(<dataDir>/dsh-patches/*.yml)
2816
- // -----------------------------------------------------------------------
2817
- /** 用户 patch 目录。 */
2818
2502
  userPatchDir() {
2819
2503
  return join(this.dataDir, "dsh-patches");
2820
2504
  }
2821
- /** 列出 <dataDir>/dsh-patches/*.yml 以及 *.yml.disabled(按文件名序),带文件信息与启停状态。 */
2822
2505
  async listDshPatches() {
2823
2506
  const dir = this.userPatchDir();
2824
2507
  const files = [];
@@ -2843,18 +2526,13 @@ export class DshClientSession {
2843
2526
  });
2844
2527
  }
2845
2528
  }
2846
- catch {
2847
- /* skip unreadable */
2848
- }
2529
+ catch { }
2849
2530
  }
2850
2531
  }
2851
- catch {
2852
- /* 目录不存在 = 无用户 patch */
2853
- }
2532
+ catch { }
2854
2533
  files.sort((a, b) => a.name.localeCompare(b.name));
2855
2534
  this.emit({ type: "dsh_patches", patchDir: dir, files });
2856
2535
  }
2857
- /** 重扫用户 patch:重启运行时使新 patch 生效(patch 只在 boot 时加载)。 */
2858
2536
  async rescanDshPatches() {
2859
2537
  try {
2860
2538
  if (this.runtime.alive) {
@@ -2877,7 +2555,6 @@ export class DshClientSession {
2877
2555
  }
2878
2556
  await this.listDshPatches();
2879
2557
  }
2880
- /** 安装/添加 DSH 用户 patch(写入 <dataDir>/dsh-patches/<id>.yml 并重载运行时)。 */
2881
2558
  async installDshPatch(rawSpec, rawId) {
2882
2559
  const spec = rawSpec.trim().replace(/^['"]|['"]$/g, "");
2883
2560
  if (!spec) {
@@ -2889,7 +2566,6 @@ export class DshClientSession {
2889
2566
  });
2890
2567
  return;
2891
2568
  }
2892
- // 推导合法 id(仅允许字母数字横线下划线)
2893
2569
  let id = (rawId ?? "").trim();
2894
2570
  if (!id) {
2895
2571
  const base = basename(spec.replace(/[\\/]+$/, ""));
@@ -2898,7 +2574,6 @@ export class DshClientSession {
2898
2574
  id = id.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || `patch-${Date.now().toString(36)}`;
2899
2575
  const dir = this.userPatchDir();
2900
2576
  mkdirSync(dir, { recursive: true });
2901
- // 规范化包名/路径:Windows 路径转为正斜杠以确保 YAML 兼容性
2902
2577
  const normalizedSpec = spec.replace(/\\/g, "/");
2903
2578
  const escapedName = normalizedSpec.replace(/'/g, "''");
2904
2579
  const yamlContent = `# DSH user patch generated by pi-web-ui\n- insert:\n - id: ${id}\n name: '${escapedName}'\n config: {}\n`;
@@ -2927,7 +2602,6 @@ export class DshClientSession {
2927
2602
  }
2928
2603
  await this.rescanDshPatches();
2929
2604
  }
2930
- /** 切换 DSH 用户 patch 启用/停用状态(重命名为 *.yml.disabled 或 *.yml)。 */
2931
2605
  async toggleDshPatch(name, enabled) {
2932
2606
  const safeName = basename(name);
2933
2607
  if (!safeName || safeName !== name) {
@@ -2959,7 +2633,6 @@ export class DshClientSession {
2959
2633
  }
2960
2634
  await this.rescanDshPatches();
2961
2635
  }
2962
- /** 删除指定的 DSH 用户 patch 文件并重启运行时。 */
2963
2636
  async deleteDshPatch(name) {
2964
2637
  const safeName = basename(name);
2965
2638
  if (!safeName || safeName !== name) {
@@ -2991,7 +2664,6 @@ export class DshClientSession {
2991
2664
  }
2992
2665
  await this.rescanDshPatches();
2993
2666
  }
2994
- /** 拉取 DSH 插件市场数据并推送给客户端。 */
2995
2667
  async fetchDshMarket(force = false) {
2996
2668
  try {
2997
2669
  const data = await loadDshMarketData(this.dataDir, force);
@@ -3012,9 +2684,6 @@ export class DshClientSession {
3012
2684
  });
3013
2685
  }
3014
2686
  }
3015
- // -----------------------------------------------------------------------
3016
- // 项目 / 文件 / SCM / 搜索
3017
- // -----------------------------------------------------------------------
3018
2687
  async pushProjects() {
3019
2688
  const recent = await this.stateStore.getRecentProjects(this.clientId);
3020
2689
  const removedKeys = new Set(this.stateStore.getRemovedProjects(this.clientId).map(normalizePathKey));
@@ -3024,7 +2693,6 @@ export class DshClientSession {
3024
2693
  projects.set(p.path, p.lastUsed);
3025
2694
  }
3026
2695
  }
3027
- // 合并当前会话目录发现的项目。
3028
2696
  const cwdProjects = new Set();
3029
2697
  try {
3030
2698
  const { readdirSync } = await import("node:fs");
@@ -3037,9 +2705,7 @@ export class DshClientSession {
3037
2705
  }
3038
2706
  }
3039
2707
  }
3040
- catch {
3041
- /* best effort */
3042
- }
2708
+ catch { }
3043
2709
  for (const cwd of cwdProjects)
3044
2710
  projects.set(cwd, Date.now());
3045
2711
  if (!removedKeys.has(normalizePathKey(this.cwd))) {
@@ -3066,7 +2732,6 @@ export class DshClientSession {
3066
2732
  this.emit({ type: "projects", projects: list });
3067
2733
  }
3068
2734
  decodeProjectKey(key) {
3069
- // --<cwd>-- → 反解(尽力)。
3070
2735
  if (!key.startsWith("--") || !key.endsWith("--"))
3071
2736
  return null;
3072
2737
  const inner = key.slice(2, -2);
@@ -3261,8 +2926,6 @@ export class DshClientSession {
3261
2926
  }
3262
2927
  await this.setCwd(fallbackCwd);
3263
2928
  }
3264
- // 清理仍挂在该沙盒下的后台会话(含子目录 cwd)——ClientSession 版有此步,
3265
- // DSH 版此前完全没有:销毁后这些对话的 runtime/终端指向已删目录
3266
2929
  for (const [id, conv] of this.convs) {
3267
2930
  if (id !== this.activeId && isSameOrSubpath(conv.cwd, sbx.path)) {
3268
2931
  this.removeConversation(id);
@@ -3311,7 +2974,6 @@ export class DshClientSession {
3311
2974
  const texts = [];
3312
2975
  const anchors = [];
3313
2976
  for (const ev of events) {
3314
- // P1-14:索引范围 = user/assistant 文本 + tool-result 工具输出。
3315
2977
  if (ev.type === "user/message" || ev.type === "assistant/message" || ev.type === "tool/result") {
3316
2978
  if (ev.type === "user/message" && isDshInternalUserMessage(ev.data))
3317
2979
  continue;
@@ -3320,7 +2982,6 @@ export class DshClientSession {
3320
2982
  [];
3321
2983
  let text = blocks.map((b) => (b?.type === "text" ? (b.text ?? "") : "")).join("\n");
3322
2984
  if (ev.type === "tool/result") {
3323
- // 工具输出在嵌套 content[](tool-result 块内),一并纳入索引。
3324
2985
  const nested = blocks
3325
2986
  .filter((b) => b?.type === "tool-result")
3326
2987
  .flatMap((b) => b.content ?? [])
@@ -3341,7 +3002,6 @@ export class DshClientSession {
3341
3002
  }
3342
3003
  const all = texts.join("\n").toLowerCase();
3343
3004
  const sessionId = basename(dirname(file));
3344
- // 审查会话不进搜索。
3345
3005
  if (sessionId.startsWith("review-"))
3346
3006
  continue;
3347
3007
  const firstMsg = firstUserText(events, this.getLang());
@@ -3365,9 +3025,7 @@ export class DshClientSession {
3365
3025
  });
3366
3026
  }
3367
3027
  }
3368
- catch {
3369
- /* skip unreadable */
3370
- }
3028
+ catch { }
3371
3029
  }
3372
3030
  results.sort((a, b) => b.modified - a.modified);
3373
3031
  this.emit({ type: "session_search_results", reqId, query, ok: true, results: results.slice(0, 50) });
@@ -3377,8 +3035,6 @@ export class DshClientSession {
3377
3035
  }
3378
3036
  }
3379
3037
  async scmQuery(kind, reqId, opts) {
3380
- // 走 FilesService:只读 git 查询 + git-dir watcher(外部提交 → scm_changed
3381
- // 面板自动刷新)+ 越界/notRepo 统一处理。
3382
3038
  await this.files.scmQuery(kind, reqId, opts);
3383
3039
  }
3384
3040
  async readFile(relPath) {
@@ -3390,7 +3046,6 @@ export class DshClientSession {
3390
3046
  async uploadFile(dirRel, name, data, uploadId) {
3391
3047
  await this.files.uploadFile(dirRel, name, data, uploadId);
3392
3048
  }
3393
- /** 文件树右键菜单:新建/重命名/删除/复制移动(FilesService 直透传)。 */
3394
3049
  async createEntry(dir, name, kind) {
3395
3050
  await this.files.createEntry(dir, name, kind);
3396
3051
  }
@@ -3403,7 +3058,6 @@ export class DshClientSession {
3403
3058
  async copyEntry(src, destDir, move) {
3404
3059
  await this.files.copyEntry(src, destDir, move);
3405
3060
  }
3406
- /** 文件树右键菜单:在资源管理器中定位 / 默认应用打开(issue #187)。 */
3407
3061
  async revealEntry(path) {
3408
3062
  await this.files.revealEntry(path);
3409
3063
  }
@@ -3419,30 +3073,20 @@ export class DshClientSession {
3419
3073
  await this.setCwd(created);
3420
3074
  }
3421
3075
  }
3422
- // -----------------------------------------------------------------------
3423
- // 模型 / 思考
3424
- // -----------------------------------------------------------------------
3425
- /** P2-17 动态与自定义模型 id 缓存(adapter 目录与 models.json 自定义模型;setModel 校验用)。 */
3426
3076
  dynamicModels = new Set();
3427
- /** 缓存自定义模型及动态适配器模型元数据,用于 setModel 快速解析。 */
3428
3077
  customModelsMap = new Map();
3429
3078
  async listModels() {
3430
- // 以本地表为底(定价/上下文窗口/vision 标记),运行时 adapter 目录与 models.json 自定义模型动态
3431
- // 扩展——新模型自动出现在选择器,无需改代码。
3432
3079
  const known = new Map(DSH_MODELS.map((m) => [m.id, m]));
3433
3080
  let dynamic = [];
3434
3081
  try {
3435
3082
  const res = await this.runtime.listModels();
3436
3083
  dynamic = res.models ?? [];
3437
3084
  }
3438
- catch {
3439
- /* 运行时不可用 → 只发本地表 */
3440
- }
3085
+ catch { }
3441
3086
  const seen = new Set();
3442
3087
  const models = [];
3443
3088
  this.dynamicModels.clear();
3444
3089
  this.customModelsMap.clear();
3445
- // 1. DSH 官方内置模型
3446
3090
  for (const m of DSH_MODELS) {
3447
3091
  const canonicalId = `deepseek/${m.id}`;
3448
3092
  seen.add(m.id);
@@ -3467,7 +3111,6 @@ export class DshClientSession {
3467
3111
  vision: m.vision,
3468
3112
  });
3469
3113
  }
3470
- // 2. 运行时动态目录(adapter 发现)
3471
3114
  for (const m of dynamic) {
3472
3115
  const canonicalId = m.id.includes("/") ? m.id : `deepseek/${m.id}`;
3473
3116
  const bareId = m.id.includes("/") ? m.id.slice(m.id.indexOf("/") + 1) : m.id;
@@ -3498,7 +3141,6 @@ export class DshClientSession {
3498
3141
  vision,
3499
3142
  });
3500
3143
  }
3501
- // 3. 用户在 models.json 中配置的第三方自定义端点模型(针对性过滤 DSH 不支持的协议,如 anthropic-messages)
3502
3144
  try {
3503
3145
  const custom = listCustomModelsFromConfig(this.agentDir, (entry) => isModelProtocolSupportedByEngine("dsh", entry));
3504
3146
  for (const c of custom) {
@@ -3528,12 +3170,9 @@ export class DshClientSession {
3528
3170
  });
3529
3171
  }
3530
3172
  }
3531
- catch {
3532
- /* models.json 不存在或解析错误 → 静默忽略 */
3533
- }
3173
+ catch { }
3534
3174
  this.emit({ type: "models", models });
3535
3175
  }
3536
- /** 解析模型 ID 对应的服务商、元数据与裸模型 ID。 */
3537
3176
  resolveModelMeta(modelId) {
3538
3177
  const normId = modelId.trim();
3539
3178
  const hasSlash = normId.includes("/");
@@ -3567,9 +3206,7 @@ export class DshClientSession {
3567
3206
  };
3568
3207
  }
3569
3208
  }
3570
- catch {
3571
- /* ignore */
3572
- }
3209
+ catch { }
3573
3210
  }
3574
3211
  }
3575
3212
  if (meta) {
@@ -3585,7 +3222,6 @@ export class DshClientSession {
3585
3222
  this.dynamicModels.has(bareModelId);
3586
3223
  return { meta, targetProvider, bareModelId, known };
3587
3224
  }
3588
- /** 应用已保存的模型配置到当前 session 实例(启动/恢复/切换工作区时用)。 */
3589
3225
  applySavedModel(modelId) {
3590
3226
  const res = this.resolveModelMeta(modelId);
3591
3227
  if (res.known || res.meta) {
@@ -3595,7 +3231,6 @@ export class DshClientSession {
3595
3231
  this.modelVision = res.meta?.vision ?? false;
3596
3232
  }
3597
3233
  }
3598
- /** 换模型 = 重启运行时。支持官方模型与第三方自定义端点模型。 */
3599
3234
  async setModel(modelId) {
3600
3235
  const { meta, targetProvider, bareModelId, known } = this.resolveModelMeta(modelId);
3601
3236
  if (!known) {
@@ -3609,7 +3244,6 @@ export class DshClientSession {
3609
3244
  }
3610
3245
  if (bareModelId === this.model && targetProvider === this.modelProvider)
3611
3246
  return;
3612
- // 解析服务商 BaseURL 与 API Key(如果是自定义 Provider)
3613
3247
  const cred = resolveProviderCredential(this.agentDir, targetProvider);
3614
3248
  if (targetProvider !== "deepseek" && !cred.apiKey && !process.env.DEEPSEEK_API_KEY) {
3615
3249
  this.emit({
@@ -3619,7 +3253,6 @@ export class DshClientSession {
3619
3253
  textEn: `Provider "${targetProvider}" has no API Key configured. Please configure it in Model Settings.`,
3620
3254
  });
3621
3255
  }
3622
- // P0-2 竞态告知:换模型 = 强杀运行时 → 进行中的 run 全部中止。
3623
3256
  if ([...this.convs.values()].some((c) => c.isStreaming)) {
3624
3257
  this.emit({
3625
3258
  type: "notice",
@@ -3632,7 +3265,6 @@ export class DshClientSession {
3632
3265
  this.modelProvider = targetProvider;
3633
3266
  this.modelDisplayName = meta?.name ?? bareModelId;
3634
3267
  this.modelVision = meta?.vision ?? false;
3635
- // 持久化当前项目的模型选择(按 DSH 引擎独立记录)
3636
3268
  this.stateStore?.saveProjectModel(this.clientId, this.cwd, modelId, "dsh");
3637
3269
  try {
3638
3270
  await this.runtime.restart(bareModelId, targetProvider);
@@ -3706,9 +3338,6 @@ export class DshClientSession {
3706
3338
  this.thinkingLevel = level;
3707
3339
  this.flushSnapshot();
3708
3340
  }
3709
- // -----------------------------------------------------------------------
3710
- // 设置 / 系统提示词
3711
- // -----------------------------------------------------------------------
3712
3341
  buildFallbackPromptSections() {
3713
3342
  const identity = "You are an AI agent powered by DeepSeek Harness.";
3714
3343
  const custom = this.settings.customSystemPrompt.trim();
@@ -3757,6 +3386,7 @@ export class DshClientSession {
3757
3386
  : this.buildFallbackPromptSourceDefaults();
3758
3387
  const promptSections = this.cachedPromptSections.length > 0 ? this.cachedPromptSections : this.buildFallbackPromptSections();
3759
3388
  const settings = {
3389
+ nativeCliInheritModel: { ...this.stateStore.getSettingsSnapshot(this.clientId).nativeCliInheritModel },
3760
3390
  ...normalizeQuickAskSettings(this.stateStore.getSettingsSnapshot(this.clientId)),
3761
3391
  steeringMode: "all",
3762
3392
  followUpMode: "all",
@@ -3764,32 +3394,25 @@ export class DshClientSession {
3764
3394
  customSystemPrompt: this.settings.customSystemPrompt,
3765
3395
  disabledSkills: this.settings.disabledSkills,
3766
3396
  disabledExtensions: this.settings.disabledExtensions,
3767
- // DSH engine: no unified tool gating (no subagent/edit_soft); empty keeps protocol complete.
3768
3397
  disabledAgentTools: [],
3769
- // DSH has no plugin host: no plugin AI tools exist here; empty keeps protocol complete.
3770
3398
  disabledPluginTools: [],
3771
3399
  terminalToolsEnabled: this.settings.terminalToolsEnabled,
3772
3400
  terminalBash: this.settings.terminalBash,
3773
3401
  terminalBashIdleMs: this.settings.terminalBashIdleMs,
3774
3402
  terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
3775
3403
  toolWatchdogTimeoutMs: this.settings.toolWatchdogTimeoutMs,
3776
- // DSH 引擎无 customTool 注册面(工具来自 shipped preset),read 目录覆盖面不存在。
3777
3404
  readDirEnabled: true,
3778
3405
  bgAutoCleanupMin: Number(this.settings.bgAutoCleanupMin ?? 0),
3779
- // DSH 无 pi 工具注册面,不适用延迟加载;保协议完整(该字段恒为 false,设置页不显示这一行)。
3780
3406
  toolLazyLoading: false,
3781
3407
  codemodeMode: "on",
3782
3408
  codemodeInlineBudget: 3000,
3783
3409
  editSoftEnabled: this.settings.editSoftEnabled,
3784
- // DSH 无独立重试配置(pi 引擎才暴露),保持默认。
3785
3410
  retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
3786
- // DSH 另有运行时:压缩软上限是 pi 引擎概念,这里保持关闭保协议完整。
3787
3411
  softCapTokens: 0,
3788
3412
  softCapByModel: {},
3789
3413
  autoCompactionInstructions: "",
3790
3414
  questionnaireEnabled: this.settings.questionnaireEnabled,
3791
3415
  toolApprovalEnabled: this.settings.toolApprovalEnabled !== false,
3792
- // DSH 无审批弹窗,策略恒为空(保协议完整)。
3793
3416
  approvalPolicy: { allowAll: false, categories: [] },
3794
3417
  approvalRules: [],
3795
3418
  goalModeEnabled: this.settings.goalModeEnabled,
@@ -3801,12 +3424,10 @@ export class DshClientSession {
3801
3424
  showForkedParentSessions: this.settings.showForkedParentSessions ?? false,
3802
3425
  retainFinishedConversations: this.settings.retainFinishedConversations ?? false,
3803
3426
  openRecentSessionOnProjectSwitch: this.settings.openRecentSessionOnProjectSwitch ?? true,
3804
- // DSH 无 skill 全文注入概念,给空保协议完整。
3805
3427
  skillsFullText: [],
3806
3428
  skillsCatalogMaxDesc: 250,
3807
3429
  skillsCatalogShowLocation: false,
3808
3430
  skillsCatalogBudget: 20000,
3809
- // DSH 不注入技能正文,但协议字段要齐全(设置页读快照)。
3810
3431
  skillsMaxFileBytes: 8192,
3811
3432
  skillsFullTextMaxBytes: 32768,
3812
3433
  chatUploadMaxMb: this.stateStore.getSettingsSnapshot(this.clientId).chatUploadMaxMb ?? 20,
@@ -3816,10 +3437,8 @@ export class DshClientSession {
3816
3437
  visionBridgeModel: null,
3817
3438
  visionBridgePromptMode: "append",
3818
3439
  visionBridgePrompt: "",
3819
- // DSH 无「AI 生成提交信息」(scm_commitmsg 分发处直接报错),保协议完整。
3820
3440
  scmCommitMsgPromptMode: "append",
3821
3441
  scmCommitMsgPrompt: "",
3822
- // DSH 引擎不渲染计划按钮(无 customTools 注册面),保协议完整。
3823
3442
  planModePromptMode: "append",
3824
3443
  planModePrompt: "",
3825
3444
  planModeDefaultPrompt: PLAN_MODE_SYSTEM_PROMPT,
@@ -3830,12 +3449,10 @@ export class DshClientSession {
3830
3449
  promptTemplate: this.settings.promptTemplate ?? "",
3831
3450
  promptOverrides: this.settings.promptOverrides ?? {},
3832
3451
  promptDisabled: [...(this.settings.promptDisabled ?? [])],
3833
- // DSH 无 pi 工具注册表面,逐工具文案覆盖不适用;保协议完整。
3834
3452
  toolPromptOverrides: {},
3835
3453
  effectiveSystemPrompt,
3836
3454
  promptSourceDefaults,
3837
3455
  promptSections,
3838
- // DSH 运行时真实的工具 schema 文本(发给模型的工具列表 JSON Schema 格式化文本)。
3839
3456
  toolsSchema: this.cachedToolsSchema,
3840
3457
  visionBridgeDefaultPrompt: "",
3841
3458
  scmCommitMsgDefaultPrompt: "",
@@ -3937,8 +3554,8 @@ export class DshClientSession {
3937
3554
  disabledMarkers: partial.disabledMarkers,
3938
3555
  });
3939
3556
  const markerGuidanceChanged = this.markerSvc.buildGuidance() !== prevMarkerGuidance;
3940
- // 持久化(跨重连存活)。
3941
3557
  this.stateStore.saveSettings(this.clientId, {
3558
+ nativeCliInheritModel: partial.nativeCliInheritModel,
3942
3559
  ...mergeQuickAskSettings(this.stateStore.getSettingsSnapshot(this.clientId), partial),
3943
3560
  chatUploadMaxMb: partial.chatUploadMaxMb,
3944
3561
  workspaceUploadMaxMb: partial.workspaceUploadMaxMb,
@@ -3952,9 +3569,7 @@ export class DshClientSession {
3952
3569
  terminalBashIdleMs: this.settings.terminalBashIdleMs,
3953
3570
  terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
3954
3571
  editSoftEnabled: this.settings.editSoftEnabled,
3955
- // DSH 无独立重试配置(pi 引擎才暴露),保持默认。
3956
3572
  retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
3957
- // DSH 另有运行时:压缩软上限是 pi 引擎概念,这里保持关闭保协议完整。
3958
3573
  softCapTokens: 0,
3959
3574
  softCapByModel: {},
3960
3575
  autoCompactionInstructions: "",
@@ -3981,14 +3596,11 @@ export class DshClientSession {
3981
3596
  promptOverrides: this.settings.promptOverrides ?? {},
3982
3597
  promptDisabled: [...(this.settings.promptDisabled ?? [])],
3983
3598
  });
3984
- // 仅系统提示词或内联标记指引变化才重启运行时(DSH_PERSONA 由 launcher env 注入);
3985
- // 其他设置(开关/隐藏插件等)只存不回写运行时。
3986
3599
  const personaChanged = partial.promptMode !== undefined || partial.customSystemPrompt !== undefined || markerGuidanceChanged;
3987
3600
  if (personaChanged) {
3988
3601
  await this.applyPersona();
3989
3602
  void this.refreshPromptInfo().catch(() => { });
3990
3603
  }
3991
- // 技能启停(#18):禁用集变化 → 同步运行时(晚 pre-step 钩子过滤目录)并刷新技能列表。
3992
3604
  if (partial.disabledSkills !== undefined) {
3993
3605
  void this.pushDisabledSkillsToRuntime();
3994
3606
  void this.refreshSkillsFromRuntime();
@@ -4008,18 +3620,12 @@ export class DshClientSession {
4008
3620
  return { DSH_PERSONA: persona, PI_WEB_DSH_CUSTOM_PROMPT: effectiveCustom };
4009
3621
  }
4010
3622
  applyPersona() {
4011
- // 自定义提示词双通道:DSH_PERSONA(host 部署人设;预设 persona 会 shadow 它,
4012
- // minimal 更全压住)+ PI_WEB_DSH_CUSTOM_PROMPT(独立 host section,随
4013
- // standard/ptc/cordis 下发;minimal 下被 complete 压住,官方语义)。
4014
3623
  this.runtime.env = { ...this.runtime.env, ...this.buildPersonaEnv() };
4015
3624
  if (this.runtime.alive) {
4016
- return this.runtime.restart(this.model).catch(() => {
4017
- /* keep old runtime */
4018
- });
3625
+ return this.runtime.restart(this.model).catch(() => { });
4019
3626
  }
4020
3627
  return Promise.resolve();
4021
3628
  }
4022
- /** 从运行时异步拉取真实组装的系统提示词、sections 与工具 schema。 */
4023
3629
  async refreshPromptInfo() {
4024
3630
  try {
4025
3631
  if (!this.runtime.alive)
@@ -4044,12 +3650,9 @@ export class DshClientSession {
4044
3650
  this.pushSettings();
4045
3651
  }
4046
3652
  }
4047
- catch {
4048
- /* 忽略拉取失败,保持上一次缓存或兜底 */
4049
- }
3653
+ catch { }
4050
3654
  }
4051
3655
  async reloadExtensions() {
4052
- // DSH 引擎无 pi 扩展体系。
4053
3656
  this.emit({
4054
3657
  type: "notice",
4055
3658
  level: "info",
@@ -4057,10 +3660,6 @@ export class DshClientSession {
4057
3660
  textEn: "The DSH engine does not support pi extension hot-reload",
4058
3661
  });
4059
3662
  }
4060
- // -----------------------------------------------------------------------
4061
- // Agent 预设(dsh-web 四模式;Node 侧是真相源,运行时只负责挂载)
4062
- // -----------------------------------------------------------------------
4063
- /** 从运行时拉取预设名录(每次启动后跑;失败/legacy → UI 隐藏预设条)。 */
4064
3663
  async refreshAgentPresets() {
4065
3664
  try {
4066
3665
  const res = await this.runtime.listPresets();
@@ -4083,13 +3682,11 @@ export class DshClientSession {
4083
3682
  this.pushAgentPresets();
4084
3683
  this.flushSnapshot();
4085
3684
  }
4086
- /** 校验一个预设 id(名录 healthy 优先;legacy/未知 → 默认)。 */
4087
3685
  resolvePreset(requested) {
4088
3686
  if (requested) {
4089
3687
  const hit = this.agentPresets.find((p) => p.id === requested && !p.broken);
4090
3688
  if (hit)
4091
3689
  return hit.id;
4092
- // 名录还没拉到(启动中)但 clone 有它 → 先信 clone,挂载期再定。
4093
3690
  if (this.presetCloneIds.includes(requested))
4094
3691
  return requested;
4095
3692
  }
@@ -4103,7 +3700,6 @@ export class DshClientSession {
4103
3700
  }
4104
3701
  return PRESET_DEFAULT_ID;
4105
3702
  }
4106
- /** 推送预设名录 + 默认(attach/变化后;legacy 下 presets 空,前端隐藏)。 */
4107
3703
  pushAgentPresets() {
4108
3704
  this.emit({
4109
3705
  type: "dsh_presets",
@@ -4111,7 +3707,6 @@ export class DshClientSession {
4111
3707
  defaultPreset: this.resolvePreset(),
4112
3708
  });
4113
3709
  }
4114
- /** 新会话默认预设(设置面板;非法 id 拒绝并提示)。 */
4115
3710
  async setDefaultAgentPreset(preset) {
4116
3711
  const hit = this.agentPresets.find((p) => p.id === preset && !p.broken);
4117
3712
  const valid = hit ? hit.id : this.presetCloneIds.includes(preset) ? preset : null;
@@ -4130,7 +3725,6 @@ export class DshClientSession {
4130
3725
  this.pushAgentPresets();
4131
3726
  this.flushSnapshot();
4132
3727
  }
4133
- /** 空白会话切换预设(首轮后锁定,官方语义;失败按 code 出双语 notice)。 */
4134
3728
  async selectAgentPreset(preset) {
4135
3729
  const conv = this.conv;
4136
3730
  if (conv.presetLocked || conv.messages.length > 0) {
@@ -4178,14 +3772,9 @@ export class DshClientSession {
4178
3772
  });
4179
3773
  }
4180
3774
  }
4181
- /** 预设显示名(名录 name > id;供 notice/前端回退)。 */
4182
3775
  presetName(id) {
4183
3776
  return this.agentPresets.find((p) => p.id === id)?.name ?? id;
4184
3777
  }
4185
- // -----------------------------------------------------------------------
4186
- // 权限预设(三档;官方 /permission 弹窗同源,Node 侧只做值守 + 转发)
4187
- // -----------------------------------------------------------------------
4188
- /** 校验三档值(非法 → 默认;组合里没有也照默认,前端按 options 取交集展示)。 */
4189
3778
  resolvePermissionPreset(requested) {
4190
3779
  if (requested && PERMISSION_OFFERED.includes(requested))
4191
3780
  return requested;
@@ -4194,7 +3783,6 @@ export class DshClientSession {
4194
3783
  return def;
4195
3784
  return PERMISSION_DEFAULT_PRESET;
4196
3785
  }
4197
- /** 推选项表 + 默认(组合静态,options 为空 = 运行时未就绪/legacy,前端隐藏)。 */
4198
3786
  pushPermission() {
4199
3787
  this.emit({
4200
3788
  type: "dsh_permission",
@@ -4202,7 +3790,6 @@ export class DshClientSession {
4202
3790
  defaultPreset: this.settings.defaultPermissionPreset,
4203
3791
  });
4204
3792
  }
4205
- /** 拉取权限选项表(运行时启动/重建后跑一次;失败 → 空,前端隐藏)。 */
4206
3793
  async refreshPermissionOptions() {
4207
3794
  try {
4208
3795
  const res = await this.runtime.getPermission(this.conv.sessionId);
@@ -4213,7 +3800,6 @@ export class DshClientSession {
4213
3800
  }
4214
3801
  this.pushPermission();
4215
3802
  }
4216
- /** 拉取当前会话的权限预设值(激活/创建/切换/重启后跑;失败保持 null)。 */
4217
3803
  async refreshActivePermission() {
4218
3804
  const conv = this.conv;
4219
3805
  try {
@@ -4227,12 +3813,9 @@ export class DshClientSession {
4227
3813
  if (cur)
4228
3814
  conv.permissionPreset = cur;
4229
3815
  }
4230
- catch {
4231
- /* 运行时未就绪:保持 null/旧值 */
4232
- }
3816
+ catch { }
4233
3817
  this.flushSnapshot();
4234
3818
  }
4235
- /** 新会话默认权限预设(设置面板;非法值拒绝并提示)。 */
4236
3819
  async setDefaultPermissionPreset(preset) {
4237
3820
  if (!PERMISSION_OFFERED.includes(preset)) {
4238
3821
  this.emit({
@@ -4248,7 +3831,6 @@ export class DshClientSession {
4248
3831
  this.pushPermission();
4249
3832
  this.flushSnapshot();
4250
3833
  }
4251
- /** 首轮 prompt 前:新会话应用 per-client 默认(与当前一致时 apply 无事件零噪音)。 */
4252
3834
  async ensurePermissionDefault(conv) {
4253
3835
  const target = this.resolvePermissionPreset();
4254
3836
  try {
@@ -4263,11 +3845,8 @@ export class DshClientSession {
4263
3845
  conv.permissionPreset = res.currentValue || target;
4264
3846
  }
4265
3847
  }
4266
- catch {
4267
- /* legacy/运行时未就绪:best effort */
4268
- }
3848
+ catch { }
4269
3849
  }
4270
- /** 当前会话切换权限预设(热切换,无需重启;失败按 code 出双语 notice)。 */
4271
3850
  async setPermissionPreset(preset) {
4272
3851
  const conv = this.conv;
4273
3852
  const target = this.resolvePermissionPreset(preset);
@@ -4308,11 +3887,6 @@ export class DshClientSession {
4308
3887
  });
4309
3888
  }
4310
3889
  }
4311
- /**
4312
- * 审查者模式:DSH 不支持(无 customTools 注册面 → 工具硬闸门无处可挂,
4313
- * 自动路由也没有可派发的会话通道)。明确回报而不是静默失败 ——
4314
- * “点了没反应”比“用不了”更让人怀疑是不是页面坏了。
4315
- */
4316
3890
  async setDelegateMode(enabled) {
4317
3891
  if (!enabled)
4318
3892
  return;
@@ -4336,18 +3910,14 @@ export class DshClientSession {
4336
3910
  promptDisabled: [],
4337
3911
  disabledSkills: this.settings.disabledSkills,
4338
3912
  disabledExtensions: this.settings.disabledExtensions,
4339
- // DSH engine: no unified tool gating (no subagent/edit_soft); empty keeps protocol complete.
4340
3913
  disabledAgentTools: [],
4341
3914
  terminalToolsEnabled: this.settings.terminalToolsEnabled,
4342
3915
  terminalBash: this.settings.terminalBash,
4343
3916
  terminalBashIdleMs: this.settings.terminalBashIdleMs,
4344
3917
  terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
4345
3918
  editSoftEnabled: this.settings.editSoftEnabled,
4346
- // DSH 无独立重试配置,预设沿用默认值。
4347
- // DSH 无 skill 全文注入概念,给空保预设类型完整。
4348
3919
  skillsFullText: [],
4349
3920
  retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
4350
- // DSH 另有运行时:压缩软上限是 pi 引擎概念,预设里保持关闭。
4351
3921
  softCapTokens: 0,
4352
3922
  softCapByModel: {},
4353
3923
  autoCompactionInstructions: "",
@@ -4376,7 +3946,6 @@ export class DshClientSession {
4376
3946
  });
4377
3947
  return;
4378
3948
  }
4379
- // Keep absent fields intact, including settings owned by other engines.
4380
3949
  const { settings } = sanitizePresetSettings(preset);
4381
3950
  this.stateStore.saveSettings(this.clientId, settings);
4382
3951
  Object.assign(this.settings, settings);
@@ -4389,11 +3958,6 @@ export class DshClientSession {
4389
3958
  this.stateStore.savePresets(this.clientId, presets.filter((p) => p.name !== name));
4390
3959
  this.pushSettings();
4391
3960
  }
4392
- /* -----------------------------------------------------------------------
4393
- * 预设分享(server/preset-share.ts)—— 与 pi 引擎同一份编排,只换适配层。
4394
- * DSH 的预设存储/应用语义不同,所以把「取/存/应用」按 DSH 的做法接上。
4395
- * --------------------------------------------------------------------- */
4396
- /** 分享编排需要的最小能力集合(DSH 侧)。 */
4397
3961
  sharePort() {
4398
3962
  return {
4399
3963
  lang: () => this.getLang(),
@@ -4401,8 +3965,6 @@ export class DshClientSession {
4401
3965
  presets: () => this.stateStore.getPresets(this.clientId),
4402
3966
  currentSettings: () => {
4403
3967
  const s = this.settings;
4404
- // DSH 的预设记录字段与 ClientSettings 不完全一致(没有 promptTemplate/
4405
- // promptOverrides 等),导出时按预设形状给默认值(应用侧只读它认识的)。
4406
3968
  return {
4407
3969
  promptMode: s.promptMode,
4408
3970
  customSystemPrompt: s.customSystemPrompt,
@@ -4434,29 +3996,21 @@ export class DshClientSession {
4434
3996
  emit: (msg) => this.emit(msg),
4435
3997
  };
4436
3998
  }
4437
- /** 导出预设/当前设置为可分享的 JSON(服务端 preset-share.ts)。 */
4438
3999
  async exportPreset(msg) {
4439
4000
  exportPresetVia(this.sharePort(), msg);
4440
4001
  }
4441
- /** 解析导入的预设 JSON(dryRun = 只预览)。 */
4442
4002
  async importPreset(msg) {
4443
4003
  await importPresetVia(this.sharePort(), msg);
4444
4004
  }
4445
- /** 按网址导入预设(服务端抓取)。 */
4446
4005
  async importPresetFromUrl(msg) {
4447
4006
  await importPresetFromUrlVia(this.sharePort(), msg);
4448
4007
  }
4449
- /** 拉社区共享预设目录。 */
4450
4008
  async pushPresetCatalog(msg) {
4451
4009
  await pushPresetCatalogVia(this.sharePort(), msg);
4452
4010
  }
4453
- /** 一键分享预设到社区共享仓库。 */
4454
4011
  async sharePreset(msg) {
4455
4012
  await sharePresetVia(this.sharePort(), msg);
4456
4013
  }
4457
- // -----------------------------------------------------------------------
4458
- // 子代理模板(DSH 引擎无子代理概念 —— 设置面板分区由前端 isDsh 隐藏)
4459
- // -----------------------------------------------------------------------
4460
4014
  async saveSubagentTemplate() {
4461
4015
  this.emit({
4462
4016
  type: "notice",
@@ -4473,16 +4027,9 @@ export class DshClientSession {
4473
4027
  textEn: "Subagent templates are not supported by the DSH engine (use the pi engine instead)",
4474
4028
  });
4475
4029
  }
4476
- // -----------------------------------------------------------------------
4477
- // 目标(DSH 原生 goal 域:goal/change 事件驱动,round-driver 自动轮次)
4478
- // -----------------------------------------------------------------------
4479
4030
  emitGoalStatus() {
4480
4031
  this.emit({ type: "goal_status", status: { ...this.conv.goal } });
4481
4032
  }
4482
- /**
4483
- * goal/change 事件(DSH 原生状态机全量快照)→ 镜像到当前 conversation。
4484
- * 权威源在运行时:create/edit/resume → active;complete → pass;block → fail。
4485
- */
4486
4033
  applyGoalChange(conv, data) {
4487
4034
  const g = conv.goal;
4488
4035
  if (data.operation === "clear" || (!data.goal && data.cleared)) {
@@ -4515,8 +4062,6 @@ export class DshClientSession {
4515
4062
  g.reviewing = true;
4516
4063
  g.verdict = "pending";
4517
4064
  g.feedback = undefined;
4518
- // P1-10:轮次已达上限且仍未完成 → 提示轮尽(模型可能正在跑最后一轮,
4519
- // 后续 complete/blocked 事件会覆盖此状态)。
4520
4065
  const rounds = g.round ?? 0;
4521
4066
  const max = data.goal.maxGoalRounds ?? g.maxRounds ?? 0;
4522
4067
  g.status =
@@ -4582,12 +4127,9 @@ export class DshClientSession {
4582
4127
  g.reviewModel = opts?.reviewModel ?? g.reviewModel;
4583
4128
  g.maxRounds = opts?.maxRounds ?? g.maxRounds;
4584
4129
  g.locked = opts?.locked ?? g.locked;
4585
- // P1-11:DSH 无独立审查者,locked 映射为轮次语义 ——
4586
- // locked=true(目标锁定,必须达成)→ 保留用户轮次上限;
4587
- // locked=false(不锁定)→ 单轮语义近似(maxGoalRounds=1,一轮后结束)。
4588
4130
  const effectiveMax = g.locked ? g.maxRounds : 1;
4589
4131
  g.round = 0;
4590
- g.reviewing = true; // round-driver 会立刻续第一轮
4132
+ g.reviewing = true;
4591
4133
  g.verdict = "pending";
4592
4134
  g.feedback = undefined;
4593
4135
  g.status = "目标已设,等待生成…";
@@ -4606,7 +4148,6 @@ export class DshClientSession {
4606
4148
  textEn: `🎯 Goal set: ${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`,
4607
4149
  });
4608
4150
  try {
4609
- // goal/set 创建 + arm;round-driver 在 agent idle 时自动续轮,无需额外 prompt。
4610
4151
  const res = (await this.runtime.goalSet(conv.sessionId, text, effectiveMax > 0 ? effectiveMax : undefined));
4611
4152
  if (res?.goal?.maxGoalRounds)
4612
4153
  g.maxRounds = res.goal.maxGoalRounds;
@@ -4627,7 +4168,6 @@ export class DshClientSession {
4627
4168
  }
4628
4169
  async clearGoal() {
4629
4170
  const conv = this.conv;
4630
- // 向导进行中 → 中断等待(模型侧提问会因超时/无 provider 恢复)。
4631
4171
  if (conv.turnWaiter) {
4632
4172
  const w = conv.turnWaiter;
4633
4173
  conv.turnWaiter = undefined;
@@ -4637,9 +4177,7 @@ export class DshClientSession {
4637
4177
  try {
4638
4178
  await this.runtime.goalClear(conv.sessionId);
4639
4179
  }
4640
- catch {
4641
- /* goal/change clear 事件会回来兜底 */
4642
- }
4180
+ catch { }
4643
4181
  }
4644
4182
  conv.dsGoal = null;
4645
4183
  const g = conv.goal;
@@ -4654,8 +4192,6 @@ export class DshClientSession {
4654
4192
  this.flushSnapshot();
4655
4193
  }
4656
4194
  async startGoalWizard(text, opts) {
4657
- // 交互式调研向导:主会话 prompt 向导指令 → 模型用 ask_user_question 逐题
4658
- // 提问(经提问桥 → 浏览器对话框)→ 收敛输出 GOAL: 行 → 自动设目标。
4659
4195
  if (this.quiesceBlocked())
4660
4196
  return;
4661
4197
  if (this.settings.goalModeEnabled === false) {
@@ -4728,12 +4264,10 @@ export class DshClientSession {
4728
4264
  g.wizard.step = 0;
4729
4265
  g.wizard.status = "";
4730
4266
  g.wizard.statusEn = "";
4731
- // 解析模型最终输出中的 GOAL: 行。
4732
4267
  const finalText = this.lastAssistantText(conv);
4733
4268
  const goalMatch = finalText.match(/GOAL\s*[::]\s*([\s\S]*)/i);
4734
4269
  let refined = goalMatch ? goalMatch[1].trim() : "";
4735
4270
  if (!refined) {
4736
- // 未按格式:取最后一段非空文本(截断防污染)。
4737
4271
  refined =
4738
4272
  finalText
4739
4273
  .split("\n")
@@ -4744,7 +4278,6 @@ export class DshClientSession {
4744
4278
  refined = refined.slice(0, 300);
4745
4279
  }
4746
4280
  if (!refined && g.goal) {
4747
- // 模型可能直接用了 create_goal —— 目标已在运行时,镜像它即可。
4748
4281
  this.emitGoalStatus();
4749
4282
  this.emit({
4750
4283
  type: "notice",
@@ -4777,7 +4310,6 @@ export class DshClientSession {
4777
4310
  });
4778
4311
  }
4779
4312
  }
4780
- /** 调研向导指令(主会话 prompt):先提问收敛,最后只输出 GOAL: 行。 */
4781
4313
  wizardPrompt(draft) {
4782
4314
  return [
4783
4315
  `You are a goal-clarification wizard. The user stated a raw requirement. Your job is to turn it into ONE precise, actionable goal that a coding agent can fully satisfy.`,
@@ -4791,7 +4323,6 @@ export class DshClientSession {
4791
4323
  `Do NOT call create_goal or update_goal — just output the GOAL: line. If the user cancels or stops answering, still produce a sensible best-effort GOAL from what you already know.`,
4792
4324
  ].join("\n");
4793
4325
  }
4794
- /** 会话最后一条 assistant 文本(向导/调试提取用)。 */
4795
4326
  lastAssistantText(conv) {
4796
4327
  for (let i = conv.messages.length - 1; i >= 0; i--) {
4797
4328
  const m = conv.messages[i];
@@ -4817,9 +4348,6 @@ export class DshClientSession {
4817
4348
  });
4818
4349
  this.emitGoalStatus();
4819
4350
  }
4820
- // -----------------------------------------------------------------------
4821
- // 命令列表(.pi/commands.json → DSH 无命令体系,简化为空/透传存储)
4822
- // -----------------------------------------------------------------------
4823
4351
  async listCommands() {
4824
4352
  const { commands, path } = await loadCommands(this.cwd);
4825
4353
  this.emit({ type: "commands", commands, path });
@@ -4838,9 +4366,6 @@ export class DshClientSession {
4838
4366
  this.emit({ type: "notice", level: "info", text: `命令已保存(${path})`, textEn: `Command saved (${path})` });
4839
4367
  }
4840
4368
  }
4841
- // -----------------------------------------------------------------------
4842
- // 斜杠命令(内置 NATIVE + 插件 registerCommand;DSH 无扩展/技能/模板体系)
4843
- // -----------------------------------------------------------------------
4844
4369
  async pushSlashCommands() {
4845
4370
  const commands = [];
4846
4371
  const seen = new Set();
@@ -4848,7 +4373,6 @@ export class DshClientSession {
4848
4373
  commands.push({ ...c, source: "builtin" });
4849
4374
  seen.add(c.name);
4850
4375
  }
4851
- // 技能命令:运行时技能 + 磁盘技能
4852
4376
  for (const s of this.skillsCache) {
4853
4377
  const name = `skill:${s.name}`;
4854
4378
  if (seen.has(name))
@@ -4887,7 +4411,6 @@ export class DshClientSession {
4887
4411
  }
4888
4412
  this.emit({ type: "slash_commands", commands });
4889
4413
  }
4890
- /** 拦截执行斜杠命令;返回 true 表示已处理(不发给模型)。 */
4891
4414
  async execSlash(name, args) {
4892
4415
  if (name.startsWith("skill:")) {
4893
4416
  const skillName = name.slice(6);
@@ -4905,8 +4428,6 @@ export class DshClientSession {
4905
4428
  switch (name) {
4906
4429
  case "new": {
4907
4430
  const first = args.trim();
4908
- // /new <prompt>:与 pi 引擎一致(共用 NATIVE_COMMANDS 的提示词),
4909
- // 仅当真的落在空白新对话上才投递首条提示,否则会把提示误发进当前对话。
4910
4431
  if ((await this.newChat()) && first)
4911
4432
  await this.prompt(first);
4912
4433
  return true;
@@ -4958,9 +4479,9 @@ export class DshClientSession {
4958
4479
  await this.refreshSessions();
4959
4480
  return true;
4960
4481
  case "help":
4961
- return true; // 前端 /help modal 展示目录
4482
+ return true;
4962
4483
  case "copy":
4963
- return true; // 前端本地实现
4484
+ return true;
4964
4485
  case "reload":
4965
4486
  this.emit({
4966
4487
  type: "notice",
@@ -4990,7 +4511,6 @@ export class DshClientSession {
4990
4511
  this.onQuit?.();
4991
4512
  return true;
4992
4513
  }
4993
- // 插件命令(host.registerCommand)
4994
4514
  const def = this.pluginCommandsProvider?.().find((c) => c.name === name);
4995
4515
  if (def) {
4996
4516
  try {
@@ -5011,15 +4531,11 @@ export class DshClientSession {
5011
4531
  }
5012
4532
  return false;
5013
4533
  }
5014
- // -----------------------------------------------------------------------
5015
- // 自更新
5016
- // -----------------------------------------------------------------------
5017
4534
  static currentAppVersion() {
5018
4535
  return getAppVersion() || "0.0.0";
5019
4536
  }
5020
4537
  async checkUpdate() {
5021
4538
  try {
5022
- // registry 遵从 ~/.pi/agent/npm/.npmrc(与 `pi update` 经 npm 的行为一致,issue #151)
5023
4539
  const npmRegistry = resolveNpmRegistry(join(homedir(), ".pi", "agent"));
5024
4540
  const latest = await checkAllUpdates([{ name: "pi-web-ui", version: DshClientSession.currentAppVersion(), kind: "webui" }], undefined, () => this.getLang(), npmRegistry);
5025
4541
  const item = latest[0];
@@ -5051,7 +4567,6 @@ export class DshClientSession {
5051
4567
  });
5052
4568
  const items = await checkAllUpdates(targets, undefined, () => this.getLang(), resolveNpmRegistry(join(homedir(), ".pi", "agent")));
5053
4569
  if (force) {
5054
- // 强制模式:忽略缓存(默认 Fetcher 带 TTL,直接再查一次即可)。
5055
4570
  void items;
5056
4571
  }
5057
4572
  this.emit({
@@ -5072,9 +4587,6 @@ export class DshClientSession {
5072
4587
  this.emit({ type: "update_status_all", items: [] });
5073
4588
  }
5074
4589
  }
5075
- // -----------------------------------------------------------------------
5076
- // pi 专属:DSH 引擎下的简化实现
5077
- // -----------------------------------------------------------------------
5078
4590
  async installPiAgent() {
5079
4591
  this.emit({
5080
4592
  type: "install_result",
@@ -5082,7 +4594,6 @@ export class DshClientSession {
5082
4594
  detail: pick(this.getLang(), "DSH 引擎不需要 pi CLI", "The DSH engine does not need the pi CLI", "dsh.engine.no.cli"),
5083
4595
  });
5084
4596
  }
5085
- /** DSH 是否就绪:auth.json 的 deepseek key、环境变量 DEEPSEEK_API_KEY 或自定义 Provider 凭据任一即可。 */
5086
4597
  isDshConfigured() {
5087
4598
  if (loadDeepSeekKey(this.agentDir) || process.env.DEEPSEEK_API_KEY)
5088
4599
  return true;
@@ -5100,12 +4611,9 @@ export class DshClientSession {
5100
4611
  }
5101
4612
  }
5102
4613
  }
5103
- catch {
5104
- /* ignore */
5105
- }
4614
+ catch { }
5106
4615
  return false;
5107
4616
  }
5108
- /** 下拉框里的 deepseek-official 归一到 auth.json 的 deepseek 槽位(loadDeepSeekKey 只读它)。 */
5109
4617
  normalizeDshProvider(provider) {
5110
4618
  const pid = provider.trim();
5111
4619
  return pid === "deepseek-official" ? "deepseek" : pid;
@@ -5206,19 +4714,12 @@ export class DshClientSession {
5206
4714
  abortEnrichModels(reqId) {
5207
4715
  this.modelAdmin.abortEnrichModels(reqId);
5208
4716
  }
5209
- // -----------------------------------------------------------------------
5210
- // 其他
5211
- // -----------------------------------------------------------------------
5212
- resolveDialog(_id, _value) {
5213
- // DSH 引擎无扩展 UI 桥(dialog 由插件宿主走,v1 忽略)。
5214
- }
4717
+ resolveDialog(_id, _value) { }
5215
4718
  async editMessage(messageId, text, attachments) {
5216
4719
  if (this.quiesceBlocked() || this.switchingWorkspace || this.disposed)
5217
4720
  return;
5218
4721
  if (!text.trim() && !attachments?.length)
5219
4722
  return;
5220
- // The runtime has no history-replacement RPC. Close its append-only writer,
5221
- // replace the persisted prefix atomically, then resume the SAME session ID.
5222
4723
  let recoverRuntime;
5223
4724
  try {
5224
4725
  const conv = this.conv;
@@ -5249,8 +4750,6 @@ export class DshClientSession {
5249
4750
  const file = this.guessSessionFile(conv);
5250
4751
  if (!file)
5251
4752
  throw new Error("Persisted DSH session log not found; history was not changed");
5252
- // Every persisted session loses its live agent when this shared process stops.
5253
- // Mark them before stopping so failed rebuilds can restore lazily on prompt.
5254
4753
  const loaded = [...this.convs.values()].filter((c) => !c.fromDisk && this.guessSessionFile(c));
5255
4754
  recoverRuntime = async () => {
5256
4755
  if (!current())
@@ -5270,7 +4769,6 @@ export class DshClientSession {
5270
4769
  .map((e) => JSON.stringify(e))
5271
4770
  .join("\n") + "\n";
5272
4771
  writeAtomicSync(file, file.endsWith(".zstd") ? zstdCompressSync(Buffer.from(saved)) : saved, { fsync: true });
5273
- // Skip file asides belonging to this question; promptConv recreates attachments.
5274
4772
  let cutIdx = idx;
5275
4773
  while (cutIdx > 0 &&
5276
4774
  conv.messages[cutIdx - 1]?.role === "custom" &&
@@ -5285,7 +4783,6 @@ export class DshClientSession {
5285
4783
  await runtime.start();
5286
4784
  if (!current())
5287
4785
  return;
5288
- // DshRuntime has not yet exposed the installed SDK's session/resume RPC.
5289
4786
  await runtime._request("session/resume", { sessionId });
5290
4787
  if (!current())
5291
4788
  return;
@@ -5316,23 +4813,15 @@ export class DshClientSession {
5316
4813
  }
5317
4814
  }
5318
4815
  }
5319
- /** Server language for this client (issue #91): resolved LIVE from the
5320
- * persisted UI locale — "zh" only for zh*; everything else is English. */
5321
4816
  getLang() {
5322
4817
  return resolveServerLang(this.stateStore.get(this.clientId).locale);
5323
4818
  }
5324
- /** Persist the browser UI locale (hello.locale / set_locale). DSH
5325
- * runtime prompts pick it up on the next run — no restart needed. */
5326
4819
  async setLocale(locale) {
5327
4820
  const code = locale.trim().slice(0, 16);
5328
4821
  if (!code)
5329
4822
  return;
5330
4823
  this.stateStore.saveLocale(this.clientId, code);
5331
4824
  }
5332
- /** 设置当前项目的额外工作区根(宿主侧多根,宿主 API v2 的宿主侧能力)。
5333
- * DSH 引擎没有插件宿主,多根只落到「宿主知道 / 快照下发」这一层:右栏文件树
5334
- * (前端)据此多出可切换的根。
5335
- * 与 pi 引擎同口径:归一化交给 ClientStateStore(只收绝对路径 / 去重 / 上限 8)。 */
5336
4825
  async setWorkspaceRoots(roots) {
5337
4826
  const before = this.stateStore.getWorkspaceRoots(this.clientId, this.cwd);
5338
4827
  this.stateStore.saveWorkspaceRoots(this.clientId, this.cwd, roots ?? []);
@@ -5390,7 +4879,6 @@ export class DshClientSession {
5390
4879
  textEn: `Switching workspace & restarting runtime: ${abs}`,
5391
4880
  });
5392
4881
  await new Promise((r) => setImmediate(r));
5393
- // 恢复新工作区的记忆模型(按 DSH 引擎独立记录:项目记忆 > 全局默认)
5394
4882
  const savedModel = this.stateStore.getProjectModel(this.clientId, abs, "dsh") ?? this.stateStore.getDefaultModel("dsh");
5395
4883
  const previousModel = this.model;
5396
4884
  const previousProvider = this.modelProvider;
@@ -5411,11 +4899,8 @@ export class DshClientSession {
5411
4899
  this.cwd = abs;
5412
4900
  this.roots = this.stateStore.getWorkspaceRoots(this.clientId, abs);
5413
4901
  this.stateStore.remember(this.clientId, abs);
5414
- // 旧 active 会话:活跃的(流式/有终端/跑过)标 listed → 后台运行可见
5415
- // (与 pi 的 displaceActive 语义一致);空白的直接弃(不列)。
5416
4902
  const prev = this.conv;
5417
4903
  prev.listed = this.shouldRetainDshConversation(prev) || prev.messages.length > 0;
5418
- // 新项目 → 恢复最近历史会话(若有)或新建空白会话
5419
4904
  const openRecent = this.settings.openRecentSessionOnProjectSwitch ?? true;
5420
4905
  const recentFiles = openRecent
5421
4906
  ? findSessionFilesForCwd(this.sessionRoot, abs).filter((f) => !basename(dirname(f)).startsWith("review-"))
@@ -5440,8 +4925,6 @@ export class DshClientSession {
5440
4925
  }
5441
4926
  }
5442
4927
  this.activeId = (resumedConv ?? this.addConversation(`web-${randomUUID().slice(0, 12)}`, abs, false)).id;
5443
- // 旧项目非活跃 conversation 回收(pi 的 displaceActive 语义:切走后
5444
- // 非 streaming / 无终端 / 未列出的旧会话从内存移除,磁盘 JSONL 可回放恢复)。
5445
4928
  // eslint-disable-next-line unicorn/no-useless-spread -- snapshot: handlers may unsubscribe mid-emit
5446
4929
  for (const [id, c] of [...this.convs]) {
5447
4930
  if (id === this.activeId)
@@ -5452,7 +4935,6 @@ export class DshClientSession {
5452
4935
  continue;
5453
4936
  if (c.isStreaming)
5454
4937
  continue;
5455
- // 只看“用过”的存活终端:没动过的空 shell 不阻止项目切换时的旧会话回收。\n\t\t\t\tif (c.terminals.countBlockingLive() > 0) continue;
5456
4938
  this.removeConversation(id);
5457
4939
  }
5458
4940
  this.onCwdChanged?.(abs);
@@ -5468,7 +4950,6 @@ export class DshClientSession {
5468
4950
  this.emitConversations();
5469
4951
  void this.pushSessions();
5470
4952
  void this.pushProjects();
5471
- // 文件树跟随新项目(服务端原生 watcher 自动重挂)。
5472
4953
  void this.listFiles(undefined);
5473
4954
  this.pushTerminals();
5474
4955
  this.pushSettings();
@@ -5526,13 +5007,32 @@ export class DshClientSession {
5526
5007
  try {
5527
5008
  await this.runtime.close();
5528
5009
  }
5529
- catch {
5530
- /* ignore */
5010
+ catch { }
5011
+ }
5012
+ async readQuickAskConversation(source, signal) {
5013
+ signal.throwIfAborted();
5014
+ const conv = source.conversationId
5015
+ ? this.convs.get(source.conversationId)
5016
+ : source.sessionFile
5017
+ ? [...this.convs.values()].find((candidate) => candidate.sessionFile &&
5018
+ normalizePathKey(candidate.sessionFile) === normalizePathKey(source.sessionFile))
5019
+ : undefined;
5020
+ if (conv) {
5021
+ const file = this.guessSessionFile(conv);
5022
+ if (source.sessionFile && (!file || normalizePathKey(file) !== normalizePathKey(source.sessionFile)))
5023
+ return undefined;
5024
+ return captureQuickAskConversation(conv.title, file ?? undefined, conv.messages, conv.cwd);
5531
5025
  }
5026
+ if (!source.sessionFile)
5027
+ return undefined;
5028
+ const cwd = this.cwd;
5029
+ const file = findSessionFilesForCwd(this.sessionRoot, cwd).find((candidate) => normalizePathKey(candidate) === normalizePathKey(source.sessionFile));
5030
+ if (!file || statSync(file).size > 16 * 1024 * 1024)
5031
+ return undefined;
5032
+ const { events } = readSessionLog(file);
5033
+ signal.throwIfAborted();
5034
+ return captureQuickAskConversation(sessionLogTitle(events) || basename(dirname(file)), file, replayEventsToMessages(events), cwd);
5532
5035
  }
5533
- // -----------------------------------------------------------------------
5534
- // 插件扩展点(与 pi 引擎的 *ForPlugins 对齐)
5535
- // -----------------------------------------------------------------------
5536
5036
  activeConversationId() {
5537
5037
  return this.activeId;
5538
5038
  }
@@ -5584,9 +5084,7 @@ export class DshClientSession {
5584
5084
  isStreaming: false,
5585
5085
  });
5586
5086
  }
5587
- catch {
5588
- // 忽略损坏的会话日志
5589
- }
5087
+ catch { }
5590
5088
  }
5591
5089
  return out;
5592
5090
  }
@@ -5671,10 +5169,6 @@ export class DshClientSession {
5671
5169
  return [{ id: `${this.modelProvider}/${this.model}`, provider: this.modelProvider, vision: this.modelVision }];
5672
5170
  }
5673
5171
  }
5674
- // ---------------------------------------------------------------------------
5675
- // DshAgentService — 服务级:客户端会话管理与引擎分发入口
5676
- // ---------------------------------------------------------------------------
5677
- /** 与 pi 引擎 AgentService 同构的顶层服务(index.ts 按 PI_WEB_ENGINE 选择)。 */
5678
5172
  export class DshAgentService {
5679
5173
  cwd;
5680
5174
  agentDir;
@@ -5742,7 +5236,6 @@ export class DshAgentService {
5742
5236
  service: toServiceInfo(launchOrigin()),
5743
5237
  };
5744
5238
  }
5745
- /** issue #145:跨客户端同会话查重(sessionId 口径,与 pi 引擎同语义)。 */
5746
5239
  findSessionOwner(sessionId, excludeClientId) {
5747
5240
  for (const [clientId, cs] of this.clients) {
5748
5241
  if (clientId === excludeClientId)
@@ -5760,7 +5253,6 @@ export class DshAgentService {
5760
5253
  }
5761
5254
  return null;
5762
5255
  }
5763
- /** issue #145:别处在某 cwd 下正在跑的对话(同项目并行感知用)。 */
5764
5256
  listProjectRunners(cwd, excludeClientId) {
5765
5257
  const out = [];
5766
5258
  for (const [clientId, cs] of this.clients) {
@@ -5771,7 +5263,6 @@ export class DshAgentService {
5771
5263
  }
5772
5264
  return out;
5773
5265
  }
5774
- /** issue #145:别处所有正在跑的对话(左栏 elsewhere 只读感知用)。 */
5775
5266
  listExternalRunning(excludeClientId) {
5776
5267
  const out = [];
5777
5268
  for (const [clientId, cs] of this.clients) {
@@ -5782,7 +5273,6 @@ export class DshAgentService {
5782
5273
  }
5783
5274
  return out;
5784
5275
  }
5785
- /** issue #145:某客户端流式集合变化 → 其他客户端重推 conversations。 */
5786
5276
  pokeExternalRunning(excludeClientId) {
5787
5277
  for (const [clientId, cs] of this.clients) {
5788
5278
  if (clientId === excludeClientId)
@@ -5790,12 +5280,9 @@ export class DshAgentService {
5790
5280
  try {
5791
5281
  cs.refreshExternalRunning();
5792
5282
  }
5793
- catch {
5794
- // 单客户端坏了不影响其他
5795
- }
5283
+ catch { }
5796
5284
  }
5797
5285
  }
5798
- /** issue #145:向除请求方外的所有客户端发一条 notice(并行通告用)。 */
5799
5286
  notifyClientsExcept(excludeClientId, msg) {
5800
5287
  for (const [clientId, cs] of this.clients) {
5801
5288
  if (clientId === excludeClientId)
@@ -5803,9 +5290,7 @@ export class DshAgentService {
5803
5290
  try {
5804
5291
  cs.emitNotice(msg.level, msg.text, msg.textEn);
5805
5292
  }
5806
- catch {
5807
- // 单客户端坏了不影响其他
5808
- }
5293
+ catch { }
5809
5294
  }
5810
5295
  }
5811
5296
  async attach(clientId, send) {
@@ -5821,11 +5306,8 @@ export class DshAgentService {
5821
5306
  if (statSync(saved.lastCwd).isDirectory())
5822
5307
  cwd = saved.lastCwd;
5823
5308
  }
5824
- catch {
5825
- /* gone — fall back to default */
5826
- }
5309
+ catch { }
5827
5310
  }
5828
- // 同步创建(runtime.start() 异步后台进行)——无并发竞态,无需 pending。
5829
5311
  cs = DshClientSession.create(clientId, cwd, this.stateStore, this.dataDir, this.agentDir);
5830
5312
  this.clients.set(clientId, cs);
5831
5313
  this.stateStore.remember(clientId, cwd);
@@ -5846,7 +5328,6 @@ export class DshAgentService {
5846
5328
  cs.pluginBgTasksProvider = this.pluginBgTasksProvider;
5847
5329
  cs.pluginStopBgTask = this.pluginStopBgTask;
5848
5330
  cs.isQuiesced = () => this.quiesced;
5849
- // issue #145 跨客户端感知接线(同会话查重 / 同项目并行 / elsewhere 列表)。
5850
5331
  cs.findSessionOwnerById = (sessionId) => this.findSessionOwner(sessionId, clientId);
5851
5332
  cs.listProjectRunners = (cwd) => this.listProjectRunners(cwd, clientId);
5852
5333
  cs.listExternalRunning = () => this.listExternalRunning(clientId);
@@ -5856,8 +5337,6 @@ export class DshAgentService {
5856
5337
  this.onClientCwdChanged?.(cs.cwd);
5857
5338
  return cs;
5858
5339
  }
5859
- /** Browser UI locale report (hello.locale / set_locale): persist per
5860
- * client; DSH runtime prompts refresh on next run (P2 bilingual). */
5861
5340
  async setLocale(clientId, locale) {
5862
5341
  const cs = this.clients.get(clientId);
5863
5342
  if (cs)
@@ -5867,7 +5346,6 @@ export class DshAgentService {
5867
5346
  return [...new Set([...this.clients.values()].flatMap((cs) => cs.mcpProjectCwds()))];
5868
5347
  }
5869
5348
  applyPluginAgentTools() {
5870
- // 工具桥(#15):插件工具列表变化 → 各客户端运行时重新注册。
5871
5349
  for (const cs of this.clients.values())
5872
5350
  void cs.syncPluginTools();
5873
5351
  }
@@ -5894,22 +5372,14 @@ export class DshAgentService {
5894
5372
  try {
5895
5373
  await cs.dispose();
5896
5374
  }
5897
- catch {
5898
- /* ignore */
5899
- }
5375
+ catch { }
5900
5376
  }
5901
5377
  this.clients.clear();
5902
5378
  }
5903
5379
  getCapabilities() {
5904
5380
  return DEFAULT_DSH_CAPABILITIES;
5905
5381
  }
5906
- /** dsh engine keeps no interrupted-run record — resume is pi-only. */
5907
- recordInterruptedRuns() {
5908
- /* no-op */
5909
- }
5910
- // -----------------------------------------------------------------------
5911
- // 插件扩展点适配层(AAL - Agent Adapter Layer)
5912
- // -----------------------------------------------------------------------
5382
+ recordInterruptedRuns() { }
5913
5383
  pluginClient() {
5914
5384
  let fallback;
5915
5385
  for (const cs of this.clients.values()) {