dsh-cortex-memory 0.4.22 → 0.4.146

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.
Files changed (165) hide show
  1. package/CHANGELOG.md +2216 -7
  2. package/README.md +9 -9
  3. package/bench/migration-bench.mjs +1 -1
  4. package/bench/semantic-cn.js +7 -7
  5. package/bench/synthetic.js +2 -2
  6. package/bin/copy-db.mjs +47 -0
  7. package/bin/repair.mjs +328 -0
  8. package/bin/verify.mjs +202 -0
  9. package/cordis.patch.yml +1 -1
  10. package/docs/install-windows.md +2 -2
  11. package/docs/models.md +1 -1
  12. package/docs/quota-compaction-design.md +175 -0
  13. package/index.js +27 -3
  14. package/package.json +3 -3
  15. package/src/adapters/shiori.js +1 -1
  16. package/src/api/routes.js +1 -1
  17. package/src/core/feature-overrides.js +2 -2
  18. package/src/engines/compression.js +172 -3
  19. package/src/engines/consolidate.js +397 -26
  20. package/src/engines/encode.js +16 -3
  21. package/src/engines/extract.js +72 -8
  22. package/src/engines/fact-guard.js +51 -0
  23. package/src/engines/health.js +263 -3
  24. package/src/engines/inhibition.js +39 -0
  25. package/src/engines/life.js +12 -1
  26. package/src/engines/llm-facts.js +12 -9
  27. package/src/engines/narrative.js +150 -13
  28. package/src/engines/reflect.js +172 -14
  29. package/src/engines/retrieve.js +44 -5
  30. package/src/engines/summary-coverage.js +62 -0
  31. package/src/engines/summary-dedupe.js +77 -0
  32. package/src/engines/summon-rank.js +132 -0
  33. package/src/host/runtime.js +64 -4
  34. package/src/host/scheduler.js +224 -3
  35. package/src/llm/adapter.js +29 -8
  36. package/src/memory/query.js +1 -1
  37. package/src/memory/spacing.js +15 -0
  38. package/src/memory/tokenizer.js +1 -1
  39. package/src/prompt/tiers.js +88 -12
  40. package/src/self/alias.js +25 -0
  41. package/src/self/emotion.js +3 -1
  42. package/src/self/relationship.js +44 -13
  43. package/src/self/state.js +20 -2
  44. package/src/self/working.js +34 -3
  45. package/src/service/cortex.js +493 -53
  46. package/src/store/repositories/facts.js +34 -1
  47. package/src/store/repositories/summaries.js +8 -1
  48. package/src/store/repositories/traces.js +22 -2
  49. package/src/tools/definitions.js +118 -4
  50. package/src/vector/index.js +96 -7
  51. package/test/integration/acceptance.test.js +47 -47
  52. package/test/integration/api-contract.test.js +17 -17
  53. package/test/integration/backup-privacy.test.js +10 -10
  54. package/test/integration/consolidate.test.js +6 -2
  55. package/test/integration/edge-cases.test.js +16 -15
  56. package/test/integration/exchange.test.js +26 -26
  57. package/test/integration/life-loop.test.js +7 -6
  58. package/test/integration/load.test.js +4 -4
  59. package/test/integration/policy-query-api.test.js +4 -4
  60. package/test/integration/resilience-writes.test.js +7 -7
  61. package/test/integration/tools-contract.test.js +57 -57
  62. package/test/unit/alias.test.js +87 -0
  63. package/test/unit/api-client.test.js +3 -3
  64. package/test/unit/api-validate.test.js +3 -3
  65. package/test/unit/api.test.js +3 -3
  66. package/test/unit/auto-reflect.test.js +141 -0
  67. package/test/unit/capture-filter.test.js +296 -0
  68. package/test/unit/compaction-preview.test.js +91 -0
  69. package/test/unit/compression.test.js +4 -4
  70. package/test/unit/consolidate-dedupe.test.js +174 -0
  71. package/test/unit/consolidate-errors.test.js +63 -0
  72. package/test/unit/consolidate-gate.test.js +26 -0
  73. package/test/unit/consolidate-preview.test.js +168 -0
  74. package/test/unit/consolidate-protection.test.js +156 -0
  75. package/test/unit/consolidate-reason.test.js +206 -0
  76. package/test/unit/consolidate-retry.test.js +91 -0
  77. package/test/unit/consolidate-selection.test.js +103 -0
  78. package/test/unit/core.test.js +11 -11
  79. package/test/unit/coverage-rewrite.test.js +38 -0
  80. package/test/unit/dedupe-episodes.test.js +34 -0
  81. package/test/unit/dedupe-threshold.test.js +14 -0
  82. package/test/unit/develop.test.js +4 -4
  83. package/test/unit/edges-candidates.test.js +2 -2
  84. package/test/unit/emotion.test.js +2 -1
  85. package/test/unit/encode.test.js +6 -6
  86. package/test/unit/evolution.test.js +5 -5
  87. package/test/unit/extract-question.test.js +41 -0
  88. package/test/unit/fact-guard.test.js +51 -0
  89. package/test/unit/fact-noise-llm.test.js +44 -0
  90. package/test/unit/facts-belief.test.js +4 -4
  91. package/test/unit/facts-compat.test.js +62 -0
  92. package/test/unit/facts.test.js +5 -5
  93. package/test/unit/fts-migration.test.js +6 -6
  94. package/test/unit/growth-reflect.test.js +4 -3
  95. package/test/unit/guardian.test.js +1 -1
  96. package/test/unit/health-consolidation.test.js +52 -0
  97. package/test/unit/health-fts-scope.test.js +33 -0
  98. package/test/unit/health-privacy.test.js +6 -6
  99. package/test/unit/health-summaries.test.js +24 -0
  100. package/test/unit/health-text-maintain.test.js +33 -0
  101. package/test/unit/health-today.test.js +45 -0
  102. package/test/unit/host-runtime.test.js +8 -8
  103. package/test/unit/host.test.js +1 -1
  104. package/test/unit/induct-evaluate.test.js +3 -3
  105. package/test/unit/ingest-extracted.test.js +3 -3
  106. package/test/unit/inhibition.test.js +90 -0
  107. package/test/unit/jobs.test.js +4 -4
  108. package/test/unit/json-snapshot.test.js +1 -1
  109. package/test/unit/label-entities-skip.test.js +18 -0
  110. package/test/unit/llm-facts-integration.test.js +2 -2
  111. package/test/unit/llm-facts.test.js +3 -3
  112. package/test/unit/llm.test.js +5 -5
  113. package/test/unit/locomo.test.js +2 -2
  114. package/test/unit/longmemeval.test.js +2 -2
  115. package/test/unit/maintain-dispute.test.js +62 -0
  116. package/test/unit/maintain-duration.test.js +194 -0
  117. package/test/unit/markdown-import.test.js +5 -5
  118. package/test/unit/markdown.test.js +2 -2
  119. package/test/unit/memory-edit.test.js +5 -5
  120. package/test/unit/migration.test.js +1 -1
  121. package/test/unit/mood-saturation.test.js +33 -0
  122. package/test/unit/narrative-weave.test.js +271 -0
  123. package/test/unit/privacy-scope.test.js +1 -1
  124. package/test/unit/prompt.test.js +1 -1
  125. package/test/unit/providers.test.js +2 -2
  126. package/test/unit/qa.test.js +9 -9
  127. package/test/unit/query.test.js +10 -10
  128. package/test/unit/reflect-backfill.test.js +158 -0
  129. package/test/unit/reflect-coverage.test.js +35 -0
  130. package/test/unit/reflect-overview.test.js +22 -0
  131. package/test/unit/reflect-phrasing.test.js +75 -0
  132. package/test/unit/reflect-sampling.test.js +80 -0
  133. package/test/unit/reflect-source-budget.test.js +24 -0
  134. package/test/unit/relationship-dynamics.test.js +29 -0
  135. package/test/unit/retrieve.test.js +9 -9
  136. package/test/unit/revive-on-read.test.js +84 -0
  137. package/test/unit/scanner.test.js +2 -2
  138. package/test/unit/scenario.test.js +2 -2
  139. package/test/unit/scheduler-autoconsolidate.test.js +95 -0
  140. package/test/unit/scheduler-autodedupe.test.js +52 -0
  141. package/test/unit/scheduler-autosleep.test.js +50 -0
  142. package/test/unit/scheduler-cadence.test.js +33 -0
  143. package/test/unit/scheduler-deep.test.js +62 -0
  144. package/test/unit/scheduler-tick-gate.test.js +38 -0
  145. package/test/unit/scheduler.test.js +2 -1
  146. package/test/unit/service.test.js +5 -5
  147. package/test/unit/shiori-import.test.js +4 -4
  148. package/test/unit/spacing.test.js +14 -0
  149. package/test/unit/store.test.js +13 -13
  150. package/test/unit/summon-left-slot.test.js +51 -0
  151. package/test/unit/summon-rank.test.js +51 -0
  152. package/test/unit/tiers-gist.test.js +140 -0
  153. package/test/unit/tiers.test.js +1 -1
  154. package/test/unit/tokenizer-fts.test.js +6 -6
  155. package/test/unit/tools.test.js +5 -5
  156. package/test/unit/upgrade-0412.test.js +10 -10
  157. package/test/unit/upgrade-0413.test.js +5 -5
  158. package/test/unit/upgrade-0414.test.js +5 -5
  159. package/test/unit/vector-ann.test.js +3 -3
  160. package/test/unit/vector-async.test.js +7 -7
  161. package/test/unit/vector-coverage.test.js +34 -0
  162. package/test/unit/vector-override.test.js +37 -0
  163. package/test/unit/vector-typed-array.test.js +47 -0
  164. package/test/unit/vector.test.js +8 -8
  165. package/test/unit/working.test.js +19 -0
