dsh-world 0.7.1 → 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.
package/lib/runtime.js CHANGED
@@ -8,17 +8,22 @@ import { createPromptSections } from "./promptSection.js";
8
8
  import { belongsToWorld, createSourceArchive, inWorld } from "./sourceArchive.js";
9
9
  import { worldNames } from "./worldPrompt.js";
10
10
  import { reassembleOnChange } from "./worldScope.js";
11
- import { DEFAULT_MEMORY_TURNS } from "./worldSwitch.js";
11
+ import { DEFAULT_COLD_HOURS, DEFAULT_MEMORY_TURNS } from "./worldSwitch.js";
12
12
  const memorySource = 'dsh-world-history';
13
13
  const isMemoryBlock = (event) => event?.type === 'user/message' && event.data.source.kind === memorySource;
14
14
  /**
15
15
  * The memory line: her conversations are archived as they happen, and every world session gets a memory
16
- * block of the newest turns at its start and after each successful compaction, never in between, so it stays
17
- * inside the provider-cached prefix. `home` archives the current home; `workspace` uses host membership. The memory block still
16
+ * block of the newest turns at its start, after each successful compaction and when it speaks again after being cold,
17
+ * never in between, so it stays inside the provider-cached prefix. `home` archives the current home; `workspace` uses host membership. The memory block still
18
18
  * goes to every world session in her workspace (`inWorkspace`), independently of the archive scope.
19
19
  * `memoryTurns` is read each time a block is built (default 200).
20
+ *
21
+ * A session silent for `coldHours` (read at each turn start, default 24) is cold (#36): its provider cache has most
22
+ * likely expired (DeepSeek clears an unused one "usually within a few hours to a few days", best effort), so its next
23
+ * turn re-reads her memory block and prompt as a newly opened session would, at the cost of at most one uncached
24
+ * request. A conversation in progress does not pause that long, so its cached prefix stays whole.
20
25
  */
