@hcmai/cli 0.4.8 → 0.4.9

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
@@ -7528,16 +7528,20 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
7528
7528
  "setting-write",
7529
7529
  "credential-reset",
7530
7530
  "action-write",
7531
- // workspace 侧只收**输入可完整绑进计划**的那两个:它们的入参是 workspace key,
7532
- // 没有外部载荷文件。
7533
- //
7534
- // 🔴 刻意不收 workspace-push / metadata-write / workspace-local-change:
7535
- // push 读的是整个本地目录、meta set 读 --file 指向的任意文件,而载荷绑定只覆盖
7536
- // --data-file / --params-file(PAYLOAD_FILE_FLAGS)。绑不住就意味着「批准时看到的内容」
7537
- // 与「执行时实际读到的内容」可以不同 —— 那正是受控执行要挡住的东西。
7538
- // 要收它们,得先把目录/文件载荷也纳入绑定与 assertPayloadsUnchanged。
7539
7531
  "workspace-create",
7540
- "workspace-activate"
7532
+ "workspace-activate",
7533
+ // 这两个的载荷是**任意文件 / 整棵目录**,此前刻意不收——绑不住就意味着
7534
+ // 「批准时看到的内容」与「执行时实际读到的内容」可以不同。
7535
+ //
7536
+ // 现在绑得住了:PAYLOAD_FILE_FLAGS 收了 --file,PAYLOAD_DIR_FLAGS 收了 --dir
7537
+ // (workspace push 不传 --dir 时按其 option 默认值 '.' 隐式绑定),
7538
+ // 目录按「路径 + 内容、排序稳定」整树摘要,assertPayloadsUnchanged 执行前逐一重算比对。
7539
+ //
7540
+ // 🔴 二次开发的整条链就卡在这两个上:2026-09-01 轨道 A 第四轮验收,
7541
+ // 受控执行第一次跑通了 workspace create,却在 meta set / workspace push 上
7542
+ // 被「该 R2 命令不在首批受控执行器支持面」拦死,远端只多了一个空 workspace。
7543
+ "metadata-write",
7544
+ "workspace-push"
7541
7545
  ]);
7542
7546
  function assessDeliveryCommand(inputArgv, options = {}) {
7543
7547
  const argv = inputArgv[0] === "--" ? inputArgv.slice(1) : [...inputArgv];
@@ -9370,7 +9374,9 @@ function requireExactlyOnePayload(argv, command) {
9370
9374
  throw invalid2(`${command} \u5FC5\u987B\u5305\u542B --data <JSON> \u6216 --data-file <\u6587\u4EF6>`);
9371
9375
  }
9372
9376
  }
9373
- var PAYLOAD_FILE_FLAGS = ["--data-file", "--params-file"];
9377
+ var PAYLOAD_FILE_FLAGS = ["--data-file", "--params-file", "--file"];
9378
+ var PAYLOAD_DIR_FLAGS = ["--dir"];
9379
+ var IMPLICIT_DIR_COMMANDS = { "workspace push": "." };
9374
9380
  async function bindPayloadFiles(project, argv) {
9375
9381
  const bound = [];
9376
9382
  for (const flag of PAYLOAD_FILE_FLAGS) {
@@ -9378,8 +9384,48 @@ async function bindPayloadFiles(project, argv) {
9378
9384
  if (reference === void 0) continue;
9379
9385
  bound.push(await bindPayloadFile(project, reference, `${flag} \u8F7D\u8377`));
9380
9386
  }
9387
+ for (const flag of PAYLOAD_DIR_FLAGS) {
9388
+ const reference = optionalFlagValue(argv, flag);
9389
+ if (reference === void 0) continue;
9390
+ bound.push(await bindPayloadDirectory(project, reference, `${flag} \u76EE\u5F55\u8F7D\u8377`));
9391
+ }
9392
+ const implicit = IMPLICIT_DIR_COMMANDS[`${argv[0]} ${argv[1]}`];
9393
+ if (implicit !== void 0 && optionalFlagValue(argv, "--dir") === void 0) {
9394
+ bound.push(await bindPayloadDirectory(project, implicit, "\u5DE5\u4F5C\u7A7A\u95F4\u76EE\u5F55\u8F7D\u8377"));
9395
+ }
9381
9396
  return bound;
9382
9397
  }
9398
+ async function bindPayloadDirectory(project, reference, label) {
9399
+ const relative2 = reference === "." ? "." : safeRelative(reference, label);
9400
+ const root = path11.join(project, relative2);
9401
+ let stat;
9402
+ try {
9403
+ stat = await fs7.stat(root);
9404
+ } catch {
9405
+ throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
9406
+ }
9407
+ if (!stat.isDirectory()) {
9408
+ throw invalid2(`${label}\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
9409
+ }
9410
+ const entries = [];
9411
+ const walk = async (dir, prefix) => {
9412
+ const items = await fs7.readdir(dir, { withFileTypes: true });
9413
+ for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
9414
+ if ([".git", "node_modules", ".hcm-delivery", "evidence"].includes(item.name)) continue;
9415
+ const child = path11.join(dir, item.name);
9416
+ const rel = prefix ? `${prefix}/${item.name}` : item.name;
9417
+ if (item.isDirectory()) {
9418
+ await walk(child, rel);
9419
+ } else if (item.isFile()) {
9420
+ const bytes = await readSafeFile(project, child, `${label} ${rel}`);
9421
+ entries.push(`${rel}
9422
+ ${sha2565(bytes)}`);
9423
+ }
9424
+ }
9425
+ };
9426
+ await walk(root, "");
9427
+ return { path: relative2, sha256: sha2565(Buffer.from(entries.join("\n"), "utf8")) };
9428
+ }
9383
9429
  async function bindPayloadFile(project, reference, label) {
9384
9430
  const relative2 = safeRelative(reference, label);
9385
9431
  const file = path11.join(project, relative2);
@@ -9388,9 +9434,17 @@ async function bindPayloadFile(project, reference, label) {
9388
9434
  }
9389
9435
  async function assertPayloadsUnchanged(project, payloads) {
9390
9436
  for (const payload of payloads) {
9391
- const current = await bindPayloadFile(project, payload.path, `\u8F7D\u8377 ${payload.path}`);
9437
+ let isDirectory = false;
9438
+ try {
9439
+ isDirectory = (await fs7.stat(path11.join(project, payload.path))).isDirectory();
9440
+ } catch {
9441
+ isDirectory = false;
9442
+ }
9443
+ const current = isDirectory ? await bindPayloadDirectory(project, payload.path, `\u8F7D\u8377 ${payload.path}`) : await bindPayloadFile(project, payload.path, `\u8F7D\u8377 ${payload.path}`);
9392
9444
  if (current.sha256 !== payload.sha256) {
9393
- throw invalid2(`\u8F7D\u8377\u6587\u4EF6 ${payload.path} \u7684\u5185\u5BB9\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0 prepare`);
9445
+ throw invalid2(
9446
+ `\u8F7D\u8377${isDirectory ? "\u76EE\u5F55" : "\u6587\u4EF6"} ${payload.path} \u7684\u5185\u5BB9\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0 prepare`
9447
+ );
9394
9448
  }
9395
9449
  }
9396
9450
  }