dsh-layers-hippocampus 1.9.1 → 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,36 @@ 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
+
7
37
  ## [1.9.1] — 2026-11-29
8
38
 
9
39
  **Dream 真正接上 LLM:默认走宿主自己的模型,不再需要 endpoint 与 API key。**
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  | | |
9
9
  | --- | --- |
10
- | 版本 | **1.9.1** |
10
+ | 版本 | **1.9.2** |
11
11
  | 包名 | `dsh-layers-hippocampus` |
12
12
  | 仓库 | <https://github.com/382quaii/dsh-Layers-Hippocampus> |
13
13
  | 许可证 | MIT |
@@ -109,12 +109,16 @@
109
109
  `context.injectMode = 'full'` 是旧行为的一键回退(正文直接进 Prompt,按整段计费)。
110
110
  `[Memory Blocks]` 标记名与缓存前缀语义保持不变;`briefing` 块(运营方钉死的策略)
111
111
  永不降级为指针。
112
- - **Dream 默认就用你现在这个模型(1.9.1)**:`dream.useLlm` 一直是 `true`,但 LLM 原本只有
113
- 「显式 OpenAI 兼容端点」一条通道,而端点和 API key 只能写在 profile(UI/HTTP 故意不接受凭据),
112
+ - **Dream 默认就用你现在这个模型(1.9.1),并给了它足够答完的预算(1.9.2)**:`dream.useLlm` 一直是 `true`,
113
+ 但 LLM 原本只有「显式 OpenAI 兼容端点」一条通道,而端点和 API key 只能写在 profile(UI/HTTP 故意不接受凭据),
114
114
  于是全新安装的每次 Dream 都在走确定性兜底。现在默认走**宿主自己的模型**
115
115
  (`ctx.get('llm')` + `agentDefaultModel.currentSelection()`),无需配置任何 endpoint 或 key;
116
116
  传输优先级是 `host → http → 本地兜底`,`dream.llm.useHost: false`(或 `DSH_DREAM_LLM_HOST=0`)
117
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`,**从不记录模型返回的正文**。
118
122
  - **「空间」与「分层」是两回事,别混着叫(1.9.0)**:`space` 是**物理目录**(可建、可删、可迁移),
119
123
  `layer` 是**业务语义**(`session` / `project` / `public`)。海马体不该知道「当前会话属于哪个项目」,
120
124
  所以配置主键换成 `features.layers`(`features.multiSpace` 保留为别名,解析后两者始终镜像;
@@ -292,7 +296,7 @@ clear_dropbox('D:/mem/sessions/abc');
292
296
  pnpm add dsh-layers-hippocampus
293
297
 
294
298
  # 或从 GitHub 指定 tag
295
- pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.9.1"
299
+ pnpm add "github:382quaii/dsh-Layers-Hippocampus#v1.9.2"
296
300
  ```
297
301
 
298
302
  ### 2. 挂到 profile
package/index.js CHANGED
@@ -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.9.1',
82
+ version: '1.9.2',
83
83
  spaces: true,
84
84
  memories: true,
85
85
  transferConsent: true,
@@ -301,22 +301,42 @@ export function createRuntime({ ctx = null, config, options, clock, raw = null,
301
301
  ...(signal ? { signal } : {}),
302
302
  };
303
303
  let text = '';
304
+ let reasoningChars = 0;
305
+ let finishKind = null;
306
+ let sawDelta = false;
304
307
  for await (const chunk of llm.stream(options)) {
305
308
  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') {
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') {
308
318
  // 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
- );
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
+ }
317
330
  }
318
331
  }
319
- return text;
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
+ };
320
340
  },
321
341
  };
322
342
  };
@@ -2642,7 +2662,11 @@ function uiConfig(config) {
2642
2662
  onlyLowValley: config.dream.onlyLowValley,
2643
2663
  // v1.9.1: the transport policy only. The endpoint/credential below it stays
2644
2664
  // out of this view — it must never round-trip through the browser.
2645
- llm: { useHost: config.dream.llm.useHost !== false },
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
+ },
2646
2670
  },
2647
2671
  // Convenience mirrors kept for older clients; the form uses the nested form.
2648
2672
  eventTimePolicy: config.identity.eventTimePolicy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-layers-hippocampus",
