dsh-layers-hippocampus 1.7.4 → 1.9.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 CHANGED
@@ -4,6 +4,131 @@ 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.9.2] — 2026-11-30
8
+
9
+ **修 1.9.1 上线后暴露的真问题:宿主模型能调到了,但 20 次里只成功 1 次。**
10
+ 19 次全都报 `dream LLM answer is not a JSON object`——根因不是提示词,是**算错了输出预算**。
11
+
12
+ - **Fixed — 输出预算(`dream.llm.maxTokens`,默认 1200)**。旧代码把预算从摘要长度推导
13
+ (`maxSummaryChars*2+64` = 默认 **464** tokens),而推理型模型要先消耗预算推理、再输出 JSON,
14
+ 464 常在写出 `{` 之前就耗尽,于是答案里根本不含花括号 → 每次都被判「不是 JSON 对象」。
15
+ 现在预算是显式配置项:实际请求值 = `max(128, 配置值, 摘要长度*2+64)`,
16
+ 配置低于摘要下限时自动抬到下限(不会静默按小值发出)。范围 128–16000,fail-fast。
17
+ - **Fixed — 截断与格式错误分开报(`llm-truncated`)**。宿主接缝现在把 finish reason 一起返回
18
+ (`{ text, finish, reasoningChars }`,同时兼容只回字符串的老接缝)。当 `finish === 'max-tokens'`
19
+ 且答案里没有 `{` 时抛 `phase:'truncated'`,`fallbackReason` 记为 **`llm-truncated`** 并附
20
+ `hint: raise dream.llm.maxTokens`;而模型明明停笔却没给 JSON 的情况仍是 `llm-error`
21
+ (`phase:'format'`,带 `chars` 与 `hasBrace`)。两种失败的修法不同,不该长得一样。
22
+ - **Fixed — 答案完整就照用**。`finish:'max-tokens'` 但答案已含 JSON 时正常采纳——
23
+ 模型写完答案后停在上限,没有理由丢弃。
24
+ - **Added — 诊断字段(不含正文)**。`dreamStatus().lastFallback.diagnostic` 携带
25
+ `phase` / `transport` / `chars` / `hasBrace` / `maxTokens` / `timeoutMs`。
26
+ **绝不记录模型返回的文本**——那是从记忆内容推导出来的,不能进面板或日志。
27
+ - **Added — 推理长度只计数不保留**。接缝统计 `reasoning-delta` 的字符数用于诊断
28
+ (推理吃光预算正是截断的解释),但推理内容本身不入库、不入状态。
29
+ - **Changed — 一处旧隐藏行为被纠正**:`block-end` 文本块以前只在「没有任何 delta」时采纳,
30
+ 现在用 `sawDelta` 显式标记,避免适配器既发 delta 又发 block-end 时重复拼接。
31
+ - **Tests — 8 个新用例(`test/v192.dream.budget.test.js`)**:预算默认值/范围 fail-fast、
32
+ 引擎确实按配置值请求(不再是 464)、配置低于摘要下限时被抬升、
33
+ 截断→`llm-truncated` 且诊断齐全、`max-tokens` 但有 JSON 仍采纳、
34
+ 停笔但没 JSON→`llm-error` 且 `hasBrace:false`、
35
+ **隐私**(`dreamStatus()` 里搜不到模型返回的正文片段)、老式字符串接缝仍可用。
36
+
37
+ ## [1.9.1] — 2026-11-29
38
+
39
+ **Dream 真正接上 LLM:默认走宿主自己的模型,不再需要 endpoint 与 API key。**
40
+ 此前 `dream.useLlm` 是 `true`,但 `dream.llm` 只能写在 profile(且 UI/HTTP 故意拒绝凭据字段),
41
+ 于是全新安装的每一次 Dream 都在走确定性兜底——`llmConfigured:false`、每次 `llmFallback`。
42
+
43
+ - **Added — 宿主模型通道(`src/dream.js` + `index.js`)**。新增传输层 `llmPath()`:
44
+ `host`(宿主模型)→ `http`(显式 endpoint)→ `null`(本地兜底),优先级固定。
45
+ 宿主侧把 `ctx.get('llm').stream()` 与 `ctx.get('agentDefaultModel').currentSelection()`
46
+ 适配成一个 `hostLlm` 接缝(`available` / `describe` / `chat`),逐块累积 `text-delta`,
47
+ `finish.reason.kind === 'error'` 时抛出带原因的 `MEM_E_DREAM_LLM_FALLBACK`。
48
+ **记忆引擎本身仍然不持有任何 LLM 客户端、也不自己开网络连接**——它只是多了一个可注入的接缝。
49
+ - **Added — `dream.llm.useHost`(默认 `true`)**。这是**传输开关**,不是凭据:
50
+ 关掉它,离线提炼就完全不碰宿主模型(不想让后台任务花配额的人需要这一条),
51
+ 此时才需要 `dream.llm.{baseUrl,model}`;环境变量 `DSH_DREAM_LLM_HOST=0/false/no/off` 同样可关。
52
+ 配置键优先于环境变量。
53
+ - **Changed — 失败纪律统一**。宿主的超时、抛错、空回答与 HTTP 走同一套:
54
+ 超时→`timeout`、抛错/空回答→`llm-error`、计入熔断计数器(`failureThreshold`)、
55
+ 写 `lastFallback`、并 warn `MEM_E_DREAM_LLM_FALLBACK`。熔断打开后不再调用模型。
56
+ - **Changed — `dreamStatus()` 说清是哪条通道**。新增 `llmPath`(`'host'` / `'http'` / `null`)
57
+ 与 `hostLlm`(接缝是否存在);`llmConfigured` 改成「实际可用」而非「显式配置了 endpoint」,
58
+ 所以「没配 key」和「你关掉了宿主通道」不再长得一样。
59
+ - **Changed — 面板与配置面**。`/stats` 的 `config.dream.llm` **只**包含 `{ useHost }`
60
+ (端点与凭据仍然绝不进浏览器);`dream.llm.useHost` 可经 HTTP 编辑,设置页新增
61
+ 「用当前宿主模型做提炼」开关。
62
+ - **Tests — 10 个新用例(`test/v191.dream.host.test.js`)**:通道优先级与 `useHost:false`、
63
+ 宿主通道在**不调用 fetch** 的情况下完成一次真实提炼、`useHost:false` 时宿主模型零调用、
64
+ 无接缝无端点时报 not-configured 而非报错、宿主抛错→本地兜底并打开熔断、
65
+ 空回答算 format 失败、运行时真的接线(`dreamStatus().llmPath === 'host'`)、
66
+ 无 `llm` 服务时不抛错、模型选择坏掉时当作「没有宿主模型」。
67
+
68
+ ## [1.9.0] — 2026-11-29
69
+
70
+ **「空间」改名为「分层」:配置主键换成 `features.layers`(`features.multiSpace` 降为弃用别名,
71
+ 两者始终镜像),能力握手新增 `capabilities.layers` / `layerReason`,并新增只读路由
72
+ `GET /api/hippocampus/layers`。面板在宿主报告 `layers:true` 时显示「会话 / 项目 / 全局」三层目录,
73
+ 否则保持原来的单一目录界面。**
74
+
75
+ - **Changed — 配置主键(`src/config.js`)**。`features.layers` 是规范名,`features.multiSpace`
76
+ 继续可用但只是别名:解析结果**同时**写两个键,值永远一致,所以已部署的 profile 不需要改配置就能升级。
77
+ 两个键同时出现且互相矛盾时报 `MEM_E_CONFIG_OUT_OF_RANGE` —— 不让「一个说开、一个说关」静默胜出。
78
+ `crossSpaceTransfer` / `crossSpaceRecall` 的依赖错误信息同步改说 `features.layers`。
79
+ - **Added — `layersActive()` / `layersReason()`(`src/config.js`)**。原
80
+ `multiSpaceActive()` / `multiSpaceReason()` 保留为 `@deprecated` 包装,转发到新函数,
81
+ 三态(`active` / `disabled-by-config` / `orchestrator-missing`)语义不变。
82
+ - **Added — 能力握手(`index.js`)**。`capabilities` 新增 `layers` 与 `layerReason`,
83
+ 同时**继续**输出 `spaces` / `multiSpace` / `multiSpaceReason`:新客户端读前者,
84
+ 旧客户端读后者,两者永远是同一个答案。
85
+ - **Added — `GET /api/hippocampus/layers`(`src/webRoutes.js`)**。只读(`POST` → 405),
86
+ 可选 `?sessionId=` / `?projectId=` 透传作用域;返回
87
+ `{ ok, available, reason, scope, layers:[{layer,dir,exists}], capabilities }`。
88
+ 目录一律由 **orchestrator** 算(`orchestrator.layers.dirsFor()` + `bindingOf()`),
89
+ 海马体只转发、只 `fs.existsSync` 探存在性,**绝不自己推导 projectId、也不自己枚举层目录**。
90
+ 没有 orchestrator 或 `features.layers:false` 时返回 `available:false` + 空列表(**200 而非报错**),
91
+ 面板据此退回单一目录界面。
92
+ - **Added — 面板分层条(`ui/client.js`)**。`Payload.capabilities.layers === true` 时在状态栏下方
93
+ 渲染三张层卡片(层名 / 是否有数据 / 目录缩短显示),10s 轮询;
94
+ `layerReason` 为 `orchestrator-missing` 或 `disabled-by-config` 时各说各的原因,不显示空框。
95
+ **分层条是只读的**:会话属于哪一层由 orchestrator 的 `bindSession()` 决定,不在这个面板里切换。
96
+ 设置页开关改名为「启用分层(features.layers)」,保存时只写规范键。
97
+ - **Tests — 11 个新用例(`test/v181.layers.test.js`)**:别名镜像与冲突报错、两个函数名答案一致、
98
+ 路由 GET-only 与 405、作用域原样透传、三层顺序(会话 → 项目 → 全局)、
99
+ 无 sessionId 时没有会话层、projectId 回退到 orchestrator 绑定、
100
+ 无 orchestrator / 配置关闭 / orchestrator 抛错三种降级,以及两条边界断言
101
+ (`index.js` 不出现 `projectIdFromWorkspace`、不自己 `readdir` 层目录)。
102
+ 路由表因此从 10 条增到 11 条,相关计数断言同步更新。
103
+ - **Unchanged — 存储语义**。写读仍按一个物理 `dataDir`;`?space=` 路由与
104
+ `space_transfer` / `transfer_to_global` 工具名**本轮未改**,线格式 `target_space_id` 保持原样,
105
+ 以免破坏已部署 profile 与模型侧的工具调用。
106
+
107
+ ## [1.8.0] — 2026-11-29
108
+
109
+ **新增「按物理路径寻址」的纯存储面与纯信箱面:`src/db/pureApi.js` 与 `src/db/dropbox.js`。
110
+ 它们在语义上不识别空间 / 项目 / 会话,只认一个绝对 `dataDir` 加不透明 id,
111
+ 把「这一切该落到哪个目录」的判断留给 `dsh-layers-orchestrator`。**
112
+
113
+ - **Added — 纯存储 API(`src/db/pureApi.js`)**。`write_event(dataDir, {content, ...})` 向
114
+ `<dataDir>/log` 的当前世代段追加一条记录,随后自行 flush 并关闭句柄;`recall(dataDir, query, filter)`
115
+ 只扫这一个目录并返回简单排序切片。两个 `dataDir` **天然隔离**,不经过配置单例。
116
+ 记录仍用引擎同一套 `contentHashOf` / `eventIdFor` 构造,因此 `src/log/records.js#parseRecord`
117
+ 与 `LogStore#snapshot` 照样能读——它不是旁路格式。
118
+ - **Added — 纯信箱(`src/db/dropbox.js`)**。`append_to_dropbox` / `read_dropbox` / `clear_dropbox`,
119
+ 落在 `<dataDir>/state/dropbox.jsonl`,一行一个 JSON。**红线:只存取,不判重、不摘要、不蒸馏、
120
+ 不归档**;损坏行跳过而不中断,空文件读作空信箱。
121
+ - **Design — 边界声明**。这两个模块只被新增测试导入,`index.js` / `src/webRoutes.js` / `ui/client.js`
122
+ 都**没有接线**:v1.8.0 是「先把纯地层立起来」,业务路由的剥离与 UI 的 space → layers 改名
123
+ 留给下一个版本,不会在本版改变任何既有运行时行为。
124
+ - **Tests — 18 个新用例**:`test/v180.pureApi.test.js`(11)覆盖绝对路径校验、写入-召回往返、
125
+ sessionId 过滤(含 meta 兼容)、双目录隔离、topK / since / until / kinds、同刻同文本仍得不同 id、
126
+ 文本排序,以及两条例行检查(插件可执行源码里不出现业务词、纯模块只按路径寻址);
127
+ `test/v180.dropbox.test.js`(7)覆盖缺失文件、损坏行、外部 id、双目录独立。
128
+
129
+ > 验证方式注意:`node --test <file>` 在受限沙箱下会以 `EPERM spawn` 失败(它要派生每个文件的子进程),
130
+ > **那不是测试失败**。本仓库自带 `node test/run.mjs` 的进程内运行器,正是为这种情况准备的。
131
+
7
132
  ## [1.7.4] — 2026-11-28
