pi-web-ui 0.116.0 → 0.118.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (529) hide show
  1. package/CHANGELOG.md +83 -3
  2. package/README.md +69 -138
  3. package/README.zh-CN.md +70 -179
  4. package/README.zh-TW.md +3 -1
  5. package/bin/device-hub-cli.mjs +163 -36
  6. package/bin/frp-manager.mjs +4 -80
  7. package/bin/hub-upgrade.mjs +561 -0
  8. package/bin/pi-device-hub.mjs +0 -1
  9. package/bin/pi-web-ui.mjs +184 -504
  10. package/deploy/nginx-subpath.conf +0 -33
  11. package/deploy/pi-web-ui.service +0 -20
  12. package/dist/server/agent-formatters.js +4 -38
  13. package/dist/server/agent-service-daemon.js +203 -371
  14. package/dist/server/agent-service.js +1281 -3030
  15. package/dist/server/approval-audit.js +2 -23
  16. package/dist/server/approval-default-rules.js +0 -6
  17. package/dist/server/approval-rules.js +7 -105
  18. package/dist/server/ask-user-question-tool.js +1 -12
  19. package/dist/server/atomic-file.js +33 -5
  20. package/dist/server/attachment-store.js +0 -36
  21. package/dist/server/attachments.js +3 -112
  22. package/dist/server/auth-cookie.js +0 -21
  23. package/dist/server/bash-tool.js +1 -32
  24. package/dist/server/bg-servers.js +0 -96
  25. package/dist/server/browser-page-tool.js +11 -62
  26. package/dist/server/builtin-modules.js +7 -0
  27. package/dist/server/canvas/canvas-agent-tool.js +58 -47
  28. package/dist/server/canvas/canvas-cards.js +0 -14
  29. package/dist/server/canvas/canvas-dispatch.js +7 -4
  30. package/dist/server/canvas/canvas-orchestrator.js +167 -181
  31. package/dist/server/canvas/canvas-runtime-messages.js +30 -0
  32. package/dist/server/canvas/canvas-scheduled-task.js +0 -3
  33. package/dist/server/canvas/canvas-scheduler.js +5 -7
  34. package/dist/server/canvas/canvas-store.js +24 -35
  35. package/dist/server/canvas/canvas-validation.js +17 -14
  36. package/dist/server/canvas/canvas-workspace.js +42 -114
  37. package/dist/server/canvas/pstack-skills-data.js +0 -5
  38. package/dist/server/claim-files-tool.js +1 -15
  39. package/dist/server/claim-store.js +5 -49
  40. package/dist/server/client-id-utils.js +0 -16
  41. package/dist/server/client-state.js +36 -214
  42. package/dist/server/communicate-tool.js +0 -3
  43. package/dist/server/compact-context-tool.js +0 -30
  44. package/dist/server/compacted-history.js +0 -35
  45. package/dist/server/compaction-instructions.js +0 -13
  46. package/dist/server/compaction-markers.js +38 -92
  47. package/dist/server/compaction-state.js +0 -21
  48. package/dist/server/composer-drafts.js +0 -34
  49. package/dist/server/context-budget-runner.js +0 -11
  50. package/dist/server/context-budget.js +1 -70
  51. package/dist/server/context-evidence.js +0 -14
  52. package/dist/server/context-usage.js +0 -12
  53. package/dist/server/control-socket.js +4 -48
  54. package/dist/server/conversation-communication.js +0 -10
  55. package/dist/server/conversation-identity.js +0 -1
  56. package/dist/server/conversation-read-tool.js +0 -58
  57. package/dist/server/conversation-tool-names.js +0 -1
  58. package/dist/server/conversation-tool.js +0 -1
  59. package/dist/server/conversation-touches.js +4 -75
  60. package/dist/server/dangling-tools.js +142 -68
  61. package/dist/server/delegate-mode.js +0 -36
  62. package/dist/server/delegate-task.js +2 -28
  63. package/dist/server/device-center/approval-summary.js +0 -1
  64. package/dist/server/device-center/bot-catalog.js +0 -3
  65. package/dist/server/device-center/bot-execution.js +48 -9
  66. package/dist/server/device-center/bot-presets.js +0 -1
  67. package/dist/server/device-center/bots.js +0 -1
  68. package/dist/server/device-center/collab-service.js +27 -11
  69. package/dist/server/device-center/collab-tool.js +393 -27
  70. package/dist/server/device-center/connector.js +128 -48
  71. package/dist/server/device-center/delivery-authority.js +95 -0
  72. package/dist/server/device-center/delivery-subject.js +29 -0
  73. package/dist/server/device-center/desktop-linux.js +3 -15
  74. package/dist/server/device-center/desktop-native.js +1 -10
  75. package/dist/server/device-center/desktop-page.js +2 -3
  76. package/dist/server/device-center/desktop-setup.js +1 -3
  77. package/dist/server/device-center/desktop.js +1 -7
  78. package/dist/server/device-center/device-integration.js +452 -208
  79. package/dist/server/device-center/device-lan-access.js +403 -0
  80. package/dist/server/device-center/device-lan.js +484 -0
  81. package/dist/server/device-center/device-portals.js +0 -3
  82. package/dist/server/device-center/execution-failure.js +0 -2
  83. package/dist/server/device-center/execution-guides.js +15 -6
  84. package/dist/server/device-center/execution-instructions.js +0 -1
  85. package/dist/server/device-center/execution-settings.js +0 -1
  86. package/dist/server/device-center/execution-system-prompt.js +0 -3
  87. package/dist/server/device-center/execution-workspace.js +1 -4
  88. package/dist/server/device-center/executor.js +46 -31
  89. package/dist/server/device-center/file-sync-paths.js +0 -5
  90. package/dist/server/device-center/file-sync.js +0 -10
  91. package/dist/server/device-center/group-context-delta.js +0 -8
  92. package/dist/server/device-center/group-context-message.js +0 -14
  93. package/dist/server/device-center/group-context.js +0 -19
  94. package/dist/server/device-center/group-events.js +0 -2
  95. package/dist/server/device-center/group-plan-guard.js +1 -35
  96. package/dist/server/device-center/group-router-runtime.js +182 -0
  97. package/dist/server/device-center/group-router-worker.js +178 -0
  98. package/dist/server/device-center/group-router.js +359 -0
  99. package/dist/server/device-center/hub-auth.js +24 -2
  100. package/dist/server/device-center/hub-conversations.js +13 -15
  101. package/dist/server/device-center/hub-deliveries.js +119 -15
  102. package/dist/server/device-center/hub-integration.js +647 -334
  103. package/dist/server/device-center/hub-locks.js +1 -5
  104. package/dist/server/device-center/hub-mobile.js +147 -0
  105. package/dist/server/device-center/hub-orchestration.js +400 -0
  106. package/dist/server/device-center/hub-page.js +28 -9
  107. package/dist/server/device-center/hub-setup.js +23 -7
  108. package/dist/server/device-center/hub-transaction-log.js +175 -0
  109. package/dist/server/device-center/hub-upgrade.js +162 -0
  110. package/dist/server/device-center/hub-webhooks.js +1 -3
  111. package/dist/server/device-center/hub.js +946 -404
  112. package/dist/server/device-center/human-interaction.js +1 -4
  113. package/dist/server/device-center/integration-errors.js +0 -2
  114. package/dist/server/device-center/integration-verification.js +111 -0
  115. package/dist/server/device-center/local-hub.js +6 -4
  116. package/dist/server/device-center/local-publication.js +416 -0
  117. package/dist/server/device-center/local-verification-job.js +95 -0
  118. package/dist/server/device-center/local-verification.js +273 -0
  119. package/dist/server/device-center/local.js +341 -18
  120. package/dist/server/device-center/main.js +18 -2
  121. package/dist/server/device-center/mobile-notification-forwarder.js +292 -0
  122. package/dist/server/device-center/native-desktop/macos.js +0 -1
  123. package/dist/server/device-center/native-desktop/windows.js +0 -1
  124. package/dist/server/device-center/partition-log.js +52 -46
  125. package/dist/server/device-center/path-portal.js +42 -12
  126. package/dist/server/device-center/publication-journal.js +305 -0
  127. package/dist/server/device-center/publish-intent.js +374 -0
  128. package/dist/server/device-center/relay.js +217 -52
  129. package/dist/server/device-center/report-upload.js +0 -1
  130. package/dist/server/device-center/runtime.js +419 -52
  131. package/dist/server/device-center/store.js +223 -65
  132. package/dist/server/device-center/task-context-budget.js +0 -3
  133. package/dist/server/device-center/task-error.js +0 -1
  134. package/dist/server/device-center/task-journal.js +6 -23
  135. package/dist/server/device-center/task-outcome.js +68 -0
  136. package/dist/server/device-center/task-plan.js +0 -1
  137. package/dist/server/device-center/task-progress.js +0 -16
  138. package/dist/server/device-center/task-recovery.js +569 -227
  139. package/dist/server/device-center/task-report-outbox.js +0 -4
  140. package/dist/server/device-center/task-report.js +2 -10
  141. package/dist/server/device-center/task-scheduler.js +1 -35
  142. package/dist/server/device-center/task-settlement.js +335 -0
  143. package/dist/server/device-center/task-state.js +0 -12
  144. package/dist/server/device-center/task-workspace.js +393 -0
  145. package/dist/server/device-center/transfer-stream.js +5 -45
  146. package/dist/server/device-center/transfers.js +2 -10
  147. package/dist/server/device-center/verification-limits.js +9 -0
  148. package/dist/server/device-center/work-contract.js +923 -0
  149. package/dist/server/device-center/work-items.js +317 -0
  150. package/dist/server/device-center/workspaces.js +0 -1
  151. package/dist/server/dispatch-domain-handlers.js +202 -29
  152. package/dist/server/dispatch-plugin-handlers.js +2 -19
  153. package/dist/server/dsh/dsh-agent-service.js +78 -601
  154. package/dist/server/dsh/dsh-client.js +7 -111
  155. package/dist/server/dsh/dsh-market-service.js +4 -25
  156. package/dist/server/dsh/dsh-serialize.js +0 -49
  157. package/dist/server/dsh/dsh-sessions.js +0 -37
  158. package/dist/server/dsh/dsh-usage.js +0 -37
  159. package/dist/server/dsh/preset-clones.js +1 -65
  160. package/dist/server/dsh/runtime/custom-prompt.mjs +0 -14
  161. package/dist/server/dsh/runtime/goal-rpc.mjs +7 -176
  162. package/dist/server/dsh/runtime/launcher.mjs +2 -53
  163. package/dist/server/dsh/runtime/override.patch.yml +0 -29
  164. package/dist/server/dsh/runtime/runtime-root.mjs +0 -54
  165. package/dist/server/durable/durable-agent-service.js +5 -23
  166. package/dist/server/durable/durable-driver.js +12 -73
  167. package/dist/server/durable/durable-event-projector.js +1 -50
  168. package/dist/server/durable/durable-loader.js +0 -12
  169. package/dist/server/durable/durable-models.js +11 -80
  170. package/dist/server/durable/durable-storage.js +1 -17
  171. package/dist/server/durable/durable-tools.js +2 -20
  172. package/dist/server/durable/index.js +0 -3
  173. package/dist/server/edit-soft-tool.js +2 -81
  174. package/dist/server/engine-capabilities.js +0 -13
  175. package/dist/server/engine-catalog.js +74 -0
  176. package/dist/server/engine-cli.js +89 -0
  177. package/dist/server/engine-probe.js +35 -217
  178. package/dist/server/ensure-bash.js +2 -28
  179. package/dist/server/eval-tool.js +1 -50
  180. package/dist/server/evidence-tool-hooks.js +0 -2
  181. package/dist/server/file-archives.js +0 -10
  182. package/dist/server/file-save.js +1 -12
  183. package/dist/server/file-transfer-routes.js +0 -11
  184. package/dist/server/files-service.js +18 -271
  185. package/dist/server/global-loader.js +9 -89
  186. package/dist/server/goal-evidence.js +1 -35
  187. package/dist/server/goal-review-gate.js +0 -58
  188. package/dist/server/goal-service.js +19 -422
  189. package/dist/server/hashline-engine.js +8 -112
  190. package/dist/server/host-guard.js +0 -24
  191. package/dist/server/host-metrics.js +0 -6
  192. package/dist/server/http-proxy.js +1 -7
  193. package/dist/server/i18n.js +5 -72
  194. package/dist/server/icon-svg.js +0 -15
  195. package/dist/server/index.js +199 -677
  196. package/dist/server/json-utils.js +0 -12
  197. package/dist/server/launch-origin.js +0 -44
  198. package/dist/server/left-panel-running.js +0 -9
  199. package/dist/server/load-timing.js +1 -4
  200. package/dist/server/load-tools-tool.js +0 -20
  201. package/dist/server/locales.js +1 -46
  202. package/dist/server/lsp-tool.js +13 -126
  203. package/dist/server/managed.js +0 -48
  204. package/dist/server/marker-service.js +1 -22
  205. package/dist/server/markers/builtins/action.js +0 -19
  206. package/dist/server/markers/builtins/notify.js +1 -9
  207. package/dist/server/markers/builtins/rename.js +0 -13
  208. package/dist/server/markers/index.js +0 -3
  209. package/dist/server/markers/marker.js +0 -13
  210. package/dist/server/markers/registry.js +0 -3
  211. package/dist/server/markers/store.js +1 -12
  212. package/dist/server/market-service.js +7 -43
  213. package/dist/server/mcp-agent-tool.js +0 -10
  214. package/dist/server/mcp-bridge.js +6 -138
  215. package/dist/server/mcp-hot-reload.js +0 -25
  216. package/dist/server/mcp-manager.js +2 -44
  217. package/dist/server/mcp-oauth-login.js +0 -2
  218. package/dist/server/mcp-oauth-ui.js +1 -4
  219. package/dist/server/mcp-oauth.js +5 -79
  220. package/dist/server/mcp-project-runtime.js +0 -4
  221. package/dist/server/message-deletion.js +0 -2
  222. package/dist/server/message-entry-resolver.js +0 -8
  223. package/dist/server/message-window.js +0 -71
  224. package/dist/server/mobile-notification-events.js +16 -0
  225. package/dist/server/mobile-origin.js +79 -0
  226. package/dist/server/mobile-push.js +523 -0
  227. package/dist/server/model-admin.js +19 -358
  228. package/dist/server/model-enrich.js +0 -19
  229. package/dist/server/model-resolver.js +2 -61
  230. package/dist/server/native-cli-discovery.js +115 -0
  231. package/dist/server/native-cli-model.js +71 -0
  232. package/dist/server/native-cli-references.js +214 -0
  233. package/dist/server/native-cli-remote-cleanup.js +58 -0
  234. package/dist/server/native-cli-remote-files.js +282 -0
  235. package/dist/server/native-cli-routes.js +68 -0
  236. package/dist/server/native-cli-runtime.js +1 -0
  237. package/dist/server/native-cli-session-hooks.js +170 -0
  238. package/dist/server/native-cli-session.js +585 -0
  239. package/dist/server/native-cli-state.js +82 -0
  240. package/dist/server/native-cli.js +210 -0
  241. package/dist/server/net-guard.js +9 -71
  242. package/dist/server/office-parse.js +0 -50
  243. package/dist/server/orphan-manager.js +0 -18
  244. package/dist/server/patch-bash-process.js +0 -4
  245. package/dist/server/patch-executable-lookup.js +0 -77
  246. package/dist/server/patch-node-pty.js +6 -45
  247. package/dist/server/patch-remote-catalog.js +4 -34
  248. package/dist/server/patch-tool.js +0 -15
  249. package/dist/server/payload-limits.js +0 -5
  250. package/dist/server/pending-question.js +0 -5
  251. package/dist/server/permission-preset.js +4 -33
  252. package/dist/server/persona-chain.js +0 -26
  253. package/dist/server/pkg-info.js +1 -17
  254. package/dist/server/plan-manager.js +2 -49
  255. package/dist/server/plan-mode.js +0 -97
  256. package/dist/server/plan-update-tool.js +1 -15
  257. package/dist/server/plugin-api-catalog.js +6 -4
  258. package/dist/server/plugin-assets.js +1 -35
  259. package/dist/server/plugin-bundled.js +68 -0
  260. package/dist/server/plugin-catalog-sync.js +0 -37
  261. package/dist/server/plugin-catalog.js +13 -67
  262. package/dist/server/plugin-chat-attachments.js +0 -1
  263. package/dist/server/plugin-conversation-view.js +0 -20
  264. package/dist/server/plugin-dom.js +1 -23
  265. package/dist/server/plugin-facilities.js +4 -115
  266. package/dist/server/plugin-grants.js +2 -90
  267. package/dist/server/plugin-install-spec.js +0 -43
  268. package/dist/server/plugin-installer.js +34 -75
  269. package/dist/server/plugin-llm.js +4 -38
  270. package/dist/server/plugin-manifest-validate.js +0 -31
  271. package/dist/server/plugin-permissions.js +1 -24
  272. package/dist/server/plugin-project.js +7 -129
  273. package/dist/server/plugin-removal.js +1 -8
  274. package/dist/server/plugin-schedule.js +1 -38
  275. package/dist/server/plugin-secrets.js +3 -16
  276. package/dist/server/plugin-tool-guard.js +1 -28
  277. package/dist/server/plugin-ui-slots.js +0 -4
  278. package/dist/server/plugin-updater.js +15 -90
  279. package/dist/server/plugins.js +71 -619
  280. package/dist/server/present-files-tool.js +0 -57
  281. package/dist/server/preset-fields.js +24 -61
  282. package/dist/server/preset-plugin-dependencies.js +0 -2
  283. package/dist/server/preset-share.js +4 -172
  284. package/dist/server/process-utils.js +4 -80
  285. package/dist/server/prompt-assembler.js +2 -30
  286. package/dist/server/prompt-base-store.js +0 -47
  287. package/dist/server/prompt-composer.js +21 -98
  288. package/dist/server/prompt-templates.js +0 -2
  289. package/dist/server/protocol-version.js +1 -11
  290. package/dist/server/protocol.js +0 -5
  291. package/dist/server/queue-modes.js +0 -3
  292. package/dist/server/queue-utils.js +0 -40
  293. package/dist/server/quick-ask-context.js +384 -0
  294. package/dist/server/quick-ask-settings.js +61 -0
  295. package/dist/server/quick-ask.js +260 -0
  296. package/dist/server/read-tool.js +0 -65
  297. package/dist/server/reasoning-registry.js +1 -29
  298. package/dist/server/remote-cli-persistence.js +373 -0
  299. package/dist/server/remote-native-cli.js +78 -0
  300. package/dist/server/remote-ssh-service.js +481 -190
  301. package/dist/server/request-context.js +0 -9
  302. package/dist/server/resolve-global-sdk.js +55 -31
  303. package/dist/server/sandbox-data.js +0 -1
  304. package/dist/server/sandbox-engines.js +0 -1
  305. package/dist/server/sandbox-runtime-gate.js +0 -3
  306. package/dist/server/sandbox-service.js +0 -41
  307. package/dist/server/sandbox-tool.js +0 -20
  308. package/dist/server/schedule-agent-tool.js +2 -31
  309. package/dist/server/scheduler-tasks.js +32 -56
  310. package/dist/server/scm-commitmsg.js +0 -53
  311. package/dist/server/scm.js +3 -48
  312. package/dist/server/sdk-builtin-extensions.js +2 -29
  313. package/dist/server/sdk-origin.js +0 -45
  314. package/dist/server/serialize.js +2 -92
  315. package/dist/server/server-config.js +0 -11
  316. package/dist/server/session-branch.js +1 -87
  317. package/dist/server/session-list-scan.js +215 -0
  318. package/dist/server/session-open.js +69 -0
  319. package/dist/server/session-parser.js +4 -54
  320. package/dist/server/session-scan.js +81 -45
  321. package/dist/server/session-search.js +0 -56
  322. package/dist/server/settings-service.js +19 -126
  323. package/dist/server/setup-config.js +0 -2
  324. package/dist/server/setup-page.js +0 -9
  325. package/dist/server/skill-content-filler.js +0 -17
  326. package/dist/server/skill-discovery.js +5 -92
  327. package/dist/server/skill-maintenance.js +1 -28
  328. package/dist/server/skill-tool.js +0 -30
  329. package/dist/server/slash-commands.js +5 -50
  330. package/dist/server/soft-cap.js +3 -40
  331. package/dist/server/startup-banner.js +0 -8
  332. package/dist/server/subagent-handoff.js +0 -11
  333. package/dist/server/subagent-helpers.js +2 -17
  334. package/dist/server/subagent-notify.js +0 -19
  335. package/dist/server/subagent-security-gate.js +0 -50
  336. package/dist/server/subagent-task.js +0 -9
  337. package/dist/server/subagent-templates-hant.js +0 -10
  338. package/dist/server/subagent-templates.js +3 -103
  339. package/dist/server/subagents.js +1 -87
  340. package/dist/server/system-screenshot-windows.js +259 -0
  341. package/dist/server/system-screenshot.js +77 -0
  342. package/dist/server/tabs.js +3 -48
  343. package/dist/server/terminals.js +559 -586
  344. package/dist/server/text-quote.js +0 -12
  345. package/dist/server/text-sniff.js +2 -52
  346. package/dist/server/themes.js +2 -41
  347. package/dist/server/tool-approval.js +0 -47
  348. package/dist/server/tool-guards.js +0 -90
  349. package/dist/server/tool-host-factories.js +1 -16
  350. package/dist/server/tool-info.js +0 -13
  351. package/dist/server/tool-manager.js +1 -229
  352. package/dist/server/tool-overrides.js +1 -46
  353. package/dist/server/tool-prompt-overrides.js +1 -30
  354. package/dist/server/tool-prompts.js +0 -14
  355. package/dist/server/tool-signature.js +0 -25
  356. package/dist/server/transcript-prepare.js +55 -0
  357. package/dist/server/tts-routes.js +58 -0
  358. package/dist/server/tts-service.js +106 -0
  359. package/dist/server/tts-system.js +160 -0
  360. package/dist/server/turn-timing.js +0 -1
  361. package/dist/server/unauthorized-page.js +0 -8
  362. package/dist/server/universal/driver-base.js +2 -31
  363. package/dist/server/universal/drivers/claude-code.js +98 -194
  364. package/dist/server/universal/drivers/codex.js +12 -35
  365. package/dist/server/universal/drivers/mock-driver.js +1 -11
  366. package/dist/server/universal/index.js +0 -3
  367. package/dist/server/universal/session-store.js +4 -21
  368. package/dist/server/universal/universal-attachments.js +2 -36
  369. package/dist/server/universal/universal-service.js +5 -24
  370. package/dist/server/universal/universal-session.js +30 -148
  371. package/dist/server/universal/universal-types.js +0 -3
  372. package/dist/server/update-check.js +6 -182
  373. package/dist/server/uploads.js +4 -43
  374. package/dist/server/virtual-tui.js +2 -27
  375. package/dist/server/vision-bridge.js +0 -27
  376. package/dist/server/wait-subscription-scan.js +13 -115
  377. package/dist/server/webui-context.js +2 -87
  378. package/dist/server/workspace-handle.js +373 -0
  379. package/dist/server/workspace-snapshot.js +7 -113
  380. package/dist/server/worktree-service.js +2 -53
  381. package/dist/server/worktree-tool.js +0 -11
  382. package/dist/server/ws-client-id.js +0 -18
  383. package/dist/server/ws-pending-queue.js +0 -7
  384. package/dist/server/ws-unknown-types.js +0 -17
  385. package/docs/README.md +24 -17
  386. package/docs/architecture-plugins.md +55 -6
  387. package/docs/device-center.md +57 -23
  388. package/docs/device-desktop.md +3 -3
  389. package/docs/group-orchestration.md +142 -0
  390. package/docs/hub-upgrade-release-testing.md +46 -0
  391. package/extensions/webui.ts +3 -74
  392. package/package.json +9 -6
  393. package/plugin-sdk/README.md +22 -8
  394. package/plugin-sdk/client-utils.mjs +0 -7
  395. package/plugin-sdk/client.d.ts +26 -0
  396. package/plugin-sdk/client.mjs +52 -0
  397. package/plugin-sdk/import-check.mjs +4 -51
  398. package/plugin-sdk/index.d.ts +128 -117
  399. package/plugin-sdk/index.mjs +2 -687
  400. package/plugin-sdk/package.json +15 -4
  401. package/plugin-sdk/ssh-host-trust.mjs +0 -12
  402. package/plugin-sdk/testing.d.ts +9 -0
  403. package/plugin-sdk/testing.mjs +511 -0
  404. package/plugins/catalog.json +52 -4
  405. package/plugins/superagent/README.md +110 -0
  406. package/plugins/superagent/client/entry.mjs +21 -0
  407. package/plugins/superagent/index.mjs +8 -0
  408. package/plugins/superagent/main.mjs +218 -0
  409. package/plugins/superagent/manifest.json +15 -0
  410. package/plugins/superagent/server.mjs +572 -0
  411. package/plugins/superagent/style.css +167 -0
  412. package/themes/aetheris.css +1 -31
  413. package/themes/ayu-light.css +0 -1
  414. package/themes/bases/flow-base.css +2 -83
  415. package/themes/bases/obsidian-base.css +2 -37
  416. package/themes/bases/statusbar-flat-base.css +0 -1
  417. package/themes/bases/zhujian-base.css +0 -63
  418. package/themes/bases/zhupi-base.css +0 -64
  419. package/themes/catppuccin-latte.css +0 -1
  420. package/themes/catppuccin.css +0 -1
  421. package/themes/claude-code-dark.css +0 -1
  422. package/themes/codex.css +0 -1
  423. package/themes/dark-teal.css +22 -54
  424. package/themes/everforest-light.css +0 -1
  425. package/themes/flow-cristallo.css +160 -0
  426. package/themes/flow-ink.css +160 -0
  427. package/themes/flow-light.css +1 -10
  428. package/themes/flow-obsidian.css +160 -0
  429. package/themes/flow-zurich.css +160 -0
  430. package/themes/flow.css +1 -9
  431. package/themes/geist.css +0 -1
  432. package/themes/gruvbox-light.css +0 -1
  433. package/themes/kanagawa-lotus.css +0 -1
  434. package/themes/md-preview.css +1 -2
  435. package/themes/mist.css +0 -1
  436. package/themes/nord.css +0 -1
  437. package/themes/one-dark.css +0 -1
  438. package/themes/paper.css +0 -1
  439. package/themes/rose-pine-dawn.css +0 -1
  440. package/themes/sakura.css +0 -1
  441. package/themes/solarized-light.css +0 -1
  442. package/themes/tokyo-night.css +0 -1
  443. package/themes/translucent.css +4 -35
  444. package/themes/transparent.css +4 -41
  445. package/themes/vs-code-dark.css +0 -1
  446. package/themes/wallpaper-flow.css +3 -17
  447. package/themes/wallpaper-obsidian.css +1 -4
  448. package/themes/white.css +0 -1
  449. package/web/dist/.build-assets.json +1 -1
  450. package/web/dist/assets/{BgTasksModal-BDoOpj-F.js → BgTasksModal-D-x7kA63.js} +1 -1
  451. package/web/dist/assets/CanvasStudio-CAWcs9tm.js +1579 -0
  452. package/web/dist/assets/DeviceCenter-Dc0whRcu.js +3 -0
  453. package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +1 -0
  454. package/web/dist/assets/DeviceGroups-C_fZMNeK.js +1 -0
  455. package/web/dist/assets/{Dropdown-C4LIhshN.js → Dropdown-CTgVLUbp.js} +1 -1
  456. package/web/dist/assets/FilePreview-C6W0PvaK.js +2 -0
  457. package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +1 -0
  458. package/web/dist/assets/GroupConversation-C81YjF2C.js +61 -0
  459. package/web/dist/assets/GroupWorkItems-BIvZtr10.js +1 -0
  460. package/web/dist/assets/{HintTip-c6d0TJoh.js → HintTip-Da6qc566.js} +1 -1
  461. package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +2 -0
  462. package/web/dist/assets/NativeCliPanel-CU1rZmyu.js +5 -0
  463. package/web/dist/assets/{PiSetupModal-BmMrrgB9.js → PiSetupModal-DZKY5Wiw.js} +1 -1
  464. package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +1 -0
  465. package/web/dist/assets/SCMPanel-CuEgzAlO.js +2 -0
  466. package/web/dist/assets/SettingsModal-Cdu5h29p.js +33 -0
  467. package/web/dist/assets/TermXterm-Bt5WKAxP.js +3 -0
  468. package/web/dist/assets/TerminalPanel-BCIBV8se.js +1 -0
  469. package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +1 -0
  470. package/web/dist/assets/app-globals-CZjFtI4F.js +129 -0
  471. package/web/dist/assets/canvas-client-WkhM55mR.js +1 -0
  472. package/web/dist/assets/composer-bridge-CImnjDHq.js +1 -0
  473. package/web/dist/assets/desktop-B8NZ3KW-.js +1 -0
  474. package/web/dist/assets/index-CQc3VrWa.css +1 -0
  475. package/web/dist/assets/index-D_AGu4Zv.js +404 -0
  476. package/web/dist/assets/plugin-host-uqZGpvCs.js +1 -0
  477. package/web/dist/assets/{remote-ssh-client-CfYSMEZg.js → remote-ssh-client-Cdf-cTUe.js} +1 -1
  478. package/web/dist/assets/theme-DGL7hLUs.js +1 -0
  479. package/web/dist/index.html +12 -11
  480. package/web/dist/sw.js +15 -61
  481. package/web/public/sw.js +14 -60
  482. package/dist/gh-comment-781.md +0 -5
  483. package/dist/server/device-center/local-page.js +0 -17
  484. package/dist/server/device-center/smoke-preview.js +0 -3
  485. package/dist/server/durable/durable-capabilities.js +0 -11
  486. package/dist/server/markers/builtins/services.js +0 -123
  487. package/dist/server/markers/builtins/todo.js +0 -189
  488. package/dist/server/markers-list-tool.js +0 -34
  489. package/dist/server/orchestrator.js +0 -109
  490. package/dist/server/patch-turn-end-boundary.js +0 -77
  491. package/dist/server/system-prompt-soul.js +0 -41
  492. package/dist/server/univer-service.js +0 -448
  493. package/dist/server/universal/drivers/dsh-driver.js +0 -379
  494. package/dist/test-artifact.md +0 -9
  495. package/dist/test-preview-modal.md +0 -11
  496. package/dist/test-report.html +0 -20
  497. package/web/dist/assets/BgTasksModal-C0i3O1FT.js +0 -1
  498. package/web/dist/assets/CanvasStudio-B8thymBN.js +0 -1579
  499. package/web/dist/assets/CanvasStudio-zSxyIx1R.js +0 -1579
  500. package/web/dist/assets/DeviceCenter-DfAHKcid.js +0 -3
  501. package/web/dist/assets/DeviceCenter-ydvOTlzE.js +0 -3
  502. package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +0 -1
  503. package/web/dist/assets/DeviceGroups-CI14_SRb.js +0 -1
  504. package/web/dist/assets/DeviceGroups-DvsB5IEU.js +0 -1
  505. package/web/dist/assets/FilePreview-BgGongmv.js +0 -2
  506. package/web/dist/assets/FilePreview-D4NrhF-U.js +0 -2
  507. package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +0 -1
  508. package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +0 -1
  509. package/web/dist/assets/GroupConversation-Dh71Pdb-.js +0 -17
  510. package/web/dist/assets/GroupConversation-ZK3nRmNm.js +0 -17
  511. package/web/dist/assets/ModelConfigModal-YVEgyy34.js +0 -2
  512. package/web/dist/assets/ModelConfigModal-vWtg3srp.js +0 -2
  513. package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +0 -1
  514. package/web/dist/assets/SCMPanel-B8_EDxNr.js +0 -2
  515. package/web/dist/assets/SCMPanel-BU58qk3T.js +0 -2
  516. package/web/dist/assets/SettingsModal-CMUybq3J.js +0 -32
  517. package/web/dist/assets/SettingsModal-OBmGTh-5.js +0 -32
  518. package/web/dist/assets/TerminalPanel-0CYvD72B.js +0 -3
  519. package/web/dist/assets/TerminalPanel-DDavKvFr.js +0 -3
  520. package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +0 -1
  521. package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +0 -1
  522. package/web/dist/assets/app-globals-CZxzGvIo.js +0 -123
  523. package/web/dist/assets/canvas-client-CUnXlQYX.js +0 -1
  524. package/web/dist/assets/desktop-aAKpvKJV.js +0 -1
  525. package/web/dist/assets/index-C6DwztqE.css +0 -1
  526. package/web/dist/assets/index-CuN802Sj.js +0 -93
  527. package/web/dist/assets/index-EH5Fw9fa.js +0 -93
  528. package/web/dist/assets/plugin-host-BRWib9DF.js +0 -1
  529. package/web/dist/assets/theme-D2l_mLNo.js +0 -1
