dsh-aiyayi 1.5.34 → 1.5.35

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.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > **维护约定**:新版本发布时在顶部加条目。本文件由 README 正文拆出(2026-11-09 重构):版本条目与踩坑记录原文照录,数字、时间、日期一律不改(量化保真是本插件的规矩)。版本事实以 npm registry 为准。
4
4
  >
5
- > **npm 发布一览(2026-11-11 核对 registry,`npm view dsh-aiyayi versions --json`)**:latest = **1.5.28**(2026-11-11 发布;**初版记为 1.5.27,1.5.29 发版时据 registry 更正**)。已发布:1.0.0、…、1.5.7、**1.5.14**、**1.5.15**、**1.5.16**、**1.5.17**、**1.5.20**、**1.5.21**、**1.5.22**、**1.5.23**、**1.5.24**、**1.5.25**、**1.5.26**、**1.5.27**、**1.5.28**;跳号 1.3.0、1.4.1、1.4.2、1.5.0、1.5.1、1.5.2、1.5.3、**1.5.8–1.5.13** 从未发布到 npm(本地开发线:1.5.8–1.5.11 飞书桥接、1.5.12 思考纪律约束、1.5.13 内置技能同步+feishu-setup 骨架);1.5.14 已发布(坑 #58–#67 修复);1.5.15 已发布(扫码接入改造);1.5.16 已发布(feishu-setup 技能脚本入包);1.5.17 已发布(坑 #68 重入保护修复);**1.5.18 / 1.5.19 也从未发布到 npm**(见下方 1.5.18 / 1.5.19 条目——它们的代码最终随 1.5.20 一起进 npm);**1.5.20 已发布**(飞书正文改走 interactive 卡片 + lark_md,含 1.5.19 附件收发与问答卡片、1.5.20 markdown 渲染,以及 create-bot v6 权限集中化);**1.5.21 已发布**(修飞书回复正文首尾空白行,坑 #72);**1.5.22 已发布**(多应用多长连接改造+chat 归属机制,见下方 1.5.22 条目);**1.5.23–1.5.25 已发布**(230001 边界/补 import/补 feishuCode 挖码三轮装版断言增量修复,见下方对应条目);**1.5.26 已发布**(回发多文本段覆盖丢段修复,坑 #73,见下方 1.5.26 条目);**1.5.27 已发布**(微信通道并入,默认关闭,见下方 1.5.27 条目);**1.5.28 已发布**(PowerShell 版本体检 + 微信通道收尾,见下方 1.5.28 条目);**1.5.29 已发布**(发布包排除 `test/` + 测试残留空目录清理,见下方 1.5.29 条目);**1.5.30 已发布**(create-bot 注释改用 `<记忆根>` 占位,见下方 1.5.30 条目);**1.5.31 已发布**(PowerShell 体检 `major:null` 根因修复:探测链补上 powershell.exe 一级,见下方 1.5.31 条目);**1.5.32 已发布**(行为变更:首次提示同时告知微信 ClawBot 能力 + 「对接默认落到发起对接的会话」固化为 persona 准则/文档;不含路由代码改动,见下方 1.5.32 条目);**1.5.33 已发布**(同一准则落成代码:未绑定 chat 三档复用,不再无条件新建会话,见下方 1.5.33 条目);**1.5.34 为本次发版版**(纯测试修复:`presence-clock` 跨午夜偶发失败,`lib/` 零改动,见下方 1.5.34 条目;其 npm 发布状态以 registry 为准)。
5
+ > **npm 发布一览(2026-11-12 核对 registry,`npm view dsh-aiyayi versions --json`)**:latest = **1.5.35**(本次发版版;registry 实况 latest 目前仍为 **1.5.34**,1.5.35 的 publish 由下一步单独执行,发布后以 registry 为准)。已发布:1.0.0、…、1.5.7、**1.5.14**、**1.5.15**、**1.5.16**、**1.5.17**、**1.5.20**、**1.5.21**、**1.5.22**、**1.5.23**、**1.5.24**、**1.5.25**、**1.5.26**、**1.5.27**、**1.5.28**、**1.5.29**、**1.5.30**、**1.5.31**、**1.5.32**、**1.5.33**、**1.5.34**;跳号 1.3.0、1.4.1、1.4.2、1.5.0、1.5.1、1.5.2、1.5.3、**1.5.8–1.5.13** 从未发布到 npm(本地开发线:1.5.8–1.5.11 飞书桥接、1.5.12 思考纪律约束、1.5.13 内置技能同步+feishu-setup 骨架);1.5.14 已发布(坑 #58–#67 修复);1.5.15 已发布(扫码接入改造);1.5.16 已发布(feishu-setup 技能脚本入包);1.5.17 已发布(坑 #68 重入保护修复);**1.5.18 / 1.5.19 也从未发布到 npm**(见下方 1.5.18 / 1.5.19 条目——它们的代码最终随 1.5.20 一起进 npm);**1.5.20 已发布**(飞书正文改走 interactive 卡片 + lark_md,含 1.5.19 附件收发与问答卡片、1.5.20 markdown 渲染,以及 create-bot v6 权限集中化);**1.5.21 已发布**(修飞书回复正文首尾空白行,坑 #72);**1.5.22 已发布**(多应用多长连接改造+chat 归属机制,见下方 1.5.22 条目);**1.5.23–1.5.25 已发布**(230001 边界/补 import/补 feishuCode 挖码三轮装版断言增量修复,见下方对应条目);**1.5.26 已发布**(回发多文本段覆盖丢段修复,坑 #73,见下方 1.5.26 条目);**1.5.27 已发布**(微信通道并入,默认关闭,见下方 1.5.27 条目);**1.5.28 已发布**(PowerShell 版本体检 + 微信通道收尾,见下方 1.5.28 条目);**1.5.29 已发布**(发布包排除 `test/` + 测试残留空目录清理,见下方 1.5.29 条目);**1.5.30 已发布**(create-bot 注释改用 `<记忆根>` 占位,见下方 1.5.30 条目);**1.5.31 已发布**(PowerShell 体检 `major:null` 根因修复:探测链补上 powershell.exe 一级,见下方 1.5.31 条目);**1.5.32 已发布**(行为变更:首次提示同时告知微信 ClawBot 能力 + 「对接默认落到发起对接的会话」固化为 persona 准则/文档;不含路由代码改动,见下方 1.5.32 条目);**1.5.33 已发布**(同一准则落成代码:未绑定 chat 三档复用,不再无条件新建会话,见下方 1.5.33 条目);**1.5.34 已发布**(纯测试修复:`presence-clock` 跨午夜偶发失败,`lib/` 零改动,见下方 1.5.34 条目);**1.5.35 为本次发版版**(`feishu_status` 新增最近入站路由回看 `inboundRouting` 字段,见下方 1.5.35 条目;其 npm 发布状态以 registry 为准)。
6
6
  >
7
7
  > **环境标识约定(2026-11-10 新增)**:写版本条目/坑条目时,**顺手记录当时的 智能体工具-智能体模式-模型供应商-模型**(如 **DSH-创造模式-loomy讯飞-GLM5.3FLASH**),写在条目内(紧跟 git 记录行、或坑条目首行),方便回溯该条目是在哪套智能体/模型环境下产出与验证的。
8
8
 
@@ -10,6 +10,16 @@
10
10
 
11
11
  ---
12
12
 
13
+ ## 1.5.35(2026-11-12 新增:`feishu_status` 最近入站路由回看 `inboundRouting` 字段)
14
+
15
+ - 环境:DSH-执行智能体(DeepSeek Harness 子会话,模型名未确证)
16
+ - **改了什么(只动 `lib/` 与新增测试,无对外行为变更)**:
17
+ - `lib/feishu-logic.js`:新增 `INBOUND_ROUTING_FILE='inbound-routing.json'`、`INBOUND_ROUTING_LIMIT=20`、`readInboundRouting(root)`、`appendInboundRouting(root,{at,chatId,appId,action,sessionId})`(空 chatId 忽略;环形缓冲 新→旧 超 20 丢最旧;写入 feishu 子目录)。
18
+ - `lib/feishu.js`:`onIncomingMessage()` 各路由分支(select/route/auto-new/bind/new/reuse/choose/new-fallback)调用 `recordRouting(action,sessionId)`;`feishu_status` 返回新增 `inboundRouting` 字段(读 `readInboundRouting(root)`)。
19
+ - **为什么**:`feishu_status` 此前只报当前绑定/应用状态,看不到最近入站消息被路由到哪个会话、怎么路由的,排查"消息去哪了"要翻日志;回看字段让最近的入站路由一目了然(新→旧,上限 20 条)。
20
+ - **测试**:新增 `test/feishu-inbound-routing.test.mjs`(本文件单跑全过);全量 159 项 3 挂 = 既有环境基线(`alarm-inject`/`home-relocate`/`tools-surface` 磁盘探测,非本次引入,与 1.5.21/1.5.22/1.5.27 条目同基线)。
21
+ - 打包与 npm publish **不在本次范围**:本版只做版本号对齐 + 推 git(gitcode / gitee / github 三远端),打包与 npm 发布留作下一步单独执行。
22
+
13
23
  ## 1.5.34(2026-11-12 修复:`presence-clock.test.mjs` 跨午夜偶发失败——**只改测试,无运行时行为变化**)
14
24
 
15
25
  - 环境:DSH-执行智能体(DeepSeek Harness 子会话,模型名未确证)
@@ -98,6 +98,46 @@ export function writeChatOwners(root, owners) {
98
98
  writeFileSync(join(dir, CHAT_OWNERS_FILE), JSON.stringify(owners, null, 2), 'utf8')
99
99
  }
100
100
 
101
+ // ─── 1.5.35 最近入站路由回看 ──────────────────────────────────────────────
102
+ // feishu_status 的「最近入站路由」:记录最近 N 条来自飞书的消息各自路由进了
103
+ // 哪个 aiyayi 会话/工作区(或走了绑定/复用/新建/待选),持久化到 feishu 子目录
104
+ // (inbound-routing.json),重启不丢。供本体排障「我在飞书发了消息但没接到
105
+ // 当前会话」时直接对上号:chatId → sessionId(或新建/待选动作)。
106
+
107
+ /** 最近入站路由记录文件名(数组,新→旧)。 */
108
+ const INBOUND_ROUTING_FILE = 'inbound-routing.json'
109
+ /** 环形缓冲上限:只保留最近 N 条路由记录。 */
110
+ export const INBOUND_ROUTING_LIMIT = 20
111
+
112
+ /** 读最近入站路由记录(新→旧);不存在/损坏返回 []。 */
113
+ export function readInboundRouting(root) {
114
+ const file = join(feishuDir(root), INBOUND_ROUTING_FILE)
115
+ if (!existsSync(file)) return []
116
+ try {
117
+ const parsed = JSON.parse(stripBom(readFileSync(file, 'utf8')))
118
+ return Array.isArray(parsed) ? parsed : []
119
+ } catch {
120
+ return []
121
+ }
122
+ }
123
+
124
+ /**
125
+ * 追加一条入站路由记录(新→旧,超上限丢最旧)。
126
+ * @param {string} root 记忆根
127
+ * @param {object} record { at:number, chatId:string, appId:string|null,
128
+ * action:string, sessionId:string|null }
129
+ * action ∈ route|bind|new|auto-new|reuse|select|choose|new-fallback。
130
+ * 空 chatId 忽略(防脏数据)。
131
+ */
132
+ export function appendInboundRouting(root, record) {
133
+ if (!record || !record.chatId) return
134
+ const list = readInboundRouting(root)
135
+ list.unshift({ at: record.at ?? Date.now(), ...record })
136
+ const trimmed = list.slice(0, INBOUND_ROUTING_LIMIT)
137
+ const dir = ensureFeishuDir(root)
138
+ writeFileSync(join(dir, INBOUND_ROUTING_FILE), JSON.stringify(trimmed, null, 2), 'utf8')
139
+ }
140
+
101
141
  /**
102
142
  * 归一化多应用配置。接受两种形态:
103
143
  * 新(1.5.22+):{ apps: [{ appId, appSecret, domain? }, ...] }
package/lib/feishu.js CHANGED
@@ -33,6 +33,7 @@ import { createLarkChannel } from '@larksuiteoapi/node-sdk'
33
33
  import { resolveRoot } from './home.js'
34
34
  import { registerOwnTool } from './own-tools.js'
35
35
  import {
36
+ appendInboundRouting,
36
37
  applyCardAction,
37
38
  buildNewSessionGuideText,
38
39
  buildNewSessionNotice,
@@ -71,6 +72,7 @@ import {
71
72
  readChatOwners,
72
73
  readConfigFile,
73
74
  readGuided,
75
+ readInboundRouting,
74
76
  readMappings,
75
77
  readPendingBind,
76
78
  readPendingQuestions,
@@ -621,6 +623,16 @@ async function onIncomingMessage(
621
623
  if (!chatId) return
622
624
  const appId = route?.app?.appId ?? null
623
625
 
626
+ // 1.5.35:入站路由回看记录——每条消息路由落点(绑定/复用/新建/待选)都记一条,
627
+ // 供 feishu_status 的 inboundRouting 字段查证「消息到底进了哪个会话」。不阻塞主流程。
628
+ const recordRouting = (action, sessionId = null) => {
629
+ try {
630
+ appendInboundRouting(root, { at: Date.now(), chatId, appId, action, sessionId })
631
+ } catch (error) {
632
+ ctx.logger.warn(`aiyayi-feishu: 记录入站路由失败: ${String(error)}`)
633
+ }
634
+ }
635
+
624
636
  // 1.5.22:归属记录(权威自愈)+ 跨 WS 去重。去重必须先于归属记录之外的一切处理。
625
637
  route?.recordChatOwner?.(chatId, appId)
626
638
  if (route?.markSeenOrDuplicate?.(messageId)) {
@@ -674,6 +686,7 @@ async function onIncomingMessage(
674
686
  const refreshed = readMappings(root)
675
687
  refreshed[chatId] = choice.sessionId
676
688
  writeMappings(root, refreshed)
689
+ recordRouting('select', choice.sessionId)
677
690
  await replyToChat(channel, chatId, messageId, `已把本对话接入:${choice.label}。`)
678
691
  return
679
692
  }
@@ -715,6 +728,7 @@ async function onIncomingMessage(
715
728
 
716
729
  if (decision.action === 'route') {
717
730
  const delivered = await deliverToSession(ctx, decision.sessionId, messageId, deliveryText)
731
+ recordRouting('route', decision.sessionId)
718
732
  if (delivered) return
719
733
  // 坑 #64:映射指向的会话可能已不在运行(插件 HMR/宿主重启回收、手动销毁),
720
734
  // 旧代码静默 return → 用户消息人间蒸发、零日志。这里自动新建并重新接入,
@@ -729,6 +743,7 @@ async function onIncomingMessage(
729
743
  messageId,
730
744
  `原会话 ${decision.sessionId} 已不在运行,已自动新建并接入 ${newSessionId}。`,
731
745
  )
746
+ recordRouting('auto-new', newSessionId)
732
747
  await deliverToSession(ctx, newSessionId, messageId, deliveryText)
733
748
  return
734
749
  }
@@ -743,6 +758,7 @@ async function onIncomingMessage(
743
758
  }
744
759
  mappings[chatId] = sessionId
745
760
  writeMappings(root, mappings)
761
+ recordRouting('bind', sessionId)
746
762
  await replyToChat(channel, chatId, messageId, `已把本对话接入会话 ${sessionId}。`)
747
763
  return
748
764
  }
@@ -754,6 +770,7 @@ async function onIncomingMessage(
754
770
  const refreshed = readMappings(root)
755
771
  refreshed[chatId] = sessionId
756
772
  writeMappings(root, refreshed)
773
+ recordRouting('new', sessionId)
757
774
  await replyToChat(channel, chatId, messageId, `已新建并接入 aiyayi 会话 ${sessionId}。`)
758
775
  await deliverToSession(ctx, sessionId, messageId, deliveryText)
759
776
  return
@@ -773,6 +790,7 @@ async function onIncomingMessage(
773
790
  const refreshed = readMappings(root)
774
791
  refreshed[chatId] = routing.sessionId
775
792
  writeMappings(root, refreshed)
793
+ recordRouting('reuse', routing.sessionId)
776
794
  await replyToChat(channel, chatId, messageId, buildReusedSessionNotice(chosen))
777
795
  await deliverToSession(ctx, routing.sessionId, messageId, deliveryText)
778
796
  return
@@ -784,6 +802,7 @@ async function onIncomingMessage(
784
802
  candidates: routing.candidates,
785
803
  createdAt: Date.now(),
786
804
  })
805
+ recordRouting('choose')
787
806
  await replyToChat(
788
807
  channel,
789
808
  chatId,
@@ -798,6 +817,7 @@ async function onIncomingMessage(
798
817
  const refreshed = readMappings(root)
799
818
  refreshed[chatId] = sessionId
800
819
  writeMappings(root, refreshed)
820
+ recordRouting('new-fallback', sessionId)
801
821
  await replyToChat(channel, chatId, messageId, buildNewSessionNotice(sessionId))
802
822
  await deliverToSession(ctx, sessionId, messageId, deliveryText)
803
823
  }
@@ -1457,6 +1477,8 @@ function registerFeishuTools(ctx, root, merged, apps, send = null) {
1457
1477
  return view
1458
1478
  })
1459
1479
  const boundChatAppId = boundChat ? (chatOwners[boundChat] ?? null) : null
1480
+ // 1.5.35:最近入站路由回看(新→旧)。字段:at(时间戳)/chatId/appId/action/sessionId。
1481
+ const inboundRouting = readInboundRouting(root)
1460
1482
  return {
1461
1483
  configured,
1462
1484
  // 语义不变:任一应用长连接在线即 true;具体每条看 apps[].connected。
@@ -1469,6 +1491,7 @@ function registerFeishuTools(ctx, root, merged, apps, send = null) {
1469
1491
  apps: appsView,
1470
1492
  chatOwners,
1471
1493
  singleApp: apps.length === 1,
1494
+ inboundRouting,
1472
1495
  }
1473
1496
  },
1474
1497
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aiyayi",
3
- "version": "1.5.34",
3
+ "version": "1.5.35",
4
4
  "license": "MIT",
5
5
  "author": "巴依浩爷 (bayihy)",
6
6
  "keywords": [