dsh-memu-memory 1.3.6 → 1.3.8

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 (61) hide show
  1. package/AGENTS.md +2 -1
  2. package/CHANGELOG.md +87 -0
  3. package/README.md +7 -7
  4. package/README.zh.md +7 -7
  5. package/docs/client-conventions.md +4 -0
  6. package/docs/contributing.md +2 -2
  7. package/docs/memory-semantics.md +10 -7
  8. package/docs/troubleshooting.md +132 -7
  9. package/lib/binding-diagnostics.js +2 -2
  10. package/lib/client.js +296 -122
  11. package/lib/consolidation-ledger.js +6 -2
  12. package/lib/consolidation-worker.js +7 -0
  13. package/lib/inbound.js +24 -9
  14. package/lib/inject.js +379 -215
  15. package/lib/lexicon.js +5 -0
  16. package/lib/local-embedding-manager.js +4 -0
  17. package/lib/local-vector-service.js +65 -1
  18. package/lib/memory.js +711 -175
  19. package/lib/paths.js +24 -0
  20. package/lib/private.js +284 -127
  21. package/lib/rpc.js +144 -45
  22. package/lib/snippet.js +49 -28
  23. package/lib/state.js +185 -26
  24. package/lib/tools.js +150 -31
  25. package/lib/webui/standalone.css +28 -1
  26. package/lib/webui.js +25 -1
  27. package/lib/worker-pool.js +260 -26
  28. package/package.json +1 -1
  29. package/scripts/check-i18n.mjs +19 -0
  30. package/scripts/recall-bench.mjs +4 -4
  31. package/scripts/simulate-injection.mjs +3 -0
  32. package/tests/activity-wiring.test.mjs +52 -0
  33. package/tests/client-render.test.mjs +207 -0
  34. package/tests/consolidation-feed.test.mjs +26 -0
  35. package/tests/consolidation-fork.test.mjs +618 -33
  36. package/tests/consolidation-snapshot.test.mjs +2 -1
  37. package/tests/cross-library-recall.test.mjs +156 -0
  38. package/tests/cue.test.mjs +15 -2
  39. package/tests/hybrid-recall.test.mjs +488 -0
  40. package/tests/inbound.test.mjs +49 -4
  41. package/tests/inject-conflict.test.mjs +70 -9
  42. package/tests/inject-guide.test.mjs +13 -1
  43. package/tests/inject.test.mjs +10 -0
  44. package/tests/injection-budget.test.mjs +101 -0
  45. package/tests/injection-chain.test.mjs +37 -0
  46. package/tests/injection-rollback.test.mjs +172 -9
  47. package/tests/issue2-chain.test.mjs +169 -0
  48. package/tests/lexicon-inject.test.mjs +33 -5
  49. package/tests/lexicon-ui.test.mjs +99 -2
  50. package/tests/managed-memory.test.mjs +625 -1
  51. package/tests/media.test.mjs +1 -1
  52. package/tests/new-session-gate.test.mjs +280 -25
  53. package/tests/open-loop-date.test.mjs +11 -1
  54. package/tests/recall-intent.test.mjs +52 -3
  55. package/tests/simulate-injection.test.mjs +4 -4
  56. package/tests/snippet.test.mjs +33 -1
  57. package/tests/state.test.mjs +8 -3
  58. package/tests/tool-schema.test.mjs +52 -0
  59. package/tests/tools.test.mjs +394 -0
  60. package/tests/webui.test.mjs +16 -2
  61. package/tests/worker-lifecycle.test.mjs +419 -36
@@ -361,6 +361,61 @@ test('the sidebar context-scope card cannot be flex-shrunk and keeps a two-colum
361
361
  assert.match(src, /\.dshm-scope-form\{[^}]*grid-template-columns:repeat\(2,minmax\(0,1fr\)\)/, 'four scope fields must wrap into two readable columns')
362
362
  })
363
363
 
