dsh-world 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # 更新日志
2
2
 
3
+ ## 0.6.6 — 2026-10-30
4
+
5
+ 本版调整压缩触发与默认值、让每日回顾后的压缩更稳,把微信和 QQ 改为默认关闭,并把注意事项整理进 `NOTES.md`。
6
+
7
+ - 压缩触发改为按窗口约 75%:去掉原来的 90% 比例和固定 65,536 的预留,窗口取模型声明的 `contextWindow`,模型没声明时用新增的 `defaultContextWindow`(默认 1M,顶层与 `modelPolicies` 均可设置),首次用到默认值时记一条日志。
8
+ - 每日回顾后自动压缩默认开启,控制台新增开关;只有关闭时才写入设置。
9
+ - 新增 `replaceCompaction`(默认开):插件在某个 profile 首次启动时换用只留对话的压缩,原版配置留 `.bak` 备份。
10
+ - 人设:装上插件后替换 DSH 自带的身份行,已有的人设不覆盖;控制台提示文字同步更新。
11
+ - 守卫拦截会话时写日志,写明原因、会话和仍在其上的记忆块位置与类型,不记录任何文本。
12
+ - 微信和 QQ 默认关闭;已经在用微信的世界(存在 `wechat-outbox.sqlite`)升级后保持开启,控制台开关会明确保存。
13
+ - 新增 `NOTES.md` 统一收纳全部注意事项,README 指向它,并说明已拓展微信与 QQ 模块、QQ 仍需外部 SnowLuma 及 `@snowluma/sdk`。
14
+ - 宿主已验证兼容清单加入 `0.2.1-rc.5`:宿主包类型检查零错误,测试全过,桌面应用包与 rc.3 对比,我们依赖的宿主包除版本号外无变化;版本范围不变。
15
+
3
16
  ## 0.6.5 — 2026-10-30
4
17
 
5
18
  本版修复记忆块刷新后埋在长历史中间、attach 与每步退役写出坏日志和微信发送前快照超时卡进人工核对三个问题,减少微信群上下文的 token 开销,新增按需看群图片和插件自带的表情库,并让每日回顾后自动压缩、装上插件默认换用只留对话的压缩。
package/INSTALL.md CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
  ## 已有 world:用编译包更新
27
27
 
28
- 已经装过 `dsh-world` 时,保留原 profile 和世界目录,不要另建 world。先下载编译好的 `.tgz`:浏览器直接打开 npm 上的安装包地址即可,例如 <https://registry.npmjs.org/dsh-world/-/dsh-world-0.6.5.tgz>,其他版本把地址里的两处版本号一起换掉;也可以从 [CI 运行记录](https://github.com/chenkezhen480/dsh-world/actions) 的 Artifacts 下载(需登录 GitHub,产物会过期)。更新成品无需 Git、npm 或 TypeScript 编译器;需要 Node ≥ 22.16、系统 `tar` 和 DSH 自带 pnpm。
28
+ 已经装过 `dsh-world` 时,保留原 profile 和世界目录,不要另建 world。先下载编译好的 `.tgz`:浏览器直接打开 npm 上的安装包地址即可,例如 <https://registry.npmjs.org/dsh-world/-/dsh-world-0.6.6.tgz>,其他版本把地址里的两处版本号一起换掉;也可以从 [CI 运行记录](https://github.com/chenkezhen480/dsh-world/actions) 的 Artifacts 下载(需登录 GitHub,产物会过期)。更新成品无需 Git、npm 或 TypeScript 编译器;需要 Node ≥ 22.16、系统 `tar` 和 DSH 自带 pnpm。
29
29
 
30
30
  1. 从应用菜单正常退出 DSH,等待微信适配器一并退出。脚本会拒绝在 DSH 或适配器仍运行时更新,不强制结束进程。
31
31
  2. 使用仓库的 `scripts/update-world.mjs`,或已安装包的 `node_modules/dsh-world/scripts/update-world.mjs`。老版本尚无此文件时,可从仓库单独下载这个脚本,无需克隆或安装源码依赖。
@@ -34,7 +34,7 @@
34
34
  ```powershell
35
35
  node .\scripts\update-world.mjs `
36
36
  --profile '<DSH_HOME>/profiles/desktop' `
37
- --package '<下载目录>/dsh-world-0.6.5.tgz' `
37
+ --package '<下载目录>/dsh-world-0.6.6.tgz' `
38
38
  --pnpm '<DSH 自带 pnpm 的入口文件>'
39
39
  ```
40
40
 
