@xmanrui/dsh-im 5.9.1 → 5.11.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 (135) hide show
  1. package/PROACTIVE_DELIVERY.en.md +33 -9
  2. package/PROACTIVE_DELIVERY.md +33 -9
  3. package/README.en.md +42 -7
  4. package/README.md +46 -8
  5. package/bin/dsh-im.mjs +65 -0
  6. package/docs/client-integration.md +4 -0
  7. package/lib/client.js +1735 -203
  8. package/lib/index.js +367 -341
  9. package/package.json +7 -6
  10. package/plugin-src/client/access-policy-settings.js +210 -12
  11. package/plugin-src/client/bot-general-settings.js +44 -3
  12. package/plugin-src/client/delivery-settings.js +2 -0
  13. package/plugin-src/client/delivery-sync-settings.js +269 -0
  14. package/plugin-src/client/global-settings.js +45 -7
  15. package/plugin-src/client/i18n-ru.js +112 -0
  16. package/plugin-src/client/i18n.js +110 -0
  17. package/plugin-src/client/im-channels.js +419 -0
  18. package/plugin-src/client/index.js +50 -2
  19. package/plugin-src/client/model-setting.js +6 -3
  20. package/plugin-src/client/styles.js +23 -7
  21. package/plugin-src/client/update-panel.js +2 -1
  22. package/plugin-src/host/channel-list-rpc.mjs +280 -0
  23. package/plugin-src/host/channels/dingtalk/production.mjs +28 -10
  24. package/plugin-src/host/channels/dingtalk/rpc.mjs +10 -1
  25. package/plugin-src/host/channels/feishu/production.mjs +50 -37
  26. package/plugin-src/host/channels/feishu/rpc.mjs +10 -1
  27. package/plugin-src/host/channels/matrix/production.mjs +28 -10
  28. package/plugin-src/host/channels/matrix/rpc.mjs +10 -0
  29. package/plugin-src/host/channels/qq/production.mjs +30 -11
  30. package/plugin-src/host/channels/qq/rpc.mjs +10 -1
  31. package/plugin-src/host/channels/shared/access-policy-production.mjs +9 -0
  32. package/plugin-src/host/channels/shared/binding-events.mjs +109 -0
  33. package/plugin-src/host/channels/shared/production.mjs +14 -1
  34. package/plugin-src/host/channels/shared/reply-content-rpc.mjs +17 -0
  35. package/plugin-src/host/channels/shared/rpc.mjs +9 -0
  36. package/plugin-src/host/channels/shared/workspace-rpc.mjs +1 -0
  37. package/plugin-src/host/channels/slack/production.mjs +28 -10
  38. package/plugin-src/host/channels/slack/rpc.mjs +10 -0
  39. package/plugin-src/host/channels/telegram/production.mjs +5 -0
  40. package/plugin-src/host/channels/wecom/production.mjs +28 -10
  41. package/plugin-src/host/channels/wecom/rpc.mjs +10 -1
  42. package/plugin-src/host/channels/wecom-app/production.mjs +28 -10
  43. package/plugin-src/host/channels/wecom-app/rpc.mjs +9 -0
  44. package/plugin-src/host/channels/weixin/production.mjs +28 -10
  45. package/plugin-src/host/channels/weixin/rpc.mjs +10 -1
  46. package/plugin-src/host/channels/whatsapp/production.mjs +28 -10
  47. package/plugin-src/host/channels/whatsapp/rpc.mjs +10 -1
  48. package/plugin-src/host/delivery-adapter.mjs +35 -20
  49. package/plugin-src/host/delivery-service.mjs +99 -1
  50. package/plugin-src/host/delivery-suggestions.mjs +31 -1
  51. package/plugin-src/host/delivery-sync-rpc.mjs +100 -0
  52. package/plugin-src/host/harness-connection.mjs +2 -1
  53. package/plugin-src/host/harness-peer.mjs +3 -1
  54. package/plugin-src/host/host-language-rpc.mjs +16 -2
  55. package/plugin-src/host/host-language.mjs +29 -0
  56. package/plugin-src/host/index.mjs +30 -1
  57. package/plugin-src/host/modern-harness-api.mjs +5 -1
  58. package/plugin-src/host/root-scope.mjs +32 -0
  59. package/plugin-src/host/session-sync-coordinator.mjs +290 -122
  60. package/plugin-src/host/session-sync-targets.mjs +71 -0
  61. package/plugin-src/management-rpc.mjs +18 -2
  62. package/scripts/verify-package.mjs +48 -10
  63. package/src/channels/dingtalk/dingtalk-bridge.mjs +50 -6
  64. package/src/channels/dingtalk/state-store.mjs +56 -0
  65. package/src/channels/discord/discord-api.mjs +2 -1
  66. package/src/channels/feishu/bridge.mjs +154 -58
  67. package/src/channels/feishu/feishu-cards.mjs +10 -4
  68. package/src/channels/feishu/feishu-runtime.mjs +11 -3
  69. package/src/channels/feishu/message-utils.mjs +106 -30
  70. package/src/channels/feishu/slash-command-panel.mjs +26 -0
  71. package/src/channels/feishu/state-store.mjs +14 -0
  72. package/src/channels/matrix/matrix-api.mjs +2 -1
  73. package/src/channels/qq/qq-bridge.mjs +114 -14
  74. package/src/channels/qq/state-store.mjs +55 -1
  75. package/src/channels/shared/access-policy.mjs +60 -7
  76. package/src/channels/shared/action-card.mjs +83 -7
  77. package/src/channels/shared/bot-workspace-store.mjs +255 -11
  78. package/src/channels/shared/busy-message-dispatcher.mjs +2 -2
  79. package/src/channels/shared/channel-capabilities.mjs +44 -0
  80. package/src/channels/shared/command-catalog.mjs +68 -3
  81. package/src/channels/shared/command-permission.mjs +6 -2
  82. package/src/channels/shared/conversation-state-store.mjs +16 -0
  83. package/src/channels/shared/deferred-delivery-coordinator.mjs +6 -1
  84. package/src/channels/shared/deferred-delivery.mjs +4 -0
  85. package/src/channels/shared/delivery-sync-settings-store.mjs +86 -0
  86. package/src/channels/shared/delivery-sync-settings.mjs +122 -0
  87. package/src/channels/shared/diagnostic-details.mjs +6 -1
  88. package/src/channels/shared/failure-log-file.mjs +79 -0
  89. package/src/channels/shared/harness-client.mjs +259 -96
  90. package/src/channels/shared/i18n-en/diagnostics.mjs +1 -0
  91. package/src/channels/shared/i18n-en/feishu.mjs +2 -2
  92. package/src/channels/shared/i18n-en/shared-a.mjs +13 -2
  93. package/src/channels/shared/i18n-en/shared-b.mjs +73 -4
  94. package/src/channels/shared/i18n-en/shared-d.mjs +144 -0
  95. package/src/channels/shared/i18n-en/weixin.mjs +4 -0
  96. package/src/channels/shared/i18n-en.mjs +2 -0
  97. package/src/channels/shared/i18n-ru/diagnostics.mjs +1 -0
  98. package/src/channels/shared/i18n-ru/feishu.mjs +2 -2
  99. package/src/channels/shared/i18n-ru/shared-a.mjs +13 -2
  100. package/src/channels/shared/i18n-ru/shared-b.mjs +72 -4
  101. package/src/channels/shared/i18n-ru/shared-d.mjs +144 -0
  102. package/src/channels/shared/i18n-ru/weixin.mjs +4 -0
  103. package/src/channels/shared/i18n-ru.mjs +2 -0
  104. package/src/channels/shared/inbound-access.mjs +10 -0
  105. package/src/channels/shared/interface-language-store.mjs +49 -10
  106. package/src/channels/shared/interface-language.mjs +19 -1
  107. package/src/channels/shared/markdown-chunks.mjs +5 -0
  108. package/src/channels/shared/message-failure.mjs +22 -1
  109. package/src/channels/shared/model-setting.mjs +6 -3
  110. package/src/channels/shared/new-command.mjs +158 -4
  111. package/src/channels/shared/plan-goal-command.mjs +132 -0
  112. package/src/channels/shared/qrcode.mjs +5 -0
  113. package/src/channels/shared/reply-content.mjs +102 -0
  114. package/src/channels/shared/reset-command.mjs +46 -0
  115. package/src/channels/shared/semantic/artifact.mjs +133 -29
  116. package/src/channels/shared/semantic/reply-reference.mjs +18 -3
  117. package/src/channels/shared/session-nav-command.mjs +999 -0
  118. package/src/channels/shared/session-ring-support.mjs +184 -0
  119. package/src/channels/shared/session-ring.mjs +202 -0
  120. package/src/channels/shared/session-title.mjs +11 -0
  121. package/src/channels/shared/status-command.mjs +2 -1
  122. package/src/channels/shared/text-harness-bridge.mjs +166 -7
  123. package/src/channels/shared/workspace-command.mjs +567 -31
  124. package/src/channels/shared/workspace-session.mjs +52 -4
  125. package/src/channels/slack/slack-api.mjs +2 -1
  126. package/src/channels/telegram/config-store.mjs +10 -2
  127. package/src/channels/telegram/telegram-api.mjs +19 -1
  128. package/src/channels/telegram/telegram-rich-message.mjs +17 -5
  129. package/src/channels/telegram/telegram-runtime.mjs +14 -1
  130. package/src/channels/wecom/state-store.mjs +13 -1
  131. package/src/channels/wecom/wecom-bridge.mjs +183 -26
  132. package/src/channels/wecom-app/state-store.mjs +13 -1
  133. package/src/channels/wecom-app/wecom-app-bridge.mjs +44 -4
  134. package/src/channels/weixin/state-store.mjs +13 -1
  135. package/src/channels/weixin/weixin-bridge.mjs +71 -4
