skill-evolution 0.0.0-stage → 0.1.1
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/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.en.md +244 -0
- package/README.md +243 -2
- package/assets/icon-180.png +0 -0
- package/assets/screenshots/workbench.png +0 -0
- package/client.js +2136 -0
- package/cordis.patch.yml +42 -0
- package/icon.svg +6 -0
- package/index.js +898 -0
- package/lib/applier.js +221 -0
- package/lib/collector.js +356 -0
- package/lib/consolidation.js +344 -0
- package/lib/gatekeeper.js +293 -0
- package/lib/http-api.js +974 -0
- package/lib/ledger.js +316 -0
- package/lib/prompts.js +514 -0
- package/lib/provenance.js +103 -0
- package/lib/reflector.js +226 -0
- package/lib/synthesizer.js +295 -0
- package/lib/tidy.js +263 -0
- package/lib/usage.js +223 -0
- package/locale/en.json +8 -0
- package/locale/zh.json +8 -0
- package/package.json +88 -4
- package/screenshots.json +3 -0
package/lib/tidy.js
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 整理器(Tidy)
|
|
3
|
+
*
|
|
4
|
+
* 解决「待审草稿堆积到看不过来」的问题。核心判断:
|
|
5
|
+
*
|
|
6
|
+
* 审阅疲劳的根因不是"草稿多",而是"把每份草稿都当成同等重要的独立决策平铺展示"。
|
|
7
|
+
* 真正需要人做判断的只有两类:① 跨领域的新增(要不要这门手艺)
|
|
8
|
+
* ② 同域多份的合并方式。其余都是低风险机械动作。
|
|
9
|
+
*
|
|
10
|
+
* 因此按风险从低到高分三档,只有第三档需要人看:
|
|
11
|
+
* Tier 0 · 清理损坏草稿 —— 零风险,直接移入 .archive/corrupt-*
|
|
12
|
+
* Tier 1 · 采纳同名/同类补丁 —— 低风险,有 SHA-256 账本可一键回滚
|
|
13
|
+
* Tier 2 · 同域多份待合并 —— 需要 LLM 蒸馏,交给人确认后走 consolidate
|
|
14
|
+
*
|
|
15
|
+
* 本模块只做"分组与判定",不做 LLM 调用(那是 consolidation.js 的事)。
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import fs from "node:fs/promises";
|
|
19
|
+
import fsSync from "node:fs";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
|
|
22
|
+
import { listSkills, listDrafts, promoteDraft, STAGING_DIRNAME } from "./applier.js";
|
|
23
|
+
|
|
24
|
+
/** 主题域关键词表:命中越多越可能属于同一把伞。 */
|
|
25
|
+
const THEMES = [
|
|
26
|
+
{ id: "dsh-plugin", label: "DSH / 插件工程", kw: ["dsh", "plugin", "cordis", "bundle", "patch", "slot", "vendored", "sri", "source-refactor"] },
|
|
27
|
+
{ id: "macos-app", label: "macOS 应用与配置", kw: ["macos", "app", "plist", "rosetta", "codesign", "third-party", "config-surgery", "install"] },
|
|
28
|
+
{ id: "game", label: "游戏与游戏 AI", kw: ["game", "rts", "gameplay", "telemetry", "asset", "map", "mod", "客户端"] },
|
|
29
|
+
{ id: "network", label: "网络与设备", kw: ["network", "nat", "tunnel", "device", "connection", "ssh", "dns", "port"] },
|
|
30
|
+
{ id: "system", label: "系统资源", kw: ["cpu", "disk", "thermal", "memory", "space", "reclaim", "resource"] },
|
|
31
|
+
{ id: "migration", label: "部署与迁移", kw: ["migrat", "deploy", "cutover", "release", "docker", "container", "service"] },
|
|
32
|
+
{ id: "agent", label: "Agent 协作", kw: ["subagent", "agent", "review", "orchestrat", "team"] },
|
|
33
|
+
{ id: "visual", label: "视觉产物验收", kw: ["visual", "render", "ui", "screenshot", "style"] },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/** 命中主题:返回该技能最可能的主题域(取命中关键词最多的一个)。 */
|
|
37
|
+
function themeOf(name, description = "") {
|
|
38
|
+
const hay = `${name} ${description}`.toLowerCase();
|
|
39
|
+
let best = null;
|
|
40
|
+
let bestScore = 0;
|
|
41
|
+
for (const t of THEMES) {
|
|
42
|
+
let score = 0;
|
|
43
|
+
for (const k of t.kw) if (hay.includes(k)) score += 1;
|
|
44
|
+
if (score > bestScore) {
|
|
45
|
+
best = t;
|
|
46
|
+
bestScore = score;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return bestScore > 0 ? best : { id: "other", label: "其它", kw: [] };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 轻量相似度:技能名字词集合的 Jaccard(只用名字,避免正文噪音)。 */
|
|
53
|
+
export function nameSimilarity(a, b) {
|
|
54
|
+
const tok = (s) => new Set(String(s).toLowerCase().split(/[-_.\s]+/).filter((x) => x.length > 2));
|
|
55
|
+
const A = tok(a);
|
|
56
|
+
const B = tok(b);
|
|
57
|
+
if (!A.size || !B.size) return 0;
|
|
58
|
+
let inter = 0;
|
|
59
|
+
for (const x of A) if (B.has(x)) inter += 1;
|
|
60
|
+
return inter / (A.size + B.size - inter);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 找草稿最可能归属的现有技能(同名优先,其次名字相似度)。 */
|
|
64
|
+
function findAnchor(draft, existingSkills) {
|
|
65
|
+
const same = existingSkills.find((s) => s.name === draft.name);
|
|
66
|
+
if (same) return { skill: same, similarity: 1, reason: "同名技能" };
|
|
67
|
+
|
|
68
|
+
let best = null;
|
|
69
|
+
for (const s of existingSkills) {
|
|
70
|
+
const sim = nameSimilarity(draft.name, s.name);
|
|
71
|
+
if (!best || sim > best.similarity) best = { skill: s, similarity: sim };
|
|
72
|
+
}
|
|
73
|
+
if (best && best.similarity >= 0.34) {
|
|
74
|
+
return { ...best, reason: `名字高度相似 (${best.similarity.toFixed(2)})` };
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 生成整理计划(只读,不改任何文件)。
|
|
81
|
+
*
|
|
82
|
+
* @param {string} skillsRoot
|
|
83
|
+
* @returns {Promise<object>} 计划
|
|
84
|
+
*/
|
|
85
|
+
export async function planTidy(skillsRoot) {
|
|
86
|
+
const stagingPath = path.join(skillsRoot, STAGING_DIRNAME);
|
|
87
|
+
const skills = await listSkills(skillsRoot);
|
|
88
|
+
const drafts = await listDrafts(skillsRoot);
|
|
89
|
+
|
|
90
|
+
const corrupt = [];
|
|
91
|
+
const autoPromote = [];
|
|
92
|
+
const candidates = [];
|
|
93
|
+
|
|
94
|
+
// ---- Tier 0:找出损坏草稿(目录存在但没有可用的 SKILL.md)----
|
|
95
|
+
let dirNames = [];
|
|
96
|
+
try {
|
|
97
|
+
dirNames = (await fs.readdir(stagingPath, { withFileTypes: true }))
|
|
98
|
+
.filter((d) => d.isDirectory() && !d.name.startsWith("."))
|
|
99
|
+
.map((d) => d.name);
|
|
100
|
+
} catch {
|
|
101
|
+
dirNames = [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---- Tier 1 / 2:逐份草稿判定 ----
|
|
105
|
+
for (const d of drafts) {
|
|
106
|
+
const dir = d.path ?? path.join(stagingPath, d.name);
|
|
107
|
+
// listDrafts 只给 name/description/path,正文要自己读
|
|
108
|
+
let body = "";
|
|
109
|
+
let hasSkillMd = true;
|
|
110
|
+
try {
|
|
111
|
+
body = await fs.readFile(path.join(dir, "SKILL.md"), "utf8");
|
|
112
|
+
} catch {
|
|
113
|
+
hasSkillMd = false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 缺 SKILL.md → 损坏草稿(listDrafts 也会列出它,所以必须在这里拦)
|
|
117
|
+
if (!hasSkillMd) {
|
|
118
|
+
const files = await fs.readdir(dir).catch(() => []);
|
|
119
|
+
corrupt.push({
|
|
120
|
+
name: d.name,
|
|
121
|
+
reason: files.length ? `缺少 SKILL.md(仅剩 ${files.join(", ")})` : "空目录",
|
|
122
|
+
});
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const desc = String(d.description ?? "");
|
|
127
|
+
const theme = themeOf(d.name, desc);
|
|
128
|
+
const anchor = findAnchor(d, skills);
|
|
129
|
+
|
|
130
|
+
// 内容过短 → 没有沉淀价值
|
|
131
|
+
if (body.trim().length < 200) {
|
|
132
|
+
candidates.push({
|
|
133
|
+
name: d.name,
|
|
134
|
+
theme,
|
|
135
|
+
tier: "drop",
|
|
136
|
+
reason: `正文过短 (${body.trim().length} 字符),不足以形成可复用规程`,
|
|
137
|
+
});
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 同名 / 高度相似 → 直接采纳为现有技能的升级(低风险,可回滚)
|
|
142
|
+
if (anchor && anchor.similarity >= 0.34) {
|
|
143
|
+
candidates.push({
|
|
144
|
+
name: d.name,
|
|
145
|
+
theme,
|
|
146
|
+
tier: "auto",
|
|
147
|
+
anchor: anchor.skill.name,
|
|
148
|
+
reason: `${anchor.reason} → 升级现有技能「${anchor.skill.name}」`,
|
|
149
|
+
});
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
candidates.push({ name: d.name, theme, tier: "review", anchor: null, reason: "跨领域新增,需要你确认是否收下" });
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// ---- 同域多份 → 组成待合并组 ----
|
|
157
|
+
const byTheme = new Map();
|
|
158
|
+
for (const c of candidates) {
|
|
159
|
+
if (c.tier !== "review") continue;
|
|
160
|
+
const key = c.theme.id;
|
|
161
|
+
if (!byTheme.has(key)) byTheme.set(key, { theme: c.theme, members: [] });
|
|
162
|
+
byTheme.get(key).members.push(c);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const groups = [];
|
|
166
|
+
for (const { theme, members } of byTheme.values()) {
|
|
167
|
+
if (members.length >= 2) {
|
|
168
|
+
groups.push({
|
|
169
|
+
theme: theme.label,
|
|
170
|
+
themeId: theme.id,
|
|
171
|
+
members: members.map((m) => m.name),
|
|
172
|
+
suggestion: "merge",
|
|
173
|
+
reason: `同属「${theme.label}」${members.length} 份,建议先合并成一把伞技能再采纳`,
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
groups.push({
|
|
177
|
+
theme: theme.label,
|
|
178
|
+
themeId: theme.id,
|
|
179
|
+
members: [members[0].name],
|
|
180
|
+
suggestion: "promote",
|
|
181
|
+
reason: `独立新增(${theme.label})`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const auto = candidates.filter((c) => c.tier === "auto");
|
|
187
|
+
const drops = candidates.filter((c) => c.tier === "drop");
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
ok: true,
|
|
191
|
+
ts: new Date().toISOString(),
|
|
192
|
+
corrupt,
|
|
193
|
+
autoPromote: auto,
|
|
194
|
+
autoDrop: drops,
|
|
195
|
+
groups,
|
|
196
|
+
summary: {
|
|
197
|
+
total: dirNames.length + drafts.length,
|
|
198
|
+
corrupt: corrupt.length,
|
|
199
|
+
autoPromote: auto.length,
|
|
200
|
+
autoDrop: drops.length,
|
|
201
|
+
groupsNeedingDecision: groups.filter((g) => g.suggestion === "merge").length,
|
|
202
|
+
hold: groups.reduce((n, g) => n + g.members.length, 0),
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 执行整理计划中"无需人判断"的部分(Tier 0 + Tier 1)。
|
|
209
|
+
*
|
|
210
|
+
* 关键:所有 promote 在同一事件循环内连续完成,利用 dsh-skill-filesystem
|
|
211
|
+
* 的 200ms 写入防抖窗口合并为**一次**目录刷新,避免会话内重复追加 <available_skills>。
|
|
212
|
+
*
|
|
213
|
+
* @param {string} skillsRoot
|
|
214
|
+
* @param {object} plan planTidy() 的结果
|
|
215
|
+
* @param {{comment?: string, actor?: string}} [opts]
|
|
216
|
+
*/
|
|
217
|
+
export async function applyTidy(skillsRoot, plan, opts = {}) {
|
|
218
|
+
const done = [];
|
|
219
|
+
const errors = [];
|
|
220
|
+
const stagingPath = path.join(skillsRoot, STAGING_DIRNAME);
|
|
221
|
+
const archivePath = path.join(skillsRoot, ".archive");
|
|
222
|
+
const stamp = new Date().toISOString().replace(/[-:T]/g, "").slice(0, 14);
|
|
223
|
+
|
|
224
|
+
// Tier 0:损坏草稿移入归档区(永不物理删除)
|
|
225
|
+
for (const c of plan.corrupt ?? []) {
|
|
226
|
+
try {
|
|
227
|
+
await fs.mkdir(archivePath, { recursive: true });
|
|
228
|
+
const target = path.join(archivePath, `${c.name}-corrupt-${stamp}`);
|
|
229
|
+
await fs.rename(path.join(stagingPath, c.name), target);
|
|
230
|
+
done.push(`archive-corrupt ${c.name}`);
|
|
231
|
+
} catch (e) {
|
|
232
|
+
errors.push(`archive-corrupt ${c.name}: ${e.message}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Tier 1:同名/高度相似的补丁直接升入正式库(每份都写 led 账本,可回滚)
|
|
237
|
+
for (const c of plan.autoPromote ?? []) {
|
|
238
|
+
try {
|
|
239
|
+
const r = await promoteDraft(skillsRoot, c.name, {
|
|
240
|
+
actor: opts.actor ?? "user",
|
|
241
|
+
comment: opts.comment ?? `一键整理:${c.reason}`,
|
|
242
|
+
});
|
|
243
|
+
if (r.ok) done.push(`promote ${c.name} → ${c.anchor}`);
|
|
244
|
+
else errors.push(`promote ${c.name}: ${r.errors?.join("; ") ?? r.error}`);
|
|
245
|
+
} catch (e) {
|
|
246
|
+
errors.push(`promote ${c.name}: ${e.message}`);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Tier 1b:过短的直接归档(保留可追溯)
|
|
251
|
+
for (const c of plan.autoDrop ?? []) {
|
|
252
|
+
try {
|
|
253
|
+
await fs.mkdir(archivePath, { recursive: true });
|
|
254
|
+
const target = path.join(archivePath, `${c.name}-dropped-${stamp}`);
|
|
255
|
+
await fs.rename(path.join(stagingPath, c.name), target);
|
|
256
|
+
done.push(`archive-dropped ${c.name}`);
|
|
257
|
+
} catch (e) {
|
|
258
|
+
errors.push(`archive-dropped ${c.name}: ${e.message}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return { ok: errors.length === 0, done, errors };
|
|
263
|
+
}
|
package/lib/usage.js
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 使用遥测与生命周期(Usage & Lifecycle)
|
|
3
|
+
*
|
|
4
|
+
* 移植自 Hermes `tools/skill_usage.py`。
|
|
5
|
+
*
|
|
6
|
+
* 关键设计(每一条都来自 Hermes 的实战教训):
|
|
7
|
+
* - 遥测存**旁路文件** `.usage.json`,绝不写进 SKILL.md frontmatter
|
|
8
|
+
* (否则会污染用户手写的技能,也会污染 bundled/hub 技能)
|
|
9
|
+
* - 生命周期三态:active → stale → archived
|
|
10
|
+
* - **use_count == 0 是"无证据",不是"陈旧"** —— 永不因零使用而归档
|
|
11
|
+
* - `pinned` 豁免全部自动状态转换
|
|
12
|
+
* - 关键内置技能永不归档
|
|
13
|
+
* - 只归档,永不删除(可恢复)
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import fs from "node:fs/promises";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
export const USAGE_FILENAME = ".usage.json";
|
|
20
|
+
export const STATE_ACTIVE = "active";
|
|
21
|
+
export const STATE_STALE = "stale";
|
|
22
|
+
export const STATE_ARCHIVED = "archived";
|
|
23
|
+
export const VALID_STATES = new Set([STATE_ACTIVE, STATE_STALE, STATE_ARCHIVED]);
|
|
24
|
+
|
|
25
|
+
export const DEFAULT_STALE_AFTER_DAYS = 14;
|
|
26
|
+
export const DEFAULT_ARCHIVE_AFTER_DAYS = 30;
|
|
27
|
+
|
|
28
|
+
/** 承载关键功能的技能,curator 无论什么判断都不得归档。保持极小。 */
|
|
29
|
+
export const PROTECTED_SKILLS = new Set([
|
|
30
|
+
"agent-experience",
|
|
31
|
+
"cordis-plugin-development",
|
|
32
|
+
"cordis-composition-reference",
|
|
33
|
+
"editing-cordis-compositions",
|
|
34
|
+
"official-plugins",
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
function usagePath(skillsRoot) {
|
|
38
|
+
return path.join(skillsRoot, USAGE_FILENAME);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 读 .usage.json;不存在或损坏返回空对象。 */
|
|
42
|
+
export async function loadUsage(skillsRoot) {
|
|
43
|
+
try {
|
|
44
|
+
const text = await fs.readFile(usagePath(skillsRoot), "utf8");
|
|
45
|
+
const data = JSON.parse(text);
|
|
46
|
+
return data && typeof data === "object" && !Array.isArray(data) ? data : {};
|
|
47
|
+
} catch {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** 原子写 .usage.json。 */
|
|
53
|
+
export async function saveUsage(skillsRoot, usage) {
|
|
54
|
+
const p = usagePath(skillsRoot);
|
|
55
|
+
const tmp = `${p}.${process.pid}.tmp`;
|
|
56
|
+
await fs.mkdir(skillsRoot, { recursive: true });
|
|
57
|
+
await fs.writeFile(tmp, JSON.stringify(usage, null, 2) + "\n", "utf8");
|
|
58
|
+
await fs.rename(tmp, p);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 取某个技能的遥测条目(不存在则返回默认值)。 */
|
|
62
|
+
export function entryOf(usage, name) {
|
|
63
|
+
const e = usage[name];
|
|
64
|
+
return {
|
|
65
|
+
useCount: Number(e?.useCount ?? e?.use_count ?? 0),
|
|
66
|
+
lastUsedAt: e?.lastUsedAt ?? e?.last_used ?? null,
|
|
67
|
+
createdAt: e?.createdAt ?? e?.created_at ?? null,
|
|
68
|
+
state: VALID_STATES.has(e?.state) ? e.state : STATE_ACTIVE,
|
|
69
|
+
pinned: Boolean(e?.pinned),
|
|
70
|
+
createdBy: e?.createdBy ?? e?.created_by ?? null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 记一次使用。**尽力而为**:失败只记日志,绝不让遥测打断工具调用。
|
|
76
|
+
*/
|
|
77
|
+
export async function bumpUsage(skillsRoot, name, { createdBy } = {}) {
|
|
78
|
+
try {
|
|
79
|
+
const usage = await loadUsage(skillsRoot);
|
|
80
|
+
const cur = usage[name] ?? {};
|
|
81
|
+
usage[name] = {
|
|
82
|
+
...cur,
|
|
83
|
+
useCount: Number(cur.useCount ?? 0) + 1,
|
|
84
|
+
lastUsedAt: new Date().toISOString(),
|
|
85
|
+
createdAt: cur.createdAt ?? new Date().toISOString(),
|
|
86
|
+
state: VALID_STATES.has(cur.state) ? cur.state : STATE_ACTIVE,
|
|
87
|
+
pinned: Boolean(cur.pinned),
|
|
88
|
+
...(createdBy ? { createdBy } : {}),
|
|
89
|
+
};
|
|
90
|
+
await saveUsage(skillsRoot, usage);
|
|
91
|
+
return usage[name];
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.warn("[dsh-evolution] usage bump failed:", error?.message ?? error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** 设置 pinned / state。 */
|
|
99
|
+
export async function setUsageFlag(skillsRoot, name, patch) {
|
|
100
|
+
const usage = await loadUsage(skillsRoot);
|
|
101
|
+
const cur = usage[name] ?? {};
|
|
102
|
+
usage[name] = { ...cur, ...patch };
|
|
103
|
+
await saveUsage(skillsRoot, usage);
|
|
104
|
+
return usage[name];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 确定性状态转换:根据活动时间戳把技能在 active/stale/archived 之间移动。
|
|
109
|
+
*
|
|
110
|
+
* 这是 curator 的**确定性**部分(不需要 LLM),对应 Hermes 的
|
|
111
|
+
* `apply_automatic_transitions`。Hermes 的注释说明了为什么这部分永远开着:
|
|
112
|
+
* 它便宜、可预测、不需要模型判断。
|
|
113
|
+
*
|
|
114
|
+
* @returns {{marked_stale: number, archived: number, reactivated: number, checked: number}}
|
|
115
|
+
*/
|
|
116
|
+
export async function applyAutomaticTransitions(
|
|
117
|
+
skillsRoot,
|
|
118
|
+
{ staleAfterDays = DEFAULT_STALE_AFTER_DAYS, archiveAfterDays = DEFAULT_ARCHIVE_AFTER_DAYS, now = new Date() } = {},
|
|
119
|
+
) {
|
|
120
|
+
const usage = await loadUsage(skillsRoot);
|
|
121
|
+
const counts = { marked_stale: 0, archived: 0, reactivated: 0, checked: 0 };
|
|
122
|
+
const staleCutoff = now.getTime() - staleAfterDays * 86400_000;
|
|
123
|
+
const archiveCutoff = now.getTime() - archiveAfterDays * 86400_000;
|
|
124
|
+
|
|
125
|
+
for (const [name, raw] of Object.entries(usage)) {
|
|
126
|
+
counts.checked += 1;
|
|
127
|
+
const e = entryOf(usage, name);
|
|
128
|
+
|
|
129
|
+
// pinned 豁免全部自动转换
|
|
130
|
+
if (e.pinned) continue;
|
|
131
|
+
// 关键内置技能永不归档
|
|
132
|
+
if (PROTECTED_SKILLS.has(name)) continue;
|
|
133
|
+
// use_count == 0 是"无证据",不是"陈旧" —— 永不因零使用归档
|
|
134
|
+
if (e.useCount === 0) continue;
|
|
135
|
+
|
|
136
|
+
const anchorIso = e.lastUsedAt ?? e.createdAt;
|
|
137
|
+
if (!anchorIso) continue;
|
|
138
|
+
const anchor = Date.parse(anchorIso);
|
|
139
|
+
if (!Number.isFinite(anchor)) continue;
|
|
140
|
+
|
|
141
|
+
if (anchor <= archiveCutoff && e.state !== STATE_ARCHIVED) {
|
|
142
|
+
usage[name] = { ...raw, state: STATE_ARCHIVED };
|
|
143
|
+
counts.archived += 1;
|
|
144
|
+
} else if (anchor <= staleCutoff && e.state === STATE_ACTIVE) {
|
|
145
|
+
usage[name] = { ...raw, state: STATE_STALE };
|
|
146
|
+
counts.marked_stale += 1;
|
|
147
|
+
} else if (anchor > staleCutoff && e.state !== STATE_ACTIVE) {
|
|
148
|
+
usage[name] = { ...raw, state: STATE_ACTIVE };
|
|
149
|
+
counts.reactivated += 1;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
await saveUsage(skillsRoot, usage);
|
|
154
|
+
return counts;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 把归档技能移到 `.archive/` 目录(**永不删除**)。
|
|
159
|
+
* 返回 { moved: boolean, to?: string, error?: string }
|
|
160
|
+
*/
|
|
161
|
+
export async function archiveSkill(skillsRoot, name) {
|
|
162
|
+
if (PROTECTED_SKILLS.has(name)) {
|
|
163
|
+
return { moved: false, error: `"${name}" is a protected skill and is never archived` };
|
|
164
|
+
}
|
|
165
|
+
const usage = await loadUsage(skillsRoot);
|
|
166
|
+
const e = entryOf(usage, name);
|
|
167
|
+
if (e.pinned) return { moved: false, error: `"${name}" is pinned` };
|
|
168
|
+
|
|
169
|
+
const from = path.join(skillsRoot, name);
|
|
170
|
+
const archiveRoot = path.join(skillsRoot, ".archive");
|
|
171
|
+
const stamp = new Date().toISOString().replace(/[-:T]/g, "").slice(0, 14);
|
|
172
|
+
const to = path.join(archiveRoot, `${name}-${stamp}`);
|
|
173
|
+
try {
|
|
174
|
+
await fs.mkdir(archiveRoot, { recursive: true });
|
|
175
|
+
await fs.rename(from, to);
|
|
176
|
+
usage[name] = { ...(usage[name] ?? {}), state: STATE_ARCHIVED, archivedAt: new Date().toISOString() };
|
|
177
|
+
await saveUsage(skillsRoot, usage);
|
|
178
|
+
return { moved: true, to };
|
|
179
|
+
} catch (error) {
|
|
180
|
+
return { moved: false, error: String(error?.message ?? error) };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 接管一个无 provenance 标记的技能(移植自 Hermes `hermes curator adopt`)。
|
|
186
|
+
*
|
|
187
|
+
* 背景:用户手写或从别处导入的技能没有 `metadata.createdBy: agent` 标记,
|
|
188
|
+
* curator 默认永不自动处理它们。`adopt` 把它们纳入管理——但只是**纳入生命周期管理**,
|
|
189
|
+
* 不改变归属:它们仍然不会被自动改写内容。
|
|
190
|
+
*
|
|
191
|
+
* @returns {{ok: boolean, error?: string}}
|
|
192
|
+
*/
|
|
193
|
+
export async function adoptSkill(skillsRoot, name) {
|
|
194
|
+
const usage = await loadUsage(skillsRoot);
|
|
195
|
+
if (usage[name]) {
|
|
196
|
+
return { ok: false, error: `"${name}" is already managed` };
|
|
197
|
+
}
|
|
198
|
+
usage[name] = {
|
|
199
|
+
useCount: 0,
|
|
200
|
+
createdAt: new Date().toISOString(),
|
|
201
|
+
state: STATE_ACTIVE,
|
|
202
|
+
pinned: false,
|
|
203
|
+
adopted: true,
|
|
204
|
+
createdBy: null,
|
|
205
|
+
};
|
|
206
|
+
await saveUsage(skillsRoot, usage);
|
|
207
|
+
return { ok: true };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** 取消接管(回到 unmanaged)。 */
|
|
211
|
+
export async function disownSkill(skillsRoot, name) {
|
|
212
|
+
const usage = await loadUsage(skillsRoot);
|
|
213
|
+
if (!usage[name]) return { ok: false, error: `"${name}" is not managed` };
|
|
214
|
+
delete usage[name];
|
|
215
|
+
await saveUsage(skillsRoot, usage);
|
|
216
|
+
return { ok: true };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** 列出未纳入管理的技能(有 SKILL.md 但 .usage.json 里没有)。 */
|
|
220
|
+
export async function listUnmanaged(skillsRoot, allSkillNames) {
|
|
221
|
+
const usage = await loadUsage(skillsRoot);
|
|
222
|
+
return allSkillNames.filter((n) => !usage[n]);
|
|
223
|
+
}
|
package/locale/en.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Skill evolution",
|
|
3
|
+
"description": "Closed-loop skill self-evolution: post-turn review, briefing & mandatory directive fusion, 4-gate validation, SHA-256 ledger rollback, and umbrella consolidation.",
|
|
4
|
+
"meta": {
|
|
5
|
+
"title": "Skill evolution",
|
|
6
|
+
"description": "Closed-loop skill self-evolution: post-turn review, briefing & mandatory directive fusion, 4-gate validation, SHA-256 ledger rollback, and umbrella consolidation."
|
|
7
|
+
}
|
|
8
|
+
}
|
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,90 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skill-evolution",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Closed-loop skill self-evolution plugin for DSH: post-turn review, Chinese briefing & mandatory directive fusion, 4-gate safety validation, SHA-256 content-addressed ledger with single-entry rollback, LLM umbrella consolidation, and a Web/Mobile/Remote review workbench.",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "veritaswiki",
|
|
9
|
+
"url": "https://github.com/veritaswiki"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/veritaswiki/skill-evolution.git"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/veritaswiki/skill-evolution#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/veritaswiki/skill-evolution/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"dsh",
|
|
21
|
+
"deepseek-harness",
|
|
22
|
+
"dsh-plugin",
|
|
23
|
+
"plugin",
|
|
24
|
+
"skill",
|
|
25
|
+
"self-evolution",
|
|
26
|
+
"hermes",
|
|
27
|
+
"curator",
|
|
28
|
+
"procedural-memory",
|
|
29
|
+
"ui"
|
|
30
|
+
],
|
|
31
|
+
"icon": "./icon.svg",
|
|
32
|
+
"main": "./index.js",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": "./index.js",
|
|
35
|
+
"./client": "./client.js",
|
|
36
|
+
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
37
|
+
"./locale/*.json": "./locale/*.json",
|
|
38
|
+
"./icon": "./icon.svg",
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"index.js",
|
|
43
|
+
"client.js",
|
|
44
|
+
"lib/*.js",
|
|
45
|
+
"cordis.patch.yml",
|
|
46
|
+
"locale/*.json",
|
|
47
|
+
"icon.svg",
|
|
48
|
+
"assets/icon-180.png",
|
|
49
|
+
"README.md",
|
|
50
|
+
"README.en.md",
|
|
51
|
+
"CHANGELOG.md",
|
|
52
|
+
"LICENSE",
|
|
53
|
+
"screenshots.json",
|
|
54
|
+
"assets/screenshots/*.png"
|
|
55
|
+
],
|
|
56
|
+
"scripts": {
|
|
57
|
+
"test": "node --test test/*.test.mjs",
|
|
58
|
+
"audit:parity": "node tools/verify-parity.mjs",
|
|
59
|
+
"audit:prompts": "node tools/verify-prompt-fidelity.mjs",
|
|
60
|
+
"sanitize": "node scripts/sanitize-check.mjs"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=20.11",
|
|
64
|
+
"dsh": ">=0.2.2-rc.1 <0.3.0"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public",
|
|
68
|
+
"provenance": true
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@deepseek-ai/schemastery": ">=3.0.0-0"
|
|
72
|
+
},
|
|
73
|
+
"dsh": {
|
|
74
|
+
"bundle": {
|
|
75
|
+
"patch": "./cordis.patch.yml"
|
|
76
|
+
},
|
|
77
|
+
"client": {
|
|
78
|
+
"platform": "web",
|
|
79
|
+
"immediately": true,
|
|
80
|
+
"inject": [
|
|
81
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
82
|
+
"@deepseek-ai/dsh-client-ui-layout",
|
|
83
|
+
"@deepseek-ai/dsh-client-ui-conversation",
|
|
84
|
+
"@deepseek-ai/dsh-client-ui-session",
|
|
85
|
+
"@deepseek-ai/dsh-client-ui-workspace",
|
|
86
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
package/screenshots.json
ADDED