@hcmai/cli 0.13.1 → 0.14.0

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
@@ -752,8 +752,8 @@ var init_TerminalRenderer = __esm({
752
752
  }
753
753
  }
754
754
  /** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
755
- originLine(path17) {
756
- const segs = path17.split(".").filter(Boolean);
755
+ originLine(path18) {
756
+ const segs = path18.split(".").filter(Boolean);
757
757
  if (segs.length < 2) return "";
758
758
  const names = segs.map((k) => agentDisplayName(k));
759
759
  return chalk.gray(` \u2191 \u6765\u81EA ${names.join(" \u203A ")}`) + "\n";
@@ -1935,8 +1935,8 @@ function agentLabel(agentId) {
1935
1935
  if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(agentId)) return `agent \u2026${agentId.slice(-4)}`;
1936
1936
  return agentDisplayName(agentId);
1937
1937
  }
1938
- function originLine(path17) {
1939
- const segs = (path17 ?? "").split(".").filter(Boolean);
1938
+ function originLine(path18) {
1939
+ const segs = (path18 ?? "").split(".").filter(Boolean);
1940
1940
  if (segs.length < 2) return null;
1941
1941
  return `\u6765\u81EA ${segs.map((k) => agentDisplayName(k)).join(" \u203A ")}`;
1942
1942
  }
@@ -2359,7 +2359,7 @@ function launchBrowser(url, platform = process.platform, onFailure) {
2359
2359
  child.unref();
2360
2360
  }
2361
2361
  async function runOpen(target, args, deps) {
2362
- const path17 = normalizeTarget(target);
2362
+ const path18 = normalizeTarget(target);
2363
2363
  if (!deps.frontend?.trim()) {
2364
2364
  throw new CliError3({
2365
2365
  code: CliErrorCode2.INVALID_ARGUMENT,
@@ -2367,13 +2367,13 @@ async function runOpen(target, args, deps) {
2367
2367
  });
2368
2368
  }
2369
2369
  const { ticket, expiresIn } = await deps.mintTicket();
2370
- const url = buildBrowserLoginUrl(deps.frontend, ticket, path17);
2370
+ const url = buildBrowserLoginUrl(deps.frontend, ticket, path18);
2371
2371
  if (args.printUrl) {
2372
2372
  deps.write(`${url}
2373
2373
  `);
2374
2374
  } else {
2375
2375
  deps.launch(url);
2376
- deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path17}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
2376
+ deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path18}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
2377
2377
  `);
2378
2378
  }
2379
2379
  return { url, expiresIn };
@@ -4451,8 +4451,8 @@ import {
4451
4451
  formatObject as formatObject7,
4452
4452
  fromAxiosError as fromAxiosError9
4453
4453
  } from "@hcmai/sdk";
4454
- function collectYmlFiles(path17) {
4455
- if (statSync(path17).isFile()) return [path17];
4454
+ function collectYmlFiles(path18) {
4455
+ if (statSync(path18).isFile()) return [path18];
4456
4456
  const out = [];
4457
4457
  const walk = (dir) => {
4458
4458
  for (const name of readdirSync(dir).sort()) {
@@ -4461,7 +4461,7 @@ function collectYmlFiles(path17) {
4461
4461
  else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
4462
4462
  }
4463
4463
  };
4464
- walk(path17);
4464
+ walk(path18);
4465
4465
  return out.sort();
4466
4466
  }
4467
4467
  var DRY_RUN_CLIENT = {
@@ -4469,9 +4469,9 @@ var DRY_RUN_CLIENT = {
4469
4469
  create: async () => ({ id: "" }),
4470
4470
  update: async () => ({})
4471
4471
  };
4472
- async function importCommand(path17, args) {
4472
+ async function importCommand(path18, args) {
4473
4473
  try {
4474
- const files = collectYmlFiles(path17);
4474
+ const files = collectYmlFiles(path18);
4475
4475
  const fixtures = files.map(
4476
4476
  (f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
4477
4477
  );
@@ -5980,8 +5980,8 @@ function emit3(payload, fmt) {
5980
5980
  // src/commands/skills.ts
5981
5981
  init_exit();
5982
5982
  import { promises as fsp2 } from "fs";
5983
- import os2 from "os";
5984
- import path6 from "path";
5983
+ import os3 from "os";
5984
+ import path8 from "path";
5985
5985
  import { createHash as createHash4 } from "crypto";
5986
5986
  import {
5987
5987
  createHttpClient as createHttpClient2,
@@ -5998,13 +5998,13 @@ import {
5998
5998
  resolveAllSkillsInstallOrder,
5999
5999
  matchSkills,
6000
6000
  filterByStage,
6001
- formatObject as formatObject16,
6001
+ formatObject as formatObject17,
6002
6002
  fromAxiosError as fromAxiosError16,
6003
6003
  loadGlobalConfig as loadGlobalConfig6,
6004
6004
  resolveEnvContext as resolveEnvContext5,
6005
6005
  printResolvedEnvironment as printResolvedEnvironment4,
6006
- CliError as CliError19,
6007
- CliErrorCode as CliErrorCode18
6006
+ CliError as CliError20,
6007
+ CliErrorCode as CliErrorCode19
6008
6008
  } from "@hcmai/sdk";
6009
6009
 
6010
6010
  // src/commands/skills-catalog.ts
@@ -6195,137 +6195,487 @@ function mergeBoundaryBlock(existing, fromProduct) {
6195
6195
  return { text: upsertBlock(existing, AGENT_BEGIN, AGENT_END, block.trimEnd()), source };
6196
6196
  }
6197
6197
 
6198
- // src/commands/skills-bundled.ts
6199
- import { promises as fsp } from "fs";
6200
- import * as path5 from "path";
6201
- import { CliError as CliError18, CliErrorCode as CliErrorCode17, assertSafeReferencePath, parseSkillRequirements } from "@hcmai/sdk";
6198
+ // src/commands/chiron-project.ts
6199
+ import { promises as fs7 } from "fs";
6200
+ import path5 from "path";
6202
6201
 
6203
- // src/commands/skills-manifest.ts
6204
- import { readFileSync as readFileSync4, readdirSync as readdirSync2, statSync as statSync3, existsSync } from "fs";
6205
- import { createHash as createHash3 } from "crypto";
6206
- import * as path4 from "path";
6207
- import { fileURLToPath } from "url";
6208
- import { formatObject as formatObject15, parseSkillFrontmatter } from "@hcmai/sdk";
6209
- function collectCommandSurface(root) {
6210
- const out = [];
6211
- const walk = (cmd, prefix) => {
6212
- for (const sub of cmd.commands) {
6213
- const segs = [...prefix, sub.name()];
6214
- const options = sub.options.map((o) => /(--[a-zA-Z0-9][\w-]*)/.exec(o.flags)?.[1] ?? "").filter((s) => s.length > 0);
6215
- out.push({ path: segs.join(" "), options: [...new Set(options)].sort() });
6216
- walk(sub, segs);
6202
+ // src/commands/chiron-case.ts
6203
+ init_exit();
6204
+ import { execFileSync } from "child_process";
6205
+ import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync as readFileSync4, rmSync, statSync as statSync3, writeFileSync as writeFileSync2 } from "fs";
6206
+ import os2 from "os";
6207
+ import path4 from "path";
6208
+ import { CASES_REPO_SLUG, CASES_REPO_URL, CNB_ORIGIN, CliError as CliError18, CliErrorCode as CliErrorCode17, formatObject as formatObject15 } from "@hcmai/sdk";
6209
+ var casesCacheDir = () => process.env.HCM_CASES_CACHE?.trim() || path4.join(os2.homedir(), ".cache", "hcm", "chiron-cases");
6210
+ var INDEX_CACHE = () => path4.join(casesCacheDir(), "index.json");
6211
+ var INDEX_TTL_MS = 60 * 60 * 1e3;
6212
+ var fail5 = (message, nextStep) => new CliError18({ code: CliErrorCode17.INVALID_ARGUMENT, message, context: { nextStep } });
6213
+ var run = (cmd, args, opts = {}) => execFileSync(cmd, args, { encoding: "utf8", maxBuffer: 1 << 26, ...opts });
6214
+ function fetchRepoFile(relPath) {
6215
+ let raw;
6216
+ try {
6217
+ raw = run("cnb", ["git", "get-raw", "--repo", CASES_REPO_SLUG, "--ref-with-path", `main/${relPath}`]);
6218
+ } catch (e) {
6219
+ throw fail5(
6220
+ `\u53D6\u4E0D\u5230\u6848\u4F8B\u5E93\u6587\u4EF6 ${relPath}\uFF1A${String(e.message).split("\n")[0]}`,
6221
+ "\u6848\u4F8B\u5E93\u8BFB\u53D6\u8D70 cnb\uFF08\u9700\u8981\u5DF2 `cnb login` \u4E14\u6709\u8BE5\u4ED3\u8BFB\u6743\u9650\uFF09\u3002\u6CA1\u6709\u6743\u9650\u5C31\u5148\u8DF3\u8FC7\u6848\u4F8B\u5E93\uFF0C\u76F4\u63A5\u6309\u6280\u80FD\u505A\uFF1B\u522B\u628A\u300C\u53D6\u4E0D\u5230\u300D\u5F53\u6210\u300C\u6CA1\u6709\u5148\u4F8B\u300D\u3002"
6222
+ );
6223
+ }
6224
+ const i = raw.indexOf("data: ");
6225
+ if (i < 0) throw fail5(`cnb \u7684\u56DE\u6267\u91CC\u6CA1\u6709 data \u90A3\u4E00\u683C\uFF1A${relPath}`, "\u5347\u7EA7 cnb CLI\uFF0C\u6216\u628A\u8FD9\u6BB5\u539F\u6837\u8D34\u7ED9\u6211\u3002");
6226
+ const body = raw.slice(i + "data: ".length).trim();
6227
+ if (body.startsWith('"')) {
6228
+ try {
6229
+ return JSON.parse(body);
6230
+ } catch {
6231
+ return body;
6217
6232
  }
6218
- };
6219
- walk(root, []);
6220
- return out.sort((a, b) => a.path.localeCompare(b.path));
6221
- }
6222
- function bundledSkillsDir() {
6223
- const here = path4.dirname(fileURLToPath(import.meta.url));
6224
- return path4.join(here, "skills");
6225
- }
6226
- function sha256(buf) {
6227
- return createHash3("sha256").update(buf).digest("hex");
6233
+ }
6234
+ return body;
6228
6235
  }
6229
- function listFiles(dir, rel = "") {
6230
- const out = [];
6231
- for (const name of readdirSync2(dir)) {
6232
- const p = path4.join(dir, name);
6233
- const r = rel ? `${rel}/${name}` : name;
6234
- if (statSync3(p).isDirectory()) out.push(...listFiles(p, r));
6235
- else out.push(r);
6236
+ function loadIndex(opts = {}) {
6237
+ const file = INDEX_CACHE();
6238
+ const fresh = !opts.refresh && existsSync(file) && Date.now() - statSync3(file).mtimeMs < INDEX_TTL_MS;
6239
+ if (fresh) return JSON.parse(readFileSync4(file, "utf8"));
6240
+ let text;
6241
+ try {
6242
+ text = fetchRepoFile("index/index.json");
6243
+ } catch (e) {
6244
+ if (!existsSync(file)) throw e;
6245
+ process.stderr.write(
6246
+ `[hcm] \u7D22\u5F15\u6CA1\u62C9\u52A8\uFF08${e.message.split("\n")[0]}\uFF09\uFF0C\u7528\u672C\u673A\u7F13\u5B58\u7684\u90A3\u4EFD\uFF1A${file}
6247
+ `
6248
+ );
6249
+ return JSON.parse(readFileSync4(file, "utf8"));
6236
6250
  }
6237
- return out;
6251
+ mkdirSync(path4.dirname(file), { recursive: true });
6252
+ writeFileSync2(file, text);
6253
+ return JSON.parse(text);
6238
6254
  }
6239
- function collectBundledSkills(dir = bundledSkillsDir()) {
6240
- if (!existsSync(dir)) return [];
6241
- const out = [];
6242
- for (const id of readdirSync2(dir).sort()) {
6243
- const skillDir = path4.join(dir, id);
6244
- if (!statSync3(skillDir).isDirectory()) continue;
6245
- const files = listFiles(skillDir).sort();
6246
- if (!files.includes("SKILL.md")) continue;
6247
- let bytes = 0;
6248
- const fileRows = files.map((rel) => {
6249
- const buf = readFileSync4(path4.join(skillDir, rel));
6250
- bytes += buf.byteLength;
6251
- return { path: rel, bytes: buf.byteLength, sha256: sha256(buf) };
6252
- });
6253
- const body = readFileSync4(path4.join(skillDir, "SKILL.md"), "utf8");
6254
- const fm = parseSkillFrontmatter(body, id);
6255
- out.push({
6256
- id,
6257
- title: str(fm.title),
6258
- description: str(fm.description),
6259
- category: str(fm.category),
6260
- stages: strArray(fm.stages),
6261
- actionSurface: str(fm.actionSurface),
6262
- requires: strArray(fm.requires),
6263
- bytes,
6264
- files: fileRows
6265
- });
6255
+ function backendFingerprint(env2) {
6256
+ if (!env2) return { reason: "\u6CA1\u7ED9 --env\uFF0C\u6CA1\u6CD5\u73B0\u67E5\u6307\u7EB9" };
6257
+ try {
6258
+ const raw = run(process.execPath, [process.argv[1], "version", "--env", env2, "--output", "json"]);
6259
+ const j = JSON.parse(raw.slice(raw.indexOf("{")));
6260
+ const backend = j.backend?.commit ?? j.commit ?? j.server?.commit;
6261
+ if (!backend) return { reason: "\u540E\u7AEF\u56DE\u6267\u91CC\u6CA1\u6709 commit \u5B57\u6BB5" };
6262
+ return { backend: String(backend), cli: String(j.cli?.version ?? j.cliVersion ?? "") };
6263
+ } catch (e) {
6264
+ return { reason: String(e.message).split("\n")[0]?.slice(0, 120) };
6266
6265
  }
6267
- return out;
6268
6266
  }
6269
- function buildManifest(root, skillsDir = bundledSkillsDir()) {
6270
- return {
6271
- schemaVersion: 1,
6272
- cliVersion: CLI_VERSION,
6273
- commands: collectCommandSurface(root),
6274
- skills: collectBundledSkills(skillsDir)
6275
- };
6267
+ function matchTag(c, fp) {
6268
+ if (!fp.backend) return `\u672A\u6BD4\u5BF9\uFF08${fp.reason ?? "\u6CA1\u6709\u6307\u7EB9"}\uFF09`;
6269
+ const be = String(c.fingerprint?.backend_commit ?? "");
6270
+ if (!be) return "\u6848\u4F8B\u6CA1\u8BB0\u540E\u7AEF\u6307\u7EB9";
6271
+ const a = be.slice(0, 12);
6272
+ const b = fp.backend.slice(0, 12);
6273
+ return a === b ? "\u5339\u914D" : `\u4E0D\u5339\u914D\uFF08\u6848\u4F8B ${a} / \u5F53\u524D ${b}\uFF09`;
6276
6274
  }
6277
- function skillsManifestCommand(root, args) {
6278
- const manifest2 = buildManifest(root);
6279
- process.stdout.write(formatObject15(manifest2, { format: args.output ?? "json" }) + "\n");
6275
+ function emit4(args, data, text) {
6276
+ if (args.output === "json" || args.output === "yaml") {
6277
+ process.stdout.write(formatObject15(data, { format: args.output }) + "\n");
6278
+ } else {
6279
+ process.stdout.write(text() + "\n");
6280
+ }
6280
6281
  }
6281
- function str(v) {
6282
- return typeof v === "string" && v ? v : void 0;
6282
+ async function guard(fn) {
6283
+ try {
6284
+ await fn();
6285
+ } catch (e) {
6286
+ exitWithError(e);
6287
+ }
6283
6288
  }
6284
- function strArray(v) {
6285
- return Array.isArray(v) ? v.map(String) : void 0;
6289
+ async function caseSearchCommand(query, args) {
6290
+ await guard(async () => {
6291
+ const idx = loadIndex({ refresh: args.refresh });
6292
+ const fp = backendFingerprint(args.env);
6293
+ let raw;
6294
+ try {
6295
+ raw = run("cnb", [
6296
+ "knowledge-base",
6297
+ "query-knowledge-base-get",
6298
+ "--repo",
6299
+ CASES_REPO_SLUG,
6300
+ "--query",
6301
+ query,
6302
+ "--top-k",
6303
+ String(args.topK ?? 5),
6304
+ "--verbose"
6305
+ ]);
6306
+ } catch (e) {
6307
+ throw fail5(
6308
+ `\u6848\u4F8B\u5E93\u68C0\u7D22\u6CA1\u8DD1\u6210\uFF1A${String(e.message).split("\n")[0]}`,
6309
+ "\u68C0\u7D22\u8D70 cnb \u7684\u77E5\u8BC6\u5E93\u63A5\u53E3\uFF0C\u9700\u8981 cnb \u5DF2\u767B\u5F55\u4E14\u6709\u6848\u4F8B\u5E93\u6743\u9650\u3002\u6CA1\u6709\u5C31\u5148\u8DF3\u8FC7\u6848\u4F8B\u5E93\uFF0C\u76F4\u63A5\u6309\u6280\u80FD\u505A\uFF1B\u522B\u628A\u300C\u67E5\u4E0D\u5230\u300D\u5F53\u6210\u300C\u6CA1\u6709\u5148\u4F8B\u300D\u3002"
6310
+ );
6311
+ }
6312
+ const json = JSON.parse(raw.slice(raw.indexOf("{")));
6313
+ const seen = /* @__PURE__ */ new Map();
6314
+ for (const h of json.data ?? []) {
6315
+ const p = h.metadata?.path ?? "";
6316
+ const m = /^cases\/[^/]+\/([^/]+)\//.exec(p);
6317
+ if (!m) continue;
6318
+ const id = m[1];
6319
+ if (seen.has(id)) continue;
6320
+ const c = idx.cases.find((x) => x.id === id);
6321
+ seen.set(id, {
6322
+ id,
6323
+ score: h.score,
6324
+ file: p.split("/").pop(),
6325
+ status: c?.status,
6326
+ tier: c?.tier,
6327
+ skills: c?.skills,
6328
+ customer_ask: c?.customer_ask,
6329
+ match: c ? matchTag(c, fp) : "\u7D22\u5F15\u91CC\u6CA1\u6709\uFF08\u672C\u673A clone \u53EF\u80FD\u65E7\u4E86\uFF0Cgit pull \u4E00\u6B21\uFF09"
6330
+ });
6331
+ }
6332
+ const rows2 = [...seen.values()];
6333
+ emit4(
6334
+ args,
6335
+ { query, rows: rows2 },
6336
+ () => rows2.length ? rows2.map((r) => `${r.id} [${r.status ?? "?"}\xB7${r.match}] ${r.customer_ask ?? ""}
6337
+ \u6280\u80FD\uFF1A${(r.skills ?? []).join(" / ") || "\uFF08\u672A\u767B\u8BB0\uFF09"}`).join("\n") : `\u6CA1\u6709\u547D\u4E2D\u300C${query}\u300D\u7684\u6848\u4F8B\u3002\u5148\u6309\u6280\u80FD\u505A\uFF0C\u8DD1\u901A\u4E86\u7528 \`hcm chiron case submit\` \u4E0A\u884C\u4E00\u6761\u3002`
6338
+ );
6339
+ });
6286
6340
  }
6341
+ async function caseShowCommand(id, args) {
6342
+ await guard(async () => {
6343
+ const idx = loadIndex({ refresh: args.refresh });
6344
+ const c = idx.cases.find((x) => x.id === id);
6345
+ if (!c?.path) {
6346
+ throw fail5(
6347
+ `\u7D22\u5F15\u91CC\u6CA1\u6709\u6848\u4F8B ${id}`,
6348
+ `\u5148 \`hcm chiron case search <\u5173\u952E\u8BCD>\` \u62FF\u51C6\u786E\u7684 id\uFF1B\u7D22\u5F15\u53EF\u80FD\u65E7\u4E86\uFF0C\u52A0 --refresh \u518D\u8BD5\u4E00\u6B21\u3002`
6349
+ );
6350
+ }
6351
+ const files = args.file ? [args.file] : ["\u95EE\u9898.md", "\u65B9\u6848.md"];
6352
+ const parts = [];
6353
+ for (const f of files) {
6354
+ try {
6355
+ parts.push(`# ${f}
6287
6356
 
6288
- // src/commands/skills-bundled.ts
6289
- function listBundledSkills(dir = bundledSkillsDir()) {
6290
- return collectBundledSkills(dir);
6357
+ ${fetchRepoFile(`${c.path}/${f}`)}`);
6358
+ } catch {
6359
+ parts.push(`# ${f}
6360
+
6361
+ \uFF08\u8FD9\u4E2A\u6848\u4F8B\u6CA1\u6709\u8FD9\u4EFD\u6587\u4EF6\uFF09`);
6362
+ }
6363
+ }
6364
+ const meta2 = fetchRepoFile(`${c.path}/case.yml`);
6365
+ emit4(
6366
+ args,
6367
+ { id, caseYml: meta2, files: parts },
6368
+ () => `case.yml:
6369
+ ${meta2}
6370
+
6371
+ ${parts.join("\n\n---\n\n")}
6372
+
6373
+ \uFF08\u8BC1\u636E\u6587\u4EF6\u6CA1\u6709\u4E0B\u8F7D \u2014\u2014 \u53BB ${CNB_ORIGIN}/${CASES_REPO_SLUG}/-/tree/main/${c.path} \u770B\uFF09`
6374
+ );
6375
+ });
6291
6376
  }