@@ -1,38 +1,14 @@
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";
3
+ import { mergeQuickAskSettings, normalizeQuickAskSettings } from "../quick-ask-settings.js";
4
+ import { captureQuickAskConversation } from "../quick-ask-context.js";
29
5
  import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
30
6
  import { basename, dirname, join, resolve, sep } from "node:path";
31
7
  import { randomUUID } from "node:crypto";
32
8
  import { homedir } from "node:os";
33
9
  import { BG_CLEANUP_FALLBACK_MIN, BgServerTracker } from "../bg-servers.js";
34
10
  import { ClientStateStore, DEFAULT_RETRY_MAX_ATTEMPTS, normalizeBgCleanupMinutes, normalizePathKey, normalizeToolWatchdogTimeoutMs, settingsPresetToUi, } from "../client-state.js";
35
- import { normalizeUiLayout, normalizeKeepRecentMessages, DEFAULT_KEEP_RECENT_MESSAGES } from "../client-state.js";
11
+ import { normalizeUiLayout, normalizeKeepRecentMessages, DEFAULT_KEEP_RECENT_MESSAGES, RECENT_PROJECTS_MAX, } from "../client-state.js";
36
12
  import { PLAN_MODE_SYSTEM_PROMPT } from "../plan-mode.js";
37
13
  import { buildToolsSchemaText } from "../prompt-composer.js";
38
14
  import { FilesService, workspacePath, desktopDirWire } from "../files-service.js";
@@ -68,19 +44,13 @@ import { exportPresetVia, importPresetFromUrlVia, importPresetVia, packageVersio
68
44
  import { getAppVersion } from "../pkg-info.js";
69
45
  import { getMaxOpenConversations } from "../agent-formatters.js";
70
46
  const SNAPSHOT_INTERVAL_MS = 60;
71
- /** 用户主目录(wire 格式):进程内不变,模块加载时求值一次(右栏 🏠)。 */
72
47
  const HOME_WIRE = homedir().replace(/\\/g, "/");
73
- /** 桌面目录(wire 格式):进程内不变,不存在则空串 → 前端不渲染 🖥️。 */
74
48
  const DESKTOP_WIRE = desktopDirWire(HOME_WIRE);
75
- /** 新会话默认权限预设(沙箱内 + 无审批弹窗;无头运行的当前行为,保持不变)。 */
76
49
  const PERMISSION_DEFAULT_PRESET = "workspace-write-never";
77
- /** 前端提供的三档(官方 workspace-write 走 ask,无应答者时是死路,不提供)。 */
78
50
  const PERMISSION_OFFERED = ["read-only", "workspace-write-never", "danger-full-access"];
79
51
  const DEFAULT_CONV_TITLE = "新对话";
80
52
  const DEFAULT_CONV_TITLE_EN = "New chat";
81
53
  const DEFAULT_MODEL = "deepseek-v4-flash";
82
- /** DSH 可选模型(顶栏模型选择器)。仅 deepseek-v4-flash-vision-exp 支持图片
83
- * (adapter 默认目录 inputModalities: [text, image]);flash/pro 是 text-only。 */
84
54
  const DSH_MODELS = [
85
55
  { id: "deepseek-v4-flash", name: "DeepSeek V4 Flash", provider: "deepseek", vision: false },
86
56
  { id: "deepseek-v4-pro", name: "DeepSeek V4 Pro", provider: "deepseek", vision: false },
@@ -91,12 +61,10 @@ const DSH_MODELS = [
91
61
  vision: true,
92
62
  },
93
63
  ];
94
- /** DeepSeek V4 context window + 官方每 1M token 定价(USD,api-docs.deepseek.com)。 */
95
64
  const DSH_CONTEXT_WINDOW = 1_000_000;
96
65
  const DSH_PRICE_INPUT = 0.14;
97
66
  const DSH_PRICE_CACHE_READ = 0.0028;
98
67
  const DSH_PRICE_OUTPUT = 0.28;
99
- /** 会话 root:<dataDir>/dsh-sessions(与 pi 引擎的会话目录隔离)。 */
100
68
  function dshSessionRoot(dataDir) {
101
69
  return join(dataDir, "dsh-sessions");
102
70
  }
@@ -108,9 +76,6 @@ function estimateCost(t) {
108
76
  t.output * DSH_PRICE_OUTPUT) /
109
77
  1e6);
110
78
  }
