@hcmai/cli 0.4.22 → 0.4.24
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 +716 -157
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +22 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -523,8 +523,8 @@ var init_TerminalRenderer = __esm({
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
/** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
|
|
526
|
-
originLine(
|
|
527
|
-
const segs =
|
|
526
|
+
originLine(path17) {
|
|
527
|
+
const segs = path17.split(".").filter(Boolean);
|
|
528
528
|
if (segs.length < 2) return "";
|
|
529
529
|
const names = segs.map((k) => agentDisplayName(k));
|
|
530
530
|
return chalk.gray(` \u2191 \u6765\u81EA ${names.join(" \u203A ")}`) + "\n";
|
|
@@ -1706,8 +1706,8 @@ function agentLabel(agentId) {
|
|
|
1706
1706
|
if (/^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(agentId)) return `agent \u2026${agentId.slice(-4)}`;
|
|
1707
1707
|
return agentDisplayName(agentId);
|
|
1708
1708
|
}
|
|
1709
|
-
function originLine(
|
|
1710
|
-
const segs = (
|
|
1709
|
+
function originLine(path17) {
|
|
1710
|
+
const segs = (path17 ?? "").split(".").filter(Boolean);
|
|
1711
1711
|
if (segs.length < 2) return null;
|
|
1712
1712
|
return `\u6765\u81EA ${segs.map((k) => agentDisplayName(k)).join(" \u203A ")}`;
|
|
1713
1713
|
}
|
|
@@ -2278,10 +2278,17 @@ async function loginCommand(args) {
|
|
|
2278
2278
|
};
|
|
2279
2279
|
await saveIdentity(idName, identityMeta);
|
|
2280
2280
|
if (principal?.tenantId && String(principal.tenantId) !== String(tenantId)) {
|
|
2281
|
-
|
|
2282
|
-
|
|
2281
|
+
if (args.tenant) {
|
|
2282
|
+
process.stderr.write(
|
|
2283
|
+
`[hcm] WARNING: \u8BF7\u6C42\u7684\u79DF\u6237\u662F ${tenantId}\uFF0C\u4F46 token \u5B9E\u9645\u5F52\u5C5E\u79DF\u6237 ${principal.tenantId}\u3002\u540E\u7EED\u547D\u4EE4\u6309 ${principal.tenantId} \u6267\u884C\u3002
|
|
2283
2284
|
`
|
|
2284
|
-
|
|
2285
|
+
);
|
|
2286
|
+
} else {
|
|
2287
|
+
envCfg.tenantId = String(principal.tenantId);
|
|
2288
|
+
await saveEnv(envName, envCfg);
|
|
2289
|
+
process.stderr.write(`[hcm] env ${envName} \u7684\u79DF\u6237\u5DF2\u8BB0\u4E3A ${principal.tenantId}\uFF08token \u5F52\u5C5E\uFF09\u3002
|
|
2290
|
+
`);
|
|
2291
|
+
}
|
|
2285
2292
|
}
|
|
2286
2293
|
const shouldActivate = args.activate !== false;
|
|
2287
2294
|
if (shouldActivate && envCfg.defaultIdentity !== idName) {
|
|
@@ -3175,7 +3182,7 @@ function launchBrowser(url, platform = process.platform) {
|
|
|
3175
3182
|
child.unref();
|
|
3176
3183
|
}
|
|
3177
3184
|
async function runOpen(target, args, deps) {
|
|
3178
|
-
const
|
|
3185
|
+
const path17 = normalizeTarget(target);
|
|
3179
3186
|
if (!deps.frontend?.trim()) {
|
|
3180
3187
|
throw new CliError12({
|
|
3181
3188
|
code: CliErrorCode11.INVALID_ARGUMENT,
|
|
@@ -3183,13 +3190,13 @@ async function runOpen(target, args, deps) {
|
|
|
3183
3190
|
});
|
|
3184
3191
|
}
|
|
3185
3192
|
const { ticket, expiresIn } = await deps.mintTicket();
|
|
3186
|
-
const url = buildBrowserLoginUrl(deps.frontend, ticket,
|
|
3193
|
+
const url = buildBrowserLoginUrl(deps.frontend, ticket, path17);
|
|
3187
3194
|
if (args.printUrl) {
|
|
3188
3195
|
deps.write(`${url}
|
|
3189
3196
|
`);
|
|
3190
3197
|
} else {
|
|
3191
3198
|
deps.launch(url);
|
|
3192
|
-
deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${
|
|
3199
|
+
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
|
|
3193
3200
|
`);
|
|
3194
3201
|
}
|
|
3195
3202
|
return { url, expiresIn };
|
|
@@ -3283,8 +3290,8 @@ import {
|
|
|
3283
3290
|
formatObject as formatObject7,
|
|
3284
3291
|
fromAxiosError as fromAxiosError9
|
|
3285
3292
|
} from "@hcmai/sdk";
|
|
3286
|
-
function collectYmlFiles(
|
|
3287
|
-
if (statSync(
|
|
3293
|
+
function collectYmlFiles(path17) {
|
|
3294
|
+
if (statSync(path17).isFile()) return [path17];
|
|
3288
3295
|
const out = [];
|
|
3289
3296
|
const walk = (dir) => {
|
|
3290
3297
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -3293,7 +3300,7 @@ function collectYmlFiles(path14) {
|
|
|
3293
3300
|
else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
|
|
3294
3301
|
}
|
|
3295
3302
|
};
|
|
3296
|
-
walk(
|
|
3303
|
+
walk(path17);
|
|
3297
3304
|
return out.sort();
|
|
3298
3305
|
}
|
|
3299
3306
|
var DRY_RUN_CLIENT = {
|
|
@@ -3301,9 +3308,9 @@ var DRY_RUN_CLIENT = {
|
|
|
3301
3308
|
create: async () => ({ id: "" }),
|
|
3302
3309
|
update: async () => ({})
|
|
3303
3310
|
};
|
|
3304
|
-
async function importCommand(
|
|
3311
|
+
async function importCommand(path17, args) {
|
|
3305
3312
|
try {
|
|
3306
|
-
const files = collectYmlFiles(
|
|
3313
|
+
const files = collectYmlFiles(path17);
|
|
3307
3314
|
const fixtures = files.map(
|
|
3308
3315
|
(f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
|
|
3309
3316
|
);
|
|
@@ -4888,17 +4895,17 @@ function emptyHalf() {
|
|
|
4888
4895
|
return { status: "skipped", entries: /* @__PURE__ */ new Map() };
|
|
4889
4896
|
}
|
|
4890
4897
|
function buildUnifiedCatalog(input) {
|
|
4891
|
-
const
|
|
4898
|
+
const chiron2 = emptyHalf();
|
|
4892
4899
|
const cli = emptyHalf();
|
|
4893
4900
|
if (input.source !== "cli" && input.chironManifest) {
|
|
4894
|
-
|
|
4895
|
-
for (const skill of flattenSkills(input.chironManifest))
|
|
4901
|
+
chiron2.status = "fetched";
|
|
4902
|
+
for (const skill of flattenSkills(input.chironManifest)) chiron2.entries.set(skill.id, chironEntry(skill));
|
|
4896
4903
|
}
|
|
4897
4904
|
if (input.source !== "chiron" && input.bundled) {
|
|
4898
4905
|
cli.status = "fetched";
|
|
4899
4906
|
for (const entry of input.bundled) cli.entries.set(entry.id, bundledEntry(entry, input.cliVersion));
|
|
4900
4907
|
}
|
|
4901
|
-
return { chiron, cli };
|
|
4908
|
+
return { chiron: chiron2, cli };
|
|
4902
4909
|
}
|
|
4903
4910
|
function detectIdConflicts(catalog) {
|
|
4904
4911
|
if (catalog.chiron.status !== "fetched" || catalog.cli.status !== "fetched") {
|
|
@@ -6419,10 +6426,10 @@ async function metaListCommand(args) {
|
|
|
6419
6426
|
fail5(e, args);
|
|
6420
6427
|
}
|
|
6421
6428
|
}
|
|
6422
|
-
async function metaGetCommand(
|
|
6429
|
+
async function metaGetCommand(path17, args) {
|
|
6423
6430
|
try {
|
|
6424
6431
|
const c = await client2(args);
|
|
6425
|
-
const content = await getTenantMeta(c.raw(),
|
|
6432
|
+
const content = await getTenantMeta(c.raw(), path17);
|
|
6426
6433
|
process.stdout.write(content.endsWith("\n") ? content : content + "\n");
|
|
6427
6434
|
process.exitCode = 0;
|
|
6428
6435
|
return;
|
|
@@ -6431,8 +6438,8 @@ async function metaGetCommand(path14, args) {
|
|
|
6431
6438
|
}
|
|
6432
6439
|
}
|
|
6433
6440
|
var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
|
|
6434
|
-
function parseMetaPath(
|
|
6435
|
-
const base =
|
|
6441
|
+
function parseMetaPath(path17) {
|
|
6442
|
+
const base = path17.split(/[\\/]/).pop() ?? path17;
|
|
6436
6443
|
if (!/\.(yml|yaml)$/i.test(base)) return {};
|
|
6437
6444
|
const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
|
|
6438
6445
|
return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
|
|
@@ -6449,10 +6456,10 @@ function unverifiableReason(e) {
|
|
|
6449
6456
|
if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
|
|
6450
6457
|
return void 0;
|
|
6451
6458
|
}
|
|
6452
|
-
async function verifyAfterWrite(c,
|
|
6453
|
-
const { model, kind, state } = parseMetaPath(
|
|
6459
|
+
async function verifyAfterWrite(c, path17) {
|
|
6460
|
+
const { model, kind, state } = parseMetaPath(path17);
|
|
6454
6461
|
if (!model || !kind) {
|
|
6455
|
-
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${
|
|
6462
|
+
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path17} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
|
|
6456
6463
|
}
|
|
6457
6464
|
try {
|
|
6458
6465
|
await clearMetaCache2(c.raw(), model, {});
|
|
@@ -6497,7 +6504,7 @@ async function verifyAfterWrite(c, path14) {
|
|
|
6497
6504
|
}
|
|
6498
6505
|
return { status: "ok" };
|
|
6499
6506
|
}
|
|
6500
|
-
async function metaSetCommand(
|
|
6507
|
+
async function metaSetCommand(path17, args) {
|
|
6501
6508
|
try {
|
|
6502
6509
|
if (!args.file) {
|
|
6503
6510
|
throw new CliError19({
|
|
@@ -6513,9 +6520,9 @@ async function metaSetCommand(path14, args) {
|
|
|
6513
6520
|
process.stdin.on("error", reject);
|
|
6514
6521
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6515
6522
|
if (!args.skipValidate) {
|
|
6516
|
-
const result2 = validateMetaContent(
|
|
6523
|
+
const result2 = validateMetaContent(path17, content);
|
|
6517
6524
|
if (result2.issues.length > 0) {
|
|
6518
|
-
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${
|
|
6525
|
+
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path17}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
|
|
6519
6526
|
`);
|
|
6520
6527
|
process.stderr.write(formatMetaIssues(result2, " ") + "\n");
|
|
6521
6528
|
}
|
|
@@ -6534,13 +6541,13 @@ async function metaSetCommand(path14, args) {
|
|
|
6534
6541
|
if (dryFmt === "json" || dryFmt === "yaml") {
|
|
6535
6542
|
process.stdout.write(
|
|
6536
6543
|
formatObject18(
|
|
6537
|
-
{ dryRun: true, path:
|
|
6544
|
+
{ dryRun: true, path: path17, bytes: Buffer.byteLength(content), content },
|
|
6538
6545
|
{ format: dryFmt }
|
|
6539
6546
|
) + "\n"
|
|
6540
6547
|
);
|
|
6541
6548
|
} else {
|
|
6542
6549
|
process.stdout.write(
|
|
6543
|
-
`[dry-run] \u5C06\u5199\u5165 ${
|
|
6550
|
+
`[dry-run] \u5C06\u5199\u5165 ${path17}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
|
|
6544
6551
|
---
|
|
6545
6552
|
${content}
|
|
6546
6553
|
`
|
|
@@ -6554,13 +6561,13 @@ ${content}
|
|
|
6554
6561
|
let backupState = "unknown";
|
|
6555
6562
|
let backupWhy;
|
|
6556
6563
|
try {
|
|
6557
|
-
const prev = await getTenantMeta(c.raw(),
|
|
6564
|
+
const prev = await getTenantMeta(c.raw(), path17);
|
|
6558
6565
|
if (!prev || prev.trim() === "") {
|
|
6559
6566
|
backupState = "absent";
|
|
6560
6567
|
} else {
|
|
6561
6568
|
backupFile = nodePath.join(
|
|
6562
6569
|
os3.tmpdir(),
|
|
6563
|
-
`hcm-meta-backup-${Date.now()}-${
|
|
6570
|
+
`hcm-meta-backup-${Date.now()}-${path17.replace(/[\\/]/g, "_")}`
|
|
6564
6571
|
);
|
|
6565
6572
|
await fsp3.writeFile(backupFile, prev, "utf8");
|
|
6566
6573
|
backupState = "saved";
|
|
@@ -6575,22 +6582,22 @@ ${content}
|
|
|
6575
6582
|
backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
|
|
6576
6583
|
}
|
|
6577
6584
|
}
|
|
6578
|
-
const result = await saveTenantMeta(c.raw(),
|
|
6585
|
+
const result = await saveTenantMeta(c.raw(), path17, content);
|
|
6579
6586
|
const fmt = args.output ?? "json";
|
|
6580
|
-
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${
|
|
6587
|
+
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path17}
|
|
6581
6588
|
`);
|
|
6582
6589
|
const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
|
|
6583
|
-
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${
|
|
6584
|
-
` : 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 ${
|
|
6590
|
+
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${path17} --file ${backupFile}${connFlags(args)}
|
|
6591
|
+
` : 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)}
|
|
6585
6592
|
` : ` \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
|
|
6586
|
-
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${
|
|
6593
|
+
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path17}${connFlags(args)}
|
|
6587
6594
|
`;
|
|
6588
6595
|
if (args.verify === false) {
|
|
6589
6596
|
process.stderr.write(
|
|
6590
6597
|
"\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
|
|
6591
6598
|
);
|
|
6592
6599
|
} else {
|
|
6593
|
-
const outcome = await verifyAfterWrite(c,
|
|
6600
|
+
const outcome = await verifyAfterWrite(c, path17);
|
|
6594
6601
|
if (outcome.status === "broken") {
|
|
6595
6602
|
const human = explainJacksonError(outcome.raw);
|
|
6596
6603
|
process.stderr.write(
|
|
@@ -6623,19 +6630,19 @@ ${content}
|
|
|
6623
6630
|
fail5(e, args);
|
|
6624
6631
|
}
|
|
6625
6632
|
}
|
|
6626
|
-
async function metaDeleteCommand(
|
|
6633
|
+
async function metaDeleteCommand(path17, args) {
|
|
6627
6634
|
try {
|
|
6628
6635
|
if (!args.yes) {
|
|
6629
|
-
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${
|
|
6636
|
+
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path17}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
|
|
6630
6637
|
if (!ok) {
|
|
6631
6638
|
process.stderr.write("\u5DF2\u53D6\u6D88\n");
|
|
6632
6639
|
process.exit(1);
|
|
6633
6640
|
}
|
|
6634
6641
|
}
|
|
6635
6642
|
const c = await client2(args);
|
|
6636
|
-
const result = await deleteTenantMeta(c.raw(),
|
|
6643
|
+
const result = await deleteTenantMeta(c.raw(), path17);
|
|
6637
6644
|
const fmt = args.output ?? "json";
|
|
6638
|
-
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${
|
|
6645
|
+
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path17}
|
|
6639
6646
|
`);
|
|
6640
6647
|
process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
|
|
6641
6648
|
process.exitCode = 0;
|
|
@@ -6644,7 +6651,7 @@ async function metaDeleteCommand(path14, args) {
|
|
|
6644
6651
|
fail5(e, args);
|
|
6645
6652
|
}
|
|
6646
6653
|
}
|
|
6647
|
-
async function metaValidateCommand(
|
|
6654
|
+
async function metaValidateCommand(path17, args) {
|
|
6648
6655
|
try {
|
|
6649
6656
|
if (!args.file) {
|
|
6650
6657
|
throw new CliError19({
|
|
@@ -6659,13 +6666,13 @@ async function metaValidateCommand(path14, args) {
|
|
|
6659
6666
|
process.stdin.on("end", () => resolve4(buf));
|
|
6660
6667
|
process.stdin.on("error", reject);
|
|
6661
6668
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6662
|
-
const result = validateMetaContent(
|
|
6669
|
+
const result = validateMetaContent(path17, content);
|
|
6663
6670
|
const fmt = args.output ?? "table";
|
|
6664
6671
|
if (fmt === "json" || fmt === "yaml") {
|
|
6665
6672
|
process.stdout.write(
|
|
6666
6673
|
formatObject18(
|
|
6667
6674
|
{
|
|
6668
|
-
path:
|
|
6675
|
+
path: path17,
|
|
6669
6676
|
kind: result.kind,
|
|
6670
6677
|
schemaKnown: result.schemaKnown,
|
|
6671
6678
|
schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
|
|
@@ -6677,7 +6684,7 @@ async function metaValidateCommand(path14, args) {
|
|
|
6677
6684
|
);
|
|
6678
6685
|
} else {
|
|
6679
6686
|
process.stdout.write(
|
|
6680
|
-
`\u{1F50E} ${
|
|
6687
|
+
`\u{1F50E} ${path17}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
|
|
6681
6688
|
`
|
|
6682
6689
|
);
|
|
6683
6690
|
process.stdout.write(
|
|
@@ -8963,7 +8970,8 @@ import { promises as fs6 } from "fs";
|
|
|
8963
8970
|
import path6 from "path";
|
|
8964
8971
|
|
|
8965
8972
|
// src/commands/delivery-page-acceptance.ts
|
|
8966
|
-
function renderPageAcceptanceSh() {
|
|
8973
|
+
function renderPageAcceptanceSh(evidenceDir = "\u8BC1\u636E") {
|
|
8974
|
+
const ev = evidenceDir;
|
|
8967
8975
|
return [
|
|
8968
8976
|
"#!/usr/bin/env bash",
|
|
8969
8977
|
"set -euo pipefail",
|
|
@@ -8973,12 +8981,12 @@ function renderPageAcceptanceSh() {
|
|
|
8973
8981
|
"\u7528\u6CD5\uFF1A",
|
|
8974
8982
|
" ./page-acceptance.sh --env <\u73AF\u5883> [--as <\u8EAB\u4EFD>] --path </\u7AD9\u5185\u8DEF\u5F84> \\",
|
|
8975
8983
|
" --expect-text <\u9875\u9762\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C> [--expect-text <\u6587\u672C> ...] \\",
|
|
8976
|
-
|
|
8984
|
+
` --out <${ev}/.../\u622A\u56FE.png> [--reject-text <\u4E0D\u5F97\u51FA\u73B0\u7684\u6587\u672C>] \\`,
|
|
8977
8985
|
" [--wait-ms 10000] [--size 1440x900]",
|
|
8978
8986
|
"",
|
|
8979
8987
|
"\u8BF4\u660E\uFF1A",
|
|
8980
8988
|
" - \u8C03\u7528 hcm open \u94F8\u4E00\u6B21\u6027\u767B\u5F55\u7968\u636E\uFF0C\u5E76\u7ACB\u5373\u4EA4\u7ED9\u672C\u673A Chrome/Chromium\u3002",
|
|
8981
|
-
|
|
8989
|
+
` - \u622A\u56FE\u53EA\u80FD\u5199\u5165\u9879\u76EE\u7684 ${ev}/ \u76EE\u5F55\uFF1B\u5DF2\u6709\u6587\u4EF6\u4E0D\u4F1A\u88AB\u8986\u76D6\u3002`,
|
|
8982
8990
|
" - \u81F3\u5C11\u4E00\u4E2A --expect-text \u662F\u5FC5\u586B\u9879\uFF0C\u9632\u6B62\u628A\u767B\u5F55\u9875\u6216\u9519\u8BEF\u9875\u8BEF\u8BB0\u6210\u901A\u8FC7\u3002",
|
|
8983
8991
|
" - \u6D4F\u89C8\u5668\u672A\u5728 PATH \u65F6\uFF0C\u7528 HCM_CHROME_BIN=/\u7EDD\u5BF9\u8DEF\u5F84 \u6307\u5B9A\u3002",
|
|
8984
8992
|
"USAGE",
|
|
@@ -9034,16 +9042,16 @@ function renderPageAcceptanceSh() {
|
|
|
9034
9042
|
'(( width >= 320 && width <= 7680 && height >= 240 && height <= 7680 )) || fail "--size \u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF08\u5BBD 320..7680\uFF0C\u9AD8 240..7680\uFF09" 2',
|
|
9035
9043
|
"",
|
|
9036
9044
|
'project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"',
|
|
9037
|
-
|
|
9038
|
-
|
|
9039
|
-
`out_abs="$(node -e "const p=require('node:path'); const root=p.resolve(process.argv[1],'
|
|
9045
|
+
`evidence_root="$project_root/${ev}"`,
|
|
9046
|
+
`[[ -d "$evidence_root" && ! -L "$evidence_root" ]] || fail "\u9879\u76EE\u7684 ${ev}/ \u5FC5\u987B\u662F\u666E\u901A\u76EE\u5F55\uFF0C\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5"`,
|
|
9047
|
+
`out_abs="$(node -e "const p=require('node:path'); const root=p.resolve(process.argv[1],'${ev}'); const out=p.resolve(process.argv[1],process.argv[2]); if(out!==root && !out.startsWith(root+p.sep)){process.stderr.write('--out \u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE\u7684 ${ev}/ \u76EE\u5F55\\n'); process.exit(2)} process.stdout.write(out)" "$project_root" "$output")" || exit $?`,
|
|
9040
9048
|
'[[ ! -e "$out_abs" && ! -L "$out_abs" ]] || fail "\u622A\u56FE\u5DF2\u5B58\u5728\u6216\u662F\u7B26\u53F7\u94FE\u63A5\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A$out_abs"',
|
|
9041
9049
|
'mkdir -p "$(dirname "$out_abs")"',
|
|
9042
9050
|
'canonical_root="$(cd "$evidence_root" && pwd -P)"',
|
|
9043
9051
|
'canonical_parent="$(cd "$(dirname "$out_abs")" && pwd -P)"',
|
|
9044
9052
|
'case "$canonical_parent/" in',
|
|
9045
9053
|
' "$canonical_root/"*) ;;',
|
|
9046
|
-
|
|
9054
|
+
` *) fail "--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u9003\u51FA\u4E86 ${ev}/\uFF1A$output" ;;`,
|
|
9047
9055
|
"esac",
|
|
9048
9056
|
"",
|
|
9049
9057
|
"find_browser() {",
|
|
@@ -9424,14 +9432,14 @@ async function assertRegularFile(file) {
|
|
|
9424
9432
|
}
|
|
9425
9433
|
function upsertBlock(existing, begin, end, block) {
|
|
9426
9434
|
const start = existing.indexOf(begin);
|
|
9427
|
-
const
|
|
9428
|
-
const markersAreMalformed = start < 0 !==
|
|
9435
|
+
const finish2 = existing.indexOf(end);
|
|
9436
|
+
const markersAreMalformed = start < 0 !== finish2 < 0 || start >= 0 && (finish2 < start || existing.lastIndexOf(begin) !== start || existing.lastIndexOf(end) !== finish2);
|
|
9429
9437
|
if (markersAreMalformed) {
|
|
9430
9438
|
throw new Error(`\u6258\u7BA1\u5757\u6807\u8BB0\u635F\u574F\u6216\u91CD\u590D\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A${begin} \u2026 ${end}`);
|
|
9431
9439
|
}
|
|
9432
9440
|
let next;
|
|
9433
|
-
if (start >= 0 &&
|
|
9434
|
-
next = `${existing.slice(0, start)}${block}${existing.slice(
|
|
9441
|
+
if (start >= 0 && finish2 >= start) {
|
|
9442
|
+
next = `${existing.slice(0, start)}${block}${existing.slice(finish2 + end.length)}`;
|
|
9435
9443
|
} else {
|
|
9436
9444
|
const prefix = existing.trimEnd();
|
|
9437
9445
|
next = `${prefix}${prefix ? "\n\n" : ""}${block}`;
|
|
@@ -9730,17 +9738,562 @@ async function deliveryDoctorCommand(args) {
|
|
|
9730
9738
|
}
|
|
9731
9739
|
}
|
|
9732
9740
|
|
|
9733
|
-
// src/commands/
|
|
9741
|
+
// src/commands/chiron-init.ts
|
|
9734
9742
|
init_auth_guard();
|
|
9735
9743
|
init_exit();
|
|
9744
|
+
import { promises as fs10 } from "fs";
|
|
9745
|
+
import path10 from "path";
|
|
9736
9746
|
import {
|
|
9747
|
+
CliError as CliError21,
|
|
9748
|
+
CliErrorCode as CliErrorCode20,
|
|
9737
9749
|
HcmClient as HcmClient22,
|
|
9750
|
+
fetchReconIdentity as fetchReconIdentity2,
|
|
9751
|
+
formatObject as formatObject24,
|
|
9752
|
+
httpProbe as httpProbe2,
|
|
9753
|
+
listIdentities as listIdentities3,
|
|
9754
|
+
loadEnv as loadEnv11,
|
|
9755
|
+
loadGlobalConfig as loadGlobalConfig10
|
|
9756
|
+
} from "@hcmai/sdk";
|
|
9757
|
+
|
|
9758
|
+
// src/commands/chiron-project.ts
|
|
9759
|
+
import { promises as fs9 } from "fs";
|
|
9760
|
+
import os4 from "os";
|
|
9761
|
+
import path9 from "path";
|
|
9762
|
+
import { spawnSync } from "child_process";
|
|
9763
|
+
import { hcmConfigDir, listEnvs as listEnvs3, loadEnv as loadEnv10 } from "@hcmai/sdk";
|
|
9764
|
+
var ENV_FILE = "env.yaml";
|
|
9765
|
+
var SKILLS_DIR = "hcm-skills";
|
|
9766
|
+
var CASES_REPO_URL = "https://cnb.cool/hcm/chiron-cases.git";
|
|
9767
|
+
var CASES_MCP_NAME = "chiron-cases";
|
|
9768
|
+
var CHIRON_PROJECT_DIRECTORIES = [
|
|
9769
|
+
"work",
|
|
9770
|
+
"decisions",
|
|
9771
|
+
"evidence",
|
|
9772
|
+
"requirements",
|
|
9773
|
+
"deliverables",
|
|
9774
|
+
"cases",
|
|
9775
|
+
"gaps",
|
|
9776
|
+
"customer-docs"
|
|
9777
|
+
];
|
|
9778
|
+
function renderEnvYaml(env2) {
|
|
9779
|
+
return [
|
|
9780
|
+
"# \u9879\u76EE\u73AF\u5883\uFF08hcm chiron init \u751F\u6210\uFF0C\u968F\u4ED3\u5E93\u63D0\u4EA4\uFF1B\u4E0D\u653E\u8EAB\u4EFD\u3001\u4E0D\u653E\u51ED\u636E\uFF09",
|
|
9781
|
+
"# \u767B\u5F55\uFF1Ahcm login <endpoint> --code <\u914D\u5BF9\u7801> \u6838\u5BF9\uFF1Ahcm chiron doctor",
|
|
9782
|
+
`endpoint: ${JSON.stringify(env2.endpoint)}`,
|
|
9783
|
+
`frontend: ${JSON.stringify(env2.frontend)}`,
|
|
9784
|
+
`tenant: ${JSON.stringify(env2.tenant)}`,
|
|
9785
|
+
""
|
|
9786
|
+
].join("\n");
|
|
9787
|
+
}
|
|
9788
|
+
function parseEnvYaml(text) {
|
|
9789
|
+
const out = {};
|
|
9790
|
+
for (const [offset, raw] of text.split(/\r?\n/).entries()) {
|
|
9791
|
+
if (!raw.trim() || raw.trimStart().startsWith("#")) continue;
|
|
9792
|
+
const m = raw.match(/^(endpoint|frontend|tenant):\s*(.+)$/);
|
|
9793
|
+
if (!m) throw new Error(`${ENV_FILE} \u7B2C ${offset + 1} \u884C\u4E0D\u662F endpoint / frontend / tenant \u4E4B\u4E00\uFF1A${raw.trim()}`);
|
|
9794
|
+
out[m[1]] = scalar(m[2] ?? "", offset + 1);
|
|
9795
|
+
}
|
|
9796
|
+
for (const key2 of ["endpoint", "frontend", "tenant"]) {
|
|
9797
|
+
if (!out[key2]) throw new Error(`${ENV_FILE} \u7F3A\u5C11 ${key2}`);
|
|
9798
|
+
}
|
|
9799
|
+
return { endpoint: normalizeOrigin(out.endpoint), frontend: normalizeOrigin(out.frontend), tenant: out.tenant };
|
|
9800
|
+
}
|
|
9801
|
+
function scalar(raw, lineNo) {
|
|
9802
|
+
const value = raw.trim();
|
|
9803
|
+
if (value.startsWith('"')) {
|
|
9804
|
+
try {
|
|
9805
|
+
return String(JSON.parse(value));
|
|
9806
|
+
} catch {
|
|
9807
|
+
throw new Error(`${ENV_FILE} \u7B2C ${lineNo} \u884C\u7684\u53CC\u5F15\u53F7\u503C\u975E\u6CD5`);
|
|
9808
|
+
}
|
|
9809
|
+
}
|
|
9810
|
+
if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1);
|
|
9811
|
+
return value.replace(/\s+#.*$/, "").trim();
|
|
9812
|
+
}
|
|
9813
|
+
function normalizeOrigin(url) {
|
|
9814
|
+
return url.trim().replace(/\/+$/, "");
|
|
9815
|
+
}
|
|
9816
|
+
function projectEnvFromConfig(cfg) {
|
|
9817
|
+
const endpoint = normalizeOrigin(cfg.endpoint);
|
|
9818
|
+
return {
|
|
9819
|
+
endpoint,
|
|
9820
|
+
// 冗余一份 frontend:前后端地址不一致的部署里,页面验收要开的是它。
|
|
9821
|
+
frontend: normalizeOrigin(cfg.frontend ?? endpoint),
|
|
9822
|
+
tenant: cfg.tenantId ?? "1"
|
|
9823
|
+
};
|
|
9824
|
+
}
|
|
9825
|
+
async function findEnvByEndpoint(endpoint) {
|
|
9826
|
+
const wanted = normalizeOrigin(endpoint);
|
|
9827
|
+
for (const name of await listEnvs3().catch(() => [])) {
|
|
9828
|
+
const config2 = await loadEnv10(name).catch(() => null);
|
|
9829
|
+
if (config2 && normalizeOrigin(config2.endpoint) === wanted) return { name, config: config2 };
|
|
9830
|
+
}
|
|
9831
|
+
return null;
|
|
9832
|
+
}
|
|
9833
|
+
function renderChironAgentInstructions() {
|
|
9834
|
+
return [
|
|
9835
|
+
AGENT_BEGIN,
|
|
9836
|
+
"# HCM \u987E\u95EE\u9879\u76EE\u8FB9\u754C",
|
|
9837
|
+
"",
|
|
9838
|
+
"- \u53EA\u4F7F\u7528\u672C\u9879\u76EE `hcm-skills/` \u91CC\u7684\u777F\u620E\u6280\u80FD\u4E0E\u5DF2\u53D1\u5E03\u7684 `hcm` CLI\uFF1B\u4E0D\u8BFB\u53D6\u4EA7\u54C1\u6E90\u7801\uFF0C\u4E0D\u76F4\u8FDE\u6570\u636E\u5E93\uFF0C\u4E0D\u7528 `curl` \u7ED5\u8FC7 CLI\u3002",
|
|
9839
|
+
"- \u9879\u76EE\u5BF9\u7740\u7684\u73AF\u5883\u5728 `env.yaml`\uFF08endpoint / frontend / tenant\uFF09\uFF0C\u8EAB\u4EFD\u5728\u672C\u673A `hcm login`\u3002\u6BCF\u6B21\u5F00\u5DE5\u5148\u8DD1 `hcm chiron doctor`\uFF1B\u73AF\u5883\u4E8B\u5B9E\u5FC5\u987B\u73B0\u67E5\uFF0C\u4E0D\u51ED\u8BB0\u5FC6\u586B\u5199\u3002",
|
|
9840
|
+
"- \u5199\u64CD\u4F5C\u5FC5\u987B\u4F9D\u6B21\u7ECF\u8FC7 `hcm delivery assess`\u3001`prepare`\u3001`execute`\uFF1B\u5199\u6388\u6743\u53EA\u8BA4\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728**\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66**\u91CC\u7684\u660E\u786E\u6279\u51C6\uFF0C\u5BA2\u6237\u53E3\u5934\u8981\u6C42\u6216\u7FA4\u6D88\u606F\u4E0D\u662F\u6267\u884C\u6388\u6743\u3002",
|
|
9841
|
+
"- \u5199\u524D\u5FC5\u987B\u8BF4\u660E\u5BF9\u8C61\u3001\u8303\u56F4\u3001\u5F71\u54CD\u4E0E\u56DE\u9000\u5E76\u53D6\u5F97\u672C\u6B21\u660E\u786E\u786E\u8BA4\u3002\u975E\u4EA4\u4E92\u8FD0\u884C\u62FF\u4E0D\u5230\u786E\u8BA4\u65F6\uFF0C\u6700\u591A\u505A\u5230 `prepare`\uFF0C\u7ED3\u8BBA\u5FC5\u987B\u4E3A `BLOCKED` \u5E76\u9644\u8BA1\u5212\uFF1B\u4E0D\u5F97\u81EA\u884C `delivery mode --set controlled` \u6216 `execute`\u3002",
|
|
9842
|
+
"- \u76EE\u5F55\u7EA6\u5B9A\uFF1A`requirements/` \u5BA2\u6237\u9700\u6C42 \xB7 `deliverables/` \u4EA4\u4ED8\u7269 \xB7 `evidence/` \u622A\u56FE\u4E0E\u6536\u636E \xB7 `cases/` \u6C89\u6DC0\u7684\u6848\u4F8B \xB7 `gaps/` \u4EA7\u54C1\u505A\u4E0D\u5230\u7684\u53F0\u8D26 \xB7 `decisions/` \u51B3\u7B56 \xB7 `customer-docs/` \u5BA2\u6237\u8D44\u6599 \xB7 `work/` \u53D8\u66F4\u4E0E\u56DE\u6EDA\u8BF4\u660E\u3002",
|
|
9843
|
+
"- \u649E\u5230\u4EA7\u54C1\u505A\u4E0D\u5230\uFF1A\u5148\u5199 `gaps/` \u53F0\u8D26\u5E76\u7B54\u6E05\u4E09\u95EE\uFF08\u8981\u4EC0\u4E48 / \u8BD5\u8FC7\u4EC0\u4E48 / \u66FF\u4EE3\u6CD5\uFF09\uFF0C\u7ECF\u987E\u95EE\u786E\u8BA4\u540E\u7528\u6848\u4F8B\u5E93 MCP \u7684 `gaps_submit` \u63D0\u4EA4\uFF0C\u62A5\u544A\u5199 `BLOCKED \xB7 \u5DF2\u63D0 #N \xB7 \u66FF\u4EE3\u6CD5`\u3002",
|
|
9844
|
+
"- \u9875\u9762\u9A8C\u6536\u7EDF\u4E00\u7528 `./page-acceptance.sh`\uFF1A\u663E\u5F0F\u4F20\u73AF\u5883\u3001\u8EAB\u4EFD\u3001\u7AD9\u5185\u8DEF\u5F84\u3001\u671F\u671B\u6587\u672C\u4E0E `evidence/` \u4E0B\u7684 PNG \u8DEF\u5F84\uFF1B\u4E0D\u80FD\u53EA\u4EE5\u201C\u751F\u6210\u4E86\u622A\u56FE\u201D\u5224\u901A\u8FC7\u3002",
|
|
9845
|
+
"- \u4EFB\u4F55\u51ED\u636E\u3001\u914D\u5BF9\u7801\u3001\u4EE4\u724C\u3001\u5BA2\u6237\u5BC6\u7801\u90FD\u4E0D\u5F97\u5199\u5165\u4ED3\u5E93\u3001\u547D\u4EE4\u53C2\u6570\u6216\u4EA4\u4ED8\u6587\u6863\u3002",
|
|
9846
|
+
AGENT_END,
|
|
9847
|
+
""
|
|
9848
|
+
].join("\n");
|
|
9849
|
+
}
|
|
9850
|
+
function mergeChironAgentInstructions(existing) {
|
|
9851
|
+
return upsertBlock(existing, AGENT_BEGIN, AGENT_END, renderChironAgentInstructions().trimEnd());
|
|
9852
|
+
}
|
|
9853
|
+
function caseLibraryDir() {
|
|
9854
|
+
return path9.join(hcmConfigDir(), CASES_MCP_NAME);
|
|
9855
|
+
}
|
|
9856
|
+
function codexConfigFile() {
|
|
9857
|
+
return path9.join(process.env.HOME ?? os4.homedir(), ".codex", "config.toml");
|
|
9858
|
+
}
|
|
9859
|
+
function renderCodexMcpSection(repo, envName, binPath = process.env.PATH ?? "") {
|
|
9860
|
+
const server = path9.join(repo, "mcp", "server.mjs");
|
|
9861
|
+
const env2 = [
|
|
9862
|
+
`CASES_REPO = ${JSON.stringify(repo)}`,
|
|
9863
|
+
`HCM_ENV = ${JSON.stringify(envName)}`,
|
|
9864
|
+
...binPath ? [`PATH = ${JSON.stringify(binPath)}`] : []
|
|
9865
|
+
].join(", ");
|
|
9866
|
+
return [
|
|
9867
|
+
`[mcp_servers.${CASES_MCP_NAME}]`,
|
|
9868
|
+
'command = "node"',
|
|
9869
|
+
`args = [${JSON.stringify(server)}]`,
|
|
9870
|
+
`env = { ${env2} }`,
|
|
9871
|
+
""
|
|
9872
|
+
].join("\n");
|
|
9873
|
+
}
|
|
9874
|
+
function mergeCodexMcpConfig(existing, section) {
|
|
9875
|
+
const lines = existing.split(/\r?\n/);
|
|
9876
|
+
const isOurs = (line) => new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}(\\.|\\])`).test(line.trim());
|
|
9877
|
+
const isHeader = (line) => /^\s*\[/.test(line);
|
|
9878
|
+
let start = -1;
|
|
9879
|
+
let end = -1;
|
|
9880
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9881
|
+
const line = lines[i] ?? "";
|
|
9882
|
+
if (start < 0 && isOurs(line)) {
|
|
9883
|
+
start = i;
|
|
9884
|
+
continue;
|
|
9885
|
+
}
|
|
9886
|
+
if (start >= 0 && isHeader(line) && !isOurs(line)) {
|
|
9887
|
+
end = i;
|
|
9888
|
+
break;
|
|
9889
|
+
}
|
|
9890
|
+
}
|
|
9891
|
+
const block = section.trimEnd();
|
|
9892
|
+
if (start < 0) {
|
|
9893
|
+
const prefix = existing.trimEnd();
|
|
9894
|
+
return `${prefix}${prefix ? "\n\n" : ""}${block}
|
|
9895
|
+
`;
|
|
9896
|
+
}
|
|
9897
|
+
const tail = lines.slice(end < 0 ? lines.length : end);
|
|
9898
|
+
const head = lines.slice(0, start);
|
|
9899
|
+
return `${[...head, block, "", ...tail].join("\n").replace(/\n{3,}/g, "\n\n").trimEnd()}
|
|
9900
|
+
`;
|
|
9901
|
+
}
|
|
9902
|
+
function codexConfigHasCases(text) {
|
|
9903
|
+
return new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}\\]`, "m").test(text);
|
|
9904
|
+
}
|
|
9905
|
+
var defaultCaseLibraryDeps = {
|
|
9906
|
+
git: (args, cwd) => {
|
|
9907
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf8", timeout: 12e4, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
9908
|
+
return { status: r.status, stderr: r.stderr ?? "", error: r.error };
|
|
9909
|
+
},
|
|
9910
|
+
npmInstall: (cwd) => {
|
|
9911
|
+
const r = spawnSync("npm", ["install", "--omit=dev", "--no-audit", "--no-fund", "--loglevel=error"], {
|
|
9912
|
+
cwd,
|
|
9913
|
+
encoding: "utf8",
|
|
9914
|
+
timeout: 3e5
|
|
9915
|
+
});
|
|
9916
|
+
return { status: r.status, stderr: r.stderr ?? "", error: r.error };
|
|
9917
|
+
}
|
|
9918
|
+
};
|
|
9919
|
+
async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths = {}) {
|
|
9920
|
+
const repo = paths.repo ?? caseLibraryDir();
|
|
9921
|
+
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
9922
|
+
const status = { ok: false, repo, step: "present", serverInstalled: false, codexWired: false };
|
|
9923
|
+
const hasGit = await exists2(path9.join(repo, ".git"));
|
|
9924
|
+
if (hasGit) {
|
|
9925
|
+
const pull = deps.git(["pull", "--ff-only", "--quiet"], repo);
|
|
9926
|
+
status.step = pull.status === 0 ? "updated" : "present";
|
|
9927
|
+
if (pull.status !== 0) status.reason = `\u66F4\u65B0\u5931\u8D25\uFF0C\u6CBF\u7528\u672C\u5730\u7248\u672C\uFF1A${firstLine(pull.stderr, pull.error)}`;
|
|
9928
|
+
} else {
|
|
9929
|
+
await fs9.mkdir(path9.dirname(repo), { recursive: true });
|
|
9930
|
+
const clone = deps.git(["clone", "--depth", "1", "--quiet", CASES_REPO_URL, repo]);
|
|
9931
|
+
if (clone.status !== 0) {
|
|
9932
|
+
status.step = "clone-failed";
|
|
9933
|
+
status.reason = `clone \u5931\u8D25\uFF08\u591A\u534A\u662F\u6CA1\u6709 ${CASES_REPO_URL.replace(/\.git$/, "")} \u7684\u6743\u9650\uFF0C\u6216\u672C\u673A git \u672A\u767B\u5F55 cnb\uFF09\uFF1A${firstLine(clone.stderr, clone.error)}`;
|
|
9934
|
+
return status;
|
|
9935
|
+
}
|
|
9936
|
+
status.step = "cloned";
|
|
9937
|
+
}
|
|
9938
|
+
const mcpDir = path9.join(repo, "mcp");
|
|
9939
|
+
if (!await exists2(path9.join(mcpDir, "server.mjs"))) {
|
|
9940
|
+
status.step = "install-failed";
|
|
9941
|
+
status.reason = `\u6848\u4F8B\u5E93\u91CC\u6CA1\u6709 mcp/server.mjs\uFF1A${mcpDir}`;
|
|
9942
|
+
return status;
|
|
9943
|
+
}
|
|
9944
|
+
if (!await exists2(path9.join(mcpDir, "node_modules", "@modelcontextprotocol"))) {
|
|
9945
|
+
const install = deps.npmInstall(mcpDir);
|
|
9946
|
+
if (install.status !== 0) {
|
|
9947
|
+
status.step = "install-failed";
|
|
9948
|
+
status.reason = `npm install \u5931\u8D25\uFF1A${firstLine(install.stderr, install.error)}`;
|
|
9949
|
+
return status;
|
|
9950
|
+
}
|
|
9951
|
+
}
|
|
9952
|
+
status.serverInstalled = true;
|
|
9953
|
+
await fs9.mkdir(path9.dirname(codexConfig), { recursive: true });
|
|
9954
|
+
const existing = await fs9.readFile(codexConfig, "utf8").catch(() => "");
|
|
9955
|
+
const next = mergeCodexMcpConfig(existing, renderCodexMcpSection(repo, envName));
|
|
9956
|
+
if (next !== existing) await fs9.writeFile(codexConfig, next, "utf8");
|
|
9957
|
+
status.codexWired = true;
|
|
9958
|
+
status.ok = true;
|
|
9959
|
+
return status;
|
|
9960
|
+
}
|
|
9961
|
+
async function inspectCaseLibrary(paths = {}) {
|
|
9962
|
+
const repo = paths.repo ?? caseLibraryDir();
|
|
9963
|
+
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
9964
|
+
const cloned = await exists2(path9.join(repo, ".git"));
|
|
9965
|
+
const serverInstalled = cloned && await exists2(path9.join(repo, "mcp", "server.mjs")) && await exists2(path9.join(repo, "mcp", "node_modules", "@modelcontextprotocol"));
|
|
9966
|
+
const codexWired = codexConfigHasCases(await fs9.readFile(codexConfig, "utf8").catch(() => ""));
|
|
9967
|
+
return { repo, cloned, serverInstalled, codexWired };
|
|
9968
|
+
}
|
|
9969
|
+
function firstLine(stderr, error) {
|
|
9970
|
+
if (error) return error.message;
|
|
9971
|
+
const line = stderr.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
|
|
9972
|
+
return line ?? "\uFF08\u65E0\u8F93\u51FA\uFF09";
|
|
9973
|
+
}
|
|
9974
|
+
async function exists2(file) {
|
|
9975
|
+
try {
|
|
9976
|
+
await fs9.access(file);
|
|
9977
|
+
return true;
|
|
9978
|
+
} catch {
|
|
9979
|
+
return false;
|
|
9980
|
+
}
|
|
9981
|
+
}
|
|
9982
|
+
|
|
9983
|
+
// src/commands/chiron-init.ts
|
|
9984
|
+
async function probeTokenTenant(envName, requested) {
|
|
9985
|
+
const ctx = await getActiveAuthContextFromCli({ env: envName });
|
|
9986
|
+
const client3 = HcmClient22.fromAuthContext(ctx);
|
|
9987
|
+
const identity2 = await fetchReconIdentity2(httpProbe2(client3.raw(), "default"), requested);
|
|
9988
|
+
return identity2?.tenantId ? String(identity2.tenantId) : void 0;
|
|
9989
|
+
}
|
|
9990
|
+
var defaultChironInitDeps = {
|
|
9991
|
+
tokenTenant: probeTokenTenant,
|
|
9992
|
+
installSkills: async (root, envName) => {
|
|
9993
|
+
const previous = process.cwd();
|
|
9994
|
+
process.chdir(root);
|
|
9995
|
+
try {
|
|
9996
|
+
await skillsInstallCommand(void 0, {
|
|
9997
|
+
all: true,
|
|
9998
|
+
target: "codex",
|
|
9999
|
+
env: envName,
|
|
10000
|
+
dir: path10.join(root, SKILLS_DIR),
|
|
10001
|
+
output: "table"
|
|
10002
|
+
});
|
|
10003
|
+
} finally {
|
|
10004
|
+
process.chdir(previous);
|
|
10005
|
+
}
|
|
10006
|
+
if (process.exitCode && process.exitCode !== 0) {
|
|
10007
|
+
throw new Error("\u6280\u80FD\u6CA1\u88C5\u4E0A\uFF08\u4E0A\u9762\u662F skills install \u7684\u8F93\u51FA\uFF09\uFF1B\u4FEE\u597D\u540E\u91CD\u8DD1 hcm chiron init");
|
|
10008
|
+
}
|
|
10009
|
+
},
|
|
10010
|
+
caseLibrary: (envName) => ensureCaseLibrary(envName)
|
|
10011
|
+
};
|
|
10012
|
+
async function resolveLoggedInEnv() {
|
|
10013
|
+
const g = await loadGlobalConfig10();
|
|
10014
|
+
const name = g.activeEnv;
|
|
10015
|
+
const loginHint = "hcm login https://<\u4F60\u7684 HCM \u5730\u5740> --code <\u914D\u5BF9\u7801>";
|
|
10016
|
+
if (!name) {
|
|
10017
|
+
throw new CliError21({
|
|
10018
|
+
code: CliErrorCode20.ENV_NOT_FOUND,
|
|
10019
|
+
message: `\u8FD8\u6CA1\u767B\u5F55\u4EFB\u4F55\u73AF\u5883\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10020
|
+
});
|
|
10021
|
+
}
|
|
10022
|
+
const config2 = await loadEnv11(name).catch(() => null);
|
|
10023
|
+
if (!config2?.endpoint) {
|
|
10024
|
+
throw new CliError21({
|
|
10025
|
+
code: CliErrorCode20.ENV_NOT_FOUND,
|
|
10026
|
+
message: `\u5F53\u524D\u73AF\u5883 '${name}' \u6CA1\u6709 endpoint\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10027
|
+
});
|
|
10028
|
+
}
|
|
10029
|
+
const identities = await listIdentities3(name).catch(() => []);
|
|
10030
|
+
if (identities.length === 0) {
|
|
10031
|
+
throw new CliError21({
|
|
10032
|
+
code: CliErrorCode20.IDENTITY_NOT_FOUND,
|
|
10033
|
+
message: `\u73AF\u5883 '${name}'\uFF08${config2.endpoint}\uFF09\u8FD8\u6CA1\u6709\u767B\u5F55\u8EAB\u4EFD\u3002\u5148\u6267\u884C\uFF1Ahcm login ${config2.endpoint} --code <\u914D\u5BF9\u7801>`
|
|
10034
|
+
});
|
|
10035
|
+
}
|
|
10036
|
+
const identity2 = config2.defaultIdentity && identities.includes(config2.defaultIdentity) ? config2.defaultIdentity : identities[0];
|
|
10037
|
+
return { name, env: projectEnvFromConfig(config2), identity: identity2 };
|
|
10038
|
+
}
|
|
10039
|
+
async function scaffoldChironProject(root, env2, envName) {
|
|
10040
|
+
const result = { created: [], updated: [], preserved: [] };
|
|
10041
|
+
const envFile = path10.join(root, ENV_FILE);
|
|
10042
|
+
const existing = await fs10.readFile(envFile, "utf8").catch(() => null);
|
|
10043
|
+
if (existing !== null) {
|
|
10044
|
+
const recorded = parseEnvYaml(existing);
|
|
10045
|
+
if (recorded.endpoint !== env2.endpoint) {
|
|
10046
|
+
throw new CliError21({
|
|
10047
|
+
code: CliErrorCode20.INVALID_ARGUMENT,
|
|
10048
|
+
message: `${ENV_FILE} \u6307\u5411 ${recorded.endpoint}\uFF0C\u800C\u4F60\u5F53\u524D\u767B\u5F55\u7684\u662F ${env2.endpoint}\uFF08env '${envName}'\uFF09\u3002
|
|
10049
|
+
\u8981\u7528\u8FD9\u4E2A\u9879\u76EE\u7684\u73AF\u5883\uFF1Ahcm login ${recorded.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init
|
|
10050
|
+
\u8981\u628A\u9879\u76EE\u6539\u5230\u4F60\u767B\u5F55\u7684\u73AF\u5883\uFF1A\u5220\u6389 ${ENV_FILE} \u540E\u91CD\u8DD1\uFF08\u8FD9\u4F1A\u5F71\u54CD\u6240\u6709\u534F\u4F5C\u8005\uFF0C\u5148\u8DDF\u8D1F\u8D23\u4EBA\u786E\u8BA4\uFF09`
|
|
10051
|
+
});
|
|
10052
|
+
}
|
|
10053
|
+
if (recorded.tenant !== env2.tenant) {
|
|
10054
|
+
throw new CliError21({
|
|
10055
|
+
code: CliErrorCode20.INVALID_ARGUMENT,
|
|
10056
|
+
message: `${ENV_FILE} \u662F\u79DF\u6237 ${recorded.tenant}\uFF0C\u800C\u4F60\u767B\u5F55\u7684\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${env2.tenant}\u3002
|
|
10057
|
+
\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\u91CD\u65B0\u767B\u5F55\uFF1Ahcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init`
|
|
10058
|
+
});
|
|
10059
|
+
}
|
|
10060
|
+
result.preserved.push(ENV_FILE);
|
|
10061
|
+
} else {
|
|
10062
|
+
await fs10.writeFile(envFile, renderEnvYaml(env2), { encoding: "utf8", mode: 420, flag: "wx" });
|
|
10063
|
+
result.created.push(ENV_FILE);
|
|
10064
|
+
}
|
|
10065
|
+
for (const directory of CHIRON_PROJECT_DIRECTORIES) {
|
|
10066
|
+
const absolute = path10.join(root, directory);
|
|
10067
|
+
await ensureDirectory(absolute);
|
|
10068
|
+
await writeIfAbsent(path10.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
|
|
10069
|
+
}
|
|
10070
|
+
const deliveryDir = path10.join(root, ".hcm-delivery");
|
|
10071
|
+
await ensureDirectory(deliveryDir);
|
|
10072
|
+
await writeIfAbsent(
|
|
10073
|
+
path10.join(deliveryDir, "project.yml"),
|
|
10074
|
+
renderProjectYml(envName, "plan-only"),
|
|
10075
|
+
result,
|
|
10076
|
+
".hcm-delivery/project.yml"
|
|
10077
|
+
);
|
|
10078
|
+
const pageAcceptanceFile = path10.join(root, "page-acceptance.sh");
|
|
10079
|
+
const created = await writeIfAbsent(pageAcceptanceFile, renderPageAcceptanceSh("evidence"), result, "page-acceptance.sh", 493);
|
|
10080
|
+
if (created) await fs10.chmod(pageAcceptanceFile, 493);
|
|
10081
|
+
await mergeManagedFile(path10.join(root, "AGENTS.md"), mergeChironAgentInstructions, result, "AGENTS.md");
|
|
10082
|
+
await mergeManagedFile(path10.join(root, "CLAUDE.md"), mergeChironAgentInstructions, result, "CLAUDE.md");
|
|
10083
|
+
await mergeManagedFile(path10.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
|
|
10084
|
+
return result;
|
|
10085
|
+
}
|
|
10086
|
+
async function runChironInit(args, deps = defaultChironInitDeps) {
|
|
10087
|
+
const root = path10.resolve(args.project ?? ".");
|
|
10088
|
+
const { name, env: env2, identity: identity2 } = await resolveLoggedInEnv();
|
|
10089
|
+
const say = (line) => process.stderr.write(`[chiron init] ${line}
|
|
10090
|
+
`);
|
|
10091
|
+
const actual = await deps.tokenTenant(name, env2.tenant);
|
|
10092
|
+
if (actual && actual !== env2.tenant) {
|
|
10093
|
+
say(`env ${name} \u8BB0\u7684\u79DF\u6237\u662F ${env2.tenant}\uFF0C\u4F46\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${actual}\uFF0C\u6309 ${actual} \u5199 ${ENV_FILE}`);
|
|
10094
|
+
env2.tenant = actual;
|
|
10095
|
+
}
|
|
10096
|
+
say(`\u73AF\u5883 ${name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant} \xB7 \u8EAB\u4EFD ${identity2}`);
|
|
10097
|
+
const scaffold = await scaffoldChironProject(root, env2, name);
|
|
10098
|
+
say(`\u9AA8\u67B6\uFF1A\u65B0\u5EFA ${scaffold.created.length} \xB7 \u66F4\u65B0 ${scaffold.updated.length} \xB7 \u4FDD\u7559 ${scaffold.preserved.length}`);
|
|
10099
|
+
let skills2 = "skipped";
|
|
10100
|
+
if (!args.skipSkills) {
|
|
10101
|
+
say("\u88C5\u777F\u620E\u6280\u80FD\uFF08\u5168\u90E8\uFF0CCodex \u5E03\u5C40\uFF09\u2026");
|
|
10102
|
+
await deps.installSkills(root, name);
|
|
10103
|
+
skills2 = "installed";
|
|
10104
|
+
}
|
|
10105
|
+
let cases = { ok: false, step: "skipped" };
|
|
10106
|
+
if (!args.skipCases) {
|
|
10107
|
+
say("\u63A5\u6848\u4F8B\u5E93\uFF08chiron-cases MCP\uFF09\u2026");
|
|
10108
|
+
cases = await deps.caseLibrary(name);
|
|
10109
|
+
if (cases.ok) say(`\u6848\u4F8B\u5E93\u5DF2\u63A5\u5165 Codex\uFF1A${cases.repo}`);
|
|
10110
|
+
else say(`\u6848\u4F8B\u5E93\u672A\u63A5\u5165\uFF08\u4E0D\u5F71\u54CD\u5F00\u5DE5\uFF0C\u7528\u5230\u65F6\u4F1A\u63D0\u793A\u6743\u9650\u4E0D\u8DB3\uFF09\uFF1A${cases.reason ?? cases.step}`);
|
|
10111
|
+
}
|
|
10112
|
+
return {
|
|
10113
|
+
project: root,
|
|
10114
|
+
env: name,
|
|
10115
|
+
endpoint: env2.endpoint,
|
|
10116
|
+
frontend: env2.frontend,
|
|
10117
|
+
tenant: env2.tenant,
|
|
10118
|
+
identity: identity2,
|
|
10119
|
+
scaffold,
|
|
10120
|
+
skills: skills2,
|
|
10121
|
+
cases,
|
|
10122
|
+
nextStep: "hcm chiron doctor \u6838\u5BF9\u4E00\u904D\uFF0C\u7136\u540E\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u542F\u52A8 codex"
|
|
10123
|
+
};
|
|
10124
|
+
}
|
|
10125
|
+
async function chironInitCommand(args, deps) {
|
|
10126
|
+
try {
|
|
10127
|
+
const result = await runChironInit(args, deps);
|
|
10128
|
+
const fmt = args.output ?? "table";
|
|
10129
|
+
if (fmt === "json" || fmt === "yaml") {
|
|
10130
|
+
process.stdout.write(formatObject24(result, { format: fmt }) + "\n");
|
|
10131
|
+
} else {
|
|
10132
|
+
process.stdout.write(
|
|
10133
|
+
[
|
|
10134
|
+
`\u2705 \u9879\u76EE\u5DF2\u521D\u59CB\u5316\uFF1A${result.project}`,
|
|
10135
|
+
` \u73AF\u5883 ${result.env} \xB7 ${result.endpoint} \xB7 \u79DF\u6237 ${result.tenant} \xB7 \u8EAB\u4EFD ${result.identity}`,
|
|
10136
|
+
` \u6280\u80FD ${result.skills === "installed" ? `\u5DF2\u88C5\u5230 ${SKILLS_DIR}/` : "\u672A\u88C5\uFF08--skip-skills\uFF09"}`,
|
|
10137
|
+
` \u6848\u4F8B\u5E93 ${result.cases.ok ? "\u5DF2\u63A5\u5165 Codex" : `\u672A\u63A5\u5165\uFF1A${"reason" in result.cases && result.cases.reason ? result.cases.reason : result.cases.step}`}`,
|
|
10138
|
+
` \u4E0B\u4E00\u6B65\uFF1A${result.nextStep}`
|
|
10139
|
+
].join("\n") + "\n"
|
|
10140
|
+
);
|
|
10141
|
+
}
|
|
10142
|
+
process.exitCode = 0;
|
|
10143
|
+
} catch (e) {
|
|
10144
|
+
exitWithError(e);
|
|
10145
|
+
}
|
|
10146
|
+
}
|
|
10147
|
+
|
|
10148
|
+
// src/commands/chiron-doctor.ts
|
|
10149
|
+
init_auth_guard();
|
|
10150
|
+
init_exit();
|
|
10151
|
+
import { promises as fs11 } from "fs";
|
|
10152
|
+
import path11 from "path";
|
|
10153
|
+
import {
|
|
10154
|
+
HcmClient as HcmClient23,
|
|
10155
|
+
CliError as CliError22,
|
|
10156
|
+
fetchReconIdentity as fetchReconIdentity3,
|
|
10157
|
+
formatObject as formatObject25,
|
|
10158
|
+
httpProbe as httpProbe3,
|
|
10159
|
+
runDoctor as runDoctor2
|
|
10160
|
+
} from "@hcmai/sdk";
|
|
10161
|
+
var defaultDeps = {
|
|
10162
|
+
anchors: async (envName, tenant2) => {
|
|
10163
|
+
const ctx = await getActiveAuthContextFromCli({ env: envName });
|
|
10164
|
+
const client3 = HcmClient23.fromAuthContext(ctx);
|
|
10165
|
+
const probe = httpProbe3(client3.raw(), "default");
|
|
10166
|
+
const identity2 = await fetchReconIdentity3(probe, tenant2);
|
|
10167
|
+
return { report: await runDoctor2(probe, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
|
|
10168
|
+
},
|
|
10169
|
+
fixSkills: (root, envName) => defaultChironInitDeps.installSkills(root, envName),
|
|
10170
|
+
fixCases: async (envName) => {
|
|
10171
|
+
await ensureCaseLibrary(envName);
|
|
10172
|
+
},
|
|
10173
|
+
inspectCases: () => inspectCaseLibrary()
|
|
10174
|
+
};
|
|
10175
|
+
async function runChironDoctor(args, deps = defaultDeps) {
|
|
10176
|
+
const root = path11.resolve(args.project ?? ".");
|
|
10177
|
+
const report = { ok: false, project: root, env: null, envName: null, lines: [] };
|
|
10178
|
+
const envText = await fs11.readFile(path11.join(root, ENV_FILE), "utf8").catch(() => null);
|
|
10179
|
+
if (envText === null) {
|
|
10180
|
+
report.lines.push({
|
|
10181
|
+
item: "\u767B\u5F55",
|
|
10182
|
+
verdict: "fail",
|
|
10183
|
+
detail: `\u8FD9\u4E2A\u76EE\u5F55\u91CC\u6CA1\u6709 ${ENV_FILE}\uFF0C\u4E0D\u662F\u777F\u620E\u9879\u76EE\u4ED3\uFF08\u6216\u8FD8\u6CA1\u521D\u59CB\u5316\uFF09`,
|
|
10184
|
+
nextStep: "\u65B0\u4ED3\uFF1Ahcm login <\u5730\u5740> --code <\u914D\u5BF9\u7801> \u540E hcm chiron init\uFF1B\u5DF2\u6709\u4ED3\uFF1A\u786E\u8BA4 clone \u7684\u662F\u5BF9\u7684\u4ED3\u3001\u7AD9\u5728\u4ED3\u6839\u76EE\u5F55"
|
|
10185
|
+
});
|
|
10186
|
+
return finish(report);
|
|
10187
|
+
}
|
|
10188
|
+
let env2;
|
|
10189
|
+
try {
|
|
10190
|
+
env2 = parseEnvYaml(envText);
|
|
10191
|
+
} catch (e) {
|
|
10192
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: e.message, nextStep: `\u6309 hcm chiron init \u751F\u6210\u7684\u4E09\u884C\u5F62\u6001\u4FEE ${ENV_FILE}` });
|
|
10193
|
+
return finish(report);
|
|
10194
|
+
}
|
|
10195
|
+
report.env = env2;
|
|
10196
|
+
const found = await findEnvByEndpoint(env2.endpoint);
|
|
10197
|
+
const loginCmd = `hcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>`;
|
|
10198
|
+
if (!found) {
|
|
10199
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env2.endpoint}`, nextStep: loginCmd });
|
|
10200
|
+
} else {
|
|
10201
|
+
report.envName = found.name;
|
|
10202
|
+
try {
|
|
10203
|
+
const { report: anchors, tokenTenant } = await deps.anchors(found.name, env2.tenant);
|
|
10204
|
+
report.anchors = anchors;
|
|
10205
|
+
const tenantMismatch = tokenTenant && tokenTenant !== env2.tenant;
|
|
10206
|
+
const bad = anchors.checks.filter((c) => !c.ok && !(tenantMismatch && c.anchor === "identity"));
|
|
10207
|
+
if (bad.length === 0 && !tenantMismatch) {
|
|
10208
|
+
const who = found.config.defaultIdentity ? ` \xB7 ${found.config.defaultIdentity}` : "";
|
|
10209
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "ok", detail: `${found.name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant}${who}` });
|
|
10210
|
+
} else {
|
|
10211
|
+
const parts = [`${found.name} \xB7 ${env2.endpoint}`];
|
|
10212
|
+
if (tenantMismatch) parts.push(`\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${tokenTenant}\uFF0C\u9879\u76EE\u662F\u79DF\u6237 ${env2.tenant}`);
|
|
10213
|
+
if (bad.length) parts.push(`\u951A\u70B9\u672A\u8FC7\uFF1A${bad.map((c) => `${c.anchor}\uFF08${c.detail}\uFF09`).join("\u3001")}`);
|
|
10214
|
+
report.lines.push({
|
|
10215
|
+
item: "\u767B\u5F55",
|
|
10216
|
+
verdict: "fail",
|
|
10217
|
+
detail: parts.join("\uFF1B"),
|
|
10218
|
+
nextStep: tenantMismatch ? `${loginCmd}\uFF08\u7528\u9879\u76EE\u79DF\u6237\u7684\u914D\u5BF9\u7801\uFF09` : "\u6309\u4E0A\u9762\u951A\u70B9\u7684\u63D0\u793A\u5904\u7406\uFF1B\u8EAB\u4EFD\u8FC7\u671F\u5C31\u91CD\u65B0 " + loginCmd
|
|
10219
|
+
});
|
|
10220
|
+
}
|
|
10221
|
+
} catch (e) {
|
|
10222
|
+
const msg = e instanceof CliError22 ? e.message : e.message;
|
|
10223
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env2.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
|
|
10224
|
+
}
|
|
10225
|
+
}
|
|
10226
|
+
const skillsLine = async () => {
|
|
10227
|
+
const state = await readSkillsState(path11.join(root, SKILLS_DIR));
|
|
10228
|
+
if (!state) return { item: "\u6280\u80FD", verdict: "fail", detail: `${SKILLS_DIR}/ \u91CC\u6CA1\u6709\u5B89\u88C5\u6E05\u5355`, nextStep: "hcm chiron doctor --fix\uFF08\u6216 hcm chiron init\uFF09" };
|
|
10229
|
+
const count = Object.keys(state.skills).length;
|
|
10230
|
+
if (state.endpoint && normalizeOrigin(state.endpoint) !== env2.endpoint) {
|
|
10231
|
+
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 doctor --fix \u91CD\u88C5" };
|
|
10232
|
+
}
|
|
10233
|
+
if (state.target !== "codex") {
|
|
10234
|
+
return { item: "\u6280\u80FD", verdict: "warn", detail: `${count} \u4E2A\uFF0C\u5E03\u5C40\u662F ${state.target}\uFF08Codex \u8981\u8BFB AGENTS.md \u7D22\u5F15\uFF09`, nextStep: "hcm skills install --all --target codex" };
|
|
10235
|
+
}
|
|
10236
|
+
return { item: "\u6280\u80FD", verdict: "ok", detail: `${count} \u4E2A\uFF0C\u6765\u81EA ${state.endpoint ?? "\u672C\u5730"}${state.all ? "\uFF0C\u8DDF\u968F\u5168\u96C6" : ""}` };
|
|
10237
|
+
};
|
|
10238
|
+
let skills2 = await skillsLine();
|
|
10239
|
+
if (skills2.verdict === "fail" && args.fix && report.envName) {
|
|
10240
|
+
await deps.fixSkills(root, report.envName);
|
|
10241
|
+
skills2 = await skillsLine();
|
|
10242
|
+
}
|
|
10243
|
+
report.lines.push(skills2);
|
|
10244
|
+
const casesLine = async () => {
|
|
10245
|
+
const c = await deps.inspectCases();
|
|
10246
|
+
if (!c.cloned) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: `\u672A clone\uFF08${c.repo}\uFF09`, nextStep: "hcm chiron doctor --fix\uFF1B\u6CA1\u6709 cnb \u6743\u9650\u5C31\u5148\u8DF3\u8FC7\uFF0C\u63D0\u4EA4\u6848\u4F8B/\u7F3A\u53E3\u65F6\u4F1A\u63D0\u793A" };
|
|
10247
|
+
if (!c.serverInstalled) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: "MCP \u4F9D\u8D56\u6CA1\u88C5", nextStep: "hcm chiron doctor --fix" };
|
|
10248
|
+
if (!c.codexWired) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: "Codex \u6CA1\u63A5\u7EBF\uFF08~/.codex/config.toml \u7F3A [mcp_servers.chiron-cases]\uFF09", nextStep: "hcm chiron doctor --fix" };
|
|
10249
|
+
return { item: "\u6848\u4F8B\u5E93", verdict: "ok", detail: `\u5DF2\u63A5\u5165 Codex\uFF08${c.repo}\uFF09` };
|
|
10250
|
+
};
|
|
10251
|
+
let cases = await casesLine();
|
|
10252
|
+
if (cases.verdict !== "ok" && args.fix && report.envName) {
|
|
10253
|
+
await deps.fixCases(report.envName);
|
|
10254
|
+
cases = await casesLine();
|
|
10255
|
+
}
|
|
10256
|
+
report.lines.push(cases);
|
|
10257
|
+
return finish(report);
|
|
10258
|
+
}
|
|
10259
|
+
function finish(report) {
|
|
10260
|
+
report.ok = report.lines.every((l) => l.verdict !== "fail");
|
|
10261
|
+
return report;
|
|
10262
|
+
}
|
|
10263
|
+
function renderChironDoctor(report) {
|
|
10264
|
+
const mark = { ok: "\u2705", warn: "\u26A0\uFE0F", fail: "\u274C" };
|
|
10265
|
+
const out = [];
|
|
10266
|
+
for (const l of report.lines) {
|
|
10267
|
+
out.push(`${mark[l.verdict]} ${l.item.padEnd(3, "\u3000")} ${l.detail}`);
|
|
10268
|
+
if (l.nextStep && l.verdict !== "ok") out.push(` \u2192 ${l.nextStep}`);
|
|
10269
|
+
}
|
|
10270
|
+
out.push("");
|
|
10271
|
+
out.push(report.ok ? "\u53EF\u4EE5\u5F00\u5DE5\uFF1A\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u542F\u52A8 codex\u3002" : "\u5148\u6309 \u2192 \u5904\u7406\u7EA2\u9879\uFF0C\u518D\u8DD1\u4E00\u6B21 hcm chiron doctor\u3002");
|
|
10272
|
+
return out.join("\n");
|
|
10273
|
+
}
|
|
10274
|
+
async function chironDoctorCommand(args, deps) {
|
|
10275
|
+
try {
|
|
10276
|
+
const report = await runChironDoctor(args, deps);
|
|
10277
|
+
const fmt = args.output ?? "table";
|
|
10278
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject25(report, { format: fmt }) + "\n");
|
|
10279
|
+
else process.stdout.write(renderChironDoctor(report) + "\n");
|
|
10280
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
10281
|
+
} catch (e) {
|
|
10282
|
+
exitWithError(e);
|
|
10283
|
+
}
|
|
10284
|
+
}
|
|
10285
|
+
|
|
10286
|
+
// src/commands/delivery-recon.ts
|
|
10287
|
+
init_auth_guard();
|
|
10288
|
+
init_exit();
|
|
10289
|
+
import {
|
|
10290
|
+
HcmClient as HcmClient24,
|
|
9738
10291
|
ReconLayout,
|
|
9739
10292
|
ROUND_EXIT_CODES,
|
|
9740
10293
|
computeReconSourceKey,
|
|
9741
|
-
formatObject as
|
|
10294
|
+
formatObject as formatObject26,
|
|
9742
10295
|
fromAxiosError as fromAxiosError22,
|
|
9743
|
-
httpProbe as
|
|
10296
|
+
httpProbe as httpProbe4,
|
|
9744
10297
|
inspectRound,
|
|
9745
10298
|
renderRound,
|
|
9746
10299
|
runRecon
|
|
@@ -9749,8 +10302,8 @@ var DEFAULT_CAPABILITIES2 = "default";
|
|
|
9749
10302
|
async function deliveryReconCommand(args) {
|
|
9750
10303
|
try {
|
|
9751
10304
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
9752
|
-
const client3 =
|
|
9753
|
-
const probe =
|
|
10305
|
+
const client3 = HcmClient24.fromAuthContext(ctx);
|
|
10306
|
+
const probe = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES2);
|
|
9754
10307
|
const sourceKey = await computeReconSourceKey(probe);
|
|
9755
10308
|
const layout = new ReconLayout(args.out ?? ".", ctx.tenantId, sourceKey);
|
|
9756
10309
|
const summary = await runRecon(probe, layout, {
|
|
@@ -9758,7 +10311,7 @@ async function deliveryReconCommand(args) {
|
|
|
9758
10311
|
onlyModel: args.model ?? null,
|
|
9759
10312
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
9760
10313
|
});
|
|
9761
|
-
process.stdout.write(
|
|
10314
|
+
process.stdout.write(formatObject26(summary, { format: args.output ?? "json" }) + "\n");
|
|
9762
10315
|
} catch (e) {
|
|
9763
10316
|
const err = e;
|
|
9764
10317
|
if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
|
|
@@ -9772,7 +10325,7 @@ async function deliveryReconRoundCommand(args) {
|
|
|
9772
10325
|
const result = inspectRound(args.dir ?? ".");
|
|
9773
10326
|
const fmt = args.output ?? "json";
|
|
9774
10327
|
if (fmt !== "json") process.stdout.write(renderRound(result));
|
|
9775
|
-
process.stdout.write(
|
|
10328
|
+
process.stdout.write(formatObject26(result, { format: fmt }) + "\n");
|
|
9776
10329
|
code = ROUND_EXIT_CODES[result.state];
|
|
9777
10330
|
} catch (e) {
|
|
9778
10331
|
exitWithError(e);
|
|
@@ -9791,14 +10344,14 @@ import {
|
|
|
9791
10344
|
GAP_REASONS,
|
|
9792
10345
|
deriveAclass,
|
|
9793
10346
|
exitCode as gate0ExitCode,
|
|
9794
|
-
formatObject as
|
|
10347
|
+
formatObject as formatObject27,
|
|
9795
10348
|
inspectRound as inspectRound2,
|
|
9796
10349
|
loadProtocolFacts,
|
|
9797
10350
|
scan
|
|
9798
10351
|
} from "@hcmai/sdk";
|
|
9799
|
-
import * as
|
|
10352
|
+
import * as path12 from "path";
|
|
9800
10353
|
function renderGate0(result, skillRoot) {
|
|
9801
|
-
const where = skillRoot ? `\uFF08${
|
|
10354
|
+
const where = skillRoot ? `\uFF08${path12.resolve(skillRoot)}\uFF09` : "";
|
|
9802
10355
|
const lines = [
|
|
9803
10356
|
`\u626B\u63CF\u9762${where}\uFF1A${result.scanned.length} \u4E2A\u6587\u4EF6\uFF1B\u5224\u7EA2 ${result.red.length} \u6761\uFF1B\u7F3A\u53E3\u653E\u884C ${result.gaps.length} \u6761\u3002`
|
|
9804
10357
|
];
|
|
@@ -9836,7 +10389,7 @@ async function deliveryGate0Command(args) {
|
|
|
9836
10389
|
const merged = { ...result, premise: premise5 };
|
|
9837
10390
|
const fmt = args.output ?? "json";
|
|
9838
10391
|
if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
|
|
9839
|
-
process.stdout.write(`${
|
|
10392
|
+
process.stdout.write(`${formatObject27(merged, { format: fmt })}
|
|
9840
10393
|
`);
|
|
9841
10394
|
for (const problem of premise5) {
|
|
9842
10395
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
|
|
@@ -9861,8 +10414,8 @@ import {
|
|
|
9861
10414
|
DRY_RUN_TAIL,
|
|
9862
10415
|
DriftDetected,
|
|
9863
10416
|
FORCE_STALE_FLAG,
|
|
9864
|
-
HcmClient as
|
|
9865
|
-
fetchReconIdentity as
|
|
10417
|
+
HcmClient as HcmClient25,
|
|
10418
|
+
fetchReconIdentity as fetchReconIdentity4,
|
|
9866
10419
|
INIT_EXIT_CODES,
|
|
9867
10420
|
JOURNAL_STOP_KINDS,
|
|
9868
10421
|
JOURNAL_STOP_UNKNOWN,
|
|
@@ -9911,7 +10464,7 @@ import {
|
|
|
9911
10464
|
writeRisk
|
|
9912
10465
|
} from "@hcmai/sdk";
|
|
9913
10466
|
import { existsSync as existsSync3 } from "fs";
|
|
9914
|
-
import * as
|
|
10467
|
+
import * as path13 from "path";
|
|
9915
10468
|
function premise(message, hint = "") {
|
|
9916
10469
|
process.stderr.write(message + (hint ? `
|
|
9917
10470
|
\u2192 ${hint}` : "") + "\n");
|
|
@@ -9938,13 +10491,13 @@ async function runSeedPlan(args, client3) {
|
|
|
9938
10491
|
const reconDir = candidates[0].reconDir;
|
|
9939
10492
|
if (candidates.length > 1) {
|
|
9940
10493
|
process.stderr.write(
|
|
9941
|
-
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${
|
|
10494
|
+
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path13.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path13.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
|
|
9942
10495
|
);
|
|
9943
10496
|
}
|
|
9944
10497
|
const round = inspectRound3(reconDir);
|
|
9945
10498
|
process.stderr.write(roundWarning(round));
|
|
9946
10499
|
const baseline = {
|
|
9947
|
-
path: `${
|
|
10500
|
+
path: `${path13.basename(path13.dirname(reconDir))}/${path13.basename(reconDir)}`,
|
|
9948
10501
|
roundId: round.roundId ?? null
|
|
9949
10502
|
};
|
|
9950
10503
|
let exemptions = null;
|
|
@@ -10001,7 +10554,7 @@ async function authOrSignpost(args, cmd) {
|
|
|
10001
10554
|
}
|
|
10002
10555
|
async function deliverySeedPlanCommand(args) {
|
|
10003
10556
|
const ctx = await authOrSignpost(args, "plan");
|
|
10004
|
-
const client3 =
|
|
10557
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10005
10558
|
process.exitCode = await runSeedPlan(args, seedClient(client3, ctx));
|
|
10006
10559
|
}
|
|
10007
10560
|
function seedClient(client3, ctx) {
|
|
@@ -10037,7 +10590,7 @@ function seedClient(client3, ctx) {
|
|
|
10037
10590
|
}
|
|
10038
10591
|
async function seedVerifyClient(client3, ctx) {
|
|
10039
10592
|
const base = seedClient(client3, ctx);
|
|
10040
|
-
const identity2 = await
|
|
10593
|
+
const identity2 = await fetchReconIdentity4(base, String(ctx.tenantId ?? ""));
|
|
10041
10594
|
return { ...base, identity: identity2 };
|
|
10042
10595
|
}
|
|
10043
10596
|
function lowerCaseHeaders(headers) {
|
|
@@ -10175,7 +10728,7 @@ async function runSeedApply(args, client3) {
|
|
|
10175
10728
|
}
|
|
10176
10729
|
async function deliverySeedApplyCommand(args) {
|
|
10177
10730
|
const ctx = await authOrSignpost(args, "apply");
|
|
10178
|
-
const client3 =
|
|
10731
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10179
10732
|
process.exitCode = await runSeedApply(args, seedClient(client3, ctx));
|
|
10180
10733
|
}
|
|
10181
10734
|
async function runSeedVerify(args, client3) {
|
|
@@ -10199,14 +10752,14 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
10199
10752
|
return;
|
|
10200
10753
|
}
|
|
10201
10754
|
const ctx = await authOrSignpost(args, "verify");
|
|
10202
|
-
const client3 =
|
|
10755
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10203
10756
|
process.exitCode = await runSeedVerify(args, await seedVerifyClient(client3, ctx));
|
|
10204
10757
|
}
|
|
10205
10758
|
|
|
10206
10759
|
// src/commands/delivery-seed-find.ts
|
|
10207
10760
|
import { existsSync as existsSync4 } from "fs";
|
|
10208
10761
|
import { readFileSync as readFileSync6 } from "fs";
|
|
10209
|
-
import * as
|
|
10762
|
+
import * as path14 from "path";
|
|
10210
10763
|
import {
|
|
10211
10764
|
INIT_EXIT_CODES as INIT_EXIT_CODES2,
|
|
10212
10765
|
ValueHints,
|
|
@@ -10220,10 +10773,10 @@ import {
|
|
|
10220
10773
|
valuesRoundCaveat
|
|
10221
10774
|
} from "@hcmai/sdk";
|
|
10222
10775
|
function provenance(chosenReconDir, others) {
|
|
10223
|
-
let line = `> \u57FA\u7EBF\uFF1A\`${
|
|
10776
|
+
let line = `> \u57FA\u7EBF\uFF1A\`${path14.basename(chosenReconDir)}\`
|
|
10224
10777
|
`;
|
|
10225
10778
|
if (others.length > 0) {
|
|
10226
|
-
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${
|
|
10779
|
+
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path14.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
|
|
10227
10780
|
}
|
|
10228
10781
|
return `${line}
|
|
10229
10782
|
`;
|
|
@@ -10314,7 +10867,7 @@ import {
|
|
|
10314
10867
|
CHANGE_STATES,
|
|
10315
10868
|
CHANGE_UNKNOWN,
|
|
10316
10869
|
CODE_WORDS,
|
|
10317
|
-
HcmClient as
|
|
10870
|
+
HcmClient as HcmClient26,
|
|
10318
10871
|
INIT_EXIT_CODES as INIT_EXIT_CODES3,
|
|
10319
10872
|
META_WRITE_STEPS,
|
|
10320
10873
|
META_VERIFY_STEPS,
|
|
@@ -10542,7 +11095,7 @@ function lowerCaseHeaders2(headers) {
|
|
|
10542
11095
|
}
|
|
10543
11096
|
async function deliveryMetaCommand(args) {
|
|
10544
11097
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
10545
|
-
const client3 =
|
|
11098
|
+
const client3 = HcmClient26.fromAuthContext(ctx);
|
|
10546
11099
|
process.exitCode = await runDeliveryMeta(
|
|
10547
11100
|
{ ...args, tenant: args.tenant ?? String(ctx.tenantId ?? "") },
|
|
10548
11101
|
metaClient(client3, ctx)
|
|
@@ -10554,13 +11107,13 @@ init_auth_guard();
|
|
|
10554
11107
|
init_exit();
|
|
10555
11108
|
import {
|
|
10556
11109
|
computeReconSourceKey as computeReconSourceKey2,
|
|
10557
|
-
HcmClient as
|
|
10558
|
-
httpProbe as
|
|
11110
|
+
HcmClient as HcmClient27,
|
|
11111
|
+
httpProbe as httpProbe5,
|
|
10559
11112
|
ReconLayout as ReconLayout2,
|
|
10560
11113
|
runTriageRound
|
|
10561
11114
|
} from "@hcmai/sdk";
|
|
10562
11115
|
import { mkdirSync, readFileSync as readFileSync8, writeFileSync as writeFileSync2 } from "fs";
|
|
10563
|
-
import * as
|
|
11116
|
+
import * as path15 from "path";
|
|
10564
11117
|
var DEFAULT_CAPABILITIES4 = "default";
|
|
10565
11118
|
function premise4(message, hint) {
|
|
10566
11119
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
|
|
@@ -10596,8 +11149,8 @@ function renderProblems(rows) {
|
|
|
10596
11149
|
`;
|
|
10597
11150
|
}
|
|
10598
11151
|
function writeTriageArtifact(outDir, body) {
|
|
10599
|
-
const out =
|
|
10600
|
-
mkdirSync(
|
|
11152
|
+
const out = path15.join(outDir, "work", "triage.md");
|
|
11153
|
+
mkdirSync(path15.dirname(out), { recursive: true });
|
|
10601
11154
|
writeFileSync2(out, body, "utf8");
|
|
10602
11155
|
return out;
|
|
10603
11156
|
}
|
|
@@ -10610,8 +11163,8 @@ async function runTriage(args) {
|
|
|
10610
11163
|
return premise4(e instanceof Error ? e.message : String(e), REQUESTS_SHAPE);
|
|
10611
11164
|
}
|
|
10612
11165
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
10613
|
-
const client3 =
|
|
10614
|
-
const probe =
|
|
11166
|
+
const client3 = HcmClient27.fromAuthContext(ctx);
|
|
11167
|
+
const probe = httpProbe5(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES4);
|
|
10615
11168
|
const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe)).dir;
|
|
10616
11169
|
const result = await runTriageRound(probe, artifactsDir, entriesIn);
|
|
10617
11170
|
if (result.body === null) {
|
|
@@ -10638,9 +11191,9 @@ async function deliveryTriageCommand(args) {
|
|
|
10638
11191
|
// src/commands/delivery-execution.ts
|
|
10639
11192
|
import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
|
|
10640
11193
|
import { spawn as spawn2 } from "child_process";
|
|
10641
|
-
import { createReadStream, promises as
|
|
10642
|
-
import
|
|
10643
|
-
import { CliError as
|
|
11194
|
+
import { createReadStream, promises as fs12 } from "fs";
|
|
11195
|
+
import path16 from "path";
|
|
11196
|
+
import { CliError as CliError23, CliErrorCode as CliErrorCode21, formatObject as formatObject28 } from "@hcmai/sdk";
|
|
10644
11197
|
init_exit();
|
|
10645
11198
|
var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
|
|
10646
11199
|
var DEFAULT_TTL_SECONDS = 15 * 60;
|
|
@@ -10682,11 +11235,11 @@ async function prepareDeliveryExecution(input) {
|
|
|
10682
11235
|
};
|
|
10683
11236
|
const planId = sha2565(canonicalJson(core)).slice(0, 24);
|
|
10684
11237
|
const plan = { ...core, planId };
|
|
10685
|
-
const plansDir =
|
|
11238
|
+
const plansDir = path16.join(project, ".hcm-delivery", "execution-plans");
|
|
10686
11239
|
await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
|
|
10687
|
-
const planFile =
|
|
11240
|
+
const planFile = path16.join(plansDir, `${planId}.json`);
|
|
10688
11241
|
try {
|
|
10689
|
-
await
|
|
11242
|
+
await fs12.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
|
|
10690
11243
|
`, {
|
|
10691
11244
|
encoding: "utf8",
|
|
10692
11245
|
mode: 384,
|
|
@@ -10700,7 +11253,7 @@ async function prepareDeliveryExecution(input) {
|
|
|
10700
11253
|
async function executeDeliveryPlan(input) {
|
|
10701
11254
|
if (!PLAN_ID_PATTERN.test(input.planId)) throw invalid2("planId \u5FC5\u987B\u662F 24 \u4F4D\u5C0F\u5199\u5341\u516D\u8FDB\u5236");
|
|
10702
11255
|
const project = await realProject(input.project);
|
|
10703
|
-
const planFile =
|
|
11256
|
+
const planFile = path16.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
10704
11257
|
const plan = await readPlan(project, planFile);
|
|
10705
11258
|
if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
|
|
10706
11259
|
throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
|
|
@@ -10737,13 +11290,13 @@ async function executeDeliveryPlan(input) {
|
|
|
10737
11290
|
await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
|
|
10738
11291
|
await assertPayloadsUnchanged(project, plan.payloads);
|
|
10739
11292
|
const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
|
|
10740
|
-
const receiptFile =
|
|
11293
|
+
const receiptFile = path16.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
|
|
10741
11294
|
if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
|
|
10742
|
-
const claimsDir =
|
|
11295
|
+
const claimsDir = path16.join(project, ".hcm-delivery", "execution-claims");
|
|
10743
11296
|
await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
|
|
10744
|
-
const claimFile =
|
|
11297
|
+
const claimFile = path16.join(claimsDir, `${plan.planId}.json`);
|
|
10745
11298
|
try {
|
|
10746
|
-
await
|
|
11299
|
+
await fs12.writeFile(
|
|
10747
11300
|
claimFile,
|
|
10748
11301
|
`${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
|
|
10749
11302
|
`,
|
|
@@ -10800,7 +11353,7 @@ async function deliveryPrepareCommand(argv, args) {
|
|
|
10800
11353
|
evidenceDir: args.evidenceDir,
|
|
10801
11354
|
...ttlSeconds === void 0 ? {} : { ttlSeconds }
|
|
10802
11355
|
});
|
|
10803
|
-
process.stdout.write(
|
|
11356
|
+
process.stdout.write(formatObject28(plan, { format: args.output ?? "json" }) + "\n");
|
|
10804
11357
|
process.stderr.write(`
|
|
10805
11358
|
\u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
|
|
10806
11359
|
${nextCommandHint(plan.planId, args.project, argv)}
|
|
@@ -10827,11 +11380,11 @@ async function deliveryExecuteCommand(planId, argv, args) {
|
|
|
10827
11380
|
}
|
|
10828
11381
|
}
|
|
10829
11382
|
function writeDeliveryExecutionReceipt(receipt, format = "json") {
|
|
10830
|
-
process.stderr.write(
|
|
11383
|
+
process.stderr.write(formatObject28(receipt, { format }) + "\n");
|
|
10831
11384
|
process.exitCode = receipt.exitCode;
|
|
10832
11385
|
}
|
|
10833
11386
|
async function readProjectMode(project, environment) {
|
|
10834
|
-
const file =
|
|
11387
|
+
const file = path16.join(project, ".hcm-delivery", "project.yml");
|
|
10835
11388
|
const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
|
|
10836
11389
|
let mode;
|
|
10837
11390
|
try {
|
|
@@ -10847,13 +11400,13 @@ async function readProjectMode(project, environment) {
|
|
|
10847
11400
|
return mode;
|
|
10848
11401
|
}
|
|
10849
11402
|
var SKILLS_LOCK_CANDIDATES = [
|
|
10850
|
-
|
|
10851
|
-
|
|
11403
|
+
path16.join("hcm-skills", ".hcm-skills.json"),
|
|
11404
|
+
path16.join(".claude", "skills", ".hcm-skills.json")
|
|
10852
11405
|
];
|
|
10853
11406
|
async function readSkillsLock(project) {
|
|
10854
11407
|
const found = [];
|
|
10855
11408
|
for (const candidate of SKILLS_LOCK_CANDIDATES) {
|
|
10856
|
-
if (await pathExists(
|
|
11409
|
+
if (await pathExists(path16.join(project, candidate))) found.push(candidate);
|
|
10857
11410
|
}
|
|
10858
11411
|
if (found.length === 0) {
|
|
10859
11412
|
throw invalid2(
|
|
@@ -10865,7 +11418,7 @@ async function readSkillsLock(project) {
|
|
|
10865
11418
|
`\u9879\u76EE\u91CC\u6709\u591A\u4EFD\u6280\u80FD\u9501\uFF08${found.join("\u3001")}\uFF09\uFF0C\u65E0\u6CD5\u552F\u4E00\u5224\u5B9A\u53D7\u63A7\u6267\u884C\u7ED1\u5B9A\u54EA\u4E00\u4EFD\u3002next_step=\u53EA\u4FDD\u7559\u5B9E\u9645\u5728\u7528\u7684\u90A3\u4E2A\u6280\u80FD\u76EE\u5F55`
|
|
10866
11419
|
);
|
|
10867
11420
|
}
|
|
10868
|
-
const bytes = await readSafeFile(project,
|
|
11421
|
+
const bytes = await readSafeFile(project, path16.join(project, found[0]), "\u6280\u80FD\u9501");
|
|
10869
11422
|
try {
|
|
10870
11423
|
JSON.parse(bytes.toString("utf8"));
|
|
10871
11424
|
} catch (cause) {
|
|
@@ -10878,7 +11431,7 @@ async function bindDocument(project, reference, label) {
|
|
|
10878
11431
|
if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
|
|
10879
11432
|
throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
|
|
10880
11433
|
}
|
|
10881
|
-
const file =
|
|
11434
|
+
const file = path16.join(project, relative2);
|
|
10882
11435
|
const bytes = await readSafeFile(project, file, label);
|
|
10883
11436
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
10884
11437
|
}
|
|
@@ -10891,11 +11444,11 @@ async function bindEvidenceDirectory(project, reference) {
|
|
|
10891
11444
|
if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
|
|
10892
11445
|
throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
|
|
10893
11446
|
}
|
|
10894
|
-
const absolute =
|
|
11447
|
+
const absolute = path16.join(project, relative2);
|
|
10895
11448
|
await assertNoSymlinkComponents(project, relative2);
|
|
10896
|
-
const stat = await
|
|
11449
|
+
const stat = await fs12.stat(absolute).catch(() => null);
|
|
10897
11450
|
if (stat === null) {
|
|
10898
|
-
await
|
|
11451
|
+
await fs12.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
|
|
10899
11452
|
throw invalid2(
|
|
10900
11453
|
`evidence \u76EE\u5F55\u5EFA\u4E0D\u51FA\u6765\uFF1A${relative2}\u3002next_step=\u68C0\u67E5\u4E0A\u7EA7\u76EE\u5F55\u6743\u9650\uFF0C\u6216\u6362\u4E00\u4E2A evidence/ \u4E0B\u7684\u8DEF\u5F84`,
|
|
10901
11454
|
cause
|
|
@@ -11075,7 +11628,7 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
11075
11628
|
const relative2 = safeRelative(reference, label);
|
|
11076
11629
|
let stat;
|
|
11077
11630
|
try {
|
|
11078
|
-
stat = await
|
|
11631
|
+
stat = await fs12.stat(path16.join(project, relative2));
|
|
11079
11632
|
} catch (cause) {
|
|
11080
11633
|
throw invalid2(
|
|
11081
11634
|
`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}\u3002next_step=\u628A\u6570\u636E\u96C6\u653E\u8FDB\u9879\u76EE\u76EE\u5F55\u5185\uFF0C\u5E76\u7528\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84\u5F15\u7528\uFF08\u53D7\u63A7\u6267\u884C\u53EA\u9489\u5F97\u4F4F\u9879\u76EE\u5185\u7684\u8F7D\u8377\uFF09`,
|
|
@@ -11086,10 +11639,10 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
11086
11639
|
}
|
|
11087
11640
|
async function bindPayloadDirectory(project, reference, label) {
|
|
11088
11641
|
const relative2 = reference === "." ? "." : safeRelative(reference, label);
|
|
11089
|
-
const root =
|
|
11642
|
+
const root = path16.join(project, relative2);
|
|
11090
11643
|
let stat;
|
|
11091
11644
|
try {
|
|
11092
|
-
stat = await
|
|
11645
|
+
stat = await fs12.stat(root);
|
|
11093
11646
|
} catch {
|
|
11094
11647
|
throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
|
|
11095
11648
|
}
|
|
@@ -11099,10 +11652,10 @@ async function bindPayloadDirectory(project, reference, label) {
|
|
|
11099
11652
|
const skipToolingAtRoot = relative2 === ".";
|
|
11100
11653
|
const entries = [];
|
|
11101
11654
|
const walk = async (dir, prefix) => {
|
|
11102
|
-
const items = await
|
|
11655
|
+
const items = await fs12.readdir(dir, { withFileTypes: true });
|
|
11103
11656
|
for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
11104
11657
|
if (skipToolingAtRoot && prefix === "" && TOOLING_DIRS.includes(item.name)) continue;
|
|
11105
|
-
const child =
|
|
11658
|
+
const child = path16.join(dir, item.name);
|
|
11106
11659
|
const rel = prefix ? `${prefix}/${item.name}` : item.name;
|
|
11107
11660
|
if (item.isSymbolicLink()) {
|
|
11108
11661
|
throw invalid2(
|
|
@@ -11127,7 +11680,7 @@ ${sha2565(bytes)}`);
|
|
|
11127
11680
|
}
|
|
11128
11681
|
async function bindPayloadFile(project, reference, label) {
|
|
11129
11682
|
const relative2 = safeRelative(reference, label);
|
|
11130
|
-
const file =
|
|
11683
|
+
const file = path16.join(project, relative2);
|
|
11131
11684
|
const bytes = await readSafeFile(project, file, label);
|
|
11132
11685
|
return { path: relative2, kind: "file", sha256: sha2565(bytes) };
|
|
11133
11686
|
}
|
|
@@ -11190,29 +11743,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
|
|
|
11190
11743
|
async function writeReceiptExclusive(target, receipt) {
|
|
11191
11744
|
const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
11192
11745
|
try {
|
|
11193
|
-
await
|
|
11746
|
+
await fs12.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
|
|
11194
11747
|
`, {
|
|
11195
11748
|
encoding: "utf8",
|
|
11196
11749
|
mode: 384,
|
|
11197
11750
|
flag: "wx"
|
|
11198
11751
|
});
|
|
11199
|
-
await
|
|
11752
|
+
await fs12.link(temp, target);
|
|
11200
11753
|
} catch (cause) {
|
|
11201
|
-
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${
|
|
11754
|
+
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path16.basename(target)}`, cause);
|
|
11202
11755
|
} finally {
|
|
11203
|
-
await
|
|
11756
|
+
await fs12.unlink(temp).catch(() => void 0);
|
|
11204
11757
|
}
|
|
11205
11758
|
}
|
|
11206
11759
|
async function safeManagedDirectory(project, relative2, absolute) {
|
|
11207
|
-
await assertNoSymlinkComponents(project,
|
|
11208
|
-
const existing = await
|
|
11760
|
+
await assertNoSymlinkComponents(project, path16.dirname(relative2));
|
|
11761
|
+
const existing = await fs12.lstat(absolute).catch(() => void 0);
|
|
11209
11762
|
if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11210
11763
|
if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
11211
|
-
if (!existing) await
|
|
11212
|
-
await
|
|
11764
|
+
if (!existing) await fs12.mkdir(absolute, { mode: 448 });
|
|
11765
|
+
await fs12.chmod(absolute, 448);
|
|
11213
11766
|
}
|
|
11214
11767
|
async function pathExists(file) {
|
|
11215
|
-
return
|
|
11768
|
+
return fs12.lstat(file).then(
|
|
11216
11769
|
() => true,
|
|
11217
11770
|
(cause) => {
|
|
11218
11771
|
if (cause.code === "ENOENT") return false;
|
|
@@ -11221,47 +11774,47 @@ async function pathExists(file) {
|
|
|
11221
11774
|
);
|
|
11222
11775
|
}
|
|
11223
11776
|
async function readSafeFile(project, file, label) {
|
|
11224
|
-
const relative2 =
|
|
11225
|
-
if (relative2.startsWith("../") ||
|
|
11777
|
+
const relative2 = path16.relative(project, file).split(path16.sep).join("/");
|
|
11778
|
+
if (relative2.startsWith("../") || path16.isAbsolute(relative2))
|
|
11226
11779
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
11227
11780
|
await assertNoSymlinkComponents(project, relative2);
|
|
11228
11781
|
let stat;
|
|
11229
11782
|
try {
|
|
11230
|
-
stat = await
|
|
11783
|
+
stat = await fs12.lstat(file);
|
|
11231
11784
|
} catch (cause) {
|
|
11232
11785
|
throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
|
|
11233
11786
|
}
|
|
11234
11787
|
if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11235
11788
|
if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
|
|
11236
|
-
return
|
|
11789
|
+
return fs12.readFile(file);
|
|
11237
11790
|
}
|
|
11238
11791
|
async function assertNoSymlinkComponents(project, relative2) {
|
|
11239
11792
|
const parts = relative2.split("/").filter(Boolean);
|
|
11240
11793
|
let current = project;
|
|
11241
11794
|
for (const part of parts) {
|
|
11242
|
-
current =
|
|
11243
|
-
const stat = await
|
|
11795
|
+
current = path16.join(current, part);
|
|
11796
|
+
const stat = await fs12.lstat(current).catch(() => void 0);
|
|
11244
11797
|
if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11245
11798
|
if (!stat) break;
|
|
11246
11799
|
}
|
|
11247
11800
|
}
|
|
11248
11801
|
async function realProject(requested) {
|
|
11249
|
-
const absolute =
|
|
11802
|
+
const absolute = path16.resolve(requested);
|
|
11250
11803
|
let project;
|
|
11251
11804
|
try {
|
|
11252
|
-
project = await
|
|
11805
|
+
project = await fs12.realpath(absolute);
|
|
11253
11806
|
} catch (cause) {
|
|
11254
11807
|
throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
|
|
11255
11808
|
}
|
|
11256
|
-
const stat = await
|
|
11809
|
+
const stat = await fs12.stat(project);
|
|
11257
11810
|
if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
|
|
11258
11811
|
return project;
|
|
11259
11812
|
}
|
|
11260
11813
|
function safeRelative(reference, label) {
|
|
11261
|
-
if (!reference ||
|
|
11814
|
+
if (!reference || path16.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
|
|
11262
11815
|
throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
|
|
11263
11816
|
}
|
|
11264
|
-
const normalized =
|
|
11817
|
+
const normalized = path16.normalize(reference).split(path16.sep).join("/");
|
|
11265
11818
|
if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
|
|
11266
11819
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
11267
11820
|
}
|
|
@@ -11314,7 +11867,7 @@ async function sha256File(file) {
|
|
|
11314
11867
|
return hash.digest("hex");
|
|
11315
11868
|
}
|
|
11316
11869
|
function invalid2(message, cause) {
|
|
11317
|
-
return new
|
|
11870
|
+
return new CliError23({ code: CliErrorCode21.INVALID_ARGUMENT, message, cause });
|
|
11318
11871
|
}
|
|
11319
11872
|
function nextCommandHint(planId, project, argv) {
|
|
11320
11873
|
const quoted = argv.map((a) => /[\s"'$`\\]/.test(a) ? `'${a.replace(/'/g, `'\\''`)}'` : a);
|
|
@@ -11326,25 +11879,25 @@ function nextCommandHint(planId, project, argv) {
|
|
|
11326
11879
|
init_auth_guard();
|
|
11327
11880
|
init_exit();
|
|
11328
11881
|
import {
|
|
11329
|
-
HcmClient as
|
|
11882
|
+
HcmClient as HcmClient28,
|
|
11330
11883
|
adminResetPassword,
|
|
11331
|
-
formatObject as
|
|
11884
|
+
formatObject as formatObject29,
|
|
11332
11885
|
fromAxiosError as fromAxiosError23,
|
|
11333
|
-
CliError as
|
|
11334
|
-
CliErrorCode as
|
|
11886
|
+
CliError as CliError24,
|
|
11887
|
+
CliErrorCode as CliErrorCode22
|
|
11335
11888
|
} from "@hcmai/sdk";
|
|
11336
11889
|
function buildAdminResetPasswordRequest(args, password) {
|
|
11337
11890
|
const hasId = Boolean(args.id);
|
|
11338
11891
|
const hasUsername = Boolean(args.username);
|
|
11339
11892
|
if (hasId === hasUsername) {
|
|
11340
|
-
throw new
|
|
11341
|
-
code:
|
|
11893
|
+
throw new CliError24({
|
|
11894
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11342
11895
|
message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
|
|
11343
11896
|
});
|
|
11344
11897
|
}
|
|
11345
11898
|
if (!password) {
|
|
11346
|
-
throw new
|
|
11347
|
-
code:
|
|
11899
|
+
throw new CliError24({
|
|
11900
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11348
11901
|
message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
|
|
11349
11902
|
});
|
|
11350
11903
|
}
|
|
@@ -11360,9 +11913,9 @@ async function userResetPasswordCommand(args) {
|
|
|
11360
11913
|
try {
|
|
11361
11914
|
const password = args.passwordStdin ? await readSecretFromStdin() : await promptPasswordTwice();
|
|
11362
11915
|
const request = buildAdminResetPasswordRequest(args, password);
|
|
11363
|
-
const client3 =
|
|
11916
|
+
const client3 = HcmClient28.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
11364
11917
|
const result = await adminResetPassword(client3.raw(), request);
|
|
11365
|
-
process.stdout.write(
|
|
11918
|
+
process.stdout.write(formatObject29(result, { format: args.output ?? "json" }) + "\n");
|
|
11366
11919
|
} catch (cause) {
|
|
11367
11920
|
const err = cause;
|
|
11368
11921
|
if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.env));
|
|
@@ -11373,8 +11926,8 @@ async function promptPasswordTwice() {
|
|
|
11373
11926
|
const password = await promptSecret("\u65B0\u5BC6\u7801: ");
|
|
11374
11927
|
const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
|
|
11375
11928
|
if (password !== confirmation) {
|
|
11376
|
-
throw new
|
|
11377
|
-
code:
|
|
11929
|
+
throw new CliError24({
|
|
11930
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11378
11931
|
message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
|
|
11379
11932
|
});
|
|
11380
11933
|
}
|
|
@@ -11385,19 +11938,19 @@ async function promptPasswordTwice() {
|
|
|
11385
11938
|
init_exit();
|
|
11386
11939
|
init_auth_guard();
|
|
11387
11940
|
import {
|
|
11388
|
-
HcmClient as
|
|
11389
|
-
formatObject as
|
|
11941
|
+
HcmClient as HcmClient29,
|
|
11942
|
+
formatObject as formatObject30,
|
|
11390
11943
|
fromAxiosError as fromAxiosError24
|
|
11391
11944
|
} from "@hcmai/sdk";
|
|
11392
11945
|
async function modelsCommand(keyword, args) {
|
|
11393
11946
|
try {
|
|
11394
|
-
const client3 =
|
|
11947
|
+
const client3 = HcmClient29.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
11395
11948
|
const all = await client3.listModels();
|
|
11396
11949
|
const needle = keyword?.trim().toLowerCase();
|
|
11397
11950
|
const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
|
|
11398
11951
|
const fmt = args.output ?? "table";
|
|
11399
11952
|
if (fmt !== "table") {
|
|
11400
|
-
process.stdout.write(
|
|
11953
|
+
process.stdout.write(formatObject30({ total: rows.length, models: rows }, { format: fmt }) + "\n");
|
|
11401
11954
|
process.exitCode = 0;
|
|
11402
11955
|
return;
|
|
11403
11956
|
}
|
|
@@ -11447,7 +12000,10 @@ var exitOnBrokenPipe = (err) => {
|
|
|
11447
12000
|
};
|
|
11448
12001
|
process.stdout.on("error", exitOnBrokenPipe);
|
|
11449
12002
|
process.stderr.on("error", exitOnBrokenPipe);
|
|
11450
|
-
program.name("hcm").description("HCM \u547D\u4EE4\u884C\u5DE5\u5177 \u2014 \u64CD\u4F5C HCM API\u3001\u4E0E Moirai \u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u3001\u5F00\u53D1\u79DF\u6237\u5F00\u53D1\u7A7A\u95F4").version(CLI_VERSION)
|
|
12003
|
+
program.name("hcm").description("HCM \u547D\u4EE4\u884C\u5DE5\u5177 \u2014 \u64CD\u4F5C HCM API\u3001\u4E0E Moirai \u6570\u5B57\u5458\u5DE5\u5BF9\u8BDD\u3001\u5F00\u53D1\u79DF\u6237\u5F00\u53D1\u7A7A\u95F4").version(CLI_VERSION).option("--lang <code>", "\u8BF7\u6C42\u8BED\u8A00\uFF1Azh_CN | zh_HK | en\uFF08\u7B49\u4EF7\u4E8E\u73AF\u5883\u53D8\u91CF HCM_LANG\uFF1B\u4E0D\u7ED9\u6309\u670D\u52A1\u7AEF\u7F3A\u7701\u8BED\u8A00\uFF09").hook("preAction", (thisCommand) => {
|
|
12004
|
+
const lang = thisCommand.opts().lang;
|
|
12005
|
+
if (lang) process.env.HCM_LANG = lang;
|
|
12006
|
+
});
|
|
11451
12007
|
program.command("login").description("\u767B\u5F55 HCM\uFF08\u914D\u5BF9\u7801 / \u7528\u6237\u540D\u5BC6\u7801 / client_credentials / PAT \u56DB\u79CD\u65B9\u5F0F\uFF09").argument("[endpoint]", "\u4ECE\u7CFB\u7EDF\u9875\u9762\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u590D\u5236\u6765\u7684\u5730\u5740\uFF08\u914D\u5BF9\u7801\u65B9\u5F0F\uFF09").option("--code <code>", "\u914D\u5BF9\u7801\uFF0C\u5728\u7CFB\u7EDF\u9875\u9762\u7528\u6237\u83DC\u5355 \u2192\u300C\u547D\u4EE4\u884C\u5DE5\u5177\u300D\u751F\u6210").option("--env <name>", "\u73AF\u5883\u540D\uFF08\u9ED8\u8BA4 activeEnv\uFF09").option("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--name <id-name>", "\u81EA\u5B9A\u4E49 identity \u540D\uFF08\u9ED8\u8BA4\u6309 scheme \u63A8\u65AD\uFF09").option("--no-activate", "login \u5B8C\u4E0D\u5207\u5230\u8BE5\u73AF\u5883\u4E5F\u4E0D\u8BBE\u4E3A default identity").option("--endpoint <url>", "HCM \u540E\u7AEF\u5730\u5740\uFF0C\u4F8B\u5982 http://localhost:8080").option("--username <user>", "\u7528\u6237\u540D\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF09").option("--password <pwd>", "\u5BC6\u7801\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF1B\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0CAgent/\u53D7\u63A7\u4EA4\u4ED8\u8BF7\u7528 --password-stdin\uFF09").option("--password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u5BC6\u7801\uFF08\u5BC6\u7801\u767B\u5F55\u6A21\u5F0F\uFF0C\u975E\u4EA4\u4E92/\u4E0D\u56DE\u663E\uFF09").option("--client-id <id>", "OAuth client_id\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--client-secret <secret>", "OAuth client_secret\uFF08client_credentials \u6A21\u5F0F\uFF09").option("--pat <token>", "PAT \u4E2A\u4EBA\u8BBF\u95EE\u4EE4\u724C\uFF08\u6CE8\u610F\uFF1A\u4F1A\u6CC4\u6F0F\u5230 ps/history\uFF0C\u5EFA\u8BAE\u6539\u7528 --pat-stdin\uFF09").option("--pat-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6 PAT\uFF08\u63A8\u8350\uFF09").option("--new-password <pwd>", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u7684\u65B0\u53E3\u4EE4\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --new-password-stdin\uFF09").option("--new-password-stdin", "\u9996\u767B\u5F3A\u5236\u6539\u5BC6\u65F6\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u65B0\u53E3\u4EE4\uFF08\u975E\u4EA4\u4E92\u573A\u666F\uFF09").option("--tenant <tenantId>", "\u79DF\u6237 ID\uFF08\u9ED8\u8BA4 1\uFF09").action((endpoint, opts) => loginCommand({ ...opts, endpointArg: endpoint }));
|
|
11452
12008
|
program.command("logout").description("\u767B\u51FA HCM\uFF08\u6E05\u9664 identity \u7684 keychain token\uFF09").option("--identity <name>", "\u6307\u5B9A identity\uFF1B\u9ED8\u8BA4\u6E05\u5F53\u524D env \u7684 default identity").option("--env <name>", "\u6307\u5B9A env\uFF08\u5F71\u54CD default identity \u89E3\u6790\uFF09").action((opts) => logoutCommand(opts));
|
|
11453
12009
|
var config = program.command("config").description("\u7BA1\u7406\u5168\u5C40 defaults\uFF08env/identity \u7528 `hcm env` / `hcm identity`\uFF09");
|
|
@@ -11472,6 +12028,9 @@ identity.command("use <name>").description("\u628A identity \u8BBE\u4E3A\u5176 e
|
|
|
11472
12028
|
identity.command("remove <name>").description("\u5220\u9664 identity\uFF08\u6E05 token + \u82E5\u662F env default \u5219\u6E05\u7A7A\uFF09").action((name) => identityRemove(name));
|
|
11473
12029
|
var user = program.command("user").description("\u7BA1\u7406\u79DF\u6237\u7528\u6237\u7684\u4E13\u7528\u51ED\u636E\u6D41\u7A0B");
|
|
11474
12030
|
user.command("reset-password").description("\u7531 admin.system \u5B89\u5168\u91CD\u7F6E\u7528\u6237\u5BC6\u7801\uFF0C\u5E76\u4F7F\u65E2\u6709\u4F1A\u8BDD\u5931\u6548").option("--id <uuid>", "\u76EE\u6807\u7528\u6237 ID\uFF08\u4E0E --username \u4E8C\u9009\u4E00\uFF09").option("--username <user>", "\u76EE\u6807\u7528\u6237\u540D\uFF08\u4E0E --id \u4E8C\u9009\u4E00\uFF09").option("--password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u53D6\u65B0\u5BC6\u7801\uFF08Agent/\u53D7\u63A7\u4EA4\u4ED8\u5FC5\u987B\u4F7F\u7528\uFF09").option("--no-force-change", "\u4E0B\u6B21\u767B\u5F55\u4E0D\u5F3A\u5236\u6539\u5BC6\uFF08\u4EC5\u9650\u5DF2\u6279\u51C6\u7684\u9694\u79BB\u6D4B\u8BD5\u73AF\u5883\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u5FC5\u987B\u5177\u5907 admin.system\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => userResetPasswordCommand(opts));
|
|
12031
|
+
var chiron = program.command("chiron").description("\u777F\u620E\u987E\u95EE\u9879\u76EE\uFF1Ainit \u4E00\u6761\u547D\u4EE4\u521D\u59CB\u5316\u9879\u76EE\u4ED3\uFF0Cdoctor \u4E09\u884C\u6838\u5BF9\u80FD\u4E0D\u80FD\u5F00\u5DE5");
|
|
12032
|
+
chiron.command("init").description("\u521D\u59CB\u5316\u987E\u95EE\u9879\u76EE\u4ED3\uFF1A\u5199 env.yaml\uFF08\u7528\u521A hcm login \u7684\u73AF\u5883\uFF09\u3001\u5EFA\u76EE\u5F55\u3001\u88C5\u5168\u90E8\u6280\u80FD\u3001\u63A5\u6848\u4F8B\u5E93\uFF1B\u91CD\u8DD1\u5B89\u5168").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--skip-skills", "\u4E0D\u88C5\u6280\u80FD\uFF08\u79BB\u7EBF/\u6D4B\u8BD5\uFF09").option("--skip-cases", "\u4E0D\u63A5\u6848\u4F8B\u5E93").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironInitCommand(opts));
|
|
12033
|
+
chiron.command("doctor").description("\u6838\u5BF9\uFF1A\u672C\u673A\u767B\u5F55\u662F\u5426\u5BF9\u7740 env.yaml \u7684\u73AF\u5883\uFF08\u542B\u56DB\u6761\u951A\u70B9\uFF09/ \u6280\u80FD\u88C5\u6CA1\u88C5 / \u6848\u4F8B\u5E93\u63A5\u6CA1\u63A5").option("--project <dir>", "\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--fix", "\u80FD\u81EA\u52A8\u8865\u7684\u8865\u4E0A\uFF08\u6280\u80FD / \u6848\u4F8B\u5E93\uFF09\u540E\u518D\u6838\u4E00\u904D").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => chironDoctorCommand(opts));
|
|
11475
12034
|
var delivery = program.command("delivery").description("\u987E\u95EE\u4EA4\u4ED8\uFF1A\u73B0\u573A\u63A2\u6D3B\u3001\u98CE\u9669\u8BC4\u4F30\u4E0E\u4E00\u6B21\u6027\u53D7\u63A7\u6267\u884C\u5408\u540C");
|
|
11476
12035
|
delivery.command("assess").description("\u8BC4\u4F30\u4E00\u6B21 HCM CLI argv\uFF1BAction \u98CE\u63A7\u58F0\u660E\u8BFB\u53D6\u81EA\u76EE\u6807 Core\uFF0C\u7528 -- \u5206\u9694\u88AB\u8BC4\u4F30\u547D\u4EE4").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("<command...>", "\u88AB\u8BC4\u4F30\u7684 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570\uFF0C\u4E0D\u5305\u542B hcm \u672C\u8EAB").action((command, opts) => deliveryAssessCommand(command, opts));
|
|
11477
12036
|
delivery.command("doctor").description("\u56DB\u6761\u951A\u70B9\u63A2\u6D3B\uFF1A\u8FDE\u901A / \u6211\u662F\u8C01 / configAdmin / \u7AD9\u5728\u54EA\u4E00\u5C42").option("--env <name>", "\u76EE\u6807\u73AF\u5883\u522B\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--capabilities <s>", "\u722C\u53D6\u65F6\u58F0\u660E\u7684 capability \u4E32\uFF08\u4F1A\u968F\u56DB\u5143\u7EC4\u7559\u6863\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryDoctorCommand(opts));
|
|
@@ -11624,7 +12183,7 @@ skills.command("update").description("\u628A\u88C5\u8FC7\u7684\u6280\u80FD\u5347
|
|
|
11624
12183
|
program.command("update <Model>").description("\u66F4\u65B0\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF09\u3002\u5347\u7EA7 CLI \u8BF7\u7528 `hcm upgrade`").requiredOption("--id <id>", "\u8BB0\u5F55 ID").option("--data <JSON>", `\u8981\u66F4\u65B0\u7684\u5B57\u6BB5 JSON\uFF0C\u4F8B\u5982 '{"name":"\u65B0\u540D\u79F0"}'`).option("--data-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6\u66F4\u65B0\u5B57\u6BB5\uFF08\u4E0E --data \u4E92\u65A5\uFF09").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD\uFF08\u8986\u76D6 env defaultIdentity\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").option("--i18n", "\u591A\u8BED\u8A00\u5B57\u6BB5\u6309 Map \u5B8C\u6574\u66FF\u6362\uFF08\u952E\u7528 zh-CN / en-US \u8FDE\u5B57\u7B26\u5F62\uFF09\uFF1B\u4E0D\u4F20\u5219\u6309\u5B57\u7B26\u4E32\u53EA\u6539\u5F53\u524D\u8BED\u8A00").action((model, opts) => updateCommand(model, opts));
|
|
11625
12184
|
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 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));
|
|
11626
12185
|
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));
|
|
11627
|
-
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>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").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((
|
|
12186
|
+
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>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").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));
|
|
11628
12187
|
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");
|
|
11629
12188
|
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>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((d, opts) => settingGetCommand(d, opts));
|
|
11630
12189
|
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("--set <assignment...>", "namespace.key=value\uFF0C\u4F8B\u5982 security.password.passwordPolicy=complex").option("--dry-run", "\u53EA\u663E\u793A\u5C06\u5199\u5165\u4EC0\u4E48\uFF0C\u4E0D\u5B9E\u9645\u5199\u5165").option("--env <name>", "\u4E34\u65F6\u5207\u73AF\u5883\uFF08\u8986\u76D6 activeEnv\uFF0C\u672C\u6B21\u547D\u4EE4\uFF09").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((d, opts) => settingSetCommand(d, opts));
|