@lmzhen/dsh-tool-skill-manage 0.30.36 → 0.30.38

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 +123 -102
  2. package/package.json +9 -8
package/lib/index.js CHANGED
@@ -1,5 +1,4 @@
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";
1
+ import { DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_HEALTH_THRESHOLDS, DEFAULT_REFERENCE_REWRITE_POLICY, DEFAULT_SKILL_LIMITS, DEFAULT_SKILL_VERSION_KEEP, DEFAULT_SUPPORT_FILE_CHAR_POLICY, DSH_AUTHORING_STANDARDS, EXTRACT_PROMPT_V1, SKILLS_GUIDANCE, SKILLS_GUIDANCE_SECTION_ORDER, anchorVerdict, authoringFeedback, authorityFrom, buildExtractPlanFromLibrary, callingScope, clampOnce, computeDedupGroups, contentHash, createSubagentChannel, evolutionIoAdapter, fuzzyPatch, isPresent, isUnknown, liveBool, nearDuplicateSummaries, newSkillLibrary, normalizeFrontmatter, ownerCandidatesFromSummaries, paramRowId, parseFrontmatter, policyStageLimits, probePresent, probeUnknown, projectExtractBodies, proposalFromPlan, protectedSkillNamesOf, resolveExecOrigins, sessionReadSkillNames, skillWriteGateContext, unwrapLive, userSetKeys, writeProposalReport } from "@lmzhen/dsh-evolution-core";
3
2
  import { effectiveSessionPolicy } from "@lmzhen/dsh-evolution-approval";
4
3
  import z from "@deepseek-ai/schemastery";
5
4
  import { defineTool } from "@deepseek-ai/dsh-tools";
@@ -130,114 +129,80 @@ function validateSkillSettings(candidate, ceilings) {
130
129
  if (next !== void 0 && next > ceilings[key]) throw new Error(`${key} may only be tightened: ${next} exceeds the deployment value ${ceilings[key]}`);
131
130
  }
