@hcmai/cli 0.3.12 → 0.3.14

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] = {
@@ -8007,9 +7994,8 @@ async function prepareDeliveryExecution(input) {
8007
7994
  const rollback = await bindDocument(project, input.rollbackRef, "\u56DE\u6EDA\u8BF4\u660E");
8008
7995
  const payloads = await bindPayloadFiles(project, input.argv);
8009
7996
  const evidence = await bindEvidenceDirectory(project, input.evidenceDir);
8010
- const { bytes: lockBytes, runtime: lockedRuntime } = await readSkillsLock(project);
7997
+ const lockBytes = await readSkillsLock(project);
8011
7998
  const runtime = await (input.runtimeIdentity ?? currentRuntimeIdentity)();
8012
- assertRuntimeMatches(runtime, lockedRuntime);
8013
7999
  const created = (input.now ?? (() => /* @__PURE__ */ new Date()))();
8014
8000
  if (Number.isNaN(created.getTime())) throw invalid2("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
8015
8001
  const core = {
@@ -8067,12 +8053,11 @@ async function executeDeliveryPlan(input) {
8067
8053
  if (canonicalJson(assessment) !== canonicalJson(plan.assessment)) {
8068
8054
  throw invalid2("\u5B9E\u9645 argv \u4E0E\u6267\u884C\u8BA1\u5212\u7684\u547D\u4EE4\u6458\u8981\u6216\u98CE\u9669\u4E8B\u5B9E\u4E0D\u4E00\u81F4");
8069
8055
  }
8070
- const { bytes: lockBytes, runtime: lockedRuntime } = await readSkillsLock(project);
8056
+ const lockBytes = await readSkillsLock(project);
8071
8057
  if (sha2565(lockBytes) !== plan.skillsLockSha256) {
8072
8058
  throw invalid2("\u6280\u80FD\u9501\u6458\u8981\u5DF2\u6F02\u79FB\uFF0C\u8BF7\u91CD\u65B0\u8BC4\u4F30\u5E76 prepare");
8073
8059
  }
8074
8060
  const runtime = await (input.runtimeIdentity ?? currentRuntimeIdentity)();
8075
- assertRuntimeMatches(runtime, lockedRuntime);
8076
8061
  if (canonicalJson(runtime) !== canonicalJson(plan.runtime)) {
8077
8062
  throw invalid2("CLI \u8FD0\u884C\u65F6\u6458\u8981\u4E0E\u6267\u884C\u8BA1\u5212\u4E0D\u4E00\u81F4");
8078
8063
  }
@@ -8193,19 +8178,12 @@ async function readSkillsLock(project) {
8193
8178
  );
8194
8179
  }
8195
8180
  const bytes = await readSafeFile(project, path8.join(project, found[0]), "\u6280\u80FD\u9501");
8196
- let parsed;
8197
8181
  try {
8198
- parsed = JSON.parse(bytes.toString("utf8"));
8182
+ JSON.parse(bytes.toString("utf8"));
8199
8183
  } catch (cause) {
8200
8184
  throw invalid2("\u6280\u80FD\u9501\u4E0D\u662F\u5408\u6CD5 JSON", cause);
8201
8185
  }
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 };
8186
+ return bytes;
8209
8187
  }
8210
8188
  async function bindDocument(project, reference, label) {
8211
8189
  const relative2 = safeRelative(reference, label);
@@ -8227,10 +8205,21 @@ async function bindEvidenceDirectory(project, reference) {
8227
8205
  }
8228
8206
  const absolute = path8.join(project, relative2);
8229
8207
  await assertNoSymlinkComponents(project, relative2);
8230
- const stat = await fs6.stat(absolute).catch((cause) => {
8231
- throw invalid2(`evidence \u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
8232
- });
8233
- if (!stat.isDirectory()) throw invalid2(`evidence \u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
8208
+ const stat = await fs6.stat(absolute).catch(() => null);
8209
+ if (stat === null) {
8210
+ await fs6.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
8211
+ throw invalid2(
8212
+ `evidence \u76EE\u5F55\u5EFA\u4E0D\u51FA\u6765\uFF1A${relative2}\u3002next_step=\u68C0\u67E5\u4E0A\u7EA7\u76EE\u5F55\u6743\u9650\uFF0C\u6216\u6362\u4E00\u4E2A evidence/ \u4E0B\u7684\u8DEF\u5F84`,
8213
+ cause
8214
+ );
8215
+ });
8216
+ return { relative: relative2, absolute };
8217
+ }
8218
+ if (!stat.isDirectory()) {
8219
+ throw invalid2(
8220
+ `evidence \u8DEF\u5F84\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}\u3002next_step=\u6362\u4E00\u4E2A evidence/ \u4E0B\u7684\u76EE\u5F55\u540D`
8221
+ );
8222
+ }
8234
8223
  return { relative: relative2, absolute };
8235
8224
  }
8236
8225
  async function readPlan(project, file) {
@@ -8372,18 +8361,13 @@ function requireFlagValue(argv, flag, message) {
8372
8361
  }
8373
8362
  throw invalid2(message);
8374
8363
  }
8375
- function assertRuntimeMatches(actual, expected) {
8376
- if (canonicalJson(actual) !== canonicalJson(expected)) {
8377
- 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");
8378
- }
8379
- }
8380
8364
  async function currentRuntimeIdentity() {
8381
8365
  const entry = process.argv[1];
8382
8366
  if (!entry) throw invalid2("\u65E0\u6CD5\u89E3\u6790\u5F53\u524D CLI entry");
8383
8367
  return {
8384
8368
  kind: "node-entry",
8385
- executableSha256: await sha256File2(process.execPath),
8386
- entrySha256: await sha256File2(entry)
8369
+ executableSha256: await sha256File(process.execPath),
8370
+ entrySha256: await sha256File(entry)
8387
8371
  };
8388
8372
  }
8389
8373
  async function runCurrentCliCommand(argv, cwd, streams) {
@@ -8522,7 +8506,7 @@ function canonicalJson(value) {
8522
8506
  function sha2565(value) {
8523
8507
  return createHash5("sha256").update(value).digest("hex");
8524
8508
  }
8525
- async function sha256File2(file) {
8509
+ async function sha256File(file) {
8526
8510
  const hash = createHash5("sha256");
8527
8511
  await new Promise((resolve4, reject) => {
8528
8512
  const stream = createReadStream(file);