@@ -78,18 +78,42 @@ Assume the Feishu bot has already received a message in the alert group:
78
78
 
79
79
  If the group Chat ID is edited later, callers can continue using the same `botId + release-alerts` pair.
80
80
 
81
- ## Two-way sync for direct-message Sessions
81
+ ## Two-way sync for any Session conversation
82
82
 
83
- A saved direct-message target has an opt-in **Two-way Session sync** switch. When enabled:
83
+ Session sync needs no delivery target in advance: the address comes from the Session's current chat binding, that is, the conversation key this Session has in a connected chat (a direct message, a group, a Slack thread, a Telegram forum topic, a Discord channel). **General settings → Delivery** is the only place where the sync is switched on; the delivery-targets page is only for manual delivery and for the candidate range of synced approvals and questions.
84
84
 
85
- 1. User text submitted from DSH Web/CLI to the DM's current Session is sent to the DM with a `[来自 DSH]` prefix.
86
- 2. After that turn completes successfully, the final assistant text merged in step order is sent once more with a `[DSH 助手]` prefix.
87
- 3. Ordinary IM prompts and `/steer` continue through the existing reply path. They are neither duplicated nor forwarded to another target.
88
- 4. Scheduled tasks (`schedule`, `deliveryMode: host`) also sync their final assistant text after successful completion in the bound Session. Internal reminder framing is not echoed as a `[来自 DSH]` message.
85
+ 1. Ordinary prompts and `/steer` inside that chat keep using the normal reply path. They are neither duplicated nor forwarded to another target.
86
+ 2. After a successful turn from another source, only the **final answer** is sent to the chat — the text after the last tool call, not every step joined together and not the talk that precedes the tools: a turn submitted in the DSH Web GUI, a scheduled task (`schedule`, `deliveryMode: host`), an answered-question receipt, or a turn started by an internal notice such as `subagent-settled`.
87
+ 3. Whether the Web input itself is mirrored into the chat and whether model answers are delivered is decided by **General settings → Delivery**; the two prefix icons apply to the mirrored input and to the answer respectively.
88
+ 4. Only text the reader submitted in the DSH Web GUI is mirrored: the context snapshot the Host injects, schedule reminders, and internal notices are never echoed, and only the model answer is delivered. When the input mirror cannot be sent, that turn's answer is withheld too.
89
+ 5. A channel that renders the answer itself — the Feishu process card — owns that delivery: the card carries the final answer, and plain text follows only when the card did not confirm it. One answer therefore reaches the chat once, never as a card and a copy of the same text. With both switches off, the card stops together with the text, because both read the same switches.
90
+ 6. The address is read from the current binding before every delivery, so it follows `/session` changes and `/new` automatically; a Session with no binding is not delivered and raises no error, but the miss is logged with the Session, the channel and the conversation key — never the message body — so an empty chat stays diagnosable.
89
91
 
90
- The setting stores the private conversation target, never a `sessionId`, so it follows `/session` changes automatically. After `/new` or a workspace change, its status becomes **Waiting for this DM to establish a new Session** and recovers as soon as that DM creates one; the switch does not need to be toggled again.
92
+ A service injection never decides where the turn came from: the context snapshot the Host prepends, a schedule reminder or an internal notice is only "one message of this turn", never proof that a service started it. The answer is delivered as a service turn only when no message of the turn came from the reader (the Web GUI or this chat); as soon as one message came from this chat, the chat answers for itself and the sync delivers nothing at all.
91
93
 
92
- Enabling requires one uniquely known DM that already has a current Session for this bot. Groups, Slack Threads, Telegram Topics, Discord server channels, and targets that cannot be confirmed as DMs are unavailable. A channel with an explicit remote `harnessBaseUrl` is also unsupported. The first version mirrors current-Host text only—no images, files, cards, tool progress, approvals, or history. Changing the target type or native route disables sync; renaming the target does not.
94
+ The **Two-way Session sync** switch on a delivery target now only affects the candidate range of synced approvals and questions; it is no longer a precondition for Session sync. That candidate range stays private-chat only: mirrored text follows any route the channel persisted (a group, a Slack thread, a Telegram forum topic, a Discord channel), but a question or an approval is offered in a private chat only, because in a group any member could answer it. The first version mirrors current-Host text only—no images, files, cards, tool progress, approvals, or history. A channel with an explicit remote `harnessBaseUrl` is still unsupported.
95
+
96
+ ## Delivery settings
97
+
98
+ **General settings → Delivery** stores plugin-wide settings rather than per-bot ones, in `<dshHome>/integrations/dsh-im/delivery-sync-settings.json`:
99
+
100
+ ```json
101
+ {
102
+ "version": 1,
103
+ "deliverySync": {
104
+ "mirrorUserInput": false,
105
+ "deliverModelAnswers": false,
106
+ "inputIcon": "",
107
+ "modelIcon": ""
108
+ }
109
+ }
110
+ ```
111
+
112
+ - `mirrorUserInput`: mirror user text submitted in the Web GUI into the chat the Session is bound to; off by default. While it is off nothing is echoed, but the model answer is still delivered.
113
+ - `deliverModelAnswers`: deliver model answers of turns that did not start in this chat; off by default, like the input mirror. Both switches are off in a fresh install, and an unreadable document is treated as both off: the coordinator logs a warning and delivers nothing rather than starting to mirror on its own.
114
+ - `inputIcon` / `modelIcon`: prefix icons for the mirrored input and for the model answer. Trimmed, at most 32 characters, no line breaks or control characters; an invalid value becomes the empty string, and an empty icon means no prefix. A non-empty icon renders as "icon, blank line, text".
115
+
116
+ The settings page reads and writes this document through `settings.delivery-sync.get` / `settings.delivery-sync.set` (`set` applies only the fields it carries, and all four are optional). `settings.language.set` switches the message language between "same as the DSH interface" and `zh`/`en`/`ru`: the explicit choice outranks the DSH interface language, and the plugin `language` option still outranks both.
93
117
 
94
118
  ## Native fields for all nine channels
95
119
 
