dsh-memu-memory 1.3.14 → 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 (59) hide show
  1. package/AGENTS.md +6 -3
  2. package/CHANGELOG.md +50 -1
  3. package/docs/binding-lifecycle.md +1 -1
  4. package/docs/client-conventions.md +1 -0
  5. package/docs/host-adaptation.md +58 -16
  6. package/docs/host-versions.md +120 -0
  7. package/docs/memory-semantics.md +4 -1
  8. package/docs/pending-work.md +51 -0
  9. package/docs/troubleshooting.md +16 -3
  10. package/lib/auto-link/candidates.js +4 -1
  11. package/lib/auto-link/decide.js +1 -1
  12. package/lib/auto-link/normalize.js +2 -2
  13. package/lib/auto-link/terminology.js +31 -1
  14. package/lib/binding-diagnostics.js +1 -1
  15. package/lib/client.js +53 -6
  16. package/lib/consolidation-snapshot.js +37 -1
  17. package/lib/curator.js +1 -1
  18. package/lib/cycle.js +5 -0
  19. package/lib/diagnostics.js +10 -0
  20. package/lib/entity-repair.js +285 -0
  21. package/lib/environment-check.js +72 -3
  22. package/lib/global-graph.js +11 -2
  23. package/lib/graph.js +32 -8
  24. package/lib/host-surface.js +30 -0
  25. package/lib/index.js +116 -1
  26. package/lib/inject.js +428 -32
  27. package/lib/private-links.js +12 -0
  28. package/lib/rpc.js +78 -11
  29. package/lib/state.js +78 -1
  30. package/package.json +16 -1
  31. package/scripts/chain-matrix.mjs +4 -0
  32. package/scripts/check-doc-drift.mjs +194 -0
  33. package/scripts/entity-dedupe.mjs +110 -0
  34. package/tests/auto-link-candidates.test.mjs +22 -9
  35. package/tests/auto-link-decide.test.mjs +59 -59
  36. package/tests/auto-link-migration.test.mjs +4 -4
  37. package/tests/client-render.test.mjs +112 -1
  38. package/tests/cue.test.mjs +2 -1
  39. package/tests/cycle.test.mjs +2 -2
  40. package/tests/diagnostics.test.mjs +21 -0
  41. package/tests/doc-drift.test.mjs +122 -2
  42. package/tests/entity-merge.test.mjs +17 -0
  43. package/tests/environment-check.test.mjs +28 -0
  44. package/tests/global-graph.test.mjs +16 -0
  45. package/tests/global-lifecycle.test.mjs +24 -4
  46. package/tests/graph-cascade.test.mjs +111 -0
  47. package/tests/hybrid-recall.test.mjs +1 -1
  48. package/tests/inject.test.mjs +7 -7
  49. package/tests/injection-chain.test.mjs +40 -2
  50. package/tests/injection-rollback.test.mjs +4 -3
  51. package/tests/managed-memory.test.mjs +7 -7
  52. package/tests/media.test.mjs +4 -1
  53. package/tests/memory-chain.test.mjs +4 -3
  54. package/tests/pending-injection.test.mjs +107 -0
  55. package/tests/private-links.test.mjs +12 -0
  56. package/tests/recall-corpus-eligibility.test.mjs +3 -3
  57. package/tests/settings-plumbing.test.mjs +2 -0
  58. package/tests/tools.test.mjs +1 -1
  59. package/tests/webui-auth.test.mjs +58 -0
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ // scripts/entity-dedupe.mjs — 实体名字碎片的体检与修复(docs/pending-work.md §14.2 P7)
3
+ //
4
+ // 规划与执行都在 lib/entity-repair.js 里——启动自愈、诊断页的修复按钮和本脚本共用同一套
5
+ // 判据,不存在"脚本会合、程序不会合"这种分叉。这里只是命令行外壳。
6
+ //
7
+ // 两类结论,处理方式不同:
8
+ // · attested(可证明)——片段首尾重叠重建出的完整名在正文里出现过,或短名从未独立于长名出现。
9
+ // · similar(只是相似)——编辑距离 / 名字核撞上来的两个称呼。默认**不动**,要 `--include-similar`
10
+ // 且逐条打印后仍由你决定;批量自动跑永远只碰 attested。
11
+ //
12
+ // 从不删除记忆:合并只改指向,条目正文一字不动(硬规则 5)。孤立节点只列出来。
13
+ //
14
+ // 用法:
15
+ // node scripts/entity-dedupe.mjs # 全部库体检(默认 dry-run,零写入)
16
+ // node scripts/entity-dedupe.mjs --library <id> # 只看一个库
17
+ // node scripts/entity-dedupe.mjs --apply # 先图备份,再合并 attested 组
18
+ // node scripts/entity-dedupe.mjs --apply --include-similar
19
+ // DSH_MEMU_HOME=<dsh home>/dsh-memu-memory node scripts/entity-dedupe.mjs
20
+ import process from 'node:process'
21
+ import { pathToFileURL } from 'node:url'
22
+
23
+ function parseArgs(argv) {
24
+ const options = { apply: false, library: null, help: false, includeSimilar: false }
25
+ for (let i = 0; i < argv.length; i += 1) {
26
+ const arg = argv[i]
27
+ if (arg === '--apply') options.apply = true
28
+ else if (arg === '--include-similar') options.includeSimilar = true
29
+ else if (arg === '--library') options.library = String(argv[++i] || '')
30
+ else if (arg.startsWith('--library=')) options.library = arg.slice('--library='.length)
31
+ else if (arg === '--help' || arg === '-h') options.help = true
32
+ else throw new Error('unknown argument: ' + arg + ' (see --help)')
33
+ }
34
+ return options
35
+ }
36
+
37
+ async function main() {
38
+ const options = parseArgs(process.argv.slice(2))
39
+ if (options.help) {
40
+ console.log('usage: node scripts/entity-dedupe.mjs [--library <id>] [--apply] [--include-similar]')
41
+ console.log('dry-run by default; --apply takes one graph backup first, then merges the provable groups')
42
+ return
43
+ }
44
+ const state = await import('../lib/state.js')
45
+ const repair = await import('../lib/entity-repair.js')
46
+ const backup = await import('../lib/backup.js')
47
+
48
+ if (options.library && !state.getLibrary(String(options.library))) throw new Error('library not found: ' + options.library)
49
+ const plan = repair.planAllRepairs({
50
+ listLibraries: state.listLibraries,
51
+ loadPrivateIndex: state.loadPrivateIndex,
52
+ libraryId: options.library || null,
53
+ })
54
+
55
+ for (const entry of plan.plans) {
56
+ if (!entry.groups.length && !entry.ambiguous.length) continue
57
+ console.log(`\n[${entry.libraryId}] — ${entry.scanned} 个实体,${entry.groups.length} 组可证明,${entry.ambiguous.length} 组只是相似`
58
+ + (entry.partial ? '(正文只扫了最近 3000 条)' : ''))
59
+ for (const line of repair.summarizePlan({ groups: entry.groups })) console.log(' · ' + line)
60
+ for (const line of repair.summarizePlan({ groups: entry.ambiguous })) console.log(' ? ' + line + ' ← 需人工确认')
61
+ }
62
+ for (const failure of plan.failures) console.log(` ! [${failure.libraryId}] 规划失败:${failure.error}`)
63
+
64
+ if (!plan.attested && !plan.similar) {
65
+ console.log('\n没有需要处理的实体组。')
66
+ return
67
+ }
68
+ if (!options.apply) {
69
+ console.log(`\ndry-run:可自动合并 ${plan.attested} 组,相似待确认 ${plan.similar} 组。确认无误后加 --apply(会先做一次图备份)`)
70
+ return
71
+ }
72
+ const groups = []
73
+ for (const entry of plan.plans) {
74
+ const picked = options.includeSimilar ? [...entry.groups, ...entry.ambiguous] : entry.groups
75
+ if (picked.length) groups.push({ libraryId: entry.libraryId, picked })
76
+ }
77
+ if (!groups.length) {
78
+ console.log('\n没有可自动合并的组;相似候选请加 --include-similar 或到关系图谱里逐个确认。')
79
+ return
80
+ }
81
+ // 备份在任何写之前:合并只改指向,但撤销要靠这份快照。
82
+ const created = await backup.createBackup({ label: 'entity-dedupe' })
83
+ console.log('\n图备份:' + (created?.name || created?.dir || JSON.stringify(created)))
84
+
85
+ let merged = 0
86
+ let made = 0
87
+ let protectedRows = 0
88
+ const failures = []
89
+ for (const entry of groups) {
90
+ const result = repair.applyRepairGroups(entry.libraryId, entry.picked)
91
+ merged += result.merged
92
+ made += result.created
93
+ protectedRows += result.restored
94
+ for (const failure of result.failures) failures.push(`[${entry.libraryId}] ${failure.group}: ${failure.error}`)
95
+ }
96
+ console.log(`\n已合并 ${merged} 组(新建完整名 ${made} 个,写回被清扫误伤的实体 ${protectedRows} 个)。`)
97
+ console.log('下一步重算确定性边:node scripts/rebuild-auto-links.mjs --apply')
98
+ if (failures.length) {
99
+ console.log('\n失败明细:')
100
+ for (const line of failures) console.log(' ! ' + line)
101
+ process.exitCode = 1
102
+ }
103
+ }
104
+
105
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
106
+ main().catch((error) => {
107
+ console.error('entity-dedupe failed: ' + (error && error.stack ? error.stack : error))
108
+ process.exitCode = 1
109
+ })
110
+ }
@@ -31,8 +31,8 @@ function entry(title, content, extra = {}) {
31
31
 
32
32
  function fixture() {
33
33
  return {
34
- 'mem-1': entry('「小柚」今天来了', '她带着伞。'),
35
- 'mem-2': entry('小柚的伞', '小柚把伞放在门口。'),
34
+ 'mem-1': entry('「小檀」今天来了', '她带着伞。'),
35
+ 'mem-2': entry('小檀的伞', '小檀把伞放在门口。'),
36
36
  'mem-3': entry('她叫阿兰', '阿兰是隔壁的邻居。'),
37
37
  'mem-4': entry('yuike_01 上线', 'yuike_01 又迟到了。'),
38
38
  'mem-5': entry('星港夜班', '今日星港开始检修,傍晚星港的风很大。'),
@@ -46,8 +46,8 @@ function fixture() {
46
46
  test('term statistics carry df/titleDf/boundary/cohesion for real names and drop glue bigrams', () => {
47
47
  const rows = Object.entries(fixture()).map(([id, item]) => ({ id, title: item.title, text: `${item.title}\n${item.content}` }))
48
48
  const stats = terminology.buildTermStats(rows)
49
- const you = stats.get('小柚')
50
- assert.ok(you, '小柚 is a repeated bigram')
49
+ const you = stats.get('小檀')
50
+ assert.ok(you, '小檀 is a repeated bigram')
51
51
  assert.equal(you.df, 2)
52
52
  assert.equal(you.titleDf, 2)
53
53
  assert.ok(you.avLeft >= 2 && you.avRight >= 2, 'both boundaries vary: ' + you.avLeft + '/' + you.avRight)
@@ -58,7 +58,7 @@ test('term statistics carry df/titleDf/boundary/cohesion for real names and drop
58
58
  assert.ok(star && star.df >= 2 && star.tf >= 4)
59
59
  assert.equal(terminology.looksGeneric('这个'), true, 'function characters disqualify a surface')
60
60
  assert.equal(terminology.looksGeneric('一条'), true, 'measure-word templates disqualify a surface')
61
- assert.equal(terminology.looksGeneric('小柚'), false)
61
+ assert.equal(terminology.looksGeneric('小檀'), false)
62
62
  })
63
63
 
64
64
  test('ranking puts evidenced terms in tier 1 and pure statistics in tier 2', () => {
@@ -67,13 +67,26 @@ test('ranking puts evidenced terms in tier 1 and pure statistics in tier 2', ()
67
67
  const ranked = terminology.rankCandidates(entries, stats)
68
68
  const tier1 = ranked.tier1.map(row => row.term)
69
69
  const tier2 = ranked.tier2.map(row => row.term)
70
- assert.ok(tier1.includes('小柚'), 'quoted name is tier 1: ' + tier1.join(','))
70
+ assert.ok(tier1.includes('小檀'), 'quoted name is tier 1: ' + tier1.join(','))
71
71
  assert.ok(tier1.includes('阿兰'), 'name-intro is tier 1: ' + tier1.join(','))
72
72
  assert.ok(tier1.includes('yuike_01'), 'mixed identifier is tier 1: ' + tier1.join(','))
73
73
  assert.ok(tier2.includes('星港'), 'statistical-only name stays tier 2: ' + tier2.join(','))
74
74
  assert.equal([...tier1, ...tier2].includes('这个'), false, 'glue bigram never becomes a candidate')
75
75
  assert.equal([...tier1, ...tier2].includes('2026'), false)
76
- assert.ok(ranked.tier1.find(row => row.term === '小柚').quoted)
76
+ assert.ok(ranked.tier1.find(row => row.term === '小檀').quoted)
77
+ })
78
+
79
+ test('overlapping window fragments of a longer name never become candidates', () => {
80
+ const entries = [
81
+ { id: 'm1', title: '南宫晚晴的午后', text: '南宫晚晴的午后\n南宫晚晴坐在窗边讲这件事。' },
82
+ { id: 'm2', title: '和南宫晚晴一起', text: '和南宫晚晴一起\n南宫晚晴先到了门口。' },
83
+ ]
84
+ const stats = terminology.buildTermStats(entries)
85
+ const ranked = terminology.rankCandidates(entries, stats)
86
+ const terms = [...ranked.tier1, ...ranked.tier2].map(row => row.term)
87
+ assert.ok(terms.includes('南宫晚晴'), 'the whole surface stays nominated: ' + terms.join(','))
88
+ assert.equal(terms.includes('南宫晚'), false, 'a window of a longer name is not a person')
89
+ assert.equal(terms.includes('宫晚晴'), false, 'the other window is not a second person either')
77
90
  })
78
91
 
79
92
  test('the queue snapshot persists, maps existing entities and stays stable across reads', () => {
@@ -212,10 +225,10 @@ test('custom candidate policy invalidates both cache layers for that library', a
212
225
  const lib = library('policy-cache')
213
226
  state.savePrivateIndex(lib, { version: 1, entries: fixture() })
214
227
  const normal = candidates.generateAnchorCandidates({ libraryId: lib, now: 1 })
215
- assert.equal(normal.tiers.tier1.find(row => row.term === '小柚')?.df, 2)
228
+ assert.equal(normal.tiers.tier1.find(row => row.term === '小檀')?.df, 2)
216
229
  const strictPolicy = { ...AUTOLINK_POLICY_V3, minDf: 3 }
217
230
  const strict = candidates.generateAnchorCandidates({ libraryId: lib, now: 2, policy: strictPolicy })
218
- assert.equal(strict.tiers.tier1.some(row => row.term === '小柚'), false)
231
+ assert.equal(strict.tiers.tier1.some(row => row.term === '小檀'), false)
219
232
  candidates.resetAnchorCandidatesCache()
220
233
  assert.deepEqual(candidates.generateAnchorCandidates({ libraryId: lib, now: 3, policy: { ...strictPolicy } }), strict)
221
234
  candidates.resetAnchorCandidatesCache()
@@ -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
+ })
@@ -31,7 +31,8 @@ test('random cue is injected once and armed', async () => {
31
31
  const sessionEvent = handlers.get('session/event')
32
32
  assert.equal(typeof sessionEvent, 'function')
33
33
  const out = await inject.injectForStep({ agent, decision, turn: 2, step: 1, signal: { aborted: false }, ctx })
34
- const text = out.messages[0]?.content?.[0]?.text || ''
34
+ const pluginMessage = out.messages.find(message => message?.source?.kind === 'plugin:dsh-memu-memory')
35
+ const text = pluginMessage?.content?.[0]?.text || ''
35
36
  assert.ok(text.includes('<memory-cue id="'))
36
37
  assert.equal(state.getActiveCue('cue-session'), null, 'a proposal must not arm the cue')
37
38
  for (const message of out.messages) {