@lmzhen/dsh-tool-skill-manage 0.25.9 → 0.26.26
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 +87 -242
- package/lib/types/write-gates.d.ts +6 -106
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -1,219 +1,37 @@
|
|
|
1
|
+
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, fuzzyPatch, isPresent, isUnknown, liveBool, nearDuplicateSummaries, newSkillLibrary, normalizeFrontmatter, paramRowId, parseFrontmatter, policyStageLimits, probePresent, probeUnknown, protectedSkillNamesOf, resolveExecOrigins, sessionReadSkillNames, skillWriteGateContext, unwrapLive, userSetKeys } from "@lmzhen/dsh-evolution-core";
|
|
1
2
|
import { effectiveSessionPolicy } from "@lmzhen/dsh-evolution-approval";
|
|
2
3
|
import z from "@deepseek-ai/schemastery";
|
|
3
4
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* Rule bodies live in `evolution-core` (the read-before-write rule in `skill-reads`, the
|
|
26
|
-
* required-argument table in `SKILL_ACTION_REQUIRED_FIELDS`); this module owns the ORDER and the
|
|
27
|
-
* applicability of each gate, which is an execution-point fact of this tool.
|
|
28
|
-
* @module @lmzhen/dsh-tool-skill-manage/write-gates
|
|
29
|
-
*/
|
|
30
|
-
/** The confirm question's stable id — one question per write, so an answer to an earlier prompt
|
|
31
|
-
* can never be read as the answer to a later one. */
|
|
32
|
-
const CONFIRM_QUESTION_ID = "evolution-skill-write";
|
|
33
|
-
/** The cancel label every confirm question offers. */
|
|
34
|
-
const CANCEL_LABEL = "取消";
|
|
35
|
-
/** What a `timeout`-mode deadline settles with: comparable by identity against the seam's
|
|
36
|
-
* boolean, so the two outcomes stay distinguishable without a mutable flag (which a linter
|
|
37
|
-
* cannot follow through a timer callback, and a reader cannot either). */
|
|
38
|
-
const CONFIRM_TIMED_OUT = "confirm-timed-out";
|
|
39
|
-
/** The mode a deployment that configures nothing gets. */
|
|
40
|
-
const DEFAULT_WRITE_CONFIRM_MODE = "auto";
|
|
41
|
-
/** A usable deadline: the configured value when it is a positive finite number, else the default. */
|
|
42
|
-
function timeoutSecondsOf(configured) {
|
|
43
|
-
return configured !== void 0 && Number.isFinite(configured) && configured >= 1 ? Math.floor(configured) : 120;
|
|
44
|
-
}
|
|
45
|
-
/** The scalar fields the tool schema types as strings; the replay channel has no schema.
|
|
46
|
-
* `action` is one of them: a non-string action used to fall through to the library as "Unknown
|
|
47
|
-
* action" while the read gate re-defaulted it to `patch` and refused with E-318 (review
|
|
48
|
-
* 2026-09-26, P2), so the shape gate refuses it by name instead. */
|
|
49
|
-
const SCALAR_ARG_FIELDS = [
|
|
50
|
-
"action",
|
|
51
|
-
"name",
|
|
52
|
-
"content",
|
|
53
|
-
"old_string",
|
|
54
|
-
"new_string",
|
|
55
|
-
"file_path",
|
|
56
|
-
"file_content",
|
|
57
|
-
"absorbed_into"
|
|
58
|
-
];
|
|
59
|
-
/** The scalar fields the tool schema types as BOOLEANS; the replay channel has no schema either.
|
|
60
|
-
* T2-V3/A28: `args.replace_all === true` answered "false" for anything else, so a staged
|
|
61
|
-
* `replace_all: 'yes'` silently patched only the FIRST occurrence — a wrong count with no signal.
|
|
62
|
-
* The plan channel already refuses a non-boolean `replace_all` by name (S1-C1); this is the same
|
|
63
|
-
* rule on the replay channel, so the two channels cannot disagree about one flag. */
|
|
64
|
-
const FLAG_ARG_FIELDS = ["replace_all"];
|
|
65
|
-
/**
|
|
66
|
-
* Narrow the arguments once for every gate.
|
|
67
|
-
*
|
|
68
|
-
* The admission point reaches the gates AFTER the schema, the replay channel BEFORE any
|
|
69
|
-
* validation, so a gate reads only what it can prove: anything else counts as absent, exactly as
|
|
70
|
-
* the missing-argument check already treated a non-string action.
|
|
71
|
-
* @param args - the arguments as the caller sent them.
|
|
72
|
-
* @returns the narrowed view.
|
|
73
|
-
*/
|
|
74
|
-
function gateArgsOf(args) {
|
|
75
|
-
const scalars = typeof args === "object" && args !== null ? args : {};
|
|
76
|
-
const action = scalars.action;
|
|
77
|
-
const name = scalars.name;
|
|
78
|
-
const absorbedInto = scalars.absorbed_into;
|
|
79
|
-
return {
|
|
80
|
-
action: typeof action === "string" ? action : void 0,
|
|
81
|
-
name: typeof name === "string" ? name : "",
|
|
82
|
-
absorbedInto: typeof absorbedInto === "string" && absorbedInto.trim() !== "" ? absorbedInto : void 0,
|
|
83
|
-
scalars
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/** The sequence, in order. A gate whose `appliesTo` omits the asking point is skipped. */
|
|
87
|
-
const GATES = [
|
|
88
|
-
{
|
|
89
|
-
id: "argument-shape",
|
|
90
|
-
appliesTo: ["admission", "execution"],
|
|
91
|
-
run: ({ view }) => {
|
|
92
|
-
for (const field of SCALAR_ARG_FIELDS) {
|
|
93
|
-
const value = view.scalars[field];
|
|
94
|
-
if (value === void 0 || value === null || typeof value === "string") continue;
|
|
95
|
-
return `skill_manage: "${field}" must be a string (got ${typeof value}); refusing the write.`;
|
|
96
|
-
}
|
|
97
|
-
for (const field of FLAG_ARG_FIELDS) {
|
|
98
|
-
const value = view.scalars[field];
|
|
99
|
-
if (value === void 0 || value === null || typeof value === "boolean") continue;
|
|
100
|
-
return `skill_manage: "${field}" must be a boolean (got ${typeof value}); refusing the write.`;
|
|
101
|
-
}
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
id: "missing-args",
|
|
107
|
-
appliesTo: ["admission", "execution"],
|
|
108
|
-
run: ({ view }) => {
|
|
109
|
-
const action = view.action;
|
|
110
|
-
const missing = (action === void 0 || !Object.hasOwn(SKILL_ACTION_REQUIRED_FIELDS, action) ? [] : SKILL_ACTION_REQUIRED_FIELDS[action] ?? []).filter((field) => view.scalars[field] === void 0 || view.scalars[field] === null);
|
|
111
|
-
if (missing.length === 0) return null;
|
|
112
|
-
return `skill_manage ${action} requires ${missing.join(", ")}; the tool description lists the arguments per action.`;
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
id: "policy-protection",
|
|
117
|
-
appliesTo: ["admission", "execution"],
|
|
118
|
-
run: ({ view, origin, protectedNames }) => {
|
|
119
|
-
if (origin === "foreground") return null;
|
|
120
|
-
if (view.name === "" || !protectedNames?.includes(view.name)) return null;
|
|
121
|
-
return `skill_manage: "${view.name}" is protected by the current policy (protectedSkillNames); replayed/autonomous writes are refused.`;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
id: "read-before-write",
|
|
126
|
-
appliesTo: ["admission"],
|
|
127
|
-
run: ({ view, origin, readNames, warn }) => {
|
|
128
|
-
if (origin === "foreground") return null;
|
|
129
|
-
if (readNames === void 0) {
|
|
130
|
-
warn("skill_manage: the read-before-write check could not run for this call — the session log is not readable here, so the write is allowed.");
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
if (view.action === void 0) return null;
|
|
134
|
-
if (!isUnreadWrite({
|
|
135
|
-
action: view.action,
|
|
136
|
-
name: view.name
|
|
137
|
-
}, readNames)) return null;
|
|
138
|
-
return errorText("e-318-skill-write-without-a-read", { a1: view.name });
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
id: "human-confirm",
|
|
143
|
-
appliesTo: ["admission"],
|
|
144
|
-
run: async ({ view, origin, confirm, warn, confirmMode, confirmTimeoutSeconds, describeTarget }) => {
|
|
145
|
-
const action = view.action;
|
|
146
|
-
if (action === void 0 || origin !== "foreground" || view.name === "") return null;
|
|
147
|
-
if (!(action === "create" || action === "delete" && view.absorbedInto === void 0)) return null;
|
|
148
|
-
const mode = confirmMode ?? "auto";
|
|
149
|
-
if (mode === "auto") return null;
|
|
150
|
-
if (confirm === void 0) {
|
|
151
|
-
warn("skill_manage: no confirmation channel is mounted, so the write proceeds unconfirmed.");
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
const confirmLabel = action === "create" ? "创建" : "删除";
|
|
155
|
-
const seconds = timeoutSecondsOf(confirmTimeoutSeconds);
|
|
156
|
-
const cancel = new AbortController();
|
|
157
|
-
let timer;
|
|
158
|
-
const deadline = mode === "timeout" ? new Promise((resolve) => {
|
|
159
|
-
timer = setTimeout(() => {
|
|
160
|
-
cancel.abort();
|
|
161
|
-
resolve(CONFIRM_TIMED_OUT);
|
|
162
|
-
}, seconds * 1e3);
|
|
163
|
-
timer.unref();
|
|
164
|
-
}) : void 0;
|
|
165
|
-
const context = await describeTarget?.();
|
|
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
|
-
const asked = confirm({
|
|
169
|
-
action,
|
|
170
|
-
name: view.name,
|
|
171
|
-
confirmLabel,
|
|
172
|
-
question: {
|
|
173
|
-
id: CONFIRM_QUESTION_ID,
|
|
174
|
-
header: "确认",
|
|
175
|
-
question: details.length === 0 ? consequence : consequence + " " + details.join(" · "),
|
|
176
|
-
options: [{ label: confirmLabel }, { label: CANCEL_LABEL }]
|
|
177
|
-
},
|
|
178
|
-
...mode === "timeout" ? { signal: cancel.signal } : {}
|
|
179
|
-
});
|
|
180
|
-
let outcome;
|
|
181
|
-
try {
|
|
182
|
-
outcome = deadline === void 0 ? await asked : await Promise.race([asked, deadline]);
|
|
183
|
-
} finally {
|
|
184
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
185
|
-
}
|
|
186
|
-
if (outcome === true) return null;
|
|
187
|
-
if (outcome === CONFIRM_TIMED_OUT || cancel.signal.aborted) return errorText("e-319-skill-write-confirm-timed-out", {
|
|
188
|
-
a1: view.name,
|
|
189
|
-
a2: action === "create" ? "创建" : "删除",
|
|
190
|
-
a3: String(seconds)
|
|
191
|
-
});
|
|
192
|
-
return errorText("e-317-skill-write-not-confirmed", {
|
|
193
|
-
a1: view.name,
|
|
194
|
-
a2: action === "create" ? "创建" : "删除"
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
];
|
|
199
|
-
/**
|
|
200
|
-
* Run the sequence for one write attempt.
|
|
201
|
-
* @param context - the asking point, the write, and the seams the human-facing gate needs.
|
|
202
|
-
* @returns the FIRST refusal, or null when every applicable gate passed. Both points return the
|
|
203
|
-
* message as the tool result unchanged, so the two entries refuse with identical wording.
|
|
204
|
-
*/
|
|
205
|
-
async function runWriteGates(context) {
|
|
206
|
-
const input = {
|
|
207
|
-
...context,
|
|
208
|
-
view: gateArgsOf(context.args)
|
|
209
|
-
};
|
|
210
|
-
for (const gate of GATES) {
|
|
211
|
-
if (!gate.appliesTo.includes(context.point)) continue;
|
|
212
|
-
const refusal = await gate.run(input);
|
|
213
|
-
if (refusal !== null) return refusal;
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __exportAll = (all, no_symbols) => {
|
|
11
|
+
let target = {};
|
|
12
|
+
for (var name in all) __defProp(target, name, {
|
|
13
|
+
get: all[name],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
21
|
+
key = keys[i];
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
+
get: ((k) => from[k]).bind(null, key),
|
|
24
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
+
});
|
|
214
26
|
}
|
|
215
|
-
return
|
|
216
|
-
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region lib/types/write-gates.js
|
|
32
|
+
var write_gates_exports = /* @__PURE__ */ __exportAll({});
|
|
33
|
+
import * as import__deepseek_ai_dsh_evolution_core from "@lmzhen/dsh-evolution-core";
|
|
34
|
+
__reExport(write_gates_exports, import__deepseek_ai_dsh_evolution_core);
|
|
217
35
|
//#endregion
|
|
218
36
|
//#region lib/types/index.js
|
|
219
37
|
/**
|
|
@@ -284,8 +102,8 @@ const Config = z.object({
|
|
|
284
102
|
z.const("auto"),
|
|
285
103
|
z.const("ask"),
|
|
286
104
|
z.const("timeout")
|
|
287
|
-
]).default(DEFAULT_WRITE_CONFIRM_MODE).volatile(),
|
|
288
|
-
skillWriteConfirmTimeoutSeconds: z.number().min(1).default(
|
|
105
|
+
]).default(write_gates_exports.DEFAULT_WRITE_CONFIRM_MODE).volatile(),
|
|
106
|
+
skillWriteConfirmTimeoutSeconds: z.number().min(1).default(write_gates_exports.DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS).volatile()
|
|
289
107
|
});
|
|
290
108
|
/** The four caps a user may only tighten, in schema order (the sentry reads it). */
|
|
291
109
|
const SKILL_SETTINGS_CAPS = [
|
|
@@ -332,7 +150,12 @@ async function previewSkillWrite(library, args) {
|
|
|
332
150
|
};
|
|
333
151
|
const filePath = typeof operation.file_path === "string" && operation.file_path !== "" ? operation.file_path : null;
|
|
334
152
|
const path = filePath ?? "SKILL.md";
|
|
335
|
-
const
|
|
153
|
+
const probe = filePath === null ? await library.readSkillProbe(name) : await library.readSupportFileProbe(name, filePath);
|
|
154
|
+
if (isUnknown(probe)) return {
|
|
155
|
+
available: false,
|
|
156
|
+
reason: "目标当前读不到(" + probe.reason + "),无法核验暂存锚点 —— 先修好可读性再批准"
|
|
157
|
+
};
|
|
158
|
+
const before = isPresent(probe) ? probe.value : null;
|
|
336
159
|
const staged = operation.staged_from_sha256;
|
|
337
160
|
if (anchorVerdict(typeof staged === "string" && staged !== "" ? staged === "absent" ? { absent: true } : { sha256: staged } : void 0, before) !== "match") return {
|
|
338
161
|
available: false,
|
|
@@ -454,12 +277,6 @@ function liveRootAgentOf(probe, exec) {
|
|
|
454
277
|
function confirmedBy(answer, questionId, confirmLabel) {
|
|
455
278
|
return (answer.answers.find((entry) => entry.id === questionId)?.selected ?? []).includes(confirmLabel);
|
|
456
279
|
}
|
|
457
|
-
/** v30 REV-02: read the protected-skill list off the (optional) policy
|
|
458
|
-
* snapshot through an `unknown` boundary — the Context augmentation types the
|
|
459
|
-
* getter non-optionally, but at runtime the row can be absent. */
|
|
460
|
-
function policySnapshotOf(source) {
|
|
461
|
-
return source?.get?.();
|
|
462
|
-
}
|
|
463
280
|
function apply(ctx, rawConfig = {}) {
|
|
464
281
|
ctx.inject(["settings"], (injected) => {
|
|
465
282
|
const settings = injected.settings;
|
|
@@ -482,7 +299,6 @@ function apply(ctx, rawConfig = {}) {
|
|
|
482
299
|
}, "tool-skill-manage.skills-guidance");
|
|
483
300
|
/** The policy snapshot's protected list, or `undefined` when the row is not mounted — read by
|
|
484
301
|
* the write gates at BOTH points, through the one unknown-boundary helper above. */
|
|
485
|
-
const protectedSkillNamesOf = () => policySnapshotOf(ctx.get("evolutionPolicy"))?.protectedSkillNames;
|
|
486
302
|
/**
|
|
487
303
|
* The protected-skill line appended to the skills guidance (B4, design §4.3).
|
|
488
304
|
*
|
|
@@ -495,7 +311,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
495
311
|
*/
|
|
496
312
|
const protectedSkillsLine = () => {
|
|
497
313
|
try {
|
|
498
|
-
const names = protectedSkillNamesOf() ?? [];
|
|
314
|
+
const names = protectedSkillNamesOf(ctx.get("evolutionPolicy")) ?? [];
|
|
499
315
|
if (names.length === 0) return "";
|
|
500
316
|
const shown = names.slice(0, PROTECTED_SKILLS_INLINE_MAX);
|
|
501
317
|
const rest = names.length - shown.length;
|
|
@@ -569,8 +385,8 @@ function apply(ctx, rawConfig = {}) {
|
|
|
569
385
|
strictCrossSource: liveBool(rawConfig.strictCrossSource),
|
|
570
386
|
citationPolicy: unwrapLive(rawConfig.citationPolicy) ?? DEFAULT_CITATION_POLICY,
|
|
571
387
|
supportFileCharPolicy: unwrapLive(rawConfig.supportFileCharPolicy) ?? DEFAULT_SUPPORT_FILE_CHAR_POLICY,
|
|
572
|
-
skillWriteConfirm: unwrapLive(rawConfig.skillWriteConfirm) ??
|
|
573
|
-
skillWriteConfirmTimeoutSeconds: limit("skillWriteConfirmTimeoutSeconds", rawConfig.skillWriteConfirmTimeoutSeconds,
|
|
388
|
+
skillWriteConfirm: unwrapLive(rawConfig.skillWriteConfirm) ?? write_gates_exports.DEFAULT_WRITE_CONFIRM_MODE,
|
|
389
|
+
skillWriteConfirmTimeoutSeconds: limit("skillWriteConfirmTimeoutSeconds", rawConfig.skillWriteConfirmTimeoutSeconds, write_gates_exports.DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS)
|
|
574
390
|
});
|
|
575
391
|
/**
|
|
576
392
|
* G3/S3.4 + G1: the USER layer sits above the deployment carriers. `settings()` is
|
|
@@ -582,7 +398,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
582
398
|
*/
|
|
583
399
|
const settings = () => {
|
|
584
400
|
const row = rowSettings();
|
|
585
|
-
const stages = policyStageLimits(
|
|
401
|
+
const stages = policyStageLimits(ctx.get("evolutionPolicy")?.get?.());
|
|
586
402
|
const userSet = userSetKeys(ctx, paramRowId("tool-skill-manage"));
|
|
587
403
|
return {
|
|
588
404
|
...row,
|
|
@@ -601,6 +417,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
601
417
|
versionKeep: limit("skillVersionKeep", rawConfig.skillVersionKeep, DEFAULT_SKILL_LIMITS.versionKeep ?? DEFAULT_SKILL_VERSION_KEEP)
|
|
602
418
|
};
|
|
603
419
|
const library = newSkillLibrary({
|
|
420
|
+
authority: authorityFrom({ origin: "foreground" }),
|
|
604
421
|
config: rawConfig,
|
|
605
422
|
io,
|
|
606
423
|
limits: libraryLimits,
|
|
@@ -610,7 +427,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
610
427
|
/** Write the CURRENT resolved settings into the library's live limits object. */
|
|
611
428
|
const applyLimits = () => {
|
|
612
429
|
const resolved = settings();
|
|
613
|
-
const stages = policyStageLimits(
|
|
430
|
+
const stages = policyStageLimits(ctx.get("evolutionPolicy")?.get?.());
|
|
614
431
|
Object.assign(libraryLimits, {
|
|
615
432
|
maxNameLength: resolved.maxSkillNameLength,
|
|
616
433
|
maxDescriptionLength: resolved.maxDescriptionLength,
|
|
@@ -721,15 +538,16 @@ function apply(ctx, rawConfig = {}) {
|
|
|
721
538
|
skills: []
|
|
722
539
|
};
|
|
723
540
|
}
|
|
724
|
-
const refusal = await runWriteGates({
|
|
725
|
-
|
|
726
|
-
args,
|
|
727
|
-
origin,
|
|
728
|
-
protectedNames: protectedSkillNamesOf(),
|
|
729
|
-
readNames: void 0,
|
|
541
|
+
const refusal = await (0, write_gates_exports.runWriteGates)(skillWriteGateContext({
|
|
542
|
+
policy: ctx.get("evolutionPolicy"),
|
|
730
543
|
confirm: void 0,
|
|
544
|
+
readNames: void 0,
|
|
731
545
|
warn: warnWriteGateOnce
|
|
732
|
-
}
|
|
546
|
+
}, {
|
|
547
|
+
point: "execution",
|
|
548
|
+
args,
|
|
549
|
+
origin
|
|
550
|
+
}));
|
|
733
551
|
if (refusal !== null) return {
|
|
734
552
|
ok: false,
|
|
735
553
|
message: refusal,
|
|
@@ -847,9 +665,15 @@ function apply(ctx, rawConfig = {}) {
|
|
|
847
665
|
});
|
|
848
666
|
const contents = /* @__PURE__ */ new Map();
|
|
849
667
|
let excludedBodies = 0;
|
|
668
|
+
let unreadableBodies = 0;
|
|
850
669
|
for (let offset = 0; offset < list.length; offset += 16) await Promise.all(list.slice(offset, offset + 16).map(async (summary) => {
|
|
851
|
-
const
|
|
852
|
-
if (
|
|
670
|
+
const probe = await library.readSkillProbe(summary.name);
|
|
671
|
+
if (isUnknown(probe)) {
|
|
672
|
+
unreadableBodies += 1;
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
const body = isPresent(probe) ? probe.value : "";
|
|
676
|
+
if (body.trim() === "") {
|
|
853
677
|
excludedBodies += 1;
|
|
854
678
|
return;
|
|
855
679
|
}
|
|
@@ -859,7 +683,8 @@ function apply(ctx, rawConfig = {}) {
|
|
|
859
683
|
const groups = dedup.groups;
|
|
860
684
|
const dedupLines = groups.slice(0, MAX_DEDUP_GROUPS_IN_REVIEW).map((group) => `- ${group.join(" ~ ")}`);
|
|
861
685
|
if (dedup.truncated) dedupLines.push(`- note: dedup scan truncated at the pair-comparison budget (${groups.length} group(s) so far); groups may be incomplete`);
|
|
862
|
-
const excludedLine = excludedBodies === 0 ? "" : `\n${excludedBodies} skill bodies were
|
|
686
|
+
const excludedLine = excludedBodies === 0 ? "" : `\n${excludedBodies} skill bodies were empty and excluded from dedup grouping.`;
|
|
687
|
+
const unreadableLine = unreadableBodies === 0 ? "" : `\n${unreadableBodies} skills could not be read and were skipped in dedup grouping - fix readability and re-run the review.`;
|
|
863
688
|
const warned = list.filter((summary) => warnedFlag(summary.name)).map((summary) => summary.name);
|
|
864
689
|
const warningLine = warned.length === 0 ? "" : `\nWarning skills (${warned.length}): ${warned.join(", ")} — low quality; consider consolidating them before authoring new skills.`;
|
|
865
690
|
return [
|
|
@@ -868,6 +693,7 @@ function apply(ctx, rawConfig = {}) {
|
|
|
868
693
|
...lines,
|
|
869
694
|
...dedupLines,
|
|
870
695
|
...excludedBodies > 0 ? [excludedLine] : [],
|
|
696
|
+
...unreadableBodies > 0 ? [unreadableLine] : [],
|
|
871
697
|
warningLine
|
|
872
698
|
].join("\n");
|
|
873
699
|
}
|
|
@@ -959,18 +785,21 @@ function apply(ctx, rawConfig = {}) {
|
|
|
959
785
|
};
|
|
960
786
|
crossSourceView = gate.view;
|
|
961
787
|
}
|
|
962
|
-
const refusal = await runWriteGates({
|
|
788
|
+
const refusal = await (0, write_gates_exports.runWriteGates)({
|
|
963
789
|
point: "admission",
|
|
964
790
|
args,
|
|
965
791
|
origin: libraryOrigin,
|
|
966
|
-
protectedNames: protectedSkillNamesOf(),
|
|
792
|
+
protectedNames: protectedSkillNamesOf(ctx.get("evolutionPolicy")),
|
|
967
793
|
readNames: sessionReadSkillNames(ctx, exec.agent?.session),
|
|
968
794
|
confirm: async (request) => confirmSkillWrite(request, exec),
|
|
969
795
|
confirmMode: approvalSeam !== void 0 && approvalSeam.isEnabled !== false && sessionPolicy !== "never" && (libraryOrigin === "background_review" || approvalSeam.stageForeground !== false) ? "auto" : settings().skillWriteConfirm,
|
|
970
796
|
confirmTimeoutSeconds: settings().skillWriteConfirmTimeoutSeconds,
|
|
971
797
|
describeTarget: async () => {
|
|
972
798
|
const versions = typeof args.name === "string" && args.name !== "" ? (await library.listVersions(args.name).catch(() => [])).length : 0;
|
|
973
|
-
const body = typeof args.content === "string" && args.content !== "" ? args.content : typeof args.name === "string" && args.name !== "" ? await
|
|
799
|
+
const body = typeof args.content === "string" && args.content !== "" ? args.content : typeof args.name === "string" && args.name !== "" ? await (async () => {
|
|
800
|
+
const p = await library.readSkillProbe(String(args.name));
|
|
801
|
+
return isPresent(p) ? p.value : null;
|
|
802
|
+
})() : null;
|
|
974
803
|
const frontmatter = body === null ? null : parseFrontmatter(body)?.frontmatter ?? null;
|
|
975
804
|
const parsedDescription = frontmatter === null ? void 0 : frontmatter.description;
|
|
976
805
|
const description = typeof parsedDescription === "string" ? parsedDescription : "";
|
|
@@ -989,14 +818,30 @@ function apply(ctx, rawConfig = {}) {
|
|
|
989
818
|
const approval = approvalSeam;
|
|
990
819
|
if (approval && !isReadOnlyAction(args.action)) {
|
|
991
820
|
if ((args.action === "update" || args.action === "edit") && typeof args.name === "string" && args.name !== "") {
|
|
992
|
-
|
|
821
|
+
let stageCurrent;
|
|
822
|
+
try {
|
|
823
|
+
stageCurrent = await library.read(args.name);
|
|
824
|
+
} catch (error) {
|
|
825
|
+
const rawCode = error?.code;
|
|
826
|
+
return {
|
|
827
|
+
ok: false,
|
|
828
|
+
message: "目标当前读不到(" + (typeof rawCode === "string" ? rawCode : "IO 失败") + "),无法核验暂存锚点 —— 先修好可读性再批准",
|
|
829
|
+
skills: []
|
|
830
|
+
};
|
|
831
|
+
}
|
|
993
832
|
operation = {
|
|
994
833
|
...args,
|
|
995
834
|
staged_from_sha256: stageCurrent === null ? "absent" : contentHash(stageCurrent)
|
|
996
835
|
};
|
|
997
836
|
}
|
|
998
837
|
if ((args.action === "write_file" || args.action === "remove_file") && typeof args.name === "string" && args.name !== "" && typeof args.file_path === "string" && args.file_path !== "") {
|
|
999
|
-
const
|
|
838
|
+
const supportProbe = await library.readSupportFileProbe(args.name, args.file_path);
|
|
839
|
+
if (isUnknown(supportProbe)) return {
|
|
840
|
+
ok: false,
|
|
841
|
+
message: "目标当前读不到(" + supportProbe.reason + "),无法核验暂存锚点 —— 先修好可读性再批准",
|
|
842
|
+
skills: []
|
|
843
|
+
};
|
|
844
|
+
const stageFile = isPresent(supportProbe) ? supportProbe.value : null;
|
|
1000
845
|
operation = {
|
|
1001
846
|
...args,
|
|
1002
847
|
staged_from_sha256: stageFile === null ? "absent" : contentHash(stageFile)
|
|
@@ -1,112 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* G1/1.2: the write-admission sequence moved to its nouns' home.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* replay) runs the gates that apply to `'execution'`: the stored plan of a replayed write passed
|
|
9
|
-
* no schema, and the protected list can change while a record sits pending, so those verdicts are
|
|
10
|
-
* re-decided at the bytes.
|
|
4
|
+
* The gate table used to be package-private to this tool, so every other write entry point - the graph
|
|
5
|
+
* commands above all - either bypassed it or copied its semantics (audit: approval mirrors the confirm
|
|
6
|
+
* vocabulary "mirrored, not imported"). It now lives in evolution-core next to `write-authority.ts`, and
|
|
7
|
+
* this file re-exports it unchanged so nothing importing from here has to move.
|
|
11
8
|
*
|
|
12
|
-
* Order is part of the contract: a gate that can only refuse comes before one that needs a round
|
|
13
|
-
* trip with the operator, so a write that is refused anyway never asks anything.
|
|
14
|
-
*
|
|
15
|
-
* A gate decides whether a write may be ATTEMPTED. The library decides whether it can be
|
|
16
|
-
* PERFORMED — its own structured refusals (a restructure element that is not an object, a patch
|
|
17
|
-
* anchor that no longer matches, an `absorbed_into` that does not exist) stay where the bytes are
|
|
18
|
-
* read.
|
|
19
|
-
*
|
|
20
|
-
* Rule bodies live in `evolution-core` (the read-before-write rule in `skill-reads`, the
|
|
21
|
-
* required-argument table in `SKILL_ACTION_REQUIRED_FIELDS`); this module owns the ORDER and the
|
|
22
|
-
* applicability of each gate, which is an execution-point fact of this tool.
|
|
23
9
|
* @module @lmzhen/dsh-tool-skill-manage/write-gates
|
|
24
10
|
*/
|
|
25
|
-
|
|
26
|
-
/** The point whose verdict is being taken. */
|
|
27
|
-
export type WriteGatePoint = 'admission' | 'execution';
|
|
28
|
-
/**
|
|
29
|
-
* How the ONE confirmation behaves (registry `skillWriteConfirm`).
|
|
30
|
-
*
|
|
31
|
-
* `auto` writes without asking — the default, because an unattended run (a background pass, a
|
|
32
|
-
* scheduled review, a headless session) must not park a tool call on a question nobody will answer.
|
|
33
|
-
* `ask` waits for as long as it takes, which is the deployment that wants the gate in the loop.
|
|
34
|
-
* `timeout` asks and cancels the write on its own deadline.
|
|
35
|
-
*/
|
|
36
|
-
export type WriteConfirmMode = 'auto' | 'ask' | 'timeout';
|
|
37
|
-
/** The mode a deployment that configures nothing gets. */
|
|
38
|
-
export declare const DEFAULT_WRITE_CONFIRM_MODE: WriteConfirmMode;
|
|
39
|
-
/** Seconds a `timeout`-mode prompt waits before the write is cancelled. */
|
|
40
|
-
export declare const DEFAULT_WRITE_CONFIRM_TIMEOUT_SECONDS = 120;
|
|
41
|
-
/** What the operator is told about the target before answering. Every field is optional: a target
|
|
42
|
-
* with no frontmatter, or one the library cannot read, simply carries less. */
|
|
43
|
-
export interface ConfirmContext {
|
|
44
|
-
readonly description?: string | undefined;
|
|
45
|
-
readonly versions?: number | undefined;
|
|
46
|
-
}
|
|
47
|
-
/** One confirm question, as the gate writes it and the seam asks it. */
|
|
48
|
-
export interface WriteConfirmRequest {
|
|
49
|
-
/** The action being confirmed (`create` or `delete`). */
|
|
50
|
-
readonly action: string;
|
|
51
|
-
/** The skill the write would create or archive. */
|
|
52
|
-
readonly name: string;
|
|
53
|
-
/** The question for the operator: the options are the confirm label, then the cancel label. */
|
|
54
|
-
readonly question: {
|
|
55
|
-
readonly id: string;
|
|
56
|
-
readonly header: string;
|
|
57
|
-
readonly question: string;
|
|
58
|
-
readonly options: readonly {
|
|
59
|
-
readonly label: string;
|
|
60
|
-
}[];
|
|
61
|
-
};
|
|
62
|
-
/** The option label that means "proceed". */
|
|
63
|
-
readonly confirmLabel: string;
|
|
64
|
-
/** A deadline the gate imposes on itself (`timeout` mode); the seam combines it with the call's
|
|
65
|
-
* own cancellation. An abort is a dismissal, never a consent. */
|
|
66
|
-
readonly signal?: AbortSignal;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Ask the human to confirm one irreversible skill write.
|
|
70
|
-
*
|
|
71
|
-
* MUST be total: an implementation resolves every unavailability — no question service, no live root
|
|
72
|
-
* agent, a failing ask — to `true`, because this gate is an operator convenience and no failure of the
|
|
73
|
-
* question service may block the operator's own write. `false` means the human answered something
|
|
74
|
-
* other than the confirm label.
|
|
75
|
-
* @param request - the question to put to the operator and the label that means "proceed".
|
|
76
|
-
* @returns true to proceed with the write.
|
|
77
|
-
*/
|
|
78
|
-
export type WriteConfirm = (request: WriteConfirmRequest) => Promise<boolean>;
|
|
79
|
-
/** What every gate reads. */
|
|
80
|
-
export interface WriteGateContext {
|
|
81
|
-
/** The point asking: the tool's admission of a call, or its execution at the bytes. */
|
|
82
|
-
readonly point: WriteGatePoint;
|
|
83
|
-
/** The parsed (admission) or stored (replay) arguments — unvalidated, hence the shape gate. */
|
|
84
|
-
readonly args: unknown;
|
|
85
|
-
/** The library write origin: `foreground` is the operator's own session. */
|
|
86
|
-
readonly origin: WriteOrigin;
|
|
87
|
-
/** The policy snapshot's protected list; `undefined` when no policy row is mounted. */
|
|
88
|
-
readonly protectedNames: readonly string[] | undefined;
|
|
89
|
-
/** Names this session read successfully; `undefined` when the session log is not readable. */
|
|
90
|
-
readonly readNames: ReadonlySet<string> | undefined;
|
|
91
|
-
/** The human confirm seam — read only by the gates that apply to `'admission'`. */
|
|
92
|
-
readonly confirm: WriteConfirm | undefined;
|
|
93
|
-
/** The registry's `skillWriteConfirm`: `auto` (the default) skips the question entirely. */
|
|
94
|
-
readonly confirmMode?: WriteConfirmMode;
|
|
95
|
-
/** The registry's `skillWriteConfirmTimeoutSeconds`, read only in `timeout` mode. */
|
|
96
|
-
readonly confirmTimeoutSeconds?: number;
|
|
97
|
-
/** Read the target's own words for the confirmation card. LAZY on purpose: a write that is not
|
|
98
|
-
* asked about must not pay a read for a question nobody sees. Absent means "say nothing extra". */
|
|
99
|
-
readonly describeTarget?: (() => Promise<ConfirmContext | undefined>) | undefined;
|
|
100
|
-
/** Report a degraded gate; must not throw. The implementation decides how often it speaks — the
|
|
101
|
-
* shipped seam latches once per PROCESS, because the conditions it reports (no question service,
|
|
102
|
-
* an unreadable session log) belong to the deployment, not to one write. */
|
|
103
|
-
readonly warn: (message: string) => void;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Run the sequence for one write attempt.
|
|
107
|
-
* @param context - the asking point, the write, and the seams the human-facing gate needs.
|
|
108
|
-
* @returns the FIRST refusal, or null when every applicable gate passed. Both points return the
|
|
109
|
-
* message as the tool result unchanged, so the two entries refuse with identical wording.
|
|
110
|
-
*/
|
|
111
|
-
export declare function runWriteGates(context: WriteGateContext): Promise<string | null>;
|
|
11
|
+
export * from '@lmzhen/dsh-evolution-core';
|
|
112
12
|
//# sourceMappingURL=write-gates.d.ts.map
|
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.26.26",
|
|
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.26.26",
|
|
31
|
+
"@lmzhen/dsh-evolution-core": "^0.26.26"
|
|
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.26.26",
|
|
39
|
+
"@lmzhen/dsh-skill-usage": "^0.26.26"
|
|
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.26.26",
|
|
47
|
+
"@lmzhen/dsh-evolution-io": "^0.26.26",
|
|
48
|
+
"@lmzhen/dsh-skill-usage": "^0.26.26"
|
|
49
49
|
}
|
|
50
50
|
}
|