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/CHANGELOG.md +379 -365
- package/NOTES.md +19 -8
- package/README.md +2 -2
- package/client/index.js +12 -2
- package/lib/console/routes.d.ts +2 -0
- package/lib/console/routes.js +11 -4
- package/lib/console/snapshot.d.ts +2 -0
- package/lib/console/snapshot.js +1 -1
- package/lib/ecosystem/qq-native/home.d.ts +1 -0
- package/lib/ecosystem/qq-native/home.js +10 -3
- package/lib/ecosystem/qq-native/index.js +17 -4
- package/lib/ecosystem/qq-native/native-bridge.js +5 -2
- package/lib/ecosystem/qq-native/replies.d.ts +3 -2
- package/lib/ecosystem/qq-native/replies.js +15 -4
- package/lib/ecosystem/shared/context.d.ts +5 -0
- package/lib/ecosystem/shared/context.js +5 -0
- package/lib/hostContract.d.ts +4 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +21 -3
- package/lib/promptSection.d.ts +5 -4
- package/lib/promptSection.js +9 -8
- package/lib/runtime.d.ts +8 -3
- package/lib/runtime.js +17 -6
- package/lib/sourceArchive.js +1 -1
- package/lib/worldSwitch.d.ts +6 -0
- package/lib/worldSwitch.js +10 -0
- package/package.json +1 -1
- package/src/ecosystem/wechat/windows/README.md +4 -2
- package/src/ecosystem/wechat/windows/engine/NOTICE.md +6 -0
- package/src/ecosystem/wechat/windows/engine/profiles.json +28 -0
package/NOTES.md
CHANGED
|
@@ -53,7 +53,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
53
53
|
|
|
54
54
|
任务会等家空闲后执行一次,不打断当前对话;完成后的下一轮使用已保存的人设、名字、世界提示词和「我是谁」。压缩会调用模型并重建上下文缓存,没有可压缩内容时只刷新配置。面板显示执行结果或失败原因,停止世界会取消任务。
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
这个按钮只作用于家会话;其他已有会话在各自下一次成功压缩、重新加载,或[隔了很久再开口](#很久没说话的窗口再开口时重新读一遍)时更新,新建会话直接读取已保存内容。
|
|
57
57
|
|
|
58
58
|
### 你自己的世界提示词不会被自动改
|
|
59
59
|
|
|
@@ -68,7 +68,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
68
68
|
- 控制台「人设」全部留空时,什么都不改,沿用 DSH 的默认身份和你已有的人设。
|
|
69
69
|
- DSH 其余的系统提示(计划、工具、文件引用等说明)不动。
|
|
70
70
|
- 如果同一份人设在 DSH 里和控制台里各写了一遍,两份都会进提示词,内容会重复;只想要一份,清掉其中一处。
|
|
71
|
-
-
|
|
71
|
+
- 范围和世界提示词一样:她工作区里、匹配该世界预设的普通会话。工作区以外的会话哪怕用的是同一个预设(默认的 `standard` 就是 DSH 大多数会话的预设),也保持 DSH 原来的身份,不会变成她;改动对已有会话在下次压缩、「应用并压缩家会话」或隔了很久(默认 24 小时)再开口时生效,新会话直接使用。
|
|
72
72
|
|
|
73
73
|
## 压缩与记忆
|
|
74
74
|
|
|
@@ -83,7 +83,19 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
83
83
|
|
|
84
84
|
### 每日回顾后自动压缩
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
默认开,可在控制台概览的「回顾后自动压缩」关掉。每晚的回顾里她会改写「我是谁」,而正在用的会话里系统提示只在压缩之后才重新读取,不压缩的话新版要等到下一次压缩才生效,可能隔好几天。所以回顾那一轮结束、家空闲后,插件会自动执行一次[「应用并压缩家会话」](#修改人设和世界提示词后要手动应用):新版「我是谁」随压缩一起生效,压缩后最近的聊天原文会作为记忆块重新放回她眼前,衔接是接得上的。压缩本来就要重建缓存,这样不会多破坏一次,但每晚会多一次摘要调用。只在回顾真的送到她那里之后才触发,闹钟和问候不会;只作用于家会话,人设和世界提示词的修改仍然需要手动应用。没压成时(比如找不到压缩服务、摘要请求被模型拒绝),原因连同底层报错一起留在健康状态里,下一次压缩成功后消失。
|
|
87
|
+
|
|
88
|
+
### 很久没说话的窗口再开口时重新读一遍
|
|
89
|
+
|
|
90
|
+
记忆块、人设、世界提示词和「我是谁」平时只在会话打开和压缩之后读取,中途不动,这样才能留在模型服务的缓存里,正在聊的会话不会每一步都重新计费。代价是:一个很少用的窗口(比如几天才聊几句的 QQ 或微信群会话)从不压缩,就会一直停在打开那天的版本,不知道别处聊过什么,也看不到她后来改写的「我是谁」。
|
|
91
|
+
|
|
92
|
+
所以一个会话**隔了 24 小时以上**(控制台「记忆」卡片里可改,1 到 720 小时)再开口时,插件按新打开的会话处理:这一轮的第一个请求就带着最新的记忆块、人设和「我是谁」。这么久没发请求,模型服务的缓存多半已经清掉了(DeepSeek 说明未使用的缓存“通常在几小时到几天内”清除,不保证),重新读基本不多花钱;就算缓存还在,也只多一次未命中。正在聊的会话不会中途停这么久,不受影响。时长算的是这个会话上一次请求模型到现在,改了以后各窗口从下一轮开始按新时长判断,不用重启;DSH 重启后的第一句本来就会重新读。
|
|
93
|
+
|
|
94
|
+
想让窗口更快跟上(比如每天切换着用微信和 QQ),可以调小,例如 6 小时:隔夜再开口的窗口第二天第一句就会带上前一晚回顾后改写的「我是谁」,代价是缓存还没清掉时多一次未命中。DeepSeek 的缓存没有固定过期时间,调得越小,碰上缓存还在、白白多付一次的可能越大。
|
|
95
|
+
|
|
96
|
+
### 近期记忆的轮数
|
|
97
|
+
|
|
98
|
+
记忆块放最近多少轮,在控制台填,默认 200。默认值是按「最近的事完整摆在眼前」设计的;多端同时用、或者想省 token 时可以调小,代价是她直接记得的轮数变少,更早的事要靠 `memory_find` 自己去翻。记忆块留在会话里,之后每一步都随请求重发:平时按缓存命中计费,重新读进来的那一次按未命中计费。调小后两种都会变少。
|
|
87
99
|
|
|
88
100
|
### 主动触发一次压缩的脚本
|
|
89
101
|
|
|
@@ -108,12 +120,11 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
108
120
|
|
|
109
121
|
### 对世界工作区以外的影响
|
|
110
122
|
|
|
111
|
-
|
|
123
|
+
只有下面这一项会作用到世界工作区以外的会话:
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
2. **只留对话的压缩**(装上插件后首次启动默认换上,可在配置里写 `replaceCompaction: false` 关掉):它替换的是整个 profile 的压缩方式,其他工作区的会话压缩时也会去掉工具调用过程,只留一段对话摘要。写代码等依赖工具过程的会话,压缩后会丢掉这些细节。
|
|
125
|
+
- **只留对话的压缩**(装上插件后首次启动默认换上,可在配置里写 `replaceCompaction: false` 关掉):它替换的是整个 profile 的压缩方式,其他工作区的会话压缩时也会去掉工具调用过程,只留一段对话摘要。写代码等依赖工具过程的会话,压缩后会丢掉这些细节。
|
|
115
126
|
|
|
116
|
-
|
|
127
|
+
除此之外,人设、记忆、世界提示词、世界线、工具、通道和归档都不会进入工作区以外的会话。人设在 0.7.1 及以前不限工作区,所有用同一预设的会话都会带上;现在和其他部分一样只进她的工作区。以前在工作区外的窗口里和她聊、想继续带着人设的,把那个窗口挪进她的工作区。
|
|
117
128
|
|
|
118
129
|
### 看到“会话已离开世界工作区,请重新发送”
|
|
119
130
|
|
|
@@ -127,7 +138,7 @@ powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\enable-tool-free-c
|
|
|
127
138
|
|
|
128
139
|
### 微信支持版本
|
|
129
140
|
|
|
130
|
-
|
|
141
|
+
目前适配 **Windows x64 微信的指定构建**。适配器核对 `Weixin.dll` 的文件大小和 SHA256,只有两项均匹配才加载原生桥。支持的构建及各版本的实测范围见 [微信模块](src/ecosystem/wechat/windows/README.md)。
|
|
131
142
|
|
|
132
143
|
### 微信风控与账号风险
|
|
133
144
|
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
### 记得:像人一样记
|
|
19
19
|
|
|
20
|
-
-
|
|
20
|
+
- **近期记忆**:你们最近数轮的对话原文,每次开始对话、每次压缩之后,以及一个窗口隔了很久(默认 24 小时,控制台可改)再开口时,都放在她眼前,谁、什么时候、说了什么,一字不差。轮数在控制台里填,默认 200。
|
|
21
21
|
- **日记**:人生里重要的事,她自己写进日记,一天一篇。这是她的长期记忆。
|
|
22
22
|
- **我是谁**:她写给自己的一份自述,随着她变化而改写。每晚回顾前,插件会留一份当时的版本,改过的都找得回来。
|
|
23
23
|
- **范围内的原文留着**:按天归档用户和助手的正文。近期记忆以外的事,她可以自己去翻。
|
|
@@ -56,7 +56,7 @@ DSH 设置里的「世界控制台」:
|
|
|
56
56
|
- **归档范围**:默认 `workspace`,归档家所在工作区的普通会话,包含独立微信群会话;`home` 仅当前家会话。保存范围后提示重启,重启前沿用原范围。启动时分页回扫所选范围内的会话日志,按消息实际时间重选最近配置轮数,下次请求前替换旧记忆块;没有时间过期。旧归档保留,范围外记录不再注入。旧配置 `world` 迁为 `workspace`。
|
|
57
57
|
- **注入范围**:世界记忆、世界提示词、世界线工具和微信/QQ 通道仅进入世界工作区内匹配预设的普通会话,其他工作区即使用相同预设也不会收到。归档选为 `home` 时,同工作区的其他会话仍可读取家记忆。
|
|
58
58
|
|
|
59
|
-
>
|
|
59
|
+
> 对世界工作区以外的会话,只有一项有影响:只留对话的压缩。详情见 [注意事项](NOTES.md#对世界工作区以外的影响)。
|
|
60
60
|
|
|
61
61
|
### 注意事项
|
|
62
62
|
|
package/client/index.js
CHANGED
|
@@ -306,19 +306,25 @@ window.__ModuleLoader__.load({
|
|
|
306
306
|
h('button', { className: 'dw-btn', onClick: save }, '保存')),
|
|
307
307
|
h(Status, { msg: msg }))
|
|
308
308
|
}
|
|
309
|
-
/** 记忆块带最近几轮:默认 200
|
|
309
|
+
/** 记忆块带最近几轮:默认 200,下次开始对话或压缩之后生效;隔多少小时没开口就重新读:默认 24,下一轮生效。 */
|
|
310
310
|
function Memory(props) {
|
|
311
311
|
var mem = props.mem, window_ = mem && mem.windowTurns || 200
|
|
312
312
|
var activeScope = mem && mem.archiveScope || 'workspace'
|
|
313
313
|
var scopeNames = { home: '仅家会话', workspace: '家所在工作区' }
|
|
314
314
|
var scopeState = useState(mem && mem.selectedArchiveScope || activeScope), scope = scopeState[0], setScope = scopeState[1]
|
|
315
315
|
var draftState = useState(String(window_)), draft = draftState[0], setDraft = draftState[1]
|
|
316
|
+
var coldState = useState(String(mem && mem.coldHours || 24)), cold = coldState[0], setCold = coldState[1]
|
|
316
317
|
var msgState = useState(''), msg = msgState[0], setMsg = msgState[1]
|
|
317
318
|
function save() {
|
|
318
319
|
var text = String(draft).trim(), value = text === '' ? null : Number(text)
|
|
319
320
|
if (value !== null && !(Number.isInteger(value) && value >= 1)) { setMsg('请填一个不小于 1 的整数,留空恢复默认 200'); return }
|
|
320
321
|
post('memory', { turns: value }).then(function () { setMsg('已保存。下次开始对话或压缩之后生效。'); if (value === null) setDraft('200'); if (props.onSaved) props.onSaved() }, failedTo(setMsg))
|
|
321
322
|
}
|
|
323
|
+
function saveCold() {
|
|
324
|
+
var text = String(cold).trim(), value = text === '' ? null : Number(text)
|
|
325
|
+
if (value !== null && !(Number.isInteger(value) && value >= 1 && value <= 720)) { setMsg('请填 1 到 720 之间的整数小时,留空恢复默认 24'); return }
|
|
326
|
+
post('memory', { coldHours: value }).then(function () { setMsg('已保存。各窗口从下一轮开始按新时长判断。'); if (value === null) setCold('24'); if (props.onSaved) props.onSaved() }, failedTo(setMsg))
|
|
327
|
+
}
|
|
322
328
|
function saveScope() {
|
|
323
329
|
post('archive-scope', { scope: scope }).then(function (result) {
|
|
324
330
|
setMsg(result.restartRequired ? '已保存。请重启 DSH,启动后按新范围和消息时间重建记忆块。' : '归档范围已保存。')
|
|
@@ -338,6 +344,10 @@ window.__ModuleLoader__.load({
|
|
|
338
344
|
h('div', { key: 's', className: 'dw-setting' },
|
|
339
345
|
h('input', { type: 'text', inputMode: 'numeric', 'aria-label': '记忆带最近几轮', placeholder: '最近几轮,留空为 200', value: draft, onChange: function (e) { setDraft(e.target.value); setMsg('') } }),
|
|
340
346
|
h('button', { className: 'dw-btn', onClick: save }, '保存')),
|
|
347
|
+
h('div', { key: 'cd', className: 'dw-muted' }, '一个窗口隔这么久再开口,就重新读一遍记忆块、人设和「我是谁」;正在聊的窗口不受影响。'),
|
|
348
|
+
h('div', { key: 'c', className: 'dw-setting' },
|
|
349
|
+
h('input', { type: 'text', inputMode: 'numeric', 'aria-label': '久未开口后重新读取(小时)', placeholder: '小时,留空为 24', value: cold, onChange: function (e) { setCold(e.target.value); setMsg('') } }),
|
|
350
|
+
h('button', { className: 'dw-btn', onClick: saveCold }, '保存')),
|
|
341
351
|
h(Status, { key: 'x', msg: msg }),
|
|
342
352
|
] : h('div', { className: 'dw-muted' }, '—'))
|
|
343
353
|
}
|
|
@@ -888,7 +898,7 @@ window.__ModuleLoader__.load({
|
|
|
888
898
|
return ctx.slots.register({ name: 'settings.section', id: 'world-console', order: 28, label: '世界控制台' }, function () { return h(Console) })
|
|
889
899
|
})
|
|
890
900
|
}
|
|
891
|
-
Object.defineProperty(exports, '__test', { value: { MemorySearch: MemorySearch, latest: latest, searchMemory: searchMemory, memoryQuery: memoryQuery, dayStartIso: dayStartIso, WorkspacePermission: WorkspacePermission, CompactAfterReview: CompactAfterReview, Schedule: Schedule, Modules: Modules, HomeApply: HomeApply, PhotoAlbum: PhotoAlbum, Wechat: Wechat, Activity: Activity, Diary: Diary, Qq: Qq, Panel: Panel, View: View, Overview: Overview, PersonaEditor: PersonaEditor, PromptEditor: PromptEditor, loadSnapshot: loadSnapshot, renderPersona: renderPersona }, enumerable: false })
|
|
901
|
+
Object.defineProperty(exports, '__test', { value: { Memory: Memory, MemorySearch: MemorySearch, latest: latest, searchMemory: searchMemory, memoryQuery: memoryQuery, dayStartIso: dayStartIso, WorkspacePermission: WorkspacePermission, CompactAfterReview: CompactAfterReview, Schedule: Schedule, Modules: Modules, HomeApply: HomeApply, PhotoAlbum: PhotoAlbum, Wechat: Wechat, Activity: Activity, Diary: Diary, Qq: Qq, Panel: Panel, View: View, Overview: Overview, PersonaEditor: PersonaEditor, PromptEditor: PromptEditor, loadSnapshot: loadSnapshot, renderPersona: renderPersona }, enumerable: false })
|
|
892
902
|
return exports
|
|
893
903
|
},
|
|
894
904
|
})
|
package/lib/console/routes.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export interface ConsoleActions {
|
|
|
41
41
|
setDailyBudget(yuan: number | undefined): void;
|
|
42
42
|
/** Turns in her memory block; undefined goes back to the default. */
|
|
43
43
|
setMemoryTurns(turns: number | undefined): void;
|
|
44
|
+
/** Hours of silence after which a session re-reads her memory and prompt; undefined goes back to the default. */
|
|
45
|
+
setColdHours(hours: number | undefined): void;
|
|
44
46
|
setArchiveScope(scope: MemoryArchiveScope): boolean;
|
|
45
47
|
setWorkspacePermission(permission: string): void;
|
|
46
48
|
/** Whether the evening look back is followed by applying and compacting her home (on unless turned off). */
|
package/lib/console/routes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsonObject, knownHost, readBody, sendJson } from "../http.js";
|
|
2
2
|
import { PERSONA_LAYERS } from "../persona.js";
|
|
3
|
-
import { validTurns, validWechatBuffer, validWechatContext, validWorkspacePermission, MAX_WECHAT_BUFFER_SECONDS, MAX_WECHAT_CONTEXT } from "../worldSwitch.js";
|
|
3
|
+
import { validColdHours, validTurns, validWechatBuffer, MAX_COLD_HOURS, validWechatContext, validWorkspacePermission, MAX_WECHAT_BUFFER_SECONDS, MAX_WECHAT_CONTEXT } from "../worldSwitch.js";
|
|
4
4
|
import { validArchiveScope } from "../archiveSelection.js";
|
|
5
5
|
import { validClockTime } from "../life/alarm.js";
|
|
6
6
|
import { MemoryError } from "../memory.js";
|
|
@@ -68,10 +68,17 @@ async function write(actions, path, body) {
|
|
|
68
68
|
return ok();
|
|
69
69
|
}
|
|
70
70
|
case '/console/memory': {
|
|
71
|
-
const turns = body?.turns;
|
|
72
|
-
if (turns !== null && !validTurns(turns))
|
|
71
|
+
const turns = body?.turns, coldHours = body?.coldHours;
|
|
72
|
+
if (turns !== undefined && turns !== null && !validTurns(turns))
|
|
73
73
|
return bad('turns must be a whole number of at least 1, or null');
|
|
74
|
-
|
|
74
|
+
if (coldHours !== undefined && coldHours !== null && !validColdHours(coldHours))
|
|
75
|
+
return bad(`coldHours must be a whole number from 1 to ${MAX_COLD_HOURS}, or null`);
|
|
76
|
+
if (turns === undefined && coldHours === undefined)
|
|
77
|
+
return bad('nothing to change');
|
|
78
|
+
if (turns !== undefined)
|
|
79
|
+
actions.setMemoryTurns(turns ?? undefined);
|
|
80
|
+
if (coldHours !== undefined)
|
|
81
|
+
actions.setColdHours(coldHours ?? undefined);
|
|
75
82
|
return ok();
|
|
76
83
|
}
|
|
77
84
|
case '/console/wechat': {
|
|
@@ -30,6 +30,8 @@ export interface SnapshotDeps {
|
|
|
30
30
|
dailyBudget(): number | undefined;
|
|
31
31
|
/** Turns her memory block carries. */
|
|
32
32
|
memoryTurns(): number;
|
|
33
|
+
/** Hours of silence after which a session re-reads her memory block and prompt. */
|
|
34
|
+
coldHours?(): number;
|
|
33
35
|
selectedArchiveScope?(): MemoryArchiveScope;
|
|
34
36
|
compactAfterReview?(): boolean;
|
|
35
37
|
/** The evening look back and the morning wake, with what an empty field goes back to; absent without the life line. */
|
package/lib/console/snapshot.js
CHANGED
|
@@ -31,7 +31,7 @@ export function consoleSources(deps) {
|
|
|
31
31
|
life: life ? { homeSessionId: life.homeSessionId, status: home ? home.status : 'cold', alarm: life.alarm, review: life.review, recentWakes: lifeStore?.wakes().slice(-5).reverse() ?? [] } : null,
|
|
32
32
|
homeApply: deps.homeApply?.() ?? null,
|
|
33
33
|
health: [...(life?.faults ?? []), ...deps.faults()],
|
|
34
|
-
memory: { index: deps.longTerm?.status() ?? null, turns: turns.length, windowTurns: window, archiveScope, selectedArchiveScope, restartRequired: archiveScope !== selectedArchiveScope, approxTokens: estimateTokens(renderHistory(turns, config.timeZone, deps.names(), archiveScope === 'home')), oldest: turns.at(-1)?.messages[0]?.occurredAt, ...archive.stats() },
|
|
34
|
+
memory: { index: deps.longTerm?.status() ?? null, turns: turns.length, windowTurns: window, coldHours: deps.coldHours?.() ?? null, archiveScope, selectedArchiveScope, restartRequired: archiveScope !== selectedArchiveScope, approxTokens: estimateTokens(renderHistory(turns, config.timeZone, deps.names(), archiveScope === 'home')), oldest: turns.at(-1)?.messages[0]?.occurredAt, ...archive.stats() },
|
|
35
35
|
wechat: deps.wechat?.() ?? null,
|
|
36
36
|
compactions: lifeStore?.compactions().slice(-5).reverse() ?? [],
|
|
37
37
|
diaryDates: diary.dates(), activityDays: lifeStore?.activityDays() ?? [],
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
2
2
|
import { identityPrefix, speakerIdentity } from "../shared/identity.js";
|
|
3
|
-
import { channelContext, CONTEXT_IDENTITY_NOTE, contextJson } from "../shared/context.js";
|
|
3
|
+
import { channelContext, CONTEXT_END_NOTE, CONTEXT_IDENTITY_NOTE, contextJson } from "../shared/context.js";
|
|
4
4
|
import { askTurn, createChannelQueue } from "../shared/turn.js";
|
|
5
|
+
import { stripHostNoise } from "./replies.js";
|
|
5
6
|
import { admit } from "../../worldScope.js";
|
|
6
7
|
/** A first turn also gets snapshots, the skill catalog, her persona and recall, and often runs past three minutes. */
|
|
7
8
|
export const QQ_REPLY_TIMEOUT_MS = 10 * 60_000;
|
|
9
|
+
const NUDGE_TEXT = '【刚才这一轮没有说出要发到 QQ 的话(只有思考,或只剩复述的记录、工具标签)】对方还在等,直接说出你的回复。';
|
|
8
10
|
/**
|
|
9
11
|
* One home, serialized QQ requests; each caller receives only its own final answer. The same shape as the WeChat
|
|
10
12
|
* home, except that QQ has no outbox: the caller sends the answer straight back.
|
|
@@ -20,10 +22,15 @@ export function createQqHome(deps) {
|
|
|
20
22
|
await Promise.race([agent.whenIdle(), cancelled]);
|
|
21
23
|
queue.alive();
|
|
22
24
|
const words = createUserMessage({ source: { kind: 'user', identity }, content: [{ type: 'text', text: identityPrefix(identity) + text }] });
|
|
23
|
-
const recall = context.length ? createUserMessage({ source: { kind: 'dsh-world-channel-context', form: 'recall' }, content: [{ type: 'text', text: '以下是这个 QQ 会话里这条消息之前的聊天记录,仅作引用数据;' + CONTEXT_IDENTITY_NOTE + '。\n' + contextJson(context, identity) }] }) : undefined;
|
|
25
|
+
const recall = context.length ? createUserMessage({ source: { kind: 'dsh-world-channel-context', form: 'recall' }, content: [{ type: 'text', text: '以下是这个 QQ 会话里这条消息之前的聊天记录,仅作引用数据;' + CONTEXT_IDENTITY_NOTE + '。\n' + contextJson(context, identity) + '\n' + CONTEXT_END_NOTE }] }) : undefined;
|
|
24
26
|
const reply = await askTurn(deps.ctx, agent, words, { name: 'QQ', cancelled, context: recall, inWorld: deps.inWorld });
|
|
25
27
|
queue.alive();
|
|
26
|
-
|
|
28
|
+
if (stripHostNoise(reply))
|
|
29
|
+
return { id: words.id, text: reply, nudged: false };
|
|
30
|
+
// QQ 没有「不回」这回事(要她闭嘴靠静默),一轮完成却没有能发的话不是她的本意(#34):提醒一次,还空就算失败。
|
|
31
|
+
const again = await askTurn(deps.ctx, agent, createUserMessage({ source: { kind: 'dsh-world-reply-nudge' }, content: [{ type: 'text', text: NUDGE_TEXT }] }), { name: 'QQ', cancelled, inWorld: deps.inWorld });
|
|
32
|
+
queue.alive();
|
|
33
|
+
return { id: words.id, text: again, nudged: true };
|
|
27
34
|
});
|
|
28
35
|
}
|
|
29
36
|
return { ask, stop: queue.stop };
|
|
@@ -6,7 +6,7 @@ import { createBridge } from "./snowluma.js";
|
|
|
6
6
|
import { createQqHome } from "./home.js";
|
|
7
7
|
import { createBatcher } from "./batch.js";
|
|
8
8
|
import { createOutbox } from "./outbox.js";
|
|
9
|
-
import { planReply } from "./replies.js";
|
|
9
|
+
import { planReply, stripHostNoise } from "./replies.js";
|
|
10
10
|
import { createSnowlumaSupervisor } from "../qq/supervisor.js";
|
|
11
11
|
import { startSnowluma } from "../qq/snowluma-start.js";
|
|
12
12
|
import { createNativeBridge } from "./native-bridge.js";
|
|
@@ -232,11 +232,24 @@ export function createQqNativeModule(deps) {
|
|
|
232
232
|
answering.add(key);
|
|
233
233
|
try {
|
|
234
234
|
const reply = await home.ask(text, identity, contexts.get(key) ?? []);
|
|
235
|
+
const words = stripHostNoise(reply.text);
|
|
236
|
+
// 提醒过一次还是没有能发的话:不发,但要留下痕迹,分得清「她没说出话」和「路丢了」(#34);
|
|
237
|
+
// 只剩复述的聊天记录、工具标签这些(#35)也一样。
|
|
238
|
+
if (!words) {
|
|
239
|
+
stats.failed += 1;
|
|
240
|
+
stats.lastError = reply.text.trim()
|
|
241
|
+
? '回复只有复述的聊天记录、来源头或工具标签,提醒过一次,过滤后仍没有能发的正文'
|
|
242
|
+
: '回复为空:提醒过一次,仍没有说出正文(可能只有思考)';
|
|
243
|
+
deps.logger.warn(`QQ 回复 ${key} ${reply.text.trim() ? '过滤后为空' : '为空'},提醒过一次,没有投递`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (reply.nudged)
|
|
247
|
+
deps.logger.info(`QQ 回复 ${key} 第一次没有能发的话,提醒后说出了`);
|
|
235
248
|
// 她那句话记成她自己说的:不然后面拿这段上下文问她「刚才聊到哪了」时,她说过的会被当成对方说的。
|
|
249
|
+
// 记过滤后的:复述的记录若回到上下文里,下一轮她更容易接着念。
|
|
236
250
|
const herIdentity = speakerIdentity({ channel: 'qq', accountId: identity.accountId, speakerId: `qq:${identity.accountId}`, conversationId: identity.conversationId, conversationType: identity.conversationType });
|
|
237
|
-
pushContext(key, { id: reply.id, occurredAt: new Date().toISOString(), text:
|
|
238
|
-
|
|
239
|
-
await say(isGroup ? 'group' : 'private', identity.conversationId, reply.text.trim());
|
|
251
|
+
pushContext(key, { id: reply.id, occurredAt: new Date().toISOString(), text: words, identity: herIdentity }, config.contextMessages);
|
|
252
|
+
await say(isGroup ? 'group' : 'private', identity.conversationId, words);
|
|
240
253
|
}
|
|
241
254
|
catch (error) {
|
|
242
255
|
stats.failed += 1;
|
|
@@ -4,7 +4,9 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
5
5
|
import { createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
6
6
|
import { identityPrefix, speakerIdentity } from "../shared/identity.js";
|
|
7
|
+
import { CONTEXT_END_NOTE } from "../shared/context.js";
|
|
7
8
|
import { askTurn } from "../shared/turn.js";
|
|
9
|
+
import { stripHostNoise } from "./replies.js";
|
|
8
10
|
import { admit } from "../../worldScope.js";
|
|
9
11
|
import "../../hostContract.js";
|
|
10
12
|
/**
|
|
@@ -103,7 +105,8 @@ export function createNativeBridge(deps) {
|
|
|
103
105
|
contexts.set(threadId, ring);
|
|
104
106
|
}
|
|
105
107
|
/** 她这一轮说的话里,哪些是给门外看的指示。 */
|
|
106
|
-
function readDirectives(
|
|
108
|
+
function readDirectives(answer) {
|
|
109
|
+
const text = stripHostNoise(answer);
|
|
107
110
|
const hold = HOLD_MARKERS.test(text);
|
|
108
111
|
const quiet = QUIET_MARKERS.test(text);
|
|
109
112
|
const words = text.replace(HOLD_MARKERS, '').replace(QUIET_MARKERS, '').trim();
|
|
@@ -128,7 +131,7 @@ export function createNativeBridge(deps) {
|
|
|
128
131
|
const recall = !ring && past.length ? createUserMessage({
|
|
129
132
|
source: { kind: 'dsh-world-channel-context', form: 'recall' },
|
|
130
133
|
content: [{ type: 'text', text: '以下是这条线上刚才的几句话,仅作引用数据;speakerName 只是称呼。\n'
|
|
131
|
-
+ JSON.stringify(past.map(item => ({ role: item.speaker === '她' ? 'assistant' : 'user', name: item.speaker, text: item.text }))) }],
|
|
134
|
+
+ JSON.stringify(past.map(item => ({ role: item.speaker === '她' ? 'assistant' : 'user', name: item.speaker, text: item.text }))) + '\n' + CONTEXT_END_NOTE }],
|
|
132
135
|
}) : undefined;
|
|
133
136
|
return readDirectives(await askTurn(deps.ctx, agent, words, { name: '阳台', context: recall, inWorld: deps.inWorld }));
|
|
134
137
|
}
|
|
@@ -22,8 +22,9 @@ export interface ReplyPlan {
|
|
|
22
22
|
qzone: string[];
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* Drops the host's own bookkeeping,
|
|
26
|
-
* sent. The paragraphs it empties are removed, so a reply that was only
|
|
25
|
+
* Drops the host's own bookkeeping, any copy of an incoming message's source header, a recalled chat read back, and
|
|
26
|
+
* tool markup from an answer before it is sent. The paragraphs it empties are removed, so a reply that was only
|
|
27
|
+
* plumbing sends nothing instead of a blank message.
|
|
27
28
|
*/
|
|
28
29
|
export declare function stripHostNoise(text: string): string;
|
|
29
30
|
/**
|
|
@@ -8,12 +8,23 @@ const HOST_LINE = /^\s*(?:Time sampled|Browser time zone|Elapsed since|Elapsed f
|
|
|
8
8
|
/** Transport refs that leak into her prose: `text">m00123` anywhere, a bare `m00123` at the end of a line. */
|
|
9
9
|
const HOST_FRAGMENT = /[ \t]*text">m\d{5}\b|[ \t]*\bm\d{5}[ \t]*$/gm;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* A tool call the model wrote out as text instead of calling (DeepSeek's `<|DSML|…>` markup). Everything from the
|
|
12
|
+
* first tag on is that call, not speech (#35).
|
|
13
|
+
*/
|
|
14
|
+
const TOOL_MARKUP = /<\/?[||]+\s*DSML\s*[||]+[\s\S]*$/;
|
|
15
|
+
/**
|
|
16
|
+
* The plugin's own recalled chat read back aloud (#35): a framing line (each carries 仅作引用数据), a line that is the
|
|
17
|
+
* recalled JSON (a role or a speakerId inside brackets), or a bare transcript role label.
|
|
18
|
+
*/
|
|
19
|
+
const RECALL_LINE = /仅作引用数据|^\s*[[{].*"(?:role|speakerId)"\s*:.*[}\]]\s*$|^\s*(?:user|assistant)\s*$/;
|
|
20
|
+
/**
|
|
21
|
+
* Drops the host's own bookkeeping, any copy of an incoming message's source header, a recalled chat read back, and
|
|
22
|
+
* tool markup from an answer before it is sent. The paragraphs it empties are removed, so a reply that was only
|
|
23
|
+
* plumbing sends nothing instead of a blank message.
|
|
13
24
|
*/
|
|
14
25
|
export function stripHostNoise(text) {
|
|
15
|
-
const kept = text.replace(/\r\n/g, '\n').replace(HOST_FRAGMENT, '').split('\n')
|
|
16
|
-
.filter(line => !HOST_LINE.test(line) && !IDENTITY_HEADER_LINE.test(line.trim()));
|
|
26
|
+
const kept = text.replace(/\r\n/g, '\n').replace(TOOL_MARKUP, '').replace(HOST_FRAGMENT, '').split('\n')
|
|
27
|
+
.filter(line => !HOST_LINE.test(line) && !IDENTITY_HEADER_LINE.test(line.trim()) && !RECALL_LINE.test(line));
|
|
17
28
|
return kept.join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
18
29
|
}
|
|
19
30
|
/**
|
|
@@ -26,4 +26,9 @@ export declare function channelContext(value: unknown, current: SpeakerIdentity,
|
|
|
26
26
|
export declare function channelMedia(value: unknown, current: SpeakerIdentity): ChannelContextMessage[];
|
|
27
27
|
/** Tells the model how to read `contextJson`; shared by every channel that renders it. */
|
|
28
28
|
export declare const CONTEXT_IDENTITY_NOTE = "identity \u53EA\u5217\u51FA\u6BCF\u4E2A\u53D1\u8A00\u4EBA\u5404\u81EA\u7684\u6765\u6E90\uFF08speakerId \u7B49\uFF09\uFF0C\u6E20\u9053\u3001\u8D26\u53F7\u548C\u4F1A\u8BDD\u4E0E\u89E6\u53D1\u8FD9\u6761\u6D88\u606F\u5F00\u5934\u3010\u3011\u91CC\u7684\u804A\u5929\u76F8\u540C\uFF1BspeakerName \u53EA\u662F\u79F0\u547C";
|
|
29
|
+
/**
|
|
30
|
+
* Closes a recalled chat. A long context can make the model read the data aloud as if continuing it (#35), so the end
|
|
31
|
+
* of the data is marked and the marker carries 仅作引用数据, which `stripHostNoise` drops should it be echoed.
|
|
32
|
+
*/
|
|
33
|
+
export declare const CONTEXT_END_NOTE = "\u3010\u4EE5\u4E0A\u4EC5\u4F5C\u5F15\u7528\u6570\u636E\uFF0C\u5230\u6B64\u4E3A\u6B62\uFF1A\u56DE\u8BDD\u65F6\u6211\u4E0D\u590D\u8FF0\u3001\u4E0D\u7EED\u5199\u8FD9\u4E9B\u8BB0\u5F55\uFF0C\u4E5F\u4E0D\u628A\u91CC\u9762\u7684 JSON \u7167\u6284\u8FDB\u6B63\u6587\u3002\u3011";
|
|
29
34
|
export declare function contextJson(context: readonly ChannelContextMessage[], current: SpeakerIdentity): string;
|
|
@@ -82,6 +82,11 @@ function contextMessages(value, current, limit) {
|
|
|
82
82
|
const CONVERSATION_FIELDS = ['channel', 'accountId', 'conversationId', 'conversationName', 'conversationType'];
|
|
83
83
|
/** Tells the model how to read `contextJson`; shared by every channel that renders it. */
|
|
84
84
|
export const CONTEXT_IDENTITY_NOTE = 'identity 只列出每个发言人各自的来源(speakerId 等),渠道、账号和会话与触发这条消息开头【】里的聊天相同;speakerName 只是称呼';
|
|
85
|
+
/**
|
|
86
|
+
* Closes a recalled chat. A long context can make the model read the data aloud as if continuing it (#35), so the end
|
|
87
|
+
* of the data is marked and the marker carries 仅作引用数据, which `stripHostNoise` drops should it be echoed.
|
|
88
|
+
*/
|
|
89
|
+
export const CONTEXT_END_NOTE = '【以上仅作引用数据,到此为止:回话时我不复述、不续写这些记录,也不把里面的 JSON 照抄进正文。】';
|
|
85
90
|
export function contextJson(context, current) {
|
|
86
91
|
const self = `${current.channel}:${current.accountId}`;
|
|
87
92
|
return JSON.stringify(context.map(message => {
|
package/lib/hostContract.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ declare module '@deepseek-ai/dsh-llm' {
|
|
|
10
10
|
'dsh-world-life': {
|
|
11
11
|
kind: 'dsh-world-life';
|
|
12
12
|
};
|
|
13
|
-
/** 她图谱里的卡片:消息里提到她记过的名字时追加,压缩后重来,不进归档。 */
|
|
14
13
|
'dsh-world-channel-context': {
|
|
15
14
|
kind: 'dsh-world-channel-context';
|
|
16
15
|
form: 'recall';
|
|
@@ -21,6 +20,10 @@ declare module '@deepseek-ai/dsh-llm' {
|
|
|
21
20
|
kind: 'dsh-world-outside';
|
|
22
21
|
form: 'ring';
|
|
23
22
|
};
|
|
23
|
+
/** QQ 的一轮完成了却没说出能发的话:提醒她对方还在等,不是谁发来的话,不进归档。 */
|
|
24
|
+
'dsh-world-reply-nudge': {
|
|
25
|
+
kind: 'dsh-world-reply-nudge';
|
|
26
|
+
};
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
export {};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { existsSync, readFileSync, rmSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
// DSH's HMR reconciles the profile once at every start and drops, as failed imports, the profile modules whose import
|
|
4
|
+
// has not finished (dsh-hmr `reconcileProfile`). The QQ module is imported later and is the only way to `ws`, a CommonJS
|
|
5
|
+
// package: dropped halfway, Node fails it with ERR_INTERNAL_ASSERTION and QQ switched on at boot never starts. Loaded
|
|
6
|
+
// with the plugin, `ws` is complete before that reconciliation runs.
|
|
7
|
+
import 'ws';
|
|
3
8
|
import z from '@deepseek-ai/schemastery';
|
|
4
9
|
import { resolveDshHome } from '@deepseek-ai/dsh-home-paths';
|
|
5
10
|
import { createBridge } from "./ecosystem/bridge/bridge.js";
|
|
@@ -151,12 +156,24 @@ export async function apply(ctx, config) {
|
|
|
151
156
|
const memoryHealth = () => memoryService.status().failures.map(failure => `记忆来源 ${failure.sourceId}:${failure.message}`);
|
|
152
157
|
let memory;
|
|
153
158
|
let stopLifeLine;
|
|
159
|
+
/**
|
|
160
|
+
* A memory line that cannot start is a fault, never a failed plugin: the console must still open to say so, and
|
|
161
|
+
* the life line and channels run on. Stopping and starting the world from the console tries again.
|
|
162
|
+
*/
|
|
154
163
|
async function startMemory(fresh) {
|
|
155
164
|
if (memory)
|
|
156
165
|
return;
|
|
157
166
|
const prompt = { file: worldPromptFile, persona: personaFile, conversationsDir: join(worldDir, 'conversations'), names: names(), memoryTools: true, ...(config.life ? { life: options } : {}) };
|
|
158
|
-
|
|
159
|
-
|
|
167
|
+
const runtime = createWorldRuntime(ctx, { ...memoryConfig, selfFile }, store, { prompt, names, isHome: id => isHome(id), archiveSession, inWorkspace, memory: memoryService }, power.memoryTurns, power.coldHours);
|
|
168
|
+
try {
|
|
169
|
+
await runtime.start({ fresh });
|
|
170
|
+
memory = runtime;
|
|
171
|
+
faults.clear('memory');
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
faults.set('memory', `记忆线没能启动:${errorText(error)}`);
|
|
175
|
+
ctx.logger.error(error);
|
|
176
|
+
}
|
|
160
177
|
}
|
|
161
178
|
async function stopMemory() {
|
|
162
179
|
const running = memory;
|
|
@@ -377,7 +394,7 @@ export async function apply(ctx, config) {
|
|
|
377
394
|
if (config.bridge)
|
|
378
395
|
lifeCtx.effect(() => webServer.register(compactRoute(() => bridge, () => !power.running() || !life ? '请先启动世界生活线' : homeApply.request(), config.allowedHosts)), 'dsh-world compact route');
|
|
379
396
|
// Her album lives in her room, so the console shows it whether or not the life line is running.
|
|
380
|
-
const sources = consoleSources({ ctx: lifeCtx, config: memoryConfig, archive: store, longTerm: memoryService, names, ...(lifeStore ? { lifeStore } : {}), life: () => life, homeApply: homeApply.snapshot, compactAfterReview: power.compactAfterReview, ...(config.life ? { schedule: () => ({ review: power.reviewTime(), wake: power.wakeTime(), defaults: { review: DEFAULT_REVIEW_TIME, wake: config.fallbackWakeTime } }) } : {}), photos, diaryDir: options.diaryDir, running: power.running, dailyBudget: power.dailyBudget, memoryTurns: power.memoryTurns, selectedArchiveScope: power.selectedArchiveScope, workspacePermissions: permissions.snapshot, wechat: () => wechat ? { ...wechat.status(), adapter: adapter?.status() ?? null } : undefined, archiveSession, native: () => qqNative?.status() ?? null,
|
|
397
|
+
const sources = consoleSources({ ctx: lifeCtx, config: memoryConfig, archive: store, longTerm: memoryService, names, ...(lifeStore ? { lifeStore } : {}), life: () => life, homeApply: homeApply.snapshot, compactAfterReview: power.compactAfterReview, ...(config.life ? { schedule: () => ({ review: power.reviewTime(), wake: power.wakeTime(), defaults: { review: DEFAULT_REVIEW_TIME, wake: config.fallbackWakeTime } }) } : {}), photos, diaryDir: options.diaryDir, running: power.running, dailyBudget: power.dailyBudget, memoryTurns: power.memoryTurns, coldHours: power.coldHours, selectedArchiveScope: power.selectedArchiveScope, workspacePermissions: permissions.snapshot, wechat: () => wechat ? { ...wechat.status(), adapter: adapter?.status() ?? null } : undefined, archiveSession, native: () => qqNative?.status() ?? null,
|
|
381
398
|
modules: () => ({ wechat: { available: config.wechat, enabled: power.wechatEnabled(), running: wechat !== undefined }, qq: { available: Boolean(config.qqNative?.enabled), enabled: power.qqEnabled(), running: qqNative !== undefined, ...(qqSdk.needsRestart() ? { restartRequired: true } : {}) } }), faults: () => [...faults.list(), ...(adapter?.status().error ? [`微信适配器:${adapter.status().error}`] : []), ...(memory?.faults() ?? []), ...(bridge?.faults() ?? []), ...memoryHealth()] });
|
|
382
399
|
const actions = {
|
|
383
400
|
async start() {
|
|
@@ -412,6 +429,7 @@ export async function apply(ctx, config) {
|
|
|
412
429
|
savePersona: persona => { writePersona(personaFile, { ...readPersona(personaFile), ...persona }); sources.invalidate(); },
|
|
413
430
|
setDailyBudget: yuan => { power.setDailyBudget(yuan); sources.invalidate(); },
|
|
414
431
|
setMemoryTurns: turns => { power.setMemoryTurns(turns); sources.invalidate(); },
|
|
432
|
+
setColdHours: hours => { power.setColdHours(hours); sources.invalidate(); },
|
|
415
433
|
setWorkspacePermission: permission => { permissions.set(permission); sources.invalidate(); },
|
|
416
434
|
setCompactAfterReview: on => { power.setCompactAfterReview(on); sources.invalidate(); },
|
|
417
435
|
setSchedule: next => { power.setSchedule(next); life?.reschedule(); sources.invalidate(); },
|
package/lib/promptSection.d.ts
CHANGED
|
@@ -14,11 +14,12 @@ export interface WorldPromptSource {
|
|
|
14
14
|
memory?: import('./memory.ts').MemoryService;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* Her persona
|
|
18
|
-
*
|
|
17
|
+
* Her persona and the world prompt both reach only sessions of her preset inside the world's workspace, and come and
|
|
18
|
+
* go together as a session enters or leaves it: the preset alone is DSH's default `standard` for most setups, so it
|
|
19
|
+
* would turn every unrelated session into her (#37). Both are sections of the session's system prompt so she sees them on every
|
|
19
20
|
* request. They are read when the session opens and again after each successful compaction (the host assembles
|
|
20
|
-
* the system prompt before pre-step, so the refresh happens on compaction/end)
|
|
21
|
-
* stays in the provider-cached prefix. Whether the session is her home is asked per request.
|
|
21
|
+
* the system prompt before pre-step, so the refresh happens on compaction/end), when a cold session speaks again
|
|
22
|
+
* (`coldHours` in `runtime.ts`, on turn/start) or on explicit console application, so the prompt stays in the provider-cached prefix. Whether the session is her home is asked per request.
|
|
22
23
|
*
|
|
23
24
|
* Her persona takes the place of DeepSeek Harness's stock identity line, but never of a persona someone has set: it is its own
|
|
24
25
|
* section placed right after the host's persona slot, so a system persona the deployment or her preset already has stays
|
package/lib/promptSection.js
CHANGED
|
@@ -6,11 +6,12 @@ import { reassembleOnChange } from "./worldScope.js";
|
|
|
6
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
7
|
const HARNESS_IDENTITY = 'harness:identity';
|
|
8
8
|
/**
|
|
9
|
-
* Her persona
|
|
10
|
-
*
|
|
9
|
+
* Her persona and the world prompt both reach only sessions of her preset inside the world's workspace, and come and
|
|
10
|
+
* go together as a session enters or leaves it: the preset alone is DSH's default `standard` for most setups, so it
|
|
11
|
+
* would turn every unrelated session into her (#37). Both are sections of the session's system prompt so she sees them on every
|
|
11
12
|
* request. They are read when the session opens and again after each successful compaction (the host assembles
|
|
12
|
-
* the system prompt before pre-step, so the refresh happens on compaction/end)
|
|
13
|
-
* stays in the provider-cached prefix. Whether the session is her home is asked per request.
|
|
13
|
+
* the system prompt before pre-step, so the refresh happens on compaction/end), when a cold session speaks again
|
|
14
|
+
* (`coldHours` in `runtime.ts`, on turn/start) or on explicit console application, so the prompt stays in the provider-cached prefix. Whether the session is her home is asked per request.
|
|
14
15
|
*
|
|
15
16
|
* 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
17
|
* section placed right after the host's persona slot, so a system persona the deployment or her preset already has stays
|
|
@@ -33,9 +34,9 @@ export function createPromptSections(config, world, deps) {
|
|
|
33
34
|
persona, names,
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
/** Registers her persona
|
|
37
|
+
/** Registers her persona while the session is in her workspace and she has one; drops it otherwise. */
|
|
37
38
|
function placePersona(agent, entry) {
|
|
38
|
-
if (!entry.text.persona) {
|
|
39
|
+
if (!entry.active || !entry.text.persona) {
|
|
39
40
|
entry.persona?.();
|
|
40
41
|
delete entry.persona;
|
|
41
42
|
return;
|
|
@@ -60,7 +61,7 @@ export function createPromptSections(config, world, deps) {
|
|
|
60
61
|
if (entries.has(agent) || !belongsToWorld(agent.session, config))
|
|
61
62
|
return;
|
|
62
63
|
let disposeWorld;
|
|
63
|
-
/** Places or removes the world prompt as the session enters or leaves her workspace; true when it did. */
|
|
64
|
+
/** Places or removes the world prompt and her persona as the session enters or leaves her workspace; true when it did. */
|
|
64
65
|
const sync = () => {
|
|
65
66
|
if (inWorld(agent.session, config, world.inWorkspace) === entry.active)
|
|
66
67
|
return false;
|
|
@@ -68,6 +69,7 @@ export function createPromptSections(config, world, deps) {
|
|
|
68
69
|
if (!entry.active) {
|
|
69
70
|
disposeWorld?.();
|
|
70
71
|
disposeWorld = undefined;
|
|
72
|
+
placePersona(agent, entry);
|
|
71
73
|
return true;
|
|
72
74
|
}
|
|
73
75
|
entry.text = read(true);
|
|
@@ -80,7 +82,6 @@ export function createPromptSections(config, world, deps) {
|
|
|
80
82
|
entries.set(agent, entry);
|
|
81
83
|
agents.set(agent.session, agent);
|
|
82
84
|
sync();
|
|
83
|
-
placePersona(agent, entry);
|
|
84
85
|
},
|
|
85
86
|
active(session) {
|
|
86
87
|
const agent = agents.get(session);
|
package/lib/runtime.d.ts
CHANGED
|
@@ -7,12 +7,17 @@ import type { WorldConfig } from './types.ts';
|
|
|
7
7
|
export type { WorldPromptSource } from './promptSection.ts';
|
|
8
8
|
/**
|
|
9
9
|
* The memory line: her conversations are archived as they happen, and every world session gets a memory
|
|
10
|
-
* block of the newest turns at its start
|
|
11
|
-
* inside the provider-cached prefix. `home` archives the current home; `workspace` uses host membership. The memory block still
|
|
10
|
+
* block of the newest turns at its start, after each successful compaction and when it speaks again after being cold,
|
|
11
|
+
* never in between, so it stays inside the provider-cached prefix. `home` archives the current home; `workspace` uses host membership. The memory block still
|
|
12
12
|
* goes to every world session in her workspace (`inWorkspace`), independently of the archive scope.
|
|
13
13
|
* `memoryTurns` is read each time a block is built (default 200).
|
|
14
|
+
*
|
|
15
|
+
* A session silent for `coldHours` (read at each turn start, default 24) is cold (#36): its provider cache has most
|
|
16
|
+
* likely expired (DeepSeek clears an unused one "usually within a few hours to a few days", best effort), so its next
|
|
17
|
+
* turn re-reads her memory block and prompt as a newly opened session would, at the cost of at most one uncached
|
|
18
|
+
* request. A conversation in progress does not pause that long, so its cached prefix stays whole.
|
|
14
19
|
*/
|
|
15
|
-
export declare function createWorldRuntime(ctx: Context, config: WorldConfig, store: ArchiveStore, world?: WorldPromptSource, memoryTurns?: () => number): {
|
|
20
|
+
export declare function createWorldRuntime(ctx: Context, config: WorldConfig, store: ArchiveStore, world?: WorldPromptSource, memoryTurns?: () => number, coldHours?: () => number, now?: () => number): {
|
|
16
21
|
start: (options?: {
|
|
17
22
|
fresh?: boolean;
|
|
18
23
|
}) => Promise<void>;
|