@hcmai/cli 0.12.0 → 0.13.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/dist/index.js +91 -6
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6021,6 +6021,7 @@ function chironEntry(skill) {
|
|
|
6021
6021
|
stages: skill.stages ?? [],
|
|
6022
6022
|
actionSurface: skill.actionSurface,
|
|
6023
6023
|
requires: skill.requires,
|
|
6024
|
+
renamedFrom: skill.renamedFrom,
|
|
6024
6025
|
bytes: skill.bytes,
|
|
6025
6026
|
files: skill.files
|
|
6026
6027
|
},
|
|
@@ -6038,6 +6039,7 @@ function bundledEntry(entry, cliVersion) {
|
|
|
6038
6039
|
// 自带技能讲的就是本 CLI 的命令,恒为 cli。
|
|
6039
6040
|
actionSurface: "cli",
|
|
6040
6041
|
requires: entry.requires,
|
|
6042
|
+
renamedFrom: entry.renamedFrom,
|
|
6041
6043
|
bytes: entry.bytes,
|
|
6042
6044
|
files: entry.files
|
|
6043
6045
|
},
|
|
@@ -6368,6 +6370,14 @@ async function resolveBundledClosure(targetId, dir = bundledSkillsDir()) {
|
|
|
6368
6370
|
|
|
6369
6371
|
// src/commands/skills.ts
|
|
6370
6372
|
var SKILLS_STATE_FILE = ".hcm-skills.json";
|
|
6373
|
+
function resolveRenamedId(id, half) {
|
|
6374
|
+
if (half.entries.has(id)) return id;
|
|
6375
|
+
if (half.status !== "fetched") return id;
|
|
6376
|
+
for (const [current, entry] of half.entries) {
|
|
6377
|
+
if ((entry.meta.renamedFrom ?? []).includes(id)) return current;
|
|
6378
|
+
}
|
|
6379
|
+
return id;
|
|
6380
|
+
}
|
|
6371
6381
|
function migrateSkillsState(state) {
|
|
6372
6382
|
const skills2 = {};
|
|
6373
6383
|
for (const [id, record] of Object.entries(state.skills ?? {})) {
|
|
@@ -6794,14 +6804,15 @@ async function skillsInstallCommand(id, args) {
|
|
|
6794
6804
|
};
|
|
6795
6805
|
const installBundled = async (one) => {
|
|
6796
6806
|
const { documents: local, external } = await resolveBundledClosure(one);
|
|
6797
|
-
for (const
|
|
6807
|
+
for (const rawNeed of external) {
|
|
6808
|
+
const need = resolveRenamedId(rawNeed, catalog.chiron);
|
|
6798
6809
|
if (catalog.chiron.status !== "fetched") {
|
|
6799
6810
|
throw invalid(
|
|
6800
6811
|
`\u81EA\u5E26\u6280\u80FD ${one} \u4F9D\u8D56\u777F\u620E\u6280\u80FD ${need}\uFF0C\u4F46\u8FD9\u4E00\u8D9F\u6CA1\u8FDE\u7F51\u53D6\u777F\u620E\u76EE\u5F55\uFF08--source ${source}\uFF09\u3002\u8054\u7F51\u540E\u91CD\u8DD1\uFF0C\u6216\u5148\u5355\u72EC\u88C5\u4E0A\u5B83\u3002`
|
|
6801
6812
|
);
|
|
6802
6813
|
}
|
|
6803
6814
|
if (!catalog.chiron.entries.has(need)) {
|
|
6804
|
-
throw invalid(`\u81EA\u5E26\u6280\u80FD ${one} \u4F9D\u8D56 ${need}\uFF0C\u4F46 ${endpoint} \u7684\u6280\u80FD\u76EE\u5F55\u91CC\u6CA1\u6709\u5B83`);
|
|
6815
|
+
throw invalid(`\u81EA\u5E26\u6280\u80FD ${one} \u4F9D\u8D56 ${rawNeed}${need !== rawNeed ? `\uFF08\u73B0\u540D ${need}\uFF09` : ""}\uFF0C\u4F46 ${endpoint} \u7684\u6280\u80FD\u76EE\u5F55\u91CC\u6CA1\u6709\u5B83`);
|
|
6805
6816
|
}
|
|
6806
6817
|
pushAll(
|
|
6807
6818
|
await mapWithConcurrency(
|
|
@@ -6847,6 +6858,34 @@ async function skillsInstallCommand(id, args) {
|
|
|
6847
6858
|
);
|
|
6848
6859
|
}
|
|
6849
6860
|
}
|
|
6861
|
+
if (args.check) {
|
|
6862
|
+
const fmtCheck = args.output ?? "table";
|
|
6863
|
+
const would = documents.map((d) => d.id).sort();
|
|
6864
|
+
if (fmtCheck === "json" || fmtCheck === "yaml") {
|
|
6865
|
+
process.stdout.write(formatObject16({
|
|
6866
|
+
dryRun: true,
|
|
6867
|
+
baseDir: layout.baseDir,
|
|
6868
|
+
target: layout.target,
|
|
6869
|
+
all,
|
|
6870
|
+
managed: false,
|
|
6871
|
+
wouldInstall: would,
|
|
6872
|
+
endpoint,
|
|
6873
|
+
base
|
|
6874
|
+
}, { format: fmtCheck }) + "\n");
|
|
6875
|
+
} else {
|
|
6876
|
+
process.stdout.write(`\u8FD9\u4E2A\u76EE\u5F55\u8FD8\u6CA1\u88C5\u8FC7\u6280\u80FD\uFF08${path6.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\uFF09\u3002
|
|
6877
|
+
`);
|
|
6878
|
+
process.stdout.write(`--check\uFF1A\u4F1A\u88C5 ${would.length} \u4E2A\u6280\u80FD\u5230 ${layout.baseDir}\uFF0C\u5E76\u628A\u7D22\u5F15\u4E0E\u9879\u76EE\u8FB9\u754C\u5757\u5199\u8FDB ${layout.agentsFile ?? "AGENTS.md"}\u3002**\u672C\u6B21\u4E00\u4E2A\u5B57\u8282\u90FD\u6CA1\u5199\u3002**
|
|
6879
|
+
`);
|
|
6880
|
+
if (would.length > 0) {
|
|
6881
|
+
process.stdout.write(` ${would.slice(0, 8).join("\u3001")}${would.length > 8 ? ` \u7B49 ${would.length} \u4E2A` : ""}
|
|
6882
|
+
`);
|
|
6883
|
+
}
|
|
6884
|
+
process.stdout.write(" \u771F\u88C5\uFF1A\u53BB\u6389 --check \u91CD\u8DD1\u3002\n");
|
|
6885
|
+
}
|
|
6886
|
+
process.exitCode = 0;
|
|
6887
|
+
return;
|
|
6888
|
+
}
|
|
6850
6889
|
const result = await installSkillDocuments(documents, requestedIds, layout.baseDir, Boolean(args.force), {
|
|
6851
6890
|
endpoint,
|
|
6852
6891
|
base,
|
|
@@ -7178,6 +7217,27 @@ async function planStaleReferences(state, documents, baseDir) {
|
|
|
7178
7217
|
const byKey = (a, b) => `${a.id}/${a.path}`.localeCompare(`${b.id}/${b.path}`);
|
|
7179
7218
|
return { remove: remove.sort(byKey), keptLocallyModified: keptLocallyModified.sort(byKey) };
|
|
7180
7219
|
}
|
|
7220
|
+
async function removeRenamedSkills(baseDir, renamed) {
|
|
7221
|
+
if (renamed.length === 0) return [];
|
|
7222
|
+
const kept = [];
|
|
7223
|
+
const state = await readSkillsState(baseDir);
|
|
7224
|
+
for (const { from } of renamed) {
|
|
7225
|
+
assertSafeSkillId(from);
|
|
7226
|
+
const dir = path6.join(baseDir, from);
|
|
7227
|
+
const resolved = path6.resolve(dir);
|
|
7228
|
+
if (resolved !== path6.join(path6.resolve(baseDir), from)) continue;
|
|
7229
|
+
const hasSkillFile = await fsp2.stat(path6.join(dir, "SKILL.md")).then(() => true).catch(() => false);
|
|
7230
|
+
const exists2 = await fsp2.stat(dir).then(() => true).catch(() => false);
|
|
7231
|
+
if (exists2 && !hasSkillFile) {
|
|
7232
|
+
kept.push({ from, kept: "\u76EE\u5F55\u91CC\u6CA1\u6709 SKILL.md\uFF0C\u50CF\u662F\u4F60\u81EA\u5DF1\u653E\u7684\u4E1C\u897F\uFF0C\u6CA1\u6709\u5220" });
|
|
7233
|
+
} else if (exists2) {
|
|
7234
|
+
await fsp2.rm(dir, { recursive: true, force: true });
|
|
7235
|
+
}
|
|
7236
|
+
if (state?.skills[from] !== void 0) delete state.skills[from];
|
|
7237
|
+
}
|
|
7238
|
+
if (state) await writeSkillsState(baseDir, state);
|
|
7239
|
+
return kept;
|
|
7240
|
+
}
|
|
7181
7241
|
async function writeSkillDocuments(documents, baseDir, removals = []) {
|
|
7182
7242
|
const staged = [];
|
|
7183
7243
|
const removed = [];
|
|
@@ -7273,7 +7333,26 @@ async function planSkillUpdate(options) {
|
|
|
7273
7333
|
const directIds = recorded.some(([, r]) => r.direct) ? recorded.filter(([, r]) => r.direct).map(([id]) => id) : recorded.map(([id]) => id);
|
|
7274
7334
|
const entries = [];
|
|
7275
7335
|
const live = [];
|
|
7276
|
-
|
|
7336
|
+
const renames = /* @__PURE__ */ new Map();
|
|
7337
|
+
for (const half of [catalog.chiron, catalog.cli]) {
|
|
7338
|
+
if (half.status !== "fetched") continue;
|
|
7339
|
+
for (const [newId, entry] of half.entries) {
|
|
7340
|
+
for (const old of entry.meta.renamedFrom ?? []) {
|
|
7341
|
+
if (old !== newId) renames.set(old, newId);
|
|
7342
|
+
}
|
|
7343
|
+
}
|
|
7344
|
+
}
|
|
7345
|
+
const renamedAway = /* @__PURE__ */ new Set();
|
|
7346
|
+
const renamedPairs = [];
|
|
7347
|
+
for (const oldId of directIds) {
|
|
7348
|
+
const newId = renames.get(oldId);
|
|
7349
|
+
if (!newId || state.skills[newId] !== void 0) continue;
|
|
7350
|
+
renamedAway.add(oldId);
|
|
7351
|
+
renamedPairs.push({ from: oldId, to: newId });
|
|
7352
|
+
entries.push({ id: oldId, status: "renamed", note: `\u4EA7\u54C1\u628A\u5B83\u6539\u540D\u4E3A ${newId}\uFF1B\u65E7\u76EE\u5F55\u4E0E\u65E7\u6E05\u5355\u6761\u76EE\u5DF2\u6E05\u6389` });
|
|
7353
|
+
}
|
|
7354
|
+
const liveIds = directIds.filter((id) => !renamedAway.has(id));
|
|
7355
|
+
for (const id of liveIds.sort()) {
|
|
7277
7356
|
const record = state.skills[id];
|
|
7278
7357
|
const status = classifyInstalledSource(id, record, catalog);
|
|
7279
7358
|
if (status === "present") {
|
|
@@ -7314,8 +7393,9 @@ async function planSkillUpdate(options) {
|
|
|
7314
7393
|
}
|
|
7315
7394
|
chironNeeded.add(item.id);
|
|
7316
7395
|
}
|
|
7317
|
-
for (const
|
|
7396
|
+
for (const rawId of chironNeeded) {
|
|
7318
7397
|
if (!manifest2) continue;
|
|
7398
|
+
const id = resolveRenamedId(rawId, catalog.chiron);
|
|
7319
7399
|
try {
|
|
7320
7400
|
for (const skill of resolveSkillInstallOrder(manifest2, id)) {
|
|
7321
7401
|
if (!closure.has(skill.id)) closure.set(skill.id, { kind: "chiron", skill });
|
|
@@ -7370,7 +7450,7 @@ async function planSkillUpdate(options) {
|
|
|
7370
7450
|
});
|
|
7371
7451
|
}
|
|
7372
7452
|
entries.sort((a, b) => a.id.localeCompare(b.id));
|
|
7373
|
-
return { entries, documents };
|
|
7453
|
+
return { entries, documents, renamed: renamedPairs };
|
|
7374
7454
|
}
|
|
7375
7455
|
var UPDATE_STATUS_LABEL = {
|
|
7376
7456
|
updated: "\u5DF2\u66F4\u65B0",
|
|
@@ -7378,6 +7458,7 @@ var UPDATE_STATUS_LABEL = {
|
|
|
7378
7458
|
unchanged: "\u5DF2\u662F\u6700\u65B0",
|
|
7379
7459
|
"locally-modified": "\u672C\u5730\u6539\u8FC7\xB7\u8DF3\u8FC7",
|
|
7380
7460
|
"removed-upstream": "\u4EA7\u54C1\u5DF2\u79FB\u9664",
|
|
7461
|
+
renamed: "\u4EA7\u54C1\u5DF2\u6539\u540D\xB7\u65E7\u4EFD\u5DF2\u6E05",
|
|
7381
7462
|
"removed-in-cli": "CLI \u4E0D\u518D\u81EA\u5E26",
|
|
7382
7463
|
// 🔴 这一档不是结论,是「这一趟没核」。文案上必须看得出区别,
|
|
7383
7464
|
// 否则顾问会把它读成「没问题」,而它可能正藏着一份真的被移除了的技能。
|
|
@@ -7426,7 +7507,7 @@ async function skillsUpdateCommand(args) {
|
|
|
7426
7507
|
});
|
|
7427
7508
|
const stale = await planStaleReferences(state, plan.documents, layout.baseDir);
|
|
7428
7509
|
const subscriptionChanged = all && !state.all;
|
|
7429
|
-
if (!args.check && (plan.documents.length > 0 || subscriptionChanged)) {
|
|
7510
|
+
if (!args.check && (plan.documents.length > 0 || subscriptionChanged || plan.renamed.length > 0)) {
|
|
7430
7511
|
await writeSkillDocuments(plan.documents, layout.baseDir, stale.remove);
|
|
7431
7512
|
await recordInstalled(layout.baseDir, plan.documents, {
|
|
7432
7513
|
endpoint,
|
|
@@ -7435,6 +7516,10 @@ async function skillsUpdateCommand(args) {
|
|
|
7435
7516
|
all,
|
|
7436
7517
|
directIds: all ? new Set(plan.documents.map((document) => document.id)) : /* @__PURE__ */ new Set()
|
|
7437
7518
|
});
|
|
7519
|
+
for (const k of await removeRenamedSkills(layout.baseDir, plan.renamed)) {
|
|
7520
|
+
process.stderr.write(`[hcm] \u6539\u540D\u6E05\u7406\u8DF3\u8FC7 ${k.from}\uFF1A${k.kept}
|
|
7521
|
+
`);
|
|
7522
|
+
}
|
|
7438
7523
|
}
|
|
7439
7524
|
const agentIndexes = !args.check && layout.agentsFile ? await syncAgentIndexes(layout, manifest2) : [];
|
|
7440
7525
|
const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");
|