111
- /** 把插件工具 execute 的原始返回值归一化成模型可读文本。
112
- * 兼容:`{content:[{type:"text",text}...],details}` → text 拼接;string → 原串;
113
- * 其它对象 → JSON.stringify;null/undefined → 空串。 */
114
79
  function normalizeToolResult(result) {
115
80
  if (typeof result === "string")
116
81
  return result;
@@ -170,30 +135,20 @@ const DEFAULT_SETTINGS = {
170
135
  promptOverrides: {},
171
136
  promptDisabled: [],
172
137
  };
173
- // ---------------------------------------------------------------------------
174
- // DshClientSession — 一个浏览器客户端
175
- // ---------------------------------------------------------------------------
176
138
  export class DshClientSession {
177
139
  clientId;
178
140
  cwd;
179
- /** 当前项目的额外工作区根(宿主侧多根,见 protocol 的 set_workspace_roots)——
180
- * 按 cwd 存在 client-state 里,这里只存一份内存缓存给快照热路径读。 */
181
141
  roots = [];
182
142
  stateStore;
183
143
  sessionRoot;
184
144
  dataDir;
185
- /** pi 配置目录(auth.json 所在;尊重 PI_CODING_AGENT_DIR)。 */
186
145
  agentDir;
187
- /** 用户直接创建的交互式终端(按 CLIENT/工作区 存活,始终显示,不受单个对话切换、生命周期与过滤影响) */
188
146
  userTerminals;
189
147
  runtime;
190
148
  convs = new Map();
191
149
  activeId = "";
192
150
  convSeq = 0;
193
- /** 待答问卷快照(见 attachRuntimeEvents 的 question.pending 与
194
- * UiState.pendingQuestion):重连/刷新后由快照恢复对话框。 */
195
151
  pendingQuestion = null;
196
- /** 客户端级目标/审查偏好(跨会话共享的默认值,per-conversation goal 用它初始化)。 */
197
152
  goalPrefs = { reviewModel: null, maxRounds: 2, locked: false };
198
153
  sinks = new Set();
199
154
  pendingNotices = [];
@@ -211,35 +166,24 @@ export class DshClientSession {
211
166
  modelDisplayName = "DeepSeek V4 Flash";
212
167
  modelVision = false;
213
168
  thinkingLevel = "high";
214
- /** P0-1 watchdog:60s 窗口内最多自动重启 2 次,超限升级为报错 notice。 */
215
169
  static RUNTIME_RESTART_WINDOW_MS = 60_000;
216
170
  static RUNTIME_MAX_RESTARTS = 2;
217
171
  runtimeRestart = { count: 0, windowStart: 0 };
218
- /** P0-3 convs 内存回收:非活跃且非 streaming 的 conversation 定期回收(JSONL 在磁盘,回放可恢复)。 */
219
172
  static RECLAIM_INTERVAL_MS = 5 * 60_000;
220
- /** 未进左栏“运行的对话”的空闲上限。 */
221
173
  static CONV_RECLAIM_IDLE_MS = 30 * 60_000;
222
- /** 已在左栏“运行的对话”里的空闲上限(用户可见,给更长的保留期)。 */
223
174
  static CONV_RECLAIM_LISTED_IDLE_MS = 24 * 3600_000;
224
175
  reclaimTimer = null;
225
- /** P1-13 会话 JSONL 保留期(PI_WEB_DSH_SESSION_RETENTION_DAYS,默认 90 天)。 */
226
176
  static SESSION_RETENTION_MS = (Number(process.env.PI_WEB_DSH_SESSION_RETENTION_DAYS) || 90) * 24 * 3600_000;
227
177
  retentionTimer = null;
228
178
  retentionOnce = null;
229
179
  settings = { ...DEFAULT_SETTINGS };
230
- /** 最近一次从运行时拉取的技能清单(UiSkillInfo,含 enabled 由 disabledSkills 推导)。 */
231
180
  skillsCache = [];
232
- /** 运行时世代(每次 start 成功 +1;conv.assignedGen 用它判断 preset/assign 是否过期)。 */
233
181
  runtimeGen = 0;
234
- /** Agent 预设名录缓存(运行时 preset/list;unavailable/空 = legacy,UI 隐藏预设条)。 */
235
182
  agentPresets = [];
236
183
  agentPresetDefault = PRESET_DEFAULT_ID;
237
184
  agentPresetsAvailable = false;
238
- /** 权限选项表缓存(组合静态;空 = 未就绪/legacy,前端隐藏权限条)。 */
239
185
  permissionOptions = [];
240
- /** clone 出来的预设 id(roster 名录校验用;空 = 未生成,走 legacy)。 */
241
186
  presetCloneIds = [];
242
- /** 系统提示词缓存(从运行时 inspectPrompt 异步拉取;未就绪时兜底)。 */
243
187
  cachedEffectiveSystemPrompt = "";
244
188
  cachedToolsSchema = "";
245
189
  cachedPromptSections = [];
@@ -254,7 +198,6 @@ export class DshClientSession {
254
198
  }
255
199
  markerSvc;
256
200
  modelAdmin;
257
- /** 插件扩展点(index.ts 注入)。 */
258
201
  onToolEvent;
259
202
  pluginToolsProvider;
260
203
  pluginCommandsProvider;
@@ -263,14 +206,11 @@ export class DshClientSession {
263
206
  onQuit;
264
207
  isQuiesced;
265
208
  onCwdChanged;
266
- /** issue #145 跨客户端感知(DshAgentService.attach 接线,与 pi 引擎同语义;
267
- * DSH 的会话身份是 sessionId = JSONL 目录名)。 */
268
209
  findSessionOwnerById = undefined;
269
210
  listProjectRunners = undefined;
270
211
  listExternalRunning = undefined;
271
212
  notifyExternalClients = undefined;
272
213
  onRunningChanged = undefined;
273
- /** issue #145:上次 emit 时流式对话签名(变化才 poke 其他客户端,防循环)。 */
274
214
  lastRunningSig = "";
275
215
  constructor(clientId, cwd, stateStore, dataDir, agentDir) {
276
216
  this.clientId = clientId;
@@ -285,9 +225,7 @@ export class DshClientSession {
285
225
  try {
286
226
  mkdirSync(this.sessionRoot, { recursive: true });
287
227
  }
288
- catch {
289
- /* best effort */
290
- }
228
+ catch { }
291
229
  this.files = new FilesService({
292
230
  emit: (msg) => this.emit(msg),
293
231
  isDisposed: () => this.disposed,
@@ -337,8 +275,6 @@ export class DshClientSession {
337
275
  }
338
276
  static create(clientId, cwd, stateStore, dataDir, agentDir) {
339
277
  const cs = new DshClientSession(clientId, cwd, stateStore, dataDir, agentDir ?? join(homedir(), ".pi", "agent"));
340
- // 恢复上次使用的目标/审查偏好(全局记忆,跨重载存活;per-conversation
341
- // 目标用它初始化)。
342
278
  const gPrefs = stateStore.getGoalPrefs(clientId);
343
279
  if (gPrefs) {
344
280
  cs.goalPrefs = {
@@ -347,12 +283,10 @@ export class DshClientSession {
347
283
  locked: gPrefs.locked,
348
284
  };
349
285
  }
350
- // 恢复上次使用的模型(按 DSH 引擎独立记录:项目记忆 > 全局默认)
351
286
  const savedModel = stateStore.getProjectModel(clientId, cwd, "dsh") ?? stateStore.getDefaultModel("dsh");
352
287
  if (savedModel) {
353
288
  cs.applySavedModel(savedModel);
354
289
  }
355
- // 恢复上次使用的设置(跨重连存活;DSH 忽略无行为字段但回显保持 UI 一致)。
356
290
  const savedSettings = stateStore.getSettings(clientId);
357
291
  if (savedSettings) {
358
292
  cs.settings = {
@@ -394,7 +328,6 @@ export class DshClientSession {
394
328
  : PERMISSION_DEFAULT_PRESET,
395
329
  };
396
330
  }
397
- // 恢复最近会话(若有)或新建空白会话(避免刷新页面后丢失历史变成空白新对话)
398
331
  cs.makeRuntime();
399
332
  const recentFiles = findSessionFilesForCwd(cs.sessionRoot, cwd).filter((f) => !basename(dirname(f)).startsWith("review-"));
400
333
  let resumedConv = null;
@@ -424,8 +357,6 @@ export class DshClientSession {
424
357
  cs.activeId = first.id;
425
358
  }
426
359
  cs.attachRuntimeEvents();
427
- // 每次启动成功(含初次/换模型/watchdog 重启)后重新注册插件工具桥,
428
- // 因为重 spawn 后的 ctx.tools 是全新的,需要重新 sync 插件工具。
429
360
  cs.runtime.onStarted = () => {
430
361
  if (cs.switchingWorkspace)
431
362
  return;
@@ -438,14 +369,12 @@ export class DshClientSession {
438
369
  void cs.refreshActivePermission().catch(() => { });
439
370
  void cs.refreshPromptInfo().catch(() => { });
440
371
  };
441
- // P0-1 watchdog:意外退出(非 kill/close 主动触发)→ 限频自动重启,保持可用。
442
372
  cs.runtime.onExit = (code, signal, intentional) => {
443
373
  cs.cancelBridgedTools();
444
374
  if (intentional)
445
- return; // kill()/close() 主动触发,不重启
375
+ return;
446
376
  cs.handleRuntimeExit(code, signal);
447
377
  };
448
- // P0-5 启动重试:1s/3s/9s 指数退避,最终失败才发 notice。
449
378
  void cs.startWithRetry().catch((err) => {
450
379
  console.error(`[dsh] runtime.start 失败 (client=${clientId}): ${err.message}`);
451
380
  const errMsg = err.message || "";
@@ -463,10 +392,8 @@ export class DshClientSession {
463
392
  textEn: `DSH runtime failed to start: ${errMsg}. ${hintEn}`,
464
393
  });
465
394
  });
466
- // P0-3 convs 内存回收定时器(unref:不阻止进程退出)。
467
395
  cs.reclaimTimer = setInterval(() => cs.reclaimIdleConversations(), DshClientSession.RECLAIM_INTERVAL_MS);
468
396
  cs.reclaimTimer.unref?.();
469
- // P1-13 会话 JSONL 保留期清理:启动后 10s 首清 + 每 24h 一次(幂等)。
470
397
  cs.retentionOnce = setTimeout(() => void cs.cleanupExpiredSessions(), 10_000);
471
398
  cs.retentionOnce.unref?.();
472
399
  cs.retentionTimer = setInterval(() => void cs.cleanupExpiredSessions(), 24 * 3600_000);
@@ -474,7 +401,6 @@ export class DshClientSession {
474
401
  cs.bg.start();
475
402
  return cs;
476
403
  }
477
- /** P0-5 带指数退避的启动(1s/3s/9s,最终失败才抛)。 */
478
404
  async startWithRetry() {
479
405
  const delays = [1000, 3000, 9000];
480
406
  let lastErr;
@@ -492,17 +418,14 @@ export class DshClientSession {
492
418
  }
493
419
  throw lastErr;
494
420
  }
495
- /** P0-1 意外崩溃处理:重置进行中的 conv 状态 → 限频自动重启。 */
496
421
  handleRuntimeExit(code, signal) {
497
422
  if (this.disposed)
498
423
  return;
499
424
  console.error(`[dsh] runtime 意外退出 (client=${this.clientId}) code=${code} signal=${signal}`);
500
- // 进行中的 run 全部中断(pending RPC 已被 failPending reject)→ 复位 streaming。
501
425
  for (const conv of this.convs.values()) {
502
426
  finishTurnTiming(conv);
503
427
  conv.isStreaming = false;
504
428
  conv.streaming = null;
505
- // 直播帧能力跟着运行时进程走:重启后重新探测(换运行时版本也能回落到持久 assistant/chunk)。
506
429
  conv.liveChunks = false;
507
430
  }
508
431
  this.emitConversations();
@@ -547,7 +470,6 @@ export class DshClientSession {
547
470
  });
548
471
  this.flushSnapshot();
549
472
  }
550
- /** P0-3 回收长时间空闲的非活跃 conversation(磁盘 JSONL 在,回放即可恢复)。 */
551
473
  reclaimIdleConversations() {
552
474
  if (this.disposed)
553
475
  return;
@@ -558,7 +480,6 @@ export class DshClientSession {
558
480
  continue;
559
481
  if (conv.isStreaming)
560
482
  continue;
561
- // 只看“用过”的存活终端:没动过的空 shell 不阻止空闲回收。
562
483
  if (conv.terminals.countBlockingLive() > 0)
563
484
  continue;
564
485
  const idle = now - conv.lastEventAt;
@@ -573,8 +494,6 @@ export class DshClientSession {
573
494
  this.flushSnapshot();
574
495
  }
575
496
  }
576
- /** P1-13 清理超过保留期未活动的会话目录(<sessionRoot>/<projectKey>/<sessionId>/)。
577
- * 目录内最新文件 mtime 判活跃(JSONL 追加写不更新目录 mtime,不能看目录本身)。 */
578
497
  async cleanupExpiredSessions() {
579
498
  if (this.disposed)
580
499
  return;
@@ -600,14 +519,10 @@ export class DshClientSession {
600
519
  max = Math.max(max, m);
601
520
  }
602
521
  }
603
- catch {
604
- /* skip unreadable */
605
- }
522
+ catch { }
606
523
  }
607
524
  }
608
- catch {
609
- /* skip unreadable dir */
610
- }
525
+ catch { }
611
526
  return max;
612
527
  };
613
528
  let removed = 0;
@@ -625,7 +540,7 @@ export class DshClientSession {
625
540
  continue;
626
541
  const lastMod = dirLastModified(p, cutoff);
627
542
  if (lastMod === 0)
628
- continue; // 空目录不删
543
+ continue;
629
544
  if (lastMod < cutoff) {
630
545
  rmSync(p, { recursive: true, force: true });
631
546
  removed++;
@@ -641,13 +556,9 @@ export class DshClientSession {
641
556
  this.scheduleSessionsRefresh();
642
557
  }
643
558
  }
644
- catch {
645
- /* best effort */
646
- }
559
+ catch { }
647
560
  }
648
561
  makeRuntime() {
649
- // Agent 预设 clone(file: 改写 shipped 预设,供 preset-plane patch 的 roster 用)。
650
- // 成功 → 下发 patch(预设时代);失败/null → 不下发(回落 legacy 单组合)。
651
562
  let presetPatch;
652
563
  try {
653
564
  const clones = generatePresetClones(this.dataDir);
@@ -691,17 +602,13 @@ export class DshClientSession {
691
602
  this.handleSessionEvent(params);
692
603
  }
693
604
  else if (method === "assistant.stream") {
694
- // 新版运行时(0.1.1-rc.2 之后)的直播流:wrapper 把 agent/assistant-stream 帧转成
695
- // assistant.stream 通知(老运行时的持久 assistant/chunk 已不存在)。
696
605
  this.handleAssistantStream(params);
697
606
  }
698
607
  else if (method === "session.status") {
699
608
  this.handleSessionStatus(params);
700
609
  }
701
610
  else if (method === "question.pending") {
702
- // 模型 ask_user_question → 转发给浏览器对话框(deadline = 服务端超时时间戳)。
703
611
  const params0 = params;
704
- // 问卷开关(默认开):关 → 不弹框,立即取消让模型得知已禁用。
705
612
  if (this.settings.questionnaireEnabled === false) {
706
613
  void this.answerQuestion(params0.id, [], true);
707
614
  return;
@@ -726,9 +633,6 @@ export class DshClientSession {
726
633
  : {}),
727
634
  ...(q.multiSelect ? { multiSelect: true } : {}),
728
635
  }));
729
- // 记下待答问卷:`question_pending` 只推给「当时在线」的连接,刷新页面
730
- // /WS 重连后靠快照(UiState.pendingQuestion)把对话框恢复出来。
731
- // DSH 的提问桥是 runtime 级的(无 conversationId),故不分对话。
732
636
  const dshConv = this.convs.get(this.activeId);
733
637
  const conversationTitle = dshConv?.title;
734
638
  this.pendingQuestion = {
@@ -749,7 +653,6 @@ export class DshClientSession {
749
653
  this.flushSnapshot();
750
654
  }
751
655
  else if (method === "tools.call.request") {
752
- // 工具桥(#15):模型调了插件工具 → 服务端跑插件实现 → tools/call-result 回传。
753
656
  void this.handleToolCallRequest(params);
754
657
  }
755
658
  }
@@ -758,10 +661,6 @@ export class DshClientSession {
758
661
  }
759
662
  });
760
663
  }
761
- /** 快照侧的待答问卷(UiState.pendingQuestion):重连/刷新后靠它恢复对话框。
762
- * DSH 的提问自带超时(goal-rpc 到点 reject),deadline 已过的不再下发——
763
- * 否则已经没人等的问卷会被重连的客户端当成活的弹出来。标准引擎不限时,
764
- * 没有 deadline,生命周期由回答/取消/dispose 精确终止。 */
765
664
  pendingQuestionForSnapshot() {
766
665
  const p = this.pendingQuestion;
767
666
  if (!p)
@@ -770,10 +669,7 @@ export class DshClientSession {
770
669
  return null;
771
670
  return p;
772
671
  }
773
- /** 前端回答模型提问(question/answer → runtime 恢复工具结果)。 */
774
672
  async answerQuestion(id, answers, cancelled) {
775
- // 无论成功失败都清掉待答快照:同 id 不会再有下一次,留着会让重连的客户端
776
- // 恢复到一张已经没人在等的问卷。
777
673
  if (this.pendingQuestion?.id === id)
778
674
  this.pendingQuestion = null;
779
675
  this.flushSnapshot();
@@ -789,11 +685,6 @@ export class DshClientSession {
789
685
  });
790
686
  }
791
687
  }
792
- // -----------------------------------------------------------------------
793
- // 工具桥(#15 插件注入点):服务端把插件工具注册进运行时,并执行模型对
794
- // 桥接工具的调用(tools.call.request → 插件 execute → tools/call-result)。
795
- // -----------------------------------------------------------------------
796
- /** 桥接的插件工具最小形状(对齐 plugins.ts 的 PluginAgentTool,仅取桥接所需字段)。 */
797
688
  bridgedTool(t) {
798
689
  const tool = t;
799
690
  if (!tool ||
@@ -813,7 +704,6 @@ export class DshClientSession {
813
704
  mcpProjectCwds() {
814
705
  return [...new Set([this.cwd, ...[...this.convs.values()].map((conv) => conv.cwd)])];
815
706
  }
816
- /** 把当前插件工具(pluginToolsProvider)同步注册进运行时(幂等,可重复调用)。 */
817
707
  async syncPluginTools() {
818
708
  if (!this.runtime.alive)
819
709
  return;
@@ -835,13 +725,6 @@ export class DshClientSession {
835
725
  console.error(`[dsh] syncPluginTools 失败 (client=${this.clientId}):`, err);
836
726
  }
837
727
  }
838
- /**
839
- * 取一条工具的**定义说明**(工具卡右键 → 「显示工具详细信息」)→ `tool_info`。
840
- *
841
- * DSH 侧的定义来自运行时(`tools/list`:DSH 原生工具 + 桥接进来的插件工具)。
842
- * 拿不到(运行时没起来 / RPC 报错)回 `unsupported`,让前端说「当前引擎不支持」
843
- * 而不是「未找到工具定义」—— 后者会让用户以为工具名写错了。
844
- */
845
728
  async getToolInfo(name) {
846
729
  if (!this.runtime.alive) {
847
730
  this.emit({ type: "tool_info", ...unsupportedToolInfo(name) });
@@ -857,7 +740,6 @@ export class DshClientSession {
857
740
  this.emit({ type: "tool_info", ...unsupportedToolInfo(name) });
858
741
  }
859
742
  }
860
- /** 从运行时拉取技能清单 → 缓存 → 重推 settings_state(enabled 由 disabledSkills 推导)。 */
861
743
  async refreshSkillsFromRuntime() {
862
744
  if (!this.runtime.alive)
863
745
  return;
@@ -877,11 +759,8 @@ export class DshClientSession {
877
759
  try {
878
760
  this.pushSettings();
879
761
  }
880
- catch {
881
- /* best effort */
882
- }
762
+ catch { }
883
763
  }
884
- /** 把禁用技能集合同步给运行时(晚 pre-step 钩子据此过滤 skill-catalog 消息)。 */
885
764
  async pushDisabledSkillsToRuntime() {
886
765
  if (!this.runtime.alive)
887
766
  return;
@@ -892,7 +771,6 @@ export class DshClientSession {
892
771
  console.error(`[dsh] setDisabledSkills 失败 (client=${this.clientId}):`, err);
893
772
  }
894
773
  }
895
- /** 模型调用桥接工具:找插件 execute,归一化结果,tools/call-result 回传。 */
896
774
  async handleToolCallRequest(params) {
897
775
  const id = String(params?.id ?? "");
898
776
  const name = String(params?.name ?? "");
@@ -941,7 +819,6 @@ export class DshClientSession {
941
819
  nextConversationId() {
942
820
  return `c${++this.convSeq}-${randomUUID().slice(0, 8)}`;
943
821
  }
944
- /** 每个会话独立的目标状态(默认来自客户端级偏好)。 */
945
822
  makeGoalStatus() {
946
823
  return {
947
824
  conversationId: null,
@@ -956,15 +833,12 @@ export class DshClientSession {
956
833
  wizard: { active: false, draft: "", model: null, step: 0, maxSteps: 3, status: "" },
957
834
  };
958
835
  }
959
- /** 未命名对话的默认标题(issue #91:按客户端语言,英文默认)。 */
960
836
  defaultTitle() {
961
837
  return pick(this.getLang(), DEFAULT_CONV_TITLE, DEFAULT_CONV_TITLE_EN, "dsh.conv.default.title");
962
838
  }
963
- /** 是否仍是默认(未命名)标题——中英都认,跨语言切换不丢命名判断。 */
964
839
  static isDefaultTitle(title) {
965
840
  return title === DEFAULT_CONV_TITLE || title === DEFAULT_CONV_TITLE_EN;
966
841
  }
967
- /** 新建(或切换)一个 conversation。existing 的 sessionId 续聊最近 JSONL。 */
968
842
  addConversation(sessionId, cwd, replay = true, preset, sessionFilePath) {
969
843
  const id = this.nextConversationId();
970
844
  const conv = {
@@ -989,9 +863,7 @@ export class DshClientSession {
989
863
  lastEventAt: Date.now(),
990
864
  listed: false,
991
865
  promptedSinceActive: false,
992
- terminals: new TerminalManager((msg) => this.emit(msg), cwd,
993
- // issue #91:终端输入错误按客户端 UI 语言出中英(英文默认)。
994
- () => this.getLang()),
866
+ terminals: new TerminalManager((msg) => this.emit(msg), cwd, () => this.getLang()),
995
867
  toolStartTimes: new Map(),
996
868
  tokens: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
997
869
  usageSeen: false,
@@ -1000,7 +872,6 @@ export class DshClientSession {
1000
872
  streamTurn: 0,
1001
873
  };
1002
874
  if (replay) {
1003
- // 从磁盘 JSONL 回放历史消息(DSH 事件流不重放历史)。
1004
875
  try {
1005
876
  let targetFile = sessionFilePath && existsSync(sessionFilePath) ? sessionFilePath : null;
1006
877
  if (!targetFile) {
@@ -1015,26 +886,19 @@ export class DshClientSession {
1015
886
  for (const m of conv.messages)
1016
887
  conv.messageIds.add(m.id);
1017
888
  conv.title = firstUserText(events, this.getLang());
1018
- // 回放定预设:日志记录(selected 事件/header)> 调用方指定 > 默认。
1019
889
  const logged = sessionLogPreset({ header, events });
1020
890
  conv.agentPreset = this.resolvePreset(logged ?? preset);
1021
- // 权限预设同理:permission/preset 事件最后一条为准(无则 null,激活时拉取)。
1022
891
  conv.permissionPreset = sessionLogPermission({ header, events });
1023
- // 底栏统计:日志里最后一次 usage(新版在 assistant/message.usage,0.1.1 在
1024
- // assistant/chunk 的 usage chunk)→ 切回历史会话立刻有上下文 / 缓存命中数字。
1025
892
  const loggedUsage = lastUsageFromEvents(events);
1026
893
  if (loggedUsage) {
1027
894
  conv.tokens = loggedUsage;
1028
895
  conv.usageSeen = true;
1029
896
  }
1030
- // 有历史消息 = 已开始的会话,预设锁定(官方语义)。
1031
897
  if (conv.messages.length > 0)
1032
898
  conv.presetLocked = true;
1033
899
  }
1034
900
  }
1035
- catch {
1036
- /* best effort */
1037
- }
901
+ catch { }
1038
902
  }
1039
903
  this.convs.set(conv.id, conv);
1040
904
  return conv;
@@ -1042,9 +906,6 @@ export class DshClientSession {
1042
906
  get conv() {
1043
907
  return this.convs.get(this.activeId);
1044
908
  }
1045
- // -----------------------------------------------------------------------
1046
- // 事件管线
1047
- // -----------------------------------------------------------------------
1048
909
  findConv(sessionId) {
1049
910
  for (const conv of this.convs.values()) {
1050
911
  if (conv.sessionId === sessionId)
@@ -1055,17 +916,13 @@ export class DshClientSession {
1055
916
  handleSessionEvent(params) {
1056
917
  const conv = this.findConv(params.sessionId);
1057
918
  if (!conv)
1058
- return; // 非本客户端 conversation(并发其他客户端)→ 忽略
919
+ return;
1059
920
  conv.lastEventAt = Date.now();
1060
921
  const ev = params.event;
1061
922
  switch (ev.type) {
1062
923
  case "user/message": {
1063
- // DSH 会注入系统内部消息(workspace 指令 / 运行时上下文快照 / 目标轮次
1064
- // prompt)——前端不显示(pi 引擎的 asides 同理),只保留真正的用户消息。
1065
924
  const srcKind = ev.data.source?.kind;
1066
925
  if (srcKind === "goal") {
1067
- // 目标轮次承认:不渲染,但更新轮数显示(round 由 source.round 携带)。
1068
- // P1-10:轮次达上限且仍未完成 → 提示轮尽。
1069
926
  const round = ev.data.source?.round;
1070
927
  if (round && conv.goal.goal && conv.id === this.activeId) {
1071
928
  conv.goal.round = round;
@@ -1088,8 +945,6 @@ export class DshClientSession {
1088
945
  const cleanText = text
1089
946
  .replace(/\n\[(?:文件引用|File reference|上传文件|Uploaded file|图片附件|Image attachment):[\s\S]*$/u, "")
1090
947
  .trim();
1091
- // 1. 优先查找是否有暂存的本地乐观用户消息(u-pending- 开头)
1092
- // DSH 运行时回抛的消息往往带有 \n[File reference: ...] 附件说明,需要替换原乐观消息避免出现两条气泡
1093
948
  const pendingIdx = conv.messages.findIndex((m) => m.role === "user" && typeof m.id === "string" && m.id.startsWith("u-pending-"));
1094
949
  if (pendingIdx !== -1) {
1095
950
  const pendingMsg = conv.messages[pendingIdx];
@@ -1098,7 +953,6 @@ export class DshClientSession {
1098
953
  conv.messageIds.delete(pendingMsg.id);
1099
954
  conv.messageIds.add(msg.id);
1100
955
  conv.messages[pendingIdx] = msg;
1101
- // 图片附件异步补图处理
1102
956
  const imgRefs = (ev.data.content ?? [])
1103
957
  .filter((b) => b?.type === "image")
1104
958
  .map((b) => b.attachment)
@@ -1109,7 +963,6 @@ export class DshClientSession {
1109
963
  break;
1110
964
  }
1111
965
  }
1112
- // 2. 重复文本(DSH 有时重放同一用户消息)→ 去重。
1113
966
  if (cleanText &&
1114
967
  conv.messages.some((m) => {
1115
968
  if (m.role !== "user")
@@ -1120,8 +973,6 @@ export class DshClientSession {
1120
973
  break;
1121
974
  }
1122
975
  this.appendMessage(conv, msg);
1123
- // 图片附件异步补图:DSH 事件里的 image 块只有 ref 没有像素,回读后
1124
- // 填 dataUrl 供前端显示(回放/事件流的图片块在本地乐观消息中已显示过)。
1125
976
  const imgRefs = (ev.data.content ?? [])
1126
977
  .filter((b) => b?.type === "image")
1127
978
  .map((b) => b.attachment)
@@ -1143,7 +994,6 @@ export class DshClientSession {
1143
994
  case "assistant/message": {
1144
995
  const msg = assistantMessageEventToUiMessage(ev.data);
1145
996
  if (msg) {
1146
- // 完整消息落地 → streaming 清空(避免重复)。
1147
997
  conv.streaming = null;
1148
998
  this.appendMessage(conv, msg);
1149
999
  }
@@ -1151,7 +1001,6 @@ export class DshClientSession {
1151
1001
  if (rawText && rawText.includes("[[")) {
1152
1002
  void this.markerSvc.handleAssistantText(conv.id, rawText);
1153
1003
  }
1154
- // 新版运行时的 usage 挂在这条持久事件上(老运行时没有 → undefined 保持原统计)。
1155
1004
  this.applyUsage(conv, ev.data.usage);
1156
1005
  break;
1157
1006
  }
@@ -1162,7 +1011,6 @@ export class DshClientSession {
1162
1011
  const startedAt = conv.toolStartTimes.get(msg?.toolCallId ?? "");
1163
1012
  if (msg)
1164
1013
  conv.toolStartTimes.delete(msg.toolCallId ?? "");
1165
- // bash 工具结束 → 后台任务端口 diff。
1166
1014
  const toolName = ev.data.toolName;
1167
1015
  if (toolName === "bash")
1168
1016
  void this.bg.trackAfterBash();
@@ -1185,8 +1033,6 @@ export class DshClientSession {
1185
1033
  break;
1186
1034
  }
1187
1035
  case "assistant/chunk": {
1188
- // 老运行时(0.1.1-rc.2)的持久直播 chunk;新版运行时没有这个事件(改发
1189
- // agent/assistant-stream 直播帧)→ 过渡期两边都在时只认直播帧,避免喂两遍。
1190
1036
  if (conv.liveChunks)
1191
1037
  break;
1192
1038
  const chunk = ev.data?.chunk;
@@ -1206,22 +1052,16 @@ export class DshClientSession {
1206
1052
  break;
1207
1053
  }
1208
1054
  case "goal/change": {
1209
- // DSH 原生目标状态机事件(create/edit/resume/complete/block/clear),
1210
- // 全量快照 → 翻译成 GoalStatus 推前端。权威源在运行时,本地只镜像。
1211
1055
  this.applyGoalChange(conv, ev.data);
1212
1056
  break;
1213
1057
  }
1214
1058
  case "turn/end": {
1215
1059
  conv.streaming = null;
1216
- // DSH 无法恢复已持久化会话(id collision)——abort 重启运行时后
1217
- // 原会话也变 "磁盘有日志无 live"。检测到 error → 自动 fork + 重发。
1218
- // 目标轮次由 goal-round-driver 自动续,这里不需要审查钩子。
1219
1060
  const reason = ev.data?.reason ?? {};
1220
1061
  if (reason.kind === "error" && /id collision/i.test(reason.error?.message ?? "") && !conv.fromDisk) {
1221
1062
  this.forkAndReprompt(conv);
1222
1063
  }
1223
1064
  else if (conv.turnWaiter) {
1224
- // 调研向导等本轮结束(completed 正常 / error 中断)。
1225
1065
  const w = conv.turnWaiter;
1226
1066
  conv.turnWaiter = undefined;
1227
1067
  if (reason.kind === "completed")
@@ -1239,7 +1079,6 @@ export class DshClientSession {
1239
1079
  break;
1240
1080
  }
1241
1081
  case "agent/inbox/spliced": {
1242
- // 用户 prompt 注入 → 清理 followUp 队列中已消费的文本。
1243
1082
  const inserted = ev.data?.inserted ?? [];
1244
1083
  const texts = inserted.map((m) => m.content?.find((c) => c.type === "text")?.text ?? "").filter(Boolean);
1245
1084
  if (texts.length > 0) {
@@ -1254,7 +1093,6 @@ export class DshClientSession {
1254
1093
  default:
1255
1094
  break;
1256
1095
  }
1257
- // 事件驱动快照(60ms 节流;边界事件立即)。
1258
1096
  if (ev.type === "turn/end" ||
1259
1097
  ev.type === "tool/result" ||
1260
1098
  ev.type === "assistant/message" ||
@@ -1265,21 +1103,13 @@ export class DshClientSession {
1265
1103
  this.scheduleSnapshot();
1266
1104
  }
1267
1105
  }
1268
- /**
1269
- * 新版运行时的直播帧处理。运行时逐 chunk 发 `agent/assistant-stream`(agent scope,
1270
- * host 侧要 `{ global: true }` 才收得到),wrapper(goal-rpc.mjs)转成本通知:
1271
- * { type: "start" | "chunk" | "end", attemptId, revision, index, time, chunk }
1272
- * chunk 形状与老运行时的 `assistant/chunk.data.chunk` 同构 → 共用 applyStreamChunk。
1273
- */
1274
1106
  handleAssistantStream(params) {
1275
1107
  const conv = this.findConv(params.sessionId);
1276
1108
  const frame = params.frame;
1277
- // 别家客户端的会话 / 子代理会话(不在本客户端 convs 里)→ 忽略。
1278
1109
  if (!conv || !frame || typeof frame.type !== "string")
1279
1110
  return;
1280
1111
  conv.lastEventAt = Date.now();
1281
1112
  if (frame.type === "start") {
1282
- // 新 attempt(含重试)→ 换锚点,丢掉上一 attempt 的累计内容(与官方 dsh-web 一致)。
1283
1113
  conv.liveChunks = true;
1284
1114
  conv.streaming = null;
1285
1115
  conv.streamAnchor = typeof frame.time === "number" && Number.isFinite(frame.time) ? frame.time : Date.now();
@@ -1288,28 +1118,18 @@ export class DshClientSession {
1288
1118
  return;
1289
1119
  }
1290
1120
  if (frame.type !== "chunk")
1291
- return; // end:结算由 assistant/message / turn/end 清
1121
+ return;
1292
1122
  conv.liveChunks = true;
1293
1123
  const chunk = frame.chunk;
1294
1124
  if (!chunk)
1295
1125
  return;
1296
1126
  if (!conv.streamAnchor) {
1297
- // 没收到 start(重连晚到)→ 用首帧补锚点。
1298
1127
  conv.streamAnchor = typeof frame.time === "number" && Number.isFinite(frame.time) ? frame.time : Date.now();
1299
1128
  conv.streamTurn = typeof frame.turn === "number" ? frame.turn : 0;
1300
1129
  }
1301
1130
  this.applyStreamChunk(conv, chunk, conv.streamAnchor, conv.streamTurn);
1302
- // 60ms 节流快照:与持久事件那条路一样,让 isStreaming / streamingMessage 进快照
1303
- // (delta 通道只负责内容增量,靠它保证状态一致 + 背压时仍能收敛)。
1304
1131
  this.scheduleSnapshot();
1305
1132
  }
1306
- /**
1307
- * 一个 model stream chunk → 会话:usage 进底栏统计,其余进 streamingMessage 累计器 +
1308
- * 实时 delta 通道(message_delta)。两条投递路径(老 assistant/chunk / 新直播帧)共用。
1309
- *
1310
- * @param anchorId - streamingMessage id 的锚(老 = chunk 事件 seq;新版 = 首帧 time)。
1311
- * @param turn - 所属 turn(累计器 id 用)。
1312
- */
1313
1133
  applyStreamChunk(conv, chunk, anchorId, turn) {
1314
1134
  if (chunk.type === "usage") {
1315
1135
  this.applyUsage(conv, chunk.usage);
@@ -1318,9 +1138,6 @@ export class DshClientSession {
1318
1138
  if (!conv.streaming)
1319
1139
  conv.streaming = new DshStreamAccumulator(anchorId, turn);
1320
1140
  conv.streaming.apply(chunk);
1321
- // message_delta 实时通道:本机快速完成时 60ms 延迟快照总被 assistant/message 抢跑
1322
- // (streaming 从未被捕捉)→ delta 直接走独立通道,保证逐 token 渲染
1323
- // (前端 patch streamingMessage)。只推给当前对话,其他对话靠快照。
1324
1141
  if (conv.id === this.conv.id && (chunk.type === "text-delta" || chunk.type === "reasoning-delta")) {
1325
1142
  this.emit({
1326
1143
  type: "message_delta",
@@ -1336,7 +1153,6 @@ export class DshClientSession {
1336
1153
  });
1337
1154
  }
1338
1155
  }
1339
- /** usage → 底栏统计(最近一次模型调用口径;缺字段 / 非对象保持原值)。 */
1340
1156
  applyUsage(conv, usage) {
1341
1157
  const next = normalizeDshUsage(usage);
1342
1158
  if (!next)
@@ -1356,7 +1172,6 @@ export class DshClientSession {
1356
1172
  finishTurnTiming(conv);
1357
1173
  conv.lastEventAt = Date.now();
1358
1174
  if (was && !conv.isStreaming) {
1359
- // run 结束:清 streaming + 刷新会话列表。
1360
1175
  conv.streaming = null;
1361
1176
  this.refreshConversationTitle(conv);
1362
1177
  this.scheduleSessionsRefresh();
@@ -1373,7 +1188,6 @@ export class DshClientSession {
1373
1188
  refreshConversationTitle(conv) {
1374
1189
  if (!DshClientSession.isDefaultTitle(conv.title))
1375
1190
  return;
1376
- // 从消息列表取第一个用户文本。
1377
1191
  const t = conv.messages
1378
1192
  .find((m) => m.role === "user")
1379
1193
  ?.content?.map((c) => ("text" in c ? c.text : ""))
@@ -1384,10 +1198,6 @@ export class DshClientSession {
1384
1198
  this.emitConversations();
1385
1199
  }
1386
1200
  }
1387
- // -----------------------------------------------------------------------
1388
- // 快照
1389
- // -----------------------------------------------------------------------
1390
- /** 立即推送(节流 60ms 合并突发)。 */
1391
1201
  flushSnapshot(forceFull = false) {
1392
1202
  if (this.disposed)
1393
1203
  return;
@@ -1410,12 +1220,9 @@ export class DshClientSession {
1410
1220
  if (this.disposed)
1411
1221
  return;
1412
1222
  const conv = this.conv;
1413
- // 拷贝一份:appendMessage 直接 push conv.messages,若把引用存进
1414
- // emittedMessages,prev/cur 就是同一数组,slice(prev.length) 恒为空。
1415
1223
  const cur = [...conv.messages];
1416
1224
  const prev = this.emittedMessages;
1417
1225
  const rev = ++this.snapRev;
1418
- // 增量:同一 conversation 且纯 append 时发 snapshot_delta。
1419
1226
  let incremental = !forceFull && prev !== null && this.emittedRev > 0 && prev.length <= cur.length;
1420
1227
  if (incremental && prev) {
1421
1228
  for (let i = 0; i < prev.length; i++) {
@@ -1454,9 +1261,7 @@ export class DshClientSession {
1454
1261
  return files[0];
1455
1262
  }
1456
1263
  }
1457
- catch {
1458
- /* ignore */
1459
- }
1264
+ catch { }
1460
1265
  return undefined;
1461
1266
  }
1462
1267
  buildLightState(rev) {
@@ -1472,7 +1277,6 @@ export class DshClientSession {
1472
1277
  total: tokens.input + tokens.output + tokens.cacheRead + tokens.cacheWrite,
1473
1278
  },
1474
1279
  cost: estimateCost(tokens),
1475
- // 最近一次请求的 prompt + 输出(usageSeen=false → tokens=null,前端显示 `—`)。
1476
1280
  contextUsage: dshContextUsage(conv.usageSeen ? tokens : null, DSH_CONTEXT_WINDOW),
1477
1281
  };
1478
1282
  return {
@@ -1494,7 +1298,6 @@ export class DshClientSession {
1494
1298
  id: this.model,
1495
1299
  name: this.modelDisplayName || (DSH_MODELS.find((m) => m.id === this.model)?.name ?? this.model),
1496
1300
  provider: this.modelProvider || "deepseek",
1497
- // dsh-llm-deepseek adapter:仅 vision-exp 模型 inputModalities 含 image
1498
1301
  vision: this.modelVision,
1499
1302
  },
1500
1303
  thinkingLevel: this.thinkingLevel,
@@ -1508,7 +1311,6 @@ export class DshClientSession {
1508
1311
  tools: [],
1509
1312
  version: ++this.version,
1510
1313
  piConfigured: this.isDshConfigured(),
1511
- // DSH 不需要 pi CLI:报 true 让 PiSetupModal 跳过“安装 pi”步骤,直达填 key 表单。
1512
1314
  piAgentInstalled: true,
1513
1315
  stats,
1514
1316
  };
@@ -1516,9 +1318,6 @@ export class DshClientSession {
1516
1318
  getCapabilities() {
1517
1319
  return DEFAULT_DSH_CAPABILITIES;
1518
1320
  }
1519
- // -----------------------------------------------------------------------
1520
- // socket / 通知
1521
- // -----------------------------------------------------------------------
1522
1321
  attachSink(send) {
1523
1322
  this.sinks.add(send);
1524
1323
  for (const msg of this.pendingNotices)
@@ -1612,9 +1411,6 @@ export class DshClientSession {
1612
1411
  getTerminalCwd(conversationId) {
1613
1412
  return (conversationId ? this.convs.get(conversationId) : this.conv)?.cwd ?? this.cwd;
1614
1413
  }
1615
- // -----------------------------------------------------------------------
1616
- // 对话管理
1617
- // -----------------------------------------------------------------------
1618
1414
  activeConversations() {
1619
1415
  let n = 0;
1620
1416
  for (const conv of this.convs.values())
@@ -1625,18 +1421,15 @@ export class DshClientSession {
1625
1421
  pendingMessages() {
1626
1422
  return 0;
1627
1423
  }
1628
- /** issue #145:本实例连接的 socket 数(0 = 标签页全关了,会话残留)。 */
1629
1424
  sinkCount() {
1630
1425
  return this.sinks.size;
1631
1426
  }
1632
- /** issue #145:按 sessionId 找本实例持有的对话(跨客户端查重的本机一半)。 */
1633
1427
  findConversationBySessionId(sessionId) {
1634
1428
  for (const conv of this.convs.values())
1635
1429
  if (conv.sessionId === sessionId)
1636
1430
  return conv;
1637
1431
  return undefined;
1638
1432
  }
1639
- /** issue #145:本实例在某 cwd 下正在跑的对话摘要(同项目并行感知用)。 */
1640
1433
  streamingInCwd(cwd) {
1641
1434
  const out = [];
1642
1435
  for (const conv of this.convs.values()) {
@@ -1646,7 +1439,6 @@ export class DshClientSession {
1646
1439
  }
1647
1440
  return out;
1648
1441
  }
1649
- /** issue #145:本实例所有正在跑的对话摘要(elsewhere 列表的本机一半)。 */
1650
1442
  streamingSummariesAll() {
1651
1443
  const out = [];
1652
1444
  for (const conv of this.convs.values()) {
@@ -1656,23 +1448,17 @@ export class DshClientSession {
1656
1448
  }
1657
1449
  return out;
1658
1450
  }
1659
- /** issue #145:其他客户端重推 conversations 用(elsewhere 刷新)。 */
1660
1451
  refreshExternalRunning() {
1661
1452
  if (this.disposed)
1662
1453
  return;
1663
1454
  this.emitConversations();
1664
1455
  }
1665
- /** 左栏展示口径(issue #140,与 pi 引擎同义):listed 之外,当前对话只要有
1666
- * 内容(DSH 的对话消息全在内存里,直接数 messages)也在列表里;空白新对话
1667
- * 不入列。只影响展示,不动 listed 的语义。 */
1668
1456
  shownInRunningList(conv) {
1669
1457
  return conv.id === this.activeId && conv.messages.length > 0;
1670
1458
  }
1671
1459
  emitConversations() {
1672
1460
  const list = [];
1673
1461
  for (const conv of this.convs.values()) {
1674
- // 被置换到后台的会话 + 当前对话(一旦有内容就是用户正在聊的那条,
1675
- // 不该在列表里缺席——issue #140;空白新对话仍然不入列)。
1676
1462
  if (!conv.listed && !this.shownInRunningList(conv))
1677
1463
  continue;
1678
1464
  const sf = this.guessSessionFile(conv);
@@ -1689,12 +1475,10 @@ export class DshClientSession {
1689
1475
  isSubagent: false,
1690
1476
  pinned: isPinned,
1691
1477
  ...(conv.terminals.countUserBlockingLive() > 0 ? { hasUserTerminals: true } : {}),
1692
- // DSH Agent 预设(左栏徽标/详情用;pi 引擎不填)。
1693
1478
  agentPreset: conv.agentPreset,
1694
1479
  presetLocked: conv.presetLocked,
1695
1480
  });
1696
1481
  }
1697
- // issue #145:流式集合签名变化 → 通知其他客户端重推(左栏「另一处正在运行」近实时)
1698
1482
  const sig = JSON.stringify([...this.convs.values()]
1699
1483
  .filter((c) => c.isStreaming)
1700
1484
  .map((c) => c.id)
@@ -1708,7 +1492,6 @@ export class DshClientSession {
1708
1492
  type: "conversations",
1709
1493
  conversations: list,
1710
1494
  activeId: this.activeId,
1711
- // 为空时缺省(老快照字节一致)
1712
1495
  ...(elsewhere.length > 0 ? { elsewhere } : {}),
1713
1496
  });
1714
1497
  }
@@ -1723,9 +1506,6 @@ export class DshClientSession {
1723
1506
  return true;
1724
1507
  return false;
1725
1508
  }
1726
- /** 语义同 pi 引擎的 newChat:true = 当前活动对话是可接收首条的空白新对话
1727
- * (/new <prompt> 靠它决定要不要把首条提示发出去)。preset = 新会话预设
1728
- * (复用空白会话时等价一次空白切换)。 */
1729
1509
  async newChat(preset, _ephemeral, onReady) {
1730
1510
  if (this.switchingWorkspace)
1731
1511
  return false;
@@ -1766,7 +1546,6 @@ export class DshClientSession {
1766
1546
  });
1767
1547
  return false;
1768
1548
  }
1769
- // 旧对话保留(listed 生命周期简化:不主动移除)。
1770
1549
  const prevModel = this.model;
1771
1550
  active.listed = this.shouldRetainDshConversation(active);
1772
1551
  const conv = this.addConversation(`chat-${randomUUID().slice(0, 12)}`, this.cwd, false, preset);
@@ -1793,7 +1572,6 @@ export class DshClientSession {
1793
1572
  return;
1794
1573
  }
1795
1574
  const prev = this.conv;
1796
- // 只看“用过”的存活终端:没动过的空 shell 不钉住 listed(与 pi 的 displaceActive 同口径)。
1797
1575
  prev.listed = this.shouldRetainDshConversation(prev);
1798
1576
  this.activeId = id;
1799
1577
  this.emitConversations();
@@ -1801,7 +1579,6 @@ export class DshClientSession {
1801
1579
  this.pushTerminals();
1802
1580
  this.pushSettings();
1803
1581
  this.flushSnapshot(true);
1804
- // 切会话带上权限值(cwd 变化走运行时重启,onStarted 会重拉)。
1805
1582
  void this.refreshActivePermission().catch(() => { });
1806
1583
  }
1807
1584
  removeConversation(id) {
@@ -1811,9 +1588,6 @@ export class DshClientSession {
1811
1588
  this.convs.delete(id);
1812
1589
  conv.terminals.killAll();
1813
1590
  }
1814
- // -----------------------------------------------------------------------
1815
- // prompt / 附件
1816
- // -----------------------------------------------------------------------
1817
1591
  async prompt(text, attachments, queue = false) {
1818
1592
  if (this.switchingWorkspace)
1819
1593
  return;
@@ -1830,12 +1604,10 @@ export class DshClientSession {
1830
1604
  this.flushSnapshot();
1831
1605
  return;
1832
1606
  }
1833
- // 斜杠命令拦截(内置 NATIVE + 插件 registerCommand);带附件时不拦截。
1834
1607
  const parsed = parseSlash(text);
1835
1608
  if (parsed && !attachments?.length) {
1836
1609
  const handled = await this.execSlash(parsed.name, parsed.args);
1837
1610
  if (handled) {
1838
- // 与 pi 一致:命令执行后强制刷一次快照(notice/状态变化立即可见)。
1839
1611
  this.flushSnapshot();
1840
1612
  return;
1841
1613
  }
@@ -1843,7 +1615,6 @@ export class DshClientSession {
1843
1615
  if (this.conv !== conv || this.switchingWorkspace)
1844
1616
  return;
1845
1617
  this.markerSvc.clearActions(conv.id);
1846
- // issue #145:同文件守卫 —— 别处正在跑同一 sessionId 时拒绝发送(不造第二个 writer)。
1847
1618
  const fileOwner = this.findSessionOwnerById?.(conv.sessionId);
1848
1619
  if (fileOwner && fileOwner.isStreaming) {
1849
1620
  this.emit({
@@ -1855,9 +1626,6 @@ export class DshClientSession {
1855
1626
  this.flushSnapshot();
1856
1627
  return;
1857
1628
  }
1858
- // issue #145:同项目并行感知(与 pi 引擎同语义;DSH 无 display:false 的
1859
- // custom 消息通道,提醒以前置系统文本随本轮发给运行时,用户气泡保持原文)。
1860
- // parallelReminderEnabled=false 时整段跳过。
1861
1629
  let sysPrefix = "";
1862
1630
  if (!conv.isStreaming && this.settings.parallelReminderEnabled !== false) {
1863
1631
  const localTitles = [...this.convs.values()]
@@ -1889,7 +1657,6 @@ export class DshClientSession {
1889
1657
  }
1890
1658
  }
1891
1659
  }
1892
- // Restore persisted sessions without changing their conversation/session identity.
1893
1660
  if (conv.fromDisk) {
1894
1661
  const runtime = this.runtime;
1895
1662
  const sessionId = conv.sessionId;
@@ -1912,7 +1679,6 @@ export class DshClientSession {
1912
1679
  return;
1913
1680
  conv.fromDisk = false;
1914
1681
  }
1915
- // 命名对话(首个 prompt)。
1916
1682
  if (DshClientSession.isDefaultTitle(conv.title) && text.trim()) {
1917
1683
  const trimmed = text.trim().replace(/\s+/g, " ");
1918
1684
  conv.title = trimmed.length > 30 ? `${trimmed.slice(0, 30)}…` : trimmed;
@@ -1920,13 +1686,6 @@ export class DshClientSession {
1920
1686
  }
1921
1687
  await this.promptConv(conv, text, attachments, queue, sysPrefix);
1922
1688
  }
1923
- /**
1924
- * Remove ONE queued prompt (the ✕ on a pending bubble). DSH queues are
1925
- * display-only — the prompt was already handed to the runtime inbox, so this
1926
- * only drops the pending bubble from the UI (there is no per-item runtime
1927
- * cancel). `index` is the clicked bubble's position (duplicate texts need
1928
- * it); mismatch or omission falls back to first-occurrence text match.
1929
- */
1930
1689
  removeQueued(kind, text, index, _id) {
1931
1690
  const conv = this.conv;
1932
1691
  const arr = kind === "steer" ? conv.queue.steering : conv.queue.followUp;
@@ -1936,8 +1695,6 @@ export class DshClientSession {
1936
1695
  }
1937
1696
  this.flushSnapshot();
1938
1697
  }
1939
- /** 向指定会话发提示(审查注入/重发用;不处理 fromDisk fork 与命名)。 */
1940
- /** 排空期拒绝新工作(与 pi 引擎同文案;存量运行继续)。 */
1941
1698
  quiesceBlocked() {
1942
1699
  if (!this.isQuiesced?.())
1943
1700
  return false;
@@ -1950,7 +1707,6 @@ export class DshClientSession {
1950
1707
  this.flushSnapshot();
1951
1708
  return true;
1952
1709
  }
1953
- /** 回放补图:按 ref 读回图片字节 → 填入消息的 image 块 dataUrl(失败静默保持占位)。 */
1954
1710
  async hydrateImageBlocks(conv, msg, refs) {
1955
1711
  if (this.disposed)
1956
1712
  return;
@@ -1962,7 +1718,6 @@ export class DshClientSession {
1962
1718
  }
1963
1719
  if (this.disposed)
1964
1720
  return;
1965
- // 找到该消息(可能已被去重跳过/会话已切换),原地填块。
1966
1721
  const target = conv.messages.find((m) => m.id === msg.id);
1967
1722
  if (!target)
1968
1723
  return;
@@ -1975,13 +1730,9 @@ export class DshClientSession {
1975
1730
  if (i > 0)
1976
1731
  this.flushSnapshot();
1977
1732
  }
1978
- catch {
1979
- /* 补图失败保持占位 */
1980
- }
1733
+ catch { }
1981
1734
  }
1982
- async promptConv(conv, text, attachments, _queue = false,
1983
- // issue #145 同项目并行提醒:只进运行时上下文,不进用户气泡。
1984
- sysPrefix = "") {
1735
+ async promptConv(conv, text, attachments, _queue = false, sysPrefix = "") {
1985
1736
  if (this.switchingWorkspace)
1986
1737
  return;
1987
1738
  const generation = this.workspaceGeneration;
@@ -1994,20 +1745,15 @@ export class DshClientSession {
1994
1745
  startTurnTiming(conv);
1995
1746
  conv.promptedSinceActive = true;
1996
1747
  conv.lastEventAt = Date.now();
1997
- // Agent 预设:运行时世代过期 → 重登 preset/assign(创建时消费;
1998
- // 已存在会话的登记永不消费,重启后新运行时建会话时正好用上)。
1999
1748
  if (conv.assignedGen !== this.runtimeGen) {
2000
1749
  try {
2001
1750
  await this.runtime.assignPreset(conv.sessionId, conv.agentPreset);
2002
1751
  conv.assignedGen = this.runtimeGen;
2003
1752
  }
2004
- catch {
2005
- /* legacy/运行时未就绪:创建走默认;best effort */
2006
- }
1753
+ catch { }
2007
1754
  }
2008
1755
  if (this.switchingWorkspace || generation !== this.workspaceGeneration)
2009
1756
  return;
2010
- // 新会话默认权限预设(与当前一致时 apply 无事件零噪音)。
2011
1757
  await this.ensurePermissionDefault(conv);
2012
1758
  if (this.switchingWorkspace || generation !== this.workspaceGeneration)
2013
1759
  return;
@@ -2027,7 +1773,6 @@ export class DshClientSession {
2027
1773
  const blocks = await this.buildContentBlocks(sysPrefix ? `${sysPrefix}${promptText}` : promptText, effectiveAttachments);
2028
1774
  if (this.switchingWorkspace || generation !== this.workspaceGeneration || conv.cwd !== this.cwd)
2029
1775
  return;
2030
- // 乐观落地用户消息(id 用暂定值;user/message 事件到达时按内容去重)。
2031
1776
  const optimistic = {
2032
1777
  id: `u-pending-${Date.now()}-${conv.deltaSeq++}`,
2033
1778
  role: "user",
@@ -2048,8 +1793,6 @@ export class DshClientSession {
2048
1793
  optimisticId = optimistic.id;
2049
1794
  this.appendMessage(conv, optimistic);
2050
1795
  if (conv.isStreaming) {
2051
- // DSH 无 mid-run steering:isStreaming 时入队(followUp),
2052
- // 运行时 inbox 在 run 结束后消费。入队后立即 flushSnapshot 让排队气泡上屏。
2053
1796
  conv.queue.followUp.push(text);
2054
1797
  followUpAdded = true;
2055
1798
  this.flushSnapshot();
@@ -2063,7 +1806,6 @@ export class DshClientSession {
2063
1806
  this.flushSnapshot();
2064
1807
  await this.runtime.prompt(conv.sessionId, blocks);
2065
1808
  }
2066
- // 首轮用户发言送达 → 预设锁定(官方语义;回放会话建时已锁)。
2067
1809
  if (!conv.presetLocked) {
2068
1810
  conv.presetLocked = true;
2069
1811
  this.emitConversations();
@@ -2072,7 +1814,6 @@ export class DshClientSession {
2072
1814
  catch (err) {
2073
1815
  if (!conv.isStreaming)
2074
1816
  finishTurnTiming(conv);
2075
- // 发送失败事务补偿:回滚乐观用户消息与排队气泡
2076
1817
  if (optimisticId) {
2077
1818
  const optIdx = conv.messages.findIndex((m) => m.id === optimisticId);
2078
1819
  if (optIdx !== -1) {
@@ -2094,7 +1835,6 @@ export class DshClientSession {
2094
1835
  }
2095
1836
  this.flushSnapshot();
2096
1837
  }
2097
- /** 会话历史 → 上下文文本(fork 时注入)。 */
2098
1838
  histToContext(conv) {
2099
1839
  return conv.messages
2100
1840
  .map((m) => {
@@ -2104,15 +1844,12 @@ export class DshClientSession {
2104
1844
  .filter(Boolean)
2105
1845
  .join("\n");
2106
1846
  }
2107
- /** 新建 fork 会话并切换到它(DSH 无法原地续聊旧会话)。 */
2108
1847
  forkConversation(prev) {
2109
1848
  const fork = this.addConversation(`fork-${randomUUID().slice(0, 12)}`, this.cwd, false, prev.agentPreset);
2110
1849
  fork.title = prev.title;
2111
- // 继承原会话的所有消息历史,使得 UI 界面上完整保留所有轮次的历史消息
2112
1850
  fork.messages = [...prev.messages];
2113
1851
  fork.messageIds = new Set(prev.messageIds);
2114
1852
  this.activeId = fork.id;
2115
- // P2-19:原会话有 active goal(DSH same-session 语义)→ 提示随会话存档。
2116
1853
  const hadGoal = prev.goal.goal !== null && prev.goal.verdict === "pending";
2117
1854
  this.emitConversations();
2118
1855
  this.emit({
@@ -2127,11 +1864,9 @@ export class DshClientSession {
2127
1864
  });
2128
1865
  return fork;
2129
1866
  }
2130
- /** turn/end 报 id collision(abort 重启运行时后会话不再 live)→ fork + 重发最后提问。 */
2131
1867
  forkAndReprompt(conv) {
2132
1868
  if (this.disposed)
2133
1869
  return;
2134
- // 找最后一条用户消息作为重发文本。
2135
1870
  let lastUser = "";
2136
1871
  for (let i = conv.messages.length - 1; i >= 0; i--) {
2137
1872
  const m = conv.messages[i];
@@ -2157,8 +1892,6 @@ export class DshClientSession {
2157
1892
  });
2158
1893
  void this.prompt(text);
2159
1894
  }
2160
- /** 附件 → DSH contentBlocks(v1 简化:文本内联 / 路径引用 / 图片占位)。 */
2161
- /** dataUrl(data:image/png;base64,XXX)→ {mediaType, base64};无前缀按 PNG 处理。 */
2162
1895
  static splitImageDataUrl(data) {
2163
1896
  const m = /^data:([^;,]+);base64,([\s\S]*)$/u.exec(data);
2164
1897
  if (m && m[2])
@@ -2190,7 +1923,6 @@ export class DshClientSession {
2190
1923
  }
2191
1924
  const resolved = a.path ? workspacePath(this.cwd, a.path) : null;
2192
1925
  if (a.imageData) {
2193
- // 视觉桥:base64 图片 → attachment store → 真 image 块(模型可看图)。
2194
1926
  try {
2195
1927
  const { mediaType, base64 } = DshClientSession.splitImageDataUrl(a.imageData);
2196
1928
  const saved = await this.runtime.attachmentSave(mediaType, base64, a.name);
@@ -2204,7 +1936,6 @@ export class DshClientSession {
2204
1936
  }
2205
1937
  }
2206
1938
  else if (a.fileData) {
2207
- // 上传文件 → 落盘 + 路径引用。
2208
1939
  try {
2209
1940
  const maxBytes = (this.stateStore.getSettingsSnapshot(this.clientId).chatUploadMaxMb ?? 20) * 1024 * 1024;
2210
1941
  if (a.fileData.length > Math.ceil(maxBytes / 3) * 4)
@@ -2226,9 +1957,6 @@ export class DshClientSession {
2226
1957
  }
2227
1958
  }
2228
1959
  else if (resolved) {
2229
- // 一律只给路径引用:不再把文件内容注入 prompt(小文件也一样),模型用
2230
- // 自己的读取工具按需读。行范围模式带上行号提示。
2231
- // 工作区图片文件仍走 attachment store → 真 image 块(模型可看图)。
2232
1960
  const refText = pick(lang, `\n[文件引用: ${resolved.rel}]`, `\n[File reference: ${resolved.rel}]`, "dsh.attach.file.ref", {
2233
1961
  "resolved.rel": resolved.rel,
2234
1962
  }) +
@@ -2240,9 +1968,7 @@ export class DshClientSession {
2240
1968
  const st = statSync(resolved.abs);
2241
1969
  isImage = st.isFile() && st.size > 0 && st.size <= 512 * 1024 && previewKind(resolved.abs) === "image";
2242
1970
  }
2243
- catch {
2244
- /* 不存在/不可读 → 照样给路径引用,读取工具会自己报错 */
2245
- }
1971
+ catch { }
2246
1972
  if (isImage) {
2247
1973
  try {
2248
1974
  const buf = readFileSync(resolved.abs);
@@ -2277,7 +2003,6 @@ export class DshClientSession {
2277
2003
  }
2278
2004
  return blocks;
2279
2005
  }
2280
- /** 中止:kill 运行时进程树(所有 conversation 的运行停止)→ 自动重启保持可用。 */
2281
2006
  async abort() {
2282
2007
  this.cancelBridgedTools();
2283
2008
  if (!this.runtime.alive)
@@ -2287,15 +2012,11 @@ export class DshClientSession {
2287
2012
  conv.isStreaming = false;
2288
2013
  conv.streaming = null;
2289
2014
  this.emitConversations();
2290
- // 手动停止 → 清当前会话的 DSH 原生目标(半成品运行不该继续被轮次驱动)。
2291
- // 旧进程还活着,先 goal/clear 落盘,再重启运行时。
2292
2015
  if (conv.dsGoal || conv.goal.goal) {
2293
2016
  try {
2294
2017
  await this.runtime.goalClear(conv.sessionId);
2295
2018
  }
2296
- catch {
2297
- /* 进程可能已死,事件兜底 */
2298
- }
2019
+ catch { }
2299
2020
  conv.dsGoal = null;
2300
2021
  conv.goal.goal = null;
2301
2022
  conv.goal.conversationId = null;
@@ -2326,7 +2047,6 @@ export class DshClientSession {
2326
2047
  this.flushSnapshot(true);
2327
2048
  }
2328
2049
  async abortBash() {
2329
- // DSH 无 per-tool 取消;bash 工具由运行时管理,超时策略在运行时侧。
2330
2050
  this.emit({
2331
2051
  type: "notice",
2332
2052
  level: "info",
@@ -2334,9 +2054,6 @@ export class DshClientSession {
2334
2054
  textEn: "The DSH engine cannot stop bash alone (stop the whole conversation instead)",
2335
2055
  });
2336
2056
  }
2337
- /** 手动重试上次失败的模型调用:找到最后一条用户提问并重发一次
2338
- * (DSH 运行时以 prompt 驱动回合,无 triggerTurn 语义)。流式中 /
2339
- * 无可重试失败时只发 notice 拒绝。 */
2340
2057
  async retryLast() {
2341
2058
  const conv = this.conv;
2342
2059
  try {
@@ -2393,9 +2110,6 @@ export class DshClientSession {
2393
2110
  }
2394
2111
  this.flushSnapshot();
2395
2112
  }
2396
- // -----------------------------------------------------------------------
2397
- // 后台任务
2398
- // -----------------------------------------------------------------------
2399
2113
  async listBgServers() {
2400
2114
  await this.bg.listAndPush();
2401
2115
  }
@@ -2421,11 +2135,9 @@ export class DshClientSession {
2421
2135
  this.bg.push();
2422
2136
  return killed;
2423
2137
  }
2424
- /** 钉住 / 取消钉住(DSH 引擎同样有后台任务面板,行为与 pi 引擎一致)。 */
2425
2138
  setBackgroundKeep(port, keep) {
2426
2139
  return this.bg.setKeep(port, keep);
2427
2140
  }
2428
- /** 手动「立即清理」(阈值策略与 pi 引擎同源:设置里的 bgAutoCleanupMin,关时兼底 30 分钟)。 */
2429
2141
  async cleanBackgroundLeftovers(minutesOverride) {
2430
2142
  const override = Number(minutesOverride);
2431
2143
  const policy = Number(this.settings.bgAutoCleanupMin ?? 0);
@@ -2433,9 +2145,6 @@ export class DshClientSession {
2433
2145
  const thresholdMs = (minutes > 0 ? minutes : BG_CLEANUP_FALLBACK_MIN) * 60_000;
2434
2146
  return this.bg.cleanStale(thresholdMs, { manual: true });
2435
2147
  }
2436
- // -----------------------------------------------------------------------
2437
- // 会话列表 / 切换 / 删除
2438
- // -----------------------------------------------------------------------
2439
2148
  sessionsTimer = null;
2440
2149
  scheduleSessionsRefresh() {
2441
2150
  if (this.sessionsTimer)
@@ -2453,22 +2162,17 @@ export class DshClientSession {
2453
2162
  }
2454
2163
  async pushSessions() {
2455
2164
  try {
2456
- // 目录/会话文件被删除、改名或不可读都不许把异常抛出去:本方法以
2457
- // fire-and-forget(void …)方式调用,未处理的 rejection 会杀死服务进程
2458
- // (issue #74 同类)。失败降级为空列表,面板显示“暂无历史”。
2459
2165
  const files = findSessionFilesForCwd(this.sessionRoot, this.cwd);
2460
2166
  const summaries = [];
2461
2167
  for (const file of files) {
2462
2168
  try {
2463
2169
  const sessionId = basename(dirname(file));
2464
- // 审查会话(review-*)是内部工作会话,不进历史列表。
2465
2170
  if (sessionId.startsWith("review-"))
2466
2171
  continue;
2467
2172
  const { events } = readSessionLog(file);
2468
2173
  const count = events.filter((e) => (e.type === "user/message" && !isDshInternalUserMessage(e.data)) ||
2469
2174
  e.type === "assistant/message" ||
2470
2175
  e.type === "tool/result").length;
2471
- // 过滤无消息空会话(仅有初始化 preset 事件的空壳不展示在历史列表)
2472
2176
  if (count === 0)
2473
2177
  continue;
2474
2178
  const isPinned = Boolean(this.stateStore?.isSessionPinned(this.cwd, file) || this.stateStore?.isSessionPinned(this.cwd, sessionId));
@@ -2482,6 +2186,7 @@ export class DshClientSession {
2482
2186
  summaries.push({
2483
2187
  path: file,
2484
2188
  sessionId,
2189
+ cwd: this.cwd,
2485
2190
  name: explicitTitle,
2486
2191
  displayName,
2487
2192
  firstMessage: firstMsg,
@@ -2491,9 +2196,7 @@ export class DshClientSession {
2491
2196
  pinned: isPinned,
2492
2197
  });
2493
2198
  }
2494
- catch {
2495
- /* skip unreadable */
2496
- }
2199
+ catch { }
2497
2200
  }
2498
2201
  this.emit({ type: "sessions", sessions: summaries });
2499
2202
  }
@@ -2501,7 +2204,6 @@ export class DshClientSession {
2501
2204
  this.emit({ type: "sessions", sessions: [] });
2502
2205
  }
2503
2206
  }
2504
- /** 引擎自属的会话展示名解析回调(定制 DSH 的首条提取 + 模型自动总结命名 + 用户显式重命名记忆) */
2505
2207
  resolveSessionDisplayName(sessionId, explicitTitle, firstMsg) {
2506
2208
  const storedTitle = this.stateStore?.getSessionTitle(this.cwd, sessionId);
2507
2209
  if (storedTitle && !DshClientSession.isDefaultTitle(storedTitle)) {
@@ -2634,8 +2336,6 @@ export class DshClientSession {
2634
2336
  }
2635
2337
  }
2636
2338
  async dismissConversation(id, _withFinishedSubagents, force) {
2637
- // DSH 引擎无第一方子代理:withFinishedSubagents 恒为 no-op(签名与标准引擎对齐)。
2638
- // force 放行 active/终端限制;运行中仍拒绝(DSH 单 runtime 无法单独 abort 一个对话,请先点停止)。
2639
2339
  const conv = this.convs.get(id);
2640
2340
  if (!conv) {
2641
2341
  this.emit({
@@ -2668,7 +2368,6 @@ export class DshClientSession {
2668
2368
  });
2669
2369
  return;
2670
2370
  }
2671
- // issue #181:只看用户终端——AI bash 随对话一起释放,不得阻断移出。
2672
2371
  if (conv.terminals.countUserBlockingLive() > 0 && !force) {
2673
2372
  this.emit({
2674
2373
  type: "notice",
@@ -2678,8 +2377,6 @@ export class DshClientSession {
2678
2377
  });
2679
2378
  return;
2680
2379
  }
2681
- // 没动过的空 shell与 AI bash 不拦截:随对话一起释放。
2682
- // force + active:先让出 active(切到其他对话或新建),再移除。
2683
2380
  if (id === this.activeId) {
2684
2381
  const other = [...this.convs.values()].find((c) => c.id !== id);
2685
2382
  if (other)
@@ -2700,8 +2397,6 @@ export class DshClientSession {
2700
2397
  this.emitConversations();
2701
2398
  this.flushSnapshot();
2702
2399
  }
2703
- /** DSH 引擎无第一方子代理(emitConversations 恒 isSubagent:false):批量
2704
- * 关闭退化为空操作提示,保持与 pi 引擎同一 wire 行为。 */
2705
2400
  async dismissFinishedSubagents(_parentId) {
2706
2401
  this.emit({
2707
2402
  type: "notice",
@@ -2710,14 +2405,12 @@ export class DshClientSession {
2710
2405
  textEn: "No finished subagents to dismiss",
2711
2406
  });
2712
2407
  }
2713
- /** 切换会话:读 JSONL 回放 → 新建 conversation(同一 sessionId 续聊)。 */
2714
2408
  async switchSession(path, wantSessionId) {
2715
2409
  assertEngineWorkspaceSupported(this.sandboxes, this.cwd, "dsh");
2716
2410
  try {
2717
2411
  const resolvedPath = path.trim() ? resolve(path.trim()) : "";
2718
2412
  const explicitSid = wantSessionId?.trim() ?? "";
2719
2413
  const sessionId = explicitSid || (resolvedPath ? basename(dirname(resolvedPath)) : "");
2720
- // 同一 sessionId 已在运行 → 直接切过去。
2721
2414
  for (const conv of this.convs.values()) {
2722
2415
  if (conv.sessionId === sessionId || conv.id === sessionId) {
2723
2416
  await this.switchConversation(conv.id);
@@ -2746,7 +2439,6 @@ export class DshClientSession {
2746
2439
  return;
2747
2440
  }
2748
2441
  }
2749
- // issue #145:同 pi 引擎 —— 别处正在跑同一 sessionId 时不建第二个持有者。
2750
2442
  const owner = this.findSessionOwnerById?.(sessionId);
2751
2443
  if (owner && owner.isStreaming) {
2752
2444
  this.emit({
@@ -2759,7 +2451,6 @@ export class DshClientSession {
2759
2451
  return;
2760
2452
  }
2761
2453
  if (owner) {
2762
- // 对端已断开(标签页关了)只剩残留会话 —— 不打扰,直接开。
2763
2454
  if (owner.connected) {
2764
2455
  this.emit({
2765
2456
  type: "notice",
@@ -2770,10 +2461,9 @@ export class DshClientSession {
2770
2461
  }
2771
2462
  }
2772
2463
  const prev = this.conv;
2773
- // 只看“用过”的存活终端:没动过的空 shell 不钉住 listed(与 pi 的 displaceActive 同口径)。
2774
2464
  prev.listed = this.shouldRetainDshConversation(prev);
2775
2465
  const conv = this.addConversation(sessionId, this.cwd, true, undefined, resolvedPath || undefined);
2776
- conv.fromDisk = true; // 磁盘回放 → prompt 时 fork
2466
+ conv.fromDisk = true;
2777
2467
  if (resolvedPath)
2778
2468
  conv.sessionFile = resolvedPath;
2779
2469
  this.activeId = conv.id;
@@ -2809,14 +2499,9 @@ export class DshClientSession {
2809
2499
  });
2810
2500
  }
2811
2501
  }
2812
- // -----------------------------------------------------------------------
2813
- // 用户 patch 扩展缝(<dataDir>/dsh-patches/*.yml)
2814
- // -----------------------------------------------------------------------
2815
- /** 用户 patch 目录。 */
2816
2502
  userPatchDir() {
2817
2503
  return join(this.dataDir, "dsh-patches");
2818
2504
  }
2819
- /** 列出 <dataDir>/dsh-patches/*.yml 以及 *.yml.disabled(按文件名序),带文件信息与启停状态。 */
2820
2505
  async listDshPatches() {
2821
2506
  const dir = this.userPatchDir();
2822
2507
  const files = [];
@@ -2841,18 +2526,13 @@ export class DshClientSession {
2841
2526
  });
2842
2527
  }
2843
2528
  }
2844
- catch {
2845
- /* skip unreadable */
2846
- }
2529
+ catch { }
2847
2530
  }
2848
2531
  }
2849
- catch {
2850
- /* 目录不存在 = 无用户 patch */
2851
- }
2532
+ catch { }
2852
2533
  files.sort((a, b) => a.name.localeCompare(b.name));
2853
2534
  this.emit({ type: "dsh_patches", patchDir: dir, files });
2854
2535
  }
2855
- /** 重扫用户 patch:重启运行时使新 patch 生效(patch 只在 boot 时加载)。 */
2856
2536
  async rescanDshPatches() {
2857
2537
  try {
2858
2538
  if (this.runtime.alive) {
@@ -2875,7 +2555,6 @@ export class DshClientSession {
2875
2555
  }
2876
2556
  await this.listDshPatches();
2877
2557
  }
2878
- /** 安装/添加 DSH 用户 patch(写入 <dataDir>/dsh-patches/<id>.yml 并重载运行时)。 */
2879
2558
  async installDshPatch(rawSpec, rawId) {
2880
2559
  const spec = rawSpec.trim().replace(/^['"]|['"]$/g, "");
2881
2560
  if (!spec) {
@@ -2887,7 +2566,6 @@ export class DshClientSession {
2887
2566
  });
2888
2567
  return;
2889
2568
  }
2890
- // 推导合法 id(仅允许字母数字横线下划线)
2891
2569
  let id = (rawId ?? "").trim();
2892
2570
  if (!id) {
2893
2571
  const base = basename(spec.replace(/[\\/]+$/, ""));
@@ -2896,7 +2574,6 @@ export class DshClientSession {
2896
2574
  id = id.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || `patch-${Date.now().toString(36)}`;
2897
2575
  const dir = this.userPatchDir();
2898
2576
  mkdirSync(dir, { recursive: true });
2899
- // 规范化包名/路径:Windows 路径转为正斜杠以确保 YAML 兼容性
2900
2577
  const normalizedSpec = spec.replace(/\\/g, "/");
2901
2578
  const escapedName = normalizedSpec.replace(/'/g, "''");
2902
2579
  const yamlContent = `# DSH user patch generated by pi-web-ui\n- insert:\n - id: ${id}\n name: '${escapedName}'\n config: {}\n`;
@@ -2925,7 +2602,6 @@ export class DshClientSession {
2925
2602
  }
2926
2603
  await this.rescanDshPatches();
2927
2604
  }
2928
- /** 切换 DSH 用户 patch 启用/停用状态(重命名为 *.yml.disabled 或 *.yml)。 */
2929
2605
  async toggleDshPatch(name, enabled) {
2930
2606
  const safeName = basename(name);
2931
2607
  if (!safeName || safeName !== name) {
@@ -2957,7 +2633,6 @@ export class DshClientSession {
2957
2633
  }
2958
2634
  await this.rescanDshPatches();
2959
2635
  }
2960
- /** 删除指定的 DSH 用户 patch 文件并重启运行时。 */
2961
2636
  async deleteDshPatch(name) {
2962
2637
  const safeName = basename(name);
2963
2638
  if (!safeName || safeName !== name) {
@@ -2989,7 +2664,6 @@ export class DshClientSession {
2989
2664
  }
2990
2665
  await this.rescanDshPatches();
2991
2666
  }
2992
- /** 拉取 DSH 插件市场数据并推送给客户端。 */
2993
2667
  async fetchDshMarket(force = false) {
2994
2668
  try {
2995
2669
  const data = await loadDshMarketData(this.dataDir, force);
@@ -3010,9 +2684,6 @@ export class DshClientSession {
3010
2684
  });
3011
2685
  }
3012
2686
  }
3013
- // -----------------------------------------------------------------------
3014
- // 项目 / 文件 / SCM / 搜索
3015
- // -----------------------------------------------------------------------
3016
2687
  async pushProjects() {
3017
2688
  const recent = await this.stateStore.getRecentProjects(this.clientId);
3018
2689
  const removedKeys = new Set(this.stateStore.getRemovedProjects(this.clientId).map(normalizePathKey));
@@ -3022,7 +2693,6 @@ export class DshClientSession {
3022
2693
  projects.set(p.path, p.lastUsed);
3023
2694
  }
3024
2695
  }
3025
- // 合并当前会话目录发现的项目。
3026
2696
  const cwdProjects = new Set();
3027
2697
  try {
3028
2698
  const { readdirSync } = await import("node:fs");
@@ -3035,9 +2705,7 @@ export class DshClientSession {
3035
2705
  }
3036
2706
  }
3037
2707
  }
3038
- catch {
3039
- /* best effort */
3040
- }
2708
+ catch { }
3041
2709
  for (const cwd of cwdProjects)
3042
2710
  projects.set(cwd, Date.now());
3043
2711
  if (!removedKeys.has(normalizePathKey(this.cwd))) {
@@ -3060,11 +2728,10 @@ export class DshClientSession {
3060
2728
  return sbx ? { path, lastUsed, sandbox: sbx } : { path, lastUsed };
3061
2729
  })
3062
2730
  .sort((a, b) => b.lastUsed - a.lastUsed)
3063
- .slice(0, 30);
2731
+ .slice(0, RECENT_PROJECTS_MAX);
3064
2732
  this.emit({ type: "projects", projects: list });
3065
2733
  }
3066
2734
  decodeProjectKey(key) {
3067
- // --<cwd>-- → 反解(尽力)。
3068
2735
  if (!key.startsWith("--") || !key.endsWith("--"))
3069
2736
  return null;
3070
2737
  const inner = key.slice(2, -2);
@@ -3259,8 +2926,6 @@ export class DshClientSession {
3259
2926
  }
3260
2927
  await this.setCwd(fallbackCwd);
3261
2928
  }
3262
- // 清理仍挂在该沙盒下的后台会话(含子目录 cwd)——ClientSession 版有此步,
3263
- // DSH 版此前完全没有:销毁后这些对话的 runtime/终端指向已删目录
3264
2929
  for (const [id, conv] of this.convs) {
3265
2930
  if (id !== this.activeId && isSameOrSubpath(conv.cwd, sbx.path)) {
3266
2931
  this.removeConversation(id);
@@ -3309,7 +2974,6 @@ export class DshClientSession {
3309
2974
  const texts = [];
3310
2975
  const anchors = [];
3311
2976
  for (const ev of events) {
3312
- // P1-14:索引范围 = user/assistant 文本 + tool-result 工具输出。
3313
2977
  if (ev.type === "user/message" || ev.type === "assistant/message" || ev.type === "tool/result") {
3314
2978
  if (ev.type === "user/message" && isDshInternalUserMessage(ev.data))
3315
2979
  continue;
@@ -3318,7 +2982,6 @@ export class DshClientSession {
3318
2982
  [];
3319
2983
  let text = blocks.map((b) => (b?.type === "text" ? (b.text ?? "") : "")).join("\n");
3320
2984
  if (ev.type === "tool/result") {
3321
- // 工具输出在嵌套 content[](tool-result 块内),一并纳入索引。
3322
2985
  const nested = blocks
3323
2986
  .filter((b) => b?.type === "tool-result")
3324
2987
  .flatMap((b) => b.content ?? [])
@@ -3339,7 +3002,6 @@ export class DshClientSession {
3339
3002
  }
3340
3003
  const all = texts.join("\n").toLowerCase();
3341
3004
  const sessionId = basename(dirname(file));
3342
- // 审查会话不进搜索。
3343
3005
  if (sessionId.startsWith("review-"))
3344
3006
  continue;
3345
3007
  const firstMsg = firstUserText(events, this.getLang());
@@ -3363,9 +3025,7 @@ export class DshClientSession {
3363
3025
  });
3364
3026
  }
3365
3027
  }
3366
- catch {
3367
- /* skip unreadable */
3368
- }
3028
+ catch { }
3369
3029
  }
3370
3030
  results.sort((a, b) => b.modified - a.modified);
3371
3031
  this.emit({ type: "session_search_results", reqId, query, ok: true, results: results.slice(0, 50) });
@@ -3375,8 +3035,6 @@ export class DshClientSession {
3375
3035
  }
3376
3036
  }
3377
3037
  async scmQuery(kind, reqId, opts) {
3378
- // 走 FilesService:只读 git 查询 + git-dir watcher(外部提交 → scm_changed
3379
- // 面板自动刷新)+ 越界/notRepo 统一处理。
3380
3038
  await this.files.scmQuery(kind, reqId, opts);
3381
3039
  }
3382
3040
  async readFile(relPath) {
@@ -3388,7 +3046,6 @@ export class DshClientSession {
3388
3046
  async uploadFile(dirRel, name, data, uploadId) {
3389
3047
  await this.files.uploadFile(dirRel, name, data, uploadId);
3390
3048
  }
3391
- /** 文件树右键菜单:新建/重命名/删除/复制移动(FilesService 直透传)。 */
3392
3049
  async createEntry(dir, name, kind) {
3393
3050
  await this.files.createEntry(dir, name, kind);
3394
3051
  }
@@ -3401,7 +3058,6 @@ export class DshClientSession {
3401
3058
  async copyEntry(src, destDir, move) {
3402
3059
  await this.files.copyEntry(src, destDir, move);
3403
3060
  }
3404
- /** 文件树右键菜单:在资源管理器中定位 / 默认应用打开(issue #187)。 */
3405
3061
  async revealEntry(path) {
3406
3062
  await this.files.revealEntry(path);
3407
3063
  }
@@ -3417,30 +3073,20 @@ export class DshClientSession {
3417
3073
  await this.setCwd(created);
3418
3074
  }
3419
3075
  }
3420
- // -----------------------------------------------------------------------
3421
- // 模型 / 思考
3422
- // -----------------------------------------------------------------------
3423
- /** P2-17 动态与自定义模型 id 缓存(adapter 目录与 models.json 自定义模型;setModel 校验用)。 */
3424
3076
  dynamicModels = new Set();
3425
- /** 缓存自定义模型及动态适配器模型元数据,用于 setModel 快速解析。 */
3426
3077
  customModelsMap = new Map();
3427
3078
  async listModels() {
3428
- // 以本地表为底(定价/上下文窗口/vision 标记),运行时 adapter 目录与 models.json 自定义模型动态
3429
- // 扩展——新模型自动出现在选择器,无需改代码。
3430
3079
  const known = new Map(DSH_MODELS.map((m) => [m.id, m]));
3431
3080
  let dynamic = [];
3432
3081
  try {
3433
3082
  const res = await this.runtime.listModels();
3434
3083
  dynamic = res.models ?? [];
3435
3084
  }
3436
- catch {
3437
- /* 运行时不可用 → 只发本地表 */
3438
- }
3085
+ catch { }
3439
3086
  const seen = new Set();
3440
3087
  const models = [];
3441
3088
  this.dynamicModels.clear();
3442
3089
  this.customModelsMap.clear();
3443
- // 1. DSH 官方内置模型
3444
3090
  for (const m of DSH_MODELS) {
3445
3091
  const canonicalId = `deepseek/${m.id}`;
3446
3092
  seen.add(m.id);
@@ -3465,7 +3111,6 @@ export class DshClientSession {
3465
3111
  vision: m.vision,
3466
3112
  });
3467
3113
  }
3468
- // 2. 运行时动态目录(adapter 发现)
3469
3114
  for (const m of dynamic) {
3470
3115
  const canonicalId = m.id.includes("/") ? m.id : `deepseek/${m.id}`;
3471
3116
  const bareId = m.id.includes("/") ? m.id.slice(m.id.indexOf("/") + 1) : m.id;
@@ -3496,7 +3141,6 @@ export class DshClientSession {
3496
3141
  vision,
3497
3142
  });
3498
3143
  }
3499
- // 3. 用户在 models.json 中配置的第三方自定义端点模型(针对性过滤 DSH 不支持的协议,如 anthropic-messages)
3500
3144
  try {
3501
3145
  const custom = listCustomModelsFromConfig(this.agentDir, (entry) => isModelProtocolSupportedByEngine("dsh", entry));
3502
3146
  for (const c of custom) {
@@ -3526,12 +3170,9 @@ export class DshClientSession {
3526
3170
  });
3527
3171
  }
3528
3172
  }
3529
- catch {
3530
- /* models.json 不存在或解析错误 → 静默忽略 */
3531
- }
3173
+ catch { }
3532
3174
  this.emit({ type: "models", models });
3533
3175
  }
3534
- /** 解析模型 ID 对应的服务商、元数据与裸模型 ID。 */
3535
3176
  resolveModelMeta(modelId) {
3536
3177
  const normId = modelId.trim();
3537
3178
  const hasSlash = normId.includes("/");
@@ -3565,9 +3206,7 @@ export class DshClientSession {
3565
3206
  };
3566
3207
  }
3567
3208
  }
3568
- catch {
3569
- /* ignore */
3570
- }
3209
+ catch { }
3571
3210
  }
3572
3211
  }
3573
3212
  if (meta) {
@@ -3583,7 +3222,6 @@ export class DshClientSession {
3583
3222
  this.dynamicModels.has(bareModelId);
3584
3223
  return { meta, targetProvider, bareModelId, known };
3585
3224
  }
3586
- /** 应用已保存的模型配置到当前 session 实例(启动/恢复/切换工作区时用)。 */
3587
3225
  applySavedModel(modelId) {
3588
3226
  const res = this.resolveModelMeta(modelId);
3589
3227
  if (res.known || res.meta) {
@@ -3593,7 +3231,6 @@ export class DshClientSession {
3593
3231
  this.modelVision = res.meta?.vision ?? false;
3594
3232
  }
3595
3233
  }
3596
- /** 换模型 = 重启运行时。支持官方模型与第三方自定义端点模型。 */
3597
3234
  async setModel(modelId) {
3598
3235
  const { meta, targetProvider, bareModelId, known } = this.resolveModelMeta(modelId);
3599
3236
  if (!known) {
@@ -3607,7 +3244,6 @@ export class DshClientSession {
3607
3244
  }
3608
3245
  if (bareModelId === this.model && targetProvider === this.modelProvider)
3609
3246
  return;
3610
- // 解析服务商 BaseURL 与 API Key(如果是自定义 Provider)
3611
3247
  const cred = resolveProviderCredential(this.agentDir, targetProvider);
3612
3248
  if (targetProvider !== "deepseek" && !cred.apiKey && !process.env.DEEPSEEK_API_KEY) {
3613
3249
  this.emit({
@@ -3617,7 +3253,6 @@ export class DshClientSession {
3617
3253
  textEn: `Provider "${targetProvider}" has no API Key configured. Please configure it in Model Settings.`,
3618
3254
  });
3619
3255
  }
3620
- // P0-2 竞态告知:换模型 = 强杀运行时 → 进行中的 run 全部中止。
3621
3256
  if ([...this.convs.values()].some((c) => c.isStreaming)) {
3622
3257
  this.emit({
3623
3258
  type: "notice",
@@ -3630,7 +3265,6 @@ export class DshClientSession {
3630
3265
  this.modelProvider = targetProvider;
3631
3266
  this.modelDisplayName = meta?.name ?? bareModelId;
3632
3267
  this.modelVision = meta?.vision ?? false;
3633
- // 持久化当前项目的模型选择(按 DSH 引擎独立记录)
3634
3268
  this.stateStore?.saveProjectModel(this.clientId, this.cwd, modelId, "dsh");
3635
3269
  try {
3636
3270
  await this.runtime.restart(bareModelId, targetProvider);
@@ -3704,9 +3338,6 @@ export class DshClientSession {
3704
3338
  this.thinkingLevel = level;
3705
3339
  this.flushSnapshot();
3706
3340
  }
3707
- // -----------------------------------------------------------------------
3708
- // 设置 / 系统提示词
3709
- // -----------------------------------------------------------------------
3710
3341
  buildFallbackPromptSections() {
3711
3342
  const identity = "You are an AI agent powered by DeepSeek Harness.";
3712
3343
  const custom = this.settings.customSystemPrompt.trim();
@@ -3755,37 +3386,33 @@ export class DshClientSession {
3755
3386
  : this.buildFallbackPromptSourceDefaults();
3756
3387
  const promptSections = this.cachedPromptSections.length > 0 ? this.cachedPromptSections : this.buildFallbackPromptSections();
3757
3388
  const settings = {
3389
+ nativeCliInheritModel: { ...this.stateStore.getSettingsSnapshot(this.clientId).nativeCliInheritModel },
3390
+ ...normalizeQuickAskSettings(this.stateStore.getSettingsSnapshot(this.clientId)),
3758
3391
  steeringMode: "all",
3759
3392
  followUpMode: "all",
3760
3393
  promptMode: this.settings.promptMode,
3761
3394
  customSystemPrompt: this.settings.customSystemPrompt,
3762
3395
  disabledSkills: this.settings.disabledSkills,
3763
3396
  disabledExtensions: this.settings.disabledExtensions,
3764
- // DSH engine: no unified tool gating (no subagent/edit_soft); empty keeps protocol complete.
3765
3397
  disabledAgentTools: [],
3766
- // DSH has no plugin host: no plugin AI tools exist here; empty keeps protocol complete.
3767
3398
  disabledPluginTools: [],
3768
3399
  terminalToolsEnabled: this.settings.terminalToolsEnabled,
3769
3400
  terminalBash: this.settings.terminalBash,
3770
3401
  terminalBashIdleMs: this.settings.terminalBashIdleMs,
3771
3402
  terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
3772
3403
  toolWatchdogTimeoutMs: this.settings.toolWatchdogTimeoutMs,
3773
- // DSH 引擎无 customTool 注册面(工具来自 shipped preset),read 目录覆盖面不存在。
3774
3404
  readDirEnabled: true,
3775
3405
  bgAutoCleanupMin: Number(this.settings.bgAutoCleanupMin ?? 0),
3776
- // DSH 无 pi 工具注册面,不适用延迟加载;保协议完整(该字段恒为 false,设置页不显示这一行)。
3777
3406
  toolLazyLoading: false,
3778
3407
  codemodeMode: "on",
3779
3408
  codemodeInlineBudget: 3000,
3780
3409
  editSoftEnabled: this.settings.editSoftEnabled,
3781
- // DSH 无独立重试配置(pi 引擎才暴露),保持默认。
3782
3410
  retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
3783
- // DSH 另有运行时:压缩软上限是 pi 引擎概念,这里保持关闭保协议完整。
3784
3411
  softCapTokens: 0,
3785
3412
  softCapByModel: {},
3413
+ autoCompactionInstructions: "",
3786
3414
  questionnaireEnabled: this.settings.questionnaireEnabled,
3787
3415
  toolApprovalEnabled: this.settings.toolApprovalEnabled !== false,
3788
- // DSH 无审批弹窗,策略恒为空(保协议完整)。
3789
3416
  approvalPolicy: { allowAll: false, categories: [] },
3790
3417
  approvalRules: [],
3791
3418
  goalModeEnabled: this.settings.goalModeEnabled,
@@ -3797,12 +3424,10 @@ export class DshClientSession {
3797
3424
  showForkedParentSessions: this.settings.showForkedParentSessions ?? false,
3798
3425
  retainFinishedConversations: this.settings.retainFinishedConversations ?? false,
3799
3426
  openRecentSessionOnProjectSwitch: this.settings.openRecentSessionOnProjectSwitch ?? true,
3800
- // DSH 无 skill 全文注入概念,给空保协议完整。
3801
3427
  skillsFullText: [],
3802
3428
  skillsCatalogMaxDesc: 250,
3803
3429
  skillsCatalogShowLocation: false,
3804
3430
  skillsCatalogBudget: 20000,
3805
- // DSH 不注入技能正文,但协议字段要齐全(设置页读快照)。
3806
3431
  skillsMaxFileBytes: 8192,
3807
3432
  skillsFullTextMaxBytes: 32768,
3808
3433
  chatUploadMaxMb: this.stateStore.getSettingsSnapshot(this.clientId).chatUploadMaxMb ?? 20,
@@ -3812,10 +3437,8 @@ export class DshClientSession {
3812
3437
  visionBridgeModel: null,
3813
3438
  visionBridgePromptMode: "append",
3814
3439
  visionBridgePrompt: "",
3815
- // DSH 无「AI 生成提交信息」(scm_commitmsg 分发处直接报错),保协议完整。
3816
3440
  scmCommitMsgPromptMode: "append",
3817
3441
  scmCommitMsgPrompt: "",
3818
- // DSH 引擎不渲染计划按钮(无 customTools 注册面),保协议完整。
3819
3442
  planModePromptMode: "append",
3820
3443
  planModePrompt: "",
3821
3444
  planModeDefaultPrompt: PLAN_MODE_SYSTEM_PROMPT,
@@ -3826,12 +3449,10 @@ export class DshClientSession {
3826
3449
  promptTemplate: this.settings.promptTemplate ?? "",
3827
3450
  promptOverrides: this.settings.promptOverrides ?? {},
3828
3451
  promptDisabled: [...(this.settings.promptDisabled ?? [])],
3829
- // DSH 无 pi 工具注册表面,逐工具文案覆盖不适用;保协议完整。
3830
3452
  toolPromptOverrides: {},
3831
3453
  effectiveSystemPrompt,
3832
3454
  promptSourceDefaults,
3833
3455
  promptSections,
3834
- // DSH 运行时真实的工具 schema 文本(发给模型的工具列表 JSON Schema 格式化文本)。
3835
3456
  toolsSchema: this.cachedToolsSchema,
3836
3457
  visionBridgeDefaultPrompt: "",
3837
3458
  scmCommitMsgDefaultPrompt: "",
@@ -3933,8 +3554,9 @@ export class DshClientSession {
3933
3554
  disabledMarkers: partial.disabledMarkers,
3934
3555
  });
3935
3556
  const markerGuidanceChanged = this.markerSvc.buildGuidance() !== prevMarkerGuidance;
3936
- // 持久化(跨重连存活)。
3937
3557
  this.stateStore.saveSettings(this.clientId, {
3558
+ nativeCliInheritModel: partial.nativeCliInheritModel,
3559
+ ...mergeQuickAskSettings(this.stateStore.getSettingsSnapshot(this.clientId), partial),
3938
3560
  chatUploadMaxMb: partial.chatUploadMaxMb,
3939
3561
  workspaceUploadMaxMb: partial.workspaceUploadMaxMb,
3940
3562
  folderUploadMaxMb: partial.folderUploadMaxMb,
@@ -3947,11 +3569,10 @@ export class DshClientSession {
3947
3569
  terminalBashIdleMs: this.settings.terminalBashIdleMs,
3948
3570
  terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
3949
3571
  editSoftEnabled: this.settings.editSoftEnabled,
3950
- // DSH 无独立重试配置(pi 引擎才暴露),保持默认。
3951
3572
  retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
3952
- // DSH 另有运行时:压缩软上限是 pi 引擎概念,这里保持关闭保协议完整。
3953
3573
  softCapTokens: 0,
3954
3574
  softCapByModel: {},
3575
+ autoCompactionInstructions: "",
3955
3576
  questionnaireEnabled: this.settings.questionnaireEnabled,
3956
3577
  toolApprovalEnabled: this.settings.toolApprovalEnabled !== false,
3957
3578
  goalModeEnabled: this.settings.goalModeEnabled,
@@ -3975,14 +3596,11 @@ export class DshClientSession {
3975
3596
  promptOverrides: this.settings.promptOverrides ?? {},
3976
3597
  promptDisabled: [...(this.settings.promptDisabled ?? [])],
3977
3598
  });
3978
- // 仅系统提示词或内联标记指引变化才重启运行时(DSH_PERSONA 由 launcher env 注入);
3979
- // 其他设置(开关/隐藏插件等)只存不回写运行时。
3980
3599
  const personaChanged = partial.promptMode !== undefined || partial.customSystemPrompt !== undefined || markerGuidanceChanged;
3981
3600
  if (personaChanged) {
3982
3601
  await this.applyPersona();
3983
3602
  void this.refreshPromptInfo().catch(() => { });
3984
3603
  }
3985
- // 技能启停(#18):禁用集变化 → 同步运行时(晚 pre-step 钩子过滤目录)并刷新技能列表。
3986
3604
  if (partial.disabledSkills !== undefined) {
3987
3605
  void this.pushDisabledSkillsToRuntime();
3988
3606
  void this.refreshSkillsFromRuntime();
@@ -4002,18 +3620,12 @@ export class DshClientSession {
4002
3620
  return { DSH_PERSONA: persona, PI_WEB_DSH_CUSTOM_PROMPT: effectiveCustom };
4003
3621
  }
4004
3622
  applyPersona() {
4005
- // 自定义提示词双通道:DSH_PERSONA(host 部署人设;预设 persona 会 shadow 它,
4006
- // minimal 更全压住)+ PI_WEB_DSH_CUSTOM_PROMPT(独立 host section,随
4007
- // standard/ptc/cordis 下发;minimal 下被 complete 压住,官方语义)。
4008
3623
  this.runtime.env = { ...this.runtime.env, ...this.buildPersonaEnv() };
4009
3624
  if (this.runtime.alive) {
4010
- return this.runtime.restart(this.model).catch(() => {
4011
- /* keep old runtime */
4012
- });
3625
+ return this.runtime.restart(this.model).catch(() => { });
4013
3626
  }
4014
3627
  return Promise.resolve();
4015
3628
  }
4016
- /** 从运行时异步拉取真实组装的系统提示词、sections 与工具 schema。 */
4017
3629
  async refreshPromptInfo() {
4018
3630
  try {
4019
3631
  if (!this.runtime.alive)
@@ -4038,12 +3650,9 @@ export class DshClientSession {
4038
3650
  this.pushSettings();
4039
3651
  }
4040
3652
  }
4041
- catch {
4042
- /* 忽略拉取失败,保持上一次缓存或兜底 */
4043
- }
3653
+ catch { }
4044
3654
  }
4045
3655
  async reloadExtensions() {
4046
- // DSH 引擎无 pi 扩展体系。
4047
3656
  this.emit({
4048
3657
  type: "notice",
4049
3658
  level: "info",
@@ -4051,10 +3660,6 @@ export class DshClientSession {
4051
3660
  textEn: "The DSH engine does not support pi extension hot-reload",
4052
3661
  });
4053
3662
  }
4054
- // -----------------------------------------------------------------------
4055
- // Agent 预设(dsh-web 四模式;Node 侧是真相源,运行时只负责挂载)
4056
- // -----------------------------------------------------------------------
4057
- /** 从运行时拉取预设名录(每次启动后跑;失败/legacy → UI 隐藏预设条)。 */
4058
3663
  async refreshAgentPresets() {
4059
3664
  try {
4060
3665
  const res = await this.runtime.listPresets();
@@ -4077,13 +3682,11 @@ export class DshClientSession {
4077
3682
  this.pushAgentPresets();
4078
3683
  this.flushSnapshot();
4079
3684
  }
4080
- /** 校验一个预设 id(名录 healthy 优先;legacy/未知 → 默认)。 */
4081
3685
  resolvePreset(requested) {
4082
3686
  if (requested) {
4083
3687
  const hit = this.agentPresets.find((p) => p.id === requested && !p.broken);
4084
3688
  if (hit)
4085
3689
  return hit.id;
4086
- // 名录还没拉到(启动中)但 clone 有它 → 先信 clone,挂载期再定。
4087
3690
  if (this.presetCloneIds.includes(requested))
4088
3691
  return requested;
4089
3692
  }
@@ -4097,7 +3700,6 @@ export class DshClientSession {
4097
3700
  }
4098
3701
  return PRESET_DEFAULT_ID;
4099
3702
  }
4100
- /** 推送预设名录 + 默认(attach/变化后;legacy 下 presets 空,前端隐藏)。 */
4101
3703
  pushAgentPresets() {
4102
3704
  this.emit({
4103
3705
  type: "dsh_presets",
@@ -4105,7 +3707,6 @@ export class DshClientSession {
4105
3707
  defaultPreset: this.resolvePreset(),
4106
3708
  });
4107
3709
  }
4108
- /** 新会话默认预设(设置面板;非法 id 拒绝并提示)。 */
4109
3710
  async setDefaultAgentPreset(preset) {
4110
3711
  const hit = this.agentPresets.find((p) => p.id === preset && !p.broken);
4111
3712
  const valid = hit ? hit.id : this.presetCloneIds.includes(preset) ? preset : null;
@@ -4124,7 +3725,6 @@ export class DshClientSession {
4124
3725
  this.pushAgentPresets();
4125
3726
  this.flushSnapshot();
4126
3727
  }
4127
- /** 空白会话切换预设(首轮后锁定,官方语义;失败按 code 出双语 notice)。 */
4128
3728
  async selectAgentPreset(preset) {
4129
3729
  const conv = this.conv;
4130
3730
  if (conv.presetLocked || conv.messages.length > 0) {
@@ -4172,14 +3772,9 @@ export class DshClientSession {
4172
3772
  });
4173
3773
  }
4174
3774
  }
4175
- /** 预设显示名(名录 name > id;供 notice/前端回退)。 */
4176
3775
  presetName(id) {
4177
3776
  return this.agentPresets.find((p) => p.id === id)?.name ?? id;
4178
3777
  }
4179
- // -----------------------------------------------------------------------
4180
- // 权限预设(三档;官方 /permission 弹窗同源,Node 侧只做值守 + 转发)
4181
- // -----------------------------------------------------------------------
4182
- /** 校验三档值(非法 → 默认;组合里没有也照默认,前端按 options 取交集展示)。 */
4183
3778
  resolvePermissionPreset(requested) {
4184
3779
  if (requested && PERMISSION_OFFERED.includes(requested))
4185
3780
  return requested;
@@ -4188,7 +3783,6 @@ export class DshClientSession {
4188
3783
  return def;
4189
3784
  return PERMISSION_DEFAULT_PRESET;
4190
3785
  }
4191
- /** 推选项表 + 默认(组合静态,options 为空 = 运行时未就绪/legacy,前端隐藏)。 */
4192
3786
  pushPermission() {
4193
3787
  this.emit({
4194
3788
  type: "dsh_permission",
@@ -4196,7 +3790,6 @@ export class DshClientSession {
4196
3790
  defaultPreset: this.settings.defaultPermissionPreset,
4197
3791
  });
4198
3792
  }
4199
- /** 拉取权限选项表(运行时启动/重建后跑一次;失败 → 空,前端隐藏)。 */
4200
3793
  async refreshPermissionOptions() {
4201
3794
  try {
4202
3795
  const res = await this.runtime.getPermission(this.conv.sessionId);
@@ -4207,7 +3800,6 @@ export class DshClientSession {
4207
3800
  }
4208
3801
  this.pushPermission();
4209
3802
  }
4210
- /** 拉取当前会话的权限预设值(激活/创建/切换/重启后跑;失败保持 null)。 */
4211
3803
  async refreshActivePermission() {
4212
3804
  const conv = this.conv;
4213
3805
  try {
@@ -4221,12 +3813,9 @@ export class DshClientSession {
4221
3813
  if (cur)
4222
3814
  conv.permissionPreset = cur;
4223
3815
  }
4224
- catch {
4225
- /* 运行时未就绪:保持 null/旧值 */
4226
- }
3816
+ catch { }
4227
3817
  this.flushSnapshot();
4228
3818
  }
4229
- /** 新会话默认权限预设(设置面板;非法值拒绝并提示)。 */
4230
3819
  async setDefaultPermissionPreset(preset) {
4231
3820
  if (!PERMISSION_OFFERED.includes(preset)) {
4232
3821
  this.emit({
@@ -4242,7 +3831,6 @@ export class DshClientSession {
4242
3831
  this.pushPermission();
4243
3832
  this.flushSnapshot();
4244
3833
  }
4245
- /** 首轮 prompt 前:新会话应用 per-client 默认(与当前一致时 apply 无事件零噪音)。 */
4246
3834
  async ensurePermissionDefault(conv) {
4247
3835
  const target = this.resolvePermissionPreset();
4248
3836
  try {
@@ -4257,11 +3845,8 @@ export class DshClientSession {
4257
3845
  conv.permissionPreset = res.currentValue || target;
4258
3846
  }
4259
3847
  }
4260
- catch {
4261
- /* legacy/运行时未就绪:best effort */
4262
- }
3848
+ catch { }
4263
3849
  }
4264
- /** 当前会话切换权限预设(热切换,无需重启;失败按 code 出双语 notice)。 */
4265
3850
  async setPermissionPreset(preset) {
4266
3851
  const conv = this.conv;
4267
3852
  const target = this.resolvePermissionPreset(preset);
@@ -4302,11 +3887,6 @@ export class DshClientSession {
4302
3887
  });
4303
3888
  }
4304
3889
  }
4305
- /**
4306
- * 审查者模式:DSH 不支持(无 customTools 注册面 → 工具硬闸门无处可挂,
4307
- * 自动路由也没有可派发的会话通道)。明确回报而不是静默失败 ——
4308
- * “点了没反应”比“用不了”更让人怀疑是不是页面坏了。
4309
- */
4310
3890
  async setDelegateMode(enabled) {
4311
3891
  if (!enabled)
4312
3892
  return;
@@ -4330,20 +3910,17 @@ export class DshClientSession {
4330
3910
  promptDisabled: [],
4331
3911
  disabledSkills: this.settings.disabledSkills,
4332
3912
  disabledExtensions: this.settings.disabledExtensions,
4333
- // DSH engine: no unified tool gating (no subagent/edit_soft); empty keeps protocol complete.
4334
3913
  disabledAgentTools: [],
4335
3914
  terminalToolsEnabled: this.settings.terminalToolsEnabled,
4336
3915
  terminalBash: this.settings.terminalBash,
4337
3916
  terminalBashIdleMs: this.settings.terminalBashIdleMs,
4338
3917
  terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
4339
3918
  editSoftEnabled: this.settings.editSoftEnabled,
4340
- // DSH 无独立重试配置,预设沿用默认值。
4341
- // DSH 无 skill 全文注入概念,给空保预设类型完整。
4342
3919
  skillsFullText: [],
4343
3920
  retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
4344
- // DSH 另有运行时:压缩软上限是 pi 引擎概念,预设里保持关闭。
4345
3921
  softCapTokens: 0,
4346
3922
  softCapByModel: {},
3923
+ autoCompactionInstructions: "",
4347
3924
  visionBridgePromptMode: "append",
4348
3925
  visionBridgePrompt: "",
4349
3926
  reviewPrompt: this.settings.reviewPrompt,
@@ -4369,7 +3946,6 @@ export class DshClientSession {
4369
3946
  });
4370
3947
  return;
4371
3948
  }
4372
- // Keep absent fields intact, including settings owned by other engines.
4373
3949
  const { settings } = sanitizePresetSettings(preset);
4374
3950
  this.stateStore.saveSettings(this.clientId, settings);
4375
3951
  Object.assign(this.settings, settings);
@@ -4382,11 +3958,6 @@ export class DshClientSession {
4382
3958
  this.stateStore.savePresets(this.clientId, presets.filter((p) => p.name !== name));
4383
3959
  this.pushSettings();
4384
3960
  }
4385
- /* -----------------------------------------------------------------------
4386
- * 预设分享(server/preset-share.ts)—— 与 pi 引擎同一份编排,只换适配层。
4387
- * DSH 的预设存储/应用语义不同,所以把「取/存/应用」按 DSH 的做法接上。
4388
- * --------------------------------------------------------------------- */
4389
- /** 分享编排需要的最小能力集合(DSH 侧)。 */
4390
3961
  sharePort() {
4391
3962
  return {
4392
3963
  lang: () => this.getLang(),
@@ -4394,8 +3965,6 @@ export class DshClientSession {
4394
3965
  presets: () => this.stateStore.getPresets(this.clientId),
4395
3966
  currentSettings: () => {
4396
3967
  const s = this.settings;
4397
- // DSH 的预设记录字段与 ClientSettings 不完全一致(没有 promptTemplate/
4398
- // promptOverrides 等),导出时按预设形状给默认值(应用侧只读它认识的)。
4399
3968
  return {
4400
3969
  promptMode: s.promptMode,
4401
3970
  customSystemPrompt: s.customSystemPrompt,
@@ -4427,29 +3996,21 @@ export class DshClientSession {
4427
3996
  emit: (msg) => this.emit(msg),
4428
3997
  };
4429
3998
  }
4430
- /** 导出预设/当前设置为可分享的 JSON(服务端 preset-share.ts)。 */
4431
3999
  async exportPreset(msg) {
4432
4000
  exportPresetVia(this.sharePort(), msg);
4433
4001
  }
4434
- /** 解析导入的预设 JSON(dryRun = 只预览)。 */
4435
4002
  async importPreset(msg) {
4436
4003
  await importPresetVia(this.sharePort(), msg);
4437
4004
  }
4438
- /** 按网址导入预设(服务端抓取)。 */
4439
4005
  async importPresetFromUrl(msg) {
4440
4006
  await importPresetFromUrlVia(this.sharePort(), msg);
4441
4007
  }
4442
- /** 拉社区共享预设目录。 */
4443
4008
  async pushPresetCatalog(msg) {
4444
4009
  await pushPresetCatalogVia(this.sharePort(), msg);
4445
4010
  }
4446
- /** 一键分享预设到社区共享仓库。 */
4447
4011
  async sharePreset(msg) {
4448
4012
  await sharePresetVia(this.sharePort(), msg);
4449
4013
  }
4450
- // -----------------------------------------------------------------------
4451
- // 子代理模板(DSH 引擎无子代理概念 —— 设置面板分区由前端 isDsh 隐藏)
4452
- // -----------------------------------------------------------------------
4453
4014
  async saveSubagentTemplate() {
4454
4015
  this.emit({
4455
4016
  type: "notice",
@@ -4466,16 +4027,9 @@ export class DshClientSession {
4466
4027
  textEn: "Subagent templates are not supported by the DSH engine (use the pi engine instead)",
4467
4028
  });
4468
4029
  }
4469
- // -----------------------------------------------------------------------
4470
- // 目标(DSH 原生 goal 域:goal/change 事件驱动,round-driver 自动轮次)
4471
- // -----------------------------------------------------------------------
4472
4030
  emitGoalStatus() {
4473
4031
  this.emit({ type: "goal_status", status: { ...this.conv.goal } });
4474
4032
  }
4475
- /**
4476
- * goal/change 事件(DSH 原生状态机全量快照)→ 镜像到当前 conversation。
4477
- * 权威源在运行时:create/edit/resume → active;complete → pass;block → fail。
4478
- */
4479
4033
  applyGoalChange(conv, data) {
4480
4034
  const g = conv.goal;
4481
4035
  if (data.operation === "clear" || (!data.goal && data.cleared)) {
@@ -4508,8 +4062,6 @@ export class DshClientSession {
4508
4062
  g.reviewing = true;
4509
4063
  g.verdict = "pending";
4510
4064
  g.feedback = undefined;
4511
- // P1-10:轮次已达上限且仍未完成 → 提示轮尽(模型可能正在跑最后一轮,
4512
- // 后续 complete/blocked 事件会覆盖此状态)。
4513
4065
  const rounds = g.round ?? 0;
4514
4066
  const max = data.goal.maxGoalRounds ?? g.maxRounds ?? 0;
4515
4067
  g.status =
@@ -4575,12 +4127,9 @@ export class DshClientSession {
4575
4127
  g.reviewModel = opts?.reviewModel ?? g.reviewModel;
4576
4128
  g.maxRounds = opts?.maxRounds ?? g.maxRounds;
4577
4129
  g.locked = opts?.locked ?? g.locked;
4578
- // P1-11:DSH 无独立审查者,locked 映射为轮次语义 ——
4579
- // locked=true(目标锁定,必须达成)→ 保留用户轮次上限;
4580
- // locked=false(不锁定)→ 单轮语义近似(maxGoalRounds=1,一轮后结束)。
4581
4130
  const effectiveMax = g.locked ? g.maxRounds : 1;
4582
4131
  g.round = 0;
4583
- g.reviewing = true; // round-driver 会立刻续第一轮
4132
+ g.reviewing = true;
4584
4133
  g.verdict = "pending";
4585
4134
  g.feedback = undefined;
4586
4135
  g.status = "目标已设,等待生成…";
@@ -4599,7 +4148,6 @@ export class DshClientSession {
4599
4148
  textEn: `🎯 Goal set: ${text.slice(0, 80)}${text.length > 80 ? "…" : ""}`,
4600
4149
  });
4601
4150
  try {
4602
- // goal/set 创建 + arm;round-driver 在 agent idle 时自动续轮,无需额外 prompt。
4603
4151
  const res = (await this.runtime.goalSet(conv.sessionId, text, effectiveMax > 0 ? effectiveMax : undefined));
4604
4152
  if (res?.goal?.maxGoalRounds)
4605
4153
  g.maxRounds = res.goal.maxGoalRounds;
@@ -4620,7 +4168,6 @@ export class DshClientSession {
4620
4168
  }
4621
4169
  async clearGoal() {
4622
4170
  const conv = this.conv;
4623
- // 向导进行中 → 中断等待(模型侧提问会因超时/无 provider 恢复)。
4624
4171
  if (conv.turnWaiter) {
4625
4172
  const w = conv.turnWaiter;
4626
4173
  conv.turnWaiter = undefined;
@@ -4630,9 +4177,7 @@ export class DshClientSession {
4630
4177
  try {
4631
4178
  await this.runtime.goalClear(conv.sessionId);
4632
4179
  }
4633
- catch {
4634
- /* goal/change clear 事件会回来兜底 */
4635
- }
4180
+ catch { }
4636
4181
  }
4637
4182
  conv.dsGoal = null;
4638
4183
  const g = conv.goal;
@@ -4647,8 +4192,6 @@ export class DshClientSession {
4647
4192
  this.flushSnapshot();
4648
4193
  }
4649
4194
  async startGoalWizard(text, opts) {
4650
- // 交互式调研向导:主会话 prompt 向导指令 → 模型用 ask_user_question 逐题
4651
- // 提问(经提问桥 → 浏览器对话框)→ 收敛输出 GOAL: 行 → 自动设目标。
4652
4195
  if (this.quiesceBlocked())
4653
4196
  return;
4654
4197
  if (this.settings.goalModeEnabled === false) {
@@ -4721,12 +4264,10 @@ export class DshClientSession {
4721
4264
  g.wizard.step = 0;
4722
4265
  g.wizard.status = "";
4723
4266
  g.wizard.statusEn = "";
4724
- // 解析模型最终输出中的 GOAL: 行。
4725
4267
  const finalText = this.lastAssistantText(conv);
4726
4268
  const goalMatch = finalText.match(/GOAL\s*[::]\s*([\s\S]*)/i);
4727
4269
  let refined = goalMatch ? goalMatch[1].trim() : "";
4728
4270
  if (!refined) {
4729
- // 未按格式:取最后一段非空文本(截断防污染)。
4730
4271
  refined =
4731
4272
  finalText
4732
4273
  .split("\n")
@@ -4737,7 +4278,6 @@ export class DshClientSession {
4737
4278
  refined = refined.slice(0, 300);
4738
4279
  }
4739
4280
  if (!refined && g.goal) {
4740
- // 模型可能直接用了 create_goal —— 目标已在运行时,镜像它即可。
4741
4281
  this.emitGoalStatus();
4742
4282
  this.emit({
4743
4283
  type: "notice",
@@ -4770,7 +4310,6 @@ export class DshClientSession {
4770
4310
  });
4771
4311
  }
4772
4312
  }
4773
- /** 调研向导指令(主会话 prompt):先提问收敛,最后只输出 GOAL: 行。 */
4774
4313
  wizardPrompt(draft) {
4775
4314
  return [
4776
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.`,
@@ -4784,7 +4323,6 @@ export class DshClientSession {
4784
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.`,
4785
4324
  ].join("\n");
4786
4325
  }
4787
- /** 会话最后一条 assistant 文本(向导/调试提取用)。 */
4788
4326
  lastAssistantText(conv) {
4789
4327
  for (let i = conv.messages.length - 1; i >= 0; i--) {
4790
4328
  const m = conv.messages[i];
@@ -4810,9 +4348,6 @@ export class DshClientSession {
4810
4348
  });
4811
4349
  this.emitGoalStatus();
4812
4350
  }
4813
- // -----------------------------------------------------------------------
4814
- // 命令列表(.pi/commands.json → DSH 无命令体系,简化为空/透传存储)
4815
- // -----------------------------------------------------------------------
4816
4351
  async listCommands() {
4817
4352
  const { commands, path } = await loadCommands(this.cwd);
4818
4353
  this.emit({ type: "commands", commands, path });
@@ -4831,9 +4366,6 @@ export class DshClientSession {
4831
4366
  this.emit({ type: "notice", level: "info", text: `命令已保存(${path})`, textEn: `Command saved (${path})` });
4832
4367
  }
4833
4368
  }
4834
- // -----------------------------------------------------------------------
4835
- // 斜杠命令(内置 NATIVE + 插件 registerCommand;DSH 无扩展/技能/模板体系)
4836
- // -----------------------------------------------------------------------
4837
4369
  async pushSlashCommands() {
4838
4370
  const commands = [];
4839
4371
  const seen = new Set();
@@ -4841,7 +4373,6 @@ export class DshClientSession {
4841
4373
  commands.push({ ...c, source: "builtin" });
4842
4374
  seen.add(c.name);
4843
4375
  }
4844
- // 技能命令:运行时技能 + 磁盘技能
4845
4376
  for (const s of this.skillsCache) {
4846
4377
  const name = `skill:${s.name}`;
4847
4378
  if (seen.has(name))
@@ -4880,7 +4411,6 @@ export class DshClientSession {
4880
4411
  }
4881
4412
  this.emit({ type: "slash_commands", commands });
4882
4413
  }
4883
- /** 拦截执行斜杠命令;返回 true 表示已处理(不发给模型)。 */
4884
4414
  async execSlash(name, args) {
4885
4415
  if (name.startsWith("skill:")) {
4886
4416
  const skillName = name.slice(6);
@@ -4898,8 +4428,6 @@ export class DshClientSession {
4898
4428
  switch (name) {
4899
4429
  case "new": {
4900
4430
  const first = args.trim();
4901
- // /new <prompt>:与 pi 引擎一致(共用 NATIVE_COMMANDS 的提示词),
4902
- // 仅当真的落在空白新对话上才投递首条提示,否则会把提示误发进当前对话。
4903
4431
  if ((await this.newChat()) && first)
4904
4432
  await this.prompt(first);
4905
4433
  return true;
@@ -4951,9 +4479,9 @@ export class DshClientSession {
4951
4479
  await this.refreshSessions();
4952
4480
  return true;
4953
4481
  case "help":
4954
- return true; // 前端 /help modal 展示目录
4482
+ return true;
4955
4483
  case "copy":
4956
- return true; // 前端本地实现
4484
+ return true;
4957
4485
  case "reload":
4958
4486
  this.emit({
4959
4487
  type: "notice",
@@ -4983,7 +4511,6 @@ export class DshClientSession {
4983
4511
  this.onQuit?.();
4984
4512
  return true;
4985
4513
  }
4986
- // 插件命令(host.registerCommand)
4987
4514
  const def = this.pluginCommandsProvider?.().find((c) => c.name === name);
4988
4515
  if (def) {
4989
4516
  try {
@@ -5004,15 +4531,11 @@ export class DshClientSession {
5004
4531
  }
5005
4532
  return false;
5006
4533
  }
5007
- // -----------------------------------------------------------------------
5008
- // 自更新
5009
- // -----------------------------------------------------------------------
5010
4534
  static currentAppVersion() {
5011
4535
  return getAppVersion() || "0.0.0";
5012
4536
  }
5013
4537
  async checkUpdate() {
5014
4538
  try {
5015
- // registry 遵从 ~/.pi/agent/npm/.npmrc(与 `pi update` 经 npm 的行为一致,issue #151)
5016
4539
  const npmRegistry = resolveNpmRegistry(join(homedir(), ".pi", "agent"));
5017
4540
  const latest = await checkAllUpdates([{ name: "pi-web-ui", version: DshClientSession.currentAppVersion(), kind: "webui" }], undefined, () => this.getLang(), npmRegistry);
5018
4541
  const item = latest[0];
@@ -5044,7 +4567,6 @@ export class DshClientSession {
5044
4567
  });
5045
4568
  const items = await checkAllUpdates(targets, undefined, () => this.getLang(), resolveNpmRegistry(join(homedir(), ".pi", "agent")));
5046
4569
  if (force) {
5047
- // 强制模式:忽略缓存(默认 Fetcher 带 TTL,直接再查一次即可)。
5048
4570
  void items;
5049
4571
  }
5050
4572
  this.emit({
@@ -5065,9 +4587,6 @@ export class DshClientSession {
5065
4587
  this.emit({ type: "update_status_all", items: [] });
5066
4588
  }
5067
4589
  }
5068
- // -----------------------------------------------------------------------
5069
- // pi 专属:DSH 引擎下的简化实现
5070
- // -----------------------------------------------------------------------
5071
4590
  async installPiAgent() {
5072
4591
  this.emit({
5073
4592
  type: "install_result",
@@ -5075,7 +4594,6 @@ export class DshClientSession {
5075
4594
  detail: pick(this.getLang(), "DSH 引擎不需要 pi CLI", "The DSH engine does not need the pi CLI", "dsh.engine.no.cli"),
5076
4595
  });
5077
4596
  }
5078
- /** DSH 是否就绪:auth.json 的 deepseek key、环境变量 DEEPSEEK_API_KEY 或自定义 Provider 凭据任一即可。 */
5079
4597
  isDshConfigured() {
5080
4598
  if (loadDeepSeekKey(this.agentDir) || process.env.DEEPSEEK_API_KEY)
5081
4599
  return true;
@@ -5093,12 +4611,9 @@ export class DshClientSession {
5093
4611
  }
5094
4612
  }
5095
4613
  }
5096
- catch {
5097
- /* ignore */
5098
- }
4614
+ catch { }
5099
4615
  return false;
5100
4616
  }
5101
- /** 下拉框里的 deepseek-official 归一到 auth.json 的 deepseek 槽位(loadDeepSeekKey 只读它)。 */
5102
4617
  normalizeDshProvider(provider) {
5103
4618
  const pid = provider.trim();
5104
4619
  return pid === "deepseek-official" ? "deepseek" : pid;
@@ -5199,19 +4714,12 @@ export class DshClientSession {
5199
4714
  abortEnrichModels(reqId) {
5200
4715
  this.modelAdmin.abortEnrichModels(reqId);
5201
4716
  }
5202
- // -----------------------------------------------------------------------
5203
- // 其他
5204
- // -----------------------------------------------------------------------
5205
- resolveDialog(_id, _value) {
5206
- // DSH 引擎无扩展 UI 桥(dialog 由插件宿主走,v1 忽略)。
5207
- }
4717
+ resolveDialog(_id, _value) { }
5208
4718
  async editMessage(messageId, text, attachments) {
5209
4719
  if (this.quiesceBlocked() || this.switchingWorkspace || this.disposed)
5210
4720
  return;
5211
4721
  if (!text.trim() && !attachments?.length)
5212
4722
  return;
5213
- // The runtime has no history-replacement RPC. Close its append-only writer,
5214
- // replace the persisted prefix atomically, then resume the SAME session ID.
5215
4723
  let recoverRuntime;
5216
4724
  try {
5217
4725
  const conv = this.conv;
@@ -5242,8 +4750,6 @@ export class DshClientSession {
5242
4750
  const file = this.guessSessionFile(conv);
5243
4751
  if (!file)
5244
4752
  throw new Error("Persisted DSH session log not found; history was not changed");
5245
- // Every persisted session loses its live agent when this shared process stops.
5246
- // Mark them before stopping so failed rebuilds can restore lazily on prompt.
5247
4753
  const loaded = [...this.convs.values()].filter((c) => !c.fromDisk && this.guessSessionFile(c));
5248
4754
  recoverRuntime = async () => {
5249
4755
  if (!current())
@@ -5263,7 +4769,6 @@ export class DshClientSession {
5263
4769
  .map((e) => JSON.stringify(e))
5264
4770
  .join("\n") + "\n";
5265
4771
  writeAtomicSync(file, file.endsWith(".zstd") ? zstdCompressSync(Buffer.from(saved)) : saved, { fsync: true });
5266
- // Skip file asides belonging to this question; promptConv recreates attachments.
5267
4772
  let cutIdx = idx;
5268
4773
  while (cutIdx > 0 &&
5269
4774
  conv.messages[cutIdx - 1]?.role === "custom" &&
@@ -5278,7 +4783,6 @@ export class DshClientSession {
5278
4783
  await runtime.start();
5279
4784
  if (!current())
5280
4785
  return;
5281
- // DshRuntime has not yet exposed the installed SDK's session/resume RPC.
5282
4786
  await runtime._request("session/resume", { sessionId });
5283
4787
  if (!current())
5284
4788
  return;
@@ -5309,23 +4813,15 @@ export class DshClientSession {
5309
4813
  }
5310
4814
  }
5311
4815
  }
5312
- /** Server language for this client (issue #91): resolved LIVE from the
5313
- * persisted UI locale — "zh" only for zh*; everything else is English. */
5314
4816
  getLang() {
5315
4817
  return resolveServerLang(this.stateStore.get(this.clientId).locale);
5316
4818
  }
5317
- /** Persist the browser UI locale (hello.locale / set_locale). DSH
5318
- * runtime prompts pick it up on the next run — no restart needed. */
5319
4819
  async setLocale(locale) {
5320
4820
  const code = locale.trim().slice(0, 16);
5321
4821
  if (!code)
5322
4822
  return;
5323
4823
  this.stateStore.saveLocale(this.clientId, code);
5324
4824
  }
5325
- /** 设置当前项目的额外工作区根(宿主侧多根,宿主 API v2 的宿主侧能力)。
5326
- * DSH 引擎没有插件宿主,多根只落到「宿主知道 / 快照下发」这一层:右栏文件树
5327
- * (前端)据此多出可切换的根。
5328
- * 与 pi 引擎同口径:归一化交给 ClientStateStore(只收绝对路径 / 去重 / 上限 8)。 */
5329
4825
  async setWorkspaceRoots(roots) {
5330
4826
  const before = this.stateStore.getWorkspaceRoots(this.clientId, this.cwd);
5331
4827
  this.stateStore.saveWorkspaceRoots(this.clientId, this.cwd, roots ?? []);
@@ -5383,7 +4879,6 @@ export class DshClientSession {
5383
4879
  textEn: `Switching workspace & restarting runtime: ${abs}`,
5384
4880
  });
5385
4881
  await new Promise((r) => setImmediate(r));
5386
- // 恢复新工作区的记忆模型(按 DSH 引擎独立记录:项目记忆 > 全局默认)
5387
4882
  const savedModel = this.stateStore.getProjectModel(this.clientId, abs, "dsh") ?? this.stateStore.getDefaultModel("dsh");
5388
4883
  const previousModel = this.model;
5389
4884
  const previousProvider = this.modelProvider;
@@ -5404,11 +4899,8 @@ export class DshClientSession {
5404
4899
  this.cwd = abs;
5405
4900
  this.roots = this.stateStore.getWorkspaceRoots(this.clientId, abs);
5406
4901
  this.stateStore.remember(this.clientId, abs);
5407
- // 旧 active 会话:活跃的(流式/有终端/跑过)标 listed → 后台运行可见
5408
- // (与 pi 的 displaceActive 语义一致);空白的直接弃(不列)。
5409
4902
  const prev = this.conv;
5410
4903
  prev.listed = this.shouldRetainDshConversation(prev) || prev.messages.length > 0;
5411
- // 新项目 → 恢复最近历史会话(若有)或新建空白会话
5412
4904
  const openRecent = this.settings.openRecentSessionOnProjectSwitch ?? true;
5413
4905
  const recentFiles = openRecent
5414
4906
  ? findSessionFilesForCwd(this.sessionRoot, abs).filter((f) => !basename(dirname(f)).startsWith("review-"))
@@ -5433,8 +4925,6 @@ export class DshClientSession {
5433
4925
  }
5434
4926
  }
5435
4927
  this.activeId = (resumedConv ?? this.addConversation(`web-${randomUUID().slice(0, 12)}`, abs, false)).id;
5436
- // 旧项目非活跃 conversation 回收(pi 的 displaceActive 语义:切走后
5437
- // 非 streaming / 无终端 / 未列出的旧会话从内存移除,磁盘 JSONL 可回放恢复)。
5438
4928
  // eslint-disable-next-line unicorn/no-useless-spread -- snapshot: handlers may unsubscribe mid-emit
5439
4929
  for (const [id, c] of [...this.convs]) {
5440
4930
  if (id === this.activeId)
@@ -5445,7 +4935,6 @@ export class DshClientSession {
5445
4935
  continue;
5446
4936
  if (c.isStreaming)
5447
4937
  continue;
5448
- // 只看“用过”的存活终端:没动过的空 shell 不阻止项目切换时的旧会话回收。\n\t\t\t\tif (c.terminals.countBlockingLive() > 0) continue;
5449
4938
  this.removeConversation(id);
5450
4939
  }
5451
4940
  this.onCwdChanged?.(abs);
@@ -5461,7 +4950,6 @@ export class DshClientSession {
5461
4950
  this.emitConversations();
5462
4951
  void this.pushSessions();
5463
4952
  void this.pushProjects();
5464
- // 文件树跟随新项目(服务端原生 watcher 自动重挂)。
5465
4953
  void this.listFiles(undefined);
5466
4954
  this.pushTerminals();
5467
4955
  this.pushSettings();
@@ -5519,13 +5007,32 @@ export class DshClientSession {
5519
5007
  try {
5520
5008
  await this.runtime.close();
5521
5009
  }
5522
- catch {
5523
- /* 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);
5524
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);
5525
5035
  }
5526
- // -----------------------------------------------------------------------
5527
- // 插件扩展点(与 pi 引擎的 *ForPlugins 对齐)
5528
- // -----------------------------------------------------------------------
5529
5036
  activeConversationId() {
5530
5037
  return this.activeId;
5531
5038
  }
@@ -5577,9 +5084,7 @@ export class DshClientSession {
5577
5084
  isStreaming: false,
5578
5085
  });
5579
5086
  }
5580
- catch {
5581
- // 忽略损坏的会话日志
5582
- }
5087
+ catch { }
5583
5088
  }
5584
5089
  return out;
5585
5090
  }
@@ -5664,10 +5169,6 @@ export class DshClientSession {
5664
5169
  return [{ id: `${this.modelProvider}/${this.model}`, provider: this.modelProvider, vision: this.modelVision }];
5665
5170
  }
5666
5171
  }
5667
- // ---------------------------------------------------------------------------
5668
- // DshAgentService — 服务级:客户端会话管理与引擎分发入口
5669
- // ---------------------------------------------------------------------------
5670
- /** 与 pi 引擎 AgentService 同构的顶层服务(index.ts 按 PI_WEB_ENGINE 选择)。 */
5671
5172
  export class DshAgentService {
5672
5173
  cwd;
5673
5174
  agentDir;
@@ -5735,7 +5236,6 @@ export class DshAgentService {
5735
5236
  service: toServiceInfo(launchOrigin()),
5736
5237
  };
5737
5238
  }
5738
- /** issue #145:跨客户端同会话查重(sessionId 口径,与 pi 引擎同语义)。 */
5739
5239
  findSessionOwner(sessionId, excludeClientId) {
5740
5240
  for (const [clientId, cs] of this.clients) {
5741
5241
  if (clientId === excludeClientId)
@@ -5753,7 +5253,6 @@ export class DshAgentService {
5753
5253
  }
5754
5254
  return null;
5755
5255
  }
5756
- /** issue #145:别处在某 cwd 下正在跑的对话(同项目并行感知用)。 */
5757
5256
  listProjectRunners(cwd, excludeClientId) {
5758
5257
  const out = [];
5759
5258
  for (const [clientId, cs] of this.clients) {
@@ -5764,7 +5263,6 @@ export class DshAgentService {
5764
5263
  }
5765
5264
  return out;
5766
5265
  }
5767
- /** issue #145:别处所有正在跑的对话(左栏 elsewhere 只读感知用)。 */
5768
5266
  listExternalRunning(excludeClientId) {
5769
5267
  const out = [];
5770
5268
  for (const [clientId, cs] of this.clients) {
@@ -5775,7 +5273,6 @@ export class DshAgentService {
5775
5273
  }
5776
5274
  return out;
5777
5275
  }
5778
- /** issue #145:某客户端流式集合变化 → 其他客户端重推 conversations。 */
5779
5276
  pokeExternalRunning(excludeClientId) {
5780
5277
  for (const [clientId, cs] of this.clients) {
5781
5278
  if (clientId === excludeClientId)
@@ -5783,12 +5280,9 @@ export class DshAgentService {
5783
5280
  try {
5784
5281
  cs.refreshExternalRunning();
5785
5282
  }
5786
- catch {
5787
- // 单客户端坏了不影响其他
5788
- }
5283
+ catch { }
5789
5284
  }
5790
5285
  }
5791
- /** issue #145:向除请求方外的所有客户端发一条 notice(并行通告用)。 */
5792
5286
  notifyClientsExcept(excludeClientId, msg) {
5793
5287
  for (const [clientId, cs] of this.clients) {
5794
5288
  if (clientId === excludeClientId)
@@ -5796,9 +5290,7 @@ export class DshAgentService {
5796
5290
  try {
5797
5291
  cs.emitNotice(msg.level, msg.text, msg.textEn);
5798
5292
  }
5799
- catch {
5800
- // 单客户端坏了不影响其他
5801
- }
5293
+ catch { }
5802
5294
  }
5803
5295
  }
5804
5296
  async attach(clientId, send) {
@@ -5814,11 +5306,8 @@ export class DshAgentService {
5814
5306
  if (statSync(saved.lastCwd).isDirectory())
5815
5307
  cwd = saved.lastCwd;
5816
5308
  }
5817
- catch {
5818
- /* gone — fall back to default */
5819
- }
5309
+ catch { }
5820
5310
  }
5821
- // 同步创建(runtime.start() 异步后台进行)——无并发竞态,无需 pending。
5822
5311
  cs = DshClientSession.create(clientId, cwd, this.stateStore, this.dataDir, this.agentDir);
5823
5312
  this.clients.set(clientId, cs);
5824
5313
  this.stateStore.remember(clientId, cwd);
@@ -5839,7 +5328,6 @@ export class DshAgentService {
5839
5328
  cs.pluginBgTasksProvider = this.pluginBgTasksProvider;
5840
5329
  cs.pluginStopBgTask = this.pluginStopBgTask;
5841
5330
  cs.isQuiesced = () => this.quiesced;
5842
- // issue #145 跨客户端感知接线(同会话查重 / 同项目并行 / elsewhere 列表)。
5843
5331
  cs.findSessionOwnerById = (sessionId) => this.findSessionOwner(sessionId, clientId);
5844
5332
  cs.listProjectRunners = (cwd) => this.listProjectRunners(cwd, clientId);
5845
5333
  cs.listExternalRunning = () => this.listExternalRunning(clientId);
@@ -5849,8 +5337,6 @@ export class DshAgentService {
5849
5337
  this.onClientCwdChanged?.(cs.cwd);
5850
5338
  return cs;
5851
5339
  }
5852
- /** Browser UI locale report (hello.locale / set_locale): persist per
5853
- * client; DSH runtime prompts refresh on next run (P2 bilingual). */
5854
5340
  async setLocale(clientId, locale) {
5855
5341
  const cs = this.clients.get(clientId);
5856
5342
  if (cs)
@@ -5860,7 +5346,6 @@ export class DshAgentService {
5860
5346
  return [...new Set([...this.clients.values()].flatMap((cs) => cs.mcpProjectCwds()))];
5861
5347
  }
5862
5348
  applyPluginAgentTools() {
5863
- // 工具桥(#15):插件工具列表变化 → 各客户端运行时重新注册。
5864
5349
  for (const cs of this.clients.values())
5865
5350
  void cs.syncPluginTools();
5866
5351
  }
@@ -5887,22 +5372,14 @@ export class DshAgentService {
5887
5372
  try {
5888
5373
  await cs.dispose();
5889
5374
  }
5890
- catch {
5891
- /* ignore */
5892
- }
5375
+ catch { }
5893
5376
  }
5894
5377
  this.clients.clear();
5895
5378
  }
5896
5379
  getCapabilities() {
5897
5380
  return DEFAULT_DSH_CAPABILITIES;
5898
5381
  }
5899
- /** dsh engine keeps no interrupted-run record — resume is pi-only. */
5900
- recordInterruptedRuns() {
5901
- /* no-op */
5902
- }
5903
- // -----------------------------------------------------------------------
5904
- // 插件扩展点适配层(AAL - Agent Adapter Layer)
5905
- // -----------------------------------------------------------------------
5382
+ recordInterruptedRuns() { }
5906
5383
  pluginClient() {
5907
5384
  let fallback;
5908
5385
  for (const cs of this.clients.values()) {