@hcmai/cli 0.3.13 → 0.3.15

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
@@ -4594,18 +4594,6 @@ async function resolveBundledClosure(targetId, dir = bundledSkillsDir()) {
4594
4594
 
4595
4595
  // src/commands/skills.ts
4596
4596
  var SKILLS_STATE_FILE = ".hcm-skills.json";
4597
- async function sha256File(file) {
4598
- return createHash2("sha256").update(await fsp2.readFile(file)).digest("hex");
4599
- }
4600
- async function currentSkillsRuntimeLaunch() {
4601
- const entry = process.argv[1];
4602
- if (!entry) throw invalid("\u65E0\u6CD5\u89E3\u6790\u5F53\u524D CLI entry");
4603
- return {
4604
- kind: "node-entry",
4605
- executableSha256: await sha256File(process.execPath),
4606
- entrySha256: await sha256File(entry)
4607
- };
4608
- }
4609
4597
  function migrateSkillsState(state) {
4610
4598
  const skills2 = {};
4611
4599
  for (const [id, record] of Object.entries(state.skills ?? {})) {
@@ -5426,7 +5414,6 @@ async function recordInstalled(baseDir, documents, meta2) {
5426
5414
  if (meta2.base !== void 0) state.base = meta2.base;
5427
5415
  if (meta2.all) state.all = true;
5428
5416
  state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
5429
- state.runtime = { launch: await currentSkillsRuntimeLaunch() };
5430
5417
  for (const document of documents) {
5431
5418
  const previous = state.skills[document.id];
5432
5419
  state.skills[document.id] = {
@@ -7669,17 +7656,25 @@ async function resolveCoreAction(request) {
7669
7656
  profile: request.profile
7670
7657
  });
7671
7658
  const description = await HcmClient17.fromAuthContext(auth).describe(request.model);
7672
- const matches = description.actions.filter((action2) => matchesRequest(action2, request));
7673
- if (matches.length === 0) {
7659
+ const named = description.actions.filter((action2) => action2.name === request.action);
7660
+ if (named.length === 0) {
7674
7661
  return failed(
7675
7662
  "action-metadata-not-found",
7676
- "Core \u5143\u6570\u636E\u4E2D\u6CA1\u6709\u4E0E\u672C\u6B21 method/scope \u7CBE\u786E\u5339\u914D\u7684 Action\uFF0C\u62D2\u7EDD\u6267\u884C\u3002"
7663
+ `Core \u5143\u6570\u636E\u91CC\u6CA1\u6709 ${request.model}.${request.action} \u8FD9\u4E2A Action\u3002next_step=\u7528 \`hcm describe ${request.model}\` \u6838\u5BF9 Action \u540D`
7664
+ );
7665
+ }
7666
+ const matches = request.explicitShape ? named.filter((action2) => matchesRequest(action2, request)) : named;
7667
+ if (matches.length === 0) {
7668
+ const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
7669
+ return failed(
7670
+ "action-shape-mismatch",
7671
+ `${request.model}.${request.action} \u5B58\u5728\uFF0C\u4F46\u5F62\u6001\u5BF9\u4E0D\u4E0A\uFF1A\u4F60\u7ED9\u7684\u662F scope=${request.scope} method=${request.httpMethod}\uFF0C\u5143\u6570\u636E\u91CC\u662F ${shapes}\u3002next_step=\u53BB\u6389 --scope/--method \u8BA9 CLI \u6309\u5143\u6570\u636E\u81EA\u52A8\u5224\u5B9A\uFF0C\u6216\u6539\u6210\u4E0A\u9762\u7684\u5F62\u6001`
7677
7672
  );
7678
7673
  }
7679
7674
  if (matches.length > 1) {
7680
7675
  return failed(
7681
7676
  "action-metadata-ambiguous",
7682
- "Core \u5143\u6570\u636E\u5B58\u5728\u591A\u4E2A\u4E0E\u672C\u6B21 method/scope \u5339\u914D\u7684 Action\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\uFF0C\u62D2\u7EDD\u6267\u884C\u3002"
7677
+ `${request.model}.${request.action} \u5728\u5143\u6570\u636E\u91CC\u6709\u591A\u79CD\u5F62\u6001\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u3002next_step=\u7528 --scope \u4E0E --method \u6307\u660E\u8981\u8C03\u54EA\u4E00\u4E2A`
7683
7678
  );
7684
7679
  }
7685
7680
  const action = matches[0];
@@ -7692,8 +7687,8 @@ async function resolveCoreAction(request) {
7692
7687
  return {
7693
7688
  status: "resolved",
7694
7689
  policy: {
7695
- scope: action.scope,
7696
- httpMethod: action.httpMethod.toUpperCase(),
7690
+ scope: action.scope ?? request.scope,
7691
+ httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
7697
7692
  readOnly: action.readOnly,
7698
7693
  ...action.source ? { source: action.source } : {}
7699
7694
  }
@@ -7715,7 +7710,8 @@ function parseActionRequest(inputArgv) {
7715
7710
  if (separator <= 0 || separator === spec.length - 1) {
7716
7711
  return failed("invalid-action-spec", "Action \u5FC5\u987B\u4F7F\u7528 <Model>.<Action> \u683C\u5F0F\u3002");
7717
7712
  }
7718
- const httpMethod = (flagValue2(argv, "--method") ?? "POST").toUpperCase();
7713
+ const explicitMethod = flagValue2(argv, "--method");
7714
+ const httpMethod = (explicitMethod ?? "POST").toUpperCase();
7719
7715
  if (!["GET", "POST", "PUT", "DELETE"].includes(httpMethod)) {
7720
7716
  return failed("invalid-action-method", "Action method \u5FC5\u987B\u662F GET\u3001POST\u3001PUT \u6216 DELETE\u3002");
7721
7717
  }
@@ -7729,6 +7725,7 @@ function parseActionRequest(inputArgv) {
7729
7725
  action: spec.slice(separator + 1),
7730
7726
  httpMethod,
7731
7727
  scope,
7728
+ ...explicitMethod !== void 0 || explicitScope !== void 0 ? { explicitShape: true } : {},
7732
7729
  env: flagValue2(argv, "--env"),
7733
7730
  identity: flagValue2(argv, "--as"),
7734
7731
  profile: flagValue2(argv, "--profile")
@@ -8007,9 +8004,8 @@ async function prepareDeliveryExecution(input) {
8007
8004
  const rollback = await bindDocument(project, input.rollbackRef, "\u56DE\u6EDA\u8BF4\u660E");
8008
8005
  const payloads = await bindPayloadFiles(project, input.argv);
8009
8006
  const evidence = await bindEvidenceDirectory(project, input.evidenceDir);
8010
- const { bytes: lockBytes, runtime: lockedRuntime } = await readSkillsLock(project);
8007
+ const lockBytes = await readSkillsLock(project);
8011
8008
  const runtime = await (input.runtimeIdentity ?? currentRuntimeIdentity)();
8012
- assertRuntimeMatches(runtime, lockedRuntime);
8013
8009
  const created = (input.now ?? (() => /* @__PURE__ */ new Date()))();
8014
8010
  if (Number.isNaN(created.getTime())) throw invalid2("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
8015
8011
  const core = {
@@ -8067,12 +8063,11 @@ async function executeDeliveryPlan(input) {
8067
8063
  if (canonicalJson(assessment) !== canonicalJson(plan.assessment)) {
8068
8064
  throw invalid2("\u5B9E\u9645 argv \u4E0E\u6267\u884C\u8BA1\u5212\u7684\u547D\u4EE4\u6458\u8981\u6216\u98CE\u9669\u4E8B\u5B9E\u4E0D\u4E00\u81F4");
8069
8065
  }
8070
- const { bytes: lockBytes, runtime: lockedRuntime } = await readSkillsLock(project);
8066
+ const lockBytes = await readSkillsLock(project);
8071
8067
  if (sha2565(lockBytes) !== plan.skillsLockSha256) {
8072
8068
  throw invalid2("\u6280\u80FD\u9501\u6458\u8981\u5DF2\u6F02\u79FB\uFF0C\u8BF7\u91CD\u65B0\u8BC4\u4F30\u5E76 prepare");
8073
8069
  }
8074
8070
  const runtime = await (input.runtimeIdentity ?? currentRuntimeIdentity)();
8075
- assertRuntimeMatches(runtime, lockedRuntime);
8076
8071
  if (canonicalJson(runtime) !== canonicalJson(plan.runtime)) {
8077
8072
  throw invalid2("CLI \u8FD0\u884C\u65F6\u6458\u8981\u4E0E\u6267\u884C\u8BA1\u5212\u4E0D\u4E00\u81F4");
8078
8073
  }
@@ -8193,19 +8188,12 @@ async function readSkillsLock(project) {
8193
8188
  );
8194
8189
  }
8195
8190
  const bytes = await readSafeFile(project, path8.join(project, found[0]), "\u6280\u80FD\u9501");
8196
- let parsed;
8197
8191
  try {
8198
- parsed = JSON.parse(bytes.toString("utf8"));
8192
+ JSON.parse(bytes.toString("utf8"));
8199
8193
  } catch (cause) {
8200
8194
  throw invalid2("\u6280\u80FD\u9501\u4E0D\u662F\u5408\u6CD5 JSON", cause);
8201
8195
  }
8202
- const launch = parsed?.runtime?.launch;
8203
- if (!isRuntimeIdentity(launch)) {
8204
- throw invalid2(
8205
- "\u6280\u80FD\u9501\u6CA1\u6709\u8BB0\u5F55 runtime.launch\uFF0C\u65E0\u6CD5\u786E\u8BA4\u300C\u73B0\u5728\u8FD9\u4EFD CLI \u5C31\u662F\u5F53\u521D\u88C5\u6280\u80FD\u7684\u90A3\u4EFD\u300D\u3002next_step=\u7528\u5F53\u524D CLI \u91CD\u8DD1\u4E00\u6B21 `hcm skills install`\uFF08\u6216 `hcm skills update`\uFF09\u5237\u65B0\u6280\u80FD\u9501"
8206
- );
8207
- }
8208
- return { bytes, runtime: launch };
8196
+ return bytes;
8209
8197
  }
8210
8198
  async function bindDocument(project, reference, label) {
8211
8199
  const relative2 = safeRelative(reference, label);
@@ -8383,18 +8371,13 @@ function requireFlagValue(argv, flag, message) {
8383
8371
  }
8384
8372
  throw invalid2(message);
8385
8373
  }
8386
- function assertRuntimeMatches(actual, expected) {
8387
- if (canonicalJson(actual) !== canonicalJson(expected)) {
8388
- throw invalid2("\u5F53\u524D CLI \u8FD0\u884C\u65F6\u6458\u8981\u4E0E\u6280\u80FD\u9501\u4E0D\u4E00\u81F4\u3002next_step=\u7528\u5F53\u524D CLI \u91CD\u8DD1\u4E00\u6B21 `hcm skills install` \u5237\u65B0\u6280\u80FD\u9501\uFF0C\u518D prepare");
8389
- }
8390
- }
8391
8374
  async function currentRuntimeIdentity() {
8392
8375
  const entry = process.argv[1];
8393
8376
  if (!entry) throw invalid2("\u65E0\u6CD5\u89E3\u6790\u5F53\u524D CLI entry");
8394
8377
  return {
8395
8378
  kind: "node-entry",
8396
- executableSha256: await sha256File2(process.execPath),
8397
- entrySha256: await sha256File2(entry)
8379
+ executableSha256: await sha256File(process.execPath),
8380
+ entrySha256: await sha256File(entry)
8398
8381
  };
8399
8382
  }
8400
8383
  async function runCurrentCliCommand(argv, cwd, streams) {
@@ -8533,7 +8516,7 @@ function canonicalJson(value) {
8533
8516
  function sha2565(value) {
8534
8517
  return createHash5("sha256").update(value).digest("hex");
8535
8518
  }
8536
- async function sha256File2(file) {
8519
+ async function sha256File(file) {
8537
8520
  const hash = createHash5("sha256");
8538
8521
  await new Promise((resolve4, reject) => {
8539
8522
  const stream = createReadStream(file);