dsh-memu-memory 1.3.0 → 1.3.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +3 -3
  3. package/README.zh.md +3 -1
  4. package/docs/contributing.md +2 -2
  5. package/docs/env-and-commands.md +12 -1
  6. package/docs/memory-semantics.md +8 -2
  7. package/docs/troubleshooting.md +9 -6
  8. package/lib/auto-link/apply.js +249 -0
  9. package/lib/auto-link/candidates.js +155 -0
  10. package/lib/auto-link/decide.js +304 -0
  11. package/lib/auto-link/normalize.js +99 -0
  12. package/lib/auto-link/policy.js +42 -0
  13. package/lib/auto-link/suppression.js +101 -0
  14. package/lib/auto-link/terminology.js +265 -0
  15. package/lib/binding-diagnostics.js +3 -3
  16. package/lib/client.js +1435 -70
  17. package/lib/consolidation-receipt.js +81 -5
  18. package/lib/consolidation-worker.js +57 -25
  19. package/lib/curator.js +91 -11
  20. package/lib/engine.js +13 -3
  21. package/lib/graph.js +326 -39
  22. package/lib/inject.js +35 -15
  23. package/lib/media.js +8 -1
  24. package/lib/memory.js +27 -1
  25. package/lib/memu.js +26 -12
  26. package/lib/private-links.js +105 -137
  27. package/lib/private.js +280 -53
  28. package/lib/prompts/global-curator.md +6 -3
  29. package/lib/prompts/system-guide.md +4 -5
  30. package/lib/prompts.js +27 -1
  31. package/lib/rpc.js +69 -9
  32. package/lib/state.js +23 -4
  33. package/lib/tools.js +199 -67
  34. package/lib/webui/graph-LICENSE.txt +1 -62
  35. package/lib/webui/graph-view.bundle.js +1 -1
  36. package/lib/webui/graph-view.js +891 -124
  37. package/lib/webui/standalone.js +3 -3
  38. package/package.json +1 -2
  39. package/scripts/build-graph.mjs +3 -3
  40. package/scripts/check-graph-browser.mjs +106 -23
  41. package/scripts/rebuild-auto-links.mjs +252 -0
  42. package/tests/audit-regression.test.mjs +11 -8
  43. package/tests/auto-link-candidates.test.mjs +161 -0
  44. package/tests/auto-link-decide.test.mjs +512 -0
  45. package/tests/auto-link-migration.test.mjs +133 -0
  46. package/tests/client-render.test.mjs +7 -6
  47. package/tests/consolidation-credential.test.mjs +2 -2
  48. package/tests/consolidation-fork.test.mjs +188 -9
  49. package/tests/consolidation-ledger.test.mjs +31 -0
  50. package/tests/consolidation-snapshot.test.mjs +9 -8
  51. package/tests/curator-probe.test.mjs +32 -2
  52. package/tests/cycle.test.mjs +1 -1
  53. package/tests/graph-view.test.mjs +163 -21
  54. package/tests/graph.test.mjs +26 -0
  55. package/tests/help-page.test.mjs +3 -3
  56. package/tests/inject-conflict.test.mjs +1 -1
  57. package/tests/inject.test.mjs +1 -1
  58. package/tests/injection-chain.test.mjs +2 -2
  59. package/tests/injection-rollback.test.mjs +1 -1
  60. package/tests/memory-chain.test.mjs +28 -0
  61. package/tests/memu-resident-route.test.mjs +130 -0
  62. package/tests/mock-llm.test.mjs +1 -1
  63. package/tests/private-links.test.mjs +81 -45
  64. package/tests/prompts.test.mjs +1 -1
  65. package/tests/stubs/child-process-spy.mjs +14 -0
  66. package/tests/tool-schema.test.mjs +2 -1
  67. package/tests/tools.test.mjs +49 -21
@@ -19,6 +19,10 @@ const {
19
19
  inferEntityKind,
20
20
  } = privateLinks
21
21
 
