dsh-memu-memory 1.3.15 → 1.4.0

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 (48) hide show
  1. package/AGENTS.md +5 -2
  2. package/CHANGELOG.md +33 -1
  3. package/docs/client-conventions.md +1 -0
  4. package/docs/host-adaptation.md +52 -36
  5. package/docs/host-versions.md +120 -0
  6. package/docs/pending-work.md +51 -0
  7. package/docs/troubleshooting.md +15 -2
  8. package/lib/auto-link/candidates.js +4 -1
  9. package/lib/auto-link/decide.js +1 -1
  10. package/lib/auto-link/normalize.js +2 -2
  11. package/lib/auto-link/terminology.js +31 -1
  12. package/lib/binding-diagnostics.js +1 -1
  13. package/lib/client.js +53 -6
  14. package/lib/consolidation-snapshot.js +7 -1
  15. package/lib/curator.js +1 -1
  16. package/lib/diagnostics.js +10 -0
  17. package/lib/entity-repair.js +285 -0
  18. package/lib/environment-check.js +72 -3
  19. package/lib/global-graph.js +11 -2
  20. package/lib/graph.js +32 -8
  21. package/lib/host-surface.js +30 -0
  22. package/lib/index.js +116 -1
  23. package/lib/private-links.js +12 -0
  24. package/lib/rpc.js +48 -10
  25. package/lib/state.js +5 -1
  26. package/package.json +16 -1
  27. package/scripts/chain-matrix.mjs +4 -0
  28. package/scripts/check-doc-drift.mjs +194 -0
  29. package/scripts/entity-dedupe.mjs +110 -0
  30. package/tests/auto-link-candidates.test.mjs +22 -9
  31. package/tests/auto-link-decide.test.mjs +59 -59
  32. package/tests/auto-link-migration.test.mjs +4 -4
  33. package/tests/client-render.test.mjs +112 -1
  34. package/tests/cycle.test.mjs +2 -2
  35. package/tests/diagnostics.test.mjs +21 -0
  36. package/tests/doc-drift.test.mjs +122 -2
  37. package/tests/entity-merge.test.mjs +17 -0
  38. package/tests/environment-check.test.mjs +28 -0
  39. package/tests/global-graph.test.mjs +16 -0
  40. package/tests/global-lifecycle.test.mjs +24 -4
  41. package/tests/graph-cascade.test.mjs +111 -0
  42. package/tests/hybrid-recall.test.mjs +1 -1
  43. package/tests/managed-memory.test.mjs +7 -7
  44. package/tests/private-links.test.mjs +12 -0
  45. package/tests/recall-corpus-eligibility.test.mjs +3 -3
  46. package/tests/settings-plumbing.test.mjs +2 -0
  47. package/tests/tools.test.mjs +1 -1
  48. package/tests/webui-auth.test.mjs +58 -0
