@modusensus/dsh-mneme 0.6.7 → 0.6.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 (139) hide show
  1. package/.github/workflows/test.yml +32 -0
  2. package/.release-notes-v0.6.9.md +13 -0
  3. package/CHANGELOG.md +89 -0
  4. package/LICENSE +21 -21
  5. package/README.md +219 -463
  6. package/SECURITY.md +544 -0
  7. package/docs/devlog/2026-08-14-dsh-mneme-dev-log.md +247 -0
  8. package/docs/devlog/2026-08-15-dsh-mneme-audit-stress-dev-log.md +145 -0
  9. package/docs/devlog/2026-08-15-dsh-mneme-pipeline-dev-log.md +56 -0
  10. package/docs/devlog/2026-08-15-dsh-mneme-reflection-dev-log.md +77 -0
  11. package/docs/devlog/2026-08-15-dsh-mneme-review-fixes-dev-log.md +64 -0
  12. package/docs/devlog/2026-08-15-dsh-mneme-semantic-dev-log.md +90 -0
  13. package/dsh-mneme/CHANGELOG.md +248 -0
  14. package/dsh-mneme/LICENSE +21 -0
  15. package/dsh-mneme/README.md +465 -0
  16. package/{cordis.patch.yml → dsh-mneme/cordis.patch.yml} +15 -15
  17. package/dsh-mneme/docs/AGENT_MEMORY_RESEARCH.md +183 -0
  18. package/dsh-mneme/docs/ENTITIES.md +245 -0
  19. package/dsh-mneme/docs/LOCAL_MODEL.md +141 -0
  20. package/dsh-mneme/docs/MIGRATION.md +127 -0
  21. package/dsh-mneme/docs/SEMANTIC.md +256 -0
  22. package/dsh-mneme/docs/SLEEP.md +163 -0
  23. package/{lib → dsh-mneme/lib}/api.js +783 -783
  24. package/{lib → dsh-mneme/lib}/client.js +1757 -1757
  25. package/{src → dsh-mneme/lib}/commands.js +64 -64
  26. package/{lib → dsh-mneme/lib}/config.js +298 -288
  27. package/{lib → dsh-mneme/lib}/dream/clustering.js +118 -118
  28. package/{src → dsh-mneme/lib}/dream/decisions.js +488 -439
  29. package/{lib → dsh-mneme/lib}/dream/sleep.js +561 -554
  30. package/{src → dsh-mneme/lib}/dream/tag-extractor.js +156 -156
  31. package/{lib → dsh-mneme/lib}/dream.js +958 -929
  32. package/{src → dsh-mneme/lib}/embedding.js +154 -154
  33. package/{src → dsh-mneme/lib}/entities/extractor.js +242 -242
  34. package/{src → dsh-mneme/lib}/hot-memory.js +53 -53
  35. package/{lib → dsh-mneme/lib}/index.js +361 -361
  36. package/{src → dsh-mneme/lib}/inject.js +208 -208
  37. package/{lib → dsh-mneme/lib}/local-embedder.js +282 -282
  38. package/{lib → dsh-mneme/lib}/mirror.js +170 -170
  39. package/{lib → dsh-mneme/lib}/parser/tag.js +59 -59
  40. package/{lib → dsh-mneme/lib}/parser/wiki-link.js +38 -38
  41. package/{src → dsh-mneme/lib}/quality-filter.js +123 -123
  42. package/{lib → dsh-mneme/lib}/reranker.js +218 -218
  43. package/{lib → dsh-mneme/lib}/search/adaptive.js +22 -22
  44. package/{lib → dsh-mneme/lib}/search/bm25.js +96 -96
  45. package/{src → dsh-mneme/lib}/search/tag-boost.js +61 -61
  46. package/{src → dsh-mneme/lib}/service.js +1726 -1726
  47. package/{lib → dsh-mneme/lib}/settings.js +172 -172
  48. package/{lib → dsh-mneme/lib}/store.js +2238 -2238
  49. package/{lib → dsh-mneme/lib}/summarize.js +236 -236
  50. package/{lib → dsh-mneme/lib}/tools.js +290 -290
  51. package/{lib → dsh-mneme/lib}/vector-index.js +116 -116
  52. package/dsh-mneme/package-lock.json +1936 -0
  53. package/dsh-mneme/package.json +80 -0
  54. package/{scripts → dsh-mneme/scripts}/benchmark-embed.js +201 -201
  55. package/{scripts → dsh-mneme/scripts}/benchmark-recall.js +133 -133
  56. package/{scripts → dsh-mneme/scripts}/benchmark-rerank.js +166 -166
  57. package/{scripts → dsh-mneme/scripts}/e2e-dsh.js +218 -218
  58. package/{scripts → dsh-mneme/scripts}/stress-dsh.js +255 -255
  59. package/{scripts → dsh-mneme/scripts}/sync-lib.js +52 -52
  60. package/{src → dsh-mneme/src}/api.js +783 -783
  61. package/{lib → dsh-mneme/src}/commands.js +64 -64
  62. package/{src → dsh-mneme/src}/config.js +298 -288
  63. package/{src → dsh-mneme/src}/dream/clustering.js +118 -118
  64. package/{lib → dsh-mneme/src}/dream/decisions.js +488 -439
  65. package/{src → dsh-mneme/src}/dream/sleep.js +561 -554
  66. package/{lib → dsh-mneme/src}/dream/tag-extractor.js +156 -156
  67. package/{src → dsh-mneme/src}/dream.js +958 -929
  68. package/{lib → dsh-mneme/src}/embedding.js +154 -154
  69. package/{lib → dsh-mneme/src}/entities/extractor.js +242 -242
  70. package/{lib → dsh-mneme/src}/hot-memory.js +53 -53
  71. package/{src → dsh-mneme/src}/index.js +361 -361
  72. package/{lib → dsh-mneme/src}/inject.js +208 -208
  73. package/{src → dsh-mneme/src}/local-embedder.js +282 -282
  74. package/{src → dsh-mneme/src}/mirror.js +170 -170
  75. package/{src → dsh-mneme/src}/parser/tag.js +59 -59
  76. package/{src → dsh-mneme/src}/parser/wiki-link.js +38 -38
  77. package/{lib → dsh-mneme/src}/quality-filter.js +123 -123
  78. package/{src → dsh-mneme/src}/reranker.js +218 -218
  79. package/{src → dsh-mneme/src}/search/adaptive.js +22 -22
  80. package/{src → dsh-mneme/src}/search/bm25.js +96 -96
  81. package/{lib → dsh-mneme/src}/search/tag-boost.js +61 -61
  82. package/{lib → dsh-mneme/src}/service.js +1726 -1726
  83. package/{src → dsh-mneme/src}/settings.js +172 -172
  84. package/{src → dsh-mneme/src}/store.js +2238 -2238
  85. package/{src → dsh-mneme/src}/summarize.js +236 -236
  86. package/{src → dsh-mneme/src}/tools.js +290 -290
  87. package/{src → dsh-mneme/src}/vector-index.js +116 -116
  88. package/{test → dsh-mneme/test}/api.test.js +594 -594
  89. package/{test → dsh-mneme/test}/audit.test.js +448 -448
  90. package/{test → dsh-mneme/test}/benchmark.test.js +35 -35
  91. package/{test → dsh-mneme/test}/boundary-v0625.test.js +82 -82
  92. package/{test → dsh-mneme/test}/client.test.js +368 -368
  93. package/{test → dsh-mneme/test}/clustering.test.js +100 -100
  94. package/{test → dsh-mneme/test}/commands.test.js +69 -69
  95. package/{test → dsh-mneme/test}/config.test.js +50 -50
  96. package/{test → dsh-mneme/test}/conflict-freeze.test.js +290 -290
  97. package/{test → dsh-mneme/test}/directory.test.js +134 -134
  98. package/{test → dsh-mneme/test}/dream.test.js +1060 -901
  99. package/{test → dsh-mneme/test}/entities.test.js +522 -522
  100. package/{test → dsh-mneme/test}/epistemic.test.js +298 -298
  101. package/{test → dsh-mneme/test}/fnew-0112.test.js +311 -311
  102. package/{test → dsh-mneme/test}/fnew-03.test.js +422 -422
  103. package/{test → dsh-mneme/test}/graph-api.test.js +175 -175
  104. package/{test → dsh-mneme/test}/helpers/dream-mock.js +82 -82
  105. package/{test → dsh-mneme/test}/hot-memory.test.js +174 -174
  106. package/{test → dsh-mneme/test}/inject.test.js +103 -103
  107. package/{test → dsh-mneme/test}/llm-audit.test.js +279 -279
  108. package/{test → dsh-mneme/test}/local-embedder.test.js +227 -227
  109. package/{test → dsh-mneme/test}/mirror-dirty.test.js +424 -424
  110. package/{test → dsh-mneme/test}/mirror-edit-digest.test.js +187 -187
  111. package/{test → dsh-mneme/test}/mirror-generation.test.js +499 -499
  112. package/{test → dsh-mneme/test}/mirror.test.js +249 -249
  113. package/{test → dsh-mneme/test}/normalize-decisions.test.js +120 -120
  114. package/{test → dsh-mneme/test}/peer-blockers.test.js +190 -190
  115. package/{test → dsh-mneme/test}/policy-epoch.test.js +259 -259
  116. package/{test → dsh-mneme/test}/provenance.test.js +103 -103
  117. package/{test → dsh-mneme/test}/quality-filter.test.js +118 -118
  118. package/{test → dsh-mneme/test}/reasoning-effort.test.js +199 -199
  119. package/{test → dsh-mneme/test}/recall-evals.test.js +235 -235
  120. package/{test → dsh-mneme/test}/recall-layer.test.js +315 -315
  121. package/{test → dsh-mneme/test}/receipt-chain.test.js +451 -451
  122. package/{test → dsh-mneme/test}/reflection.test.js +226 -226
  123. package/{test → dsh-mneme/test}/reranker.test.js +240 -240
  124. package/{test → dsh-mneme/test}/search-fusion.test.js +90 -90
  125. package/{test → dsh-mneme/test}/semantic.test.js +124 -124
  126. package/{test → dsh-mneme/test}/service-search.test.js +199 -199
  127. package/{test → dsh-mneme/test}/service.test.js +435 -435
  128. package/{test → dsh-mneme/test}/settings.test.js +118 -118
  129. package/{test → dsh-mneme/test}/sleep.test.js +365 -365
  130. package/{test → dsh-mneme/test}/store.test.js +436 -436
  131. package/{test → dsh-mneme/test}/stress.test.js +209 -209
  132. package/{test → dsh-mneme/test}/summarize.test.js +191 -191
  133. package/{test → dsh-mneme/test}/tag-boost.test.js +125 -125
  134. package/{test → dsh-mneme/test}/tag.test.js +312 -312
  135. package/{test → dsh-mneme/test}/tools.test.js +285 -285
  136. package/{test → dsh-mneme/test}/vector-index.test.js +221 -221
  137. package/{test → dsh-mneme/test}/wiki-link.test.js +332 -332
  138. package/package.json +18 -40
  139. package//346/250/252/345/271/205.png +0 -0
