@hcmai/cli 0.4.18 → 0.4.19

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
@@ -7939,6 +7939,7 @@ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
7939
7939
  import { join as pathJoin } from "path";
7940
7940
  import {
7941
7941
  HcmClient as HcmClient20,
7942
+ classifyEffect,
7942
7943
  formatObject as formatObject20
7943
7944
  } from "@hcmai/sdk";
7944
7945
 
@@ -8296,8 +8297,35 @@ function classifyAction(policy) {
8296
8297
  reason: "Core \u58F0\u660E\u8BE5 Action \u4E3A\u53EA\u8BFB\uFF0C\u4E0E Moirai \u7684\u53EA\u8BFB Action \u8DEF\u5F84\u4E00\u81F4\uFF0C\u53EF\u76F4\u63A5\u6267\u884C\u3002"
8297
8298
  };
8298
8299
  }
8300
+ if (policy.effect === "declared-unknown") {
8301
+ return {
8302
+ risk: "R2",
8303
+ execution: "guarded",
8304
+ effect: "undetermined",
8305
+ reasonCode: "action-effect-undetermined",
8306
+ reason: "\u4EA7\u54C1\u4FA7\u628A\u8FD9\u4E2A Action \u58F0\u660E\u6210 effect=UNKNOWN\uFF1A**\u6CA1\u4EBA\u5224\u8FC7**\u5B83\u5199\u4E0D\u5199\u5E93\u3002\u6309\u6700\u574F\u60C5\u51B5\u8D70\u53D7\u63A7\u6267\u884C\uFF08\u4E0E\u4F1A\u5199\u7684 Action \u540C\u4E00\u6761\u8DEF\u5F84\uFF09\uFF0C\u4F46\u5B83\u4E0D\u7B49\u4E8E\u300C\u786E\u8BA4\u4F1A\u5199\u300D\u3002next_step=\u53BB\u4EA7\u54C1\u4FA7\u7ED9\u8FD9\u4E2A @ClassAction/@ObjectAction \u628A effect \u5224\u6389\uFF08READ_ONLY / WRITES\uFF09\uFF0C\u800C\u4E0D\u662F\u5728 CLI \u8FD9\u8FB9\u653E\u5BBD\u3002"
8307
+ };
8308
+ }
8309
+ if (policy.effect === "unrecognized-effect") {
8310
+ return {
8311
+ risk: "R2",
8312
+ execution: "guarded",
8313
+ effect: "undetermined",
8314
+ reasonCode: "action-effect-unrecognized",
8315
+ reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / UNKNOWN \u4E09\u6001\u5185\uFF08\u62FC\u5199\u6F02\u79FB\uFF1F\u670D\u52A1\u7AEF\u6BD4\u672C CLI \u65B0\u3001\u591A\u4E86\u4E00\u6001\uFF1F\uFF09\u3002fail-closed\uFF1A\u6309 UNKNOWN \u5904\u7F6E\u8D70\u53D7\u63A7\u6267\u884C\uFF0C\u4E0D\u731C\u6210\u53EA\u8BFB\u3002next_step=\u62FF\u8FD9\u4E2A\u539F\u503C\u53BB\u5BF9\u4EA7\u54C1\u4FA7\u7684 ActionEffect \u5B9A\u4E49\uFF0C\u5FC5\u8981\u65F6\u5347\u7EA7 CLI\u3002`
8316
+ };
8317
+ }
8299
8318
  return guarded("tenant-write", "action-write");
8300
8319
  }
8320
+ function describeEffectRaw(raw) {
8321
+ if (raw === null) return "null";
8322
+ if (typeof raw === "string") return JSON.stringify(raw);
8323
+ try {
8324
+ return `${JSON.stringify(raw)}\uFF08${typeof raw}\uFF09`;
8325
+ } catch {
8326
+ return `<\u65E0\u6CD5\u5E8F\u5217\u5316\u7684 ${typeof raw}>`;
8327
+ }
8328
+ }
8301
8329
  function forbidden(reasonCode, reason) {
8302
8330
  return { risk: "R3", execution: "forbidden", effect: reasonCode, reasonCode, reason };
8303
8331
  }
@@ -8408,7 +8436,7 @@ async function resolveCoreAction(request) {
8408
8436
  profile: request.profile
8409
8437
  });
8410
8438
  const description = await HcmClient20.fromAuthContext(auth).describe(request.model);
8411
- const named = description.actions.filter((action2) => action2.name === request.action);
8439
+ const named = description.actions.filter((action) => action.name === request.action);
8412
8440
  if (named.length === 0) {
8413
8441
  const degraded = description.effectiveActionsAvailable ? "" : `\u26A0\uFE0F \u672C\u6B21\u6BD4\u5BF9\u4E0D\u542B\u811A\u672C Action\u2014\u2014${description.effectiveActionsNote ?? "\u539F\u56E0\u672A\u77E5"}\u3002`;
8414
8442
  return failed(
@@ -8416,7 +8444,7 @@ async function resolveCoreAction(request) {
8416
8444
  `Core \u5143\u6570\u636E\u91CC\u6CA1\u6709 ${request.model}.${request.action} \u8FD9\u4E2A Action\u3002${degraded}next_step=\u7528 \`hcm describe ${request.model}\` \u770B\u5B83\u5217\u51FA\u7684 Action \u540D\uFF08\u811A\u672C Action \u4F1A\u6807 [script]\uFF09`
8417
8445
  );
8418
8446
  }
