@lmzhen/dsh-tool-memory 0.22.0 → 0.24.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/lib/index.js +17 -15
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import { MEMORY_GUIDANCE_SECTION_ORDER, clampedNumber, payloadText, resolveExecO
|
|
|
9
9
|
*/
|
|
10
10
|
const name = "tool-memory";
|
|
11
11
|
/** Max characters of each echoed memory entry (single source for the Config default and the runtime slice). */
|
|
12
|
+
/** G2.4/C3: the give-up bound of the snapshot retry — a NAMED ceiling, not a literal in the call. */
|
|
13
|
+
const SNAPSHOT_RETRY_GIVE_UP_MS = 6e4;
|
|
12
14
|
const DEFAULT_ENTRY_PREVIEW_CHARS = 200;
|
|
13
15
|
const inject = ["tools", "memory"];
|
|
14
16
|
/**
|
|
@@ -90,7 +92,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
90
92
|
}, "tool-memory.snapshot-retry");
|
|
91
93
|
setTimeout(() => {
|
|
92
94
|
clearInterval(retryTimer);
|
|
93
|
-
},
|
|
95
|
+
}, SNAPSHOT_RETRY_GIVE_UP_MS).unref();
|
|
94
96
|
}
|
|
95
97
|
} else if (!memoryDisabled) ctx.logger.warn("tool-memory: systemPrompt service not mounted; memory guidance and snapshot are not injected (the write tool still works)");
|
|
96
98
|
async function executeCore(normalized) {
|
|
@@ -99,7 +101,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
99
101
|
return raw === null || typeof raw !== "object";
|
|
100
102
|
})) return {
|
|
101
103
|
ok: false,
|
|
102
|
-
message: "
|
|
104
|
+
message: "operations 的每一项都必须是对象。",
|
|
103
105
|
entries: [],
|
|
104
106
|
chars: 0,
|
|
105
107
|
limit: 0
|
|
@@ -107,7 +109,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
107
109
|
const target = normalized.target;
|
|
108
110
|
if (target !== "memory" && target !== "user") return {
|
|
109
111
|
ok: false,
|
|
110
|
-
message: `memory
|
|
112
|
+
message: `memory:"target" 必须是 "memory" 或 "user"(收到 ${String(target)});拒绝写入。`,
|
|
111
113
|
entries: [],
|
|
112
114
|
chars: 0,
|
|
113
115
|
limit: 0
|
|
@@ -120,7 +122,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
120
122
|
const value = normalized[field];
|
|
121
123
|
if (value !== void 0 && value !== null && typeof value !== "string") return {
|
|
122
124
|
ok: false,
|
|
123
|
-
message: `memory
|
|
125
|
+
message: `memory:"${field}" 必须是字符串(收到 ${typeof value});拒绝写入。`,
|
|
124
126
|
entries: [],
|
|
125
127
|
chars: 0,
|
|
126
128
|
limit: 0
|
|
@@ -135,7 +137,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
135
137
|
if (value === void 0 || value === null || typeof value === "string") continue;
|
|
136
138
|
return {
|
|
137
139
|
ok: false,
|
|
138
|
-
message: `memory
|
|
140
|
+
message: `memory:operations[${index}].${field} 必须是字符串(收到 ${typeof value});拒绝写入 —— 重新批准无法修复载荷缺陷,请驳回该记录。`,
|
|
139
141
|
entries: [],
|
|
140
142
|
chars: 0,
|
|
141
143
|
limit: 0
|
|
@@ -156,10 +158,10 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
156
158
|
}
|
|
157
159
|
const requiredFieldRejection = (op, position) => {
|
|
158
160
|
const body = payloadText(op);
|
|
159
|
-
if (op.action === "add") return body ? null :
|
|
160
|
-
if (op.action !== "remove" && op.action !== "replace") return
|
|
161
|
-
if (!(op.old_text ?? "").trim()) return
|
|
162
|
-
if (op.action === "replace" && !body) return
|
|
161
|
+
if (op.action === "add") return body ? null : `第 ${position} 个操作(add):必须提供 facts。未应用任何操作。`;
|
|
162
|
+
if (op.action !== "remove" && op.action !== "replace") return `第 ${position} 个操作:未知动作「${String(op.action)}」(应为 add/remove/replace)。未应用任何操作。`;
|
|
163
|
+
if (!(op.old_text ?? "").trim()) return `第 ${position} 个操作(${op.action}):必须提供 old_text。未应用任何操作。`;
|
|
164
|
+
if (op.action === "replace" && !body) return `第 ${position} 个操作(replace):必须提供 facts。`;
|
|
163
165
|
return null;
|
|
164
166
|
};
|
|
165
167
|
if (!memoryDisabled) ctx.tools.register(defineTool({
|
|
@@ -249,14 +251,14 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
249
251
|
const raw = op;
|
|
250
252
|
if (raw === null || typeof raw !== "object") return {
|
|
251
253
|
ok: false,
|
|
252
|
-
message: "
|
|
254
|
+
message: "operations 的每一项都必须是对象。",
|
|
253
255
|
entries: [],
|
|
254
256
|
chars: 0,
|
|
255
257
|
limit: 0
|
|
256
258
|
};
|
|
257
259
|
if (conflict(op)) return {
|
|
258
260
|
ok: false,
|
|
259
|
-
message: "
|
|
261
|
+
message: "每个操作只能提供 facts 或 content 之一(同一字段):两者给了不同的值。",
|
|
260
262
|
entries: [],
|
|
261
263
|
chars: 0,
|
|
262
264
|
limit: 0
|
|
@@ -264,21 +266,21 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
264
266
|
}
|
|
265
267
|
else if (conflict(args)) return {
|
|
266
268
|
ok: false,
|
|
267
|
-
message: "
|
|
269
|
+
message: "只能提供 facts 或 content 之一(同一字段):两者给了不同的值。",
|
|
268
270
|
entries: [],
|
|
269
271
|
chars: 0,
|
|
270
272
|
limit: 0
|
|
271
273
|
};
|
|
272
274
|
if (Array.isArray(args.operations) && args.operations.length === 0) return {
|
|
273
275
|
ok: false,
|
|
274
|
-
message: "
|
|
276
|
+
message: "没有提供任何操作(operations 数组为空)。",
|
|
275
277
|
entries: [],
|
|
276
278
|
chars: 0,
|
|
277
279
|
limit: 0
|
|
278
280
|
};
|
|
279
281
|
if (args.operations !== void 0 && !Array.isArray(args.operations)) return {
|
|
280
282
|
ok: false,
|
|
281
|
-
message: "
|
|
283
|
+
message: "形状不合法:operations 必须是 {action, content?, old_text?} 对象的数组(单个操作时可省略 operations)。",
|
|
282
284
|
entries: [],
|
|
283
285
|
chars: 0,
|
|
284
286
|
limit: 0
|
|
@@ -343,7 +345,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
343
345
|
const approval = approvalCtx.evolutionApproval;
|
|
344
346
|
const dispose = memoryDisabled ? approval.registerRunner("memory", () => Promise.resolve({
|
|
345
347
|
ok: false,
|
|
346
|
-
message: "
|
|
348
|
+
message: "拒绝:记忆工具已禁用(tool-memory memoryEnabled:false)—— 它的回放运行器无法执行这条暂存写入。请驳回该记录;若仍需要该写入,请在重新启用该工具后再暂存。"
|
|
347
349
|
})) : approval.registerRunner("memory", (args) => executeCore(args));
|
|
348
350
|
approvalCtx.effect(() => dispose, memoryDisabled ? "tool-memory.approval-runner-disabled" : "tool-memory.approval-runner");
|
|
349
351
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-tool-memory",
|
|
3
3
|
"description": "Model-facing memory tool and prompt context (community build)",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.24.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,21 +27,21 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@deepseek-ai/schemastery": "^3.18.4",
|
|
30
|
-
"@lmzhen/dsh-evolution-approval": "^0.
|
|
31
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
30
|
+
"@lmzhen/dsh-evolution-approval": "^0.24.0",
|
|
31
|
+
"@lmzhen/dsh-evolution-core": "^0.24.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
35
35
|
"@deepseek-ai/dsh-tools": "^0.2.0-rc.1",
|
|
36
36
|
"@deepseek-ai/dsh-system-prompt": "^0.2.0-rc.1",
|
|
37
|
-
"@lmzhen/dsh-memory": "^0.
|
|
37
|
+
"@lmzhen/dsh-memory": "^0.24.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@deepseek-ai/dsh-tools": "^0.2.0-rc.1",
|
|
41
41
|
"@deepseek-ai/dsh-system-prompt": "^0.2.0-rc.1",
|
|
42
42
|
"@deepseek-ai/dsh-agent-loop-testkit": "^0.2.0-rc.1",
|
|
43
|
-
"@lmzhen/dsh-evolution-approval": "^0.
|
|
44
|
-
"@lmzhen/dsh-memory": "^0.
|
|
45
|
-
"@lmzhen/dsh-memory-files": "^0.
|
|
43
|
+
"@lmzhen/dsh-evolution-approval": "^0.24.0",
|
|
44
|
+
"@lmzhen/dsh-memory": "^0.24.0",
|
|
45
|
+
"@lmzhen/dsh-memory-files": "^0.24.0"
|
|
46
46
|
}
|
|
47
47
|
}
|