dsh-layers-hippocampus 1.7.4 → 1.9.1

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,101 @@ 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.1] — 2026-11-29
8
+
9
+ **Dream 真正接上 LLM:默认走宿主自己的模型,不再需要 endpoint 与 API key。**
10
+ 此前 `dream.useLlm` 是 `true`,但 `dream.llm` 只能写在 profile(且 UI/HTTP 故意拒绝凭据字段),
11
+ 于是全新安装的每一次 Dream 都在走确定性兜底——`llmConfigured:false`、每次 `llmFallback`。
12
+
13
+ - **Added — 宿主模型通道(`src/dream.js` + `index.js`)**。新增传输层 `llmPath()`:
14
+ `host`(宿主模型)→ `http`(显式 endpoint)→ `null`(本地兜底),优先级固定。
15
+ 宿主侧把 `ctx.get('llm').stream()` 与 `ctx.get('agentDefaultModel').currentSelection()`
16
+ 适配成一个 `hostLlm` 接缝(`available` / `describe` / `chat`),逐块累积 `text-delta`,
17
+ `finish.reason.kind === 'error'` 时抛出带原因的 `MEM_E_DREAM_LLM_FALLBACK`。
18
+ **记忆引擎本身仍然不持有任何 LLM 客户端、也不自己开网络连接**——它只是多了一个可注入的接缝。
19
+ - **Added — `dream.llm.useHost`(默认 `true`)**。这是**传输开关**,不是凭据:
20
+ 关掉它,离线提炼就完全不碰宿主模型(不想让后台任务花配额的人需要这一条),
21
+ 此时才需要 `dream.llm.{baseUrl,model}`;环境变量 `DSH_DREAM_LLM_HOST=0/false/no/off` 同样可关。
22
+ 配置键优先于环境变量。
23
+ - **Changed — 失败纪律统一**。宿主的超时、抛错、空回答与 HTTP 走同一套:
24
+ 超时→`timeout`、抛错/空回答→`llm-error`、计入熔断计数器(`failureThreshold`)、
25
+ 写 `lastFallback`、并 warn `MEM_E_DREAM_LLM_FALLBACK`。熔断打开后不再调用模型。
26
+ - **Changed — `dreamStatus()` 说清是哪条通道**。新增 `llmPath`(`'host'` / `'http'` / `null`)
27
+ 与 `hostLlm`(接缝是否存在);`llmConfigured` 改成「实际可用」而非「显式配置了 endpoint」,
28
+ 所以「没配 key」和「你关掉了宿主通道」不再长得一样。
29
+ - **Changed — 面板与配置面**。`/stats` 的 `config.dream.llm` **只**包含 `{ useHost }`
30
+ (端点与凭据仍然绝不进浏览器);`dream.llm.useHost` 可经 HTTP 编辑,设置页新增
31
+ 「用当前宿主模型做提炼」开关。
32
+ - **Tests — 10 个新用例(`test/v191.dream.host.test.js`)**:通道优先级与 `useHost:false`、
33
+ 宿主通道在**不调用 fetch** 的情况下完成一次真实提炼、`useHost:false` 时宿主模型零调用、
34
+ 无接缝无端点时报 not-configured 而非报错、宿主抛错→本地兜底并打开熔断、
35
+ 空回答算 format 失败、运行时真的接线(`dreamStatus().llmPath === 'host'`)、
36
+ 无 `llm` 服务时不抛错、模型选择坏掉时当作「没有宿主模型」。
37
+
38
+ ## [1.9.0] — 2026-11-29
39
+
40
+ **「空间」改名为「分层」:配置主键换成 `features.layers`(`features.multiSpace` 降为弃用别名,
41
+ 两者始终镜像),能力握手新增 `capabilities.layers` / `layerReason`,并新增只读路由
42
+ `GET /api/hippocampus/layers`。面板在宿主报告 `layers:true` 时显示「会话 / 项目 / 全局」三层目录,
43
+ 否则保持原来的单一目录界面。**
44
+
45
+ - **Changed — 配置主键(`src/config.js`)**。`features.layers` 是规范名,`features.multiSpace`
46
+ 继续可用但只是别名:解析结果**同时**写两个键,值永远一致,所以已部署的 profile 不需要改配置就能升级。
47
+ 两个键同时出现且互相矛盾时报 `MEM_E_CONFIG_OUT_OF_RANGE` —— 不让「一个说开、一个说关」静默胜出。
48
+ `crossSpaceTransfer` / `crossSpaceRecall` 的依赖错误信息同步改说 `features.layers`。
49
+ - **Added — `layersActive()` / `layersReason()`(`src/config.js`)**。原
50
+ `multiSpaceActive()` / `multiSpaceReason()` 保留为 `@deprecated` 包装,转发到新函数,
51
+ 三态(`active` / `disabled-by-config` / `orchestrator-missing`)语义不变。
52
+ - **Added — 能力握手(`index.js`)**。`capabilities` 新增 `layers` 与 `layerReason`,
53
+ 同时**继续**输出 `spaces` / `multiSpace` / `multiSpaceReason`:新客户端读前者,
54
+ 旧客户端读后者,两者永远是同一个答案。
55
+ - **Added — `GET /api/hippocampus/layers`(`src/webRoutes.js`)**。只读(`POST` → 405),
56
+ 可选 `?sessionId=` / `?projectId=` 透传作用域;返回
57
+ `{ ok, available, reason, scope, layers:[{layer,dir,exists}], capabilities }`。
58
+ 目录一律由 **orchestrator** 算(`orchestrator.layers.dirsFor()` + `bindingOf()`),
59
+ 海马体只转发、只 `fs.existsSync` 探存在性,**绝不自己推导 projectId、也不自己枚举层目录**。
60
+ 没有 orchestrator 或 `features.layers:false` 时返回 `available:false` + 空列表(**200 而非报错**),
61
+ 面板据此退回单一目录界面。
62
+ - **Added — 面板分层条(`ui/client.js`)**。`Payload.capabilities.layers === true` 时在状态栏下方
63
+ 渲染三张层卡片(层名 / 是否有数据 / 目录缩短显示),10s 轮询;
64
+ `layerReason` 为 `orchestrator-missing` 或 `disabled-by-config` 时各说各的原因,不显示空框。
65
+ **分层条是只读的**:会话属于哪一层由 orchestrator 的 `bindSession()` 决定,不在这个面板里切换。
66
+ 设置页开关改名为「启用分层(features.layers)」,保存时只写规范键。
67
+ - **Tests — 11 个新用例(`test/v181.layers.test.js`)**:别名镜像与冲突报错、两个函数名答案一致、
68
+ 路由 GET-only 与 405、作用域原样透传、三层顺序(会话 → 项目 → 全局)、
69
+ 无 sessionId 时没有会话层、projectId 回退到 orchestrator 绑定、
70
+ 无 orchestrator / 配置关闭 / orchestrator 抛错三种降级,以及两条边界断言
71
+ (`index.js` 不出现 `projectIdFromWorkspace`、不自己 `readdir` 层目录)。
72
+ 路由表因此从 10 条增到 11 条,相关计数断言同步更新。
73
+ - **Unchanged — 存储语义**。写读仍按一个物理 `dataDir`;`?space=` 路由与
74
+ `space_transfer` / `transfer_to_global` 工具名**本轮未改**,线格式 `target_space_id` 保持原样,
75
+ 以免破坏已部署 profile 与模型侧的工具调用。
76
+
77
+ ## [1.8.0] — 2026-11-29
78
+
79
+ **新增「按物理路径寻址」的纯存储面与纯信箱面:`src/db/pureApi.js` 与 `src/db/dropbox.js`。
80
+ 它们在语义上不识别空间 / 项目 / 会话,只认一个绝对 `dataDir` 加不透明 id,
81
+ 把「这一切该落到哪个目录」的判断留给 `dsh-layers-orchestrator`。**
82
+
83
+ - **Added — 纯存储 API(`src/db/pureApi.js`)**。`write_event(dataDir, {content, ...})` 向
84
+ `<dataDir>/log` 的当前世代段追加一条记录,随后自行 flush 并关闭句柄;`recall(dataDir, query, filter)`
85
+ 只扫这一个目录并返回简单排序切片。两个 `dataDir` **天然隔离**,不经过配置单例。
86
+ 记录仍用引擎同一套 `contentHashOf` / `eventIdFor` 构造,因此 `src/log/records.js#parseRecord`
87
+ 与 `LogStore#snapshot` 照样能读——它不是旁路格式。
88
+ - **Added — 纯信箱(`src/db/dropbox.js`)**。`append_to_dropbox` / `read_dropbox` / `clear_dropbox`,
89
+ 落在 `<dataDir>/state/dropbox.jsonl`,一行一个 JSON。**红线:只存取,不判重、不摘要、不蒸馏、
90
+ 不归档**;损坏行跳过而不中断,空文件读作空信箱。
91
+ - **Design — 边界声明**。这两个模块只被新增测试导入,`index.js` / `src/webRoutes.js` / `ui/client.js`
92
+ 都**没有接线**:v1.8.0 是「先把纯地层立起来」,业务路由的剥离与 UI 的 space → layers 改名
93
+ 留给下一个版本,不会在本版改变任何既有运行时行为。
94
+ - **Tests — 18 个新用例**:`test/v180.pureApi.test.js`(11)覆盖绝对路径校验、写入-召回往返、
95
+ sessionId 过滤(含 meta 兼容)、双目录隔离、topK / since / until / kinds、同刻同文本仍得不同 id、
96
+ 文本排序,以及两条例行检查(插件可执行源码里不出现业务词、纯模块只按路径寻址);
97
+ `test/v180.dropbox.test.js`(7)覆盖缺失文件、损坏行、外部 id、双目录独立。
98
+
99
+ > 验证方式注意:`node --test <file>` 在受限沙箱下会以 `EPERM spawn` 失败(它要派生每个文件的子进程),
100
+ > **那不是测试失败**。本仓库自带 `node test/run.mjs` 的进程内运行器,正是为这种情况准备的。
101
+
7
102
  ## [1.7.4] — 2026-11-28