21
- export function createWorldRuntime(ctx, config, store, world, memoryTurns = () => DEFAULT_MEMORY_TURNS) {
26
+ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () => DEFAULT_MEMORY_TURNS, coldHours = () => DEFAULT_COLD_HOURS, now = Date.now) {
22
27
  if (config.archiveScope === 'workspace' && !world?.archiveSession)
23
28
  throw new Error('Workspace archive requires the host workspace selection');
24
29
  const archivedByScope = world?.archiveSession ?? ((sessionId) => config.archiveScope !== 'home' || !!world?.isHome(sessionId));
@@ -144,7 +149,11 @@ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () =
144
149
  if (state && compacted) {
145
150
  state.reload = true;
146
151
  }
147
- if (compacted)
152
+ // The host assembles the system prompt after turn/start, so a cold session's first request already has both.
153
+ const cold = !!state && event.type === 'turn/start' && state.lastRequestAt !== undefined && now() - state.lastRequestAt >= coldHours() * 60 * 60_000;
154
+ if (cold)
155
+ state.reload = true;
156
+ if (compacted || cold)
148
157
  prompts?.refresh(session);
149
158
  if (!isOrdinarySession(session.header))
150
159
  return;
@@ -208,8 +217,10 @@ export function createWorldRuntime(ctx, config, store, world, memoryTurns = () =
208
217
  // The step is open here and its request is not built yet: the one place retired blocks can be written validly.
209
218
  disposers.push(ctx.on('agent/request', async function (payload, next) {
210
219
  const state = memory.get(payload.agent.session);
211
- if (state)
220
+ if (state) {
212
221
  state.position = { turn: payload.turn, step: payload.step };
222
+ state.lastRequestAt = now();
223
+ }
213
224
  if (state?.retiring.length)
214
225
  flushRetired(payload.agent.session, state, state.position);
215
226
  return next();
@@ -6,7 +6,7 @@ const pageSize = 128;
6
6
  /** Unreadable logs are isolated per source; their archive gaps remain visible until replay succeeds. */
7
7
  export function isCorruptSessionLog(error) {
8
8
  const text = error instanceof Error ? `${error.name} ${error.message}` : String(error ?? '');
9
- return /stored log is corrupt|SessionFormatError|does not match an open turn/i.test(text);
9
+ return /stored log is corrupt|SessionFormatError|does not match (?:an|the) open turn/i.test(text);
10
10
  }
11
11
  export function belongsToWorld(session, config) {
12
12
  const header = session.header;
@@ -1,6 +1,8 @@
1
1
  import { type MemoryArchiveScope } from './archiveSelection.ts';
2
2
  /** How many of the newest turns the memory block carries when nothing else is set. */
3
3
  export declare const DEFAULT_MEMORY_TURNS = 200;
4
+ /** Hours a session stays silent before its next turn re-reads her memory block and prompt (#36); see `runtime.ts`. */
5
+ export declare const DEFAULT_COLD_HOURS = 24, MAX_COLD_HOURS = 720;
4
6
  /** WeChat group messages read before a mention, and seconds a private image waits for its companions. */
5
7
  export declare const DEFAULT_WECHAT_CONTEXT = 5, MAX_WECHAT_CONTEXT = 20;
6
8
  export declare const DEFAULT_WECHAT_BUFFER_SECONDS = 3, MAX_WECHAT_BUFFER_SECONDS = 30;
@@ -31,6 +33,9 @@ export declare function createWorldSwitch(worldDir: string, configuredScope?: Me
31
33
  /** Turns in her memory block; read when a block is built, so a change shows from the next session start or compaction. */
32
34
  memoryTurns: () => number;
33
35
  setMemoryTurns(turns: number | undefined): void;
36
+ /** Read at every turn start, so a change applies from the next turn of each session. */
37
+ coldHours: () => number;
38
+ setColdHours(hours: number | undefined): void;
34
39
  /**
35
40
  * The console's switches for the WeChat and QQ modules; both are off until someone turns them on. QQ's SDK is an
36
41
  * optional dependency, so its code is not even loaded before then. WeChat used to default to on, so a world that
@@ -60,6 +65,7 @@ export declare function createWorldSwitch(worldDir: string, configuredScope?: Me
60
65
  };
61
66
  export type WorldSwitch = ReturnType<typeof createWorldSwitch>;
62
67
  export declare const validTurns: (value: unknown) => value is number;
68
+ export declare const validColdHours: (value: unknown) => value is number;
63
69
  export declare const validWorkspacePermission: (value: unknown) => value is string;
64
70
  export declare const validWechatContext: (value: unknown) => value is number;
65
71
  export declare const validWechatBuffer: (value: unknown) => value is number;
@@ -5,6 +5,8 @@ import { validArchiveScope } from "./archiveSelection.js";
5
5
  import { DEFAULT_REVIEW_TIME, validClockTime } from "./life/alarm.js";
6
6
  /** How many of the newest turns the memory block carries when nothing else is set. */
7
7
  export const DEFAULT_MEMORY_TURNS = 200;
8
+ /** Hours a session stays silent before its next turn re-reads her memory block and prompt (#36); see `runtime.ts`. */
9
+ export const DEFAULT_COLD_HOURS = 24, MAX_COLD_HOURS = 720;
8
10
  /** WeChat group messages read before a mention, and seconds a private image waits for its companions. */
9
11
  export const DEFAULT_WECHAT_CONTEXT = 5, MAX_WECHAT_CONTEXT = 20;
10
12
  export const DEFAULT_WECHAT_BUFFER_SECONDS = 3, MAX_WECHAT_BUFFER_SECONDS = 30;
@@ -21,6 +23,7 @@ export function createWorldSwitch(worldDir, configuredScope = 'workspace', confi
21
23
  running: stored ? stored.running === true : existsSync(join(worldDir, 'life.json')),
22
24
  ...(typeof stored?.dailyBudget === 'number' ? { dailyBudget: stored.dailyBudget } : {}),
23
25
  ...(validTurns(stored?.memoryTurns) ? { memoryTurns: stored.memoryTurns } : {}),
26
+ ...(validColdHours(stored?.coldHours) ? { coldHours: stored.coldHours } : {}),
24
27
  ...(validArchiveScope(stored?.archiveScope) ? { archiveScope: stored.archiveScope } : {}),
25
28
  ...(validWorkspacePermission(stored?.workspacePermission) ? { workspacePermission: stored.workspacePermission } : {}),
26
29
  ...(validWechatContext(stored?.wechatContext) ? { wechatContext: stored.wechatContext } : {}),
@@ -75,6 +78,12 @@ export function createWorldSwitch(worldDir, configuredScope = 'workspace', confi
75
78
  const { memoryTurns: _old, ...rest } = settings;
76
79
  save(turns === undefined || turns === DEFAULT_MEMORY_TURNS ? rest : { ...rest, memoryTurns: turns });
77
80
  },
81
+ /** Read at every turn start, so a change applies from the next turn of each session. */
82
+ coldHours: () => settings.coldHours ?? DEFAULT_COLD_HOURS,
83
+ setColdHours(hours) {
84
+ const { coldHours: _old, ...rest } = settings;
85
+ save(hours === undefined || hours === DEFAULT_COLD_HOURS ? rest : { ...rest, coldHours: hours });
86
+ },
78
87
  /**
79
88
  * The console's switches for the WeChat and QQ modules; both are off until someone turns them on. QQ's SDK is an
80
89
  * optional dependency, so its code is not even loaded before then. WeChat used to default to on, so a world that
@@ -109,6 +118,7 @@ export function createWorldSwitch(worldDir, configuredScope = 'workspace', confi
109
118
  };
110
119
  }
111
120
  export const validTurns = (value) => typeof value === 'number' && Number.isInteger(value) && value >= 1;
121
+ export const validColdHours = (value) => typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= MAX_COLD_HOURS;
112
122
  export const validWorkspacePermission = (value) => typeof value === 'string' && value.trim().length > 0;
113
123
  export const validWechatContext = (value) => typeof value === 'number' && Number.isInteger(value) && value >= 1 && value <= MAX_WECHAT_CONTEXT;
114
124
  export const validWechatBuffer = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= MAX_WECHAT_BUFFER_SECONDS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-world",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
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": {
@@ -10,7 +10,7 @@ DSH 端代码在 `src/ecosystem/wechat/`,此目录只负责 Windows 微信收
10
10
  - 收到要交给她的消息后先缓冲(默认 3 秒,`bufferSeconds`):同一聊天、同一发言人在等待中又发来文字(私聊还包括图片),就重新计时,安静下来后合并为一次模型请求;最长等 30 秒、最多 16 条、合并文字不超过 2000 字,私聊最多两张图片。别人发言、引用、表情包等其他类型让批次立即结束。群聊只有 @ 她的消息会等待,同一人随后的文字合并进来,身份仍是 @ 她的那条。批次开始处理后才收到的消息留在微信数据库中,下一轮按序读取,不中断当前回复。
11
11
  - 批次成员保留原平台消息 ID,在同一事务中进入待处理与完成状态;缓冲期间不推进游标,处理中断后保留待核对状态,不自动重跑模型。图片单发仅进入会话图片上下文;图片加文字时只把真实文字按原范围归档。图片及附件引用不写入共享记忆块,是否另行留存其中信息由她自己判断。
12
12
  - 暂不接收视频号分享卡片:卡片会被跳过,不进入宿主会话或共享记忆。视频号卡片解析、视频内容读取,以及朋友圈浏览/发布,均预留为微信模块后续扩展,尚未实现;朋友圈发布需要独立接口,不能复用私聊/群聊发送接口。
13
- - 后台原生发送文字、图片及 GIF 表情,不操作窗口、鼠标、键盘或剪贴板。按 `engine/profiles.json` 中的文件大小与 SHA256 自动选择 Windows x64 微信 4.1.15.13 / 4.1.15.56 / 4.2.0.11 / 4.2.0.12 的指定构建(4.2 不能发原生 GIF 表情,表情包改为截取一帧作为图片发送,见下);未知或匹配不唯一的构建会在加载原生桥前报错,不能只凭版本号判断兼容。
13
+ - 后台原生发送文字、图片及 GIF 表情,不操作窗口、鼠标、键盘或剪贴板。按 `engine/profiles.json` 中的文件大小与 SHA256 自动选择 Windows x64 微信 4.1.15.13 / 4.1.15.56 / 4.2.0.11 / 4.2.0.12 / 4.2.0.13 的指定构建(4.2 的表情包截取一帧作为图片发送,见下)。未知或匹配不唯一的构建会在加载原生桥前报错。
14
14
  - 发言人使用真实 wxid,消息保持 `role: user`;昵称只作显示。
15
15
  - 每个群按平台、登录账号、聊天类型和群 ID 绑定独立会话,列在原房间工作区下,重启继续复用;群名变化不产生新会话。QQ 的相同参数可使用同一映射结构,但本模块仍只提供微信传输。
16
16
  - 群消息只在微信来源元数据的 `atuserlist` 包含她的真实 wxid 时触发,正文里手打 `@昵称` 不触发。回复携带当前消息之前默认 5 条(控制台可调,1–20)、最多 16KB 的同群上下文,保留各自的发言人 ID;每轮最多读取其中最近两张图片。
@@ -144,7 +144,9 @@ node <dsh-world 包目录>scriptsimport-stickers.mjs C:Usersyou.dshmemes C:Users
144
144
 
145
145
  4.1.15.56 的指纹与 19 个原生地址映射来自 [helper 的版本表](https://github.com/Prometheus-first/helper/blob/main/native/core_version.h)。两版沿用相同请求 ABI、账号核对和消息对象字段布局;版本表选择、地址编码及未知构建拒绝由离线测试覆盖。上游已实测新版文字收发及桥接加载卸载,媒体未逐项重做真实网络操作,详见其 [验证范围](https://github.com/Prometheus-first/helper/blob/main/native/README.md);本项目实测范围见下方日期记录。本次仅更新 Python 和版本表,无须重新编译未改动的 C++ 桥;新增构建或结构发生变化时仍需校准并实测。
146
146
 
147
- 4.2.0.11 与 4.2.0.12 的指纹和地址同样取自 helper 的版本表(按同一方法推出的 4.1.15.56 地址与已实测的配置逐项一致)。上游 4.2 只映射了文字、撤回和图片收发路径,原生 GIF 表情的 5 个地址没有映射,上游自己的表情发送在 4.2 上也直接拒绝;所以这两个构建的这 5 项为 null,原生桥只在发表情包时要求它们,文字和图片照常发送。在 4.2 上发表情包时,适配器把 GIF 转成一张静态 PNG 按图片发送:取第一帧,第一帧完全透明或只有一种颜色时改取最后一帧。**本项目没有 4.2 实机,以上未经真实微信验证**;首次使用请先向测试私聊各发一次文字、图片和表情包核对。原生桥源码因此改动,升级后需要重新运行 `wechat.ps1 Build`,否则适配器会以“原生桥源码已变化”拒绝加载。
147
+ 4.2.0.11 与 4.2.0.12 的指纹和地址取自 helper 的版本表。4.2.0.13 的地址由本项目从腾讯签名的 `Weixin.dll` 独立比对得出,基准是从安装包离线解出的 4.2.0.12 DLL。三个 4.2 构建都沿用静态表情发送方式。适配器取 GIF 第一帧转为 PNG,第一帧完全透明或只有一种颜色时改取最后一帧。4.2.0.13 仅更新版本表,已构建当前原生桥的环境可直接使用。来源见 [NOTICE](engine/NOTICE.md)。
148
+
149
+ 2026-11-04 已在 Windows 微信 4.2.0.13 上通过 `Probe`,核对了构建指纹、绑定账号及原生调度。实际文字、图片、表情包投递及 DSH 收发联动待验证。
148
150
 
149
151
  2026-10-25 已在绑定的专用账号私聊中确认两条独立文字及一条原生表情(类型 47),并在选定家庭群补发确认一张原生表情和一条文字;均核对服务器消息编号,媒体内容同时核对 MD5。首次群会话的技能目录误判已修复并有回归测试。2026-10-26 已确认家庭群真实 @ 触发时读取两张缓存图片、模型描述图片并回群发送成功,附件引用保存在群会话日志,该群共享归档记录数仍为 0。该轮未测独立图片发送和锁屏运行。
150
152
 
@@ -11,3 +11,9 @@ hooks, recall handling, account discovery or group management.
11
11
 
12
12
  profiles.json contains the fingerprint-locked 4.1.15.13, 4.1.15.56, 4.2.0.11 and 4.2.0.12
13
13
  address mappings from https://github.com/Prometheus-first/helper/blob/main/native/core_version.h.
14
+
15
+ The 4.2.0.13 mapping was derived by dsh-world from the Tencent-signed Windows
16
+ x64 Weixin.dll. The comparison used the 4.2.0.12 DLL extracted from Tencent's
17
+ installer and verified against the existing profile. Function disassembly,
18
+ references to the account root, and the context vtable were compared between
19
+ the two builds.
@@ -110,5 +110,33 @@
110
110
  "contextVtable": 151871336,
111
111
  "emoticonVtable": null
112
112
  }
113
+ },
114
+ {
115
+ "version": "4.2.0.13",
116
+ "size": 205943848,
117
+ "sha256": "afe3d02c58bada3c35009c0cd58ee1f57b2a00fe53237d0dce649107fddb9a20",
118
+ "timestamp": 1793604862,
119
+ "imageSize": 206430208,
120
+ "addresses": {
121
+ "application": 285968,
122
+ "scheduler": 291600,
123
+ "schedule": 3228064,
124
+ "context": 291360,
125
+ "provider": 3690048,
126
+ "manager": 7465840,
127
+ "text": 91370832,
128
+ "image": 65862832,
129
+ "emoticon": null,
130
+ "copyWide": 636384,
131
+ "validateGif": null,
132
+ "probeGif": null,
133
+ "releaseProbe": null,
134
+ "send": 25014992,
135
+ "allocate": 124417292,
136
+ "free": 124417360,
137
+ "accountRoot": 198245872,
138
+ "contextVtable": 151879656,
139
+ "emoticonVtable": null
140
+ }
113
141
  }
114
142
  ]