8
133
 
9
134
  **图谱从「640×320 里挤沙子」变成可缩放的布局世界;节点按事件数自动收敛到 80;
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  | | |
9
9
  | --- | --- |
10
- | 版本 | **1.7.4** |
10
+ | 版本 | **1.9.2** |
11
11
  | 包名 | `dsh-layers-hippocampus` |
12
12
  | 仓库 | <https://github.com/382quaii/dsh-Layers-Hippocampus> |
13
13
  | 许可证 | MIT |
@@ -109,10 +109,29 @@
109
109
  `context.injectMode = 'full'` 是旧行为的一键回退(正文直接进 Prompt,按整段计费)。
110
110
  `[Memory Blocks]` 标记名与缓存前缀语义保持不变;`briefing` 块(运营方钉死的策略)
111
111
  永不降级为指针。
112
- - **多空间开关会说明自己为什么没生效(1.6.7,M6)**:`features.multiSpace` 默认 `true`,
113
- 但只有注入了能创建空间适配器的 `orchestrator` 服务时才真正运行。以前两者的差异是静默的
114
- ——「我开了多空间」和「我实际在单空间」可以同时为真。现在
115
- `capabilities.multiSpaceRequested`(配置意图)与 `capabilities.multiSpaceReason`
112
+ - **Dream 默认就用你现在这个模型(1.9.1),并给了它足够答完的预算(1.9.2)**:`dream.useLlm` 一直是 `true`,
113
+ 但 LLM 原本只有「显式 OpenAI 兼容端点」一条通道,而端点和 API key 只能写在 profile(UI/HTTP 故意不接受凭据),
114
+ 于是全新安装的每次 Dream 都在走确定性兜底。现在默认走**宿主自己的模型**
115
+ (`ctx.get('llm')` + `agentDefaultModel.currentSelection()`),无需配置任何 endpoint 或 key;
116
+ 传输优先级是 `host → http → 本地兜底`,`dream.llm.useHost: false`(或 `DSH_DREAM_LLM_HOST=0`)
117
+ 可让后台维护完全不碰你的额度。`dreamStatus()` 会写明 `llmPath`(`host` / `http` / `null`)。
118
+ **输出预算** `dream.llm.maxTokens` 默认 1200:旧实现从摘要长度推导出 464,推理型模型常在写出 `{`
119
+ 之前就耗尽预算,于是每次都被判「不是 JSON 对象」。现在截断单独报 **`llm-truncated`**(附
120
+ `hint: raise dream.llm.maxTokens`),而「停笔却没给 JSON」才是 `llm-error`;诊断只记
121
+ `phase/chars/hasBrace/maxTokens`,**从不记录模型返回的正文**。
122
+ - **「空间」与「分层」是两回事,别混着叫(1.9.0)**:`space` 是**物理目录**(可建、可删、可迁移),
123
+ `layer` 是**业务语义**(`session` / `project` / `public`)。海马体不该知道「当前会话属于哪个项目」,
124
+ 所以配置主键换成 `features.layers`(`features.multiSpace` 保留为别名,解析后两者始终镜像;
125
+ 两个键互相矛盾直接报 `MEM_E_CONFIG_OUT_OF_RANGE`),能力握手同时给出
126
+ `capabilities.layers` / `layerReason` 与旧的 `spaces` / `multiSpaceReason`。
127
+ 新路由 `GET /api/hippocampus/layers` **只读**,目录一律由 `dsh-orchestrator` 算
128
+ (`layers.dirsFor()` + `bindingOf()`),海马体只转发作用域并探一下有没有数据;
129
+ 没有 orchestrator 或配置关闭时返回 `200 { available:false, layers:[] }`,面板退回单一目录界面。
130
+ 面板在 `layers:true` 时显示三层目录卡片,**不可点、不可切换**——归属由编排器的 `bindSession()` 决定。
131
+ - **多空间开关会说明自己为什么没生效(1.6.7,M6)**:`features.layers`(旧名 `features.multiSpace`)
132
+ 默认 `true`,但只有注入了能创建空间适配器的 `orchestrator` 服务时才真正运行。以前两者的差异是静默的
133
+ ——「我开了分层」和「我实际在单目录」可以同时为真。现在
134
+ `capabilities.layerRequested` / `capabilities.layerReason`
116
135
  (`active` / `disabled-by-config` / `orchestrator-missing`)一起返回,
