@lmzhen/dsh-tool-memory 0.3.79 → 0.3.80

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.
Files changed (2) hide show
  1. package/lib/index.js +13 -9
  2. package/package.json +7 -7
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, resolveOrigins } from "@lmzhen/dsh-evolution-core";
4
+ import { MEMORY_GUIDANCE_SECTION_ORDER, clampedNumber, 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.
@@ -32,17 +32,17 @@ const Config = z.object({
32
32
  entryPreviewChars: z.number().min(1).default(DEFAULT_ENTRY_PREVIEW_CHARS)
33
33
  });
34
34
  async function apply(ctx, rawConfig = {}) {
35
- if (!rawConfig.memoryEnabled) return;
35
+ const memoryDisabled = rawConfig.memoryEnabled === false;
36
36
  const entryPreviewChars = clampedNumber(rawConfig.entryPreviewChars, DEFAULT_ENTRY_PREVIEW_CHARS, { min: 1 });
37
37
  if (entryPreviewChars !== (rawConfig.entryPreviewChars ?? DEFAULT_ENTRY_PREVIEW_CHARS)) ctx.logger.warn(`tool-memory: entryPreviewChars=${String(rawConfig.entryPreviewChars)} is invalid; falling back to the default ${DEFAULT_ENTRY_PREVIEW_CHARS}`);
38
38
  const systemPrompt = ctx.get("systemPrompt");
39
39
  let snapshotText = "";
40
- try {
40
+ if (!memoryDisabled) try {
41
41
  snapshotText = await ctx.memory.renderContext();
42
42
  } catch (error) {
43
43
  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)}`);
44
44
  }
45
- if (systemPrompt) {
45
+ if (systemPrompt && !memoryDisabled) {
46
46
  ctx.effect(() => systemPrompt.section({
47
47
  name: "evolution:memory-guidance",
48
48
  order: MEMORY_GUIDANCE_SECTION_ORDER,
@@ -61,7 +61,7 @@ async function apply(ctx, rawConfig = {}) {
61
61
  ctx.effect(() => ctx.on("evolution/memory-applied", () => {
62
62
  refreshSnapshot();
63
63
  }), "tool-memory.snapshot-refresh");
64
- } else ctx.logger.warn("tool-memory: systemPrompt service not mounted; memory guidance and snapshot are not injected (the write tool still works)");
64
+ } else if (!memoryDisabled) ctx.logger.warn("tool-memory: systemPrompt service not mounted; memory guidance and snapshot are not injected (the write tool still works)");
65
65
  async function executeCore(normalized) {
66
66
  if (normalized.operations?.some((op) => {
67
67
  const raw = op;
@@ -104,7 +104,7 @@ async function apply(ctx, rawConfig = {}) {
104
104
  limit: result.limit
105
105
  };
106
106
  }
107
- ctx.tools.register(defineTool({
107
+ if (!memoryDisabled) ctx.tools.register(defineTool({
108
108
  name: "memory",
109
109
  description: MEMORY_TOOL_DESCRIPTION,
110
110
  parameters: {
@@ -235,7 +235,7 @@ async function apply(ctx, rawConfig = {}) {
235
235
  old_text: args.old_text
236
236
  };
237
237
  const targetLabel = target === "memory" ? "" : `${target} `;
238
- const origin = resolveOrigins(exec.agent?.session?.header.origin).approval;
238
+ const origin = resolveExecOrigins(exec).approval;
239
239
  const sessionPolicy = effectiveSessionPolicy(ctx, exec.agent?.session);
240
240
  const approval = ctx.get("evolutionApproval");
241
241
  if (approval) {
@@ -261,8 +261,12 @@ async function apply(ctx, rawConfig = {}) {
261
261
  }
262
262
  }));
263
263
  ctx.inject(["evolutionApproval"], (approvalCtx) => {
264
- const dispose = approvalCtx.evolutionApproval.registerRunner("memory", (args) => executeCore(args));
265
- approvalCtx.effect(() => dispose, "tool-memory.approval-runner");
264
+ const approval = approvalCtx.evolutionApproval;
265
+ const dispose = memoryDisabled ? approval.registerRunner("memory", () => Promise.resolve({
266
+ ok: false,
267
+ message: "Refused: the memory tool is disabled (tool-memory memoryEnabled:false) — its replay runner cannot execute this staged write. Reject the record; re-stage after re-enabling the tool if the write is still wanted."
268
+ })) : approval.registerRunner("memory", (args) => executeCore(args));
269
+ approvalCtx.effect(() => dispose, memoryDisabled ? "tool-memory.approval-runner-disabled" : "tool-memory.approval-runner");
266
270
  });
267
271
  }
268
272
  //#endregion
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.79",
4
+ "version": "0.3.80",
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.1",
30
- "@lmzhen/dsh-evolution-approval": "^0.3.79",
31
- "@lmzhen/dsh-evolution-core": "^0.3.79"
30
+ "@lmzhen/dsh-evolution-approval": "^0.3.80",
31
+ "@lmzhen/dsh-evolution-core": "^0.3.80"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@deepseek-ai/cordis": "^4.0.1",
35
35
  "@deepseek-ai/dsh-tools": "^0.1.5-rc.2",
36
36
  "@deepseek-ai/dsh-system-prompt": "^0.1.5-rc.2",
37
- "@lmzhen/dsh-memory": "^0.3.79"
37
+ "@lmzhen/dsh-memory": "^0.3.80"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@deepseek-ai/dsh-tools": "^0.1.5-rc.2",
41
41
  "@deepseek-ai/dsh-system-prompt": "^0.1.5-rc.2",
42
42
  "@deepseek-ai/dsh-agent-loop-testkit": "^0.1.5-rc.2",
43
- "@lmzhen/dsh-evolution-approval": "^0.3.79",
44
- "@lmzhen/dsh-memory": "^0.3.79",
45
- "@lmzhen/dsh-memory-files": "^0.3.79"
43
+ "@lmzhen/dsh-evolution-approval": "^0.3.80",
44
+ "@lmzhen/dsh-memory": "^0.3.80",
45
+ "@lmzhen/dsh-memory-files": "^0.3.80"
46
46
  }
47
47
  }