dsh-memu-memory 1.2.1 → 1.2.3

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 (105) hide show
  1. package/AGENTS.md +3 -1
  2. package/README.md +23 -8
  3. package/README.zh.md +16 -6
  4. package/docs/client-conventions.md +1 -0
  5. package/docs/contributing.md +18 -4
  6. package/docs/emotion-model-spec.md +2 -2
  7. package/docs/env-and-commands.md +20 -0
  8. package/docs/host-api.md +22 -1
  9. package/docs/memory-semantics.md +30 -2
  10. package/docs/troubleshooting.md +76 -5
  11. package/lib/activity-log.js +1 -1
  12. package/lib/backup.js +24 -2
  13. package/lib/binding-diagnostics.js +2 -2
  14. package/lib/client.js +1511 -153
  15. package/lib/consolidation-worker.js +30 -8
  16. package/lib/curator-evidence.js +131 -0
  17. package/lib/curator-policy.js +81 -0
  18. package/lib/curator.js +1252 -91
  19. package/lib/cycle.js +12 -1
  20. package/lib/embedding-download.js +39 -4
  21. package/lib/engine.js +6 -3
  22. package/lib/freshness.js +97 -0
  23. package/lib/global-graph.js +282 -0
  24. package/lib/graph.js +295 -11
  25. package/lib/inbound.js +19 -0
  26. package/lib/inject.js +396 -25
  27. package/lib/lexicon.js +1115 -0
  28. package/lib/local-vector-service.js +8 -6
  29. package/lib/managed-runtime.js +33 -2
  30. package/lib/memory.js +365 -34
  31. package/lib/memu.js +2 -2
  32. package/lib/migrate.js +83 -2
  33. package/lib/private-links.js +587 -0
  34. package/lib/private.js +32 -3
  35. package/lib/prompts/global-curator.md +76 -19
  36. package/lib/prompts/private-consolidation.coding.md +4 -1
  37. package/lib/prompts/private-consolidation.md +3 -1
  38. package/lib/prompts/private-consolidation.mixed.md +3 -1
  39. package/lib/prompts/private-consolidation.rp.md +3 -1
  40. package/lib/prompts.js +1 -1
  41. package/lib/rpc.js +589 -10
  42. package/lib/salient-wake.js +402 -0
  43. package/lib/state.js +95 -1
  44. package/lib/text-retrieval.js +661 -0
  45. package/lib/text-similarity.js +36 -18
  46. package/lib/tools.js +168 -10
  47. package/lib/webui/standalone.css +17 -0
  48. package/lib/webui/standalone.js +2 -0
  49. package/package.json +1 -1
  50. package/scripts/acceptance-local.mjs +8 -5
  51. package/scripts/curator-pair-calibrate.mjs +259 -0
  52. package/scripts/drive-session.mjs +853 -0
  53. package/scripts/lexicon-calibrate.mjs +230 -0
  54. package/scripts/lexicon-dedupe.mjs +318 -0
  55. package/scripts/mock-llm.mjs +903 -0
  56. package/tests/absorb-review.test.mjs +353 -0
  57. package/tests/appendix-b2.test.mjs +2 -2
  58. package/tests/client-export.test.mjs +520 -0
  59. package/tests/client-render.test.mjs +32 -4
  60. package/tests/consolidation-fork.test.mjs +14 -12
  61. package/tests/consolidation-snapshot.test.mjs +39 -0
  62. package/tests/curator-absorb.test.mjs +443 -0
  63. package/tests/curator-calibrate.test.mjs +173 -0
  64. package/tests/curator-clusters.test.mjs +281 -0
  65. package/tests/curator-commit.test.mjs +52 -5
  66. package/tests/curator-evidence.test.mjs +102 -0
  67. package/tests/curator-link.test.mjs +316 -0
  68. package/tests/curator-pairing.test.mjs +252 -0
  69. package/tests/curator-probe.test.mjs +15 -6
  70. package/tests/curator-review-mode.test.mjs +314 -0
  71. package/tests/disclosure.test.mjs +2 -1
  72. package/tests/entity-merge.test.mjs +261 -0
  73. package/tests/fixtures/curator-pairs/labeled.v1.jsonl +90 -0
  74. package/tests/fixtures/lexicon-stub-hooks.mjs +15 -0
  75. package/tests/fixtures/lexicon-stub.mjs +284 -0
  76. package/tests/fixtures/mock-llm/reply.txt +1 -0
  77. package/tests/freshness.test.mjs +140 -0
  78. package/tests/graph-cascade.test.mjs +35 -2
  79. package/tests/graph.test.mjs +96 -0
  80. package/tests/help-page.test.mjs +415 -0
  81. package/tests/inbound.test.mjs +6 -3
  82. package/tests/inject-guide.test.mjs +28 -0
  83. package/tests/inject.test.mjs +157 -5
  84. package/tests/injection-chain.test.mjs +176 -0
  85. package/tests/lexicon-calibrate.test.mjs +48 -0
  86. package/tests/lexicon-dedupe.test.mjs +171 -0
  87. package/tests/lexicon-frequency.test.mjs +179 -0
  88. package/tests/lexicon-inject.test.mjs +410 -0
  89. package/tests/lexicon-perf.test.mjs +436 -0
  90. package/tests/lexicon-ui.test.mjs +547 -0
  91. package/tests/lexicon.test.mjs +922 -0
  92. package/tests/managed-runtime.test.mjs +32 -0
  93. package/tests/mock-llm.test.mjs +225 -0
  94. package/tests/open-loop-date.test.mjs +406 -0
  95. package/tests/private-links.test.mjs +445 -0
  96. package/tests/prompts.test.mjs +35 -0
  97. package/tests/recall-dedup.test.mjs +33 -4
  98. package/tests/salient-wake.test.mjs +362 -0
  99. package/tests/settings-plumbing.test.mjs +76 -0
  100. package/tests/sidebar.test.mjs +5 -1
  101. package/tests/stubs/dsh-schedule.js +105 -0
  102. package/tests/tool-schema.test.mjs +1 -1
  103. package/tests/tools.test.mjs +112 -3
  104. package/tests/webui-auth.test.mjs +352 -2
  105. package/tests/webui.test.mjs +188 -0
