dsh-layered-memory 0.6.0 → 0.7.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.en.md +101 -81
- package/README.md +91 -71
- package/assets/img/Hero.png +0 -0
- package/assets/img/Layers.png +0 -0
- package/assets/img/Modes.png +0 -0
- package/assets/img/ui-dark.jpg +0 -0
- package/assets/img/ui-light.jpg +0 -0
- package/assets/readme/flow.svg +189 -0
- package/assets/readme/storage.svg +115 -0
- package/dist/client.js +1242 -325
- package/dist/config.d.ts +12 -0
- package/dist/config.js +20 -17
- package/dist/hooks/capture.d.ts +17 -1
- package/dist/hooks/capture.js +45 -11
- package/dist/hooks/recall.d.ts +7 -0
- package/dist/hooks/recall.js +20 -4
- package/dist/index.d.ts +8 -0
- package/dist/index.js +112 -44
- package/dist/pipeline/rebuild.d.ts +80 -0
- package/dist/pipeline/rebuild.js +307 -0
- package/dist/pipeline/runner.d.ts +42 -4
- package/dist/pipeline/runner.js +125 -21
- package/dist/settings.js +79 -20
- package/dist/stats.d.ts +8 -1
- package/dist/stats.js +156 -14
- package/dist/store/download-queue.d.ts +71 -0
- package/dist/store/download-queue.js +313 -0
- package/dist/store/embedding-source.d.ts +160 -0
- package/dist/store/embedding-source.js +421 -0
- package/dist/store/embedding.d.ts +3 -1
- package/dist/store/embedding.js +5 -0
- package/dist/store/l0.d.ts +13 -5
- package/dist/store/l0.js +33 -6
- package/dist/store/l1.d.ts +15 -5
- package/dist/store/l1.js +40 -15
- package/dist/store/local-embedding.d.ts +64 -0
- package/dist/store/local-embedding.js +120 -0
- package/dist/store/model-catalog.d.ts +45 -0
- package/dist/store/model-catalog.js +78 -0
- package/dist/store/pending.d.ts +15 -0
- package/dist/store/pending.js +56 -0
- package/dist/store/runtime-installer.d.ts +60 -0
- package/dist/store/runtime-installer.js +181 -0
- package/dist/store/sqlite.d.ts +68 -7
- package/dist/store/sqlite.js +414 -71
- package/dist/store/state.d.ts +6 -0
- package/dist/store/state.js +11 -0
- package/dist/tools/index.js +6 -4
- package/dist/util/filelog.d.ts +2 -0
- package/dist/util/filelog.js +20 -3
- package/package.json +1 -1
- package/assets/readme/hero.svg +0 -58
package/dist/tools/index.js
CHANGED
|
@@ -38,17 +38,18 @@ export function registerMemoryTools(ctx, cfg, stores, logger, modes) {
|
|
|
38
38
|
additionalProperties: false,
|
|
39
39
|
},
|
|
40
40
|
},
|
|
41
|
+
notice: { type: 'string', description: '非搜索结果的状态提示(如本会话记忆已关闭)' },
|
|
41
42
|
},
|
|
42
43
|
additionalProperties: false,
|
|
43
44
|
},
|
|
44
45
|
render: (_args, value) => [
|
|
45
|
-
{ type: 'text', text: renderMemoryItems(value.items ?? []) },
|
|
46
|
+
{ type: 'text', text: value.notice ?? renderMemoryItems(value.items ?? []) },
|
|
46
47
|
],
|
|
47
48
|
},
|
|
48
49
|
execute: async (args, exec) => {
|
|
49
50
|
const family = familyOfCaller(exec.agent?.id);
|
|
50
51
|
if (family === null)
|
|
51
|
-
return { items: [] };
|
|
52
|
+
return { items: [], notice: OFF_NOTICE };
|
|
52
53
|
const limit = Math.min(Math.max(args.limit ?? 5, 1), 20);
|
|
53
54
|
const hits = await stores.l1.search(args.query, limit, { type: args.type || undefined, family: family ?? undefined });
|
|
54
55
|
return {
|
|
@@ -86,16 +87,17 @@ export function registerMemoryTools(ctx, cfg, stores, logger, modes) {
|
|
|
86
87
|
additionalProperties: false,
|
|
87
88
|
},
|
|
88
89
|
},
|
|
90
|
+
notice: { type: 'string', description: '非搜索结果的状态提示(如本会话记忆已关闭)' },
|
|
89
91
|
},
|
|
90
92
|
additionalProperties: false,
|
|
91
93
|
},
|
|
92
94
|
render: (_args, value) => [
|
|
93
|
-
{ type: 'text', text: renderConversationItems(value.items ?? []) },
|
|
95
|
+
{ type: 'text', text: value.notice ?? renderConversationItems(value.items ?? []) },
|
|
94
96
|
],
|
|
95
97
|
},
|
|
96
98
|
execute: async (args, exec) => {
|
|
97
99
|
if (familyOfCaller(exec.agent?.id) === null)
|
|
98
|
-
return { items: [] };
|
|
100
|
+
return { items: [], notice: OFF_NOTICE };
|
|
99
101
|
const limit = Math.min(Math.max(args.limit ?? 5, 1), 20);
|
|
100
102
|
const records = await stores.l0.search(args.query, limit);
|
|
101
103
|
return {
|
package/dist/util/filelog.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { MemoryLogger } from '../types.js';
|
|
2
|
+
/** 体积检查抽样间隔:每 N 条写检查一次,减少同步 stat 系统调用(超限误差 ≤ N 条日志)。 */
|
|
3
|
+
export declare const SIZE_CHECK_INTERVAL = 32;
|
|
2
4
|
/** 错误对象转带堆栈的单行描述(诊断日志用,非 Error 直接字符串化)。 */
|
|
3
5
|
export declare function errDetail(err: unknown): string;
|
|
4
6
|
export declare function withFileLog(dataDir: string, logger: MemoryLogger): MemoryLogger;
|
package/dist/util/filelog.js
CHANGED
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
* 这里镜像 warn/error/info 到数据目录 memory.log,供事后诊断蒸馏管线。
|
|
4
4
|
* 写入失败静默忽略——诊断日志绝不能反过来拖垮管线。
|
|
5
5
|
*/
|
|
6
|
-
import { appendFileSync, existsSync, renameSync, statSync } from 'node:fs';
|
|
6
|
+
import { appendFileSync, existsSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
const MAX_LOG_BYTES = 2 * 1024 * 1024;
|
|
9
|
+
/** 轮转 rename 连续失败多少次后放弃归档、直接截断重开(Windows 文件占用兜底)。 */
|
|
10
|
+
const ROTATE_FAIL_LIMIT = 5;
|
|
11
|
+
/** 体积检查抽样间隔:每 N 条写检查一次,减少同步 stat 系统调用(超限误差 ≤ N 条日志)。 */
|
|
12
|
+
export const SIZE_CHECK_INTERVAL = 32;
|
|
9
13
|
/** 错误对象转带堆栈的单行描述(诊断日志用,非 Error 直接字符串化)。 */
|
|
10
14
|
export function errDetail(err) {
|
|
11
15
|
if (err instanceof Error)
|
|
@@ -14,10 +18,23 @@ export function errDetail(err) {
|
|
|
14
18
|
}
|
|
15
19
|
export function withFileLog(dataDir, logger) {
|
|
16
20
|
const logPath = join(dataDir, 'memory.log');
|
|
21
|
+
let rotateFailures = 0;
|
|
22
|
+
let writesSinceCheck = 0;
|
|
17
23
|
const write = (level, msg) => {
|
|
18
24
|
try {
|
|
19
|
-
if (existsSync(logPath) && statSync(logPath).size > MAX_LOG_BYTES) {
|
|
20
|
-
|
|
25
|
+
if (writesSinceCheck++ % SIZE_CHECK_INTERVAL === 0 && existsSync(logPath) && statSync(logPath).size > MAX_LOG_BYTES) {
|
|
26
|
+
try {
|
|
27
|
+
renameSync(logPath, `${logPath}.1`);
|
|
28
|
+
rotateFailures = 0;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// rename 可能因文件被占用失败(Windows EBUSY):连续失败达上限后
|
|
32
|
+
// 截断重开,保住"日志体积有上界"的底线(放弃 .1 归档,保当前日志可用)
|
|
33
|
+
if (++rotateFailures >= ROTATE_FAIL_LIMIT) {
|
|
34
|
+
writeFileSync(logPath, '');
|
|
35
|
+
rotateFailures = 0;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
21
38
|
}
|
|
22
39
|
appendFileSync(logPath, `${new Date().toISOString()} [${level}] ${msg}\n`);
|
|
23
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-layered-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "L0~L3 分层蒸馏记忆插件 for DeepSeek Harness:自动捕获对话(L0)、抽取原子记忆(L1)、整合场景块(L2)、蒸馏核心画像/团队方法论(L3),并在模型步骤前自动召回注入。移植自 MemoryCore (TencentDB Agent Memory) 的管线设计。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
package/assets/readme/hero.svg
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg"
|
|
2
|
-
width="1200" height="400" viewBox="0 0 1200 400"
|
|
3
|
-
role="img" aria-labelledby="title desc">
|
|
4
|
-
<title id="title">dsh-layered-memory</title>
|
|
5
|
-
<desc id="desc">DeepSeek Harness 分层蒸馏记忆插件:对话经 L0 捕获、L1 原子记忆、L2 场景整合、L3 画像蒸馏四层提炼,宽度递减表示数据精炼;模型每一步前自动召回注入。</desc>
|
|
6
|
-
|
|
7
|
-
<rect width="1200" height="400" rx="26" fill="#0B0E14"/>
|
|
8
|
-
|
|
9
|
-
<!-- ── 标题区 ── -->
|
|
10
|
-
<g id="title-block" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif">
|
|
11
|
-
<text x="64" y="88" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
|
|
12
|
-
font-size="22" letter-spacing="2" fill="#8B93A7">DEEPSEEK HARNESS · PERSISTENT PLUGIN</text>
|
|
13
|
-
<text x="64" y="152" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
|
|
14
|
-
font-size="48" font-weight="700" fill="#F2F3F5">dsh-layered-memory</text>
|
|
15
|
-
<text x="64" y="198" font-size="34" fill="#C9CFDB">对话自动分层蒸馏成记忆,</text>
|
|
16
|
-
<text x="64" y="244" font-size="34" fill="#C9CFDB">模型每步前自动召回注入。</text>
|
|
17
|
-
<text x="64" y="288" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
|
|
18
|
-
font-size="18" fill="#6B7484">MIT LICENSE · v0.5.0 · SESSION-LEVEL MODES</text>
|
|
19
|
-
</g>
|
|
20
|
-
|
|
21
|
-
<!-- ── 分层管线(宽度递减 = 数据精炼) ── -->
|
|
22
|
-
<g id="distill-pipeline">
|
|
23
|
-
<!-- L0 -->
|
|
24
|
-
<rect x="704" y="96" width="436" height="46" rx="12" fill="#11161F" stroke="#232A38" stroke-width="1.5"/>
|
|
25
|
-
<circle cx="732" cy="119" r="6" fill="#2DD4BF"/>
|
|
26
|
-
<text x="760" y="126" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="20" fill="#2DD4BF">L0</text>
|
|
27
|
-
<text x="800" y="126" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif" font-size="20" fill="#F2F3F5">原始对话</text>
|
|
28
|
-
<text x="1120" y="126" text-anchor="end" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="16" fill="#6B7484">conversations/</text>
|
|
29
|
-
<!-- L1 -->
|
|
30
|
-
<rect x="704" y="158" width="396" height="46" rx="12" fill="#11161F" stroke="#232A38" stroke-width="1.5"/>
|
|
31
|
-
<circle cx="732" cy="181" r="6" fill="#2DD4BF"/>
|
|
32
|
-
<text x="760" y="188" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="20" fill="#2DD4BF">L1</text>
|
|
33
|
-
<text x="800" y="188" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif" font-size="20" fill="#F2F3F5">原子记忆</text>
|
|
34
|
-
<text x="1080" y="188" text-anchor="end" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="16" fill="#6B7484">records/</text>
|
|
35
|
-
<!-- L2 -->
|
|
36
|
-
<rect x="704" y="220" width="356" height="46" rx="12" fill="#11161F" stroke="#232A38" stroke-width="1.5"/>
|
|
37
|
-
<circle cx="732" cy="243" r="6" fill="#2DD4BF"/>
|
|
38
|
-
<text x="760" y="250" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="20" fill="#2DD4BF">L2</text>
|
|
39
|
-
<text x="800" y="250" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif" font-size="20" fill="#F2F3F5">场景块</text>
|
|
40
|
-
<text x="1040" y="250" text-anchor="end" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="16" fill="#6B7484">scenes/</text>
|
|
41
|
-
<!-- L3 -->
|
|
42
|
-
<rect x="704" y="282" width="316" height="46" rx="12" fill="#11161F" stroke="#232A38" stroke-width="1.5"/>
|
|
43
|
-
<circle cx="732" cy="305" r="6" fill="#2DD4BF"/>
|
|
44
|
-
<text x="760" y="312" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="20" fill="#2DD4BF">L3</text>
|
|
45
|
-
<text x="800" y="312" font-family="-apple-system,BlinkMacSystemFont,'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif" font-size="20" fill="#F2F3F5">核心画像</text>
|
|
46
|
-
<text x="1010" y="312" text-anchor="end" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="16" fill="#6B7484">persona-*.md</text>
|
|
47
|
-
|
|
48
|
-
<!-- 层间蒸馏箭头(左侧圆点列) -->
|
|
49
|
-
<path d="M732 142 v10 l-5 -5 M732 152 l5 -5" stroke="#2DD4BF" stroke-width="2" fill="none"/>
|
|
50
|
-
<path d="M732 204 v10 l-5 -5 M732 214 l5 -5" stroke="#2DD4BF" stroke-width="2" fill="none"/>
|
|
51
|
-
<path d="M732 266 v10 l-5 -5 M732 276 l5 -5" stroke="#2DD4BF" stroke-width="2" fill="none"/>
|
|
52
|
-
|
|
53
|
-
<!-- 召回回路说明 -->
|
|
54
|
-
<circle cx="716" cy="352" r="5" fill="#F5A623"/>
|
|
55
|
-
<text x="734" y="357" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace"
|
|
56
|
-
font-size="18" fill="#8B93A7">pre-step 自动召回注入 · 与写入同档</text>
|
|
57
|
-
</g>
|
|
58
|
-
</svg>
|