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.
- package/CHANGELOG.md +50 -0
- package/README.md +3 -3
- package/README.zh.md +3 -1
- package/docs/contributing.md +2 -2
- package/docs/env-and-commands.md +12 -1
- package/docs/memory-semantics.md +8 -2
- package/docs/troubleshooting.md +9 -6
- package/lib/auto-link/apply.js +249 -0
- package/lib/auto-link/candidates.js +155 -0
- package/lib/auto-link/decide.js +304 -0
- package/lib/auto-link/normalize.js +99 -0
- package/lib/auto-link/policy.js +42 -0
- package/lib/auto-link/suppression.js +101 -0
- package/lib/auto-link/terminology.js +265 -0
- package/lib/binding-diagnostics.js +3 -3
- package/lib/client.js +1435 -70
- package/lib/consolidation-receipt.js +81 -5
- package/lib/consolidation-worker.js +57 -25
- package/lib/curator.js +91 -11
- package/lib/engine.js +13 -3
- package/lib/graph.js +326 -39
- package/lib/inject.js +35 -15
- package/lib/media.js +8 -1
- package/lib/memory.js +27 -1
- package/lib/memu.js +26 -12
- package/lib/private-links.js +105 -137
- package/lib/private.js +280 -53
- package/lib/prompts/global-curator.md +6 -3
- package/lib/prompts/system-guide.md +4 -5
- package/lib/prompts.js +27 -1
- package/lib/rpc.js +69 -9
- package/lib/state.js +23 -4
- package/lib/tools.js +199 -67
- package/lib/webui/graph-LICENSE.txt +1 -62
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +891 -124
- package/lib/webui/standalone.js +3 -3
- package/package.json +1 -2
- package/scripts/build-graph.mjs +3 -3
- package/scripts/check-graph-browser.mjs +106 -23
- package/scripts/rebuild-auto-links.mjs +252 -0
- package/tests/audit-regression.test.mjs +11 -8
- package/tests/auto-link-candidates.test.mjs +161 -0
- package/tests/auto-link-decide.test.mjs +512 -0
- package/tests/auto-link-migration.test.mjs +133 -0
- package/tests/client-render.test.mjs +7 -6
- package/tests/consolidation-credential.test.mjs +2 -2
- package/tests/consolidation-fork.test.mjs +188 -9
- package/tests/consolidation-ledger.test.mjs +31 -0
- package/tests/consolidation-snapshot.test.mjs +9 -8
- package/tests/curator-probe.test.mjs +32 -2
- package/tests/cycle.test.mjs +1 -1
- package/tests/graph-view.test.mjs +163 -21
- package/tests/graph.test.mjs +26 -0
- package/tests/help-page.test.mjs +3 -3
- package/tests/inject-conflict.test.mjs +1 -1
- package/tests/inject.test.mjs +1 -1
- package/tests/injection-chain.test.mjs +2 -2
- package/tests/injection-rollback.test.mjs +1 -1
- package/tests/memory-chain.test.mjs +28 -0
- package/tests/memu-resident-route.test.mjs +130 -0
- package/tests/mock-llm.test.mjs +1 -1
- package/tests/private-links.test.mjs +81 -45
- package/tests/prompts.test.mjs +1 -1
- package/tests/stubs/child-process-spy.mjs +14 -0
- package/tests/tool-schema.test.mjs +2 -1
- 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('
|
|
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,
|
|
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
|
-
|
|
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
|
|
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.
|
|
342
|
-
assert.equal(entityLink.
|
|
343
|
-
assert.
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
assert.
|
|
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
|
|
352
|
-
|
|
353
|
-
assert.
|
|
354
|
-
assert.equal(
|
|
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
|
|
363
|
-
assert.equal(again.entities, 0, '
|
|
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('
|
|
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,
|
|
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 ===
|
|
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
|
|
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)
|
package/tests/prompts.test.mjs
CHANGED
|
@@ -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/, /
|
|
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,
|
|
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
|
})
|
package/tests/tools.test.mjs
CHANGED
|
@@ -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
|
|
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,
|
|
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:
|
|
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
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
assert.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
|