package/NOTES.md ADDED
@@ -0,0 +1,152 @@
1
+ # 注意事项
2
+
3
+ 容易踩的地方集中写在这里,按主题分类。功能介绍见 [README](README.md),安装步骤见 [INSTALL](INSTALL.md),每个版本改了什么见 [更新日志](CHANGELOG.md)。
4
+
5
+ - [默认就会发生的事](#默认就会发生的事)
6
+ - [安装与升级](#安装与升级)
7
+ - [人设与提示词](#人设与提示词)
8
+ - [压缩与记忆](#压缩与记忆)
9
+ - [世界范围与会话](#世界范围与会话)
10
+ - [微信](#微信)
11
+ - [QQ](#qq)
12
+
13
+ ## 默认就会发生的事
14
+
15
+ 装上、升级之后不用你做什么,下面这些就会发生:
16
+
17
+ - **首次启动时,profile 的压缩会被换成 dsh-world 自带的“只留对话”压缩**(先备份,重启 DSH 后生效)。整个 profile 的会话都会受影响。不想换,写 `replaceCompaction: false`。详情:[默认换用只留对话的压缩](#默认换用只留对话的压缩)。
18
+ - **自动压缩在上下文窗口的 75% 触发**,没声明窗口的模型按 1M 估算。详情:[自动压缩什么时候触发](#自动压缩什么时候触发)。
19
+ - **每晚 23:00 的回顾之后,家会话会自动压缩一次**,让她改写的“我是谁”生效;每晚多一次摘要调用,控制台可关。详情:[每日回顾后自动压缩](#每日回顾后自动压缩)。
20
+ - **在控制台写了人设,它会取代 DSH 自带的那句默认身份**;你已经在 DSH 里设好的系统人设原样保留。详情:[人设和 DSH 自带的系统提示词](#人设和-dsh-自带的系统提示词)。
21
+ - **微信和 QQ 默认都是关的**,要用先在配置里启用,再到控制台「概览 → 接入」拨开(已经在用微信的世界升级后保持开着)。微信群里被 @ 时默认带前 5 条消息作上下文,控制台微信页可调 1–20。详情:[微信的开关](#微信的开关)、[QQ 的开关](#qq-的开关)。
22
+
23
+ ## 安装与升级
24
+
25
+ ### 默认换用只留对话的压缩
26
+
27
+ 默认自动换上。装好 `dsh-world` 后第一次启动,插件会把你 profile 的 `cordis.patch.yml` 里原版压缩那一行换成 `dsh-world/compaction`,先在同目录留一份 `.dsh-world.<随机>.bak` 备份,重启 DSH 后生效,世界面板的健康状态里会提示这件事。只有找到唯一一条原版压缩配置时才会改;已经换过、写法对不上或有多条时什么都不动。每个世界只试这一次:之后你手动改回原版,它不会再替你换。不想换,在 `dsh-world` 的配置里写 `replaceCompaction: false`。手动启用或恢复也可以用下面的脚本:
28
+
29
+ ```powershell
30
+ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-compaction.ps1 -profilePath '<你的 DSH profile 目录>'
31
+ ```
32
+
33
+ 脚本做的是同一件事:把原版压缩条目换成 `dsh-world/compaction` 并留备份。它对整个 profile 生效,不限世界工作区,见 [对世界工作区以外的影响](#对世界工作区以外的影响)。
34
+
35
+ ### 微信首次接入与升级
36
+
37
+ 开启插件的微信开关本身不会启动 Windows 适配器;可手动启动,或在配置里写 `wechatAdapter` 让插件随微信模块启动和停止它(见适配器 README)。无论哪种,都需要配套适配器并完成账号及聊天目标注册后,微信工具才可使用。这套原生桥不依赖 `dsh-plugin-weixin` 或 iLink。升级插件和适配器后,两者均需重启,不能让旧适配器进程继续运行新版协议;保留原配置、游标和回执。
38
+
39
+ ## 人设与提示词
40
+
41
+ ### 修改人设和世界提示词后要手动应用
42
+
43
+ **修改人设、世界提示词后,需要手动热加载,才能让已有家会话及时用上新内容。** 先保存修改,再到「人设」或「世界提示词」页点击 **「应用并压缩家会话」**。仅保存或重新打开控制台,不会立即刷新家会话。
44
+
45
+ 任务会等家空闲后执行一次,不打断当前对话;完成后的下一轮使用已保存的人设、名字、世界提示词和「我是谁」。压缩会调用模型并重建上下文缓存,没有可压缩内容时只刷新配置。面板显示执行结果或失败原因,停止世界会取消任务。
46
+
47
+ 这个按钮只作用于家会话;其他已有会话在各自下一次成功压缩或重新加载时更新,新建会话直接读取已保存内容。
48
+
49
+ ### 人设和 DSH 自带的系统提示词
50
+
51
+ 在控制台「人设」页写了内容以后:
52
+
53
+ - 它取代 DSH 自带的那句默认身份(“You are an AI agent powered by DeepSeek Harness.”),作为单独一段放进系统提示词。
54
+ - 你在 DSH 里已经设好的系统人设(宿主设置里的人设前缀,或当前预设自带的人设)**不会被替换**,原样保留在最前面,控制台写的排在它后面。预设如果已经自己改写了那句默认身份,也按它写的保留;你在 DSH 里关掉了默认身份、自己写开头,同样不动。
55
+ - 控制台「人设」全部留空时,什么都不改,沿用 DSH 的默认身份和你已有的人设。
56
+ - DSH 其余的系统提示(计划、工具、文件引用等说明)不动。
57
+ - 如果同一份人设在 DSH 里和控制台里各写了一遍,两份都会进提示词,内容会重复;只想要一份,清掉其中一处。
58
+ - 范围是所有匹配该世界预设的普通会话,不限工作区;改动对已有会话在下次压缩或「应用并压缩家会话」后生效,新会话直接使用。
59
+
60
+ ## 压缩与记忆
61
+
62
+ ### 自动压缩什么时候触发
63
+
64
+ 适用于 dsh-world 自带的压缩,默认会换上。每一步发请求之前检查一次,会话用量超过上下文窗口的 **75%** 就先压缩。窗口是 1M 时约 786,432。比例可以在压缩那一行的 `config` 里用 `thresholdRatio` 调整。
65
+
66
+ - 只有当单次回复上限(`maxTokens`,由 DSH 给模型的请求带上,不是本插件设的)大到“提示加回复装不下”时,才会比 75% 更早触发;不再额外扣固定的余量。
67
+ - 窗口值取自模型适配器声明的 `contextWindow`。适配器没有声明的模型(自己加的通道常见),按 `defaultContextWindow`(默认 1,048,576,即 1M)估算,并在日志里警告一次。如果它真实的窗口更小,请在适配器模型上配置 `contextWindow`,或在 `modelPolicies` 里给这个模型写 `defaultContextWindow`。
68
+ - 估大了不会卡死:请求被模型以“超出上下文窗口”拒绝时,会整段压缩后自动重试一次,但每次会白挨一次被拒绝的请求。
69
+ - 如果你没有换用本插件的压缩(`replaceCompaction: false`),触发规则以 DSH 原版压缩为准,上面这些不适用。
70
+
71
+ ### 每日回顾后自动压缩
72
+
73
+ 默认开,可在控制台概览的「回顾后自动压缩」关掉。每晚 23:00 的回顾里她会改写「我是谁」,而系统提示只在压缩之后才重新读取,不压缩的话新版要等到下一次压缩才生效,可能隔好几天。所以回顾那一轮结束、家空闲后,插件会自动执行一次[「应用并压缩家会话」](#修改人设和世界提示词后要手动应用):新版「我是谁」随压缩一起生效,压缩后最近的聊天原文会作为记忆块重新放回她眼前,衔接是接得上的。压缩本来就要重建缓存,这样不会多破坏一次,但每晚会多一次摘要调用。只在回顾真的送到她那里之后才触发,闹钟和问候不会;只作用于家会话,人设和世界提示词的修改仍然需要手动应用。
74
+
75
+ ## 世界范围与会话
76
+
77
+ ### 对世界工作区以外的影响
78
+
79
+ 只有下面这两项会作用到世界工作区以外的会话:
80
+
81
+ 1. **人设**:控制台人设作为单独一段,取代 DSH 自带的默认身份句、排在宿主系统人设之后,所有匹配该世界预设的普通会话都会带上,不限工作区。
82
+ 2. **只留对话的压缩**(装上插件后首次启动默认换上,可在配置里写 `replaceCompaction: false` 关掉):它替换的是整个 profile 的压缩方式,其他工作区的会话压缩时也会去掉工具调用过程,只留一段对话摘要。写代码等依赖工具过程的会话,压缩后会丢掉这些细节。
83
+
84
+ 除此之外,记忆、世界提示词、世界线、工具、通道和归档都不会进入工作区以外的会话。
85
+
86
+ ### 看到“会话已离开世界工作区,请重新发送”
87
+
88
+ 这是插件在请求发出前的最后一道检查,会话不在世界工作区里、却还带着世界上下文时就拦住它,并顺手把残留的世界记忆块清掉,所以重新发送通常就能通过。每次拦截,DSH 日志里都有一条 `dsh-world: 阻止了会话 …` 的警告,写明原因(请求里还带着几条世界记忆块、世界提示还挂在会话上)、会话 ID 和预设,以及清理之后会话表面上还剩哪些记忆节点(位置和事件类型)。日志里不会出现任何消息文字。如果重新发送后仍然被拦,请把这条日志发给作者。
89
+
90
+ ## 微信
91
+
92
+ ### 微信的开关
93
+
94
+ 默认关。要用微信,先在配置里写 `wechat: true`,再到控制台「概览 → 接入」把微信拨开:开着就立即注册 `wechat_chats`、`wechat_history`、`wechat_image`、`wechat_send`、`wechat_delivery` 和 `sticker_*` 这些工具,并拉起适配器(配了 `wechatAdapter` 时);关掉就撤掉工具、停止适配器。没在配置里启用的模块不能从控制台打开。已经在用微信的世界(它的微信模块以前跑过)升级后保持开着,不会被悄悄关掉。
95
+
96
+ ### 微信支持版本
97
+
98
+ 目前仅适配 **Windows x64 微信 `4.1.15.13`、`4.1.15.56` 的指定构建**。适配器会核对 `Weixin.dll` 的文件大小和 SHA256;其他构建(包括版本号相同但文件指纹不同的构建)会在加载原生桥前被拒绝。macOS、Linux 客户端暂不支持。升级微信前请确认新构建已有适配;各版本的实测范围见 [微信模块](src/ecosystem/wechat/windows/README.md)。
99
+
100
+ ### 微信风控与账号风险
101
+
102
+ 当前桥不是微信官方 API,接收端解密读取本地消息数据库,发送端向微信进程加载 DLL 并调用内部函数,存在账号功能受限或封禁风险。微信安全中心 [2026 年 1 月 29 日公告(媒体转载)](https://www.thepaper.cn/newsDetail_forward_32493057) 将违规获取聊天记录、联系人数据,以及通过模拟按键、自动化脚本操控微信等列为治理内容。仅用于家庭群、低频聊天,或改用 Computer Use,都不能保证账号安全;公开资料没有可靠的封号概率或安全发送阈值。
103
+
104
+ ### 微信退出重开
105
+
106
+ 保持适配器运行,退出微信后它会暂停收发并等待;她原来的账号重新登录后,会自动重新绑定进程并沿用消息游标恢复监听,无需重启 DSH。若退出发生在消息处理或发送途中,且结果尚未确认,则停止并保留待核对记录,不会自动重复回复;按微信模块中的 `Acknowledge` 流程核对后恢复。
107
+
108
+ ### 微信图片接收
109
+
110
+ 私聊普通图片会先缓冲最多 3 秒,合并紧随的同一发言人的一条说明文字后进入模型,每轮最多两张图,更多图片留到后续轮次。开始处理后才到达的文字排到下一轮,继续使用同一会话已有的图片上下文。群聊里被真实 @ 时最近两张图会直接给她;平时翻群消息时图片先显示为未读取,她想看哪张就用 `wechat_image` 取(一次一张,图片还没下载到这台电脑时会明确报错)。图片及附件引用只进入对应会话总日志,不自动写入共享记忆块;合并的真实文字按原归档范围保存,是否另行留存图片中的信息由她自己判断。缓存不可用时明确标记未读取,不操作界面下载。
111
+
112
+ ### 微信表情包接收
113
+
114
+ 私聊里你发来的原生表情包会按消息中的地址从腾讯 CDN 下载,md5 与消息一致才接受,并取第一帧作为图片交给她;这是适配器主动联网的功能,可在适配器配置里写 `"fetchStickers": false` 关闭,读取失败时她会看到明确的“未读取”原因。动图只取第一帧;群聊里的表情包目前不会交给她,群里发表情包后再 @ 她,她只能收到触发文字和其他已支持的上下文。原生表情包也不会进入插件的记忆归档。
115
+
116
+ ### 微信表情库
117
+
118
+ 她的表情库由本插件自己维护,放在世界目录的 `stickers/` 下,每张只有名称和标签。`sticker_search` 按关键词找(一次最多几张,不倾倒整个库,也不回传图片),`sticker_save` 把聊天里别人发来的表情包收进来(保留原始动图,同一张不重复收),`sticker_edit`、`sticker_remove` 管理;发送用 `wechat_send`。不再需要 DeepSeek-meme 插件和 `stickerDir` 配置,旧库用 `scripts/import-stickers.mjs` 导入一次即可,说明见 [微信模块](src/ecosystem/wechat/windows/README.md#表情库)。QQ 仍用自己的收藏表情。
119
+
120
+ ### 微信里的 @
121
+
122
+ 她发出的文字里写 `@昵称` 只是普通文字,不会真的 @ 到人,被提到的人也收不到提醒。原生发送没有 @ 列表,靠操作窗口输入 @ 又会抢占焦点、与“后台发送、不操作窗口”的设计冲突,所以不做;需要点名时她会在文字里写清对方的称呼。
123
+
124
+ ### 视频号与朋友圈(预留)
125
+
126
+ 目前聊天中分享的视频号卡片会被跳过,不进入她的会话或共享记忆;收到卡片后没有回复,不代表微信监听掉线。视频号需要另行接入卡片解析和视频内容读取。朋友圈的浏览、发布也需要独立的操作能力,现有私聊/群聊发送接口不能发布朋友圈。这些能力暂只记录为微信模块的后续扩展,尚未实现。
127
+
128
+ ## QQ
129
+
130
+ ### QQ 模块仍需要外部的 SnowLuma
131
+
132
+ QQ 模块是插件自己连 OneBot,但登录 QQ、对外提供 OneBot 服务的是外部的 **SnowLuma**,需要你另行安装,插件不会替你安装它(看门狗只会把已装好的 SnowLuma 拉起来)。SnowLuma 按它自己的 EULA 不许被自动化脚本部署,装法与参数怎么拿见 [INSTALL.md](INSTALL.md)。除了 SnowLuma 本体,还需要它的 SDK,见下一条。没装 SnowLuma 时 QQ 通道连不上,不影响微信和其他功能。
133
+
134
+ ### 额外依赖 SnowLuma SDK(`@snowluma/sdk`)
135
+
136
+ 首次手动开启 QQ 时,缺少 SDK 就调用宿主包管理器装到当前 DSH profile,禁用安装脚本,不修补 SDK 文件;安装完成后提示重启 DSH,再按保存的开关启用 QQ。安装失败会显示原因,运行环境要求以 SDK 自身说明为准,不自动升级 Node。不使用 QQ 时无需 SDK,不影响其他功能;也可自行安装兼容版本,见 [安装说明](INSTALL.md#第一步把-dsh-world-装进-profile)。
137
+
138
+ ### QQ 的开关
139
+
140
+ 默认关。要用 QQ,先在配置里写 `qqNative.enabled: true`,再到控制台「概览 → 接入」把 QQ 拨开:开着才加载通道,关掉就断开连接。没在配置里启用的模块不能从控制台打开。首次手动开启时缺少 SDK 会按需安装,见上一条。
141
+
142
+ ### QQ 的记忆
143
+
144
+ QQ 消息由插件自己那条原生通道送进家里,插件没有为它做微信那样的渠道身份。按 `bindHomeSession`(默认 `owner`),主人的私聊用她的家会话,因此按普通家会话归档;每个群各挂一个独立会话(标题形如 `QQ · <群名>`),挂在她的房间工作区下、用同一个 `agentPreset`——所以在默认的 `archiveScope: workspace` 下,**群里的对话和微信群一样会进归档、进记忆块**,归档里只有会话、没有渠道标记。写 `none` 时私聊也另建一个这样的独立会话。群里的消息默认只有被叫到才接话,其余只进本轮上下文、不开口也不花额度。
145
+
146
+ ### 群里默认只接被叫到的
147
+
148
+ 对应 `groupTrigger: mention`:被 @、引用她刚说过的话、或文本命中 `groupKeywords` 才算叫她,其余消息只进本轮上下文,不开口也不花额度;写 `all` 就是每句都接,代价是群里每一条都会让她跑完一轮。`@全体` 是群公告,不算叫她。`bindHomeSession` 决定谁和她的家会话共用一个入口,默认 `owner`。
149
+
150
+ ### 看门狗
151
+
152
+ 对应 `supervise`,默认开。QQ 开着时每 30 秒探一次 `wsUrl` 的端口,不通就按 `snowlumaHome` 把 SnowLuma 拉起来(本机有 `SnowLuma-watchdog` 计划任务时借它跑,能活过 DSH 重启;没有就直接起进程,只活到 DSH 退出)。拉不起来的原因写在卡上。不想让插件动手就设成 `false`,卡上的「拉起 SnowLuma」按钮照旧能用。
package/README.md CHANGED
@@ -6,6 +6,11 @@
6
6
 
7
7
  插件只用 DSH 原本开放的扩展接口,不改宿主的一行代码。
8
8
 
9
+ **已拓展到微信和 QQ**:除了 DSH 里的窗口,她也能在 **微信** 和 **QQ** 里收发消息,私聊和群聊都可以,和家共用同一份记忆、同一个她。
10
+
11
+ - **微信模块**自带 Windows 适配器和原生发送,不依赖 `dsh-plugin-weixin` 等其他微信插件;只适配指定的微信构建,需要按适配器说明准备 Python 环境,有账号风险,见 [注意事项·微信](NOTES.md#微信)。
12
+ - **QQ 模块仍然需要外部的 SnowLuma**:插件自己连 OneBot,但登录 QQ、提供 OneBot 服务的是需要你另行安装的 SnowLuma,另外还要它的 SDK `@snowluma/sdk`(首次手动开启 QQ 时按需安装)。微信和 QQ 默认都是关的,要用先在控制台拨开;不用 QQ 时不需要装这些。见 [注意事项·QQ](NOTES.md#qq)。
13
+
9
14
  当前版本 **0.6.5**。完整变更和升级说明见 [更新日志](CHANGELOG.md#065--2026-10-30)。
10
15
 
11
16
  ## 她能做到什么
@@ -38,36 +43,33 @@
38
43
  DSH 设置里的「世界控制台」:
39
44
 
40
45
  - **开始 / 停止**:按下开始,她才住进来;按下停止,记忆、人设和生活线一起安静下来,家还在,等你回来。
41
- - **人设**:分层写她是谁:名字、她是谁、性格、说话方式、愿景、补充,旁边实时预览她读到的样子。全部留空时沿用宿主或当前预设的人设,控制台不自动回填。
46
+ - **人设**:分层写她是谁:名字、她是谁、性格、说话方式、愿景、补充,旁边实时预览她读到的样子。写了以后,它取代 DSH 自带的那句默认身份(“You are an AI agent powered by DeepSeek Harness.”);你已经在 DSH 里设过的系统人设(宿主设置里的人设,或当前预设自带的人设)不会被替换,原样保留,这里写的排在它后面;预设如果已经自己改写了那句默认身份,也按它写的保留,不会被盖掉。全部留空时什么都不改,沿用 DSH 的默认身份和你已有的人设,控制台不自动回填。DSH 里其余的系统提示(计划、工具和文件引用等说明)不动。
42
47
  - **世界提示词**:你想对她说的话,以及她的世界的说明。
43
48
  - **相册**:家会话可用 `keep_photo` 收藏本轮最新消息中的图片(含本轮已读取的微信图片和引用图),`list_photos` 分页查看说明,`forget_photo` 移除收藏。控制台顶部「相册」页查看照片,点开才加载图片;照片不会自动加入之后每轮上下文。旧相册首次打开时导入,原文件保留。
44
- - **应用并压缩家会话**:人设和世界提示词页面里的热加载入口,操作方法见下方[注意事项](#注意事项)。
49
+ - **应用并压缩家会话**:人设和世界提示词页面里的热加载入口,操作方法见[注意事项](NOTES.md#修改人设和世界提示词后要手动应用)。
45
50
  - **工作区权限**:选择世界工作区新建会话的默认权限,选项沿用宿主提供的权限预设,默认完全权限。保存后对新会话生效;已有会话及其手动权限不会被重新覆盖。
46
51
  - **概览与记录**:她此刻在做什么、下个闹钟、近期记忆有多少轮、今天花了多少;还有活动记录、日记和压缩记录。
47
- - **接入开关**:配置里启用了微信(`wechat: true`)或 QQ(`qqNative.enabled: true`)后,概览里有一张「接入」卡片,状态记在 `world.json`。微信开着才注册工具并拉起适配器(配了 `wechatAdapter` 时),关掉就撤掉;QQ 开着才加载通道,关掉就断开连接。微信默认开,QQ 默认关。首次手动开启 QQ 时,缺少 SnowLuma SDK 就按需安装,完成后提示重启 DSH;SDK 已就绪时直接切换,无需重启。
52
+ - **接入开关**:配置里启用了微信(`wechat: true`)或 QQ(`qqNative.enabled: true`)后,概览里有一张「接入」卡片,状态记在 `world.json`。微信开着才注册工具并拉起适配器(配了 `wechatAdapter` 时),关掉就撤掉;QQ 开着才加载通道,关掉就断开连接。微信和 QQ 都默认关,已经在用微信的世界升级后保持开着。首次手动开启 QQ 时,缺少 SnowLuma SDK 就按需安装,完成后提示重启 DSH;SDK 已就绪时直接切换,无需重启。
48
53
  - **微信 / QQ 页面**:顶部各有一个独立入口,详细状态和设置不再挤在概览里。微信页查看连接、待发送与待核对数量,重启适配器并调整读取条数和图片缓冲;QQ 页管理 OneBot、白名单、静默和 SnowLuma。通道关闭或世界停止时,页面提示未开启。
49
54
  - **归档范围**:默认 `workspace`,归档家所在工作区的普通会话,包含独立微信群会话;`home` 仅当前家会话。保存范围后提示重启,重启前沿用原范围。启动时分页回扫所选范围内的会话日志,按消息实际时间重选最近配置轮数,下次请求前替换旧记忆块;没有时间过期。旧归档保留,范围外记录不再注入。旧配置 `world` 迁为 `workspace`。
50
55
  - **注入范围**:世界记忆、世界提示词、世界线工具和微信/QQ 通道仅进入世界工作区内匹配预设的普通会话,其他工作区即使用相同预设也不会收到。归档选为 `home` 时,同工作区的其他会话仍可读取家记忆。
51
56
 
52
- > **对世界工作区以外的影响(只有这两项)**:
53
- > 1. **人设**:控制台人设映射到系统提示词的人设槽位,所有匹配该世界预设的普通会话都会带上,不限工作区。
54
- > 2. **只留对话的压缩**(装上插件后首次启动默认换上,可在配置里写 `replaceCompaction: false` 关掉):它替换的是整个 profile 的压缩方式,其他工作区的会话压缩时也会去掉工具调用过程,只留一段对话摘要。写代码等依赖工具过程的会话,压缩后会丢掉这些细节。
55
- >
56
- > 除此之外,记忆、世界提示词、世界线、工具、通道和归档都不会进入工作区以外的会话。
57
+ > 对世界工作区以外的会话,只有两项有影响:控制台人设和只留对话的压缩。详情见 [注意事项](NOTES.md#对世界工作区以外的影响)。
57
58
 
58
59
  ### 注意事项
59
60
 
60
- **修改人设、世界提示词后,需要手动热加载,才能让已有家会话及时用上新内容。** 先保存修改,再到「人设」或「世界提示词」页点击 **「应用并压缩家会话」**。仅保存或重新打开控制台,不会立即刷新家会话。
61
-
62
- 任务会等家空闲后执行一次,不打断当前对话;完成后的下一轮使用已保存的人设、名字、世界提示词和「我是谁」。压缩会调用模型并重建上下文缓存,没有可压缩内容时只刷新配置。面板显示执行结果或失败原因,停止世界会取消任务。
63
-
64
- 这个按钮只作用于家会话;其他已有会话在各自下一次成功压缩或重新加载时更新,新建会话直接读取已保存内容。
61
+ 容易踩的地方都集中写在 [注意事项](NOTES.md),按主题分类。第一次装或升级之前,建议先看 [默认就会发生的事](NOTES.md#默认就会发生的事)。
65
62
 
66
- **每日回顾后自动压缩**(默认开,可在控制台概览的「回顾后自动压缩」关掉):每晚 23:00 的回顾里她会改写「我是谁」,而系统提示只在压缩之后才重新读取,不压缩的话新版要等到下一次压缩才生效,可能隔好几天。所以回顾那一轮结束、家空闲后,插件会自动执行一次上面的「应用并压缩家会话」:新版「我是谁」随压缩一起生效,压缩后最近的聊天原文会作为记忆块重新放回她眼前,衔接是接得上的。压缩本来就要重建缓存,这样不会多破坏一次,但每晚会多一次摘要调用。只在回顾真的送到她那里之后才触发,闹钟和问候不会;只作用于家会话,人设和世界提示词的修改仍然需要手动应用。
63
+ - [安装与升级](NOTES.md#安装与升级):默认换用只留对话的压缩。
64
+ - [人设与提示词](NOTES.md#人设与提示词):改了以后要手动应用;控制台人设和 DSH 自带系统提示词怎么共存。
65
+ - [压缩与记忆](NOTES.md#压缩与记忆):什么时候自动压缩、每日回顾后自动压缩。
66
+ - [世界范围与会话](NOTES.md#世界范围与会话):对世界工作区以外的影响,以及“会话已离开世界工作区”怎么排查。
67
+ - [微信](NOTES.md#微信):支持的版本、账号风险、图片和表情包、@、退出重开。
68
+ - [QQ](NOTES.md#qq):SnowLuma SDK、群里默认只接被叫到的、看门狗。
67
69
 
68
70
  ### 只留下你们之间的话的压缩
69
71
 
70
- 对话太长需要压缩时,dsh-world 自带的压缩方式会去掉工具调用的过程,把你们之间的交流整理成一段摘要。她记住的是你,不是那些命令。
72
+ 对话太长需要压缩时,dsh-world 自带的压缩方式会去掉工具调用的过程,把你们之间的交流整理成一段摘要。她记住的是你,不是那些命令。装上插件后它默认就会换上,见 [注意事项](NOTES.md#默认就会发生的事)。
71
73
 
72
74
  ### 桌宠和其他程序
73
75
 
@@ -77,28 +79,10 @@ dsh-world 开放了一个本地的「桥」:桌宠之类的程序可以把你
77
79
 
78
80
  **群聊动静**:适配器在线时,已配置群里未 @ 她的消息只更新未读数、最后发言人和时间,不唤醒模型,也不把正文加入上下文。她原有的闹钟响起时,会附上一行群聊概况,包括未读消息或安静了多久;是否去看、是否发言,由她自己决定。成功读取群的最新一页后清零未读,自己的发言不计入未读;计数保存在适配器状态中,重启保留。插件不会改写你的 `alarm.md`、`world-prompt.md` 或「我是谁」。
79
81
 
80
- > **微信支持版本**:目前仅适配 **Windows x64 微信 `4.1.15.13`、`4.1.15.56` 的指定构建**。适配器会核对 `Weixin.dll` 的文件大小和 SHA256;其他构建(包括版本号相同但文件指纹不同的构建)会在加载原生桥前被拒绝。macOS、Linux 客户端暂不支持。升级微信前请确认新构建已有适配;各版本的实测范围见 [微信模块](src/ecosystem/wechat/windows/README.md)。
81
-
82
- > **微信里的 @**:她发出的文字里写 `@昵称` 只是普通文字,不会真的 @ 到人,被提到的人也收不到提醒。原生发送没有 @ 列表,靠操作窗口输入 @ 又会抢占焦点、与“后台发送、不操作窗口”的设计冲突,所以不做;需要点名时她会在文字里写清对方的称呼。
83
-
84
- > **微信图片接收**:私聊普通图片会先缓冲最多 3 秒,合并紧随的同一发言人的一条说明文字后进入模型,每轮最多两张图,更多图片留到后续轮次。开始处理后才到达的文字排到下一轮,继续使用同一会话已有的图片上下文。群聊里被真实 @ 时最近两张图会直接给她;平时翻群消息时图片先显示为未读取,她想看哪张就用 `wechat_image` 取(一次一张,图片还没下载到这台电脑时会明确报错)。图片及附件引用只进入对应会话总日志,不自动写入共享记忆块;合并的真实文字按原归档范围保存,是否另行留存图片中的信息由她自己判断。缓存不可用时明确标记未读取,不操作界面下载。
85
-
86
- > **微信风控与账号风险**:当前桥不是微信官方 API,接收端解密读取本地消息数据库,发送端向微信进程加载 DLL 并调用内部函数,存在账号功能受限或封禁风险。微信安全中心 [2026 年 1 月 29 日公告(媒体转载)](https://www.thepaper.cn/newsDetail_forward_32493057) 将违规获取聊天记录、联系人数据,以及通过模拟按键、自动化脚本操控微信等列为治理内容。仅用于家庭群、低频聊天,或改用 Computer Use,都不能保证账号安全;公开资料没有可靠的封号概率或安全发送阈值。
87
-
88
- > **微信表情包接收**:私聊里你发来的原生表情包会按消息中的地址从腾讯 CDN 下载,md5 与消息一致才接受,并取第一帧作为图片交给她;这是适配器主动联网的功能,可在适配器配置里写 `"fetchStickers": false` 关闭,读取失败时她会看到明确的“未读取”原因。动图只取第一帧;群聊里的表情包目前不会交给她,群里发表情包后再 @ 她,她只能收到触发文字和其他已支持的上下文。原生表情包也不会进入插件的记忆归档。
89
-
90
- > **微信表情库**:她的表情库由本插件自己维护,放在世界目录的 `stickers/` 下,每张只有名称和标签。`sticker_search` 按关键词找(一次最多几张,不倾倒整个库,也不回传图片),`sticker_save` 把聊天里别人发来的表情包收进来(保留原始动图,同一张不重复收),`sticker_edit`、`sticker_remove` 管理;发送用 `wechat_send`。不再需要 DeepSeek-meme 插件和 `stickerDir` 配置,旧库用 `scripts/import-stickers.mjs` 导入一次即可,说明见 [微信模块](src/ecosystem/wechat/windows/README.md#表情库)。QQ 仍用自己的收藏表情。
91
-
92
- > **视频号与朋友圈(预留)**:目前聊天中分享的视频号卡片会被跳过,不进入她的会话或共享记忆;收到卡片后没有回复,不代表微信监听掉线。视频号需要另行接入卡片解析和视频内容读取。朋友圈的浏览、发布也需要独立的操作能力,现有私聊/群聊发送接口不能发布朋友圈。这些能力暂只记录为微信模块的后续扩展,尚未实现。
93
-
94
- > **微信退出重开**:保持适配器运行,退出微信后它会暂停收发并等待;她原来的账号重新登录后,会自动重新绑定进程并沿用消息游标恢复监听,无需重启 DSH。若退出发生在消息处理或发送途中,且结果尚未确认,则停止并保留待核对记录,不会自动重复回复;按微信模块中的 `Acknowledge` 流程核对后恢复。
95
-
96
- > **微信首次接入与升级**:开启插件的微信开关本身不会启动 Windows 适配器;可手动启动,或在配置里写 `wechatAdapter` 让插件随微信模块启动和停止它(见适配器 README)。无论哪种,都需要配套适配器并完成账号及聊天目标注册后,微信工具才可使用。这套原生桥不依赖 `dsh-plugin-weixin` 或 iLink。升级插件和适配器后,两者均需重启,不能让旧适配器进程继续运行新版协议;保留原配置、游标和回执。
82
+ 微信的支持版本、账号风险、图片与表情包、表情库、@、退出重开等注意事项,见 [注意事项·微信](NOTES.md#微信);首次接入与升级见 [注意事项·安装与升级](NOTES.md#微信首次接入与升级)。
97
83
 
98
84
  > **QQ 走插件自己那条原生通道**:插件直接连 SnowLuma 提供的 OneBot WebSocket,自己收、自己发(代码在 [`src/ecosystem/qq-native/`](src/ecosystem/qq-native/index.ts)),中间没有第二个进程,也不需要别的 QQ 实现。SnowLuma 负责登录 QQ 并对外提供 OneBot 的 HTTP/WS 服务;它按自己的 EULA 不许被自动化脚本部署,装法与参数怎么拿见 [INSTALL.md](INSTALL.md)。这条通道的配置都在 profile 的 `cordis.patch.yml` 里(见下文「设置」),控制台上改过的设置存在世界目录的 `qq-native.json`。
99
85
 
100
- > **QQ 的记忆与开关**:QQ 消息由这条通道送进家里,插件没有为它做微信那样的渠道身份。按 `bindHomeSession`(默认 `owner`),主人的私聊用她的家会话,因此按普通家会话归档;每个群各挂一个独立会话(标题形如 `QQ · <群名>`),挂在她的房间工作区下、用同一个 `agentPreset`——所以在默认的 `archiveScope: workspace` 下,**群里的对话和微信群一样会进归档、进记忆块**,归档里只有会话、没有渠道标记。写 `none` 时私聊也另建一个这样的独立会话。群里的消息默认只有被叫到才接话,其余只进本轮上下文、不开口也不花额度。控制台「接入」里的 QQ 开关决定这条通道连不连。微信开关则会立即注册或撤掉 `wechat_chats`、`wechat_history`、`wechat_image`、`wechat_send`、`wechat_delivery` 和 `sticker_*`,并拉起或停止适配器。微信默认开、QQ 默认关,没在配置里启用的模块不能从控制台打开。
101
-
102
86
  外部生态接入代码统一放在 [`src/ecosystem/`](src/ecosystem/README.md):`wechat/` 包含微信宿主模块、Windows 收发适配器和原生桥;`qq-native/` 是插件自己连 OneBot 的那条 QQ 通道(`qq/` 里是与它配套的控制台接口和 SnowLuma 控制台那扇门);`shared/` 保存通用身份协议、群会话路由与消息出口;`bridge/` 为桌宠等本地程序提供通用桥。后续平台在同一目录下独立扩展,核心记忆、人设和生活线保持独立。
103
87
 
104
88
  微信原生发送引擎单独适用非商业许可,详见该模块的许可说明。
@@ -107,18 +91,14 @@ dsh-world 开放了一个本地的「桥」:桌宠之类的程序可以把你
107
91
 
108
92
  QQ 走插件自己那条原生通道:直接连 SnowLuma 开出来的 OneBot WebSocket,收文本、发文本,中途没有别的进程。代码在 [`src/ecosystem/qq-native/`](src/ecosystem/qq-native/index.ts)。
109
93
 
110
- **额外依赖 SnowLuma SDK(`@snowluma/sdk`)**:首次手动开启 QQ 时,缺少 SDK 就调用宿主包管理器装到当前 DSH profile,禁用安装脚本,不修补 SDK 文件;安装完成后提示重启 DSH,再按保存的开关启用 QQ。安装失败会显示原因,运行环境要求以 SDK 自身说明为准,不自动升级 Node。不使用 QQ 时无需 SDK,不影响其他功能;也可自行安装兼容版本,见 [安装说明](INSTALL.md#第一步把-dsh-world-装进-profile)。
94
+ QQ 的 SDK 依赖、群里默认只接被叫到的、看门狗,以及 QQ 的记忆和接入开关,见 [注意事项·QQ](NOTES.md#qq)。
111
95
 
112
96
  在 profile 的 `cordis.patch.yml` 里打开 `qqNative`(`enabled: true` 只是允许它存在)、填上 WS 地址与 token,再到控制台「概览 → 接入」把 QQ 拨开,切到顶部「QQ」页查看:连着哪个地址、收过几个会话、发过几条、挡下几条、排队待发几条、会自己回还是只看不回,一眼看到。页面里能直接拨「会自己回话 / 只看不回」,设「静默到某个时间点」(只收不回,到点自己醒),改私聊和群的白名单(留空就是谁都不收,改完不用重启),也能打开 SnowLuma 控制台、手动拉起 SnowLuma。这些改动记在世界目录的 `qq-native.json`,盖在配置之上。没配 `qqNative.enabled` 时,QQ 页提示通道未开启。
113
97
 
114
98
  参数不对不会崩,只会连不上:卡上会把原因写在 `lastError` 里(比如 `WS 错误: Unexpected server response: 401`,说明填的是 HTTP 那份 token,该换成 WebSocket 那份)。QQ 页在通道启用、世界已经开始时展示详细状态,其他时候提示未开启。
115
99
 
116
- **群里默认只接被叫到的**(`groupTrigger: mention`):被 @、引用她刚说过的话、或文本命中 `groupKeywords` 才算叫她,其余消息只进本轮上下文,不开口也不花额度;写 `all` 就是每句都接,代价是群里每一条都会让她跑完一轮。`@全体` 是群公告,不算叫她。`bindHomeSession` 决定谁和她的家会话共用一个入口,默认 `owner`。
117
-
118
100
  **她怎么说话**:同一会话 `batchQuietMs`(默认 10 秒)内连着来的几句攒成一条再问她(最多等 30 秒),群里每句前面带着是谁说的。她的回答按空行分成几条发,中间停一下;回话里写 `[[img:路径]]`、`[[face:id]]`、`[[at:QQ号]]` 会变成图片、QQ 表情和 @,`[[sticker:开心]]` 按备注挑一个收藏表情单发(也可以写第几个),`[[qzone:正文]]` 发一条所有人可见的 QQ 空间说说。发不出去的消息先排队,每 3 秒重试,最多留 5 分钟。她在家里自己开的那一轮(闹钟、世界线)说完的话,也会推一份给主人(`ownerQQ`,空着取 `allowPrivate` 的第一个);有人说话的轮次是在回那个人,不另推。
119
101
 
120
- **看门狗**(`supervise`,默认开):QQ 开着时每 30 秒探一次 `wsUrl` 的端口,不通就按 `snowlumaHome` 把 SnowLuma 拉起来(本机有 `SnowLuma-watchdog` 计划任务时借它跑,能活过 DSH 重启;没有就直接起进程,只活到 DSH 退出)。拉不起来的原因写在卡上。不想让插件动手就设成 `false`,卡上的「拉起 SnowLuma」按钮照旧能用。
121
-
122
102
  卡上那个「打开 SnowLuma 控制台」的按钮,读 `snowlumaHome` 下 `config/runtime.json` 里的地址与端口,带着一次性登录票据打开系统浏览器——第一次要先填一次 SnowLuma 的面板密码,之后记在世界目录的 `panel.json` 里(权限 600),不用再输。
123
103
 
124
104
  ## 安装
@@ -139,13 +119,7 @@ node <DSH 自带 pnpm 的入口文件> add dsh-world@latest --ignore-scripts --r
139
119
 
140
120
  **已有 world 更新**:正常退出 DSH 后,用 [`scripts/update-world.mjs`](scripts/update-world.mjs) 指定原 profile、`.tgz` 和 DSH 自带 pnpm;`.tgz` 可直接从 npm 下载,例如 <https://registry.npmjs.org/dsh-world/-/dsh-world-0.6.4.tgz>。脚本先备份完整 profile、世界及会话,再更新并校验;失败恢复旧 profile,保留她已有文件。安装成品无需 Git、npm 或 TypeScript,完整命令与恢复说明见 [已有 world 升级](INSTALL.md#已有-world用编译包更新)。
141
121
 
142
- **只留对话的压缩**(默认自动换上):装好 `dsh-world` 后第一次启动,插件会把你 profile 的 `cordis.patch.yml` 里原版压缩那一行换成 `dsh-world/compaction`,先在同目录留一份 `.dsh-world.<随机>.bak` 备份,重启 DSH 后生效,世界面板的健康状态里会提示这件事。只有找到唯一一条原版压缩配置时才会改;已经换过、写法对不上或有多条时什么都不动。每个世界只试这一次:之后你手动改回原版,它不会再替你换。不想换,在 `dsh-world` 的配置里写 `replaceCompaction: false`。手动启用或恢复也可以用下面的脚本:
143
-
144
- ```powershell
145
- powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-compaction.ps1 -profilePath '<你的 DSH profile 目录>'
146
- ```
147
-
148
- 脚本做的是同一件事:把原版压缩条目换成 `dsh-world/compaction` 并留备份。它对整个 profile 生效,不限世界工作区,见上文「对世界工作区以外的影响」。
122
+ **只留对话的压缩**:装好 `dsh-world` 后第一次启动,默认会把 profile 的压缩换成 `dsh-world/compaction`(先备份,重启 DSH 后生效),整个 profile 的会话压缩都会受影响。怎么关、怎么手动启用,见 [注意事项·安装与升级](NOTES.md#安装与升级)。
149
123
 
150
124
  ## 设置
151
125
 
@@ -161,6 +135,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
161
135
  agentPreset: standard # 她所在的预设
162
136
  timeZone: Asia/Seoul # 默认系统时区
163
137
  life: true # 生活线,默认开启
138
+ replaceCompaction: true # 首次启动把 profile 的压缩换成 dsh-world 的只留对话压缩;false = 不动
164
139
  archiveScope: workspace # workspace:家的工作区;home:仅当前家会话
165
140
  fallbackWakeTime: '09:00' # 没定闹钟时,早上几点叫醒她
166
141
  diaryDir: C:/path/to/日记 # 日记目录,默认在世界目录里
@@ -188,6 +163,23 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
188
163
  supervise: true # 看门狗:端口不通就把 SnowLuma 拉起来
189
164
  ```
190
165
 
166
+ **压缩的配置**写在压缩那一行的 `config` 里(profile 的 `cordis.patch.yml` 中 `name: 'dsh-world/compaction'` 那一条),不是上面 `dsh-world` 这一行:
167
+
168
+ ```yaml
169
+ - id: compaction-basic
170
+ name: 'dsh-world/compaction'
171
+ config:
172
+ thresholdRatio: 0.75 # 用量超过上下文窗口的这个比例就压缩,默认 0.75
173
+ defaultContextWindow: 1048576 # 适配器没声明窗口的模型按这个估算,默认 1M
174
+ auto: true # false = 只手动压缩(「应用并压缩家会话」仍可用)
175
+ # maxTokens: 65536 # 压缩时摘要回复的长度上限
176
+ # headroomTokens: 65536 # 不再影响触发点;只在没写 maxTokens 时当作摘要回复的长度
177
+ # maxOverflowRetries: 1 # 请求被模型以“超出窗口”拒绝后,压缩重试的次数
178
+ # modelPolicies: [] # 按 provider/model 单独写上面的项,例如给一个窗口只有 128k 的自建模型写 defaultContextWindow
179
+ ```
180
+
181
+ 触发点怎么算、窗口值从哪来,见 [注意事项](NOTES.md#自动压缩什么时候触发)。
182
+
191
183
  **改她的措辞**:世界提示词可以直接在控制台里改。闹钟响时、提前停下时、每日回顾时她收到的话,在世界目录里放一份 `alarm.md` 就能按段覆盖,段落名和可用的占位符见 `templates/alarm.md`。插件写给她的话一律用第一人称「我」,读起来是她自己的念头。
192
184
 
193
185
  **时间**:建议把预设里 `time-context` 条目的 `refreshIntervalMs` 设为 `0`,让她每一步都知道现在几点。
package/client/index.js CHANGED
@@ -231,14 +231,14 @@ window.__ModuleLoader__.load({
231
231
  }
232
232
  var preview = renderPersona(persona)
233
233
  return h('div', { className: 'dw-pane' },
234
- h(Card, { title: '她是谁' }, LAYERS.map(function (layer) {
234
+ h(Card, { title: '她是谁' }, h('div', { className: 'dw-muted' }, '这里写的会取代 DSH 自带的那句默认身份(“You are an AI agent powered by DeepSeek Harness.”);如果你在 DSH 里已经设过系统人设,它原样保留,这里写的排在它后面。'), LAYERS.map(function (layer) {
235
235
  var common = { id: 'dw-' + layer.key, value: persona[layer.key] || '', onChange: function (e) { set(layer.key, e.target.value) } }
236
236
  return h('div', { className: 'dw-layer', key: layer.key },
237
237
  h('label', { htmlFor: common.id }, layer.key),
238
238
  layer.rows === 1 ? h('input', Object.assign({ type: 'text', className: 'dw-name', placeholder: '比如:鲸鲸' }, common)) : h('textarea', Object.assign({ rows: layer.rows }, common)),
239
239
  h('small', null, layer.hint))
240
240
  })),
241
- h(Card, { title: '她读到的样子', delay: 80 }, preview ? h('pre', { className: 'dw-preview' }, preview) : h('div', { className: 'dw-muted' }, '还什么都没写。没写的时候,她用宿主默认的人设。')),
241
+ h(Card, { title: '她读到的样子', delay: 80 }, preview ? h('pre', { className: 'dw-preview' }, preview) : h('div', { className: 'dw-muted' }, '还什么都没写。没写的时候,她沿用 DSH 自带的默认身份和你在 DSH 里设的系统人设。')),
242
242
  h('div', { className: 'dw-bar' },
243
243
  h('button', { className: 'dw-btn primary', disabled: !dirty || busy, onClick: save }, busy ? '保存中…' : '保存人设'),
244
244
  h('span', { className: msg.indexOf('失败') >= 0 ? 'dw-bad' : 'dw-muted' }, msg || (dirty ? '有改动还没保存' : ''))))
@@ -20,8 +20,14 @@ declare module '@deepseek-ai/dsh-session/types' {
20
20
  'plugin:dsh-world/compaction-request': SummaryAudit;
21
21
  }
22
22
  }
23
+ /**
24
+ * `thresholdRatio`: compaction starts at this share of the context window. `defaultContextWindow`: the window assumed for a model
25
+ * whose adapter declares none. `headroomTokens` no longer takes anything off the trigger; it only sizes the summary reply when
26
+ * `maxTokens` is unset.
27
+ */
23
28
  interface Policy {
24
29
  thresholdRatio: number;
30
+ defaultContextWindow: number;
25
31
  headroomTokens: number;
26
32
  summarizationProvider: string;
27
33
  summarizationModel: string;
@@ -42,6 +48,12 @@ export interface ToolFreeCompactionConfig extends Partial<Policy> {
42
48
  * provider-cached prefix. Assistant text split around a removed call is rejoined.
43
49
  */
44
50
  export declare function toolFreeMessages(messages: readonly Message[]): Message[];
51
+ /** Compaction starts at `ratio` of the window, or earlier when a reply of `reserved` tokens would then no longer fit after the prompt. */
52
+ export declare function compactionThreshold(input: {
53
+ contextWindow: number;
54
+ ratio: number;
55
+ reserved: number;
56
+ }): number;
45
57
  /**
46
58
  * Replacement for `@deepseek-ai/dsh-compaction-basic`: drops every tool call,
47
59
  * tool result, tool schema and reasoning block from the compacted span, then
@@ -53,6 +65,7 @@ export default class ToolFreeCompaction extends CompactionEngine {
53
65
  timeZone: z<string, string, "plain">;
54
66
  auto: z<boolean, boolean, "plain">;
55
67
  thresholdRatio: z<number, number, "plain">;
68
+ defaultContextWindow: z<number, number, "plain">;
56
69
  headroomTokens: z<number, number, "plain">;
57
70
  summarizationProvider: z<string, string, "plain">;
58
71
  summarizationModel: z<string, string, "plain">;
@@ -62,6 +75,7 @@ export default class ToolFreeCompaction extends CompactionEngine {
62
75
  provider?: string | null | undefined;
63
76
  model?: string | null | undefined;
64
77
  thresholdRatio?: number | null | undefined;
78
+ defaultContextWindow?: number | null | undefined;
65
79
  headroomTokens?: number | null | undefined;
66
80
  summarizationProvider?: string | null | undefined;
67
81
  summarizationModel?: string | null | undefined;
@@ -71,6 +85,7 @@ export default class ToolFreeCompaction extends CompactionEngine {
71
85
  provider: z<string, string, "defined">;
72
86
  model: z<string, string, "defined">;
73
87
  thresholdRatio: z<number, number, "plain">;
88
+ defaultContextWindow: z<number, number, "plain">;
74
89
  headroomTokens: z<number, number, "plain">;
75
90
  summarizationProvider: z<string, string, "plain">;
76
91
  summarizationModel: z<string, string, "plain">;
@@ -81,6 +96,7 @@ export default class ToolFreeCompaction extends CompactionEngine {
81
96
  timeZone: z<string, string, "plain">;
82
97
  auto: z<boolean, boolean, "plain">;
83
98
  thresholdRatio: z<number, number, "plain">;
99
+ defaultContextWindow: z<number, number, "plain">;
84
100
  headroomTokens: z<number, number, "plain">;
85
101
  summarizationProvider: z<string, string, "plain">;
86
102
  summarizationModel: z<string, string, "plain">;
@@ -90,6 +106,7 @@ export default class ToolFreeCompaction extends CompactionEngine {
90
106
  provider?: string | null | undefined;
91
107
  model?: string | null | undefined;
92
108
  thresholdRatio?: number | null | undefined;
109
+ defaultContextWindow?: number | null | undefined;
93
110
  headroomTokens?: number | null | undefined;
94
111
  summarizationProvider?: string | null | undefined;
95
112
  summarizationModel?: string | null | undefined;
@@ -99,6 +116,7 @@ export default class ToolFreeCompaction extends CompactionEngine {
99
116
  provider: z<string, string, "defined">;
100
117
  model: z<string, string, "defined">;
101
118
  thresholdRatio: z<number, number, "plain">;
119
+ defaultContextWindow: z<number, number, "plain">;
102
120
  headroomTokens: z<number, number, "plain">;
103
121
  summarizationProvider: z<string, string, "plain">;
104
122
  summarizationModel: z<string, string, "plain">;
@@ -110,6 +128,7 @@ export default class ToolFreeCompaction extends CompactionEngine {
110
128
  private readonly overrides;
111
129
  private readonly timeZone;
112
130
  private readonly warnedTargets;
131
+ private readonly assumedWindows;
113
132
  private readonly overflowRetries;
114
133
  private readonly overflowAgents;
115
134
  constructor(ctx: Context, config?: ToolFreeCompactionConfig);
package/lib/compaction.js CHANGED
@@ -53,11 +53,18 @@ function routedTarget(session) {
53
53
  }
54
54
  function resolvePolicy(config) {
55
55
  return {
56
- thresholdRatio: config.thresholdRatio ?? 0.9, headroomTokens: config.headroomTokens ?? 65536,
56
+ thresholdRatio: config.thresholdRatio ?? 0.75, defaultContextWindow: config.defaultContextWindow ?? 1_048_576, headroomTokens: config.headroomTokens ?? 65536,
57
57
  summarizationProvider: config.summarizationProvider ?? '', summarizationModel: config.summarizationModel ?? '',
58
58
  maxTokens: config.maxTokens ?? config.headroomTokens ?? 65536, maxOverflowRetries: config.maxOverflowRetries ?? 1,
59
59
  };
60
60
  }
61
+ /** Compaction starts at `ratio` of the window, or earlier when a reply of `reserved` tokens would then no longer fit after the prompt. */
62
+ export function compactionThreshold(input) {
63
+ const fits = input.contextWindow - input.reserved;
64
+ if (fits <= 0)
65
+ throw new Error(`a ${input.reserved}-token reply leaves no room in a ${input.contextWindow}-token window`);
66
+ return Math.floor(Math.min(input.contextWindow * input.ratio, fits));
67
+ }
61
68
  /** Pressure failures specific to one routed model; warned once per target. */
62
69
  class TargetConfigError extends Error {
63
70
  targetKey;
@@ -72,14 +79,15 @@ export default class ToolFreeCompaction extends CompactionEngine {
72
79
  static inject = ['llm', 'tokenMeter', 'sessions'];
73
80
  static Config = z.object({
74
81
  timeZone: z.string(), auto: z.boolean(),
75
- thresholdRatio: z.number(), headroomTokens: z.natural(), summarizationProvider: z.string(), summarizationModel: z.string(),
82
+ thresholdRatio: z.number(), defaultContextWindow: z.natural(), headroomTokens: z.natural(), summarizationProvider: z.string(), summarizationModel: z.string(),
76
83
  maxTokens: z.natural(), maxOverflowRetries: z.natural(),
77
- modelPolicies: z.array(z.object({ provider: z.string().required(), model: z.string().required(), thresholdRatio: z.number(), headroomTokens: z.natural(), summarizationProvider: z.string(), summarizationModel: z.string(), maxTokens: z.natural(), maxOverflowRetries: z.natural() })),
84
+ modelPolicies: z.array(z.object({ provider: z.string().required(), model: z.string().required(), thresholdRatio: z.number(), defaultContextWindow: z.natural(), headroomTokens: z.natural(), summarizationProvider: z.string(), summarizationModel: z.string(), maxTokens: z.natural(), maxOverflowRetries: z.natural() })),
78
85
  });
79
86
  policy;
80
87
  overrides;
81
88
  timeZone;
82
89
  warnedTargets = new Set();
90
+ assumedWindows = new Set();
83
91
  overflowRetries = new WeakMap();
84
92
  overflowAgents = new WeakMap();
85
93
  constructor(ctx, config = {}) {
@@ -175,14 +183,22 @@ export default class ToolFreeCompaction extends CompactionEngine {
175
183
  const info = await this.ctx.llm.resolveModelInfo(target.provider, target.model, signal);
176
184
  assertNoActiveCompaction(agent.session, 'automatic pressure compaction');
177
185
  const key = `${target.provider}/${target.model}`;
178
- if (!info.context)
179
- throw new TargetConfigError(key, `dsh-world/compaction: no context capacity for ${key}; configure contextWindow on that adapter model`);
180
- const { contextWindow } = info.context;
186
+ let contextWindow = info.context?.contextWindow;
187
+ if (contextWindow === undefined) {
188
+ contextWindow = policy.defaultContextWindow;
189
+ if (!this.assumedWindows.has(key)) {
190
+ this.assumedWindows.add(key);
191
+ this.ctx.logger.warn(`dsh-world/compaction: ${key} declares no contextWindow; assuming ${contextWindow} tokens, so compaction starts at ${Math.floor(contextWindow * policy.thresholdRatio)}. If its real window is smaller, set contextWindow on that adapter model, or defaultContextWindow for it in modelPolicies.`);
192
+ }
193
+ }
181
194
  const reserved = agent.session.requestHeader()?.config.maxTokens ?? info.defaultMaxTokens ?? 0;
182
- const pressureBudget = contextWindow - reserved - policy.headroomTokens;
183
- if (pressureBudget <= 0)
184
- throw new TargetConfigError(key, `dsh-world/compaction: ${key} reserves ${reserved} completion and ${policy.headroomTokens} headroom tokens of its ${contextWindow}-token window, leaving no pressure budget`);
185
- const threshold = Math.floor(Math.min(contextWindow * policy.thresholdRatio, pressureBudget));
195
+ let threshold;
196
+ try {
197
+ threshold = compactionThreshold({ contextWindow, ratio: policy.thresholdRatio, reserved });
198
+ }
199
+ catch (error) {
200
+ throw new TargetConfigError(key, `dsh-world/compaction: ${key}: ${error instanceof Error ? error.message : String(error)}`);
201
+ }
186
202
  if (meter.measure(agent.session).totalTokens < threshold)
187
203
  return null;
188
204
  const range = selectWholeRange(agent.session, meter.measure(agent.session));
@@ -1,6 +1,5 @@
1
1
  import type { Agent } from '@deepseek-ai/dsh-agent';
2
2
  import type { Session } from '@deepseek-ai/dsh-session';
3
- import { type Faults } from './faults.ts';
4
3
  import type { WorldConfig } from './types.ts';
5
4
  import { type WorldNames, type WorldPrompt } from './worldPrompt.ts';
6
5
  export interface WorldPromptSource {
@@ -19,12 +18,11 @@ export interface WorldPromptSource {
19
18
  * the system prompt before pre-step, so the refresh happens on compaction/end) or explicit console application, so the prompt
20
19
  * stays in the provider-cached prefix. Whether the session is her home is asked per request.
21
20
  *
22
- * Her persona takes the place of the host's: registered under the host persona's name for her agent, it shadows
23
- * the deployment default. Where her preset already gave her agent a persona, that name is taken, so hers follows
24
- * it under its own name and the console says so.
21
+ * Her persona takes the place of DeepSeek Harness's stock identity line, but never of a persona someone has set: it is its own
22
+ * section placed right after the host's persona slot, so a system persona the deployment or her preset already has stays
23
+ * where it is and hers follows it.
25
24
  */
26
25
  export declare function createPromptSections(config: WorldConfig, world: WorldPromptSource, deps: {
27
- faults: Faults;
28
26
  logger: {
29
27
  warn(...args: unknown[]): void;
30
28
  };
@@ -1,11 +1,10 @@
1
- import { errorText } from "./faults.js";
2
1
  import { readPersona, renderPersona } from "./persona.js";
3
2
  import { renderSelf } from "./self.js";
4
3
  import { belongsToWorld, inWorld } from "./sourceArchive.js";
5
4
  import { readTemplate, renderWorldPrompt } from "./worldPrompt.js";
6
5
  import { reassembleOnChange } from "./worldScope.js";
7
- /** The host's persona section; a preset may also register it for its own agents. */
8
- const HOST_PERSONA = 'deployment:persona-prefix';
6
+ /** The stock "You are an AI agent powered by DeepSeek Harness." line; a section of the same name on her agent shadows it. */
7
+ const HARNESS_IDENTITY = 'harness:identity';
9
8
  /**
10
9
  * Her persona follows the configured preset; the world prompt is limited to the world's workspace.
11
10
  * Both are sections of the session's system prompt so she sees them on every
@@ -13,9 +12,9 @@ const HOST_PERSONA = 'deployment:persona-prefix';
13
12
  * the system prompt before pre-step, so the refresh happens on compaction/end) or explicit console application, so the prompt
14
13
  * stays in the provider-cached prefix. Whether the session is her home is asked per request.
15
14
  *
16
- * Her persona takes the place of the host's: registered under the host persona's name for her agent, it shadows
17
- * the deployment default. Where her preset already gave her agent a persona, that name is taken, so hers follows
18
- * it under its own name and the console says so.
15
+ * Her persona takes the place of DeepSeek Harness's stock identity line, but never of a persona someone has set: it is its own
16
+ * section placed right after the host's persona slot, so a system persona the deployment or her preset already has stays
17
+ * where it is and hers follows it.
19
18
  */
20
19
  export function createPromptSections(config, world, deps) {
21
20
  const entries = new Map();
@@ -46,14 +45,15 @@ export function createPromptSections(config, world, deps) {
46
45
  const prompt = agent.ctx.systemPrompt;
47
46
  const order = prompt.getSectionOrder('DEPLOYMENT_PERSONA_PREFIX') ?? 0;
48
47
  const text = () => entry.text.persona;
48
+ const persona = prompt.section({ name: 'dsh-world-persona', order: order + 1, interpolate: false, text });
49
+ // DeepSeek Harness's own identity line gives way to hers; a persona someone set in DSH sits in its own slot and is left alone.
50
+ // If a preset already put its own words on that identity slot for this agent, they stay exactly as written.
51
+ let identity;
49
52
  try {
50
- entry.persona = prompt.section({ name: HOST_PERSONA, order, interpolate: false, text });
51
- deps.faults.clear('persona');
52
- }
53
- catch (error) {
54
- entry.persona = prompt.section({ name: 'dsh-world-persona', order: order + 1, interpolate: false, text });
55
- deps.faults.set('persona', `她的预设自带人设,你写的人设排在它后面(${errorText(error)})`);
53
+ identity = prompt.section({ name: HARNESS_IDENTITY, order: prompt.getSectionOrder('HARNESS_IDENTITY'), interpolate: false, text: () => '' });
56
54
  }
55
+ catch { /* the slot is already taken for this agent */ }
56
+ entry.persona = () => { persona(); identity?.(); };
57
57
  }
58
58
  return {
59
59
  add(agent) {
package/lib/runtime.js CHANGED
@@ -33,7 +33,7 @@ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () =
33
33
  const names = () => world?.names?.() ?? world?.prompt.names ?? worldNames(config);
34
34
  const included = (session) => inWorld(session, config, world?.inWorkspace);
35
35
  const faults = new Faults();
36
- const prompts = world && createPromptSections(config, world, { faults, logger: ctx.logger });
36
+ const prompts = world && createPromptSections(config, world, { logger: ctx.logger });
37
37
  const memory = new WeakMap();
38
38
  const attaching = new WeakMap();
39
39
  const disposers = [];
@@ -82,6 +82,25 @@ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () =
82
82
  state.reload = true;
83
83
  state.pendingId = undefined;
84
84
  }
85
+ /** Where memory blocks sit on a session's surface, for the log: positions and event types only, never message text. */
86
+ function memoryNodesOn(session) {
87
+ const found = [];
88
+ for (const seq of session.surface.nodes) {
89
+ const event = session.eventAt(seq);
90
+ if (!event)
91
+ continue;
92
+ let message;
93
+ try {
94
+ message = session.deriveEventMessage(event);
95
+ }
96
+ catch {
97
+ continue;
98
+ }
99
+ if (message?.source?.kind === memorySource)
100
+ found.push(`#${seq}(${event.type})`);
101
+ }
102
+ return found.length ? found.slice(0, 8).join('、') + (found.length > 8 ? `…共 ${found.length} 个` : '') : '无';
103
+ }
85
104
  /** Empty system nodes retire only our recalled blocks and derive no model message; original logs stay intact. */
86
105
  function flushRetired(session, state, position) {
87
106
  const retiring = state.retiring;
@@ -206,13 +225,17 @@ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () =
206
225
  disposers.push(ctx.on('llm/stream', async function* (request, next) {
207
226
  const agent = isAgentLoopRequest(request) && request.sessionId ? ctx.agents.get(request.sessionId) : undefined;
208
227
  const owned = agent && included(agent.session);
209
- if (agent && !owned && (prompts?.active(agent.session) || request.messages.some(message => message.source?.kind === memorySource))) {
228
+ const inRequest = agent && !owned ? request.messages.filter(message => message.source?.kind === memorySource).length : 0;
229
+ const placed = !!agent && !owned && !!prompts?.active(agent.session);
230
+ if (agent && !owned && (placed || inRequest)) {
210
231
  const state = memory.get(agent.session);
211
232
  if (state) {
212
233
  retireMemory(agent.session, state);
213
234
  flushRetired(agent.session, state, state.position);
214
235
  state.restart = true;
215
236
  }
237
+ const reasons = [inRequest ? `请求里还带着 ${inRequest} 条世界记忆块` : '', placed ? '世界提示还挂在会话上' : ''].filter(Boolean).join(';');
238
+ ctx.logger.warn(`dsh-world: 阻止了会话 ${agent.id}(预设 ${agent.session.header.agentPreset ?? '无'})的一次请求,它不在世界工作区里。原因:${reasons}。${state ? '已尝试退役记忆块' : '这个会话没有记忆状态,没法退役'};退役后会话表面上仍有的记忆节点:${memoryNodesOn(agent.session)}。DSH_WORLD_SCOPE_CHANGED`);
216
239
  yield { type: 'finish', reason: { kind: 'error', failure: { code: 'DSH_WORLD_SCOPE_CHANGED', message: 'dsh-world: 会话已离开世界工作区,已阻止携带世界上下文的请求,请重新发送。' } } };
217
240
  return;
218
241
  }
@@ -32,8 +32,9 @@ export declare function createWorldSwitch(worldDir: string, configuredScope?: Me
32
32
  memoryTurns: () => number;
33
33
  setMemoryTurns(turns: number | undefined): void;
34
34
  /**
35
- * The console's switches for the WeChat and QQ modules. WeChat is on unless turned off; QQ, whose SDK is an
36
- * optional dependency, is off until turned on, so its code is not even loaded before someone asks for it.
35
+ * The console's switches for the WeChat and QQ modules; both are off until someone turns them on. QQ's SDK is an
36
+ * optional dependency, so its code is not even loaded before then. WeChat used to default to on, so a world that
37
+ * never stored a choice but whose WeChat module has already run (it keeps its outbox) stays on after the upgrade.
37
38
  */
38
39
  wechatEnabled: () => boolean;
39
40
  qqEnabled: () => boolean;
@@ -24,7 +24,7 @@ export function createWorldSwitch(worldDir, configuredScope = 'workspace') {
24
24
  ...(validWorkspacePermission(stored?.workspacePermission) ? { workspacePermission: stored.workspacePermission } : {}),
25
25
  ...(validWechatContext(stored?.wechatContext) ? { wechatContext: stored.wechatContext } : {}),
26
26
  ...(validWechatBuffer(stored?.wechatBufferSeconds) ? { wechatBufferSeconds: stored.wechatBufferSeconds } : {}),
27
- ...(stored?.wechatEnabled === false ? { wechatEnabled: false } : {}),
27
+ ...(typeof stored?.wechatEnabled === 'boolean' ? { wechatEnabled: stored.wechatEnabled } : {}),
28
28
  ...(typeof stored?.qqEnabled === 'boolean' ? { qqEnabled: stored.qqEnabled } : {}),
29
29
  ...(stored?.compactAfterReview === false ? { compactAfterReview: false } : {}),
30
30
  ...(stored?.compactionSwapped === true ? { compactionSwapped: true } : {}),
@@ -73,15 +73,16 @@ export function createWorldSwitch(worldDir, configuredScope = 'workspace') {
73
73
  save(turns === undefined || turns === DEFAULT_MEMORY_TURNS ? rest : { ...rest, memoryTurns: turns });
74
74
  },
75
75
  /**
76
- * The console's switches for the WeChat and QQ modules. WeChat is on unless turned off; QQ, whose SDK is an
77
- * optional dependency, is off until turned on, so its code is not even loaded before someone asks for it.
76
+ * The console's switches for the WeChat and QQ modules; both are off until someone turns them on. QQ's SDK is an
77
+ * optional dependency, so its code is not even loaded before then. WeChat used to default to on, so a world that
78
+ * never stored a choice but whose WeChat module has already run (it keeps its outbox) stays on after the upgrade.
78
79
  */
79
- wechatEnabled: () => settings.wechatEnabled !== false,
80
+ wechatEnabled: () => settings.wechatEnabled ?? existsSync(join(worldDir, 'wechat-outbox.sqlite')),
80
81
  qqEnabled: () => settings.qqEnabled === true,
81
82
  setModules(next) {
82
83
  const { wechatEnabled, qqEnabled, ...rest } = settings;
83
- const wechat = next.wechat ?? wechatEnabled !== false, qq = next.qq ?? qqEnabled === true;
84
- save({ ...rest, ...(wechat ? {} : { wechatEnabled: false }), ...(qq ? { qqEnabled: true } : {}) });
84
+ const wechat = next.wechat ?? wechatEnabled ?? existsSync(join(worldDir, 'wechat-outbox.sqlite')), qq = next.qq ?? qqEnabled === true;
85
+ save({ ...rest, wechatEnabled: wechat, ...(qq ? { qqEnabled: true } : {}) });
85
86
  },
86
87
  /** Read by the WeChat adapter on its next poll; a batch already waiting keeps the value it started with. */
87
88
  wechatContext: () => settings.wechatContext ?? DEFAULT_WECHAT_CONTEXT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-world",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "description": "Cross-session memory, persona and life routines for DSH, with a world console, tool-free compaction, native QQ and Windows WeChat messaging, group history and quoted replies",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -37,6 +37,7 @@
37
37
  "INSTALL.md",
38
38
  "CONTRIBUTING.md",
39
39
  "CHANGELOG.md",
40
+ "NOTES.md",
40
41
  "assets",
41
42
  "scripts/enable-tool-free-compaction.ps1",
42
43
  "scripts/update-world.mjs",
@@ -66,7 +67,8 @@
66
67
  "compatibility": {
67
68
  "dshReleases": {
68
69
  "0.2.1-rc.2": "compatible",
69
- "0.2.1-rc.3": "compatible"
70
+ "0.2.1-rc.3": "compatible",
71
+ "0.2.1-rc.5": "compatible"
70
72
  }
71
73
  }
72
74
  },