@lmzhen/dsh-tool-memory 0.17.1 → 0.18.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 +28 -7
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { effectiveSessionPolicy } from "@lmzhen/dsh-evolution-approval";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
4
|
-
import { MEMORY_GUIDANCE_SECTION_ORDER, clampedNumber, resolveExecOrigins } from "@lmzhen/dsh-evolution-core";
|
|
4
|
+
import { MEMORY_GUIDANCE_SECTION_ORDER, clampedNumber, payloadText, resolveExecOrigins } from "@lmzhen/dsh-evolution-core";
|
|
5
5
|
//#region lib/types/index.js
|
|
6
6
|
/**
|
|
7
7
|
* Model-facing memory tool and runtime-context memory snapshot.
|
|
@@ -35,7 +35,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
35
35
|
ctx.inject(["settings"], (injected) => {
|
|
36
36
|
const settings = injected.settings;
|
|
37
37
|
if (typeof settings?.configure !== "function") return;
|
|
38
|
-
const disposer = settings.configure({ auto: false });
|
|
38
|
+
const disposer = settings.configure({ auto: false }, ctx.fiber);
|
|
39
39
|
if (typeof disposer === "function") ctx.effect(() => disposer, "tool-memory: settings presentation");
|
|
40
40
|
});
|
|
41
41
|
const memoryDisabled = rawConfig.memoryEnabled === false;
|
|
@@ -84,6 +84,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
84
84
|
} catch {}
|
|
85
85
|
})();
|
|
86
86
|
}, 500);
|
|
87
|
+
retryTimer.unref();
|
|
87
88
|
ctx.effect(() => () => {
|
|
88
89
|
clearInterval(retryTimer);
|
|
89
90
|
}, "tool-memory.snapshot-retry");
|
|
@@ -111,7 +112,11 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
111
112
|
chars: 0,
|
|
112
113
|
limit: 0
|
|
113
114
|
};
|
|
114
|
-
for (const field of [
|
|
115
|
+
for (const field of [
|
|
116
|
+
"facts",
|
|
117
|
+
"old_text",
|
|
118
|
+
"content"
|
|
119
|
+
]) {
|
|
115
120
|
const value = normalized[field];
|
|
116
121
|
if (value !== void 0 && value !== null && typeof value !== "string") return {
|
|
117
122
|
ok: false,
|
|
@@ -121,6 +126,21 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
121
126
|
limit: 0
|
|
122
127
|
};
|
|
123
128
|
}
|
|
129
|
+
for (const [index, operation] of (normalized.operations ?? []).entries()) for (const field of [
|
|
130
|
+
"facts",
|
|
131
|
+
"content",
|
|
132
|
+
"old_text"
|
|
133
|
+
]) {
|
|
134
|
+
const value = operation[field];
|
|
135
|
+
if (value === void 0 || value === null || typeof value === "string") continue;
|
|
136
|
+
return {
|
|
137
|
+
ok: false,
|
|
138
|
+
message: `memory: operations[${index}].${field} must be a string (got ${typeof value}); refusing the write — re-approving cannot fix a payload defect, so reject the record.`,
|
|
139
|
+
entries: [],
|
|
140
|
+
chars: 0,
|
|
141
|
+
limit: 0
|
|
142
|
+
};
|
|
143
|
+
}
|
|
124
144
|
const result = normalized.operations ? await ctx.memory.applyBatch(normalized.target, normalized.operations) : await ctx.memory.applyBatch(normalized.target, [{
|
|
125
145
|
action: normalized.action ?? "add",
|
|
126
146
|
facts: normalized.facts,
|
|
@@ -135,7 +155,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
135
155
|
};
|
|
136
156
|
}
|
|
137
157
|
const requiredFieldRejection = (op, position) => {
|
|
138
|
-
const body = (op
|
|
158
|
+
const body = payloadText(op);
|
|
139
159
|
if (op.action === "add") return body ? null : `Operation ${position} (add): facts is required. No operations were applied.`;
|
|
140
160
|
if (op.action !== "remove" && op.action !== "replace") return `Operation ${position}: unknown action "${String(op.action)}" (expected add/remove/replace). No operations were applied.`;
|
|
141
161
|
if (!(op.old_text ?? "").trim()) return `Operation ${position} (${op.action}): old_text is required. No operations were applied.`;
|
|
@@ -221,8 +241,9 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
221
241
|
isConcurrencySafe: () => false,
|
|
222
242
|
async execute(args, exec) {
|
|
223
243
|
const conflict = (a) => {
|
|
224
|
-
|
|
225
|
-
|
|
244
|
+
const facts = payloadText({ facts: a.facts });
|
|
245
|
+
const content = payloadText({ content: a.content });
|
|
246
|
+
return facts !== "" && content !== "" && facts !== content;
|
|
226
247
|
};
|
|
227
248
|
if (Array.isArray(args.operations)) for (const op of args.operations) {
|
|
228
249
|
const raw = op;
|
|
@@ -269,7 +290,7 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
269
290
|
} : {
|
|
270
291
|
target,
|
|
271
292
|
action: args.action ?? "add",
|
|
272
|
-
facts: args
|
|
293
|
+
facts: payloadText(args),
|
|
273
294
|
old_text: args.old_text
|
|
274
295
|
};
|
|
275
296
|
if (normalized.operations) for (const [index, op] of normalized.operations.entries()) {
|
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.18.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -26,22 +26,22 @@
|
|
|
26
26
|
],
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@deepseek-ai/schemastery": "^3.18.
|
|
30
|
-
"@lmzhen/dsh-evolution-approval": "^0.
|
|
31
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
29
|
+
"@deepseek-ai/schemastery": "^3.18.4",
|
|
30
|
+
"@lmzhen/dsh-evolution-approval": "^0.18.0",
|
|
31
|
+
"@lmzhen/dsh-evolution-core": "^0.18.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.18.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.18.0",
|
|
44
|
+
"@lmzhen/dsh-memory": "^0.18.0",
|
|
45
|
+
"@lmzhen/dsh-memory-files": "^0.18.0"
|
|
46
46
|
}
|
|
47
47
|
}
|