dsh-recall-rebuild 0.1.1 → 0.1.2
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 +7 -7
- package/dist/config.d.ts +5 -4
- package/dist/config.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/store.d.ts +7 -2
- package/dist/store.js +127 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
## 特性
|
|
31
31
|
|
|
32
32
|
- **只读增强,零污染**:以 `readOnly` 打开现有记忆库(`$DSH_HOME/memory/memory.db`),不重写捕获管线、不写任何数据,装/卸都不影响原插件;
|
|
33
|
-
- **多记忆源可插拔**:`source` 支持 dsh-prime-memory(SQLite FTS5)与 dsh-memory-palace(Markdown 文件)
|
|
33
|
+
- **多记忆源可插拔**:`source` 支持 dsh-prime-memory(SQLite FTS5)、@max-null/dsh-memory(JSON 记忆库)与 dsh-memory-palace(Markdown 文件)三种底层记忆,`auto` 自动探测,后续可继续扩展;
|
|
34
34
|
- **生成式重建**:在 `agent/pre-step` 用会话末尾消息召回碎片,LLM 重建为带语境/情绪/时间感的回忆片段,替代生硬原文注入;
|
|
35
35
|
- **与生态共存不错位**:注入消息 `source.kind='plugin:recall-rebuild'`,不会被 prime-memory 当作新用户消息再次捕获/蒸馏;`replace` 策略原位替换对方的原文召回,`append` 策略追加,不重复注入;
|
|
36
36
|
- **永不阻塞对话**:无记忆库/无模型路由/超时/重建失败,一律静默跳过本轮;
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
|
|
50
50
|
- DeepSeek Harness `0.1.0-rc.2 … 0.2.1-rc.3`;
|
|
51
51
|
- Node ≥ 22.5(需要内置 `node:sqlite`);
|
|
52
|
-
- 已安装并运行过 `dsh-prime-memory`(0.26.x,SQLite 记忆库)**或** `dsh-memory-palace`(Markdown 记忆文件),且已有记忆数据。
|
|
52
|
+
- 已安装并运行过 `dsh-prime-memory`(0.26.x,SQLite 记忆库)、`dsh-memory`(@max-null,JSON 记忆库)**或** `dsh-memory-palace`(Markdown 记忆文件),且已有记忆数据。
|
|
53
53
|
|
|
54
54
|
```bash
|
|
55
55
|
dsh plugin --profile <你的配置文件名> add dsh-recall-rebuild
|
|
@@ -77,7 +77,7 @@ dsh plugin --profile <你的配置文件名> add dsh-recall-rebuild
|
|
|
77
77
|
flowchart LR
|
|
78
78
|
U["用户新消息"] --> P["agent/pre-step<br/>(本插件 prepend)"]
|
|
79
79
|
P --> Q["构造召回查询<br/>(会话末尾消息)"]
|
|
80
|
-
Q --> S[("记忆库<br/>prime(SQLite
|
|
80
|
+
Q --> S[("记忆库<br/>prime(SQLite)/ dsh-memory(JSON)/ palace(Markdown)")]
|
|
81
81
|
S --> R["LLM 重建式回忆<br/>(碎片 → 带语境的回忆片段)"]
|
|
82
82
|
R --> I["注入回忆片段<br/>source.kind = plugin:recall-rebuild"]
|
|
83
83
|
P --> M["模型推理"]
|
|
@@ -99,7 +99,7 @@ flowchart LR
|
|
|
99
99
|
| --- | --- | --- |
|
|
100
100
|
| `enabled` | `true` | 总开关 |
|
|
101
101
|
| `dataDir` | `''` | 记忆库目录;空 = `$DSH_HOME/memory` |
|
|
102
|
-
| `source` | `auto` | 记忆来源:`auto` 自动探测(prime → palace);`prime` = dsh-prime-memory SQLite 库;`palace` = dsh-memory-palace Markdown 文件 |
|
|
102
|
+
| `source` | `auto` | 记忆来源:`auto` 自动探测(prime → dsh-memory → palace);`prime` = dsh-prime-memory SQLite 库;`dsh-memory` = @max-null/dsh-memory JSON 记忆库;`palace` = dsh-memory-palace Markdown 文件 |
|
|
103
103
|
| `rebuild.enabled` | `true` | 重建式回忆开关;`false` 退化为原文检索注入 |
|
|
104
104
|
| `rebuild.maxResults` | `5` | 每轮检索条数 |
|
|
105
105
|
| `rebuild.maxMemoryChars` | `400` | 单条记忆进重建 prompt 的字符上限 |
|
|
@@ -116,7 +116,7 @@ flowchart LR
|
|
|
116
116
|
|
|
117
117
|
## Roadmap
|
|
118
118
|
|
|
119
|
-
- [ ] 更多记忆源 adapter(
|
|
119
|
+
- [ ] 更多记忆源 adapter(`dsh-memory-vault`、`dsh-auto-memory`、`dsh-memory-gate` 等变体);
|
|
120
120
|
- [ ] IM 用户级命名空间隔离(跨 QQ/微信的同一人记忆共享);
|
|
121
121
|
- [ ] 重建质量可观测:注入效果对比开关 + 每轮重建日志;
|
|
122
122
|
- [ ] 睡眠巩固 / 联想扩散(更接近人脑的长期记忆子系统的后续阶段)。
|
|
@@ -134,7 +134,7 @@ flowchart LR
|
|
|
134
134
|
npm install
|
|
135
135
|
npm run typecheck # tsc --noEmit
|
|
136
136
|
npm run build # 编译到 dist/
|
|
137
|
-
node scripts/verify.mjs # 运行时验证:导出/Config/prime FTS+LIKE/palace Markdown/降级
|
|
137
|
+
node scripts/verify.mjs # 运行时验证:导出/Config/prime FTS+LIKE/palace Markdown/dsh-memory JSON/降级
|
|
138
138
|
npm pack --dry-run # 检查发布包内容
|
|
139
139
|
```
|
|
140
140
|
|
|
@@ -146,7 +146,7 @@ MIT
|
|
|
146
146
|
|
|
147
147
|
## English Overview
|
|
148
148
|
|
|
149
|
-
**dsh-recall-rebuild** is an *enhancer* for memory plugins in [DeepSeek Harness](https://github.com/deepseek-ai/DeepSeek-Harness) (DSH). Existing memory plugins such as `dsh-prime-memory` (SQLite) or `dsh-memory-palace` (Markdown) already handle *storage* very well — cross-session capture, distillation and persistence are mature, so install one first. This plugin does **not** duplicate that work; it enhances a single layer: **how memories are recalled** — instead of injecting raw snippets as-is, it has the LLM reconstruct them into contextual recollections, so "remembering" feels natural rather than like quoting a file.
|
|
149
|
+
**dsh-recall-rebuild** is an *enhancer* for memory plugins in [DeepSeek Harness](https://github.com/deepseek-ai/DeepSeek-Harness) (DSH). Existing memory plugins such as `dsh-prime-memory` (SQLite), `@max-null/dsh-memory` (JSON) or `dsh-memory-palace` (Markdown) already handle *storage* very well — cross-session capture, distillation and persistence are mature, so install one first. This plugin does **not** duplicate that work; it enhances a single layer: **how memories are recalled** — instead of injecting raw snippets as-is, it has the LLM reconstruct them into contextual recollections, so "remembering" feels natural rather than like quoting a file.
|
|
150
150
|
|
|
151
151
|
This plugin upgrades the **recall/presentation layer**:
|
|
152
152
|
|
package/dist/config.d.ts
CHANGED
|
@@ -48,11 +48,12 @@ export interface RecallRebuildConfig {
|
|
|
48
48
|
dataDir: string;
|
|
49
49
|
/**
|
|
50
50
|
* 记忆来源:
|
|
51
|
-
* - 'auto':自动探测 —— prime-memory
|
|
51
|
+
* - 'auto':自动探测 —— prime-memory 库存在则读它,否则依次尝试 dsh-memory(JSON)与 memory-palace(Markdown);
|
|
52
52
|
* - 'prime':只读 dsh-prime-memory 的 SQLite 库($dataDir/memory.db);
|
|
53
|
+
* - 'dsh-memory':只读 @max-null/dsh-memory 的 JSON 记忆(~/.dsh/storages/memory.json 与 <cwd>/.dsh/storages/);
|
|
53
54
|
* - 'palace':只读 dsh-memory-palace 的 Markdown 文件(~/.deepseek-harness/MEMORY.md 与 <cwd>/.deepseek-harness/memory/)。
|
|
54
55
|
*/
|
|
55
|
-
source: 'auto' | 'prime' | 'palace';
|
|
56
|
+
source: 'auto' | 'prime' | 'dsh-memory' | 'palace';
|
|
56
57
|
rebuild: RebuildOptions;
|
|
57
58
|
inject: InjectOptions;
|
|
58
59
|
query: QueryOptions;
|
|
@@ -60,7 +61,7 @@ export interface RecallRebuildConfig {
|
|
|
60
61
|
export declare const recallRebuildSchema: Schema<Schemastery.ObjectS<NoInfer<{
|
|
61
62
|
enabled: Schema<boolean, boolean, "defined">;
|
|
62
63
|
dataDir: Schema<string, string, "defined">;
|
|
63
|
-
source: Schema<"auto" | "prime" | "palace", "auto" | "prime" | "palace", "defined">;
|
|
64
|
+
source: Schema<"auto" | "prime" | "dsh-memory" | "palace", "auto" | "prime" | "dsh-memory" | "palace", "defined">;
|
|
64
65
|
rebuild: Schema<Schemastery.ObjectS<NoInfer<{
|
|
65
66
|
enabled: Schema<boolean, boolean, "defined">;
|
|
66
67
|
maxResults: Schema<number, number, "defined">;
|
|
@@ -99,7 +100,7 @@ export declare const recallRebuildSchema: Schema<Schemastery.ObjectS<NoInfer<{
|
|
|
99
100
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
100
101
|
enabled: Schema<boolean, boolean, "defined">;
|
|
101
102
|
dataDir: Schema<string, string, "defined">;
|
|
102
|
-
source: Schema<"auto" | "prime" | "palace", "auto" | "prime" | "palace", "defined">;
|
|
103
|
+
source: Schema<"auto" | "prime" | "dsh-memory" | "palace", "auto" | "prime" | "dsh-memory" | "palace", "defined">;
|
|
103
104
|
rebuild: Schema<Schemastery.ObjectS<NoInfer<{
|
|
104
105
|
enabled: Schema<boolean, boolean, "defined">;
|
|
105
106
|
maxResults: Schema<number, number, "defined">;
|
package/dist/config.js
CHANGED
|
@@ -9,7 +9,7 @@ import Schema from '@deepseek-ai/schemastery';
|
|
|
9
9
|
export const recallRebuildSchema = Schema.object({
|
|
10
10
|
enabled: Schema.boolean().default(true),
|
|
11
11
|
dataDir: Schema.string().default(''),
|
|
12
|
-
source: Schema.union(['auto', 'prime', 'palace']).default('auto'),
|
|
12
|
+
source: Schema.union(['auto', 'prime', 'dsh-memory', 'palace']).default('auto'),
|
|
13
13
|
rebuild: Schema.object({
|
|
14
14
|
enabled: Schema.boolean().default(true),
|
|
15
15
|
maxResults: Schema.number().min(1).max(20).default(5),
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const inject: string[];
|
|
|
5
5
|
export declare const Config: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
6
6
|
enabled: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
|
|
7
7
|
dataDir: import("@deepseek-ai/schemastery").default<string, string, "defined">;
|
|
8
|
-
source: import("@deepseek-ai/schemastery").default<"auto" | "prime" | "palace", "auto" | "prime" | "palace", "defined">;
|
|
8
|
+
source: import("@deepseek-ai/schemastery").default<"auto" | "prime" | "dsh-memory" | "palace", "auto" | "prime" | "dsh-memory" | "palace", "defined">;
|
|
9
9
|
rebuild: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
10
10
|
enabled: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
|
|
11
11
|
maxResults: import("@deepseek-ai/schemastery").default<number, number, "defined">;
|
|
@@ -44,7 +44,7 @@ export declare const Config: import("@deepseek-ai/schemastery").default<Schemast
|
|
|
44
44
|
}>>, Schemastery.ObjectT<NoInfer<{
|
|
45
45
|
enabled: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
|
|
46
46
|
dataDir: import("@deepseek-ai/schemastery").default<string, string, "defined">;
|
|
47
|
-
source: import("@deepseek-ai/schemastery").default<"auto" | "prime" | "palace", "auto" | "prime" | "palace", "defined">;
|
|
47
|
+
source: import("@deepseek-ai/schemastery").default<"auto" | "prime" | "dsh-memory" | "palace", "auto" | "prime" | "dsh-memory" | "palace", "defined">;
|
|
48
48
|
rebuild: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
|
|
49
49
|
enabled: import("@deepseek-ai/schemastery").default<boolean, boolean, "defined">;
|
|
50
50
|
maxResults: import("@deepseek-ai/schemastery").default<number, number, "defined">;
|
package/dist/store.d.ts
CHANGED
|
@@ -32,8 +32,13 @@ export declare function sanitizeFts(query: string): string;
|
|
|
32
32
|
export declare function openPrimeMemoryStore(dataDir: string, logger: LoggerLike): MemoryStore;
|
|
33
33
|
/** 打开 dsh-memory-palace 的只读记忆源(cwd = DSH 工作目录,用于定位工作区记忆)。 */
|
|
34
34
|
export declare function openPalaceStore(cwd: string, logger: LoggerLike): MemoryStore;
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* 打开 @max-null/dsh-memory 的只读记忆源。
|
|
37
|
+
* @param cwd DSH 工作目录(用于定位 project 记忆)
|
|
38
|
+
*/
|
|
39
|
+
export declare function openDshMemoryStore(cwd: string, logger: LoggerLike): MemoryStore;
|
|
40
|
+
/** 记忆来源路由:auto 探测 prime → dsh-memory → palace,或按 source 显式指定。 */
|
|
41
|
+
export declare function openMemorySource(source: 'auto' | 'prime' | 'dsh-memory' | 'palace', opts: {
|
|
37
42
|
dataDir: string;
|
|
38
43
|
cwd: string;
|
|
39
44
|
logger: LoggerLike;
|
package/dist/store.js
CHANGED
|
@@ -284,23 +284,146 @@ export function openPalaceStore(cwd, logger) {
|
|
|
284
284
|
},
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
/**
|
|
287
|
+
/** epoch ms → 本地时区 YYYY-MM-DD;非法值返回空串。 */
|
|
288
|
+
function epochToDate(ms) {
|
|
289
|
+
if (typeof ms !== 'number' || !Number.isFinite(ms) || ms <= 0)
|
|
290
|
+
return '';
|
|
291
|
+
const d = new Date(ms);
|
|
292
|
+
const mm = String(d.getMonth() + 1).padStart(2, '0');
|
|
293
|
+
const dd = String(d.getDate()).padStart(2, '0');
|
|
294
|
+
return `${d.getFullYear()}-${mm}-${dd}`;
|
|
295
|
+
}
|
|
296
|
+
/** 解析单个 dsh-memory JSON 库文件为生效记录(只读;跳过 suggested/隔离/prompt/结构异常)。 */
|
|
297
|
+
function parseDshMemoryFile(file, rel) {
|
|
298
|
+
let doc;
|
|
299
|
+
try {
|
|
300
|
+
doc = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
return [];
|
|
304
|
+
}
|
|
305
|
+
const blocks = doc?.unit?.tables?.blocks;
|
|
306
|
+
if (!Array.isArray(blocks))
|
|
307
|
+
return [];
|
|
308
|
+
const out = [];
|
|
309
|
+
for (const raw of blocks) {
|
|
310
|
+
const b = raw;
|
|
311
|
+
if (!b || typeof b !== 'object')
|
|
312
|
+
continue;
|
|
313
|
+
if (b.status !== 'approved')
|
|
314
|
+
continue; // suggested 未生效
|
|
315
|
+
if (b.quarantined === true)
|
|
316
|
+
continue; // 隔离记录不进检索
|
|
317
|
+
if (b.kind === 'prompt')
|
|
318
|
+
continue; // 模板索引非用户记忆
|
|
319
|
+
const content = typeof b.content === 'string' ? b.content.trim() : '';
|
|
320
|
+
if (!content)
|
|
321
|
+
continue;
|
|
322
|
+
out.push({
|
|
323
|
+
id: typeof b.id === 'string' ? b.id : '',
|
|
324
|
+
content,
|
|
325
|
+
namespace: b.namespace === 'project' ? 'project' : 'global',
|
|
326
|
+
keywords: Array.isArray(b.keywords) ? b.keywords.filter((k) => typeof k === 'string') : [],
|
|
327
|
+
updatedAt: typeof b.updatedAt === 'number' ? b.updatedAt : 0,
|
|
328
|
+
rel,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return out;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* 打开 @max-null/dsh-memory 的只读记忆源。
|
|
335
|
+
* @param cwd DSH 工作目录(用于定位 project 记忆)
|
|
336
|
+
*/
|
|
337
|
+
export function openDshMemoryStore(cwd, logger) {
|
|
338
|
+
// global:join(DSH_HOME ?? ~/.dsh, 'storages', 'memory.json')
|
|
339
|
+
const home = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
340
|
+
const globalFile = path.join(home, 'storages', 'memory.json');
|
|
341
|
+
// project:<cwd>/.dsh/storages/*.json(每个 backend 一个文件)
|
|
342
|
+
const projectDir = path.join(cwd, '.dsh', 'storages');
|
|
343
|
+
const entries = [];
|
|
344
|
+
if (fs.existsSync(globalFile)) {
|
|
345
|
+
entries.push(...parseDshMemoryFile(globalFile, '<DSH_HOME>/storages/memory.json'));
|
|
346
|
+
}
|
|
347
|
+
let projectNames = [];
|
|
348
|
+
try {
|
|
349
|
+
projectNames = fs.readdirSync(projectDir).filter((n) => n.endsWith('.json'));
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
/* 无 project 记忆 */
|
|
353
|
+
}
|
|
354
|
+
for (const n of projectNames) {
|
|
355
|
+
if (n === 'query-log.json')
|
|
356
|
+
continue; // 查询日志非记忆库
|
|
357
|
+
const f = path.join(projectDir, n);
|
|
358
|
+
entries.push(...parseDshMemoryFile(f, `<cwd>/.dsh/storages/${n}`));
|
|
359
|
+
}
|
|
360
|
+
if (entries.length === 0) {
|
|
361
|
+
logger.warn(`[recall-rebuild] 未找到 dsh-memory 记忆文件(检查 <DSH_HOME>/storages/memory.json 或 ` +
|
|
362
|
+
`<cwd>/.dsh/storages/*.json),记忆读取停用`);
|
|
363
|
+
return disabledStore('未找到 dsh-memory 记忆文件');
|
|
364
|
+
}
|
|
365
|
+
const sources = [...new Set(entries.map((e) => e.rel))];
|
|
366
|
+
return {
|
|
367
|
+
ok: true,
|
|
368
|
+
label: `@max-null/dsh-memory (${sources.join(', ')})`,
|
|
369
|
+
search(query, limit) {
|
|
370
|
+
const words = tokenizeQuery(query);
|
|
371
|
+
if (words.length === 0)
|
|
372
|
+
return [];
|
|
373
|
+
const scored = [];
|
|
374
|
+
for (const e of entries) {
|
|
375
|
+
const cNorm = palaceNorm(e.content);
|
|
376
|
+
let hits = 0;
|
|
377
|
+
for (const w of words) {
|
|
378
|
+
if (cNorm.includes(w))
|
|
379
|
+
hits += 1;
|
|
380
|
+
// keywords 命中更精准,权重 ×2
|
|
381
|
+
for (const k of e.keywords)
|
|
382
|
+
if (palaceNorm(k).includes(w))
|
|
383
|
+
hits += 2;
|
|
384
|
+
}
|
|
385
|
+
if (hits > 0)
|
|
386
|
+
scored.push({ e, hits });
|
|
387
|
+
}
|
|
388
|
+
// 命中权重优先,其次更新时间倒序(最近优先)
|
|
389
|
+
scored.sort((a, b) => b.hits - a.hits || (a.e.updatedAt < b.e.updatedAt ? 1 : a.e.updatedAt > b.e.updatedAt ? -1 : 0));
|
|
390
|
+
return scored.slice(0, limit).map(({ e, hits }) => ({
|
|
391
|
+
id: `${e.rel}#${e.id}`,
|
|
392
|
+
content: e.content,
|
|
393
|
+
type: 'dsh-memory',
|
|
394
|
+
sceneName: e.namespace === 'project' ? 'project 记忆' : 'global 记忆',
|
|
395
|
+
family: e.rel,
|
|
396
|
+
priority: hits,
|
|
397
|
+
timestampStr: epochToDate(e.updatedAt),
|
|
398
|
+
}));
|
|
399
|
+
},
|
|
400
|
+
close() {
|
|
401
|
+
/* 无资源 */
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
/** 记忆来源路由:auto 探测 prime → dsh-memory → palace,或按 source 显式指定。 */
|
|
288
406
|
export function openMemorySource(source, opts) {
|
|
289
407
|
const { dataDir, cwd, logger } = opts;
|
|
290
408
|
if (source === 'prime')
|
|
291
409
|
return openPrimeMemoryStore(dataDir, logger);
|
|
410
|
+
if (source === 'dsh-memory')
|
|
411
|
+
return openDshMemoryStore(cwd, logger);
|
|
292
412
|
if (source === 'palace')
|
|
293
413
|
return openPalaceStore(cwd, logger);
|
|
294
|
-
// auto:prime-memory 库存在则优先(
|
|
414
|
+
// auto:prime-memory 库存在则优先(打开失败依次落 dsh-memory / palace),否则尝试后两者
|
|
295
415
|
const primeDb = path.join(dataDir, 'memory.db');
|
|
296
416
|
if (fs.existsSync(primeDb)) {
|
|
297
417
|
const s = openPrimeMemoryStore(dataDir, logger);
|
|
298
418
|
if (s.ok)
|
|
299
419
|
return s;
|
|
300
|
-
logger.warn(`[recall-rebuild] prime-memory 库存在但打不开,尝试 memory-palace 记忆源`);
|
|
420
|
+
logger.warn(`[recall-rebuild] prime-memory 库存在但打不开,尝试 dsh-memory / memory-palace 记忆源`);
|
|
301
421
|
}
|
|
422
|
+
const dm = openDshMemoryStore(cwd, logger);
|
|
423
|
+
if (dm.ok)
|
|
424
|
+
return dm;
|
|
302
425
|
const p = openPalaceStore(cwd, logger);
|
|
303
426
|
if (p.ok)
|
|
304
427
|
return p;
|
|
305
|
-
return disabledStore('未检测到 prime-memory
|
|
428
|
+
return disabledStore('未检测到 prime-memory / dsh-memory / memory-palace 记忆库');
|
|
306
429
|
}
|