@hcmai/cli 0.4.17 → 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
@@ -6178,6 +6178,8 @@ async function tenantBootstrapCommand(args) {
6178
6178
 
6179
6179
  // src/commands/meta.ts
6180
6180
  import { promises as fsp3 } from "fs";
6181
+ import os3 from "os";
6182
+ import nodePath from "path";
6181
6183
  import {
6182
6184
  HcmClient as HcmClient18,
6183
6185
  formatObject as formatObject18,
@@ -6186,6 +6188,11 @@ import {
6186
6188
  getTenantMeta,
6187
6189
  saveTenantMeta,
6188
6190
  deleteTenantMeta,
6191
+ clearMetaCache as clearMetaCache2,
6192
+ validateMetaContent,
6193
+ formatMetaIssues,
6194
+ explainJacksonError,
6195
+ META_SCHEMA_SOURCE_COMMIT,
6189
6196
  CliError as CliError19,
6190
6197
  CliErrorCode as CliErrorCode18
6191
6198
  } from "@hcmai/sdk";
@@ -6233,6 +6240,73 @@ async function metaGetCommand(path12, args) {
6233
6240
  fail5(e, args);
6234
6241
  }
6235
6242
  }
6243
+ var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
6244
+ function parseMetaPath(path12) {
6245
+ const base = path12.split(/[\\/]/).pop() ?? path12;
6246
+ if (!/\.(yml|yaml)$/i.test(base)) return {};
6247
+ const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
6248
+ return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
6249
+ }
6250
+ function connFlags(args) {
6251
+ return (args.env ? ` --env ${args.env}` : "") + (args.as ? ` --as ${args.as}` : "");
6252
+ }
6253
+ function unverifiableReason(e) {
6254
+ const err = e;
6255
+ const st = err.response?.status;
6256
+ if (st === 401 || st === 403) return `\u6743\u9650\u4E0D\u8DB3\uFF08HTTP ${st}\uFF09`;
6257
+ if (st === 404) return "\u63A5\u53E3 404\uFF08\u6A21\u578B\u540D\u5BF9\u4E0D\u4E0A\uFF1F\uFF09";
6258
+ if (st === 429 || st != null && st >= 502) return `\u670D\u52A1\u7AEF\u6682\u65F6\u4E0D\u53EF\u7528\uFF08HTTP ${st}\uFF09`;
6259
+ if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
6260
+ return void 0;
6261
+ }
6262
+ async function verifyAfterWrite(c, path12) {
6263
+ const { model, kind, state } = parseMetaPath(path12);
6264
+ if (!model || !kind) {
6265
+ return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path12} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
6266
+ }
6267
+ try {
6268
+ await clearMetaCache2(c.raw(), model, {});
6269
+ } catch (e) {
6270
+ const err = e;
6271
+ return {
6272
+ status: "unverified",
6273
+ where: `DELETE /api/models/${model}/meta/cache`,
6274
+ why: `\u6E05\u5143\u6570\u636E\u7F13\u5B58\u5931\u8D25\uFF08${err.response?.status ?? err.message ?? "\u672A\u77E5"}\uFF09\uFF1B\u540E\u9762\u90A3\u4E00\u8BFB\u4F1A\u547D\u4E2D\u65E7\u7F13\u5B58\uFF0C\u9A8C\u4E0D\u51FA\u8FD9\u4EFD\u65B0\u7684\u771F\u5047`
6275
+ };
6276
+ }
6277
+ const probes = [];
6278
+ if (PROBEABLE_META_TYPES.has(kind)) {
6279
+ const params = { type: kind };
6280
+ if (state) params.state = state;
6281
+ probes.push({
6282
+ where: `GET /api/models/${model}/meta?type=${kind}${state ? `&state=${state}` : ""}`,
6283
+ run: () => c.raw().get(`/api/models/${model}/meta`, { params })
6284
+ });
6285
+ }
6286
+ probes.push({
6287
+ where: `GET /api/models/${model}/meta`,
6288
+ run: () => c.raw().get(`/api/models/${model}/meta`)
6289
+ });
6290
+ if (kind === "list") {
6291
+ probes.push({
6292
+ where: `GET /api/models/${model}?state=${state ?? "default"}`,
6293
+ run: () => c.raw().get(`/api/models/${model}`, { params: { state: state ?? "default", size: 1 } })
6294
+ });
6295
+ }
6296
+ for (const probe of probes) {
6297
+ try {
6298
+ await probe.run();
6299
+ } catch (e) {
6300
+ const why = unverifiableReason(e);
6301
+ if (why) return { status: "unverified", where: probe.where, why };
6302
+ const err = e;
6303
+ const body = err.response?.data;
6304
+ const raw = typeof body === "string" ? body : JSON.stringify(body ?? err.message ?? String(e));
6305
+ return { status: "broken", where: probe.where, raw };
6306
+ }
6307
+ }
6308
+ return { status: "ok" };
6309
+ }
6236
6310
  async function metaSetCommand(path12, args) {
6237
6311
  try {
6238
6312
  if (!args.file) {
@@ -6248,27 +6322,112 @@ async function metaSetCommand(path12, args) {
6248
6322
  process.stdin.on("end", () => resolve4(buf));
6249
6323
  process.stdin.on("error", reject);
6250
6324
  }) : await fsp3.readFile(args.file, "utf8");
6325
+ if (!args.skipValidate) {
6326
+ const result2 = validateMetaContent(path12, content);
6327
+ if (result2.issues.length > 0) {
6328
+ process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path12}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
6329
+ `);
6330
+ process.stderr.write(formatMetaIssues(result2, " ") + "\n");
6331
+ }
6332
+ if (result2.errors.length > 0) {
6333
+ process.stderr.write(
6334
+ `
6335
+ \u274C \u4E0A\u9762 ${result2.errors.length} \u5904\u7C7B\u578B\u4E0D\u7B26\uFF0C\u5199\u4E0B\u53BB\u670D\u52A1\u7AEF\u4F1A**\u6536\u4E0B\u5E76\u8FD4 200**\uFF0C\u7136\u540E\u5728\u771F\u5B9E\u7528\u6237\u6253\u5F00\u9875\u9762\u65F6\u624D\u70B8\u3002\u5DF2\u62E6\u5728\u5199\u4E4B\u524D\u3002
6336
+ \u786E\u4FE1 schema \u526F\u672C\u65E7\u4E86\uFF08core \u6539\u8FC7\u5951\u7EA6\uFF09\u21D2 \u52A0 --skip-validate \u5F3A\u5199\u3002
6337
+ `
6338
+ );
6339
+ process.exit(1);
6340
+ }
6341
+ }
6251
6342
  if (args.dryRun) {
6252
- process.stdout.write(
6253
- `[dry-run] \u5C06\u5199\u5165 ${path12}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6343
+ const dryFmt = args.output;
6344
+ if (dryFmt === "json" || dryFmt === "yaml") {
6345
+ process.stdout.write(
6346
+ formatObject18(
6347
+ { dryRun: true, path: path12, bytes: Buffer.byteLength(content), content },
6348
+ { format: dryFmt }
6349
+ ) + "\n"
6350
+ );
6351
+ } else {
6352
+ process.stdout.write(
6353
+ `[dry-run] \u5C06\u5199\u5165 ${path12}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
6254
6354
  ---
6255
6355
  ${content}
6256
6356
  `
6257
- );
6357
+ );
6358
+ }
6258
6359
  process.exit(0);
6259
6360
  }
6260
6361
  const c = await client2(args);
6362
+ let backupFile;
6363
+ let backupState = "unknown";
6364
+ let backupWhy;
6365
+ try {
6366
+ const prev = await getTenantMeta(c.raw(), path12);
6367
+ if (!prev || prev.trim() === "") {
6368
+ backupState = "absent";
6369
+ } else {
6370
+ backupFile = nodePath.join(
6371
+ os3.tmpdir(),
6372
+ `hcm-meta-backup-${Date.now()}-${path12.replace(/[\\/]/g, "_")}`
6373
+ );
6374
+ await fsp3.writeFile(backupFile, prev, "utf8");
6375
+ backupState = "saved";
6376
+ }
6377
+ } catch (e) {
6378
+ const err = e;
6379
+ const st = err.response?.status;
6380
+ if (st === 404) {
6381
+ backupState = "absent";
6382
+ } else {
6383
+ backupState = "unknown";
6384
+ backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
6385
+ }
6386
+ }
6261
6387
  const result = await saveTenantMeta(c.raw(), path12, content);
6262
6388
  const fmt = args.output ?? "json";
6263
- if (fmt !== "json") {
6264
- process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path12}
6265
- \u8BB0\u5F97\u6E05\u7F13\u5B58\uFF1Ahcm cache clear-meta <Model>
6389
+ if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path12}
6266
6390
  `);
6391
+ const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
6392
+ \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path12} --file ${backupFile}${connFlags(args)}
6393
+ ` : backupState === "absent" ? ` \u8FD9\u4E00\u5C42\u6B64\u524D\u6CA1\u6709\u8986\u76D6\uFF08\u5DF2\u8BC1\u5B9E\uFF09\uFF0C\u6062\u590D\u5373\u5220\u9664\uFF1Ahcm meta delete ${path12}${connFlags(args)}
6394
+ ` : ` \u26A0\uFE0F \u65E7\u5185\u5BB9**\u6CA1\u5907\u4EFD\u6210**\uFF08${backupWhy ?? "\u539F\u56E0\u672A\u77E5"}\uFF09\u2014\u2014\u65E2\u4E0D\u77E5\u9053\u6B64\u524D\u6709\u6CA1\u6709\u8986\u76D6\uFF0C\u4E5F\u5C31\u7ED9\u4E0D\u51FA\u6062\u590D\u547D\u4EE4\u3002
6395
+ \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path12}${connFlags(args)}
6396
+ `;
6397
+ if (args.verify === false) {
6398
+ process.stderr.write(
6399
+ "\u26A0\uFE0F --no-verify\uFF1A**\u6CA1\u6709**\u9A8C\u8FC7\u670D\u52A1\u7AEF\u8BFB\u4E0D\u8BFB\u5F97\u52A8\u8FD9\u4EFD meta\u3002\u300C\u5199\u5165\u6210\u529F\u300D\u53EA\u8BF4\u660E\u5B57\u8282\u6536\u4E0B\u4E86\u3002\n \u81EA\u5DF1\u8865\uFF1Ahcm cache clear-meta <Model> \u540E\u6253\u5F00\u9875\u9762\u770B\u4E00\u773C\u3002\n" + restoreHint
6400
+ );
6401
+ } else {
6402
+ const outcome = await verifyAfterWrite(c, path12);
6403
+ if (outcome.status === "broken") {
6404
+ const human = explainJacksonError(outcome.raw);
6405
+ process.stderr.write(
6406
+ `
6407
+ \u{1F534} \u5199\u8FDB\u53BB\u4E86\uFF0C\u4F46**\u670D\u52A1\u7AEF\u8BFB\u4E0D\u52A8** \u2014\u2014 \u9875\u9762\u73B0\u5728\u662F\u574F\u7684\u3002
6408
+ \u63A2\u9488\uFF1A${outcome.where}
6409
+ ` + (human ? `${human.split("\n").map((l) => " " + l).join("\n")}
6410
+ ` : "") + ` \u670D\u52A1\u7AEF\u539F\u8BDD\uFF1A${outcome.raw.slice(0, 600)}
6411
+ ` + restoreHint
6412
+ );
6413
+ process.exit(1);
6414
+ }
6415
+ if (outcome.status === "unverified") {
6416
+ process.stderr.write(
6417
+ `
6418
+ \u26A0\uFE0F \u5199\u8FDB\u53BB\u4E86\uFF0C\u4F46**\u6CA1\u9A8C\u6210**\uFF1A${outcome.why}
6419
+ \u63A2\u9488\uFF1A${outcome.where}
6420
+ \u4E5F\u5C31\u662F\u8BF4\uFF0C\u670D\u52A1\u7AEF\u8BFB\u4E0D\u8BFB\u5F97\u52A8\u8FD9\u4EFD meta\uFF0C\u672C\u6B21\u547D\u4EE4**\u4E0D\u77E5\u9053**\u3002
6421
+ ` + restoreHint
6422
+ );
6423
+ } else if (fmt !== "json") {
6424
+ process.stdout.write(" \u5DF2\u6E05\u5143\u6570\u636E\u7F13\u5B58\uFF0C\u5E76\u771F\u8BFB\u4E86\u4E00\u904D\uFF1A\u670D\u52A1\u7AEF\u8BFB\u5F97\u52A8 \u2714\n");
6425
+ }
6267
6426
  }