117
136
  `panel.spaces.{requested,reason}` 同样如此,设置页会直接写明是哪一种。
118
137
  **默认值没有改动**:改默认会静默改变已部署 profile 的行为。
@@ -242,6 +261,30 @@ raw 层提供三档,覆盖从“只留关键”到“全留”:
242
261
  - **上限剪枝**:`salience × 3.9` 是分数硬上界,候选按 salience 降序早停,长尾不再计算 decay。
243
262
  - 全量 Web 面板:图谱、标签树、记忆列表、空间管理、设置页、raw 归档与索引统计。
244
263
 
264
+ ### 纯存储面:按路径寻址的「笨数据库」(1.8.0)
265
+
266
+ `src/db/` 是给编排层用的**无业务语义**接口:只认一个绝对 `dataDir` 加不透明 id,
267
+ 不认识空间 / 项目 / 会话,两个目录天然隔离。
268
+
269
+ | 模块 | 导出 | 落盘位置 |
270
+ | --- | --- | --- |
271
+ | `src/db/pureApi.js` | `write_event` / `recall` | `<dataDir>/log`(与引擎同一套记录格式) |
272
+ | `src/db/dropbox.js` | `append_to_dropbox` / `read_dropbox` / `clear_dropbox` | `<dataDir>/state/dropbox.jsonl` |
273
+
274
+ ```js
275
+ import { write_event, recall } from 'dsh-layers-hippocampus/src/db/pureApi.js';
276
+ import { read_dropbox, clear_dropbox } from 'dsh-layers-hippocampus/src/db/dropbox.js';
277
+
278
+ write_event('D:/mem/sessions/abc', { content: '用户偏好极简风格', tags: ['preference'] });
279
+ const hits = recall('D:/mem/sessions/abc', '偏好', { topK: 5 });
280
+
281
+ const notes = read_dropbox('D:/mem/sessions/abc'); // 原样返回,不判重不摘要
282
+ clear_dropbox('D:/mem/sessions/abc');
283
+ ```
284
+
285
+ **红线**:信箱只存取。判重、摘要、蒸馏、归档一律属于 `dsh-layers-orchestrator`。
286
+ 本版仅新增模块与测试,**未接线**到任何既有路由或 UI。
287
+
245
288
  ---
