dsh-world 0.7.2 → 0.7.4
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 +403 -379
- package/INSTALL.md +314 -314
- package/LICENSE +21 -21
- package/NOTES.md +23 -13
- package/README.md +22 -7
- package/client/index.js +74 -27
- package/cordis.patch.yml +6 -6
- package/lib/archiveSelection.d.ts +6 -2
- package/lib/archiveSelection.js +21 -12
- package/lib/compaction.d.ts +7 -0
- package/lib/compaction.js +18 -9
- package/lib/compactionSwap.d.ts +17 -0
- package/lib/compactionSwap.js +68 -6
- package/lib/console/routes.d.ts +2 -3
- package/lib/console/routes.js +7 -8
- package/lib/console/snapshot.d.ts +1 -3
- package/lib/console/snapshot.js +0 -3
- package/lib/ecosystem/bridge/bridge.d.ts +5 -0
- package/lib/ecosystem/bridge/bridge.js +2 -1
- package/lib/ecosystem/bridge/route.d.ts +4 -6
- package/lib/ecosystem/bridge/route.js +34 -58
- package/lib/ecosystem/qq/panel.d.ts +0 -1
- package/lib/ecosystem/qq/route.d.ts +6 -7
- package/lib/ecosystem/qq/route.js +10 -10
- package/lib/ecosystem/qq/snowluma-start.d.ts +1 -0
- package/lib/ecosystem/qq/snowluma-start.js +41 -8
- package/lib/ecosystem/qq/supervisor.d.ts +1 -2
- package/lib/ecosystem/qq/supervisor.js +4 -2
- package/lib/ecosystem/qq-native/index.js +2 -0
- package/lib/ecosystem/qq-native/native-bridge.d.ts +0 -1
- package/lib/ecosystem/qq-native/native-bridge.js +0 -2
- package/lib/ecosystem/qq-native/snowluma.js +11 -2
- package/lib/ecosystem/shared/turn.d.ts +3 -0
- package/lib/ecosystem/shared/turn.js +9 -2
- package/lib/ecosystem/wechat/home.d.ts +3 -0
- package/lib/ecosystem/wechat/home.js +12 -4
- package/lib/ecosystem/wechat/index.d.ts +0 -1
- package/lib/ecosystem/wechat/index.js +9 -6
- package/lib/hostContract.d.ts +19 -0
- package/lib/index.js +117 -49
- package/lib/life/toolRegistry.js +2 -2
- package/lib/memoryFiles.d.ts +0 -1
- package/lib/memoryStore.d.ts +0 -1
- package/lib/memoryStore.js +0 -1
- package/lib/memoryTools.d.ts +0 -1
- package/lib/memoryTools.js +2 -3
- package/lib/mood.d.ts +28 -0
- package/lib/mood.js +69 -0
- package/lib/promptSection.d.ts +7 -5
- package/lib/promptSection.js +74 -28
- package/lib/runtime.d.ts +6 -2
- package/lib/runtime.js +163 -26
- package/lib/self.d.ts +1 -1
- package/lib/self.js +1 -1
- package/lib/sourceArchive.d.ts +4 -2
- package/lib/sourceArchive.js +18 -4
- package/lib/store.js +2 -1
- package/lib/types.d.ts +3 -1
- package/lib/worldPrompt.d.ts +2 -3
- package/lib/worldPrompt.js +2 -3
- package/lib/worldRoutes.d.ts +9 -0
- package/lib/worldRoutes.js +29 -0
- package/lib/worldScope.d.ts +5 -5
- package/lib/worldScope.js +16 -7
- package/lib/worldSwitch.d.ts +1 -2
- package/lib/worldSwitch.js +1 -1
- package/package.json +17 -16
- package/scripts/compact-home.mjs +29 -29
- package/scripts/enable-tool-free-compaction.ps1 +33 -33
- package/scripts/import-stickers.mjs +17 -17
- package/scripts/update-world.mjs +2 -2
- package/src/ecosystem/README.md +1 -1
- package/src/ecosystem/wechat/windows/README.md +3 -3
- package/src/ecosystem/wechat/windows/adapter.py +21 -3
- package/src/ecosystem/wechat/windows/engine/profiles.json +142 -142
- package/src/ecosystem/wechat/windows/presence.py +109 -109
- package/templates/alarm.md +2 -2
- package/templates/world-prompt.md +11 -2
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,13 +16,17 @@
|
|
|
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
21
|
- **在控制台写了人设,它会取代 DSH 自带的那句默认身份**;你已经在 DSH 里设好的系统人设原样保留。详情:[人设和 DSH 自带的系统提示词](#人设和-dsh-自带的系统提示词)。
|
|
22
22
|
- **微信和 QQ 默认都是关的**,要用先在配置里启用,再到控制台「概览 → 接入」拨开(已经在用微信的世界升级后保持开着)。微信群里被 @ 时默认带前 5 条消息作上下文,控制台微信页可调 1–20。详情:[微信的开关](#微信的开关)、[QQ 的开关](#qq-的开关)。
|
|
23
23
|
|
|
24
24
|
## 安装与升级
|
|
25
25
|
|
|
26
|
+
### DSH 0.2.2 的运行时要求
|
|
27
|
+
|
|
28
|
+
DSH 0.2.2-rc.1 要求 Node.js 至少 24.9,升级自部署宿主时请同时检查运行时。插件仍兼容原有 DSH 0.2.1;升级不迁移归档、不覆盖自定义模板或配置。新版宿主在每步开始时确定可用工具,工作区变化会在下一步更新工具列表;已经发出的请求仍会在执行工具时重新检查范围。
|
|
29
|
+
|
|
26
30
|
### 默认换用只留对话的压缩
|
|
27
31
|
|
|
28
32
|
默认自动换上。装好 `dsh-world` 后第一次启动,插件会把你 profile 的 `cordis.patch.yml` 里原版压缩那一行换成 `dsh-world/compaction`,先在同目录留一份 `.dsh-world.<随机>.bak` 备份,重启 DSH 后生效,世界面板的健康状态里会提示这件事。只有找到唯一一条原版压缩配置时才会改;已经换过、写法对不上或有多条时什么都不动。每个世界只试这一次:之后你手动改回原版,它不会再替你换。不想换,在 `dsh-world` 的配置里写 `replaceCompaction: false`。手动启用或恢复也可以用下面的脚本:
|
|
@@ -37,6 +41,8 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
37
41
|
|
|
38
42
|
整份写进 profile 的代价:之后 DSH 升级对这个预设的改动(新工具、提示词调整)不会自动进来,因为 profile 里这份会盖住 DSH 自带的。想跟上新版,恢复备份(或删掉 profile 里 `preset-standard` 那一项),再把 `world.json` 里的 `compactionSwapped` 删掉,下次启动会按新版预设重新换一次。只影响这个预设:其他预设的会话仍用原版压缩。
|
|
39
43
|
|
|
44
|
+
DSH 从预设里删掉某一行时,这份副本还留着它,DSH 找不到那个插件就整个预设都不挂,用这个预设的会话全都打不开。已知的一处:DSH 0.2.2 把 `list_agents` 并进了 `dsh-tool-subagent-control`,副本里 `@deepseek-ai/dsh-tool-subagent-control/list-agents` 那一行不再存在,健康里是「家打不开……never started」。插件每次启动会检查 profile 里的每份预设副本,DSH 自带的预设已经不带这一行时,先备份 `cordis.patch.yml` 再删掉它,健康里说明删了哪个预设,重启 DSH 后恢复;DSH 0.2.1 上这一行仍然有效,不会被删。别的行插件不会替你删:遇到同样「never started」的报错,退出 DSH,对照 DSH 自带的预设,手动删掉报错里那一行。故障期间发来的微信消息不会自动补送,那个聊天会停在「上次消息结果尚未确认」,按 [微信模块](src/ecosystem/wechat/windows/README.md) 的 `Acknowledge` 流程核对(运行中的适配器会占着它,先在控制台关掉微信模块,做完再打开),然后重发那条消息。
|
|
45
|
+
|
|
40
46
|
换不成时(找不到预设、预设里没有或有多条原版压缩),插件不改任何文件,在健康状态里说明:自动压缩仍由预设自带的压缩负责,下面的 75% 触发线不生效。控制台的「应用并压缩」和回顾后压缩不受影响,它们直接使用家会话预设里的那个压缩。
|
|
41
47
|
|
|
42
48
|
### 微信首次接入与升级
|
|
@@ -47,13 +53,11 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
47
53
|
|
|
48
54
|
## 人设与提示词
|
|
49
55
|
|
|
50
|
-
###
|
|
51
|
-
|
|
52
|
-
**修改人设、世界提示词后,需要手动热加载,才能让已有家会话及时用上新内容。** 先保存修改,再到「人设」或「世界提示词」页点击 **「应用并压缩家会话」**。仅保存或重新打开控制台,不会立即刷新家会话。
|
|
56
|
+
### 提示词保存后何时生效
|
|
53
57
|
|
|
54
|
-
|
|
58
|
+
**人设、世界提示词和「我是谁」保存后,世界里的现有会话会在下一轮对话读取改动。** 文件内容相同时继续复用原有提示词。改动提示词可能让模型服务重新计算缓存。
|
|
55
59
|
|
|
56
|
-
|
|
60
|
+
**「应用并压缩家会话」**会等家空闲后整理聊天历史,压缩时调用模型并重建上下文缓存。面板显示执行结果或失败原因,停止世界会取消任务。
|
|
57
61
|
|
|
58
62
|
### 你自己的世界提示词不会被自动改
|
|
59
63
|
|
|
@@ -68,7 +72,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
68
72
|
- 控制台「人设」全部留空时,什么都不改,沿用 DSH 的默认身份和你已有的人设。
|
|
69
73
|
- DSH 其余的系统提示(计划、工具、文件引用等说明)不动。
|
|
70
74
|
- 如果同一份人设在 DSH 里和控制台里各写了一遍,两份都会进提示词,内容会重复;只想要一份,清掉其中一处。
|
|
71
|
-
-
|
|
75
|
+
- 范围和世界提示词一样,只在她工作区里、匹配该世界预设的普通会话生效。已有会话下一轮使用改动,新会话直接读取已保存的内容。
|
|
72
76
|
|
|
73
77
|
## 压缩与记忆
|
|
74
78
|
|
|
@@ -83,15 +87,17 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
83
87
|
|
|
84
88
|
### 每日回顾后自动压缩
|
|
85
89
|
|
|
86
|
-
|
|
90
|
+
默认开,可在控制台概览的「回顾后自动压缩」关掉。每日回顾送达、家空闲后,插件会压缩一次家会话,随后把最近的聊天原文作为记忆块放回她眼前。每晚会多一次摘要调用。压缩失败的原因会显示在控制台健康状态里。「我是谁」的改动会在下一轮对话生效。
|
|
87
91
|
|
|
88
92
|
### 很久没说话的窗口再开口时重新读一遍
|
|
89
93
|
|
|
90
|
-
|
|
94
|
+
近期记忆块在会话打开或压缩之后读取,以便留在模型服务的缓存里。一个很少用的窗口(比如几天才聊几句的 QQ 或微信群会话)如果一直没压缩,看到的仍是较早的近期记忆。
|
|
91
95
|
|
|
92
|
-
所以一个会话**隔了 24 小时以上**(控制台「记忆」卡片里可改,1 到 720
|
|
96
|
+
所以一个会话**隔了 24 小时以上**(控制台「记忆」卡片里可改,1 到 720 小时)再开口时,插件先把之前的对话压缩成一段摘要,再按新打开的会话处理:这一轮的第一个请求就带着最新的记忆块、人设和「我是谁」。这么久没发请求,模型服务的缓存多半已经清掉了(DeepSeek 说明未使用的缓存“通常在几小时到几天内”清除,不保证),这一轮本来就要整段重新计费;先压缩以后,之后每一步带的是摘要而不是整段旧对话,会话越长越省。最近的原文不会丢:记忆块会把最近几轮(包括这个窗口自己的)原样放回她眼前,归档里也一直留着。正在聊的会话不会中途停这么久,不受影响。
|
|
93
97
|
|
|
94
|
-
|
|
98
|
+
代价是这一句的回复要等摘要做完才开始,旧对话很长时会慢一些。压缩只在用插件自带的「只留对话」压缩时进行(默认会换上);没换上、或者这次压缩失败时,照旧只重读记忆块和人设,失败原因显示在控制台的「健康」里。时长算的是这个会话上一次请求模型到现在,改了以后各窗口从下一轮开始按新时长判断,不用重启;DSH 重启后的第一句本来就会重新读。
|
|
99
|
+
|
|
100
|
+
想让各窗口更快看到最新的近期记忆(比如每天切换着用微信和 QQ),可以把时长调小,例如 6 小时。DeepSeek 的缓存没有固定过期时间,调得越小,碰上缓存还在、额外付一次缓存未命中费用的可能越大。
|
|
95
101
|
|
|
96
102
|
### 近期记忆的轮数
|
|
97
103
|
|
|
@@ -104,7 +110,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
104
110
|
### 长期记忆的查找
|
|
105
111
|
|
|
106
112
|
- **没有索引,也就没有升级时的建库**:聊天在 `archive.sqlite` 的原表里直接按字面扫描,日记等文件在查询时直接读,没有额外的表、队列或重建,旧档案升级后第一次查询就能用。扫描随聊天量线性变慢:我们量过合成数据,约 10 万条 50 毫秒、50 万条 300 毫秒以内,陪伴场景远用不到这个量级。
|
|
107
|
-
- **查找的范围**:聊天和日记(`diaryDir` 里的 `.md`/`.txt
|
|
113
|
+
- **查找的范围**:聊天和日记(`diaryDir` 里的 `.md`/`.txt`,一层)。查找读取日记的当前版本。自述放进系统提示词,最多读前 5000 字。
|
|
108
114
|
- **查找的限制**:查询只认字面文字(区分大小写);没有共同文字、时间线索的往事找不回来;有来源读不到时结果里会带 `coverage`,零结果不代表没发生过;分页只限制返回的量,不限制扫描的量。
|
|
109
115
|
- **一次返回的量是故意压小的**:`memory_find` 默认 8 条、每条摘录约 200 字,`memory_read` 默认 2000 字,因为工具结果会在这一轮之后的每一步被重发。要更多就翻页(`nextCursor`)或读原文,不要一次要几十条。
|
|
110
116
|
|
|
@@ -118,6 +124,10 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
118
124
|
|
|
119
125
|
## 世界范围与会话
|
|
120
126
|
|
|
127
|
+
### 新会话的预设选择
|
|
128
|
+
|
|
129
|
+
在她的工作区新建会话后,选择世界配置的 `agentPreset`(默认 `standard`),第一句就会带上世界提示、人设、记忆和记忆工具,不需要把 DSH 的全局默认预设也改成它。选择其他预设就不注入这些内容;恢复会话时按日志里的最后一次选择判断。工作区以外仍然不注入,DSH 也仍然只允许尚未开始聊天的空白会话切换预设。
|
|
130
|
+
|
|
121
131
|
### 对世界工作区以外的影响
|
|
122
132
|
|
|
123
133
|
只有下面这一项会作用到世界工作区以外的会话:
|
|
@@ -192,4 +202,4 @@ QQ 消息由插件自己那条原生通道送进家里,插件没有为它做
|
|
|
192
202
|
|
|
193
203
|
### 看门狗
|
|
194
204
|
|
|
195
|
-
对应 `supervise`,默认开。QQ 开着时每 30 秒探一次 `wsUrl`
|
|
205
|
+
对应 `supervise`,默认开。QQ 开着时每 30 秒探一次 `wsUrl` 的端口,不通时先按 `snowlumaHome` 检查已有进程,没有实例才把 SnowLuma 拉起来(本机有 `SnowLuma-watchdog` 计划任务时借它跑,能活过 DSH 重启;没有就直接起进程,只活到 DSH 退出)。一次启动后等待 90 秒,给进程启动和 QQ 握手留出时间;已有进程但端口仍不通时只提示等待,不重复启动,也不自动结束它,请检查 SnowLuma 控制台。拉不起来或查不了进程的原因写在卡上。不想让插件动手就设成 `false`,卡上的「拉起 SnowLuma」按钮照旧能用,也会检查已有实例和等待中的启动。
|
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
- **近期记忆**:你们最近数轮的对话原文,每次开始对话、每次压缩之后,以及一个窗口隔了很久(默认 24 小时,控制台可改)再开口时,都放在她眼前,谁、什么时候、说了什么,一字不差。轮数在控制台里填,默认 200。
|
|
21
21
|
- **日记**:人生里重要的事,她自己写进日记,一天一篇。这是她的长期记忆。
|
|
22
22
|
- **我是谁**:她写给自己的一份自述,随着她变化而改写。每晚回顾前,插件会留一份当时的版本,改过的都找得回来。
|
|
23
|
+
- **心情值**:`room/mood.md` 是她自己写的,一行一件:`开心 6` 这样的「名字 数值」是一种心情(0 到 10 的整数),不以数字结尾的行是心情旁边的几件小事(最多三行)。默认的一组是开心、兴奋、平静、累、困、烦、难过、紧张,没写的算 0,她也可以加自己的词。她世界里的会话在每轮开头、以及她改过之后的下一步,把当前的心情值作为一条快照放在时间块前面;没变就不重复放,旧的那条不删,以最新一条为准,压缩时一起清掉,不打乱缓存。插件只读、不判断、不衰减、不提醒她改;没有 `mood.md` 就什么都不放。快照不进归档;写错的行只在快照里告诉她,文件读不出来才进健康状态。
|
|
23
24
|
- **范围内的原文留着**:按天归档用户和助手的正文。近期记忆以外的事,她可以自己去翻。
|
|
24
25
|
- **找回过去**:`memory_find` 与 `memory_read` 两个工具(一次默认只返回 8 条、每条约 200 字的摘录,要更多自己翻页或读原文,免得每轮重发的上下文越滚越大),按原文里的字面线索、时间、种类或来源,在聊天原文和日记里统一查找,并读原文。控制台的「档案」页是同一份查找的只读入口。
|
|
25
26
|
|
|
@@ -47,7 +48,7 @@ DSH 设置里的「世界控制台」:
|
|
|
47
48
|
- **人设**:分层写她是谁:名字、她是谁、性格、说话方式、愿景、补充,旁边实时预览她读到的样子。写了以后,它取代 DSH 自带的那句默认身份(“You are an AI agent powered by DeepSeek Harness.”);你已经在 DSH 里设过的系统人设(宿主设置里的人设,或当前预设自带的人设)不会被替换,原样保留,这里写的排在它后面;预设如果已经自己改写了那句默认身份,也按它写的保留,不会被盖掉。全部留空时什么都不改,沿用 DSH 的默认身份和你已有的人设,控制台不自动回填。DSH 里其余的系统提示(计划、工具和文件引用等说明)不动。
|
|
48
49
|
- **世界提示词**:你想对她说的话,以及她的世界的说明。
|
|
49
50
|
- **相册**:家会话可用 `keep_photo` 收藏本轮最新消息中的图片(含本轮已读取的微信图片和引用图),`list_photos` 分页查看说明,`forget_photo` 移除收藏。控制台顶部「相册」页查看照片,点开才加载图片;照片不会自动加入之后每轮上下文。旧相册首次打开时导入,原文件保留。
|
|
50
|
-
-
|
|
51
|
+
- **应用并压缩家会话**:等家空闲后压缩聊天历史。人设、世界提示词和「我是谁」的改动会在下一轮对话生效。详见[注意事项](NOTES.md#提示词保存后何时生效)。
|
|
51
52
|
- **作息**:概览里的「作息」卡片设每日回顾和早上醒来的时间,记在 `world.json`;留空恢复默认(回顾 23:00,早上用配置里的 `fallbackWakeTime`)。保存后,已排好的回顾和早上闹钟立刻改到新时间,她自己定的闹钟不动;世界停着时改的,下次启动时跟上。回顾定在中午以前,回顾的是前一天。
|
|
52
53
|
- **工作区权限**:选择世界工作区新建会话的默认权限,选项沿用宿主提供的权限预设,默认完全权限。保存后对新会话生效;已有会话及其手动权限不会被重新覆盖。
|
|
53
54
|
- **概览与记录**:她此刻在做什么、下个闹钟、近期记忆有多少轮、今天花了多少;还有活动记录、日记和压缩记录。
|
|
@@ -63,7 +64,7 @@ DSH 设置里的「世界控制台」:
|
|
|
63
64
|
容易踩的地方都集中写在 [注意事项](NOTES.md),按主题分类。第一次装或升级之前,建议先看 [默认就会发生的事](NOTES.md#默认就会发生的事)。
|
|
64
65
|
|
|
65
66
|
- [安装与升级](NOTES.md#安装与升级):默认换用只留对话的压缩。
|
|
66
|
-
- [人设与提示词](NOTES.md#人设与提示词)
|
|
67
|
+
- [人设与提示词](NOTES.md#人设与提示词):提示词何时更新,以及控制台人设和 DSH 自带系统提示词如何共存。
|
|
67
68
|
- [压缩与记忆](NOTES.md#压缩与记忆):什么时候自动压缩、每日回顾后自动压缩。
|
|
68
69
|
- [世界范围与会话](NOTES.md#世界范围与会话):对世界工作区以外的影响,以及“会话已离开世界工作区”怎么排查。
|
|
69
70
|
- [微信](NOTES.md#微信):支持的版本、账号风险、图片和表情包、@、退出重开。
|
|
@@ -125,6 +126,8 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
|
|
|
125
126
|
|
|
126
127
|
## 设置
|
|
127
128
|
|
|
129
|
+
同一个 DSH profile 可以加载多个世界。每个世界用不同的 `worldId`,在「世界控制台」选择要管理的世界。它们可以共用预设,使用各自的房间工作区、家会话和记忆。接入 QQ 或微信时,每个世界配置自己的通道。
|
|
130
|
+
|
|
128
131
|
大多数东西在世界控制台里改。其余的写在 profile 的 `cordis.patch.yml` 里,按 id 覆盖插件那一行,只写想改的项:
|
|
129
132
|
|
|
130
133
|
```yaml
|
|
@@ -133,7 +136,7 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
|
|
|
133
136
|
config:
|
|
134
137
|
companionName: 小鱼 # 她的名字(控制台人设里写了名字时以人设为准),默认 TA
|
|
135
138
|
partnerName: 伙伴 # 她对你的称呼,默认 伙伴
|
|
136
|
-
worldId: default #
|
|
139
|
+
worldId: default # 当前 profile 使用的世界目录名
|
|
137
140
|
agentPreset: standard # 她所在的预设
|
|
138
141
|
timeZone: Asia/Seoul # 默认系统时区
|
|
139
142
|
life: true # 生活线,默认开启
|
|
@@ -162,9 +165,21 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
|
|
|
162
165
|
mutedUntil: '' # 静默到这个时间(ISO):只收不回,到点自己醒
|
|
163
166
|
bindHomeSession: owner # owner:主人私聊用家会话、群各自独立;all:都用;none:各建一个
|
|
164
167
|
snowlumaHome: '' # SnowLuma 安装目录:控制台那扇门、看门狗和「拉起 SnowLuma」都靠它
|
|
165
|
-
supervise: true #
|
|
168
|
+
supervise: true # 看门狗:端口不通且没有实例时才拉起 SnowLuma
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
添加第二个世界时,用另一条插入配置:
|
|
172
|
+
|
|
173
|
+
```yaml
|
|
174
|
+
- insert:
|
|
175
|
+
- id: dsh-world-tata
|
|
176
|
+
name: dsh-world
|
|
177
|
+
config:
|
|
178
|
+
worldId: tata
|
|
166
179
|
```
|
|
167
180
|
|
|
181
|
+
控制台和接入地址以 `/dsh-world/worlds/<worldId>/` 开头。外部桥接调用方从 `bridge.json` 读取路径,微信适配器与插件一起升级。
|
|
182
|
+
|
|
168
183
|
**压缩的配置**写在压缩那一行的 `config` 里(profile 的 `cordis.patch.yml` 中 `name: 'dsh-world/compaction'` 那一条),不是上面 `dsh-world` 这一行:
|
|
169
184
|
|
|
170
185
|
```yaml
|
|
@@ -184,7 +199,7 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
|
|
|
184
199
|
|
|
185
200
|
**长期记忆的查找**(`memory_find`、`memory_read`,控制台「档案」页同源):
|
|
186
201
|
|
|
187
|
-
-
|
|
202
|
+
- 聊天在 `archive.sqlite` 的原表里直接按字面扫描,日记在查询时直接读文件。自述放进她的系统提示词,最多读前 5000 字。
|
|
188
203
|
- `memory_find` 参数:`query`(原文里的一小段字面文字,区分大小写,不是 SQL 或搜索语法;不填就按时间翻页)、`kinds`(`conversation`、`diary`)、`from`/`to`(带时区的 ISO 时间,左闭右开,日期请换成当天零点)、`sourceId`、`turnId`(取同一轮)、`order`、`limit`(工具里默认 8,最多 100)、`cursor`。工具返回 `items`(`ref`、`time`、`kind`、`who`、`text`,摘录约 200 字)和 `nextCursor`;有来源没能读到时才带 `coverage`(`state`:`partial`,`failures`)。控制台的同源接口返回更完整的字段。`timeBasis`:聊天是发言时间,日记是日记日期,其他文件是最后改动的时间。
|
|
189
204
|
- `memory_read` 参数:`ref`、`offset`(按字,默认 0)、`limit`(工具里默认 2000,最多 16000)。返回原文的一段,不是摘要,按字符分页,不会切坏一个字。聊天被修订后,旧 `ref` 报 `sourceChanged`;程序不保留旧正文。
|
|
190
205
|
- `ref` 由程序生成,别手写。能解析只说明找得到出处,不说明出处支持结论。
|
|
@@ -201,7 +216,7 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
|
|
|
201
216
|
| 位置 | 是什么 |
|
|
202
217
|
|---|---|
|
|
203
218
|
| `conversations/` | 按天归档的聊天原文(给人看的导出,正本在 `archive.sqlite`) |
|
|
204
|
-
| `room/` | 她的房间;`room/我是谁.md`
|
|
219
|
+
| `room/` | 她的房间;`room/我是谁.md` 是她的自述,`room/mood.md` 是她的心情值 |
|
|
205
220
|
| `diary/` | 她的日记(可用 `diaryDir` 换位置) |
|
|
206
221
|
| `persona.md`、`world-prompt.md`、`alarm.md` | 你写给她的人设、世界提示词和闹钟措辞 |
|
|
207
222
|
| `world.json` | 世界是否在运行、每天额度、近期记忆轮数和选定归档范围 |
|
|
@@ -218,7 +233,7 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
|
|
|
218
233
|
|
|
219
234
|
给桌宠等本地程序用。
|
|
220
235
|
|
|
221
|
-
**把话送进她的家**(`bridge: true`):插件启动时写出 `<世界目录>/bridge.json`,内容是 `{ origin, token, name, ... }`。向 `POST {origin}
|
|
236
|
+
**把话送进她的家**(`bridge: true`):插件启动时写出 `<世界目录>/bridge.json`,内容是 `{ origin, sayPath, compactPath, token, name, ... }`。向 `POST {origin}{sayPath}` 发 `{ "text": "..." }`,请求头带 `x-dsh-world-token: <token>`,会立即返回 `202`。这句话会作为你本人说的话进入她的家和记忆。
|
|
222
237
|
|
|
223
238
|
**接收她的话**(`outlets`):每个目标写一个 `name`,地址用 `url`(其中 `{origin}` 会被替换),或者用 `urlFile` + `path`(端口会变的程序用这个);再用 `kinds` 选择要接收哪些:`reply` 是桥上那句话的回复,`busy` 表示她正忙,`reach` 是她主动找你。插件会向目标 `POST`:
|
|
224
239
|
|
package/client/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* dsh-world — 浏览器半侧:设置里的「世界控制台」。
|
|
3
|
-
* 模块 id 必须等于 bundle 行名 dsh-world
|
|
3
|
+
* 模块 id 必须等于 bundle 行名 dsh-world;数据来自当前世界的路由。
|
|
4
4
|
* 读取是 GET;会改变东西的(开始、停止、人设、世界提示词、额度、记忆轮数)是带 x-dsh-world 头的 JSON POST。
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
;(function () {
|
|
7
|
+
var worldsPath = '/dsh-world/worlds'
|
|
8
|
+
|
|
9
|
+
function worldConsole(react, worldId) {
|
|
10
|
+
var prefix = worldsPath + '/' + encodeURIComponent(worldId)
|
|
10
11
|
var h = react.createElement
|
|
11
12
|
var useState = react.useState
|
|
12
13
|
var useEffect = react.useEffect
|
|
@@ -24,11 +25,11 @@ window.__ModuleLoader__.load({
|
|
|
24
25
|
function postTo(base, path, body) {
|
|
25
26
|
return fetch(base + path, { method: 'POST', cache: 'no-store', headers: { 'content-type': 'application/json', 'x-dsh-world': '1' }, body: JSON.stringify(body || {}) }).then(settle)
|
|
26
27
|
}
|
|
27
|
-
function api(path) { return getFrom('/
|
|
28
|
-
function post(path, body) { return postTo('/
|
|
29
|
-
/** QQ
|
|
30
|
-
function qqGet(path) { return getFrom('/
|
|
31
|
-
function qqPost(path, body) { return postTo('/
|
|
28
|
+
function api(path) { return getFrom(prefix + '/console/', path) }
|
|
29
|
+
function post(path, body) { return postTo(prefix + '/console/', path, body) }
|
|
30
|
+
/** QQ 那几扇门在自己的前缀下(…/qq/*),不和 console 混在一起。 */
|
|
31
|
+
function qqGet(path) { return getFrom(prefix + '/qq/', path) }
|
|
32
|
+
function qqPost(path, body) { return postTo(prefix + '/qq/', path, body) }
|
|
32
33
|
/** 保存没成时的那句话。 */
|
|
33
34
|
function failedTo(setMsg) { return function (e) { setMsg('保存失败:' + (e.message || e)) } }
|
|
34
35
|
/** 设置卡下面那行状态:没成(失败、请填…)标红,其余灰色。 */
|
|
@@ -206,7 +207,7 @@ window.__ModuleLoader__.load({
|
|
|
206
207
|
return h('div', { className: 'dw-setting', key: photo.id },
|
|
207
208
|
h('span', { style: { flex: '1 1 180px', overflowWrap: 'anywhere' } }, photo.description || '未写说明', ' · ', photo.width + '×' + photo.height, ' · ', local(photo.savedAt, props.zone), photo.tags.length ? ' · ' + photo.tags.join('、') : ''),
|
|
208
209
|
h('button', { className: 'dw-btn', onClick: function () { setOpen(open === photo.id ? null : photo.id) } }, open === photo.id ? '收起照片' : '查看照片'),
|
|
209
|
-
open === photo.id ? h('img', { src: '/
|
|
210
|
+
open === photo.id ? h('img', { src: prefix + '/console/photo?id=' + encodeURIComponent(photo.id), alt: photo.description || '收藏的照片', style: { display: 'block', width: '100%', maxHeight: 480, objectFit: 'contain' }, onError: function () { setError('照片读取失败,请刷新后重试。') } }) : null)
|
|
210
211
|
}) : h('div', { className: 'dw-muted' }, '她还没有收藏照片。'),
|
|
211
212
|
h('div', { className: 'dw-setting' },
|
|
212
213
|
h('button', { className: 'dw-btn', disabled: offset === 0, onClick: function () { setOffset(Math.max(0, offset - 12)); setOpen(null) } }, '上一页'),
|
|
@@ -227,7 +228,7 @@ window.__ModuleLoader__.load({
|
|
|
227
228
|
function set(key, value) { var next = Object.assign({}, persona); next[key] = value; setPersona(next); setMsg('') }
|
|
228
229
|
function save() {
|
|
229
230
|
setBusy(true)
|
|
230
|
-
post('persona', persona).then(function () { setSaved(persona); setMsg('
|
|
231
|
+
post('persona', persona).then(function () { setSaved(persona); setMsg('已保存。下一轮对话生效。'); if (props.onSaved) props.onSaved() },
|
|
231
232
|
failedTo(setMsg)).then(function () { setBusy(false) })
|
|
232
233
|
}
|
|
233
234
|
var preview = renderPersona(persona)
|
|
@@ -264,7 +265,7 @@ window.__ModuleLoader__.load({
|
|
|
264
265
|
h('div', { className: 'dw-muted' }, '你自己的这份没有用到:' + list(prompt.memory.missing).join('、') + '。工具照样可用,但她在提示里读不到它们的来历。想加的话,把下面这段贴进去;插件不会自动改你的模板。'),
|
|
265
266
|
h('pre', { className: 'dw-diary' }, prompt.memory.snippet)) : null,
|
|
266
267
|
h('div', { className: 'dw-bar' },
|
|
267
|
-
h('button', { className: 'dw-btn primary', disabled: text === prompt.text, onClick: function () { save(text, '
|
|
268
|
+
h('button', { className: 'dw-btn primary', disabled: text === prompt.text, onClick: function () { save(text, '已保存。下一轮对话生效。') } }, '保存'),
|
|
268
269
|
prompt.custom ? h('button', { className: 'dw-btn', onClick: function () { if (window.confirm('删掉你自己的这份,换回插件自带的模板?')) save('', '已换回插件自带的模板。') } }, '恢复默认') : null,
|
|
269
270
|
h('span', { className: msg.indexOf('失败') >= 0 ? 'dw-bad' : 'dw-muted' }, msg)))
|
|
270
271
|
}
|
|
@@ -279,7 +280,7 @@ window.__ModuleLoader__.load({
|
|
|
279
280
|
post('apply-home').then(function () { props.refresh() }, function (e) { setError(String(e.message || e)) }).then(function () { setSending(false) })
|
|
280
281
|
}
|
|
281
282
|
return h(Card, { title: '应用已保存配置' },
|
|
282
|
-
h('div', { className: 'dw-muted' }, '
|
|
283
|
+
h('div', { className: 'dw-muted' }, '保存的提示词会在下一轮对话生效。此操作等待家空闲后调用模型压缩聊天历史,并重建上下文缓存。'),
|
|
283
284
|
h('div', { className: 'dw-setting' },
|
|
284
285
|
h('button', { className: 'dw-btn', disabled: sending || waiting || compacting || !snap.running || !snap.life || !snap.homeApply, onClick: apply }, waiting ? '等待家空闲…' : compacting ? '正在压缩家会话…' : sending ? '提交中…' : '应用并压缩家会话'),
|
|
285
286
|
h('span', { role: 'status', 'aria-live': 'polite', className: error || state.status === 'failed' ? 'dw-bad' : 'dw-muted' }, error || (waiting ? '已排队,不打断当前对话。' : compacting ? '正在执行,请稍候。' : state.message) || (!snap.running || !snap.life ? '请先启动世界生活线。' : ''))))
|
|
@@ -384,12 +385,12 @@ window.__ModuleLoader__.load({
|
|
|
384
385
|
function toggle(on) {
|
|
385
386
|
setBusy(true)
|
|
386
387
|
post('compact-after-review', { on: on }).then(function () {
|
|
387
|
-
setMsg(on ? '
|
|
388
|
+
setMsg(on ? '已开启。每晚回顾后会自动压缩家会话。' : '已关闭。')
|
|
388
389
|
if (props.onSaved) props.onSaved()
|
|
389
390
|
}, failedTo(setMsg)).then(function () { setBusy(false) })
|
|
390
391
|
}
|
|
391
392
|
return h(Card, { title: '回顾后自动压缩' },
|
|
392
|
-
h('div', { className: 'dw-muted' }, '
|
|
393
|
+
h('div', { className: 'dw-muted' }, '每晚回顾结束、家空闲后,自动压缩一次家会话,随后重读近期聊天。“我是谁”的改动在下一轮对话生效。'),
|
|
393
394
|
h('label', { className: 'dw-setting' },
|
|
394
395
|
h('input', { type: 'checkbox', checked: props.on, disabled: busy, 'aria-label': '回顾后自动压缩', onChange: function (e) { toggle(e.target.checked) } }),
|
|
395
396
|
' ', props.on ? '已开启' : '已关闭'),
|
|
@@ -470,7 +471,7 @@ window.__ModuleLoader__.load({
|
|
|
470
471
|
var busyState = useState(false), busy = busyState[0], setBusy = busyState[1]
|
|
471
472
|
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
472
473
|
// 两个控制台都带 X-Frame-Options: DENY,塞不进 iframe,所以交给系统浏览器开。
|
|
473
|
-
//
|
|
474
|
+
// 地址和令牌由宿主半侧现给(…/qq/console),所以打开就是登录态。
|
|
474
475
|
function openDoor(kind) {
|
|
475
476
|
var label = 'SnowLuma'
|
|
476
477
|
setBusy(true); setMsg('')
|
|
@@ -532,6 +533,7 @@ window.__ModuleLoader__.load({
|
|
|
532
533
|
function startSnowluma() {
|
|
533
534
|
change({ startSnowluma: true }, function (state) {
|
|
534
535
|
var r = state && state.launch
|
|
536
|
+
if (r && r.alreadyRunning) return 'SnowLuma 已在运行或启动中,无需重复拉起'
|
|
535
537
|
if (!r || !r.started) return '没起来:' + ((r && r.error) || '原因不明')
|
|
536
538
|
return '已经让 SnowLuma 起来' + (r.how === 'spawn' ? '(直接起的,这条线只活到 DSH 退出)' : '') + (r.error ? ';' + r.error : '')
|
|
537
539
|
})
|
|
@@ -891,14 +893,59 @@ window.__ModuleLoader__.load({
|
|
|
891
893
|
return h(View, { snap: snap, error: error, tick: tick, refresh: function () { if (loadRef.current) loadRef.current() } })
|
|
892
894
|
}
|
|
893
895
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
896
|
+
return { Console: Console, test: { 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 } }
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
async function loadWorldIds() {
|
|
900
|
+
var ids = [], offset = 0
|
|
901
|
+
do {
|
|
902
|
+
var response = await fetch(worldsPath + '?limit=100&offset=' + offset, { cache: 'no-store' })
|
|
903
|
+
if (!response.ok) throw new Error('HTTP ' + response.status)
|
|
904
|
+
var page = await response.json()
|
|
905
|
+
ids.push.apply(ids, page.worldIds)
|
|
906
|
+
offset = page.nextOffset
|
|
907
|
+
} while (offset !== null)
|
|
908
|
+
return ids
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
window.__ModuleLoader__.load({
|
|
912
|
+
id: 'dsh-world',
|
|
913
|
+
factory: function (require) {
|
|
914
|
+
var react = require('react')
|
|
915
|
+
var h = react.createElement
|
|
916
|
+
function SelectedWorld(props) {
|
|
917
|
+
var components = react.useState(function () { return worldConsole(react, props.worldId) })[0]
|
|
918
|
+
return h(components.Console)
|
|
919
|
+
}
|
|
920
|
+
function WorldSettings() {
|
|
921
|
+
var idsState = react.useState(null), ids = idsState[0], setIds = idsState[1]
|
|
922
|
+
var selectedState = react.useState(''), selected = selectedState[0], select = selectedState[1]
|
|
923
|
+
var errorState = react.useState(''), error = errorState[0], setError = errorState[1]
|
|
924
|
+
react.useEffect(function () {
|
|
925
|
+
var alive = true
|
|
926
|
+
loadWorldIds().then(function (items) {
|
|
927
|
+
if (alive) { setIds(items); select(items[0] || '') }
|
|
928
|
+
}, function (e) { if (alive) setError(String(e.message || e)) })
|
|
929
|
+
return function () { alive = false }
|
|
930
|
+
}, [])
|
|
931
|
+
if (error) return h('p', { role: 'alert' }, '读取世界列表失败:' + error)
|
|
932
|
+
if (!ids) return h('p', null, '读取中…')
|
|
933
|
+
if (!selected) return h('p', null, '没有已加载的世界')
|
|
934
|
+
return h('div', null,
|
|
935
|
+
ids.length > 1 ? h('label', null, '世界 ', h('select', { value: selected, onChange: function (event) { select(event.target.value) } },
|
|
936
|
+
ids.map(function (id) { return h('option', { key: id, value: id }, id) }))) : null,
|
|
937
|
+
h(SelectedWorld, { key: selected, worldId: selected }))
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
var exports = { inject: ['slots'] }
|
|
941
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
|
|
942
|
+
exports.apply = function (ctx) {
|
|
943
|
+
ctx.slots.inject('settings.section', function () {
|
|
944
|
+
return ctx.slots.register({ name: 'settings.section', id: 'world-console', order: 28, label: '世界控制台' }, function () { return h(WorldSettings) })
|
|
945
|
+
})
|
|
946
|
+
}
|
|
947
|
+
Object.defineProperty(exports, '__test', { value: function (worldId) { return worldConsole(react, worldId).test } })
|
|
948
|
+
return exports
|
|
900
949
|
}
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
},
|
|
904
|
-
})
|
|
950
|
+
})
|
|
951
|
+
})()
|
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
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
2
|
export type MemoryArchiveScope = 'home' | 'workspace';
|
|
3
3
|
export declare const validArchiveScope: (value: unknown) => value is MemoryArchiveScope;
|
|
4
|
+
/** Native resolution canonicalizes case on Windows, as the host's registry does. */
|
|
5
|
+
export declare const canonicalPath: (path: string) => string;
|
|
6
|
+
type WorkspaceMembership = (id: string, requireRegistry?: boolean) => boolean;
|
|
4
7
|
/**
|
|
5
8
|
* Whose conversations her archive keeps: her home, or every session of her room's workspace. The room is found by
|
|
6
9
|
* its path, as for her world's reach: a home moved in from an older workspace stays listed there too, and that
|
|
7
10
|
* workspace must not become hers. Workspace membership comes from the host, never a preset or a display name.
|
|
8
11
|
*/
|
|
9
|
-
export declare function createArchiveSelection(
|
|
12
|
+
export declare function createArchiveSelection(scope: MemoryArchiveScope, isHome: (id: string) => boolean, inWorkspace: WorkspaceMembership): (id: string) => boolean;
|
|
10
13
|
/**
|
|
11
14
|
* Whether a session is in her room's workspace. Found by the room's path only, so a home recorded elsewhere cannot
|
|
12
15
|
* pull another workspace in; nothing is while the host keeps no workspaces (or has not started them yet).
|
|
13
16
|
*/
|
|
14
|
-
export declare function createWorkspaceMembership(ctx: Context, roomDir: string
|
|
17
|
+
export declare function createWorkspaceMembership(ctx: Context, roomDir: string, rooms?: () => Iterable<string>): WorkspaceMembership;
|
|
18
|
+
export {};
|
package/lib/archiveSelection.js
CHANGED
|
@@ -2,26 +2,35 @@ import { existsSync, realpathSync } from 'node:fs';
|
|
|
2
2
|
export const validArchiveScope = (value) => value === 'home' || value === 'workspace';
|
|
3
3
|
const workspaces = (ctx) => ctx.get('workspaceRegistry')?.list();
|
|
4
4
|
/** Native resolution canonicalizes case on Windows, as the host's registry does. */
|
|
5
|
-
const
|
|
5
|
+
export const canonicalPath = (path) => existsSync(path) ? realpathSync.native(path) : path;
|
|
6
6
|
/**
|
|
7
7
|
* Whose conversations her archive keeps: her home, or every session of her room's workspace. The room is found by
|
|
8
8
|
* its path, as for her world's reach: a home moved in from an older workspace stays listed there too, and that
|
|
9
9
|
* workspace must not become hers. Workspace membership comes from the host, never a preset or a display name.
|
|
10
10
|
*/
|
|
11
|
-
export function createArchiveSelection(
|
|
12
|
-
return id =>
|
|
13
|
-
if (scope === 'home')
|
|
14
|
-
return isHome(id);
|
|
15
|
-
const all = workspaces(ctx);
|
|
16
|
-
if (!all)
|
|
17
|
-
throw new Error('工作区归档需要宿主工作区服务');
|
|
18
|
-
return all.find(byPath(roomDir))?.sessionIds.includes(id) ?? false;
|
|
19
|
-
};
|
|
11
|
+
export function createArchiveSelection(scope, isHome, inWorkspace) {
|
|
12
|
+
return id => (scope !== 'home' || isHome(id)) && inWorkspace(id, true);
|
|
20
13
|
}
|
|
21
14
|
/**
|
|
22
15
|
* Whether a session is in her room's workspace. Found by the room's path only, so a home recorded elsewhere cannot
|
|
23
16
|
* pull another workspace in; nothing is while the host keeps no workspaces (or has not started them yet).
|
|
24
17
|
*/
|
|
25
|
-
export function createWorkspaceMembership(ctx, roomDir) {
|
|
26
|
-
return id
|
|
18
|
+
export function createWorkspaceMembership(ctx, roomDir, rooms) {
|
|
19
|
+
return (id, requireRegistry = false) => {
|
|
20
|
+
const all = workspaces(ctx);
|
|
21
|
+
if (!all) {
|
|
22
|
+
if (requireRegistry)
|
|
23
|
+
throw new Error('工作区归档需要宿主工作区服务');
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const path = canonicalPath(roomDir);
|
|
27
|
+
if (!all.find(workspace => workspace.path === path)?.sessionIds.includes(id))
|
|
28
|
+
return false;
|
|
29
|
+
return !rooms || !Array.from(rooms()).some(other => {
|
|
30
|
+
if (other === roomDir)
|
|
31
|
+
return false;
|
|
32
|
+
const otherPath = canonicalPath(other);
|
|
33
|
+
return otherPath === path || all.some(workspace => workspace.path === otherPath && workspace.sessionIds.includes(id));
|
|
34
|
+
});
|
|
35
|
+
};
|
|
27
36
|
}
|
package/lib/compaction.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export declare function compactionThreshold(input: {
|
|
|
59
59
|
* tool result, tool schema and reasoning block from the compacted span, then
|
|
60
60
|
* replaces the whole conversation with one summary paragraph.
|
|
61
61
|
*/
|
|
62
|
+
/** Whether a session's compaction service is this one, which can summarize inside a running turn; DSH's stock one cannot. */
|
|
63
|
+
export declare const compactsWhole: (engine: unknown) => engine is Pick<ToolFreeCompaction, "compactWhole">;
|
|
62
64
|
export default class ToolFreeCompaction extends CompactionEngine {
|
|
63
65
|
static inject: string[];
|
|
64
66
|
static Config: z<Schemastery.ObjectS<NoInfer<{
|
|
@@ -135,6 +137,11 @@ export default class ToolFreeCompaction extends CompactionEngine {
|
|
|
135
137
|
private policyFor;
|
|
136
138
|
private registerAutomaticCompaction;
|
|
137
139
|
compactIfNeeded(agent: CompactionAgentContext, trigger: CompactionTrigger, signal: AbortSignal): Promise<CompactionResult | null>;
|
|
140
|
+
/**
|
|
141
|
+
* Summarizes the whole conversation inside the running turn, before its next request; null when there is nothing to
|
|
142
|
+
* summarize. Besides pressure and overflow, the world runtime calls it on a cold session's first step (#36).
|
|
143
|
+
*/
|
|
144
|
+
compactWhole(agent: CompactionAgentContext, signal: AbortSignal): Promise<CompactionResult | null>;
|
|
138
145
|
compactRegion(start: SessionSeq, end: SessionSeq, agent: CompactionAgentContext, signal?: AbortSignal): Promise<CompactionResult>;
|
|
139
146
|
compactNow(agent: ManualCompactAgentContext, signal: AbortSignal, sourceCommandId?: CommandId): Promise<CompactionResult | null>;
|
|
140
147
|
private dependencies;
|
package/lib/compaction.js
CHANGED
|
@@ -10,14 +10,14 @@ const summaryInstruction = [
|
|
|
10
10
|
'现在暂停对话,改为执行上下文压缩:把上面这段会话中双方的交流整理成一段精炼的中文摘要,供你之后接着对话使用。',
|
|
11
11
|
'保留用户的意图、情绪与关系进展、明确要求、重要事实、已作决定、未完成事项和最近进展;最后一条用户发言尽量按原意完整保留。以“以下是此前交流的摘要”开头的消息是更早的摘要,请与新内容合并为同一段。',
|
|
12
12
|
'以【我的时间】(较早的是【你的时间】)开头的消息是你自己定的闹钟和留给自己的话,不是用户说的话;把它们当作你自己的安排来记,不要算作用户发言。',
|
|
13
|
-
'
|
|
13
|
+
'开头写着“这是我们最近的聊天记录”(较早的写着“最近的聊天记忆”或“最近的相处记忆”)的记忆资料、系统提示里的世界提示词(含「我是谁」)、以【我的心情值】开头的心情快照和“Time sampled”开头的时间块会在压缩后重新提供,不要写进摘要。工具调用过程已从会话中删除,不要提及工具。',
|
|
14
14
|
'保留准确的姓名、日期、数字和标识,分清每件事是谁说的、谁做的。不要标题、列表或分段,不要开头语,不要补写原文没有的事实,不要调用任何工具,直接输出摘要正文。',
|
|
15
15
|
].join('\n');
|
|
16
16
|
// The model tends to echo the checkpoint lead it saw on earlier summaries; the frame adds it once.
|
|
17
17
|
const leadEcho = /^以下是此前交流的摘要[^::]{0,40}[::]\s*/;
|
|
18
18
|
const checkpointLead = '以下是此前交流的摘要,工具调用过程已省略;请把它当作已知背景,直接接着当前对话继续:';
|
|
19
19
|
// Re-injected after every successful compaction by the memory runtime; replayed only as cacheable prefix.
|
|
20
|
-
const injectedSources = new Set(['time-context', 'dsh-world-history']);
|
|
20
|
+
const injectedSources = new Set(['time-context', 'dsh-world-history', 'dsh-world-mood']);
|
|
21
21
|
/**
|
|
22
22
|
* The compacted span exactly as the conversation request sent it, minus every
|
|
23
23
|
* tool call and tool result, so the summary request shares the longest possible
|
|
@@ -83,6 +83,8 @@ class TargetConfigError extends Error {
|
|
|
83
83
|
* tool result, tool schema and reasoning block from the compacted span, then
|
|
84
84
|
* replaces the whole conversation with one summary paragraph.
|
|
85
85
|
*/
|
|
86
|
+
/** Whether a session's compaction service is this one, which can summarize inside a running turn; DSH's stock one cannot. */
|
|
87
|
+
export const compactsWhole = (engine) => typeof engine?.compactWhole === 'function';
|
|
86
88
|
export default class ToolFreeCompaction extends CompactionEngine {
|
|
87
89
|
static inject = ['llm', 'tokenMeter', 'sessions'];
|
|
88
90
|
static Config = z.object({
|
|
@@ -183,10 +185,8 @@ export default class ToolFreeCompaction extends CompactionEngine {
|
|
|
183
185
|
if (!target)
|
|
184
186
|
return null;
|
|
185
187
|
const meter = this.ctx.tokenMeter;
|
|
186
|
-
if (trigger === 'context-overflow')
|
|
187
|
-
|
|
188
|
-
return range && this.compactRegion(range.start, range.end, agent, signal);
|
|
189
|
-
}
|
|
188
|
+
if (trigger === 'context-overflow')
|
|
189
|
+
return this.compactWhole(agent, signal);
|
|
190
190
|
const policy = this.policyFor(target);
|
|
191
191
|
const info = await this.ctx.llm.resolveModelInfo(target.provider, target.model, signal);
|
|
192
192
|
assertNoActiveCompaction(agent.session, 'automatic pressure compaction');
|
|
@@ -209,15 +209,24 @@ export default class ToolFreeCompaction extends CompactionEngine {
|
|
|
209
209
|
}
|
|
210
210
|
if (meter.measure(agent.session).totalTokens < threshold)
|
|
211
211
|
return null;
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
212
|
+
const result = await this.compactWhole(agent, signal);
|
|
213
|
+
if (!result)
|
|
214
214
|
return null;
|
|
215
|
-
const result = await this.compactRegion(range.start, range.end, agent, signal);
|
|
216
215
|
const after = meter.measure(agent.session).totalTokens;
|
|
217
216
|
if (after >= threshold)
|
|
218
217
|
throw new Error(`compaction still above threshold after summarizing the whole conversation (${after} estimated tokens >= threshold ${threshold})`);
|
|
219
218
|
return result;
|
|
220
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Summarizes the whole conversation inside the running turn, before its next request; null when there is nothing to
|
|
222
|
+
* summarize. Besides pressure and overflow, the world runtime calls it on a cold session's first step (#36).
|
|
223
|
+
*/
|
|
224
|
+
async compactWhole(agent, signal) {
|
|
225
|
+
if (!routedTarget(agent.session))
|
|
226
|
+
return null;
|
|
227
|
+
const range = selectWholeRange(agent.session, this.ctx.tokenMeter.measure(agent.session));
|
|
228
|
+
return range && this.compactRegion(range.start, range.end, agent, signal);
|
|
229
|
+
}
|
|
221
230
|
compactRegion(start, end, agent, signal) {
|
|
222
231
|
return compactSurfaceRegion(this.dependencies(), agent, start, end, { owner: 'current-turn', stability: 'whole-surface' }, signal);
|
|
223
232
|
}
|