6268
6427
  process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
6269
6428
  process.exit(0);
6270
6429
  } catch (e) {
6271
- if (e?.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6430
+ if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6272
6431
  fail5(e, args);
6273
6432
  }
6274
6433
  }
@@ -6292,6 +6451,52 @@ async function metaDeleteCommand(path12, args) {
6292
6451
  fail5(e, args);
6293
6452
  }
6294
6453
  }
6454
+ async function metaValidateCommand(path12, args) {
6455
+ try {
6456
+ if (!args.file) {
6457
+ throw new CliError19({
6458
+ code: CliErrorCode18.MISSING_FLAG,
6459
+ message: "--file <path> \u5FC5\u586B\uFF08\u8981\u9A8C\u7684\u90A3\u4EFD\u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
6460
+ });
6461
+ }
6462
+ const content = args.file === "-" ? await new Promise((resolve4, reject) => {
6463
+ let buf = "";
6464
+ process.stdin.setEncoding("utf8");
6465
+ process.stdin.on("data", (d) => buf += d);
6466
+ process.stdin.on("end", () => resolve4(buf));
6467
+ process.stdin.on("error", reject);
6468
+ }) : await fsp3.readFile(args.file, "utf8");
6469
+ const result = validateMetaContent(path12, content);
6470
+ const fmt = args.output ?? "table";
6471
+ if (fmt === "json" || fmt === "yaml") {
6472
+ process.stdout.write(
6473
+ formatObject18(
6474
+ {
6475
+ path: path12,
6476
+ kind: result.kind,
6477
+ schemaKnown: result.schemaKnown,
6478
+ schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
6479
+ errorCount: result.errors.length,
6480
+ issues: result.issues
6481
+ },
6482
+ { format: fmt }
6483
+ ) + "\n"
6484
+ );
6485
+ } else {
6486
+ process.stdout.write(
6487
+ `\u{1F50E} ${path12}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
6488
+ `
6489
+ );
6490
+ process.stdout.write(
6491
+ result.issues.length === 0 ? " \u6CA1\u6709\u53D1\u73B0\u95EE\u9898\u3002\n" : formatMetaIssues(result, " ") + "\n"
6492
+ );
6493
+ }
6494
+ process.exit(result.errors.length > 0 ? 1 : 0);
6495
+ } catch (e) {
6496
+ if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
6497
+ fail5(e, args);
6498
+ }
6499
+ }
6295
6500
 