8
103
 
9
104
  **图谱从「640×320 里挤沙子」变成可缩放的布局世界;节点按事件数自动收敛到 80;
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  | | |
9
9
  | --- | --- |
10
- | 版本 | **1.7.4** |
10
+ | 版本 | **1.9.1** |
11
11
  | 包名 | `dsh-layers-hippocampus` |
12
12
  | 仓库 | <https://github.com/382quaii/dsh-Layers-Hippocampus> |
13
13
  | 许可证 | MIT |
@@ -109,10 +109,25 @@
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)**:`dream.useLlm` 一直是 `true`,但 LLM 原本只有
113
+ 「显式 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
+ - **「空间」与「分层」是两回事,别混着叫(1.9.0)**:`space` 是**物理目录**(可建、可删、可迁移),
119
+ `layer` 是**业务语义**(`session` / `project` / `public`)。海马体不该知道「当前会话属于哪个项目」,
120
+ 所以配置主键换成 `features.layers`(`features.multiSpace` 保留为别名,解析后两者始终镜像;
121
+ 两个键互相矛盾直接报 `MEM_E_CONFIG_OUT_OF_RANGE`),能力握手同时给出
122
+ `capabilities.layers` / `layerReason` 与旧的 `spaces` / `multiSpaceReason`。
123
+ 新路由 `GET /api/hippocampus/layers` **只读**,目录一律由 `dsh-orchestrator` 算
124
+ (`layers.dirsFor()` + `bindingOf()`),海马体只转发作用域并探一下有没有数据;
125
+ 没有 orchestrator 或配置关闭时返回 `200 { available:false, layers:[] }`,面板退回单一目录界面。
126
+ 面板在 `layers:true` 时显示三层目录卡片,**不可点、不可切换**——归属由编排器的 `bindSession()` 决定。
127
+ - **多空间开关会说明自己为什么没生效(1.6.7,M6)**:`features.layers`(旧名 `features.multiSpace`)
128
+ 默认 `true`,但只有注入了能创建空间适配器的 `orchestrator` 服务时才真正运行。以前两者的差异是静默的
129
+ ——「我开了分层」和「我实际在单目录」可以同时为真。现在
130
+ `capabilities.layerRequested` / `capabilities.layerReason`
116
131
  (`active` / `disabled-by-config` / `orchestrator-missing`)一起返回,
