dsh-world 0.7.0 → 0.7.1

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 (75) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/INSTALL.md +314 -314
  3. package/LICENSE +21 -21
  4. package/NOTES.md +14 -3
  5. package/README.md +5 -4
  6. package/client/index.js +47 -2
  7. package/cordis.patch.yml +6 -6
  8. package/lib/archive.d.ts +3 -1
  9. package/lib/archive.js +6 -4
  10. package/lib/console/routes.d.ts +5 -0
  11. package/lib/console/routes.js +15 -4
  12. package/lib/console/snapshot.d.ts +5 -0
  13. package/lib/console/snapshot.js +2 -1
  14. package/lib/ecosystem/qq/route.d.ts +2 -1
  15. package/lib/ecosystem/qq/route.js +10 -2
  16. package/lib/ecosystem/qq-native/batch.d.ts +2 -0
  17. package/lib/ecosystem/qq-native/batch.js +3 -1
  18. package/lib/ecosystem/qq-native/index.d.ts +2 -0
  19. package/lib/ecosystem/qq-native/index.js +4 -0
  20. package/lib/ecosystem/qq-native/replies.d.ts +6 -1
  21. package/lib/ecosystem/qq-native/replies.js +19 -1
  22. package/lib/ecosystem/shared/context.d.ts +1 -1
  23. package/lib/ecosystem/shared/context.js +1 -1
  24. package/lib/ecosystem/shared/identity.d.ts +12 -0
  25. package/lib/ecosystem/shared/identity.js +17 -1
  26. package/lib/ecosystem/shared/turn.d.ts +8 -5
  27. package/lib/ecosystem/shared/turn.js +16 -17
  28. package/lib/ecosystem/wechat/archive.d.ts +2 -0
  29. package/lib/ecosystem/wechat/archive.js +3 -1
  30. package/lib/ecosystem/wechat/home.js +9 -4
  31. package/lib/ecosystem/wechat/messages.d.ts +11 -0
  32. package/lib/ecosystem/wechat/messages.js +9 -1
  33. package/lib/ecosystem/wechat/sending.js +36 -9
  34. package/lib/ecosystem/wechat/supervisor.d.ts +11 -2
  35. package/lib/ecosystem/wechat/supervisor.js +90 -9
  36. package/lib/history.d.ts +6 -4
  37. package/lib/history.js +61 -12
  38. package/lib/index.js +7 -5
  39. package/lib/life/activity.d.ts +2 -0
  40. package/lib/life/activity.js +1 -1
  41. package/lib/life/alarm.d.ts +12 -4
  42. package/lib/life/alarm.js +21 -6
  43. package/lib/life/diary.d.ts +6 -0
  44. package/lib/life/diary.js +23 -2
  45. package/lib/life/runtime.d.ts +1 -0
  46. package/lib/life/runtime.js +57 -9
  47. package/lib/life/toolRegistry.d.ts +4 -3
  48. package/lib/life/toolRegistry.js +13 -3
  49. package/lib/life/types.d.ts +6 -1
  50. package/lib/memory.js +1 -4
  51. package/lib/memoryFiles.d.ts +1 -4
  52. package/lib/memoryFiles.js +18 -43
  53. package/lib/memoryStore.d.ts +1 -3
  54. package/lib/memoryStore.js +1 -1
  55. package/lib/memoryTools.js +2 -2
  56. package/lib/runtime.js +44 -89
  57. package/lib/sourceArchive.js +3 -4
  58. package/lib/store.d.ts +1 -1
  59. package/lib/store.js +1 -1
  60. package/lib/types.d.ts +1 -4
  61. package/lib/worldPrompt.js +1 -1
  62. package/lib/worldSwitch.d.ts +9 -1
  63. package/lib/worldSwitch.js +14 -1
  64. package/package.json +1 -1
  65. package/scripts/compact-home.mjs +29 -29
  66. package/scripts/enable-tool-free-compaction.ps1 +33 -33
  67. package/scripts/import-stickers.mjs +17 -17
  68. package/scripts/update-world.mjs +2 -2
  69. package/src/ecosystem/wechat/windows/README.md +2 -2
  70. package/src/ecosystem/wechat/windows/adapter.py +6 -0
  71. package/src/ecosystem/wechat/windows/engine/build.ps1 +8 -2
  72. package/src/ecosystem/wechat/windows/engine/profiles.json +114 -114
  73. package/src/ecosystem/wechat/windows/presence.py +109 -109
  74. package/src/ecosystem/wechat/windows/sender.py +17 -5
  75. package/templates/alarm.md +1 -1
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 ckz
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ckz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTES.md CHANGED
@@ -16,7 +16,8 @@
16
16
 
