@hcmai/cli 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +248 -93
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +10 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -523,8 +523,8 @@ var init_TerminalRenderer = __esm({
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
/** 来源行(仅子代理触发,agentPath ≥2 段时显示 `↑ 来自 a › b`,对齐 Web)。 */
|
|
526
|
-
originLine(
|
|
527
|
-
const segs =
|
|
526
|
+
originLine(path12) {
|
|
527
|
+
const segs = path12.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(path12) {
|
|
1710
|
+
const segs = (path12 ?? "").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
|
}
|
|
@@ -3084,8 +3084,8 @@ import {
|
|
|
3084
3084
|
formatObject as formatObject7,
|
|
3085
3085
|
fromAxiosError as fromAxiosError8
|
|
3086
3086
|
} from "@hcmai/sdk";
|
|
3087
|
-
function collectYmlFiles(
|
|
3088
|
-
if (statSync(
|
|
3087
|
+
function collectYmlFiles(path12) {
|
|
3088
|
+
if (statSync(path12).isFile()) return [path12];
|
|
3089
3089
|
const out = [];
|
|
3090
3090
|
const walk = (dir) => {
|
|
3091
3091
|
for (const name of readdirSync(dir).sort()) {
|
|
@@ -3094,7 +3094,7 @@ function collectYmlFiles(path11) {
|
|
|
3094
3094
|
else if (full.endsWith(".yml") || full.endsWith(".yaml")) out.push(full);
|
|
3095
3095
|
}
|
|
3096
3096
|
};
|
|
3097
|
-
walk(
|
|
3097
|
+
walk(path12);
|
|
3098
3098
|
return out.sort();
|
|
3099
3099
|
}
|
|
3100
3100
|
var DRY_RUN_CLIENT = {
|
|
@@ -3102,9 +3102,9 @@ var DRY_RUN_CLIENT = {
|
|
|
3102
3102
|
create: async () => ({ id: "" }),
|
|
3103
3103
|
update: async () => ({})
|
|
3104
3104
|
};
|
|
3105
|
-
async function importCommand(
|
|
3105
|
+
async function importCommand(path12, args) {
|
|
3106
3106
|
try {
|
|
3107
|
-
const files = collectYmlFiles(
|
|
3107
|
+
const files = collectYmlFiles(path12);
|
|
3108
3108
|
const fixtures = files.map(
|
|
3109
3109
|
(f) => parseFixture(readFileSync2(f, "utf8"), relative(process.cwd(), f))
|
|
3110
3110
|
);
|
|
@@ -5994,17 +5994,17 @@ async function metaListCommand(args) {
|
|
|
5994
5994
|
fail5(e, args);
|
|
5995
5995
|
}
|
|
5996
5996
|
}
|
|
5997
|
-
async function metaGetCommand(
|
|
5997
|
+
async function metaGetCommand(path12, args) {
|
|
5998
5998
|
try {
|
|
5999
5999
|
const c = await client2(args);
|
|
6000
|
-
const content = await getTenantMeta(c.raw(),
|
|
6000
|
+
const content = await getTenantMeta(c.raw(), path12);
|
|
6001
6001
|
process.stdout.write(content.endsWith("\n") ? content : content + "\n");
|
|
6002
6002
|
process.exit(0);
|
|
6003
6003
|
} catch (e) {
|
|
6004
6004
|
fail5(e, args);
|
|
6005
6005
|
}
|
|
6006
6006
|
}
|
|
6007
|
-
async function metaSetCommand(
|
|
6007
|
+
async function metaSetCommand(path12, args) {
|
|
6008
6008
|
try {
|
|
6009
6009
|
if (!args.file) {
|
|
6010
6010
|
throw new CliError18({
|
|
@@ -6021,7 +6021,7 @@ async function metaSetCommand(path11, args) {
|
|
|
6021
6021
|
}) : await fsp3.readFile(args.file, "utf8");
|
|
6022
6022
|
if (args.dryRun) {
|
|
6023
6023
|
process.stdout.write(
|
|
6024
|
-
`[dry-run] \u5C06\u5199\u5165 ${
|
|
6024
|
+
`[dry-run] \u5C06\u5199\u5165 ${path12}\uFF08${Buffer.byteLength(content)} B\uFF09\u2014\u2014\u672A\u5B9E\u9645\u5199\u5165
|
|
6025
6025
|
---
|
|
6026
6026
|
${content}
|
|
6027
6027
|
`
|
|
@@ -6029,10 +6029,10 @@ ${content}
|
|
|
6029
6029
|
process.exit(0);
|
|
6030
6030
|
}
|
|
6031
6031
|
const c = await client2(args);
|
|
6032
|
-
const result = await saveTenantMeta(c.raw(),
|
|
6032
|
+
const result = await saveTenantMeta(c.raw(), path12, content);
|
|
6033
6033
|
const fmt = args.output ?? "json";
|
|
6034
6034
|
if (fmt !== "json") {
|
|
6035
|
-
process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${
|
|
6035
|
+
process.stdout.write(`\u2705 \u5DF2\u5199\u5165 ${path12}
|
|
6036
6036
|
\u8BB0\u5F97\u6E05\u7F13\u5B58\uFF1Ahcm cache clear-meta <Model>
|
|
6037
6037
|
`);
|
|
6038
6038
|
}
|
|
@@ -6043,19 +6043,19 @@ ${content}
|
|
|
6043
6043
|
fail5(e, args);
|
|
6044
6044
|
}
|
|
6045
6045
|
}
|
|
6046
|
-
async function metaDeleteCommand(
|
|
6046
|
+
async function metaDeleteCommand(path12, args) {
|
|
6047
6047
|
try {
|
|
6048
6048
|
if (!args.yes) {
|
|
6049
|
-
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${
|
|
6049
|
+
const ok = await promptConfirm(`\u5C06\u5220\u9664\u5143\u6570\u636E ${path12}\uFF0C\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\u3002\u7EE7\u7EED\uFF1F`);
|
|
6050
6050
|
if (!ok) {
|
|
6051
6051
|
process.stderr.write("\u5DF2\u53D6\u6D88\n");
|
|
6052
6052
|
process.exit(1);
|
|
6053
6053
|
}
|
|
6054
6054
|
}
|
|
6055
6055
|
const c = await client2(args);
|
|
6056
|
-
const result = await deleteTenantMeta(c.raw(),
|
|
6056
|
+
const result = await deleteTenantMeta(c.raw(), path12);
|
|
6057
6057
|
const fmt = args.output ?? "json";
|
|
6058
|
-
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${
|
|
6058
|
+
if (fmt !== "json") process.stdout.write(`\u{1F5D1}\uFE0F \u5DF2\u5220\u9664 ${path12}
|
|
6059
6059
|
`);
|
|
6060
6060
|
process.stdout.write(formatObject17(result, { format: fmt }) + "\n");
|
|
6061
6061
|
process.exit(0);
|
|
@@ -7501,6 +7501,8 @@ async function identityRemove(name) {
|
|
|
7501
7501
|
|
|
7502
7502
|
// src/commands/delivery-action-policy.ts
|
|
7503
7503
|
init_auth_guard();
|
|
7504
|
+
import { existsSync as existsSync2 } from "fs";
|
|
7505
|
+
import { join as pathJoin } from "path";
|
|
7504
7506
|
import {
|
|
7505
7507
|
HcmClient as HcmClient18,
|
|
7506
7508
|
formatObject as formatObject19
|
|
@@ -7525,7 +7527,21 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
|
|
|
7525
7527
|
"cache-mutation",
|
|
7526
7528
|
"setting-write",
|
|
7527
7529
|
"credential-reset",
|
|
7528
|
-
"action-write"
|
|
7530
|
+
"action-write",
|
|
7531
|
+
"workspace-create",
|
|
7532
|
+
"workspace-activate",
|
|
7533
|
+
// 这两个的载荷是**任意文件 / 整棵目录**,此前刻意不收——绑不住就意味着
|
|
7534
|
+
// 「批准时看到的内容」与「执行时实际读到的内容」可以不同。
|
|
7535
|
+
//
|
|
7536
|
+
// 现在绑得住了:PAYLOAD_FILE_FLAGS 收了 --file,PAYLOAD_DIR_FLAGS 收了 --dir
|
|
7537
|
+
// (workspace push 不传 --dir 时按其 option 默认值 '.' 隐式绑定),
|
|
7538
|
+
// 目录按「路径 + 内容、排序稳定」整树摘要,assertPayloadsUnchanged 执行前逐一重算比对。
|
|
7539
|
+
//
|
|
7540
|
+
// 🔴 二次开发的整条链就卡在这两个上:2026-09-01 轨道 A 第四轮验收,
|
|
7541
|
+
// 受控执行第一次跑通了 workspace create,却在 meta set / workspace push 上
|
|
7542
|
+
// 被「该 R2 命令不在首批受控执行器支持面」拦死,远端只多了一个空 workspace。
|
|
7543
|
+
"metadata-write",
|
|
7544
|
+
"workspace-push"
|
|
7529
7545
|
]);
|
|
7530
7546
|
function assessDeliveryCommand(inputArgv, options = {}) {
|
|
7531
7547
|
const argv = inputArgv[0] === "--" ? inputArgv.slice(1) : [...inputArgv];
|
|
@@ -7866,9 +7882,26 @@ async function assessEffectiveDeliveryCommand(inputArgv, dependencies = {}) {
|
|
|
7866
7882
|
const resolution = await (dependencies.resolveAction ?? resolveCoreAction)(request);
|
|
7867
7883
|
return assessDeliveryCommand(inputArgv, { actionResolution: resolution });
|
|
7868
7884
|
}
|
|
7885
|
+
function withProjectReadiness(assessment, projectRoot = ".") {
|
|
7886
|
+
const projectFile = pathJoin(projectRoot, ".hcm-delivery", "project.yml");
|
|
7887
|
+
const projectInitialized = existsSync2(projectFile);
|
|
7888
|
+
if (projectInitialized || !assessment.guardedExecutionAvailable) {
|
|
7889
|
+
return { ...assessment, projectInitialized };
|
|
7890
|
+
}
|
|
7891
|
+
const requirements = [...assessment.requirements ?? []];
|
|
7892
|
+
if (!requirements.includes("delivery-project")) requirements.push("delivery-project");
|
|
7893
|
+
return {
|
|
7894
|
+
...assessment,
|
|
7895
|
+
projectInitialized,
|
|
7896
|
+
requirements,
|
|
7897
|
+
modePolicy: assessment.modePolicy ? { ...assessment.modePolicy, controlled: "deny" } : assessment.modePolicy,
|
|
7898
|
+
projectNextStep: `\u672C\u9879\u76EE\u5C1A\u672A\u521D\u59CB\u5316\uFF08\u7F3A ${projectFile}\uFF09\uFF1B\u5148\u8DD1 hcm delivery init`
|
|
7899
|
+
};
|
|
7900
|
+
}
|
|
7869
7901
|
async function deliveryAssessCommand(argv, args) {
|
|
7870
7902
|
const assessment = await assessEffectiveDeliveryCommand(argv);
|
|
7871
|
-
|
|
7903
|
+
const enriched = withProjectReadiness(assessment);
|
|
7904
|
+
process.stdout.write(formatObject19(enriched, { format: args.output ?? "json" }) + "\n");
|
|
7872
7905
|
}
|
|
7873
7906
|
async function resolveCoreAction(request) {
|
|
7874
7907
|
try {
|
|
@@ -7963,13 +7996,84 @@ function flagValue2(argv, flag) {
|
|
|
7963
7996
|
return index >= 0 ? argv[index + 1] : void 0;
|
|
7964
7997
|
}
|
|
7965
7998
|
|
|
7999
|
+
// src/commands/delivery-init.ts
|
|
8000
|
+
init_exit();
|
|
8001
|
+
import { promises as fs6 } from "fs";
|
|
8002
|
+
import path6 from "path";
|
|
8003
|
+
import { formatObject as formatObject20 } from "@hcmai/sdk";
|
|
8004
|
+
var MODES = ["plan-only", "controlled"];
|
|
8005
|
+
var SCAFFOLD_DIRS = ["work", "decisions", "evidence"];
|
|
8006
|
+
function renderProjectYml(mode) {
|
|
8007
|
+
return [
|
|
8008
|
+
"# HCM \u987E\u95EE\u4EA4\u4ED8\u9879\u76EE\u914D\u7F6E\uFF08hcm delivery init \u751F\u6210\uFF09",
|
|
8009
|
+
"#",
|
|
8010
|
+
"# deliveryMode \u51B3\u5B9A\u8FD9\u4E2A\u9879\u76EE\u5141\u8BB8\u8D70\u5230\u54EA\u4E00\u6B65\uFF1A",
|
|
8011
|
+
"# plan-only \u2014\u2014 \u53EA\u5141\u8BB8 assess / prepare \u51FA\u8BA1\u5212\uFF0Cexecute \u4E00\u5F8B\u62D2\u7EDD",
|
|
8012
|
+
"# controlled \u2014\u2014 \u5141\u8BB8 prepare + execute \u5355\u6B21\u53D7\u63A7\u6267\u884C\uFF08\u4ECD\u9700\u9010\u6B21\u6279\u51C6\uFF09",
|
|
8013
|
+
"#",
|
|
8014
|
+
"# \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",
|
|
8015
|
+
"# \u6539\u8FD9\u4E00\u884C\u53EA\u6539\u300C\u672C\u9879\u76EE\u5141\u4E0D\u5141\u8BB8\u771F\u7684\u6267\u884C\u300D\uFF0C\u4E0D\u6539\u300C\u8FD9\u6761\u547D\u4EE4\u6709\u591A\u5371\u9669\u300D\u3002",
|
|
8016
|
+
`deliveryMode: ${mode}`,
|
|
8017
|
+
""
|
|
8018
|
+
].join("\n");
|
|
8019
|
+
}
|
|
8020
|
+
async function deliveryInitCommand(args) {
|
|
8021
|
+
try {
|
|
8022
|
+
const mode = args.mode ?? "controlled";
|
|
8023
|
+
if (!MODES.includes(mode)) {
|
|
8024
|
+
throw new Error(
|
|
8025
|
+
`--mode \u53EA\u63A5\u53D7 ${MODES.join(" | ")}\uFF0C\u6536\u5230 "${args.mode}"
|
|
8026
|
+
\u8FD9\u4E24\u4E2A\u503C\u662F delivery prepare \u8BA4\u5F97\u7684\u5168\u90E8\uFF1B\u5199\u522B\u7684\u503C prepare \u4F1A\u62D2\u7EDD\u52A0\u8F7D\u3002`
|
|
8027
|
+
);
|
|
8028
|
+
}
|
|
8029
|
+
const root = path6.resolve(args.project ?? ".");
|
|
8030
|
+
const dir = path6.join(root, ".hcm-delivery");
|
|
8031
|
+
const file = path6.join(dir, "project.yml");
|
|
8032
|
+
let existed = false;
|
|
8033
|
+
try {
|
|
8034
|
+
await fs6.access(file);
|
|
8035
|
+
existed = true;
|
|
8036
|
+
} catch {
|
|
8037
|
+
existed = false;
|
|
8038
|
+
}
|
|
8039
|
+
if (existed && !args.force) {
|
|
8040
|
+
throw new Error(
|
|
8041
|
+
`\u9879\u76EE\u914D\u7F6E\u5DF2\u5B58\u5728\uFF1A${file}
|
|
8042
|
+
\u4E0D\u8986\u76D6\u5DF2\u6709\u914D\u7F6E\u2014\u2014\u5B83\u51B3\u5B9A\u672C\u9879\u76EE\u5141\u4E0D\u5141\u8BB8\u771F\u7684\u6267\u884C\u3002
|
|
8043
|
+
\u786E\u8981\u91CD\u5199\uFF1Ahcm delivery init --force`
|
|
8044
|
+
);
|
|
8045
|
+
}
|
|
8046
|
+
await fs6.mkdir(dir, { recursive: true });
|
|
8047
|
+
await fs6.writeFile(file, renderProjectYml(mode), "utf8");
|
|
8048
|
+
const created = [];
|
|
8049
|
+
for (const sub of SCAFFOLD_DIRS) {
|
|
8050
|
+
const p = path6.join(root, sub);
|
|
8051
|
+
await fs6.mkdir(p, { recursive: true });
|
|
8052
|
+
created.push(sub + "/");
|
|
8053
|
+
}
|
|
8054
|
+
const result = {
|
|
8055
|
+
project: root,
|
|
8056
|
+
projectFile: file,
|
|
8057
|
+
deliveryMode: mode,
|
|
8058
|
+
overwritten: existed,
|
|
8059
|
+
scaffold: created,
|
|
8060
|
+
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"
|
|
8061
|
+
};
|
|
8062
|
+
process.stdout.write(formatObject20(result, { format: args.output ?? "json" }) + "\n");
|
|
8063
|
+
process.exit(0);
|
|
8064
|
+
} catch (e) {
|
|
8065
|
+
exitWithError(e);
|
|
8066
|
+
process.exit(1);
|
|
8067
|
+
}
|
|
8068
|
+
}
|
|
8069
|
+
|
|
7966
8070
|
// src/commands/delivery-doctor.ts
|
|
7967
8071
|
init_auth_guard();
|
|
7968
8072
|
init_exit();
|
|
7969
8073
|
import {
|
|
7970
8074
|
HcmClient as HcmClient19,
|
|
7971
8075
|
fetchReconIdentity,
|
|
7972
|
-
formatObject as
|
|
8076
|
+
formatObject as formatObject21,
|
|
7973
8077
|
fromAxiosError as fromAxiosError18,
|
|
7974
8078
|
httpProbe,
|
|
7975
8079
|
runDoctor
|
|
@@ -7995,7 +8099,7 @@ async function deliveryDoctorCommand(args) {
|
|
|
7995
8099
|
const report = await runDoctor(probe, identity2);
|
|
7996
8100
|
const fmt = args.output ?? "json";
|
|
7997
8101
|
if (fmt !== "json") process.stdout.write(render2(report) + "\n");
|
|
7998
|
-
process.stdout.write(
|
|
8102
|
+
process.stdout.write(formatObject21(report, { format: fmt }) + "\n");
|
|
7999
8103
|
process.exit(report.ok ? 0 : 1);
|
|
8000
8104
|
} catch (e) {
|
|
8001
8105
|
const err = e;
|
|
@@ -8013,7 +8117,7 @@ import {
|
|
|
8013
8117
|
ReconLayout,
|
|
8014
8118
|
ROUND_EXIT_CODES,
|
|
8015
8119
|
computeReconSourceKey,
|
|
8016
|
-
formatObject as
|
|
8120
|
+
formatObject as formatObject22,
|
|
8017
8121
|
fromAxiosError as fromAxiosError19,
|
|
8018
8122
|
httpProbe as httpProbe2,
|
|
8019
8123
|
inspectRound,
|
|
@@ -8033,7 +8137,7 @@ async function deliveryReconCommand(args) {
|
|
|
8033
8137
|
onlyModel: args.model ?? null,
|
|
8034
8138
|
identity: ctx.tenantId ? { requestedTenantId: ctx.tenantId } : null
|
|
8035
8139
|
});
|
|
8036
|
-
process.stdout.write(
|
|
8140
|
+
process.stdout.write(formatObject22(summary, { format: args.output ?? "json" }) + "\n");
|
|
8037
8141
|
} catch (e) {
|
|
8038
8142
|
const err = e;
|
|
8039
8143
|
if (err?.isAxiosError) exitWithError(fromAxiosError19(err, args.env));
|
|
@@ -8047,7 +8151,7 @@ async function deliveryReconRoundCommand(args) {
|
|
|
8047
8151
|
const result = inspectRound(args.dir ?? ".");
|
|
8048
8152
|
const fmt = args.output ?? "json";
|
|
8049
8153
|
if (fmt !== "json") process.stdout.write(renderRound(result));
|
|
8050
|
-
process.stdout.write(
|
|
8154
|
+
process.stdout.write(formatObject22(result, { format: fmt }) + "\n");
|
|
8051
8155
|
code = ROUND_EXIT_CODES[result.state];
|
|
8052
8156
|
} catch (e) {
|
|
8053
8157
|
exitWithError(e);
|
|
@@ -8065,14 +8169,14 @@ import {
|
|
|
8065
8169
|
GAP_REASONS,
|
|
8066
8170
|
deriveAclass,
|
|
8067
8171
|
exitCode as gate0ExitCode,
|
|
8068
|
-
formatObject as
|
|
8172
|
+
formatObject as formatObject23,
|
|
8069
8173
|
inspectRound as inspectRound2,
|
|
8070
8174
|
loadProtocolFacts,
|
|
8071
8175
|
scan
|
|
8072
8176
|
} from "@hcmai/sdk";
|
|
8073
|
-
import * as
|
|
8177
|
+
import * as path7 from "path";
|
|
8074
8178
|
function renderGate0(result, skillRoot) {
|
|
8075
|
-
const where = skillRoot ? `\uFF08${
|
|
8179
|
+
const where = skillRoot ? `\uFF08${path7.resolve(skillRoot)}\uFF09` : "";
|
|
8076
8180
|
const lines = [
|
|
8077
8181
|
`\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`
|
|
8078
8182
|
];
|
|
@@ -8110,7 +8214,7 @@ async function deliveryGate0Command(args) {
|
|
|
8110
8214
|
const merged = { ...result, premise: premise5 };
|
|
8111
8215
|
const fmt = args.output ?? "json";
|
|
8112
8216
|
if (fmt !== "json") process.stdout.write(renderGate0(merged, skillRoot));
|
|
8113
|
-
process.stdout.write(`${
|
|
8217
|
+
process.stdout.write(`${formatObject23(merged, { format: fmt })}
|
|
8114
8218
|
`);
|
|
8115
8219
|
for (const problem of premise5) {
|
|
8116
8220
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF08${problem.reason}\uFF09\uFF1A${problem.message}
|
|
@@ -8183,8 +8287,8 @@ import {
|
|
|
8183
8287
|
writeImportPlan,
|
|
8184
8288
|
writeRisk
|
|
8185
8289
|
} from "@hcmai/sdk";
|
|
8186
|
-
import { existsSync as
|
|
8187
|
-
import * as
|
|
8290
|
+
import { existsSync as existsSync3 } from "fs";
|
|
8291
|
+
import * as path8 from "path";
|
|
8188
8292
|
function premise(message, hint = "") {
|
|
8189
8293
|
process.stderr.write(message + (hint ? `
|
|
8190
8294
|
\u2192 ${hint}` : "") + "\n");
|
|
@@ -8195,7 +8299,7 @@ async function runSeedPlan(args, client3) {
|
|
|
8195
8299
|
const tenant2 = tenantOf(client3);
|
|
8196
8300
|
const work = seedWorkDir({ out, tenant: tenant2, work: args.work ?? null, mapping: args.mapping ?? null });
|
|
8197
8301
|
const mappingPath = seedMappingPath({ out, tenant: tenant2, mapping: args.mapping ?? null }, work);
|
|
8198
|
-
if (!
|
|
8302
|
+
if (!existsSync3(mappingPath)) {
|
|
8199
8303
|
return premise(
|
|
8200
8304
|
`\u8BFB\u4E0D\u5230\u5BFC\u5165\u6620\u5C04\u5DE5\u4EF6\uFF1A${mappingPath}`,
|
|
8201
8305
|
"\u5DE5\u4EF6\u662F\u987E\u95EE\u81EA\u5DF1\u5199\u7684\uFF08\u5951\u7EA6\u89C1 README \u7684 `work/mapping.json` \u4E00\u8282\uFF09\u3002\u5199\u5728\u522B\u5904\u5C31\u7528 `--mapping <\u8DEF\u5F84>` \u6307\u8FC7\u53BB\uFF0C\u6216\u7528 `--work <\u76EE\u5F55>` \u6362 work \u76EE\u5F55\u3002"
|
|
@@ -8211,13 +8315,13 @@ async function runSeedPlan(args, client3) {
|
|
|
8211
8315
|
const reconDir = candidates[0].reconDir;
|
|
8212
8316
|
if (candidates.length > 1) {
|
|
8213
8317
|
process.stderr.write(
|
|
8214
|
-
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${
|
|
8318
|
+
`\u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u6709 ${candidates.length} \u4EFD\u57FA\u7EBF\uFF0C\u672C\u8F6E\u8BFB\u7684\u662F \`${path8.basename(reconDir)}\`\uFF1A` + candidates.slice(1).map((c) => `\`${path8.basename(c.reconDir)}\``).join("\u3001") + " \u672A\u88AB\u8BFB\u53D6 \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n"
|
|
8215
8319
|
);
|
|
8216
8320
|
}
|
|
8217
8321
|
const round = inspectRound3(reconDir);
|
|
8218
8322
|
process.stderr.write(roundWarning(round));
|
|
8219
8323
|
const baseline = {
|
|
8220
|
-
path: `${
|
|
8324
|
+
path: `${path8.basename(path8.dirname(reconDir))}/${path8.basename(reconDir)}`,
|
|
8221
8325
|
roundId: round.roundId ?? null
|
|
8222
8326
|
};
|
|
8223
8327
|
let exemptions = null;
|
|
@@ -8477,9 +8581,9 @@ async function deliverySeedVerifyCommand(args) {
|
|
|
8477
8581
|
}
|
|
8478
8582
|
|
|
8479
8583
|
// src/commands/delivery-seed-find.ts
|
|
8480
|
-
import { existsSync as
|
|
8584
|
+
import { existsSync as existsSync4 } from "fs";
|
|
8481
8585
|
import { readFileSync as readFileSync5 } from "fs";
|
|
8482
|
-
import * as
|
|
8586
|
+
import * as path9 from "path";
|
|
8483
8587
|
import {
|
|
8484
8588
|
INIT_EXIT_CODES as INIT_EXIT_CODES2,
|
|
8485
8589
|
ValueHints,
|
|
@@ -8493,10 +8597,10 @@ import {
|
|
|
8493
8597
|
valuesRoundCaveat
|
|
8494
8598
|
} from "@hcmai/sdk";
|
|
8495
8599
|
function provenance(chosenReconDir, others) {
|
|
8496
|
-
let line = `> \u57FA\u7EBF\uFF1A\`${
|
|
8600
|
+
let line = `> \u57FA\u7EBF\uFF1A\`${path9.basename(chosenReconDir)}\`
|
|
8497
8601
|
`;
|
|
8498
8602
|
if (others.length > 0) {
|
|
8499
|
-
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${
|
|
8603
|
+
line += `> \u26A0\uFE0F \u540C\u79DF\u6237\u4E0B\u53E6\u6709 ${others.length} \u4EFD\u57FA\u7EBF\u672A\u88AB\u8BFB\u53D6\uFF1A` + others.map((o) => `\`${path9.basename(o)}\``).join("\u3001") + " \u2014\u2014 \u4E0D\u540C sourceKey \u7684\u4EA7\u7269**\u4E0D\u53EF\u4E92\u6362**\u3002\n";
|
|
8500
8604
|
}
|
|
8501
8605
|
return `${line}
|
|
8502
8606
|
`;
|
|
@@ -8538,7 +8642,7 @@ function runSeedFind(args) {
|
|
|
8538
8642
|
const chosen = { reconDir: picked.reconDir, indexFile: picked.indexFile };
|
|
8539
8643
|
const prefix = picked.prefix;
|
|
8540
8644
|
process.stdout.write(prefix);
|
|
8541
|
-
if (!
|
|
8645
|
+
if (!existsSync4(chosen.indexFile)) {
|
|
8542
8646
|
return premise2(`\u7D22\u5F15\u6587\u4EF6\u5728\u9009\u4E2D\u4E4B\u540E\u6D88\u5931\u4E86\uFF1A${chosen.indexFile}`);
|
|
8543
8647
|
}
|
|
8544
8648
|
const { rows, problems } = loadRows(readFileSync5(chosen.indexFile, "utf-8"));
|
|
@@ -8833,7 +8937,7 @@ import {
|
|
|
8833
8937
|
runTriageRound
|
|
8834
8938
|
} from "@hcmai/sdk";
|
|
8835
8939
|
import { mkdirSync, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "fs";
|
|
8836
|
-
import * as
|
|
8940
|
+
import * as path10 from "path";
|
|
8837
8941
|
var DEFAULT_CAPABILITIES4 = "default";
|
|
8838
8942
|
function premise4(message, hint) {
|
|
8839
8943
|
process.stderr.write(`\u{1F534} \u524D\u63D0\u4E0D\u6210\u7ACB\uFF1A${message}
|
|
@@ -8869,8 +8973,8 @@ function renderProblems(rows) {
|
|
|
8869
8973
|
`;
|
|
8870
8974
|
}
|
|
8871
8975
|
function writeTriageArtifact(outDir, body) {
|
|
8872
|
-
const out =
|
|
8873
|
-
mkdirSync(
|
|
8976
|
+
const out = path10.join(outDir, "work", "triage.md");
|
|
8977
|
+
mkdirSync(path10.dirname(out), { recursive: true });
|
|
8874
8978
|
writeFileSync2(out, body, "utf8");
|
|
8875
8979
|
return out;
|
|
8876
8980
|
}
|
|
@@ -8910,9 +9014,9 @@ async function deliveryTriageCommand(args) {
|
|
|
8910
9014
|
// src/commands/delivery-execution.ts
|
|
8911
9015
|
import { createHash as createHash5, randomBytes as secureRandomBytes } from "crypto";
|
|
8912
9016
|
import { spawn } from "child_process";
|
|
8913
|
-
import { createReadStream, promises as
|
|
8914
|
-
import
|
|
8915
|
-
import { CliError as CliError20, CliErrorCode as CliErrorCode19, formatObject as
|
|
9017
|
+
import { createReadStream, promises as fs7 } from "fs";
|
|
9018
|
+
import path11 from "path";
|
|
9019
|
+
import { CliError as CliError20, CliErrorCode as CliErrorCode19, formatObject as formatObject24 } from "@hcmai/sdk";
|
|
8916
9020
|
init_exit();
|
|
8917
9021
|
var EXECUTION_CONTRACT_VERSION = "2026-08-29.controlled-v3";
|
|
8918
9022
|
var DEFAULT_TTL_SECONDS = 15 * 60;
|
|
@@ -8951,11 +9055,11 @@ async function prepareDeliveryExecution(input) {
|
|
|
8951
9055
|
};
|
|
8952
9056
|
const planId = sha2565(canonicalJson(core)).slice(0, 24);
|
|
8953
9057
|
const plan = { ...core, planId };
|
|
8954
|
-
const plansDir =
|
|
9058
|
+
const plansDir = path11.join(project, ".hcm-delivery", "execution-plans");
|
|
8955
9059
|
await safeManagedDirectory(project, ".hcm-delivery/execution-plans", plansDir);
|
|
8956
|
-
const planFile =
|
|
9060
|
+
const planFile = path11.join(plansDir, `${planId}.json`);
|
|
8957
9061
|
try {
|
|
8958
|
-
await
|
|
9062
|
+
await fs7.writeFile(planFile, `${JSON.stringify(plan, null, 2)}
|
|
8959
9063
|
`, {
|
|
8960
9064
|
encoding: "utf8",
|
|
8961
9065
|
mode: 384,
|
|
@@ -8972,7 +9076,7 @@ async function executeDeliveryPlan(input) {
|
|
|
8972
9076
|
if (await readProjectMode(project) !== "controlled") {
|
|
8973
9077
|
throw invalid2("\u9879\u76EE\u4E0D\u662F controlled\uFF0C\u4E0D\u80FD\u6267\u884C R2 \u8BA1\u5212");
|
|
8974
9078
|
}
|
|
8975
|
-
const planFile =
|
|
9079
|
+
const planFile = path11.join(project, ".hcm-delivery", "execution-plans", `${input.planId}.json`);
|
|
8976
9080
|
const plan = await readPlan(project, planFile);
|
|
8977
9081
|
if (plan.planId !== input.planId || computePlanId(plan) !== input.planId) {
|
|
8978
9082
|
throw invalid2("\u6267\u884C\u8BA1\u5212\u5185\u5BB9\u4E0E planId \u6458\u8981\u4E0D\u4E00\u81F4");
|
|
@@ -9003,13 +9107,13 @@ async function executeDeliveryPlan(input) {
|
|
|
9003
9107
|
await assertDocumentUnchanged(project, plan.documents.rollback, "\u56DE\u6EDA\u8BF4\u660E");
|
|
9004
9108
|
await assertPayloadsUnchanged(project, plan.payloads);
|
|
9005
9109
|
const evidenceDir = await bindEvidenceDirectory(project, plan.evidenceDir);
|
|
9006
|
-
const receiptFile =
|
|
9110
|
+
const receiptFile = path11.join(evidenceDir.absolute, `${plan.planId}.receipt.json`);
|
|
9007
9111
|
if (await pathExists(receiptFile)) throw invalid2(`\u6267\u884C\u6536\u636E\u5DF2\u5B58\u5728\uFF0C\u62D2\u7EDD\u518D\u6B21\u6267\u884C\uFF1A${plan.planId}`);
|
|
9008
|
-
const claimsDir =
|
|
9112
|
+
const claimsDir = path11.join(project, ".hcm-delivery", "execution-claims");
|
|
9009
9113
|
await safeManagedDirectory(project, ".hcm-delivery/execution-claims", claimsDir);
|
|
9010
|
-
const claimFile =
|
|
9114
|
+
const claimFile = path11.join(claimsDir, `${plan.planId}.json`);
|
|
9011
9115
|
try {
|
|
9012
|
-
await
|
|
9116
|
+
await fs7.writeFile(
|
|
9013
9117
|
claimFile,
|
|
9014
9118
|
`${JSON.stringify({ schemaVersion: 1, planId: plan.planId, claimedAt: now.toISOString() }, null, 2)}
|
|
9015
9119
|
`,
|
|
@@ -9066,7 +9170,7 @@ async function deliveryPrepareCommand(argv, args) {
|
|
|
9066
9170
|
evidenceDir: args.evidenceDir,
|
|
9067
9171
|
...ttlSeconds === void 0 ? {} : { ttlSeconds }
|
|
9068
9172
|
});
|
|
9069
|
-
process.stdout.write(
|
|
9173
|
+
process.stdout.write(formatObject24(plan, { format: args.output ?? "json" }) + "\n");
|
|
9070
9174
|
process.stderr.write(`
|
|
9071
9175
|
\u4E0B\u4E00\u6B65\uFF08argv \u5FC5\u987B\u4E0E\u672C\u6B21\u5B8C\u5168\u4E00\u81F4\uFF09\uFF1A
|
|
9072
9176
|
${nextCommandHint(plan.planId, args.project, argv)}
|
|
@@ -9087,14 +9191,14 @@ async function deliveryExecuteCommand(planId, argv, args) {
|
|
|
9087
9191
|
planId,
|
|
9088
9192
|
argv
|
|
9089
9193
|
});
|
|
9090
|
-
process.stdout.write(
|
|
9194
|
+
process.stdout.write(formatObject24(receipt, { format: args.output ?? "json" }) + "\n");
|
|
9091
9195
|
process.exitCode = receipt.exitCode;
|
|
9092
9196
|
} catch (cause) {
|
|
9093
9197
|
exitWithError(cause);
|
|
9094
9198
|
}
|
|
9095
9199
|
}
|
|
9096
9200
|
async function readProjectMode(project) {
|
|
9097
|
-
const file =
|
|
9201
|
+
const file = path11.join(project, ".hcm-delivery", "project.yml");
|
|
9098
9202
|
const content = await readSafeFile(project, file, "\u9879\u76EE\u914D\u7F6E");
|
|
9099
9203
|
const match = content.toString("utf8").match(
|
|
9100
9204
|
/^deliveryMode:\s*(?:"(plan-only|controlled)"|'(plan-only|controlled)'|(plan-only|controlled))\s*$/m
|
|
@@ -9106,13 +9210,13 @@ async function readProjectMode(project) {
|
|
|
9106
9210
|
return mode;
|
|
9107
9211
|
}
|
|
9108
9212
|
var SKILLS_LOCK_CANDIDATES = [
|
|
9109
|
-
|
|
9110
|
-
|
|
9213
|
+
path11.join("hcm-skills", ".hcm-skills.json"),
|
|
9214
|
+
path11.join(".claude", "skills", ".hcm-skills.json")
|
|
9111
9215
|
];
|
|
9112
9216
|
async function readSkillsLock(project) {
|
|
9113
9217
|
const found = [];
|
|
9114
9218
|
for (const candidate of SKILLS_LOCK_CANDIDATES) {
|
|
9115
|
-
if (await pathExists(
|
|
9219
|
+
if (await pathExists(path11.join(project, candidate))) found.push(candidate);
|
|
9116
9220
|
}
|
|
9117
9221
|
if (found.length === 0) {
|
|
9118
9222
|
throw invalid2(
|
|
@@ -9124,7 +9228,7 @@ async function readSkillsLock(project) {
|
|
|
9124
9228
|
`\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`
|
|
9125
9229
|
);
|
|
9126
9230
|
}
|
|
9127
|
-
const bytes = await readSafeFile(project,
|
|
9231
|
+
const bytes = await readSafeFile(project, path11.join(project, found[0]), "\u6280\u80FD\u9501");
|
|
9128
9232
|
try {
|
|
9129
9233
|
JSON.parse(bytes.toString("utf8"));
|
|
9130
9234
|
} catch (cause) {
|
|
@@ -9137,7 +9241,7 @@ async function bindDocument(project, reference, label) {
|
|
|
9137
9241
|
if (!(relative2.startsWith("work/") || relative2.startsWith("decisions/"))) {
|
|
9138
9242
|
throw invalid2(`${label}\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE work/ \u6216 decisions/ \u4E0B`);
|
|
9139
9243
|
}
|
|
9140
|
-
const file =
|
|
9244
|
+
const file = path11.join(project, relative2);
|
|
9141
9245
|
const bytes = await readSafeFile(project, file, label);
|
|
9142
9246
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
9143
9247
|
}
|
|
@@ -9150,11 +9254,11 @@ async function bindEvidenceDirectory(project, reference) {
|
|
|
9150
9254
|
if (!(relative2 === "evidence" || relative2.startsWith("evidence/"))) {
|
|
9151
9255
|
throw invalid2("evidence \u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E\u9879\u76EE evidence/ \u4E0B");
|
|
9152
9256
|
}
|
|
9153
|
-
const absolute =
|
|
9257
|
+
const absolute = path11.join(project, relative2);
|
|
9154
9258
|
await assertNoSymlinkComponents(project, relative2);
|
|
9155
|
-
const stat = await
|
|
9259
|
+
const stat = await fs7.stat(absolute).catch(() => null);
|
|
9156
9260
|
if (stat === null) {
|
|
9157
|
-
await
|
|
9261
|
+
await fs7.mkdir(absolute, { recursive: true, mode: 448 }).catch((cause) => {
|
|
9158
9262
|
throw invalid2(
|
|
9159
9263
|
`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`,
|
|
9160
9264
|
cause
|
|
@@ -9270,7 +9374,9 @@ function requireExactlyOnePayload(argv, command) {
|
|
|
9270
9374
|
throw invalid2(`${command} \u5FC5\u987B\u5305\u542B --data <JSON> \u6216 --data-file <\u6587\u4EF6>`);
|
|
9271
9375
|
}
|
|
9272
9376
|
}
|
|
9273
|
-
var PAYLOAD_FILE_FLAGS = ["--data-file", "--params-file"];
|
|
9377
|
+
var PAYLOAD_FILE_FLAGS = ["--data-file", "--params-file", "--file"];
|
|
9378
|
+
var PAYLOAD_DIR_FLAGS = ["--dir"];
|
|
9379
|
+
var IMPLICIT_DIR_COMMANDS = { "workspace push": "." };
|
|
9274
9380
|
async function bindPayloadFiles(project, argv) {
|
|
9275
9381
|
const bound = [];
|
|
9276
9382
|
for (const flag of PAYLOAD_FILE_FLAGS) {
|
|
@@ -9278,19 +9384,67 @@ async function bindPayloadFiles(project, argv) {
|
|
|
9278
9384
|
if (reference === void 0) continue;
|
|
9279
9385
|
bound.push(await bindPayloadFile(project, reference, `${flag} \u8F7D\u8377`));
|
|
9280
9386
|
}
|
|
9387
|
+
for (const flag of PAYLOAD_DIR_FLAGS) {
|
|
9388
|
+
const reference = optionalFlagValue(argv, flag);
|
|
9389
|
+
if (reference === void 0) continue;
|
|
9390
|
+
bound.push(await bindPayloadDirectory(project, reference, `${flag} \u76EE\u5F55\u8F7D\u8377`));
|
|
9391
|
+
}
|
|
9392
|
+
const implicit = IMPLICIT_DIR_COMMANDS[`${argv[0]} ${argv[1]}`];
|
|
9393
|
+
if (implicit !== void 0 && optionalFlagValue(argv, "--dir") === void 0) {
|
|
9394
|
+
bound.push(await bindPayloadDirectory(project, implicit, "\u5DE5\u4F5C\u7A7A\u95F4\u76EE\u5F55\u8F7D\u8377"));
|
|
9395
|
+
}
|
|
9281
9396
|
return bound;
|
|
9282
9397
|
}
|
|
9398
|
+
async function bindPayloadDirectory(project, reference, label) {
|
|
9399
|
+
const relative2 = reference === "." ? "." : safeRelative(reference, label);
|
|
9400
|
+
const root = path11.join(project, relative2);
|
|
9401
|
+
let stat;
|
|
9402
|
+
try {
|
|
9403
|
+
stat = await fs7.stat(root);
|
|
9404
|
+
} catch {
|
|
9405
|
+
throw invalid2(`${label}\u4E0D\u5B58\u5728\uFF1A${relative2}`);
|
|
9406
|
+
}
|
|
9407
|
+
if (!stat.isDirectory()) {
|
|
9408
|
+
throw invalid2(`${label}\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
9409
|
+
}
|
|
9410
|
+
const entries = [];
|
|
9411
|
+
const walk = async (dir, prefix) => {
|
|
9412
|
+
const items = await fs7.readdir(dir, { withFileTypes: true });
|
|
9413
|
+
for (const item of [...items].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)) {
|
|
9414
|
+
if ([".git", "node_modules", ".hcm-delivery", "evidence"].includes(item.name)) continue;
|
|
9415
|
+
const child = path11.join(dir, item.name);
|
|
9416
|
+
const rel = prefix ? `${prefix}/${item.name}` : item.name;
|
|
9417
|
+
if (item.isDirectory()) {
|
|
9418
|
+
await walk(child, rel);
|
|
9419
|
+
} else if (item.isFile()) {
|
|
9420
|
+
const bytes = await readSafeFile(project, child, `${label} ${rel}`);
|
|
9421
|
+
entries.push(`${rel}
|
|
9422
|
+
${sha2565(bytes)}`);
|
|
9423
|
+
}
|
|
9424
|
+
}
|
|
9425
|
+
};
|
|
9426
|
+
await walk(root, "");
|
|
9427
|
+
return { path: relative2, sha256: sha2565(Buffer.from(entries.join("\n"), "utf8")) };
|
|
9428
|
+
}
|
|
9283
9429
|
async function bindPayloadFile(project, reference, label) {
|
|
9284
9430
|
const relative2 = safeRelative(reference, label);
|
|
9285
|
-
const file =
|
|
9431
|
+
const file = path11.join(project, relative2);
|
|
9286
9432
|
const bytes = await readSafeFile(project, file, label);
|
|
9287
9433
|
return { path: relative2, sha256: sha2565(bytes) };
|
|
9288
9434
|
}
|
|
9289
9435
|
async function assertPayloadsUnchanged(project, payloads) {
|
|
9290
9436
|
for (const payload of payloads) {
|
|
9291
|
-
|
|
9437
|
+
let isDirectory = false;
|
|
9438
|
+
try {
|
|
9439
|
+
isDirectory = (await fs7.stat(path11.join(project, payload.path))).isDirectory();
|
|
9440
|
+
} catch {
|
|
9441
|
+
isDirectory = false;
|
|
9442
|
+
}
|
|
9443
|
+
const current = isDirectory ? await bindPayloadDirectory(project, payload.path, `\u8F7D\u8377 ${payload.path}`) : await bindPayloadFile(project, payload.path, `\u8F7D\u8377 ${payload.path}`);
|
|
9292
9444
|
if (current.sha256 !== payload.sha256) {
|
|
9293
|
-
throw invalid2(
|
|
9445
|
+
throw invalid2(
|
|
9446
|
+
`\u8F7D\u8377${isDirectory ? "\u76EE\u5F55" : "\u6587\u4EF6"} ${payload.path} \u7684\u5185\u5BB9\u5DF2\u53D8\u66F4\uFF0C\u8BF7\u91CD\u65B0 prepare`
|
|
9447
|
+
);
|
|
9294
9448
|
}
|
|
9295
9449
|
}
|
|
9296
9450
|
}
|
|
@@ -9343,29 +9497,29 @@ async function runCurrentCliCommand(argv, cwd, streams) {
|
|
|
9343
9497
|
async function writeReceiptExclusive(target, receipt) {
|
|
9344
9498
|
const temp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
9345
9499
|
try {
|
|
9346
|
-
await
|
|
9500
|
+
await fs7.writeFile(temp, `${JSON.stringify(receipt, null, 2)}
|
|
9347
9501
|
`, {
|
|
9348
9502
|
encoding: "utf8",
|
|
9349
9503
|
mode: 384,
|
|
9350
9504
|
flag: "wx"
|
|
9351
9505
|
});
|
|
9352
|
-
await
|
|
9506
|
+
await fs7.link(temp, target);
|
|
9353
9507
|
} catch (cause) {
|
|
9354
|
-
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${
|
|
9508
|
+
throw invalid2(`\u6267\u884C\u6536\u636E\u5199\u5165\u5931\u8D25\u6216\u5DF2\u5B58\u5728\uFF1A${path11.basename(target)}`, cause);
|
|
9355
9509
|
} finally {
|
|
9356
|
-
await
|
|
9510
|
+
await fs7.unlink(temp).catch(() => void 0);
|
|
9357
9511
|
}
|
|
9358
9512
|
}
|
|
9359
9513
|
async function safeManagedDirectory(project, relative2, absolute) {
|
|
9360
|
-
await assertNoSymlinkComponents(project,
|
|
9361
|
-
const existing = await
|
|
9514
|
+
await assertNoSymlinkComponents(project, path11.dirname(relative2));
|
|
9515
|
+
const existing = await fs7.lstat(absolute).catch(() => void 0);
|
|
9362
9516
|
if (existing?.isSymbolicLink()) throw invalid2(`\u53D7\u7BA1\u76EE\u5F55\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
9363
9517
|
if (existing && !existing.isDirectory()) throw invalid2(`\u53D7\u7BA1\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${relative2}`);
|
|
9364
|
-
if (!existing) await
|
|
9365
|
-
await
|
|
9518
|
+
if (!existing) await fs7.mkdir(absolute, { mode: 448 });
|
|
9519
|
+
await fs7.chmod(absolute, 448);
|
|
9366
9520
|
}
|
|
9367
9521
|
async function pathExists(file) {
|
|
9368
|
-
return
|
|
9522
|
+
return fs7.lstat(file).then(
|
|
9369
9523
|
() => true,
|
|
9370
9524
|
(cause) => {
|
|
9371
9525
|
if (cause.code === "ENOENT") return false;
|
|
@@ -9374,47 +9528,47 @@ async function pathExists(file) {
|
|
|
9374
9528
|
);
|
|
9375
9529
|
}
|
|
9376
9530
|
async function readSafeFile(project, file, label) {
|
|
9377
|
-
const relative2 =
|
|
9378
|
-
if (relative2.startsWith("../") ||
|
|
9531
|
+
const relative2 = path11.relative(project, file).split(path11.sep).join("/");
|
|
9532
|
+
if (relative2.startsWith("../") || path11.isAbsolute(relative2))
|
|
9379
9533
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
9380
9534
|
await assertNoSymlinkComponents(project, relative2);
|
|
9381
9535
|
let stat;
|
|
9382
9536
|
try {
|
|
9383
|
-
stat = await
|
|
9537
|
+
stat = await fs7.lstat(file);
|
|
9384
9538
|
} catch (cause) {
|
|
9385
9539
|
throw invalid2(`${label}\u4E0D\u53EF\u7528\uFF1A${relative2}`, cause);
|
|
9386
9540
|
}
|
|
9387
9541
|
if (stat.isSymbolicLink()) throw invalid2(`${label}\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
9388
9542
|
if (!stat.isFile()) throw invalid2(`${label}\u4E0D\u662F\u666E\u901A\u6587\u4EF6\uFF1A${relative2}`);
|
|
9389
|
-
return
|
|
9543
|
+
return fs7.readFile(file);
|
|
9390
9544
|
}
|
|
9391
9545
|
async function assertNoSymlinkComponents(project, relative2) {
|
|
9392
9546
|
const parts = relative2.split("/").filter(Boolean);
|
|
9393
9547
|
let current = project;
|
|
9394
9548
|
for (const part of parts) {
|
|
9395
|
-
current =
|
|
9396
|
-
const stat = await
|
|
9549
|
+
current = path11.join(current, part);
|
|
9550
|
+
const stat = await fs7.lstat(current).catch(() => void 0);
|
|
9397
9551
|
if (stat?.isSymbolicLink()) throw invalid2(`\u8DEF\u5F84\u5305\u542B\u7B26\u53F7\u94FE\u63A5\uFF1A${relative2}`);
|
|
9398
9552
|
if (!stat) break;
|
|
9399
9553
|
}
|
|
9400
9554
|
}
|
|
9401
9555
|
async function realProject(requested) {
|
|
9402
|
-
const absolute =
|
|
9556
|
+
const absolute = path11.resolve(requested);
|
|
9403
9557
|
let project;
|
|
9404
9558
|
try {
|
|
9405
|
-
project = await
|
|
9559
|
+
project = await fs7.realpath(absolute);
|
|
9406
9560
|
} catch (cause) {
|
|
9407
9561
|
throw invalid2(`\u9879\u76EE\u76EE\u5F55\u4E0D\u53EF\u7528\uFF1A${absolute}`, cause);
|
|
9408
9562
|
}
|
|
9409
|
-
const stat = await
|
|
9563
|
+
const stat = await fs7.stat(project);
|
|
9410
9564
|
if (!stat.isDirectory()) throw invalid2(`\u9879\u76EE\u8DEF\u5F84\u4E0D\u662F\u76EE\u5F55\uFF1A${absolute}`);
|
|
9411
9565
|
return project;
|
|
9412
9566
|
}
|
|
9413
9567
|
function safeRelative(reference, label) {
|
|
9414
|
-
if (!reference ||
|
|
9568
|
+
if (!reference || path11.isAbsolute(reference) || /[\r\n\0]/.test(reference)) {
|
|
9415
9569
|
throw invalid2(`${label}\u5FC5\u987B\u662F\u9879\u76EE\u5185\u76F8\u5BF9\u8DEF\u5F84`);
|
|
9416
9570
|
}
|
|
9417
|
-
const normalized =
|
|
9571
|
+
const normalized = path11.normalize(reference).split(path11.sep).join("/");
|
|
9418
9572
|
if (normalized === ".." || normalized.startsWith("../") || normalized === ".") {
|
|
9419
9573
|
throw invalid2(`${label}\u8DEF\u5F84\u9003\u9038\u9879\u76EE`);
|
|
9420
9574
|
}
|
|
@@ -9478,7 +9632,7 @@ init_exit();
|
|
|
9478
9632
|
import {
|
|
9479
9633
|
HcmClient as HcmClient24,
|
|
9480
9634
|
adminResetPassword,
|
|
9481
|
-
formatObject as
|
|
9635
|
+
formatObject as formatObject25,
|
|
9482
9636
|
fromAxiosError as fromAxiosError20,
|
|
9483
9637
|
CliError as CliError21,
|
|
9484
9638
|
CliErrorCode as CliErrorCode20
|
|
@@ -9512,7 +9666,7 @@ async function userResetPasswordCommand(args) {
|
|
|
9512
9666
|
const request = buildAdminResetPasswordRequest(args, password);
|
|
9513
9667
|
const client3 = HcmClient24.fromAuthContext(await getActiveAuthContextFromCli(args));
|
|
9514
9668
|
const result = await adminResetPassword(client3.raw(), request);
|
|
9515
|
-
process.stdout.write(
|
|
9669
|
+
process.stdout.write(formatObject25(result, { format: args.output ?? "json" }) + "\n");
|
|
9516
9670
|
} catch (cause) {
|
|
9517
9671
|
const err = cause;
|
|
9518
9672
|
if (err?.isAxiosError) exitWithError(fromAxiosError20(err, args.env));
|
|
@@ -9536,7 +9690,7 @@ init_exit();
|
|
|
9536
9690
|
init_auth_guard();
|
|
9537
9691
|
import {
|
|
9538
9692
|
HcmClient as HcmClient25,
|
|
9539
|
-
formatObject as
|
|
9693
|
+
formatObject as formatObject26,
|
|
9540
9694
|
fromAxiosError as fromAxiosError21
|
|
9541
9695
|
} from "@hcmai/sdk";
|
|
9542
9696
|
async function modelsCommand(keyword, args) {
|
|
@@ -9547,7 +9701,7 @@ async function modelsCommand(keyword, args) {
|
|
|
9547
9701
|
const rows = (needle ? all.filter((m) => JSON.stringify(m).toLowerCase().includes(needle)) : all).sort((a, b) => key(a).localeCompare(key(b)));
|
|
9548
9702
|
const fmt = args.output ?? "table";
|
|
9549
9703
|
if (fmt !== "table") {
|
|
9550
|
-
process.stdout.write(
|
|
9704
|
+
process.stdout.write(formatObject26({ total: rows.length, models: rows }, { format: fmt }) + "\n");
|
|
9551
9705
|
process.exit(0);
|
|
9552
9706
|
}
|
|
9553
9707
|
if (rows.length === 0) {
|
|
@@ -9683,6 +9837,7 @@ delivery.command("triage").description(
|
|
|
9683
9837
|
"--recon <dir>",
|
|
9684
9838
|
"\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"
|
|
9685
9839
|
).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));
|
|
9840
|
+
delivery.command("init").description("\u751F\u6210\u53D7\u63A7\u6267\u884C\u6240\u9700\u7684\u9879\u76EE\u9AA8\u67B6\uFF08.hcm-delivery/project.yml + work/ decisions/ evidence/\uFF09").option("--project <dir>", "HCM \u987E\u95EE\u9879\u76EE\u6839\u76EE\u5F55", ".").option("--mode <mode>", "\u4EA4\u4ED8\u6A21\u5F0F\uFF1Acontrolled | plan-only", "controlled").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));
|
|
9686
9841
|
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));
|
|
9687
9842
|
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));
|
|
9688
9843
|
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(
|