@hcmai/cli 0.12.0 → 0.13.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/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
  },
@@ -7178,6 +7180,27 @@ async function planStaleReferences(state, documents, baseDir) {
7178
7180
  const byKey = (a, b) => `${a.id}/${a.path}`.localeCompare(`${b.id}/${b.path}`);
7179
7181
  return { remove: remove.sort(byKey), keptLocallyModified: keptLocallyModified.sort(byKey) };
7180
7182
  }
7183
+ async function removeRenamedSkills(baseDir, renamed) {
7184
+ if (renamed.length === 0) return [];
7185
+ const kept = [];
7186
+ const state = await readSkillsState(baseDir);
7187
+ for (const { from } of renamed) {
7188
+ assertSafeSkillId(from);
7189
+ const dir = path6.join(baseDir, from);
7190
+ const resolved = path6.resolve(dir);
7191
+ if (resolved !== path6.join(path6.resolve(baseDir), from)) continue;
7192
+ const hasSkillFile = await fsp2.stat(path6.join(dir, "SKILL.md")).then(() => true).catch(() => false);
7193
+ const exists2 = await fsp2.stat(dir).then(() => true).catch(() => false);
7194
+ if (exists2 && !hasSkillFile) {
7195
+ 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" });
7196
+ } else if (exists2) {
7197
+ await fsp2.rm(dir, { recursive: true, force: true });
7198
+ }
7199
+ if (state?.skills[from] !== void 0) delete state.skills[from];
7200
+ }
7201
+ if (state) await writeSkillsState(baseDir, state);
7202
+ return kept;
7203
+ }
7181
7204
  async function writeSkillDocuments(documents, baseDir, removals = []) {
7182
7205
  const staged = [];
7183
7206
  const removed = [];
@@ -7273,7 +7296,26 @@ async function planSkillUpdate(options) {
7273
7296
  const directIds = recorded.some(([, r]) => r.direct) ? recorded.filter(([, r]) => r.direct).map(([id]) => id) : recorded.map(([id]) => id);
7274
7297
  const entries = [];
7275
7298
  const live = [];
7276
- for (const id of directIds.sort()) {
7299
+ const renames = /* @__PURE__ */ new Map();
7300
+ for (const half of [catalog.chiron, catalog.cli]) {
7301
+ if (half.status !== "fetched") continue;
7302
+ for (const [newId, entry] of half.entries) {
7303
+ for (const old of entry.meta.renamedFrom ?? []) {
7304
+ if (old !== newId) renames.set(old, newId);
7305
+ }
7306
+ }
7307
+ }
7308
+ const renamedAway = /* @__PURE__ */ new Set();
7309
+ const renamedPairs = [];
7310
+ for (const oldId of directIds) {
7311
+ const newId = renames.get(oldId);
7312
+ if (!newId || state.skills[newId] !== void 0) continue;
7313
+ renamedAway.add(oldId);
7314
+ renamedPairs.push({ from: oldId, to: newId });
7315
+ 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` });
7316
+ }
7317
+ const liveIds = directIds.filter((id) => !renamedAway.has(id));
7318
+ for (const id of liveIds.sort()) {
7277
7319
  const record = state.skills[id];
7278
7320
  const status = classifyInstalledSource(id, record, catalog);
7279
7321
  if (status === "present") {
@@ -7370,7 +7412,7 @@ async function planSkillUpdate(options) {
7370
7412
  });
7371
7413
  }
7372
7414
  entries.sort((a, b) => a.id.localeCompare(b.id));
7373
- return { entries, documents };
7415
+ return { entries, documents, renamed: renamedPairs };
7374
7416
  }
7375
7417
  var UPDATE_STATUS_LABEL = {
7376
7418
  updated: "\u5DF2\u66F4\u65B0",
@@ -7378,6 +7420,7 @@ var UPDATE_STATUS_LABEL = {
7378
7420
  unchanged: "\u5DF2\u662F\u6700\u65B0",
7379
7421
  "locally-modified": "\u672C\u5730\u6539\u8FC7\xB7\u8DF3\u8FC7",
7380
7422
  "removed-upstream": "\u4EA7\u54C1\u5DF2\u79FB\u9664",
7423
+ renamed: "\u4EA7\u54C1\u5DF2\u6539\u540D\xB7\u65E7\u4EFD\u5DF2\u6E05",
7381
7424
  "removed-in-cli": "CLI \u4E0D\u518D\u81EA\u5E26",
7382
7425
  // 🔴 这一档不是结论,是「这一趟没核」。文案上必须看得出区别,
7383
7426
  // 否则顾问会把它读成「没问题」,而它可能正藏着一份真的被移除了的技能。
@@ -7426,7 +7469,7 @@ async function skillsUpdateCommand(args) {
7426
7469
  });
7427
7470
  const stale = await planStaleReferences(state, plan.documents, layout.baseDir);
7428
7471
  const subscriptionChanged = all && !state.all;
7429
- if (!args.check && (plan.documents.length > 0 || subscriptionChanged)) {
7472
+ if (!args.check && (plan.documents.length > 0 || subscriptionChanged || plan.renamed.length > 0)) {
7430
7473
  await writeSkillDocuments(plan.documents, layout.baseDir, stale.remove);
7431
7474
  await recordInstalled(layout.baseDir, plan.documents, {
7432
7475
  endpoint,
@@ -7435,6 +7478,10 @@ async function skillsUpdateCommand(args) {
7435
7478
  all,
7436
7479
  directIds: all ? new Set(plan.documents.map((document) => document.id)) : /* @__PURE__ */ new Set()
7437
7480
  });
7481
+ for (const k of await removeRenamedSkills(layout.baseDir, plan.renamed)) {
7482
+ process.stderr.write(`[hcm] \u6539\u540D\u6E05\u7406\u8DF3\u8FC7 ${k.from}\uFF1A${k.kept}
7483
+ `);
7484
+ }
7438
7485
  }
7439
7486
  const agentIndexes = !args.check && layout.agentsFile ? await syncAgentIndexes(layout, manifest2) : [];
7440
7487
  const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");