dsh-memvault 0.9.12 → 0.10.1
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.
- package/README.md +52 -397
- package/README.zh.md +51 -325
- package/cordis.patch.yml +18 -20
- package/docs/CORE-DESIGN.md +277 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/DEVLOG.md +752 -0
- package/docs/images/relation-graph-2026-11-02.png +0 -0
- package/docs/preview.svg +41 -0
- package/icon.svg +9 -0
- package/lib/blocks.js +11 -2
- package/lib/client.js +705 -168
- package/lib/config.js +46 -87
- package/lib/core/adjudicate.js +94 -0
- package/lib/core/backfill.js +32 -0
- package/lib/core/block-write.js +85 -0
- package/lib/core/decide.js +159 -0
- package/lib/core/embed.js +122 -0
- package/lib/core/env.js +72 -0
- package/lib/core/extract.js +151 -0
- package/lib/core/host.js +81 -0
- package/lib/core/importers.js +261 -0
- package/lib/core/llm.js +49 -0
- package/lib/{memories.js → core/panel-read.js} +80 -136
- package/lib/core/pipeline.js +95 -0
- package/lib/core/schema.js +123 -0
- package/lib/core/search.js +191 -0
- package/lib/core/store.js +347 -0
- package/lib/core/tools.js +182 -0
- package/lib/core/write.js +89 -0
- package/lib/extract.js +1 -39
- package/lib/index.js +194 -128
- package/lib/panel.js +13 -11
- package/lib/review.js +5 -1
- package/lib/structure.js +6 -1
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +11 -8
- package/scripts/backfill-core.mjs +53 -0
- package/scripts/import-core.mjs +56 -0
- package/scripts/smoke-config.mjs +12 -14
- package/scripts/smoke-extract.mjs +19 -40
- package/scripts/smoke-package.mjs +105 -27
- package/scripts/smoke-panel.mjs +293 -162
- package/src/client/index.js +703 -166
- package/lib/blocks-write.js +0 -121
- package/lib/cli.js +0 -90
- package/lib/reindex.js +0 -32
package/lib/review.js
CHANGED
|
@@ -90,11 +90,15 @@ export function pruneInputs(inputs = {}) {
|
|
|
90
90
|
*/
|
|
91
91
|
export function recordProduced(index = {}, entries = [], meta = {}) {
|
|
92
92
|
const next = { ...pruneProduced(index) }
|
|
93
|
+
// One timestamp for the whole batch: they were produced by the same extraction,
|
|
94
|
+
// and per-entry `new Date()` calls made the ordering (and therefore the key
|
|
95
|
+
// order after pruning) depend on the millisecond the loop happened to reach.
|
|
96
|
+
const at = meta.at ?? new Date().toISOString()
|
|
93
97
|
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
94
98
|
const id = typeof entry?.id === 'string' ? entry.id : null
|
|
95
99
|
if (id === null) continue
|
|
96
100
|
next[id] = {
|
|
97
|
-
at
|
|
101
|
+
at,
|
|
98
102
|
seq: meta.seq ?? null,
|
|
99
103
|
sessionId: meta.sessionId ?? null,
|
|
100
104
|
inputKey: meta.inputKey ?? null,
|
package/lib/structure.js
CHANGED
|
@@ -70,6 +70,11 @@ export function buildStructure({
|
|
|
70
70
|
// must say "nothing written yet" instead of surfacing a SQL error.
|
|
71
71
|
const tables = new Set(db.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all().map((row) => row.name))
|
|
72
72
|
if (!tables.has('memories')) return blank
|
|
73
|
+
// Two schemas are in the wild during the migration: the old engine's
|
|
74
|
+
// `memories.memory` and the in-plugin store's `memories.text`. Read whichever
|
|
75
|
+
// this file has instead of assuming one of them.
|
|
76
|
+
const memoryColumns = new Set(db.prepare('PRAGMA table_info(memories)').all().map((row) => row.name))
|
|
77
|
+
const textColumn = memoryColumns.has('text') ? 'text' : 'memory'
|
|
73
78
|
|
|
74
79
|
const injected = new Set(injectedScopes)
|
|
75
80
|
const totals = { memories: 0, byType: emptyByType(), flagged: 0, retyped: retypedCount, blocks: 0, injectedBlocks: 0 }
|
|
@@ -127,7 +132,7 @@ export function buildStructure({
|
|
|
127
132
|
if (nodeIds.length > 0) {
|
|
128
133
|
const placeholders = nodeIds.map(() => '?').join(', ')
|
|
129
134
|
for (const row of db.prepare(
|
|
130
|
-
`SELECT id, memory, memory_type, user_id, agent_id, metadata FROM memories WHERE id IN (${placeholders})`,
|
|
135
|
+
`SELECT id, ${textColumn} AS memory, memory_type, user_id, agent_id, metadata FROM memories WHERE id IN (${placeholders})`,
|
|
131
136
|
).all(...nodeIds)) {
|
|
132
137
|
nodes.set(row.id, {
|
|
133
138
|
id: row.id,
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "MemVault memory bridge",
|
|
4
|
+
"description": "Puts MemVault's core memory blocks into the system prompt, turns finished conversation windows into stored memories, and adds a memory panel for browsing, review and replay. It also registers memory_search and memory_add, which read and write the same local SQLite store. Everything stays on this machine: without an API key in the MemVault .env, extraction uses offline rules and an offline embedder. Turning the plugin off removes the injection, both tools and the panel.",
|
|
5
|
+
"detail": "docs/DETAIL.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"title": "MemVault 记忆桥",
|
|
4
|
+
"description": "把 MemVault 的核心记忆块注入 system prompt,把收尾后的整窗对话抽取成记忆,并提供可浏览、复核、重抽的记忆面板;同时注册 memory_search 与 memory_add 两个工具,读写同一个本地 SQLite 库。数据全部在本机:MemVault 的 .env 里没有 key 时,抽取走离线规则、嵌入走离线哈希。关闭本插件会同时移除注入、两个工具与面板。",
|
|
5
|
+
"detail": "docs/DETAIL.zh.md"
|
|
6
|
+
}
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-memvault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "DeepSeek Harness plugin: inject MemVault core memory blocks into the system prompt, extract finished turns as one windowed pass, and show, edit, trace, review and replay all of it in a memory panel",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
"./client": "./lib/client.js",
|
|
10
10
|
"./blocks": "./lib/blocks.js",
|
|
11
11
|
"./flags": "./lib/flags.js",
|
|
12
|
-
"./memories": "./lib/memories.js",
|
|
13
12
|
"./panel": "./lib/panel.js",
|
|
14
13
|
"./review": "./lib/review.js",
|
|
14
|
+
"./locale/*.json": "./locale/*.json",
|
|
15
|
+
"./icon": "./icon.svg",
|
|
15
16
|
"./package.json": "./package.json"
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
@@ -19,6 +20,8 @@
|
|
|
19
20
|
"src",
|
|
20
21
|
"scripts",
|
|
21
22
|
"docs",
|
|
23
|
+
"locale",
|
|
24
|
+
"icon.svg",
|
|
22
25
|
"cordis.patch.yml",
|
|
23
26
|
"README.md",
|
|
24
27
|
"README.zh.md",
|
|
@@ -30,9 +33,10 @@
|
|
|
30
33
|
"smoke:config": "node scripts/smoke-config.mjs",
|
|
31
34
|
"smoke:extract": "node scripts/smoke-extract.mjs",
|
|
32
35
|
"smoke:panel": "node scripts/smoke-panel.mjs",
|
|
33
|
-
|
|
36
|
+
"smoke:panel-routes": "node scripts/smoke-panel-routes.mjs",
|
|
34
37
|
"smoke:package": "node scripts/smoke-package.mjs",
|
|
35
|
-
"test": "node
|
|
38
|
+
"test:core": "node --test \"test/**/*.test.mjs\"",
|
|
39
|
+
"test": "node scripts/smoke-package.mjs && node scripts/smoke-config.mjs && node scripts/smoke.mjs && node scripts/smoke-extract.mjs && node scripts/smoke-panel.mjs && node scripts/smoke-panel-routes.mjs && node --test \"test/**/*.test.mjs\""
|
|
36
40
|
},
|
|
37
41
|
"repository": {
|
|
38
42
|
"type": "git",
|
|
@@ -54,8 +58,8 @@
|
|
|
54
58
|
"panel"
|
|
55
59
|
],
|
|
56
60
|
"engines": {
|
|
57
|
-
"node": ">=
|
|
58
|
-
"dsh": ">=0.
|
|
61
|
+
"node": ">=24.9.0",
|
|
62
|
+
"dsh": ">=0.2.1-0 <0.3.0-0 || >=0.2.2-0 <0.3.0-0"
|
|
59
63
|
},
|
|
60
64
|
"dsh": {
|
|
61
65
|
"manifestVersion": 1,
|
|
@@ -67,8 +71,7 @@
|
|
|
67
71
|
}
|
|
68
72
|
},
|
|
69
73
|
"peerDependencies": {
|
|
70
|
-
"@deepseek-ai/dsh-system-prompt": ">=0.
|
|
71
|
-
"@deepseek-ai/dsh-client-ui-slots": ">=0.1.0-rc.1 <0.2.0-0 || >=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-0 <0.3.0-0",
|
|
74
|
+
"@deepseek-ai/dsh-system-prompt": ">=0.2.1-0 <0.3.0-0 || >=0.2.2-0 <0.3.0-0",
|
|
72
75
|
"@deepseek-ai/schemastery": "^3.18.0"
|
|
73
76
|
},
|
|
74
77
|
"license": "MIT"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backfill the in-plugin store with embeddings for the selected model.
|
|
3
|
+
*
|
|
4
|
+
* node scripts/backfill-core.mjs <db-path> [--project-dir <dir>] [--batch 32] [--apply]
|
|
5
|
+
*
|
|
6
|
+
* The embedder is resolved exactly like the plugin resolves it at runtime: the
|
|
7
|
+
* project `.env` (or real environment) selects the OpenAI-compatible endpoint
|
|
8
|
+
* when `OPENAI_API_KEY` is set, otherwise the offline hashing embedder. Dry-run
|
|
9
|
+
* by default — it reports how many rows are missing a vector without spending a
|
|
10
|
+
* single embedding call.
|
|
11
|
+
*/
|
|
12
|
+
import { resolveEmbedder } from '../lib/core/env.js'
|
|
13
|
+
import { backfillEmbeddings } from '../lib/core/backfill.js'
|
|
14
|
+
import { CoreStore } from '../lib/core/store.js'
|
|
15
|
+
|
|
16
|
+
const args = process.argv.slice(2)
|
|
17
|
+
const dbPath = args[0]
|
|
18
|
+
const flag = (name) => {
|
|
19
|
+
const index = args.indexOf(name)
|
|
20
|
+
return index === -1 ? null : args[index + 1] ?? null
|
|
21
|
+
}
|
|
22
|
+
const apply = args.includes('--apply')
|
|
23
|
+
const batchSize = Number(flag('--batch') ?? 32)
|
|
24
|
+
|
|
25
|
+
if (!dbPath || dbPath.startsWith('--')) {
|
|
26
|
+
console.error('usage: node scripts/backfill-core.mjs <db-path> [--project-dir <dir>] [--batch 32] [--apply]')
|
|
27
|
+
process.exit(2)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const embedder = resolveEmbedder({
|
|
31
|
+
projectDir: flag('--project-dir') ?? '',
|
|
32
|
+
dbPath,
|
|
33
|
+
})
|
|
34
|
+
const store = new CoreStore(dbPath)
|
|
35
|
+
try {
|
|
36
|
+
const missing = store.db.prepare(`
|
|
37
|
+
SELECT COUNT(*) AS n FROM memories
|
|
38
|
+
WHERE id NOT IN (SELECT memory_id FROM memory_embeddings WHERE model = ?)
|
|
39
|
+
`).get(embedder.model).n
|
|
40
|
+
|
|
41
|
+
if (!apply) {
|
|
42
|
+
console.log(JSON.stringify({ db: dbPath, model: embedder.model, missing, applied: false }, null, 2))
|
|
43
|
+
process.exit(0)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const report = await backfillEmbeddings(store, embedder, {
|
|
47
|
+
batchSize,
|
|
48
|
+
onBatch: ({ done, total }) => console.error(` embedded ${done}/${total}`),
|
|
49
|
+
})
|
|
50
|
+
console.log(JSON.stringify({ db: dbPath, ...report, stats: store.stats(), applied: true }, null, 2))
|
|
51
|
+
} finally {
|
|
52
|
+
store.close()
|
|
53
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import a `memvault-export` JSON into the in-plugin store.
|
|
3
|
+
*
|
|
4
|
+
* node scripts/import-core.mjs <export.json> <db-path> [--apply]
|
|
5
|
+
*
|
|
6
|
+
* Dry-run by default: it reports how many memories/blocks/relations would be
|
|
7
|
+
* added and the store's current size. `--apply` performs the import, which is
|
|
8
|
+
* idempotent by memory id — running it twice skips what is already there.
|
|
9
|
+
*
|
|
10
|
+
* This is the operational half of the migration: the Python store is exported
|
|
11
|
+
* once (`memvault export`), imported here, and then retired.
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, statSync } from 'node:fs'
|
|
14
|
+
|
|
15
|
+
import { importMemvaultExport } from '../lib/core/importers.js'
|
|
16
|
+
import { CoreStore } from '../lib/core/store.js'
|
|
17
|
+
|
|
18
|
+
const [exportPath, dbPath, ...flags] = process.argv.slice(2)
|
|
19
|
+
if (!exportPath || !dbPath) {
|
|
20
|
+
console.error('usage: node scripts/import-core.mjs <export.json> <db-path> [--apply]')
|
|
21
|
+
process.exit(2)
|
|
22
|
+
}
|
|
23
|
+
const apply = flags.includes('--apply')
|
|
24
|
+
const payload = JSON.parse(readFileSync(exportPath, 'utf8'))
|
|
25
|
+
if (payload.format !== 'memvault-export') {
|
|
26
|
+
console.error(`not a memvault-export payload: ${payload.format ?? '(no format)'}`)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const store = new CoreStore(dbPath)
|
|
31
|
+
try {
|
|
32
|
+
const before = store.stats()
|
|
33
|
+
const existing = new Set(store.currentMemories({ limit: 1_000_000 }).map((memory) => memory.id))
|
|
34
|
+
const wouldAdd = (payload.memories ?? []).filter((memory) => !existing.has(memory.id)).length
|
|
35
|
+
const summary = {
|
|
36
|
+
export: {
|
|
37
|
+
path: exportPath,
|
|
38
|
+
bytes: statSync(exportPath).size,
|
|
39
|
+
memories: payload.memories?.length ?? 0,
|
|
40
|
+
blocks: payload.blocks?.length ?? 0,
|
|
41
|
+
relations: payload.relations?.length ?? 0,
|
|
42
|
+
},
|
|
43
|
+
store: { path: dbPath, before },
|
|
44
|
+
wouldAdd,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!apply) {
|
|
48
|
+
console.log(JSON.stringify({ ...summary, applied: false }, null, 2))
|
|
49
|
+
process.exit(0)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const report = importMemvaultExport(store, payload)
|
|
53
|
+
console.log(JSON.stringify({ ...summary, applied: true, report, after: store.stats() }, null, 2))
|
|
54
|
+
} finally {
|
|
55
|
+
store.close()
|
|
56
|
+
}
|
package/scripts/smoke-config.mjs
CHANGED
|
@@ -19,7 +19,6 @@ import { DEFAULT_STATE_PATH } from '../lib/extract.js'
|
|
|
19
19
|
import {
|
|
20
20
|
CONFIG_SPEC,
|
|
21
21
|
MEMVAULT_DIR,
|
|
22
|
-
MEMVAULT_PYTHON,
|
|
23
22
|
configDefaults,
|
|
24
23
|
resolveConfig,
|
|
25
24
|
} from '../lib/config.js'
|
|
@@ -45,8 +44,6 @@ const defaults = configDefaults()
|
|
|
45
44
|
defaults.enabled === true && defaults.name === 'memvault:core' && defaults.order === 210
|
|
46
45
|
&& defaults.maxChars === 4000 && defaults.refreshMs === 30000 && defaults.panel.writes === true,
|
|
47
46
|
JSON.stringify({ name: defaults.name, maxChars: defaults.maxChars }))
|
|
48
|
-
check('the spec default for dbPath is the env-aware one from blocks.js',
|
|
49
|
-
defaults.dbPath === DEFAULT_DB_PATH, String(defaults.dbPath))
|
|
50
47
|
check('the spec defaults for scopes are the reader defaults',
|
|
51
48
|
same(defaults.scopes, DEFAULT_SCOPES), JSON.stringify(defaults.scopes))
|
|
52
49
|
check('the spec default for statePath is the storage path from extract.js',
|
|
@@ -54,10 +51,14 @@ const defaults = configDefaults()
|
|
|
54
51
|
check('the extraction defaults come from the spec with the window policy',
|
|
55
52
|
defaults.extract.everyNTurns === 3 && defaults.extract.idleMs === 20000
|
|
56
53
|
&& defaults.extract.windowTurns === 8 && defaults.extract.endReasons.join(',') === 'completed,max-tokens'
|
|
57
|
-
&& defaults.extract.env
|
|
54
|
+
&& same(defaults.extract.env, {}),
|
|
58
55
|
JSON.stringify({ ...defaults.extract, env: undefined }))
|
|
59
|
-
check('the portability
|
|
60
|
-
defaults.extract.
|
|
56
|
+
check('the portability default for projectDir is the discovered .env directory',
|
|
57
|
+
defaults.extract.projectDir === MEMVAULT_DIR, String(defaults.extract.projectDir))
|
|
58
|
+
check('the Python-era keys are gone from the spec',
|
|
59
|
+
!Object.hasOwn(CONFIG_SPEC, 'dbPath') && !Object.hasOwn(CONFIG_SPEC.extract.fields, 'pythonPath')
|
|
60
|
+
&& !Object.hasOwn(CONFIG_SPEC.extract.fields, 'user') && !Object.hasOwn(CONFIG_SPEC.extract.fields, 'agent')
|
|
61
|
+
&& !Object.hasOwn(CONFIG_SPEC.extract.fields, 'run'))
|
|
61
62
|
|
|
62
63
|
check('DEFAULT_EXTRACT is exactly the spec default (no second copy)',
|
|
63
64
|
same(DEFAULT_EXTRACT, defaults.extract))
|
|
@@ -137,9 +138,9 @@ const defaults = configDefaults()
|
|
|
137
138
|
same(env.config.extract.env, { PYTHONUTF8: '1' }) && env.problems.some((p) => p.includes('extract.env.BAD')),
|
|
138
139
|
env.problems.join('; '))
|
|
139
140
|
|
|
140
|
-
const nullable = resolveConfig({ extract: {
|
|
141
|
-
check('null means "not set", so the default stands
|
|
142
|
-
nullable.config.extract.
|
|
141
|
+
const nullable = resolveConfig({ extract: { minTranscriptChars: null } })
|
|
142
|
+
check('null means "not set", so the default stands',
|
|
143
|
+
nullable.config.extract.minTranscriptChars === defaults.extract.minTranscriptChars && same(nullable.config, defaults))
|
|
143
144
|
|
|
144
145
|
const reasons = resolveConfig({ extract: { endReasons: ['completed'] } })
|
|
145
146
|
check('an array field is replaced wholesale', same(reasons.config.extract.endReasons, ['completed']))
|
|
@@ -147,7 +148,6 @@ const defaults = configDefaults()
|
|
|
147
148
|
// The shape the shipped patch actually uses — keeping this green is what stops
|
|
148
149
|
// the patch and the spec from drifting apart.
|
|
149
150
|
const patchShaped = {
|
|
150
|
-
dbPath: 'D:/Claude_code/memory/data/memvault.db',
|
|
151
151
|
scopes: [{ type: 'user', id: 'lenovo' }, { type: 'agent', id: 'claude-code-memory' }],
|
|
152
152
|
labels: [],
|
|
153
153
|
maxChars: 4000,
|
|
@@ -162,11 +162,9 @@ const defaults = configDefaults()
|
|
|
162
162
|
includeTools: false,
|
|
163
163
|
maxInputChars: 6000,
|
|
164
164
|
minTranscriptChars: 40,
|
|
165
|
-
timeoutMs:
|
|
166
|
-
pythonPath: 'D:/Claude_code/memory/.venv/Scripts/python.exe',
|
|
165
|
+
timeoutMs: 60000,
|
|
167
166
|
projectDir: 'D:/Claude_code/memory',
|
|
168
|
-
|
|
169
|
-
agent: 'claude-code-memory',
|
|
167
|
+
env: {},
|
|
170
168
|
},
|
|
171
169
|
}
|
|
172
170
|
const fromPatch = resolveConfig(patchShaped)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Smoke test for the extraction half: transcript rendering, the watermark store,
|
|
3
|
-
* and a REAL end-to-end write through the
|
|
3
|
+
* and a REAL end-to-end write through the in-plugin core pipeline.
|
|
4
4
|
*
|
|
5
5
|
* node scripts/smoke-extract.mjs
|
|
6
6
|
*
|
|
@@ -13,17 +13,16 @@ import { mkdtempSync, rmSync } from 'node:fs'
|
|
|
13
13
|
import { tmpdir } from 'node:os'
|
|
14
14
|
import { join } from 'node:path'
|
|
15
15
|
import {
|
|
16
|
-
buildAddInvocation,
|
|
17
16
|
createEventBuffer,
|
|
18
17
|
loadState,
|
|
19
18
|
loadWatermarks,
|
|
20
19
|
renderTranscript,
|
|
21
|
-
runExtraction,
|
|
22
20
|
saveState,
|
|
23
21
|
saveWatermarks,
|
|
24
22
|
turnSpanByBoundary,
|
|
25
23
|
} from '../lib/extract.js'
|
|
26
|
-
import {
|
|
24
|
+
import { CoreStore } from '../lib/core/store.js'
|
|
25
|
+
import { buildPipeline, runCoreExtraction } from '../lib/core/pipeline.js'
|
|
27
26
|
import { DEFAULT_WINDOW, createTurnWindow } from '../lib/window.js'
|
|
28
27
|
|
|
29
28
|
const failures = []
|
|
@@ -158,51 +157,31 @@ try {
|
|
|
158
157
|
return Object.keys(loadState(statePath).flags).length === 0
|
|
159
158
|
})())
|
|
160
159
|
|
|
161
|
-
// ──
|
|
162
|
-
const inv = buildAddInvocation({ pythonPath: 'py.exe', projectDir: 'D:/x', user: 'u', agent: 'a' })
|
|
163
|
-
check('invocation uses add --stdin with scope flags',
|
|
164
|
-
inv.args.join(' ') === '-m memvault.cli add --stdin --user u --agent a' && inv.cwd === 'D:/x',
|
|
165
|
-
inv.args.join(' '))
|
|
166
|
-
|
|
167
|
-
// ── REAL end-to-end write, throwaway db ────────────────────────────────────
|
|
160
|
+
// ── REAL end-to-end write through the core pipeline, throwaway db ──────────
|
|
168
161
|
const dbPath = join(dir, 'e2e.db')
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
},
|
|
162
|
+
const store = new CoreStore(dbPath)
|
|
163
|
+
const pipeline = buildPipeline({
|
|
164
|
+
env: { MEMVAULT_EXTRACTOR: 'rule', MEMVAULT_EMBEDDER: 'local', OPENAI_API_KEY: '' },
|
|
165
|
+
dbPath,
|
|
166
|
+
})
|
|
167
|
+
const result = await runCoreExtraction({
|
|
168
|
+
store,
|
|
169
|
+
extractor: pipeline.extractor,
|
|
170
|
+
embedder: pipeline.embedder,
|
|
171
|
+
scope: { userId: 'u', agentId: 'a' },
|
|
180
172
|
messages: [{ role: 'user', content: rendered }],
|
|
181
173
|
})
|
|
182
174
|
console.log('extraction result:', JSON.stringify(result))
|
|
183
175
|
check('extraction reports success', result.ok === true, result.error ?? '')
|
|
184
176
|
check('extraction wrote memories', (result.added ?? 0) >= 1, `added=${result.added}`)
|
|
185
177
|
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
console.log('rows written:', JSON.stringify(rows.map((r) => r.memory)))
|
|
190
|
-
check('the fact landed in the store', rows.some((r) => r.memory.includes('喜欢吃辣')))
|
|
178
|
+
const rows = store.db.prepare('SELECT text FROM memories').all()
|
|
179
|
+
console.log('rows written:', JSON.stringify(rows.map((r) => r.text)))
|
|
180
|
+
check('the fact landed in the store', rows.some((r) => r.text.includes('喜欢吃辣')))
|
|
191
181
|
check('rows carry an embedding (pipeline ran, not a raw insert)',
|
|
192
|
-
(()
|
|
193
|
-
|
|
194
|
-
const n = d.prepare('SELECT COUNT(*) c FROM memories WHERE embedding IS NOT NULL').get().c
|
|
195
|
-
d.close()
|
|
196
|
-
return n >= 1
|
|
197
|
-
})())
|
|
182
|
+
store.db.prepare('SELECT COUNT(*) c FROM memory_embeddings').get().c >= 1)
|
|
183
|
+
store.close()
|
|
198
184
|
|
|
199
|
-
// ── failure path ───────────────────────────────────────────────────────────
|
|
200
|
-
const bad = await runExtraction({
|
|
201
|
-
config: { ...DEFAULT_EXTRACT, pythonPath: 'D:/nonexistent/python.exe', timeoutMs: 5000, env: {} },
|
|
202
|
-
messages: [{ role: 'user', content: 'x' }],
|
|
203
|
-
})
|
|
204
|
-
check('a broken python path fails soft, never throws', bad.ok === false && typeof bad.error === 'string',
|
|
205
|
-
bad.error?.slice(0, 60) ?? '')
|
|
206
185
|
} finally {
|
|
207
186
|
rmSync(dir, { recursive: true, force: true })
|
|
208
187
|
}
|
|
@@ -17,13 +17,16 @@
|
|
|
17
17
|
* checked, and a missing declaration imposes no constraint at all — so the
|
|
18
18
|
* declarations that exist are checked for the right package family.
|
|
19
19
|
* - `engines.dsh` decides alone when present, so it must agree with every DSH
|
|
20
|
-
* peer, and the range must cover the 0.2.1
|
|
21
|
-
* that do not pass `includePrerelease`.
|
|
20
|
+
* peer, and the range must cover the 0.2.1 and the whole 0.2.2 pre-release
|
|
21
|
+
* lines (rc.1 … rc.5) for readers that do not pass `includePrerelease`.
|
|
22
|
+
* - `engines.node` names the floor the verified DSH release itself enforces
|
|
23
|
+
* (Node 24.9), which is also the first line with `DatabaseSync` timeouts.
|
|
22
24
|
* - `files[]` names real paths, otherwise a published tarball silently lacks
|
|
23
25
|
* the patch or the docs.
|
|
24
26
|
*/
|
|
25
27
|
import { readFileSync, existsSync, mkdtempSync, writeFileSync } from 'node:fs'
|
|
26
|
-
import {
|
|
28
|
+
import { createRequire } from 'node:module'
|
|
29
|
+
import { homedir, tmpdir } from 'node:os'
|
|
27
30
|
import { dirname, join, resolve } from 'node:path'
|
|
28
31
|
import { fileURLToPath } from 'node:url'
|
|
29
32
|
|
|
@@ -33,6 +36,9 @@ function check(label, ok, detail = '') {
|
|
|
33
36
|
console.log(` [${ok ? 'PASS' : 'FAIL'}] ${label}${detail ? ` -- ${detail}` : ''}`)
|
|
34
37
|
if (!ok) failures.push(label)
|
|
35
38
|
}
|
|
39
|
+
function skip(label, reason) {
|
|
40
|
+
console.log(` [SKIP] ${label} -- ${reason}`)
|
|
41
|
+
}
|
|
36
42
|
|
|
37
43
|
const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
|
38
44
|
|
|
@@ -44,7 +50,11 @@ check('type is module (the plugin is plain ESM)', pkg.type === 'module')
|
|
|
44
50
|
check('main points at a real file', existsSync(join(root, pkg.main ?? '')), pkg.main)
|
|
45
51
|
check('every exports target exists',
|
|
46
52
|
Object.values(pkg.exports ?? {}).filter((v) => typeof v === 'string' && v.startsWith('.'))
|
|
47
|
-
|
|
53
|
+
// A wildcard export is a pattern, not a path: at least one file must match, or
|
|
54
|
+
// the locale/icon resource the Plugin Manager reads is silently absent.
|
|
55
|
+
.every((v) => v.includes('*')
|
|
56
|
+
? existsSync(join(root, v.split('*')[0]))
|
|
57
|
+
: existsSync(join(root, v)) || v === './package.json'))
|
|
48
58
|
check('declares no runtime dependencies (node: builtins only)',
|
|
49
59
|
Object.keys(pkg.dependencies ?? {}).length === 0)
|
|
50
60
|
check('every files[] entry exists', (pkg.files ?? []).every((f) => existsSync(join(root, f))),
|
|
@@ -120,6 +130,46 @@ check('every DSH peer declares the same host range as engines.dsh',
|
|
|
120
130
|
dshPeers.length > 0 && dshPeers.every(([, range]) => range === DSH_RANGE),
|
|
121
131
|
dshPeers.map(([name]) => name).join(', '))
|
|
122
132
|
|
|
133
|
+
// The range is a promise about which host builds may run this plugin. A bare
|
|
134
|
+
// `>=0.2.1-0 <0.3.0-0` does NOT match a 0.2.2 prerelease when `includePrerelease`
|
|
135
|
+
// is off — semver only admits a prerelease through a comparator on its own
|
|
136
|
+
// major.minor.patch tuple — and npm/pnpm peer resolution plus dsh-market's
|
|
137
|
+
// discovery preflight are strict. So the 0.2.2 arm is what makes the declaration
|
|
138
|
+
// true for a 0.2.2 host, and it covers that whole line (rc.1 through rc.5 and the
|
|
139
|
+
// stable release); verify it with the same semver the runtime ships.
|
|
140
|
+
{
|
|
141
|
+
const probe = createRequire(join(process.env.DSH_HOME ?? join(homedir(), '.dsh'), 'profiles', 'node_modules') + '/')
|
|
142
|
+
let semver = null
|
|
143
|
+
try { semver = probe('semver') } catch { semver = null }
|
|
144
|
+
if (semver === null) {
|
|
145
|
+
skip('the declared host range matches 0.2.2 prereleases under strict semver',
|
|
146
|
+
'no semver under the profile node_modules')
|
|
147
|
+
} else {
|
|
148
|
+
const must = [
|
|
149
|
+
'0.2.1', '0.2.1-rc.3',
|
|
150
|
+
'0.2.2-rc.1', '0.2.2-rc.3', '0.2.2-rc.4', '0.2.2-rc.5', '0.2.2', '0.2.3',
|
|
151
|
+
]
|
|
152
|
+
const mustNot = ['0.1.9', '0.3.0-rc.1', '1.0.0']
|
|
153
|
+
const strictOk = must.every((v) => semver.satisfies(v, DSH_RANGE))
|
|
154
|
+
&& mustNot.every((v) => !semver.satisfies(v, DSH_RANGE))
|
|
155
|
+
check('the declared host range matches 0.2.2 prereleases under strict semver',
|
|
156
|
+
strictOk, `${must.filter((v) => !semver.satisfies(v, DSH_RANGE)).join(', ')} rejected`)
|
|
157
|
+
check('the declared host range still rejects 0.3 prereleases with includePrerelease',
|
|
158
|
+
!semver.satisfies('0.3.0-rc.1', DSH_RANGE, { includePrerelease: true }))
|
|
159
|
+
|
|
160
|
+
// DSH 0.2.2 runs on Node 24.9+ (upgrade guide v0.2.1-rc.2/node-24), and this
|
|
161
|
+
// plugin uses Node 24's `DatabaseSync(path, { timeout })`. Declaring the floor
|
|
162
|
+
// the host itself enforces keeps "supported" from meaning "never executed".
|
|
163
|
+
const NODE_RANGE = pkg.engines?.node
|
|
164
|
+
check('engines.node matches the Node floor of the verified DSH release',
|
|
165
|
+
typeof NODE_RANGE === 'string'
|
|
166
|
+
&& semver.satisfies('24.9.0', NODE_RANGE)
|
|
167
|
+
&& semver.satisfies(process.versions.node, NODE_RANGE)
|
|
168
|
+
&& !semver.satisfies('22.13.0', NODE_RANGE),
|
|
169
|
+
`${NODE_RANGE} vs running ${process.versions.node}`)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
123
173
|
// ── the browser half ────────────────────────────────────────────────────────
|
|
124
174
|
// `dsh.client` is parsed by @deepseek-ai/dsh-client-modules, which reads
|
|
125
175
|
// `platform` (must be the string 'web') and the optional `external` list; any
|
|
@@ -155,35 +205,20 @@ check('the built bundle offers un-flagging from the review queue',
|
|
|
155
205
|
clientBundle.includes('取消标记') && existsSync(join(root, pkg.exports['./client'])))
|
|
156
206
|
check('the built bundle carries the structure view',
|
|
157
207
|
clientBundle.includes('/memvault/api/structure') && clientBundle.includes('关系图'))
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const { MEMVAULT_DIR: vaultDir, MEMVAULT_PYTHON: vaultPython } = await import('../lib/index.js')
|
|
161
|
-
const dir = mkdtempSync(join(tmpdir(), 'dsh-mv-reindex-'))
|
|
162
|
-
const env = { ...process.env, MEMVAULT_DB_PATH: join(dir, 'r.db'), MEMVAULT_EMBEDDER: 'local', MEMVAULT_EMBEDDING_DIM: '384' }
|
|
163
|
-
const dry = runReindex({ pythonPath: vaultPython, projectDir: vaultDir, env })
|
|
164
|
-
check('the reindex runner reports without writing',
|
|
165
|
-
dry.ok && dry.report && dry.report.dryRun === true && typeof dry.report.total === 'number',
|
|
166
|
-
dry.ok ? ('total ' + dry.report.total) : String(dry.error))
|
|
167
|
-
check('the reindex runner fails loudly on a project it cannot run',
|
|
168
|
-
runReindex({ pythonPath: vaultPython, projectDir: join(dir, 'nope'), env }).ok === false)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
check('the built bundle carries the reindex entry',
|
|
172
|
-
clientBundle.includes('嵌入器重算') && clientBundle.includes('执行重算') && clientBundle.includes('/memvault/api/reindex'))
|
|
208
|
+
check('the built bundle carries the vector backfill entry',
|
|
209
|
+
clientBundle.includes('向量回填') && clientBundle.includes('检查缺口') && clientBundle.includes('/memvault/api/reindex'))
|
|
173
210
|
|
|
174
211
|
check('the built bundle reports what the window dropped',
|
|
175
212
|
clientBundle.includes('窗口丢弃') && clientBundle.includes('超上限'))
|
|
176
213
|
|
|
177
|
-
check('the built bundle
|
|
178
|
-
clientBundle.includes('
|
|
214
|
+
check('the built bundle keeps the path map behind one toggle',
|
|
215
|
+
clientBundle.includes('存储与注入') && clientBundle.includes('路径、窗口与自检'))
|
|
179
216
|
|
|
180
217
|
// ── absolute paths only where they are allowed to be ─────────────────────────
|
|
181
218
|
// A hard-coded disk is how "works on my machine" starts. Four files may contain one,
|
|
182
219
|
// each for a stated reason; anything else fails here rather than on someone else's
|
|
183
220
|
// machine:
|
|
184
221
|
// lib/config.js the discovery *candidates* (searched, never assumed)
|
|
185
|
-
// lib/blocks.js the documented fallback for a direct readCoreBlocks call
|
|
186
|
-
// lib/index.js a comment about Windows path normalisation
|
|
187
222
|
// cordis.patch.yml the shipped example configuration, annotated as such
|
|
188
223
|
//
|
|
189
224
|
// The pattern requires a non-alphanumeric (or the start) before the letter: the first
|
|
@@ -193,10 +228,11 @@ check('the path guard does not mistake a URL scheme for a drive letter',
|
|
|
193
228
|
!DRIVE_PATH.test('http://localhost') && !DRIVE_PATH.test('https://example.com/x')
|
|
194
229
|
&& DRIVE_PATH.test('D:/x') && DRIVE_PATH.test("'C:\\Users\\x'"))
|
|
195
230
|
|
|
196
|
-
const ALLOWED_ABSOLUTE_PATH_FILES = ['lib/config.js', '
|
|
231
|
+
const ALLOWED_ABSOLUTE_PATH_FILES = ['lib/config.js', 'cordis.patch.yml']
|
|
197
232
|
const SOURCE_FILES = [
|
|
198
|
-
'lib/config.js', 'lib/blocks.js', 'lib/index.js', 'lib/panel.js',
|
|
199
|
-
'lib/structure.js', 'lib/extract.js', 'lib/window.js', 'lib/
|
|
233
|
+
'lib/config.js', 'lib/blocks.js', 'lib/index.js', 'lib/panel.js',
|
|
234
|
+
'lib/structure.js', 'lib/extract.js', 'lib/window.js', 'lib/flags.js',
|
|
235
|
+
'lib/core/store.js', 'lib/core/pipeline.js', 'lib/core/panel-read.js', 'lib/core/block-write.js',
|
|
200
236
|
'src/client/index.js', 'cordis.patch.yml',
|
|
201
237
|
]
|
|
202
238
|
const offenders = SOURCE_FILES.filter((rel) => !ALLOWED_ABSOLUTE_PATH_FILES.includes(rel)
|
|
@@ -208,7 +244,7 @@ check('an absolute path appears only in the files allowed to carry one',
|
|
|
208
244
|
const dir = mkdtempSync(join(tmpdir(), 'dsh-mv-env-'))
|
|
209
245
|
writeFileSync(join(dir, '.env'), 'MEMVAULT_DB_PATH=data/x.db\nMEMVAULT_EMBEDDER=openai\nOPENAI_EMBEDDING_MODEL=qwen3-embedding-8b\n')
|
|
210
246
|
const { checkPaths } = await import('../lib/index.js')
|
|
211
|
-
const options = {
|
|
247
|
+
const options = { dbPath: join(dir, 'data', 'x.db'), statePath: join(dir, 'state.json') }
|
|
212
248
|
const row = checkPaths({ ...options, projectDir: dir }).find((r) => r.key === 'serviceEmbedder')
|
|
213
249
|
check('the service embedder is reported, with its model',
|
|
214
250
|
Boolean(row) && row.detail.includes('openai') && row.detail.includes('qwen3-embedding-8b'),
|
|
@@ -222,5 +258,47 @@ check('every allow-listed file still contains one (a stale entry would be a lie)
|
|
|
222
258
|
ALLOWED_ABSOLUTE_PATH_FILES.every((rel) => DRIVE_PATH.test(readFileSync(join(root, rel), 'utf8'))),
|
|
223
259
|
ALLOWED_ABSOLUTE_PATH_FILES.join(', '))
|
|
224
260
|
|
|
261
|
+
// ── display metadata (DSH reads locale JSON + ./icon without activating) ──────
|
|
262
|
+
// The plugin manager shows `meta.title` / `meta.description` / `meta.detail` and the
|
|
263
|
+
// exported icon on the Plugins page. None of it is code, so a typo or a missing file
|
|
264
|
+
// is invisible until someone opens the page — hence a check here.
|
|
265
|
+
{
|
|
266
|
+
check('exports the icon and the locale resources DSH reads',
|
|
267
|
+
pkg.exports?.['./icon'] === './icon.svg' && pkg.exports?.['./locale/*.json'] === './locale/*.json',
|
|
268
|
+
JSON.stringify({ icon: pkg.exports?.['./icon'], locale: pkg.exports?.['./locale/*.json'] }))
|
|
269
|
+
|
|
270
|
+
const icon = join(root, 'icon.svg')
|
|
271
|
+
const iconSvg = existsSync(icon) ? readFileSync(icon, 'utf8') : ''
|
|
272
|
+
check('the icon is a self-contained 36-unit SVG', /^<svg[\s>]/.test(iconSvg.trim())
|
|
273
|
+
&& /width="36"/.test(iconSvg) && /height="36"/.test(iconSvg) && /viewBox="0 0 36 36"/.test(iconSvg)
|
|
274
|
+
&& !/<script|<style|<image|<foreignObject/i.test(iconSvg),
|
|
275
|
+
`${Buffer.byteLength(iconSvg, 'utf8')} bytes`)
|
|
276
|
+
check('the icon stays inside the 256 KiB limit', Buffer.byteLength(iconSvg, 'utf8') <= 256 * 1024)
|
|
277
|
+
|
|
278
|
+
for (const locale of ['en', 'zh']) {
|
|
279
|
+
const file = join(root, 'locale', `${locale}.json`)
|
|
280
|
+
let meta = null
|
|
281
|
+
try { meta = JSON.parse(readFileSync(file, 'utf8'))?.meta ?? null } catch { meta = null }
|
|
282
|
+
check(`locale/${locale}.json carries a title, a description and a detail document`,
|
|
283
|
+
typeof meta?.title === 'string' && meta.title.trim() !== ''
|
|
284
|
+
&& typeof meta?.description === 'string' && meta.description.trim().length > 40
|
|
285
|
+
&& typeof meta?.detail === 'string' && meta.detail.endsWith('.md'),
|
|
286
|
+
JSON.stringify(meta))
|
|
287
|
+
// The page treats a declared-but-missing document as an error, not a fallback.
|
|
288
|
+
const doc = typeof meta?.detail === 'string' ? join(root, meta.detail) : ''
|
|
289
|
+
const docText = doc !== '' && existsSync(doc) ? readFileSync(doc, 'utf8') : null
|
|
290
|
+
check(`locale/${locale}.json names a detail document that exists`, docText !== null, meta?.detail ?? '—')
|
|
291
|
+
const imageLine = (docText ?? '').split('\n').map((line) => line.trim()).filter(Boolean)
|
|
292
|
+
check(`the ${locale} detail document is exactly one image line`,
|
|
293
|
+
imageLine.length === 1 && /^!\[[^\]]+\]\([^)]+\)$/.test(imageLine[0]), imageLine.join(' | '))
|
|
294
|
+
const imagePath = imageLine[0]?.match(/\(([^)]+)\)$/)?.[1] ?? ''
|
|
295
|
+
const image = imagePath === '' ? '' : join(doc, '..', imagePath)
|
|
296
|
+
check(`the ${locale} detail image exists and is a self-contained SVG`,
|
|
297
|
+
image !== '' && existsSync(image) && /^<svg[\s>]/.test(readFileSync(image, 'utf8').trim())
|
|
298
|
+
&& !/<script|<image|<foreignObject/i.test(readFileSync(image, 'utf8')),
|
|
299
|
+
imagePath)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
225
303
|
console.log(`\n${failures.length === 0 ? 'ALL PASS' : `FAILED: ${failures.join(', ')}`}`)
|
|
226
304
|
process.exit(failures.length === 0 ? 0 : 1)
|