@restregular/dsh-memory 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +69 -2
- package/cordis.patch.yml +10 -0
- package/lib/inject/apply.js +82 -0
- package/lib/inject/inject.js +127 -0
- package/lib/provider/apply.js +108 -0
- package/lib/provider/embed-server.js +296 -0
- package/lib/provider/embed.js +105 -0
- package/lib/provider/index.js +612 -0
- package/lib/provider/rerank-cache.js +64 -0
- package/lib/provider/rerank.js +169 -0
- package/lib/provider/scoring.js +145 -0
- package/lib/provider/secrets.js +57 -0
- package/lib/provider/store.js +485 -0
- package/lib/tools/apply.js +106 -0
- package/lib/tools/index.js +224 -0
- package/package.json +49 -4
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool implementations as plain data + functions. Keeping them free of both
|
|
3
|
+
* cordis and dsh-tools imports lets us unit-test the exact argument/response
|
|
4
|
+
* contracts standalone; the DSH entry (apply.ts) wraps them with defineTool.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/** Shape each tool shares: JSON-schema parameters + canonical output value. */
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export class MemoryToolError extends Error {
|
|
24
|
+
code
|
|
25
|
+
|
|
26
|
+
constructor(code , message ) {
|
|
27
|
+
super(message)
|
|
28
|
+
this.code = code
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function svc(opts ) {
|
|
33
|
+
const s = opts.getService()
|
|
34
|
+
if (!s) throw new MemoryToolError('SERVICE_UNAVAILABLE', 'memory service is not loaded; check that dsh-memory-local is enabled')
|
|
35
|
+
return s
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function scopeOr(opts , scope ) {
|
|
39
|
+
if (scope === 'global') return 'global'
|
|
40
|
+
if (typeof scope === 'string' && scope.startsWith('project:')) return scope
|
|
41
|
+
if (scope === 'project') return opts.defaultScope()
|
|
42
|
+
return opts.defaultScope()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
export function memorySaveTool(opts ) {
|
|
61
|
+
return {
|
|
62
|
+
name: 'memory_save',
|
|
63
|
+
description: 'Save a durable memory (fact, decision, preference, procedure) for future sessions.',
|
|
64
|
+
parameters: {
|
|
65
|
+
content: { type: 'string', description: 'Self-contained declarative sentence, readable without context', required: true },
|
|
66
|
+
scope: { type: 'string', enum: ['global', 'project'], description: 'global = all projects; project = current workspace' },
|
|
67
|
+
kind: { type: 'string', enum: ['fact', 'decision', 'preference', 'procedure', 'note'] },
|
|
68
|
+
tags: { type: 'array', items: { type: 'string' } },
|
|
69
|
+
importance: { type: 'number', description: '0~1, higher = more important' },
|
|
70
|
+
supersedes: { type: 'string', description: 'Record id this corrects/replaces' },
|
|
71
|
+
},
|
|
72
|
+
async execute(args ) {
|
|
73
|
+
if (typeof args.content !== 'string' || args.content.trim().length === 0) {
|
|
74
|
+
throw new MemoryToolError('CONTENT_EMPTY', 'content must be a non-empty string')
|
|
75
|
+
}
|
|
76
|
+
if (args.importance !== undefined && (args.importance < 0 || args.importance > 1)) {
|
|
77
|
+
throw new MemoryToolError('IMPORTANCE_RANGE', 'importance must be between 0 and 1')
|
|
78
|
+
}
|
|
79
|
+
const record = await svc(opts).save({
|
|
80
|
+
scope: scopeOr(opts, args.scope),
|
|
81
|
+
kind: args.kind ?? 'note',
|
|
82
|
+
content: args.content.trim(),
|
|
83
|
+
...(args.tags ? { tags: args.tags } : {}),
|
|
84
|
+
...(args.importance !== undefined ? { importance: args.importance } : {}),
|
|
85
|
+
...(args.supersedes ? { supersedes: args.supersedes } : {}),
|
|
86
|
+
source: { origin: 'explicit' },
|
|
87
|
+
})
|
|
88
|
+
return { id: record.id, scope: record.scope, deduped: false }
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
export function memorySearchTool(opts ) {
|
|
113
|
+
return {
|
|
114
|
+
name: 'memory_search',
|
|
115
|
+
description: 'Search saved memories by keyword or meaning (lexical + local vector recall).',
|
|
116
|
+
parameters: {
|
|
117
|
+
query: { type: 'string', required: true },
|
|
118
|
+
scope: { type: 'string', enum: ['global', 'project'] },
|
|
119
|
+
topK: { type: 'number', description: '1~20' },
|
|
120
|
+
},
|
|
121
|
+
async execute(args ) {
|
|
122
|
+
if (typeof args.query !== 'string' || args.query.trim().length === 0) {
|
|
123
|
+
throw new MemoryToolError('QUERY_EMPTY', 'query must be a non-empty string')
|
|
124
|
+
}
|
|
125
|
+
const hits = await svc(opts).search({
|
|
126
|
+
text: args.query,
|
|
127
|
+
...(args.scope ? { scope: scopeOr(opts, args.scope) } : {}),
|
|
128
|
+
...(args.topK !== undefined ? { topK: args.topK } : {}),
|
|
129
|
+
})
|
|
130
|
+
return {
|
|
131
|
+
records: hits.map((h) => ({
|
|
132
|
+
id: h.record.id,
|
|
133
|
+
score: h.score,
|
|
134
|
+
scope: h.record.scope,
|
|
135
|
+
kind: h.record.kind,
|
|
136
|
+
updatedAt: h.record.updatedAt,
|
|
137
|
+
content: h.record.content,
|
|
138
|
+
})),
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
export function memoryForgetTool(opts ) {
|
|
156
|
+
return {
|
|
157
|
+
name: 'memory_forget',
|
|
158
|
+
description: 'Delete a memory by id, or all memories matching a query in one scope.',
|
|
159
|
+
parameters: {
|
|
160
|
+
id: { type: 'string', description: 'Exact record id' },
|
|
161
|
+
query: { type: 'string', description: 'Substring match within one scope' },
|
|
162
|
+
scope: { type: 'string', enum: ['global', 'project'] },
|
|
163
|
+
},
|
|
164
|
+
async execute(args ) {
|
|
165
|
+
if (!args.id && !args.query) throw new MemoryToolError('TARGET_REQUIRED', 'provide id or query')
|
|
166
|
+
if (args.id && args.query) throw new MemoryToolError('TARGET_AMBIGUOUS', 'provide id or query, not both')
|
|
167
|
+
return svc(opts).forget({
|
|
168
|
+
...(args.id ? { id: args.id } : {}),
|
|
169
|
+
...(args.query ? { query: args.query } : {}),
|
|
170
|
+
...(args.scope ? { scope: scopeOr(opts, args.scope) } : {}),
|
|
171
|
+
})
|
|
172
|
+
},
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
export function memoryListTool(opts ) {
|
|
187
|
+
return {
|
|
188
|
+
name: 'memory_list',
|
|
189
|
+
description: 'List saved memories, most recently updated first.',
|
|
190
|
+
parameters: {
|
|
191
|
+
scope: { type: 'string', enum: ['global', 'project'] },
|
|
192
|
+
kind: { type: 'string' },
|
|
193
|
+
limit: { type: 'number', description: '1~200' },
|
|
194
|
+
},
|
|
195
|
+
async execute(args ) {
|
|
196
|
+
const records = await svc(opts).list({
|
|
197
|
+
...(args.scope ? { scope: scopeOr(opts, args.scope) } : {}),
|
|
198
|
+
...(args.kind ? { kind: args.kind } : {}),
|
|
199
|
+
...(args.limit !== undefined ? { limit: args.limit } : {}),
|
|
200
|
+
})
|
|
201
|
+
return {
|
|
202
|
+
records: records.map((r) => ({
|
|
203
|
+
id: r.id,
|
|
204
|
+
scope: r.scope,
|
|
205
|
+
kind: r.kind,
|
|
206
|
+
updatedAt: r.updatedAt,
|
|
207
|
+
content: r.content,
|
|
208
|
+
})),
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function memoryTools(opts ) {
|
|
215
|
+
return {
|
|
216
|
+
memory_save: memorySaveTool(opts),
|
|
217
|
+
memory_search: memorySearchTool(opts),
|
|
218
|
+
memory_forget: memoryForgetTool(opts),
|
|
219
|
+
memory_list: memoryListTool(opts),
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
//# sourceURL=D:\.deepseek\memory-plugin\packages\tool-memory\src\index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-memory",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "DeepSeek Harness 本地长期记忆:JSONL 存储 + 本地向量检索(BGE-M3)+ 四个模型工具 + 自动召回注入。",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./lib/provider/apply.js",
|
|
8
|
+
"./tools": "./lib/tools/apply.js",
|
|
9
|
+
"./inject": "./lib/inject/apply.js",
|
|
10
|
+
"./package.json": "./package.json"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"lib/",
|
|
14
|
+
"cordis.patch.yml",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"dsh": {
|
|
19
|
+
"bundle": {
|
|
20
|
+
"patch": "./cordis.patch.yml"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@deepseek-ai/cordis": "*",
|
|
25
|
+
"@deepseek-ai/dsh-tools": "*",
|
|
26
|
+
"@deepseek-ai/dsh-llm": "*"
|
|
27
|
+
},
|
|
28
|
+
"peerDependenciesMeta": {
|
|
29
|
+
"@deepseek-ai/cordis": {
|
|
30
|
+
"optional": true
|
|
31
|
+
},
|
|
32
|
+
"@deepseek-ai/dsh-tools": {
|
|
33
|
+
"optional": true
|
|
34
|
+
},
|
|
35
|
+
"@deepseek-ai/dsh-llm": {
|
|
36
|
+
"optional": true
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"dsh-plugin",
|
|
41
|
+
"deepseek-harness",
|
|
42
|
+
"memory",
|
|
43
|
+
"bge-m3",
|
|
44
|
+
"embeddings",
|
|
45
|
+
"recall"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22.13.0"
|
|
49
|
+
},
|
|
50
|
+
"license": "MIT"
|
|
51
|
+
}
|