@lmzhen/dsh-tool-memory 0.16.1 → 0.17.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 +19 -10
- package/lib/types/index.d.ts +14 -14
- package/package.json +12 -12
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,
|
|
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.
|
|
@@ -10,7 +10,6 @@ import { MEMORY_GUIDANCE_SECTION_ORDER, PARAM_NAMESPACES, clampedNumber, install
|
|
|
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
12
|
const DEFAULT_ENTRY_PREVIEW_CHARS = 200;
|
|
13
|
-
const TOOL_MEMORY_SETTINGS_SCHEMA = z.object({ entryPreviewChars: z.number().min(1).default(DEFAULT_ENTRY_PREVIEW_CHARS) });
|
|
14
13
|
const inject = ["tools", "memory"];
|
|
15
14
|
/**
|
|
16
15
|
* System-prompt memory guidance, aligned with Hermes `MEMORY_GUIDANCE`.
|
|
@@ -30,16 +29,26 @@ const MEMORY_GUIDANCE = "You have durable memory across sessions. Save stable us
|
|
|
30
29
|
const MEMORY_TOOL_DESCRIPTION = "Save durable facts to persistent memory that survive across sessions. Memory is injected into future turns, so keep entries compact and high-signal.\n\nHOW: make all changes in ONE call via an `operations` array (each item {action, facts?|content?, old_text?}). The batch applies atomically and the char limit is checked on the final result — so one call can remove/replace stale entries to free room AND add new ones. Use bare action/content/old_text only for a single lone change.\n\nWHEN: save proactively when the user states a preference, correction, or personal detail, or you learn a stable fact about their environment, conventions, or workflow. Priority: user preferences & corrections > environment facts > procedures. The best memory stops the user repeating themselves.\n\nTARGETS: \"user\" = who the user is (name, role, preferences, style). \"memory\" = your notes (environment, conventions, tool quirks, lessons).\n\nSKIP: trivial/obvious info, easily re-discovered facts, task progress, completed-work logs, temporary TODO state. To recall a past session use the session query tool, not memory. Reusable procedures belong in a skill, not memory.";
|
|
31
30
|
const Config = z.object({
|
|
32
31
|
memoryEnabled: z.boolean().default(true),
|
|
33
|
-
entryPreviewChars: z.number().min(1).default(DEFAULT_ENTRY_PREVIEW_CHARS)
|
|
32
|
+
entryPreviewChars: z.number().min(1).default(DEFAULT_ENTRY_PREVIEW_CHARS).volatile()
|
|
34
33
|
});
|
|
35
34
|
async function apply(ctx, rawConfig = {}) {
|
|
35
|
+
ctx.inject(["settings"], (injected) => {
|
|
36
|
+
const settings = injected.settings;
|
|
37
|
+
if (typeof settings?.configure !== "function") return;
|
|
38
|
+
const disposer = settings.configure({ auto: false });
|
|
39
|
+
if (typeof disposer === "function") ctx.effect(() => disposer, "tool-memory: settings presentation");
|
|
40
|
+
});
|
|
36
41
|
const memoryDisabled = rawConfig.memoryEnabled === false;
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
let previewClampWarned = false;
|
|
43
|
+
const previewChars = () => {
|
|
44
|
+
const value = rawConfig.entryPreviewChars?.get();
|
|
45
|
+
const clamped = clampedNumber(value, DEFAULT_ENTRY_PREVIEW_CHARS, { min: 1 });
|
|
46
|
+
if (!previewClampWarned && value !== void 0 && clamped !== value) {
|
|
47
|
+
previewClampWarned = true;
|
|
48
|
+
ctx.logger.warn(`tool-memory: entryPreviewChars=${String(value)} is invalid; falling back to the default ${DEFAULT_ENTRY_PREVIEW_CHARS}`);
|
|
49
|
+
}
|
|
50
|
+
return clamped;
|
|
51
|
+
};
|
|
43
52
|
const systemPrompt = ctx.get("systemPrompt");
|
|
44
53
|
let snapshotText = "";
|
|
45
54
|
if (!memoryDisabled) try {
|
|
@@ -319,4 +328,4 @@ async function apply(ctx, rawConfig = {}) {
|
|
|
319
328
|
});
|
|
320
329
|
}
|
|
321
330
|
//#endregion
|
|
322
|
-
export { Config, MEMORY_GUIDANCE, MEMORY_TOOL_DESCRIPTION,
|
|
331
|
+
export { Config, MEMORY_GUIDANCE, MEMORY_TOOL_DESCRIPTION, apply, inject, name };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,19 +2,9 @@
|
|
|
2
2
|
* Model-facing memory tool and runtime-context memory snapshot.
|
|
3
3
|
* @module @lmzhen/dsh-tool-memory
|
|
4
4
|
*/
|
|
5
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
5
|
+
import type { Context, Volatile } from '@deepseek-ai/cordis';
|
|
6
6
|
import z from '@deepseek-ai/schemastery';
|
|
7
7
|
export declare const name = "tool-memory";
|
|
8
|
-
/** G3/S3.2: the memory TOOL's user-tunable display knob (canonical id).
|
|
9
|
-
* `memoryEnabled` stays a deployment switch on purpose: it decides whether the
|
|
10
|
-
* tool and its prompt section are REGISTERED at all, so making it live would mean
|
|
11
|
-
* dynamic registration with catalog-visible effects — a structural change this
|
|
12
|
-
* batch deliberately does not make (registry tier E2). */
|
|
13
|
-
export interface ToolMemorySettings {
|
|
14
|
-
/** Characters of one memory entry shown in a tool result preview. */
|
|
15
|
-
entryPreviewChars: number;
|
|
16
|
-
}
|
|
17
|
-
export declare const TOOL_MEMORY_SETTINGS_SCHEMA: z<ToolMemorySettings>;
|
|
18
8
|
export declare const inject: string[];
|
|
19
9
|
/**
|
|
20
10
|
* System-prompt memory guidance, aligned with Hermes `MEMORY_GUIDANCE`.
|
|
@@ -32,11 +22,21 @@ export declare const MEMORY_GUIDANCE: string;
|
|
|
32
22
|
* `MEMORY_GUIDANCE` system prompt.
|
|
33
23
|
*/
|
|
34
24
|
export declare const MEMORY_TOOL_DESCRIPTION: string;
|
|
25
|
+
/** G3/S3.2: `memoryEnabled` stays a deployment switch on purpose — it decides whether the
|
|
26
|
+
* tool and its prompt section are REGISTERED at all, so making it live would mean dynamic
|
|
27
|
+
* registration with catalog-visible effects (registry tier E2). The display knob the user
|
|
28
|
+
* may tune (`entryPreviewChars`) is a volatile row field instead (G1 §8.1). */
|
|
35
29
|
export interface Config {
|
|
36
30
|
memoryEnabled?: boolean;
|
|
37
|
-
/** Maximum characters of each memory entry echoed back in tool results. */
|
|
38
|
-
entryPreviewChars?: number
|
|
31
|
+
/** Maximum characters of each memory entry echoed back in tool results (live reference). */
|
|
32
|
+
entryPreviewChars?: Volatile<number>;
|
|
39
33
|
}
|
|
40
|
-
export declare const Config: z<
|
|
34
|
+
export declare const Config: z<Schemastery.ObjectS<NoInfer<{
|
|
35
|
+
memoryEnabled: z<boolean, boolean, "defined">;
|
|
36
|
+
entryPreviewChars: z<number, number, "volatile-defined">;
|
|
37
|
+
}>>, Schemastery.ObjectT<NoInfer<{
|
|
38
|
+
memoryEnabled: z<boolean, boolean, "defined">;
|
|
39
|
+
entryPreviewChars: z<number, number, "volatile-defined">;
|
|
40
|
+
}>>, "plain">;
|
|
41
41
|
export declare function apply(ctx: Context, rawConfig?: Config): Promise<void>;
|
|
42
42
|
//# sourceMappingURL=index.d.ts.map
|
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.17.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.1",
|
|
30
|
-
"@lmzhen/dsh-evolution-approval": "^0.
|
|
31
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
30
|
+
"@lmzhen/dsh-evolution-approval": "^0.17.0",
|
|
31
|
+
"@lmzhen/dsh-evolution-core": "^0.17.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
35
|
-
"@deepseek-ai/dsh-tools": "^0.
|
|
36
|
-
"@deepseek-ai/dsh-system-prompt": "^0.
|
|
37
|
-
"@lmzhen/dsh-memory": "^0.
|
|
35
|
+
"@deepseek-ai/dsh-tools": "^0.2.0-rc.1",
|
|
36
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.0-rc.1",
|
|
37
|
+
"@lmzhen/dsh-memory": "^0.17.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@deepseek-ai/dsh-tools": "^0.
|
|
41
|
-
"@deepseek-ai/dsh-system-prompt": "^0.
|
|
42
|
-
"@deepseek-ai/dsh-agent-loop-testkit": "^0.
|
|
43
|
-
"@lmzhen/dsh-evolution-approval": "^0.
|
|
44
|
-
"@lmzhen/dsh-memory": "^0.
|
|
45
|
-
"@lmzhen/dsh-memory-files": "^0.
|
|
40
|
+
"@deepseek-ai/dsh-tools": "^0.2.0-rc.1",
|
|
41
|
+
"@deepseek-ai/dsh-system-prompt": "^0.2.0-rc.1",
|
|
42
|
+
"@deepseek-ai/dsh-agent-loop-testkit": "^0.2.0-rc.1",
|
|
43
|
+
"@lmzhen/dsh-evolution-approval": "^0.17.0",
|
|
44
|
+
"@lmzhen/dsh-memory": "^0.17.0",
|
|
45
|
+
"@lmzhen/dsh-memory-files": "^0.17.0"
|
|
46
46
|
}
|
|
47
47
|
}
|