17
17
  - **首次启动时,profile 的压缩会被换成 dsh-world 自带的“只留对话”压缩**(先备份,重启 DSH 后生效)。整个 profile 的会话都会受影响。不想换,写 `replaceCompaction: false`。DSH 桌面版上会把世界所用的预设整份写进 profile 再换。详情:[默认换用只留对话的压缩](#默认换用只留对话的压缩)。
18
18
  - **自动压缩在上下文窗口的 75% 触发**,没声明窗口的模型按 1M 估算。详情:[自动压缩什么时候触发](#自动压缩什么时候触发)。
19
- - **每晚 23:00 的回顾之后,家会话会自动压缩一次**,让她改写的“我是谁”生效;每晚多一次摘要调用,控制台可关。详情:[每日回顾后自动压缩](#每日回顾后自动压缩)。
19
+ - **每晚回顾(默认 23:00)之后,家会话会自动压缩一次**,让她改写的“我是谁”生效;每晚多一次摘要调用,控制台可关。详情:[每日回顾后自动压缩](#每日回顾后自动压缩)。
20
+ - **过去的日记她改不了**:只能写今天的;写错了,在今天的日记里纠正。详情:[过去的日记只读](#过去的日记只读)。
20
21
  - **在控制台写了人设,它会取代 DSH 自带的那句默认身份**;你已经在 DSH 里设好的系统人设原样保留。详情:[人设和 DSH 自带的系统提示词](#人设和-dsh-自带的系统提示词)。
21
22
  - **微信和 QQ 默认都是关的**,要用先在配置里启用,再到控制台「概览 → 接入」拨开(已经在用微信的世界升级后保持开着)。微信群里被 @ 时默认带前 5 条消息作上下文,控制台微信页可调 1–20。详情:[微信的开关](#微信的开关)、[QQ 的开关](#qq-的开关)。
22
23
 
@@ -42,6 +43,8 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
42
43
 
43
44
  开启插件的微信开关本身不会启动 Windows 适配器;可手动启动,或在配置里写 `wechatAdapter` 让插件随微信模块启动和停止它(见适配器 README)。无论哪种,都需要配套适配器并完成账号及聊天目标注册后,微信工具才可使用。这套原生桥不依赖 `dsh-plugin-weixin` 或 iLink。升级插件和适配器后,两者均需重启,不能让旧适配器进程继续运行新版协议;保留原配置、游标和回执。
44
45
 
46
+ 升级改动了原生桥源码时,由插件管理的适配器(配了 `wechatAdapter`)会自己重新构建一次:用插件自带的 `engine/build.ps1` 编到适配器 `config.json` 旁边的 `engine` 目录,编好再启动,控制台微信页这时显示「正在重新构建原生桥」;编好后旧的构建目录会删掉(微信正占用着的留到下次)。需要的还是第一次部署时用过的 Visual Studio C++ x64 构建工具。没有这套工具或编译失败时,适配器停下不再重试,原因写进控制台的健康,按提示在仓库里运行 `wechat.ps1 Build`,再在控制台重启适配器。自己手动运行的适配器不会自动构建,升级后照旧手动 Build。适配器因为别的原因退出时,控制台也会显示它退出前说的最后一句话。
47
+
45
48
  ## 人设与提示词
46
49
 
47
50
  ### 修改人设和世界提示词后要手动应用
@@ -80,7 +83,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
80
83
 
81
84
  ### 每日回顾后自动压缩
82
85
 
83
- 默认开,可在控制台概览的「回顾后自动压缩」关掉。每晚 23:00 的回顾里她会改写「我是谁」,而系统提示只在压缩之后才重新读取,不压缩的话新版要等到下一次压缩才生效,可能隔好几天。所以回顾那一轮结束、家空闲后,插件会自动执行一次[「应用并压缩家会话」](#修改人设和世界提示词后要手动应用):新版「我是谁」随压缩一起生效,压缩后最近的聊天原文会作为记忆块重新放回她眼前,衔接是接得上的。压缩本来就要重建缓存,这样不会多破坏一次,但每晚会多一次摘要调用。只在回顾真的送到她那里之后才触发,闹钟和问候不会;只作用于家会话,人设和世界提示词的修改仍然需要手动应用。没压成时(比如找不到压缩服务、摘要请求被模型拒绝),原因连同底层报错一起留在健康状态里,下一次压缩成功后消失。
86
+ 默认开,可在控制台概览的「回顾后自动压缩」关掉。每晚的回顾里她会改写「我是谁」,而系统提示只在压缩之后才重新读取,不压缩的话新版要等到下一次压缩才生效,可能隔好几天。所以回顾那一轮结束、家空闲后,插件会自动执行一次[「应用并压缩家会话」](#修改人设和世界提示词后要手动应用):新版「我是谁」随压缩一起生效,压缩后最近的聊天原文会作为记忆块重新放回她眼前,衔接是接得上的。压缩本来就要重建缓存,这样不会多破坏一次,但每晚会多一次摘要调用。只在回顾真的送到她那里之后才触发,闹钟和问候不会;只作用于家会话,人设和世界提示词的修改仍然需要手动应用。没压成时(比如找不到压缩服务、摘要请求被模型拒绝),原因连同底层报错一起留在健康状态里,下一次压缩成功后消失。
84
87
 
85
88
  ### 主动触发一次压缩的脚本
86
89
 
@@ -89,10 +92,18 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
89
92
  ### 长期记忆的查找
90
93
 
91
94
  - **没有索引,也就没有升级时的建库**:聊天在 `archive.sqlite` 的原表里直接按字面扫描,日记等文件在查询时直接读,没有额外的表、队列或重建,旧档案升级后第一次查询就能用。扫描随聊天量线性变慢:我们量过合成数据,约 10 万条 50 毫秒、50 万条 300 毫秒以内,陪伴场景远用不到这个量级。
92
- - **查找的范围**:聊天和日记(`diaryDir` 里的 `.md`/`.txt`,一层)。自述不进查找,仍然全文放进提示。文件只有当前内容,旧版本不保存;`history` 参数还收,但不起作用。
95
+ - **查找的范围**:聊天和日记(`diaryDir` 里的 `.md`/`.txt`,一层)。自述不进查找,仍然全文放进提示。文件只有当前内容,旧版本不保存。
93
96
  - **查找的限制**:查询只认字面文字(区分大小写);没有共同文字、时间线索的往事找不回来;有来源读不到时结果里会带 `coverage`,零结果不代表没发生过;分页只限制返回的量,不限制扫描的量。
94
97
  - **一次返回的量是故意压小的**:`memory_find` 默认 8 条、每条摘录约 200 字,`memory_read` 默认 2000 字,因为工具结果会在这一轮之后的每一步被重发。要更多就翻页(`nextCursor`)或读原文,不要一次要几十条。
95
98
 
99
+ ### 过去的日记只读
100
+
101
+ 日记目录里按日期命名的 `YYYY-MM-DD.md`,她只能用 `write`、`edit` 改还没合上的那几天:今天,以及回顾还没做完的那天(回顾定在中午以前、或者回顾晚到第二天时,前一天的日记会一直开到那一轮回顾结束)。改已经合上的日子,工具会被拒绝,并告诉她在今天的日记里写下哪里记错了、现在怎么看。读日记不受影响;日记目录里不按日期命名的文件、子目录里的文件不管。这条只拦她的文件工具:`pwsh` 等命令行能写任何文件,没法可靠地分辨,所以不拦。你自己在编辑器里改日记不受影响。
102
+
103
+ ### 归档或记忆出错时她照常说话
104
+
105
+ 归档写不进去(比如磁盘满、数据库被占用)、某个会话的日志一时读不出来,或者记忆块建不出来时,她照常回话,问题显示在控制台的「健康」里。这期间说的话不会丢:它们在宿主的会话日志里,插件记着每个会话归档到了哪里,问题解决后,这个会话下一次有动静或 DSH 下次启动时,会从断点补进归档,不会重复。记忆块建不出来时,她眼前还是上一块(刚压缩完就没有),下一步会再试。补不回来的只有一种:宿主的会话日志在磁盘上坏了、一直读不出来,那个会话里的话就进不了归档,健康里会一直显示它。
106
+
96
107
  ## 世界范围与会话
97
108
 
98
109
  ### 对世界工作区以外的影响
package/README.md CHANGED
@@ -35,7 +35,7 @@
35
35
  - **家**:她有一个自己的会话「<名字>的家」,和一个房间(工作目录),在里面过自己的日子。
36
36
  - **自己定节奏**:她说好接下来做什么、做到几点,到点了再决定继续还是换一件。什么都不定,就休息到第二天早上。
37
37
  - **主动找你**:想你的时候,她可以把一句话送到你面前(Windows 系统通知,或你接上的桌宠等程序)。
38
- - **每日回顾**:每天晚上 23:00,她回想当天的聊天和做过的事,写日记,更新「我是谁」。
38
+ - **每日回顾**:每天晚上 23:00(控制台可改),她回想当天的聊天和做过的事,写日记,更新「我是谁」。
39
39
  - **每天额度**:可以给家里每天的花费设个上限,超过了会提醒她一次,由她自己决定收尾。
40
40
  - **大事先问**:删改房间外的文件、装软件、花钱、以你的名义对外发消息等,约定好先问你。
41
41
 
@@ -48,6 +48,7 @@ DSH 设置里的「世界控制台」:
48
48
  - **世界提示词**:你想对她说的话,以及她的世界的说明。
49
49
  - **相册**:家会话可用 `keep_photo` 收藏本轮最新消息中的图片(含本轮已读取的微信图片和引用图),`list_photos` 分页查看说明,`forget_photo` 移除收藏。控制台顶部「相册」页查看照片,点开才加载图片;照片不会自动加入之后每轮上下文。旧相册首次打开时导入,原文件保留。
50
50
  - **应用并压缩家会话**:人设和世界提示词页面里的热加载入口,操作方法见[注意事项](NOTES.md#修改人设和世界提示词后要手动应用)。
51
+ - **作息**:概览里的「作息」卡片设每日回顾和早上醒来的时间,记在 `world.json`;留空恢复默认(回顾 23:00,早上用配置里的 `fallbackWakeTime`)。保存后,已排好的回顾和早上闹钟立刻改到新时间,她自己定的闹钟不动;世界停着时改的,下次启动时跟上。回顾定在中午以前,回顾的是前一天。
51
52
  - **工作区权限**:选择世界工作区新建会话的默认权限,选项沿用宿主提供的权限预设,默认完全权限。保存后对新会话生效;已有会话及其手动权限不会被重新覆盖。
52
53
  - **概览与记录**:她此刻在做什么、下个闹钟、近期记忆有多少轮、今天花了多少;还有活动记录、日记和压缩记录。
53
54
  - **接入开关**:配置里启用了微信(`wechat: true`)或 QQ(`qqNative.enabled: true`)后,概览里有一张「接入」卡片,状态记在 `world.json`。微信开着才注册工具并拉起适配器(配了 `wechatAdapter` 时),关掉就撤掉;QQ 开着才加载通道,关掉就断开连接。微信和 QQ 都默认关,已经在用微信的世界升级后保持开着。首次手动开启 QQ 时,缺少 SnowLuma SDK 就按需安装,完成后提示重启 DSH;SDK 已就绪时直接切换,无需重启。
@@ -76,7 +77,7 @@ DSH 设置里的「世界控制台」:
76
77
 
77
78
  dsh-world 开放了一个本地的「桥」:桌宠之类的程序可以把你说的话送进她的家,也可以接收她的回复和主动找你的话。协议见文末。
78
79
 
79
- 微信作为独立模块接入同一个家,使用她的独立账号收发指定私聊或群聊。她可用 `wechat_chats` 查询已配置目标,用 `wechat_history` 主动分页查看群消息,无需等别人 @,历史里的图片用 `wechat_image` 按消息 ID 一张张看;读完以同一个 `chatId` 调用 `wechat_send` 自主联系对方或回复消息,文字、图片和表情共用同一发送队列;`wechat_delivery` 查询确认结果。普通最终回答不会自动转发到微信。Windows 适配器和配置步骤见 [微信模块](src/ecosystem/wechat/windows/README.md)。B 站尚未接入。
80
+ 微信作为独立模块接入同一个家,使用她的独立账号收发指定私聊或群聊。她可用 `wechat_chats` 查询已配置目标,用 `wechat_history` 主动分页查看群消息,无需等别人 @,历史里的图片用 `wechat_image` 按消息 ID 一张张看;读完以同一个 `chatId` 调用 `wechat_send` 自主联系对方或回复消息,文字、图片和表情共用同一发送队列;一批话没发出或结果不明时,发起的会话会在下一步收到一条说明(不会因此被叫醒),平时不用逐条查回执,需要时仍可用 `wechat_delivery` 查询。普通最终回答不会自动转发到微信。Windows 适配器和配置步骤见 [微信模块](src/ecosystem/wechat/windows/README.md)。B 站尚未接入。
80
81
 
81
82
  **群聊动静**:适配器在线时,已配置群里未 @ 她的消息只更新未读数、最后发言人和时间,不唤醒模型,也不把正文加入上下文。她原有的闹钟响起时,会附上一行群聊概况,包括未读消息或安静了多久;是否去看、是否发言,由她自己决定。成功读取群的最新一页后清零未读,自己的发言不计入未读;计数保存在适配器状态中,重启保留。插件不会改写你的 `alarm.md`、`world-prompt.md` 或「我是谁」。
82
83
 
@@ -138,7 +139,7 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
138
139
  life: true # 生活线,默认开启
139
140
  replaceCompaction: true # 首次启动把 profile 的压缩换成 dsh-world 的只留对话压缩;false = 不动
140
141
  archiveScope: workspace # workspace:家的工作区;home:仅当前家会话
141
- fallbackWakeTime: '09:00' # 没定闹钟时,早上几点叫醒她
142
+ fallbackWakeTime: '09:00' # 没定闹钟时,早上几点叫醒她;控制台「作息」里改过的优先
142
143
  diaryDir: C:/path/to/日记 # 日记目录,默认在世界目录里
143
144
  toast: true # 主动找你时发 Windows 系统通知
144
145
  # toastAppId: com.deepseek.dsh # 通知身份,默认在开始菜单里找 DSH 桌面版(com.deepseek.dsh 或 electron.app.DeepSeek Harness)
@@ -155,7 +156,7 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
155
156
  allowGroups: [] # 群白名单
156
157
  autoReply: true # false = 只看不回
157
158
  contextMessages: 6 # 每轮带上最近的几条
158
- batchQuietMs: 10000 # 同一会话这几毫秒内的话攒成一条问她;0 = 一条一问
159
+ batchQuietMs: 10000 # 同一会话这几毫秒内的话攒成一条问她;0 = 一条一问;QQ 页里改过的优先(0–30 秒,一批最多等 30 秒)
159
160
  groupTrigger: mention # mention:@ 她/引用她/命中关键词才接;all:每句都接
160
161
  groupKeywords: [] # groupTrigger: mention 时算「在叫她」的词
161
162
  mutedUntil: '' # 静默到这个时间(ISO):只收不回,到点自己醒
package/client/index.js CHANGED
@@ -385,6 +385,30 @@ window.__ModuleLoader__.load({
385
385
  ' ', props.on ? '已开启' : '已关闭'),
386
386
  h(Status, { msg: msg }))
387
387
  }
388
+ /** 每日回顾和早上兜底的时间:留空恢复默认;保存后已排好的回顾和早上闹钟立刻改到新时间。 */
389
+ function Schedule(props) {
390
+ var s = props.schedule
391
+ var reviewState = useState(s.review), review = reviewState[0], setReview = reviewState[1]
392
+ var wakeState = useState(s.wake), wake = wakeState[0], setWake = wakeState[1]
393
+ var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
394
+ function save() {
395
+ var values = [String(review).trim(), String(wake).trim()]
396
+ if (values.some(function (v) { return v !== '' && !/^([01]\d|2[0-3]):[0-5]\d$/.test(v) })) { setMsg('请填 HH:MM 格式的时间(00:00–23:59),留空恢复默认'); return }
397
+ post('schedule', { review: values[0] || null, wake: values[1] || null }).then(function () {
398
+ if (!values[0]) setReview(s.defaults.review); if (!values[1]) setWake(s.defaults.wake)
399
+ setMsg('已保存。已排好的回顾和早上闹钟已改到新时间,她自己定的闹钟不变。')
400
+ if (props.onSaved) props.onSaved()
401
+ }, failedTo(setMsg))
402
+ }
403
+ return h(Card, { title: '作息' },
404
+ h('div', { className: 'dw-muted' }, '每日回顾:她回头看一天、写日记的时间,定在中午以前就回顾前一天。早上:她没定闹钟时醒来的时间。留空恢复默认(回顾 ' + s.defaults.review + ',早上 ' + s.defaults.wake + ')。'),
405
+ h('div', { className: 'dw-setting' },
406
+ h('label', null, '每日回顾 ', h('input', { type: 'time', 'aria-label': '每日回顾时间', value: review, onChange: function (e) { setReview(e.target.value); setMsg('') } })),
407
+ h('label', null, '早上 ', h('input', { type: 'time', 'aria-label': '早上醒来时间', value: wake, onChange: function (e) { setWake(e.target.value); setMsg('') } })),
408
+ h('button', { className: 'dw-btn', onClick: save }, '保存')),
409
+ h('div', { className: 'dw-muted' }, '她看到的工具说明里写的早上时间,要等新开的会话或重启 DSH 后才更新。'),
410
+ h(Status, { msg: msg }))
411
+ }
388
412
  /** 微信:适配器每约 2 秒来问一次,最近一次来问的时间就是连接状态;两个读取参数在它下次来问时同步。 */
389
413
  function Wechat(props) {
390
414
  var w = props.wechat, zone = props.zone
@@ -395,7 +419,7 @@ window.__ModuleLoader__.load({
395
419
  var contacted = age != null && age < 30000, offline = contacted && w.account === 'offline'
396
420
  var ad = w.adapter
397
421
  var blocked = ad && ad.needsHuman
398
- var stateText = blocked ? '● 有消息待核对,适配器已停' : !contacted ? (ad && ad.running ? '● 适配器启动中' : ad && ad.error ? '● 等待适配器文件' : w.lastContactAt ? '● 适配器已断开' : '● 等待适配器') : offline ? '● 微信离线,等待重新登录' : '● 已连接'
422
+ var stateText = blocked ? '● 有消息待核对,适配器已停' : !contacted ? (ad && ad.building ? '● 正在重新构建原生桥' : ad && ad.running ? '● 适配器启动中' : ad && ad.error ? '● 适配器没能启动' : w.lastContactAt ? '● 适配器已断开' : '● 等待适配器') : offline ? '● 微信离线,等待重新登录' : '● 已连接'
399
423
  var adMsgState = useState(''), adMsg = adMsgState[0], setAdMsg = adMsgState[1]
400
424
  function restartAdapter() {
401
425
  setAdMsg('正在重启…')
@@ -471,6 +495,17 @@ window.__ModuleLoader__.load({
471
495
  if (isNaN(at.getTime())) { setMsg('这个时间看不懂,重挑一下'); return }
472
496
  change({ mutedUntil: at.toISOString() })
473
497
  }
498
+ // 合批窗口:同一个人在这么多秒内连发几句,合成一次问。填 0 就是每句单独回。
499
+ var quietState = useState(''), quiet = quietState[0], setQuiet = quietState[1]
500
+ useEffect(function () {
501
+ var ms = props.native && typeof props.native.batchQuietMs === 'number' ? String(Math.round(props.native.batchQuietMs / 1000)) : ''
502
+ setQuiet(function (cur) { return cur === '' ? ms : cur })
503
+ }, [props.native && props.native.batchQuietMs])
504
+ function saveQuiet() {
505
+ var sec = Number(String(quiet).trim())
506
+ if (!isFinite(sec) || sec < 0 || sec > 30) { setMsg('填 0 到 30 之间的秒数(一批最多等 30 秒)'); return }
507
+ change({ batchQuietMs: Math.round(sec * 1000) })
508
+ }
474
509
  // 白名单:谁的话能进来。打开时填上现有的名单,之后不覆盖正在改的字。
475
510
  var ids = props.native ? [(props.native.allowPrivateIds || []).join(', '), (props.native.allowGroupsIds || []).join(', ')] : ['', '']
476
511
  var allowState = useState({ from: '', people: '', groups: '' }), allow = allowState[0], setAllow = allowState[1]
@@ -513,6 +548,15 @@ window.__ModuleLoader__.load({
513
548
  h('span', { key: 't' }, n.autoReply === true ? ' 会自己回话' : ' 只看不回'),
514
549
  ])
515
550
  })(props.native),
551
+ (function (n) {
552
+ if (!n) return null
553
+ var ms = typeof n.batchQuietMs === 'number' ? n.batchQuietMs : 10000
554
+ return h('div', { key: 'quiet', className: 'dw-setting' }, [
555
+ h('span', { key: 's', className: 'dw-muted' }, ms ? '连着发几句:' + (ms / 1000) + ' 秒内合成一次问' : '连着发几句:每句单独回'),
556
+ h('input', { key: 'i', type: 'number', min: 0, max: 30, step: 1, 'aria-label': '合批窗口(秒)', style: { width: 64 }, disabled: busy, value: quiet, onChange: function (e) { setQuiet(e.target.value) } }),
557
+ h('button', { key: 'b', className: 'dw-btn', disabled: busy, onClick: saveQuiet }, '存'),
558
+ ])
559
+ })(props.native),
516
560
  (function (n) {
517
561
  if (!n) return null
518
562
  return h('div', { key: 'mute', className: 'dw-setting' }, [
@@ -643,6 +687,7 @@ window.__ModuleLoader__.load({
643
687
  h(Budget, { budget: snap.budget, onSaved: props.refresh }),
644
688
  snap.workspace ? h(WorkspacePermission, { workspace: snap.workspace, onSaved: props.refresh }) : null,
645
689
  typeof snap.compactAfterReview === 'boolean' ? h(CompactAfterReview, { on: snap.compactAfterReview, onSaved: props.refresh }) : null,
690
+ snap.schedule ? h(Schedule, { schedule: snap.schedule, onSaved: props.refresh }) : null,
646
691
  snap.modules && (snap.modules.wechat.available || snap.modules.qq.available) ? h(Modules, { modules: snap.modules, running: snap.running, onSaved: props.refresh }) : null))
647
692
  }
648
693
  function Records(props) {
@@ -843,7 +888,7 @@ window.__ModuleLoader__.load({
843
888
  return ctx.slots.register({ name: 'settings.section', id: 'world-console', order: 28, label: '世界控制台' }, function () { return h(Console) })
844
889
  })
845
890
  }
846
- Object.defineProperty(exports, '__test', { value: { MemorySearch: MemorySearch, latest: latest, searchMemory: searchMemory, memoryQuery: memoryQuery, dayStartIso: dayStartIso, WorkspacePermission: WorkspacePermission, CompactAfterReview: CompactAfterReview, Modules: Modules, HomeApply: HomeApply, PhotoAlbum: PhotoAlbum, Wechat: Wechat, Activity: Activity, Diary: Diary, Qq: Qq, Panel: Panel, View: View, Overview: Overview, PersonaEditor: PersonaEditor, PromptEditor: PromptEditor, loadSnapshot: loadSnapshot, renderPersona: renderPersona }, enumerable: false })
891
+ Object.defineProperty(exports, '__test', { value: { MemorySearch: MemorySearch, latest: latest, searchMemory: searchMemory, memoryQuery: memoryQuery, dayStartIso: dayStartIso, WorkspacePermission: WorkspacePermission, CompactAfterReview: CompactAfterReview, Schedule: Schedule, Modules: Modules, HomeApply: HomeApply, PhotoAlbum: PhotoAlbum, Wechat: Wechat, Activity: Activity, Diary: Diary, Qq: Qq, Panel: Panel, View: View, Overview: Overview, PersonaEditor: PersonaEditor, PromptEditor: PromptEditor, loadSnapshot: loadSnapshot, renderPersona: renderPersona }, enumerable: false })
847
892
  return exports
848
893
  },
849
894
  })
package/cordis.patch.yml CHANGED
@@ -1,6 +1,6 @@
1
- # Inserts the dsh-world row enabled: with no config it serves the standard preset as a world named
2
- # "default" in the system time zone. Override the row by id in a profile to name the companion, pick
3
- # another preset or turn on the life line (see README).
4
- - insert:
5
- - id: dsh-world
6
- name: dsh-world
1
+ # Inserts the dsh-world row enabled: with no config it serves the standard preset as a world named
2
+ # "default" in the system time zone. Override the row by id in a profile to name the companion, pick
3
+ # another preset or turn on the life line (see README).
4
+ - insert:
5
+ - id: dsh-world
6
+ name: dsh-world
package/lib/archive.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { type ContentBlock } from '@deepseek-ai/dsh-llm';
2
- import { type SessionEvent } from '@deepseek-ai/dsh-session';
2
+ import { type SessionEvent, type SessionHeader } from '@deepseek-ai/dsh-session';
3
3
  import type { ArchiveScope, ConversationRecord } from './types.ts';
4
4
  export declare const conversationRecordId: (worldId: string, sessionId: string, messageId: string) => string;
5
5
  export declare function visibleText(content: readonly ContentBlock[]): string;
6
+ /** A session someone talks in: not a subagent, not delegated. Only these are archived or carry her world. */
7
+ export declare const isOrdinarySession: (header: Pick<SessionHeader, "origin" | "delegationDepth">) => boolean;
6
8
  export declare function extractConversationRecords(event: SessionEvent, scope: ArchiveScope): ConversationRecord[];
package/lib/archive.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { lastAssistantStreamChunk } from '@deepseek-ai/dsh-llm';
3
3
  import { isAppendSurfaceEvent } from '@deepseek-ai/dsh-session';
4
- import { identityPrefix, speakerIdentity } from "./ecosystem/shared/identity.js";
4
+ import { identityPrefix, legacyIdentityPrefix, speakerIdentity } from "./ecosystem/shared/identity.js";
5
5
  import { replyMessages, replyText } from "./ecosystem/wechat/messages.js";
6
6
  export const conversationRecordId = (worldId, sessionId, messageId) => createHash('sha256').update(JSON.stringify([worldId, sessionId, messageId])).digest('hex');
7
7
  export function visibleText(content) {
@@ -13,9 +13,11 @@ export function visibleText(content) {
13
13
  return [];
14
14
  }).join('\n');
15
15
  }
16
+ /** A session someone talks in: not a subagent, not delegated. Only these are archived or carry her world. */
17
+ export const isOrdinarySession = (header) => header.origin !== 'subagent' && (header.delegationDepth ?? 0) === 0;
16
18
  export function extractConversationRecords(event, scope) {
17
19
  const { header } = scope;
18
- if ((!scope.archiveScope && header.agentPreset !== scope.agentPreset) || header.origin === 'subagent' || (header.delegationDepth ?? 0) > 0 || event.seq < scope.inheritedEventCount)
20
+ if (!isOrdinarySession(header) || event.seq < scope.inheritedEventCount)
19
21
  return [];
20
22
  if (event.type !== 'user/message' && event.type !== 'assistant/message')
21
23
  return [];
@@ -30,8 +32,8 @@ export function extractConversationRecords(event, scope) {
30
32
  if (outgoing && (identity?.channel !== 'wechat' || identity.speakerId !== `wechat:${identity.accountId}`))
31
33
  throw new Error('Invalid WeChat outgoing identity');
32
34
  const visible = visibleText(message.content);
33
- const prefix = identity ? identityPrefix(identity) : '';
34
- const content = outgoing ? `微信待发送给 ${identity.conversationId}(已生成,发送尚未确认):\n${replyText(sentMessages)}` : prefix && visible.startsWith(prefix) ? visible.slice(prefix.length) : visible;
35
+ const prefix = identity && [identityPrefix(identity), legacyIdentityPrefix(identity)].find(prefix => visible.startsWith(prefix));
36
+ const content = outgoing ? `微信待发送给 ${identity.conversationId}(已生成,发送尚未确认):\n${replyText(sentMessages)}` : prefix ? visible.slice(prefix.length) : visible;
35
37
  if (!content)
36
38
  return [];
37
39
  const turn = event.type === 'assistant/message' ? event.data.turn : scope.turn;
@@ -45,6 +45,11 @@ export interface ConsoleActions {
45
45
  setWorkspacePermission(permission: string): void;
46
46
  /** Whether the evening look back is followed by applying and compacting her home (on unless turned off). */
47
47
  setCompactAfterReview(on: boolean): void;
48
+ /** Local HH:MM of the evening look back and the morning wake; a field left out stays, null goes back to its default. */
49
+ setSchedule(schedule: {
50
+ review?: string | null;
51
+ wake?: string | null;
52
+ }): void;
48
53
  /** A field left out stays as it is; null goes back to its default. */
49
54
  /** Turns the WeChat and QQ modules on or off now (their tools and routes come and go with the switch). Returns why it cannot, or nothing. */
50
55
  setModules(modules: {
@@ -2,6 +2,7 @@ import { jsonObject, knownHost, readBody, sendJson } from "../http.js";
2
2
  import { PERSONA_LAYERS } from "../persona.js";
3
3
  import { validTurns, validWechatBuffer, validWechatContext, validWorkspacePermission, MAX_WECHAT_BUFFER_SECONDS, MAX_WECHAT_CONTEXT } from "../worldSwitch.js";
4
4
  import { validArchiveScope } from "../archiveSelection.js";
5
+ import { validClockTime } from "../life/alarm.js";
5
6
  import { MemoryError } from "../memory.js";
6
7
  export const CONSOLE_PREFIX = '/dsh-world';
7
8
  /** A write must carry this header; a page on another site cannot add it without a CORS preflight, which is never answered. */
@@ -9,12 +10,12 @@ export const WRITE_HEADER = 'x-dsh-world';
9
10
  const MAX_BODY_BYTES = 64 * 1024;
10
11
  const MEMORY_STATUS = { invalidQuery: 400, invalidRef: 400, invalidCursor: 400, notFound: 404, outOfScope: 403, cursorExpired: 409, sourceChanged: 409, scopeChanged: 409, readFailed: 500 };
11
12
  /** Query-string values to the shape the tools take: a number that is not one stays NaN and is refused by the shared check. */
12
- function memoryInput(params, numbers, flags, lists) {
13
+ function memoryInput(params, numbers, lists) {
13
14
  const input = {};
14
15
  for (const [key, value] of params) {
15
16
  if (value === '')
16
17
  continue;
17
- input[key] = numbers.includes(key) ? Number(value) : flags.includes(key) ? value === '1' || value === 'true' : lists.includes(key) ? value.split(',') : value;
18
+ input[key] = numbers.includes(key) ? Number(value) : lists.includes(key) ? value.split(',') : value;
18
19
  }
19
20
  return input;
20
21
  }
@@ -105,6 +106,16 @@ async function write(actions, path, body) {
105
106
  actions.setCompactAfterReview(body.on);
106
107
  return ok();
107
108
  }
109
+ case '/console/schedule': {
110
+ const review = body?.review, wake = body?.wake;
111
+ for (const [name, value] of [['review', review], ['wake', wake]])
112
+ if (value !== undefined && value !== null && !validClockTime(value))
113
+ return bad(`${name} must be HH:MM (00:00–23:59), or null`);
114
+ if (review === undefined && wake === undefined)
115
+ return bad('nothing to change');
116
+ actions.setSchedule({ ...(review === undefined ? {} : { review: review }), ...(wake === undefined ? {} : { wake: wake }) });
117
+ return ok();
118
+ }
108
119
  case '/console/workspace-permission': {
109
120
  if (!validWorkspacePermission(body?.permission))
110
121
  return bad('工作区权限必须为非空字符串');
@@ -148,11 +159,11 @@ export async function handleConsole(sources, actions, request) {
148
159
  }
149
160
  case '/console/prompts': return ok(actions.prompts());
150
161
  case '/console/memory/find': {
151
- const input = memoryInput(url.searchParams, ['limit'], ['history'], ['kinds']);
162
+ const input = memoryInput(url.searchParams, ['limit'], ['kinds']);
152
163
  return memoryCall(sources.memoryFind && (() => sources.memoryFind(input)));
153
164
  }
154
165
  case '/console/memory/read': {
155
- const input = memoryInput(url.searchParams, ['offset', 'limit'], [], []);
166
+ const input = memoryInput(url.searchParams, ['offset', 'limit'], []);
156
167
  return memoryCall(sources.memoryRead && (() => sources.memoryRead(input)));
157
168
  }
158
169
  case '/console/photos': {
@@ -8,6 +8,7 @@ import type { MemoryArchiveScope } from '../archiveSelection.ts';
8
8
  import type { ConsoleSources } from './routes.ts';
9
9
  import type { HomeApplyState } from './homeApply.ts';
10
10
  import type { PhotoStore } from '../life/photos.ts';
11
+ import type { DailySchedule } from '../life/types.ts';
11
12
  import type { MemoryService } from '../memory.ts';
12
13
  export declare function estimateTokens(text: string): number;
13
14
  export interface SnapshotDeps {
@@ -31,6 +32,10 @@ export interface SnapshotDeps {
31
32
  memoryTurns(): number;
32
33
  selectedArchiveScope?(): MemoryArchiveScope;
33
34
  compactAfterReview?(): boolean;
35
+ /** The evening look back and the morning wake, with what an empty field goes back to; absent without the life line. */
36
+ schedule?(): DailySchedule & {
37
+ defaults: DailySchedule;
38
+ };
34
39
  workspacePermissions?(): {
35
40
  defaultPermission: string;
36
41
  options: {
@@ -16,7 +16,7 @@ export function consoleSources(deps) {
16
16
  const life = deps.life()?.snapshot();
17
17
  const home = life?.homeSessionId ? deps.ctx.agents.get(SessionId(life.homeSessionId)) : undefined;
18
18
  const window = deps.memoryTurns();
19
- const turns = await history.loadRecentTurns(config.worldId, window, deps.archiveSession);
19
+ const turns = await history.loadRecentTurns(window, deps.archiveSession);
20
20
  const archiveScope = config.archiveScope ?? 'workspace';
21
21
  const selectedArchiveScope = deps.selectedArchiveScope?.() ?? archiveScope;
22
22
  // Never let a dead bridge take the whole console down with it: a broken QQ module shows as "not running".
@@ -27,6 +27,7 @@ export function consoleSources(deps) {
27
27
  budget: { daily: deps.dailyBudget() ?? null, today: life?.spend ?? null },
28
28
  workspace: deps.workspacePermissions?.() ?? null,
29
29
  compactAfterReview: deps.compactAfterReview?.() ?? null,
30
+ schedule: deps.schedule?.() ?? null,
30
31
  life: life ? { homeSessionId: life.homeSessionId, status: home ? home.status : 'cold', alarm: life.alarm, review: life.review, recentWakes: lifeStore?.wakes().slice(-5).reverse() ?? [] } : null,
31
32
  homeApply: deps.homeApply?.() ?? null,
32
33
  health: [...(life?.faults ?? []), ...deps.faults()],
@@ -8,7 +8,7 @@ import type { ConsoleDoors } from './panel.ts';
8
8
  * GET /dsh-world/qq/console SnowLuma's console address, with a session token already traded for the
9
9
  * panel password
10
10
  * Write: POST /dsh-world/qq/native { autoReply?, bridge?: { port? }, mutedUntil?, allowPrivate?, allowGroups?,
11
- * startSnowluma? } the channel's switches, applied together; a new bridge
11
+ * batchQuietMs?, startSnowluma? } the channel's switches, applied together; a new bridge
12
12
  * port restarts the balcony on the spot
13
13
  * POST /dsh-world/qq/panel-password { username, password } remembers SnowLuma's panel password and
14
14
  * trades it for a session token right away
@@ -36,6 +36,7 @@ export interface NativePatch {
36
36
  mutedUntil?: string | null;
37
37
  allowPrivate?: string[];
38
38
  allowGroups?: string[];
39
+ batchQuietMs?: number;
39
40
  startSnowluma?: true;
40
41
  }
41
42
  type SetNative = (patch: NativePatch) => unknown;
@@ -1,4 +1,5 @@
1
1
  import { jsonObject, knownHost, readBody, sendJson } from "../../http.js";
2
+ import { MAX_BATCH_MS } from "../qq-native/batch.js";
2
3
  /**
3
4
  * The QQ module's few doors, on the same webServer as the console. The `/dsh-world/qq` prefix is never eaten
4
5
  * by the console's `/dsh-world` prefix (the host matches the longer one first).
@@ -7,7 +8,7 @@ import { jsonObject, knownHost, readBody, sendJson } from "../../http.js";
7
8
  * GET /dsh-world/qq/console SnowLuma's console address, with a session token already traded for the
8
9
  * panel password
9
10
  * Write: POST /dsh-world/qq/native { autoReply?, bridge?: { port? }, mutedUntil?, allowPrivate?, allowGroups?,
10
- * startSnowluma? } the channel's switches, applied together; a new bridge
11
+ * batchQuietMs?, startSnowluma? } the channel's switches, applied together; a new bridge
11
12
  * port restarts the balcony on the spot
12
13
  * POST /dsh-world/qq/panel-password { username, password } remembers SnowLuma's panel password and
13
14
  * trades it for a session token right away
@@ -70,6 +71,13 @@ async function write(doors, path, body, setNative) {
70
71
  return bad('mutedUntil 要是能解析的 ISO 时间,或者 null');
71
72
  patch.mutedUntil = until === null || !until.trim() ? null : until.trim();
72
73
  }
74
+ // 合批窗口:同一个人在这么多毫秒内连发几句,合成一次问。给 0 就是每句单独回;一批从第一句起最多等 MAX_BATCH_MS,再长也没用。
75
+ if (body?.batchQuietMs !== undefined) {
76
+ const ms = body.batchQuietMs;
77
+ if (typeof ms !== 'number' || !Number.isInteger(ms) || ms < 0 || ms > MAX_BATCH_MS)
78
+ return bad(`batchQuietMs 要是 0 到 ${MAX_BATCH_MS} 之间的整数(毫秒)`);
79
+ patch.batchQuietMs = ms;
80
+ }
73
81
  if (body?.startSnowluma === true)
74
82
  patch.startSnowluma = true;
75
83
  // 阳台:外面那条线开在哪个端口。换端口会打断已经连上的线,所以只认一个整数,别的一律拒。
@@ -85,7 +93,7 @@ async function write(doors, path, body, setNative) {
85
93
  patch.bridge = { port };
86
94
  }
87
95
  if (!Object.keys(patch).length)
88
- return bad('autoReply、bridge、mutedUntil、allowPrivate、allowGroups、startSnowluma 至少要给一个');
96
+ return bad('autoReply、bridge、mutedUntil、allowPrivate、allowGroups、batchQuietMs、startSnowluma 至少要给一个');
89
97
  return ok(setNative(patch));
90
98
  }
91
99
  case '/open': {
@@ -3,6 +3,8 @@
3
3
  * row, and asking her each half sentence on its own costs a turn apiece. The quiet window restarts with every
4
4
  * message but never stretches past `maxMs` from the first, so a busy group still gets its answer.
5
5
  */
6
+ /** The longest a batch waits from its first message, so a quiet window past it changes nothing. */
7
+ export declare const MAX_BATCH_MS = 30000;
6
8
  export declare function createBatcher<T>(options: {
7
9
  quietMs(): number;
8
10
  maxMs?: number;
@@ -3,8 +3,10 @@
3
3
  * row, and asking her each half sentence on its own costs a turn apiece. The quiet window restarts with every
4
4
  * message but never stretches past `maxMs` from the first, so a busy group still gets its answer.
5
5
  */
6
+ /** The longest a batch waits from its first message, so a quiet window past it changes nothing. */
7
+ export const MAX_BATCH_MS = 30_000;
6
8
  export function createBatcher(options) {
7
- const maxMs = options.maxMs ?? 30_000;
9
+ const maxMs = options.maxMs ?? MAX_BATCH_MS;
8
10
  const open = new Map();
9
11
  return {
10
12
  add(key, item) {
@@ -73,6 +73,8 @@ export interface QqNativeStatus {
73
73
  groupTrigger: 'mention' | 'all';
74
74
  /** 静默到什么时候;没在静默就是 null。 */
75
75
  mutedUntil: string | null;
76
+ /** 同一个人连发几句合成一次问的窗口(毫秒)。 */
77
+ batchQuietMs: number;
76
78
  supervisor: SnowlumaStatus;
77
79
  /** 这次请求按下「拉起 SnowLuma」的结果。 */
78
80
  launch?: StartResult;
@@ -85,6 +85,7 @@ export function createQqNativeModule(deps) {
85
85
  ...(overrides.mutedUntil === undefined ? {} : { mutedUntil: overrides.mutedUntil ?? '' }),
86
86
  ...(overrides.allowPrivate === undefined ? {} : { allowPrivate: overrides.allowPrivate }),
87
87
  ...(overrides.allowGroups === undefined ? {} : { allowGroups: overrides.allowGroups }),
88
+ ...(overrides.batchQuietMs === undefined ? {} : { batchQuietMs: overrides.batchQuietMs }),
88
89
  bridge: overrides.bridge?.port === undefined ? base.bridge : { ...base.bridge, port: overrides.bridge.port },
89
90
  };
90
91
  };
@@ -333,6 +334,7 @@ export function createQqNativeModule(deps) {
333
334
  failed: stats.failed,
334
335
  outbox: outbox.size,
335
336
  mutedUntil: mutedUntil(config),
337
+ batchQuietMs: config.batchQuietMs,
336
338
  supervisor: supervisor.status(),
337
339
  };
338
340
  }
@@ -353,6 +355,8 @@ export function createQqNativeModule(deps) {
353
355
  overrides.allowGroups = patch.allowGroups;
354
356
  if (patch.bridge)
355
357
  overrides.bridge = { port: patch.bridge.port };
358
+ if (patch.batchQuietMs !== undefined)
359
+ overrides.batchQuietMs = patch.batchQuietMs;
356
360
  writeOverrides();
357
361
  if (patch.bridge) {
358
362
  nativeBridge?.stop();
@@ -21,9 +21,14 @@ export interface ReplyPlan {
21
21
  /** QQ Zone posts: not chat at all, published separately. */
22
22
  qzone: string[];
23
23
  }
24
+ /**
25
+ * Drops the host's own bookkeeping, and any copy of an incoming message's source header, from an answer before it is
26
+ * sent. The paragraphs it empties are removed, so a reply that was only plumbing sends nothing instead of a blank message.
27
+ */
28
+ export declare function stripHostNoise(text: string): string;
24
29
  /**
25
30
  * Reads her answer. `[[img:路径]]`, `[[face:id]]` and `[[at:qq]]` become segments of the message, `[[sticker:…]]`
26
31
  * (an emoji id, a number or a meaning such as 开心) and `[[qzone:…]]` are taken out to go on their own. Most
27
32
  * answers have no marks and stay one plain string per paragraph; doubled brackets leave markdown links alone.
28
33
  */
29
- export declare function planReply(text: string): ReplyPlan;
34
+ export declare function planReply(raw: string): ReplyPlan;
@@ -1,10 +1,28 @@
1
+ import { IDENTITY_HEADER_LINE } from "../shared/identity.js";
1
2
  const MARK = /\[\[(img|face|at|sticker|qzone):([^[\]]+)\]\]/g;
3
+ /**
4
+ * Lines the host injects into a turn that must never reach QQ: the time sample, the browser time-zone note and the
5
+ * elapsed-time note. Matched by line prefix only, so a sentence of hers that merely mentions 时间 is left alone.
6
+ */
7
+ const HOST_LINE = /^\s*(?:Time sampled|Browser time zone|Elapsed since|Elapsed from)\b/;
8
+ /** Transport refs that leak into her prose: `text">m00123` anywhere, a bare `m00123` at the end of a line. */
9
+ const HOST_FRAGMENT = /[ \t]*text">m\d{5}\b|[ \t]*\bm\d{5}[ \t]*$/gm;
10
+ /**
11
+ * Drops the host's own bookkeeping, and any copy of an incoming message's source header, from an answer before it is
12
+ * sent. The paragraphs it empties are removed, so a reply that was only plumbing sends nothing instead of a blank message.
13
+ */
14
+ export function stripHostNoise(text) {
15
+ const kept = text.replace(/\r\n/g, '\n').replace(HOST_FRAGMENT, '').split('\n')
16
+ .filter(line => !HOST_LINE.test(line) && !IDENTITY_HEADER_LINE.test(line.trim()));
17
+ return kept.join('\n').replace(/\n{3,}/g, '\n\n').trim();
18
+ }
2
19
  /**
3
20
  * Reads her answer. `[[img:路径]]`, `[[face:id]]` and `[[at:qq]]` become segments of the message, `[[sticker:…]]`
4
21
  * (an emoji id, a number or a meaning such as 开心) and `[[qzone:…]]` are taken out to go on their own. Most
5
22
  * answers have no marks and stay one plain string per paragraph; doubled brackets leave markdown links alone.
6
23
  */
7
- export function planReply(text) {
24
+ export function planReply(raw) {
25
+ const text = stripHostNoise(raw);
8
26
  const parts = [], stickers = [], qzone = [];
9
27
  let last = 0, marked = false;
10
28
  for (const match of text.matchAll(MARK)) {
@@ -25,5 +25,5 @@ export declare function channelReference(value: unknown, current: SpeakerIdentit
25
25
  export declare function channelContext(value: unknown, current: SpeakerIdentity, limit?: number): ChannelContextMessage[];
26
26
  export declare function channelMedia(value: unknown, current: SpeakerIdentity): ChannelContextMessage[];
27
27
  /** Tells the model how to read `contextJson`; shared by every channel that renders it. */
28
- export declare const CONTEXT_IDENTITY_NOTE = "identity \u53EA\u5217\u51FA\u6BCF\u4E2A\u53D1\u8A00\u4EBA\u5404\u81EA\u7684\u6765\u6E90\uFF08speakerId \u7B49\uFF09\uFF0C\u6E20\u9053\u3001\u8D26\u53F7\u548C\u4F1A\u8BDD\u4E0E\u89E6\u53D1\u8FD9\u6761\u6D88\u606F\u7684\u3010\u6D88\u606F\u6765\u6E90\u3011\u76F8\u540C\uFF1BspeakerName \u53EA\u662F\u79F0\u547C";
28
+ export declare const CONTEXT_IDENTITY_NOTE = "identity \u53EA\u5217\u51FA\u6BCF\u4E2A\u53D1\u8A00\u4EBA\u5404\u81EA\u7684\u6765\u6E90\uFF08speakerId \u7B49\uFF09\uFF0C\u6E20\u9053\u3001\u8D26\u53F7\u548C\u4F1A\u8BDD\u4E0E\u89E6\u53D1\u8FD9\u6761\u6D88\u606F\u5F00\u5934\u3010\u3011\u91CC\u7684\u804A\u5929\u76F8\u540C\uFF1BspeakerName \u53EA\u662F\u79F0\u547C";
29
29
  export declare function contextJson(context: readonly ChannelContextMessage[], current: SpeakerIdentity): string;
@@ -81,7 +81,7 @@ function contextMessages(value, current, limit) {
81
81
  /** Context messages all belong to the conversation the triggering message names, so only what differs per speaker is repeated. */
82
82
  const CONVERSATION_FIELDS = ['channel', 'accountId', 'conversationId', 'conversationName', 'conversationType'];
83
83
  /** Tells the model how to read `contextJson`; shared by every channel that renders it. */
84
- export const CONTEXT_IDENTITY_NOTE = 'identity 只列出每个发言人各自的来源(speakerId 等),渠道、账号和会话与触发这条消息的【消息来源】相同;speakerName 只是称呼';
84
+ export const CONTEXT_IDENTITY_NOTE = 'identity 只列出每个发言人各自的来源(speakerId 等),渠道、账号和会话与触发这条消息开头【】里的聊天相同;speakerName 只是称呼';
85
85
  export function contextJson(context, current) {
86
86
  const self = `${current.channel}:${current.accountId}`;
87
87
  return JSON.stringify(context.map(message => {
@@ -12,4 +12,16 @@ export interface SpeakerIdentity {
12
12
  /** Structured adapter metadata only; message text is never an identity source. */
13
13
  export declare function speakerIdentity(value: unknown): SpeakerIdentity;
14
14
  export declare function conversationKey(identity: SpeakerIdentity): string;
15
+ /** A chat as she reads it: 微信「Ken」, 微信群「一家人」, QQ群「…」. */
16
+ export declare function chatLabel(channel: string, conversationType: SpeakerIdentity['conversationType'], name: string): string;
17
+ /** The chat's own name, or for a private chat the person it is with. */
18
+ export declare const chatName: (identity: Pick<SpeakerIdentity, "conversationName" | "conversationType" | "speakerName">) => string | undefined;
19
+ /**
20
+ * Opens every channel message she receives: which chat, who in a group, and the chatId her send tools take. Kept to
21
+ * one short line because it stays in her context with every message; the full identity rides on the message source.
22
+ */
15
23
  export declare function identityPrefix(identity: SpeakerIdentity): string;
24
+ /** Channel messages from 0.7.0 and earlier opened with the whole identity; an upgraded log may still hold some. */
25
+ export declare const legacyIdentityPrefix: (identity: SpeakerIdentity) => string;
26
+ /** A whole line that is one of the headers above, new or legacy, whoever it names. */
27
+ export declare const IDENTITY_HEADER_LINE: RegExp;