246
289
 
247
290
  ## 快速开始
@@ -253,7 +296,7 @@ raw 层提供三档,覆盖从“只留关键”到“全留”:
253
296
  pnpm add dsh-layers-hippocampus
254
297
 
255
298
  # 或从 GitHub 指定 tag
256
- pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.7.4"
299
+ pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.9.2"
257
300
  ```
258
301
 
259
302
  ### 2. 挂到 profile
package/index.js CHANGED
@@ -29,7 +29,7 @@
29
29
 
30
30
  import fs from 'node:fs';
31
31
  import path from 'node:path';
32
- import { resolveConfig, toMemoryOptions, DEFAULT_CONFIG, multiSpaceActive, multiSpaceReason } from './src/config.js';
32
+ import { resolveConfig, toMemoryOptions, DEFAULT_CONFIG, layersActive, layersReason, multiSpaceActive, multiSpaceReason } from './src/config.js';
33
33
  import { extractEntities } from './src/utils/RegexExtractor.js';
34
34
  import { migrateDataDir } from './src/migration.js';
35
35
  import { MigrationRunner } from './src/migrationRunner.js';
@@ -79,7 +79,7 @@ export { resolveConfig, DEFAULT_CONFIG };
79
79
  * of letting a raw 404 reach the user.
80
80
  */
81
81
  export const CAPABILITIES = Object.freeze({
82
- version: '1.7.4',
82
+ version: '1.9.2',
83
83
  spaces: true,
84
84
  memories: true,
85
85
  transferConsent: true,
@@ -247,10 +247,107 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
247
247
  // v1.5.6 physical split: multi-space lives in dsh-orchestrator. `orchestrator` is a
248
248
  // test/embedding override; the Host supplies the real service through `ctx.get`.
249
249
  const orchestratorService = () => orchestrator ?? ctx?.get?.('orchestrator') ?? null;
250
+
251
+ /**
252
+ * v1.9.1: the Host's own model, adapted to the offline Dream seam.
253
+ *
254
+ * Dream needs exactly one thing — "given a system+user prompt, return text" — and
255
+ * DSH already owns that capability: `llm.stream()` plus the default model
256
+ * selection. Adapting it here (rather than giving the memory engine an LLM
257
+ * client) means:
258
+ * - no endpoint and no API key to configure before distillation works;
259
+ * - the memory engine still opens no network connection of its own;
260
+ * - a profile without an `llm` service degrades to `null`, so Dream falls back
261
+ * to an explicit endpoint or to the deterministic local merge.
262
+ *
263
+ * `available()` is evaluated per call, never cached: the user can switch models
264
+ * (or sign out) while the Host is running, and Dream must follow that.
265
+ */
266
+ const hostLlmSeam = () => {
267
+ const llm = ctx?.get?.('llm') ?? ctx?.llm ?? null;
268
+ if (!llm || typeof llm.stream !== 'function') return null;
269
+ const modelService = ctx?.get?.('agentDefaultModel') ?? null;
270
+ const selection = () => {
271
+ try {
272
+ const selected = modelService?.currentSelection?.() ?? null;
273
+ if (!selected || typeof selected.provider !== 'string' || typeof selected.model !== 'string') return null;
274
+ if (!selected.provider || !selected.model) return null;
275
+ return selected;
276
+ } catch {
277
+ return null; // a broken selection is "no host model", never a crash
278
+ }
279
+ };
280
+ return {
281
+ available: () => selection() !== null,
282
+ describe: () => {
283
+ const selected = selection();
284
+ return selected ? { provider: selected.provider, model: selected.model } : null;
285
+ },
286
+ /** One non-streaming-text call over the Host's streaming API. */
287
+ chat: async ({ system, user, maxTokens, signal }) => {
288
+ const selected = selection();
289
+ if (!selected) {
290
+ throw new MemoryError(ErrorCodes.DREAM_LLM_FALLBACK, 'no default model is selected in the Host', {
291
+ phase: 'config',
292
+ transport: 'host',
293
+ });
294
+ }
295
+ const options = {
296
+ provider: selected.provider,
297
+ model: selected.model,
298
+ system,
299
+ messages: [{ role: 'user', content: [{ type: 'text', text: user }] }],
300
+ ...(Number.isFinite(maxTokens) && maxTokens > 0 ? { maxTokens } : {}),
301
+ ...(signal ? { signal } : {}),
302
+ };
303
+ let text = '';
304
+ let reasoningChars = 0;
305
+ let finishKind = null;
306
+ let sawDelta = false;
307
+ for await (const chunk of llm.stream(options)) {
308
+ if (!chunk || typeof chunk !== 'object') continue;
309
+ if (chunk.type === 'text-delta' && typeof chunk.text === 'string') {
310
+ text += chunk.text;
311
+ sawDelta = true;
312
+ } else if (chunk.type === 'reasoning-delta') {
313
+ // v1.9.2: reasoning is not the answer, but its SIZE explains a truncated
314
+ // one — a model that spends the whole output budget here never reaches
315
+ // the JSON. Only the length is kept, never the reasoning itself.
316
+ if (typeof chunk.text === 'string') reasoningChars += chunk.text.length;
317
+ } else if (chunk.type === 'block-end' && chunk.block?.type === 'text' && typeof chunk.block.text === 'string') {
318
+ // Prefer deltas when the adapter emits them; otherwise take the block.
319
+ if (!sawDelta) text += chunk.block.text;
320
+ } else if (chunk.type === 'finish') {
321
+ finishKind = chunk.reason?.kind ?? null;
322
+ if (chunk.reason?.kind === 'error') {
323
+ const failure = chunk.reason.failure ?? {};
324
+ throw new MemoryError(
325
+ ErrorCodes.DREAM_LLM_FALLBACK,
326
+ `host model call failed: ${failure.message ?? 'unknown error'}`,
327
+ { phase: 'host', transport: 'host', code: failure.code ?? null },
328
+ );
329
+ }
330
+ }
331
+ }
332
+ // v1.9.2: hand the finish reason back with the text. Without it the caller
333
+ // cannot tell a bad answer from a cut-off one.
334
+ return {
335
+ text,
336
+ finish: finishKind,
337
+ reasoningChars,
338
+ maxTokens: Number.isFinite(maxTokens) ? maxTokens : null,
339
+ };
340
+ },
341
+ };
342
+ };
250
343
  const multiSpaceExtras = () => {
344
+ // v1.9.1: every Memory instance (root, child space, migrated, reloaded) gets the
345
+ // same host-model seam, so Dream behaves identically wherever it runs.
346
+ const base = { hostLlm: hostLlmSeam() };
251
347
  const orchestrator = orchestratorService();
252
- if (typeof orchestrator?.createSpaceAdapter !== 'function') return {};
348
+ if (typeof orchestrator?.createSpaceAdapter !== 'function') return base;
253
349
  return {
350
+ ...base,
254
351
  spacesFactory: (owner) =>
255
352
  orchestrator.createSpaceAdapter({
256
353
  owner,
@@ -1758,6 +1855,70 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
1758
1855
  return multiSpaceReason(runtime.config, typeof orchestrator?.createSpaceAdapter === 'function');
1759
1856
  };
1760
1857
 
1858
+ /**
1859
+ * v1.9.0: the LAYERED view of the same capability.
1860
+ *
1861
+ * The hippocampus still stores one directory at a time and still cannot tell a
1862
+ * "session" from a "project" — that decision stays in the orchestrator. What this
1863
+ * exposes is only what the orchestrator already computed: which physical
1864
+ * directory each layer means for a given conversation. With no orchestrator, or
1865
+ * with `features.layers: false`, the answer is an empty list and the client
1866
+ * degrades to the plain directory selector instead of inventing layers.
1867
+ */
1868
+ runtime.layersAvailable = () => {
1869
+ const orchestrator = orchestratorService();
1870
+ return layersActive(runtime.config, typeof orchestrator?.createSpaceAdapter === 'function');
1871
+ };
1872
+
1873
+ runtime.layersReason = () => {
1874
+ const orchestrator = orchestratorService();
1875
+ return layersReason(runtime.config, typeof orchestrator?.createSpaceAdapter === 'function');
1876
+ };
1877
+
1878
+ /**
1879
+ * Resolve the layer directories for one conversation scope.
1880
+ *
1881
+ * `sessionId` is optional: without it a session layer simply does not exist (a
1882
+ * conversation that was never bound has no private directory), and the list is
1883
+ * project + public. `exists` is a plain `fs.existsSync` — a layer that has never
1884
+ * been written is reported as present-but-empty rather than hidden, so the panel
1885
+ * can show "public: empty" instead of making the row silently disappear.
1886
+ */
1887
+ runtime.layerList = ({ sessionId = null, projectId = null } = {}) => {
1888
+ const orchestrator = orchestratorService();
1889
+ const layersApi = orchestrator?.layers;
1890
+ if (!runtime.layersAvailable() || typeof layersApi?.dirsFor !== 'function') return [];
1891
+ let binding = null;
1892
+ try {
1893
+ binding = sessionId && typeof orchestrator.bindingOf === 'function' ? orchestrator.bindingOf(sessionId) : null;
1894
+ } catch {
1895
+ binding = null; // an orchestrator that throws here must not break the panel
1896
+ }
1897
+ const resolvedProject = projectId ?? binding?.projectId ?? null;
1898
+ let dirs = {};
1899
+ try {
1900
+ dirs = layersApi.dirsFor({ sessionId: sessionId ?? null, projectId: resolvedProject }) ?? {};
1901
+ } catch {
1902
+ return [];
1903
+ }
1904
+ return ['session', 'project', 'public']
1905
+ .filter((layer) => typeof dirs[layer] === 'string' && dirs[layer].length > 0)
1906
+ .map((layer) => ({ layer, dir: dirs[layer], exists: fs.existsSync(dirs[layer]) }));
1907
+ };
1908
+
1909
+ /** Route payload for `GET /api/hippocampus/layers`. */
1910
+ runtime.layersPayload = ({ sessionId = null, projectId = null } = {}) => {
1911
+ const available = runtime.layersAvailable();
1912
+ return {
1913
+ ok: true,
1914
+ available,
1915
+ reason: runtime.layersReason(),
1916
+ scope: { sessionId: sessionId ?? null, projectId: projectId ?? null },
1917
+ layers: available ? runtime.layerList({ sessionId, projectId }) : [],
1918
+ capabilities: runtime.capabilities?.() ?? null,
1919
+ };
1920
+ };
1921
+
1761
1922
  /**
1762
1923
  * Capability handshake read by the client bundle (old host → new UI safety).
1763
1924
  * v1.5.6: function, not a constant — the feature flags can change live and the
@@ -1767,6 +1928,14 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
1767
1928
  ...CAPABILITIES,
1768
1929
  spaces: runtime.multiSpaceAvailable(),
1769
1930
  multiSpace: runtime.multiSpaceAvailable(),
1931
+ // v1.9.0: the same capability under its canonical name. A client that knows
1932
+ // about layers checks THIS flag and renders the three layers; a client that
1933
+ // predates it keeps reading `spaces` and degrades to the directory selector.
1934
+ layers: runtime.layersAvailable(),
1935
+ layerReason: runtime.layersReason(),
1936
+ // v1.9.0: the CONFIGURED intent next to the effective answer, exactly like
1937
+ // `multiSpaceRequested` below — "I asked for it" and "it is running" differ.
1938
+ layerRequested: runtime.config.features.layers !== false,
1770
1939
  // v1.6.7 (M6): the CONFIGURED intent and the reason the effective answer may
1771
1940
  // differ. `multiSpaceRequested` mirrors `features.multiSpace`; `multiSpaceReason`
1772
1941
  // is 'active' | 'disabled-by-config' | 'orchestrator-missing'.
@@ -2491,6 +2660,13 @@ function uiConfig(config) {
2491
2660
  cooldownMinutes: config.dream.cooldownMinutes,
2492
2661
  compensateAfterHours: config.dream.compensateAfterHours,
2493
2662
  onlyLowValley: config.dream.onlyLowValley,
2663
+ // v1.9.1: the transport policy only. The endpoint/credential below it stays
2664
+ // out of this view — it must never round-trip through the browser.
2665
+ // v1.9.2: plus the output budget, which is the knob that fixes `llm-truncated`.
2666
+ llm: {
2667
+ useHost: config.dream.llm.useHost !== false,
2668
+ maxTokens: config.dream.llm.maxTokens,
2669
+ },
2494
2670
  },
2495
2671
  // Convenience mirrors kept for older clients; the form uses the nested form.
2496
2672
  eventTimePolicy: config.identity.eventTimePolicy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-layers-hippocampus",
3
- "version": "1.7.4",
3
+ "version": "1.9.2",
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",