@hcmai/cli 0.27.1 → 0.27.3

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
@@ -4309,6 +4309,14 @@ function printQueryResult(result, fmt, dsl = {}) {
4309
4309
  process.stderr.write(`\u63D0\u793A [${w.code}]${text2 ? " " + text2 : ""}
4310
4310
  `);
4311
4311
  }
4312
+ for (const m of result.match ?? []) {
4313
+ const total = m.includedTotal ?? m.included.length;
4314
+ const listed = m.listedInWarning ?? m.included.length;
4315
+ if (m.included.length <= listed && total <= listed) continue;
4316
+ process.stderr.write(
4317
+ `match \u53D6\u503C\u5168\u96C6 [${m.field}]\uFF08\u5171 ${total} \u4E2A\uFF0C\u63D0\u793A\u6B63\u6587\u53EA\u5217\u4E86\u524D ${listed} \u4E2A\uFF09\uFF1A` + m.included.map((hit) => `"${hit.value}"`).join("\u3001") + "\n"
4318
+ );
4319
+ }
4312
4320
  if (fmt === "table" && result.total !== void 0) {
4313
4321
  process.stdout.write(`Showing ${result.rows.length} of ${result.total} results.
4314
4322
  `);
@@ -5107,7 +5115,13 @@ function formatDescriptionTable(desc, verbose = false) {
5107
5115
  );
5108
5116
  }
5109
5117
  if (desc.relations.length) {
5110
- lines.push(`relations: ${desc.relations.map((r) => `${r.key}(via ${r.via})`).join(", ")}`);
5118
+ lines.push(`relations: ${desc.relations.map((r) => {
5119
+ const target = r.target ? ` \u2192 ${r.target}` : "";
5120
+ const card = r.cardinality ? `, ${r.cardinality}${r.cardinality === "many" ? "\uFF08\u4EC5 exists\uFF09" : ""}` : "";
5121
+ const filter = r.filter ? `, \u8FC7\u6EE4 ${r.filter}` : "";
5122
+ const declared = r.declaredIn && r.declaredIn !== desc.model && !r.auto ? `, \u58F0\u660E\u4E8E ${r.declaredIn}` : "";
5123
+ return `${r.key}(via ${r.via}${target}${card}${filter}${declared})`;
5124
+ }).join(", ")}`);
5111
5125
  }
5112
5126
  return lines.join("\n");
5113
5127
  }