@@ -47,31 +47,31 @@ function index(entries) {
47
47
  test('mentions are boundary-aware and punctuation-insensitive: CJK substrings, identifiers, NFKC folding', () => {
48
48
  assert.equal(normalize.mentionCount('yuike 和 yuikeee', 'yuike'), 1, 'Latin must not match a longer identifier')
49
49
  assert.equal(normalize.mentionCount('YUIKE!来了', 'yuike'), 1, 'full-width and punctuation fold away')
50
- assert.equal(normalize.mentionCount('星宫雲来了,星宫雲走了', '星宫雲'), 2)
50
+ assert.equal(normalize.mentionCount('洛云澜来了,洛云澜走了', '洛云澜'), 2)
51
51
  // §8.1: NFKC + 去标点/空白 applies to the name as well as the text.
52
- assert.equal(normalize.mentionCount('小·柚来了', '小柚'), 1)
53
- assert.equal(normalize.mentionCount('小 柚来了', '小柚'), 1)
54
- assert.equal(normalize.mentionCount('小柚来了', '小 柚'), 1)
52
+ assert.equal(normalize.mentionCount('小·檀来了', '小檀'), 1)
53
+ assert.equal(normalize.mentionCount('小 檀来了', '小檀'), 1)
54
+ assert.equal(normalize.mentionCount('小檀来了', '小 檀'), 1)
55
55
  // §2: code identifiers keep their punctuation and their word boundaries.
56
56
  assert.equal(normalize.mentionCount('Yuike_01 上线', 'Yuike_01'), 1)
57
57
  assert.equal(normalize.mentionCount('yuike.dev is down', 'yuike.dev'), 1)
58
- assert.equal(normalize.mentionCount('星宫雲-yuike 来了', '星宫雲-yuike'), 1)
58
+ assert.equal(normalize.mentionCount('洛云澜-alex 来了', '洛云澜-alex'), 1)
59
59
  assert.equal(normalize.firstMention('猫娘yuike', 'yuike'), 2)
60
- assert.equal(normalize.firstMention('「小·柚」来了', '小柚'), 1, 'offset is the raw text position, not the compact index')
60
+ assert.equal(normalize.firstMention('「小·檀」来了', '小檀'), 1, 'offset is the raw text position, not the compact index')
61
61
  assert.equal(normalize.isMentionSurface('小'), false, 'one CJK character is not a surface')
62
- assert.equal(normalize.isMentionSurface('小柚'), true)
62
+ assert.equal(normalize.isMentionSurface('小檀'), true)
63
63
  assert.equal(normalize.isMentionSurface('a'), false, 'one Latin character is not a surface')
64
64
  })
65
65
 
66
66
  test('punctuated and identifier surfaces produce mention edges with raw offsets', () => {
67
67
  const lib = library('punct')
68
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', status: 'confirmed' })
68
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', status: 'confirmed' })
69
69
  const yuike = graph.createEntity({ libraryId: lib, name: 'yuike_01', kind: 'person', status: 'confirmed' })
70
- const mixed = graph.createEntity({ libraryId: lib, name: '星宫雲-yuike', kind: 'person', status: 'confirmed' })
70
+ const mixed = graph.createEntity({ libraryId: lib, name: '洛云澜-alex', kind: 'person', status: 'confirmed' })
71
71
  const snapshot = index({
72
- 'mem-a': entry('「小·柚」来了', '她带着伞。'),
72
+ 'mem-a': entry('「小·檀」来了', '她带着伞。'),
73
73
  'mem-b': entry('yuike_01 上线', 'yuike_01 迟到了。'),
74
- 'mem-c': entry('星宫雲-yuike 到访', '星宫雲-yuike 和 星宫雲 yuike 都来了。'),
74
+ 'mem-c': entry('洛云澜-alex 到访', '洛云澜-alex 和 洛云澜 yuike 都来了。'),
75
75
  })
76
76
  const edges = decide.decideAutoLinks({ index: snapshot, entities: [you, yuike, mixed] })
77
77
  const mention = edges.filter(edge => edge.rule === 'entity-mention')
@@ -79,8 +79,8 @@ test('punctuated and identifier surfaces produce mention edges with raw offsets'
79
79
  for (const edge of edges) assert.ok(policy.EVIDENCE_RULES.includes(edge.rule), 'only the declared rule vocabulary: ' + edge.rule)
80
80
  const byEntity = new Map(mention.map(edge => [edge.to, edge]))
81
81
  const youEdge = byEntity.get(you.id)
82
- assert.equal(youEdge.evidence.surface, '小柚')
83
- assert.equal(youEdge.evidence.offset, 1, 'raw offset inside 「小·柚」')
82
+ assert.equal(youEdge.evidence.surface, '小檀')
83
+ assert.equal(youEdge.evidence.offset, 1, 'raw offset inside 「小·檀」')
84
84
  assert.ok(byEntity.has(yuike.id), 'identifier with underscore is found')
85
85
  assert.ok(byEntity.has(mixed.id), 'mixed CJK-Latin name is found')
86
86
  })
@@ -89,17 +89,17 @@ test('punctuated and identifier surfaces produce mention edges with raw offsets'
89
89
 
90
90
  test('only confirmed entities produce mention edges; provisional, archived and secret rows do not', () => {
91
91
  const lib = library('mention')
92
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', aliases: ['柚子'], status: 'confirmed', confirmedBy: 'user' })
93
- graph.createEntity({ libraryId: lib, name: '未晞', kind: 'person' })
92
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', aliases: ['檀子'], status: 'confirmed', confirmedBy: 'user' })
93
+ graph.createEntity({ libraryId: lib, name: '沈砚舟', kind: 'person' })
94
94
  graph.createEntity({ libraryId: lib, name: '阿兰', kind: 'person', status: 'archived' })
95
95
  const snapshot = index({
96
- 'mem-a': entry('小柚今天来了', '她带了一篮柚子。'),
97
- 'mem-b': entry('未晞的日记', '未晞写下了今天的安排。'),
96
+ 'mem-a': entry('小檀今天来了', '她带了一篮水果。'),
97
+ 'mem-b': entry('沈砚舟的日记', '沈砚舟写下了今天的安排。'),
98
98
  'mem-c': entry('阿兰回信', '阿兰说下周再联系。'),
99
- 'mem-d': entry('小柚与秘密', '关于小柚的一件不能外传的事。', { visibility: 'secret' }),
100
- 'mem-e': entry('小柚旧事', '小柚很久以前来过。', { status: 'archived' }),
99
+ 'mem-d': entry('小檀与秘密', '关于小檀的一件不能外传的事。', { visibility: 'secret' }),
100
+ 'mem-e': entry('小檀旧事', '小檀很久以前来过。', { status: 'archived' }),
101
101
  })
102
- const edges = decide.decideAutoLinks({ index: snapshot, entities: [you, { id: 'ent-provisional', name: '未晞', kind: 'person', status: 'provisional' }, { id: 'ent-archived', name: '阿兰', kind: 'person', status: 'archived' }] })
102
+ const edges = decide.decideAutoLinks({ index: snapshot, entities: [you, { id: 'ent-provisional', name: '沈砚舟', kind: 'person', status: 'provisional' }, { id: 'ent-archived', name: '阿兰', kind: 'person', status: 'archived' }] })
103
103
  const mention = edges.filter(edge => edge.rule === 'entity-mention')
104
104
  assert.equal(mention.length, 1, 'one eligible memory mentions the confirmed entity')
105
105
  assert.equal(mention[0].from, 'mem-a')
@@ -107,7 +107,7 @@ test('only confirmed entities produce mention edges; provisional, archived and s
107
107
  assert.equal(mention[0].kind, 'person')
108
108
  assert.equal(mention[0].confidence, 1)
109
109
  assert.equal(mention[0].schemaVersion, 2)
110
- assert.ok(mention[0].evidence.surface === '小柚' || mention[0].evidence.surface === '柚子')
110
+ assert.ok(mention[0].evidence.surface === '小檀' || mention[0].evidence.surface === '檀子')
111
111
  assert.equal(mention[0].evidence.entityId, you.id)
112
112
  assert.equal(mention[0].evidence.field, 'title')
113
113
  assert.equal(mention[0].evidence.offset, 0)
@@ -115,8 +115,8 @@ test('only confirmed entities produce mention edges; provisional, archived and s
115
115
 
116
116
  test('suppression removes a decided edge and decide stays pure', () => {
117
117
  const lib = library('suppress')
118
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', status: 'confirmed' })
119
- const snapshot = index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') })
118
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', status: 'confirmed' })
119
+ const snapshot = index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') })
120
120
  const first = decide.decideAutoLinks({ index: snapshot, entities: [you] })
121
121
  const second = decide.decideAutoLinks({ index: snapshot, entities: [you] })
122
122
  assert.deepEqual(second, first, 'same input -> same output')
@@ -152,10 +152,10 @@ test('field evidence builds conflict, supersede and fact-key edges without cliqu
152
152
 
153
153
  test('apply writes evidence and never overwrites a manual edge', () => {
154
154
  const lib = library('apply')
155
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', status: 'confirmed' })
155
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', status: 'confirmed' })
156
156
  state.savePrivateIndex(lib, index({
157
- 'mem-a': entry('小柚来了', '小柚进门坐下。'),
158
- 'mem-b': entry('小柚与阿柚', '小柚提起阿柚。', {
157
+ 'mem-a': entry('小檀来了', '小檀进门坐下。'),
158
+ 'mem-b': entry('小檀与阿檀', '小檀提起阿檀。', {
159
159
  links: [{ to: you.id, kind: 'person', note: '用户手动确认过这条关系。', confidence: 0.9 }],
160
160
  }),
161
161
  }))
@@ -181,11 +181,11 @@ test('apply writes evidence and never overwrites a manual edge', () => {
181
181
 
182
182
  test('confirming an entity flips its status and backfills mention edges immediately', () => {
183
183
  const lib = library('confirm')
184
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
184
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
185
185
  assert.equal(you.status, 'provisional', 'creation alone does not confirm')
186
186
  state.savePrivateIndex(lib, index({
187
- 'mem-a': entry('小柚来了', '小柚进门坐下。'),
188
- 'mem-b': entry('小柚的伞', '小柚把伞落在门口。'),
187
+ 'mem-a': entry('小檀来了', '小檀进门坐下。'),
188
+ 'mem-b': entry('小檀的伞', '小檀把伞落在门口。'),
189
189
  }))
190
190
  const confirmed = graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
191
191
  assert.deepEqual(confirmed.confirmed, [you.id])
@@ -203,29 +203,29 @@ test('confirming an entity flips its status and backfills mention edges immediat
203
203
 
204
204
  test('renaming a confirmed entity retires stale mention edges and attaches the new surface', () => {
205
205
  const lib = library('rename')
206
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
206
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
207
207
  state.savePrivateIndex(lib, index({
208
- 'mem-a': entry('小柚来了', '小柚进门坐下。'),
209
- 'mem-b': entry('柚子来了', '柚子带着伞。'),
208
+ 'mem-a': entry('小檀来了', '小檀进门坐下。'),
209
+ 'mem-b': entry('檀子来了', '檀子带着伞。'),
210
210
  }))
211
211
  graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
212
212
  assert.ok((state.loadPrivateIndex(lib).entries['mem-a'].links || []).some(link => link.to === you.id))
213
- graph.renameEntity({ libraryId: lib, entityId: you.id, name: '柚子', aliases: [] })
213
+ graph.renameEntity({ libraryId: lib, entityId: you.id, name: '檀子', aliases: [] })
214
214
  const rows = state.loadPrivateIndex(lib)
215
215
  assert.equal((rows.entries['mem-a'].links || []).some(link => link.to === you.id), false, 'old name no longer matches')
216
- assert.ok((rows.entries['mem-b'].links || []).some(link => link.to === you.id && link.evidence?.surface === '柚子'))
216
+ assert.ok((rows.entries['mem-b'].links || []).some(link => link.to === you.id && link.evidence?.surface === '檀子'))
217
217
  })
218
218
 
219
219
  test('merging a confirmed source into a provisional target confirms it and remaps evidence', () => {
220
220
  const lib = library('merge')
221
- const source = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
222
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
221
+ const source = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
222
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
223
223
  graph.confirmEntities({ libraryId: lib, entityIds: [source.id], by: 'user' })
224
- const target = graph.createEntity({ libraryId: lib, name: '柚子', kind: 'person' })
224
+ const target = graph.createEntity({ libraryId: lib, name: '檀子', kind: 'person' })
225
225
  graph.mergeEntities({ libraryId: lib, targetId: target.id, sourceIds: [source.id] })
226
226
  const store = graph.graphExport(lib)
227
227
  assert.equal(store.entities[target.id].status, 'confirmed', 'a confirmed source confirms the surviving row')
228
- assert.deepEqual(store.entities[target.id].aliases, ['小柚'])
228
+ assert.deepEqual(store.entities[target.id].aliases, ['小檀'])
229
229
  const link = (state.loadPrivateIndex(lib).entries['mem-a'].links || []).find(item => item.to === target.id)
230
230
  assert.ok(link, 'the mention edge points at the merged row')
231
231
  assert.equal(link.evidence.entityId, target.id)
@@ -233,8 +233,8 @@ test('merging a confirmed source into a provisional target confirms it and remap
233
233
 
234
234
  test('deleting an entity records suppression for the auto edges it collects', () => {
235
235
  const lib = library('delete')
236
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
237
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
236
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
237
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
238
238
  graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
239
239
  graph.deleteEntity({ libraryId: lib, entityId: you.id, force: true })
240
240
  const store = suppression.readSuppression(lib)
@@ -244,8 +244,8 @@ test('deleting an entity records suppression for the auto edges it collects', ()
244
244
 
245
245
  test('removing an auto edge by hand suppresses it against the next recompute', () => {
246
246
  const lib = library('unlink')
247
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
248
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
247
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
248
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
249
249
  graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
250
250
  const removed = graph.unlinkEntry({ libraryId: lib, fromId: 'mem-a', toId: you.id, kind: 'person' })
251
251
  assert.equal(removed.removed, 1)
@@ -258,9 +258,9 @@ test('removing an auto edge by hand suppresses it against the next recompute', (
258
258
 
259
259
  test('deleting a legacy auto edge also blocks the later entity-mention edge (P6)', () => {
260
260
  const lib = library('legacy-suppress')
261
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
261
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
262
262
  state.savePrivateIndex(lib, index({
263
- 'mem-a': entry('小柚来了', '小柚进门坐下。', {
263
+ 'mem-a': entry('小檀来了', '小檀进门坐下。', {
264
264
  links: [{ to: you.id, kind: 'person', note: '旧算法自动建立的实体枢纽。', confidence: 0.65, source: 'auto' }],
265
265
  }),
266
266
  }))
@@ -297,8 +297,8 @@ test('purgeAutoLinks removes only auto edges, keeps a manual edge byte-for-byte
297
297
 
298
298
  test('off mode closes explicit mention maintenance too, and apply rejects unknown rules', () => {
299
299
  const lib = library('off-mode')
300
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
301
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
300
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
301
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
302
302
  state.updateSettings({ autoLinkMode: 'off' })
303
303
  try {
304
304
  const result = graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
@@ -306,7 +306,7 @@ test('off mode closes explicit mention maintenance too, and apply rejects unknow
306
306
  assert.equal(result.entities, 0, 'off writes no edge')
307
307
  assert.equal((state.loadPrivateIndex(lib).entries['mem-a'].links || []).length, 0)
308
308
  // A hand-supplied edge outside the evidence vocabulary is refused by the writer.
309
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
309
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
310
310
  const applied = apply.applyAutoEdges({
311
311
  libraryId: lib,
312
312
  entities: [you],
@@ -321,8 +321,8 @@ test('off mode closes explicit mention maintenance too, and apply rejects unknow
321
321
 
322
322
  test('clearLinkSuppression removes markers and the deterministic rebuild restores the edge', async () => {
323
323
  const lib = library('clear-suppress')
324
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
325
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
324
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
325
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
326
326
  state.updateSettings({ autoLinkMode: 'deterministic' })
327
327
  try {
328
328
  graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
@@ -340,8 +340,8 @@ test('clearLinkSuppression removes markers and the deterministic rebuild restore
340
340
 
341
341
  test('switching to deterministic backfills entities confirmed while off', async () => {
342
342
  const lib = library('mode-switch')
343
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person' })
344
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
343
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person' })
344
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
345
345
  state.updateSettings({ autoLinkMode: 'off' })
346
346
  try {
347
347
  const off = graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
@@ -357,8 +357,8 @@ test('switching to deterministic backfills entities confirmed while off', async
357
357
 
358
358
  test('re-confirming an already-confirmed entity backfills missing mentions', () => {
359
359
  const lib = library('reconfirm')
360
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', status: 'confirmed' })
361
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
360
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', status: 'confirmed' })
361
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
362
362
  const result = graph.confirmEntities({ libraryId: lib, entityIds: [you.id], by: 'user' })
363
363
  assert.deepEqual(result.confirmed, [], 'it was already confirmed')
364
364
  assert.equal(result.entities, 1, 'the refresh still runs and attaches the edge')
@@ -369,8 +369,8 @@ test('three automatic passes in suggest mode add no edges', async () => {
369
369
  state.updateSettings({ autoLinkMode: 'suggest' })
370
370
  try {
371
371
  const lib = library('suggest-three')
372
- graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', status: 'confirmed' })
373
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
372
+ graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', status: 'confirmed' })
373
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
374
374
  for (let pass = 0; pass < 3; pass += 1) {
375
375
  const result = await privateLinks.refreshPrivateAutoLinks({ libraryId: lib, ids: ['mem-a'] })
376
376
  assert.equal(result.skipped, 'suggest')
@@ -398,7 +398,7 @@ test('confirming eight entities backfills all mentions in one batch (8 x 9 = 72)
398
398
 
399
399
  test('a broken entity store makes the automatic refresh fail open (warn, no throw)', async () => {
400
400
  const lib = library('broken-entities')
401
- state.savePrivateIndex(lib, index({ 'mem-a': entry('小柚来了', '小柚进门坐下。') }))
401
+ state.savePrivateIndex(lib, index({ 'mem-a': entry('小檀来了', '小檀进门坐下。') }))
402
402
  const file = path.join(home, 'index', `${lib}.entities.json`)
403
403
  fs.mkdirSync(path.dirname(file), { recursive: true })
404
404
  fs.writeFileSync(file, '{not json', 'utf8')
@@ -496,11 +496,11 @@ test('review accept refreshes the supersede edge immediately and stays silent in
496
496
 
497
497
  test('recallRelations ignores entity-mention edges even at confidence 1.0 but keeps field evidence', () => {
498
498
  const lib = library('recall')
499
- const you = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', status: 'confirmed' })
499
+ const you = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', status: 'confirmed' })
500
500
  state.savePrivateIndex(lib, index({
501
- 'mem-a': entry('小柚来了', '小柚进门坐下。', {
501
+ 'mem-a': entry('小檀来了', '小檀进门坐下。', {
502
502
  links: [
503
- { to: you.id, kind: 'person', note: '提及已确认实体「小柚」(标题)。', confidence: 1, source: 'auto', evidence: { rule: 'entity-mention', entityId: you.id, surface: '小柚', field: 'title', offset: 0 } },
503
+ { to: you.id, kind: 'person', note: '提及已确认实体「小檀」(标题)。', confidence: 1, source: 'auto', evidence: { rule: 'entity-mention', entityId: you.id, surface: '小檀', field: 'title', offset: 0 } },
504
504
  { to: 'mem-b', kind: 'conflict', note: '字段证据:conflicts_with 指向这条记忆。', confidence: 1, source: 'auto', evidence: { rule: 'conflict', field: 'conflicts_with' } },
505
505
  ],
506
506
  }),
@@ -76,14 +76,14 @@ test('dry run reports legacy edges and writes no entity status or edge', async (
76
76
  test('apply backs up, removes legacy auto edges, grades rows and rebuilds confirmed mentions', async () => {
77
77
  const binding = state.ensureSession('migration-apply', { cwd: path.join(home, 'ws-apply'), agentPreset: 'rp' })
78
78
  const lib = binding.libraryId
79
- const confirmed = graph.createEntity({ libraryId: lib, name: '小柚', kind: 'person', status: 'confirmed' })
80
- const provisional = graph.createEntity({ libraryId: lib, name: '未晞', kind: 'person' })
79
+ const confirmed = graph.createEntity({ libraryId: lib, name: '小檀', kind: 'person', status: 'confirmed' })
80
+ const provisional = graph.createEntity({ libraryId: lib, name: '沈砚舟', kind: 'person' })
81
81
  state.savePrivateIndex(lib, { version: 1, entries: {
82
- 'mem-a': entry('小柚来了,未晞也在', '小柚进门,未晞在窗边。', [
82
+ 'mem-a': entry('小檀来了,沈砚舟也在', '小檀进门,沈砚舟在窗边。', [
83
83
  { to: 'mem-b', kind: 'relation', note: '旧的词面自动关联,没有任何证据字段。', confidence: 0.66, source: 'auto' },
84
84
  { to: 'mem-b', kind: 'event', note: '用户手动建立的一条边,不能被迁移删掉。', confidence: 0.8 },
85
85
  ]),
86
- 'mem-b': entry('另一条记录', '只有小柚出现。'),
86
+ 'mem-b': entry('另一条记录', '只有小檀出现。'),
87
87
  } })
88
88
  const report = await runRebuildAutoLinks({ apply: true, json: true, log: () => {} })
89
89
  assert.ok(report.backup, 'apply takes a backup first')
@@ -327,8 +327,44 @@ test('graph studio pages all libraries and filters custom domains without mergin
327
327
  } finally { view.close() }
328
328
  })
329
329
 
330
- test('graph studio surfaces failed libraries and retains successful results', async () => {
330
+ test('the whole-workspace graph sends its domain filter to the global endpoint', async () => {
331
+ const calls = []
331
332
  const call = async (endpoint, payload) => {
333
+ calls.push({ endpoint, payload })
334
+ if (endpoint !== 'getGraph') return { items: [] }
335
+ const wanted = 'project:travel'
336
+ const hit = !payload.domain || payload.domain === wanted
337
+ return {
338
+ scope: 'global',
339
+ nodes: hit ? [{ id: 'mem-g-1', title: 'global memory', kind: 'global', domain: 'project:travel' }] : [],
340
+ edges: [],
341
+ domains: ['general', 'project:travel'],
342
+ }
343
+ }
344
+ // 没有私有库时面板落在全局图:这条路径走的是 getGlobalGraph,不是逐库合并。
345
+ const view = await graphStudioHarness(call, [])
346
+ try {
347
+ let tree = await view.render(true)
348
+ view.pick(tree, node => node.type === 'input' && node.props['aria-label'] === 'gsDomain')[0]
349
+ .props.onChange({ target: { value: 'project:travel' } })
350
+ tree = await view.render(true)
351
+ const asked = calls.filter(row => row.endpoint === 'getGraph')
352
+ const last = asked[asked.length - 1]
353
+ assert.equal(last.payload.scope, 'global', 'the panel stayed on the global graph')
354
+ assert.equal(last.payload.domain, 'project:travel', 'the global branch forwards the domain filter')
355
+ const datalist = view.pick(tree, node => node.type === 'datalist' && node.props?.id === 'dshm-graph-domains')[0]
356
+ const options = []
357
+ const visit = (value) => {
358
+ if (Array.isArray(value)) { value.forEach(visit); return }
359
+ if (value && value.type === 'option') options.push(String(value.props?.value ?? ''))
360
+ }
361
+ if (datalist) visit([].concat(datalist.props?.children ?? []))
362
+ assert.deepEqual(options, ['rp', 'coding', 'general', 'mixed', 'project:travel'].sort(),
363
+ 'the datalist keeps every domain the server reported, not only the filtered one')
364
+ } finally { view.close() }
365
+ })
366
+
367
+ test('graph studio surfaces failed libraries and retains successful results', async () => { const call = async (endpoint, payload) => {
332
368
  if (endpoint !== 'getGraph') return { items: [] }
333
369
  if (payload.libraryId === 'lib-denied') throw new Error('forbidden')
334
370
  return { nodes: [{ id: 'mem-ok', title: 'visible', kind: 'memory' }], edges: [], nextOffset: null }
@@ -1614,3 +1650,78 @@ test('the memory wall global block bulk-archives and the drawer deletes global e
1614
1650
  delete RPC_ANSWERS.deleteMemory
1615
1651
  }
1616
1652
  })
1653
+
1654
+ test('the memory wall filters by domain and names every card domain', async () => {
1655
+ const rpcCalls = []
1656
+ const ctx = fakeCtx({ rpcCalls })
1657
+ const originalGetState = RPC_ANSWERS.getState
1658
+ const originalSettingsState = RPC_ANSWERS.getSettingsState
1659
+ const loaded = {
1660
+ ...EMPTY_STATE,
1661
+ libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 2 }],
1662
+ }
1663
+ RPC_ANSWERS.getState = loaded
1664
+ RPC_ANSWERS.getSettingsState = loaded
1665
+ RPC_ANSWERS.browseWall = {
1666
+ total: 2,
1667
+ domains: ['coding', 'rp'],
1668
+ items: [
1669
+ { id: 'mem-rp', libraryId: 'lib-1', libraryName: 'demo', title: '约定的日子', preview: 'p', layer: 'long_term', status: 'active', source: 'user_said', decay: 0.5, tags: [], domain: 'rp' },
1670
+ { id: 'mem-code', libraryId: 'lib-1', libraryName: 'demo', title: '部署窗口', preview: 'p', layer: 'long_term', status: 'active', source: 'inferred', decay: 0.4, tags: [], domain: 'coding' },
1671
+ ],
1672
+ }
1673
+ const settle = async () => {
1674
+ await new Promise((resolve) => setTimeout(resolve, 0))
1675
+ await new Promise((resolve) => setTimeout(resolve, 0))
1676
+ }
1677
+ // harness 的 hook 游标是全局的:同一棵树只能展开一次,二次 walk 会把子组件的
1678
+ // useState 重新初始化。所以每轮 render 只走一遍,把要的东西一次收齐。
1679
+ const collect = (tree) => {
1680
+ const found = { select: null, domainTags: [], cards: 0 }
1681
+ walkNodes(tree, (node) => {
1682
+ if (node.type === 'select' && node.props?.['aria-label'] === 'wallFilterDomain' && !found.select) found.select = node
1683
+ if (node.type === 'span' && node.props?.title === 'wallDomainHint') found.domainTags.push(String(node.props?.children ?? ''))
1684
+ if (node.type === 'button' && String(node.props?.className || '').includes('dshm-wall-item')) found.cards += 1
1685
+ })
1686
+ const values = []
1687
+ const visit = (value) => {
1688
+ if (Array.isArray(value)) { value.forEach(visit); return }
1689
+ if (value && value.type === 'option') values.push(String(value.props?.value ?? ''))
1690
+ }
1691
+ if (found.select) visit([].concat(found.select.props?.children ?? []))
1692
+ found.values = values
1693
+ return found
1694
+ }
1695
+ try {
1696
+ globalThis.__dshMemuExports.apply(ctx)
1697
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
1698
+ const props = { ctx, t: (key) => key }
1699
+ const first = await renderPage(settings.component, props, undefined, { remount: true })
1700
+ collectPageHook()
1701
+ for (const effect of first.effects) effect.fn()
1702
+ await settle()
1703
+ let view = collect((await renderPage(settings.component, props, 9)).tree)
1704
+ for (const effect of effects) effect.fn()
1705
+ await settle()
1706
+ view = collect((await renderPage(settings.component, props, 9)).tree)
1707
+
1708
+ assert.ok(view.select, 'the wall renders a domain filter')
1709
+ assert.equal(view.cards, 2, 'both wall cards rendered')
1710
+ assert.deepEqual(view.values, ['', 'coding', 'rp'], 'the filter offers every domain the server reported')
1711
+ assert.deepEqual(view.domainTags.sort(), ['dmCoding', 'dmRp'], 'each card names the domain it came from')
1712
+
1713
+ view.select.props.onChange({ target: { value: 'rp' } })
1714
+ view = collect((await renderPage(settings.component, props, 9)).tree)
1715
+ for (const effect of effects) effect.fn()
1716
+ await settle()
1717
+ const asked = rpcCalls.filter((call) => call.endpoint === 'browseWall')
1718
+ assert.equal(asked[asked.length - 1].payload.domain, 'rp', 'picking a domain asks the server instead of trimming the page in the browser')
1719
+ view = collect((await renderPage(settings.component, props, 9)).tree)
1720
+ assert.deepEqual(view.domainTags, [], 'once filtered, cards stop repeating the same domain')
1721
+ assert.equal(view.select.props.value, 'rp', 'the filter keeps what the reader picked')
1722
+ } finally {
1723
+ RPC_ANSWERS.getState = originalGetState
1724
+ RPC_ANSWERS.getSettingsState = originalSettingsState
1725
+ delete RPC_ANSWERS.browseWall
1726
+ }
1727
+ })
@@ -521,7 +521,7 @@ test('a session arriving at an archived library revives it through the fast path
521
521
  })
522
522
 
523
523
  test('a legacy archive with no recorded source is not revived just because an old binding exists', () => {
524
- // 本机实测:rp(14 个绑定)、ai中转站(4 个)都是「归档 + 还有旧绑定」,但 lastUsed 三周前。
524
+ // 本机实测:rp(14 个绑定)、另一个工作区库(4 个)都是「归档 + 还有旧绑定」,但 lastUsed 三周前。
525
525
  // 旧数据分不清是用户归档还是老扫描误归档,所以只复活「还热」的;冷的不动。
526
526
  const lib = state.createLibrary({ name: 'legacy-cold', cwd: path.join(home, 'legacy-cold') })
527
527
  const st = state.loadState()
@@ -553,7 +553,7 @@ test('a warm legacy archive (no source recorded, used minutes ago) is revived',
553
553
  })
554
554
 
555
555
  test('a cold legacy archive with an old binding can still be deleted', () => {
556
- // 本机 rp / ai中转站 形态:很久以前归档、仍留着旧绑定、lastUsed 三周前。
556
+ // 本机 rp / 另一个工作区库 形态:很久以前归档、仍留着旧绑定、lastUsed 三周前。
557
557
  // 它不是扫描误归档(那类会被自愈),也不该因为“有旧绑定”变成永远删不掉。
558
558
  const lib = state.createLibrary({ name: 'legacy-deletable', cwd: path.join(home, 'legacy-deletable') })
559
559
  const st = state.loadState()
@@ -255,3 +255,24 @@ test('rows on disk survive a restart, so the page is not empty after a reload',
255
255
  assert.equal(parsed.total >= 1, true, 'a fresh process must read the persisted rows')
256
256
  assert.equal(parsed.code, 'PERSISTED_ROW')
257
257
  })
258
+
259
+ // docs/host-versions.md §13.6:台账指纹的运行时对应物。它不判断、不比版本号,
260
+ // 只是把已经发生过的结构探测结果聚合成一行——所以断言盯着"记下了什么"。
261
+ test('host surface records probe verdicts and refuses unregistered keys', async () => {
262
+ const surface = await import('../lib/host-surface.js')
263
+ const before = surface.hostSurface()
264
+ assert.deepEqual(Object.keys(before).sort(), [...surface.HOST_SURFACES].sort())
265
+
266
+ surface.noteHostSurface('rpcGuard', 'admit')
267
+ assert.equal(surface.hostSurface().rpcGuard, 'admit')
268
+ surface.noteHostSurface('rpcGuard', '')
269
+ assert.equal(surface.hostSurface().rpcGuard, 'admit', 'an empty verdict never erases a known one')
270
+ surface.noteHostSurface('semver', '0.2.3-alpha.1')
271
+ assert.equal('semver' in surface.hostSurface(), false, 'a stale call site cannot invent a ledger key')
272
+
273
+ const line = surface.hostSurfaceLine()
274
+ assert.match(line, /rpcGuard=admit/)
275
+ assert.equal(line.split(' ').length, surface.HOST_SURFACES.length)
276
+ for (const part of line.split(' ')) assert.match(part, /^[a-zA-Z]+=\S+$/, 'every surface prints key=value: ' + line)
277
+ surface.noteHostSurface('rpcGuard', before.rpcGuard)
278
+ })
@@ -200,9 +200,129 @@ test('suite without any *.test.mjs fails loader/stub completeness', () => {
200
200
  assert.match(detailText(result), /tests\/: no \*\.test\.mjs file/)
201
201
  })
202
202
 
203
- test('runChecks returns the three gates in order', () => {
203
+ test('runChecks returns the four gates in order', () => {
204
204
  const root = makeFixture()
205
- assert.deepEqual(gate.runChecks(root).map((entry) => entry.label), ['rpc-method-count', 'test-tracking', 'loader-stubs'])
205
+ assert.deepEqual(gate.runChecks(root).map((entry) => entry.label),
206
+ ['rpc-method-count', 'test-tracking', 'loader-stubs', 'host-versions'])
207
+ })
208
+
209
+ // ---- Gate 4: the cross-version host ledger ----
210
+
211
+ const LEDGER_SURFACES = [
212
+ '| `rpcGuard` | RPC 入口守卫 | 存在性 | `lib/rpc.js:requestRejectionOf` | warn | requestRejection |',
213
+ '| `schedule` | 定时器 | edit | `lib/salient-wake.js:scheduleFlavor` | skip | global |',
214
+ '| `activation` | startActivation | rootOf | `lib/curator.js:activationUsesFlatSpec` | 换形 | nested |',
215
+ '| `coldLog` | 会话冷读 | 模块候选 | `lib/consolidation-snapshot.js:COLD_LOG_MODULES` | 活视图 | session-query |',
216
+ ].join('\n')
217
+
218
+ function ledgerRow(build, overrides = {}) {
219
+ const row = { commit: '66491b05e3', verdict: '源码', grade: 'exact', date: '2026-11-26', ...overrides }
220
+ return `| \`${build}\` | \`${row.commit}\` | ${row.verdict} | ${row.grade} | ${row.date} |`
221
+ + ' `rpcGuard=requestRejection;schedule=global;activation=nested;coldLog=session-query` | 桌面壳 |'
222
+ }
223
+
224
+ function makeHostFixture(options = {}) {
225
+ const root = tempDir()
226
+ write(root, 'lib/rpc.js', 'export function requestRejectionOf(connection, req) { return undefined }\n')
227
+ write(root, 'lib/salient-wake.js', 'export function scheduleFlavor(schedule) { return schedule ? \'global\' : null }\n')
228
+ write(root, 'lib/curator.js', 'export function activationUsesFlatSpec(subagents) { return Boolean(subagents) }\n')
229
+ write(root, 'lib/consolidation-snapshot.js', 'const COLD_LOG_MODULES = []\nexport const reconcile = 1\n')
230
+ if (options.package !== null) {
231
+ write(root, 'package.json', JSON.stringify(options.package
232
+ ?? { dsh: { compatibility: { dshReleases: ['0.2.2-rc.1'] } } }))
233
+ }
234
+ const rows = options.rows ?? [ledgerRow('0.2.2-rc.1')]
235
+ const surfaces = options.surfaces ?? LEDGER_SURFACES
236
+ write(root, 'docs/host-versions.md', '# 台账\n\n## 13.1 核对台账\n\n'
237
+ + '| 宿主构建 | commit | 核对方式 | 判定 | 日期 | 结构指纹 | 未覆盖面 |\n|---|---|---|---|---|---|---|\n'
238
+ + rows.join('\n') + '\n\n## 13.2 宿主面事实矩阵\n\n| 面ID | 宿主表面 | 探测判据 | 落点 | 降级 | 形状 |\n|---|---|---|---|---|---|\n'
239
+ + surfaces + '\n')
240
+ for (const [rel, body] of Object.entries(options.docs || {})) write(root, rel, body)
241
+ return root
242
+ }
243
+
244
+ const hostCheck = (root) => gate.checkHostVersions(root)
245
+
246
+ test('host-versions: a complete ledger passes', () => {
247
+ const result = hostCheck(makeHostFixture())
248
+ assert.equal(result.status, 'ok', JSON.stringify(result.details))
249
+ })
250
+
251
+ test('host-versions: a build named in another doc without a ledger row fails', () => {
252
+ const root = makeHostFixture({ docs: { 'docs/host-adaptation.md': '升到 `0.2.3-alpha.9` 后守卫变了。\n' } })
253
+ const result = hostCheck(root)
254
+ assert.equal(result.status, 'fail')
255
+ assert.ok(result.details.some((line) => line.includes('0.2.3-alpha.9') && line.includes('no row')), result.details.join('\n'))
256
+ })
257
+
258
+ test('host-versions: fenced code does not count as a build claim', () => {
259
+ const root = makeHostFixture({ docs: { 'docs/host-adaptation.md': '```bash\ngit tag dsh-v0.2.9-rc.7\n```\n' } })
260
+ assert.equal(hostCheck(root).status, 'ok')
261
+ })
262
+
263
+ test('host-versions: a renamed probe symbol fails until the ledger is updated', () => {
264
+ const root = makeHostFixture({ surfaces: LEDGER_SURFACES.replace('scheduleFlavor', 'flavourOfSchedule') })
265
+ const result = hostCheck(root)
266
+ assert.equal(result.status, 'fail')
267
+ assert.ok(result.details.some((line) => line.includes('schedule') && line.includes('not found')), result.details.join('\n'))
268
+ })
269
+
270
+ test('host-versions: a row must state how it was verified', () => {
271
+ const root = makeHostFixture({ rows: [ledgerRow('0.2.2-rc.1', { verdict: '大概可以' })] })
272
+ const result = hostCheck(root)
273
+ assert.equal(result.status, 'fail')
274
+ assert.ok(result.details.some((line) => line.includes('核对方式')), result.details.join('\n'))
275
+ })
276
+
277
+ test('host-versions: commit and date columns are checked', () => {
278
+ const root = makeHostFixture({ rows: [ledgerRow('0.2.2-rc.1', { commit: 'HEAD', date: '11-26' })] })
279
+ const result = hostCheck(root)
280
+ assert.equal(result.status, 'fail')
281
+ assert.ok(result.details.some((line) => line.includes('short sha')))
282
+ assert.ok(result.details.some((line) => line.includes('ISO')))
283
+ })
284
+
285
+ test('host-versions: a fingerprint key must be a registered surface', () => {
286
+ const root = makeHostFixture()
287
+ const docFile = path.join(root, 'docs', 'host-versions.md')
288
+ fs.writeFileSync(docFile, fs.readFileSync(docFile, 'utf8')
289
+ .replace('coldLog=session-query', 'cron=session-query'))
290
+ const result = hostCheck(root)
291
+ assert.equal(result.status, 'fail')
292
+ assert.ok(result.details.some((line) => line.includes('cron') && line.includes('not a surface')), result.details.join('\n'))
293
+ })
294
+
295
+ test('host-versions: a host version in running code fails, in a comment it does not', () => {
296
+ const root = makeHostFixture()
297
+ write(root, 'lib/versiongate.js', '// 0.2.3-alpha.1 起守卫换了形状\nexport const probed = true\n')
298
+ assert.equal(hostCheck(root).status, 'ok')
299
+ write(root, 'lib/versiongate.js', 'export const isAlpha = () => host === \'0.2.3-alpha.1\'\n')
300
+ const result = hostCheck(root)
301
+ assert.equal(result.status, 'fail')
302
+ assert.ok(result.details.some((line) => line.includes('versiongate.js') && line.includes('running code')), result.details.join('\n'))
303
+ })
304
+
305
+ test('host-versions: dshReleases must agree with the verified rows', () => {
306
+ const root = makeHostFixture({ rows: [ledgerRow('0.2.2-rc.1'), ledgerRow('0.2.2-rc.2')] })
307
+ const result = hostCheck(root)
308
+ assert.equal(result.status, 'fail')
309
+ assert.ok(result.details.some((line) => line.includes('dshReleases')), result.details.join('\n'))
310
+ const agreed = makeHostFixture({
311
+ rows: [ledgerRow('0.2.2-rc.1'), ledgerRow('0.2.2-rc.2')],
312
+ package: { dsh: { compatibility: { dshReleases: ['0.2.2-rc.1', '0.2.2-rc.2'] } } },
313
+ })
314
+ assert.equal(hostCheck(agreed).status, 'ok')
315
+ })
316
+
317
+ test('host-versions: an install directory without docs/ is skipped, not failed', () => {
318
+ const root = tempDir()
319
+ write(root, 'lib/rpc.js', 'export const shipped = true\n')
320
+ const result = hostCheck(root)
321
+ assert.equal(result.status, 'skipped', JSON.stringify(result))
322
+ })
323
+
324
+ test('host-versions: the shipped ledger itself passes the gate', () => {
325
+ assert.equal(hostCheck(REPO).status, 'ok', JSON.stringify(hostCheck(REPO).details))
206
326
  })
207
327
 
208
328
  test('CLI exits 1 and prints FAIL/skip when a gate fails', () => {