@@ -1,368 +1,368 @@
1
- import test from "node:test";
2
- import assert from "node:assert/strict";
3
- import { readFileSync, existsSync } from "node:fs";
4
- import { fileURLToPath } from "node:url";
5
- import { dirname, join } from "node:path";
6
-
7
- const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
- const clientSource = readFileSync(join(root, "lib/client.js"), "utf8");
9
- const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
10
-
11
- // The Web client bundle registers itself via __ModuleLoader__.load. DSH
12
- // resolves the bundle by plugin package name, so the registered id must match
13
- // package.json `name` exactly (a mismatch surfaces as "loaded without
14
- // registering '@modusensus/dsh-mneme'" in the DSH client).
15
- test("client bundle registers under the package name", () => {
16
- const match = clientSource.match(/__ModuleLoader__\.load\(\{\s*id:\s*"([^"]+)"/);
17
- assert.ok(match, "client bundle must call __ModuleLoader__.load with an id");
18
- assert.equal(match[1], pkg.name, "registered id must equal package.json name");
19
- });
20
-
21
- // client.js is hand-authored under lib/ only (no src/ counterpart), so the
22
- // src->lib sync must never prune it.
23
- test("client bundle is lib-only with no src counterpart", () => {
24
- assert.equal(existsSync(join(root, "src/client.js")), false, "src/ must not contain client.js");
25
- assert.equal(existsSync(join(root, "lib/client.js")), true, "lib/client.js must exist");
26
- });
27
-
28
- // The memory entry lives at the sidebar foot, not in the settings modal: the
29
- // migration must register into `sidebar.footer.action` (the list slot the
30
- // sidebar shell renders beside Settings) and must not keep a `settings.section`
31
- // registration, or the entry would appear twice under different hosts.
32
- test("memory entry registers into the sidebar foot slot", () => {
33
- assert.ok(
34
- clientSource.includes('ctx.slots.inject("sidebar.footer.action"'),
35
- "client must inject into sidebar.footer.action"
36
- );
37
- assert.equal(
38
- clientSource.includes('"settings.section"'),
39
- false,
40
- "the old settings.section registration must be gone"
41
- );
42
- });
43
-
44
- // The drawer era is over as the PRIMARY surface: the sidebar entry must
45
- // activate the main-area memory library tab first. The one sanctioned
46
- // exception is the hero screen — the host hides the whole tab ring while a
47
- // session is blank, so activation legitimately fails there and the same
48
- // click falls back to a full-viewport overlay (same MemoryExplorer, not the
49
- // old 420px side drawer). A dialog role stays banned either way.
50
- test("tab-first activation with hero-screen overlay fallback", () => {
51
- assert.equal(
52
- clientSource.includes("role: \"dialog\""),
53
- false,
54
- "no dialog surface should remain"
55
- );
56
- assert.ok(
57
- clientSource.includes("activateExplorerTab(t(\"memory.view.label\"))"),
58
- "the sidebar trigger must activate the memory library tab by its label"
59
- );
60
- assert.ok(
61
- clientSource.includes("activateExplorerTab(t(\"memory.view.label\")).then((ok) => { if (!ok) setOpen(true); })"),
62
- "a failed tab activation must open the fallback overlay"
63
- );
64
- assert.ok(
65
- /if \(!tab\) \{ resolve\(false\); return; \}/.test(clientSource),
66
- "activation must resolve false when the tab ring is absent (hero screen)"
67
- );
68
- assert.ok(
69
- /aria-selected.*true/.test(clientSource),
70
- "activation is only confirmed once the host marks the tab selected"
71
- );
72
- });
73
-
74
- // The fallback overlay reuses the full MemoryExplorer (three columns, graph,
75
- // settings) at viewport size — not the old side drawer — and closes on Esc
76
- // or the close button.
77
- test("hero fallback overlay is a full-viewport MemoryExplorer with a close affordance", () => {
78
- assert.ok(
79
- clientSource.includes('.mneme-overlay{position:fixed;inset:0'),
80
- "the overlay must cover the full viewport"
81
- );
82
- assert.ok(
83
- clientSource.includes('h(MemoryExplorer, { t })'),
84
- "the overlay renders the same MemoryExplorer component as the tab"
85
- );
86
- assert.ok(
87
- clientSource.includes('e.key === "Escape"'),
88
- "Esc must close the overlay"
89
- );
90
- assert.ok(
91
- clientSource.includes('"memory.overlay.close"'),
92
- "the overlay ships a localized close label in both dictionaries"
93
- );
94
- });
95
-
96
- // The sidebar hands each footer action only its column state: a wide row
97
- // (icon + label) when expanded, a bare rail icon when collapsed.
98
- test("trigger renders a wide row or a rail icon from the wide flag", () => {
99
- assert.ok(
100
- /wide \? "mneme-trigger" : "mneme-trigger mneme-rail"/.test(clientSource),
101
- "trigger must branch on the wide flag"
102
- );
103
- assert.ok(
104
- /wide && h\("span", \{ className: "mneme-trigger-label" \}/.test(clientSource),
105
- "the label span must render only when wide"
106
- );
107
- });
108
-
109
- // The full-width memory browser lives in the conversation view ring beside
110
- // Chat / Trajectory, so the client must inject into `conversation.view` with
111
- // a stable entry id (the active view is persisted by that id).
112
- test("explorer registers into the conversation view ring", () => {
113
- assert.ok(
114
- clientSource.includes('ctx.slots.inject("conversation.view"'),
115
- "client must inject into conversation.view"
116
- );
117
- assert.ok(
118
- clientSource.includes('id: "dsh-mneme-memory"'),
119
- "the view entry needs a stable, unique id"
120
- );
121
- assert.ok(
122
- clientSource.includes('"memory.view.label"'),
123
- "the tab label must come from the memory.view.label dictionary key"
124
- );
125
- });
126
-
127
- // The graph toggle must not read as "share": the primitives share icon is
128
- // banned and a custom node-graph glyph takes its place.
129
- test("graph toggle uses a node-graph glyph, not the share icon", () => {
130
- assert.equal(
131
- clientSource.includes("IconShareOutline16"),
132
- false,
133
- "IconShareOutline16 reads as share and must not appear"
134
- );
135
- assert.ok(
136
- clientSource.includes("GraphNodesIcon"),
137
- "the custom node-graph icon must back the graph toggle"
138
- );
139
- });
140
-
141
- // Every memory feature lives in the main-area library now: the explorer
142
- // hosts three sub-views (browse / graph / settings) switched by tabs whose
143
- // labels come from dedicated dictionary keys.
144
- test("explorer hosts browse, graph and settings sub-views", () => {
145
- for (const key of ["tabMemory", "tabGraph", "tabSettings"]) {
146
- assert.ok(
147
- clientSource.includes(`"memory.explorer.${key}"`),
148
- `sub-view labels must come from memory.explorer.${key}`
149
- );
150
- }
151
- assert.ok(
152
- clientSource.includes('h(GraphPanel, { t, focusEntity: graphFocus, onJumpMemory: jumpToMemory })'),
153
- "the graph panel must be embedded as a sub-view"
154
- );
155
- assert.ok(
156
- clientSource.includes('h(SettingsContent, { t })'),
157
- "the settings forms must be embedded as a sub-view"
158
- );
159
- });
160
-
161
- // The graph panel jumps back into the browser: related-memory rows and the
162
- // edge source button must land on the browse tab with the target selected.
163
- test("graph jump lands on the selected memory in the browser", () => {
164
- assert.ok(
165
- /onClick: \(\) => onJumpMemory && onJumpMemory\(m\)/.test(clientSource),
166
- "related-memory rows must jump via onJumpMemory(m)"
167
- );
168
- assert.ok(
169
- clientSource.includes("onJumpMemory({ id: selected.edge.memory_id })"),
170
- "the edge source button must jump to the origin memory by id"
171
- );
172
- assert.ok(
173
- /const jumpToMemory = \(target\) => \{/.test(clientSource),
174
- "jumpToMemory must reset filters and select the target"
175
- );
176
- });
177
-
178
- // "entity:" in the browser search is the graph entry grammar: it must offer
179
- // a jump chip instead of filtering the list.
180
- test("entity: search grammar offers a graph jump", () => {
181
- assert.ok(
182
- clientSource.includes('query.trim().startsWith("entity:")'),
183
- "the entity: prefix must be recognized"
184
- );
185
- assert.ok(
186
- /onClick: \(\) => openGraphFor\(entityQuery\)/.test(clientSource),
187
- "the jump chip must switch to the graph sub-view"
188
- );
189
- });
190
-
191
- // The explorer is a three-pane layout: types with counts, a month→day time
192
- // tree, and a detail pane rendering the untruncated content.
193
- test("explorer lays out types, timeline, and full-text detail", () => {
194
- assert.ok(
195
- clientSource.includes('className: "mneme-xmain"'),
196
- "the three-column grid must be present"
197
- );
198
- assert.ok(
199
- clientSource.includes('className: "mneme-xdcontent"'),
200
- "the detail pane must render the full content"
201
- );
202
- assert.ok(
203
- /toLocaleDateString\(undefined, \{ year: "numeric", month: "long" \}\)/.test(clientSource),
204
- "month groups must format via the host locale, not hardcoded strings"
205
- );
206
- });
207
-
208
- // The library page must read as a first-party view: the chrome resolves to
209
- // the host's design tokens (layer-1 canvas, brand-blue active states) and
210
- // the boxed-panel / pill-chip patterns of the drawer era must stay gone.
211
- test("explorer chrome aligns with the host design system", () => {
212
- assert.ok(
213
- clientSource.includes("background:var(--dsw-alias-bg-layer-1)"),
214
- "the page canvas must sit on the host bg-layer-1 token"
215
- );
216
- assert.ok(
217
- /\.mneme-vtab\.mneme-active::after/.test(clientSource),
218
- "active sub-tabs use the host underline treatment"
219
- );
220
- assert.ok(
221
- clientSource.includes(".mneme-vtab.mneme-active{color:var(--dsw-alias-state-business-primary)}"),
222
- "active sub-tab text must turn the host brand blue"
223
- );
224
- assert.equal(
225
- /\.mneme-xmain\{[^}]*border:1px/.test(clientSource),
226
- false,
227
- "the three-column layout must not wrap itself in a boxed panel"
228
- );
229
- assert.equal(
230
- clientSource.includes("border-radius:999px"),
231
- false,
232
- "pill chips belong to the drawer era and must stay gone"
233
- );
234
- });
235
-
236
- // The v0.6.1 wiki-link feature: the detail pane mounts a BacklinksPanel that
237
- // fetches the two read-only link endpoints by the selected memory id and
238
- // renders back/forward rows, each jumping back into the browser.
239
- test("detail pane mounts a BacklinksPanel backed by the two link endpoints", () => {
240
- assert.ok(
241
- clientSource.includes("h(BacklinksPanel, { memory: selected, t, onJump: jumpToMemory })"),
242
- "the detail pane must mount BacklinksPanel after the actions row"
243
- );
244
- assert.ok(
245
- clientSource.includes("/api/dsh-mneme/wikilinks/backlinks?id="),
246
- "BacklinksPanel must fetch the backlinks endpoint by memory id"
247
- );
248
- assert.ok(
249
- clientSource.includes("/api/dsh-mneme/wikilinks/forward?id="),
250
- "BacklinksPanel must fetch the forward-links endpoint by memory id"
251
- );
252
- });
253
-
254
- // Detail content turns [[target]] / [[display|target]] into clickable links:
255
- // the display text survives, the target title is kept for hover, and a click
256
- // resolves the title through the resolve endpoint before jumping.
257
- test("detail content renders wiki-links and resolves them on click", () => {
258
- assert.ok(
259
- clientSource.includes('className: "mneme-wikilink"'),
260
- "inline [[target]] links must use the .mneme-wikilink style"
261
- );
262
- assert.ok(
263
- clientSource.includes("/api/dsh-mneme/wikilinks/resolve?title="),
264
- "clicking a wiki-link must resolve the title via the resolve endpoint"
265
- );
266
- assert.ok(
267
- clientSource.includes('className: "mneme-backlinks"'),
268
- "the panel must render inside a .mneme-backlinks block"
269
- );
270
- });
271
-
272
- // v0.6.2 tag system: the detail pane renders tags as clickable chips wired to
273
- // the memory/tags endpoints, and a tag: query always goes server-side.
274
- test("detail pane renders editable tag chips backed by the tags endpoint", () => {
275
- assert.ok(
276
- clientSource.includes("/api/dsh-mneme/memory/tags?id="),
277
- "the panel must fetch the selected memory's tags via the GET endpoint"
278
- );
279
- assert.ok(
280
- clientSource.includes('method: "POST"'),
281
- "adding/removing a tag must POST to the tags endpoint"
282
- );
283
- assert.ok(
284
- clientSource.includes("onClick: () => onTagClick(tag)"),
285
- "a tag chip click must trigger a tag: search"
286
- );
287
- assert.ok(
288
- clientSource.includes("tagManual"),
289
- "the panel must read the manualTagEnabled gate to hide editing"
290
- );
291
- });
292
-
293
- test("tag: queries run server-side regardless of the semantic toggle", () => {
294
- assert.ok(
295
- clientSource.includes('(!semantic && !q.startsWith("tag:"))'),
296
- "tag: must bypass the semantic toggle and use the search endpoint"
297
- );
298
- assert.ok(
299
- clientSource.includes('setQuery(`tag:${tag}`)'),
300
- "a tag chip click must set the query to tag:<tag>"
301
- );
302
- });
303
-
304
- test("tag UI ships localized labels in both dictionaries", () => {
305
- for (const key of ["tagAdd", "tagRemove", "tagPlaceholder", "tagsEmpty"]) {
306
- assert.ok(
307
- clientSource.includes(`"memory.explorer.${key}"`),
308
- `memory.explorer.${key} key must exist`
309
- );
310
- }
311
- });
312
-
313
- // v0.6.3 directory view: a tag-folder tree backed by the directory endpoint.
314
- // Folders accordion via data-expanded controlled by MemoryExplorer-lifted
315
- // state; a memory entry click jumps back into the browser via onJump.
316
- test("directory sub-view mounts DirectoryPanel backed by the directory endpoint", () => {
317
- assert.ok(
318
- clientSource.includes("h(DirectoryPanel, { t, onJump: jumpToMemory, collapsed: dirCollapsed, setCollapsed: setDirCollapsed })"),
319
- "the directory panel must be embedded as a sub-view with lifted collapse state"
320
- );
321
- assert.ok(
322
- clientSource.includes("/api/dsh-mneme/directory"),
323
- "DirectoryPanel must fetch the directory endpoint"
324
- );
325
- assert.ok(
326
- clientSource.includes('className: "mneme-directory"'),
327
- "the directory panel must render inside the .mneme-directory block"
328
- );
329
- });
330
-
331
- test("directory folders accordion via data-expanded driven by MemoryExplorer state", () => {
332
- assert.ok(
333
- clientSource.includes('"data-expanded": String(open)'),
334
- "folder expansion must be driven by the data-expanded attribute"
335
- );
336
- assert.ok(
337
- clientSource.includes("const [dirCollapsed, setDirCollapsed] = useState({})"),
338
- "collapse state must live in MemoryExplorer so tab switches keep it"
339
- );
340
- assert.ok(
341
- clientSource.includes('"aria-expanded": String(open)'),
342
- "folder headers must announce their expanded state"
343
- );
344
- });
345
-
346
- test("directory entry click jumps to the memory detail via onJump", () => {
347
- assert.ok(
348
- clientSource.includes("onClick: () => onJump(m)"),
349
- "clicking a memory entry must call onJump with the memory"
350
- );
351
- assert.ok(
352
- clientSource.includes("formatDate(m.updated_at || m.created_at)"),
353
- "entries must render a timestamp via formatDate"
354
- );
355
- assert.ok(
356
- clientSource.includes("memory.directory.untagged"),
357
- "untagged memories must be bucketed under a labeled fallback folder"
358
- );
359
- });
360
-
361
- test("directory ships localized labels in both dictionaries", () => {
362
- for (const key of ["memory.explorer.tabDirectory", "memory.directory.untagged", "memory.directory.loading", "memory.directory.empty"]) {
363
- assert.ok(
364
- clientSource.includes(`"${key}"`),
365
- `${key} key must exist`
366
- );
367
- }
368
- });
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { readFileSync, existsSync } from "node:fs";
4
+ import { fileURLToPath } from "node:url";
5
+ import { dirname, join } from "node:path";
6
+
7
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
8
+ const clientSource = readFileSync(join(root, "lib/client.js"), "utf8");
9
+ const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
10
+
11
+ // The Web client bundle registers itself via __ModuleLoader__.load. DSH
12
+ // resolves the bundle by plugin package name, so the registered id must match
13
+ // package.json `name` exactly (a mismatch surfaces as "loaded without
14
+ // registering '@modusensus/dsh-mneme'" in the DSH client).
15
+ test("client bundle registers under the package name", () => {
16
+ const match = clientSource.match(/__ModuleLoader__\.load\(\{\s*id:\s*"([^"]+)"/);
17
+ assert.ok(match, "client bundle must call __ModuleLoader__.load with an id");
18
+ assert.equal(match[1], pkg.name, "registered id must equal package.json name");
19
+ });
20
+
21
+ // client.js is hand-authored under lib/ only (no src/ counterpart), so the
22
+ // src->lib sync must never prune it.
23
+ test("client bundle is lib-only with no src counterpart", () => {
24
+ assert.equal(existsSync(join(root, "src/client.js")), false, "src/ must not contain client.js");
25
+ assert.equal(existsSync(join(root, "lib/client.js")), true, "lib/client.js must exist");
26
+ });
27
+
28
+ // The memory entry lives at the sidebar foot, not in the settings modal: the
29
+ // migration must register into `sidebar.footer.action` (the list slot the
30
+ // sidebar shell renders beside Settings) and must not keep a `settings.section`
31
+ // registration, or the entry would appear twice under different hosts.
32
+ test("memory entry registers into the sidebar foot slot", () => {
33
+ assert.ok(
34
+ clientSource.includes('ctx.slots.inject("sidebar.footer.action"'),
35
+ "client must inject into sidebar.footer.action"
36
+ );
37
+ assert.equal(
38
+ clientSource.includes('"settings.section"'),
39
+ false,
40
+ "the old settings.section registration must be gone"
41
+ );
42
+ });
43
+
44
+ // The drawer era is over as the PRIMARY surface: the sidebar entry must
45
+ // activate the main-area memory library tab first. The one sanctioned
46
+ // exception is the hero screen — the host hides the whole tab ring while a
47
+ // session is blank, so activation legitimately fails there and the same
48
+ // click falls back to a full-viewport overlay (same MemoryExplorer, not the
49
+ // old 420px side drawer). A dialog role stays banned either way.
50
+ test("tab-first activation with hero-screen overlay fallback", () => {
51
+ assert.equal(
52
+ clientSource.includes("role: \"dialog\""),
53
+ false,
54
+ "no dialog surface should remain"
55
+ );
56
+ assert.ok(
57
+ clientSource.includes("activateExplorerTab(t(\"memory.view.label\"))"),
58
+ "the sidebar trigger must activate the memory library tab by its label"
59
+ );
60
+ assert.ok(
61
+ clientSource.includes("activateExplorerTab(t(\"memory.view.label\")).then((ok) => { if (!ok) setOpen(true); })"),
62
+ "a failed tab activation must open the fallback overlay"
63
+ );
64
+ assert.ok(
65
+ /if \(!tab\) \{ resolve\(false\); return; \}/.test(clientSource),
66
+ "activation must resolve false when the tab ring is absent (hero screen)"
67
+ );
68
+ assert.ok(
69
+ /aria-selected.*true/.test(clientSource),
70
+ "activation is only confirmed once the host marks the tab selected"
71
+ );
72
+ });
73
+
74
+ // The fallback overlay reuses the full MemoryExplorer (three columns, graph,
75
+ // settings) at viewport size — not the old side drawer — and closes on Esc
76
+ // or the close button.
77
+ test("hero fallback overlay is a full-viewport MemoryExplorer with a close affordance", () => {
78
+ assert.ok(
79
+ clientSource.includes('.mneme-overlay{position:fixed;inset:0'),
80
+ "the overlay must cover the full viewport"
81
+ );
82
+ assert.ok(
83
+ clientSource.includes('h(MemoryExplorer, { t })'),
84
+ "the overlay renders the same MemoryExplorer component as the tab"
85
+ );
86
+ assert.ok(
87
+ clientSource.includes('e.key === "Escape"'),
88
+ "Esc must close the overlay"
89
+ );
90
+ assert.ok(
91
+ clientSource.includes('"memory.overlay.close"'),
92
+ "the overlay ships a localized close label in both dictionaries"
93
+ );
94
+ });
95
+
96
+ // The sidebar hands each footer action only its column state: a wide row
97
+ // (icon + label) when expanded, a bare rail icon when collapsed.
98
+ test("trigger renders a wide row or a rail icon from the wide flag", () => {
99
+ assert.ok(
100
+ /wide \? "mneme-trigger" : "mneme-trigger mneme-rail"/.test(clientSource),
101
+ "trigger must branch on the wide flag"
102
+ );
103
+ assert.ok(
104
+ /wide && h\("span", \{ className: "mneme-trigger-label" \}/.test(clientSource),
105
+ "the label span must render only when wide"
106
+ );
107
+ });
108
+
109
+ // The full-width memory browser lives in the conversation view ring beside
110
+ // Chat / Trajectory, so the client must inject into `conversation.view` with
111
+ // a stable entry id (the active view is persisted by that id).
112
+ test("explorer registers into the conversation view ring", () => {
113
+ assert.ok(
114
+ clientSource.includes('ctx.slots.inject("conversation.view"'),
115
+ "client must inject into conversation.view"
116
+ );
117
+ assert.ok(
118
+ clientSource.includes('id: "dsh-mneme-memory"'),
119
+ "the view entry needs a stable, unique id"
120
+ );
121
+ assert.ok(
122
+ clientSource.includes('"memory.view.label"'),
123
+ "the tab label must come from the memory.view.label dictionary key"
124
+ );
125
+ });
126
+
127
+ // The graph toggle must not read as "share": the primitives share icon is
128
+ // banned and a custom node-graph glyph takes its place.
129
+ test("graph toggle uses a node-graph glyph, not the share icon", () => {
130
+ assert.equal(
131
+ clientSource.includes("IconShareOutline16"),
132
+ false,
133
+ "IconShareOutline16 reads as share and must not appear"
134
+ );
135
+ assert.ok(
136
+ clientSource.includes("GraphNodesIcon"),
137
+ "the custom node-graph icon must back the graph toggle"
138
+ );
139
+ });
140
+
141
+ // Every memory feature lives in the main-area library now: the explorer
142
+ // hosts three sub-views (browse / graph / settings) switched by tabs whose
143
+ // labels come from dedicated dictionary keys.
144
+ test("explorer hosts browse, graph and settings sub-views", () => {
145
+ for (const key of ["tabMemory", "tabGraph", "tabSettings"]) {
146
+ assert.ok(
147
+ clientSource.includes(`"memory.explorer.${key}"`),
148
+ `sub-view labels must come from memory.explorer.${key}`
149
+ );
150
+ }
151
+ assert.ok(
152
+ clientSource.includes('h(GraphPanel, { t, focusEntity: graphFocus, onJumpMemory: jumpToMemory })'),
153
+ "the graph panel must be embedded as a sub-view"
154
+ );
155
+ assert.ok(
156
+ clientSource.includes('h(SettingsContent, { t })'),
157
+ "the settings forms must be embedded as a sub-view"
158
+ );
159
+ });
160
+
161
+ // The graph panel jumps back into the browser: related-memory rows and the
162
+ // edge source button must land on the browse tab with the target selected.
163
+ test("graph jump lands on the selected memory in the browser", () => {
164
+ assert.ok(
165
+ /onClick: \(\) => onJumpMemory && onJumpMemory\(m\)/.test(clientSource),
166
+ "related-memory rows must jump via onJumpMemory(m)"
167
+ );
168
+ assert.ok(
169
+ clientSource.includes("onJumpMemory({ id: selected.edge.memory_id })"),
170
+ "the edge source button must jump to the origin memory by id"
171
+ );
172
+ assert.ok(
173
+ /const jumpToMemory = \(target\) => \{/.test(clientSource),
174
+ "jumpToMemory must reset filters and select the target"
175
+ );
176
+ });
177
+
178
+ // "entity:" in the browser search is the graph entry grammar: it must offer
179
+ // a jump chip instead of filtering the list.
180
+ test("entity: search grammar offers a graph jump", () => {
181
+ assert.ok(
182
+ clientSource.includes('query.trim().startsWith("entity:")'),
183
+ "the entity: prefix must be recognized"
184
+ );
185
+ assert.ok(
186
+ /onClick: \(\) => openGraphFor\(entityQuery\)/.test(clientSource),
187
+ "the jump chip must switch to the graph sub-view"
188
+ );
189
+ });
190
+
191
+ // The explorer is a three-pane layout: types with counts, a month→day time
192
+ // tree, and a detail pane rendering the untruncated content.
193
+ test("explorer lays out types, timeline, and full-text detail", () => {
194
+ assert.ok(
195
+ clientSource.includes('className: "mneme-xmain"'),
196
+ "the three-column grid must be present"
197
+ );
198
+ assert.ok(
199
+ clientSource.includes('className: "mneme-xdcontent"'),
200
+ "the detail pane must render the full content"
201
+ );
202
+ assert.ok(
203
+ /toLocaleDateString\(undefined, \{ year: "numeric", month: "long" \}\)/.test(clientSource),
204
+ "month groups must format via the host locale, not hardcoded strings"
205
+ );
206
+ });
207
+
208
+ // The library page must read as a first-party view: the chrome resolves to
209
+ // the host's design tokens (layer-1 canvas, brand-blue active states) and
210
+ // the boxed-panel / pill-chip patterns of the drawer era must stay gone.
211
+ test("explorer chrome aligns with the host design system", () => {
212
+ assert.ok(
213
+ clientSource.includes("background:var(--dsw-alias-bg-layer-1)"),
214
+ "the page canvas must sit on the host bg-layer-1 token"
215
+ );
216
+ assert.ok(
217
+ /\.mneme-vtab\.mneme-active::after/.test(clientSource),
218
+ "active sub-tabs use the host underline treatment"
219
+ );
220
+ assert.ok(
221
+ clientSource.includes(".mneme-vtab.mneme-active{color:var(--dsw-alias-state-business-primary)}"),
222
+ "active sub-tab text must turn the host brand blue"
223
+ );
224
+ assert.equal(
225
+ /\.mneme-xmain\{[^}]*border:1px/.test(clientSource),
226
+ false,
227
+ "the three-column layout must not wrap itself in a boxed panel"
228
+ );
229
+ assert.equal(
230
+ clientSource.includes("border-radius:999px"),
231
+ false,
232
+ "pill chips belong to the drawer era and must stay gone"
233
+ );
234
+ });
235
+
236
+ // The v0.6.1 wiki-link feature: the detail pane mounts a BacklinksPanel that
237
+ // fetches the two read-only link endpoints by the selected memory id and
238
+ // renders back/forward rows, each jumping back into the browser.
239
+ test("detail pane mounts a BacklinksPanel backed by the two link endpoints", () => {
240
+ assert.ok(
241
+ clientSource.includes("h(BacklinksPanel, { memory: selected, t, onJump: jumpToMemory })"),
242
+ "the detail pane must mount BacklinksPanel after the actions row"
243
+ );
244
+ assert.ok(
245
+ clientSource.includes("/api/dsh-mneme/wikilinks/backlinks?id="),
246
+ "BacklinksPanel must fetch the backlinks endpoint by memory id"
247
+ );
248
+ assert.ok(
249
+ clientSource.includes("/api/dsh-mneme/wikilinks/forward?id="),
250
+ "BacklinksPanel must fetch the forward-links endpoint by memory id"
251
+ );
252
+ });
253
+
254
+ // Detail content turns [[target]] / [[display|target]] into clickable links:
255
+ // the display text survives, the target title is kept for hover, and a click
256
+ // resolves the title through the resolve endpoint before jumping.
257
+ test("detail content renders wiki-links and resolves them on click", () => {
258
+ assert.ok(
259
+ clientSource.includes('className: "mneme-wikilink"'),
260
+ "inline [[target]] links must use the .mneme-wikilink style"
261
+ );
262
+ assert.ok(
263
+ clientSource.includes("/api/dsh-mneme/wikilinks/resolve?title="),
264
+ "clicking a wiki-link must resolve the title via the resolve endpoint"
265
+ );
266
+ assert.ok(
267
+ clientSource.includes('className: "mneme-backlinks"'),
268
+ "the panel must render inside a .mneme-backlinks block"
269
+ );
270
+ });
271
+
272
+ // v0.6.2 tag system: the detail pane renders tags as clickable chips wired to
273
+ // the memory/tags endpoints, and a tag: query always goes server-side.
274
+ test("detail pane renders editable tag chips backed by the tags endpoint", () => {
275
+ assert.ok(
276
+ clientSource.includes("/api/dsh-mneme/memory/tags?id="),
277
+ "the panel must fetch the selected memory's tags via the GET endpoint"
278
+ );
279
+ assert.ok(
280
+ clientSource.includes('method: "POST"'),
281
+ "adding/removing a tag must POST to the tags endpoint"
282
+ );
283
+ assert.ok(
284
+ clientSource.includes("onClick: () => onTagClick(tag)"),
285
+ "a tag chip click must trigger a tag: search"
286
+ );
287
+ assert.ok(
288
+ clientSource.includes("tagManual"),
289
+ "the panel must read the manualTagEnabled gate to hide editing"
290
+ );
291
+ });
292
+
293
+ test("tag: queries run server-side regardless of the semantic toggle", () => {
294
+ assert.ok(
295
+ clientSource.includes('(!semantic && !q.startsWith("tag:"))'),
296
+ "tag: must bypass the semantic toggle and use the search endpoint"
297
+ );
298
+ assert.ok(
299
+ clientSource.includes('setQuery(`tag:${tag}`)'),
300
+ "a tag chip click must set the query to tag:<tag>"
301
+ );
302
+ });
303
+
304
+ test("tag UI ships localized labels in both dictionaries", () => {
305
+ for (const key of ["tagAdd", "tagRemove", "tagPlaceholder", "tagsEmpty"]) {
306
+ assert.ok(
307
+ clientSource.includes(`"memory.explorer.${key}"`),
308
+ `memory.explorer.${key} key must exist`
309
+ );
310
+ }
311
+ });
312
+
313
+ // v0.6.3 directory view: a tag-folder tree backed by the directory endpoint.
314
+ // Folders accordion via data-expanded controlled by MemoryExplorer-lifted
315
+ // state; a memory entry click jumps back into the browser via onJump.
316
+ test("directory sub-view mounts DirectoryPanel backed by the directory endpoint", () => {
317
+ assert.ok(
318
+ clientSource.includes("h(DirectoryPanel, { t, onJump: jumpToMemory, collapsed: dirCollapsed, setCollapsed: setDirCollapsed })"),
319
+ "the directory panel must be embedded as a sub-view with lifted collapse state"
320
+ );
321
+ assert.ok(
322
+ clientSource.includes("/api/dsh-mneme/directory"),
323
+ "DirectoryPanel must fetch the directory endpoint"
324
+ );
325
+ assert.ok(
326
+ clientSource.includes('className: "mneme-directory"'),
327
+ "the directory panel must render inside the .mneme-directory block"
328
+ );
329
+ });
330
+
331
+ test("directory folders accordion via data-expanded driven by MemoryExplorer state", () => {
332
+ assert.ok(
333
+ clientSource.includes('"data-expanded": String(open)'),
334
+ "folder expansion must be driven by the data-expanded attribute"
335
+ );
336
+ assert.ok(
337
+ clientSource.includes("const [dirCollapsed, setDirCollapsed] = useState({})"),
338
+ "collapse state must live in MemoryExplorer so tab switches keep it"
339
+ );
340
+ assert.ok(
341
+ clientSource.includes('"aria-expanded": String(open)'),
342
+ "folder headers must announce their expanded state"
343
+ );
344
+ });
345
+
346
+ test("directory entry click jumps to the memory detail via onJump", () => {
347
+ assert.ok(
348
+ clientSource.includes("onClick: () => onJump(m)"),
349
+ "clicking a memory entry must call onJump with the memory"
350
+ );
351
+ assert.ok(
352
+ clientSource.includes("formatDate(m.updated_at || m.created_at)"),
353
+ "entries must render a timestamp via formatDate"
354
+ );
355
+ assert.ok(
356
+ clientSource.includes("memory.directory.untagged"),
357
+ "untagged memories must be bucketed under a labeled fallback folder"
358
+ );
359
+ });
360
+
361
+ test("directory ships localized labels in both dictionaries", () => {
362
+ for (const key of ["memory.explorer.tabDirectory", "memory.directory.untagged", "memory.directory.loading", "memory.directory.empty"]) {
363
+ assert.ok(
364
+ clientSource.includes(`"${key}"`),
365
+ `${key} key must exist`
366
+ );
367
+ }
368
+ });