117
132
  `panel.spaces.{requested,reason}` 同样如此,设置页会直接写明是哪一种。
118
133
  **默认值没有改动**:改默认会静默改变已部署 profile 的行为。
@@ -242,6 +257,30 @@ raw 层提供三档,覆盖从“只留关键”到“全留”:
242
257
  - **上限剪枝**:`salience × 3.9` 是分数硬上界,候选按 salience 降序早停,长尾不再计算 decay。
243
258
  - 全量 Web 面板:图谱、标签树、记忆列表、空间管理、设置页、raw 归档与索引统计。
244
259
 
260
+ ### 纯存储面:按路径寻址的「笨数据库」(1.8.0)
261
+
262
+ `src/db/` 是给编排层用的**无业务语义**接口:只认一个绝对 `dataDir` 加不透明 id,
263
+ 不认识空间 / 项目 / 会话,两个目录天然隔离。
264
+
265
+ | 模块 | 导出 | 落盘位置 |
266
+ | --- | --- | --- |
267
+ | `src/db/pureApi.js` | `write_event` / `recall` | `<dataDir>/log`(与引擎同一套记录格式) |
268
+ | `src/db/dropbox.js` | `append_to_dropbox` / `read_dropbox` / `clear_dropbox` | `<dataDir>/state/dropbox.jsonl` |
269
+
270
+ ```js
271
+ import { write_event, recall } from 'dsh-layers-hippocampus/src/db/pureApi.js';
272
+ import { read_dropbox, clear_dropbox } from 'dsh-layers-hippocampus/src/db/dropbox.js';
273
+
274
+ write_event('D:/mem/sessions/abc', { content: '用户偏好极简风格', tags: ['preference'] });
275
+ const hits = recall('D:/mem/sessions/abc', '偏好', { topK: 5 });
276
+
277
+ const notes = read_dropbox('D:/mem/sessions/abc'); // 原样返回,不判重不摘要
278
+ clear_dropbox('D:/mem/sessions/abc');
279
+ ```
280
+
281
+ **红线**:信箱只存取。判重、摘要、蒸馏、归档一律属于 `dsh-layers-orchestrator`。
282
+ 本版仅新增模块与测试,**未接线**到任何既有路由或 UI。
283
+
245
284
  ---
