@modusensus/dsh-mneme 0.6.9 → 0.6.10

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/LICENSE +21 -21
  2. package/README.md +468 -219
  3. package/{dsh-mneme/cordis.patch.yml → cordis.patch.yml} +15 -15
  4. package/{dsh-mneme/src → lib}/api.js +783 -783
  5. package/{dsh-mneme/lib → lib}/client.js +1754 -1757
  6. package/{dsh-mneme/src → lib}/commands.js +64 -64
  7. package/{dsh-mneme/lib → lib}/config.js +298 -298
  8. package/{dsh-mneme/lib → lib}/dream/clustering.js +118 -118
  9. package/{dsh-mneme/lib → lib}/dream/decisions.js +488 -488
  10. package/{dsh-mneme/lib → lib}/dream/sleep.js +561 -561
  11. package/{dsh-mneme/src → lib}/dream/tag-extractor.js +156 -156
  12. package/{dsh-mneme/lib → lib}/dream.js +958 -958
  13. package/{dsh-mneme/src → lib}/embedding.js +154 -154
  14. package/{dsh-mneme/src → lib}/entities/extractor.js +242 -242
  15. package/{dsh-mneme/lib → lib}/hot-memory.js +53 -53
  16. package/{dsh-mneme/lib → lib}/index.js +361 -361
  17. package/{dsh-mneme/src → lib}/inject.js +208 -208
  18. package/{dsh-mneme/lib → lib}/local-embedder.js +282 -282
  19. package/{dsh-mneme/lib → lib}/mirror.js +170 -170
  20. package/{dsh-mneme/lib → lib}/parser/tag.js +59 -59
  21. package/{dsh-mneme/lib → lib}/parser/wiki-link.js +38 -38
  22. package/{dsh-mneme/src → lib}/quality-filter.js +123 -123
  23. package/{dsh-mneme/lib → lib}/reranker.js +218 -218
  24. package/{dsh-mneme/src → lib}/search/adaptive.js +22 -22
  25. package/{dsh-mneme/src → lib}/search/bm25.js +96 -96
  26. package/{dsh-mneme/src → lib}/search/tag-boost.js +61 -61
  27. package/{dsh-mneme/src → lib}/service.js +1726 -1726
  28. package/{dsh-mneme/lib → lib}/settings.js +172 -172
  29. package/{dsh-mneme/src → lib}/store.js +2238 -2238
  30. package/{dsh-mneme/src → lib}/summarize.js +236 -236
  31. package/{dsh-mneme/lib → lib}/tools.js +290 -290
  32. package/{dsh-mneme/lib → lib}/vector-index.js +116 -116
  33. package/package.json +40 -18
  34. package/{dsh-mneme/scripts → scripts}/benchmark-embed.js +201 -201
  35. package/{dsh-mneme/scripts → scripts}/benchmark-recall.js +133 -133
  36. package/{dsh-mneme/scripts → scripts}/benchmark-rerank.js +166 -166
  37. package/{dsh-mneme/scripts → scripts}/e2e-dsh.js +218 -218
  38. package/{dsh-mneme/scripts → scripts}/stress-dsh.js +255 -255
  39. package/{dsh-mneme/scripts → scripts}/sync-lib.js +52 -52
  40. package/{dsh-mneme/lib → src}/api.js +783 -783
  41. package/{dsh-mneme/lib → src}/commands.js +64 -64
  42. package/{dsh-mneme/src → src}/config.js +298 -298
  43. package/{dsh-mneme/src → src}/dream/clustering.js +118 -118
  44. package/{dsh-mneme/src → src}/dream/decisions.js +488 -488
  45. package/{dsh-mneme/src → src}/dream/sleep.js +561 -561
  46. package/{dsh-mneme/lib → src}/dream/tag-extractor.js +156 -156
  47. package/{dsh-mneme/src → src}/dream.js +958 -958
  48. package/{dsh-mneme/lib → src}/embedding.js +154 -154
  49. package/{dsh-mneme/lib → src}/entities/extractor.js +242 -242
  50. package/{dsh-mneme/src → src}/hot-memory.js +53 -53
  51. package/{dsh-mneme/src → src}/index.js +361 -361
  52. package/{dsh-mneme/lib → src}/inject.js +208 -208
  53. package/{dsh-mneme/src → src}/local-embedder.js +282 -282
  54. package/{dsh-mneme/src → src}/mirror.js +170 -170
  55. package/{dsh-mneme/src → src}/parser/tag.js +59 -59
  56. package/{dsh-mneme/src → src}/parser/wiki-link.js +38 -38
  57. package/{dsh-mneme/lib → src}/quality-filter.js +123 -123
  58. package/{dsh-mneme/src → src}/reranker.js +218 -218
  59. package/{dsh-mneme/lib → src}/search/adaptive.js +22 -22
  60. package/{dsh-mneme/lib → src}/search/bm25.js +96 -96
  61. package/{dsh-mneme/lib → src}/search/tag-boost.js +61 -61
  62. package/{dsh-mneme/lib → src}/service.js +1726 -1726
  63. package/{dsh-mneme/src → src}/settings.js +172 -172
  64. package/{dsh-mneme/lib → src}/store.js +2238 -2238
  65. package/{dsh-mneme/lib → src}/summarize.js +236 -236
  66. package/{dsh-mneme/src → src}/tools.js +290 -290
  67. package/{dsh-mneme/src → src}/vector-index.js +116 -116
  68. package/{dsh-mneme/test → test}/api.test.js +594 -594
  69. package/{dsh-mneme/test → test}/audit.test.js +448 -448
  70. package/{dsh-mneme/test → test}/benchmark.test.js +35 -35
  71. package/{dsh-mneme/test → test}/boundary-v0625.test.js +82 -82
  72. package/{dsh-mneme/test → test}/client.test.js +368 -368
  73. package/{dsh-mneme/test → test}/clustering.test.js +100 -100
  74. package/{dsh-mneme/test → test}/commands.test.js +69 -69
  75. package/{dsh-mneme/test → test}/config.test.js +50 -50
  76. package/{dsh-mneme/test → test}/conflict-freeze.test.js +290 -290
  77. package/{dsh-mneme/test → test}/directory.test.js +134 -134
  78. package/{dsh-mneme/test → test}/dream.test.js +1060 -1060
  79. package/{dsh-mneme/test → test}/entities.test.js +522 -522
  80. package/{dsh-mneme/test → test}/epistemic.test.js +298 -298
  81. package/{dsh-mneme/test → test}/fnew-0112.test.js +311 -311
  82. package/{dsh-mneme/test → test}/fnew-03.test.js +422 -422
  83. package/{dsh-mneme/test → test}/graph-api.test.js +175 -175
  84. package/{dsh-mneme/test → test}/helpers/dream-mock.js +82 -82
  85. package/{dsh-mneme/test → test}/hot-memory.test.js +174 -174
  86. package/{dsh-mneme/test → test}/inject.test.js +103 -103
  87. package/{dsh-mneme/test → test}/llm-audit.test.js +279 -279
  88. package/{dsh-mneme/test → test}/local-embedder.test.js +227 -227
  89. package/{dsh-mneme/test → test}/mirror-dirty.test.js +424 -424
  90. package/{dsh-mneme/test → test}/mirror-edit-digest.test.js +187 -187
  91. package/{dsh-mneme/test → test}/mirror-generation.test.js +499 -499
  92. package/{dsh-mneme/test → test}/mirror.test.js +249 -249
  93. package/{dsh-mneme/test → test}/normalize-decisions.test.js +120 -120
  94. package/{dsh-mneme/test → test}/peer-blockers.test.js +190 -190
  95. package/{dsh-mneme/test → test}/policy-epoch.test.js +259 -259
  96. package/{dsh-mneme/test → test}/provenance.test.js +103 -103
  97. package/{dsh-mneme/test → test}/quality-filter.test.js +118 -118
  98. package/{dsh-mneme/test → test}/reasoning-effort.test.js +199 -199
  99. package/{dsh-mneme/test → test}/recall-evals.test.js +235 -235
  100. package/{dsh-mneme/test → test}/recall-layer.test.js +315 -315
  101. package/{dsh-mneme/test → test}/receipt-chain.test.js +451 -451
  102. package/{dsh-mneme/test → test}/reflection.test.js +226 -226
  103. package/{dsh-mneme/test → test}/reranker.test.js +240 -240
  104. package/{dsh-mneme/test → test}/search-fusion.test.js +90 -90
  105. package/{dsh-mneme/test → test}/semantic.test.js +124 -124
  106. package/{dsh-mneme/test → test}/service-search.test.js +199 -199
  107. package/{dsh-mneme/test → test}/service.test.js +435 -435
  108. package/{dsh-mneme/test → test}/settings.test.js +118 -118
  109. package/{dsh-mneme/test → test}/sleep.test.js +365 -365
  110. package/{dsh-mneme/test → test}/store.test.js +436 -436
  111. package/{dsh-mneme/test → test}/stress.test.js +209 -209
  112. package/{dsh-mneme/test → test}/summarize.test.js +191 -191
  113. package/{dsh-mneme/test → test}/tag-boost.test.js +125 -125
  114. package/{dsh-mneme/test → test}/tag.test.js +312 -312
  115. package/{dsh-mneme/test → test}/tools.test.js +285 -285
  116. package/{dsh-mneme/test → test}/vector-index.test.js +221 -221
  117. package/{dsh-mneme/test → test}/wiki-link.test.js +332 -332
  118. package/.github/workflows/test.yml +0 -32
  119. package/.release-notes-v0.6.9.md +0 -13
  120. package/CHANGELOG.md +0 -89
  121. package/SECURITY.md +0 -544
  122. package/docs/devlog/2026-08-14-dsh-mneme-dev-log.md +0 -247
  123. package/docs/devlog/2026-08-15-dsh-mneme-audit-stress-dev-log.md +0 -145
  124. package/docs/devlog/2026-08-15-dsh-mneme-pipeline-dev-log.md +0 -56
  125. package/docs/devlog/2026-08-15-dsh-mneme-reflection-dev-log.md +0 -77
  126. package/docs/devlog/2026-08-15-dsh-mneme-review-fixes-dev-log.md +0 -64
  127. package/docs/devlog/2026-08-15-dsh-mneme-semantic-dev-log.md +0 -90
  128. package/dsh-mneme/CHANGELOG.md +0 -248
  129. package/dsh-mneme/LICENSE +0 -21
  130. package/dsh-mneme/README.md +0 -465
  131. package/dsh-mneme/docs/AGENT_MEMORY_RESEARCH.md +0 -183
  132. package/dsh-mneme/docs/ENTITIES.md +0 -245
  133. package/dsh-mneme/docs/LOCAL_MODEL.md +0 -141
  134. package/dsh-mneme/docs/MIGRATION.md +0 -127
  135. package/dsh-mneme/docs/SEMANTIC.md +0 -256
  136. package/dsh-mneme/docs/SLEEP.md +0 -163
  137. package/dsh-mneme/package-lock.json +0 -1936
  138. package/dsh-mneme/package.json +0 -80
  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
+ });