6296
6501
  // src/commands/workspace.ts
6297
6502
  init_exit();
@@ -7734,6 +7939,7 @@ import { existsSync as existsSync2, readFileSync as readFileSync5 } from "fs";
7734
7939
  import { join as pathJoin } from "path";
7735
7940
  import {
7736
7941
  HcmClient as HcmClient20,
7942
+ classifyEffect,
7737
7943
  formatObject as formatObject20
7738
7944
  } from "@hcmai/sdk";
7739
7945
 
@@ -7784,8 +7990,31 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
7784
7990
  // 「该 R2 命令不在首批受控执行器支持面」拦死,一个写请求都没发出去。
7785
7991
  "import-write"
7786
7992
  ]);
7993
+ function normalizeAssessedArgv(inputArgv) {
7994
+ let rest = inputArgv;
7995
+ const dropSeparators = () => {
7996
+ let start = 0;
7997
+ while (rest[start] === "--") start += 1;
7998
+ rest = start > 0 ? rest.slice(start) : rest;
7999
+ };
8000
+ dropSeparators();
8001
+ if (PACKAGE_RUNNERS.has(rest[0] ?? "") && isCliLauncher(rest[1])) {
8002
+ rest = rest.slice(2);
8003
+ } else if (isCliLauncher(rest[0])) {
8004
+ rest = rest.slice(1);
8005
+ }
8006
+ dropSeparators();
8007
+ return rest === inputArgv ? [...inputArgv] : rest;
8008
+ }
8009
+ var PACKAGE_RUNNERS = /* @__PURE__ */ new Set(["npx", "bunx", "pnpx"]);
8010
+ function isCliLauncher(token) {
8011
+ if (!token || token.startsWith("-")) return false;
8012
+ if (token === "@hcmai/cli") return true;
8013
+ const base = token.split(/[\\/]/).pop() ?? token;
8014
+ return base === "hcm" || base === "hcm.js" || base === "hcmai";
8015
+ }
7787
8016
  function assessDeliveryCommand(inputArgv, options = {}) {
7788
- const argv = inputArgv[0] === "--" ? inputArgv.slice(1) : [...inputArgv];
8017
+ const argv = normalizeAssessedArgv(inputArgv);
7789
8018
  const commandSha256 = sha2564(JSON.stringify(argv));
7790
8019
  const name = argv[0] ?? "";
7791
8020
  const subcommand = argv[1] && !argv[1].startsWith("-") ? argv[1] : void 0;
@@ -8068,8 +8297,35 @@ function classifyAction(policy) {
8068
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"
8069
8298
  };
8070
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
+ }
8071
8318
  return guarded("tenant-write", "action-write");