8419
- const matches = request.explicitShape ? named.filter((action2) => matchesRequest(action2, request)) : named;
8447
+ const matches = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
8420
8448
  if (matches.length === 0) {
8421
8449
  const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
8422
8450
  return failed(
@@ -8430,22 +8458,7 @@ async function resolveCoreAction(request) {
8430
8458
  `${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`
8431
8459
  );
8432
8460
  }
8433
- const action = matches[0];
8434
- if (typeof action.readOnly !== "boolean") {
8435
- return failed(
8436
- "action-readonly-unclassified",
8437
- "Core \u672A\u8FD4\u56DE Action \u7684 readOnly \u58F0\u660E\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
8438
- );
8439
- }
8440
- return {
8441
- status: "resolved",
8442
- policy: {
8443
- scope: action.scope ?? request.scope,
8444
- httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
8445
- readOnly: action.readOnly,
8446
- ...action.source ? { source: action.source } : {}
8447
- }
8448
- };
8461
+ return policyFromActionMeta(matches[0], request);
8449
8462
  } catch {
8450
8463
  return failed(
8451
8464
  "action-metadata-unavailable",
@@ -8453,6 +8466,32 @@ async function resolveCoreAction(request) {
8453
8466
  );
8454
8467
  }
8455
8468
  }
8469
+ function policyFromActionMeta(action, request) {
8470
+ const shape = {
8471
+ scope: action.scope ?? request.scope,
8472
+ httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
8473
+ ...action.source ? { source: action.source } : {}
8474
+ };
8475
+ const effectClass = classifyEffect(action.effect);
8476
+ if (effectClass === "absent") {
8477
+ if (typeof action.readOnly !== "boolean") {
8478
+ return failed(
8479
+ "action-readonly-unclassified",
8480
+ "Core \u672A\u8FD4\u56DE Action \u7684 effect \u4E09\u6001\u58F0\u660E\uFF0C\u4E5F\u6CA1\u6709\u56DE\u843D\u7528\u7684 readOnly \u5E03\u5C14\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
8481
+ );
8482
+ }
8483
+ return { status: "resolved", policy: { ...shape, readOnly: action.readOnly } };
8484
+ }
8485
+ return {
8486
+ status: "resolved",
8487
+ policy: {
8488
+ ...shape,
8489
+ effect: effectClass,
8490
+ ...effectClass === "unrecognized-effect" ? { effectRaw: action.effect } : {},
8491
+ readOnly: effectClass === "read-only"
8492
+ }
8493
+ };
8494
+ }
8456
8495
  function matchesRequest(action, request) {
8457
8496
  return action.name === request.action && action.httpMethod?.toUpperCase() === request.httpMethod && action.scope?.toLowerCase() === request.scope;
8458
8497
  }