dsh-memu-memory 1.2.8 → 1.2.9

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 (78) hide show
  1. package/CHANGELOG.md +472 -0
  2. package/README.md +1 -1
  3. package/README.zh.md +1 -1
  4. package/lib/backup.js +154 -25
  5. package/lib/binding-diagnostics.js +1 -2
  6. package/lib/budget.js +0 -9
  7. package/lib/client.js +221 -128
  8. package/lib/commitment.js +3 -3
  9. package/lib/consolidation-ledger.js +5 -2
  10. package/lib/curator-policy.js +23 -0
  11. package/lib/cycle.js +8 -4
  12. package/lib/embedding-download.js +168 -28
  13. package/lib/embedding-runtime.js +76 -17
  14. package/lib/engine.js +0 -6
  15. package/lib/freshness.js +2 -2
  16. package/lib/graph.js +139 -11
  17. package/lib/index.js +71 -20
  18. package/lib/inject.js +50 -7
  19. package/lib/lexicon.js +61 -16
  20. package/lib/local-vector-service.js +21 -1
  21. package/lib/media.js +49 -12
  22. package/lib/memory.js +662 -116
  23. package/lib/paths.js +0 -7
  24. package/lib/preset-scope.js +6 -1
  25. package/lib/private.js +45 -7
  26. package/lib/prompts.js +0 -7
  27. package/lib/rpc.js +95 -17
  28. package/lib/snippet.js +18 -2
  29. package/lib/state.js +109 -30
  30. package/lib/stats.js +2 -2
  31. package/lib/temporal.js +19 -0
  32. package/lib/text-retrieval.js +120 -44
  33. package/lib/text-similarity.js +205 -24
  34. package/lib/tokenizer-v2.js +0 -24
  35. package/lib/vector-migration.js +15 -0
  36. package/lib/vector-profile.js +81 -8
  37. package/lib/visibility.js +0 -4
  38. package/lib/webui/standalone.css +17 -22
  39. package/lib/webui/standalone.js +27 -9
  40. package/lib/webui.js +4 -4
  41. package/package.json +3 -2
  42. package/scripts/acceptance-local.mjs +2 -2
  43. package/scripts/check-all.mjs +3 -1
  44. package/scripts/check-i18n.mjs +35 -1
  45. package/scripts/migrate-visibility.mjs +3 -3
  46. package/scripts/prune-sessions.mjs +34 -0
  47. package/scripts/prune-vectors.mjs +24 -0
  48. package/tests/appendix-b.test.mjs +5 -4
  49. package/tests/audit-batch3.test.mjs +247 -0
  50. package/tests/audit-regression.test.mjs +2 -2
  51. package/tests/backup.test.mjs +83 -83
  52. package/tests/browser.test.mjs +6 -1
  53. package/tests/client-render.test.mjs +2 -2
  54. package/tests/curator-clusters.test.mjs +18 -0
  55. package/tests/curator-pairing.test.mjs +59 -16
  56. package/tests/dynamic-rrf.test.mjs +22 -19
  57. package/tests/dynamic-threshold.test.mjs +52 -0
  58. package/tests/fact-version.test.mjs +18 -0
  59. package/tests/fixtures/tokenizer-cases.mjs +27 -0
  60. package/tests/graph-cascade.test.mjs +29 -0
  61. package/tests/graph.test.mjs +45 -0
  62. package/tests/inject-conflict.test.mjs +18 -0
  63. package/tests/lexical-bm25.test.mjs +171 -0
  64. package/tests/lexicon-frequency.test.mjs +16 -0
  65. package/tests/lexicon-inject.test.mjs +21 -0
  66. package/tests/lexicon-perf.test.mjs +37 -9
  67. package/tests/lexicon-scope.test.mjs +2 -2
  68. package/tests/lexicon-ui.test.mjs +1 -1
  69. package/tests/managed-memory.test.mjs +19 -0
  70. package/tests/ops-hardening.test.mjs +209 -0
  71. package/tests/package-shipping.test.mjs +4 -0
  72. package/tests/recall-intent.test.mjs +23 -0
  73. package/tests/slot-similarity.test.mjs +153 -0
  74. package/tests/state-gc.test.mjs +34 -0
  75. package/tests/state.test.mjs +2 -2
  76. package/tests/tokenizer-v2.test.mjs +1 -1
  77. package/tests/vector-gc.test.mjs +37 -0
  78. package/tests/webui.test.mjs +27 -0
@@ -172,6 +172,11 @@ export function createVectorMigrator(options = {}) {
172
172
  listFiles: configured.listFiles ?? configured.list,
173
173
  retrieve: typeof configured.retrieve === 'function' ? configured.retrieve : null,
174
174
  smoke: typeof configured.smoke === 'function' ? configured.smoke : null,
175
+ // Optional: drop the index-side `vectorPending` marker for ids that this rebuild
176
+ // has just proven present in the shadow. Without it the marker was write-only —
177
+ // nothing ever cleared it after a successful migration, so a fully migrated
178
+ // library kept advertising itself as "not in the vector store yet".
179
+ clearVectorPending: typeof configured.clearVectorPending === 'function' ? configured.clearVectorPending : null,
175
180
  }