3
- "version": "1.9.1",
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",
package/src/config.js CHANGED
@@ -185,7 +185,7 @@ export const DEFAULT_CONFIG = Object.freeze({
185
185
  // v1.5.6 local scheduler: LLM Dream waits for the DeepSeek low-valley window
186
186
  // (Beijing 09–12 / 14–18 are peak) instead of requiring an external price plugin.
187
187
  onlyLowValley: true,
188
- llm: Object.freeze({ useHost: true, baseUrl: null, model: null, apiKey: null }),
188
+ llm: Object.freeze({ useHost: true, maxTokens: 1200, baseUrl: null, model: null, apiKey: null }),
189
189
  }),
190
190
  enableReflection: true,
191
191
  // Edges returned by /api/memory/graph. The offline cache may hold up to
@@ -1582,6 +1582,15 @@ function buildResolvedConfig(raw = {}, { env = process.env } = {}) {
1582
1582
  dreamLlmIn.useHost === undefined ? defaults.dream.llm.useHost : dreamLlmIn.useHost,
1583
1583
  'dream.llm.useHost',
1584
1584
  ),
1585
+ // v1.9.2: the OUTPUT budget for one distillation. The engine used to derive
1586
+ // it from `maxSummaryChars` alone (`chars*2+64` = 464 by default), which a
1587
+ // reasoning model spends on reasoning and then runs out of room before the
1588
+ // closing brace — the answer arrives with no `{` and every run fell back.
1589
+ maxTokens: requireInteger(
1590
+ dreamLlmIn.maxTokens === undefined ? defaults.dream.llm.maxTokens : dreamLlmIn.maxTokens,
1591
+ 'dream.llm.maxTokens',
1592
+ { min: 128, max: 16_000 },
1593
+ ),
1585
1594
  baseUrl: optionalString(dreamLlmIn.baseUrl, 'dream.llm.baseUrl'),
1586
1595
  model: optionalString(dreamLlmIn.model, 'dream.llm.model'),
1587
1596
  apiKey: optionalString(dreamLlmIn.apiKey, 'dream.llm.apiKey'),
package/src/dream.js CHANGED
@@ -49,7 +49,13 @@ export const DEFAULT_DREAM_CONFIG = Object.freeze({
49
49
  // out of the box with no endpoint and no credential to copy; `baseUrl`/`model`/
50
50
  // `apiKey` stay as an explicit override for a deployment that wants a separate
51
51
  // endpoint for offline work.
52
- llm: Object.freeze({ useHost: true, baseUrl: null, model: null, apiKey: null }),
52
+ //
53
+ // v1.9.2: `maxTokens` is the OUTPUT budget for one distillation. Deriving it from
54
+ // `maxSummaryChars` alone produced 464 tokens by default; a reasoning model
55
+ // spends that on reasoning and never reaches the closing brace, so EVERY run
56
+ // degraded with "answer is not a JSON object". 1200 leaves room for a short
57
+ // summary plus reasoning.
58
+ llm: Object.freeze({ useHost: true, maxTokens: 1200, baseUrl: null, model: null, apiKey: null }),
53
59
  });
54
60
 