@@ -192,7 +216,7 @@ await ctx.dshIm.send(botId, targetId, '# Daily report\n\n**Checks complete**', {
192
216
 
193
217
  Channels apply their own message limits and splitting. Feishu proactive cards retain their existing unsplit behavior and do not automatically resend as text after rejection or an uncertain result. Other newly added fallback paths only handle local formatting errors or definite format rejection; they do not resend accepted chunks or retry ambiguous network outcomes. Older Hosts may ignore `format`; load the updated plugin on the Host.
194
218
 
195
- Session sync requests Markdown for final assistant answers and retains the existing default text behavior for user echoes. Feishu keeps its dedicated mirror cards and existing plain-text fallback when the mirror cannot confirm the final answer. This does not expand the supported sync targets.
219
+ Session sync requests Markdown for the final assistant answer and plain text for mirrored Web input. Both follow the Session binding through the ordinary delivery path and no longer use Feishu's dedicated mirror cards, so Feishu receives that same text.
196
220
 
197
221
  A same-Host plugin may also list the saved targets for one bot:
198
222
 
@@ -78,18 +78,42 @@
78
78
 
79
79
  以后即使编辑并更换群 Chat ID,调用方仍可继续使用同一组 `botId + release-alerts`。
80
80
 
81
- ## 私聊会话双向同步
81
+ ## 会话双向同步
82
82
 
83
- 已保存的私聊目标可以在目标行开启「会话双向同步」,默认关闭。开启后:
83
+ 会话同步不需要预先创建投递目标:地址取自 Session 当前的聊天绑定,也就是这个 Session 在某个已接入聊天里的会话键(私聊、群聊、Slack Thread、Telegram Topic、Discord 频道等)。是否同步由「通用设置 → 投递」决定,这是唯一的开关位置;「投递目标」页只服务于手动投递,以及同步审批和同步提问的候选范围。
84
84
 
85
- 1. DSH Web/CLI 向该私聊当前绑定的 Session 提交的用户文字,会以 `[来自 DSH]` 开头发送到私聊。
86
- 2. 该 Turn 成功完成后,按 step 合并的最终助手文字会以 `[DSH 助手]` 开头再发送一次。
87
- 3. IM 用户自己的普通提问和 `/steer` 仍走原回复链,不会被同步逻辑重复发送或转发给其他目标。
88
- 4. 定时任务(`schedule`、`deliveryMode: host`)在绑定 Session 中成功完成后,也会同步最终助手文字;内部提醒提示不会以 `[来自 DSH]` 消息回显到私聊。
85
+ 1. 在该聊天里的普通提问和 `/steer` 仍走原回复链,不会被同步逻辑重复发送或转发到其他目标。
86
+ 2. 其他来源的 Turn 成功完成后,只投递**最终回答**——最后一次工具调用之后的文字,而不是各 step 拼接的全文,也不是工具调用之前的寒暄:Web GUI 中提交的 Turn、定时任务(`schedule`、`deliveryMode: host`)、待答问题回执,以及 `subagent-settled` 等内部通知发起的 Turn。
87
+ 3. 是否把 Web 中输入的文字本身也镜像到聊天、是否投递模型回答,由「通用设置 → 投递」决定;两个前缀图标分别作用于镜像的输入与模型回答。
88
+ 4. 只有读者自己在 Web GUI 里提交的文字才会被镜像:Host 注入的上下文快照、定时提醒和内部通知都不会回显,只投递模型回答。镜像发送失败时,该 Turn 的回答也不再投递。
89
+ 5. 渠道自己渲染回答时(飞书过程卡片),卡片就是这次投递:最终回答写在卡片里,只有卡片没能确认,才补发一条纯文字。同一条回答因此只会到达聊天一次,不会既在卡片里又以文字重发一遍。两个全局开关关闭时,卡片与文字一起停发,因为两者读的是同一份开关。
90
+ 6. 地址在每次投递前从当前绑定读取,因此自动跟随 `/session` 切换与 `/new`;没有绑定的 Session 不会投递,也不会报错,但会写一条不含消息正文的日志(Session、渠道与会话 Key),方便排查为什么聊天没有收到内容。
89
91
 
90
- 开关只保存私聊目标,不保存 `sessionId`,因此会自动跟随 `/session` 切换。执行 `/new` 或切换工作区后,状态暂时显示「等待该私聊建立新会话」;该私聊下一次建立 Session 后自动恢复,无需重新开关。
92
+ 服务注入不会决定 Turn 的来源:Host 在每个 Turn 前注入的上下文快照、定时提醒与内部通知只是「这是本 Turn 的一条消息」,不会把 Turn 判成服务发起的。只有整个 Turn 都没有一条来自读者(Web 或本聊天)的消息时,才按服务发起的 Turn 投递回答;只要其中一条消息来自本聊天,该 Turn 就由聊天自己回答,同步逻辑完全不投递。
91
93
 
92
- 开启要求目标来自该机器人已经聊过、已有当前 Session 的唯一私聊。群聊、Slack Thread、Telegram Topic、Discord 服务器频道和其他无法确认是私聊的目标显示为不可用。显式配置了远程 `harnessBaseUrl` 的渠道也不支持;首版仅同步当前 Host 的文字,不同步图片、文件、卡片、工具过程、审批或历史消息。修改目标类型或平台路由会自动关闭同步,改名不会。
94
+ 投递目标行上原有的「会话双向同步」开关现在只影响同步审批与同步提问的候选范围,不再是会话同步的前提;这个候选范围仍然只限私聊:镜像文字可以跟随渠道持久化的任意路由(群聊、Slack Thread、Telegram Topic、Discord 频道),但同步审批与同步提问只在私聊中提出,因为在群里任何成员都能替读者作答。首版仅同步当前 Host 的文字,不同步图片、文件、卡片、工具过程、审批或历史消息。显式配置了远程 `harnessBaseUrl` 的渠道也不支持。
95
+
96
+ ## 投递设置
97
+
98
+ 「通用设置 → 投递」保存的是全局设置,不属于单个机器人,写入 `<dshHome>/integrations/dsh-im/delivery-sync-settings.json`:
99
+
100
+ ```json
101
+ {
102
+ "version": 1,
103
+ "deliverySync": {
104
+ "mirrorUserInput": false,
105
+ "deliverModelAnswers": false,
106
+ "inputIcon": "",
107
+ "modelIcon": ""
108
+ }
109
+ }
110
+ ```
111
+
112
+ - `mirrorUserInput`:把在 Web GUI 中提交的用户文字镜像到该 Session 绑定的聊天;默认关闭。关闭时不发送输入,模型回答照常投递。
113
+ - `deliverModelAnswers`:投递「非本聊天发起」的 Turn 的模型回答;默认关闭,与输入镜像一致。全新安装两项都是关闭的;设置文件无法读取时同样按两项关闭处理——协调器只记录一条警告,不会自行开始镜像。
114
+ - `inputIcon` / `modelIcon`:镜像输入与模型回答的前缀图标。去除首尾空白,最长 32 个字符,不允许多行或控制字符;无效值按空字符串处理,空字符串表示不加前缀。非空时消息格式为「图标 + 空行 + 文字」。
115
+
116
+ 同机设置页通过 `settings.delivery-sync.get` / `settings.delivery-sync.set` 读写这份设置(`set` 只应用传入的字段,四个字段都可选)。消息语言通过 `settings.language.set` 在「跟随 DSH 界面语言」与 `zh`/`en`/`ru` 之间切换:显式选择优先于 DSH 界面语言,插件 `language` 选项仍然优先于两者。
93
117
 
94
118
  ## 九渠道手动填写字段
95
119
 
@@ -192,7 +216,7 @@ await ctx.dshIm.send(botId, targetId, '# 每日报告\n\n**检查完成**', {
192
216
 
193
217
  长消息按渠道限制分段。飞书主动卡片保留原有不自动分段的行为,平台拒绝或结果未知时不自动改发文本。其他新增回退仅针对本地格式处理错误或明确的格式拒绝,不重发已成功的分段,不因网络结果未知而改格式重试。旧 Host 可能忽略 `format`,需要加载更新后的插件。
194
218
 
195
- 会话同步的最终助手回答请求 Markdown,用户回显继续使用原有默认文字行为。飞书继续使用专用镜像卡片,无法确认最终答案可见时仍走现有纯文本兜底。同步目标范围不变。
219
+ 会话同步的最终助手回答请求 Markdown,镜像的 Web 输入使用纯文本,两者都按 Session 绑定地址走普通投递路径,不再经由飞书专用的镜像卡片:飞书收到的就是同一份文本。
196
220
 
197
221
  同 Host 插件也可以列出某个机器人的已保存目标:
198
222
 
package/README.en.md CHANGED
@@ -200,6 +200,34 @@ npx -y github:xmanrui/dsh-im install
200
200
 
201
201
  A GitHub-source installation fetches and builds a Git dependency directly. With pnpm 10 or newer, the profile may first need an `allowBuilds` entry in `pnpm-workspace.yaml`. Most users should prefer the stable npm release.
202
202
 
203
+ > **On a “different pnpm major” error** (the one suggesting `run the pnpm major that built this node_modules`, or a localized note that this profile's `node_modules` was built by another pnpm major): the profile's `node_modules` was created by a different pnpm major (say 10.x) than the one performing this install (say 11.x). How pnpm treats cross-major `node_modules` varies by version (12.17 and newer refuse outright with `ERR_PNPM_MODULES_BREAKING_CHANGE`), and every version appends its own directory under any `storeDir`, so overriding `storeDir` cannot fix it and the automatic rollback fails the same way once an install goes wrong. Pick one remedy and retry:
204
+ >
205
+ > 1. **Rebuild from scratch (recommended; the only option for plugin-market UI installs)**: quit DSH, delete the profile's `node_modules`, and install again. Previously installed plugins are restored from the profile's `package.json`; every package is downloaded once more:
206
+ >
207
+ > ```sh
208
+ > # macOS / Linux (adjust the profile name)
209
+ > rm -rf ~/.dsh/profiles/web/node_modules
210
+ > ```
211
+ >
212
+ > ```powershell
213
+ > # Windows PowerShell
214
+ > Remove-Item -Recurse -Force "$env:USERPROFILE\.dsh\profiles\web\node_modules" # adjust the profile name
215
+ > ```
216
+ >
217
+ > 2. **Run the CLI install with the pnpm major that built this `node_modules`**: put that pnpm first on `PATH` (on macOS with Homebrew it lives in `/opt/homebrew/bin`):
218
+ >
219
+ > ```sh
220
+ > # macOS / Linux
221
+ > PATH="/opt/homebrew/bin:$PATH" dsh plugin --profile web add --save-exact github:xmanrui/dsh-im
222
+ > ```
223
+ >
224
+ > ```powershell
225
+ > # Windows PowerShell
226
+ > $env:PATH = "<folder containing pnpm 10.x>;$env:PATH"; dsh plugin --profile web add --save-exact github:xmanrui/dsh-im
227
+ > ```
228
+ >
229
+ > `npx -y github:xmanrui/dsh-im install` detects this mismatch before invoking pnpm (including the JSON-format `.modules.yaml` pnpm 12 writes) and prints the same guidance.
230
+
203
231
  After installation, follow the built-in instructions on each channel page to scan a QR code or enter credentials. Secrets and Tokens are sent only to the local Harness Host and stored through its protected credential provider; status responses and bot lists never return them.
204
232
 
205
233
  If this machine must use a forward proxy to reach Feishu, set `HTTPS_PROXY` to a full HTTP proxy URL before starting `dsh web` (for example, `http://proxy:8080`; lowercase `https_proxy` is also supported, with `HTTP_PROXY` accepted as a fallback), then restart the Host after changing it. Feishu registration and credential verification reuse the SDK's proxy-aware HTTP client, while the message WebSocket explicitly uses that proxy; the WebSocket path does not currently read `ALL_PROXY` or `NO_PROXY`.
@@ -274,9 +302,10 @@ const info = await dshIm.describeConversation(sessionId);
274
302
 
275
303
  - Read-only: no network access, session creation, blocking reply, or thrown error; unknown Sessions return `null`.
276
304
  - Data comes from the plugin's state files (`sessions`) and bot configuration; no new core fields are required.
277
- - `chatType` is `group`, `thread`, or `dm`; a `direct:dm:<id>` key supplies `<id>` as `senderId`.
305
+ - `chatType` is `group`, `thread`, or `dm`. Without an author record, `senderId` is derived from the key only where the key names the user: Matrix `direct:dm:<userId>`, `p2p:<id>` (Feishu, Weixin, WeCom app, DingTalk), QQ `c2c:<openid>`, and `direct:<id>` on Telegram and WeCom. On Slack, Discord, WhatsApp, iMessage and others `direct:<id>` names the DM channel, so it is reported as `chatId` and `senderId` stays `null`.
278
306
  - The first lookup logs one line per Session; later lookups do not repeat it.
279
- - The bridge remembers the last inbound author's id, name, username, and bot flag in the bot state, without storing message text.
307
+ - The bridge remembers the last inbound author's id and bot flag in the bot state, without storing message text. The display name and username are stored only when context enhancement is enabled for that chat kind (or the channel already exposes a speaker name, as Matrix does); otherwise they are `null`.
308
+ - Links inserted from conversation keys into numeric chat/topic fields are **Telegram-only**; QQ and other channels must use their native route fields and must not be treated as Telegram links.
280
309
 
281
310
  ### The two binding events
282
311
 
@@ -288,7 +317,10 @@ A binding change is announced synchronously, so a subscriber keeps its own sessi
288
317
  | `dsh-im/session-unbind` | the conversation no longer points at its session: it moved to another one, or the binding was cleared | the same fields without the author; `sessionId` is the old session that was detached |
289
318
 
290
319
  - Both are synchronous, and the order is detach-then-bind, so a subscriber reads one straight line.
320
+ - Every chat channel emits both events: Telegram, Discord, Email and iMessage through the shared production controller; DingTalk, Feishu, Matrix, QQ, Slack, WeCom (`wecom` and `wecom-app`), Weixin and WhatsApp assemble their own controllers but load their state through the same wrapper. `office` is a job connector with no conversations and emits neither event.
321
+ - A channel with its own controller must not call `new StateStore(path).load()` directly: `createAnnouncedStateStore({ announcer, StateStore, statePath })` loads once per bot, hands back the wrapped store and the `stateForSync` the delivery adapter needs. Prime it at start-up, or the first prompt has nothing to answer from.
291
322
  - Only committed writes announce anything: a refused write (`false`) or a rewrite of the same session emits no `unbind`.
323
+ - A subscriber has to be idempotent per `(conversationKey, sessionId)`: a rewritten binding announces the bind again, and nothing in the protocol distinguishes that repeat from a first bind.
292
324
  - Clearing one binding (`clearSession`) or every binding (`clearSessions`) emits a `session-unbind` per conversation.
293
325
  - A throwing subscriber never breaks message handling.
294
326
  - A detach does not erase the session's identity: keeping the row (with a `superseded_at`, for instance) still lets a scheduled task that owns that session deliver into the original chat — only "who owns this conversation" has to be answered from the latest bind.
@@ -338,9 +370,10 @@ A binding change is announced synchronously, so a subscriber keeps its own sessi
338
370
  | `/clear` | Clear the model context in the Session bound to the current chat while retaining its Session binding and history; report explicitly when the current Host does not support the command. |
339
371
  | `/workspace [workspace index or absolute path]`, `/ws [...]` | View and switch the current bot's Harness workspace: without an argument it lists switchable workspaces (a tappable card on Telegram — one tap switches and the current entry is re-marked in place); an index or absolute path switches directly. |
340
372
  | `/workspacelist`, `/workspaces`, `/wsl` | Legacy aliases of `/workspace`, equivalent to its no-argument form; native command menus keep a single workspace entry. |
341
- | `/sessionlist [workspace number or absolute path]`, `/sessions [...]` | Equivalent aliases that list session IDs and titles in the selected workspace, including ungrouped sessions in the default IM directory; omit the argument to use the current workspace. |
373
+ | `/sessionlist [workspace number or absolute path]`, `/sessions [...]` | Equivalent aliases that list session IDs and titles in the selected workspace and mark the session this chat is already bound to; include ungrouped sessions in the default IM directory; omit the argument to use the current workspace. |
374
+ | `/sessionlist --all`, `/sessions --all` | Summarize sessions across workspaces: the conversation's effective workspace comes first and is marked; 10 per workspace by default, adjustable with `--limit N`; unreadable workspaces are skipped and counted. |
342
375
  | `/sessionlist --limit N`, `/sessions --limit N` | List the first N sessions in the current workspace's existing order; N must be a positive integer. |
343
- | `/session <Session ID>` | Bind the current chat to an existing Harness session. |
376
+ | `/session <Session ID, index, or title keyword>` | Bind the current chat to an existing Harness session; a title keyword binds automatically only when it matches uniquely in the current conversation workspace, otherwise the full Session ID is required; archived Sessions are never selected by keyword. |
344
377
  | `/history [count]` | Preview recent messages from the bound Session in a direct chat; defaults to 3, capped at 5. |
345
378
  | Interactive question | Reply with an option number, option label, or custom text; separate multiple choices with commas. In Feishu, an image or image post from the person answering ends the pending question turn and is processed in the same Session, without finishing the remaining questions or resending the image. |
346
379
  | Remote approval | Reply with `批准` / `拒绝` / `同意` / `不同意` / `yes` / `no`. |
@@ -362,7 +395,7 @@ Set `groupByAgentPreset: true` in the plugin Host config to opt in (off by defau
362
395
 
363
396
  - **Image understanding**: built-in channels with image input support can send JPEG, PNG, WebP, and GIF files sent as images to Harness, with an optional text description. Originals are saved in the workspace (default 30 MB per image, 20 images per message). Model copies are resized or compressed within configurable 5 MB per-image and 20 MB total budgets, with workspace-file fallback when necessary. Configure these limits in General settings → Attachments → Image input. iMessage's MVP supports text DMs only.
364
397
  - **Switch workspaces from a bot card**: every bot card on the settings page shows its current Harness workspace. Enter an existing absolute directory path directly or open the directory picker. Switching clears only that bot's old chat mappings; it never deletes, empties, or archives old Sessions. Replies already in progress may finish, while later messages use the new workspace.
365
- - **Default directory and ungrouped sessions**: bots using the default share `$DSH_HOME/im`, while retaining separate chat-to-Session mappings. The plugin creates no workspace group for this directory. Use `/sessions` to list its ungrouped sessions and `/session <Session ID>` or `/session N` to bind an ordinary session. New sessions in other directories use the existing workspace grouping mechanism; switching back to the default directory creates ungrouped sessions again. Existing bot directories are not migrated automatically.
398
+ - **Default directory and ungrouped sessions**: bots using the default share `$DSH_HOME/im`, while retaining separate chat-to-Session mappings. The plugin creates no workspace group for this directory. Use `/sessions` to list its ungrouped sessions and `/session <Session ID>`, `/session N`, or `/session <title keyword>` to bind an ordinary session. New sessions in other directories use the existing workspace grouping mechanism; switching back to the default directory creates ungrouped sessions again. Existing bot directories are not migrated automatically.
366
399
  - **Choose a model and reasoning effort from a bot card**: every bot card in each IM channel offers model and effort controls below the workspace, with DSH-style provider groups, descriptions, and checkmarks. Select an available model and one of its supported efforts, or use the model default. Leaving the model unset follows the Host default. Settings are stored per bot and used only for later new Sessions; existing Sessions and replies already in progress are unchanged.
367
400
  - **Choose an Agent Preset from a bot card**: every bot card can select one of the Host's existing Agent Presets, or follow the Host default. The change applies only to that bot and only to later new Sessions; existing Sessions and replies already in progress are left unchanged.
368
401
  - **Check the connection and send a test message**: when a bot is online, clicking **Check connection** verifies the platform connection and sends a “DeepSeek Harness connection test succeeded” message to the bot's most recently remembered direct conversation; WhatsApp uses the account's self-chat. The test neither creates a Harness Session nor invokes the model. The bot must have received at least one direct message before it has a remembered test target; otherwise the page reports that no test conversation is available yet.
@@ -385,9 +418,11 @@ Startup configuration validation failures also include `file`, `field`, and `iss
385
418
 
386
419
  ## Local development
387
420
 
388
- The latest dsh-im follows the latest DSH, with DSH `0.2.1-rc.2` (Session format V4) as this update's supported baseline. New features and fixes do not add compatibility branches for older DSH versions; existing unrelated compatibility code remains in place. Older hosts should use the corresponding historical plugin release. `package.json` declares only the host versions actually verified for this build, without promising support for untested future releases. After upgrading the plugin, restart the Host and refresh the settings page so both sides use the same plugin build.
421
+ The latest dsh-im follows the latest DSH, with DSH `0.2.2-rc.5` (Session format V4) as this update's supported baseline. New features and fixes do not add compatibility branches for older DSH versions; existing unrelated compatibility code remains in place. Older hosts should use the corresponding historical plugin release. `package.json` declares only the host versions actually verified for this build, without promising support for untested future releases. After upgrading the plugin, restart the Host and refresh the settings page so both sides use the same plugin build.
422
+
423
+ DSH `0.2.2-rc.5` requires an explicit caller `peer` on internal Gateway requests. The shared adapter creates it through Host Connection, reuses it for unary and streaming calls across all channels, and disposes it when the plugin unloads.
389
424
 
390
- DSH `0.2.1-rc.2` requires an explicit caller `peer` on internal Gateway requests. The shared adapter creates it through Host Connection, reuses it for unary and streaming calls across all channels, and disposes it when the plugin unloads. Live WeChat and QQ tests verified replies in both new and existing sessions.
425
+ Adapting to 0.2.2-rc.5 touches two host-version-bound declarations: `dsh.compatibility` in `package.json` (the verified baseline) and `dsh.client.inject` (client load order). The slot service now comes from `@deepseek-ai/dsh-client-ui-renderer` and the workspace service from `@deepseek-ai/dsh-client-ui-workspace`; `@deepseek-ai/dsh-client-runtime` stopped shipping after 0.1.1-rc.2 and `@deepseek-ai/dsh-client-ui-slots` is not a loadable client row, so neither belongs in `inject` — naming them on 0.2.2-rc.5 leaves the client row waiting for a dependency that never arrives. `test/package-client-inject.test.mjs` pins the list, and `scripts/verify-package.mjs` checks that the `dsh.compatibility` baseline is one `dshReleases` marks compatible and that `inject` names neither retired package.
391
426
 
392
427
  Source details, guidance, and quoted replies now use the V4 `plugin:dsh-im` source kind, fixing `SessionFormatError: format v4 message requires a producer-owned source kind`. Message ordering, user text, and session-level guidance deduplication retain their existing behavior. The host owns historical Session migration.
393
428
 
package/README.md CHANGED
@@ -130,6 +130,8 @@ Matrix 加密目前仅供非敏感测试:默认 optional 模式尝试启动加
130
130
 
131
131
  扫码新建的飞书和 QQ 机器人,默认允许所有用户在私聊和群聊中聊天及执行内置命令;可在机器人的访问设置中调整白名单和命令权限。已有机器人的访问设置保持不变。
132
132
 
133
+ 开放模式下可额外配置 `commandAllowlist`(命令名数组,不带斜杠):当默认命令权限为“不可以执行命令”时,只有列表中的命令可由普通用户执行;`canExecuteCommands: true` 的用户和所有者仍然不受限制。命令名按首个 token 统一为小写,例如 `/SessionList --limit 5` 记为 `sessionlist`。旧配置缺少该字段时按空数组处理,行为不变。每个命令权限例外的用户也可以带自己的 `commandAllowlist`,与场景级列表取并集。
134
+
133
135
  飞书群聊默认接收其他机器人明确 @ 当前机器人的消息,无需额外开关;未 @、仅 @ 其他成员或全体、机器人自身发送的消息和机器人私聊消息仍会忽略,即使群聊响应方式设为“全部”。消息仍受群聊白名单与命令权限约束。飞书应用需要租户权限 `im:message.group_at_msg.include_bot:readonly`(“获取群组中其他机器人和用户@当前机器人的消息”);扫码新建应用会默认申请,已有或手动绑定的应用可点击“补全权限”或私聊执行 `/repair`,扫码并完成飞书要求的发布审批后生效。详见[飞书接收消息权限说明](https://open.feishu.cn/document/server-docs/im-v1/message/events/receive)。
134
136
 
135
137
  支持图片输入的内置渠道均支持把 JPEG、PNG、WebP 图片,以及以图片文件方式发送的 GIF,连同可选文字说明发送给 Harness;默认每张原图最多接收 30 MB、每条消息最多 20 张;原图保存到会话工作区,模型副本自动缩放或压缩到单张 5 MB、总计 20 MB 以内,仍超限或模型不支持图片时按文件交给模型处理。这四项限制可在「通用设置 → 附件 → 图片输入」调整,对后续消息生效;原图沿用附件保留时长。调高模型输入上限会增加请求体积、处理耗时和模型成本,也仍受平台及宿主限制。iMessage 首版仅支持文本私聊,不包含在图片能力中。飞书下载用户消息中的图片或文件需要租户权限 `im:message:readonly`,确认页将其显示为“获取单聊、群组消息”;飞书目前没有为该下载接口提供仅限图片的更窄权限。扫码新建的应用会默认申请;已有或手动绑定的应用可私聊机器人执行 `/repair`,或在「IM机器人」设置页点击“补全权限”,扫码增量补全该权限、上传机器人图片或文件所需的 `im:resource`、原生命令面板所需的 `application:app_slash_command:read` / `write`,以及卡片回调。
@@ -203,6 +205,34 @@ npx -y github:xmanrui/dsh-im install
203
205
 
204
206
  GitHub 源安装会直接拉取并构建 Git 依赖;pnpm 10 及以上版本可能要求先在 profile 的 `pnpm-workspace.yaml` 中允许该依赖执行构建脚本。普通用户建议优先使用 npm 稳定版。
205
207
 
208
+ > **遇到 “pnpm 大版本不同” 报错**(提示 `run the pnpm major that built this node_modules`,或中文提示 node_modules 由另一个大版本的 pnpm 建成):说明 profile 的 `node_modules` 由另一个 pnpm 大版本(如 10.x)建成,而本次安装运行的是另一个大版本(如 11.x)。pnpm 跨大版本复用 `node_modules` 的行为随版本而异(12.17 起会以 `ERR_PNPM_MODULES_BREAKING_CHANGE` 直接拒绝执行),且各版本会在任何 `storeDir` 下再拼自己的版本目录,因此调整 `storeDir` 无法绕过,执行一旦失败,失败后的自动回滚也会以同样方式失败。任选其一处理后重试:
209
+ >
210
+ > 1. **清空重建(推荐;插件市场的 UI 安装只能走这条)**:退出 DSH,删除 profile 的 `node_modules` 后重新安装。已装插件会按 profile 的 `package.json` 自动恢复,包会重新下载一次:
211
+ >
212
+ > ```sh
213
+ > # macOS / Linux(profile 名称按实际调整)
214
+ > rm -rf ~/.dsh/profiles/web/node_modules
215
+ > ```
216
+ >
217
+ > ```powershell
218
+ > # Windows PowerShell
219
+ > Remove-Item -Recurse -Force "$env:USERPROFILE\.dsh\profiles\web\node_modules" # profile 名称按实际调整
220
+ > ```
221
+ >
222
+ > 2. **改用建这份 `node_modules` 的 pnpm 大版本执行命令行安装**:把该版本的 pnpm 提到 `PATH` 最前(macOS Homebrew 安装的 pnpm 位于 `/opt/homebrew/bin`):
223
+ >
224
+ > ```sh
225
+ > # macOS / Linux
226
+ > PATH="/opt/homebrew/bin:$PATH" dsh plugin --profile web add --save-exact github:xmanrui/dsh-im
227
+ > ```
228
+ >
229
+ > ```powershell
230
+ > # Windows PowerShell
231
+ > $env:PATH = "<pnpm 10.x 所在目录>;$env:PATH"; dsh plugin --profile web add --save-exact github:xmanrui/dsh-im
232
+ > ```
233
+ >
234
+ > `npx -y github:xmanrui/dsh-im install` 会在调用 pnpm 前检测这类不匹配(兼容 pnpm 12 写入的 JSON 格式 `.modules.yaml`),并给出与上面相同的提示。
235
+
206
236
  安装后,在对应渠道页面按照内置引导完成扫码或凭据配置。所有 Secret 和 Token 只提交给本机 Harness Host,并写入受保护的凭据存储;状态接口和机器人列表不会回传这些凭据。
207
237
 
208
238
  如果本机必须通过正向代理访问飞书,请在启动 `dsh web` 前把 `HTTPS_PROXY` 设置为包含协议的 HTTP 代理 URL(例如 `http://proxy:8080`;也支持小写 `https_proxy`,并兼容使用 `HTTP_PROXY` 作为回退),修改后重启 Host。飞书注册和凭据验证会复用 SDK 的代理感知 HTTP 客户端,消息长连接会显式通过这个代理建立 WebSocket;长连接目前不读取 `ALL_PROXY` 或 `NO_PROXY`。
@@ -230,6 +260,7 @@ dsh web
230
260
  | 飞书指令面板 | 每个飞书机器人可在「更多设置 → 指令面板」里决定聊天输入框打 `/` 时列出哪些指令、按什么顺序:「跟随默认」使用插件自带的 31 条清单(随插件版本更新),「自定义」则恰好是所选指令和所选顺序。隐藏只是不在候选里出现,手动输入同一命令照旧可用;清单之外手工添加的指令不会被删除。配好一个机器人后,可用「保存并同步到其他机器人」一次写到该渠道的其他所有机器人(会覆盖它们各自的面板设置;离线机器人下次启动时生效)。保存后由机器人后台同步,指令较多时需要一点时间。 |
231
261
  | 飞书被 @ 时开话题 | 默认开启。在群聊或私聊里 @机器人 提问时,机器人会在那条消息下新建一条飞书话题,问答都落在话题内;该话题是 dsh 会话列表里一条独立会话,话题里的后续消息属于同一个会话。只发一个 @机器人(打开菜单)不会新建话题,没有 @机器人 的消息仍留在原会话。可在机器人卡片的「群聊」设置里关闭,关闭后群聊与私聊都恢复平铺回复。 |
232
262
  | 飞书任务过程展示 | 每个飞书机器人可选择不显示过程、实时直播、实时过程卡或逐步消息。实时直播使用飞书原生思考过程展示推理、工具调用和结果,最终答案单独发送;需要飞书 PC 7.70、移动端 7.74 或更新版本。飞书原生思考过程目前无法发到话题内,因此话题中的回合会改用实时过程卡,过程与答案都留在话题里。 |
263
+ | 飞书最终答案格式 | 不显示过程时,流式卡不可用、创建失败或封存失败,最终答案仍优先通过支持 Markdown 的富文本消息发送;保留原话题路由,只有富文本也被拒绝时才降级为纯文本,不会再次请求模型。 |
233
264
  | 会话渠道标识 | 本机 Host 的 IM 渠道与 AI Office 会话自动标记来源。Web 会话列表和搜索结果将「微信 ·」等前缀显示为渠道 Logo;保留 DSH 原有的自动标题生成与更新。已有会话在下次加载时补上。 |
234
265
 
235
266
  渠道前缀在 DSH 生成标题后追加,完整保留原始标题与自动/手动来源,不会将自动标题锁定为手动命名,也不会额外调用模型。重复生成、刷新或重启不会叠加前缀;真实的手动命名仍遵循 DSH 原有的锁定规则。此功能由当前 Host 的会话事件驱动,显式连接远程 `harnessBaseUrl` 时需在目标 Host 上安装该插件。
@@ -276,10 +307,11 @@ const info = await dshIm.describeConversation(sessionId);
276
307
 
277
308
  - 只读:不访问网络、不创建会话、不阻塞回复,也不抛错;未知会话返回 `null`。
278
309
  - 数据全部来自插件自己的状态文件(`sessions` 映射)与机器人配置,不要求内核新增字段。
279
- - `chatType` 为 `group`、`thread` 或 `dm`;`direct:dm:<id>` 形式的键会把 `<id>` 填进 `senderId`。
310
+ - `chatType` 为 `group`、`thread` 或 `dm`。没有作者记录时,只有当键本身标识用户时才从键推出 `senderId`:Matrix `direct:dm:<userId>`、`p2p:<id>`(飞书、微信、企业微信自建应用、钉钉)、QQ `c2c:<openid>`,以及 Telegram 和企业微信的 `direct:<id>`。Slack、Discord、WhatsApp、iMessage 等渠道的 `direct:<id>` 标识的是私聊频道,因此放进 `chatId`,`senderId` 保持 `null`。
280
311
  - 每个会话首次反查写一行日志 `[dsh-im] describeConversation session=… chat=… sender=…`,之后不再重复。
281
- - 发言人会被记住:桥接在把消息交给会话之前,把 `senderId`、显示名、`username` 与「是否机器人」写进机器人状态文件(`authors`),每条新消息覆盖前一条,只保留身份、不保留文本;因此重启后仍然可读。
282
- - 私聊的 `senderId` 还可以从键 `direct:dm:<id>` 推出,即使作者记录缺失也有值;群聊作者在第一条入站消息之前为 `null`。
312
+ - 发言人会被记住:桥接在把消息交给会话之前,把 `senderId` 与「是否机器人」写进机器人状态文件(`authors`);显示名和 `username` 只有在该聊天类型启用了上下文增强(或渠道本身提供发言人名称,如 Matrix)时才记录,否则为 `null`,每条新消息覆盖前一条,只保留身份、不保留文本;因此重启后仍然可读。
313
+ - 上述渠道的私聊 `senderId` 即使作者记录缺失也能从键推出;群聊作者在第一条入站消息之前为 `null`。
314
+ - 由对话键插入数字聊天/话题字段的链接是 **Telegram 专用**;QQ 和其他渠道必须使用各自的原生 route 字段,不能把它们当作 Telegram 链接。
283
315
 
284
316
  同一个反查还有一个同步版本,供在同步上下文里组装的场景使用(例如系统提示词的渲染):
285
317
 
@@ -301,7 +333,10 @@ const info = dshIm.describeConversationSync(sessionId);
301
333
  | `dsh-im/session-unbind` | 对话不再指向原会话:切换到另一个会话,或绑定被清除 | 同上,但没有作者字段;`sessionId` 是被解绑的旧会话 |
302
334
 
303
335
  - 两个事件同步发出,顺序是「先解绑旧的、再绑定新的」,订阅方能一条线读完。
336
+ - 所有聊天通道都会发这两个事件:Telegram、Discord、Email、iMessage 走共用的生产控制器;DingTalk、飞书、Matrix、QQ、Slack、企业微信(`wecom` 与 `wecom-app`)、微信(`weixin`)和 WhatsApp 各自组装控制器,但状态同样经过同一层封装。`office` 是任务连接器,没有对话,因此不发这两个事件。
337
+ - 自己组装生产控制器的通道不要直接 `new StateStore(path).load()`:用 `createAnnouncedStateStore({ announcer, StateStore, statePath })`,它按机器人只加载一次并返回已包装的 store,同时给出投递适配器需要的 `stateForSync`;启动时用 `prime()` 预热,第一次提示词组装才能同步拿到身份。
304
338
  - 只有真正提交的写入才会发事件:写入被拒绝(返回 `false`)或写成同一个会话时不发 `unbind`。
339
+ - 订阅方必须按 `(conversationKey, sessionId)` 做到幂等:重复写入同一条绑定会再发一次绑定事件,协议上分不出这次重复和第一次。
305
340
  - 清除一个会话绑定(`clearSession`)和清除全部绑定(`clearSessions`)同样会按对话逐个发 `session-unbind`。
306
341
  - 订阅方抛错不影响消息处理。
307
342
  - 解绑不代表会话的身份消失:把它留在自己的表里(例如带 `superseded_at`)仍可让独占该会话的定时任务继续投递到原来的对话,只是「谁拥有这个对话」要按最新一次绑定算。
@@ -351,9 +386,10 @@ const info = dshIm.describeConversationSync(sessionId);
351
386
  | `/clear` | 清空当前聊天绑定会话的模型上下文,同时保留 Session 绑定和历史记录;当前 Host 未注册该命令时会明确提示未支持。 |
352
387
  | `/workspace [工作区序号或绝对路径]`、`/ws [...]` | 查看并切换当前机器人的 Harness 工作区:不带参数时列出可切换的工作区(Telegram 上为可点击卡片,点一下即切换,原地标记当前项);带序号或绝对路径时直接切换。 |
353
388
  | `/workspacelist`、`/workspaces`、`/wsl` | `/workspace` 的旧别名,等同无参数形式;原生命令菜单只保留一个工作区入口。 |
354
- | `/sessionlist [工作区序号或绝对路径]`、`/sessions [...]` | 两个等价命令;列出指定工作区的会话 ID 和标题,默认 IM 目录也包含其中的未分组会话;省略参数时使用当前工作区。 |
389
+ | `/sessionlist [工作区序号或绝对路径]`、`/sessions [...]` | 两个等价命令;列出指定工作区的会话 ID 和标题,并标出本对话已绑定的会话(「(当前绑定)」);默认 IM 目录也包含其中的未分组会话;省略参数时使用当前工作区。 |
390
+ | `/sessionlist --all`、`/sessions --all` | 跨工作区汇总会话:当前对话有效工作区置顶并标注,每个工作区默认显示 10 条,可用 `--limit N` 调整;读取失败的工作区会跳过并提示数量。 |
355
391
  | `/sessionlist --limit N`、`/sessions --limit N` | 列出当前工作区现有顺序中的前 N 个会话;N 必须是正整数。 |
356
- | `/session <Session ID>` | 将当前聊天绑定到指定的已有 Harness 会话。 |
392
+ | `/session <Session ID、序号或标题关键词>` | 将当前聊天绑定到指定的已有 Harness 会话;标题关键词只在当前对话工作区唯一命中时自动绑定,其他情况要求完整 Session ID;已归档的会话不会被关键词选中。 |
357
393
  | `/history [数量]` | 在私聊中查看当前绑定会话的最近历史消息,默认 3 条,最多 5 条。 |
358
394
  | 交互式提问 | 回复选项序号、选项文字或自定义文字;多选时用逗号分隔。飞书中,提问发起人发送图片或图文消息会结束本轮追问,并在同一会话继续处理图片,无需答完剩余问题或重新发图。 |
359
395
  | 远程审批 | 回复 `批准` / `拒绝` / `同意` / `不同意` / `yes` / `no`。 |
@@ -375,7 +411,7 @@ Web 与机器人可同时处理同一审批,先提交的「批准一次」或
375
411
 
376
412
  - **图片识别**:支持图片输入的内置渠道都可以把 JPEG、PNG、WebP,以及以图片文件方式发送的 GIF 交给 Harness;图片可以附带文字说明。默认每张原图最多接收 30 MB、每条消息最多 20 张;原图保存到会话工作区,模型副本自动缩放或压缩到单张 5 MB、总计 20 MB 以内,仍超限或模型不支持图片时按文件交给模型处理。这四项限制可在「通用设置 → 附件 → 图片输入」调整,对后续消息生效;原图沿用附件保留时长。调高模型输入上限会增加请求体积、处理耗时和模型成本,也仍受平台及宿主限制。iMessage 首版仅支持文本私聊。
377
413
  - **在机器人卡片切换工作区**:设置页中的每张机器人卡片都会显示当前 Harness 工作区。可以直接填写已有目录的绝对路径,也可以打开目录选择器。切换只清除该机器人的旧聊天映射,不会删除、清空或归档旧 Session;已经开始的回复可以继续完成,后续消息使用新工作区。
378
- - **默认目录与未分组会话**:所有使用默认值的机器人共用 `$DSH_HOME/im`,但各自保存聊天与会话的绑定。插件不会为该目录创建工作区分组;`/sessions` 可以列出该目录的未分组会话,`/session <Session ID>` 或 `/session N` 可以绑定普通会话。切换到其他目录后,新会话按现有机制加入对应工作区分组;切回默认目录后新会话归入「未分组」。已有机器人的目录不会自动迁移。
414
+ - **默认目录与未分组会话**:所有使用默认值的机器人共用 `$DSH_HOME/im`,但各自保存聊天与会话的绑定。插件不会为该目录创建工作区分组;`/sessions` 可以列出该目录的未分组会话,`/session <Session ID>`、`/session N` 或 `/session <标题关键词>` 可以绑定普通会话。切换到其他目录后,新会话按现有机制加入对应工作区分组;切回默认目录后新会话归入「未分组」。已有机器人的目录不会自动迁移。
379
415
  - **在机器人卡片选择模型与思考强度**:每个 IM 渠道的每张机器人卡片都在工作区下方提供模型与思考强度入口,采用 DSH 风格的分组列表、档位说明和选中标记。先选择 Host 当前可用模型,再选择其支持的强度,或跟随模型默认;未选模型时整体跟随 Host 默认。设置按机器人独立保存,只用于之后新建的 Session;已有 Session 和正在生成的回复不受影响。
380
416
  - **在机器人卡片选择 Agent Preset**:设置页中的每张机器人卡片都可以选择 Host 已有的 Agent Preset,或跟随 Host 默认。切换只作用于该机器人,并且只影响之后新建的会话;已有会话和正在生成的回复不受影响。
381
417
  - **检查连接并发送测试消息**:机器人在线时,点击卡片上的「检查连接」会检查平台连接,并向该机器人最近记录的私聊发送一条“DeepSeek Harness 连接测试成功”消息;WhatsApp 会发送到账号自聊。测试消息不会创建 Harness Session,也不会调用模型。机器人必须至少收到过一条私聊才能记住测试目标,否则页面会提示尚无可用的测试会话。
@@ -399,9 +435,11 @@ Web 与机器人可同时处理同一审批,先提交的「批准一次」或
399
435
 
400
436
  ## 本地开发
401
437
 
402
- 最新版 dsh-im 跟随最新版 DSH,本次支持基线为 DSH `0.2.1-rc.2`(Session 格式 v4)。后续功能和修复不再增加旧版 DSH 的兼容分支,已有其他兼容逻辑暂时保留;旧宿主请使用对应的历史插件版本。`package.json` 只声明当前实际验证的宿主版本,不承诺未经验证的未来版本。升级插件后重启 Host 并刷新设置页,使 Host 和客户端使用同一版插件。
438
+ 最新版 dsh-im 跟随最新版 DSH,本次支持基线为 DSH `0.2.2-rc.5`(Session 格式 v4)。后续功能和修复不再增加旧版 DSH 的兼容分支,已有其他兼容逻辑暂时保留;旧宿主请使用对应的历史插件版本。`package.json` 只声明当前实际验证的宿主版本,不承诺未经验证的未来版本。升级插件后重启 Host 并刷新设置页,使 Host 和客户端使用同一版插件。
439
+
440
+ DSH `0.2.2-rc.5` 要求内部网关请求携带调用方 `peer`。所有渠道共用的适配层通过 Host Connection 创建并复用该身份,同时用于普通调用和流式调用,在插件卸载时释放。
403
441
 
404
- DSH `0.2.1-rc.2` 要求内部网关请求携带调用方 `peer`。所有渠道共用的适配层通过 Host Connection 创建并复用该身份,同时用于普通调用和流式调用,在插件卸载时释放。微信和 QQ 的新会话、已有会话收发已完成真机验证。
442
+ 适配 0.2.2-rc.5 时需要更新两处与宿主版本绑定的声明:`package.json` 的 `dsh.compatibility`(验证基线)和 `dsh.client.inject`(客户端加载顺序)。客户端槽位服务由 `@deepseek-ai/dsh-client-ui-renderer` 提供,工作区服务由 `@deepseek-ai/dsh-client-ui-workspace` 提供;`@deepseek-ai/dsh-client-runtime` 自 0.1.1-rc.2 后不再发布,`@deepseek-ai/dsh-client-ui-slots` 不是可加载的客户端行,二者都不能写进 `inject`——旧声明在 0.2.2-rc.5 会让客户端行等一个永远不会到达的依赖。`test/package-client-inject.test.mjs` 锁定这份清单,`scripts/verify-package.mjs` 会核对 `dsh.compatibility` 的基线与 `dshReleases` 一致、且 `inject` 不含这两个退役包名。
405
443
 
406
444
  上下文增强中的来源信息、引导词和引用回复使用 v4 的 `plugin:dsh-im` 来源字段,修复了它们触发的 `SessionFormatError: format v4 message requires a producer-owned source kind`。消息顺序、用户正文和会话级引导词去重沿用原有机制,历史会话由宿主负责迁移。
407
445
 
package/bin/dsh-im.mjs CHANGED
@@ -59,6 +59,68 @@ async function directProfilePackages(profile) {
59
59
  }
60
60
  }
61
61
 
62
+ /** Major version of the pnpm `dsh plugin` will reach through PATH; null when it cannot be determined. */
63
+ function currentPnpmMajor() {
64
+ // npm/corepack expose .cmd shims on Windows that only a shell can start; the argv is constant, so
65
+ // enabling the shell there has no injection surface. The probe runs from tmpdir() to mirror runDsh,
66
+ // so corepack resolves the same version it would for the actual command.
67
+ const result = spawnSync('pnpm', ['--version'], {
68
+ encoding: 'utf8',
69
+ shell: process.platform === 'win32',
70
+ cwd: tmpdir(),
71
+ });
72
+ if (result.error || result.status !== 0 || typeof result.stdout !== 'string') return null;
73
+ const match = result.stdout.trim().match(/^(\d+)\./);
74
+ return match ? Number(match[1]) : null;
75
+ }
76
+
77
+ /** The pnpm major that built node_modules, from the manifest pnpm writes: YAML through 11, JSON since 12. */
78
+ function builtPnpmMajor(modules) {
79
+ const match = modules.match(/^\s*["']?packageManager["']?\s*:\s*["']?pnpm@(\d+)\./m);
80
+ return match ? Number(match[1]) : null;
81
+ }
82
+
83
+ /**
84
+ * Refuse to run when the profile's node_modules was built by another pnpm major. How pnpm treats a
85
+ * cross-major node_modules varies by version (12.17 and newer refuse outright; older versions may
86
+ * rebuild, but every major appends its own directory under any storeDir, so a storeDir override
87
+ * cannot fix an install and the automatic rollback fails the same way once an install goes wrong).
88
+ * The refusal is fail-closed on purpose: remedy 1 costs a re-download of store-cached packages,
89
+ * while the destructive path costs a broken profile. Skips silently whenever the check cannot
90
+ * decide (no node_modules yet, unrecognisable manifest, no pnpm on PATH — the dsh command reports
91
+ * that itself), and never assumes more than the default PATH resolution: a profile or host that
92
+ * pins pnpmCommand runs its own pnpm regardless.
93
+ */
94
+ async function assertCompatiblePnpmModules(profile, remedy, operation) {
95
+ const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh');
96
+ const modulesDir = join(dshHome, 'profiles', profile, 'node_modules');
97
+ let modules;
98
+ try {
99
+ modules = await readFile(join(modulesDir, '.modules.yaml'), 'utf8');
100
+ } catch {
101
+ return;
102
+ }
103
+ const builtMajor = builtPnpmMajor(modules);
104
+ const runningMajor = currentPnpmMajor();
105
+ if (builtMajor === null || runningMajor === null || builtMajor === runningMajor) return;
106
+ const windows = process.platform === 'win32';
107
+ const wipe = windows
108
+ ? `Remove-Item -Recurse -Force "${modulesDir}"`
109
+ : `rm -rf "${modulesDir}"`;
110
+ const repath = windows
111
+ ? `$env:PATH = "<pnpm ${builtMajor} 所在目录>;$env:PATH";`
112
+ : `PATH="/opt/homebrew/bin:$PATH"`;
113
+ throw new Error([
114
+ `profile ${profile} 的 node_modules 由 pnpm ${builtMajor}.x 建成,而 \`dsh plugin\` 会通过 PATH 调到 pnpm ${runningMajor}.x,本次${operation}很可能失败:pnpm 跨大版本复用 node_modules 的行为随版本而异(12.17 起会以 ERR_PNPM_MODULES_BREAKING_CHANGE 拒绝执行),且各版本会在任何 storeDir 下再拼自己的版本目录,调整 storeDir 修不好;一旦执行失败,失败后的自动回滚也会以同样方式失败。`,
115
+ '任选其一处理后重跑本命令:',
116
+ ` 1) 清空 node_modules 让当前 pnpm 重建(插件市场的 UI 安装只能走这条;已装插件会按 package.json 自动恢复,包会重新下载一次):`,
117
+ ` ${wipe}`,
118
+ ` 2) 改用 pnpm ${builtMajor}.x 执行同一命令(把该版本的 pnpm 提到 PATH 最前,路径按本机安装位置调整;macOS Homebrew 安装在 /opt/homebrew/bin):`,
119
+ ` ${repath} ${remedy}`,
120
+ '(若 profile 或宿主通过 pnpmCommand 固定了 pnpm 路径,本探测可能不代表实际执行的那份 pnpm。)',
121
+ ].join('\n'));
122
+ }
123
+
62
124
  const args = process.argv.slice(2);
63
125
  const command = args.shift();
64
126
 
@@ -77,6 +139,8 @@ try {
77
139
  : (isAbsolute(requested) ? requested : requested);
78
140
  if (args.length > 0) throw new Error(`无法识别的参数:${args.join(' ')}`);
79
141
 
142
+ await assertCompatiblePnpmModules(profile, `dsh plugin --profile ${profile} add --save-exact ${source}`, '安装');
143
+
80
144
  const legacy = await directProfilePackages(profile);
81
145
  runDsh(['plugin', '--profile', profile, 'add', '--save-exact', source]);
82
146
  for (const packageName of legacy) {
@@ -88,6 +152,7 @@ try {
88
152
  }
89
153
  } else if (command === 'uninstall') {
90
154
  if (args.length > 0) throw new Error(`无法识别的参数:${args.join(' ')}`);
155
+ await assertCompatiblePnpmModules(profile, `dsh plugin --profile ${profile} remove ${PACKAGE_NAME}`, '卸载');
91
156
  runDsh(['plugin', '--profile', profile, 'remove', PACKAGE_NAME]);
92
157
  console.log('\nIM 机器人插件已卸载。请重启 dsh web。');
93
158
  } else {
@@ -8,6 +8,10 @@ The optional `dshImClient` service exposes the existing IM management panel to a
8
8
 
9
9
  On DSH versions with plugin detail actions, **Open IM bots** opens the same management panel in the main area. The panel has no back button; use the host sidebar to switch panels. This entry uses the optional `layout` service and the `plugins.detail.actions` slot. Older DSH versions retain the Settings entry.
10
10
 
11
+ 「IM机器人」页面右上角的「会话记录」按钮与「通用设置」并列,打开各 IM 通道已绑定会话的只读列表;点击 Session ID 可查看用户与助手正文、刷新或加载更早消息。列表和正文页均提供「返回 IM机器人」。会话记录不注册独立侧边栏入口;只有宿主提供导航服务与主面板槽位时才显示按钮。目录覆盖标准机器人状态路径、微信账号状态和已配置的飞书旧版状态,不推断自定义 `dataDir` / `botsDir`。
12
+
13
+ **Session history**, next to **General settings** in the IM bots toolbar, opens a read-only list of bound IM sessions. Select a Session ID to read user and assistant text, refresh, or load earlier messages. Both the list and transcript provide **Back to IM bots**. History has no separate sidebar entry, and the toolbar action appears only when the host provides navigation and a main-panel slot. Discovery covers standard bot state, Weixin accounts, and configured Feishu legacy state; custom `dataDir` / `botsDir` overrides are not inferred.
14
+
11
15
  支持 `sidebar.panellist` 的宿主同时提供左侧「IM机器人」入口,与插件详情操作共用同一个 `main` 面板。侧栏沿用插件页的双对话框造型,在 16×16 矢量画布上使用与宿主普通图标一致的 1px 描边,通过 `currentColor` 跟随侧栏颜色和传入尺寸;插件页仍使用原彩色图标。此入口不调用 `setSettingsVisible()`,设置入口和插件详情操作均保留。侧栏槽位消失时只移除侧栏入口,主面板或依赖服务退出时清理全部对应注册。
12
16
 
13
17
  Hosts with `sidebar.panellist` also show **IM bots** in the left sidebar, targeting the same `main` panel as the detail action. The sidebar retains the catalog's linked speech bubbles as a 16×16 vector with the host's regular 1px stroke, using `currentColor` and the requested icon size; the catalog keeps its original color image. This entry does not call `setSettingsVisible()`: both existing entry points remain available. Sidebar withdrawal removes only its entry, while main-slot or navigation-service withdrawal cleans up all related registrations.