@lmzhen/dsh-evolution-plan-validator 0.1.0-rc.4 → 0.1.0-rc.40

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 CHANGED
@@ -1,3 +1,131 @@
1
+ import { createHash } from "node:crypto";
2
+ //#endregion
3
+ //#region ../evolution-core/src/prompts.ts
4
+ /**
5
+ * Review and curation prompts adapted from Hermes Agent
6
+ * `agent/background_review.py`, `agent/curator.py`, and
7
+ * `agent/learn_prompt.py`, with tool names translated to the DSH-native
8
+ * catalog (`memory`, `skill_manage`, `skill`, `bash`, `str_replace_editor`).
9
+ *
10
+ * Every prompt is pinned in a versioned bundle. Review workers verify the
11
+ * bundle digest before spending a model call, so a partially-patched
12
+ * deployment fails closed instead of silently running a truncated prompt.
13
+ */
14
+ /**
15
+ * Prompt bundle identity. Bump both id and version whenever a prompt's text
16
+ * changes semantically: the bundle digest is the fail-closed signal for
17
+ * review workers, so a stale id across deployments must be distinguishable.
18
+ */
19
+ const PROMPT_BUNDLE_ID = "dsh-evolution@2";
20
+ const MEMORY_REVIEW_PROMPT = `[Auto-review — Memory]
21
+ Review the conversation above and consider saving to memory if appropriate.
22
+
23
+ Focus on:
24
+ 1. Has the user revealed things about themselves — persona, desires, preferences, or personal details worth remembering?
25
+ 2. Has the user expressed expectations about how you should behave, their work style, or ways they want you to operate?
26
+
27
+ If something stands out, save it using the memory tool.
28
+ If nothing is worth saving, just say "Nothing to save." and stop.`;
29
+ const SKILL_REVIEW_PROMPT = `[Auto-review — Skills]
30
+ Review the conversation above and update the skill library. Be ACTIVE — most sessions produce at least one skill update, even if small.
31
+
32
+ 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.
33
+
34
+ Signals that warrant action:
35
+ - The user corrected your style, tone, format, verbosity, workflow, or approach.
36
+ - A non-trivial technique, fix, workaround, or debugging path emerged.
37
+ - A loaded skill turned out wrong, missing, or outdated — patch it now.
38
+
39
+ Preference order:
40
+ 1. Patch a skill that was loaded or read this session.
41
+ 2. Patch an existing umbrella skill.
42
+ 3. Add references/, templates/, or scripts/ support under an existing skill.
43
+ 4. Create a new class-level umbrella skill only when nothing fits.
44
+
45
+ Protected skills (bundled/hub-installed) must not be edited. Pinned skills may be patched but not archived.
46
+
47
+ Do NOT capture:
48
+ - Environment-dependent failures (missing binaries, unconfigured credentials).
49
+ - Negative claims about tools ("browser tools do not work").
50
+ - Transient errors that resolved during the session.
51
+ - One-off task narratives.
52
+
53
+ 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.
54
+
55
+ "Nothing to save." is a real option but should NOT be the default.`;
56
+ const COMBINED_REVIEW_PROMPT = `[Auto-review]
57
+ Review the conversation above and update two things.
58
+
59
+ **Memory**: who the user is. Save durable user preferences, personal details, and expectations with the memory tool.
60
+
61
+ **Skills**: how to do this class of task. Be ACTIVE. Follow the same class-level umbrella policy, preference order, protected-skill rules, and do-not-capture list as a skill review.
62
+
63
+ 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.`;
64
+ const CURATOR_PROMPT = `You are the skill curator. Maintain a healthy, class-level skill library, not a flat pile of narrow one-session skills.
65
+
66
+ 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.
67
+
68
+ Right target shape: class-level skills with rich SKILL.md + references/, templates/, scripts/ support files for session-specific detail.
69
+
70
+ Hard rules:
71
+ 1. NEVER hard-delete a skill. Archive (moving to .archive/) is the maximum destructive action; archives are recoverable, deletion is not.
72
+ 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.
73
+ 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.
74
+ 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.
75
+ 5. Judge overlap on CONTENT, not on usage counters.
76
+ 6. Before archiving a merged skill, ensure its unique content was preserved in the umbrella.
77
+
78
+ How to work:
79
+ 1. Scan the candidate list. Identify PREFIX CLUSTERS — skills sharing a first word or domain keyword (expect 10-25 clusters).
80
+ 2. For each cluster with 2+ members, ask "what is the UMBRELLA CLASS these skills serve?" and consolidate:
81
+ a. MERGE INTO AN EXISTING UMBRELLA (patch a labeled section for each sibling's unique insight, then archive the siblings).
82
+ b. CREATE A NEW UMBRELLA SKILL.md covering the shared workflow with short labeled subsections, then archive the absorbed siblings.
83
+ c. DEMOTE session-specific detail to references/, templates/, or scripts/ under the umbrella.
84
+ 3. Keep the umbrella body tight and scannable: exact commands, verbatim paths, ~100-200 lines; never invent flags or APIs.
85
+
86
+ Produce a YAML summary with exactly this shape:
87
+ consolidations:
88
+ - from: <old-skill-name>
89
+ into: <umbrella-skill-name>
90
+ reason: <one short sentence>
91
+ prunings:
92
+ - name: <skill-name>
93
+ reason: <one short sentence>
94
+ Nominate a pruning only when archival is clearly safe (stale AND genuinely obsolete or fully absorbed elsewhere).`;
95
+ const COMPLETION_SKILL_REVIEW_PROMPT = `[Auto-review — Skills · task complete]
96
+ Your current task now appears complete. Before wrapping up, review the approach and update the skill library via skill_manage.
97
+
98
+ Follow the skills review policy: be ACTIVE, prefer class-level umbrellas, patch skills loaded 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.
99
+
100
+ Do NOT modify output files or re-run the task. If you are still mid-task, ignore this.`;
101
+ function sha256(text) {
102
+ return createHash("sha256").update(text).digest("hex");
103
+ }
104
+ function createPromptBundle(prompts) {
105
+ const canonical = JSON.stringify({
106
+ id: PROMPT_BUNDLE_ID,
107
+ version: 2,
108
+ prompts: Object.fromEntries(Object.entries(prompts).sort())
109
+ });
110
+ return Object.freeze({
111
+ id: PROMPT_BUNDLE_ID,
112
+ version: 2,
113
+ prompts: Object.freeze({ ...prompts }),
114
+ sha256: sha256(canonical)
115
+ });
116
+ }
117
+ createPromptBundle({
118
+ memory: MEMORY_REVIEW_PROMPT,
119
+ skill: SKILL_REVIEW_PROMPT,
120
+ combined: COMBINED_REVIEW_PROMPT,
121
+ curator: CURATOR_PROMPT,
122
+ completion: COMPLETION_SKILL_REVIEW_PROMPT
123
+ });
124
+ //#endregion
125
+ //#region ../evolution-core/src/threats.ts
126
+ const FILLER = String.raw`(?:\w+\s+){0,8}`;
127
+ 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");
128
+ //#endregion
1
129
  //#region lib/types/index.js