132
131
  }
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 {
132
+ async function proposeExtractWithAgent(ctx, parent, library, source) {
133
+ if (parent === void 0) return {
138
134
  ok: false,
139
- message: "extract 需要 name 与至少一个 extract 项。"
135
+ message: "extract agent 不可用:当前调用没有 agent 上下文。"
140
136
  };
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 {
137
+ const body = await library.read(source);
138
+ if (body === null) return {
171
139
  ok: false,
172
140
  message: "技能「" + source + "」不存在。"
173
141
  };
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({
142
+ const lookup = ownerCandidatesFromSummaries(source, await library.model.list({
184
143
  withContent: true,
185
144
  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)
145
+ }));
146
+ const support = await library.listSupportFiles(source);
147
+ const input = JSON.stringify({
148
+ source,
149
+ body,
150
+ support: isPresent(support) ? support.value : null,
151
+ candidates: lookup.candidates.map((candidate) => ({
152
+ name: candidate.name,
153
+ description: candidate.description,
154
+ whenToUse: candidate.whenToUse ?? null,
155
+ headings: candidate.headings
156
+ })),
157
+ excluded: lookup.excluded
158
+ });
159
+ const outcome = await createSubagentChannel(ctx).run({
160
+ parent,
161
+ label: "dsh-evolution-extract",
162
+ kind: "maintainer",
163
+ allow: ["skill"],
164
+ promptText: EXTRACT_PROMPT_V1 + "\n\nEXTRACT INPUT\n" + input,
165
+ timeoutMs: 12e4,
166
+ outputSchema: {
167
+ type: "object",
168
+ additionalProperties: false,
169
+ required: ["outcome", "reason"],
170
+ properties: {
171
+ outcome: {
172
+ type: "string",
173
+ enum: [
174
+ "keep",
175
+ "extract",
176
+ "mixed",
177
+ "owner-gap"
178
+ ]
179
+ },
180
+ target: { type: "string" },
181
+ neededOwner: { type: "string" },
182
+ reason: { type: "string" },
183
+ parts: {
184
+ type: "array",
185
+ items: {
186
+ type: "object",
187
+ additionalProperties: false,
188
+ required: ["heading"],
189
+ properties: {
190
+ heading: { type: "string" },
191
+ start: { type: "string" },
192
+ end: { type: "string" }
193
+ }
194
+ }
195
+ }
196
+ }
232
197
  }
233
198
  });
234
- if (!plan.ok) return {
199
+ if (outcome.kind !== "ok") return {
235
200
  ok: false,
236
- message: plan.message
201
+ message: "extract agent 不可用:" + ("reason" in outcome ? outcome.reason : outcome.kind)
237
202
  };
238
203
  return {
239
204
  ok: true,
240
- plan: plan.plan
205
+ proposal: JSON.stringify(outcome.structured)
241
206
  };
242
207
  }
243
208
  /**
@@ -340,7 +305,12 @@ async function previewSkillWrite(library, args) {
340
305
  after: null
341
306
  };
342
307
  if (action === "extract") {
343
- const built = await buildExtractPlan(library, operation);
308
+ const built = await buildExtractPlanFromLibrary(library, {
309
+ source: typeof operation.name === "string" ? operation.name : "",
310
+ items: Array.isArray(operation.extract) ? operation.extract : [],
311
+ ...operation.outcome === void 0 ? {} : { outcome: operation.outcome },
312
+ ...operation.owner_covers === void 0 ? {} : { ownerCovers: operation.owner_covers }
313
+ });
344
314
  if (!built.ok) return {
345
315
  available: false,
346
316
  reason: built.message
@@ -581,6 +551,9 @@ function apply(ctx, rawConfig = {}) {
581
551
  ctx,
582
552
  threatExemptLabels: rawConfig.threatExemptLabels
583
553
  });
554
+ library.recoverOnBoot().catch((error) => {
555
+ ctx.logger.warn("skill_manage: boot unit recovery failed: " + (error instanceof Error ? error.message : String(error)));
556
+ });
584
557
  /** Write the CURRENT resolved settings into the library's live limits object. */
585
558
  const applyLimits = () => {
586
559
  const resolved = settings();
@@ -735,7 +708,7 @@ function apply(ctx, rawConfig = {}) {
735
708
  let proposal;
736
709
  if (action === "create") {
737
710
  feedbackLines.push(...await duplicateHintLines(name, candidateDescription, crossSourceView));
738
- result = await library.create(name, args.content ?? "", origin);
711
+ result = await library.create(name, args.content ?? "", origin, { managed: origin !== "foreground" });
739
712
  } else if (action === "edit" || action === "update") result = await library.update(name, args.content ?? "", origin, stagedAnchor);
740
713
  else if (action === "patch") result = await library.patch(name, args.old_string ?? "", args.new_string ?? "", args.file_path ?? "", args.replace_all === true, origin);
741
714
  else if (action === "delete") result = await library.archive(name, args.absorbed_into ? { absorbedInto: args.absorbed_into } : {});
@@ -755,17 +728,37 @@ function apply(ctx, rawConfig = {}) {
755
728
  toFile: typeof move.to_file === "string" ? move.to_file : ""
756
729
  })), origin);
757
730
  } else if (action === "extract") {
758
- const built = await buildExtractPlan(library, args);
731
+ const built = await buildExtractPlanFromLibrary(library, {
732
+ source: typeof args.name === "string" ? args.name : "",
733
+ items: Array.isArray(args.extract) ? args.extract : [],
734
+ ...args.outcome === void 0 ? {} : { outcome: args.outcome },
735
+ ...args.owner_covers === void 0 ? {} : { ownerCovers: args.owner_covers }
736
+ });
759
737
  if (!built.ok) result = {
760
738
  ok: false,
761
739
  message: built.message
762
740
  };
763
741
  else {
764
742
  proposal = JSON.stringify(proposalFromPlan(built.plan, { runId: "tool-" + Date.now().toString(36) }));
743
+ const ownerText = built.plan.owner.mode === "covered" ? `covered by ${built.plan.owner.name}` : `owner-gap, neededOwner=${built.plan.owner.neededOwner ?? "unknown"}`;
744
+ const decisionLine = `提取判定:outcome=${built.plan.outcome};target=${built.plan.target.name};owner=${ownerText}`;
745
+ const candidateLines = built.candidates.slice(0, 8).map((candidate) => "- " + candidate.name + ":" + candidate.description + (candidate.whenToUse === void 0 ? "" : ";whenToUse: " + candidate.whenToUse) + (candidate.headings.length === 0 ? "" : ";headings: " + candidate.headings.join(" / ")));
765
746
  result = args.dry_run === true ? {
766
747
  ok: true,
767
- message: "提取计划(未写入):" + built.plan.parts.map((part) => "## " + part.heading).join(", ") + " -> " + built.plan.target.name
748
+ message: "提取计划(未写入):" + built.plan.parts.map((part) => "## " + part.heading).join(", ") + " -> " + built.plan.target.name + "\n" + decisionLine + (candidateLines.length === 0 ? "" : "\n候选 owner:\n" + candidateLines.join("\n"))
768
749
  } : await library.extract(built.plan, origin);
750
+ if (result.ok && built.warnings !== void 0 && built.warnings.length > 0) result = {
751
+ ...result,
752
+ message: result.message + "\n" + built.warnings.join("\n")
753
+ };
754
+ if (args.dry_run === true) try {
755
+ const io = ctx.get("evolutionIo")?.provider();
756
+ if (io !== void 0) await writeProposalReport(io, proposalFromPlan(built.plan, { runId: "tool-" + Date.now().toString(36) }));
757
+ } catch {}
758
+ if (result.ok) result = {
759
+ ...result,
760
+ message: result.message + "\n" + decisionLine
761
+ };
769
762
  }
770
763
  } else if (action === "pin") result = await library.setPinned(name, true, origin);
771
764
  else if (action === "unpin") result = await library.setPinned(name, false, origin);
@@ -779,8 +772,12 @@ function apply(ctx, rawConfig = {}) {
779
772
  skills: []
780
773
  };
781
774
  if (result.ok) {
775
+ if (name !== void 0 && name !== "" && (action === "create" || action === "update" || action === "patch")) {
776
+ const body = action === "create" ? args.content ?? null : await library.read(name);
777
+ if (body !== null && body.length > DEFAULT_HEALTH_THRESHOLDS.softBodyChars) feedbackLines.push(`正文 ${body.length} 字符,超过 ${DEFAULT_HEALTH_THRESHOLDS.softBodyChars} 字符软线;保持不改是合法的。`);
778
+ }
782
779
  if (result.normalizedFrontmatterFields && result.normalizedFrontmatterFields.length > 0) feedbackLines.push(`frontmatter auto-quoted (YAML compatibility): ${result.normalizedFrontmatterFields.join(", ")}`);
783
- const mutating = !isReadOnlyAction(action);
780
+ const mutating = !isReadOnlyAction(action) && !(action === "extract" && args.dry_run === true);
784
781
  if (name && action === "create") await ctx.skillUsage.ensureRecordCreated(name, origin !== "foreground");
785
782
  if (name && action === "delete") await ctx.skillUsage.markArchived(name);
786
783
  else if (name && mutating && action !== "create" && result.noop !== true) await ctx.skillUsage.record(name, "patch");
@@ -930,6 +927,11 @@ function apply(ctx, rawConfig = {}) {
930
927
  }
931
928
  }
932
929
  },
930
+ outcome: {
931
+ type: "string",
932
+ enum: ["extract", "mixed"]
933
+ },
934
+ owner_covers: { type: "boolean" },
933
935
  dry_run: { type: "boolean" }
934
936
  },