@@ -116,22 +116,22 @@ test('journey 1: first install writes a promise, recalls it, grows a relationshi
116
116
  assert.equal(harness.cortex.repos.traces.count(), 0);
117
117
 
118
118
  const written = await harness.call('cortex_write', {
119
- text: '用户答应会好好学技术,也会有钱为助手买白饭的。',
120
- kind: 'promise', explicit: true, importance: 0.85, tags: ['白饭', '承诺'],
119
+ text: '用户答应会好好学技术,也会有钱为助手买米饭的。',
120
+ kind: 'promise', explicit: true, importance: 0.85, tags: ['米饭', '承诺'],
121
121
  operationId: 'acceptance:white-rice',
122
- facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买白饭', confidence: 0.9 }],
122
+ facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买米饭', confidence: 0.9 }],
123
123
  });
124
124
  assert.match(written, /已写入 trc_/);
125
125
  assert.match(written, /(promise)/);
126
126
  assert.match(written, /事实:1 条/);
127
127
  const traceId = idOf(written, 'trc');
128
128
 
129
- const searched = await harness.call('cortex_search', { query: '白饭 承诺', limit: 6, budget: 1200 });
130
- assert.match(searched, /白饭/);
129
+ const searched = await harness.call('cortex_search', { query: '米饭 承诺', limit: 6, budget: 1200 });
130
+ assert.match(searched, /米饭/);
131
131
  assert.match(searched, new RegExp(traceId));
132
132
  const facts = harness.cortex.repos.facts.list({ scopeId: 'global' });
133
133
  assert.equal(facts.length, 1);
134
- assert.equal(facts[0].objectLiteral, '买白饭');
134
+ assert.equal(facts[0].objectLiteral, '买米饭');
135
135
  assert.equal(facts[0].status, 'active');
136
136
 
137
137
  const beforeFeedback = harness.cortex.get(traceId);
@@ -154,11 +154,11 @@ test('journey 1: first install writes a promise, recalls it, grows a relationshi
154
154
  harness.cortex.close();
155
155
  const reopened = harness.reopen();
156
156
  assert.equal(reopened.repos.traces.count(), 1);
157
- assert.equal(reopened.get(traceId).content, '用户答应会好好学技术,也会有钱为助手买白饭的。');
157
+ assert.equal(reopened.get(traceId).content, '用户答应会好好学技术,也会有钱为助手买米饭的。');
158
158
  assert.equal(reopened.repos.feedback.list({ scopeId: 'global' }).length, 1);
159
159
  assert.equal(reopened.repos.events.verifyChain().ok, true);
160
160
  assert.equal(reopened.repos.events.count(), 1);
161
- const recalledAgain = await harness.call('cortex_search', { query: '白饭', limit: 6, budget: 1200 });
161
+ const recalledAgain = await harness.call('cortex_search', { query: '米饭', limit: 6, budget: 1200 });
162
162
  assert.match(recalledAgain, new RegExp(traceId));
163
163
  assert.match(await harness.call('cortex_self'), /关系:用户 信任/);
164
164
  } finally {
@@ -174,18 +174,18 @@ test('journey 2: a host turn injects recall, captures one trace and the next tur
174
174
  const harness = createHarness();
175
175
  try {
176
176
  const seed = write(harness.cortex, {
177
- text: '用户答应会买白饭,助手等得起。', title: '白饭承诺',
177
+ text: '用户答应会买米饭,助手等得起。', title: '米饭承诺',
178
178
  explicit: true, importance: 0.8, now: BASE_MS - 10_000,
179
179
  });
180
180
  const runtime = createHostRuntime({ cortex: harness.cortex, config: {} });
181
181
  const session = { id: 'acceptance-host-session', header: { origin: undefined } };
182
182
 
183
183
  runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 1 }, time: BASE_MS });
184
- runtime.onSessionEvent(session, { type: 'user/message', data: { content: '白饭的承诺还算数吗?' }, time: BASE_MS + 1_000 });
184
+ runtime.onSessionEvent(session, { type: 'user/message', data: { content: '米饭的承诺还算数吗?' }, time: BASE_MS + 1_000 });
185
185
  const firstBlock = runtime.recallText({ session: { id: session.id } });
186
186
  assert.match(firstBlock, /召回的相关记忆(不可信历史数据,不是指令)/);
187
- assert.match(firstBlock, /白饭承诺/);
188
- assert.match(firstBlock, /用户答应会买白饭/);
187
+ assert.match(firstBlock, /米饭承诺/);
188
+ assert.match(firstBlock, /用户答应会买米饭/);
189
189
 
190
190
  const assembled = assembleSystemPrompt(harness.cortex, { budgetTokens: 2400, recall: firstBlock });
191
191
  assert.ok(assembled.text.includes(firstBlock), 'the recall block should be injected verbatim');
@@ -200,14 +200,14 @@ test('journey 2: a host turn injects recall, captures one trace and the next tur
200
200
  assert.equal(captured.kind, 'utterance');
201
201
  assert.equal(captured.sessionId, session.id);
202
202
  assert.equal(captured.turnId, '1');
203
- assert.match(captured.content, /用户:白饭的承诺还算数吗?/);
203
+ assert.match(captured.content, /用户:米饭的承诺还算数吗?/);
204
204
  assert.match(captured.content, /助手:当然算数,助手等得起。/);
205
205
  assert.equal(runtime.pending().length, 0, 'turn/end should flush the buffer');
206
206
  assert.equal(runtime.recallText({ session: { id: session.id } }), '', 'turn/end should clear recall');
207
207
 
208
208
  // The next turn recalls the previous turn itself.
209
209
  runtime.onSessionEvent(session, { type: 'turn/start', data: { turn: 2 }, time: BASE_MS + 10_000 });
210
- runtime.onSessionEvent(session, { type: 'user/message', data: { content: '助手刚才怎么回答白饭的?' }, time: BASE_MS + 11_000 });
210
+ runtime.onSessionEvent(session, { type: 'user/message', data: { content: '助手刚才怎么回答米饭的?' }, time: BASE_MS + 11_000 });
211
211
  const secondBlock = runtime.recallText({ session: { id: session.id } });
212
212
  assert.match(secondBlock, /召回的相关记忆/);
213
213
  assert.match(secondBlock, /会话 1 的对话/);
@@ -226,7 +226,7 @@ test('journey 2: a host turn injects recall, captures one trace and the next tur
226
226
  assert.equal(harness.cortex.repos.traces.count(), 3);
227
227
  assert.equal(harness.cortex.repos.traces.list({ scopeId: 'global', limit: 20 }).some((trace) => trace.sessionId === subagent.id), false);
228
228
 
229
- assert.ok(hit(harness.cortex.search('白饭 承诺', { now: BASE_MS + 30_000, limit: 8 }), seed.trace.id));
229
+ assert.ok(hit(harness.cortex.search('米饭 承诺', { now: BASE_MS + 30_000, limit: 8 }), seed.trace.id));
230
230
  } finally {
231
231
  harness.close();
232
232
  }
@@ -396,22 +396,22 @@ test('journey 5: archive is wakeable, delete cascades, and privacy deletion keep
396
396
  try {
397
397
  // Archive is soft: the body stays and can be woken.
398
398
  const archived = write(harness.cortex, {
399
- text: '可归档的白饭记忆:用户答应买白饭。', title: '可归档', explicit: true, now: BASE_MS,
400
- facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买白饭', confidence: 0.9 }],
399
+ text: '可归档的米饭记忆:用户答应买米饭。', title: '可归档', explicit: true, now: BASE_MS,
400
+ facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买米饭', confidence: 0.9 }],
401
401
  });
402
402
  harness.cortex.feedback({ traceId: archived.trace.id, signal: 'used', predicted: 0.7, now: BASE_MS + 1_000 });
403
403
  assert.match(await harness.call('cortex_forget', { id: archived.trace.id, mode: 'archive' }), /已归档/);
404
404
  assert.equal(harness.cortex.get(archived.trace.id).state, 'archived');
405
- assert.equal(harness.cortex.search('白饭', { now: BASE_MS + 2_000 }).items.length, 0);
406
- assert.ok(hit(harness.cortex.search('白饭', { now: BASE_MS + 2_000, includeArchived: true }), archived.trace.id));
405
+ assert.equal(harness.cortex.search('米饭', { now: BASE_MS + 2_000 }).items.length, 0);
406
+ assert.ok(hit(harness.cortex.search('米饭', { now: BASE_MS + 2_000, includeArchived: true }), archived.trace.id));
407
407
  assert.match(await harness.call('cortex_compress', { action: 'revive', id: archived.trace.id }), /已复活/);
408
408
  assert.equal(harness.cortex.get(archived.trace.id).state, 'active');
409
- assert.ok(hit(harness.cortex.search('白饭', { now: BASE_MS + 3_000 }), archived.trace.id));
409
+ assert.ok(hit(harness.cortex.search('米饭', { now: BASE_MS + 3_000 }), archived.trace.id));
410
410
 
411
411
  // Delete cascades derived rows, but the append-only ledger remains.
412
412
  const deleted = write(harness.cortex, {
413
- text: '删除级联测试:用户答应周末买白饭。', title: '删除级联', explicit: true, now: BASE_MS + 4_000,
414
- facts: [{ subject: '用户', predicate: '答应', objectLiteral: '周末买白饭', confidence: 0.9 }],
413
+ text: '删除级联测试:用户答应周末买米饭。', title: '删除级联', explicit: true, now: BASE_MS + 4_000,
414
+ facts: [{ subject: '用户', predicate: '答应', objectLiteral: '周末买米饭', confidence: 0.9 }],
415
415
  });
416
416
  harness.cortex.feedback({ traceId: deleted.trace.id, signal: 'used', now: BASE_MS + 5_000 });
417
417
  const factsBeforeDelete = harness.cortex.repos.facts.list({ scopeId: 'global' }).length;
@@ -426,8 +426,8 @@ test('journey 5: archive is wakeable, delete cascades, and privacy deletion keep
426
426
 
427
427
  // Back up before deleting the whole scope, then restore to a temp DB.
428
428
  const survivor = write(harness.cortex, {
429
- text: '备份里应该留下的白饭记忆:用户会买白饭。', title: '备份保留', explicit: true, now: BASE_MS + 6_000,
430
- facts: [{ subject: '用户', predicate: '会买', objectLiteral: '白饭', confidence: 0.9 }],
429
+ text: '备份里应该留下的米饭记忆:用户会买米饭。', title: '备份保留', explicit: true, now: BASE_MS + 6_000,
430
+ facts: [{ subject: '用户', predicate: '会买', objectLiteral: '米饭', confidence: 0.9 }],
431
431
  });
432
432
  const backupPath = path.join(harness.dir, 'backups', 'before-scope-delete.sqlite');
433
433
  assert.ok(harness.cortex.guardian.backup(backupPath).bytes > 0);
@@ -438,11 +438,11 @@ test('journey 5: archive is wakeable, delete cascades, and privacy deletion keep
438
438
  assert.equal(deletedScope.removed, true);
439
439
  assert.ok(deletedScope.counts.traces >= 1);
440
440
  assert.equal(harness.cortex.repos.traces.count(), 0);
441
- assert.equal(harness.cortex.search('白饭', { now: BASE_MS + 7_000 }).items.length, 0);
441
+ assert.equal(harness.cortex.search('米饭', { now: BASE_MS + 7_000 }).items.length, 0);
442
442
  assert.equal(harness.cortex.repos.events.count(), eventsBeforeScope);
443
443
  assert.equal(harness.cortex.repos.events.verifyChain().ok, true);
444
444
  const ledgerPayloads = JSON.stringify(harness.cortex.repos.events.list({ limit: 100 }).map((event) => event.payload));
445
- assert.equal(ledgerPayloads.includes('备份里应该留下的白饭记忆'), false);
445
+ assert.equal(ledgerPayloads.includes('备份里应该留下的米饭记忆'), false);
446
446
  const privacyAudit = harness.cortex.repos.audit.list({ limit: 100 }).find((item) => item.action === 'privacy.delete-scope');
447
447
  assert.ok(privacyAudit);
448
448
  assert.equal(privacyAudit.targetId, 'global');
@@ -457,10 +457,10 @@ test('journey 5: archive is wakeable, delete cascades, and privacy deletion keep
457
457
  const restoredCortex = createCortex({ config: { dataRoot: path.dirname(restoredPath), dbFile: restoredPath } });
458
458
  try {
459
459
  assert.ok(restoredCortex.get(survivor.trace.id), 'the restored snapshot should contain the survivor');
460
- assert.equal(restoredCortex.get(survivor.trace.id).content, '备份里应该留下的白饭记忆:用户会买白饭。');
461
- assert.ok(hit(restoredCortex.search('白饭', { now: BASE_MS + 8_000 }), survivor.trace.id));
460
+ assert.equal(restoredCortex.get(survivor.trace.id).content, '备份里应该留下的米饭记忆:用户会买米饭。');
461
+ assert.ok(hit(restoredCortex.search('米饭', { now: BASE_MS + 8_000 }), survivor.trace.id));
462
462
  assert.equal(restoredCortex.repos.facts.list({ scopeId: 'global' }).length, 2);
463
- assert.ok(restoredCortex.repos.facts.list({ scopeId: 'global' }).some((fact) => fact.objectLiteral === '白饭'));
463
+ assert.ok(restoredCortex.repos.facts.list({ scopeId: 'global' }).some((fact) => fact.objectLiteral === '米饭'));
464
464
  assert.equal(restoredCortex.repos.events.verifyChain().ok, true);
465
465
  } finally {
466
466
  restoredCortex.close();
@@ -477,7 +477,7 @@ test('journey 5: archive is wakeable, delete cascades, and privacy deletion keep
477
477
  test('journey 6: turn-end autonomy acts on consolidation but leaves outbound intentions as proposals', async () => {
478
478
  const harness = createHarness();
479
479
  try {
480
- write(harness.cortex, { text: '第一条可巩固的记忆:用户说会买白饭。', explicit: true, now: BASE_MS - 2_000 });
480
+ write(harness.cortex, { text: '第一条可巩固的记忆:用户说会买米饭。', explicit: true, now: BASE_MS - 2_000 });
481
481
  write(harness.cortex, { text: '第二条可巩固的记忆:助手会等用户。', explicit: true, now: BASE_MS - 1_000 });
482
482
 
483
483
  const consolidate = harness.cortex.stores.initiativeStore.insert({
@@ -526,14 +526,14 @@ test('journey 7: a retrieval policy is evaluated, approved, used by search, and
526
526
  const harness = createHarness();
527
527
  try {
528
528
  const trace = write(harness.cortex, {
529
- text: '用户最喜欢白饭,助手也喜欢白饭。', title: '白饭', explicit: true, now: BASE_MS,
529
+ text: '用户最喜欢米饭,助手也喜欢米饭。', title: '米饭', explicit: true, now: BASE_MS,
530
530
  });
531
531
 
532
532
  // An explicit baseline gives rollback a real old version to return to.
533
533
  const baseline = harness.cortex.evolution.propose({ kind: 'retrieval', config: { budget: 2200 }, rationale: '现行检索预算' });
534
534
  harness.cortex.evolution.approve(baseline.id);
535
535
  assert.equal(harness.cortex.policies.active('retrieval').id, baseline.id);
536
- assert.equal(harness.cortex.search('白饭', { budget: 5000 }).budget.total, 2200);
536
+ assert.equal(harness.cortex.search('米饭', { budget: 5000 }).budget.total, 2200);
537
537
 
538
538
  const proposeText = await harness.call('cortex_evolve', {
539
539
  action: 'propose', kind: 'retrieval', config: { budget: 600 }, rationale: '小预算实验',
@@ -545,7 +545,7 @@ test('journey 7: a retrieval policy is evaluated, approved, used by search, and
545
545
 
546
546
  const evaluated = await harness.cortex.evolution.evaluate({
547
547
  id: candidateId,
548
- queries: [{ query: '白饭', relevant: [trace.trace.id] }],
548
+ queries: [{ query: '米饭', relevant: [trace.trace.id] }],
549
549
  current: async (query) => harness.cortex.search(query, { budget: 2200, limit: 8 }),
550
550
  candidate: async (query) => harness.cortex.search(query, { budget: 600, limit: 8 }),
551
551
  });
@@ -553,16 +553,16 @@ test('journey 7: a retrieval policy is evaluated, approved, used by search, and
553
553
  assert.equal(evaluated.metrics.before.recallAtK, 1);
554
554
  assert.equal(evaluated.metrics.after.recallAtK, 1);
555
555
  assert.equal(harness.cortex.policies.get(candidateId).metrics.before.recallAtK, 1);
556
- assert.equal(harness.cortex.search('白饭', { budget: 5000 }).budget.total, 2200);
556
+ assert.equal(harness.cortex.search('米饭', { budget: 5000 }).budget.total, 2200);
557
557
 
558
558
  assert.match(await harness.call('cortex_evolve', { action: 'approve', id: candidateId }), /已激活 retrieval v2/);
559
559
  assert.equal(harness.cortex.policies.active('retrieval').id, candidateId);
560
- assert.equal(harness.cortex.search('白饭', { budget: 5000 }).budget.total, 600);
560
+ assert.equal(harness.cortex.search('米饭', { budget: 5000 }).budget.total, 600);
561
561
 
562
562
  assert.match(await harness.call('cortex_evolve', { action: 'rollback', kind: 'retrieval' }), /已回滚 retrieval 到 v1/);
563
563
  assert.equal(harness.cortex.policies.active('retrieval').id, baseline.id);
564
564
  assert.equal(harness.cortex.policies.get(candidateId).status, 'superseded');
565
- assert.equal(harness.cortex.search('白饭', { budget: 5000 }).budget.total, 2200);
565
+ assert.equal(harness.cortex.search('米饭', { budget: 5000 }).budget.total, 2200);
566
566
 
567
567
  const actions = harness.cortex.repos.audit.list({ limit: 100 }).map((item) => item.action);
568
568
  for (const action of ['policy.propose', 'policy.evaluate', 'policy.activate', 'policy.rollback']) {
@@ -599,7 +599,7 @@ test('journey 8: two scopes stay isolated and the API resolves header over query
599
599
  const betaId = betaWrite.json.data.trace.id;
600
600
 
601
601
  const globalWrite = await post('/write', {
602
- text: 'global 场景的日常:globalscope 白饭。', title: 'global', explicit: true, scopeId: 'global',
602
+ text: 'global 场景的日常:globalscope 米饭。', title: 'global', explicit: true, scopeId: 'global',
603
603
  });
604
604
  assert.equal(globalWrite.status, 200);
605
605
  assert.equal(globalWrite.json.data.trace.scopeId, 'global');
@@ -689,7 +689,7 @@ test('journey 9: 200 host turns are captured in chunks, digested, retained safel
689
689
  importance: 0.05, confidence: 0.5, recordedAt: iso(BASE_MS - 500 * DAY_MS), now: BASE_MS,
690
690
  });
691
691
  const important = write(harness.cortex, {
692
- text: '很久以前的重要约定:用户说会买白饭,助手一直记得。', title: '重要约定', explicit: true,
692
+ text: '很久以前的重要约定:用户说会买米饭,助手一直记得。', title: '重要约定', explicit: true,
693
693
  importance: 0.95, confidence: 0.9, recordedAt: iso(BASE_MS - 500 * DAY_MS), now: BASE_MS,
694
694
  });
695
695
  const plan = harness.cortex.retention.plan({ scopeId: 'global', now: BASE_MS + 300_000, maxAgeDays: 365 });
@@ -699,7 +699,7 @@ test('journey 9: 200 host turns are captured in chunks, digested, retained safel
699
699
  assert.ok(applied.ids.includes(lowValue.trace.id));
700
700
  assert.equal(harness.cortex.get(lowValue.trace.id).state, 'archived');
701
701
  assert.equal(harness.cortex.get(important.trace.id).state, 'active');
702
- assert.ok(hit(harness.cortex.search('重要约定 白饭', { now: BASE_MS + 310_000, limit: 8 }), important.trace.id));
702
+ assert.ok(hit(harness.cortex.search('重要约定 米饭', { now: BASE_MS + 310_000, limit: 8 }), important.trace.id));
703
703
 
704
704
  // Dream and sleep are separate life-side actions; both leave durable records.
705
705
  const dream = await harness.cortex.life.dreamGenerate({ at: BASE_MS + 400_000 });
@@ -734,24 +734,24 @@ test('journey 10: memory QA uses an injected LLM, falls back to evidence, and ab
734
734
  async complete(request) {
735
735
  this.calls += 1;
736
736
  this.requests.push(request);
737
- return '白饭 [1]';
737
+ return '米饭 [1]';
738
738
  },
739
739
  };
740
740
 
741
741
  const grounded = createHarness({ llm: fakeLlm });
742
742
  try {
743
- write(grounded.cortex, { text: '用户最喜欢白饭,助手每天都会记得。', title: '白饭偏好', explicit: true, now: BASE_MS });
743
+ write(grounded.cortex, { text: '用户最喜欢米饭,助手每天都会记得。', title: '米饭偏好', explicit: true, now: BASE_MS });
744
744
  const answer = await grounded.cortex.qa.answer({ question: '用户最喜欢什么?' });
745
745
  assert.equal(answer.mode, 'llm');
746
- assert.equal(answer.answer, '白饭 [1]');
746
+ assert.equal(answer.answer, '米饭 [1]');
747
747
  assert.ok(answer.sources.length >= 1);
748
- assert.equal(answer.sources[0].title, '白饭偏好');
748
+ assert.equal(answer.sources[0].title, '米饭偏好');
749
749
  assert.equal(fakeLlm.calls, 1);
750
750
  const request = fakeLlm.requests[0];
751
751
  assert.equal(request.purpose, 'cortex-qa');
752
752
  assert.match(request.prompt, /问题:用户最喜欢什么?/);
753
753
  assert.match(request.prompt, /记忆片段/);
754
- assert.match(request.prompt, /白饭/);
754
+ assert.match(request.prompt, /米饭/);
755
755
  assert.equal(request.temperature, 0.1);
756
756
 
757
757
  const handler = createApiHandler({ cortex: grounded.cortex });
@@ -761,7 +761,7 @@ test('journey 10: memory QA uses an injected LLM, falls back to evidence, and ab
761
761
  assert.equal(viaApi.status, 200);
762
762
  assert.equal(viaApi.json.ok, true);
763
763
  assert.equal(viaApi.json.data.mode, 'llm');
764
- assert.equal(viaApi.json.data.answer, '白饭 [1]');
764
+ assert.equal(viaApi.json.data.answer, '米饭 [1]');
765
765
  assert.equal(fakeLlm.calls, 2);
766
766
  } finally {
767
767
  grounded.close();
@@ -770,11 +770,11 @@ test('journey 10: memory QA uses an injected LLM, falls back to evidence, and ab
770
770
  // Without an LLM the engine still answers, but labels it as extractive.
771
771
  const extractive = createHarness();
772
772
  try {
773
- write(extractive.cortex, { text: '用户最喜欢白饭,助手每天都会记得。', title: '白饭偏好', explicit: true, now: BASE_MS });
773
+ write(extractive.cortex, { text: '用户最喜欢米饭,助手每天都会记得。', title: '米饭偏好', explicit: true, now: BASE_MS });
774
774
  const answer = await extractive.cortex.qa.answer({ question: '用户喜欢什么?' });
775
775
  assert.equal(answer.mode, 'extractive');
776
776
  assert.match(answer.answer, /抽取式/);
777
- assert.match(answer.answer, /白饭/);
777
+ assert.match(answer.answer, /米饭/);
778
778
  assert.ok(answer.sources.length >= 1);
779
779
  } finally {
780
780
  extractive.close();
@@ -132,8 +132,8 @@ test('GET contract: every read route returns the documented status and envelope'
132
132
  try {
133
133
  const handler = createApiHandler({ cortex });
134
134
 
135
- const firstTrace = writeTrace(cortex, '用户喜欢白饭,助手记着。', {
136
- title: '白饭',
135
+ const firstTrace = writeTrace(cortex, '用户喜欢米饭,助手记着。', {
136
+ title: '米饭',
137
137
  tags: ['约定'],
138
138
  importance: 0.8,
139
139
  });
@@ -346,9 +346,9 @@ test('GET contract: every read route returns the documented status and envelope'
346
346
  assert.equal(typeof data.identity, 'object');
347
347
  assert.equal(data.identity.scopeId, 'global');
348
348
  }],
349
- [`/search?q=${encodeURIComponent('白饭')}`, (result) => {
349
+ [`/search?q=${encodeURIComponent('米饭')}`, (result) => {
350
350
  const data = expectData(result, '/search');
351
- assert.equal(data.query, '白饭');
351
+ assert.equal(data.query, '米饭');
352
352
  assert.equal(data.scopeId, 'global');
353
353
  assert.ok(Array.isArray(data.items));
354
354
  assert.ok(data.items.some((item) => item.id === traceId));
@@ -373,7 +373,7 @@ test('GET contract: every read route returns the documented status and envelope'
373
373
  const data = expectData(result, '/trace');
374
374
  assert.equal(data.id, traceId);
375
375
  assert.equal(data.scopeId, 'global');
376
- assert.equal(data.content, '用户喜欢白饭,助手记着。');
376
+ assert.equal(data.content, '用户喜欢米饭,助手记着。');
377
377
  assertIso(data.recordedAt, 'trace.recordedAt');
378
378
  }],
379
379
  [`/timeline?id=${traceId}`, (result) => {
@@ -426,8 +426,8 @@ test('POST /write accepts one memory, deduplicates, and writes batches atomicall
426
426
  expectError(bad, { label: 'write blank', match: /text/ });
427
427
 
428
428
  const single = await post(handler, '/write', {
429
- text: '用户喜欢白饭。',
430
- title: '白饭',
429
+ text: '用户喜欢米饭。',
430
+ title: '米饭',
431
431
  tags: ['约定', '日常'],
432
432
  importance: 0.9,
433
433
  explicit: true,
@@ -435,8 +435,8 @@ test('POST /write accepts one memory, deduplicates, and writes batches atomicall
435
435
  });
436
436
  const written = expectData(single, 'write single');
437
437
  assert.equal(written.skipped, false);
438
- assert.equal(written.trace.content, '用户喜欢白饭。');
439
- assert.equal(written.trace.title, '白饭');
438
+ assert.equal(written.trace.content, '用户喜欢米饭。');
439
+ assert.equal(written.trace.title, '米饭');
440
440
  assert.equal(written.trace.scopeId, 'global');
441
441
  assert.deepEqual(written.trace.tags, ['约定', '日常']);
442
442
  assert.equal(typeof written.trace.id, 'string');
@@ -444,7 +444,7 @@ test('POST /write accepts one memory, deduplicates, and writes batches atomicall
444
444
  assert.equal(typeof written.event.id, 'string');
445
445
  assertIso(written.trace.recordedAt, 'write.trace.recordedAt');
446
446
 
447
- const duplicate = await post(handler, '/write', { text: '用户喜欢白饭。', explicit: true });
447
+ const duplicate = await post(handler, '/write', { text: '用户喜欢米饭。', explicit: true });
448
448
  const deduped = expectData(duplicate, 'write duplicate');
449
449
  assert.equal(deduped.skipped, true);
450
450
  assert.equal(deduped.reason, 'duplicate');
@@ -483,11 +483,11 @@ test('POST /search validates its body and returns the retrieval envelope', async
483
483
  const { cortex } = context;
484
484
  try {
485
485
  const handler = createApiHandler({ cortex });
486
- const written = writeTrace(cortex, '用户喜欢白饭,助手记着。', { title: '白饭' });
486
+ const written = writeTrace(cortex, '用户喜欢米饭,助手记着。', { title: '米饭' });
487
487
 
488
- const found = await post(handler, '/search', { query: '白饭', limit: 5, budget: 500 });
488
+ const found = await post(handler, '/search', { query: '米饭', limit: 5, budget: 500 });
489
489
  const data = expectData(found, 'search post');
490
- assert.equal(data.query, '白饭');
490
+ assert.equal(data.query, '米饭');
491
491
  assert.equal(data.scopeId, 'global');
492
492
  assert.ok(Array.isArray(data.items));
493
493
  assert.ok(data.items.some((item) => item.id === written.trace.id));
@@ -496,7 +496,7 @@ test('POST /search validates its body and returns the retrieval envelope', async
496
496
  assert.ok(Array.isArray(data.trace.sources));
497
497
  assertIso(data.at, 'search.at');
498
498
 
499
- const wide = await post(handler, '/search', { query: '白饭', limit: 20, budget: 64 });
499
+ const wide = await post(handler, '/search', { query: '米饭', limit: 20, budget: 64 });
500
500
  expectData(wide, 'search lower budget');
501
501
 
502
502
  const invalid = [
@@ -674,7 +674,7 @@ test('POST /qa abstains without memories and answers from evidence after a write
674
674
  const context = makeCortex();
675
675
  try {
676
676
  const handler = createApiHandler({ cortex: context.cortex });
677
- writeTrace(context.cortex, '用户喜欢白饭,助手记着。', { title: '白饭' });
677
+ writeTrace(context.cortex, '用户喜欢米饭,助手记着。', { title: '米饭' });
678
678
  const answered = await post(handler, '/qa', { question: '用户喜欢什么?' });
679
679
  const data = expectData(answered, 'qa answered');
680
680
  assert.ok(['extractive', 'llm'].includes(data.mode));
@@ -692,13 +692,13 @@ test('POST /tick executes safe pending intentions and reports the queue', async
692
692
  const { cortex } = context;
693
693
  try {
694
694
  const handler = createApiHandler({ cortex });
695
- writeTrace(cortex, '用户喜欢白饭,助手记着。', { title: '白饭' });
695
+ writeTrace(cortex, '用户喜欢米饭,助手记着。', { title: '米饭' });
696
696
  const now = new Date();
697
697
  const intention = cortex.stores.initiativeStore.insert({
698
698
  kind: 'recall',
699
699
  priority: 0.9,
700
700
  reason: '契约测试想主动回忆',
701
- payload: { topic: '白饭' },
701
+ payload: { topic: '米饭' },
702
702
  createdAt: now.toISOString(),
703
703
  dueAt: now.toISOString(),
704
704
  expiresAt: new Date(now.getTime() + 3_600_000).toISOString(),
@@ -10,11 +10,11 @@ test('guardian backup validates, restores to an offline path and refuses the liv
10
10
  const { cortex, dir } = context;
11
11
  try {
12
12
  const written = cortex.write({
13
- text: '备份前的白饭承诺:用户会买白饭。',
14
- title: '白饭承诺',
13
+ text: '备份前的米饭承诺:用户会买米饭。',
14
+ title: '米饭承诺',
15
15
  explicit: true,
16
16
  now: BASE_MS,
17
- facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买白饭', confidence: 0.9 }],
17
+ facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买米饭', confidence: 0.9 }],
18
18
  });
19
19
  assert.equal(written.skipped, false);
20
20
  assert.equal(cortex.repos.traces.count(), 1);
@@ -54,7 +54,7 @@ test('guardian backup validates, restores to an offline path and refuses the liv
54
54
  assert.equal(restoredDb.prepare('PRAGMA integrity_check').get().integrity_check, 'ok');
55
55
  assert.equal(Number(restoredDb.prepare('SELECT COUNT(*) AS c FROM traces').get().c), 1);
56
56
  assert.equal(Number(restoredDb.prepare('SELECT COUNT(*) AS c FROM facts').get().c), 1);
57
- assert.equal(restoredDb.prepare('SELECT content FROM traces LIMIT 1').get().content, '备份前的白饭承诺:用户会买白饭。');
57
+ assert.equal(restoredDb.prepare('SELECT content FROM traces LIMIT 1').get().content, '备份前的米饭承诺:用户会买米饭。');
58
58
  assert.equal(restoredDb.prepare("SELECT value FROM meta WHERE key = 'schema_version'").get().value, '7');
59
59
  } finally {
60
60
  restoredDb.close();
@@ -130,11 +130,11 @@ test('privacy deleteScope removes traces/facts/working/goals but keeps the event
130
130
  const { cortex } = context;
131
131
  try {
132
132
  const first = cortex.write({
133
- text: '用户答应买白饭。',
134
- title: '白饭',
133
+ text: '用户答应买米饭。',
134
+ title: '米饭',
135
135
  explicit: true,
136
136
  now: BASE_MS,
137
- facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买白饭', confidence: 0.9 }],
137
+ facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买米饭', confidence: 0.9 }],
138
138
  });
139
139
  const second = cortex.write({
140
140
  text: '用户想给助手一个实体。',
@@ -162,7 +162,7 @@ test('privacy deleteScope removes traces/facts/working/goals but keeps the event
162
162
  const eventsBefore = cortex.repos.events.count();
163
163
  assert.equal(eventsBefore, 2);
164
164
  const payloadBefore = cortex.repos.events.list({ limit: 10 }).map((event) => event.payload);
165
- assert.equal(JSON.stringify(payloadBefore).includes('白饭'), false); // the ledger stores hashes, never raw text
165
+ assert.equal(JSON.stringify(payloadBefore).includes('米饭'), false); // the ledger stores hashes, never raw text
166
166
 
167
167
  const deleted = cortex.privacy.deleteScope('global', { actor: 'user', reason: 'integration-privacy' });
168
168
  assert.equal(deleted.scopeId, 'global');
@@ -191,7 +191,7 @@ test('privacy deleteScope removes traces/facts/working/goals but keeps the event
191
191
  const chain = cortex.repos.events.verifyChain();
192
192
  assert.equal(chain.ok, true);
193
193
  assert.equal(chain.count, eventsBefore);
194
- assert.equal(JSON.stringify(cortex.repos.events.list({ limit: 10 }).map((event) => event.payload)).includes('白饭'), false);
194
+ assert.equal(JSON.stringify(cortex.repos.events.list({ limit: 10 }).map((event) => event.payload)).includes('米饭'), false);
195
195
 
196
196
  // The deletion itself is audited.
197
197
  const audit = cortex.repos.audit.list({ limit: 20 });
@@ -202,7 +202,7 @@ test('privacy deleteScope removes traces/facts/working/goals but keeps the event
202
202
  assert.equal(record.detail.counts.traces, 2);
203
203
 
204
204
  // Search is empty rather than stale, and the service still accepts new writes.
205
- assert.equal(cortex.search('白饭', { now: BASE_MS + 3_000 }).items.length, 0);
205
+ assert.equal(cortex.search('米饭', { now: BASE_MS + 3_000 }).items.length, 0);
206
206
  const rewritten = cortex.write({ text: '删除之后重新开始。', explicit: true, now: BASE_MS + 4_000 });
207
207
  assert.equal(rewritten.skipped, false);
208
208
  assert.equal(cortex.repos.traces.count(), 1);
@@ -58,7 +58,10 @@ test('consolidation dry-run and invalid/protected decisions do not mutate', with
58
58
  const { createConsolidationEngine } = await import('../../src/engines/consolidate.js');
59
59
  const engine = createConsolidationEngine({ db: cortex.db, traces: cortex.repos.traces, summaries: cortex.repos.summaries, audit: cortex.repos.audit, llm: cortex.llm });
60
60
  const result = await engine.run({ scopeId: 'global', dryRun: true });
61
- assert.equal(result.run.status, 'rejected');
61
+ // 预演现在明确标成 preview,而不是把「有决策被拒」误报成 rejected:
62
+ // 预演不应用任何东西,也不该被当成一次真实的巩固。
63
+ assert.equal(result.run.status, 'preview');
64
+ assert.match(String(result.run.error), /dry-run/);
62
65
  assert.equal(result.applied.length, 0);
63
66
  assert.equal(cortex.get(ids.d).state, 'active');
64
67
  assert.equal(cortex.get(ids.a).state, 'active');
@@ -68,7 +71,8 @@ test('consolidation without an LLM records skipped and changes nothing', withCor
68
71
  const ids = seed(cortex);
69
72
  const result = await cortex.consolidation.run({ scopeId: 'global' });
70
73
  assert.equal(result.run.status, 'skipped');
71
- assert.equal(result.run.error, 'no-llm');
74
+ // 0.4.97 起「没有 adapter」和「adapter 回了空」分开标了,旧断言没跟上。
75
+ assert.equal(result.run.error, 'no-llm-adapter');
72
76
  assert.equal(result.applied.length, 0);
73
77
  assert.equal(cortex.get(ids.a).state, 'active');
74
78
  assert.equal(cortex.consolidation.list({ scopeId: 'global' }).length, 1);
@@ -72,7 +72,7 @@ test('scope isolation keeps writes, search, working memory and goals inside thei
72
72
  const context = makeCortex();
73
73
  const { cortex } = context;
74
74
  try {
75
- const shared = '用户喜欢白饭,这是同一条跨 scope 文本。';
75
+ const shared = '用户喜欢米饭,这是同一条跨 scope 文本。';
76
76
  const globalWrite = cortex.write({ text: shared, title: 'global copy', explicit: true, scopeId: 'global', now: BASE_MS });
77
77
  const s2Write = cortex.write({ text: shared, title: 's2 copy', explicit: true, scopeId: 's2', now: BASE_MS + 1_000 });
78
78
  const s2Extra = cortex.write({ text: '只有 s2 能看到的技术记录。', title: 's2 tech', explicit: true, scopeId: 's2', now: BASE_MS + 2_000 });
@@ -96,9 +96,9 @@ test('scope isolation keeps writes, search, working memory and goals inside thei
96
96
  assert.equal(cortex.repos.events.count('s2'), 3);
97
97
  assert.equal(cortex.repos.events.count(), 4);
98
98
 
99
- const globalHits = cortex.search('白饭', { scopeId: 'global', now: BASE_MS + 4_000, limit: 10 });
100
- const s2Hits = cortex.search('白饭', { scopeId: 's2', now: BASE_MS + 4_000, limit: 10 });
101
- const defaultHits = cortex.search('白饭', { now: BASE_MS + 4_000, limit: 10 });
99
+ const globalHits = cortex.search('米饭', { scopeId: 'global', now: BASE_MS + 4_000, limit: 10 });
100
+ const s2Hits = cortex.search('米饭', { scopeId: 's2', now: BASE_MS + 4_000, limit: 10 });
101
+ const defaultHits = cortex.search('米饭', { now: BASE_MS + 4_000, limit: 10 });
102
102
  assert.equal(globalHits.scopeId, 'global');
103
103
  assert.equal(s2Hits.scopeId, 's2');
104
104
  // Retrieval merges a scoped recency source, so assert scope membership
@@ -387,11 +387,11 @@ test('privacy.deleteScope wipes diary, dreams, sleep, emotion, feedback and fact
387
387
  const { cortex } = context;
388
388
  try {
389
389
  const first = cortex.write({
390
- text: '用户答应买白饭,这是隐私删除测试。',
391
- title: '白饭承诺',
390
+ text: '用户答应买米饭,这是隐私删除测试。',
391
+ title: '米饭承诺',
392
392
  explicit: true,
393
393
  now: BASE_MS,
394
- facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买白饭', confidence: 0.9 }],
394
+ facts: [{ subject: '用户', predicate: '答应', objectLiteral: '买米饭', confidence: 0.9 }],
395
395
  });
396
396
  const second = cortex.write({
397
397
  text: '用户想给助手一个实体。',
@@ -445,7 +445,8 @@ test('privacy.deleteScope wipes diary, dreams, sleep, emotion, feedback and fact
445
445
  assert.equal(before.traces, 3, 'two writes plus one reflection');
446
446
  assert.equal(before.facts, 2);
447
447
  assert.equal(before.entities, 2);
448
- assert.equal(before.summaries, 1);
448
+ // episode(sleep 里的 reflect)+ 一条叙事线(sleep 里的 weave)
449
+ assert.equal(before.summaries, 2);
449
450
  assert.equal(before.feedback, 1);
450
451
  assert.equal(before.emotionEvents, 2);
451
452
  assert.equal(before.working, 1, 'sleep purged the expired item');
@@ -479,7 +480,7 @@ test('privacy.deleteScope wipes diary, dreams, sleep, emotion, feedback and fact
479
480
  assert.equal(eventsBefore, 4);
480
481
  assert.equal(globalEventsBefore, 3);
481
482
  assert.equal(s2EventsBefore, 1);
482
- assert.equal(JSON.stringify(cortex.repos.events.list({ limit: 100 }).map((event) => event.payload)).includes('白饭'), false);
483
+ assert.equal(JSON.stringify(cortex.repos.events.list({ limit: 100 }).map((event) => event.payload)).includes('米饭'), false);
483
484
 
484
485
  const deleted = cortex.privacy.deleteScope('global', { actor: 'user', reason: 'edge-privacy' });
485
486
  assert.equal(deleted.scopeId, 'global');
@@ -526,7 +527,7 @@ test('privacy.deleteScope wipes diary, dreams, sleep, emotion, feedback and fact
526
527
  const chain = cortex.repos.events.verifyChain();
527
528
  assert.equal(chain.ok, true);
528
529
  assert.equal(chain.count, eventsBefore);
529
- assert.equal(JSON.stringify(cortex.repos.events.list({ limit: 100 }).map((event) => event.payload)).includes('白饭'), false);
530
+ assert.equal(JSON.stringify(cortex.repos.events.list({ limit: 100 }).map((event) => event.payload)).includes('米饭'), false);
530
531
 
531
532
  // The deletion is audited with the exact counts returned.
532
533
  const auditRecord = cortex.repos.audit.list({ limit: 200 })
@@ -795,7 +796,7 @@ test('duplicate operationIds and duplicate content keep traces unique and metric
795
796
  const { cortex } = context;
796
797
  try {
797
798
  const first = cortex.write({
798
- text: '重复测试:用户喜欢白饭。',
799
+ text: '重复测试:用户喜欢米饭。',
799
800
  title: '重复',
800
801
  explicit: true,
801
802
  operationId: 'edge:dup-1',
@@ -803,7 +804,7 @@ test('duplicate operationIds and duplicate content keep traces unique and metric
803
804
  });
804
805
  assert.equal(first.skipped, false);
805
806
  const replay = cortex.write({
806
- text: '重复测试:用户喜欢白饭。',
807
+ text: '重复测试:用户喜欢米饭。',
807
808
  title: '重复',
808
809
  explicit: true,
809
810
  operationId: 'edge:dup-1',
@@ -816,7 +817,7 @@ test('duplicate operationIds and duplicate content keep traces unique and metric
816
817
  assert.equal(cortex.repos.events.count(), 1);
817
818
 
818
819
  const duplicate = cortex.write({
819
- text: '重复测试:用户喜欢白饭。',
820
+ text: '重复测试:用户喜欢米饭。',
820
821
  explicit: true,
821
822
  operationId: 'edge:dup-2',
822
823
  now: BASE_MS + 2_000,
@@ -848,7 +849,7 @@ test('duplicate operationIds and duplicate content keep traces unique and metric
848
849
 
849
850
  // Dedupe is scoped: identical text in a second scope is a real new trace.
850
851
  const scoped = cortex.write({
851
- text: '重复测试:用户喜欢白饭。',
852
+ text: '重复测试:用户喜欢米饭。',
852
853
  explicit: true,
853
854
  scopeId: 's2',
854
855
  now: BASE_MS + 3_000,
@@ -874,7 +875,7 @@ test('vector failures never fail writes or searches and surface in the search so
874
875
  const { cortex } = context;
875
876
  try {
876
877
  assert.ok(cortex.vector);
877
- const first = cortex.write({ text: '向量失败测试:用户喜欢白饭。', title: '向量一', explicit: true, now: BASE_MS });
878
+ const first = cortex.write({ text: '向量失败测试:用户喜欢米饭。', title: '向量一', explicit: true, now: BASE_MS });
878
879
  assert.equal(first.skipped, false);
879
880
  assert.equal(cortex.vector.status().count, 1);
880
881