dsh-world 0.7.0 → 0.7.2

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 (84) hide show
  1. package/CHANGELOG.md +379 -347
  2. package/INSTALL.md +314 -314
  3. package/LICENSE +21 -21
  4. package/NOTES.md +32 -10
  5. package/README.md +7 -6
  6. package/client/index.js +58 -3
  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 +7 -0
  11. package/lib/console/routes.js +26 -8
  12. package/lib/console/snapshot.d.ts +7 -0
  13. package/lib/console/snapshot.js +3 -2
  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/home.d.ts +1 -0
  19. package/lib/ecosystem/qq-native/home.js +10 -3
  20. package/lib/ecosystem/qq-native/index.d.ts +2 -0
  21. package/lib/ecosystem/qq-native/index.js +21 -4
  22. package/lib/ecosystem/qq-native/native-bridge.js +5 -2
  23. package/lib/ecosystem/qq-native/replies.d.ts +7 -1
  24. package/lib/ecosystem/qq-native/replies.js +30 -1
  25. package/lib/ecosystem/shared/context.d.ts +6 -1
  26. package/lib/ecosystem/shared/context.js +6 -1
  27. package/lib/ecosystem/shared/identity.d.ts +12 -0
  28. package/lib/ecosystem/shared/identity.js +17 -1
  29. package/lib/ecosystem/shared/turn.d.ts +8 -5
  30. package/lib/ecosystem/shared/turn.js +16 -17
  31. package/lib/ecosystem/wechat/archive.d.ts +2 -0
  32. package/lib/ecosystem/wechat/archive.js +3 -1
  33. package/lib/ecosystem/wechat/home.js +9 -4
  34. package/lib/ecosystem/wechat/messages.d.ts +11 -0
  35. package/lib/ecosystem/wechat/messages.js +9 -1
  36. package/lib/ecosystem/wechat/sending.js +36 -9
  37. package/lib/ecosystem/wechat/supervisor.d.ts +11 -2
  38. package/lib/ecosystem/wechat/supervisor.js +90 -9
  39. package/lib/history.d.ts +6 -4
  40. package/lib/history.js +61 -12
  41. package/lib/hostContract.d.ts +4 -1
  42. package/lib/index.d.ts +1 -0
  43. package/lib/index.js +27 -7
  44. package/lib/life/activity.d.ts +2 -0
  45. package/lib/life/activity.js +1 -1
  46. package/lib/life/alarm.d.ts +12 -4
  47. package/lib/life/alarm.js +21 -6
  48. package/lib/life/diary.d.ts +6 -0
  49. package/lib/life/diary.js +23 -2
  50. package/lib/life/runtime.d.ts +1 -0
  51. package/lib/life/runtime.js +57 -9
  52. package/lib/life/toolRegistry.d.ts +4 -3
  53. package/lib/life/toolRegistry.js +13 -3
  54. package/lib/life/types.d.ts +6 -1
  55. package/lib/memory.js +1 -4
  56. package/lib/memoryFiles.d.ts +1 -4
  57. package/lib/memoryFiles.js +18 -43
  58. package/lib/memoryStore.d.ts +1 -3
  59. package/lib/memoryStore.js +1 -1
  60. package/lib/memoryTools.js +2 -2
  61. package/lib/promptSection.d.ts +5 -4
  62. package/lib/promptSection.js +9 -8
  63. package/lib/runtime.d.ts +8 -3
  64. package/lib/runtime.js +60 -94
  65. package/lib/sourceArchive.js +4 -5
  66. package/lib/store.d.ts +1 -1
  67. package/lib/store.js +1 -1
  68. package/lib/types.d.ts +1 -4
  69. package/lib/worldPrompt.js +1 -1
  70. package/lib/worldSwitch.d.ts +15 -1
  71. package/lib/worldSwitch.js +24 -1
  72. package/package.json +1 -1
  73. package/scripts/compact-home.mjs +29 -29
  74. package/scripts/enable-tool-free-compaction.ps1 +33 -33
  75. package/scripts/import-stickers.mjs +17 -17
  76. package/scripts/update-world.mjs +2 -2
  77. package/src/ecosystem/wechat/windows/README.md +5 -3
  78. package/src/ecosystem/wechat/windows/adapter.py +6 -0
  79. package/src/ecosystem/wechat/windows/engine/NOTICE.md +6 -0
  80. package/src/ecosystem/wechat/windows/engine/build.ps1 +8 -2
  81. package/src/ecosystem/wechat/windows/engine/profiles.json +142 -114
  82. package/src/ecosystem/wechat/windows/presence.py +109 -109
  83. package/src/ecosystem/wechat/windows/sender.py +17 -5
  84. 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
  ### 修改人设和世界提示词后要手动应用