176
181
  for (const name of REQUIRED_DEPS) {
177
182
  if (typeof impl[name] !== 'function') throw new TypeError('createVectorMigrator requires a ' + name + '(… ) dependency')
@@ -527,6 +532,16 @@ export function createVectorMigrator(options = {}) {
527
532
  const verifiedPresent = await presentIds(scope, profile, generation)
528
533
  if (verifiedPresent.size !== known.size || [...known].some(id => !verifiedPresent.has(id))) {
529
534
  report.failed.push({ libraryId: scope.key, code: 'VECTOR_COVERAGE_FAILED', message: 'shadow membership differs from eligible index snapshot' })
535
+ } else if (impl.clearVectorPending) {
536
+ // Coverage passed: every admitted entry is provably in this generation's
537
+ // shadow, so "write me into the vector store later" is finished for all of
538
+ // them. Fail-open — a stale flag costs a little wasted work next rebuild, it
539
+ // must never turn a successful migration into a failed one.
540
+ try {
541
+ impl.clearVectorPending({ libraryId: scope.libraryId, ids: [...known], generation })
542
+ } catch (error) {
543
+ log('clear vectorPending failed for ' + scope.key + ': ' + (error?.message || error))
544
+ }
530
545
  }
531
546
  bucket.snapshot = { digest: before.scopes[index].digest, items: items.length, at: before.at }
532
547
  report.libraries[scope.key] = { items: items.length, present: present.size, digest: before.scopes[index].digest }
@@ -130,13 +130,6 @@ export function manifestDigestAccepted(stored, manifest) {
130
130
  /** 直接复用 embedding-catalog 的指纹协议(任何改变向量空间的字段都进指纹,§14.8)。 */
131
131
  export { profileFingerprint }
132
132
 
133
- export function profileShortFingerprint(profileOrEntry) {
134
- const fingerprint = typeof profileOrEntry === 'string'
135
- ? profileOrEntry
136
- : (profileOrEntry?.fingerprint || profileFingerprint(profileOrEntry))
137
- return String(fingerprint).slice(0, 8)
138
- }
139
-
140
133
  // ---------------------------------------------------------------- catalog 注入点
141
134
 
142
135
  // 默认只认 embedding-catalog.js 的目录。测试(以及将来多目录场景)可以换一个解析器:
@@ -989,4 +982,84 @@ export const activeVectorState = vectorState
989
982
  export const memuDbFor = dbPathFor
990
983
  export const memuGlobalDbFor = () => dbPathFor(null)
991
984
  export const captureVectorGeneration = captureGeneration
992
- export const assertVectorGeneration = assertGeneration
985
+ export const assertVectorGeneration = assertGeneration
986
+ // ---------------------------------------------------------------- P2-5 vector GC
987
+ //
988
+ // Generation files are safe to collect only when they are (a) not referenced by
989
+ // the active/pending manifest, (b) older than the active generation by the
990
+ // configured keep count, and (c) older than a retention window. The pure
991
+ // candidate filter is exported so the script and tests share exactly one rule.
992
+ const VECTOR_GC_DAY_MS = 86_400_000
993
+
994
+ export function vectorGcCandidates({
995
+ files = [], activeGeneration = 0, keepGenerations = 2, olderThanDays = 7,
996
+ now = Date.now(), keepPaths = [],
997
+ } = {}) {
998
+ const keepGenerationsCount = Math.max(1, Number(keepGenerations) || 2)
999
+ const minKeep = Math.max(0, (Number(activeGeneration) || 0) - (keepGenerationsCount - 1))
1000
+ const cutoff = Number(now) - Math.max(0, Number(olderThanDays) || 0) * VECTOR_GC_DAY_MS
1001
+ const keep = new Set((keepPaths || []).map((file) => path.resolve(String(file))))
1002
+ return (files || []).filter((item) => {
1003
+ const generation = Number(item?.generation)
1004
+ if (!Number.isSafeInteger(generation) || generation < 1) return false
1005
+ if (generation >= minKeep) return false
1006
+ if (keep.has(path.resolve(String(item.file)))) return false
1007
+ return Number(item.mtimeMs) < cutoff
1008
+ })
1009
+ }
1010
+
1011
+ export function listVectorArtifacts() {
1012
+ const state = readVectorState({ tolerateMissing: true }).state
1013
+ const keepPaths = []
1014
+ const collect = (manifest) => {
1015
+ if (!manifest?.databases) return
1016
+ const global = manifest.databases.global
1017
+ if (global?.path) keepPaths.push(resolveVectorPath(global.path))
1018
+ for (const entry of Object.values(manifest.databases.libraries || {})) {
1019
+ if (entry?.path) keepPaths.push(resolveVectorPath(entry.path))
1020
+ }
1021
+ }
1022
+ collect(state?.active)
1023
+ collect(state?.pending?.databases ? { databases: state.pending.databases } : null)
1024
+ const files = []
1025
+ for (const dir of [librariesDir(), indexDir()]) {
1026
+ let names = []
1027
+ try { names = fs.readdirSync(dir) } catch { continue }
1028
+ for (const name of names) {
1029
+ const match = /\.g(\d+)\.(?:sqlite3|json)$/.exec(name)
1030
+ if (!match) continue
1031
+ if (!name.endsWith('.sqlite3') && !name.startsWith('vector-ledger.')) continue
1032
+ const file = path.join(dir, name)
1033
+ let info
1034
+ try { info = fs.statSync(file) } catch { continue }
1035
+ files.push({ file, generation: Number(match[1]), bytes: info.size, mtimeMs: info.mtimeMs })
1036
+ }
1037
+ }
1038
+ return { activeGeneration: state?.active?.generation ?? 0, keepPaths, files }
1039
+ }
1040
+
1041
+ export function pruneVectorArtifacts({ apply = false, keepGenerations = 2, olderThanDays = 7, now = Date.now() } = {}) {
1042
+ const info = listVectorArtifacts()
1043
+ const candidates = vectorGcCandidates({
1044
+ files: info.files,
1045
+ activeGeneration: info.activeGeneration,
1046
+ keepGenerations,
1047
+ olderThanDays,
1048
+ now,
1049
+ keepPaths: info.keepPaths,
1050
+ })
1051
+ const removed = []
1052
+ if (apply) {
1053
+ for (const item of candidates) {
1054
+ try { fs.unlinkSync(item.file); removed.push(item.file) } catch {}
1055
+ }
1056
+ }
1057
+ return {
1058
+ dryRun: apply !== true,
1059
+ activeGeneration: info.activeGeneration,
1060
+ keepGenerations,
1061
+ olderThanDays,
1062
+ candidates: candidates.map((item) => ({ file: item.file, generation: item.generation, bytes: item.bytes })),
1063
+ removed,
1064
+ }
1065
+ }
package/lib/visibility.js CHANGED
@@ -16,10 +16,6 @@
16
16
  export const STORED_VISIBILITIES = ['shared', 'secret']
17
17
  export const LEGACY_SESSION = 'session'
18
18
 
19
- export function normalizeVisibility(value) {
20
- return value === LEGACY_SESSION ? 'shared' : value
21
- }
22
-
23
19
  export function isLegacySession(entry) {
24
20
  return entry?.visibility === LEGACY_SESSION
25
21
  }
@@ -455,9 +455,6 @@ body[data-scrolled="true"] .topbar {
455
455
  #root {
456
456
  min-height: 50vh;
457
457
  }
458
- .boot-failed #root::before {
459
- content: "";
460
- }
461
458
 
462
459
  /* ── footer ────────────────────────────────────────────────────────────── */
463
460
  .foot {
@@ -619,11 +616,9 @@ html[data-standalone] .dshm-root {
619
616
  padding: 0;
620
617
  min-height: 0;
621
618
  animation: none;
622
- /* The component uses container queries inside the host pane. On a full page
623
- `contain: layout` would also make it the containing block for the detail
624
- drawer's fixed overlay, pinning it under the topbar; the media queries above
625
- already cover the narrow layout. */
626
- container-type: normal;
619
+ /* Keep the query container alive in the standalone shell too, so UI_CSS's
620
+ @container rules drive the narrow layout in both shells (see UI_CSS). */
621
+ container-type: inline-size;
627
622
  --dshm-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
628
623
  }
629
624
  html[data-standalone] .dshm-shell {
@@ -651,7 +646,7 @@ html[data-standalone] .dshm-nav {
651
646
  z-index: 20;
652
647
  }
653
648
  html[data-standalone] .dshm-nav::before {
654
- content: "MEMORY STUDIO";
649
+ content: var(--dshm-studio-label, "MEMORY STUDIO");
655
650
  display: block;
656
651
  padding: 4px 12px 10px;
657
652
  font-size: 9px;
@@ -922,8 +917,8 @@ html[data-standalone] .dshm-error {
922
917
  margin: 2px 0;
923
918
  padding: 8px 12px;
924
919
  border-radius: 11px;
925
- border: 1px solid color-mix(in srgb, var(--dshm-error, #b43e45) 30%, transparent);
926
- background: color-mix(in srgb, var(--dshm-error, #b43e45) 10%, transparent);
920
+ border: 1px solid color-mix(in srgb, var(--dsw-alias-state-error-primary, #b43e45) 30%, transparent);
921
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary, #b43e45) 10%, transparent);
927
922
  font-size: 12.5px;
928
923
  }
929
924
 
@@ -960,15 +955,19 @@ html[data-standalone] .dshm-wall-grid {
960
955
  }
961
956
  html[data-standalone] .dshm-wall-item {
962
957
  min-height: 236px;
958
+ /* Skip layout/paint for rows outside the viewport: a fullscreen wall can hold
959
+ 300 cards, and rendering all of them is what starves the WebView2 compositor. */
960
+ content-visibility: auto;
961
+ contain-intrinsic-size: auto 236px;
963
962
  padding: 18px;
964
963
  border-radius: 18px;
965
964
  border: 1px solid var(--dshm-line);
965
+ /* No backdrop-filter here. A fullscreen wall puts dozens of blurred cards on
966
+ screen at once; the pointer spotlight repaints their backdrop every frame
967
+ and WebView2 starts dropping compositor tiles (cards flash, then vanish).
968
+ The gradients below already carry the depth. */
966
969
  background:
967
- linear-gradient(180deg,
968
- color-mix(in srgb, var(--dshm-panel-strong) 92%, transparent),
969
- color-mix(in srgb, var(--dshm-panel) 82%, transparent));
970
- -webkit-backdrop-filter: blur(14px);
971
- backdrop-filter: blur(14px);
970
+ linear-gradient(180deg, var(--dshm-panel-strong), var(--dshm-panel));
972
971
  box-shadow: 0 18px 36px -32px rgba(10, 28, 23, .5);
973
972
  transition: transform .28s cubic-bezier(.22, 1, .36, 1), box-shadow .28s ease,
974
973
  border-color .28s ease;
@@ -998,9 +997,7 @@ html[data-standalone] .dshm-wall-cover-count {
998
997
  bottom: 10px;
999
998
  font-size: 10.5px;
1000
999
  letter-spacing: .01em;
1001
- background: rgba(10, 16, 32, .62);
1002
- -webkit-backdrop-filter: blur(6px);
1003
- backdrop-filter: blur(6px);
1000
+ background: rgba(10, 16, 32, .72);
1004
1001
  }
1005
1002
  html[data-standalone] .dshm-wall-meta {
1006
1003
  font-size: 11px;
@@ -1036,7 +1033,6 @@ html[data-standalone] .dshm-drawer {
1036
1033
  border-left-color: var(--dshm-line);
1037
1034
  box-shadow: -30px 0 80px -40px rgba(0, 0, 0, .55);
1038
1035
  }
1039
- html[data-standalone] .dshm-drawer .dshm-input,
1040
1036
  html[data-standalone] .dshm-drawer input,
1041
1037
  html[data-standalone] .dshm-drawer textarea,
1042
1038
  html[data-standalone] .dshm-drawer select {
@@ -1104,7 +1100,6 @@ html[data-standalone] .dshm-wall-graph {
1104
1100
 
1105
1101
  /* ── responsive ────────────────────────────────────────────────────────── */
1106
1102
  @media (max-width: 760px) {
1107
- html[data-standalone] .dshm-shell { grid-template-columns: minmax(0, 1fr); gap: 16px; }
1108
1103
  html[data-standalone] .dshm-nav { position: static; }
1109
1104
  html[data-standalone] .dshm-nav-list { flex-direction: row; flex-wrap: wrap; }
1110
1105
  html[data-standalone] .dshm-nav-ind { display: none; }
@@ -1112,7 +1107,7 @@ html[data-standalone] .dshm-wall-graph {
1112
1107
  }
1113
1108
  @media (max-width: 1120px) {
1114
1109
  :root { --dshm-rail: 186px; --dshm-gap: 24px; }
1115
- .stage { padding: 22px 22px 48px; }
1110
+ .stage { padding: 22px 22px 48px calc(var(--dshm-rail) + 38px); }
1116
1111
  }
1117
1112
  @media (max-width: 900px) {
1118
1113
  .topbar { top: 8px; width: calc(100% - 16px); margin-top: 8px; padding: 10px 12px; }
@@ -10,6 +10,7 @@
10
10
  backToDsh: '返回 DSH', close: '关闭', back: '返回',
11
11
  footer: '与 DSH 共用同一份记忆 · 本地优先', opening: '正在打开记忆工作室…',
12
12
  bootFailed: '打不开记忆工作台', reload: '重新加载', unknown: '未知错误',
13
+ studioLabel: '记忆工作室',
13
14
  },
14
15
  en: {
15
16
  skip: 'Skip to content', brand: 'MemU Memory', memories: 'Memories', sync: 'Local memory',
@@ -17,18 +18,22 @@
17
18
  backToDsh: 'Back to DSH', close: 'Close', back: 'Back',
18
19
  footer: 'Shares the same memory as DSH · local-first', opening: 'Opening the memory studio…',
19
20
  bootFailed: 'The memory studio failed to open', reload: 'Reload', unknown: 'Unknown error',
21
+ studioLabel: 'MEMORY STUDIO',
20
22
  },
21
23
  }
24
+ // 页序只留这一份 slug 清单;PAGE_NAMES 的键由 check-i18n.mjs 与
25
+ // client.js 的 SETTINGS_PAGES 对齐校验,避免第三份清单漂移。
26
+ var SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'logs', 'lexicon', 'help']
22
27
  var PAGE_NAMES = {
23
28
  zh: {
24
- engine: '引擎与连接', settings: '记忆设置', folders: '文件夹', libraries: '记忆库',
29
+ engine: '引擎与连接', connection: '连接与向量', settings: '记忆设置', folders: '文件夹', libraries: '记忆库',
25
30
  browser: '记忆浏览', global: '全局记忆', prompts: '提示词', stats: '统计', memories: '记忆总览',
26
- lexicon: '词典', help: '帮助',
31
+ logs: '日志', lexicon: '词典', help: '帮助',
27
32
  },
28
33
  en: {
29
- engine: 'Engine & connection', settings: 'Memory settings', folders: 'Folders', libraries: 'Libraries',
34
+ engine: 'Engine & connection', connection: 'Connection & vectors', settings: 'Memory settings', folders: 'Folders', libraries: 'Libraries',
30
35
  browser: 'Memory browser', global: 'Global memory', prompts: 'Prompts', stats: 'Stats', memories: 'Memories',
31
- lexicon: 'Lexicon', help: 'Help',
36
+ logs: 'Logs', lexicon: 'Lexicon', help: 'Help',
32
37
  },
33
38
  }
34
39
  var copy = COPY[locale]
@@ -51,6 +56,8 @@
51
56
  }
52
57
  }
53
58
  applyCopy()
59
+ // 导航装饰文字改走 CSS 变量,随语言切换(见 standalone.css 的 --dshm-studio-label)。
60
+ try { document.documentElement.style.setProperty('--dshm-studio-label', JSON.stringify(copy.studioLabel || '')) } catch (e) {}
54
61
  var root = document.getElementById('root')
55
62
  var boot = document.getElementById('boot')
56
63
  var pageLabel = document.getElementById('pageLabel')
@@ -98,7 +105,7 @@
98
105
  /* ── chrome: page label, title, footer, return control ─────────────────── */
99
106
  function currentSlug() {
100
107
  var match = /^#\/settings\/([a-z]+)/.exec(String(window.location.hash || ''))
101
- return match && PAGE_NAMES[locale][match[1]] ? match[1] : 'memories'
108
+ return match && SETTINGS_PAGES.indexOf(match[1]) >= 0 ? match[1] : 'memories'
102
109
  }
103
110
  function paintLocation() {
104
111
  var slug = currentSlug()
@@ -137,20 +144,31 @@
137
144
  }
138
145
  if (window.opener && !window.opener.closed) {
139
146
  try { window.opener.focus() } catch (e) {}
140
- try { window.close(); return } catch (e) {}
141
147
  }
142
- if (window.history.length > 1) window.history.back()
148
+ // window.close() 对不允许关闭的窗口静默失败且不抛异常,用 window.closed 判定兜底。
149
+ window.close()
150
+ if (!window.closed) window.history.back()
143
151
  })
144
152
 
145
153
  /* ── ambience: pointer spotlight and a shadow once the page scrolls ────── */
146
- if (!reduceMotion && window.matchMedia('(pointer: fine)').matches) {
154
+ // The overlay host embeds this page in an iframe over the whole DSH app.
155
+ // Repainting a full-viewport gradient on every pointer frame forces the host's
156
+ // compositor to keep re-combining that surface, and a maximized window is where
157
+ // WebView2 starts dropping wall tiles. Keep the spotlight for the standalone
158
+ // tab only; the overlay keeps the static ambient layers.
159
+ if (!framed && !reduceMotion && window.matchMedia('(pointer: fine)').matches) {
147
160
  document.body.dataset.pointer = 'fine'
161
+ var spot = document.querySelector('.ambient-spot')
148
162
  var pending = 0
149
163
  window.addEventListener('pointermove', function (event) {
150
164
  if (pending) return
151
165
  pending = window.requestAnimationFrame(function () {
152
166
  pending = 0
153
- var style = document.documentElement.style
167
+ // Scope the variables to the one element that paints the gradient.
168
+ // Writing them on <html> invalidated style for the whole document on
169
+ // every pointer frame — with a long wall of backdrop-filter cards that
170
+ // is enough for WebView2 to drop or flicker compositor frames.
171
+ var style = (spot || document.documentElement).style
154
172
  style.setProperty('--spot-x', event.clientX + 'px')
155
173
  style.setProperty('--spot-y', event.clientY + 'px')
156
174
  })
package/lib/webui.js CHANGED
@@ -26,7 +26,7 @@ export function standaloneAsset(pathname) {
26
26
  }
27
27
 
28
28
  /** The studio stylesheet lives next to this file so it can be read and edited as CSS. */
29
- export function standaloneCss() {
29
+ function standaloneCss() {
30
30
  return fs.readFileSync(path.join(DIR, 'standalone.css'), 'utf8')
31
31
  }
32
32
 
@@ -43,10 +43,10 @@ export function standaloneHtml() {
43
43
  <title>MemU 记忆</title>
44
44
  <meta name="theme-color" content="#f4f5f9">
45
45
  <link rel="icon" href="/dsh-memu-memory/ui-assets/mark.svg" type="image/svg+xml"><link rel="alternate icon" href="/dsh-memu-memory/ui-assets/icon.png">
46
- <script>try{var t=localStorage.getItem('dshm-theme');document.documentElement.dataset.theme=t||(window.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light')}catch(e){}</script>
46
+ <script>try{var q=new URLSearchParams(location.search).get('theme');q=(q==='dark'||q==='light')?q:null;var t=localStorage.getItem('dshm-theme');document.documentElement.dataset.theme=t||q||(window.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light')}catch(e){}</script>
47
47
  <style>
48
- :root{--dsw-alias-bg-base:#f4f5f9;--dsw-alias-bg-layer-1:#ffffff;--dsw-alias-bg-layer-2:#eceef5;--dsw-alias-bg-layer-3:#e2e5ef;--dsw-alias-bg-layer-4:#d8dce9;--dsw-alias-label-primary:#1a1e2b;--dsw-alias-label-secondary:#5f6577;--dsw-alias-label-primary-inverted:#ffffff;--dsw-alias-border-l1:rgba(26,30,43,.10);--dsw-alias-border-l2:rgba(26,30,43,.18);--dsw-alias-brand-primary:#3b5bdb;--dsw-alias-brand-text:#ffffff;--dsw-alias-label-error:#b43e45;--dsw-alias-label-warning:#9a6b1f}
49
- :root[data-theme=dark]{--dsw-alias-bg-base:#0d0f15;--dsw-alias-bg-layer-1:#171a23;--dsw-alias-bg-layer-2:#1e222d;--dsw-alias-bg-layer-3:#272c39;--dsw-alias-bg-layer-4:#313747;--dsw-alias-label-primary:#e9ebf4;--dsw-alias-label-secondary:#9ba2b5;--dsw-alias-label-primary-inverted:#0b1030;--dsw-alias-border-l1:rgba(233,235,244,.10);--dsw-alias-border-l2:rgba(233,235,244,.18);--dsw-alias-brand-primary:#8ea2ff;--dsw-alias-brand-text:#0b1030;--dsw-alias-label-error:#f08a91;--dsw-alias-label-warning:#d6a45f}
48
+ :root{--dsw-alias-bg-base:#f4f5f9;--dsw-alias-bg-layer-1:#ffffff;--dsw-alias-bg-layer-2:#eceef5;--dsw-alias-bg-layer-3:#e2e5ef;--dsw-alias-bg-layer-4:#d8dce9;--dsw-alias-label-primary:#1a1e2b;--dsw-alias-label-secondary:#5f6577;--dsw-alias-label-primary-inverted:#ffffff;--dsw-alias-border-l1:rgba(26,30,43,.10);--dsw-alias-border-l2:rgba(26,30,43,.18);--dsw-alias-brand-primary:#3b5bdb;--dsw-alias-brand-text:#ffffff;--dsw-alias-label-error:#b43e45;--dsw-alias-label-warning:#9a6b1f;--dsw-alias-state-error-primary:#b43e45;--dsw-alias-state-warn-label:#9a6b1f;--dsw-alias-state-warn-primary:#9a6b1f}
49
+ :root[data-theme=dark]{--dsw-alias-bg-base:#0d0f15;--dsw-alias-bg-layer-1:#171a23;--dsw-alias-bg-layer-2:#1e222d;--dsw-alias-bg-layer-3:#272c39;--dsw-alias-bg-layer-4:#313747;--dsw-alias-label-primary:#e9ebf4;--dsw-alias-label-secondary:#9ba2b5;--dsw-alias-label-primary-inverted:#0b1030;--dsw-alias-border-l1:rgba(233,235,244,.10);--dsw-alias-border-l2:rgba(233,235,244,.18);--dsw-alias-brand-primary:#8ea2ff;--dsw-alias-brand-text:#0b1030;--dsw-alias-label-error:#f08a91;--dsw-alias-label-warning:#d6a45f;--dsw-alias-state-error-primary:#f08a91;--dsw-alias-state-warn-label:#d6a45f;--dsw-alias-state-warn-primary:#d6a45f}
50
50
  ${css}
51
51
  </style>
52
52
  </head>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-memu-memory",
3
3
  "icon": "./assets/icon.png",
4
- "version": "1.2.8",
4
+ "version": "1.2.9",
5
5
  "description": "面向长篇 RP 与陪伴对话的 DeepSeek Harness 记忆插件:三层记忆、逐轮召回、来源标注、关系图、图片附件与独立 WebUI。",
6
6
  "keywords": [
7
7
  "deepseek-harness",
@@ -49,10 +49,11 @@
49
49
  "cordis.patch.yml",
50
50
  "requirements.lock",
51
51
  "README.md",
52
+ "README.zh.md",
53
+ "CHANGELOG.md",
52
54
  "assets",
53
55
  "AGENTS.md",
54
56
  "docs",
55
- "README.zh.md",
56
57
  "LICENSE"
57
58
  ],
58
59
  "scripts": {
@@ -626,7 +626,7 @@ await auto('F-1', 'the engine can be listed, switched and pruned', async () => {
626
626
  await auto('F-2', 'a backup restore brings a deleted memory back', async () => {
627
627
  const lib = makeLibrary('f2')
628
628
  seed(lib.id, 'mem-f2keep', { title: 'written before the backup' })
629
- const made = state.backupDatabases()
629
+ const made = await state.backupDatabases()
630
630
  assert.ok(made, 'a backup was taken')
631
631
  const backups = (await dispatch({}, 'listBackups', {})).backups
632
632
  assert.ok(backups.length >= 1, 'it shows up in the list')
@@ -894,7 +894,7 @@ await auto('H-7', 'an archived memory can be deleted, and only an archived one',
894
894
  await memory.privateArchive({ libraryId: lib.id, id: live.id })
895
895
  const archivedRow = (await dispatch({}, 'browseLibrary', { libraryId: lib.id })).files.find((item) => item.id === live.id)
896
896
  assert.equal(archivedRow.status, 'archived', 'archiving keeps it, so the archived tab has something to show')
897
- const gone = await dispatch({}, 'deleteMemory', { id: live.id, libraryId: lib.id })
897
+ const gone = await dispatch({}, 'deleteMemory', { id: live.id, libraryId: lib.id, confirmed: true })
898
898
  assert.equal(gone.deleted, true)
899
899
  assert.ok(!(await dispatch({}, 'browseLibrary', { libraryId: lib.id })).files.some((item) => item.id === live.id), 'and then it is really gone')
900
900
  let needsLib = ""
@@ -43,7 +43,9 @@ const budget = (rel, limit) => {
43
43
  budget('AGENTS.md', 60000)
44
44
 
45
45
  check('i18n', process.execPath, ['scripts/check-i18n.mjs'])
46
- check('package.json', process.execPath, ['-e', 'JSON.parse(require("fs").readFileSync("package.json","utf8"))'])
46
+ // npm silently de-duplicates `files` on pack, so a repeated entry only rots in
47
+ // source without any failing check. Pin the whitelist shape here instead.
48
+ check('package.json', process.execPath, ['-e', 'const p=JSON.parse(require("fs").readFileSync("package.json","utf8"));if(!Array.isArray(p.files)||new Set(p.files).size!==p.files.length)throw new Error("package.json: files must be an array with no duplicates")'])
47
49
 
48
50
  // W2 防漂移闸门:RPC 方法数标记、tests 跟踪状态、loader/stub 完整性。
49
51
  // 这三项由 scripts/check-doc-drift.mjs 实现,返回 ok / skipped / fail 三态:
@@ -1,6 +1,7 @@
1
1
  import fs from 'node:fs'
2
2
 
3
3
  const src = fs.readFileSync('lib/client.js', 'utf8')
4
+ const standalone = fs.readFileSync('lib/webui/standalone.js', 'utf8')
4
5
  const used = new Set()
5
6
  for (const m of src.matchAll(/\bt\('([a-zA-Z][a-zA-Z0-9]*)'\)/g)) used.add(m[1])
6
7
 
@@ -27,4 +28,37 @@ console.log('zh/en key diff:', [...zh].filter((k) => !en.has(k)).concat([...en].
27
28
  console.log(missing(zh, 'MISSING-ZH').join('\n') || 'zh complete')
28
29
  console.log(missing(en, 'MISSING-EN').join('\n') || 'en complete')
29
30
  console.log(unused(zh, 'UNUSED-ZH').join('\n') || 'no unused zh')
30
- if (missing(zh, 'zh').length || missing(en, 'en').length || [...zh].some(key => !en.has(key)) || [...en].some(key => !zh.has(key))) process.exitCode = 1
31
+
32
+ // The standalone shell carries its own COPY (data-i18n attributes) and PAGE_NAMES
33
+ // (breadcrumb / title labels). They are reached dynamically, so literal t('key')
34
+ // matching never sees them; check zh/en parity and the page list here instead of
35
+ // letting a missing page silently fall back to "memories".
36
+ const standaloneKeys = (block, lang) => {
37
+ const start = block.indexOf(lang + ': {')
38
+ if (start < 0) return new Set()
39
+ const end = block.indexOf('\n }', start)
40
+ const body = block.slice(start, end < 0 ? undefined : end)
41
+ // COPY / PAGE_NAMES pack several `key: 'value'` pairs onto one line, so match
42
+ // every pair rather than only the first key on each line.
43
+ return new Set([...body.matchAll(/([a-zA-Z][a-zA-Z0-9]*)\s*:\s*'/g)].map((m) => m[1]))
44
+ }
45
+ const copyBlock = standalone.slice(standalone.indexOf('var COPY = {'), standalone.indexOf('var SETTINGS_PAGES = ['))
46
+ const pageBlock = standalone.slice(standalone.indexOf('var PAGE_NAMES = {'), standalone.indexOf('var copy = COPY'))
47
+ const settingsPages = new Set([...src.matchAll(/const SETTINGS_PAGES = \[([^\]]+)\]/g)]
48
+ .flatMap((m) => [...m[1].matchAll(/'([a-z]+)'/g)].map((x) => x[1])))
49
+
50
+ const diff = (a, b) => [...a].filter((k) => !b.has(k)).concat([...b].filter((k) => !a.has(k)))
51
+ const checks = [
52
+ ['COPY zh/en', diff(standaloneKeys(copyBlock, 'zh'), standaloneKeys(copyBlock, 'en'))],
53
+ ['PAGE_NAMES zh/en', diff(standaloneKeys(pageBlock, 'zh'), standaloneKeys(pageBlock, 'en'))],
54
+ ['PAGE_NAMES vs SETTINGS_PAGES', diff(standaloneKeys(pageBlock, 'zh'), settingsPages)],
55
+ ]
56
+ let standaloneOk = true
57
+ for (const [label, keys] of checks) {
58
+ if (keys.length) { standaloneOk = false; console.log(label + ' mismatch:', keys.join(', ')) }
59
+ }
60
+ if (standaloneOk) console.log('standalone zh/en + page keys complete')
61
+
62
+ const i18nOk = !missing(zh, 'zh').length && !missing(en, 'en').length
63
+ && ![...zh].some((key) => !en.has(key)) && ![...en].some((key) => !zh.has(key))
64
+ if (!i18nOk || !standaloneOk) process.exitCode = 1
@@ -33,7 +33,7 @@ if (argv.includes('--help') || argv.includes('-h')) {
33
33
  const apply = argv.includes('--apply')
34
34
  const json = argv.includes('--json')
35
35
 
36
- function main() {
36
+ async function main() {
37
37
  const pending = scanLegacyLibraries()
38
38
  const report = { ok: true, applied: false, dataDir: dataDir(), pending, backup: null, libraries: [] }
39
39
 
@@ -44,7 +44,7 @@ function main() {
44
44
  if (apply) {
45
45
  // A rewrite that cannot be undone is not a repair; the same backup the panel's
46
46
  // maintenance button takes, with a manifest the restore path understands.
47
- report.backup = state.backupDatabases()
47
+ report.backup = await state.backupDatabases()
48
48
  report.applied = true
49
49
  report.libraries = migrateLibraries()
50
50
  state.flushState()
@@ -56,7 +56,7 @@ function main() {
56
56
 
57
57
  let report
58
58
  try {
59
- report = main()
59
+ report = await main()
60
60
  } catch (error) {
61
61
  const failed = { ok: false, error: String(error?.message || error) }
62
62
  if (json) console.log(JSON.stringify(failed, null, 2))
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ // P2-5 explicit session-binding GC. Dry-run by default; --apply removes old bindings
3
+ // and their consolidation-ledger state.
4
+ //
5
+ // Two clocks, not one: lastTurnAt says when the conversation last spoke, and a live
6
+ // consolidation lease says something is writing for it right now. Pruning on
7
+ // lastTurnAt alone deleted sessions mid-job, so a session with an unexpired lease is
8
+ // skipped and reported.
9
+ import { pruneSessionBindings } from '../lib/state.js'
10
+ import { clearSessionState, sessionState } from '../lib/consolidation-ledger.js'
11
+
12
+ const args = process.argv.slice(2)
13
+ const apply = args.includes('--apply')
14
+ const daysFlag = args.indexOf('--days')
15
+ const days = daysFlag >= 0 ? Number(args[daysFlag + 1]) : 30
16
+ // 0 used to mean "every session is old enough", which made this a wipe command with a
17
+ // harmless-looking flag. Deleting a binding cannot be undone, so refuse it.
18
+ if (!Number.isFinite(days) || days <= 0) {
19
+ console.error('prune-sessions: --days must be a positive number of days (0 is not "all")')
20
+ process.exit(2)
21
+ }
22
+
23
+ const isBusy = (sessionId) => {
24
+ const leaseUntil = Number(sessionState(sessionId)?.inflight?.leaseUntil) || 0
25
+ return leaseUntil > Date.now()
26
+ }
27
+
28
+ const result = pruneSessionBindings({ olderThanDays: days, dryRun: !apply, isBusy })
29
+ if (apply) {
30
+ for (const sessionId of result.removed || []) {
31
+ try { clearSessionState(sessionId) } catch {}
32
+ }
33
+ }
34
+ console.log(JSON.stringify(result, null, 2))
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+ // P2-5 vector generation GC. Dry-run by default. --apply deletes only
3
+ // generation files that are not referenced by the active/pending manifest,
4
+ // older than --keep generations, and older than the retention window.
5
+ import { pruneVectorArtifacts } from '../lib/vector-profile.js'
6
+
7
+ const args = process.argv.slice(2)
8
+ const apply = args.includes('--apply')
9
+ const valueOf = (name, fallback) => {
10
+ const index = args.indexOf(name)
11
+ if (index < 0) return fallback
12
+ const value = Number(args[index + 1])
13
+ if (!Number.isFinite(value) || value < 0) {
14
+ console.error(`prune-vectors: ${name} must be a non-negative number`)
15
+ process.exit(2)
16
+ }
17
+ return value
18
+ }
19
+ const result = pruneVectorArtifacts({
20
+ apply,
21
+ keepGenerations: valueOf('--keep', 2),
22
+ olderThanDays: valueOf('--days', 7),
23
+ })
24
+ console.log(JSON.stringify(result, null, 2))
@@ -149,14 +149,15 @@ test('maybeCue falls back to a fixed sentence when no memory qualifies', async (
149
149
 
150
150
  test('a tense room pulls charged memories further ahead than a quiet one', async () => {
151
151
  const { sessionId, exec } = setup('arousal')
152
- // 两条正文词面不同(dice 0.512,低于 TOPIC_DICE):事实级去重上线后,同文改标题的
153
- // 旧写法会被写入侧打标/召回侧折叠,唤醒度因子就测不到了。语义并行 + 显式 arousal
154
- // 仍然隔离这个因子。
152
+ // Both bodies cover the query terms equally (BM25 gives the same lexical score),
153
+ // so arousal is the only variable. The old includes scorer tied on the same
154
+ // fixture; BM25's length/IDF normalisation would otherwise let a lexically better
155
+ // sentence outrank the charged one before the mood factor is applied.
155
156
  const calm = await memory.privateRemember({
156
157
  exec, content: 'The hallway smelled of rain on warm stone.', title: 'hallway calm', arousal: 0.1, moodValence: 0.05,
157
158
  })
158
159
  const loud = await memory.privateRemember({
159
- exec, content: 'Rain hammered the hallway stones while voices echoed off the walls.', title: 'hallway loud', arousal: 0.95, moodValence: 0.05,
160
+ exec, content: 'Rain hammered the hallway stone as voices echoed.', title: 'hallway loud', arousal: 0.95, moodValence: 0.05,
160
161
  })
161
162
 
162
163
  async function gapAt(arousal) {