@@ -6271,6 +6285,7 @@ function extractToolNames(raw) {
6271
6285
  function buildLlmTable(rows2) {
6272
6286
  let inSum = 0;
6273
6287
  let outSum = 0;
6288
+ const hasFallback = rows2.some((r) => r.selectionFallbackReason != null);
6274
6289
  const table = rows2.map((r) => {
6275
6290
  const pIn = Number(r.promptTokens ?? 0);
6276
6291
  const pOut = Number(r.completionTokens ?? 0);
@@ -6283,7 +6298,8 @@ function buildLlmTable(rows2) {
6283
6298
  TOOLS: short(extractToolNames(r.responseToolCalls), 30),
6284
6299
  "TOKENS(in/out)": `${pIn}/${pOut}`,
6285
6300
  LATENCY: fmtDuration(r.latencyMs ?? void 0),
6286
- FINISH: short(r.finishReason, 12)
6301
+ FINISH: short(r.finishReason, 12),
6302
+ ...hasFallback ? { FALLBACK: r.selectionFallbackReason ?? "-" } : {}
6287
6303
  };
6288
6304
  });
6289
6305
  return { table, inSum, outSum };
@@ -10643,6 +10659,7 @@ import {
10643
10659
  collectMiniPushWrites,
10644
10660
  createWorkspaceFile,
10645
10661
  deleteWorkspaceFileChecked,
10662
+ findPullMiniAppCodeCaseCollisions,
10646
10663
  formatMiniVerifyReport,
10647
10664
  formatObject as formatObject26,
10648
10665
  formatRows as formatRows6,
@@ -11122,6 +11139,8 @@ async function workspacePullCommand(args) {
11122
11139
  endpoint: client4.endpoint ?? existing?.endpoint
11123
11140
  });
11124
11141
  const files = await listWorkspaceFilesForSync(client4.raw(), workspaceKey);
11142
+ const miniApps = detectRemoteMiniApps(files.data);
11143
+ await assertNoMiniAppCaseCollisionBeforePull(rootDir, miniApps, workspaceKey);
11125
11144
  const localFiles = await readWorkspaceRawLocalFiles(rootDir);
11126
11145
  const remotePaths = new Set(files.data.map((file) => file.relativePath));
11127
11146
  const manifest2 = await readWorkspaceRawManifest(rootDir, context, true);
@@ -11145,7 +11164,6 @@ async function workspacePullCommand(args) {
11145
11164
  path11.join(rootDir, WORKSPACE_STATE_DIR, WORKSPACE_PULL_INCOMPLETE_FILE),
11146
11165
  JSON.stringify(context, null, 2) + "\n"
11147
11166
  );
11148
- const miniApps = detectRemoteMiniApps(files.data);
11149
11167
  const pulledMiniApps = [];
11150
11168
  for (const appCode of miniApps) {
11151
11169
  const result = await pullMiniAppProject({
@@ -11230,6 +11248,7 @@ async function workspaceAddMiniCommand(appCode, args) {
11230
11248
  fields: args.fields,
11231
11249
  defaults: args.defaults
11232
11250
  });
11251
+ await assertNoLocalMiniAppCaseCollision(rootDir, appCode);
11233
11252
  const result = await initMiniAppProject({
11234
11253
  appCode,
11235
11254
  workspaceKey: context.workspaceKey,
@@ -12409,6 +12428,48 @@ function detectRemoteMiniApps(files) {
12409
12428
  }
12410
12429
  return Array.from(appCodes).sort();
12411
12430
  }
12431
+ async function assertNoMiniAppCaseCollisionBeforePull(rootDir, remoteCodes, workspaceKey) {
12432
+ const remote = new Set(remoteCodes);
12433
+ const local = new Set((await discoverMiniApps(rootDir)).map((app) => app.appCode));
12434
+ const collisions = findPullMiniAppCodeCaseCollisions(remote, local);
12435
+ if (!collisions.length) return;
12436
+ const origin = (code2) => remote.has(code2) && local.has(code2) ? "\u8FDC\u7AEF\uFF0C\u672C\u5730\u5DF2\u6709" : remote.has(code2) ? "\u8FDC\u7AEF" : `\u672C\u5730\u76EE\u5F55 ${MINI_APPS_DIR}/${code2}`;
12437
+ const listed = collisions.map((group) => group.map((code2) => `${code2}\uFF08${origin(code2)}\uFF09`).join(" / ")).join("\uFF1B");
12438
+ const remotePairs = collisions.some((group) => group.filter((code2) => remote.has(code2)).length > 1);
12439
+ const localPairs = collisions.some((group) => group.some((code2) => local.has(code2) && !remote.has(code2)));
12440
+ const steps = [
12441
+ ...remotePairs ? ["\u8FDC\u7AEF\u540C\u4E00\u7A7A\u95F4\u91CC\u6709\u53EA\u5DEE\u5927\u5C0F\u5199\u7684\u7F16\u7801\uFF1A\u5728\u7CFB\u7EDF\u91CC\u628A\u5176\u4E2D\u4E00\u4E2A\u8F7B\u5E94\u7528\u6539\u6210\u4E0D\u540C\u7684\u7F16\u7801\uFF08\u6216\u5220\u6389\u4E0D\u7528\u7684\u90A3\u4E2A\uFF09\u540E\u91CD\u65B0 pull"] : [],
12442
+ ...localPairs ? [`\u672C\u5730\u76EE\u5F55\u4E0E\u8FDC\u7AEF\u7F16\u7801\u53EA\u5DEE\u5927\u5C0F\u5199\uFF1A\u786E\u8BA4\u662F\u4E0D\u662F\u540C\u4E00\u4E2A\u5E94\u7528\u2014\u2014\u662F\u5C31\u628A\u6539\u52A8\u5E76\u5165\u4E0E\u8FDC\u7AEF\u7F16\u7801\u540C\u540D\u7684\u76EE\u5F55\uFF08\u672C\u5730\u8FD8\u6CA1\u6709\u5C31\u628A\u8BE5\u76EE\u5F55\u6539\u540D\u6210\u8FDC\u7AEF\u7684\u7F16\u7801\uFF09\uFF0C\u4E0D\u662F\u5C31\u5148\u628A\u672C\u5730\u76EE\u5F55\u79FB\u51FA ${MINI_APPS_DIR}/\uFF08\u672A push \u7684\u6539\u52A8\u5148\u5907\u4EFD\uFF09`] : []
12443
+ ];
12444
+ throw new CliError28({
12445
+ code: CliErrorCode29.BUSINESS_RULE_VIOLATION,
12446
+ message: `\u8F7B\u5E94\u7528\u7F16\u7801\u53EA\u5DEE\u5927\u5C0F\u5199\uFF1A${listed}\u3002\u670D\u52A1\u7AEF\u533A\u5206\u5927\u5C0F\u5199\uFF0C\u672C\u5730\u76EE\u5F55\u5728 macOS / Windows \u9ED8\u8BA4\u4E0D\u533A\u5206\uFF0C\u7EE7\u7EED\u62C9\u53D6\u4F1A\u5199\u8FDB\u540C\u4E00\u4E2A\u76EE\u5F55\u4E92\u76F8\u8986\u76D6\uFF1B\u672A\u5199\u5165\u4EFB\u4F55\u6587\u4EF6\u3002`,
12447
+ context: {
12448
+ workspaceKey,
12449
+ reasonCode: "MINI_APP_CODE_CASE_COLLISION",
12450
+ collisions,
12451
+ remote: collisions.flat().filter((code2) => remote.has(code2)),
12452
+ local: collisions.flat().filter((code2) => local.has(code2)),
12453
+ nextStep: steps.join("\uFF1B") + "\u3002"
12454
+ }
12455
+ });
12456
+ }
12457
+ async function assertNoLocalMiniAppCaseCollision(rootDir, appCode) {
12458
+ const wanted = appCode.trim();
12459
+ const existing = (await discoverMiniApps(rootDir)).map((app) => app.appCode);
12460
+ const clash = existing.filter((code2) => code2 !== wanted && code2.toLowerCase() === wanted.toLowerCase());
12461
+ if (!clash.length) return;
12462
+ throw new CliError28({
12463
+ code: CliErrorCode29.BUSINESS_RULE_VIOLATION,
12464
+ message: `\u672C\u5730\u5DF2\u6709\u53EA\u5DEE\u5927\u5C0F\u5199\u7684\u8F7B\u5E94\u7528\u76EE\u5F55 ${clash.map((code2) => `${MINI_APPS_DIR}/${code2}`).join(", ")}\uFF0C\u4E0D\u80FD\u518D\u65B0\u589E ${wanted}\uFF1A\u5728\u5927\u5C0F\u5199\u4E0D\u654F\u611F\u7684\u6587\u4EF6\u7CFB\u7EDF\u4E0A\u4E24\u8005\u662F\u540C\u4E00\u4E2A\u76EE\u5F55\u3002`,
12465
+ context: {
12466
+ reasonCode: "MINI_APP_CODE_CASE_COLLISION",
12467
+ appCode: wanted,
12468
+ existing: clash,
12469
+ nextStep: `\u6CBF\u7528\u5DF2\u6709\u7684\u7F16\u7801 ${clash[0]}\uFF0C\u6216\u6362\u4E00\u4E2A\u4E0D\u53EA\u5DEE\u5927\u5C0F\u5199\u7684\u65B0\u7F16\u7801\u3002`
12470
+ }
12471
+ });
12472
+ }
12412
12473
  function isMiniAppPath(relativePath) {
12413
12474
  return relativePath === MINI_APPS_DIR || relativePath.startsWith(`${MINI_APPS_DIR}/`);
12414
12475
  }
@@ -16418,16 +16479,37 @@ var installed = async (ctx) => {
16418
16479
  ctx.skills = states;
16419
16480
  const keys = (s) => Object.keys(s.state.skills);
16420
16481
  const count = new Set(states.flatMap(keys)).size;
16482
+ const localDir = skillsLocalDir(ctx.root);
16483
+ let local;
16484
+ try {
16485
+ local = await readLocalSkills(localDir, { strict: true });
16486
+ } catch (error) {
16487
+ if (!(error instanceof SkillsDirUnreadable)) throw error;
16488
+ return unknown("SKILLS_LOCAL_UNREADABLE", `${path15.relative(ctx.root, localDir)} \u8BFB\u4E0D\u4E86\uFF0C\u81EA\u5199\u6280\u80FD\u6570\u4E0D\u51FA\u6765\uFF1B${unreadableFix(error.code, error.detail)}\u540E\u91CD\u67E5`, {
16489
+ note: `${error.where}\uFF1A${error.detail}`
16490
+ });
16491
+ }
16492
+ const localNote = local.length > 0 ? `\uFF1B${path15.relative(ctx.root, localDir)}/ \u53E6\u6709 ${local.length} \u4EFD\u81EA\u5199\u6280\u80FD\uFF08\u4E0D\u8FDB\u9501\u6587\u4EF6\uFF0Csync \u4E0D\u7BA1\u5B83\u4EEC\uFF09` : "";
16421
16493
  const target = ctx.environments.find((e) => e.report.target);
16422
16494
  if (states.some((s) => s.state.endpoint && normalizeOrigin6(s.state.endpoint) !== normalizeOrigin6(target.config.endpoint)))
16423
16495
  return found("SKILLS_ENDPOINT_MISMATCH", void 0, { value: count });
16424
16496
  if (count === 0) {
16425
16497
  const legacy = await read(path15.join(ctx.root, "hcm-skills"));
16426
- return found(legacy && Object.keys(legacy.skills).length > 0 ? "SKILLS_LEGACY_LAYOUT" : "SKILLS_EMPTY", void 0, { value: count, evidence: "ABSENT" });
16498
+ if (legacy && Object.keys(legacy.skills).length > 0) return found("SKILLS_LEGACY_LAYOUT", void 0, { value: count, evidence: "ABSENT" });
16499
+ if (local.length > 0) {
16500
+ return pass(
16501
+ `0 \u4E2A\u4EA7\u54C1\u6280\u80FD\uFF08hcm-skills/sync/ \u4E0E .claude/skills/ \u90FD\u6CA1\u6709\u9501\u6587\u4EF6\uFF09${localNote}\uFF1B\u8981\u88C5\u4EA7\u54C1\u6280\u80FD\u518D\u8DD1 sync`,
16502
+ { value: local.length }
16503
+ );
16504
+ }
16505
+ return found("SKILLS_EMPTY", void 0, { value: count, evidence: "ABSENT" });
16427
16506
  }
16428
16507
  if (states.length === 2 && keys(states[0]).length > 0 && keys(states[1]).length > 0 && keys(states[0]).sort().join("\0") !== keys(states[1]).sort().join("\0"))
16429
16508
  return found("SKILLS_SPLIT_LAYOUT", void 0, { value: count });
16430
- return pass(`${count} \u4E2A\u6280\u80FD\uFF08\u4E24\u4EFD\u9501\u6587\u4EF6 skills \u952E\u7684\u5E76\u96C6\uFF09\uFF1B${states.map((s) => path15.relative(ctx.root, s.baseDir)).join("\u3001")}`, { value: count });
16509
+ return pass(
16510
+ `${count} \u4E2A\u4EA7\u54C1\u6280\u80FD\uFF08\u4E24\u4EFD\u9501\u6587\u4EF6 skills \u952E\u7684\u5E76\u96C6\uFF09\uFF1B${states.map((s) => path15.relative(ctx.root, s.baseDir)).join("\u3001")}${localNote}`,
16511
+ { value: count + local.length }
16512
+ );
16431
16513
  } catch (error) {
16432
16514
  return unknown("SKILLS_STATE_UNREADABLE", void 0, {
16433
16515
  note: `${reading}\uFF1A${safeError(error)}\uFF1B\u5148\u4FEE\u590D\u9501\u6587\u4EF6 JSON \u6216\u8BFB\u53D6\u6743\u9650\uFF08\u53EF\u4ECE\u5907\u4EFD\u6062\u590D\uFF09\uFF0C\u518D\u6309\u4E0B\u4E00\u6B65\u540C\u6B65\u5E76\u91CD\u8DD1\u4F53\u68C0`
@@ -17112,7 +17194,7 @@ var CODE_TABLE = {
17112
17194
  CLI_LATEST_UNKNOWN: c("\u53D6\u4E0D\u5230 npm \u6700\u65B0\u7248\u672C\uFF1B\u68C0\u67E5 registry \u7F51\u7EDC\u540E\u91CD\u8BD5"),
17113
17195
  CLI_VERSION_UNPARSEABLE: c("\u7248\u672C\u53F7\u4E0D\u662F X.Y.Z\uFF0C\u6BD4\u4E0D\u4E86\u65B0\u65E7\uFF1B\u5BF9\u7167 hcm --version \u4E0E npm view @hcmai/cli version --registry https://registry.npmjs.org \u7684\u539F\u6837\u8F93\u51FA\uFF0C\u91CD\u88C5\u672C\u673A CLI \u6216\u62A5\u7ED9 CLI \u7EF4\u62A4\u65B9\u540E\u91CD\u67E5"),
17114
17196
  SKILLS_STATE_UNREADABLE: c("\u6280\u80FD\u9501\u6587\u4EF6\u65E0\u6CD5\u8BFB\u53D6\uFF1B\u4FEE\u590D\u6587\u4EF6\u540E\u540C\u6B65\u91CD\u67E5", "WARN", "FDE", both),
17115
- SKILLS_EMPTY: c("\u4E24\u79CD\u5E03\u5C40\u4E0B\u6280\u80FD\u5747\u4E3A\u7A7A", "CRITICAL", "FDE", both),
17197
+ SKILLS_EMPTY: c("\u4E24\u79CD\u5E03\u5C40\u7684\u9501\u6587\u4EF6\u4E0E hcm-skills/local/ \u90FD\u6CA1\u6709\u6280\u80FD", "CRITICAL", "FDE", both),
17116
17198
  SKILLS_LEGACY_LAYOUT: c("\u4EC5\u6709\u65E7\u6241\u5E73\u5E03\u5C40\u7684\u6280\u80FD", "WARN", "FDE", (e) => sync(e, "codex")),
17117
17199
  SKILLS_SPLIT_LAYOUT: c("\u4E24\u79CD\u5E03\u5C40\u7684\u6280\u80FD\u96C6\u5408\u4E0D\u540C", "WARN", "FDE", both),
17118
17200
  SKILLS_ENDPOINT_MISMATCH: c("\u6280\u80FD\u9501\u6587\u4EF6\u7684 endpoint \u4E0E\u76EE\u6807\u4E0D\u7B26", "CRITICAL", "FDE", both),
@@ -17200,7 +17282,7 @@ var CHECKS = [
17200
17282
  descriptor("local.project.env", "\u9879\u76EE\u73AF\u5883", [], ["ENV_FILE_MISSING", "ENV_FILE_INVALID", "ENV_NOT_RESOLVED"], 5e3, localChecks.project),
17201
17283
  descriptor("local.credential", "\u672C\u673A\u51ED\u636E\u69FD", ["local.project.env"], ["CREDENTIAL_MISSING"], 5e3, localChecks.credential),
17202
17284
  descriptor("local.cli.version", "CLI \u7248\u672C", [], ["CLI_OUTDATED", "CLI_LATEST_UNKNOWN", "CLI_VERSION_UNPARSEABLE"], 1e4, localChecks.version),
17203
- descriptor("local.skills.installed", "\u6280\u80FD", ["local.project.env"], ["SKILLS_STATE_UNREADABLE", "SKILLS_EMPTY", "SKILLS_LEGACY_LAYOUT", "SKILLS_SPLIT_LAYOUT", "SKILLS_ENDPOINT_MISMATCH"], 5e3, localChecks.installed),
17285
+ descriptor("local.skills.installed", "\u6280\u80FD", ["local.project.env"], ["SKILLS_STATE_UNREADABLE", "SKILLS_EMPTY", "SKILLS_LEGACY_LAYOUT", "SKILLS_SPLIT_LAYOUT", "SKILLS_ENDPOINT_MISMATCH", "SKILLS_LOCAL_UNREADABLE"], 5e3, localChecks.installed),
17204
17286
  descriptor("local.skills.fresh", "\u6280\u80FD\u65B0\u9C9C\u5EA6", ["local.skills.installed"], ["SKILLS_STALE", "SKILLS_LOCALLY_MODIFIED", "SKILLS_CATALOG_UNCHECKED", "SKILLS_CATALOG_UNAVAILABLE"], 1e4, localChecks.fresh),
17205
17287
  descriptor("local.skills.shadow", "\u672C\u5730\u906E\u853D", [], ["SKILLS_LOCAL_SHADOW", "SKILLS_LOCAL_UNREADABLE"], 5e3, localChecks.shadow),
17206
17288
  descriptor("local.boundary", "\u9879\u76EE\u8FB9\u754C", [], ["BOUNDARY_MISSING", "BOUNDARY_FALLBACK"], 5e3, localChecks.boundary),
@@ -17997,7 +18079,7 @@ var localCriterion = {
17997
18079
  "local.project.env": "env.yaml \u5B58\u5728\u3001\u53EF\u89E3\u6790\uFF0C\u76EE\u6807\u73AF\u5883\u80FD\u89E3\u6790\u5230\u9879\u76EE\u73AF\u5883",
17998
18080
  "local.credential": "\u6BCF\u4E2A\u9879\u76EE\u73AF\u5883\u6709\u5339\u914D endpoint \u4E0E\u79DF\u6237\u7684\u672C\u673A\u51ED\u636E\u69FD",
17999
18081
  "local.cli.version": "\u4E0E npm \u6700\u65B0 CLI \u7248\u672C\u6BD4\u8F83",
18000
- "local.skills.installed": "\u4E24\u79CD\u5E03\u5C40\u7684\u6280\u80FD\u5E76\u96C6\u3001\u9501\u6587\u4EF6\u4E0E\u76EE\u6807\u73AF\u5883\u4E00\u81F4",
18082
+ "local.skills.installed": "\u4E24\u79CD\u5E03\u5C40\u7684\u9501\u6587\u4EF6\u5E76\u96C6\u52A0 hcm-skills/local/ \u81EA\u5199\u6280\u80FD\u3001\u9501\u6587\u4EF6\u4E0E\u76EE\u6807\u73AF\u5883\u4E00\u81F4",
18001
18083
  "local.skills.fresh": "\u672C\u673A\u6280\u80FD\u4E0E\u76EE\u6807\u73AF\u5883\u7684\u4EA7\u54C1\u6280\u80FD\u76EE\u5F55\u5BF9\u8D26",
18002
18084
  "local.skills.shadow": "hcm-skills/local/ \u91CC\u4E0E hcm-skills/sync/ \u540C id \u7684\u6280\u80FD\uFF08\u540C\u540D\u65F6\u751F\u6548\u7684\u662F local/\uFF0C\u4EA7\u54C1\u7248\u88AB\u538B\u4F4F\uFF09\uFF1B\u6709\u5C31 WARN \u5E76\u5217\u51FA id \u4E0E local \u90A3\u4EFD\u7684\u9996\u884C\u8BF4\u660E\u3002local/ \u8BFB\u4E0D\u4E86\u3001\u6216 sync/ \u91CC\u4E0E local/ \u540C id \u7684\u90A3\u4EFD\u8BFB\u4E0D\u4E86\uFF0C\u5224 UNDETERMINED\uFF1Bsync/ \u91CC\u4E0E local/ \u65E0\u5173\u7684\u6761\u76EE\u8BFB\u4E0D\u4E86\u4E0D\u6321\u7ED3\u8BBA\uFF0C\u6458\u8981\u5217\u51FA\u3001note \u5E26\u539F\u59CB\u62A5\u9519\uFF1Bsync/ \u8BFB\u5F97\u4E86\u7684\u4E00\u4EFD\u90FD\u6CA1\u6709\u53C8\u6709\u8BFB\u4E0D\u4E86\u7684\uFF0C\u5224 UNDETERMINED",
18003
18085
  "local.boundary": "\u9879\u76EE\u8FB9\u754C\u5757\u5B58\u5728\uFF0C\u4E14\u4E0D\u662F CLI fallback \u526F\u672C",