@lmzhen/dsh-tool-memory 0.3.17 → 0.3.18
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 +29 -26
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -2648,11 +2648,7 @@ function resolveOrigins(headerOrigin, isReview = false) {
|
|
|
2648
2648
|
const name = "tool-memory";
|
|
2649
2649
|
/** Max characters of each echoed memory entry (single source for the Config default and the runtime slice). */
|
|
2650
2650
|
const DEFAULT_ENTRY_PREVIEW_CHARS = 200;
|
|
2651
|
-
const inject = [
|
|
2652
|
-
"tools",
|
|
2653
|
-
"systemPrompt",
|
|
2654
|
-
"memory"
|
|
2655
|
-
];
|
|
2651
|
+
const inject = ["tools", "memory"];
|
|
2656
2652
|
/**
|
|
2657
2653
|
* System-prompt memory guidance, aligned with Hermes `MEMORY_GUIDANCE`.
|
|
2658
2654
|
* Reached by the model every turn, so it is the place to steer behavior: what
|
|
@@ -2682,36 +2678,43 @@ function effectiveSessionPolicy(ctx, session) {
|
|
|
2682
2678
|
}
|
|
2683
2679
|
const Config = z.object({
|
|
2684
2680
|
memoryEnabled: z.boolean().default(true),
|
|
2685
|
-
entryPreviewChars: z.number().default(DEFAULT_ENTRY_PREVIEW_CHARS)
|
|
2681
|
+
entryPreviewChars: z.number().min(1).default(DEFAULT_ENTRY_PREVIEW_CHARS)
|
|
2686
2682
|
});
|
|
2687
2683
|
async function apply(ctx, rawConfig) {
|
|
2688
2684
|
if (!rawConfig.memoryEnabled) return;
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2685
|
+
const systemPrompt = ctx.get("systemPrompt");
|
|
2686
|
+
let snapshotText = "";
|
|
2687
|
+
try {
|
|
2688
|
+
snapshotText = await ctx.memory.renderContext();
|
|
2689
|
+
} catch (error) {
|
|
2690
|
+
ctx.logger.warn(`tool-memory: memory provider not ready at mount; snapshot starts empty until the first write: ${error instanceof Error ? error.message : String(error)}`);
|
|
2691
|
+
}
|
|
2692
|
+
if (systemPrompt) {
|
|
2693
|
+
ctx.effect(() => systemPrompt.section({
|
|
2694
|
+
name: "evolution:memory-guidance",
|
|
2695
|
+
order: 150,
|
|
2696
|
+
text: MEMORY_GUIDANCE
|
|
2697
|
+
}), "tool-memory.memory-guidance");
|
|
2698
|
+
ctx.effect(() => systemPrompt.context({
|
|
2699
|
+
name: "evolution:memory-snapshot",
|
|
2700
|
+
order: 150,
|
|
2701
|
+
text: () => snapshotText
|
|
2702
|
+
}), "tool-memory.memory-snapshot");
|
|
2703
|
+
const refreshSnapshot = async () => {
|
|
2704
|
+
try {
|
|
2705
|
+
snapshotText = await ctx.memory.renderContext();
|
|
2706
|
+
} catch {}
|
|
2707
|
+
};
|
|
2708
|
+
ctx.effect(() => ctx.on("evolution/memory-applied", () => {
|
|
2709
|
+
refreshSnapshot();
|
|
2710
|
+
}), "tool-memory.snapshot-refresh");
|
|
2711
|
+
} else ctx.logger.warn("tool-memory: systemPrompt service not mounted; memory guidance and snapshot are not injected (the write tool still works)");
|
|
2708
2712
|
async function executeCore(normalized) {
|
|
2709
2713
|
const result = normalized.operations ? await ctx.memory.applyBatch(normalized.target, normalized.operations) : await ctx.memory.applyBatch(normalized.target, [{
|
|
2710
2714
|
action: normalized.action ?? "add",
|
|
2711
2715
|
facts: normalized.facts,
|
|
2712
2716
|
old_text: normalized.old_text
|
|
2713
2717
|
}]);
|
|
2714
|
-
if (result.ok) snapshotText = await ctx.memory.renderContext();
|
|
2715
2718
|
return {
|
|
2716
2719
|
ok: result.ok,
|
|
2717
2720
|
message: result.message,
|
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.3.
|
|
4
|
+
"version": "0.3.18",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
40
40
|
"@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
|
|
41
41
|
"@deepseek-ai/dsh-system-prompt": "^0.1.1-rc.2",
|
|
42
|
-
"@lmzhen/dsh-memory": "^0.3.
|
|
43
|
-
"@lmzhen/dsh-memory-files": "^0.3.
|
|
42
|
+
"@lmzhen/dsh-memory": "^0.3.18",
|
|
43
|
+
"@lmzhen/dsh-memory-files": "^0.3.18"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@deepseek-ai/dsh-invariants": "^0.1.1-rc.2",
|
|
47
47
|
"@deepseek-ai/dsh-tools": "^0.1.1-rc.2",
|
|
48
48
|
"@deepseek-ai/dsh-system-prompt": "^0.1.1-rc.2",
|
|
49
49
|
"@deepseek-ai/dsh-agent-loop-testkit": "^0.1.1-rc.2",
|
|
50
|
-
"@lmzhen/dsh-memory": "^0.3.
|
|
51
|
-
"@lmzhen/dsh-memory-files": "^0.3.
|
|
50
|
+
"@lmzhen/dsh-memory": "^0.3.18",
|
|
51
|
+
"@lmzhen/dsh-memory-files": "^0.3.18"
|
|
52
52
|
}
|
|
53
53
|
}
|