364
+ test('consolidation alerts keep identity separate from actions when expanded', async () => {
365
+ const ctx = fakeCtx()
366
+ globalThis.__dshMemuExports.apply(ctx)
367
+ const tab = registrations.filter((r) => r.slot === 'sidebar.right.pane.tab').pop()
368
+ const wrapped = tab.component({ ctx, t: (key) => key, sessionId: 'probe-session' })
369
+ const first = await renderPage(wrapped.type, wrapped.props, undefined, { remount: true })
370
+ for (const effect of first.effects) effect.fn()
371
+ await new Promise((resolve) => setTimeout(resolve, 0))
372
+ const sidebar = (await renderPage(wrapped.type, wrapped.props)).tree
373
+ let alerts
374
+ walkNodes(sidebar, (node) => {
375
+ if (node.type?.name === 'ConsolidationAlerts') { alerts = node.type; return false }
376
+ })
377
+ assert.ok(alerts)
378
+ const failure = { id: 'failure', sessionId: 's1', sessionTitle: 'A long conversation title', message: 'An unbroken failure message'.repeat(12), at: '2026-11-17T16:59:33Z' }
379
+ const success = { ...failure, id: 'success', message: 'done' }
380
+ const jumps = []
381
+ let cleared = 0
382
+ const props = { feed: { failures: [failure], successes: [success] }, t: (key) => key, onJump: row => jumps.push(row.id), onClear: () => cleared++ }
383
+ const nodes = (tree, className) => {
384
+ const found = []
385
+ walkNodes(tree, node => { if (node.props?.className === className) found.push(node) })
386
+ return found
387
+ }
388
+ let tree = (await renderPage(alerts, props, undefined, { remount: true })).tree
389
+ assert.equal(nodes(tree, 'dshm-consolidation-row').length, 1)
390
+ nodes(tree, 'dshm-consolidation-head')[0].props.onClick()
391
+ tree = (await renderPage(alerts, props)).tree
392
+ assert.equal(nodes(tree, 'dshm-consolidation-column').length, 2)
393
+ const rows = nodes(tree, 'dshm-consolidation-row')
394
+ assert.equal(rows.length, 2)
395
+ for (const row of rows) {
396
+ assert.equal(row.props.children[0].props.className, 'dshm-consolidation-identity')
397
+ assert.equal(row.props.children[1].props.className, 'dshm-consolidation-meta')
398
+ assert.equal(nodes(row, 'dshm-consolidation-label')[0].props.title, failure.sessionTitle)
399
+ assert.equal(nodes(row, 'dshm-consolidation-time').length, 1)
400
+ }
401
+ const buttons = []
402
+ walkNodes(tree, node => { if (node.type === 'button') buttons.push(node) })
403
+ buttons.find(node => node.props.title === 'consolidateJumpHint').props.onClick()
404
+ buttons.find(node => node.props.title === 'consolidateClearHint').props.onClick()
405
+ assert.deepEqual(jumps, ['failure'])
406
+ assert.equal(cleared, 1)
407
+ assert.ok(!treeText(tree).includes('consolidateStarted'))
408
+ })
409
+
410
+ test('consolidation alert columns wrap before their controls must be clipped', () => {
411
+ const src = fs.readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
412
+ assert.match(src, /\.dshm-consolidation-columns\{[^}]*grid-template-columns:repeat\(auto-fit,minmax\(min\(100%,240px\),1fr\)\)/)
413
+ assert.match(src, /\.dshm-consolidation-meta\{[^}]*flex-wrap:wrap/)
414
+ assert.match(src, /\.dshm-consolidation-column-head\{[^}]*flex-wrap:wrap/)
415
+ assert.match(src, /\.dshm-consolidation-label\{[^}]*text-overflow:ellipsis/)
416
+ assert.doesNotMatch(src, /\.dshm-consolidation-row\{[^}]*overflow:hidden/)
417
+ })
418
+
364
419
  test('the memory UI renders the read-only arousal/dominance/emotionSource line', () => {
365
420
  const src = fs.readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
366
421
  for (const key of ['arousalLabel', 'dominanceLabel', 'emotionSourceLabel', 'emotionSourceModel', 'emotionSourceSession', 'emotionSourceContent', 'emotionSourceUnknown']) {
@@ -490,6 +545,158 @@ test('the memory browser badges what a memory is allowed to say', async () => {
490
545
  }
491
546
  })
492
547
 
548
+ test('the memory browser decides pending reviews in place', async () => {
549
+ // 待复核条目在浏览页的复核池里就有接受/丢弃按钮,不必绕去全局页队列;
550
+ // 点击走的是同一个 resolveReview RPC,带本库 libraryId。
551
+ const rpcCalls = []
552
+ const ctx = fakeCtx({ rpcCalls })
553
+ const originalGetState = RPC_ANSWERS.getState
554
+ const originalSettingsState = RPC_ANSWERS.getSettingsState
555
+ const loaded = {
556
+ ...EMPTY_STATE,
557
+ libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 1 }],
558
+ }
559
+ RPC_ANSWERS.getState = loaded
560
+ RPC_ANSWERS.getSettingsState = loaded
561
+ RPC_ANSWERS.browseLibrary = {
562
+ source: 'engine',
563
+ files: [
564
+ { id: 'mem-pending', title: 'pending fact', content: 'awaiting a human', layer: 'long_term', status: 'pending_review', decay: 0.5, disclosure: 'can_tell', visibility: 'shared' },
565
+ { id: 'mem-active', title: 'settled fact', content: 'already true', layer: 'long_term', status: 'active', decay: 0.9, disclosure: 'can_tell', visibility: 'shared' },
566
+ ],
567
+ }
568
+ RPC_ANSWERS.resolveReview = { id: 'mem-pending', status: 'active', resolution: 'replace' }
569
+ RPC_ANSWERS.listReviews = { items: [] }
570
+ try {
571
+ globalThis.__dshMemuExports.apply(ctx)
572
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
573
+ const first = await renderPage(settings.component, { ctx, t: (key) => key }, undefined, { remount: true })
574
+ collectPageHook()
575
+ for (const effect of first.effects) effect.fn()
576
+ await new Promise((resolve) => setTimeout(resolve, 0))
577
+ await new Promise((resolve) => setTimeout(resolve, 0))
578
+
579
+ let tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 5)).tree
580
+ const picker = []
581
+ walkNodes(tree, (node) => {
582
+ const options = Array.isArray(node.props?.children) ? node.props.children : []
583
+ if (node.type === 'select' && options.some((option) => option?.props?.value === 'lib-1')) picker.push(node)
584
+ })
585
+ picker[0].props.onChange({ target: { value: 'lib-1' } })
586
+ tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 5)).tree
587
+ const reload = []
588
+ walkNodes(tree, (node) => {
589
+ if (typeof node.type === 'function' && node.props?.children === 'reload') reload.push(node)
590
+ })
591
+ reload[0].props.onClick()
592
+ await new Promise((resolve) => setTimeout(resolve, 0))
593
+ await new Promise((resolve) => setTimeout(resolve, 0))
594
+
595
+ // 切到复核池:页签文案是 poolReview + 计数。
596
+ tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 5)).tree
597
+ const reviewTab = []
598
+ walkNodes(tree, (node) => {
599
+ if (node.type === 'button' && String(node.props?.children || '').startsWith('poolReview')) reviewTab.push(node)
600
+ })
601
+ assert.equal(reviewTab.length, 1, 'the review pool tab did not render')
602
+ reviewTab[0].props.onClick()
603
+ tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 5)).tree
604
+ const buttons = []
605
+ walkNodes(tree, (node) => {
606
+ if (typeof node.type === 'function' && (node.props?.children === 'accept' || node.props?.children === 'reject')) buttons.push(node)
607
+ })
608
+ assert.equal(buttons.length, 2, 'the pending row offers exactly accept and reject')
609
+ const accept = buttons.find((node) => node.props.children === 'accept')
610
+ accept.props.onClick()
611
+ await new Promise((resolve) => setTimeout(resolve, 0))
612
+ await new Promise((resolve) => setTimeout(resolve, 0))
613
+ const resolved = rpcCalls.filter((call) => call.endpoint === 'resolveReview')
614
+ assert.equal(resolved.length, 1, 'accept fires exactly one resolveReview')
615
+ assert.equal(resolved[0].payload.id, 'mem-pending')
616
+ assert.equal(resolved[0].payload.libraryId, 'lib-1')
617
+ assert.equal(resolved[0].payload.action, 'accept')
618
+ } finally {
619
+ RPC_ANSWERS.getState = originalGetState
620
+ RPC_ANSWERS.getSettingsState = originalSettingsState
621
+ delete RPC_ANSWERS.browseLibrary
622
+ delete RPC_ANSWERS.resolveReview
623
+ delete RPC_ANSWERS.listReviews
624
+ }
625
+ })
626
+
627
+ test('the memory wall drawer decides pending reviews without leaving the wall', async () => {
628
+ const rpcCalls = []
629
+ const ctx = fakeCtx({ rpcCalls })
630
+ const originalGetState = RPC_ANSWERS.getState
631
+ const originalSettingsState = RPC_ANSWERS.getSettingsState
632
+ const loaded = {
633
+ ...EMPTY_STATE,
634
+ libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 1 }],
635
+ }
636
+ RPC_ANSWERS.getState = loaded
637
+ RPC_ANSWERS.getSettingsState = loaded
638
+ RPC_ANSWERS.browseWall = {
639
+ total: 1,
640
+ items: [{ id: 'mem-pending', libraryId: 'lib-1', libraryName: 'demo', title: 'pending fact', preview: 'awaiting a human', layer: 'long_term', status: 'pending_review', source: 'inferred', decay: 0.5, tags: [] }],
641
+ }
642
+ RPC_ANSWERS.getMemory = { id: 'mem-pending', libraryId: 'lib-1', entry: { title: 'pending fact', content: 'awaiting a human', status: 'pending_review', layer: 'long_term', disclosure: 'can_tell' }, attachments: [] }
643
+ RPC_ANSWERS.resolveReview = { id: 'mem-pending', status: 'active', resolution: 'replace' }
644
+ try {
645
+ globalThis.__dshMemuExports.apply(ctx)
646
+ const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
647
+ const first = await renderPage(settings.component, { ctx, t: (key) => key }, undefined, { remount: true })
648
+ collectPageHook()
649
+ for (const effect of first.effects) effect.fn()
650
+ await new Promise((resolve) => setTimeout(resolve, 0))
651
+ await new Promise((resolve) => setTimeout(resolve, 0))
652
+
653
+ let tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 9)).tree
654
+ // 墙的数据加载在 MemoryWallPanel 自己的 effect 里:展开子组件登记 effect 再执行。
655
+ treeText(tree)
656
+ for (const effect of effects) effect.fn()
657
+ await new Promise((resolve) => setTimeout(resolve, 0))
658
+ await new Promise((resolve) => setTimeout(resolve, 0))
659
+ tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 9)).tree
660
+ // 墙默认看活跃池;待复核条目在复核池,先切池再找卡片。
661
+ const poolTab = []
662
+ walkNodes(tree, (node) => {
663
+ if (node.type === 'button' && String(node.props?.children || '').startsWith('poolReview')) poolTab.push(node)
664
+ })
665
+ assert.equal(poolTab.length, 1, 'the wall review pool tab did not render')
666
+ poolTab[0].props.onClick()
667
+ tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 9)).tree
668
+ const cards = []
669
+ walkNodes(tree, (node) => {
670
+ if (node.type === 'button' && String(node.props?.className || '').includes('dshm-wall-item')) cards.push(node)
671
+ })
672
+ assert.equal(cards.length, 1, 'the pending card did not render on the wall')
673
+ cards[0].props.onClick()
674
+ await new Promise((resolve) => setTimeout(resolve, 0))
675
+ await new Promise((resolve) => setTimeout(resolve, 0))
676
+
677
+ tree = (await renderPage(settings.component, { ctx, t: (key) => key }, 9)).tree
678
+ const buttons = []
679
+ walkNodes(tree, (node) => {
680
+ if (typeof node.type === 'function' && (node.props?.children === 'accept' || node.props?.children === 'reject')) buttons.push(node)
681
+ })
682
+ assert.equal(buttons.length, 2, 'the drawer offers accept and reject for a pending review')
683
+ buttons.find((node) => node.props.children === 'reject').props.onClick()
684
+ await new Promise((resolve) => setTimeout(resolve, 0))
685
+ await new Promise((resolve) => setTimeout(resolve, 0))
686
+ const resolved = rpcCalls.filter((call) => call.endpoint === 'resolveReview')
687
+ assert.equal(resolved.length, 1, 'reject fires exactly one resolveReview')
688
+ assert.equal(resolved[0].payload.id, 'mem-pending')
689
+ assert.equal(resolved[0].payload.libraryId, 'lib-1')
690
+ assert.equal(resolved[0].payload.action, 'reject')
691
+ } finally {
692
+ RPC_ANSWERS.getState = originalGetState
693
+ RPC_ANSWERS.getSettingsState = originalSettingsState
694
+ delete RPC_ANSWERS.browseWall
695
+ delete RPC_ANSWERS.getMemory
696
+ delete RPC_ANSWERS.resolveReview
697
+ }
698
+ })
699
+
493
700
  test('the browse search box filters the loaded library in place', async () => {
494
701
  // 搜索是纯前端的:它只过滤已经拉回来的那一页,不新发 RPC。库一切换就清空,
495
702
  // 否则上一个库的关键词会把当前库筛成「空库」。
@@ -72,6 +72,32 @@ test('getActivityLog decorates consolidation rows with session title and library
72
72
  assert.equal(row.libraryName, '第二个工作区')
73
73
  })
74
74
 
75
+ test('the feed exposes bounded metering without pretending missing cached usage is zero', async () => {
76
+ resetActivityLogCache()
77
+ clearEvents()
78
+ record({ kind: 'consolidate', ok: true, message: 'metered worker', detail: { runner: 'worker', measurement: {
79
+ schemaVersion: 2, measurementVersion: 2,
80
+ packet: { kind: 'increment', inputChars: 120, estimatedTokens: 40, text: 'private packet must not escape' },
81
+ dispatched: { inputChars: 120, estimatedTokens: 40, followups: 1 },
82
+ observed: { outputTextChars: 20, toolArgumentsChars: 10, toolResultsChars: 0, reasoningChars: null },
83
+ usage: { inputTokens: 10, cacheReadTokens: 20, cacheWriteTokens: 0, outputTokens: 5, reasoningTokens: null, requests: 1, source: 'assistant/message.data.usage' },
84
+ } } })
85
+ let feed = await dispatch(ctx, 'getConsolidationFeed')
86
+ const result = feed.successes[0]
87
+ assert.equal(result.runner, 'worker')
88
+ assert.equal(result.measurement.packet.text, undefined)
89
+ assert.equal(result.measurement.packet.inputChars, 120)
90
+ assert.equal(result.measurement.usage.totalInputTokens, 30)
91
+ assert.equal(result.measurement.usage.reasoningTokens, null)
92
+ assert.equal(result.measurement.dispatched.wrapupChars, null)
93
+ clearEvents()
94
+ record({ kind: 'consolidate', ok: true, message: 'partial usage', detail: { runner: 'fork', measurement: { schemaVersion: 2, usage: { inputTokens: 10 }, packet: null } } })
95
+ feed = await dispatch(ctx, 'getConsolidationFeed')
96
+ assert.equal(feed.successes[0].measurement.usage.cacheReadTokens, null)
97
+ assert.equal(feed.successes[0].measurement.usage.totalInputTokens, null)
98
+ assert.equal(feed.successes[0].measurement.usage.source, 'unavailable')
99
+ })
100
+
75
101
  test('clearConsolidationFailures deletes only failed consolidate rows, everything else stays', async () => {
76
102
  const library = state.createLibrary({ cwd: path.join(home, 'feed-clear'), name: '清除测试区' })
77
103
  resetActivityLogCache()