8072
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
+ }
8073
8329
  function forbidden(reasonCode, reason) {
8074
8330
  return { risk: "R3", execution: "forbidden", effect: reasonCode, reasonCode, reason };
8075
8331
  }
@@ -8180,7 +8436,7 @@ async function resolveCoreAction(request) {
8180
8436
  profile: request.profile
8181
8437
  });
8182
8438
  const description = await HcmClient20.fromAuthContext(auth).describe(request.model);
8183
- const named = description.actions.filter((action2) => action2.name === request.action);
8439
+ const named = description.actions.filter((action) => action.name === request.action);
8184
8440
  if (named.length === 0) {
8185
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`;
8186
8442
  return failed(
@@ -8188,7 +8444,7 @@ async function resolveCoreAction(request) {
8188
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`
8189
8445
  );
8190
8446
  }
8191
- const matches = request.explicitShape ? named.filter((action2) => matchesRequest(action2, request)) : named;
8447
+ const matches = request.explicitShape ? named.filter((action) => matchesRequest(action, request)) : named;
8192
8448
  if (matches.length === 0) {
8193
8449
  const shapes = named.map((a) => `scope=${a.scope ?? "?"} method=${(a.httpMethod ?? "?").toUpperCase()}`).join("\uFF1B");
8194
8450
  return failed(
@@ -8202,22 +8458,7 @@ async function resolveCoreAction(request) {
8202
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`
8203
8459
  );
8204
8460
  }
8205
- const action = matches[0];
8206
- if (typeof action.readOnly !== "boolean") {
8207
- return failed(
8208
- "action-readonly-unclassified",
8209
- "Core \u672A\u8FD4\u56DE Action \u7684 readOnly \u58F0\u660E\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
8210
- );
8211
- }
8212
- return {
8213
- status: "resolved",
8214
- policy: {
8215
- scope: action.scope ?? request.scope,
8216
- httpMethod: (action.httpMethod ?? request.httpMethod).toUpperCase(),
8217
- readOnly: action.readOnly,
8218
- ...action.source ? { source: action.source } : {}
8219
- }
8220
- };
8461
+ return policyFromActionMeta(matches[0], request);
8221
8462
  } catch {
8222
8463
  return failed(
8223
8464
  "action-metadata-unavailable",
@@ -8225,6 +8466,32 @@ async function resolveCoreAction(request) {
8225
8466
  );
8226
8467
  }
8227
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
+ }
8228
8495
  function matchesRequest(action, request) {
8229
8496
  return action.name === request.action && action.httpMethod?.toUpperCase() === request.httpMethod && action.scope?.toLowerCase() === request.scope;
8230
8497
  }
@@ -9729,9 +9996,7 @@ var IMPLICIT_DIR_COMMANDS = { "workspace push": "." };
9729
9996
  var TOOLING_DIRS = [".git", "node_modules", ".hcm-delivery", "evidence"];
9730
9997
  var POSITIONAL_PAYLOAD_COMMANDS = { import: 1 };
9731
9998
  function normalizeCommandArgv(argv) {
9732
- let start = 0;
9733
- while (argv[start] === "--") start += 1;
9734
- return argv.slice(start);
9999
+ return normalizeAssessedArgv(argv);
9735
10000
  }
9736
10001
  async function bindPayloadFiles(project, argv) {
9737
10002
  const bound = [];
@@ -10287,7 +10552,8 @@ tenant.command("bootstrap").description("\u5F00\u901A\u65B0\u79DF\u6237\uFF08\u5
10287
10552
  var meta = program.command("meta").description("\u79DF\u6237\u5143\u6570\u636E\u8BFB\u5199\uFF08\u9875\u9762/\u5B57\u6BB5/\u5217\u8868\u914D\u7F6E\uFF09");
10288
10553
  meta.command("list").description("\u5217\u51FA\u79DF\u6237\u5143\u6570\u636E\u6587\u4EF6").option("--keyword <kw>", "\u641C\u7D22\u5173\u952E\u8BCD").option("--type <type>", "\u7C7B\u578B\uFF1Ayml | properties | all", "all").option("--page <n>", "\u9875\u7801\uFF08\u4ECE 0 \u5F00\u59CB\uFF09").option("--page-size <n>", "\u6BCF\u9875\u6761\u6570").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => metaListCommand(opts));
10289
10554
  meta.command("get <path>").description("\u6253\u5370 meta \u539F\u6587\uFF08\u5982 metas/Employee.list.yml\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").action((p, opts) => metaGetCommand(p, opts));
10290
- meta.command("set <path>").description("\u5199\u5165 meta \u539F\u6587\uFF1B\u5199\u5B8C\u987B hcm cache clear-meta <Model> \u624D\u751F\u6548").requiredOption("--file <file>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6\u539F\u6587\uFF08- \u8868\u793A stdin\uFF09").option("--dry-run", "\u53EA\u663E\u793A\u5C06\u5199\u5165\u7684\u5185\u5BB9\uFF0C\u4E0D\u5B9E\u9645\u5199\u5165").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((p, opts) => metaSetCommand(p, opts));
10555
+ meta.command("set <path>").description("\u5199\u5165 meta \u539F\u6587\uFF1A\u5199\u524D\u6309 schema \u9A8C\u7C7B\u578B \u2192 \u5199\u5165 \u2192 \u6E05\u7F13\u5B58\u540E\u771F\u8BFB\u4E00\u904D\uFF08\u8BFB\u4E0D\u52A8\u5C31\u62A5\u5E76\u7ED9\u6062\u590D\u547D\u4EE4\uFF09").requiredOption("--file <file>", "\u4ECE\u6587\u4EF6\u8BFB\u53D6\u539F\u6587\uFF08- \u8868\u793A stdin\uFF09").option("--dry-run", "\u53EA\u663E\u793A\u5C06\u5199\u5165\u7684\u5185\u5BB9\uFF0C\u4E0D\u5B9E\u9645\u5199\u5165").option("--skip-validate", "\u8DF3\u8FC7\u5199\u524D schema \u7C7B\u578B\u6821\u9A8C\uFF08schema \u526F\u672C\u65E7\u4E86\u65F6\u7684\u9003\u751F\u95E8\uFF09").option("--no-verify", "\u4E0D\u505A\u5199\u540E\u81EA\u8BC1\u3002\u26A0\uFE0F \u300C\u5199\u5165\u6210\u529F\u300D\u53EA\u8BF4\u660E\u5B57\u8282\u6536\u4E0B\u4E86\uFF0C\u4E0D\u8BF4\u660E\u670D\u52A1\u7AEF\u8BFB\u5F97\u52A8").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((p, opts) => metaSetCommand(p, opts));
10556
+ meta.command("validate <path>").description("\u96F6\u7F51\u7EDC\uFF1A\u6309 core \u4ED3\u7684 JSON Schema \u9A8C\u4E00\u4EFD meta \u539F\u6587\uFF08path \u53EA\u7528\u6765\u6311 schema\uFF0C\u4E0D\u53D1\u8BF7\u6C42\uFF09").requiredOption("--file <file>", "\u8981\u9A8C\u7684\u539F\u6587\uFF08- \u8868\u793A stdin\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((p, opts) => metaValidateCommand(p, opts));
10291
10557
  meta.command("delete <path>").description("\u5220\u9664 meta\uFF08\u4E0D\u53EF\u9006\uFF0C\u9ED8\u8BA4\u8FC7\u786E\u8BA4\u95F8\uFF09").option("-y, --yes", "\u8DF3\u8FC7\u786E\u8BA4").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((p, opts) => metaDeleteCommand(p, opts));
10292
10558
  var skills = program.command("skills").description("\u4EA4\u4ED8\u6280\u80FD\uFF1A\u777F\u620E Chiron \u6280\u80FD\u5E93 + CLI \u81EA\u5E26\u6280\u80FD\uFF08\u514D\u8BA4\u8BC1\uFF0C\u65E0\u9700\u5148 login\uFF09");
10293
10559
  skills.command("list [keyword]").description("\u5217\u51FA\u76EE\u6807\u73AF\u5883\u8FD9\u4E00\u7248\u7684\u4EA4\u4ED8\u6280\u80FD\uFF1B--installed \u6539\u770B\u672C\u5730\u88C5\u4E86\u54EA\u4E9B\uFF08\u4E0D\u8FDE\u7F51\uFF09").option("--installed", "\u53EA\u770B\u672C\u5730\u5DF2\u88C5\u7684\u6280\u80FD\uFF08\u8BFB .hcm-skills.json\uFF0C\u4E0D\u8FDE\u7F51\uFF09").option("--target <agent>", "\u914D\u5408 --installed\uFF1Aclaude | codex | auto", "auto").option("--global", "\u914D\u5408 --installed\uFF1A\u770B\u7528\u6237\u7EA7\u76EE\u5F55").option("--dir <path>", "\u914D\u5408 --installed\uFF1A\u770B\u6307\u5B9A\u76EE\u5F55").option("--category <key>", "\u53EA\u770B\u67D0\u4E2A\u5206\u7C7B").option("--stage <key>", "\u53EA\u770B\u67D0\u4E2A\u4EA4\u4ED8\u9636\u6BB5\uFF1Ahandover | baseline | configure | migrate | integrate | golive | operate").option("--by-stage", "\u6309\u4EA4\u4ED8\u751F\u547D\u5468\u671F\u5206\u7EC4\u5C55\u793A\uFF08\u9ED8\u8BA4\u6309\u529F\u80FD\u5206\u7C7B\uFF09").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((kw, opts) => skillsListCommand(kw, opts));