@hcmai/cli 0.13.2 → 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,25 +7330,65 @@ 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 = await Promise.all(Object.keys(state.skills).sort().map(async (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
- let title = known?.title;
7000
- let description = known?.description;
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;
7001
7392
  if (title === void 0 || description === void 0) {
7002
7393
  const markdown = await readInstalled(layout.baseDir, id);
7003
7394
  if (markdown !== void 0) {
@@ -7017,9 +7408,22 @@ async function syncAgentIndexes(layout, manifest2) {
7017
7408
  id,
7018
7409
  title: title ?? id,
7019
7410
  description: description ?? "",
7020
- relativePath: relative2.split(path6.sep).join("/")
7411
+ relativePath: relative2.split(path8.sep).join("/")
7021
7412
  };
7022
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("/")
7424
+ };
7425
+ });
7426
+ const entries = [...managed.filter((m) => !shadowed.has(m.id)), ...localEntries].sort((a, b) => a.id.localeCompare(b.id));
7023
7427
  const status = await upsertAgentsBlock(file, renderAgentsBlock(entries));
7024
7428
  const before = await fsp2.readFile(file, "utf8").catch(() => "");
7025
7429
  const merged = mergeBoundaryBlock(before, manifest2?.agentBoundary);
@@ -7042,13 +7446,13 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
7042
7446
  throw invalid(`\u6280\u80FD\u4F9D\u8D56\u5B58\u5728\u73AF: ${[...pathStack.slice(Math.max(0, start)), id].join(" -> ")}`);
7043
7447
  }
7044
7448
  assertSafeSkillId(id);
7045
- const local = path6.join(sourceRoot, id, "SKILL.md");
7449
+ const local = path8.join(sourceRoot, id, "SKILL.md");
7046
7450
  let markdown;
7047
7451
  try {
7048
7452
  markdown = await fsp2.readFile(local, "utf8");
7049
7453
  } catch (cause) {
7050
7454
  if (cause?.code === "ENOENT") {
7051
- 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)}`);
7052
7456
  }
7053
7457
  throw cause;
7054
7458
  }
@@ -7060,7 +7464,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
7060
7464
  markdown,
7061
7465
  source: local,
7062
7466
  sourceKind: "local",
7063
- references: await readLocalReferences(path6.join(sourceRoot, id))
7467
+ references: await readLocalReferences(path8.join(sourceRoot, id))
7064
7468
  };
7065
7469
  for (const required2 of parseSkillRequirements2(markdown, id)) {
7066
7470
  await visit(required2, id);
@@ -7074,7 +7478,7 @@ async function resolveLocalSkillDocuments(sourceRoot, targetId) {
7074
7478
  }
7075
7479
  async function readSkillsState(baseDir) {
7076
7480
  try {
7077
- 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");
7078
7482
  const parsed = JSON.parse(raw);
7079
7483
  if (!parsed || typeof parsed !== "object" || !parsed.skills) return void 0;
7080
7484
  return migrateSkillsState(parsed);
@@ -7084,7 +7488,7 @@ async function readSkillsState(baseDir) {
7084
7488
  }
7085
7489
  async function writeSkillsState(baseDir, state) {
7086
7490
  await fsp2.mkdir(baseDir, { recursive: true });
7087
- const file = path6.join(baseDir, SKILLS_STATE_FILE);
7491
+ const file = path8.join(baseDir, SKILLS_STATE_FILE);
7088
7492
  const temp = `${file}.${process.pid}.tmp`;
7089
7493
  await fsp2.writeFile(temp, JSON.stringify(state, null, 2) + "\n", "utf8");
7090
7494
  await fsp2.rename(temp, file);
@@ -7117,7 +7521,7 @@ async function upsertAgentsBlock(agentsFile, block) {
7117
7521
  existing = await fsp2.readFile(agentsFile, "utf8");
7118
7522
  } catch (cause) {
7119
7523
  if (cause?.code !== "ENOENT") throw cause;
7120
- await fsp2.mkdir(path6.dirname(agentsFile), { recursive: true });
7524
+ await fsp2.mkdir(path8.dirname(agentsFile), { recursive: true });
7121
7525
  await fsp2.writeFile(agentsFile, block + "\n", "utf8");
7122
7526
  return "created";
7123
7527
  }
@@ -7143,7 +7547,7 @@ async function installSkillDocuments(documents, requestedIds, baseDir, force, me
7143
7547
  if (!document.markdown.trim()) throw invalid(`\u6280\u80FD ${document.id} \u5185\u5BB9\u4E3A\u7A7A`);
7144
7548
  return {
7145
7549
  ...document,
7146
- target: path6.join(baseDir, document.id, "SKILL.md"),
7550
+ target: path8.join(baseDir, document.id, "SKILL.md"),
7147
7551
  bytes: Buffer.byteLength(document.markdown)
7148
7552
  };
7149
7553
  });
@@ -7194,7 +7598,7 @@ async function sameOnDisk(baseDir, candidate) {
7194
7598
  return true;
7195
7599
  }
7196
7600
  async function readLocalReferences(skillDir) {
7197
- const root = path6.join(skillDir, "references");
7601
+ const root = path8.join(skillDir, "references");
7198
7602
  const out = [];
7199
7603
  const walk = async (dir, prefix) => {
7200
7604
  let items;
@@ -7207,12 +7611,12 @@ async function readLocalReferences(skillDir) {
7207
7611
  for (const item of items.sort((a, b) => a.name.localeCompare(b.name))) {
7208
7612
  const relative2 = prefix ? `${prefix}/${item.name}` : item.name;
7209
7613
  if (item.isDirectory()) {
7210
- await walk(path6.join(dir, item.name), relative2);
7614
+ await walk(path8.join(dir, item.name), relative2);
7211
7615
  continue;
7212
7616
  }
7213
7617
  if (!item.isFile()) continue;
7214
7618
  assertSafeReferencePath2(relative2);
7215
- 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") });
7216
7620
  }
7217
7621
  };
7218
7622
  await walk(root, "");
@@ -7244,10 +7648,10 @@ async function removeRenamedSkills(baseDir, renamed) {
7244
7648
  const state = await readSkillsState(baseDir);
7245
7649
  for (const { from } of renamed) {
7246
7650
  assertSafeSkillId(from);
7247
- const dir = path6.join(baseDir, from);
7248
- const resolved = path6.resolve(dir);
7249
- if (resolved !== path6.join(path6.resolve(baseDir), from)) continue;
7250
- 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);
7251
7655
  const exists2 = await fsp2.stat(dir).then(() => true).catch(() => false);
7252
7656
  if (exists2 && !hasSkillFile) {
7253
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" });
@@ -7264,15 +7668,15 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
7264
7668
  const removed = [];
7265
7669
  try {
7266
7670
  for (const document of documents) {
7267
- const target = path6.join(baseDir, document.id, "SKILL.md");
7268
- await fsp2.mkdir(path6.dirname(target), { recursive: true });
7269
- 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`);
7270
7674
  await fsp2.writeFile(temp, document.markdown, "utf8");
7271
7675
  staged.push({ temp, target });
7272
7676
  for (const reference of document.references ?? []) {
7273
7677
  assertSafeReferencePath2(reference.path);
7274
- const referenceTarget = path6.join(baseDir, document.id, "references", reference.path);
7275
- 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 });
7276
7680
  const referenceTemp = `${referenceTarget}.${process.pid}.${Date.now()}.tmp`;
7277
7681
  await fsp2.writeFile(referenceTemp, reference.content, "utf8");
7278
7682
  staged.push({ temp: referenceTemp, target: referenceTarget });
@@ -7280,7 +7684,7 @@ async function writeSkillDocuments(documents, baseDir, removals = []) {
7280
7684
  }
