dsh-layers-hippocampus 1.6.2 → 1.6.3
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 +115 -0
- package/README.md +47 -8
- package/docs/ARCHITECTURE.zh.md +2 -2
- package/index.js +217 -37
- package/package.json +1 -1
- package/src/config.js +247 -34
- package/src/memory.js +144 -6
- package/src/schedule.js +28 -0
- package/src/webRoutes.js +10 -5
- package/ui/client.js +205 -191
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,121 @@ All notable changes to `dsh-layers-hippocampus` are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
5
|
and the project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [1.6.3] — 2026-11-13
|
|
8
|
+
|
|
9
|
+
**配置加载器加固:把 1.6.2 的“旧配置启动阻断”事故固化为引擎能力——先迁移、再严格校验、
|
|
10
|
+
必要时安全降级,绝不让 DSH 客户端卡在“正在启动…”。**
|
|
11
|
+
|
|
12
|
+
- **Added — 配置 schema 版本与迁移机制**:`src/config.js` 新增
|
|
13
|
+
`CONFIG_SCHEMA_VERSION = 3`;配置对象可携带 `configVersion`。加载顺序变为
|
|
14
|
+
**`migrateConfig()` → 严格校验**:迁移阶段只做“补值 + 告警”,从不抛错,也绝不覆盖
|
|
15
|
+
用户显式写下的值。缺少 `configVersion` 的旧配置被视为 legacy(`fromVersion: 0`)并
|
|
16
|
+
升级到当前版本。
|
|
17
|
+
- 首次落地的迁移规则:`raw.archiveAfterDays` 缺失且
|
|
18
|
+
`raw.retentionDays <= 新默认值(90)` 时,派生为 `Math.max(1, retentionDays - 1)`
|
|
19
|
+
(即 30 → 29),从而满足 `archiveAfterDays < retentionDays` 的硬约束。
|
|
20
|
+
- 每条迁移都写入 `console.warn`(前缀 `hippocampus/config-migration:`)并携带在
|
|
21
|
+
`config.warnings` 里,`apply()` 再经 `ctx.logger.warn` 输出一次——**迁移永不被静默**。
|
|
22
|
+
- 空配置 `{}` 视为“使用默认值”,不算 legacy,因此内部调用不会产生噪声告警。
|
|
23
|
+
- **Added — `strictStartup`(默认 `true`)启动安全网**:显式设为 `false` 时,若严格校验
|
|
24
|
+
抛出 `MEM_E_CONFIG_OUT_OF_RANGE`,引擎会丢弃该越界键、回退到安全值并继续启动,同时
|
|
25
|
+
置 `config.startup.degraded = true`、记录 `degradedReason{code,key,message}`、
|
|
26
|
+
输出 `hippocampus/config-degraded:` 警告,并在 `apply()` 里额外 warn
|
|
27
|
+
`STARTED DEGRADED (strictStartup=false)`。
|
|
28
|
+
- 降级**只**覆盖越界值:`MEM_E_CONFIG_INVALID_TYPE` / `MEM_E_CONFIG_UNKNOWN_KEY`
|
|
29
|
+
仍然 fail-fast(拼写错误不该被宽容)。
|
|
30
|
+
- `strictStartup` 自身必须是布尔值。
|
|
31
|
+
- **Added — 启动状态进入可观测面**:`CAPABILITIES.startup` / `CAPABILITIES.configVersion`
|
|
32
|
+
与 `memory_admin action=status` 的 `panel.startup` / `panel.configVersion` /
|
|
33
|
+
`panel.configWarnings`。设置页与运维方可以直接看到“这份配置来自哪个 schema 版本、
|
|
34
|
+
是否迁移过、是否降级启动”。
|
|
35
|
+
- **Added — 设置页「简洁模式」(纯显示层)**:设置页顶部新增“简洁模式 / 专业模式”切换。
|
|
36
|
+
简洁模式只渲染四块——**身份、上下文窗口、系统级存储位置迁移、原始回合留存(raw)**;
|
|
37
|
+
raw 卡内再收敛为三项(`raw.mode`、`raw.maxTotalMb`、`raw.compressionEngine`),
|
|
38
|
+
最小显著度 / 保留期 / 冷压缩阈值 / deep_raw 扫描上限全部隐藏。
|
|
39
|
+
- 隐藏是**纯 UI 行为,不碰配置值**:保存时 patch 被过滤为
|
|
40
|
+
`SIMPLE_PATCH_KEYS`(9 个可见键),文件里未显示的项保持原值;新装即默认值,
|
|
41
|
+
专业模式下调过的不会被简洁模式覆盖。
|
|
42
|
+
- 校验同步收敛:只检查可见数字键,隐藏项的越界值不会阻断保存,Cron 非空检查也跳过。
|
|
43
|
+
- 模式偏好存浏览器 `localStorage`(键 `hippocampus:settings-mode`),不进插件配置、
|
|
44
|
+
不影响引擎行为;读写失败一律退回专业模式。
|
|
45
|
+
- **Removed — 交接时“自动开启新会话”(`context.autoNewSession*`)**:交接就发生在对话
|
|
46
|
+
中间,宿主会在标记后**继续同一个对话**;客户端再调 `uiWorkspace.startSession()` 只会
|
|
47
|
+
额外弹出一个空对话,在“追加到原对话”的用法下毫无意义还打断体验。因此彻底移除:
|
|
48
|
+
- 配置层:`autoNewSession` / `autoNewSessionPoll` / `autoNewSessionIntervalSeconds`
|
|
49
|
+
三个键从 `DEFAULT_CONFIG`、校验、resolved 与 HTTP 可编辑白名单中删除。
|
|
50
|
+
- `migrateConfig` 会**静默剥离**旧 profile 残留的这三个键并 warn(否则老用户会撞上
|
|
51
|
+
未知键阻断启动)。
|
|
52
|
+
- 可观测面:`CAPABILITIES.autoNewSession` 与 `handoffView().autoNewSession` 删除。
|
|
53
|
+
- 客户端:三个设置控件、`startAutoNewSession()` 轮询器与其 `ctx.effect` 注册全部删除;
|
|
54
|
+
设置页不再渲染任何“自动开新会话”开关。
|
|
55
|
+
- **Fixed — 新对话拿不到交接摘要与前几轮原话**(2026-11-13 用户报告):
|
|
56
|
+
- 根因:冷启动注入是一个**进程级一次性布尔** `coldStartPending`,被**第一个组装
|
|
57
|
+
prompt 的 agent** 抢先消费(子代理、标题生成等),用户真正的新对话拿到的是空。
|
|
58
|
+
- 改为**按会话幂等**:`runtime.coldStart = { pending: Map, injected: Set, lastSessionId }`,
|
|
59
|
+
以 `session|handoffEpoch` 为键;`noteColdStart()` 在「新 session id 的首个
|
|
60
|
+
`session/event`」与「`agent/created`」两处布防(同键复用、已被注入过的直接跳过、
|
|
61
|
+
过期 5 分钟未消费自动丢弃、最多 8 条 pending 有界淘汰),
|
|
62
|
+
`promptState(assemblyContext)` 用宿主传给 `systemPrompt.context` 的
|
|
63
|
+
`assemblyContext.agent.id` 与当前 session id 做匹配,注入后写入 `injected` 集合并
|
|
64
|
+
有界淘汰(64)。**兄弟 agent 先装配不会再吞掉用户的注入**——这是单槽位实现仍会
|
|
65
|
+
踩的坑:标题生成器或子代理随后布防会覆盖并且消费掉用户的那一条。
|
|
66
|
+
- `handoff.json` 标记新增 `tailTurns`:交接蒸馏时把最后 5 轮(role + 文本,每条
|
|
67
|
+
≤400 字,内存环形缓冲 12 条、跨会话自动清空)写进标记;
|
|
68
|
+
`[Previous Context Tail]` 优先回放这些**原话**(`- user: …` / `- assistant: …`),
|
|
69
|
+
没有 tailTurns 时才回退到最近业务事件。
|
|
70
|
+
- `context.coldStartInjectRecentTurns` 默认由 `false` 改为 **`true`**:只给摘要会让
|
|
71
|
+
新对话接不上具体语境。
|
|
72
|
+
- 即使两个开关全关,匹配到的 pending 也会被消费掉,不会遗留到下一次无关会话。
|
|
73
|
+
- **可观测**:`/stats` 新增 `coldStart{ pending[], injected, lastSessionId }`(`runtime.coldStartView()`),
|
|
74
|
+
运维方不必读 prompt 就能区分“已布防未装配”与“已注入”。
|
|
75
|
+
- **`panel.startup` / `panel.configVersion` / `panel.configWarnings` 与 `capabilities.startup`
|
|
76
|
+
对齐**:此前 `toMemoryOptions()` 没有把迁移结果传给引擎,panel 报的是“未迁移”默认值,
|
|
77
|
+
而 capabilities 报的是真相——同一个进程两处说法不一致,现由 `toMemoryOptions` 一并透传。
|
|
78
|
+
- **Fixed — 复习队列只报不消费(积压到 337 条)**:`maintain()` 里
|
|
79
|
+
`ReviewSchedule.tick()` 的结果只被写进报告,**从来没有人推进它**,于是新装用户的
|
|
80
|
+
`state/reviews.json` 里每条都是 `lastAt: null`、`dueAt` 停在初始间隔,队列只增不减
|
|
81
|
+
(现场:`total 346 / due 337`)。两个后果:复习面板永远是“全到期”,且 recall 拿不到
|
|
82
|
+
强化锚点——衰减曲线相当于“写下之后从未被碰过”。
|
|
83
|
+
- 现在 `maintain()` 会真正消费到期行:`_consumeDueReviews()` 取出到期 id,
|
|
84
|
+
**分批**(默认 30–50 条,`review.consumeBatchSize = 40`)调用批量 `reinforce()`
|
|
85
|
+
(权重 1,日志即锚点,不改任何字段),再用 `ReviewSchedule.advanceMany()` 一次性
|
|
86
|
+
推进 `lastAt` / `step` / `dueAt`。
|
|
87
|
+
- **性能防线**:每批之间 `await new Promise(setImmediate)` 让出事件循环,HTTP 路由与
|
|
88
|
+
prompt 组装不会被一个巨大积压卡住;单次维护总量上限 `review.consumeMaxPerRun = 200`,
|
|
89
|
+
再多就跨多次维护轮次排空(报告里的 `remaining` 说明还剩多少)。
|
|
90
|
+
- **一次文件写/批**:新增的 `advanceMany()` 把“逐条 advance = 每条一次读+一次原子写”
|
|
91
|
+
变成“整批一次”,337 条积压不再是 337 次 fsync。
|
|
92
|
+
- 开关:`review.autoConsume`(默认 `true`)可关;`review.enabled: false` 时不会消费。
|
|
93
|
+
失败的批次不中断维护(`lastAt` 保持 null,下一轮自然重试),错误写进
|
|
94
|
+
`report.reviewConsumeError`。三条新键均进入 HTTP 可编辑白名单。
|
|
95
|
+
- **Fixed — 1.6.2 遗留的两个启动/保留缺陷(随 1.6.3 一并锁定)**:
|
|
96
|
+
- **旧 profile 启动阻断**:旧配置只写 `raw.retentionDays: 30`、没有 `archiveAfterDays`,
|
|
97
|
+
而 1.6.2 的新默认值是 90,硬校验 `archiveAfterDays < retentionDays` 直接抛错,
|
|
98
|
+
`apply()` 失败 → 插件整体不注册 → `/api/hippocampus/*` 全部 404,设置页永远停在
|
|
99
|
+
“正在启动…”。现在 `migrateConfig()` 在**未显式配置**且冲突时自适应派生
|
|
100
|
+
`Math.max(1, retentionDays - 1)`(30 → 29)并告警;**显式**写下越界值仍然 fail-fast。
|
|
101
|
+
- **`.jsonl.br` 冷归档永不清理**:`prune()` 原先只删明文分片,Brotli/Gzip/Zstd 归档
|
|
102
|
+
变成“保留期之外的永久副本”,等于变相突破 `retentionDays`。现在 `prune()` 按
|
|
103
|
+
`cutoffMonth` 整月删除过期归档,并同步从 `state/raw-archive.json` 抹掉记录
|
|
104
|
+
(返回 `removedArchives`)。
|
|
105
|
+
- **Tests**:`test/v163.migration.test.js`(9 例)锁定本次教训——旧配置(仅
|
|
106
|
+
`retentionDays: 30`)可启动且 `archiveAfterDays` 派生为 29;显式冲突在
|
|
107
|
+
`strictStartup: true` 下阻断、在 `false` 下降级启动;降级不吞类型错误与未知键;
|
|
108
|
+
以及 1.6.2 生产 profile 的原始形状可被完整解析。`test/helpers.js` 的夹具改走同一
|
|
109
|
+
迁移步骤,`test/status.test.js` 的 panel 形状契约同步新增三个字段。
|
|
110
|
+
`test/v163.ui.test.js`(5 例)锁定简洁模式契约:`Section` 的 `hidden` 短路、
|
|
111
|
+
14 个专业模式卡片全部带 `hidden: simpleMode`、raw 只剩三项、保存与校验按白名单收敛。
|
|
112
|
+
`test/v163.reviewQueue.test.js`(5 例)锁定复习消费契约:到期行被消费且 `step`/`lastAt`
|
|
113
|
+
前进、强化记录数 == 消费数、超出单轮预算的积压跨轮次排空、`autoConsume:false` 不动队列、
|
|
114
|
+
整批只写一次 `reviews.json`。
|
|
115
|
+
`test/v156.autoSession.test.js` 重写为「该功能已移除」契约(配置无该键、旧 profile
|
|
116
|
+
迁移剥离、路由/能力面不暴露、客户端无轮询器);
|
|
117
|
+
`test/v160.coldStart.test.js` 重写为按会话注入契约(无标记不布防、摘要+尾部各一次、
|
|
118
|
+
兄弟 agent 先装配不吞注入、两个会话各注入一次、**两条 pending 先布防后装配也各得其份**、
|
|
119
|
+
双关不遗留 pending、tailTurns 优先、stats 暴露 coldStart 状态)。
|
|
120
|
+
全量 **483/483**(78 个测试文件)。
|
|
121
|
+
|
|
7
122
|
## [1.6.2] — 2026-11-11
|
|
8
123
|
|
|
9
124
|
**补丁版:修复冷数据归档与保留期的时间冲突,并把“打破日志线性增长”的三层机制并入正式记录。**
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
| | |
|
|
9
9
|
| --- | --- |
|
|
10
|
-
| 版本 | **1.6.
|
|
10
|
+
| 版本 | **1.6.3** |
|
|
11
11
|
| 包名 | `dsh-layers-hippocampus` |
|
|
12
12
|
| 仓库 | <https://github.com/382quaii/dsh-Layers-Hippocampus> |
|
|
13
13
|
| 许可证 | MIT |
|
|
@@ -77,8 +77,12 @@
|
|
|
77
77
|
- 交接状态机 `active → consumed | failed`,带超时看门狗:**任何异常都降级为可继续的标记**,
|
|
78
78
|
绝不会把会话卡死。
|
|
79
79
|
- 新会话首轮可注入 `[Cold-Start Detected]` 与两段可独立开关的历史块
|
|
80
|
-
(`context.coldStartInjectSummary` 默认开、`context.coldStartInjectRecentTurns`
|
|
80
|
+
(`context.coldStartInjectSummary` 默认开、`context.coldStartInjectRecentTurns` 默认开);
|
|
81
|
+
**注入按会话幂等**(键为 `session|交接批次`),兄弟 agent 先装配不会吞掉用户新对话的注入;
|
|
82
|
+
「前几轮原话」取自交接标记里的 `tailTurns`(最后 ≤5 轮原话),摘要之外还能接上具体语境。
|
|
81
83
|
静态「状态唤醒」策略常驻,两个开关都关时也不会退化成客服腔。
|
|
84
|
+
- 交接**不会**自动弹出新对话:交接发生在对话中间,宿主在标记后继续同一对话;是否需要另开
|
|
85
|
+
新对话由用户自己决定(v1.5.6 的 `context.autoNewSession*` 已在 1.6.3 移除)。
|
|
82
86
|
|
|
83
87
|
### 打破线性增长:压缩 / 编码 / 语义三层
|
|
84
88
|
|
|
@@ -146,7 +150,7 @@ raw 层提供三档,覆盖从“只留关键”到“全留”:
|
|
|
146
150
|
pnpm add dsh-layers-hippocampus
|
|
147
151
|
|
|
148
152
|
# 或从 GitHub 指定 tag
|
|
149
|
-
pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.6.
|
|
153
|
+
pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.6.3"
|
|
150
154
|
```
|
|
151
155
|
|
|
152
156
|
### 2. 挂到 profile
|
|
@@ -174,15 +178,50 @@ node scripts/wait-for-routes.mjs
|
|
|
174
178
|
config:
|
|
175
179
|
dataDir: "C:/Users/<you>/.dsh/memory" # 可选;默认 <DSH_HOME>/memory
|
|
176
180
|
raw:
|
|
177
|
-
mode: salience
|
|
178
|
-
retentionDays:
|
|
179
|
-
archiveAfterDays:
|
|
181
|
+
mode: salience # off | salience | all
|
|
182
|
+
retentionDays: 365 # 必须 > archiveAfterDays
|
|
183
|
+
archiveAfterDays: 90 # 超过该天数的分片按月归档
|
|
184
|
+
coldAccessWindowDays: 90 # 近 N 天零访问才允许归档
|
|
185
|
+
compressionEngine: brotli # brotli(11) | gzip(9) | zstd
|
|
180
186
|
```
|
|
181
187
|
|
|
182
|
-
### 4.
|
|
188
|
+
### 4. 配置版本与启动安全
|
|
189
|
+
|
|
190
|
+
配置对象带 `configVersion`(当前 **3**)。加载顺序是 **迁移 → 严格校验**:
|
|
191
|
+
|
|
192
|
+
- **迁移**:缺少 `configVersion` 的旧配置视为 legacy,先补齐版本号与新增默认值
|
|
193
|
+
(例如 `archiveAfterDays` 缺失且 `retentionDays` 不大于新默认 90 时,派生为
|
|
194
|
+
`retentionDays - 1`),每条迁移都会 `console.warn` 并记录在 `config.warnings` 里。
|
|
195
|
+
迁移只补值、不覆盖你显式写下的键,也从不抛错。
|
|
196
|
+
- **严格校验**:迁移之后仍按类型/取值范围/未知键严格检查。
|
|
197
|
+
- **安全降级**:`strictStartup: false`(默认 `true`)时,若严格校验发现取值越界,
|
|
198
|
+
引擎回退到安全值并继续启动,同时把 `startup.degraded` 置为 `true`、记录
|
|
199
|
+
`degradedReason` 并输出 `hippocampus/config-degraded:` 警告。
|
|
200
|
+
类型错误与未知键**不会**被降级吞掉。
|
|
201
|
+
|
|
202
|
+
启动结果可在 `memory_admin action=status` 的 `panel.startup` / `panel.configVersion` /
|
|
203
|
+
`panel.configWarnings` 里看到——插件绝不会静默地以与你写的不一样的配置运行。
|
|
204
|
+
|
|
205
|
+
> 2026-11-13 的生产事故正是这一层缺失造成的:新默认值与旧 profile 冲突,`apply()`
|
|
206
|
+
> 抛错导致插件整体不加载,UI 只能看到 HTTP 404。1.6.3 起该路径由
|
|
207
|
+
> `test/v163.migration.test.js` 锁定。
|
|
208
|
+
|
|
209
|
+
### 5. 设置页的两种视图
|
|
210
|
+
|
|
211
|
+
设置 → 海马体记忆 顶部可切换 **简洁模式 / 专业模式**:
|
|
212
|
+
|
|
213
|
+
- **简洁模式**只显示四块:**身份**(事件时间策略)、**上下文窗口**(预算 / 注入上限 /
|
|
214
|
+
淘汰阈值 / 收敛目标 / 是否注入)、**系统级存储位置迁移**、**原始回合留存**
|
|
215
|
+
(只留 `raw.mode`、总量上限、冷压缩引擎三项)。
|
|
216
|
+
- 它是**纯显示层**:隐藏项不渲染,也不参与保存——POST 只携带可见键,文件里其余配置
|
|
217
|
+
保持原值(新装即默认值,专业模式下调过的不会被覆盖)。
|
|
218
|
+
- 视图选择只存在浏览器 `localStorage`(`hippocampus:settings-mode`),不进插件配置、
|
|
219
|
+
不影响引擎行为;默认是专业模式。
|
|
220
|
+
|
|
221
|
+
### 6. 验证
|
|
183
222
|
|
|
184
223
|
```bash
|
|
185
|
-
npm test # 进程内全量用例(
|
|
224
|
+
npm test # 进程内全量用例(483 个)
|
|
186
225
|
npm run check # 语法检查 + 全量测试
|
|
187
226
|
```
|
|
188
227
|
|
package/docs/ARCHITECTURE.zh.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @local/dsh-memory — 分层长期记忆 Host 插件
|
|
2
2
|
|
|
3
|
-
> 版本:**1.6.
|
|
3
|
+
> 版本:**1.6.3** | 全量用例:**483/483** | 运行时依赖:**零**
|
|
4
4
|
|
|
5
5
|
给 DSH 智能体一份"活得比会话久"的记忆:**追加式原始日志是唯一真相源**,标签索引、日记、活跃集合全部是可丢弃、可重建的读模型,语义摘要独立于原始日志生死。
|
|
6
6
|
|
|
@@ -681,7 +681,7 @@ window.__ModuleLoader__.load({
|
|
|
681
681
|
|
|
682
682
|
运行器带**看门狗**:默认 **60s**(`MEM_TEST_TIMEOUT_MS` 可调)仍未退出,就打印**卡住时正在导入/执行的文件、最后完成的测试名与完成数、活动资源、尚未触发的定时器**,然后 `process.exit(1)`。它不会用 `process.exit(0)` 掩盖超时——挂起即失败。`MEM_TEST_TRACE=1` 可看文件级进度,`MEM_TEST_ONLY=<子串>` 只跑一组。
|
|
683
683
|
|
|
684
|
-
|
|
684
|
+
483 个用例(78 个文件)覆盖:
|
|
685
685
|
|
|
686
686
|
- 索引与标签:重建 digest 一致、行号漂移防护(eventId 不变、行号变)、同义合并、活跃集 cap 挤出、规则变更不改清单、空活跃集降级、top-k 有界有序去重。
|
|
687
687
|
- 衰减与删除:30 天半衰期、reinforce 移动锚点(不存字段)、仅文本粗筛、标签过滤、维护代切换且旧代可读、boot 检查、压缩不丢记录、并发维护串行化、四阶段删除、archive 可回滚 vs purge 不可、strict 巩固暂停与恢复、任务重放幂等、错误 id 零变更。
|
package/index.js
CHANGED
|
@@ -61,7 +61,7 @@ export { resolveConfig, DEFAULT_CONFIG };
|
|
|
61
61
|
* of letting a raw 404 reach the user.
|
|
62
62
|
*/
|
|
63
63
|
export const CAPABILITIES = Object.freeze({
|
|
64
|
-
version: '1.6.
|
|
64
|
+
version: '1.6.3',
|
|
65
65
|
spaces: true,
|
|
66
66
|
memories: true,
|
|
67
67
|
transferConsent: true,
|
|
@@ -398,8 +398,25 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
398
398
|
* made the model look like it was rereading the same page.
|
|
399
399
|
*/
|
|
400
400
|
runtime.injection = { sessionId: null, ids: new Set(), tags: new Set(), handoffAt: null };
|
|
401
|
-
|
|
402
|
-
|
|
401
|
+
/**
|
|
402
|
+
* v1.6.3 cold-start state (replaces the v1.6.0 boolean `coldStartPending`).
|
|
403
|
+
*
|
|
404
|
+
* The boolean was consumed by the FIRST prompt assembly of the whole process, so
|
|
405
|
+
* any other agent that assembled a prompt first (a delegated sub-agent, a title
|
|
406
|
+
* generator, a background fibre) swallowed the injection and the user's brand-new
|
|
407
|
+
* conversation started blind — exactly the reported bug.
|
|
408
|
+
*
|
|
409
|
+
* Now a *pending injection* is armed per conversation start (a new session id from
|
|
410
|
+
* `session/event`, or `agent/created(source=startup)`) and is keyed by
|
|
411
|
+
* `session|handoffEpoch`. `injected` records what has already been delivered, so:
|
|
412
|
+
* - one conversation is injected at most once per handoff epoch;
|
|
413
|
+
* - a different agent cannot consume someone else's injection silently: the new
|
|
414
|
+
* conversation arms its own pending entry on its first captured turn.
|
|
415
|
+
*/
|
|
416
|
+
runtime.coldStart = { pending: new Map(), injected: new Set(), lastSessionId: null };
|
|
417
|
+
const COLD_START_INJECTED_LIMIT = 64;
|
|
418
|
+
const COLD_START_PENDING_LIMIT = 8;
|
|
419
|
+
const COLD_START_PENDING_TTL_MS = 5 * 60_000;
|
|
403
420
|
runtime.lastHintTags = [];
|
|
404
421
|
runtime.resetInjection = (sessionId = runtime.injection.sessionId) => {
|
|
405
422
|
runtime.injection = { sessionId, ids: new Set(), tags: new Set(), handoffAt: null };
|
|
@@ -455,20 +472,114 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
455
472
|
};
|
|
456
473
|
|
|
457
474
|
/**
|
|
458
|
-
* v1.6.
|
|
475
|
+
* v1.6.3: arm a cold-start injection for the conversation that is about to run.
|
|
476
|
+
*
|
|
477
|
+
* Two independent hosts signal "a conversation started": `agent/created` (a new
|
|
478
|
+
* agent, `source: startup`) and the first `session/event` of a session id we have
|
|
479
|
+
* not seen. Either one arms the SAME per-conversation entry, so a host that does
|
|
480
|
+
* not deliver one of them still gets the behaviour (and the second signal for the
|
|
481
|
+
* same conversation is a no-op, not a second injection).
|
|
482
|
+
*
|
|
483
|
+
* A MAP of pendings, not a single slot: a title generator or a delegated sub-agent
|
|
484
|
+
* may be created right after the user's conversation and arm its own entry. With a
|
|
485
|
+
* single slot that later arm would OVERWRITE — and then consume — the user's entry,
|
|
486
|
+
* which is exactly the bug being fixed.
|
|
487
|
+
*
|
|
488
|
+
* Nothing is armed when there is nothing to inject: no handoff summary and no L3
|
|
489
|
+
* summaries means a brand-new install, where a cold-start block would be noise.
|
|
490
|
+
*/
|
|
491
|
+
runtime.noteColdStart = ({ sessionId = null, agentId = null, source = 'session' } = {}) => {
|
|
492
|
+
if (runtime.phase !== 'ready') return null;
|
|
493
|
+
const handoff = memory.handoffState();
|
|
494
|
+
const hasSummaryEvent = typeof handoff?.summaryEventId === 'string' && handoff.summaryEventId.length > 0;
|
|
495
|
+
if (!hasSummaryEvent) return null;
|
|
496
|
+
const epoch = `${handoff.at ?? 0}:${handoff.summaryEventId}`;
|
|
497
|
+
const key = `${sessionId ?? agentId ?? 'unknown'}|${epoch}`;
|
|
498
|
+
if (runtime.coldStart.injected.has(key)) return null;
|
|
499
|
+
const pendings = runtime.coldStart.pending;
|
|
500
|
+
runtime.pruneColdStartPendings();
|
|
501
|
+
const existing = pendings.get(key);
|
|
502
|
+
if (existing) {
|
|
503
|
+
// Same conversation re-armed (created + first turn): merge identifiers and keep
|
|
504
|
+
// the FIRST arming time instead of restarting the TTL.
|
|
505
|
+
existing.sessionId = existing.sessionId ?? sessionId;
|
|
506
|
+
existing.agentId = existing.agentId ?? agentId;
|
|
507
|
+
return existing;
|
|
508
|
+
}
|
|
509
|
+
const entry = {
|
|
510
|
+
key,
|
|
511
|
+
sessionId,
|
|
512
|
+
agentId,
|
|
513
|
+
source,
|
|
514
|
+
at: memory.clock.now(),
|
|
515
|
+
epoch,
|
|
516
|
+
summaryEventId: handoff.summaryEventId,
|
|
517
|
+
};
|
|
518
|
+
pendings.set(key, entry);
|
|
519
|
+
// Bounded: the oldest armed entry is dropped, so a long-lived process cannot grow
|
|
520
|
+
// this map without limit (each conversation adds at most a couple of entries).
|
|
521
|
+
while (pendings.size > COLD_START_PENDING_LIMIT) {
|
|
522
|
+
pendings.delete(pendings.keys().next().value);
|
|
523
|
+
}
|
|
524
|
+
return entry;
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
/** Drop pendings that were never consumed (a conversation that never assembled). */
|
|
528
|
+
runtime.pruneColdStartPendings = () => {
|
|
529
|
+
const pendings = runtime.coldStart.pending;
|
|
530
|
+
if (pendings.size === 0) return 0;
|
|
531
|
+
const now = memory.clock.now();
|
|
532
|
+
let dropped = 0;
|
|
533
|
+
for (const [key, entry] of pendings) {
|
|
534
|
+
if (now - (Number(entry.at) || 0) > COLD_START_PENDING_TTL_MS) {
|
|
535
|
+
pendings.delete(key);
|
|
536
|
+
dropped += 1;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return dropped;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
/** True when an armed entry belongs to the conversation currently assembling. */
|
|
543
|
+
const coldStartMatches = (pending, sessionId, agentId) => {
|
|
544
|
+
if (!pending) return false;
|
|
545
|
+
if (pending.sessionId && sessionId && pending.sessionId === sessionId) return true;
|
|
546
|
+
if (pending.agentId && agentId && pending.agentId === agentId) return true;
|
|
547
|
+
// Neither side known (older host without session/agent identity): the entry is
|
|
548
|
+
// still this process's ONLY armed injection, so let it through once.
|
|
549
|
+
return !pending.sessionId && !pending.agentId && !sessionId && !agentId;
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* v1.6.0 / v1.6.3: one-shot cold-start block for a conversation that just started
|
|
554
|
+
* after a handoff.
|
|
459
555
|
*
|
|
460
|
-
* Two independent switches
|
|
461
|
-
* - `context.coldStartInjectSummary`
|
|
462
|
-
* event
|
|
463
|
-
* - `context.coldStartInjectRecentTurns` → `[Previous Context Tail]` (last ≤5
|
|
464
|
-
*
|
|
465
|
-
* Both off →
|
|
466
|
-
*
|
|
556
|
+
* Two independent switches:
|
|
557
|
+
* - `context.coldStartInjectSummary` → `[Cold-Start Summary]` (the handoff
|
|
558
|
+
* summary event; falls back to the top L3 semantic summaries);
|
|
559
|
+
* - `context.coldStartInjectRecentTurns` → `[Previous Context Tail]` (the last ≤5
|
|
560
|
+
* turns captured at handoff time, else the newest episodes).
|
|
561
|
+
* Both off → empty string; the static anti-customer-service policy still ships in
|
|
562
|
+
* `memory:policy`, so the model never falls back to a canned opener.
|
|
467
563
|
*/
|
|
468
|
-
runtime.coldStartText = () => {
|
|
469
|
-
if (runtime.phase !== 'ready'
|
|
564
|
+
runtime.coldStartText = ({ sessionId = null, agentId = null } = {}) => {
|
|
565
|
+
if (runtime.phase !== 'ready') return '';
|
|
566
|
+
runtime.pruneColdStartPendings();
|
|
567
|
+
const pendings = runtime.coldStart.pending;
|
|
568
|
+
let pending = null;
|
|
569
|
+
for (const entry of pendings.values()) {
|
|
570
|
+
if (coldStartMatches(entry, sessionId, agentId)) {
|
|
571
|
+
pending = entry;
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
if (!pending) return '';
|
|
576
|
+
// Consume on the FIRST matching assembly, even when both switches are off: the
|
|
577
|
+
// entry must not linger and fire later on an unrelated conversation.
|
|
578
|
+
pendings.delete(pending.key);
|
|
470
579
|
const contextConfig = runtime.config?.context ?? {};
|
|
471
|
-
|
|
580
|
+
const wantSummary = contextConfig.coldStartInjectSummary === true;
|
|
581
|
+
const wantTurns = contextConfig.coldStartInjectRecentTurns === true;
|
|
582
|
+
if (!wantSummary && !wantTurns) return '';
|
|
472
583
|
try {
|
|
473
584
|
const view = memory.indexManager.snapshot();
|
|
474
585
|
const allEvents = Array.isArray(view?.events) ? [...view.events] : [];
|
|
@@ -483,11 +594,15 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
483
594
|
const spaces = memory.spaces.status();
|
|
484
595
|
const activeSpace = spaces?.current ?? 'default';
|
|
485
596
|
const lines = ['', `[Cold-Start Detected: Active Space=${activeSpace}, Recent Topic=${latestTopic}]`];
|
|
486
|
-
|
|
597
|
+
const handoff = memory.handoffState();
|
|
598
|
+
if (wantSummary) {
|
|
487
599
|
let summaryText = '';
|
|
488
|
-
const handoff = memory.handoffState();
|
|
489
600
|
if (handoff?.summaryEventId) {
|
|
490
|
-
|
|
601
|
+
// The summary event carries a business tag (`folded_summary`), but be
|
|
602
|
+
// defensive: search ALL events so a bookkeeping-tag rewrite cannot hide it.
|
|
603
|
+
const summaryEvent =
|
|
604
|
+
allEvents.find((event) => event.eventId === handoff.summaryEventId) ??
|
|
605
|
+
events.find((event) => event.eventId === handoff.summaryEventId);
|
|
491
606
|
if (summaryEvent?.content) summaryText = String(summaryEvent.content);
|
|
492
607
|
}
|
|
493
608
|
if (!summaryText) {
|
|
@@ -502,20 +617,34 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
502
617
|
lines.push('[Cold-Start Summary]', summaryText.replace(/\s+/g, ' ').trim().slice(0, 800));
|
|
503
618
|
}
|
|
504
619
|
}
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
620
|
+
if (wantTurns) {
|
|
621
|
+
// Prefer the turns captured AT the handoff (verbatim roles, exactly "the last
|
|
622
|
+
// few things said"); episodes are distilled text and lose the dialogue shape.
|
|
623
|
+
const tail = Array.isArray(handoff?.tailTurns) ? handoff.tailTurns : [];
|
|
624
|
+
const recent = tail.length > 0
|
|
625
|
+
? tail
|
|
626
|
+
.slice(-5)
|
|
627
|
+
.map((turn) => `- ${turn.role === 'assistant' ? 'assistant' : 'user'}: ${String(turn.text ?? '').replace(/\s+/g, ' ').trim().slice(0, 200)}`)
|
|
628
|
+
.filter((line) => line.length > 10)
|
|
629
|
+
: events
|
|
630
|
+
.slice(0, 5)
|
|
631
|
+
.map((event) => `- ${String(event.content ?? '').replace(/\s+/g, ' ').trim().slice(0, 200)}`)
|
|
632
|
+
.filter((line) => line.length > 2);
|
|
510
633
|
if (recent.length > 0) lines.push('[Previous Context Tail]', ...recent);
|
|
511
634
|
}
|
|
512
|
-
|
|
635
|
+
const text = lines.join('\n');
|
|
636
|
+
runtime.coldStart.injected.add(pending.key);
|
|
637
|
+
if (runtime.coldStart.injected.size > COLD_START_INJECTED_LIMIT) {
|
|
638
|
+
const oldest = runtime.coldStart.injected.values().next().value;
|
|
639
|
+
runtime.coldStart.injected.delete(oldest);
|
|
640
|
+
}
|
|
641
|
+
return text;
|
|
513
642
|
} catch {
|
|
514
643
|
return '';
|
|
515
644
|
}
|
|
516
645
|
};
|
|
517
646
|
|
|
518
|
-
runtime.promptState = () => {
|
|
647
|
+
runtime.promptState = (assemblyContext = null) => {
|
|
519
648
|
// Opportunistic mode tracking: prompt assembly is inside the agent turn, so the
|
|
520
649
|
// current preset is readable here even when no change event ever fired.
|
|
521
650
|
runtime.syncAgentPreset();
|
|
@@ -577,9 +706,12 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
577
706
|
.join('\n')
|
|
578
707
|
: '';
|
|
579
708
|
// v1.6.0 cold-start block: volatile tail (after the cacheable prefix), injected
|
|
580
|
-
//
|
|
581
|
-
|
|
582
|
-
|
|
709
|
+
// at most once per conversation (v1.6.3: keyed by session|handoff-epoch, so a
|
|
710
|
+
// sibling agent assembling first can no longer swallow the user's injection).
|
|
711
|
+
const coldStart = runtime.coldStartText({
|
|
712
|
+
sessionId: usage?.sessionId ?? null,
|
|
713
|
+
agentId: assemblyContext?.agent?.id ?? null,
|
|
714
|
+
});
|
|
583
715
|
return (
|
|
584
716
|
composePrompt({ rules: PROMPT_STATE_RULES, activeTask: activeTaskBlock, blocks, hints }) +
|
|
585
717
|
marker +
|
|
@@ -853,6 +985,9 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
853
985
|
dreamQueue: memory.dreamQueue(),
|
|
854
986
|
dreamTimer: runtime.dreamTimer?.status() ?? null,
|
|
855
987
|
handoff: runtime.handoffView(),
|
|
988
|
+
// v1.6.3: cold-start injection observability. Without it the only way to tell
|
|
989
|
+
// "armed but never assembled" from "already injected" is to read the prompt.
|
|
990
|
+
coldStart: runtime.coldStartView?.() ?? null,
|
|
856
991
|
panel: { ...status.panel, migration: runtime.migrationStatus() },
|
|
857
992
|
briefing: memory.briefing(),
|
|
858
993
|
config: uiConfig(runtime.config),
|
|
@@ -904,6 +1039,25 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
904
1039
|
: ['default']
|
|
905
1040
|
: [];
|
|
906
1041
|
|
|
1042
|
+
/**
|
|
1043
|
+
* v1.6.3: cold-start injection observability for /stats.
|
|
1044
|
+
*
|
|
1045
|
+
* `pending` = armed but not yet assembled (a conversation that has not run its
|
|
1046
|
+
* first turn), `injected` = delivered keys (bounded), `lastSessionId` = the most
|
|
1047
|
+
* recent conversation this process captured a turn for.
|
|
1048
|
+
*/
|
|
1049
|
+
runtime.coldStartView = () => ({
|
|
1050
|
+
pending: [...runtime.coldStart.pending.values()].map((entry) => ({
|
|
1051
|
+
key: entry.key,
|
|
1052
|
+
sessionId: entry.sessionId,
|
|
1053
|
+
agentId: entry.agentId,
|
|
1054
|
+
source: entry.source,
|
|
1055
|
+
at: entry.at,
|
|
1056
|
+
})),
|
|
1057
|
+
injected: runtime.coldStart.injected.size,
|
|
1058
|
+
lastSessionId: runtime.coldStart.lastSessionId,
|
|
1059
|
+
});
|
|
1060
|
+
|
|
907
1061
|
/**
|
|
908
1062
|
* True only when a multi-space adapter (dsh-orchestrator) is present AND the
|
|
909
1063
|
* profile has not turned the capability off. The core alone is single-space.
|
|
@@ -929,8 +1083,11 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
929
1083
|
// but no spacesDelete, so the client hides the delete button instead of sending an
|
|
930
1084
|
// action the old server would misread as CREATE ("空间已存在").
|
|
931
1085
|
spacesDelete: runtime.multiSpaceAvailable() && typeof memory.spaces?.deleteSpace === 'function',
|
|
932
|
-
// v1.
|
|
933
|
-
|
|
1086
|
+
// v1.6.3: `autoNewSession` was REMOVED — a handoff continues the same conversation,
|
|
1087
|
+
// so there is no client-side "open another one" capability to advertise.
|
|
1088
|
+
// v1.6.3: how the config was loaded — a degraded boot must be visible, not silent.
|
|
1089
|
+
startup: runtime.config.startup ?? { strict: true, degraded: false, migrated: false, fromVersion: null },
|
|
1090
|
+
configVersion: runtime.config.configVersion ?? null,
|
|
934
1091
|
// v1.6.1: cold-archive compression engines available in THIS Node runtime.
|
|
935
1092
|
compression: (() => {
|
|
936
1093
|
const probe = probeCompression();
|
|
@@ -946,15 +1103,13 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
946
1103
|
})(),
|
|
947
1104
|
});
|
|
948
1105
|
|
|
949
|
-
/** v1.5.6: handoff observability
|
|
950
|
-
runtime.handoffView = () => {
|
|
1106
|
+
/** v1.5.6: handoff observability (the client shows the marker + summary link). */ runtime.handoffView = () => {
|
|
951
1107
|
const handoff = memory.handoffState();
|
|
952
1108
|
return {
|
|
953
1109
|
active: handoff?.active === true,
|
|
954
1110
|
at: handoff?.at ?? null,
|
|
955
1111
|
summaryEventId: handoff?.summaryEventId ?? null,
|
|
956
1112
|
agentPreset: runtime.agentPreset ?? null,
|
|
957
|
-
autoNewSession: runtime.config.context.autoNewSession === true,
|
|
958
1113
|
};
|
|
959
1114
|
};
|
|
960
1115
|
|
|
@@ -1328,9 +1483,13 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
|
|
|
1328
1483
|
runtime.agentPresetSessionId = sessionId ?? null;
|
|
1329
1484
|
},
|
|
1330
1485
|
onAgentCreated: async (payload) => {
|
|
1331
|
-
// v1.6.
|
|
1332
|
-
//
|
|
1333
|
-
|
|
1486
|
+
// v1.6.3: arm a cold-start injection for the new agent. The host reports
|
|
1487
|
+
// `source: 'startup'` for a user-created conversation, and there is no separate
|
|
1488
|
+
// "user pressed +" signal, so we do NOT gate on source here: the real gate is
|
|
1489
|
+
// "a handoff summary exists and this conversation has not seen it yet"
|
|
1490
|
+
// (inside noteColdStart). A delegated sub-agent also lands here — it merely
|
|
1491
|
+
// arms its OWN entry, and the user's conversation arms its own on first turn.
|
|
1492
|
+
runtime.noteColdStart({ agentId: payload?.agent?.id ?? null, source: 'agent-created' });
|
|
1334
1493
|
// Track the mode this session actually runs in (a session may be created with
|
|
1335
1494
|
// a preset without emitting a change event).
|
|
1336
1495
|
try {
|
|
@@ -1503,9 +1662,19 @@ export async function discoverLegacyDataDir({ existsSync, dataDir }) {
|
|
|
1503
1662
|
* @param {object} [rawConfig] plugin config from cordis.patch.yml / Config panel
|
|
1504
1663
|
*/
|
|
1505
1664
|
export async function apply(ctx, rawConfig = {}) {
|
|
1506
|
-
//
|
|
1665
|
+
// v1.6.3: migrate-then-validate. `resolveConfig` migrates older config schemas
|
|
1666
|
+
// BEFORE strict validation, and with `strictStartup: false` degrades an
|
|
1667
|
+
// out-of-range value instead of aborting activation — a boot abort is what left
|
|
1668
|
+
// the whole plugin unregistered in 1.6.2 (UI polled /stats → 404 forever).
|
|
1507
1669
|
const config = resolveConfig(rawConfig);
|
|
1508
1670
|
const options = toMemoryOptions(config);
|
|
1671
|
+
const startupWarnings = Array.isArray(config.warnings) ? config.warnings : [];
|
|
1672
|
+
for (const warning of startupWarnings) ctx?.logger?.warn?.(`hippocampus/config: ${warning}`);
|
|
1673
|
+
if (config.startup?.degraded) {
|
|
1674
|
+
ctx?.logger?.warn?.(
|
|
1675
|
+
`hippocampus/config: STARTED DEGRADED (strictStartup=false) — ${config.startup.degradedReason?.message ?? 'config value out of range'}`,
|
|
1676
|
+
);
|
|
1677
|
+
}
|
|
1509
1678
|
|
|
1510
1679
|
const runtime = createRuntime({ ctx, config, options, raw: rawConfig });
|
|
1511
1680
|
// Internal handle, kept OFF the context: `ctx.memory` is a provided service name
|
|
@@ -1609,6 +1778,15 @@ export async function apply(ctx, rawConfig = {}) {
|
|
|
1609
1778
|
// raw store's own gating/budgets still decide what lands on disk.
|
|
1610
1779
|
const captureListener = (session, event) => {
|
|
1611
1780
|
if (!runtime.memory || runtime.phase !== 'ready') return;
|
|
1781
|
+
// v1.6.3: a NEW conversation id is the reliable "the user started a conversation"
|
|
1782
|
+
// signal on every host (a user-created and a resumed session both arrive here).
|
|
1783
|
+
// Arming on the first captured turn also beats any sibling agent assembling a
|
|
1784
|
+
// prompt, because this conversation's assembly happens after its own turn.
|
|
1785
|
+
const sessionId = typeof session?.id === 'string' && session.id.length > 0 ? session.id : null;
|
|
1786
|
+
if (sessionId && sessionId !== runtime.coldStart.lastSessionId) {
|
|
1787
|
+
runtime.coldStart.lastSessionId = sessionId;
|
|
1788
|
+
runtime.noteColdStart({ sessionId, source: 'session-switch' });
|
|
1789
|
+
}
|
|
1612
1790
|
// v1.5.6: remember the latest USER turn as the relevance input for
|
|
1613
1791
|
// `[Memory Hints]`. This is the only place the current input is available:
|
|
1614
1792
|
// prompt assembly receives no message text.
|
|
@@ -2195,11 +2373,13 @@ export async function apply(ctx, rawConfig = {}) {
|
|
|
2195
2373
|
}),
|
|
2196
2374
|
);
|
|
2197
2375
|
// On-demand: this function runs at assemble time and reads the live window.
|
|
2376
|
+
// v1.6.3: the assembly context carries `agent`, which lets the cold-start
|
|
2377
|
+
// injection be matched to the conversation that is actually assembling.
|
|
2198
2378
|
disposers.push(
|
|
2199
2379
|
ctx.systemPrompt.context({
|
|
2200
2380
|
name: 'memory-state',
|
|
2201
2381
|
order: 220,
|
|
2202
|
-
text: () => runtime.promptState(),
|
|
2382
|
+
text: (assemblyContext) => runtime.promptState(assemblyContext),
|
|
2203
2383
|
}),
|
|
2204
2384
|
);
|
|
2205
2385
|
if (config.enableReflection) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-layers-hippocampus",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Layered long-term memory for DeepSeek Harness: append-only event log, rebuildable tag index, day diaries, independent semantic layer, L2.5 trend quarantine, offline knowledge graph and a Web UI panel.",
|
|
6
6
|
"type": "module",
|