22
+ // 旧写路径的用例验证 deterministic 模式下的行为;默认的 suggest(只出候选)
23
+ // 与 off 由文件末尾的专门用例覆盖。
24
+ state.updateSettings({ autoLinkMode: 'deterministic' })
25
+
22
26
  test.after(() => {
23
27
  try { state.flushState() } catch {}
24
28
  try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
@@ -301,25 +305,22 @@ test('an existing entity with a conflicting kind blocks the auto-link and become
301
305
 
302
306
  // ---- 应用层 ----
303
307
 
304
- test('autoLinkPrivateMemories applies the link, reuses Yuike and is idempotent', async () => {
308
+ test('deterministic mode links mentions of a confirmed entity and never writes lexical pairs', async () => {
305
309
  activity.clearEvents()
306
310
  const binding = bind('links-apply')
307
311
  const libraryId = binding.libraryId
308
- const yuike = graph.createEntity({ libraryId, name: 'Yuike', kind: 'person' })
312
+ const yuike = graph.createEntity({ libraryId, name: 'Yuike', kind: 'person', status: 'confirmed', confirmedBy: 'user' })
309
313
  state.savePrivateIndex(libraryId, snapshot({
310
314
  'mem-a': entry('猫娘yuike', 'yuike 是一只住在窗台的猫娘,喜欢在午后晒太阳。'),
311
315
  'mem-b': entry('yuike名字的由来', '这个名字来自小时候养过的一只白猫,后来一直被沿用。'),
312
316
  }))
313
317
 
314
- const result = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-apply', ids: ['mem-a'] })
315
- assert.equal(result.linked, 1)
316
- assert.equal(result.entities, 2)
318
+ const result = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-apply', ids: ['mem-a', 'mem-b'] })
319
+ assert.equal(result.linked, 0, 'the old lexical memory↔memory edge is never written')
320
+ assert.equal(result.entities, 2, 'both memories mention the confirmed entity')
317
321
  assert.equal(result.suggested, 0)
318
322
  assert.deepEqual(result.candidates, [])
319
- // The compact return the worker tool forwards: edges only, no bodies or notes, and
320
- // one entry per write (the memory pair first, then both hub links).
321
323
  assert.deepEqual(result.autoLinked.map(item => `${item.from}->${item.to}:${item.kind}`), [
322
- 'mem-a->mem-b:relation',
323
324
  `mem-a->${yuike.id}:person`,
324
325
  `mem-b->${yuike.id}:person`,
325
326
  ])
@@ -327,64 +328,51 @@ test('autoLinkPrivateMemories applies the link, reuses Yuike and is idempotent',
327
328
 
328
329
  const index = state.loadPrivateIndex(libraryId)
329
330
  const outbound = index.entries['mem-a'].links || []
330
- const memoryLink = outbound.find(link => link.to === 'mem-b')
331
- assert.ok(memoryLink, 'the high-confidence memory link is persisted')
332
- assert.equal(memoryLink.kind, 'relation')
333
- assert.equal(memoryLink.source, 'auto', 'the auto source is persisted on the link record')
334
- assert.match(memoryLink.note, /自动关联/)
335
- assert.match(memoryLink.note, /yuike/)
336
- assert.ok(memoryLink.confidence >= 0.6 && memoryLink.confidence <= 0.78)
331
+ assert.equal(outbound.some(link => link.to === 'mem-b'), false, 'no lexical pair edge survives')
337
332
  const entityLink = outbound.find(link => link.to === yuike.id)
338
- assert.ok(entityLink, 'the memory links to the reused entity hub')
333
+ assert.ok(entityLink, 'the confirmed-entity mention is persisted')
339
334
  assert.equal(entityLink.kind, 'person')
340
335
  assert.equal(entityLink.source, 'auto')
341
- assert.match(entityLink.note, /自动实体枢纽/)
342
- assert.equal(entityLink.confidence, 0.65)
343
- assert.ok((index.entries['mem-b'].links || []).some(link => link.to === yuike.id),
344
- 'every memory sharing the stable name is linked to the hub')
345
-
346
- const entities = Object.values(graph.graphExport(libraryId).entities)
347
- assert.equal(entities.length, 1, 'Yuike is reused, not duplicated as yuike')
348
- assert.equal(entities[0].id, yuike.id)
336
+ assert.equal(entityLink.confidence, 1, 'deterministic edges are confidence 1.0')
337
+ assert.equal(entityLink.schemaVersion, 2)
338
+ assert.equal(entityLink.evidence.rule, 'entity-mention')
339
+ assert.equal(entityLink.evidence.entityId, yuike.id)
340
+ assert.equal(entityLink.evidence.surface, 'Yuike')
341
+ assert.equal(entityLink.evidence.field, 'title')
342
+ assert.match(entityLink.note, /已确认实体/)
349
343
 
350
344
  const events = activity.listEvents({ kind: 'write', sessionId: 'links-apply' })
351
- const linkEvent = events.find(event => event.detail?.op === 'auto-link' && event.ok)
352
- const entityEvents = events.filter(event => event.detail?.op === 'auto-entity' && event.ok)
353
- assert.ok(linkEvent, 'the applied link is recorded in the activity log')
354
- assert.equal(linkEvent.detail.source, 'auto', 'source travels through the apply layer')
355
- assert.deepEqual(new Set(linkEvent.refs), new Set(['mem-a', 'mem-b']))
356
- assert.equal(entityEvents.length, 2)
357
- assert.ok(entityEvents.every(event => event.detail.source === 'auto'))
358
- assert.ok(entityEvents.every(event => event.detail.kind === 'person'))
345
+ const applyEvent = events.find(event => event.detail?.op === 'auto-link-apply' && event.ok)
346
+ assert.ok(applyEvent, 'the deterministic write is recorded in the activity log')
347
+ assert.equal(applyEvent.detail.added, 2)
348
+ assert.equal(applyEvent.detail.entity, 2)
359
349
 
360
350
  activity.clearEvents()
361
- const again = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-apply', ids: ['mem-a'] })
362
- assert.equal(again.linked, 0, 'an existing relation link makes the pair idempotent')
363
- assert.equal(again.entities, 0, 'a memory already linked to the entity is skipped')
351
+ const again = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-apply', ids: ['mem-a', 'mem-b'] })
352
+ assert.equal(again.linked, 0)
353
+ assert.equal(again.entities, 0, 'an unchanged pass is a no-op')
354
+ assert.deepEqual(again.autoLinked, [])
364
355
  const after = state.loadPrivateIndex(libraryId)
365
- assert.equal((after.entries['mem-a'].links || []).filter(link => link.to === 'mem-b').length, 1)
366
356
  assert.equal((after.entries['mem-a'].links || []).filter(link => link.to === yuike.id).length, 1)
367
357
  })
368
358
 
369
- test('autoLinkPrivateMemories links a thing hub with kind relation', async () => {
359
+ test('a confirmed non-person entity produces relation-kind mention edges', async () => {
370
360
  activity.clearEvents()
371
361
  const binding = bind('links-thing')
372
362
  const libraryId = binding.libraryId
363
+ const nebula = graph.createEntity({ libraryId, name: 'nebula', kind: 'thing', status: 'confirmed', confirmedBy: 'user' })
373
364
  state.savePrivateIndex(libraryId, snapshot({
374
365
  'mem-c': entry('nebula kickoff', 'the nebula survey starts at dawn near the outer ring.'),
375
366
  'mem-d': entry('nebula notes', 'a nebula chart was folded inside the old folder.'),
376
367
  }))
377
- const result = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-thing', ids: ['mem-c'] })
378
- assert.equal(result.linked, 1)
368
+ const result = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-thing', ids: ['mem-c', 'mem-d'] })
369
+ assert.equal(result.linked, 0)
379
370
  assert.equal(result.entities, 2)
380
- const entity = Object.values(graph.graphExport(libraryId).entities)
381
- .find(item => normalizeEntityName(item.name) === 'nebula')
382
- assert.ok(entity)
383
- assert.equal(entity.kind, 'thing')
384
371
  const index = state.loadPrivateIndex(libraryId)
385
- const link = (index.entries['mem-c'].links || []).find(item => item.to === entity.id)
372
+ const link = (index.entries['mem-c'].links || []).find(item => item.to === nebula.id)
386
373
  assert.ok(link)
387
- assert.equal(link.kind, 'relation', 'non-person hubs use kind relation')
374
+ assert.equal(link.kind, 'relation', 'non-person entities use kind relation')
375
+ assert.equal(link.evidence.rule, 'entity-mention')
388
376
  })
389
377
 
390
378
  test('autoLinkPrivateMemories never throws on a missing or broken index and logs a warning path', async () => {
@@ -437,6 +425,54 @@ test('autoLinkPrivateMemories never throws on a missing or broken index and logs
437
425
  assert.equal(activity.listEvents({ kind: 'write' }).length, before, 'no ids means no work and no log row')
438
426
  })
439
427
 
428
+ test('suggest is the default mode and the only valid values are suggest/deterministic/off', () => {
429
+ assert.equal(state.DEFAULT_SETTINGS.autoLinkMode, 'suggest', 'migration starts with the write gate closed')
430
+ assert.equal(state.DEFAULT_SETTINGS.allowWorkerAssertion, false, 'worker assertion is reserved and off')
431
+ assert.throws(() => state.updateSettings({ autoLinkMode: 'auto' }), /invalid setting autoLinkMode/)
432
+ assert.throws(() => state.updateSettings({ allowWorkerAssertion: 'yes' }), /must be boolean/)
433
+ })
434
+
435
+ test('suggest mode returns candidates without writing edges or creating entities', async () => {
436
+ state.updateSettings({ autoLinkMode: 'suggest' })
437
+ try {
438
+ const binding = bind('links-suggest')
439
+ const libraryId = binding.libraryId
440
+ state.savePrivateIndex(libraryId, snapshot({
441
+ 'mem-a': entry('星港入口', '深夜的星港入口很冷,风从卸货区一直灌进来。'),
442
+ 'mem-b': entry('星港夜班', '星港的夜班登记表还压在值班室桌上。'),
443
+ }))
444
+ const result = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-suggest', ids: ['mem-a'] })
445
+ assert.equal(result.linked, 0, 'suggest never writes a memory edge')
446
+ assert.equal(result.entities, 0, 'suggest never creates or links an entity')
447
+ assert.deepEqual(result.autoLinked, [])
448
+ assert.equal(result.candidates.length, 1, 'the uncertain pair is still returned for adjudication')
449
+ assert.equal(result.suggested, 1)
450
+ const index = state.loadPrivateIndex(libraryId)
451
+ assert.equal(index.entries['mem-a'].links, undefined, 'index is untouched')
452
+ assert.deepEqual(Object.keys(graph.graphExport(libraryId).entities), [], 'no entity is created')
453
+ } finally {
454
+ state.updateSettings({ autoLinkMode: 'deterministic' })
455
+ }
456
+ })
457
+
458
+ test('off mode skips the suggestion pass entirely', async () => {
459
+ state.updateSettings({ autoLinkMode: 'off' })
460
+ try {
461
+ const binding = bind('links-off')
462
+ const libraryId = binding.libraryId
463
+ state.savePrivateIndex(libraryId, snapshot({
464
+ 'mem-a': entry('猫娘yuike', 'yuike 是一只住在窗台的猫娘,喜欢在午后晒太阳。'),
465
+ 'mem-b': entry('yuike名字的由来', '这个名字来自小时候养过的一只白猫,后来一直被沿用。'),
466
+ }))
467
+ const result = await autoLinkPrivateMemories({ libraryId, sessionId: 'links-off', ids: ['mem-a'] })
468
+ assert.deepEqual(result, ZERO)
469
+ assert.equal(state.loadPrivateIndex(libraryId).entries['mem-a'].links, undefined)
470
+ assert.deepEqual(Object.keys(graph.graphExport(libraryId).entities), [])
471
+ } finally {
472
+ state.updateSettings({ autoLinkMode: 'deterministic' })
473
+ }
474
+ })
475
+
440
476
  test('the default export exposes the whole module surface', () => {
441
477
  assert.equal(privateLinks.default.suggestPrivateLinks, suggestPrivateLinks)
442
478
  assert.equal(privateLinks.default.autoLinkPrivateMemories, autoLinkPrivateMemories)
@@ -222,7 +222,7 @@ test('title guidance ships in every consolidation page; tool workflow lives in t
222
222
 
223
223
  const { buildWorkerBrief } = await import('../lib/consolidation-worker.js')
224
224
  const brief = buildWorkerBrief({ snapshot: { fromSeq: 1, throughSeq: 2, eventCount: 2, hash: 'prompt-test' }, probe: null, contract: '' })
225
- for (const rule of [/memu_private_remember/, /memu_private_update/, /memu_private_link_suggest/, /每窗最多新增 8 条/]) {
225
+ for (const rule of [/memu_private_remember/, /memu_private_update/, /memu_private_remember_batch/, /总数仍不超过 8 条/]) {
226
226
  assert.match(brief, rule, 'the local worker brief owns the tool workflow')
227
227
  }
228
228
  assert.match(prompts.CONSOLIDATION_CONTRACTS.remote, /8-40字/, 'the remote JSON contract uses the same title length')
@@ -0,0 +1,14 @@
1
+ // Only lib/memu.js is routed here (see tests/memu-resident-route.test.mjs), and
2
+ // only `spawn` is intercepted: the test injects a fake child that speaks the
3
+ // resident worker protocol. Everything else, and every other importer in the
4
+ // process, still gets the real child_process.
5
+ import real from 'node:child_process'
6
+
7
+ export * from 'node:child_process'
8
+
9
+ export const spawn = (...args) => {
10
+ const spy = globalThis.__dshMemuSpawnSpy
11
+ return typeof spy === 'function' ? spy(...args) : real.spawn(...args)
12
+ }
13
+
14
+ export default { ...real, spawn }
@@ -68,6 +68,7 @@ test('the shipped tool surface compiles under the host rules', async () => {
68
68
  tools: { register: (tool) => { registered.push(tool.name); return () => {} } },
69
69
  logger: { warn: (message) => { throw new Error(`unexpected registration warning: ${message}`) } },
70
70
  })
71
- assert.equal(registered.length, 13, `registered ${registered.join(', ')}`)
71
+ assert.equal(registered.length, 14, `registered ${registered.join(', ')}`)
72
+ assert.ok(registered.includes('memu_private_remember_batch'), 'the batch write tool compiles under the host rules')
72
73
  dispose()
73
74
  })
@@ -41,6 +41,7 @@ test('all v1 tools register', () => {
41
41
  'memu_private_link',
42
42
  'memu_private_link_suggest',
43
43
  'memu_private_remember',
44
+ 'memu_private_remember_batch',
44
45
  'memu_private_recall',
45
46
  'memu_private_list',
46
47
  'memu_private_update',
@@ -54,10 +55,31 @@ test('all v1 tools register', () => {
54
55
  ]) {
55
56
  assert.ok(names.includes(name), `missing ${name}`)
56
57
  }
57
- // Exactly thirteen, not "at least these twelve": a schema the host DSL refuses used to
58
+ // Exactly fourteen, not "at least these": a schema the host DSL refuses used to
58
59
  // abort registerTools() before any register() ran, so counting is the assertion
59
60
  // that actually catches a total registration failure.
60
- assert.equal(names.length, 13, `expected 13 tools, got ${names.length}: ${names.join(', ')}`)
61
+ assert.equal(names.length, 14, `expected 14 tools, got ${names.length}: ${names.join(', ')}`)
62
+ dispose()
63
+ })
64
+
65
+ test('batch write applies shared defaults and reports each item', async () => {
66
+ const { tools, dispose } = fakeCtx()
67
+ const batch = tools.find((t) => t.name === 'memu_private_remember_batch')
68
+ const batchExec = {
69
+ agent: { session: { header: { id: 'tools-batch-session', cwd: path.join(home, 'project-batch'), agentPreset: 'coding' } } },
70
+ }
71
+ const reply = await batch.execute({
72
+ defaults: { speaker_id: 'user', source: 'user_said', observed_at: '2026-11-06T04:00:00+08:00' },
73
+ items: [
74
+ { title: '码头见面', content: '明天下午三点在码头见面,别迟到。' },
75
+ { title: '带伞', content: '她说码头风大,让我带把伞。' },
76
+ ],
77
+ }, batchExec)
78
+ assert.match(reply, /批量写入完成:新增 2/)
79
+ assert.match(reply, /1\. 已写入私有记忆/)
80
+ assert.match(reply, /2\. 已写入私有记忆/)
81
+ const empty = await batch.execute({ items: [] }, batchExec)
82
+ assert.match(empty, /items 为空/)
61
83
  dispose()
62
84
  })
63
85
 
@@ -68,7 +90,7 @@ test('status works without an engine', async () => {
68
90
  assert.match(status, /library:/)
69
91
  // The registration count is the visible signal for a refused schema: without it
70
92
  // a host that rejects the tool and a plugin that never had it look identical.
71
- assert.match(status, /tools: 13\/13 registered/)
93
+ assert.match(status, /tools: 14\/14 registered/)
72
94
  dispose()
73
95
  })
74
96
 
@@ -138,11 +160,13 @@ test('lexicon propose writes an active entry immediately; search only sees activ
138
160
  dispose()
139
161
  })
140
162
 
141
- test('link suggest applies high-confidence links and returns only uncertain candidates', async () => {
163
+ test('link suggest refreshes deterministic mention edges and returns only uncertain candidates', async () => {
142
164
  const { tools, dispose } = fakeCtx()
143
165
  const cwd = path.join(home, 'project-links')
144
166
  const execLinks = { agent: { session: { header: { id: 'tools-links', cwd, agentPreset: 'rp' } } } }
145
167
  const binding = state.ensureSession('tools-links', { cwd, agentPreset: 'rp' })
168
+ const graph = await import('../lib/graph.js')
169
+ const yuike = graph.createEntity({ libraryId: binding.libraryId, name: 'yuike', kind: 'person', status: 'confirmed', confirmedBy: 'user' })
146
170
  state.savePrivateIndex(binding.libraryId, { version: 1, entries: {
147
171
  'mem-a': { title: '猫娘yuike', content: 'yuike 是一只住在窗台的猫娘,喜欢晒太阳。', status: 'active', visibility: 'shared', layer: 'long_term' },
148
172
  'mem-b': { title: 'yuike名字的由来', content: '这个名字来自小时候养过的一只白猫。', status: 'active', visibility: 'shared', layer: 'long_term' },
@@ -157,24 +181,28 @@ test('link suggest applies high-confidence links and returns only uncertain cand
157
181
  const empty = await suggest.execute({ ids: [] }, execLinks)
158
182
  assert.match(empty, /1-20/)
159
183
 
160
- const payload = JSON.parse(await suggest.execute({ ids: ['mem-a'] }, execLinks))
161
- assert.deepEqual(Object.keys(payload).sort(), ['autoLinked', 'candidates'], 'the tool answers with the two-field contract only')
162
- assert.deepEqual(payload.candidates, [], 'the yuike pair is high confidence, so nothing is handed over')
163
- assert.equal(payload.autoLinked.length, 3, 'relation link plus one hub link per memory')
164
- for (const edge of payload.autoLinked) {
165
- assert.deepEqual(Object.keys(edge).sort(), ['from', 'kind', 'to'], 'no bodies or notes in the compact payload')
166
- }
167
- assert.ok(payload.autoLinked.some((edge) => edge.from === 'mem-a' && edge.to === 'mem-b' && edge.kind === 'relation'))
168
- assert.ok(payload.autoLinked.some((edge) => edge.from === 'mem-a' && edge.kind === 'person'))
169
- // The auto source survives into the graph the UI reads.
170
- const graph = await import('../lib/graph.js')
171
- const view = graph.getGraph({ libraryId: binding.libraryId, focusId: 'mem-a', depth: 1 })
172
- assert.ok(view.edges.some((edge) => edge.from === 'mem-a' && edge.to === 'mem-b' && edge.source === 'auto'))
184
+ updateSettings({ autoLinkMode: 'deterministic' })
185
+ try {
186
+ const payload = JSON.parse(await suggest.execute({ ids: ['mem-a', 'mem-b'] }, execLinks))
187
+ assert.deepEqual(Object.keys(payload).sort(), ['autoLinked', 'candidates'], 'the tool answers with the two-field contract only')
188
+ assert.deepEqual(payload.candidates, [], 'the yuike pair is a deterministic mention, not an uncertain candidate')
189
+ assert.equal(payload.autoLinked.length, 2, 'one mention edge per memory, no lexical pair edge')
190
+ for (const edge of payload.autoLinked) {
191
+ assert.deepEqual(Object.keys(edge).sort(), ['from', 'kind', 'to'], 'no bodies or notes in the compact payload')
192
+ assert.equal(edge.to, yuike.id)
193
+ assert.equal(edge.kind, 'person')
194
+ }
195
+ // The deterministic edge survives into the graph the UI reads.
196
+ const view = graph.getGraph({ libraryId: binding.libraryId, focusId: 'mem-a', depth: 1 })
197
+ assert.ok(view.edges.some((edge) => edge.from === 'mem-a' && edge.to === yuike.id && edge.source === 'auto'))
173
198
 
174
- // Running it again is idempotent: no new links, same empty candidate list.
175
- const rerun = JSON.parse(await suggest.execute({ ids: ['mem-a', 'mem-b'] }, execLinks))
176
- assert.deepEqual(rerun.autoLinked, [])
177
- assert.deepEqual(rerun.candidates, [])
199
+ // Running it again is idempotent: no new links, same empty candidate list.
200
+ const rerun = JSON.parse(await suggest.execute({ ids: ['mem-a', 'mem-b'] }, execLinks))
201
+ assert.deepEqual(rerun.autoLinked, [])
202
+ assert.deepEqual(rerun.candidates, [])
203
+ } finally {
204
+ updateSettings({ autoLinkMode: 'suggest' })
205
+ }
178
206
  dispose()
179
207
  })
180
208