6292
- function unreachable(id, detail) {
6293
- return new CliError18({
6294
- code: CliErrorCode17.SKILL_SOURCE_UNREACHABLE,
6295
- message: `\u88C5\u5728\u8FD9\u4EFD CLI \u91CC\u7684\u6280\u80FD\u8D44\u6E90\u8BFB\u4E0D\u5230\uFF08${detail}\uFF09\uFF0C\u91CD\u88C5 @hcmai/cli\u3002
6296
- \u6280\u80FD id\uFF1A${id}\uFF1B\u627E\u7684\u4F4D\u7F6E\uFF1A${bundledSkillsDir()}`
6377
+ async function caseMatchCommand(args) {
6378
+ await guard(async () => {
6379
+ const idx = loadIndex({ refresh: args.refresh });
6380
+ const fp = backendFingerprint(args.env);
6381
+ const rows2 = idx.cases.filter((c) => c.status === "approved").map((c) => ({ id: c.id, match: matchTag(c, fp), skills: c.skills, customer_ask: c.customer_ask }));
6382
+ emit4(args, { fingerprint: fp, rows: rows2 }, () => {
6383
+ const head = fp.backend ? `\u5F53\u524D\u540E\u7AEF ${fp.backend.slice(0, 12)}\uFF08env ${args.env}\uFF09` : `\u26A0\uFE0F \u6CA1\u53D6\u5230\u5F53\u524D\u6307\u7EB9\uFF08${fp.reason}\uFF09\u2014\u2014\u4E0B\u9762\u6BCF\u4E00\u6761\u90FD\u6807\u7740\u300C\u672A\u6BD4\u5BF9\u300D\uFF0C\u522B\u628A\u5B83\u8BFB\u6210\u300C\u90FD\u80FD\u7167\u505A\u300D`;
6384
+ return [head, ...rows2.map((r) => `${r.match === "\u5339\u914D" ? "\u2705" : "\xB7 "} ${r.id} [${r.match}] ${r.customer_ask ?? ""}`)].join("\n");
6385
+ });
6297
6386
  });
6298
6387
  }
6299
- async function readBundledReferences(skillDir) {
6300
- const root = path5.join(skillDir, "references");
6301
- const out = [];
6302
- const walk = async (dir, prefix) => {
6303
- let items;
6304
- try {
6305
- items = await fsp.readdir(dir, { withFileTypes: true });
6306
- } catch (cause) {
6307
- if (cause?.code === "ENOENT") return;
6308
- throw cause;
6388
+ async function caseSubmitCommand(dir, args) {
6389
+ await guard(async () => {
6390
+ const src = path4.resolve(dir);
6391
+ if (!existsSync(path4.join(src, "case.yml"))) {
6392
+ throw fail5(`${src} \u91CC\u6CA1\u6709 case.yml`, "\u6307\u5230\u9879\u76EE\u4ED3\u7684\u6848\u4F8B\u76EE\u5F55\uFF08\u5982 cases/CASE-20260902-xxx\uFF09\uFF0C\u90A3\u91CC\u5E94\u5F53\u6709 case.yml\u3002");
6309
6393
  }
6310
- for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
6311
- const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
6312
- if (item.isDirectory()) {
6313
- await walk(path5.join(dir, item.name), relative2);
6314
- continue;
6394
+ const yamlText = readFileSync4(path4.join(src, "case.yml"), "utf8");
6395
+ const id = /^\s*(?:id|case_id):\s*(\S+)/m.exec(yamlText)?.[1];
6396
+ if (!id) throw fail5("case.yml \u91CC\u6CA1\u6709 id", "case.yml \u9876\u5C42\u8981\u6709 `id: CASE-YYYYMMDD-xxx`\u3002");
6397
+ const work = mkdtempSync(path4.join(os2.tmpdir(), "hcm-case-submit-"));
6398
+ try {
6399
+ const repo = path4.join(work, "chiron-cases");
6400
+ try {
6401
+ run("git", ["clone", "--depth", "1", "--filter=blob:none", "--quiet", CASES_REPO_URL, repo]);
6402
+ } catch (e) {
6403
+ throw fail5(
6404
+ `clone \u6848\u4F8B\u5E93\u5931\u8D25\uFF1A${String(e.message).split("\n")[0]}`,
6405
+ `\u4E0A\u884C\u8981\u5F80 ${CASES_REPO_SLUG} \u63D0 PR\uFF0C\u9700\u8981\u8BE5\u4ED3\u5199\u6743\u9650\uFF08\`cnb login\` \u4E14\u88AB\u52A0\u8FDB\u4ED3\uFF09\u3002\u6848\u4F8B\u8FD8\u5728\u4F60\u7684\u9879\u76EE\u4ED3\u91CC\uFF0C\u6CA1\u4E22\u3002`
6406
+ );
6315
6407
  }
6316
- if (!item.isFile()) continue;
6408
+ const branch = `case/${id}-submit`;
6409
+ run("git", ["-C", repo, "checkout", "-q", "-B", branch]);
6410
+ const dst = path4.join(repo, "cases", args.category, id);
6411
+ cpSync(src, dst, { recursive: true, filter: (p) => !p.includes("node_modules") });
6412
+ mkdirSync(path4.join(dst, "evidence"), { recursive: true });
6413
+ let doc = readFileSync4(path4.join(dst, "case.yml"), "utf8");
6414
+ doc = /^\s*tier:/m.test(doc) ? doc.replace(/^\s*tier:.*$/m, "tier: public") : `tier: public
6415
+ ${doc}`;
6416
+ doc = /^\s*category:/m.test(doc) ? doc.replace(/^\s*category:.*$/m, `category: ${args.category}`) : `category: ${args.category}
6417
+ ${doc}`;
6418
+ doc = /^\s*origin:/m.test(doc) ? doc.replace(/^\s*origin:.*$/m, `origin: ${args.origin}`) : `origin: ${args.origin}
6419
+ ${doc}`;
6420
+ if (!/^\s*status:/m.test(doc)) doc = `status: approved
6421
+ ${doc}`;
6422
+ writeFileSync2(path4.join(dst, "case.yml"), doc);
6423
+ run("python3", ["scripts/render-readme.py", dst], { cwd: repo });
6424
+ let lint;
6425
+ try {
6426
+ lint = run("python3", ["scripts/lint-case.py"], { cwd: repo });
6427
+ } catch (e) {
6428
+ throw fail5(
6429
+ `\u6848\u4F8B lint \u6CA1\u8FC7\uFF0CPR \u6CA1\u5F00\uFF1A
6430
+ ${e.stdout ?? e.message}`,
6431
+ "\u7167 lint \u7684\u63D0\u793A\u8865\u9F50 case.yml \u4E0E\u6B63\u6587\uFF0C\u518D\u8DD1\u4E00\u6B21\u3002\u6848\u4F8B\u8FD8\u5728\u9879\u76EE\u4ED3\u91CC\uFF0C\u6CA1\u4E22\u3002"
6432
+ );
6433
+ }
6434
+ run("python3", ["scripts/build-index.py"], { cwd: repo });
6435
+ run("git", ["-C", repo, "add", "-A"]);
6436
+ run("git", ["-C", repo, "-c", "user.name=hcm-cli", "-c", "user.email=chiron@local", "commit", "-q", "-m", `case: ${id}\uFF08\u9879\u76EE\u6848\u4F8B\u4E0A\u884C\uFF09`]);
6437
+ run("git", ["-C", repo, "push", "-q", "-f", "-u", "origin", branch]);
6438
+ const pr = run("cnb", [
6439
+ "pulls",
6440
+ "post-pull",
6441
+ "--repo",
6442
+ CASES_REPO_SLUG,
6443
+ "--base",
6444
+ "main",
6445
+ "--head",
6446
+ branch,
6447
+ "--title",
6448
+ `case: ${id}\uFF08\u9879\u76EE\u6848\u4F8B\u4E0A\u884C\uFF09`,
6449
+ "--body",
6450
+ `\u6765\u6E90\uFF1A${args.origin}
6451
+
6452
+ \u7531 \`hcm chiron case submit\` \u63D0\u4EA4\uFF0Clint \u5DF2\u8FC7\u3002`
6453
+ ]);
6454
+ const num = /number: "?(\d+)/.exec(pr)?.[1];
6455
+ rmSync(INDEX_CACHE(), { force: true });
6456
+ emit4(
6457
+ args,
6458
+ { id, pr: num, lint: lint.trim() },
6459
+ () => `\u5DF2\u5F00 PR #${num ?? "?"}\uFF1A${CNB_ORIGIN}/${CASES_REPO_SLUG}/-/pulls/${num ?? ""}
6460
+ ${lint.trim()}`
6461
+ );
6462
+ } finally {
6463
+ rmSync(work, { recursive: true, force: true });
6464
+ }
6465
+ });
6466
+ }
6467
+
6468
+ // src/commands/chiron-project.ts
6469
+ import { normalizeOrigin as normalizeOrigin2 } from "@hcmai/sdk";
6470
+ import { JIRA_BASE, JIRA_PROJECT, jiraTokenSource } from "@hcmai/sdk";
6471
+ import { ENV_FILE, parseEnvYaml, renderEnvYaml, findEnvByEndpoint as findEnvByEndpoint3, normalizeOrigin as normalizeOrigin3 } from "@hcmai/sdk";
6472
+ import { CASES_REPO_URL as CASES_REPO_URL2 } from "@hcmai/sdk";
6473
+ import { JIRA_BASE as JIRA_BASE2, JIRA_PROJECT as JIRA_PROJECT2, JIRA_TOKEN_FILE, jiraTokenSource as jiraTokenSource2 } from "@hcmai/sdk";
6474
+ var SKILLS_DIR = "hcm-skills";
6475
+ var SKILLS_SYNC_SUBDIR = "sync";
6476
+ var SKILLS_LOCAL_SUBDIR = "local";
6477
+ function skillsSyncDir(root) {
6478
+ return path5.join(root, SKILLS_DIR, SKILLS_SYNC_SUBDIR);
6479
+ }
6480
+ function skillsLocalDir(root) {
6481
+ return path5.join(root, SKILLS_DIR, SKILLS_LOCAL_SUBDIR);
6482
+ }
6483
+ var CHIRON_PROJECT_DIRECTORIES = [
6484
+ "work",
6485
+ "decisions",
6486
+ "evidence",
6487
+ "requirements",
6488
+ "deliverables",
6489
+ "cases",
6490
+ "gaps",
6491
+ "customer-docs"
6492
+ ];
6493
+ function projectEnvFromConfig(cfg) {
6494
+ const endpoint = normalizeOrigin2(cfg.endpoint);
6495
+ return {
6496
+ endpoint,
6497
+ // 冗余一份 frontend:前后端地址不一致的部署里,页面验收要开的是它。
6498
+ frontend: normalizeOrigin2(cfg.frontend ?? endpoint),
6499
+ tenant: cfg.tenantId ?? "1"
6500
+ };
6501
+ }
6502
+ async function inspectCaseLibrary() {
6503
+ try {
6504
+ const idx = loadIndex();
6505
+ return { ok: true, count: idx.cases.length };
6506
+ } catch (e) {
6507
+ return { ok: false, reason: firstLine("", e) };
6508
+ }
6509
+ }
6510
+ function firstLine(stderr, error) {
6511
+ if (error) return error.message;
6512
+ const line = stderr.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
6513
+ return line ?? "\uFF08\u65E0\u8F93\u51FA\uFF09";
6514
+ }
6515
+ async function inspectJira() {
6516
+ const src = await jiraTokenSource();
6517
+ if (!src) {
6518
+ return {
6519
+ ok: false,
6520
+ reason: `\u6CA1\u6709\u4EE4\u724C\u3002\u5728 ${JIRA_BASE} \u53F3\u4E0A\u89D2\u5934\u50CF \u2192 \u4E2A\u4EBA\u8BBE\u7F6E \u2192 Personal Access Tokens \u5EFA\u4E00\u4E2A\uFF0C\u7136\u540E\uFF1Amkdir -p ~/.config/hcm && read -rs pat && printf "%s" "$pat" > ~/.config/hcm/jira-token && chmod 600 ~/.config/hcm/jira-token && unset pat`
6521
+ };
6522
+ }
6523
+ const call = async (path_) => {
6524
+ const res = await fetch(`${JIRA_BASE}${path_}`, {
6525
+ headers: { Authorization: `Bearer ${src.token}`, Accept: "application/json" },
6526
+ signal: AbortSignal.timeout(15e3)
6527
+ });
6528
+ return res;
6529
+ };
6530
+ try {
6531
+ const me = await call("/rest/api/2/myself");
6532
+ if (me.status === 401) return { ok: false, from: src.from, reason: "\u4EE4\u724C\u65E0\u6548\u6216\u5DF2\u8FC7\u671F\uFF0C\u91CD\u5EFA PAT \u540E\u91CD\u65B0\u5B58\u4E00\u6B21" };
6533
+ if (!me.ok) return { ok: false, from: src.from, reason: `\u8FDE\u5F97\u4E0A\u4F46 /myself \u8FD4\u56DE ${me.status}` };
6534
+ const who = (await me.json()).displayName ?? "";
6535
+ const project = await call(`/rest/api/2/project/${JIRA_PROJECT}`);
6536
+ return {
6537
+ ok: project.ok,
6538
+ from: src.from,
6539
+ who,
6540
+ projectVisible: project.ok,
6541
+ reason: project.ok ? void 0 : `\u770B\u4E0D\u5230\u9879\u76EE ${JIRA_PROJECT}\uFF08${project.status}\uFF09\uFF0C\u627E Jira \u7BA1\u7406\u5458\u5F00\u6743\u9650`
6542
+ };
6543
+ } catch (e) {
6544
+ return { ok: false, from: src.from, reason: `\u8FDE\u4E0D\u4E0A ${JIRA_BASE}\uFF1A${e.message}` };
6545
+ }
6546
+ }
6547
+
6548
+ // src/commands/skills-bundled.ts
6549
+ import { promises as fsp } from "fs";
6550
+ import * as path7 from "path";
6551
+ import { CliError as CliError19, CliErrorCode as CliErrorCode18, assertSafeReferencePath, parseSkillRequirements } from "@hcmai/sdk";
6552
+
6553
+ // src/commands/skills-manifest.ts
6554
+ import { readFileSync as readFileSync5, readdirSync as readdirSync2, statSync as statSync4, existsSync as existsSync2 } from "fs";
6555
+ import { createHash as createHash3 } from "crypto";
6556
+ import * as path6 from "path";
6557
+ import { fileURLToPath } from "url";
6558
+ import { formatObject as formatObject16, parseSkillFrontmatter } from "@hcmai/sdk";
6559
+ function collectCommandSurface(root) {
6560
+ const out = [];
6561
+ const walk = (cmd, prefix) => {
6562
+ for (const sub of cmd.commands) {
6563
+ const segs = [...prefix, sub.name()];
6564
+ const options = sub.options.map((o) => /(--[a-zA-Z0-9][\w-]*)/.exec(o.flags)?.[1] ?? "").filter((s) => s.length > 0);
6565
+ out.push({ path: segs.join(" "), options: [...new Set(options)].sort() });
6566
+ walk(sub, segs);
6567
+ }
6568
+ };
6569
+ walk(root, []);
6570
+ return out.sort((a, b) => a.path.localeCompare(b.path));
6571
+ }
6572
+ function bundledSkillsDir() {
6573
+ const here = path6.dirname(fileURLToPath(import.meta.url));
6574
+ return path6.join(here, "skills");
6575
+ }
6576
+ function sha256(buf) {
6577
+ return createHash3("sha256").update(buf).digest("hex");
6578
+ }
6579
+ function listFiles(dir, rel = "") {
6580
+ const out = [];
6581
+ for (const name of readdirSync2(dir)) {
6582
+ const p = path6.join(dir, name);
6583
+ const r = rel ? `${rel}/${name}` : name;
6584
+ if (statSync4(p).isDirectory()) out.push(...listFiles(p, r));
6585
+ else out.push(r);
6586
+ }
6587
+ return out;
6588
+ }
6589
+ function collectBundledSkills(dir = bundledSkillsDir()) {
6590
+ if (!existsSync2(dir)) return [];
6591
+ const out = [];
6592
+ for (const id of readdirSync2(dir).sort()) {
6593
+ const skillDir = path6.join(dir, id);
6594
+ if (!statSync4(skillDir).isDirectory()) continue;
6595
+ const files = listFiles(skillDir).sort();
6596
+ if (!files.includes("SKILL.md")) continue;
6597
+ let bytes = 0;
6598
+ const fileRows = files.map((rel) => {
6599
+ const buf = readFileSync5(path6.join(skillDir, rel));
6600
+ bytes += buf.byteLength;
6601
+ return { path: rel, bytes: buf.byteLength, sha256: sha256(buf) };
6602
+ });
6603
+ const body = readFileSync5(path6.join(skillDir, "SKILL.md"), "utf8");
6604
+ const fm = parseSkillFrontmatter(body, id);
6605
+ out.push({
6606
+ id,
6607
+ title: str(fm.title),
6608
+ description: str(fm.description),
6609
+ category: str(fm.category),
6610
+ stages: strArray(fm.stages),
6611
+ actionSurface: str(fm.actionSurface),
6612
+ requires: strArray(fm.requires),
6613
+ bytes,
6614
+ files: fileRows
6615
+ });
6616
+ }
6617
+ return out;
6618
+ }
6619
+ function buildManifest(root, skillsDir = bundledSkillsDir()) {
6620
+ return {
6621
+ schemaVersion: 1,
6622
+ cliVersion: CLI_VERSION,
6623
+ commands: collectCommandSurface(root),
6624
+ skills: collectBundledSkills(skillsDir)
6625
+ };
6626
+ }
6627
+ function skillsManifestCommand(root, args) {
6628
+ const manifest2 = buildManifest(root);
6629
+ process.stdout.write(formatObject16(manifest2, { format: args.output ?? "json" }) + "\n");
6630
+ }
6631
+ function str(v) {
6632
+ return typeof v === "string" && v ? v : void 0;
6633
+ }
6634
+ function strArray(v) {
6635
+ return Array.isArray(v) ? v.map(String) : void 0;
6636
+ }
6637
+
6638
+ // src/commands/skills-bundled.ts
6639
+ function listBundledSkills(dir = bundledSkillsDir()) {
6640
+ return collectBundledSkills(dir);
6641
+ }
6642
+ function unreachable(id, detail) {
6643
+ return new CliError19({
6644
+ code: CliErrorCode18.SKILL_SOURCE_UNREACHABLE,
6645
+ message: `\u88C5\u5728\u8FD9\u4EFD CLI \u91CC\u7684\u6280\u80FD\u8D44\u6E90\u8BFB\u4E0D\u5230\uFF08${detail}\uFF09\uFF0C\u91CD\u88C5 @hcmai/cli\u3002
6646
+ \u6280\u80FD id\uFF1A${id}\uFF1B\u627E\u7684\u4F4D\u7F6E\uFF1A${bundledSkillsDir()}`
6647
+ });
6648
+ }
6649
+ async function readBundledReferences(skillDir) {
6650
+ const root = path7.join(skillDir, "references");
6651
+ const out = [];
6652
+ const walk = async (dir, prefix) => {
6653
+ let items;
6654
+ try {
6655
+ items = await fsp.readdir(dir, { withFileTypes: true });
6656
+ } catch (cause) {
6657
+ if (cause?.code === "ENOENT") return;
6658
+ throw cause;
6659
+ }
6660
+ for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
6661
+ const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
6662
+ if (item.isDirectory()) {
6663
+ await walk(path7.join(dir, item.name), relative2);
6664
+ continue;
6665
+ }
6666
+ if (!item.isFile()) continue;
6317
6667
  assertSafeReferencePath(relative2);
6318
- out.push({ path: relative2, content: await fsp.readFile(path5.join(dir, item.name), "utf8") });
6668
+ out.push({ path: relative2, content: await fsp.readFile(path7.join(dir, item.name), "utf8") });
6319
6669
  }
6320
6670
  };
6321
6671
  await walk(root, "");
6322
6672
  return out;
6323
6673
  }
6324
6674
  async function readBundledSkillDocument(id, dir = bundledSkillsDir()) {
6325
- const skillDir = path5.join(dir, id);
6675
+ const skillDir = path7.join(dir, id);
6326
6676
  let markdown;
6327
6677
  try {
6328
- markdown = await fsp.readFile(path5.join(skillDir, "SKILL.md"), "utf8");
6678
+ markdown = await fsp.readFile(path7.join(skillDir, "SKILL.md"), "utf8");
6329
6679
  } catch (cause) {
6330
6680
  if (cause?.code === "ENOENT") throw unreachable(id, "SKILL.md \u4E0D\u5B58\u5728");
6331
6681
  throw cause;
@@ -6348,8 +6698,8 @@ async function resolveBundledClosure(targetId, dir = bundledSkillsDir()) {
6348
6698
  const visit = async (id) => {
6349
6699
  if (state.get(id) === "done") return;
6350
6700
  if (state.get(id) === "visiting") {
6351
- throw new CliError18({
6352
- code: CliErrorCode17.INVALID_ARGUMENT,
6701
+ throw new CliError19({
6702
+ code: CliErrorCode18.INVALID_ARGUMENT,
6353
6703
  message: `\u81EA\u5E26\u6280\u80FD\u4F9D\u8D56\u6210\u73AF\uFF1A${[...stack, id].join(" \u2192 ")}`
6354
6704
  });
6355
6705
  }
@@ -6404,8 +6754,8 @@ async function resolveEndpoint(args) {
6404
6754
  printResolvedEnvironment4(resolved);
6405
6755
  const env2 = resolved.config;
6406
6756
  if (!env2?.endpoint) {
6407
- throw new CliError19({
6408
- code: CliErrorCode18.MISSING_FLAG,
6757
+ throw new CliError20({
6758
+ code: CliErrorCode19.MISSING_FLAG,
6409
6759
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`\u3002\uFF08\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u4E0D\u9700\u8981\u5148 login\uFF09"
6410
6760
  });
6411
6761
  }
@@ -6424,8 +6774,8 @@ function decideTrackedEndpoint(options) {
6424
6774
  }
6425
6775
  if (!recorded) {
6426
6776
  if (!current) {
6427
- throw new CliError19({
6428
- code: CliErrorCode18.MISSING_FLAG,
6777
+ throw new CliError20({
6778
+ code: CliErrorCode19.MISSING_FLAG,
6429
6779
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`\u3002\uFF08\u6280\u80FD\u5E93\u514D\u8BA4\u8BC1\uFF0C\u4E0D\u9700\u8981\u5148 login\uFF09"
6430
6780
  });
6431
6781
  }
@@ -6449,27 +6799,28 @@ async function exists(target) {
6449
6799
  }
6450
6800
  }
6451
6801
  async function detectTarget(cwd) {
6452
- if (await exists(path6.join(cwd, ".claude"))) return "claude";
6453
- if (await exists(path6.join(cwd, "AGENTS.md"))) return "codex";
6454
- if (await exists(path6.join(cwd, ".codex"))) return "codex";
6802
+ if (await exists(path8.join(cwd, ".claude"))) return "claude";
6803
+ if (await exists(path8.join(cwd, "AGENTS.md"))) return "codex";
6804
+ if (await exists(path8.join(cwd, ".codex"))) return "codex";
6455
6805
  return void 0;
6456
6806
  }
6457
6807
  async function resolveInstallLayout(args, cwd = process.cwd()) {
6458
6808
  const requested = args.target && args.target !== "auto" ? args.target : void 0;
6459
6809
  const target = requested ?? await detectTarget(cwd) ?? "claude";
6460
6810
  if (target === "codex") {
6461
- const root = args.global ? path6.join(os2.homedir(), ".codex") : cwd;
6462
- const claudeFile = path6.join(root, "CLAUDE.md");
6811
+ const root = args.global ? path8.join(os3.homedir(), ".codex") : cwd;
6812
+ const claudeFile = path8.join(root, "CLAUDE.md");
6463
6813
  return {
6464
6814
  target,
6465
- baseDir: args.dir ? path6.resolve(args.dir) : path6.join(root, "hcm-skills"),
6466
- agentsFile: path6.join(root, "AGENTS.md"),
6815
+ baseDir: args.dir ? path8.resolve(args.dir) : skillsSyncDir(root),
6816
+ localDir: args.dir ? void 0 : skillsLocalDir(root),
6817
+ agentsFile: path8.join(root, "AGENTS.md"),
6467
6818
  companionAgentFiles: !args.global && await exists(claudeFile) ? [claudeFile] : []
6468
6819
  };
6469
6820
  }
6470
6821
  return {
6471
6822
  target,
6472
- baseDir: args.dir ? path6.resolve(args.dir) : args.global ? path6.join(os2.homedir(), ".claude", "skills") : path6.join(cwd, ".claude", "skills")
6823
+ baseDir: args.dir ? path8.resolve(args.dir) : args.global ? path8.join(os3.homedir(), ".claude", "skills") : path8.join(cwd, ".claude", "skills")
6473
6824
  };
6474
6825
  }
6475
6826
  async function chironClient(args) {
@@ -6482,7 +6833,7 @@ async function chironClient(args) {
6482
6833
  });
6483
6834
  return { http, endpoint, base: await resolveChironBase(http) };
6484
6835
  }
6485
- function fail5(e, args) {
6836
+ function fail6(e, args) {
6486
6837
  const err = e;
6487
6838
  if (err?.response?.status === 404) {
6488
6839
  exitWithError(new Error("\u8BE5\u73AF\u5883\u6CA1\u6709\u8FD9\u4E2A\u6280\u80FD \u2014\u2014 \u8DD1 `hcm skills list` \u770B\u76EE\u5F55\uFF08\u6280\u80FD\u968F\u4EA7\u54C1\u7248\u672C\u8D70\uFF09"));
@@ -6506,8 +6857,8 @@ async function skillsListCommand(keyword, args) {
6506
6857
  const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
6507
6858
  const conflicts = detectIdConflicts(catalog);
6508
6859
  if (conflicts.ids.length > 0) {
6509
- throw new CliError19({
6510
- code: CliErrorCode18.SKILL_ID_CONFLICT,
6860
+ throw new CliError20({
6861
+ code: CliErrorCode19.SKILL_ID_CONFLICT,
6511
6862
  message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
6512
6863
  });
6513
6864
  }
@@ -6538,7 +6889,7 @@ async function skillsListCommand(keyword, args) {
6538
6889
  }
6539
6890
  if (fmt === "json" || fmt === "yaml") {
6540
6891
  process.stdout.write(
6541
- formatObject16(
6892
+ formatObject17(
6542
6893
  {
6543
6894
  ...manifest2 ?? {},
6544
6895
  categories: cats,
@@ -6615,7 +6966,7 @@ async function skillsListCommand(keyword, args) {
6615
6966
  process.exitCode = 0;
6616
6967
  return;
6617
6968
  } catch (e) {
6618
- fail5(e, args);
6969
+ fail6(e, args);
6619
6970
  }
6620
6971
  }
6621
6972
  async function listInstalledSkills(keyword, args) {
@@ -6624,11 +6975,11 @@ async function listInstalledSkills(keyword, args) {
6624
6975
  const fmt = args.output ?? "table";
6625
6976
  if (!state || Object.keys(state.skills).length === 0) {
6626
6977
  if (fmt === "json" || fmt === "yaml") {
6627
- process.stdout.write(formatObject16({ baseDir: layout.baseDir, target: layout.target, all: false, skills: [] }, { format: fmt }) + "\n");
6978
+ process.stdout.write(formatObject17({ baseDir: layout.baseDir, target: layout.target, all: false, skills: [] }, { format: fmt }) + "\n");
6628
6979
  process.exitCode = 0;
6629
6980
  return;
6630
6981
  }
6631
- process.stdout.write(`${path6.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002
6982
+ process.stdout.write(`${path8.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002
6632
6983
  `);
6633
6984
  process.stdout.write(" \u5168\u90E8\u88C5\u9F50\uFF1Ahcm chiron skills sync\n");
6634
6985
  process.exitCode = 0;
@@ -6659,7 +7010,7 @@ async function listInstalledSkills(keyword, args) {
6659
7010
  const shown = sourceFilter === "all" ? byKeyword : byKeyword.filter((row) => row.sourceKind === sourceFilter);
6660
7011
  const groupOf = (kind) => kind === "cli" ? "CLI \u81EA\u5E26" : kind === "local" ? "\u672C\u5730\u76EE\u5F55\u88C5\u7684" : "\u777F\u620E\u6280\u80FD\u5E93";
6661
7012
  if (fmt === "json" || fmt === "yaml") {
6662
- process.stdout.write(formatObject16({
7013
+ process.stdout.write(formatObject17({
6663
7014
  baseDir: layout.baseDir,
6664
7015
  target: layout.target,
6665
7016
  endpoint: state.endpoint,
@@ -6733,7 +7084,7 @@ async function skillsShowCommand(id, args) {
6733
7084
  process.exitCode = 0;
6734
7085
  return;
6735
7086
  } catch (e) {
6736
- fail5(e, args);
7087
+ fail6(e, args);
6737
7088
  }
6738
7089
  }
6739
7090
  async function skillsInstallCommand(id, args) {
@@ -6750,7 +7101,7 @@ async function skillsInstallCommand(id, args) {
6750
7101
  let manifest2;
6751
7102
  let conflictNote;
6752
7103
  if (args.from) {
6753
- const root = path6.resolve(args.from);
7104
+ const root = path8.resolve(args.from);
6754
7105
  requestedIds = all ? await listLocalSkillIds(root) : [id];
6755
7106
  const seen = /* @__PURE__ */ new Set();
6756
7107
  documents = [];
@@ -6769,7 +7120,7 @@ async function skillsInstallCommand(id, args) {
6769
7120
  const tracked = decideTrackedEndpoint({
6770
7121
  explicit: Boolean(args.endpoint || args.env),
6771
7122
  current: await resolveEndpoint(args).catch((error) => {
6772
- if (error instanceof CliError19 && error.code === CliErrorCode18.NO_ACTIVE_ENV) return void 0;
7123
+ if (error instanceof CliError20 && error.code === CliErrorCode19.NO_ACTIVE_ENV) return void 0;
6773
7124
  throw error;
6774
7125
  }),
6775
7126
  recorded: (await readSkillsState(layout.baseDir))?.endpoint
@@ -6783,8 +7134,8 @@ async function skillsInstallCommand(id, args) {
6783
7134
  const catalog = buildUnifiedCatalog({ source, chironManifest: manifest2, bundled, cliVersion: CLI_VERSION });
6784
7135
  const conflicts = detectIdConflicts(catalog);
6785
7136
  if (conflicts.ids.length > 0) {
6786
- throw new CliError19({
6787
- code: CliErrorCode18.SKILL_ID_CONFLICT,
7137
+ throw new CliError20({
7138
+ code: CliErrorCode19.SKILL_ID_CONFLICT,
6788
7139
  message: conflictMessage(conflicts.ids, endpoint ?? "(\u672A\u77E5\u73AF\u5883)")
6789
7140
  });
6790
7141
  }
@@ -6862,7 +7213,7 @@ async function skillsInstallCommand(id, args) {
6862
7213
  const fmtCheck = args.output ?? "table";
6863
7214
  const would = documents.map((d) => d.id).sort();
6864
7215
  if (fmtCheck === "json" || fmtCheck === "yaml") {
6865
- process.stdout.write(formatObject16({
7216
+ process.stdout.write(formatObject17({
6866
7217
  dryRun: true,
6867
7218
  baseDir: layout.baseDir,
6868
7219
  target: layout.target,
@@ -6873,7 +7224,7 @@ async function skillsInstallCommand(id, args) {
6873
7224
  base
6874
7225
  }, { format: fmtCheck }) + "\n");
6875
7226
  } else {
6876
- process.stdout.write(`\u8FD9\u4E2A\u76EE\u5F55\u8FD8\u6CA1\u88C5\u8FC7\u6280\u80FD\uFF08${path6.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\uFF09\u3002
7227
+ process.stdout.write(`\u8FD9\u4E2A\u76EE\u5F55\u8FD8\u6CA1\u88C5\u8FC7\u6280\u80FD\uFF08${path8.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\uFF09\u3002
6877
7228
  `);
6878
7229
  process.stdout.write(`--check\uFF1A\u4F1A\u88C5 ${would.length} \u4E2A\u6280\u80FD\u5230 ${layout.baseDir}\uFF0C\u5E76\u628A\u7D22\u5F15\u4E0E\u9879\u76EE\u8FB9\u754C\u5757\u5199\u8FDB ${layout.agentsFile ?? "AGENTS.md"}\u3002**\u672C\u6B21\u4E00\u4E2A\u5B57\u8282\u90FD\u6CA1\u5199\u3002**
6879
7230
  `);
@@ -6896,9 +7247,9 @@ async function skillsInstallCommand(id, args) {
6896
7247
  const agents = agentIndexes[0]?.status;
6897
7248
  const fmt = args.output ?? "table";
6898
7249
  if (fmt === "json" || fmt === "yaml") {
6899
- process.stdout.write(formatObject16({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, agentIndexes, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
7250
+ process.stdout.write(formatObject17({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, agentIndexes, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
6900
7251
  } else {
6901
- const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path6.join(result.baseDir, id, "SKILL.md")}`;
7252
+ const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path8.join(result.baseDir, id, "SKILL.md")}`;
6902
7253
  process.stdout.write(`${headline}
6903
7254
  `);
6904
7255
  if (result.installed.length > 0) {
@@ -6917,14 +7268,14 @@ async function skillsInstallCommand(id, args) {
6917
7268
  `);
6918
7269
  }
6919
7270
  for (const index of agentIndexes) {
6920
- const reader = path6.basename(index.file) === "CLAUDE.md" ? "Claude Code" : "Codex";
7271
+ const reader = path8.basename(index.file) === "CLAUDE.md" ? "Claude Code" : "Codex";
6921
7272
  process.stdout.write(` \u5DF2${index.status === "created" ? "\u521B\u5EFA" : "\u66F4\u65B0"} ${index.file} \u91CC\u7684\u6280\u80FD\u7D22\u5F15\u4E0E\u9879\u76EE\u8FB9\u754C\u5757\uFF08${reader} \u8BFB\u8FD9\u91CC\uFF09
6922
7273
  `);
6923
7274
  }
6924
7275
  if (agentIndexes.some((i) => i.boundary === "cli-fallback")) {
6925
7276
  process.stdout.write(" \u26A0\uFE0F \u9879\u76EE\u8FB9\u754C\u5757\u7528\u7684\u662F CLI \u5185\u7F6E\u526F\u672C\uFF08\u8FD9\u4E2A\u73AF\u5883\u7684 /chiron.json \u6CA1\u5E26 agentBoundary\uFF09\uFF0C\u672A\u4E0E\u4EA7\u54C1\u7248\u672C\u6838\u5BF9\n");
6926
7277
  }
6927
- process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ? path6.resolve(args.from) : `@hcmai/cli@${CLI_VERSION}`)}
7278
+ process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ? path8.resolve(args.from) : `@hcmai/cli@${CLI_VERSION}`)}
6928
7279
  `);
6929
7280
  if (conflictNote) process.stdout.write(` \u26A0\uFE0F ${conflictNote}
6930
7281
  `);
@@ -6933,7 +7284,7 @@ async function skillsInstallCommand(id, args) {
6933
7284
  process.exitCode = 0;
6934
7285
  return;
6935
7286
  } catch (e) {
6936
- fail5(e, args);
7287
+ fail6(e, args);
6937
7288
  }
6938
7289
  }
6939
7290
  var FETCH_CONCURRENCY = 6;
@@ -6960,7 +7311,7 @@ async function listLocalSkillIds(root) {
6960
7311
  const ids = [];
6961
7312
  for (const entry of entries) {
6962
7313
  if (!entry.isDirectory()) continue;
6963
- if (await exists(path6.join(root, entry.name, "SKILL.md"))) ids.push(entry.name);
7314
+ if (await exists(path8.join(root, entry.name, "SKILL.md"))) ids.push(entry.name);
6964
7315
  }
6965
7316
  if (ids.length === 0) throw invalid(`\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709\u4EFB\u4F55 <id>/SKILL.md\uFF1A${root}`);
6966
7317
  return ids.sort();
@@ -6979,30 +7330,100 @@ async function fetchSkillDocument(http, skill, endpoint, base) {
6979
7330
  references
6980
7331
  };
6981
7332
  }
6982
- async function syncAgentIndexes(layout, manifest2) {
6983
- if (!layout.agentsFile) return [];
6984
- const state = await readSkillsState(layout.baseDir);
6985
- if (!state) return [];
6986
- const catalog = /* @__PURE__ */ new Map();
6987
- for (const category of manifest2?.categories ?? []) {
6988
- for (const skill of category.skills ?? []) catalog.set(skill.id, skill);
7333
+ async function ensureLocalSlot(localDir) {
7334
+ if (!localDir) return;
7335
+ const keep = path8.join(localDir, ".gitkeep");
7336
+ if (await fsp2.stat(localDir).then(() => true).catch(() => false)) return;
7337
+ await fsp2.mkdir(localDir, { recursive: true });
7338
+ await fsp2.writeFile(keep, "# \u4F60\u81EA\u5DF1\u5199\u7684\u6280\u80FD\u653E\u8FD9\u513F\u3002hcm chiron skills sync \u53EA\u7BA1\u9694\u58C1 sync/\uFF0C\u4E00\u4E2A\u5B57\u8282\u90FD\u4E0D\u78B0\u8FD9\u91CC\u3002\n", "utf8");
7339
+ }
7340
+ async function readLocalSkills(localDir) {
7341
+ if (!localDir) return [];
7342
+ let names;
7343
+ try {
7344
+ names = (await fsp2.readdir(localDir, { withFileTypes: true })).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name);
7345
+ } catch {
7346
+ return [];
6989
7347
  }
6990
- const files = [layout.agentsFile, ...layout.companionAgentFiles ?? []];
6991
- const results = [];
6992
- for (const file of files) {
6993
- const agentsDir = path6.dirname(file);
6994
- const entries = Object.keys(state.skills).sort().map((id) => {
6995
- const known = catalog.get(id);
6996
- const absolute = path6.join(layout.baseDir, id, "SKILL.md");
6997
- let relative2 = path6.relative(agentsDir, absolute);
6998
- if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
6999
- return {
7000
- id,
7001
- title: known?.title ?? id,
7002
- description: known?.description ?? "",
7003
- relativePath: relative2.split(path6.sep).join("/")
7348
+ const out = [];
7349
+ for (const id of names.sort()) {
7350
+ const absolute = path8.join(localDir, id, "SKILL.md");
7351
+ let markdown;
7352
+ try {
7353
+ markdown = await fsp2.readFile(absolute, "utf8");
7354
+ } catch {
7355
+ continue;
7356
+ }
7357
+ let title = id;
7358
+ let description = "";
7359
+ try {
7360
+ const frontmatter = parseSkillFrontmatter2(markdown, id);
7361
+ if (typeof frontmatter.title === "string" && frontmatter.title.trim()) title = frontmatter.title.trim();
7362
+ if (typeof frontmatter.description === "string" && frontmatter.description.trim()) {
7363
+ description = frontmatter.description.trim();
7364
+ }
7365
+ } catch {
7366
+ }
7367
+ out.push({ id, title, description, absolute });
7368
+ }
7369
+ return out;
7370
+ }
7371
+ async function syncAgentIndexes(layout, manifest2) {
7372
+ if (!layout.agentsFile) return [];
7373
+ const state = await readSkillsState(layout.baseDir);
7374
+ const local = await readLocalSkills(layout.localDir);
7375
+ if (!state && local.length === 0) return [];
7376
+ const catalog = /* @__PURE__ */ new Map();
7377
+ for (const category of manifest2?.categories ?? []) {
7378
+ for (const skill of category.skills ?? []) catalog.set(skill.id, skill);
7379
+ }
7380
+ await ensureLocalSlot(layout.localDir);
7381
+ const files = [layout.agentsFile, ...layout.companionAgentFiles ?? []];
7382
+ const results = [];
7383
+ for (const file of files) {
7384
+ const agentsDir = path8.dirname(file);
7385
+ const managed = await Promise.all(Object.keys(state?.skills ?? {}).sort().map(async (id) => {
7386
+ const known = catalog.get(id);
7387
+ const absolute = path8.join(layout.baseDir, id, "SKILL.md");
7388
+ let relative2 = path8.relative(agentsDir, absolute);
7389
+ if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
7390
+ let title = known?.title;
7391
+ let description = known?.description;
7392
+ if (title === void 0 || description === void 0) {
7393
+ const markdown = await readInstalled(layout.baseDir, id);
7394
+ if (markdown !== void 0) {
7395
+ try {
7396
+ const frontmatter = parseSkillFrontmatter2(markdown, id);
7397
+ const localTitle = frontmatter.title;
7398
+ const localDescription = frontmatter.description;
7399
+ if (title === void 0 && typeof localTitle === "string" && localTitle.trim()) title = localTitle.trim();
7400
+ if (description === void 0 && typeof localDescription === "string" && localDescription.trim()) {
7401
+ description = localDescription.trim();
7402
+ }
7403
+ } catch {
7404
+ }
7405
+ }
7406
+ }
7407
+ return {
7408
+ id,
7409
+ title: title ?? id,
7410
+ description: description ?? "",
7411
+ relativePath: relative2.split(path8.sep).join("/")
7412
+ };
7413
+ }));
7414
+ const shadowed = new Set(local.map((x) => x.id));
7415
+ const localEntries = local.map((x) => {
7416
+ let relative2 = path8.relative(agentsDir, x.absolute);
7417
+ if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
7418
+ const covers = managed.some((m) => m.id === x.id) ? `\uFF08\u4F60\u6539\u8FC7\u7684\u7248\u672C\uFF0C\u4EA7\u54C1\u90A3\u4E00\u4EFD\u5728 ${SKILLS_DIR}/${SKILLS_SYNC_SUBDIR}/${x.id}/\uFF0C\u540C\u6B65\u53EA\u66F4\u65B0\u90A3\u4E00\u4EFD\uFF09` : "";
7419
+ return {
7420
+ id: x.id,
7421
+ title: x.title,
7422
+ description: x.description ? `${x.description}${covers}` : covers,
7423
+ relativePath: relative2.split(path8.sep).join("/")
7004
7424
  };
7005
7425
  });
7426
+ const entries = [...managed.filter((m) => !shadowed.has(m.id)), ...localEntries].sort((a, b) => a.id.localeCompare(b.id));
7006
7427
  const status = await upsertAgentsBlock(file, renderAgentsBlock(entries));
7007
7428
  const before = await fsp2.readFile(file, "utf8").catch(() => "");
7008
7429
  const merged = mergeBoundaryBlock(before, manifest2?.agentBoundary);
@@ -7025,13 +7446,13 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
7025
7446
  throw invalid(`\u6280\u80FD\u4F9D\u8D56\u5B58\u5728\u73AF: ${[...pathStack.slice(Math.max(0, start)), id].join(" -> ")}`);
7026
7447
  }
7027
7448
  assertSafeSkillId(id);
7028
- const local = path6.join(sourceRoot, id, "SKILL.md");
7449
+ const local = path8.join(sourceRoot, id, "SKILL.md");
7029
7450
  let markdown;
7030
7451
  try {
7031
7452
  markdown = await fsp2.readFile(local, "utf8");
7032
7453
  } catch (cause) {
7033
7454
  if (cause?.code === "ENOENT") {
7034
- throw invalid(requiredBy ? `\u672C\u5730\u6280\u80FD ${requiredBy} \u4F9D\u8D56\u4E0D\u5B58\u5728: ${id}\uFF08${local}\uFF09` : `\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709 ${id}/SKILL.md\uFF1A${path6.join(sourceRoot, id)}`);
7455
+ throw invalid(requiredBy ? `\u672C\u5730\u6280\u80FD ${requiredBy} \u4F9D\u8D56\u4E0D\u5B58\u5728: ${id}\uFF08${local}\uFF09` : `\u672C\u5730\u76EE\u5F55\u91CC\u6CA1\u6709 ${id}/SKILL.md\uFF1A${path8.join(sourceRoot, id)}`);
7035
7456
  }
7036
7457
  throw cause;
7037
7458
  }
@@ -7043,7 +7464,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
7043
7464
  markdown,
7044
7465
  source: local,
7045
7466
  sourceKind: "local",
7046
- references: await readLocalReferences(path6.join(sourceRoot, id))
7467
+ references: await readLocalReferences(path8.join(sourceRoot, id))
7047
7468
  };
7048
7469
  for (const required2 of parseSkillRequirements2(markdown, id)) {
7049
7470
  await visit(required2, id);
@@ -7057,7 +7478,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
7057
7478
  }
7058
7479
  async function readSkillsState(baseDir) {
7059
7480
  try {
7060
- const raw = await fsp2.readFile(path6.join(baseDir, SKILLS_STATE_FILE), "utf8");
7481
+ const raw = await fsp2.readFile(path8.join(baseDir, SKILLS_STATE_FILE), "utf8");
7061
7482
  const parsed = JSON.parse(raw);
7062
7483
  if (!parsed || typeof parsed !== "object" || !parsed.skills) return void 0;
7063
7484
  return migrateSkillsState(parsed);
@@ -7067,7 +7488,7 @@ async function readSkillsState(baseDir) {
7067
7488
  }
7068
7489
  async function writeSkillsState(baseDir, state) {
7069
7490
  await fsp2.mkdir(baseDir, { recursive: true });
7070
- const file = path6.join(baseDir, SKILLS_STATE_FILE);
7491
+ const file = path8.join(baseDir, SKILLS_STATE_FILE);
7071
7492
  const temp = `${file}.${process.pid}.tmp`;
7072
7493
  await fsp2.writeFile(temp, JSON.stringify(state, null, 2) + "\n", "utf8");
7073
7494
  await fsp2.rename(temp, file);
@@ -7085,7 +7506,11 @@ function renderAgentsBlock(entries) {
7085
7506
  ];
7086
7507
  for (const e of entries) {
7087
7508
  lines.push(`- \`${e.relativePath}\` \u2014 **${e.title}**`);
7088
- if (e.description) lines.push(` ${e.description}`);
7509
+ if (e.description) {
7510
+ lines.push(` ${e.description}`);
7511
+ } else {
7512
+ lines.push(" \uFF08\u67E5\u4E0D\u5230\u63CF\u8FF0\uFF1A\u4EA7\u54C1\u76EE\u5F55\u91CC\u6CA1\u6709\u5B83\uFF0C\u76D8\u4E0A\u90A3\u4EFD SKILL.md \u7684 frontmatter \u4E5F\u6CA1\u7ED9\u3002\u8981\u7528\u5B83\u5C31\u5148\u6253\u5F00\u8BFB\u4E00\u773C\u3002\uFF09");
7513
+ }
7089
7514
  }
7090
7515
  lines.push("", AGENTS_BLOCK_END);
7091
7516
  return lines.join("\n");
@@ -7096,7 +7521,7 @@ async function upsertAgentsBlock(agentsFile, block) {
7096
7521
  existing = await fsp2.readFile(agentsFile, "utf8");
7097
7522
  } catch (cause) {
7098
7523
  if (cause?.code !== "ENOENT") throw cause;
7099
- await fsp2.mkdir(path6.dirname(agentsFile), { recursive: true });
7524
+ await fsp2.mkdir(path8.dirname(agentsFile), { recursive: true });
7100
7525
  await fsp2.writeFile(agentsFile, block + "\n", "utf8");
7101
7526
  return "created";
7102
7527
  }
@@ -7122,7 +7547,7 @@ async function installSkillDocuments(documents, requestedIds, baseDir, force, me
7122
7547
  if (!document.markdown.trim()) throw invalid(`\u6280\u80FD ${document.id} \u5185\u5BB9\u4E3A\u7A7A`);
7123
7548
  return {
7124
7549
  ...document,
7125
- target: path6.join(baseDir, document.id, "SKILL.md"),
7550
+ target: path8.join(baseDir, document.id, "SKILL.md"),
7126
7551
  bytes: Buffer.byteLength(document.markdown)
7127
7552
  };
7128
7553
  });
@@ -7173,7 +7598,7 @@ async function sameOnDisk(baseDir, candidate) {
7173
7598
  return true;
7174
7599
  }
7175
7600
  async function readLocalReferences(skillDir) {
7176
- const root = path6.join(skillDir, "references");
7601
+ const root = path8.join(skillDir, "references");
7177
7602
  const out = [];
7178
7603
  const walk = async (dir, prefix) => {
7179
7604
  let items;
@@ -7186,12 +7611,12 @@ async function readLocalReferences(skillDir) {
7186
7611
  for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
7187
7612
  const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
7188
7613
  if (item.isDirectory()) {
7189
- await walk(path6.join(dir, item.name), relative2);
7614
+ await walk(path8.join(dir, item.name), relative2);
7190
7615
  continue;
7191
7616
  }
7192
7617
  if (!item.isFile()) continue;
7193
7618
  assertSafeReferencePath2(relative2);
7194
- out.push({ path: relative2, content: await fsp2.readFile(path6.join(dir, item.name), "utf8") });
7619
+ out.push({ path: relative2, content: await fsp2.readFile(path8.join(dir, item.name), "utf8") });
7195
7620
  }
7196
7621
  };
7197
7622
  await walk(root, "");
@@ -7223,10 +7648,10 @@ async function removeRenamedSkills(baseDir, renamed) {
7223
7648
  const state = await readSkillsState(baseDir);
7224
7649
  for (const { from } of renamed) {
7225
7650
  assertSafeSkillId(from);
7226
- const dir = path6.join(baseDir, from);
7227
- const resolved = path6.resolve(dir);
7228
- if (resolved !== path6.join(path6.resolve(baseDir), from)) continue;
7229
- const hasSkillFile = await fsp2.stat(path6.join(dir, "SKILL.md")).then(() => true).catch(() => false);
7651
+ const dir = path8.join(baseDir, from);
7652
+ const resolved = path8.resolve(dir);
7653
+ if (resolved !== path8.join(path8.resolve(baseDir), from)) continue;
7654
+ const hasSkillFile = await fsp2.stat(path8.join(dir, "SKILL.md")).then(() => true).catch(() => false);
7230
7655
  const exists2 = await fsp2.stat(dir).then(() => true).catch(() => false);
7231
7656
  if (exists2 && !hasSkillFile) {
7232
7657
  kept.push({ from, kept: "\u76EE\u5F55\u91CC\u6CA1\u6709 SKILL.md\uFF0C\u50CF\u662F\u4F60\u81EA\u5DF1\u653E\u7684\u4E1C\u897F\uFF0C\u6CA1\u6709\u5220" });
@@ -7243,15 +7668,15 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
7243
7668
  const removed = [];
7244
7669
  try {
7245
7670
  for (const document of documents) {
7246
- const target = path6.join(baseDir, document.id, "SKILL.md");
7247
- await fsp2.mkdir(path6.dirname(target), { recursive: true });
7248
- const temp = path6.join(path6.dirname(target), `.SKILL.md.${process.pid}.${Date.now()}.tmp`);
7671
+ const target = path8.join(baseDir, document.id, "SKILL.md");
7672
+ await fsp2.mkdir(path8.dirname(target), { recursive: true });
7673
+ const temp = path8.join(path8.dirname(target), `.SKILL.md.${process.pid}.${Date.now()}.tmp`);
7249
7674
  await fsp2.writeFile(temp, document.markdown, "utf8");
7250
7675
  staged.push({ temp, target });
7251
7676
  for (const reference of document.references ?? []) {
7252
7677
  assertSafeReferencePath2(reference.path);
7253
- const referenceTarget = path6.join(baseDir, document.id, "references", reference.path);
7254
- await fsp2.mkdir(path6.dirname(referenceTarget), { recursive: true });
7678
+ const referenceTarget = path8.join(baseDir, document.id, "references", reference.path);
7679
+ await fsp2.mkdir(path8.dirname(referenceTarget), { recursive: true });
7255
7680
  const referenceTemp = `${referenceTarget}.${process.pid}.${Date.now()}.tmp`;
7256
7681
  await fsp2.writeFile(referenceTemp, reference.content, "utf8");
7257
7682
  staged.push({ temp: referenceTemp, target: referenceTarget });
@@ -7259,7 +7684,7 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
7259
7684
  }
7260
7685
  for (const stale of removals) {
7261
7686
  assertSafeReferencePath2(stale.path);
7262
- const original = path6.join(baseDir, stale.id, "references", stale.path);
7687
+ const original = path8.join(baseDir, stale.id, "references", stale.path);
7263
7688
  const parked = `${original}.${process.pid}.${Date.now()}.removed`;
7264
7689
  await fsp2.rename(original, parked);
7265
7690
  removed.push({ parked, original });
@@ -7305,11 +7730,11 @@ async function recordInstalled(baseDir, documents, meta2) {
7305
7730
  return state;
7306
7731
  }
7307
7732
  function invalid(message) {
7308
- return new CliError19({ code: CliErrorCode18.INVALID_ARGUMENT, message });
7733
+ return new CliError20({ code: CliErrorCode19.INVALID_ARGUMENT, message });
7309
7734
  }
7310
7735
  async function readInstalled(baseDir, id) {
7311
7736
  try {
7312
- return await fsp2.readFile(path6.join(baseDir, id, "SKILL.md"), "utf8");
7737
+ return await fsp2.readFile(path8.join(baseDir, id, "SKILL.md"), "utf8");
7313
7738
  } catch (cause) {
7314
7739
  if (cause?.code === "ENOENT") return void 0;
7315
7740
  throw cause;
@@ -7317,7 +7742,7 @@ async function readInstalled(baseDir, id) {
7317
7742
  }
7318
7743
  async function readInstalledReference(baseDir, id, relative2) {
7319
7744
  try {
7320
- return await fsp2.readFile(path6.join(baseDir, id, "references", relative2), "utf8");
7745
+ return await fsp2.readFile(path8.join(baseDir, id, "references", relative2), "utf8");
7321
7746
  } catch (cause) {
7322
7747
  if (cause?.code === "ENOENT") return void 0;
7323
7748
  throw cause;
@@ -7413,10 +7838,11 @@ async function planSkillUpdate(options) {
7413
7838
  const fetch2 = async () => item.kind === "cli" ? await fetchBundled(id) : await fetchDocument(item.skill);
7414
7839
  if (onDisk === void 0) {
7415
7840
  documents.push(await fetch2());
7841
+ const renamedFromId = renamedPairs.find((pair) => pair.to === id)?.from;
7416
7842
  entries.push({
7417
7843
  id,
7418
7844
  status: "added",
7419
- note: record ? "\u672C\u5730\u6587\u4EF6\u7F3A\u5931\uFF0C\u91CD\u65B0\u88C5\u56DE" : all ? "\u4EA7\u54C1\u8FD9\u4E00\u7248\u65B0\u589E\u7684\u6280\u80FD" : "\u4EA7\u54C1\u65B0\u589E\u7684\u524D\u7F6E\u6280\u80FD"
7845
+ note: renamedFromId ? `${renamedFromId} \u6539\u540D\u540E\u7684\u65B0\u540D\uFF0C\u5185\u5BB9\u642C\u5230\u4E86\u8FD9\u91CC` : record ? "\u672C\u5730\u6587\u4EF6\u7F3A\u5931\uFF0C\u91CD\u65B0\u88C5\u56DE" : all ? "\u4EA7\u54C1\u8FD9\u4E00\u7248\u65B0\u589E\u7684\u6280\u80FD" : "\u4EA7\u54C1\u65B0\u589E\u7684\u524D\u7F6E\u6280\u80FD"
7420
7846
  });
7421
7847
  continue;
7422
7848
  }
@@ -7438,7 +7864,7 @@ async function planSkillUpdate(options) {
7438
7864
  entries.push({
7439
7865
  id,
7440
7866
  status: "locally-modified",
7441
- note: "\u672C\u5730\u6539\u8FC7\uFF0C\u6CA1\u6709\u8986\u76D6\uFF1B\u786E\u5B9A\u8981\u7528\u4EA7\u54C1\u8FD9\u4E00\u7248\u5C31\u52A0 --force"
7867
+ note: `\u672C\u5730\u6539\u8FC7\uFF0C\u6CA1\u6709\u8986\u76D6\u3002${SKILLS_SYNC_SUBDIR}/ \u5F52\u4EA7\u54C1\uFF1A\u628A\u8FD9\u4EFD\u6539\u52A8\u632A\u5230 ${SKILLS_LOCAL_SUBDIR}/${id}/ \u5C31\u80FD\u957F\u671F\u7559\u4F4F\uFF08\u540C\u540D\u65F6\u5B83\u906E\u853D\u4EA7\u54C1\u90A3\u4EFD\uFF0C\u4EA7\u54C1\u90A3\u4EFD\u7EE7\u7EED\u8DDF\u7740\u66F4\u65B0\uFF09\uFF1B\u786E\u5B9A\u8981\u4E22\u5F03\u6539\u52A8\u624D\u7528 --force`
7442
7868
  });
7443
7869
  continue;
7444
7870
  }
@@ -7470,16 +7896,16 @@ async function skillsUpdateCommand(args) {
7470
7896
  const layout = await resolveInstallLayout(args);
7471
7897
  const state = await readSkillsState(layout.baseDir);
7472
7898
  if (!state || Object.keys(state.skills).length === 0) {
7473
- throw new CliError19({
7474
- code: CliErrorCode18.INVALID_ARGUMENT,
7475
- message: `${path6.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u6709\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002\u5148\u8DD1 \`hcm chiron skills sync\`\uFF1B\u5982\u679C\u6280\u80FD\u662F\u624B\u5DE5\u62F7\u8FDB\u6765\u7684\uFF0C\u540C\u6B65\u4E00\u6B21\u5373\u53EF\u63A5\u7BA1\u5347\u7EA7\u3002`
7899
+ throw new CliError20({
7900
+ code: CliErrorCode19.INVALID_ARGUMENT,
7901
+ message: `${path8.join(layout.baseDir, SKILLS_STATE_FILE)} \u4E0D\u5B58\u5728\u6216\u4E3A\u7A7A \u2014\u2014 \u8FD9\u4E2A\u76EE\u5F55\u4E0B\u8FD8\u6CA1\u6709\u7528\u672C CLI \u88C5\u8FC7\u6280\u80FD\u3002\u5148\u8DD1 \`hcm chiron skills sync\`\uFF1B\u5982\u679C\u6280\u80FD\u662F\u624B\u5DE5\u62F7\u8FDB\u6765\u7684\uFF0C\u540C\u6B65\u4E00\u6B21\u5373\u53EF\u63A5\u7BA1\u5347\u7EA7\u3002`
7476
7902
  });
7477
7903
  }
7478
7904
  const source = parseSourceFilter(args.source);
7479
7905
  const endpoint = decideTrackedEndpoint({
7480
7906
  explicit: Boolean(args.endpoint || args.env),
7481
7907
  current: await resolveEndpoint(args).catch((error) => {
7482
- if (error instanceof CliError19 && error.code === CliErrorCode18.NO_ACTIVE_ENV) return void 0;
7908
+ if (error instanceof CliError20 && error.code === CliErrorCode19.NO_ACTIVE_ENV) return void 0;
7483
7909
  throw error;
7484
7910
  }),
7485
7911
  recorded: state.endpoint
@@ -7525,7 +7951,7 @@ async function skillsUpdateCommand(args) {
7525
7951
  const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");
7526
7952
  const fmt = args.output ?? "table";
7527
7953
  if (fmt === "json" || fmt === "yaml") {
7528
- process.stdout.write(formatObject16({
7954
+ process.stdout.write(formatObject17({
7529
7955
  endpoint,
7530
7956
  baseDir: layout.baseDir,
7531
7957
  target: layout.target,
@@ -7601,9 +8027,37 @@ async function skillsUpdateCommand(args) {
7601
8027
  process.exitCode = 0;
7602
8028
  return;
7603
8029
  } catch (e) {
7604
- fail5(e, args);
8030
+ fail6(e, args);
7605
8031
  }
7606
8032
  }
8033
+ async function migrateFlatSkillsLayout(skillsRoot) {
8034
+ const legacyState = path8.join(skillsRoot, SKILLS_STATE_FILE);
8035
+ const syncDir = path8.join(skillsRoot, SKILLS_SYNC_SUBDIR);
8036
+ const localDir = path8.join(skillsRoot, SKILLS_LOCAL_SUBDIR);
8037
+ const hasLegacy = await fsp2.stat(legacyState).then(() => true).catch(() => false);
8038
+ if (!hasLegacy) return { moved: [], migrated: false };
8039
+ const state = await readSkillsState(skillsRoot);
8040
+ const owned = new Set(Object.keys(state?.skills ?? {}));
8041
+ let names;
8042
+ try {
8043
+ names = (await fsp2.readdir(skillsRoot, { withFileTypes: true })).filter((e) => e.isDirectory() && !e.name.startsWith(".")).map((e) => e.name).filter((n) => n !== SKILLS_SYNC_SUBDIR && n !== SKILLS_LOCAL_SUBDIR).sort();
8044
+ } catch {
8045
+ return { moved: [], migrated: false };
8046
+ }
8047
+ const moved = [];
8048
+ for (const id of names) {
8049
+ const hasSkill = await fsp2.stat(path8.join(skillsRoot, id, "SKILL.md")).then(() => true).catch(() => false);
8050
+ if (!hasSkill) continue;
8051
+ const to = owned.has(id) ? "sync" : "local";
8052
+ const target = path8.join(to === "sync" ? syncDir : localDir, id);
8053
+ await fsp2.mkdir(path8.dirname(target), { recursive: true });
8054
+ await fsp2.rename(path8.join(skillsRoot, id), target);
8055
+ moved.push({ id, to });
8056
+ }
8057
+ await fsp2.mkdir(syncDir, { recursive: true });
8058
+ await fsp2.rename(legacyState, path8.join(syncDir, SKILLS_STATE_FILE));
8059
+ return { moved, migrated: true };
8060
+ }
7607
8061
  function assertSyncArgs(args) {
7608
8062
  const only = (args.only ?? []).filter((id) => id.trim().length > 0);
7609
8063
  if (only.length > 0 && args.check) {
@@ -7619,6 +8073,11 @@ var defaultSkillsSyncDeps = {
7619
8073
  if (!layout) return false;
7620
8074
  const state = await readSkillsState(layout.baseDir).catch(() => void 0);
7621
8075
  return Boolean(state && Object.keys(state.skills).length > 0);
8076
+ },
8077
+ migrate: async (args) => {
8078
+ const layout = await resolveInstallLayout(args).catch(() => null);
8079
+ if (!layout || !layout.localDir) return { moved: [], migrated: false };
8080
+ return migrateFlatSkillsLayout(path8.dirname(layout.baseDir)).catch(() => ({ moved: [], migrated: false }));
7622
8081
  }
7623
8082
  };
7624
8083
  async function skillsSyncCommand(args, deps = defaultSkillsSyncDeps) {
@@ -7628,6 +8087,19 @@ async function skillsSyncCommand(args, deps = defaultSkillsSyncDeps) {
7628
8087
  } catch (e) {
7629
8088
  return exitWithError(e);
7630
8089
  }
8090
+ if (!args.check) {
8091
+ const result = await deps.migrate(args);
8092
+ if (result.migrated) {
8093
+ const toSync = result.moved.filter((m) => m.to === "sync");
8094
+ const toLocal = result.moved.filter((m) => m.to === "local");
8095
+ process.stderr.write(`\u2192 \u6280\u80FD\u76EE\u5F55\u5DF2\u5206\u6210\u4E24\u534A\uFF1A${SKILLS_DIR}/${SKILLS_SYNC_SUBDIR}/\uFF08\u4EA7\u54C1\u7684\uFF0C\u540C\u6B65\u5168\u6743\uFF09 \u4E0E ${SKILLS_DIR}/${SKILLS_LOCAL_SUBDIR}/\uFF08\u4F60\u81EA\u5DF1\u7684\uFF0C\u540C\u6B65\u4E0D\u78B0\uFF09
8096
+ `);
8097
+ process.stderr.write(` \u642C\u8FDB ${SKILLS_SYNC_SUBDIR}/\uFF1A${toSync.length} \u4EFD${toLocal.length > 0 ? `\uFF1B\u642C\u8FDB ${SKILLS_LOCAL_SUBDIR}/\uFF1A${toLocal.length} \u4EFD\uFF08${toLocal.map((m) => m.id).join("\u3001")}\uFF09` : ""}
8098
+ `);
8099
+ process.stderr.write(` \u26A0\uFE0F ${SKILLS_SYNC_SUBDIR}/ \u91CC\u7684\u6539\u52A8\u4EE5\u540E\u4F1A\u88AB\u540C\u6B65\u8986\u76D6\uFF1B\u8981\u4FDD\u4F4F\u54EA\u4E00\u4EFD\uFF0C\u628A\u5B83\u632A\u5230 ${SKILLS_LOCAL_SUBDIR}/\uFF08\u540C\u540D\u65F6 ${SKILLS_LOCAL_SUBDIR}/ \u4F18\u5148\uFF0C\u4EA7\u54C1\u90A3\u4EFD\u7EE7\u7EED\u66F4\u65B0\uFF09\u3002
8100
+ `);
8101
+ }
8102
+ }
7631
8103
  if (only.length > 0) {
7632
8104
  for (const id of only) {
7633
8105
  await deps.install(id, { ...args, all: false });
@@ -7644,15 +8116,15 @@ import {
7644
8116
  bootstrapTenant,
7645
8117
  discoverProjectEnv as discoverProjectEnv3,
7646
8118
  assertDangerWrite as assertDangerWrite3,
7647
- normalizeOrigin as normalizeOrigin2,
8119
+ normalizeOrigin as normalizeOrigin4,
7648
8120
  createHttpClient as createHttpClient3,
7649
- formatObject as formatObject17,
8121
+ formatObject as formatObject18,
7650
8122
  fromAxiosError as fromAxiosError17,
7651
8123
  loadGlobalConfig as loadGlobalConfig7,
7652
8124
  resolveEnvContext as resolveEnvContext6,
7653
8125
  printResolvedEnvironment as printResolvedEnvironment5,
7654
- CliError as CliError20,
7655
- CliErrorCode as CliErrorCode19
8126
+ CliError as CliError21,
8127
+ CliErrorCode as CliErrorCode20
7656
8128
  } from "@hcmai/sdk";
7657
8129
  init_exit();
7658
8130
  async function resolveBootstrapKey(args, stdinTaken) {
@@ -7660,8 +8132,8 @@ async function resolveBootstrapKey(args, stdinTaken) {
7660
8132
  if (fromEnv) return fromEnv;
7661
8133
  if (args.bootstrapKeyStdin) {
7662
8134
  if (stdinTaken) {
7663
- throw new CliError20({
7664
- code: CliErrorCode19.INVALID_ARGUMENT,
8135
+ throw new CliError21({
8136
+ code: CliErrorCode20.INVALID_ARGUMENT,
7665
8137
  message: "--bootstrap-key-stdin \u4E0E --admin-password-stdin \u4E0D\u80FD\u540C\u65F6\u7528\uFF08stdin \u53EA\u6709\u4E00\u8DEF\uFF09\uFF1B\u628A\u5176\u4E2D\u4E00\u4E2A\u6539\u8D70 HCM_BOOTSTRAP_KEY \u73AF\u5883\u53D8\u91CF\u6216\u4EA4\u4E92\u8F93\u5165"
7666
8138
  });
7667
8139
  }
@@ -7692,8 +8164,8 @@ async function resolveEndpoint2(args) {
7692
8164
  printResolvedEnvironment5(resolved);
7693
8165
  const env2 = resolved.config;
7694
8166
  if (!env2?.endpoint) {
7695
- throw new CliError20({
7696
- code: CliErrorCode19.MISSING_FLAG,
8167
+ throw new CliError21({
8168
+ code: CliErrorCode20.MISSING_FLAG,
7697
8169
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
7698
8170
  });
7699
8171
  }
@@ -7702,14 +8174,14 @@ async function resolveEndpoint2(args) {
7702
8174
  async function tenantBootstrapCommand(args) {
7703
8175
  try {
7704
8176
  if (!args.tenantId || !args.adminUsername) {
7705
- throw new CliError20({
7706
- code: CliErrorCode19.MISSING_FLAG,
8177
+ throw new CliError21({
8178
+ code: CliErrorCode20.MISSING_FLAG,
7707
8179
  message: "--tenant-id \u4E0E --admin-username \u5FC5\u586B"
7708
8180
  });
7709
8181
  }
7710
8182
  const endpoint = await resolveEndpoint2(args);
7711
8183
  const project = await discoverProjectEnv3();
7712
- const protectedNames = project ? Object.entries(project.config.environments).filter(([, candidate]) => candidate.danger && candidate.endpoint === normalizeOrigin2(endpoint)).map(([name]) => name) : [];
8184
+ const protectedNames = project ? Object.entries(project.config.environments).filter(([, candidate]) => candidate.danger && candidate.endpoint === normalizeOrigin4(endpoint)).map(([name]) => name) : [];
7713
8185
  assertDangerWrite3({ name: protectedNames.join(", "), danger: protectedNames.length > 0, allowDanger: args.allowDanger }, "\u5F00\u901A\u79DF\u6237");
7714
8186
  if (args.endpoint) process.stderr.write(`\u2192 ${endpoint} \xB7 \u79DF\u6237 ${args.tenantId} \xB7 \u8EAB\u4EFD bootstrap key\uFF08\u6765\u81EA --endpoint\uFF09
7715
8187
  `);
@@ -7744,7 +8216,7 @@ async function tenantBootstrapCommand(args) {
7744
8216
  `
7745
8217
  );
7746
8218
  }
7747
- process.stdout.write(formatObject17(result, { format: fmt }) + "\n");
8219
+ process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
7748
8220
  process.exitCode = 0;
7749
8221
  return;
7750
8222
  } catch (e) {
@@ -7761,11 +8233,11 @@ async function tenantBootstrapCommand(args) {
7761
8233
 
7762
8234
  // src/commands/meta.ts
7763
8235
  import { promises as fsp3 } from "fs";
7764
- import os3 from "os";
8236
+ import os4 from "os";
7765
8237
  import nodePath from "path";
7766
8238
  import {
7767
8239
  HcmClient as HcmClient18,
7768
- formatObject as formatObject18,
8240
+ formatObject as formatObject19,
7769
8241
  fromAxiosError as fromAxiosError18,
7770
8242
  listTenantMeta,
7771
8243
  getTenantMeta,
@@ -7776,8 +8248,8 @@ import {
7776
8248
  formatMetaIssues,
7777
8249
  explainJacksonError,
7778
8250
  META_SCHEMA_SOURCE_COMMIT,
7779
- CliError as CliError21,
7780
- CliErrorCode as CliErrorCode20
8251
+ CliError as CliError22,
8252
+ CliErrorCode as CliErrorCode21
7781
8253
  } from "@hcmai/sdk";
7782
8254
  init_exit();
7783
8255
  init_impersonation_lifecycle();
@@ -7785,7 +8257,7 @@ init_auth_guard();
7785
8257
  async function client2(args) {
7786
8258
  return HcmClient18.fromAuthContext(await getActiveAuthContextFromCli(args));
7787
8259
  }
7788
- function fail6(e, args) {
8260
+ function fail7(e, args) {
7789
8261
  const err = e;
7790
8262
  if (err?.response?.status === 403) {
7791
8263
  exitWithError(
@@ -7808,27 +8280,27 @@ async function metaListCommand(args) {
7808
8280
  const fmt = args.output ?? "json";
7809
8281
  if (fmt !== "json") process.stdout.write(`\u{1F4C4} ${items.length} \u4EFD${total ? ` / \u5171 ${total}` : ""}
7810
8282
  `);
7811
- process.stdout.write(formatObject18(items, { format: fmt }) + "\n");
8283
+ process.stdout.write(formatObject19(items, { format: fmt }) + "\n");
7812
8284
  process.exitCode = 0;
7813
8285
  return;
7814
8286
  } catch (e) {
7815
- fail6(e, args);
8287
+ fail7(e, args);
7816
8288
  }
7817
8289
  }
7818
- async function metaGetCommand(path17, args) {
8290
+ async function metaGetCommand(path18, args) {
7819
8291
  try {
7820
8292
  const c = await client2(args);
7821
- const content = await getTenantMeta(c.raw(), path17);
8293
+ const content = await getTenantMeta(c.raw(), path18);
7822
8294
  process.stdout.write(content.endsWith("\n") ? content : content + "\n");
7823
8295
  process.exitCode = 0;
7824
8296
  return;
7825
8297
  } catch (e) {
7826
- fail6(e, args);
8298
+ fail7(e, args);
7827
8299
  }
7828
8300
  }
7829
8301
  var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
7830
- function parseMetaPath(path17) {
7831
- const base = path17.split(/[\\/]/).pop() ?? path17;
8302
+ function parseMetaPath(path18) {
8303
+ const base = path18.split(/[\\/]/).pop() ?? path18;
7832
8304
  if (!/\.(yml|yaml)$/i.test(base)) return {};
7833
8305
  const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
7834
8306
  return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
@@ -7845,10 +8317,10 @@ function unverifiableReason(e) {
7845
8317
  if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
7846
8318
  return void 0;
7847
8319
  }
7848
- async function verifyAfterWrite(c, path17) {
7849
- const { model, kind, state } = parseMetaPath(path17);
8320
+ async function verifyAfterWrite(c, path18) {
8321
+ const { model, kind, state } = parseMetaPath(path18);
7850
8322
  if (!model || !kind) {
7851
- return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path17} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
8323
+ return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path18} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
7852
8324
  }
7853
8325
  try {
7854
8326
  await clearMetaCache2(c.raw(), model, {});
@@ -7893,11 +8365,11 @@ async function verifyAfterWrite(c, path17) {
7893
8365
  }
7894
8366
  return { status: "ok" };
7895
8367
  }
7896
- async function metaSetCommand(path17, args) {
8368
+ async function metaSetCommand(path18, args) {
7897
8369
  try {
7898
8370
  if (!args.file) {
7899
- throw new CliError21({
7900
- code: CliErrorCode20.MISSING_FLAG,
8371
+ throw new CliError22({
8372
+ code: CliErrorCode21.MISSING_FLAG,
7901
8373
  message: "--file <path> \u5FC5\u586B\uFF08\u4ECE\u6587\u4EF6\u8BFB\u53D6 meta \u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
7902
8374
  });
7903
8375
  }
@@ -7909,9 +8381,9 @@ async function metaSetCommand(path17, args) {
7909
8381
  process.stdin.on("error", reject);
7910
8382
  }) : await fsp3.readFile(args.file, "utf8");
7911
8383
  if (!args.skipValidate) {
7912
- const result2 = validateMetaContent(path17, content);
8384
+ const result2 = validateMetaContent(path18, content);
7913
8385
  if (result2.issues.length > 0) {
7914
- process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path17}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
8386
+ process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path18}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
7915
8387
  `);
7916
8388
  process.stderr.write(formatMetaIssues(result2, " ") + "\n");
7917
8389
  }
@@ -7929,14 +8401,14 @@ async function metaSetCommand(path17, args) {
7929
8401
  const dryFmt = args.output;
7930
8402
  if (dryFmt === "json" || dryFmt === "yaml") {
7931
8403
  process.stdout.write(
7932
- formatObject18(
7933
- { dryRun: true, path: path17, bytes: Buffer.byteLength(content), content },
8404
+ formatObject19(
8405
+ { dryRun: true, path: path18, bytes: Buffer.byteLength(content), content },
7934
8406
  { format: dryFmt }
7935
8407
  ) + "\n"
7936
8408
  );
7937
8409
  } else {
7938
8410
  process.stdout.write(
7939
- `[dry-run] \u5C06\u5199\u5165 ${path17}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
8411
+ `[dry-run] \u5C06\u5199\u5165 ${path18}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
7940
8412
  ---
7941
8413
  ${content}
7942
8414
  `
@@ -7950,13 +8422,13 @@ ${content}
7950
8422
  let backupState = "unknown";
7951
8423
  let backupWhy;
7952
8424
  try {
7953
- const prev = await getTenantMeta(c.raw(), path17);
8425
+ const prev = await getTenantMeta(c.raw(), path18);
7954
8426
  if (!prev || prev.trim() === "") {
7955
8427
  backupState = "absent";
7956
8428
  } else {
7957
8429
  backupFile = nodePath.join(
7958
- os3.tmpdir(),
7959
- `hcm-meta-backup-${Date.now()}-${path17.replace(/[\\/]/g, "_")}`
8430
+ os4.tmpdir(),
8431
+ `hcm-meta-backup-${Date.now()}-${path18.replace(/[\\/]/g, "_")}`
7960
8432
  );
7961
8433
  await fsp3.writeFile(backupFile, prev, "utf8");
7962
8434
  backupState = "saved";
@@ -7971,22 +8443,22 @@ ${content}
7971
8443
  backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
7972
8444
  }
7973
8445
  }
7974
- const result = await saveTenantMeta(c.raw(), path17, content);
8446
+ const result = await saveTenantMeta(c.raw(), path18, content);
7975
8447
  const fmt = args.output ?? "json";
7976
- if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path17}
8448
+ if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path18}
7977
8449
  `);
7978
8450
  const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
7979
- \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path17} --file ${backupFile}${connFlags(args)}
7980
- ` : 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 ${path17}${connFlags(args)}
8451
+ \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path18} --file ${backupFile}${connFlags(args)}
8452
+ ` : 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 ${path18}${connFlags(args)}
7981
8453
  ` : ` \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
7982
- \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path17}${connFlags(args)}
8454
+ \u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path18}${connFlags(args)}
7983
8455
  `;
7984
8456
  if (args.verify === false) {
7985
8457
  process.stderr.write(
7986
8458
  "\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
7987
8459
  );
7988
8460
  } else {
7989
- const outcome = await verifyAfterWrite(c, path17);
8461
+ const outcome = await verifyAfterWrite(c, path18);
7990
8462
  if (outcome.status === "broken") {
7991
8463
  const human = explainJacksonError(outcome.raw);
7992
8464
  process.stderr.write(
@@ -8012,40 +8484,40 @@ ${content}
8012
8484
  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");
8013
8485
  }
8014
8486
  }
8015
- process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
8487
+ process.stdout.write(formatObject19(result, { format: fmt }) + "\n");
8016
8488
  process.exitCode = 0;
8017
8489
  return;
8018
8490
  } catch (e) {
8019
8491
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
8020
- fail6(e, args);
8492
+ fail7(e, args);
8021
8493
  }
8022
8494
  }
8023
- async function metaDeleteCommand(path17, args) {
8495
+ async function metaDeleteCommand(path18, args) {
8024
8496
  try {
8025
8497
  if (!args.yes) {
8026
- const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path17}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
8498
+ const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path18}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
8027
8499
  if (!ok) {
8028
8500
  process.stderr.write("\u5DF2\u53D6\u6D88\n");
8029
8501
  process.exit(1);
8030
8502
  }
8031
8503
  }
8032
8504
  const c = await client2(args);
8033
- const result = await deleteTenantMeta(c.raw(), path17);
8505
+ const result = await deleteTenantMeta(c.raw(), path18);
8034
8506
  const fmt = args.output ?? "json";
8035
- if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path17}
8507
+ if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path18}
8036
8508
  `);
8037
- process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
8509
+ process.stdout.write(formatObject19(result, { format: fmt }) + "\n");
8038
8510
  process.exitCode = 0;
8039
8511
  return;
8040
8512
  } catch (e) {
8041
- fail6(e, args);
8513
+ fail7(e, args);
8042
8514
  }
8043
8515
  }
8044
- async function metaValidateCommand(path17, args) {
8516
+ async function metaValidateCommand(path18, args) {
8045
8517
  try {
8046
8518
  if (!args.file) {
8047
- throw new CliError21({
8048
- code: CliErrorCode20.MISSING_FLAG,
8519
+ throw new CliError22({
8520
+ code: CliErrorCode21.MISSING_FLAG,
8049
8521
  message: "--file <path> \u5FC5\u586B\uFF08\u8981\u9A8C\u7684\u90A3\u4EFD\u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
8050
8522
  });
8051
8523
  }
@@ -8056,13 +8528,13 @@ async function metaValidateCommand(path17, args) {
8056
8528
  process.stdin.on("end", () => resolve3(buf));
8057
8529
  process.stdin.on("error", reject);
8058
8530
  }) : await fsp3.readFile(args.file, "utf8");
8059
- const result = validateMetaContent(path17, content);
8531
+ const result = validateMetaContent(path18, content);
8060
8532
  const fmt = args.output ?? "table";
8061
8533
  if (fmt === "json" || fmt === "yaml") {
8062
8534
  process.stdout.write(
8063
- formatObject18(
8535
+ formatObject19(
8064
8536
  {
8065
- path: path17,
8537
+ path: path18,
8066
8538
  kind: result.kind,
8067
8539
  schemaKnown: result.schemaKnown,
8068
8540
  schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
@@ -8074,7 +8546,7 @@ async function metaValidateCommand(path17, args) {
8074
8546
  );
8075
8547
  } else {
8076
8548
  process.stdout.write(
8077
- `\u{1F50E} ${path17}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
8549
+ `\u{1F50E} ${path18}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
8078
8550
  `
8079
8551
  );
8080
8552
  process.stdout.write(
@@ -8085,7 +8557,7 @@ async function metaValidateCommand(path17, args) {
8085
8557
  return;
8086
8558
  } catch (e) {
8087
8559
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
8088
- fail6(e, args);
8560
+ fail7(e, args);
8089
8561
  }
8090
8562
  }
8091
8563
 
@@ -8093,15 +8565,15 @@ async function metaValidateCommand(path17, args) {
8093
8565
  init_exit();
8094
8566
  init_auth_guard();
8095
8567
  import * as crypto from "crypto";
8096
- import * as fs7 from "fs/promises";
8097
- import * as path7 from "path";
8568
+ import * as fs8 from "fs/promises";
8569
+ import * as path9 from "path";
8098
8570
  import {
8099
8571
  buildMiniPreviewTargets,
8100
8572
  buildMiniVerifyAgentReport,
8101
8573
  createWorkspaceFile,
8102
8574
  deleteWorkspaceFile,
8103
8575
  formatMiniVerifyReport,
8104
- formatObject as formatObject19,
8576
+ formatObject as formatObject20,
8105
8577
  formatRows as formatRows5,
8106
8578
  getMiniStatus,
8107
8579
  HcmClient as HcmClient19,
@@ -8234,7 +8706,7 @@ async function workspaceBindCommand(workspaceKey, args) {
8234
8706
  tenantId: args.tenant ?? client3?.tenantId,
8235
8707
  endpoint: args.endpoint ?? client3?.endpoint
8236
8708
  });
8237
- await fs7.mkdir(rootDir, { recursive: true });
8709
+ await fs8.mkdir(rootDir, { recursive: true });
8238
8710
  await writeWorkspaceContext(rootDir, context);
8239
8711
  writeWorkspaceBindResult(context, rootDir, args.output ?? "table");
8240
8712
  process.exitCode = 0;
@@ -8271,7 +8743,7 @@ async function workspaceCreateCommand(workspaceKey, args) {
8271
8743
  tenantId: client3.tenantId,
8272
8744
  endpoint: client3.endpoint
8273
8745
  });
8274
- await fs7.mkdir(rootDir, { recursive: true });
8746
+ await fs8.mkdir(rootDir, { recursive: true });
8275
8747
  await writeWorkspaceContext(rootDir, context);
8276
8748
  writeWorkspaceCreateResult(
8277
8749
  {
@@ -8309,7 +8781,7 @@ async function workspacePullCommand(args) {
8309
8781
  tenantId: client3.tenantId ?? existing?.tenantId,
8310
8782
  endpoint: client3.endpoint ?? existing?.endpoint
8311
8783
  });
8312
- await fs7.mkdir(rootDir, { recursive: true });
8784
+ await fs8.mkdir(rootDir, { recursive: true });
8313
8785
  await writeWorkspaceContext(rootDir, context);
8314
8786
  const files = await listWorkspaceFiles(client3.raw(), workspaceKey, { pageSize: 5e3 });
8315
8787
  const miniApps = detectRemoteMiniApps(files.data);
@@ -8319,7 +8791,7 @@ async function workspacePullCommand(args) {
8319
8791
  http: client3.raw(),
8320
8792
  appCode,
8321
8793
  workspaceKey,
8322
- targetDir: path7.join(rootDir, MINI_APPS_DIR, appCode),
8794
+ targetDir: path9.join(rootDir, MINI_APPS_DIR, appCode),
8323
8795
  tenantId: client3.tenantId,
8324
8796
  endpoint: client3.endpoint,
8325
8797
  profile: args.profile ?? client3.profile,
@@ -8334,7 +8806,7 @@ async function workspacePullCommand(args) {
8334
8806
  const rawRemoteByLocalPath = /* @__PURE__ */ new Map();
8335
8807
  for (const file of rawFiles) {
8336
8808
  const content = await loadWorkspaceFileContent(client3.raw(), file.id);
8337
- const target = path7.join(rootDir, content.relativePath);
8809
+ const target = path9.join(rootDir, content.relativePath);
8338
8810
  await writeTextFile(target, content.content, !!args.force);
8339
8811
  pulledRawFiles.push(content.relativePath);
8340
8812
  rawRemoteByLocalPath.set(content.relativePath, file);
@@ -8385,7 +8857,7 @@ async function workspaceAddMiniCommand(appCode, args) {
8385
8857
  const result = await initMiniAppProject({
8386
8858
  appCode,
8387
8859
  workspaceKey: context.workspaceKey,
8388
- targetDir: path7.join(rootDir, MINI_APPS_DIR, appCode),
8860
+ targetDir: path9.join(rootDir, MINI_APPS_DIR, appCode),
8389
8861
  name: args.name,
8390
8862
  defaultSurface: parseSurface(args.surface),
8391
8863
  templateKind,
@@ -8411,10 +8883,10 @@ async function workspaceRmCommand(relativePath, args) {
8411
8883
  const rootDir = resolveRootDir(args.dir);
8412
8884
  const context = await requireWorkspaceContext(rootDir);
8413
8885
  const normalized = normalizeWorkspaceRmPath(relativePath);
8414
- const absolutePath = path7.join(rootDir, ...normalized.split("/"));
8886
+ const absolutePath = path9.join(rootDir, ...normalized.split("/"));
8415
8887
  let stat;
8416
8888
  try {
8417
- stat = await fs7.lstat(absolutePath);
8889
+ stat = await fs8.lstat(absolutePath);
8418
8890
  } catch (e) {
8419
8891
  if (e.code !== "ENOENT") throw e;
8420
8892
  stat = null;
@@ -8454,7 +8926,7 @@ async function workspaceRmCommand(relativePath, args) {
8454
8926
  if (!stat) {
8455
8927
  if (manifestEntry) {
8456
8928
  process.stdout.write(
8457
- formatObject19(
8929
+ formatObject20(
8458
8930
  {
8459
8931
  workspaceKey: context.workspaceKey,
8460
8932
  file: normalized,
@@ -8470,7 +8942,7 @@ async function workspaceRmCommand(relativePath, args) {
8470
8942
  }
8471
8943
  throw new Error(`workspace file not found locally or in the workspace: ${normalized}`);
8472
8944
  }
8473
- await fs7.unlink(absolutePath);
8945
+ await fs8.unlink(absolutePath);
8474
8946
  const result = {
8475
8947
  workspaceKey: context.workspaceKey,
8476
8948
  file: normalized,
@@ -8479,7 +8951,7 @@ async function workspaceRmCommand(relativePath, args) {
8479
8951
  next: `hcm workspace push --dir ${args.dir ?? "."}`
8480
8952
  };
8481
8953
  if (args.output === "json" || args.output === "yaml") {
8482
- process.stdout.write(formatObject19(result, { format: args.output }) + "\n");
8954
+ process.stdout.write(formatObject20(result, { format: args.output }) + "\n");
8483
8955
  } else {
8484
8956
  process.stdout.write(`workspace file staged for deletion: ${normalized}
8485
8957
  `);
@@ -8526,7 +8998,7 @@ async function workspaceStatusCommand(args) {
8526
8998
  }
8527
8999
  if (args.output === "json" || args.output === "yaml") {
8528
9000
  process.stdout.write(
8529
- formatObject19({ rootDir, miniApps: rows2 }, { format: args.output }) + "\n"
9001
+ formatObject20({ rootDir, miniApps: rows2 }, { format: args.output }) + "\n"
8530
9002
  );
8531
9003
  } else {
8532
9004
  process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
@@ -8631,7 +9103,7 @@ async function workspacePreviewCommand(args) {
8631
9103
  );
8632
9104
  }
8633
9105
  if (args.output === "json" || args.output === "yaml") {
8634
- process.stdout.write(formatObject19(rows2, { format: args.output }) + "\n");
9106
+ process.stdout.write(formatObject20(rows2, { format: args.output }) + "\n");
8635
9107
  } else {
8636
9108
  process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
8637
9109
  }
@@ -8744,7 +9216,7 @@ function removedMiniCommand() {
8744
9216
  );
8745
9217
  }
8746
9218
  function resolveRootDir(dir) {
8747
- return path7.resolve(dir ?? ".");
9219
+ return path9.resolve(dir ?? ".");
8748
9220
  }
8749
9221
  function buildWorkspaceContext(args) {
8750
9222
  return {
@@ -8760,7 +9232,7 @@ function buildWorkspaceContext(args) {
8760
9232
  async function readWorkspaceContext(rootDir) {
8761
9233
  try {
8762
9234
  const parsed = JSON.parse(
8763
- await fs7.readFile(path7.join(rootDir, WORKSPACE_CONTEXT_FILE), "utf-8")
9235
+ await fs8.readFile(path9.join(rootDir, WORKSPACE_CONTEXT_FILE), "utf-8")
8764
9236
  );
8765
9237
  if (parsed.kind !== WORKSPACE_CONTEXT_KIND || parsed.version !== WORKSPACE_CONTEXT_VERSION) {
8766
9238
  throw new Error(`${WORKSPACE_CONTEXT_FILE} is not an HCM workspace context`);
@@ -8789,26 +9261,26 @@ async function requireWorkspaceContext(rootDir) {
8789
9261
  return context;
8790
9262
  }
8791
9263
  async function writeWorkspaceContext(rootDir, context) {
8792
- await fs7.writeFile(
8793
- path7.join(rootDir, WORKSPACE_CONTEXT_FILE),
9264
+ await fs8.writeFile(
9265
+ path9.join(rootDir, WORKSPACE_CONTEXT_FILE),
8794
9266
  JSON.stringify(context, null, 2) + "\n"
8795
9267
  );
8796
9268
  }
8797
9269
  async function writeTextFile(file, content, force) {
8798
9270
  try {
8799
- await fs7.access(file);
9271
+ await fs8.access(file);
8800
9272
  if (!force) throw new Error(`${file} already exists; use --force to overwrite`);
8801
9273
  } catch (e) {
8802
9274
  if (e.code !== "ENOENT") throw e;
8803
9275
  }
8804
- await fs7.mkdir(path7.dirname(file), { recursive: true });
8805
- await fs7.writeFile(file, content);
9276
+ await fs8.mkdir(path9.dirname(file), { recursive: true });
9277
+ await fs8.writeFile(file, content);
8806
9278
  }
8807
9279
  async function readWorkspaceRawManifest(rootDir, context) {
8808
9280
  try {
8809
9281
  const parsed = JSON.parse(
8810
- await fs7.readFile(
8811
- path7.join(rootDir, WORKSPACE_STATE_DIR, WORKSPACE_PULL_MANIFEST_FILE),
9282
+ await fs8.readFile(
9283
+ path9.join(rootDir, WORKSPACE_STATE_DIR, WORKSPACE_PULL_MANIFEST_FILE),
8812
9284
  "utf-8"
8813
9285
  )
8814
9286
  );
@@ -8830,8 +9302,8 @@ async function readWorkspaceRawManifest(rootDir, context) {
8830
9302
  }
8831
9303
  }
8832
9304
  async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath) {
8833
- const stateDir = path7.join(rootDir, WORKSPACE_STATE_DIR);
8834
- await fs7.mkdir(stateDir, { recursive: true });
9305
+ const stateDir = path9.join(rootDir, WORKSPACE_STATE_DIR);
9306
+ await fs8.mkdir(stateDir, { recursive: true });
8835
9307
  const snapshots = files.map(
8836
9308
  (file) => ({
8837
9309
  localPath: file.localPath,
@@ -8842,8 +9314,8 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
8842
9314
  lastModified: remoteByLocalPath.get(file.localPath)?.lastModified
8843
9315
  })
8844
9316
  );
8845
- await fs7.writeFile(
8846
- path7.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
9317
+ await fs8.writeFile(
9318
+ path9.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
8847
9319
  JSON.stringify(
8848
9320
  {
8849
9321
  version: WORKSPACE_CONTEXT_VERSION,
@@ -8859,10 +9331,10 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
8859
9331
  );
8860
9332
  }
8861
9333
  async function writeWorkspaceRawManifest(rootDir, manifest2) {
8862
- const stateDir = path7.join(rootDir, WORKSPACE_STATE_DIR);
8863
- await fs7.mkdir(stateDir, { recursive: true });
8864
- await fs7.writeFile(
8865
- path7.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
9334
+ const stateDir = path9.join(rootDir, WORKSPACE_STATE_DIR);
9335
+ await fs8.mkdir(stateDir, { recursive: true });
9336
+ await fs8.writeFile(
9337
+ path9.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
8866
9338
  JSON.stringify(manifest2, null, 2) + "\n",
8867
9339
  "utf8"
8868
9340
  );
@@ -8874,10 +9346,10 @@ async function readWorkspaceRawLocalFiles(rootDir) {
8874
9346
  return files;
8875
9347
  }
8876
9348
  async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
8877
- const absoluteDir = path7.join(rootDir, relativeDir);
9349
+ const absoluteDir = path9.join(rootDir, relativeDir);
8878
9350
  let entries;
8879
9351
  try {
8880
- entries = await fs7.readdir(absoluteDir, { withFileTypes: true });
9352
+ entries = await fs8.readdir(absoluteDir, { withFileTypes: true });
8881
9353
  } catch (e) {
8882
9354
  if (e.code === "ENOENT") return;
8883
9355
  throw e;
@@ -8885,14 +9357,14 @@ async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
8885
9357
  for (const entry of entries) {
8886
9358
  if (entry.isDirectory() && RAW_WORKSPACE_EXCLUDED_DIRS.has(entry.name)) continue;
8887
9359
  if (entry.isFile() && RAW_WORKSPACE_EXCLUDED_FILES.has(entry.name)) continue;
8888
- const localPath = normalizeRelativePath(path7.posix.join(toPosix(relativeDir), entry.name));
8889
- const absolutePath = path7.join(rootDir, localPath);
9360
+ const localPath = normalizeRelativePath(path9.posix.join(toPosix(relativeDir), entry.name));
9361
+ const absolutePath = path9.join(rootDir, localPath);
8890
9362
  if (entry.isDirectory()) {
8891
9363
  await walkWorkspaceRawFiles(rootDir, localPath, files);
8892
9364
  continue;
8893
9365
  }
8894
9366
  if (!entry.isFile()) continue;
8895
- const content = await fs7.readFile(absolutePath, "utf-8");
9367
+ const content = await fs8.readFile(absolutePath, "utf-8");
8896
9368
  files.push({
8897
9369
  localPath,
8898
9370
  absolutePath,
@@ -9074,15 +9546,15 @@ function workspaceRawConflict(entry, reason) {
9074
9546
  };
9075
9547
  }
9076
9548
  async function discoverMiniApps(rootDir) {
9077
- const appsRoot = path7.join(rootDir, MINI_APPS_DIR);
9549
+ const appsRoot = path9.join(rootDir, MINI_APPS_DIR);
9078
9550
  let entries;
9079
9551
  try {
9080
- entries = await fs7.readdir(appsRoot, { withFileTypes: true });
9552
+ entries = await fs8.readdir(appsRoot, { withFileTypes: true });
9081
9553
  } catch (e) {
9082
9554
  if (e.code === "ENOENT") return [];
9083
9555
  throw e;
9084
9556
  }
9085
- return entries.filter((entry) => entry.isDirectory()).map((entry) => ({ appCode: entry.name, dir: path7.join(appsRoot, entry.name) })).sort((a, b) => a.appCode.localeCompare(b.appCode));
9557
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => ({ appCode: entry.name, dir: path9.join(appsRoot, entry.name) })).sort((a, b) => a.appCode.localeCompare(b.appCode));
9086
9558
  }
9087
9559
  function detectRemoteMiniApps(files) {
9088
9560
  const appCodes = /* @__PURE__ */ new Set();
@@ -9225,7 +9697,7 @@ function normalizeWorkspaceKey(value) {
9225
9697
  return key2;
9226
9698
  }
9227
9699
  function normalizeWorkspaceRmPath(value) {
9228
- if (path7.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value)) {
9700
+ if (path9.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value)) {
9229
9701
  throw new Error("workspace rm path must be relative to the bound workspace");
9230
9702
  }
9231
9703
  const normalized = normalizeRelativePath(value);
@@ -9247,7 +9719,7 @@ function normalizeRelativePath(value) {
9247
9719
  return normalized;
9248
9720
  }
9249
9721
  function toPosix(value) {
9250
- return value.split(path7.sep).join("/");
9722
+ return value.split(path9.sep).join("/");
9251
9723
  }
9252
9724
  function sha2563(content) {
9253
9725
  return crypto.createHash("sha256").update(content, "utf-8").digest("hex");
@@ -9275,7 +9747,7 @@ function optionalText(value) {
9275
9747
  }
9276
9748
  function writeWorkspaceListResult(rows2, format, total) {
9277
9749
  if (format !== "table") {
9278
- process.stdout.write(formatObject19({ rows: rows2, total }, { format }) + "\n");
9750
+ process.stdout.write(formatObject20({ rows: rows2, total }, { format }) + "\n");
9279
9751
  return;
9280
9752
  }
9281
9753
  process.stdout.write(formatRows5(toWorkspaceListRows(rows2), { format: "table" }) + "\n");
@@ -9286,7 +9758,7 @@ function writeWorkspaceListResult(rows2, format, total) {
9286
9758
  }
9287
9759
  function writeWorkspaceActiveResult(view, format) {
9288
9760
  if (format !== "table") {
9289
- process.stdout.write(formatObject19(view, { format }) + "\n");
9761
+ process.stdout.write(formatObject20(view, { format }) + "\n");
9290
9762
  return;
9291
9763
  }
9292
9764
  const rows2 = [
@@ -9308,7 +9780,7 @@ function writeWorkspaceActiveResult(view, format) {
9308
9780
  }
9309
9781
  function writeWorkspaceBindResult(context, rootDir, format) {
9310
9782
  if (format !== "table") {
9311
- process.stdout.write(formatObject19({ ...context, rootDir }, { format }) + "\n");
9783
+ process.stdout.write(formatObject20({ ...context, rootDir }, { format }) + "\n");
9312
9784
  return;
9313
9785
  }
9314
9786
  process.stdout.write(
@@ -9322,7 +9794,7 @@ function writeWorkspaceBindResult(context, rootDir, format) {
9322
9794
  }
9323
9795
  function writeWorkspaceCreateResult(result, format) {
9324
9796
  if (format !== "table") {
9325
- process.stdout.write(formatObject19(result, { format }) + "\n");
9797
+ process.stdout.write(formatObject20(result, { format }) + "\n");
9326
9798
  return;
9327
9799
  }
9328
9800
  process.stdout.write(
@@ -9338,7 +9810,7 @@ function writeWorkspaceCreateResult(result, format) {
9338
9810
  }
9339
9811
  function writeWorkspacePullResult(result, format) {
9340
9812
  if (format !== "table") {
9341
- process.stdout.write(formatObject19(result, { format }) + "\n");
9813
+ process.stdout.write(formatObject20(result, { format }) + "\n");
9342
9814
  return;
9343
9815
  }
9344
9816
  const lines = [
@@ -9356,7 +9828,7 @@ function writeWorkspacePullResult(result, format) {
9356
9828
  }
9357
9829
  function writeWorkspaceAddMiniResult(result, rootDir, format) {
9358
9830
  if (format !== "table") {
9359
- process.stdout.write(formatObject19({ ...result, workspaceRoot: rootDir }, { format }) + "\n");
9831
+ process.stdout.write(formatObject20({ ...result, workspaceRoot: rootDir }, { format }) + "\n");
9360
9832
  return;
9361
9833
  }
9362
9834
  process.stdout.write(
@@ -9372,7 +9844,7 @@ function writeWorkspaceAddMiniResult(result, rootDir, format) {
9372
9844
  function writeWorkspaceValidateResult(results, format) {
9373
9845
  if (format !== "table") {
9374
9846
  process.stdout.write(
9375
- formatObject19(
9847
+ formatObject20(
9376
9848
  results.map((item) => ({ artifact: `mini:${item.app.appCode}`, ...item.result })),
9377
9849
  { format }
9378
9850
  ) + "\n"
@@ -9400,7 +9872,7 @@ mini:${item.app.appCode}
9400
9872
  function writeWorkspacePushResult(rawResult, results, format) {
9401
9873
  if (format !== "table") {
9402
9874
  process.stdout.write(
9403
- formatObject19(
9875
+ formatObject20(
9404
9876
  {
9405
9877
  workspaceFiles: { artifact: "workspace", ...rawResult },
9406
9878
  miniApps: results.map((item) => ({
@@ -9459,7 +9931,7 @@ function writeWorkspaceVerifyResult(context, rootDir, raw, reports, format) {
9459
9931
  const ok = rawOk && reports.every((item) => item.report.ok);
9460
9932
  if (format === "json") {
9461
9933
  process.stdout.write(
9462
- formatObject19(
9934
+ formatObject20(
9463
9935
  {
9464
9936
  ok,
9465
9937
  workspaceKey: context.workspaceKey,
@@ -9486,7 +9958,7 @@ function writeWorkspaceVerifyResult(context, rootDir, raw, reports, format) {
9486
9958
  }
9487
9959
  if (format !== "table") {
9488
9960
  process.stdout.write(
9489
- formatObject19(
9961
+ formatObject20(
9490
9962
  {
9491
9963
  ok,
9492
9964
  workspaceKey: context.workspaceKey,
@@ -9571,557 +10043,214 @@ async function setDevModeBinding(client3, workspaceKey) {
9571
10043
  workspaceKey
9572
10044
  });
9573
10045
  }
9574
- function workspaceActiveNextCommand(activeWorkspaceKey) {
9575
- return activeWorkspaceKey ? "hcm workspace deactivate" : null;
9576
- }
9577
- function unwrapWorkspaceActionPayload(response) {
9578
- if (!response || typeof response !== "object") return response;
9579
- const envelope = response;
9580
- if (envelope.data && typeof envelope.data === "object") return envelope.data;
9581
- if (envelope.result && typeof envelope.result === "object") return envelope.result;
9582
- return response;
9583
- }
9584
- async function requestWorkspaceDeactivation(client3) {
9585
- const response = await client3.action(
9586
- "TenantExtensionWorkspace",
9587
- "unbind-current-user",
9588
- { method: "POST", scope: "class" }
9589
- );
9590
- const binding = unwrapWorkspaceActionPayload(response);
9591
- if (!binding || typeof binding !== "object" || binding.enabled !== false) {
9592
- throw new Error("workspace deactivate \u672A\u6536\u5230 enabled=false \u7684\u670D\u52A1\u7AEF\u56DE\u6267\uFF0C\u4E0D\u80FD\u786E\u8BA4\u5DF2\u9000\u51FA\u5F00\u53D1\u6A21\u5F0F");
9593
- }
9594
- return binding;
9595
- }
9596
- async function workspaceActivateCommand(workspaceKey, args) {
9597
- try {
9598
- const client3 = HcmClient19.fromAuthContext(await getActiveAuthContextFromCli(args));
9599
- const key2 = normalizeWorkspaceKey(workspaceKey);
9600
- await setDevModeBinding(client3, key2);
9601
- const fmt = args.output ?? "table";
9602
- if (fmt === "table") {
9603
- process.stdout.write(`workspace activated: ${key2}
9604
- `);
9605
- process.stdout.write("\u8BE5\u7A7A\u95F4\u7684 metas / scripts / menus / mini_apps \u73B0\u5DF2\u5728\u5F53\u524D\u79DF\u6237\u751F\u6548\u3002\n");
9606
- } else {
9607
- process.stdout.write(
9608
- formatObject19({ workspaceKey: key2, activated: true }, { format: fmt }) + "\n"
9609
- );
9610
- }
9611
- process.exitCode = 0;
9612
- return;
9613
- } catch (e) {
9614
- exitWorkspaceError(e, args.env ?? args.profile);
9615
- }
9616
- }
9617
- async function workspaceDeactivateCommand(args) {
9618
- try {
9619
- const client3 = HcmClient19.fromAuthContext(await getActiveAuthContextFromCli(args));
9620
- const binding = await requestWorkspaceDeactivation(client3);
9621
- const result = { ...binding, deactivated: true };
9622
- const fmt = args.output ?? "table";
9623
- if (fmt === "table") {
9624
- process.stdout.write("workspace deactivated\n");
9625
- process.stdout.write("\u5F53\u524D\u8EAB\u4EFD\u5DF2\u9000\u51FA\u5F00\u53D1\u8005\u6A21\u5F0F\uFF1B\u5F00\u53D1\u7A7A\u95F4\u3001\u672C\u5730\u6587\u4EF6\u4E0E\u5DF2\u53D1\u5E03\u8D44\u4EA7\u5747\u672A\u5220\u9664\u3002\n");
9626
- } else {
9627
- process.stdout.write(formatObject19(result, { format: fmt }) + "\n");
9628
- }
9629
- process.exitCode = 0;
9630
- return;
9631
- } catch (e) {
9632
- exitWorkspaceError(e, args.env ?? args.profile);
9633
- }
9634
- }
9635
-
9636
- // src/commands/identity.ts
9637
- init_exit();
9638
- import axios4 from "axios";
9639
- import {
9640
- AUTH_INFO_PATH,
9641
- CliError as CliError22,
9642
- CliErrorCode as CliErrorCode21,
9643
- formatObject as formatObject20,
9644
- fromAxiosError as fromAxiosError20,
9645
- loadEnv as loadEnv4,
9646
- saveEnv as saveEnv3,
9647
- loadIdentity as loadIdentity4,
9648
- listIdentities as listIdentities4,
9649
- deleteIdentity as deleteIdentity3,
9650
- loadGlobalConfig as loadGlobalConfig8,
9651
- resolveActiveEnv,
9652
- printResolvedEnvironment as printResolvedEnvironment6,
9653
- TokenStore as TokenStore4,
9654
- toPrincipal
9655
- } from "@hcmai/sdk";
9656
- var fetchAuthInfo = async (endpoint, accessToken) => {
9657
- const response = await axios4.get(`${endpoint.replace(/\/$/, "")}${AUTH_INFO_PATH}`, {
9658
- headers: { Authorization: `Bearer ${accessToken}` },
9659
- timeout: 3e4
9660
- });
9661
- return response.data;
9662
- };
9663
- async function inspectIdentity(name, fetcher = fetchAuthInfo) {
9664
- const meta2 = await loadIdentity4(name);
9665
- const env2 = await loadEnv4(meta2.env);
9666
- const accessToken = await TokenStore4.forIdentity(name).getStoredAccessToken();
9667
- if (!accessToken) {
9668
- throw new CliError22({
9669
- code: CliErrorCode21.AUTH_FAILED,
9670
- message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
9671
- context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
9672
- });
9673
- }
9674
- printResolvedEnvironment6({ name: meta2.env, config: env2, source: "identity" }, name, meta2.tenantId);
9675
- const raw = await fetcher(env2.endpoint, accessToken);
9676
- const principal = toPrincipal(raw);
9677
- const body = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
9678
- const serverScopes = Array.isArray(body.scopes) ? body.scopes.map(String) : void 0;
9679
- return {
9680
- identity: name,
9681
- env: meta2.env,
9682
- endpoint: env2.endpoint,
9683
- scheme: meta2.scheme,
9684
- userId: principal?.userId ?? null,
9685
- username: principal?.username ?? null,
9686
- tenantId: principal?.tenantId ?? null,
9687
- // null 明确表示服务端没回该字段;[] 才表示服务端确认角色为空。
9688
- roles: principal?.roles ?? null,
9689
- scopes: serverScopes ?? meta2.scopes,
9690
- expiresAt: meta2.expiresAt ?? null,
9691
- source: AUTH_INFO_PATH
9692
- };
9693
- }
9694
- async function identityShow(name, args) {
9695
- try {
9696
- const details = await inspectIdentity(name);
9697
- return exitOk(formatObject20(details, { format: args.output ?? "json" }));
9698
- } catch (e) {
9699
- exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
9700
- }
9701
- }
9702
- async function identityList(args) {
9703
- try {
9704
- const g = await loadGlobalConfig8();
9705
- const filter = args.env === "all" ? void 0 : await resolveActiveEnv({ envFlag: args.env }, process.env, g);
9706
- const names = await listIdentities4(filter);
9707
- if (names.length === 0) {
9708
- return exitOk("(no identities)");
9709
- }
9710
- const lines = [];
9711
- for (const n of names) {
9712
- const meta2 = await loadIdentity4(n);
9713
- const env2 = await loadEnv4(meta2.env).catch(() => null);
9714
- const isDefault = env2?.defaultIdentity === n ? "*" : " ";
9715
- const expired = meta2.expiresAt && new Date(meta2.expiresAt) < /* @__PURE__ */ new Date() ? " (expired)" : "";
9716
- lines.push(`${isDefault} ${n} scheme=${meta2.scheme} env=${meta2.env}${expired}`);
9717
- }
9718
- return exitOk(lines.join("\n"));
9719
- } catch (e) {
9720
- exitWithError(e);
9721
- }
9722
- }
9723
- async function identityUse(name) {
9724
- try {
9725
- const meta2 = await loadIdentity4(name);
9726
- const env2 = await loadEnv4(meta2.env).catch(() => {
9727
- throw new CliError22({
9728
- code: CliErrorCode21.IDENTITY_NOT_IN_ENV,
9729
- message: `identity '${name}' references env '${meta2.env}' which no longer exists. Re-create the env, or remove this orphan: hcm identity remove ${name}`
9730
- });
9731
- });
9732
- env2.defaultIdentity = name;
9733
- await saveEnv3(meta2.env, env2);
9734
- return exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
9735
- } catch (e) {
9736
- exitWithError(e);
9737
- }
9738
- }
9739
- async function identityRemove(name) {
9740
- try {
9741
- const meta2 = await loadIdentity4(name);
9742
- try {
9743
- await TokenStore4.forIdentity(name).clear();
9744
- } catch (err) {
9745
- process.stderr.write(
9746
- `[hcm] event=identity_cleanup_failed identity=${name} reason=${JSON.stringify(String(err.message))}
9747
- `
9748
- );
9749
- }
9750
- await deleteIdentity3(name);
9751
- const env2 = await loadEnv4(meta2.env).catch(() => null);
9752
- if (env2?.defaultIdentity === name) {
9753
- env2.defaultIdentity = void 0;
9754
- await saveEnv3(meta2.env, env2);
9755
- }
9756
- return exitOk(`\u2705 identity '${name}' removed`);
9757
- } catch (e) {
9758
- exitWithError(e);
9759
- }
9760
- }
9761
-
9762
- // src/commands/chiron-init.ts
9763
- init_auth_guard();
9764
- init_exit();
9765
- import { promises as fs9 } from "fs";
9766
- import path9 from "path";
9767
- import {
9768
- CliError as CliError24,
9769
- CliErrorCode as CliErrorCode23,
9770
- HcmClient as HcmClient20,
9771
- fetchReconIdentity,
9772
- formatObject as formatObject22,
9773
- httpProbe,
9774
- isTempEnv as isTempEnv3,
9775
- listIdentities as listIdentities5,
9776
- loadEnv as loadEnv5,
9777
- discoverProjectEnv as discoverProjectEnv4,
9778
- findEnvByEndpoint as findEnvByEndpoint4,
9779
- normalizeOrigin as normalizeOrigin5,
9780
- loadGlobalConfig as loadGlobalConfig9
9781
- } from "@hcmai/sdk";
9782
-
9783
- // src/commands/chiron-project.ts
9784
- import { promises as fs8 } from "fs";
9785
-
9786
- // src/commands/chiron-case.ts
9787
- init_exit();
9788
- import { execFileSync } from "child_process";
9789
- import { cpSync, existsSync as existsSync2, mkdirSync, mkdtempSync, readFileSync as readFileSync5, rmSync, statSync as statSync4, writeFileSync as writeFileSync2 } from "fs";
9790
- import os4 from "os";
9791
- import path8 from "path";
9792
- import { CASES_REPO_SLUG, CASES_REPO_URL, CNB_ORIGIN, CliError as CliError23, CliErrorCode as CliErrorCode22, formatObject as formatObject21 } from "@hcmai/sdk";
9793
- var casesCacheDir = () => process.env.HCM_CASES_CACHE?.trim() || path8.join(os4.homedir(), ".cache", "hcm", "chiron-cases");
9794
- var INDEX_CACHE = () => path8.join(casesCacheDir(), "index.json");
9795
- var INDEX_TTL_MS = 60 * 60 * 1e3;
9796
- var fail7 = (message, nextStep) => new CliError23({ code: CliErrorCode22.INVALID_ARGUMENT, message, context: { nextStep } });
9797
- var run = (cmd, args, opts = {}) => execFileSync(cmd, args, { encoding: "utf8", maxBuffer: 1 << 26, ...opts });
9798
- function fetchRepoFile(relPath) {
9799
- let raw;
9800
- try {
9801
- raw = run("cnb", ["git", "get-raw", "--repo", CASES_REPO_SLUG, "--ref-with-path", `main/${relPath}`]);
9802
- } catch (e) {
9803
- throw fail7(
9804
- `\u53D6\u4E0D\u5230\u6848\u4F8B\u5E93\u6587\u4EF6 ${relPath}\uFF1A${String(e.message).split("\n")[0]}`,
9805
- "\u6848\u4F8B\u5E93\u8BFB\u53D6\u8D70 cnb\uFF08\u9700\u8981\u5DF2 `cnb login` \u4E14\u6709\u8BE5\u4ED3\u8BFB\u6743\u9650\uFF09\u3002\u6CA1\u6709\u6743\u9650\u5C31\u5148\u8DF3\u8FC7\u6848\u4F8B\u5E93\uFF0C\u76F4\u63A5\u6309\u6280\u80FD\u505A\uFF1B\u522B\u628A\u300C\u53D6\u4E0D\u5230\u300D\u5F53\u6210\u300C\u6CA1\u6709\u5148\u4F8B\u300D\u3002"
9806
- );
9807
- }
9808
- const i = raw.indexOf("data: ");
9809
- if (i < 0) throw fail7(`cnb \u7684\u56DE\u6267\u91CC\u6CA1\u6709 data \u90A3\u4E00\u683C\uFF1A${relPath}`, "\u5347\u7EA7 cnb CLI\uFF0C\u6216\u628A\u8FD9\u6BB5\u539F\u6837\u8D34\u7ED9\u6211\u3002");
9810
- const body = raw.slice(i + "data: ".length).trim();
9811
- if (body.startsWith('"')) {
9812
- try {
9813
- return JSON.parse(body);
9814
- } catch {
9815
- return body;
9816
- }
9817
- }
9818
- return body;
9819
- }
9820
- function loadIndex(opts = {}) {
9821
- const file = INDEX_CACHE();
9822
- const fresh = !opts.refresh && existsSync2(file) && Date.now() - statSync4(file).mtimeMs < INDEX_TTL_MS;
9823
- if (fresh) return JSON.parse(readFileSync5(file, "utf8"));
9824
- let text;
9825
- try {
9826
- text = fetchRepoFile("index/index.json");
9827
- } catch (e) {
9828
- if (!existsSync2(file)) throw e;
9829
- process.stderr.write(
9830
- `[hcm] \u7D22\u5F15\u6CA1\u62C9\u52A8\uFF08${e.message.split("\n")[0]}\uFF09\uFF0C\u7528\u672C\u673A\u7F13\u5B58\u7684\u90A3\u4EFD\uFF1A${file}
9831
- `
9832
- );
9833
- return JSON.parse(readFileSync5(file, "utf8"));
9834
- }
9835
- mkdirSync(path8.dirname(file), { recursive: true });
9836
- writeFileSync2(file, text);
9837
- return JSON.parse(text);
9838
- }
9839
- function backendFingerprint(env2) {
9840
- if (!env2) return { reason: "\u6CA1\u7ED9 --env\uFF0C\u6CA1\u6CD5\u73B0\u67E5\u6307\u7EB9" };
9841
- try {
9842
- const raw = run(process.execPath, [process.argv[1], "version", "--env", env2, "--output", "json"]);
9843
- const j = JSON.parse(raw.slice(raw.indexOf("{")));
9844
- const backend = j.backend?.commit ?? j.commit ?? j.server?.commit;
9845
- if (!backend) return { reason: "\u540E\u7AEF\u56DE\u6267\u91CC\u6CA1\u6709 commit \u5B57\u6BB5" };
9846
- return { backend: String(backend), cli: String(j.cli?.version ?? j.cliVersion ?? "") };
9847
- } catch (e) {
9848
- return { reason: String(e.message).split("\n")[0]?.slice(0, 120) };
9849
- }
9850
- }
9851
- function matchTag(c, fp) {
9852
- if (!fp.backend) return `\u672A\u6BD4\u5BF9\uFF08${fp.reason ?? "\u6CA1\u6709\u6307\u7EB9"}\uFF09`;
9853
- const be = String(c.fingerprint?.backend_commit ?? "");
9854
- if (!be) return "\u6848\u4F8B\u6CA1\u8BB0\u540E\u7AEF\u6307\u7EB9";
9855
- const a = be.slice(0, 12);
9856
- const b = fp.backend.slice(0, 12);
9857
- return a === b ? "\u5339\u914D" : `\u4E0D\u5339\u914D\uFF08\u6848\u4F8B ${a} / \u5F53\u524D ${b}\uFF09`;
9858
- }
9859
- function emit4(args, data, text) {
9860
- if (args.output === "json" || args.output === "yaml") {
9861
- process.stdout.write(formatObject21(data, { format: args.output }) + "\n");
9862
- } else {
9863
- process.stdout.write(text() + "\n");
9864
- }
9865
- }
9866
- async function guard(fn) {
9867
- try {
9868
- await fn();
9869
- } catch (e) {
9870
- exitWithError(e);
9871
- }
9872
- }
9873
- async function caseSearchCommand(query, args) {
9874
- await guard(async () => {
9875
- const idx = loadIndex({ refresh: args.refresh });
9876
- const fp = backendFingerprint(args.env);
9877
- let raw;
9878
- try {
9879
- raw = run("cnb", [
9880
- "knowledge-base",
9881
- "query-knowledge-base-get",
9882
- "--repo",
9883
- CASES_REPO_SLUG,
9884
- "--query",
9885
- query,
9886
- "--top-k",
9887
- String(args.topK ?? 5),
9888
- "--verbose"
9889
- ]);
9890
- } catch (e) {
9891
- throw fail7(
9892
- `\u6848\u4F8B\u5E93\u68C0\u7D22\u6CA1\u8DD1\u6210\uFF1A${String(e.message).split("\n")[0]}`,
9893
- "\u68C0\u7D22\u8D70 cnb \u7684\u77E5\u8BC6\u5E93\u63A5\u53E3\uFF0C\u9700\u8981 cnb \u5DF2\u767B\u5F55\u4E14\u6709\u6848\u4F8B\u5E93\u6743\u9650\u3002\u6CA1\u6709\u5C31\u5148\u8DF3\u8FC7\u6848\u4F8B\u5E93\uFF0C\u76F4\u63A5\u6309\u6280\u80FD\u505A\uFF1B\u522B\u628A\u300C\u67E5\u4E0D\u5230\u300D\u5F53\u6210\u300C\u6CA1\u6709\u5148\u4F8B\u300D\u3002"
9894
- );
9895
- }
9896
- const json = JSON.parse(raw.slice(raw.indexOf("{")));
9897
- const seen = /* @__PURE__ */ new Map();
9898
- for (const h of json.data ?? []) {
9899
- const p = h.metadata?.path ?? "";
9900
- const m = /^cases\/[^/]+\/([^/]+)\//.exec(p);
9901
- if (!m) continue;
9902
- const id = m[1];
9903
- if (seen.has(id)) continue;
9904
- const c = idx.cases.find((x) => x.id === id);
9905
- seen.set(id, {
9906
- id,
9907
- score: h.score,
9908
- file: p.split("/").pop(),
9909
- status: c?.status,
9910
- tier: c?.tier,
9911
- skills: c?.skills,
9912
- customer_ask: c?.customer_ask,
9913
- match: c ? matchTag(c, fp) : "\u7D22\u5F15\u91CC\u6CA1\u6709\uFF08\u672C\u673A clone \u53EF\u80FD\u65E7\u4E86\uFF0Cgit pull \u4E00\u6B21\uFF09"
9914
- });
9915
- }
9916
- const rows2 = [...seen.values()];
9917
- emit4(
9918
- args,
9919
- { query, rows: rows2 },
9920
- () => rows2.length ? rows2.map((r) => `${r.id} [${r.status ?? "?"}\xB7${r.match}] ${r.customer_ask ?? ""}
9921
- \u6280\u80FD\uFF1A${(r.skills ?? []).join(" / ") || "\uFF08\u672A\u767B\u8BB0\uFF09"}`).join("\n") : `\u6CA1\u6709\u547D\u4E2D\u300C${query}\u300D\u7684\u6848\u4F8B\u3002\u5148\u6309\u6280\u80FD\u505A\uFF0C\u8DD1\u901A\u4E86\u7528 \`hcm chiron case submit\` \u4E0A\u884C\u4E00\u6761\u3002`
9922
- );
9923
- });
9924
- }
9925
- async function caseShowCommand(id, args) {
9926
- await guard(async () => {
9927
- const idx = loadIndex({ refresh: args.refresh });
9928
- const c = idx.cases.find((x) => x.id === id);
9929
- if (!c?.path) {
9930
- throw fail7(
9931
- `\u7D22\u5F15\u91CC\u6CA1\u6709\u6848\u4F8B ${id}`,
9932
- `\u5148 \`hcm chiron case search <\u5173\u952E\u8BCD>\` \u62FF\u51C6\u786E\u7684 id\uFF1B\u7D22\u5F15\u53EF\u80FD\u65E7\u4E86\uFF0C\u52A0 --refresh \u518D\u8BD5\u4E00\u6B21\u3002`
9933
- );
9934
- }
9935
- const files = args.file ? [args.file] : ["\u95EE\u9898.md", "\u65B9\u6848.md"];
9936
- const parts = [];
9937
- for (const f of files) {
9938
- try {
9939
- parts.push(`# ${f}
9940
-
9941
- ${fetchRepoFile(`${c.path}/${f}`)}`);
9942
- } catch {
9943
- parts.push(`# ${f}
9944
-
9945
- \uFF08\u8FD9\u4E2A\u6848\u4F8B\u6CA1\u6709\u8FD9\u4EFD\u6587\u4EF6\uFF09`);
9946
- }
9947
- }
9948
- const meta2 = fetchRepoFile(`${c.path}/case.yml`);
9949
- emit4(
9950
- args,
9951
- { id, caseYml: meta2, files: parts },
9952
- () => `case.yml:
9953
- ${meta2}
9954
-
9955
- ${parts.join("\n\n---\n\n")}
9956
-
9957
- \uFF08\u8BC1\u636E\u6587\u4EF6\u6CA1\u6709\u4E0B\u8F7D \u2014\u2014 \u53BB ${CNB_ORIGIN}/${CASES_REPO_SLUG}/-/tree/main/${c.path} \u770B\uFF09`
9958
- );
9959
- });
9960
- }
9961
- async function caseMatchCommand(args) {
9962
- await guard(async () => {
9963
- const idx = loadIndex({ refresh: args.refresh });
9964
- const fp = backendFingerprint(args.env);
9965
- const rows2 = idx.cases.filter((c) => c.status === "approved").map((c) => ({ id: c.id, match: matchTag(c, fp), skills: c.skills, customer_ask: c.customer_ask }));
9966
- emit4(args, { fingerprint: fp, rows: rows2 }, () => {
9967
- const head = fp.backend ? `\u5F53\u524D\u540E\u7AEF ${fp.backend.slice(0, 12)}\uFF08env ${args.env}\uFF09` : `\u26A0\uFE0F \u6CA1\u53D6\u5230\u5F53\u524D\u6307\u7EB9\uFF08${fp.reason}\uFF09\u2014\u2014\u4E0B\u9762\u6BCF\u4E00\u6761\u90FD\u6807\u7740\u300C\u672A\u6BD4\u5BF9\u300D\uFF0C\u522B\u628A\u5B83\u8BFB\u6210\u300C\u90FD\u80FD\u7167\u505A\u300D`;
9968
- return [head, ...rows2.map((r) => `${r.match === "\u5339\u914D" ? "\u2705" : "\xB7 "} ${r.id} [${r.match}] ${r.customer_ask ?? ""}`)].join("\n");
9969
- });
9970
- });
9971
- }
9972
- async function caseSubmitCommand(dir, args) {
9973
- await guard(async () => {
9974
- const src = path8.resolve(dir);
9975
- if (!existsSync2(path8.join(src, "case.yml"))) {
9976
- throw fail7(`${src} \u91CC\u6CA1\u6709 case.yml`, "\u6307\u5230\u9879\u76EE\u4ED3\u7684\u6848\u4F8B\u76EE\u5F55\uFF08\u5982 cases/CASE-20260902-xxx\uFF09\uFF0C\u90A3\u91CC\u5E94\u5F53\u6709 case.yml\u3002");
9977
- }
9978
- const yamlText = readFileSync5(path8.join(src, "case.yml"), "utf8");
9979
- const id = /^\s*(?:id|case_id):\s*(\S+)/m.exec(yamlText)?.[1];
9980
- if (!id) throw fail7("case.yml \u91CC\u6CA1\u6709 id", "case.yml \u9876\u5C42\u8981\u6709 `id: CASE-YYYYMMDD-xxx`\u3002");
9981
- const work = mkdtempSync(path8.join(os4.tmpdir(), "hcm-case-submit-"));
9982
- try {
9983
- const repo = path8.join(work, "chiron-cases");
9984
- try {
9985
- run("git", ["clone", "--depth", "1", "--filter=blob:none", "--quiet", CASES_REPO_URL, repo]);
9986
- } catch (e) {
9987
- throw fail7(
9988
- `clone \u6848\u4F8B\u5E93\u5931\u8D25\uFF1A${String(e.message).split("\n")[0]}`,
9989
- `\u4E0A\u884C\u8981\u5F80 ${CASES_REPO_SLUG} \u63D0 PR\uFF0C\u9700\u8981\u8BE5\u4ED3\u5199\u6743\u9650\uFF08\`cnb login\` \u4E14\u88AB\u52A0\u8FDB\u4ED3\uFF09\u3002\u6848\u4F8B\u8FD8\u5728\u4F60\u7684\u9879\u76EE\u4ED3\u91CC\uFF0C\u6CA1\u4E22\u3002`
9990
- );
9991
- }
9992
- const branch = `case/${id}-submit`;
9993
- run("git", ["-C", repo, "checkout", "-q", "-B", branch]);
9994
- const dst = path8.join(repo, "cases", args.category, id);
9995
- cpSync(src, dst, { recursive: true, filter: (p) => !p.includes("node_modules") });
9996
- mkdirSync(path8.join(dst, "evidence"), { recursive: true });
9997
- let doc = readFileSync5(path8.join(dst, "case.yml"), "utf8");
9998
- doc = /^\s*tier:/m.test(doc) ? doc.replace(/^\s*tier:.*$/m, "tier: public") : `tier: public
9999
- ${doc}`;
10000
- doc = /^\s*category:/m.test(doc) ? doc.replace(/^\s*category:.*$/m, `category: ${args.category}`) : `category: ${args.category}
10001
- ${doc}`;
10002
- doc = /^\s*origin:/m.test(doc) ? doc.replace(/^\s*origin:.*$/m, `origin: ${args.origin}`) : `origin: ${args.origin}
10003
- ${doc}`;
10004
- if (!/^\s*status:/m.test(doc)) doc = `status: approved
10005
- ${doc}`;
10006
- writeFileSync2(path8.join(dst, "case.yml"), doc);
10007
- run("python3", ["scripts/render-readme.py", dst], { cwd: repo });
10008
- let lint;
10009
- try {
10010
- lint = run("python3", ["scripts/lint-case.py"], { cwd: repo });
10011
- } catch (e) {
10012
- throw fail7(
10013
- `\u6848\u4F8B lint \u6CA1\u8FC7\uFF0CPR \u6CA1\u5F00\uFF1A
10014
- ${e.stdout ?? e.message}`,
10015
- "\u7167 lint \u7684\u63D0\u793A\u8865\u9F50 case.yml \u4E0E\u6B63\u6587\uFF0C\u518D\u8DD1\u4E00\u6B21\u3002\u6848\u4F8B\u8FD8\u5728\u9879\u76EE\u4ED3\u91CC\uFF0C\u6CA1\u4E22\u3002"
10016
- );
10017
- }
10018
- run("python3", ["scripts/build-index.py"], { cwd: repo });
10019
- run("git", ["-C", repo, "add", "-A"]);
10020
- run("git", ["-C", repo, "-c", "user.name=hcm-cli", "-c", "user.email=chiron@local", "commit", "-q", "-m", `case: ${id}\uFF08\u9879\u76EE\u6848\u4F8B\u4E0A\u884C\uFF09`]);
10021
- run("git", ["-C", repo, "push", "-q", "-f", "-u", "origin", branch]);
10022
- const pr = run("cnb", [
10023
- "pulls",
10024
- "post-pull",
10025
- "--repo",
10026
- CASES_REPO_SLUG,
10027
- "--base",
10028
- "main",
10029
- "--head",
10030
- branch,
10031
- "--title",
10032
- `case: ${id}\uFF08\u9879\u76EE\u6848\u4F8B\u4E0A\u884C\uFF09`,
10033
- "--body",
10034
- `\u6765\u6E90\uFF1A${args.origin}
10035
-
10036
- \u7531 \`hcm chiron case submit\` \u63D0\u4EA4\uFF0Clint \u5DF2\u8FC7\u3002`
10037
- ]);
10038
- const num = /number: "?(\d+)/.exec(pr)?.[1];
10039
- rmSync(INDEX_CACHE(), { force: true });
10040
- emit4(
10041
- args,
10042
- { id, pr: num, lint: lint.trim() },
10043
- () => `\u5DF2\u5F00 PR #${num ?? "?"}\uFF1A${CNB_ORIGIN}/${CASES_REPO_SLUG}/-/pulls/${num ?? ""}
10044
- ${lint.trim()}`
10046
+ function workspaceActiveNextCommand(activeWorkspaceKey) {
10047
+ return activeWorkspaceKey ? "hcm workspace deactivate" : null;
10048
+ }
10049
+ function unwrapWorkspaceActionPayload(response) {
10050
+ if (!response || typeof response !== "object") return response;
10051
+ const envelope = response;
10052
+ if (envelope.data && typeof envelope.data === "object") return envelope.data;
10053
+ if (envelope.result && typeof envelope.result === "object") return envelope.result;
10054
+ return response;
10055
+ }
10056
+ async function requestWorkspaceDeactivation(client3) {
10057
+ const response = await client3.action(
10058
+ "TenantExtensionWorkspace",
10059
+ "unbind-current-user",
10060
+ { method: "POST", scope: "class" }
10061
+ );
10062
+ const binding = unwrapWorkspaceActionPayload(response);
10063
+ if (!binding || typeof binding !== "object" || binding.enabled !== false) {
10064
+ throw new Error("workspace deactivate \u672A\u6536\u5230 enabled=false \u7684\u670D\u52A1\u7AEF\u56DE\u6267\uFF0C\u4E0D\u80FD\u786E\u8BA4\u5DF2\u9000\u51FA\u5F00\u53D1\u6A21\u5F0F");
10065
+ }
10066
+ return binding;
10067
+ }
10068
+ async function workspaceActivateCommand(workspaceKey, args) {
10069
+ try {
10070
+ const client3 = HcmClient19.fromAuthContext(await getActiveAuthContextFromCli(args));
10071
+ const key2 = normalizeWorkspaceKey(workspaceKey);
10072
+ await setDevModeBinding(client3, key2);
10073
+ const fmt = args.output ?? "table";
10074
+ if (fmt === "table") {
10075
+ process.stdout.write(`workspace activated: ${key2}
10076
+ `);
10077
+ process.stdout.write("\u8BE5\u7A7A\u95F4\u7684 metas / scripts / menus / mini_apps \u73B0\u5DF2\u5728\u5F53\u524D\u79DF\u6237\u751F\u6548\u3002\n");
10078
+ } else {
10079
+ process.stdout.write(
10080
+ formatObject20({ workspaceKey: key2, activated: true }, { format: fmt }) + "\n"
10045
10081
  );
10046
- } finally {
10047
- rmSync(work, { recursive: true, force: true });
10048
10082
  }
10049
- });
10083
+ process.exitCode = 0;
10084
+ return;
10085
+ } catch (e) {
10086
+ exitWorkspaceError(e, args.env ?? args.profile);
10087
+ }
10088
+ }
10089
+ async function workspaceDeactivateCommand(args) {
10090
+ try {
10091
+ const client3 = HcmClient19.fromAuthContext(await getActiveAuthContextFromCli(args));
10092
+ const binding = await requestWorkspaceDeactivation(client3);
10093
+ const result = { ...binding, deactivated: true };
10094
+ const fmt = args.output ?? "table";
10095
+ if (fmt === "table") {
10096
+ process.stdout.write("workspace deactivated\n");
10097
+ process.stdout.write("\u5F53\u524D\u8EAB\u4EFD\u5DF2\u9000\u51FA\u5F00\u53D1\u8005\u6A21\u5F0F\uFF1B\u5F00\u53D1\u7A7A\u95F4\u3001\u672C\u5730\u6587\u4EF6\u4E0E\u5DF2\u53D1\u5E03\u8D44\u4EA7\u5747\u672A\u5220\u9664\u3002\n");
10098
+ } else {
10099
+ process.stdout.write(formatObject20(result, { format: fmt }) + "\n");
10100
+ }
10101
+ process.exitCode = 0;
10102
+ return;
10103
+ } catch (e) {
10104
+ exitWorkspaceError(e, args.env ?? args.profile);
10105
+ }
10050
10106
  }
10051
10107
 
10052
- // src/commands/chiron-project.ts
10053
- import { normalizeOrigin as normalizeOrigin3 } from "@hcmai/sdk";
10054
- import { JIRA_BASE, JIRA_PROJECT, jiraTokenSource } from "@hcmai/sdk";
10055
- import { ENV_FILE, parseEnvYaml, renderEnvYaml, findEnvByEndpoint as findEnvByEndpoint3, normalizeOrigin as normalizeOrigin4 } from "@hcmai/sdk";
10056
- import { CASES_REPO_URL as CASES_REPO_URL2 } from "@hcmai/sdk";
10057
- import { JIRA_BASE as JIRA_BASE2, JIRA_PROJECT as JIRA_PROJECT2, JIRA_TOKEN_FILE, jiraTokenSource as jiraTokenSource2 } from "@hcmai/sdk";
10058
- var SKILLS_DIR = "hcm-skills";
10059
- var CHIRON_PROJECT_DIRECTORIES = [
10060
- "work",
10061
- "decisions",
10062
- "evidence",
10063
- "requirements",
10064
- "deliverables",
10065
- "cases",
10066
- "gaps",
10067
- "customer-docs"
10068
- ];
10069
- function projectEnvFromConfig(cfg) {
10070
- const endpoint = normalizeOrigin3(cfg.endpoint);
10108
+ // src/commands/identity.ts
10109
+ init_exit();
10110
+ import axios4 from "axios";
10111
+ import {
10112
+ AUTH_INFO_PATH,
10113
+ CliError as CliError23,
10114
+ CliErrorCode as CliErrorCode22,
10115
+ formatObject as formatObject21,
10116
+ fromAxiosError as fromAxiosError20,
10117
+ loadEnv as loadEnv4,
10118
+ saveEnv as saveEnv3,
10119
+ loadIdentity as loadIdentity4,
10120
+ listIdentities as listIdentities4,
10121
+ deleteIdentity as deleteIdentity3,
10122
+ loadGlobalConfig as loadGlobalConfig8,
10123
+ resolveActiveEnv,
10124
+ printResolvedEnvironment as printResolvedEnvironment6,
10125
+ TokenStore as TokenStore4,
10126
+ toPrincipal
10127
+ } from "@hcmai/sdk";
10128
+ var fetchAuthInfo = async (endpoint, accessToken) => {
10129
+ const response = await axios4.get(`${endpoint.replace(/\/$/, "")}${AUTH_INFO_PATH}`, {
10130
+ headers: { Authorization: `Bearer ${accessToken}` },
10131
+ timeout: 3e4
10132
+ });
10133
+ return response.data;
10134
+ };
10135
+ async function inspectIdentity(name, fetcher = fetchAuthInfo) {
10136
+ const meta2 = await loadIdentity4(name);
10137
+ const env2 = await loadEnv4(meta2.env);
10138
+ const accessToken = await TokenStore4.forIdentity(name).getStoredAccessToken();
10139
+ if (!accessToken) {
10140
+ throw new CliError23({
10141
+ code: CliErrorCode22.AUTH_FAILED,
10142
+ message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
10143
+ context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
10144
+ });
10145
+ }
10146
+ printResolvedEnvironment6({ name: meta2.env, config: env2, source: "identity" }, name, meta2.tenantId);
10147
+ const raw = await fetcher(env2.endpoint, accessToken);
10148
+ const principal = toPrincipal(raw);
10149
+ const body = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
10150
+ const serverScopes = Array.isArray(body.scopes) ? body.scopes.map(String) : void 0;
10071
10151
  return {
10072
- endpoint,
10073
- // 冗余一份 frontend:前后端地址不一致的部署里,页面验收要开的是它。
10074
- frontend: normalizeOrigin3(cfg.frontend ?? endpoint),
10075
- tenant: cfg.tenantId ?? "1"
10152
+ identity: name,
10153
+ env: meta2.env,
10154
+ endpoint: env2.endpoint,
10155
+ scheme: meta2.scheme,
10156
+ userId: principal?.userId ?? null,
10157
+ username: principal?.username ?? null,
10158
+ tenantId: principal?.tenantId ?? null,
10159
+ // null 明确表示服务端没回该字段;[] 才表示服务端确认角色为空。
10160
+ roles: principal?.roles ?? null,
10161
+ scopes: serverScopes ?? meta2.scopes,
10162
+ expiresAt: meta2.expiresAt ?? null,
10163
+ source: AUTH_INFO_PATH
10076
10164
  };
10077
10165
  }
10078
- async function inspectCaseLibrary() {
10166
+ async function identityShow(name, args) {
10079
10167
  try {
10080
- const idx = loadIndex();
10081
- return { ok: true, count: idx.cases.length };
10168
+ const details = await inspectIdentity(name);
10169
+ return exitOk(formatObject21(details, { format: args.output ?? "json" }));
10082
10170
  } catch (e) {
10083
- return { ok: false, reason: firstLine("", e) };
10171
+ exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
10084
10172
  }
10085
10173
  }
10086
- function firstLine(stderr, error) {
10087
- if (error) return error.message;
10088
- const line = stderr.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
10089
- return line ?? "\uFF08\u65E0\u8F93\u51FA\uFF09";
10090
- }
10091
- async function inspectJira() {
10092
- const src = await jiraTokenSource();
10093
- if (!src) {
10094
- return {
10095
- ok: false,
10096
- reason: `\u6CA1\u6709\u4EE4\u724C\u3002\u5728 ${JIRA_BASE} \u53F3\u4E0A\u89D2\u5934\u50CF \u2192 \u4E2A\u4EBA\u8BBE\u7F6E \u2192 Personal Access Tokens \u5EFA\u4E00\u4E2A\uFF0C\u7136\u540E\uFF1Amkdir -p ~/.config/hcm && read -rs pat && printf "%s" "$pat" > ~/.config/hcm/jira-token && chmod 600 ~/.config/hcm/jira-token && unset pat`
10097
- };
10174
+ async function identityList(args) {
10175
+ try {
10176
+ const g = await loadGlobalConfig8();
10177
+ const filter = args.env === "all" ? void 0 : await resolveActiveEnv({ envFlag: args.env }, process.env, g);
10178
+ const names = await listIdentities4(filter);
10179
+ if (names.length === 0) {
10180
+ return exitOk("(no identities)");
10181
+ }
10182
+ const lines = [];
10183
+ for (const n of names) {
10184
+ const meta2 = await loadIdentity4(n);
10185
+ const env2 = await loadEnv4(meta2.env).catch(() => null);
10186
+ const isDefault = env2?.defaultIdentity === n ? "*" : " ";
10187
+ const expired = meta2.expiresAt && new Date(meta2.expiresAt) < /* @__PURE__ */ new Date() ? " (expired)" : "";
10188
+ lines.push(`${isDefault} ${n} scheme=${meta2.scheme} env=${meta2.env}${expired}`);
10189
+ }
10190
+ return exitOk(lines.join("\n"));
10191
+ } catch (e) {
10192
+ exitWithError(e);
10098
10193
  }
10099
- const call = async (path_) => {
10100
- const res = await fetch(`${JIRA_BASE}${path_}`, {
10101
- headers: { Authorization: `Bearer ${src.token}`, Accept: "application/json" },
10102
- signal: AbortSignal.timeout(15e3)
10194
+ }
10195
+ async function identityUse(name) {
10196
+ try {
10197
+ const meta2 = await loadIdentity4(name);
10198
+ const env2 = await loadEnv4(meta2.env).catch(() => {
10199
+ throw new CliError23({
10200
+ code: CliErrorCode22.IDENTITY_NOT_IN_ENV,
10201
+ message: `identity '${name}' references env '${meta2.env}' which no longer exists. Re-create the env, or remove this orphan: hcm identity remove ${name}`
10202
+ });
10103
10203
  });
10104
- return res;
10105
- };
10204
+ env2.defaultIdentity = name;
10205
+ await saveEnv3(meta2.env, env2);
10206
+ return exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
10207
+ } catch (e) {
10208
+ exitWithError(e);
10209
+ }
10210
+ }
10211
+ async function identityRemove(name) {
10106
10212
  try {
10107
- const me = await call("/rest/api/2/myself");
10108
- if (me.status === 401) return { ok: false, from: src.from, reason: "\u4EE4\u724C\u65E0\u6548\u6216\u5DF2\u8FC7\u671F\uFF0C\u91CD\u5EFA PAT \u540E\u91CD\u65B0\u5B58\u4E00\u6B21" };
10109
- if (!me.ok) return { ok: false, from: src.from, reason: `\u8FDE\u5F97\u4E0A\u4F46 /myself \u8FD4\u56DE ${me.status}` };
10110
- const who = (await me.json()).displayName ?? "";
10111
- const project = await call(`/rest/api/2/project/${JIRA_PROJECT}`);
10112
- return {
10113
- ok: project.ok,
10114
- from: src.from,
10115
- who,
10116
- projectVisible: project.ok,
10117
- reason: project.ok ? void 0 : `\u770B\u4E0D\u5230\u9879\u76EE ${JIRA_PROJECT}\uFF08${project.status}\uFF09\uFF0C\u627E Jira \u7BA1\u7406\u5458\u5F00\u6743\u9650`
10118
- };
10213
+ const meta2 = await loadIdentity4(name);
10214
+ try {
10215
+ await TokenStore4.forIdentity(name).clear();
10216
+ } catch (err) {
10217
+ process.stderr.write(
10218
+ `[hcm] event=identity_cleanup_failed identity=${name} reason=${JSON.stringify(String(err.message))}
10219
+ `
10220
+ );
10221
+ }
10222
+ await deleteIdentity3(name);
10223
+ const env2 = await loadEnv4(meta2.env).catch(() => null);
10224
+ if (env2?.defaultIdentity === name) {
10225
+ env2.defaultIdentity = void 0;
10226
+ await saveEnv3(meta2.env, env2);
10227
+ }
10228
+ return exitOk(`\u2705 identity '${name}' removed`);
10119
10229
  } catch (e) {
10120
- return { ok: false, from: src.from, reason: `\u8FDE\u4E0D\u4E0A ${JIRA_BASE}\uFF1A${e.message}` };
10230
+ exitWithError(e);
10121
10231
  }
10122
10232
  }
10123
10233
 
10124
10234
  // src/commands/chiron-init.ts
10235
+ init_auth_guard();
10236
+ init_exit();
10237
+ import { promises as fs9 } from "fs";
10238
+ import path10 from "path";
10239
+ import {
10240
+ CliError as CliError24,
10241
+ CliErrorCode as CliErrorCode23,
10242
+ HcmClient as HcmClient20,
10243
+ fetchReconIdentity,
10244
+ formatObject as formatObject22,
10245
+ httpProbe,
10246
+ isTempEnv as isTempEnv3,
10247
+ listIdentities as listIdentities5,
10248
+ loadEnv as loadEnv5,
10249
+ discoverProjectEnv as discoverProjectEnv4,
10250
+ findEnvByEndpoint as findEnvByEndpoint4,
10251
+ normalizeOrigin as normalizeOrigin5,
10252
+ loadGlobalConfig as loadGlobalConfig9
10253
+ } from "@hcmai/sdk";
10125
10254
  async function probeTokenTenant(envName, requested) {
10126
10255
  const ctx = await getActiveAuthContextFromCli({ env: envName });
10127
10256
  const client3 = HcmClient20.fromAuthContext(ctx);
@@ -10139,7 +10268,6 @@ var defaultChironInitDeps = {
10139
10268
  await skillsSyncCommand({
10140
10269
  target: "codex",
10141
10270
  env: envName,
10142
- dir: path9.join(root, SKILLS_DIR),
10143
10271
  output: "table"
10144
10272
  });
10145
10273
  } finally {
@@ -10170,7 +10298,7 @@ async function resolveInitEnv(root, args, deps) {
10170
10298
  };
10171
10299
  }
10172
10300
  const existing = await discoverProjectEnv4(root);
10173
- if (existing && path9.dirname(existing.path) === path9.resolve(root)) {
10301
+ if (existing && path10.dirname(existing.path) === path10.resolve(root)) {
10174
10302
  const name2 = args.env ?? existing.config.default;
10175
10303
  const env2 = existing.config.environments[name2];
10176
10304
  if (!env2) throw new CliError24({
@@ -10220,7 +10348,7 @@ ${explicitPaths}` }
10220
10348
  }
10221
10349
  async function scaffoldChironProject(root, env2, envName) {
10222
10350
  const result = { created: [], updated: [], preserved: [] };
10223
- const envFile = path9.join(root, ENV_FILE);
10351
+ const envFile = path10.join(root, ENV_FILE);
10224
10352
  const existing = await fs9.readFile(envFile, "utf8").catch(() => null);
10225
10353
  if (existing !== null) {
10226
10354
  const document = parseEnvYaml(existing);
@@ -10246,14 +10374,14 @@ async function scaffoldChironProject(root, env2, envName) {
10246
10374
  result.created.push(ENV_FILE);
10247
10375
  }
10248
10376
  for (const directory of CHIRON_PROJECT_DIRECTORIES) {
10249
- const absolute = path9.join(root, directory);
10377
+ const absolute = path10.join(root, directory);
10250
10378
  await ensureDirectory(absolute);
10251
- await writeIfAbsent(path9.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
10379
+ await writeIfAbsent(path10.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
10252
10380
  }
10253
10381
  return result;
10254
10382
  }
10255
10383
  async function runChironInit(args, deps = defaultChironInitDeps) {
10256
- const root = path9.resolve(args.project ?? ".");
10384
+ const root = path10.resolve(args.project ?? ".");
10257
10385
  const say = (line) => process.stderr.write(`[chiron init] ${line}
10258
10386
  `);
10259
10387
  const choice = await resolveInitEnv(root, args, deps);
@@ -10685,7 +10813,7 @@ ${r.url}
10685
10813
  init_auth_guard();
10686
10814
  init_exit();
10687
10815
  import { promises as fs10 } from "fs";
10688
- import path10 from "path";
10816
+ import path11 from "path";
10689
10817
  import {
10690
10818
  HcmClient as HcmClient21,
10691
10819
  CliError as CliError25,
@@ -10706,9 +10834,9 @@ var defaultDeps2 = {
10706
10834
  inspectJira: () => inspectJira()
10707
10835
  };
10708
10836
  async function runChironDoctor(args, deps = defaultDeps2) {
10709
- const root = path10.resolve(args.project ?? ".");
10837
+ const root = path11.resolve(args.project ?? ".");
10710
10838
  const report = { ok: false, project: root, env: null, envName: null, lines: [] };
10711
- const envText = await fs10.readFile(path10.join(root, ENV_FILE), "utf8").catch(() => null);
10839
+ const envText = await fs10.readFile(path11.join(root, ENV_FILE), "utf8").catch(() => null);
10712
10840
  if (envText === null) {
10713
10841
  report.lines.push({
10714
10842
  item: "\u767B\u5F55",
@@ -10778,10 +10906,17 @@ async function runChironDoctor(args, deps = defaultDeps2) {
10778
10906
  }
10779
10907
  }
10780
10908
  const skillsLine = async () => {
10781
- const state = await readSkillsState(path10.join(root, SKILLS_DIR));
10782
- if (!state) return { item: "\u6280\u80FD", verdict: "fail", detail: `${SKILLS_DIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`, nextStep: "hcm chiron skills sync" };
10909
+ const state = await readSkillsState(skillsSyncDir(root));
10910
+ if (!state) {
10911
+ return {
10912
+ item: "\u6280\u80FD",
10913
+ verdict: "fail",
10914
+ detail: `${SKILLS_DIR}/${SKILLS_SYNC_SUBDIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`,
10915
+ nextStep: "hcm chiron skills sync"
10916
+ };
10917
+ }
10783
10918
  const count = Object.keys(state.skills).length;
10784
- if (state.endpoint && normalizeOrigin4(state.endpoint) !== env2.endpoint) {
10919
+ if (state.endpoint && normalizeOrigin3(state.endpoint) !== env2.endpoint) {
10785
10920
  return { item: "\u6280\u80FD", verdict: "fail", detail: `${count} \u4E2A\uFF0C\u4F46\u88C5\u81EA ${state.endpoint}\uFF0C\u4E0D\u662F\u9879\u76EE\u73AF\u5883 ${env2.endpoint}`, nextStep: "hcm chiron skills sync \u91CD\u88C5\uFF08\u5B83\u4F1A\u6309\u9879\u76EE\u73AF\u5883\u91CD\u65B0\u5BF9\u8D26\uFF09" };
10786
10921
  }
10787
10922
  if (state.target !== "codex") {
@@ -10835,7 +10970,7 @@ async function chironDoctorCommand(args, deps) {
10835
10970
  // src/commands/chiron-env.ts
10836
10971
  init_exit();
10837
10972
  import { promises as fs11 } from "fs";
10838
- import path11 from "path";
10973
+ import path12 from "path";
10839
10974
  import yaml from "js-yaml";
10840
10975
  import {
10841
10976
  AUTH_INFO_PATH as AUTH_INFO_PATH2,
@@ -10981,9 +11116,9 @@ async function runChironEnv(action, args = {}) {
10981
11116
  if (args.output && !["table", "json", "yaml"].includes(args.output)) {
10982
11117
  invalid2(`\u672A\u77E5\u8F93\u51FA\u683C\u5F0F '${args.output}'\uFF0C\u914D\u7F6E\u672A\u5199\u5165\u3002`, "\u4F7F\u7528 --output table\u3001json \u6216 yaml");
10983
11118
  }
10984
- const root = path11.resolve(args.project ?? ".");
11119
+ const root = path12.resolve(args.project ?? ".");
10985
11120
  const discovered = await discoverProjectEnv5(root);
10986
- const file = discovered?.path ?? path11.join(root, ENV_FILE2);
11121
+ const file = discovered?.path ?? path12.join(root, ENV_FILE2);
10987
11122
  if (!discovered && action !== "add") invalid2(`\u6CA1\u6709\u627E\u5230 ${file}\u3002`, "\u8FDB\u5165\u987E\u95EE\u9879\u76EE\uFF0C\u6216\u8FD0\u884C hcm chiron env add <\u540D\u5B57> --endpoint <URL> --frontend <URL> --tenant <\u79DF\u6237>");
10988
11123
  const original = discovered ? await fs11.readFile(file, "utf8") : null;
10989
11124
  const config2 = original ? parseEnvYaml2(original) : { default: "", environments: {} };
@@ -11079,7 +11214,7 @@ init_exit();
11079
11214
  import { spawnSync } from "child_process";
11080
11215
  import { accessSync, constants } from "fs";
11081
11216
  import fs12 from "fs/promises";
11082
- import path12 from "path";
11217
+ import path13 from "path";
11083
11218
  import { CliError as CliError27, CliErrorCode as CliErrorCode25, formatObject as formatObject26, HcmClient as HcmClient22, loadEnv as loadEnv6 } from "@hcmai/sdk";
11084
11219
  var EVIDENCE_DIR = "evidence";
11085
11220
  var WAIT_MS_MAX = 6e4;
@@ -11120,10 +11255,10 @@ function resolveEvidenceTarget(projectRoot, out) {
11120
11255
  if (!out.endsWith(".png")) {
11121
11256
  throw new CliError27({ code: CliErrorCode25.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
11122
11257
  }
11123
- const root = path12.resolve(projectRoot);
11124
- const evidenceRoot = path12.join(root, EVIDENCE_DIR);
11125
- const absolute = path12.resolve(root, out);
11126
- if (absolute !== evidenceRoot && !absolute.startsWith(evidenceRoot + path12.sep)) {
11258
+ const root = path13.resolve(projectRoot);
11259
+ const evidenceRoot = path13.join(root, EVIDENCE_DIR);
11260
+ const absolute = path13.resolve(root, out);
11261
+ if (absolute !== evidenceRoot && !absolute.startsWith(evidenceRoot + path13.sep)) {
11127
11262
  throw new CliError27({
11128
11263
  code: CliErrorCode25.INVALID_ARGUMENT,
11129
11264
  message: `--out \u8981\u843D\u5728\u9879\u76EE\u7684 ${EVIDENCE_DIR}/ \u4E0B\uFF08${evidenceRoot}\uFF09\uFF0C\u6536\u5230\u7684\u662F ${absolute}`
@@ -11170,9 +11305,9 @@ function findChrome(probe, override) {
11170
11305
  }
11171
11306
  async function assertInsideEvidence(deps, evidenceRoot, absolute) {
11172
11307
  const canonicalRoot = await deps.realpath(evidenceRoot);
11173
- const canonicalParent = await deps.realpath(path12.dirname(absolute));
11308
+ const canonicalParent = await deps.realpath(path13.dirname(absolute));
11174
11309
  if (canonicalRoot === null || canonicalParent === null) return;
11175
- if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path12.sep)) {
11310
+ if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path13.sep)) {
11176
11311
  throw new CliError27({
11177
11312
  code: CliErrorCode25.INVALID_ARGUMENT,
11178
11313
  message: `--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u8DD1\u51FA\u4E86 ${EVIDENCE_DIR}/\uFF1A${canonicalParent}`
@@ -11191,7 +11326,7 @@ async function runChironPage(target, args, deps) {
11191
11326
  const reject = (args.rejectText ?? []).filter((t) => t.trim().length > 0);
11192
11327
  const viewport = parseViewport(args.size ?? "1440x900");
11193
11328
  const waitMs = parseWaitMs(args.waitMs);
11194
- const root = path12.resolve(args.project ?? ".");
11329
+ const root = path13.resolve(args.project ?? ".");
11195
11330
  const { evidenceRoot, absolute } = resolveEvidenceTarget(root, args.out);
11196
11331
  if (await deps.present(absolute)) {
11197
11332
  throw new CliError27({
@@ -11199,7 +11334,7 @@ async function runChironPage(target, args, deps) {
11199
11334
  message: `\u622A\u56FE\u5DF2\u5B58\u5728\uFF0C\u4E0D\u8986\u76D6\uFF1A${absolute}\u3002\u6362\u4E2A --out\uFF0C\u6216\u5148\u628A\u65E7\u8BC1\u636E\u632A\u8D70\u3002`
11200
11335
  });
11201
11336
  }
11202
- await deps.ensureDir(path12.dirname(absolute));
11337
+ await deps.ensureDir(path13.dirname(absolute));
11203
11338
  await assertInsideEvidence(deps, evidenceRoot, absolute);
11204
11339
  const browser = deps.findBrowser();
11205
11340
  if (!browser) {
@@ -11312,7 +11447,7 @@ async function chironPageCommand(target, args, deps = defaultChironPageDeps) {
11312
11447
  init_exit();
11313
11448
  import { spawnSync as spawnSync2 } from "child_process";
11314
11449
  import { promises as fs13 } from "fs";
11315
- import path13 from "path";
11450
+ import path14 from "path";
11316
11451
  import yaml2 from "js-yaml";
11317
11452
  import { formatObject as formatObject27 } from "@hcmai/sdk";
11318
11453
 
@@ -12181,7 +12316,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
12181
12316
  continue;
12182
12317
  }
12183
12318
  if (c.file) {
12184
- const file = path13.resolve(root, fill(c.file));
12319
+ const file = path14.resolve(root, fill(c.file));
12185
12320
  const want = c.expect ?? {};
12186
12321
  const bad = [];
12187
12322
  if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
@@ -12197,7 +12332,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
12197
12332
  results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
12198
12333
  continue;
12199
12334
  }
12200
- const out = path13.join("evidence", "test", `${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png");
12335
+ const out = path14.join("evidence", "test", `${spec.name}-${c.name}`.replace(/[^\w一-龥-]+/g, "_") + ".png");
12201
12336
  const argv = [fill(c.page), "--out", out, "--project", root];
12202
12337
  if (opts.env) argv.push("--env", opts.env);
12203
12338
  const as = c.as ?? opts.as;
@@ -12214,11 +12349,11 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
12214
12349
  }
12215
12350
  async function loadCases(target) {
12216
12351
  const stat = await fs13.stat(target);
12217
- const files = stat.isDirectory() ? (await fs13.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path13.join(target, f)) : [target];
12352
+ const files = stat.isDirectory() ? (await fs13.readdir(target)).filter((f) => /\.ya?ml$/.test(f)).sort().map((f) => path14.join(target, f)) : [target];
12218
12353
  const out = [];
12219
12354
  for (const f of files) {
12220
12355
  const spec = yaml2.load(await fs13.readFile(f, "utf8"));
12221
- assertUsableSpec(spec, path13.basename(f));
12356
+ assertUsableSpec(spec, path14.basename(f));
12222
12357
  out.push({ file: f, spec });
12223
12358
  }
12224
12359
  if (out.length === 0) throw new Error(`${target} \u4E0B\u6CA1\u6709\u7528\u4F8B\uFF08*.yml\uFF09`);
@@ -12226,15 +12361,15 @@ async function loadCases(target) {
12226
12361
  }
12227
12362
  async function chironTestCommand(target, args, deps) {
12228
12363
  try {
12229
- const root = path13.resolve(args.project ?? ".");
12230
- const where = path13.resolve(root, target ?? "tests");
12364
+ const root = path14.resolve(args.project ?? ".");
12365
+ const where = path14.resolve(root, target ?? "tests");
12231
12366
  const cases = await loadCases(where);
12232
12367
  const report = [];
12233
12368
  let failed2 = 0;
12234
12369
  for (const { file, spec } of cases) {
12235
12370
  const results = await runCase(spec, root, { env: args.env, as: args.as }, deps);
12236
12371
  failed2 += results.filter((r) => r.verdict === "fail").length;
12237
- report.push({ case: spec.name, file: path13.relative(root, file), results });
12372
+ report.push({ case: spec.name, file: path14.relative(root, file), results });
12238
12373
  }
12239
12374
  const fmt = args.output ?? "table";
12240
12375
  if (fmt === "json" || fmt === "yaml") {
@@ -12375,7 +12510,7 @@ import {
12375
12510
  writeRisk
12376
12511
  } from "@hcmai/sdk";
12377
12512
  import { existsSync as existsSync3 } from "fs";
12378
- import * as path14 from "path";
12513
+ import * as path15 from "path";
12379
12514
  function premise(message, hint = "") {
12380
12515
  process.stderr.write(message + (hint ? `
12381
12516
  \u2192 ${hint}` : "") + "\n");
@@ -12402,13 +12537,13 @@ async function runSeedPlan(args, client3) {
12402
12537
  const reconDir = candidates[0].reconDir;
12403
12538
  if (candidates.length > 1) {
12404
12539
  process.stderr.write(
12405
- `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path14.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path14.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
12540
+ `\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path15.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path15.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
12406
12541
  );
12407
12542
  }
12408
12543
  const round = inspectRound2(reconDir);
12409
12544
  process.stderr.write(roundWarning(round));
12410
12545
  const baseline = {
12411
- path: `${path14.basename(path14.dirname(reconDir))}/${path14.basename(reconDir)}`,
12546
+ path: `${path15.basename(path15.dirname(reconDir))}/${path15.basename(reconDir)}`,
12412
12547
  roundId: round.roundId ?? null
12413
12548
  };
12414
12549
  let exemptions = null;
@@ -12670,7 +12805,7 @@ async function deliverySeedVerifyCommand(args) {
12670
12805
  // src/commands/delivery-seed-find.ts
12671
12806
  import { existsSync as existsSync4 } from "fs";
12672
12807
  import { readFileSync as readFileSync8 } from "fs";
12673
- import * as path15 from "path";
12808
+ import * as path16 from "path";
12674
12809
  import {
12675
12810
  INIT_EXIT_CODES as INIT_EXIT_CODES2,
12676
12811
  ValueHints,
@@ -12684,10 +12819,10 @@ import {
12684
12819
  valuesRoundCaveat
12685
12820
  } from "@hcmai/sdk";
12686
12821
  function provenance(chosenReconDir, others) {
12687
- let line = `> \u57FA\u7EBF\uFF1A\`${path15.basename(chosenReconDir)}\`
12822
+ let line = `> \u57FA\u7EBF\uFF1A\`${path16.basename(chosenReconDir)}\`
12688
12823
  `;
12689
12824
  if (others.length > 0) {
12690
- line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path15.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
12825
+ line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path16.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
12691
12826
  }
12692
12827
  return `${line}
12693
12828
  `;
@@ -13024,7 +13159,7 @@ import {
13024
13159
  runTriageRound
13025
13160
  } from "@hcmai/sdk";
13026
13161
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync10, writeFileSync as writeFileSync3 } from "fs";
13027
- import * as path16 from "path";
13162
+ import * as path17 from "path";
13028
13163
  var DEFAULT_CAPABILITIES3 = "default";
13029
13164
  function premise4(message, hint) {
13030
13165
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
@@ -13060,8 +13195,8 @@ function renderProblems(rows2) {
13060
13195
  `;
13061
13196
  }
13062
13197
  function writeTriageArtifact(outDir, body) {
13063
- const out = path16.join(outDir, "work", "triage.md");
13064
- mkdirSync2(path16.dirname(out), { recursive: true });
13198
+ const out = path17.join(outDir, "work", "triage.md");
13199
+ mkdirSync2(path17.dirname(out), { recursive: true });
13065
13200
  writeFileSync3(out, body, "utf8");
13066
13201
  return out;
13067
13202
  }
@@ -13480,7 +13615,7 @@ program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u
13480
13615
  ).action((model, opts) => updateCommand(model, opts));
13481
13616
  program.command("version").description("\u67E5 CLI \u4E0E\u540E\u7AEF\u4E24\u4E2A\u7248\u672C\uFF08commit / tag / \u6784\u5EFA\u65F6\u95F4\uFF09\u2014\u2014\u514D\u8BA4\u8BC1\uFF0C\u65E0\u9700\u5148 login").option("--endpoint <url>", "\u540E\u7AEF\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u9879\u76EE\u73AF\u5883\u6216 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => versionCommand(opts));
13482
13617
  program.command("upgrade").alias("self-update").description("\u5347\u7EA7 CLI \u81EA\u5DF1\uFF08\u6CE8\u610F\uFF1A`hcm update` \u662F\u66F4\u65B0\u4E1A\u52A1\u8BB0\u5F55\uFF0C\u4E0D\u662F\u5347\u7EA7\uFF09").option("--check", "\u53EA\u68C0\u67E5\uFF1B\u6709\u65B0\u7248\u672C\u65F6\u4EE5\u9000\u51FA\u7801 1 \u7ED3\u675F\uFF0C\u4FBF\u4E8E\u811A\u672C\u5224\u65AD").action((opts) => upgradeCommand(opts));
13483
- program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path17, opts) => openCommand(path17, opts));
13618
+ program.command("open [path]").description("\u7528\u5F53\u524D CLI \u8EAB\u4EFD\u6253\u5F00\u524D\u7AEF\u9875\u9762\uFF1A\u94F8\u4E00\u5F20 60s \u4E00\u6B21\u6027\u7968\u636E\u4EA4\u7ED9\u6D4F\u89C8\u5668\uFF0C\u4F1A\u8BDD token \u4E0D\u8FDB URL").option("--print-url", "\u53EA\u6253\u5370\u767B\u5F55 URL\uFF0C\u4E0D\u5F00\u6D4F\u89C8\u5668\uFF08\u7ED9 agent \u6D4F\u89C8\u5668 navigate \u7528\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").action((path18, opts) => openCommand(path18, opts));
13484
13619
  var setting = program.command("setting").description("\u79DF\u6237\u7CFB\u7EDF\u53C2\u6570\uFF08\u767B\u5F55\u7B56\u7565 / \u5BC6\u7801\u7B56\u7565 / \u529F\u80FD\u5F00\u5173 / \u96C6\u6210\u53C2\u6570\uFF09");
13485
13620
  setting.command("get <domain>").description("\u8BFB\u67D0\u57DF\u53C2\u6570\uFF08\u5B9A\u4E49 + \u79DF\u6237\u8986\u76D6\u503C\u5408\u5E76\uFF0C\u7F3A\u5931\u56DE\u843D\u9ED8\u8BA4\u503C\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((d, opts) => settingGetCommand(d, opts));
13486
13621
  setting.command("set <domain>").description("\u6539\u53C2\u6570\uFF0C\u53EF\u91CD\u590D --set\uFF1B\u8D70\u53D7\u63A7\u6821\u9A8C\u8DEF\u5F84\u800C\u975E\u6807\u51C6 CRUD").option(