@@ -50,7 +53,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
50
53
 
51
54
  任务会等家空闲后执行一次,不打断当前对话;完成后的下一轮使用已保存的人设、名字、世界提示词和「我是谁」。压缩会调用模型并重建上下文缓存,没有可压缩内容时只刷新配置。面板显示执行结果或失败原因,停止世界会取消任务。
52
55
 
53
- 这个按钮只作用于家会话;其他已有会话在各自下一次成功压缩或重新加载时更新,新建会话直接读取已保存内容。
56
+ 这个按钮只作用于家会话;其他已有会话在各自下一次成功压缩、重新加载,或[隔了很久再开口](#很久没说话的窗口再开口时重新读一遍)时更新,新建会话直接读取已保存内容。
54
57
 
55
58
  ### 你自己的世界提示词不会被自动改
56
59
 
@@ -65,7 +68,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
65
68
  - 控制台「人设」全部留空时,什么都不改,沿用 DSH 的默认身份和你已有的人设。
66
69
  - DSH 其余的系统提示(计划、工具、文件引用等说明)不动。
67
70
  - 如果同一份人设在 DSH 里和控制台里各写了一遍,两份都会进提示词,内容会重复;只想要一份,清掉其中一处。
68
- - 范围是所有匹配该世界预设的普通会话,不限工作区;改动对已有会话在下次压缩或「应用并压缩家会话」后生效,新会话直接使用。
71
+ - 范围和世界提示词一样:她工作区里、匹配该世界预设的普通会话。工作区以外的会话哪怕用的是同一个预设(默认的 `standard` 就是 DSH 大多数会话的预设),也保持 DSH 原来的身份,不会变成她;改动对已有会话在下次压缩、「应用并压缩家会话」或隔了很久(默认 24 小时)再开口时生效,新会话直接使用。
69
72
 
70
73
  ## 压缩与记忆
71
74
 
@@ -80,7 +83,19 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
80
83
 
81
84
  ### 每日回顾后自动压缩
82
85
 
83
- 默认开,可在控制台概览的「回顾后自动压缩」关掉。每晚 23:00 的回顾里她会改写「我是谁」,而系统提示只在压缩之后才重新读取,不压缩的话新版要等到下一次压缩才生效,可能隔好几天。所以回顾那一轮结束、家空闲后,插件会自动执行一次[「应用并压缩家会话」](#修改人设和世界提示词后要手动应用):新版「我是谁」随压缩一起生效,压缩后最近的聊天原文会作为记忆块重新放回她眼前,衔接是接得上的。压缩本来就要重建缓存,这样不会多破坏一次,但每晚会多一次摘要调用。只在回顾真的送到她那里之后才触发,闹钟和问候不会;只作用于家会话,人设和世界提示词的修改仍然需要手动应用。没压成时(比如找不到压缩服务、摘要请求被模型拒绝),原因连同底层报错一起留在健康状态里,下一次压缩成功后消失。
86
+ 默认开,可在控制台概览的「回顾后自动压缩」关掉。每晚的回顾里她会改写「我是谁」,而正在用的会话里系统提示只在压缩之后才重新读取,不压缩的话新版要等到下一次压缩才生效,可能隔好几天。所以回顾那一轮结束、家空闲后,插件会自动执行一次[「应用并压缩家会话」](#修改人设和世界提示词后要手动应用):新版「我是谁」随压缩一起生效,压缩后最近的聊天原文会作为记忆块重新放回她眼前,衔接是接得上的。压缩本来就要重建缓存,这样不会多破坏一次,但每晚会多一次摘要调用。只在回顾真的送到她那里之后才触发,闹钟和问候不会;只作用于家会话,人设和世界提示词的修改仍然需要手动应用。没压成时(比如找不到压缩服务、摘要请求被模型拒绝),原因连同底层报错一起留在健康状态里,下一次压缩成功后消失。
87
+
88
+ ### 很久没说话的窗口再开口时重新读一遍
89
+
90
+ 记忆块、人设、世界提示词和「我是谁」平时只在会话打开和压缩之后读取,中途不动,这样才能留在模型服务的缓存里,正在聊的会话不会每一步都重新计费。代价是:一个很少用的窗口(比如几天才聊几句的 QQ 或微信群会话)从不压缩,就会一直停在打开那天的版本,不知道别处聊过什么,也看不到她后来改写的「我是谁」。
91
+
92
+ 所以一个会话**隔了 24 小时以上**(控制台「记忆」卡片里可改,1 到 720 小时)再开口时,插件按新打开的会话处理:这一轮的第一个请求就带着最新的记忆块、人设和「我是谁」。这么久没发请求,模型服务的缓存多半已经清掉了(DeepSeek 说明未使用的缓存“通常在几小时到几天内”清除,不保证),重新读基本不多花钱;就算缓存还在,也只多一次未命中。正在聊的会话不会中途停这么久,不受影响。时长算的是这个会话上一次请求模型到现在,改了以后各窗口从下一轮开始按新时长判断,不用重启;DSH 重启后的第一句本来就会重新读。
93
+
94
+ 想让窗口更快跟上(比如每天切换着用微信和 QQ),可以调小,例如 6 小时:隔夜再开口的窗口第二天第一句就会带上前一晚回顾后改写的「我是谁」,代价是缓存还没清掉时多一次未命中。DeepSeek 的缓存没有固定过期时间,调得越小,碰上缓存还在、白白多付一次的可能越大。
95
+
96
+ ### 近期记忆的轮数
97
+
98
+ 记忆块放最近多少轮,在控制台填,默认 200。默认值是按「最近的事完整摆在眼前」设计的;多端同时用、或者想省 token 时可以调小,代价是她直接记得的轮数变少,更早的事要靠 `memory_find` 自己去翻。记忆块留在会话里,之后每一步都随请求重发:平时按缓存命中计费,重新读进来的那一次按未命中计费。调小后两种都会变少。
84
99
 
85
100
  ### 主动触发一次压缩的脚本
86
101
 
@@ -89,20 +104,27 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
89
104
  ### 长期记忆的查找
90
105
 
91
106
  - **没有索引,也就没有升级时的建库**:聊天在 `archive.sqlite` 的原表里直接按字面扫描,日记等文件在查询时直接读,没有额外的表、队列或重建,旧档案升级后第一次查询就能用。扫描随聊天量线性变慢:我们量过合成数据,约 10 万条 50 毫秒、50 万条 300 毫秒以内,陪伴场景远用不到这个量级。
92
- - **查找的范围**:聊天和日记(`diaryDir` 里的 `.md`/`.txt`,一层)。自述不进查找,仍然全文放进提示。文件只有当前内容,旧版本不保存;`history` 参数还收,但不起作用。
107
+ - **查找的范围**:聊天和日记(`diaryDir` 里的 `.md`/`.txt`,一层)。自述不进查找,仍然全文放进提示。文件只有当前内容,旧版本不保存。
93
108
  - **查找的限制**:查询只认字面文字(区分大小写);没有共同文字、时间线索的往事找不回来;有来源读不到时结果里会带 `coverage`,零结果不代表没发生过;分页只限制返回的量,不限制扫描的量。
94
109
  - **一次返回的量是故意压小的**:`memory_find` 默认 8 条、每条摘录约 200 字,`memory_read` 默认 2000 字,因为工具结果会在这一轮之后的每一步被重发。要更多就翻页(`nextCursor`)或读原文,不要一次要几十条。
95
110
 
111
+ ### 过去的日记只读
112
+
113
+ 日记目录里按日期命名的 `YYYY-MM-DD.md`,她只能用 `write`、`edit` 改还没合上的那几天:今天,以及回顾还没做完的那天(回顾定在中午以前、或者回顾晚到第二天时,前一天的日记会一直开到那一轮回顾结束)。改已经合上的日子,工具会被拒绝,并告诉她在今天的日记里写下哪里记错了、现在怎么看。读日记不受影响;日记目录里不按日期命名的文件、子目录里的文件不管。这条只拦她的文件工具:`pwsh` 等命令行能写任何文件,没法可靠地分辨,所以不拦。你自己在编辑器里改日记不受影响。
114
+
115
+ ### 归档或记忆出错时她照常说话
116
+
117
+ 归档写不进去(比如磁盘满、数据库被占用)、某个会话的日志一时读不出来,或者记忆块建不出来时,她照常回话,问题显示在控制台的「健康」里。这期间说的话不会丢:它们在宿主的会话日志里,插件记着每个会话归档到了哪里,问题解决后,这个会话下一次有动静或 DSH 下次启动时,会从断点补进归档,不会重复。记忆块建不出来时,她眼前还是上一块(刚压缩完就没有),下一步会再试。补不回来的只有一种:宿主的会话日志在磁盘上坏了、一直读不出来,那个会话里的话就进不了归档,健康里会一直显示它。
118
+
96
119
  ## 世界范围与会话
97
120
 
98
121
  ### 对世界工作区以外的影响
99
122
 
100
- 只有下面这两项会作用到世界工作区以外的会话:
123
+ 只有下面这一项会作用到世界工作区以外的会话:
101
124
 
102
- 1. **人设**:控制台人设作为单独一段,取代 DSH 自带的默认身份句、排在宿主系统人设之后,所有匹配该世界预设的普通会话都会带上,不限工作区。
103
- 2. **只留对话的压缩**(装上插件后首次启动默认换上,可在配置里写 `replaceCompaction: false` 关掉):它替换的是整个 profile 的压缩方式,其他工作区的会话压缩时也会去掉工具调用过程,只留一段对话摘要。写代码等依赖工具过程的会话,压缩后会丢掉这些细节。
125
+ - **只留对话的压缩**(装上插件后首次启动默认换上,可在配置里写 `replaceCompaction: false` 关掉):它替换的是整个 profile 的压缩方式,其他工作区的会话压缩时也会去掉工具调用过程,只留一段对话摘要。写代码等依赖工具过程的会话,压缩后会丢掉这些细节。
104
126
 
105
- 除此之外,记忆、世界提示词、世界线、工具、通道和归档都不会进入工作区以外的会话。
127
+ 除此之外,人设、记忆、世界提示词、世界线、工具、通道和归档都不会进入工作区以外的会话。人设在 0.7.1 及以前不限工作区,所有用同一预设的会话都会带上;现在和其他部分一样只进她的工作区。以前在工作区外的窗口里和她聊、想继续带着人设的,把那个窗口挪进她的工作区。
106
128
 
107
129
  ### 看到“会话已离开世界工作区,请重新发送”
108
130
 
@@ -116,7 +138,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
116
138
 
117
139
  ### 微信支持版本
118
140
 
119
- 目前仅适配 **Windows x64 微信 `4.1.15.13`、`4.1.15.56` 的指定构建**。适配器会核对 `Weixin.dll` 的文件大小和 SHA256;其他构建(包括版本号相同但文件指纹不同的构建)会在加载原生桥前被拒绝。macOS、Linux 客户端暂不支持。升级微信前请确认新构建已有适配;各版本的实测范围见 [微信模块](src/ecosystem/wechat/windows/README.md)。
141
+ 目前适配 **Windows x64 微信的指定构建**。适配器核对 `Weixin.dll` 的文件大小和 SHA256,只有两项均匹配才加载原生桥。支持的构建及各版本的实测范围见 [微信模块](src/ecosystem/wechat/windows/README.md)。
120
142
 
121
143
  ### 微信风控与账号风险
122
144
 
package/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  ### 记得:像人一样记
19
19
 
20
- - **近期记忆**:你们最近数轮的对话原文,每次开始对话和每次压缩之后都放在她眼前,谁、什么时候、说了什么,一字不差。轮数在控制台里填,默认 200。
20
+ - **近期记忆**:你们最近数轮的对话原文,每次开始对话、每次压缩之后,以及一个窗口隔了很久(默认 24 小时,控制台可改)再开口时,都放在她眼前,谁、什么时候、说了什么,一字不差。轮数在控制台里填,默认 200。
21
21
  - **日记**:人生里重要的事,她自己写进日记,一天一篇。这是她的长期记忆。
22
22
  - **我是谁**:她写给自己的一份自述,随着她变化而改写。每晚回顾前,插件会留一份当时的版本,改过的都找得回来。
23
23
  - **范围内的原文留着**:按天归档用户和助手的正文。近期记忆以外的事,她可以自己去翻。
@@ -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 已就绪时直接切换,无需重启。
@@ -55,7 +56,7 @@ DSH 设置里的「世界控制台」:
55
56
  - **归档范围**:默认 `workspace`,归档家所在工作区的普通会话,包含独立微信群会话;`home` 仅当前家会话。保存范围后提示重启,重启前沿用原范围。启动时分页回扫所选范围内的会话日志,按消息实际时间重选最近配置轮数,下次请求前替换旧记忆块;没有时间过期。旧归档保留,范围外记录不再注入。旧配置 `world` 迁为 `workspace`。
56
57
  - **注入范围**:世界记忆、世界提示词、世界线工具和微信/QQ 通道仅进入世界工作区内匹配预设的普通会话,其他工作区即使用相同预设也不会收到。归档选为 `home` 时,同工作区的其他会话仍可读取家记忆。
57
58
 
58
- > 对世界工作区以外的会话,只有两项有影响:控制台人设和只留对话的压缩。详情见 [注意事项](NOTES.md#对世界工作区以外的影响)。
59
+ > 对世界工作区以外的会话,只有一项有影响:只留对话的压缩。详情见 [注意事项](NOTES.md#对世界工作区以外的影响)。
59
60
 
60
61
  ### 注意事项
61
62
 
@@ -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
@@ -306,19 +306,25 @@ window.__ModuleLoader__.load({
306
306
  h('button', { className: 'dw-btn', onClick: save }, '保存')),
307
307
  h(Status, { msg: msg }))
308
308
  }
309
- /** 记忆块带最近几轮:默认 200,下次开始对话或压缩之后生效。 */
309
+ /** 记忆块带最近几轮:默认 200,下次开始对话或压缩之后生效;隔多少小时没开口就重新读:默认 24,下一轮生效。 */
310
310
  function Memory(props) {
311
311
  var mem = props.mem, window_ = mem && mem.windowTurns || 200
312
312
  var activeScope = mem && mem.archiveScope || 'workspace'
313
313
  var scopeNames = { home: '仅家会话', workspace: '家所在工作区' }
314
314
  var scopeState = useState(mem && mem.selectedArchiveScope || activeScope), scope = scopeState[0], setScope = scopeState[1]
315
315
  var draftState = useState(String(window_)), draft = draftState[0], setDraft = draftState[1]
316
+ var coldState = useState(String(mem && mem.coldHours || 24)), cold = coldState[0], setCold = coldState[1]
316
317
  var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
317
318
  function save() {
318
319
  var text = String(draft).trim(), value = text === '' ? null : Number(text)
319
320
  if (value !== null && !(Number.isInteger(value) && value >= 1)) { setMsg('请填一个不小于 1 的整数,留空恢复默认 200'); return }
320
321
  post('memory', { turns: value }).then(function () { setMsg('已保存。下次开始对话或压缩之后生效。'); if (value === null) setDraft('200'); if (props.onSaved) props.onSaved() }, failedTo(setMsg))
321
322
  }
323
+ function saveCold() {
324
+ var text = String(cold).trim(), value = text === '' ? null : Number(text)
325
+ if (value !== null && !(Number.isInteger(value) && value >= 1 && value <= 720)) { setMsg('请填 1 到 720 之间的整数小时,留空恢复默认 24'); return }
326
+ post('memory', { coldHours: value }).then(function () { setMsg('已保存。各窗口从下一轮开始按新时长判断。'); if (value === null) setCold('24'); if (props.onSaved) props.onSaved() }, failedTo(setMsg))
327
+ }
322
328
  function saveScope() {
323
329
  post('archive-scope', { scope: scope }).then(function (result) {
324
330
  setMsg(result.restartRequired ? '已保存。请重启 DSH,启动后按新范围和消息时间重建记忆块。' : '归档范围已保存。')
@@ -338,6 +344,10 @@ window.__ModuleLoader__.load({
338
344
  h('div', { key: 's', className: 'dw-setting' },
339
345
  h('input', { type: 'text', inputMode: 'numeric', 'aria-label': '记忆带最近几轮', placeholder: '最近几轮,留空为 200', value: draft, onChange: function (e) { setDraft(e.target.value); setMsg('') } }),
340
346
  h('button', { className: 'dw-btn', onClick: save }, '保存')),
347
+ h('div', { key: 'cd', className: 'dw-muted' }, '一个窗口隔这么久再开口,就重新读一遍记忆块、人设和「我是谁」;正在聊的窗口不受影响。'),
348
+ h('div', { key: 'c', className: 'dw-setting' },
349
+ h('input', { type: 'text', inputMode: 'numeric', 'aria-label': '久未开口后重新读取(小时)', placeholder: '小时,留空为 24', value: cold, onChange: function (e) { setCold(e.target.value); setMsg('') } }),
350
+ h('button', { className: 'dw-btn', onClick: saveCold }, '保存')),
341
351
  h(Status, { key: 'x', msg: msg }),
342
352
  ] : h('div', { className: 'dw-muted' }, '—'))
343
353
  }
@@ -385,6 +395,30 @@ window.__ModuleLoader__.load({
385
395
  ' ', props.on ? '已开启' : '已关闭'),
386
396
  h(Status, { msg: msg }))
387
397
  }
398
+ /** 每日回顾和早上兜底的时间:留空恢复默认;保存后已排好的回顾和早上闹钟立刻改到新时间。 */
399
+ function Schedule(props) {
400
+ var s = props.schedule
401
+ var reviewState = useState(s.review), review = reviewState[0], setReview = reviewState[1]
402
+ var wakeState = useState(s.wake), wake = wakeState[0], setWake = wakeState[1]
403
+ var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
404
+ function save() {
405
+ var values = [String(review).trim(), String(wake).trim()]
406
+ 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 }
407
+ post('schedule', { review: values[0] || null, wake: values[1] || null }).then(function () {
408
+ if (!values[0]) setReview(s.defaults.review); if (!values[1]) setWake(s.defaults.wake)
409
+ setMsg('已保存。已排好的回顾和早上闹钟已改到新时间,她自己定的闹钟不变。')
410
+ if (props.onSaved) props.onSaved()
411
+ }, failedTo(setMsg))
412
+ }
413
+ return h(Card, { title: '作息' },
414
+ h('div', { className: 'dw-muted' }, '每日回顾:她回头看一天、写日记的时间,定在中午以前就回顾前一天。早上:她没定闹钟时醒来的时间。留空恢复默认(回顾 ' + s.defaults.review + ',早上 ' + s.defaults.wake + ')。'),
415
+ h('div', { className: 'dw-setting' },
416
+ h('label', null, '每日回顾 ', h('input', { type: 'time', 'aria-label': '每日回顾时间', value: review, onChange: function (e) { setReview(e.target.value); setMsg('') } })),
417
+ h('label', null, '早上 ', h('input', { type: 'time', 'aria-label': '早上醒来时间', value: wake, onChange: function (e) { setWake(e.target.value); setMsg('') } })),
418
+ h('button', { className: 'dw-btn', onClick: save }, '保存')),
419
+ h('div', { className: 'dw-muted' }, '她看到的工具说明里写的早上时间,要等新开的会话或重启 DSH 后才更新。'),
420
+ h(Status, { msg: msg }))
421
+ }
388
422
  /** 微信:适配器每约 2 秒来问一次,最近一次来问的时间就是连接状态;两个读取参数在它下次来问时同步。 */
389
423
  function Wechat(props) {
390
424
  var w = props.wechat, zone = props.zone
@@ -395,7 +429,7 @@ window.__ModuleLoader__.load({
395
429
  var contacted = age != null && age < 30000, offline = contacted && w.account === 'offline'
396
430
  var ad = w.adapter
397
431
  var blocked = ad && ad.needsHuman
398
- var stateText = blocked ? '● 有消息待核对,适配器已停' : !contacted ? (ad && ad.running ? '● 适配器启动中' : ad && ad.error ? '● 等待适配器文件' : w.lastContactAt ? '● 适配器已断开' : '● 等待适配器') : offline ? '● 微信离线,等待重新登录' : '● 已连接'
432
+ var stateText = blocked ? '● 有消息待核对,适配器已停' : !contacted ? (ad && ad.building ? '● 正在重新构建原生桥' : ad && ad.running ? '● 适配器启动中' : ad && ad.error ? '● 适配器没能启动' : w.lastContactAt ? '● 适配器已断开' : '● 等待适配器') : offline ? '● 微信离线,等待重新登录' : '● 已连接'
399
433
  var adMsgState = useState(''), adMsg = adMsgState[0], setAdMsg = adMsgState[1]
400
434
  function restartAdapter() {
401
435
  setAdMsg('正在重启…')
@@ -471,6 +505,17 @@ window.__ModuleLoader__.load({
471
505
  if (isNaN(at.getTime())) { setMsg('这个时间看不懂,重挑一下'); return }
472
506
  change({ mutedUntil: at.toISOString() })
473
507
  }
508
+ // 合批窗口:同一个人在这么多秒内连发几句,合成一次问。填 0 就是每句单独回。
509
+ var quietState = useState(''), quiet = quietState[0], setQuiet = quietState[1]
510
+ useEffect(function () {
511
+ var ms = props.native && typeof props.native.batchQuietMs === 'number' ? String(Math.round(props.native.batchQuietMs / 1000)) : ''
512
+ setQuiet(function (cur) { return cur === '' ? ms : cur })
513
+ }, [props.native && props.native.batchQuietMs])
514
+ function saveQuiet() {
515
+ var sec = Number(String(quiet).trim())
516
+ if (!isFinite(sec) || sec < 0 || sec > 30) { setMsg('填 0 到 30 之间的秒数(一批最多等 30 秒)'); return }
517
+ change({ batchQuietMs: Math.round(sec * 1000) })
518
+ }
474
519
  // 白名单:谁的话能进来。打开时填上现有的名单,之后不覆盖正在改的字。
475
520
  var ids = props.native ? [(props.native.allowPrivateIds || []).join(', '), (props.native.allowGroupsIds || []).join(', ')] : ['', '']
476
521
  var allowState = useState({ from: '', people: '', groups: '' }), allow = allowState[0], setAllow = allowState[1]
@@ -513,6 +558,15 @@ window.__ModuleLoader__.load({
513
558
  h('span', { key: 't' }, n.autoReply === true ? ' 会自己回话' : ' 只看不回'),
514
559
  ])
515
560
  })(props.native),
561
+ (function (n) {
562
+ if (!n) return null
563
+ var ms = typeof n.batchQuietMs === 'number' ? n.batchQuietMs : 10000
564
+ return h('div', { key: 'quiet', className: 'dw-setting' }, [
565
+ h('span', { key: 's', className: 'dw-muted' }, ms ? '连着发几句:' + (ms / 1000) + ' 秒内合成一次问' : '连着发几句:每句单独回'),
566
+ 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) } }),
567
+ h('button', { key: 'b', className: 'dw-btn', disabled: busy, onClick: saveQuiet }, '存'),
568
+ ])
569
+ })(props.native),
516
570
  (function (n) {
517
571
  if (!n) return null
518
572
  return h('div', { key: 'mute', className: 'dw-setting' }, [
@@ -643,6 +697,7 @@ window.__ModuleLoader__.load({
643
697
  h(Budget, { budget: snap.budget, onSaved: props.refresh }),
644
698
  snap.workspace ? h(WorkspacePermission, { workspace: snap.workspace, onSaved: props.refresh }) : null,
645
699
  typeof snap.compactAfterReview === 'boolean' ? h(CompactAfterReview, { on: snap.compactAfterReview, onSaved: props.refresh }) : null,
700
+ snap.schedule ? h(Schedule, { schedule: snap.schedule, onSaved: props.refresh }) : null,
646
701
  snap.modules && (snap.modules.wechat.available || snap.modules.qq.available) ? h(Modules, { modules: snap.modules, running: snap.running, onSaved: props.refresh }) : null))
647
702
  }
648
703
  function Records(props) {
@@ -843,7 +898,7 @@ window.__ModuleLoader__.load({
843
898
  return ctx.slots.register({ name: 'settings.section', id: 'world-console', order: 28, label: '世界控制台' }, function () { return h(Console) })
844
899
  })
845
900
  }
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 })
901
+ Object.defineProperty(exports, '__test', { value: { Memory: Memory, 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
902
  return exports
848
903
  },
849
904
  })
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;
@@ -41,10 +41,17 @@ export interface ConsoleActions {
41
41
  setDailyBudget(yuan: number | undefined): void;
42
42
  /** Turns in her memory block; undefined goes back to the default. */
43
43
  setMemoryTurns(turns: number | undefined): void;
44
+ /** Hours of silence after which a session re-reads her memory and prompt; undefined goes back to the default. */
45
+ setColdHours(hours: number | undefined): void;
44
46
  setArchiveScope(scope: MemoryArchiveScope): boolean;
45
47
  setWorkspacePermission(permission: string): void;
46
48
  /** Whether the evening look back is followed by applying and compacting her home (on unless turned off). */
47
49
  setCompactAfterReview(on: boolean): void;
50
+ /** Local HH:MM of the evening look back and the morning wake; a field left out stays, null goes back to its default. */
51
+ setSchedule(schedule: {
52
+ review?: string | null;
53
+ wake?: string | null;
54
+ }): void;
48
55
  /** A field left out stays as it is; null goes back to its default. */
49
56
  /** 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
57
  setModules(modules: {
@@ -1,7 +1,8 @@
1
1
  import { jsonObject, knownHost, readBody, sendJson } from "../http.js";
2
2
  import { PERSONA_LAYERS } from "../persona.js";
3
- import { validTurns, validWechatBuffer, validWechatContext, validWorkspacePermission, MAX_WECHAT_BUFFER_SECONDS, MAX_WECHAT_CONTEXT } from "../worldSwitch.js";
3
+ import { validColdHours, validTurns, validWechatBuffer, MAX_COLD_HOURS, 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
  }
@@ -67,10 +68,17 @@ async function write(actions, path, body) {
67
68
  return ok();
68
69
  }
69
70
  case '/console/memory': {
70
- const turns = body?.turns;
71
- if (turns !== null && !validTurns(turns))
71
+ const turns = body?.turns, coldHours = body?.coldHours;
72
+ if (turns !== undefined && turns !== null && !validTurns(turns))
72
73
  return bad('turns must be a whole number of at least 1, or null');
73
- actions.setMemoryTurns(turns === null ? undefined : turns);
74
+ if (coldHours !== undefined && coldHours !== null && !validColdHours(coldHours))
75
+ return bad(`coldHours must be a whole number from 1 to ${MAX_COLD_HOURS}, or null`);
76
+ if (turns === undefined && coldHours === undefined)
77
+ return bad('nothing to change');
78
+ if (turns !== undefined)
79
+ actions.setMemoryTurns(turns ?? undefined);
80
+ if (coldHours !== undefined)
81
+ actions.setColdHours(coldHours ?? undefined);
74
82
  return ok();
75
83
  }
76
84
  case '/console/wechat': {
@@ -105,6 +113,16 @@ async function write(actions, path, body) {
105
113
  actions.setCompactAfterReview(body.on);
106
114
  return ok();
107
115
  }
116
+ case '/console/schedule': {
117
+ const review = body?.review, wake = body?.wake;
118
+ for (const [name, value] of [['review', review], ['wake', wake]])
119
+ if (value !== undefined && value !== null && !validClockTime(value))
120
+ return bad(`${name} must be HH:MM (00:00–23:59), or null`);
121
+ if (review === undefined && wake === undefined)
122
+ return bad('nothing to change');
123
+ actions.setSchedule({ ...(review === undefined ? {} : { review: review }), ...(wake === undefined ? {} : { wake: wake }) });
124
+ return ok();
125
+ }
108
126
  case '/console/workspace-permission': {
109
127
  if (!validWorkspacePermission(body?.permission))
110
128
  return bad('工作区权限必须为非空字符串');
@@ -148,11 +166,11 @@ export async function handleConsole(sources, actions, request) {
148
166
  }
149
167
  case '/console/prompts': return ok(actions.prompts());
150
168
  case '/console/memory/find': {
151
- const input = memoryInput(url.searchParams, ['limit'], ['history'], ['kinds']);
169
+ const input = memoryInput(url.searchParams, ['limit'], ['kinds']);
152
170
  return memoryCall(sources.memoryFind && (() => sources.memoryFind(input)));
153
171
  }
154
172
  case '/console/memory/read': {
155
- const input = memoryInput(url.searchParams, ['offset', 'limit'], [], []);
173
+ const input = memoryInput(url.searchParams, ['offset', 'limit'], []);
156
174
  return memoryCall(sources.memoryRead && (() => sources.memoryRead(input)));
157
175
  }
158
176
  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 {
@@ -29,8 +30,14 @@ export interface SnapshotDeps {
29
30
  dailyBudget(): number | undefined;
30
31
  /** Turns her memory block carries. */
31
32
  memoryTurns(): number;
33
+ /** Hours of silence after which a session re-reads her memory block and prompt. */
34
+ coldHours?(): number;
32
35
  selectedArchiveScope?(): MemoryArchiveScope;
33
36
  compactAfterReview?(): boolean;
37
+ /** The evening look back and the morning wake, with what an empty field goes back to; absent without the life line. */
38
+ schedule?(): DailySchedule & {
39
+ defaults: DailySchedule;
40
+ };
34
41
  workspacePermissions?(): {
35
42
  defaultPermission: string;
36
43
  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,10 +27,11 @@ 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()],
33
- memory: { index: deps.longTerm?.status() ?? null, turns: turns.length, windowTurns: window, archiveScope, selectedArchiveScope, restartRequired: archiveScope !== selectedArchiveScope, approxTokens: estimateTokens(renderHistory(turns, config.timeZone, deps.names(), archiveScope === 'home')), oldest: turns.at(-1)?.messages[0]?.occurredAt, ...archive.stats() },
34
+ memory: { index: deps.longTerm?.status() ?? null, turns: turns.length, windowTurns: window, coldHours: deps.coldHours?.() ?? null, archiveScope, selectedArchiveScope, restartRequired: archiveScope !== selectedArchiveScope, approxTokens: estimateTokens(renderHistory(turns, config.timeZone, deps.names(), archiveScope === 'home')), oldest: turns.at(-1)?.messages[0]?.occurredAt, ...archive.stats() },
34
35
  wechat: deps.wechat?.() ?? null,
35
36
  compactions: lifeStore?.compactions().slice(-5).reverse() ?? [],
36
37
  diaryDates: diary.dates(), activityDays: lifeStore?.activityDays() ?? [],
@@ -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': {