246
285
 
247
286
  ## 快速开始
@@ -253,7 +292,7 @@ raw 层提供三档,覆盖从“只留关键”到“全留”:
253
292
  pnpm add dsh-layers-hippocampus
254
293
 
255
294
  # 或从 GitHub 指定 tag
256
- pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.7.4"
295
+ pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.9.1"
257
296
  ```
258
297
 
259
298
  ### 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.1',
83
83
  spaces: true,
84
84
  memories: true,
85
85
  transferConsent: true,
@@ -247,10 +247,87 @@ 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
+ for await (const chunk of llm.stream(options)) {
305
+ if (!chunk || typeof chunk !== 'object') continue;
306
+ if (chunk.type === 'text-delta' && typeof chunk.text === 'string') text += chunk.text;
307
+ else if (chunk.type === 'block-end' && chunk.block?.type === 'text' && typeof chunk.block.text === 'string') {
308
+ // Prefer deltas when the adapter emits them; otherwise take the block.
309
+ if (text.length === 0) text += chunk.block.text;
310
+ } else if (chunk.type === 'finish' && chunk.reason?.kind === 'error') {
311
+ const failure = chunk.reason.failure ?? {};
312
+ throw new MemoryError(
313
+ ErrorCodes.DREAM_LLM_FALLBACK,
314
+ `host model call failed: ${failure.message ?? 'unknown error'}`,
315
+ { phase: 'host', transport: 'host', code: failure.code ?? null },
316
+ );
317
+ }
318
+ }
319
+ return text;
320
+ },
321
+ };
322
+ };
250
323
  const multiSpaceExtras = () => {
324
+ // v1.9.1: every Memory instance (root, child space, migrated, reloaded) gets the
325
+ // same host-model seam, so Dream behaves identically wherever it runs.
326
+ const base = { hostLlm: hostLlmSeam() };
251
327
  const orchestrator = orchestratorService();
252
- if (typeof orchestrator?.createSpaceAdapter !== 'function') return {};
328
+ if (typeof orchestrator?.createSpaceAdapter !== 'function') return base;
253
329
  return {
330
+ ...base,
254
331
  spacesFactory: (owner) =>
255
332
  orchestrator.createSpaceAdapter({
256
333
  owner,
@@ -1758,6 +1835,70 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
1758
1835
  return multiSpaceReason(runtime.config, typeof orchestrator?.createSpaceAdapter === 'function');
1759
1836
  };
1760
1837
 
1838
+ /**
1839
+ * v1.9.0: the LAYERED view of the same capability.
1840
+ *
1841
+ * The hippocampus still stores one directory at a time and still cannot tell a
1842
+ * "session" from a "project" — that decision stays in the orchestrator. What this
1843
+ * exposes is only what the orchestrator already computed: which physical
1844
+ * directory each layer means for a given conversation. With no orchestrator, or
1845
+ * with `features.layers: false`, the answer is an empty list and the client
1846
+ * degrades to the plain directory selector instead of inventing layers.
1847
+ */
1848
+ runtime.layersAvailable = () => {
1849
+ const orchestrator = orchestratorService();
1850
+ return layersActive(runtime.config, typeof orchestrator?.createSpaceAdapter === 'function');
1851
+ };
1852
+
1853
+ runtime.layersReason = () => {
1854
+ const orchestrator = orchestratorService();
1855
+ return layersReason(runtime.config, typeof orchestrator?.createSpaceAdapter === 'function');
1856
+ };
1857
+
1858
+ /**
1859
+ * Resolve the layer directories for one conversation scope.
1860
+ *
1861
+ * `sessionId` is optional: without it a session layer simply does not exist (a
1862
+ * conversation that was never bound has no private directory), and the list is
1863
+ * project + public. `exists` is a plain `fs.existsSync` — a layer that has never
1864
+ * been written is reported as present-but-empty rather than hidden, so the panel
1865
+ * can show "public: empty" instead of making the row silently disappear.
1866
+ */
1867
+ runtime.layerList = ({ sessionId = null, projectId = null } = {}) => {
1868
+ const orchestrator = orchestratorService();
1869
+ const layersApi = orchestrator?.layers;
1870
+ if (!runtime.layersAvailable() || typeof layersApi?.dirsFor !== 'function') return [];
1871
+ let binding = null;
1872
+ try {
1873
+ binding = sessionId && typeof orchestrator.bindingOf === 'function' ? orchestrator.bindingOf(sessionId) : null;
1874
+ } catch {
1875
+ binding = null; // an orchestrator that throws here must not break the panel
1876
+ }
1877
+ const resolvedProject = projectId ?? binding?.projectId ?? null;
1878
+ let dirs = {};
1879
+ try {
1880
+ dirs = layersApi.dirsFor({ sessionId: sessionId ?? null, projectId: resolvedProject }) ?? {};
1881
+ } catch {
1882
+ return [];
1883
+ }
1884
+ return ['session', 'project', 'public']
1885
+ .filter((layer) => typeof dirs[layer] === 'string' && dirs[layer].length > 0)
1886
+ .map((layer) => ({ layer, dir: dirs[layer], exists: fs.existsSync(dirs[layer]) }));
1887
+ };
1888
+
1889
+ /** Route payload for `GET /api/hippocampus/layers`. */
1890
+ runtime.layersPayload = ({ sessionId = null, projectId = null } = {}) => {
1891
+ const available = runtime.layersAvailable();
1892
+ return {
1893
+ ok: true,
1894
+ available,
1895
+ reason: runtime.layersReason(),
1896
+ scope: { sessionId: sessionId ?? null, projectId: projectId ?? null },
1897
+ layers: available ? runtime.layerList({ sessionId, projectId }) : [],
1898
+ capabilities: runtime.capabilities?.() ?? null,
1899
+ };
1900
+ };
1901
+
1761
1902
  /**
1762
1903
  * Capability handshake read by the client bundle (old host → new UI safety).
1763
1904
  * v1.5.6: function, not a constant — the feature flags can change live and the
@@ -1767,6 +1908,14 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
1767
1908
  ...CAPABILITIES,
1768
1909
  spaces: runtime.multiSpaceAvailable(),
1769
1910
  multiSpace: runtime.multiSpaceAvailable(),
1911
+ // v1.9.0: the same capability under its canonical name. A client that knows
1912
+ // about layers checks THIS flag and renders the three layers; a client that
1913
+ // predates it keeps reading `spaces` and degrades to the directory selector.
1914
+ layers: runtime.layersAvailable(),
1915
+ layerReason: runtime.layersReason(),
1916
+ // v1.9.0: the CONFIGURED intent next to the effective answer, exactly like
1917
+ // `multiSpaceRequested` below — "I asked for it" and "it is running" differ.
1918
+ layerRequested: runtime.config.features.layers !== false,
1770
1919
  // v1.6.7 (M6): the CONFIGURED intent and the reason the effective answer may
1771
1920
  // differ. `multiSpaceRequested` mirrors `features.multiSpace`; `multiSpaceReason`
1772
1921
  // is 'active' | 'disabled-by-config' | 'orchestrator-missing'.
@@ -2491,6 +2640,9 @@ function uiConfig(config) {
2491
2640
  cooldownMinutes: config.dream.cooldownMinutes,
2492
2641
  compensateAfterHours: config.dream.compensateAfterHours,
2493
2642
  onlyLowValley: config.dream.onlyLowValley,
2643
+ // v1.9.1: the transport policy only. The endpoint/credential below it stays
2644
+ // out of this view — it must never round-trip through the browser.
2645
+ llm: { useHost: config.dream.llm.useHost !== false },
2494
2646
  },
2495
2647
  // Convenience mirrors kept for older clients; the form uses the nested form.
2496
2648
  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.1",
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",
package/src/config.js CHANGED
@@ -163,9 +163,12 @@ export const DEFAULT_CONFIG = Object.freeze({
163
163
  autoMaintainOnBoot: true,
164
164
  enableDream: true,
165
165
  dreamIdleMinutes: 180,
166
- // v1.5.5: offline semantic distillation. The LLM leg is optional — when
167
- // `dream.llm` is not configured the engine silently uses the deterministic local
168
- // merge (and logs MEM_E_DREAM_LLM_FALLBACK), so Dream always completes.
166
+ // v1.5.5: offline semantic distillation. The LLM leg is optional.
167
+ // v1.9.1: the DEFAULT leg is now the Host's own model (`dream.llm.useHost`), so a
168
+ // fresh install distils with the model the user already signed in to and never
169
+ // needs an endpoint or a copied API key. An explicit `dream.llm.{baseUrl,model,
170
+ // apiKey}` remains the override; with neither available the deterministic local
171
+ // merge runs and MEM_E_DREAM_LLM_FALLBACK is logged, so Dream always completes.
169
172
  dream: Object.freeze({
170
173
  useLlm: true,
171
174
  minGroupSize: 3,
@@ -182,7 +185,7 @@ export const DEFAULT_CONFIG = Object.freeze({
182
185
  // v1.5.6 local scheduler: LLM Dream waits for the DeepSeek low-valley window
183
186
  // (Beijing 09–12 / 14–18 are peak) instead of requiring an external price plugin.
184
187
  onlyLowValley: true,
185
- llm: Object.freeze({ baseUrl: null, model: null, apiKey: null }),
188
+ llm: Object.freeze({ useHost: true, baseUrl: null, model: null, apiKey: null }),
186
189
  }),
187
190
  enableReflection: true,
188
191
  // Edges returned by /api/memory/graph. The offline cache may hold up to
@@ -371,10 +374,19 @@ export const DEFAULT_CONFIG = Object.freeze({
371
374
  // code fence, HTTP status, file path, task statement). `autoTag:false` disables
372
375
  // the heuristic entirely (manual behaviour stays unchanged either way).
373
376
  tagging: Object.freeze({ autoTag: true, maxTags: 2 }),
374
- // v1.5.6 microkernel boundary. Default ON so behaviour is unchanged; turning
375
- // multiSpace off makes the engine a strict single-space core (targetSpaceId must
376
- // be "default"), and crossSpaceTransfer requires multiSpace.
377
- features: Object.freeze({ multiSpace: true, crossSpaceTransfer: true, crossSpaceRecall: false }),
377
+ // v1.5.6 microkernel boundary. Default ON so behaviour is unchanged.
378
+ // v1.9.0: `layers` is the canonical name — the three physical directories the
379
+ // orchestrator fills (session / project / public). `multiSpace` is the older
380
+ // name for the SAME switch and stays accepted as a deprecated alias so a
381
+ // deployed profile keeps booting. Turning it off makes the engine a strict
382
+ // single-directory core (targetSpaceId must be "default"), and
383
+ // crossSpaceTransfer requires it.
384
+ features: Object.freeze({
385
+ layers: true,
386
+ multiSpace: true,
387
+ crossSpaceTransfer: true,
388
+ crossSpaceRecall: false,
389
+ }),
378
390
  // v1.5.6 L2 multi-merge: condense duplicate same-tag episodes into one record,
379
391
  // pinned and ordinary groups strictly separated. Offline (maintain) only.
380
392
  l2Merge: Object.freeze({ enabled: true, minGroupSize: 2, maxGroupsPerRun: 5, maxSummaryChars: 400 }),
@@ -596,34 +608,47 @@ function normaliseRaw(raw) {
596
608
  }
597
609
 
598
610
  /**
599
- * v1.5.6: multi-space is a CAPABILITY, not a config promise. It is active only when
600
- * the Host provides the Orchestrator service AND the profile has not turned
601
- * `features.multiSpace` off; otherwise the engine runs the strict single-space core.
611
+ * v1.9.0: the layered world is a CAPABILITY, not a config promise. It is active only
612
+ * when the Host provides the Orchestrator service AND the profile has not turned
613
+ * `features.layers` off; otherwise the engine runs the strict single-directory core.
614
+ *
615
+ * `features.multiSpace` is the deprecated alias for the same switch; the resolver
616
+ * keeps both keys in sync, so either name reads the same effective value.
602
617
  */
603
- export function multiSpaceActive(config, hasOrchestrator) {
604
- return hasOrchestrator === true && config?.features?.multiSpace !== false;
618
+ export function layersActive(config, hasOrchestrator) {
619
+ return hasOrchestrator === true && config?.features?.layers !== false;
605
620
  }
606
621
 
607
622
  /**
608
- * v1.6.7 (M6): WHY multi-space is on or off, so a caller never has to guess whether
609
- * `features.multiSpace: true` was honoured.
623
+ * v1.6.7 (M6): WHY the layered world is on or off, so a caller never has to guess
624
+ * whether `features.layers: true` was honoured.
610
625
  *
611
- * Before this, the default `features.multiSpace: true` combined with
612
- * `multiSpaceActive()` returning false whenever no adapter was injected meant a user
613
- * who explicitly enabled the feature silently got single-space behaviour with no
614
- * explanation. The flag now reports one of three states instead of a bare boolean.
626
+ * The default is `true`, but the effective answer is false whenever no adapter was
627
+ * injected — a user who explicitly enabled the feature would otherwise silently get
628
+ * single-directory behaviour with no explanation. The flag reports one of three
629
+ * states instead of a bare boolean.
615
630
  *
616
631
  * @param {object} config resolved config
617
632
  * @param {boolean} hasOrchestrator true when an injected `orchestrator` service can
618
- * actually create a space adapter
633
+ * actually create a layer adapter
619
634
  * @returns {'active'|'disabled-by-config'|'orchestrator-missing'}
620
635
  */
621
- export function multiSpaceReason(config, hasOrchestrator) {
622
- if (config?.features?.multiSpace === false) return 'disabled-by-config';
636
+ export function layersReason(config, hasOrchestrator) {
637
+ if (config?.features?.layers === false) return 'disabled-by-config';
623
638
  if (hasOrchestrator !== true) return 'orchestrator-missing';
624
639
  return 'active';
625
640
  }
626
641
 
642
+ /** @deprecated v1.9.0 — use `layersActive`. Kept so older callers keep working. */
643
+ export function multiSpaceActive(config, hasOrchestrator) {
644
+ return layersActive(config, hasOrchestrator);
645
+ }
646
+
647
+ /** @deprecated v1.9.0 — use `layersReason`. Kept so older callers keep working. */
648
+ export function multiSpaceReason(config, hasOrchestrator) {
649
+ return layersReason(config, hasOrchestrator);
650
+ }
651
+
627
652
  /**
628
653
  * Migrate a config object from any older schema to the current one.
629
654
  *
@@ -1348,25 +1373,47 @@ function buildResolvedConfig(raw = {}, { env = process.env } = {}) {
1348
1373
  if (!isPlainObject(featuresIn)) {
1349
1374
  throw configError(ErrorCodes.CONFIG_INVALID_TYPE, 'config.features must be an object', { key: 'features' });
1350
1375
  }
1351
- const featureMultiSpace = requireBoolean(
1352
- featuresIn.multiSpace === undefined ? defaults.features.multiSpace : featuresIn.multiSpace,
1353
- 'features.multiSpace',
1354
- );
1376
+ // v1.9.0: `layers` is canonical and `multiSpace` is its deprecated alias. When
1377
+ // BOTH are written they must agree — silently preferring one would let a profile
1378
+ // say "off" in one key and "on" in the other, which is exactly the kind of
1379
+ // unexplained capability flip this config layer refuses to allow.
1380
+ const featuresLayersWanted =
1381
+ featuresIn.layers === undefined
1382
+ ? featuresIn.multiSpace === undefined
1383
+ ? defaults.features.layers
1384
+ : featuresIn.multiSpace
1385
+ : featuresIn.layers;
1386
+ const featureLayers = requireBoolean(featuresLayersWanted, 'features.layers');
1387
+ if (
1388
+ featuresIn.layers !== undefined &&
1389
+ featuresIn.multiSpace !== undefined &&
1390
+ featuresIn.layers !== featuresIn.multiSpace
1391
+ ) {
1392
+ throw configError(
1393
+ ErrorCodes.CONFIG_OUT_OF_RANGE,
1394
+ 'config.features.layers and the deprecated config.features.multiSpace disagree; set only features.layers',
1395
+ { key: 'features.layers', layers: featuresIn.layers, multiSpace: featuresIn.multiSpace },
1396
+ );
1397
+ }
1398
+ // Kept as a mirror of `layers` (not an independent switch) so every existing
1399
+ // reader — UI, tests, a deployed profile's own tooling — keeps seeing the value
1400
+ // it already understands.
1401
+ const featureMultiSpace = featureLayers;
1355
1402
  const featureCrossSpaceTransfer = requireBoolean(
1356
1403
  featuresIn.crossSpaceTransfer === undefined
1357
- ? // Turning multi-space off implies no cross-space transfer: require the
1404
+ ? // Turning the layered world off implies no cross-space transfer: require the
1358
1405
  // operator to opt back IN explicitly, never the other way around.
1359
- featureMultiSpace
1406
+ featureLayers
1360
1407
  ? defaults.features.crossSpaceTransfer
1361
1408
  : false
1362
1409
  : featuresIn.crossSpaceTransfer,
1363
1410
  'features.crossSpaceTransfer',
1364
1411
  );
1365
- if (featureCrossSpaceTransfer && !featureMultiSpace) {
1412
+ if (featureCrossSpaceTransfer && !featureLayers) {
1366
1413
  throw configError(
1367
1414
  ErrorCodes.CONFIG_OUT_OF_RANGE,
1368
- 'config.features.crossSpaceTransfer requires features.multiSpace (a single-space core has no target space)',
1369
- { key: 'features.crossSpaceTransfer', multiSpace: false },
1415
+ 'config.features.crossSpaceTransfer requires features.layers (a single-directory core has no target space)',
1416
+ { key: 'features.crossSpaceTransfer', layers: false },
1370
1417
  );
1371
1418
  }
1372
1419
  // v1.5.6: cross-space recall aggregation is OPT-IN (and off by default): it
@@ -1375,14 +1422,15 @@ function buildResolvedConfig(raw = {}, { env = process.env } = {}) {
1375
1422
  featuresIn.crossSpaceRecall === undefined ? defaults.features.crossSpaceRecall : featuresIn.crossSpaceRecall,
1376
1423
  'features.crossSpaceRecall',
1377
1424
  );
1378
- if (featureCrossSpaceRecall && !featureMultiSpace) {
1425
+ if (featureCrossSpaceRecall && !featureLayers) {
1379
1426
  throw configError(
1380
1427
  ErrorCodes.CONFIG_OUT_OF_RANGE,
1381
- 'config.features.crossSpaceRecall requires features.multiSpace (a single-space core has only one space)',
1382
- { key: 'features.crossSpaceRecall', multiSpace: false },
1428
+ 'config.features.crossSpaceRecall requires features.layers (a single-directory core has only one space)',
1429
+ { key: 'features.crossSpaceRecall', layers: false },
1383
1430
  );
1384
1431
  }
1385
1432
  const featuresConfig = Object.freeze({
1433
+ layers: featureLayers,
1386
1434
  multiSpace: featureMultiSpace,
1387
1435
  crossSpaceTransfer: featureCrossSpaceTransfer,
1388
1436
  crossSpaceRecall: featureCrossSpaceRecall,
@@ -1527,6 +1575,13 @@ function buildResolvedConfig(raw = {}, { env = process.env } = {}) {
1527
1575
  'dream.onlyLowValley',
1528
1576
  ),
1529
1577
  llm: {
1578
+ // v1.9.1: which TRANSPORT offline Dream uses. `useHost` (default on) calls
1579
+ // the Host's own model, so Dream works with no endpoint and no credential;
1580
+ // the three keys below are the explicit override for a separate endpoint.
1581
+ useHost: requireBoolean(
1582
+ dreamLlmIn.useHost === undefined ? defaults.dream.llm.useHost : dreamLlmIn.useHost,
1583
+ 'dream.llm.useHost',
1584
+ ),
1530
1585
  baseUrl: optionalString(dreamLlmIn.baseUrl, 'dream.llm.baseUrl'),
1531
1586
  model: optionalString(dreamLlmIn.model, 'dream.llm.model'),
1532
1587
  apiKey: optionalString(dreamLlmIn.apiKey, 'dream.llm.apiKey'),