935
937
  output: {
@@ -1061,6 +1063,25 @@ function apply(ctx, rawConfig = {}) {
1061
1063
  ...decision.pendingId !== void 0 ? { pending_id: decision.pendingId } : {}
1062
1064
  };
1063
1065
  }
1066
+ if (operation.action === "extract" && operation.dry_run === true && (operation.extract === void 0 || operation.extract.length === 0)) {
1067
+ const source = typeof operation.name === "string" ? operation.name.trim() : "";
1068
+ if (source === "") return {
1069
+ ok: false,
1070
+ message: "extract agent 需要 name。",
1071
+ skills: []
1072
+ };
1073
+ const proposed = await proposeExtractWithAgent(ctx, exec.agent, library, source);
1074
+ return proposed.ok ? {
1075
+ ok: true,
1076
+ message: "提取提议(未写入)。",
1077
+ skills: [],
1078
+ proposal: proposed.proposal
1079
+ } : {
1080
+ ok: false,
1081
+ message: proposed.message,
1082
+ skills: []
1083
+ };
1084
+ }
1064
1085
  return await executeCore(operation, libraryOrigin, crossSourceView ?? void 0);
1065
1086
  }
1066
1087
  }));
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.36",
4
+ "version": "0.30.38",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -27,25 +27,26 @@
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "@deepseek-ai/schemastery": "^3.18.5",
30
- "@lmzhen/dsh-evolution-approval": "^0.30.36",
31
- "@lmzhen/dsh-evolution-core": "^0.30.36"
30
+ "@lmzhen/dsh-evolution-approval": "^0.30.38",
31
+ "@lmzhen/dsh-evolution-core": "^0.30.38"
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.36",
39
- "@lmzhen/dsh-skill-usage": "^0.30.36"
38
+ "@deepseek-ai/dsh-agent": "^0.2.1-rc.2",
39
+ "@lmzhen/dsh-evolution-io": "^0.30.38",
40
+ "@lmzhen/dsh-skill-usage": "^0.30.38"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@deepseek-ai/dsh-agent-loop-testkit": "^0.2.1-rc.2",
43
44
  "@deepseek-ai/dsh-skill": "^0.2.1-rc.2",
44
45
  "@deepseek-ai/dsh-system-prompt": "^0.2.1-rc.2",
45
46
  "@deepseek-ai/dsh-tools": "^0.2.1-rc.2",
46
- "@lmzhen/dsh-evolution-core": "^0.30.36",
47
- "@lmzhen/dsh-evolution-io": "^0.30.36",
48
- "@lmzhen/dsh-skill-usage": "^0.30.36"
47
+ "@lmzhen/dsh-evolution-core": "^0.30.38",
48
+ "@lmzhen/dsh-evolution-io": "^0.30.38",
49
+ "@lmzhen/dsh-skill-usage": "^0.30.38"
49
50
  },
50
51
  "engines": {
51
52
  "dsh": ">=0.2.1-rc.2 <0.2.2-0"