@hcmai/cli 0.4.19 → 0.4.21
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/README.md +15 -0
- package/dist/index.js +1151 -270
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +16 -2
- package/package.json +3 -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(path14) {
|
|
527
|
+
const segs = path14.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(path14) {
|
|
1710
|
+
const segs = (path14 ?? "").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
|
}
|
|
@@ -2229,7 +2229,19 @@ async function loginCommand(args) {
|
|
|
2229
2229
|
scopes = record.scopes;
|
|
2230
2230
|
} else {
|
|
2231
2231
|
username = args.username ?? await promptText("username: ");
|
|
2232
|
-
|
|
2232
|
+
if (args.passwordStdin && args.password) {
|
|
2233
|
+
throw new CliError2({
|
|
2234
|
+
code: CliErrorCode.INVALID_ARGUMENT,
|
|
2235
|
+
message: "--password \u4E0E --password-stdin \u53EA\u80FD\u4E8C\u9009\u4E00"
|
|
2236
|
+
});
|
|
2237
|
+
}
|
|
2238
|
+
if (args.password) {
|
|
2239
|
+
process.stderr.write("[hcm] WARNING: --password <p> \u4F1A\u6CC4\u6F0F\u5230 shell history / ps aux\u3002\u63A8\u8350 --password-stdin\u3002\n");
|
|
2240
|
+
}
|
|
2241
|
+
const password = args.passwordStdin ? await readStdin() : args.password ?? await promptSecret("password: ");
|
|
2242
|
+
if (args.passwordStdin && !password) {
|
|
2243
|
+
throw new CliError2({ code: CliErrorCode.INVALID_ARGUMENT, message: "--password-stdin \u8BFB\u5230\u7684\u5BC6\u7801\u4E3A\u7A7A" });
|
|
2244
|
+
}
|
|
2233
2245
|
if (!username || !password) {
|
|
2234
2246
|
throw new CliError2({
|
|
2235
2247
|
code: CliErrorCode.MISSING_FLAG,
|
|
@@ -2286,9 +2298,9 @@ async function loginCommand(args) {
|
|
|
2286
2298
|
} catch (e) {
|
|
2287
2299
|
const err = e;
|
|
2288
2300
|
if (err.isAxiosError) {
|
|
2289
|
-
const { fromAxiosError:
|
|
2301
|
+
const { fromAxiosError: fromAxiosError25 } = await import("@hcmai/sdk");
|
|
2290
2302
|
exitWithError(
|
|
2291
|
-
|
|
2303
|
+
fromAxiosError25(
|
|
2292
2304
|
e,
|
|
2293
2305
|
envName
|
|
2294
2306
|
)
|
|
@@ -2644,6 +2656,7 @@ async function queryCommand(model, args) {
|
|
|
2644
2656
|
const dsl = {};
|
|
2645
2657
|
if (args.filter) dsl.filter = parseJsonOrThrow(args.filter, "--filter");
|
|
2646
2658
|
if (args.sort) dsl.sort = parseJsonOrThrow(args.sort, "--sort");
|
|
2659
|
+
if (args.additions) dsl.additions = parseAdditionsOrThrow(args.additions);
|
|
2647
2660
|
if (args.fields) dsl.fields = args.fields.split(",").map((s) => s.trim());
|
|
2648
2661
|
if (args.keyword) dsl.keyword = args.keyword;
|
|
2649
2662
|
if (args.limit) dsl.limit = Number(args.limit);
|
|
@@ -2652,13 +2665,7 @@ async function queryCommand(model, args) {
|
|
|
2652
2665
|
const client3 = HcmClient.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
2653
2666
|
const result = await client3.query(model, dsl);
|
|
2654
2667
|
const fmt = args.output ?? "table";
|
|
2655
|
-
|
|
2656
|
-
process.stdout.write(out + "\n");
|
|
2657
|
-
if (fmt === "table" && result.total !== void 0) {
|
|
2658
|
-
process.stdout.write(`Showing ${result.rows.length} of ${result.total} results.
|
|
2659
|
-
`);
|
|
2660
|
-
}
|
|
2661
|
-
process.exit(0);
|
|
2668
|
+
printQueryResult(result, fmt);
|
|
2662
2669
|
} catch (e) {
|
|
2663
2670
|
const err = e;
|
|
2664
2671
|
if (err?.isAxiosError) {
|
|
@@ -2667,6 +2674,25 @@ async function queryCommand(model, args) {
|
|
|
2667
2674
|
exitWithError(e);
|
|
2668
2675
|
}
|
|
2669
2676
|
}
|
|
2677
|
+
function printQueryResult(result, fmt) {
|
|
2678
|
+
const out = formatRows(result.rows, { format: fmt });
|
|
2679
|
+
process.stdout.write(out + "\n");
|
|
2680
|
+
if (fmt === "table" && result.total !== void 0) {
|
|
2681
|
+
process.stdout.write(`Showing ${result.rows.length} of ${result.total} results.
|
|
2682
|
+
`);
|
|
2683
|
+
}
|
|
2684
|
+
process.exitCode = 0;
|
|
2685
|
+
}
|
|
2686
|
+
function parseAdditionsOrThrow(text) {
|
|
2687
|
+
const parsed = parseJsonOrThrow(text, "--additions");
|
|
2688
|
+
if (!Array.isArray(parsed) || parsed.some((item) => typeof item !== "object" || item === null || Array.isArray(item))) {
|
|
2689
|
+
throw new CliError6({
|
|
2690
|
+
code: CliErrorCode5.INVALID_ARGUMENT,
|
|
2691
|
+
message: `--additions \u5FC5\u987B\u662F JSON \u5BF9\u8C61\u6570\u7EC4\uFF0C\u4F8B\u5982 '[{"key":"employee","model":"Employee"}]'`
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
return parsed;
|
|
2695
|
+
}
|
|
2670
2696
|
function parseJsonOrThrow(text, flag) {
|
|
2671
2697
|
try {
|
|
2672
2698
|
return JSON.parse(text);
|
|
@@ -2785,16 +2811,7 @@ async function actionCommand(spec, args) {
|
|
|
2785
2811
|
}
|
|
2786
2812
|
const result = await client3.action(model, action, input);
|
|
2787
2813
|
const fmt = args.output ?? "json";
|
|
2788
|
-
|
|
2789
|
-
process.stdout.write(
|
|
2790
|
-
`\u23F3 task created: ${result.taskId} (use \`hcm task ${result.taskId}\` to follow up \u2014 coming Phase 1)
|
|
2791
|
-
`
|
|
2792
|
-
);
|
|
2793
|
-
} else if (fmt !== "json") {
|
|
2794
|
-
process.stdout.write("\u2705 action succeeded\n");
|
|
2795
|
-
}
|
|
2796
|
-
process.stdout.write(formatObject(result, { format: fmt }) + "\n");
|
|
2797
|
-
process.exit(0);
|
|
2814
|
+
printActionResult(result, fmt);
|
|
2798
2815
|
} catch (e) {
|
|
2799
2816
|
const err = e;
|
|
2800
2817
|
if (err?.isAxiosError) {
|
|
@@ -2803,6 +2820,18 @@ async function actionCommand(spec, args) {
|
|
|
2803
2820
|
exitWithError(e);
|
|
2804
2821
|
}
|
|
2805
2822
|
}
|
|
2823
|
+
function printActionResult(result, fmt) {
|
|
2824
|
+
if (fmt !== "json" && result.taskId) {
|
|
2825
|
+
process.stdout.write(
|
|
2826
|
+
`\u23F3 task created: ${result.taskId} (use \`hcm task ${result.taskId}\` to follow up \u2014 coming Phase 1)
|
|
2827
|
+
`
|
|
2828
|
+
);
|
|
2829
|
+
} else if (fmt !== "json") {
|
|
2830
|
+
process.stdout.write("\u2705 action succeeded\n");
|
|
2831
|
+
}
|
|
2832
|
+
process.stdout.write(formatObject(result, { format: fmt }) + "\n");
|
|
2833
|
+
process.exitCode = 0;
|
|
2834
|
+
}
|
|
2806
2835
|
function normalizeMethod(value) {
|
|
2807
2836
|
const raw = (value ?? "POST").toUpperCase();
|
|
2808
2837
|
if (raw === "GET" || raw === "POST" || raw === "PUT" || raw === "DELETE") return raw;
|
|
@@ -3140,7 +3169,7 @@ function launchBrowser(url, platform = process.platform) {
|
|
|
3140
3169
|
child.unref();
|
|
3141
3170
|
}
|
|
3142
3171
|
async function runOpen(target, args, deps) {
|
|
3143
|
-
const
|
|
3172
|
+
const path14 = normalizeTarget(target);
|
|
3144
3173
|
if (!deps.frontend?.trim()) {
|
|
3145
3174
|
throw new CliError12({
|
|
3146
3175
|
code: CliErrorCode11.INVALID_ARGUMENT,
|
|
@@ -3148,13 +3177,13 @@ async function runOpen(target, args, deps) {
|
|
|
3148
3177
|
});
|
|
3149
3178
|
}
|
|
3150
3179
|
const { ticket, expiresIn } = await deps.mintTicket();
|
|
3151
|
-
const url = buildBrowserLoginUrl(deps.frontend, ticket,
|
|
3180
|
+
const url = buildBrowserLoginUrl(deps.frontend, ticket, path14);
|
|
3152
3181
|
if (args.printUrl) {
|
|
3153
3182
|
deps.write(`${url}
|
|
3154
3183
|
`);
|
|
3155
3184
|
} else {
|
|
3156
3185
|
deps.launch(url);
|
|
3157
|
-
deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${
|
|
3186
|
+
deps.write(`\u5DF2\u7528\u5F53\u524D\u8EAB\u4EFD\u6253\u5F00 ${path14}\uFF08\u7968\u636E ${expiresIn ?? 60}s \u5185\u6709\u6548\uFF0C\u53EA\u80FD\u7528\u4E00\u6B21\uFF09
|
|
3158
3187
|
`);
|
|
3159
3188
|
}
|
|
3160
3189
|
return { url, expiresIn };
|
|
@@ -3246,8 +3275,8 @@ import {
|
|
|
3246
3275
|
formatObject as formatObject7,
|
|
3247
3276
|
fromAxiosError as fromAxiosError9
|
|
3248
3277
|
} from "@hcmai/sdk";
|
|
3249
|
-
function collectYmlFiles(
|
|
3250
|
-
if (statSync(
|
|
3278
|
+
function collectYmlFiles(path14) {
|
|
3279
|
+
if (statSync(path14).isFile()) return [path14];
|
|
3251
3280
|
const out = [];
|
|
3252
3281
|
const walk = (dir) => {
|
|
3253
3282
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -3256,7 +3285,7 @@ function collectYmlFiles(path12) {
|
|
|
3256
3285
|
else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
|
|
3257
3286
|
}
|
|
3258
3287
|
};
|
|
3259
|
-
walk(
|
|
3288
|
+
walk(path14);
|
|
3260
3289
|
return out.sort();
|
|
3261
3290
|
}
|
|
3262
3291
|
var DRY_RUN_CLIENT = {
|
|
@@ -3264,9 +3293,9 @@ var DRY_RUN_CLIENT = {
|
|
|
3264
3293
|
create: async () => ({ id: "" }),
|
|
3265
3294
|
update: async () => ({})
|
|
3266
3295
|
};
|
|
3267
|
-
async function importCommand(
|
|
3296
|
+
async function importCommand(path14, args) {
|
|
3268
3297
|
try {
|
|
3269
|
-
const files = collectYmlFiles(
|
|
3298
|
+
const files = collectYmlFiles(path14);
|
|
3270
3299
|
const fixtures = files.map(
|
|
3271
3300
|
(f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
|
|
3272
3301
|
);
|
|
@@ -4503,8 +4532,8 @@ async function scriptManifestValidateCommand(args) {
|
|
|
4503
4532
|
if (!args.file) {
|
|
4504
4533
|
throw new Error("\u7F3A\u5C11 --file\n \u4E0B\u4E00\u6B65\uFF1Ahcm script manifest-validate --file ./manifest.yml");
|
|
4505
4534
|
}
|
|
4506
|
-
const
|
|
4507
|
-
const result = await withClient2(args, (c) => validateScriptManifest(c.raw(),
|
|
4535
|
+
const yaml2 = readFileSync3(args.file, "utf8");
|
|
4536
|
+
const result = await withClient2(args, (c) => validateScriptManifest(c.raw(), yaml2));
|
|
4508
4537
|
emit2(result, args, `\u{1F4CB} manifest \u6821\u9A8C\u5B8C\u6210\uFF1A${args.file}`);
|
|
4509
4538
|
} catch (e) {
|
|
4510
4539
|
fail3(e, args);
|
|
@@ -5035,10 +5064,12 @@ async function resolveInstallLayout(args, cwd = process.cwd()) {
|
|
|
5035
5064
|
const target = requested ?? await detectTarget(cwd) ?? "claude";
|
|
5036
5065
|
if (target === "codex") {
|
|
5037
5066
|
const root = args.global ? path4.join(os2.homedir(), ".codex") : cwd;
|
|
5067
|
+
const claudeFile = path4.join(root, "CLAUDE.md");
|
|
5038
5068
|
return {
|
|
5039
5069
|
target,
|
|
5040
5070
|
baseDir: args.dir ? path4.resolve(args.dir) : path4.join(root, "hcm-skills"),
|
|
5041
|
-
agentsFile: path4.join(root, "AGENTS.md")
|
|
5071
|
+
agentsFile: path4.join(root, "AGENTS.md"),
|
|
5072
|
+
companionAgentFiles: !args.global && await exists(claudeFile) ? [claudeFile] : []
|
|
5042
5073
|
};
|
|
5043
5074
|
}
|
|
5044
5075
|
return {
|
|
@@ -5423,10 +5454,11 @@ async function skillsInstallCommand(id, args) {
|
|
|
5423
5454
|
target: layout.target,
|
|
5424
5455
|
all
|
|
5425
5456
|
});
|
|
5426
|
-
const
|
|
5457
|
+
const agentIndexes = layout.agentsFile ? await syncAgentIndexes(layout, manifest2) : [];
|
|
5458
|
+
const agents = agentIndexes[0]?.status;
|
|
5427
5459
|
const fmt = args.output ?? "table";
|
|
5428
5460
|
if (fmt === "json" || fmt === "yaml") {
|
|
5429
|
-
process.stdout.write(formatObject16({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
|
|
5461
|
+
process.stdout.write(formatObject16({ ...result, all, target_agent: layout.target, agentsFile: layout.agentsFile, agents, agentIndexes, conflictCheck: conflictNote ? { checked: false, note: conflictNote } : { checked: true } }, { format: fmt }) + "\n");
|
|
5430
5462
|
} else {
|
|
5431
5463
|
const headline = all ? `\u2705 \u5168\u90E8 ${requestedIds.length} \u4E2A\u6280\u80FD \u2192 ${result.baseDir}` : `\u2705 ${id} \u2192 ${path4.join(result.baseDir, id, "SKILL.md")}`;
|
|
5432
5464
|
process.stdout.write(`${headline}
|
|
@@ -5446,8 +5478,9 @@ async function skillsInstallCommand(id, args) {
|
|
|
5446
5478
|
process.stdout.write(` \u53C2\u8003\u6587\u4EF6 ${referenceCount} \u4E2A\uFF08references/ \u4E0B\uFF09
|
|
5447
5479
|
`);
|
|
5448
5480
|
}
|
|
5449
|
-
|
|
5450
|
-
|
|
5481
|
+
for (const index of agentIndexes) {
|
|
5482
|
+
const reader = path4.basename(index.file) === "CLAUDE.md" ? "Claude Code" : "Codex";
|
|
5483
|
+
process.stdout.write(` \u5DF2${index.status === "created" ? "\u521B\u5EFA" : "\u66F4\u65B0"} ${index.file} \u91CC\u7684\u6280\u80FD\u7D22\u5F15\uFF08${reader} \u8BFB\u8FD9\u91CC\uFF09
|
|
5451
5484
|
`);
|
|
5452
5485
|
}
|
|
5453
5486
|
process.stdout.write(` \u6765\u6E90 ${endpoint ?? (args.from ? path4.resolve(args.from) : `@hcmai/cli@${CLI_VERSION}`)}
|
|
@@ -5499,33 +5532,38 @@ async function fetchSkillDocument(http, skill, endpoint, base) {
|
|
|
5499
5532
|
return {
|
|
5500
5533
|
id: skill.id,
|
|
5501
5534
|
markdown: await fetchSkillMarkdown(http, skill.id, base),
|
|
5502
|
-
source: `${endpoint}${base}
|
|
5535
|
+
source: `${endpoint}${base}/${skill.id}.md`,
|
|
5503
5536
|
sourceKind: "chiron",
|
|
5504
5537
|
references
|
|
5505
5538
|
};
|
|
5506
5539
|
}
|
|
5507
|
-
async function
|
|
5508
|
-
if (!layout.agentsFile) return
|
|
5540
|
+
async function syncAgentIndexes(layout, manifest2) {
|
|
5541
|
+
if (!layout.agentsFile) return [];
|
|
5509
5542
|
const state = await readSkillsState(layout.baseDir);
|
|
5510
|
-
if (!state) return
|
|
5543
|
+
if (!state) return [];
|
|
5511
5544
|
const catalog = /* @__PURE__ */ new Map();
|
|
5512
5545
|
for (const category of manifest2?.categories ?? []) {
|
|
5513
5546
|
for (const skill of category.skills ?? []) catalog.set(skill.id, skill);
|
|
5514
5547
|
}
|
|
5515
|
-
const
|
|
5516
|
-
const
|
|
5517
|
-
|
|
5518
|
-
const
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5528
|
-
|
|
5548
|
+
const files = [layout.agentsFile, ...layout.companionAgentFiles ?? []];
|
|
5549
|
+
const results = [];
|
|
5550
|
+
for (const file of files) {
|
|
5551
|
+
const agentsDir = path4.dirname(file);
|
|
5552
|
+
const entries = Object.keys(state.skills).sort().map((id) => {
|
|
5553
|
+
const known = catalog.get(id);
|
|
5554
|
+
const absolute = path4.join(layout.baseDir, id, "SKILL.md");
|
|
5555
|
+
let relative2 = path4.relative(agentsDir, absolute);
|
|
5556
|
+
if (!relative2.startsWith(".")) relative2 = `./${relative2}`;
|
|
5557
|
+
return {
|
|
5558
|
+
id,
|
|
5559
|
+
title: known?.title ?? id,
|
|
5560
|
+
description: known?.description ?? "",
|
|
5561
|
+
relativePath: relative2.split(path4.sep).join("/")
|
|
5562
|
+
};
|
|
5563
|
+
});
|
|
5564
|
+
results.push({ file, status: await upsertAgentsBlock(file, renderAgentsBlock(entries)) });
|
|
5565
|
+
}
|
|
5566
|
+
return results;
|
|
5529
5567
|
}
|
|
5530
5568
|
async function resolveLocalSkillDocuments(sourceRoot, targetId) {
|
|
5531
5569
|
assertSafeSkillId(targetId);
|
|
@@ -5986,8 +6024,8 @@ async function skillsUpdateCommand(args) {
|
|
|
5986
6024
|
all,
|
|
5987
6025
|
directIds: all ? new Set(plan.documents.map((document) => document.id)) : /* @__PURE__ */ new Set()
|
|
5988
6026
|
});
|
|
5989
|
-
if (layout.agentsFile) await syncAgentsIndex(layout, manifest2);
|
|
5990
6027
|
}
|
|
6028
|
+
if (!args.check && layout.agentsFile) await syncAgentIndexes(layout, manifest2);
|
|
5991
6029
|
const changed = plan.entries.filter((e) => e.status === "updated" || e.status === "added");
|
|
5992
6030
|
const fmt = args.output ?? "table";
|
|
5993
6031
|
if (fmt === "json" || fmt === "yaml") {
|
|
@@ -6230,10 +6268,10 @@ async function metaListCommand(args) {
|
|
|
6230
6268
|
fail5(e, args);
|
|
6231
6269
|
}
|
|
6232
6270
|
}
|
|
6233
|
-
async function metaGetCommand(
|
|
6271
|
+
async function metaGetCommand(path14, args) {
|
|
6234
6272
|
try {
|
|
6235
6273
|
const c = await client2(args);
|
|
6236
|
-
const content = await getTenantMeta(c.raw(),
|
|
6274
|
+
const content = await getTenantMeta(c.raw(), path14);
|
|
6237
6275
|
process.stdout.write(content.endsWith("\n") ? content : content + "\n");
|
|
6238
6276
|
process.exit(0);
|
|
6239
6277
|
} catch (e) {
|
|
@@ -6241,8 +6279,8 @@ async function metaGetCommand(path12, args) {
|
|
|
6241
6279
|
}
|
|
6242
6280
|
}
|
|
6243
6281
|
var PROBEABLE_META_TYPES = /* @__PURE__ */ new Set(["model", "list", "info", "view", "filter", "page", "wiz", "impexp"]);
|
|
6244
|
-
function parseMetaPath(
|
|
6245
|
-
const base =
|
|
6282
|
+
function parseMetaPath(path14) {
|
|
6283
|
+
const base = path14.split(/[\\/]/).pop() ?? path14;
|
|
6246
6284
|
if (!/\.(yml|yaml)$/i.test(base)) return {};
|
|
6247
6285
|
const parts = base.replace(/\.(yml|yaml)$/i, "").split(".");
|
|
6248
6286
|
return { model: parts[0] || void 0, kind: parts[1] ?? "model", state: parts[2] };
|
|
@@ -6259,10 +6297,10 @@ function unverifiableReason(e) {
|
|
|
6259
6297
|
if (st == null) return `\u8BF7\u6C42\u6CA1\u53D1\u51FA\u53BB\u6216\u6CA1\u56DE\u6765\uFF08${err.code ?? err.message ?? "\u672A\u77E5"}\uFF09`;
|
|
6260
6298
|
return void 0;
|
|
6261
6299
|
}
|
|
6262
|
-
async function verifyAfterWrite(c,
|
|
6263
|
-
const { model, kind, state } = parseMetaPath(
|
|
6300
|
+
async function verifyAfterWrite(c, path14) {
|
|
6301
|
+
const { model, kind, state } = parseMetaPath(path14);
|
|
6264
6302
|
if (!model || !kind) {
|
|
6265
|
-
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${
|
|
6303
|
+
return { status: "unverified", where: "(\u672A\u63A2)", why: `\u4ECE\u8DEF\u5F84 ${path14} \u8BA4\u4E0D\u51FA\u6A21\u578B\u540D/\u5C42\u540D` };
|
|
6266
6304
|
}
|
|
6267
6305
|
try {
|
|
6268
6306
|
await clearMetaCache2(c.raw(), model, {});
|
|
@@ -6307,7 +6345,7 @@ async function verifyAfterWrite(c, path12) {
|
|
|
6307
6345
|
}
|
|
6308
6346
|
return { status: "ok" };
|
|
6309
6347
|
}
|
|
6310
|
-
async function metaSetCommand(
|
|
6348
|
+
async function metaSetCommand(path14, args) {
|
|
6311
6349
|
try {
|
|
6312
6350
|
if (!args.file) {
|
|
6313
6351
|
throw new CliError19({
|
|
@@ -6323,9 +6361,9 @@ async function metaSetCommand(path12, args) {
|
|
|
6323
6361
|
process.stdin.on("error", reject);
|
|
6324
6362
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6325
6363
|
if (!args.skipValidate) {
|
|
6326
|
-
const result2 = validateMetaContent(
|
|
6364
|
+
const result2 = validateMetaContent(path14, content);
|
|
6327
6365
|
if (result2.issues.length > 0) {
|
|
6328
|
-
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${
|
|
6366
|
+
process.stderr.write(`\u{1F50E} \u5199\u524D\u6821\u9A8C ${path14}\uFF08schema \u7C7B\u578B\uFF1A${result2.kind ?? "\u672A\u8BC6\u522B"}\uFF09
|
|
6329
6367
|
`);
|
|
6330
6368
|
process.stderr.write(formatMetaIssues(result2, " ") + "\n");
|
|
6331
6369
|
}
|
|
@@ -6344,13 +6382,13 @@ async function metaSetCommand(path12, args) {
|
|
|
6344
6382
|
if (dryFmt === "json" || dryFmt === "yaml") {
|
|
6345
6383
|
process.stdout.write(
|
|
6346
6384
|
formatObject18(
|
|
6347
|
-
{ dryRun: true, path:
|
|
6385
|
+
{ dryRun: true, path: path14, bytes: Buffer.byteLength(content), content },
|
|
6348
6386
|
{ format: dryFmt }
|
|
6349
6387
|
) + "\n"
|
|
6350
6388
|
);
|
|
6351
6389
|
} else {
|
|
6352
6390
|
process.stdout.write(
|
|
6353
|
-
`[dry-run] \u5C06\u5199\u5165 ${
|
|
6391
|
+
`[dry-run] \u5C06\u5199\u5165 ${path14}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
|
|
6354
6392
|
---
|
|
6355
6393
|
${content}
|
|
6356
6394
|
`
|
|
@@ -6363,13 +6401,13 @@ ${content}
|
|
|
6363
6401
|
let backupState = "unknown";
|
|
6364
6402
|
let backupWhy;
|
|
6365
6403
|
try {
|
|
6366
|
-
const prev = await getTenantMeta(c.raw(),
|
|
6404
|
+
const prev = await getTenantMeta(c.raw(), path14);
|
|
6367
6405
|
if (!prev || prev.trim() === "") {
|
|
6368
6406
|
backupState = "absent";
|
|
6369
6407
|
} else {
|
|
6370
6408
|
backupFile = nodePath.join(
|
|
6371
6409
|
os3.tmpdir(),
|
|
6372
|
-
`hcm-meta-backup-${Date.now()}-${
|
|
6410
|
+
`hcm-meta-backup-${Date.now()}-${path14.replace(/[\\/]/g, "_")}`
|
|
6373
6411
|
);
|
|
6374
6412
|
await fsp3.writeFile(backupFile, prev, "utf8");
|
|
6375
6413
|
backupState = "saved";
|
|
@@ -6384,22 +6422,22 @@ ${content}
|
|
|
6384
6422
|
backupWhy = `HTTP ${st ?? "-"}${err.code ? ` ${err.code}` : ""}${err.message ? `\uFF1A${err.message}` : ""}`;
|
|
6385
6423
|
}
|
|
6386
6424
|
}
|
|
6387
|
-
const result = await saveTenantMeta(c.raw(),
|
|
6425
|
+
const result = await saveTenantMeta(c.raw(), path14, content);
|
|
6388
6426
|
const fmt = args.output ?? "json";
|
|
6389
|
-
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${
|
|
6427
|
+
if (fmt !== "json") process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path14}
|
|
6390
6428
|
`);
|
|
6391
6429
|
const restoreHint = backupState === "saved" && backupFile ? ` \u65E7\u5185\u5BB9\u5DF2\u5B58\uFF1A${backupFile}
|
|
6392
|
-
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${
|
|
6393
|
-
` : 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 ${
|
|
6430
|
+
\u653E\u56DE\u53BB\uFF1Ahcm meta set ${path14} --file ${backupFile}${connFlags(args)}
|
|
6431
|
+
` : 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 ${path14}${connFlags(args)}
|
|
6394
6432
|
` : ` \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
|
|
6395
|
-
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${
|
|
6433
|
+
\u5148\u81EA\u5DF1\u8BFB\u4E00\u904D\u786E\u8BA4\uFF1Ahcm meta get ${path14}${connFlags(args)}
|
|
6396
6434
|
`;
|
|
6397
6435
|
if (args.verify === false) {
|
|
6398
6436
|
process.stderr.write(
|
|
6399
6437
|
"\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
|
|
6400
6438
|
);
|
|
6401
6439
|
} else {
|
|
6402
|
-
const outcome = await verifyAfterWrite(c,
|
|
6440
|
+
const outcome = await verifyAfterWrite(c, path14);
|
|
6403
6441
|
if (outcome.status === "broken") {
|
|
6404
6442
|
const human = explainJacksonError(outcome.raw);
|
|
6405
6443
|
process.stderr.write(
|
|
@@ -6431,19 +6469,19 @@ ${content}
|
|
|
6431
6469
|
fail5(e, args);
|
|
6432
6470
|
}
|
|
6433
6471
|
}
|
|
6434
|
-
async function metaDeleteCommand(
|
|
6472
|
+
async function metaDeleteCommand(path14, args) {
|
|
6435
6473
|
try {
|
|
6436
6474
|
if (!args.yes) {
|
|
6437
|
-
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${
|
|
6475
|
+
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path14}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
|
|
6438
6476
|
if (!ok) {
|
|
6439
6477
|
process.stderr.write("\u5DF2\u53D6\u6D88\n");
|
|
6440
6478
|
process.exit(1);
|
|
6441
6479
|
}
|
|
6442
6480
|
}
|
|
6443
6481
|
const c = await client2(args);
|
|
6444
|
-
const result = await deleteTenantMeta(c.raw(),
|
|
6482
|
+
const result = await deleteTenantMeta(c.raw(), path14);
|
|
6445
6483
|
const fmt = args.output ?? "json";
|
|
6446
|
-
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${
|
|
6484
|
+
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path14}
|
|
6447
6485
|
`);
|
|
6448
6486
|
process.stdout.write(formatObject18(result, { format: fmt }) + "\n");
|
|
6449
6487
|
process.exit(0);
|
|
@@ -6451,7 +6489,7 @@ async function metaDeleteCommand(path12, args) {
|
|
|
6451
6489
|
fail5(e, args);
|
|
6452
6490
|
}
|
|
6453
6491
|
}
|
|
6454
|
-
async function metaValidateCommand(
|
|
6492
|
+
async function metaValidateCommand(path14, args) {
|
|
6455
6493
|
try {
|
|
6456
6494
|
if (!args.file) {
|
|
6457
6495
|
throw new CliError19({
|
|
@@ -6466,13 +6504,13 @@ async function metaValidateCommand(path12, args) {
|
|
|
6466
6504
|
process.stdin.on("end", () => resolve4(buf));
|
|
6467
6505
|
process.stdin.on("error", reject);
|
|
6468
6506
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6469
|
-
const result = validateMetaContent(
|
|
6507
|
+
const result = validateMetaContent(path14, content);
|
|
6470
6508
|
const fmt = args.output ?? "table";
|
|
6471
6509
|
if (fmt === "json" || fmt === "yaml") {
|
|
6472
6510
|
process.stdout.write(
|
|
6473
6511
|
formatObject18(
|
|
6474
6512
|
{
|
|
6475
|
-
path:
|
|
6513
|
+
path: path14,
|
|
6476
6514
|
kind: result.kind,
|
|
6477
6515
|
schemaKnown: result.schemaKnown,
|
|
6478
6516
|
schemaSourceCommit: META_SCHEMA_SOURCE_COMMIT,
|
|
@@ -6484,7 +6522,7 @@ async function metaValidateCommand(path12, args) {
|
|
|
6484
6522
|
);
|
|
6485
6523
|
} else {
|
|
6486
6524
|
process.stdout.write(
|
|
6487
|
-
`\u{1F50E} ${
|
|
6525
|
+
`\u{1F50E} ${path14}\uFF08schema \u7C7B\u578B\uFF1A${result.kind ?? "\u672A\u8BC6\u522B"}\uFF0C\u6765\u6E90 ${META_SCHEMA_SOURCE_COMMIT.slice(0, 8)}\uFF09
|
|
6488
6526
|
`
|
|
6489
6527
|
);
|
|
6490
6528
|
process.stdout.write(
|
|
@@ -7861,7 +7899,13 @@ async function workspaceActivateCommand(workspaceKey, args) {
|
|
|
7861
7899
|
|
|
7862
7900
|
// src/commands/identity.ts
|
|
7863
7901
|
init_exit();
|
|
7902
|
+
import axios4 from "axios";
|
|
7864
7903
|
import {
|
|
7904
|
+
AUTH_INFO_PATH,
|
|
7905
|
+
CliError as CliError20,
|
|
7906
|
+
CliErrorCode as CliErrorCode19,
|
|
7907
|
+
formatObject as formatObject20,
|
|
7908
|
+
fromAxiosError as fromAxiosError20,
|
|
7865
7909
|
loadEnv as loadEnv8,
|
|
7866
7910
|
saveEnv as saveEnv3,
|
|
7867
7911
|
loadIdentity as loadIdentity4,
|
|
@@ -7869,9 +7913,53 @@ import {
|
|
|
7869
7913
|
deleteIdentity as deleteIdentity2,
|
|
7870
7914
|
loadGlobalConfig as loadGlobalConfig8,
|
|
7871
7915
|
TokenStore as TokenStore3,
|
|
7872
|
-
|
|
7873
|
-
CliErrorCode as CliErrorCode19
|
|
7916
|
+
toPrincipal
|
|
7874
7917
|
} from "@hcmai/sdk";
|
|
7918
|
+
var fetchAuthInfo = async (endpoint, accessToken) => {
|
|
7919
|
+
const response = await axios4.get(`${endpoint.replace(/\/$/, "")}${AUTH_INFO_PATH}`, {
|
|
7920
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
7921
|
+
timeout: 3e4
|
|
7922
|
+
});
|
|
7923
|
+
return response.data;
|
|
7924
|
+
};
|
|
7925
|
+
async function inspectIdentity(name, fetcher = fetchAuthInfo) {
|
|
7926
|
+
const meta2 = await loadIdentity4(name);
|
|
7927
|
+
const env2 = await loadEnv8(meta2.env);
|
|
7928
|
+
const accessToken = await TokenStore3.forIdentity(name).getStoredAccessToken();
|
|
7929
|
+
if (!accessToken) {
|
|
7930
|
+
throw new CliError20({
|
|
7931
|
+
code: CliErrorCode19.AUTH_FAILED,
|
|
7932
|
+
message: `identity '${name}' \u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u6301\u4E45\u5316 token`,
|
|
7933
|
+
context: { nextStep: `\u91CD\u65B0\u767B\u5F55\u8BE5\u8EAB\u4EFD\uFF1Ahcm login --env ${meta2.env} --name ${name}` }
|
|
7934
|
+
});
|
|
7935
|
+
}
|
|
7936
|
+
const raw = await fetcher(env2.endpoint, accessToken);
|
|
7937
|
+
const principal = toPrincipal(raw);
|
|
7938
|
+
const body = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
|
|
7939
|
+
const serverScopes = Array.isArray(body.scopes) ? body.scopes.map(String) : void 0;
|
|
7940
|
+
return {
|
|
7941
|
+
identity: name,
|
|
7942
|
+
env: meta2.env,
|
|
7943
|
+
endpoint: env2.endpoint,
|
|
7944
|
+
scheme: meta2.scheme,
|
|
7945
|
+
userId: principal?.userId ?? null,
|
|
7946
|
+
username: principal?.username ?? null,
|
|
7947
|
+
tenantId: principal?.tenantId ?? null,
|
|
7948
|
+
// null 明确表示服务端没回该字段;[] 才表示服务端确认角色为空。
|
|
7949
|
+
roles: principal?.roles ?? null,
|
|
7950
|
+
scopes: serverScopes ?? meta2.scopes,
|
|
7951
|
+
expiresAt: meta2.expiresAt ?? null,
|
|
7952
|
+
source: AUTH_INFO_PATH
|
|
7953
|
+
};
|
|
7954
|
+
}
|
|
7955
|
+
async function identityShow(name, args) {
|
|
7956
|
+
try {
|
|
7957
|
+
const details = await inspectIdentity(name);
|
|
7958
|
+
exitOk(formatObject20(details, { format: args.output ?? "json" }));
|
|
7959
|
+
} catch (e) {
|
|
7960
|
+
exitWithError(axios4.isAxiosError(e) ? fromAxiosError20(e, name) : e);
|
|
7961
|
+
}
|
|
7962
|
+
}
|
|
7875
7963
|
async function identityList(args) {
|
|
7876
7964
|
try {
|
|
7877
7965
|
const g = await loadGlobalConfig8();
|
|
@@ -7940,7 +8028,7 @@ import { join as pathJoin } from "path";
|
|
|
7940
8028
|
import {
|
|
7941
8029
|
HcmClient as HcmClient20,
|
|
7942
8030
|
classifyEffect,
|
|
7943
|
-
formatObject as
|
|
8031
|
+
formatObject as formatObject21
|
|
7944
8032
|
} from "@hcmai/sdk";
|
|
7945
8033
|
|
|
7946
8034
|
// src/commands/delivery.ts
|
|
@@ -7963,6 +8051,11 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
|
|
|
7963
8051
|
"setting-write",
|
|
7964
8052
|
"credential-reset",
|
|
7965
8053
|
"action-write",
|
|
8054
|
+
// 三态 effect 的 UNKNOWN / 未识别值都按最坏情况视作写操作,走与 WRITES
|
|
8055
|
+
// 完全相同的 prepare + execute 通道。分类函数已经返回 R2 guarded;这里漏登记
|
|
8056
|
+
// 会把 guardedExecutionAvailable 又翻回 false,造成 reason 与 modePolicy 自相矛盾。
|
|
8057
|
+
"action-effect-undetermined",
|
|
8058
|
+
"action-effect-unrecognized",
|
|
7966
8059
|
"workspace-create",
|
|
7967
8060
|
"workspace-activate",
|
|
7968
8061
|
// 这两个的载荷是**任意文件 / 整棵目录**,此前刻意不收——绑不住就意味着
|
|
@@ -7988,7 +8081,11 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
|
|
|
7988
8081
|
// 🔴 客户存量组织导入的整条链就卡在这一个上:2026-09-01 演示环境租户 15,
|
|
7989
8082
|
// 531 条组织机构 dry-run 全绿(静态校验 0 失败),正式导入被
|
|
7990
8083
|
// 「该 R2 命令不在首批受控执行器支持面」拦死,一个写请求都没发出去。
|
|
7991
|
-
"import-write"
|
|
8084
|
+
"import-write",
|
|
8085
|
+
// 报表 / 套打模板回传要先 upload 拿 documentId,再挂到业务对象。文件路径是
|
|
8086
|
+
// 固定位置参数,prepare 会钉住项目内普通文件的摘要,execute 前重算后才单次执行。
|
|
8087
|
+
// 2026-09-02 弹性报表顾问仿真已证实这条交付链会在缺受控执行器时中断。
|
|
8088
|
+
"document-upload"
|
|
7992
8089
|
]);
|
|
7993
8090
|
function normalizeAssessedArgv(inputArgv) {
|
|
7994
8091
|
let rest = inputArgv;
|
|
@@ -8378,6 +8475,151 @@ function isPlainObject(value) {
|
|
|
8378
8475
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8379
8476
|
}
|
|
8380
8477
|
|
|
8478
|
+
// src/commands/delivery-project-config.ts
|
|
8479
|
+
import yaml, { JSON_SCHEMA } from "js-yaml";
|
|
8480
|
+
var DELIVERY_MODES = ["plan-only", "controlled"];
|
|
8481
|
+
function isDeliveryMode(value) {
|
|
8482
|
+
return value === "plan-only" || value === "controlled";
|
|
8483
|
+
}
|
|
8484
|
+
function parseProjectDeliveryModes(content) {
|
|
8485
|
+
let loaded;
|
|
8486
|
+
try {
|
|
8487
|
+
loaded = yaml.load(content, { schema: JSON_SCHEMA });
|
|
8488
|
+
} catch (cause) {
|
|
8489
|
+
throw new Error(`project.yml \u4E0D\u662F\u5408\u6CD5 YAML\uFF1A${String(cause.message)}`);
|
|
8490
|
+
}
|
|
8491
|
+
if (!isRecord(loaded)) throw new Error("project.yml \u9876\u5C42\u5FC5\u987B\u662F\u5BF9\u8C61");
|
|
8492
|
+
const version = loaded.schemaVersion;
|
|
8493
|
+
const raw = loaded.deliveryMode;
|
|
8494
|
+
if (isDeliveryMode(raw)) {
|
|
8495
|
+
if (version !== void 0 && version !== 1) {
|
|
8496
|
+
throw new Error("project.yml \u7684\u6807\u91CF deliveryMode \u53EA\u5C5E\u4E8E schemaVersion 1");
|
|
8497
|
+
}
|
|
8498
|
+
return { kind: "legacy", mode: raw };
|
|
8499
|
+
}
|
|
8500
|
+
if (version !== 2) {
|
|
8501
|
+
throw new Error("project.yml \u7684\u5206\u73AF\u5883 deliveryMode \u5FC5\u987B\u58F0\u660E schemaVersion: 2");
|
|
8502
|
+
}
|
|
8503
|
+
if (raw !== null && raw !== void 0 && !isRecord(raw)) {
|
|
8504
|
+
throw new Error("project.yml \u7684 deliveryMode \u5FC5\u987B\u662F\u201C\u73AF\u5883\u522B\u540D \u2192 \u6A21\u5F0F\u201D\u7684\u6620\u5C04");
|
|
8505
|
+
}
|
|
8506
|
+
const modes = /* @__PURE__ */ Object.create(null);
|
|
8507
|
+
for (const [environment, mode] of Object.entries(raw ?? {})) {
|
|
8508
|
+
if (!environment.trim()) throw new Error("project.yml \u7684 deliveryMode \u542B\u7A7A\u73AF\u5883\u522B\u540D");
|
|
8509
|
+
if (!isDeliveryMode(mode)) {
|
|
8510
|
+
throw new Error(
|
|
8511
|
+
`project.yml \u4E2D\u73AF\u5883 ${JSON.stringify(environment)} \u7684 deliveryMode \u975E\u6CD5\uFF1A${String(mode)}`
|
|
8512
|
+
);
|
|
8513
|
+
}
|
|
8514
|
+
modes[environment] = mode;
|
|
8515
|
+
}
|
|
8516
|
+
return { kind: "per-environment", modes };
|
|
8517
|
+
}
|
|
8518
|
+
function deliveryModeForEnvironment(content, environment) {
|
|
8519
|
+
assertEnvironment(environment);
|
|
8520
|
+
const parsed = parseProjectDeliveryModes(content);
|
|
8521
|
+
return parsed.kind === "per-environment" ? parsed.modes[environment] ?? null : null;
|
|
8522
|
+
}
|
|
8523
|
+
function setDeliveryModeForEnvironment(content, environment, mode) {
|
|
8524
|
+
assertEnvironment(environment);
|
|
8525
|
+
const parsed = parseProjectDeliveryModes(content);
|
|
8526
|
+
const hadFinalNewline = content.endsWith("\n");
|
|
8527
|
+
const lines = content.split("\n");
|
|
8528
|
+
if (hadFinalNewline) lines.pop();
|
|
8529
|
+
if (parsed.kind === "legacy") {
|
|
8530
|
+
const scalarIndex = lines.findIndex(
|
|
8531
|
+
(line) => /^deliveryMode:\s*(?:"(?:plan-only|controlled)"|'(?:plan-only|controlled)'|(?:plan-only|controlled))\s*(?:#.*)?$/.test(line)
|
|
8532
|
+
);
|
|
8533
|
+
if (scalarIndex < 0) {
|
|
8534
|
+
throw new Error("project.yml \u7684\u65E7 deliveryMode \u4E0D\u662F\u53EF\u5B89\u5168\u8FC1\u79FB\u7684\u9876\u5C42\u6807\u91CF\u884C");
|
|
8535
|
+
}
|
|
8536
|
+
const inlineComment = lines[scalarIndex]?.match(/\s+(#.*)$/)?.[1];
|
|
8537
|
+
lines.splice(
|
|
8538
|
+
scalarIndex,
|
|
8539
|
+
1,
|
|
8540
|
+
`deliveryMode:${inlineComment ? ` ${inlineComment}` : ""}`,
|
|
8541
|
+
renderModeEntry(environment, mode)
|
|
8542
|
+
);
|
|
8543
|
+
const versionIndex = lines.findIndex((line) => /^schemaVersion:\s*/.test(line));
|
|
8544
|
+
if (versionIndex >= 0) {
|
|
8545
|
+
const versionComment = lines[versionIndex]?.match(/\s+(#.*)$/)?.[1];
|
|
8546
|
+
lines[versionIndex] = `schemaVersion: 2${versionComment ? ` ${versionComment}` : ""}`;
|
|
8547
|
+
} else {
|
|
8548
|
+
lines.splice(scalarIndex, 0, "schemaVersion: 2");
|
|
8549
|
+
}
|
|
8550
|
+
return {
|
|
8551
|
+
content: finishLines(lines, hadFinalNewline),
|
|
8552
|
+
previous: parsed.mode,
|
|
8553
|
+
migratedLegacy: true
|
|
8554
|
+
};
|
|
8555
|
+
}
|
|
8556
|
+
const sectionStart = lines.findIndex((line) => /^deliveryMode:\s*(?:#.*)?$/.test(line));
|
|
8557
|
+
if (sectionStart < 0) {
|
|
8558
|
+
throw new Error("project.yml \u7F3A\u5C11\u53EF\u5B89\u5168\u66F4\u65B0\u7684\u9876\u5C42 deliveryMode \u6620\u5C04");
|
|
8559
|
+
}
|
|
8560
|
+
let sectionEnd = lines.length;
|
|
8561
|
+
for (let index = sectionStart + 1; index < lines.length; index += 1) {
|
|
8562
|
+
const line = lines[index] ?? "";
|
|
8563
|
+
if (line.trim() === "" || line.trimStart().startsWith("#")) continue;
|
|
8564
|
+
if (!/^\s/.test(line)) {
|
|
8565
|
+
sectionEnd = index;
|
|
8566
|
+
break;
|
|
8567
|
+
}
|
|
8568
|
+
}
|
|
8569
|
+
let lastEntry = sectionStart;
|
|
8570
|
+
let targetIndex = -1;
|
|
8571
|
+
for (let index = sectionStart + 1; index < sectionEnd; index += 1) {
|
|
8572
|
+
const line = lines[index] ?? "";
|
|
8573
|
+
if (!/^ {2}\S/.test(line) || /^ {4}/.test(line)) continue;
|
|
8574
|
+
const entry = parseDirectModeEntry(line);
|
|
8575
|
+
if (!entry) continue;
|
|
8576
|
+
lastEntry = index;
|
|
8577
|
+
if (entry.environment === environment) targetIndex = index;
|
|
8578
|
+
}
|
|
8579
|
+
const previous = parsed.modes[environment] ?? null;
|
|
8580
|
+
if (previous !== null && targetIndex < 0) {
|
|
8581
|
+
throw new Error(
|
|
8582
|
+
`project.yml \u4E2D ${JSON.stringify(environment)} \u4F7F\u7528\u4E86\u65E0\u6CD5\u5B89\u5168\u5C31\u5730\u6539\u5199\u7684 YAML \u5E03\u5C40`
|
|
8583
|
+
);
|
|
8584
|
+
}
|
|
8585
|
+
if (targetIndex >= 0) {
|
|
8586
|
+
const trailingComment = lines[targetIndex]?.match(
|
|
8587
|
+
/(?:"(?:plan-only|controlled)"|'(?:plan-only|controlled)'|(?:plan-only|controlled))\s+(#.*)$/
|
|
8588
|
+
)?.[1];
|
|
8589
|
+
lines[targetIndex] = `${renderModeEntry(environment, mode)}${trailingComment ? ` ${trailingComment}` : ""}`;
|
|
8590
|
+
} else {
|
|
8591
|
+
lines.splice(lastEntry + 1, 0, renderModeEntry(environment, mode));
|
|
8592
|
+
}
|
|
8593
|
+
return {
|
|
8594
|
+
content: finishLines(lines, hadFinalNewline),
|
|
8595
|
+
previous,
|
|
8596
|
+
migratedLegacy: false
|
|
8597
|
+
};
|
|
8598
|
+
}
|
|
8599
|
+
function parseDirectModeEntry(line) {
|
|
8600
|
+
try {
|
|
8601
|
+
const value = yaml.load(line.trim(), { schema: JSON_SCHEMA });
|
|
8602
|
+
if (!isRecord(value)) return null;
|
|
8603
|
+
const entries = Object.entries(value);
|
|
8604
|
+
if (entries.length !== 1 || !isDeliveryMode(entries[0]?.[1])) return null;
|
|
8605
|
+
return { environment: entries[0][0], mode: entries[0][1] };
|
|
8606
|
+
} catch {
|
|
8607
|
+
return null;
|
|
8608
|
+
}
|
|
8609
|
+
}
|
|
8610
|
+
function renderModeEntry(environment, mode) {
|
|
8611
|
+
return ` ${JSON.stringify(environment)}: ${mode}`;
|
|
8612
|
+
}
|
|
8613
|
+
function finishLines(lines, finalNewline) {
|
|
8614
|
+
return `${lines.join("\n")}${finalNewline ? "\n" : ""}`;
|
|
8615
|
+
}
|
|
8616
|
+
function assertEnvironment(environment) {
|
|
8617
|
+
if (!environment.trim()) throw new Error("\u73AF\u5883\u522B\u540D\u4E0D\u80FD\u4E3A\u7A7A");
|
|
8618
|
+
}
|
|
8619
|
+
function isRecord(value) {
|
|
8620
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
8621
|
+
}
|
|
8622
|
+
|
|
8381
8623
|
// src/commands/delivery-action-policy.ts
|
|
8382
8624
|
async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
|
|
8383
8625
|
const local = assessDeliveryCommand(inputArgv);
|
|
@@ -8389,25 +8631,32 @@ async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
|
|
|
8389
8631
|
const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
|
|
8390
8632
|
return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
|
|
8391
8633
|
}
|
|
8392
|
-
function readDeliveryMode(projectRoot = ".") {
|
|
8634
|
+
function readDeliveryMode(projectRoot = ".", environment) {
|
|
8393
8635
|
const file = pathJoin(projectRoot, ".hcm-delivery", "project.yml");
|
|
8394
8636
|
if (!existsSync2(file)) return null;
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
8637
|
+
try {
|
|
8638
|
+
return deliveryModeForEnvironment(readFileSync5(file, "utf8"), environment);
|
|
8639
|
+
} catch {
|
|
8640
|
+
return null;
|
|
8641
|
+
}
|
|
8399
8642
|
}
|
|
8400
8643
|
function withProjectReadiness(assessment, projectRoot = ".") {
|
|
8401
8644
|
const projectFile = pathJoin(projectRoot, ".hcm-delivery", "project.yml");
|
|
8402
8645
|
const projectInitialized = existsSync2(projectFile);
|
|
8403
|
-
const
|
|
8404
|
-
|
|
8646
|
+
const environment = assessment.environment?.envAlias;
|
|
8647
|
+
const deliveryMode = environment ? readDeliveryMode(projectRoot, environment) : null;
|
|
8648
|
+
if (projectInitialized && deliveryMode !== "controlled" && assessment.guardedExecutionAvailable) {
|
|
8649
|
+
const requirements2 = [...assessment.requirements ?? []];
|
|
8650
|
+
if (!requirements2.includes("environment-delivery-mode")) {
|
|
8651
|
+
requirements2.push("environment-delivery-mode");
|
|
8652
|
+
}
|
|
8405
8653
|
return {
|
|
8406
8654
|
...assessment,
|
|
8407
8655
|
projectInitialized,
|
|
8408
8656
|
deliveryMode,
|
|
8657
|
+
requirements: requirements2,
|
|
8409
8658
|
modePolicy: assessment.modePolicy ? { ...assessment.modePolicy, controlled: "deny" } : assessment.modePolicy,
|
|
8410
|
-
projectNextStep: "\
|
|
8659
|
+
projectNextStep: deliveryMode === "plan-only" ? `\u73AF\u5883 ${environment} \u7684\u4EA4\u4ED8\u6A21\u5F0F\u662F plan-only\uFF0C\u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\u3002\u8981\u771F\u6B63\u6267\u884C R2\uFF0C\u9700\u9879\u76EE\u8D1F\u8D23\u4EBA\u6388\u6743\u540E\u53EA\u5207\u6362\u8FD9\u4E2A\u73AF\u5883\uFF08hcm delivery mode --env ${environment} --set controlled --approved-by '<\u9879\u76EE\u8D1F\u8D23\u4EBA>' --reason '<\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u660E\u786E\u6388\u6743\u4F9D\u636E>'\uFF09` : environment ? `\u73AF\u5883 ${environment} \u5C1A\u672A\u767B\u8BB0\u5408\u6CD5\u4EA4\u4ED8\u6A21\u5F0F\uFF0C\u5DF2 fail-closed\u3002\u5148\u6267\u884C hcm delivery mode --env ${environment} --set plan-only` : "R2 \u547D\u4EE4\u5FC5\u987B\u5728\u88AB\u8BC4\u4F30\u7684 argv \u4E2D\u663E\u5F0F\u5305\u542B --env <\u73AF\u5883\u522B\u540D>"
|
|
8411
8660
|
};
|
|
8412
8661
|
}
|
|
8413
8662
|
if (projectInitialized || !assessment.guardedExecutionAvailable) {
|
|
@@ -8426,7 +8675,7 @@ function withProjectReadiness(assessment, projectRoot = ".") {
|
|
|
8426
8675
|
async function deliveryAssessCommand(argv, args) {
|
|
8427
8676
|
const assessment = await assessEffectiveDeliveryCommand(argv);
|
|
8428
8677
|
const enriched = withProjectReadiness(assessment);
|
|
8429
|
-
process.stdout.write(
|
|
8678
|
+
process.stdout.write(formatObject21(enriched, { format: args.output ?? "json" }) + "\n");
|
|
8430
8679
|
}
|
|
8431
8680
|
async function resolveCoreAction(request) {
|
|
8432
8681
|
try {
|
|
@@ -8535,40 +8784,628 @@ function flagValue2(argv, flag) {
|
|
|
8535
8784
|
|
|
8536
8785
|
// src/commands/delivery-init.ts
|
|
8537
8786
|
init_exit();
|
|
8787
|
+
import { promises as fs8 } from "fs";
|
|
8788
|
+
import path8 from "path";
|
|
8789
|
+
import {
|
|
8790
|
+
formatObject as formatObject22,
|
|
8791
|
+
loadEnv as loadEnv9,
|
|
8792
|
+
loadGlobalConfig as loadGlobalConfig9,
|
|
8793
|
+
resolveActiveEnv as resolveActiveEnv5
|
|
8794
|
+
} from "@hcmai/sdk";
|
|
8795
|
+
|
|
8796
|
+
// src/commands/delivery-project-scaffold.ts
|
|
8538
8797
|
import { promises as fs6 } from "fs";
|
|
8539
8798
|
import path6 from "path";
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8799
|
+
|
|
8800
|
+
// src/commands/delivery-page-acceptance.ts
|
|
8801
|
+
function renderPageAcceptanceSh() {
|
|
8802
|
+
return [
|
|
8803
|
+
"#!/usr/bin/env bash",
|
|
8804
|
+
"set -euo pipefail",
|
|
8805
|
+
"",
|
|
8806
|
+
"usage() {",
|
|
8807
|
+
" cat >&2 <<'USAGE'",
|
|
8808
|
+
"\u7528\u6CD5\uFF1A",
|
|
8809
|
+
" ./page-acceptance.sh --env <\u73AF\u5883> [--as <\u8EAB\u4EFD>] --path </\u7AD9\u5185\u8DEF\u5F84> \\",
|
|
8810
|
+
" --expect-text <\u9875\u9762\u5FC5\u987B\u51FA\u73B0\u7684\u6587\u672C> [--expect-text <\u6587\u672C> ...] \\",
|
|
8811
|
+
" --out <\u8BC1\u636E/.../\u622A\u56FE.png> [--reject-text <\u4E0D\u5F97\u51FA\u73B0\u7684\u6587\u672C>] \\",
|
|
8812
|
+
" [--wait-ms 10000] [--size 1440x900]",
|
|
8813
|
+
"",
|
|
8814
|
+
"\u8BF4\u660E\uFF1A",
|
|
8815
|
+
" - \u8C03\u7528 hcm open \u94F8\u4E00\u6B21\u6027\u767B\u5F55\u7968\u636E\uFF0C\u5E76\u7ACB\u5373\u4EA4\u7ED9\u672C\u673A Chrome/Chromium\u3002",
|
|
8816
|
+
" - \u622A\u56FE\u53EA\u80FD\u5199\u5165\u9879\u76EE\u7684 \u8BC1\u636E/ \u76EE\u5F55\uFF1B\u5DF2\u6709\u6587\u4EF6\u4E0D\u4F1A\u88AB\u8986\u76D6\u3002",
|
|
8817
|
+
" - \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",
|
|
8818
|
+
" - \u6D4F\u89C8\u5668\u672A\u5728 PATH \u65F6\uFF0C\u7528 HCM_CHROME_BIN=/\u7EDD\u5BF9\u8DEF\u5F84 \u6307\u5B9A\u3002",
|
|
8819
|
+
"USAGE",
|
|
8820
|
+
"}",
|
|
8821
|
+
"",
|
|
8822
|
+
"fail() {",
|
|
8823
|
+
` printf '\u9875\u9762\u9A8C\u6536\u5931\u8D25\uFF1A%s\\n' "$1" >&2`,
|
|
8824
|
+
' exit "${2:-1}"',
|
|
8825
|
+
"}",
|
|
8826
|
+
"",
|
|
8827
|
+
"need_value() {",
|
|
8828
|
+
' if (( $# < 2 )) || [[ -z "$2" ]]; then fail "$1 \u7F3A\u5C11\u503C" 2; fi',
|
|
8829
|
+
"}",
|
|
8830
|
+
"",
|
|
8831
|
+
'environment=""',
|
|
8832
|
+
'identity=""',
|
|
8833
|
+
'page_path=""',
|
|
8834
|
+
'output=""',
|
|
8835
|
+
'wait_ms="10000"',
|
|
8836
|
+
'size="1440x900"',
|
|
8837
|
+
"expected_texts=()",
|
|
8838
|
+
"rejected_texts=()",
|
|
8839
|
+
"",
|
|
8840
|
+
"while (( $# > 0 )); do",
|
|
8841
|
+
' case "$1" in',
|
|
8842
|
+
' --env) need_value "$@"; environment="$2"; shift 2 ;;',
|
|
8843
|
+
' --as) need_value "$@"; identity="$2"; shift 2 ;;',
|
|
8844
|
+
' --path) need_value "$@"; page_path="$2"; shift 2 ;;',
|
|
8845
|
+
' --out) need_value "$@"; output="$2"; shift 2 ;;',
|
|
8846
|
+
' --expect-text) need_value "$@"; expected_texts+=("$2"); shift 2 ;;',
|
|
8847
|
+
' --reject-text) need_value "$@"; rejected_texts+=("$2"); shift 2 ;;',
|
|
8848
|
+
' --wait-ms) need_value "$@"; wait_ms="$2"; shift 2 ;;',
|
|
8849
|
+
' --size) need_value "$@"; size="$2"; shift 2 ;;',
|
|
8850
|
+
" -h|--help) usage; exit 0 ;;",
|
|
8851
|
+
' *) fail "\u672A\u77E5\u53C2\u6570\uFF1A$1" 2 ;;',
|
|
8852
|
+
" esac",
|
|
8853
|
+
"done",
|
|
8854
|
+
"",
|
|
8855
|
+
'[[ -n "$environment" ]] || fail "\u5FC5\u987B\u663E\u5F0F\u4F20 --env" 2',
|
|
8856
|
+
'[[ -n "$page_path" ]] || fail "\u5FC5\u987B\u4F20 --path" 2',
|
|
8857
|
+
'[[ "$page_path" == /* ]] || fail "--path \u53EA\u63A5\u53D7\u4EE5 / \u5F00\u5934\u7684\u7AD9\u5185\u8DEF\u5F84" 2',
|
|
8858
|
+
'[[ -n "$output" ]] || fail "\u5FC5\u987B\u4F20 --out" 2',
|
|
8859
|
+
'[[ "$output" == *.png ]] || fail "--out \u5FC5\u987B\u4EE5 .png \u7ED3\u5C3E" 2',
|
|
8860
|
+
'(( ${#expected_texts[@]} > 0 )) || fail "\u81F3\u5C11\u4F20\u4E00\u4E2A --expect-text" 2',
|
|
8861
|
+
'[[ "$wait_ms" =~ ^[0-9]+$ ]] || fail "--wait-ms \u5FC5\u987B\u662F\u6574\u6570" 2',
|
|
8862
|
+
'(( wait_ms >= 0 && wait_ms <= 60000 )) || fail "--wait-ms \u5FC5\u987B\u5728 0..60000" 2',
|
|
8863
|
+
'if [[ "$size" =~ ^([0-9]+)x([0-9]+)$ ]]; then',
|
|
8864
|
+
' width="${BASH_REMATCH[1]}"',
|
|
8865
|
+
' height="${BASH_REMATCH[2]}"',
|
|
8866
|
+
"else",
|
|
8867
|
+
' fail "--size \u5FC5\u987B\u662F <\u5BBD>x<\u9AD8>\uFF0C\u4F8B\u5982 1440x900" 2',
|
|
8868
|
+
"fi",
|
|
8869
|
+
'(( 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',
|
|
8870
|
+
"",
|
|
8871
|
+
'project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"',
|
|
8872
|
+
'evidence_root="$project_root/\u8BC1\u636E"',
|
|
8873
|
+
'[[ -d "$evidence_root" && ! -L "$evidence_root" ]] || fail "\u9879\u76EE\u7684 \u8BC1\u636E/ \u5FC5\u987B\u662F\u666E\u901A\u76EE\u5F55\uFF0C\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5"',
|
|
8874
|
+
`out_abs="$(node -e "const p=require('node:path'); const root=p.resolve(process.argv[1],'\u8BC1\u636E'); 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 \u8BC1\u636E/ \u76EE\u5F55\\n'); process.exit(2)} process.stdout.write(out)" "$project_root" "$output")" || exit $?`,
|
|
8875
|
+
'[[ ! -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"',
|
|
8876
|
+
'mkdir -p "$(dirname "$out_abs")"',
|
|
8877
|
+
'canonical_root="$(cd "$evidence_root" && pwd -P)"',
|
|
8878
|
+
'canonical_parent="$(cd "$(dirname "$out_abs")" && pwd -P)"',
|
|
8879
|
+
'case "$canonical_parent/" in',
|
|
8880
|
+
' "$canonical_root/"*) ;;',
|
|
8881
|
+
' *) fail "--out \u7684\u7236\u76EE\u5F55\u7ECF\u7B26\u53F7\u94FE\u63A5\u9003\u51FA\u4E86 \u8BC1\u636E/\uFF1A$output" ;;',
|
|
8882
|
+
"esac",
|
|
8883
|
+
"",
|
|
8884
|
+
"find_browser() {",
|
|
8885
|
+
' if [[ -n "${HCM_CHROME_BIN:-}" ]]; then',
|
|
8886
|
+
' if [[ -x "$HCM_CHROME_BIN" ]]; then printf "%s" "$HCM_CHROME_BIN"; return 0; fi',
|
|
8887
|
+
' if command -v "$HCM_CHROME_BIN" >/dev/null 2>&1; then command -v "$HCM_CHROME_BIN"; return 0; fi',
|
|
8888
|
+
" return 1",
|
|
8889
|
+
" fi",
|
|
8890
|
+
" local candidate",
|
|
8891
|
+
" for candidate in google-chrome-stable google-chrome chromium chromium-browser; do",
|
|
8892
|
+
' if command -v "$candidate" >/dev/null 2>&1; then command -v "$candidate"; return 0; fi',
|
|
8893
|
+
" done",
|
|
8894
|
+
' for candidate in "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "/Applications/Chromium.app/Contents/MacOS/Chromium"; do',
|
|
8895
|
+
' if [[ -x "$candidate" ]]; then printf "%s" "$candidate"; return 0; fi',
|
|
8896
|
+
" done",
|
|
8897
|
+
" return 1",
|
|
8898
|
+
"}",
|
|
8899
|
+
"",
|
|
8900
|
+
'command -v hcm >/dev/null 2>&1 || fail "\u627E\u4E0D\u5230 hcm\uFF1B\u5148\u8FD0\u884C ./setup.sh"',
|
|
8901
|
+
'browser="$(find_browser)" || fail "\u627E\u4E0D\u5230 Chrome/Chromium\uFF1B\u8BF7\u8BBE\u7F6E HCM_CHROME_BIN"',
|
|
8902
|
+
'temp_dir="$(mktemp -d "${TMPDIR:-/tmp}/hcm-page-acceptance.XXXXXX")"',
|
|
8903
|
+
"cleanup() {",
|
|
8904
|
+
' case "$temp_dir" in "${TMPDIR:-/tmp}"/hcm-page-acceptance.*) rm -rf -- "$temp_dir" ;; esac',
|
|
8905
|
+
"}",
|
|
8906
|
+
"trap cleanup EXIT",
|
|
8907
|
+
'dom_file="$temp_dir/page.dom"',
|
|
8908
|
+
'browser_log="$temp_dir/browser.log"',
|
|
8909
|
+
"",
|
|
8910
|
+
'hcm_args=(open "$page_path" --env "$environment")',
|
|
8911
|
+
'if [[ -n "$identity" ]]; then hcm_args+=(--as "$identity"); fi',
|
|
8912
|
+
"hcm_args+=(--print-url)",
|
|
8913
|
+
'url="$(hcm "${hcm_args[@]}")" || fail "hcm open \u672A\u80FD\u94F8\u51FA\u9875\u9762\u7968\u636E"',
|
|
8914
|
+
`url="\${url//$'\\r'/}"`,
|
|
8915
|
+
'[[ "$url" == http://* || "$url" == https://* ]] || fail "hcm open \u6CA1\u6709\u8FD4\u56DE\u6709\u6548 URL"',
|
|
8916
|
+
"",
|
|
8917
|
+
"browser_args=(",
|
|
8918
|
+
" --headless=new",
|
|
8919
|
+
" --disable-gpu",
|
|
8920
|
+
" --disable-dev-shm-usage",
|
|
8921
|
+
" --hide-scrollbars",
|
|
8922
|
+
" --no-first-run",
|
|
8923
|
+
" --no-default-browser-check",
|
|
8924
|
+
' "--window-size=$size"',
|
|
8925
|
+
' "--virtual-time-budget=$wait_ms"',
|
|
8926
|
+
' "--screenshot=$out_abs"',
|
|
8927
|
+
" --dump-dom",
|
|
8928
|
+
")",
|
|
8929
|
+
'if [[ "$(id -u)" == "0" ]]; then browser_args+=(--no-sandbox); fi',
|
|
8930
|
+
'if ! "$browser" "${browser_args[@]}" "$url" >"$dom_file" 2>"$browser_log"; then',
|
|
8931
|
+
' sed -E "s/(ticket=)[^&[:space:]]+/\\1<redacted>/g" "$browser_log" >&2 || true',
|
|
8932
|
+
' fail "\u6D4F\u89C8\u5668\u622A\u56FE\u8FDB\u7A0B\u5931\u8D25"',
|
|
8933
|
+
"fi",
|
|
8934
|
+
'[[ -s "$out_abs" ]] || fail "\u6D4F\u89C8\u5668\u672A\u751F\u6210\u975E\u7A7A PNG\uFF1A$out_abs"',
|
|
8935
|
+
"",
|
|
8936
|
+
'for text in "${expected_texts[@]}"; do',
|
|
8937
|
+
' grep -Fq -- "$text" "$dom_file" || fail "\u9875\u9762\u672A\u51FA\u73B0\u671F\u671B\u6587\u672C\uFF1A$text\uFF08\u622A\u56FE\u5DF2\u4FDD\u7559\uFF09"',
|
|
8938
|
+
"done",
|
|
8939
|
+
'for text in "${rejected_texts[@]}"; do',
|
|
8940
|
+
' if grep -Fq -- "$text" "$dom_file"; then fail "\u9875\u9762\u51FA\u73B0\u62D2\u7EDD\u6587\u672C\uFF1A$text\uFF08\u622A\u56FE\u5DF2\u4FDD\u7559\uFF09"; fi',
|
|
8941
|
+
"done",
|
|
8942
|
+
"",
|
|
8943
|
+
'browser_version="$("$browser" --version 2>/dev/null | head -n 1 || true)"',
|
|
8944
|
+
`node -e "const fs=require('node:fs'); const result={ok:true,screenshot:process.argv[1],bytes:fs.statSync(process.argv[1]).size,environment:process.argv[2],identity:process.argv[3]||null,path:process.argv[4],viewport:process.argv[5],waitMs:Number(process.argv[6]),browser:process.argv[7]}; process.stdout.write(JSON.stringify(result)+'\\n')" "$out_abs" "$environment" "$identity" "$page_path" "$size" "$wait_ms" "$browser_version"`,
|
|
8945
|
+
""
|
|
8946
|
+
].join("\n");
|
|
8947
|
+
}
|
|
8948
|
+
|
|
8949
|
+
// src/commands/delivery-project-scaffold.ts
|
|
8950
|
+
var AGENT_BEGIN = "<!-- hcm-delivery-project:begin -->";
|
|
8951
|
+
var AGENT_END = "<!-- hcm-delivery-project:end -->";
|
|
8952
|
+
var GITIGNORE_BEGIN = "# >>> hcm delivery local state >>>";
|
|
8953
|
+
var GITIGNORE_END = "# <<< hcm delivery local state <<<";
|
|
8954
|
+
var DELIVERY_PROJECT_DIRECTORIES = [
|
|
8955
|
+
"work",
|
|
8956
|
+
"decisions",
|
|
8957
|
+
"evidence",
|
|
8958
|
+
"hcm-skills",
|
|
8959
|
+
"\u5BA2\u6237\u8D44\u6599",
|
|
8960
|
+
"\u9700\u6C42",
|
|
8961
|
+
"\u4EA4\u4ED8\u7269",
|
|
8962
|
+
"\u8BC1\u636E",
|
|
8963
|
+
"\u51B3\u7B56",
|
|
8964
|
+
"\u6848\u4F8B"
|
|
8965
|
+
];
|
|
8966
|
+
function renderEnvironmentYml(environment, config2, initialMode) {
|
|
8967
|
+
const endpoint = config2?.endpoint ?? "REPLACE_ME";
|
|
8968
|
+
const frontend = config2?.frontend ?? endpoint;
|
|
8969
|
+
const tenant2 = config2?.tenantId ?? "1";
|
|
8970
|
+
return [
|
|
8971
|
+
"# \u5BA2\u6237\u9879\u76EE\u5171\u4EAB\u73AF\u5883\u6E05\u5355\uFF08\u4E0D\u653E\u8EAB\u4EFD\u6216\u51ED\u636E\uFF09",
|
|
8972
|
+
"# owner \u4E0E controlled \u7531\u9879\u76EE\u8D1F\u8D23\u4EBA\u8BC4\u5BA1\uFF1B\u4E2A\u4EBA\u673A\u5668\u4E0A\u7684\u5B9E\u9645\u6A21\u5F0F\u5728 .hcm-delivery/project.yml\u3002",
|
|
8973
|
+
"schemaVersion: 1",
|
|
8974
|
+
"environments:",
|
|
8975
|
+
` - alias: ${JSON.stringify(environment)}`,
|
|
8976
|
+
` endpoint: ${JSON.stringify(endpoint)}`,
|
|
8977
|
+
` frontend: ${JSON.stringify(frontend)}`,
|
|
8978
|
+
` tenant: ${JSON.stringify(tenant2)}`,
|
|
8979
|
+
` controlled: ${initialMode === "controlled" ? "true" : "false"}`,
|
|
8980
|
+
' owner: "TODO: \u9879\u76EE\u8D1F\u8D23\u4EBA"',
|
|
8981
|
+
""
|
|
8982
|
+
].join("\n");
|
|
8983
|
+
}
|
|
8984
|
+
function renderAgentInstructions() {
|
|
8985
|
+
return [
|
|
8986
|
+
AGENT_BEGIN,
|
|
8987
|
+
"# HCM \u987E\u95EE\u9879\u76EE\u8FB9\u754C",
|
|
8988
|
+
"",
|
|
8989
|
+
"- \u53EA\u4F7F\u7528\u672C\u9879\u76EE\u5185\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",
|
|
8990
|
+
"- \u6BCF\u6B21\u5F00\u5DE5\u5148\u53EA\u8BFB\u6838\u5BF9 CLI \u7248\u672C\u3001\u76EE\u6807\u73AF\u5883\u3001\u8EAB\u4EFD\u3001\u6280\u80FD\u9501\u4E0E `hcm delivery doctor`\uFF1B\u73AF\u5883\u4E8B\u5B9E\u5FC5\u987B\u73B0\u67E5\uFF0C\u4E0D\u51ED\u8BB0\u5FC6\u586B\u5199\u3002",
|
|
8991
|
+
"- R2 \u5199\u64CD\u4F5C\u5FC5\u987B\u4F9D\u6B21\u7ECF\u8FC7 `hcm delivery assess`\u3001`prepare`\u3001`execute`\uFF0C\u88AB\u6267\u884C argv \u5FC5\u987B\u663E\u5F0F\u5E26 `--env` \u4E0E `--as`\u3002",
|
|
8992
|
+
"- R2 \u5199\u6388\u6743\u53EA\u8BA4\u53EF\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728**\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66**\u91CC\u7684\u660E\u786E\u6279\u51C6\uFF1B\u5BA2\u6237\u53E3\u5934\u8981\u6C42\u6216\u7FA4\u6D88\u606F\u53EA\u662F\u4E1A\u52A1\u9700\u6C42\uFF0C\u4E0D\u662F\u6267\u884C\u6388\u6743\uFF0C\u4E0D\u80FD\u636E\u6B64\u5207\u5230 controlled \u6216\u6267\u884C\u3002",
|
|
8993
|
+
"- \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",
|
|
8994
|
+
"- `.hcm-delivery/project.yml` \u662F\u6BCF\u4EBA\u6BCF\u673A\u72B6\u6001\uFF0C\u4E0D\u63D0\u4EA4\uFF1B\u53EA\u6709 `\u73AF\u5883.yml` \u4E2D `controlled: true` \u4E14\u6EE1\u8DB3\u4E0A\u8FF0\u6388\u6743\u65F6\uFF0C\u624D\u80FD\u7528 `--approved-by` \u4E0E `--reason` \u7559\u4E0B\u6A21\u5F0F\u5207\u6362\u6536\u636E\uFF0C\u5B8C\u6210\u540E\u7ACB\u5373\u56DE\u5230 plan-only\u3002\u5BA1\u8BA1\u53C2\u6570\u4E0D\u80FD\u66FF\u4EE3\u771F\u5B9E\u6388\u6743\u3002",
|
|
8995
|
+
"- \u53D8\u66F4/\u56DE\u6EDA\u8BF4\u660E\u653E CLI \u56FA\u5B9A\u7684 `work/` \u6216 `decisions/`\uFF0C\u6536\u636E\u653E `evidence/`\uFF1B\u5BA2\u6237\u5171\u4EAB\u6750\u6599\u5206\u522B\u5F52\u6863\u5230\u4E2D\u6587\u4E1A\u52A1\u76EE\u5F55\u3002",
|
|
8996
|
+
"- \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 `\u8BC1\u636E/` \u4E0B\u7684 PNG \u8DEF\u5F84\uFF1B\u4E0D\u80FD\u53EA\u4EE5\u201C\u751F\u6210\u4E86\u622A\u56FE\u201D\u5224\u901A\u8FC7\u3002",
|
|
8997
|
+
"- \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",
|
|
8998
|
+
AGENT_END,
|
|
8999
|
+
""
|
|
9000
|
+
].join("\n");
|
|
9001
|
+
}
|
|
9002
|
+
function renderSetupSh(cliVersion) {
|
|
9003
|
+
return [
|
|
9004
|
+
"#!/usr/bin/env bash",
|
|
9005
|
+
"set -euo pipefail",
|
|
9006
|
+
"",
|
|
9007
|
+
`expected_hcm_version=${JSON.stringify(cliVersion)}`,
|
|
9008
|
+
'actual_hcm_version="$(hcm --version 2>/dev/null || true)"',
|
|
9009
|
+
'if [[ "$actual_hcm_version" != "$expected_hcm_version" ]]; then',
|
|
9010
|
+
` printf '\u9700\u8981 hcm %s\uFF0C\u5F53\u524D\u662F %s\u3002\u5148\u6267\u884C\uFF1Anpm install --global @hcmai/cli@%s\\n' "$expected_hcm_version" "\${actual_hcm_version:-\u672A\u5B89\u88C5}" "$expected_hcm_version" >&2`,
|
|
9011
|
+
" exit 1",
|
|
9012
|
+
"fi",
|
|
9013
|
+
"",
|
|
9014
|
+
"node <<'HCM_PROJECT_SETUP'",
|
|
9015
|
+
"const fs = require('node:fs');",
|
|
9016
|
+
"const path = require('node:path');",
|
|
9017
|
+
"const { spawnSync } = require('node:child_process');",
|
|
9018
|
+
"",
|
|
9019
|
+
"const project = process.cwd();",
|
|
9020
|
+
"const environmentsFile = path.join(project, '\u73AF\u5883.yml');",
|
|
9021
|
+
"const projectFile = path.join(project, '.hcm-delivery', 'project.yml');",
|
|
9022
|
+
"const skillsLock = path.join(project, 'hcm-skills', '.hcm-skills.json');",
|
|
9023
|
+
"const source = fs.readFileSync(environmentsFile, 'utf8');",
|
|
9024
|
+
"const environments = parseEnvironments(source);",
|
|
9025
|
+
"if (environments.length === 0) throw new Error('\u73AF\u5883.yml \u81F3\u5C11\u8981\u6709\u4E00\u4E2A\u73AF\u5883');",
|
|
9026
|
+
"",
|
|
9027
|
+
"const missingEnvironments = new Set();",
|
|
9028
|
+
"for (const environment of environments) {",
|
|
9029
|
+
" const probe = spawnSync('hcm', ['env', 'show', environment.alias], { encoding: 'utf8' });",
|
|
9030
|
+
" if (probe.error) throw new Error(`\u65E0\u6CD5\u68C0\u67E5\u73AF\u5883 ${environment.alias}\uFF1A${probe.error.message}`);",
|
|
9031
|
+
" if (probe.status === 0) {",
|
|
9032
|
+
" const existing = parseExistingEnvironment(probe.stdout, environment.alias);",
|
|
9033
|
+
" assertEnvironmentMatches(environment, existing);",
|
|
9034
|
+
" process.stdout.write(`[setup] env ${environment.alias} \u5DF2\u5B58\u5728\u4E14\u4E0E \u73AF\u5883.yml \u4E00\u81F4\uFF0C\u4FDD\u7559\u672C\u673A\u8EAB\u4EFD\\n`);",
|
|
9035
|
+
" continue;",
|
|
9036
|
+
" }",
|
|
9037
|
+
" if (/\\bENV_NOT_FOUND\\b/.test(probe.stderr)) {",
|
|
9038
|
+
" missingEnvironments.add(environment.alias);",
|
|
9039
|
+
" continue;",
|
|
9040
|
+
" }",
|
|
9041
|
+
" const detail = probe.stderr.trim() || `\u9000\u51FA\u7801 ${probe.status ?? 'unknown'}`;",
|
|
9042
|
+
" throw new Error(`\u65E0\u6CD5\u68C0\u67E5\u73AF\u5883 ${environment.alias}\uFF1A${detail}`);",
|
|
9043
|
+
"}",
|
|
9044
|
+
"",
|
|
9045
|
+
"let projectInitialized = fs.existsSync(projectFile);",
|
|
9046
|
+
"for (const environment of environments) {",
|
|
9047
|
+
" if (missingEnvironments.has(environment.alias)) {",
|
|
9048
|
+
" const add = ['env', 'add', environment.alias, '--endpoint', environment.endpoint];",
|
|
9049
|
+
" if (environment.frontend) add.push('--frontend', environment.frontend);",
|
|
9050
|
+
" if (environment.tenant) add.push('--tenant', environment.tenant);",
|
|
9051
|
+
" run(add);",
|
|
9052
|
+
" }",
|
|
9053
|
+
" if (!projectInitialized) {",
|
|
9054
|
+
" run(['delivery', 'init', '--project', project, '--env', environment.alias, '--mode', 'plan-only']);",
|
|
9055
|
+
" projectInitialized = true;",
|
|
9056
|
+
" } else {",
|
|
9057
|
+
" run(['delivery', 'mode', '--project', project, '--env', environment.alias, '--set', 'plan-only']);",
|
|
9058
|
+
" }",
|
|
9059
|
+
"}",
|
|
9060
|
+
"",
|
|
9061
|
+
"if (!fs.existsSync(skillsLock)) {",
|
|
9062
|
+
" run(['skills', 'install', '--all', '--target', 'codex', '--env', environments[0].alias]);",
|
|
9063
|
+
"} else {",
|
|
9064
|
+
" process.stdout.write('[setup] \u5DF2\u6709 hcm-skills \u9501\uFF0C\u6309\u4ED3\u5E93\u7248\u672C\u4F7F\u7528\uFF1B\u5347\u7EA7\u6280\u80FD\u8BF7\u53E6\u8D70 PR\\n');",
|
|
9065
|
+
"}",
|
|
9066
|
+
'process.stdout.write("[setup] \u5B8C\u6210\u3002\u4E0B\u4E00\u6B65\uFF1A\u9010\u4E2A\u6267\u884C hcm login --env <alias> --code <\u914D\u5BF9\u7801> --name <\u4F60\u7684\u540D\u5B57>-<alias>\\n");',
|
|
9067
|
+
"",
|
|
9068
|
+
"function run(args) {",
|
|
9069
|
+
" const result = spawnSync('hcm', args, { cwd: project, stdio: 'inherit' });",
|
|
9070
|
+
" if (result.error) throw new Error(`\u65E0\u6CD5\u6267\u884C hcm ${args.join(' ')}\uFF1A${result.error.message}`);",
|
|
9071
|
+
" if (result.status !== 0) process.exit(result.status ?? 1);",
|
|
9072
|
+
"}",
|
|
9073
|
+
"",
|
|
9074
|
+
"function parseEnvironments(text) {",
|
|
9075
|
+
" const result = [];",
|
|
9076
|
+
" let current = null;",
|
|
9077
|
+
" let inEnvironments = false;",
|
|
9078
|
+
" for (const [offset, rawLine] of text.split(/\\r?\\n/).entries()) {",
|
|
9079
|
+
" const lineNo = offset + 1;",
|
|
9080
|
+
' if (!rawLine.trim() || rawLine.trimStart().startsWith("#")) continue;',
|
|
9081
|
+
" if (/^schemaVersion:\\s*1\\s*$/.test(rawLine)) continue;",
|
|
9082
|
+
" if (/^environments:\\s*$/.test(rawLine)) { inEnvironments = true; continue; }",
|
|
9083
|
+
" if (!inEnvironments) throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u4E0D\u5C5E\u4E8E environments`);",
|
|
9084
|
+
" const first = rawLine.match(/^ {2}- alias:\\s*(.+)$/);",
|
|
9085
|
+
" if (first) {",
|
|
9086
|
+
" if (current) result.push(validateEnvironment(current, lineNo));",
|
|
9087
|
+
" current = { alias: scalar(first[1], lineNo) };",
|
|
9088
|
+
" continue;",
|
|
9089
|
+
" }",
|
|
9090
|
+
" const field = rawLine.match(/^ {4}(endpoint|frontend|tenant|controlled|owner):\\s*(.+)$/);",
|
|
9091
|
+
" if (!field || !current) throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u4E0D\u7B26\u5408\u811A\u624B\u67B6\u683C\u5F0F`);",
|
|
9092
|
+
" current[field[1]] = scalar(field[2], lineNo);",
|
|
9093
|
+
" }",
|
|
9094
|
+
" if (current) result.push(validateEnvironment(current, text.split(/\\r?\\n/).length));",
|
|
9095
|
+
" return result;",
|
|
9096
|
+
"}",
|
|
9097
|
+
"",
|
|
9098
|
+
"function scalar(raw, lineNo) {",
|
|
9099
|
+
" const value = raw.trim();",
|
|
9100
|
+
` if (value.startsWith('"')) {`,
|
|
9101
|
+
" try { return JSON.parse(value); } catch { throw new Error(`\u73AF\u5883.yml \u7B2C ${lineNo} \u884C\u7684\u53CC\u5F15\u53F7\u503C\u975E\u6CD5`); }",
|
|
9102
|
+
" }",
|
|
9103
|
+
` if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1).replace(/''/g, "'");`,
|
|
9104
|
+
' const plain = value.replace(/\\s+#.*$/, "").trim();',
|
|
9105
|
+
' if (plain === "true") return true;',
|
|
9106
|
+
' if (plain === "false") return false;',
|
|
9107
|
+
" return plain;",
|
|
9108
|
+
"}",
|
|
9109
|
+
"",
|
|
9110
|
+
"function validateEnvironment(environment, lineNo) {",
|
|
9111
|
+
' for (const key of ["alias", "endpoint"]) {',
|
|
9112
|
+
' if (typeof environment[key] !== "string" || !environment[key].trim()) {',
|
|
9113
|
+
" throw new Error(`\u73AF\u5883.yml \u622A\u81F3\u7B2C ${lineNo} \u884C\u7F3A\u5C11 ${key}`);",
|
|
9114
|
+
" }",
|
|
9115
|
+
" }",
|
|
9116
|
+
' if (environment.endpoint === "REPLACE_ME") {',
|
|
9117
|
+
" throw new Error(`\u73AF\u5883 ${environment.alias} \u7684 endpoint \u4ECD\u662F REPLACE_ME\uFF0C\u8BF7\u5148\u7F16\u8F91 \u73AF\u5883.yml`);",
|
|
9118
|
+
" }",
|
|
9119
|
+
" if (environment.controlled !== true && environment.controlled !== false) {",
|
|
9120
|
+
" throw new Error(`\u73AF\u5883 ${environment.alias} \u7684 controlled \u5FC5\u987B\u662F true \u6216 false`);",
|
|
9121
|
+
" }",
|
|
9122
|
+
' for (const key of ["frontend", "tenant"]) {',
|
|
9123
|
+
' if (environment[key] !== undefined && typeof environment[key] !== "string") {',
|
|
9124
|
+
" environment[key] = String(environment[key]);",
|
|
9125
|
+
" }",
|
|
9126
|
+
" }",
|
|
9127
|
+
" return environment;",
|
|
9128
|
+
"}",
|
|
9129
|
+
"",
|
|
9130
|
+
"function parseExistingEnvironment(text, alias) {",
|
|
9131
|
+
" const result = {};",
|
|
9132
|
+
" for (const [offset, rawLine] of text.split(/\\r?\\n/).entries()) {",
|
|
9133
|
+
' if (!rawLine.trim() || rawLine.startsWith(" ") || rawLine.trimStart().startsWith("#")) continue;',
|
|
9134
|
+
" const field = rawLine.match(/^(endpoint|frontend|tenantId):\\s*(.+)$/);",
|
|
9135
|
+
" if (field) result[field[1]] = scalar(field[2], offset + 1);",
|
|
9136
|
+
" }",
|
|
9137
|
+
' if (typeof result.endpoint !== "string" || !result.endpoint) {',
|
|
9138
|
+
" throw new Error(`hcm env show ${alias} \u672A\u8FD4\u56DE\u6709\u6548 endpoint\uFF0C\u62D2\u7EDD\u7EE7\u7EED`);",
|
|
9139
|
+
" }",
|
|
9140
|
+
" return result;",
|
|
9141
|
+
"}",
|
|
9142
|
+
"",
|
|
9143
|
+
"function assertEnvironmentMatches(expected, actual) {",
|
|
9144
|
+
" const fields = [",
|
|
9145
|
+
' ["endpoint", expected.endpoint, actual.endpoint],',
|
|
9146
|
+
' ["frontend", expected.frontend ?? "", actual.frontend ?? ""],',
|
|
9147
|
+
' ["tenant", expected.tenant ?? "1", actual.tenantId ?? "1"],',
|
|
9148
|
+
" ];",
|
|
9149
|
+
" const mismatches = fields",
|
|
9150
|
+
" .filter(([, wanted, found]) => String(wanted) !== String(found))",
|
|
9151
|
+
" .map(([name, wanted, found]) => `${name}: \u9879\u76EE=${JSON.stringify(wanted)} \u672C\u673A=${JSON.stringify(found)}`);",
|
|
9152
|
+
" if (mismatches.length === 0) return;",
|
|
9153
|
+
" throw new Error(",
|
|
9154
|
+
' `\u73AF\u5883 ${expected.alias} \u5DF2\u5B58\u5728\uFF0C\u4F46\u672C\u673A\u914D\u7F6E\u4E0E \u73AF\u5883.yml \u4E0D\u4E00\u81F4\uFF1A${mismatches.join("\uFF1B")}\u3002` +',
|
|
9155
|
+
' "\u4E3A\u4FDD\u62A4\u672C\u673A\u5DF2\u6709\u8EAB\u4EFD\uFF0Csetup.sh \u4E0D\u4F1A\u7528 --force \u8986\u76D6\uFF1B\u8BF7\u6838\u5BF9\u540E\u663E\u5F0F\u4FEE\u6B63\u672C\u673A\u73AF\u5883\u6216 \u73AF\u5883.yml\u3002",',
|
|
9156
|
+
" );",
|
|
9157
|
+
"}",
|
|
9158
|
+
"HCM_PROJECT_SETUP",
|
|
9159
|
+
""
|
|
9160
|
+
].join("\n");
|
|
9161
|
+
}
|
|
9162
|
+
function mergeDeliveryGitignore(existing) {
|
|
9163
|
+
const block = [
|
|
9164
|
+
GITIGNORE_BEGIN,
|
|
9165
|
+
".hcm-delivery/project.yml",
|
|
9166
|
+
".hcm-delivery/execution-plans/",
|
|
9167
|
+
".hcm-delivery/execution-claims/",
|
|
9168
|
+
GITIGNORE_END
|
|
9169
|
+
].join("\n");
|
|
9170
|
+
return upsertBlock(existing, GITIGNORE_BEGIN, GITIGNORE_END, block);
|
|
9171
|
+
}
|
|
9172
|
+
function mergeAgentInstructions(existing) {
|
|
9173
|
+
return upsertBlock(
|
|
9174
|
+
existing,
|
|
9175
|
+
AGENT_BEGIN,
|
|
9176
|
+
AGENT_END,
|
|
9177
|
+
renderAgentInstructions().trimEnd()
|
|
9178
|
+
);
|
|
9179
|
+
}
|
|
9180
|
+
async function scaffoldDeliveryProject(root, options) {
|
|
9181
|
+
const result = { created: [], updated: [], preserved: [] };
|
|
9182
|
+
for (const directory of DELIVERY_PROJECT_DIRECTORIES) {
|
|
9183
|
+
const absolute = path6.join(root, directory);
|
|
9184
|
+
await ensureDirectory(absolute);
|
|
9185
|
+
await writeIfAbsent(path6.join(absolute, ".gitkeep"), "", result, `${directory}/.gitkeep`);
|
|
9186
|
+
}
|
|
9187
|
+
await writeIfAbsent(
|
|
9188
|
+
path6.join(root, "\u73AF\u5883.yml"),
|
|
9189
|
+
renderEnvironmentYml(options.environment, options.environmentConfig, options.initialMode),
|
|
9190
|
+
result,
|
|
9191
|
+
"\u73AF\u5883.yml"
|
|
9192
|
+
);
|
|
9193
|
+
const setupFile = path6.join(root, "setup.sh");
|
|
9194
|
+
const setupCreated = await writeIfAbsent(
|
|
9195
|
+
setupFile,
|
|
9196
|
+
renderSetupSh(options.cliVersion),
|
|
9197
|
+
result,
|
|
9198
|
+
"setup.sh",
|
|
9199
|
+
493
|
|
9200
|
+
);
|
|
9201
|
+
if (setupCreated) await fs6.chmod(setupFile, 493);
|
|
9202
|
+
const pageAcceptanceFile = path6.join(root, "page-acceptance.sh");
|
|
9203
|
+
const pageAcceptanceCreated = await writeIfAbsent(
|
|
9204
|
+
pageAcceptanceFile,
|
|
9205
|
+
renderPageAcceptanceSh(),
|
|
9206
|
+
result,
|
|
9207
|
+
"page-acceptance.sh",
|
|
9208
|
+
493
|
|
9209
|
+
);
|
|
9210
|
+
if (pageAcceptanceCreated) await fs6.chmod(pageAcceptanceFile, 493);
|
|
9211
|
+
await mergeManagedFile(path6.join(root, "AGENTS.md"), mergeAgentInstructions, result, "AGENTS.md");
|
|
9212
|
+
await mergeManagedFile(path6.join(root, "CLAUDE.md"), mergeAgentInstructions, result, "CLAUDE.md");
|
|
9213
|
+
await mergeManagedFile(path6.join(root, ".gitignore"), mergeDeliveryGitignore, result, ".gitignore");
|
|
9214
|
+
return result;
|
|
9215
|
+
}
|
|
9216
|
+
async function mergeManagedFile(file, merge, result, relative2) {
|
|
9217
|
+
const existing = await readRegularFile(file);
|
|
9218
|
+
const next = merge(existing ?? "");
|
|
9219
|
+
if (existing === next) {
|
|
9220
|
+
result.preserved.push(relative2);
|
|
9221
|
+
return;
|
|
9222
|
+
}
|
|
9223
|
+
await fs6.writeFile(file, next, { encoding: "utf8", mode: 420 });
|
|
9224
|
+
(existing === null ? result.created : result.updated).push(relative2);
|
|
9225
|
+
}
|
|
9226
|
+
async function writeIfAbsent(file, content, result, relative2, mode = 420) {
|
|
9227
|
+
try {
|
|
9228
|
+
await fs6.writeFile(file, content, { encoding: "utf8", mode, flag: "wx" });
|
|
9229
|
+
result.created.push(relative2);
|
|
9230
|
+
return true;
|
|
9231
|
+
} catch (cause) {
|
|
9232
|
+
if (cause.code !== "EEXIST") throw cause;
|
|
9233
|
+
await assertRegularFile(file);
|
|
9234
|
+
result.preserved.push(relative2);
|
|
9235
|
+
return false;
|
|
9236
|
+
}
|
|
9237
|
+
}
|
|
9238
|
+
async function ensureDirectory(directory) {
|
|
9239
|
+
await fs6.mkdir(directory, { recursive: true });
|
|
9240
|
+
const stat = await fs6.lstat(directory);
|
|
9241
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
9242
|
+
throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
|
|
9243
|
+
}
|
|
9244
|
+
}
|
|
9245
|
+
async function readRegularFile(file) {
|
|
9246
|
+
try {
|
|
9247
|
+
await assertRegularFile(file);
|
|
9248
|
+
return await fs6.readFile(file, "utf8");
|
|
9249
|
+
} catch (cause) {
|
|
9250
|
+
if (cause.code === "ENOENT") return null;
|
|
9251
|
+
throw cause;
|
|
9252
|
+
}
|
|
9253
|
+
}
|
|
9254
|
+
async function assertRegularFile(file) {
|
|
9255
|
+
const stat = await fs6.lstat(file);
|
|
9256
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
9257
|
+
throw new Error(`\u811A\u624B\u67B6\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${file}`);
|
|
9258
|
+
}
|
|
9259
|
+
}
|
|
9260
|
+
function upsertBlock(existing, begin, end, block) {
|
|
9261
|
+
const start = existing.indexOf(begin);
|
|
9262
|
+
const finish = existing.indexOf(end);
|
|
9263
|
+
const markersAreMalformed = start < 0 !== finish < 0 || start >= 0 && (finish < start || existing.lastIndexOf(begin) !== start || existing.lastIndexOf(end) !== finish);
|
|
9264
|
+
if (markersAreMalformed) {
|
|
9265
|
+
throw new Error(`\u6258\u7BA1\u5757\u6807\u8BB0\u635F\u574F\u6216\u91CD\u590D\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A${begin} \u2026 ${end}`);
|
|
9266
|
+
}
|
|
9267
|
+
let next;
|
|
9268
|
+
if (start >= 0 && finish >= start) {
|
|
9269
|
+
next = `${existing.slice(0, start)}${block}${existing.slice(finish + end.length)}`;
|
|
9270
|
+
} else {
|
|
9271
|
+
const prefix = existing.trimEnd();
|
|
9272
|
+
next = `${prefix}${prefix ? "\n\n" : ""}${block}`;
|
|
9273
|
+
}
|
|
9274
|
+
return `${next.trimEnd()}
|
|
9275
|
+
`;
|
|
9276
|
+
}
|
|
9277
|
+
|
|
9278
|
+
// src/commands/delivery-mode-approval.ts
|
|
9279
|
+
import { randomUUID } from "crypto";
|
|
9280
|
+
import { promises as fs7 } from "fs";
|
|
9281
|
+
import path7 from "path";
|
|
9282
|
+
function requireControlledModeApproval(mode, approvedBy, reason) {
|
|
9283
|
+
if (mode !== "controlled") return null;
|
|
9284
|
+
const approver = approvedBy?.trim() ?? "";
|
|
9285
|
+
const approvalReason = reason?.trim() ?? "";
|
|
9286
|
+
if (!approver || !approvalReason) {
|
|
9287
|
+
throw new Error(
|
|
9288
|
+
"\u5207\u6362\u5230 controlled \u5FC5\u987B\u540C\u65F6\u4F20 --approved-by <\u9879\u76EE\u8D1F\u8D23\u4EBA> \u4E0E --reason <\u672C\u6B21\u660E\u786E\u6388\u6743\u4F9D\u636E>\u3002\u6388\u6743\u5FC5\u987B\u6765\u81EA\u9879\u76EE\u8D1F\u8D23\u4EBA\u5728\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u660E\u786E\u6279\u51C6\uFF1B\u5BA2\u6237\u53E3\u5934\u6216\u7FA4\u6D88\u606F\u4E0D\u662F\u6267\u884C\u6388\u6743"
|
|
9289
|
+
);
|
|
9290
|
+
}
|
|
9291
|
+
return { approvedBy: approver, reason: approvalReason };
|
|
9292
|
+
}
|
|
9293
|
+
async function setDeliveryModeWithReceipt(input) {
|
|
9294
|
+
const approval = requireControlledModeApproval(input.mode, input.approvedBy, input.reason);
|
|
9295
|
+
const root = path7.resolve(input.project);
|
|
9296
|
+
const projectFile = path7.join(root, ".hcm-delivery", "project.yml");
|
|
9297
|
+
const content = await fs7.readFile(projectFile, "utf8").catch((cause) => {
|
|
9298
|
+
throw new Error(`\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${projectFile}
|
|
9299
|
+
\u4E0B\u4E00\u6B65\uFF1Ahcm delivery init`, {
|
|
9300
|
+
cause
|
|
9301
|
+
});
|
|
9302
|
+
});
|
|
9303
|
+
const update = setDeliveryModeForEnvironment(content, input.environment, input.mode);
|
|
9304
|
+
const changed = (input.now ?? (() => /* @__PURE__ */ new Date()))();
|
|
9305
|
+
if (Number.isNaN(changed.getTime())) throw new Error("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
|
|
9306
|
+
let receiptFile = null;
|
|
9307
|
+
if (approval) {
|
|
9308
|
+
const relativeDirectory = path7.join("evidence", "delivery-mode");
|
|
9309
|
+
await ensureReceiptDirectory(root);
|
|
9310
|
+
const safeTime = changed.toISOString().replace(/[:.]/g, "-");
|
|
9311
|
+
const id = (input.receiptId ?? randomUUID)();
|
|
9312
|
+
if (!/^[a-zA-Z0-9-]+$/.test(id)) throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E ID \u975E\u6CD5");
|
|
9313
|
+
receiptFile = path7.join(relativeDirectory, `${safeTime}-${id}.receipt.json`);
|
|
9314
|
+
}
|
|
9315
|
+
const receipt = {
|
|
9316
|
+
schemaVersion: 1,
|
|
9317
|
+
receiptType: "delivery-mode-change",
|
|
9318
|
+
changedAt: changed.toISOString(),
|
|
9319
|
+
project: root,
|
|
9320
|
+
projectFile,
|
|
9321
|
+
environment: input.environment,
|
|
9322
|
+
previous: update.previous,
|
|
9323
|
+
deliveryMode: input.mode,
|
|
9324
|
+
canExecuteR2: input.mode === "controlled",
|
|
9325
|
+
migratedLegacy: update.migratedLegacy,
|
|
9326
|
+
approvedBy: approval?.approvedBy ?? null,
|
|
9327
|
+
reason: approval?.reason ?? null,
|
|
9328
|
+
receiptFile
|
|
9329
|
+
};
|
|
9330
|
+
await fs7.writeFile(projectFile, update.content, "utf8");
|
|
9331
|
+
if (receiptFile) {
|
|
9332
|
+
try {
|
|
9333
|
+
await fs7.writeFile(path7.join(root, receiptFile), `${JSON.stringify(receipt, null, 2)}
|
|
9334
|
+
`, {
|
|
9335
|
+
encoding: "utf8",
|
|
9336
|
+
mode: 384,
|
|
9337
|
+
flag: "wx"
|
|
9338
|
+
});
|
|
9339
|
+
} catch (cause) {
|
|
9340
|
+
try {
|
|
9341
|
+
await fs7.writeFile(projectFile, content, "utf8");
|
|
9342
|
+
} catch (rollbackCause) {
|
|
9343
|
+
throw new Error(
|
|
9344
|
+
`\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF0C\u4E14 project.yml \u56DE\u6EDA\u5931\u8D25\uFF1A${String(rollbackCause.message)}`,
|
|
9345
|
+
{ cause }
|
|
9346
|
+
);
|
|
9347
|
+
}
|
|
9348
|
+
throw new Error("\u6A21\u5F0F\u5207\u6362\u6536\u636E\u5199\u5165\u5931\u8D25\uFF1Bproject.yml \u5DF2\u56DE\u6EDA\uFF0C\u4ECD\u4FDD\u6301\u539F\u6A21\u5F0F", { cause });
|
|
9349
|
+
}
|
|
9350
|
+
}
|
|
9351
|
+
return receipt;
|
|
9352
|
+
}
|
|
9353
|
+
async function ensureReceiptDirectory(root) {
|
|
9354
|
+
const evidenceDirectory = path7.join(root, "evidence");
|
|
9355
|
+
await ensurePlainDirectory(evidenceDirectory, false);
|
|
9356
|
+
await ensurePlainDirectory(path7.join(evidenceDirectory, "delivery-mode"), true);
|
|
9357
|
+
}
|
|
9358
|
+
async function ensurePlainDirectory(directory, privateDirectory) {
|
|
9359
|
+
let created = false;
|
|
9360
|
+
try {
|
|
9361
|
+
await fs7.mkdir(directory, { mode: privateDirectory ? 448 : 493 });
|
|
9362
|
+
created = true;
|
|
9363
|
+
} catch (cause) {
|
|
9364
|
+
if (cause.code !== "EEXIST") throw cause;
|
|
9365
|
+
}
|
|
9366
|
+
const stat = await fs7.lstat(directory);
|
|
9367
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) {
|
|
9368
|
+
throw new Error(`\u6A21\u5F0F\u5207\u6362\u6536\u636E\u8DEF\u5F84\u4E0D\u662F\u666E\u901A\u76EE\u5F55\uFF1A${directory}`);
|
|
9369
|
+
}
|
|
9370
|
+
if (privateDirectory || created) {
|
|
9371
|
+
await fs7.chmod(directory, privateDirectory ? 448 : 493);
|
|
9372
|
+
}
|
|
9373
|
+
}
|
|
9374
|
+
|
|
9375
|
+
// src/commands/delivery-init.ts
|
|
9376
|
+
function renderProjectYml(environment, mode) {
|
|
8544
9377
|
return [
|
|
8545
9378
|
"# HCM \u987E\u95EE\u4EA4\u4ED8\u9879\u76EE\u914D\u7F6E\uFF08hcm delivery init \u751F\u6210\uFF09",
|
|
8546
9379
|
"#",
|
|
8547
|
-
"# deliveryMode \u51B3\u5B9A\
|
|
9380
|
+
"# deliveryMode \u6309\u76EE\u6807\u73AF\u5883\u51B3\u5B9A\u672C\u673A\u5141\u8BB8\u8D70\u5230\u54EA\u4E00\u6B65\uFF1A",
|
|
8548
9381
|
"# plan-only \u2014\u2014 \u53EA\u5141\u8BB8 assess / prepare \u51FA\u8BA1\u5212\uFF0Cexecute \u4E00\u5F8B\u62D2\u7EDD",
|
|
8549
9382
|
"# controlled \u2014\u2014 \u5141\u8BB8 prepare + execute \u5355\u6B21\u53D7\u63A7\u6267\u884C\uFF08\u4ECD\u9700\u9010\u6B21\u6279\u51C6\uFF09",
|
|
8550
9383
|
"#",
|
|
8551
9384
|
"# \u{1F534} \u5B83\u4E0D\u653E\u5BBD\u4EFB\u4F55\u98CE\u9669\u5224\u7EA7\uFF1AR3 \u5728\u4E24\u79CD\u6A21\u5F0F\u4E0B\u90FD\u62D2\u7EDD\uFF0CR2 \u4ECD\u8981\u8BA1\u5212\u3001\u56DE\u6EDA\u8BF4\u660E\u4E0E\u6536\u636E\u3002",
|
|
8552
|
-
"# \u6539\
|
|
8553
|
-
|
|
9385
|
+
"# \u6539\u4E00\u4E2A\u73AF\u5883\u53EA\u5F71\u54CD\u8BE5\u73AF\u5883\uFF1B\u672A\u767B\u8BB0\u7684\u73AF\u5883 fail-closed\uFF0C\u4E0D\u7EE7\u627F\u5176\u5B83\u73AF\u5883\u7684 controlled\u3002",
|
|
9386
|
+
"schemaVersion: 2",
|
|
9387
|
+
"deliveryMode:",
|
|
9388
|
+
` ${JSON.stringify(environment)}: ${mode}`,
|
|
8554
9389
|
""
|
|
8555
9390
|
].join("\n");
|
|
8556
9391
|
}
|
|
8557
9392
|
async function deliveryInitCommand(args) {
|
|
8558
9393
|
try {
|
|
8559
|
-
const mode = args.mode ?? "
|
|
8560
|
-
if (!
|
|
9394
|
+
const mode = args.mode ?? "plan-only";
|
|
9395
|
+
if (!DELIVERY_MODES.includes(mode)) {
|
|
8561
9396
|
throw new Error(
|
|
8562
|
-
`--mode \u53EA\u63A5\u53D7 ${
|
|
9397
|
+
`--mode \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.mode}"
|
|
8563
9398
|
\u8FD9\u4E24\u4E2A\u503C\u662F delivery prepare \u8BA4\u5F97\u7684\u5168\u90E8\uFF1B\u5199\u522B\u7684\u503C prepare \u4F1A\u62D2\u7EDD\u52A0\u8F7D\u3002`
|
|
8564
9399
|
);
|
|
8565
9400
|
}
|
|
8566
|
-
const
|
|
8567
|
-
const
|
|
8568
|
-
const
|
|
9401
|
+
const approval = requireControlledModeApproval(mode, args.approvedBy, args.reason);
|
|
9402
|
+
const environment = await resolveDeliveryEnvironment(args.env);
|
|
9403
|
+
const root = path8.resolve(args.project ?? ".");
|
|
9404
|
+
const dir = path8.join(root, ".hcm-delivery");
|
|
9405
|
+
const file = path8.join(dir, "project.yml");
|
|
8569
9406
|
let existed = false;
|
|
8570
9407
|
try {
|
|
8571
|
-
await
|
|
9408
|
+
await fs8.access(file);
|
|
8572
9409
|
existed = true;
|
|
8573
9410
|
} catch {
|
|
8574
9411
|
existed = false;
|
|
@@ -8580,23 +9417,33 @@ async function deliveryInitCommand(args) {
|
|
|
8580
9417
|
\u786E\u8981\u91CD\u5199\uFF1Ahcm delivery init --force`
|
|
8581
9418
|
);
|
|
8582
9419
|
}
|
|
8583
|
-
await
|
|
8584
|
-
await
|
|
8585
|
-
const
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
9420
|
+
await fs8.mkdir(dir, { recursive: true });
|
|
9421
|
+
await fs8.writeFile(file, renderProjectYml(environment, "plan-only"), "utf8");
|
|
9422
|
+
const environmentConfig = await loadEnv9(environment).catch(() => null);
|
|
9423
|
+
const scaffold = await scaffoldDeliveryProject(root, {
|
|
9424
|
+
environment,
|
|
9425
|
+
environmentConfig,
|
|
9426
|
+
initialMode: mode,
|
|
9427
|
+
cliVersion: CLI_VERSION
|
|
9428
|
+
});
|
|
9429
|
+
const modeReceipt = approval ? await setDeliveryModeWithReceipt({
|
|
9430
|
+
project: root,
|
|
9431
|
+
environment,
|
|
9432
|
+
mode,
|
|
9433
|
+
approvedBy: approval.approvedBy,
|
|
9434
|
+
reason: approval.reason
|
|
9435
|
+
}) : null;
|
|
8591
9436
|
const result = {
|
|
8592
9437
|
project: root,
|
|
8593
9438
|
projectFile: file,
|
|
9439
|
+
environment,
|
|
8594
9440
|
deliveryMode: mode,
|
|
8595
9441
|
overwritten: existed,
|
|
8596
|
-
scaffold
|
|
9442
|
+
scaffold,
|
|
9443
|
+
...modeReceipt ? { modeReceipt } : {},
|
|
8597
9444
|
nextStep: mode === "controlled" ? "hcm delivery assess <\u547D\u4EE4>\uFF1BR2 \u518D hcm delivery prepare --change-ref \u2026 --rollback-ref \u2026 --evidence-dir \u2026" : "hcm delivery assess <\u547D\u4EE4>\uFF1B\u672C\u9879\u76EE\u4E3A plan-only\uFF0Cexecute \u4F1A\u88AB\u62D2\u7EDD"
|
|
8598
9445
|
};
|
|
8599
|
-
process.stdout.write(
|
|
9446
|
+
process.stdout.write(formatObject22(result, { format: args.output ?? "json" }) + "\n");
|
|
8600
9447
|
process.exit(0);
|
|
8601
9448
|
} catch (e) {
|
|
8602
9449
|
exitWithError(e);
|
|
@@ -8605,31 +9452,31 @@ async function deliveryInitCommand(args) {
|
|
|
8605
9452
|
}
|
|
8606
9453
|
async function deliveryModeCommand(args) {
|
|
8607
9454
|
try {
|
|
8608
|
-
const
|
|
8609
|
-
const
|
|
9455
|
+
const environment = requireDeliveryModeEnvironment(args.env);
|
|
9456
|
+
const root = path8.resolve(args.project ?? ".");
|
|
9457
|
+
const file = path8.join(root, ".hcm-delivery", "project.yml");
|
|
8610
9458
|
let content;
|
|
8611
9459
|
try {
|
|
8612
|
-
content = await
|
|
9460
|
+
content = await fs8.readFile(file, "utf8");
|
|
8613
9461
|
} catch {
|
|
8614
9462
|
throw new Error(
|
|
8615
9463
|
`\u9879\u76EE\u672A\u521D\u59CB\u5316\uFF1A\u627E\u4E0D\u5230 ${file}
|
|
8616
9464
|
\u4E0B\u4E00\u6B65\uFF1Ahcm delivery init`
|
|
8617
9465
|
);
|
|
8618
9466
|
}
|
|
8619
|
-
const read = () => content.match(
|
|
8620
|
-
/^deliveryMode:\s*(?:"(plan-only|controlled)"|'(plan-only|controlled)'|(plan-only|controlled))\s*$/m
|
|
8621
|
-
);
|
|
8622
9467
|
if (!args.set) {
|
|
8623
|
-
const
|
|
8624
|
-
const current = m2?.[1] ?? m2?.[2] ?? m2?.[3] ?? null;
|
|
9468
|
+
const current = deliveryModeForEnvironment(content, environment);
|
|
8625
9469
|
process.stdout.write(
|
|
8626
|
-
|
|
9470
|
+
formatObject22(
|
|
8627
9471
|
{
|
|
8628
9472
|
project: root,
|
|
8629
9473
|
projectFile: file,
|
|
9474
|
+
environment,
|
|
8630
9475
|
deliveryMode: current,
|
|
8631
9476
|
canExecuteR2: current === "controlled",
|
|
8632
|
-
...current === "plan-only" ? { note: "plan-only \u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\uFF1Bexecute \u4F1A\u62D2\u7EDD R2 \u8BA1\u5212" } : {
|
|
9477
|
+
...current === "plan-only" ? { note: "plan-only \u53EA\u51FA\u8BA1\u5212\u4E0D\u6267\u884C\uFF1Bexecute \u4F1A\u62D2\u7EDD R2 \u8BA1\u5212" } : current === null ? {
|
|
9478
|
+
note: `\u73AF\u5883 ${environment} \u5C1A\u672A\u767B\u8BB0\u4EA4\u4ED8\u6A21\u5F0F\uFF1Bfail-closed\u3002\u5148\u6267\u884C hcm delivery mode --env ${environment} --set plan-only`
|
|
9479
|
+
} : {}
|
|
8633
9480
|
},
|
|
8634
9481
|
{ format: args.output ?? "json" }
|
|
8635
9482
|
) + "\n"
|
|
@@ -8637,30 +9484,18 @@ async function deliveryModeCommand(args) {
|
|
|
8637
9484
|
process.exit(0);
|
|
8638
9485
|
}
|
|
8639
9486
|
const next = args.set;
|
|
8640
|
-
if (!
|
|
8641
|
-
throw new Error(`--set \u53EA\u63A5\u53D7 ${
|
|
8642
|
-
}
|
|
8643
|
-
const m = read();
|
|
8644
|
-
if (!m) {
|
|
8645
|
-
throw new Error(
|
|
8646
|
-
`${file} \u91CC\u6CA1\u6709\u5408\u6CD5\u7684 deliveryMode \u884C\uFF0C\u4E0D\u5C31\u5730\u6539\u5199\u4EE5\u514D\u7834\u574F\u914D\u7F6E
|
|
8647
|
-
\u4E0B\u4E00\u6B65\uFF1A\u786E\u8BA4\u6587\u4EF6\u5185\u5BB9\uFF0C\u6216 hcm delivery init --force \u91CD\u65B0\u751F\u6210`
|
|
8648
|
-
);
|
|
9487
|
+
if (!DELIVERY_MODES.includes(next)) {
|
|
9488
|
+
throw new Error(`--set \u53EA\u63A5\u53D7 ${DELIVERY_MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.set}"`);
|
|
8649
9489
|
}
|
|
8650
|
-
const
|
|
8651
|
-
|
|
8652
|
-
|
|
9490
|
+
const receipt = await setDeliveryModeWithReceipt({
|
|
9491
|
+
project: root,
|
|
9492
|
+
environment,
|
|
9493
|
+
mode: next,
|
|
9494
|
+
approvedBy: args.approvedBy,
|
|
9495
|
+
reason: args.reason
|
|
9496
|
+
});
|
|
8653
9497
|
process.stdout.write(
|
|
8654
|
-
|
|
8655
|
-
{
|
|
8656
|
-
project: root,
|
|
8657
|
-
projectFile: file,
|
|
8658
|
-
deliveryMode: next,
|
|
8659
|
-
previous: before,
|
|
8660
|
-
canExecuteR2: next === "controlled"
|
|
8661
|
-
},
|
|
8662
|
-
{ format: args.output ?? "json" }
|
|
8663
|
-
) + "\n"
|
|
9498
|
+
formatObject22(receipt, { format: args.output ?? "json" }) + "\n"
|
|
8664
9499
|
);
|
|
8665
9500
|
process.exit(0);
|
|
8666
9501
|
} catch (e) {
|
|
@@ -8668,6 +9503,21 @@ async function deliveryModeCommand(args) {
|
|
|
8668
9503
|
process.exit(1);
|
|
8669
9504
|
}
|
|
8670
9505
|
}
|
|
9506
|
+
function requireDeliveryModeEnvironment(envFlag) {
|
|
9507
|
+
const environment = envFlag?.trim();
|
|
9508
|
+
if (!environment) {
|
|
9509
|
+
throw new Error(
|
|
9510
|
+
"hcm delivery mode \u5FC5\u987B\u663E\u5F0F\u4F20 --env <\u73AF\u5883\u522B\u540D>\uFF1B\u9879\u76EE\u4EA4\u4ED8\u6A21\u5F0F\u4E0D\u7EE7\u627F\u5168\u5C40 activeEnv\uFF0C\u907F\u514D\u67E5\u770B\u6216\u4FEE\u6539\u9519\u8BEF\u73AF\u5883"
|
|
9511
|
+
);
|
|
9512
|
+
}
|
|
9513
|
+
return environment;
|
|
9514
|
+
}
|
|
9515
|
+
async function resolveDeliveryEnvironment(envFlag) {
|
|
9516
|
+
const global = await loadGlobalConfig9();
|
|
9517
|
+
const environment = resolveActiveEnv5({ envFlag }, process.env, global);
|
|
9518
|
+
if (!environment.trim()) throw new Error("\u65E0\u6CD5\u89E3\u6790\u76EE\u6807\u73AF\u5883\uFF1B\u8BF7\u4F20 --env <\u73AF\u5883\u522B\u540D>");
|
|
9519
|
+
return environment;
|
|
9520
|
+
}
|
|
8671
9521
|
|
|
8672
9522
|
// src/commands/delivery-doctor.ts
|
|
8673
9523
|
init_auth_guard();
|
|
@@ -8675,8 +9525,8 @@ init_exit();
|
|
|
8675
9525
|
import {
|
|
8676
9526
|
HcmClient as HcmClient21,
|
|
8677
9527
|
fetchReconIdentity,
|
|
8678
|
-
formatObject as
|
|
8679
|
-
fromAxiosError as
|
|
9528
|
+
formatObject as formatObject23,
|
|
9529
|
+
fromAxiosError as fromAxiosError21,
|
|
8680
9530
|
httpProbe,
|
|
8681
9531
|
runDoctor
|
|
8682
9532
|
} from "@hcmai/sdk";
|
|
@@ -8701,11 +9551,11 @@ async function deliveryDoctorCommand(args) {
|
|
|
8701
9551
|
const report = await runDoctor(probe, identity2);
|
|
8702
9552
|
const fmt = args.output ?? "json";
|
|
8703
9553
|
if (fmt !== "json") process.stdout.write(render2(report) + "\n");
|
|
8704
|
-
process.stdout.write(
|
|
9554
|
+
process.stdout.write(formatObject23(report, { format: fmt }) + "\n");
|
|
8705
9555
|
process.exit(report.ok ? 0 : 1);
|
|
8706
9556
|
} catch (e) {
|
|
8707
9557
|
const err = e;
|
|
8708
|
-
if (err?.isAxiosError) exitWithError(
|
|
9558
|
+
if (err?.isAxiosError) exitWithError(fromAxiosError21(err, args.env));
|
|
8709
9559
|
exitWithError(e);
|
|
8710
9560
|
process.exit(1);
|
|
8711
9561
|
}
|
|
@@ -8719,8 +9569,8 @@ import {
|
|
|
8719
9569
|
ReconLayout,
|
|
8720
9570
|
ROUND_EXIT_CODES,
|
|
8721
9571
|
computeReconSourceKey,
|
|
8722
|
-
formatObject as
|
|
8723
|
-
fromAxiosError as
|
|
9572
|
+
formatObject as formatObject24,
|
|
9573
|
+
fromAxiosError as fromAxiosError22,
|
|
8724
9574
|
httpProbe as httpProbe2,
|
|
8725
9575
|
inspectRound,
|
|
8726
9576
|
renderRound,
|
|
@@ -8739,10 +9589,10 @@ async function deliveryReconCommand(args) {
|
|
|
8739
9589
|
onlyModel: args.model ?? null,
|
|
8740
9590
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
8741
9591
|
});
|
|
8742
|
-
process.stdout.write(
|
|
9592
|
+
process.stdout.write(formatObject24(summary, { format: args.output ?? "json" }) + "\n");
|
|
8743
9593
|
} catch (e) {
|
|
8744
9594
|
const err = e;
|
|
8745
|
-
if (err?.isAxiosError) exitWithError(
|
|
9595
|
+
if (err?.isAxiosError) exitWithError(fromAxiosError22(err, args.env));
|
|
8746
9596
|
exitWithError(e);
|
|
8747
9597
|
process.exit(1);
|
|
8748
9598
|
}
|
|
@@ -8753,7 +9603,7 @@ async function deliveryReconRoundCommand(args) {
|
|
|
8753
9603
|
const result = inspectRound(args.dir ?? ".");
|
|
8754
9604
|
const fmt = args.output ?? "json";
|
|
8755
9605
|
if (fmt !== "json") process.stdout.write(renderRound(result));
|
|
8756
|
-
process.stdout.write(
|
|
9606
|
+
process.stdout.write(formatObject24(result, { format: fmt }) + "\n");
|
|
8757
9607
|
code = ROUND_EXIT_CODES[result.state];
|
|
8758
9608
|
} catch (e) {
|
|
8759
9609
|
exitWithError(e);
|
|
@@ -8771,14 +9621,14 @@ import {
|
|
|
8771
9621
|
GAP_REASONS,
|
|
8772
9622
|
deriveAclass,
|
|
8773
9623
|
exitCode as gate0ExitCode,
|
|
8774
|
-
formatObject as
|
|
9624
|
+
formatObject as formatObject25,
|
|
8775
9625
|
inspectRound as inspectRound2,
|
|
8776
9626
|
loadProtocolFacts,
|
|
8777
9627
|
scan
|
|
8778
9628
|
} from "@hcmai/sdk";
|
|
8779
|
-
import * as
|
|
9629
|
+
import * as path9 from "path";
|
|
8780
9630
|
function renderGate0(result, skillRoot) {
|
|
8781
|
-
const where = skillRoot ? `\uFF08${
|
|
9631
|
+
const where = skillRoot ? `\uFF08${path9.resolve(skillRoot)}\uFF09` : "";
|
|
8782
9632
|
const lines = [
|
|
8783
9633
|
`\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`
|
|
8784
9634
|
];
|
|
@@ -8816,7 +9666,7 @@ async function deliveryGate0Command(args) {
|
|
|
8816
9666
|
const merged = { ...result, premise: premise5 };
|
|
8817
9667
|
const fmt = args.output ?? "json";
|
|
8818
9668
|
if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
|
|
8819
|
-
process.stdout.write(`${
|
|
9669
|
+
process.stdout.write(`${formatObject25(merged, { format: fmt })}
|
|
8820
9670
|
`);
|
|
8821
9671
|
for (const problem of premise5) {
|
|
8822
9672
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
|
|
@@ -8890,7 +9740,7 @@ import {
|
|
|
8890
9740
|
writeRisk
|
|
8891
9741
|
} from "@hcmai/sdk";
|
|
8892
9742
|
import { existsSync as existsSync3 } from "fs";
|
|
8893
|
-
import * as
|
|
9743
|
+
import * as path10 from "path";
|
|
8894
9744
|
function premise(message, hint = "") {
|
|
8895
9745
|
process.stderr.write(message + (hint ? `
|
|
8896
9746
|
\u2192 ${hint}` : "") + "\n");
|
|
@@ -8917,13 +9767,13 @@ async function runSeedPlan(args, client3) {
|
|
|
8917
9767
|
const reconDir = candidates[0].reconDir;
|
|
8918
9768
|
if (candidates.length > 1) {
|
|
8919
9769
|
process.stderr.write(
|
|
8920
|
-
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${
|
|
9770
|
+
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path10.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path10.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
|
|
8921
9771
|
);
|
|
8922
9772
|
}
|
|
8923
9773
|
const round = inspectRound3(reconDir);
|
|
8924
9774
|
process.stderr.write(roundWarning(round));
|
|
8925
9775
|
const baseline = {
|
|
8926
|
-
path: `${
|
|
9776
|
+
path: `${path10.basename(path10.dirname(reconDir))}/${path10.basename(reconDir)}`,
|
|
8927
9777
|
roundId: round.roundId ?? null
|
|
8928
9778
|
};
|
|
8929
9779
|
let exemptions = null;
|
|
@@ -9185,7 +10035,7 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
9185
10035
|
// src/commands/delivery-seed-find.ts
|
|
9186
10036
|
import { existsSync as existsSync4 } from "fs";
|
|
9187
10037
|
import { readFileSync as readFileSync6 } from "fs";
|
|
9188
|
-
import * as
|
|
10038
|
+
import * as path11 from "path";
|
|
9189
10039
|
import {
|
|
9190
10040
|
INIT_EXIT_CODES as INIT_EXIT_CODES2,
|
|
9191
10041
|
ValueHints,
|
|
@@ -9199,10 +10049,10 @@ import {
|
|
|
9199
10049
|
valuesRoundCaveat
|
|
9200
10050
|
} from "@hcmai/sdk";
|
|
9201
10051
|
function provenance(chosenReconDir, others) {
|
|
9202
|
-
let line = `> \u57FA\u7EBF\uFF1A\`${
|
|
10052
|
+
let line = `> \u57FA\u7EBF\uFF1A\`${path11.basename(chosenReconDir)}\`
|
|
9203
10053
|
`;
|
|
9204
10054
|
if (others.length > 0) {
|
|
9205
|
-
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${
|
|
10055
|
+
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path11.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
|
|
9206
10056
|
}
|
|
9207
10057
|
return `${line}
|
|
9208
10058
|
`;
|
|
@@ -9539,7 +10389,7 @@ import {
|
|
|
9539
10389
|
runTriageRound
|
|
9540
10390
|
} from "@hcmai/sdk";
|
|
9541
10391
|
import { mkdirSync, readFileSync as readFileSync8, writeFileSync as writeFileSync2 } from "fs";
|
|
9542
|
-
import * as
|
|
10392
|
+
import * as path12 from "path";
|
|
9543
10393
|
var DEFAULT_CAPABILITIES4 = "default";
|
|
9544
10394
|
function premise4(message, hint) {
|
|
9545
10395
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
|
|
@@ -9575,8 +10425,8 @@ function renderProblems(rows) {
|
|
|
9575
10425
|
`;
|
|
9576
10426
|
}
|
|
9577
10427
|
function writeTriageArtifact(outDir, body) {
|
|
9578
|
-
const out =
|
|
9579
|
-
mkdirSync(
|
|
10428
|
+
const out = path12.join(outDir, "work", "triage.md");
|
|
10429
|
+
mkdirSync(path12.dirname(out), { recursive: true });
|
|
9580
10430
|
writeFileSync2(out, body, "utf8");
|
|
9581
10431
|
return out;
|
|
9582
10432
|
}
|
|
@@ -9616,21 +10466,23 @@ async function deliveryTriageCommand(args) {
|
|
|
9616
10466
|
// src/commands/delivery-execution.ts
|
|
9617
10467
|
import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
|
|
9618
10468
|
import { spawn as spawn2 } from "child_process";
|
|
9619
|
-
import { createReadStream, promises as
|
|
9620
|
-
import
|
|
9621
|
-
import { CliError as CliError21, CliErrorCode as CliErrorCode20, formatObject as
|
|
10469
|
+
import { createReadStream, promises as fs9 } from "fs";
|
|
10470
|
+
import path13 from "path";
|
|
10471
|
+
import { CliError as CliError21, CliErrorCode as CliErrorCode20, formatObject as formatObject26 } from "@hcmai/sdk";
|
|
9622
10472
|
init_exit();
|
|
9623
|
-
var EXECUTION_CONTRACT_VERSION = "2026-
|
|
10473
|
+
var EXECUTION_CONTRACT_VERSION = "2026-09-03.controlled-v4";
|
|
9624
10474
|
var DEFAULT_TTL_SECONDS = 15 * 60;
|
|
9625
10475
|
var MIN_TTL_SECONDS = 60;
|
|
9626
10476
|
var MAX_TTL_SECONDS = 60 * 60;
|
|
9627
10477
|
var PLAN_ID_PATTERN = /^[a-f0-9]{24}$/;
|
|
9628
10478
|
async function prepareDeliveryExecution(input) {
|
|
9629
10479
|
const project = await realProject(input.project);
|
|
9630
|
-
await readProjectMode(project);
|
|
9631
10480
|
const argv = normalizeCommandArgv(input.argv);
|
|
9632
10481
|
const assessment = await (input.assessCommand ?? assessEffectiveDeliveryCommand)(argv);
|
|
9633
10482
|
assertGuardedAssessment(assessment, argv);
|
|
10483
|
+
const environment = assessment.environment.envAlias;
|
|
10484
|
+
if (!environment) throw invalid2("R2 argv \u5FC5\u987B\u663E\u5F0F\u5305\u542B --env \u73AF\u5883\u522B\u540D");
|
|
10485
|
+
await readProjectMode(project, environment);
|
|
9634
10486
|
const ttlSeconds = input.ttlSeconds ?? DEFAULT_TTL_SECONDS;
|
|
9635
10487
|
if (!Number.isInteger(ttlSeconds) || ttlSeconds < MIN_TTL_SECONDS || ttlSeconds > MAX_TTL_SECONDS) {
|
|
9636
10488
|
throw invalid2(`--ttl-seconds \u5FC5\u987B\u662F ${MIN_TTL_SECONDS} \u5230 ${MAX_TTL_SECONDS} \u7684\u6574\u6570`);
|
|
@@ -9658,11 +10510,11 @@ async function prepareDeliveryExecution(input) {
|
|
|
9658
10510
|
};
|
|
9659
10511
|
const planId = sha2565(canonicalJson(core)).slice(0, 24);
|
|
9660
10512
|
const plan = { ...core, planId };
|
|
9661
|
-
const plansDir =
|
|
10513
|
+
const plansDir = path13.join(project, ".hcm-delivery", "execution-plans");
|
|
9662
10514
|
await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
|
|
9663
|
-
const planFile =
|
|
10515
|
+
const planFile = path13.join(plansDir, `${planId}.json`);
|
|
9664
10516
|
try {
|
|
9665
|
-
await
|
|
10517
|
+
await fs9.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
|
|
9666
10518
|
`, {
|
|
9667
10519
|
encoding: "utf8",
|
|
9668
10520
|
mode: 384,
|
|
@@ -9676,14 +10528,16 @@ async function prepareDeliveryExecution(input) {
|
|
|
9676
10528
|
async function executeDeliveryPlan(input) {
|
|
9677
10529
|
if (!PLAN_ID_PATTERN.test(input.planId)) throw invalid2("planId \u5FC5\u987B\u662F 24 \u4F4D\u5C0F\u5199\u5341\u516D\u8FDB\u5236");
|
|
9678
10530
|
const project = await realProject(input.project);
|
|
9679
|
-
|
|
9680
|
-
throw invalid2("\u9879\u76EE\u4E0D\u662F controlled\uFF0C\u4E0D\u80FD\u6267\u884C R2 \u8BA1\u5212");
|
|
9681
|
-
}
|
|
9682
|
-
const planFile = path11.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
10531
|
+
const planFile = path13.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
9683
10532
|
const plan = await readPlan(project, planFile);
|
|
9684
10533
|
if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
|
|
9685
10534
|
throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
|
|
9686
10535
|
}
|
|
10536
|
+
const environment = plan.assessment.environment.envAlias;
|
|
10537
|
+
if (!environment) throw invalid2("\u6267\u884C\u8BA1\u5212\u7F3A\u5C11\u76EE\u6807\u73AF\u5883");
|
|
10538
|
+
if (await readProjectMode(project, environment) !== "controlled") {
|
|
10539
|
+
throw invalid2(`\u73AF\u5883 ${environment} \u4E0D\u662F controlled\uFF0C\u4E0D\u80FD\u6267\u884C R2 \u8BA1\u5212`);
|
|
10540
|
+
}
|
|
9687
10541
|
const now = (input.now ?? (() => /* @__PURE__ */ new Date()))();
|
|
9688
10542
|
if (Number.isNaN(now.getTime())) throw invalid2("\u5F53\u524D\u65F6\u95F4\u65E0\u6548");
|
|
9689
10543
|
const expiresAt = Date.parse(plan.expiresAt);
|
|
@@ -9711,13 +10565,13 @@ async function executeDeliveryPlan(input) {
|
|
|
9711
10565
|
await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
|
|
9712
10566
|
await assertPayloadsUnchanged(project, plan.payloads);
|
|
9713
10567
|
const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
|
|
9714
|
-
const receiptFile =
|
|
10568
|
+
const receiptFile = path13.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
|
|
9715
10569
|
if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
|
|
9716
|
-
const claimsDir =
|
|
10570
|
+
const claimsDir = path13.join(project, ".hcm-delivery", "execution-claims");
|
|
9717
10571
|
await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
|
|
9718
|
-
const claimFile =
|
|
10572
|
+
const claimFile = path13.join(claimsDir, `${plan.planId}.json`);
|
|
9719
10573
|
try {
|
|
9720
|
-
await
|
|
10574
|
+
await fs9.writeFile(
|
|
9721
10575
|
claimFile,
|
|
9722
10576
|
`${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
|
|
9723
10577
|
`,
|
|
@@ -9774,7 +10628,7 @@ async function deliveryPrepareCommand(argv, args) {
|
|
|
9774
10628
|
evidenceDir: args.evidenceDir,
|
|
9775
10629
|
...ttlSeconds === void 0 ? {} : { ttlSeconds }
|
|
9776
10630
|
});
|
|
9777
|
-
process.stdout.write(
|
|
10631
|
+
process.stdout.write(formatObject26(plan, { format: args.output ?? "json" }) + "\n");
|
|
9778
10632
|
process.stderr.write(`
|
|
9779
10633
|
\u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
|
|
9780
10634
|
${nextCommandHint(plan.planId, args.project, argv)}
|
|
@@ -9795,32 +10649,36 @@ async function deliveryExecuteCommand(planId, argv, args) {
|
|
|
9795
10649
|
planId,
|
|
9796
10650
|
argv
|
|
9797
10651
|
});
|
|
9798
|
-
process.stdout.write(
|
|
10652
|
+
process.stdout.write(formatObject26(receipt, { format: args.output ?? "json" }) + "\n");
|
|
9799
10653
|
process.exitCode = receipt.exitCode;
|
|
9800
10654
|
} catch (cause) {
|
|
9801
10655
|
exitWithError(cause);
|
|
9802
10656
|
}
|
|
9803
10657
|
}
|
|
9804
|
-
async function readProjectMode(project) {
|
|
9805
|
-
const file =
|
|
10658
|
+
async function readProjectMode(project, environment) {
|
|
10659
|
+
const file = path13.join(project, ".hcm-delivery", "project.yml");
|
|
9806
10660
|
const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
10661
|
+
let mode;
|
|
10662
|
+
try {
|
|
10663
|
+
mode = deliveryModeForEnvironment(content.toString("utf8"), environment);
|
|
10664
|
+
} catch (cause) {
|
|
10665
|
+
throw invalid2(`project.yml \u7684 deliveryMode \u914D\u7F6E\u65E0\u6548\uFF1A${String(cause.message)}`, cause);
|
|
10666
|
+
}
|
|
10667
|
+
if (!mode) {
|
|
10668
|
+
throw invalid2(
|
|
10669
|
+
`project.yml \u672A\u7ED9\u73AF\u5883 ${environment} \u914D\u7F6E deliveryMode\u3002next_step=hcm delivery mode --env ${environment} --set plan-only`
|
|
10670
|
+
);
|
|
9813
10671
|
}
|
|
9814
10672
|
return mode;
|
|
9815
10673
|
}
|
|
9816
10674
|
var SKILLS_LOCK_CANDIDATES = [
|
|
9817
|
-
|
|
9818
|
-
|
|
10675
|
+
path13.join("hcm-skills", ".hcm-skills.json"),
|
|
10676
|
+
path13.join(".claude", "skills", ".hcm-skills.json")
|
|
9819
10677
|
];
|
|
9820
10678
|
async function readSkillsLock(project) {
|
|
9821
10679
|
const found = [];
|
|
9822
10680
|
for (const candidate of SKILLS_LOCK_CANDIDATES) {
|
|
9823
|
-
if (await pathExists(
|
|
10681
|
+
if (await pathExists(path13.join(project, candidate))) found.push(candidate);
|
|
9824
10682
|
}
|
|
9825
10683
|
if (found.length === 0) {
|
|
9826
10684
|
throw invalid2(
|
|
@@ -9832,7 +10690,7 @@ async function readSkillsLock(project) {
|
|
|
9832
10690
|
`\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`
|
|
9833
10691
|
);
|
|
9834
10692
|
}
|
|
9835
|
-
const bytes = await readSafeFile(project,
|
|
10693
|
+
const bytes = await readSafeFile(project, path13.join(project, found[0]), "\u6280\u80FD\u9501");
|
|
9836
10694
|
try {
|
|
9837
10695
|
JSON.parse(bytes.toString("utf8"));
|
|
9838
10696
|
} catch (cause) {
|
|
@@ -9845,7 +10703,7 @@ async function bindDocument(project, reference, label) {
|
|
|
9845
10703
|
if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
|
|
9846
10704
|
throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
|
|
9847
10705
|
}
|
|
9848
|
-
const file =
|
|
10706
|
+
const file = path13.join(project, relative2);
|
|
9849
10707
|
const bytes = await readSafeFile(project, file, label);
|
|
9850
10708
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
9851
10709
|
}
|
|
@@ -9858,11 +10716,11 @@ async function bindEvidenceDirectory(project, reference) {
|
|
|
9858
10716
|
if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
|
|
9859
10717
|
throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
|
|
9860
10718
|
}
|
|
9861
|
-
const absolute =
|
|
10719
|
+
const absolute = path13.join(project, relative2);
|
|
9862
10720
|
await assertNoSymlinkComponents(project, relative2);
|
|
9863
|
-
const stat = await
|
|
10721
|
+
const stat = await fs9.stat(absolute).catch(() => null);
|
|
9864
10722
|
if (stat === null) {
|
|
9865
|
-
await
|
|
10723
|
+
await fs9.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
|
|
9866
10724
|
throw invalid2(
|
|
9867
10725
|
`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`,
|
|
9868
10726
|
cause
|
|
@@ -9943,6 +10801,18 @@ function validateSupportedCommandShape(reasonCode, argv) {
|
|
|
9943
10801
|
}
|
|
9944
10802
|
return;
|
|
9945
10803
|
}
|
|
10804
|
+
if (reasonCode === "document-upload") {
|
|
10805
|
+
if (argv[0] !== "upload") {
|
|
10806
|
+
throw invalid2(`upload \u7684\u547D\u4EE4\u540D\u5FC5\u987B\u662F argv \u7684\u7B2C\u4E00\u4E2A token\uFF0C\u5B9E\u9645\u662F\uFF1A${argv[0] ?? "(\u7A7A)"}`);
|
|
10807
|
+
}
|
|
10808
|
+
const file = argv[1];
|
|
10809
|
+
if (!file || file.startsWith("-")) {
|
|
10810
|
+
throw invalid2(
|
|
10811
|
+
"upload \u7684\u6587\u4EF6\u8DEF\u5F84\u5FC5\u987B\u7D27\u8DDF\u5728 upload \u4E4B\u540E\uFF08hcm upload <\u6587\u4EF6> ...\uFF09\u3002next_step=\u628A\u6587\u4EF6\u8DEF\u5F84\u79FB\u5230\u547D\u4EE4\u540D\u540E\u9762\u7684\u7B2C\u4E00\u4E2A\u4F4D\u7F6E\u2014\u2014\u53D7\u63A7\u6267\u884C\u6309\u8FD9\u4E2A\u4F4D\u7F6E\u9489\u4F4F\u8F7D\u8377"
|
|
10812
|
+
);
|
|
10813
|
+
}
|
|
10814
|
+
return;
|
|
10815
|
+
}
|
|
9946
10816
|
if (reasonCode === "record-create") {
|
|
9947
10817
|
requireExactlyOnePayload(argv, "create");
|
|
9948
10818
|
return;
|
|
@@ -9994,7 +10864,10 @@ var PAYLOAD_FILE_FLAGS = ["--data-file", "--params-file", "--file"];
|
|
|
9994
10864
|
var PAYLOAD_DIR_FLAGS = ["--dir"];
|
|
9995
10865
|
var IMPLICIT_DIR_COMMANDS = { "workspace push": "." };
|
|
9996
10866
|
var TOOLING_DIRS = [".git", "node_modules", ".hcm-delivery", "evidence"];
|
|
9997
|
-
var POSITIONAL_PAYLOAD_COMMANDS = {
|
|
10867
|
+
var POSITIONAL_PAYLOAD_COMMANDS = {
|
|
10868
|
+
import: { index: 1, kind: "file-or-directory", label: "import \u6570\u636E\u96C6\u8F7D\u8377" },
|
|
10869
|
+
upload: { index: 1, kind: "file", label: "upload \u6587\u4EF6\u8F7D\u8377" }
|
|
10870
|
+
};
|
|
9998
10871
|
function normalizeCommandArgv(argv) {
|
|
9999
10872
|
return normalizeAssessedArgv(argv);
|
|
10000
10873
|
}
|
|
@@ -10016,7 +10889,10 @@ async function bindPayloadFiles(project, argv) {
|
|
|
10016
10889
|
}
|
|
10017
10890
|
const positional = POSITIONAL_PAYLOAD_COMMANDS[argv[0] ?? ""];
|
|
10018
10891
|
if (positional !== void 0) {
|
|
10019
|
-
|
|
10892
|
+
const reference = argv[positional.index] ?? "";
|
|
10893
|
+
bound.push(
|
|
10894
|
+
await (positional.kind === "file" ? bindPayloadFile(project, reference, positional.label) : bindPayloadPath(project, reference, positional.label))
|
|
10895
|
+
);
|
|
10020
10896
|
}
|
|
10021
10897
|
return bound;
|
|
10022
10898
|
}
|
|
@@ -10024,7 +10900,7 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
10024
10900
|
const relative2 = safeRelative(reference, label);
|
|
10025
10901
|
let stat;
|
|
10026
10902
|
try {
|
|
10027
|
-
stat = await
|
|
10903
|
+
stat = await fs9.stat(path13.join(project, relative2));
|
|
10028
10904
|
} catch (cause) {
|
|
10029
10905
|
throw invalid2(
|
|
10030
10906
|
`${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`,
|
|
@@ -10035,10 +10911,10 @@ async function bindPayloadPath(project, reference, label) {
|
|
|
10035
10911
|
}
|
|
10036
10912
|
async function bindPayloadDirectory(project, reference, label) {
|
|
10037
10913
|
const relative2 = reference === "." ? "." : safeRelative(reference, label);
|
|
10038
|
-
const root =
|
|
10914
|
+
const root = path13.join(project, relative2);
|
|
10039
10915
|
let stat;
|
|
10040
10916
|
try {
|
|
10041
|
-
stat = await
|
|
10917
|
+
stat = await fs9.stat(root);
|
|
10042
10918
|
} catch {
|
|
10043
10919
|
throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
|
|
10044
10920
|
}
|
|
@@ -10048,10 +10924,10 @@ async function bindPayloadDirectory(project, reference, label) {
|
|
|
10048
10924
|
const skipToolingAtRoot = relative2 === ".";
|
|
10049
10925
|
const entries = [];
|
|
10050
10926
|
const walk = async (dir, prefix) => {
|
|
10051
|
-
const items = await
|
|
10927
|
+
const items = await fs9.readdir(dir, { withFileTypes: true });
|
|
10052
10928
|
for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
10053
10929
|
if (skipToolingAtRoot && prefix === "" && TOOLING_DIRS.includes(item.name)) continue;
|
|
10054
|
-
const child =
|
|
10930
|
+
const child = path13.join(dir, item.name);
|
|
10055
10931
|
const rel = prefix ? `${prefix}/${item.name}` : item.name;
|
|
10056
10932
|
if (item.isSymbolicLink()) {
|
|
10057
10933
|
throw invalid2(
|
|
@@ -10068,26 +10944,24 @@ ${sha2565(bytes)}`);
|
|
|
10068
10944
|
}
|
|
10069
10945
|
};
|
|
10070
10946
|
await walk(root, "");
|
|
10071
|
-
return {
|
|
10947
|
+
return {
|
|
10948
|
+
path: relative2,
|
|
10949
|
+
kind: "directory",
|
|
10950
|
+
sha256: sha2565(Buffer.from(entries.join("\n"), "utf8"))
|
|
10951
|
+
};
|
|
10072
10952
|
}
|
|
10073
10953
|
async function bindPayloadFile(project, reference, label) {
|
|
10074
10954
|
const relative2 = safeRelative(reference, label);
|
|
10075
|
-
const file =
|
|
10955
|
+
const file = path13.join(project, relative2);
|
|
10076
10956
|
const bytes = await readSafeFile(project, file, label);
|
|
10077
|
-
return { path: relative2, sha256: sha2565(bytes) };
|
|
10957
|
+
return { path: relative2, kind: "file", sha256: sha2565(bytes) };
|
|
10078
10958
|
}
|
|
10079
10959
|
async function assertPayloadsUnchanged(project, payloads) {
|
|
10080
10960
|
for (const payload of payloads) {
|
|
10081
|
-
|
|
10082
|
-
try {
|
|
10083
|
-
isDirectory = (await fs7.stat(path11.join(project, payload.path))).isDirectory();
|
|
10084
|
-
} catch {
|
|
10085
|
-
isDirectory = false;
|
|
10086
|
-
}
|
|
10087
|
-
const current = isDirectory ? await bindPayloadDirectory(project, payload.path, `\u8F7D\u8377 ${payload.path}`) : await bindPayloadFile(project, payload.path, `\u8F7D\u8377 ${payload.path}`);
|
|
10961
|
+
const current = payload.kind === "directory" ? await bindPayloadDirectory(project, payload.path, `\u8F7D\u8377 ${payload.path}`) : await bindPayloadFile(project, payload.path, `\u8F7D\u8377 ${payload.path}`);
|
|
10088
10962
|
if (current.sha256 !== payload.sha256) {
|
|
10089
10963
|
throw invalid2(
|
|
10090
|
-
`\u8F7D\u8377${
|
|
10964
|
+
`\u8F7D\u8377${payload.kind === "directory" ? "\u76EE\u5F55" : "\u6587\u4EF6"} ${payload.path} \u7684\u5185\u5BB9\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0 prepare`
|
|
10091
10965
|
);
|
|
10092
10966
|
}
|
|
10093
10967
|
}
|
|
@@ -10141,29 +11015,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
|
|
|
10141
11015
|
async function writeReceiptExclusive(target, receipt) {
|
|
10142
11016
|
const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
10143
11017
|
try {
|
|
10144
|
-
await
|
|
11018
|
+
await fs9.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
|
|
10145
11019
|
`, {
|
|
10146
11020
|
encoding: "utf8",
|
|
10147
11021
|
mode: 384,
|
|
10148
11022
|
flag: "wx"
|
|
10149
11023
|
});
|
|
10150
|
-
await
|
|
11024
|
+
await fs9.link(temp, target);
|
|
10151
11025
|
} catch (cause) {
|
|
10152
|
-
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${
|
|
11026
|
+
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path13.basename(target)}`, cause);
|
|
10153
11027
|
} finally {
|
|
10154
|
-
await
|
|
11028
|
+
await fs9.unlink(temp).catch(() => void 0);
|
|
10155
11029
|
}
|
|
10156
11030
|
}
|
|
10157
11031
|
async function safeManagedDirectory(project, relative2, absolute) {
|
|
10158
|
-
await assertNoSymlinkComponents(project,
|
|
10159
|
-
const existing = await
|
|
11032
|
+
await assertNoSymlinkComponents(project, path13.dirname(relative2));
|
|
11033
|
+
const existing = await fs9.lstat(absolute).catch(() => void 0);
|
|
10160
11034
|
if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
10161
11035
|
if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
10162
|
-
if (!existing) await
|
|
10163
|
-
await
|
|
11036
|
+
if (!existing) await fs9.mkdir(absolute, { mode: 448 });
|
|
11037
|
+
await fs9.chmod(absolute, 448);
|
|
10164
11038
|
}
|
|
10165
11039
|
async function pathExists(file) {
|
|
10166
|
-
return
|
|
11040
|
+
return fs9.lstat(file).then(
|
|
10167
11041
|
() => true,
|
|
10168
11042
|
(cause) => {
|
|
10169
11043
|
if (cause.code === "ENOENT") return false;
|
|
@@ -10172,65 +11046,68 @@ async function pathExists(file) {
|
|
|
10172
11046
|
);
|
|
10173
11047
|
}
|
|
10174
11048
|
async function readSafeFile(project, file, label) {
|
|
10175
|
-
const relative2 =
|
|
10176
|
-
if (relative2.startsWith("../") ||
|
|
11049
|
+
const relative2 = path13.relative(project, file).split(path13.sep).join("/");
|
|
11050
|
+
if (relative2.startsWith("../") || path13.isAbsolute(relative2))
|
|
10177
11051
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
10178
11052
|
await assertNoSymlinkComponents(project, relative2);
|
|
10179
11053
|
let stat;
|
|
10180
11054
|
try {
|
|
10181
|
-
stat = await
|
|
11055
|
+
stat = await fs9.lstat(file);
|
|
10182
11056
|
} catch (cause) {
|
|
10183
11057
|
throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
|
|
10184
11058
|
}
|
|
10185
11059
|
if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
10186
11060
|
if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
|
|
10187
|
-
return
|
|
11061
|
+
return fs9.readFile(file);
|
|
10188
11062
|
}
|
|
10189
11063
|
async function assertNoSymlinkComponents(project, relative2) {
|
|
10190
11064
|
const parts = relative2.split("/").filter(Boolean);
|
|
10191
11065
|
let current = project;
|
|
10192
11066
|
for (const part of parts) {
|
|
10193
|
-
current =
|
|
10194
|
-
const stat = await
|
|
11067
|
+
current = path13.join(current, part);
|
|
11068
|
+
const stat = await fs9.lstat(current).catch(() => void 0);
|
|
10195
11069
|
if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
10196
11070
|
if (!stat) break;
|
|
10197
11071
|
}
|
|
10198
11072
|
}
|
|
10199
11073
|
async function realProject(requested) {
|
|
10200
|
-
const absolute =
|
|
11074
|
+
const absolute = path13.resolve(requested);
|
|
10201
11075
|
let project;
|
|
10202
11076
|
try {
|
|
10203
|
-
project = await
|
|
11077
|
+
project = await fs9.realpath(absolute);
|
|
10204
11078
|
} catch (cause) {
|
|
10205
11079
|
throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
|
|
10206
11080
|
}
|
|
10207
|
-
const stat = await
|
|
11081
|
+
const stat = await fs9.stat(project);
|
|
10208
11082
|
if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
|
|
10209
11083
|
return project;
|
|
10210
11084
|
}
|
|
10211
11085
|
function safeRelative(reference, label) {
|
|
10212
|
-
if (!reference ||
|
|
11086
|
+
if (!reference || path13.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
|
|
10213
11087
|
throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
|
|
10214
11088
|
}
|
|
10215
|
-
const normalized =
|
|
11089
|
+
const normalized = path13.normalize(reference).split(path13.sep).join("/");
|
|
10216
11090
|
if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
|
|
10217
11091
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
10218
11092
|
}
|
|
10219
11093
|
return normalized.replace(/^\.\//, "");
|
|
10220
11094
|
}
|
|
10221
11095
|
function isRuntimeIdentity(value) {
|
|
10222
|
-
if (!
|
|
11096
|
+
if (!isRecord2(value) || !isSha(value.executableSha256)) return false;
|
|
10223
11097
|
if (value.kind === "executable") return true;
|
|
10224
11098
|
return value.kind === "node-entry" && isSha(value.entrySha256);
|
|
10225
11099
|
}
|
|
10226
11100
|
function isExecutionPlan(value) {
|
|
10227
|
-
if (!
|
|
10228
|
-
return value.schemaVersion === 1 && value.contractVersion === EXECUTION_CONTRACT_VERSION && typeof value.planId === "string" && PLAN_ID_PATTERN.test(value.planId) && typeof value.createdAt === "string" && typeof value.expiresAt === "string" && isSha(value.nonceSha256) && isSha(value.skillsLockSha256) && isRuntimeIdentity(value.runtime) &&
|
|
11101
|
+
if (!isRecord2(value)) return false;
|
|
11102
|
+
return value.schemaVersion === 1 && value.contractVersion === EXECUTION_CONTRACT_VERSION && typeof value.planId === "string" && PLAN_ID_PATTERN.test(value.planId) && typeof value.createdAt === "string" && typeof value.expiresAt === "string" && isSha(value.nonceSha256) && isSha(value.skillsLockSha256) && isRuntimeIdentity(value.runtime) && isRecord2(value.assessment) && isRecord2(value.documents) && isBoundDocument(value.documents.change) && isBoundDocument(value.documents.rollback) && Array.isArray(value.payloads) && value.payloads.every(isBoundPayload) && typeof value.evidenceDir === "string";
|
|
10229
11103
|
}
|
|
10230
11104
|
function isBoundDocument(value) {
|
|
10231
|
-
return
|
|
11105
|
+
return isRecord2(value) && typeof value.path === "string" && isSha(value.sha256);
|
|
10232
11106
|
}
|
|
10233
|
-
function
|
|
11107
|
+
function isBoundPayload(value) {
|
|
11108
|
+
return isBoundDocument(value) && "kind" in value && (value.kind === "file" || value.kind === "directory");
|
|
11109
|
+
}
|
|
11110
|
+
function isRecord2(value) {
|
|
10234
11111
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10235
11112
|
}
|
|
10236
11113
|
function isSha(value) {
|
|
@@ -10243,7 +11120,7 @@ function parseTtl(value) {
|
|
|
10243
11120
|
}
|
|
10244
11121
|
function canonicalJson(value) {
|
|
10245
11122
|
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
10246
|
-
if (
|
|
11123
|
+
if (isRecord2(value)) {
|
|
10247
11124
|
return `{${Object.keys(value).sort().map((key2) => `${JSON.stringify(key2)}:${canonicalJson(value[key2])}`).join(",")}}`;
|
|
10248
11125
|
}
|
|
10249
11126
|
return JSON.stringify(value) ?? "null";
|
|
@@ -10276,8 +11153,8 @@ init_exit();
|
|
|
10276
11153
|
import {
|
|
10277
11154
|
HcmClient as HcmClient26,
|
|
10278
11155
|
adminResetPassword,
|
|
10279
|
-
formatObject as
|
|
10280
|
-
fromAxiosError as
|
|
11156
|
+
formatObject as formatObject27,
|
|
11157
|
+
fromAxiosError as fromAxiosError23,
|
|
10281
11158
|
CliError as CliError22,
|
|
10282
11159
|
CliErrorCode as CliErrorCode21
|
|
10283
11160
|
} from "@hcmai/sdk";
|
|
@@ -10310,10 +11187,10 @@ async function userResetPasswordCommand(args) {
|
|
|
10310
11187
|
const request = buildAdminResetPasswordRequest(args, password);
|
|
10311
11188
|
const client3 = HcmClient26.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
10312
11189
|
const result = await adminResetPassword(client3.raw(), request);
|
|
10313
|
-
process.stdout.write(
|
|
11190
|
+
process.stdout.write(formatObject27(result, { format: args.output ?? "json" }) + "\n");
|
|
10314
11191
|
} catch (cause) {
|
|
10315
11192
|
const err = cause;
|
|
10316
|
-
if (err?.isAxiosError) exitWithError(
|
|
11193
|
+
if (err?.isAxiosError) exitWithError(fromAxiosError23(err, args.env));
|
|
10317
11194
|
exitWithError(cause);
|
|
10318
11195
|
}
|
|
10319
11196
|
}
|
|
@@ -10334,8 +11211,8 @@ init_exit();
|
|
|
10334
11211
|
init_auth_guard();
|
|
10335
11212
|
import {
|
|
10336
11213
|
HcmClient as HcmClient27,
|
|
10337
|
-
formatObject as
|
|
10338
|
-
fromAxiosError as
|
|
11214
|
+
formatObject as formatObject28,
|
|
11215
|
+
fromAxiosError as fromAxiosError24
|
|
10339
11216
|
} from "@hcmai/sdk";
|
|
10340
11217
|
async function modelsCommand(keyword, args) {
|
|
10341
11218
|
try {
|
|
@@ -10345,7 +11222,7 @@ async function modelsCommand(keyword, args) {
|
|
|
10345
11222
|
const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
|
|
10346
11223
|
const fmt = args.output ?? "table";
|
|
10347
11224
|
if (fmt !== "table") {
|
|
10348
|
-
process.stdout.write(
|
|
11225
|
+
process.stdout.write(formatObject28({ total: rows.length, models: rows }, { format: fmt }) + "\n");
|
|
10349
11226
|
process.exit(0);
|
|
10350
11227
|
}
|
|
10351
11228
|
if (rows.length === 0) {
|
|
@@ -10369,7 +11246,7 @@ async function modelsCommand(keyword, args) {
|
|
|
10369
11246
|
process.exit(0);
|
|
10370
11247
|
} catch (e) {
|
|
10371
11248
|
const err = e;
|
|
10372
|
-
if (err?.isAxiosError) exitWithError(
|
|
11249
|
+
if (err?.isAxiosError) exitWithError(fromAxiosError24(err, args.profile));
|
|
10373
11250
|
exitWithError(e);
|
|
10374
11251
|
}
|
|
10375
11252
|
}
|
|
@@ -10393,7 +11270,7 @@ var exitOnBrokenPipe = (err) => {
|
|
|
10393
11270
|
process.stdout.on("error", exitOnBrokenPipe);
|
|
10394
11271
|
process.stderr.on("error", exitOnBrokenPipe);
|
|
10395
11272
|
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);
|
|
10396
|
-
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\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 }));
|
|
11273
|
+
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 }));
|
|
10397
11274
|
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));
|
|
10398
11275
|
var config = program.command("config").description("\u7BA1\u7406\u5168\u5C40 defaults\uFF08env/identity \u7528 `hcm env` / `hcm identity`\uFF09");
|
|
10399
11276
|
config.command("list").description("[deprecated] \u7528 `hcm env list`").action(() => configListDeprecated());
|
|
@@ -10412,6 +11289,7 @@ env.command("show [name]").description("\u663E\u793A env \u8BE6\u60C5\uFF08\u542
|
|
|
10412
11289
|
env.command("edit <field> <value>").description("\u7F16\u8F91 env \u5B57\u6BB5\uFF08endpoint / frontend / tenantId / defaultIdentity / defaultAgent\uFF09").option("--env <name>", "\u76EE\u6807 env \u540D\uFF08\u9ED8\u8BA4\u5F53\u524D activeEnv\uFF09").action((field, value, opts) => envEdit(field, value, opts));
|
|
10413
11290
|
var identity = program.command("identity").description("\u7BA1\u7406 HCM \u8EAB\u4EFD\u51ED\u636E\uFF08env \u4E0B\u7684 identity\uFF09");
|
|
10414
11291
|
identity.command("list").description("\u5217\u51FA identity\uFF08\u9ED8\u8BA4\u5217\u5F53\u524D env\uFF0C--env all \u5217\u5168\u90E8\uFF09").option("--env <name>", '\u8FC7\u6EE4 env\uFF1B\u4F20 "all" \u5217\u5168\u90E8', void 0).action((opts) => identityList(opts));
|
|
11292
|
+
identity.command("show <name>").description("\u5B9E\u65F6\u663E\u793A alias \u5BF9\u5E94\u7684\u670D\u52A1\u7AEF\u7528\u6237\u3001\u79DF\u6237\u4E0E\u89D2\u8272\uFF08\u4E0D\u8F93\u51FA token\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((name, opts) => identityShow(name, opts));
|
|
10415
11293
|
identity.command("use <name>").description("\u628A identity \u8BBE\u4E3A\u5176 env \u7684 default identity").action((name) => identityUse(name));
|
|
10416
11294
|
identity.command("remove <name>").description("\u5220\u9664 identity\uFF08\u6E05 token + \u82E5\u662F env default \u5219\u6E05\u7A7A\uFF09").action((name) => identityRemove(name));
|
|
10417
11295
|
var user = program.command("user").description("\u7BA1\u7406\u79DF\u6237\u7528\u6237\u7684\u4E13\u7528\u51ED\u636E\u6D41\u7A0B");
|
|
@@ -10481,14 +11359,17 @@ delivery.command("triage").description(
|
|
|
10481
11359
|
"--recon <dir>",
|
|
10482
11360
|
"\u57FA\u7EBF\u4EA7\u7269\u76EE\u5F55\uFF08<out>/recon/<\u79DF\u6237\u6BB5>/<\u6765\u6E90\u6BB5>\uFF09\uFF1B\u4E0D\u7ED9\u5219\u6309\u722C\u53D6\u8EAB\u4EFD\u73B0\u7B97\u4E00\u4EFD"
|
|
10483
11361
|
).option("--out <dir>", "\u4EA7\u7269\u6839\uFF08\u5199 work/triage.md\uFF09", ".").option("--capabilities <caps>", "\u672C\u6B21\u63A2\u6D4B\u58F0\u660E\u7684 capability \u4E32", "default").action((opts) => deliveryTriageCommand(opts));
|
|
10484
|
-
delivery.command("init").description("\u751F\u6210\
|
|
10485
|
-
delivery.command("mode").description("\u770B/\u6539\u672C\
|
|
11362
|
+
delivery.command("init").description("\u751F\u6210\u5BA2\u6237\u9879\u76EE\u4ED3\u9AA8\u67B6\u3001\u73AF\u5883\u6E05\u5355\u3001\u6210\u5458 setup \u4E0E\u672C\u673A\u53D7\u63A7\u4EA4\u4ED8\u914D\u7F6E").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--env <name>", "\u521D\u59CB\u5316\u54EA\u4E2A\u73AF\u5883\uFF08\u9ED8\u8BA4 HCM_ENV / activeEnv\uFF09").option("--mode <mode>", "\u672C\u673A\u521D\u59CB\u4EA4\u4ED8\u6A21\u5F0F\uFF1Acontrolled | plan-only", "plan-only").option("--approved-by <person>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u660E\u786E\u6279\u51C6\u7684\u9879\u76EE\u8D1F\u8D23\u4EBA").option("--reason <text>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u6388\u6743\u4F9D\u636E").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u9879\u76EE\u914D\u7F6E").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryInitCommand(opts));
|
|
11363
|
+
delivery.command("mode").description("\u6309\u73AF\u5883\u770B/\u6539\u672C\u673A\u4EA4\u4ED8\u6A21\u5F0F\uFF1B\u4E0D\u5E26 --set \u53EA\u8BFB\uFF0C\u5E26 --set \u53EA\u6539\u76EE\u6807\u73AF\u5883").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").requiredOption("--env <name>", "\u76EE\u6807\u73AF\u5883\uFF08\u5FC5\u586B\uFF1B\u4E0D\u7EE7\u627F\u5168\u5C40 activeEnv\uFF09").option("--set <mode>", "\u6539\u4E3A\uFF1Acontrolled | plan-only").option("--approved-by <person>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u660E\u786E\u6279\u51C6\u7684\u9879\u76EE\u8D1F\u8D23\u4EBA").option("--reason <text>", "\u5207\u5230 controlled \u65F6\u5FC5\u586B\uFF1A\u672C\u6B21\u5BF9\u8BDD\u6216\u4EFB\u52A1\u4E66\u4E2D\u7684\u6388\u6743\u4F9D\u636E").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => deliveryModeCommand(opts));
|
|
10486
11364
|
delivery.command("prepare").description("\u628A\u53D7\u652F\u6301\u7684 R2 argv \u4E0E\u9501\u3001\u8FD0\u884C\u65F6\u548C\u53D8\u66F4/\u56DE\u6EDA\u8BF4\u660E\u7ED1\u5B9A\u4E3A\u77ED\u65F6\u6267\u884C\u8BA1\u5212").requiredOption("--change-ref <file>", "\u9879\u76EE work/ \u6216 decisions/ \u4E0B\u7684\u53D8\u66F4\u8BF4\u660E").requiredOption("--rollback-ref <file>", "\u9879\u76EE work/ \u6216 decisions/ \u4E0B\u7684\u56DE\u6EDA\u8BF4\u660E").requiredOption("--evidence-dir <dir>", "\u9879\u76EE evidence/ \u4E0B\u7684\u6536\u636E\u76EE\u5F55").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--ttl-seconds <n>", "\u6709\u6548\u671F\u79D2\u6570\uFF0860-3600\uFF09", "900").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("<command...>", "\u88AB\u7ED1\u5B9A\u7684 R2 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570\uFF0C\u4E0D\u5305\u542B hcm \u672C\u8EAB").action((command, opts) => deliveryPrepareCommand(command, opts));
|
|
10487
11365
|
delivery.command("execute <planId>").description("\u9010\u6B21\u6279\u51C6\u540E\u6D88\u8D39\u77ED\u65F6\u8BA1\u5212\uFF0C\u5E76\u6267\u884C\u4E00\u6B21\u4E0E\u8BA1\u5212\u5B8C\u5168\u76F8\u540C\u7684 R2 argv").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--output <fmt>", "\u6536\u636E\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").allowUnknownOption(true).argument("[command...]", "\u4E0E prepare \u5B8C\u5168\u76F8\u540C\u7684 R2 HCM \u5B50\u547D\u4EE4\u4E0E\u53C2\u6570").action((planId, command, opts) => deliveryExecuteCommand(planId, command, opts));
|
|
10488
|
-
program.command("query <Model>").description("\u67E5\u8BE2 Model \u5217\u8868\u6570\u636E\uFF08\u901A\u8FC7 ModelQueryDsl JSON \u8868\u8FBE\u8FC7\u6EE4/\u6392\u5E8F/\u5206\u9875\uFF09").option(
|
|
11366
|
+
program.command("query <Model>").description("\u67E5\u8BE2 Model \u5217\u8868\u6570\u636E\uFF08\u901A\u8FC7 ModelQueryDsl JSON \u8868\u8FBE\u8FC7\u6EE4/\u6392\u5E8F/\u5173\u8054/\u5206\u9875\uFF09").option(
|
|
10489
11367
|
"--filter <JSON>",
|
|
10490
11368
|
`\u8FC7\u6EE4 AST\uFF08ModelQueryDsl\uFF09\uFF1A\u53F6\u5B50 '{"field":"status","op":"eq","value":"ACTIVE"}'\uFF0C\u591A\u6761\u4EF6\u7528 '{"and":[\u53F6\u5B50,\u2026]}'\u3002\u26A0\uFE0F \u4E0D\u63A5\u53D7 {"\u5B57\u6BB5":"\u503C"} \u7B80\u5199\uFF0Cschema \u5C42\u4F1A\u62D2`
|
|
10491
|
-
).option("--sort <JSON>", `\u6392\u5E8F\u6761\u4EF6 JSON\uFF0C\u4F8B\u5982 '[{"field":"hireDate","direction":"desc"}]'`).option(
|
|
11369
|
+
).option("--sort <JSON>", `\u6392\u5E8F\u6761\u4EF6 JSON\uFF0C\u4F8B\u5982 '[{"field":"hireDate","direction":"desc"}]'`).option(
|
|
11370
|
+
"--additions <JSON>",
|
|
11371
|
+
`\u8DE8\u5173\u7CFB JOIN \u7684\u5BF9\u8C61\u6570\u7EC4 JSON\uFF0C\u4F8B\u5982 '[{"key":"employee","model":"Employee"}]'`
|
|
11372
|
+
).option("--fields <list>", "\u8FD4\u56DE\u5B57\u6BB5\u5217\u8868\uFF08\u9017\u53F7\u5206\u9694\uFF09\uFF0C\u4F8B\u5982 name,code,email").option("--keyword <text>", "\u5168\u6587\u68C0\u7D22\u5173\u952E\u5B57").option("--limit <n>", "\u6BCF\u9875\u5927\u5C0F", "20").option("--offset <n>", "\u504F\u79FB\u91CF\uFF08\u6309 limit \u81EA\u52A8\u6362\u7B97 page\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").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((m, opts) => queryCommand(m, opts));
|
|
10492
11373
|
program.command("action <Model.Action>").description("\u8C03\u7528 Model \u4E0A\u7684 Action\uFF08\u4E1A\u52A1\u65B9\u6CD5\uFF09\uFF0C\u4F8B\u5982 Employee.regularize").option("--id <id>", "\u76EE\u6807\u5B9E\u4F53 ID\uFF08object Action \u5FC5\u586B\uFF09").option("--ids <csv>", "\u6279\u91CF ID\uFF08\u9017\u53F7\u5206\u9694\uFF0Cbulk Action \u7528\uFF09").option("--method <method>", "HTTP \u65B9\u6CD5\uFF1AGET | POST | PUT | DELETE\uFF08\u9ED8\u8BA4\u6309 Core \u5143\u6570\u636E\u81EA\u52A8\u5224\u5B9A\uFF09").option("--scope <scope>", "\u5F3A\u5236 Action scope\uFF1Aclass | object\uFF08\u9ED8\u8BA4\uFF1A\u6709 --id \u4E3A object\uFF0C\u5426\u5219 class\uFF09").option("--params <JSON>", `Action \u5165\u53C2 JSON\uFF0C\u4F8B\u5982 '{"effectDate":"2026-06-01"}'`).option("--params-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6 Action \u5165\u53C2\uFF08\u4E0E --params \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("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((spec, opts) => actionCommand(spec, opts));
|
|
10493
11374
|
program.command("create <Model>").description("\u521B\u5EFA\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF09").option("--data <JSON>", `\u8BB0\u5F55\u5B57\u6BB5 JSON\uFF0C\u4F8B\u5982 '{"code":"ORG_SALES","name":"\u9500\u552E\u90E8"}'`).option("--data-file <path>", "\u4ECE UTF-8 JSON \u6587\u4EF6\u8BFB\u53D6\u8BB0\u5F55\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("--profile <name>", "[deprecated] \u7528 --env \u66FF\u4EE3").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((m, opts) => createCommand(m, opts));
|
|
10494
11375
|
program.command("delete <Model>").description("\u5220\u9664\u4E00\u6761 Model \u8BB0\u5F55\uFF08\u8D70\u540E\u7AEF\u5B8C\u6574\u6821\u9A8C\uFF1B\u90E8\u5206 Model \u4F1A\u6267\u884C\u4E1A\u52A1\u64A4\u9500\uFF09").option("--id <id>", "\u76EE\u6807\u5B9E\u4F53 ID\uFF08\u5FC5\u586B\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").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((m, opts) => deleteCommand(m, opts));
|
|
@@ -10559,12 +11440,12 @@ var skills = program.command("skills").description("\u4EA4\u4ED8\u6280\u80FD\uFF
|
|
|
10559
11440
|
skills.command("list [keyword]").description("\u5217\u51FA\u76EE\u6807\u73AF\u5883\u8FD9\u4E00\u7248\u7684\u4EA4\u4ED8\u6280\u80FD\uFF1B--installed \u6539\u770B\u672C\u5730\u88C5\u4E86\u54EA\u4E9B\uFF08\u4E0D\u8FDE\u7F51\uFF09").option("--installed", "\u53EA\u770B\u672C\u5730\u5DF2\u88C5\u7684\u6280\u80FD\uFF08\u8BFB .hcm-skills.json\uFF0C\u4E0D\u8FDE\u7F51\uFF09").option("--target <agent>", "\u914D\u5408 --installed\uFF1Aclaude | codex | auto", "auto").option("--global", "\u914D\u5408 --installed\uFF1A\u770B\u7528\u6237\u7EA7\u76EE\u5F55").option("--dir <path>", "\u914D\u5408 --installed\uFF1A\u770B\u6307\u5B9A\u76EE\u5F55").option("--category <key>", "\u53EA\u770B\u67D0\u4E2A\u5206\u7C7B").option("--stage <key>", "\u53EA\u770B\u67D0\u4E2A\u4EA4\u4ED8\u9636\u6BB5\uFF1Ahandover | baseline | configure | migrate | integrate | golive | operate").option("--by-stage", "\u6309\u4EA4\u4ED8\u751F\u547D\u5468\u671F\u5206\u7EC4\u5C55\u793A\uFF08\u9ED8\u8BA4\u6309\u529F\u80FD\u5206\u7C7B\uFF09").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\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", "table").action((kw, opts) => skillsListCommand(kw, opts));
|
|
10560
11441
|
skills.command("manifest").description("\u6253\u5370\u672C CLI \u7684\u547D\u4EE4\u9762\u4E0E\u81EA\u5E26\u6280\u80FD\u6E05\u5355\uFF08\u4E0D\u8FDE\u7F51\uFF0C\u4F9B\u5B88\u536B\u4E0E\u5916\u90E8\u5DE5\u5177\u6BD4\u5BF9\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => skillsManifestCommand(program, opts));
|
|
10561
11442
|
skills.command("show <id>").description("\u6253\u5370\u6280\u80FD\u539F\u6587\uFF08\u7BA1\u9053\u53CB\u597D\uFF09\uFF1B\u81EA\u5E26\u6280\u80FD\u76F4\u63A5\u8BFB\u672C\u5730\uFF0C\u4E0D\u8FDE\u7F51").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").action((id, opts) => skillsShowCommand(id, opts));
|
|
10562
|
-
skills.command("install [id]").description("\u8FDE\u540C requires \u524D\u7F6E\u6280\u80FD\u4E0E\u53C2\u8003\u6587\u4EF6\u88C5\u5230 agent \u6280\u80FD\u76EE\u5F55\uFF1B--all \u88C5\u6574\u4E2A\u6280\u80FD\u5E93").option("--all", "\u88C5\u6574\u4E2A\u6280\u80FD\u5E93\uFF0C\u5E76\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D\uFF08\u5F80\u540E update \u4F1A\u81EA\u52A8\u8865\u4E0A\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\uFF09").option("--target <agent>", "\u88C5\u7ED9\u54EA\u4E2A agent\uFF1Aclaude\uFF08.claude/skills/\uFF09| codex\uFF08hcm-skills/ +
|
|
11443
|
+
skills.command("install [id]").description("\u8FDE\u540C requires \u524D\u7F6E\u6280\u80FD\u4E0E\u53C2\u8003\u6587\u4EF6\u88C5\u5230 agent \u6280\u80FD\u76EE\u5F55\uFF1B--all \u88C5\u6574\u4E2A\u6280\u80FD\u5E93").option("--all", "\u88C5\u6574\u4E2A\u6280\u80FD\u5E93\uFF0C\u5E76\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D\uFF08\u5F80\u540E update \u4F1A\u81EA\u52A8\u8865\u4E0A\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\uFF09").option("--target <agent>", "\u88C5\u7ED9\u54EA\u4E2A agent\uFF1Aclaude\uFF08.claude/skills/\uFF09| codex\uFF08hcm-skills/ + Agent \u7D22\u5F15\uFF09| auto", "auto").option("--global", "\u88C5\u5230\u7528\u6237\u7EA7\u76EE\u5F55\u800C\u975E\u5F53\u524D\u9879\u76EE").option("--dir <path>", "\u88C5\u5230\u6307\u5B9A\u76EE\u5F55").option("--from <dir>", "\u4ECE\u672C\u5730\u76EE\u5F55\u88C5\uFF08\u73B0\u573A\u6539\u8FC7\u7684\u7248\u672C\uFF09\uFF0C\u4E0D\u8D70\u7F51\u7EDC").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--force", "\u8986\u76D6\u5DF2\u5B58\u5728\u7684\u540C\u540D\u6280\u80FD").option("--endpoint <url>", "\u6280\u80FD\u5E93\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", "table").action((id, opts) => skillsInstallCommand(id, opts));
|
|
10563
11444
|
skills.command("update").description("\u628A\u88C5\u8FC7\u7684\u6280\u80FD\u5347\u5230\u76EE\u6807\u73AF\u5883\u8FD9\u4E00\u7248\uFF08\u4EA7\u54C1\u5347\u7EA7\u540E\u8DD1\u5B83\uFF09").option("--all", "\u8FDE\u4EA7\u54C1\u65B0\u589E\u7684\u6280\u80FD\u4E00\u8D77\u88C5\u4E0A\uFF0C\u5E76\u8BB0\u4E3A\u300C\u8DDF\u968F\u5168\u96C6\u300D").option("--check", "\u53EA\u770B\u4F1A\u53D8\u4EC0\u4E48\uFF0C\u4E0D\u5199\u76D8").option("--target <agent>", "claude | codex | auto\uFF08\u9ED8\u8BA4\u6309\u5DF2\u5B89\u88C5\u76EE\u5F55\u63A2\uFF09", "auto").option("--global", "\u5347\u7EA7\u7528\u6237\u7EA7\u76EE\u5F55\u91CC\u7684\u6280\u80FD").option("--dir <path>", "\u5347\u7EA7\u6307\u5B9A\u76EE\u5F55\u91CC\u7684\u6280\u80FD").option("--force", "\u8FDE\u672C\u5730\u6539\u8FC7\u7684\u6280\u80FD\u4E00\u8D77\u8986\u76D6\u6210\u4EA7\u54C1\u8FD9\u4E00\u7248").option("--source <kind>", "\u8FD9\u4E00\u8D9F\u770B\u54EA\u4E9B\u6765\u6E90\uFF1Acli\uFF08\u53EA\u770B\u81EA\u5E26\uFF0C\u4E0D\u8FDE\u7F51\uFF09| chiron | all", "all").option("--endpoint <url>", "\u6280\u80FD\u5E93\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u5B89\u88C5\u65F6\u8BB0\u5F55\u7684\u5730\u5740\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "table").action((opts) => skillsUpdateCommand(opts));
|
|
10564
11445
|
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));
|
|
10565
11446
|
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));
|
|
10566
11447
|
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));
|
|
10567
|
-
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((
|
|
11448
|
+
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((path14, opts) => openCommand(path14, opts));
|
|
10568
11449
|
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");
|
|
10569
11450
|
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));
|
|
10570
11451
|
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));
|