55
61
  function isPlainObject(value) {
@@ -89,6 +95,8 @@ export function resolveDreamConfig(input = {}, env = process.env) {
89
95
  cooldownMinutes: finiteInt(raw.cooldownMinutes, DEFAULT_DREAM_CONFIG.cooldownMinutes, 1, 1440),
90
96
  llm: {
91
97
  useHost: resolveUseHost(llmIn.useHost, env),
98
+ // v1.9.2: output budget for one distillation (see DEFAULT_DREAM_CONFIG).
99
+ maxTokens: finiteInt(llmIn.maxTokens, DEFAULT_DREAM_CONFIG.llm.maxTokens, 128, 16_000),
92
100
  baseUrl: pickString(llmIn.baseUrl) ?? pickString(env?.DSH_DREAM_LLM_BASE_URL),
93
101
  model: pickString(llmIn.model) ?? pickString(env?.DSH_DREAM_LLM_MODEL),
94
102
  apiKey: pickString(llmIn.apiKey) ?? pickString(env?.DSH_DREAM_LLM_API_KEY),
@@ -167,7 +175,15 @@ export function parseDistillation(text, { maxSummaryChars = 200 } = {}) {
167
175
  const start = fenced.indexOf('{');
168
176
  const end = fenced.lastIndexOf('}');
169
177
  if (start < 0 || end <= start) {
170
- throw new MemoryError(DREAM_FALLBACK_CODE, 'dream LLM answer is not a JSON object', { phase: 'format' });
178
+ // v1.9.2: an answer with no braces is almost always a CUT-OFF answer, so the
179
+ // error carries what is needed to tell the two apart later: how long it was
180
+ // and whether a brace appeared at all. The TEXT itself is never recorded —
181
+ // it is derived from memory sources and must not reach a panel or a log.
182
+ throw new MemoryError(DREAM_FALLBACK_CODE, 'dream LLM answer is not a JSON object', {
183
+ phase: 'format',
184
+ chars: text.length,
185
+ hasBrace: start >= 0,
186
+ });
171
187
  }
172
188
  let parsed;
173
189
  try {
@@ -380,12 +396,24 @@ export class DreamEngine {
380
396
 
381
397
  _warn(logger, { tag, reason, at, error }) {
382
398
  const message = `[${DREAM_FALLBACK_CODE}] dream LLM fallback: ${reason} (tag=${tag})`;
399
+ // v1.9.2: keep the cheap, non-content diagnostics (phase, chars, hasBrace,
400
+ // maxTokens). They are what turns "not a JSON object" into an actionable
401
+ // answer without ever storing the model's text — which is derived from memory.
402
+ const details = error?.details ?? null;
403
+ const diagnostic = details
404
+ ? Object.fromEntries(
405
+ ['phase', 'transport', 'chars', 'hasBrace', 'maxTokens', 'timeoutMs']
406
+ .filter((key) => details[key] !== undefined)
407
+ .map((key) => [key, details[key]]),
408
+ )
409
+ : null;
383
410
  this._load().lastFallback = {
384
411
  code: DREAM_FALLBACK_CODE,
385
412
  reason,
386
413
  tag,
387
414
  at,
388
415
  error: error ? { code: error.code ?? null, message: error.message ?? String(error) } : null,
416
+ ...(diagnostic && Object.keys(diagnostic).length > 0 ? { diagnostic } : {}),
389
417
  };
390
418
  logger?.warn?.(message);
391
419
  }
@@ -510,15 +538,34 @@ export class DreamEngine {
510
538
  timer.unref?.();
511
539
  });
512
540
  const request = (async () => {
513
- const content = await this.hostLlm.chat({
541
+ const answer = await this.hostLlm.chat({
514
542
  system,
515
543
  user,
516
544
  maxTokens,
517
545
  signal: controller.signal,
518
546
  });
547
+ // v1.9.2: the seam may hand back the finish reason with the text. A model
548
+ // that ran out of OUTPUT budget has not answered badly — it was cut off, and
549
+ // saying so is the difference between "check your prompt" and "raise
550
+ // dream.llm.maxTokens".
551
+ const content = typeof answer === 'string' ? answer : answer?.text;
552
+ const finish = typeof answer === 'string' ? null : (answer?.finish ?? null);
519
553
  if (typeof content !== 'string' || content.trim().length === 0) {
520
554
  throw new MemoryError(DREAM_FALLBACK_CODE, 'host model returned no text', { phase: 'format', transport: 'host' });
521
555
  }
556
+ if (finish === 'max-tokens' && !content.includes('{')) {
557
+ throw new MemoryError(
558
+ DREAM_FALLBACK_CODE,
559
+ `host model ran out of output budget at ${maxTokens} tokens before emitting JSON`,
560
+ {
561
+ phase: 'truncated',
562
+ transport: 'host',
563
+ maxTokens,
564
+ chars: content.length,
565
+ hint: 'raise dream.llm.maxTokens (or let the model answer shorter)',
566
+ },
567
+ );
568
+ }
522
569
  return content;
523
570
  })();
524
571
  try {
@@ -599,11 +646,14 @@ export class DreamEngine {
599
646
 
600
647
  /** Distil one tag group through the shared chat call. */
601
648
  async _callLlm({ tag, sources, config }) {
649
+ // v1.9.2: `dream.llm.maxTokens` is the OUTPUT budget; the summary length is a
650
+ // floor, not the whole answer. A reasoning model needs room for both.
651
+ const maxTokens = Math.max(128, Number(config.llm?.maxTokens) || 0, Math.ceil(config.maxSummaryChars * 2) + 64);
602
652
  const content = await this._chat({
603
653
  system: systemPrompt(config),
604
654
  user: userPrompt(tag, sources, config),
605
655
  config,
606
- maxTokens: Math.max(64, Math.ceil(config.maxSummaryChars * 2) + 64),
656
+ maxTokens,
607
657
  });
608
658
  return parseDistillation(content, { maxSummaryChars: config.maxSummaryChars });
609
659
  }
@@ -640,7 +690,12 @@ export class DreamEngine {
640
690
  this._recordLlmSuccess();
641
691
  } catch (error) {
642
692
  failure = error;
643
- fallbackReason = error?.details?.phase === 'timeout' ? 'timeout' : 'llm-error';
693
+ fallbackReason =
694
+ error?.details?.phase === 'timeout'
695
+ ? 'timeout'
696
+ : error?.details?.phase === 'truncated'
697
+ ? 'llm-truncated'
698
+ : 'llm-error';
644
699
  this._recordLlmFailure(now, config);
645
700
  this._warn(logger, { tag, reason: fallbackReason, at: now, error });
646
701
  }
package/src/webRoutes.js CHANGED
@@ -146,8 +146,11 @@ export const EDITABLE_CONFIG_KEYS = Object.freeze([
146
146
  'dream.llmTimeoutMs',
147
147
  // v1.9.1: the TRANSPORT switch, not a credential — "let offline Dream use the
148
148
  // Host's own model" is a policy a person may legitimately flip from the panel.
149
- // The endpoint keys below it stay un-editable on purpose.
149
+ // The endpoint keys stay un-editable on purpose.
150
150
  'dream.llm.useHost',
151
+ // v1.9.2: the OUTPUT budget for one distillation (the first knob to raise when
152
+ // Dream reports `llm-truncated`). Not a credential either.
153
+ 'dream.llm.maxTokens',
151
154
  'dream.failureThreshold',
152
155
  'dream.cooldownMinutes',
153
156
  'dream.compensateAfterHours',
package/ui/client.js CHANGED
@@ -3129,6 +3129,8 @@
3129
3129
  // v1.9.1: transport policy (the endpoint/credential below it is never
3130
3130
  // editable here on purpose).
3131
3131
  llmUseHost: !(config.dream && config.dream.llm && config.dream.llm.useHost === false),
3132
+ // v1.9.2: the output budget — raise it when the panel reports llm-truncated.
3133
+ llmMaxTokens: Number((config.dream && config.dream.llm && config.dream.llm.maxTokens) ?? 1200),
3132
3134
  },
3133
3135
  // v1.5.6 L2 multi-merge tunables (offline maintain phase).
3134
3136
  l2Merge: {
@@ -3890,6 +3892,18 @@
3890
3892
  onChange: (value) => edit('dream.llm.useHost', value),
3891
3893
  disabled: disabled || !draft.dream.useLlm,
3892
3894
  }),
3895
+ h(Field, {
3896
+ // v1.9.2: the fix for `llm-truncated` — a reasoning model needs room to
3897
+ // think AND to answer; deriving this from maxSummaryChars was too small.
3898
+ label: 'LLM 输出预算(tokens,dream.llm.maxTokens)',
3899
+ hint: '一次提炼允许模型输出的上限。出现 llm-truncated(模型还没写完 JSON 就被截断)时先调大这里;推理型模型建议 1500 以上。',
3900
+ value: draft.dream.llmMaxTokens,
3901
+ min: 128,
3902
+ max: 16000,
3903
+ step: 1,
3904
+ onChange: (value) => edit('dream.llm.maxTokens', value),
3905
+ disabled: disabled || !draft.dream.llmUseHost,
3906
+ }),
3893
3907
  h(Field, {
3894
3908
  label: '成组最少条数(dream.minGroupSize)',
3895
3909
  value: draft.dream.minGroupSize,
@@ -4718,6 +4732,7 @@
4718
4732
  // v1.9.1: only the transport policy is writable over HTTP; the endpoint
4719
4733
  // and credential keys are deliberately absent from this form.
4720
4734
  'dream.llm.useHost': Boolean(draft.dream.llmUseHost),
4735
+ 'dream.llm.maxTokens': Number(draft.dream.llmMaxTokens),
4721
4736
  'dream.minGroupSize': Number(draft.dream.minGroupSize),
4722
4737
  'dream.maxGroupsPerRun': Number(draft.dream.maxGroupsPerRun),
4723
4738
  'dream.maxSummaryChars': Number(draft.dream.maxSummaryChars),