@hcmai/cli 0.4.22 → 0.4.23
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 +711 -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,557 @@ 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) {
|
|
9860
|
+
const server = path9.join(repo, "mcp", "server.mjs");
|
|
9861
|
+
return [
|
|
9862
|
+
`[mcp_servers.${CASES_MCP_NAME}]`,
|
|
9863
|
+
'command = "node"',
|
|
9864
|
+
`args = [${JSON.stringify(server)}]`,
|
|
9865
|
+
`env = { CASES_REPO = ${JSON.stringify(repo)}, HCM_ENV = ${JSON.stringify(envName)} }`,
|
|
9866
|
+
""
|
|
9867
|
+
].join("\n");
|
|
9868
|
+
}
|
|
9869
|
+
function mergeCodexMcpConfig(existing, section) {
|
|
9870
|
+
const lines = existing.split(/\r?\n/);
|
|
9871
|
+
const isOurs = (line) => new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}(\\.|\\])`).test(line.trim());
|
|
9872
|
+
const isHeader = (line) => /^\s*\[/.test(line);
|
|
9873
|
+
let start = -1;
|
|
9874
|
+
let end = -1;
|
|
9875
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9876
|
+
const line = lines[i] ?? "";
|
|
9877
|
+
if (start < 0 && isOurs(line)) {
|
|
9878
|
+
start = i;
|
|
9879
|
+
continue;
|
|
9880
|
+
}
|
|
9881
|
+
if (start >= 0 && isHeader(line) && !isOurs(line)) {
|
|
9882
|
+
end = i;
|
|
9883
|
+
break;
|
|
9884
|
+
}
|
|
9885
|
+
}
|
|
9886
|
+
const block = section.trimEnd();
|
|
9887
|
+
if (start < 0) {
|
|
9888
|
+
const prefix = existing.trimEnd();
|
|
9889
|
+
return `${prefix}${prefix ? "\n\n" : ""}${block}
|
|
9890
|
+
`;
|
|
9891
|
+
}
|
|
9892
|
+
const tail = lines.slice(end < 0 ? lines.length : end);
|
|
9893
|
+
const head = lines.slice(0, start);
|
|
9894
|
+
return `${[...head, block, "", ...tail].join("\n").replace(/\n{3,}/g, "\n\n").trimEnd()}
|
|
9895
|
+
`;
|
|
9896
|
+
}
|
|
9897
|
+
function codexConfigHasCases(text) {
|
|
9898
|
+
return new RegExp(`^\\[mcp_servers\\.${CASES_MCP_NAME}\\]`, "m").test(text);
|
|
9899
|
+
}
|
|
9900
|
+
var defaultCaseLibraryDeps = {
|
|
9901
|
+
git: (args, cwd) => {
|
|
9902
|
+
const r = spawnSync("git", args, { cwd, encoding: "utf8", timeout: 12e4, env: { ...process.env, GIT_TERMINAL_PROMPT: "0" } });
|
|
9903
|
+
return { status: r.status, stderr: r.stderr ?? "", error: r.error };
|
|
9904
|
+
},
|
|
9905
|
+
npmInstall: (cwd) => {
|
|
9906
|
+
const r = spawnSync("npm", ["install", "--omit=dev", "--no-audit", "--no-fund", "--loglevel=error"], {
|
|
9907
|
+
cwd,
|
|
9908
|
+
encoding: "utf8",
|
|
9909
|
+
timeout: 3e5
|
|
9910
|
+
});
|
|
9911
|
+
return { status: r.status, stderr: r.stderr ?? "", error: r.error };
|
|
9912
|
+
}
|
|
9913
|
+
};
|
|
9914
|
+
async function ensureCaseLibrary(envName, deps = defaultCaseLibraryDeps, paths = {}) {
|
|
9915
|
+
const repo = paths.repo ?? caseLibraryDir();
|
|
9916
|
+
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
9917
|
+
const status = { ok: false, repo, step: "present", serverInstalled: false, codexWired: false };
|
|
9918
|
+
const hasGit = await exists2(path9.join(repo, ".git"));
|
|
9919
|
+
if (hasGit) {
|
|
9920
|
+
const pull = deps.git(["pull", "--ff-only", "--quiet"], repo);
|
|
9921
|
+
status.step = pull.status === 0 ? "updated" : "present";
|
|
9922
|
+
if (pull.status !== 0) status.reason = `\u66F4\u65B0\u5931\u8D25\uFF0C\u6CBF\u7528\u672C\u5730\u7248\u672C\uFF1A${firstLine(pull.stderr, pull.error)}`;
|
|
9923
|
+
} else {
|
|
9924
|
+
await fs9.mkdir(path9.dirname(repo), { recursive: true });
|
|
9925
|
+
const clone = deps.git(["clone", "--depth", "1", "--quiet", CASES_REPO_URL, repo]);
|
|
9926
|
+
if (clone.status !== 0) {
|
|
9927
|
+
status.step = "clone-failed";
|
|
9928
|
+
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)}`;
|
|
9929
|
+
return status;
|
|
9930
|
+
}
|
|
9931
|
+
status.step = "cloned";
|
|
9932
|
+
}
|
|
9933
|
+
const mcpDir = path9.join(repo, "mcp");
|
|
9934
|
+
if (!await exists2(path9.join(mcpDir, "server.mjs"))) {
|
|
9935
|
+
status.step = "install-failed";
|
|
9936
|
+
status.reason = `\u6848\u4F8B\u5E93\u91CC\u6CA1\u6709 mcp/server.mjs\uFF1A${mcpDir}`;
|
|
9937
|
+
return status;
|
|
9938
|
+
}
|
|
9939
|
+
if (!await exists2(path9.join(mcpDir, "node_modules", "@modelcontextprotocol"))) {
|
|
9940
|
+
const install = deps.npmInstall(mcpDir);
|
|
9941
|
+
if (install.status !== 0) {
|
|
9942
|
+
status.step = "install-failed";
|
|
9943
|
+
status.reason = `npm install \u5931\u8D25\uFF1A${firstLine(install.stderr, install.error)}`;
|
|
9944
|
+
return status;
|
|
9945
|
+
}
|
|
9946
|
+
}
|
|
9947
|
+
status.serverInstalled = true;
|
|
9948
|
+
await fs9.mkdir(path9.dirname(codexConfig), { recursive: true });
|
|
9949
|
+
const existing = await fs9.readFile(codexConfig, "utf8").catch(() => "");
|
|
9950
|
+
const next = mergeCodexMcpConfig(existing, renderCodexMcpSection(repo, envName));
|
|
9951
|
+
if (next !== existing) await fs9.writeFile(codexConfig, next, "utf8");
|
|
9952
|
+
status.codexWired = true;
|
|
9953
|
+
status.ok = true;
|
|
9954
|
+
return status;
|
|
9955
|
+
}
|
|
9956
|
+
async function inspectCaseLibrary(paths = {}) {
|
|
9957
|
+
const repo = paths.repo ?? caseLibraryDir();
|
|
9958
|
+
const codexConfig = paths.codexConfig ?? codexConfigFile();
|
|
9959
|
+
const cloned = await exists2(path9.join(repo, ".git"));
|
|
9960
|
+
const serverInstalled = cloned && await exists2(path9.join(repo, "mcp", "server.mjs")) && await exists2(path9.join(repo, "mcp", "node_modules", "@modelcontextprotocol"));
|
|
9961
|
+
const codexWired = codexConfigHasCases(await fs9.readFile(codexConfig, "utf8").catch(() => ""));
|
|
9962
|
+
return { repo, cloned, serverInstalled, codexWired };
|
|
9963
|
+
}
|
|
9964
|
+
function firstLine(stderr, error) {
|
|
9965
|
+
if (error) return error.message;
|
|
9966
|
+
const line = stderr.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
|
|
9967
|
+
return line ?? "\uFF08\u65E0\u8F93\u51FA\uFF09";
|
|
9968
|
+
}
|
|
9969
|
+
async function exists2(file) {
|
|
9970
|
+
try {
|
|
9971
|
+
await fs9.access(file);
|
|
9972
|
+
return true;
|
|
9973
|
+
} catch {
|
|
9974
|
+
return false;
|
|
9975
|
+
}
|
|
9976
|
+
}
|
|
9977
|
+
|
|
9978
|
+
// src/commands/chiron-init.ts
|
|
9979
|
+
async function probeTokenTenant(envName, requested) {
|
|
9980
|
+
const ctx = await getActiveAuthContextFromCli({ env: envName });
|
|
9981
|
+
const client3 = HcmClient22.fromAuthContext(ctx);
|
|
9982
|
+
const identity2 = await fetchReconIdentity2(httpProbe2(client3.raw(), "default"), requested);
|
|
9983
|
+
return identity2?.tenantId ? String(identity2.tenantId) : void 0;
|
|
9984
|
+
}
|
|
9985
|
+
var defaultChironInitDeps = {
|
|
9986
|
+
tokenTenant: probeTokenTenant,
|
|
9987
|
+
installSkills: async (root, envName) => {
|
|
9988
|
+
const previous = process.cwd();
|
|
9989
|
+
process.chdir(root);
|
|
9990
|
+
try {
|
|
9991
|
+
await skillsInstallCommand(void 0, {
|
|
9992
|
+
all: true,
|
|
9993
|
+
target: "codex",
|
|
9994
|
+
env: envName,
|
|
9995
|
+
dir: path10.join(root, SKILLS_DIR),
|
|
9996
|
+
output: "table"
|
|
9997
|
+
});
|
|
9998
|
+
} finally {
|
|
9999
|
+
process.chdir(previous);
|
|
10000
|
+
}
|
|
10001
|
+
if (process.exitCode && process.exitCode !== 0) {
|
|
10002
|
+
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");
|
|
10003
|
+
}
|
|
10004
|
+
},
|
|
10005
|
+
caseLibrary: (envName) => ensureCaseLibrary(envName)
|
|
10006
|
+
};
|
|
10007
|
+
async function resolveLoggedInEnv() {
|
|
10008
|
+
const g = await loadGlobalConfig10();
|
|
10009
|
+
const name = g.activeEnv;
|
|
10010
|
+
const loginHint = "hcm login https://<\u4F60\u7684 HCM \u5730\u5740> --code <\u914D\u5BF9\u7801>";
|
|
10011
|
+
if (!name) {
|
|
10012
|
+
throw new CliError21({
|
|
10013
|
+
code: CliErrorCode20.ENV_NOT_FOUND,
|
|
10014
|
+
message: `\u8FD8\u6CA1\u767B\u5F55\u4EFB\u4F55\u73AF\u5883\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10015
|
+
});
|
|
10016
|
+
}
|
|
10017
|
+
const config2 = await loadEnv11(name).catch(() => null);
|
|
10018
|
+
if (!config2?.endpoint) {
|
|
10019
|
+
throw new CliError21({
|
|
10020
|
+
code: CliErrorCode20.ENV_NOT_FOUND,
|
|
10021
|
+
message: `\u5F53\u524D\u73AF\u5883 '${name}' \u6CA1\u6709 endpoint\u3002\u5148\u6267\u884C\uFF1A${loginHint}`
|
|
10022
|
+
});
|
|
10023
|
+
}
|
|
10024
|
+
const identities = await listIdentities3(name).catch(() => []);
|
|
10025
|
+
if (identities.length === 0) {
|
|
10026
|
+
throw new CliError21({
|
|
10027
|
+
code: CliErrorCode20.IDENTITY_NOT_FOUND,
|
|
10028
|
+
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>`
|
|
10029
|
+
});
|
|
10030
|
+
}
|
|
10031
|
+
const identity2 = config2.defaultIdentity && identities.includes(config2.defaultIdentity) ? config2.defaultIdentity : identities[0];
|
|
10032
|
+
return { name, env: projectEnvFromConfig(config2), identity: identity2 };
|
|
10033
|
+
}
|
|
10034
|
+
async function scaffoldChironProject(root, env2, envName) {
|
|
10035
|
+
const result = { created: [], updated: [], preserved: [] };
|
|
10036
|
+
const envFile = path10.join(root, ENV_FILE);
|
|
10037
|
+
const existing = await fs10.readFile(envFile, "utf8").catch(() => null);
|
|
10038
|
+
if (existing !== null) {
|
|
10039
|
+
const recorded = parseEnvYaml(existing);
|
|
10040
|
+
if (recorded.endpoint !== env2.endpoint) {
|
|
10041
|
+
throw new CliError21({
|
|
10042
|
+
code: CliErrorCode20.INVALID_ARGUMENT,
|
|
10043
|
+
message: `${ENV_FILE} \u6307\u5411 ${recorded.endpoint}\uFF0C\u800C\u4F60\u5F53\u524D\u767B\u5F55\u7684\u662F ${env2.endpoint}\uFF08env '${envName}'\uFF09\u3002
|
|
10044
|
+
\u8981\u7528\u8FD9\u4E2A\u9879\u76EE\u7684\u73AF\u5883\uFF1Ahcm login ${recorded.endpoint} --code <\u914D\u5BF9\u7801>\uFF0C\u518D\u91CD\u8DD1 hcm chiron init
|
|
10045
|
+
\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`
|
|
10046
|
+
});
|
|
10047
|
+
}
|
|
10048
|
+
if (recorded.tenant !== env2.tenant) {
|
|
10049
|
+
throw new CliError21({
|
|
10050
|
+
code: CliErrorCode20.INVALID_ARGUMENT,
|
|
10051
|
+
message: `${ENV_FILE} \u662F\u79DF\u6237 ${recorded.tenant}\uFF0C\u800C\u4F60\u767B\u5F55\u7684\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${env2.tenant}\u3002
|
|
10052
|
+
\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`
|
|
10053
|
+
});
|
|
10054
|
+
}
|
|
10055
|
+
result.preserved.push(ENV_FILE);
|
|
10056
|
+
} else {
|
|
10057
|
+
await fs10.writeFile(envFile, renderEnvYaml(env2), { encoding: "utf8", mode: 420, flag: "wx" });
|
|
10058
|
+
result.created.push(ENV_FILE);
|
|
10059
|
+
}
|
|
10060
|
+
for (const directory of CHIRON_PROJECT_DIRECTORIES) {
|
|
10061
|
+
const absolute = path10.join(root, directory);
|
|
10062
|
+
await ensureDirectory(absolute);
|
|
10063
|
+
await writeIfAbsent(path10.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
|
|
10064
|
+
}
|
|
10065
|
+
const deliveryDir = path10.join(root, ".hcm-delivery");
|
|
10066
|
+
await ensureDirectory(deliveryDir);
|
|
10067
|
+
await writeIfAbsent(
|
|
10068
|
+
path10.join(deliveryDir, "project.yml"),
|
|
10069
|
+
renderProjectYml(envName, "plan-only"),
|
|
10070
|
+
result,
|
|
10071
|
+
".hcm-delivery/project.yml"
|
|
10072
|
+
);
|
|
10073
|
+
const pageAcceptanceFile = path10.join(root, "page-acceptance.sh");
|
|
10074
|
+
const created = await writeIfAbsent(pageAcceptanceFile, renderPageAcceptanceSh("evidence"), result, "page-acceptance.sh", 493);
|
|
10075
|
+
if (created) await fs10.chmod(pageAcceptanceFile, 493);
|
|
10076
|
+
await mergeManagedFile(path10.join(root, "AGENTS.md"), mergeChironAgentInstructions, result, "AGENTS.md");
|
|
10077
|
+
await mergeManagedFile(path10.join(root, "CLAUDE.md"), mergeChironAgentInstructions, result, "CLAUDE.md");
|
|
10078
|
+
await mergeManagedFile(path10.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
|
|
10079
|
+
return result;
|
|
10080
|
+
}
|
|
10081
|
+
async function runChironInit(args, deps = defaultChironInitDeps) {
|
|
10082
|
+
const root = path10.resolve(args.project ?? ".");
|
|
10083
|
+
const { name, env: env2, identity: identity2 } = await resolveLoggedInEnv();
|
|
10084
|
+
const say = (line) => process.stderr.write(`[chiron init] ${line}
|
|
10085
|
+
`);
|
|
10086
|
+
const actual = await deps.tokenTenant(name, env2.tenant);
|
|
10087
|
+
if (actual && actual !== env2.tenant) {
|
|
10088
|
+
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}`);
|
|
10089
|
+
env2.tenant = actual;
|
|
10090
|
+
}
|
|
10091
|
+
say(`\u73AF\u5883 ${name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant} \xB7 \u8EAB\u4EFD ${identity2}`);
|
|
10092
|
+
const scaffold = await scaffoldChironProject(root, env2, name);
|
|
10093
|
+
say(`\u9AA8\u67B6\uFF1A\u65B0\u5EFA ${scaffold.created.length} \xB7 \u66F4\u65B0 ${scaffold.updated.length} \xB7 \u4FDD\u7559 ${scaffold.preserved.length}`);
|
|
10094
|
+
let skills2 = "skipped";
|
|
10095
|
+
if (!args.skipSkills) {
|
|
10096
|
+
say("\u88C5\u777F\u620E\u6280\u80FD\uFF08\u5168\u90E8\uFF0CCodex \u5E03\u5C40\uFF09\u2026");
|
|
10097
|
+
await deps.installSkills(root, name);
|
|
10098
|
+
skills2 = "installed";
|
|
10099
|
+
}
|
|
10100
|
+
let cases = { ok: false, step: "skipped" };
|
|
10101
|
+
if (!args.skipCases) {
|
|
10102
|
+
say("\u63A5\u6848\u4F8B\u5E93\uFF08chiron-cases MCP\uFF09\u2026");
|
|
10103
|
+
cases = await deps.caseLibrary(name);
|
|
10104
|
+
if (cases.ok) say(`\u6848\u4F8B\u5E93\u5DF2\u63A5\u5165 Codex\uFF1A${cases.repo}`);
|
|
10105
|
+
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}`);
|
|
10106
|
+
}
|
|
10107
|
+
return {
|
|
10108
|
+
project: root,
|
|
10109
|
+
env: name,
|
|
10110
|
+
endpoint: env2.endpoint,
|
|
10111
|
+
frontend: env2.frontend,
|
|
10112
|
+
tenant: env2.tenant,
|
|
10113
|
+
identity: identity2,
|
|
10114
|
+
scaffold,
|
|
10115
|
+
skills: skills2,
|
|
10116
|
+
cases,
|
|
10117
|
+
nextStep: "hcm chiron doctor \u6838\u5BF9\u4E00\u904D\uFF0C\u7136\u540E\u5728\u8FD9\u4E2A\u76EE\u5F55\u91CC\u542F\u52A8 codex"
|
|
10118
|
+
};
|
|
10119
|
+
}
|
|
10120
|
+
async function chironInitCommand(args, deps) {
|
|
10121
|
+
try {
|
|
10122
|
+
const result = await runChironInit(args, deps);
|
|
10123
|
+
const fmt = args.output ?? "table";
|
|
10124
|
+
if (fmt === "json" || fmt === "yaml") {
|
|
10125
|
+
process.stdout.write(formatObject24(result, { format: fmt }) + "\n");
|
|
10126
|
+
} else {
|
|
10127
|
+
process.stdout.write(
|
|
10128
|
+
[
|
|
10129
|
+
`\u2705 \u9879\u76EE\u5DF2\u521D\u59CB\u5316\uFF1A${result.project}`,
|
|
10130
|
+
` \u73AF\u5883 ${result.env} \xB7 ${result.endpoint} \xB7 \u79DF\u6237 ${result.tenant} \xB7 \u8EAB\u4EFD ${result.identity}`,
|
|
10131
|
+
` \u6280\u80FD ${result.skills === "installed" ? `\u5DF2\u88C5\u5230 ${SKILLS_DIR}/` : "\u672A\u88C5\uFF08--skip-skills\uFF09"}`,
|
|
10132
|
+
` \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}`}`,
|
|
10133
|
+
` \u4E0B\u4E00\u6B65\uFF1A${result.nextStep}`
|
|
10134
|
+
].join("\n") + "\n"
|
|
10135
|
+
);
|
|
10136
|
+
}
|
|
10137
|
+
process.exitCode = 0;
|
|
10138
|
+
} catch (e) {
|
|
10139
|
+
exitWithError(e);
|
|
10140
|
+
}
|
|
10141
|
+
}
|
|
10142
|
+
|
|
10143
|
+
// src/commands/chiron-doctor.ts
|
|
10144
|
+
init_auth_guard();
|
|
10145
|
+
init_exit();
|
|
10146
|
+
import { promises as fs11 } from "fs";
|
|
10147
|
+
import path11 from "path";
|
|
10148
|
+
import {
|
|
10149
|
+
HcmClient as HcmClient23,
|
|
10150
|
+
CliError as CliError22,
|
|
10151
|
+
fetchReconIdentity as fetchReconIdentity3,
|
|
10152
|
+
formatObject as formatObject25,
|
|
10153
|
+
httpProbe as httpProbe3,
|
|
10154
|
+
runDoctor as runDoctor2
|
|
10155
|
+
} from "@hcmai/sdk";
|
|
10156
|
+
var defaultDeps = {
|
|
10157
|
+
anchors: async (envName, tenant2) => {
|
|
10158
|
+
const ctx = await getActiveAuthContextFromCli({ env: envName });
|
|
10159
|
+
const client3 = HcmClient23.fromAuthContext(ctx);
|
|
10160
|
+
const probe = httpProbe3(client3.raw(), "default");
|
|
10161
|
+
const identity2 = await fetchReconIdentity3(probe, tenant2);
|
|
10162
|
+
return { report: await runDoctor2(probe, identity2), tokenTenant: identity2?.tenantId ? String(identity2.tenantId) : void 0 };
|
|
10163
|
+
},
|
|
10164
|
+
fixSkills: (root, envName) => defaultChironInitDeps.installSkills(root, envName),
|
|
10165
|
+
fixCases: async (envName) => {
|
|
10166
|
+
await ensureCaseLibrary(envName);
|
|
10167
|
+
},
|
|
10168
|
+
inspectCases: () => inspectCaseLibrary()
|
|
10169
|
+
};
|
|
10170
|
+
async function runChironDoctor(args, deps = defaultDeps) {
|
|
10171
|
+
const root = path11.resolve(args.project ?? ".");
|
|
10172
|
+
const report = { ok: false, project: root, env: null, envName: null, lines: [] };
|
|
10173
|
+
const envText = await fs11.readFile(path11.join(root, ENV_FILE), "utf8").catch(() => null);
|
|
10174
|
+
if (envText === null) {
|
|
10175
|
+
report.lines.push({
|
|
10176
|
+
item: "\u767B\u5F55",
|
|
10177
|
+
verdict: "fail",
|
|
10178
|
+
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`,
|
|
10179
|
+
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"
|
|
10180
|
+
});
|
|
10181
|
+
return finish(report);
|
|
10182
|
+
}
|
|
10183
|
+
let env2;
|
|
10184
|
+
try {
|
|
10185
|
+
env2 = parseEnvYaml(envText);
|
|
10186
|
+
} catch (e) {
|
|
10187
|
+
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}` });
|
|
10188
|
+
return finish(report);
|
|
10189
|
+
}
|
|
10190
|
+
report.env = env2;
|
|
10191
|
+
const found = await findEnvByEndpoint(env2.endpoint);
|
|
10192
|
+
const loginCmd = `hcm login ${env2.endpoint} --code <\u914D\u5BF9\u7801>`;
|
|
10193
|
+
if (!found) {
|
|
10194
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `\u672C\u673A\u6CA1\u6709\u767B\u5F55\u8FC7 ${env2.endpoint}`, nextStep: loginCmd });
|
|
10195
|
+
} else {
|
|
10196
|
+
report.envName = found.name;
|
|
10197
|
+
try {
|
|
10198
|
+
const { report: anchors, tokenTenant } = await deps.anchors(found.name, env2.tenant);
|
|
10199
|
+
report.anchors = anchors;
|
|
10200
|
+
const tenantMismatch = tokenTenant && tokenTenant !== env2.tenant;
|
|
10201
|
+
const bad = anchors.checks.filter((c) => !c.ok && !(tenantMismatch && c.anchor === "identity"));
|
|
10202
|
+
if (bad.length === 0 && !tenantMismatch) {
|
|
10203
|
+
const who = found.config.defaultIdentity ? ` \xB7 ${found.config.defaultIdentity}` : "";
|
|
10204
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "ok", detail: `${found.name} \xB7 ${env2.endpoint} \xB7 \u79DF\u6237 ${env2.tenant}${who}` });
|
|
10205
|
+
} else {
|
|
10206
|
+
const parts = [`${found.name} \xB7 ${env2.endpoint}`];
|
|
10207
|
+
if (tenantMismatch) parts.push(`\u4F60\u7684\u767B\u5F55\u8EAB\u4EFD\u5C5E\u4E8E\u79DF\u6237 ${tokenTenant}\uFF0C\u9879\u76EE\u662F\u79DF\u6237 ${env2.tenant}`);
|
|
10208
|
+
if (bad.length) parts.push(`\u951A\u70B9\u672A\u8FC7\uFF1A${bad.map((c) => `${c.anchor}\uFF08${c.detail}\uFF09`).join("\u3001")}`);
|
|
10209
|
+
report.lines.push({
|
|
10210
|
+
item: "\u767B\u5F55",
|
|
10211
|
+
verdict: "fail",
|
|
10212
|
+
detail: parts.join("\uFF1B"),
|
|
10213
|
+
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
|
|
10214
|
+
});
|
|
10215
|
+
}
|
|
10216
|
+
} catch (e) {
|
|
10217
|
+
const msg = e instanceof CliError22 ? e.message : e.message;
|
|
10218
|
+
report.lines.push({ item: "\u767B\u5F55", verdict: "fail", detail: `${found.name} \xB7 ${env2.endpoint}\uFF1A${msg}`, nextStep: loginCmd });
|
|
10219
|
+
}
|
|
10220
|
+
}
|
|
10221
|
+
const skillsLine = async () => {
|
|
10222
|
+
const state = await readSkillsState(path11.join(root, SKILLS_DIR));
|
|
10223
|
+
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" };
|
|
10224
|
+
const count = Object.keys(state.skills).length;
|
|
10225
|
+
if (state.endpoint && normalizeOrigin(state.endpoint) !== env2.endpoint) {
|
|
10226
|
+
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" };
|
|
10227
|
+
}
|
|
10228
|
+
if (state.target !== "codex") {
|
|
10229
|
+
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" };
|
|
10230
|
+
}
|
|
10231
|
+
return { item: "\u6280\u80FD", verdict: "ok", detail: `${count} \u4E2A\uFF0C\u6765\u81EA ${state.endpoint ?? "\u672C\u5730"}${state.all ? "\uFF0C\u8DDF\u968F\u5168\u96C6" : ""}` };
|
|
10232
|
+
};
|
|
10233
|
+
let skills2 = await skillsLine();
|
|
10234
|
+
if (skills2.verdict === "fail" && args.fix && report.envName) {
|
|
10235
|
+
await deps.fixSkills(root, report.envName);
|
|
10236
|
+
skills2 = await skillsLine();
|
|
10237
|
+
}
|
|
10238
|
+
report.lines.push(skills2);
|
|
10239
|
+
const casesLine = async () => {
|
|
10240
|
+
const c = await deps.inspectCases();
|
|
10241
|
+
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" };
|
|
10242
|
+
if (!c.serverInstalled) return { item: "\u6848\u4F8B\u5E93", verdict: "warn", detail: "MCP \u4F9D\u8D56\u6CA1\u88C5", nextStep: "hcm chiron doctor --fix" };
|
|
10243
|
+
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" };
|
|
10244
|
+
return { item: "\u6848\u4F8B\u5E93", verdict: "ok", detail: `\u5DF2\u63A5\u5165 Codex\uFF08${c.repo}\uFF09` };
|
|
10245
|
+
};
|
|
10246
|
+
let cases = await casesLine();
|
|
10247
|
+
if (cases.verdict !== "ok" && args.fix && report.envName) {
|
|
10248
|
+
await deps.fixCases(report.envName);
|
|
10249
|
+
cases = await casesLine();
|
|
10250
|
+
}
|
|
10251
|
+
report.lines.push(cases);
|
|
10252
|
+
return finish(report);
|
|
10253
|
+
}
|
|
10254
|
+
function finish(report) {
|
|
10255
|
+
report.ok = report.lines.every((l) => l.verdict !== "fail");
|
|
10256
|
+
return report;
|
|
10257
|
+
}
|
|
10258
|
+
function renderChironDoctor(report) {
|
|
10259
|
+
const mark = { ok: "\u2705", warn: "\u26A0\uFE0F", fail: "\u274C" };
|
|
10260
|
+
const out = [];
|
|
10261
|
+
for (const l of report.lines) {
|
|
10262
|
+
out.push(`${mark[l.verdict]} ${l.item.padEnd(3, "\u3000")} ${l.detail}`);
|
|
10263
|
+
if (l.nextStep && l.verdict !== "ok") out.push(` \u2192 ${l.nextStep}`);
|
|
10264
|
+
}
|
|
10265
|
+
out.push("");
|
|
10266
|
+
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");
|
|
10267
|
+
return out.join("\n");
|
|
10268
|
+
}
|
|
10269
|
+
async function chironDoctorCommand(args, deps) {
|
|
10270
|
+
try {
|
|
10271
|
+
const report = await runChironDoctor(args, deps);
|
|
10272
|
+
const fmt = args.output ?? "table";
|
|
10273
|
+
if (fmt === "json" || fmt === "yaml") process.stdout.write(formatObject25(report, { format: fmt }) + "\n");
|
|
10274
|
+
else process.stdout.write(renderChironDoctor(report) + "\n");
|
|
10275
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
10276
|
+
} catch (e) {
|
|
10277
|
+
exitWithError(e);
|
|
10278
|
+
}
|
|
10279
|
+
}
|
|
10280
|
+
|
|
10281
|
+
// src/commands/delivery-recon.ts
|
|
10282
|
+
init_auth_guard();
|
|
10283
|
+
init_exit();
|
|
10284
|
+
import {
|
|
10285
|
+
HcmClient as HcmClient24,
|
|
9738
10286
|
ReconLayout,
|
|
9739
10287
|
ROUND_EXIT_CODES,
|
|
9740
10288
|
computeReconSourceKey,
|
|
9741
|
-
formatObject as
|
|
10289
|
+
formatObject as formatObject26,
|
|
9742
10290
|
fromAxiosError as fromAxiosError22,
|
|
9743
|
-
httpProbe as
|
|
10291
|
+
httpProbe as httpProbe4,
|
|
9744
10292
|
inspectRound,
|
|
9745
10293
|
renderRound,
|
|
9746
10294
|
runRecon
|
|
@@ -9749,8 +10297,8 @@ var DEFAULT_CAPABILITIES2 = "default";
|
|
|
9749
10297
|
async function deliveryReconCommand(args) {
|
|
9750
10298
|
try {
|
|
9751
10299
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
9752
|
-
const client3 =
|
|
9753
|
-
const probe =
|
|
10300
|
+
const client3 = HcmClient24.fromAuthContext(ctx);
|
|
10301
|
+
const probe = httpProbe4(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES2);
|
|
9754
10302
|
const sourceKey = await computeReconSourceKey(probe);
|
|
9755
10303
|
const layout = new ReconLayout(args.out ?? ".", ctx.tenantId, sourceKey);
|
|
9756
10304
|
const summary = await runRecon(probe, layout, {
|
|
@@ -9758,7 +10306,7 @@ async function deliveryReconCommand(args) {
|
|
|
9758
10306
|
onlyModel: args.model ?? null,
|
|
9759
10307
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
9760
10308
|
});
|
|
9761
|
-
process.stdout.write(
|
|
10309
|
+
process.stdout.write(formatObject26(summary, { format: args.output ?? "json" }) + "\n");
|
|
9762
10310
|
} catch (e) {
|
|
9763
10311
|
const err = e;
|
|
9764
10312
|
if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
|
|
@@ -9772,7 +10320,7 @@ async function deliveryReconRoundCommand(args) {
|
|
|
9772
10320
|
const result = inspectRound(args.dir ?? ".");
|
|
9773
10321
|
const fmt = args.output ?? "json";
|
|
9774
10322
|
if (fmt !== "json") process.stdout.write(renderRound(result));
|
|
9775
|
-
process.stdout.write(
|
|
10323
|
+
process.stdout.write(formatObject26(result, { format: fmt }) + "\n");
|
|
9776
10324
|
code = ROUND_EXIT_CODES[result.state];
|
|
9777
10325
|
} catch (e) {
|
|
9778
10326
|
exitWithError(e);
|
|
@@ -9791,14 +10339,14 @@ import {
|
|
|
9791
10339
|
GAP_REASONS,
|
|
9792
10340
|
deriveAclass,
|
|
9793
10341
|
exitCode as gate0ExitCode,
|
|
9794
|
-
formatObject as
|
|
10342
|
+
formatObject as formatObject27,
|
|
9795
10343
|
inspectRound as inspectRound2,
|
|
9796
10344
|
loadProtocolFacts,
|
|
9797
10345
|
scan
|
|
9798
10346
|
} from "@hcmai/sdk";
|
|
9799
|
-
import * as
|
|
10347
|
+
import * as path12 from "path";
|
|
9800
10348
|
function renderGate0(result, skillRoot) {
|
|
9801
|
-
const where = skillRoot ? `\uFF08${
|
|
10349
|
+
const where = skillRoot ? `\uFF08${path12.resolve(skillRoot)}\uFF09` : "";
|
|
9802
10350
|
const lines = [
|
|
9803
10351
|
`\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
10352
|
];
|
|
@@ -9836,7 +10384,7 @@ async function deliveryGate0Command(args) {
|
|
|
9836
10384
|
const merged = { ...result, premise: premise5 };
|
|
9837
10385
|
const fmt = args.output ?? "json";
|
|
9838
10386
|
if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
|
|
9839
|
-
process.stdout.write(`${
|
|
10387
|
+
process.stdout.write(`${formatObject27(merged, { format: fmt })}
|
|
9840
10388
|
`);
|
|
9841
10389
|
for (const problem of premise5) {
|
|
9842
10390
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
|
|
@@ -9861,8 +10409,8 @@ import {
|
|
|
9861
10409
|
DRY_RUN_TAIL,
|
|
9862
10410
|
DriftDetected,
|
|
9863
10411
|
FORCE_STALE_FLAG,
|
|
9864
|
-
HcmClient as
|
|
9865
|
-
fetchReconIdentity as
|
|
10412
|
+
HcmClient as HcmClient25,
|
|
10413
|
+
fetchReconIdentity as fetchReconIdentity4,
|
|
9866
10414
|
INIT_EXIT_CODES,
|
|
9867
10415
|
JOURNAL_STOP_KINDS,
|
|
9868
10416
|
JOURNAL_STOP_UNKNOWN,
|
|
@@ -9911,7 +10459,7 @@ import {
|
|
|
9911
10459
|
writeRisk
|
|
9912
10460
|
} from "@hcmai/sdk";
|
|
9913
10461
|
import { existsSync as existsSync3 } from "fs";
|
|
9914
|
-
import * as
|
|
10462
|
+
import * as path13 from "path";
|
|
9915
10463
|
function premise(message, hint = "") {
|
|
9916
10464
|
process.stderr.write(message + (hint ? `
|
|
9917
10465
|
\u2192 ${hint}` : "") + "\n");
|
|
@@ -9938,13 +10486,13 @@ async function runSeedPlan(args, client3) {
|
|
|
9938
10486
|
const reconDir = candidates[0].reconDir;
|
|
9939
10487
|
if (candidates.length > 1) {
|
|
9940
10488
|
process.stderr.write(
|
|
9941
|
-
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${
|
|
10489
|
+
`\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
10490
|
);
|
|
9943
10491
|
}
|
|
9944
10492
|
const round = inspectRound3(reconDir);
|
|
9945
10493
|
process.stderr.write(roundWarning(round));
|
|
9946
10494
|
const baseline = {
|
|
9947
|
-
path: `${
|
|
10495
|
+
path: `${path13.basename(path13.dirname(reconDir))}/${path13.basename(reconDir)}`,
|
|
9948
10496
|
roundId: round.roundId ?? null
|
|
9949
10497
|
};
|
|
9950
10498
|
let exemptions = null;
|
|
@@ -10001,7 +10549,7 @@ async function authOrSignpost(args, cmd) {
|
|
|
10001
10549
|
}
|
|
10002
10550
|
async function deliverySeedPlanCommand(args) {
|
|
10003
10551
|
const ctx = await authOrSignpost(args, "plan");
|
|
10004
|
-
const client3 =
|
|
10552
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10005
10553
|
process.exitCode = await runSeedPlan(args, seedClient(client3, ctx));
|
|
10006
10554
|
}
|
|
10007
10555
|
function seedClient(client3, ctx) {
|
|
@@ -10037,7 +10585,7 @@ function seedClient(client3, ctx) {
|
|
|
10037
10585
|
}
|
|
10038
10586
|
async function seedVerifyClient(client3, ctx) {
|
|
10039
10587
|
const base = seedClient(client3, ctx);
|
|
10040
|
-
const identity2 = await
|
|
10588
|
+
const identity2 = await fetchReconIdentity4(base, String(ctx.tenantId ?? ""));
|
|
10041
10589
|
return { ...base, identity: identity2 };
|
|
10042
10590
|
}
|
|
10043
10591
|
function lowerCaseHeaders(headers) {
|
|
@@ -10175,7 +10723,7 @@ async function runSeedApply(args, client3) {
|
|
|
10175
10723
|
}
|
|
10176
10724
|
async function deliverySeedApplyCommand(args) {
|
|
10177
10725
|
const ctx = await authOrSignpost(args, "apply");
|
|
10178
|
-
const client3 =
|
|
10726
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10179
10727
|
process.exitCode = await runSeedApply(args, seedClient(client3, ctx));
|
|
10180
10728
|
}
|
|
10181
10729
|
async function runSeedVerify(args, client3) {
|
|
@@ -10199,14 +10747,14 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
10199
10747
|
return;
|
|
10200
10748
|
}
|
|
10201
10749
|
const ctx = await authOrSignpost(args, "verify");
|
|
10202
|
-
const client3 =
|
|
10750
|
+
const client3 = HcmClient25.fromAuthContext(ctx);
|
|
10203
10751
|
process.exitCode = await runSeedVerify(args, await seedVerifyClient(client3, ctx));
|
|
10204
10752
|
}
|
|
10205
10753
|
|
|
10206
10754
|
// src/commands/delivery-seed-find.ts
|
|
10207
10755
|
import { existsSync as existsSync4 } from "fs";
|
|
10208
10756
|
import { readFileSync as readFileSync6 } from "fs";
|
|
10209
|
-
import * as
|
|
10757
|
+
import * as path14 from "path";
|
|
10210
10758
|
import {
|
|
10211
10759
|
INIT_EXIT_CODES as INIT_EXIT_CODES2,
|
|
10212
10760
|
ValueHints,
|
|
@@ -10220,10 +10768,10 @@ import {
|
|
|
10220
10768
|
valuesRoundCaveat
|
|
10221
10769
|
} from "@hcmai/sdk";
|
|
10222
10770
|
function provenance(chosenReconDir, others) {
|
|
10223
|
-
let line = `> \u57FA\u7EBF\uFF1A\`${
|
|
10771
|
+
let line = `> \u57FA\u7EBF\uFF1A\`${path14.basename(chosenReconDir)}\`
|
|
10224
10772
|
`;
|
|
10225
10773
|
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) => `\`${
|
|
10774
|
+
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
10775
|
}
|
|
10228
10776
|
return `${line}
|
|
10229
10777
|
`;
|
|
@@ -10314,7 +10862,7 @@ import {
|
|
|
10314
10862
|
CHANGE_STATES,
|
|
10315
10863
|
CHANGE_UNKNOWN,
|
|
10316
10864
|
CODE_WORDS,
|
|
10317
|
-
HcmClient as
|
|
10865
|
+
HcmClient as HcmClient26,
|
|
10318
10866
|
INIT_EXIT_CODES as INIT_EXIT_CODES3,
|
|
10319
10867
|
META_WRITE_STEPS,
|
|
10320
10868
|
META_VERIFY_STEPS,
|
|
@@ -10542,7 +11090,7 @@ function lowerCaseHeaders2(headers) {
|
|
|
10542
11090
|
}
|
|
10543
11091
|
async function deliveryMetaCommand(args) {
|
|
10544
11092
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
10545
|
-
const client3 =
|
|
11093
|
+
const client3 = HcmClient26.fromAuthContext(ctx);
|
|
10546
11094
|
process.exitCode = await runDeliveryMeta(
|
|
10547
11095
|
{ ...args, tenant: args.tenant ?? String(ctx.tenantId ?? "") },
|
|
10548
11096
|
metaClient(client3, ctx)
|
|
@@ -10554,13 +11102,13 @@ init_auth_guard();
|
|
|
10554
11102
|
init_exit();
|
|
10555
11103
|
import {
|
|
10556
11104
|
computeReconSourceKey as computeReconSourceKey2,
|
|
10557
|
-
HcmClient as
|
|
10558
|
-
httpProbe as
|
|
11105
|
+
HcmClient as HcmClient27,
|
|
11106
|
+
httpProbe as httpProbe5,
|
|
10559
11107
|
ReconLayout as ReconLayout2,
|
|
10560
11108
|
runTriageRound
|
|
10561
11109
|
} from "@hcmai/sdk";
|
|
10562
11110
|
import { mkdirSync, readFileSync as readFileSync8, writeFileSync as writeFileSync2 } from "fs";
|
|
10563
|
-
import * as
|
|
11111
|
+
import * as path15 from "path";
|
|
10564
11112
|
var DEFAULT_CAPABILITIES4 = "default";
|
|
10565
11113
|
function premise4(message, hint) {
|
|
10566
11114
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
|
|
@@ -10596,8 +11144,8 @@ function renderProblems(rows) {
|
|
|
10596
11144
|
`;
|
|
10597
11145
|
}
|
|
10598
11146
|
function writeTriageArtifact(outDir, body) {
|
|
10599
|
-
const out =
|
|
10600
|
-
mkdirSync(
|
|
11147
|
+
const out = path15.join(outDir, "work", "triage.md");
|
|
11148
|
+
mkdirSync(path15.dirname(out), { recursive: true });
|
|
10601
11149
|
writeFileSync2(out, body, "utf8");
|
|
10602
11150
|
return out;
|
|
10603
11151
|
}
|
|
@@ -10610,8 +11158,8 @@ async function runTriage(args) {
|
|
|
10610
11158
|
return premise4(e instanceof Error ? e.message : String(e), REQUESTS_SHAPE);
|
|
10611
11159
|
}
|
|
10612
11160
|
const ctx = await getActiveAuthContextFromCli(args);
|
|
10613
|
-
const client3 =
|
|
10614
|
-
const probe =
|
|
11161
|
+
const client3 = HcmClient27.fromAuthContext(ctx);
|
|
11162
|
+
const probe = httpProbe5(client3.raw(), args.capabilities ?? DEFAULT_CAPABILITIES4);
|
|
10615
11163
|
const artifactsDir = args.recon ?? new ReconLayout2(args.out ?? ".", ctx.tenantId, await computeReconSourceKey2(probe)).dir;
|
|
10616
11164
|
const result = await runTriageRound(probe, artifactsDir, entriesIn);
|
|
10617
11165
|
if (result.body === null) {
|
|
@@ -10638,9 +11186,9 @@ async function deliveryTriageCommand(args) {
|
|
|
10638
11186
|
// src/commands/delivery-execution.ts
|
|
10639
11187
|
import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
|
|
10640
11188
|
import { spawn as spawn2 } from "child_process";
|
|
10641
|
-
import { createReadStream, promises as
|
|
10642
|
-
import
|
|
10643
|
-
import { CliError as
|
|
11189
|
+
import { createReadStream, promises as fs12 } from "fs";
|
|
11190
|
+
import path16 from "path";
|
|
11191
|
+
import { CliError as CliError23, CliErrorCode as CliErrorCode21, formatObject as formatObject28 } from "@hcmai/sdk";
|
|
10644
11192
|
init_exit();
|
|
10645
11193
|
var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
|
|
10646
11194
|
var DEFAULT_TTL_SECONDS = 15 * 60;
|
|
@@ -10682,11 +11230,11 @@ async function prepareDeliveryExecution(input) {
|
|
|
10682
11230
|
};
|
|
10683
11231
|
const planId = sha2565(canonicalJson(core)).slice(0, 24);
|
|
10684
11232
|
const plan = { ...core, planId };
|
|
10685
|
-
const plansDir =
|
|
11233
|
+
const plansDir = path16.join(project, ".hcm-delivery", "execution-plans");
|
|
10686
11234
|
await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
|
|
10687
|
-
const planFile =
|
|
11235
|
+
const planFile = path16.join(plansDir, `${planId}.json`);
|
|
10688
11236
|
try {
|
|
10689
|
-
await
|
|
11237
|
+
await fs12.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
|
|
10690
11238
|
`, {
|
|
10691
11239
|
encoding: "utf8",
|
|
10692
11240
|
mode: 384,
|
|
@@ -10700,7 +11248,7 @@ async function prepareDeliveryExecution(input) {
|
|
|
10700
11248
|
async function executeDeliveryPlan(input) {
|
|
10701
11249
|
if (!PLAN_ID_PATTERN.test(input.planId)) throw invalid2("planId \u5FC5\u987B\u662F 24 \u4F4D\u5C0F\u5199\u5341\u516D\u8FDB\u5236");
|
|
10702
11250
|
const project = await realProject(input.project);
|
|
10703
|
-
const planFile =
|
|
11251
|
+
const planFile = path16.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
10704
11252
|
const plan = await readPlan(project, planFile);
|
|
10705
11253
|
if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
|
|
10706
11254
|
throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
|
|
@@ -10737,13 +11285,13 @@ async function executeDeliveryPlan(input) {
|
|
|
10737
11285
|
await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
|
|
10738
11286
|
await assertPayloadsUnchanged(project, plan.payloads);
|
|
10739
11287
|
const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
|
|
10740
|
-
const receiptFile =
|
|
11288
|
+
const receiptFile = path16.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
|
|
10741
11289
|
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 =
|
|
11290
|
+
const claimsDir = path16.join(project, ".hcm-delivery", "execution-claims");
|
|
10743
11291
|
await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
|
|
10744
|
-
const claimFile =
|
|
11292
|
+
const claimFile = path16.join(claimsDir, `${plan.planId}.json`);
|
|
10745
11293
|
try {
|
|
10746
|
-
await
|
|
11294
|
+
await fs12.writeFile(
|
|
10747
11295
|
claimFile,
|
|
10748
11296
|
`${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
|
|
10749
11297
|
`,
|
|
@@ -10800,7 +11348,7 @@ async function deliveryPrepareCommand(argv, args) {
|
|
|
10800
11348
|
evidenceDir: args.evidenceDir,
|
|
10801
11349
|
...ttlSeconds === void 0 ? {} : { ttlSeconds }
|
|
10802
11350
|
});
|
|
10803
|
-
process.stdout.write(
|
|
11351
|
+
process.stdout.write(formatObject28(plan, { format: args.output ?? "json" }) + "\n");
|
|
10804
11352
|
process.stderr.write(`
|
|
10805
11353
|
\u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
|
|
10806
11354
|
${nextCommandHint(plan.planId, args.project, argv)}
|
|
@@ -10827,11 +11375,11 @@ async function deliveryExecuteCommand(planId, argv, args) {
|
|
|
10827
11375
|
}
|
|
10828
11376
|
}
|
|
10829
11377
|
function writeDeliveryExecutionReceipt(receipt, format = "json") {
|
|
10830
|
-
process.stderr.write(
|
|
11378
|
+
process.stderr.write(formatObject28(receipt, { format }) + "\n");
|
|
10831
11379
|
process.exitCode = receipt.exitCode;
|
|
10832
11380
|
}
|
|
10833
11381
|
async function readProjectMode(project, environment) {
|
|
10834
|
-
const file =
|
|
11382
|
+
const file = path16.join(project, ".hcm-delivery", "project.yml");
|
|
10835
11383
|
const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
|
|
10836
11384
|
let mode;
|
|
10837
11385
|
try {
|
|
@@ -10847,13 +11395,13 @@ async function readProjectMode(project, environment) {
|
|
|
10847
11395
|
return mode;
|
|
10848
11396
|
}
|
|
10849
11397
|
var SKILLS_LOCK_CANDIDATES = [
|
|
10850
|
-
|
|
10851
|
-
|
|
11398
|
+
path16.join("hcm-skills", ".hcm-skills.json"),
|
|
11399
|
+
path16.join(".claude", "skills", ".hcm-skills.json")
|
|
10852
11400
|
];
|
|
10853
11401
|
async function readSkillsLock(project) {
|
|
10854
11402
|
const found = [];
|
|
10855
11403
|
for (const candidate of SKILLS_LOCK_CANDIDATES) {
|
|
10856
|
-
if (await pathExists(
|
|
11404
|
+
if (await pathExists(path16.join(project, candidate))) found.push(candidate);
|
|
10857
11405
|
}
|
|
10858
11406
|
if (found.length === 0) {
|
|
10859
11407
|
throw invalid2(
|
|
@@ -10865,7 +11413,7 @@ async function readSkillsLock(project) {
|
|
|
10865
11413
|
`\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
11414
|
);
|
|
10867
11415
|
}
|
|
10868
|
-
const bytes = await readSafeFile(project,
|
|
11416
|
+
const bytes = await readSafeFile(project, path16.join(project, found[0]), "\u6280\u80FD\u9501");
|
|
10869
11417
|
try {
|
|
10870
11418
|
JSON.parse(bytes.toString("utf8"));
|
|
10871
11419
|
} catch (cause) {
|
|
@@ -10878,7 +11426,7 @@ async function bindDocument(project, reference, label) {
|
|
|
10878
11426
|
if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
|
|
10879
11427
|
throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
|
|
10880
11428
|
}
|
|
10881
|
-
const file =
|
|
11429
|
+
const file = path16.join(project, relative2);
|
|
10882
11430
|
const bytes = await readSafeFile(project, file, label);
|
|
10883
11431
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
10884
11432
|
}
|
|
@@ -10891,11 +11439,11 @@ async function bindEvidenceDirectory(project, reference) {
|
|
|
10891
11439
|
if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
|
|
10892
11440
|
throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
|
|
10893
11441
|
}
|
|
10894
|
-
const absolute =
|
|
11442
|
+
const absolute = path16.join(project, relative2);
|
|
10895
11443
|
await assertNoSymlinkComponents(project, relative2);
|
|
10896
|
-
const stat = await
|
|
11444
|
+
const stat = await fs12.stat(absolute).catch(() => null);
|
|
10897
11445
|
if (stat === null) {
|
|
10898
|
-
await
|
|
11446
|
+
await fs12.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
|
|
10899
11447
|
throw invalid2(
|
|
10900
11448
|
`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
11449
|
cause
|
|
@@ -11075,7 +11623,7 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
11075
11623
|
const relative2 = safeRelative(reference, label);
|
|
11076
11624
|
let stat;
|
|
11077
11625
|
try {
|
|
11078
|
-
stat = await
|
|
11626
|
+
stat = await fs12.stat(path16.join(project, relative2));
|
|
11079
11627
|
} catch (cause) {
|
|
11080
11628
|
throw invalid2(
|
|
11081
11629
|
`${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 +11634,10 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
11086
11634
|
}
|
|
11087
11635
|
async function bindPayloadDirectory(project, reference, label) {
|
|
11088
11636
|
const relative2 = reference === "." ? "." : safeRelative(reference, label);
|
|
11089
|
-
const root =
|
|
11637
|
+
const root = path16.join(project, relative2);
|
|
11090
11638
|
let stat;
|
|
11091
11639
|
try {
|
|
11092
|
-
stat = await
|
|
11640
|
+
stat = await fs12.stat(root);
|
|
11093
11641
|
} catch {
|
|
11094
11642
|
throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
|
|
11095
11643
|
}
|
|
@@ -11099,10 +11647,10 @@ async function bindPayloadDirectory(project, reference, label) {
|
|
|
11099
11647
|
const skipToolingAtRoot = relative2 === ".";
|
|
11100
11648
|
const entries = [];
|
|
11101
11649
|
const walk = async (dir, prefix) => {
|
|
11102
|
-
const items = await
|
|
11650
|
+
const items = await fs12.readdir(dir, { withFileTypes: true });
|
|
11103
11651
|
for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
11104
11652
|
if (skipToolingAtRoot && prefix === "" && TOOLING_DIRS.includes(item.name)) continue;
|
|
11105
|
-
const child =
|
|
11653
|
+
const child = path16.join(dir, item.name);
|
|
11106
11654
|
const rel = prefix ? `${prefix}/${item.name}` : item.name;
|
|
11107
11655
|
if (item.isSymbolicLink()) {
|
|
11108
11656
|
throw invalid2(
|
|
@@ -11127,7 +11675,7 @@ ${sha2565(bytes)}`);
|
|
|
11127
11675
|
}
|
|
11128
11676
|
async function bindPayloadFile(project, reference, label) {
|
|
11129
11677
|
const relative2 = safeRelative(reference, label);
|
|
11130
|
-
const file =
|
|
11678
|
+
const file = path16.join(project, relative2);
|
|
11131
11679
|
const bytes = await readSafeFile(project, file, label);
|
|
11132
11680
|
return { path: relative2, kind: "file", sha256: sha2565(bytes) };
|
|
11133
11681
|
}
|
|
@@ -11190,29 +11738,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
|
|
|
11190
11738
|
async function writeReceiptExclusive(target, receipt) {
|
|
11191
11739
|
const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
11192
11740
|
try {
|
|
11193
|
-
await
|
|
11741
|
+
await fs12.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
|
|
11194
11742
|
`, {
|
|
11195
11743
|
encoding: "utf8",
|
|
11196
11744
|
mode: 384,
|
|
11197
11745
|
flag: "wx"
|
|
11198
11746
|
});
|
|
11199
|
-
await
|
|
11747
|
+
await fs12.link(temp, target);
|
|
11200
11748
|
} catch (cause) {
|
|
11201
|
-
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${
|
|
11749
|
+
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path16.basename(target)}`, cause);
|
|
11202
11750
|
} finally {
|
|
11203
|
-
await
|
|
11751
|
+
await fs12.unlink(temp).catch(() => void 0);
|
|
11204
11752
|
}
|
|
11205
11753
|
}
|
|
11206
11754
|
async function safeManagedDirectory(project, relative2, absolute) {
|
|
11207
|
-
await assertNoSymlinkComponents(project,
|
|
11208
|
-
const existing = await
|
|
11755
|
+
await assertNoSymlinkComponents(project, path16.dirname(relative2));
|
|
11756
|
+
const existing = await fs12.lstat(absolute).catch(() => void 0);
|
|
11209
11757
|
if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11210
11758
|
if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
11211
|
-
if (!existing) await
|
|
11212
|
-
await
|
|
11759
|
+
if (!existing) await fs12.mkdir(absolute, { mode: 448 });
|
|
11760
|
+
await fs12.chmod(absolute, 448);
|
|
11213
11761
|
}
|
|
11214
11762
|
async function pathExists(file) {
|
|
11215
|
-
return
|
|
11763
|
+
return fs12.lstat(file).then(
|
|
11216
11764
|
() => true,
|
|
11217
11765
|
(cause) => {
|
|
11218
11766
|
if (cause.code === "ENOENT") return false;
|
|
@@ -11221,47 +11769,47 @@ async function pathExists(file) {
|
|
|
11221
11769
|
);
|
|
11222
11770
|
}
|
|
11223
11771
|
async function readSafeFile(project, file, label) {
|
|
11224
|
-
const relative2 =
|
|
11225
|
-
if (relative2.startsWith("../") ||
|
|
11772
|
+
const relative2 = path16.relative(project, file).split(path16.sep).join("/");
|
|
11773
|
+
if (relative2.startsWith("../") || path16.isAbsolute(relative2))
|
|
11226
11774
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
11227
11775
|
await assertNoSymlinkComponents(project, relative2);
|
|
11228
11776
|
let stat;
|
|
11229
11777
|
try {
|
|
11230
|
-
stat = await
|
|
11778
|
+
stat = await fs12.lstat(file);
|
|
11231
11779
|
} catch (cause) {
|
|
11232
11780
|
throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
|
|
11233
11781
|
}
|
|
11234
11782
|
if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11235
11783
|
if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
|
|
11236
|
-
return
|
|
11784
|
+
return fs12.readFile(file);
|
|
11237
11785
|
}
|
|
11238
11786
|
async function assertNoSymlinkComponents(project, relative2) {
|
|
11239
11787
|
const parts = relative2.split("/").filter(Boolean);
|
|
11240
11788
|
let current = project;
|
|
11241
11789
|
for (const part of parts) {
|
|
11242
|
-
current =
|
|
11243
|
-
const stat = await
|
|
11790
|
+
current = path16.join(current, part);
|
|
11791
|
+
const stat = await fs12.lstat(current).catch(() => void 0);
|
|
11244
11792
|
if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
11245
11793
|
if (!stat) break;
|
|
11246
11794
|
}
|
|
11247
11795
|
}
|
|
11248
11796
|
async function realProject(requested) {
|
|
11249
|
-
const absolute =
|
|
11797
|
+
const absolute = path16.resolve(requested);
|
|
11250
11798
|
let project;
|
|
11251
11799
|
try {
|
|
11252
|
-
project = await
|
|
11800
|
+
project = await fs12.realpath(absolute);
|
|
11253
11801
|
} catch (cause) {
|
|
11254
11802
|
throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
|
|
11255
11803
|
}
|
|
11256
|
-
const stat = await
|
|
11804
|
+
const stat = await fs12.stat(project);
|
|
11257
11805
|
if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
|
|
11258
11806
|
return project;
|
|
11259
11807
|
}
|
|
11260
11808
|
function safeRelative(reference, label) {
|
|
11261
|
-
if (!reference ||
|
|
11809
|
+
if (!reference || path16.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
|
|
11262
11810
|
throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
|
|
11263
11811
|
}
|
|
11264
|
-
const normalized =
|
|
11812
|
+
const normalized = path16.normalize(reference).split(path16.sep).join("/");
|
|
11265
11813
|
if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
|
|
11266
11814
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
11267
11815
|
}
|
|
@@ -11314,7 +11862,7 @@ async function sha256File(file) {
|
|
|
11314
11862
|
return hash.digest("hex");
|
|
11315
11863
|
}
|
|
11316
11864
|
function invalid2(message, cause) {
|
|
11317
|
-
return new
|
|
11865
|
+
return new CliError23({ code: CliErrorCode21.INVALID_ARGUMENT, message, cause });
|
|
11318
11866
|
}
|
|
11319
11867
|
function nextCommandHint(planId, project, argv) {
|
|
11320
11868
|
const quoted = argv.map((a) => /[\s"'$`\\]/.test(a) ? `'${a.replace(/'/g, `'\\''`)}'` : a);
|
|
@@ -11326,25 +11874,25 @@ function nextCommandHint(planId, project, argv) {
|
|
|
11326
11874
|
init_auth_guard();
|
|
11327
11875
|
init_exit();
|
|
11328
11876
|
import {
|
|
11329
|
-
HcmClient as
|
|
11877
|
+
HcmClient as HcmClient28,
|
|
11330
11878
|
adminResetPassword,
|
|
11331
|
-
formatObject as
|
|
11879
|
+
formatObject as formatObject29,
|
|
11332
11880
|
fromAxiosError as fromAxiosError23,
|
|
11333
|
-
CliError as
|
|
11334
|
-
CliErrorCode as
|
|
11881
|
+
CliError as CliError24,
|
|
11882
|
+
CliErrorCode as CliErrorCode22
|
|
11335
11883
|
} from "@hcmai/sdk";
|
|
11336
11884
|
function buildAdminResetPasswordRequest(args, password) {
|
|
11337
11885
|
const hasId = Boolean(args.id);
|
|
11338
11886
|
const hasUsername = Boolean(args.username);
|
|
11339
11887
|
if (hasId === hasUsername) {
|
|
11340
|
-
throw new
|
|
11341
|
-
code:
|
|
11888
|
+
throw new CliError24({
|
|
11889
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11342
11890
|
message: "--id <uuid> \u4E0E --username <user> \u5FC5\u987B\u4E14\u53EA\u80FD\u63D0\u4F9B\u4E00\u4E2A"
|
|
11343
11891
|
});
|
|
11344
11892
|
}
|
|
11345
11893
|
if (!password) {
|
|
11346
|
-
throw new
|
|
11347
|
-
code:
|
|
11894
|
+
throw new CliError24({
|
|
11895
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11348
11896
|
message: "\u65B0\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A"
|
|
11349
11897
|
});
|
|
11350
11898
|
}
|
|
@@ -11360,9 +11908,9 @@ async function userResetPasswordCommand(args) {
|
|
|
11360
11908
|
try {
|
|
11361
11909
|
const password = args.passwordStdin ? await readSecretFromStdin() : await promptPasswordTwice();
|
|
11362
11910
|
const request = buildAdminResetPasswordRequest(args, password);
|
|
11363
|
-
const client3 =
|
|
11911
|
+
const client3 = HcmClient28.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
11364
11912
|
const result = await adminResetPassword(client3.raw(), request);
|
|
11365
|
-
process.stdout.write(
|
|
11913
|
+
process.stdout.write(formatObject29(result, { format: args.output ?? "json" }) + "\n");
|
|
11366
11914
|
} catch (cause) {
|
|
11367
11915
|
const err = cause;
|
|
11368
11916
|
if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.env));
|
|
@@ -11373,8 +11921,8 @@ async function promptPasswordTwice() {
|
|
|
11373
11921
|
const password = await promptSecret("\u65B0\u5BC6\u7801: ");
|
|
11374
11922
|
const confirmation = await promptSecret("\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801: ");
|
|
11375
11923
|
if (password !== confirmation) {
|
|
11376
|
-
throw new
|
|
11377
|
-
code:
|
|
11924
|
+
throw new CliError24({
|
|
11925
|
+
code: CliErrorCode22.INVALID_ARGUMENT,
|
|
11378
11926
|
message: "\u4E24\u6B21\u8F93\u5165\u7684\u65B0\u5BC6\u7801\u4E0D\u4E00\u81F4"
|
|
11379
11927
|
});
|
|
11380
11928
|
}
|
|
@@ -11385,19 +11933,19 @@ async function promptPasswordTwice() {
|
|
|
11385
11933
|
init_exit();
|
|
11386
11934
|
init_auth_guard();
|
|
11387
11935
|
import {
|
|
11388
|
-
HcmClient as
|
|
11389
|
-
formatObject as
|
|
11936
|
+
HcmClient as HcmClient29,
|
|
11937
|
+
formatObject as formatObject30,
|
|
11390
11938
|
fromAxiosError as fromAxiosError24
|
|
11391
11939
|
} from "@hcmai/sdk";
|
|
11392
11940
|
async function modelsCommand(keyword, args) {
|
|
11393
11941
|
try {
|
|
11394
|
-
const client3 =
|
|
11942
|
+
const client3 = HcmClient29.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
11395
11943
|
const all = await client3.listModels();
|
|
11396
11944
|
const needle = keyword?.trim().toLowerCase();
|
|
11397
11945
|
const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
|
|
11398
11946
|
const fmt = args.output ?? "table";
|
|
11399
11947
|
if (fmt !== "table") {
|
|
11400
|
-
process.stdout.write(
|
|
11948
|
+
process.stdout.write(formatObject30({ total: rows.length, models: rows }, { format: fmt }) + "\n");
|
|
11401
11949
|
process.exitCode = 0;
|
|
11402
11950
|
return;
|
|
11403
11951
|
}
|
|
@@ -11447,7 +11995,10 @@ var exitOnBrokenPipe = (err) => {
|
|
|
11447
11995
|
};
|
|
11448
11996
|
process.stdout.on("error", exitOnBrokenPipe);
|
|
11449
11997
|
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)
|
|
11998
|
+
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) => {
|
|
11999
|
+
const lang = thisCommand.opts().lang;
|
|
12000
|
+
if (lang) process.env.HCM_LANG = lang;
|
|
12001
|
+
});
|
|
11451
12002
|
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
12003
|
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
12004
|
var config = program.command("config").description("\u7BA1\u7406\u5168\u5C40 defaults\uFF08env/identity \u7528 `hcm env` / `hcm identity`\uFF09");
|
|
@@ -11472,6 +12023,9 @@ identity.command("use <name>").description("\u628A identity \u8BBE\u4E3A\u5176 e
|
|
|
11472
12023
|
identity.command("remove <name>").description("\u5220\u9664 identity\uFF08\u6E05 token + \u82E5\u662F env default \u5219\u6E05\u7A7A\uFF09").action((name) => identityRemove(name));
|
|
11473
12024
|
var user = program.command("user").description("\u7BA1\u7406\u79DF\u6237\u7528\u6237\u7684\u4E13\u7528\u51ED\u636E\u6D41\u7A0B");
|
|
11474
12025
|
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));
|
|
12026
|
+
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");
|
|
12027
|
+
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));
|
|
12028
|
+
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
12029
|
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
12030
|
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
12031
|
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 +12178,7 @@ skills.command("update").description("\u628A\u88C5\u8FC7\u7684\u6280\u80FD\u5347
|
|
|
11624
12178
|
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
12179
|
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
12180
|
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((
|
|
12181
|
+
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
12182
|
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
12183
|
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
12184
|
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));
|