@lmzhen/dsh-tool-memory 0.1.0-rc.45 → 0.1.0-rc.46
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 +156 -1
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -1,5 +1,160 @@
|
|
|
1
1
|
import z from "@deepseek-ai/schemastery";
|
|
2
2
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
//#region ../evolution-core/src/prompts.ts
|
|
5
|
+
/**
|
|
6
|
+
* Review and curation prompts adapted from Hermes Agent
|
|
7
|
+
* `agent/background_review.py`, `agent/curator.py`, and
|
|
8
|
+
* `agent/learn_prompt.py`, with tool names translated to the DSH-native
|
|
9
|
+
* catalog (`memory`, `skill_manage`, `skill`, `bash`, `str_replace_editor`).
|
|
10
|
+
*
|
|
11
|
+
* Every prompt is pinned in a versioned bundle. Review workers verify the
|
|
12
|
+
* bundle digest before spending a model call, so a partially-patched
|
|
13
|
+
* deployment fails closed instead of silently running a truncated prompt.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Prompt bundle identity. Bump both id and version whenever a prompt's text
|
|
17
|
+
* changes semantically: the bundle digest is the fail-closed signal for
|
|
18
|
+
* review workers, so a stale id across deployments must be distinguishable.
|
|
19
|
+
*/
|
|
20
|
+
const PROMPT_BUNDLE_ID = "dsh-evolution@3";
|
|
21
|
+
const MEMORY_REVIEW_PROMPT = `[Auto-review — Memory]
|
|
22
|
+
Review the conversation above and consider saving to memory if appropriate.
|
|
23
|
+
|
|
24
|
+
Focus on:
|
|
25
|
+
1. Has the user revealed things about themselves — persona, desires, preferences, or personal details worth remembering?
|
|
26
|
+
2. Has the user expressed expectations about how you should behave, their work style, or ways they want you to operate?
|
|
27
|
+
|
|
28
|
+
If something stands out, save it using the memory tool.
|
|
29
|
+
If nothing is worth saving, just say "Nothing to save." and stop.`;
|
|
30
|
+
const SKILL_REVIEW_PROMPT = `[Auto-review — Skills]
|
|
31
|
+
Review the conversation above and update the skill library. Be ACTIVE — most sessions produce at least one skill update, even if small.
|
|
32
|
+
|
|
33
|
+
Target shape: CLASS-LEVEL skills with a rich SKILL.md and a references/ directory for session-specific detail. Not a flat list of narrow one-session skills.
|
|
34
|
+
|
|
35
|
+
Signals that warrant action:
|
|
36
|
+
- The user corrected your style, tone, format, verbosity, workflow, or approach.
|
|
37
|
+
- A non-trivial technique, fix, workaround, or debugging path emerged.
|
|
38
|
+
- A loaded skill turned out wrong, missing, or outdated — patch it now.
|
|
39
|
+
|
|
40
|
+
Only update skills you loaded or read in THIS session; never touch skills you have not read.
|
|
41
|
+
|
|
42
|
+
Preference order:
|
|
43
|
+
1. Patch a skill that was loaded or read this session.
|
|
44
|
+
2. Patch an existing umbrella skill.
|
|
45
|
+
3. Add references/, templates/, or scripts/ support under an existing skill.
|
|
46
|
+
4. Create a new class-level umbrella skill only when nothing fits.
|
|
47
|
+
|
|
48
|
+
Protected skills (bundled/hub-installed) must not be edited. Pinned skills are read-only to the background review: the pinned write guard refuses background changes, so only the foreground may update or archive them.
|
|
49
|
+
|
|
50
|
+
Do NOT capture:
|
|
51
|
+
- Environment-dependent failures (missing binaries, unconfigured credentials).
|
|
52
|
+
- Negative claims about tools ("browser tools do not work").
|
|
53
|
+
- Transient errors that resolved during the session.
|
|
54
|
+
- One-off task narratives.
|
|
55
|
+
|
|
56
|
+
If a tool failed because of setup state, capture the FIX under an existing setup skill — never "this tool does not work" as a standalone constraint.
|
|
57
|
+
|
|
58
|
+
"Nothing to save." is a real option but should NOT be the default.`;
|
|
59
|
+
const COMBINED_REVIEW_PROMPT = `[Auto-review]
|
|
60
|
+
Review the conversation above and update two things.
|
|
61
|
+
|
|
62
|
+
**Memory**: who the user is. Save durable user preferences, personal details, and expectations with the memory tool.
|
|
63
|
+
|
|
64
|
+
**Skills**: how to do this class of task. Be ACTIVE. Only update skills you loaded or read in THIS session. Follow the same class-level umbrella policy, preference order, protected-skill rules, and do-not-capture list as a skill review.
|
|
65
|
+
|
|
66
|
+
Act on whichever dimension has real signal. If genuinely nothing stands out on either, say "Nothing to save." and stop — but don't reach for that conclusion as a default.`;
|
|
67
|
+
const CURATOR_PROMPT = `You are the skill curator. Maintain a healthy, class-level skill library, not a flat pile of narrow one-session skills.
|
|
68
|
+
|
|
69
|
+
The goal is a LIBRARY OF CLASS-LEVEL INSTRUCTIONS. A skill collection of many narrow skills where each captures one session's specific bug is a FAILURE of the library. An agent searching skills matches on descriptions, not exact names; one broad umbrella with labeled subsections beats five narrow siblings for discoverability.
|
|
70
|
+
|
|
71
|
+
Right target shape: class-level skills with rich SKILL.md + references/, templates/, scripts/ support files for session-specific detail.
|
|
72
|
+
|
|
73
|
+
Hard rules:
|
|
74
|
+
1. NEVER hard-delete a skill. Archive (moving to .archive/) is the maximum destructive action; archives are recoverable, deletion is not.
|
|
75
|
+
2. Do not touch bundled, hub-installed, pinned, or scheduled-task-referenced (\`referenced\`) skills. Referenced skills MAY be consolidated into an umbrella, but never simply pruned.
|
|
76
|
+
3. Do not archive recently-created or never-used skills without strong evidence. "use=0" is NOT evidence either way — it only means the trigger has not come up yet.
|
|
77
|
+
4. Do NOT reject consolidation on the grounds that "each skill has a distinct trigger". The right bar is: would a human maintainer write this as N separate skills, or one skill with N labeled subsections? When the answer is the latter, merge.
|
|
78
|
+
5. Judge overlap on CONTENT, not on usage counters.
|
|
79
|
+
6. Before archiving a merged skill, ensure its unique content was preserved in the umbrella.
|
|
80
|
+
|
|
81
|
+
How to work:
|
|
82
|
+
1. Scan the candidate list. Identify PREFIX CLUSTERS — skills sharing a first word or domain keyword (expect 10-25 clusters).
|
|
83
|
+
2. For each cluster with 2+ members, ask "what is the UMBRELLA CLASS these skills serve?" and consolidate:
|
|
84
|
+
a. MERGE INTO AN EXISTING UMBRELLA (patch a labeled section for each sibling's unique insight, then archive the siblings).
|
|
85
|
+
b. CREATE A NEW UMBRELLA SKILL.md covering the shared workflow with short labeled subsections, then archive the absorbed siblings.
|
|
86
|
+
c. DEMOTE session-specific detail to references/, templates/, or scripts/ under the umbrella.
|
|
87
|
+
3. Keep the umbrella body tight and scannable: exact commands, verbatim paths, ~100-200 lines; never invent flags or APIs.
|
|
88
|
+
|
|
89
|
+
Produce a YAML summary with exactly this shape:
|
|
90
|
+
consolidations:
|
|
91
|
+
- from: <old-skill-name>
|
|
92
|
+
into: <umbrella-skill-name>
|
|
93
|
+
reason: <one short sentence>
|
|
94
|
+
prunings:
|
|
95
|
+
- name: <skill-name>
|
|
96
|
+
reason: <one short sentence>
|
|
97
|
+
Nominate a pruning only when archival is clearly safe (stale AND genuinely obsolete or fully absorbed elsewhere).`;
|
|
98
|
+
const COMPLETION_SKILL_REVIEW_PROMPT = `[Auto-review — Skills · task complete]
|
|
99
|
+
Your current task now appears complete. Before wrapping up, review the approach and update the skill library via skill_manage.
|
|
100
|
+
|
|
101
|
+
Follow the skills review policy: be ACTIVE, prefer class-level umbrellas, patch ONLY skills loaded or read this session, and capture non-trivial techniques and user corrections. Do NOT capture environment-dependent failures, negative claims about tools, or one-off task narratives.
|
|
102
|
+
|
|
103
|
+
Do NOT modify output files or re-run the task. If you are still mid-task, ignore this.`;
|
|
104
|
+
function sha256(text) {
|
|
105
|
+
return createHash("sha256").update(text).digest("hex");
|
|
106
|
+
}
|
|
107
|
+
function createPromptBundle(prompts) {
|
|
108
|
+
const canonical = JSON.stringify({
|
|
109
|
+
id: PROMPT_BUNDLE_ID,
|
|
110
|
+
version: 3,
|
|
111
|
+
prompts: Object.fromEntries(Object.entries(prompts).sort())
|
|
112
|
+
});
|
|
113
|
+
return Object.freeze({
|
|
114
|
+
id: PROMPT_BUNDLE_ID,
|
|
115
|
+
version: 3,
|
|
116
|
+
prompts: Object.freeze({ ...prompts }),
|
|
117
|
+
sha256: sha256(canonical)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
createPromptBundle({
|
|
121
|
+
memory: MEMORY_REVIEW_PROMPT,
|
|
122
|
+
skill: SKILL_REVIEW_PROMPT,
|
|
123
|
+
combined: COMBINED_REVIEW_PROMPT,
|
|
124
|
+
curator: CURATOR_PROMPT,
|
|
125
|
+
completion: COMPLETION_SKILL_REVIEW_PROMPT
|
|
126
|
+
});
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region ../evolution-core/src/threats.ts
|
|
129
|
+
const FILLER = String.raw`(?:\w+\s+){0,8}`;
|
|
130
|
+
new RegExp(String.raw`ignore\s+${FILLER}(?:previous|above|prior|all)\s+${FILLER}instructions`, "i"), new RegExp(String.raw`new\s+${FILLER}system\s+${FILLER}prompt`, "i"), new RegExp(String.raw`forget\s+${FILLER}(?:everything|all)\s+${FILLER}(?:discussed|you\s+know)`, "i"), new RegExp(String.raw`you\s+have\s+been\s+${FILLER}(?:updated|upgraded|patched)\s+to`, "i"), new RegExp(String.raw`do\s+not\s+${FILLER}tell\s+${FILLER}the\s+user`, "i"), new RegExp(String.raw`output\s+${FILLER}(?:system|initial)\s+prompt`, "i");
|
|
131
|
+
//#endregion
|
|
132
|
+
//#region ../evolution-core/src/skill-store.ts
|
|
133
|
+
/**
|
|
134
|
+
* Map a requesting session onto the two origin surfaces (rc.44 plan M2-2.3):
|
|
135
|
+
* the APPROVAL surface treats every delegated subagent as the autonomous
|
|
136
|
+
* review channel, while the LIBRARY surface keeps the Hermes distinction -
|
|
137
|
+
* the review fork is 'background_review' (the pinned guard blocks its
|
|
138
|
+
* writes) and any other subagent is 'subagent' (agent-authored, not
|
|
139
|
+
* review-channel). `isReview` marks the caller as the background review
|
|
140
|
+
* pipeline itself. Single source: the two tools and the review executor all
|
|
141
|
+
* read this table instead of re-deriving it.
|
|
142
|
+
*/
|
|
143
|
+
function resolveOrigins(headerOrigin, isReview = false) {
|
|
144
|
+
if (isReview) return {
|
|
145
|
+
approval: "background_review",
|
|
146
|
+
library: "background_review"
|
|
147
|
+
};
|
|
148
|
+
if (headerOrigin === "subagent") return {
|
|
149
|
+
approval: "background_review",
|
|
150
|
+
library: "subagent"
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
approval: "foreground",
|
|
154
|
+
library: "foreground"
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
3
158
|
//#region lib/types/index.js
|
|
4
159
|
/**
|
|
5
160
|
* Model-facing memory tool and runtime-context memory snapshot.
|
|
@@ -179,7 +334,7 @@ async function apply(ctx, rawConfig) {
|
|
|
179
334
|
facts: args.facts ?? args.content,
|
|
180
335
|
old_text: args.old_text
|
|
181
336
|
};
|
|
182
|
-
const origin = exec.agent?.session.header.origin
|
|
337
|
+
const origin = resolveOrigins(exec.agent?.session.header.origin).approval;
|
|
183
338
|
const sessionPolicy = effectiveSessionPolicy(ctx, exec.agent?.session);
|
|
184
339
|
const approval = ctx.get("evolutionApproval");
|
|
185
340
|
if (approval) {
|
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.1.0-rc.
|
|
4
|
+
"version": "0.1.0-rc.46",
|
|
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.0-rc.6",
|
|
41
41
|
"@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6",
|
|
42
|
-
"@lmzhen/dsh-memory": "^0.1.0-rc.
|
|
43
|
-
"@lmzhen/dsh-memory-files": "^0.1.0-rc.
|
|
42
|
+
"@lmzhen/dsh-memory": "^0.1.0-rc.46",
|
|
43
|
+
"@lmzhen/dsh-memory-files": "^0.1.0-rc.46"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
|
|
47
47
|
"@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
|
|
48
48
|
"@deepseek-ai/dsh-system-prompt": "^0.1.0-rc.6",
|
|
49
49
|
"@deepseek-ai/dsh-agent-loop-testkit": "^0.1.0-rc.6",
|
|
50
|
-
"@lmzhen/dsh-memory": "^0.1.0-rc.
|
|
51
|
-
"@lmzhen/dsh-memory-files": "^0.1.0-rc.
|
|
50
|
+
"@lmzhen/dsh-memory": "^0.1.0-rc.46",
|
|
51
|
+
"@lmzhen/dsh-memory-files": "^0.1.0-rc.46"
|
|
52
52
|
}
|
|
53
53
|
}
|