@lmzhen/dsh-tool-skill-manage 0.30.31 → 0.30.36
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 +199 -5
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_SKILL_LIMITS, DEFAULT_SKILL_VERSION_KEEP, DEFAULT_SUPPORT_FILE_CHAR_POLICY, DSH_AUTHORING_STANDARDS, SKILLS_GUIDANCE, SKILLS_GUIDANCE_SECTION_ORDER, anchorVerdict, authoringFeedback, authorityFrom, callingScope, clampOnce, computeDedupGroups, contentHash, evolutionIoAdapter, findOwnerCandidate, fuzzyPatch, isPresent, isUnknown, liveBool, nearDuplicateSummaries, newSkillLibrary, normalizeFrontmatter, ownerCandidatesFromSummaries, paramRowId, parseFrontmatter, planExtract, policyStageLimits, probePresent, probeUnknown, projectExtractBodies, proposalFromPlan, protectedSkillNamesOf, readExternalSupport, resolveExecOrigins, sessionReadSkillNames, skillWriteGateContext, unwrapLive, userSetKeys } from "@lmzhen/dsh-evolution-core";
|
|
2
3
|
import { effectiveSessionPolicy } from "@lmzhen/dsh-evolution-approval";
|
|
3
4
|
import z from "@deepseek-ai/schemastery";
|
|
4
5
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
@@ -129,6 +130,116 @@ function validateSkillSettings(candidate, ceilings) {
|
|
|
129
130
|
if (next !== void 0 && next > ceilings[key]) throw new Error(`${key} may only be tightened: ${next} exceeds the deployment value ${ceilings[key]}`);
|
|
130
131
|
}
|
|
131
132
|
}
|
|
133
|
+
/** Build the one G1 plan both the execute path and the preview path consume. */
|
|
134
|
+
async function buildExtractPlan(library, operation) {
|
|
135
|
+
const source = typeof operation.name === "string" ? operation.name.trim() : "";
|
|
136
|
+
const raw = Array.isArray(operation.extract) ? operation.extract : [];
|
|
137
|
+
if (source === "" || raw.length === 0) return {
|
|
138
|
+
ok: false,
|
|
139
|
+
message: "extract 需要 name 与至少一个 extract 项。"
|
|
140
|
+
};
|
|
141
|
+
const requests = [];
|
|
142
|
+
let target = "";
|
|
143
|
+
for (const item of raw) {
|
|
144
|
+
if (item === null || typeof item !== "object") return {
|
|
145
|
+
ok: false,
|
|
146
|
+
message: "extract 的每一项都必须是对象。"
|
|
147
|
+
};
|
|
148
|
+
const heading = typeof item.heading === "string" ? item.heading.trim() : "";
|
|
149
|
+
const toSkill = typeof item.to_skill === "string" ? item.to_skill.trim() : "";
|
|
150
|
+
if (heading === "" || toSkill === "") return {
|
|
151
|
+
ok: false,
|
|
152
|
+
message: "extract 的每一项都需要 heading 与 to_skill。"
|
|
153
|
+
};
|
|
154
|
+
if (target === "") target = toSkill;
|
|
155
|
+
if (target !== toSkill) return {
|
|
156
|
+
ok: false,
|
|
157
|
+
message: "一次 extract 只能有一个 to_skill;多目标请分多次调用。"
|
|
158
|
+
};
|
|
159
|
+
if (item.to_heading !== void 0 && item.to_heading !== heading) return {
|
|
160
|
+
ok: false,
|
|
161
|
+
message: "to_heading 暂不支持改名;G3 要求 heading 与 to_heading 相同。"
|
|
162
|
+
};
|
|
163
|
+
requests.push({
|
|
164
|
+
heading,
|
|
165
|
+
...typeof item.start === "string" ? { start: item.start } : {},
|
|
166
|
+
...typeof item.end === "string" ? { end: item.end } : {}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const sourceMd = await library.read(source);
|
|
170
|
+
if (sourceMd === null) return {
|
|
171
|
+
ok: false,
|
|
172
|
+
message: "技能「" + source + "」不存在。"
|
|
173
|
+
};
|
|
174
|
+
const targetMd = await library.read(target);
|
|
175
|
+
if (targetMd === null) return {
|
|
176
|
+
ok: false,
|
|
177
|
+
message: "目标技能「" + target + "」不存在;owner-gap 不自动 create。"
|
|
178
|
+
};
|
|
179
|
+
if (source === target) return {
|
|
180
|
+
ok: false,
|
|
181
|
+
message: "source 与 target 不能相同。"
|
|
182
|
+
};
|
|
183
|
+
const candidate = findOwnerCandidate(ownerCandidatesFromSummaries(source, await library.list({
|
|
184
|
+
withContent: true,
|
|
185
|
+
withFrontmatter: true
|
|
186
|
+
})), target);
|
|
187
|
+
if (candidate === void 0) return {
|
|
188
|
+
ok: false,
|
|
189
|
+
message: "目标「" + target + "」不是可用的 owner candidate(描述为空或已排除);owner-gap,不自动 create。"
|
|
190
|
+
};
|
|
191
|
+
if (candidate.protectionUnknown || candidate.protectedBy !== null) return {
|
|
192
|
+
ok: false,
|
|
193
|
+
message: "目标「" + target + "」受保护(" + (candidate.protectedBy ?? "未知") + "),拒绝提取。"
|
|
194
|
+
};
|
|
195
|
+
const parsed = parseFrontmatter(sourceMd);
|
|
196
|
+
if (parsed === null) return {
|
|
197
|
+
ok: false,
|
|
198
|
+
message: "技能「" + source + "」没有可读取的正文。"
|
|
199
|
+
};
|
|
200
|
+
const sourceProbe = await library.listSupportFiles(source);
|
|
201
|
+
const targetProbe = await library.listSupportFiles(target);
|
|
202
|
+
if (!isPresent(sourceProbe) || !isPresent(targetProbe)) return {
|
|
203
|
+
ok: false,
|
|
204
|
+
message: "支撑文件列表不可读;拒绝在不确定的闭包上提取。"
|
|
205
|
+
};
|
|
206
|
+
const external = await readExternalSupport(parsed.body, join(library.root, source), dirname(library.root), targetProbe.value);
|
|
207
|
+
if (!external.ok) return {
|
|
208
|
+
ok: false,
|
|
209
|
+
message: external.message
|
|
210
|
+
};
|
|
211
|
+
const outcome = requests.some((request) => request.start !== void 0 || request.end !== void 0) ? "mixed" : "extract";
|
|
212
|
+
const plan = planExtract({
|
|
213
|
+
body: parsed.body,
|
|
214
|
+
sourceName: source,
|
|
215
|
+
targetName: target,
|
|
216
|
+
targetExists: true,
|
|
217
|
+
outcome,
|
|
218
|
+
owner: {
|
|
219
|
+
mode: "covered",
|
|
220
|
+
name: target,
|
|
221
|
+
triggerCovers: true,
|
|
222
|
+
outcomeCovers: true,
|
|
223
|
+
reason: "explicit target"
|
|
224
|
+
},
|
|
225
|
+
requests,
|
|
226
|
+
sourceFiles: sourceProbe.value,
|
|
227
|
+
targetFiles: targetProbe.value,
|
|
228
|
+
external: external.files,
|
|
229
|
+
anchors: {
|
|
230
|
+
sourceMdSha256: contentHash(sourceMd),
|
|
231
|
+
targetMdSha256: contentHash(targetMd)
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
if (!plan.ok) return {
|
|
235
|
+
ok: false,
|
|
236
|
+
message: plan.message
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
ok: true,
|
|
240
|
+
plan: plan.plan
|
|
241
|
+
};
|
|
242
|
+
}
|
|
132
243
|
/**
|
|
133
244
|
* What the staged skill write WOULD store, resolved WITHOUT writing.
|
|
134
245
|
*
|
|
@@ -228,6 +339,52 @@ async function previewSkillWrite(library, args) {
|
|
|
228
339
|
before,
|
|
229
340
|
after: null
|
|
230
341
|
};
|
|
342
|
+
if (action === "extract") {
|
|
343
|
+
const built = await buildExtractPlan(library, operation);
|
|
344
|
+
if (!built.ok) return {
|
|
345
|
+
available: false,
|
|
346
|
+
reason: built.message
|
|
347
|
+
};
|
|
348
|
+
const source = built.plan.source;
|
|
349
|
+
const target = built.plan.target.name;
|
|
350
|
+
const sourceBefore = await library.read(source);
|
|
351
|
+
const targetBefore = await library.read(target);
|
|
352
|
+
if (sourceBefore === null || targetBefore === null) return {
|
|
353
|
+
available: false,
|
|
354
|
+
reason: "source/target 在预览期间不可读。"
|
|
355
|
+
};
|
|
356
|
+
const projected = projectExtractBodies(built.plan, sourceBefore, targetBefore);
|
|
357
|
+
if (!projected.ok) return {
|
|
358
|
+
available: false,
|
|
359
|
+
reason: projected.message
|
|
360
|
+
};
|
|
361
|
+
const files = [{
|
|
362
|
+
path: source + "/SKILL.md",
|
|
363
|
+
before: sourceBefore,
|
|
364
|
+
after: projected.projection.sourceAfter
|
|
365
|
+
}, {
|
|
366
|
+
path: target + "/SKILL.md",
|
|
367
|
+
before: targetBefore,
|
|
368
|
+
after: projected.projection.targetAfter
|
|
369
|
+
}];
|
|
370
|
+
for (const move of [...built.plan.support.shared, ...built.plan.support.exclusive]) files.push({
|
|
371
|
+
path: target + "/" + move.to,
|
|
372
|
+
before: await library.readSupportFile(target, move.to),
|
|
373
|
+
after: await library.readSupportFile(source, move.from)
|
|
374
|
+
});
|
|
375
|
+
for (const move of built.plan.support.exclusive) files.push({
|
|
376
|
+
path: source + "/" + move.from,
|
|
377
|
+
before: await library.readSupportFile(source, move.from),
|
|
378
|
+
after: null
|
|
379
|
+
});
|
|
380
|
+
return {
|
|
381
|
+
available: true,
|
|
382
|
+
path: source + "/SKILL.md",
|
|
383
|
+
before: sourceBefore,
|
|
384
|
+
after: projected.projection.sourceAfter,
|
|
385
|
+
files
|
|
386
|
+
};
|
|
387
|
+
}
|
|
231
388
|
return {
|
|
232
389
|
available: false,
|
|
233
390
|
reason: "\"" + action + "\" has no byte-level preview"
|
|
@@ -511,6 +668,11 @@ function apply(ctx, rawConfig = {}) {
|
|
|
511
668
|
applyLimits();
|
|
512
669
|
const action = args.action;
|
|
513
670
|
const name = args.name ?? "";
|
|
671
|
+
if (action === "extract" && origin === "background_review") return {
|
|
672
|
+
ok: false,
|
|
673
|
+
message: "背景审查不能执行 extract:review 只提议;提取必须由显式前台工具/命令执行。",
|
|
674
|
+
skills: []
|
|
675
|
+
};
|
|
514
676
|
if (action === "review") try {
|
|
515
677
|
return {
|
|
516
678
|
ok: true,
|
|
@@ -570,6 +732,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
570
732
|
}
|
|
571
733
|
}
|
|
572
734
|
let result;
|
|
735
|
+
let proposal;
|
|
573
736
|
if (action === "create") {
|
|
574
737
|
feedbackLines.push(...await duplicateHintLines(name, candidateDescription, crossSourceView));
|
|
575
738
|
result = await library.create(name, args.content ?? "", origin);
|
|
@@ -591,6 +754,19 @@ function apply(ctx, rawConfig = {}) {
|
|
|
591
754
|
heading: typeof move.heading === "string" ? move.heading : "",
|
|
592
755
|
toFile: typeof move.to_file === "string" ? move.to_file : ""
|
|
593
756
|
})), origin);
|
|
757
|
+
} else if (action === "extract") {
|
|
758
|
+
const built = await buildExtractPlan(library, args);
|
|
759
|
+
if (!built.ok) result = {
|
|
760
|
+
ok: false,
|
|
761
|
+
message: built.message
|
|
762
|
+
};
|
|
763
|
+
else {
|
|
764
|
+
proposal = JSON.stringify(proposalFromPlan(built.plan, { runId: "tool-" + Date.now().toString(36) }));
|
|
765
|
+
result = args.dry_run === true ? {
|
|
766
|
+
ok: true,
|
|
767
|
+
message: "提取计划(未写入):" + built.plan.parts.map((part) => "## " + part.heading).join(", ") + " -> " + built.plan.target.name
|
|
768
|
+
} : await library.extract(built.plan, origin);
|
|
769
|
+
}
|
|
594
770
|
} else if (action === "pin") result = await library.setPinned(name, true, origin);
|
|
595
771
|
else if (action === "unpin") result = await library.setPinned(name, false, origin);
|
|
596
772
|
else result = {
|
|
@@ -612,7 +788,8 @@ function apply(ctx, rawConfig = {}) {
|
|
|
612
788
|
return {
|
|
613
789
|
ok: result.ok,
|
|
614
790
|
message: result.ok && feedbackLines.length > 0 ? `${result.message}\n\nAuthoring check:\n${feedbackLines.map((line) => `- ${line}`).join("\n")}` : result.message,
|
|
615
|
-
skills: []
|
|
791
|
+
skills: [],
|
|
792
|
+
...proposal === void 0 ? {} : { proposal }
|
|
616
793
|
};
|
|
617
794
|
}
|
|
618
795
|
/** Batch C (2026-09-27, design §3C-2): the create-time near-duplicate hint — one
|
|
@@ -699,7 +876,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
699
876
|
}
|
|
700
877
|
ctx.tools.register(defineTool({
|
|
701
878
|
name: "skill_manage",
|
|
702
|
-
description: "Manage reusable skills. review returns the library review text (state/usage/quality per skill); list returns names only; create/edit/update take full SKILL.md content (edit is an alias of update); patch applies old_string -> new_string; delete archives to .archive (absorbed_into names an umbrella skill); write_file/remove_file add or remove one support file under references/ or scripts/; pin protects a skill from deletion, background review, and the lifecycle (pin/unpin are never allowed from a background review — foreground and delegated subagents may). Per-action arguments: patch needs name + old_string + new_string and patches SKILL.md unless file_path names a support file (e.g. \"references/topic.md\"); patch replaces the FIRST occurrence only unless replace_all=true, and the result message reports how many anchors the file carried. write_file needs name + file_path + file_content; remove_file needs name + file_path; create/edit/update need name + content; delete needs name. A rejected patch names the reason and the remedy (missing anchor, stale snapshot, frontmatter that cannot be auto-quoted, byte/char limit). Protected bundled/hub skills reject any mutation; pinned skills reject deletion and are read-only to the background review.Prefer patching an umbrella over creating narrow skills. restructure moves entire body sections (by their exact \"## heading\" line, via restructure: [{heading, to_file: \"references/<topic>.md\"}]) into a references/ file and replaces each with a pointer line — the skill name and directory never change.Created/edited SKILL.md MUST start with YAML frontmatter (a name/description block), or creation is rejected. " + DSH_AUTHORING_STANDARDS,
|
|
879
|
+
description: "Manage reusable skills. review returns the library review text (state/usage/quality per skill); list returns names only; create/edit/update take full SKILL.md content (edit is an alias of update); patch applies old_string -> new_string; delete archives to .archive (absorbed_into names an umbrella skill); write_file/remove_file add or remove one support file under references/ or scripts/; pin protects a skill from deletion, background review, and the lifecycle (pin/unpin are never allowed from a background review — foreground and delegated subagents may). Per-action arguments: patch needs name + old_string + new_string and patches SKILL.md unless file_path names a support file (e.g. \"references/topic.md\"); patch replaces the FIRST occurrence only unless replace_all=true, and the result message reports how many anchors the file carried. write_file needs name + file_path + file_content; remove_file needs name + file_path; create/edit/update need name + content; delete needs name. A rejected patch names the reason and the remedy (missing anchor, stale snapshot, frontmatter that cannot be auto-quoted, byte/char limit). Protected bundled/hub skills reject any mutation; pinned skills reject deletion and are read-only to the background review.Prefer patching an umbrella over creating narrow skills. restructure moves entire body sections (by their exact \"## heading\" line, via restructure: [{heading, to_file: \"references/<topic>.md\"}]) into a references/ file and replaces each with a pointer line — the skill name and directory never change. extract moves a reusable part (exact heading, optional start/end sub-block) into an existing class-level owner: extract: [{heading, start?, end?, to_skill}]. One target per call; owner-gap is reported, never auto-created.Created/edited SKILL.md MUST start with YAML frontmatter (a name/description block), or creation is rejected. " + DSH_AUTHORING_STANDARDS,
|
|
703
880
|
parameters: {
|
|
704
881
|
action: {
|
|
705
882
|
type: "string",
|
|
@@ -715,6 +892,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
715
892
|
"write_file",
|
|
716
893
|
"remove_file",
|
|
717
894
|
"restructure",
|
|
895
|
+
"extract",
|
|
718
896
|
"pin",
|
|
719
897
|
"unpin"
|
|
720
898
|
]
|
|
@@ -737,7 +915,22 @@ function apply(ctx, rawConfig = {}) {
|
|
|
737
915
|
to_file: { type: "string" }
|
|
738
916
|
}
|
|
739
917
|
}
|
|
740
|
-
}
|
|
918
|
+
},
|
|
919
|
+
extract: {
|
|
920
|
+
type: "array",
|
|
921
|
+
items: {
|
|
922
|
+
type: "object",
|
|
923
|
+
additionalProperties: false,
|
|
924
|
+
properties: {
|
|
925
|
+
heading: { type: "string" },
|
|
926
|
+
start: { type: "string" },
|
|
927
|
+
end: { type: "string" },
|
|
928
|
+
to_skill: { type: "string" },
|
|
929
|
+
to_heading: { type: "string" }
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
},
|
|
933
|
+
dry_run: { type: "boolean" }
|
|
741
934
|
},
|
|
742
935
|
output: {
|
|
743
936
|
schema: {
|
|
@@ -757,7 +950,8 @@ function apply(ctx, rawConfig = {}) {
|
|
|
757
950
|
required: true,
|
|
758
951
|
items: { type: "string" }
|
|
759
952
|
},
|
|
760
|
-
pending_id: { type: "string" }
|
|
953
|
+
pending_id: { type: "string" },
|
|
954
|
+
proposal: { type: "string" }
|
|
761
955
|
}
|
|
762
956
|
},
|
|
763
957
|
render: (_args, value) => [{
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmzhen/dsh-tool-skill-manage",
|
|
3
3
|
"description": "Model-facing skill_manage tool (community build)",
|
|
4
|
-
"version": "0.30.
|
|
4
|
+
"version": "0.30.36",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,25 +27,25 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@deepseek-ai/schemastery": "^3.18.5",
|
|
30
|
-
"@lmzhen/dsh-evolution-approval": "^0.30.
|
|
31
|
-
"@lmzhen/dsh-evolution-core": "^0.30.
|
|
30
|
+
"@lmzhen/dsh-evolution-approval": "^0.30.36",
|
|
31
|
+
"@lmzhen/dsh-evolution-core": "^0.30.36"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@deepseek-ai/cordis": "^4.0.5",
|
|
35
35
|
"@deepseek-ai/dsh-skill": "^0.2.1-rc.2",
|
|
36
36
|
"@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.2",
|
|
37
37
|
"@deepseek-ai/dsh-tools": "^0.2.1-rc.2",
|
|
38
|
-
"@lmzhen/dsh-evolution-io": "^0.30.
|
|
39
|
-
"@lmzhen/dsh-skill-usage": "^0.30.
|
|
38
|
+
"@lmzhen/dsh-evolution-io": "^0.30.36",
|
|
39
|
+
"@lmzhen/dsh-skill-usage": "^0.30.36"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@deepseek-ai/dsh-agent-loop-testkit": "^0.2.1-rc.2",
|
|
43
43
|
"@deepseek-ai/dsh-skill": "^0.2.1-rc.2",
|
|
44
44
|
"@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.2",
|
|
45
45
|
"@deepseek-ai/dsh-tools": "^0.2.1-rc.2",
|
|
46
|
-
"@lmzhen/dsh-evolution-core": "^0.30.
|
|
47
|
-
"@lmzhen/dsh-evolution-io": "^0.30.
|
|
48
|
-
"@lmzhen/dsh-skill-usage": "^0.30.
|
|
46
|
+
"@lmzhen/dsh-evolution-core": "^0.30.36",
|
|
47
|
+
"@lmzhen/dsh-evolution-io": "^0.30.36",
|
|
48
|
+
"@lmzhen/dsh-skill-usage": "^0.30.36"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"dsh": ">=0.2.1-rc.2 <0.2.2-0"
|