@modusensus/dsh-mneme 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 +179 -0
- package/lib/api.js +59 -0
- package/lib/client.js +187 -0
- package/lib/config.js +15 -0
- package/lib/dream/decisions.js +121 -0
- package/lib/dream.js +205 -0
- package/lib/index.js +86 -0
- package/lib/inject.js +22 -0
- package/lib/mirror.js +131 -0
- package/lib/service.js +157 -0
- package/lib/store.js +230 -0
- package/lib/summarize.js +171 -0
- package/lib/tools.js +221 -0
- package/package.json +32 -0
- package/src/api.js +59 -0
- package/src/config.js +15 -0
- package/src/dream/decisions.js +121 -0
- package/src/dream.js +205 -0
- package/src/index.js +86 -0
- package/src/inject.js +22 -0
- package/src/mirror.js +131 -0
- package/src/service.js +157 -0
- package/src/store.js +230 -0
- package/src/summarize.js +171 -0
- package/src/tools.js +221 -0
package/src/tools.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2
|
+
|
|
3
|
+
const TEXT_OUTPUT = (text) => [{ type: "text", text }];
|
|
4
|
+
|
|
5
|
+
// Wire shape emitted by service.toApiList: shared by memory_search and
|
|
6
|
+
// memory_list so their output schemas always declare every key the runtime
|
|
7
|
+
// value carries (additionalProperties: false would reject undeclared keys).
|
|
8
|
+
const MEMORY_ITEM_SCHEMA = {
|
|
9
|
+
type: "object",
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
properties: {
|
|
12
|
+
id: { type: "string", required: true },
|
|
13
|
+
type: { type: "string", required: true },
|
|
14
|
+
title: { type: "string", required: true },
|
|
15
|
+
content: { type: "string", required: true },
|
|
16
|
+
tags: { type: "array", items: { type: "string" } },
|
|
17
|
+
importance: { type: "integer", required: true },
|
|
18
|
+
source: { type: "string" },
|
|
19
|
+
created_at: { type: "string", required: true },
|
|
20
|
+
updated_at: { type: "string", required: true }
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function createTools(ctx, service, config) {
|
|
25
|
+
const tools = [
|
|
26
|
+
defineTool({
|
|
27
|
+
name: "memory_save",
|
|
28
|
+
description:
|
|
29
|
+
"Persist one memory entry for future sessions (user preferences, project state, decisions). " +
|
|
30
|
+
"Call this when the user states a durable preference, a project decision is made, or a lesson is learned. " +
|
|
31
|
+
"Merges into an existing entry of the same type when the title matches.",
|
|
32
|
+
parameters: {
|
|
33
|
+
type: { type: "string", required: true, enum: ["preference", "project", "decision", "history"], description: "preference=user profile; project=project knowledge/state; decision=key decision; history=conversation summary" },
|
|
34
|
+
title: { type: "string", required: true, description: "Short unique title" },
|
|
35
|
+
content: { type: "string", required: true, description: "Memory body" },
|
|
36
|
+
tags: { type: "array", items: { type: "string" }, description: "Optional tags" },
|
|
37
|
+
importance: { type: "integer", description: "1-5; >= threshold auto-injects into future sessions" },
|
|
38
|
+
source: { type: "string", description: "Optional provenance" }
|
|
39
|
+
},
|
|
40
|
+
output: {
|
|
41
|
+
schema: {
|
|
42
|
+
type: "object",
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
properties: {
|
|
45
|
+
action: { type: "string", required: true, enum: ["created", "merged"] },
|
|
46
|
+
id: { type: "string", required: true }
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
render: (_args, value) => TEXT_OUTPUT(`memory ${value.action}: ${value.id}`)
|
|
50
|
+
},
|
|
51
|
+
async execute(args) {
|
|
52
|
+
const { action, memory } = service.saveWithDedupe({
|
|
53
|
+
type: args.type,
|
|
54
|
+
title: args.title,
|
|
55
|
+
content: args.content,
|
|
56
|
+
tags: args.tags ?? [],
|
|
57
|
+
importance: args.importance ?? 3,
|
|
58
|
+
source: args.source ?? "tool"
|
|
59
|
+
});
|
|
60
|
+
return { action, id: memory.id };
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
|
|
64
|
+
defineTool({
|
|
65
|
+
name: "memory_search",
|
|
66
|
+
description: "Full-text search the cross-session memory store. Use when you need past context: how a problem was solved, user preferences, project decisions. Returns matching entries with source and timestamps.",
|
|
67
|
+
parameters: {
|
|
68
|
+
query: { type: "string", required: true, description: "Search text; substring match over title/content/tags" },
|
|
69
|
+
limit: { type: "integer", description: "Max results (default 20)" }
|
|
70
|
+
},
|
|
71
|
+
output: {
|
|
72
|
+
schema: {
|
|
73
|
+
type: "object",
|
|
74
|
+
additionalProperties: false,
|
|
75
|
+
properties: {
|
|
76
|
+
items: {
|
|
77
|
+
type: "array", required: true,
|
|
78
|
+
items: MEMORY_ITEM_SCHEMA
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
render: (_args, value) => TEXT_OUTPUT(`Found ${value.items.length} memory entr${value.items.length === 1 ? "y" : "ies"}.`)
|
|
83
|
+
},
|
|
84
|
+
async execute(args) {
|
|
85
|
+
const rows = service.toApiList(service.search(args.query, { limit: args.limit ?? 20 }));
|
|
86
|
+
return { items: rows };
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
|
|
90
|
+
defineTool({
|
|
91
|
+
name: "memory_list",
|
|
92
|
+
description: "List memory entries by type, high-importance first, then newest, paginated.",
|
|
93
|
+
parameters: {
|
|
94
|
+
type: { type: "string", enum: ["preference", "project", "decision", "history"], description: "Filter by type; omit for all" },
|
|
95
|
+
limit: { type: "integer", description: "Page size (default 50)" },
|
|
96
|
+
offset: { type: "integer", description: "Page offset (default 0)" }
|
|
97
|
+
},
|
|
98
|
+
output: {
|
|
99
|
+
schema: {
|
|
100
|
+
type: "object",
|
|
101
|
+
additionalProperties: false,
|
|
102
|
+
properties: {
|
|
103
|
+
items: {
|
|
104
|
+
type: "array", required: true,
|
|
105
|
+
items: MEMORY_ITEM_SCHEMA
|
|
106
|
+
},
|
|
107
|
+
total: { type: "integer", required: true }
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
render: (_args, value) => TEXT_OUTPUT(`${value.items.length} memory entries (of ${value.total}).`)
|
|
111
|
+
},
|
|
112
|
+
async execute(args) {
|
|
113
|
+
const rows = service.toApiList(service.list({ type: args.type, limit: args.limit ?? 50, offset: args.offset ?? 0 }));
|
|
114
|
+
return { items: rows, total: service.count(args.type) };
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
|
|
118
|
+
defineTool({
|
|
119
|
+
name: "memory_update",
|
|
120
|
+
description: "Modify an existing memory entry (title, content, type, tags, importance).",
|
|
121
|
+
parameters: {
|
|
122
|
+
id: { type: "string", required: true, description: "Memory id" },
|
|
123
|
+
title: { type: "string" },
|
|
124
|
+
content: { type: "string" },
|
|
125
|
+
type: { type: "string", enum: ["preference", "project", "decision", "history"] },
|
|
126
|
+
tags: { type: "array", items: { type: "string" } },
|
|
127
|
+
importance: { type: "integer", description: "1-5" }
|
|
128
|
+
},
|
|
129
|
+
output: {
|
|
130
|
+
schema: {
|
|
131
|
+
type: "object",
|
|
132
|
+
additionalProperties: false,
|
|
133
|
+
properties: {
|
|
134
|
+
memory: {
|
|
135
|
+
type: "object",
|
|
136
|
+
additionalProperties: false,
|
|
137
|
+
properties: {
|
|
138
|
+
id: { type: "string", required: true },
|
|
139
|
+
title: { type: "string", required: true },
|
|
140
|
+
content: { type: "string", required: true }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
render: (_args, value) => TEXT_OUTPUT(`Updated memory ${value.memory.id}: ${value.memory.title}`)
|
|
146
|
+
},
|
|
147
|
+
async execute(args) {
|
|
148
|
+
const memory = service.update(args.id, {
|
|
149
|
+
title: args.title,
|
|
150
|
+
content: args.content,
|
|
151
|
+
type: args.type,
|
|
152
|
+
tags: args.tags,
|
|
153
|
+
importance: args.importance
|
|
154
|
+
});
|
|
155
|
+
return { memory: { id: memory.id, title: memory.title, content: memory.content } };
|
|
156
|
+
}
|
|
157
|
+
}),
|
|
158
|
+
|
|
159
|
+
defineTool({
|
|
160
|
+
name: "memory_delete",
|
|
161
|
+
description: "Permanently delete a memory entry.",
|
|
162
|
+
parameters: {
|
|
163
|
+
id: { type: "string", required: true }
|
|
164
|
+
},
|
|
165
|
+
output: {
|
|
166
|
+
schema: {
|
|
167
|
+
type: "object",
|
|
168
|
+
additionalProperties: false,
|
|
169
|
+
properties: { deleted: { type: "boolean", required: true } }
|
|
170
|
+
},
|
|
171
|
+
render: (_args, value) => TEXT_OUTPUT(value.deleted ? "Memory deleted." : "Memory not found.")
|
|
172
|
+
},
|
|
173
|
+
async execute(args) {
|
|
174
|
+
const existed = service.getById(args.id) !== undefined;
|
|
175
|
+
if (existed) service.remove(args.id);
|
|
176
|
+
return { deleted: existed };
|
|
177
|
+
}
|
|
178
|
+
}),
|
|
179
|
+
|
|
180
|
+
defineTool({
|
|
181
|
+
name: "memory_forget",
|
|
182
|
+
description:
|
|
183
|
+
"Stop a memory from being auto-injected and from appearing in searches and lists without deleting it. " +
|
|
184
|
+
"The entry stays in storage; pass forgotten: false to restore it.",
|
|
185
|
+
parameters: {
|
|
186
|
+
id: { type: "string", required: true },
|
|
187
|
+
forgotten: { type: "boolean", description: "Suppress (true, default) or restore (false) the entry's visibility" }
|
|
188
|
+
},
|
|
189
|
+
output: {
|
|
190
|
+
schema: {
|
|
191
|
+
type: "object",
|
|
192
|
+
additionalProperties: false,
|
|
193
|
+
properties: {
|
|
194
|
+
memory: {
|
|
195
|
+
type: "object",
|
|
196
|
+
additionalProperties: false,
|
|
197
|
+
properties: {
|
|
198
|
+
id: { type: "string", required: true },
|
|
199
|
+
forgotten: { type: "boolean", required: true }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
render: (_args, value) => TEXT_OUTPUT(`Memory ${value.memory.id} injection ${value.memory.forgotten ? "suppressed" : "restored"}.`)
|
|
205
|
+
},
|
|
206
|
+
async execute(args) {
|
|
207
|
+
if (service.getById(args.id) === undefined) {
|
|
208
|
+
throw new Error("memory not found");
|
|
209
|
+
}
|
|
210
|
+
const memory = service.setForget(args.id, args.forgotten ?? true);
|
|
211
|
+
return { memory: { id: memory.id, forgotten: memory.forgotten } };
|
|
212
|
+
}
|
|
213
|
+
})
|
|
214
|
+
];
|
|
215
|
+
|
|
216
|
+
for (const tool of tools) {
|
|
217
|
+
ctx.tools.register(tool);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return tools;
|
|
221
|
+
}
|