7281
7685
  for (const stale of removals) {
7282
7686
  assertSafeReferencePath2(stale.path);
7283
- const original = path6.join(baseDir, stale.id, "references", stale.path);
7687
+ const original = path8.join(baseDir, stale.id, "references", stale.path);
7284
7688
  const parked = `${original}.${process.pid}.${Date.now()}.removed`;
7285
7689
  await fsp2.rename(original, parked);
7286
7690
  removed.push({ parked, original });
@@ -7326,11 +7730,11 @@ async function recordInstalled(baseDir, documents, meta2) {
7326
7730
  return state;
7327
7731
  }
7328
7732
  function invalid(message) {
7329
- return new CliError19({ code: CliErrorCode18.INVALID_ARGUMENT, message });
7733
+ return new CliError20({ code: CliErrorCode19.INVALID_ARGUMENT, message });
7330
7734
  }
7331
7735
  async function readInstalled(baseDir, id) {
7332
7736
  try {
7333
- return await fsp2.readFile(path6.join(baseDir, id, "SKILL.md"), "utf8");
7737
+ return await fsp2.readFile(path8.join(baseDir, id, "SKILL.md"), "utf8");
7334
7738
  } catch (cause) {
7335
7739
  if (cause?.code === "ENOENT") return void 0;
7336
7740
  throw cause;
@@ -7338,7 +7742,7 @@ async function readInstalled(baseDir, id) {
7338
7742
  }
7339
7743
  async function readInstalledReference(baseDir, id, relative2) {
7340
7744
  try {
7341
- return await fsp2.readFile(path6.join(baseDir, id, "references", relative2), "utf8");
7745
+ return await fsp2.readFile(path8.join(baseDir, id, "references", relative2), "utf8");
7342
7746
  } catch (cause) {
7343
7747
  if (cause?.code === "ENOENT") return void 0;
7344
7748
  throw cause;
@@ -7460,7 +7864,7 @@ async function planSkillUpdate(options) {
7460
7864
  entries.push({
7461
7865
  id,
7462
7866
  status: "locally-modified",
7463
- 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`
7464
7868
  });
7465
7869
  continue;
7466
7870
  }
@@ -7492,16 +7896,16 @@ async function skillsUpdateCommand(args) {
7492
7896
  const layout = await resolveInstallLayout(args);
7493
7897
  const state = await readSkillsState(layout.baseDir);
7494
7898
  if (!state || Object.keys(state.skills).length === 0) {
7495
- throw new CliError19({
7496
- code: CliErrorCode18.INVALID_ARGUMENT,
7497
- 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`
7498
7902
  });
7499
7903
  }
7500
7904
  const source = parseSourceFilter(args.source);
7501
7905
  const endpoint = decideTrackedEndpoint({
7502
7906
  explicit: Boolean(args.endpoint || args.env),
7503
7907
  current: await resolveEndpoint(args).catch((error) => {
7504
- 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;
7505
7909
  throw error;
7506
7910
  }),
7507
7911
  recorded: state.endpoint
@@ -7547,7 +7951,7 @@ async function skillsUpdateCommand(args) {
7547
7951
  const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");
7548
7952
  const fmt = args.output ?? "table";
7549
7953
  if (fmt === "json" || fmt === "yaml") {
7550
- process.stdout.write(formatObject16({
7954
+ process.stdout.write(formatObject17({
7551
7955
  endpoint,
7552
7956
  baseDir: layout.baseDir,
7553
7957
  target: layout.target,
@@ -7623,9 +8027,37 @@ async function skillsUpdateCommand(args) {
7623
8027
  process.exitCode = 0;
7624
8028
  return;
7625
8029
  } catch (e) {
7626
- fail5(e, args);
8030
+ fail6(e, args);
7627
8031
  }
7628
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
+ }
7629
8061
  function assertSyncArgs(args) {
7630
8062
  const only = (args.only ?? []).filter((id) => id.trim().length > 0);
7631
8063
  if (only.length > 0 && args.check) {
@@ -7641,6 +8073,11 @@ var defaultSkillsSyncDeps = {
7641
8073
  if (!layout) return false;
7642
8074
  const state = await readSkillsState(layout.baseDir).catch(() => void 0);
7643
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 }));
7644
8081
  }
7645
8082
  };
7646
8083
  async function skillsSyncCommand(args, deps = defaultSkillsSyncDeps) {
@@ -7650,6 +8087,19 @@ async function skillsSyncCommand(args, deps = defaultSkillsSyncDeps) {
7650
8087
  } catch (e) {
7651
8088
  return exitWithError(e);
7652
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
+ }
7653
8103
  if (only.length > 0) {
7654
8104
  for (const id of only) {
7655
8105
  await deps.install(id, { ...args, all: false });
@@ -7666,15 +8116,15 @@ import {
7666
8116
  bootstrapTenant,
7667
8117
  discoverProjectEnv as discoverProjectEnv3,
7668
8118
  assertDangerWrite as assertDangerWrite3,
7669
- normalizeOrigin as normalizeOrigin2,
8119
+ normalizeOrigin as normalizeOrigin4,
7670
8120
  createHttpClient as createHttpClient3,
7671
- formatObject as formatObject17,
8121
+ formatObject as formatObject18,
7672
8122
  fromAxiosError as fromAxiosError17,
7673
8123
  loadGlobalConfig as loadGlobalConfig7,
7674
8124
  resolveEnvContext as resolveEnvContext6,
7675
8125
  printResolvedEnvironment as printResolvedEnvironment5,
7676
- CliError as CliError20,
7677
- CliErrorCode as CliErrorCode19
8126
+ CliError as CliError21,
8127
+ CliErrorCode as CliErrorCode20
7678
8128
  } from "@hcmai/sdk";
7679
8129
  init_exit();
7680
8130
  async function resolveBootstrapKey(args, stdinTaken) {
@@ -7682,8 +8132,8 @@ async function resolveBootstrapKey(args, stdinTaken) {
7682
8132
  if (fromEnv) return fromEnv;
7683
8133
  if (args.bootstrapKeyStdin) {
7684
8134
  if (stdinTaken) {
7685
- throw new CliError20({
7686
- code: CliErrorCode19.INVALID_ARGUMENT,
8135
+ throw new CliError21({
8136
+ code: CliErrorCode20.INVALID_ARGUMENT,
7687
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"
7688
8138
  });
7689
8139
  }
@@ -7714,8 +8164,8 @@ async function resolveEndpoint2(args) {
7714
8164
  printResolvedEnvironment5(resolved);
7715
8165
  const env2 = resolved.config;
7716
8166
  if (!env2?.endpoint) {
7717
- throw new CliError20({
7718
- code: CliErrorCode19.MISSING_FLAG,
8167
+ throw new CliError21({
8168
+ code: CliErrorCode20.MISSING_FLAG,
7719
8169
  message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
7720
8170
  });
7721
8171
  }
@@ -7724,14 +8174,14 @@ async function resolveEndpoint2(args) {
7724
8174
  async function tenantBootstrapCommand(args) {
7725
8175
  try {
7726
8176
  if (!args.tenantId || !args.adminUsername) {
7727
- throw new CliError20({
7728
- code: CliErrorCode19.MISSING_FLAG,
8177
+ throw new CliError21({
8178
+ code: CliErrorCode20.MISSING_FLAG,
7729
8179
  message: "--tenant-id \u4E0E --admin-username \u5FC5\u586B"
7730
8180
  });
7731
8181
  }
7732
8182
  const endpoint = await resolveEndpoint2(args);
7733
8183
  const project = await discoverProjectEnv3();
7734
- 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) : [];
7735
8185
  assertDangerWrite3({ name: protectedNames.join(", "), danger: protectedNames.length > 0, allowDanger: args.allowDanger }, "\u5F00\u901A\u79DF\u6237");
7736
8186
  if (args.endpoint) process.stderr.write(`\u2192 ${endpoint} \xB7 \u79DF\u6237 ${args.tenantId} \xB7 \u8EAB\u4EFD bootstrap key\uFF08\u6765\u81EA --endpoint\uFF09
7737
8187
  `);
@@ -7766,7 +8216,7 @@ async function tenantBootstrapCommand(args) {
7766
8216
  `
7767
8217
  );
7768
8218
  }
7769
- process.stdout.write(formatObject17(result, { format: fmt }) + "\n");
8219
+ process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
7770
8220
  process.exitCode = 0;
7771
8221
  return;
7772
8222
  } catch (e) {
@@ -7783,11 +8233,11 @@ async function tenantBootstrapCommand(args) {
7783
8233
 
7784
8234
  // src/commands/meta.ts
7785
8235
  import { promises as fsp3 } from "fs";
7786
- import os3 from "os";
8236
+ import os4 from "os";
7787
8237
  import nodePath from "path";
7788
8238
  import {
7789
8239
  HcmClient as HcmClient18,
7790
- formatObject as formatObject18,
8240
+ formatObject as formatObject19,
7791
8241
  fromAxiosError as fromAxiosError18,
7792
8242
  listTenantMeta,
7793
8243
  getTenantMeta,
@@ -7798,8 +8248,8 @@ import {
7798
8248
  formatMetaIssues,
7799
8249
  explainJacksonError,
7800
8250
  META_SCHEMA_SOURCE_COMMIT,
7801
- CliError as CliError21,
7802
- CliErrorCode as CliErrorCode20
8251
+ CliError as CliError22,
8252
+ CliErrorCode as CliErrorCode21
7803
8253
  } from "@hcmai/sdk";
7804
8254
  init_exit();
7805
8255
  init_impersonation_lifecycle();
@@ -7807,7 +8257,7 @@ init_auth_guard();
7807
8257
  async function client2(args) {
7808
8258
  return HcmClient18.fromAuthContext(await getActiveAuthContextFromCli(args));
7809
8259
  }
7810
- function fail6(e, args) {
8260
+ function fail7(e, args) {
7811
8261
  const err = e;
7812
8262
  if (err?.response?.status === 403) {
7813
8263
  exitWithError(
@@ -7830,27 +8280,27 @@ async function metaListCommand(args) {
7830
8280
  const fmt = args.output ?? "json";
7831
8281
  if (fmt !== "json") process.stdout.write(`\u{1F4C4} ${items.length} \u4EFD${total ? ` / \u5171 ${total}` : ""}
7832
8282
  `);
7833
- process.stdout.write(formatObject18(items, { format: fmt }) + "\n");
8283
+ process.stdout.write(formatObject19(items, { format: fmt }) + "\n");
7834
8284
  process.exitCode = 0;
7835
8285
  return;
7836
8286
  } catch (e) {
7837
- fail6(e, args);
8287
+ fail7(e, args);
7838
8288
  }
7839
8289
  }
7840
- async function metaGetCommand(path17, args) {
8290
+ async function metaGetCommand(path18, args) {
7841
8291
  try {
7842
8292
  const c = await client2(args);
7843
- const content = await getTenantMeta(c.raw(), path17);
8293
+ const content = await getTenantMeta(c.raw(), path18);
7844
8294
  process.stdout.write(content.endsWith("\n") ? content : content + "\n");
7845
8295
  process.exitCode = 0;
7846
8296
  return;
7847
8297
  } catch (e) {
7848
- fail6(e, args);
8298
+ fail7(e, args);
7849
8299
  }
7850
8300
  }
7851
8301
  var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
7852
- function parseMetaPath(path17) {
7853
- const base = path17.split(/[\\/]/).pop() ?? path17;
8302
+ function parseMetaPath(path18) {
8303
+ const base = path18.split(/[\\/]/).pop() ?? path18;
7854
8304
  if (!/\.(yml|yaml)$/i.test(base)) return {};
7855
8305
  const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
7856
8306
  return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
@@ -7867,10 +8317,10 @@ function unverifiableReason(e) {
7867
8317
  if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
7868
8318
  return void 0;
7869
8319
  }
7870
- async function verifyAfterWrite(c, path17) {
7871
- const { model, kind, state } = parseMetaPath(path17);
8320
+ async function verifyAfterWrite(c, path18) {
8321
+ const { model, kind, state } = parseMetaPath(path18);
7872
8322
  if (!model || !kind) {
7873
- 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` };
7874
8324
  }
7875
8325
  try {
7876
8326
  await clearMetaCache2(c.raw(), model, {});
@@ -7915,11 +8365,11 @@ async function verifyAfterWrite(c, path17) {
7915
8365
  }
7916
8366
  return { status: "ok" };
7917
8367
  }
7918
- async function metaSetCommand(path17, args) {
8368
+ async function metaSetCommand(path18, args) {
7919
8369
  try {
7920
8370
  if (!args.file) {
7921
- throw new CliError21({
7922
- code: CliErrorCode20.MISSING_FLAG,
8371
+ throw new CliError22({
8372
+ code: CliErrorCode21.MISSING_FLAG,
7923
8373
  message: "--file <path> \u5FC5\u586B\uFF08\u4ECE\u6587\u4EF6\u8BFB\u53D6 meta \u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
7924
8374
  });
7925
8375
  }
@@ -7931,9 +8381,9 @@ async function metaSetCommand(path17, args) {
7931
8381
  process.stdin.on("error", reject);
7932
8382
  }) : await fsp3.readFile(args.file, "utf8");
7933
8383
  if (!args.skipValidate) {
7934
- const result2 = validateMetaContent(path17, content);
8384
+ const result2 = validateMetaContent(path18, content);
7935
8385
  if (result2.issues.length > 0) {
7936
- 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
7937
8387
  `);
7938
8388
  process.stderr.write(formatMetaIssues(result2, " ") + "\n");
7939
8389
  }
@@ -7951,14 +8401,14 @@ async function metaSetCommand(path17, args) {
7951
8401
  const dryFmt = args.output;
7952
8402
  if (dryFmt === "json" || dryFmt === "yaml") {
7953
8403
  process.stdout.write(
7954
- formatObject18(
7955
- { dryRun: true, path: path17, bytes: Buffer.byteLength(content), content },
8404
+ formatObject19(
8405
+ { dryRun: true, path: path18, bytes: Buffer.byteLength(content), content },
7956
8406
  { format: dryFmt }
7957
8407
  ) + "\n"
7958
8408
  );
7959
8409
  } else {
7960
8410
  process.stdout.write(
7961
- `[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
7962
8412
  ---
7963
8413
  ${content}
7964
8414
  `
@@ -7972,13 +8422,13 @@ ${content}
7972
8422
  let backupState = "unknown";
7973
8423
  let backupWhy;
7974
8424
  try {
7975
- const prev = await getTenantMeta(c.raw(), path17);
8425
+ const prev = await getTenantMeta(c.raw(), path18);
7976
8426
  if (!prev || prev.trim() === "") {
7977
8427
  backupState = "absent";
7978
8428
  } else {
7979
8429
  backupFile = nodePath.join(
7980
- os3.tmpdir(),
7981
- `hcm-meta-backup-${Date.now()}-${path17.replace(/[\\/]/g, "_")}`
8430
+ os4.tmpdir(),
8431
+ `hcm-meta-backup-${Date.now()}-${path18.replace(/[\\/]/g, "_")}`
7982
8432
  );
7983
8433
  await fsp3.writeFile(backupFile, prev, "utf8");
7984
8434
  backupState = "saved";
@@ -7993,22 +8443,22 @@ ${content}
7993
8443
  backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
7994
8444
  }
7995
8445
  }
7996
- const result = await saveTenantMeta(c.raw(), path17, content);
8446
+ const result = await saveTenantMeta(c.raw(), path18, content);
7997
8447
  const fmt = args.output ?? "json";
7998
- if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path17}
8448
+ if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path18}
7999
8449
  `);
8000
8450
  const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
8001
- \u653E\u56DE\u53BB\uFF1Ahcm meta set ${path17} --file ${backupFile}${connFlags(args)}
8002
- ` : 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)}
8003
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
8004
- \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)}
8005
8455
  `;
8006
8456
  if (args.verify === false) {
8007
8457
  process.stderr.write(
8008
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
8009
8459
  );
8010
8460
  } else {
8011
- const outcome = await verifyAfterWrite(c, path17);
8461
+ const outcome = await verifyAfterWrite(c, path18);
8012
8462
  if (outcome.status === "broken") {
8013
8463
  const human = explainJacksonError(outcome.raw);
8014
8464
  process.stderr.write(
@@ -8034,40 +8484,40 @@ ${content}
8034
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");
8035
8485
  }
8036
8486
  }
8037
- process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
8487
+ process.stdout.write(formatObject19(result, { format: fmt }) + "\n");
8038
8488
  process.exitCode = 0;
8039
8489
  return;
8040
8490
  } catch (e) {
8041
8491
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
8042
- fail6(e, args);
8492
+ fail7(e, args);
8043
8493
  }
8044
8494
  }
8045
- async function metaDeleteCommand(path17, args) {
8495
+ async function metaDeleteCommand(path18, args) {
8046
8496
  try {
8047
8497
  if (!args.yes) {
8048
- 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`);
8049
8499
  if (!ok) {
8050
8500
  process.stderr.write("\u5DF2\u53D6\u6D88\n");
8051
8501
  process.exit(1);
8052
8502
  }
8053
8503
  }
8054
8504
  const c = await client2(args);
8055
- const result = await deleteTenantMeta(c.raw(), path17);
8505
+ const result = await deleteTenantMeta(c.raw(), path18);
8056
8506
  const fmt = args.output ?? "json";
8057
- 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}
8058
8508
  `);
8059
- process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
8509
+ process.stdout.write(formatObject19(result, { format: fmt }) + "\n");
8060
8510
  process.exitCode = 0;
8061
8511
  return;
8062
8512
  } catch (e) {
8063
- fail6(e, args);
8513
+ fail7(e, args);
8064
8514
  }
8065
8515
  }
8066
- async function metaValidateCommand(path17, args) {
8516
+ async function metaValidateCommand(path18, args) {
8067
8517
  try {
8068
8518
  if (!args.file) {
8069
- throw new CliError21({
8070
- code: CliErrorCode20.MISSING_FLAG,
8519
+ throw new CliError22({
8520
+ code: CliErrorCode21.MISSING_FLAG,
8071
8521
  message: "--file <path> \u5FC5\u586B\uFF08\u8981\u9A8C\u7684\u90A3\u4EFD\u539F\u6587\uFF1B\u7528 - \u8868\u793A stdin\uFF09"
8072
8522
  });
8073
8523
  }
@@ -8078,13 +8528,13 @@ async function metaValidateCommand(path17, args) {
8078
8528
  process.stdin.on("end", () => resolve3(buf));
8079
8529
  process.stdin.on("error", reject);
8080
8530
  }) : await fsp3.readFile(args.file, "utf8");
8081
- const result = validateMetaContent(path17, content);
8531
+ const result = validateMetaContent(path18, content);
8082
8532
  const fmt = args.output ?? "table";
8083
8533
  if (fmt === "json" || fmt === "yaml") {
8084
8534
  process.stdout.write(
8085
- formatObject18(
8535
+ formatObject19(
8086
8536
  {
8087
- path: path17,
8537
+ path: path18,
8088
8538
  kind: result.kind,
8089
8539
  schemaKnown: result.schemaKnown,
8090
8540
  schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
@@ -8096,7 +8546,7 @@ async function metaValidateCommand(path17, args) {
8096
8546
  );
8097
8547
  } else {
8098
8548
  process.stdout.write(
8099
- `\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
8100
8550
  `
8101
8551
  );
8102
8552
  process.stdout.write(
@@ -8107,7 +8557,7 @@ async function metaValidateCommand(path17, args) {
8107
8557
  return;
8108
8558
  } catch (e) {
8109
8559
  if (e.code === "ENOENT") exitWithError(new Error(`\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${args.file}`));
8110
- fail6(e, args);
8560
+ fail7(e, args);
8111
8561
  }
8112
8562
  }
8113
8563
 
@@ -8115,15 +8565,15 @@ async function metaValidateCommand(path17, args) {
8115
8565
  init_exit();
8116
8566
  init_auth_guard();
8117
8567
  import * as crypto from "crypto";
8118
- import * as fs7 from "fs/promises";
8119
- import * as path7 from "path";
8568
+ import * as fs8 from "fs/promises";
8569
+ import * as path9 from "path";
8120
8570
  import {
8121
8571
  buildMiniPreviewTargets,
8122
8572
  buildMiniVerifyAgentReport,
8123
8573
  createWorkspaceFile,
8124
8574
  deleteWorkspaceFile,
8125
8575
  formatMiniVerifyReport,
8126
- formatObject as formatObject19,
8576
+ formatObject as formatObject20,
8127
8577
  formatRows as formatRows5,
8128
8578
  getMiniStatus,
8129
8579
  HcmClient as HcmClient19,
@@ -8256,7 +8706,7 @@ async function workspaceBindCommand(workspaceKey, args) {
8256
8706
  tenantId: args.tenant ?? client3?.tenantId,
8257
8707
  endpoint: args.endpoint ?? client3?.endpoint
8258
8708
  });
8259
- await fs7.mkdir(rootDir, { recursive: true });
8709
+ await fs8.mkdir(rootDir, { recursive: true });
8260
8710
  await writeWorkspaceContext(rootDir, context);
8261
8711
  writeWorkspaceBindResult(context, rootDir, args.output ?? "table");
8262
8712
  process.exitCode = 0;
@@ -8293,7 +8743,7 @@ async function workspaceCreateCommand(workspaceKey, args) {
8293
8743
  tenantId: client3.tenantId,
8294
8744
  endpoint: client3.endpoint
8295
8745
  });
8296
- await fs7.mkdir(rootDir, { recursive: true });
8746
+ await fs8.mkdir(rootDir, { recursive: true });
8297
8747
  await writeWorkspaceContext(rootDir, context);
8298
8748
  writeWorkspaceCreateResult(
8299
8749
  {
@@ -8331,7 +8781,7 @@ async function workspacePullCommand(args) {
8331
8781
  tenantId: client3.tenantId ?? existing?.tenantId,
8332
8782
  endpoint: client3.endpoint ?? existing?.endpoint
8333
8783
  });
8334
- await fs7.mkdir(rootDir, { recursive: true });
8784
+ await fs8.mkdir(rootDir, { recursive: true });
8335
8785
  await writeWorkspaceContext(rootDir, context);
8336
8786
  const files = await listWorkspaceFiles(client3.raw(), workspaceKey, { pageSize: 5e3 });
8337
8787
  const miniApps = detectRemoteMiniApps(files.data);
@@ -8341,7 +8791,7 @@ async function workspacePullCommand(args) {
8341
8791
  http: client3.raw(),
8342
8792
  appCode,
8343
8793
  workspaceKey,
8344
- targetDir: path7.join(rootDir, MINI_APPS_DIR, appCode),
8794
+ targetDir: path9.join(rootDir, MINI_APPS_DIR, appCode),
8345
8795
  tenantId: client3.tenantId,
8346
8796
  endpoint: client3.endpoint,
8347
8797
  profile: args.profile ?? client3.profile,
@@ -8356,7 +8806,7 @@ async function workspacePullCommand(args) {
8356
8806
  const rawRemoteByLocalPath = /* @__PURE__ */ new Map();
8357
8807
  for (const file of rawFiles) {
8358
8808
  const content = await loadWorkspaceFileContent(client3.raw(), file.id);
8359
- const target = path7.join(rootDir, content.relativePath);
8809
+ const target = path9.join(rootDir, content.relativePath);
8360
8810
  await writeTextFile(target, content.content, !!args.force);
8361
8811
  pulledRawFiles.push(content.relativePath);
8362
8812
  rawRemoteByLocalPath.set(content.relativePath, file);
@@ -8407,7 +8857,7 @@ async function workspaceAddMiniCommand(appCode, args) {
8407
8857
  const result = await initMiniAppProject({
8408
8858
  appCode,
8409
8859
  workspaceKey: context.workspaceKey,
8410
- targetDir: path7.join(rootDir, MINI_APPS_DIR, appCode),
8860
+ targetDir: path9.join(rootDir, MINI_APPS_DIR, appCode),
8411
8861
  name: args.name,
8412
8862
  defaultSurface: parseSurface(args.surface),
8413
8863
  templateKind,
@@ -8433,10 +8883,10 @@ async function workspaceRmCommand(relativePath, args) {
8433
8883
  const rootDir = resolveRootDir(args.dir);
8434
8884
  const context = await requireWorkspaceContext(rootDir);
8435
8885
  const normalized = normalizeWorkspaceRmPath(relativePath);
8436
- const absolutePath = path7.join(rootDir, ...normalized.split("/"));
8886
+ const absolutePath = path9.join(rootDir, ...normalized.split("/"));
8437
8887
  let stat;
8438
8888
  try {
8439
- stat = await fs7.lstat(absolutePath);
8889
+ stat = await fs8.lstat(absolutePath);
8440
8890
  } catch (e) {
8441
8891
  if (e.code !== "ENOENT") throw e;
8442
8892
  stat = null;
@@ -8476,7 +8926,7 @@ async function workspaceRmCommand(relativePath, args) {
8476
8926
  if (!stat) {
8477
8927
  if (manifestEntry) {
8478
8928
  process.stdout.write(
8479
- formatObject19(
8929
+ formatObject20(
8480
8930
  {
8481
8931
  workspaceKey: context.workspaceKey,
8482
8932
  file: normalized,
@@ -8492,7 +8942,7 @@ async function workspaceRmCommand(relativePath, args) {
8492
8942
  }
8493
8943
  throw new Error(`workspace file not found locally or in the workspace: ${normalized}`);
8494
8944
  }
8495
- await fs7.unlink(absolutePath);
8945
+ await fs8.unlink(absolutePath);
8496
8946
  const result = {
8497
8947
  workspaceKey: context.workspaceKey,
8498
8948
  file: normalized,
@@ -8501,7 +8951,7 @@ async function workspaceRmCommand(relativePath, args) {
8501
8951
  next: `hcm workspace push --dir ${args.dir ?? "."}`
8502
8952
  };
8503
8953
  if (args.output === "json" || args.output === "yaml") {
8504
- process.stdout.write(formatObject19(result, { format: args.output }) + "\n");
8954
+ process.stdout.write(formatObject20(result, { format: args.output }) + "\n");
8505
8955
  } else {
8506
8956
  process.stdout.write(`workspace file staged for deletion: ${normalized}
8507
8957
  `);
@@ -8548,7 +8998,7 @@ async function workspaceStatusCommand(args) {
8548
8998
  }
8549
8999
  if (args.output === "json" || args.output === "yaml") {
8550
9000
  process.stdout.write(
8551
- formatObject19({ rootDir, miniApps: rows2 }, { format: args.output }) + "\n"
9001
+ formatObject20({ rootDir, miniApps: rows2 }, { format: args.output }) + "\n"
8552
9002
  );
8553
9003
  } else {
8554
9004
  process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
@@ -8653,7 +9103,7 @@ async function workspacePreviewCommand(args) {
8653
9103
  );
8654
9104
  }
8655
9105
  if (args.output === "json" || args.output === "yaml") {
8656
- process.stdout.write(formatObject19(rows2, { format: args.output }) + "\n");
9106
+ process.stdout.write(formatObject20(rows2, { format: args.output }) + "\n");
8657
9107
  } else {
8658
9108
  process.stdout.write(formatRows5(rows2, { format: "table" }) + "\n");
8659
9109
  }
@@ -8766,7 +9216,7 @@ function removedMiniCommand() {
8766
9216
  );
8767
9217
  }
8768
9218
  function resolveRootDir(dir) {
8769
- return path7.resolve(dir ?? ".");
9219
+ return path9.resolve(dir ?? ".");
8770
9220
  }
8771
9221
  function buildWorkspaceContext(args) {
8772
9222
  return {
@@ -8782,7 +9232,7 @@ function buildWorkspaceContext(args) {
8782
9232
  async function readWorkspaceContext(rootDir) {
8783
9233
  try {
8784
9234
  const parsed = JSON.parse(
8785
- await fs7.readFile(path7.join(rootDir, WORKSPACE_CONTEXT_FILE), "utf-8")
9235
+ await fs8.readFile(path9.join(rootDir, WORKSPACE_CONTEXT_FILE), "utf-8")
8786
9236
  );
8787
9237
  if (parsed.kind !== WORKSPACE_CONTEXT_KIND || parsed.version !== WORKSPACE_CONTEXT_VERSION) {
8788
9238
  throw new Error(`${WORKSPACE_CONTEXT_FILE} is not an HCM workspace context`);
@@ -8811,26 +9261,26 @@ async function requireWorkspaceContext(rootDir) {
8811
9261
  return context;
8812
9262
  }
8813
9263
  async function writeWorkspaceContext(rootDir, context) {
8814
- await fs7.writeFile(
8815
- path7.join(rootDir, WORKSPACE_CONTEXT_FILE),
9264
+ await fs8.writeFile(
9265
+ path9.join(rootDir, WORKSPACE_CONTEXT_FILE),
8816
9266
  JSON.stringify(context, null, 2) + "\n"
8817
9267
  );
8818
9268
  }
8819
9269
  async function writeTextFile(file, content, force) {
8820
9270
  try {
8821
- await fs7.access(file);
9271
+ await fs8.access(file);
8822
9272
  if (!force) throw new Error(`${file} already exists; use --force to overwrite`);
8823
9273
  } catch (e) {
8824
9274
  if (e.code !== "ENOENT") throw e;
8825
9275
  }
8826
- await fs7.mkdir(path7.dirname(file), { recursive: true });
8827
- await fs7.writeFile(file, content);
9276
+ await fs8.mkdir(path9.dirname(file), { recursive: true });
9277
+ await fs8.writeFile(file, content);
8828
9278
  }
8829
9279
  async function readWorkspaceRawManifest(rootDir, context) {
8830
9280
  try {
8831
9281
  const parsed = JSON.parse(
8832
- await fs7.readFile(
8833
- 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),
8834
9284
  "utf-8"
8835
9285
  )
8836
9286
  );
@@ -8852,8 +9302,8 @@ async function readWorkspaceRawManifest(rootDir, context) {
8852
9302
  }
8853
9303
  }
8854
9304
  async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath) {
8855
- const stateDir = path7.join(rootDir, WORKSPACE_STATE_DIR);
8856
- await fs7.mkdir(stateDir, { recursive: true });
9305
+ const stateDir = path9.join(rootDir, WORKSPACE_STATE_DIR);
9306
+ await fs8.mkdir(stateDir, { recursive: true });
8857
9307
  const snapshots = files.map(
8858
9308
  (file) => ({
8859
9309
  localPath: file.localPath,
@@ -8864,8 +9314,8 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
8864
9314
  lastModified: remoteByLocalPath.get(file.localPath)?.lastModified
8865
9315
  })
8866
9316
  );
8867
- await fs7.writeFile(
8868
- path7.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
9317
+ await fs8.writeFile(
9318
+ path9.join(stateDir, WORKSPACE_PULL_MANIFEST_FILE),
8869
9319
  JSON.stringify(
8870
9320
  {
8871
9321
  version: WORKSPACE_CONTEXT_VERSION,
@@ -8881,10 +9331,10 @@ async function writeWorkspaceRawState(rootDir, context, files, remoteByLocalPath
8881
9331
  );
8882
9332
  }
8883
9333
  async function writeWorkspaceRawManifest(rootDir, manifest2) {
8884
- const stateDir = path7.join(rootDir, WORKSPACE_STATE_DIR);
8885
- await fs7.mkdir(stateDir, { recursive: true });
8886
- await fs7.writeFile(
8887
- 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),
8888
9338
  JSON.stringify(manifest2, null, 2) + "\n",
8889
9339
  "utf8"
8890
9340
  );
@@ -8896,10 +9346,10 @@ async function readWorkspaceRawLocalFiles(rootDir) {
8896
9346
  return files;
8897
9347
  }
8898
9348
  async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
8899
- const absoluteDir = path7.join(rootDir, relativeDir);
9349
+ const absoluteDir = path9.join(rootDir, relativeDir);
8900
9350
  let entries;
8901
9351
  try {
8902
- entries = await fs7.readdir(absoluteDir, { withFileTypes: true });
9352
+ entries = await fs8.readdir(absoluteDir, { withFileTypes: true });
8903
9353
  } catch (e) {
8904
9354
  if (e.code === "ENOENT") return;
8905
9355
  throw e;
@@ -8907,14 +9357,14 @@ async function walkWorkspaceRawFiles(rootDir, relativeDir, files) {
8907
9357
  for (const entry of entries) {
8908
9358
  if (entry.isDirectory() && RAW_WORKSPACE_EXCLUDED_DIRS.has(entry.name)) continue;
8909
9359
  if (entry.isFile() && RAW_WORKSPACE_EXCLUDED_FILES.has(entry.name)) continue;
8910
- const localPath = normalizeRelativePath(path7.posix.join(toPosix(relativeDir), entry.name));
8911
- const absolutePath = path7.join(rootDir, localPath);
9360
+ const localPath = normalizeRelativePath(path9.posix.join(toPosix(relativeDir), entry.name));
9361
+ const absolutePath = path9.join(rootDir, localPath);
8912
9362
  if (entry.isDirectory()) {
8913
9363
  await walkWorkspaceRawFiles(rootDir, localPath, files);
8914
9364
  continue;
8915
9365
  }
8916
9366
  if (!entry.isFile()) continue;
8917
- const content = await fs7.readFile(absolutePath, "utf-8");
9367
+ const content = await fs8.readFile(absolutePath, "utf-8");
8918
9368
  files.push({
8919
9369
  localPath,
8920
9370
  absolutePath,
@@ -9096,15 +9546,15 @@ function workspaceRawConflict(entry, reason) {
9096
9546
  };
9097
9547
  }
9098
9548
  async function discoverMiniApps(rootDir) {
9099
- const appsRoot = path7.join(rootDir, MINI_APPS_DIR);
9549
+ const appsRoot = path9.join(rootDir, MINI_APPS_DIR);
9100
9550
  let entries;
9101
9551
  try {
9102
- entries = await fs7.readdir(appsRoot, { withFileTypes: true });
9552
+ entries = await fs8.readdir(appsRoot, { withFileTypes: true });
9103
9553
  } catch (e) {
9104
9554
  if (e.code === "ENOENT") return [];
9105
9555
  throw e;
9106
9556
  }
9107
- 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));
9108
9558
  }
9109
9559
  function detectRemoteMiniApps(files) {
9110
9560
  const appCodes = /* @__PURE__ */ new Set();
@@ -9247,7 +9697,7 @@ function normalizeWorkspaceKey(value) {
9247
9697
  return key2;
9248
9698
  }
9249
9699
  function normalizeWorkspaceRmPath(value) {
9250
- if (path7.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value)) {
9700
+ if (path9.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value)) {
9251
9701
  throw new Error("workspace rm path must be relative to the bound workspace");
9252
9702
  }
9253
9703
  const normalized = normalizeRelativePath(value);
@@ -9269,7 +9719,7 @@ function normalizeRelativePath(value) {
9269
9719
  return normalized;
9270
9720
  }
9271
9721
  function toPosix(value) {
9272
- return value.split(path7.sep).join("/");
9722
+ return value.split(path9.sep).join("/");
9273
9723
  }
9274
9724
  function sha2563(content) {
9275
9725
  return crypto.createHash("sha256").update(content, "utf-8").digest("hex");
@@ -9297,7 +9747,7 @@ function optionalText(value) {
9297
9747
  }
9298
9748
  function writeWorkspaceListResult(rows2, format, total) {
9299
9749
  if (format !== "table") {
9300
- process.stdout.write(formatObject19({ rows: rows2, total }, { format }) + "\n");
9750
+ process.stdout.write(formatObject20({ rows: rows2, total }, { format }) + "\n");
9301
9751
  return;
9302
9752
  }
9303
9753
  process.stdout.write(formatRows5(toWorkspaceListRows(rows2), { format: "table" }) + "\n");
@@ -9308,7 +9758,7 @@ function writeWorkspaceListResult(rows2, format, total) {
9308
9758
  }
9309
9759
  function writeWorkspaceActiveResult(view, format) {
9310
9760
  if (format !== "table") {
9311
- process.stdout.write(formatObject19(view, { format }) + "\n");
9761
+ process.stdout.write(formatObject20(view, { format }) + "\n");
9312
9762
  return;
9313
9763
  }
9314
9764
  const rows2 = [
@@ -9330,7 +9780,7 @@ function writeWorkspaceActiveResult(view, format) {
9330
9780
  }
9331
9781
  function writeWorkspaceBindResult(context, rootDir, format) {
9332
9782
  if (format !== "table") {
9333
- process.stdout.write(formatObject19({ ...context, rootDir }, { format }) + "\n");
9783
+ process.stdout.write(formatObject20({ ...context, rootDir }, { format }) + "\n");
9334
9784
  return;
9335
9785
  }
9336
9786
  process.stdout.write(
@@ -9344,7 +9794,7 @@ function writeWorkspaceBindResult(context, rootDir, format) {
9344
9794
  }
9345
9795
  function writeWorkspaceCreateResult(result, format) {
9346
9796
  if (format !== "table") {
9347
- process.stdout.write(formatObject19(result, { format }) + "\n");
9797
+ process.stdout.write(formatObject20(result, { format }) + "\n");
9348
9798
  return;
9349
9799
  }
9350
9800
  process.stdout.write(
@@ -9360,7 +9810,7 @@ function writeWorkspaceCreateResult(result, format) {
9360
9810
  }
9361
9811
  function writeWorkspacePullResult(result, format) {
9362
9812
  if (format !== "table") {
9363
- process.stdout.write(formatObject19(result, { format }) + "\n");
9813
+ process.stdout.write(formatObject20(result, { format }) + "\n");
9364
9814
  return;
9365
9815
  }
9366
9816
  const lines = [
@@ -9378,7 +9828,7 @@ function writeWorkspacePullResult(result, format) {
9378
9828
  }
9379
9829
  function writeWorkspaceAddMiniResult(result, rootDir, format) {
9380
9830
  if (format !== "table") {
9381
- process.stdout.write(formatObject19({ ...result, workspaceRoot: rootDir }, { format }) + "\n");
9831
+ process.stdout.write(formatObject20({ ...result, workspaceRoot: rootDir }, { format }) + "\n");
9382
9832
  return;
9383
9833
  }
9384
9834
  process.stdout.write(
@@ -9394,7 +9844,7 @@ function writeWorkspaceAddMiniResult(result, rootDir, format) {
9394
9844
  function writeWorkspaceValidateResult(results, format) {
9395
9845
  if (format !== "table") {
9396
9846
  process.stdout.write(
9397
- formatObject19(
9847
+ formatObject20(
9398
9848
  results.map((item) => ({ artifact: `mini:${item.app.appCode}`, ...item.result })),
9399
9849
  { format }
9400
9850
  ) + "\n"
@@ -9422,7 +9872,7 @@ mini:${item.app.appCode}
9422
9872
  function writeWorkspacePushResult(rawResult, results, format) {
9423
9873
  if (format !== "table") {
9424
9874
  process.stdout.write(
9425
- formatObject19(
9875
+ formatObject20(
9426
9876
  {
9427
9877
  workspaceFiles: { artifact: "workspace", ...rawResult },
9428
9878
  miniApps: results.map((item) => ({
@@ -9481,7 +9931,7 @@ function writeWorkspaceVerifyResult(context, rootDir, raw, reports, format) {
9481
9931
  const ok = rawOk && reports.every((item) => item.report.ok);
9482
9932
  if (format === "json") {
9483
9933
  process.stdout.write(
9484
- formatObject19(
9934
+ formatObject20(
9485
9935
  {
9486
9936
  ok,
9487
9937
  workspaceKey: context.workspaceKey,
@@ -9508,7 +9958,7 @@ function writeWorkspaceVerifyResult(context, rootDir, raw, reports, format) {
9508
9958
  }
9509
9959
  if (format !== "table") {
9510
9960
  process.stdout.write(
9511
- formatObject19(
9961
+ formatObject20(
9512
9962
  {
9513
9963
  ok,
9514
9964
  workspaceKey: context.workspaceKey,
@@ -9593,557 +10043,214 @@ async function setDevModeBinding(client3, workspaceKey) {
9593
10043
  workspaceKey
9594
10044
  });
9595
10045
  }
9596
- function workspaceActiveNextCommand(activeWorkspaceKey) {
9597
- return activeWorkspaceKey ? "hcm workspace deactivate" : null;
9598
- }
9599
- function unwrapWorkspaceActionPayload(response) {
9600
- if (!response || typeof response !== "object") return response;
9601
- const envelope = response;
9602
- if (envelope.data && typeof envelope.data === "object") return envelope.data;
9603
- if (envelope.result && typeof envelope.result === "object") return envelope.result;
9604
- return response;
9605
- }
9606
- async function requestWorkspaceDeactivation(client3) {
9607
- const response = await client3.action(
9608
- "TenantExtensionWorkspace",
9609
- "unbind-current-user",
9610
- { method: "POST", scope: "class" }
9611
- );
9612
- const binding = unwrapWorkspaceActionPayload(response);
9613
- if (!binding || typeof binding !== "object" || binding.enabled !== false) {
9614
- 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");
9615
- }
9616
- return binding;
9617
- }
9618
- async function workspaceActivateCommand(workspaceKey, args) {
9619
- try {
9620
- const client3 = HcmClient19.fromAuthContext(await getActiveAuthContextFromCli(args));
9621
- const key2 = normalizeWorkspaceKey(workspaceKey);
9622
- await setDevModeBinding(client3, key2);
9623
- const fmt = args.output ?? "table";
9624
- if (fmt === "table") {
9625
- process.stdout.write(`workspace activated: ${key2}
9626
- `);
9627
- process.stdout.write("\u8BE5\u7A7A\u95F4\u7684 metas / scripts / menus / mini_apps \u73B0\u5DF2\u5728\u5F53\u524D\u79DF\u6237\u751F\u6548\u3002\n");
9628
- } else {
9629
- process.stdout.write(
9630
- formatObject19({ workspaceKey: key2, activated: true }, { format: fmt }) + "\n"
9631
- );
9632
- }
9633
- process.exitCode = 0;
9634
- return;
9635
- } catch (e) {
9636
- exitWorkspaceError(e, args.env ?? args.profile);
9637
- }
9638
- }
9639
- async function workspaceDeactivateCommand(args) {
9640
- try {
9641
- const client3 = HcmClient19.fromAuthContext(await getActiveAuthContextFromCli(args));
9642
- const binding = await requestWorkspaceDeactivation(client3);
9643
- const result = { ...binding, deactivated: true };
9644
- const fmt = args.output ?? "table";
9645
- if (fmt === "table") {
9646
- process.stdout.write("workspace deactivated\n");
9647
- 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");
9648
- } else {
9649
- process.stdout.write(formatObject19(result, { format: fmt }) + "\n");
9650
- }
9651
- process.exitCode = 0;
9652
- return;
9653
- } catch (e) {
9654
- exitWorkspaceError(e, args.env ?? args.profile);
9655
- }
9656
- }
9657
-
9658
- // src/commands/identity.ts
9659
- init_exit();
9660
- import axios4 from "axios";
9661
- import {
9662
- AUTH_INFO_PATH,
9663
- CliError as CliError22,
9664
- CliErrorCode as CliErrorCode21,
9665
- formatObject as formatObject20,
9666
- fromAxiosError as fromAxiosError20,
9667
- loadEnv as loadEnv4,
9668
- saveEnv as saveEnv3,
9669
- loadIdentity as loadIdentity4,
9670
- listIdentities as listIdentities4,
9671
- deleteIdentity as deleteIdentity3,
9672
- loadGlobalConfig as loadGlobalConfig8,
9673
- resolveActiveEnv,
9674
- printResolvedEnvironment as printResolvedEnvironment6,
9675
- TokenStore as TokenStore4,
9676
- toPrincipal
9677
- } from "@hcmai/sdk";
9678
- var fetchAuthInfo = async (endpoint, accessToken) => {
9679
- const response = await axios4.get(`${endpoint.replace(/\/$/, "")}${AUTH_INFO_PATH}`, {
9680
- headers: { Authorization: `Bearer ${accessToken}` },
9681
- timeout: 3e4
9682
- });
9683
- return response.data;
9684
- };
9685
- async function inspectIdentity(name, fetcher = fetchAuthInfo) {
9686
- const meta2 = await loadIdentity4(name);
9687
- const env2 = await loadEnv4(meta2.env);
9688
- const accessToken = await TokenStore4.forIdentity(name).getStoredAccessToken();
9689
- if (!accessToken) {
9690
- throw new CliError22({
9691
- code: CliErrorCode21.AUTH_FAILED,
9692
- message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
9693
- context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
9694
- });
9695
- }
9696
- printResolvedEnvironment6({ name: meta2.env, config: env2, source: "identity" }, name, meta2.tenantId);
9697
- const raw = await fetcher(env2.endpoint, accessToken);
9698
- const principal = toPrincipal(raw);
9699
- const body = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
9700
- const serverScopes = Array.isArray(body.scopes) ? body.scopes.map(String) : void 0;
9701
- return {
9702
- identity: name,
9703
- env: meta2.env,
9704
- endpoint: env2.endpoint,
9705
- scheme: meta2.scheme,
9706
- userId: principal?.userId ?? null,
9707
- username: principal?.username ?? null,
9708
- tenantId: principal?.tenantId ?? null,
9709
- // null 明确表示服务端没回该字段;[] 才表示服务端确认角色为空。
9710
- roles: principal?.roles ?? null,
9711
- scopes: serverScopes ?? meta2.scopes,
9712
- expiresAt: meta2.expiresAt ?? null,
9713
- source: AUTH_INFO_PATH
9714
- };
9715
- }
9716
- async function identityShow(name, args) {
9717
- try {
9718
- const details = await inspectIdentity(name);
9719
- return exitOk(formatObject20(details, { format: args.output ?? "json" }));
9720
- } catch (e) {
9721
- exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
9722
- }
9723
- }
9724
- async function identityList(args) {
9725
- try {
9726
- const g = await loadGlobalConfig8();
9727
- const filter = args.env === "all" ? void 0 : await resolveActiveEnv({ envFlag: args.env }, process.env, g);
9728
- const names = await listIdentities4(filter);
9729
- if (names.length === 0) {
9730
- return exitOk("(no identities)");
9731
- }
9732
- const lines = [];
9733
- for (const n of names) {
9734
- const meta2 = await loadIdentity4(n);
9735
- const env2 = await loadEnv4(meta2.env).catch(() => null);
9736
- const isDefault = env2?.defaultIdentity === n ? "*" : " ";
9737
- const expired = meta2.expiresAt && new Date(meta2.expiresAt) < /* @__PURE__ */ new Date() ? " (expired)" : "";
9738
- lines.push(`${isDefault} ${n} scheme=${meta2.scheme} env=${meta2.env}${expired}`);
9739
- }
9740
- return exitOk(lines.join("\n"));
9741
- } catch (e) {
9742
- exitWithError(e);
9743
- }
9744
- }
9745
- async function identityUse(name) {
9746
- try {
9747
- const meta2 = await loadIdentity4(name);
9748
- const env2 = await loadEnv4(meta2.env).catch(() => {
9749
- throw new CliError22({
9750
- code: CliErrorCode21.IDENTITY_NOT_IN_ENV,
9751
- message: `identity '${name}' references env '${meta2.env}' which no longer exists. Re-create the env, or remove this orphan: hcm identity remove ${name}`
9752
- });
9753
- });
9754
- env2.defaultIdentity = name;
9755
- await saveEnv3(meta2.env, env2);
9756
- return exitOk(`\u2705 default identity for env '${meta2.env}': ${name}`);
9757
- } catch (e) {
9758
- exitWithError(e);
9759
- }
9760
- }
9761
- async function identityRemove(name) {
9762
- try {
9763
- const meta2 = await loadIdentity4(name);
9764
- try {
9765
- await TokenStore4.forIdentity(name).clear();
9766
- } catch (err) {
9767
- process.stderr.write(
9768
- `[hcm] event=identity_cleanup_failed identity=${name} reason=${JSON.stringify(String(err.message))}
9769
- `
9770
- );
9771
- }
9772
- await deleteIdentity3(name);
9773
- const env2 = await loadEnv4(meta2.env).catch(() => null);
9774
- if (env2?.defaultIdentity === name) {
9775
- env2.defaultIdentity = void 0;
9776
- await saveEnv3(meta2.env, env2);
9777
- }
9778
- return exitOk(`\u2705 identity '${name}' removed`);
9779
- } catch (e) {
9780
- exitWithError(e);
9781
- }
9782
- }
9783
-
9784
- // src/commands/chiron-init.ts
9785
- init_auth_guard();
9786
- init_exit();
9787
- import { promises as fs9 } from "fs";
9788
- import path9 from "path";
9789
- import {
9790
- CliError as CliError24,
9791
- CliErrorCode as CliErrorCode23,
9792
- HcmClient as HcmClient20,
9793
- fetchReconIdentity,
9794
- formatObject as formatObject22,
9795
- httpProbe,
9796
- isTempEnv as isTempEnv3,
9797
- listIdentities as listIdentities5,
9798
- loadEnv as loadEnv5,
9799
- discoverProjectEnv as discoverProjectEnv4,
9800
- findEnvByEndpoint as findEnvByEndpoint4,
9801
- normalizeOrigin as normalizeOrigin5,
9802
- loadGlobalConfig as loadGlobalConfig9
9803
- } from "@hcmai/sdk";
9804
-
9805
- // src/commands/chiron-project.ts
9806
- import { promises as fs8 } from "fs";
9807
-
9808
- // src/commands/chiron-case.ts
9809
- init_exit();
9810
- import { execFileSync } from "child_process";
9811
- import { cpSync, existsSync as existsSync2, mkdirSync, mkdtempSync, readFileSync as readFileSync5, rmSync, statSync as statSync4, writeFileSync as writeFileSync2 } from "fs";
9812
- import os4 from "os";
9813
- import path8 from "path";
9814
- import { CASES_REPO_SLUG, CASES_REPO_URL, CNB_ORIGIN, CliError as CliError23, CliErrorCode as CliErrorCode22, formatObject as formatObject21 } from "@hcmai/sdk";
9815
- var casesCacheDir = () => process.env.HCM_CASES_CACHE?.trim() || path8.join(os4.homedir(), ".cache", "hcm", "chiron-cases");
9816
- var INDEX_CACHE = () => path8.join(casesCacheDir(), "index.json");
9817
- var INDEX_TTL_MS = 60 * 60 * 1e3;
9818
- var fail7 = (message, nextStep) => new CliError23({ code: CliErrorCode22.INVALID_ARGUMENT, message, context: { nextStep } });
9819
- var run = (cmd, args, opts = {}) => execFileSync(cmd, args, { encoding: "utf8", maxBuffer: 1 << 26, ...opts });
9820
- function fetchRepoFile(relPath) {
9821
- let raw;
9822
- try {
9823
- raw = run("cnb", ["git", "get-raw", "--repo", CASES_REPO_SLUG, "--ref-with-path", `main/${relPath}`]);
9824
- } catch (e) {
9825
- throw fail7(
9826
- `\u53D6\u4E0D\u5230\u6848\u4F8B\u5E93\u6587\u4EF6 ${relPath}\uFF1A${String(e.message).split("\n")[0]}`,
9827
- "\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"
9828
- );
9829
- }
9830
- const i = raw.indexOf("data: ");
9831
- 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");
9832
- const body = raw.slice(i + "data: ".length).trim();
9833
- if (body.startsWith('"')) {
9834
- try {
9835
- return JSON.parse(body);
9836
- } catch {
9837
- return body;
9838
- }
9839
- }
9840
- return body;
9841
- }
9842
- function loadIndex(opts = {}) {
9843
- const file = INDEX_CACHE();
9844
- const fresh = !opts.refresh && existsSync2(file) && Date.now() - statSync4(file).mtimeMs < INDEX_TTL_MS;
9845
- if (fresh) return JSON.parse(readFileSync5(file, "utf8"));
9846
- let text;
9847
- try {
9848
- text = fetchRepoFile("index/index.json");
9849
- } catch (e) {
9850
- if (!existsSync2(file)) throw e;
9851
- process.stderr.write(
9852
- `[hcm] \u7D22\u5F15\u6CA1\u62C9\u52A8\uFF08${e.message.split("\n")[0]}\uFF09\uFF0C\u7528\u672C\u673A\u7F13\u5B58\u7684\u90A3\u4EFD\uFF1A${file}
9853
- `
9854
- );
9855
- return JSON.parse(readFileSync5(file, "utf8"));
9856
- }
9857
- mkdirSync(path8.dirname(file), { recursive: true });
9858
- writeFileSync2(file, text);
9859
- return JSON.parse(text);
9860
- }
9861
- function backendFingerprint(env2) {
9862
- if (!env2) return { reason: "\u6CA1\u7ED9 --env\uFF0C\u6CA1\u6CD5\u73B0\u67E5\u6307\u7EB9" };
9863
- try {
9864
- const raw = run(process.execPath, [process.argv[1], "version", "--env", env2, "--output", "json"]);
9865
- const j = JSON.parse(raw.slice(raw.indexOf("{")));
9866
- const backend = j.backend?.commit ?? j.commit ?? j.server?.commit;
9867
- if (!backend) return { reason: "\u540E\u7AEF\u56DE\u6267\u91CC\u6CA1\u6709 commit \u5B57\u6BB5" };
9868
- return { backend: String(backend), cli: String(j.cli?.version ?? j.cliVersion ?? "") };
9869
- } catch (e) {
9870
- return { reason: String(e.message).split("\n")[0]?.slice(0, 120) };
9871
- }
9872
- }
9873
- function matchTag(c, fp) {
9874
- if (!fp.backend) return `\u672A\u6BD4\u5BF9\uFF08${fp.reason ?? "\u6CA1\u6709\u6307\u7EB9"}\uFF09`;
9875
- const be = String(c.fingerprint?.backend_commit ?? "");
9876
- if (!be) return "\u6848\u4F8B\u6CA1\u8BB0\u540E\u7AEF\u6307\u7EB9";
9877
- const a = be.slice(0, 12);
9878
- const b = fp.backend.slice(0, 12);
9879
- return a === b ? "\u5339\u914D" : `\u4E0D\u5339\u914D\uFF08\u6848\u4F8B ${a} / \u5F53\u524D ${b}\uFF09`;
9880
- }
9881
- function emit4(args, data, text) {
9882
- if (args.output === "json" || args.output === "yaml") {
9883
- process.stdout.write(formatObject21(data, { format: args.output }) + "\n");
9884
- } else {
9885
- process.stdout.write(text() + "\n");
9886
- }
9887
- }
9888
- async function guard(fn) {
9889
- try {
9890
- await fn();
9891
- } catch (e) {
9892
- exitWithError(e);
9893
- }
9894
- }
9895
- async function caseSearchCommand(query, args) {
9896
- await guard(async () => {
9897
- const idx = loadIndex({ refresh: args.refresh });
9898
- const fp = backendFingerprint(args.env);
9899
- let raw;
9900
- try {
9901
- raw = run("cnb", [
9902
- "knowledge-base",
9903
- "query-knowledge-base-get",
9904
- "--repo",
9905
- CASES_REPO_SLUG,
9906
- "--query",
9907
- query,
9908
- "--top-k",
9909
- String(args.topK ?? 5),
9910
- "--verbose"
9911
- ]);
9912
- } catch (e) {
9913
- throw fail7(
9914
- `\u6848\u4F8B\u5E93\u68C0\u7D22\u6CA1\u8DD1\u6210\uFF1A${String(e.message).split("\n")[0]}`,
9915
- "\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"
9916
- );
9917
- }
9918
- const json = JSON.parse(raw.slice(raw.indexOf("{")));
9919
- const seen = /* @__PURE__ */ new Map();
9920
- for (const h of json.data ?? []) {
9921
- const p = h.metadata?.path ?? "";
9922
- const m = /^cases\/[^/]+\/([^/]+)\//.exec(p);
9923
- if (!m) continue;
9924
- const id = m[1];
9925
- if (seen.has(id)) continue;
9926
- const c = idx.cases.find((x) => x.id === id);
9927
- seen.set(id, {
9928
- id,
9929
- score: h.score,
9930
- file: p.split("/").pop(),
9931
- status: c?.status,
9932
- tier: c?.tier,
9933
- skills: c?.skills,
9934
- customer_ask: c?.customer_ask,
9935
- match: c ? matchTag(c, fp) : "\u7D22\u5F15\u91CC\u6CA1\u6709\uFF08\u672C\u673A clone \u53EF\u80FD\u65E7\u4E86\uFF0Cgit pull \u4E00\u6B21\uFF09"
9936
- });
9937
- }
9938
- const rows2 = [...seen.values()];
9939
- emit4(
9940
- args,
9941
- { query, rows: rows2 },
9942
- () => rows2.length ? rows2.map((r) => `${r.id} [${r.status ?? "?"}\xB7${r.match}] ${r.customer_ask ?? ""}
9943
- \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`
9944
- );
9945
- });
9946
- }
9947
- async function caseShowCommand(id, args) {
9948
- await guard(async () => {
9949
- const idx = loadIndex({ refresh: args.refresh });
9950
- const c = idx.cases.find((x) => x.id === id);
9951
- if (!c?.path) {
9952
- throw fail7(
9953
- `\u7D22\u5F15\u91CC\u6CA1\u6709\u6848\u4F8B ${id}`,
9954
- `\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`
9955
- );
9956
- }
9957
- const files = args.file ? [args.file] : ["\u95EE\u9898.md", "\u65B9\u6848.md"];
9958
- const parts = [];
9959
- for (const f of files) {
9960
- try {
9961
- parts.push(`# ${f}
9962
-
9963
- ${fetchRepoFile(`${c.path}/${f}`)}`);
9964
- } catch {
9965
- parts.push(`# ${f}
9966
-
9967
- \uFF08\u8FD9\u4E2A\u6848\u4F8B\u6CA1\u6709\u8FD9\u4EFD\u6587\u4EF6\uFF09`);
9968
- }
9969
- }
9970
- const meta2 = fetchRepoFile(`${c.path}/case.yml`);
9971
- emit4(
9972
- args,
9973
- { id, caseYml: meta2, files: parts },
9974
- () => `case.yml:
9975
- ${meta2}
9976
-
9977
- ${parts.join("\n\n---\n\n")}
9978
-
9979
- \uFF08\u8BC1\u636E\u6587\u4EF6\u6CA1\u6709\u4E0B\u8F7D \u2014\u2014 \u53BB ${CNB_ORIGIN}/${CASES_REPO_SLUG}/-/tree/main/${c.path} \u770B\uFF09`
9980
- );
9981
- });
9982
- }
9983
- async function caseMatchCommand(args) {
9984
- await guard(async () => {
9985
- const idx = loadIndex({ refresh: args.refresh });
9986
- const fp = backendFingerprint(args.env);
9987
- 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 }));
9988
- emit4(args, { fingerprint: fp, rows: rows2 }, () => {
9989
- 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`;
9990
- return [head, ...rows2.map((r) => `${r.match === "\u5339\u914D" ? "\u2705" : "\xB7 "} ${r.id} [${r.match}] ${r.customer_ask ?? ""}`)].join("\n");
9991
- });
9992
- });
9993
- }
9994
- async function caseSubmitCommand(dir, args) {
9995
- await guard(async () => {
9996
- const src = path8.resolve(dir);
9997
- if (!existsSync2(path8.join(src, "case.yml"))) {
9998
- 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");
9999
- }
10000
- const yamlText = readFileSync5(path8.join(src, "case.yml"), "utf8");
10001
- const id = /^\s*(?:id|case_id):\s*(\S+)/m.exec(yamlText)?.[1];
10002
- if (!id) throw fail7("case.yml \u91CC\u6CA1\u6709 id", "case.yml \u9876\u5C42\u8981\u6709 `id: CASE-YYYYMMDD-xxx`\u3002");
10003
- const work = mkdtempSync(path8.join(os4.tmpdir(), "hcm-case-submit-"));
10004
- try {
10005
- const repo = path8.join(work, "chiron-cases");
10006
- try {
10007
- run("git", ["clone", "--depth", "1", "--filter=blob:none", "--quiet", CASES_REPO_URL, repo]);
10008
- } catch (e) {
10009
- throw fail7(
10010
- `clone \u6848\u4F8B\u5E93\u5931\u8D25\uFF1A${String(e.message).split("\n")[0]}`,
10011
- `\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`
10012
- );
10013
- }
10014
- const branch = `case/${id}-submit`;
10015
- run("git", ["-C", repo, "checkout", "-q", "-B", branch]);
10016
- const dst = path8.join(repo, "cases", args.category, id);
10017
- cpSync(src, dst, { recursive: true, filter: (p) => !p.includes("node_modules") });
10018
- mkdirSync(path8.join(dst, "evidence"), { recursive: true });
10019
- let doc = readFileSync5(path8.join(dst, "case.yml"), "utf8");
10020
- doc = /^\s*tier:/m.test(doc) ? doc.replace(/^\s*tier:.*$/m, "tier: public") : `tier: public
10021
- ${doc}`;
10022
- doc = /^\s*category:/m.test(doc) ? doc.replace(/^\s*category:.*$/m, `category: ${args.category}`) : `category: ${args.category}
10023
- ${doc}`;
10024
- doc = /^\s*origin:/m.test(doc) ? doc.replace(/^\s*origin:.*$/m, `origin: ${args.origin}`) : `origin: ${args.origin}
10025
- ${doc}`;
10026
- if (!/^\s*status:/m.test(doc)) doc = `status: approved
10027
- ${doc}`;
10028
- writeFileSync2(path8.join(dst, "case.yml"), doc);
10029
- run("python3", ["scripts/render-readme.py", dst], { cwd: repo });
10030
- let lint;
10031
- try {
10032
- lint = run("python3", ["scripts/lint-case.py"], { cwd: repo });
10033
- } catch (e) {
10034
- throw fail7(
10035
- `\u6848\u4F8B lint \u6CA1\u8FC7\uFF0CPR \u6CA1\u5F00\uFF1A
10036
- ${e.stdout ?? e.message}`,
10037
- "\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"
10038
- );
10039
- }
10040
- run("python3", ["scripts/build-index.py"], { cwd: repo });
10041
- run("git", ["-C", repo, "add", "-A"]);
10042
- 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`]);
10043
- run("git", ["-C", repo, "push", "-q", "-f", "-u", "origin", branch]);
10044
- const pr = run("cnb", [
10045
- "pulls",
10046
- "post-pull",
10047
- "--repo",
10048
- CASES_REPO_SLUG,
10049
- "--base",
10050
- "main",
10051
- "--head",
10052
- branch,
10053
- "--title",
10054
- `case: ${id}\uFF08\u9879\u76EE\u6848\u4F8B\u4E0A\u884C\uFF09`,
10055
- "--body",
10056
- `\u6765\u6E90\uFF1A${args.origin}
10057
-
10058
- \u7531 \`hcm chiron case submit\` \u63D0\u4EA4\uFF0Clint \u5DF2\u8FC7\u3002`
10059
- ]);
10060
- const num = /number: "?(\d+)/.exec(pr)?.[1];
10061
- rmSync(INDEX_CACHE(), { force: true });
10062
- emit4(
10063
- args,
10064
- { id, pr: num, lint: lint.trim() },
10065
- () => `\u5DF2\u5F00 PR #${num ?? "?"}\uFF1A${CNB_ORIGIN}/${CASES_REPO_SLUG}/-/pulls/${num ?? ""}
10066
- ${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"
10067
10081
  );
10068
- } finally {
10069
- rmSync(work, { recursive: true, force: true });
10070
10082
  }
10071
- });
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
+ }
10072
10106
  }
10073
10107
 
10074
- // src/commands/chiron-project.ts
10075
- import { normalizeOrigin as normalizeOrigin3 } from "@hcmai/sdk";
10076
- import { JIRA_BASE, JIRA_PROJECT, jiraTokenSource } from "@hcmai/sdk";
10077
- import { ENV_FILE, parseEnvYaml, renderEnvYaml, findEnvByEndpoint as findEnvByEndpoint3, normalizeOrigin as normalizeOrigin4 } from "@hcmai/sdk";
10078
- import { CASES_REPO_URL as CASES_REPO_URL2 } from "@hcmai/sdk";
10079
- import { JIRA_BASE as JIRA_BASE2, JIRA_PROJECT as JIRA_PROJECT2, JIRA_TOKEN_FILE, jiraTokenSource as jiraTokenSource2 } from "@hcmai/sdk";
10080
- var SKILLS_DIR = "hcm-skills";
10081
- var CHIRON_PROJECT_DIRECTORIES = [
10082
- "work",
10083
- "decisions",
10084
- "evidence",
10085
- "requirements",
10086
- "deliverables",
10087
- "cases",
10088
- "gaps",
10089
- "customer-docs"
10090
- ];
10091
- function projectEnvFromConfig(cfg) {
10092
- 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;
10093
10151
  return {
10094
- endpoint,
10095
- // 冗余一份 frontend:前后端地址不一致的部署里,页面验收要开的是它。
10096
- frontend: normalizeOrigin3(cfg.frontend ?? endpoint),
10097
- 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
10098
10164
  };
10099
10165
  }
10100
- async function inspectCaseLibrary() {
10166
+ async function identityShow(name, args) {
10101
10167
  try {
10102
- const idx = loadIndex();
10103
- return { ok: true, count: idx.cases.length };
10168
+ const details = await inspectIdentity(name);
10169
+ return exitOk(formatObject21(details, { format: args.output ?? "json" }));
10104
10170
  } catch (e) {
10105
- return { ok: false, reason: firstLine("", e) };
10171
+ exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
10106
10172
  }
10107
10173
  }
10108
- function firstLine(stderr, error) {
10109
- if (error) return error.message;
10110
- const line = stderr.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
10111
- return line ?? "\uFF08\u65E0\u8F93\u51FA\uFF09";
10112
- }
10113
- async function inspectJira() {
10114
- const src = await jiraTokenSource();
10115
- if (!src) {
10116
- return {
10117
- ok: false,
10118
- 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`
10119
- };
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);
10120
10193
  }
10121
- const call = async (path_) => {
10122
- const res = await fetch(`${JIRA_BASE}${path_}`, {
10123
- headers: { Authorization: `Bearer ${src.token}`, Accept: "application/json" },
10124
- 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
+ });
10125
10203
  });
10126
- return res;
10127
- };
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) {
10128
10212
  try {
10129
- const me = await call("/rest/api/2/myself");
10130
- 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" };
10131
- if (!me.ok) return { ok: false, from: src.from, reason: `\u8FDE\u5F97\u4E0A\u4F46 /myself \u8FD4\u56DE ${me.status}` };
10132
- const who = (await me.json()).displayName ?? "";
10133
- const project = await call(`/rest/api/2/project/${JIRA_PROJECT}`);
10134
- return {
10135
- ok: project.ok,
10136
- from: src.from,
10137
- who,
10138
- projectVisible: project.ok,
10139
- 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`
10140
- };
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`);
10141
10229
  } catch (e) {
10142
- return { ok: false, from: src.from, reason: `\u8FDE\u4E0D\u4E0A ${JIRA_BASE}\uFF1A${e.message}` };
10230
+ exitWithError(e);
10143
10231
  }
10144
10232
  }
10145
10233
 
10146
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";
10147
10254
  async function probeTokenTenant(envName, requested) {
10148
10255
  const ctx = await getActiveAuthContextFromCli({ env: envName });
10149
10256
  const client3 = HcmClient20.fromAuthContext(ctx);
@@ -10161,7 +10268,6 @@ var defaultChironInitDeps = {
10161
10268
  await skillsSyncCommand({
10162
10269
  target: "codex",
10163
10270
  env: envName,
10164
- dir: path9.join(root, SKILLS_DIR),
10165
10271
  output: "table"
10166
10272
  });
10167
10273
  } finally {
@@ -10192,7 +10298,7 @@ async function resolveInitEnv(root, args, deps) {
10192
10298
  };
10193
10299
  }
10194
10300
  const existing = await discoverProjectEnv4(root);
10195
- if (existing && path9.dirname(existing.path) === path9.resolve(root)) {
10301
+ if (existing && path10.dirname(existing.path) === path10.resolve(root)) {
10196
10302
  const name2 = args.env ?? existing.config.default;
10197
10303
  const env2 = existing.config.environments[name2];
10198
10304
  if (!env2) throw new CliError24({
@@ -10242,7 +10348,7 @@ ${explicitPaths}` }
10242
10348
  }
10243
10349
  async function scaffoldChironProject(root, env2, envName) {
10244
10350
  const result = { created: [], updated: [], preserved: [] };
10245
- const envFile = path9.join(root, ENV_FILE);
10351
+ const envFile = path10.join(root, ENV_FILE);
10246
10352
  const existing = await fs9.readFile(envFile, "utf8").catch(() => null);
10247
10353
  if (existing !== null) {
10248
10354
  const document = parseEnvYaml(existing);
@@ -10268,14 +10374,14 @@ async function scaffoldChironProject(root, env2, envName) {
10268
10374
  result.created.push(ENV_FILE);
10269
10375
  }
10270
10376
  for (const directory of CHIRON_PROJECT_DIRECTORIES) {
10271
- const absolute = path9.join(root, directory);
10377
+ const absolute = path10.join(root, directory);
10272
10378
  await ensureDirectory(absolute);
10273
- await writeIfAbsent(path9.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
10379
+ await writeIfAbsent(path10.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
10274
10380
  }
10275
10381
  return result;
10276
10382
  }
10277
10383
  async function runChironInit(args, deps = defaultChironInitDeps) {
10278
- const root = path9.resolve(args.project ?? ".");
10384
+ const root = path10.resolve(args.project ?? ".");
10279
10385
  const say = (line) => process.stderr.write(`[chiron init] ${line}
10280
10386
  `);
10281
10387
  const choice = await resolveInitEnv(root, args, deps);
@@ -10707,7 +10813,7 @@ ${r.url}
10707
10813
  init_auth_guard();
10708
10814
  init_exit();
10709
10815
  import { promises as fs10 } from "fs";
10710
- import path10 from "path";
10816
+ import path11 from "path";
10711
10817
  import {
10712
10818
  HcmClient as HcmClient21,
10713
10819
  CliError as CliError25,
@@ -10728,9 +10834,9 @@ var defaultDeps2 = {
10728
10834
  inspectJira: () => inspectJira()
10729
10835
  };
10730
10836
  async function runChironDoctor(args, deps = defaultDeps2) {
10731
- const root = path10.resolve(args.project ?? ".");
10837
+ const root = path11.resolve(args.project ?? ".");
10732
10838
  const report = { ok: false, project: root, env: null, envName: null, lines: [] };
10733
- 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);
10734
10840
  if (envText === null) {
10735
10841
  report.lines.push({
10736
10842
  item: "\u767B\u5F55",
@@ -10800,10 +10906,17 @@ async function runChironDoctor(args, deps = defaultDeps2) {
10800
10906
  }
10801
10907
  }
10802
10908
  const skillsLine = async () => {
10803
- const state = await readSkillsState(path10.join(root, SKILLS_DIR));
10804
- 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
+ }
10805
10918
  const count = Object.keys(state.skills).length;
10806
- if (state.endpoint && normalizeOrigin4(state.endpoint) !== env2.endpoint) {
10919
+ if (state.endpoint && normalizeOrigin3(state.endpoint) !== env2.endpoint) {
10807
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" };
10808
10921
  }
10809
10922
  if (state.target !== "codex") {
@@ -10857,7 +10970,7 @@ async function chironDoctorCommand(args, deps) {
10857
10970
  // src/commands/chiron-env.ts
10858
10971
  init_exit();
10859
10972
  import { promises as fs11 } from "fs";
10860
- import path11 from "path";
10973
+ import path12 from "path";
10861
10974
  import yaml from "js-yaml";
10862
10975
  import {
10863
10976
  AUTH_INFO_PATH as AUTH_INFO_PATH2,
@@ -11003,9 +11116,9 @@ async function runChironEnv(action, args = {}) {
11003
11116
  if (args.output && !["table", "json", "yaml"].includes(args.output)) {
11004
11117
  invalid2(`\u672A\u77E5\u8F93\u51FA\u683C\u5F0F '${args.output}'\uFF0C\u914D\u7F6E\u672A\u5199\u5165\u3002`, "\u4F7F\u7528 --output table\u3001json \u6216 yaml");
11005
11118
  }
11006
- const root = path11.resolve(args.project ?? ".");
11119
+ const root = path12.resolve(args.project ?? ".");
11007
11120
  const discovered = await discoverProjectEnv5(root);
11008
- const file = discovered?.path ?? path11.join(root, ENV_FILE2);
11121
+ const file = discovered?.path ?? path12.join(root, ENV_FILE2);
11009
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>");
11010
11123
  const original = discovered ? await fs11.readFile(file, "utf8") : null;
11011
11124
  const config2 = original ? parseEnvYaml2(original) : { default: "", environments: {} };
@@ -11101,7 +11214,7 @@ init_exit();
11101
11214
  import { spawnSync } from "child_process";
11102
11215
  import { accessSync, constants } from "fs";
11103
11216
  import fs12 from "fs/promises";
11104
- import path12 from "path";
11217
+ import path13 from "path";
11105
11218
  import { CliError as CliError27, CliErrorCode as CliErrorCode25, formatObject as formatObject26, HcmClient as HcmClient22, loadEnv as loadEnv6 } from "@hcmai/sdk";
11106
11219
  var EVIDENCE_DIR = "evidence";
11107
11220
  var WAIT_MS_MAX = 6e4;
@@ -11142,10 +11255,10 @@ function resolveEvidenceTarget(projectRoot, out) {
11142
11255
  if (!out.endsWith(".png")) {
11143
11256
  throw new CliError27({ code: CliErrorCode25.INVALID_ARGUMENT, message: `--out \u8981\u4EE5 .png \u7ED3\u5C3E\uFF0C\u6536\u5230\u7684\u662F ${out}` });
11144
11257
  }
11145
- const root = path12.resolve(projectRoot);
11146
- const evidenceRoot = path12.join(root, EVIDENCE_DIR);
11147
- const absolute = path12.resolve(root, out);
11148
- 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)) {
11149
11262
  throw new CliError27({
11150
11263
  code: CliErrorCode25.INVALID_ARGUMENT,
11151
11264
  message: `--out \u8981\u843D\u5728\u9879\u76EE\u7684 ${EVIDENCE_DIR}/ \u4E0B\uFF08${evidenceRoot}\uFF09\uFF0C\u6536\u5230\u7684\u662F ${absolute}`
@@ -11192,9 +11305,9 @@ function findChrome(probe, override) {
11192
11305
  }
11193
11306
  async function assertInsideEvidence(deps, evidenceRoot, absolute) {
11194
11307
  const canonicalRoot = await deps.realpath(evidenceRoot);
11195
- const canonicalParent = await deps.realpath(path12.dirname(absolute));
11308
+ const canonicalParent = await deps.realpath(path13.dirname(absolute));
11196
11309
  if (canonicalRoot === null || canonicalParent === null) return;
11197
- if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path12.sep)) {
11310
+ if (canonicalParent !== canonicalRoot && !canonicalParent.startsWith(canonicalRoot + path13.sep)) {
11198
11311
  throw new CliError27({
11199
11312
  code: CliErrorCode25.INVALID_ARGUMENT,
11200
11313
  message: `--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u8DD1\u51FA\u4E86 ${EVIDENCE_DIR}/\uFF1A${canonicalParent}`
@@ -11213,7 +11326,7 @@ async function runChironPage(target, args, deps) {
11213
11326
  const reject = (args.rejectText ?? []).filter((t) => t.trim().length > 0);
11214
11327
  const viewport = parseViewport(args.size ?? "1440x900");
11215
11328
  const waitMs = parseWaitMs(args.waitMs);
11216
- const root = path12.resolve(args.project ?? ".");
11329
+ const root = path13.resolve(args.project ?? ".");
11217
11330
  const { evidenceRoot, absolute } = resolveEvidenceTarget(root, args.out);
11218
11331
  if (await deps.present(absolute)) {
11219
11332
  throw new CliError27({
@@ -11221,7 +11334,7 @@ async function runChironPage(target, args, deps) {
11221
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`
11222
11335
  });
11223
11336
  }
11224
- await deps.ensureDir(path12.dirname(absolute));
11337
+ await deps.ensureDir(path13.dirname(absolute));
11225
11338
  await assertInsideEvidence(deps, evidenceRoot, absolute);
11226
11339
  const browser = deps.findBrowser();
11227
11340
  if (!browser) {
@@ -11334,7 +11447,7 @@ async function chironPageCommand(target, args, deps = defaultChironPageDeps) {
11334
11447
  init_exit();
11335
11448
  import { spawnSync as spawnSync2 } from "child_process";
11336
11449
  import { promises as fs13 } from "fs";
11337
- import path13 from "path";
11450
+ import path14 from "path";
11338
11451
  import yaml2 from "js-yaml";
11339
11452
  import { formatObject as formatObject27 } from "@hcmai/sdk";
11340
11453
 
@@ -12203,7 +12316,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
12203
12316
  continue;
12204
12317
  }
12205
12318
  if (c.file) {
12206
- const file = path13.resolve(root, fill(c.file));
12319
+ const file = path14.resolve(root, fill(c.file));
12207
12320
  const want = c.expect ?? {};
12208
12321
  const bad = [];
12209
12322
  if (want.xlsx_header || want.xlsx_min_rows !== void 0) {
@@ -12219,7 +12332,7 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
12219
12332
  results.push(bad.length ? { name: c.name, verdict: "fail", detail: bad.join("\uFF1B") } : { name: c.name, verdict: "pass", detail: "" });
12220
12333
  continue;
12221
12334
  }
12222
- 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");
12223
12336
  const argv = [fill(c.page), "--out", out, "--project", root];
12224
12337
  if (opts.env) argv.push("--env", opts.env);
12225
12338
  const as = c.as ?? opts.as;
@@ -12236,11 +12349,11 @@ async function runCase(spec, root, opts = {}, deps = defaultDeps3) {
12236
12349
  }
12237
12350
  async function loadCases(target) {
12238
12351
  const stat = await fs13.stat(target);
12239
- 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];
12240
12353
  const out = [];
12241
12354
  for (const f of files) {
12242
12355
  const spec = yaml2.load(await fs13.readFile(f, "utf8"));
12243
- assertUsableSpec(spec, path13.basename(f));
12356
+ assertUsableSpec(spec, path14.basename(f));
12244
12357
  out.push({ file: f, spec });
12245
12358
  }
12246
12359
  if (out.length === 0) throw new Error(`${target} \u4E0B\u6CA1\u6709\u7528\u4F8B\uFF08*.yml\uFF09`);
@@ -12248,15 +12361,15 @@ async function loadCases(target) {
12248
12361
  }
12249
12362
  async function chironTestCommand(target, args, deps) {
12250
12363
  try {
12251
- const root = path13.resolve(args.project ?? ".");
12252
- const where = path13.resolve(root, target ?? "tests");
12364
+ const root = path14.resolve(args.project ?? ".");
12365
+ const where = path14.resolve(root, target ?? "tests");
12253
12366
  const cases = await loadCases(where);
12254
12367
  const report = [];
12255
12368
  let failed2 = 0;
12256
12369
  for (const { file, spec } of cases) {
12257
12370
  const results = await runCase(spec, root, { env: args.env, as: args.as }, deps);
12258
12371
  failed2 += results.filter((r) => r.verdict === "fail").length;
12259
- report.push({ case: spec.name, file: path13.relative(root, file), results });
12372
+ report.push({ case: spec.name, file: path14.relative(root, file), results });
12260
12373
  }
12261
12374
  const fmt = args.output ?? "table";
12262
12375
  if (fmt === "json" || fmt === "yaml") {
@@ -12397,7 +12510,7 @@ import {
12397
12510
  writeRisk
12398
12511
  } from "@hcmai/sdk";
12399
12512
  import { existsSync as existsSync3 } from "fs";
12400
- import * as path14 from "path";
12513
+ import * as path15 from "path";
12401
12514
  function premise(message, hint = "") {
12402
12515
  process.stderr.write(message + (hint ? `
12403
12516
  \u2192 ${hint}` : "") + "\n");
@@ -12424,13 +12537,13 @@ async function runSeedPlan(args, client3) {
12424
12537
  const reconDir = candidates[0].reconDir;
12425
12538
  if (candidates.length > 1) {
12426
12539
  process.stderr.write(
12427
- `\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"
12428
12541
  );
12429
12542
  }
12430
12543
  const round = inspectRound2(reconDir);
12431
12544
  process.stderr.write(roundWarning(round));
12432
12545
  const baseline = {
12433
- path: `${path14.basename(path14.dirname(reconDir))}/${path14.basename(reconDir)}`,
12546
+ path: `${path15.basename(path15.dirname(reconDir))}/${path15.basename(reconDir)}`,
12434
12547
  roundId: round.roundId ?? null
12435
12548
  };
12436
12549
  let exemptions = null;
@@ -12692,7 +12805,7 @@ async function deliverySeedVerifyCommand(args) {
12692
12805
  // src/commands/delivery-seed-find.ts
12693
12806
  import { existsSync as existsSync4 } from "fs";
12694
12807
  import { readFileSync as readFileSync8 } from "fs";
12695
- import * as path15 from "path";
12808
+ import * as path16 from "path";
12696
12809
  import {
12697
12810
  INIT_EXIT_CODES as INIT_EXIT_CODES2,
12698
12811
  ValueHints,
@@ -12706,10 +12819,10 @@ import {
12706
12819
  valuesRoundCaveat
12707
12820
  } from "@hcmai/sdk";
12708
12821
  function provenance(chosenReconDir, others) {
12709
- let line = `> \u57FA\u7EBF\uFF1A\`${path15.basename(chosenReconDir)}\`
12822
+ let line = `> \u57FA\u7EBF\uFF1A\`${path16.basename(chosenReconDir)}\`
12710
12823
  `;
12711
12824
  if (others.length > 0) {
12712
- 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";
12713
12826
  }
12714
12827
  return `${line}
12715
12828
  `;
@@ -13046,7 +13159,7 @@ import {
13046
13159
  runTriageRound
13047
13160
  } from "@hcmai/sdk";
13048
13161
  import { mkdirSync as mkdirSync2, readFileSync as readFileSync10, writeFileSync as writeFileSync3 } from "fs";
13049
- import * as path16 from "path";
13162
+ import * as path17 from "path";
13050
13163
  var DEFAULT_CAPABILITIES3 = "default";
13051
13164
  function premise4(message, hint) {
13052
13165
  process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
@@ -13082,8 +13195,8 @@ function renderProblems(rows2) {
13082
13195
  `;
13083
13196
  }
13084
13197
  function writeTriageArtifact(outDir, body) {
13085
- const out = path16.join(outDir, "work", "triage.md");
13086
- mkdirSync2(path16.dirname(out), { recursive: true });
13198
+ const out = path17.join(outDir, "work", "triage.md");
13199
+ mkdirSync2(path17.dirname(out), { recursive: true });
13087
13200
  writeFileSync3(out, body, "utf8");
13088
13201
  return out;
13089
13202
  }
@@ -13502,7 +13615,7 @@ program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u
13502
13615
  ).action((model, opts) => updateCommand(model, opts));
13503
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));
13504
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));
13505
- 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));
13506
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");
13507
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));
13508
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(