package/lib/backup.js CHANGED
@@ -59,6 +59,7 @@ const leaseFile = () => path.join(backupsDir(), '.leases.json')
59
59
  const lockAnchor = () => path.join(backupsDir(), '.backup')
60
60
  const stateFile = () => path.join(dataDir(), 'state.json')
61
61
  const globalDbFile = () => path.join(dataDir(), 'global.sqlite3')
62
+ const lexiconRoot = () => path.join(dataDir(), 'lexicon')
62
63
  const vectorActiveFile = () => path.join(indexDir(), 'vector-active.json')
63
64
  const engineCurrentFile = () => path.join(dataDir(), 'engine', 'current.json')
64
65
 
@@ -505,8 +506,9 @@ function engineSummary() {
505
506
 
506
507
  /**
507
508
  * Copies every store a restore needs: plugin state, the global index and the
508
- * per-library index files, the active vector profile journal, prompt overrides
509
- * and their manifest, attachment references, and every MemU SQLite database.
509
+ * per-library index files, the per-library lexicon files, the active vector
510
+ * profile journal, prompt overrides and their manifest, attachment references,
511
+ * and every MemU SQLite database.
510
512
  * Deliberately absent: engine/, downloads/, logs/, tmp/ (large and
511
513
  * re-downloadable) and any key material - the manifest carries identity, never
512
514
  * a credential.
@@ -519,9 +521,21 @@ function writeStores(staging, exec) {
519
521
  ensureDir(path.join(staging, 'index'))
520
522
  ensureDir(path.join(staging, 'prompts'))
521
523
  copyRegular(stateFile(), path.join(staging, 'state.json'))
524
+ // Consolidation ledger: per-session ranges/operations. It now participates in
525
+ // backup/restore so a restored install does not re-fork work it already did.
526
+ copyRegular(path.join(dataDir(), 'consolidation.json'), path.join(staging, 'consolidation.json'))
522
527
  for (const name of readdirSafe(indexDir())) {
523
528
  if (name.endsWith('.json')) copyRegular(path.join(indexDir(), name), path.join(staging, 'index', name))
524
529
  }
530
+ // 词典:data/lexicon/<libraryId>.json 与索引同权进备份清单。只收安全 id
531
+ // 命名的 JSON(restore 侧 allowlist 用同一规则拒绝越界);目录还不存在(这个
532
+ // 数据根从未写过词典)就是空集。
533
+ ensureDir(path.join(staging, 'lexicon'))
534
+ for (const name of readdirSafe(lexiconRoot())) {
535
+ if (!name.endsWith('.json')) continue
536
+ if (!isSafeId(name.slice(0, -'.json'.length))) continue
537
+ copyRegular(path.join(lexiconRoot(), name), path.join(staging, 'lexicon', name))
538
+ }
525
539
  copyRegular(path.join(dataDir(), 'prompts', 'manifest.json'), path.join(staging, 'prompts', 'manifest.json'))
526
540
  copyTree(path.join(dataDir(), 'prompts'), path.join(staging, 'prompts'))
527
541
  copyTree(path.join(dataDir(), 'attachments'), path.join(staging, 'attachments'))
@@ -903,6 +917,7 @@ function liveTargetFor(rel) {
903
917
  const head = parts[0]
904
918
  if (parts.length === 1) {
905
919
  if (head === 'state.json') return stateFile()
920
+ if (head === 'consolidation.json') return path.join(dataDir(), 'consolidation.json')
906
921
  if (head === 'global.sqlite3') return globalDbFile()
907
922
  if (head === 'global.sqlite3-wal') return globalDbFile() + '-wal'
908
923
  if (head === 'global.sqlite3-shm') return globalDbFile() + '-shm'
@@ -910,6 +925,13 @@ function liveTargetFor(rel) {
910
925
  if ((head === 'index' || head === 'libraries') && parts.length === 2) {
911
926
  return path.join(head === 'index' ? indexDir() : librariesDir(), parts[1])
912
927
  }
928
+ if (head === 'lexicon' && parts.length === 2) {
929
+ // 词典只接受 <libraryId>.json:isSafeId 挡掉 ..、路径分隔符和任意文件名,
930
+ // 与 writeStores 收录时的同一规则对称。
931
+ const id = parts[1].endsWith('.json') ? parts[1].slice(0, -'.json'.length) : ''
932
+ if (!id || !isSafeId(id)) throw new Error('backup contains an entry this version cannot restore: ' + rel)
933
+ return path.join(lexiconRoot(), parts[1])
934
+ }
913
935
  if ((head === 'prompts' || head === 'attachments') && parts.length >= 2) {
914
936
  return path.join(dataDir(), parts.join(path.sep))
915
937
  }
@@ -55,8 +55,8 @@ export const RUNTIME_STATE = Object.freeze([
55
55
  { layer: 'temporary-map', file: 'lib/inbound.js:14', name: 'sessions', keyedBy: 'sessionId', clearedBy: 'session/disposed (releaseInboundSession)' },
56
56
  { layer: 'temporary-map', file: 'lib/media.js:19', name: 'captures', keyedBy: 'sessionId', clearedBy: 'capture settle' },
57
57
  { layer: 'temporary-map', file: 'lib/private.js:347', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
58
- { layer: 'temporary-map', file: 'lib/curator.js:13', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
59
- { layer: 'cache', file: 'lib/state.js:967', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
58
+ { layer: 'temporary-map', file: 'lib/curator.js:50', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
59
+ { layer: 'cache', file: 'lib/state.js:1061', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
60
60
  { layer: 'cache', file: 'lib/paths.js:52', name: 'readFailures', keyedBy: 'absolute file', clearedBy: 'a later successful read' },
61
61
  ])
62
62