@restregular/dsh-memory 0.2.0 → 0.3.0
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 +15 -0
- package/lib/provider/apply.js +10 -0
- package/lib/provider/index.js +123 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,6 +80,21 @@ patch 里给 `dsh-memory-local` 传配置即可(默认值通常够用):
|
|
|
80
80
|
- 若 `autoInstall.dir`(或 `storeDir` 上一级)里已经存在 `llamacpp/` + `models/`,插件会**直接采用**,面板只显示状态,不需要重新下载。
|
|
81
81
|
- 面板的开关只在"进程确实由本应用托管"时出现;未配置给下载按钮,外部服务只显示连通性,配置里关掉了就只解释原因——不会出现一个永远灰着的开关。
|
|
82
82
|
|
|
83
|
+
### 维护与卸载
|
|
84
|
+
|
|
85
|
+
面板底部有一个「维护」区,不可撤销的操作都走**两步确认**(第一次点击只是把按钮换成"确认…"):
|
|
86
|
+
|
|
87
|
+
| 动作 | 做什么 | 安全边界 |
|
|
88
|
+
| --- | --- | --- |
|
|
89
|
+
| **卸载向量服务** | 删掉插件下载的 llama.cpp 运行时 + 模型 + 日志(约 480 MB) | 只删 `retrieval.vector.autoInstall.dir`(默认 storeDir 上一级)里的东西;**绝不碰记忆数据目录**;若 `spawn.exe` 指向该根目录之外(也就是你自己装的 llama.cpp),直接拒绝并说明原因 |
|
|
90
|
+
| **清空记忆数据** | 删除所有作用域的全部记录(走 store,JSONL 与 `.vec` 边车保持一致,不会删出半个库) | 两步确认,且接口要求显式 `confirm: "delete"`,缺了不执行 |
|
|
91
|
+
|
|
92
|
+
**卸载插件本身**:在 DSH 的「插件 / 插件市场」里移除本包和 `@restregular/dsh-memory-panel`。
|
|
93
|
+
|
|
94
|
+
> ⚠️ DSH 卸载插件只是在 profile 里 `pnpm remove` 并去掉 bundles 条目:它**不会**给插件任何提问机会,也**不会**自动删除向量服务文件或记忆数据。所以"要不要留向量服务""要不要留记忆数据"这两件事要在卸载**之前**到面板「维护」区处理——插件卸载后那个面板也就没了。
|
|
95
|
+
>
|
|
96
|
+
> 手动清理路径:向量服务在 `retrieval.vector.autoInstall.dir`(默认 `~/.dsh/memory-vector`;显式配了 `storeDir` 时是它的上一级目录),记忆数据在 `storeDir`。
|
|
97
|
+
|
|
83
98
|
## 说明
|
|
84
99
|
|
|
85
100
|
- 存储为每作用域一个 JSONL + `.vec` 向量边车(含模型/维度身份头,不匹配自动重建)。
|
package/lib/provider/apply.js
CHANGED
|
@@ -92,6 +92,16 @@ export class CordisMemoryService extends Service {
|
|
|
92
92
|
this.impl.cancelVectorInstall()
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/** Panel: remove the runtime + model we installed (never the memory store). */
|
|
96
|
+
uninstallVectorBackend() {
|
|
97
|
+
return this.impl.uninstallVectorBackend()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Panel: delete every record in every scope. */
|
|
101
|
+
wipeAllRecords() {
|
|
102
|
+
return this.impl.wipeAllRecords()
|
|
103
|
+
}
|
|
104
|
+
|
|
95
105
|
search(query ) {
|
|
96
106
|
return this.impl.search(query)
|
|
97
107
|
}
|
package/lib/provider/index.js
CHANGED
|
@@ -22,9 +22,29 @@ import { RerankCache } from './rerank-cache.js'
|
|
|
22
22
|
import { scanSecrets, redactSecrets } from './secrets.js'
|
|
23
23
|
import { EmbedServerManager, } from './embed-server.js'
|
|
24
24
|
import { VectorInstaller, detectInstalled, installPaths, } from './embed-install.js'
|
|
25
|
-
import {
|
|
25
|
+
import { existsSync, readdirSync, rmSync, statSync } from 'node:fs'
|
|
26
|
+
import { dirname, isAbsolute, join, relative, resolve } from 'node:path'
|
|
26
27
|
import { homedir } from 'node:os'
|
|
27
28
|
|
|
29
|
+
/** Recursive byte count; 0 for anything unreadable. */
|
|
30
|
+
function pathSize(path ) {
|
|
31
|
+
try {
|
|
32
|
+
const st = statSync(path)
|
|
33
|
+
if (!st.isDirectory()) return st.size
|
|
34
|
+
let total = 0
|
|
35
|
+
for (const entry of readdirSync(path)) total += pathSize(join(path, entry))
|
|
36
|
+
return total
|
|
37
|
+
} catch {
|
|
38
|
+
return 0
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** True when `child` is `parent` or lives under it (both resolved). */
|
|
43
|
+
function isInside(parent , child ) {
|
|
44
|
+
const rel = relative(resolve(parent), resolve(child))
|
|
45
|
+
return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel))
|
|
46
|
+
}
|
|
47
|
+
|
|
28
48
|
|
|
29
49
|
|
|
30
50
|
|
|
@@ -131,7 +151,13 @@ export function resolveConfig(config = {}) {
|
|
|
131
151
|
?? (config.storeDir !== undefined ? dirname(resolve(storeDir)) : join(homedir(), '.dsh', 'memory-vector'))
|
|
132
152
|
const installed = detectInstalled(installRoot)
|
|
133
153
|
const endpointConfigured = v.endpoint !== undefined
|
|
134
|
-
|
|
154
|
+
// A configured spawn path that no longer exists (plugin uninstalled the
|
|
155
|
+
// backend, or the user moved it) must not count as configured: that would
|
|
156
|
+
// leave the panel showing a managed server that can never start, instead of
|
|
157
|
+
// offering the download button again.
|
|
158
|
+
const spawnExe = v.spawn?.exe
|
|
159
|
+
const spawnExeUsable = spawnExe === undefined || spawnExe === '' || existsSync(spawnExe)
|
|
160
|
+
const spawnConfigured = ((v.spawn?.enabled === true || (spawnExe ?? '') !== '') && spawnExeUsable) || installed !== null
|
|
135
161
|
const configured = endpointConfigured || spawnConfigured
|
|
136
162
|
const vectorEnabled = v.enabled ?? configured
|
|
137
163
|
return {
|
|
@@ -299,11 +325,14 @@ export class LocalMemoryService {
|
|
|
299
325
|
|
|
300
326
|
|
|
301
327
|
|
|
328
|
+
|
|
329
|
+
|
|
302
330
|
{
|
|
303
331
|
const mgr = this.embedServer
|
|
304
332
|
const cfg = this.cfg.vector
|
|
305
333
|
const pendingEmbeds = this.pendingEmbedCount
|
|
306
334
|
const mode = !cfg.configured ? 'off' : cfg.spawnConfigured ? 'managed' : 'external'
|
|
335
|
+
const usage = this.vectorInstallUsage()
|
|
307
336
|
const base = {
|
|
308
337
|
enabled: cfg.enabled,
|
|
309
338
|
configured: cfg.configured,
|
|
@@ -313,6 +342,14 @@ export class LocalMemoryService {
|
|
|
313
342
|
spawnConfigured: cfg.spawnConfigured,
|
|
314
343
|
pendingEmbeds,
|
|
315
344
|
install: this.installSnapshot(),
|
|
345
|
+
maintenance: {
|
|
346
|
+
usageBytes: usage.bytes,
|
|
347
|
+
paths: usage.paths,
|
|
348
|
+
// NOTE: `cfg` is the VECTOR config here, not the whole config — reading
|
|
349
|
+
// cfg.storeDir would silently yield undefined (and JSON drops it).
|
|
350
|
+
storeDir: this.cfg.storeDir,
|
|
351
|
+
records: this.store.allScopes().reduce((n, s) => n + s.records.size, 0),
|
|
352
|
+
},
|
|
316
353
|
}
|
|
317
354
|
if (!mgr) return { ...base, owned: false, pid: null, baseUrl: '', reachable: false }
|
|
318
355
|
const reachable = await mgr.healthCheck()
|
|
@@ -361,6 +398,90 @@ export class LocalMemoryService {
|
|
|
361
398
|
this.installer?.cancel()
|
|
362
399
|
}
|
|
363
400
|
|
|
401
|
+
/**
|
|
402
|
+
* What the installer put on disk, so the panel can say "释放 xxx MB" before
|
|
403
|
+
* offering to remove it. Counts only our own layout (runtime dir, models dir,
|
|
404
|
+
* log + pid), never the memory store.
|
|
405
|
+
*/
|
|
406
|
+
vectorInstallUsage() {
|
|
407
|
+
const paths = installPaths(this.cfg.vector.installRoot)
|
|
408
|
+
const roots = [paths.dir, join(this.cfg.vector.installRoot, 'models')]
|
|
409
|
+
const files = [paths.logFile, `${paths.logFile}.pid`, `${paths.logFile}.err`]
|
|
410
|
+
let bytes = 0
|
|
411
|
+
const seen = []
|
|
412
|
+
for (const p of [...roots, ...files]) {
|
|
413
|
+
if (!existsSync(p)) continue
|
|
414
|
+
seen.push(p)
|
|
415
|
+
bytes += pathSize(p)
|
|
416
|
+
}
|
|
417
|
+
return { bytes, paths: seen }
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Remove the vector backend we installed (runtime + model + logs).
|
|
422
|
+
*
|
|
423
|
+
* Refuses when the configured backend lives outside installRoot: that is a
|
|
424
|
+
* server the user installed and manages, and deleting it would be destroying
|
|
425
|
+
* something we never created. The memory store is never touched — it lives
|
|
426
|
+
* beside the runtime, not inside it.
|
|
427
|
+
*/
|
|
428
|
+
uninstallVectorBackend()
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
{
|
|
434
|
+
const root = this.cfg.vector.installRoot
|
|
435
|
+
const configuredExe = this.cfg.vector.spawn.exe
|
|
436
|
+
if (configuredExe && !isInside(root, configuredExe)) {
|
|
437
|
+
return { removed: false, reason: 'EXTERNAL_BACKEND', freedBytes: 0, paths: [] }
|
|
438
|
+
}
|
|
439
|
+
const usage = this.vectorInstallUsage()
|
|
440
|
+
if (usage.paths.length === 0) {
|
|
441
|
+
return { removed: false, reason: 'NOT_INSTALLED', freedBytes: 0, paths: [] }
|
|
442
|
+
}
|
|
443
|
+
// Stop our child first: on Windows the executable and its DLLs are locked
|
|
444
|
+
// while it runs, so removal would fail with EBUSY/EPERM.
|
|
445
|
+
try { this.embedServer?.stop() } catch { /* best effort */ }
|
|
446
|
+
const removedPaths = []
|
|
447
|
+
for (const p of usage.paths) {
|
|
448
|
+
// Belt and braces: never step outside the install root, and never delete
|
|
449
|
+
// the memory store even if someone pointed storeDir inside it.
|
|
450
|
+
if (!isInside(root, p)) continue
|
|
451
|
+
if (isInside(p, this.cfg.storeDir) || resolve(p) === resolve(this.cfg.storeDir)) continue
|
|
452
|
+
try {
|
|
453
|
+
rmSync(p, { recursive: true, force: true })
|
|
454
|
+
removedPaths.push(p)
|
|
455
|
+
} catch { /* leave it; the panel reports what went */ }
|
|
456
|
+
}
|
|
457
|
+
this.cfg.vector.configured = false
|
|
458
|
+
this.cfg.vector.spawnConfigured = false
|
|
459
|
+
this.cfg.vector.enabled = false
|
|
460
|
+
this.embedServer = null
|
|
461
|
+
return { removed: true, reason: 'REMOVED', freedBytes: usage.bytes, paths: removedPaths }
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Delete every memory record in every scope (the panel's "delete all data"
|
|
466
|
+
* action, used when someone wants the plugin gone without leaving notes
|
|
467
|
+
* behind). Goes through the store so the JSONL + vector sidecars stay
|
|
468
|
+
* consistent instead of ripping files out from under a live store.
|
|
469
|
+
*/
|
|
470
|
+
wipeAllRecords() {
|
|
471
|
+
let removed = 0
|
|
472
|
+
const scopes = []
|
|
473
|
+
for (const scope of this.store.allScopes()) {
|
|
474
|
+
const ids = [...scope.records.keys()]
|
|
475
|
+
if (ids.length === 0) continue
|
|
476
|
+
let local = 0
|
|
477
|
+
for (const id of ids) if (scope.remove(id)) local += 1
|
|
478
|
+
removed += local
|
|
479
|
+
scopes.push(scope.scope)
|
|
480
|
+
}
|
|
481
|
+
try { this.store.flushSync() } catch { /* scheduled flush covers it */ }
|
|
482
|
+
return { removed, scopes }
|
|
483
|
+
}
|
|
484
|
+
|
|
364
485
|
/**
|
|
365
486
|
* Switch the provider over to a backend that is now on disk: fill the spawn
|
|
366
487
|
* config from the installed layout and start it. Idempotent.
|