@lmzhen/dsh-tool-skill-manage 0.22.0 → 0.24.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 +40 -27
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -31,7 +31,7 @@ import { DEFAULT_ARCHIVE_RETENTION_POLICY, DEFAULT_CITATION_POLICY, DEFAULT_REFE
|
|
|
31
31
|
* can never be read as the answer to a later one. */
|
|
32
32
|
const CONFIRM_QUESTION_ID = "evolution-skill-write";
|
|
33
33
|
/** The cancel label every confirm question offers. */
|
|
34
|
-
const CANCEL_LABEL = "
|
|
34
|
+
const CANCEL_LABEL = "取消";
|
|
35
35
|
/** What a `timeout`-mode deadline settles with: comparable by identity against the seam's
|
|
36
36
|
* boolean, so the two outcomes stay distinguishable without a mutable flag (which a linter
|
|
37
37
|
* cannot follow through a timer callback, and a reader cannot either). */
|
|
@@ -151,7 +151,7 @@ const GATES = [
|
|
|
151
151
|
warn("skill_manage: no confirmation channel is mounted, so the write proceeds unconfirmed.");
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
|
-
const confirmLabel = action === "create" ? "
|
|
154
|
+
const confirmLabel = action === "create" ? "创建" : "删除";
|
|
155
155
|
const seconds = timeoutSecondsOf(confirmTimeoutSeconds);
|
|
156
156
|
const cancel = new AbortController();
|
|
157
157
|
let timer;
|
|
@@ -163,15 +163,15 @@ const GATES = [
|
|
|
163
163
|
timer.unref();
|
|
164
164
|
}) : void 0;
|
|
165
165
|
const context = await describeTarget?.();
|
|
166
|
-
const details = [context?.description === void 0 || context.description === "" ? null : "
|
|
167
|
-
const consequence = action === "create" ?
|
|
166
|
+
const details = [context?.description === void 0 || context.description === "" ? null : "功能:" + context.description, context?.versions === void 0 ? null : "已记录的内容版本数:" + String(context.versions)].filter((line) => line !== null);
|
|
167
|
+
const consequence = action === "create" ? `创建技能 "${view.name}"?会在家族目录树里新建一个技能目录。` : `删除技能 "${view.name}"?它会被归档到 .archive 并离开目录。`;
|
|
168
168
|
const asked = confirm({
|
|
169
169
|
action,
|
|
170
170
|
name: view.name,
|
|
171
171
|
confirmLabel,
|
|
172
172
|
question: {
|
|
173
173
|
id: CONFIRM_QUESTION_ID,
|
|
174
|
-
header: "
|
|
174
|
+
header: "确认",
|
|
175
175
|
question: details.length === 0 ? consequence : consequence + " " + details.join(" · "),
|
|
176
176
|
options: [{ label: confirmLabel }, { label: CANCEL_LABEL }]
|
|
177
177
|
},
|
|
@@ -186,12 +186,12 @@ const GATES = [
|
|
|
186
186
|
if (outcome === true) return null;
|
|
187
187
|
if (outcome === CONFIRM_TIMED_OUT || cancel.signal.aborted) return errorText("e-319-skill-write-confirm-timed-out", {
|
|
188
188
|
a1: view.name,
|
|
189
|
-
a2: action === "create" ? "
|
|
189
|
+
a2: action === "create" ? "创建" : "删除",
|
|
190
190
|
a3: String(seconds)
|
|
191
191
|
});
|
|
192
192
|
return errorText("e-317-skill-write-not-confirmed", {
|
|
193
193
|
a1: view.name,
|
|
194
|
-
a2: action === "create" ? "
|
|
194
|
+
a2: action === "create" ? "创建" : "删除"
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
197
|
}
|
|
@@ -235,6 +235,19 @@ async function runWriteGates(context) {
|
|
|
235
235
|
* documented in the README Safety model section.
|
|
236
236
|
* @module @lmzhen/dsh-tool-skill-manage
|
|
237
237
|
*/
|
|
238
|
+
/**
|
|
239
|
+
* F-2 (audit v46 / G7.2): the read-only action set used to be spelled out FOUR times in this file
|
|
240
|
+
* (usage accounting at the patch_count bump, the cross-source directory exemption, the approval gap
|
|
241
|
+
* and the replay exemption). The four USES stay where they are — their neighbouring logic differs —
|
|
242
|
+
* but the CRITERION is this one predicate, so adding an action cannot update three of four.
|
|
243
|
+
*/
|
|
244
|
+
const READ_ONLY_ACTIONS = [
|
|
245
|
+
"list",
|
|
246
|
+
"review",
|
|
247
|
+
"pin",
|
|
248
|
+
"unpin"
|
|
249
|
+
];
|
|
250
|
+
const isReadOnlyAction = (action) => typeof action === "string" && READ_ONLY_ACTIONS.includes(action);
|
|
238
251
|
const name = "tool-skill-manage";
|
|
239
252
|
const inject = [
|
|
240
253
|
"tools",
|
|
@@ -315,7 +328,7 @@ async function previewSkillWrite(library, args) {
|
|
|
315
328
|
const name = typeof operation.name === "string" ? operation.name.trim() : "";
|
|
316
329
|
if (name === "") return {
|
|
317
330
|
available: false,
|
|
318
|
-
reason: "
|
|
331
|
+
reason: "这条暂存写入没有指明技能"
|
|
319
332
|
};
|
|
320
333
|
const filePath = typeof operation.file_path === "string" && operation.file_path !== "" ? operation.file_path : null;
|
|
321
334
|
const path = filePath ?? "SKILL.md";
|
|
@@ -323,7 +336,7 @@ async function previewSkillWrite(library, args) {
|
|
|
323
336
|
const staged = operation.staged_from_sha256;
|
|
324
337
|
if (anchorVerdict(typeof staged === "string" && staged !== "" ? staged === "absent" ? { absent: true } : { sha256: staged } : void 0, before) !== "match") return {
|
|
325
338
|
available: false,
|
|
326
|
-
reason: "
|
|
339
|
+
reason: "目标在这次写入暂存之后发生了变化 —— 批准它会被拒绝"
|
|
327
340
|
};
|
|
328
341
|
const action = typeof operation.action === "string" ? operation.action : "";
|
|
329
342
|
/**
|
|
@@ -347,7 +360,7 @@ async function previewSkillWrite(library, args) {
|
|
|
347
360
|
const norm = normalizeFrontmatter(content);
|
|
348
361
|
if (norm.issues.length > 0) return {
|
|
349
362
|
available: false,
|
|
350
|
-
reason: "frontmatter
|
|
363
|
+
reason: "frontmatter 无法自动修复:" + norm.issues.join("; ")
|
|
351
364
|
};
|
|
352
365
|
return {
|
|
353
366
|
available: true,
|
|
@@ -358,23 +371,23 @@ async function previewSkillWrite(library, args) {
|
|
|
358
371
|
};
|
|
359
372
|
if (action === "create" || action === "update") return typeof operation.content === "string" ? bodyOnDisk(operation.content) : {
|
|
360
373
|
available: false,
|
|
361
|
-
reason: "\"" + action + "\"
|
|
374
|
+
reason: "\"" + action + "\" 没有携带内容"
|
|
362
375
|
};
|
|
363
376
|
if (action === "patch") {
|
|
364
377
|
if (before === null) return {
|
|
365
378
|
available: false,
|
|
366
|
-
reason: "
|
|
379
|
+
reason: "该技能没有可修补的正文"
|
|
367
380
|
};
|
|
368
381
|
const patched = fuzzyPatch(before, operation.old_string ?? "", operation.new_string ?? "", operation.replace_all === true);
|
|
369
382
|
return patched === null ? {
|
|
370
383
|
available: false,
|
|
371
|
-
reason: "
|
|
384
|
+
reason: "暂存的旧文本不在当前正文里 —— 批准它会被拒绝"
|
|
372
385
|
} : bodyOnDisk(patched);
|
|
373
386
|
}
|
|
374
387
|
if (action === "write_file") {
|
|
375
388
|
if (typeof operation.file_content !== "string") return {
|
|
376
389
|
available: false,
|
|
377
|
-
reason: "\"write_file\"
|
|
390
|
+
reason: "\"write_file\" 没有携带内容"
|
|
378
391
|
};
|
|
379
392
|
return {
|
|
380
393
|
available: true,
|
|
@@ -385,7 +398,7 @@ async function previewSkillWrite(library, args) {
|
|
|
385
398
|
}
|
|
386
399
|
if (action === "remove_file") return before === null ? {
|
|
387
400
|
available: false,
|
|
388
|
-
reason: "
|
|
401
|
+
reason: "该支撑文件不存在,无法移除"
|
|
389
402
|
} : {
|
|
390
403
|
available: true,
|
|
391
404
|
path,
|
|
@@ -690,7 +703,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
690
703
|
} catch (error) {
|
|
691
704
|
return {
|
|
692
705
|
ok: false,
|
|
693
|
-
message: `skill_manage review
|
|
706
|
+
message: `skill_manage review:技能目录树扫描失败(${error instanceof Error ? error.message : String(error)})。`,
|
|
694
707
|
skills: []
|
|
695
708
|
};
|
|
696
709
|
}
|
|
@@ -698,13 +711,13 @@ function apply(ctx, rawConfig = {}) {
|
|
|
698
711
|
const list = await library.list();
|
|
699
712
|
return {
|
|
700
713
|
ok: true,
|
|
701
|
-
message:
|
|
714
|
+
message: `已列出 ${list.length} 个技能。`,
|
|
702
715
|
skills: list.map((s) => s.name)
|
|
703
716
|
};
|
|
704
717
|
} catch (error) {
|
|
705
718
|
return {
|
|
706
719
|
ok: false,
|
|
707
|
-
message: `skill_manage list
|
|
720
|
+
message: `skill_manage list:技能目录树扫描失败(${error instanceof Error ? error.message : String(error)})。`,
|
|
708
721
|
skills: []
|
|
709
722
|
};
|
|
710
723
|
}
|
|
@@ -733,7 +746,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
733
746
|
feedbackLines = feedback.lines;
|
|
734
747
|
if (settings().descriptionStrict && feedback.over60) return {
|
|
735
748
|
ok: false,
|
|
736
|
-
message:
|
|
749
|
+
message: `作者检查:description 为 ${feedback.descriptionChars}/60 个字符,超过严格上限;请压到 60 以内,或设置 descriptionStrict=false。`,
|
|
737
750
|
skills: []
|
|
738
751
|
};
|
|
739
752
|
}
|
|
@@ -754,7 +767,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
754
767
|
return raw === null || typeof raw !== "object";
|
|
755
768
|
})) result = {
|
|
756
769
|
ok: false,
|
|
757
|
-
message: "
|
|
770
|
+
message: "restructure 的每一项都必须是带 heading 与 to_file 的对象。"
|
|
758
771
|
};
|
|
759
772
|
else result = await library.restructure(name, moves.map((move) => ({
|
|
760
773
|
heading: typeof move.heading === "string" ? move.heading : "",
|
|
@@ -764,16 +777,16 @@ function apply(ctx, rawConfig = {}) {
|
|
|
764
777
|
else if (action === "unpin") result = await library.setPinned(name, false, origin);
|
|
765
778
|
else result = {
|
|
766
779
|
ok: false,
|
|
767
|
-
message:
|
|
780
|
+
message: `未知动作「${action}」。`
|
|
768
781
|
};
|
|
769
782
|
if (result.stale === true) return {
|
|
770
783
|
ok: false,
|
|
771
|
-
message: action === "write_file" || action === "remove_file" ?
|
|
784
|
+
message: action === "write_file" || action === "remove_file" ? `技能「${name}」的支撑文件「${args.file_path ?? ""}」在这次写入暂存之后发生了变化(或其状态无法验证)。` : `技能「${name}」在这次写入暂存之后发生了变化(内容${result.anchor === "missing" ? "已不存在" : "哈希不匹配"})。`,
|
|
772
785
|
skills: []
|
|
773
786
|
};
|
|
774
787
|
if (result.ok) {
|
|
775
788
|
if (result.normalizedFrontmatterFields && result.normalizedFrontmatterFields.length > 0) feedbackLines.push(`frontmatter auto-quoted (YAML compatibility): ${result.normalizedFrontmatterFields.join(", ")}`);
|
|
776
|
-
const mutating = action
|
|
789
|
+
const mutating = !isReadOnlyAction(action);
|
|
777
790
|
if (name && action === "create") await ctx.skillUsage.ensureRecordCreated(name, origin !== "foreground");
|
|
778
791
|
if (name && action === "delete") await ctx.skillUsage.markArchived(name);
|
|
779
792
|
else if (name && mutating && action !== "create" && result.noop !== true) await ctx.skillUsage.record(name, "patch");
|
|
@@ -937,7 +950,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
937
950
|
/** The approval seam this write would go through (T2-10/A25: the gate decision below reads it). */
|
|
938
951
|
const approvalSeam = ctx.get("evolutionApproval");
|
|
939
952
|
let crossSourceView = null;
|
|
940
|
-
if (typeof args.name === "string" && args.name !== "" && args.action
|
|
953
|
+
if (typeof args.name === "string" && args.name !== "" && !isReadOnlyAction(args.action)) {
|
|
941
954
|
const gate = await crossSourceRefusal(args.name);
|
|
942
955
|
if (gate.refusal !== null) return {
|
|
943
956
|
ok: false,
|
|
@@ -974,7 +987,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
974
987
|
skills: []
|
|
975
988
|
};
|
|
976
989
|
const approval = approvalSeam;
|
|
977
|
-
if (approval && args.action
|
|
990
|
+
if (approval && !isReadOnlyAction(args.action)) {
|
|
978
991
|
if ((args.action === "update" || args.action === "edit") && typeof args.name === "string" && args.name !== "") {
|
|
979
992
|
const stageCurrent = await library.read(args.name).catch(() => null);
|
|
980
993
|
operation = {
|
|
@@ -1019,10 +1032,10 @@ function apply(ctx, rawConfig = {}) {
|
|
|
1019
1032
|
const wrapped = args ?? {};
|
|
1020
1033
|
const operation = wrapped.operation ?? {};
|
|
1021
1034
|
const replayAction = operation.action;
|
|
1022
|
-
if (replayAction
|
|
1035
|
+
if (!isReadOnlyAction(replayAction)) return crossSourceRefusal(operation.name, "replay").then((gate) => {
|
|
1023
1036
|
if (gate.refusal !== null) return {
|
|
1024
1037
|
ok: false,
|
|
1025
|
-
message: `${gate.refusal}
|
|
1038
|
+
message: `${gate.refusal}(在批准时重新检查:该写入暂存期间目录排名发生了变化)`,
|
|
1026
1039
|
skills: []
|
|
1027
1040
|
};
|
|
1028
1041
|
return executeCore(operation, wrapped.libraryOrigin ?? wrapped.origin ?? "background_review", gate.view ?? void 0);
|
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.
|
|
4
|
+
"version": "0.24.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -27,24 +27,24 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@deepseek-ai/schemastery": "^3.18.4",
|
|
30
|
-
"@lmzhen/dsh-evolution-approval": "^0.
|
|
31
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
30
|
+
"@lmzhen/dsh-evolution-approval": "^0.24.0",
|
|
31
|
+
"@lmzhen/dsh-evolution-core": "^0.24.0"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
35
35
|
"@deepseek-ai/dsh-skill": "^0.2.0-rc.1",
|
|
36
36
|
"@deepseek-ai/dsh-system-prompt": "^0.2.0-rc.1",
|
|
37
37
|
"@deepseek-ai/dsh-tools": "^0.2.0-rc.1",
|
|
38
|
-
"@lmzhen/dsh-evolution-io": "^0.
|
|
39
|
-
"@lmzhen/dsh-skill-usage": "^0.
|
|
38
|
+
"@lmzhen/dsh-evolution-io": "^0.24.0",
|
|
39
|
+
"@lmzhen/dsh-skill-usage": "^0.24.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@deepseek-ai/dsh-agent-loop-testkit": "^0.2.0-rc.1",
|
|
43
43
|
"@deepseek-ai/dsh-skill": "^0.2.0-rc.1",
|
|
44
44
|
"@deepseek-ai/dsh-system-prompt": "^0.2.0-rc.1",
|
|
45
45
|
"@deepseek-ai/dsh-tools": "^0.2.0-rc.1",
|
|
46
|
-
"@lmzhen/dsh-evolution-core": "^0.
|
|
47
|
-
"@lmzhen/dsh-evolution-io": "^0.
|
|
48
|
-
"@lmzhen/dsh-skill-usage": "^0.
|
|
46
|
+
"@lmzhen/dsh-evolution-core": "^0.24.0",
|
|
47
|
+
"@lmzhen/dsh-evolution-io": "^0.24.0",
|
|
48
|
+
"@lmzhen/dsh-skill-usage": "^0.24.0"
|
|
49
49
|
}
|
|
50
50
|
}
|