@modusensus/dsh-mneme 0.7.24 → 0.7.25
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 +8 -1
- package/README.md +8 -1
- package/lib/api-standalone.js +43 -3
- package/lib/client.js +7 -2
- package/lib/config.js +13 -0
- package/lib/tools.js +76 -3
- package/package.json +3 -5
- package/src/api-standalone.js +43 -3
- package/src/config.js +13 -0
- package/src/tools.js +76 -3
- package/test/client.test.js +1 -1
- package/test/tools.test.js +54 -3
package/README.en.md
CHANGED
|
@@ -66,7 +66,14 @@ The default `32768` reserves headroom for reasoning models, where reasoning alon
|
|
|
66
66
|
| Medium (10k–50k chars) | `65536` |
|
|
67
67
|
| Large (>50k chars) | `131072` (cap) |
|
|
68
68
|
|
|
69
|
-
> With **reasoning models** (e.g. DeepSeek-R1-like), the model may spend the entire budget on reasoning and return an empty body (the log shows `no json array in llm output`). Resolution order: ① set `dreamReasoningEffort` to `low` to suppress reasoning overhead (when the provider rejects the parameter it is stripped automatically and retried once — the rejection reason lands in `llm_audit
|
|
69
|
+
> With **reasoning models** (e.g. DeepSeek-R1-like), the model may spend the entire budget on reasoning and return an empty body (the log shows `no json array in llm output`). Resolution order: ① set `dreamReasoningEffort` to `low` to suppress reasoning overhead (when the provider rejects the parameter it is stripped automatically and retried once — the rejection reason lands in `llm_audit`); ② if the retry still returns an empty body under the model's default reasoning behavior, raise `dreamMaxTokens` (reasoning and body share this budget) or route `dreamProvider`/`dreamModel` to a non-reasoning model. The sleep side has the corresponding `sleepReasoningEffort`.
|
|
70
|
+
|
|
71
|
+
**Consolidation model classification** (settings panel "consolidation model" = `dreamProvider`/`dreamModel`; sleep side: `sleepProvider`/`sleepModel`):
|
|
72
|
+
|
|
73
|
+
| Model kind | Examples | Notes |
|
|
74
|
+
|-----------|----------|-------|
|
|
75
|
+
| **Non-reasoning (recommended)** | glm-5-2-class | No reasoning declaration; even if an effort is configured and the harness rejects it, the fallback strips the field and the retry succeeds. Lowest risk of empty-body runs |
|
|
76
|
+
| **Reasoning (test first)** | deepseek-v4-flash-ga and other v4-flash-ga family | Reasons by default and may burn the whole token budget on an empty body; some SKUs (e.g. v4-flash-ga) are additionally declared by the harness as accepting **no reasoning effort at all** — the no-effort retry still gets rejected through the harness `defaultEffort` (`UNSUPPORTED_REASONING_EFFORT`), which the plugin fallback cannot bypass. If you use one, set `dreamReasoningEffort` and test; switch to a non-reasoning model otherwise |
|
|
70
77
|
|
|
71
78
|
### Sleep Mode: System-Level Sleep 💤 (v0.4.0, opt-in)
|
|
72
79
|
|
package/README.md
CHANGED
|
@@ -89,7 +89,14 @@ dsh web
|
|
|
89
89
|
| 中等(1 万-5 万字) | `65536` |
|
|
90
90
|
| 大型(5 万字以上) | `131072`(上限) |
|
|
91
91
|
|
|
92
|
-
> 若使用**思考型模型**(如 deepseek-v4-flash / DeepSeek-R1 类),模型可能把全部预算花在 reasoning 上导致正文为空(日志出现 `no json array in llm output`)。处理顺序:① 把 `dreamReasoningEffort` 设为 `low` 显式压低思考(被方舟拒绝该参数时自动去掉重试一次,拒绝原因会记入 llm_audit
|
|
92
|
+
> 若使用**思考型模型**(如 deepseek-v4-flash / DeepSeek-R1 类),模型可能把全部预算花在 reasoning 上导致正文为空(日志出现 `no json array in llm output`)。处理顺序:① 把 `dreamReasoningEffort` 设为 `low` 显式压低思考(被方舟拒绝该参数时自动去掉重试一次,拒绝原因会记入 llm_audit);② 重试走模型默认思考行为后正文仍为空的,调大 `dreamMaxTokens`(reasoning 与正文共享该预算)或配置 `dreamProvider`/`dreamModel` 指向非思考模型。sleep 侧对应 `sleepReasoningEffort`。
|
|
93
|
+
|
|
94
|
+
**巩固模型分类声明**(settings panel「巩固模型」= `dreamProvider`/`dreamModel`,睡眠侧对应 `sleepProvider`/`sleepModel`):
|
|
95
|
+
|
|
96
|
+
| 模型类别 | 例子 | 说明 |
|
|
97
|
+
|---------|------|------|
|
|
98
|
+
| **非思考模型(推荐)** | glm-5-2 类等 | 无 reasoning 声明;即使配了 effort 被 harness 拒绝,fallback 去掉字段重试即成功。空体风险最低 |
|
|
99
|
+
| **思考模型(需实测)** | deepseek-v4-flash-ga 等 v4-flash-ga 系 | 默认开推理,可能烧光 token 预算返回空体;且部分型号(如 v4-flash-ga)在 harness 侧被声明为**不接受任何 reasoning effort** —— 去掉 effort 重试时 harness 的 `defaultEffort` 仍会顶上来再次拒绝(`UNSUPPORTED_REASONING_EFFORT`),插件侧 fallback 无法绕开。选用时建议配 `dreamReasoningEffort` 实测,不行就换非思考模型 |
|
|
93
100
|
|
|
94
101
|
### Sleep Mode 系统级睡眠 💤(v0.4.0,opt-in)
|
|
95
102
|
|
package/lib/api-standalone.js
CHANGED
|
@@ -16,6 +16,46 @@ const DEFAULT_HOST = "127.0.0.1";
|
|
|
16
16
|
// Hardcoded release version (package.json is bumped at publish time and may
|
|
17
17
|
// lag the code that ships in between).
|
|
18
18
|
const VERSION = "0.7.12";
|
|
19
|
+
const MAX_PORT_ATTEMPTS = 20;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Listen with automatic EADDRINUSE recovery. Tries the configured port, then
|
|
23
|
+
* the next MAX_PORT_ATTEMPTS-1 ports, and finally falls back to port 0 so the
|
|
24
|
+
* OS assigns a free port. Multiple DSH profiles/instances sharing the default
|
|
25
|
+
* port no longer leave the standalone API permanently unavailable.
|
|
26
|
+
*/
|
|
27
|
+
function listenWithRetry(server, startPort, host, logger) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
let attempt = 0;
|
|
30
|
+
const tryListen = (port) => {
|
|
31
|
+
const onListening = () => {
|
|
32
|
+
server.off("error", onError);
|
|
33
|
+
const address = server.address();
|
|
34
|
+
resolve(address && typeof address === "object" ? address.port : port);
|
|
35
|
+
};
|
|
36
|
+
const onError = (error) => {
|
|
37
|
+
server.off("listening", onListening);
|
|
38
|
+
if (error?.code === "EADDRINUSE" && attempt < MAX_PORT_ATTEMPTS - 1) {
|
|
39
|
+
attempt++;
|
|
40
|
+
const next = startPort + attempt;
|
|
41
|
+
logger?.warn?.(`[dsh-mneme] standalone API port ${port} in use, retrying ${next}`);
|
|
42
|
+
tryListen(next);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (error?.code === "EADDRINUSE") {
|
|
46
|
+
logger?.warn?.(`[dsh-mneme] standalone API port ${port} still in use, falling back to OS-assigned port`);
|
|
47
|
+
tryListen(0);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
reject(error);
|
|
51
|
+
};
|
|
52
|
+
server.once("listening", onListening);
|
|
53
|
+
server.once("error", onError);
|
|
54
|
+
server.listen(port, host);
|
|
55
|
+
};
|
|
56
|
+
tryListen(startPort);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
19
59
|
|
|
20
60
|
function sendJson(res, status, payload) {
|
|
21
61
|
res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
|
|
@@ -243,10 +283,10 @@ export function createStandaloneApi({ service, store, config = {}, logger, setti
|
|
|
243
283
|
logger?.warn?.(`[dsh-mneme] standalone API error: ${String(error)}`);
|
|
244
284
|
});
|
|
245
285
|
const ready = new Promise((resolve, reject) => {
|
|
246
|
-
|
|
247
|
-
server.
|
|
286
|
+
// listening handled by listenWithRetry
|
|
287
|
+
listenWithRetry(server, boundPort, boundHost, logger).then(resolve, reject);
|
|
248
288
|
});
|
|
249
|
-
server.listen
|
|
289
|
+
// server.listen is called inside listenWithRetry
|
|
250
290
|
ready.then(() => {
|
|
251
291
|
const address = server.address();
|
|
252
292
|
if (address && typeof address === "object") {
|
package/lib/client.js
CHANGED
|
@@ -3610,9 +3610,14 @@ window.__ModuleLoader__.load({
|
|
|
3610
3610
|
if (dead) return;
|
|
3611
3611
|
const reg = bsCtx.betterSidebar;
|
|
3612
3612
|
if (!reg || typeof reg.registerTab !== "function") return;
|
|
3613
|
+
const TAB_ID = "dsh-mneme:memory";
|
|
3614
|
+
if (typeof reg.getTab === "function" && reg.getTab(TAB_ID)) {
|
|
3615
|
+
console.warn(`[dsh-mneme] better-sidebar tab "${TAB_ID}" already registered, skipping duplicate`);
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3613
3618
|
try {
|
|
3614
3619
|
reg.registerTab({
|
|
3615
|
-
id:
|
|
3620
|
+
id: TAB_ID,
|
|
3616
3621
|
title: () => t("memory.view.label"),
|
|
3617
3622
|
icon: (size) => h(IconArchiveOutline20, { size }),
|
|
3618
3623
|
order: 60,
|
|
@@ -3620,7 +3625,7 @@ window.__ModuleLoader__.load({
|
|
|
3620
3625
|
});
|
|
3621
3626
|
} catch (err) {
|
|
3622
3627
|
// id 重复等注册失败不应拖垮其余功能,留一条线索即可
|
|
3623
|
-
console.
|
|
3628
|
+
console.warn("[dsh-mneme] better-sidebar registerTab failed, falling back to native sidebar entry:", err);
|
|
3624
3629
|
}
|
|
3625
3630
|
}, "dsh-mneme: better-sidebar tab");
|
|
3626
3631
|
}
|
package/lib/config.js
CHANGED
|
@@ -52,6 +52,16 @@ export const Config = z.object({
|
|
|
52
52
|
// 起算,失败/degraded 的 run 也占用间隔;间隔内的触发请求静默跳过,下一次
|
|
53
53
|
// 写入事件会重新评估。
|
|
54
54
|
dreamMinIntervalMinutes: z.natural().min(0).max(10080).default(0),
|
|
55
|
+
// 巩固模型路由(settings panel「巩固模型」/ dreamProvider+dreamModel):
|
|
56
|
+
// dream 的记忆沉淀专用 LLM 路由,显式配置优先于 agent 默认模型(config-first,
|
|
57
|
+
// Issue #25)。模型分类声明:
|
|
58
|
+
// - 非思考模型(推荐,如 glm-5-2 类):无 reasoning 声明,effort 请求被 harness
|
|
59
|
+
// 拒绝后 withEffortFallback 去掉字段重试即成功;空体/no json array 风险最低。
|
|
60
|
+
// - 思考模型(如 deepseek-v4-flash-ga 等 v4-flash-ga 系):默认开推理,可能烧光
|
|
61
|
+
// token 预算返回空体;且部分(如 v4-flash-ga)在 harness 侧被声明为不接受任何
|
|
62
|
+
// reasoning effort —— 即使去掉 effort 重试,harness 的 defaultEffort 也会顶上来
|
|
63
|
+
// 再次拒绝(UNSUPPORTED_REASONING_EFFORT),插件 fallback 无法绕开。
|
|
64
|
+
// 选用时建议配 dreamReasoningEffort 并实测;不行就换非思考模型。
|
|
55
65
|
dreamProvider: z.string(),
|
|
56
66
|
dreamModel: z.string(),
|
|
57
67
|
dreamMaxTokens: z.natural().min(256).max(131072).default(32768),
|
|
@@ -60,6 +70,9 @@ export const Config = z.object({
|
|
|
60
70
|
// are forwarded verbatim. Useful to cap reasoning spend on thinking-type
|
|
61
71
|
// models that would otherwise drain the whole token budget and return an
|
|
62
72
|
// empty body ("no json array in llm output").
|
|
73
|
+
// Caveat: on some thinking models (e.g. v4-flash-ga) the harness declares NO
|
|
74
|
+
// supported effort, so even the fallback retry (field stripped) is rejected
|
|
75
|
+
// again via its defaultEffort — prefer a non-reasoning dreamProvider/dreamModel.
|
|
63
76
|
dreamReasoningEffort: z.union([
|
|
64
77
|
z.const("low"),
|
|
65
78
|
z.const("medium"),
|
package/lib/tools.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2
2
|
|
|
3
3
|
const TEXT_OUTPUT = (text) => [{ type: "text", text }];
|
|
4
|
+
// Per-registry tool-name registry: guards against duplicate registration on
|
|
5
|
+
// live patch reload (DSH Desktop `patchReload: "live"`) where a plugin may be
|
|
6
|
+
// re-applied on the same tools registry without an intervening unregister.
|
|
7
|
+
const REGISTERED_TOOLS = new WeakMap();
|
|
4
8
|
|
|
5
9
|
// Wire shape emitted by service.toApiList: shared by memory_search and
|
|
6
10
|
// memory_list so their output schemas always declare every key the runtime
|
|
@@ -22,6 +26,12 @@ const MEMORY_ITEM_SCHEMA = {
|
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
export function createTools(ctx, service, config, embedder) {
|
|
29
|
+
const toolsRegistry = ctx.tools;
|
|
30
|
+
let registeredTools = REGISTERED_TOOLS.get(toolsRegistry);
|
|
31
|
+
if (!registeredTools) {
|
|
32
|
+
registeredTools = new Set();
|
|
33
|
+
REGISTERED_TOOLS.set(toolsRegistry, registeredTools);
|
|
34
|
+
}
|
|
25
35
|
const tools = [
|
|
26
36
|
defineTool({
|
|
27
37
|
name: "memory_save",
|
|
@@ -82,7 +92,18 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
},
|
|
85
|
-
render: (_args, value) =>
|
|
95
|
+
render: (_args, value) => {
|
|
96
|
+
const items = value.items ?? [];
|
|
97
|
+
if (items.length === 0) return TEXT_OUTPUT("No memory entries found.");
|
|
98
|
+
const body = items
|
|
99
|
+
.map((m, i) => {
|
|
100
|
+
const preview = (m.content ?? "").replace(/\s+/g, " ").trim();
|
|
101
|
+
const cut = preview.length > 200 ? `${preview.slice(0, 200)}…` : preview;
|
|
102
|
+
return `[${i + 1}] ${m.title}\n ID: ${m.id} | type: ${m.type} | importance: ${m.importance} | updated: ${m.updated_at}\n ${cut}`;
|
|
103
|
+
})
|
|
104
|
+
.join("\n\n");
|
|
105
|
+
return TEXT_OUTPUT(`Found ${items.length} memory entr${items.length === 1 ? "y" : "ies"}:\n\n${body}`);
|
|
106
|
+
}
|
|
86
107
|
},
|
|
87
108
|
async execute(args) {
|
|
88
109
|
const limit = args.limit ?? 20;
|
|
@@ -117,7 +138,14 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
117
138
|
total: { type: "integer", required: true }
|
|
118
139
|
}
|
|
119
140
|
},
|
|
120
|
-
render: (_args, value) =>
|
|
141
|
+
render: (_args, value) => {
|
|
142
|
+
const items = value.items ?? [];
|
|
143
|
+
if (items.length === 0) return TEXT_OUTPUT(`0 memory entries (of ${value.total}).`);
|
|
144
|
+
const body = items
|
|
145
|
+
.map((m, i) => `[${i + 1}] ${m.title} (type=${m.type}, importance=${m.importance})\n ID: ${m.id} | updated: ${m.updated_at}`)
|
|
146
|
+
.join("\n\n");
|
|
147
|
+
return TEXT_OUTPUT(`${items.length} memory entries (of ${value.total}):\n\n${body}`);
|
|
148
|
+
}
|
|
121
149
|
},
|
|
122
150
|
async execute(args) {
|
|
123
151
|
const includeArchived = args.include_archived === true;
|
|
@@ -131,6 +159,46 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
131
159
|
}
|
|
132
160
|
}),
|
|
133
161
|
|
|
162
|
+
defineTool({
|
|
163
|
+
name: "memory_get",
|
|
164
|
+
description: "Fetch one memory entry by ID and return its full content as text. Use after memory_list to read a specific entry.",
|
|
165
|
+
parameters: {
|
|
166
|
+
id: { type: "string", required: true, description: "Memory id" }
|
|
167
|
+
},
|
|
168
|
+
output: {
|
|
169
|
+
schema: {
|
|
170
|
+
type: "object",
|
|
171
|
+
additionalProperties: false,
|
|
172
|
+
properties: {
|
|
173
|
+
memory: {
|
|
174
|
+
type: "object",
|
|
175
|
+
additionalProperties: false,
|
|
176
|
+
properties: {
|
|
177
|
+
id: { type: "string", required: true },
|
|
178
|
+
title: { type: "string", required: true },
|
|
179
|
+
type: { type: "string", required: true },
|
|
180
|
+
importance: { type: "integer", required: true },
|
|
181
|
+
tags: { type: "array", items: { type: "string" } },
|
|
182
|
+
content: { type: "string", required: true },
|
|
183
|
+
source: { type: "string" },
|
|
184
|
+
created_at: { type: "string" },
|
|
185
|
+
updated_at: { type: "string" }
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
render: (_args, value) => {
|
|
191
|
+
const m = value.memory;
|
|
192
|
+
return TEXT_OUTPUT(`${m.title}\nID: ${m.id} | type: ${m.type} | importance: ${m.importance}\n\n${m.content}`);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
async execute(args) {
|
|
196
|
+
const memory = service.getById(args.id);
|
|
197
|
+
if (memory === undefined) throw new Error("memory not found");
|
|
198
|
+
return { memory: service.toApiList([memory])[0] };
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
|
|
134
202
|
defineTool({
|
|
135
203
|
name: "memory_update",
|
|
136
204
|
description: "Modify an existing memory entry (title, content, type, tags, importance).",
|
|
@@ -267,7 +335,12 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
267
335
|
];
|
|
268
336
|
|
|
269
337
|
for (const tool of tools) {
|
|
270
|
-
|
|
338
|
+
if (registeredTools.has(tool.name)) {
|
|
339
|
+
ctx.logger?.warn?.(`[dsh-mneme] tool "${tool.name}" already registered, skipping duplicate`);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
registeredTools.add(tool.name);
|
|
343
|
+
ctx.tools.register(tool);
|
|
271
344
|
}
|
|
272
345
|
|
|
273
346
|
return tools;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modusensus/dsh-mneme",
|
|
3
3
|
"description": "Cross-session memory plugin for DeepSeek Harness with autoDream consolidation: SQLite store, Markdown mirrors, 7 model tools, automatic injection, session summarization, user profile/rules, custom slash commands, vector (semantic) search, and a Web GUI panel",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.25",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -37,9 +37,7 @@
|
|
|
37
37
|
"client": {
|
|
38
38
|
"inject": [
|
|
39
39
|
"slots",
|
|
40
|
-
"locale"
|
|
41
|
-
"layout",
|
|
42
|
-
"connection"
|
|
40
|
+
"locale"
|
|
43
41
|
],
|
|
44
42
|
"platform": "web"
|
|
45
43
|
},
|
|
@@ -54,7 +52,7 @@
|
|
|
54
52
|
"@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6",
|
|
55
53
|
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
|
|
56
54
|
"@deepseek-ai/schemastery": "^3.18.1",
|
|
57
|
-
"dsh-better-sidebar": "
|
|
55
|
+
"dsh-better-sidebar": "^0.18.0"
|
|
58
56
|
},
|
|
59
57
|
"peerDependenciesMeta": {
|
|
60
58
|
"dsh-better-sidebar": {
|
package/src/api-standalone.js
CHANGED
|
@@ -16,6 +16,46 @@ const DEFAULT_HOST = "127.0.0.1";
|
|
|
16
16
|
// Hardcoded release version (package.json is bumped at publish time and may
|
|
17
17
|
// lag the code that ships in between).
|
|
18
18
|
const VERSION = "0.7.12";
|
|
19
|
+
const MAX_PORT_ATTEMPTS = 20;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Listen with automatic EADDRINUSE recovery. Tries the configured port, then
|
|
23
|
+
* the next MAX_PORT_ATTEMPTS-1 ports, and finally falls back to port 0 so the
|
|
24
|
+
* OS assigns a free port. Multiple DSH profiles/instances sharing the default
|
|
25
|
+
* port no longer leave the standalone API permanently unavailable.
|
|
26
|
+
*/
|
|
27
|
+
function listenWithRetry(server, startPort, host, logger) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
let attempt = 0;
|
|
30
|
+
const tryListen = (port) => {
|
|
31
|
+
const onListening = () => {
|
|
32
|
+
server.off("error", onError);
|
|
33
|
+
const address = server.address();
|
|
34
|
+
resolve(address && typeof address === "object" ? address.port : port);
|
|
35
|
+
};
|
|
36
|
+
const onError = (error) => {
|
|
37
|
+
server.off("listening", onListening);
|
|
38
|
+
if (error?.code === "EADDRINUSE" && attempt < MAX_PORT_ATTEMPTS - 1) {
|
|
39
|
+
attempt++;
|
|
40
|
+
const next = startPort + attempt;
|
|
41
|
+
logger?.warn?.(`[dsh-mneme] standalone API port ${port} in use, retrying ${next}`);
|
|
42
|
+
tryListen(next);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (error?.code === "EADDRINUSE") {
|
|
46
|
+
logger?.warn?.(`[dsh-mneme] standalone API port ${port} still in use, falling back to OS-assigned port`);
|
|
47
|
+
tryListen(0);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
reject(error);
|
|
51
|
+
};
|
|
52
|
+
server.once("listening", onListening);
|
|
53
|
+
server.once("error", onError);
|
|
54
|
+
server.listen(port, host);
|
|
55
|
+
};
|
|
56
|
+
tryListen(startPort);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
19
59
|
|
|
20
60
|
function sendJson(res, status, payload) {
|
|
21
61
|
res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
|
|
@@ -243,10 +283,10 @@ export function createStandaloneApi({ service, store, config = {}, logger, setti
|
|
|
243
283
|
logger?.warn?.(`[dsh-mneme] standalone API error: ${String(error)}`);
|
|
244
284
|
});
|
|
245
285
|
const ready = new Promise((resolve, reject) => {
|
|
246
|
-
|
|
247
|
-
server.
|
|
286
|
+
// listening handled by listenWithRetry
|
|
287
|
+
listenWithRetry(server, boundPort, boundHost, logger).then(resolve, reject);
|
|
248
288
|
});
|
|
249
|
-
server.listen
|
|
289
|
+
// server.listen is called inside listenWithRetry
|
|
250
290
|
ready.then(() => {
|
|
251
291
|
const address = server.address();
|
|
252
292
|
if (address && typeof address === "object") {
|
package/src/config.js
CHANGED
|
@@ -52,6 +52,16 @@ export const Config = z.object({
|
|
|
52
52
|
// 起算,失败/degraded 的 run 也占用间隔;间隔内的触发请求静默跳过,下一次
|
|
53
53
|
// 写入事件会重新评估。
|
|
54
54
|
dreamMinIntervalMinutes: z.natural().min(0).max(10080).default(0),
|
|
55
|
+
// 巩固模型路由(settings panel「巩固模型」/ dreamProvider+dreamModel):
|
|
56
|
+
// dream 的记忆沉淀专用 LLM 路由,显式配置优先于 agent 默认模型(config-first,
|
|
57
|
+
// Issue #25)。模型分类声明:
|
|
58
|
+
// - 非思考模型(推荐,如 glm-5-2 类):无 reasoning 声明,effort 请求被 harness
|
|
59
|
+
// 拒绝后 withEffortFallback 去掉字段重试即成功;空体/no json array 风险最低。
|
|
60
|
+
// - 思考模型(如 deepseek-v4-flash-ga 等 v4-flash-ga 系):默认开推理,可能烧光
|
|
61
|
+
// token 预算返回空体;且部分(如 v4-flash-ga)在 harness 侧被声明为不接受任何
|
|
62
|
+
// reasoning effort —— 即使去掉 effort 重试,harness 的 defaultEffort 也会顶上来
|
|
63
|
+
// 再次拒绝(UNSUPPORTED_REASONING_EFFORT),插件 fallback 无法绕开。
|
|
64
|
+
// 选用时建议配 dreamReasoningEffort 并实测;不行就换非思考模型。
|
|
55
65
|
dreamProvider: z.string(),
|
|
56
66
|
dreamModel: z.string(),
|
|
57
67
|
dreamMaxTokens: z.natural().min(256).max(131072).default(32768),
|
|
@@ -60,6 +70,9 @@ export const Config = z.object({
|
|
|
60
70
|
// are forwarded verbatim. Useful to cap reasoning spend on thinking-type
|
|
61
71
|
// models that would otherwise drain the whole token budget and return an
|
|
62
72
|
// empty body ("no json array in llm output").
|
|
73
|
+
// Caveat: on some thinking models (e.g. v4-flash-ga) the harness declares NO
|
|
74
|
+
// supported effort, so even the fallback retry (field stripped) is rejected
|
|
75
|
+
// again via its defaultEffort — prefer a non-reasoning dreamProvider/dreamModel.
|
|
63
76
|
dreamReasoningEffort: z.union([
|
|
64
77
|
z.const("low"),
|
|
65
78
|
z.const("medium"),
|
package/src/tools.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2
2
|
|
|
3
3
|
const TEXT_OUTPUT = (text) => [{ type: "text", text }];
|
|
4
|
+
// Per-registry tool-name registry: guards against duplicate registration on
|
|
5
|
+
// live patch reload (DSH Desktop `patchReload: "live"`) where a plugin may be
|
|
6
|
+
// re-applied on the same tools registry without an intervening unregister.
|
|
7
|
+
const REGISTERED_TOOLS = new WeakMap();
|
|
4
8
|
|
|
5
9
|
// Wire shape emitted by service.toApiList: shared by memory_search and
|
|
6
10
|
// memory_list so their output schemas always declare every key the runtime
|
|
@@ -22,6 +26,12 @@ const MEMORY_ITEM_SCHEMA = {
|
|
|
22
26
|
};
|
|
23
27
|
|
|
24
28
|
export function createTools(ctx, service, config, embedder) {
|
|
29
|
+
const toolsRegistry = ctx.tools;
|
|
30
|
+
let registeredTools = REGISTERED_TOOLS.get(toolsRegistry);
|
|
31
|
+
if (!registeredTools) {
|
|
32
|
+
registeredTools = new Set();
|
|
33
|
+
REGISTERED_TOOLS.set(toolsRegistry, registeredTools);
|
|
34
|
+
}
|
|
25
35
|
const tools = [
|
|
26
36
|
defineTool({
|
|
27
37
|
name: "memory_save",
|
|
@@ -82,7 +92,18 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
},
|
|
85
|
-
render: (_args, value) =>
|
|
95
|
+
render: (_args, value) => {
|
|
96
|
+
const items = value.items ?? [];
|
|
97
|
+
if (items.length === 0) return TEXT_OUTPUT("No memory entries found.");
|
|
98
|
+
const body = items
|
|
99
|
+
.map((m, i) => {
|
|
100
|
+
const preview = (m.content ?? "").replace(/\s+/g, " ").trim();
|
|
101
|
+
const cut = preview.length > 200 ? `${preview.slice(0, 200)}…` : preview;
|
|
102
|
+
return `[${i + 1}] ${m.title}\n ID: ${m.id} | type: ${m.type} | importance: ${m.importance} | updated: ${m.updated_at}\n ${cut}`;
|
|
103
|
+
})
|
|
104
|
+
.join("\n\n");
|
|
105
|
+
return TEXT_OUTPUT(`Found ${items.length} memory entr${items.length === 1 ? "y" : "ies"}:\n\n${body}`);
|
|
106
|
+
}
|
|
86
107
|
},
|
|
87
108
|
async execute(args) {
|
|
88
109
|
const limit = args.limit ?? 20;
|
|
@@ -117,7 +138,14 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
117
138
|
total: { type: "integer", required: true }
|
|
118
139
|
}
|
|
119
140
|
},
|
|
120
|
-
render: (_args, value) =>
|
|
141
|
+
render: (_args, value) => {
|
|
142
|
+
const items = value.items ?? [];
|
|
143
|
+
if (items.length === 0) return TEXT_OUTPUT(`0 memory entries (of ${value.total}).`);
|
|
144
|
+
const body = items
|
|
145
|
+
.map((m, i) => `[${i + 1}] ${m.title} (type=${m.type}, importance=${m.importance})\n ID: ${m.id} | updated: ${m.updated_at}`)
|
|
146
|
+
.join("\n\n");
|
|
147
|
+
return TEXT_OUTPUT(`${items.length} memory entries (of ${value.total}):\n\n${body}`);
|
|
148
|
+
}
|
|
121
149
|
},
|
|
122
150
|
async execute(args) {
|
|
123
151
|
const includeArchived = args.include_archived === true;
|
|
@@ -131,6 +159,46 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
131
159
|
}
|
|
132
160
|
}),
|
|
133
161
|
|
|
162
|
+
defineTool({
|
|
163
|
+
name: "memory_get",
|
|
164
|
+
description: "Fetch one memory entry by ID and return its full content as text. Use after memory_list to read a specific entry.",
|
|
165
|
+
parameters: {
|
|
166
|
+
id: { type: "string", required: true, description: "Memory id" }
|
|
167
|
+
},
|
|
168
|
+
output: {
|
|
169
|
+
schema: {
|
|
170
|
+
type: "object",
|
|
171
|
+
additionalProperties: false,
|
|
172
|
+
properties: {
|
|
173
|
+
memory: {
|
|
174
|
+
type: "object",
|
|
175
|
+
additionalProperties: false,
|
|
176
|
+
properties: {
|
|
177
|
+
id: { type: "string", required: true },
|
|
178
|
+
title: { type: "string", required: true },
|
|
179
|
+
type: { type: "string", required: true },
|
|
180
|
+
importance: { type: "integer", required: true },
|
|
181
|
+
tags: { type: "array", items: { type: "string" } },
|
|
182
|
+
content: { type: "string", required: true },
|
|
183
|
+
source: { type: "string" },
|
|
184
|
+
created_at: { type: "string" },
|
|
185
|
+
updated_at: { type: "string" }
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
render: (_args, value) => {
|
|
191
|
+
const m = value.memory;
|
|
192
|
+
return TEXT_OUTPUT(`${m.title}\nID: ${m.id} | type: ${m.type} | importance: ${m.importance}\n\n${m.content}`);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
async execute(args) {
|
|
196
|
+
const memory = service.getById(args.id);
|
|
197
|
+
if (memory === undefined) throw new Error("memory not found");
|
|
198
|
+
return { memory: service.toApiList([memory])[0] };
|
|
199
|
+
}
|
|
200
|
+
}),
|
|
201
|
+
|
|
134
202
|
defineTool({
|
|
135
203
|
name: "memory_update",
|
|
136
204
|
description: "Modify an existing memory entry (title, content, type, tags, importance).",
|
|
@@ -267,7 +335,12 @@ export function createTools(ctx, service, config, embedder) {
|
|
|
267
335
|
];
|
|
268
336
|
|
|
269
337
|
for (const tool of tools) {
|
|
270
|
-
|
|
338
|
+
if (registeredTools.has(tool.name)) {
|
|
339
|
+
ctx.logger?.warn?.(`[dsh-mneme] tool "${tool.name}" already registered, skipping duplicate`);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
registeredTools.add(tool.name);
|
|
343
|
+
ctx.tools.register(tool);
|
|
271
344
|
}
|
|
272
345
|
|
|
273
346
|
return tools;
|
package/test/client.test.js
CHANGED
|
@@ -235,7 +235,7 @@ test("better-sidebar tab mounts via an inner sub-plugin, standalone mode intact"
|
|
|
235
235
|
"the inner apply must still guard the service shape before registering"
|
|
236
236
|
);
|
|
237
237
|
assert.ok(
|
|
238
|
-
/id: "dsh-mneme:memory"/.test(clientSource),
|
|
238
|
+
/(?:const TAB_ID = |id: )"dsh-mneme:memory"/.test(clientSource),
|
|
239
239
|
"the registered tab id must be package-prefixed"
|
|
240
240
|
);
|
|
241
241
|
assert.ok(
|
package/test/tools.test.js
CHANGED
|
@@ -44,15 +44,15 @@ function walkSchema(node, path, problems) {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
test("registers
|
|
47
|
+
test("registers eight tools with correct names", () => {
|
|
48
48
|
const { registered } = setup();
|
|
49
49
|
const names = registered.map((t) => t.name).sort();
|
|
50
|
-
assert.deepEqual(names, ["memory_archive", "memory_delete", "memory_forget", "memory_list", "memory_save", "memory_search", "memory_update"]);
|
|
50
|
+
assert.deepEqual(names, ["memory_archive", "memory_delete", "memory_forget", "memory_get", "memory_list", "memory_save", "memory_search", "memory_update"]);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
test("compiled schemas pass the enforced DSH subset (defineTool projection)", () => {
|
|
54
54
|
const { registered } = setup();
|
|
55
|
-
assert.equal(registered.length,
|
|
55
|
+
assert.equal(registered.length, 8);
|
|
56
56
|
for (const tool of registered) {
|
|
57
57
|
assertSupportedJsonSchema(tool.parameters);
|
|
58
58
|
assertSupportedJsonSchema(tool.output.schema);
|
|
@@ -91,6 +91,57 @@ test("memory_search finds by CJK substring", async () => {
|
|
|
91
91
|
assert.equal(result.items[0].title, "记忆插件");
|
|
92
92
|
});
|
|
93
93
|
|
|
94
|
+
// Regression: memory_get.execute must live on the defineTool options (top
|
|
95
|
+
// level), NOT nested inside output — a misplaced execute silently becomes
|
|
96
|
+
// options.execute === undefined and every call throws "userExecute is not a
|
|
97
|
+
// function" while tests that only count tool names still pass.
|
|
98
|
+
test("memory_get returns the full body via execute and render", async () => {
|
|
99
|
+
const { registered, service } = setup();
|
|
100
|
+
const { memory } = service.saveWithDedupe({ type: "decision", title: "t", content: "完整正文内容" });
|
|
101
|
+
const get = registered.find((t) => t.name === "memory_get");
|
|
102
|
+
const res = await get.execute({ id: memory.id });
|
|
103
|
+
assert.equal(res.memory.id, memory.id);
|
|
104
|
+
assert.equal(res.memory.content, "完整正文内容");
|
|
105
|
+
assert.deepEqual(validateJsonSchemaValue(get.output.schema, res), []);
|
|
106
|
+
const text = get.output.render({}, res)[0].text;
|
|
107
|
+
assert.ok(text.includes("完整正文内容"), "full body in render");
|
|
108
|
+
assert.ok(text.includes(memory.id) && text.includes("t"), "id + title in render");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("memory_get on missing id rejects", async () => {
|
|
112
|
+
const { registered } = setup();
|
|
113
|
+
const get = registered.find((t) => t.name === "memory_get");
|
|
114
|
+
await assert.rejects(() => get.execute({ id: "missing" }), /memory not found/);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Render output is what hosts surface to the model (not the structured JSON),
|
|
118
|
+
// so it must embed titles + body previews, not just a hit count.
|
|
119
|
+
test("memory_search render embeds titles and body previews, not just a count", async () => {
|
|
120
|
+
const { registered, service } = setup();
|
|
121
|
+
service.saveWithDedupe({ type: "history", title: "旅行计划", content: "用户当前最苦恼时间安排与伦敦行程" });
|
|
122
|
+
service.saveWithDedupe({ type: "project", title: "插件定位", content: "dsh-mneme 插件做记忆沉淀" });
|
|
123
|
+
const search = registered.find((t) => t.name === "memory_search");
|
|
124
|
+
const res = await search.execute({ query: "时间" });
|
|
125
|
+
assert.ok(res.items.length >= 1, "search hit exists");
|
|
126
|
+
const text = search.output.render({}, res)[0].text;
|
|
127
|
+
assert.match(text, /Found \d+ memory entr/);
|
|
128
|
+
assert.ok(text.includes("旅行计划"), "title embedded in render");
|
|
129
|
+
assert.ok(text.includes("伦敦行程"), "body preview embedded in render");
|
|
130
|
+
assert.ok(text.includes("ID: "), "id embedded");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("memory_list render embeds titles and ids, not just counts", async () => {
|
|
134
|
+
const { registered, service } = setup();
|
|
135
|
+
service.saveWithDedupe({ type: "preference", title: "昵称", content: "桉桉" });
|
|
136
|
+
service.saveWithDedupe({ type: "project", title: "博客", content: "modusensus" });
|
|
137
|
+
const list = registered.find((t) => t.name === "memory_list");
|
|
138
|
+
const res = await list.execute({});
|
|
139
|
+
const text = list.output.render({}, res)[0].text;
|
|
140
|
+
assert.match(text, /\d+ memory entries \(of \d+\):/);
|
|
141
|
+
assert.ok(text.includes("昵称") && text.includes("博客"), "titles embedded");
|
|
142
|
+
assert.ok(text.includes("ID: "), "ids embedded");
|
|
143
|
+
});
|
|
144
|
+
|
|
94
145
|
test("memory_list filters by type", async () => {
|
|
95
146
|
const { registered, service } = setup();
|
|
96
147
|
service.saveWithDedupe({ type: "preference", title: "a", content: "x" });
|