2
130
  /**
3
131
  * Deterministic validator for model-produced evolution plans.
@@ -116,7 +244,10 @@ function validateSkillOp(op, context, index) {
116
244
  if (!SKILL_ACTIONS.has(action)) return `skill op ${index}: unknown action ${action}`;
117
245
  if ((action === "create" || action === "edit" || action === "update") && !(op.content ?? "").trim()) return `skill op ${index}: ${action} requires content`;
118
246
  if (action === "patch" && !(op.old_string ?? "")) return `skill op ${index}: patch requires old_string`;
119
- if ((op.content ?? "").length > (context.maxSkillContentChars ?? 1e5)) return `skill op ${index}: content exceeds skill budget`;
247
+ if (action === "delete" && !(op.absorbed_into ?? "").trim()) return `skill op ${index}: delete requires absorbed_into`;
248
+ const writeContent = op.file_content ?? op.content ?? "";
249
+ if (action === "write_file" && !writeContent.trim()) return `skill op ${index}: write_file requires file_content`;
250
+ if (writeContent.length > (context.maxSkillContentChars ?? 1e5)) return `skill op ${index}: content exceeds skill budget`;
120
251
  return null;
121
252
  }
122
253
  //#endregion
@@ -15,6 +15,8 @@ export interface SkillOp {
15
15
  action?: string;
16
16
  name?: string;
17
17
  content?: string;
18
+ /** write_file payload (the tool reads `file_content`, not `content`). */
19
+ file_content?: string;
18
20
  old_string?: string;
19
21
  new_string?: string;
20
22
  file_path?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-plan-validator",
3
3
  "description": "Deterministic validator for model-produced evolution plans (community build)",
4
- "version": "0.1.0-rc.4",
4
+ "version": "0.1.0-rc.40",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },