keel-agent 0.129.0 → 0.130.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 (196) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +12 -16
  3. package/README.zh-CN.md +12 -16
  4. package/README.zh-TW.md +74 -189
  5. package/bin/keel.mjs +295 -55
  6. package/dist/packages/keel/src/adapters/sdk/prompt-render.js +3 -1
  7. package/dist/packages/keel/src/adapters/sdk/session-opener.js +2 -1
  8. package/dist/packages/keel/src/adapters/tools/guarded.js +31 -4
  9. package/dist/packages/keel/src/adapters/tools/patch.js +16 -0
  10. package/dist/packages/keel/src/app/client-assembly.js +43 -24
  11. package/dist/packages/keel/src/app/client-runtime.js +37 -2
  12. package/dist/packages/keel/src/app/connection-init.js +4 -2
  13. package/dist/packages/keel/src/app/conversation-content.js +14 -0
  14. package/dist/packages/keel/src/app/core-engine.js +6 -2
  15. package/dist/packages/keel/src/app/engine-coordination.js +4 -0
  16. package/dist/packages/keel/src/app/engine-elsewhere.js +8 -2
  17. package/dist/packages/keel/src/app/engine-orphans.js +8 -1
  18. package/dist/packages/keel/src/app/engine-sessions.js +26 -22
  19. package/dist/packages/keel/src/app/engine-takeover.js +13 -8
  20. package/dist/packages/keel/src/app/extra-handlers.js +8 -5
  21. package/dist/packages/keel/src/app/host-faces.js +1 -0
  22. package/dist/packages/keel/src/app/host-tool-mounts.js +12 -0
  23. package/dist/packages/keel/src/app/note-delivery.js +2 -2
  24. package/dist/packages/keel/src/app/session-registry.js +3 -1
  25. package/dist/packages/keel/src/app/session-surface.js +2 -1
  26. package/dist/packages/keel/src/app/subagent-model-choice.js +44 -30
  27. package/dist/packages/keel/src/bg-job-notice.js +1 -0
  28. package/dist/packages/keel/src/composer-complete-settings.js +43 -0
  29. package/dist/packages/keel/src/conversation-rows.js +8 -0
  30. package/dist/packages/keel/src/domains/background/handlers.js +1 -0
  31. package/dist/packages/keel/src/domains/bots/chat.js +1 -1
  32. package/dist/packages/keel/src/domains/snapshots/builders.js +4 -0
  33. package/dist/packages/keel/src/domains/turns/turn-runner.js +18 -0
  34. package/dist/packages/keel/src/settings-schema.js +9 -0
  35. package/dist/packages/keel/src/subagent-model-policy.js +49 -0
  36. package/dist/packages/keel/src/subagent-templates-hant.js +3 -3
  37. package/dist/packages/keel/src/subagent-templates.js +6 -6
  38. package/dist/packages/keel/src/tool-catalog.js +9 -0
  39. package/dist/packages/keel/src/tool-names.js +2 -0
  40. package/dist/server/background-task-service.js +61 -22
  41. package/dist/server/bg-tasks/client.js +5 -4
  42. package/dist/server/bg-tasks/registry.js +29 -18
  43. package/dist/server/bot-memory-tool.js +15 -3
  44. package/dist/server/client-state.js +65 -0
  45. package/dist/server/composer-complete-settings.js +1 -0
  46. package/dist/server/composer-complete.js +243 -0
  47. package/dist/server/control-socket.js +13 -1
  48. package/dist/server/conversation-import/engines/agy.js +222 -0
  49. package/dist/server/conversation-import/engines/claude.js +171 -0
  50. package/dist/server/conversation-import/engines/codex.js +178 -0
  51. package/dist/server/conversation-import/engines/dsh.js +240 -0
  52. package/dist/server/conversation-import/engines/opencode.js +160 -0
  53. package/dist/server/conversation-import/index.js +183 -0
  54. package/dist/server/conversation-import/jsonl.js +100 -0
  55. package/dist/server/conversation-import/messages.js +147 -0
  56. package/dist/server/conversation-import/sqlite.js +47 -0
  57. package/dist/server/conversation-import/types.js +8 -0
  58. package/dist/server/conversation-import-routes.js +53 -0
  59. package/dist/server/core-bot-adapter.js +5 -1
  60. package/dist/server/core-plugin-adapter.js +4 -1
  61. package/dist/server/core-settings-adapter.js +19 -9
  62. package/dist/server/custom-cli-routes.js +59 -0
  63. package/dist/server/custom-cli-store.js +134 -0
  64. package/dist/server/delegate-task.js +18 -7
  65. package/dist/server/device-center/bot-chat.js +34 -17
  66. package/dist/server/device-center/bot-creation-tool.js +8 -64
  67. package/dist/server/device-center/bot-drafts.js +24 -0
  68. package/dist/server/device-center/bot-memory.js +101 -12
  69. package/dist/server/device-center/bot-tool-face.js +24 -20
  70. package/dist/server/device-center/local.js +59 -9
  71. package/dist/server/durable/durable-agent-service.js +27 -0
  72. package/dist/server/engine-owner-route.js +43 -0
  73. package/dist/server/files-service.js +10 -6
  74. package/dist/server/index.js +236 -47
  75. package/dist/server/marker-service.js +19 -0
  76. package/dist/server/message-window.js +2 -2
  77. package/dist/server/multi-engine.js +1 -0
  78. package/dist/server/native-cli.js +3 -1
  79. package/dist/server/obs-recall-tool.js +173 -0
  80. package/dist/server/plugin-facilities.js +9 -1
  81. package/dist/server/plugins.js +11 -4
  82. package/dist/server/preset-fields.js +9 -0
  83. package/dist/server/protocol-version.js +1 -1
  84. package/dist/server/remote-ssh-service.js +13 -0
  85. package/dist/server/schedule-agent-tool.js +2 -0
  86. package/dist/server/scheduler-tasks.js +5 -0
  87. package/dist/server/settings-commit.js +2 -0
  88. package/dist/server/settings-service.js +2 -0
  89. package/dist/server/shell-activate.js +118 -1
  90. package/dist/server/slash-commands.js +48 -12
  91. package/dist/server/tool-bridge-host.js +5 -0
  92. package/dist/server/universal/acp/acp-driver.js +96 -22
  93. package/dist/server/universal/drivers/claude-acp-driver.js +3 -0
  94. package/dist/server/universal/internal-mcp.js +7 -3
  95. package/dist/server/universal/seat-takeover.js +145 -0
  96. package/dist/server/universal/subagent-slash.js +54 -0
  97. package/dist/server/universal/universal-service.js +28 -0
  98. package/dist/server/universal/universal-session.js +242 -88
  99. package/dist/server/update-service.js +12 -8
  100. package/package.json +20 -15
  101. package/plugins/catalog.json +128 -90
  102. package/plugins/superagent/manifest.json +2 -2
  103. package/themes/flow-zurich.css +2 -2
  104. package/web/dist/.build-assets.json +1 -1
  105. package/web/dist/assets/ApprovalRulesTab-QmzsJItk.js +1 -0
  106. package/web/dist/assets/BgTasksModal-COLmy-4E.js +1 -0
  107. package/web/dist/assets/{BotDraftSettings-BcXWHOSd.js → BotDraftSettings-nP4g1fge.js} +1 -1
  108. package/web/dist/assets/BottomDock-BZXSlOom.js +1 -0
  109. package/web/dist/assets/{CanvasStudio-KZ0MmCL7.js → CanvasStudio-BL1BWXpp.js} +3 -3
  110. package/web/dist/assets/CommunityThemesSection-BLd_oox1.js +1 -0
  111. package/web/dist/assets/DesktopAppSettings-Dn18vrLK.js +1 -0
  112. package/web/dist/assets/DeviceCenter-DxoAwlTt.js +3 -0
  113. package/web/dist/assets/{DeviceExecutionSettings-VONJ-2Ns.js → DeviceExecutionSettings-B1mya5TJ.js} +1 -1
  114. package/web/dist/assets/{DeviceGroups-DUq2YZ8O.js → DeviceGroups-C-xwewog.js} +1 -1
  115. package/web/dist/assets/DisplayTab-DRGFt78v.js +1 -0
  116. package/web/dist/assets/{FieldRow-CHxkNX2z.js → FieldRow-DHxAXFtL.js} +1 -1
  117. package/web/dist/assets/FilePreview-DcyP9paf.js +2 -0
  118. package/web/dist/assets/GlobalSearchModal-Cs6hB5KO.js +1 -0
  119. package/web/dist/assets/GroupConversation-B7NfTB89.js +9 -0
  120. package/web/dist/assets/{GroupWorkItems-B-wweVMR.js → GroupWorkItems-CSUjIxDT.js} +1 -1
  121. package/web/dist/assets/{HintTip-lXOOr9p3.js → HintTip-CKxIx9CD.js} +1 -1
  122. package/web/dist/assets/LayoutTab-9popvCLQ.js +1 -0
  123. package/web/dist/assets/McpServersPanel-dRwq7Wjq.js +1 -0
  124. package/web/dist/assets/ModelConfigModal-C0CXhSl0.js +2 -0
  125. package/web/dist/assets/{ModelsTab-CMSi1MT-.js → ModelsTab-CyG2rYeY.js} +1 -1
  126. package/web/dist/assets/{NativeCliPanel-DotHqKv_.js → NativeCliPanel-mlB4dw42.js} +2 -2
  127. package/web/dist/assets/{PiSetupModal-Dd0w2Koi.js → PiSetupModal-D7PjlTVx.js} +1 -1
  128. package/web/dist/assets/PluginsTab-0s0qClcC.js +2 -0
  129. package/web/dist/assets/PresetShareModal-Dw4t6p6s.js +11 -0
  130. package/web/dist/assets/{PresetsTab-BnFFB24b.js → PresetsTab-DdXvpc2d.js} +1 -1
  131. package/web/dist/assets/{PromptHistoryTab-CNUzjdJl.js → PromptHistoryTab-DirJHaH6.js} +1 -1
  132. package/web/dist/assets/{PromptOverrideEditor-DZOQdWy3.js → PromptOverrideEditor-ldLRCp0e.js} +1 -1
  133. package/web/dist/assets/PromptTab-SV01BMC0.js +11 -0
  134. package/web/dist/assets/{ProviderOAuthControls-BSqBp-QA.js → ProviderOAuthControls-Clyn3fnw.js} +1 -1
  135. package/web/dist/assets/QuestionTab-Bi1NYK5U.js +1 -0
  136. package/web/dist/assets/{QuickAskSettings-DICkDFsE.js → QuickAskSettings-dzG95DYl.js} +2 -2
  137. package/web/dist/assets/QuickTab-C8bknYDU.js +5 -0
  138. package/web/dist/assets/{ReviewTab-DRMQoVjL.js → ReviewTab-D9lbphZe.js} +1 -1
  139. package/web/dist/assets/SCMPanel-BfrlvHxI.js +7 -0
  140. package/web/dist/assets/SchedulerPanel-DDDWOSsw.js +2 -0
  141. package/web/dist/assets/SettingsModal-BqzfvDlI.js +2 -0
  142. package/web/dist/assets/SkillsTab-D8C-kghN.js +1 -0
  143. package/web/dist/assets/{SoundTab-BR6gVIOZ.js → SoundTab-CXcWmvkX.js} +1 -1
  144. package/web/dist/assets/{SubagentTemplatesTab-BonIA-lD.js → SubagentTemplatesTab-KjPMnYN4.js} +1 -1
  145. package/web/dist/assets/{TermXterm-EHBR2avX.js → TermXterm-B7klZwgq.js} +1 -1
  146. package/web/dist/assets/TerminalDockControls-lbPY2V5U.js +1 -0
  147. package/web/dist/assets/TerminalPanel-ERotdy8I.js +1 -0
  148. package/web/dist/assets/{ThemeMarketModal-CGaoF3NZ.js → ThemeMarketModal-BZJZ7doZ.js} +1 -1
  149. package/web/dist/assets/{ToggleRow-DvouPLLK.js → ToggleRow-irywH1NJ.js} +1 -1
  150. package/web/dist/assets/ToolBridgeSettings-CG1HleEp.js +1 -0
  151. package/web/dist/assets/ToolsTab-_OJA76Sw.js +4 -0
  152. package/web/dist/assets/TuiOverlayModal-CDqXNwW-.js +1 -0
  153. package/web/dist/assets/{VisionTab-HDlpKVeq.js → VisionTab-B580SGpU.js} +1 -1
  154. package/web/dist/assets/{api-client-J4QrjRw8.js → api-client-B2iSv9kK.js} +1 -1
  155. package/web/dist/assets/{canvas-client-BsNp2mr3.js → canvas-client-DRiwRbfy.js} +1 -1
  156. package/web/dist/assets/{desktop-BcTQigaN.js → desktop-DRyQQXnx.js} +1 -1
  157. package/web/dist/assets/host-icon-DMg5PU4C.js +1 -0
  158. package/web/dist/assets/i18n-D2DJ-AHq.js +225 -0
  159. package/web/dist/assets/index-CP0EEOA0.js +423 -0
  160. package/web/dist/assets/index-Ds_pheLF.css +1 -0
  161. package/web/dist/assets/plugin-host-VU6JOOPu.js +1 -0
  162. package/web/dist/assets/{theme-7DF4yEv3.js → theme-ZteIcUdF.js} +1 -1
  163. package/web/dist/assets/{tool-inventory-D2UKR8Ja.js → tool-inventory-DnzKVLYq.js} +1 -1
  164. package/web/dist/index.html +10 -9
  165. package/web/dist/sw.js +1 -1
  166. package/web/dist/assets/ApprovalRulesTab-BlcxVgms.js +0 -1
  167. package/web/dist/assets/BgTasksModal-wL4p27CE.js +0 -1
  168. package/web/dist/assets/BottomDock-CUnQsIDW.js +0 -1
  169. package/web/dist/assets/CommunityThemesSection-BAcS2VQK.js +0 -1
  170. package/web/dist/assets/DesktopAppSettings-BeikxSqV.js +0 -1
  171. package/web/dist/assets/DeviceCenter-BWKRVpWt.js +0 -3
  172. package/web/dist/assets/DisplayTab-B5x4nQh5.js +0 -1
  173. package/web/dist/assets/FilePreview-0IDddE5F.js +0 -2
  174. package/web/dist/assets/GlobalSearchModal-BaXs1zRG.js +0 -1
  175. package/web/dist/assets/GroupConversation-EaMawnF-.js +0 -9
  176. package/web/dist/assets/LayoutTab-8N74U83U.js +0 -1
  177. package/web/dist/assets/McpServersPanel-BAhwoE87.js +0 -1
  178. package/web/dist/assets/ModelConfigModal-i3m9glTy.js +0 -2
  179. package/web/dist/assets/PluginsTab-DL8j6LEI.js +0 -2
  180. package/web/dist/assets/PresetShareModal-BGhCpas6.js +0 -11
  181. package/web/dist/assets/PromptTab-DPYuPM07.js +0 -11
  182. package/web/dist/assets/QuestionTab-C7oF1MYO.js +0 -1
  183. package/web/dist/assets/QuickTab-DDaxH3XV.js +0 -1
  184. package/web/dist/assets/SCMPanel-CfOxsL8H.js +0 -7
  185. package/web/dist/assets/SchedulerPanel-BLaVSPXj.js +0 -2
  186. package/web/dist/assets/SettingsModal-6jgsnLF0.js +0 -2
  187. package/web/dist/assets/SkillsTab-C5XuZ4a-.js +0 -1
  188. package/web/dist/assets/TerminalDockControls-Dn51FqM9.js +0 -1
  189. package/web/dist/assets/TerminalPanel-D2Bpt0f_.js +0 -1
  190. package/web/dist/assets/ToolBridgeSettings-8vlLWWvW.js +0 -1
  191. package/web/dist/assets/ToolsTab-Byx7wDZe.js +0 -4
  192. package/web/dist/assets/TuiOverlayModal-Bj6jyAvr.js +0 -1
  193. package/web/dist/assets/i18n-CaWsBwiA.js +0 -225
  194. package/web/dist/assets/index-2jVkYOYt.css +0 -1
  195. package/web/dist/assets/index-KuttBaFw.js +0 -420
  196. package/web/dist/assets/plugin-host-C2Iki5ig.js +0 -1
@@ -145,9 +145,18 @@ export function assembleClient(ctx) {
145
145
  onToolEvent: (ev) => ctx.onToolEvent?.(ev),
146
146
  onRunEvent: (ev) => ctx.onRunEvent?.(ev),
147
147
  });
148
+ // 行内暗号执行面:宿主给了就每轮收口递一次「最后一条 assistant 原文」。
149
+ // 在这之前它只把说明塞进提示词、没人执行——教了却做不到,比不教更糟。
150
+ const markerPort = options.markers?.({
151
+ clientId,
152
+ emit: deliver,
153
+ isDisposed: () => ctx.runtimes.get(clientId) !== runtime,
154
+ lang: () => ctx.langOf(clientId),
155
+ });
148
156
  runtime = new ClientRuntime({
149
157
  clientId,
150
158
  cwd,
159
+ onDispose: () => markerPort?.dispose?.(),
151
160
  workspaceRoots: cwd ? stateStore.getWorkspaceRoots(clientId, cwd) : [],
152
161
  clock: systemClock,
153
162
  transport,
@@ -158,6 +167,11 @@ export function assembleClient(ctx) {
158
167
  ctx.notifyExternalRunning(runtime.clientId);
159
168
  },
160
169
  onTurnSettled: (conversationId, outcome) => {
170
+ // 暗号(rename / notify)在这一轮最后一条 assistant 原文上执行;文本惰性取。
171
+ markerPort?.onTurnSettled(conversationId, () => {
172
+ const opened = sessions.get(conversationId);
173
+ return opened?.session.getLastAssistantText?.() ?? "";
174
+ });
161
175
  subagents?.settle(conversationId, outcome === "done" ? "done" : outcome === "aborted" ? "stopped" : "failed");
162
176
  goalPort?.onTurnSettled?.(conversationId, outcome);
163
177
  runtime.pushConversations();
@@ -250,31 +264,36 @@ export function assembleClient(ctx) {
250
264
  findSessionOwner: (target) => ctx.findSessionOwner?.(target, runtime.clientId),
251
265
  ...(ctx.takeOverElsewhere ? { takeOverElsewhere: (owner) => ctx.takeOverElsewhere(clientId, owner) } : {}),
252
266
  checkParallelWork: (conv) => ctx.checkParallelWork?.(runtime.clientId, conv),
253
- viewOf: (conv) => ({
254
- ...conversationViewFromSession(conv, sessions.get(conv.id)?.session),
255
- planMode: chatModes.planModeOf(conv.id),
256
- delegateMode: chatModes.delegateModeOf(conv.id),
257
- delegateConvId: chatModes.delegateConvIdOf(conv.id),
258
- ...conversationPresetViewOf({
259
- conversationId: conv.id,
260
- queued: conv.queues.total(),
261
- session: sessions.get(conv.id)?.session,
262
- settings: stateStore.getSettingsSnapshot(runtime.clientId),
263
- presets,
264
- chatModes,
265
- lang: ctx.langOf(runtime.clientId),
266
- }),
267
- pendingApprovals: approvalWaiter.pendingForSnapshot(conv.id),
268
- pendingQuestion: askWaiter.pendingForSnapshot(conv.id)[0]
269
- ? {
270
- id: askWaiter.pendingForSnapshot(conv.id)[0].id,
271
- questions: askWaiter.pendingForSnapshot(conv.id)[0].questions,
267
+ viewOf: (conv) => {
268
+ const actionSuggestions = markerPort?.actionsOf?.(conv.id);
269
+ return {
270
+ ...conversationViewFromSession(conv, sessions.get(conv.id)?.session),
271
+ // `[[action:suggest:…]]` 的产物:与正文同源,每次出帧都要带上(快照整体替换 state)。
272
+ ...(actionSuggestions?.length ? { actionSuggestions } : {}),
273
+ planMode: chatModes.planModeOf(conv.id),
274
+ delegateMode: chatModes.delegateModeOf(conv.id),
275
+ delegateConvId: chatModes.delegateConvIdOf(conv.id),
276
+ ...conversationPresetViewOf({
272
277
  conversationId: conv.id,
273
- conversationTitle: conv.meta.title,
274
- }
275
- : null,
276
- bot: conv.meta.botId ? { id: conv.meta.botId, name: conv.meta.botName ?? conv.meta.botId } : null,
277
- }),
278
+ queued: conv.queues.total(),
279
+ session: sessions.get(conv.id)?.session,
280
+ settings: stateStore.getSettingsSnapshot(runtime.clientId),
281
+ presets,
282
+ chatModes,
283
+ lang: ctx.langOf(runtime.clientId),
284
+ }),
285
+ pendingApprovals: approvalWaiter.pendingForSnapshot(conv.id),
286
+ pendingQuestion: askWaiter.pendingForSnapshot(conv.id)[0]
287
+ ? {
288
+ id: askWaiter.pendingForSnapshot(conv.id)[0].id,
289
+ questions: askWaiter.pendingForSnapshot(conv.id)[0].questions,
290
+ conversationId: conv.id,
291
+ conversationTitle: conv.meta.title,
292
+ }
293
+ : null,
294
+ bot: conv.meta.botId ? { id: conv.meta.botId, name: conv.meta.botName ?? conv.meta.botId } : null,
295
+ };
296
+ },
278
297
  env: () => ({
279
298
  settingsVersion: stateStore.getSettingsVersion(),
280
299
  piConfigured: faces.uiBridge?.probe().piConfigured ?? false,
@@ -430,8 +430,42 @@ export class ClientRuntime {
430
430
  if (!sessions)
431
431
  throw new Error("core: session registry is not wired");
432
432
  const opened = await sessions.ensure(conv);
433
- if (structured)
434
- return await deliverStructuredNote(opened.session, text, structured);
433
+ if (structured) {
434
+ if (!structured.triggerTurn)
435
+ return await deliverStructuredNote(opened.session, text, structured);
436
+ if (typeof opened.session.sendCustomMessage !== "function") {
437
+ throw new Error("core: this engine cannot append custom messages");
438
+ }
439
+ // 压缩期间只落盘不触发轮次,避免 SDK 拒收 `compaction is in progress`。
440
+ if (conv.compaction) {
441
+ return await deliverStructuredNote(opened.session, text, { ...structured, triggerTurn: false });
442
+ }
443
+ // 正在跑一轮时直接走 steer 插队;空闲态走 TurnRunner 统一管理回合相位与 streaming。
444
+ if (conv.phase === "running") {
445
+ return await deliverStructuredNote(opened.session, text, structured);
446
+ }
447
+ this.turnInFlight.add(conv.id);
448
+ this.pushConversations();
449
+ try {
450
+ await this.turns.startCustom(conv, () => deliverStructuredNote(opened.session, text, structured));
451
+ }
452
+ catch (error) {
453
+ if (isCompactionRejection(error)) {
454
+ await deliverStructuredNote(opened.session, text, { ...structured, triggerTurn: false });
455
+ }
456
+ else if (this.options.onTurnError) {
457
+ this.options.onTurnError(conv.id, error);
458
+ }
459
+ else {
460
+ console.error("[core] structured turn failed:", error);
461
+ }
462
+ }
463
+ finally {
464
+ this.turnInFlight.delete(conv.id);
465
+ flushConversationAndPeer(this, conv, this.options.findRuntime);
466
+ }
467
+ return;
468
+ }
435
469
  if (conv.phase === "running")
436
470
  await this.turns.steer(conv, opened.session, text);
437
471
  else
@@ -449,6 +483,7 @@ export class ClientRuntime {
449
483
  this.options.plugins?.()?.dispose?.();
450
484
  // UI 桥的挂起表(页面 / 手机 / dialog / overlay):断开时全部结算,不留永不 settle 的 Promise。
451
485
  this.assembly?.dispose();
486
+ this.options.onDispose?.();
452
487
  this.options.sessions?.closeAll();
453
488
  for (const conv of this.registry.list()) {
454
489
  if (conv.acceptsTurns)
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { resolve } from "node:path";
3
3
  import { DEFAULT_GOAL_PREFS, goalStatusOfPrefs } from "../domains/goals/handlers.js";
4
+ import { permissionFrame } from "./extra-handlers.js";
4
5
  /**
5
6
  * 一条连接建好之后要做的**三件事**(老实现 `AgentService.attach()` 尾部那一段的对应物):
6
7
  *
@@ -138,7 +139,7 @@ async function openLeadingConversation(runtime, sessions) {
138
139
  * | 9 | `listProviderKeys()` | ★ `dispatch.listProviderKeys()` |
139
140
  * | 10 | `listProviderOAuthFlows()` | ★ `dispatch.listProviderOAuthFlows()` |
140
141
  * | 11 | `pushDefaultModel()` | ★ `runtime.optionalFrames().pushDefaultModel()`(★ 键星标 +「设为全局默认」按钮态)|
141
- * | 12 | `refreshAgentPresets()` + `refreshPermission()` | ★ `dispatch.refreshAgentPresets()`;权限预设帧没有只读/重推的 handler(只有 `setDefaultPermissionPreset` 会发),不编一条 |
142
+ * | 12 | `refreshAgentPresets()` + `refreshPermission()` | ★ `dispatch.refreshAgentPresets()` + `emit(permissionFrame(...))`(`dsh_permission` 无拉取型客户端消息,连接期与重连统一由这里推送) |
142
143
  * | 13 | `pushTerminals()` | 无对应帧(内核没有 `terminal_list` 生产者;终端按请求出帧) |
143
144
  *
144
145
  * 帧顺序照老实现(会话 → 目标 → 设置 → 后台 → 供应商 → 预设):设置帧里会读当前审批策略
@@ -161,8 +162,9 @@ function pushConnectFrames(input, dispatch) {
161
162
  }
162
163
  // 11 全局默认模型(模型选择器的 ★ 标记 + 「设为全局默认」按钮态)。
163
164
  runtime.optionalFrames()?.pushDefaultModel();
164
- // 12 智能体预设目录(`dsh_presets`):缺省预设是客户端徽标的源。
165
+ // 12 智能体预设目录(`dsh_presets`)与权限预设目录(`dsh_permission`):前端权限开关与默认权限设置依赖连接期下发。
165
166
  void dispatch.refreshAgentPresets?.();
167
+ emit(permissionFrame(stateStore.getSettingsSnapshot(clientId).defaultPermissionPreset));
166
168
  // 13 历史会话列表(sessions 帧):连接期推一次,让历史面板首屏有内容。
167
169
  void runtime.optionalFrames()?.refreshSessions();
168
170
  // 14 待答问卷队列(question_queue):连接期推一次,恢复待处理问卷。
@@ -0,0 +1,14 @@
1
+ /** 已接上的会话里真正的消息条数(没接上 = 0;与 `session-surface` 的 `messageCount` 同口径)。 */
2
+ export function openedMessageCount(sessions, conversationId) {
3
+ const messages = sessions?.get(conversationId)?.session.messages;
4
+ return Array.isArray(messages) ? messages.length : 0;
5
+ }
6
+ /**
7
+ * 对话里有没有真东西:会话**接上了**就只看消息条数(转录文件存在也可能是刚开出来的空壳);
8
+ * 没接上(已退役 / 只留注册表行)只能凭转录路径判断 —— 那是「落过盘的历史对话」,别当空白。
9
+ */
10
+ export function conversationHasContent(sessions, conversation) {
11
+ if (sessions?.get(conversation.id))
12
+ return openedMessageCount(sessions, conversation.id) > 0;
13
+ return conversation.meta.sessionFile !== undefined;
14
+ }
@@ -131,6 +131,7 @@ export class CoreEngine {
131
131
  connectFrames: this.connectFrames,
132
132
  clearOffline: (id) => this.clearOffline(id),
133
133
  bindSender: (id, s) => this.bindSender(id, s),
134
+ ...(this.options.onClientAdopted ? { onClientAdopted: this.options.onClientAdopted } : {}),
134
135
  });
135
136
  this.notifyExternalRunning();
136
137
  sendGlobalInteractionsTo(this.globalInteractionsDeps(), clientId);
@@ -182,7 +183,7 @@ export class CoreEngine {
182
183
  subagentsRegistry: this.subagentsRegistry,
183
184
  findSessionOwner: (target, excludeClientId) => this.findSessionOwner(target, excludeClientId),
184
185
  // 别处开着、没在跑:把那条对话过户到本客户端再打开(跨客户端单一写者,issue #567)。
185
- takeOverElsewhere: (targetClientId, owner) => this.takeOverConversation(targetClientId, owner.clientId, owner.conversationId),
186
+ takeOverElsewhere: (targetClientId, owner) => this.takeOverConversation(targetClientId, owner.clientId, owner.conversationId).then(() => { }),
186
187
  checkParallelWork: (clientId, conv) => this.checkParallelWork(clientId, conv),
187
188
  });
188
189
  this.runtimes.set(clientId, runtime);
@@ -271,6 +272,9 @@ export class CoreEngine {
271
272
  get(clientId) {
272
273
  return this.runtimes.get(clientId)?.handlers();
273
274
  }
275
+ holdsConversation(clientId, convId) {
276
+ return Boolean(this.runtimes.get(clientId)?.registry.has(convId));
277
+ }
274
278
  async disposeAll() {
275
279
  // 先记账再拆:老实现同口径(`disposeAll()` 里第一件事就是 `recordInterruptedRuns()`),
276
280
  // 否则正在跑的对话在拆的时候还「跑着」,记录却已经写不进了。
@@ -424,7 +428,7 @@ export class CoreEngine {
424
428
  clearOfflineRows(clientId, this.offlineSince, this.offlineTimers);
425
429
  }
426
430
  async takeOverConversation(targetId, ownerId, convId) {
427
- await executeTakeOverConversation(this.takeoverDeps, targetId, ownerId, convId);
431
+ return executeTakeOverConversation(this.takeoverDeps, targetId, ownerId, convId);
428
432
  }
429
433
  async dismissConversation(clientId, msg) {
430
434
  return executeDismissConversation({
@@ -81,6 +81,10 @@ export async function chatFromScheduler(deps, task) {
81
81
  const cs = await deps.attach(clientId, () => { });
82
82
  if (cs.cwd !== cwd)
83
83
  await cs.setCwd(cwd);
84
+ const botId = String(task.botId ?? "").trim();
85
+ if (botId) {
86
+ await cs.newChat(undefined, false, undefined, true, botId);
87
+ }
84
88
  const model = String(task.model ?? "").trim();
85
89
  if (model) {
86
90
  try {
@@ -1,5 +1,7 @@
1
1
  import { resolve } from "node:path";
2
2
  import { isOrphanAdoptionExcludedClientId, isPseudoClientId, isUnattendedClientId } from "../client-id-utils.js";
3
+ import { isDefaultConversationTitle } from "../conversation-rows.js";
4
+ import { conversationHasContent } from "./conversation-content.js";
3
5
  import { findMostRecentSessionFileFast } from "../session-parser.js";
4
6
  import { resolveWorkspaceSessionDir } from "../remote-workspace.js";
5
7
  /**
@@ -43,8 +45,12 @@ export function listExternalRunning(deps, excludeClientId, offlineTtlMs) {
43
45
  if (isSubagent && (!conv.meta.parentId || !parentIds.has(conv.meta.parentId)))
44
46
  continue;
45
47
  const hasQ = deps.hasQuestionOf ? deps.hasQuestionOf(clientId, conv.id) : false;
46
- // 还没落盘且非流式、无问卷、默认标题的纯空白新对话不列入别处
47
- if (!streaming && !hasQ && conv.meta.title === "新对话" && !conv.meta.sessionFile) {
48
+ // 空白对话(默认标题 + 一条消息都没有)不列入别处:`sessionFile` 只是开会话时预定的路径,
49
+ // 空白新对话也带着它(`model_change` 就落盘),拿它当「有内容」会让每个关掉的页面留一行幽灵行。
50
+ if (!streaming &&
51
+ !hasQ &&
52
+ isDefaultConversationTitle(conv.meta.title) &&
53
+ !conversationHasContent(runtime.sessions, conv)) {
48
54
  continue;
49
55
  }
50
56
  const activity = conv.meta.lastActiveAt || 0;
@@ -1,5 +1,7 @@
1
1
  import { pickAdoptableOrphan } from "../orphan-manager.js";
2
2
  import { isOrphanAdoptionExcludedClientId } from "../client-id-utils.js";
3
+ import { isDefaultConversationTitle } from "../conversation-rows.js";
4
+ import { conversationHasContent } from "./conversation-content.js";
3
5
  function moveMapKey(map, from, to) {
4
6
  const value = map.get(from);
5
7
  if (value === undefined)
@@ -16,6 +18,7 @@ export function adoptOrphanRuntime(deps) {
16
18
  moveMapKey(deps.approvalWaiters, orphan.oldId, clientId);
17
19
  deps.runtimes.set(clientId, orphan.runtime);
18
20
  orphan.runtime.updateClientId(clientId);
21
+ deps.onClientAdopted?.(orphan.oldId, clientId);
19
22
  deps.bindSender(clientId, send);
20
23
  moveMapKey(deps.connectFrames, orphan.oldId, clientId);
21
24
  send({
@@ -46,7 +49,11 @@ export function findAdoptableOrphan(runtimes, sockets, excludeClientId) {
46
49
  if (conv.phase === "running")
47
50
  streaming++;
48
51
  if (conv.meta.kind !== "subagent") {
49
- if (conv.meta.sessionFile || conv.phase === "running" || conv.meta.title !== "新对话") {
52
+ // 有内容才值得认领:空白新对话也带着 `sessionFile`(开会话就落盘 model_change),
53
+ // 拿它当「有工作会话要恢复」会让新页面抢回一个空壳并弹一句假的「已恢复」提示。
54
+ if (conv.phase === "running" ||
55
+ !isDefaultConversationTitle(conv.meta.title) ||
56
+ conversationHasContent(runtime.sessions, conv)) {
50
57
  adoptable = true;
51
58
  }
52
59
  }
@@ -14,6 +14,7 @@ import { subscribePluginSessionEvents } from "./plugin-engine-hooks.js";
14
14
  import { applyQueueUpdateEvent, applySessionCompactionEvent } from "./session-compaction.js";
15
15
  import { createToolGating } from "./tool-gating.js";
16
16
  import { SessionRegistry } from "./session-registry.js";
17
+ import { resolveWorkspaceSessionDir } from "../remote-workspace.js";
17
18
  import { restoreTranscriptTitle } from "./host-frames.js";
18
19
  import { sessionHostToolsOf } from "./session-tool-mounts.js";
19
20
  import { formatPlanSummary } from "../domains/goals/plan-store.js";
@@ -80,7 +81,10 @@ export function createEngineSessionRegistry(deps) {
80
81
  const botFaceOf = (conv) => {
81
82
  const current = conv.meta.clientId;
82
83
  const targetClientId = typeof current === "string" && current.length > 0 ? current : deps.clientId;
83
- return deps.bots?.()?.toolFace?.({ clientId: targetClientId });
84
+ return deps.bots?.()?.toolFace?.({
85
+ clientId: targetClientId,
86
+ ...(conv.meta.kind === "bot" && conv.meta.botId ? { botId: conv.meta.botId } : {}),
87
+ });
84
88
  };
85
89
  /**
86
90
  * Bot 执行的活动工具集 = 白名单 ∩ 全部工具(老 `applyToolGating` 的 Bot 早返回)。
@@ -203,6 +207,7 @@ export function createEngineSessionRegistry(deps) {
203
207
  });
204
208
  const created = (registry = new SessionRegistry({
205
209
  agentDir: deps.agentDir,
210
+ dataDir: deps.stateStore.dataDir,
206
211
  // 扩展的 UI 上下文:子代理用 headless(dialog 立刻 null、不等浏览器),真对话用浏览器那份。
207
212
  uiContextOf: (conv) => deps.getFaces().uiBridge?.uiContextFor(conv.meta.kind === "subagent" ? undefined : conv.id),
208
213
  /**
@@ -244,7 +249,7 @@ export function createEngineSessionRegistry(deps) {
244
249
  }
245
250
  })(),
246
251
  ...createGuardedBuiltinTools({
247
- cwd: deps.cwd,
252
+ cwd: resolveWorkspaceSessionDir(deps.stateStore.dataDir, conv.meta.cwd),
248
253
  ...(deps.remoteOpsOf ? { remoteOpsOf: deps.remoteOpsOf } : {}),
249
254
  getLang: () => deps.langOf(deps.clientId),
250
255
  getRules: getApprovalRules,
@@ -360,6 +365,9 @@ export function createEngineSessionRegistry(deps) {
360
365
  if (release)
361
366
  mcpReleases.set(conv.id, release);
362
367
  await deps.mcpProjects?.()?.prepare(conv.meta.cwd);
368
+ if (conv.meta.kind === "bot" && conv.meta.botId) {
369
+ await deps.bots?.()?.prepareChat?.(conv.meta.botId);
370
+ }
363
371
  },
364
372
  onOpened: (conv, opened) => {
365
373
  const runtime = deps.getRuntime();
@@ -445,37 +453,33 @@ export function createEngineSessionRegistry(deps) {
445
453
  })());
446
454
  },
447
455
  onClosed: (conversationId) => {
448
- mcpReleases.get(conversationId)?.();
449
- mcpReleases.delete(conversationId);
450
- jitUnsubscribers.get(conversationId)?.();
451
- jitUnsubscribers.delete(conversationId);
452
- unsubscribers.get(conversationId)?.();
453
- unsubscribers.delete(conversationId);
456
+ for (const m of [mcpReleases, jitUnsubscribers, unsubscribers]) {
457
+ m.get(conversationId)?.();
458
+ m.delete(conversationId);
459
+ }
454
460
  deps.pluginTools.forget(deps.clientId, conversationId);
455
461
  },
456
462
  onTransferred: (other, sourceId, targetId) => {
457
463
  const src = registryResources.get(other);
458
464
  if (!src)
459
465
  return;
460
- const moveEntry = (from, to) => {
466
+ for (const [from, to] of [
467
+ [src.mcpReleases, mcpReleases],
468
+ [src.jitUnsubscribers, jitUnsubscribers],
469
+ [src.unsubscribers, unsubscribers],
470
+ ]) {
461
471
  const fn = from.get(sourceId);
462
- if (!fn)
463
- return;
464
- from.delete(sourceId);
465
- to.set(targetId, fn);
466
- };
467
- moveEntry(src.mcpReleases, mcpReleases);
468
- moveEntry(src.jitUnsubscribers, jitUnsubscribers);
469
- moveEntry(src.unsubscribers, unsubscribers);
472
+ if (fn) {
473
+ from.delete(sourceId);
474
+ to.set(targetId, fn);
475
+ }
476
+ }
470
477
  src.forgetPluginTools(sourceId);
471
478
  },
472
479
  onSessionFile: (conv, sessionFile) => {
473
- // `bindSessionFile` 返回被顶掉的对话(#1040):同一份转录换主人时,旧对话的
474
- // `sessionFile` 会被摘掉——不复一声,用户看到的就是“一条对话裂成两条”。
480
+ // `bindSessionFile` 返回被顶掉的对话(#1040):同转录换主人时摘掉旧 sessionFile 并通知用户。
475
481
  const displaced = deps.getRuntime().registry.bindSessionFile(conv.id, sessionFile);
476
- if (!displaced)
477
- return;
478
- const previous = deps.getRuntime().registry.get(displaced);
482
+ const previous = displaced ? deps.getRuntime().registry.get(displaced) : null;
479
483
  if (!previous || deps.transport.isClosed())
480
484
  return;
481
485
  deps.transport.send({
@@ -13,17 +13,20 @@ function isSubagentDescendant(candidate, rootId, all) {
13
13
  /**
14
14
  * 跨客户端会话过户:将某客户端持有的主会话(连同其在跑的子代理)事务性移交给目标客户端。
15
15
  * 顺序:准备 → 插入 → 提交移除 → 激活目标。出错时完整回退来源持有权。
16
+ *
17
+ * 返回 `true` 只在「这条对话真的落到目标手里」时成立:调用方(组合根)据此决定要不要把
18
+ * 目标页面切到这台引擎 —— 失败/回滚时切过去就把用户丢到另一台引擎的空白对话里。
16
19
  */
17
20
  export async function executeTakeOverConversation(deps, targetId, ownerId, convId) {
18
21
  const target = deps.runtimes.get(targetId);
19
22
  if (!target)
20
- return;
23
+ return false;
21
24
  const fail = (text, textEn) => {
22
25
  deps.sendNotice(targetId, { type: "notice", level: "warning", text, textEn });
23
26
  };
24
27
  if (!ownerId || !convId) {
25
28
  fail("过户目标不明确(缺 owner/id),请重试", "Takeover target unclear (missing owner/id), please retry.");
26
- return;
29
+ return false;
27
30
  }
28
31
  if (ownerId === targetId) {
29
32
  try {
@@ -32,11 +35,11 @@ export async function executeTakeOverConversation(deps, targetId, ownerId, convI
32
35
  target.publisher.flush({ forceFull: true });
33
36
  }
34
37
  catch { }
35
- return;
38
+ return true;
36
39
  }
37
40
  if (ownerId.startsWith("scheduler:")) {
38
41
  fail("定时任务会话不支持过户 —— 报告会自动落回绑定的对话,可在后台任务面板查看进度", "Scheduler sessions cannot be taken over — reports are saved to the bound conversation automatically; check progress in the Background Tasks panel.");
39
- return;
42
+ return false;
40
43
  }
41
44
  const flightKey = `${ownerId}:${convId}`;
42
45
  if (deps.takeoverFlights.has(flightKey)) {
@@ -46,7 +49,7 @@ export async function executeTakeOverConversation(deps, targetId, ownerId, convI
46
49
  text: "这条对话正在接管中,请稍候(不要重复点击)。",
47
50
  textEn: "This conversation is already being taken over; please wait (do not click again).",
48
51
  });
49
- return;
52
+ return false;
50
53
  }
51
54
  deps.takeoverFlights.set(flightKey, Promise.resolve());
52
55
  try {
@@ -54,17 +57,17 @@ export async function executeTakeOverConversation(deps, targetId, ownerId, convI
54
57
  if (!source) {
55
58
  fail("对方会话已不存在,可从历史对话里直接打开", "The source session is gone; reopen it from History instead.");
56
59
  deps.notifyExternalRunning();
57
- return;
60
+ return false;
58
61
  }
59
62
  const conv = source.registry.get(convId);
60
63
  if (!conv) {
61
64
  fail("对方已经没有这条对话(刚结束或被关闭),左栏稍后自动刷新", "That conversation is gone on the other side; the list refreshes shortly.");
62
65
  deps.notifyExternalRunning();
63
- return;
66
+ return false;
64
67
  }
65
68
  if (conv.meta.kind === "subagent") {
66
69
  fail("只能过户主对话(子代理随主对话一起搬)", "Only main conversations can be taken over (subagents move with their parent).");
67
- return;
70
+ return false;
68
71
  }
69
72
  const allSourceConvs = source.registry.list();
70
73
  const descendants = allSourceConvs.filter((c) => c.meta.kind === "subagent" && isSubagentDescendant(c, convId, allSourceConvs));
@@ -170,6 +173,7 @@ export async function executeTakeOverConversation(deps, targetId, ownerId, convI
170
173
  textEn: `"${conv.meta.title}" was moved to this page — pick up right where it left off.`,
171
174
  });
172
175
  deps.notifyExternalRunning();
176
+ return true;
173
177
  }
174
178
  catch (err) {
175
179
  console.error("[takeover] takeover failed, rolling back:", err);
@@ -213,6 +217,7 @@ export async function executeTakeOverConversation(deps, targetId, ownerId, convI
213
217
  });
214
218
  fail(`过户失败(${err.message})——对话已退回原页面,可直接重试`, `Takeover failed (${err.message}) — the conversation is back on the source page; retry there.`);
215
219
  deps.notifyExternalRunning();
220
+ return false;
216
221
  }
217
222
  }
218
223
  finally {
@@ -1,6 +1,7 @@
1
1
  import { CoreEngineNotReadyError } from "../contracts/core-engine-errors.js";
2
2
  import { searchSessions } from "../session-search.js";
3
3
  import { PI_AGENT_PRESETS, PI_PERMISSION_OPTIONS } from "../tool-catalog.js";
4
+ import { DEFAULT_PERMISSION_PRESET } from "../domains/tools/index.js";
4
5
  import { applySessionListLimit, scanHistory, sessionSummaryOf, } from "../domains/history/index.js";
5
6
  /** 一次全局检索最多回多少条(老实现 `searchSessions` 的 `.slice(0, 50)` 同口径)。 */
6
7
  const MAX_SEARCH_RESULTS = 50;
@@ -24,6 +25,13 @@ function searchableOf(entry) {
24
25
  allMessagesText: "",
25
26
  };
26
27
  }
28
+ export function permissionFrame(defaultPreset) {
29
+ return {
30
+ type: "dsh_permission",
31
+ options: PI_PERMISSION_OPTIONS,
32
+ defaultPreset: defaultPreset || DEFAULT_PERMISSION_PRESET,
33
+ };
34
+ }
27
35
  /**
28
36
  * 六个「端口/域/帧都齐、只差 handler」的成员:这里只做编排,能力本身都在既有域与端口后面
29
37
  * (分页状态在 `domains/history/limit.ts`、检索在 `session-search.ts`、预设目录在 `tool-catalog.ts`、
@@ -59,11 +67,6 @@ export function createExtraHandlers(runtime, frames) {
59
67
  presets: PI_AGENT_PRESETS,
60
68
  defaultPreset,
61
69
  });
62
- const permissionFrame = (defaultPreset) => ({
63
- type: "dsh_permission",
64
- options: PI_PERMISSION_OPTIONS,
65
- defaultPreset,
66
- });
67
70
  /** 老实现 `removeProject`:沙盒先销毁(销毁里连墓碑与 projects 帧一起走),否则只清墓碑 + 推 projects。 */
68
71
  const removeProject = async (ports, path) => {
69
72
  const located = await ports.sandbox.locate(path);
@@ -157,6 +157,7 @@ export function createHostFaces(deps) {
157
157
  };
158
158
  const background = deps.background?.({
159
159
  clientId,
160
+ getClientId: () => runtime.clientId,
160
161
  emit: (msg) => transport.send(msg),
161
162
  flushSnapshot: () => runtime.publisher.request(),
162
163
  isDisposed: () => deps.isDisposed(),
@@ -13,6 +13,7 @@ export function hostOwnedToolsOf(mounts) {
13
13
  clientId: conv.meta.clientId,
14
14
  cwd: conv.meta.cwd,
15
15
  conversationId: conv.id,
16
+ ...(conv.meta.botId ? { botId: conv.meta.botId } : {}),
16
17
  // 转录地址延迟读:开会话那一刻 `meta.sessionFile` 可能还没分配。
17
18
  sessionFile: () => conv.meta.sessionFile,
18
19
  lang: mounts.lang,
@@ -29,6 +30,17 @@ export function hostOwnedToolsOf(mounts) {
29
30
  const canvas = mounts.hostTools?.canvas?.(ctx);
30
31
  if (canvas)
31
32
  tools.push(canvas);
33
+ // 取回被外置的工具输出:只读且与会话绑定,子代理的打包外置同样需要这个入口。
34
+ const obsRecall = mounts.hostTools?.obsRecall?.(ctx);
35
+ if (obsRecall)
36
+ tools.push(obsRecall);
37
+ }
38
+ // Bot 私聊(有固定私聊会话,非群/设备任务)若在能力范围中勾选了 `schedule`,允许挂载并投回该私聊。
39
+ if (conv.meta.kind === "bot" && conv.meta.botId && !conv.meta.clientId.startsWith("device-task-")) {
40
+ const schedule = mounts.hostTools?.schedule?.(ctx);
41
+ if (schedule)
42
+ tools.push(schedule);
43
+ return tools;
32
44
  }
33
45
  // 下面这些都只对普通主对话注册:Bot 执行 / Bot 私聊 / 子代理都不是
34
46
  // 稳定的「向谁汇报 / 给谁看」的地址,在那儿注册只会让模型建出一条投不回去的任务。
@@ -8,6 +8,6 @@ export async function deliverStructuredNote(session, text, structured) {
8
8
  display: true,
9
9
  ...(structured.details === undefined ? {} : { details: structured.details }),
10
10
  },
11
- // 旁述不改相位、不起新一轮;流式中追加会推到本轮末,不插在工具调用中间。
12
- { triggerTurn: false });
11
+ // 默认旁述不改相位、不起新一轮;`triggerTurn: true` 时空闲起新一轮、流式中插队 steer。
12
+ { triggerTurn: structured.triggerTurn === true });
13
13
  }
@@ -1,4 +1,5 @@
1
1
  import { openTurnSession } from "../adapters/sdk/index.js";
2
+ import { resolveWorkspaceSessionDir } from "../remote-workspace.js";
2
3
  export class SessionUnavailableError extends Error {
3
4
  code = "session_unavailable";
4
5
  constructor(conversationId, reason) {
@@ -73,9 +74,10 @@ export class SessionRegistry {
73
74
  this.options.onClosed?.(conv.id);
74
75
  throw new SessionUnavailableError(conv.id, this.disposed ? "disposed" : `phase ${conv.phase}`);
75
76
  }
77
+ const sessionCwd = resolveWorkspaceSessionDir(this.options.dataDir, options?.cwd ?? conv.meta.cwd);
76
78
  const opened = await openTurnSession({
77
79
  // 远程工作区的 SDK 会话目录与 cwd 分离(`cwd` 是 URI,会话落本地镜像目录)。
78
- cwd: options?.cwd ?? conv.meta.cwd,
80
+ cwd: sessionCwd,
79
81
  agentDir: this.options.agentDir,
80
82
  sessionDir: conv.meta.kind === "bot" && conv.meta.botId ? this.options.botSessionDir?.(conv.meta.botId) : undefined,
81
83
  sessionFile: conv.meta.sessionFile,
@@ -10,6 +10,7 @@ import { findMostRecentSessionFileFast } from "../session-parser.js";
10
10
  import { resolveWorkspaceSessionDir } from "../remote-workspace.js";
11
11
  import { findTurnBaseEntryId, resolveEntry, undeletedContextEntries } from "../domains/turns/entries.js";
12
12
  import { createSandboxHandlers } from "../domains/sandbox/index.js";
13
+ import { openedMessageCount } from "./conversation-content.js";
13
14
  /**
14
15
  * 会话实体重绑面的装配:老树把这段(约 200 行)绑在 `ClientSession` 上,这里单独一处,
15
16
  * 让 `ClientRuntime` 只留「谁来调用」,不再跟着长。
@@ -75,7 +76,7 @@ export function createSessionSurface(options) {
75
76
  const thinkingLevel = typeof session?.thinkingLevel === "string" ? session.thinkingLevel : undefined;
76
77
  // CLI 账与状态在宿主那边:非 CLI 对话这里恒为 `undefined`(不编相位)。
77
78
  const nativeCli = options.nativeCliOf?.(conv.id);
78
- const messageCount = Array.isArray(session?.messages) ? session.messages.length : 0;
79
+ const messageCount = openedMessageCount(options.sessions, conv.id);
79
80
  return {
80
81
  id: conv.id,
81
82
  title: conv.meta.title,